blob: 4b4f347f5b75a6fb7381185047fe40b04298134b [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
Jamie Madill09463932018-04-04 05:26:59 -0400132void MarkTransformFeedbackBufferUsage(const gl::Context *context,
133 gl::TransformFeedback *transformFeedback,
James Darpinian30b604d2018-03-12 17:26:57 -0700134 GLsizei count,
135 GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -0400136{
Geoff Lang1a683462015-09-29 15:09:59 -0400137 if (transformFeedback && transformFeedback->isActive() && !transformFeedback->isPaused())
Geoff Langf6db0982015-08-25 13:04:00 -0400138 {
Jamie Madill09463932018-04-04 05:26:59 -0400139 transformFeedback->onVerticesDrawn(context, count, instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -0400140 }
141}
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500142
143// Attribute map queries.
Martin Radev1be913c2016-07-11 17:59:16 +0300144EGLint GetClientMajorVersion(const egl::AttributeMap &attribs)
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500145{
Ian Ewellec2c0c52016-04-05 13:46:26 -0400146 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_CLIENT_VERSION, 1));
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500147}
148
Martin Radev1be913c2016-07-11 17:59:16 +0300149EGLint GetClientMinorVersion(const egl::AttributeMap &attribs)
150{
151 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_MINOR_VERSION, 0));
152}
153
Geoff Langeb66a6e2016-10-31 13:06:12 -0400154gl::Version GetClientVersion(const egl::AttributeMap &attribs)
155{
156 return gl::Version(GetClientMajorVersion(attribs), GetClientMinorVersion(attribs));
157}
158
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500159GLenum GetResetStrategy(const egl::AttributeMap &attribs)
160{
Lingfeng Yangb27b03a2018-02-19 13:38:48 -0800161 EGLAttrib attrib =
162 attribs.get(EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT, EGL_NO_RESET_NOTIFICATION);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500163 switch (attrib)
164 {
165 case EGL_NO_RESET_NOTIFICATION:
166 return GL_NO_RESET_NOTIFICATION_EXT;
167 case EGL_LOSE_CONTEXT_ON_RESET:
168 return GL_LOSE_CONTEXT_ON_RESET_EXT;
169 default:
170 UNREACHABLE();
171 return GL_NONE;
172 }
173}
174
175bool GetRobustAccess(const egl::AttributeMap &attribs)
176{
Geoff Lang077f20a2016-11-01 10:08:02 -0400177 return (attribs.get(EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT, EGL_FALSE) == EGL_TRUE) ||
178 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR) !=
179 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500180}
181
182bool GetDebug(const egl::AttributeMap &attribs)
183{
Geoff Lang077f20a2016-11-01 10:08:02 -0400184 return (attribs.get(EGL_CONTEXT_OPENGL_DEBUG, EGL_FALSE) == EGL_TRUE) ||
185 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR) != 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500186}
187
188bool GetNoError(const egl::AttributeMap &attribs)
189{
190 return (attribs.get(EGL_CONTEXT_OPENGL_NO_ERROR_KHR, EGL_FALSE) == EGL_TRUE);
191}
192
Geoff Langc287ea62016-09-16 14:46:51 -0400193bool GetWebGLContext(const egl::AttributeMap &attribs)
194{
195 return (attribs.get(EGL_CONTEXT_WEBGL_COMPATIBILITY_ANGLE, EGL_FALSE) == EGL_TRUE);
196}
197
Geoff Lang0ab41fa2018-03-14 11:03:30 -0400198bool GetExtensionsEnabled(const egl::AttributeMap &attribs, bool webGLContext)
199{
200 // If the context is WebGL, extensions are disabled by default
201 EGLAttrib defaultValue = webGLContext ? EGL_FALSE : EGL_TRUE;
202 return (attribs.get(EGL_EXTENSIONS_ENABLED_ANGLE, defaultValue) == EGL_TRUE);
203}
204
Geoff Langf41a7152016-09-19 15:11:17 -0400205bool GetBindGeneratesResource(const egl::AttributeMap &attribs)
206{
207 return (attribs.get(EGL_CONTEXT_BIND_GENERATES_RESOURCE_CHROMIUM, EGL_TRUE) == EGL_TRUE);
208}
209
Geoff Langfeb8c682017-02-13 16:07:35 -0500210bool GetClientArraysEnabled(const egl::AttributeMap &attribs)
211{
212 return (attribs.get(EGL_CONTEXT_CLIENT_ARRAYS_ENABLED_ANGLE, EGL_TRUE) == EGL_TRUE);
213}
214
Geoff Langb433e872017-10-05 14:01:47 -0400215bool GetRobustResourceInit(const egl::AttributeMap &attribs)
216{
217 return (attribs.get(EGL_ROBUST_RESOURCE_INITIALIZATION_ANGLE, EGL_FALSE) == EGL_TRUE);
218}
219
Martin Radev9d901792016-07-15 15:58:58 +0300220std::string GetObjectLabelFromPointer(GLsizei length, const GLchar *label)
221{
222 std::string labelName;
223 if (label != nullptr)
224 {
225 size_t labelLength = length < 0 ? strlen(label) : length;
226 labelName = std::string(label, labelLength);
227 }
228 return labelName;
229}
230
231void GetObjectLabelBase(const std::string &objectLabel,
232 GLsizei bufSize,
233 GLsizei *length,
234 GLchar *label)
235{
236 size_t writeLength = objectLabel.length();
237 if (label != nullptr && bufSize > 0)
238 {
239 writeLength = std::min(static_cast<size_t>(bufSize) - 1, objectLabel.length());
240 std::copy(objectLabel.begin(), objectLabel.begin() + writeLength, label);
241 label[writeLength] = '\0';
242 }
243
244 if (length != nullptr)
245 {
246 *length = static_cast<GLsizei>(writeLength);
247 }
248}
249
Jamie Madill0f80ed82017-09-19 00:24:56 -0400250template <typename CapT, typename MaxT>
251void LimitCap(CapT *cap, MaxT maximum)
252{
253 *cap = std::min(*cap, static_cast<CapT>(maximum));
254}
255
Geoff Langf6db0982015-08-25 13:04:00 -0400256} // anonymous namespace
257
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000258namespace gl
259{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +0000260
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400261Context::Context(rx::EGLImplFactory *implFactory,
262 const egl::Config *config,
Corentin Wallez51706ea2015-08-07 14:39:22 -0400263 const Context *shareContext,
Geoff Langce02f082017-02-06 16:46:21 -0500264 TextureManager *shareTextures,
Jamie Madill32447362017-06-28 14:53:52 -0400265 MemoryProgramCache *memoryProgramCache,
Corentin Wallezc295e512017-01-27 17:47:50 -0500266 const egl::AttributeMap &attribs,
Geoff Langb433e872017-10-05 14:01:47 -0400267 const egl::DisplayExtensions &displayExtensions)
Jamie Madill5b772312018-03-08 20:28:32 -0500268 : mState(reinterpret_cast<ContextID>(this),
269 shareContext ? &shareContext->mState : nullptr,
270 shareTextures,
271 GetClientVersion(attribs),
272 &mGLState,
273 mCaps,
274 mTextureCaps,
275 mExtensions,
276 mLimitations),
277 mSkipValidation(GetNoError(attribs)),
278 mDisplayTextureShareGroup(shareTextures != nullptr),
279 mSavedArgsType(nullptr),
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700280 mImplementation(implFactory->createContext(mState)),
Jamie Madill2f348d22017-06-05 10:50:59 -0400281 mCompiler(),
Corentin Walleze3b10e82015-05-20 11:06:25 -0400282 mConfig(config),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500283 mClientType(EGL_OPENGL_ES_API),
284 mHasBeenCurrent(false),
285 mContextLost(false),
286 mResetStatus(GL_NO_ERROR),
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700287 mContextLostForced(false),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500288 mResetStrategy(GetResetStrategy(attribs)),
289 mRobustAccess(GetRobustAccess(attribs)),
Jamie Madill61e16b42017-06-19 11:13:23 -0400290 mCurrentSurface(static_cast<egl::Surface *>(EGL_NO_SURFACE)),
291 mCurrentDisplay(static_cast<egl::Display *>(EGL_NO_DISPLAY)),
Jamie Madill4e0e6f82017-02-17 11:06:03 -0500292 mSurfacelessFramebuffer(nullptr),
Jamie Madille14951e2017-03-09 18:55:16 -0500293 mWebGLContext(GetWebGLContext(attribs)),
Geoff Lang0ab41fa2018-03-14 11:03:30 -0400294 mExtensionsEnabled(GetExtensionsEnabled(attribs, mWebGLContext)),
Jamie Madill32447362017-06-28 14:53:52 -0400295 mMemoryProgramCache(memoryProgramCache),
Jamie Madillb3f26b92017-07-19 15:07:41 -0400296 mScratchBuffer(1000u),
297 mZeroFilledBuffer(1000u)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000298{
Jamie Madill5b772312018-03-08 20:28:32 -0500299 // Needed to solve a Clang warning of unused variables.
300 UNUSED_VARIABLE(mSavedArgsType);
301 UNUSED_VARIABLE(mParamsBuffer);
302
Jamie Madill14bbb3f2017-09-12 15:23:01 -0400303 mImplementation->setMemoryProgramCache(memoryProgramCache);
304
Geoff Langb433e872017-10-05 14:01:47 -0400305 bool robustResourceInit = GetRobustResourceInit(attribs);
306 initCaps(displayExtensions, robustResourceInit);
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700307 initWorkarounds();
Geoff Langc0b9ef42014-07-02 10:02:37 -0400308
Jamie Madill4928b7c2017-06-20 12:57:39 -0400309 mGLState.initialize(this, GetDebug(attribs), GetBindGeneratesResource(attribs),
Jamie Madillc43be722017-07-13 16:22:14 -0400310 GetClientArraysEnabled(attribs), robustResourceInit,
311 mMemoryProgramCache != nullptr);
Régis Fénéon83107972015-02-05 12:57:44 +0100312
Shannon Woods53a94a82014-06-24 15:20:36 -0400313 mFenceNVHandleAllocator.setBaseHandle(0);
Geoff Lang7dca1862013-07-30 16:30:46 -0400314
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000315 // [OpenGL ES 2.0.24] section 3.7 page 83:
Corentin Wallez336129f2017-10-17 15:55:40 -0400316 // In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have two-dimensional
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000317 // and cube map texture state vectors respectively associated with them.
318 // In order that access to these initial textures not be lost, they are treated as texture
319 // objects all of whose names are 0.
320
Corentin Wallez99d492c2018-02-27 15:17:10 -0500321 Texture *zeroTexture2D = new Texture(mImplementation.get(), 0, TextureType::_2D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800322 mZeroTextures[TextureType::_2D].set(this, zeroTexture2D);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500323
Corentin Wallez99d492c2018-02-27 15:17:10 -0500324 Texture *zeroTextureCube = new Texture(mImplementation.get(), 0, TextureType::CubeMap);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800325 mZeroTextures[TextureType::CubeMap].set(this, zeroTextureCube);
Geoff Lang76b10c92014-09-05 16:28:14 -0400326
Geoff Langeb66a6e2016-10-31 13:06:12 -0400327 if (getClientVersion() >= Version(3, 0))
Geoff Lang76b10c92014-09-05 16:28:14 -0400328 {
329 // TODO: These could also be enabled via extension
Corentin Wallez99d492c2018-02-27 15:17:10 -0500330 Texture *zeroTexture3D = new Texture(mImplementation.get(), 0, TextureType::_3D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800331 mZeroTextures[TextureType::_3D].set(this, zeroTexture3D);
Geoff Lang76b10c92014-09-05 16:28:14 -0400332
Corentin Wallez99d492c2018-02-27 15:17:10 -0500333 Texture *zeroTexture2DArray = new Texture(mImplementation.get(), 0, TextureType::_2DArray);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800334 mZeroTextures[TextureType::_2DArray].set(this, zeroTexture2DArray);
Geoff Lang76b10c92014-09-05 16:28:14 -0400335 }
Geoff Lang3b573612016-10-31 14:08:10 -0400336 if (getClientVersion() >= Version(3, 1))
337 {
338 Texture *zeroTexture2DMultisample =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500339 new Texture(mImplementation.get(), 0, TextureType::_2DMultisample);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800340 mZeroTextures[TextureType::_2DMultisample].set(this, zeroTexture2DMultisample);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800341
Jiajia Qin6eafb042016-12-27 17:04:07 +0800342 for (unsigned int i = 0; i < mCaps.maxAtomicCounterBufferBindings; i++)
343 {
Qin Jiajia339f65b2018-02-27 12:52:48 +0800344 bindBufferRange(BufferBinding::AtomicCounter, i, 0, 0, 0);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800345 }
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800346
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800347 for (unsigned int i = 0; i < mCaps.maxShaderStorageBufferBindings; i++)
348 {
Corentin Wallez336129f2017-10-17 15:55:40 -0400349 bindBufferRange(BufferBinding::ShaderStorage, i, 0, 0, 0);
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800350 }
Geoff Lang3b573612016-10-31 14:08:10 -0400351 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000352
Geoff Lang4751aab2017-10-30 15:14:52 -0400353 const Extensions &nativeExtensions = mImplementation->getNativeExtensions();
354 if (nativeExtensions.textureRectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400355 {
356 Texture *zeroTextureRectangle =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500357 new Texture(mImplementation.get(), 0, TextureType::Rectangle);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800358 mZeroTextures[TextureType::Rectangle].set(this, zeroTextureRectangle);
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400359 }
360
Geoff Lang4751aab2017-10-30 15:14:52 -0400361 if (nativeExtensions.eglImageExternal || nativeExtensions.eglStreamConsumerExternal)
Ian Ewellbda75592016-04-18 17:25:54 -0400362 {
Corentin Wallez99d492c2018-02-27 15:17:10 -0500363 Texture *zeroTextureExternal = new Texture(mImplementation.get(), 0, TextureType::External);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800364 mZeroTextures[TextureType::External].set(this, zeroTextureExternal);
Ian Ewellbda75592016-04-18 17:25:54 -0400365 }
366
Jamie Madill4928b7c2017-06-20 12:57:39 -0400367 mGLState.initializeZeroTextures(this, mZeroTextures);
Jamie Madille6382c32014-11-07 15:05:26 -0500368
Jamie Madill57a89722013-07-02 11:57:03 -0400369 bindVertexArray(0);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000370
Geoff Langeb66a6e2016-10-31 13:06:12 -0400371 if (getClientVersion() >= Version(3, 0))
Geoff Lang1a683462015-09-29 15:09:59 -0400372 {
373 // [OpenGL ES 3.0.2] section 2.14.1 pg 85:
374 // In the initial state, a default transform feedback object is bound and treated as
375 // a transform feedback object with a name of zero. That object is bound any time
376 // BindTransformFeedback is called with id of zero
Jamie Madillf0dcb8b2017-08-26 19:05:13 -0400377 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Geoff Lang1a683462015-09-29 15:09:59 -0400378 }
Geoff Langc8058452014-02-03 12:04:11 -0500379
Corentin Wallez336129f2017-10-17 15:55:40 -0400380 for (auto type : angle::AllEnums<BufferBinding>())
381 {
382 bindBuffer(type, 0);
383 }
384
385 bindRenderbuffer(GL_RENDERBUFFER, 0);
386
387 for (unsigned int i = 0; i < mCaps.maxUniformBufferBindings; i++)
388 {
389 bindBufferRange(BufferBinding::Uniform, i, 0, 0, -1);
390 }
391
Jamie Madillad9f24e2016-02-12 09:27:24 -0500392 // Initialize dirty bit masks
Jamie Madillc67323a2017-11-02 23:11:41 -0400393 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500394 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500395 // No dirty objects.
396
397 // Readpixels uses the pack state and read FBO
Jamie Madillc67323a2017-11-02 23:11:41 -0400398 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500399 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500400 mReadPixelsDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
401
402 mClearDirtyBits.set(State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED);
403 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
404 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR);
405 mClearDirtyBits.set(State::DIRTY_BIT_VIEWPORT);
406 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_COLOR);
407 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_DEPTH);
408 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_STENCIL);
409 mClearDirtyBits.set(State::DIRTY_BIT_COLOR_MASK);
410 mClearDirtyBits.set(State::DIRTY_BIT_DEPTH_MASK);
411 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT);
412 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_BACK);
413 mClearDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
414
415 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
416 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR);
Geoff Lang1d2c41d2016-10-19 16:14:46 -0700417 mBlitDirtyBits.set(State::DIRTY_BIT_FRAMEBUFFER_SRGB);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500418 mBlitDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
419 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
Jamie Madill437fa652016-05-03 15:13:24 -0400420
Xinghua Cao10a4d432017-11-28 14:46:26 +0800421 // TODO(xinghua.cao@intel.com): add other dirty bits and dirty objects.
422 mComputeDirtyBits.set(State::DIRTY_BIT_SHADER_STORAGE_BUFFER_BINDING);
423 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_BINDING);
424 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_EXECUTABLE);
425 mComputeDirtyBits.set(State::DIRTY_BIT_TEXTURE_BINDINGS);
426 mComputeDirtyBits.set(State::DIRTY_BIT_SAMPLER_BINDINGS);
Qin Jiajia62fcf622017-11-30 16:16:12 +0800427 mComputeDirtyBits.set(State::DIRTY_BIT_DISPATCH_INDIRECT_BUFFER_BINDING);
Jiajia Qin5ae6ee42018-03-06 17:39:42 +0800428 mComputeDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM_TEXTURES);
Xinghua Cao10a4d432017-11-28 14:46:26 +0800429
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400430 handleError(mImplementation->initialize());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000431}
432
Jamie Madill4928b7c2017-06-20 12:57:39 -0400433egl::Error Context::onDestroy(const egl::Display *display)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000434{
Jamie Madille7b3fe22018-04-05 09:42:46 -0400435 // Delete the Surface first to trigger a finish() in Vulkan.
436 SafeDelete(mSurfacelessFramebuffer);
437
438 ANGLE_TRY(releaseSurface(display));
439
Corentin Wallez80b24112015-08-25 16:41:57 -0400440 for (auto fence : mFenceNVMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000441 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400442 SafeDelete(fence.second);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000443 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400444 mFenceNVMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000445
Corentin Wallez80b24112015-08-25 16:41:57 -0400446 for (auto query : mQueryMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000447 {
Geoff Langf0aa8422015-09-29 15:08:34 -0400448 if (query.second != nullptr)
449 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400450 query.second->release(this);
Geoff Langf0aa8422015-09-29 15:08:34 -0400451 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000452 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400453 mQueryMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000454
Corentin Wallez80b24112015-08-25 16:41:57 -0400455 for (auto vertexArray : mVertexArrayMap)
Jamie Madill57a89722013-07-02 11:57:03 -0400456 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400457 if (vertexArray.second)
458 {
459 vertexArray.second->onDestroy(this);
460 }
Jamie Madill57a89722013-07-02 11:57:03 -0400461 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400462 mVertexArrayMap.clear();
Jamie Madill57a89722013-07-02 11:57:03 -0400463
Corentin Wallez80b24112015-08-25 16:41:57 -0400464 for (auto transformFeedback : mTransformFeedbackMap)
Geoff Langc8058452014-02-03 12:04:11 -0500465 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500466 if (transformFeedback.second != nullptr)
467 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500468 transformFeedback.second->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500469 }
Geoff Langc8058452014-02-03 12:04:11 -0500470 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400471 mTransformFeedbackMap.clear();
Geoff Langc8058452014-02-03 12:04:11 -0500472
Jamie Madill5b772312018-03-08 20:28:32 -0500473 for (BindingPointer<Texture> &zeroTexture : mZeroTextures)
Geoff Lang76b10c92014-09-05 16:28:14 -0400474 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800475 if (zeroTexture.get() != nullptr)
476 {
477 ANGLE_TRY(zeroTexture->onDestroy(this));
478 zeroTexture.set(this, nullptr);
479 }
Geoff Lang76b10c92014-09-05 16:28:14 -0400480 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000481
Jamie Madill2f348d22017-06-05 10:50:59 -0400482 releaseShaderCompiler();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500483
Jamie Madill4928b7c2017-06-20 12:57:39 -0400484 mGLState.reset(this);
485
Jamie Madill6c1f6712017-02-14 19:08:04 -0500486 mState.mBuffers->release(this);
487 mState.mShaderPrograms->release(this);
488 mState.mTextures->release(this);
489 mState.mRenderbuffers->release(this);
490 mState.mSamplers->release(this);
Jamie Madill70b5bb02017-08-28 13:32:37 -0400491 mState.mSyncs->release(this);
Jamie Madill6c1f6712017-02-14 19:08:04 -0500492 mState.mPaths->release(this);
493 mState.mFramebuffers->release(this);
Yunchao Hea336b902017-08-02 16:05:21 +0800494 mState.mPipelines->release(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400495
Jamie Madill76e471e2017-10-21 09:56:01 -0400496 mImplementation->onDestroy(this);
497
Jamie Madill4928b7c2017-06-20 12:57:39 -0400498 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000499}
500
Jamie Madill70ee0f62017-02-06 16:04:20 -0500501Context::~Context()
502{
503}
504
Jamie Madill4928b7c2017-06-20 12:57:39 -0400505egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000506{
Jamie Madill61e16b42017-06-19 11:13:23 -0400507 mCurrentDisplay = display;
508
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000509 if (!mHasBeenCurrent)
510 {
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000511 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500512 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400513 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000514
Corentin Wallezc295e512017-01-27 17:47:50 -0500515 int width = 0;
516 int height = 0;
517 if (surface != nullptr)
518 {
519 width = surface->getWidth();
520 height = surface->getHeight();
521 }
522
523 mGLState.setViewportParams(0, 0, width, height);
524 mGLState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000525
526 mHasBeenCurrent = true;
527 }
528
Jamie Madill1b94d432015-08-07 13:23:23 -0400529 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700530 mGLState.setAllDirtyBits();
Jamie Madill81c2e252017-09-09 23:32:46 -0400531 mGLState.setAllDirtyObjects();
Jamie Madill1b94d432015-08-07 13:23:23 -0400532
Jamie Madill4928b7c2017-06-20 12:57:39 -0400533 ANGLE_TRY(releaseSurface(display));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500534
535 Framebuffer *newDefault = nullptr;
536 if (surface != nullptr)
537 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400538 ANGLE_TRY(surface->setIsCurrent(this, true));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500539 mCurrentSurface = surface;
540 newDefault = surface->getDefaultFramebuffer();
541 }
542 else
543 {
544 if (mSurfacelessFramebuffer == nullptr)
545 {
546 mSurfacelessFramebuffer = new Framebuffer(mImplementation.get());
547 }
548
549 newDefault = mSurfacelessFramebuffer;
550 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000551
Corentin Wallez37c39792015-08-20 14:19:46 -0400552 // Update default framebuffer, the binding of the previous default
553 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400554 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700555 if (mGLState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400556 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700557 mGLState.setReadFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400558 }
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700559 if (mGLState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400560 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700561 mGLState.setDrawFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400562 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500563 mState.mFramebuffers->setDefaultFramebuffer(newDefault);
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400564 }
Ian Ewell292f0052016-02-04 10:37:32 -0500565
566 // Notify the renderer of a context switch
Jamie Madill4928b7c2017-06-20 12:57:39 -0400567 mImplementation->onMakeCurrent(this);
568 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000569}
570
Jamie Madill4928b7c2017-06-20 12:57:39 -0400571egl::Error Context::releaseSurface(const egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400572{
Corentin Wallez37c39792015-08-20 14:19:46 -0400573 // Remove the default framebuffer
Corentin Wallezc295e512017-01-27 17:47:50 -0500574 Framebuffer *currentDefault = nullptr;
575 if (mCurrentSurface != nullptr)
Corentin Wallez51706ea2015-08-07 14:39:22 -0400576 {
Corentin Wallezc295e512017-01-27 17:47:50 -0500577 currentDefault = mCurrentSurface->getDefaultFramebuffer();
578 }
579 else if (mSurfacelessFramebuffer != nullptr)
580 {
581 currentDefault = mSurfacelessFramebuffer;
Corentin Wallez51706ea2015-08-07 14:39:22 -0400582 }
583
Corentin Wallezc295e512017-01-27 17:47:50 -0500584 if (mGLState.getReadFramebuffer() == currentDefault)
585 {
586 mGLState.setReadFramebufferBinding(nullptr);
587 }
588 if (mGLState.getDrawFramebuffer() == currentDefault)
589 {
590 mGLState.setDrawFramebufferBinding(nullptr);
591 }
592 mState.mFramebuffers->setDefaultFramebuffer(nullptr);
593
594 if (mCurrentSurface)
595 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400596 ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
Corentin Wallezc295e512017-01-27 17:47:50 -0500597 mCurrentSurface = nullptr;
598 }
Jamie Madill4928b7c2017-06-20 12:57:39 -0400599
600 return egl::NoError();
Jamie Madill77a72f62015-04-14 11:18:32 -0400601}
602
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000603GLuint Context::createBuffer()
604{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500605 return mState.mBuffers->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000606}
607
608GLuint Context::createProgram()
609{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500610 return mState.mShaderPrograms->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000611}
612
Jiawei Shao385b3e02018-03-21 09:43:28 +0800613GLuint Context::createShader(ShaderType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000614{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500615 return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000616}
617
618GLuint Context::createTexture()
619{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500620 return mState.mTextures->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000621}
622
623GLuint Context::createRenderbuffer()
624{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500625 return mState.mRenderbuffers->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000626}
627
Brandon Jones59770802018-04-02 13:18:42 -0700628GLuint Context::genPaths(GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300629{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500630 auto resultOrError = mState.mPaths->createPaths(mImplementation.get(), range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300631 if (resultOrError.isError())
632 {
633 handleError(resultOrError.getError());
634 return 0;
635 }
636 return resultOrError.getResult();
637}
638
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000639// Returns an unused framebuffer name
640GLuint Context::createFramebuffer()
641{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500642 return mState.mFramebuffers->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000643}
644
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500645void Context::genFencesNV(GLsizei n, GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000646{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500647 for (int i = 0; i < n; i++)
648 {
649 GLuint handle = mFenceNVHandleAllocator.allocate();
650 mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV()));
651 fences[i] = handle;
652 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000653}
654
Yunchao Hea336b902017-08-02 16:05:21 +0800655GLuint Context::createProgramPipeline()
656{
657 return mState.mPipelines->createProgramPipeline();
658}
659
Jiawei Shao385b3e02018-03-21 09:43:28 +0800660GLuint Context::createShaderProgramv(ShaderType type, GLsizei count, const GLchar *const *strings)
Jiajia Qin5451d532017-11-16 17:16:34 +0800661{
662 UNIMPLEMENTED();
663 return 0u;
664}
665
James Darpinian4d9d4832018-03-13 12:43:28 -0700666void Context::deleteBuffer(GLuint bufferName)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000667{
James Darpinian4d9d4832018-03-13 12:43:28 -0700668 Buffer *buffer = mState.mBuffers->getBuffer(bufferName);
669 if (buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000670 {
671 detachBuffer(buffer);
672 }
Jamie Madill893ab082014-05-16 16:56:10 -0400673
James Darpinian4d9d4832018-03-13 12:43:28 -0700674 mState.mBuffers->deleteObject(this, bufferName);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000675}
676
677void Context::deleteShader(GLuint shader)
678{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500679 mState.mShaderPrograms->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000680}
681
682void Context::deleteProgram(GLuint program)
683{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500684 mState.mShaderPrograms->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000685}
686
687void Context::deleteTexture(GLuint texture)
688{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500689 if (mState.mTextures->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000690 {
691 detachTexture(texture);
692 }
693
Jamie Madill6c1f6712017-02-14 19:08:04 -0500694 mState.mTextures->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000695}
696
697void Context::deleteRenderbuffer(GLuint renderbuffer)
698{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500699 if (mState.mRenderbuffers->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000700 {
701 detachRenderbuffer(renderbuffer);
702 }
Jamie Madill893ab082014-05-16 16:56:10 -0400703
Jamie Madill6c1f6712017-02-14 19:08:04 -0500704 mState.mRenderbuffers->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000705}
706
Jamie Madill7f0c5a42017-08-26 22:43:26 -0400707void Context::deleteSync(GLsync sync)
Jamie Madillcd055f82013-07-26 11:55:15 -0400708{
709 // The spec specifies the underlying Fence object is not deleted until all current
710 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
711 // and since our API is currently designed for being called from a single thread, we can delete
712 // the fence immediately.
Jamie Madill70b5bb02017-08-28 13:32:37 -0400713 mState.mSyncs->deleteObject(this, static_cast<GLuint>(reinterpret_cast<uintptr_t>(sync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400714}
715
Yunchao Hea336b902017-08-02 16:05:21 +0800716void Context::deleteProgramPipeline(GLuint pipeline)
717{
718 if (mState.mPipelines->getProgramPipeline(pipeline))
719 {
720 detachProgramPipeline(pipeline);
721 }
722
723 mState.mPipelines->deleteObject(this, pipeline);
724}
725
Sami Väisänene45e53b2016-05-25 10:36:04 +0300726void Context::deletePaths(GLuint first, GLsizei range)
727{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500728 mState.mPaths->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300729}
730
Brandon Jones59770802018-04-02 13:18:42 -0700731bool Context::isPath(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300732{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500733 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300734 if (pathObj == nullptr)
735 return false;
736
737 return pathObj->hasPathData();
738}
739
Brandon Jones59770802018-04-02 13:18:42 -0700740bool Context::isPathGenerated(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300741{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500742 return mState.mPaths->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300743}
744
Brandon Jones59770802018-04-02 13:18:42 -0700745void Context::pathCommands(GLuint path,
746 GLsizei numCommands,
747 const GLubyte *commands,
748 GLsizei numCoords,
749 GLenum coordType,
750 const void *coords)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300751{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500752 auto *pathObject = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300753
754 handleError(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
755}
756
Jamie Madill007530e2017-12-28 14:27:04 -0500757void Context::pathParameterf(GLuint path, GLenum pname, GLfloat value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300758{
Jamie Madill007530e2017-12-28 14:27:04 -0500759 Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300760
761 switch (pname)
762 {
763 case GL_PATH_STROKE_WIDTH_CHROMIUM:
764 pathObj->setStrokeWidth(value);
765 break;
766 case GL_PATH_END_CAPS_CHROMIUM:
767 pathObj->setEndCaps(static_cast<GLenum>(value));
768 break;
769 case GL_PATH_JOIN_STYLE_CHROMIUM:
770 pathObj->setJoinStyle(static_cast<GLenum>(value));
771 break;
772 case GL_PATH_MITER_LIMIT_CHROMIUM:
773 pathObj->setMiterLimit(value);
774 break;
775 case GL_PATH_STROKE_BOUND_CHROMIUM:
776 pathObj->setStrokeBound(value);
777 break;
778 default:
779 UNREACHABLE();
780 break;
781 }
782}
783
Jamie Madill007530e2017-12-28 14:27:04 -0500784void Context::pathParameteri(GLuint path, GLenum pname, GLint value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300785{
Jamie Madill007530e2017-12-28 14:27:04 -0500786 // TODO(jmadill): Should use proper clamping/casting.
787 pathParameterf(path, pname, static_cast<GLfloat>(value));
788}
789
790void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value)
791{
792 const Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300793
794 switch (pname)
795 {
796 case GL_PATH_STROKE_WIDTH_CHROMIUM:
797 *value = pathObj->getStrokeWidth();
798 break;
799 case GL_PATH_END_CAPS_CHROMIUM:
800 *value = static_cast<GLfloat>(pathObj->getEndCaps());
801 break;
802 case GL_PATH_JOIN_STYLE_CHROMIUM:
803 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
804 break;
805 case GL_PATH_MITER_LIMIT_CHROMIUM:
806 *value = pathObj->getMiterLimit();
807 break;
808 case GL_PATH_STROKE_BOUND_CHROMIUM:
809 *value = pathObj->getStrokeBound();
810 break;
811 default:
812 UNREACHABLE();
813 break;
814 }
815}
816
Jamie Madill007530e2017-12-28 14:27:04 -0500817void Context::getPathParameteriv(GLuint path, GLenum pname, GLint *value)
818{
819 GLfloat val = 0.0f;
820 getPathParameterfv(path, pname, value != nullptr ? &val : nullptr);
821 if (value)
822 *value = static_cast<GLint>(val);
823}
824
Brandon Jones59770802018-04-02 13:18:42 -0700825void Context::pathStencilFunc(GLenum func, GLint ref, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300826{
827 mGLState.setPathStencilFunc(func, ref, mask);
828}
829
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000830void Context::deleteFramebuffer(GLuint framebuffer)
831{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500832 if (mState.mFramebuffers->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000833 {
834 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000835 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500836
Jamie Madill6c1f6712017-02-14 19:08:04 -0500837 mState.mFramebuffers->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000838}
839
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500840void Context::deleteFencesNV(GLsizei n, const GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000841{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500842 for (int i = 0; i < n; i++)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000843 {
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500844 GLuint fence = fences[i];
845
846 FenceNV *fenceObject = nullptr;
847 if (mFenceNVMap.erase(fence, &fenceObject))
848 {
849 mFenceNVHandleAllocator.release(fence);
850 delete fenceObject;
851 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000852 }
853}
854
Geoff Lang70d0f492015-12-10 17:45:46 -0500855Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000856{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500857 return mState.mBuffers->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000858}
859
Jamie Madill570f7c82014-07-03 10:38:54 -0400860Texture *Context::getTexture(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000861{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500862 return mState.mTextures->getTexture(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000863}
864
Geoff Lang70d0f492015-12-10 17:45:46 -0500865Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000866{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500867 return mState.mRenderbuffers->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000868}
869
Jamie Madill70b5bb02017-08-28 13:32:37 -0400870Sync *Context::getSync(GLsync handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400871{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400872 return mState.mSyncs->getSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400873}
874
Jamie Madill57a89722013-07-02 11:57:03 -0400875VertexArray *Context::getVertexArray(GLuint handle) const
876{
Jamie Madill96a483b2017-06-27 16:49:21 -0400877 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -0400878}
879
Jamie Madilldc356042013-07-19 16:36:57 -0400880Sampler *Context::getSampler(GLuint handle) const
881{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500882 return mState.mSamplers->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400883}
884
Geoff Langc8058452014-02-03 12:04:11 -0500885TransformFeedback *Context::getTransformFeedback(GLuint handle) const
886{
Jamie Madill96a483b2017-06-27 16:49:21 -0400887 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -0500888}
889
Yunchao Hea336b902017-08-02 16:05:21 +0800890ProgramPipeline *Context::getProgramPipeline(GLuint handle) const
891{
892 return mState.mPipelines->getProgramPipeline(handle);
893}
894
Geoff Lang70d0f492015-12-10 17:45:46 -0500895LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
896{
897 switch (identifier)
898 {
899 case GL_BUFFER:
900 return getBuffer(name);
901 case GL_SHADER:
902 return getShader(name);
903 case GL_PROGRAM:
904 return getProgram(name);
905 case GL_VERTEX_ARRAY:
906 return getVertexArray(name);
907 case GL_QUERY:
908 return getQuery(name);
909 case GL_TRANSFORM_FEEDBACK:
910 return getTransformFeedback(name);
911 case GL_SAMPLER:
912 return getSampler(name);
913 case GL_TEXTURE:
914 return getTexture(name);
915 case GL_RENDERBUFFER:
916 return getRenderbuffer(name);
917 case GL_FRAMEBUFFER:
918 return getFramebuffer(name);
919 default:
920 UNREACHABLE();
921 return nullptr;
922 }
923}
924
925LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
926{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400927 return getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
Geoff Lang70d0f492015-12-10 17:45:46 -0500928}
929
Martin Radev9d901792016-07-15 15:58:58 +0300930void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
931{
932 LabeledObject *object = getLabeledObject(identifier, name);
933 ASSERT(object != nullptr);
934
935 std::string labelName = GetObjectLabelFromPointer(length, label);
936 object->setLabel(labelName);
Jamie Madill8693bdb2017-09-02 15:32:14 -0400937
938 // TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the
939 // specified object is active until we do this.
940 mGLState.setObjectDirty(identifier);
Martin Radev9d901792016-07-15 15:58:58 +0300941}
942
943void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
944{
945 LabeledObject *object = getLabeledObjectFromPtr(ptr);
946 ASSERT(object != nullptr);
947
948 std::string labelName = GetObjectLabelFromPointer(length, label);
949 object->setLabel(labelName);
950}
951
952void Context::getObjectLabel(GLenum identifier,
953 GLuint name,
954 GLsizei bufSize,
955 GLsizei *length,
956 GLchar *label) const
957{
958 LabeledObject *object = getLabeledObject(identifier, name);
959 ASSERT(object != nullptr);
960
961 const std::string &objectLabel = object->getLabel();
962 GetObjectLabelBase(objectLabel, bufSize, length, label);
963}
964
965void Context::getObjectPtrLabel(const void *ptr,
966 GLsizei bufSize,
967 GLsizei *length,
968 GLchar *label) const
969{
970 LabeledObject *object = getLabeledObjectFromPtr(ptr);
971 ASSERT(object != nullptr);
972
973 const std::string &objectLabel = object->getLabel();
974 GetObjectLabelBase(objectLabel, bufSize, length, label);
975}
976
Jamie Madilldc356042013-07-19 16:36:57 -0400977bool Context::isSampler(GLuint samplerName) const
978{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500979 return mState.mSamplers->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -0400980}
981
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800982void Context::bindTexture(TextureType target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000983{
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500984 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000985
Jamie Madilldedd7b92014-11-05 16:30:36 -0500986 if (handle == 0)
987 {
988 texture = mZeroTextures[target].get();
989 }
990 else
991 {
Corentin Wallez99d492c2018-02-27 15:17:10 -0500992 texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500993 }
994
995 ASSERT(texture);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400996 mGLState.setSamplerTexture(this, target, texture);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +0000997}
998
Jamie Madill5bf9ff42016-02-01 11:13:03 -0500999void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001000{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001001 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1002 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001003 mGLState.setReadFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001004}
1005
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001006void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001007{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001008 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1009 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001010 mGLState.setDrawFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001011}
1012
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001013void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -04001014{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001015 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001016 mGLState.setVertexArrayBinding(vertexArray);
Jamie Madill57a89722013-07-02 11:57:03 -04001017}
1018
Shao80957d92017-02-20 21:25:59 +08001019void Context::bindVertexBuffer(GLuint bindingIndex,
1020 GLuint bufferHandle,
1021 GLintptr offset,
1022 GLsizei stride)
1023{
1024 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001025 mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Shao80957d92017-02-20 21:25:59 +08001026}
1027
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001028void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -04001029{
Geoff Lang76b10c92014-09-05 16:28:14 -04001030 ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -04001031 Sampler *sampler =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001032 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001033 mGLState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04001034}
1035
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001036void Context::bindImageTexture(GLuint unit,
1037 GLuint texture,
1038 GLint level,
1039 GLboolean layered,
1040 GLint layer,
1041 GLenum access,
1042 GLenum format)
1043{
1044 Texture *tex = mState.mTextures->getTexture(texture);
1045 mGLState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
1046}
1047
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001048void Context::useProgram(GLuint program)
1049{
Jamie Madill6c1f6712017-02-14 19:08:04 -05001050 mGLState.setProgram(this, getProgram(program));
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001051}
1052
Jiajia Qin5451d532017-11-16 17:16:34 +08001053void Context::useProgramStages(GLuint pipeline, GLbitfield stages, GLuint program)
1054{
1055 UNIMPLEMENTED();
1056}
1057
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001058void Context::bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001059{
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001060 ASSERT(target == GL_TRANSFORM_FEEDBACK);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001061 TransformFeedback *transformFeedback =
1062 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001063 mGLState.setTransformFeedbackBinding(this, transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -05001064}
1065
Yunchao Hea336b902017-08-02 16:05:21 +08001066void Context::bindProgramPipeline(GLuint pipelineHandle)
1067{
1068 ProgramPipeline *pipeline =
1069 mState.mPipelines->checkProgramPipelineAllocation(mImplementation.get(), pipelineHandle);
1070 mGLState.setProgramPipelineBinding(this, pipeline);
1071}
1072
Jamie Madillf0e04492017-08-26 15:28:42 -04001073void Context::beginQuery(GLenum target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001074{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001075 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001076 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001077
Geoff Lang5aad9672014-09-08 11:10:42 -04001078 // begin query
Jamie Madillf0e04492017-08-26 15:28:42 -04001079 ANGLE_CONTEXT_TRY(queryObject->begin());
Geoff Lang5aad9672014-09-08 11:10:42 -04001080
1081 // set query as active for specified target only if begin succeeded
Jamie Madill4928b7c2017-06-20 12:57:39 -04001082 mGLState.setActiveQuery(this, target, queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001083}
1084
Jamie Madillf0e04492017-08-26 15:28:42 -04001085void Context::endQuery(GLenum target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001086{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001087 Query *queryObject = mGLState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001088 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001089
Jamie Madillf0e04492017-08-26 15:28:42 -04001090 handleError(queryObject->end());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001091
Geoff Lang5aad9672014-09-08 11:10:42 -04001092 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madill4928b7c2017-06-20 12:57:39 -04001093 mGLState.setActiveQuery(this, target, nullptr);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001094}
1095
Jamie Madillf0e04492017-08-26 15:28:42 -04001096void Context::queryCounter(GLuint id, GLenum target)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001097{
1098 ASSERT(target == GL_TIMESTAMP_EXT);
1099
1100 Query *queryObject = getQuery(id, true, target);
1101 ASSERT(queryObject);
1102
Jamie Madillf0e04492017-08-26 15:28:42 -04001103 handleError(queryObject->queryCounter());
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001104}
1105
1106void Context::getQueryiv(GLenum target, GLenum pname, GLint *params)
1107{
1108 switch (pname)
1109 {
1110 case GL_CURRENT_QUERY_EXT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001111 params[0] = mGLState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001112 break;
1113 case GL_QUERY_COUNTER_BITS_EXT:
1114 switch (target)
1115 {
1116 case GL_TIME_ELAPSED_EXT:
1117 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1118 break;
1119 case GL_TIMESTAMP_EXT:
1120 params[0] = getExtensions().queryCounterBitsTimestamp;
1121 break;
1122 default:
1123 UNREACHABLE();
1124 params[0] = 0;
1125 break;
1126 }
1127 break;
1128 default:
1129 UNREACHABLE();
1130 return;
1131 }
1132}
1133
Brandon Jones59770802018-04-02 13:18:42 -07001134void Context::getQueryivRobust(GLenum target,
1135 GLenum pname,
1136 GLsizei bufSize,
1137 GLsizei *length,
1138 GLint *params)
1139{
1140 getQueryiv(target, pname, params);
1141}
1142
Geoff Lang2186c382016-10-14 10:54:54 -04001143void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *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
Brandon Jones59770802018-04-02 13:18:42 -07001148void Context::getQueryObjectivRobust(GLuint id,
1149 GLenum pname,
1150 GLsizei bufSize,
1151 GLsizei *length,
1152 GLint *params)
1153{
1154 getQueryObjectiv(id, pname, params);
1155}
1156
Geoff Lang2186c382016-10-14 10:54:54 -04001157void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001158{
Geoff Lang2186c382016-10-14 10:54:54 -04001159 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001160}
1161
Brandon Jones59770802018-04-02 13:18:42 -07001162void Context::getQueryObjectuivRobust(GLuint id,
1163 GLenum pname,
1164 GLsizei bufSize,
1165 GLsizei *length,
1166 GLuint *params)
1167{
1168 getQueryObjectuiv(id, pname, params);
1169}
1170
Geoff Lang2186c382016-10-14 10:54:54 -04001171void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001172{
Geoff Lang2186c382016-10-14 10:54:54 -04001173 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001174}
1175
Brandon Jones59770802018-04-02 13:18:42 -07001176void Context::getQueryObjecti64vRobust(GLuint id,
1177 GLenum pname,
1178 GLsizei bufSize,
1179 GLsizei *length,
1180 GLint64 *params)
1181{
1182 getQueryObjecti64v(id, pname, params);
1183}
1184
Geoff Lang2186c382016-10-14 10:54:54 -04001185void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001186{
Geoff Lang2186c382016-10-14 10:54:54 -04001187 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001188}
1189
Brandon Jones59770802018-04-02 13:18:42 -07001190void Context::getQueryObjectui64vRobust(GLuint id,
1191 GLenum pname,
1192 GLsizei bufSize,
1193 GLsizei *length,
1194 GLuint64 *params)
1195{
1196 getQueryObjectui64v(id, pname, params);
1197}
1198
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001199Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001200{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001201 return mState.mFramebuffers->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001202}
1203
Jamie Madill2f348d22017-06-05 10:50:59 -04001204FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001205{
Jamie Madill96a483b2017-06-27 16:49:21 -04001206 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001207}
1208
Jamie Madill2f348d22017-06-05 10:50:59 -04001209Query *Context::getQuery(GLuint handle, bool create, GLenum type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001210{
Jamie Madill96a483b2017-06-27 16:49:21 -04001211 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001212 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001213 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001214 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001215
1216 Query *query = mQueryMap.query(handle);
1217 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001218 {
Jamie Madill96a483b2017-06-27 16:49:21 -04001219 query = new Query(mImplementation->createQuery(type), handle);
1220 query->addRef();
1221 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001222 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001223 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001224}
1225
Geoff Lang70d0f492015-12-10 17:45:46 -05001226Query *Context::getQuery(GLuint handle) const
1227{
Jamie Madill96a483b2017-06-27 16:49:21 -04001228 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001229}
1230
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001231Texture *Context::getTargetTexture(TextureType type) const
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001232{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001233 ASSERT(ValidTextureTarget(this, type) || ValidTextureExternalTarget(this, type));
1234 return mGLState.getTargetTexture(type);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001235}
1236
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001237Texture *Context::getSamplerTexture(unsigned int sampler, TextureType type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001238{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001239 return mGLState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001240}
1241
Geoff Lang492a7e42014-11-05 13:27:06 -05001242Compiler *Context::getCompiler() const
1243{
Jamie Madill2f348d22017-06-05 10:50:59 -04001244 if (mCompiler.get() == nullptr)
1245 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001246 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001247 }
1248 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001249}
1250
Jamie Madillc1d770e2017-04-13 17:31:24 -04001251void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001252{
1253 switch (pname)
1254 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001255 case GL_SHADER_COMPILER:
1256 *params = GL_TRUE;
1257 break;
1258 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1259 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1260 break;
1261 default:
1262 mGLState.getBooleanv(pname, params);
1263 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001264 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001265}
1266
Jamie Madillc1d770e2017-04-13 17:31:24 -04001267void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001268{
Shannon Woods53a94a82014-06-24 15:20:36 -04001269 // Queries about context capabilities and maximums are answered by Context.
1270 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001271 switch (pname)
1272 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001273 case GL_ALIASED_LINE_WIDTH_RANGE:
1274 params[0] = mCaps.minAliasedLineWidth;
1275 params[1] = mCaps.maxAliasedLineWidth;
1276 break;
1277 case GL_ALIASED_POINT_SIZE_RANGE:
1278 params[0] = mCaps.minAliasedPointSize;
1279 params[1] = mCaps.maxAliasedPointSize;
1280 break;
1281 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1282 ASSERT(mExtensions.textureFilterAnisotropic);
1283 *params = mExtensions.maxTextureAnisotropy;
1284 break;
1285 case GL_MAX_TEXTURE_LOD_BIAS:
1286 *params = mCaps.maxLODBias;
1287 break;
1288
1289 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1290 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1291 {
Lingfeng Yang3a41af62018-04-09 07:28:56 -07001292 // GLES1 emulation: // GL_PATH_(MODELVIEW|PROJECTION)_MATRIX_CHROMIUM collides with the
1293 // GLES1 constants for modelview/projection matrix.
1294 if (getClientVersion() < Version(2, 0))
1295 {
1296 mGLState.getFloatv(pname, params);
1297 }
1298 else
1299 {
1300 ASSERT(mExtensions.pathRendering);
1301 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1302 memcpy(params, m, 16 * sizeof(GLfloat));
1303 }
Jamie Madill231c7f52017-04-26 13:45:37 -04001304 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001305 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001306
Jamie Madill231c7f52017-04-26 13:45:37 -04001307 default:
1308 mGLState.getFloatv(pname, params);
1309 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001310 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001311}
1312
Jamie Madillc1d770e2017-04-13 17:31:24 -04001313void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001314{
Shannon Woods53a94a82014-06-24 15:20:36 -04001315 // Queries about context capabilities and maximums are answered by Context.
1316 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001317
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001318 switch (pname)
1319 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001320 case GL_MAX_VERTEX_ATTRIBS:
1321 *params = mCaps.maxVertexAttributes;
1322 break;
1323 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1324 *params = mCaps.maxVertexUniformVectors;
1325 break;
1326 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
1327 *params = mCaps.maxVertexUniformComponents;
1328 break;
1329 case GL_MAX_VARYING_VECTORS:
1330 *params = mCaps.maxVaryingVectors;
1331 break;
1332 case GL_MAX_VARYING_COMPONENTS:
1333 *params = mCaps.maxVertexOutputComponents;
1334 break;
1335 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1336 *params = mCaps.maxCombinedTextureImageUnits;
1337 break;
1338 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
1339 *params = mCaps.maxVertexTextureImageUnits;
1340 break;
1341 case GL_MAX_TEXTURE_IMAGE_UNITS:
1342 *params = mCaps.maxTextureImageUnits;
1343 break;
1344 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1345 *params = mCaps.maxFragmentUniformVectors;
1346 break;
1347 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
1348 *params = mCaps.maxFragmentUniformComponents;
1349 break;
1350 case GL_MAX_RENDERBUFFER_SIZE:
1351 *params = mCaps.maxRenderbufferSize;
1352 break;
1353 case GL_MAX_COLOR_ATTACHMENTS_EXT:
1354 *params = mCaps.maxColorAttachments;
1355 break;
1356 case GL_MAX_DRAW_BUFFERS_EXT:
1357 *params = mCaps.maxDrawBuffers;
1358 break;
1359 // case GL_FRAMEBUFFER_BINDING: // now equivalent to
1360 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
1361 case GL_SUBPIXEL_BITS:
1362 *params = 4;
1363 break;
1364 case GL_MAX_TEXTURE_SIZE:
1365 *params = mCaps.max2DTextureSize;
1366 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001367 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
1368 *params = mCaps.maxRectangleTextureSize;
1369 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001370 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1371 *params = mCaps.maxCubeMapTextureSize;
1372 break;
1373 case GL_MAX_3D_TEXTURE_SIZE:
1374 *params = mCaps.max3DTextureSize;
1375 break;
1376 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1377 *params = mCaps.maxArrayTextureLayers;
1378 break;
1379 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1380 *params = mCaps.uniformBufferOffsetAlignment;
1381 break;
1382 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1383 *params = mCaps.maxUniformBufferBindings;
1384 break;
1385 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
1386 *params = mCaps.maxVertexUniformBlocks;
1387 break;
1388 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
1389 *params = mCaps.maxFragmentUniformBlocks;
1390 break;
1391 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1392 *params = mCaps.maxCombinedTextureImageUnits;
1393 break;
1394 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1395 *params = mCaps.maxVertexOutputComponents;
1396 break;
1397 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1398 *params = mCaps.maxFragmentInputComponents;
1399 break;
1400 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1401 *params = mCaps.minProgramTexelOffset;
1402 break;
1403 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1404 *params = mCaps.maxProgramTexelOffset;
1405 break;
1406 case GL_MAJOR_VERSION:
1407 *params = getClientVersion().major;
1408 break;
1409 case GL_MINOR_VERSION:
1410 *params = getClientVersion().minor;
1411 break;
1412 case GL_MAX_ELEMENTS_INDICES:
1413 *params = mCaps.maxElementsIndices;
1414 break;
1415 case GL_MAX_ELEMENTS_VERTICES:
1416 *params = mCaps.maxElementsVertices;
1417 break;
1418 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1419 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1420 break;
1421 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1422 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1423 break;
1424 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1425 *params = mCaps.maxTransformFeedbackSeparateComponents;
1426 break;
1427 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1428 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1429 break;
1430 case GL_MAX_SAMPLES_ANGLE:
1431 *params = mCaps.maxSamples;
1432 break;
1433 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001434 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001435 params[0] = mCaps.maxViewportWidth;
1436 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001437 }
1438 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001439 case GL_COMPRESSED_TEXTURE_FORMATS:
1440 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1441 params);
1442 break;
1443 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1444 *params = mResetStrategy;
1445 break;
1446 case GL_NUM_SHADER_BINARY_FORMATS:
1447 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1448 break;
1449 case GL_SHADER_BINARY_FORMATS:
1450 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1451 break;
1452 case GL_NUM_PROGRAM_BINARY_FORMATS:
1453 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1454 break;
1455 case GL_PROGRAM_BINARY_FORMATS:
1456 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1457 break;
1458 case GL_NUM_EXTENSIONS:
1459 *params = static_cast<GLint>(mExtensionStrings.size());
1460 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001461
Jamie Madill231c7f52017-04-26 13:45:37 -04001462 // GL_KHR_debug
1463 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1464 *params = mExtensions.maxDebugMessageLength;
1465 break;
1466 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1467 *params = mExtensions.maxDebugLoggedMessages;
1468 break;
1469 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1470 *params = mExtensions.maxDebugGroupStackDepth;
1471 break;
1472 case GL_MAX_LABEL_LENGTH:
1473 *params = mExtensions.maxLabelLength;
1474 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001475
Martin Radeve5285d22017-07-14 16:23:53 +03001476 // GL_ANGLE_multiview
1477 case GL_MAX_VIEWS_ANGLE:
1478 *params = mExtensions.maxViews;
1479 break;
1480
Jamie Madill231c7f52017-04-26 13:45:37 -04001481 // GL_EXT_disjoint_timer_query
1482 case GL_GPU_DISJOINT_EXT:
1483 *params = mImplementation->getGPUDisjoint();
1484 break;
1485 case GL_MAX_FRAMEBUFFER_WIDTH:
1486 *params = mCaps.maxFramebufferWidth;
1487 break;
1488 case GL_MAX_FRAMEBUFFER_HEIGHT:
1489 *params = mCaps.maxFramebufferHeight;
1490 break;
1491 case GL_MAX_FRAMEBUFFER_SAMPLES:
1492 *params = mCaps.maxFramebufferSamples;
1493 break;
1494 case GL_MAX_SAMPLE_MASK_WORDS:
1495 *params = mCaps.maxSampleMaskWords;
1496 break;
1497 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1498 *params = mCaps.maxColorTextureSamples;
1499 break;
1500 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1501 *params = mCaps.maxDepthTextureSamples;
1502 break;
1503 case GL_MAX_INTEGER_SAMPLES:
1504 *params = mCaps.maxIntegerSamples;
1505 break;
1506 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1507 *params = mCaps.maxVertexAttribRelativeOffset;
1508 break;
1509 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1510 *params = mCaps.maxVertexAttribBindings;
1511 break;
1512 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1513 *params = mCaps.maxVertexAttribStride;
1514 break;
1515 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
1516 *params = mCaps.maxVertexAtomicCounterBuffers;
1517 break;
1518 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
1519 *params = mCaps.maxVertexAtomicCounters;
1520 break;
1521 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
1522 *params = mCaps.maxVertexImageUniforms;
1523 break;
1524 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
1525 *params = mCaps.maxVertexShaderStorageBlocks;
1526 break;
1527 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
1528 *params = mCaps.maxFragmentAtomicCounterBuffers;
1529 break;
1530 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
1531 *params = mCaps.maxFragmentAtomicCounters;
1532 break;
1533 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
1534 *params = mCaps.maxFragmentImageUniforms;
1535 break;
1536 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
1537 *params = mCaps.maxFragmentShaderStorageBlocks;
1538 break;
1539 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1540 *params = mCaps.minProgramTextureGatherOffset;
1541 break;
1542 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1543 *params = mCaps.maxProgramTextureGatherOffset;
1544 break;
1545 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1546 *params = mCaps.maxComputeWorkGroupInvocations;
1547 break;
1548 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
1549 *params = mCaps.maxComputeUniformBlocks;
1550 break;
1551 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
1552 *params = mCaps.maxComputeTextureImageUnits;
1553 break;
1554 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1555 *params = mCaps.maxComputeSharedMemorySize;
1556 break;
1557 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
1558 *params = mCaps.maxComputeUniformComponents;
1559 break;
1560 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
1561 *params = mCaps.maxComputeAtomicCounterBuffers;
1562 break;
1563 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
1564 *params = mCaps.maxComputeAtomicCounters;
1565 break;
1566 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
1567 *params = mCaps.maxComputeImageUniforms;
1568 break;
1569 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
1570 *params = mCaps.maxCombinedComputeUniformComponents;
1571 break;
1572 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
1573 *params = mCaps.maxComputeShaderStorageBlocks;
1574 break;
1575 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1576 *params = mCaps.maxCombinedShaderOutputResources;
1577 break;
1578 case GL_MAX_UNIFORM_LOCATIONS:
1579 *params = mCaps.maxUniformLocations;
1580 break;
1581 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1582 *params = mCaps.maxAtomicCounterBufferBindings;
1583 break;
1584 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1585 *params = mCaps.maxAtomicCounterBufferSize;
1586 break;
1587 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1588 *params = mCaps.maxCombinedAtomicCounterBuffers;
1589 break;
1590 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1591 *params = mCaps.maxCombinedAtomicCounters;
1592 break;
1593 case GL_MAX_IMAGE_UNITS:
1594 *params = mCaps.maxImageUnits;
1595 break;
1596 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1597 *params = mCaps.maxCombinedImageUniforms;
1598 break;
1599 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1600 *params = mCaps.maxShaderStorageBufferBindings;
1601 break;
1602 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1603 *params = mCaps.maxCombinedShaderStorageBlocks;
1604 break;
1605 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1606 *params = mCaps.shaderStorageBufferOffsetAlignment;
1607 break;
Jiawei Shao361df072017-11-22 09:33:59 +08001608
1609 // GL_EXT_geometry_shader
1610 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
1611 *params = mCaps.maxFramebufferLayers;
1612 break;
1613 case GL_LAYER_PROVOKING_VERTEX_EXT:
1614 *params = mCaps.layerProvokingVertex;
1615 break;
1616 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
1617 *params = mCaps.maxGeometryUniformComponents;
1618 break;
1619 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
1620 *params = mCaps.maxGeometryUniformBlocks;
1621 break;
1622 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
1623 *params = mCaps.maxCombinedGeometryUniformComponents;
1624 break;
1625 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
1626 *params = mCaps.maxGeometryInputComponents;
1627 break;
1628 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
1629 *params = mCaps.maxGeometryOutputComponents;
1630 break;
1631 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
1632 *params = mCaps.maxGeometryOutputVertices;
1633 break;
1634 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
1635 *params = mCaps.maxGeometryTotalOutputComponents;
1636 break;
1637 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
1638 *params = mCaps.maxGeometryShaderInvocations;
1639 break;
1640 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
1641 *params = mCaps.maxGeometryTextureImageUnits;
1642 break;
1643 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
1644 *params = mCaps.maxGeometryAtomicCounterBuffers;
1645 break;
1646 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
1647 *params = mCaps.maxGeometryAtomicCounters;
1648 break;
1649 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
1650 *params = mCaps.maxGeometryImageUniforms;
1651 break;
1652 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
1653 *params = mCaps.maxGeometryShaderStorageBlocks;
1654 break;
Lingfeng Yang96310cd2018-03-28 11:56:28 -07001655 // GLES1 emulation: Caps queries
1656 case GL_MAX_TEXTURE_UNITS:
1657 *params = mCaps.maxMultitextureUnits;
1658 break;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001659 case GL_MAX_MODELVIEW_STACK_DEPTH:
1660 *params = mCaps.maxModelviewMatrixStackDepth;
1661 break;
1662 case GL_MAX_PROJECTION_STACK_DEPTH:
1663 *params = mCaps.maxProjectionMatrixStackDepth;
1664 break;
1665 case GL_MAX_TEXTURE_STACK_DEPTH:
1666 *params = mCaps.maxTextureMatrixStackDepth;
1667 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001668 default:
Jamie Madille98b1b52018-03-08 09:47:23 -05001669 handleError(mGLState.getIntegerv(this, pname, params));
Jamie Madill231c7f52017-04-26 13:45:37 -04001670 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001671 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001672}
1673
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001674void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001675{
Shannon Woods53a94a82014-06-24 15:20:36 -04001676 // Queries about context capabilities and maximums are answered by Context.
1677 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001678 switch (pname)
1679 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001680 case GL_MAX_ELEMENT_INDEX:
1681 *params = mCaps.maxElementIndex;
1682 break;
1683 case GL_MAX_UNIFORM_BLOCK_SIZE:
1684 *params = mCaps.maxUniformBlockSize;
1685 break;
1686 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
1687 *params = mCaps.maxCombinedVertexUniformComponents;
1688 break;
1689 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
1690 *params = mCaps.maxCombinedFragmentUniformComponents;
1691 break;
1692 case GL_MAX_SERVER_WAIT_TIMEOUT:
1693 *params = mCaps.maxServerWaitTimeout;
1694 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001695
Jamie Madill231c7f52017-04-26 13:45:37 -04001696 // GL_EXT_disjoint_timer_query
1697 case GL_TIMESTAMP_EXT:
1698 *params = mImplementation->getTimestamp();
1699 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001700
Jamie Madill231c7f52017-04-26 13:45:37 -04001701 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1702 *params = mCaps.maxShaderStorageBlockSize;
1703 break;
1704 default:
1705 UNREACHABLE();
1706 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001707 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001708}
1709
Geoff Lang70d0f492015-12-10 17:45:46 -05001710void Context::getPointerv(GLenum pname, void **params) const
1711{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001712 mGLState.getPointerv(pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001713}
1714
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001715void Context::getPointervRobustANGLERobust(GLenum pname,
1716 GLsizei bufSize,
1717 GLsizei *length,
1718 void **params)
1719{
1720 UNIMPLEMENTED();
1721}
1722
Martin Radev66fb8202016-07-28 11:45:20 +03001723void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001724{
Shannon Woods53a94a82014-06-24 15:20:36 -04001725 // Queries about context capabilities and maximums are answered by Context.
1726 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001727
1728 GLenum nativeType;
1729 unsigned int numParams;
1730 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1731 ASSERT(queryStatus);
1732
1733 if (nativeType == GL_INT)
1734 {
1735 switch (target)
1736 {
1737 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1738 ASSERT(index < 3u);
1739 *data = mCaps.maxComputeWorkGroupCount[index];
1740 break;
1741 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1742 ASSERT(index < 3u);
1743 *data = mCaps.maxComputeWorkGroupSize[index];
1744 break;
1745 default:
1746 mGLState.getIntegeri_v(target, index, data);
1747 }
1748 }
1749 else
1750 {
1751 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1752 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001753}
1754
Brandon Jones59770802018-04-02 13:18:42 -07001755void Context::getIntegeri_vRobust(GLenum target,
1756 GLuint index,
1757 GLsizei bufSize,
1758 GLsizei *length,
1759 GLint *data)
1760{
1761 getIntegeri_v(target, index, data);
1762}
1763
Martin Radev66fb8202016-07-28 11:45:20 +03001764void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001765{
Shannon Woods53a94a82014-06-24 15:20:36 -04001766 // Queries about context capabilities and maximums are answered by Context.
1767 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001768
1769 GLenum nativeType;
1770 unsigned int numParams;
1771 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1772 ASSERT(queryStatus);
1773
1774 if (nativeType == GL_INT_64_ANGLEX)
1775 {
1776 mGLState.getInteger64i_v(target, index, data);
1777 }
1778 else
1779 {
1780 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1781 }
1782}
1783
Brandon Jones59770802018-04-02 13:18:42 -07001784void Context::getInteger64i_vRobust(GLenum target,
1785 GLuint index,
1786 GLsizei bufSize,
1787 GLsizei *length,
1788 GLint64 *data)
1789{
1790 getInteger64i_v(target, index, data);
1791}
1792
Martin Radev66fb8202016-07-28 11:45:20 +03001793void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1794{
1795 // Queries about context capabilities and maximums are answered by Context.
1796 // Queries about current GL state values are answered by State.
1797
1798 GLenum nativeType;
1799 unsigned int numParams;
1800 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1801 ASSERT(queryStatus);
1802
1803 if (nativeType == GL_BOOL)
1804 {
1805 mGLState.getBooleani_v(target, index, data);
1806 }
1807 else
1808 {
1809 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1810 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001811}
1812
Brandon Jones59770802018-04-02 13:18:42 -07001813void Context::getBooleani_vRobust(GLenum target,
1814 GLuint index,
1815 GLsizei bufSize,
1816 GLsizei *length,
1817 GLboolean *data)
1818{
1819 getBooleani_v(target, index, data);
1820}
1821
Corentin Wallez336129f2017-10-17 15:55:40 -04001822void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001823{
1824 Buffer *buffer = mGLState.getTargetBuffer(target);
1825 QueryBufferParameteriv(buffer, pname, params);
1826}
1827
Brandon Jones59770802018-04-02 13:18:42 -07001828void Context::getBufferParameterivRobust(BufferBinding target,
1829 GLenum pname,
1830 GLsizei bufSize,
1831 GLsizei *length,
1832 GLint *params)
1833{
1834 getBufferParameteriv(target, pname, params);
1835}
1836
He Yunchao010e4db2017-03-03 14:22:06 +08001837void Context::getFramebufferAttachmentParameteriv(GLenum target,
1838 GLenum attachment,
1839 GLenum pname,
1840 GLint *params)
1841{
1842 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08001843 QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08001844}
1845
Brandon Jones59770802018-04-02 13:18:42 -07001846void Context::getFramebufferAttachmentParameterivRobust(GLenum target,
1847 GLenum attachment,
1848 GLenum pname,
1849 GLsizei bufSize,
1850 GLsizei *length,
1851 GLint *params)
1852{
1853 getFramebufferAttachmentParameteriv(target, attachment, pname, params);
1854}
1855
He Yunchao010e4db2017-03-03 14:22:06 +08001856void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
1857{
1858 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
1859 QueryRenderbufferiv(this, renderbuffer, pname, params);
1860}
1861
Brandon Jones59770802018-04-02 13:18:42 -07001862void Context::getRenderbufferParameterivRobust(GLenum target,
1863 GLenum pname,
1864 GLsizei bufSize,
1865 GLsizei *length,
1866 GLint *params)
1867{
1868 getRenderbufferParameteriv(target, pname, params);
1869}
1870
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001871void Context::getTexParameterfv(TextureType target, GLenum pname, GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001872{
1873 Texture *texture = getTargetTexture(target);
1874 QueryTexParameterfv(texture, pname, params);
1875}
1876
Brandon Jones59770802018-04-02 13:18:42 -07001877void Context::getTexParameterfvRobust(TextureType target,
1878 GLenum pname,
1879 GLsizei bufSize,
1880 GLsizei *length,
1881 GLfloat *params)
1882{
1883 getTexParameterfv(target, pname, params);
1884}
1885
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001886void Context::getTexParameteriv(TextureType target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001887{
1888 Texture *texture = getTargetTexture(target);
1889 QueryTexParameteriv(texture, pname, params);
1890}
Jiajia Qin5451d532017-11-16 17:16:34 +08001891
Brandon Jones59770802018-04-02 13:18:42 -07001892void Context::getTexParameterivRobust(TextureType target,
1893 GLenum pname,
1894 GLsizei bufSize,
1895 GLsizei *length,
1896 GLint *params)
1897{
1898 getTexParameteriv(target, pname, params);
1899}
1900
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001901void Context::getTexParameterIivRobust(TextureType target,
1902 GLenum pname,
1903 GLsizei bufSize,
1904 GLsizei *length,
1905 GLint *params)
1906{
1907 UNIMPLEMENTED();
1908}
1909
1910void Context::getTexParameterIuivRobust(TextureType target,
1911 GLenum pname,
1912 GLsizei bufSize,
1913 GLsizei *length,
1914 GLuint *params)
1915{
1916 UNIMPLEMENTED();
1917}
1918
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001919void Context::getTexLevelParameteriv(TextureTarget target, GLint level, GLenum pname, GLint *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08001920{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001921 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05001922 QueryTexLevelParameteriv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08001923}
1924
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001925void Context::getTexLevelParameterivRobust(TextureTarget target,
1926 GLint level,
1927 GLenum pname,
1928 GLsizei bufSize,
1929 GLsizei *length,
1930 GLint *params)
1931{
1932 UNIMPLEMENTED();
1933}
1934
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001935void Context::getTexLevelParameterfv(TextureTarget target,
1936 GLint level,
1937 GLenum pname,
1938 GLfloat *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08001939{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001940 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05001941 QueryTexLevelParameterfv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08001942}
1943
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001944void Context::getTexLevelParameterfvRobust(TextureTarget target,
1945 GLint level,
1946 GLenum pname,
1947 GLsizei bufSize,
1948 GLsizei *length,
1949 GLfloat *params)
1950{
1951 UNIMPLEMENTED();
1952}
1953
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001954void Context::texParameterf(TextureType target, GLenum pname, GLfloat param)
He Yunchao010e4db2017-03-03 14:22:06 +08001955{
1956 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001957 SetTexParameterf(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04001958 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001959}
1960
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001961void Context::texParameterfv(TextureType target, GLenum pname, const GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001962{
1963 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001964 SetTexParameterfv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04001965 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001966}
1967
Brandon Jones59770802018-04-02 13:18:42 -07001968void Context::texParameterfvRobust(TextureType target,
1969 GLenum pname,
1970 GLsizei bufSize,
1971 const GLfloat *params)
1972{
1973 texParameterfv(target, pname, params);
1974}
1975
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001976void Context::texParameteri(TextureType target, GLenum pname, GLint param)
He Yunchao010e4db2017-03-03 14:22:06 +08001977{
1978 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001979 SetTexParameteri(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04001980 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001981}
1982
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001983void Context::texParameteriv(TextureType target, GLenum pname, const GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001984{
1985 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001986 SetTexParameteriv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04001987 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001988}
1989
Brandon Jones59770802018-04-02 13:18:42 -07001990void Context::texParameterivRobust(TextureType target,
1991 GLenum pname,
1992 GLsizei bufSize,
1993 const GLint *params)
1994{
1995 texParameteriv(target, pname, params);
1996}
1997
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001998void Context::texParameterIivRobust(TextureType target,
1999 GLenum pname,
2000 GLsizei bufSize,
2001 const GLint *params)
2002{
2003 UNIMPLEMENTED();
2004}
2005
2006void Context::texParameterIuivRobust(TextureType target,
2007 GLenum pname,
2008 GLsizei bufSize,
2009 const GLuint *params)
2010{
2011 UNIMPLEMENTED();
2012}
2013
Jamie Madill675fe712016-12-19 13:07:54 -05002014void Context::drawArrays(GLenum mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002015{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002016 // No-op if zero count
2017 if (count == 0)
2018 {
2019 return;
2020 }
2021
Jamie Madill05b35b22017-10-03 09:01:44 -04002022 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002023 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
Jamie Madill09463932018-04-04 05:26:59 -04002024 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count, 1);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002025}
2026
Jamie Madill675fe712016-12-19 13:07:54 -05002027void Context::drawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04002028{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002029 // No-op if zero count
2030 if (count == 0 || instanceCount == 0)
2031 {
2032 return;
2033 }
2034
Jamie Madill05b35b22017-10-03 09:01:44 -04002035 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002036 ANGLE_CONTEXT_TRY(
2037 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
Jamie Madill09463932018-04-04 05:26:59 -04002038 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count,
2039 instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -04002040}
2041
Jamie Madill876429b2017-04-20 15:46:24 -04002042void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002043{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002044 // No-op if zero count
2045 if (count == 0)
2046 {
2047 return;
2048 }
2049
Jamie Madill05b35b22017-10-03 09:01:44 -04002050 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002051 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04002052}
2053
Jamie Madill675fe712016-12-19 13:07:54 -05002054void Context::drawElementsInstanced(GLenum mode,
2055 GLsizei count,
2056 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002057 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04002058 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04002059{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002060 // No-op if zero count
2061 if (count == 0 || instances == 0)
2062 {
2063 return;
2064 }
2065
Jamie Madill05b35b22017-10-03 09:01:44 -04002066 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002067 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08002068 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04002069}
2070
Jamie Madill675fe712016-12-19 13:07:54 -05002071void Context::drawRangeElements(GLenum mode,
2072 GLuint start,
2073 GLuint end,
2074 GLsizei count,
2075 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002076 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04002077{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002078 // No-op if zero count
2079 if (count == 0)
2080 {
2081 return;
2082 }
2083
Jamie Madill05b35b22017-10-03 09:01:44 -04002084 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002085 ANGLE_CONTEXT_TRY(
2086 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002087}
2088
Jamie Madill876429b2017-04-20 15:46:24 -04002089void Context::drawArraysIndirect(GLenum mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002090{
Jamie Madill05b35b22017-10-03 09:01:44 -04002091 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002092 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002093}
2094
Jamie Madill876429b2017-04-20 15:46:24 -04002095void Context::drawElementsIndirect(GLenum mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002096{
Jamie Madill05b35b22017-10-03 09:01:44 -04002097 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002098 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002099}
2100
Jamie Madill675fe712016-12-19 13:07:54 -05002101void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002102{
Jamie Madillafa02a22017-11-23 12:57:38 -05002103 handleError(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05002104}
2105
Jamie Madill675fe712016-12-19 13:07:54 -05002106void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05002107{
Jamie Madillafa02a22017-11-23 12:57:38 -05002108 handleError(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002109}
2110
Austin Kinross6ee1e782015-05-29 17:05:37 -07002111void Context::insertEventMarker(GLsizei length, const char *marker)
2112{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002113 ASSERT(mImplementation);
2114 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07002115}
2116
2117void Context::pushGroupMarker(GLsizei length, const char *marker)
2118{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002119 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05002120
2121 if (marker == nullptr)
2122 {
2123 // From the EXT_debug_marker spec,
2124 // "If <marker> is null then an empty string is pushed on the stack."
2125 mImplementation->pushGroupMarker(length, "");
2126 }
2127 else
2128 {
2129 mImplementation->pushGroupMarker(length, marker);
2130 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07002131}
2132
2133void Context::popGroupMarker()
2134{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002135 ASSERT(mImplementation);
2136 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07002137}
2138
Geoff Langd8605522016-04-13 10:19:12 -04002139void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
2140{
2141 Program *programObject = getProgram(program);
2142 ASSERT(programObject);
2143
2144 programObject->bindUniformLocation(location, name);
2145}
2146
Brandon Jones59770802018-04-02 13:18:42 -07002147void Context::coverageModulation(GLenum components)
Sami Väisänena797e062016-05-12 15:23:40 +03002148{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002149 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03002150}
2151
Brandon Jones59770802018-04-02 13:18:42 -07002152void Context::matrixLoadf(GLenum matrixMode, const GLfloat *matrix)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002153{
2154 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
2155}
2156
Brandon Jones59770802018-04-02 13:18:42 -07002157void Context::matrixLoadIdentity(GLenum matrixMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002158{
2159 GLfloat I[16];
2160 angle::Matrix<GLfloat>::setToIdentity(I);
2161
2162 mGLState.loadPathRenderingMatrix(matrixMode, I);
2163}
2164
2165void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
2166{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002167 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002168 if (!pathObj)
2169 return;
2170
2171 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002172 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002173
2174 mImplementation->stencilFillPath(pathObj, fillMode, mask);
2175}
2176
2177void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
2178{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002179 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002180 if (!pathObj)
2181 return;
2182
2183 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002184 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002185
2186 mImplementation->stencilStrokePath(pathObj, reference, mask);
2187}
2188
2189void Context::coverFillPath(GLuint path, GLenum coverMode)
2190{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002191 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002192 if (!pathObj)
2193 return;
2194
2195 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002196 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002197
2198 mImplementation->coverFillPath(pathObj, coverMode);
2199}
2200
2201void Context::coverStrokePath(GLuint path, GLenum coverMode)
2202{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002203 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002204 if (!pathObj)
2205 return;
2206
2207 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002208 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002209
2210 mImplementation->coverStrokePath(pathObj, coverMode);
2211}
2212
2213void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
2214{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002215 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002216 if (!pathObj)
2217 return;
2218
2219 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002220 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002221
2222 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
2223}
2224
2225void Context::stencilThenCoverStrokePath(GLuint path,
2226 GLint reference,
2227 GLuint mask,
2228 GLenum coverMode)
2229{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002230 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002231 if (!pathObj)
2232 return;
2233
2234 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002235 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002236
2237 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2238}
2239
Sami Väisänend59ca052016-06-21 16:10:00 +03002240void Context::coverFillPathInstanced(GLsizei numPaths,
2241 GLenum pathNameType,
2242 const void *paths,
2243 GLuint pathBase,
2244 GLenum coverMode,
2245 GLenum transformType,
2246 const GLfloat *transformValues)
2247{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002248 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002249
2250 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002251 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002252
2253 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2254}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002255
Sami Väisänend59ca052016-06-21 16:10:00 +03002256void Context::coverStrokePathInstanced(GLsizei numPaths,
2257 GLenum pathNameType,
2258 const void *paths,
2259 GLuint pathBase,
2260 GLenum coverMode,
2261 GLenum transformType,
2262 const GLfloat *transformValues)
2263{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002264 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002265
2266 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002267 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002268
2269 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2270 transformValues);
2271}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002272
Sami Väisänend59ca052016-06-21 16:10:00 +03002273void Context::stencilFillPathInstanced(GLsizei numPaths,
2274 GLenum pathNameType,
2275 const void *paths,
2276 GLuint pathBase,
2277 GLenum fillMode,
2278 GLuint mask,
2279 GLenum transformType,
2280 const GLfloat *transformValues)
2281{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002282 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002283
2284 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002285 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002286
2287 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2288 transformValues);
2289}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002290
Sami Väisänend59ca052016-06-21 16:10:00 +03002291void Context::stencilStrokePathInstanced(GLsizei numPaths,
2292 GLenum pathNameType,
2293 const void *paths,
2294 GLuint pathBase,
2295 GLint reference,
2296 GLuint mask,
2297 GLenum transformType,
2298 const GLfloat *transformValues)
2299{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002300 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002301
2302 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002303 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002304
2305 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2306 transformValues);
2307}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002308
Sami Väisänend59ca052016-06-21 16:10:00 +03002309void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2310 GLenum pathNameType,
2311 const void *paths,
2312 GLuint pathBase,
2313 GLenum fillMode,
2314 GLuint mask,
2315 GLenum coverMode,
2316 GLenum transformType,
2317 const GLfloat *transformValues)
2318{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002319 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002320
2321 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002322 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002323
2324 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2325 transformType, transformValues);
2326}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002327
Sami Väisänend59ca052016-06-21 16:10:00 +03002328void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2329 GLenum pathNameType,
2330 const void *paths,
2331 GLuint pathBase,
2332 GLint reference,
2333 GLuint mask,
2334 GLenum coverMode,
2335 GLenum transformType,
2336 const GLfloat *transformValues)
2337{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002338 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002339
2340 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002341 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002342
2343 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2344 transformType, transformValues);
2345}
2346
Sami Väisänen46eaa942016-06-29 10:26:37 +03002347void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2348{
2349 auto *programObject = getProgram(program);
2350
2351 programObject->bindFragmentInputLocation(location, name);
2352}
2353
2354void Context::programPathFragmentInputGen(GLuint program,
2355 GLint location,
2356 GLenum genMode,
2357 GLint components,
2358 const GLfloat *coeffs)
2359{
2360 auto *programObject = getProgram(program);
2361
Jamie Madillbd044ed2017-06-05 12:59:21 -04002362 programObject->pathFragmentInputGen(this, location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002363}
2364
jchen1015015f72017-03-16 13:54:21 +08002365GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2366{
jchen10fd7c3b52017-03-21 15:36:03 +08002367 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002368 return QueryProgramResourceIndex(programObject, programInterface, name);
2369}
2370
jchen10fd7c3b52017-03-21 15:36:03 +08002371void Context::getProgramResourceName(GLuint program,
2372 GLenum programInterface,
2373 GLuint index,
2374 GLsizei bufSize,
2375 GLsizei *length,
2376 GLchar *name)
2377{
2378 const auto *programObject = getProgram(program);
2379 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2380}
2381
jchen10191381f2017-04-11 13:59:04 +08002382GLint Context::getProgramResourceLocation(GLuint program,
2383 GLenum programInterface,
2384 const GLchar *name)
2385{
2386 const auto *programObject = getProgram(program);
2387 return QueryProgramResourceLocation(programObject, programInterface, name);
2388}
2389
jchen10880683b2017-04-12 16:21:55 +08002390void Context::getProgramResourceiv(GLuint program,
2391 GLenum programInterface,
2392 GLuint index,
2393 GLsizei propCount,
2394 const GLenum *props,
2395 GLsizei bufSize,
2396 GLsizei *length,
2397 GLint *params)
2398{
2399 const auto *programObject = getProgram(program);
2400 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2401 length, params);
2402}
2403
jchen10d9cd7b72017-08-30 15:04:25 +08002404void Context::getProgramInterfaceiv(GLuint program,
2405 GLenum programInterface,
2406 GLenum pname,
2407 GLint *params)
2408{
2409 const auto *programObject = getProgram(program);
2410 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2411}
2412
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002413void Context::getProgramInterfaceivRobust(GLuint program,
2414 GLenum programInterface,
2415 GLenum pname,
2416 GLsizei bufSize,
2417 GLsizei *length,
2418 GLint *params)
2419{
2420 UNIMPLEMENTED();
2421}
2422
Jamie Madill71c88b32017-09-14 22:20:29 -04002423void Context::handleError(const Error &error)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002424{
Geoff Langda5777c2014-07-11 09:52:58 -04002425 if (error.isError())
2426 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002427 GLenum code = error.getCode();
2428 mErrors.insert(code);
2429 if (code == GL_OUT_OF_MEMORY && getWorkarounds().loseContextOnOutOfMemory)
2430 {
2431 markContextLost();
2432 }
Geoff Lang70d0f492015-12-10 17:45:46 -05002433
Geoff Langee6884e2017-11-09 16:51:11 -05002434 ASSERT(!error.getMessage().empty());
2435 mGLState.getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, error.getID(),
2436 GL_DEBUG_SEVERITY_HIGH, error.getMessage());
Geoff Langda5777c2014-07-11 09:52:58 -04002437 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002438}
2439
2440// Get one of the recorded errors and clear its flag, if any.
2441// [OpenGL ES 2.0.24] section 2.5 page 13.
2442GLenum Context::getError()
2443{
Geoff Langda5777c2014-07-11 09:52:58 -04002444 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002445 {
Geoff Langda5777c2014-07-11 09:52:58 -04002446 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002447 }
Geoff Langda5777c2014-07-11 09:52:58 -04002448 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002449 {
Geoff Langda5777c2014-07-11 09:52:58 -04002450 GLenum error = *mErrors.begin();
2451 mErrors.erase(mErrors.begin());
2452 return error;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002453 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002454}
2455
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002456// NOTE: this function should not assume that this context is current!
2457void Context::markContextLost()
2458{
2459 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002460 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002461 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002462 mContextLostForced = true;
2463 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002464 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002465}
2466
2467bool Context::isContextLost()
2468{
2469 return mContextLost;
2470}
2471
Jamie Madillfa920eb2018-01-04 11:45:50 -05002472GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002473{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002474 // Even if the application doesn't want to know about resets, we want to know
2475 // as it will allow us to skip all the calls.
2476 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002477 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002478 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002479 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002480 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002481 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002482
2483 // EXT_robustness, section 2.6: If the reset notification behavior is
2484 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2485 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2486 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002487 }
2488
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002489 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2490 // status should be returned at least once, and GL_NO_ERROR should be returned
2491 // once the device has finished resetting.
2492 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002493 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002494 ASSERT(mResetStatus == GL_NO_ERROR);
2495 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002496
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002497 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002498 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002499 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002500 }
2501 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002502 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002503 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002504 // If markContextLost was used to mark the context lost then
2505 // assume that is not recoverable, and continue to report the
2506 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002507 mResetStatus = mImplementation->getResetStatus();
2508 }
Jamie Madill893ab082014-05-16 16:56:10 -04002509
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002510 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002511}
2512
2513bool Context::isResetNotificationEnabled()
2514{
2515 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2516}
2517
Corentin Walleze3b10e82015-05-20 11:06:25 -04002518const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002519{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002520 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002521}
2522
2523EGLenum Context::getClientType() const
2524{
2525 return mClientType;
2526}
2527
2528EGLenum Context::getRenderBuffer() const
2529{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002530 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2531 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002532 {
2533 return EGL_NONE;
2534 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002535
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002536 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002537 ASSERT(backAttachment != nullptr);
2538 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002539}
2540
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002541VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002542{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002543 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002544 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2545 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002546 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002547 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2548 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002549
Jamie Madill96a483b2017-06-27 16:49:21 -04002550 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002551 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002552
2553 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002554}
2555
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002556TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002557{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002558 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002559 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2560 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002561 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002562 transformFeedback =
2563 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002564 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002565 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002566 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002567
2568 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002569}
2570
2571bool Context::isVertexArrayGenerated(GLuint vertexArray)
2572{
Jamie Madill96a483b2017-06-27 16:49:21 -04002573 ASSERT(mVertexArrayMap.contains(0));
2574 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002575}
2576
2577bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2578{
Jamie Madill96a483b2017-06-27 16:49:21 -04002579 ASSERT(mTransformFeedbackMap.contains(0));
2580 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002581}
2582
Shannon Woods53a94a82014-06-24 15:20:36 -04002583void Context::detachTexture(GLuint texture)
2584{
2585 // Simple pass-through to State's detachTexture method, as textures do not require
2586 // allocation map management either here or in the resource manager at detach time.
2587 // Zero textures are held by the Context, and we don't attempt to request them from
2588 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002589 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002590}
2591
James Darpinian4d9d4832018-03-13 12:43:28 -07002592void Context::detachBuffer(Buffer *buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002593{
Yuly Novikov5807a532015-12-03 13:01:22 -05002594 // Simple pass-through to State's detachBuffer method, since
2595 // only buffer attachments to container objects that are bound to the current context
2596 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002597
Yuly Novikov5807a532015-12-03 13:01:22 -05002598 // [OpenGL ES 3.2] section 5.1.2 page 45:
2599 // Attachments to unbound container objects, such as
2600 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2601 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002602 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002603}
2604
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002605void Context::detachFramebuffer(GLuint framebuffer)
2606{
Shannon Woods53a94a82014-06-24 15:20:36 -04002607 // Framebuffer detachment is handled by Context, because 0 is a valid
2608 // Framebuffer object, and a pointer to it must be passed from Context
2609 // to State at binding time.
2610
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002611 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002612 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2613 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2614 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002615
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002616 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002617 {
2618 bindReadFramebuffer(0);
2619 }
2620
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002621 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002622 {
2623 bindDrawFramebuffer(0);
2624 }
2625}
2626
2627void Context::detachRenderbuffer(GLuint renderbuffer)
2628{
Jamie Madilla02315b2017-02-23 14:14:47 -05002629 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002630}
2631
Jamie Madill57a89722013-07-02 11:57:03 -04002632void Context::detachVertexArray(GLuint vertexArray)
2633{
Jamie Madill77a72f62015-04-14 11:18:32 -04002634 // Vertex array detachment is handled by Context, because 0 is a valid
2635 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002636 // binding time.
2637
Jamie Madill57a89722013-07-02 11:57:03 -04002638 // [OpenGL ES 3.0.2] section 2.10 page 43:
2639 // If a vertex array object that is currently bound is deleted, the binding
2640 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002641 if (mGLState.removeVertexArrayBinding(vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002642 {
2643 bindVertexArray(0);
2644 }
2645}
2646
Geoff Langc8058452014-02-03 12:04:11 -05002647void Context::detachTransformFeedback(GLuint transformFeedback)
2648{
Corentin Walleza2257da2016-04-19 16:43:12 -04002649 // Transform feedback detachment is handled by Context, because 0 is a valid
2650 // transform feedback, and a pointer to it must be passed from Context to State at
2651 // binding time.
2652
2653 // The OpenGL specification doesn't mention what should happen when the currently bound
2654 // transform feedback object is deleted. Since it is a container object, we treat it like
2655 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002656 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002657 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002658 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002659 }
Geoff Langc8058452014-02-03 12:04:11 -05002660}
2661
Jamie Madilldc356042013-07-19 16:36:57 -04002662void Context::detachSampler(GLuint sampler)
2663{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002664 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002665}
2666
Yunchao Hea336b902017-08-02 16:05:21 +08002667void Context::detachProgramPipeline(GLuint pipeline)
2668{
2669 mGLState.detachProgramPipeline(this, pipeline);
2670}
2671
Jamie Madill3ef140a2017-08-26 23:11:21 -04002672void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002673{
Shaodde78e82017-05-22 14:13:27 +08002674 mGLState.setVertexAttribDivisor(this, index, divisor);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002675}
2676
Jamie Madille29d1672013-07-19 16:36:57 -04002677void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2678{
Geoff Langc1984ed2016-10-07 12:41:00 -04002679 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002680 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002681 SetSamplerParameteri(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002682 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002683}
Jamie Madille29d1672013-07-19 16:36:57 -04002684
Geoff Langc1984ed2016-10-07 12:41:00 -04002685void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2686{
2687 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002688 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002689 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002690 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002691}
2692
Brandon Jones59770802018-04-02 13:18:42 -07002693void Context::samplerParameterivRobust(GLuint sampler,
2694 GLenum pname,
2695 GLsizei bufSize,
2696 const GLint *param)
2697{
2698 samplerParameteriv(sampler, pname, param);
2699}
2700
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002701void Context::samplerParameterIivRobust(GLuint sampler,
2702 GLenum pname,
2703 GLsizei bufSize,
2704 const GLint *param)
2705{
2706 UNIMPLEMENTED();
2707}
2708
2709void Context::samplerParameterIuivRobust(GLuint sampler,
2710 GLenum pname,
2711 GLsizei bufSize,
2712 const GLuint *param)
2713{
2714 UNIMPLEMENTED();
2715}
2716
Jamie Madille29d1672013-07-19 16:36:57 -04002717void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2718{
Geoff Langc1984ed2016-10-07 12:41:00 -04002719 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002720 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002721 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002722 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002723}
2724
Geoff Langc1984ed2016-10-07 12:41:00 -04002725void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002726{
Geoff Langc1984ed2016-10-07 12:41:00 -04002727 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002728 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002729 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002730 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002731}
2732
Brandon Jones59770802018-04-02 13:18:42 -07002733void Context::samplerParameterfvRobust(GLuint sampler,
2734 GLenum pname,
2735 GLsizei bufSize,
2736 const GLfloat *param)
2737{
2738 samplerParameterfv(sampler, pname, param);
2739}
2740
Geoff Langc1984ed2016-10-07 12:41:00 -04002741void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002742{
Geoff Langc1984ed2016-10-07 12:41:00 -04002743 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002744 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002745 QuerySamplerParameteriv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002746 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002747}
Jamie Madill9675b802013-07-19 16:36:59 -04002748
Brandon Jones59770802018-04-02 13:18:42 -07002749void Context::getSamplerParameterivRobust(GLuint sampler,
2750 GLenum pname,
2751 GLsizei bufSize,
2752 GLsizei *length,
2753 GLint *params)
2754{
2755 getSamplerParameteriv(sampler, pname, params);
2756}
2757
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002758void Context::getSamplerParameterIivRobust(GLuint sampler,
2759 GLenum pname,
2760 GLsizei bufSize,
2761 GLsizei *length,
2762 GLint *params)
2763{
2764 UNIMPLEMENTED();
2765}
2766
2767void Context::getSamplerParameterIuivRobust(GLuint sampler,
2768 GLenum pname,
2769 GLsizei bufSize,
2770 GLsizei *length,
2771 GLuint *params)
2772{
2773 UNIMPLEMENTED();
2774}
2775
Geoff Langc1984ed2016-10-07 12:41:00 -04002776void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2777{
2778 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002779 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002780 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002781 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002782}
2783
Brandon Jones59770802018-04-02 13:18:42 -07002784void Context::getSamplerParameterfvRobust(GLuint sampler,
2785 GLenum pname,
2786 GLsizei bufSize,
2787 GLsizei *length,
2788 GLfloat *params)
2789{
2790 getSamplerParameterfv(sampler, pname, params);
2791}
2792
Olli Etuahof0fee072016-03-30 15:11:58 +03002793void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2794{
2795 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002796 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002797}
2798
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002799void Context::initRendererString()
2800{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002801 std::ostringstream rendererString;
2802 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002803 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002804 rendererString << ")";
2805
Geoff Langcec35902014-04-16 10:52:36 -04002806 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002807}
2808
Geoff Langc339c4e2016-11-29 10:37:36 -05002809void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002810{
Geoff Langc339c4e2016-11-29 10:37:36 -05002811 const Version &clientVersion = getClientVersion();
2812
2813 std::ostringstream versionString;
2814 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2815 << ANGLE_VERSION_STRING << ")";
2816 mVersionString = MakeStaticString(versionString.str());
2817
2818 std::ostringstream shadingLanguageVersionString;
2819 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2820 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2821 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2822 << ")";
2823 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002824}
2825
Geoff Langcec35902014-04-16 10:52:36 -04002826void Context::initExtensionStrings()
2827{
Geoff Langc339c4e2016-11-29 10:37:36 -05002828 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2829 std::ostringstream combinedStringStream;
2830 std::copy(strings.begin(), strings.end(),
2831 std::ostream_iterator<const char *>(combinedStringStream, " "));
2832 return MakeStaticString(combinedStringStream.str());
2833 };
2834
2835 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002836 for (const auto &extensionString : mExtensions.getStrings())
2837 {
2838 mExtensionStrings.push_back(MakeStaticString(extensionString));
2839 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002840 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002841
Bryan Bernhart58806562017-01-05 13:09:31 -08002842 const gl::Extensions &nativeExtensions = mImplementation->getNativeExtensions();
2843
Geoff Langc339c4e2016-11-29 10:37:36 -05002844 mRequestableExtensionStrings.clear();
2845 for (const auto &extensionInfo : GetExtensionInfoMap())
2846 {
2847 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08002848 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
2849 nativeExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002850 {
2851 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
2852 }
2853 }
2854 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002855}
2856
Geoff Langc339c4e2016-11-29 10:37:36 -05002857const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04002858{
Geoff Langc339c4e2016-11-29 10:37:36 -05002859 switch (name)
2860 {
2861 case GL_VENDOR:
2862 return reinterpret_cast<const GLubyte *>("Google Inc.");
2863
2864 case GL_RENDERER:
2865 return reinterpret_cast<const GLubyte *>(mRendererString);
2866
2867 case GL_VERSION:
2868 return reinterpret_cast<const GLubyte *>(mVersionString);
2869
2870 case GL_SHADING_LANGUAGE_VERSION:
2871 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
2872
2873 case GL_EXTENSIONS:
2874 return reinterpret_cast<const GLubyte *>(mExtensionString);
2875
2876 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2877 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
2878
2879 default:
2880 UNREACHABLE();
2881 return nullptr;
2882 }
Geoff Langcec35902014-04-16 10:52:36 -04002883}
2884
Geoff Langc339c4e2016-11-29 10:37:36 -05002885const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04002886{
Geoff Langc339c4e2016-11-29 10:37:36 -05002887 switch (name)
2888 {
2889 case GL_EXTENSIONS:
2890 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
2891
2892 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2893 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
2894
2895 default:
2896 UNREACHABLE();
2897 return nullptr;
2898 }
Geoff Langcec35902014-04-16 10:52:36 -04002899}
2900
2901size_t Context::getExtensionStringCount() const
2902{
2903 return mExtensionStrings.size();
2904}
2905
Geoff Lang111a99e2017-10-17 10:58:41 -04002906bool Context::isExtensionRequestable(const char *name)
2907{
2908 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2909 auto extension = extensionInfos.find(name);
2910
2911 const Extensions &nativeExtensions = mImplementation->getNativeExtensions();
2912 return extension != extensionInfos.end() && extension->second.Requestable &&
2913 nativeExtensions.*(extension->second.ExtensionsMember);
2914}
2915
Geoff Langc339c4e2016-11-29 10:37:36 -05002916void Context::requestExtension(const char *name)
2917{
2918 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2919 ASSERT(extensionInfos.find(name) != extensionInfos.end());
2920 const auto &extension = extensionInfos.at(name);
2921 ASSERT(extension.Requestable);
Geoff Lang111a99e2017-10-17 10:58:41 -04002922 ASSERT(mImplementation->getNativeExtensions().*(extension.ExtensionsMember));
Geoff Langc339c4e2016-11-29 10:37:36 -05002923
2924 if (mExtensions.*(extension.ExtensionsMember))
2925 {
2926 // Extension already enabled
2927 return;
2928 }
2929
2930 mExtensions.*(extension.ExtensionsMember) = true;
2931 updateCaps();
2932 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08002933
Jamie Madill2f348d22017-06-05 10:50:59 -04002934 // Release the shader compiler so it will be re-created with the requested extensions enabled.
2935 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04002936
Jamie Madill81c2e252017-09-09 23:32:46 -04002937 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
2938 // sampleable.
Jamie Madilld4442552018-02-27 22:03:47 -05002939 mState.mTextures->signalAllTexturesDirty(this);
Geoff Lang9aded172017-04-05 11:07:56 -04002940 for (auto &zeroTexture : mZeroTextures)
2941 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002942 if (zeroTexture.get() != nullptr)
2943 {
2944 zeroTexture->signalDirty(this, InitState::Initialized);
2945 }
Geoff Lang9aded172017-04-05 11:07:56 -04002946 }
2947
2948 mState.mFramebuffers->invalidateFramebufferComplenessCache();
Geoff Langc339c4e2016-11-29 10:37:36 -05002949}
2950
2951size_t Context::getRequestableExtensionStringCount() const
2952{
2953 return mRequestableExtensionStrings.size();
2954}
2955
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002956void Context::beginTransformFeedback(GLenum primitiveMode)
2957{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002958 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002959 ASSERT(transformFeedback != nullptr);
2960 ASSERT(!transformFeedback->isPaused());
2961
Jamie Madill6c1f6712017-02-14 19:08:04 -05002962 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002963}
2964
2965bool Context::hasActiveTransformFeedback(GLuint program) const
2966{
2967 for (auto pair : mTransformFeedbackMap)
2968 {
2969 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
2970 {
2971 return true;
2972 }
2973 }
2974 return false;
2975}
2976
Geoff Langb433e872017-10-05 14:01:47 -04002977void Context::initCaps(const egl::DisplayExtensions &displayExtensions, bool robustResourceInit)
Geoff Lang493daf52014-07-03 13:38:44 -04002978{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002979 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04002980
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08002981 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
2982 if (getClientVersion() < Version(2, 0))
2983 {
2984 mCaps.maxMultitextureUnits = 4;
2985 mCaps.maxClipPlanes = 6;
2986 mCaps.maxLights = 8;
Lingfeng Yange547aac2018-04-05 09:39:20 -07002987 mCaps.maxModelviewMatrixStackDepth = Caps::GlobalMatrixStackDepth;
2988 mCaps.maxProjectionMatrixStackDepth = Caps::GlobalMatrixStackDepth;
2989 mCaps.maxTextureMatrixStackDepth = Caps::GlobalMatrixStackDepth;
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08002990 }
2991
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002992 mExtensions = mImplementation->getNativeExtensions();
Geoff Lang493daf52014-07-03 13:38:44 -04002993
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002994 mLimitations = mImplementation->getNativeLimitations();
Austin Kinross02df7962015-07-01 10:03:42 -07002995
Geoff Langeb66a6e2016-10-31 13:06:12 -04002996 if (getClientVersion() < Version(3, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002997 {
2998 // Disable ES3+ extensions
Jamie Madill231c7f52017-04-26 13:45:37 -04002999 mExtensions.colorBufferFloat = false;
Geoff Langb66a9092016-05-16 15:59:14 -04003000 mExtensions.eglImageExternalEssl3 = false;
Vincent Lang25ab4512016-05-13 18:13:59 +02003001 mExtensions.textureNorm16 = false;
Martin Radev137032d2017-07-13 10:11:12 +03003002 mExtensions.multiview = false;
3003 mExtensions.maxViews = 1u;
Geoff Lang493daf52014-07-03 13:38:44 -04003004 }
3005
Jiawei Shao89be29a2017-11-06 14:36:45 +08003006 if (getClientVersion() < ES_3_1)
3007 {
3008 // Disable ES3.1+ extensions
3009 mExtensions.geometryShader = false;
3010 }
3011
Geoff Langeb66a6e2016-10-31 13:06:12 -04003012 if (getClientVersion() > Version(2, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04003013 {
3014 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
Jamie Madill231c7f52017-04-26 13:45:37 -04003015 // mExtensions.sRGB = false;
Geoff Lang493daf52014-07-03 13:38:44 -04003016 }
3017
Jamie Madill00ed7a12016-05-19 13:13:38 -04003018 // Some extensions are always available because they are implemented in the GL layer.
Jamie Madill231c7f52017-04-26 13:45:37 -04003019 mExtensions.bindUniformLocation = true;
3020 mExtensions.vertexArrayObject = true;
Geoff Langf41a7152016-09-19 15:11:17 -04003021 mExtensions.bindGeneratesResource = true;
Geoff Langfeb8c682017-02-13 16:07:35 -05003022 mExtensions.clientArrays = true;
Geoff Langc339c4e2016-11-29 10:37:36 -05003023 mExtensions.requestExtension = true;
Jamie Madill00ed7a12016-05-19 13:13:38 -04003024
3025 // Enable the no error extension if the context was created with the flag.
3026 mExtensions.noError = mSkipValidation;
3027
Corentin Wallezccab69d2017-01-27 16:57:15 -05003028 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Corentin Wallezc295e512017-01-27 17:47:50 -05003029 mExtensions.surfacelessContext = displayExtensions.surfacelessContext;
Corentin Wallezccab69d2017-01-27 16:57:15 -05003030
Geoff Lang70d0f492015-12-10 17:45:46 -05003031 // Explicitly enable GL_KHR_debug
3032 mExtensions.debug = true;
3033 mExtensions.maxDebugMessageLength = 1024;
3034 mExtensions.maxDebugLoggedMessages = 1024;
3035 mExtensions.maxDebugGroupStackDepth = 1024;
3036 mExtensions.maxLabelLength = 1024;
3037
Geoff Langff5b2d52016-09-07 11:32:23 -04003038 // Explicitly enable GL_ANGLE_robust_client_memory
3039 mExtensions.robustClientMemory = true;
3040
Jamie Madille08a1d32017-03-07 17:24:06 -05003041 // Determine robust resource init availability from EGL.
Geoff Langb433e872017-10-05 14:01:47 -04003042 mExtensions.robustResourceInitialization = robustResourceInit;
Jamie Madille08a1d32017-03-07 17:24:06 -05003043
Jiajia Qin8a7b3a02017-08-25 16:05:48 +08003044 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
3045 // supports it.
3046 mExtensions.robustBufferAccessBehavior =
3047 mRobustAccess && mExtensions.robustBufferAccessBehavior;
3048
Jamie Madillc43be722017-07-13 16:22:14 -04003049 // Enable the cache control query unconditionally.
3050 mExtensions.programCacheControl = true;
3051
Geoff Lang301d1612014-07-09 10:34:37 -04003052 // Apply implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04003053 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003054
Jamie Madill0f80ed82017-09-19 00:24:56 -04003055 if (getClientVersion() < ES_3_1)
3056 {
3057 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
3058 }
3059 else
3060 {
3061 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
3062 }
Geoff Lang301d1612014-07-09 10:34:37 -04003063
Jamie Madill0f80ed82017-09-19 00:24:56 -04003064 LimitCap(&mCaps.maxVertexUniformBlocks, IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
3065 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3066 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3067
3068 // Limit textures as well, so we can use fast bitsets with texture bindings.
3069 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
3070 LimitCap(&mCaps.maxVertexTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
3071 LimitCap(&mCaps.maxTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04003072
Jiawei Shaodb342272017-09-27 10:21:45 +08003073 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
3074
Geoff Langc287ea62016-09-16 14:46:51 -04003075 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05003076 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04003077 for (const auto &extensionInfo : GetExtensionInfoMap())
3078 {
Geoff Lang0ab41fa2018-03-14 11:03:30 -04003079 // If the user has requested that extensions start disabled and they are requestable,
3080 // disable them.
3081 if (!mExtensionsEnabled && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04003082 {
3083 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
3084 }
3085 }
3086
3087 // Generate texture caps
3088 updateCaps();
3089}
3090
3091void Context::updateCaps()
3092{
Geoff Lang900013c2014-07-07 11:32:19 -04003093 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04003094 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04003095
Jamie Madill7b62cf92017-11-02 15:20:49 -04003096 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04003097 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04003098 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04003099 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003100
Geoff Lang0d8b7242015-09-09 14:56:53 -04003101 // Update the format caps based on the client version and extensions.
3102 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
3103 // ES3.
3104 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003105 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04003106 formatCaps.renderable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003107 formatCaps.renderable && formatInfo.renderSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04003108 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003109 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04003110
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003111 // OpenGL ES does not support multisampling with non-rendererable formats
3112 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Olli Etuaho50c562d2017-06-06 14:43:30 +03003113 if (!formatCaps.renderable ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003114 (getClientVersion() < ES_3_1 &&
3115 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04003116 {
Geoff Langd87878e2014-09-19 15:42:59 -04003117 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04003118 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03003119 else
3120 {
3121 // We may have limited the max samples for some required renderbuffer formats due to
3122 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
3123 GLuint formatMaxSamples = formatCaps.getMaxSamples();
3124
3125 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
3126 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
3127 // exception of signed and unsigned integer formats."
3128 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
3129 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
3130 {
3131 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
3132 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
3133 }
3134
3135 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
3136 if (getClientVersion() >= ES_3_1)
3137 {
3138 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
3139 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
3140 // the exception that the signed and unsigned integer formats are required only to
3141 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
3142 // multisamples, which must be at least one."
3143 if (formatInfo.componentType == GL_INT ||
3144 formatInfo.componentType == GL_UNSIGNED_INT)
3145 {
3146 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
3147 }
3148
3149 // GLES 3.1 section 19.3.1.
3150 if (formatCaps.texturable)
3151 {
3152 if (formatInfo.depthBits > 0)
3153 {
3154 mCaps.maxDepthTextureSamples =
3155 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
3156 }
3157 else if (formatInfo.redBits > 0)
3158 {
3159 mCaps.maxColorTextureSamples =
3160 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
3161 }
3162 }
3163 }
3164 }
Geoff Langd87878e2014-09-19 15:42:59 -04003165
3166 if (formatCaps.texturable && formatInfo.compressed)
3167 {
Geoff Langca271392017-04-05 12:30:00 -04003168 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003169 }
3170
Geoff Langca271392017-04-05 12:30:00 -04003171 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04003172 }
Jamie Madill32447362017-06-28 14:53:52 -04003173
3174 // If program binary is disabled, blank out the memory cache pointer.
3175 if (!mImplementation->getNativeExtensions().getProgramBinary)
3176 {
3177 mMemoryProgramCache = nullptr;
3178 }
Corentin Walleze4477002017-12-01 14:39:58 -05003179
3180 // Compute which buffer types are allowed
3181 mValidBufferBindings.reset();
3182 mValidBufferBindings.set(BufferBinding::ElementArray);
3183 mValidBufferBindings.set(BufferBinding::Array);
3184
3185 if (mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
3186 {
3187 mValidBufferBindings.set(BufferBinding::PixelPack);
3188 mValidBufferBindings.set(BufferBinding::PixelUnpack);
3189 }
3190
3191 if (getClientVersion() >= ES_3_0)
3192 {
3193 mValidBufferBindings.set(BufferBinding::CopyRead);
3194 mValidBufferBindings.set(BufferBinding::CopyWrite);
3195 mValidBufferBindings.set(BufferBinding::TransformFeedback);
3196 mValidBufferBindings.set(BufferBinding::Uniform);
3197 }
3198
3199 if (getClientVersion() >= ES_3_1)
3200 {
3201 mValidBufferBindings.set(BufferBinding::AtomicCounter);
3202 mValidBufferBindings.set(BufferBinding::ShaderStorage);
3203 mValidBufferBindings.set(BufferBinding::DrawIndirect);
3204 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
3205 }
Geoff Lang493daf52014-07-03 13:38:44 -04003206}
3207
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003208void Context::initWorkarounds()
3209{
Jamie Madill761b02c2017-06-23 16:27:06 -04003210 // Apply back-end workarounds.
3211 mImplementation->applyNativeWorkarounds(&mWorkarounds);
3212
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003213 // Lose the context upon out of memory error if the application is
3214 // expecting to watch for those events.
3215 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
3216}
3217
Jamie Madill05b35b22017-10-03 09:01:44 -04003218Error Context::prepareForDraw()
3219{
Geoff Langa8cb2872018-03-09 16:09:40 -05003220 ANGLE_TRY(syncDirtyObjects());
Jamie Madilla59fc192017-11-02 12:57:58 -04003221
3222 if (isRobustResourceInitEnabled())
3223 {
3224 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
3225 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
3226 }
3227
Geoff Langa8cb2872018-03-09 16:09:40 -05003228 ANGLE_TRY(syncDirtyBits());
Geoff Langd4fff502017-09-22 11:28:28 -04003229 return NoError();
3230}
3231
3232Error Context::prepareForClear(GLbitfield mask)
3233{
Geoff Langa8cb2872018-03-09 16:09:40 -05003234 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003235 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearAttachmentsInitialized(this, mask));
Geoff Langa8cb2872018-03-09 16:09:40 -05003236 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04003237 return NoError();
3238}
3239
3240Error Context::prepareForClearBuffer(GLenum buffer, GLint drawbuffer)
3241{
Geoff Langa8cb2872018-03-09 16:09:40 -05003242 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003243 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearBufferAttachmentsInitialized(this, buffer,
3244 drawbuffer));
Geoff Langa8cb2872018-03-09 16:09:40 -05003245 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill05b35b22017-10-03 09:01:44 -04003246 return NoError();
3247}
3248
Geoff Langa8cb2872018-03-09 16:09:40 -05003249Error Context::syncState()
Jamie Madill1b94d432015-08-07 13:23:23 -04003250{
Geoff Langa8cb2872018-03-09 16:09:40 -05003251 ANGLE_TRY(syncDirtyObjects());
3252 ANGLE_TRY(syncDirtyBits());
Jamie Madillbc918e72018-03-08 09:47:21 -05003253 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003254}
3255
Geoff Langa8cb2872018-03-09 16:09:40 -05003256Error Context::syncState(const State::DirtyBits &bitMask, const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04003257{
Geoff Langa8cb2872018-03-09 16:09:40 -05003258 ANGLE_TRY(syncDirtyObjects(objectMask));
3259 ANGLE_TRY(syncDirtyBits(bitMask));
Geoff Langd4fff502017-09-22 11:28:28 -04003260 return NoError();
3261}
3262
Geoff Langa8cb2872018-03-09 16:09:40 -05003263Error Context::syncDirtyBits()
Geoff Langd4fff502017-09-22 11:28:28 -04003264{
3265 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
3266 mImplementation->syncState(this, dirtyBits);
3267 mGLState.clearDirtyBits();
3268 return NoError();
3269}
3270
Geoff Langa8cb2872018-03-09 16:09:40 -05003271Error Context::syncDirtyBits(const State::DirtyBits &bitMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003272{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003273 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madillfe548342017-06-19 11:13:24 -04003274 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003275 mGLState.clearDirtyBits(dirtyBits);
Jamie Madillbc918e72018-03-08 09:47:21 -05003276 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003277}
Jamie Madillc29968b2016-01-20 11:17:23 -05003278
Geoff Langa8cb2872018-03-09 16:09:40 -05003279Error Context::syncDirtyObjects()
Geoff Langd4fff502017-09-22 11:28:28 -04003280{
3281 return mGLState.syncDirtyObjects(this);
3282}
3283
Geoff Langa8cb2872018-03-09 16:09:40 -05003284Error Context::syncDirtyObjects(const State::DirtyObjects &objectMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003285{
3286 return mGLState.syncDirtyObjects(this, objectMask);
3287}
3288
Jamie Madillc29968b2016-01-20 11:17:23 -05003289void Context::blitFramebuffer(GLint srcX0,
3290 GLint srcY0,
3291 GLint srcX1,
3292 GLint srcY1,
3293 GLint dstX0,
3294 GLint dstY0,
3295 GLint dstX1,
3296 GLint dstY1,
3297 GLbitfield mask,
3298 GLenum filter)
3299{
Qin Jiajiaaef92162018-02-27 13:51:44 +08003300 if (mask == 0)
3301 {
3302 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
3303 // buffers are copied.
3304 return;
3305 }
3306
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003307 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003308 ASSERT(drawFramebuffer);
3309
3310 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
3311 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
3312
Jamie Madillbc918e72018-03-08 09:47:21 -05003313 ANGLE_CONTEXT_TRY(syncStateForBlit());
Jamie Madillc29968b2016-01-20 11:17:23 -05003314
Jamie Madillc564c072017-06-01 12:45:42 -04003315 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003316}
Jamie Madillc29968b2016-01-20 11:17:23 -05003317
3318void Context::clear(GLbitfield mask)
3319{
Geoff Langd4fff502017-09-22 11:28:28 -04003320 ANGLE_CONTEXT_TRY(prepareForClear(mask));
3321 ANGLE_CONTEXT_TRY(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05003322}
3323
3324void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
3325{
Geoff Langd4fff502017-09-22 11:28:28 -04003326 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3327 ANGLE_CONTEXT_TRY(
3328 mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003329}
3330
3331void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3332{
Geoff Langd4fff502017-09-22 11:28:28 -04003333 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3334 ANGLE_CONTEXT_TRY(
3335 mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003336}
3337
3338void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3339{
Geoff Langd4fff502017-09-22 11:28:28 -04003340 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3341 ANGLE_CONTEXT_TRY(
3342 mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003343}
3344
3345void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3346{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003347 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003348 ASSERT(framebufferObject);
3349
3350 // If a buffer is not present, the clear has no effect
3351 if (framebufferObject->getDepthbuffer() == nullptr &&
3352 framebufferObject->getStencilbuffer() == nullptr)
3353 {
3354 return;
3355 }
3356
Geoff Langd4fff502017-09-22 11:28:28 -04003357 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3358 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003359}
3360
3361void Context::readPixels(GLint x,
3362 GLint y,
3363 GLsizei width,
3364 GLsizei height,
3365 GLenum format,
3366 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003367 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003368{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003369 if (width == 0 || height == 0)
3370 {
3371 return;
3372 }
3373
Jamie Madillbc918e72018-03-08 09:47:21 -05003374 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003375
Jamie Madillb6664922017-07-25 12:55:04 -04003376 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3377 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003378
3379 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04003380 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003381}
3382
Brandon Jones59770802018-04-02 13:18:42 -07003383void Context::readPixelsRobust(GLint x,
3384 GLint y,
3385 GLsizei width,
3386 GLsizei height,
3387 GLenum format,
3388 GLenum type,
3389 GLsizei bufSize,
3390 GLsizei *length,
3391 GLsizei *columns,
3392 GLsizei *rows,
3393 void *pixels)
3394{
3395 readPixels(x, y, width, height, format, type, pixels);
3396}
3397
3398void Context::readnPixelsRobust(GLint x,
3399 GLint y,
3400 GLsizei width,
3401 GLsizei height,
3402 GLenum format,
3403 GLenum type,
3404 GLsizei bufSize,
3405 GLsizei *length,
3406 GLsizei *columns,
3407 GLsizei *rows,
3408 void *data)
3409{
3410 readPixels(x, y, width, height, format, type, data);
3411}
3412
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003413void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003414 GLint level,
3415 GLenum internalformat,
3416 GLint x,
3417 GLint y,
3418 GLsizei width,
3419 GLsizei height,
3420 GLint border)
3421{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003422 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003423 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003424
Jamie Madillc29968b2016-01-20 11:17:23 -05003425 Rectangle sourceArea(x, y, width, height);
3426
Jamie Madill05b35b22017-10-03 09:01:44 -04003427 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003428 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003429 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003430}
3431
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003432void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003433 GLint level,
3434 GLint xoffset,
3435 GLint yoffset,
3436 GLint x,
3437 GLint y,
3438 GLsizei width,
3439 GLsizei height)
3440{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003441 if (width == 0 || height == 0)
3442 {
3443 return;
3444 }
3445
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003446 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003447 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003448
Jamie Madillc29968b2016-01-20 11:17:23 -05003449 Offset destOffset(xoffset, yoffset, 0);
3450 Rectangle sourceArea(x, y, width, height);
3451
Jamie Madill05b35b22017-10-03 09:01:44 -04003452 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003453 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003454 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003455}
3456
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003457void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003458 GLint level,
3459 GLint xoffset,
3460 GLint yoffset,
3461 GLint zoffset,
3462 GLint x,
3463 GLint y,
3464 GLsizei width,
3465 GLsizei height)
3466{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003467 if (width == 0 || height == 0)
3468 {
3469 return;
3470 }
3471
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003472 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003473 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003474
Jamie Madillc29968b2016-01-20 11:17:23 -05003475 Offset destOffset(xoffset, yoffset, zoffset);
3476 Rectangle sourceArea(x, y, width, height);
3477
Jamie Madill05b35b22017-10-03 09:01:44 -04003478 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3479 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003480 handleError(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level, destOffset,
3481 sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003482}
3483
3484void Context::framebufferTexture2D(GLenum target,
3485 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003486 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003487 GLuint texture,
3488 GLint level)
3489{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003490 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003491 ASSERT(framebuffer);
3492
3493 if (texture != 0)
3494 {
3495 Texture *textureObj = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003496 ImageIndex index = ImageIndex::MakeFromTarget(textarget, level);
Jamie Madilla02315b2017-02-23 14:14:47 -05003497 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003498 }
3499 else
3500 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003501 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003502 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003503
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003504 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003505}
3506
3507void Context::framebufferRenderbuffer(GLenum target,
3508 GLenum attachment,
3509 GLenum renderbuffertarget,
3510 GLuint renderbuffer)
3511{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003512 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003513 ASSERT(framebuffer);
3514
3515 if (renderbuffer != 0)
3516 {
3517 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003518
Jamie Madillcc129372018-04-12 09:13:18 -04003519 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003520 renderbufferObject);
3521 }
3522 else
3523 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003524 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003525 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003526
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003527 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003528}
3529
3530void Context::framebufferTextureLayer(GLenum target,
3531 GLenum attachment,
3532 GLuint texture,
3533 GLint level,
3534 GLint layer)
3535{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003536 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003537 ASSERT(framebuffer);
3538
3539 if (texture != 0)
3540 {
3541 Texture *textureObject = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003542 ImageIndex index = ImageIndex::MakeFromType(textureObject->getType(), level, layer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003543 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003544 }
3545 else
3546 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003547 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003548 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003549
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003550 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003551}
3552
Brandon Jones59770802018-04-02 13:18:42 -07003553void Context::framebufferTextureMultiviewLayered(GLenum target,
3554 GLenum attachment,
3555 GLuint texture,
3556 GLint level,
3557 GLint baseViewIndex,
3558 GLsizei numViews)
Martin Radev137032d2017-07-13 10:11:12 +03003559{
Martin Radev82ef7742017-08-08 17:44:58 +03003560 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3561 ASSERT(framebuffer);
3562
3563 if (texture != 0)
3564 {
3565 Texture *textureObj = getTexture(texture);
3566
Martin Radev18b75ba2017-08-15 15:50:40 +03003567 ImageIndex index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
Martin Radev82ef7742017-08-08 17:44:58 +03003568 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3569 numViews, baseViewIndex);
3570 }
3571 else
3572 {
3573 framebuffer->resetAttachment(this, attachment);
3574 }
3575
3576 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003577}
3578
Brandon Jones59770802018-04-02 13:18:42 -07003579void Context::framebufferTextureMultiviewSideBySide(GLenum target,
3580 GLenum attachment,
3581 GLuint texture,
3582 GLint level,
3583 GLsizei numViews,
3584 const GLint *viewportOffsets)
Martin Radev137032d2017-07-13 10:11:12 +03003585{
Martin Radev5dae57b2017-07-14 16:15:55 +03003586 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3587 ASSERT(framebuffer);
3588
3589 if (texture != 0)
3590 {
3591 Texture *textureObj = getTexture(texture);
3592
3593 ImageIndex index = ImageIndex::Make2D(level);
3594 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3595 textureObj, numViews, viewportOffsets);
3596 }
3597 else
3598 {
3599 framebuffer->resetAttachment(this, attachment);
3600 }
3601
3602 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003603}
3604
Jamie Madillc29968b2016-01-20 11:17:23 -05003605void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3606{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003607 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003608 ASSERT(framebuffer);
3609 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003610 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003611}
3612
3613void Context::readBuffer(GLenum mode)
3614{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003615 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003616 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003617 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003618}
3619
3620void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3621{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003622 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003623 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003624
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003625 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003626 ASSERT(framebuffer);
3627
3628 // The specification isn't clear what should be done when the framebuffer isn't complete.
3629 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003630 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003631}
3632
3633void Context::invalidateFramebuffer(GLenum target,
3634 GLsizei numAttachments,
3635 const GLenum *attachments)
3636{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003637 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003638 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003639
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003640 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003641 ASSERT(framebuffer);
3642
Jamie Madille98b1b52018-03-08 09:47:23 -05003643 bool complete = false;
3644 ANGLE_CONTEXT_TRY(framebuffer->isComplete(this, &complete));
3645 if (!complete)
Jamie Madillc29968b2016-01-20 11:17:23 -05003646 {
Jamie Madill437fa652016-05-03 15:13:24 -04003647 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003648 }
Jamie Madill437fa652016-05-03 15:13:24 -04003649
Jamie Madill4928b7c2017-06-20 12:57:39 -04003650 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003651}
3652
3653void Context::invalidateSubFramebuffer(GLenum target,
3654 GLsizei numAttachments,
3655 const GLenum *attachments,
3656 GLint x,
3657 GLint y,
3658 GLsizei width,
3659 GLsizei height)
3660{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003661 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003662 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003663
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003664 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003665 ASSERT(framebuffer);
3666
Jamie Madille98b1b52018-03-08 09:47:23 -05003667 bool complete = false;
3668 ANGLE_CONTEXT_TRY(framebuffer->isComplete(this, &complete));
3669 if (!complete)
Jamie Madillc29968b2016-01-20 11:17:23 -05003670 {
Jamie Madill437fa652016-05-03 15:13:24 -04003671 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003672 }
Jamie Madill437fa652016-05-03 15:13:24 -04003673
3674 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003675 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003676}
3677
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003678void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003679 GLint level,
3680 GLint internalformat,
3681 GLsizei width,
3682 GLsizei height,
3683 GLint border,
3684 GLenum format,
3685 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003686 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003687{
Jamie Madillbc918e72018-03-08 09:47:21 -05003688 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003689
3690 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003691 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003692 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3693 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003694}
3695
Brandon Jones59770802018-04-02 13:18:42 -07003696void Context::texImage2DRobust(TextureTarget target,
3697 GLint level,
3698 GLint internalformat,
3699 GLsizei width,
3700 GLsizei height,
3701 GLint border,
3702 GLenum format,
3703 GLenum type,
3704 GLsizei bufSize,
3705 const void *pixels)
3706{
3707 texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
3708}
3709
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003710void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003711 GLint level,
3712 GLint internalformat,
3713 GLsizei width,
3714 GLsizei height,
3715 GLsizei depth,
3716 GLint border,
3717 GLenum format,
3718 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003719 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003720{
Jamie Madillbc918e72018-03-08 09:47:21 -05003721 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003722
3723 Extents size(width, height, depth);
3724 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003725 handleError(texture->setImage(this, mGLState.getUnpackState(),
3726 NonCubeTextureTypeToTarget(target), level, internalformat, size,
3727 format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003728}
3729
Brandon Jones59770802018-04-02 13:18:42 -07003730void Context::texImage3DRobust(TextureType target,
3731 GLint level,
3732 GLint internalformat,
3733 GLsizei width,
3734 GLsizei height,
3735 GLsizei depth,
3736 GLint border,
3737 GLenum format,
3738 GLenum type,
3739 GLsizei bufSize,
3740 const void *pixels)
3741{
3742 texImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels);
3743}
3744
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003745void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003746 GLint level,
3747 GLint xoffset,
3748 GLint yoffset,
3749 GLsizei width,
3750 GLsizei height,
3751 GLenum format,
3752 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003753 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003754{
3755 // Zero sized uploads are valid but no-ops
3756 if (width == 0 || height == 0)
3757 {
3758 return;
3759 }
3760
Jamie Madillbc918e72018-03-08 09:47:21 -05003761 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003762
3763 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003764 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003765 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3766 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003767}
3768
Brandon Jones59770802018-04-02 13:18:42 -07003769void Context::texSubImage2DRobust(TextureTarget target,
3770 GLint level,
3771 GLint xoffset,
3772 GLint yoffset,
3773 GLsizei width,
3774 GLsizei height,
3775 GLenum format,
3776 GLenum type,
3777 GLsizei bufSize,
3778 const void *pixels)
3779{
3780 texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
3781}
3782
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003783void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003784 GLint level,
3785 GLint xoffset,
3786 GLint yoffset,
3787 GLint zoffset,
3788 GLsizei width,
3789 GLsizei height,
3790 GLsizei depth,
3791 GLenum format,
3792 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003793 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003794{
3795 // Zero sized uploads are valid but no-ops
3796 if (width == 0 || height == 0 || depth == 0)
3797 {
3798 return;
3799 }
3800
Jamie Madillbc918e72018-03-08 09:47:21 -05003801 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003802
3803 Box area(xoffset, yoffset, zoffset, width, height, depth);
3804 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003805 handleError(texture->setSubImage(this, mGLState.getUnpackState(),
3806 NonCubeTextureTypeToTarget(target), level, area, format, type,
3807 reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003808}
3809
Brandon Jones59770802018-04-02 13:18:42 -07003810void Context::texSubImage3DRobust(TextureType target,
3811 GLint level,
3812 GLint xoffset,
3813 GLint yoffset,
3814 GLint zoffset,
3815 GLsizei width,
3816 GLsizei height,
3817 GLsizei depth,
3818 GLenum format,
3819 GLenum type,
3820 GLsizei bufSize,
3821 const void *pixels)
3822{
3823 texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type,
3824 pixels);
3825}
3826
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003827void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003828 GLint level,
3829 GLenum internalformat,
3830 GLsizei width,
3831 GLsizei height,
3832 GLint border,
3833 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003834 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003835{
Jamie Madillbc918e72018-03-08 09:47:21 -05003836 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003837
3838 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003839 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003840 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
3841 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003842 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003843}
3844
Brandon Jones59770802018-04-02 13:18:42 -07003845void Context::compressedTexImage2DRobust(TextureTarget target,
3846 GLint level,
3847 GLenum internalformat,
3848 GLsizei width,
3849 GLsizei height,
3850 GLint border,
3851 GLsizei imageSize,
3852 GLsizei dataSize,
3853 const GLvoid *data)
3854{
3855 compressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
3856}
3857
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003858void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003859 GLint level,
3860 GLenum internalformat,
3861 GLsizei width,
3862 GLsizei height,
3863 GLsizei depth,
3864 GLint border,
3865 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003866 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003867{
Jamie Madillbc918e72018-03-08 09:47:21 -05003868 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003869
3870 Extents size(width, height, depth);
3871 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003872 handleError(texture->setCompressedImage(
3873 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
3874 size, imageSize, reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003875}
3876
Brandon Jones59770802018-04-02 13:18:42 -07003877void Context::compressedTexImage3DRobust(TextureType target,
3878 GLint level,
3879 GLenum internalformat,
3880 GLsizei width,
3881 GLsizei height,
3882 GLsizei depth,
3883 GLint border,
3884 GLsizei imageSize,
3885 GLsizei dataSize,
3886 const GLvoid *data)
3887{
3888 compressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize,
3889 data);
3890}
3891
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003892void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003893 GLint level,
3894 GLint xoffset,
3895 GLint yoffset,
3896 GLsizei width,
3897 GLsizei height,
3898 GLenum format,
3899 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003900 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003901{
Jamie Madillbc918e72018-03-08 09:47:21 -05003902 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003903
3904 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003905 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003906 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
3907 format, imageSize,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003908 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003909}
3910
Brandon Jones59770802018-04-02 13:18:42 -07003911void Context::compressedTexSubImage2DRobust(TextureTarget target,
3912 GLint level,
3913 GLint xoffset,
3914 GLint yoffset,
3915 GLsizei width,
3916 GLsizei height,
3917 GLenum format,
3918 GLsizei imageSize,
3919 GLsizei dataSize,
3920 const GLvoid *data)
3921{
3922 compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize,
3923 data);
3924}
3925
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003926void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003927 GLint level,
3928 GLint xoffset,
3929 GLint yoffset,
3930 GLint zoffset,
3931 GLsizei width,
3932 GLsizei height,
3933 GLsizei depth,
3934 GLenum format,
3935 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003936 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003937{
3938 // Zero sized uploads are valid but no-ops
3939 if (width == 0 || height == 0)
3940 {
3941 return;
3942 }
3943
Jamie Madillbc918e72018-03-08 09:47:21 -05003944 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003945
3946 Box area(xoffset, yoffset, zoffset, width, height, depth);
3947 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003948 handleError(texture->setCompressedSubImage(
3949 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
3950 imageSize, reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003951}
3952
Brandon Jones59770802018-04-02 13:18:42 -07003953void Context::compressedTexSubImage3DRobust(TextureType target,
3954 GLint level,
3955 GLint xoffset,
3956 GLint yoffset,
3957 GLint zoffset,
3958 GLsizei width,
3959 GLsizei height,
3960 GLsizei depth,
3961 GLenum format,
3962 GLsizei imageSize,
3963 GLsizei dataSize,
3964 const GLvoid *data)
3965{
3966 compressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format,
3967 imageSize, data);
3968}
3969
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003970void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003971{
3972 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003973 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003974}
3975
Jamie Madill007530e2017-12-28 14:27:04 -05003976void Context::copyTexture(GLuint sourceId,
3977 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05003978 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05003979 GLuint destId,
3980 GLint destLevel,
3981 GLint internalFormat,
3982 GLenum destType,
3983 GLboolean unpackFlipY,
3984 GLboolean unpackPremultiplyAlpha,
3985 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07003986{
Jamie Madillbc918e72018-03-08 09:47:21 -05003987 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07003988
3989 gl::Texture *sourceTexture = getTexture(sourceId);
3990 gl::Texture *destTexture = getTexture(destId);
Geoff Lang92019432017-11-20 13:09:34 -05003991 handleError(destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType,
3992 sourceLevel, ConvertToBool(unpackFlipY),
3993 ConvertToBool(unpackPremultiplyAlpha),
3994 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003995}
3996
Jamie Madill007530e2017-12-28 14:27:04 -05003997void Context::copySubTexture(GLuint sourceId,
3998 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05003999 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004000 GLuint destId,
4001 GLint destLevel,
4002 GLint xoffset,
4003 GLint yoffset,
4004 GLint x,
4005 GLint y,
4006 GLsizei width,
4007 GLsizei height,
4008 GLboolean unpackFlipY,
4009 GLboolean unpackPremultiplyAlpha,
4010 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004011{
4012 // Zero sized copies are valid but no-ops
4013 if (width == 0 || height == 0)
4014 {
4015 return;
4016 }
4017
Jamie Madillbc918e72018-03-08 09:47:21 -05004018 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004019
4020 gl::Texture *sourceTexture = getTexture(sourceId);
4021 gl::Texture *destTexture = getTexture(destId);
4022 Offset offset(xoffset, yoffset, 0);
4023 Rectangle area(x, y, width, height);
Geoff Lang92019432017-11-20 13:09:34 -05004024 handleError(destTexture->copySubTexture(this, destTarget, destLevel, offset, sourceLevel, area,
4025 ConvertToBool(unpackFlipY),
4026 ConvertToBool(unpackPremultiplyAlpha),
4027 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004028}
4029
Jamie Madill007530e2017-12-28 14:27:04 -05004030void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07004031{
Jamie Madillbc918e72018-03-08 09:47:21 -05004032 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07004033
4034 gl::Texture *sourceTexture = getTexture(sourceId);
4035 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05004036 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07004037}
4038
Corentin Wallez336129f2017-10-17 15:55:40 -04004039void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03004040{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004041 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004042 ASSERT(buffer);
4043
Geoff Lang496c02d2016-10-20 11:38:11 -07004044 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03004045}
4046
Brandon Jones59770802018-04-02 13:18:42 -07004047void Context::getBufferPointervRobust(BufferBinding target,
4048 GLenum pname,
4049 GLsizei bufSize,
4050 GLsizei *length,
4051 void **params)
4052{
4053 getBufferPointerv(target, pname, params);
4054}
4055
Corentin Wallez336129f2017-10-17 15:55:40 -04004056void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004057{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004058 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004059 ASSERT(buffer);
4060
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004061 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004062 if (error.isError())
4063 {
Jamie Madill437fa652016-05-03 15:13:24 -04004064 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004065 return nullptr;
4066 }
4067
4068 return buffer->getMapPointer();
4069}
4070
Corentin Wallez336129f2017-10-17 15:55:40 -04004071GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03004072{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004073 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004074 ASSERT(buffer);
4075
4076 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004077 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03004078 if (error.isError())
4079 {
Jamie Madill437fa652016-05-03 15:13:24 -04004080 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004081 return GL_FALSE;
4082 }
4083
4084 return result;
4085}
4086
Corentin Wallez336129f2017-10-17 15:55:40 -04004087void *Context::mapBufferRange(BufferBinding target,
4088 GLintptr offset,
4089 GLsizeiptr length,
4090 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004091{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004092 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004093 ASSERT(buffer);
4094
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004095 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004096 if (error.isError())
4097 {
Jamie Madill437fa652016-05-03 15:13:24 -04004098 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004099 return nullptr;
4100 }
4101
4102 return buffer->getMapPointer();
4103}
4104
Corentin Wallez336129f2017-10-17 15:55:40 -04004105void Context::flushMappedBufferRange(BufferBinding /*target*/,
4106 GLintptr /*offset*/,
4107 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03004108{
4109 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
4110}
4111
Jamie Madillbc918e72018-03-08 09:47:21 -05004112Error Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004113{
Geoff Langa8cb2872018-03-09 16:09:40 -05004114 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004115}
4116
Jamie Madillbc918e72018-03-08 09:47:21 -05004117Error Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004118{
Geoff Langa8cb2872018-03-09 16:09:40 -05004119 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004120}
4121
Jamie Madillbc918e72018-03-08 09:47:21 -05004122Error Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004123{
Geoff Langa8cb2872018-03-09 16:09:40 -05004124 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004125}
4126
Jiajia Qin5451d532017-11-16 17:16:34 +08004127void Context::activeShaderProgram(GLuint pipeline, GLuint program)
4128{
4129 UNIMPLEMENTED();
4130}
4131
Jamie Madillc20ab272016-06-09 07:20:46 -07004132void Context::activeTexture(GLenum texture)
4133{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004134 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004135}
4136
Jamie Madill876429b2017-04-20 15:46:24 -04004137void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004138{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004139 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004140}
4141
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004142void Context::blendEquation(GLenum mode)
4143{
4144 mGLState.setBlendEquation(mode, mode);
4145}
4146
Jamie Madillc20ab272016-06-09 07:20:46 -07004147void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
4148{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004149 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004150}
4151
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004152void Context::blendFunc(GLenum sfactor, GLenum dfactor)
4153{
4154 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
4155}
4156
Jamie Madillc20ab272016-06-09 07:20:46 -07004157void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
4158{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004159 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004160}
4161
Jamie Madill876429b2017-04-20 15:46:24 -04004162void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004163{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004164 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004165}
4166
Jamie Madill876429b2017-04-20 15:46:24 -04004167void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07004168{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004169 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07004170}
4171
4172void Context::clearStencil(GLint s)
4173{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004174 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07004175}
4176
4177void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
4178{
Geoff Lang92019432017-11-20 13:09:34 -05004179 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
4180 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004181}
4182
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004183void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07004184{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004185 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004186}
4187
4188void Context::depthFunc(GLenum func)
4189{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004190 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07004191}
4192
4193void Context::depthMask(GLboolean flag)
4194{
Geoff Lang92019432017-11-20 13:09:34 -05004195 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07004196}
4197
Jamie Madill876429b2017-04-20 15:46:24 -04004198void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07004199{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004200 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07004201}
4202
4203void Context::disable(GLenum cap)
4204{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004205 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07004206}
4207
4208void Context::disableVertexAttribArray(GLuint index)
4209{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004210 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07004211}
4212
4213void Context::enable(GLenum cap)
4214{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004215 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07004216}
4217
4218void Context::enableVertexAttribArray(GLuint index)
4219{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004220 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07004221}
4222
4223void Context::frontFace(GLenum mode)
4224{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004225 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004226}
4227
4228void Context::hint(GLenum target, GLenum mode)
4229{
4230 switch (target)
4231 {
4232 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004233 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004234 break;
4235
4236 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004237 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004238 break;
4239
4240 default:
4241 UNREACHABLE();
4242 return;
4243 }
4244}
4245
4246void Context::lineWidth(GLfloat width)
4247{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004248 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07004249}
4250
4251void Context::pixelStorei(GLenum pname, GLint param)
4252{
4253 switch (pname)
4254 {
4255 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004256 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004257 break;
4258
4259 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004260 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004261 break;
4262
4263 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004264 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004265 break;
4266
4267 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004268 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004269 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004270 break;
4271
4272 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03004273 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004274 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004275 break;
4276
4277 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03004278 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004279 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004280 break;
4281
4282 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004283 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004284 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004285 break;
4286
4287 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004288 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004289 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004290 break;
4291
4292 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004293 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004294 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004295 break;
4296
4297 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004298 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004299 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004300 break;
4301
4302 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004303 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004304 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004305 break;
4306
4307 default:
4308 UNREACHABLE();
4309 return;
4310 }
4311}
4312
4313void Context::polygonOffset(GLfloat factor, GLfloat units)
4314{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004315 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07004316}
4317
Jamie Madill876429b2017-04-20 15:46:24 -04004318void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07004319{
Geoff Lang92019432017-11-20 13:09:34 -05004320 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07004321}
4322
Jiawei Shaodb342272017-09-27 10:21:45 +08004323void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
4324{
4325 mGLState.setSampleMaskParams(maskNumber, mask);
4326}
4327
Jamie Madillc20ab272016-06-09 07:20:46 -07004328void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
4329{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004330 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004331}
4332
4333void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
4334{
4335 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4336 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004337 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004338 }
4339
4340 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4341 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004342 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004343 }
4344}
4345
4346void Context::stencilMaskSeparate(GLenum face, GLuint mask)
4347{
4348 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4349 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004350 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004351 }
4352
4353 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4354 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004355 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004356 }
4357}
4358
4359void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4360{
4361 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4362 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004363 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004364 }
4365
4366 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4367 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004368 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004369 }
4370}
4371
4372void Context::vertexAttrib1f(GLuint index, GLfloat x)
4373{
4374 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004375 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004376}
4377
4378void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
4379{
4380 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004381 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004382}
4383
4384void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4385{
4386 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004387 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004388}
4389
4390void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
4391{
4392 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004393 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004394}
4395
4396void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4397{
4398 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004399 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004400}
4401
4402void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
4403{
4404 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004405 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004406}
4407
4408void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4409{
4410 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004411 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004412}
4413
4414void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
4415{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004416 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07004417}
4418
4419void Context::vertexAttribPointer(GLuint index,
4420 GLint size,
4421 GLenum type,
4422 GLboolean normalized,
4423 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004424 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07004425{
Corentin Wallez336129f2017-10-17 15:55:40 -04004426 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05004427 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc20ab272016-06-09 07:20:46 -07004428}
4429
Shao80957d92017-02-20 21:25:59 +08004430void Context::vertexAttribFormat(GLuint attribIndex,
4431 GLint size,
4432 GLenum type,
4433 GLboolean normalized,
4434 GLuint relativeOffset)
4435{
Geoff Lang92019432017-11-20 13:09:34 -05004436 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08004437 relativeOffset);
4438}
4439
4440void Context::vertexAttribIFormat(GLuint attribIndex,
4441 GLint size,
4442 GLenum type,
4443 GLuint relativeOffset)
4444{
4445 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
4446}
4447
4448void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4449{
Shaodde78e82017-05-22 14:13:27 +08004450 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Shao80957d92017-02-20 21:25:59 +08004451}
4452
Jiajia Qin5451d532017-11-16 17:16:34 +08004453void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004454{
4455 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
4456}
4457
Jamie Madillc20ab272016-06-09 07:20:46 -07004458void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4459{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004460 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004461}
4462
4463void Context::vertexAttribIPointer(GLuint index,
4464 GLint size,
4465 GLenum type,
4466 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004467 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004468{
Corentin Wallez336129f2017-10-17 15:55:40 -04004469 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
4470 size, type, false, true, stride, pointer);
Jamie Madillc20ab272016-06-09 07:20:46 -07004471}
4472
4473void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4474{
4475 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004476 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004477}
4478
4479void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4480{
4481 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004482 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004483}
4484
4485void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4486{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004487 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004488}
4489
4490void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4491{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004492 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004493}
4494
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004495void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4496{
4497 const VertexAttribCurrentValueData &currentValues =
4498 getGLState().getVertexAttribCurrentValue(index);
4499 const VertexArray *vao = getGLState().getVertexArray();
4500 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4501 currentValues, pname, params);
4502}
4503
Brandon Jones59770802018-04-02 13:18:42 -07004504void Context::getVertexAttribivRobust(GLuint index,
4505 GLenum pname,
4506 GLsizei bufSize,
4507 GLsizei *length,
4508 GLint *params)
4509{
4510 getVertexAttribiv(index, pname, params);
4511}
4512
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004513void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4514{
4515 const VertexAttribCurrentValueData &currentValues =
4516 getGLState().getVertexAttribCurrentValue(index);
4517 const VertexArray *vao = getGLState().getVertexArray();
4518 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4519 currentValues, pname, params);
4520}
4521
Brandon Jones59770802018-04-02 13:18:42 -07004522void Context::getVertexAttribfvRobust(GLuint index,
4523 GLenum pname,
4524 GLsizei bufSize,
4525 GLsizei *length,
4526 GLfloat *params)
4527{
4528 getVertexAttribfv(index, pname, params);
4529}
4530
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004531void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4532{
4533 const VertexAttribCurrentValueData &currentValues =
4534 getGLState().getVertexAttribCurrentValue(index);
4535 const VertexArray *vao = getGLState().getVertexArray();
4536 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4537 currentValues, pname, params);
4538}
4539
Brandon Jones59770802018-04-02 13:18:42 -07004540void Context::getVertexAttribIivRobust(GLuint index,
4541 GLenum pname,
4542 GLsizei bufSize,
4543 GLsizei *length,
4544 GLint *params)
4545{
4546 getVertexAttribIiv(index, pname, params);
4547}
4548
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004549void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4550{
4551 const VertexAttribCurrentValueData &currentValues =
4552 getGLState().getVertexAttribCurrentValue(index);
4553 const VertexArray *vao = getGLState().getVertexArray();
4554 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4555 currentValues, pname, params);
4556}
4557
Brandon Jones59770802018-04-02 13:18:42 -07004558void Context::getVertexAttribIuivRobust(GLuint index,
4559 GLenum pname,
4560 GLsizei bufSize,
4561 GLsizei *length,
4562 GLuint *params)
4563{
4564 getVertexAttribIuiv(index, pname, params);
4565}
4566
Jamie Madill876429b2017-04-20 15:46:24 -04004567void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004568{
4569 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
4570 QueryVertexAttribPointerv(attrib, pname, pointer);
4571}
4572
Brandon Jones59770802018-04-02 13:18:42 -07004573void Context::getVertexAttribPointervRobust(GLuint index,
4574 GLenum pname,
4575 GLsizei bufSize,
4576 GLsizei *length,
4577 void **pointer)
4578{
4579 getVertexAttribPointerv(index, pname, pointer);
4580}
4581
Jamie Madillc20ab272016-06-09 07:20:46 -07004582void Context::debugMessageControl(GLenum source,
4583 GLenum type,
4584 GLenum severity,
4585 GLsizei count,
4586 const GLuint *ids,
4587 GLboolean enabled)
4588{
4589 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004590 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05004591 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004592}
4593
4594void Context::debugMessageInsert(GLenum source,
4595 GLenum type,
4596 GLuint id,
4597 GLenum severity,
4598 GLsizei length,
4599 const GLchar *buf)
4600{
4601 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004602 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004603}
4604
4605void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4606{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004607 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004608}
4609
4610GLuint Context::getDebugMessageLog(GLuint count,
4611 GLsizei bufSize,
4612 GLenum *sources,
4613 GLenum *types,
4614 GLuint *ids,
4615 GLenum *severities,
4616 GLsizei *lengths,
4617 GLchar *messageLog)
4618{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004619 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4620 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004621}
4622
4623void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4624{
4625 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004626 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05004627 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07004628}
4629
4630void Context::popDebugGroup()
4631{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004632 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05004633 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004634}
4635
Corentin Wallez336129f2017-10-17 15:55:40 -04004636void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004637{
4638 Buffer *buffer = mGLState.getTargetBuffer(target);
4639 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004640 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004641}
4642
Corentin Wallez336129f2017-10-17 15:55:40 -04004643void Context::bufferSubData(BufferBinding target,
4644 GLintptr offset,
4645 GLsizeiptr size,
4646 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004647{
4648 if (data == nullptr)
4649 {
4650 return;
4651 }
4652
4653 Buffer *buffer = mGLState.getTargetBuffer(target);
4654 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004655 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004656}
4657
Jamie Madillef300b12016-10-07 15:12:09 -04004658void Context::attachShader(GLuint program, GLuint shader)
4659{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05004660 Program *programObject = mState.mShaderPrograms->getProgram(program);
4661 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004662 ASSERT(programObject && shaderObject);
4663 programObject->attachShader(shaderObject);
4664}
4665
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004666const Workarounds &Context::getWorkarounds() const
4667{
4668 return mWorkarounds;
4669}
4670
Corentin Wallez336129f2017-10-17 15:55:40 -04004671void Context::copyBufferSubData(BufferBinding readTarget,
4672 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04004673 GLintptr readOffset,
4674 GLintptr writeOffset,
4675 GLsizeiptr size)
4676{
4677 // if size is zero, the copy is a successful no-op
4678 if (size == 0)
4679 {
4680 return;
4681 }
4682
4683 // TODO(jmadill): cache these.
4684 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4685 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4686
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004687 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004688}
4689
Jamie Madill01a80ee2016-11-07 12:06:18 -05004690void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4691{
4692 Program *programObject = getProgram(program);
4693 // TODO(jmadill): Re-use this from the validation if possible.
4694 ASSERT(programObject);
4695 programObject->bindAttributeLocation(index, name);
4696}
4697
Corentin Wallez336129f2017-10-17 15:55:40 -04004698void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004699{
Corentin Wallez336129f2017-10-17 15:55:40 -04004700 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4701 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004702}
4703
Corentin Wallez336129f2017-10-17 15:55:40 -04004704void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08004705{
4706 bindBufferRange(target, index, buffer, 0, 0);
4707}
4708
Corentin Wallez336129f2017-10-17 15:55:40 -04004709void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08004710 GLuint index,
4711 GLuint buffer,
4712 GLintptr offset,
4713 GLsizeiptr size)
4714{
Corentin Wallez336129f2017-10-17 15:55:40 -04004715 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4716 mGLState.setIndexedBufferBinding(this, target, index, bufferObject, offset, size);
Jiajia Qin6eafb042016-12-27 17:04:07 +08004717}
4718
Jamie Madill01a80ee2016-11-07 12:06:18 -05004719void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
4720{
4721 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4722 {
4723 bindReadFramebuffer(framebuffer);
4724 }
4725
4726 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4727 {
4728 bindDrawFramebuffer(framebuffer);
4729 }
4730}
4731
4732void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4733{
4734 ASSERT(target == GL_RENDERBUFFER);
4735 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004736 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04004737 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004738}
4739
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004740void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08004741 GLsizei samples,
4742 GLenum internalformat,
4743 GLsizei width,
4744 GLsizei height,
4745 GLboolean fixedsamplelocations)
4746{
4747 Extents size(width, height, 1);
4748 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004749 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
4750 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004751}
4752
4753void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4754{
JiangYizhou5b03f472017-01-09 10:22:53 +08004755 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
4756 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillbc918e72018-03-08 09:47:21 -05004757 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
JiangYizhou5b03f472017-01-09 10:22:53 +08004758 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08004759
4760 switch (pname)
4761 {
4762 case GL_SAMPLE_POSITION:
4763 handleError(framebuffer->getSamplePosition(index, val));
4764 break;
4765 default:
4766 UNREACHABLE();
4767 }
4768}
4769
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07004770void Context::getMultisamplefvRobust(GLenum pname,
4771 GLuint index,
4772 GLsizei bufSize,
4773 GLsizei *length,
4774 GLfloat *val)
4775{
4776 UNIMPLEMENTED();
4777}
4778
Jamie Madille8fb6402017-02-14 17:56:40 -05004779void Context::renderbufferStorage(GLenum target,
4780 GLenum internalformat,
4781 GLsizei width,
4782 GLsizei height)
4783{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004784 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4785 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
4786
Jamie Madille8fb6402017-02-14 17:56:40 -05004787 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04004788 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004789}
4790
4791void Context::renderbufferStorageMultisample(GLenum target,
4792 GLsizei samples,
4793 GLenum internalformat,
4794 GLsizei width,
4795 GLsizei height)
4796{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004797 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4798 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05004799
4800 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004801 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04004802 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004803}
4804
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004805void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
4806{
Jamie Madill70b5bb02017-08-28 13:32:37 -04004807 const Sync *syncObject = getSync(sync);
Geoff Lang82483b92017-04-11 15:33:00 -04004808 handleError(QuerySynciv(syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004809}
4810
JiangYizhoue18e6392017-02-20 10:32:23 +08004811void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
4812{
4813 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4814 QueryFramebufferParameteriv(framebuffer, pname, params);
4815}
4816
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07004817void Context::getFramebufferParameterivRobust(GLenum target,
4818 GLenum pname,
4819 GLsizei bufSize,
4820 GLsizei *length,
4821 GLint *params)
4822{
4823 UNIMPLEMENTED();
4824}
4825
Jiajia Qin5451d532017-11-16 17:16:34 +08004826void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08004827{
4828 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4829 SetFramebufferParameteri(framebuffer, pname, param);
4830}
4831
Jamie Madillb3f26b92017-07-19 15:07:41 -04004832Error Context::getScratchBuffer(size_t requstedSizeBytes,
4833 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05004834{
Jamie Madillb3f26b92017-07-19 15:07:41 -04004835 if (!mScratchBuffer.get(requstedSizeBytes, scratchBufferOut))
4836 {
4837 return OutOfMemory() << "Failed to allocate internal buffer.";
4838 }
4839 return NoError();
4840}
4841
4842Error Context::getZeroFilledBuffer(size_t requstedSizeBytes,
4843 angle::MemoryBuffer **zeroBufferOut) const
4844{
4845 if (!mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0))
Jamie Madille14951e2017-03-09 18:55:16 -05004846 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004847 return OutOfMemory() << "Failed to allocate internal buffer.";
Jamie Madille14951e2017-03-09 18:55:16 -05004848 }
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004849 return NoError();
Jamie Madille14951e2017-03-09 18:55:16 -05004850}
4851
Xinghua Cao10a4d432017-11-28 14:46:26 +08004852Error Context::prepareForDispatch()
4853{
Geoff Langa8cb2872018-03-09 16:09:40 -05004854 ANGLE_TRY(syncState(mComputeDirtyBits, mComputeDirtyObjects));
Xinghua Cao10a4d432017-11-28 14:46:26 +08004855
4856 if (isRobustResourceInitEnabled())
4857 {
4858 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
4859 }
4860
4861 return NoError();
4862}
4863
Xinghua Cao2b396592017-03-29 15:36:04 +08004864void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
4865{
4866 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
4867 {
4868 return;
4869 }
4870
Xinghua Cao10a4d432017-11-28 14:46:26 +08004871 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill71c88b32017-09-14 22:20:29 -04004872 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08004873}
4874
Jiajia Qin5451d532017-11-16 17:16:34 +08004875void Context::dispatchComputeIndirect(GLintptr indirect)
4876{
Qin Jiajia62fcf622017-11-30 16:16:12 +08004877 ANGLE_CONTEXT_TRY(prepareForDispatch());
4878 handleError(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08004879}
4880
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004881void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08004882 GLsizei levels,
4883 GLenum internalFormat,
4884 GLsizei width,
4885 GLsizei height)
4886{
4887 Extents size(width, height, 1);
4888 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004889 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08004890}
4891
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004892void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08004893 GLsizei levels,
4894 GLenum internalFormat,
4895 GLsizei width,
4896 GLsizei height,
4897 GLsizei depth)
4898{
4899 Extents size(width, height, depth);
4900 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004901 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08004902}
4903
Jiajia Qin5451d532017-11-16 17:16:34 +08004904void Context::memoryBarrier(GLbitfield barriers)
4905{
Xinghua Cao89c422a2017-11-29 18:24:20 +08004906 handleError(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08004907}
4908
4909void Context::memoryBarrierByRegion(GLbitfield barriers)
4910{
Xinghua Cao89c422a2017-11-29 18:24:20 +08004911 handleError(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08004912}
4913
Jamie Madillc1d770e2017-04-13 17:31:24 -04004914GLenum Context::checkFramebufferStatus(GLenum target)
4915{
4916 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4917 ASSERT(framebuffer);
4918
Jamie Madille98b1b52018-03-08 09:47:23 -05004919 GLenum status = GL_NONE;
4920 Error err = framebuffer->checkStatus(this, &status);
4921 if (err.isError())
4922 {
4923 handleError(err);
4924 return 0;
4925 }
4926 return status;
Jamie Madillc1d770e2017-04-13 17:31:24 -04004927}
4928
4929void Context::compileShader(GLuint shader)
4930{
4931 Shader *shaderObject = GetValidShader(this, shader);
4932 if (!shaderObject)
4933 {
4934 return;
4935 }
4936 shaderObject->compile(this);
4937}
4938
4939void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
4940{
4941 for (int i = 0; i < n; i++)
4942 {
4943 deleteBuffer(buffers[i]);
4944 }
4945}
4946
4947void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
4948{
4949 for (int i = 0; i < n; i++)
4950 {
4951 if (framebuffers[i] != 0)
4952 {
4953 deleteFramebuffer(framebuffers[i]);
4954 }
4955 }
4956}
4957
4958void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
4959{
4960 for (int i = 0; i < n; i++)
4961 {
4962 deleteRenderbuffer(renderbuffers[i]);
4963 }
4964}
4965
4966void Context::deleteTextures(GLsizei n, const GLuint *textures)
4967{
4968 for (int i = 0; i < n; i++)
4969 {
4970 if (textures[i] != 0)
4971 {
4972 deleteTexture(textures[i]);
4973 }
4974 }
4975}
4976
4977void Context::detachShader(GLuint program, GLuint shader)
4978{
4979 Program *programObject = getProgram(program);
4980 ASSERT(programObject);
4981
4982 Shader *shaderObject = getShader(shader);
4983 ASSERT(shaderObject);
4984
4985 programObject->detachShader(this, shaderObject);
4986}
4987
4988void Context::genBuffers(GLsizei n, GLuint *buffers)
4989{
4990 for (int i = 0; i < n; i++)
4991 {
4992 buffers[i] = createBuffer();
4993 }
4994}
4995
4996void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
4997{
4998 for (int i = 0; i < n; i++)
4999 {
5000 framebuffers[i] = createFramebuffer();
5001 }
5002}
5003
5004void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
5005{
5006 for (int i = 0; i < n; i++)
5007 {
5008 renderbuffers[i] = createRenderbuffer();
5009 }
5010}
5011
5012void Context::genTextures(GLsizei n, GLuint *textures)
5013{
5014 for (int i = 0; i < n; i++)
5015 {
5016 textures[i] = createTexture();
5017 }
5018}
5019
5020void Context::getActiveAttrib(GLuint program,
5021 GLuint index,
5022 GLsizei bufsize,
5023 GLsizei *length,
5024 GLint *size,
5025 GLenum *type,
5026 GLchar *name)
5027{
5028 Program *programObject = getProgram(program);
5029 ASSERT(programObject);
5030 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
5031}
5032
5033void Context::getActiveUniform(GLuint program,
5034 GLuint index,
5035 GLsizei bufsize,
5036 GLsizei *length,
5037 GLint *size,
5038 GLenum *type,
5039 GLchar *name)
5040{
5041 Program *programObject = getProgram(program);
5042 ASSERT(programObject);
5043 programObject->getActiveUniform(index, bufsize, length, size, type, name);
5044}
5045
5046void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
5047{
5048 Program *programObject = getProgram(program);
5049 ASSERT(programObject);
5050 programObject->getAttachedShaders(maxcount, count, shaders);
5051}
5052
5053GLint Context::getAttribLocation(GLuint program, const GLchar *name)
5054{
5055 Program *programObject = getProgram(program);
5056 ASSERT(programObject);
5057 return programObject->getAttributeLocation(name);
5058}
5059
5060void Context::getBooleanv(GLenum pname, GLboolean *params)
5061{
5062 GLenum nativeType;
5063 unsigned int numParams = 0;
5064 getQueryParameterInfo(pname, &nativeType, &numParams);
5065
5066 if (nativeType == GL_BOOL)
5067 {
5068 getBooleanvImpl(pname, params);
5069 }
5070 else
5071 {
5072 CastStateValues(this, nativeType, pname, numParams, params);
5073 }
5074}
5075
Brandon Jones59770802018-04-02 13:18:42 -07005076void Context::getBooleanvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLboolean *params)
5077{
5078 getBooleanv(pname, params);
5079}
5080
Jamie Madillc1d770e2017-04-13 17:31:24 -04005081void Context::getFloatv(GLenum pname, GLfloat *params)
5082{
5083 GLenum nativeType;
5084 unsigned int numParams = 0;
5085 getQueryParameterInfo(pname, &nativeType, &numParams);
5086
5087 if (nativeType == GL_FLOAT)
5088 {
5089 getFloatvImpl(pname, params);
5090 }
5091 else
5092 {
5093 CastStateValues(this, nativeType, pname, numParams, params);
5094 }
5095}
5096
Brandon Jones59770802018-04-02 13:18:42 -07005097void Context::getFloatvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLfloat *params)
5098{
5099 getFloatv(pname, params);
5100}
5101
Jamie Madillc1d770e2017-04-13 17:31:24 -04005102void Context::getIntegerv(GLenum pname, GLint *params)
5103{
5104 GLenum nativeType;
5105 unsigned int numParams = 0;
5106 getQueryParameterInfo(pname, &nativeType, &numParams);
5107
5108 if (nativeType == GL_INT)
5109 {
5110 getIntegervImpl(pname, params);
5111 }
5112 else
5113 {
5114 CastStateValues(this, nativeType, pname, numParams, params);
5115 }
5116}
5117
Brandon Jones59770802018-04-02 13:18:42 -07005118void Context::getIntegervRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint *data)
5119{
5120 getIntegerv(pname, data);
5121}
5122
Jamie Madillc1d770e2017-04-13 17:31:24 -04005123void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
5124{
5125 Program *programObject = getProgram(program);
5126 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04005127 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005128}
5129
Brandon Jones59770802018-04-02 13:18:42 -07005130void Context::getProgramivRobust(GLuint program,
5131 GLenum pname,
5132 GLsizei bufSize,
5133 GLsizei *length,
5134 GLint *params)
5135{
5136 getProgramiv(program, pname, params);
5137}
5138
Jiajia Qin5451d532017-11-16 17:16:34 +08005139void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
5140{
5141 UNIMPLEMENTED();
5142}
5143
Jamie Madillbe849e42017-05-02 15:49:00 -04005144void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005145{
5146 Program *programObject = getProgram(program);
5147 ASSERT(programObject);
5148 programObject->getInfoLog(bufsize, length, infolog);
5149}
5150
Jiajia Qin5451d532017-11-16 17:16:34 +08005151void Context::getProgramPipelineInfoLog(GLuint pipeline,
5152 GLsizei bufSize,
5153 GLsizei *length,
5154 GLchar *infoLog)
5155{
5156 UNIMPLEMENTED();
5157}
5158
Jamie Madillc1d770e2017-04-13 17:31:24 -04005159void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
5160{
5161 Shader *shaderObject = getShader(shader);
5162 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04005163 QueryShaderiv(this, shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005164}
5165
Brandon Jones59770802018-04-02 13:18:42 -07005166void Context::getShaderivRobust(GLuint shader,
5167 GLenum pname,
5168 GLsizei bufSize,
5169 GLsizei *length,
5170 GLint *params)
5171{
5172 getShaderiv(shader, pname, params);
5173}
5174
Jamie Madillc1d770e2017-04-13 17:31:24 -04005175void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
5176{
5177 Shader *shaderObject = getShader(shader);
5178 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04005179 shaderObject->getInfoLog(this, bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005180}
5181
5182void Context::getShaderPrecisionFormat(GLenum shadertype,
5183 GLenum precisiontype,
5184 GLint *range,
5185 GLint *precision)
5186{
5187 // TODO(jmadill): Compute shaders.
5188
5189 switch (shadertype)
5190 {
5191 case GL_VERTEX_SHADER:
5192 switch (precisiontype)
5193 {
5194 case GL_LOW_FLOAT:
5195 mCaps.vertexLowpFloat.get(range, precision);
5196 break;
5197 case GL_MEDIUM_FLOAT:
5198 mCaps.vertexMediumpFloat.get(range, precision);
5199 break;
5200 case GL_HIGH_FLOAT:
5201 mCaps.vertexHighpFloat.get(range, precision);
5202 break;
5203
5204 case GL_LOW_INT:
5205 mCaps.vertexLowpInt.get(range, precision);
5206 break;
5207 case GL_MEDIUM_INT:
5208 mCaps.vertexMediumpInt.get(range, precision);
5209 break;
5210 case GL_HIGH_INT:
5211 mCaps.vertexHighpInt.get(range, precision);
5212 break;
5213
5214 default:
5215 UNREACHABLE();
5216 return;
5217 }
5218 break;
5219
5220 case GL_FRAGMENT_SHADER:
5221 switch (precisiontype)
5222 {
5223 case GL_LOW_FLOAT:
5224 mCaps.fragmentLowpFloat.get(range, precision);
5225 break;
5226 case GL_MEDIUM_FLOAT:
5227 mCaps.fragmentMediumpFloat.get(range, precision);
5228 break;
5229 case GL_HIGH_FLOAT:
5230 mCaps.fragmentHighpFloat.get(range, precision);
5231 break;
5232
5233 case GL_LOW_INT:
5234 mCaps.fragmentLowpInt.get(range, precision);
5235 break;
5236 case GL_MEDIUM_INT:
5237 mCaps.fragmentMediumpInt.get(range, precision);
5238 break;
5239 case GL_HIGH_INT:
5240 mCaps.fragmentHighpInt.get(range, precision);
5241 break;
5242
5243 default:
5244 UNREACHABLE();
5245 return;
5246 }
5247 break;
5248
5249 default:
5250 UNREACHABLE();
5251 return;
5252 }
5253}
5254
5255void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
5256{
5257 Shader *shaderObject = getShader(shader);
5258 ASSERT(shaderObject);
5259 shaderObject->getSource(bufsize, length, source);
5260}
5261
5262void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
5263{
5264 Program *programObject = getProgram(program);
5265 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005266 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005267}
5268
Brandon Jones59770802018-04-02 13:18:42 -07005269void Context::getUniformfvRobust(GLuint program,
5270 GLint location,
5271 GLsizei bufSize,
5272 GLsizei *length,
5273 GLfloat *params)
5274{
5275 getUniformfv(program, location, params);
5276}
5277
Jamie Madillc1d770e2017-04-13 17:31:24 -04005278void Context::getUniformiv(GLuint program, GLint location, GLint *params)
5279{
5280 Program *programObject = getProgram(program);
5281 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005282 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005283}
5284
Brandon Jones59770802018-04-02 13:18:42 -07005285void Context::getUniformivRobust(GLuint program,
5286 GLint location,
5287 GLsizei bufSize,
5288 GLsizei *length,
5289 GLint *params)
5290{
5291 getUniformiv(program, location, params);
5292}
5293
Jamie Madillc1d770e2017-04-13 17:31:24 -04005294GLint Context::getUniformLocation(GLuint program, const GLchar *name)
5295{
5296 Program *programObject = getProgram(program);
5297 ASSERT(programObject);
5298 return programObject->getUniformLocation(name);
5299}
5300
5301GLboolean Context::isBuffer(GLuint buffer)
5302{
5303 if (buffer == 0)
5304 {
5305 return GL_FALSE;
5306 }
5307
5308 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
5309}
5310
5311GLboolean Context::isEnabled(GLenum cap)
5312{
5313 return mGLState.getEnableFeature(cap);
5314}
5315
5316GLboolean Context::isFramebuffer(GLuint framebuffer)
5317{
5318 if (framebuffer == 0)
5319 {
5320 return GL_FALSE;
5321 }
5322
5323 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
5324}
5325
5326GLboolean Context::isProgram(GLuint program)
5327{
5328 if (program == 0)
5329 {
5330 return GL_FALSE;
5331 }
5332
5333 return (getProgram(program) ? GL_TRUE : GL_FALSE);
5334}
5335
5336GLboolean Context::isRenderbuffer(GLuint renderbuffer)
5337{
5338 if (renderbuffer == 0)
5339 {
5340 return GL_FALSE;
5341 }
5342
5343 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
5344}
5345
5346GLboolean Context::isShader(GLuint shader)
5347{
5348 if (shader == 0)
5349 {
5350 return GL_FALSE;
5351 }
5352
5353 return (getShader(shader) ? GL_TRUE : GL_FALSE);
5354}
5355
5356GLboolean Context::isTexture(GLuint texture)
5357{
5358 if (texture == 0)
5359 {
5360 return GL_FALSE;
5361 }
5362
5363 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
5364}
5365
5366void Context::linkProgram(GLuint program)
5367{
5368 Program *programObject = getProgram(program);
5369 ASSERT(programObject);
5370 handleError(programObject->link(this));
Martin Radev0abb7a22017-08-28 15:34:45 +03005371 mGLState.onProgramExecutableChange(programObject);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005372}
5373
5374void Context::releaseShaderCompiler()
5375{
Jamie Madill4928b7c2017-06-20 12:57:39 -04005376 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005377}
5378
5379void Context::shaderBinary(GLsizei n,
5380 const GLuint *shaders,
5381 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04005382 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005383 GLsizei length)
5384{
5385 // No binary shader formats are supported.
5386 UNIMPLEMENTED();
5387}
5388
5389void Context::shaderSource(GLuint shader,
5390 GLsizei count,
5391 const GLchar *const *string,
5392 const GLint *length)
5393{
5394 Shader *shaderObject = getShader(shader);
5395 ASSERT(shaderObject);
5396 shaderObject->setSource(count, string, length);
5397}
5398
5399void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
5400{
5401 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
5402}
5403
5404void Context::stencilMask(GLuint mask)
5405{
5406 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
5407}
5408
5409void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
5410{
5411 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
5412}
5413
5414void Context::uniform1f(GLint location, GLfloat x)
5415{
5416 Program *program = mGLState.getProgram();
5417 program->setUniform1fv(location, 1, &x);
5418}
5419
5420void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
5421{
5422 Program *program = mGLState.getProgram();
5423 program->setUniform1fv(location, count, v);
5424}
5425
5426void Context::uniform1i(GLint location, GLint x)
5427{
5428 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04005429 if (program->setUniform1iv(location, 1, &x) == Program::SetUniformResult::SamplerChanged)
5430 {
5431 mGLState.setObjectDirty(GL_PROGRAM);
5432 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005433}
5434
5435void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
5436{
5437 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04005438 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
5439 {
5440 mGLState.setObjectDirty(GL_PROGRAM);
5441 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005442}
5443
5444void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
5445{
5446 GLfloat xy[2] = {x, y};
5447 Program *program = mGLState.getProgram();
5448 program->setUniform2fv(location, 1, xy);
5449}
5450
5451void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
5452{
5453 Program *program = mGLState.getProgram();
5454 program->setUniform2fv(location, count, v);
5455}
5456
5457void Context::uniform2i(GLint location, GLint x, GLint y)
5458{
5459 GLint xy[2] = {x, y};
5460 Program *program = mGLState.getProgram();
5461 program->setUniform2iv(location, 1, xy);
5462}
5463
5464void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
5465{
5466 Program *program = mGLState.getProgram();
5467 program->setUniform2iv(location, count, v);
5468}
5469
5470void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
5471{
5472 GLfloat xyz[3] = {x, y, z};
5473 Program *program = mGLState.getProgram();
5474 program->setUniform3fv(location, 1, xyz);
5475}
5476
5477void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
5478{
5479 Program *program = mGLState.getProgram();
5480 program->setUniform3fv(location, count, v);
5481}
5482
5483void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
5484{
5485 GLint xyz[3] = {x, y, z};
5486 Program *program = mGLState.getProgram();
5487 program->setUniform3iv(location, 1, xyz);
5488}
5489
5490void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
5491{
5492 Program *program = mGLState.getProgram();
5493 program->setUniform3iv(location, count, v);
5494}
5495
5496void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
5497{
5498 GLfloat xyzw[4] = {x, y, z, w};
5499 Program *program = mGLState.getProgram();
5500 program->setUniform4fv(location, 1, xyzw);
5501}
5502
5503void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
5504{
5505 Program *program = mGLState.getProgram();
5506 program->setUniform4fv(location, count, v);
5507}
5508
5509void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
5510{
5511 GLint xyzw[4] = {x, y, z, w};
5512 Program *program = mGLState.getProgram();
5513 program->setUniform4iv(location, 1, xyzw);
5514}
5515
5516void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
5517{
5518 Program *program = mGLState.getProgram();
5519 program->setUniform4iv(location, count, v);
5520}
5521
5522void Context::uniformMatrix2fv(GLint location,
5523 GLsizei count,
5524 GLboolean transpose,
5525 const GLfloat *value)
5526{
5527 Program *program = mGLState.getProgram();
5528 program->setUniformMatrix2fv(location, count, transpose, value);
5529}
5530
5531void Context::uniformMatrix3fv(GLint location,
5532 GLsizei count,
5533 GLboolean transpose,
5534 const GLfloat *value)
5535{
5536 Program *program = mGLState.getProgram();
5537 program->setUniformMatrix3fv(location, count, transpose, value);
5538}
5539
5540void Context::uniformMatrix4fv(GLint location,
5541 GLsizei count,
5542 GLboolean transpose,
5543 const GLfloat *value)
5544{
5545 Program *program = mGLState.getProgram();
5546 program->setUniformMatrix4fv(location, count, transpose, value);
5547}
5548
5549void Context::validateProgram(GLuint program)
5550{
5551 Program *programObject = getProgram(program);
5552 ASSERT(programObject);
5553 programObject->validate(mCaps);
5554}
5555
Jiajia Qin5451d532017-11-16 17:16:34 +08005556void Context::validateProgramPipeline(GLuint pipeline)
5557{
5558 UNIMPLEMENTED();
5559}
5560
Jamie Madilld04908b2017-06-09 14:15:35 -04005561void Context::getProgramBinary(GLuint program,
5562 GLsizei bufSize,
5563 GLsizei *length,
5564 GLenum *binaryFormat,
5565 void *binary)
5566{
5567 Program *programObject = getProgram(program);
5568 ASSERT(programObject != nullptr);
5569
5570 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
5571}
5572
5573void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
5574{
5575 Program *programObject = getProgram(program);
5576 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04005577
Jamie Madilld04908b2017-06-09 14:15:35 -04005578 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
5579}
5580
Jamie Madillff325f12017-08-26 15:06:05 -04005581void Context::uniform1ui(GLint location, GLuint v0)
5582{
5583 Program *program = mGLState.getProgram();
5584 program->setUniform1uiv(location, 1, &v0);
5585}
5586
5587void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
5588{
5589 Program *program = mGLState.getProgram();
5590 const GLuint xy[] = {v0, v1};
5591 program->setUniform2uiv(location, 1, xy);
5592}
5593
5594void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
5595{
5596 Program *program = mGLState.getProgram();
5597 const GLuint xyz[] = {v0, v1, v2};
5598 program->setUniform3uiv(location, 1, xyz);
5599}
5600
5601void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
5602{
5603 Program *program = mGLState.getProgram();
5604 const GLuint xyzw[] = {v0, v1, v2, v3};
5605 program->setUniform4uiv(location, 1, xyzw);
5606}
5607
5608void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
5609{
5610 Program *program = mGLState.getProgram();
5611 program->setUniform1uiv(location, count, value);
5612}
5613void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
5614{
5615 Program *program = mGLState.getProgram();
5616 program->setUniform2uiv(location, count, value);
5617}
5618
5619void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
5620{
5621 Program *program = mGLState.getProgram();
5622 program->setUniform3uiv(location, count, value);
5623}
5624
5625void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
5626{
5627 Program *program = mGLState.getProgram();
5628 program->setUniform4uiv(location, count, value);
5629}
5630
Jamie Madillf0e04492017-08-26 15:28:42 -04005631void Context::genQueries(GLsizei n, GLuint *ids)
5632{
5633 for (GLsizei i = 0; i < n; i++)
5634 {
5635 GLuint handle = mQueryHandleAllocator.allocate();
5636 mQueryMap.assign(handle, nullptr);
5637 ids[i] = handle;
5638 }
5639}
5640
5641void Context::deleteQueries(GLsizei n, const GLuint *ids)
5642{
5643 for (int i = 0; i < n; i++)
5644 {
5645 GLuint query = ids[i];
5646
5647 Query *queryObject = nullptr;
5648 if (mQueryMap.erase(query, &queryObject))
5649 {
5650 mQueryHandleAllocator.release(query);
5651 if (queryObject)
5652 {
5653 queryObject->release(this);
5654 }
5655 }
5656 }
5657}
5658
5659GLboolean Context::isQuery(GLuint id)
5660{
5661 return (getQuery(id, false, GL_NONE) != nullptr) ? GL_TRUE : GL_FALSE;
5662}
5663
Jamie Madillc8c95812017-08-26 18:40:09 -04005664void Context::uniformMatrix2x3fv(GLint location,
5665 GLsizei count,
5666 GLboolean transpose,
5667 const GLfloat *value)
5668{
5669 Program *program = mGLState.getProgram();
5670 program->setUniformMatrix2x3fv(location, count, transpose, value);
5671}
5672
5673void Context::uniformMatrix3x2fv(GLint location,
5674 GLsizei count,
5675 GLboolean transpose,
5676 const GLfloat *value)
5677{
5678 Program *program = mGLState.getProgram();
5679 program->setUniformMatrix3x2fv(location, count, transpose, value);
5680}
5681
5682void Context::uniformMatrix2x4fv(GLint location,
5683 GLsizei count,
5684 GLboolean transpose,
5685 const GLfloat *value)
5686{
5687 Program *program = mGLState.getProgram();
5688 program->setUniformMatrix2x4fv(location, count, transpose, value);
5689}
5690
5691void Context::uniformMatrix4x2fv(GLint location,
5692 GLsizei count,
5693 GLboolean transpose,
5694 const GLfloat *value)
5695{
5696 Program *program = mGLState.getProgram();
5697 program->setUniformMatrix4x2fv(location, count, transpose, value);
5698}
5699
5700void Context::uniformMatrix3x4fv(GLint location,
5701 GLsizei count,
5702 GLboolean transpose,
5703 const GLfloat *value)
5704{
5705 Program *program = mGLState.getProgram();
5706 program->setUniformMatrix3x4fv(location, count, transpose, value);
5707}
5708
5709void Context::uniformMatrix4x3fv(GLint location,
5710 GLsizei count,
5711 GLboolean transpose,
5712 const GLfloat *value)
5713{
5714 Program *program = mGLState.getProgram();
5715 program->setUniformMatrix4x3fv(location, count, transpose, value);
5716}
5717
Jamie Madilld7576732017-08-26 18:49:50 -04005718void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
5719{
5720 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5721 {
5722 GLuint vertexArray = arrays[arrayIndex];
5723
5724 if (arrays[arrayIndex] != 0)
5725 {
5726 VertexArray *vertexArrayObject = nullptr;
5727 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
5728 {
5729 if (vertexArrayObject != nullptr)
5730 {
5731 detachVertexArray(vertexArray);
5732 vertexArrayObject->onDestroy(this);
5733 }
5734
5735 mVertexArrayHandleAllocator.release(vertexArray);
5736 }
5737 }
5738 }
5739}
5740
5741void Context::genVertexArrays(GLsizei n, GLuint *arrays)
5742{
5743 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5744 {
5745 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
5746 mVertexArrayMap.assign(vertexArray, nullptr);
5747 arrays[arrayIndex] = vertexArray;
5748 }
5749}
5750
5751bool Context::isVertexArray(GLuint array)
5752{
5753 if (array == 0)
5754 {
5755 return GL_FALSE;
5756 }
5757
5758 VertexArray *vao = getVertexArray(array);
5759 return (vao != nullptr ? GL_TRUE : GL_FALSE);
5760}
5761
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04005762void Context::endTransformFeedback()
5763{
5764 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5765 transformFeedback->end(this);
5766}
5767
5768void Context::transformFeedbackVaryings(GLuint program,
5769 GLsizei count,
5770 const GLchar *const *varyings,
5771 GLenum bufferMode)
5772{
5773 Program *programObject = getProgram(program);
5774 ASSERT(programObject);
5775 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
5776}
5777
5778void Context::getTransformFeedbackVarying(GLuint program,
5779 GLuint index,
5780 GLsizei bufSize,
5781 GLsizei *length,
5782 GLsizei *size,
5783 GLenum *type,
5784 GLchar *name)
5785{
5786 Program *programObject = getProgram(program);
5787 ASSERT(programObject);
5788 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
5789}
5790
5791void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
5792{
5793 for (int i = 0; i < n; i++)
5794 {
5795 GLuint transformFeedback = ids[i];
5796 if (transformFeedback == 0)
5797 {
5798 continue;
5799 }
5800
5801 TransformFeedback *transformFeedbackObject = nullptr;
5802 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
5803 {
5804 if (transformFeedbackObject != nullptr)
5805 {
5806 detachTransformFeedback(transformFeedback);
5807 transformFeedbackObject->release(this);
5808 }
5809
5810 mTransformFeedbackHandleAllocator.release(transformFeedback);
5811 }
5812 }
5813}
5814
5815void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
5816{
5817 for (int i = 0; i < n; i++)
5818 {
5819 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
5820 mTransformFeedbackMap.assign(transformFeedback, nullptr);
5821 ids[i] = transformFeedback;
5822 }
5823}
5824
5825bool Context::isTransformFeedback(GLuint id)
5826{
5827 if (id == 0)
5828 {
5829 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
5830 // returns FALSE
5831 return GL_FALSE;
5832 }
5833
5834 const TransformFeedback *transformFeedback = getTransformFeedback(id);
5835 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
5836}
5837
5838void Context::pauseTransformFeedback()
5839{
5840 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5841 transformFeedback->pause();
5842}
5843
5844void Context::resumeTransformFeedback()
5845{
5846 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5847 transformFeedback->resume();
5848}
5849
Jamie Madill12e957f2017-08-26 21:42:26 -04005850void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
5851{
5852 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04005853 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04005854}
5855
Brandon Jones59770802018-04-02 13:18:42 -07005856void Context::getUniformuivRobust(GLuint program,
5857 GLint location,
5858 GLsizei bufSize,
5859 GLsizei *length,
5860 GLuint *params)
5861{
5862 getUniformuiv(program, location, params);
5863}
5864
Jamie Madill12e957f2017-08-26 21:42:26 -04005865GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
5866{
5867 const Program *programObject = getProgram(program);
5868 return programObject->getFragDataLocation(name);
5869}
5870
5871void Context::getUniformIndices(GLuint program,
5872 GLsizei uniformCount,
5873 const GLchar *const *uniformNames,
5874 GLuint *uniformIndices)
5875{
5876 const Program *programObject = getProgram(program);
5877 if (!programObject->isLinked())
5878 {
5879 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5880 {
5881 uniformIndices[uniformId] = GL_INVALID_INDEX;
5882 }
5883 }
5884 else
5885 {
5886 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5887 {
5888 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
5889 }
5890 }
5891}
5892
5893void Context::getActiveUniformsiv(GLuint program,
5894 GLsizei uniformCount,
5895 const GLuint *uniformIndices,
5896 GLenum pname,
5897 GLint *params)
5898{
5899 const Program *programObject = getProgram(program);
5900 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5901 {
5902 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08005903 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04005904 }
5905}
5906
5907GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
5908{
5909 const Program *programObject = getProgram(program);
5910 return programObject->getUniformBlockIndex(uniformBlockName);
5911}
5912
5913void Context::getActiveUniformBlockiv(GLuint program,
5914 GLuint uniformBlockIndex,
5915 GLenum pname,
5916 GLint *params)
5917{
5918 const Program *programObject = getProgram(program);
5919 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
5920}
5921
Brandon Jones59770802018-04-02 13:18:42 -07005922void Context::getActiveUniformBlockivRobust(GLuint program,
5923 GLuint uniformBlockIndex,
5924 GLenum pname,
5925 GLsizei bufSize,
5926 GLsizei *length,
5927 GLint *params)
5928{
5929 getActiveUniformBlockiv(program, uniformBlockIndex, pname, params);
5930}
5931
Jamie Madill12e957f2017-08-26 21:42:26 -04005932void Context::getActiveUniformBlockName(GLuint program,
5933 GLuint uniformBlockIndex,
5934 GLsizei bufSize,
5935 GLsizei *length,
5936 GLchar *uniformBlockName)
5937{
5938 const Program *programObject = getProgram(program);
5939 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
5940}
5941
5942void Context::uniformBlockBinding(GLuint program,
5943 GLuint uniformBlockIndex,
5944 GLuint uniformBlockBinding)
5945{
5946 Program *programObject = getProgram(program);
5947 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
5948}
5949
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005950GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
5951{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005952 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
5953 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005954
Jamie Madill70b5bb02017-08-28 13:32:37 -04005955 Sync *syncObject = getSync(syncHandle);
5956 Error error = syncObject->set(condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005957 if (error.isError())
5958 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04005959 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005960 handleError(error);
5961 return nullptr;
5962 }
5963
Jamie Madill70b5bb02017-08-28 13:32:37 -04005964 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005965}
5966
5967GLboolean Context::isSync(GLsync sync)
5968{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005969 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005970}
5971
5972GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
5973{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005974 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005975
5976 GLenum result = GL_WAIT_FAILED;
5977 handleError(syncObject->clientWait(flags, timeout, &result));
5978 return result;
5979}
5980
5981void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
5982{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005983 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005984 handleError(syncObject->serverWait(flags, timeout));
5985}
5986
5987void Context::getInteger64v(GLenum pname, GLint64 *params)
5988{
5989 GLenum nativeType = GL_NONE;
5990 unsigned int numParams = 0;
5991 getQueryParameterInfo(pname, &nativeType, &numParams);
5992
5993 if (nativeType == GL_INT_64_ANGLEX)
5994 {
5995 getInteger64vImpl(pname, params);
5996 }
5997 else
5998 {
5999 CastStateValues(this, nativeType, pname, numParams, params);
6000 }
6001}
6002
Brandon Jones59770802018-04-02 13:18:42 -07006003void Context::getInteger64vRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint64 *data)
6004{
6005 getInteger64v(pname, data);
6006}
6007
Corentin Wallez336129f2017-10-17 15:55:40 -04006008void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04006009{
6010 Buffer *buffer = mGLState.getTargetBuffer(target);
6011 QueryBufferParameteri64v(buffer, pname, params);
6012}
6013
Brandon Jones59770802018-04-02 13:18:42 -07006014void Context::getBufferParameteri64vRobust(BufferBinding target,
6015 GLenum pname,
6016 GLsizei bufSize,
6017 GLsizei *length,
6018 GLint64 *params)
6019{
6020 getBufferParameteri64v(target, pname, params);
6021}
6022
Jamie Madill3ef140a2017-08-26 23:11:21 -04006023void Context::genSamplers(GLsizei count, GLuint *samplers)
6024{
6025 for (int i = 0; i < count; i++)
6026 {
6027 samplers[i] = mState.mSamplers->createSampler();
6028 }
6029}
6030
6031void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
6032{
6033 for (int i = 0; i < count; i++)
6034 {
6035 GLuint sampler = samplers[i];
6036
6037 if (mState.mSamplers->getSampler(sampler))
6038 {
6039 detachSampler(sampler);
6040 }
6041
6042 mState.mSamplers->deleteObject(this, sampler);
6043 }
6044}
6045
6046void Context::getInternalformativ(GLenum target,
6047 GLenum internalformat,
6048 GLenum pname,
6049 GLsizei bufSize,
6050 GLint *params)
6051{
6052 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
6053 QueryInternalFormativ(formatCaps, pname, bufSize, params);
6054}
6055
Brandon Jones59770802018-04-02 13:18:42 -07006056void Context::getInternalformativRobust(GLenum target,
6057 GLenum internalformat,
6058 GLenum pname,
6059 GLsizei bufSize,
6060 GLsizei *length,
6061 GLint *params)
6062{
6063 getInternalformativ(target, internalformat, pname, bufSize, params);
6064}
6065
Jiajia Qin5451d532017-11-16 17:16:34 +08006066void Context::programUniform1i(GLuint program, GLint location, GLint v0)
6067{
6068 programUniform1iv(program, location, 1, &v0);
6069}
6070
6071void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
6072{
6073 GLint xy[2] = {v0, v1};
6074 programUniform2iv(program, location, 1, xy);
6075}
6076
6077void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
6078{
6079 GLint xyz[3] = {v0, v1, v2};
6080 programUniform3iv(program, location, 1, xyz);
6081}
6082
6083void Context::programUniform4i(GLuint program,
6084 GLint location,
6085 GLint v0,
6086 GLint v1,
6087 GLint v2,
6088 GLint v3)
6089{
6090 GLint xyzw[4] = {v0, v1, v2, v3};
6091 programUniform4iv(program, location, 1, xyzw);
6092}
6093
6094void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
6095{
6096 programUniform1uiv(program, location, 1, &v0);
6097}
6098
6099void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
6100{
6101 GLuint xy[2] = {v0, v1};
6102 programUniform2uiv(program, location, 1, xy);
6103}
6104
6105void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
6106{
6107 GLuint xyz[3] = {v0, v1, v2};
6108 programUniform3uiv(program, location, 1, xyz);
6109}
6110
6111void Context::programUniform4ui(GLuint program,
6112 GLint location,
6113 GLuint v0,
6114 GLuint v1,
6115 GLuint v2,
6116 GLuint v3)
6117{
6118 GLuint xyzw[4] = {v0, v1, v2, v3};
6119 programUniform4uiv(program, location, 1, xyzw);
6120}
6121
6122void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
6123{
6124 programUniform1fv(program, location, 1, &v0);
6125}
6126
6127void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
6128{
6129 GLfloat xy[2] = {v0, v1};
6130 programUniform2fv(program, location, 1, xy);
6131}
6132
6133void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
6134{
6135 GLfloat xyz[3] = {v0, v1, v2};
6136 programUniform3fv(program, location, 1, xyz);
6137}
6138
6139void Context::programUniform4f(GLuint program,
6140 GLint location,
6141 GLfloat v0,
6142 GLfloat v1,
6143 GLfloat v2,
6144 GLfloat v3)
6145{
6146 GLfloat xyzw[4] = {v0, v1, v2, v3};
6147 programUniform4fv(program, location, 1, xyzw);
6148}
6149
Jamie Madill81c2e252017-09-09 23:32:46 -04006150void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6151{
6152 Program *programObject = getProgram(program);
6153 ASSERT(programObject);
6154 if (programObject->setUniform1iv(location, count, value) ==
6155 Program::SetUniformResult::SamplerChanged)
6156 {
6157 mGLState.setObjectDirty(GL_PROGRAM);
6158 }
6159}
6160
Jiajia Qin5451d532017-11-16 17:16:34 +08006161void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6162{
6163 Program *programObject = getProgram(program);
6164 ASSERT(programObject);
6165 programObject->setUniform2iv(location, count, value);
6166}
6167
6168void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6169{
6170 Program *programObject = getProgram(program);
6171 ASSERT(programObject);
6172 programObject->setUniform3iv(location, count, value);
6173}
6174
6175void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6176{
6177 Program *programObject = getProgram(program);
6178 ASSERT(programObject);
6179 programObject->setUniform4iv(location, count, value);
6180}
6181
6182void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6183{
6184 Program *programObject = getProgram(program);
6185 ASSERT(programObject);
6186 programObject->setUniform1uiv(location, count, value);
6187}
6188
6189void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6190{
6191 Program *programObject = getProgram(program);
6192 ASSERT(programObject);
6193 programObject->setUniform2uiv(location, count, value);
6194}
6195
6196void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6197{
6198 Program *programObject = getProgram(program);
6199 ASSERT(programObject);
6200 programObject->setUniform3uiv(location, count, value);
6201}
6202
6203void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6204{
6205 Program *programObject = getProgram(program);
6206 ASSERT(programObject);
6207 programObject->setUniform4uiv(location, count, value);
6208}
6209
6210void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6211{
6212 Program *programObject = getProgram(program);
6213 ASSERT(programObject);
6214 programObject->setUniform1fv(location, count, value);
6215}
6216
6217void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6218{
6219 Program *programObject = getProgram(program);
6220 ASSERT(programObject);
6221 programObject->setUniform2fv(location, count, value);
6222}
6223
6224void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6225{
6226 Program *programObject = getProgram(program);
6227 ASSERT(programObject);
6228 programObject->setUniform3fv(location, count, value);
6229}
6230
6231void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6232{
6233 Program *programObject = getProgram(program);
6234 ASSERT(programObject);
6235 programObject->setUniform4fv(location, count, value);
6236}
6237
6238void Context::programUniformMatrix2fv(GLuint program,
6239 GLint location,
6240 GLsizei count,
6241 GLboolean transpose,
6242 const GLfloat *value)
6243{
6244 Program *programObject = getProgram(program);
6245 ASSERT(programObject);
6246 programObject->setUniformMatrix2fv(location, count, transpose, value);
6247}
6248
6249void Context::programUniformMatrix3fv(GLuint program,
6250 GLint location,
6251 GLsizei count,
6252 GLboolean transpose,
6253 const GLfloat *value)
6254{
6255 Program *programObject = getProgram(program);
6256 ASSERT(programObject);
6257 programObject->setUniformMatrix3fv(location, count, transpose, value);
6258}
6259
6260void Context::programUniformMatrix4fv(GLuint program,
6261 GLint location,
6262 GLsizei count,
6263 GLboolean transpose,
6264 const GLfloat *value)
6265{
6266 Program *programObject = getProgram(program);
6267 ASSERT(programObject);
6268 programObject->setUniformMatrix4fv(location, count, transpose, value);
6269}
6270
6271void Context::programUniformMatrix2x3fv(GLuint program,
6272 GLint location,
6273 GLsizei count,
6274 GLboolean transpose,
6275 const GLfloat *value)
6276{
6277 Program *programObject = getProgram(program);
6278 ASSERT(programObject);
6279 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
6280}
6281
6282void Context::programUniformMatrix3x2fv(GLuint program,
6283 GLint location,
6284 GLsizei count,
6285 GLboolean transpose,
6286 const GLfloat *value)
6287{
6288 Program *programObject = getProgram(program);
6289 ASSERT(programObject);
6290 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
6291}
6292
6293void Context::programUniformMatrix2x4fv(GLuint program,
6294 GLint location,
6295 GLsizei count,
6296 GLboolean transpose,
6297 const GLfloat *value)
6298{
6299 Program *programObject = getProgram(program);
6300 ASSERT(programObject);
6301 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
6302}
6303
6304void Context::programUniformMatrix4x2fv(GLuint program,
6305 GLint location,
6306 GLsizei count,
6307 GLboolean transpose,
6308 const GLfloat *value)
6309{
6310 Program *programObject = getProgram(program);
6311 ASSERT(programObject);
6312 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
6313}
6314
6315void Context::programUniformMatrix3x4fv(GLuint program,
6316 GLint location,
6317 GLsizei count,
6318 GLboolean transpose,
6319 const GLfloat *value)
6320{
6321 Program *programObject = getProgram(program);
6322 ASSERT(programObject);
6323 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
6324}
6325
6326void Context::programUniformMatrix4x3fv(GLuint program,
6327 GLint location,
6328 GLsizei count,
6329 GLboolean transpose,
6330 const GLfloat *value)
6331{
6332 Program *programObject = getProgram(program);
6333 ASSERT(programObject);
6334 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
6335}
6336
Jamie Madill81c2e252017-09-09 23:32:46 -04006337void Context::onTextureChange(const Texture *texture)
6338{
6339 // Conservatively assume all textures are dirty.
6340 // TODO(jmadill): More fine-grained update.
6341 mGLState.setObjectDirty(GL_TEXTURE);
6342}
6343
James Darpiniane8a93c62018-01-04 18:02:24 -08006344bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
6345{
6346 return mGLState.isCurrentTransformFeedback(tf);
6347}
6348bool Context::isCurrentVertexArray(const VertexArray *va) const
6349{
6350 return mGLState.isCurrentVertexArray(va);
6351}
6352
Yunchao Hea336b902017-08-02 16:05:21 +08006353void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
6354{
6355 for (int i = 0; i < count; i++)
6356 {
6357 pipelines[i] = createProgramPipeline();
6358 }
6359}
6360
6361void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
6362{
6363 for (int i = 0; i < count; i++)
6364 {
6365 if (pipelines[i] != 0)
6366 {
6367 deleteProgramPipeline(pipelines[i]);
6368 }
6369 }
6370}
6371
6372GLboolean Context::isProgramPipeline(GLuint pipeline)
6373{
6374 if (pipeline == 0)
6375 {
6376 return GL_FALSE;
6377 }
6378
6379 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
6380}
6381
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006382void Context::finishFenceNV(GLuint fence)
6383{
6384 FenceNV *fenceObject = getFenceNV(fence);
6385
6386 ASSERT(fenceObject && fenceObject->isSet());
6387 handleError(fenceObject->finish());
6388}
6389
6390void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
6391{
6392 FenceNV *fenceObject = getFenceNV(fence);
6393
6394 ASSERT(fenceObject && fenceObject->isSet());
6395
6396 switch (pname)
6397 {
6398 case GL_FENCE_STATUS_NV:
6399 {
6400 // GL_NV_fence spec:
6401 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
6402 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
6403 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
6404 GLboolean status = GL_TRUE;
6405 if (fenceObject->getStatus() != GL_TRUE)
6406 {
6407 ANGLE_CONTEXT_TRY(fenceObject->test(&status));
6408 }
6409 *params = status;
6410 break;
6411 }
6412
6413 case GL_FENCE_CONDITION_NV:
6414 {
6415 *params = static_cast<GLint>(fenceObject->getCondition());
6416 break;
6417 }
6418
6419 default:
6420 UNREACHABLE();
6421 }
6422}
6423
6424void Context::getTranslatedShaderSource(GLuint shader,
6425 GLsizei bufsize,
6426 GLsizei *length,
6427 GLchar *source)
6428{
6429 Shader *shaderObject = getShader(shader);
6430 ASSERT(shaderObject);
6431 shaderObject->getTranslatedSourceWithDebugInfo(this, bufsize, length, source);
6432}
6433
6434void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
6435{
6436 Program *programObject = getProgram(program);
6437 ASSERT(programObject);
6438
6439 programObject->getUniformfv(this, location, params);
6440}
6441
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006442void Context::getnUniformfvRobust(GLuint program,
6443 GLint location,
6444 GLsizei bufSize,
6445 GLsizei *length,
6446 GLfloat *params)
6447{
6448 UNIMPLEMENTED();
6449}
6450
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006451void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
6452{
6453 Program *programObject = getProgram(program);
6454 ASSERT(programObject);
6455
6456 programObject->getUniformiv(this, location, params);
6457}
6458
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006459void Context::getnUniformivRobust(GLuint program,
6460 GLint location,
6461 GLsizei bufSize,
6462 GLsizei *length,
6463 GLint *params)
6464{
6465 UNIMPLEMENTED();
6466}
6467
6468void Context::getnUniformuivRobust(GLuint program,
6469 GLint location,
6470 GLsizei bufSize,
6471 GLsizei *length,
6472 GLuint *params)
6473{
6474 UNIMPLEMENTED();
6475}
6476
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006477GLboolean Context::isFenceNV(GLuint fence)
6478{
6479 FenceNV *fenceObject = getFenceNV(fence);
6480
6481 if (fenceObject == nullptr)
6482 {
6483 return GL_FALSE;
6484 }
6485
6486 // GL_NV_fence spec:
6487 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
6488 // existing fence.
6489 return fenceObject->isSet();
6490}
6491
6492void Context::readnPixels(GLint x,
6493 GLint y,
6494 GLsizei width,
6495 GLsizei height,
6496 GLenum format,
6497 GLenum type,
6498 GLsizei bufSize,
6499 void *data)
6500{
6501 return readPixels(x, y, width, height, format, type, data);
6502}
6503
Jamie Madill007530e2017-12-28 14:27:04 -05006504void Context::setFenceNV(GLuint fence, GLenum condition)
6505{
6506 ASSERT(condition == GL_ALL_COMPLETED_NV);
6507
6508 FenceNV *fenceObject = getFenceNV(fence);
6509 ASSERT(fenceObject != nullptr);
6510 handleError(fenceObject->set(condition));
6511}
6512
6513GLboolean Context::testFenceNV(GLuint fence)
6514{
6515 FenceNV *fenceObject = getFenceNV(fence);
6516
6517 ASSERT(fenceObject != nullptr);
6518 ASSERT(fenceObject->isSet() == GL_TRUE);
6519
6520 GLboolean result = GL_TRUE;
6521 Error error = fenceObject->test(&result);
6522 if (error.isError())
6523 {
6524 handleError(error);
6525 return GL_TRUE;
6526 }
6527
6528 return result;
6529}
6530
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006531void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006532{
6533 Texture *texture = getTargetTexture(target);
6534 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
Corentin Wallez99d492c2018-02-27 15:17:10 -05006535 handleError(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05006536}
6537
Jamie Madillfa920eb2018-01-04 11:45:50 -05006538void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006539{
6540 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
6541 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
6542 handleError(renderbuffer->setStorageEGLImageTarget(this, imageObject));
6543}
6544
Jamie Madillfa920eb2018-01-04 11:45:50 -05006545void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
6546{
6547 UNIMPLEMENTED();
6548}
6549
Jamie Madill5b772312018-03-08 20:28:32 -05006550bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
6551{
6552 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
6553 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
6554 // to the fact that it is stored internally as a float, and so would require conversion
6555 // if returned from Context::getIntegerv. Since this conversion is already implemented
6556 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
6557 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
6558 // application.
6559 switch (pname)
6560 {
6561 case GL_COMPRESSED_TEXTURE_FORMATS:
6562 {
6563 *type = GL_INT;
6564 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
6565 return true;
6566 }
6567 case GL_SHADER_BINARY_FORMATS:
6568 {
6569 *type = GL_INT;
6570 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
6571 return true;
6572 }
6573
6574 case GL_MAX_VERTEX_ATTRIBS:
6575 case GL_MAX_VERTEX_UNIFORM_VECTORS:
6576 case GL_MAX_VARYING_VECTORS:
6577 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
6578 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
6579 case GL_MAX_TEXTURE_IMAGE_UNITS:
6580 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
6581 case GL_MAX_RENDERBUFFER_SIZE:
6582 case GL_NUM_SHADER_BINARY_FORMATS:
6583 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
6584 case GL_ARRAY_BUFFER_BINDING:
6585 case GL_FRAMEBUFFER_BINDING:
6586 case GL_RENDERBUFFER_BINDING:
6587 case GL_CURRENT_PROGRAM:
6588 case GL_PACK_ALIGNMENT:
6589 case GL_UNPACK_ALIGNMENT:
6590 case GL_GENERATE_MIPMAP_HINT:
6591 case GL_RED_BITS:
6592 case GL_GREEN_BITS:
6593 case GL_BLUE_BITS:
6594 case GL_ALPHA_BITS:
6595 case GL_DEPTH_BITS:
6596 case GL_STENCIL_BITS:
6597 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
6598 case GL_CULL_FACE_MODE:
6599 case GL_FRONT_FACE:
6600 case GL_ACTIVE_TEXTURE:
6601 case GL_STENCIL_FUNC:
6602 case GL_STENCIL_VALUE_MASK:
6603 case GL_STENCIL_REF:
6604 case GL_STENCIL_FAIL:
6605 case GL_STENCIL_PASS_DEPTH_FAIL:
6606 case GL_STENCIL_PASS_DEPTH_PASS:
6607 case GL_STENCIL_BACK_FUNC:
6608 case GL_STENCIL_BACK_VALUE_MASK:
6609 case GL_STENCIL_BACK_REF:
6610 case GL_STENCIL_BACK_FAIL:
6611 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
6612 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
6613 case GL_DEPTH_FUNC:
6614 case GL_BLEND_SRC_RGB:
6615 case GL_BLEND_SRC_ALPHA:
6616 case GL_BLEND_DST_RGB:
6617 case GL_BLEND_DST_ALPHA:
6618 case GL_BLEND_EQUATION_RGB:
6619 case GL_BLEND_EQUATION_ALPHA:
6620 case GL_STENCIL_WRITEMASK:
6621 case GL_STENCIL_BACK_WRITEMASK:
6622 case GL_STENCIL_CLEAR_VALUE:
6623 case GL_SUBPIXEL_BITS:
6624 case GL_MAX_TEXTURE_SIZE:
6625 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
6626 case GL_SAMPLE_BUFFERS:
6627 case GL_SAMPLES:
6628 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
6629 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
6630 case GL_TEXTURE_BINDING_2D:
6631 case GL_TEXTURE_BINDING_CUBE_MAP:
6632 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
6633 {
6634 *type = GL_INT;
6635 *numParams = 1;
6636 return true;
6637 }
6638 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6639 {
6640 if (!getExtensions().packReverseRowOrder)
6641 {
6642 return false;
6643 }
6644 *type = GL_INT;
6645 *numParams = 1;
6646 return true;
6647 }
6648 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
6649 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
6650 {
6651 if (!getExtensions().textureRectangle)
6652 {
6653 return false;
6654 }
6655 *type = GL_INT;
6656 *numParams = 1;
6657 return true;
6658 }
6659 case GL_MAX_DRAW_BUFFERS_EXT:
6660 case GL_MAX_COLOR_ATTACHMENTS_EXT:
6661 {
6662 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
6663 {
6664 return false;
6665 }
6666 *type = GL_INT;
6667 *numParams = 1;
6668 return true;
6669 }
6670 case GL_MAX_VIEWPORT_DIMS:
6671 {
6672 *type = GL_INT;
6673 *numParams = 2;
6674 return true;
6675 }
6676 case GL_VIEWPORT:
6677 case GL_SCISSOR_BOX:
6678 {
6679 *type = GL_INT;
6680 *numParams = 4;
6681 return true;
6682 }
6683 case GL_SHADER_COMPILER:
6684 case GL_SAMPLE_COVERAGE_INVERT:
6685 case GL_DEPTH_WRITEMASK:
6686 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
6687 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
6688 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
6689 // bool-natural
6690 case GL_SAMPLE_COVERAGE:
6691 case GL_SCISSOR_TEST:
6692 case GL_STENCIL_TEST:
6693 case GL_DEPTH_TEST:
6694 case GL_BLEND:
6695 case GL_DITHER:
6696 case GL_CONTEXT_ROBUST_ACCESS_EXT:
6697 {
6698 *type = GL_BOOL;
6699 *numParams = 1;
6700 return true;
6701 }
6702 case GL_COLOR_WRITEMASK:
6703 {
6704 *type = GL_BOOL;
6705 *numParams = 4;
6706 return true;
6707 }
6708 case GL_POLYGON_OFFSET_FACTOR:
6709 case GL_POLYGON_OFFSET_UNITS:
6710 case GL_SAMPLE_COVERAGE_VALUE:
6711 case GL_DEPTH_CLEAR_VALUE:
6712 case GL_LINE_WIDTH:
6713 {
6714 *type = GL_FLOAT;
6715 *numParams = 1;
6716 return true;
6717 }
6718 case GL_ALIASED_LINE_WIDTH_RANGE:
6719 case GL_ALIASED_POINT_SIZE_RANGE:
6720 case GL_DEPTH_RANGE:
6721 {
6722 *type = GL_FLOAT;
6723 *numParams = 2;
6724 return true;
6725 }
6726 case GL_COLOR_CLEAR_VALUE:
6727 case GL_BLEND_COLOR:
6728 {
6729 *type = GL_FLOAT;
6730 *numParams = 4;
6731 return true;
6732 }
6733 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
6734 if (!getExtensions().textureFilterAnisotropic)
6735 {
6736 return false;
6737 }
6738 *type = GL_FLOAT;
6739 *numParams = 1;
6740 return true;
6741 case GL_TIMESTAMP_EXT:
6742 if (!getExtensions().disjointTimerQuery)
6743 {
6744 return false;
6745 }
6746 *type = GL_INT_64_ANGLEX;
6747 *numParams = 1;
6748 return true;
6749 case GL_GPU_DISJOINT_EXT:
6750 if (!getExtensions().disjointTimerQuery)
6751 {
6752 return false;
6753 }
6754 *type = GL_INT;
6755 *numParams = 1;
6756 return true;
6757 case GL_COVERAGE_MODULATION_CHROMIUM:
6758 if (!getExtensions().framebufferMixedSamples)
6759 {
6760 return false;
6761 }
6762 *type = GL_INT;
6763 *numParams = 1;
6764 return true;
6765 case GL_TEXTURE_BINDING_EXTERNAL_OES:
6766 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
6767 {
6768 return false;
6769 }
6770 *type = GL_INT;
6771 *numParams = 1;
6772 return true;
6773 }
6774
6775 if (getExtensions().debug)
6776 {
6777 switch (pname)
6778 {
6779 case GL_DEBUG_LOGGED_MESSAGES:
6780 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
6781 case GL_DEBUG_GROUP_STACK_DEPTH:
6782 case GL_MAX_DEBUG_MESSAGE_LENGTH:
6783 case GL_MAX_DEBUG_LOGGED_MESSAGES:
6784 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
6785 case GL_MAX_LABEL_LENGTH:
6786 *type = GL_INT;
6787 *numParams = 1;
6788 return true;
6789
6790 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
6791 case GL_DEBUG_OUTPUT:
6792 *type = GL_BOOL;
6793 *numParams = 1;
6794 return true;
6795 }
6796 }
6797
6798 if (getExtensions().multisampleCompatibility)
6799 {
6800 switch (pname)
6801 {
6802 case GL_MULTISAMPLE_EXT:
6803 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
6804 *type = GL_BOOL;
6805 *numParams = 1;
6806 return true;
6807 }
6808 }
6809
6810 if (getExtensions().pathRendering)
6811 {
6812 switch (pname)
6813 {
6814 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
6815 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
6816 *type = GL_FLOAT;
6817 *numParams = 16;
6818 return true;
6819 }
6820 }
6821
6822 if (getExtensions().bindGeneratesResource)
6823 {
6824 switch (pname)
6825 {
6826 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
6827 *type = GL_BOOL;
6828 *numParams = 1;
6829 return true;
6830 }
6831 }
6832
6833 if (getExtensions().clientArrays)
6834 {
6835 switch (pname)
6836 {
6837 case GL_CLIENT_ARRAYS_ANGLE:
6838 *type = GL_BOOL;
6839 *numParams = 1;
6840 return true;
6841 }
6842 }
6843
6844 if (getExtensions().sRGBWriteControl)
6845 {
6846 switch (pname)
6847 {
6848 case GL_FRAMEBUFFER_SRGB_EXT:
6849 *type = GL_BOOL;
6850 *numParams = 1;
6851 return true;
6852 }
6853 }
6854
6855 if (getExtensions().robustResourceInitialization &&
6856 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
6857 {
6858 *type = GL_BOOL;
6859 *numParams = 1;
6860 return true;
6861 }
6862
6863 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
6864 {
6865 *type = GL_BOOL;
6866 *numParams = 1;
6867 return true;
6868 }
6869
6870 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
6871 switch (pname)
6872 {
6873 // case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE // equivalent to FRAMEBUFFER_BINDING
6874 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
6875 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
6876 {
6877 return false;
6878 }
6879 *type = GL_INT;
6880 *numParams = 1;
6881 return true;
6882
6883 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
6884 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
6885 {
6886 return false;
6887 }
6888 *type = GL_INT;
6889 *numParams = 1;
6890 return true;
6891
6892 case GL_PROGRAM_BINARY_FORMATS_OES:
6893 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
6894 {
6895 return false;
6896 }
6897 *type = GL_INT;
6898 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
6899 return true;
6900
6901 case GL_PACK_ROW_LENGTH:
6902 case GL_PACK_SKIP_ROWS:
6903 case GL_PACK_SKIP_PIXELS:
6904 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
6905 {
6906 return false;
6907 }
6908 *type = GL_INT;
6909 *numParams = 1;
6910 return true;
6911 case GL_UNPACK_ROW_LENGTH:
6912 case GL_UNPACK_SKIP_ROWS:
6913 case GL_UNPACK_SKIP_PIXELS:
6914 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
6915 {
6916 return false;
6917 }
6918 *type = GL_INT;
6919 *numParams = 1;
6920 return true;
6921 case GL_VERTEX_ARRAY_BINDING:
6922 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
6923 {
6924 return false;
6925 }
6926 *type = GL_INT;
6927 *numParams = 1;
6928 return true;
6929 case GL_PIXEL_PACK_BUFFER_BINDING:
6930 case GL_PIXEL_UNPACK_BUFFER_BINDING:
6931 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
6932 {
6933 return false;
6934 }
6935 *type = GL_INT;
6936 *numParams = 1;
6937 return true;
6938 case GL_MAX_SAMPLES:
6939 {
6940 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
6941 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
6942 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
6943 {
6944 return false;
6945 }
6946 *type = GL_INT;
6947 *numParams = 1;
6948 return true;
6949
6950 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
6951 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
6952 {
6953 return false;
6954 }
6955 *type = GL_INT;
6956 *numParams = 1;
6957 return true;
6958 }
6959 }
6960
6961 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
6962 {
6963 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
6964 {
6965 return false;
6966 }
6967 *type = GL_INT;
6968 *numParams = 1;
6969 return true;
6970 }
6971
6972 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
6973 {
6974 *type = GL_INT;
6975 *numParams = 1;
6976 return true;
6977 }
6978
Lingfeng Yang13b708f2018-03-21 12:14:10 -07006979 if (getClientVersion() < Version(2, 0))
6980 {
6981 switch (pname)
6982 {
6983 case GL_ALPHA_TEST_FUNC:
Lingfeng Yange547aac2018-04-05 09:39:20 -07006984 case GL_CLIENT_ACTIVE_TEXTURE:
6985 case GL_MATRIX_MODE:
6986 case GL_MAX_TEXTURE_UNITS:
6987 case GL_MAX_MODELVIEW_STACK_DEPTH:
6988 case GL_MAX_PROJECTION_STACK_DEPTH:
6989 case GL_MAX_TEXTURE_STACK_DEPTH:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07006990 *type = GL_INT;
6991 *numParams = 1;
6992 return true;
6993 case GL_ALPHA_TEST_REF:
6994 *type = GL_FLOAT;
6995 *numParams = 1;
6996 return true;
Lingfeng Yanga43994c2018-03-29 07:21:41 -07006997 case GL_CURRENT_COLOR:
Lingfeng Yange547aac2018-04-05 09:39:20 -07006998 case GL_CURRENT_TEXTURE_COORDS:
Lingfeng Yanga43994c2018-03-29 07:21:41 -07006999 *type = GL_FLOAT;
7000 *numParams = 4;
7001 return true;
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007002 case GL_CURRENT_NORMAL:
7003 *type = GL_FLOAT;
7004 *numParams = 3;
7005 return true;
Lingfeng Yang3a41af62018-04-09 07:28:56 -07007006 case GL_MODELVIEW_MATRIX:
7007 case GL_PROJECTION_MATRIX:
7008 case GL_TEXTURE_MATRIX:
7009 *type = GL_FLOAT;
7010 *numParams = 16;
7011 return true;
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007012 }
7013 }
7014
Jamie Madill5b772312018-03-08 20:28:32 -05007015 if (getClientVersion() < Version(3, 0))
7016 {
7017 return false;
7018 }
7019
7020 // Check for ES3.0+ parameter names
7021 switch (pname)
7022 {
7023 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
7024 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
7025 case GL_UNIFORM_BUFFER_BINDING:
7026 case GL_TRANSFORM_FEEDBACK_BINDING:
7027 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7028 case GL_COPY_READ_BUFFER_BINDING:
7029 case GL_COPY_WRITE_BUFFER_BINDING:
7030 case GL_SAMPLER_BINDING:
7031 case GL_READ_BUFFER:
7032 case GL_TEXTURE_BINDING_3D:
7033 case GL_TEXTURE_BINDING_2D_ARRAY:
7034 case GL_MAX_3D_TEXTURE_SIZE:
7035 case GL_MAX_ARRAY_TEXTURE_LAYERS:
7036 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
7037 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
7038 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
7039 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
7040 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
7041 case GL_MAX_VARYING_COMPONENTS:
7042 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
7043 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
7044 case GL_MIN_PROGRAM_TEXEL_OFFSET:
7045 case GL_MAX_PROGRAM_TEXEL_OFFSET:
7046 case GL_NUM_EXTENSIONS:
7047 case GL_MAJOR_VERSION:
7048 case GL_MINOR_VERSION:
7049 case GL_MAX_ELEMENTS_INDICES:
7050 case GL_MAX_ELEMENTS_VERTICES:
7051 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
7052 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
7053 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
7054 case GL_UNPACK_IMAGE_HEIGHT:
7055 case GL_UNPACK_SKIP_IMAGES:
7056 {
7057 *type = GL_INT;
7058 *numParams = 1;
7059 return true;
7060 }
7061
7062 case GL_MAX_ELEMENT_INDEX:
7063 case GL_MAX_UNIFORM_BLOCK_SIZE:
7064 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
7065 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
7066 case GL_MAX_SERVER_WAIT_TIMEOUT:
7067 {
7068 *type = GL_INT_64_ANGLEX;
7069 *numParams = 1;
7070 return true;
7071 }
7072
7073 case GL_TRANSFORM_FEEDBACK_ACTIVE:
7074 case GL_TRANSFORM_FEEDBACK_PAUSED:
7075 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
7076 case GL_RASTERIZER_DISCARD:
7077 {
7078 *type = GL_BOOL;
7079 *numParams = 1;
7080 return true;
7081 }
7082
7083 case GL_MAX_TEXTURE_LOD_BIAS:
7084 {
7085 *type = GL_FLOAT;
7086 *numParams = 1;
7087 return true;
7088 }
7089 }
7090
7091 if (getExtensions().requestExtension)
7092 {
7093 switch (pname)
7094 {
7095 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
7096 *type = GL_INT;
7097 *numParams = 1;
7098 return true;
7099 }
7100 }
7101
7102 if (getClientVersion() < Version(3, 1))
7103 {
7104 return false;
7105 }
7106
7107 switch (pname)
7108 {
7109 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7110 case GL_DRAW_INDIRECT_BUFFER_BINDING:
7111 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
7112 case GL_MAX_FRAMEBUFFER_WIDTH:
7113 case GL_MAX_FRAMEBUFFER_HEIGHT:
7114 case GL_MAX_FRAMEBUFFER_SAMPLES:
7115 case GL_MAX_SAMPLE_MASK_WORDS:
7116 case GL_MAX_COLOR_TEXTURE_SAMPLES:
7117 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
7118 case GL_MAX_INTEGER_SAMPLES:
7119 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
7120 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
7121 case GL_MAX_VERTEX_ATTRIB_STRIDE:
7122 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
7123 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
7124 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
7125 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
7126 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
7127 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
7128 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
7129 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
7130 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
7131 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
7132 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
7133 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
7134 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
7135 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
7136 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
7137 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
7138 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
7139 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
7140 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
7141 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
7142 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
7143 case GL_MAX_UNIFORM_LOCATIONS:
7144 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
7145 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
7146 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
7147 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
7148 case GL_MAX_IMAGE_UNITS:
7149 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
7150 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
7151 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
7152 case GL_SHADER_STORAGE_BUFFER_BINDING:
7153 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
7154 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
7155 *type = GL_INT;
7156 *numParams = 1;
7157 return true;
7158 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7159 *type = GL_INT_64_ANGLEX;
7160 *numParams = 1;
7161 return true;
7162 case GL_SAMPLE_MASK:
7163 *type = GL_BOOL;
7164 *numParams = 1;
7165 return true;
7166 }
7167
7168 if (getExtensions().geometryShader)
7169 {
7170 switch (pname)
7171 {
7172 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7173 case GL_LAYER_PROVOKING_VERTEX_EXT:
7174 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7175 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7176 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7177 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7178 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7179 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7180 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7181 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7182 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7183 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7184 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7185 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7186 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7187 *type = GL_INT;
7188 *numParams = 1;
7189 return true;
7190 }
7191 }
7192
7193 return false;
7194}
7195
7196bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7197{
7198 if (getClientVersion() < Version(3, 0))
7199 {
7200 return false;
7201 }
7202
7203 switch (target)
7204 {
7205 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7206 case GL_UNIFORM_BUFFER_BINDING:
7207 {
7208 *type = GL_INT;
7209 *numParams = 1;
7210 return true;
7211 }
7212 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7213 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7214 case GL_UNIFORM_BUFFER_START:
7215 case GL_UNIFORM_BUFFER_SIZE:
7216 {
7217 *type = GL_INT_64_ANGLEX;
7218 *numParams = 1;
7219 return true;
7220 }
7221 }
7222
7223 if (getClientVersion() < Version(3, 1))
7224 {
7225 return false;
7226 }
7227
7228 switch (target)
7229 {
7230 case GL_IMAGE_BINDING_LAYERED:
7231 {
7232 *type = GL_BOOL;
7233 *numParams = 1;
7234 return true;
7235 }
7236 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7237 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7238 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7239 case GL_SHADER_STORAGE_BUFFER_BINDING:
7240 case GL_VERTEX_BINDING_BUFFER:
7241 case GL_VERTEX_BINDING_DIVISOR:
7242 case GL_VERTEX_BINDING_OFFSET:
7243 case GL_VERTEX_BINDING_STRIDE:
7244 case GL_SAMPLE_MASK_VALUE:
7245 case GL_IMAGE_BINDING_NAME:
7246 case GL_IMAGE_BINDING_LEVEL:
7247 case GL_IMAGE_BINDING_LAYER:
7248 case GL_IMAGE_BINDING_ACCESS:
7249 case GL_IMAGE_BINDING_FORMAT:
7250 {
7251 *type = GL_INT;
7252 *numParams = 1;
7253 return true;
7254 }
7255 case GL_ATOMIC_COUNTER_BUFFER_START:
7256 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
7257 case GL_SHADER_STORAGE_BUFFER_START:
7258 case GL_SHADER_STORAGE_BUFFER_SIZE:
7259 {
7260 *type = GL_INT_64_ANGLEX;
7261 *numParams = 1;
7262 return true;
7263 }
7264 }
7265
7266 return false;
7267}
7268
7269Program *Context::getProgram(GLuint handle) const
7270{
7271 return mState.mShaderPrograms->getProgram(handle);
7272}
7273
7274Shader *Context::getShader(GLuint handle) const
7275{
7276 return mState.mShaderPrograms->getShader(handle);
7277}
7278
7279bool Context::isTextureGenerated(GLuint texture) const
7280{
7281 return mState.mTextures->isHandleGenerated(texture);
7282}
7283
7284bool Context::isBufferGenerated(GLuint buffer) const
7285{
7286 return mState.mBuffers->isHandleGenerated(buffer);
7287}
7288
7289bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
7290{
7291 return mState.mRenderbuffers->isHandleGenerated(renderbuffer);
7292}
7293
7294bool Context::isFramebufferGenerated(GLuint framebuffer) const
7295{
7296 return mState.mFramebuffers->isHandleGenerated(framebuffer);
7297}
7298
7299bool Context::isProgramPipelineGenerated(GLuint pipeline) const
7300{
7301 return mState.mPipelines->isHandleGenerated(pipeline);
7302}
7303
7304bool Context::usingDisplayTextureShareGroup() const
7305{
7306 return mDisplayTextureShareGroup;
7307}
7308
7309GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
7310{
7311 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
7312 internalformat == GL_DEPTH_STENCIL
7313 ? GL_DEPTH24_STENCIL8
7314 : internalformat;
7315}
7316
Jamie Madillc29968b2016-01-20 11:17:23 -05007317} // namespace gl