blob: f7ce94e79bdb593240bf1c799e0a0a05198b7fdc [file] [log] [blame]
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001//
Geoff Langeeba6e12014-02-03 13:12:30 -05002// Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7// Context.cpp: Implements the gl::Context class, managing all GL state and performing
8// rendering operations. It is the GLES2 specific implementation of EGLContext.
9
Geoff Lang2b5420c2014-11-19 14:20:15 -050010#include "libANGLE/Context.h"
apatrick@chromium.org144f2802012-07-12 01:42:34 +000011
Jamie Madill231c7f52017-04-26 13:45:37 -040012#include <string.h>
Jamie Madillb9293972015-02-19 11:07:54 -050013#include <iterator>
14#include <sstream>
Sami Väisänend59ca052016-06-21 16:10:00 +030015#include <vector>
Jamie Madillb9293972015-02-19 11:07:54 -050016
Sami Väisänene45e53b2016-05-25 10:36:04 +030017#include "common/matrix_utils.h"
Geoff Lang0b7eef72014-06-12 14:10:47 -040018#include "common/platform.h"
Jamie Madillb9293972015-02-19 11:07:54 -050019#include "common/utilities.h"
Geoff Langc339c4e2016-11-29 10:37:36 -050020#include "common/version.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050021#include "libANGLE/Buffer.h"
Jamie Madillb9293972015-02-19 11:07:54 -050022#include "libANGLE/Compiler.h"
Jamie Madill948bbe52017-06-01 13:10:42 -040023#include "libANGLE/Display.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050024#include "libANGLE/Fence.h"
25#include "libANGLE/Framebuffer.h"
26#include "libANGLE/FramebufferAttachment.h"
Sami Väisänene45e53b2016-05-25 10:36:04 +030027#include "libANGLE/Path.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050028#include "libANGLE/Program.h"
Yunchao Hea336b902017-08-02 16:05:21 +080029#include "libANGLE/ProgramPipeline.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050030#include "libANGLE/Query.h"
Jamie Madillb9293972015-02-19 11:07:54 -050031#include "libANGLE/Renderbuffer.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050032#include "libANGLE/ResourceManager.h"
33#include "libANGLE/Sampler.h"
Jamie Madill9dd0cf02014-11-24 11:38:51 -050034#include "libANGLE/Surface.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050035#include "libANGLE/Texture.h"
36#include "libANGLE/TransformFeedback.h"
37#include "libANGLE/VertexArray.h"
Kenneth Russellf2f6f652016-10-05 19:53:23 -070038#include "libANGLE/Workarounds.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040039#include "libANGLE/formatutils.h"
Martin Radev66fb8202016-07-28 11:45:20 +030040#include "libANGLE/queryconversions.h"
Geoff Langc1984ed2016-10-07 12:41:00 -040041#include "libANGLE/queryutils.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040042#include "libANGLE/renderer/ContextImpl.h"
43#include "libANGLE/renderer/EGLImplFactory.h"
Jamie Madill7b62cf92017-11-02 15:20:49 -040044#include "libANGLE/renderer/Format.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040045#include "libANGLE/validationES.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000046
Geoff Langf6db0982015-08-25 13:04:00 -040047namespace
48{
49
Jamie Madillb6664922017-07-25 12:55:04 -040050#define ANGLE_HANDLE_ERR(X) \
51 handleError(X); \
52 return;
53#define ANGLE_CONTEXT_TRY(EXPR) ANGLE_TRY_TEMPLATE(EXPR, ANGLE_HANDLE_ERR);
54
Ian Ewell3ffd78b2016-01-22 16:09:42 -050055template <typename T>
Geoff Lang4ddf5af2016-12-01 14:30:44 -050056std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager,
Sami Väisänend59ca052016-06-21 16:10:00 +030057 GLsizei numPaths,
58 const void *paths,
59 GLuint pathBase)
60{
61 std::vector<gl::Path *> ret;
62 ret.reserve(numPaths);
63
64 const auto *nameArray = static_cast<const T *>(paths);
65
66 for (GLsizei i = 0; i < numPaths; ++i)
67 {
68 const GLuint pathName = nameArray[i] + pathBase;
69
70 ret.push_back(resourceManager.getPath(pathName));
71 }
72
73 return ret;
74}
75
Geoff Lang4ddf5af2016-12-01 14:30:44 -050076std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager,
Sami Väisänend59ca052016-06-21 16:10:00 +030077 GLsizei numPaths,
78 GLenum pathNameType,
79 const void *paths,
80 GLuint pathBase)
81{
82 switch (pathNameType)
83 {
84 case GL_UNSIGNED_BYTE:
85 return GatherPaths<GLubyte>(resourceManager, numPaths, paths, pathBase);
86
87 case GL_BYTE:
88 return GatherPaths<GLbyte>(resourceManager, numPaths, paths, pathBase);
89
90 case GL_UNSIGNED_SHORT:
91 return GatherPaths<GLushort>(resourceManager, numPaths, paths, pathBase);
92
93 case GL_SHORT:
94 return GatherPaths<GLshort>(resourceManager, numPaths, paths, pathBase);
95
96 case GL_UNSIGNED_INT:
97 return GatherPaths<GLuint>(resourceManager, numPaths, paths, pathBase);
98
99 case GL_INT:
100 return GatherPaths<GLint>(resourceManager, numPaths, paths, pathBase);
101 }
102
103 UNREACHABLE();
104 return std::vector<gl::Path *>();
105}
106
107template <typename T>
Geoff Lang2186c382016-10-14 10:54:54 -0400108gl::Error GetQueryObjectParameter(gl::Query *query, GLenum pname, T *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500109{
Geoff Lang2186c382016-10-14 10:54:54 -0400110 ASSERT(query != nullptr);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500111
112 switch (pname)
113 {
114 case GL_QUERY_RESULT_EXT:
Geoff Lang2186c382016-10-14 10:54:54 -0400115 return query->getResult(params);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500116 case GL_QUERY_RESULT_AVAILABLE_EXT:
117 {
118 bool available;
Geoff Lang2186c382016-10-14 10:54:54 -0400119 gl::Error error = query->isResultAvailable(&available);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500120 if (!error.isError())
121 {
jchen10a99ed552017-09-22 08:10:32 +0800122 *params = gl::CastFromStateValue<T>(pname, static_cast<GLuint>(available));
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500123 }
124 return error;
125 }
126 default:
127 UNREACHABLE();
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500128 return gl::InternalError() << "Unreachable Error";
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500129 }
130}
131
Jamie Madill09463932018-04-04 05:26:59 -0400132void MarkTransformFeedbackBufferUsage(const gl::Context *context,
133 gl::TransformFeedback *transformFeedback,
James Darpinian30b604d2018-03-12 17:26:57 -0700134 GLsizei count,
135 GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -0400136{
Geoff Lang1a683462015-09-29 15:09:59 -0400137 if (transformFeedback && transformFeedback->isActive() && !transformFeedback->isPaused())
Geoff Langf6db0982015-08-25 13:04:00 -0400138 {
Jamie Madill09463932018-04-04 05:26:59 -0400139 transformFeedback->onVerticesDrawn(context, count, instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -0400140 }
141}
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500142
143// Attribute map queries.
Martin Radev1be913c2016-07-11 17:59:16 +0300144EGLint GetClientMajorVersion(const egl::AttributeMap &attribs)
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500145{
Ian Ewellec2c0c52016-04-05 13:46:26 -0400146 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_CLIENT_VERSION, 1));
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500147}
148
Martin Radev1be913c2016-07-11 17:59:16 +0300149EGLint GetClientMinorVersion(const egl::AttributeMap &attribs)
150{
151 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_MINOR_VERSION, 0));
152}
153
Geoff Langeb66a6e2016-10-31 13:06:12 -0400154gl::Version GetClientVersion(const egl::AttributeMap &attribs)
155{
156 return gl::Version(GetClientMajorVersion(attribs), GetClientMinorVersion(attribs));
157}
158
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500159GLenum GetResetStrategy(const egl::AttributeMap &attribs)
160{
Lingfeng Yangb27b03a2018-02-19 13:38:48 -0800161 EGLAttrib attrib =
162 attribs.get(EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT, EGL_NO_RESET_NOTIFICATION);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500163 switch (attrib)
164 {
165 case EGL_NO_RESET_NOTIFICATION:
166 return GL_NO_RESET_NOTIFICATION_EXT;
167 case EGL_LOSE_CONTEXT_ON_RESET:
168 return GL_LOSE_CONTEXT_ON_RESET_EXT;
169 default:
170 UNREACHABLE();
171 return GL_NONE;
172 }
173}
174
175bool GetRobustAccess(const egl::AttributeMap &attribs)
176{
Geoff Lang077f20a2016-11-01 10:08:02 -0400177 return (attribs.get(EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT, EGL_FALSE) == EGL_TRUE) ||
178 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR) !=
179 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500180}
181
182bool GetDebug(const egl::AttributeMap &attribs)
183{
Geoff Lang077f20a2016-11-01 10:08:02 -0400184 return (attribs.get(EGL_CONTEXT_OPENGL_DEBUG, EGL_FALSE) == EGL_TRUE) ||
185 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR) != 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500186}
187
188bool GetNoError(const egl::AttributeMap &attribs)
189{
190 return (attribs.get(EGL_CONTEXT_OPENGL_NO_ERROR_KHR, EGL_FALSE) == EGL_TRUE);
191}
192
Geoff Langc287ea62016-09-16 14:46:51 -0400193bool GetWebGLContext(const egl::AttributeMap &attribs)
194{
195 return (attribs.get(EGL_CONTEXT_WEBGL_COMPATIBILITY_ANGLE, EGL_FALSE) == EGL_TRUE);
196}
197
Geoff Lang0ab41fa2018-03-14 11:03:30 -0400198bool GetExtensionsEnabled(const egl::AttributeMap &attribs, bool webGLContext)
199{
200 // If the context is WebGL, extensions are disabled by default
201 EGLAttrib defaultValue = webGLContext ? EGL_FALSE : EGL_TRUE;
202 return (attribs.get(EGL_EXTENSIONS_ENABLED_ANGLE, defaultValue) == EGL_TRUE);
203}
204
Geoff Langf41a7152016-09-19 15:11:17 -0400205bool GetBindGeneratesResource(const egl::AttributeMap &attribs)
206{
207 return (attribs.get(EGL_CONTEXT_BIND_GENERATES_RESOURCE_CHROMIUM, EGL_TRUE) == EGL_TRUE);
208}
209
Geoff Langfeb8c682017-02-13 16:07:35 -0500210bool GetClientArraysEnabled(const egl::AttributeMap &attribs)
211{
212 return (attribs.get(EGL_CONTEXT_CLIENT_ARRAYS_ENABLED_ANGLE, EGL_TRUE) == EGL_TRUE);
213}
214
Geoff Langb433e872017-10-05 14:01:47 -0400215bool GetRobustResourceInit(const egl::AttributeMap &attribs)
216{
217 return (attribs.get(EGL_ROBUST_RESOURCE_INITIALIZATION_ANGLE, EGL_FALSE) == EGL_TRUE);
218}
219
Martin Radev9d901792016-07-15 15:58:58 +0300220std::string GetObjectLabelFromPointer(GLsizei length, const GLchar *label)
221{
222 std::string labelName;
223 if (label != nullptr)
224 {
225 size_t labelLength = length < 0 ? strlen(label) : length;
226 labelName = std::string(label, labelLength);
227 }
228 return labelName;
229}
230
231void GetObjectLabelBase(const std::string &objectLabel,
232 GLsizei bufSize,
233 GLsizei *length,
234 GLchar *label)
235{
236 size_t writeLength = objectLabel.length();
237 if (label != nullptr && bufSize > 0)
238 {
239 writeLength = std::min(static_cast<size_t>(bufSize) - 1, objectLabel.length());
240 std::copy(objectLabel.begin(), objectLabel.begin() + writeLength, label);
241 label[writeLength] = '\0';
242 }
243
244 if (length != nullptr)
245 {
246 *length = static_cast<GLsizei>(writeLength);
247 }
248}
249
Jamie Madill0f80ed82017-09-19 00:24:56 -0400250template <typename CapT, typename MaxT>
251void LimitCap(CapT *cap, MaxT maximum)
252{
253 *cap = std::min(*cap, static_cast<CapT>(maximum));
254}
255
Geoff Langf6db0982015-08-25 13:04:00 -0400256} // anonymous namespace
257
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000258namespace gl
259{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +0000260
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400261Context::Context(rx::EGLImplFactory *implFactory,
262 const egl::Config *config,
Corentin Wallez51706ea2015-08-07 14:39:22 -0400263 const Context *shareContext,
Geoff Langce02f082017-02-06 16:46:21 -0500264 TextureManager *shareTextures,
Jamie Madill32447362017-06-28 14:53:52 -0400265 MemoryProgramCache *memoryProgramCache,
Corentin Wallezc295e512017-01-27 17:47:50 -0500266 const egl::AttributeMap &attribs,
Geoff Langb433e872017-10-05 14:01:47 -0400267 const egl::DisplayExtensions &displayExtensions)
Jamie Madill5b772312018-03-08 20:28:32 -0500268 : mState(reinterpret_cast<ContextID>(this),
269 shareContext ? &shareContext->mState : nullptr,
270 shareTextures,
271 GetClientVersion(attribs),
272 &mGLState,
273 mCaps,
274 mTextureCaps,
275 mExtensions,
276 mLimitations),
277 mSkipValidation(GetNoError(attribs)),
278 mDisplayTextureShareGroup(shareTextures != nullptr),
279 mSavedArgsType(nullptr),
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700280 mImplementation(implFactory->createContext(mState)),
Jamie Madill2f348d22017-06-05 10:50:59 -0400281 mCompiler(),
Corentin Walleze3b10e82015-05-20 11:06:25 -0400282 mConfig(config),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500283 mClientType(EGL_OPENGL_ES_API),
284 mHasBeenCurrent(false),
285 mContextLost(false),
286 mResetStatus(GL_NO_ERROR),
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700287 mContextLostForced(false),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500288 mResetStrategy(GetResetStrategy(attribs)),
289 mRobustAccess(GetRobustAccess(attribs)),
Jamie Madill61e16b42017-06-19 11:13:23 -0400290 mCurrentSurface(static_cast<egl::Surface *>(EGL_NO_SURFACE)),
291 mCurrentDisplay(static_cast<egl::Display *>(EGL_NO_DISPLAY)),
Jamie Madill4e0e6f82017-02-17 11:06:03 -0500292 mSurfacelessFramebuffer(nullptr),
Jamie Madille14951e2017-03-09 18:55:16 -0500293 mWebGLContext(GetWebGLContext(attribs)),
Geoff Lang0ab41fa2018-03-14 11:03:30 -0400294 mExtensionsEnabled(GetExtensionsEnabled(attribs, mWebGLContext)),
Jamie Madill32447362017-06-28 14:53:52 -0400295 mMemoryProgramCache(memoryProgramCache),
Jamie Madillb3f26b92017-07-19 15:07:41 -0400296 mScratchBuffer(1000u),
297 mZeroFilledBuffer(1000u)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000298{
Jamie Madill5b772312018-03-08 20:28:32 -0500299 // Needed to solve a Clang warning of unused variables.
300 UNUSED_VARIABLE(mSavedArgsType);
301 UNUSED_VARIABLE(mParamsBuffer);
302
Jamie Madill14bbb3f2017-09-12 15:23:01 -0400303 mImplementation->setMemoryProgramCache(memoryProgramCache);
304
Geoff Langb433e872017-10-05 14:01:47 -0400305 bool robustResourceInit = GetRobustResourceInit(attribs);
306 initCaps(displayExtensions, robustResourceInit);
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700307 initWorkarounds();
Geoff Langc0b9ef42014-07-02 10:02:37 -0400308
Jamie Madill4928b7c2017-06-20 12:57:39 -0400309 mGLState.initialize(this, GetDebug(attribs), GetBindGeneratesResource(attribs),
Jamie Madillc43be722017-07-13 16:22:14 -0400310 GetClientArraysEnabled(attribs), robustResourceInit,
311 mMemoryProgramCache != nullptr);
Régis Fénéon83107972015-02-05 12:57:44 +0100312
Shannon Woods53a94a82014-06-24 15:20:36 -0400313 mFenceNVHandleAllocator.setBaseHandle(0);
Geoff Lang7dca1862013-07-30 16:30:46 -0400314
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000315 // [OpenGL ES 2.0.24] section 3.7 page 83:
Corentin Wallez336129f2017-10-17 15:55:40 -0400316 // In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have two-dimensional
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000317 // and cube map texture state vectors respectively associated with them.
318 // In order that access to these initial textures not be lost, they are treated as texture
319 // objects all of whose names are 0.
320
Corentin Wallez99d492c2018-02-27 15:17:10 -0500321 Texture *zeroTexture2D = new Texture(mImplementation.get(), 0, TextureType::_2D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800322 mZeroTextures[TextureType::_2D].set(this, zeroTexture2D);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500323
Corentin Wallez99d492c2018-02-27 15:17:10 -0500324 Texture *zeroTextureCube = new Texture(mImplementation.get(), 0, TextureType::CubeMap);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800325 mZeroTextures[TextureType::CubeMap].set(this, zeroTextureCube);
Geoff Lang76b10c92014-09-05 16:28:14 -0400326
Geoff Langeb66a6e2016-10-31 13:06:12 -0400327 if (getClientVersion() >= Version(3, 0))
Geoff Lang76b10c92014-09-05 16:28:14 -0400328 {
329 // TODO: These could also be enabled via extension
Corentin Wallez99d492c2018-02-27 15:17:10 -0500330 Texture *zeroTexture3D = new Texture(mImplementation.get(), 0, TextureType::_3D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800331 mZeroTextures[TextureType::_3D].set(this, zeroTexture3D);
Geoff Lang76b10c92014-09-05 16:28:14 -0400332
Corentin Wallez99d492c2018-02-27 15:17:10 -0500333 Texture *zeroTexture2DArray = new Texture(mImplementation.get(), 0, TextureType::_2DArray);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800334 mZeroTextures[TextureType::_2DArray].set(this, zeroTexture2DArray);
Geoff Lang76b10c92014-09-05 16:28:14 -0400335 }
Geoff Lang3b573612016-10-31 14:08:10 -0400336 if (getClientVersion() >= Version(3, 1))
337 {
338 Texture *zeroTexture2DMultisample =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500339 new Texture(mImplementation.get(), 0, TextureType::_2DMultisample);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800340 mZeroTextures[TextureType::_2DMultisample].set(this, zeroTexture2DMultisample);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800341
Jiajia Qin6eafb042016-12-27 17:04:07 +0800342 for (unsigned int i = 0; i < mCaps.maxAtomicCounterBufferBindings; i++)
343 {
Qin Jiajia339f65b2018-02-27 12:52:48 +0800344 bindBufferRange(BufferBinding::AtomicCounter, i, 0, 0, 0);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800345 }
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800346
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800347 for (unsigned int i = 0; i < mCaps.maxShaderStorageBufferBindings; i++)
348 {
Corentin Wallez336129f2017-10-17 15:55:40 -0400349 bindBufferRange(BufferBinding::ShaderStorage, i, 0, 0, 0);
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800350 }
Geoff Lang3b573612016-10-31 14:08:10 -0400351 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000352
Geoff Lang4751aab2017-10-30 15:14:52 -0400353 const Extensions &nativeExtensions = mImplementation->getNativeExtensions();
354 if (nativeExtensions.textureRectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400355 {
356 Texture *zeroTextureRectangle =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500357 new Texture(mImplementation.get(), 0, TextureType::Rectangle);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800358 mZeroTextures[TextureType::Rectangle].set(this, zeroTextureRectangle);
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400359 }
360
Geoff Lang4751aab2017-10-30 15:14:52 -0400361 if (nativeExtensions.eglImageExternal || nativeExtensions.eglStreamConsumerExternal)
Ian Ewellbda75592016-04-18 17:25:54 -0400362 {
Corentin Wallez99d492c2018-02-27 15:17:10 -0500363 Texture *zeroTextureExternal = new Texture(mImplementation.get(), 0, TextureType::External);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800364 mZeroTextures[TextureType::External].set(this, zeroTextureExternal);
Ian Ewellbda75592016-04-18 17:25:54 -0400365 }
366
Jamie Madill4928b7c2017-06-20 12:57:39 -0400367 mGLState.initializeZeroTextures(this, mZeroTextures);
Jamie Madille6382c32014-11-07 15:05:26 -0500368
Jamie Madill57a89722013-07-02 11:57:03 -0400369 bindVertexArray(0);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000370
Geoff Langeb66a6e2016-10-31 13:06:12 -0400371 if (getClientVersion() >= Version(3, 0))
Geoff Lang1a683462015-09-29 15:09:59 -0400372 {
373 // [OpenGL ES 3.0.2] section 2.14.1 pg 85:
374 // In the initial state, a default transform feedback object is bound and treated as
375 // a transform feedback object with a name of zero. That object is bound any time
376 // BindTransformFeedback is called with id of zero
Jamie Madillf0dcb8b2017-08-26 19:05:13 -0400377 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Geoff Lang1a683462015-09-29 15:09:59 -0400378 }
Geoff Langc8058452014-02-03 12:04:11 -0500379
Corentin Wallez336129f2017-10-17 15:55:40 -0400380 for (auto type : angle::AllEnums<BufferBinding>())
381 {
382 bindBuffer(type, 0);
383 }
384
385 bindRenderbuffer(GL_RENDERBUFFER, 0);
386
387 for (unsigned int i = 0; i < mCaps.maxUniformBufferBindings; i++)
388 {
389 bindBufferRange(BufferBinding::Uniform, i, 0, 0, -1);
390 }
391
Jamie Madillad9f24e2016-02-12 09:27:24 -0500392 // Initialize dirty bit masks
Jamie Madillc67323a2017-11-02 23:11:41 -0400393 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500394 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500395 // No dirty objects.
396
397 // Readpixels uses the pack state and read FBO
Jamie Madillc67323a2017-11-02 23:11:41 -0400398 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500399 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500400 mReadPixelsDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
401
402 mClearDirtyBits.set(State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED);
403 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
404 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR);
405 mClearDirtyBits.set(State::DIRTY_BIT_VIEWPORT);
406 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_COLOR);
407 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_DEPTH);
408 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_STENCIL);
409 mClearDirtyBits.set(State::DIRTY_BIT_COLOR_MASK);
410 mClearDirtyBits.set(State::DIRTY_BIT_DEPTH_MASK);
411 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT);
412 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_BACK);
413 mClearDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
414
415 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
416 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR);
Geoff Lang1d2c41d2016-10-19 16:14:46 -0700417 mBlitDirtyBits.set(State::DIRTY_BIT_FRAMEBUFFER_SRGB);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500418 mBlitDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
419 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
Jamie Madill437fa652016-05-03 15:13:24 -0400420
Xinghua Cao10a4d432017-11-28 14:46:26 +0800421 // TODO(xinghua.cao@intel.com): add other dirty bits and dirty objects.
422 mComputeDirtyBits.set(State::DIRTY_BIT_SHADER_STORAGE_BUFFER_BINDING);
423 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_BINDING);
424 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_EXECUTABLE);
425 mComputeDirtyBits.set(State::DIRTY_BIT_TEXTURE_BINDINGS);
426 mComputeDirtyBits.set(State::DIRTY_BIT_SAMPLER_BINDINGS);
Qin Jiajia62fcf622017-11-30 16:16:12 +0800427 mComputeDirtyBits.set(State::DIRTY_BIT_DISPATCH_INDIRECT_BUFFER_BINDING);
Jiajia Qin5ae6ee42018-03-06 17:39:42 +0800428 mComputeDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM_TEXTURES);
Xinghua Cao10a4d432017-11-28 14:46:26 +0800429
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400430 handleError(mImplementation->initialize());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000431}
432
Jamie Madill4928b7c2017-06-20 12:57:39 -0400433egl::Error Context::onDestroy(const egl::Display *display)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000434{
Jamie Madille7b3fe22018-04-05 09:42:46 -0400435 // Delete the Surface first to trigger a finish() in Vulkan.
436 SafeDelete(mSurfacelessFramebuffer);
437
438 ANGLE_TRY(releaseSurface(display));
439
Corentin Wallez80b24112015-08-25 16:41:57 -0400440 for (auto fence : mFenceNVMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000441 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400442 SafeDelete(fence.second);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000443 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400444 mFenceNVMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000445
Corentin Wallez80b24112015-08-25 16:41:57 -0400446 for (auto query : mQueryMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000447 {
Geoff Langf0aa8422015-09-29 15:08:34 -0400448 if (query.second != nullptr)
449 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400450 query.second->release(this);
Geoff Langf0aa8422015-09-29 15:08:34 -0400451 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000452 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400453 mQueryMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000454
Corentin Wallez80b24112015-08-25 16:41:57 -0400455 for (auto vertexArray : mVertexArrayMap)
Jamie Madill57a89722013-07-02 11:57:03 -0400456 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400457 if (vertexArray.second)
458 {
459 vertexArray.second->onDestroy(this);
460 }
Jamie Madill57a89722013-07-02 11:57:03 -0400461 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400462 mVertexArrayMap.clear();
Jamie Madill57a89722013-07-02 11:57:03 -0400463
Corentin Wallez80b24112015-08-25 16:41:57 -0400464 for (auto transformFeedback : mTransformFeedbackMap)
Geoff Langc8058452014-02-03 12:04:11 -0500465 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500466 if (transformFeedback.second != nullptr)
467 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500468 transformFeedback.second->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500469 }
Geoff Langc8058452014-02-03 12:04:11 -0500470 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400471 mTransformFeedbackMap.clear();
Geoff Langc8058452014-02-03 12:04:11 -0500472
Jamie Madill5b772312018-03-08 20:28:32 -0500473 for (BindingPointer<Texture> &zeroTexture : mZeroTextures)
Geoff Lang76b10c92014-09-05 16:28:14 -0400474 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800475 if (zeroTexture.get() != nullptr)
476 {
477 ANGLE_TRY(zeroTexture->onDestroy(this));
478 zeroTexture.set(this, nullptr);
479 }
Geoff Lang76b10c92014-09-05 16:28:14 -0400480 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000481
Jamie Madill2f348d22017-06-05 10:50:59 -0400482 releaseShaderCompiler();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500483
Jamie Madill4928b7c2017-06-20 12:57:39 -0400484 mGLState.reset(this);
485
Jamie Madill6c1f6712017-02-14 19:08:04 -0500486 mState.mBuffers->release(this);
487 mState.mShaderPrograms->release(this);
488 mState.mTextures->release(this);
489 mState.mRenderbuffers->release(this);
490 mState.mSamplers->release(this);
Jamie Madill70b5bb02017-08-28 13:32:37 -0400491 mState.mSyncs->release(this);
Jamie Madill6c1f6712017-02-14 19:08:04 -0500492 mState.mPaths->release(this);
493 mState.mFramebuffers->release(this);
Yunchao Hea336b902017-08-02 16:05:21 +0800494 mState.mPipelines->release(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400495
Jamie Madill76e471e2017-10-21 09:56:01 -0400496 mImplementation->onDestroy(this);
497
Jamie Madill4928b7c2017-06-20 12:57:39 -0400498 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000499}
500
Jamie Madill70ee0f62017-02-06 16:04:20 -0500501Context::~Context()
502{
503}
504
Jamie Madill4928b7c2017-06-20 12:57:39 -0400505egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000506{
Jamie Madill61e16b42017-06-19 11:13:23 -0400507 mCurrentDisplay = display;
508
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000509 if (!mHasBeenCurrent)
510 {
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000511 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500512 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400513 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000514
Corentin Wallezc295e512017-01-27 17:47:50 -0500515 int width = 0;
516 int height = 0;
517 if (surface != nullptr)
518 {
519 width = surface->getWidth();
520 height = surface->getHeight();
521 }
522
523 mGLState.setViewportParams(0, 0, width, height);
524 mGLState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000525
526 mHasBeenCurrent = true;
527 }
528
Jamie Madill1b94d432015-08-07 13:23:23 -0400529 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700530 mGLState.setAllDirtyBits();
Jamie Madill81c2e252017-09-09 23:32:46 -0400531 mGLState.setAllDirtyObjects();
Jamie Madill1b94d432015-08-07 13:23:23 -0400532
Jamie Madill4928b7c2017-06-20 12:57:39 -0400533 ANGLE_TRY(releaseSurface(display));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500534
535 Framebuffer *newDefault = nullptr;
536 if (surface != nullptr)
537 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400538 ANGLE_TRY(surface->setIsCurrent(this, true));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500539 mCurrentSurface = surface;
540 newDefault = surface->getDefaultFramebuffer();
541 }
542 else
543 {
544 if (mSurfacelessFramebuffer == nullptr)
545 {
546 mSurfacelessFramebuffer = new Framebuffer(mImplementation.get());
547 }
548
549 newDefault = mSurfacelessFramebuffer;
550 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000551
Corentin Wallez37c39792015-08-20 14:19:46 -0400552 // Update default framebuffer, the binding of the previous default
553 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400554 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700555 if (mGLState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400556 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700557 mGLState.setReadFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400558 }
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700559 if (mGLState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400560 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700561 mGLState.setDrawFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400562 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500563 mState.mFramebuffers->setDefaultFramebuffer(newDefault);
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400564 }
Ian Ewell292f0052016-02-04 10:37:32 -0500565
566 // Notify the renderer of a context switch
Jamie Madill4928b7c2017-06-20 12:57:39 -0400567 mImplementation->onMakeCurrent(this);
568 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000569}
570
Jamie Madill4928b7c2017-06-20 12:57:39 -0400571egl::Error Context::releaseSurface(const egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400572{
Corentin Wallez37c39792015-08-20 14:19:46 -0400573 // Remove the default framebuffer
Corentin Wallezc295e512017-01-27 17:47:50 -0500574 Framebuffer *currentDefault = nullptr;
575 if (mCurrentSurface != nullptr)
Corentin Wallez51706ea2015-08-07 14:39:22 -0400576 {
Corentin Wallezc295e512017-01-27 17:47:50 -0500577 currentDefault = mCurrentSurface->getDefaultFramebuffer();
578 }
579 else if (mSurfacelessFramebuffer != nullptr)
580 {
581 currentDefault = mSurfacelessFramebuffer;
Corentin Wallez51706ea2015-08-07 14:39:22 -0400582 }
583
Corentin Wallezc295e512017-01-27 17:47:50 -0500584 if (mGLState.getReadFramebuffer() == currentDefault)
585 {
586 mGLState.setReadFramebufferBinding(nullptr);
587 }
588 if (mGLState.getDrawFramebuffer() == currentDefault)
589 {
590 mGLState.setDrawFramebufferBinding(nullptr);
591 }
592 mState.mFramebuffers->setDefaultFramebuffer(nullptr);
593
594 if (mCurrentSurface)
595 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400596 ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
Corentin Wallezc295e512017-01-27 17:47:50 -0500597 mCurrentSurface = nullptr;
598 }
Jamie Madill4928b7c2017-06-20 12:57:39 -0400599
600 return egl::NoError();
Jamie Madill77a72f62015-04-14 11:18:32 -0400601}
602
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000603GLuint Context::createBuffer()
604{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500605 return mState.mBuffers->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000606}
607
608GLuint Context::createProgram()
609{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500610 return mState.mShaderPrograms->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000611}
612
Jiawei Shao385b3e02018-03-21 09:43:28 +0800613GLuint Context::createShader(ShaderType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000614{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500615 return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000616}
617
618GLuint Context::createTexture()
619{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500620 return mState.mTextures->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000621}
622
623GLuint Context::createRenderbuffer()
624{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500625 return mState.mRenderbuffers->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000626}
627
Brandon Jones59770802018-04-02 13:18:42 -0700628GLuint Context::genPaths(GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300629{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500630 auto resultOrError = mState.mPaths->createPaths(mImplementation.get(), range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300631 if (resultOrError.isError())
632 {
633 handleError(resultOrError.getError());
634 return 0;
635 }
636 return resultOrError.getResult();
637}
638
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000639// Returns an unused framebuffer name
640GLuint Context::createFramebuffer()
641{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500642 return mState.mFramebuffers->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000643}
644
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500645void Context::genFencesNV(GLsizei n, GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000646{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500647 for (int i = 0; i < n; i++)
648 {
649 GLuint handle = mFenceNVHandleAllocator.allocate();
650 mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV()));
651 fences[i] = handle;
652 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000653}
654
Yunchao Hea336b902017-08-02 16:05:21 +0800655GLuint Context::createProgramPipeline()
656{
657 return mState.mPipelines->createProgramPipeline();
658}
659
Jiawei Shao385b3e02018-03-21 09:43:28 +0800660GLuint Context::createShaderProgramv(ShaderType type, GLsizei count, const GLchar *const *strings)
Jiajia Qin5451d532017-11-16 17:16:34 +0800661{
662 UNIMPLEMENTED();
663 return 0u;
664}
665
James Darpinian4d9d4832018-03-13 12:43:28 -0700666void Context::deleteBuffer(GLuint bufferName)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000667{
James Darpinian4d9d4832018-03-13 12:43:28 -0700668 Buffer *buffer = mState.mBuffers->getBuffer(bufferName);
669 if (buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000670 {
671 detachBuffer(buffer);
672 }
Jamie Madill893ab082014-05-16 16:56:10 -0400673
James Darpinian4d9d4832018-03-13 12:43:28 -0700674 mState.mBuffers->deleteObject(this, bufferName);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000675}
676
677void Context::deleteShader(GLuint shader)
678{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500679 mState.mShaderPrograms->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000680}
681
682void Context::deleteProgram(GLuint program)
683{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500684 mState.mShaderPrograms->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000685}
686
687void Context::deleteTexture(GLuint texture)
688{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500689 if (mState.mTextures->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000690 {
691 detachTexture(texture);
692 }
693
Jamie Madill6c1f6712017-02-14 19:08:04 -0500694 mState.mTextures->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000695}
696
697void Context::deleteRenderbuffer(GLuint renderbuffer)
698{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500699 if (mState.mRenderbuffers->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000700 {
701 detachRenderbuffer(renderbuffer);
702 }
Jamie Madill893ab082014-05-16 16:56:10 -0400703
Jamie Madill6c1f6712017-02-14 19:08:04 -0500704 mState.mRenderbuffers->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000705}
706
Jamie Madill7f0c5a42017-08-26 22:43:26 -0400707void Context::deleteSync(GLsync sync)
Jamie Madillcd055f82013-07-26 11:55:15 -0400708{
709 // The spec specifies the underlying Fence object is not deleted until all current
710 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
711 // and since our API is currently designed for being called from a single thread, we can delete
712 // the fence immediately.
Jamie Madill70b5bb02017-08-28 13:32:37 -0400713 mState.mSyncs->deleteObject(this, static_cast<GLuint>(reinterpret_cast<uintptr_t>(sync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400714}
715
Yunchao Hea336b902017-08-02 16:05:21 +0800716void Context::deleteProgramPipeline(GLuint pipeline)
717{
718 if (mState.mPipelines->getProgramPipeline(pipeline))
719 {
720 detachProgramPipeline(pipeline);
721 }
722
723 mState.mPipelines->deleteObject(this, pipeline);
724}
725
Sami Väisänene45e53b2016-05-25 10:36:04 +0300726void Context::deletePaths(GLuint first, GLsizei range)
727{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500728 mState.mPaths->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300729}
730
Brandon Jones59770802018-04-02 13:18:42 -0700731bool Context::isPath(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300732{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500733 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300734 if (pathObj == nullptr)
735 return false;
736
737 return pathObj->hasPathData();
738}
739
Brandon Jones59770802018-04-02 13:18:42 -0700740bool Context::isPathGenerated(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300741{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500742 return mState.mPaths->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300743}
744
Brandon Jones59770802018-04-02 13:18:42 -0700745void Context::pathCommands(GLuint path,
746 GLsizei numCommands,
747 const GLubyte *commands,
748 GLsizei numCoords,
749 GLenum coordType,
750 const void *coords)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300751{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500752 auto *pathObject = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300753
754 handleError(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
755}
756
Jamie Madill007530e2017-12-28 14:27:04 -0500757void Context::pathParameterf(GLuint path, GLenum pname, GLfloat value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300758{
Jamie Madill007530e2017-12-28 14:27:04 -0500759 Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300760
761 switch (pname)
762 {
763 case GL_PATH_STROKE_WIDTH_CHROMIUM:
764 pathObj->setStrokeWidth(value);
765 break;
766 case GL_PATH_END_CAPS_CHROMIUM:
767 pathObj->setEndCaps(static_cast<GLenum>(value));
768 break;
769 case GL_PATH_JOIN_STYLE_CHROMIUM:
770 pathObj->setJoinStyle(static_cast<GLenum>(value));
771 break;
772 case GL_PATH_MITER_LIMIT_CHROMIUM:
773 pathObj->setMiterLimit(value);
774 break;
775 case GL_PATH_STROKE_BOUND_CHROMIUM:
776 pathObj->setStrokeBound(value);
777 break;
778 default:
779 UNREACHABLE();
780 break;
781 }
782}
783
Jamie Madill007530e2017-12-28 14:27:04 -0500784void Context::pathParameteri(GLuint path, GLenum pname, GLint value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300785{
Jamie Madill007530e2017-12-28 14:27:04 -0500786 // TODO(jmadill): Should use proper clamping/casting.
787 pathParameterf(path, pname, static_cast<GLfloat>(value));
788}
789
790void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value)
791{
792 const Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300793
794 switch (pname)
795 {
796 case GL_PATH_STROKE_WIDTH_CHROMIUM:
797 *value = pathObj->getStrokeWidth();
798 break;
799 case GL_PATH_END_CAPS_CHROMIUM:
800 *value = static_cast<GLfloat>(pathObj->getEndCaps());
801 break;
802 case GL_PATH_JOIN_STYLE_CHROMIUM:
803 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
804 break;
805 case GL_PATH_MITER_LIMIT_CHROMIUM:
806 *value = pathObj->getMiterLimit();
807 break;
808 case GL_PATH_STROKE_BOUND_CHROMIUM:
809 *value = pathObj->getStrokeBound();
810 break;
811 default:
812 UNREACHABLE();
813 break;
814 }
815}
816
Jamie Madill007530e2017-12-28 14:27:04 -0500817void Context::getPathParameteriv(GLuint path, GLenum pname, GLint *value)
818{
819 GLfloat val = 0.0f;
820 getPathParameterfv(path, pname, value != nullptr ? &val : nullptr);
821 if (value)
822 *value = static_cast<GLint>(val);
823}
824
Brandon Jones59770802018-04-02 13:18:42 -0700825void Context::pathStencilFunc(GLenum func, GLint ref, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300826{
827 mGLState.setPathStencilFunc(func, ref, mask);
828}
829
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000830void Context::deleteFramebuffer(GLuint framebuffer)
831{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500832 if (mState.mFramebuffers->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000833 {
834 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000835 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500836
Jamie Madill6c1f6712017-02-14 19:08:04 -0500837 mState.mFramebuffers->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000838}
839
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500840void Context::deleteFencesNV(GLsizei n, const GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000841{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500842 for (int i = 0; i < n; i++)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000843 {
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500844 GLuint fence = fences[i];
845
846 FenceNV *fenceObject = nullptr;
847 if (mFenceNVMap.erase(fence, &fenceObject))
848 {
849 mFenceNVHandleAllocator.release(fence);
850 delete fenceObject;
851 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000852 }
853}
854
Geoff Lang70d0f492015-12-10 17:45:46 -0500855Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000856{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500857 return mState.mBuffers->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000858}
859
Jamie Madill570f7c82014-07-03 10:38:54 -0400860Texture *Context::getTexture(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000861{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500862 return mState.mTextures->getTexture(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000863}
864
Geoff Lang70d0f492015-12-10 17:45:46 -0500865Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000866{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500867 return mState.mRenderbuffers->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000868}
869
Jamie Madill70b5bb02017-08-28 13:32:37 -0400870Sync *Context::getSync(GLsync handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400871{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400872 return mState.mSyncs->getSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400873}
874
Jamie Madill57a89722013-07-02 11:57:03 -0400875VertexArray *Context::getVertexArray(GLuint handle) const
876{
Jamie Madill96a483b2017-06-27 16:49:21 -0400877 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -0400878}
879
Jamie Madilldc356042013-07-19 16:36:57 -0400880Sampler *Context::getSampler(GLuint handle) const
881{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500882 return mState.mSamplers->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400883}
884
Geoff Langc8058452014-02-03 12:04:11 -0500885TransformFeedback *Context::getTransformFeedback(GLuint handle) const
886{
Jamie Madill96a483b2017-06-27 16:49:21 -0400887 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -0500888}
889
Yunchao Hea336b902017-08-02 16:05:21 +0800890ProgramPipeline *Context::getProgramPipeline(GLuint handle) const
891{
892 return mState.mPipelines->getProgramPipeline(handle);
893}
894
Geoff Lang70d0f492015-12-10 17:45:46 -0500895LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
896{
897 switch (identifier)
898 {
899 case GL_BUFFER:
900 return getBuffer(name);
901 case GL_SHADER:
902 return getShader(name);
903 case GL_PROGRAM:
904 return getProgram(name);
905 case GL_VERTEX_ARRAY:
906 return getVertexArray(name);
907 case GL_QUERY:
908 return getQuery(name);
909 case GL_TRANSFORM_FEEDBACK:
910 return getTransformFeedback(name);
911 case GL_SAMPLER:
912 return getSampler(name);
913 case GL_TEXTURE:
914 return getTexture(name);
915 case GL_RENDERBUFFER:
916 return getRenderbuffer(name);
917 case GL_FRAMEBUFFER:
918 return getFramebuffer(name);
919 default:
920 UNREACHABLE();
921 return nullptr;
922 }
923}
924
925LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
926{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400927 return getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
Geoff Lang70d0f492015-12-10 17:45:46 -0500928}
929
Martin Radev9d901792016-07-15 15:58:58 +0300930void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
931{
932 LabeledObject *object = getLabeledObject(identifier, name);
933 ASSERT(object != nullptr);
934
935 std::string labelName = GetObjectLabelFromPointer(length, label);
936 object->setLabel(labelName);
Jamie Madill8693bdb2017-09-02 15:32:14 -0400937
938 // TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the
939 // specified object is active until we do this.
940 mGLState.setObjectDirty(identifier);
Martin Radev9d901792016-07-15 15:58:58 +0300941}
942
943void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
944{
945 LabeledObject *object = getLabeledObjectFromPtr(ptr);
946 ASSERT(object != nullptr);
947
948 std::string labelName = GetObjectLabelFromPointer(length, label);
949 object->setLabel(labelName);
950}
951
952void Context::getObjectLabel(GLenum identifier,
953 GLuint name,
954 GLsizei bufSize,
955 GLsizei *length,
956 GLchar *label) const
957{
958 LabeledObject *object = getLabeledObject(identifier, name);
959 ASSERT(object != nullptr);
960
961 const std::string &objectLabel = object->getLabel();
962 GetObjectLabelBase(objectLabel, bufSize, length, label);
963}
964
965void Context::getObjectPtrLabel(const void *ptr,
966 GLsizei bufSize,
967 GLsizei *length,
968 GLchar *label) const
969{
970 LabeledObject *object = getLabeledObjectFromPtr(ptr);
971 ASSERT(object != nullptr);
972
973 const std::string &objectLabel = object->getLabel();
974 GetObjectLabelBase(objectLabel, bufSize, length, label);
975}
976
Jamie Madilldc356042013-07-19 16:36:57 -0400977bool Context::isSampler(GLuint samplerName) const
978{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500979 return mState.mSamplers->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -0400980}
981
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800982void Context::bindTexture(TextureType target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000983{
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500984 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000985
Jamie Madilldedd7b92014-11-05 16:30:36 -0500986 if (handle == 0)
987 {
988 texture = mZeroTextures[target].get();
989 }
990 else
991 {
Corentin Wallez99d492c2018-02-27 15:17:10 -0500992 texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500993 }
994
995 ASSERT(texture);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400996 mGLState.setSamplerTexture(this, target, texture);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +0000997}
998
Jamie Madill5bf9ff42016-02-01 11:13:03 -0500999void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001000{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001001 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1002 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001003 mGLState.setReadFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001004}
1005
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001006void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001007{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001008 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1009 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001010 mGLState.setDrawFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001011}
1012
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001013void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -04001014{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001015 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001016 mGLState.setVertexArrayBinding(vertexArray);
Jamie Madill57a89722013-07-02 11:57:03 -04001017}
1018
Shao80957d92017-02-20 21:25:59 +08001019void Context::bindVertexBuffer(GLuint bindingIndex,
1020 GLuint bufferHandle,
1021 GLintptr offset,
1022 GLsizei stride)
1023{
1024 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001025 mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Shao80957d92017-02-20 21:25:59 +08001026}
1027
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001028void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -04001029{
Geoff Lang76b10c92014-09-05 16:28:14 -04001030 ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -04001031 Sampler *sampler =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001032 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001033 mGLState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04001034}
1035
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001036void Context::bindImageTexture(GLuint unit,
1037 GLuint texture,
1038 GLint level,
1039 GLboolean layered,
1040 GLint layer,
1041 GLenum access,
1042 GLenum format)
1043{
1044 Texture *tex = mState.mTextures->getTexture(texture);
1045 mGLState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
1046}
1047
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001048void Context::useProgram(GLuint program)
1049{
Jamie Madill6c1f6712017-02-14 19:08:04 -05001050 mGLState.setProgram(this, getProgram(program));
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001051}
1052
Jiajia Qin5451d532017-11-16 17:16:34 +08001053void Context::useProgramStages(GLuint pipeline, GLbitfield stages, GLuint program)
1054{
1055 UNIMPLEMENTED();
1056}
1057
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001058void Context::bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001059{
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001060 ASSERT(target == GL_TRANSFORM_FEEDBACK);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001061 TransformFeedback *transformFeedback =
1062 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001063 mGLState.setTransformFeedbackBinding(this, transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -05001064}
1065
Yunchao Hea336b902017-08-02 16:05:21 +08001066void Context::bindProgramPipeline(GLuint pipelineHandle)
1067{
1068 ProgramPipeline *pipeline =
1069 mState.mPipelines->checkProgramPipelineAllocation(mImplementation.get(), pipelineHandle);
1070 mGLState.setProgramPipelineBinding(this, pipeline);
1071}
1072
Jamie Madillf0e04492017-08-26 15:28:42 -04001073void Context::beginQuery(GLenum target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001074{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001075 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001076 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001077
Geoff Lang5aad9672014-09-08 11:10:42 -04001078 // begin query
Jamie Madillf0e04492017-08-26 15:28:42 -04001079 ANGLE_CONTEXT_TRY(queryObject->begin());
Geoff Lang5aad9672014-09-08 11:10:42 -04001080
1081 // set query as active for specified target only if begin succeeded
Jamie Madill4928b7c2017-06-20 12:57:39 -04001082 mGLState.setActiveQuery(this, target, queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001083}
1084
Jamie Madillf0e04492017-08-26 15:28:42 -04001085void Context::endQuery(GLenum target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001086{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001087 Query *queryObject = mGLState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001088 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001089
Jamie Madillf0e04492017-08-26 15:28:42 -04001090 handleError(queryObject->end());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001091
Geoff Lang5aad9672014-09-08 11:10:42 -04001092 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madill4928b7c2017-06-20 12:57:39 -04001093 mGLState.setActiveQuery(this, target, nullptr);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001094}
1095
Jamie Madillf0e04492017-08-26 15:28:42 -04001096void Context::queryCounter(GLuint id, GLenum target)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001097{
1098 ASSERT(target == GL_TIMESTAMP_EXT);
1099
1100 Query *queryObject = getQuery(id, true, target);
1101 ASSERT(queryObject);
1102
Jamie Madillf0e04492017-08-26 15:28:42 -04001103 handleError(queryObject->queryCounter());
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001104}
1105
1106void Context::getQueryiv(GLenum target, GLenum pname, GLint *params)
1107{
1108 switch (pname)
1109 {
1110 case GL_CURRENT_QUERY_EXT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001111 params[0] = mGLState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001112 break;
1113 case GL_QUERY_COUNTER_BITS_EXT:
1114 switch (target)
1115 {
1116 case GL_TIME_ELAPSED_EXT:
1117 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1118 break;
1119 case GL_TIMESTAMP_EXT:
1120 params[0] = getExtensions().queryCounterBitsTimestamp;
1121 break;
1122 default:
1123 UNREACHABLE();
1124 params[0] = 0;
1125 break;
1126 }
1127 break;
1128 default:
1129 UNREACHABLE();
1130 return;
1131 }
1132}
1133
Brandon Jones59770802018-04-02 13:18:42 -07001134void Context::getQueryivRobust(GLenum target,
1135 GLenum pname,
1136 GLsizei bufSize,
1137 GLsizei *length,
1138 GLint *params)
1139{
1140 getQueryiv(target, pname, params);
1141}
1142
Geoff Lang2186c382016-10-14 10:54:54 -04001143void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001144{
Geoff Lang2186c382016-10-14 10:54:54 -04001145 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001146}
1147
Brandon Jones59770802018-04-02 13:18:42 -07001148void Context::getQueryObjectivRobust(GLuint id,
1149 GLenum pname,
1150 GLsizei bufSize,
1151 GLsizei *length,
1152 GLint *params)
1153{
1154 getQueryObjectiv(id, pname, params);
1155}
1156
Geoff Lang2186c382016-10-14 10:54:54 -04001157void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001158{
Geoff Lang2186c382016-10-14 10:54:54 -04001159 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001160}
1161
Brandon Jones59770802018-04-02 13:18:42 -07001162void Context::getQueryObjectuivRobust(GLuint id,
1163 GLenum pname,
1164 GLsizei bufSize,
1165 GLsizei *length,
1166 GLuint *params)
1167{
1168 getQueryObjectuiv(id, pname, params);
1169}
1170
Geoff Lang2186c382016-10-14 10:54:54 -04001171void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001172{
Geoff Lang2186c382016-10-14 10:54:54 -04001173 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001174}
1175
Brandon Jones59770802018-04-02 13:18:42 -07001176void Context::getQueryObjecti64vRobust(GLuint id,
1177 GLenum pname,
1178 GLsizei bufSize,
1179 GLsizei *length,
1180 GLint64 *params)
1181{
1182 getQueryObjecti64v(id, pname, params);
1183}
1184
Geoff Lang2186c382016-10-14 10:54:54 -04001185void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001186{
Geoff Lang2186c382016-10-14 10:54:54 -04001187 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001188}
1189
Brandon Jones59770802018-04-02 13:18:42 -07001190void Context::getQueryObjectui64vRobust(GLuint id,
1191 GLenum pname,
1192 GLsizei bufSize,
1193 GLsizei *length,
1194 GLuint64 *params)
1195{
1196 getQueryObjectui64v(id, pname, params);
1197}
1198
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001199Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001200{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001201 return mState.mFramebuffers->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001202}
1203
Jamie Madill2f348d22017-06-05 10:50:59 -04001204FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001205{
Jamie Madill96a483b2017-06-27 16:49:21 -04001206 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001207}
1208
Jamie Madill2f348d22017-06-05 10:50:59 -04001209Query *Context::getQuery(GLuint handle, bool create, GLenum type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001210{
Jamie Madill96a483b2017-06-27 16:49:21 -04001211 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001212 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001213 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001214 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001215
1216 Query *query = mQueryMap.query(handle);
1217 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001218 {
Jamie Madill96a483b2017-06-27 16:49:21 -04001219 query = new Query(mImplementation->createQuery(type), handle);
1220 query->addRef();
1221 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001222 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001223 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001224}
1225
Geoff Lang70d0f492015-12-10 17:45:46 -05001226Query *Context::getQuery(GLuint handle) const
1227{
Jamie Madill96a483b2017-06-27 16:49:21 -04001228 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001229}
1230
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001231Texture *Context::getTargetTexture(TextureType type) const
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001232{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001233 ASSERT(ValidTextureTarget(this, type) || ValidTextureExternalTarget(this, type));
1234 return mGLState.getTargetTexture(type);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001235}
1236
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001237Texture *Context::getSamplerTexture(unsigned int sampler, TextureType type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001238{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001239 return mGLState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001240}
1241
Geoff Lang492a7e42014-11-05 13:27:06 -05001242Compiler *Context::getCompiler() const
1243{
Jamie Madill2f348d22017-06-05 10:50:59 -04001244 if (mCompiler.get() == nullptr)
1245 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001246 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001247 }
1248 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001249}
1250
Jamie Madillc1d770e2017-04-13 17:31:24 -04001251void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001252{
1253 switch (pname)
1254 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001255 case GL_SHADER_COMPILER:
1256 *params = GL_TRUE;
1257 break;
1258 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1259 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1260 break;
1261 default:
1262 mGLState.getBooleanv(pname, params);
1263 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001264 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001265}
1266
Jamie Madillc1d770e2017-04-13 17:31:24 -04001267void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001268{
Shannon Woods53a94a82014-06-24 15:20:36 -04001269 // Queries about context capabilities and maximums are answered by Context.
1270 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001271 switch (pname)
1272 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001273 case GL_ALIASED_LINE_WIDTH_RANGE:
1274 params[0] = mCaps.minAliasedLineWidth;
1275 params[1] = mCaps.maxAliasedLineWidth;
1276 break;
1277 case GL_ALIASED_POINT_SIZE_RANGE:
1278 params[0] = mCaps.minAliasedPointSize;
1279 params[1] = mCaps.maxAliasedPointSize;
1280 break;
1281 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1282 ASSERT(mExtensions.textureFilterAnisotropic);
1283 *params = mExtensions.maxTextureAnisotropy;
1284 break;
1285 case GL_MAX_TEXTURE_LOD_BIAS:
1286 *params = mCaps.maxLODBias;
1287 break;
1288
1289 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1290 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1291 {
1292 ASSERT(mExtensions.pathRendering);
1293 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1294 memcpy(params, m, 16 * sizeof(GLfloat));
1295 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001296 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001297
Jamie Madill231c7f52017-04-26 13:45:37 -04001298 default:
1299 mGLState.getFloatv(pname, params);
1300 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001301 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001302}
1303
Jamie Madillc1d770e2017-04-13 17:31:24 -04001304void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001305{
Shannon Woods53a94a82014-06-24 15:20:36 -04001306 // Queries about context capabilities and maximums are answered by Context.
1307 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001308
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001309 switch (pname)
1310 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001311 case GL_MAX_VERTEX_ATTRIBS:
1312 *params = mCaps.maxVertexAttributes;
1313 break;
1314 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1315 *params = mCaps.maxVertexUniformVectors;
1316 break;
1317 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
1318 *params = mCaps.maxVertexUniformComponents;
1319 break;
1320 case GL_MAX_VARYING_VECTORS:
1321 *params = mCaps.maxVaryingVectors;
1322 break;
1323 case GL_MAX_VARYING_COMPONENTS:
1324 *params = mCaps.maxVertexOutputComponents;
1325 break;
1326 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1327 *params = mCaps.maxCombinedTextureImageUnits;
1328 break;
1329 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
1330 *params = mCaps.maxVertexTextureImageUnits;
1331 break;
1332 case GL_MAX_TEXTURE_IMAGE_UNITS:
1333 *params = mCaps.maxTextureImageUnits;
1334 break;
1335 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1336 *params = mCaps.maxFragmentUniformVectors;
1337 break;
1338 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
1339 *params = mCaps.maxFragmentUniformComponents;
1340 break;
1341 case GL_MAX_RENDERBUFFER_SIZE:
1342 *params = mCaps.maxRenderbufferSize;
1343 break;
1344 case GL_MAX_COLOR_ATTACHMENTS_EXT:
1345 *params = mCaps.maxColorAttachments;
1346 break;
1347 case GL_MAX_DRAW_BUFFERS_EXT:
1348 *params = mCaps.maxDrawBuffers;
1349 break;
1350 // case GL_FRAMEBUFFER_BINDING: // now equivalent to
1351 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
1352 case GL_SUBPIXEL_BITS:
1353 *params = 4;
1354 break;
1355 case GL_MAX_TEXTURE_SIZE:
1356 *params = mCaps.max2DTextureSize;
1357 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001358 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
1359 *params = mCaps.maxRectangleTextureSize;
1360 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001361 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1362 *params = mCaps.maxCubeMapTextureSize;
1363 break;
1364 case GL_MAX_3D_TEXTURE_SIZE:
1365 *params = mCaps.max3DTextureSize;
1366 break;
1367 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1368 *params = mCaps.maxArrayTextureLayers;
1369 break;
1370 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1371 *params = mCaps.uniformBufferOffsetAlignment;
1372 break;
1373 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1374 *params = mCaps.maxUniformBufferBindings;
1375 break;
1376 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
1377 *params = mCaps.maxVertexUniformBlocks;
1378 break;
1379 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
1380 *params = mCaps.maxFragmentUniformBlocks;
1381 break;
1382 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1383 *params = mCaps.maxCombinedTextureImageUnits;
1384 break;
1385 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1386 *params = mCaps.maxVertexOutputComponents;
1387 break;
1388 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1389 *params = mCaps.maxFragmentInputComponents;
1390 break;
1391 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1392 *params = mCaps.minProgramTexelOffset;
1393 break;
1394 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1395 *params = mCaps.maxProgramTexelOffset;
1396 break;
1397 case GL_MAJOR_VERSION:
1398 *params = getClientVersion().major;
1399 break;
1400 case GL_MINOR_VERSION:
1401 *params = getClientVersion().minor;
1402 break;
1403 case GL_MAX_ELEMENTS_INDICES:
1404 *params = mCaps.maxElementsIndices;
1405 break;
1406 case GL_MAX_ELEMENTS_VERTICES:
1407 *params = mCaps.maxElementsVertices;
1408 break;
1409 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1410 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1411 break;
1412 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1413 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1414 break;
1415 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1416 *params = mCaps.maxTransformFeedbackSeparateComponents;
1417 break;
1418 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1419 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1420 break;
1421 case GL_MAX_SAMPLES_ANGLE:
1422 *params = mCaps.maxSamples;
1423 break;
1424 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001425 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001426 params[0] = mCaps.maxViewportWidth;
1427 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001428 }
1429 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001430 case GL_COMPRESSED_TEXTURE_FORMATS:
1431 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1432 params);
1433 break;
1434 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1435 *params = mResetStrategy;
1436 break;
1437 case GL_NUM_SHADER_BINARY_FORMATS:
1438 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1439 break;
1440 case GL_SHADER_BINARY_FORMATS:
1441 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1442 break;
1443 case GL_NUM_PROGRAM_BINARY_FORMATS:
1444 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1445 break;
1446 case GL_PROGRAM_BINARY_FORMATS:
1447 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1448 break;
1449 case GL_NUM_EXTENSIONS:
1450 *params = static_cast<GLint>(mExtensionStrings.size());
1451 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001452
Jamie Madill231c7f52017-04-26 13:45:37 -04001453 // GL_KHR_debug
1454 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1455 *params = mExtensions.maxDebugMessageLength;
1456 break;
1457 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1458 *params = mExtensions.maxDebugLoggedMessages;
1459 break;
1460 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1461 *params = mExtensions.maxDebugGroupStackDepth;
1462 break;
1463 case GL_MAX_LABEL_LENGTH:
1464 *params = mExtensions.maxLabelLength;
1465 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001466
Martin Radeve5285d22017-07-14 16:23:53 +03001467 // GL_ANGLE_multiview
1468 case GL_MAX_VIEWS_ANGLE:
1469 *params = mExtensions.maxViews;
1470 break;
1471
Jamie Madill231c7f52017-04-26 13:45:37 -04001472 // GL_EXT_disjoint_timer_query
1473 case GL_GPU_DISJOINT_EXT:
1474 *params = mImplementation->getGPUDisjoint();
1475 break;
1476 case GL_MAX_FRAMEBUFFER_WIDTH:
1477 *params = mCaps.maxFramebufferWidth;
1478 break;
1479 case GL_MAX_FRAMEBUFFER_HEIGHT:
1480 *params = mCaps.maxFramebufferHeight;
1481 break;
1482 case GL_MAX_FRAMEBUFFER_SAMPLES:
1483 *params = mCaps.maxFramebufferSamples;
1484 break;
1485 case GL_MAX_SAMPLE_MASK_WORDS:
1486 *params = mCaps.maxSampleMaskWords;
1487 break;
1488 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1489 *params = mCaps.maxColorTextureSamples;
1490 break;
1491 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1492 *params = mCaps.maxDepthTextureSamples;
1493 break;
1494 case GL_MAX_INTEGER_SAMPLES:
1495 *params = mCaps.maxIntegerSamples;
1496 break;
1497 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1498 *params = mCaps.maxVertexAttribRelativeOffset;
1499 break;
1500 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1501 *params = mCaps.maxVertexAttribBindings;
1502 break;
1503 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1504 *params = mCaps.maxVertexAttribStride;
1505 break;
1506 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
1507 *params = mCaps.maxVertexAtomicCounterBuffers;
1508 break;
1509 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
1510 *params = mCaps.maxVertexAtomicCounters;
1511 break;
1512 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
1513 *params = mCaps.maxVertexImageUniforms;
1514 break;
1515 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
1516 *params = mCaps.maxVertexShaderStorageBlocks;
1517 break;
1518 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
1519 *params = mCaps.maxFragmentAtomicCounterBuffers;
1520 break;
1521 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
1522 *params = mCaps.maxFragmentAtomicCounters;
1523 break;
1524 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
1525 *params = mCaps.maxFragmentImageUniforms;
1526 break;
1527 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
1528 *params = mCaps.maxFragmentShaderStorageBlocks;
1529 break;
1530 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1531 *params = mCaps.minProgramTextureGatherOffset;
1532 break;
1533 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1534 *params = mCaps.maxProgramTextureGatherOffset;
1535 break;
1536 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1537 *params = mCaps.maxComputeWorkGroupInvocations;
1538 break;
1539 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
1540 *params = mCaps.maxComputeUniformBlocks;
1541 break;
1542 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
1543 *params = mCaps.maxComputeTextureImageUnits;
1544 break;
1545 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1546 *params = mCaps.maxComputeSharedMemorySize;
1547 break;
1548 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
1549 *params = mCaps.maxComputeUniformComponents;
1550 break;
1551 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
1552 *params = mCaps.maxComputeAtomicCounterBuffers;
1553 break;
1554 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
1555 *params = mCaps.maxComputeAtomicCounters;
1556 break;
1557 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
1558 *params = mCaps.maxComputeImageUniforms;
1559 break;
1560 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
1561 *params = mCaps.maxCombinedComputeUniformComponents;
1562 break;
1563 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
1564 *params = mCaps.maxComputeShaderStorageBlocks;
1565 break;
1566 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1567 *params = mCaps.maxCombinedShaderOutputResources;
1568 break;
1569 case GL_MAX_UNIFORM_LOCATIONS:
1570 *params = mCaps.maxUniformLocations;
1571 break;
1572 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1573 *params = mCaps.maxAtomicCounterBufferBindings;
1574 break;
1575 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1576 *params = mCaps.maxAtomicCounterBufferSize;
1577 break;
1578 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1579 *params = mCaps.maxCombinedAtomicCounterBuffers;
1580 break;
1581 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1582 *params = mCaps.maxCombinedAtomicCounters;
1583 break;
1584 case GL_MAX_IMAGE_UNITS:
1585 *params = mCaps.maxImageUnits;
1586 break;
1587 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1588 *params = mCaps.maxCombinedImageUniforms;
1589 break;
1590 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1591 *params = mCaps.maxShaderStorageBufferBindings;
1592 break;
1593 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1594 *params = mCaps.maxCombinedShaderStorageBlocks;
1595 break;
1596 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1597 *params = mCaps.shaderStorageBufferOffsetAlignment;
1598 break;
Jiawei Shao361df072017-11-22 09:33:59 +08001599
1600 // GL_EXT_geometry_shader
1601 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
1602 *params = mCaps.maxFramebufferLayers;
1603 break;
1604 case GL_LAYER_PROVOKING_VERTEX_EXT:
1605 *params = mCaps.layerProvokingVertex;
1606 break;
1607 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
1608 *params = mCaps.maxGeometryUniformComponents;
1609 break;
1610 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
1611 *params = mCaps.maxGeometryUniformBlocks;
1612 break;
1613 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
1614 *params = mCaps.maxCombinedGeometryUniformComponents;
1615 break;
1616 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
1617 *params = mCaps.maxGeometryInputComponents;
1618 break;
1619 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
1620 *params = mCaps.maxGeometryOutputComponents;
1621 break;
1622 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
1623 *params = mCaps.maxGeometryOutputVertices;
1624 break;
1625 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
1626 *params = mCaps.maxGeometryTotalOutputComponents;
1627 break;
1628 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
1629 *params = mCaps.maxGeometryShaderInvocations;
1630 break;
1631 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
1632 *params = mCaps.maxGeometryTextureImageUnits;
1633 break;
1634 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
1635 *params = mCaps.maxGeometryAtomicCounterBuffers;
1636 break;
1637 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
1638 *params = mCaps.maxGeometryAtomicCounters;
1639 break;
1640 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
1641 *params = mCaps.maxGeometryImageUniforms;
1642 break;
1643 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
1644 *params = mCaps.maxGeometryShaderStorageBlocks;
1645 break;
Lingfeng Yang96310cd2018-03-28 11:56:28 -07001646 // GLES1 emulation: Caps queries
1647 case GL_MAX_TEXTURE_UNITS:
1648 *params = mCaps.maxMultitextureUnits;
1649 break;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001650 case GL_MAX_MODELVIEW_STACK_DEPTH:
1651 *params = mCaps.maxModelviewMatrixStackDepth;
1652 break;
1653 case GL_MAX_PROJECTION_STACK_DEPTH:
1654 *params = mCaps.maxProjectionMatrixStackDepth;
1655 break;
1656 case GL_MAX_TEXTURE_STACK_DEPTH:
1657 *params = mCaps.maxTextureMatrixStackDepth;
1658 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001659 default:
Jamie Madille98b1b52018-03-08 09:47:23 -05001660 handleError(mGLState.getIntegerv(this, pname, params));
Jamie Madill231c7f52017-04-26 13:45:37 -04001661 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001662 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001663}
1664
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001665void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001666{
Shannon Woods53a94a82014-06-24 15:20:36 -04001667 // Queries about context capabilities and maximums are answered by Context.
1668 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001669 switch (pname)
1670 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001671 case GL_MAX_ELEMENT_INDEX:
1672 *params = mCaps.maxElementIndex;
1673 break;
1674 case GL_MAX_UNIFORM_BLOCK_SIZE:
1675 *params = mCaps.maxUniformBlockSize;
1676 break;
1677 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
1678 *params = mCaps.maxCombinedVertexUniformComponents;
1679 break;
1680 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
1681 *params = mCaps.maxCombinedFragmentUniformComponents;
1682 break;
1683 case GL_MAX_SERVER_WAIT_TIMEOUT:
1684 *params = mCaps.maxServerWaitTimeout;
1685 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001686
Jamie Madill231c7f52017-04-26 13:45:37 -04001687 // GL_EXT_disjoint_timer_query
1688 case GL_TIMESTAMP_EXT:
1689 *params = mImplementation->getTimestamp();
1690 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001691
Jamie Madill231c7f52017-04-26 13:45:37 -04001692 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1693 *params = mCaps.maxShaderStorageBlockSize;
1694 break;
1695 default:
1696 UNREACHABLE();
1697 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001698 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001699}
1700
Geoff Lang70d0f492015-12-10 17:45:46 -05001701void Context::getPointerv(GLenum pname, void **params) const
1702{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001703 mGLState.getPointerv(pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001704}
1705
Martin Radev66fb8202016-07-28 11:45:20 +03001706void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -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.
Martin Radev66fb8202016-07-28 11:45:20 +03001710
1711 GLenum nativeType;
1712 unsigned int numParams;
1713 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1714 ASSERT(queryStatus);
1715
1716 if (nativeType == GL_INT)
1717 {
1718 switch (target)
1719 {
1720 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1721 ASSERT(index < 3u);
1722 *data = mCaps.maxComputeWorkGroupCount[index];
1723 break;
1724 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1725 ASSERT(index < 3u);
1726 *data = mCaps.maxComputeWorkGroupSize[index];
1727 break;
1728 default:
1729 mGLState.getIntegeri_v(target, index, data);
1730 }
1731 }
1732 else
1733 {
1734 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1735 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001736}
1737
Brandon Jones59770802018-04-02 13:18:42 -07001738void Context::getIntegeri_vRobust(GLenum target,
1739 GLuint index,
1740 GLsizei bufSize,
1741 GLsizei *length,
1742 GLint *data)
1743{
1744 getIntegeri_v(target, index, data);
1745}
1746
Martin Radev66fb8202016-07-28 11:45:20 +03001747void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001748{
Shannon Woods53a94a82014-06-24 15:20:36 -04001749 // Queries about context capabilities and maximums are answered by Context.
1750 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001751
1752 GLenum nativeType;
1753 unsigned int numParams;
1754 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1755 ASSERT(queryStatus);
1756
1757 if (nativeType == GL_INT_64_ANGLEX)
1758 {
1759 mGLState.getInteger64i_v(target, index, data);
1760 }
1761 else
1762 {
1763 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1764 }
1765}
1766
Brandon Jones59770802018-04-02 13:18:42 -07001767void Context::getInteger64i_vRobust(GLenum target,
1768 GLuint index,
1769 GLsizei bufSize,
1770 GLsizei *length,
1771 GLint64 *data)
1772{
1773 getInteger64i_v(target, index, data);
1774}
1775
Martin Radev66fb8202016-07-28 11:45:20 +03001776void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1777{
1778 // Queries about context capabilities and maximums are answered by Context.
1779 // Queries about current GL state values are answered by State.
1780
1781 GLenum nativeType;
1782 unsigned int numParams;
1783 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1784 ASSERT(queryStatus);
1785
1786 if (nativeType == GL_BOOL)
1787 {
1788 mGLState.getBooleani_v(target, index, data);
1789 }
1790 else
1791 {
1792 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1793 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001794}
1795
Brandon Jones59770802018-04-02 13:18:42 -07001796void Context::getBooleani_vRobust(GLenum target,
1797 GLuint index,
1798 GLsizei bufSize,
1799 GLsizei *length,
1800 GLboolean *data)
1801{
1802 getBooleani_v(target, index, data);
1803}
1804
Corentin Wallez336129f2017-10-17 15:55:40 -04001805void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001806{
1807 Buffer *buffer = mGLState.getTargetBuffer(target);
1808 QueryBufferParameteriv(buffer, pname, params);
1809}
1810
Brandon Jones59770802018-04-02 13:18:42 -07001811void Context::getBufferParameterivRobust(BufferBinding target,
1812 GLenum pname,
1813 GLsizei bufSize,
1814 GLsizei *length,
1815 GLint *params)
1816{
1817 getBufferParameteriv(target, pname, params);
1818}
1819
He Yunchao010e4db2017-03-03 14:22:06 +08001820void Context::getFramebufferAttachmentParameteriv(GLenum target,
1821 GLenum attachment,
1822 GLenum pname,
1823 GLint *params)
1824{
1825 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08001826 QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08001827}
1828
Brandon Jones59770802018-04-02 13:18:42 -07001829void Context::getFramebufferAttachmentParameterivRobust(GLenum target,
1830 GLenum attachment,
1831 GLenum pname,
1832 GLsizei bufSize,
1833 GLsizei *length,
1834 GLint *params)
1835{
1836 getFramebufferAttachmentParameteriv(target, attachment, pname, params);
1837}
1838
He Yunchao010e4db2017-03-03 14:22:06 +08001839void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
1840{
1841 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
1842 QueryRenderbufferiv(this, renderbuffer, pname, params);
1843}
1844
Brandon Jones59770802018-04-02 13:18:42 -07001845void Context::getRenderbufferParameterivRobust(GLenum target,
1846 GLenum pname,
1847 GLsizei bufSize,
1848 GLsizei *length,
1849 GLint *params)
1850{
1851 getRenderbufferParameteriv(target, pname, params);
1852}
1853
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001854void Context::getTexParameterfv(TextureType target, GLenum pname, GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001855{
1856 Texture *texture = getTargetTexture(target);
1857 QueryTexParameterfv(texture, pname, params);
1858}
1859
Brandon Jones59770802018-04-02 13:18:42 -07001860void Context::getTexParameterfvRobust(TextureType target,
1861 GLenum pname,
1862 GLsizei bufSize,
1863 GLsizei *length,
1864 GLfloat *params)
1865{
1866 getTexParameterfv(target, pname, params);
1867}
1868
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001869void Context::getTexParameteriv(TextureType target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001870{
1871 Texture *texture = getTargetTexture(target);
1872 QueryTexParameteriv(texture, pname, params);
1873}
Jiajia Qin5451d532017-11-16 17:16:34 +08001874
Brandon Jones59770802018-04-02 13:18:42 -07001875void Context::getTexParameterivRobust(TextureType target,
1876 GLenum pname,
1877 GLsizei bufSize,
1878 GLsizei *length,
1879 GLint *params)
1880{
1881 getTexParameteriv(target, pname, params);
1882}
1883
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001884void Context::getTexLevelParameteriv(TextureTarget target, GLint level, GLenum pname, GLint *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08001885{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001886 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05001887 QueryTexLevelParameteriv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08001888}
1889
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001890void Context::getTexLevelParameterfv(TextureTarget target,
1891 GLint level,
1892 GLenum pname,
1893 GLfloat *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08001894{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001895 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05001896 QueryTexLevelParameterfv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08001897}
1898
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001899void Context::texParameterf(TextureType target, GLenum pname, GLfloat param)
He Yunchao010e4db2017-03-03 14:22:06 +08001900{
1901 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001902 SetTexParameterf(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04001903 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001904}
1905
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001906void Context::texParameterfv(TextureType target, GLenum pname, const GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001907{
1908 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001909 SetTexParameterfv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04001910 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001911}
1912
Brandon Jones59770802018-04-02 13:18:42 -07001913void Context::texParameterfvRobust(TextureType target,
1914 GLenum pname,
1915 GLsizei bufSize,
1916 const GLfloat *params)
1917{
1918 texParameterfv(target, pname, params);
1919}
1920
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001921void Context::texParameteri(TextureType target, GLenum pname, GLint param)
He Yunchao010e4db2017-03-03 14:22:06 +08001922{
1923 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001924 SetTexParameteri(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04001925 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001926}
1927
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001928void Context::texParameteriv(TextureType target, GLenum pname, const GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001929{
1930 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001931 SetTexParameteriv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04001932 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001933}
1934
Brandon Jones59770802018-04-02 13:18:42 -07001935void Context::texParameterivRobust(TextureType target,
1936 GLenum pname,
1937 GLsizei bufSize,
1938 const GLint *params)
1939{
1940 texParameteriv(target, pname, params);
1941}
1942
Jamie Madill675fe712016-12-19 13:07:54 -05001943void Context::drawArrays(GLenum mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001944{
Jamie Madill9fdaa492018-02-16 10:52:11 -05001945 // No-op if zero count
1946 if (count == 0)
1947 {
1948 return;
1949 }
1950
Jamie Madill05b35b22017-10-03 09:01:44 -04001951 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001952 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
Jamie Madill09463932018-04-04 05:26:59 -04001953 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count, 1);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001954}
1955
Jamie Madill675fe712016-12-19 13:07:54 -05001956void Context::drawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04001957{
Jamie Madill9fdaa492018-02-16 10:52:11 -05001958 // No-op if zero count
1959 if (count == 0 || instanceCount == 0)
1960 {
1961 return;
1962 }
1963
Jamie Madill05b35b22017-10-03 09:01:44 -04001964 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001965 ANGLE_CONTEXT_TRY(
1966 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
Jamie Madill09463932018-04-04 05:26:59 -04001967 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count,
1968 instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -04001969}
1970
Jamie Madill876429b2017-04-20 15:46:24 -04001971void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001972{
Jamie Madill9fdaa492018-02-16 10:52:11 -05001973 // No-op if zero count
1974 if (count == 0)
1975 {
1976 return;
1977 }
1978
Jamie Madill05b35b22017-10-03 09:01:44 -04001979 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001980 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04001981}
1982
Jamie Madill675fe712016-12-19 13:07:54 -05001983void Context::drawElementsInstanced(GLenum mode,
1984 GLsizei count,
1985 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04001986 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04001987 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04001988{
Jamie Madill9fdaa492018-02-16 10:52:11 -05001989 // No-op if zero count
1990 if (count == 0 || instances == 0)
1991 {
1992 return;
1993 }
1994
Jamie Madill05b35b22017-10-03 09:01:44 -04001995 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001996 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08001997 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04001998}
1999
Jamie Madill675fe712016-12-19 13:07:54 -05002000void Context::drawRangeElements(GLenum mode,
2001 GLuint start,
2002 GLuint end,
2003 GLsizei count,
2004 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002005 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04002006{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002007 // No-op if zero count
2008 if (count == 0)
2009 {
2010 return;
2011 }
2012
Jamie Madill05b35b22017-10-03 09:01:44 -04002013 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002014 ANGLE_CONTEXT_TRY(
2015 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002016}
2017
Jamie Madill876429b2017-04-20 15:46:24 -04002018void Context::drawArraysIndirect(GLenum mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002019{
Jamie Madill05b35b22017-10-03 09:01:44 -04002020 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002021 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002022}
2023
Jamie Madill876429b2017-04-20 15:46:24 -04002024void Context::drawElementsIndirect(GLenum mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002025{
Jamie Madill05b35b22017-10-03 09:01:44 -04002026 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002027 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002028}
2029
Jamie Madill675fe712016-12-19 13:07:54 -05002030void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002031{
Jamie Madillafa02a22017-11-23 12:57:38 -05002032 handleError(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05002033}
2034
Jamie Madill675fe712016-12-19 13:07:54 -05002035void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05002036{
Jamie Madillafa02a22017-11-23 12:57:38 -05002037 handleError(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002038}
2039
Austin Kinross6ee1e782015-05-29 17:05:37 -07002040void Context::insertEventMarker(GLsizei length, const char *marker)
2041{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002042 ASSERT(mImplementation);
2043 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07002044}
2045
2046void Context::pushGroupMarker(GLsizei length, const char *marker)
2047{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002048 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05002049
2050 if (marker == nullptr)
2051 {
2052 // From the EXT_debug_marker spec,
2053 // "If <marker> is null then an empty string is pushed on the stack."
2054 mImplementation->pushGroupMarker(length, "");
2055 }
2056 else
2057 {
2058 mImplementation->pushGroupMarker(length, marker);
2059 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07002060}
2061
2062void Context::popGroupMarker()
2063{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002064 ASSERT(mImplementation);
2065 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07002066}
2067
Geoff Langd8605522016-04-13 10:19:12 -04002068void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
2069{
2070 Program *programObject = getProgram(program);
2071 ASSERT(programObject);
2072
2073 programObject->bindUniformLocation(location, name);
2074}
2075
Brandon Jones59770802018-04-02 13:18:42 -07002076void Context::coverageModulation(GLenum components)
Sami Väisänena797e062016-05-12 15:23:40 +03002077{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002078 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03002079}
2080
Brandon Jones59770802018-04-02 13:18:42 -07002081void Context::matrixLoadf(GLenum matrixMode, const GLfloat *matrix)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002082{
2083 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
2084}
2085
Brandon Jones59770802018-04-02 13:18:42 -07002086void Context::matrixLoadIdentity(GLenum matrixMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002087{
2088 GLfloat I[16];
2089 angle::Matrix<GLfloat>::setToIdentity(I);
2090
2091 mGLState.loadPathRenderingMatrix(matrixMode, I);
2092}
2093
2094void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
2095{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002096 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002097 if (!pathObj)
2098 return;
2099
2100 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002101 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002102
2103 mImplementation->stencilFillPath(pathObj, fillMode, mask);
2104}
2105
2106void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
2107{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002108 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002109 if (!pathObj)
2110 return;
2111
2112 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002113 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002114
2115 mImplementation->stencilStrokePath(pathObj, reference, mask);
2116}
2117
2118void Context::coverFillPath(GLuint path, GLenum coverMode)
2119{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002120 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002121 if (!pathObj)
2122 return;
2123
2124 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002125 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002126
2127 mImplementation->coverFillPath(pathObj, coverMode);
2128}
2129
2130void Context::coverStrokePath(GLuint path, GLenum coverMode)
2131{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002132 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002133 if (!pathObj)
2134 return;
2135
2136 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002137 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002138
2139 mImplementation->coverStrokePath(pathObj, coverMode);
2140}
2141
2142void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
2143{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002144 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002145 if (!pathObj)
2146 return;
2147
2148 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002149 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002150
2151 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
2152}
2153
2154void Context::stencilThenCoverStrokePath(GLuint path,
2155 GLint reference,
2156 GLuint mask,
2157 GLenum coverMode)
2158{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002159 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002160 if (!pathObj)
2161 return;
2162
2163 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002164 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002165
2166 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2167}
2168
Sami Väisänend59ca052016-06-21 16:10:00 +03002169void Context::coverFillPathInstanced(GLsizei numPaths,
2170 GLenum pathNameType,
2171 const void *paths,
2172 GLuint pathBase,
2173 GLenum coverMode,
2174 GLenum transformType,
2175 const GLfloat *transformValues)
2176{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002177 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002178
2179 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002180 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002181
2182 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2183}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002184
Sami Väisänend59ca052016-06-21 16:10:00 +03002185void Context::coverStrokePathInstanced(GLsizei numPaths,
2186 GLenum pathNameType,
2187 const void *paths,
2188 GLuint pathBase,
2189 GLenum coverMode,
2190 GLenum transformType,
2191 const GLfloat *transformValues)
2192{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002193 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002194
2195 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002196 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002197
2198 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2199 transformValues);
2200}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002201
Sami Väisänend59ca052016-06-21 16:10:00 +03002202void Context::stencilFillPathInstanced(GLsizei numPaths,
2203 GLenum pathNameType,
2204 const void *paths,
2205 GLuint pathBase,
2206 GLenum fillMode,
2207 GLuint mask,
2208 GLenum transformType,
2209 const GLfloat *transformValues)
2210{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002211 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002212
2213 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002214 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002215
2216 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2217 transformValues);
2218}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002219
Sami Väisänend59ca052016-06-21 16:10:00 +03002220void Context::stencilStrokePathInstanced(GLsizei numPaths,
2221 GLenum pathNameType,
2222 const void *paths,
2223 GLuint pathBase,
2224 GLint reference,
2225 GLuint mask,
2226 GLenum transformType,
2227 const GLfloat *transformValues)
2228{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002229 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002230
2231 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002232 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002233
2234 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2235 transformValues);
2236}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002237
Sami Väisänend59ca052016-06-21 16:10:00 +03002238void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2239 GLenum pathNameType,
2240 const void *paths,
2241 GLuint pathBase,
2242 GLenum fillMode,
2243 GLuint mask,
2244 GLenum coverMode,
2245 GLenum transformType,
2246 const GLfloat *transformValues)
2247{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002248 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002249
2250 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002251 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002252
2253 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2254 transformType, transformValues);
2255}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002256
Sami Väisänend59ca052016-06-21 16:10:00 +03002257void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2258 GLenum pathNameType,
2259 const void *paths,
2260 GLuint pathBase,
2261 GLint reference,
2262 GLuint mask,
2263 GLenum coverMode,
2264 GLenum transformType,
2265 const GLfloat *transformValues)
2266{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002267 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002268
2269 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002270 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002271
2272 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2273 transformType, transformValues);
2274}
2275
Sami Väisänen46eaa942016-06-29 10:26:37 +03002276void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2277{
2278 auto *programObject = getProgram(program);
2279
2280 programObject->bindFragmentInputLocation(location, name);
2281}
2282
2283void Context::programPathFragmentInputGen(GLuint program,
2284 GLint location,
2285 GLenum genMode,
2286 GLint components,
2287 const GLfloat *coeffs)
2288{
2289 auto *programObject = getProgram(program);
2290
Jamie Madillbd044ed2017-06-05 12:59:21 -04002291 programObject->pathFragmentInputGen(this, location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002292}
2293
jchen1015015f72017-03-16 13:54:21 +08002294GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2295{
jchen10fd7c3b52017-03-21 15:36:03 +08002296 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002297 return QueryProgramResourceIndex(programObject, programInterface, name);
2298}
2299
jchen10fd7c3b52017-03-21 15:36:03 +08002300void Context::getProgramResourceName(GLuint program,
2301 GLenum programInterface,
2302 GLuint index,
2303 GLsizei bufSize,
2304 GLsizei *length,
2305 GLchar *name)
2306{
2307 const auto *programObject = getProgram(program);
2308 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2309}
2310
jchen10191381f2017-04-11 13:59:04 +08002311GLint Context::getProgramResourceLocation(GLuint program,
2312 GLenum programInterface,
2313 const GLchar *name)
2314{
2315 const auto *programObject = getProgram(program);
2316 return QueryProgramResourceLocation(programObject, programInterface, name);
2317}
2318
jchen10880683b2017-04-12 16:21:55 +08002319void Context::getProgramResourceiv(GLuint program,
2320 GLenum programInterface,
2321 GLuint index,
2322 GLsizei propCount,
2323 const GLenum *props,
2324 GLsizei bufSize,
2325 GLsizei *length,
2326 GLint *params)
2327{
2328 const auto *programObject = getProgram(program);
2329 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2330 length, params);
2331}
2332
jchen10d9cd7b72017-08-30 15:04:25 +08002333void Context::getProgramInterfaceiv(GLuint program,
2334 GLenum programInterface,
2335 GLenum pname,
2336 GLint *params)
2337{
2338 const auto *programObject = getProgram(program);
2339 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2340}
2341
Jamie Madill71c88b32017-09-14 22:20:29 -04002342void Context::handleError(const Error &error)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002343{
Geoff Langda5777c2014-07-11 09:52:58 -04002344 if (error.isError())
2345 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002346 GLenum code = error.getCode();
2347 mErrors.insert(code);
2348 if (code == GL_OUT_OF_MEMORY && getWorkarounds().loseContextOnOutOfMemory)
2349 {
2350 markContextLost();
2351 }
Geoff Lang70d0f492015-12-10 17:45:46 -05002352
Geoff Langee6884e2017-11-09 16:51:11 -05002353 ASSERT(!error.getMessage().empty());
2354 mGLState.getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, error.getID(),
2355 GL_DEBUG_SEVERITY_HIGH, error.getMessage());
Geoff Langda5777c2014-07-11 09:52:58 -04002356 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002357}
2358
2359// Get one of the recorded errors and clear its flag, if any.
2360// [OpenGL ES 2.0.24] section 2.5 page 13.
2361GLenum Context::getError()
2362{
Geoff Langda5777c2014-07-11 09:52:58 -04002363 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002364 {
Geoff Langda5777c2014-07-11 09:52:58 -04002365 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002366 }
Geoff Langda5777c2014-07-11 09:52:58 -04002367 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002368 {
Geoff Langda5777c2014-07-11 09:52:58 -04002369 GLenum error = *mErrors.begin();
2370 mErrors.erase(mErrors.begin());
2371 return error;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002372 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002373}
2374
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002375// NOTE: this function should not assume that this context is current!
2376void Context::markContextLost()
2377{
2378 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002379 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002380 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002381 mContextLostForced = true;
2382 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002383 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002384}
2385
2386bool Context::isContextLost()
2387{
2388 return mContextLost;
2389}
2390
Jamie Madillfa920eb2018-01-04 11:45:50 -05002391GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002392{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002393 // Even if the application doesn't want to know about resets, we want to know
2394 // as it will allow us to skip all the calls.
2395 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002396 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002397 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002398 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002399 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002400 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002401
2402 // EXT_robustness, section 2.6: If the reset notification behavior is
2403 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2404 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2405 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002406 }
2407
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002408 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2409 // status should be returned at least once, and GL_NO_ERROR should be returned
2410 // once the device has finished resetting.
2411 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002412 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002413 ASSERT(mResetStatus == GL_NO_ERROR);
2414 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002415
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002416 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002417 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002418 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002419 }
2420 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002421 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002422 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002423 // If markContextLost was used to mark the context lost then
2424 // assume that is not recoverable, and continue to report the
2425 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002426 mResetStatus = mImplementation->getResetStatus();
2427 }
Jamie Madill893ab082014-05-16 16:56:10 -04002428
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002429 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002430}
2431
2432bool Context::isResetNotificationEnabled()
2433{
2434 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2435}
2436
Corentin Walleze3b10e82015-05-20 11:06:25 -04002437const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002438{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002439 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002440}
2441
2442EGLenum Context::getClientType() const
2443{
2444 return mClientType;
2445}
2446
2447EGLenum Context::getRenderBuffer() const
2448{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002449 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2450 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002451 {
2452 return EGL_NONE;
2453 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002454
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002455 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002456 ASSERT(backAttachment != nullptr);
2457 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002458}
2459
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002460VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002461{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002462 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002463 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2464 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002465 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002466 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2467 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002468
Jamie Madill96a483b2017-06-27 16:49:21 -04002469 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002470 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002471
2472 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002473}
2474
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002475TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002476{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002477 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002478 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2479 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002480 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002481 transformFeedback =
2482 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002483 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002484 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002485 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002486
2487 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002488}
2489
2490bool Context::isVertexArrayGenerated(GLuint vertexArray)
2491{
Jamie Madill96a483b2017-06-27 16:49:21 -04002492 ASSERT(mVertexArrayMap.contains(0));
2493 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002494}
2495
2496bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2497{
Jamie Madill96a483b2017-06-27 16:49:21 -04002498 ASSERT(mTransformFeedbackMap.contains(0));
2499 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002500}
2501
Shannon Woods53a94a82014-06-24 15:20:36 -04002502void Context::detachTexture(GLuint texture)
2503{
2504 // Simple pass-through to State's detachTexture method, as textures do not require
2505 // allocation map management either here or in the resource manager at detach time.
2506 // Zero textures are held by the Context, and we don't attempt to request them from
2507 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002508 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002509}
2510
James Darpinian4d9d4832018-03-13 12:43:28 -07002511void Context::detachBuffer(Buffer *buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002512{
Yuly Novikov5807a532015-12-03 13:01:22 -05002513 // Simple pass-through to State's detachBuffer method, since
2514 // only buffer attachments to container objects that are bound to the current context
2515 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002516
Yuly Novikov5807a532015-12-03 13:01:22 -05002517 // [OpenGL ES 3.2] section 5.1.2 page 45:
2518 // Attachments to unbound container objects, such as
2519 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2520 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002521 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002522}
2523
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002524void Context::detachFramebuffer(GLuint framebuffer)
2525{
Shannon Woods53a94a82014-06-24 15:20:36 -04002526 // Framebuffer detachment is handled by Context, because 0 is a valid
2527 // Framebuffer object, and a pointer to it must be passed from Context
2528 // to State at binding time.
2529
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002530 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002531 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2532 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2533 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002534
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002535 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002536 {
2537 bindReadFramebuffer(0);
2538 }
2539
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002540 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002541 {
2542 bindDrawFramebuffer(0);
2543 }
2544}
2545
2546void Context::detachRenderbuffer(GLuint renderbuffer)
2547{
Jamie Madilla02315b2017-02-23 14:14:47 -05002548 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002549}
2550
Jamie Madill57a89722013-07-02 11:57:03 -04002551void Context::detachVertexArray(GLuint vertexArray)
2552{
Jamie Madill77a72f62015-04-14 11:18:32 -04002553 // Vertex array detachment is handled by Context, because 0 is a valid
2554 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002555 // binding time.
2556
Jamie Madill57a89722013-07-02 11:57:03 -04002557 // [OpenGL ES 3.0.2] section 2.10 page 43:
2558 // If a vertex array object that is currently bound is deleted, the binding
2559 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002560 if (mGLState.removeVertexArrayBinding(vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002561 {
2562 bindVertexArray(0);
2563 }
2564}
2565
Geoff Langc8058452014-02-03 12:04:11 -05002566void Context::detachTransformFeedback(GLuint transformFeedback)
2567{
Corentin Walleza2257da2016-04-19 16:43:12 -04002568 // Transform feedback detachment is handled by Context, because 0 is a valid
2569 // transform feedback, and a pointer to it must be passed from Context to State at
2570 // binding time.
2571
2572 // The OpenGL specification doesn't mention what should happen when the currently bound
2573 // transform feedback object is deleted. Since it is a container object, we treat it like
2574 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002575 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002576 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002577 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002578 }
Geoff Langc8058452014-02-03 12:04:11 -05002579}
2580
Jamie Madilldc356042013-07-19 16:36:57 -04002581void Context::detachSampler(GLuint sampler)
2582{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002583 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002584}
2585
Yunchao Hea336b902017-08-02 16:05:21 +08002586void Context::detachProgramPipeline(GLuint pipeline)
2587{
2588 mGLState.detachProgramPipeline(this, pipeline);
2589}
2590
Jamie Madill3ef140a2017-08-26 23:11:21 -04002591void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002592{
Shaodde78e82017-05-22 14:13:27 +08002593 mGLState.setVertexAttribDivisor(this, index, divisor);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002594}
2595
Jamie Madille29d1672013-07-19 16:36:57 -04002596void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2597{
Geoff Langc1984ed2016-10-07 12:41:00 -04002598 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002599 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002600 SetSamplerParameteri(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002601 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002602}
Jamie Madille29d1672013-07-19 16:36:57 -04002603
Geoff Langc1984ed2016-10-07 12:41:00 -04002604void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2605{
2606 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002607 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002608 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002609 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002610}
2611
Brandon Jones59770802018-04-02 13:18:42 -07002612void Context::samplerParameterivRobust(GLuint sampler,
2613 GLenum pname,
2614 GLsizei bufSize,
2615 const GLint *param)
2616{
2617 samplerParameteriv(sampler, pname, param);
2618}
2619
Jamie Madille29d1672013-07-19 16:36:57 -04002620void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2621{
Geoff Langc1984ed2016-10-07 12:41:00 -04002622 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002623 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002624 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002625 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002626}
2627
Geoff Langc1984ed2016-10-07 12:41:00 -04002628void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002629{
Geoff Langc1984ed2016-10-07 12:41:00 -04002630 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002631 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002632 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002633 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002634}
2635
Brandon Jones59770802018-04-02 13:18:42 -07002636void Context::samplerParameterfvRobust(GLuint sampler,
2637 GLenum pname,
2638 GLsizei bufSize,
2639 const GLfloat *param)
2640{
2641 samplerParameterfv(sampler, pname, param);
2642}
2643
Geoff Langc1984ed2016-10-07 12:41:00 -04002644void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002645{
Geoff Langc1984ed2016-10-07 12:41:00 -04002646 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002647 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002648 QuerySamplerParameteriv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002649 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002650}
Jamie Madill9675b802013-07-19 16:36:59 -04002651
Brandon Jones59770802018-04-02 13:18:42 -07002652void Context::getSamplerParameterivRobust(GLuint sampler,
2653 GLenum pname,
2654 GLsizei bufSize,
2655 GLsizei *length,
2656 GLint *params)
2657{
2658 getSamplerParameteriv(sampler, pname, params);
2659}
2660
Geoff Langc1984ed2016-10-07 12:41:00 -04002661void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2662{
2663 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002664 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002665 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002666 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002667}
2668
Brandon Jones59770802018-04-02 13:18:42 -07002669void Context::getSamplerParameterfvRobust(GLuint sampler,
2670 GLenum pname,
2671 GLsizei bufSize,
2672 GLsizei *length,
2673 GLfloat *params)
2674{
2675 getSamplerParameterfv(sampler, pname, params);
2676}
2677
Olli Etuahof0fee072016-03-30 15:11:58 +03002678void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2679{
2680 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002681 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002682}
2683
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002684void Context::initRendererString()
2685{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002686 std::ostringstream rendererString;
2687 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002688 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002689 rendererString << ")";
2690
Geoff Langcec35902014-04-16 10:52:36 -04002691 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002692}
2693
Geoff Langc339c4e2016-11-29 10:37:36 -05002694void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002695{
Geoff Langc339c4e2016-11-29 10:37:36 -05002696 const Version &clientVersion = getClientVersion();
2697
2698 std::ostringstream versionString;
2699 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2700 << ANGLE_VERSION_STRING << ")";
2701 mVersionString = MakeStaticString(versionString.str());
2702
2703 std::ostringstream shadingLanguageVersionString;
2704 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2705 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2706 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2707 << ")";
2708 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002709}
2710
Geoff Langcec35902014-04-16 10:52:36 -04002711void Context::initExtensionStrings()
2712{
Geoff Langc339c4e2016-11-29 10:37:36 -05002713 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2714 std::ostringstream combinedStringStream;
2715 std::copy(strings.begin(), strings.end(),
2716 std::ostream_iterator<const char *>(combinedStringStream, " "));
2717 return MakeStaticString(combinedStringStream.str());
2718 };
2719
2720 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002721 for (const auto &extensionString : mExtensions.getStrings())
2722 {
2723 mExtensionStrings.push_back(MakeStaticString(extensionString));
2724 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002725 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002726
Bryan Bernhart58806562017-01-05 13:09:31 -08002727 const gl::Extensions &nativeExtensions = mImplementation->getNativeExtensions();
2728
Geoff Langc339c4e2016-11-29 10:37:36 -05002729 mRequestableExtensionStrings.clear();
2730 for (const auto &extensionInfo : GetExtensionInfoMap())
2731 {
2732 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08002733 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
2734 nativeExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002735 {
2736 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
2737 }
2738 }
2739 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002740}
2741
Geoff Langc339c4e2016-11-29 10:37:36 -05002742const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04002743{
Geoff Langc339c4e2016-11-29 10:37:36 -05002744 switch (name)
2745 {
2746 case GL_VENDOR:
2747 return reinterpret_cast<const GLubyte *>("Google Inc.");
2748
2749 case GL_RENDERER:
2750 return reinterpret_cast<const GLubyte *>(mRendererString);
2751
2752 case GL_VERSION:
2753 return reinterpret_cast<const GLubyte *>(mVersionString);
2754
2755 case GL_SHADING_LANGUAGE_VERSION:
2756 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
2757
2758 case GL_EXTENSIONS:
2759 return reinterpret_cast<const GLubyte *>(mExtensionString);
2760
2761 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2762 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
2763
2764 default:
2765 UNREACHABLE();
2766 return nullptr;
2767 }
Geoff Langcec35902014-04-16 10:52:36 -04002768}
2769
Geoff Langc339c4e2016-11-29 10:37:36 -05002770const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04002771{
Geoff Langc339c4e2016-11-29 10:37:36 -05002772 switch (name)
2773 {
2774 case GL_EXTENSIONS:
2775 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
2776
2777 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2778 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
2779
2780 default:
2781 UNREACHABLE();
2782 return nullptr;
2783 }
Geoff Langcec35902014-04-16 10:52:36 -04002784}
2785
2786size_t Context::getExtensionStringCount() const
2787{
2788 return mExtensionStrings.size();
2789}
2790
Geoff Lang111a99e2017-10-17 10:58:41 -04002791bool Context::isExtensionRequestable(const char *name)
2792{
2793 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2794 auto extension = extensionInfos.find(name);
2795
2796 const Extensions &nativeExtensions = mImplementation->getNativeExtensions();
2797 return extension != extensionInfos.end() && extension->second.Requestable &&
2798 nativeExtensions.*(extension->second.ExtensionsMember);
2799}
2800
Geoff Langc339c4e2016-11-29 10:37:36 -05002801void Context::requestExtension(const char *name)
2802{
2803 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2804 ASSERT(extensionInfos.find(name) != extensionInfos.end());
2805 const auto &extension = extensionInfos.at(name);
2806 ASSERT(extension.Requestable);
Geoff Lang111a99e2017-10-17 10:58:41 -04002807 ASSERT(mImplementation->getNativeExtensions().*(extension.ExtensionsMember));
Geoff Langc339c4e2016-11-29 10:37:36 -05002808
2809 if (mExtensions.*(extension.ExtensionsMember))
2810 {
2811 // Extension already enabled
2812 return;
2813 }
2814
2815 mExtensions.*(extension.ExtensionsMember) = true;
2816 updateCaps();
2817 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08002818
Jamie Madill2f348d22017-06-05 10:50:59 -04002819 // Release the shader compiler so it will be re-created with the requested extensions enabled.
2820 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04002821
Jamie Madill81c2e252017-09-09 23:32:46 -04002822 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
2823 // sampleable.
Jamie Madilld4442552018-02-27 22:03:47 -05002824 mState.mTextures->signalAllTexturesDirty(this);
Geoff Lang9aded172017-04-05 11:07:56 -04002825 for (auto &zeroTexture : mZeroTextures)
2826 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002827 if (zeroTexture.get() != nullptr)
2828 {
2829 zeroTexture->signalDirty(this, InitState::Initialized);
2830 }
Geoff Lang9aded172017-04-05 11:07:56 -04002831 }
2832
2833 mState.mFramebuffers->invalidateFramebufferComplenessCache();
Geoff Langc339c4e2016-11-29 10:37:36 -05002834}
2835
2836size_t Context::getRequestableExtensionStringCount() const
2837{
2838 return mRequestableExtensionStrings.size();
2839}
2840
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002841void Context::beginTransformFeedback(GLenum primitiveMode)
2842{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002843 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002844 ASSERT(transformFeedback != nullptr);
2845 ASSERT(!transformFeedback->isPaused());
2846
Jamie Madill6c1f6712017-02-14 19:08:04 -05002847 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002848}
2849
2850bool Context::hasActiveTransformFeedback(GLuint program) const
2851{
2852 for (auto pair : mTransformFeedbackMap)
2853 {
2854 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
2855 {
2856 return true;
2857 }
2858 }
2859 return false;
2860}
2861
Geoff Langb433e872017-10-05 14:01:47 -04002862void Context::initCaps(const egl::DisplayExtensions &displayExtensions, bool robustResourceInit)
Geoff Lang493daf52014-07-03 13:38:44 -04002863{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002864 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04002865
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08002866 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
2867 if (getClientVersion() < Version(2, 0))
2868 {
2869 mCaps.maxMultitextureUnits = 4;
2870 mCaps.maxClipPlanes = 6;
2871 mCaps.maxLights = 8;
Lingfeng Yange547aac2018-04-05 09:39:20 -07002872 mCaps.maxModelviewMatrixStackDepth = Caps::GlobalMatrixStackDepth;
2873 mCaps.maxProjectionMatrixStackDepth = Caps::GlobalMatrixStackDepth;
2874 mCaps.maxTextureMatrixStackDepth = Caps::GlobalMatrixStackDepth;
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08002875 }
2876
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002877 mExtensions = mImplementation->getNativeExtensions();
Geoff Lang493daf52014-07-03 13:38:44 -04002878
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002879 mLimitations = mImplementation->getNativeLimitations();
Austin Kinross02df7962015-07-01 10:03:42 -07002880
Geoff Langeb66a6e2016-10-31 13:06:12 -04002881 if (getClientVersion() < Version(3, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002882 {
2883 // Disable ES3+ extensions
Jamie Madill231c7f52017-04-26 13:45:37 -04002884 mExtensions.colorBufferFloat = false;
Geoff Langb66a9092016-05-16 15:59:14 -04002885 mExtensions.eglImageExternalEssl3 = false;
Vincent Lang25ab4512016-05-13 18:13:59 +02002886 mExtensions.textureNorm16 = false;
Martin Radev137032d2017-07-13 10:11:12 +03002887 mExtensions.multiview = false;
2888 mExtensions.maxViews = 1u;
Geoff Lang493daf52014-07-03 13:38:44 -04002889 }
2890
Jiawei Shao89be29a2017-11-06 14:36:45 +08002891 if (getClientVersion() < ES_3_1)
2892 {
2893 // Disable ES3.1+ extensions
2894 mExtensions.geometryShader = false;
2895 }
2896
Geoff Langeb66a6e2016-10-31 13:06:12 -04002897 if (getClientVersion() > Version(2, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002898 {
2899 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
Jamie Madill231c7f52017-04-26 13:45:37 -04002900 // mExtensions.sRGB = false;
Geoff Lang493daf52014-07-03 13:38:44 -04002901 }
2902
Jamie Madill00ed7a12016-05-19 13:13:38 -04002903 // Some extensions are always available because they are implemented in the GL layer.
Jamie Madill231c7f52017-04-26 13:45:37 -04002904 mExtensions.bindUniformLocation = true;
2905 mExtensions.vertexArrayObject = true;
Geoff Langf41a7152016-09-19 15:11:17 -04002906 mExtensions.bindGeneratesResource = true;
Geoff Langfeb8c682017-02-13 16:07:35 -05002907 mExtensions.clientArrays = true;
Geoff Langc339c4e2016-11-29 10:37:36 -05002908 mExtensions.requestExtension = true;
Jamie Madill00ed7a12016-05-19 13:13:38 -04002909
2910 // Enable the no error extension if the context was created with the flag.
2911 mExtensions.noError = mSkipValidation;
2912
Corentin Wallezccab69d2017-01-27 16:57:15 -05002913 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Corentin Wallezc295e512017-01-27 17:47:50 -05002914 mExtensions.surfacelessContext = displayExtensions.surfacelessContext;
Corentin Wallezccab69d2017-01-27 16:57:15 -05002915
Geoff Lang70d0f492015-12-10 17:45:46 -05002916 // Explicitly enable GL_KHR_debug
2917 mExtensions.debug = true;
2918 mExtensions.maxDebugMessageLength = 1024;
2919 mExtensions.maxDebugLoggedMessages = 1024;
2920 mExtensions.maxDebugGroupStackDepth = 1024;
2921 mExtensions.maxLabelLength = 1024;
2922
Geoff Langff5b2d52016-09-07 11:32:23 -04002923 // Explicitly enable GL_ANGLE_robust_client_memory
2924 mExtensions.robustClientMemory = true;
2925
Jamie Madille08a1d32017-03-07 17:24:06 -05002926 // Determine robust resource init availability from EGL.
Geoff Langb433e872017-10-05 14:01:47 -04002927 mExtensions.robustResourceInitialization = robustResourceInit;
Jamie Madille08a1d32017-03-07 17:24:06 -05002928
Jiajia Qin8a7b3a02017-08-25 16:05:48 +08002929 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
2930 // supports it.
2931 mExtensions.robustBufferAccessBehavior =
2932 mRobustAccess && mExtensions.robustBufferAccessBehavior;
2933
Jamie Madillc43be722017-07-13 16:22:14 -04002934 // Enable the cache control query unconditionally.
2935 mExtensions.programCacheControl = true;
2936
Geoff Lang301d1612014-07-09 10:34:37 -04002937 // Apply implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04002938 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002939
Jamie Madill0f80ed82017-09-19 00:24:56 -04002940 if (getClientVersion() < ES_3_1)
2941 {
2942 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
2943 }
2944 else
2945 {
2946 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
2947 }
Geoff Lang301d1612014-07-09 10:34:37 -04002948
Jamie Madill0f80ed82017-09-19 00:24:56 -04002949 LimitCap(&mCaps.maxVertexUniformBlocks, IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
2950 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
2951 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
2952
2953 // Limit textures as well, so we can use fast bitsets with texture bindings.
2954 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
2955 LimitCap(&mCaps.maxVertexTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
2956 LimitCap(&mCaps.maxTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04002957
Jiawei Shaodb342272017-09-27 10:21:45 +08002958 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
2959
Geoff Langc287ea62016-09-16 14:46:51 -04002960 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002961 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04002962 for (const auto &extensionInfo : GetExtensionInfoMap())
2963 {
Geoff Lang0ab41fa2018-03-14 11:03:30 -04002964 // If the user has requested that extensions start disabled and they are requestable,
2965 // disable them.
2966 if (!mExtensionsEnabled && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04002967 {
2968 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
2969 }
2970 }
2971
2972 // Generate texture caps
2973 updateCaps();
2974}
2975
2976void Context::updateCaps()
2977{
Geoff Lang900013c2014-07-07 11:32:19 -04002978 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002979 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04002980
Jamie Madill7b62cf92017-11-02 15:20:49 -04002981 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04002982 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04002983 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04002984 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04002985
Geoff Lang0d8b7242015-09-09 14:56:53 -04002986 // Update the format caps based on the client version and extensions.
2987 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
2988 // ES3.
2989 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002990 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002991 formatCaps.renderable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002992 formatCaps.renderable && formatInfo.renderSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002993 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002994 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04002995
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002996 // OpenGL ES does not support multisampling with non-rendererable formats
2997 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Olli Etuaho50c562d2017-06-06 14:43:30 +03002998 if (!formatCaps.renderable ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002999 (getClientVersion() < ES_3_1 &&
3000 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04003001 {
Geoff Langd87878e2014-09-19 15:42:59 -04003002 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04003003 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03003004 else
3005 {
3006 // We may have limited the max samples for some required renderbuffer formats due to
3007 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
3008 GLuint formatMaxSamples = formatCaps.getMaxSamples();
3009
3010 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
3011 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
3012 // exception of signed and unsigned integer formats."
3013 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
3014 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
3015 {
3016 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
3017 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
3018 }
3019
3020 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
3021 if (getClientVersion() >= ES_3_1)
3022 {
3023 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
3024 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
3025 // the exception that the signed and unsigned integer formats are required only to
3026 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
3027 // multisamples, which must be at least one."
3028 if (formatInfo.componentType == GL_INT ||
3029 formatInfo.componentType == GL_UNSIGNED_INT)
3030 {
3031 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
3032 }
3033
3034 // GLES 3.1 section 19.3.1.
3035 if (formatCaps.texturable)
3036 {
3037 if (formatInfo.depthBits > 0)
3038 {
3039 mCaps.maxDepthTextureSamples =
3040 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
3041 }
3042 else if (formatInfo.redBits > 0)
3043 {
3044 mCaps.maxColorTextureSamples =
3045 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
3046 }
3047 }
3048 }
3049 }
Geoff Langd87878e2014-09-19 15:42:59 -04003050
3051 if (formatCaps.texturable && formatInfo.compressed)
3052 {
Geoff Langca271392017-04-05 12:30:00 -04003053 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003054 }
3055
Geoff Langca271392017-04-05 12:30:00 -04003056 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04003057 }
Jamie Madill32447362017-06-28 14:53:52 -04003058
3059 // If program binary is disabled, blank out the memory cache pointer.
3060 if (!mImplementation->getNativeExtensions().getProgramBinary)
3061 {
3062 mMemoryProgramCache = nullptr;
3063 }
Corentin Walleze4477002017-12-01 14:39:58 -05003064
3065 // Compute which buffer types are allowed
3066 mValidBufferBindings.reset();
3067 mValidBufferBindings.set(BufferBinding::ElementArray);
3068 mValidBufferBindings.set(BufferBinding::Array);
3069
3070 if (mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
3071 {
3072 mValidBufferBindings.set(BufferBinding::PixelPack);
3073 mValidBufferBindings.set(BufferBinding::PixelUnpack);
3074 }
3075
3076 if (getClientVersion() >= ES_3_0)
3077 {
3078 mValidBufferBindings.set(BufferBinding::CopyRead);
3079 mValidBufferBindings.set(BufferBinding::CopyWrite);
3080 mValidBufferBindings.set(BufferBinding::TransformFeedback);
3081 mValidBufferBindings.set(BufferBinding::Uniform);
3082 }
3083
3084 if (getClientVersion() >= ES_3_1)
3085 {
3086 mValidBufferBindings.set(BufferBinding::AtomicCounter);
3087 mValidBufferBindings.set(BufferBinding::ShaderStorage);
3088 mValidBufferBindings.set(BufferBinding::DrawIndirect);
3089 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
3090 }
Geoff Lang493daf52014-07-03 13:38:44 -04003091}
3092
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003093void Context::initWorkarounds()
3094{
Jamie Madill761b02c2017-06-23 16:27:06 -04003095 // Apply back-end workarounds.
3096 mImplementation->applyNativeWorkarounds(&mWorkarounds);
3097
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003098 // Lose the context upon out of memory error if the application is
3099 // expecting to watch for those events.
3100 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
3101}
3102
Jamie Madill05b35b22017-10-03 09:01:44 -04003103Error Context::prepareForDraw()
3104{
Geoff Langa8cb2872018-03-09 16:09:40 -05003105 ANGLE_TRY(syncDirtyObjects());
Jamie Madilla59fc192017-11-02 12:57:58 -04003106
3107 if (isRobustResourceInitEnabled())
3108 {
3109 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
3110 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
3111 }
3112
Geoff Langa8cb2872018-03-09 16:09:40 -05003113 ANGLE_TRY(syncDirtyBits());
Geoff Langd4fff502017-09-22 11:28:28 -04003114 return NoError();
3115}
3116
3117Error Context::prepareForClear(GLbitfield mask)
3118{
Geoff Langa8cb2872018-03-09 16:09:40 -05003119 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003120 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearAttachmentsInitialized(this, mask));
Geoff Langa8cb2872018-03-09 16:09:40 -05003121 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04003122 return NoError();
3123}
3124
3125Error Context::prepareForClearBuffer(GLenum buffer, GLint drawbuffer)
3126{
Geoff Langa8cb2872018-03-09 16:09:40 -05003127 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003128 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearBufferAttachmentsInitialized(this, buffer,
3129 drawbuffer));
Geoff Langa8cb2872018-03-09 16:09:40 -05003130 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill05b35b22017-10-03 09:01:44 -04003131 return NoError();
3132}
3133
Geoff Langa8cb2872018-03-09 16:09:40 -05003134Error Context::syncState()
Jamie Madill1b94d432015-08-07 13:23:23 -04003135{
Geoff Langa8cb2872018-03-09 16:09:40 -05003136 ANGLE_TRY(syncDirtyObjects());
3137 ANGLE_TRY(syncDirtyBits());
Jamie Madillbc918e72018-03-08 09:47:21 -05003138 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003139}
3140
Geoff Langa8cb2872018-03-09 16:09:40 -05003141Error Context::syncState(const State::DirtyBits &bitMask, const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04003142{
Geoff Langa8cb2872018-03-09 16:09:40 -05003143 ANGLE_TRY(syncDirtyObjects(objectMask));
3144 ANGLE_TRY(syncDirtyBits(bitMask));
Geoff Langd4fff502017-09-22 11:28:28 -04003145 return NoError();
3146}
3147
Geoff Langa8cb2872018-03-09 16:09:40 -05003148Error Context::syncDirtyBits()
Geoff Langd4fff502017-09-22 11:28:28 -04003149{
3150 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
3151 mImplementation->syncState(this, dirtyBits);
3152 mGLState.clearDirtyBits();
3153 return NoError();
3154}
3155
Geoff Langa8cb2872018-03-09 16:09:40 -05003156Error Context::syncDirtyBits(const State::DirtyBits &bitMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003157{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003158 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madillfe548342017-06-19 11:13:24 -04003159 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003160 mGLState.clearDirtyBits(dirtyBits);
Jamie Madillbc918e72018-03-08 09:47:21 -05003161 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003162}
Jamie Madillc29968b2016-01-20 11:17:23 -05003163
Geoff Langa8cb2872018-03-09 16:09:40 -05003164Error Context::syncDirtyObjects()
Geoff Langd4fff502017-09-22 11:28:28 -04003165{
3166 return mGLState.syncDirtyObjects(this);
3167}
3168
Geoff Langa8cb2872018-03-09 16:09:40 -05003169Error Context::syncDirtyObjects(const State::DirtyObjects &objectMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003170{
3171 return mGLState.syncDirtyObjects(this, objectMask);
3172}
3173
Jamie Madillc29968b2016-01-20 11:17:23 -05003174void Context::blitFramebuffer(GLint srcX0,
3175 GLint srcY0,
3176 GLint srcX1,
3177 GLint srcY1,
3178 GLint dstX0,
3179 GLint dstY0,
3180 GLint dstX1,
3181 GLint dstY1,
3182 GLbitfield mask,
3183 GLenum filter)
3184{
Qin Jiajiaaef92162018-02-27 13:51:44 +08003185 if (mask == 0)
3186 {
3187 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
3188 // buffers are copied.
3189 return;
3190 }
3191
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003192 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003193 ASSERT(drawFramebuffer);
3194
3195 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
3196 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
3197
Jamie Madillbc918e72018-03-08 09:47:21 -05003198 ANGLE_CONTEXT_TRY(syncStateForBlit());
Jamie Madillc29968b2016-01-20 11:17:23 -05003199
Jamie Madillc564c072017-06-01 12:45:42 -04003200 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003201}
Jamie Madillc29968b2016-01-20 11:17:23 -05003202
3203void Context::clear(GLbitfield mask)
3204{
Geoff Langd4fff502017-09-22 11:28:28 -04003205 ANGLE_CONTEXT_TRY(prepareForClear(mask));
3206 ANGLE_CONTEXT_TRY(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05003207}
3208
3209void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
3210{
Geoff Langd4fff502017-09-22 11:28:28 -04003211 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3212 ANGLE_CONTEXT_TRY(
3213 mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003214}
3215
3216void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3217{
Geoff Langd4fff502017-09-22 11:28:28 -04003218 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3219 ANGLE_CONTEXT_TRY(
3220 mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003221}
3222
3223void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3224{
Geoff Langd4fff502017-09-22 11:28:28 -04003225 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3226 ANGLE_CONTEXT_TRY(
3227 mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003228}
3229
3230void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3231{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003232 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003233 ASSERT(framebufferObject);
3234
3235 // If a buffer is not present, the clear has no effect
3236 if (framebufferObject->getDepthbuffer() == nullptr &&
3237 framebufferObject->getStencilbuffer() == nullptr)
3238 {
3239 return;
3240 }
3241
Geoff Langd4fff502017-09-22 11:28:28 -04003242 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3243 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003244}
3245
3246void Context::readPixels(GLint x,
3247 GLint y,
3248 GLsizei width,
3249 GLsizei height,
3250 GLenum format,
3251 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003252 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003253{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003254 if (width == 0 || height == 0)
3255 {
3256 return;
3257 }
3258
Jamie Madillbc918e72018-03-08 09:47:21 -05003259 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003260
Jamie Madillb6664922017-07-25 12:55:04 -04003261 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3262 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003263
3264 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04003265 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003266}
3267
Brandon Jones59770802018-04-02 13:18:42 -07003268void Context::readPixelsRobust(GLint x,
3269 GLint y,
3270 GLsizei width,
3271 GLsizei height,
3272 GLenum format,
3273 GLenum type,
3274 GLsizei bufSize,
3275 GLsizei *length,
3276 GLsizei *columns,
3277 GLsizei *rows,
3278 void *pixels)
3279{
3280 readPixels(x, y, width, height, format, type, pixels);
3281}
3282
3283void Context::readnPixelsRobust(GLint x,
3284 GLint y,
3285 GLsizei width,
3286 GLsizei height,
3287 GLenum format,
3288 GLenum type,
3289 GLsizei bufSize,
3290 GLsizei *length,
3291 GLsizei *columns,
3292 GLsizei *rows,
3293 void *data)
3294{
3295 readPixels(x, y, width, height, format, type, data);
3296}
3297
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003298void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003299 GLint level,
3300 GLenum internalformat,
3301 GLint x,
3302 GLint y,
3303 GLsizei width,
3304 GLsizei height,
3305 GLint border)
3306{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003307 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003308 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003309
Jamie Madillc29968b2016-01-20 11:17:23 -05003310 Rectangle sourceArea(x, y, width, height);
3311
Jamie Madill05b35b22017-10-03 09:01:44 -04003312 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003313 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003314 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003315}
3316
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003317void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003318 GLint level,
3319 GLint xoffset,
3320 GLint yoffset,
3321 GLint x,
3322 GLint y,
3323 GLsizei width,
3324 GLsizei height)
3325{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003326 if (width == 0 || height == 0)
3327 {
3328 return;
3329 }
3330
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003331 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003332 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003333
Jamie Madillc29968b2016-01-20 11:17:23 -05003334 Offset destOffset(xoffset, yoffset, 0);
3335 Rectangle sourceArea(x, y, width, height);
3336
Jamie Madill05b35b22017-10-03 09:01:44 -04003337 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003338 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003339 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003340}
3341
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003342void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003343 GLint level,
3344 GLint xoffset,
3345 GLint yoffset,
3346 GLint zoffset,
3347 GLint x,
3348 GLint y,
3349 GLsizei width,
3350 GLsizei height)
3351{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003352 if (width == 0 || height == 0)
3353 {
3354 return;
3355 }
3356
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003357 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003358 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003359
Jamie Madillc29968b2016-01-20 11:17:23 -05003360 Offset destOffset(xoffset, yoffset, zoffset);
3361 Rectangle sourceArea(x, y, width, height);
3362
Jamie Madill05b35b22017-10-03 09:01:44 -04003363 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3364 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003365 handleError(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level, destOffset,
3366 sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003367}
3368
3369void Context::framebufferTexture2D(GLenum target,
3370 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003371 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003372 GLuint texture,
3373 GLint level)
3374{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003375 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003376 ASSERT(framebuffer);
3377
3378 if (texture != 0)
3379 {
3380 Texture *textureObj = getTexture(texture);
3381
3382 ImageIndex index = ImageIndex::MakeInvalid();
3383
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003384 if (textarget == TextureTarget::_2D)
Jamie Madillc29968b2016-01-20 11:17:23 -05003385 {
3386 index = ImageIndex::Make2D(level);
3387 }
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003388 else if (textarget == TextureTarget::Rectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -04003389 {
3390 index = ImageIndex::MakeRectangle(level);
3391 }
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003392 else if (textarget == TextureTarget::_2DMultisample)
JiangYizhoubddc46b2016-12-09 09:50:51 +08003393 {
3394 ASSERT(level == 0);
3395 index = ImageIndex::Make2DMultisample();
3396 }
Jamie Madillc29968b2016-01-20 11:17:23 -05003397 else
3398 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003399 ASSERT(TextureTargetToType(textarget) == TextureType::CubeMap);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003400 index = ImageIndex::MakeCube(textarget, level);
Jamie Madillc29968b2016-01-20 11:17:23 -05003401 }
3402
Jamie Madilla02315b2017-02-23 14:14:47 -05003403 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003404 }
3405 else
3406 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003407 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003408 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003409
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003410 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003411}
3412
3413void Context::framebufferRenderbuffer(GLenum target,
3414 GLenum attachment,
3415 GLenum renderbuffertarget,
3416 GLuint renderbuffer)
3417{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003418 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003419 ASSERT(framebuffer);
3420
3421 if (renderbuffer != 0)
3422 {
3423 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003424
3425 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex::MakeInvalid(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003426 renderbufferObject);
3427 }
3428 else
3429 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003430 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003431 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003432
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003433 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003434}
3435
3436void Context::framebufferTextureLayer(GLenum target,
3437 GLenum attachment,
3438 GLuint texture,
3439 GLint level,
3440 GLint layer)
3441{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003442 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003443 ASSERT(framebuffer);
3444
3445 if (texture != 0)
3446 {
3447 Texture *textureObject = getTexture(texture);
3448
3449 ImageIndex index = ImageIndex::MakeInvalid();
3450
Corentin Wallez99d492c2018-02-27 15:17:10 -05003451 if (textureObject->getType() == TextureType::_3D)
Jamie Madillc29968b2016-01-20 11:17:23 -05003452 {
3453 index = ImageIndex::Make3D(level, layer);
3454 }
3455 else
3456 {
Corentin Wallez99d492c2018-02-27 15:17:10 -05003457 ASSERT(textureObject->getType() == TextureType::_2DArray);
Jamie Madillc29968b2016-01-20 11:17:23 -05003458 index = ImageIndex::Make2DArray(level, layer);
3459 }
3460
Jamie Madilla02315b2017-02-23 14:14:47 -05003461 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003462 }
3463 else
3464 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003465 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003466 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003467
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003468 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003469}
3470
Brandon Jones59770802018-04-02 13:18:42 -07003471void Context::framebufferTextureMultiviewLayered(GLenum target,
3472 GLenum attachment,
3473 GLuint texture,
3474 GLint level,
3475 GLint baseViewIndex,
3476 GLsizei numViews)
Martin Radev137032d2017-07-13 10:11:12 +03003477{
Martin Radev82ef7742017-08-08 17:44:58 +03003478 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3479 ASSERT(framebuffer);
3480
3481 if (texture != 0)
3482 {
3483 Texture *textureObj = getTexture(texture);
3484
Martin Radev18b75ba2017-08-15 15:50:40 +03003485 ImageIndex index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
Martin Radev82ef7742017-08-08 17:44:58 +03003486 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3487 numViews, baseViewIndex);
3488 }
3489 else
3490 {
3491 framebuffer->resetAttachment(this, attachment);
3492 }
3493
3494 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003495}
3496
Brandon Jones59770802018-04-02 13:18:42 -07003497void Context::framebufferTextureMultiviewSideBySide(GLenum target,
3498 GLenum attachment,
3499 GLuint texture,
3500 GLint level,
3501 GLsizei numViews,
3502 const GLint *viewportOffsets)
Martin Radev137032d2017-07-13 10:11:12 +03003503{
Martin Radev5dae57b2017-07-14 16:15:55 +03003504 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3505 ASSERT(framebuffer);
3506
3507 if (texture != 0)
3508 {
3509 Texture *textureObj = getTexture(texture);
3510
3511 ImageIndex index = ImageIndex::Make2D(level);
3512 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3513 textureObj, numViews, viewportOffsets);
3514 }
3515 else
3516 {
3517 framebuffer->resetAttachment(this, attachment);
3518 }
3519
3520 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003521}
3522
Jamie Madillc29968b2016-01-20 11:17:23 -05003523void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3524{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003525 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003526 ASSERT(framebuffer);
3527 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003528 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003529}
3530
3531void Context::readBuffer(GLenum mode)
3532{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003533 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003534 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003535 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003536}
3537
3538void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3539{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003540 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003541 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003542
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003543 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003544 ASSERT(framebuffer);
3545
3546 // The specification isn't clear what should be done when the framebuffer isn't complete.
3547 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003548 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003549}
3550
3551void Context::invalidateFramebuffer(GLenum target,
3552 GLsizei numAttachments,
3553 const GLenum *attachments)
3554{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003555 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003556 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003557
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003558 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003559 ASSERT(framebuffer);
3560
Jamie Madille98b1b52018-03-08 09:47:23 -05003561 bool complete = false;
3562 ANGLE_CONTEXT_TRY(framebuffer->isComplete(this, &complete));
3563 if (!complete)
Jamie Madillc29968b2016-01-20 11:17:23 -05003564 {
Jamie Madill437fa652016-05-03 15:13:24 -04003565 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003566 }
Jamie Madill437fa652016-05-03 15:13:24 -04003567
Jamie Madill4928b7c2017-06-20 12:57:39 -04003568 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003569}
3570
3571void Context::invalidateSubFramebuffer(GLenum target,
3572 GLsizei numAttachments,
3573 const GLenum *attachments,
3574 GLint x,
3575 GLint y,
3576 GLsizei width,
3577 GLsizei height)
3578{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003579 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003580 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003581
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003582 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003583 ASSERT(framebuffer);
3584
Jamie Madille98b1b52018-03-08 09:47:23 -05003585 bool complete = false;
3586 ANGLE_CONTEXT_TRY(framebuffer->isComplete(this, &complete));
3587 if (!complete)
Jamie Madillc29968b2016-01-20 11:17:23 -05003588 {
Jamie Madill437fa652016-05-03 15:13:24 -04003589 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003590 }
Jamie Madill437fa652016-05-03 15:13:24 -04003591
3592 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003593 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003594}
3595
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003596void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003597 GLint level,
3598 GLint internalformat,
3599 GLsizei width,
3600 GLsizei height,
3601 GLint border,
3602 GLenum format,
3603 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003604 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003605{
Jamie Madillbc918e72018-03-08 09:47:21 -05003606 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003607
3608 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003609 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003610 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3611 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003612}
3613
Brandon Jones59770802018-04-02 13:18:42 -07003614void Context::texImage2DRobust(TextureTarget target,
3615 GLint level,
3616 GLint internalformat,
3617 GLsizei width,
3618 GLsizei height,
3619 GLint border,
3620 GLenum format,
3621 GLenum type,
3622 GLsizei bufSize,
3623 const void *pixels)
3624{
3625 texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
3626}
3627
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003628void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003629 GLint level,
3630 GLint internalformat,
3631 GLsizei width,
3632 GLsizei height,
3633 GLsizei depth,
3634 GLint border,
3635 GLenum format,
3636 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003637 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003638{
Jamie Madillbc918e72018-03-08 09:47:21 -05003639 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003640
3641 Extents size(width, height, depth);
3642 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003643 handleError(texture->setImage(this, mGLState.getUnpackState(),
3644 NonCubeTextureTypeToTarget(target), level, internalformat, size,
3645 format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003646}
3647
Brandon Jones59770802018-04-02 13:18:42 -07003648void Context::texImage3DRobust(TextureType target,
3649 GLint level,
3650 GLint internalformat,
3651 GLsizei width,
3652 GLsizei height,
3653 GLsizei depth,
3654 GLint border,
3655 GLenum format,
3656 GLenum type,
3657 GLsizei bufSize,
3658 const void *pixels)
3659{
3660 texImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels);
3661}
3662
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003663void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003664 GLint level,
3665 GLint xoffset,
3666 GLint yoffset,
3667 GLsizei width,
3668 GLsizei height,
3669 GLenum format,
3670 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003671 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003672{
3673 // Zero sized uploads are valid but no-ops
3674 if (width == 0 || height == 0)
3675 {
3676 return;
3677 }
3678
Jamie Madillbc918e72018-03-08 09:47:21 -05003679 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003680
3681 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003682 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003683 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3684 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003685}
3686
Brandon Jones59770802018-04-02 13:18:42 -07003687void Context::texSubImage2DRobust(TextureTarget target,
3688 GLint level,
3689 GLint xoffset,
3690 GLint yoffset,
3691 GLsizei width,
3692 GLsizei height,
3693 GLenum format,
3694 GLenum type,
3695 GLsizei bufSize,
3696 const void *pixels)
3697{
3698 texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
3699}
3700
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003701void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003702 GLint level,
3703 GLint xoffset,
3704 GLint yoffset,
3705 GLint zoffset,
3706 GLsizei width,
3707 GLsizei height,
3708 GLsizei depth,
3709 GLenum format,
3710 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003711 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003712{
3713 // Zero sized uploads are valid but no-ops
3714 if (width == 0 || height == 0 || depth == 0)
3715 {
3716 return;
3717 }
3718
Jamie Madillbc918e72018-03-08 09:47:21 -05003719 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003720
3721 Box area(xoffset, yoffset, zoffset, width, height, depth);
3722 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003723 handleError(texture->setSubImage(this, mGLState.getUnpackState(),
3724 NonCubeTextureTypeToTarget(target), level, area, format, type,
3725 reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003726}
3727
Brandon Jones59770802018-04-02 13:18:42 -07003728void Context::texSubImage3DRobust(TextureType target,
3729 GLint level,
3730 GLint xoffset,
3731 GLint yoffset,
3732 GLint zoffset,
3733 GLsizei width,
3734 GLsizei height,
3735 GLsizei depth,
3736 GLenum format,
3737 GLenum type,
3738 GLsizei bufSize,
3739 const void *pixels)
3740{
3741 texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type,
3742 pixels);
3743}
3744
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003745void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003746 GLint level,
3747 GLenum internalformat,
3748 GLsizei width,
3749 GLsizei height,
3750 GLint border,
3751 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003752 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003753{
Jamie Madillbc918e72018-03-08 09:47:21 -05003754 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003755
3756 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003757 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003758 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
3759 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003760 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003761}
3762
Brandon Jones59770802018-04-02 13:18:42 -07003763void Context::compressedTexImage2DRobust(TextureTarget target,
3764 GLint level,
3765 GLenum internalformat,
3766 GLsizei width,
3767 GLsizei height,
3768 GLint border,
3769 GLsizei imageSize,
3770 GLsizei dataSize,
3771 const GLvoid *data)
3772{
3773 compressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
3774}
3775
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003776void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003777 GLint level,
3778 GLenum internalformat,
3779 GLsizei width,
3780 GLsizei height,
3781 GLsizei depth,
3782 GLint border,
3783 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003784 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003785{
Jamie Madillbc918e72018-03-08 09:47:21 -05003786 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003787
3788 Extents size(width, height, depth);
3789 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003790 handleError(texture->setCompressedImage(
3791 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
3792 size, imageSize, reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003793}
3794
Brandon Jones59770802018-04-02 13:18:42 -07003795void Context::compressedTexImage3DRobust(TextureType target,
3796 GLint level,
3797 GLenum internalformat,
3798 GLsizei width,
3799 GLsizei height,
3800 GLsizei depth,
3801 GLint border,
3802 GLsizei imageSize,
3803 GLsizei dataSize,
3804 const GLvoid *data)
3805{
3806 compressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize,
3807 data);
3808}
3809
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003810void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003811 GLint level,
3812 GLint xoffset,
3813 GLint yoffset,
3814 GLsizei width,
3815 GLsizei height,
3816 GLenum format,
3817 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003818 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003819{
Jamie Madillbc918e72018-03-08 09:47:21 -05003820 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003821
3822 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003823 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003824 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
3825 format, imageSize,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003826 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003827}
3828
Brandon Jones59770802018-04-02 13:18:42 -07003829void Context::compressedTexSubImage2DRobust(TextureTarget target,
3830 GLint level,
3831 GLint xoffset,
3832 GLint yoffset,
3833 GLsizei width,
3834 GLsizei height,
3835 GLenum format,
3836 GLsizei imageSize,
3837 GLsizei dataSize,
3838 const GLvoid *data)
3839{
3840 compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize,
3841 data);
3842}
3843
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003844void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003845 GLint level,
3846 GLint xoffset,
3847 GLint yoffset,
3848 GLint zoffset,
3849 GLsizei width,
3850 GLsizei height,
3851 GLsizei depth,
3852 GLenum format,
3853 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003854 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003855{
3856 // Zero sized uploads are valid but no-ops
3857 if (width == 0 || height == 0)
3858 {
3859 return;
3860 }
3861
Jamie Madillbc918e72018-03-08 09:47:21 -05003862 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003863
3864 Box area(xoffset, yoffset, zoffset, width, height, depth);
3865 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003866 handleError(texture->setCompressedSubImage(
3867 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
3868 imageSize, reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003869}
3870
Brandon Jones59770802018-04-02 13:18:42 -07003871void Context::compressedTexSubImage3DRobust(TextureType target,
3872 GLint level,
3873 GLint xoffset,
3874 GLint yoffset,
3875 GLint zoffset,
3876 GLsizei width,
3877 GLsizei height,
3878 GLsizei depth,
3879 GLenum format,
3880 GLsizei imageSize,
3881 GLsizei dataSize,
3882 const GLvoid *data)
3883{
3884 compressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format,
3885 imageSize, data);
3886}
3887
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003888void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003889{
3890 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003891 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003892}
3893
Jamie Madill007530e2017-12-28 14:27:04 -05003894void Context::copyTexture(GLuint sourceId,
3895 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05003896 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05003897 GLuint destId,
3898 GLint destLevel,
3899 GLint internalFormat,
3900 GLenum destType,
3901 GLboolean unpackFlipY,
3902 GLboolean unpackPremultiplyAlpha,
3903 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07003904{
Jamie Madillbc918e72018-03-08 09:47:21 -05003905 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07003906
3907 gl::Texture *sourceTexture = getTexture(sourceId);
3908 gl::Texture *destTexture = getTexture(destId);
Geoff Lang92019432017-11-20 13:09:34 -05003909 handleError(destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType,
3910 sourceLevel, ConvertToBool(unpackFlipY),
3911 ConvertToBool(unpackPremultiplyAlpha),
3912 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003913}
3914
Jamie Madill007530e2017-12-28 14:27:04 -05003915void Context::copySubTexture(GLuint sourceId,
3916 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05003917 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05003918 GLuint destId,
3919 GLint destLevel,
3920 GLint xoffset,
3921 GLint yoffset,
3922 GLint x,
3923 GLint y,
3924 GLsizei width,
3925 GLsizei height,
3926 GLboolean unpackFlipY,
3927 GLboolean unpackPremultiplyAlpha,
3928 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07003929{
3930 // Zero sized copies are valid but no-ops
3931 if (width == 0 || height == 0)
3932 {
3933 return;
3934 }
3935
Jamie Madillbc918e72018-03-08 09:47:21 -05003936 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07003937
3938 gl::Texture *sourceTexture = getTexture(sourceId);
3939 gl::Texture *destTexture = getTexture(destId);
3940 Offset offset(xoffset, yoffset, 0);
3941 Rectangle area(x, y, width, height);
Geoff Lang92019432017-11-20 13:09:34 -05003942 handleError(destTexture->copySubTexture(this, destTarget, destLevel, offset, sourceLevel, area,
3943 ConvertToBool(unpackFlipY),
3944 ConvertToBool(unpackPremultiplyAlpha),
3945 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003946}
3947
Jamie Madill007530e2017-12-28 14:27:04 -05003948void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07003949{
Jamie Madillbc918e72018-03-08 09:47:21 -05003950 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07003951
3952 gl::Texture *sourceTexture = getTexture(sourceId);
3953 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05003954 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07003955}
3956
Corentin Wallez336129f2017-10-17 15:55:40 -04003957void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03003958{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003959 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003960 ASSERT(buffer);
3961
Geoff Lang496c02d2016-10-20 11:38:11 -07003962 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03003963}
3964
Brandon Jones59770802018-04-02 13:18:42 -07003965void Context::getBufferPointervRobust(BufferBinding target,
3966 GLenum pname,
3967 GLsizei bufSize,
3968 GLsizei *length,
3969 void **params)
3970{
3971 getBufferPointerv(target, pname, params);
3972}
3973
Corentin Wallez336129f2017-10-17 15:55:40 -04003974void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003975{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003976 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003977 ASSERT(buffer);
3978
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003979 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003980 if (error.isError())
3981 {
Jamie Madill437fa652016-05-03 15:13:24 -04003982 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003983 return nullptr;
3984 }
3985
3986 return buffer->getMapPointer();
3987}
3988
Corentin Wallez336129f2017-10-17 15:55:40 -04003989GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03003990{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003991 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003992 ASSERT(buffer);
3993
3994 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003995 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03003996 if (error.isError())
3997 {
Jamie Madill437fa652016-05-03 15:13:24 -04003998 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003999 return GL_FALSE;
4000 }
4001
4002 return result;
4003}
4004
Corentin Wallez336129f2017-10-17 15:55:40 -04004005void *Context::mapBufferRange(BufferBinding target,
4006 GLintptr offset,
4007 GLsizeiptr length,
4008 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004009{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004010 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004011 ASSERT(buffer);
4012
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004013 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004014 if (error.isError())
4015 {
Jamie Madill437fa652016-05-03 15:13:24 -04004016 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004017 return nullptr;
4018 }
4019
4020 return buffer->getMapPointer();
4021}
4022
Corentin Wallez336129f2017-10-17 15:55:40 -04004023void Context::flushMappedBufferRange(BufferBinding /*target*/,
4024 GLintptr /*offset*/,
4025 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03004026{
4027 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
4028}
4029
Jamie Madillbc918e72018-03-08 09:47:21 -05004030Error Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004031{
Geoff Langa8cb2872018-03-09 16:09:40 -05004032 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004033}
4034
Jamie Madillbc918e72018-03-08 09:47:21 -05004035Error Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004036{
Geoff Langa8cb2872018-03-09 16:09:40 -05004037 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004038}
4039
Jamie Madillbc918e72018-03-08 09:47:21 -05004040Error Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004041{
Geoff Langa8cb2872018-03-09 16:09:40 -05004042 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004043}
4044
Jiajia Qin5451d532017-11-16 17:16:34 +08004045void Context::activeShaderProgram(GLuint pipeline, GLuint program)
4046{
4047 UNIMPLEMENTED();
4048}
4049
Jamie Madillc20ab272016-06-09 07:20:46 -07004050void Context::activeTexture(GLenum texture)
4051{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004052 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004053}
4054
Jamie Madill876429b2017-04-20 15:46:24 -04004055void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004056{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004057 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004058}
4059
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004060void Context::blendEquation(GLenum mode)
4061{
4062 mGLState.setBlendEquation(mode, mode);
4063}
4064
Jamie Madillc20ab272016-06-09 07:20:46 -07004065void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
4066{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004067 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004068}
4069
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004070void Context::blendFunc(GLenum sfactor, GLenum dfactor)
4071{
4072 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
4073}
4074
Jamie Madillc20ab272016-06-09 07:20:46 -07004075void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
4076{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004077 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004078}
4079
Jamie Madill876429b2017-04-20 15:46:24 -04004080void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004081{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004082 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004083}
4084
Jamie Madill876429b2017-04-20 15:46:24 -04004085void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07004086{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004087 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07004088}
4089
4090void Context::clearStencil(GLint s)
4091{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004092 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07004093}
4094
4095void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
4096{
Geoff Lang92019432017-11-20 13:09:34 -05004097 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
4098 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004099}
4100
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004101void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07004102{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004103 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004104}
4105
4106void Context::depthFunc(GLenum func)
4107{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004108 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07004109}
4110
4111void Context::depthMask(GLboolean flag)
4112{
Geoff Lang92019432017-11-20 13:09:34 -05004113 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07004114}
4115
Jamie Madill876429b2017-04-20 15:46:24 -04004116void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07004117{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004118 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07004119}
4120
4121void Context::disable(GLenum cap)
4122{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004123 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07004124}
4125
4126void Context::disableVertexAttribArray(GLuint index)
4127{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004128 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07004129}
4130
4131void Context::enable(GLenum cap)
4132{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004133 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07004134}
4135
4136void Context::enableVertexAttribArray(GLuint index)
4137{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004138 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07004139}
4140
4141void Context::frontFace(GLenum mode)
4142{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004143 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004144}
4145
4146void Context::hint(GLenum target, GLenum mode)
4147{
4148 switch (target)
4149 {
4150 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004151 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004152 break;
4153
4154 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004155 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004156 break;
4157
4158 default:
4159 UNREACHABLE();
4160 return;
4161 }
4162}
4163
4164void Context::lineWidth(GLfloat width)
4165{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004166 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07004167}
4168
4169void Context::pixelStorei(GLenum pname, GLint param)
4170{
4171 switch (pname)
4172 {
4173 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004174 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004175 break;
4176
4177 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004178 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004179 break;
4180
4181 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004182 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004183 break;
4184
4185 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004186 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004187 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004188 break;
4189
4190 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03004191 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004192 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004193 break;
4194
4195 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03004196 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004197 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004198 break;
4199
4200 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004201 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004202 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004203 break;
4204
4205 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004206 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004207 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004208 break;
4209
4210 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004211 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004212 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004213 break;
4214
4215 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004216 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004217 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004218 break;
4219
4220 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004221 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004222 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004223 break;
4224
4225 default:
4226 UNREACHABLE();
4227 return;
4228 }
4229}
4230
4231void Context::polygonOffset(GLfloat factor, GLfloat units)
4232{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004233 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07004234}
4235
Jamie Madill876429b2017-04-20 15:46:24 -04004236void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07004237{
Geoff Lang92019432017-11-20 13:09:34 -05004238 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07004239}
4240
Jiawei Shaodb342272017-09-27 10:21:45 +08004241void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
4242{
4243 mGLState.setSampleMaskParams(maskNumber, mask);
4244}
4245
Jamie Madillc20ab272016-06-09 07:20:46 -07004246void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
4247{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004248 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004249}
4250
4251void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
4252{
4253 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4254 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004255 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004256 }
4257
4258 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4259 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004260 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004261 }
4262}
4263
4264void Context::stencilMaskSeparate(GLenum face, GLuint mask)
4265{
4266 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4267 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004268 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004269 }
4270
4271 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4272 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004273 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004274 }
4275}
4276
4277void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4278{
4279 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4280 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004281 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004282 }
4283
4284 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4285 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004286 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004287 }
4288}
4289
4290void Context::vertexAttrib1f(GLuint index, GLfloat x)
4291{
4292 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004293 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004294}
4295
4296void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
4297{
4298 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004299 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004300}
4301
4302void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4303{
4304 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004305 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004306}
4307
4308void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
4309{
4310 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004311 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004312}
4313
4314void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4315{
4316 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004317 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004318}
4319
4320void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
4321{
4322 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004323 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004324}
4325
4326void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4327{
4328 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004329 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004330}
4331
4332void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
4333{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004334 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07004335}
4336
4337void Context::vertexAttribPointer(GLuint index,
4338 GLint size,
4339 GLenum type,
4340 GLboolean normalized,
4341 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004342 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07004343{
Corentin Wallez336129f2017-10-17 15:55:40 -04004344 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05004345 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc20ab272016-06-09 07:20:46 -07004346}
4347
Shao80957d92017-02-20 21:25:59 +08004348void Context::vertexAttribFormat(GLuint attribIndex,
4349 GLint size,
4350 GLenum type,
4351 GLboolean normalized,
4352 GLuint relativeOffset)
4353{
Geoff Lang92019432017-11-20 13:09:34 -05004354 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08004355 relativeOffset);
4356}
4357
4358void Context::vertexAttribIFormat(GLuint attribIndex,
4359 GLint size,
4360 GLenum type,
4361 GLuint relativeOffset)
4362{
4363 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
4364}
4365
4366void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4367{
Shaodde78e82017-05-22 14:13:27 +08004368 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Shao80957d92017-02-20 21:25:59 +08004369}
4370
Jiajia Qin5451d532017-11-16 17:16:34 +08004371void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004372{
4373 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
4374}
4375
Jamie Madillc20ab272016-06-09 07:20:46 -07004376void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4377{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004378 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004379}
4380
4381void Context::vertexAttribIPointer(GLuint index,
4382 GLint size,
4383 GLenum type,
4384 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004385 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004386{
Corentin Wallez336129f2017-10-17 15:55:40 -04004387 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
4388 size, type, false, true, stride, pointer);
Jamie Madillc20ab272016-06-09 07:20:46 -07004389}
4390
4391void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4392{
4393 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004394 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004395}
4396
4397void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4398{
4399 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004400 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004401}
4402
4403void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4404{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004405 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004406}
4407
4408void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4409{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004410 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004411}
4412
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004413void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4414{
4415 const VertexAttribCurrentValueData &currentValues =
4416 getGLState().getVertexAttribCurrentValue(index);
4417 const VertexArray *vao = getGLState().getVertexArray();
4418 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4419 currentValues, pname, params);
4420}
4421
Brandon Jones59770802018-04-02 13:18:42 -07004422void Context::getVertexAttribivRobust(GLuint index,
4423 GLenum pname,
4424 GLsizei bufSize,
4425 GLsizei *length,
4426 GLint *params)
4427{
4428 getVertexAttribiv(index, pname, params);
4429}
4430
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004431void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4432{
4433 const VertexAttribCurrentValueData &currentValues =
4434 getGLState().getVertexAttribCurrentValue(index);
4435 const VertexArray *vao = getGLState().getVertexArray();
4436 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4437 currentValues, pname, params);
4438}
4439
Brandon Jones59770802018-04-02 13:18:42 -07004440void Context::getVertexAttribfvRobust(GLuint index,
4441 GLenum pname,
4442 GLsizei bufSize,
4443 GLsizei *length,
4444 GLfloat *params)
4445{
4446 getVertexAttribfv(index, pname, params);
4447}
4448
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004449void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4450{
4451 const VertexAttribCurrentValueData &currentValues =
4452 getGLState().getVertexAttribCurrentValue(index);
4453 const VertexArray *vao = getGLState().getVertexArray();
4454 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4455 currentValues, pname, params);
4456}
4457
Brandon Jones59770802018-04-02 13:18:42 -07004458void Context::getVertexAttribIivRobust(GLuint index,
4459 GLenum pname,
4460 GLsizei bufSize,
4461 GLsizei *length,
4462 GLint *params)
4463{
4464 getVertexAttribIiv(index, pname, params);
4465}
4466
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004467void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4468{
4469 const VertexAttribCurrentValueData &currentValues =
4470 getGLState().getVertexAttribCurrentValue(index);
4471 const VertexArray *vao = getGLState().getVertexArray();
4472 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4473 currentValues, pname, params);
4474}
4475
Brandon Jones59770802018-04-02 13:18:42 -07004476void Context::getVertexAttribIuivRobust(GLuint index,
4477 GLenum pname,
4478 GLsizei bufSize,
4479 GLsizei *length,
4480 GLuint *params)
4481{
4482 getVertexAttribIuiv(index, pname, params);
4483}
4484
Jamie Madill876429b2017-04-20 15:46:24 -04004485void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004486{
4487 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
4488 QueryVertexAttribPointerv(attrib, pname, pointer);
4489}
4490
Brandon Jones59770802018-04-02 13:18:42 -07004491void Context::getVertexAttribPointervRobust(GLuint index,
4492 GLenum pname,
4493 GLsizei bufSize,
4494 GLsizei *length,
4495 void **pointer)
4496{
4497 getVertexAttribPointerv(index, pname, pointer);
4498}
4499
Jamie Madillc20ab272016-06-09 07:20:46 -07004500void Context::debugMessageControl(GLenum source,
4501 GLenum type,
4502 GLenum severity,
4503 GLsizei count,
4504 const GLuint *ids,
4505 GLboolean enabled)
4506{
4507 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004508 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05004509 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004510}
4511
4512void Context::debugMessageInsert(GLenum source,
4513 GLenum type,
4514 GLuint id,
4515 GLenum severity,
4516 GLsizei length,
4517 const GLchar *buf)
4518{
4519 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004520 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004521}
4522
4523void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4524{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004525 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004526}
4527
4528GLuint Context::getDebugMessageLog(GLuint count,
4529 GLsizei bufSize,
4530 GLenum *sources,
4531 GLenum *types,
4532 GLuint *ids,
4533 GLenum *severities,
4534 GLsizei *lengths,
4535 GLchar *messageLog)
4536{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004537 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4538 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004539}
4540
4541void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4542{
4543 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004544 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05004545 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07004546}
4547
4548void Context::popDebugGroup()
4549{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004550 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05004551 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004552}
4553
Corentin Wallez336129f2017-10-17 15:55:40 -04004554void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004555{
4556 Buffer *buffer = mGLState.getTargetBuffer(target);
4557 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004558 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004559}
4560
Corentin Wallez336129f2017-10-17 15:55:40 -04004561void Context::bufferSubData(BufferBinding target,
4562 GLintptr offset,
4563 GLsizeiptr size,
4564 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004565{
4566 if (data == nullptr)
4567 {
4568 return;
4569 }
4570
4571 Buffer *buffer = mGLState.getTargetBuffer(target);
4572 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004573 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004574}
4575
Jamie Madillef300b12016-10-07 15:12:09 -04004576void Context::attachShader(GLuint program, GLuint shader)
4577{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05004578 Program *programObject = mState.mShaderPrograms->getProgram(program);
4579 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004580 ASSERT(programObject && shaderObject);
4581 programObject->attachShader(shaderObject);
4582}
4583
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004584const Workarounds &Context::getWorkarounds() const
4585{
4586 return mWorkarounds;
4587}
4588
Corentin Wallez336129f2017-10-17 15:55:40 -04004589void Context::copyBufferSubData(BufferBinding readTarget,
4590 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04004591 GLintptr readOffset,
4592 GLintptr writeOffset,
4593 GLsizeiptr size)
4594{
4595 // if size is zero, the copy is a successful no-op
4596 if (size == 0)
4597 {
4598 return;
4599 }
4600
4601 // TODO(jmadill): cache these.
4602 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4603 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4604
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004605 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004606}
4607
Jamie Madill01a80ee2016-11-07 12:06:18 -05004608void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4609{
4610 Program *programObject = getProgram(program);
4611 // TODO(jmadill): Re-use this from the validation if possible.
4612 ASSERT(programObject);
4613 programObject->bindAttributeLocation(index, name);
4614}
4615
Corentin Wallez336129f2017-10-17 15:55:40 -04004616void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004617{
Corentin Wallez336129f2017-10-17 15:55:40 -04004618 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4619 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004620}
4621
Corentin Wallez336129f2017-10-17 15:55:40 -04004622void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08004623{
4624 bindBufferRange(target, index, buffer, 0, 0);
4625}
4626
Corentin Wallez336129f2017-10-17 15:55:40 -04004627void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08004628 GLuint index,
4629 GLuint buffer,
4630 GLintptr offset,
4631 GLsizeiptr size)
4632{
Corentin Wallez336129f2017-10-17 15:55:40 -04004633 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4634 mGLState.setIndexedBufferBinding(this, target, index, bufferObject, offset, size);
Jiajia Qin6eafb042016-12-27 17:04:07 +08004635}
4636
Jamie Madill01a80ee2016-11-07 12:06:18 -05004637void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
4638{
4639 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4640 {
4641 bindReadFramebuffer(framebuffer);
4642 }
4643
4644 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4645 {
4646 bindDrawFramebuffer(framebuffer);
4647 }
4648}
4649
4650void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4651{
4652 ASSERT(target == GL_RENDERBUFFER);
4653 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004654 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04004655 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004656}
4657
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004658void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08004659 GLsizei samples,
4660 GLenum internalformat,
4661 GLsizei width,
4662 GLsizei height,
4663 GLboolean fixedsamplelocations)
4664{
4665 Extents size(width, height, 1);
4666 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004667 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
4668 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004669}
4670
4671void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4672{
JiangYizhou5b03f472017-01-09 10:22:53 +08004673 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
4674 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillbc918e72018-03-08 09:47:21 -05004675 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
JiangYizhou5b03f472017-01-09 10:22:53 +08004676 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08004677
4678 switch (pname)
4679 {
4680 case GL_SAMPLE_POSITION:
4681 handleError(framebuffer->getSamplePosition(index, val));
4682 break;
4683 default:
4684 UNREACHABLE();
4685 }
4686}
4687
Jamie Madille8fb6402017-02-14 17:56:40 -05004688void Context::renderbufferStorage(GLenum target,
4689 GLenum internalformat,
4690 GLsizei width,
4691 GLsizei height)
4692{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004693 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4694 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
4695
Jamie Madille8fb6402017-02-14 17:56:40 -05004696 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04004697 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004698}
4699
4700void Context::renderbufferStorageMultisample(GLenum target,
4701 GLsizei samples,
4702 GLenum internalformat,
4703 GLsizei width,
4704 GLsizei height)
4705{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004706 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4707 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05004708
4709 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004710 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04004711 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004712}
4713
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004714void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
4715{
Jamie Madill70b5bb02017-08-28 13:32:37 -04004716 const Sync *syncObject = getSync(sync);
Geoff Lang82483b92017-04-11 15:33:00 -04004717 handleError(QuerySynciv(syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004718}
4719
JiangYizhoue18e6392017-02-20 10:32:23 +08004720void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
4721{
4722 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4723 QueryFramebufferParameteriv(framebuffer, pname, params);
4724}
4725
Jiajia Qin5451d532017-11-16 17:16:34 +08004726void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08004727{
4728 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4729 SetFramebufferParameteri(framebuffer, pname, param);
4730}
4731
Jamie Madillb3f26b92017-07-19 15:07:41 -04004732Error Context::getScratchBuffer(size_t requstedSizeBytes,
4733 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05004734{
Jamie Madillb3f26b92017-07-19 15:07:41 -04004735 if (!mScratchBuffer.get(requstedSizeBytes, scratchBufferOut))
4736 {
4737 return OutOfMemory() << "Failed to allocate internal buffer.";
4738 }
4739 return NoError();
4740}
4741
4742Error Context::getZeroFilledBuffer(size_t requstedSizeBytes,
4743 angle::MemoryBuffer **zeroBufferOut) const
4744{
4745 if (!mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0))
Jamie Madille14951e2017-03-09 18:55:16 -05004746 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004747 return OutOfMemory() << "Failed to allocate internal buffer.";
Jamie Madille14951e2017-03-09 18:55:16 -05004748 }
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004749 return NoError();
Jamie Madille14951e2017-03-09 18:55:16 -05004750}
4751
Xinghua Cao10a4d432017-11-28 14:46:26 +08004752Error Context::prepareForDispatch()
4753{
Geoff Langa8cb2872018-03-09 16:09:40 -05004754 ANGLE_TRY(syncState(mComputeDirtyBits, mComputeDirtyObjects));
Xinghua Cao10a4d432017-11-28 14:46:26 +08004755
4756 if (isRobustResourceInitEnabled())
4757 {
4758 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
4759 }
4760
4761 return NoError();
4762}
4763
Xinghua Cao2b396592017-03-29 15:36:04 +08004764void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
4765{
4766 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
4767 {
4768 return;
4769 }
4770
Xinghua Cao10a4d432017-11-28 14:46:26 +08004771 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill71c88b32017-09-14 22:20:29 -04004772 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08004773}
4774
Jiajia Qin5451d532017-11-16 17:16:34 +08004775void Context::dispatchComputeIndirect(GLintptr indirect)
4776{
Qin Jiajia62fcf622017-11-30 16:16:12 +08004777 ANGLE_CONTEXT_TRY(prepareForDispatch());
4778 handleError(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08004779}
4780
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004781void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08004782 GLsizei levels,
4783 GLenum internalFormat,
4784 GLsizei width,
4785 GLsizei height)
4786{
4787 Extents size(width, height, 1);
4788 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004789 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08004790}
4791
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004792void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08004793 GLsizei levels,
4794 GLenum internalFormat,
4795 GLsizei width,
4796 GLsizei height,
4797 GLsizei depth)
4798{
4799 Extents size(width, height, depth);
4800 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004801 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08004802}
4803
Jiajia Qin5451d532017-11-16 17:16:34 +08004804void Context::memoryBarrier(GLbitfield barriers)
4805{
Xinghua Cao89c422a2017-11-29 18:24:20 +08004806 handleError(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08004807}
4808
4809void Context::memoryBarrierByRegion(GLbitfield barriers)
4810{
Xinghua Cao89c422a2017-11-29 18:24:20 +08004811 handleError(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08004812}
4813
Jamie Madillc1d770e2017-04-13 17:31:24 -04004814GLenum Context::checkFramebufferStatus(GLenum target)
4815{
4816 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4817 ASSERT(framebuffer);
4818
Jamie Madille98b1b52018-03-08 09:47:23 -05004819 GLenum status = GL_NONE;
4820 Error err = framebuffer->checkStatus(this, &status);
4821 if (err.isError())
4822 {
4823 handleError(err);
4824 return 0;
4825 }
4826 return status;
Jamie Madillc1d770e2017-04-13 17:31:24 -04004827}
4828
4829void Context::compileShader(GLuint shader)
4830{
4831 Shader *shaderObject = GetValidShader(this, shader);
4832 if (!shaderObject)
4833 {
4834 return;
4835 }
4836 shaderObject->compile(this);
4837}
4838
4839void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
4840{
4841 for (int i = 0; i < n; i++)
4842 {
4843 deleteBuffer(buffers[i]);
4844 }
4845}
4846
4847void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
4848{
4849 for (int i = 0; i < n; i++)
4850 {
4851 if (framebuffers[i] != 0)
4852 {
4853 deleteFramebuffer(framebuffers[i]);
4854 }
4855 }
4856}
4857
4858void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
4859{
4860 for (int i = 0; i < n; i++)
4861 {
4862 deleteRenderbuffer(renderbuffers[i]);
4863 }
4864}
4865
4866void Context::deleteTextures(GLsizei n, const GLuint *textures)
4867{
4868 for (int i = 0; i < n; i++)
4869 {
4870 if (textures[i] != 0)
4871 {
4872 deleteTexture(textures[i]);
4873 }
4874 }
4875}
4876
4877void Context::detachShader(GLuint program, GLuint shader)
4878{
4879 Program *programObject = getProgram(program);
4880 ASSERT(programObject);
4881
4882 Shader *shaderObject = getShader(shader);
4883 ASSERT(shaderObject);
4884
4885 programObject->detachShader(this, shaderObject);
4886}
4887
4888void Context::genBuffers(GLsizei n, GLuint *buffers)
4889{
4890 for (int i = 0; i < n; i++)
4891 {
4892 buffers[i] = createBuffer();
4893 }
4894}
4895
4896void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
4897{
4898 for (int i = 0; i < n; i++)
4899 {
4900 framebuffers[i] = createFramebuffer();
4901 }
4902}
4903
4904void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
4905{
4906 for (int i = 0; i < n; i++)
4907 {
4908 renderbuffers[i] = createRenderbuffer();
4909 }
4910}
4911
4912void Context::genTextures(GLsizei n, GLuint *textures)
4913{
4914 for (int i = 0; i < n; i++)
4915 {
4916 textures[i] = createTexture();
4917 }
4918}
4919
4920void Context::getActiveAttrib(GLuint program,
4921 GLuint index,
4922 GLsizei bufsize,
4923 GLsizei *length,
4924 GLint *size,
4925 GLenum *type,
4926 GLchar *name)
4927{
4928 Program *programObject = getProgram(program);
4929 ASSERT(programObject);
4930 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
4931}
4932
4933void Context::getActiveUniform(GLuint program,
4934 GLuint index,
4935 GLsizei bufsize,
4936 GLsizei *length,
4937 GLint *size,
4938 GLenum *type,
4939 GLchar *name)
4940{
4941 Program *programObject = getProgram(program);
4942 ASSERT(programObject);
4943 programObject->getActiveUniform(index, bufsize, length, size, type, name);
4944}
4945
4946void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
4947{
4948 Program *programObject = getProgram(program);
4949 ASSERT(programObject);
4950 programObject->getAttachedShaders(maxcount, count, shaders);
4951}
4952
4953GLint Context::getAttribLocation(GLuint program, const GLchar *name)
4954{
4955 Program *programObject = getProgram(program);
4956 ASSERT(programObject);
4957 return programObject->getAttributeLocation(name);
4958}
4959
4960void Context::getBooleanv(GLenum pname, GLboolean *params)
4961{
4962 GLenum nativeType;
4963 unsigned int numParams = 0;
4964 getQueryParameterInfo(pname, &nativeType, &numParams);
4965
4966 if (nativeType == GL_BOOL)
4967 {
4968 getBooleanvImpl(pname, params);
4969 }
4970 else
4971 {
4972 CastStateValues(this, nativeType, pname, numParams, params);
4973 }
4974}
4975
Brandon Jones59770802018-04-02 13:18:42 -07004976void Context::getBooleanvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLboolean *params)
4977{
4978 getBooleanv(pname, params);
4979}
4980
Jamie Madillc1d770e2017-04-13 17:31:24 -04004981void Context::getFloatv(GLenum pname, GLfloat *params)
4982{
4983 GLenum nativeType;
4984 unsigned int numParams = 0;
4985 getQueryParameterInfo(pname, &nativeType, &numParams);
4986
4987 if (nativeType == GL_FLOAT)
4988 {
4989 getFloatvImpl(pname, params);
4990 }
4991 else
4992 {
4993 CastStateValues(this, nativeType, pname, numParams, params);
4994 }
4995}
4996
Brandon Jones59770802018-04-02 13:18:42 -07004997void Context::getFloatvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLfloat *params)
4998{
4999 getFloatv(pname, params);
5000}
5001
Jamie Madillc1d770e2017-04-13 17:31:24 -04005002void Context::getIntegerv(GLenum pname, GLint *params)
5003{
5004 GLenum nativeType;
5005 unsigned int numParams = 0;
5006 getQueryParameterInfo(pname, &nativeType, &numParams);
5007
5008 if (nativeType == GL_INT)
5009 {
5010 getIntegervImpl(pname, params);
5011 }
5012 else
5013 {
5014 CastStateValues(this, nativeType, pname, numParams, params);
5015 }
5016}
5017
Brandon Jones59770802018-04-02 13:18:42 -07005018void Context::getIntegervRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint *data)
5019{
5020 getIntegerv(pname, data);
5021}
5022
Jamie Madillc1d770e2017-04-13 17:31:24 -04005023void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
5024{
5025 Program *programObject = getProgram(program);
5026 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04005027 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005028}
5029
Brandon Jones59770802018-04-02 13:18:42 -07005030void Context::getProgramivRobust(GLuint program,
5031 GLenum pname,
5032 GLsizei bufSize,
5033 GLsizei *length,
5034 GLint *params)
5035{
5036 getProgramiv(program, pname, params);
5037}
5038
Jiajia Qin5451d532017-11-16 17:16:34 +08005039void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
5040{
5041 UNIMPLEMENTED();
5042}
5043
Jamie Madillbe849e42017-05-02 15:49:00 -04005044void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005045{
5046 Program *programObject = getProgram(program);
5047 ASSERT(programObject);
5048 programObject->getInfoLog(bufsize, length, infolog);
5049}
5050
Jiajia Qin5451d532017-11-16 17:16:34 +08005051void Context::getProgramPipelineInfoLog(GLuint pipeline,
5052 GLsizei bufSize,
5053 GLsizei *length,
5054 GLchar *infoLog)
5055{
5056 UNIMPLEMENTED();
5057}
5058
Jamie Madillc1d770e2017-04-13 17:31:24 -04005059void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
5060{
5061 Shader *shaderObject = getShader(shader);
5062 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04005063 QueryShaderiv(this, shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005064}
5065
Brandon Jones59770802018-04-02 13:18:42 -07005066void Context::getShaderivRobust(GLuint shader,
5067 GLenum pname,
5068 GLsizei bufSize,
5069 GLsizei *length,
5070 GLint *params)
5071{
5072 getShaderiv(shader, pname, params);
5073}
5074
Jamie Madillc1d770e2017-04-13 17:31:24 -04005075void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
5076{
5077 Shader *shaderObject = getShader(shader);
5078 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04005079 shaderObject->getInfoLog(this, bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005080}
5081
5082void Context::getShaderPrecisionFormat(GLenum shadertype,
5083 GLenum precisiontype,
5084 GLint *range,
5085 GLint *precision)
5086{
5087 // TODO(jmadill): Compute shaders.
5088
5089 switch (shadertype)
5090 {
5091 case GL_VERTEX_SHADER:
5092 switch (precisiontype)
5093 {
5094 case GL_LOW_FLOAT:
5095 mCaps.vertexLowpFloat.get(range, precision);
5096 break;
5097 case GL_MEDIUM_FLOAT:
5098 mCaps.vertexMediumpFloat.get(range, precision);
5099 break;
5100 case GL_HIGH_FLOAT:
5101 mCaps.vertexHighpFloat.get(range, precision);
5102 break;
5103
5104 case GL_LOW_INT:
5105 mCaps.vertexLowpInt.get(range, precision);
5106 break;
5107 case GL_MEDIUM_INT:
5108 mCaps.vertexMediumpInt.get(range, precision);
5109 break;
5110 case GL_HIGH_INT:
5111 mCaps.vertexHighpInt.get(range, precision);
5112 break;
5113
5114 default:
5115 UNREACHABLE();
5116 return;
5117 }
5118 break;
5119
5120 case GL_FRAGMENT_SHADER:
5121 switch (precisiontype)
5122 {
5123 case GL_LOW_FLOAT:
5124 mCaps.fragmentLowpFloat.get(range, precision);
5125 break;
5126 case GL_MEDIUM_FLOAT:
5127 mCaps.fragmentMediumpFloat.get(range, precision);
5128 break;
5129 case GL_HIGH_FLOAT:
5130 mCaps.fragmentHighpFloat.get(range, precision);
5131 break;
5132
5133 case GL_LOW_INT:
5134 mCaps.fragmentLowpInt.get(range, precision);
5135 break;
5136 case GL_MEDIUM_INT:
5137 mCaps.fragmentMediumpInt.get(range, precision);
5138 break;
5139 case GL_HIGH_INT:
5140 mCaps.fragmentHighpInt.get(range, precision);
5141 break;
5142
5143 default:
5144 UNREACHABLE();
5145 return;
5146 }
5147 break;
5148
5149 default:
5150 UNREACHABLE();
5151 return;
5152 }
5153}
5154
5155void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
5156{
5157 Shader *shaderObject = getShader(shader);
5158 ASSERT(shaderObject);
5159 shaderObject->getSource(bufsize, length, source);
5160}
5161
5162void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
5163{
5164 Program *programObject = getProgram(program);
5165 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005166 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005167}
5168
Brandon Jones59770802018-04-02 13:18:42 -07005169void Context::getUniformfvRobust(GLuint program,
5170 GLint location,
5171 GLsizei bufSize,
5172 GLsizei *length,
5173 GLfloat *params)
5174{
5175 getUniformfv(program, location, params);
5176}
5177
Jamie Madillc1d770e2017-04-13 17:31:24 -04005178void Context::getUniformiv(GLuint program, GLint location, GLint *params)
5179{
5180 Program *programObject = getProgram(program);
5181 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005182 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005183}
5184
Brandon Jones59770802018-04-02 13:18:42 -07005185void Context::getUniformivRobust(GLuint program,
5186 GLint location,
5187 GLsizei bufSize,
5188 GLsizei *length,
5189 GLint *params)
5190{
5191 getUniformiv(program, location, params);
5192}
5193
Jamie Madillc1d770e2017-04-13 17:31:24 -04005194GLint Context::getUniformLocation(GLuint program, const GLchar *name)
5195{
5196 Program *programObject = getProgram(program);
5197 ASSERT(programObject);
5198 return programObject->getUniformLocation(name);
5199}
5200
5201GLboolean Context::isBuffer(GLuint buffer)
5202{
5203 if (buffer == 0)
5204 {
5205 return GL_FALSE;
5206 }
5207
5208 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
5209}
5210
5211GLboolean Context::isEnabled(GLenum cap)
5212{
5213 return mGLState.getEnableFeature(cap);
5214}
5215
5216GLboolean Context::isFramebuffer(GLuint framebuffer)
5217{
5218 if (framebuffer == 0)
5219 {
5220 return GL_FALSE;
5221 }
5222
5223 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
5224}
5225
5226GLboolean Context::isProgram(GLuint program)
5227{
5228 if (program == 0)
5229 {
5230 return GL_FALSE;
5231 }
5232
5233 return (getProgram(program) ? GL_TRUE : GL_FALSE);
5234}
5235
5236GLboolean Context::isRenderbuffer(GLuint renderbuffer)
5237{
5238 if (renderbuffer == 0)
5239 {
5240 return GL_FALSE;
5241 }
5242
5243 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
5244}
5245
5246GLboolean Context::isShader(GLuint shader)
5247{
5248 if (shader == 0)
5249 {
5250 return GL_FALSE;
5251 }
5252
5253 return (getShader(shader) ? GL_TRUE : GL_FALSE);
5254}
5255
5256GLboolean Context::isTexture(GLuint texture)
5257{
5258 if (texture == 0)
5259 {
5260 return GL_FALSE;
5261 }
5262
5263 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
5264}
5265
5266void Context::linkProgram(GLuint program)
5267{
5268 Program *programObject = getProgram(program);
5269 ASSERT(programObject);
5270 handleError(programObject->link(this));
Martin Radev0abb7a22017-08-28 15:34:45 +03005271 mGLState.onProgramExecutableChange(programObject);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005272}
5273
5274void Context::releaseShaderCompiler()
5275{
Jamie Madill4928b7c2017-06-20 12:57:39 -04005276 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005277}
5278
5279void Context::shaderBinary(GLsizei n,
5280 const GLuint *shaders,
5281 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04005282 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005283 GLsizei length)
5284{
5285 // No binary shader formats are supported.
5286 UNIMPLEMENTED();
5287}
5288
5289void Context::shaderSource(GLuint shader,
5290 GLsizei count,
5291 const GLchar *const *string,
5292 const GLint *length)
5293{
5294 Shader *shaderObject = getShader(shader);
5295 ASSERT(shaderObject);
5296 shaderObject->setSource(count, string, length);
5297}
5298
5299void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
5300{
5301 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
5302}
5303
5304void Context::stencilMask(GLuint mask)
5305{
5306 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
5307}
5308
5309void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
5310{
5311 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
5312}
5313
5314void Context::uniform1f(GLint location, GLfloat x)
5315{
5316 Program *program = mGLState.getProgram();
5317 program->setUniform1fv(location, 1, &x);
5318}
5319
5320void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
5321{
5322 Program *program = mGLState.getProgram();
5323 program->setUniform1fv(location, count, v);
5324}
5325
5326void Context::uniform1i(GLint location, GLint x)
5327{
5328 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04005329 if (program->setUniform1iv(location, 1, &x) == Program::SetUniformResult::SamplerChanged)
5330 {
5331 mGLState.setObjectDirty(GL_PROGRAM);
5332 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005333}
5334
5335void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
5336{
5337 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04005338 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
5339 {
5340 mGLState.setObjectDirty(GL_PROGRAM);
5341 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005342}
5343
5344void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
5345{
5346 GLfloat xy[2] = {x, y};
5347 Program *program = mGLState.getProgram();
5348 program->setUniform2fv(location, 1, xy);
5349}
5350
5351void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
5352{
5353 Program *program = mGLState.getProgram();
5354 program->setUniform2fv(location, count, v);
5355}
5356
5357void Context::uniform2i(GLint location, GLint x, GLint y)
5358{
5359 GLint xy[2] = {x, y};
5360 Program *program = mGLState.getProgram();
5361 program->setUniform2iv(location, 1, xy);
5362}
5363
5364void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
5365{
5366 Program *program = mGLState.getProgram();
5367 program->setUniform2iv(location, count, v);
5368}
5369
5370void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
5371{
5372 GLfloat xyz[3] = {x, y, z};
5373 Program *program = mGLState.getProgram();
5374 program->setUniform3fv(location, 1, xyz);
5375}
5376
5377void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
5378{
5379 Program *program = mGLState.getProgram();
5380 program->setUniform3fv(location, count, v);
5381}
5382
5383void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
5384{
5385 GLint xyz[3] = {x, y, z};
5386 Program *program = mGLState.getProgram();
5387 program->setUniform3iv(location, 1, xyz);
5388}
5389
5390void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
5391{
5392 Program *program = mGLState.getProgram();
5393 program->setUniform3iv(location, count, v);
5394}
5395
5396void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
5397{
5398 GLfloat xyzw[4] = {x, y, z, w};
5399 Program *program = mGLState.getProgram();
5400 program->setUniform4fv(location, 1, xyzw);
5401}
5402
5403void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
5404{
5405 Program *program = mGLState.getProgram();
5406 program->setUniform4fv(location, count, v);
5407}
5408
5409void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
5410{
5411 GLint xyzw[4] = {x, y, z, w};
5412 Program *program = mGLState.getProgram();
5413 program->setUniform4iv(location, 1, xyzw);
5414}
5415
5416void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
5417{
5418 Program *program = mGLState.getProgram();
5419 program->setUniform4iv(location, count, v);
5420}
5421
5422void Context::uniformMatrix2fv(GLint location,
5423 GLsizei count,
5424 GLboolean transpose,
5425 const GLfloat *value)
5426{
5427 Program *program = mGLState.getProgram();
5428 program->setUniformMatrix2fv(location, count, transpose, value);
5429}
5430
5431void Context::uniformMatrix3fv(GLint location,
5432 GLsizei count,
5433 GLboolean transpose,
5434 const GLfloat *value)
5435{
5436 Program *program = mGLState.getProgram();
5437 program->setUniformMatrix3fv(location, count, transpose, value);
5438}
5439
5440void Context::uniformMatrix4fv(GLint location,
5441 GLsizei count,
5442 GLboolean transpose,
5443 const GLfloat *value)
5444{
5445 Program *program = mGLState.getProgram();
5446 program->setUniformMatrix4fv(location, count, transpose, value);
5447}
5448
5449void Context::validateProgram(GLuint program)
5450{
5451 Program *programObject = getProgram(program);
5452 ASSERT(programObject);
5453 programObject->validate(mCaps);
5454}
5455
Jiajia Qin5451d532017-11-16 17:16:34 +08005456void Context::validateProgramPipeline(GLuint pipeline)
5457{
5458 UNIMPLEMENTED();
5459}
5460
Jamie Madilld04908b2017-06-09 14:15:35 -04005461void Context::getProgramBinary(GLuint program,
5462 GLsizei bufSize,
5463 GLsizei *length,
5464 GLenum *binaryFormat,
5465 void *binary)
5466{
5467 Program *programObject = getProgram(program);
5468 ASSERT(programObject != nullptr);
5469
5470 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
5471}
5472
5473void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
5474{
5475 Program *programObject = getProgram(program);
5476 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04005477
Jamie Madilld04908b2017-06-09 14:15:35 -04005478 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
5479}
5480
Jamie Madillff325f12017-08-26 15:06:05 -04005481void Context::uniform1ui(GLint location, GLuint v0)
5482{
5483 Program *program = mGLState.getProgram();
5484 program->setUniform1uiv(location, 1, &v0);
5485}
5486
5487void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
5488{
5489 Program *program = mGLState.getProgram();
5490 const GLuint xy[] = {v0, v1};
5491 program->setUniform2uiv(location, 1, xy);
5492}
5493
5494void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
5495{
5496 Program *program = mGLState.getProgram();
5497 const GLuint xyz[] = {v0, v1, v2};
5498 program->setUniform3uiv(location, 1, xyz);
5499}
5500
5501void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
5502{
5503 Program *program = mGLState.getProgram();
5504 const GLuint xyzw[] = {v0, v1, v2, v3};
5505 program->setUniform4uiv(location, 1, xyzw);
5506}
5507
5508void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
5509{
5510 Program *program = mGLState.getProgram();
5511 program->setUniform1uiv(location, count, value);
5512}
5513void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
5514{
5515 Program *program = mGLState.getProgram();
5516 program->setUniform2uiv(location, count, value);
5517}
5518
5519void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
5520{
5521 Program *program = mGLState.getProgram();
5522 program->setUniform3uiv(location, count, value);
5523}
5524
5525void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
5526{
5527 Program *program = mGLState.getProgram();
5528 program->setUniform4uiv(location, count, value);
5529}
5530
Jamie Madillf0e04492017-08-26 15:28:42 -04005531void Context::genQueries(GLsizei n, GLuint *ids)
5532{
5533 for (GLsizei i = 0; i < n; i++)
5534 {
5535 GLuint handle = mQueryHandleAllocator.allocate();
5536 mQueryMap.assign(handle, nullptr);
5537 ids[i] = handle;
5538 }
5539}
5540
5541void Context::deleteQueries(GLsizei n, const GLuint *ids)
5542{
5543 for (int i = 0; i < n; i++)
5544 {
5545 GLuint query = ids[i];
5546
5547 Query *queryObject = nullptr;
5548 if (mQueryMap.erase(query, &queryObject))
5549 {
5550 mQueryHandleAllocator.release(query);
5551 if (queryObject)
5552 {
5553 queryObject->release(this);
5554 }
5555 }
5556 }
5557}
5558
5559GLboolean Context::isQuery(GLuint id)
5560{
5561 return (getQuery(id, false, GL_NONE) != nullptr) ? GL_TRUE : GL_FALSE;
5562}
5563
Jamie Madillc8c95812017-08-26 18:40:09 -04005564void Context::uniformMatrix2x3fv(GLint location,
5565 GLsizei count,
5566 GLboolean transpose,
5567 const GLfloat *value)
5568{
5569 Program *program = mGLState.getProgram();
5570 program->setUniformMatrix2x3fv(location, count, transpose, value);
5571}
5572
5573void Context::uniformMatrix3x2fv(GLint location,
5574 GLsizei count,
5575 GLboolean transpose,
5576 const GLfloat *value)
5577{
5578 Program *program = mGLState.getProgram();
5579 program->setUniformMatrix3x2fv(location, count, transpose, value);
5580}
5581
5582void Context::uniformMatrix2x4fv(GLint location,
5583 GLsizei count,
5584 GLboolean transpose,
5585 const GLfloat *value)
5586{
5587 Program *program = mGLState.getProgram();
5588 program->setUniformMatrix2x4fv(location, count, transpose, value);
5589}
5590
5591void Context::uniformMatrix4x2fv(GLint location,
5592 GLsizei count,
5593 GLboolean transpose,
5594 const GLfloat *value)
5595{
5596 Program *program = mGLState.getProgram();
5597 program->setUniformMatrix4x2fv(location, count, transpose, value);
5598}
5599
5600void Context::uniformMatrix3x4fv(GLint location,
5601 GLsizei count,
5602 GLboolean transpose,
5603 const GLfloat *value)
5604{
5605 Program *program = mGLState.getProgram();
5606 program->setUniformMatrix3x4fv(location, count, transpose, value);
5607}
5608
5609void Context::uniformMatrix4x3fv(GLint location,
5610 GLsizei count,
5611 GLboolean transpose,
5612 const GLfloat *value)
5613{
5614 Program *program = mGLState.getProgram();
5615 program->setUniformMatrix4x3fv(location, count, transpose, value);
5616}
5617
Jamie Madilld7576732017-08-26 18:49:50 -04005618void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
5619{
5620 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5621 {
5622 GLuint vertexArray = arrays[arrayIndex];
5623
5624 if (arrays[arrayIndex] != 0)
5625 {
5626 VertexArray *vertexArrayObject = nullptr;
5627 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
5628 {
5629 if (vertexArrayObject != nullptr)
5630 {
5631 detachVertexArray(vertexArray);
5632 vertexArrayObject->onDestroy(this);
5633 }
5634
5635 mVertexArrayHandleAllocator.release(vertexArray);
5636 }
5637 }
5638 }
5639}
5640
5641void Context::genVertexArrays(GLsizei n, GLuint *arrays)
5642{
5643 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5644 {
5645 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
5646 mVertexArrayMap.assign(vertexArray, nullptr);
5647 arrays[arrayIndex] = vertexArray;
5648 }
5649}
5650
5651bool Context::isVertexArray(GLuint array)
5652{
5653 if (array == 0)
5654 {
5655 return GL_FALSE;
5656 }
5657
5658 VertexArray *vao = getVertexArray(array);
5659 return (vao != nullptr ? GL_TRUE : GL_FALSE);
5660}
5661
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04005662void Context::endTransformFeedback()
5663{
5664 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5665 transformFeedback->end(this);
5666}
5667
5668void Context::transformFeedbackVaryings(GLuint program,
5669 GLsizei count,
5670 const GLchar *const *varyings,
5671 GLenum bufferMode)
5672{
5673 Program *programObject = getProgram(program);
5674 ASSERT(programObject);
5675 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
5676}
5677
5678void Context::getTransformFeedbackVarying(GLuint program,
5679 GLuint index,
5680 GLsizei bufSize,
5681 GLsizei *length,
5682 GLsizei *size,
5683 GLenum *type,
5684 GLchar *name)
5685{
5686 Program *programObject = getProgram(program);
5687 ASSERT(programObject);
5688 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
5689}
5690
5691void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
5692{
5693 for (int i = 0; i < n; i++)
5694 {
5695 GLuint transformFeedback = ids[i];
5696 if (transformFeedback == 0)
5697 {
5698 continue;
5699 }
5700
5701 TransformFeedback *transformFeedbackObject = nullptr;
5702 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
5703 {
5704 if (transformFeedbackObject != nullptr)
5705 {
5706 detachTransformFeedback(transformFeedback);
5707 transformFeedbackObject->release(this);
5708 }
5709
5710 mTransformFeedbackHandleAllocator.release(transformFeedback);
5711 }
5712 }
5713}
5714
5715void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
5716{
5717 for (int i = 0; i < n; i++)
5718 {
5719 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
5720 mTransformFeedbackMap.assign(transformFeedback, nullptr);
5721 ids[i] = transformFeedback;
5722 }
5723}
5724
5725bool Context::isTransformFeedback(GLuint id)
5726{
5727 if (id == 0)
5728 {
5729 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
5730 // returns FALSE
5731 return GL_FALSE;
5732 }
5733
5734 const TransformFeedback *transformFeedback = getTransformFeedback(id);
5735 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
5736}
5737
5738void Context::pauseTransformFeedback()
5739{
5740 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5741 transformFeedback->pause();
5742}
5743
5744void Context::resumeTransformFeedback()
5745{
5746 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5747 transformFeedback->resume();
5748}
5749
Jamie Madill12e957f2017-08-26 21:42:26 -04005750void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
5751{
5752 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04005753 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04005754}
5755
Brandon Jones59770802018-04-02 13:18:42 -07005756void Context::getUniformuivRobust(GLuint program,
5757 GLint location,
5758 GLsizei bufSize,
5759 GLsizei *length,
5760 GLuint *params)
5761{
5762 getUniformuiv(program, location, params);
5763}
5764
Jamie Madill12e957f2017-08-26 21:42:26 -04005765GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
5766{
5767 const Program *programObject = getProgram(program);
5768 return programObject->getFragDataLocation(name);
5769}
5770
5771void Context::getUniformIndices(GLuint program,
5772 GLsizei uniformCount,
5773 const GLchar *const *uniformNames,
5774 GLuint *uniformIndices)
5775{
5776 const Program *programObject = getProgram(program);
5777 if (!programObject->isLinked())
5778 {
5779 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5780 {
5781 uniformIndices[uniformId] = GL_INVALID_INDEX;
5782 }
5783 }
5784 else
5785 {
5786 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5787 {
5788 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
5789 }
5790 }
5791}
5792
5793void Context::getActiveUniformsiv(GLuint program,
5794 GLsizei uniformCount,
5795 const GLuint *uniformIndices,
5796 GLenum pname,
5797 GLint *params)
5798{
5799 const Program *programObject = getProgram(program);
5800 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5801 {
5802 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08005803 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04005804 }
5805}
5806
5807GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
5808{
5809 const Program *programObject = getProgram(program);
5810 return programObject->getUniformBlockIndex(uniformBlockName);
5811}
5812
5813void Context::getActiveUniformBlockiv(GLuint program,
5814 GLuint uniformBlockIndex,
5815 GLenum pname,
5816 GLint *params)
5817{
5818 const Program *programObject = getProgram(program);
5819 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
5820}
5821
Brandon Jones59770802018-04-02 13:18:42 -07005822void Context::getActiveUniformBlockivRobust(GLuint program,
5823 GLuint uniformBlockIndex,
5824 GLenum pname,
5825 GLsizei bufSize,
5826 GLsizei *length,
5827 GLint *params)
5828{
5829 getActiveUniformBlockiv(program, uniformBlockIndex, pname, params);
5830}
5831
Jamie Madill12e957f2017-08-26 21:42:26 -04005832void Context::getActiveUniformBlockName(GLuint program,
5833 GLuint uniformBlockIndex,
5834 GLsizei bufSize,
5835 GLsizei *length,
5836 GLchar *uniformBlockName)
5837{
5838 const Program *programObject = getProgram(program);
5839 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
5840}
5841
5842void Context::uniformBlockBinding(GLuint program,
5843 GLuint uniformBlockIndex,
5844 GLuint uniformBlockBinding)
5845{
5846 Program *programObject = getProgram(program);
5847 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
5848}
5849
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005850GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
5851{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005852 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
5853 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005854
Jamie Madill70b5bb02017-08-28 13:32:37 -04005855 Sync *syncObject = getSync(syncHandle);
5856 Error error = syncObject->set(condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005857 if (error.isError())
5858 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04005859 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005860 handleError(error);
5861 return nullptr;
5862 }
5863
Jamie Madill70b5bb02017-08-28 13:32:37 -04005864 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005865}
5866
5867GLboolean Context::isSync(GLsync sync)
5868{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005869 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005870}
5871
5872GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
5873{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005874 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005875
5876 GLenum result = GL_WAIT_FAILED;
5877 handleError(syncObject->clientWait(flags, timeout, &result));
5878 return result;
5879}
5880
5881void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
5882{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005883 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005884 handleError(syncObject->serverWait(flags, timeout));
5885}
5886
5887void Context::getInteger64v(GLenum pname, GLint64 *params)
5888{
5889 GLenum nativeType = GL_NONE;
5890 unsigned int numParams = 0;
5891 getQueryParameterInfo(pname, &nativeType, &numParams);
5892
5893 if (nativeType == GL_INT_64_ANGLEX)
5894 {
5895 getInteger64vImpl(pname, params);
5896 }
5897 else
5898 {
5899 CastStateValues(this, nativeType, pname, numParams, params);
5900 }
5901}
5902
Brandon Jones59770802018-04-02 13:18:42 -07005903void Context::getInteger64vRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint64 *data)
5904{
5905 getInteger64v(pname, data);
5906}
5907
Corentin Wallez336129f2017-10-17 15:55:40 -04005908void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04005909{
5910 Buffer *buffer = mGLState.getTargetBuffer(target);
5911 QueryBufferParameteri64v(buffer, pname, params);
5912}
5913
Brandon Jones59770802018-04-02 13:18:42 -07005914void Context::getBufferParameteri64vRobust(BufferBinding target,
5915 GLenum pname,
5916 GLsizei bufSize,
5917 GLsizei *length,
5918 GLint64 *params)
5919{
5920 getBufferParameteri64v(target, pname, params);
5921}
5922
Jamie Madill3ef140a2017-08-26 23:11:21 -04005923void Context::genSamplers(GLsizei count, GLuint *samplers)
5924{
5925 for (int i = 0; i < count; i++)
5926 {
5927 samplers[i] = mState.mSamplers->createSampler();
5928 }
5929}
5930
5931void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
5932{
5933 for (int i = 0; i < count; i++)
5934 {
5935 GLuint sampler = samplers[i];
5936
5937 if (mState.mSamplers->getSampler(sampler))
5938 {
5939 detachSampler(sampler);
5940 }
5941
5942 mState.mSamplers->deleteObject(this, sampler);
5943 }
5944}
5945
5946void Context::getInternalformativ(GLenum target,
5947 GLenum internalformat,
5948 GLenum pname,
5949 GLsizei bufSize,
5950 GLint *params)
5951{
5952 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
5953 QueryInternalFormativ(formatCaps, pname, bufSize, params);
5954}
5955
Brandon Jones59770802018-04-02 13:18:42 -07005956void Context::getInternalformativRobust(GLenum target,
5957 GLenum internalformat,
5958 GLenum pname,
5959 GLsizei bufSize,
5960 GLsizei *length,
5961 GLint *params)
5962{
5963 getInternalformativ(target, internalformat, pname, bufSize, params);
5964}
5965
Jiajia Qin5451d532017-11-16 17:16:34 +08005966void Context::programUniform1i(GLuint program, GLint location, GLint v0)
5967{
5968 programUniform1iv(program, location, 1, &v0);
5969}
5970
5971void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
5972{
5973 GLint xy[2] = {v0, v1};
5974 programUniform2iv(program, location, 1, xy);
5975}
5976
5977void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
5978{
5979 GLint xyz[3] = {v0, v1, v2};
5980 programUniform3iv(program, location, 1, xyz);
5981}
5982
5983void Context::programUniform4i(GLuint program,
5984 GLint location,
5985 GLint v0,
5986 GLint v1,
5987 GLint v2,
5988 GLint v3)
5989{
5990 GLint xyzw[4] = {v0, v1, v2, v3};
5991 programUniform4iv(program, location, 1, xyzw);
5992}
5993
5994void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
5995{
5996 programUniform1uiv(program, location, 1, &v0);
5997}
5998
5999void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
6000{
6001 GLuint xy[2] = {v0, v1};
6002 programUniform2uiv(program, location, 1, xy);
6003}
6004
6005void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
6006{
6007 GLuint xyz[3] = {v0, v1, v2};
6008 programUniform3uiv(program, location, 1, xyz);
6009}
6010
6011void Context::programUniform4ui(GLuint program,
6012 GLint location,
6013 GLuint v0,
6014 GLuint v1,
6015 GLuint v2,
6016 GLuint v3)
6017{
6018 GLuint xyzw[4] = {v0, v1, v2, v3};
6019 programUniform4uiv(program, location, 1, xyzw);
6020}
6021
6022void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
6023{
6024 programUniform1fv(program, location, 1, &v0);
6025}
6026
6027void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
6028{
6029 GLfloat xy[2] = {v0, v1};
6030 programUniform2fv(program, location, 1, xy);
6031}
6032
6033void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
6034{
6035 GLfloat xyz[3] = {v0, v1, v2};
6036 programUniform3fv(program, location, 1, xyz);
6037}
6038
6039void Context::programUniform4f(GLuint program,
6040 GLint location,
6041 GLfloat v0,
6042 GLfloat v1,
6043 GLfloat v2,
6044 GLfloat v3)
6045{
6046 GLfloat xyzw[4] = {v0, v1, v2, v3};
6047 programUniform4fv(program, location, 1, xyzw);
6048}
6049
Jamie Madill81c2e252017-09-09 23:32:46 -04006050void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6051{
6052 Program *programObject = getProgram(program);
6053 ASSERT(programObject);
6054 if (programObject->setUniform1iv(location, count, value) ==
6055 Program::SetUniformResult::SamplerChanged)
6056 {
6057 mGLState.setObjectDirty(GL_PROGRAM);
6058 }
6059}
6060
Jiajia Qin5451d532017-11-16 17:16:34 +08006061void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6062{
6063 Program *programObject = getProgram(program);
6064 ASSERT(programObject);
6065 programObject->setUniform2iv(location, count, value);
6066}
6067
6068void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6069{
6070 Program *programObject = getProgram(program);
6071 ASSERT(programObject);
6072 programObject->setUniform3iv(location, count, value);
6073}
6074
6075void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6076{
6077 Program *programObject = getProgram(program);
6078 ASSERT(programObject);
6079 programObject->setUniform4iv(location, count, value);
6080}
6081
6082void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6083{
6084 Program *programObject = getProgram(program);
6085 ASSERT(programObject);
6086 programObject->setUniform1uiv(location, count, value);
6087}
6088
6089void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6090{
6091 Program *programObject = getProgram(program);
6092 ASSERT(programObject);
6093 programObject->setUniform2uiv(location, count, value);
6094}
6095
6096void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6097{
6098 Program *programObject = getProgram(program);
6099 ASSERT(programObject);
6100 programObject->setUniform3uiv(location, count, value);
6101}
6102
6103void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6104{
6105 Program *programObject = getProgram(program);
6106 ASSERT(programObject);
6107 programObject->setUniform4uiv(location, count, value);
6108}
6109
6110void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6111{
6112 Program *programObject = getProgram(program);
6113 ASSERT(programObject);
6114 programObject->setUniform1fv(location, count, value);
6115}
6116
6117void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6118{
6119 Program *programObject = getProgram(program);
6120 ASSERT(programObject);
6121 programObject->setUniform2fv(location, count, value);
6122}
6123
6124void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6125{
6126 Program *programObject = getProgram(program);
6127 ASSERT(programObject);
6128 programObject->setUniform3fv(location, count, value);
6129}
6130
6131void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6132{
6133 Program *programObject = getProgram(program);
6134 ASSERT(programObject);
6135 programObject->setUniform4fv(location, count, value);
6136}
6137
6138void Context::programUniformMatrix2fv(GLuint program,
6139 GLint location,
6140 GLsizei count,
6141 GLboolean transpose,
6142 const GLfloat *value)
6143{
6144 Program *programObject = getProgram(program);
6145 ASSERT(programObject);
6146 programObject->setUniformMatrix2fv(location, count, transpose, value);
6147}
6148
6149void Context::programUniformMatrix3fv(GLuint program,
6150 GLint location,
6151 GLsizei count,
6152 GLboolean transpose,
6153 const GLfloat *value)
6154{
6155 Program *programObject = getProgram(program);
6156 ASSERT(programObject);
6157 programObject->setUniformMatrix3fv(location, count, transpose, value);
6158}
6159
6160void Context::programUniformMatrix4fv(GLuint program,
6161 GLint location,
6162 GLsizei count,
6163 GLboolean transpose,
6164 const GLfloat *value)
6165{
6166 Program *programObject = getProgram(program);
6167 ASSERT(programObject);
6168 programObject->setUniformMatrix4fv(location, count, transpose, value);
6169}
6170
6171void Context::programUniformMatrix2x3fv(GLuint program,
6172 GLint location,
6173 GLsizei count,
6174 GLboolean transpose,
6175 const GLfloat *value)
6176{
6177 Program *programObject = getProgram(program);
6178 ASSERT(programObject);
6179 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
6180}
6181
6182void Context::programUniformMatrix3x2fv(GLuint program,
6183 GLint location,
6184 GLsizei count,
6185 GLboolean transpose,
6186 const GLfloat *value)
6187{
6188 Program *programObject = getProgram(program);
6189 ASSERT(programObject);
6190 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
6191}
6192
6193void Context::programUniformMatrix2x4fv(GLuint program,
6194 GLint location,
6195 GLsizei count,
6196 GLboolean transpose,
6197 const GLfloat *value)
6198{
6199 Program *programObject = getProgram(program);
6200 ASSERT(programObject);
6201 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
6202}
6203
6204void Context::programUniformMatrix4x2fv(GLuint program,
6205 GLint location,
6206 GLsizei count,
6207 GLboolean transpose,
6208 const GLfloat *value)
6209{
6210 Program *programObject = getProgram(program);
6211 ASSERT(programObject);
6212 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
6213}
6214
6215void Context::programUniformMatrix3x4fv(GLuint program,
6216 GLint location,
6217 GLsizei count,
6218 GLboolean transpose,
6219 const GLfloat *value)
6220{
6221 Program *programObject = getProgram(program);
6222 ASSERT(programObject);
6223 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
6224}
6225
6226void Context::programUniformMatrix4x3fv(GLuint program,
6227 GLint location,
6228 GLsizei count,
6229 GLboolean transpose,
6230 const GLfloat *value)
6231{
6232 Program *programObject = getProgram(program);
6233 ASSERT(programObject);
6234 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
6235}
6236
Jamie Madill81c2e252017-09-09 23:32:46 -04006237void Context::onTextureChange(const Texture *texture)
6238{
6239 // Conservatively assume all textures are dirty.
6240 // TODO(jmadill): More fine-grained update.
6241 mGLState.setObjectDirty(GL_TEXTURE);
6242}
6243
James Darpiniane8a93c62018-01-04 18:02:24 -08006244bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
6245{
6246 return mGLState.isCurrentTransformFeedback(tf);
6247}
6248bool Context::isCurrentVertexArray(const VertexArray *va) const
6249{
6250 return mGLState.isCurrentVertexArray(va);
6251}
6252
Yunchao Hea336b902017-08-02 16:05:21 +08006253void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
6254{
6255 for (int i = 0; i < count; i++)
6256 {
6257 pipelines[i] = createProgramPipeline();
6258 }
6259}
6260
6261void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
6262{
6263 for (int i = 0; i < count; i++)
6264 {
6265 if (pipelines[i] != 0)
6266 {
6267 deleteProgramPipeline(pipelines[i]);
6268 }
6269 }
6270}
6271
6272GLboolean Context::isProgramPipeline(GLuint pipeline)
6273{
6274 if (pipeline == 0)
6275 {
6276 return GL_FALSE;
6277 }
6278
6279 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
6280}
6281
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006282void Context::finishFenceNV(GLuint fence)
6283{
6284 FenceNV *fenceObject = getFenceNV(fence);
6285
6286 ASSERT(fenceObject && fenceObject->isSet());
6287 handleError(fenceObject->finish());
6288}
6289
6290void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
6291{
6292 FenceNV *fenceObject = getFenceNV(fence);
6293
6294 ASSERT(fenceObject && fenceObject->isSet());
6295
6296 switch (pname)
6297 {
6298 case GL_FENCE_STATUS_NV:
6299 {
6300 // GL_NV_fence spec:
6301 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
6302 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
6303 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
6304 GLboolean status = GL_TRUE;
6305 if (fenceObject->getStatus() != GL_TRUE)
6306 {
6307 ANGLE_CONTEXT_TRY(fenceObject->test(&status));
6308 }
6309 *params = status;
6310 break;
6311 }
6312
6313 case GL_FENCE_CONDITION_NV:
6314 {
6315 *params = static_cast<GLint>(fenceObject->getCondition());
6316 break;
6317 }
6318
6319 default:
6320 UNREACHABLE();
6321 }
6322}
6323
6324void Context::getTranslatedShaderSource(GLuint shader,
6325 GLsizei bufsize,
6326 GLsizei *length,
6327 GLchar *source)
6328{
6329 Shader *shaderObject = getShader(shader);
6330 ASSERT(shaderObject);
6331 shaderObject->getTranslatedSourceWithDebugInfo(this, bufsize, length, source);
6332}
6333
6334void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
6335{
6336 Program *programObject = getProgram(program);
6337 ASSERT(programObject);
6338
6339 programObject->getUniformfv(this, location, params);
6340}
6341
6342void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
6343{
6344 Program *programObject = getProgram(program);
6345 ASSERT(programObject);
6346
6347 programObject->getUniformiv(this, location, params);
6348}
6349
6350GLboolean Context::isFenceNV(GLuint fence)
6351{
6352 FenceNV *fenceObject = getFenceNV(fence);
6353
6354 if (fenceObject == nullptr)
6355 {
6356 return GL_FALSE;
6357 }
6358
6359 // GL_NV_fence spec:
6360 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
6361 // existing fence.
6362 return fenceObject->isSet();
6363}
6364
6365void Context::readnPixels(GLint x,
6366 GLint y,
6367 GLsizei width,
6368 GLsizei height,
6369 GLenum format,
6370 GLenum type,
6371 GLsizei bufSize,
6372 void *data)
6373{
6374 return readPixels(x, y, width, height, format, type, data);
6375}
6376
Jamie Madill007530e2017-12-28 14:27:04 -05006377void Context::setFenceNV(GLuint fence, GLenum condition)
6378{
6379 ASSERT(condition == GL_ALL_COMPLETED_NV);
6380
6381 FenceNV *fenceObject = getFenceNV(fence);
6382 ASSERT(fenceObject != nullptr);
6383 handleError(fenceObject->set(condition));
6384}
6385
6386GLboolean Context::testFenceNV(GLuint fence)
6387{
6388 FenceNV *fenceObject = getFenceNV(fence);
6389
6390 ASSERT(fenceObject != nullptr);
6391 ASSERT(fenceObject->isSet() == GL_TRUE);
6392
6393 GLboolean result = GL_TRUE;
6394 Error error = fenceObject->test(&result);
6395 if (error.isError())
6396 {
6397 handleError(error);
6398 return GL_TRUE;
6399 }
6400
6401 return result;
6402}
6403
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006404void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006405{
6406 Texture *texture = getTargetTexture(target);
6407 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
Corentin Wallez99d492c2018-02-27 15:17:10 -05006408 handleError(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05006409}
6410
Jamie Madillfa920eb2018-01-04 11:45:50 -05006411void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006412{
6413 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
6414 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
6415 handleError(renderbuffer->setStorageEGLImageTarget(this, imageObject));
6416}
6417
Jamie Madillfa920eb2018-01-04 11:45:50 -05006418void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
6419{
6420 UNIMPLEMENTED();
6421}
6422
Jamie Madill5b772312018-03-08 20:28:32 -05006423bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
6424{
6425 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
6426 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
6427 // to the fact that it is stored internally as a float, and so would require conversion
6428 // if returned from Context::getIntegerv. Since this conversion is already implemented
6429 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
6430 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
6431 // application.
6432 switch (pname)
6433 {
6434 case GL_COMPRESSED_TEXTURE_FORMATS:
6435 {
6436 *type = GL_INT;
6437 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
6438 return true;
6439 }
6440 case GL_SHADER_BINARY_FORMATS:
6441 {
6442 *type = GL_INT;
6443 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
6444 return true;
6445 }
6446
6447 case GL_MAX_VERTEX_ATTRIBS:
6448 case GL_MAX_VERTEX_UNIFORM_VECTORS:
6449 case GL_MAX_VARYING_VECTORS:
6450 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
6451 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
6452 case GL_MAX_TEXTURE_IMAGE_UNITS:
6453 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
6454 case GL_MAX_RENDERBUFFER_SIZE:
6455 case GL_NUM_SHADER_BINARY_FORMATS:
6456 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
6457 case GL_ARRAY_BUFFER_BINDING:
6458 case GL_FRAMEBUFFER_BINDING:
6459 case GL_RENDERBUFFER_BINDING:
6460 case GL_CURRENT_PROGRAM:
6461 case GL_PACK_ALIGNMENT:
6462 case GL_UNPACK_ALIGNMENT:
6463 case GL_GENERATE_MIPMAP_HINT:
6464 case GL_RED_BITS:
6465 case GL_GREEN_BITS:
6466 case GL_BLUE_BITS:
6467 case GL_ALPHA_BITS:
6468 case GL_DEPTH_BITS:
6469 case GL_STENCIL_BITS:
6470 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
6471 case GL_CULL_FACE_MODE:
6472 case GL_FRONT_FACE:
6473 case GL_ACTIVE_TEXTURE:
6474 case GL_STENCIL_FUNC:
6475 case GL_STENCIL_VALUE_MASK:
6476 case GL_STENCIL_REF:
6477 case GL_STENCIL_FAIL:
6478 case GL_STENCIL_PASS_DEPTH_FAIL:
6479 case GL_STENCIL_PASS_DEPTH_PASS:
6480 case GL_STENCIL_BACK_FUNC:
6481 case GL_STENCIL_BACK_VALUE_MASK:
6482 case GL_STENCIL_BACK_REF:
6483 case GL_STENCIL_BACK_FAIL:
6484 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
6485 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
6486 case GL_DEPTH_FUNC:
6487 case GL_BLEND_SRC_RGB:
6488 case GL_BLEND_SRC_ALPHA:
6489 case GL_BLEND_DST_RGB:
6490 case GL_BLEND_DST_ALPHA:
6491 case GL_BLEND_EQUATION_RGB:
6492 case GL_BLEND_EQUATION_ALPHA:
6493 case GL_STENCIL_WRITEMASK:
6494 case GL_STENCIL_BACK_WRITEMASK:
6495 case GL_STENCIL_CLEAR_VALUE:
6496 case GL_SUBPIXEL_BITS:
6497 case GL_MAX_TEXTURE_SIZE:
6498 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
6499 case GL_SAMPLE_BUFFERS:
6500 case GL_SAMPLES:
6501 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
6502 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
6503 case GL_TEXTURE_BINDING_2D:
6504 case GL_TEXTURE_BINDING_CUBE_MAP:
6505 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
6506 {
6507 *type = GL_INT;
6508 *numParams = 1;
6509 return true;
6510 }
6511 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6512 {
6513 if (!getExtensions().packReverseRowOrder)
6514 {
6515 return false;
6516 }
6517 *type = GL_INT;
6518 *numParams = 1;
6519 return true;
6520 }
6521 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
6522 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
6523 {
6524 if (!getExtensions().textureRectangle)
6525 {
6526 return false;
6527 }
6528 *type = GL_INT;
6529 *numParams = 1;
6530 return true;
6531 }
6532 case GL_MAX_DRAW_BUFFERS_EXT:
6533 case GL_MAX_COLOR_ATTACHMENTS_EXT:
6534 {
6535 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
6536 {
6537 return false;
6538 }
6539 *type = GL_INT;
6540 *numParams = 1;
6541 return true;
6542 }
6543 case GL_MAX_VIEWPORT_DIMS:
6544 {
6545 *type = GL_INT;
6546 *numParams = 2;
6547 return true;
6548 }
6549 case GL_VIEWPORT:
6550 case GL_SCISSOR_BOX:
6551 {
6552 *type = GL_INT;
6553 *numParams = 4;
6554 return true;
6555 }
6556 case GL_SHADER_COMPILER:
6557 case GL_SAMPLE_COVERAGE_INVERT:
6558 case GL_DEPTH_WRITEMASK:
6559 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
6560 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
6561 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
6562 // bool-natural
6563 case GL_SAMPLE_COVERAGE:
6564 case GL_SCISSOR_TEST:
6565 case GL_STENCIL_TEST:
6566 case GL_DEPTH_TEST:
6567 case GL_BLEND:
6568 case GL_DITHER:
6569 case GL_CONTEXT_ROBUST_ACCESS_EXT:
6570 {
6571 *type = GL_BOOL;
6572 *numParams = 1;
6573 return true;
6574 }
6575 case GL_COLOR_WRITEMASK:
6576 {
6577 *type = GL_BOOL;
6578 *numParams = 4;
6579 return true;
6580 }
6581 case GL_POLYGON_OFFSET_FACTOR:
6582 case GL_POLYGON_OFFSET_UNITS:
6583 case GL_SAMPLE_COVERAGE_VALUE:
6584 case GL_DEPTH_CLEAR_VALUE:
6585 case GL_LINE_WIDTH:
6586 {
6587 *type = GL_FLOAT;
6588 *numParams = 1;
6589 return true;
6590 }
6591 case GL_ALIASED_LINE_WIDTH_RANGE:
6592 case GL_ALIASED_POINT_SIZE_RANGE:
6593 case GL_DEPTH_RANGE:
6594 {
6595 *type = GL_FLOAT;
6596 *numParams = 2;
6597 return true;
6598 }
6599 case GL_COLOR_CLEAR_VALUE:
6600 case GL_BLEND_COLOR:
6601 {
6602 *type = GL_FLOAT;
6603 *numParams = 4;
6604 return true;
6605 }
6606 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
6607 if (!getExtensions().textureFilterAnisotropic)
6608 {
6609 return false;
6610 }
6611 *type = GL_FLOAT;
6612 *numParams = 1;
6613 return true;
6614 case GL_TIMESTAMP_EXT:
6615 if (!getExtensions().disjointTimerQuery)
6616 {
6617 return false;
6618 }
6619 *type = GL_INT_64_ANGLEX;
6620 *numParams = 1;
6621 return true;
6622 case GL_GPU_DISJOINT_EXT:
6623 if (!getExtensions().disjointTimerQuery)
6624 {
6625 return false;
6626 }
6627 *type = GL_INT;
6628 *numParams = 1;
6629 return true;
6630 case GL_COVERAGE_MODULATION_CHROMIUM:
6631 if (!getExtensions().framebufferMixedSamples)
6632 {
6633 return false;
6634 }
6635 *type = GL_INT;
6636 *numParams = 1;
6637 return true;
6638 case GL_TEXTURE_BINDING_EXTERNAL_OES:
6639 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
6640 {
6641 return false;
6642 }
6643 *type = GL_INT;
6644 *numParams = 1;
6645 return true;
6646 }
6647
6648 if (getExtensions().debug)
6649 {
6650 switch (pname)
6651 {
6652 case GL_DEBUG_LOGGED_MESSAGES:
6653 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
6654 case GL_DEBUG_GROUP_STACK_DEPTH:
6655 case GL_MAX_DEBUG_MESSAGE_LENGTH:
6656 case GL_MAX_DEBUG_LOGGED_MESSAGES:
6657 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
6658 case GL_MAX_LABEL_LENGTH:
6659 *type = GL_INT;
6660 *numParams = 1;
6661 return true;
6662
6663 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
6664 case GL_DEBUG_OUTPUT:
6665 *type = GL_BOOL;
6666 *numParams = 1;
6667 return true;
6668 }
6669 }
6670
6671 if (getExtensions().multisampleCompatibility)
6672 {
6673 switch (pname)
6674 {
6675 case GL_MULTISAMPLE_EXT:
6676 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
6677 *type = GL_BOOL;
6678 *numParams = 1;
6679 return true;
6680 }
6681 }
6682
6683 if (getExtensions().pathRendering)
6684 {
6685 switch (pname)
6686 {
6687 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
6688 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
6689 *type = GL_FLOAT;
6690 *numParams = 16;
6691 return true;
6692 }
6693 }
6694
6695 if (getExtensions().bindGeneratesResource)
6696 {
6697 switch (pname)
6698 {
6699 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
6700 *type = GL_BOOL;
6701 *numParams = 1;
6702 return true;
6703 }
6704 }
6705
6706 if (getExtensions().clientArrays)
6707 {
6708 switch (pname)
6709 {
6710 case GL_CLIENT_ARRAYS_ANGLE:
6711 *type = GL_BOOL;
6712 *numParams = 1;
6713 return true;
6714 }
6715 }
6716
6717 if (getExtensions().sRGBWriteControl)
6718 {
6719 switch (pname)
6720 {
6721 case GL_FRAMEBUFFER_SRGB_EXT:
6722 *type = GL_BOOL;
6723 *numParams = 1;
6724 return true;
6725 }
6726 }
6727
6728 if (getExtensions().robustResourceInitialization &&
6729 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
6730 {
6731 *type = GL_BOOL;
6732 *numParams = 1;
6733 return true;
6734 }
6735
6736 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
6737 {
6738 *type = GL_BOOL;
6739 *numParams = 1;
6740 return true;
6741 }
6742
6743 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
6744 switch (pname)
6745 {
6746 // case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE // equivalent to FRAMEBUFFER_BINDING
6747 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
6748 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
6749 {
6750 return false;
6751 }
6752 *type = GL_INT;
6753 *numParams = 1;
6754 return true;
6755
6756 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
6757 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
6758 {
6759 return false;
6760 }
6761 *type = GL_INT;
6762 *numParams = 1;
6763 return true;
6764
6765 case GL_PROGRAM_BINARY_FORMATS_OES:
6766 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
6767 {
6768 return false;
6769 }
6770 *type = GL_INT;
6771 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
6772 return true;
6773
6774 case GL_PACK_ROW_LENGTH:
6775 case GL_PACK_SKIP_ROWS:
6776 case GL_PACK_SKIP_PIXELS:
6777 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
6778 {
6779 return false;
6780 }
6781 *type = GL_INT;
6782 *numParams = 1;
6783 return true;
6784 case GL_UNPACK_ROW_LENGTH:
6785 case GL_UNPACK_SKIP_ROWS:
6786 case GL_UNPACK_SKIP_PIXELS:
6787 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
6788 {
6789 return false;
6790 }
6791 *type = GL_INT;
6792 *numParams = 1;
6793 return true;
6794 case GL_VERTEX_ARRAY_BINDING:
6795 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
6796 {
6797 return false;
6798 }
6799 *type = GL_INT;
6800 *numParams = 1;
6801 return true;
6802 case GL_PIXEL_PACK_BUFFER_BINDING:
6803 case GL_PIXEL_UNPACK_BUFFER_BINDING:
6804 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
6805 {
6806 return false;
6807 }
6808 *type = GL_INT;
6809 *numParams = 1;
6810 return true;
6811 case GL_MAX_SAMPLES:
6812 {
6813 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
6814 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
6815 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
6816 {
6817 return false;
6818 }
6819 *type = GL_INT;
6820 *numParams = 1;
6821 return true;
6822
6823 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
6824 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
6825 {
6826 return false;
6827 }
6828 *type = GL_INT;
6829 *numParams = 1;
6830 return true;
6831 }
6832 }
6833
6834 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
6835 {
6836 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
6837 {
6838 return false;
6839 }
6840 *type = GL_INT;
6841 *numParams = 1;
6842 return true;
6843 }
6844
6845 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
6846 {
6847 *type = GL_INT;
6848 *numParams = 1;
6849 return true;
6850 }
6851
Lingfeng Yang13b708f2018-03-21 12:14:10 -07006852 if (getClientVersion() < Version(2, 0))
6853 {
6854 switch (pname)
6855 {
6856 case GL_ALPHA_TEST_FUNC:
Lingfeng Yange547aac2018-04-05 09:39:20 -07006857 case GL_CLIENT_ACTIVE_TEXTURE:
6858 case GL_MATRIX_MODE:
6859 case GL_MAX_TEXTURE_UNITS:
6860 case GL_MAX_MODELVIEW_STACK_DEPTH:
6861 case GL_MAX_PROJECTION_STACK_DEPTH:
6862 case GL_MAX_TEXTURE_STACK_DEPTH:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07006863 *type = GL_INT;
6864 *numParams = 1;
6865 return true;
6866 case GL_ALPHA_TEST_REF:
6867 *type = GL_FLOAT;
6868 *numParams = 1;
6869 return true;
Lingfeng Yanga43994c2018-03-29 07:21:41 -07006870 case GL_CURRENT_COLOR:
Lingfeng Yange547aac2018-04-05 09:39:20 -07006871 case GL_CURRENT_TEXTURE_COORDS:
Lingfeng Yanga43994c2018-03-29 07:21:41 -07006872 *type = GL_FLOAT;
6873 *numParams = 4;
6874 return true;
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07006875 case GL_CURRENT_NORMAL:
6876 *type = GL_FLOAT;
6877 *numParams = 3;
6878 return true;
Lingfeng Yang13b708f2018-03-21 12:14:10 -07006879 }
6880 }
6881
Jamie Madill5b772312018-03-08 20:28:32 -05006882 if (getClientVersion() < Version(3, 0))
6883 {
6884 return false;
6885 }
6886
6887 // Check for ES3.0+ parameter names
6888 switch (pname)
6889 {
6890 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
6891 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
6892 case GL_UNIFORM_BUFFER_BINDING:
6893 case GL_TRANSFORM_FEEDBACK_BINDING:
6894 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
6895 case GL_COPY_READ_BUFFER_BINDING:
6896 case GL_COPY_WRITE_BUFFER_BINDING:
6897 case GL_SAMPLER_BINDING:
6898 case GL_READ_BUFFER:
6899 case GL_TEXTURE_BINDING_3D:
6900 case GL_TEXTURE_BINDING_2D_ARRAY:
6901 case GL_MAX_3D_TEXTURE_SIZE:
6902 case GL_MAX_ARRAY_TEXTURE_LAYERS:
6903 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
6904 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
6905 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
6906 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
6907 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
6908 case GL_MAX_VARYING_COMPONENTS:
6909 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
6910 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
6911 case GL_MIN_PROGRAM_TEXEL_OFFSET:
6912 case GL_MAX_PROGRAM_TEXEL_OFFSET:
6913 case GL_NUM_EXTENSIONS:
6914 case GL_MAJOR_VERSION:
6915 case GL_MINOR_VERSION:
6916 case GL_MAX_ELEMENTS_INDICES:
6917 case GL_MAX_ELEMENTS_VERTICES:
6918 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
6919 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
6920 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
6921 case GL_UNPACK_IMAGE_HEIGHT:
6922 case GL_UNPACK_SKIP_IMAGES:
6923 {
6924 *type = GL_INT;
6925 *numParams = 1;
6926 return true;
6927 }
6928
6929 case GL_MAX_ELEMENT_INDEX:
6930 case GL_MAX_UNIFORM_BLOCK_SIZE:
6931 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
6932 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
6933 case GL_MAX_SERVER_WAIT_TIMEOUT:
6934 {
6935 *type = GL_INT_64_ANGLEX;
6936 *numParams = 1;
6937 return true;
6938 }
6939
6940 case GL_TRANSFORM_FEEDBACK_ACTIVE:
6941 case GL_TRANSFORM_FEEDBACK_PAUSED:
6942 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
6943 case GL_RASTERIZER_DISCARD:
6944 {
6945 *type = GL_BOOL;
6946 *numParams = 1;
6947 return true;
6948 }
6949
6950 case GL_MAX_TEXTURE_LOD_BIAS:
6951 {
6952 *type = GL_FLOAT;
6953 *numParams = 1;
6954 return true;
6955 }
6956 }
6957
6958 if (getExtensions().requestExtension)
6959 {
6960 switch (pname)
6961 {
6962 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
6963 *type = GL_INT;
6964 *numParams = 1;
6965 return true;
6966 }
6967 }
6968
6969 if (getClientVersion() < Version(3, 1))
6970 {
6971 return false;
6972 }
6973
6974 switch (pname)
6975 {
6976 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
6977 case GL_DRAW_INDIRECT_BUFFER_BINDING:
6978 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
6979 case GL_MAX_FRAMEBUFFER_WIDTH:
6980 case GL_MAX_FRAMEBUFFER_HEIGHT:
6981 case GL_MAX_FRAMEBUFFER_SAMPLES:
6982 case GL_MAX_SAMPLE_MASK_WORDS:
6983 case GL_MAX_COLOR_TEXTURE_SAMPLES:
6984 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
6985 case GL_MAX_INTEGER_SAMPLES:
6986 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
6987 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
6988 case GL_MAX_VERTEX_ATTRIB_STRIDE:
6989 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
6990 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
6991 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
6992 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
6993 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
6994 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
6995 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
6996 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
6997 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
6998 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
6999 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
7000 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
7001 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
7002 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
7003 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
7004 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
7005 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
7006 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
7007 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
7008 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
7009 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
7010 case GL_MAX_UNIFORM_LOCATIONS:
7011 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
7012 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
7013 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
7014 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
7015 case GL_MAX_IMAGE_UNITS:
7016 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
7017 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
7018 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
7019 case GL_SHADER_STORAGE_BUFFER_BINDING:
7020 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
7021 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
7022 *type = GL_INT;
7023 *numParams = 1;
7024 return true;
7025 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7026 *type = GL_INT_64_ANGLEX;
7027 *numParams = 1;
7028 return true;
7029 case GL_SAMPLE_MASK:
7030 *type = GL_BOOL;
7031 *numParams = 1;
7032 return true;
7033 }
7034
7035 if (getExtensions().geometryShader)
7036 {
7037 switch (pname)
7038 {
7039 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7040 case GL_LAYER_PROVOKING_VERTEX_EXT:
7041 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7042 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7043 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7044 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7045 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7046 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7047 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7048 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7049 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7050 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7051 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7052 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7053 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7054 *type = GL_INT;
7055 *numParams = 1;
7056 return true;
7057 }
7058 }
7059
7060 return false;
7061}
7062
7063bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7064{
7065 if (getClientVersion() < Version(3, 0))
7066 {
7067 return false;
7068 }
7069
7070 switch (target)
7071 {
7072 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7073 case GL_UNIFORM_BUFFER_BINDING:
7074 {
7075 *type = GL_INT;
7076 *numParams = 1;
7077 return true;
7078 }
7079 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7080 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7081 case GL_UNIFORM_BUFFER_START:
7082 case GL_UNIFORM_BUFFER_SIZE:
7083 {
7084 *type = GL_INT_64_ANGLEX;
7085 *numParams = 1;
7086 return true;
7087 }
7088 }
7089
7090 if (getClientVersion() < Version(3, 1))
7091 {
7092 return false;
7093 }
7094
7095 switch (target)
7096 {
7097 case GL_IMAGE_BINDING_LAYERED:
7098 {
7099 *type = GL_BOOL;
7100 *numParams = 1;
7101 return true;
7102 }
7103 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7104 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7105 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7106 case GL_SHADER_STORAGE_BUFFER_BINDING:
7107 case GL_VERTEX_BINDING_BUFFER:
7108 case GL_VERTEX_BINDING_DIVISOR:
7109 case GL_VERTEX_BINDING_OFFSET:
7110 case GL_VERTEX_BINDING_STRIDE:
7111 case GL_SAMPLE_MASK_VALUE:
7112 case GL_IMAGE_BINDING_NAME:
7113 case GL_IMAGE_BINDING_LEVEL:
7114 case GL_IMAGE_BINDING_LAYER:
7115 case GL_IMAGE_BINDING_ACCESS:
7116 case GL_IMAGE_BINDING_FORMAT:
7117 {
7118 *type = GL_INT;
7119 *numParams = 1;
7120 return true;
7121 }
7122 case GL_ATOMIC_COUNTER_BUFFER_START:
7123 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
7124 case GL_SHADER_STORAGE_BUFFER_START:
7125 case GL_SHADER_STORAGE_BUFFER_SIZE:
7126 {
7127 *type = GL_INT_64_ANGLEX;
7128 *numParams = 1;
7129 return true;
7130 }
7131 }
7132
7133 return false;
7134}
7135
7136Program *Context::getProgram(GLuint handle) const
7137{
7138 return mState.mShaderPrograms->getProgram(handle);
7139}
7140
7141Shader *Context::getShader(GLuint handle) const
7142{
7143 return mState.mShaderPrograms->getShader(handle);
7144}
7145
7146bool Context::isTextureGenerated(GLuint texture) const
7147{
7148 return mState.mTextures->isHandleGenerated(texture);
7149}
7150
7151bool Context::isBufferGenerated(GLuint buffer) const
7152{
7153 return mState.mBuffers->isHandleGenerated(buffer);
7154}
7155
7156bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
7157{
7158 return mState.mRenderbuffers->isHandleGenerated(renderbuffer);
7159}
7160
7161bool Context::isFramebufferGenerated(GLuint framebuffer) const
7162{
7163 return mState.mFramebuffers->isHandleGenerated(framebuffer);
7164}
7165
7166bool Context::isProgramPipelineGenerated(GLuint pipeline) const
7167{
7168 return mState.mPipelines->isHandleGenerated(pipeline);
7169}
7170
7171bool Context::usingDisplayTextureShareGroup() const
7172{
7173 return mDisplayTextureShareGroup;
7174}
7175
7176GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
7177{
7178 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
7179 internalformat == GL_DEPTH_STENCIL
7180 ? GL_DEPTH24_STENCIL8
7181 : internalformat;
7182}
7183
Jamie Madillc29968b2016-01-20 11:17:23 -05007184} // namespace gl