blob: 78087d72c87ae9e3a7ffcb629006006b0b768520 [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.
Jamie Madillc6dbc252018-04-30 19:07:56 -0400300 ANGLE_UNUSED_VARIABLE(mSavedArgsType);
301 ANGLE_UNUSED_VARIABLE(mParamsBuffer);
Jamie Madill5b772312018-03-08 20:28:32 -0500302
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 Langb0f917f2017-12-05 13:41:54 -0500353 if (mSupportedExtensions.textureRectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400354 {
355 Texture *zeroTextureRectangle =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500356 new Texture(mImplementation.get(), 0, TextureType::Rectangle);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800357 mZeroTextures[TextureType::Rectangle].set(this, zeroTextureRectangle);
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400358 }
359
Geoff Langb0f917f2017-12-05 13:41:54 -0500360 if (mSupportedExtensions.eglImageExternal || mSupportedExtensions.eglStreamConsumerExternal)
Ian Ewellbda75592016-04-18 17:25:54 -0400361 {
Corentin Wallez99d492c2018-02-27 15:17:10 -0500362 Texture *zeroTextureExternal = new Texture(mImplementation.get(), 0, TextureType::External);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800363 mZeroTextures[TextureType::External].set(this, zeroTextureExternal);
Ian Ewellbda75592016-04-18 17:25:54 -0400364 }
365
Jamie Madill4928b7c2017-06-20 12:57:39 -0400366 mGLState.initializeZeroTextures(this, mZeroTextures);
Jamie Madille6382c32014-11-07 15:05:26 -0500367
Jamie Madill57a89722013-07-02 11:57:03 -0400368 bindVertexArray(0);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000369
Geoff Langeb66a6e2016-10-31 13:06:12 -0400370 if (getClientVersion() >= Version(3, 0))
Geoff Lang1a683462015-09-29 15:09:59 -0400371 {
372 // [OpenGL ES 3.0.2] section 2.14.1 pg 85:
373 // In the initial state, a default transform feedback object is bound and treated as
374 // a transform feedback object with a name of zero. That object is bound any time
375 // BindTransformFeedback is called with id of zero
Jamie Madillf0dcb8b2017-08-26 19:05:13 -0400376 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Geoff Lang1a683462015-09-29 15:09:59 -0400377 }
Geoff Langc8058452014-02-03 12:04:11 -0500378
Corentin Wallez336129f2017-10-17 15:55:40 -0400379 for (auto type : angle::AllEnums<BufferBinding>())
380 {
381 bindBuffer(type, 0);
382 }
383
384 bindRenderbuffer(GL_RENDERBUFFER, 0);
385
386 for (unsigned int i = 0; i < mCaps.maxUniformBufferBindings; i++)
387 {
388 bindBufferRange(BufferBinding::Uniform, i, 0, 0, -1);
389 }
390
Jamie Madillad9f24e2016-02-12 09:27:24 -0500391 // Initialize dirty bit masks
Jamie Madillc67323a2017-11-02 23:11:41 -0400392 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500393 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500394 // No dirty objects.
395
396 // Readpixels uses the pack state and read FBO
Jamie Madillc67323a2017-11-02 23:11:41 -0400397 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500398 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500399 mReadPixelsDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
400
401 mClearDirtyBits.set(State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED);
402 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
403 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR);
404 mClearDirtyBits.set(State::DIRTY_BIT_VIEWPORT);
405 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_COLOR);
406 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_DEPTH);
407 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_STENCIL);
408 mClearDirtyBits.set(State::DIRTY_BIT_COLOR_MASK);
409 mClearDirtyBits.set(State::DIRTY_BIT_DEPTH_MASK);
410 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT);
411 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_BACK);
412 mClearDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
413
414 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
415 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR);
Geoff Lang1d2c41d2016-10-19 16:14:46 -0700416 mBlitDirtyBits.set(State::DIRTY_BIT_FRAMEBUFFER_SRGB);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500417 mBlitDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
418 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
Jamie Madill437fa652016-05-03 15:13:24 -0400419
Xinghua Cao10a4d432017-11-28 14:46:26 +0800420 // TODO(xinghua.cao@intel.com): add other dirty bits and dirty objects.
421 mComputeDirtyBits.set(State::DIRTY_BIT_SHADER_STORAGE_BUFFER_BINDING);
422 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_BINDING);
423 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_EXECUTABLE);
424 mComputeDirtyBits.set(State::DIRTY_BIT_TEXTURE_BINDINGS);
425 mComputeDirtyBits.set(State::DIRTY_BIT_SAMPLER_BINDINGS);
Qin Jiajia62fcf622017-11-30 16:16:12 +0800426 mComputeDirtyBits.set(State::DIRTY_BIT_DISPATCH_INDIRECT_BUFFER_BINDING);
Jiajia Qin5ae6ee42018-03-06 17:39:42 +0800427 mComputeDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM_TEXTURES);
Xinghua Cao10a4d432017-11-28 14:46:26 +0800428
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400429 handleError(mImplementation->initialize());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000430}
431
Jamie Madill4928b7c2017-06-20 12:57:39 -0400432egl::Error Context::onDestroy(const egl::Display *display)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000433{
Jamie Madille7b3fe22018-04-05 09:42:46 -0400434 // Delete the Surface first to trigger a finish() in Vulkan.
435 SafeDelete(mSurfacelessFramebuffer);
436
437 ANGLE_TRY(releaseSurface(display));
438
Corentin Wallez80b24112015-08-25 16:41:57 -0400439 for (auto fence : mFenceNVMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000440 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400441 SafeDelete(fence.second);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000442 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400443 mFenceNVMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000444
Corentin Wallez80b24112015-08-25 16:41:57 -0400445 for (auto query : mQueryMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000446 {
Geoff Langf0aa8422015-09-29 15:08:34 -0400447 if (query.second != nullptr)
448 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400449 query.second->release(this);
Geoff Langf0aa8422015-09-29 15:08:34 -0400450 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000451 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400452 mQueryMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000453
Corentin Wallez80b24112015-08-25 16:41:57 -0400454 for (auto vertexArray : mVertexArrayMap)
Jamie Madill57a89722013-07-02 11:57:03 -0400455 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400456 if (vertexArray.second)
457 {
458 vertexArray.second->onDestroy(this);
459 }
Jamie Madill57a89722013-07-02 11:57:03 -0400460 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400461 mVertexArrayMap.clear();
Jamie Madill57a89722013-07-02 11:57:03 -0400462
Corentin Wallez80b24112015-08-25 16:41:57 -0400463 for (auto transformFeedback : mTransformFeedbackMap)
Geoff Langc8058452014-02-03 12:04:11 -0500464 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500465 if (transformFeedback.second != nullptr)
466 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500467 transformFeedback.second->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500468 }
Geoff Langc8058452014-02-03 12:04:11 -0500469 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400470 mTransformFeedbackMap.clear();
Geoff Langc8058452014-02-03 12:04:11 -0500471
Jamie Madill5b772312018-03-08 20:28:32 -0500472 for (BindingPointer<Texture> &zeroTexture : mZeroTextures)
Geoff Lang76b10c92014-09-05 16:28:14 -0400473 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800474 if (zeroTexture.get() != nullptr)
475 {
476 ANGLE_TRY(zeroTexture->onDestroy(this));
477 zeroTexture.set(this, nullptr);
478 }
Geoff Lang76b10c92014-09-05 16:28:14 -0400479 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000480
Jamie Madill2f348d22017-06-05 10:50:59 -0400481 releaseShaderCompiler();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500482
Jamie Madill4928b7c2017-06-20 12:57:39 -0400483 mGLState.reset(this);
484
Jamie Madill6c1f6712017-02-14 19:08:04 -0500485 mState.mBuffers->release(this);
486 mState.mShaderPrograms->release(this);
487 mState.mTextures->release(this);
488 mState.mRenderbuffers->release(this);
489 mState.mSamplers->release(this);
Jamie Madill70b5bb02017-08-28 13:32:37 -0400490 mState.mSyncs->release(this);
Jamie Madill6c1f6712017-02-14 19:08:04 -0500491 mState.mPaths->release(this);
492 mState.mFramebuffers->release(this);
Yunchao Hea336b902017-08-02 16:05:21 +0800493 mState.mPipelines->release(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400494
Jamie Madill76e471e2017-10-21 09:56:01 -0400495 mImplementation->onDestroy(this);
496
Jamie Madill4928b7c2017-06-20 12:57:39 -0400497 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000498}
499
Jamie Madill70ee0f62017-02-06 16:04:20 -0500500Context::~Context()
501{
502}
503
Jamie Madill4928b7c2017-06-20 12:57:39 -0400504egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000505{
Jamie Madill61e16b42017-06-19 11:13:23 -0400506 mCurrentDisplay = display;
507
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000508 if (!mHasBeenCurrent)
509 {
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000510 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500511 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400512 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000513
Corentin Wallezc295e512017-01-27 17:47:50 -0500514 int width = 0;
515 int height = 0;
516 if (surface != nullptr)
517 {
518 width = surface->getWidth();
519 height = surface->getHeight();
520 }
521
522 mGLState.setViewportParams(0, 0, width, height);
523 mGLState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000524
525 mHasBeenCurrent = true;
526 }
527
Jamie Madill1b94d432015-08-07 13:23:23 -0400528 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700529 mGLState.setAllDirtyBits();
Jamie Madill81c2e252017-09-09 23:32:46 -0400530 mGLState.setAllDirtyObjects();
Jamie Madill1b94d432015-08-07 13:23:23 -0400531
Jamie Madill4928b7c2017-06-20 12:57:39 -0400532 ANGLE_TRY(releaseSurface(display));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500533
534 Framebuffer *newDefault = nullptr;
535 if (surface != nullptr)
536 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400537 ANGLE_TRY(surface->setIsCurrent(this, true));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500538 mCurrentSurface = surface;
539 newDefault = surface->getDefaultFramebuffer();
540 }
541 else
542 {
543 if (mSurfacelessFramebuffer == nullptr)
544 {
545 mSurfacelessFramebuffer = new Framebuffer(mImplementation.get());
546 }
547
548 newDefault = mSurfacelessFramebuffer;
549 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000550
Corentin Wallez37c39792015-08-20 14:19:46 -0400551 // Update default framebuffer, the binding of the previous default
552 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400553 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700554 if (mGLState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400555 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700556 mGLState.setReadFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400557 }
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700558 if (mGLState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400559 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700560 mGLState.setDrawFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400561 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500562 mState.mFramebuffers->setDefaultFramebuffer(newDefault);
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400563 }
Ian Ewell292f0052016-02-04 10:37:32 -0500564
565 // Notify the renderer of a context switch
Jamie Madill4928b7c2017-06-20 12:57:39 -0400566 mImplementation->onMakeCurrent(this);
567 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000568}
569
Jamie Madill4928b7c2017-06-20 12:57:39 -0400570egl::Error Context::releaseSurface(const egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400571{
Corentin Wallez37c39792015-08-20 14:19:46 -0400572 // Remove the default framebuffer
Corentin Wallezc295e512017-01-27 17:47:50 -0500573 Framebuffer *currentDefault = nullptr;
574 if (mCurrentSurface != nullptr)
Corentin Wallez51706ea2015-08-07 14:39:22 -0400575 {
Corentin Wallezc295e512017-01-27 17:47:50 -0500576 currentDefault = mCurrentSurface->getDefaultFramebuffer();
577 }
578 else if (mSurfacelessFramebuffer != nullptr)
579 {
580 currentDefault = mSurfacelessFramebuffer;
Corentin Wallez51706ea2015-08-07 14:39:22 -0400581 }
582
Corentin Wallezc295e512017-01-27 17:47:50 -0500583 if (mGLState.getReadFramebuffer() == currentDefault)
584 {
585 mGLState.setReadFramebufferBinding(nullptr);
586 }
587 if (mGLState.getDrawFramebuffer() == currentDefault)
588 {
589 mGLState.setDrawFramebufferBinding(nullptr);
590 }
591 mState.mFramebuffers->setDefaultFramebuffer(nullptr);
592
593 if (mCurrentSurface)
594 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400595 ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
Corentin Wallezc295e512017-01-27 17:47:50 -0500596 mCurrentSurface = nullptr;
597 }
Jamie Madill4928b7c2017-06-20 12:57:39 -0400598
599 return egl::NoError();
Jamie Madill77a72f62015-04-14 11:18:32 -0400600}
601
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000602GLuint Context::createBuffer()
603{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500604 return mState.mBuffers->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000605}
606
607GLuint Context::createProgram()
608{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500609 return mState.mShaderPrograms->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000610}
611
Jiawei Shao385b3e02018-03-21 09:43:28 +0800612GLuint Context::createShader(ShaderType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000613{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500614 return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000615}
616
617GLuint Context::createTexture()
618{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500619 return mState.mTextures->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000620}
621
622GLuint Context::createRenderbuffer()
623{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500624 return mState.mRenderbuffers->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000625}
626
Brandon Jones59770802018-04-02 13:18:42 -0700627GLuint Context::genPaths(GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300628{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500629 auto resultOrError = mState.mPaths->createPaths(mImplementation.get(), range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300630 if (resultOrError.isError())
631 {
632 handleError(resultOrError.getError());
633 return 0;
634 }
635 return resultOrError.getResult();
636}
637
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000638// Returns an unused framebuffer name
639GLuint Context::createFramebuffer()
640{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500641 return mState.mFramebuffers->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000642}
643
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500644void Context::genFencesNV(GLsizei n, GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000645{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500646 for (int i = 0; i < n; i++)
647 {
648 GLuint handle = mFenceNVHandleAllocator.allocate();
649 mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV()));
650 fences[i] = handle;
651 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000652}
653
Yunchao Hea336b902017-08-02 16:05:21 +0800654GLuint Context::createProgramPipeline()
655{
656 return mState.mPipelines->createProgramPipeline();
657}
658
Jiawei Shao385b3e02018-03-21 09:43:28 +0800659GLuint Context::createShaderProgramv(ShaderType type, GLsizei count, const GLchar *const *strings)
Jiajia Qin5451d532017-11-16 17:16:34 +0800660{
661 UNIMPLEMENTED();
662 return 0u;
663}
664
James Darpinian4d9d4832018-03-13 12:43:28 -0700665void Context::deleteBuffer(GLuint bufferName)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000666{
James Darpinian4d9d4832018-03-13 12:43:28 -0700667 Buffer *buffer = mState.mBuffers->getBuffer(bufferName);
668 if (buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000669 {
670 detachBuffer(buffer);
671 }
Jamie Madill893ab082014-05-16 16:56:10 -0400672
James Darpinian4d9d4832018-03-13 12:43:28 -0700673 mState.mBuffers->deleteObject(this, bufferName);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000674}
675
676void Context::deleteShader(GLuint shader)
677{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500678 mState.mShaderPrograms->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000679}
680
681void Context::deleteProgram(GLuint program)
682{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500683 mState.mShaderPrograms->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000684}
685
686void Context::deleteTexture(GLuint texture)
687{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500688 if (mState.mTextures->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000689 {
690 detachTexture(texture);
691 }
692
Jamie Madill6c1f6712017-02-14 19:08:04 -0500693 mState.mTextures->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000694}
695
696void Context::deleteRenderbuffer(GLuint renderbuffer)
697{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500698 if (mState.mRenderbuffers->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000699 {
700 detachRenderbuffer(renderbuffer);
701 }
Jamie Madill893ab082014-05-16 16:56:10 -0400702
Jamie Madill6c1f6712017-02-14 19:08:04 -0500703 mState.mRenderbuffers->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000704}
705
Jamie Madill7f0c5a42017-08-26 22:43:26 -0400706void Context::deleteSync(GLsync sync)
Jamie Madillcd055f82013-07-26 11:55:15 -0400707{
708 // The spec specifies the underlying Fence object is not deleted until all current
709 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
710 // and since our API is currently designed for being called from a single thread, we can delete
711 // the fence immediately.
Jamie Madill70b5bb02017-08-28 13:32:37 -0400712 mState.mSyncs->deleteObject(this, static_cast<GLuint>(reinterpret_cast<uintptr_t>(sync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400713}
714
Yunchao Hea336b902017-08-02 16:05:21 +0800715void Context::deleteProgramPipeline(GLuint pipeline)
716{
717 if (mState.mPipelines->getProgramPipeline(pipeline))
718 {
719 detachProgramPipeline(pipeline);
720 }
721
722 mState.mPipelines->deleteObject(this, pipeline);
723}
724
Sami Väisänene45e53b2016-05-25 10:36:04 +0300725void Context::deletePaths(GLuint first, GLsizei range)
726{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500727 mState.mPaths->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300728}
729
Brandon Jones59770802018-04-02 13:18:42 -0700730bool Context::isPath(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300731{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500732 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300733 if (pathObj == nullptr)
734 return false;
735
736 return pathObj->hasPathData();
737}
738
Brandon Jones59770802018-04-02 13:18:42 -0700739bool Context::isPathGenerated(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300740{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500741 return mState.mPaths->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300742}
743
Brandon Jones59770802018-04-02 13:18:42 -0700744void Context::pathCommands(GLuint path,
745 GLsizei numCommands,
746 const GLubyte *commands,
747 GLsizei numCoords,
748 GLenum coordType,
749 const void *coords)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300750{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500751 auto *pathObject = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300752
753 handleError(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
754}
755
Jamie Madill007530e2017-12-28 14:27:04 -0500756void Context::pathParameterf(GLuint path, GLenum pname, GLfloat value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300757{
Jamie Madill007530e2017-12-28 14:27:04 -0500758 Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300759
760 switch (pname)
761 {
762 case GL_PATH_STROKE_WIDTH_CHROMIUM:
763 pathObj->setStrokeWidth(value);
764 break;
765 case GL_PATH_END_CAPS_CHROMIUM:
766 pathObj->setEndCaps(static_cast<GLenum>(value));
767 break;
768 case GL_PATH_JOIN_STYLE_CHROMIUM:
769 pathObj->setJoinStyle(static_cast<GLenum>(value));
770 break;
771 case GL_PATH_MITER_LIMIT_CHROMIUM:
772 pathObj->setMiterLimit(value);
773 break;
774 case GL_PATH_STROKE_BOUND_CHROMIUM:
775 pathObj->setStrokeBound(value);
776 break;
777 default:
778 UNREACHABLE();
779 break;
780 }
781}
782
Jamie Madill007530e2017-12-28 14:27:04 -0500783void Context::pathParameteri(GLuint path, GLenum pname, GLint value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300784{
Jamie Madill007530e2017-12-28 14:27:04 -0500785 // TODO(jmadill): Should use proper clamping/casting.
786 pathParameterf(path, pname, static_cast<GLfloat>(value));
787}
788
789void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value)
790{
791 const Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300792
793 switch (pname)
794 {
795 case GL_PATH_STROKE_WIDTH_CHROMIUM:
796 *value = pathObj->getStrokeWidth();
797 break;
798 case GL_PATH_END_CAPS_CHROMIUM:
799 *value = static_cast<GLfloat>(pathObj->getEndCaps());
800 break;
801 case GL_PATH_JOIN_STYLE_CHROMIUM:
802 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
803 break;
804 case GL_PATH_MITER_LIMIT_CHROMIUM:
805 *value = pathObj->getMiterLimit();
806 break;
807 case GL_PATH_STROKE_BOUND_CHROMIUM:
808 *value = pathObj->getStrokeBound();
809 break;
810 default:
811 UNREACHABLE();
812 break;
813 }
814}
815
Jamie Madill007530e2017-12-28 14:27:04 -0500816void Context::getPathParameteriv(GLuint path, GLenum pname, GLint *value)
817{
818 GLfloat val = 0.0f;
819 getPathParameterfv(path, pname, value != nullptr ? &val : nullptr);
820 if (value)
821 *value = static_cast<GLint>(val);
822}
823
Brandon Jones59770802018-04-02 13:18:42 -0700824void Context::pathStencilFunc(GLenum func, GLint ref, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300825{
826 mGLState.setPathStencilFunc(func, ref, mask);
827}
828
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000829void Context::deleteFramebuffer(GLuint framebuffer)
830{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500831 if (mState.mFramebuffers->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000832 {
833 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000834 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500835
Jamie Madill6c1f6712017-02-14 19:08:04 -0500836 mState.mFramebuffers->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000837}
838
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500839void Context::deleteFencesNV(GLsizei n, const GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000840{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500841 for (int i = 0; i < n; i++)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000842 {
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500843 GLuint fence = fences[i];
844
845 FenceNV *fenceObject = nullptr;
846 if (mFenceNVMap.erase(fence, &fenceObject))
847 {
848 mFenceNVHandleAllocator.release(fence);
849 delete fenceObject;
850 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000851 }
852}
853
Geoff Lang70d0f492015-12-10 17:45:46 -0500854Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000855{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500856 return mState.mBuffers->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000857}
858
Jamie Madill570f7c82014-07-03 10:38:54 -0400859Texture *Context::getTexture(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000860{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500861 return mState.mTextures->getTexture(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000862}
863
Geoff Lang70d0f492015-12-10 17:45:46 -0500864Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000865{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500866 return mState.mRenderbuffers->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000867}
868
Jamie Madill70b5bb02017-08-28 13:32:37 -0400869Sync *Context::getSync(GLsync handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400870{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400871 return mState.mSyncs->getSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400872}
873
Jamie Madill57a89722013-07-02 11:57:03 -0400874VertexArray *Context::getVertexArray(GLuint handle) const
875{
Jamie Madill96a483b2017-06-27 16:49:21 -0400876 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -0400877}
878
Jamie Madilldc356042013-07-19 16:36:57 -0400879Sampler *Context::getSampler(GLuint handle) const
880{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500881 return mState.mSamplers->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400882}
883
Geoff Langc8058452014-02-03 12:04:11 -0500884TransformFeedback *Context::getTransformFeedback(GLuint handle) const
885{
Jamie Madill96a483b2017-06-27 16:49:21 -0400886 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -0500887}
888
Yunchao Hea336b902017-08-02 16:05:21 +0800889ProgramPipeline *Context::getProgramPipeline(GLuint handle) const
890{
891 return mState.mPipelines->getProgramPipeline(handle);
892}
893
Geoff Lang70d0f492015-12-10 17:45:46 -0500894LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
895{
896 switch (identifier)
897 {
898 case GL_BUFFER:
899 return getBuffer(name);
900 case GL_SHADER:
901 return getShader(name);
902 case GL_PROGRAM:
903 return getProgram(name);
904 case GL_VERTEX_ARRAY:
905 return getVertexArray(name);
906 case GL_QUERY:
907 return getQuery(name);
908 case GL_TRANSFORM_FEEDBACK:
909 return getTransformFeedback(name);
910 case GL_SAMPLER:
911 return getSampler(name);
912 case GL_TEXTURE:
913 return getTexture(name);
914 case GL_RENDERBUFFER:
915 return getRenderbuffer(name);
916 case GL_FRAMEBUFFER:
917 return getFramebuffer(name);
918 default:
919 UNREACHABLE();
920 return nullptr;
921 }
922}
923
924LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
925{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400926 return getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
Geoff Lang70d0f492015-12-10 17:45:46 -0500927}
928
Martin Radev9d901792016-07-15 15:58:58 +0300929void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
930{
931 LabeledObject *object = getLabeledObject(identifier, name);
932 ASSERT(object != nullptr);
933
934 std::string labelName = GetObjectLabelFromPointer(length, label);
935 object->setLabel(labelName);
Jamie Madill8693bdb2017-09-02 15:32:14 -0400936
937 // TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the
938 // specified object is active until we do this.
939 mGLState.setObjectDirty(identifier);
Martin Radev9d901792016-07-15 15:58:58 +0300940}
941
942void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
943{
944 LabeledObject *object = getLabeledObjectFromPtr(ptr);
945 ASSERT(object != nullptr);
946
947 std::string labelName = GetObjectLabelFromPointer(length, label);
948 object->setLabel(labelName);
949}
950
951void Context::getObjectLabel(GLenum identifier,
952 GLuint name,
953 GLsizei bufSize,
954 GLsizei *length,
955 GLchar *label) const
956{
957 LabeledObject *object = getLabeledObject(identifier, name);
958 ASSERT(object != nullptr);
959
960 const std::string &objectLabel = object->getLabel();
961 GetObjectLabelBase(objectLabel, bufSize, length, label);
962}
963
964void Context::getObjectPtrLabel(const void *ptr,
965 GLsizei bufSize,
966 GLsizei *length,
967 GLchar *label) const
968{
969 LabeledObject *object = getLabeledObjectFromPtr(ptr);
970 ASSERT(object != nullptr);
971
972 const std::string &objectLabel = object->getLabel();
973 GetObjectLabelBase(objectLabel, bufSize, length, label);
974}
975
Jamie Madilldc356042013-07-19 16:36:57 -0400976bool Context::isSampler(GLuint samplerName) const
977{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500978 return mState.mSamplers->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -0400979}
980
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800981void Context::bindTexture(TextureType target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000982{
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500983 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000984
Jamie Madilldedd7b92014-11-05 16:30:36 -0500985 if (handle == 0)
986 {
987 texture = mZeroTextures[target].get();
988 }
989 else
990 {
Corentin Wallez99d492c2018-02-27 15:17:10 -0500991 texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500992 }
993
994 ASSERT(texture);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400995 mGLState.setSamplerTexture(this, target, texture);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +0000996}
997
Jamie Madill5bf9ff42016-02-01 11:13:03 -0500998void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000999{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001000 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1001 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001002 mGLState.setReadFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001003}
1004
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001005void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001006{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001007 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1008 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001009 mGLState.setDrawFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001010}
1011
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001012void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -04001013{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001014 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madill7267aa62018-04-17 15:28:21 -04001015 mGLState.setVertexArrayBinding(this, vertexArray);
Jamie Madill57a89722013-07-02 11:57:03 -04001016}
1017
Shao80957d92017-02-20 21:25:59 +08001018void Context::bindVertexBuffer(GLuint bindingIndex,
1019 GLuint bufferHandle,
1020 GLintptr offset,
1021 GLsizei stride)
1022{
1023 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001024 mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Shao80957d92017-02-20 21:25:59 +08001025}
1026
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001027void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -04001028{
Geoff Lang76b10c92014-09-05 16:28:14 -04001029 ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -04001030 Sampler *sampler =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001031 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001032 mGLState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04001033}
1034
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001035void Context::bindImageTexture(GLuint unit,
1036 GLuint texture,
1037 GLint level,
1038 GLboolean layered,
1039 GLint layer,
1040 GLenum access,
1041 GLenum format)
1042{
1043 Texture *tex = mState.mTextures->getTexture(texture);
1044 mGLState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
1045}
1046
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001047void Context::useProgram(GLuint program)
1048{
Jamie Madill6c1f6712017-02-14 19:08:04 -05001049 mGLState.setProgram(this, getProgram(program));
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001050}
1051
Jiajia Qin5451d532017-11-16 17:16:34 +08001052void Context::useProgramStages(GLuint pipeline, GLbitfield stages, GLuint program)
1053{
1054 UNIMPLEMENTED();
1055}
1056
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001057void Context::bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001058{
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001059 ASSERT(target == GL_TRANSFORM_FEEDBACK);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001060 TransformFeedback *transformFeedback =
1061 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001062 mGLState.setTransformFeedbackBinding(this, transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -05001063}
1064
Yunchao Hea336b902017-08-02 16:05:21 +08001065void Context::bindProgramPipeline(GLuint pipelineHandle)
1066{
1067 ProgramPipeline *pipeline =
1068 mState.mPipelines->checkProgramPipelineAllocation(mImplementation.get(), pipelineHandle);
1069 mGLState.setProgramPipelineBinding(this, pipeline);
1070}
1071
Corentin Wallezad3ae902018-03-09 13:40:42 -05001072void Context::beginQuery(QueryType target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001073{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001074 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001075 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001076
Geoff Lang5aad9672014-09-08 11:10:42 -04001077 // begin query
Jamie Madillf0e04492017-08-26 15:28:42 -04001078 ANGLE_CONTEXT_TRY(queryObject->begin());
Geoff Lang5aad9672014-09-08 11:10:42 -04001079
1080 // set query as active for specified target only if begin succeeded
Jamie Madill4928b7c2017-06-20 12:57:39 -04001081 mGLState.setActiveQuery(this, target, queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001082}
1083
Corentin Wallezad3ae902018-03-09 13:40:42 -05001084void Context::endQuery(QueryType target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001085{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001086 Query *queryObject = mGLState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001087 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001088
Jamie Madillf0e04492017-08-26 15:28:42 -04001089 handleError(queryObject->end());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001090
Geoff Lang5aad9672014-09-08 11:10:42 -04001091 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madill4928b7c2017-06-20 12:57:39 -04001092 mGLState.setActiveQuery(this, target, nullptr);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001093}
1094
Corentin Wallezad3ae902018-03-09 13:40:42 -05001095void Context::queryCounter(GLuint id, QueryType target)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001096{
Corentin Wallezad3ae902018-03-09 13:40:42 -05001097 ASSERT(target == QueryType::Timestamp);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001098
1099 Query *queryObject = getQuery(id, true, target);
1100 ASSERT(queryObject);
1101
Jamie Madillf0e04492017-08-26 15:28:42 -04001102 handleError(queryObject->queryCounter());
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001103}
1104
Corentin Wallezad3ae902018-03-09 13:40:42 -05001105void Context::getQueryiv(QueryType target, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001106{
1107 switch (pname)
1108 {
1109 case GL_CURRENT_QUERY_EXT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001110 params[0] = mGLState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001111 break;
1112 case GL_QUERY_COUNTER_BITS_EXT:
1113 switch (target)
1114 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001115 case QueryType::TimeElapsed:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001116 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1117 break;
Corentin Wallezad3ae902018-03-09 13:40:42 -05001118 case QueryType::Timestamp:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001119 params[0] = getExtensions().queryCounterBitsTimestamp;
1120 break;
1121 default:
1122 UNREACHABLE();
1123 params[0] = 0;
1124 break;
1125 }
1126 break;
1127 default:
1128 UNREACHABLE();
1129 return;
1130 }
1131}
1132
Corentin Wallezad3ae902018-03-09 13:40:42 -05001133void Context::getQueryivRobust(QueryType target,
Brandon Jones59770802018-04-02 13:18:42 -07001134 GLenum pname,
1135 GLsizei bufSize,
1136 GLsizei *length,
1137 GLint *params)
1138{
1139 getQueryiv(target, pname, params);
1140}
1141
Geoff Lang2186c382016-10-14 10:54:54 -04001142void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001143{
Geoff Lang2186c382016-10-14 10:54:54 -04001144 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001145}
1146
Brandon Jones59770802018-04-02 13:18:42 -07001147void Context::getQueryObjectivRobust(GLuint id,
1148 GLenum pname,
1149 GLsizei bufSize,
1150 GLsizei *length,
1151 GLint *params)
1152{
1153 getQueryObjectiv(id, pname, params);
1154}
1155
Geoff Lang2186c382016-10-14 10:54:54 -04001156void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001157{
Geoff Lang2186c382016-10-14 10:54:54 -04001158 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001159}
1160
Brandon Jones59770802018-04-02 13:18:42 -07001161void Context::getQueryObjectuivRobust(GLuint id,
1162 GLenum pname,
1163 GLsizei bufSize,
1164 GLsizei *length,
1165 GLuint *params)
1166{
1167 getQueryObjectuiv(id, pname, params);
1168}
1169
Geoff Lang2186c382016-10-14 10:54:54 -04001170void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001171{
Geoff Lang2186c382016-10-14 10:54:54 -04001172 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001173}
1174
Brandon Jones59770802018-04-02 13:18:42 -07001175void Context::getQueryObjecti64vRobust(GLuint id,
1176 GLenum pname,
1177 GLsizei bufSize,
1178 GLsizei *length,
1179 GLint64 *params)
1180{
1181 getQueryObjecti64v(id, pname, params);
1182}
1183
Geoff Lang2186c382016-10-14 10:54:54 -04001184void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001185{
Geoff Lang2186c382016-10-14 10:54:54 -04001186 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001187}
1188
Brandon Jones59770802018-04-02 13:18:42 -07001189void Context::getQueryObjectui64vRobust(GLuint id,
1190 GLenum pname,
1191 GLsizei bufSize,
1192 GLsizei *length,
1193 GLuint64 *params)
1194{
1195 getQueryObjectui64v(id, pname, params);
1196}
1197
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001198Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001199{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001200 return mState.mFramebuffers->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001201}
1202
Jamie Madill2f348d22017-06-05 10:50:59 -04001203FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001204{
Jamie Madill96a483b2017-06-27 16:49:21 -04001205 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001206}
1207
Corentin Wallezad3ae902018-03-09 13:40:42 -05001208Query *Context::getQuery(GLuint handle, bool create, QueryType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001209{
Jamie Madill96a483b2017-06-27 16:49:21 -04001210 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001211 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001212 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001213 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001214
1215 Query *query = mQueryMap.query(handle);
1216 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001217 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001218 ASSERT(type != QueryType::InvalidEnum);
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:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001339 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001340 break;
1341 case GL_MAX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001342 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001343 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:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001386 *params = mCaps.maxShaderUniformBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001387 break;
1388 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001389 *params = mCaps.maxShaderUniformBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001390 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:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001525 *params = mCaps.maxShaderStorageBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001526 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:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001537 *params = mCaps.maxShaderStorageBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001538 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:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001549 *params = mCaps.maxShaderUniformBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001550 break;
1551 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001552 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001553 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:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001573 *params = mCaps.maxShaderStorageBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001574 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:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001620 *params = mCaps.maxShaderUniformBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001621 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:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001641 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001642 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:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001653 *params = mCaps.maxShaderStorageBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001654 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;
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001668 // GLES1 emulation: Vertex attribute queries
1669 case GL_VERTEX_ARRAY_BUFFER_BINDING:
1670 case GL_NORMAL_ARRAY_BUFFER_BINDING:
1671 case GL_COLOR_ARRAY_BUFFER_BINDING:
1672 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
1673 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
1674 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1675 GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, params);
1676 break;
1677 case GL_VERTEX_ARRAY_STRIDE:
1678 case GL_NORMAL_ARRAY_STRIDE:
1679 case GL_COLOR_ARRAY_STRIDE:
1680 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
1681 case GL_TEXTURE_COORD_ARRAY_STRIDE:
1682 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1683 GL_VERTEX_ATTRIB_ARRAY_STRIDE, params);
1684 break;
1685 case GL_VERTEX_ARRAY_SIZE:
1686 case GL_COLOR_ARRAY_SIZE:
1687 case GL_TEXTURE_COORD_ARRAY_SIZE:
1688 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1689 GL_VERTEX_ATTRIB_ARRAY_SIZE, params);
1690 break;
1691 case GL_VERTEX_ARRAY_TYPE:
1692 case GL_COLOR_ARRAY_TYPE:
1693 case GL_NORMAL_ARRAY_TYPE:
1694 case GL_POINT_SIZE_ARRAY_TYPE_OES:
1695 case GL_TEXTURE_COORD_ARRAY_TYPE:
1696 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1697 GL_VERTEX_ATTRIB_ARRAY_TYPE, params);
1698 break;
1699
Jamie Madill231c7f52017-04-26 13:45:37 -04001700 default:
Jamie Madille98b1b52018-03-08 09:47:23 -05001701 handleError(mGLState.getIntegerv(this, pname, params));
Jamie Madill231c7f52017-04-26 13:45:37 -04001702 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001703 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001704}
1705
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001706void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001707{
Shannon Woods53a94a82014-06-24 15:20:36 -04001708 // Queries about context capabilities and maximums are answered by Context.
1709 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001710 switch (pname)
1711 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001712 case GL_MAX_ELEMENT_INDEX:
1713 *params = mCaps.maxElementIndex;
1714 break;
1715 case GL_MAX_UNIFORM_BLOCK_SIZE:
1716 *params = mCaps.maxUniformBlockSize;
1717 break;
1718 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
1719 *params = mCaps.maxCombinedVertexUniformComponents;
1720 break;
1721 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
1722 *params = mCaps.maxCombinedFragmentUniformComponents;
1723 break;
1724 case GL_MAX_SERVER_WAIT_TIMEOUT:
1725 *params = mCaps.maxServerWaitTimeout;
1726 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001727
Jamie Madill231c7f52017-04-26 13:45:37 -04001728 // GL_EXT_disjoint_timer_query
1729 case GL_TIMESTAMP_EXT:
1730 *params = mImplementation->getTimestamp();
1731 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001732
Jamie Madill231c7f52017-04-26 13:45:37 -04001733 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1734 *params = mCaps.maxShaderStorageBlockSize;
1735 break;
1736 default:
1737 UNREACHABLE();
1738 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001739 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001740}
1741
Geoff Lang70d0f492015-12-10 17:45:46 -05001742void Context::getPointerv(GLenum pname, void **params) const
1743{
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001744 mGLState.getPointerv(this, pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001745}
1746
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001747void Context::getPointervRobustANGLERobust(GLenum pname,
1748 GLsizei bufSize,
1749 GLsizei *length,
1750 void **params)
1751{
1752 UNIMPLEMENTED();
1753}
1754
Martin Radev66fb8202016-07-28 11:45:20 +03001755void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001756{
Shannon Woods53a94a82014-06-24 15:20:36 -04001757 // Queries about context capabilities and maximums are answered by Context.
1758 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001759
1760 GLenum nativeType;
1761 unsigned int numParams;
1762 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1763 ASSERT(queryStatus);
1764
1765 if (nativeType == GL_INT)
1766 {
1767 switch (target)
1768 {
1769 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1770 ASSERT(index < 3u);
1771 *data = mCaps.maxComputeWorkGroupCount[index];
1772 break;
1773 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1774 ASSERT(index < 3u);
1775 *data = mCaps.maxComputeWorkGroupSize[index];
1776 break;
1777 default:
1778 mGLState.getIntegeri_v(target, index, data);
1779 }
1780 }
1781 else
1782 {
1783 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1784 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001785}
1786
Brandon Jones59770802018-04-02 13:18:42 -07001787void Context::getIntegeri_vRobust(GLenum target,
1788 GLuint index,
1789 GLsizei bufSize,
1790 GLsizei *length,
1791 GLint *data)
1792{
1793 getIntegeri_v(target, index, data);
1794}
1795
Martin Radev66fb8202016-07-28 11:45:20 +03001796void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001797{
Shannon Woods53a94a82014-06-24 15:20:36 -04001798 // Queries about context capabilities and maximums are answered by Context.
1799 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001800
1801 GLenum nativeType;
1802 unsigned int numParams;
1803 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1804 ASSERT(queryStatus);
1805
1806 if (nativeType == GL_INT_64_ANGLEX)
1807 {
1808 mGLState.getInteger64i_v(target, index, data);
1809 }
1810 else
1811 {
1812 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1813 }
1814}
1815
Brandon Jones59770802018-04-02 13:18:42 -07001816void Context::getInteger64i_vRobust(GLenum target,
1817 GLuint index,
1818 GLsizei bufSize,
1819 GLsizei *length,
1820 GLint64 *data)
1821{
1822 getInteger64i_v(target, index, data);
1823}
1824
Martin Radev66fb8202016-07-28 11:45:20 +03001825void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1826{
1827 // Queries about context capabilities and maximums are answered by Context.
1828 // Queries about current GL state values are answered by State.
1829
1830 GLenum nativeType;
1831 unsigned int numParams;
1832 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1833 ASSERT(queryStatus);
1834
1835 if (nativeType == GL_BOOL)
1836 {
1837 mGLState.getBooleani_v(target, index, data);
1838 }
1839 else
1840 {
1841 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1842 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001843}
1844
Brandon Jones59770802018-04-02 13:18:42 -07001845void Context::getBooleani_vRobust(GLenum target,
1846 GLuint index,
1847 GLsizei bufSize,
1848 GLsizei *length,
1849 GLboolean *data)
1850{
1851 getBooleani_v(target, index, data);
1852}
1853
Corentin Wallez336129f2017-10-17 15:55:40 -04001854void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001855{
1856 Buffer *buffer = mGLState.getTargetBuffer(target);
1857 QueryBufferParameteriv(buffer, pname, params);
1858}
1859
Brandon Jones59770802018-04-02 13:18:42 -07001860void Context::getBufferParameterivRobust(BufferBinding target,
1861 GLenum pname,
1862 GLsizei bufSize,
1863 GLsizei *length,
1864 GLint *params)
1865{
1866 getBufferParameteriv(target, pname, params);
1867}
1868
He Yunchao010e4db2017-03-03 14:22:06 +08001869void Context::getFramebufferAttachmentParameteriv(GLenum target,
1870 GLenum attachment,
1871 GLenum pname,
1872 GLint *params)
1873{
1874 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08001875 QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08001876}
1877
Brandon Jones59770802018-04-02 13:18:42 -07001878void Context::getFramebufferAttachmentParameterivRobust(GLenum target,
1879 GLenum attachment,
1880 GLenum pname,
1881 GLsizei bufSize,
1882 GLsizei *length,
1883 GLint *params)
1884{
1885 getFramebufferAttachmentParameteriv(target, attachment, pname, params);
1886}
1887
He Yunchao010e4db2017-03-03 14:22:06 +08001888void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
1889{
1890 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
1891 QueryRenderbufferiv(this, renderbuffer, pname, params);
1892}
1893
Brandon Jones59770802018-04-02 13:18:42 -07001894void Context::getRenderbufferParameterivRobust(GLenum target,
1895 GLenum pname,
1896 GLsizei bufSize,
1897 GLsizei *length,
1898 GLint *params)
1899{
1900 getRenderbufferParameteriv(target, pname, params);
1901}
1902
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001903void Context::getTexParameterfv(TextureType target, GLenum pname, GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001904{
1905 Texture *texture = getTargetTexture(target);
1906 QueryTexParameterfv(texture, pname, params);
1907}
1908
Brandon Jones59770802018-04-02 13:18:42 -07001909void Context::getTexParameterfvRobust(TextureType target,
1910 GLenum pname,
1911 GLsizei bufSize,
1912 GLsizei *length,
1913 GLfloat *params)
1914{
1915 getTexParameterfv(target, pname, params);
1916}
1917
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001918void Context::getTexParameteriv(TextureType target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001919{
1920 Texture *texture = getTargetTexture(target);
1921 QueryTexParameteriv(texture, pname, params);
1922}
Jiajia Qin5451d532017-11-16 17:16:34 +08001923
Brandon Jones59770802018-04-02 13:18:42 -07001924void Context::getTexParameterivRobust(TextureType target,
1925 GLenum pname,
1926 GLsizei bufSize,
1927 GLsizei *length,
1928 GLint *params)
1929{
1930 getTexParameteriv(target, pname, params);
1931}
1932
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001933void Context::getTexParameterIivRobust(TextureType target,
1934 GLenum pname,
1935 GLsizei bufSize,
1936 GLsizei *length,
1937 GLint *params)
1938{
1939 UNIMPLEMENTED();
1940}
1941
1942void Context::getTexParameterIuivRobust(TextureType target,
1943 GLenum pname,
1944 GLsizei bufSize,
1945 GLsizei *length,
1946 GLuint *params)
1947{
1948 UNIMPLEMENTED();
1949}
1950
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001951void Context::getTexLevelParameteriv(TextureTarget target, GLint level, GLenum pname, GLint *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08001952{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001953 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05001954 QueryTexLevelParameteriv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08001955}
1956
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001957void Context::getTexLevelParameterivRobust(TextureTarget target,
1958 GLint level,
1959 GLenum pname,
1960 GLsizei bufSize,
1961 GLsizei *length,
1962 GLint *params)
1963{
1964 UNIMPLEMENTED();
1965}
1966
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001967void Context::getTexLevelParameterfv(TextureTarget target,
1968 GLint level,
1969 GLenum pname,
1970 GLfloat *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08001971{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001972 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05001973 QueryTexLevelParameterfv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08001974}
1975
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001976void Context::getTexLevelParameterfvRobust(TextureTarget target,
1977 GLint level,
1978 GLenum pname,
1979 GLsizei bufSize,
1980 GLsizei *length,
1981 GLfloat *params)
1982{
1983 UNIMPLEMENTED();
1984}
1985
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001986void Context::texParameterf(TextureType target, GLenum pname, GLfloat param)
He Yunchao010e4db2017-03-03 14:22:06 +08001987{
1988 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001989 SetTexParameterf(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04001990 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001991}
1992
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001993void Context::texParameterfv(TextureType target, GLenum pname, const GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001994{
1995 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001996 SetTexParameterfv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04001997 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001998}
1999
Brandon Jones59770802018-04-02 13:18:42 -07002000void Context::texParameterfvRobust(TextureType target,
2001 GLenum pname,
2002 GLsizei bufSize,
2003 const GLfloat *params)
2004{
2005 texParameterfv(target, pname, params);
2006}
2007
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002008void Context::texParameteri(TextureType target, GLenum pname, GLint param)
He Yunchao010e4db2017-03-03 14:22:06 +08002009{
2010 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002011 SetTexParameteri(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002012 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002013}
2014
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002015void Context::texParameteriv(TextureType target, GLenum pname, const GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002016{
2017 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002018 SetTexParameteriv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002019 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002020}
2021
Brandon Jones59770802018-04-02 13:18:42 -07002022void Context::texParameterivRobust(TextureType target,
2023 GLenum pname,
2024 GLsizei bufSize,
2025 const GLint *params)
2026{
2027 texParameteriv(target, pname, params);
2028}
2029
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002030void Context::texParameterIivRobust(TextureType target,
2031 GLenum pname,
2032 GLsizei bufSize,
2033 const GLint *params)
2034{
2035 UNIMPLEMENTED();
2036}
2037
2038void Context::texParameterIuivRobust(TextureType target,
2039 GLenum pname,
2040 GLsizei bufSize,
2041 const GLuint *params)
2042{
2043 UNIMPLEMENTED();
2044}
2045
Jamie Madill675fe712016-12-19 13:07:54 -05002046void Context::drawArrays(GLenum mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002047{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002048 // No-op if zero count
2049 if (count == 0)
2050 {
2051 return;
2052 }
2053
Jamie Madill05b35b22017-10-03 09:01:44 -04002054 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002055 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
Jamie Madill09463932018-04-04 05:26:59 -04002056 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count, 1);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002057}
2058
Jamie Madill675fe712016-12-19 13:07:54 -05002059void Context::drawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04002060{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002061 // No-op if zero count
2062 if (count == 0 || instanceCount == 0)
2063 {
2064 return;
2065 }
2066
Jamie Madill05b35b22017-10-03 09:01:44 -04002067 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002068 ANGLE_CONTEXT_TRY(
2069 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
Jamie Madill09463932018-04-04 05:26:59 -04002070 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count,
2071 instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -04002072}
2073
Jamie Madill876429b2017-04-20 15:46:24 -04002074void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002075{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002076 // No-op if zero count
2077 if (count == 0)
2078 {
2079 return;
2080 }
2081
Jamie Madill05b35b22017-10-03 09:01:44 -04002082 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002083 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04002084}
2085
Jamie Madill675fe712016-12-19 13:07:54 -05002086void Context::drawElementsInstanced(GLenum mode,
2087 GLsizei count,
2088 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002089 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04002090 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04002091{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002092 // No-op if zero count
2093 if (count == 0 || instances == 0)
2094 {
2095 return;
2096 }
2097
Jamie Madill05b35b22017-10-03 09:01:44 -04002098 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002099 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08002100 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04002101}
2102
Jamie Madill675fe712016-12-19 13:07:54 -05002103void Context::drawRangeElements(GLenum mode,
2104 GLuint start,
2105 GLuint end,
2106 GLsizei count,
2107 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002108 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04002109{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002110 // No-op if zero count
2111 if (count == 0)
2112 {
2113 return;
2114 }
2115
Jamie Madill05b35b22017-10-03 09:01:44 -04002116 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002117 ANGLE_CONTEXT_TRY(
2118 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002119}
2120
Jamie Madill876429b2017-04-20 15:46:24 -04002121void Context::drawArraysIndirect(GLenum mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002122{
Jamie Madill05b35b22017-10-03 09:01:44 -04002123 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002124 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002125}
2126
Jamie Madill876429b2017-04-20 15:46:24 -04002127void Context::drawElementsIndirect(GLenum mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002128{
Jamie Madill05b35b22017-10-03 09:01:44 -04002129 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002130 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002131}
2132
Jamie Madill675fe712016-12-19 13:07:54 -05002133void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002134{
Jamie Madillafa02a22017-11-23 12:57:38 -05002135 handleError(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05002136}
2137
Jamie Madill675fe712016-12-19 13:07:54 -05002138void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05002139{
Jamie Madillafa02a22017-11-23 12:57:38 -05002140 handleError(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002141}
2142
Austin Kinross6ee1e782015-05-29 17:05:37 -07002143void Context::insertEventMarker(GLsizei length, const char *marker)
2144{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002145 ASSERT(mImplementation);
2146 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07002147}
2148
2149void Context::pushGroupMarker(GLsizei length, const char *marker)
2150{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002151 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05002152
2153 if (marker == nullptr)
2154 {
2155 // From the EXT_debug_marker spec,
2156 // "If <marker> is null then an empty string is pushed on the stack."
2157 mImplementation->pushGroupMarker(length, "");
2158 }
2159 else
2160 {
2161 mImplementation->pushGroupMarker(length, marker);
2162 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07002163}
2164
2165void Context::popGroupMarker()
2166{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002167 ASSERT(mImplementation);
2168 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07002169}
2170
Geoff Langd8605522016-04-13 10:19:12 -04002171void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
2172{
2173 Program *programObject = getProgram(program);
2174 ASSERT(programObject);
2175
2176 programObject->bindUniformLocation(location, name);
2177}
2178
Brandon Jones59770802018-04-02 13:18:42 -07002179void Context::coverageModulation(GLenum components)
Sami Väisänena797e062016-05-12 15:23:40 +03002180{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002181 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03002182}
2183
Brandon Jones59770802018-04-02 13:18:42 -07002184void Context::matrixLoadf(GLenum matrixMode, const GLfloat *matrix)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002185{
2186 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
2187}
2188
Brandon Jones59770802018-04-02 13:18:42 -07002189void Context::matrixLoadIdentity(GLenum matrixMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002190{
2191 GLfloat I[16];
2192 angle::Matrix<GLfloat>::setToIdentity(I);
2193
2194 mGLState.loadPathRenderingMatrix(matrixMode, I);
2195}
2196
2197void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
2198{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002199 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002200 if (!pathObj)
2201 return;
2202
2203 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002204 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002205
2206 mImplementation->stencilFillPath(pathObj, fillMode, mask);
2207}
2208
2209void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
2210{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002211 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002212 if (!pathObj)
2213 return;
2214
2215 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002216 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002217
2218 mImplementation->stencilStrokePath(pathObj, reference, mask);
2219}
2220
2221void Context::coverFillPath(GLuint path, GLenum coverMode)
2222{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002223 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002224 if (!pathObj)
2225 return;
2226
2227 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002228 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002229
2230 mImplementation->coverFillPath(pathObj, coverMode);
2231}
2232
2233void Context::coverStrokePath(GLuint path, GLenum coverMode)
2234{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002235 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002236 if (!pathObj)
2237 return;
2238
2239 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002240 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002241
2242 mImplementation->coverStrokePath(pathObj, coverMode);
2243}
2244
2245void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
2246{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002247 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002248 if (!pathObj)
2249 return;
2250
2251 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002252 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002253
2254 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
2255}
2256
2257void Context::stencilThenCoverStrokePath(GLuint path,
2258 GLint reference,
2259 GLuint mask,
2260 GLenum coverMode)
2261{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002262 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002263 if (!pathObj)
2264 return;
2265
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änene45e53b2016-05-25 10:36:04 +03002268
2269 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2270}
2271
Sami Väisänend59ca052016-06-21 16:10:00 +03002272void Context::coverFillPathInstanced(GLsizei numPaths,
2273 GLenum pathNameType,
2274 const void *paths,
2275 GLuint pathBase,
2276 GLenum coverMode,
2277 GLenum transformType,
2278 const GLfloat *transformValues)
2279{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002280 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002281
2282 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002283 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002284
2285 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2286}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002287
Sami Väisänend59ca052016-06-21 16:10:00 +03002288void Context::coverStrokePathInstanced(GLsizei numPaths,
2289 GLenum pathNameType,
2290 const void *paths,
2291 GLuint pathBase,
2292 GLenum coverMode,
2293 GLenum transformType,
2294 const GLfloat *transformValues)
2295{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002296 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002297
2298 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002299 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002300
2301 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2302 transformValues);
2303}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002304
Sami Väisänend59ca052016-06-21 16:10:00 +03002305void Context::stencilFillPathInstanced(GLsizei numPaths,
2306 GLenum pathNameType,
2307 const void *paths,
2308 GLuint pathBase,
2309 GLenum fillMode,
2310 GLuint mask,
2311 GLenum transformType,
2312 const GLfloat *transformValues)
2313{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002314 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002315
2316 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002317 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002318
2319 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2320 transformValues);
2321}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002322
Sami Väisänend59ca052016-06-21 16:10:00 +03002323void Context::stencilStrokePathInstanced(GLsizei numPaths,
2324 GLenum pathNameType,
2325 const void *paths,
2326 GLuint pathBase,
2327 GLint reference,
2328 GLuint mask,
2329 GLenum transformType,
2330 const GLfloat *transformValues)
2331{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002332 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002333
2334 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002335 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002336
2337 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2338 transformValues);
2339}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002340
Sami Väisänend59ca052016-06-21 16:10:00 +03002341void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2342 GLenum pathNameType,
2343 const void *paths,
2344 GLuint pathBase,
2345 GLenum fillMode,
2346 GLuint mask,
2347 GLenum coverMode,
2348 GLenum transformType,
2349 const GLfloat *transformValues)
2350{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002351 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002352
2353 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002354 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002355
2356 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2357 transformType, transformValues);
2358}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002359
Sami Väisänend59ca052016-06-21 16:10:00 +03002360void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2361 GLenum pathNameType,
2362 const void *paths,
2363 GLuint pathBase,
2364 GLint reference,
2365 GLuint mask,
2366 GLenum coverMode,
2367 GLenum transformType,
2368 const GLfloat *transformValues)
2369{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002370 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002371
2372 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002373 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002374
2375 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2376 transformType, transformValues);
2377}
2378
Sami Väisänen46eaa942016-06-29 10:26:37 +03002379void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2380{
2381 auto *programObject = getProgram(program);
2382
2383 programObject->bindFragmentInputLocation(location, name);
2384}
2385
2386void Context::programPathFragmentInputGen(GLuint program,
2387 GLint location,
2388 GLenum genMode,
2389 GLint components,
2390 const GLfloat *coeffs)
2391{
2392 auto *programObject = getProgram(program);
2393
Jamie Madillbd044ed2017-06-05 12:59:21 -04002394 programObject->pathFragmentInputGen(this, location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002395}
2396
jchen1015015f72017-03-16 13:54:21 +08002397GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2398{
jchen10fd7c3b52017-03-21 15:36:03 +08002399 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002400 return QueryProgramResourceIndex(programObject, programInterface, name);
2401}
2402
jchen10fd7c3b52017-03-21 15:36:03 +08002403void Context::getProgramResourceName(GLuint program,
2404 GLenum programInterface,
2405 GLuint index,
2406 GLsizei bufSize,
2407 GLsizei *length,
2408 GLchar *name)
2409{
2410 const auto *programObject = getProgram(program);
2411 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2412}
2413
jchen10191381f2017-04-11 13:59:04 +08002414GLint Context::getProgramResourceLocation(GLuint program,
2415 GLenum programInterface,
2416 const GLchar *name)
2417{
2418 const auto *programObject = getProgram(program);
2419 return QueryProgramResourceLocation(programObject, programInterface, name);
2420}
2421
jchen10880683b2017-04-12 16:21:55 +08002422void Context::getProgramResourceiv(GLuint program,
2423 GLenum programInterface,
2424 GLuint index,
2425 GLsizei propCount,
2426 const GLenum *props,
2427 GLsizei bufSize,
2428 GLsizei *length,
2429 GLint *params)
2430{
2431 const auto *programObject = getProgram(program);
2432 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2433 length, params);
2434}
2435
jchen10d9cd7b72017-08-30 15:04:25 +08002436void Context::getProgramInterfaceiv(GLuint program,
2437 GLenum programInterface,
2438 GLenum pname,
2439 GLint *params)
2440{
2441 const auto *programObject = getProgram(program);
2442 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2443}
2444
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002445void Context::getProgramInterfaceivRobust(GLuint program,
2446 GLenum programInterface,
2447 GLenum pname,
2448 GLsizei bufSize,
2449 GLsizei *length,
2450 GLint *params)
2451{
2452 UNIMPLEMENTED();
2453}
2454
Jamie Madill427064d2018-04-13 16:20:34 -04002455void Context::handleError(const Error &error) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002456{
Geoff Lang7b19a492018-04-20 09:31:52 -04002457 if (ANGLE_UNLIKELY(error.isError()))
Geoff Langda5777c2014-07-11 09:52:58 -04002458 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002459 GLenum code = error.getCode();
2460 mErrors.insert(code);
2461 if (code == GL_OUT_OF_MEMORY && getWorkarounds().loseContextOnOutOfMemory)
2462 {
2463 markContextLost();
2464 }
Geoff Lang70d0f492015-12-10 17:45:46 -05002465
Geoff Langee6884e2017-11-09 16:51:11 -05002466 ASSERT(!error.getMessage().empty());
2467 mGLState.getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, error.getID(),
2468 GL_DEBUG_SEVERITY_HIGH, error.getMessage());
Geoff Langda5777c2014-07-11 09:52:58 -04002469 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002470}
2471
2472// Get one of the recorded errors and clear its flag, if any.
2473// [OpenGL ES 2.0.24] section 2.5 page 13.
2474GLenum Context::getError()
2475{
Geoff Langda5777c2014-07-11 09:52:58 -04002476 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002477 {
Geoff Langda5777c2014-07-11 09:52:58 -04002478 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002479 }
Geoff Langda5777c2014-07-11 09:52:58 -04002480 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002481 {
Geoff Langda5777c2014-07-11 09:52:58 -04002482 GLenum error = *mErrors.begin();
2483 mErrors.erase(mErrors.begin());
2484 return error;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002485 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002486}
2487
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002488// NOTE: this function should not assume that this context is current!
Jamie Madill427064d2018-04-13 16:20:34 -04002489void Context::markContextLost() const
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002490{
2491 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002492 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002493 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002494 mContextLostForced = true;
2495 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002496 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002497}
2498
Jamie Madill427064d2018-04-13 16:20:34 -04002499bool Context::isContextLost() const
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002500{
2501 return mContextLost;
2502}
2503
Jamie Madillfa920eb2018-01-04 11:45:50 -05002504GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002505{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002506 // Even if the application doesn't want to know about resets, we want to know
2507 // as it will allow us to skip all the calls.
2508 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002509 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002510 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002511 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002512 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002513 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002514
2515 // EXT_robustness, section 2.6: If the reset notification behavior is
2516 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2517 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2518 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002519 }
2520
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002521 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2522 // status should be returned at least once, and GL_NO_ERROR should be returned
2523 // once the device has finished resetting.
2524 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002525 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002526 ASSERT(mResetStatus == GL_NO_ERROR);
2527 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002528
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002529 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002530 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002531 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002532 }
2533 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002534 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002535 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002536 // If markContextLost was used to mark the context lost then
2537 // assume that is not recoverable, and continue to report the
2538 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002539 mResetStatus = mImplementation->getResetStatus();
2540 }
Jamie Madill893ab082014-05-16 16:56:10 -04002541
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002542 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002543}
2544
2545bool Context::isResetNotificationEnabled()
2546{
2547 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2548}
2549
Corentin Walleze3b10e82015-05-20 11:06:25 -04002550const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002551{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002552 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002553}
2554
2555EGLenum Context::getClientType() const
2556{
2557 return mClientType;
2558}
2559
2560EGLenum Context::getRenderBuffer() const
2561{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002562 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2563 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002564 {
2565 return EGL_NONE;
2566 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002567
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002568 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002569 ASSERT(backAttachment != nullptr);
2570 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002571}
2572
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002573VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002574{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002575 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002576 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2577 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002578 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002579 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2580 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002581
Jamie Madill96a483b2017-06-27 16:49:21 -04002582 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002583 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002584
2585 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002586}
2587
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002588TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002589{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002590 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002591 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2592 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002593 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002594 transformFeedback =
2595 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002596 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002597 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002598 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002599
2600 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002601}
2602
2603bool Context::isVertexArrayGenerated(GLuint vertexArray)
2604{
Jamie Madill96a483b2017-06-27 16:49:21 -04002605 ASSERT(mVertexArrayMap.contains(0));
2606 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002607}
2608
2609bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2610{
Jamie Madill96a483b2017-06-27 16:49:21 -04002611 ASSERT(mTransformFeedbackMap.contains(0));
2612 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002613}
2614
Shannon Woods53a94a82014-06-24 15:20:36 -04002615void Context::detachTexture(GLuint texture)
2616{
2617 // Simple pass-through to State's detachTexture method, as textures do not require
2618 // allocation map management either here or in the resource manager at detach time.
2619 // Zero textures are held by the Context, and we don't attempt to request them from
2620 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002621 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002622}
2623
James Darpinian4d9d4832018-03-13 12:43:28 -07002624void Context::detachBuffer(Buffer *buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002625{
Yuly Novikov5807a532015-12-03 13:01:22 -05002626 // Simple pass-through to State's detachBuffer method, since
2627 // only buffer attachments to container objects that are bound to the current context
2628 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002629
Yuly Novikov5807a532015-12-03 13:01:22 -05002630 // [OpenGL ES 3.2] section 5.1.2 page 45:
2631 // Attachments to unbound container objects, such as
2632 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2633 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002634 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002635}
2636
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002637void Context::detachFramebuffer(GLuint framebuffer)
2638{
Shannon Woods53a94a82014-06-24 15:20:36 -04002639 // Framebuffer detachment is handled by Context, because 0 is a valid
2640 // Framebuffer object, and a pointer to it must be passed from Context
2641 // to State at binding time.
2642
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002643 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002644 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2645 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2646 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002647
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002648 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002649 {
2650 bindReadFramebuffer(0);
2651 }
2652
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002653 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002654 {
2655 bindDrawFramebuffer(0);
2656 }
2657}
2658
2659void Context::detachRenderbuffer(GLuint renderbuffer)
2660{
Jamie Madilla02315b2017-02-23 14:14:47 -05002661 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002662}
2663
Jamie Madill57a89722013-07-02 11:57:03 -04002664void Context::detachVertexArray(GLuint vertexArray)
2665{
Jamie Madill77a72f62015-04-14 11:18:32 -04002666 // Vertex array detachment is handled by Context, because 0 is a valid
2667 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002668 // binding time.
2669
Jamie Madill57a89722013-07-02 11:57:03 -04002670 // [OpenGL ES 3.0.2] section 2.10 page 43:
2671 // If a vertex array object that is currently bound is deleted, the binding
2672 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madill7267aa62018-04-17 15:28:21 -04002673 if (mGLState.removeVertexArrayBinding(this, vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002674 {
2675 bindVertexArray(0);
2676 }
2677}
2678
Geoff Langc8058452014-02-03 12:04:11 -05002679void Context::detachTransformFeedback(GLuint transformFeedback)
2680{
Corentin Walleza2257da2016-04-19 16:43:12 -04002681 // Transform feedback detachment is handled by Context, because 0 is a valid
2682 // transform feedback, and a pointer to it must be passed from Context to State at
2683 // binding time.
2684
2685 // The OpenGL specification doesn't mention what should happen when the currently bound
2686 // transform feedback object is deleted. Since it is a container object, we treat it like
2687 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002688 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002689 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002690 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002691 }
Geoff Langc8058452014-02-03 12:04:11 -05002692}
2693
Jamie Madilldc356042013-07-19 16:36:57 -04002694void Context::detachSampler(GLuint sampler)
2695{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002696 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002697}
2698
Yunchao Hea336b902017-08-02 16:05:21 +08002699void Context::detachProgramPipeline(GLuint pipeline)
2700{
2701 mGLState.detachProgramPipeline(this, pipeline);
2702}
2703
Jamie Madill3ef140a2017-08-26 23:11:21 -04002704void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002705{
Shaodde78e82017-05-22 14:13:27 +08002706 mGLState.setVertexAttribDivisor(this, index, divisor);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002707}
2708
Jamie Madille29d1672013-07-19 16:36:57 -04002709void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2710{
Geoff Langc1984ed2016-10-07 12:41:00 -04002711 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002712 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002713 SetSamplerParameteri(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002714 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002715}
Jamie Madille29d1672013-07-19 16:36:57 -04002716
Geoff Langc1984ed2016-10-07 12:41:00 -04002717void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2718{
2719 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002720 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002721 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002722 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002723}
2724
Brandon Jones59770802018-04-02 13:18:42 -07002725void Context::samplerParameterivRobust(GLuint sampler,
2726 GLenum pname,
2727 GLsizei bufSize,
2728 const GLint *param)
2729{
2730 samplerParameteriv(sampler, pname, param);
2731}
2732
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002733void Context::samplerParameterIivRobust(GLuint sampler,
2734 GLenum pname,
2735 GLsizei bufSize,
2736 const GLint *param)
2737{
2738 UNIMPLEMENTED();
2739}
2740
2741void Context::samplerParameterIuivRobust(GLuint sampler,
2742 GLenum pname,
2743 GLsizei bufSize,
2744 const GLuint *param)
2745{
2746 UNIMPLEMENTED();
2747}
2748
Jamie Madille29d1672013-07-19 16:36:57 -04002749void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2750{
Geoff Langc1984ed2016-10-07 12:41:00 -04002751 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002752 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002753 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002754 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002755}
2756
Geoff Langc1984ed2016-10-07 12:41:00 -04002757void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002758{
Geoff Langc1984ed2016-10-07 12:41:00 -04002759 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002760 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002761 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002762 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002763}
2764
Brandon Jones59770802018-04-02 13:18:42 -07002765void Context::samplerParameterfvRobust(GLuint sampler,
2766 GLenum pname,
2767 GLsizei bufSize,
2768 const GLfloat *param)
2769{
2770 samplerParameterfv(sampler, pname, param);
2771}
2772
Geoff Langc1984ed2016-10-07 12:41:00 -04002773void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002774{
Geoff Langc1984ed2016-10-07 12:41:00 -04002775 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002776 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002777 QuerySamplerParameteriv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002778 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002779}
Jamie Madill9675b802013-07-19 16:36:59 -04002780
Brandon Jones59770802018-04-02 13:18:42 -07002781void Context::getSamplerParameterivRobust(GLuint sampler,
2782 GLenum pname,
2783 GLsizei bufSize,
2784 GLsizei *length,
2785 GLint *params)
2786{
2787 getSamplerParameteriv(sampler, pname, params);
2788}
2789
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002790void Context::getSamplerParameterIivRobust(GLuint sampler,
2791 GLenum pname,
2792 GLsizei bufSize,
2793 GLsizei *length,
2794 GLint *params)
2795{
2796 UNIMPLEMENTED();
2797}
2798
2799void Context::getSamplerParameterIuivRobust(GLuint sampler,
2800 GLenum pname,
2801 GLsizei bufSize,
2802 GLsizei *length,
2803 GLuint *params)
2804{
2805 UNIMPLEMENTED();
2806}
2807
Geoff Langc1984ed2016-10-07 12:41:00 -04002808void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2809{
2810 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002811 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002812 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002813 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002814}
2815
Brandon Jones59770802018-04-02 13:18:42 -07002816void Context::getSamplerParameterfvRobust(GLuint sampler,
2817 GLenum pname,
2818 GLsizei bufSize,
2819 GLsizei *length,
2820 GLfloat *params)
2821{
2822 getSamplerParameterfv(sampler, pname, params);
2823}
2824
Olli Etuahof0fee072016-03-30 15:11:58 +03002825void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2826{
2827 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002828 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002829}
2830
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002831void Context::initRendererString()
2832{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002833 std::ostringstream rendererString;
2834 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002835 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002836 rendererString << ")";
2837
Geoff Langcec35902014-04-16 10:52:36 -04002838 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002839}
2840
Geoff Langc339c4e2016-11-29 10:37:36 -05002841void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002842{
Geoff Langc339c4e2016-11-29 10:37:36 -05002843 const Version &clientVersion = getClientVersion();
2844
2845 std::ostringstream versionString;
2846 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2847 << ANGLE_VERSION_STRING << ")";
2848 mVersionString = MakeStaticString(versionString.str());
2849
2850 std::ostringstream shadingLanguageVersionString;
2851 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2852 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2853 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2854 << ")";
2855 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002856}
2857
Geoff Langcec35902014-04-16 10:52:36 -04002858void Context::initExtensionStrings()
2859{
Geoff Langc339c4e2016-11-29 10:37:36 -05002860 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2861 std::ostringstream combinedStringStream;
2862 std::copy(strings.begin(), strings.end(),
2863 std::ostream_iterator<const char *>(combinedStringStream, " "));
2864 return MakeStaticString(combinedStringStream.str());
2865 };
2866
2867 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002868 for (const auto &extensionString : mExtensions.getStrings())
2869 {
2870 mExtensionStrings.push_back(MakeStaticString(extensionString));
2871 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002872 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002873
Geoff Langc339c4e2016-11-29 10:37:36 -05002874 mRequestableExtensionStrings.clear();
2875 for (const auto &extensionInfo : GetExtensionInfoMap())
2876 {
2877 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08002878 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
Geoff Langb0f917f2017-12-05 13:41:54 -05002879 mSupportedExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002880 {
2881 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
2882 }
2883 }
2884 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002885}
2886
Geoff Langc339c4e2016-11-29 10:37:36 -05002887const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04002888{
Geoff Langc339c4e2016-11-29 10:37:36 -05002889 switch (name)
2890 {
2891 case GL_VENDOR:
2892 return reinterpret_cast<const GLubyte *>("Google Inc.");
2893
2894 case GL_RENDERER:
2895 return reinterpret_cast<const GLubyte *>(mRendererString);
2896
2897 case GL_VERSION:
2898 return reinterpret_cast<const GLubyte *>(mVersionString);
2899
2900 case GL_SHADING_LANGUAGE_VERSION:
2901 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
2902
2903 case GL_EXTENSIONS:
2904 return reinterpret_cast<const GLubyte *>(mExtensionString);
2905
2906 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2907 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
2908
2909 default:
2910 UNREACHABLE();
2911 return nullptr;
2912 }
Geoff Langcec35902014-04-16 10:52:36 -04002913}
2914
Geoff Langc339c4e2016-11-29 10:37:36 -05002915const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04002916{
Geoff Langc339c4e2016-11-29 10:37:36 -05002917 switch (name)
2918 {
2919 case GL_EXTENSIONS:
2920 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
2921
2922 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2923 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
2924
2925 default:
2926 UNREACHABLE();
2927 return nullptr;
2928 }
Geoff Langcec35902014-04-16 10:52:36 -04002929}
2930
2931size_t Context::getExtensionStringCount() const
2932{
2933 return mExtensionStrings.size();
2934}
2935
Geoff Lang111a99e2017-10-17 10:58:41 -04002936bool Context::isExtensionRequestable(const char *name)
2937{
2938 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2939 auto extension = extensionInfos.find(name);
2940
Geoff Lang111a99e2017-10-17 10:58:41 -04002941 return extension != extensionInfos.end() && extension->second.Requestable &&
Geoff Langb0f917f2017-12-05 13:41:54 -05002942 mSupportedExtensions.*(extension->second.ExtensionsMember);
Geoff Lang111a99e2017-10-17 10:58:41 -04002943}
2944
Geoff Langc339c4e2016-11-29 10:37:36 -05002945void Context::requestExtension(const char *name)
2946{
2947 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2948 ASSERT(extensionInfos.find(name) != extensionInfos.end());
2949 const auto &extension = extensionInfos.at(name);
2950 ASSERT(extension.Requestable);
Geoff Langb0f917f2017-12-05 13:41:54 -05002951 ASSERT(isExtensionRequestable(name));
Geoff Langc339c4e2016-11-29 10:37:36 -05002952
2953 if (mExtensions.*(extension.ExtensionsMember))
2954 {
2955 // Extension already enabled
2956 return;
2957 }
2958
2959 mExtensions.*(extension.ExtensionsMember) = true;
2960 updateCaps();
2961 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08002962
Jamie Madill2f348d22017-06-05 10:50:59 -04002963 // Release the shader compiler so it will be re-created with the requested extensions enabled.
2964 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04002965
Jamie Madill81c2e252017-09-09 23:32:46 -04002966 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
2967 // sampleable.
Jamie Madilld4442552018-02-27 22:03:47 -05002968 mState.mTextures->signalAllTexturesDirty(this);
Geoff Lang9aded172017-04-05 11:07:56 -04002969 for (auto &zeroTexture : mZeroTextures)
2970 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002971 if (zeroTexture.get() != nullptr)
2972 {
2973 zeroTexture->signalDirty(this, InitState::Initialized);
2974 }
Geoff Lang9aded172017-04-05 11:07:56 -04002975 }
2976
2977 mState.mFramebuffers->invalidateFramebufferComplenessCache();
Geoff Langc339c4e2016-11-29 10:37:36 -05002978}
2979
2980size_t Context::getRequestableExtensionStringCount() const
2981{
2982 return mRequestableExtensionStrings.size();
2983}
2984
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002985void Context::beginTransformFeedback(GLenum primitiveMode)
2986{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002987 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002988 ASSERT(transformFeedback != nullptr);
2989 ASSERT(!transformFeedback->isPaused());
2990
Jamie Madill6c1f6712017-02-14 19:08:04 -05002991 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002992}
2993
2994bool Context::hasActiveTransformFeedback(GLuint program) const
2995{
2996 for (auto pair : mTransformFeedbackMap)
2997 {
2998 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
2999 {
3000 return true;
3001 }
3002 }
3003 return false;
3004}
3005
Geoff Langb0f917f2017-12-05 13:41:54 -05003006Extensions Context::generateSupportedExtensions(const egl::DisplayExtensions &displayExtensions,
3007 bool robustResourceInit) const
3008{
3009 Extensions supportedExtensions = mImplementation->getNativeExtensions();
3010
3011 if (getClientVersion() < ES_2_0)
3012 {
3013 // Default extensions for GLES1
3014 supportedExtensions.pointSizeArray = true;
Lingfeng Yang23dc90b2018-04-23 09:01:49 -07003015 supportedExtensions.textureCubeMap = true;
Geoff Langb0f917f2017-12-05 13:41:54 -05003016 }
3017
3018 if (getClientVersion() < ES_3_0)
3019 {
3020 // Disable ES3+ extensions
3021 supportedExtensions.colorBufferFloat = false;
3022 supportedExtensions.eglImageExternalEssl3 = false;
3023 supportedExtensions.textureNorm16 = false;
3024 supportedExtensions.multiview = false;
3025 supportedExtensions.maxViews = 1u;
3026 }
3027
3028 if (getClientVersion() < ES_3_1)
3029 {
3030 // Disable ES3.1+ extensions
3031 supportedExtensions.geometryShader = false;
3032 }
3033
3034 if (getClientVersion() > ES_2_0)
3035 {
3036 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
3037 // supportedExtensions.sRGB = false;
3038 }
3039
3040 // Some extensions are always available because they are implemented in the GL layer.
3041 supportedExtensions.bindUniformLocation = true;
3042 supportedExtensions.vertexArrayObject = true;
3043 supportedExtensions.bindGeneratesResource = true;
3044 supportedExtensions.clientArrays = true;
3045 supportedExtensions.requestExtension = true;
3046
3047 // Enable the no error extension if the context was created with the flag.
3048 supportedExtensions.noError = mSkipValidation;
3049
3050 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
3051 supportedExtensions.surfacelessContext = displayExtensions.surfacelessContext;
3052
3053 // Explicitly enable GL_KHR_debug
3054 supportedExtensions.debug = true;
3055 supportedExtensions.maxDebugMessageLength = 1024;
3056 supportedExtensions.maxDebugLoggedMessages = 1024;
3057 supportedExtensions.maxDebugGroupStackDepth = 1024;
3058 supportedExtensions.maxLabelLength = 1024;
3059
3060 // Explicitly enable GL_ANGLE_robust_client_memory
3061 supportedExtensions.robustClientMemory = true;
3062
3063 // Determine robust resource init availability from EGL.
3064 supportedExtensions.robustResourceInitialization = robustResourceInit;
3065
3066 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
3067 // supports it.
3068 supportedExtensions.robustBufferAccessBehavior =
3069 mRobustAccess && supportedExtensions.robustBufferAccessBehavior;
3070
3071 // Enable the cache control query unconditionally.
3072 supportedExtensions.programCacheControl = true;
3073
3074 return supportedExtensions;
3075}
3076
Geoff Langb433e872017-10-05 14:01:47 -04003077void Context::initCaps(const egl::DisplayExtensions &displayExtensions, bool robustResourceInit)
Geoff Lang493daf52014-07-03 13:38:44 -04003078{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04003079 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04003080
Geoff Langb0f917f2017-12-05 13:41:54 -05003081 mSupportedExtensions = generateSupportedExtensions(displayExtensions, robustResourceInit);
3082 mExtensions = mSupportedExtensions;
Lingfeng Yang01074432018-04-16 10:19:51 -07003083
3084 mLimitations = mImplementation->getNativeLimitations();
3085
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003086 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
3087 if (getClientVersion() < Version(2, 0))
3088 {
3089 mCaps.maxMultitextureUnits = 4;
3090 mCaps.maxClipPlanes = 6;
3091 mCaps.maxLights = 8;
Lingfeng Yange547aac2018-04-05 09:39:20 -07003092 mCaps.maxModelviewMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3093 mCaps.maxProjectionMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3094 mCaps.maxTextureMatrixStackDepth = Caps::GlobalMatrixStackDepth;
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003095 }
3096
Geoff Lang301d1612014-07-09 10:34:37 -04003097 // Apply implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04003098 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003099
Jamie Madill0f80ed82017-09-19 00:24:56 -04003100 if (getClientVersion() < ES_3_1)
3101 {
3102 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
3103 }
3104 else
3105 {
3106 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
3107 }
Geoff Lang301d1612014-07-09 10:34:37 -04003108
Jiawei Shao54aafe52018-04-27 14:54:57 +08003109 LimitCap(&mCaps.maxShaderUniformBlocks[ShaderType::Vertex],
3110 IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
Jamie Madill0f80ed82017-09-19 00:24:56 -04003111 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3112 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3113
3114 // Limit textures as well, so we can use fast bitsets with texture bindings.
3115 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
Jiawei Shao54aafe52018-04-27 14:54:57 +08003116 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Vertex],
3117 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
3118 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Fragment],
3119 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04003120
Jiawei Shaodb342272017-09-27 10:21:45 +08003121 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
3122
Geoff Langc287ea62016-09-16 14:46:51 -04003123 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05003124 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04003125 for (const auto &extensionInfo : GetExtensionInfoMap())
3126 {
Geoff Lang0ab41fa2018-03-14 11:03:30 -04003127 // If the user has requested that extensions start disabled and they are requestable,
3128 // disable them.
3129 if (!mExtensionsEnabled && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04003130 {
3131 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
3132 }
3133 }
3134
3135 // Generate texture caps
3136 updateCaps();
3137}
3138
3139void Context::updateCaps()
3140{
Geoff Lang900013c2014-07-07 11:32:19 -04003141 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04003142 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04003143
Jamie Madill7b62cf92017-11-02 15:20:49 -04003144 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04003145 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04003146 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04003147 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003148
Geoff Lang0d8b7242015-09-09 14:56:53 -04003149 // Update the format caps based on the client version and extensions.
3150 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
3151 // ES3.
3152 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003153 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04003154 formatCaps.renderable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003155 formatCaps.renderable && formatInfo.renderSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04003156 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003157 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04003158
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003159 // OpenGL ES does not support multisampling with non-rendererable formats
3160 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Olli Etuaho50c562d2017-06-06 14:43:30 +03003161 if (!formatCaps.renderable ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003162 (getClientVersion() < ES_3_1 &&
3163 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04003164 {
Geoff Langd87878e2014-09-19 15:42:59 -04003165 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04003166 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03003167 else
3168 {
3169 // We may have limited the max samples for some required renderbuffer formats due to
3170 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
3171 GLuint formatMaxSamples = formatCaps.getMaxSamples();
3172
3173 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
3174 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
3175 // exception of signed and unsigned integer formats."
3176 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
3177 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
3178 {
3179 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
3180 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
3181 }
3182
3183 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
3184 if (getClientVersion() >= ES_3_1)
3185 {
3186 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
3187 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
3188 // the exception that the signed and unsigned integer formats are required only to
3189 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
3190 // multisamples, which must be at least one."
3191 if (formatInfo.componentType == GL_INT ||
3192 formatInfo.componentType == GL_UNSIGNED_INT)
3193 {
3194 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
3195 }
3196
3197 // GLES 3.1 section 19.3.1.
3198 if (formatCaps.texturable)
3199 {
3200 if (formatInfo.depthBits > 0)
3201 {
3202 mCaps.maxDepthTextureSamples =
3203 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
3204 }
3205 else if (formatInfo.redBits > 0)
3206 {
3207 mCaps.maxColorTextureSamples =
3208 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
3209 }
3210 }
3211 }
3212 }
Geoff Langd87878e2014-09-19 15:42:59 -04003213
3214 if (formatCaps.texturable && formatInfo.compressed)
3215 {
Geoff Langca271392017-04-05 12:30:00 -04003216 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003217 }
3218
Geoff Langca271392017-04-05 12:30:00 -04003219 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04003220 }
Jamie Madill32447362017-06-28 14:53:52 -04003221
3222 // If program binary is disabled, blank out the memory cache pointer.
Geoff Langb0f917f2017-12-05 13:41:54 -05003223 if (!mSupportedExtensions.getProgramBinary)
Jamie Madill32447362017-06-28 14:53:52 -04003224 {
3225 mMemoryProgramCache = nullptr;
3226 }
Corentin Walleze4477002017-12-01 14:39:58 -05003227
3228 // Compute which buffer types are allowed
3229 mValidBufferBindings.reset();
3230 mValidBufferBindings.set(BufferBinding::ElementArray);
3231 mValidBufferBindings.set(BufferBinding::Array);
3232
3233 if (mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
3234 {
3235 mValidBufferBindings.set(BufferBinding::PixelPack);
3236 mValidBufferBindings.set(BufferBinding::PixelUnpack);
3237 }
3238
3239 if (getClientVersion() >= ES_3_0)
3240 {
3241 mValidBufferBindings.set(BufferBinding::CopyRead);
3242 mValidBufferBindings.set(BufferBinding::CopyWrite);
3243 mValidBufferBindings.set(BufferBinding::TransformFeedback);
3244 mValidBufferBindings.set(BufferBinding::Uniform);
3245 }
3246
3247 if (getClientVersion() >= ES_3_1)
3248 {
3249 mValidBufferBindings.set(BufferBinding::AtomicCounter);
3250 mValidBufferBindings.set(BufferBinding::ShaderStorage);
3251 mValidBufferBindings.set(BufferBinding::DrawIndirect);
3252 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
3253 }
Geoff Lang493daf52014-07-03 13:38:44 -04003254}
3255
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003256void Context::initWorkarounds()
3257{
Jamie Madill761b02c2017-06-23 16:27:06 -04003258 // Apply back-end workarounds.
3259 mImplementation->applyNativeWorkarounds(&mWorkarounds);
3260
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003261 // Lose the context upon out of memory error if the application is
3262 // expecting to watch for those events.
3263 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
3264}
3265
Jamie Madill05b35b22017-10-03 09:01:44 -04003266Error Context::prepareForDraw()
3267{
Geoff Langa8cb2872018-03-09 16:09:40 -05003268 ANGLE_TRY(syncDirtyObjects());
Jamie Madilla59fc192017-11-02 12:57:58 -04003269
3270 if (isRobustResourceInitEnabled())
3271 {
3272 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
3273 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
3274 }
3275
Geoff Langa8cb2872018-03-09 16:09:40 -05003276 ANGLE_TRY(syncDirtyBits());
Geoff Langd4fff502017-09-22 11:28:28 -04003277 return NoError();
3278}
3279
3280Error Context::prepareForClear(GLbitfield mask)
3281{
Geoff Langa8cb2872018-03-09 16:09:40 -05003282 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003283 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearAttachmentsInitialized(this, mask));
Geoff Langa8cb2872018-03-09 16:09:40 -05003284 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04003285 return NoError();
3286}
3287
3288Error Context::prepareForClearBuffer(GLenum buffer, GLint drawbuffer)
3289{
Geoff Langa8cb2872018-03-09 16:09:40 -05003290 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003291 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearBufferAttachmentsInitialized(this, buffer,
3292 drawbuffer));
Geoff Langa8cb2872018-03-09 16:09:40 -05003293 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill05b35b22017-10-03 09:01:44 -04003294 return NoError();
3295}
3296
Geoff Langa8cb2872018-03-09 16:09:40 -05003297Error Context::syncState()
Jamie Madill1b94d432015-08-07 13:23:23 -04003298{
Geoff Langa8cb2872018-03-09 16:09:40 -05003299 ANGLE_TRY(syncDirtyObjects());
3300 ANGLE_TRY(syncDirtyBits());
Jamie Madillbc918e72018-03-08 09:47:21 -05003301 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003302}
3303
Geoff Langa8cb2872018-03-09 16:09:40 -05003304Error Context::syncState(const State::DirtyBits &bitMask, const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04003305{
Geoff Langa8cb2872018-03-09 16:09:40 -05003306 ANGLE_TRY(syncDirtyObjects(objectMask));
3307 ANGLE_TRY(syncDirtyBits(bitMask));
Geoff Langd4fff502017-09-22 11:28:28 -04003308 return NoError();
3309}
3310
Geoff Langa8cb2872018-03-09 16:09:40 -05003311Error Context::syncDirtyBits()
Geoff Langd4fff502017-09-22 11:28:28 -04003312{
3313 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
3314 mImplementation->syncState(this, dirtyBits);
3315 mGLState.clearDirtyBits();
3316 return NoError();
3317}
3318
Geoff Langa8cb2872018-03-09 16:09:40 -05003319Error Context::syncDirtyBits(const State::DirtyBits &bitMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003320{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003321 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madillfe548342017-06-19 11:13:24 -04003322 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003323 mGLState.clearDirtyBits(dirtyBits);
Jamie Madillbc918e72018-03-08 09:47:21 -05003324 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003325}
Jamie Madillc29968b2016-01-20 11:17:23 -05003326
Geoff Langa8cb2872018-03-09 16:09:40 -05003327Error Context::syncDirtyObjects()
Geoff Langd4fff502017-09-22 11:28:28 -04003328{
3329 return mGLState.syncDirtyObjects(this);
3330}
3331
Geoff Langa8cb2872018-03-09 16:09:40 -05003332Error Context::syncDirtyObjects(const State::DirtyObjects &objectMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003333{
3334 return mGLState.syncDirtyObjects(this, objectMask);
3335}
3336
Jamie Madillc29968b2016-01-20 11:17:23 -05003337void Context::blitFramebuffer(GLint srcX0,
3338 GLint srcY0,
3339 GLint srcX1,
3340 GLint srcY1,
3341 GLint dstX0,
3342 GLint dstY0,
3343 GLint dstX1,
3344 GLint dstY1,
3345 GLbitfield mask,
3346 GLenum filter)
3347{
Qin Jiajiaaef92162018-02-27 13:51:44 +08003348 if (mask == 0)
3349 {
3350 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
3351 // buffers are copied.
3352 return;
3353 }
3354
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003355 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003356 ASSERT(drawFramebuffer);
3357
3358 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
3359 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
3360
Jamie Madillbc918e72018-03-08 09:47:21 -05003361 ANGLE_CONTEXT_TRY(syncStateForBlit());
Jamie Madillc29968b2016-01-20 11:17:23 -05003362
Jamie Madillc564c072017-06-01 12:45:42 -04003363 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003364}
Jamie Madillc29968b2016-01-20 11:17:23 -05003365
3366void Context::clear(GLbitfield mask)
3367{
Geoff Langd4fff502017-09-22 11:28:28 -04003368 ANGLE_CONTEXT_TRY(prepareForClear(mask));
3369 ANGLE_CONTEXT_TRY(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05003370}
3371
3372void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
3373{
Geoff Langd4fff502017-09-22 11:28:28 -04003374 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3375 ANGLE_CONTEXT_TRY(
3376 mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003377}
3378
3379void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3380{
Geoff Langd4fff502017-09-22 11:28:28 -04003381 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3382 ANGLE_CONTEXT_TRY(
3383 mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003384}
3385
3386void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3387{
Geoff Langd4fff502017-09-22 11:28:28 -04003388 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3389 ANGLE_CONTEXT_TRY(
3390 mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003391}
3392
3393void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3394{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003395 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003396 ASSERT(framebufferObject);
3397
3398 // If a buffer is not present, the clear has no effect
3399 if (framebufferObject->getDepthbuffer() == nullptr &&
3400 framebufferObject->getStencilbuffer() == nullptr)
3401 {
3402 return;
3403 }
3404
Geoff Langd4fff502017-09-22 11:28:28 -04003405 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3406 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003407}
3408
3409void Context::readPixels(GLint x,
3410 GLint y,
3411 GLsizei width,
3412 GLsizei height,
3413 GLenum format,
3414 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003415 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003416{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003417 if (width == 0 || height == 0)
3418 {
3419 return;
3420 }
3421
Jamie Madillbc918e72018-03-08 09:47:21 -05003422 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003423
Jamie Madillb6664922017-07-25 12:55:04 -04003424 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3425 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003426
3427 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04003428 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003429}
3430
Brandon Jones59770802018-04-02 13:18:42 -07003431void Context::readPixelsRobust(GLint x,
3432 GLint y,
3433 GLsizei width,
3434 GLsizei height,
3435 GLenum format,
3436 GLenum type,
3437 GLsizei bufSize,
3438 GLsizei *length,
3439 GLsizei *columns,
3440 GLsizei *rows,
3441 void *pixels)
3442{
3443 readPixels(x, y, width, height, format, type, pixels);
3444}
3445
3446void Context::readnPixelsRobust(GLint x,
3447 GLint y,
3448 GLsizei width,
3449 GLsizei height,
3450 GLenum format,
3451 GLenum type,
3452 GLsizei bufSize,
3453 GLsizei *length,
3454 GLsizei *columns,
3455 GLsizei *rows,
3456 void *data)
3457{
3458 readPixels(x, y, width, height, format, type, data);
3459}
3460
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003461void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003462 GLint level,
3463 GLenum internalformat,
3464 GLint x,
3465 GLint y,
3466 GLsizei width,
3467 GLsizei height,
3468 GLint border)
3469{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003470 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003471 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003472
Jamie Madillc29968b2016-01-20 11:17:23 -05003473 Rectangle sourceArea(x, y, width, height);
3474
Jamie Madill05b35b22017-10-03 09:01:44 -04003475 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003476 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003477 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003478}
3479
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003480void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003481 GLint level,
3482 GLint xoffset,
3483 GLint yoffset,
3484 GLint x,
3485 GLint y,
3486 GLsizei width,
3487 GLsizei height)
3488{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003489 if (width == 0 || height == 0)
3490 {
3491 return;
3492 }
3493
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003494 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003495 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003496
Jamie Madillc29968b2016-01-20 11:17:23 -05003497 Offset destOffset(xoffset, yoffset, 0);
3498 Rectangle sourceArea(x, y, width, height);
3499
Jamie Madill05b35b22017-10-03 09:01:44 -04003500 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003501 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003502 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003503}
3504
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003505void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003506 GLint level,
3507 GLint xoffset,
3508 GLint yoffset,
3509 GLint zoffset,
3510 GLint x,
3511 GLint y,
3512 GLsizei width,
3513 GLsizei height)
3514{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003515 if (width == 0 || height == 0)
3516 {
3517 return;
3518 }
3519
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003520 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003521 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003522
Jamie Madillc29968b2016-01-20 11:17:23 -05003523 Offset destOffset(xoffset, yoffset, zoffset);
3524 Rectangle sourceArea(x, y, width, height);
3525
Jamie Madill05b35b22017-10-03 09:01:44 -04003526 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3527 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003528 handleError(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level, destOffset,
3529 sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003530}
3531
3532void Context::framebufferTexture2D(GLenum target,
3533 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003534 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003535 GLuint texture,
3536 GLint level)
3537{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003538 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003539 ASSERT(framebuffer);
3540
3541 if (texture != 0)
3542 {
3543 Texture *textureObj = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003544 ImageIndex index = ImageIndex::MakeFromTarget(textarget, level);
Jamie Madilla02315b2017-02-23 14:14:47 -05003545 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003546 }
3547 else
3548 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003549 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003550 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003551
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003552 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003553}
3554
3555void Context::framebufferRenderbuffer(GLenum target,
3556 GLenum attachment,
3557 GLenum renderbuffertarget,
3558 GLuint renderbuffer)
3559{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003560 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003561 ASSERT(framebuffer);
3562
3563 if (renderbuffer != 0)
3564 {
3565 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003566
Jamie Madillcc129372018-04-12 09:13:18 -04003567 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003568 renderbufferObject);
3569 }
3570 else
3571 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003572 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003573 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003574
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003575 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003576}
3577
3578void Context::framebufferTextureLayer(GLenum target,
3579 GLenum attachment,
3580 GLuint texture,
3581 GLint level,
3582 GLint layer)
3583{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003584 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003585 ASSERT(framebuffer);
3586
3587 if (texture != 0)
3588 {
3589 Texture *textureObject = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003590 ImageIndex index = ImageIndex::MakeFromType(textureObject->getType(), level, layer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003591 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003592 }
3593 else
3594 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003595 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003596 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003597
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003598 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003599}
3600
Brandon Jones59770802018-04-02 13:18:42 -07003601void Context::framebufferTextureMultiviewLayered(GLenum target,
3602 GLenum attachment,
3603 GLuint texture,
3604 GLint level,
3605 GLint baseViewIndex,
3606 GLsizei numViews)
Martin Radev137032d2017-07-13 10:11:12 +03003607{
Martin Radev82ef7742017-08-08 17:44:58 +03003608 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3609 ASSERT(framebuffer);
3610
3611 if (texture != 0)
3612 {
3613 Texture *textureObj = getTexture(texture);
3614
Martin Radev18b75ba2017-08-15 15:50:40 +03003615 ImageIndex index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
Martin Radev82ef7742017-08-08 17:44:58 +03003616 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3617 numViews, baseViewIndex);
3618 }
3619 else
3620 {
3621 framebuffer->resetAttachment(this, attachment);
3622 }
3623
3624 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003625}
3626
Brandon Jones59770802018-04-02 13:18:42 -07003627void Context::framebufferTextureMultiviewSideBySide(GLenum target,
3628 GLenum attachment,
3629 GLuint texture,
3630 GLint level,
3631 GLsizei numViews,
3632 const GLint *viewportOffsets)
Martin Radev137032d2017-07-13 10:11:12 +03003633{
Martin Radev5dae57b2017-07-14 16:15:55 +03003634 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3635 ASSERT(framebuffer);
3636
3637 if (texture != 0)
3638 {
3639 Texture *textureObj = getTexture(texture);
3640
3641 ImageIndex index = ImageIndex::Make2D(level);
3642 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3643 textureObj, numViews, viewportOffsets);
3644 }
3645 else
3646 {
3647 framebuffer->resetAttachment(this, attachment);
3648 }
3649
3650 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003651}
3652
Jamie Madillc29968b2016-01-20 11:17:23 -05003653void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3654{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003655 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003656 ASSERT(framebuffer);
3657 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003658 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003659}
3660
3661void Context::readBuffer(GLenum mode)
3662{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003663 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003664 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003665 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003666}
3667
3668void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3669{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003670 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003671 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003672
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003673 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003674 ASSERT(framebuffer);
3675
3676 // The specification isn't clear what should be done when the framebuffer isn't complete.
3677 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003678 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003679}
3680
3681void Context::invalidateFramebuffer(GLenum target,
3682 GLsizei numAttachments,
3683 const GLenum *attachments)
3684{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003685 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003686 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003687
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003688 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003689 ASSERT(framebuffer);
3690
Jamie Madill427064d2018-04-13 16:20:34 -04003691 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003692 {
Jamie Madill437fa652016-05-03 15:13:24 -04003693 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003694 }
Jamie Madill437fa652016-05-03 15:13:24 -04003695
Jamie Madill4928b7c2017-06-20 12:57:39 -04003696 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003697}
3698
3699void Context::invalidateSubFramebuffer(GLenum target,
3700 GLsizei numAttachments,
3701 const GLenum *attachments,
3702 GLint x,
3703 GLint y,
3704 GLsizei width,
3705 GLsizei height)
3706{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003707 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003708 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003709
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003710 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003711 ASSERT(framebuffer);
3712
Jamie Madill427064d2018-04-13 16:20:34 -04003713 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003714 {
Jamie Madill437fa652016-05-03 15:13:24 -04003715 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003716 }
Jamie Madill437fa652016-05-03 15:13:24 -04003717
3718 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003719 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003720}
3721
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003722void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003723 GLint level,
3724 GLint internalformat,
3725 GLsizei width,
3726 GLsizei height,
3727 GLint border,
3728 GLenum format,
3729 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003730 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003731{
Jamie Madillbc918e72018-03-08 09:47:21 -05003732 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003733
3734 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003735 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003736 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3737 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003738}
3739
Brandon Jones59770802018-04-02 13:18:42 -07003740void Context::texImage2DRobust(TextureTarget target,
3741 GLint level,
3742 GLint internalformat,
3743 GLsizei width,
3744 GLsizei height,
3745 GLint border,
3746 GLenum format,
3747 GLenum type,
3748 GLsizei bufSize,
3749 const void *pixels)
3750{
3751 texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
3752}
3753
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003754void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003755 GLint level,
3756 GLint internalformat,
3757 GLsizei width,
3758 GLsizei height,
3759 GLsizei depth,
3760 GLint border,
3761 GLenum format,
3762 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003763 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003764{
Jamie Madillbc918e72018-03-08 09:47:21 -05003765 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003766
3767 Extents size(width, height, depth);
3768 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003769 handleError(texture->setImage(this, mGLState.getUnpackState(),
3770 NonCubeTextureTypeToTarget(target), level, internalformat, size,
3771 format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003772}
3773
Brandon Jones59770802018-04-02 13:18:42 -07003774void Context::texImage3DRobust(TextureType target,
3775 GLint level,
3776 GLint internalformat,
3777 GLsizei width,
3778 GLsizei height,
3779 GLsizei depth,
3780 GLint border,
3781 GLenum format,
3782 GLenum type,
3783 GLsizei bufSize,
3784 const void *pixels)
3785{
3786 texImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels);
3787}
3788
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003789void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003790 GLint level,
3791 GLint xoffset,
3792 GLint yoffset,
3793 GLsizei width,
3794 GLsizei height,
3795 GLenum format,
3796 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003797 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003798{
3799 // Zero sized uploads are valid but no-ops
3800 if (width == 0 || height == 0)
3801 {
3802 return;
3803 }
3804
Jamie Madillbc918e72018-03-08 09:47:21 -05003805 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003806
3807 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003808 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003809 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3810 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003811}
3812
Brandon Jones59770802018-04-02 13:18:42 -07003813void Context::texSubImage2DRobust(TextureTarget target,
3814 GLint level,
3815 GLint xoffset,
3816 GLint yoffset,
3817 GLsizei width,
3818 GLsizei height,
3819 GLenum format,
3820 GLenum type,
3821 GLsizei bufSize,
3822 const void *pixels)
3823{
3824 texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
3825}
3826
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003827void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003828 GLint level,
3829 GLint xoffset,
3830 GLint yoffset,
3831 GLint zoffset,
3832 GLsizei width,
3833 GLsizei height,
3834 GLsizei depth,
3835 GLenum format,
3836 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003837 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003838{
3839 // Zero sized uploads are valid but no-ops
3840 if (width == 0 || height == 0 || depth == 0)
3841 {
3842 return;
3843 }
3844
Jamie Madillbc918e72018-03-08 09:47:21 -05003845 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003846
3847 Box area(xoffset, yoffset, zoffset, width, height, depth);
3848 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003849 handleError(texture->setSubImage(this, mGLState.getUnpackState(),
3850 NonCubeTextureTypeToTarget(target), level, area, format, type,
3851 reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003852}
3853
Brandon Jones59770802018-04-02 13:18:42 -07003854void Context::texSubImage3DRobust(TextureType target,
3855 GLint level,
3856 GLint xoffset,
3857 GLint yoffset,
3858 GLint zoffset,
3859 GLsizei width,
3860 GLsizei height,
3861 GLsizei depth,
3862 GLenum format,
3863 GLenum type,
3864 GLsizei bufSize,
3865 const void *pixels)
3866{
3867 texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type,
3868 pixels);
3869}
3870
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003871void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003872 GLint level,
3873 GLenum internalformat,
3874 GLsizei width,
3875 GLsizei height,
3876 GLint border,
3877 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003878 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003879{
Jamie Madillbc918e72018-03-08 09:47:21 -05003880 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003881
3882 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003883 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003884 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
3885 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003886 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003887}
3888
Brandon Jones59770802018-04-02 13:18:42 -07003889void Context::compressedTexImage2DRobust(TextureTarget target,
3890 GLint level,
3891 GLenum internalformat,
3892 GLsizei width,
3893 GLsizei height,
3894 GLint border,
3895 GLsizei imageSize,
3896 GLsizei dataSize,
3897 const GLvoid *data)
3898{
3899 compressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
3900}
3901
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003902void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003903 GLint level,
3904 GLenum internalformat,
3905 GLsizei width,
3906 GLsizei height,
3907 GLsizei depth,
3908 GLint border,
3909 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003910 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003911{
Jamie Madillbc918e72018-03-08 09:47:21 -05003912 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003913
3914 Extents size(width, height, depth);
3915 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003916 handleError(texture->setCompressedImage(
3917 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
3918 size, imageSize, reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003919}
3920
Brandon Jones59770802018-04-02 13:18:42 -07003921void Context::compressedTexImage3DRobust(TextureType target,
3922 GLint level,
3923 GLenum internalformat,
3924 GLsizei width,
3925 GLsizei height,
3926 GLsizei depth,
3927 GLint border,
3928 GLsizei imageSize,
3929 GLsizei dataSize,
3930 const GLvoid *data)
3931{
3932 compressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize,
3933 data);
3934}
3935
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003936void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003937 GLint level,
3938 GLint xoffset,
3939 GLint yoffset,
3940 GLsizei width,
3941 GLsizei height,
3942 GLenum format,
3943 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003944 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003945{
Jamie Madillbc918e72018-03-08 09:47:21 -05003946 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003947
3948 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003949 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003950 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
3951 format, imageSize,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003952 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003953}
3954
Brandon Jones59770802018-04-02 13:18:42 -07003955void Context::compressedTexSubImage2DRobust(TextureTarget target,
3956 GLint level,
3957 GLint xoffset,
3958 GLint yoffset,
3959 GLsizei width,
3960 GLsizei height,
3961 GLenum format,
3962 GLsizei imageSize,
3963 GLsizei dataSize,
3964 const GLvoid *data)
3965{
3966 compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize,
3967 data);
3968}
3969
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003970void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003971 GLint level,
3972 GLint xoffset,
3973 GLint yoffset,
3974 GLint zoffset,
3975 GLsizei width,
3976 GLsizei height,
3977 GLsizei depth,
3978 GLenum format,
3979 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003980 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003981{
3982 // Zero sized uploads are valid but no-ops
3983 if (width == 0 || height == 0)
3984 {
3985 return;
3986 }
3987
Jamie Madillbc918e72018-03-08 09:47:21 -05003988 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003989
3990 Box area(xoffset, yoffset, zoffset, width, height, depth);
3991 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003992 handleError(texture->setCompressedSubImage(
3993 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
3994 imageSize, reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003995}
3996
Brandon Jones59770802018-04-02 13:18:42 -07003997void Context::compressedTexSubImage3DRobust(TextureType target,
3998 GLint level,
3999 GLint xoffset,
4000 GLint yoffset,
4001 GLint zoffset,
4002 GLsizei width,
4003 GLsizei height,
4004 GLsizei depth,
4005 GLenum format,
4006 GLsizei imageSize,
4007 GLsizei dataSize,
4008 const GLvoid *data)
4009{
4010 compressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format,
4011 imageSize, data);
4012}
4013
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004014void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004015{
4016 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05004017 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004018}
4019
Jamie Madill007530e2017-12-28 14:27:04 -05004020void Context::copyTexture(GLuint sourceId,
4021 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004022 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004023 GLuint destId,
4024 GLint destLevel,
4025 GLint internalFormat,
4026 GLenum destType,
4027 GLboolean unpackFlipY,
4028 GLboolean unpackPremultiplyAlpha,
4029 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004030{
Jamie Madillbc918e72018-03-08 09:47:21 -05004031 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004032
4033 gl::Texture *sourceTexture = getTexture(sourceId);
4034 gl::Texture *destTexture = getTexture(destId);
Geoff Lang92019432017-11-20 13:09:34 -05004035 handleError(destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType,
4036 sourceLevel, ConvertToBool(unpackFlipY),
4037 ConvertToBool(unpackPremultiplyAlpha),
4038 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004039}
4040
Jamie Madill007530e2017-12-28 14:27:04 -05004041void Context::copySubTexture(GLuint sourceId,
4042 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004043 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004044 GLuint destId,
4045 GLint destLevel,
4046 GLint xoffset,
4047 GLint yoffset,
4048 GLint x,
4049 GLint y,
4050 GLsizei width,
4051 GLsizei height,
4052 GLboolean unpackFlipY,
4053 GLboolean unpackPremultiplyAlpha,
4054 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004055{
4056 // Zero sized copies are valid but no-ops
4057 if (width == 0 || height == 0)
4058 {
4059 return;
4060 }
4061
Jamie Madillbc918e72018-03-08 09:47:21 -05004062 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004063
4064 gl::Texture *sourceTexture = getTexture(sourceId);
4065 gl::Texture *destTexture = getTexture(destId);
4066 Offset offset(xoffset, yoffset, 0);
4067 Rectangle area(x, y, width, height);
Geoff Lang92019432017-11-20 13:09:34 -05004068 handleError(destTexture->copySubTexture(this, destTarget, destLevel, offset, sourceLevel, area,
4069 ConvertToBool(unpackFlipY),
4070 ConvertToBool(unpackPremultiplyAlpha),
4071 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004072}
4073
Jamie Madill007530e2017-12-28 14:27:04 -05004074void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07004075{
Jamie Madillbc918e72018-03-08 09:47:21 -05004076 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07004077
4078 gl::Texture *sourceTexture = getTexture(sourceId);
4079 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05004080 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07004081}
4082
Corentin Wallez336129f2017-10-17 15:55:40 -04004083void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03004084{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004085 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004086 ASSERT(buffer);
4087
Geoff Lang496c02d2016-10-20 11:38:11 -07004088 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03004089}
4090
Brandon Jones59770802018-04-02 13:18:42 -07004091void Context::getBufferPointervRobust(BufferBinding target,
4092 GLenum pname,
4093 GLsizei bufSize,
4094 GLsizei *length,
4095 void **params)
4096{
4097 getBufferPointerv(target, pname, params);
4098}
4099
Corentin Wallez336129f2017-10-17 15:55:40 -04004100void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004101{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004102 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004103 ASSERT(buffer);
4104
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004105 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004106 if (error.isError())
4107 {
Jamie Madill437fa652016-05-03 15:13:24 -04004108 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004109 return nullptr;
4110 }
4111
4112 return buffer->getMapPointer();
4113}
4114
Corentin Wallez336129f2017-10-17 15:55:40 -04004115GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03004116{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004117 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004118 ASSERT(buffer);
4119
4120 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004121 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03004122 if (error.isError())
4123 {
Jamie Madill437fa652016-05-03 15:13:24 -04004124 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004125 return GL_FALSE;
4126 }
4127
4128 return result;
4129}
4130
Corentin Wallez336129f2017-10-17 15:55:40 -04004131void *Context::mapBufferRange(BufferBinding target,
4132 GLintptr offset,
4133 GLsizeiptr length,
4134 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004135{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004136 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004137 ASSERT(buffer);
4138
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004139 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004140 if (error.isError())
4141 {
Jamie Madill437fa652016-05-03 15:13:24 -04004142 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004143 return nullptr;
4144 }
4145
4146 return buffer->getMapPointer();
4147}
4148
Corentin Wallez336129f2017-10-17 15:55:40 -04004149void Context::flushMappedBufferRange(BufferBinding /*target*/,
4150 GLintptr /*offset*/,
4151 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03004152{
4153 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
4154}
4155
Jamie Madillbc918e72018-03-08 09:47:21 -05004156Error Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004157{
Geoff Langa8cb2872018-03-09 16:09:40 -05004158 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004159}
4160
Jamie Madillbc918e72018-03-08 09:47:21 -05004161Error Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004162{
Geoff Langa8cb2872018-03-09 16:09:40 -05004163 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004164}
4165
Jamie Madillbc918e72018-03-08 09:47:21 -05004166Error Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004167{
Geoff Langa8cb2872018-03-09 16:09:40 -05004168 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004169}
4170
Jiajia Qin5451d532017-11-16 17:16:34 +08004171void Context::activeShaderProgram(GLuint pipeline, GLuint program)
4172{
4173 UNIMPLEMENTED();
4174}
4175
Jamie Madillc20ab272016-06-09 07:20:46 -07004176void Context::activeTexture(GLenum texture)
4177{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004178 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004179}
4180
Jamie Madill876429b2017-04-20 15:46:24 -04004181void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004182{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004183 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004184}
4185
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004186void Context::blendEquation(GLenum mode)
4187{
4188 mGLState.setBlendEquation(mode, mode);
4189}
4190
Jamie Madillc20ab272016-06-09 07:20:46 -07004191void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
4192{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004193 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004194}
4195
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004196void Context::blendFunc(GLenum sfactor, GLenum dfactor)
4197{
4198 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
4199}
4200
Jamie Madillc20ab272016-06-09 07:20:46 -07004201void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
4202{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004203 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004204}
4205
Jamie Madill876429b2017-04-20 15:46:24 -04004206void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004207{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004208 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004209}
4210
Jamie Madill876429b2017-04-20 15:46:24 -04004211void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07004212{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004213 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07004214}
4215
4216void Context::clearStencil(GLint s)
4217{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004218 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07004219}
4220
4221void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
4222{
Geoff Lang92019432017-11-20 13:09:34 -05004223 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
4224 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004225}
4226
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004227void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07004228{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004229 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004230}
4231
4232void Context::depthFunc(GLenum func)
4233{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004234 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07004235}
4236
4237void Context::depthMask(GLboolean flag)
4238{
Geoff Lang92019432017-11-20 13:09:34 -05004239 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07004240}
4241
Jamie Madill876429b2017-04-20 15:46:24 -04004242void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07004243{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004244 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07004245}
4246
4247void Context::disable(GLenum cap)
4248{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004249 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07004250}
4251
4252void Context::disableVertexAttribArray(GLuint index)
4253{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004254 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07004255}
4256
4257void Context::enable(GLenum cap)
4258{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004259 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07004260}
4261
4262void Context::enableVertexAttribArray(GLuint index)
4263{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004264 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07004265}
4266
4267void Context::frontFace(GLenum mode)
4268{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004269 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004270}
4271
4272void Context::hint(GLenum target, GLenum mode)
4273{
4274 switch (target)
4275 {
4276 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004277 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004278 break;
4279
4280 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004281 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004282 break;
4283
4284 default:
4285 UNREACHABLE();
4286 return;
4287 }
4288}
4289
4290void Context::lineWidth(GLfloat width)
4291{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004292 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07004293}
4294
4295void Context::pixelStorei(GLenum pname, GLint param)
4296{
4297 switch (pname)
4298 {
4299 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004300 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004301 break;
4302
4303 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004304 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004305 break;
4306
4307 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004308 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004309 break;
4310
4311 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004312 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004313 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004314 break;
4315
4316 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03004317 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004318 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004319 break;
4320
4321 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03004322 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004323 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004324 break;
4325
4326 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004327 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004328 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004329 break;
4330
4331 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004332 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004333 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004334 break;
4335
4336 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004337 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004338 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004339 break;
4340
4341 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004342 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004343 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004344 break;
4345
4346 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004347 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004348 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004349 break;
4350
4351 default:
4352 UNREACHABLE();
4353 return;
4354 }
4355}
4356
4357void Context::polygonOffset(GLfloat factor, GLfloat units)
4358{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004359 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07004360}
4361
Jamie Madill876429b2017-04-20 15:46:24 -04004362void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07004363{
Geoff Lang92019432017-11-20 13:09:34 -05004364 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07004365}
4366
Jiawei Shaodb342272017-09-27 10:21:45 +08004367void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
4368{
4369 mGLState.setSampleMaskParams(maskNumber, mask);
4370}
4371
Jamie Madillc20ab272016-06-09 07:20:46 -07004372void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
4373{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004374 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004375}
4376
4377void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
4378{
4379 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4380 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004381 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004382 }
4383
4384 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4385 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004386 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004387 }
4388}
4389
4390void Context::stencilMaskSeparate(GLenum face, GLuint mask)
4391{
4392 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4393 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004394 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004395 }
4396
4397 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4398 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004399 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004400 }
4401}
4402
4403void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4404{
4405 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4406 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004407 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004408 }
4409
4410 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4411 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004412 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004413 }
4414}
4415
4416void Context::vertexAttrib1f(GLuint index, GLfloat x)
4417{
4418 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004419 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004420}
4421
4422void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
4423{
4424 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004425 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004426}
4427
4428void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4429{
4430 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004431 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004432}
4433
4434void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
4435{
4436 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004437 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004438}
4439
4440void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4441{
4442 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004443 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004444}
4445
4446void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
4447{
4448 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004449 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004450}
4451
4452void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4453{
4454 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004455 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004456}
4457
4458void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
4459{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004460 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07004461}
4462
4463void Context::vertexAttribPointer(GLuint index,
4464 GLint size,
4465 GLenum type,
4466 GLboolean normalized,
4467 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004468 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07004469{
Corentin Wallez336129f2017-10-17 15:55:40 -04004470 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05004471 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc20ab272016-06-09 07:20:46 -07004472}
4473
Shao80957d92017-02-20 21:25:59 +08004474void Context::vertexAttribFormat(GLuint attribIndex,
4475 GLint size,
4476 GLenum type,
4477 GLboolean normalized,
4478 GLuint relativeOffset)
4479{
Geoff Lang92019432017-11-20 13:09:34 -05004480 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08004481 relativeOffset);
4482}
4483
4484void Context::vertexAttribIFormat(GLuint attribIndex,
4485 GLint size,
4486 GLenum type,
4487 GLuint relativeOffset)
4488{
4489 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
4490}
4491
4492void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4493{
Shaodde78e82017-05-22 14:13:27 +08004494 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Shao80957d92017-02-20 21:25:59 +08004495}
4496
Jiajia Qin5451d532017-11-16 17:16:34 +08004497void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004498{
4499 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
4500}
4501
Jamie Madillc20ab272016-06-09 07:20:46 -07004502void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4503{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004504 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004505}
4506
4507void Context::vertexAttribIPointer(GLuint index,
4508 GLint size,
4509 GLenum type,
4510 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004511 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004512{
Corentin Wallez336129f2017-10-17 15:55:40 -04004513 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
4514 size, type, false, true, stride, pointer);
Jamie Madillc20ab272016-06-09 07:20:46 -07004515}
4516
4517void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4518{
4519 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004520 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004521}
4522
4523void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4524{
4525 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004526 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004527}
4528
4529void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4530{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004531 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004532}
4533
4534void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4535{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004536 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004537}
4538
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004539void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4540{
4541 const VertexAttribCurrentValueData &currentValues =
4542 getGLState().getVertexAttribCurrentValue(index);
4543 const VertexArray *vao = getGLState().getVertexArray();
4544 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4545 currentValues, pname, params);
4546}
4547
Brandon Jones59770802018-04-02 13:18:42 -07004548void Context::getVertexAttribivRobust(GLuint index,
4549 GLenum pname,
4550 GLsizei bufSize,
4551 GLsizei *length,
4552 GLint *params)
4553{
4554 getVertexAttribiv(index, pname, params);
4555}
4556
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004557void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4558{
4559 const VertexAttribCurrentValueData &currentValues =
4560 getGLState().getVertexAttribCurrentValue(index);
4561 const VertexArray *vao = getGLState().getVertexArray();
4562 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4563 currentValues, pname, params);
4564}
4565
Brandon Jones59770802018-04-02 13:18:42 -07004566void Context::getVertexAttribfvRobust(GLuint index,
4567 GLenum pname,
4568 GLsizei bufSize,
4569 GLsizei *length,
4570 GLfloat *params)
4571{
4572 getVertexAttribfv(index, pname, params);
4573}
4574
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004575void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4576{
4577 const VertexAttribCurrentValueData &currentValues =
4578 getGLState().getVertexAttribCurrentValue(index);
4579 const VertexArray *vao = getGLState().getVertexArray();
4580 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4581 currentValues, pname, params);
4582}
4583
Brandon Jones59770802018-04-02 13:18:42 -07004584void Context::getVertexAttribIivRobust(GLuint index,
4585 GLenum pname,
4586 GLsizei bufSize,
4587 GLsizei *length,
4588 GLint *params)
4589{
4590 getVertexAttribIiv(index, pname, params);
4591}
4592
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004593void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4594{
4595 const VertexAttribCurrentValueData &currentValues =
4596 getGLState().getVertexAttribCurrentValue(index);
4597 const VertexArray *vao = getGLState().getVertexArray();
4598 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4599 currentValues, pname, params);
4600}
4601
Brandon Jones59770802018-04-02 13:18:42 -07004602void Context::getVertexAttribIuivRobust(GLuint index,
4603 GLenum pname,
4604 GLsizei bufSize,
4605 GLsizei *length,
4606 GLuint *params)
4607{
4608 getVertexAttribIuiv(index, pname, params);
4609}
4610
Jamie Madill876429b2017-04-20 15:46:24 -04004611void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004612{
4613 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
4614 QueryVertexAttribPointerv(attrib, pname, pointer);
4615}
4616
Brandon Jones59770802018-04-02 13:18:42 -07004617void Context::getVertexAttribPointervRobust(GLuint index,
4618 GLenum pname,
4619 GLsizei bufSize,
4620 GLsizei *length,
4621 void **pointer)
4622{
4623 getVertexAttribPointerv(index, pname, pointer);
4624}
4625
Jamie Madillc20ab272016-06-09 07:20:46 -07004626void Context::debugMessageControl(GLenum source,
4627 GLenum type,
4628 GLenum severity,
4629 GLsizei count,
4630 const GLuint *ids,
4631 GLboolean enabled)
4632{
4633 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004634 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05004635 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004636}
4637
4638void Context::debugMessageInsert(GLenum source,
4639 GLenum type,
4640 GLuint id,
4641 GLenum severity,
4642 GLsizei length,
4643 const GLchar *buf)
4644{
4645 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004646 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004647}
4648
4649void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4650{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004651 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004652}
4653
4654GLuint Context::getDebugMessageLog(GLuint count,
4655 GLsizei bufSize,
4656 GLenum *sources,
4657 GLenum *types,
4658 GLuint *ids,
4659 GLenum *severities,
4660 GLsizei *lengths,
4661 GLchar *messageLog)
4662{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004663 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4664 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004665}
4666
4667void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4668{
4669 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004670 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05004671 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07004672}
4673
4674void Context::popDebugGroup()
4675{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004676 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05004677 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004678}
4679
Corentin Wallez336129f2017-10-17 15:55:40 -04004680void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004681{
4682 Buffer *buffer = mGLState.getTargetBuffer(target);
4683 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004684 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004685}
4686
Corentin Wallez336129f2017-10-17 15:55:40 -04004687void Context::bufferSubData(BufferBinding target,
4688 GLintptr offset,
4689 GLsizeiptr size,
4690 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004691{
4692 if (data == nullptr)
4693 {
4694 return;
4695 }
4696
4697 Buffer *buffer = mGLState.getTargetBuffer(target);
4698 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004699 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004700}
4701
Jamie Madillef300b12016-10-07 15:12:09 -04004702void Context::attachShader(GLuint program, GLuint shader)
4703{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05004704 Program *programObject = mState.mShaderPrograms->getProgram(program);
4705 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004706 ASSERT(programObject && shaderObject);
4707 programObject->attachShader(shaderObject);
4708}
4709
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004710const Workarounds &Context::getWorkarounds() const
4711{
4712 return mWorkarounds;
4713}
4714
Corentin Wallez336129f2017-10-17 15:55:40 -04004715void Context::copyBufferSubData(BufferBinding readTarget,
4716 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04004717 GLintptr readOffset,
4718 GLintptr writeOffset,
4719 GLsizeiptr size)
4720{
4721 // if size is zero, the copy is a successful no-op
4722 if (size == 0)
4723 {
4724 return;
4725 }
4726
4727 // TODO(jmadill): cache these.
4728 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4729 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4730
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004731 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004732}
4733
Jamie Madill01a80ee2016-11-07 12:06:18 -05004734void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4735{
4736 Program *programObject = getProgram(program);
4737 // TODO(jmadill): Re-use this from the validation if possible.
4738 ASSERT(programObject);
4739 programObject->bindAttributeLocation(index, name);
4740}
4741
Corentin Wallez336129f2017-10-17 15:55:40 -04004742void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004743{
Corentin Wallez336129f2017-10-17 15:55:40 -04004744 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4745 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004746}
4747
Corentin Wallez336129f2017-10-17 15:55:40 -04004748void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08004749{
4750 bindBufferRange(target, index, buffer, 0, 0);
4751}
4752
Corentin Wallez336129f2017-10-17 15:55:40 -04004753void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08004754 GLuint index,
4755 GLuint buffer,
4756 GLintptr offset,
4757 GLsizeiptr size)
4758{
Corentin Wallez336129f2017-10-17 15:55:40 -04004759 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4760 mGLState.setIndexedBufferBinding(this, target, index, bufferObject, offset, size);
Jiajia Qin6eafb042016-12-27 17:04:07 +08004761}
4762
Jamie Madill01a80ee2016-11-07 12:06:18 -05004763void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
4764{
4765 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4766 {
4767 bindReadFramebuffer(framebuffer);
4768 }
4769
4770 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4771 {
4772 bindDrawFramebuffer(framebuffer);
4773 }
4774}
4775
4776void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4777{
4778 ASSERT(target == GL_RENDERBUFFER);
4779 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004780 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04004781 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004782}
4783
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004784void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08004785 GLsizei samples,
4786 GLenum internalformat,
4787 GLsizei width,
4788 GLsizei height,
4789 GLboolean fixedsamplelocations)
4790{
4791 Extents size(width, height, 1);
4792 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004793 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
4794 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004795}
4796
4797void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4798{
JiangYizhou5b03f472017-01-09 10:22:53 +08004799 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
4800 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillbc918e72018-03-08 09:47:21 -05004801 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
JiangYizhou5b03f472017-01-09 10:22:53 +08004802 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08004803
4804 switch (pname)
4805 {
4806 case GL_SAMPLE_POSITION:
4807 handleError(framebuffer->getSamplePosition(index, val));
4808 break;
4809 default:
4810 UNREACHABLE();
4811 }
4812}
4813
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07004814void Context::getMultisamplefvRobust(GLenum pname,
4815 GLuint index,
4816 GLsizei bufSize,
4817 GLsizei *length,
4818 GLfloat *val)
4819{
4820 UNIMPLEMENTED();
4821}
4822
Jamie Madille8fb6402017-02-14 17:56:40 -05004823void Context::renderbufferStorage(GLenum target,
4824 GLenum internalformat,
4825 GLsizei width,
4826 GLsizei height)
4827{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004828 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4829 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
4830
Jamie Madille8fb6402017-02-14 17:56:40 -05004831 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04004832 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004833}
4834
4835void Context::renderbufferStorageMultisample(GLenum target,
4836 GLsizei samples,
4837 GLenum internalformat,
4838 GLsizei width,
4839 GLsizei height)
4840{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004841 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4842 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05004843
4844 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004845 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04004846 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004847}
4848
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004849void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
4850{
Jamie Madill70b5bb02017-08-28 13:32:37 -04004851 const Sync *syncObject = getSync(sync);
Geoff Lang82483b92017-04-11 15:33:00 -04004852 handleError(QuerySynciv(syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004853}
4854
JiangYizhoue18e6392017-02-20 10:32:23 +08004855void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
4856{
4857 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4858 QueryFramebufferParameteriv(framebuffer, pname, params);
4859}
4860
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07004861void Context::getFramebufferParameterivRobust(GLenum target,
4862 GLenum pname,
4863 GLsizei bufSize,
4864 GLsizei *length,
4865 GLint *params)
4866{
4867 UNIMPLEMENTED();
4868}
4869
Jiajia Qin5451d532017-11-16 17:16:34 +08004870void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08004871{
4872 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4873 SetFramebufferParameteri(framebuffer, pname, param);
4874}
4875
Jamie Madillb3f26b92017-07-19 15:07:41 -04004876Error Context::getScratchBuffer(size_t requstedSizeBytes,
4877 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05004878{
Jamie Madillb3f26b92017-07-19 15:07:41 -04004879 if (!mScratchBuffer.get(requstedSizeBytes, scratchBufferOut))
4880 {
4881 return OutOfMemory() << "Failed to allocate internal buffer.";
4882 }
4883 return NoError();
4884}
4885
4886Error Context::getZeroFilledBuffer(size_t requstedSizeBytes,
4887 angle::MemoryBuffer **zeroBufferOut) const
4888{
4889 if (!mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0))
Jamie Madille14951e2017-03-09 18:55:16 -05004890 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004891 return OutOfMemory() << "Failed to allocate internal buffer.";
Jamie Madille14951e2017-03-09 18:55:16 -05004892 }
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004893 return NoError();
Jamie Madille14951e2017-03-09 18:55:16 -05004894}
4895
Xinghua Cao10a4d432017-11-28 14:46:26 +08004896Error Context::prepareForDispatch()
4897{
Geoff Langa8cb2872018-03-09 16:09:40 -05004898 ANGLE_TRY(syncState(mComputeDirtyBits, mComputeDirtyObjects));
Xinghua Cao10a4d432017-11-28 14:46:26 +08004899
4900 if (isRobustResourceInitEnabled())
4901 {
4902 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
4903 }
4904
4905 return NoError();
4906}
4907
Xinghua Cao2b396592017-03-29 15:36:04 +08004908void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
4909{
4910 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
4911 {
4912 return;
4913 }
4914
Xinghua Cao10a4d432017-11-28 14:46:26 +08004915 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill71c88b32017-09-14 22:20:29 -04004916 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08004917}
4918
Jiajia Qin5451d532017-11-16 17:16:34 +08004919void Context::dispatchComputeIndirect(GLintptr indirect)
4920{
Qin Jiajia62fcf622017-11-30 16:16:12 +08004921 ANGLE_CONTEXT_TRY(prepareForDispatch());
4922 handleError(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08004923}
4924
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004925void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08004926 GLsizei levels,
4927 GLenum internalFormat,
4928 GLsizei width,
4929 GLsizei height)
4930{
4931 Extents size(width, height, 1);
4932 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004933 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08004934}
4935
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004936void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08004937 GLsizei levels,
4938 GLenum internalFormat,
4939 GLsizei width,
4940 GLsizei height,
4941 GLsizei depth)
4942{
4943 Extents size(width, height, depth);
4944 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004945 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08004946}
4947
Jiajia Qin5451d532017-11-16 17:16:34 +08004948void Context::memoryBarrier(GLbitfield barriers)
4949{
Xinghua Cao89c422a2017-11-29 18:24:20 +08004950 handleError(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08004951}
4952
4953void Context::memoryBarrierByRegion(GLbitfield barriers)
4954{
Xinghua Cao89c422a2017-11-29 18:24:20 +08004955 handleError(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08004956}
4957
Jamie Madillc1d770e2017-04-13 17:31:24 -04004958GLenum Context::checkFramebufferStatus(GLenum target)
4959{
4960 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4961 ASSERT(framebuffer);
Jamie Madill427064d2018-04-13 16:20:34 -04004962 return framebuffer->checkStatus(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004963}
4964
4965void Context::compileShader(GLuint shader)
4966{
4967 Shader *shaderObject = GetValidShader(this, shader);
4968 if (!shaderObject)
4969 {
4970 return;
4971 }
4972 shaderObject->compile(this);
4973}
4974
4975void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
4976{
4977 for (int i = 0; i < n; i++)
4978 {
4979 deleteBuffer(buffers[i]);
4980 }
4981}
4982
4983void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
4984{
4985 for (int i = 0; i < n; i++)
4986 {
4987 if (framebuffers[i] != 0)
4988 {
4989 deleteFramebuffer(framebuffers[i]);
4990 }
4991 }
4992}
4993
4994void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
4995{
4996 for (int i = 0; i < n; i++)
4997 {
4998 deleteRenderbuffer(renderbuffers[i]);
4999 }
5000}
5001
5002void Context::deleteTextures(GLsizei n, const GLuint *textures)
5003{
5004 for (int i = 0; i < n; i++)
5005 {
5006 if (textures[i] != 0)
5007 {
5008 deleteTexture(textures[i]);
5009 }
5010 }
5011}
5012
5013void Context::detachShader(GLuint program, GLuint shader)
5014{
5015 Program *programObject = getProgram(program);
5016 ASSERT(programObject);
5017
5018 Shader *shaderObject = getShader(shader);
5019 ASSERT(shaderObject);
5020
5021 programObject->detachShader(this, shaderObject);
5022}
5023
5024void Context::genBuffers(GLsizei n, GLuint *buffers)
5025{
5026 for (int i = 0; i < n; i++)
5027 {
5028 buffers[i] = createBuffer();
5029 }
5030}
5031
5032void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
5033{
5034 for (int i = 0; i < n; i++)
5035 {
5036 framebuffers[i] = createFramebuffer();
5037 }
5038}
5039
5040void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
5041{
5042 for (int i = 0; i < n; i++)
5043 {
5044 renderbuffers[i] = createRenderbuffer();
5045 }
5046}
5047
5048void Context::genTextures(GLsizei n, GLuint *textures)
5049{
5050 for (int i = 0; i < n; i++)
5051 {
5052 textures[i] = createTexture();
5053 }
5054}
5055
5056void Context::getActiveAttrib(GLuint program,
5057 GLuint index,
5058 GLsizei bufsize,
5059 GLsizei *length,
5060 GLint *size,
5061 GLenum *type,
5062 GLchar *name)
5063{
5064 Program *programObject = getProgram(program);
5065 ASSERT(programObject);
5066 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
5067}
5068
5069void Context::getActiveUniform(GLuint program,
5070 GLuint index,
5071 GLsizei bufsize,
5072 GLsizei *length,
5073 GLint *size,
5074 GLenum *type,
5075 GLchar *name)
5076{
5077 Program *programObject = getProgram(program);
5078 ASSERT(programObject);
5079 programObject->getActiveUniform(index, bufsize, length, size, type, name);
5080}
5081
5082void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
5083{
5084 Program *programObject = getProgram(program);
5085 ASSERT(programObject);
5086 programObject->getAttachedShaders(maxcount, count, shaders);
5087}
5088
5089GLint Context::getAttribLocation(GLuint program, const GLchar *name)
5090{
5091 Program *programObject = getProgram(program);
5092 ASSERT(programObject);
5093 return programObject->getAttributeLocation(name);
5094}
5095
5096void Context::getBooleanv(GLenum pname, GLboolean *params)
5097{
5098 GLenum nativeType;
5099 unsigned int numParams = 0;
5100 getQueryParameterInfo(pname, &nativeType, &numParams);
5101
5102 if (nativeType == GL_BOOL)
5103 {
5104 getBooleanvImpl(pname, params);
5105 }
5106 else
5107 {
5108 CastStateValues(this, nativeType, pname, numParams, params);
5109 }
5110}
5111
Brandon Jones59770802018-04-02 13:18:42 -07005112void Context::getBooleanvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLboolean *params)
5113{
5114 getBooleanv(pname, params);
5115}
5116
Jamie Madillc1d770e2017-04-13 17:31:24 -04005117void Context::getFloatv(GLenum pname, GLfloat *params)
5118{
5119 GLenum nativeType;
5120 unsigned int numParams = 0;
5121 getQueryParameterInfo(pname, &nativeType, &numParams);
5122
5123 if (nativeType == GL_FLOAT)
5124 {
5125 getFloatvImpl(pname, params);
5126 }
5127 else
5128 {
5129 CastStateValues(this, nativeType, pname, numParams, params);
5130 }
5131}
5132
Brandon Jones59770802018-04-02 13:18:42 -07005133void Context::getFloatvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLfloat *params)
5134{
5135 getFloatv(pname, params);
5136}
5137
Jamie Madillc1d770e2017-04-13 17:31:24 -04005138void Context::getIntegerv(GLenum pname, GLint *params)
5139{
5140 GLenum nativeType;
5141 unsigned int numParams = 0;
5142 getQueryParameterInfo(pname, &nativeType, &numParams);
5143
5144 if (nativeType == GL_INT)
5145 {
5146 getIntegervImpl(pname, params);
5147 }
5148 else
5149 {
5150 CastStateValues(this, nativeType, pname, numParams, params);
5151 }
5152}
5153
Brandon Jones59770802018-04-02 13:18:42 -07005154void Context::getIntegervRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint *data)
5155{
5156 getIntegerv(pname, data);
5157}
5158
Jamie Madillc1d770e2017-04-13 17:31:24 -04005159void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
5160{
5161 Program *programObject = getProgram(program);
5162 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04005163 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005164}
5165
Brandon Jones59770802018-04-02 13:18:42 -07005166void Context::getProgramivRobust(GLuint program,
5167 GLenum pname,
5168 GLsizei bufSize,
5169 GLsizei *length,
5170 GLint *params)
5171{
5172 getProgramiv(program, pname, params);
5173}
5174
Jiajia Qin5451d532017-11-16 17:16:34 +08005175void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
5176{
5177 UNIMPLEMENTED();
5178}
5179
Jamie Madillbe849e42017-05-02 15:49:00 -04005180void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005181{
5182 Program *programObject = getProgram(program);
5183 ASSERT(programObject);
5184 programObject->getInfoLog(bufsize, length, infolog);
5185}
5186
Jiajia Qin5451d532017-11-16 17:16:34 +08005187void Context::getProgramPipelineInfoLog(GLuint pipeline,
5188 GLsizei bufSize,
5189 GLsizei *length,
5190 GLchar *infoLog)
5191{
5192 UNIMPLEMENTED();
5193}
5194
Jamie Madillc1d770e2017-04-13 17:31:24 -04005195void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
5196{
5197 Shader *shaderObject = getShader(shader);
5198 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04005199 QueryShaderiv(this, shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005200}
5201
Brandon Jones59770802018-04-02 13:18:42 -07005202void Context::getShaderivRobust(GLuint shader,
5203 GLenum pname,
5204 GLsizei bufSize,
5205 GLsizei *length,
5206 GLint *params)
5207{
5208 getShaderiv(shader, pname, params);
5209}
5210
Jamie Madillc1d770e2017-04-13 17:31:24 -04005211void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
5212{
5213 Shader *shaderObject = getShader(shader);
5214 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04005215 shaderObject->getInfoLog(this, bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005216}
5217
5218void Context::getShaderPrecisionFormat(GLenum shadertype,
5219 GLenum precisiontype,
5220 GLint *range,
5221 GLint *precision)
5222{
5223 // TODO(jmadill): Compute shaders.
5224
5225 switch (shadertype)
5226 {
5227 case GL_VERTEX_SHADER:
5228 switch (precisiontype)
5229 {
5230 case GL_LOW_FLOAT:
5231 mCaps.vertexLowpFloat.get(range, precision);
5232 break;
5233 case GL_MEDIUM_FLOAT:
5234 mCaps.vertexMediumpFloat.get(range, precision);
5235 break;
5236 case GL_HIGH_FLOAT:
5237 mCaps.vertexHighpFloat.get(range, precision);
5238 break;
5239
5240 case GL_LOW_INT:
5241 mCaps.vertexLowpInt.get(range, precision);
5242 break;
5243 case GL_MEDIUM_INT:
5244 mCaps.vertexMediumpInt.get(range, precision);
5245 break;
5246 case GL_HIGH_INT:
5247 mCaps.vertexHighpInt.get(range, precision);
5248 break;
5249
5250 default:
5251 UNREACHABLE();
5252 return;
5253 }
5254 break;
5255
5256 case GL_FRAGMENT_SHADER:
5257 switch (precisiontype)
5258 {
5259 case GL_LOW_FLOAT:
5260 mCaps.fragmentLowpFloat.get(range, precision);
5261 break;
5262 case GL_MEDIUM_FLOAT:
5263 mCaps.fragmentMediumpFloat.get(range, precision);
5264 break;
5265 case GL_HIGH_FLOAT:
5266 mCaps.fragmentHighpFloat.get(range, precision);
5267 break;
5268
5269 case GL_LOW_INT:
5270 mCaps.fragmentLowpInt.get(range, precision);
5271 break;
5272 case GL_MEDIUM_INT:
5273 mCaps.fragmentMediumpInt.get(range, precision);
5274 break;
5275 case GL_HIGH_INT:
5276 mCaps.fragmentHighpInt.get(range, precision);
5277 break;
5278
5279 default:
5280 UNREACHABLE();
5281 return;
5282 }
5283 break;
5284
5285 default:
5286 UNREACHABLE();
5287 return;
5288 }
5289}
5290
5291void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
5292{
5293 Shader *shaderObject = getShader(shader);
5294 ASSERT(shaderObject);
5295 shaderObject->getSource(bufsize, length, source);
5296}
5297
5298void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
5299{
5300 Program *programObject = getProgram(program);
5301 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005302 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005303}
5304
Brandon Jones59770802018-04-02 13:18:42 -07005305void Context::getUniformfvRobust(GLuint program,
5306 GLint location,
5307 GLsizei bufSize,
5308 GLsizei *length,
5309 GLfloat *params)
5310{
5311 getUniformfv(program, location, params);
5312}
5313
Jamie Madillc1d770e2017-04-13 17:31:24 -04005314void Context::getUniformiv(GLuint program, GLint location, GLint *params)
5315{
5316 Program *programObject = getProgram(program);
5317 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005318 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005319}
5320
Brandon Jones59770802018-04-02 13:18:42 -07005321void Context::getUniformivRobust(GLuint program,
5322 GLint location,
5323 GLsizei bufSize,
5324 GLsizei *length,
5325 GLint *params)
5326{
5327 getUniformiv(program, location, params);
5328}
5329
Jamie Madillc1d770e2017-04-13 17:31:24 -04005330GLint Context::getUniformLocation(GLuint program, const GLchar *name)
5331{
5332 Program *programObject = getProgram(program);
5333 ASSERT(programObject);
5334 return programObject->getUniformLocation(name);
5335}
5336
5337GLboolean Context::isBuffer(GLuint buffer)
5338{
5339 if (buffer == 0)
5340 {
5341 return GL_FALSE;
5342 }
5343
5344 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
5345}
5346
5347GLboolean Context::isEnabled(GLenum cap)
5348{
5349 return mGLState.getEnableFeature(cap);
5350}
5351
5352GLboolean Context::isFramebuffer(GLuint framebuffer)
5353{
5354 if (framebuffer == 0)
5355 {
5356 return GL_FALSE;
5357 }
5358
5359 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
5360}
5361
5362GLboolean Context::isProgram(GLuint program)
5363{
5364 if (program == 0)
5365 {
5366 return GL_FALSE;
5367 }
5368
5369 return (getProgram(program) ? GL_TRUE : GL_FALSE);
5370}
5371
5372GLboolean Context::isRenderbuffer(GLuint renderbuffer)
5373{
5374 if (renderbuffer == 0)
5375 {
5376 return GL_FALSE;
5377 }
5378
5379 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
5380}
5381
5382GLboolean Context::isShader(GLuint shader)
5383{
5384 if (shader == 0)
5385 {
5386 return GL_FALSE;
5387 }
5388
5389 return (getShader(shader) ? GL_TRUE : GL_FALSE);
5390}
5391
5392GLboolean Context::isTexture(GLuint texture)
5393{
5394 if (texture == 0)
5395 {
5396 return GL_FALSE;
5397 }
5398
5399 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
5400}
5401
5402void Context::linkProgram(GLuint program)
5403{
5404 Program *programObject = getProgram(program);
5405 ASSERT(programObject);
5406 handleError(programObject->link(this));
Martin Radev0abb7a22017-08-28 15:34:45 +03005407 mGLState.onProgramExecutableChange(programObject);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005408}
5409
5410void Context::releaseShaderCompiler()
5411{
Jamie Madill4928b7c2017-06-20 12:57:39 -04005412 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005413}
5414
5415void Context::shaderBinary(GLsizei n,
5416 const GLuint *shaders,
5417 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04005418 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005419 GLsizei length)
5420{
5421 // No binary shader formats are supported.
5422 UNIMPLEMENTED();
5423}
5424
5425void Context::shaderSource(GLuint shader,
5426 GLsizei count,
5427 const GLchar *const *string,
5428 const GLint *length)
5429{
5430 Shader *shaderObject = getShader(shader);
5431 ASSERT(shaderObject);
5432 shaderObject->setSource(count, string, length);
5433}
5434
5435void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
5436{
5437 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
5438}
5439
5440void Context::stencilMask(GLuint mask)
5441{
5442 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
5443}
5444
5445void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
5446{
5447 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
5448}
5449
5450void Context::uniform1f(GLint location, GLfloat x)
5451{
5452 Program *program = mGLState.getProgram();
5453 program->setUniform1fv(location, 1, &x);
5454}
5455
5456void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
5457{
5458 Program *program = mGLState.getProgram();
5459 program->setUniform1fv(location, count, v);
5460}
5461
5462void Context::uniform1i(GLint location, GLint x)
5463{
5464 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04005465 if (program->setUniform1iv(location, 1, &x) == Program::SetUniformResult::SamplerChanged)
5466 {
5467 mGLState.setObjectDirty(GL_PROGRAM);
5468 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005469}
5470
5471void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
5472{
5473 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04005474 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
5475 {
5476 mGLState.setObjectDirty(GL_PROGRAM);
5477 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005478}
5479
5480void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
5481{
5482 GLfloat xy[2] = {x, y};
5483 Program *program = mGLState.getProgram();
5484 program->setUniform2fv(location, 1, xy);
5485}
5486
5487void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
5488{
5489 Program *program = mGLState.getProgram();
5490 program->setUniform2fv(location, count, v);
5491}
5492
5493void Context::uniform2i(GLint location, GLint x, GLint y)
5494{
5495 GLint xy[2] = {x, y};
5496 Program *program = mGLState.getProgram();
5497 program->setUniform2iv(location, 1, xy);
5498}
5499
5500void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
5501{
5502 Program *program = mGLState.getProgram();
5503 program->setUniform2iv(location, count, v);
5504}
5505
5506void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
5507{
5508 GLfloat xyz[3] = {x, y, z};
5509 Program *program = mGLState.getProgram();
5510 program->setUniform3fv(location, 1, xyz);
5511}
5512
5513void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
5514{
5515 Program *program = mGLState.getProgram();
5516 program->setUniform3fv(location, count, v);
5517}
5518
5519void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
5520{
5521 GLint xyz[3] = {x, y, z};
5522 Program *program = mGLState.getProgram();
5523 program->setUniform3iv(location, 1, xyz);
5524}
5525
5526void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
5527{
5528 Program *program = mGLState.getProgram();
5529 program->setUniform3iv(location, count, v);
5530}
5531
5532void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
5533{
5534 GLfloat xyzw[4] = {x, y, z, w};
5535 Program *program = mGLState.getProgram();
5536 program->setUniform4fv(location, 1, xyzw);
5537}
5538
5539void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
5540{
5541 Program *program = mGLState.getProgram();
5542 program->setUniform4fv(location, count, v);
5543}
5544
5545void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
5546{
5547 GLint xyzw[4] = {x, y, z, w};
5548 Program *program = mGLState.getProgram();
5549 program->setUniform4iv(location, 1, xyzw);
5550}
5551
5552void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
5553{
5554 Program *program = mGLState.getProgram();
5555 program->setUniform4iv(location, count, v);
5556}
5557
5558void Context::uniformMatrix2fv(GLint location,
5559 GLsizei count,
5560 GLboolean transpose,
5561 const GLfloat *value)
5562{
5563 Program *program = mGLState.getProgram();
5564 program->setUniformMatrix2fv(location, count, transpose, value);
5565}
5566
5567void Context::uniformMatrix3fv(GLint location,
5568 GLsizei count,
5569 GLboolean transpose,
5570 const GLfloat *value)
5571{
5572 Program *program = mGLState.getProgram();
5573 program->setUniformMatrix3fv(location, count, transpose, value);
5574}
5575
5576void Context::uniformMatrix4fv(GLint location,
5577 GLsizei count,
5578 GLboolean transpose,
5579 const GLfloat *value)
5580{
5581 Program *program = mGLState.getProgram();
5582 program->setUniformMatrix4fv(location, count, transpose, value);
5583}
5584
5585void Context::validateProgram(GLuint program)
5586{
5587 Program *programObject = getProgram(program);
5588 ASSERT(programObject);
5589 programObject->validate(mCaps);
5590}
5591
Jiajia Qin5451d532017-11-16 17:16:34 +08005592void Context::validateProgramPipeline(GLuint pipeline)
5593{
5594 UNIMPLEMENTED();
5595}
5596
Jamie Madilld04908b2017-06-09 14:15:35 -04005597void Context::getProgramBinary(GLuint program,
5598 GLsizei bufSize,
5599 GLsizei *length,
5600 GLenum *binaryFormat,
5601 void *binary)
5602{
5603 Program *programObject = getProgram(program);
5604 ASSERT(programObject != nullptr);
5605
5606 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
5607}
5608
5609void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
5610{
5611 Program *programObject = getProgram(program);
5612 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04005613
Jamie Madilld04908b2017-06-09 14:15:35 -04005614 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
5615}
5616
Jamie Madillff325f12017-08-26 15:06:05 -04005617void Context::uniform1ui(GLint location, GLuint v0)
5618{
5619 Program *program = mGLState.getProgram();
5620 program->setUniform1uiv(location, 1, &v0);
5621}
5622
5623void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
5624{
5625 Program *program = mGLState.getProgram();
5626 const GLuint xy[] = {v0, v1};
5627 program->setUniform2uiv(location, 1, xy);
5628}
5629
5630void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
5631{
5632 Program *program = mGLState.getProgram();
5633 const GLuint xyz[] = {v0, v1, v2};
5634 program->setUniform3uiv(location, 1, xyz);
5635}
5636
5637void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
5638{
5639 Program *program = mGLState.getProgram();
5640 const GLuint xyzw[] = {v0, v1, v2, v3};
5641 program->setUniform4uiv(location, 1, xyzw);
5642}
5643
5644void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
5645{
5646 Program *program = mGLState.getProgram();
5647 program->setUniform1uiv(location, count, value);
5648}
5649void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
5650{
5651 Program *program = mGLState.getProgram();
5652 program->setUniform2uiv(location, count, value);
5653}
5654
5655void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
5656{
5657 Program *program = mGLState.getProgram();
5658 program->setUniform3uiv(location, count, value);
5659}
5660
5661void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
5662{
5663 Program *program = mGLState.getProgram();
5664 program->setUniform4uiv(location, count, value);
5665}
5666
Jamie Madillf0e04492017-08-26 15:28:42 -04005667void Context::genQueries(GLsizei n, GLuint *ids)
5668{
5669 for (GLsizei i = 0; i < n; i++)
5670 {
5671 GLuint handle = mQueryHandleAllocator.allocate();
5672 mQueryMap.assign(handle, nullptr);
5673 ids[i] = handle;
5674 }
5675}
5676
5677void Context::deleteQueries(GLsizei n, const GLuint *ids)
5678{
5679 for (int i = 0; i < n; i++)
5680 {
5681 GLuint query = ids[i];
5682
5683 Query *queryObject = nullptr;
5684 if (mQueryMap.erase(query, &queryObject))
5685 {
5686 mQueryHandleAllocator.release(query);
5687 if (queryObject)
5688 {
5689 queryObject->release(this);
5690 }
5691 }
5692 }
5693}
5694
5695GLboolean Context::isQuery(GLuint id)
5696{
Corentin Wallezad3ae902018-03-09 13:40:42 -05005697 return (getQuery(id, false, QueryType::InvalidEnum) != nullptr) ? GL_TRUE : GL_FALSE;
Jamie Madillf0e04492017-08-26 15:28:42 -04005698}
5699
Jamie Madillc8c95812017-08-26 18:40:09 -04005700void Context::uniformMatrix2x3fv(GLint location,
5701 GLsizei count,
5702 GLboolean transpose,
5703 const GLfloat *value)
5704{
5705 Program *program = mGLState.getProgram();
5706 program->setUniformMatrix2x3fv(location, count, transpose, value);
5707}
5708
5709void Context::uniformMatrix3x2fv(GLint location,
5710 GLsizei count,
5711 GLboolean transpose,
5712 const GLfloat *value)
5713{
5714 Program *program = mGLState.getProgram();
5715 program->setUniformMatrix3x2fv(location, count, transpose, value);
5716}
5717
5718void Context::uniformMatrix2x4fv(GLint location,
5719 GLsizei count,
5720 GLboolean transpose,
5721 const GLfloat *value)
5722{
5723 Program *program = mGLState.getProgram();
5724 program->setUniformMatrix2x4fv(location, count, transpose, value);
5725}
5726
5727void Context::uniformMatrix4x2fv(GLint location,
5728 GLsizei count,
5729 GLboolean transpose,
5730 const GLfloat *value)
5731{
5732 Program *program = mGLState.getProgram();
5733 program->setUniformMatrix4x2fv(location, count, transpose, value);
5734}
5735
5736void Context::uniformMatrix3x4fv(GLint location,
5737 GLsizei count,
5738 GLboolean transpose,
5739 const GLfloat *value)
5740{
5741 Program *program = mGLState.getProgram();
5742 program->setUniformMatrix3x4fv(location, count, transpose, value);
5743}
5744
5745void Context::uniformMatrix4x3fv(GLint location,
5746 GLsizei count,
5747 GLboolean transpose,
5748 const GLfloat *value)
5749{
5750 Program *program = mGLState.getProgram();
5751 program->setUniformMatrix4x3fv(location, count, transpose, value);
5752}
5753
Jamie Madilld7576732017-08-26 18:49:50 -04005754void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
5755{
5756 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5757 {
5758 GLuint vertexArray = arrays[arrayIndex];
5759
5760 if (arrays[arrayIndex] != 0)
5761 {
5762 VertexArray *vertexArrayObject = nullptr;
5763 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
5764 {
5765 if (vertexArrayObject != nullptr)
5766 {
5767 detachVertexArray(vertexArray);
5768 vertexArrayObject->onDestroy(this);
5769 }
5770
5771 mVertexArrayHandleAllocator.release(vertexArray);
5772 }
5773 }
5774 }
5775}
5776
5777void Context::genVertexArrays(GLsizei n, GLuint *arrays)
5778{
5779 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5780 {
5781 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
5782 mVertexArrayMap.assign(vertexArray, nullptr);
5783 arrays[arrayIndex] = vertexArray;
5784 }
5785}
5786
5787bool Context::isVertexArray(GLuint array)
5788{
5789 if (array == 0)
5790 {
5791 return GL_FALSE;
5792 }
5793
5794 VertexArray *vao = getVertexArray(array);
5795 return (vao != nullptr ? GL_TRUE : GL_FALSE);
5796}
5797
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04005798void Context::endTransformFeedback()
5799{
5800 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5801 transformFeedback->end(this);
5802}
5803
5804void Context::transformFeedbackVaryings(GLuint program,
5805 GLsizei count,
5806 const GLchar *const *varyings,
5807 GLenum bufferMode)
5808{
5809 Program *programObject = getProgram(program);
5810 ASSERT(programObject);
5811 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
5812}
5813
5814void Context::getTransformFeedbackVarying(GLuint program,
5815 GLuint index,
5816 GLsizei bufSize,
5817 GLsizei *length,
5818 GLsizei *size,
5819 GLenum *type,
5820 GLchar *name)
5821{
5822 Program *programObject = getProgram(program);
5823 ASSERT(programObject);
5824 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
5825}
5826
5827void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
5828{
5829 for (int i = 0; i < n; i++)
5830 {
5831 GLuint transformFeedback = ids[i];
5832 if (transformFeedback == 0)
5833 {
5834 continue;
5835 }
5836
5837 TransformFeedback *transformFeedbackObject = nullptr;
5838 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
5839 {
5840 if (transformFeedbackObject != nullptr)
5841 {
5842 detachTransformFeedback(transformFeedback);
5843 transformFeedbackObject->release(this);
5844 }
5845
5846 mTransformFeedbackHandleAllocator.release(transformFeedback);
5847 }
5848 }
5849}
5850
5851void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
5852{
5853 for (int i = 0; i < n; i++)
5854 {
5855 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
5856 mTransformFeedbackMap.assign(transformFeedback, nullptr);
5857 ids[i] = transformFeedback;
5858 }
5859}
5860
5861bool Context::isTransformFeedback(GLuint id)
5862{
5863 if (id == 0)
5864 {
5865 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
5866 // returns FALSE
5867 return GL_FALSE;
5868 }
5869
5870 const TransformFeedback *transformFeedback = getTransformFeedback(id);
5871 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
5872}
5873
5874void Context::pauseTransformFeedback()
5875{
5876 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5877 transformFeedback->pause();
5878}
5879
5880void Context::resumeTransformFeedback()
5881{
5882 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5883 transformFeedback->resume();
5884}
5885
Jamie Madill12e957f2017-08-26 21:42:26 -04005886void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
5887{
5888 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04005889 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04005890}
5891
Brandon Jones59770802018-04-02 13:18:42 -07005892void Context::getUniformuivRobust(GLuint program,
5893 GLint location,
5894 GLsizei bufSize,
5895 GLsizei *length,
5896 GLuint *params)
5897{
5898 getUniformuiv(program, location, params);
5899}
5900
Jamie Madill12e957f2017-08-26 21:42:26 -04005901GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
5902{
5903 const Program *programObject = getProgram(program);
5904 return programObject->getFragDataLocation(name);
5905}
5906
5907void Context::getUniformIndices(GLuint program,
5908 GLsizei uniformCount,
5909 const GLchar *const *uniformNames,
5910 GLuint *uniformIndices)
5911{
5912 const Program *programObject = getProgram(program);
5913 if (!programObject->isLinked())
5914 {
5915 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5916 {
5917 uniformIndices[uniformId] = GL_INVALID_INDEX;
5918 }
5919 }
5920 else
5921 {
5922 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5923 {
5924 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
5925 }
5926 }
5927}
5928
5929void Context::getActiveUniformsiv(GLuint program,
5930 GLsizei uniformCount,
5931 const GLuint *uniformIndices,
5932 GLenum pname,
5933 GLint *params)
5934{
5935 const Program *programObject = getProgram(program);
5936 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5937 {
5938 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08005939 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04005940 }
5941}
5942
5943GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
5944{
5945 const Program *programObject = getProgram(program);
5946 return programObject->getUniformBlockIndex(uniformBlockName);
5947}
5948
5949void Context::getActiveUniformBlockiv(GLuint program,
5950 GLuint uniformBlockIndex,
5951 GLenum pname,
5952 GLint *params)
5953{
5954 const Program *programObject = getProgram(program);
5955 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
5956}
5957
Brandon Jones59770802018-04-02 13:18:42 -07005958void Context::getActiveUniformBlockivRobust(GLuint program,
5959 GLuint uniformBlockIndex,
5960 GLenum pname,
5961 GLsizei bufSize,
5962 GLsizei *length,
5963 GLint *params)
5964{
5965 getActiveUniformBlockiv(program, uniformBlockIndex, pname, params);
5966}
5967
Jamie Madill12e957f2017-08-26 21:42:26 -04005968void Context::getActiveUniformBlockName(GLuint program,
5969 GLuint uniformBlockIndex,
5970 GLsizei bufSize,
5971 GLsizei *length,
5972 GLchar *uniformBlockName)
5973{
5974 const Program *programObject = getProgram(program);
5975 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
5976}
5977
5978void Context::uniformBlockBinding(GLuint program,
5979 GLuint uniformBlockIndex,
5980 GLuint uniformBlockBinding)
5981{
5982 Program *programObject = getProgram(program);
5983 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
5984}
5985
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005986GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
5987{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005988 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
5989 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005990
Jamie Madill70b5bb02017-08-28 13:32:37 -04005991 Sync *syncObject = getSync(syncHandle);
5992 Error error = syncObject->set(condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005993 if (error.isError())
5994 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04005995 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005996 handleError(error);
5997 return nullptr;
5998 }
5999
Jamie Madill70b5bb02017-08-28 13:32:37 -04006000 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006001}
6002
6003GLboolean Context::isSync(GLsync sync)
6004{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006005 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006006}
6007
6008GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6009{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006010 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006011
6012 GLenum result = GL_WAIT_FAILED;
6013 handleError(syncObject->clientWait(flags, timeout, &result));
6014 return result;
6015}
6016
6017void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6018{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006019 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006020 handleError(syncObject->serverWait(flags, timeout));
6021}
6022
6023void Context::getInteger64v(GLenum pname, GLint64 *params)
6024{
6025 GLenum nativeType = GL_NONE;
6026 unsigned int numParams = 0;
6027 getQueryParameterInfo(pname, &nativeType, &numParams);
6028
6029 if (nativeType == GL_INT_64_ANGLEX)
6030 {
6031 getInteger64vImpl(pname, params);
6032 }
6033 else
6034 {
6035 CastStateValues(this, nativeType, pname, numParams, params);
6036 }
6037}
6038
Brandon Jones59770802018-04-02 13:18:42 -07006039void Context::getInteger64vRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint64 *data)
6040{
6041 getInteger64v(pname, data);
6042}
6043
Corentin Wallez336129f2017-10-17 15:55:40 -04006044void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04006045{
6046 Buffer *buffer = mGLState.getTargetBuffer(target);
6047 QueryBufferParameteri64v(buffer, pname, params);
6048}
6049
Brandon Jones59770802018-04-02 13:18:42 -07006050void Context::getBufferParameteri64vRobust(BufferBinding target,
6051 GLenum pname,
6052 GLsizei bufSize,
6053 GLsizei *length,
6054 GLint64 *params)
6055{
6056 getBufferParameteri64v(target, pname, params);
6057}
6058
Jamie Madill3ef140a2017-08-26 23:11:21 -04006059void Context::genSamplers(GLsizei count, GLuint *samplers)
6060{
6061 for (int i = 0; i < count; i++)
6062 {
6063 samplers[i] = mState.mSamplers->createSampler();
6064 }
6065}
6066
6067void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
6068{
6069 for (int i = 0; i < count; i++)
6070 {
6071 GLuint sampler = samplers[i];
6072
6073 if (mState.mSamplers->getSampler(sampler))
6074 {
6075 detachSampler(sampler);
6076 }
6077
6078 mState.mSamplers->deleteObject(this, sampler);
6079 }
6080}
6081
6082void Context::getInternalformativ(GLenum target,
6083 GLenum internalformat,
6084 GLenum pname,
6085 GLsizei bufSize,
6086 GLint *params)
6087{
6088 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
6089 QueryInternalFormativ(formatCaps, pname, bufSize, params);
6090}
6091
Brandon Jones59770802018-04-02 13:18:42 -07006092void Context::getInternalformativRobust(GLenum target,
6093 GLenum internalformat,
6094 GLenum pname,
6095 GLsizei bufSize,
6096 GLsizei *length,
6097 GLint *params)
6098{
6099 getInternalformativ(target, internalformat, pname, bufSize, params);
6100}
6101
Jiajia Qin5451d532017-11-16 17:16:34 +08006102void Context::programUniform1i(GLuint program, GLint location, GLint v0)
6103{
6104 programUniform1iv(program, location, 1, &v0);
6105}
6106
6107void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
6108{
6109 GLint xy[2] = {v0, v1};
6110 programUniform2iv(program, location, 1, xy);
6111}
6112
6113void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
6114{
6115 GLint xyz[3] = {v0, v1, v2};
6116 programUniform3iv(program, location, 1, xyz);
6117}
6118
6119void Context::programUniform4i(GLuint program,
6120 GLint location,
6121 GLint v0,
6122 GLint v1,
6123 GLint v2,
6124 GLint v3)
6125{
6126 GLint xyzw[4] = {v0, v1, v2, v3};
6127 programUniform4iv(program, location, 1, xyzw);
6128}
6129
6130void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
6131{
6132 programUniform1uiv(program, location, 1, &v0);
6133}
6134
6135void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
6136{
6137 GLuint xy[2] = {v0, v1};
6138 programUniform2uiv(program, location, 1, xy);
6139}
6140
6141void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
6142{
6143 GLuint xyz[3] = {v0, v1, v2};
6144 programUniform3uiv(program, location, 1, xyz);
6145}
6146
6147void Context::programUniform4ui(GLuint program,
6148 GLint location,
6149 GLuint v0,
6150 GLuint v1,
6151 GLuint v2,
6152 GLuint v3)
6153{
6154 GLuint xyzw[4] = {v0, v1, v2, v3};
6155 programUniform4uiv(program, location, 1, xyzw);
6156}
6157
6158void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
6159{
6160 programUniform1fv(program, location, 1, &v0);
6161}
6162
6163void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
6164{
6165 GLfloat xy[2] = {v0, v1};
6166 programUniform2fv(program, location, 1, xy);
6167}
6168
6169void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
6170{
6171 GLfloat xyz[3] = {v0, v1, v2};
6172 programUniform3fv(program, location, 1, xyz);
6173}
6174
6175void Context::programUniform4f(GLuint program,
6176 GLint location,
6177 GLfloat v0,
6178 GLfloat v1,
6179 GLfloat v2,
6180 GLfloat v3)
6181{
6182 GLfloat xyzw[4] = {v0, v1, v2, v3};
6183 programUniform4fv(program, location, 1, xyzw);
6184}
6185
Jamie Madill81c2e252017-09-09 23:32:46 -04006186void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6187{
6188 Program *programObject = getProgram(program);
6189 ASSERT(programObject);
6190 if (programObject->setUniform1iv(location, count, value) ==
6191 Program::SetUniformResult::SamplerChanged)
6192 {
6193 mGLState.setObjectDirty(GL_PROGRAM);
6194 }
6195}
6196
Jiajia Qin5451d532017-11-16 17:16:34 +08006197void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6198{
6199 Program *programObject = getProgram(program);
6200 ASSERT(programObject);
6201 programObject->setUniform2iv(location, count, value);
6202}
6203
6204void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6205{
6206 Program *programObject = getProgram(program);
6207 ASSERT(programObject);
6208 programObject->setUniform3iv(location, count, value);
6209}
6210
6211void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6212{
6213 Program *programObject = getProgram(program);
6214 ASSERT(programObject);
6215 programObject->setUniform4iv(location, count, value);
6216}
6217
6218void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6219{
6220 Program *programObject = getProgram(program);
6221 ASSERT(programObject);
6222 programObject->setUniform1uiv(location, count, value);
6223}
6224
6225void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6226{
6227 Program *programObject = getProgram(program);
6228 ASSERT(programObject);
6229 programObject->setUniform2uiv(location, count, value);
6230}
6231
6232void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6233{
6234 Program *programObject = getProgram(program);
6235 ASSERT(programObject);
6236 programObject->setUniform3uiv(location, count, value);
6237}
6238
6239void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6240{
6241 Program *programObject = getProgram(program);
6242 ASSERT(programObject);
6243 programObject->setUniform4uiv(location, count, value);
6244}
6245
6246void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6247{
6248 Program *programObject = getProgram(program);
6249 ASSERT(programObject);
6250 programObject->setUniform1fv(location, count, value);
6251}
6252
6253void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6254{
6255 Program *programObject = getProgram(program);
6256 ASSERT(programObject);
6257 programObject->setUniform2fv(location, count, value);
6258}
6259
6260void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6261{
6262 Program *programObject = getProgram(program);
6263 ASSERT(programObject);
6264 programObject->setUniform3fv(location, count, value);
6265}
6266
6267void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6268{
6269 Program *programObject = getProgram(program);
6270 ASSERT(programObject);
6271 programObject->setUniform4fv(location, count, value);
6272}
6273
6274void Context::programUniformMatrix2fv(GLuint program,
6275 GLint location,
6276 GLsizei count,
6277 GLboolean transpose,
6278 const GLfloat *value)
6279{
6280 Program *programObject = getProgram(program);
6281 ASSERT(programObject);
6282 programObject->setUniformMatrix2fv(location, count, transpose, value);
6283}
6284
6285void Context::programUniformMatrix3fv(GLuint program,
6286 GLint location,
6287 GLsizei count,
6288 GLboolean transpose,
6289 const GLfloat *value)
6290{
6291 Program *programObject = getProgram(program);
6292 ASSERT(programObject);
6293 programObject->setUniformMatrix3fv(location, count, transpose, value);
6294}
6295
6296void Context::programUniformMatrix4fv(GLuint program,
6297 GLint location,
6298 GLsizei count,
6299 GLboolean transpose,
6300 const GLfloat *value)
6301{
6302 Program *programObject = getProgram(program);
6303 ASSERT(programObject);
6304 programObject->setUniformMatrix4fv(location, count, transpose, value);
6305}
6306
6307void Context::programUniformMatrix2x3fv(GLuint program,
6308 GLint location,
6309 GLsizei count,
6310 GLboolean transpose,
6311 const GLfloat *value)
6312{
6313 Program *programObject = getProgram(program);
6314 ASSERT(programObject);
6315 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
6316}
6317
6318void Context::programUniformMatrix3x2fv(GLuint program,
6319 GLint location,
6320 GLsizei count,
6321 GLboolean transpose,
6322 const GLfloat *value)
6323{
6324 Program *programObject = getProgram(program);
6325 ASSERT(programObject);
6326 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
6327}
6328
6329void Context::programUniformMatrix2x4fv(GLuint program,
6330 GLint location,
6331 GLsizei count,
6332 GLboolean transpose,
6333 const GLfloat *value)
6334{
6335 Program *programObject = getProgram(program);
6336 ASSERT(programObject);
6337 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
6338}
6339
6340void Context::programUniformMatrix4x2fv(GLuint program,
6341 GLint location,
6342 GLsizei count,
6343 GLboolean transpose,
6344 const GLfloat *value)
6345{
6346 Program *programObject = getProgram(program);
6347 ASSERT(programObject);
6348 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
6349}
6350
6351void Context::programUniformMatrix3x4fv(GLuint program,
6352 GLint location,
6353 GLsizei count,
6354 GLboolean transpose,
6355 const GLfloat *value)
6356{
6357 Program *programObject = getProgram(program);
6358 ASSERT(programObject);
6359 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
6360}
6361
6362void Context::programUniformMatrix4x3fv(GLuint program,
6363 GLint location,
6364 GLsizei count,
6365 GLboolean transpose,
6366 const GLfloat *value)
6367{
6368 Program *programObject = getProgram(program);
6369 ASSERT(programObject);
6370 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
6371}
6372
Jamie Madill81c2e252017-09-09 23:32:46 -04006373void Context::onTextureChange(const Texture *texture)
6374{
6375 // Conservatively assume all textures are dirty.
6376 // TODO(jmadill): More fine-grained update.
6377 mGLState.setObjectDirty(GL_TEXTURE);
6378}
6379
James Darpiniane8a93c62018-01-04 18:02:24 -08006380bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
6381{
6382 return mGLState.isCurrentTransformFeedback(tf);
6383}
6384bool Context::isCurrentVertexArray(const VertexArray *va) const
6385{
6386 return mGLState.isCurrentVertexArray(va);
6387}
6388
Yunchao Hea336b902017-08-02 16:05:21 +08006389void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
6390{
6391 for (int i = 0; i < count; i++)
6392 {
6393 pipelines[i] = createProgramPipeline();
6394 }
6395}
6396
6397void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
6398{
6399 for (int i = 0; i < count; i++)
6400 {
6401 if (pipelines[i] != 0)
6402 {
6403 deleteProgramPipeline(pipelines[i]);
6404 }
6405 }
6406}
6407
6408GLboolean Context::isProgramPipeline(GLuint pipeline)
6409{
6410 if (pipeline == 0)
6411 {
6412 return GL_FALSE;
6413 }
6414
6415 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
6416}
6417
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006418void Context::finishFenceNV(GLuint fence)
6419{
6420 FenceNV *fenceObject = getFenceNV(fence);
6421
6422 ASSERT(fenceObject && fenceObject->isSet());
6423 handleError(fenceObject->finish());
6424}
6425
6426void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
6427{
6428 FenceNV *fenceObject = getFenceNV(fence);
6429
6430 ASSERT(fenceObject && fenceObject->isSet());
6431
6432 switch (pname)
6433 {
6434 case GL_FENCE_STATUS_NV:
6435 {
6436 // GL_NV_fence spec:
6437 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
6438 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
6439 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
6440 GLboolean status = GL_TRUE;
6441 if (fenceObject->getStatus() != GL_TRUE)
6442 {
6443 ANGLE_CONTEXT_TRY(fenceObject->test(&status));
6444 }
6445 *params = status;
6446 break;
6447 }
6448
6449 case GL_FENCE_CONDITION_NV:
6450 {
6451 *params = static_cast<GLint>(fenceObject->getCondition());
6452 break;
6453 }
6454
6455 default:
6456 UNREACHABLE();
6457 }
6458}
6459
6460void Context::getTranslatedShaderSource(GLuint shader,
6461 GLsizei bufsize,
6462 GLsizei *length,
6463 GLchar *source)
6464{
6465 Shader *shaderObject = getShader(shader);
6466 ASSERT(shaderObject);
6467 shaderObject->getTranslatedSourceWithDebugInfo(this, bufsize, length, source);
6468}
6469
6470void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
6471{
6472 Program *programObject = getProgram(program);
6473 ASSERT(programObject);
6474
6475 programObject->getUniformfv(this, location, params);
6476}
6477
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006478void Context::getnUniformfvRobust(GLuint program,
6479 GLint location,
6480 GLsizei bufSize,
6481 GLsizei *length,
6482 GLfloat *params)
6483{
6484 UNIMPLEMENTED();
6485}
6486
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006487void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
6488{
6489 Program *programObject = getProgram(program);
6490 ASSERT(programObject);
6491
6492 programObject->getUniformiv(this, location, params);
6493}
6494
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006495void Context::getnUniformivRobust(GLuint program,
6496 GLint location,
6497 GLsizei bufSize,
6498 GLsizei *length,
6499 GLint *params)
6500{
6501 UNIMPLEMENTED();
6502}
6503
6504void Context::getnUniformuivRobust(GLuint program,
6505 GLint location,
6506 GLsizei bufSize,
6507 GLsizei *length,
6508 GLuint *params)
6509{
6510 UNIMPLEMENTED();
6511}
6512
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006513GLboolean Context::isFenceNV(GLuint fence)
6514{
6515 FenceNV *fenceObject = getFenceNV(fence);
6516
6517 if (fenceObject == nullptr)
6518 {
6519 return GL_FALSE;
6520 }
6521
6522 // GL_NV_fence spec:
6523 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
6524 // existing fence.
6525 return fenceObject->isSet();
6526}
6527
6528void Context::readnPixels(GLint x,
6529 GLint y,
6530 GLsizei width,
6531 GLsizei height,
6532 GLenum format,
6533 GLenum type,
6534 GLsizei bufSize,
6535 void *data)
6536{
6537 return readPixels(x, y, width, height, format, type, data);
6538}
6539
Jamie Madill007530e2017-12-28 14:27:04 -05006540void Context::setFenceNV(GLuint fence, GLenum condition)
6541{
6542 ASSERT(condition == GL_ALL_COMPLETED_NV);
6543
6544 FenceNV *fenceObject = getFenceNV(fence);
6545 ASSERT(fenceObject != nullptr);
6546 handleError(fenceObject->set(condition));
6547}
6548
6549GLboolean Context::testFenceNV(GLuint fence)
6550{
6551 FenceNV *fenceObject = getFenceNV(fence);
6552
6553 ASSERT(fenceObject != nullptr);
6554 ASSERT(fenceObject->isSet() == GL_TRUE);
6555
6556 GLboolean result = GL_TRUE;
6557 Error error = fenceObject->test(&result);
6558 if (error.isError())
6559 {
6560 handleError(error);
6561 return GL_TRUE;
6562 }
6563
6564 return result;
6565}
6566
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006567void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006568{
6569 Texture *texture = getTargetTexture(target);
6570 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
Corentin Wallez99d492c2018-02-27 15:17:10 -05006571 handleError(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05006572}
6573
Jamie Madillfa920eb2018-01-04 11:45:50 -05006574void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006575{
6576 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
6577 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
6578 handleError(renderbuffer->setStorageEGLImageTarget(this, imageObject));
6579}
6580
Jamie Madillfa920eb2018-01-04 11:45:50 -05006581void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
6582{
6583 UNIMPLEMENTED();
6584}
6585
Jamie Madill5b772312018-03-08 20:28:32 -05006586bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
6587{
6588 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
6589 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
6590 // to the fact that it is stored internally as a float, and so would require conversion
6591 // if returned from Context::getIntegerv. Since this conversion is already implemented
6592 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
6593 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
6594 // application.
6595 switch (pname)
6596 {
6597 case GL_COMPRESSED_TEXTURE_FORMATS:
6598 {
6599 *type = GL_INT;
6600 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
6601 return true;
6602 }
6603 case GL_SHADER_BINARY_FORMATS:
6604 {
6605 *type = GL_INT;
6606 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
6607 return true;
6608 }
6609
6610 case GL_MAX_VERTEX_ATTRIBS:
6611 case GL_MAX_VERTEX_UNIFORM_VECTORS:
6612 case GL_MAX_VARYING_VECTORS:
6613 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
6614 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
6615 case GL_MAX_TEXTURE_IMAGE_UNITS:
6616 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
6617 case GL_MAX_RENDERBUFFER_SIZE:
6618 case GL_NUM_SHADER_BINARY_FORMATS:
6619 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
6620 case GL_ARRAY_BUFFER_BINDING:
6621 case GL_FRAMEBUFFER_BINDING:
6622 case GL_RENDERBUFFER_BINDING:
6623 case GL_CURRENT_PROGRAM:
6624 case GL_PACK_ALIGNMENT:
6625 case GL_UNPACK_ALIGNMENT:
6626 case GL_GENERATE_MIPMAP_HINT:
6627 case GL_RED_BITS:
6628 case GL_GREEN_BITS:
6629 case GL_BLUE_BITS:
6630 case GL_ALPHA_BITS:
6631 case GL_DEPTH_BITS:
6632 case GL_STENCIL_BITS:
6633 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
6634 case GL_CULL_FACE_MODE:
6635 case GL_FRONT_FACE:
6636 case GL_ACTIVE_TEXTURE:
6637 case GL_STENCIL_FUNC:
6638 case GL_STENCIL_VALUE_MASK:
6639 case GL_STENCIL_REF:
6640 case GL_STENCIL_FAIL:
6641 case GL_STENCIL_PASS_DEPTH_FAIL:
6642 case GL_STENCIL_PASS_DEPTH_PASS:
6643 case GL_STENCIL_BACK_FUNC:
6644 case GL_STENCIL_BACK_VALUE_MASK:
6645 case GL_STENCIL_BACK_REF:
6646 case GL_STENCIL_BACK_FAIL:
6647 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
6648 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
6649 case GL_DEPTH_FUNC:
6650 case GL_BLEND_SRC_RGB:
6651 case GL_BLEND_SRC_ALPHA:
6652 case GL_BLEND_DST_RGB:
6653 case GL_BLEND_DST_ALPHA:
6654 case GL_BLEND_EQUATION_RGB:
6655 case GL_BLEND_EQUATION_ALPHA:
6656 case GL_STENCIL_WRITEMASK:
6657 case GL_STENCIL_BACK_WRITEMASK:
6658 case GL_STENCIL_CLEAR_VALUE:
6659 case GL_SUBPIXEL_BITS:
6660 case GL_MAX_TEXTURE_SIZE:
6661 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
6662 case GL_SAMPLE_BUFFERS:
6663 case GL_SAMPLES:
6664 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
6665 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
6666 case GL_TEXTURE_BINDING_2D:
6667 case GL_TEXTURE_BINDING_CUBE_MAP:
6668 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
6669 {
6670 *type = GL_INT;
6671 *numParams = 1;
6672 return true;
6673 }
6674 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6675 {
6676 if (!getExtensions().packReverseRowOrder)
6677 {
6678 return false;
6679 }
6680 *type = GL_INT;
6681 *numParams = 1;
6682 return true;
6683 }
6684 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
6685 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
6686 {
6687 if (!getExtensions().textureRectangle)
6688 {
6689 return false;
6690 }
6691 *type = GL_INT;
6692 *numParams = 1;
6693 return true;
6694 }
6695 case GL_MAX_DRAW_BUFFERS_EXT:
6696 case GL_MAX_COLOR_ATTACHMENTS_EXT:
6697 {
6698 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
6699 {
6700 return false;
6701 }
6702 *type = GL_INT;
6703 *numParams = 1;
6704 return true;
6705 }
6706 case GL_MAX_VIEWPORT_DIMS:
6707 {
6708 *type = GL_INT;
6709 *numParams = 2;
6710 return true;
6711 }
6712 case GL_VIEWPORT:
6713 case GL_SCISSOR_BOX:
6714 {
6715 *type = GL_INT;
6716 *numParams = 4;
6717 return true;
6718 }
6719 case GL_SHADER_COMPILER:
6720 case GL_SAMPLE_COVERAGE_INVERT:
6721 case GL_DEPTH_WRITEMASK:
6722 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
6723 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
6724 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
6725 // bool-natural
6726 case GL_SAMPLE_COVERAGE:
6727 case GL_SCISSOR_TEST:
6728 case GL_STENCIL_TEST:
6729 case GL_DEPTH_TEST:
6730 case GL_BLEND:
6731 case GL_DITHER:
6732 case GL_CONTEXT_ROBUST_ACCESS_EXT:
6733 {
6734 *type = GL_BOOL;
6735 *numParams = 1;
6736 return true;
6737 }
6738 case GL_COLOR_WRITEMASK:
6739 {
6740 *type = GL_BOOL;
6741 *numParams = 4;
6742 return true;
6743 }
6744 case GL_POLYGON_OFFSET_FACTOR:
6745 case GL_POLYGON_OFFSET_UNITS:
6746 case GL_SAMPLE_COVERAGE_VALUE:
6747 case GL_DEPTH_CLEAR_VALUE:
6748 case GL_LINE_WIDTH:
6749 {
6750 *type = GL_FLOAT;
6751 *numParams = 1;
6752 return true;
6753 }
6754 case GL_ALIASED_LINE_WIDTH_RANGE:
6755 case GL_ALIASED_POINT_SIZE_RANGE:
6756 case GL_DEPTH_RANGE:
6757 {
6758 *type = GL_FLOAT;
6759 *numParams = 2;
6760 return true;
6761 }
6762 case GL_COLOR_CLEAR_VALUE:
6763 case GL_BLEND_COLOR:
6764 {
6765 *type = GL_FLOAT;
6766 *numParams = 4;
6767 return true;
6768 }
6769 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
6770 if (!getExtensions().textureFilterAnisotropic)
6771 {
6772 return false;
6773 }
6774 *type = GL_FLOAT;
6775 *numParams = 1;
6776 return true;
6777 case GL_TIMESTAMP_EXT:
6778 if (!getExtensions().disjointTimerQuery)
6779 {
6780 return false;
6781 }
6782 *type = GL_INT_64_ANGLEX;
6783 *numParams = 1;
6784 return true;
6785 case GL_GPU_DISJOINT_EXT:
6786 if (!getExtensions().disjointTimerQuery)
6787 {
6788 return false;
6789 }
6790 *type = GL_INT;
6791 *numParams = 1;
6792 return true;
6793 case GL_COVERAGE_MODULATION_CHROMIUM:
6794 if (!getExtensions().framebufferMixedSamples)
6795 {
6796 return false;
6797 }
6798 *type = GL_INT;
6799 *numParams = 1;
6800 return true;
6801 case GL_TEXTURE_BINDING_EXTERNAL_OES:
6802 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
6803 {
6804 return false;
6805 }
6806 *type = GL_INT;
6807 *numParams = 1;
6808 return true;
6809 }
6810
6811 if (getExtensions().debug)
6812 {
6813 switch (pname)
6814 {
6815 case GL_DEBUG_LOGGED_MESSAGES:
6816 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
6817 case GL_DEBUG_GROUP_STACK_DEPTH:
6818 case GL_MAX_DEBUG_MESSAGE_LENGTH:
6819 case GL_MAX_DEBUG_LOGGED_MESSAGES:
6820 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
6821 case GL_MAX_LABEL_LENGTH:
6822 *type = GL_INT;
6823 *numParams = 1;
6824 return true;
6825
6826 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
6827 case GL_DEBUG_OUTPUT:
6828 *type = GL_BOOL;
6829 *numParams = 1;
6830 return true;
6831 }
6832 }
6833
6834 if (getExtensions().multisampleCompatibility)
6835 {
6836 switch (pname)
6837 {
6838 case GL_MULTISAMPLE_EXT:
6839 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
6840 *type = GL_BOOL;
6841 *numParams = 1;
6842 return true;
6843 }
6844 }
6845
6846 if (getExtensions().pathRendering)
6847 {
6848 switch (pname)
6849 {
6850 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
6851 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
6852 *type = GL_FLOAT;
6853 *numParams = 16;
6854 return true;
6855 }
6856 }
6857
6858 if (getExtensions().bindGeneratesResource)
6859 {
6860 switch (pname)
6861 {
6862 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
6863 *type = GL_BOOL;
6864 *numParams = 1;
6865 return true;
6866 }
6867 }
6868
6869 if (getExtensions().clientArrays)
6870 {
6871 switch (pname)
6872 {
6873 case GL_CLIENT_ARRAYS_ANGLE:
6874 *type = GL_BOOL;
6875 *numParams = 1;
6876 return true;
6877 }
6878 }
6879
6880 if (getExtensions().sRGBWriteControl)
6881 {
6882 switch (pname)
6883 {
6884 case GL_FRAMEBUFFER_SRGB_EXT:
6885 *type = GL_BOOL;
6886 *numParams = 1;
6887 return true;
6888 }
6889 }
6890
6891 if (getExtensions().robustResourceInitialization &&
6892 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
6893 {
6894 *type = GL_BOOL;
6895 *numParams = 1;
6896 return true;
6897 }
6898
6899 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
6900 {
6901 *type = GL_BOOL;
6902 *numParams = 1;
6903 return true;
6904 }
6905
6906 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
6907 switch (pname)
6908 {
6909 // case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE // equivalent to FRAMEBUFFER_BINDING
6910 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
6911 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
6912 {
6913 return false;
6914 }
6915 *type = GL_INT;
6916 *numParams = 1;
6917 return true;
6918
6919 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
6920 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
6921 {
6922 return false;
6923 }
6924 *type = GL_INT;
6925 *numParams = 1;
6926 return true;
6927
6928 case GL_PROGRAM_BINARY_FORMATS_OES:
6929 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
6930 {
6931 return false;
6932 }
6933 *type = GL_INT;
6934 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
6935 return true;
6936
6937 case GL_PACK_ROW_LENGTH:
6938 case GL_PACK_SKIP_ROWS:
6939 case GL_PACK_SKIP_PIXELS:
6940 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
6941 {
6942 return false;
6943 }
6944 *type = GL_INT;
6945 *numParams = 1;
6946 return true;
6947 case GL_UNPACK_ROW_LENGTH:
6948 case GL_UNPACK_SKIP_ROWS:
6949 case GL_UNPACK_SKIP_PIXELS:
6950 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
6951 {
6952 return false;
6953 }
6954 *type = GL_INT;
6955 *numParams = 1;
6956 return true;
6957 case GL_VERTEX_ARRAY_BINDING:
6958 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
6959 {
6960 return false;
6961 }
6962 *type = GL_INT;
6963 *numParams = 1;
6964 return true;
6965 case GL_PIXEL_PACK_BUFFER_BINDING:
6966 case GL_PIXEL_UNPACK_BUFFER_BINDING:
6967 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
6968 {
6969 return false;
6970 }
6971 *type = GL_INT;
6972 *numParams = 1;
6973 return true;
6974 case GL_MAX_SAMPLES:
6975 {
6976 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
6977 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
6978 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
6979 {
6980 return false;
6981 }
6982 *type = GL_INT;
6983 *numParams = 1;
6984 return true;
6985
6986 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
6987 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
6988 {
6989 return false;
6990 }
6991 *type = GL_INT;
6992 *numParams = 1;
6993 return true;
6994 }
6995 }
6996
6997 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
6998 {
6999 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
7000 {
7001 return false;
7002 }
7003 *type = GL_INT;
7004 *numParams = 1;
7005 return true;
7006 }
7007
7008 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
7009 {
7010 *type = GL_INT;
7011 *numParams = 1;
7012 return true;
7013 }
7014
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007015 if (getClientVersion() < Version(2, 0))
7016 {
7017 switch (pname)
7018 {
7019 case GL_ALPHA_TEST_FUNC:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007020 case GL_CLIENT_ACTIVE_TEXTURE:
7021 case GL_MATRIX_MODE:
7022 case GL_MAX_TEXTURE_UNITS:
7023 case GL_MAX_MODELVIEW_STACK_DEPTH:
7024 case GL_MAX_PROJECTION_STACK_DEPTH:
7025 case GL_MAX_TEXTURE_STACK_DEPTH:
Lingfeng Yangabb09f12018-04-16 10:43:53 -07007026 case GL_VERTEX_ARRAY_STRIDE:
7027 case GL_NORMAL_ARRAY_STRIDE:
7028 case GL_COLOR_ARRAY_STRIDE:
7029 case GL_TEXTURE_COORD_ARRAY_STRIDE:
7030 case GL_VERTEX_ARRAY_SIZE:
7031 case GL_COLOR_ARRAY_SIZE:
7032 case GL_TEXTURE_COORD_ARRAY_SIZE:
7033 case GL_VERTEX_ARRAY_TYPE:
7034 case GL_NORMAL_ARRAY_TYPE:
7035 case GL_COLOR_ARRAY_TYPE:
7036 case GL_TEXTURE_COORD_ARRAY_TYPE:
7037 case GL_VERTEX_ARRAY_BUFFER_BINDING:
7038 case GL_NORMAL_ARRAY_BUFFER_BINDING:
7039 case GL_COLOR_ARRAY_BUFFER_BINDING:
7040 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
7041 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
7042 case GL_POINT_SIZE_ARRAY_TYPE_OES:
7043 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007044 *type = GL_INT;
7045 *numParams = 1;
7046 return true;
7047 case GL_ALPHA_TEST_REF:
7048 *type = GL_FLOAT;
7049 *numParams = 1;
7050 return true;
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007051 case GL_CURRENT_COLOR:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007052 case GL_CURRENT_TEXTURE_COORDS:
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007053 *type = GL_FLOAT;
7054 *numParams = 4;
7055 return true;
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007056 case GL_CURRENT_NORMAL:
7057 *type = GL_FLOAT;
7058 *numParams = 3;
7059 return true;
Lingfeng Yang3a41af62018-04-09 07:28:56 -07007060 case GL_MODELVIEW_MATRIX:
7061 case GL_PROJECTION_MATRIX:
7062 case GL_TEXTURE_MATRIX:
7063 *type = GL_FLOAT;
7064 *numParams = 16;
7065 return true;
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007066 }
7067 }
7068
Jamie Madill5b772312018-03-08 20:28:32 -05007069 if (getClientVersion() < Version(3, 0))
7070 {
7071 return false;
7072 }
7073
7074 // Check for ES3.0+ parameter names
7075 switch (pname)
7076 {
7077 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
7078 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
7079 case GL_UNIFORM_BUFFER_BINDING:
7080 case GL_TRANSFORM_FEEDBACK_BINDING:
7081 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7082 case GL_COPY_READ_BUFFER_BINDING:
7083 case GL_COPY_WRITE_BUFFER_BINDING:
7084 case GL_SAMPLER_BINDING:
7085 case GL_READ_BUFFER:
7086 case GL_TEXTURE_BINDING_3D:
7087 case GL_TEXTURE_BINDING_2D_ARRAY:
7088 case GL_MAX_3D_TEXTURE_SIZE:
7089 case GL_MAX_ARRAY_TEXTURE_LAYERS:
7090 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
7091 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
7092 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
7093 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
7094 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
7095 case GL_MAX_VARYING_COMPONENTS:
7096 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
7097 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
7098 case GL_MIN_PROGRAM_TEXEL_OFFSET:
7099 case GL_MAX_PROGRAM_TEXEL_OFFSET:
7100 case GL_NUM_EXTENSIONS:
7101 case GL_MAJOR_VERSION:
7102 case GL_MINOR_VERSION:
7103 case GL_MAX_ELEMENTS_INDICES:
7104 case GL_MAX_ELEMENTS_VERTICES:
7105 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
7106 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
7107 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
7108 case GL_UNPACK_IMAGE_HEIGHT:
7109 case GL_UNPACK_SKIP_IMAGES:
7110 {
7111 *type = GL_INT;
7112 *numParams = 1;
7113 return true;
7114 }
7115
7116 case GL_MAX_ELEMENT_INDEX:
7117 case GL_MAX_UNIFORM_BLOCK_SIZE:
7118 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
7119 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
7120 case GL_MAX_SERVER_WAIT_TIMEOUT:
7121 {
7122 *type = GL_INT_64_ANGLEX;
7123 *numParams = 1;
7124 return true;
7125 }
7126
7127 case GL_TRANSFORM_FEEDBACK_ACTIVE:
7128 case GL_TRANSFORM_FEEDBACK_PAUSED:
7129 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
7130 case GL_RASTERIZER_DISCARD:
7131 {
7132 *type = GL_BOOL;
7133 *numParams = 1;
7134 return true;
7135 }
7136
7137 case GL_MAX_TEXTURE_LOD_BIAS:
7138 {
7139 *type = GL_FLOAT;
7140 *numParams = 1;
7141 return true;
7142 }
7143 }
7144
7145 if (getExtensions().requestExtension)
7146 {
7147 switch (pname)
7148 {
7149 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
7150 *type = GL_INT;
7151 *numParams = 1;
7152 return true;
7153 }
7154 }
7155
7156 if (getClientVersion() < Version(3, 1))
7157 {
7158 return false;
7159 }
7160
7161 switch (pname)
7162 {
7163 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7164 case GL_DRAW_INDIRECT_BUFFER_BINDING:
7165 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
7166 case GL_MAX_FRAMEBUFFER_WIDTH:
7167 case GL_MAX_FRAMEBUFFER_HEIGHT:
7168 case GL_MAX_FRAMEBUFFER_SAMPLES:
7169 case GL_MAX_SAMPLE_MASK_WORDS:
7170 case GL_MAX_COLOR_TEXTURE_SAMPLES:
7171 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
7172 case GL_MAX_INTEGER_SAMPLES:
7173 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
7174 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
7175 case GL_MAX_VERTEX_ATTRIB_STRIDE:
7176 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
7177 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
7178 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
7179 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
7180 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
7181 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
7182 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
7183 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
7184 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
7185 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
7186 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
7187 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
7188 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
7189 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
7190 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
7191 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
7192 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
7193 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
7194 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
7195 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
7196 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
7197 case GL_MAX_UNIFORM_LOCATIONS:
7198 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
7199 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
7200 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
7201 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
7202 case GL_MAX_IMAGE_UNITS:
7203 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
7204 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
7205 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
7206 case GL_SHADER_STORAGE_BUFFER_BINDING:
7207 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
7208 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
7209 *type = GL_INT;
7210 *numParams = 1;
7211 return true;
7212 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7213 *type = GL_INT_64_ANGLEX;
7214 *numParams = 1;
7215 return true;
7216 case GL_SAMPLE_MASK:
7217 *type = GL_BOOL;
7218 *numParams = 1;
7219 return true;
7220 }
7221
7222 if (getExtensions().geometryShader)
7223 {
7224 switch (pname)
7225 {
7226 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7227 case GL_LAYER_PROVOKING_VERTEX_EXT:
7228 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7229 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7230 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7231 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7232 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7233 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7234 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7235 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7236 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7237 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7238 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7239 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7240 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7241 *type = GL_INT;
7242 *numParams = 1;
7243 return true;
7244 }
7245 }
7246
7247 return false;
7248}
7249
7250bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7251{
7252 if (getClientVersion() < Version(3, 0))
7253 {
7254 return false;
7255 }
7256
7257 switch (target)
7258 {
7259 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7260 case GL_UNIFORM_BUFFER_BINDING:
7261 {
7262 *type = GL_INT;
7263 *numParams = 1;
7264 return true;
7265 }
7266 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7267 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7268 case GL_UNIFORM_BUFFER_START:
7269 case GL_UNIFORM_BUFFER_SIZE:
7270 {
7271 *type = GL_INT_64_ANGLEX;
7272 *numParams = 1;
7273 return true;
7274 }
7275 }
7276
7277 if (getClientVersion() < Version(3, 1))
7278 {
7279 return false;
7280 }
7281
7282 switch (target)
7283 {
7284 case GL_IMAGE_BINDING_LAYERED:
7285 {
7286 *type = GL_BOOL;
7287 *numParams = 1;
7288 return true;
7289 }
7290 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7291 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7292 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7293 case GL_SHADER_STORAGE_BUFFER_BINDING:
7294 case GL_VERTEX_BINDING_BUFFER:
7295 case GL_VERTEX_BINDING_DIVISOR:
7296 case GL_VERTEX_BINDING_OFFSET:
7297 case GL_VERTEX_BINDING_STRIDE:
7298 case GL_SAMPLE_MASK_VALUE:
7299 case GL_IMAGE_BINDING_NAME:
7300 case GL_IMAGE_BINDING_LEVEL:
7301 case GL_IMAGE_BINDING_LAYER:
7302 case GL_IMAGE_BINDING_ACCESS:
7303 case GL_IMAGE_BINDING_FORMAT:
7304 {
7305 *type = GL_INT;
7306 *numParams = 1;
7307 return true;
7308 }
7309 case GL_ATOMIC_COUNTER_BUFFER_START:
7310 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
7311 case GL_SHADER_STORAGE_BUFFER_START:
7312 case GL_SHADER_STORAGE_BUFFER_SIZE:
7313 {
7314 *type = GL_INT_64_ANGLEX;
7315 *numParams = 1;
7316 return true;
7317 }
7318 }
7319
7320 return false;
7321}
7322
7323Program *Context::getProgram(GLuint handle) const
7324{
7325 return mState.mShaderPrograms->getProgram(handle);
7326}
7327
7328Shader *Context::getShader(GLuint handle) const
7329{
7330 return mState.mShaderPrograms->getShader(handle);
7331}
7332
7333bool Context::isTextureGenerated(GLuint texture) const
7334{
7335 return mState.mTextures->isHandleGenerated(texture);
7336}
7337
7338bool Context::isBufferGenerated(GLuint buffer) const
7339{
7340 return mState.mBuffers->isHandleGenerated(buffer);
7341}
7342
7343bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
7344{
7345 return mState.mRenderbuffers->isHandleGenerated(renderbuffer);
7346}
7347
7348bool Context::isFramebufferGenerated(GLuint framebuffer) const
7349{
7350 return mState.mFramebuffers->isHandleGenerated(framebuffer);
7351}
7352
7353bool Context::isProgramPipelineGenerated(GLuint pipeline) const
7354{
7355 return mState.mPipelines->isHandleGenerated(pipeline);
7356}
7357
7358bool Context::usingDisplayTextureShareGroup() const
7359{
7360 return mDisplayTextureShareGroup;
7361}
7362
7363GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
7364{
7365 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
7366 internalformat == GL_DEPTH_STENCIL
7367 ? GL_DEPTH24_STENCIL8
7368 : internalformat;
7369}
7370
Jamie Madillc29968b2016-01-20 11:17:23 -05007371} // namespace gl