blob: d580009a7c65aa9fb3945c8f646273f39c6c9ef0 [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"
Lingfeng Yang461b09a2018-04-23 09:02:09 -070027#include "libANGLE/GLES1Renderer.h"
Sami Väisänene45e53b2016-05-25 10:36:04 +030028#include "libANGLE/Path.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050029#include "libANGLE/Program.h"
Yunchao Hea336b902017-08-02 16:05:21 +080030#include "libANGLE/ProgramPipeline.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050031#include "libANGLE/Query.h"
Jamie Madillb9293972015-02-19 11:07:54 -050032#include "libANGLE/Renderbuffer.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050033#include "libANGLE/ResourceManager.h"
34#include "libANGLE/Sampler.h"
Jamie Madill9dd0cf02014-11-24 11:38:51 -050035#include "libANGLE/Surface.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050036#include "libANGLE/Texture.h"
37#include "libANGLE/TransformFeedback.h"
38#include "libANGLE/VertexArray.h"
Kenneth Russellf2f6f652016-10-05 19:53:23 -070039#include "libANGLE/Workarounds.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040040#include "libANGLE/formatutils.h"
Martin Radev66fb8202016-07-28 11:45:20 +030041#include "libANGLE/queryconversions.h"
Geoff Langc1984ed2016-10-07 12:41:00 -040042#include "libANGLE/queryutils.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040043#include "libANGLE/renderer/ContextImpl.h"
44#include "libANGLE/renderer/EGLImplFactory.h"
Jamie Madill7b62cf92017-11-02 15:20:49 -040045#include "libANGLE/renderer/Format.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040046#include "libANGLE/validationES.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000047
Geoff Langf6db0982015-08-25 13:04:00 -040048namespace
49{
50
Jamie Madillb6664922017-07-25 12:55:04 -040051#define ANGLE_HANDLE_ERR(X) \
52 handleError(X); \
53 return;
54#define ANGLE_CONTEXT_TRY(EXPR) ANGLE_TRY_TEMPLATE(EXPR, ANGLE_HANDLE_ERR);
55
Ian Ewell3ffd78b2016-01-22 16:09:42 -050056template <typename T>
Geoff Lang4ddf5af2016-12-01 14:30:44 -050057std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager,
Sami Väisänend59ca052016-06-21 16:10:00 +030058 GLsizei numPaths,
59 const void *paths,
60 GLuint pathBase)
61{
62 std::vector<gl::Path *> ret;
63 ret.reserve(numPaths);
64
65 const auto *nameArray = static_cast<const T *>(paths);
66
67 for (GLsizei i = 0; i < numPaths; ++i)
68 {
69 const GLuint pathName = nameArray[i] + pathBase;
70
71 ret.push_back(resourceManager.getPath(pathName));
72 }
73
74 return ret;
75}
76
Geoff Lang4ddf5af2016-12-01 14:30:44 -050077std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager,
Sami Väisänend59ca052016-06-21 16:10:00 +030078 GLsizei numPaths,
79 GLenum pathNameType,
80 const void *paths,
81 GLuint pathBase)
82{
83 switch (pathNameType)
84 {
85 case GL_UNSIGNED_BYTE:
86 return GatherPaths<GLubyte>(resourceManager, numPaths, paths, pathBase);
87
88 case GL_BYTE:
89 return GatherPaths<GLbyte>(resourceManager, numPaths, paths, pathBase);
90
91 case GL_UNSIGNED_SHORT:
92 return GatherPaths<GLushort>(resourceManager, numPaths, paths, pathBase);
93
94 case GL_SHORT:
95 return GatherPaths<GLshort>(resourceManager, numPaths, paths, pathBase);
96
97 case GL_UNSIGNED_INT:
98 return GatherPaths<GLuint>(resourceManager, numPaths, paths, pathBase);
99
100 case GL_INT:
101 return GatherPaths<GLint>(resourceManager, numPaths, paths, pathBase);
102 }
103
104 UNREACHABLE();
105 return std::vector<gl::Path *>();
106}
107
108template <typename T>
Geoff Lang2186c382016-10-14 10:54:54 -0400109gl::Error GetQueryObjectParameter(gl::Query *query, GLenum pname, T *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500110{
Geoff Lang2186c382016-10-14 10:54:54 -0400111 ASSERT(query != nullptr);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500112
113 switch (pname)
114 {
115 case GL_QUERY_RESULT_EXT:
Geoff Lang2186c382016-10-14 10:54:54 -0400116 return query->getResult(params);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500117 case GL_QUERY_RESULT_AVAILABLE_EXT:
118 {
119 bool available;
Geoff Lang2186c382016-10-14 10:54:54 -0400120 gl::Error error = query->isResultAvailable(&available);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500121 if (!error.isError())
122 {
jchen10a99ed552017-09-22 08:10:32 +0800123 *params = gl::CastFromStateValue<T>(pname, static_cast<GLuint>(available));
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500124 }
125 return error;
126 }
127 default:
128 UNREACHABLE();
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500129 return gl::InternalError() << "Unreachable Error";
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500130 }
131}
132
Jamie Madill09463932018-04-04 05:26:59 -0400133void MarkTransformFeedbackBufferUsage(const gl::Context *context,
134 gl::TransformFeedback *transformFeedback,
James Darpinian30b604d2018-03-12 17:26:57 -0700135 GLsizei count,
136 GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -0400137{
Geoff Lang1a683462015-09-29 15:09:59 -0400138 if (transformFeedback && transformFeedback->isActive() && !transformFeedback->isPaused())
Geoff Langf6db0982015-08-25 13:04:00 -0400139 {
Jamie Madill09463932018-04-04 05:26:59 -0400140 transformFeedback->onVerticesDrawn(context, count, instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -0400141 }
142}
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500143
144// Attribute map queries.
Martin Radev1be913c2016-07-11 17:59:16 +0300145EGLint GetClientMajorVersion(const egl::AttributeMap &attribs)
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500146{
Ian Ewellec2c0c52016-04-05 13:46:26 -0400147 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_CLIENT_VERSION, 1));
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500148}
149
Martin Radev1be913c2016-07-11 17:59:16 +0300150EGLint GetClientMinorVersion(const egl::AttributeMap &attribs)
151{
152 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_MINOR_VERSION, 0));
153}
154
Geoff Langeb66a6e2016-10-31 13:06:12 -0400155gl::Version GetClientVersion(const egl::AttributeMap &attribs)
156{
157 return gl::Version(GetClientMajorVersion(attribs), GetClientMinorVersion(attribs));
158}
159
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500160GLenum GetResetStrategy(const egl::AttributeMap &attribs)
161{
Lingfeng Yangb27b03a2018-02-19 13:38:48 -0800162 EGLAttrib attrib =
163 attribs.get(EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT, EGL_NO_RESET_NOTIFICATION);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500164 switch (attrib)
165 {
166 case EGL_NO_RESET_NOTIFICATION:
167 return GL_NO_RESET_NOTIFICATION_EXT;
168 case EGL_LOSE_CONTEXT_ON_RESET:
169 return GL_LOSE_CONTEXT_ON_RESET_EXT;
170 default:
171 UNREACHABLE();
172 return GL_NONE;
173 }
174}
175
176bool GetRobustAccess(const egl::AttributeMap &attribs)
177{
Geoff Lang077f20a2016-11-01 10:08:02 -0400178 return (attribs.get(EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT, EGL_FALSE) == EGL_TRUE) ||
179 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR) !=
180 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500181}
182
183bool GetDebug(const egl::AttributeMap &attribs)
184{
Geoff Lang077f20a2016-11-01 10:08:02 -0400185 return (attribs.get(EGL_CONTEXT_OPENGL_DEBUG, EGL_FALSE) == EGL_TRUE) ||
186 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR) != 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500187}
188
189bool GetNoError(const egl::AttributeMap &attribs)
190{
191 return (attribs.get(EGL_CONTEXT_OPENGL_NO_ERROR_KHR, EGL_FALSE) == EGL_TRUE);
192}
193
Geoff Langc287ea62016-09-16 14:46:51 -0400194bool GetWebGLContext(const egl::AttributeMap &attribs)
195{
196 return (attribs.get(EGL_CONTEXT_WEBGL_COMPATIBILITY_ANGLE, EGL_FALSE) == EGL_TRUE);
197}
198
Geoff Lang0ab41fa2018-03-14 11:03:30 -0400199bool GetExtensionsEnabled(const egl::AttributeMap &attribs, bool webGLContext)
200{
201 // If the context is WebGL, extensions are disabled by default
202 EGLAttrib defaultValue = webGLContext ? EGL_FALSE : EGL_TRUE;
203 return (attribs.get(EGL_EXTENSIONS_ENABLED_ANGLE, defaultValue) == EGL_TRUE);
204}
205
Geoff Langf41a7152016-09-19 15:11:17 -0400206bool GetBindGeneratesResource(const egl::AttributeMap &attribs)
207{
208 return (attribs.get(EGL_CONTEXT_BIND_GENERATES_RESOURCE_CHROMIUM, EGL_TRUE) == EGL_TRUE);
209}
210
Geoff Langfeb8c682017-02-13 16:07:35 -0500211bool GetClientArraysEnabled(const egl::AttributeMap &attribs)
212{
213 return (attribs.get(EGL_CONTEXT_CLIENT_ARRAYS_ENABLED_ANGLE, EGL_TRUE) == EGL_TRUE);
214}
215
Geoff Langb433e872017-10-05 14:01:47 -0400216bool GetRobustResourceInit(const egl::AttributeMap &attribs)
217{
218 return (attribs.get(EGL_ROBUST_RESOURCE_INITIALIZATION_ANGLE, EGL_FALSE) == EGL_TRUE);
219}
220
Martin Radev9d901792016-07-15 15:58:58 +0300221std::string GetObjectLabelFromPointer(GLsizei length, const GLchar *label)
222{
223 std::string labelName;
224 if (label != nullptr)
225 {
226 size_t labelLength = length < 0 ? strlen(label) : length;
227 labelName = std::string(label, labelLength);
228 }
229 return labelName;
230}
231
232void GetObjectLabelBase(const std::string &objectLabel,
233 GLsizei bufSize,
234 GLsizei *length,
235 GLchar *label)
236{
237 size_t writeLength = objectLabel.length();
238 if (label != nullptr && bufSize > 0)
239 {
240 writeLength = std::min(static_cast<size_t>(bufSize) - 1, objectLabel.length());
241 std::copy(objectLabel.begin(), objectLabel.begin() + writeLength, label);
242 label[writeLength] = '\0';
243 }
244
245 if (length != nullptr)
246 {
247 *length = static_cast<GLsizei>(writeLength);
248 }
249}
250
Jamie Madill0f80ed82017-09-19 00:24:56 -0400251template <typename CapT, typename MaxT>
252void LimitCap(CapT *cap, MaxT maximum)
253{
254 *cap = std::min(*cap, static_cast<CapT>(maximum));
255}
256
Geoff Langf6db0982015-08-25 13:04:00 -0400257} // anonymous namespace
258
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000259namespace gl
260{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +0000261
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400262Context::Context(rx::EGLImplFactory *implFactory,
263 const egl::Config *config,
Corentin Wallez51706ea2015-08-07 14:39:22 -0400264 const Context *shareContext,
Geoff Langce02f082017-02-06 16:46:21 -0500265 TextureManager *shareTextures,
Jamie Madill32447362017-06-28 14:53:52 -0400266 MemoryProgramCache *memoryProgramCache,
Corentin Wallezc295e512017-01-27 17:47:50 -0500267 const egl::AttributeMap &attribs,
Brandon Jones2b0cdcc2018-05-02 08:02:50 -0700268 const egl::DisplayExtensions &displayExtensions,
269 const egl::ClientExtensions &clientExtensions)
Jamie Madill5b772312018-03-08 20:28:32 -0500270 : mState(reinterpret_cast<ContextID>(this),
271 shareContext ? &shareContext->mState : nullptr,
272 shareTextures,
273 GetClientVersion(attribs),
274 &mGLState,
275 mCaps,
276 mTextureCaps,
277 mExtensions,
278 mLimitations),
279 mSkipValidation(GetNoError(attribs)),
280 mDisplayTextureShareGroup(shareTextures != nullptr),
281 mSavedArgsType(nullptr),
Geoff Lang3cacf692018-06-20 16:49:57 -0400282 mImplementation(implFactory->createContext(mState, config, shareContext, attribs)),
Geoff Lang75359662018-04-11 01:42:27 -0400283 mLabel(nullptr),
Jamie Madill2f348d22017-06-05 10:50:59 -0400284 mCompiler(),
Geoff Lang4fb8a8b2018-06-01 16:47:57 -0400285 mGLState(GetDebug(attribs),
286 GetBindGeneratesResource(attribs),
287 GetClientArraysEnabled(attribs),
288 GetRobustResourceInit(attribs),
289 memoryProgramCache != nullptr),
Corentin Walleze3b10e82015-05-20 11:06:25 -0400290 mConfig(config),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500291 mClientType(EGL_OPENGL_ES_API),
292 mHasBeenCurrent(false),
293 mContextLost(false),
294 mResetStatus(GL_NO_ERROR),
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700295 mContextLostForced(false),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500296 mResetStrategy(GetResetStrategy(attribs)),
297 mRobustAccess(GetRobustAccess(attribs)),
Geoff Lang33f11fb2018-05-07 13:42:47 -0400298 mSurfacelessSupported(displayExtensions.surfacelessContext),
299 mExplicitContextAvailable(clientExtensions.explicitContext),
Jamie Madill61e16b42017-06-19 11:13:23 -0400300 mCurrentSurface(static_cast<egl::Surface *>(EGL_NO_SURFACE)),
301 mCurrentDisplay(static_cast<egl::Display *>(EGL_NO_DISPLAY)),
Jamie Madille14951e2017-03-09 18:55:16 -0500302 mWebGLContext(GetWebGLContext(attribs)),
Geoff Lang0ab41fa2018-03-14 11:03:30 -0400303 mExtensionsEnabled(GetExtensionsEnabled(attribs, mWebGLContext)),
Jamie Madill32447362017-06-28 14:53:52 -0400304 mMemoryProgramCache(memoryProgramCache),
Jamie Madillb3f26b92017-07-19 15:07:41 -0400305 mScratchBuffer(1000u),
306 mZeroFilledBuffer(1000u)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000307{
Jamie Madill5b772312018-03-08 20:28:32 -0500308 // Needed to solve a Clang warning of unused variables.
Jamie Madillc6dbc252018-04-30 19:07:56 -0400309 ANGLE_UNUSED_VARIABLE(mSavedArgsType);
310 ANGLE_UNUSED_VARIABLE(mParamsBuffer);
Geoff Lang33f11fb2018-05-07 13:42:47 -0400311}
Jamie Madill5b772312018-03-08 20:28:32 -0500312
Geoff Lang33f11fb2018-05-07 13:42:47 -0400313void Context::initialize()
314{
315 mImplementation->setMemoryProgramCache(mMemoryProgramCache);
Jamie Madill14bbb3f2017-09-12 15:23:01 -0400316
Geoff Lang33f11fb2018-05-07 13:42:47 -0400317 initCaps();
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700318 initWorkarounds();
Geoff Langc0b9ef42014-07-02 10:02:37 -0400319
Geoff Lang4fb8a8b2018-06-01 16:47:57 -0400320 mGLState.initialize(this);
Régis Fénéon83107972015-02-05 12:57:44 +0100321
Shannon Woods53a94a82014-06-24 15:20:36 -0400322 mFenceNVHandleAllocator.setBaseHandle(0);
Geoff Lang7dca1862013-07-30 16:30:46 -0400323
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000324 // [OpenGL ES 2.0.24] section 3.7 page 83:
Corentin Wallez336129f2017-10-17 15:55:40 -0400325 // In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have two-dimensional
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000326 // and cube map texture state vectors respectively associated with them.
327 // In order that access to these initial textures not be lost, they are treated as texture
328 // objects all of whose names are 0.
329
Corentin Wallez99d492c2018-02-27 15:17:10 -0500330 Texture *zeroTexture2D = new Texture(mImplementation.get(), 0, TextureType::_2D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800331 mZeroTextures[TextureType::_2D].set(this, zeroTexture2D);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500332
Corentin Wallez99d492c2018-02-27 15:17:10 -0500333 Texture *zeroTextureCube = new Texture(mImplementation.get(), 0, TextureType::CubeMap);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800334 mZeroTextures[TextureType::CubeMap].set(this, zeroTextureCube);
Geoff Lang76b10c92014-09-05 16:28:14 -0400335
Geoff Langeb66a6e2016-10-31 13:06:12 -0400336 if (getClientVersion() >= Version(3, 0))
Geoff Lang76b10c92014-09-05 16:28:14 -0400337 {
338 // TODO: These could also be enabled via extension
Corentin Wallez99d492c2018-02-27 15:17:10 -0500339 Texture *zeroTexture3D = new Texture(mImplementation.get(), 0, TextureType::_3D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800340 mZeroTextures[TextureType::_3D].set(this, zeroTexture3D);
Geoff Lang76b10c92014-09-05 16:28:14 -0400341
Corentin Wallez99d492c2018-02-27 15:17:10 -0500342 Texture *zeroTexture2DArray = new Texture(mImplementation.get(), 0, TextureType::_2DArray);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800343 mZeroTextures[TextureType::_2DArray].set(this, zeroTexture2DArray);
Geoff Lang76b10c92014-09-05 16:28:14 -0400344 }
Geoff Lang3b573612016-10-31 14:08:10 -0400345 if (getClientVersion() >= Version(3, 1))
346 {
347 Texture *zeroTexture2DMultisample =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500348 new Texture(mImplementation.get(), 0, TextureType::_2DMultisample);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800349 mZeroTextures[TextureType::_2DMultisample].set(this, zeroTexture2DMultisample);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800350
Jiajia Qin6eafb042016-12-27 17:04:07 +0800351 for (unsigned int i = 0; i < mCaps.maxAtomicCounterBufferBindings; i++)
352 {
Qin Jiajia339f65b2018-02-27 12:52:48 +0800353 bindBufferRange(BufferBinding::AtomicCounter, i, 0, 0, 0);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800354 }
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800355
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800356 for (unsigned int i = 0; i < mCaps.maxShaderStorageBufferBindings; i++)
357 {
Corentin Wallez336129f2017-10-17 15:55:40 -0400358 bindBufferRange(BufferBinding::ShaderStorage, i, 0, 0, 0);
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800359 }
Geoff Lang3b573612016-10-31 14:08:10 -0400360 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000361
Geoff Langb0f917f2017-12-05 13:41:54 -0500362 if (mSupportedExtensions.textureRectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400363 {
364 Texture *zeroTextureRectangle =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500365 new Texture(mImplementation.get(), 0, TextureType::Rectangle);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800366 mZeroTextures[TextureType::Rectangle].set(this, zeroTextureRectangle);
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400367 }
368
Geoff Langb0f917f2017-12-05 13:41:54 -0500369 if (mSupportedExtensions.eglImageExternal || mSupportedExtensions.eglStreamConsumerExternal)
Ian Ewellbda75592016-04-18 17:25:54 -0400370 {
Corentin Wallez99d492c2018-02-27 15:17:10 -0500371 Texture *zeroTextureExternal = new Texture(mImplementation.get(), 0, TextureType::External);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800372 mZeroTextures[TextureType::External].set(this, zeroTextureExternal);
Ian Ewellbda75592016-04-18 17:25:54 -0400373 }
374
Jamie Madill4928b7c2017-06-20 12:57:39 -0400375 mGLState.initializeZeroTextures(this, mZeroTextures);
Jamie Madille6382c32014-11-07 15:05:26 -0500376
Jamie Madill57a89722013-07-02 11:57:03 -0400377 bindVertexArray(0);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000378
Geoff Langeb66a6e2016-10-31 13:06:12 -0400379 if (getClientVersion() >= Version(3, 0))
Geoff Lang1a683462015-09-29 15:09:59 -0400380 {
381 // [OpenGL ES 3.0.2] section 2.14.1 pg 85:
382 // In the initial state, a default transform feedback object is bound and treated as
383 // a transform feedback object with a name of zero. That object is bound any time
384 // BindTransformFeedback is called with id of zero
Jamie Madillf0dcb8b2017-08-26 19:05:13 -0400385 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Geoff Lang1a683462015-09-29 15:09:59 -0400386 }
Geoff Langc8058452014-02-03 12:04:11 -0500387
Corentin Wallez336129f2017-10-17 15:55:40 -0400388 for (auto type : angle::AllEnums<BufferBinding>())
389 {
390 bindBuffer(type, 0);
391 }
392
393 bindRenderbuffer(GL_RENDERBUFFER, 0);
394
395 for (unsigned int i = 0; i < mCaps.maxUniformBufferBindings; i++)
396 {
397 bindBufferRange(BufferBinding::Uniform, i, 0, 0, -1);
398 }
399
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700400 // Initialize GLES1 renderer if appropriate.
401 if (getClientVersion() < Version(2, 0))
402 {
403 mGLES1Renderer.reset(new GLES1Renderer());
404 }
405
Jamie Madillad9f24e2016-02-12 09:27:24 -0500406 // Initialize dirty bit masks
Jamie Madillc67323a2017-11-02 23:11:41 -0400407 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500408 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500409 // No dirty objects.
410
411 // Readpixels uses the pack state and read FBO
Jamie Madillc67323a2017-11-02 23:11:41 -0400412 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500413 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500414 mReadPixelsDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
415
416 mClearDirtyBits.set(State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED);
417 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
418 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR);
419 mClearDirtyBits.set(State::DIRTY_BIT_VIEWPORT);
420 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_COLOR);
421 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_DEPTH);
422 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_STENCIL);
423 mClearDirtyBits.set(State::DIRTY_BIT_COLOR_MASK);
424 mClearDirtyBits.set(State::DIRTY_BIT_DEPTH_MASK);
425 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT);
426 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_BACK);
427 mClearDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
428
429 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
430 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR);
Geoff Lang1d2c41d2016-10-19 16:14:46 -0700431 mBlitDirtyBits.set(State::DIRTY_BIT_FRAMEBUFFER_SRGB);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500432 mBlitDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
433 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
Jamie Madill437fa652016-05-03 15:13:24 -0400434
Xinghua Cao10a4d432017-11-28 14:46:26 +0800435 // TODO(xinghua.cao@intel.com): add other dirty bits and dirty objects.
436 mComputeDirtyBits.set(State::DIRTY_BIT_SHADER_STORAGE_BUFFER_BINDING);
437 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_BINDING);
438 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_EXECUTABLE);
439 mComputeDirtyBits.set(State::DIRTY_BIT_TEXTURE_BINDINGS);
440 mComputeDirtyBits.set(State::DIRTY_BIT_SAMPLER_BINDINGS);
Qin Jiajia62fcf622017-11-30 16:16:12 +0800441 mComputeDirtyBits.set(State::DIRTY_BIT_DISPATCH_INDIRECT_BUFFER_BINDING);
Jiajia Qin5ae6ee42018-03-06 17:39:42 +0800442 mComputeDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM_TEXTURES);
Xinghua Cao10a4d432017-11-28 14:46:26 +0800443
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400444 handleError(mImplementation->initialize());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000445}
446
Jamie Madill4928b7c2017-06-20 12:57:39 -0400447egl::Error Context::onDestroy(const egl::Display *display)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000448{
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700449 if (mGLES1Renderer)
450 {
451 mGLES1Renderer->onDestroy(this, &mGLState);
452 }
453
Jamie Madille7b3fe22018-04-05 09:42:46 -0400454 // Delete the Surface first to trigger a finish() in Vulkan.
Jamie Madille7b3fe22018-04-05 09:42:46 -0400455 ANGLE_TRY(releaseSurface(display));
456
Corentin Wallez80b24112015-08-25 16:41:57 -0400457 for (auto fence : mFenceNVMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000458 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400459 SafeDelete(fence.second);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000460 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400461 mFenceNVMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000462
Corentin Wallez80b24112015-08-25 16:41:57 -0400463 for (auto query : mQueryMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000464 {
Geoff Langf0aa8422015-09-29 15:08:34 -0400465 if (query.second != nullptr)
466 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400467 query.second->release(this);
Geoff Langf0aa8422015-09-29 15:08:34 -0400468 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000469 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400470 mQueryMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000471
Corentin Wallez80b24112015-08-25 16:41:57 -0400472 for (auto vertexArray : mVertexArrayMap)
Jamie Madill57a89722013-07-02 11:57:03 -0400473 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400474 if (vertexArray.second)
475 {
476 vertexArray.second->onDestroy(this);
477 }
Jamie Madill57a89722013-07-02 11:57:03 -0400478 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400479 mVertexArrayMap.clear();
Jamie Madill57a89722013-07-02 11:57:03 -0400480
Corentin Wallez80b24112015-08-25 16:41:57 -0400481 for (auto transformFeedback : mTransformFeedbackMap)
Geoff Langc8058452014-02-03 12:04:11 -0500482 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500483 if (transformFeedback.second != nullptr)
484 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500485 transformFeedback.second->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500486 }
Geoff Langc8058452014-02-03 12:04:11 -0500487 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400488 mTransformFeedbackMap.clear();
Geoff Langc8058452014-02-03 12:04:11 -0500489
Jamie Madill5b772312018-03-08 20:28:32 -0500490 for (BindingPointer<Texture> &zeroTexture : mZeroTextures)
Geoff Lang76b10c92014-09-05 16:28:14 -0400491 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800492 if (zeroTexture.get() != nullptr)
493 {
494 ANGLE_TRY(zeroTexture->onDestroy(this));
495 zeroTexture.set(this, nullptr);
496 }
Geoff Lang76b10c92014-09-05 16:28:14 -0400497 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000498
Jamie Madill2f348d22017-06-05 10:50:59 -0400499 releaseShaderCompiler();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500500
Jamie Madill4928b7c2017-06-20 12:57:39 -0400501 mGLState.reset(this);
502
Jamie Madill6c1f6712017-02-14 19:08:04 -0500503 mState.mBuffers->release(this);
504 mState.mShaderPrograms->release(this);
505 mState.mTextures->release(this);
506 mState.mRenderbuffers->release(this);
507 mState.mSamplers->release(this);
Jamie Madill70b5bb02017-08-28 13:32:37 -0400508 mState.mSyncs->release(this);
Jamie Madill6c1f6712017-02-14 19:08:04 -0500509 mState.mPaths->release(this);
510 mState.mFramebuffers->release(this);
Yunchao Hea336b902017-08-02 16:05:21 +0800511 mState.mPipelines->release(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400512
Jamie Madill76e471e2017-10-21 09:56:01 -0400513 mImplementation->onDestroy(this);
514
Jamie Madill4928b7c2017-06-20 12:57:39 -0400515 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000516}
517
Jamie Madill70ee0f62017-02-06 16:04:20 -0500518Context::~Context()
519{
520}
521
Geoff Lang75359662018-04-11 01:42:27 -0400522void Context::setLabel(EGLLabelKHR label)
523{
524 mLabel = label;
525}
526
527EGLLabelKHR Context::getLabel() const
528{
529 return mLabel;
530}
531
Jamie Madill4928b7c2017-06-20 12:57:39 -0400532egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000533{
Jamie Madill61e16b42017-06-19 11:13:23 -0400534 mCurrentDisplay = display;
535
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000536 if (!mHasBeenCurrent)
537 {
Geoff Lang33f11fb2018-05-07 13:42:47 -0400538 initialize();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000539 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500540 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400541 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000542
Corentin Wallezc295e512017-01-27 17:47:50 -0500543 int width = 0;
544 int height = 0;
545 if (surface != nullptr)
546 {
547 width = surface->getWidth();
548 height = surface->getHeight();
549 }
550
551 mGLState.setViewportParams(0, 0, width, height);
552 mGLState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000553
554 mHasBeenCurrent = true;
555 }
556
Jamie Madill1b94d432015-08-07 13:23:23 -0400557 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700558 mGLState.setAllDirtyBits();
Jamie Madill81c2e252017-09-09 23:32:46 -0400559 mGLState.setAllDirtyObjects();
Jamie Madill1b94d432015-08-07 13:23:23 -0400560
Jamie Madill4928b7c2017-06-20 12:57:39 -0400561 ANGLE_TRY(releaseSurface(display));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500562
563 Framebuffer *newDefault = nullptr;
564 if (surface != nullptr)
565 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400566 ANGLE_TRY(surface->setIsCurrent(this, true));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500567 mCurrentSurface = surface;
Geoff Langbf7b95d2018-05-01 16:48:21 -0400568 newDefault = surface->createDefaultFramebuffer(this);
Corentin Wallezccab69d2017-01-27 16:57:15 -0500569 }
570 else
571 {
Geoff Langbf7b95d2018-05-01 16:48:21 -0400572 newDefault = new Framebuffer(mImplementation.get());
Corentin Wallezccab69d2017-01-27 16:57:15 -0500573 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000574
Corentin Wallez37c39792015-08-20 14:19:46 -0400575 // Update default framebuffer, the binding of the previous default
576 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400577 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700578 if (mGLState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400579 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700580 mGLState.setReadFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400581 }
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700582 if (mGLState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400583 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700584 mGLState.setDrawFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400585 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500586 mState.mFramebuffers->setDefaultFramebuffer(newDefault);
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400587 }
Ian Ewell292f0052016-02-04 10:37:32 -0500588
589 // Notify the renderer of a context switch
Jamie Madill4928b7c2017-06-20 12:57:39 -0400590 mImplementation->onMakeCurrent(this);
591 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000592}
593
Jamie Madill4928b7c2017-06-20 12:57:39 -0400594egl::Error Context::releaseSurface(const egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400595{
Geoff Langbf7b95d2018-05-01 16:48:21 -0400596 gl::Framebuffer *defaultFramebuffer = mState.mFramebuffers->getFramebuffer(0);
Corentin Wallez51706ea2015-08-07 14:39:22 -0400597
Geoff Langbf7b95d2018-05-01 16:48:21 -0400598 // Remove the default framebuffer
599 if (mGLState.getReadFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500600 {
601 mGLState.setReadFramebufferBinding(nullptr);
602 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400603
604 if (mGLState.getDrawFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500605 {
606 mGLState.setDrawFramebufferBinding(nullptr);
607 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400608
609 if (defaultFramebuffer)
610 {
611 defaultFramebuffer->onDestroy(this);
612 delete defaultFramebuffer;
613 }
614
Corentin Wallezc295e512017-01-27 17:47:50 -0500615 mState.mFramebuffers->setDefaultFramebuffer(nullptr);
616
617 if (mCurrentSurface)
618 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400619 ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
Corentin Wallezc295e512017-01-27 17:47:50 -0500620 mCurrentSurface = nullptr;
621 }
Jamie Madill4928b7c2017-06-20 12:57:39 -0400622
623 return egl::NoError();
Jamie Madill77a72f62015-04-14 11:18:32 -0400624}
625
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000626GLuint Context::createBuffer()
627{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500628 return mState.mBuffers->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000629}
630
631GLuint Context::createProgram()
632{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500633 return mState.mShaderPrograms->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000634}
635
Jiawei Shao385b3e02018-03-21 09:43:28 +0800636GLuint Context::createShader(ShaderType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000637{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500638 return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000639}
640
641GLuint Context::createTexture()
642{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500643 return mState.mTextures->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000644}
645
646GLuint Context::createRenderbuffer()
647{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500648 return mState.mRenderbuffers->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000649}
650
Brandon Jones59770802018-04-02 13:18:42 -0700651GLuint Context::genPaths(GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300652{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500653 auto resultOrError = mState.mPaths->createPaths(mImplementation.get(), range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300654 if (resultOrError.isError())
655 {
656 handleError(resultOrError.getError());
657 return 0;
658 }
659 return resultOrError.getResult();
660}
661
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000662// Returns an unused framebuffer name
663GLuint Context::createFramebuffer()
664{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500665 return mState.mFramebuffers->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000666}
667
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500668void Context::genFencesNV(GLsizei n, GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000669{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500670 for (int i = 0; i < n; i++)
671 {
672 GLuint handle = mFenceNVHandleAllocator.allocate();
673 mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV()));
674 fences[i] = handle;
675 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000676}
677
Yunchao Hea336b902017-08-02 16:05:21 +0800678GLuint Context::createProgramPipeline()
679{
680 return mState.mPipelines->createProgramPipeline();
681}
682
Jiawei Shao385b3e02018-03-21 09:43:28 +0800683GLuint Context::createShaderProgramv(ShaderType type, GLsizei count, const GLchar *const *strings)
Jiajia Qin5451d532017-11-16 17:16:34 +0800684{
685 UNIMPLEMENTED();
686 return 0u;
687}
688
James Darpinian4d9d4832018-03-13 12:43:28 -0700689void Context::deleteBuffer(GLuint bufferName)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000690{
James Darpinian4d9d4832018-03-13 12:43:28 -0700691 Buffer *buffer = mState.mBuffers->getBuffer(bufferName);
692 if (buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000693 {
694 detachBuffer(buffer);
695 }
Jamie Madill893ab082014-05-16 16:56:10 -0400696
James Darpinian4d9d4832018-03-13 12:43:28 -0700697 mState.mBuffers->deleteObject(this, bufferName);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000698}
699
700void Context::deleteShader(GLuint shader)
701{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500702 mState.mShaderPrograms->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000703}
704
705void Context::deleteProgram(GLuint program)
706{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500707 mState.mShaderPrograms->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000708}
709
710void Context::deleteTexture(GLuint texture)
711{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500712 if (mState.mTextures->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000713 {
714 detachTexture(texture);
715 }
716
Jamie Madill6c1f6712017-02-14 19:08:04 -0500717 mState.mTextures->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000718}
719
720void Context::deleteRenderbuffer(GLuint renderbuffer)
721{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500722 if (mState.mRenderbuffers->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000723 {
724 detachRenderbuffer(renderbuffer);
725 }
Jamie Madill893ab082014-05-16 16:56:10 -0400726
Jamie Madill6c1f6712017-02-14 19:08:04 -0500727 mState.mRenderbuffers->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000728}
729
Jamie Madill7f0c5a42017-08-26 22:43:26 -0400730void Context::deleteSync(GLsync sync)
Jamie Madillcd055f82013-07-26 11:55:15 -0400731{
732 // The spec specifies the underlying Fence object is not deleted until all current
733 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
734 // and since our API is currently designed for being called from a single thread, we can delete
735 // the fence immediately.
Jamie Madill70b5bb02017-08-28 13:32:37 -0400736 mState.mSyncs->deleteObject(this, static_cast<GLuint>(reinterpret_cast<uintptr_t>(sync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400737}
738
Yunchao Hea336b902017-08-02 16:05:21 +0800739void Context::deleteProgramPipeline(GLuint pipeline)
740{
741 if (mState.mPipelines->getProgramPipeline(pipeline))
742 {
743 detachProgramPipeline(pipeline);
744 }
745
746 mState.mPipelines->deleteObject(this, pipeline);
747}
748
Sami Väisänene45e53b2016-05-25 10:36:04 +0300749void Context::deletePaths(GLuint first, GLsizei range)
750{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500751 mState.mPaths->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300752}
753
Brandon Jones59770802018-04-02 13:18:42 -0700754bool Context::isPath(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300755{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500756 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300757 if (pathObj == nullptr)
758 return false;
759
760 return pathObj->hasPathData();
761}
762
Brandon Jones59770802018-04-02 13:18:42 -0700763bool Context::isPathGenerated(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300764{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500765 return mState.mPaths->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300766}
767
Brandon Jones59770802018-04-02 13:18:42 -0700768void Context::pathCommands(GLuint path,
769 GLsizei numCommands,
770 const GLubyte *commands,
771 GLsizei numCoords,
772 GLenum coordType,
773 const void *coords)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300774{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500775 auto *pathObject = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300776
777 handleError(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
778}
779
Jamie Madill007530e2017-12-28 14:27:04 -0500780void Context::pathParameterf(GLuint path, GLenum pname, GLfloat value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300781{
Jamie Madill007530e2017-12-28 14:27:04 -0500782 Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300783
784 switch (pname)
785 {
786 case GL_PATH_STROKE_WIDTH_CHROMIUM:
787 pathObj->setStrokeWidth(value);
788 break;
789 case GL_PATH_END_CAPS_CHROMIUM:
790 pathObj->setEndCaps(static_cast<GLenum>(value));
791 break;
792 case GL_PATH_JOIN_STYLE_CHROMIUM:
793 pathObj->setJoinStyle(static_cast<GLenum>(value));
794 break;
795 case GL_PATH_MITER_LIMIT_CHROMIUM:
796 pathObj->setMiterLimit(value);
797 break;
798 case GL_PATH_STROKE_BOUND_CHROMIUM:
799 pathObj->setStrokeBound(value);
800 break;
801 default:
802 UNREACHABLE();
803 break;
804 }
805}
806
Jamie Madill007530e2017-12-28 14:27:04 -0500807void Context::pathParameteri(GLuint path, GLenum pname, GLint value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300808{
Jamie Madill007530e2017-12-28 14:27:04 -0500809 // TODO(jmadill): Should use proper clamping/casting.
810 pathParameterf(path, pname, static_cast<GLfloat>(value));
811}
812
813void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value)
814{
815 const Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300816
817 switch (pname)
818 {
819 case GL_PATH_STROKE_WIDTH_CHROMIUM:
820 *value = pathObj->getStrokeWidth();
821 break;
822 case GL_PATH_END_CAPS_CHROMIUM:
823 *value = static_cast<GLfloat>(pathObj->getEndCaps());
824 break;
825 case GL_PATH_JOIN_STYLE_CHROMIUM:
826 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
827 break;
828 case GL_PATH_MITER_LIMIT_CHROMIUM:
829 *value = pathObj->getMiterLimit();
830 break;
831 case GL_PATH_STROKE_BOUND_CHROMIUM:
832 *value = pathObj->getStrokeBound();
833 break;
834 default:
835 UNREACHABLE();
836 break;
837 }
838}
839
Jamie Madill007530e2017-12-28 14:27:04 -0500840void Context::getPathParameteriv(GLuint path, GLenum pname, GLint *value)
841{
842 GLfloat val = 0.0f;
843 getPathParameterfv(path, pname, value != nullptr ? &val : nullptr);
844 if (value)
845 *value = static_cast<GLint>(val);
846}
847
Brandon Jones59770802018-04-02 13:18:42 -0700848void Context::pathStencilFunc(GLenum func, GLint ref, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300849{
850 mGLState.setPathStencilFunc(func, ref, mask);
851}
852
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000853void Context::deleteFramebuffer(GLuint framebuffer)
854{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500855 if (mState.mFramebuffers->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000856 {
857 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000858 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500859
Jamie Madill6c1f6712017-02-14 19:08:04 -0500860 mState.mFramebuffers->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000861}
862
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500863void Context::deleteFencesNV(GLsizei n, const GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000864{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500865 for (int i = 0; i < n; i++)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000866 {
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500867 GLuint fence = fences[i];
868
869 FenceNV *fenceObject = nullptr;
870 if (mFenceNVMap.erase(fence, &fenceObject))
871 {
872 mFenceNVHandleAllocator.release(fence);
873 delete fenceObject;
874 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000875 }
876}
877
Geoff Lang70d0f492015-12-10 17:45:46 -0500878Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000879{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500880 return mState.mBuffers->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000881}
882
Jamie Madill570f7c82014-07-03 10:38:54 -0400883Texture *Context::getTexture(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000884{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500885 return mState.mTextures->getTexture(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000886}
887
Geoff Lang70d0f492015-12-10 17:45:46 -0500888Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000889{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500890 return mState.mRenderbuffers->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000891}
892
Jamie Madill70b5bb02017-08-28 13:32:37 -0400893Sync *Context::getSync(GLsync handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400894{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400895 return mState.mSyncs->getSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400896}
897
Jamie Madill57a89722013-07-02 11:57:03 -0400898VertexArray *Context::getVertexArray(GLuint handle) const
899{
Jamie Madill96a483b2017-06-27 16:49:21 -0400900 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -0400901}
902
Jamie Madilldc356042013-07-19 16:36:57 -0400903Sampler *Context::getSampler(GLuint handle) const
904{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500905 return mState.mSamplers->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400906}
907
Geoff Langc8058452014-02-03 12:04:11 -0500908TransformFeedback *Context::getTransformFeedback(GLuint handle) const
909{
Jamie Madill96a483b2017-06-27 16:49:21 -0400910 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -0500911}
912
Yunchao Hea336b902017-08-02 16:05:21 +0800913ProgramPipeline *Context::getProgramPipeline(GLuint handle) const
914{
915 return mState.mPipelines->getProgramPipeline(handle);
916}
917
Geoff Lang75359662018-04-11 01:42:27 -0400918gl::LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
Geoff Lang70d0f492015-12-10 17:45:46 -0500919{
920 switch (identifier)
921 {
922 case GL_BUFFER:
923 return getBuffer(name);
924 case GL_SHADER:
925 return getShader(name);
926 case GL_PROGRAM:
927 return getProgram(name);
928 case GL_VERTEX_ARRAY:
929 return getVertexArray(name);
930 case GL_QUERY:
931 return getQuery(name);
932 case GL_TRANSFORM_FEEDBACK:
933 return getTransformFeedback(name);
934 case GL_SAMPLER:
935 return getSampler(name);
936 case GL_TEXTURE:
937 return getTexture(name);
938 case GL_RENDERBUFFER:
939 return getRenderbuffer(name);
940 case GL_FRAMEBUFFER:
941 return getFramebuffer(name);
942 default:
943 UNREACHABLE();
944 return nullptr;
945 }
946}
947
Geoff Lang75359662018-04-11 01:42:27 -0400948gl::LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
Geoff Lang70d0f492015-12-10 17:45:46 -0500949{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400950 return getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
Geoff Lang70d0f492015-12-10 17:45:46 -0500951}
952
Martin Radev9d901792016-07-15 15:58:58 +0300953void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
954{
Geoff Lang75359662018-04-11 01:42:27 -0400955 gl::LabeledObject *object = getLabeledObject(identifier, name);
Martin Radev9d901792016-07-15 15:58:58 +0300956 ASSERT(object != nullptr);
957
958 std::string labelName = GetObjectLabelFromPointer(length, label);
959 object->setLabel(labelName);
Jamie Madill8693bdb2017-09-02 15:32:14 -0400960
961 // TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the
962 // specified object is active until we do this.
963 mGLState.setObjectDirty(identifier);
Martin Radev9d901792016-07-15 15:58:58 +0300964}
965
966void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
967{
Geoff Lang75359662018-04-11 01:42:27 -0400968 gl::LabeledObject *object = getLabeledObjectFromPtr(ptr);
Martin Radev9d901792016-07-15 15:58:58 +0300969 ASSERT(object != nullptr);
970
971 std::string labelName = GetObjectLabelFromPointer(length, label);
972 object->setLabel(labelName);
973}
974
975void Context::getObjectLabel(GLenum identifier,
976 GLuint name,
977 GLsizei bufSize,
978 GLsizei *length,
979 GLchar *label) const
980{
Geoff Lang75359662018-04-11 01:42:27 -0400981 gl::LabeledObject *object = getLabeledObject(identifier, name);
Martin Radev9d901792016-07-15 15:58:58 +0300982 ASSERT(object != nullptr);
983
984 const std::string &objectLabel = object->getLabel();
985 GetObjectLabelBase(objectLabel, bufSize, length, label);
986}
987
988void Context::getObjectPtrLabel(const void *ptr,
989 GLsizei bufSize,
990 GLsizei *length,
991 GLchar *label) const
992{
Geoff Lang75359662018-04-11 01:42:27 -0400993 gl::LabeledObject *object = getLabeledObjectFromPtr(ptr);
Martin Radev9d901792016-07-15 15:58:58 +0300994 ASSERT(object != nullptr);
995
996 const std::string &objectLabel = object->getLabel();
997 GetObjectLabelBase(objectLabel, bufSize, length, label);
998}
999
Jamie Madilldc356042013-07-19 16:36:57 -04001000bool Context::isSampler(GLuint samplerName) const
1001{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001002 return mState.mSamplers->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -04001003}
1004
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001005void Context::bindTexture(TextureType target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001006{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001007 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001008
Jamie Madilldedd7b92014-11-05 16:30:36 -05001009 if (handle == 0)
1010 {
1011 texture = mZeroTextures[target].get();
1012 }
1013 else
1014 {
Corentin Wallez99d492c2018-02-27 15:17:10 -05001015 texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -05001016 }
1017
1018 ASSERT(texture);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001019 mGLState.setSamplerTexture(this, target, texture);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00001020}
1021
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001022void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001023{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001024 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1025 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001026 mGLState.setReadFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001027}
1028
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001029void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001030{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001031 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1032 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001033 mGLState.setDrawFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001034}
1035
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001036void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -04001037{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001038 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madill7267aa62018-04-17 15:28:21 -04001039 mGLState.setVertexArrayBinding(this, vertexArray);
Jamie Madill57a89722013-07-02 11:57:03 -04001040}
1041
Shao80957d92017-02-20 21:25:59 +08001042void Context::bindVertexBuffer(GLuint bindingIndex,
1043 GLuint bufferHandle,
1044 GLintptr offset,
1045 GLsizei stride)
1046{
1047 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001048 mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Shao80957d92017-02-20 21:25:59 +08001049}
1050
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001051void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -04001052{
Geoff Lang76b10c92014-09-05 16:28:14 -04001053 ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -04001054 Sampler *sampler =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001055 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001056 mGLState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04001057}
1058
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001059void Context::bindImageTexture(GLuint unit,
1060 GLuint texture,
1061 GLint level,
1062 GLboolean layered,
1063 GLint layer,
1064 GLenum access,
1065 GLenum format)
1066{
1067 Texture *tex = mState.mTextures->getTexture(texture);
1068 mGLState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
1069}
1070
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001071void Context::useProgram(GLuint program)
1072{
Jamie Madill6c1f6712017-02-14 19:08:04 -05001073 mGLState.setProgram(this, getProgram(program));
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001074}
1075
Jiajia Qin5451d532017-11-16 17:16:34 +08001076void Context::useProgramStages(GLuint pipeline, GLbitfield stages, GLuint program)
1077{
1078 UNIMPLEMENTED();
1079}
1080
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001081void Context::bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001082{
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001083 ASSERT(target == GL_TRANSFORM_FEEDBACK);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001084 TransformFeedback *transformFeedback =
1085 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001086 mGLState.setTransformFeedbackBinding(this, transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -05001087}
1088
Yunchao Hea336b902017-08-02 16:05:21 +08001089void Context::bindProgramPipeline(GLuint pipelineHandle)
1090{
1091 ProgramPipeline *pipeline =
1092 mState.mPipelines->checkProgramPipelineAllocation(mImplementation.get(), pipelineHandle);
1093 mGLState.setProgramPipelineBinding(this, pipeline);
1094}
1095
Corentin Wallezad3ae902018-03-09 13:40:42 -05001096void Context::beginQuery(QueryType target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001097{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001098 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001099 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001100
Geoff Lang5aad9672014-09-08 11:10:42 -04001101 // begin query
Jamie Madillf0e04492017-08-26 15:28:42 -04001102 ANGLE_CONTEXT_TRY(queryObject->begin());
Geoff Lang5aad9672014-09-08 11:10:42 -04001103
1104 // set query as active for specified target only if begin succeeded
Jamie Madill4928b7c2017-06-20 12:57:39 -04001105 mGLState.setActiveQuery(this, target, queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001106}
1107
Corentin Wallezad3ae902018-03-09 13:40:42 -05001108void Context::endQuery(QueryType target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001109{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001110 Query *queryObject = mGLState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001111 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001112
Jamie Madillf0e04492017-08-26 15:28:42 -04001113 handleError(queryObject->end());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001114
Geoff Lang5aad9672014-09-08 11:10:42 -04001115 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madill4928b7c2017-06-20 12:57:39 -04001116 mGLState.setActiveQuery(this, target, nullptr);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001117}
1118
Corentin Wallezad3ae902018-03-09 13:40:42 -05001119void Context::queryCounter(GLuint id, QueryType target)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001120{
Corentin Wallezad3ae902018-03-09 13:40:42 -05001121 ASSERT(target == QueryType::Timestamp);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001122
1123 Query *queryObject = getQuery(id, true, target);
1124 ASSERT(queryObject);
1125
Jamie Madillf0e04492017-08-26 15:28:42 -04001126 handleError(queryObject->queryCounter());
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001127}
1128
Corentin Wallezad3ae902018-03-09 13:40:42 -05001129void Context::getQueryiv(QueryType target, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001130{
1131 switch (pname)
1132 {
1133 case GL_CURRENT_QUERY_EXT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001134 params[0] = mGLState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001135 break;
1136 case GL_QUERY_COUNTER_BITS_EXT:
1137 switch (target)
1138 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001139 case QueryType::TimeElapsed:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001140 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1141 break;
Corentin Wallezad3ae902018-03-09 13:40:42 -05001142 case QueryType::Timestamp:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001143 params[0] = getExtensions().queryCounterBitsTimestamp;
1144 break;
1145 default:
1146 UNREACHABLE();
1147 params[0] = 0;
1148 break;
1149 }
1150 break;
1151 default:
1152 UNREACHABLE();
1153 return;
1154 }
1155}
1156
Corentin Wallezad3ae902018-03-09 13:40:42 -05001157void Context::getQueryivRobust(QueryType target,
Brandon Jones59770802018-04-02 13:18:42 -07001158 GLenum pname,
1159 GLsizei bufSize,
1160 GLsizei *length,
1161 GLint *params)
1162{
1163 getQueryiv(target, pname, params);
1164}
1165
Geoff Lang2186c382016-10-14 10:54:54 -04001166void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001167{
Geoff Lang2186c382016-10-14 10:54:54 -04001168 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001169}
1170
Brandon Jones59770802018-04-02 13:18:42 -07001171void Context::getQueryObjectivRobust(GLuint id,
1172 GLenum pname,
1173 GLsizei bufSize,
1174 GLsizei *length,
1175 GLint *params)
1176{
1177 getQueryObjectiv(id, pname, params);
1178}
1179
Geoff Lang2186c382016-10-14 10:54:54 -04001180void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001181{
Geoff Lang2186c382016-10-14 10:54:54 -04001182 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001183}
1184
Brandon Jones59770802018-04-02 13:18:42 -07001185void Context::getQueryObjectuivRobust(GLuint id,
1186 GLenum pname,
1187 GLsizei bufSize,
1188 GLsizei *length,
1189 GLuint *params)
1190{
1191 getQueryObjectuiv(id, pname, params);
1192}
1193
Geoff Lang2186c382016-10-14 10:54:54 -04001194void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001195{
Geoff Lang2186c382016-10-14 10:54:54 -04001196 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001197}
1198
Brandon Jones59770802018-04-02 13:18:42 -07001199void Context::getQueryObjecti64vRobust(GLuint id,
1200 GLenum pname,
1201 GLsizei bufSize,
1202 GLsizei *length,
1203 GLint64 *params)
1204{
1205 getQueryObjecti64v(id, pname, params);
1206}
1207
Geoff Lang2186c382016-10-14 10:54:54 -04001208void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001209{
Geoff Lang2186c382016-10-14 10:54:54 -04001210 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001211}
1212
Brandon Jones59770802018-04-02 13:18:42 -07001213void Context::getQueryObjectui64vRobust(GLuint id,
1214 GLenum pname,
1215 GLsizei bufSize,
1216 GLsizei *length,
1217 GLuint64 *params)
1218{
1219 getQueryObjectui64v(id, pname, params);
1220}
1221
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001222Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001223{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001224 return mState.mFramebuffers->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001225}
1226
Jamie Madill2f348d22017-06-05 10:50:59 -04001227FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001228{
Jamie Madill96a483b2017-06-27 16:49:21 -04001229 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001230}
1231
Corentin Wallezad3ae902018-03-09 13:40:42 -05001232Query *Context::getQuery(GLuint handle, bool create, QueryType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001233{
Jamie Madill96a483b2017-06-27 16:49:21 -04001234 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001235 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001236 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001237 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001238
1239 Query *query = mQueryMap.query(handle);
1240 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001241 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001242 ASSERT(type != QueryType::InvalidEnum);
Jamie Madill96a483b2017-06-27 16:49:21 -04001243 query = new Query(mImplementation->createQuery(type), handle);
1244 query->addRef();
1245 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001246 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001247 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001248}
1249
Geoff Lang70d0f492015-12-10 17:45:46 -05001250Query *Context::getQuery(GLuint handle) const
1251{
Jamie Madill96a483b2017-06-27 16:49:21 -04001252 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001253}
1254
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001255Texture *Context::getTargetTexture(TextureType type) const
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001256{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001257 ASSERT(ValidTextureTarget(this, type) || ValidTextureExternalTarget(this, type));
1258 return mGLState.getTargetTexture(type);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001259}
1260
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001261Texture *Context::getSamplerTexture(unsigned int sampler, TextureType type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001262{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001263 return mGLState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001264}
1265
Geoff Lang492a7e42014-11-05 13:27:06 -05001266Compiler *Context::getCompiler() const
1267{
Jamie Madill2f348d22017-06-05 10:50:59 -04001268 if (mCompiler.get() == nullptr)
1269 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001270 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001271 }
1272 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001273}
1274
Jamie Madillc1d770e2017-04-13 17:31:24 -04001275void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001276{
1277 switch (pname)
1278 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001279 case GL_SHADER_COMPILER:
1280 *params = GL_TRUE;
1281 break;
1282 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1283 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1284 break;
1285 default:
1286 mGLState.getBooleanv(pname, params);
1287 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001288 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001289}
1290
Jamie Madillc1d770e2017-04-13 17:31:24 -04001291void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001292{
Shannon Woods53a94a82014-06-24 15:20:36 -04001293 // Queries about context capabilities and maximums are answered by Context.
1294 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001295 switch (pname)
1296 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001297 case GL_ALIASED_LINE_WIDTH_RANGE:
1298 params[0] = mCaps.minAliasedLineWidth;
1299 params[1] = mCaps.maxAliasedLineWidth;
1300 break;
1301 case GL_ALIASED_POINT_SIZE_RANGE:
1302 params[0] = mCaps.minAliasedPointSize;
1303 params[1] = mCaps.maxAliasedPointSize;
1304 break;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07001305 case GL_SMOOTH_POINT_SIZE_RANGE:
1306 params[0] = mCaps.minSmoothPointSize;
1307 params[1] = mCaps.maxSmoothPointSize;
1308 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001309 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1310 ASSERT(mExtensions.textureFilterAnisotropic);
1311 *params = mExtensions.maxTextureAnisotropy;
1312 break;
1313 case GL_MAX_TEXTURE_LOD_BIAS:
1314 *params = mCaps.maxLODBias;
1315 break;
1316
1317 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1318 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1319 {
Lingfeng Yang3a41af62018-04-09 07:28:56 -07001320 // GLES1 emulation: // GL_PATH_(MODELVIEW|PROJECTION)_MATRIX_CHROMIUM collides with the
1321 // GLES1 constants for modelview/projection matrix.
1322 if (getClientVersion() < Version(2, 0))
1323 {
1324 mGLState.getFloatv(pname, params);
1325 }
1326 else
1327 {
1328 ASSERT(mExtensions.pathRendering);
1329 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1330 memcpy(params, m, 16 * sizeof(GLfloat));
1331 }
Jamie Madill231c7f52017-04-26 13:45:37 -04001332 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001333 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001334
Jamie Madill231c7f52017-04-26 13:45:37 -04001335 default:
1336 mGLState.getFloatv(pname, params);
1337 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001338 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001339}
1340
Jamie Madillc1d770e2017-04-13 17:31:24 -04001341void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001342{
Shannon Woods53a94a82014-06-24 15:20:36 -04001343 // Queries about context capabilities and maximums are answered by Context.
1344 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001345
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001346 switch (pname)
1347 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001348 case GL_MAX_VERTEX_ATTRIBS:
1349 *params = mCaps.maxVertexAttributes;
1350 break;
1351 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1352 *params = mCaps.maxVertexUniformVectors;
1353 break;
1354 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001355 *params = mCaps.maxShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001356 break;
1357 case GL_MAX_VARYING_VECTORS:
1358 *params = mCaps.maxVaryingVectors;
1359 break;
1360 case GL_MAX_VARYING_COMPONENTS:
1361 *params = mCaps.maxVertexOutputComponents;
1362 break;
1363 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1364 *params = mCaps.maxCombinedTextureImageUnits;
1365 break;
1366 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001367 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001368 break;
1369 case GL_MAX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001370 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001371 break;
1372 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1373 *params = mCaps.maxFragmentUniformVectors;
1374 break;
1375 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001376 *params = mCaps.maxShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001377 break;
1378 case GL_MAX_RENDERBUFFER_SIZE:
1379 *params = mCaps.maxRenderbufferSize;
1380 break;
1381 case GL_MAX_COLOR_ATTACHMENTS_EXT:
1382 *params = mCaps.maxColorAttachments;
1383 break;
1384 case GL_MAX_DRAW_BUFFERS_EXT:
1385 *params = mCaps.maxDrawBuffers;
1386 break;
1387 // case GL_FRAMEBUFFER_BINDING: // now equivalent to
1388 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
1389 case GL_SUBPIXEL_BITS:
1390 *params = 4;
1391 break;
1392 case GL_MAX_TEXTURE_SIZE:
1393 *params = mCaps.max2DTextureSize;
1394 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001395 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
1396 *params = mCaps.maxRectangleTextureSize;
1397 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001398 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1399 *params = mCaps.maxCubeMapTextureSize;
1400 break;
1401 case GL_MAX_3D_TEXTURE_SIZE:
1402 *params = mCaps.max3DTextureSize;
1403 break;
1404 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1405 *params = mCaps.maxArrayTextureLayers;
1406 break;
1407 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1408 *params = mCaps.uniformBufferOffsetAlignment;
1409 break;
1410 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1411 *params = mCaps.maxUniformBufferBindings;
1412 break;
1413 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001414 *params = mCaps.maxShaderUniformBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001415 break;
1416 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001417 *params = mCaps.maxShaderUniformBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001418 break;
1419 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1420 *params = mCaps.maxCombinedTextureImageUnits;
1421 break;
1422 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1423 *params = mCaps.maxVertexOutputComponents;
1424 break;
1425 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1426 *params = mCaps.maxFragmentInputComponents;
1427 break;
1428 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1429 *params = mCaps.minProgramTexelOffset;
1430 break;
1431 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1432 *params = mCaps.maxProgramTexelOffset;
1433 break;
1434 case GL_MAJOR_VERSION:
1435 *params = getClientVersion().major;
1436 break;
1437 case GL_MINOR_VERSION:
1438 *params = getClientVersion().minor;
1439 break;
1440 case GL_MAX_ELEMENTS_INDICES:
1441 *params = mCaps.maxElementsIndices;
1442 break;
1443 case GL_MAX_ELEMENTS_VERTICES:
1444 *params = mCaps.maxElementsVertices;
1445 break;
1446 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1447 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1448 break;
1449 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1450 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1451 break;
1452 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1453 *params = mCaps.maxTransformFeedbackSeparateComponents;
1454 break;
1455 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1456 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1457 break;
1458 case GL_MAX_SAMPLES_ANGLE:
1459 *params = mCaps.maxSamples;
1460 break;
1461 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001462 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001463 params[0] = mCaps.maxViewportWidth;
1464 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001465 }
1466 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001467 case GL_COMPRESSED_TEXTURE_FORMATS:
1468 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1469 params);
1470 break;
1471 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1472 *params = mResetStrategy;
1473 break;
1474 case GL_NUM_SHADER_BINARY_FORMATS:
1475 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1476 break;
1477 case GL_SHADER_BINARY_FORMATS:
1478 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1479 break;
1480 case GL_NUM_PROGRAM_BINARY_FORMATS:
1481 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1482 break;
1483 case GL_PROGRAM_BINARY_FORMATS:
1484 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1485 break;
1486 case GL_NUM_EXTENSIONS:
1487 *params = static_cast<GLint>(mExtensionStrings.size());
1488 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001489
Jamie Madill231c7f52017-04-26 13:45:37 -04001490 // GL_KHR_debug
1491 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1492 *params = mExtensions.maxDebugMessageLength;
1493 break;
1494 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1495 *params = mExtensions.maxDebugLoggedMessages;
1496 break;
1497 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1498 *params = mExtensions.maxDebugGroupStackDepth;
1499 break;
1500 case GL_MAX_LABEL_LENGTH:
1501 *params = mExtensions.maxLabelLength;
1502 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001503
Martin Radeve5285d22017-07-14 16:23:53 +03001504 // GL_ANGLE_multiview
1505 case GL_MAX_VIEWS_ANGLE:
1506 *params = mExtensions.maxViews;
1507 break;
1508
Jamie Madill231c7f52017-04-26 13:45:37 -04001509 // GL_EXT_disjoint_timer_query
1510 case GL_GPU_DISJOINT_EXT:
1511 *params = mImplementation->getGPUDisjoint();
1512 break;
1513 case GL_MAX_FRAMEBUFFER_WIDTH:
1514 *params = mCaps.maxFramebufferWidth;
1515 break;
1516 case GL_MAX_FRAMEBUFFER_HEIGHT:
1517 *params = mCaps.maxFramebufferHeight;
1518 break;
1519 case GL_MAX_FRAMEBUFFER_SAMPLES:
1520 *params = mCaps.maxFramebufferSamples;
1521 break;
1522 case GL_MAX_SAMPLE_MASK_WORDS:
1523 *params = mCaps.maxSampleMaskWords;
1524 break;
1525 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1526 *params = mCaps.maxColorTextureSamples;
1527 break;
1528 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1529 *params = mCaps.maxDepthTextureSamples;
1530 break;
1531 case GL_MAX_INTEGER_SAMPLES:
1532 *params = mCaps.maxIntegerSamples;
1533 break;
1534 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1535 *params = mCaps.maxVertexAttribRelativeOffset;
1536 break;
1537 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1538 *params = mCaps.maxVertexAttribBindings;
1539 break;
1540 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1541 *params = mCaps.maxVertexAttribStride;
1542 break;
1543 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001544 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001545 break;
1546 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001547 *params = mCaps.maxShaderAtomicCounters[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001548 break;
1549 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001550 *params = mCaps.maxShaderImageUniforms[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001551 break;
1552 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001553 *params = mCaps.maxShaderStorageBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001554 break;
1555 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001556 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001557 break;
1558 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001559 *params = mCaps.maxShaderAtomicCounters[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001560 break;
1561 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001562 *params = mCaps.maxShaderImageUniforms[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001563 break;
1564 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001565 *params = mCaps.maxShaderStorageBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001566 break;
1567 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1568 *params = mCaps.minProgramTextureGatherOffset;
1569 break;
1570 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1571 *params = mCaps.maxProgramTextureGatherOffset;
1572 break;
1573 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1574 *params = mCaps.maxComputeWorkGroupInvocations;
1575 break;
1576 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001577 *params = mCaps.maxShaderUniformBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001578 break;
1579 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001580 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001581 break;
1582 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1583 *params = mCaps.maxComputeSharedMemorySize;
1584 break;
1585 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001586 *params = mCaps.maxShaderUniformComponents[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001587 break;
1588 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001589 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001590 break;
1591 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001592 *params = mCaps.maxShaderAtomicCounters[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001593 break;
1594 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001595 *params = mCaps.maxShaderImageUniforms[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001596 break;
1597 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001598 *params =
1599 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Compute]);
Jamie Madill231c7f52017-04-26 13:45:37 -04001600 break;
1601 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001602 *params = mCaps.maxShaderStorageBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001603 break;
1604 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1605 *params = mCaps.maxCombinedShaderOutputResources;
1606 break;
1607 case GL_MAX_UNIFORM_LOCATIONS:
1608 *params = mCaps.maxUniformLocations;
1609 break;
1610 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1611 *params = mCaps.maxAtomicCounterBufferBindings;
1612 break;
1613 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1614 *params = mCaps.maxAtomicCounterBufferSize;
1615 break;
1616 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1617 *params = mCaps.maxCombinedAtomicCounterBuffers;
1618 break;
1619 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1620 *params = mCaps.maxCombinedAtomicCounters;
1621 break;
1622 case GL_MAX_IMAGE_UNITS:
1623 *params = mCaps.maxImageUnits;
1624 break;
1625 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1626 *params = mCaps.maxCombinedImageUniforms;
1627 break;
1628 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1629 *params = mCaps.maxShaderStorageBufferBindings;
1630 break;
1631 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1632 *params = mCaps.maxCombinedShaderStorageBlocks;
1633 break;
1634 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1635 *params = mCaps.shaderStorageBufferOffsetAlignment;
1636 break;
Jiawei Shao361df072017-11-22 09:33:59 +08001637
1638 // GL_EXT_geometry_shader
1639 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
1640 *params = mCaps.maxFramebufferLayers;
1641 break;
1642 case GL_LAYER_PROVOKING_VERTEX_EXT:
1643 *params = mCaps.layerProvokingVertex;
1644 break;
1645 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001646 *params = mCaps.maxShaderUniformComponents[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001647 break;
1648 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001649 *params = mCaps.maxShaderUniformBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001650 break;
1651 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001652 *params =
1653 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Geometry]);
Jiawei Shao361df072017-11-22 09:33:59 +08001654 break;
1655 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
1656 *params = mCaps.maxGeometryInputComponents;
1657 break;
1658 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
1659 *params = mCaps.maxGeometryOutputComponents;
1660 break;
1661 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
1662 *params = mCaps.maxGeometryOutputVertices;
1663 break;
1664 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
1665 *params = mCaps.maxGeometryTotalOutputComponents;
1666 break;
1667 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
1668 *params = mCaps.maxGeometryShaderInvocations;
1669 break;
1670 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001671 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001672 break;
1673 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001674 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001675 break;
1676 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001677 *params = mCaps.maxShaderAtomicCounters[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001678 break;
1679 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001680 *params = mCaps.maxShaderImageUniforms[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001681 break;
1682 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001683 *params = mCaps.maxShaderStorageBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001684 break;
Lingfeng Yang96310cd2018-03-28 11:56:28 -07001685 // GLES1 emulation: Caps queries
1686 case GL_MAX_TEXTURE_UNITS:
1687 *params = mCaps.maxMultitextureUnits;
1688 break;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001689 case GL_MAX_MODELVIEW_STACK_DEPTH:
1690 *params = mCaps.maxModelviewMatrixStackDepth;
1691 break;
1692 case GL_MAX_PROJECTION_STACK_DEPTH:
1693 *params = mCaps.maxProjectionMatrixStackDepth;
1694 break;
1695 case GL_MAX_TEXTURE_STACK_DEPTH:
1696 *params = mCaps.maxTextureMatrixStackDepth;
1697 break;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07001698 case GL_MAX_LIGHTS:
1699 *params = mCaps.maxLights;
1700 break;
Lingfeng Yang060088a2018-05-30 20:40:57 -07001701 case GL_MAX_CLIP_PLANES:
1702 *params = mCaps.maxClipPlanes;
1703 break;
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001704 // GLES1 emulation: Vertex attribute queries
1705 case GL_VERTEX_ARRAY_BUFFER_BINDING:
1706 case GL_NORMAL_ARRAY_BUFFER_BINDING:
1707 case GL_COLOR_ARRAY_BUFFER_BINDING:
1708 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
1709 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
1710 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1711 GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, params);
1712 break;
1713 case GL_VERTEX_ARRAY_STRIDE:
1714 case GL_NORMAL_ARRAY_STRIDE:
1715 case GL_COLOR_ARRAY_STRIDE:
1716 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
1717 case GL_TEXTURE_COORD_ARRAY_STRIDE:
1718 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1719 GL_VERTEX_ATTRIB_ARRAY_STRIDE, params);
1720 break;
1721 case GL_VERTEX_ARRAY_SIZE:
1722 case GL_COLOR_ARRAY_SIZE:
1723 case GL_TEXTURE_COORD_ARRAY_SIZE:
1724 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1725 GL_VERTEX_ATTRIB_ARRAY_SIZE, params);
1726 break;
1727 case GL_VERTEX_ARRAY_TYPE:
1728 case GL_COLOR_ARRAY_TYPE:
1729 case GL_NORMAL_ARRAY_TYPE:
1730 case GL_POINT_SIZE_ARRAY_TYPE_OES:
1731 case GL_TEXTURE_COORD_ARRAY_TYPE:
1732 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1733 GL_VERTEX_ATTRIB_ARRAY_TYPE, params);
1734 break;
1735
Jamie Madill231c7f52017-04-26 13:45:37 -04001736 default:
Jamie Madille98b1b52018-03-08 09:47:23 -05001737 handleError(mGLState.getIntegerv(this, pname, params));
Jamie Madill231c7f52017-04-26 13:45:37 -04001738 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001739 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001740}
1741
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001742void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001743{
Shannon Woods53a94a82014-06-24 15:20:36 -04001744 // Queries about context capabilities and maximums are answered by Context.
1745 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001746 switch (pname)
1747 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001748 case GL_MAX_ELEMENT_INDEX:
1749 *params = mCaps.maxElementIndex;
1750 break;
1751 case GL_MAX_UNIFORM_BLOCK_SIZE:
1752 *params = mCaps.maxUniformBlockSize;
1753 break;
1754 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001755 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001756 break;
1757 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001758 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001759 break;
1760 case GL_MAX_SERVER_WAIT_TIMEOUT:
1761 *params = mCaps.maxServerWaitTimeout;
1762 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001763
Jamie Madill231c7f52017-04-26 13:45:37 -04001764 // GL_EXT_disjoint_timer_query
1765 case GL_TIMESTAMP_EXT:
1766 *params = mImplementation->getTimestamp();
1767 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001768
Jamie Madill231c7f52017-04-26 13:45:37 -04001769 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1770 *params = mCaps.maxShaderStorageBlockSize;
1771 break;
1772 default:
1773 UNREACHABLE();
1774 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001775 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001776}
1777
Geoff Lang70d0f492015-12-10 17:45:46 -05001778void Context::getPointerv(GLenum pname, void **params) const
1779{
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001780 mGLState.getPointerv(this, pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001781}
1782
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001783void Context::getPointervRobustANGLERobust(GLenum pname,
1784 GLsizei bufSize,
1785 GLsizei *length,
1786 void **params)
1787{
1788 UNIMPLEMENTED();
1789}
1790
Martin Radev66fb8202016-07-28 11:45:20 +03001791void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001792{
Shannon Woods53a94a82014-06-24 15:20:36 -04001793 // Queries about context capabilities and maximums are answered by Context.
1794 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001795
1796 GLenum nativeType;
1797 unsigned int numParams;
1798 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1799 ASSERT(queryStatus);
1800
1801 if (nativeType == GL_INT)
1802 {
1803 switch (target)
1804 {
1805 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1806 ASSERT(index < 3u);
1807 *data = mCaps.maxComputeWorkGroupCount[index];
1808 break;
1809 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1810 ASSERT(index < 3u);
1811 *data = mCaps.maxComputeWorkGroupSize[index];
1812 break;
1813 default:
1814 mGLState.getIntegeri_v(target, index, data);
1815 }
1816 }
1817 else
1818 {
1819 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1820 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001821}
1822
Brandon Jones59770802018-04-02 13:18:42 -07001823void Context::getIntegeri_vRobust(GLenum target,
1824 GLuint index,
1825 GLsizei bufSize,
1826 GLsizei *length,
1827 GLint *data)
1828{
1829 getIntegeri_v(target, index, data);
1830}
1831
Martin Radev66fb8202016-07-28 11:45:20 +03001832void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001833{
Shannon Woods53a94a82014-06-24 15:20:36 -04001834 // Queries about context capabilities and maximums are answered by Context.
1835 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001836
1837 GLenum nativeType;
1838 unsigned int numParams;
1839 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1840 ASSERT(queryStatus);
1841
1842 if (nativeType == GL_INT_64_ANGLEX)
1843 {
1844 mGLState.getInteger64i_v(target, index, data);
1845 }
1846 else
1847 {
1848 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1849 }
1850}
1851
Brandon Jones59770802018-04-02 13:18:42 -07001852void Context::getInteger64i_vRobust(GLenum target,
1853 GLuint index,
1854 GLsizei bufSize,
1855 GLsizei *length,
1856 GLint64 *data)
1857{
1858 getInteger64i_v(target, index, data);
1859}
1860
Martin Radev66fb8202016-07-28 11:45:20 +03001861void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1862{
1863 // Queries about context capabilities and maximums are answered by Context.
1864 // Queries about current GL state values are answered by State.
1865
1866 GLenum nativeType;
1867 unsigned int numParams;
1868 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1869 ASSERT(queryStatus);
1870
1871 if (nativeType == GL_BOOL)
1872 {
1873 mGLState.getBooleani_v(target, index, data);
1874 }
1875 else
1876 {
1877 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1878 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001879}
1880
Brandon Jones59770802018-04-02 13:18:42 -07001881void Context::getBooleani_vRobust(GLenum target,
1882 GLuint index,
1883 GLsizei bufSize,
1884 GLsizei *length,
1885 GLboolean *data)
1886{
1887 getBooleani_v(target, index, data);
1888}
1889
Corentin Wallez336129f2017-10-17 15:55:40 -04001890void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001891{
1892 Buffer *buffer = mGLState.getTargetBuffer(target);
1893 QueryBufferParameteriv(buffer, pname, params);
1894}
1895
Brandon Jones59770802018-04-02 13:18:42 -07001896void Context::getBufferParameterivRobust(BufferBinding target,
1897 GLenum pname,
1898 GLsizei bufSize,
1899 GLsizei *length,
1900 GLint *params)
1901{
1902 getBufferParameteriv(target, pname, params);
1903}
1904
He Yunchao010e4db2017-03-03 14:22:06 +08001905void Context::getFramebufferAttachmentParameteriv(GLenum target,
1906 GLenum attachment,
1907 GLenum pname,
1908 GLint *params)
1909{
1910 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08001911 QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08001912}
1913
Brandon Jones59770802018-04-02 13:18:42 -07001914void Context::getFramebufferAttachmentParameterivRobust(GLenum target,
1915 GLenum attachment,
1916 GLenum pname,
1917 GLsizei bufSize,
1918 GLsizei *length,
1919 GLint *params)
1920{
1921 getFramebufferAttachmentParameteriv(target, attachment, pname, params);
1922}
1923
He Yunchao010e4db2017-03-03 14:22:06 +08001924void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
1925{
1926 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
1927 QueryRenderbufferiv(this, renderbuffer, pname, params);
1928}
1929
Brandon Jones59770802018-04-02 13:18:42 -07001930void Context::getRenderbufferParameterivRobust(GLenum target,
1931 GLenum pname,
1932 GLsizei bufSize,
1933 GLsizei *length,
1934 GLint *params)
1935{
1936 getRenderbufferParameteriv(target, pname, params);
1937}
1938
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001939void Context::getTexParameterfv(TextureType target, GLenum pname, GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001940{
1941 Texture *texture = getTargetTexture(target);
1942 QueryTexParameterfv(texture, pname, params);
1943}
1944
Brandon Jones59770802018-04-02 13:18:42 -07001945void Context::getTexParameterfvRobust(TextureType target,
1946 GLenum pname,
1947 GLsizei bufSize,
1948 GLsizei *length,
1949 GLfloat *params)
1950{
1951 getTexParameterfv(target, pname, params);
1952}
1953
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001954void Context::getTexParameteriv(TextureType target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001955{
1956 Texture *texture = getTargetTexture(target);
1957 QueryTexParameteriv(texture, pname, params);
1958}
Jiajia Qin5451d532017-11-16 17:16:34 +08001959
Brandon Jones59770802018-04-02 13:18:42 -07001960void Context::getTexParameterivRobust(TextureType target,
1961 GLenum pname,
1962 GLsizei bufSize,
1963 GLsizei *length,
1964 GLint *params)
1965{
1966 getTexParameteriv(target, pname, params);
1967}
1968
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001969void Context::getTexParameterIivRobust(TextureType target,
1970 GLenum pname,
1971 GLsizei bufSize,
1972 GLsizei *length,
1973 GLint *params)
1974{
1975 UNIMPLEMENTED();
1976}
1977
1978void Context::getTexParameterIuivRobust(TextureType target,
1979 GLenum pname,
1980 GLsizei bufSize,
1981 GLsizei *length,
1982 GLuint *params)
1983{
1984 UNIMPLEMENTED();
1985}
1986
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001987void Context::getTexLevelParameteriv(TextureTarget target, GLint level, GLenum pname, GLint *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08001988{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001989 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05001990 QueryTexLevelParameteriv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08001991}
1992
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001993void Context::getTexLevelParameterivRobust(TextureTarget target,
1994 GLint level,
1995 GLenum pname,
1996 GLsizei bufSize,
1997 GLsizei *length,
1998 GLint *params)
1999{
2000 UNIMPLEMENTED();
2001}
2002
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002003void Context::getTexLevelParameterfv(TextureTarget target,
2004 GLint level,
2005 GLenum pname,
2006 GLfloat *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002007{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002008 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002009 QueryTexLevelParameterfv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002010}
2011
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002012void Context::getTexLevelParameterfvRobust(TextureTarget target,
2013 GLint level,
2014 GLenum pname,
2015 GLsizei bufSize,
2016 GLsizei *length,
2017 GLfloat *params)
2018{
2019 UNIMPLEMENTED();
2020}
2021
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002022void Context::texParameterf(TextureType target, GLenum pname, GLfloat param)
He Yunchao010e4db2017-03-03 14:22:06 +08002023{
2024 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002025 SetTexParameterf(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002026 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002027}
2028
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002029void Context::texParameterfv(TextureType target, GLenum pname, const GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002030{
2031 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002032 SetTexParameterfv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002033 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002034}
2035
Brandon Jones59770802018-04-02 13:18:42 -07002036void Context::texParameterfvRobust(TextureType target,
2037 GLenum pname,
2038 GLsizei bufSize,
2039 const GLfloat *params)
2040{
2041 texParameterfv(target, pname, params);
2042}
2043
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002044void Context::texParameteri(TextureType target, GLenum pname, GLint param)
He Yunchao010e4db2017-03-03 14:22:06 +08002045{
2046 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002047 SetTexParameteri(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002048 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002049}
2050
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002051void Context::texParameteriv(TextureType target, GLenum pname, const GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002052{
2053 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002054 SetTexParameteriv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002055 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002056}
2057
Brandon Jones59770802018-04-02 13:18:42 -07002058void Context::texParameterivRobust(TextureType target,
2059 GLenum pname,
2060 GLsizei bufSize,
2061 const GLint *params)
2062{
2063 texParameteriv(target, pname, params);
2064}
2065
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002066void Context::texParameterIivRobust(TextureType target,
2067 GLenum pname,
2068 GLsizei bufSize,
2069 const GLint *params)
2070{
2071 UNIMPLEMENTED();
2072}
2073
2074void Context::texParameterIuivRobust(TextureType target,
2075 GLenum pname,
2076 GLsizei bufSize,
2077 const GLuint *params)
2078{
2079 UNIMPLEMENTED();
2080}
2081
Jamie Madill493f9572018-05-24 19:52:15 -04002082void Context::drawArrays(PrimitiveMode mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002083{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002084 // No-op if zero count
2085 if (count == 0)
2086 {
2087 return;
2088 }
2089
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002090 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002091 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
Jamie Madill09463932018-04-04 05:26:59 -04002092 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count, 1);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002093}
2094
Jamie Madill493f9572018-05-24 19:52:15 -04002095void Context::drawArraysInstanced(PrimitiveMode mode,
2096 GLint first,
2097 GLsizei count,
2098 GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04002099{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002100 // No-op if zero count
2101 if (count == 0 || instanceCount == 0)
2102 {
2103 return;
2104 }
2105
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002106 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002107 ANGLE_CONTEXT_TRY(
2108 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
Jamie Madill09463932018-04-04 05:26:59 -04002109 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count,
2110 instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -04002111}
2112
Jamie Madill493f9572018-05-24 19:52:15 -04002113void Context::drawElements(PrimitiveMode mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002114{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002115 // No-op if zero count
2116 if (count == 0)
2117 {
2118 return;
2119 }
2120
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002121 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002122 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04002123}
2124
Jamie Madill493f9572018-05-24 19:52:15 -04002125void Context::drawElementsInstanced(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002126 GLsizei count,
2127 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002128 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04002129 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04002130{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002131 // No-op if zero count
2132 if (count == 0 || instances == 0)
2133 {
2134 return;
2135 }
2136
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002137 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002138 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08002139 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04002140}
2141
Jamie Madill493f9572018-05-24 19:52:15 -04002142void Context::drawRangeElements(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002143 GLuint start,
2144 GLuint end,
2145 GLsizei count,
2146 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002147 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04002148{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002149 // No-op if zero count
2150 if (count == 0)
2151 {
2152 return;
2153 }
2154
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002155 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002156 ANGLE_CONTEXT_TRY(
2157 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002158}
2159
Jamie Madill493f9572018-05-24 19:52:15 -04002160void Context::drawArraysIndirect(PrimitiveMode mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002161{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002162 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002163 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002164}
2165
Jamie Madill493f9572018-05-24 19:52:15 -04002166void Context::drawElementsIndirect(PrimitiveMode mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002167{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002168 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002169 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002170}
2171
Jamie Madill675fe712016-12-19 13:07:54 -05002172void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002173{
Jamie Madillafa02a22017-11-23 12:57:38 -05002174 handleError(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05002175}
2176
Jamie Madill675fe712016-12-19 13:07:54 -05002177void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05002178{
Jamie Madillafa02a22017-11-23 12:57:38 -05002179 handleError(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002180}
2181
Austin Kinross6ee1e782015-05-29 17:05:37 -07002182void Context::insertEventMarker(GLsizei length, const char *marker)
2183{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002184 ASSERT(mImplementation);
2185 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07002186}
2187
2188void Context::pushGroupMarker(GLsizei length, const char *marker)
2189{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002190 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05002191
2192 if (marker == nullptr)
2193 {
2194 // From the EXT_debug_marker spec,
2195 // "If <marker> is null then an empty string is pushed on the stack."
2196 mImplementation->pushGroupMarker(length, "");
2197 }
2198 else
2199 {
2200 mImplementation->pushGroupMarker(length, marker);
2201 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07002202}
2203
2204void Context::popGroupMarker()
2205{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002206 ASSERT(mImplementation);
2207 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07002208}
2209
Geoff Langd8605522016-04-13 10:19:12 -04002210void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
2211{
2212 Program *programObject = getProgram(program);
2213 ASSERT(programObject);
2214
2215 programObject->bindUniformLocation(location, name);
2216}
2217
Brandon Jones59770802018-04-02 13:18:42 -07002218void Context::coverageModulation(GLenum components)
Sami Väisänena797e062016-05-12 15:23:40 +03002219{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002220 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03002221}
2222
Brandon Jones59770802018-04-02 13:18:42 -07002223void Context::matrixLoadf(GLenum matrixMode, const GLfloat *matrix)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002224{
2225 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
2226}
2227
Brandon Jones59770802018-04-02 13:18:42 -07002228void Context::matrixLoadIdentity(GLenum matrixMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002229{
2230 GLfloat I[16];
2231 angle::Matrix<GLfloat>::setToIdentity(I);
2232
2233 mGLState.loadPathRenderingMatrix(matrixMode, I);
2234}
2235
2236void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
2237{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002238 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002239 if (!pathObj)
2240 return;
2241
2242 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002243 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002244
2245 mImplementation->stencilFillPath(pathObj, fillMode, mask);
2246}
2247
2248void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
2249{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002250 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002251 if (!pathObj)
2252 return;
2253
2254 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002255 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002256
2257 mImplementation->stencilStrokePath(pathObj, reference, mask);
2258}
2259
2260void Context::coverFillPath(GLuint path, GLenum coverMode)
2261{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002262 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002263 if (!pathObj)
2264 return;
2265
2266 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002267 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002268
2269 mImplementation->coverFillPath(pathObj, coverMode);
2270}
2271
2272void Context::coverStrokePath(GLuint path, GLenum coverMode)
2273{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002274 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002275 if (!pathObj)
2276 return;
2277
2278 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002279 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002280
2281 mImplementation->coverStrokePath(pathObj, coverMode);
2282}
2283
2284void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
2285{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002286 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002287 if (!pathObj)
2288 return;
2289
2290 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002291 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002292
2293 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
2294}
2295
2296void Context::stencilThenCoverStrokePath(GLuint path,
2297 GLint reference,
2298 GLuint mask,
2299 GLenum coverMode)
2300{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002301 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002302 if (!pathObj)
2303 return;
2304
2305 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002306 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002307
2308 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2309}
2310
Sami Väisänend59ca052016-06-21 16:10:00 +03002311void Context::coverFillPathInstanced(GLsizei numPaths,
2312 GLenum pathNameType,
2313 const void *paths,
2314 GLuint pathBase,
2315 GLenum coverMode,
2316 GLenum transformType,
2317 const GLfloat *transformValues)
2318{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002319 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002320
2321 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002322 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002323
2324 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2325}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002326
Sami Väisänend59ca052016-06-21 16:10:00 +03002327void Context::coverStrokePathInstanced(GLsizei numPaths,
2328 GLenum pathNameType,
2329 const void *paths,
2330 GLuint pathBase,
2331 GLenum coverMode,
2332 GLenum transformType,
2333 const GLfloat *transformValues)
2334{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002335 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002336
2337 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002338 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002339
2340 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2341 transformValues);
2342}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002343
Sami Väisänend59ca052016-06-21 16:10:00 +03002344void Context::stencilFillPathInstanced(GLsizei numPaths,
2345 GLenum pathNameType,
2346 const void *paths,
2347 GLuint pathBase,
2348 GLenum fillMode,
2349 GLuint mask,
2350 GLenum transformType,
2351 const GLfloat *transformValues)
2352{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002353 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002354
2355 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002356 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002357
2358 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2359 transformValues);
2360}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002361
Sami Väisänend59ca052016-06-21 16:10:00 +03002362void Context::stencilStrokePathInstanced(GLsizei numPaths,
2363 GLenum pathNameType,
2364 const void *paths,
2365 GLuint pathBase,
2366 GLint reference,
2367 GLuint mask,
2368 GLenum transformType,
2369 const GLfloat *transformValues)
2370{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002371 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002372
2373 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002374 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002375
2376 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2377 transformValues);
2378}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002379
Sami Väisänend59ca052016-06-21 16:10:00 +03002380void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2381 GLenum pathNameType,
2382 const void *paths,
2383 GLuint pathBase,
2384 GLenum fillMode,
2385 GLuint mask,
2386 GLenum coverMode,
2387 GLenum transformType,
2388 const GLfloat *transformValues)
2389{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002390 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002391
2392 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002393 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002394
2395 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2396 transformType, transformValues);
2397}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002398
Sami Väisänend59ca052016-06-21 16:10:00 +03002399void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2400 GLenum pathNameType,
2401 const void *paths,
2402 GLuint pathBase,
2403 GLint reference,
2404 GLuint mask,
2405 GLenum coverMode,
2406 GLenum transformType,
2407 const GLfloat *transformValues)
2408{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002409 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002410
2411 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002412 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002413
2414 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2415 transformType, transformValues);
2416}
2417
Sami Väisänen46eaa942016-06-29 10:26:37 +03002418void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2419{
2420 auto *programObject = getProgram(program);
2421
2422 programObject->bindFragmentInputLocation(location, name);
2423}
2424
2425void Context::programPathFragmentInputGen(GLuint program,
2426 GLint location,
2427 GLenum genMode,
2428 GLint components,
2429 const GLfloat *coeffs)
2430{
2431 auto *programObject = getProgram(program);
2432
Jamie Madillbd044ed2017-06-05 12:59:21 -04002433 programObject->pathFragmentInputGen(this, location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002434}
2435
jchen1015015f72017-03-16 13:54:21 +08002436GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2437{
jchen10fd7c3b52017-03-21 15:36:03 +08002438 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002439 return QueryProgramResourceIndex(programObject, programInterface, name);
2440}
2441
jchen10fd7c3b52017-03-21 15:36:03 +08002442void Context::getProgramResourceName(GLuint program,
2443 GLenum programInterface,
2444 GLuint index,
2445 GLsizei bufSize,
2446 GLsizei *length,
2447 GLchar *name)
2448{
2449 const auto *programObject = getProgram(program);
2450 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2451}
2452
jchen10191381f2017-04-11 13:59:04 +08002453GLint Context::getProgramResourceLocation(GLuint program,
2454 GLenum programInterface,
2455 const GLchar *name)
2456{
2457 const auto *programObject = getProgram(program);
2458 return QueryProgramResourceLocation(programObject, programInterface, name);
2459}
2460
jchen10880683b2017-04-12 16:21:55 +08002461void Context::getProgramResourceiv(GLuint program,
2462 GLenum programInterface,
2463 GLuint index,
2464 GLsizei propCount,
2465 const GLenum *props,
2466 GLsizei bufSize,
2467 GLsizei *length,
2468 GLint *params)
2469{
2470 const auto *programObject = getProgram(program);
2471 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2472 length, params);
2473}
2474
jchen10d9cd7b72017-08-30 15:04:25 +08002475void Context::getProgramInterfaceiv(GLuint program,
2476 GLenum programInterface,
2477 GLenum pname,
2478 GLint *params)
2479{
2480 const auto *programObject = getProgram(program);
2481 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2482}
2483
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002484void Context::getProgramInterfaceivRobust(GLuint program,
2485 GLenum programInterface,
2486 GLenum pname,
2487 GLsizei bufSize,
2488 GLsizei *length,
2489 GLint *params)
2490{
2491 UNIMPLEMENTED();
2492}
2493
Jamie Madill427064d2018-04-13 16:20:34 -04002494void Context::handleError(const Error &error) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002495{
Geoff Lang7b19a492018-04-20 09:31:52 -04002496 if (ANGLE_UNLIKELY(error.isError()))
Geoff Langda5777c2014-07-11 09:52:58 -04002497 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002498 GLenum code = error.getCode();
2499 mErrors.insert(code);
2500 if (code == GL_OUT_OF_MEMORY && getWorkarounds().loseContextOnOutOfMemory)
2501 {
2502 markContextLost();
2503 }
Geoff Lang70d0f492015-12-10 17:45:46 -05002504
Geoff Langee6884e2017-11-09 16:51:11 -05002505 ASSERT(!error.getMessage().empty());
2506 mGLState.getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, error.getID(),
2507 GL_DEBUG_SEVERITY_HIGH, error.getMessage());
Geoff Langda5777c2014-07-11 09:52:58 -04002508 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002509}
2510
2511// Get one of the recorded errors and clear its flag, if any.
2512// [OpenGL ES 2.0.24] section 2.5 page 13.
2513GLenum Context::getError()
2514{
Geoff Langda5777c2014-07-11 09:52:58 -04002515 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002516 {
Geoff Langda5777c2014-07-11 09:52:58 -04002517 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002518 }
Geoff Langda5777c2014-07-11 09:52:58 -04002519 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002520 {
Geoff Langda5777c2014-07-11 09:52:58 -04002521 GLenum error = *mErrors.begin();
2522 mErrors.erase(mErrors.begin());
2523 return error;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002524 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002525}
2526
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002527// NOTE: this function should not assume that this context is current!
Jamie Madill427064d2018-04-13 16:20:34 -04002528void Context::markContextLost() const
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002529{
2530 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002531 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002532 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002533 mContextLostForced = true;
2534 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002535 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002536}
2537
Jamie Madill427064d2018-04-13 16:20:34 -04002538bool Context::isContextLost() const
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002539{
2540 return mContextLost;
2541}
2542
Jamie Madillfa920eb2018-01-04 11:45:50 -05002543GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002544{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002545 // Even if the application doesn't want to know about resets, we want to know
2546 // as it will allow us to skip all the calls.
2547 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002548 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002549 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002550 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002551 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002552 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002553
2554 // EXT_robustness, section 2.6: If the reset notification behavior is
2555 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2556 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2557 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002558 }
2559
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002560 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2561 // status should be returned at least once, and GL_NO_ERROR should be returned
2562 // once the device has finished resetting.
2563 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002564 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002565 ASSERT(mResetStatus == GL_NO_ERROR);
2566 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002567
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002568 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002569 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002570 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002571 }
2572 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002573 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002574 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002575 // If markContextLost was used to mark the context lost then
2576 // assume that is not recoverable, and continue to report the
2577 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002578 mResetStatus = mImplementation->getResetStatus();
2579 }
Jamie Madill893ab082014-05-16 16:56:10 -04002580
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002581 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002582}
2583
2584bool Context::isResetNotificationEnabled()
2585{
2586 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2587}
2588
Corentin Walleze3b10e82015-05-20 11:06:25 -04002589const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002590{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002591 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002592}
2593
2594EGLenum Context::getClientType() const
2595{
2596 return mClientType;
2597}
2598
2599EGLenum Context::getRenderBuffer() const
2600{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002601 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2602 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002603 {
2604 return EGL_NONE;
2605 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002606
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002607 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002608 ASSERT(backAttachment != nullptr);
2609 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002610}
2611
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002612VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002613{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002614 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002615 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2616 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002617 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002618 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2619 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002620
Jamie Madill96a483b2017-06-27 16:49:21 -04002621 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002622 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002623
2624 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002625}
2626
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002627TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002628{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002629 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002630 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2631 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002632 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002633 transformFeedback =
2634 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002635 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002636 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002637 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002638
2639 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002640}
2641
2642bool Context::isVertexArrayGenerated(GLuint vertexArray)
2643{
Jamie Madill96a483b2017-06-27 16:49:21 -04002644 ASSERT(mVertexArrayMap.contains(0));
2645 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002646}
2647
2648bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2649{
Jamie Madill96a483b2017-06-27 16:49:21 -04002650 ASSERT(mTransformFeedbackMap.contains(0));
2651 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002652}
2653
Shannon Woods53a94a82014-06-24 15:20:36 -04002654void Context::detachTexture(GLuint texture)
2655{
2656 // Simple pass-through to State's detachTexture method, as textures do not require
2657 // allocation map management either here or in the resource manager at detach time.
2658 // Zero textures are held by the Context, and we don't attempt to request them from
2659 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002660 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002661}
2662
James Darpinian4d9d4832018-03-13 12:43:28 -07002663void Context::detachBuffer(Buffer *buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002664{
Yuly Novikov5807a532015-12-03 13:01:22 -05002665 // Simple pass-through to State's detachBuffer method, since
2666 // only buffer attachments to container objects that are bound to the current context
2667 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002668
Yuly Novikov5807a532015-12-03 13:01:22 -05002669 // [OpenGL ES 3.2] section 5.1.2 page 45:
2670 // Attachments to unbound container objects, such as
2671 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2672 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002673 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002674}
2675
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002676void Context::detachFramebuffer(GLuint framebuffer)
2677{
Shannon Woods53a94a82014-06-24 15:20:36 -04002678 // Framebuffer detachment is handled by Context, because 0 is a valid
2679 // Framebuffer object, and a pointer to it must be passed from Context
2680 // to State at binding time.
2681
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002682 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002683 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2684 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2685 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002686
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002687 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002688 {
2689 bindReadFramebuffer(0);
2690 }
2691
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002692 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002693 {
2694 bindDrawFramebuffer(0);
2695 }
2696}
2697
2698void Context::detachRenderbuffer(GLuint renderbuffer)
2699{
Jamie Madilla02315b2017-02-23 14:14:47 -05002700 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002701}
2702
Jamie Madill57a89722013-07-02 11:57:03 -04002703void Context::detachVertexArray(GLuint vertexArray)
2704{
Jamie Madill77a72f62015-04-14 11:18:32 -04002705 // Vertex array detachment is handled by Context, because 0 is a valid
2706 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002707 // binding time.
2708
Jamie Madill57a89722013-07-02 11:57:03 -04002709 // [OpenGL ES 3.0.2] section 2.10 page 43:
2710 // If a vertex array object that is currently bound is deleted, the binding
2711 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madill7267aa62018-04-17 15:28:21 -04002712 if (mGLState.removeVertexArrayBinding(this, vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002713 {
2714 bindVertexArray(0);
2715 }
2716}
2717
Geoff Langc8058452014-02-03 12:04:11 -05002718void Context::detachTransformFeedback(GLuint transformFeedback)
2719{
Corentin Walleza2257da2016-04-19 16:43:12 -04002720 // Transform feedback detachment is handled by Context, because 0 is a valid
2721 // transform feedback, and a pointer to it must be passed from Context to State at
2722 // binding time.
2723
2724 // The OpenGL specification doesn't mention what should happen when the currently bound
2725 // transform feedback object is deleted. Since it is a container object, we treat it like
2726 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002727 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002728 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002729 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002730 }
Geoff Langc8058452014-02-03 12:04:11 -05002731}
2732
Jamie Madilldc356042013-07-19 16:36:57 -04002733void Context::detachSampler(GLuint sampler)
2734{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002735 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002736}
2737
Yunchao Hea336b902017-08-02 16:05:21 +08002738void Context::detachProgramPipeline(GLuint pipeline)
2739{
2740 mGLState.detachProgramPipeline(this, pipeline);
2741}
2742
Jamie Madill3ef140a2017-08-26 23:11:21 -04002743void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002744{
Shaodde78e82017-05-22 14:13:27 +08002745 mGLState.setVertexAttribDivisor(this, index, divisor);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002746}
2747
Jamie Madille29d1672013-07-19 16:36:57 -04002748void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2749{
Geoff Langc1984ed2016-10-07 12:41:00 -04002750 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002751 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002752 SetSamplerParameteri(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002753 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002754}
Jamie Madille29d1672013-07-19 16:36:57 -04002755
Geoff Langc1984ed2016-10-07 12:41:00 -04002756void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2757{
2758 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002759 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002760 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002761 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002762}
2763
Brandon Jones59770802018-04-02 13:18:42 -07002764void Context::samplerParameterivRobust(GLuint sampler,
2765 GLenum pname,
2766 GLsizei bufSize,
2767 const GLint *param)
2768{
2769 samplerParameteriv(sampler, pname, param);
2770}
2771
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002772void Context::samplerParameterIivRobust(GLuint sampler,
2773 GLenum pname,
2774 GLsizei bufSize,
2775 const GLint *param)
2776{
2777 UNIMPLEMENTED();
2778}
2779
2780void Context::samplerParameterIuivRobust(GLuint sampler,
2781 GLenum pname,
2782 GLsizei bufSize,
2783 const GLuint *param)
2784{
2785 UNIMPLEMENTED();
2786}
2787
Jamie Madille29d1672013-07-19 16:36:57 -04002788void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2789{
Geoff Langc1984ed2016-10-07 12:41:00 -04002790 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002791 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002792 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002793 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002794}
2795
Geoff Langc1984ed2016-10-07 12:41:00 -04002796void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002797{
Geoff Langc1984ed2016-10-07 12:41:00 -04002798 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002799 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002800 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002801 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002802}
2803
Brandon Jones59770802018-04-02 13:18:42 -07002804void Context::samplerParameterfvRobust(GLuint sampler,
2805 GLenum pname,
2806 GLsizei bufSize,
2807 const GLfloat *param)
2808{
2809 samplerParameterfv(sampler, pname, param);
2810}
2811
Geoff Langc1984ed2016-10-07 12:41:00 -04002812void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002813{
Geoff Langc1984ed2016-10-07 12:41:00 -04002814 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002815 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002816 QuerySamplerParameteriv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002817 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002818}
Jamie Madill9675b802013-07-19 16:36:59 -04002819
Brandon Jones59770802018-04-02 13:18:42 -07002820void Context::getSamplerParameterivRobust(GLuint sampler,
2821 GLenum pname,
2822 GLsizei bufSize,
2823 GLsizei *length,
2824 GLint *params)
2825{
2826 getSamplerParameteriv(sampler, pname, params);
2827}
2828
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002829void Context::getSamplerParameterIivRobust(GLuint sampler,
2830 GLenum pname,
2831 GLsizei bufSize,
2832 GLsizei *length,
2833 GLint *params)
2834{
2835 UNIMPLEMENTED();
2836}
2837
2838void Context::getSamplerParameterIuivRobust(GLuint sampler,
2839 GLenum pname,
2840 GLsizei bufSize,
2841 GLsizei *length,
2842 GLuint *params)
2843{
2844 UNIMPLEMENTED();
2845}
2846
Geoff Langc1984ed2016-10-07 12:41:00 -04002847void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2848{
2849 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002850 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002851 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002852 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002853}
2854
Brandon Jones59770802018-04-02 13:18:42 -07002855void Context::getSamplerParameterfvRobust(GLuint sampler,
2856 GLenum pname,
2857 GLsizei bufSize,
2858 GLsizei *length,
2859 GLfloat *params)
2860{
2861 getSamplerParameterfv(sampler, pname, params);
2862}
2863
Olli Etuahof0fee072016-03-30 15:11:58 +03002864void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2865{
2866 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002867 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002868}
2869
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002870void Context::initRendererString()
2871{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002872 std::ostringstream rendererString;
2873 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002874 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002875 rendererString << ")";
2876
Geoff Langcec35902014-04-16 10:52:36 -04002877 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002878}
2879
Geoff Langc339c4e2016-11-29 10:37:36 -05002880void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002881{
Geoff Langc339c4e2016-11-29 10:37:36 -05002882 const Version &clientVersion = getClientVersion();
2883
2884 std::ostringstream versionString;
2885 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2886 << ANGLE_VERSION_STRING << ")";
2887 mVersionString = MakeStaticString(versionString.str());
2888
2889 std::ostringstream shadingLanguageVersionString;
2890 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2891 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2892 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2893 << ")";
2894 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002895}
2896
Geoff Langcec35902014-04-16 10:52:36 -04002897void Context::initExtensionStrings()
2898{
Geoff Langc339c4e2016-11-29 10:37:36 -05002899 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2900 std::ostringstream combinedStringStream;
2901 std::copy(strings.begin(), strings.end(),
2902 std::ostream_iterator<const char *>(combinedStringStream, " "));
2903 return MakeStaticString(combinedStringStream.str());
2904 };
2905
2906 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002907 for (const auto &extensionString : mExtensions.getStrings())
2908 {
2909 mExtensionStrings.push_back(MakeStaticString(extensionString));
2910 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002911 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002912
Geoff Langc339c4e2016-11-29 10:37:36 -05002913 mRequestableExtensionStrings.clear();
2914 for (const auto &extensionInfo : GetExtensionInfoMap())
2915 {
2916 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08002917 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
Geoff Langb0f917f2017-12-05 13:41:54 -05002918 mSupportedExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002919 {
2920 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
2921 }
2922 }
2923 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002924}
2925
Geoff Langc339c4e2016-11-29 10:37:36 -05002926const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04002927{
Geoff Langc339c4e2016-11-29 10:37:36 -05002928 switch (name)
2929 {
2930 case GL_VENDOR:
2931 return reinterpret_cast<const GLubyte *>("Google Inc.");
2932
2933 case GL_RENDERER:
2934 return reinterpret_cast<const GLubyte *>(mRendererString);
2935
2936 case GL_VERSION:
2937 return reinterpret_cast<const GLubyte *>(mVersionString);
2938
2939 case GL_SHADING_LANGUAGE_VERSION:
2940 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
2941
2942 case GL_EXTENSIONS:
2943 return reinterpret_cast<const GLubyte *>(mExtensionString);
2944
2945 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2946 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
2947
2948 default:
2949 UNREACHABLE();
2950 return nullptr;
2951 }
Geoff Langcec35902014-04-16 10:52:36 -04002952}
2953
Geoff Langc339c4e2016-11-29 10:37:36 -05002954const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04002955{
Geoff Langc339c4e2016-11-29 10:37:36 -05002956 switch (name)
2957 {
2958 case GL_EXTENSIONS:
2959 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
2960
2961 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2962 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
2963
2964 default:
2965 UNREACHABLE();
2966 return nullptr;
2967 }
Geoff Langcec35902014-04-16 10:52:36 -04002968}
2969
2970size_t Context::getExtensionStringCount() const
2971{
2972 return mExtensionStrings.size();
2973}
2974
Geoff Lang111a99e2017-10-17 10:58:41 -04002975bool Context::isExtensionRequestable(const char *name)
2976{
2977 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2978 auto extension = extensionInfos.find(name);
2979
Geoff Lang111a99e2017-10-17 10:58:41 -04002980 return extension != extensionInfos.end() && extension->second.Requestable &&
Geoff Langb0f917f2017-12-05 13:41:54 -05002981 mSupportedExtensions.*(extension->second.ExtensionsMember);
Geoff Lang111a99e2017-10-17 10:58:41 -04002982}
2983
Geoff Langc339c4e2016-11-29 10:37:36 -05002984void Context::requestExtension(const char *name)
2985{
2986 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2987 ASSERT(extensionInfos.find(name) != extensionInfos.end());
2988 const auto &extension = extensionInfos.at(name);
2989 ASSERT(extension.Requestable);
Geoff Langb0f917f2017-12-05 13:41:54 -05002990 ASSERT(isExtensionRequestable(name));
Geoff Langc339c4e2016-11-29 10:37:36 -05002991
2992 if (mExtensions.*(extension.ExtensionsMember))
2993 {
2994 // Extension already enabled
2995 return;
2996 }
2997
2998 mExtensions.*(extension.ExtensionsMember) = true;
2999 updateCaps();
3000 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08003001
Jamie Madill2f348d22017-06-05 10:50:59 -04003002 // Release the shader compiler so it will be re-created with the requested extensions enabled.
3003 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04003004
Jamie Madill81c2e252017-09-09 23:32:46 -04003005 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
3006 // sampleable.
Jamie Madilld4442552018-02-27 22:03:47 -05003007 mState.mTextures->signalAllTexturesDirty(this);
Geoff Lang9aded172017-04-05 11:07:56 -04003008 for (auto &zeroTexture : mZeroTextures)
3009 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003010 if (zeroTexture.get() != nullptr)
3011 {
3012 zeroTexture->signalDirty(this, InitState::Initialized);
3013 }
Geoff Lang9aded172017-04-05 11:07:56 -04003014 }
3015
3016 mState.mFramebuffers->invalidateFramebufferComplenessCache();
Geoff Langc339c4e2016-11-29 10:37:36 -05003017}
3018
3019size_t Context::getRequestableExtensionStringCount() const
3020{
3021 return mRequestableExtensionStrings.size();
3022}
3023
Jamie Madill493f9572018-05-24 19:52:15 -04003024void Context::beginTransformFeedback(PrimitiveMode primitiveMode)
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003025{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003026 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003027 ASSERT(transformFeedback != nullptr);
3028 ASSERT(!transformFeedback->isPaused());
3029
Jamie Madill6c1f6712017-02-14 19:08:04 -05003030 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003031}
3032
3033bool Context::hasActiveTransformFeedback(GLuint program) const
3034{
3035 for (auto pair : mTransformFeedbackMap)
3036 {
3037 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
3038 {
3039 return true;
3040 }
3041 }
3042 return false;
3043}
3044
Geoff Lang33f11fb2018-05-07 13:42:47 -04003045Extensions Context::generateSupportedExtensions() const
Geoff Langb0f917f2017-12-05 13:41:54 -05003046{
3047 Extensions supportedExtensions = mImplementation->getNativeExtensions();
3048
3049 if (getClientVersion() < ES_2_0)
3050 {
3051 // Default extensions for GLES1
3052 supportedExtensions.pointSizeArray = true;
Lingfeng Yang23dc90b2018-04-23 09:01:49 -07003053 supportedExtensions.textureCubeMap = true;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003054 supportedExtensions.pointSprite = true;
Geoff Langb0f917f2017-12-05 13:41:54 -05003055 }
3056
3057 if (getClientVersion() < ES_3_0)
3058 {
3059 // Disable ES3+ extensions
3060 supportedExtensions.colorBufferFloat = false;
3061 supportedExtensions.eglImageExternalEssl3 = false;
3062 supportedExtensions.textureNorm16 = false;
3063 supportedExtensions.multiview = false;
3064 supportedExtensions.maxViews = 1u;
3065 }
3066
3067 if (getClientVersion() < ES_3_1)
3068 {
3069 // Disable ES3.1+ extensions
3070 supportedExtensions.geometryShader = false;
3071 }
3072
3073 if (getClientVersion() > ES_2_0)
3074 {
3075 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
3076 // supportedExtensions.sRGB = false;
3077 }
3078
3079 // Some extensions are always available because they are implemented in the GL layer.
3080 supportedExtensions.bindUniformLocation = true;
3081 supportedExtensions.vertexArrayObject = true;
3082 supportedExtensions.bindGeneratesResource = true;
3083 supportedExtensions.clientArrays = true;
3084 supportedExtensions.requestExtension = true;
3085
3086 // Enable the no error extension if the context was created with the flag.
3087 supportedExtensions.noError = mSkipValidation;
3088
3089 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Geoff Lang33f11fb2018-05-07 13:42:47 -04003090 supportedExtensions.surfacelessContext = mSurfacelessSupported;
Geoff Langb0f917f2017-12-05 13:41:54 -05003091
3092 // Explicitly enable GL_KHR_debug
3093 supportedExtensions.debug = true;
3094 supportedExtensions.maxDebugMessageLength = 1024;
3095 supportedExtensions.maxDebugLoggedMessages = 1024;
3096 supportedExtensions.maxDebugGroupStackDepth = 1024;
3097 supportedExtensions.maxLabelLength = 1024;
3098
3099 // Explicitly enable GL_ANGLE_robust_client_memory
3100 supportedExtensions.robustClientMemory = true;
3101
3102 // Determine robust resource init availability from EGL.
Geoff Lang33f11fb2018-05-07 13:42:47 -04003103 supportedExtensions.robustResourceInitialization = mGLState.isRobustResourceInitEnabled();
Geoff Langb0f917f2017-12-05 13:41:54 -05003104
3105 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
3106 // supports it.
3107 supportedExtensions.robustBufferAccessBehavior =
3108 mRobustAccess && supportedExtensions.robustBufferAccessBehavior;
3109
3110 // Enable the cache control query unconditionally.
3111 supportedExtensions.programCacheControl = true;
3112
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003113 // Enable EGL_ANGLE_explicit_context subextensions
Geoff Lang33f11fb2018-05-07 13:42:47 -04003114 if (mExplicitContextAvailable)
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003115 {
3116 // GL_ANGLE_explicit_context_gles1
3117 supportedExtensions.explicitContextGles1 = true;
3118 // GL_ANGLE_explicit_context
3119 supportedExtensions.explicitContext = true;
3120 }
3121
Geoff Langb0f917f2017-12-05 13:41:54 -05003122 return supportedExtensions;
3123}
3124
Geoff Lang33f11fb2018-05-07 13:42:47 -04003125void Context::initCaps()
Geoff Lang493daf52014-07-03 13:38:44 -04003126{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04003127 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04003128
Geoff Lang33f11fb2018-05-07 13:42:47 -04003129 mSupportedExtensions = generateSupportedExtensions();
3130 mExtensions = mSupportedExtensions;
Lingfeng Yang01074432018-04-16 10:19:51 -07003131
3132 mLimitations = mImplementation->getNativeLimitations();
3133
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003134 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
3135 if (getClientVersion() < Version(2, 0))
3136 {
3137 mCaps.maxMultitextureUnits = 4;
3138 mCaps.maxClipPlanes = 6;
3139 mCaps.maxLights = 8;
Lingfeng Yange547aac2018-04-05 09:39:20 -07003140 mCaps.maxModelviewMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3141 mCaps.maxProjectionMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3142 mCaps.maxTextureMatrixStackDepth = Caps::GlobalMatrixStackDepth;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003143 mCaps.minSmoothPointSize = 1.0f;
3144 mCaps.maxSmoothPointSize = 1.0f;
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003145 }
3146
Luc Ferronad2ae932018-06-11 15:31:17 -04003147 // Apply/Verify implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04003148 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003149
Luc Ferronad2ae932018-06-11 15:31:17 -04003150 ASSERT(mCaps.minAliasedPointSize >= 1.0f);
3151
Jamie Madill0f80ed82017-09-19 00:24:56 -04003152 if (getClientVersion() < ES_3_1)
3153 {
3154 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
3155 }
3156 else
3157 {
3158 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
3159 }
Geoff Lang301d1612014-07-09 10:34:37 -04003160
Jiawei Shao54aafe52018-04-27 14:54:57 +08003161 LimitCap(&mCaps.maxShaderUniformBlocks[ShaderType::Vertex],
3162 IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
Jamie Madill0f80ed82017-09-19 00:24:56 -04003163 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3164 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3165
3166 // Limit textures as well, so we can use fast bitsets with texture bindings.
3167 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
Jiawei Shao54aafe52018-04-27 14:54:57 +08003168 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Vertex],
3169 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
3170 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Fragment],
3171 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04003172
Jiawei Shaodb342272017-09-27 10:21:45 +08003173 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
3174
Geoff Langc287ea62016-09-16 14:46:51 -04003175 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05003176 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04003177 for (const auto &extensionInfo : GetExtensionInfoMap())
3178 {
Geoff Lang0ab41fa2018-03-14 11:03:30 -04003179 // If the user has requested that extensions start disabled and they are requestable,
3180 // disable them.
3181 if (!mExtensionsEnabled && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04003182 {
3183 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
3184 }
3185 }
3186
3187 // Generate texture caps
3188 updateCaps();
3189}
3190
3191void Context::updateCaps()
3192{
Geoff Lang900013c2014-07-07 11:32:19 -04003193 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04003194 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04003195
Jamie Madill7b62cf92017-11-02 15:20:49 -04003196 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04003197 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04003198 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04003199 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003200
Geoff Lang0d8b7242015-09-09 14:56:53 -04003201 // Update the format caps based on the client version and extensions.
3202 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
3203 // ES3.
3204 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003205 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04003206 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003207 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Yuly Novikovf15f8862018-06-04 18:59:41 -04003208 formatCaps.textureAttachment =
3209 formatCaps.textureAttachment &&
3210 formatInfo.textureAttachmentSupport(getClientVersion(), mExtensions);
3211 formatCaps.renderbuffer = formatCaps.renderbuffer &&
3212 formatInfo.renderbufferSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04003213
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003214 // OpenGL ES does not support multisampling with non-rendererable formats
3215 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Yuly Novikovf15f8862018-06-04 18:59:41 -04003216 if (!formatCaps.renderbuffer ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003217 (getClientVersion() < ES_3_1 &&
3218 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04003219 {
Geoff Langd87878e2014-09-19 15:42:59 -04003220 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04003221 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03003222 else
3223 {
3224 // We may have limited the max samples for some required renderbuffer formats due to
3225 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
3226 GLuint formatMaxSamples = formatCaps.getMaxSamples();
3227
3228 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
3229 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
3230 // exception of signed and unsigned integer formats."
3231 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
3232 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
3233 {
3234 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
3235 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
3236 }
3237
3238 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
3239 if (getClientVersion() >= ES_3_1)
3240 {
3241 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
3242 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
3243 // the exception that the signed and unsigned integer formats are required only to
3244 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
3245 // multisamples, which must be at least one."
3246 if (formatInfo.componentType == GL_INT ||
3247 formatInfo.componentType == GL_UNSIGNED_INT)
3248 {
3249 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
3250 }
3251
3252 // GLES 3.1 section 19.3.1.
3253 if (formatCaps.texturable)
3254 {
3255 if (formatInfo.depthBits > 0)
3256 {
3257 mCaps.maxDepthTextureSamples =
3258 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
3259 }
3260 else if (formatInfo.redBits > 0)
3261 {
3262 mCaps.maxColorTextureSamples =
3263 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
3264 }
3265 }
3266 }
3267 }
Geoff Langd87878e2014-09-19 15:42:59 -04003268
3269 if (formatCaps.texturable && formatInfo.compressed)
3270 {
Geoff Langca271392017-04-05 12:30:00 -04003271 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003272 }
3273
Geoff Langca271392017-04-05 12:30:00 -04003274 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04003275 }
Jamie Madill32447362017-06-28 14:53:52 -04003276
3277 // If program binary is disabled, blank out the memory cache pointer.
Geoff Langb0f917f2017-12-05 13:41:54 -05003278 if (!mSupportedExtensions.getProgramBinary)
Jamie Madill32447362017-06-28 14:53:52 -04003279 {
3280 mMemoryProgramCache = nullptr;
3281 }
Corentin Walleze4477002017-12-01 14:39:58 -05003282
3283 // Compute which buffer types are allowed
3284 mValidBufferBindings.reset();
3285 mValidBufferBindings.set(BufferBinding::ElementArray);
3286 mValidBufferBindings.set(BufferBinding::Array);
3287
3288 if (mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
3289 {
3290 mValidBufferBindings.set(BufferBinding::PixelPack);
3291 mValidBufferBindings.set(BufferBinding::PixelUnpack);
3292 }
3293
3294 if (getClientVersion() >= ES_3_0)
3295 {
3296 mValidBufferBindings.set(BufferBinding::CopyRead);
3297 mValidBufferBindings.set(BufferBinding::CopyWrite);
3298 mValidBufferBindings.set(BufferBinding::TransformFeedback);
3299 mValidBufferBindings.set(BufferBinding::Uniform);
3300 }
3301
3302 if (getClientVersion() >= ES_3_1)
3303 {
3304 mValidBufferBindings.set(BufferBinding::AtomicCounter);
3305 mValidBufferBindings.set(BufferBinding::ShaderStorage);
3306 mValidBufferBindings.set(BufferBinding::DrawIndirect);
3307 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
3308 }
Geoff Lang493daf52014-07-03 13:38:44 -04003309}
3310
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003311void Context::initWorkarounds()
3312{
Jamie Madill761b02c2017-06-23 16:27:06 -04003313 // Apply back-end workarounds.
3314 mImplementation->applyNativeWorkarounds(&mWorkarounds);
3315
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003316 // Lose the context upon out of memory error if the application is
3317 // expecting to watch for those events.
3318 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
3319}
3320
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003321Error Context::prepareForDraw(PrimitiveMode mode)
Jamie Madill05b35b22017-10-03 09:01:44 -04003322{
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003323 if (mGLES1Renderer)
3324 {
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003325 ANGLE_TRY(mGLES1Renderer->prepareForDraw(mode, this, &mGLState));
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003326 }
3327
Geoff Langa8cb2872018-03-09 16:09:40 -05003328 ANGLE_TRY(syncDirtyObjects());
Jamie Madilla59fc192017-11-02 12:57:58 -04003329
3330 if (isRobustResourceInitEnabled())
3331 {
3332 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
3333 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
3334 }
3335
Geoff Langa8cb2872018-03-09 16:09:40 -05003336 ANGLE_TRY(syncDirtyBits());
Geoff Langd4fff502017-09-22 11:28:28 -04003337 return NoError();
3338}
3339
3340Error Context::prepareForClear(GLbitfield mask)
3341{
Geoff Langa8cb2872018-03-09 16:09:40 -05003342 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003343 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearAttachmentsInitialized(this, mask));
Geoff Langa8cb2872018-03-09 16:09:40 -05003344 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04003345 return NoError();
3346}
3347
3348Error Context::prepareForClearBuffer(GLenum buffer, GLint drawbuffer)
3349{
Geoff Langa8cb2872018-03-09 16:09:40 -05003350 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003351 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearBufferAttachmentsInitialized(this, buffer,
3352 drawbuffer));
Geoff Langa8cb2872018-03-09 16:09:40 -05003353 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill05b35b22017-10-03 09:01:44 -04003354 return NoError();
3355}
3356
Geoff Langa8cb2872018-03-09 16:09:40 -05003357Error Context::syncState()
Jamie Madill1b94d432015-08-07 13:23:23 -04003358{
Geoff Langa8cb2872018-03-09 16:09:40 -05003359 ANGLE_TRY(syncDirtyObjects());
3360 ANGLE_TRY(syncDirtyBits());
Jamie Madillbc918e72018-03-08 09:47:21 -05003361 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003362}
3363
Geoff Langa8cb2872018-03-09 16:09:40 -05003364Error Context::syncState(const State::DirtyBits &bitMask, const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04003365{
Geoff Langa8cb2872018-03-09 16:09:40 -05003366 ANGLE_TRY(syncDirtyObjects(objectMask));
3367 ANGLE_TRY(syncDirtyBits(bitMask));
Geoff Langd4fff502017-09-22 11:28:28 -04003368 return NoError();
3369}
3370
Geoff Langa8cb2872018-03-09 16:09:40 -05003371Error Context::syncDirtyBits()
Geoff Langd4fff502017-09-22 11:28:28 -04003372{
3373 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
3374 mImplementation->syncState(this, dirtyBits);
3375 mGLState.clearDirtyBits();
3376 return NoError();
3377}
3378
Geoff Langa8cb2872018-03-09 16:09:40 -05003379Error Context::syncDirtyBits(const State::DirtyBits &bitMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003380{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003381 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madillfe548342017-06-19 11:13:24 -04003382 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003383 mGLState.clearDirtyBits(dirtyBits);
Jamie Madillbc918e72018-03-08 09:47:21 -05003384 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003385}
Jamie Madillc29968b2016-01-20 11:17:23 -05003386
Geoff Langa8cb2872018-03-09 16:09:40 -05003387Error Context::syncDirtyObjects()
Geoff Langd4fff502017-09-22 11:28:28 -04003388{
3389 return mGLState.syncDirtyObjects(this);
3390}
3391
Geoff Langa8cb2872018-03-09 16:09:40 -05003392Error Context::syncDirtyObjects(const State::DirtyObjects &objectMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003393{
3394 return mGLState.syncDirtyObjects(this, objectMask);
3395}
3396
Jamie Madillc29968b2016-01-20 11:17:23 -05003397void Context::blitFramebuffer(GLint srcX0,
3398 GLint srcY0,
3399 GLint srcX1,
3400 GLint srcY1,
3401 GLint dstX0,
3402 GLint dstY0,
3403 GLint dstX1,
3404 GLint dstY1,
3405 GLbitfield mask,
3406 GLenum filter)
3407{
Qin Jiajiaaef92162018-02-27 13:51:44 +08003408 if (mask == 0)
3409 {
3410 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
3411 // buffers are copied.
3412 return;
3413 }
3414
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003415 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003416 ASSERT(drawFramebuffer);
3417
3418 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
3419 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
3420
Jamie Madillbc918e72018-03-08 09:47:21 -05003421 ANGLE_CONTEXT_TRY(syncStateForBlit());
Jamie Madillc29968b2016-01-20 11:17:23 -05003422
Jamie Madillc564c072017-06-01 12:45:42 -04003423 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003424}
Jamie Madillc29968b2016-01-20 11:17:23 -05003425
3426void Context::clear(GLbitfield mask)
3427{
Geoff Langd4fff502017-09-22 11:28:28 -04003428 ANGLE_CONTEXT_TRY(prepareForClear(mask));
3429 ANGLE_CONTEXT_TRY(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05003430}
3431
3432void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
3433{
Geoff Langd4fff502017-09-22 11:28:28 -04003434 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3435 ANGLE_CONTEXT_TRY(
3436 mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003437}
3438
3439void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3440{
Geoff Langd4fff502017-09-22 11:28:28 -04003441 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3442 ANGLE_CONTEXT_TRY(
3443 mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003444}
3445
3446void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3447{
Geoff Langd4fff502017-09-22 11:28:28 -04003448 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3449 ANGLE_CONTEXT_TRY(
3450 mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003451}
3452
3453void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3454{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003455 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003456 ASSERT(framebufferObject);
3457
3458 // If a buffer is not present, the clear has no effect
3459 if (framebufferObject->getDepthbuffer() == nullptr &&
3460 framebufferObject->getStencilbuffer() == nullptr)
3461 {
3462 return;
3463 }
3464
Geoff Langd4fff502017-09-22 11:28:28 -04003465 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3466 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003467}
3468
3469void Context::readPixels(GLint x,
3470 GLint y,
3471 GLsizei width,
3472 GLsizei height,
3473 GLenum format,
3474 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003475 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003476{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003477 if (width == 0 || height == 0)
3478 {
3479 return;
3480 }
3481
Jamie Madillbc918e72018-03-08 09:47:21 -05003482 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003483
Jamie Madillb6664922017-07-25 12:55:04 -04003484 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3485 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003486
3487 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04003488 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003489}
3490
Brandon Jones59770802018-04-02 13:18:42 -07003491void Context::readPixelsRobust(GLint x,
3492 GLint y,
3493 GLsizei width,
3494 GLsizei height,
3495 GLenum format,
3496 GLenum type,
3497 GLsizei bufSize,
3498 GLsizei *length,
3499 GLsizei *columns,
3500 GLsizei *rows,
3501 void *pixels)
3502{
3503 readPixels(x, y, width, height, format, type, pixels);
3504}
3505
3506void Context::readnPixelsRobust(GLint x,
3507 GLint y,
3508 GLsizei width,
3509 GLsizei height,
3510 GLenum format,
3511 GLenum type,
3512 GLsizei bufSize,
3513 GLsizei *length,
3514 GLsizei *columns,
3515 GLsizei *rows,
3516 void *data)
3517{
3518 readPixels(x, y, width, height, format, type, data);
3519}
3520
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003521void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003522 GLint level,
3523 GLenum internalformat,
3524 GLint x,
3525 GLint y,
3526 GLsizei width,
3527 GLsizei height,
3528 GLint border)
3529{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003530 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003531 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003532
Jamie Madillc29968b2016-01-20 11:17:23 -05003533 Rectangle sourceArea(x, y, width, height);
3534
Jamie Madill05b35b22017-10-03 09:01:44 -04003535 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003536 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003537 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003538}
3539
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003540void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003541 GLint level,
3542 GLint xoffset,
3543 GLint yoffset,
3544 GLint x,
3545 GLint y,
3546 GLsizei width,
3547 GLsizei height)
3548{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003549 if (width == 0 || height == 0)
3550 {
3551 return;
3552 }
3553
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003554 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003555 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003556
Jamie Madillc29968b2016-01-20 11:17:23 -05003557 Offset destOffset(xoffset, yoffset, 0);
3558 Rectangle sourceArea(x, y, width, height);
3559
Jamie Madill05b35b22017-10-03 09:01:44 -04003560 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003561 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003562 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003563}
3564
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003565void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003566 GLint level,
3567 GLint xoffset,
3568 GLint yoffset,
3569 GLint zoffset,
3570 GLint x,
3571 GLint y,
3572 GLsizei width,
3573 GLsizei height)
3574{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003575 if (width == 0 || height == 0)
3576 {
3577 return;
3578 }
3579
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003580 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003581 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003582
Jamie Madillc29968b2016-01-20 11:17:23 -05003583 Offset destOffset(xoffset, yoffset, zoffset);
3584 Rectangle sourceArea(x, y, width, height);
3585
Jamie Madill05b35b22017-10-03 09:01:44 -04003586 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3587 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003588 handleError(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level, destOffset,
3589 sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003590}
3591
3592void Context::framebufferTexture2D(GLenum target,
3593 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003594 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003595 GLuint texture,
3596 GLint level)
3597{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003598 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003599 ASSERT(framebuffer);
3600
3601 if (texture != 0)
3602 {
3603 Texture *textureObj = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003604 ImageIndex index = ImageIndex::MakeFromTarget(textarget, level);
Jamie Madilla02315b2017-02-23 14:14:47 -05003605 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003606 }
3607 else
3608 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003609 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003610 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003611
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003612 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003613}
3614
3615void Context::framebufferRenderbuffer(GLenum target,
3616 GLenum attachment,
3617 GLenum renderbuffertarget,
3618 GLuint renderbuffer)
3619{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003620 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003621 ASSERT(framebuffer);
3622
3623 if (renderbuffer != 0)
3624 {
3625 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003626
Jamie Madillcc129372018-04-12 09:13:18 -04003627 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003628 renderbufferObject);
3629 }
3630 else
3631 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003632 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003633 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003634
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003635 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003636}
3637
3638void Context::framebufferTextureLayer(GLenum target,
3639 GLenum attachment,
3640 GLuint texture,
3641 GLint level,
3642 GLint layer)
3643{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003644 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003645 ASSERT(framebuffer);
3646
3647 if (texture != 0)
3648 {
3649 Texture *textureObject = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003650 ImageIndex index = ImageIndex::MakeFromType(textureObject->getType(), level, layer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003651 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003652 }
3653 else
3654 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003655 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003656 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003657
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003658 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003659}
3660
Brandon Jones59770802018-04-02 13:18:42 -07003661void Context::framebufferTextureMultiviewLayered(GLenum target,
3662 GLenum attachment,
3663 GLuint texture,
3664 GLint level,
3665 GLint baseViewIndex,
3666 GLsizei numViews)
Martin Radev137032d2017-07-13 10:11:12 +03003667{
Martin Radev82ef7742017-08-08 17:44:58 +03003668 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3669 ASSERT(framebuffer);
3670
3671 if (texture != 0)
3672 {
3673 Texture *textureObj = getTexture(texture);
3674
Martin Radev18b75ba2017-08-15 15:50:40 +03003675 ImageIndex index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
Martin Radev82ef7742017-08-08 17:44:58 +03003676 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3677 numViews, baseViewIndex);
3678 }
3679 else
3680 {
3681 framebuffer->resetAttachment(this, attachment);
3682 }
3683
3684 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003685}
3686
Brandon Jones59770802018-04-02 13:18:42 -07003687void Context::framebufferTextureMultiviewSideBySide(GLenum target,
3688 GLenum attachment,
3689 GLuint texture,
3690 GLint level,
3691 GLsizei numViews,
3692 const GLint *viewportOffsets)
Martin Radev137032d2017-07-13 10:11:12 +03003693{
Martin Radev5dae57b2017-07-14 16:15:55 +03003694 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3695 ASSERT(framebuffer);
3696
3697 if (texture != 0)
3698 {
3699 Texture *textureObj = getTexture(texture);
3700
3701 ImageIndex index = ImageIndex::Make2D(level);
3702 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3703 textureObj, numViews, viewportOffsets);
3704 }
3705 else
3706 {
3707 framebuffer->resetAttachment(this, attachment);
3708 }
3709
3710 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003711}
3712
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003713void Context::framebufferTexture(GLenum target, GLenum attachment, GLuint texture, GLint level)
3714{
Jiawei Shaoa8802472018-05-28 11:17:47 +08003715 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3716 ASSERT(framebuffer);
3717
3718 if (texture != 0)
3719 {
3720 Texture *textureObj = getTexture(texture);
3721
3722 ImageIndex index = ImageIndex::MakeFromType(
3723 textureObj->getType(), level, ImageIndex::kEntireLevel, ImageIndex::kEntireLevel);
3724 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
3725 }
3726 else
3727 {
3728 framebuffer->resetAttachment(this, attachment);
3729 }
3730
3731 mGLState.setObjectDirty(target);
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003732}
3733
Jamie Madillc29968b2016-01-20 11:17:23 -05003734void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3735{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003736 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003737 ASSERT(framebuffer);
3738 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003739 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003740}
3741
3742void Context::readBuffer(GLenum mode)
3743{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003744 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003745 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003746 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003747}
3748
3749void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3750{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003751 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003752 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003753
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003754 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003755 ASSERT(framebuffer);
3756
3757 // The specification isn't clear what should be done when the framebuffer isn't complete.
3758 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003759 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003760}
3761
3762void Context::invalidateFramebuffer(GLenum target,
3763 GLsizei numAttachments,
3764 const GLenum *attachments)
3765{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003766 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003767 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003768
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003769 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003770 ASSERT(framebuffer);
3771
Jamie Madill427064d2018-04-13 16:20:34 -04003772 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003773 {
Jamie Madill437fa652016-05-03 15:13:24 -04003774 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003775 }
Jamie Madill437fa652016-05-03 15:13:24 -04003776
Jamie Madill4928b7c2017-06-20 12:57:39 -04003777 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003778}
3779
3780void Context::invalidateSubFramebuffer(GLenum target,
3781 GLsizei numAttachments,
3782 const GLenum *attachments,
3783 GLint x,
3784 GLint y,
3785 GLsizei width,
3786 GLsizei height)
3787{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003788 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003789 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003790
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003791 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003792 ASSERT(framebuffer);
3793
Jamie Madill427064d2018-04-13 16:20:34 -04003794 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003795 {
Jamie Madill437fa652016-05-03 15:13:24 -04003796 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003797 }
Jamie Madill437fa652016-05-03 15:13:24 -04003798
3799 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003800 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003801}
3802
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003803void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003804 GLint level,
3805 GLint internalformat,
3806 GLsizei width,
3807 GLsizei height,
3808 GLint border,
3809 GLenum format,
3810 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003811 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003812{
Jamie Madillbc918e72018-03-08 09:47:21 -05003813 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003814
3815 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003816 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003817 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003818 size, format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003819}
3820
Brandon Jones59770802018-04-02 13:18:42 -07003821void Context::texImage2DRobust(TextureTarget target,
3822 GLint level,
3823 GLint internalformat,
3824 GLsizei width,
3825 GLsizei height,
3826 GLint border,
3827 GLenum format,
3828 GLenum type,
3829 GLsizei bufSize,
3830 const void *pixels)
3831{
3832 texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
3833}
3834
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003835void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003836 GLint level,
3837 GLint internalformat,
3838 GLsizei width,
3839 GLsizei height,
3840 GLsizei depth,
3841 GLint border,
3842 GLenum format,
3843 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003844 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003845{
Jamie Madillbc918e72018-03-08 09:47:21 -05003846 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003847
3848 Extents size(width, height, depth);
3849 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003850 handleError(texture->setImage(this, mGLState.getUnpackState(),
3851 NonCubeTextureTypeToTarget(target), level, internalformat, size,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003852 format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003853}
3854
Brandon Jones59770802018-04-02 13:18:42 -07003855void Context::texImage3DRobust(TextureType target,
3856 GLint level,
3857 GLint internalformat,
3858 GLsizei width,
3859 GLsizei height,
3860 GLsizei depth,
3861 GLint border,
3862 GLenum format,
3863 GLenum type,
3864 GLsizei bufSize,
3865 const void *pixels)
3866{
3867 texImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels);
3868}
3869
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003870void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003871 GLint level,
3872 GLint xoffset,
3873 GLint yoffset,
3874 GLsizei width,
3875 GLsizei height,
3876 GLenum format,
3877 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003878 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003879{
3880 // Zero sized uploads are valid but no-ops
3881 if (width == 0 || height == 0)
3882 {
3883 return;
3884 }
3885
Jamie Madillbc918e72018-03-08 09:47:21 -05003886 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003887
3888 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003889 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003890 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003891 type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003892}
3893
Brandon Jones59770802018-04-02 13:18:42 -07003894void Context::texSubImage2DRobust(TextureTarget target,
3895 GLint level,
3896 GLint xoffset,
3897 GLint yoffset,
3898 GLsizei width,
3899 GLsizei height,
3900 GLenum format,
3901 GLenum type,
3902 GLsizei bufSize,
3903 const void *pixels)
3904{
3905 texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
3906}
3907
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003908void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003909 GLint level,
3910 GLint xoffset,
3911 GLint yoffset,
3912 GLint zoffset,
3913 GLsizei width,
3914 GLsizei height,
3915 GLsizei depth,
3916 GLenum format,
3917 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003918 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003919{
3920 // Zero sized uploads are valid but no-ops
3921 if (width == 0 || height == 0 || depth == 0)
3922 {
3923 return;
3924 }
3925
Jamie Madillbc918e72018-03-08 09:47:21 -05003926 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003927
3928 Box area(xoffset, yoffset, zoffset, width, height, depth);
3929 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003930 handleError(texture->setSubImage(this, mGLState.getUnpackState(),
3931 NonCubeTextureTypeToTarget(target), level, area, format, type,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003932 static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003933}
3934
Brandon Jones59770802018-04-02 13:18:42 -07003935void Context::texSubImage3DRobust(TextureType target,
3936 GLint level,
3937 GLint xoffset,
3938 GLint yoffset,
3939 GLint zoffset,
3940 GLsizei width,
3941 GLsizei height,
3942 GLsizei depth,
3943 GLenum format,
3944 GLenum type,
3945 GLsizei bufSize,
3946 const void *pixels)
3947{
3948 texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type,
3949 pixels);
3950}
3951
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003952void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003953 GLint level,
3954 GLenum internalformat,
3955 GLsizei width,
3956 GLsizei height,
3957 GLint border,
3958 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003959 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003960{
Jamie Madillbc918e72018-03-08 09:47:21 -05003961 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003962
3963 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003964 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003965 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
3966 internalformat, size, imageSize,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003967 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003968}
3969
Brandon Jones59770802018-04-02 13:18:42 -07003970void Context::compressedTexImage2DRobust(TextureTarget target,
3971 GLint level,
3972 GLenum internalformat,
3973 GLsizei width,
3974 GLsizei height,
3975 GLint border,
3976 GLsizei imageSize,
3977 GLsizei dataSize,
3978 const GLvoid *data)
3979{
3980 compressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
3981}
3982
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003983void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003984 GLint level,
3985 GLenum internalformat,
3986 GLsizei width,
3987 GLsizei height,
3988 GLsizei depth,
3989 GLint border,
3990 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003991 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003992{
Jamie Madillbc918e72018-03-08 09:47:21 -05003993 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003994
3995 Extents size(width, height, depth);
3996 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003997 handleError(texture->setCompressedImage(
3998 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003999 size, imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004000}
4001
Brandon Jones59770802018-04-02 13:18:42 -07004002void Context::compressedTexImage3DRobust(TextureType target,
4003 GLint level,
4004 GLenum internalformat,
4005 GLsizei width,
4006 GLsizei height,
4007 GLsizei depth,
4008 GLint border,
4009 GLsizei imageSize,
4010 GLsizei dataSize,
4011 const GLvoid *data)
4012{
4013 compressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize,
4014 data);
4015}
4016
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004017void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004018 GLint level,
4019 GLint xoffset,
4020 GLint yoffset,
4021 GLsizei width,
4022 GLsizei height,
4023 GLenum format,
4024 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004025 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004026{
Jamie Madillbc918e72018-03-08 09:47:21 -05004027 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004028
4029 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004030 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05004031 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
4032 format, imageSize,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004033 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004034}
4035
Brandon Jones59770802018-04-02 13:18:42 -07004036void Context::compressedTexSubImage2DRobust(TextureTarget target,
4037 GLint level,
4038 GLint xoffset,
4039 GLint yoffset,
4040 GLsizei width,
4041 GLsizei height,
4042 GLenum format,
4043 GLsizei imageSize,
4044 GLsizei dataSize,
4045 const GLvoid *data)
4046{
4047 compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize,
4048 data);
4049}
4050
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004051void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004052 GLint level,
4053 GLint xoffset,
4054 GLint yoffset,
4055 GLint zoffset,
4056 GLsizei width,
4057 GLsizei height,
4058 GLsizei depth,
4059 GLenum format,
4060 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004061 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004062{
4063 // Zero sized uploads are valid but no-ops
4064 if (width == 0 || height == 0)
4065 {
4066 return;
4067 }
4068
Jamie Madillbc918e72018-03-08 09:47:21 -05004069 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004070
4071 Box area(xoffset, yoffset, zoffset, width, height, depth);
4072 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004073 handleError(texture->setCompressedSubImage(
4074 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004075 imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004076}
4077
Brandon Jones59770802018-04-02 13:18:42 -07004078void Context::compressedTexSubImage3DRobust(TextureType target,
4079 GLint level,
4080 GLint xoffset,
4081 GLint yoffset,
4082 GLint zoffset,
4083 GLsizei width,
4084 GLsizei height,
4085 GLsizei depth,
4086 GLenum format,
4087 GLsizei imageSize,
4088 GLsizei dataSize,
4089 const GLvoid *data)
4090{
4091 compressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format,
4092 imageSize, data);
4093}
4094
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004095void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004096{
4097 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05004098 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004099}
4100
Jamie Madill007530e2017-12-28 14:27:04 -05004101void Context::copyTexture(GLuint sourceId,
4102 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004103 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004104 GLuint destId,
4105 GLint destLevel,
4106 GLint internalFormat,
4107 GLenum destType,
4108 GLboolean unpackFlipY,
4109 GLboolean unpackPremultiplyAlpha,
4110 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004111{
Jamie Madillbc918e72018-03-08 09:47:21 -05004112 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004113
4114 gl::Texture *sourceTexture = getTexture(sourceId);
4115 gl::Texture *destTexture = getTexture(destId);
Geoff Lang92019432017-11-20 13:09:34 -05004116 handleError(destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType,
4117 sourceLevel, ConvertToBool(unpackFlipY),
4118 ConvertToBool(unpackPremultiplyAlpha),
4119 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004120}
4121
Jamie Madill007530e2017-12-28 14:27:04 -05004122void Context::copySubTexture(GLuint sourceId,
4123 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004124 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004125 GLuint destId,
4126 GLint destLevel,
4127 GLint xoffset,
4128 GLint yoffset,
4129 GLint x,
4130 GLint y,
4131 GLsizei width,
4132 GLsizei height,
4133 GLboolean unpackFlipY,
4134 GLboolean unpackPremultiplyAlpha,
4135 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004136{
4137 // Zero sized copies are valid but no-ops
4138 if (width == 0 || height == 0)
4139 {
4140 return;
4141 }
4142
Jamie Madillbc918e72018-03-08 09:47:21 -05004143 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004144
4145 gl::Texture *sourceTexture = getTexture(sourceId);
4146 gl::Texture *destTexture = getTexture(destId);
4147 Offset offset(xoffset, yoffset, 0);
4148 Rectangle area(x, y, width, height);
Geoff Lang92019432017-11-20 13:09:34 -05004149 handleError(destTexture->copySubTexture(this, destTarget, destLevel, offset, sourceLevel, area,
4150 ConvertToBool(unpackFlipY),
4151 ConvertToBool(unpackPremultiplyAlpha),
4152 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004153}
4154
Jamie Madill007530e2017-12-28 14:27:04 -05004155void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07004156{
Jamie Madillbc918e72018-03-08 09:47:21 -05004157 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07004158
4159 gl::Texture *sourceTexture = getTexture(sourceId);
4160 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05004161 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07004162}
4163
Corentin Wallez336129f2017-10-17 15:55:40 -04004164void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03004165{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004166 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004167 ASSERT(buffer);
4168
Geoff Lang496c02d2016-10-20 11:38:11 -07004169 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03004170}
4171
Brandon Jones59770802018-04-02 13:18:42 -07004172void Context::getBufferPointervRobust(BufferBinding target,
4173 GLenum pname,
4174 GLsizei bufSize,
4175 GLsizei *length,
4176 void **params)
4177{
4178 getBufferPointerv(target, pname, params);
4179}
4180
Corentin Wallez336129f2017-10-17 15:55:40 -04004181void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004182{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004183 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004184 ASSERT(buffer);
4185
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004186 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004187 if (error.isError())
4188 {
Jamie Madill437fa652016-05-03 15:13:24 -04004189 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004190 return nullptr;
4191 }
4192
4193 return buffer->getMapPointer();
4194}
4195
Corentin Wallez336129f2017-10-17 15:55:40 -04004196GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03004197{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004198 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004199 ASSERT(buffer);
4200
4201 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004202 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03004203 if (error.isError())
4204 {
Jamie Madill437fa652016-05-03 15:13:24 -04004205 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004206 return GL_FALSE;
4207 }
4208
4209 return result;
4210}
4211
Corentin Wallez336129f2017-10-17 15:55:40 -04004212void *Context::mapBufferRange(BufferBinding target,
4213 GLintptr offset,
4214 GLsizeiptr length,
4215 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004216{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004217 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004218 ASSERT(buffer);
4219
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004220 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004221 if (error.isError())
4222 {
Jamie Madill437fa652016-05-03 15:13:24 -04004223 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004224 return nullptr;
4225 }
4226
4227 return buffer->getMapPointer();
4228}
4229
Corentin Wallez336129f2017-10-17 15:55:40 -04004230void Context::flushMappedBufferRange(BufferBinding /*target*/,
4231 GLintptr /*offset*/,
4232 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03004233{
4234 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
4235}
4236
Jamie Madillbc918e72018-03-08 09:47:21 -05004237Error Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004238{
Geoff Langa8cb2872018-03-09 16:09:40 -05004239 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004240}
4241
Jamie Madillbc918e72018-03-08 09:47:21 -05004242Error Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004243{
Geoff Langa8cb2872018-03-09 16:09:40 -05004244 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004245}
4246
Jamie Madillbc918e72018-03-08 09:47:21 -05004247Error Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004248{
Geoff Langa8cb2872018-03-09 16:09:40 -05004249 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004250}
4251
Jiajia Qin5451d532017-11-16 17:16:34 +08004252void Context::activeShaderProgram(GLuint pipeline, GLuint program)
4253{
4254 UNIMPLEMENTED();
4255}
4256
Jamie Madillc20ab272016-06-09 07:20:46 -07004257void Context::activeTexture(GLenum texture)
4258{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004259 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004260}
4261
Jamie Madill876429b2017-04-20 15:46:24 -04004262void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004263{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004264 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004265}
4266
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004267void Context::blendEquation(GLenum mode)
4268{
4269 mGLState.setBlendEquation(mode, mode);
4270}
4271
Jamie Madillc20ab272016-06-09 07:20:46 -07004272void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
4273{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004274 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004275}
4276
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004277void Context::blendFunc(GLenum sfactor, GLenum dfactor)
4278{
4279 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
4280}
4281
Jamie Madillc20ab272016-06-09 07:20:46 -07004282void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
4283{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004284 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004285}
4286
Jamie Madill876429b2017-04-20 15:46:24 -04004287void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004288{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004289 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004290}
4291
Jamie Madill876429b2017-04-20 15:46:24 -04004292void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07004293{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004294 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07004295}
4296
4297void Context::clearStencil(GLint s)
4298{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004299 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07004300}
4301
4302void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
4303{
Geoff Lang92019432017-11-20 13:09:34 -05004304 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
4305 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004306}
4307
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004308void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07004309{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004310 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004311}
4312
4313void Context::depthFunc(GLenum func)
4314{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004315 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07004316}
4317
4318void Context::depthMask(GLboolean flag)
4319{
Geoff Lang92019432017-11-20 13:09:34 -05004320 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07004321}
4322
Jamie Madill876429b2017-04-20 15:46:24 -04004323void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07004324{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004325 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07004326}
4327
4328void Context::disable(GLenum cap)
4329{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004330 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07004331}
4332
4333void Context::disableVertexAttribArray(GLuint index)
4334{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004335 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07004336}
4337
4338void Context::enable(GLenum cap)
4339{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004340 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07004341}
4342
4343void Context::enableVertexAttribArray(GLuint index)
4344{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004345 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07004346}
4347
4348void Context::frontFace(GLenum mode)
4349{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004350 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004351}
4352
4353void Context::hint(GLenum target, GLenum mode)
4354{
4355 switch (target)
4356 {
4357 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004358 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004359 break;
4360
4361 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004362 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004363 break;
4364
4365 default:
4366 UNREACHABLE();
4367 return;
4368 }
4369}
4370
4371void Context::lineWidth(GLfloat width)
4372{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004373 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07004374}
4375
4376void Context::pixelStorei(GLenum pname, GLint param)
4377{
4378 switch (pname)
4379 {
4380 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004381 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004382 break;
4383
4384 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004385 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004386 break;
4387
4388 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004389 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004390 break;
4391
4392 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004393 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004394 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004395 break;
4396
4397 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03004398 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004399 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004400 break;
4401
4402 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03004403 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004404 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004405 break;
4406
4407 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004408 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004409 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004410 break;
4411
4412 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004413 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004414 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004415 break;
4416
4417 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004418 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004419 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004420 break;
4421
4422 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004423 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004424 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004425 break;
4426
4427 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004428 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004429 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004430 break;
4431
4432 default:
4433 UNREACHABLE();
4434 return;
4435 }
4436}
4437
4438void Context::polygonOffset(GLfloat factor, GLfloat units)
4439{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004440 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07004441}
4442
Jamie Madill876429b2017-04-20 15:46:24 -04004443void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07004444{
Geoff Lang92019432017-11-20 13:09:34 -05004445 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07004446}
4447
Jiawei Shaodb342272017-09-27 10:21:45 +08004448void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
4449{
4450 mGLState.setSampleMaskParams(maskNumber, mask);
4451}
4452
Jamie Madillc20ab272016-06-09 07:20:46 -07004453void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
4454{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004455 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004456}
4457
4458void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
4459{
4460 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4461 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004462 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004463 }
4464
4465 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4466 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004467 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004468 }
4469}
4470
4471void Context::stencilMaskSeparate(GLenum face, GLuint mask)
4472{
4473 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4474 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004475 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004476 }
4477
4478 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4479 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004480 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004481 }
4482}
4483
4484void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4485{
4486 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4487 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004488 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004489 }
4490
4491 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4492 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004493 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004494 }
4495}
4496
4497void Context::vertexAttrib1f(GLuint index, GLfloat x)
4498{
4499 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004500 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004501}
4502
4503void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
4504{
4505 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004506 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004507}
4508
4509void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4510{
4511 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004512 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004513}
4514
4515void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
4516{
4517 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004518 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004519}
4520
4521void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4522{
4523 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004524 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004525}
4526
4527void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
4528{
4529 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004530 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004531}
4532
4533void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4534{
4535 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004536 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004537}
4538
4539void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
4540{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004541 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07004542}
4543
4544void Context::vertexAttribPointer(GLuint index,
4545 GLint size,
4546 GLenum type,
4547 GLboolean normalized,
4548 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004549 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07004550{
Corentin Wallez336129f2017-10-17 15:55:40 -04004551 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05004552 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc20ab272016-06-09 07:20:46 -07004553}
4554
Shao80957d92017-02-20 21:25:59 +08004555void Context::vertexAttribFormat(GLuint attribIndex,
4556 GLint size,
4557 GLenum type,
4558 GLboolean normalized,
4559 GLuint relativeOffset)
4560{
Geoff Lang92019432017-11-20 13:09:34 -05004561 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08004562 relativeOffset);
4563}
4564
4565void Context::vertexAttribIFormat(GLuint attribIndex,
4566 GLint size,
4567 GLenum type,
4568 GLuint relativeOffset)
4569{
4570 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
4571}
4572
4573void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4574{
Shaodde78e82017-05-22 14:13:27 +08004575 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Shao80957d92017-02-20 21:25:59 +08004576}
4577
Jiajia Qin5451d532017-11-16 17:16:34 +08004578void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004579{
4580 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
4581}
4582
Jamie Madillc20ab272016-06-09 07:20:46 -07004583void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4584{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004585 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004586}
4587
4588void Context::vertexAttribIPointer(GLuint index,
4589 GLint size,
4590 GLenum type,
4591 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004592 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004593{
Corentin Wallez336129f2017-10-17 15:55:40 -04004594 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
4595 size, type, false, true, stride, pointer);
Jamie Madillc20ab272016-06-09 07:20:46 -07004596}
4597
4598void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4599{
4600 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004601 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004602}
4603
4604void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4605{
4606 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004607 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004608}
4609
4610void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4611{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004612 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004613}
4614
4615void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4616{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004617 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004618}
4619
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004620void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4621{
4622 const VertexAttribCurrentValueData &currentValues =
4623 getGLState().getVertexAttribCurrentValue(index);
4624 const VertexArray *vao = getGLState().getVertexArray();
4625 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4626 currentValues, pname, params);
4627}
4628
Brandon Jones59770802018-04-02 13:18:42 -07004629void Context::getVertexAttribivRobust(GLuint index,
4630 GLenum pname,
4631 GLsizei bufSize,
4632 GLsizei *length,
4633 GLint *params)
4634{
4635 getVertexAttribiv(index, pname, params);
4636}
4637
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004638void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4639{
4640 const VertexAttribCurrentValueData &currentValues =
4641 getGLState().getVertexAttribCurrentValue(index);
4642 const VertexArray *vao = getGLState().getVertexArray();
4643 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4644 currentValues, pname, params);
4645}
4646
Brandon Jones59770802018-04-02 13:18:42 -07004647void Context::getVertexAttribfvRobust(GLuint index,
4648 GLenum pname,
4649 GLsizei bufSize,
4650 GLsizei *length,
4651 GLfloat *params)
4652{
4653 getVertexAttribfv(index, pname, params);
4654}
4655
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004656void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4657{
4658 const VertexAttribCurrentValueData &currentValues =
4659 getGLState().getVertexAttribCurrentValue(index);
4660 const VertexArray *vao = getGLState().getVertexArray();
4661 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4662 currentValues, pname, params);
4663}
4664
Brandon Jones59770802018-04-02 13:18:42 -07004665void Context::getVertexAttribIivRobust(GLuint index,
4666 GLenum pname,
4667 GLsizei bufSize,
4668 GLsizei *length,
4669 GLint *params)
4670{
4671 getVertexAttribIiv(index, pname, params);
4672}
4673
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004674void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4675{
4676 const VertexAttribCurrentValueData &currentValues =
4677 getGLState().getVertexAttribCurrentValue(index);
4678 const VertexArray *vao = getGLState().getVertexArray();
4679 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4680 currentValues, pname, params);
4681}
4682
Brandon Jones59770802018-04-02 13:18:42 -07004683void Context::getVertexAttribIuivRobust(GLuint index,
4684 GLenum pname,
4685 GLsizei bufSize,
4686 GLsizei *length,
4687 GLuint *params)
4688{
4689 getVertexAttribIuiv(index, pname, params);
4690}
4691
Jamie Madill876429b2017-04-20 15:46:24 -04004692void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004693{
4694 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
4695 QueryVertexAttribPointerv(attrib, pname, pointer);
4696}
4697
Brandon Jones59770802018-04-02 13:18:42 -07004698void Context::getVertexAttribPointervRobust(GLuint index,
4699 GLenum pname,
4700 GLsizei bufSize,
4701 GLsizei *length,
4702 void **pointer)
4703{
4704 getVertexAttribPointerv(index, pname, pointer);
4705}
4706
Jamie Madillc20ab272016-06-09 07:20:46 -07004707void Context::debugMessageControl(GLenum source,
4708 GLenum type,
4709 GLenum severity,
4710 GLsizei count,
4711 const GLuint *ids,
4712 GLboolean enabled)
4713{
4714 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004715 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05004716 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004717}
4718
4719void Context::debugMessageInsert(GLenum source,
4720 GLenum type,
4721 GLuint id,
4722 GLenum severity,
4723 GLsizei length,
4724 const GLchar *buf)
4725{
4726 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004727 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004728}
4729
4730void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4731{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004732 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004733}
4734
4735GLuint Context::getDebugMessageLog(GLuint count,
4736 GLsizei bufSize,
4737 GLenum *sources,
4738 GLenum *types,
4739 GLuint *ids,
4740 GLenum *severities,
4741 GLsizei *lengths,
4742 GLchar *messageLog)
4743{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004744 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4745 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004746}
4747
4748void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4749{
4750 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004751 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05004752 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07004753}
4754
4755void Context::popDebugGroup()
4756{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004757 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05004758 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004759}
4760
Corentin Wallez336129f2017-10-17 15:55:40 -04004761void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004762{
4763 Buffer *buffer = mGLState.getTargetBuffer(target);
4764 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004765 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004766}
4767
Corentin Wallez336129f2017-10-17 15:55:40 -04004768void Context::bufferSubData(BufferBinding target,
4769 GLintptr offset,
4770 GLsizeiptr size,
4771 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004772{
4773 if (data == nullptr)
4774 {
4775 return;
4776 }
4777
4778 Buffer *buffer = mGLState.getTargetBuffer(target);
4779 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004780 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004781}
4782
Jamie Madillef300b12016-10-07 15:12:09 -04004783void Context::attachShader(GLuint program, GLuint shader)
4784{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05004785 Program *programObject = mState.mShaderPrograms->getProgram(program);
4786 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004787 ASSERT(programObject && shaderObject);
4788 programObject->attachShader(shaderObject);
4789}
4790
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004791const Workarounds &Context::getWorkarounds() const
4792{
4793 return mWorkarounds;
4794}
4795
Corentin Wallez336129f2017-10-17 15:55:40 -04004796void Context::copyBufferSubData(BufferBinding readTarget,
4797 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04004798 GLintptr readOffset,
4799 GLintptr writeOffset,
4800 GLsizeiptr size)
4801{
4802 // if size is zero, the copy is a successful no-op
4803 if (size == 0)
4804 {
4805 return;
4806 }
4807
4808 // TODO(jmadill): cache these.
4809 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4810 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4811
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004812 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004813}
4814
Jamie Madill01a80ee2016-11-07 12:06:18 -05004815void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4816{
4817 Program *programObject = getProgram(program);
4818 // TODO(jmadill): Re-use this from the validation if possible.
4819 ASSERT(programObject);
4820 programObject->bindAttributeLocation(index, name);
4821}
4822
Corentin Wallez336129f2017-10-17 15:55:40 -04004823void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004824{
Corentin Wallez336129f2017-10-17 15:55:40 -04004825 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4826 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004827}
4828
Corentin Wallez336129f2017-10-17 15:55:40 -04004829void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08004830{
4831 bindBufferRange(target, index, buffer, 0, 0);
4832}
4833
Corentin Wallez336129f2017-10-17 15:55:40 -04004834void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08004835 GLuint index,
4836 GLuint buffer,
4837 GLintptr offset,
4838 GLsizeiptr size)
4839{
Corentin Wallez336129f2017-10-17 15:55:40 -04004840 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4841 mGLState.setIndexedBufferBinding(this, target, index, bufferObject, offset, size);
Jiajia Qin6eafb042016-12-27 17:04:07 +08004842}
4843
Jamie Madill01a80ee2016-11-07 12:06:18 -05004844void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
4845{
4846 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4847 {
4848 bindReadFramebuffer(framebuffer);
4849 }
4850
4851 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4852 {
4853 bindDrawFramebuffer(framebuffer);
4854 }
4855}
4856
4857void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4858{
4859 ASSERT(target == GL_RENDERBUFFER);
4860 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004861 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04004862 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004863}
4864
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004865void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08004866 GLsizei samples,
4867 GLenum internalformat,
4868 GLsizei width,
4869 GLsizei height,
4870 GLboolean fixedsamplelocations)
4871{
4872 Extents size(width, height, 1);
4873 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004874 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
4875 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004876}
4877
4878void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4879{
JiangYizhou5b03f472017-01-09 10:22:53 +08004880 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
4881 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillbc918e72018-03-08 09:47:21 -05004882 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
JiangYizhou5b03f472017-01-09 10:22:53 +08004883 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08004884
4885 switch (pname)
4886 {
4887 case GL_SAMPLE_POSITION:
Geoff Lang13455072018-05-09 11:24:43 -04004888 handleError(framebuffer->getSamplePosition(this, index, val));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004889 break;
4890 default:
4891 UNREACHABLE();
4892 }
4893}
4894
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07004895void Context::getMultisamplefvRobust(GLenum pname,
4896 GLuint index,
4897 GLsizei bufSize,
4898 GLsizei *length,
4899 GLfloat *val)
4900{
4901 UNIMPLEMENTED();
4902}
4903
Jamie Madille8fb6402017-02-14 17:56:40 -05004904void Context::renderbufferStorage(GLenum target,
4905 GLenum internalformat,
4906 GLsizei width,
4907 GLsizei height)
4908{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004909 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4910 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
4911
Jamie Madille8fb6402017-02-14 17:56:40 -05004912 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04004913 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004914}
4915
4916void Context::renderbufferStorageMultisample(GLenum target,
4917 GLsizei samples,
4918 GLenum internalformat,
4919 GLsizei width,
4920 GLsizei height)
4921{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004922 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4923 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05004924
4925 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004926 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04004927 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004928}
4929
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004930void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
4931{
Jamie Madill70b5bb02017-08-28 13:32:37 -04004932 const Sync *syncObject = getSync(sync);
Geoff Lang82483b92017-04-11 15:33:00 -04004933 handleError(QuerySynciv(syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004934}
4935
JiangYizhoue18e6392017-02-20 10:32:23 +08004936void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
4937{
4938 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4939 QueryFramebufferParameteriv(framebuffer, pname, params);
4940}
4941
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07004942void Context::getFramebufferParameterivRobust(GLenum target,
4943 GLenum pname,
4944 GLsizei bufSize,
4945 GLsizei *length,
4946 GLint *params)
4947{
4948 UNIMPLEMENTED();
4949}
4950
Jiajia Qin5451d532017-11-16 17:16:34 +08004951void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08004952{
4953 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4954 SetFramebufferParameteri(framebuffer, pname, param);
4955}
4956
Jamie Madillb3f26b92017-07-19 15:07:41 -04004957Error Context::getScratchBuffer(size_t requstedSizeBytes,
4958 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05004959{
Jamie Madillb3f26b92017-07-19 15:07:41 -04004960 if (!mScratchBuffer.get(requstedSizeBytes, scratchBufferOut))
4961 {
4962 return OutOfMemory() << "Failed to allocate internal buffer.";
4963 }
4964 return NoError();
4965}
4966
4967Error Context::getZeroFilledBuffer(size_t requstedSizeBytes,
4968 angle::MemoryBuffer **zeroBufferOut) const
4969{
4970 if (!mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0))
Jamie Madille14951e2017-03-09 18:55:16 -05004971 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004972 return OutOfMemory() << "Failed to allocate internal buffer.";
Jamie Madille14951e2017-03-09 18:55:16 -05004973 }
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004974 return NoError();
Jamie Madille14951e2017-03-09 18:55:16 -05004975}
4976
Xinghua Cao10a4d432017-11-28 14:46:26 +08004977Error Context::prepareForDispatch()
4978{
Geoff Langa8cb2872018-03-09 16:09:40 -05004979 ANGLE_TRY(syncState(mComputeDirtyBits, mComputeDirtyObjects));
Xinghua Cao10a4d432017-11-28 14:46:26 +08004980
4981 if (isRobustResourceInitEnabled())
4982 {
4983 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
4984 }
4985
4986 return NoError();
4987}
4988
Xinghua Cao2b396592017-03-29 15:36:04 +08004989void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
4990{
4991 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
4992 {
4993 return;
4994 }
4995
Xinghua Cao10a4d432017-11-28 14:46:26 +08004996 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill71c88b32017-09-14 22:20:29 -04004997 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08004998}
4999
Jiajia Qin5451d532017-11-16 17:16:34 +08005000void Context::dispatchComputeIndirect(GLintptr indirect)
5001{
Qin Jiajia62fcf622017-11-30 16:16:12 +08005002 ANGLE_CONTEXT_TRY(prepareForDispatch());
5003 handleError(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08005004}
5005
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005006void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005007 GLsizei levels,
5008 GLenum internalFormat,
5009 GLsizei width,
5010 GLsizei height)
5011{
5012 Extents size(width, height, 1);
5013 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005014 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005015}
5016
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005017void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005018 GLsizei levels,
5019 GLenum internalFormat,
5020 GLsizei width,
5021 GLsizei height,
5022 GLsizei depth)
5023{
5024 Extents size(width, height, depth);
5025 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005026 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005027}
5028
Jiajia Qin5451d532017-11-16 17:16:34 +08005029void Context::memoryBarrier(GLbitfield barriers)
5030{
Xinghua Cao89c422a2017-11-29 18:24:20 +08005031 handleError(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005032}
5033
5034void Context::memoryBarrierByRegion(GLbitfield barriers)
5035{
Xinghua Cao89c422a2017-11-29 18:24:20 +08005036 handleError(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005037}
5038
Jamie Madillc1d770e2017-04-13 17:31:24 -04005039GLenum Context::checkFramebufferStatus(GLenum target)
5040{
5041 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5042 ASSERT(framebuffer);
Jamie Madill427064d2018-04-13 16:20:34 -04005043 return framebuffer->checkStatus(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005044}
5045
5046void Context::compileShader(GLuint shader)
5047{
5048 Shader *shaderObject = GetValidShader(this, shader);
5049 if (!shaderObject)
5050 {
5051 return;
5052 }
5053 shaderObject->compile(this);
5054}
5055
5056void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
5057{
5058 for (int i = 0; i < n; i++)
5059 {
5060 deleteBuffer(buffers[i]);
5061 }
5062}
5063
5064void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
5065{
5066 for (int i = 0; i < n; i++)
5067 {
5068 if (framebuffers[i] != 0)
5069 {
5070 deleteFramebuffer(framebuffers[i]);
5071 }
5072 }
5073}
5074
5075void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
5076{
5077 for (int i = 0; i < n; i++)
5078 {
5079 deleteRenderbuffer(renderbuffers[i]);
5080 }
5081}
5082
5083void Context::deleteTextures(GLsizei n, const GLuint *textures)
5084{
5085 for (int i = 0; i < n; i++)
5086 {
5087 if (textures[i] != 0)
5088 {
5089 deleteTexture(textures[i]);
5090 }
5091 }
5092}
5093
5094void Context::detachShader(GLuint program, GLuint shader)
5095{
5096 Program *programObject = getProgram(program);
5097 ASSERT(programObject);
5098
5099 Shader *shaderObject = getShader(shader);
5100 ASSERT(shaderObject);
5101
5102 programObject->detachShader(this, shaderObject);
5103}
5104
5105void Context::genBuffers(GLsizei n, GLuint *buffers)
5106{
5107 for (int i = 0; i < n; i++)
5108 {
5109 buffers[i] = createBuffer();
5110 }
5111}
5112
5113void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
5114{
5115 for (int i = 0; i < n; i++)
5116 {
5117 framebuffers[i] = createFramebuffer();
5118 }
5119}
5120
5121void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
5122{
5123 for (int i = 0; i < n; i++)
5124 {
5125 renderbuffers[i] = createRenderbuffer();
5126 }
5127}
5128
5129void Context::genTextures(GLsizei n, GLuint *textures)
5130{
5131 for (int i = 0; i < n; i++)
5132 {
5133 textures[i] = createTexture();
5134 }
5135}
5136
5137void Context::getActiveAttrib(GLuint program,
5138 GLuint index,
5139 GLsizei bufsize,
5140 GLsizei *length,
5141 GLint *size,
5142 GLenum *type,
5143 GLchar *name)
5144{
5145 Program *programObject = getProgram(program);
5146 ASSERT(programObject);
5147 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
5148}
5149
5150void Context::getActiveUniform(GLuint program,
5151 GLuint index,
5152 GLsizei bufsize,
5153 GLsizei *length,
5154 GLint *size,
5155 GLenum *type,
5156 GLchar *name)
5157{
5158 Program *programObject = getProgram(program);
5159 ASSERT(programObject);
5160 programObject->getActiveUniform(index, bufsize, length, size, type, name);
5161}
5162
5163void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
5164{
5165 Program *programObject = getProgram(program);
5166 ASSERT(programObject);
5167 programObject->getAttachedShaders(maxcount, count, shaders);
5168}
5169
5170GLint Context::getAttribLocation(GLuint program, const GLchar *name)
5171{
5172 Program *programObject = getProgram(program);
5173 ASSERT(programObject);
5174 return programObject->getAttributeLocation(name);
5175}
5176
5177void Context::getBooleanv(GLenum pname, GLboolean *params)
5178{
5179 GLenum nativeType;
5180 unsigned int numParams = 0;
5181 getQueryParameterInfo(pname, &nativeType, &numParams);
5182
5183 if (nativeType == GL_BOOL)
5184 {
5185 getBooleanvImpl(pname, params);
5186 }
5187 else
5188 {
5189 CastStateValues(this, nativeType, pname, numParams, params);
5190 }
5191}
5192
Brandon Jones59770802018-04-02 13:18:42 -07005193void Context::getBooleanvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLboolean *params)
5194{
5195 getBooleanv(pname, params);
5196}
5197
Jamie Madillc1d770e2017-04-13 17:31:24 -04005198void Context::getFloatv(GLenum pname, GLfloat *params)
5199{
5200 GLenum nativeType;
5201 unsigned int numParams = 0;
5202 getQueryParameterInfo(pname, &nativeType, &numParams);
5203
5204 if (nativeType == GL_FLOAT)
5205 {
5206 getFloatvImpl(pname, params);
5207 }
5208 else
5209 {
5210 CastStateValues(this, nativeType, pname, numParams, params);
5211 }
5212}
5213
Brandon Jones59770802018-04-02 13:18:42 -07005214void Context::getFloatvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLfloat *params)
5215{
5216 getFloatv(pname, params);
5217}
5218
Jamie Madillc1d770e2017-04-13 17:31:24 -04005219void Context::getIntegerv(GLenum pname, GLint *params)
5220{
5221 GLenum nativeType;
5222 unsigned int numParams = 0;
5223 getQueryParameterInfo(pname, &nativeType, &numParams);
5224
5225 if (nativeType == GL_INT)
5226 {
5227 getIntegervImpl(pname, params);
5228 }
5229 else
5230 {
5231 CastStateValues(this, nativeType, pname, numParams, params);
5232 }
5233}
5234
Brandon Jones59770802018-04-02 13:18:42 -07005235void Context::getIntegervRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint *data)
5236{
5237 getIntegerv(pname, data);
5238}
5239
Jamie Madillc1d770e2017-04-13 17:31:24 -04005240void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
5241{
5242 Program *programObject = getProgram(program);
5243 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04005244 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005245}
5246
Brandon Jones59770802018-04-02 13:18:42 -07005247void Context::getProgramivRobust(GLuint program,
5248 GLenum pname,
5249 GLsizei bufSize,
5250 GLsizei *length,
5251 GLint *params)
5252{
5253 getProgramiv(program, pname, params);
5254}
5255
Jiajia Qin5451d532017-11-16 17:16:34 +08005256void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
5257{
5258 UNIMPLEMENTED();
5259}
5260
Jamie Madillbe849e42017-05-02 15:49:00 -04005261void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005262{
5263 Program *programObject = getProgram(program);
5264 ASSERT(programObject);
5265 programObject->getInfoLog(bufsize, length, infolog);
5266}
5267
Jiajia Qin5451d532017-11-16 17:16:34 +08005268void Context::getProgramPipelineInfoLog(GLuint pipeline,
5269 GLsizei bufSize,
5270 GLsizei *length,
5271 GLchar *infoLog)
5272{
5273 UNIMPLEMENTED();
5274}
5275
Jamie Madillc1d770e2017-04-13 17:31:24 -04005276void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
5277{
5278 Shader *shaderObject = getShader(shader);
5279 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04005280 QueryShaderiv(this, shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005281}
5282
Brandon Jones59770802018-04-02 13:18:42 -07005283void Context::getShaderivRobust(GLuint shader,
5284 GLenum pname,
5285 GLsizei bufSize,
5286 GLsizei *length,
5287 GLint *params)
5288{
5289 getShaderiv(shader, pname, params);
5290}
5291
Jamie Madillc1d770e2017-04-13 17:31:24 -04005292void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
5293{
5294 Shader *shaderObject = getShader(shader);
5295 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04005296 shaderObject->getInfoLog(this, bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005297}
5298
5299void Context::getShaderPrecisionFormat(GLenum shadertype,
5300 GLenum precisiontype,
5301 GLint *range,
5302 GLint *precision)
5303{
5304 // TODO(jmadill): Compute shaders.
5305
5306 switch (shadertype)
5307 {
5308 case GL_VERTEX_SHADER:
5309 switch (precisiontype)
5310 {
5311 case GL_LOW_FLOAT:
5312 mCaps.vertexLowpFloat.get(range, precision);
5313 break;
5314 case GL_MEDIUM_FLOAT:
5315 mCaps.vertexMediumpFloat.get(range, precision);
5316 break;
5317 case GL_HIGH_FLOAT:
5318 mCaps.vertexHighpFloat.get(range, precision);
5319 break;
5320
5321 case GL_LOW_INT:
5322 mCaps.vertexLowpInt.get(range, precision);
5323 break;
5324 case GL_MEDIUM_INT:
5325 mCaps.vertexMediumpInt.get(range, precision);
5326 break;
5327 case GL_HIGH_INT:
5328 mCaps.vertexHighpInt.get(range, precision);
5329 break;
5330
5331 default:
5332 UNREACHABLE();
5333 return;
5334 }
5335 break;
5336
5337 case GL_FRAGMENT_SHADER:
5338 switch (precisiontype)
5339 {
5340 case GL_LOW_FLOAT:
5341 mCaps.fragmentLowpFloat.get(range, precision);
5342 break;
5343 case GL_MEDIUM_FLOAT:
5344 mCaps.fragmentMediumpFloat.get(range, precision);
5345 break;
5346 case GL_HIGH_FLOAT:
5347 mCaps.fragmentHighpFloat.get(range, precision);
5348 break;
5349
5350 case GL_LOW_INT:
5351 mCaps.fragmentLowpInt.get(range, precision);
5352 break;
5353 case GL_MEDIUM_INT:
5354 mCaps.fragmentMediumpInt.get(range, precision);
5355 break;
5356 case GL_HIGH_INT:
5357 mCaps.fragmentHighpInt.get(range, precision);
5358 break;
5359
5360 default:
5361 UNREACHABLE();
5362 return;
5363 }
5364 break;
5365
5366 default:
5367 UNREACHABLE();
5368 return;
5369 }
5370}
5371
5372void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
5373{
5374 Shader *shaderObject = getShader(shader);
5375 ASSERT(shaderObject);
5376 shaderObject->getSource(bufsize, length, source);
5377}
5378
5379void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
5380{
5381 Program *programObject = getProgram(program);
5382 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005383 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005384}
5385
Brandon Jones59770802018-04-02 13:18:42 -07005386void Context::getUniformfvRobust(GLuint program,
5387 GLint location,
5388 GLsizei bufSize,
5389 GLsizei *length,
5390 GLfloat *params)
5391{
5392 getUniformfv(program, location, params);
5393}
5394
Jamie Madillc1d770e2017-04-13 17:31:24 -04005395void Context::getUniformiv(GLuint program, GLint location, GLint *params)
5396{
5397 Program *programObject = getProgram(program);
5398 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005399 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005400}
5401
Brandon Jones59770802018-04-02 13:18:42 -07005402void Context::getUniformivRobust(GLuint program,
5403 GLint location,
5404 GLsizei bufSize,
5405 GLsizei *length,
5406 GLint *params)
5407{
5408 getUniformiv(program, location, params);
5409}
5410
Jamie Madillc1d770e2017-04-13 17:31:24 -04005411GLint Context::getUniformLocation(GLuint program, const GLchar *name)
5412{
5413 Program *programObject = getProgram(program);
5414 ASSERT(programObject);
5415 return programObject->getUniformLocation(name);
5416}
5417
5418GLboolean Context::isBuffer(GLuint buffer)
5419{
5420 if (buffer == 0)
5421 {
5422 return GL_FALSE;
5423 }
5424
5425 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
5426}
5427
5428GLboolean Context::isEnabled(GLenum cap)
5429{
5430 return mGLState.getEnableFeature(cap);
5431}
5432
5433GLboolean Context::isFramebuffer(GLuint framebuffer)
5434{
5435 if (framebuffer == 0)
5436 {
5437 return GL_FALSE;
5438 }
5439
5440 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
5441}
5442
5443GLboolean Context::isProgram(GLuint program)
5444{
5445 if (program == 0)
5446 {
5447 return GL_FALSE;
5448 }
5449
5450 return (getProgram(program) ? GL_TRUE : GL_FALSE);
5451}
5452
5453GLboolean Context::isRenderbuffer(GLuint renderbuffer)
5454{
5455 if (renderbuffer == 0)
5456 {
5457 return GL_FALSE;
5458 }
5459
5460 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
5461}
5462
5463GLboolean Context::isShader(GLuint shader)
5464{
5465 if (shader == 0)
5466 {
5467 return GL_FALSE;
5468 }
5469
5470 return (getShader(shader) ? GL_TRUE : GL_FALSE);
5471}
5472
5473GLboolean Context::isTexture(GLuint texture)
5474{
5475 if (texture == 0)
5476 {
5477 return GL_FALSE;
5478 }
5479
5480 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
5481}
5482
5483void Context::linkProgram(GLuint program)
5484{
5485 Program *programObject = getProgram(program);
5486 ASSERT(programObject);
5487 handleError(programObject->link(this));
Martin Radev0abb7a22017-08-28 15:34:45 +03005488 mGLState.onProgramExecutableChange(programObject);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005489}
5490
5491void Context::releaseShaderCompiler()
5492{
Jamie Madill4928b7c2017-06-20 12:57:39 -04005493 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005494}
5495
5496void Context::shaderBinary(GLsizei n,
5497 const GLuint *shaders,
5498 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04005499 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005500 GLsizei length)
5501{
5502 // No binary shader formats are supported.
5503 UNIMPLEMENTED();
5504}
5505
5506void Context::shaderSource(GLuint shader,
5507 GLsizei count,
5508 const GLchar *const *string,
5509 const GLint *length)
5510{
5511 Shader *shaderObject = getShader(shader);
5512 ASSERT(shaderObject);
5513 shaderObject->setSource(count, string, length);
5514}
5515
5516void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
5517{
5518 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
5519}
5520
5521void Context::stencilMask(GLuint mask)
5522{
5523 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
5524}
5525
5526void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
5527{
5528 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
5529}
5530
5531void Context::uniform1f(GLint location, GLfloat x)
5532{
5533 Program *program = mGLState.getProgram();
5534 program->setUniform1fv(location, 1, &x);
5535}
5536
5537void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
5538{
5539 Program *program = mGLState.getProgram();
5540 program->setUniform1fv(location, count, v);
5541}
5542
5543void Context::uniform1i(GLint location, GLint x)
5544{
5545 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04005546 if (program->setUniform1iv(location, 1, &x) == Program::SetUniformResult::SamplerChanged)
5547 {
5548 mGLState.setObjectDirty(GL_PROGRAM);
5549 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005550}
5551
5552void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
5553{
5554 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04005555 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
5556 {
5557 mGLState.setObjectDirty(GL_PROGRAM);
5558 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005559}
5560
5561void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
5562{
5563 GLfloat xy[2] = {x, y};
5564 Program *program = mGLState.getProgram();
5565 program->setUniform2fv(location, 1, xy);
5566}
5567
5568void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
5569{
5570 Program *program = mGLState.getProgram();
5571 program->setUniform2fv(location, count, v);
5572}
5573
5574void Context::uniform2i(GLint location, GLint x, GLint y)
5575{
5576 GLint xy[2] = {x, y};
5577 Program *program = mGLState.getProgram();
5578 program->setUniform2iv(location, 1, xy);
5579}
5580
5581void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
5582{
5583 Program *program = mGLState.getProgram();
5584 program->setUniform2iv(location, count, v);
5585}
5586
5587void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
5588{
5589 GLfloat xyz[3] = {x, y, z};
5590 Program *program = mGLState.getProgram();
5591 program->setUniform3fv(location, 1, xyz);
5592}
5593
5594void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
5595{
5596 Program *program = mGLState.getProgram();
5597 program->setUniform3fv(location, count, v);
5598}
5599
5600void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
5601{
5602 GLint xyz[3] = {x, y, z};
5603 Program *program = mGLState.getProgram();
5604 program->setUniform3iv(location, 1, xyz);
5605}
5606
5607void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
5608{
5609 Program *program = mGLState.getProgram();
5610 program->setUniform3iv(location, count, v);
5611}
5612
5613void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
5614{
5615 GLfloat xyzw[4] = {x, y, z, w};
5616 Program *program = mGLState.getProgram();
5617 program->setUniform4fv(location, 1, xyzw);
5618}
5619
5620void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
5621{
5622 Program *program = mGLState.getProgram();
5623 program->setUniform4fv(location, count, v);
5624}
5625
5626void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
5627{
5628 GLint xyzw[4] = {x, y, z, w};
5629 Program *program = mGLState.getProgram();
5630 program->setUniform4iv(location, 1, xyzw);
5631}
5632
5633void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
5634{
5635 Program *program = mGLState.getProgram();
5636 program->setUniform4iv(location, count, v);
5637}
5638
5639void Context::uniformMatrix2fv(GLint location,
5640 GLsizei count,
5641 GLboolean transpose,
5642 const GLfloat *value)
5643{
5644 Program *program = mGLState.getProgram();
5645 program->setUniformMatrix2fv(location, count, transpose, value);
5646}
5647
5648void Context::uniformMatrix3fv(GLint location,
5649 GLsizei count,
5650 GLboolean transpose,
5651 const GLfloat *value)
5652{
5653 Program *program = mGLState.getProgram();
5654 program->setUniformMatrix3fv(location, count, transpose, value);
5655}
5656
5657void Context::uniformMatrix4fv(GLint location,
5658 GLsizei count,
5659 GLboolean transpose,
5660 const GLfloat *value)
5661{
5662 Program *program = mGLState.getProgram();
5663 program->setUniformMatrix4fv(location, count, transpose, value);
5664}
5665
5666void Context::validateProgram(GLuint program)
5667{
5668 Program *programObject = getProgram(program);
5669 ASSERT(programObject);
5670 programObject->validate(mCaps);
5671}
5672
Jiajia Qin5451d532017-11-16 17:16:34 +08005673void Context::validateProgramPipeline(GLuint pipeline)
5674{
5675 UNIMPLEMENTED();
5676}
5677
Jamie Madilld04908b2017-06-09 14:15:35 -04005678void Context::getProgramBinary(GLuint program,
5679 GLsizei bufSize,
5680 GLsizei *length,
5681 GLenum *binaryFormat,
5682 void *binary)
5683{
5684 Program *programObject = getProgram(program);
5685 ASSERT(programObject != nullptr);
5686
5687 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
5688}
5689
5690void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
5691{
5692 Program *programObject = getProgram(program);
5693 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04005694
Jamie Madilld04908b2017-06-09 14:15:35 -04005695 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
5696}
5697
Jamie Madillff325f12017-08-26 15:06:05 -04005698void Context::uniform1ui(GLint location, GLuint v0)
5699{
5700 Program *program = mGLState.getProgram();
5701 program->setUniform1uiv(location, 1, &v0);
5702}
5703
5704void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
5705{
5706 Program *program = mGLState.getProgram();
5707 const GLuint xy[] = {v0, v1};
5708 program->setUniform2uiv(location, 1, xy);
5709}
5710
5711void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
5712{
5713 Program *program = mGLState.getProgram();
5714 const GLuint xyz[] = {v0, v1, v2};
5715 program->setUniform3uiv(location, 1, xyz);
5716}
5717
5718void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
5719{
5720 Program *program = mGLState.getProgram();
5721 const GLuint xyzw[] = {v0, v1, v2, v3};
5722 program->setUniform4uiv(location, 1, xyzw);
5723}
5724
5725void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
5726{
5727 Program *program = mGLState.getProgram();
5728 program->setUniform1uiv(location, count, value);
5729}
5730void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
5731{
5732 Program *program = mGLState.getProgram();
5733 program->setUniform2uiv(location, count, value);
5734}
5735
5736void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
5737{
5738 Program *program = mGLState.getProgram();
5739 program->setUniform3uiv(location, count, value);
5740}
5741
5742void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
5743{
5744 Program *program = mGLState.getProgram();
5745 program->setUniform4uiv(location, count, value);
5746}
5747
Jamie Madillf0e04492017-08-26 15:28:42 -04005748void Context::genQueries(GLsizei n, GLuint *ids)
5749{
5750 for (GLsizei i = 0; i < n; i++)
5751 {
5752 GLuint handle = mQueryHandleAllocator.allocate();
5753 mQueryMap.assign(handle, nullptr);
5754 ids[i] = handle;
5755 }
5756}
5757
5758void Context::deleteQueries(GLsizei n, const GLuint *ids)
5759{
5760 for (int i = 0; i < n; i++)
5761 {
5762 GLuint query = ids[i];
5763
5764 Query *queryObject = nullptr;
5765 if (mQueryMap.erase(query, &queryObject))
5766 {
5767 mQueryHandleAllocator.release(query);
5768 if (queryObject)
5769 {
5770 queryObject->release(this);
5771 }
5772 }
5773 }
5774}
5775
5776GLboolean Context::isQuery(GLuint id)
5777{
Corentin Wallezad3ae902018-03-09 13:40:42 -05005778 return (getQuery(id, false, QueryType::InvalidEnum) != nullptr) ? GL_TRUE : GL_FALSE;
Jamie Madillf0e04492017-08-26 15:28:42 -04005779}
5780
Jamie Madillc8c95812017-08-26 18:40:09 -04005781void Context::uniformMatrix2x3fv(GLint location,
5782 GLsizei count,
5783 GLboolean transpose,
5784 const GLfloat *value)
5785{
5786 Program *program = mGLState.getProgram();
5787 program->setUniformMatrix2x3fv(location, count, transpose, value);
5788}
5789
5790void Context::uniformMatrix3x2fv(GLint location,
5791 GLsizei count,
5792 GLboolean transpose,
5793 const GLfloat *value)
5794{
5795 Program *program = mGLState.getProgram();
5796 program->setUniformMatrix3x2fv(location, count, transpose, value);
5797}
5798
5799void Context::uniformMatrix2x4fv(GLint location,
5800 GLsizei count,
5801 GLboolean transpose,
5802 const GLfloat *value)
5803{
5804 Program *program = mGLState.getProgram();
5805 program->setUniformMatrix2x4fv(location, count, transpose, value);
5806}
5807
5808void Context::uniformMatrix4x2fv(GLint location,
5809 GLsizei count,
5810 GLboolean transpose,
5811 const GLfloat *value)
5812{
5813 Program *program = mGLState.getProgram();
5814 program->setUniformMatrix4x2fv(location, count, transpose, value);
5815}
5816
5817void Context::uniformMatrix3x4fv(GLint location,
5818 GLsizei count,
5819 GLboolean transpose,
5820 const GLfloat *value)
5821{
5822 Program *program = mGLState.getProgram();
5823 program->setUniformMatrix3x4fv(location, count, transpose, value);
5824}
5825
5826void Context::uniformMatrix4x3fv(GLint location,
5827 GLsizei count,
5828 GLboolean transpose,
5829 const GLfloat *value)
5830{
5831 Program *program = mGLState.getProgram();
5832 program->setUniformMatrix4x3fv(location, count, transpose, value);
5833}
5834
Jamie Madilld7576732017-08-26 18:49:50 -04005835void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
5836{
5837 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5838 {
5839 GLuint vertexArray = arrays[arrayIndex];
5840
5841 if (arrays[arrayIndex] != 0)
5842 {
5843 VertexArray *vertexArrayObject = nullptr;
5844 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
5845 {
5846 if (vertexArrayObject != nullptr)
5847 {
5848 detachVertexArray(vertexArray);
5849 vertexArrayObject->onDestroy(this);
5850 }
5851
5852 mVertexArrayHandleAllocator.release(vertexArray);
5853 }
5854 }
5855 }
5856}
5857
5858void Context::genVertexArrays(GLsizei n, GLuint *arrays)
5859{
5860 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5861 {
5862 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
5863 mVertexArrayMap.assign(vertexArray, nullptr);
5864 arrays[arrayIndex] = vertexArray;
5865 }
5866}
5867
5868bool Context::isVertexArray(GLuint array)
5869{
5870 if (array == 0)
5871 {
5872 return GL_FALSE;
5873 }
5874
5875 VertexArray *vao = getVertexArray(array);
5876 return (vao != nullptr ? GL_TRUE : GL_FALSE);
5877}
5878
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04005879void Context::endTransformFeedback()
5880{
5881 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5882 transformFeedback->end(this);
5883}
5884
5885void Context::transformFeedbackVaryings(GLuint program,
5886 GLsizei count,
5887 const GLchar *const *varyings,
5888 GLenum bufferMode)
5889{
5890 Program *programObject = getProgram(program);
5891 ASSERT(programObject);
5892 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
5893}
5894
5895void Context::getTransformFeedbackVarying(GLuint program,
5896 GLuint index,
5897 GLsizei bufSize,
5898 GLsizei *length,
5899 GLsizei *size,
5900 GLenum *type,
5901 GLchar *name)
5902{
5903 Program *programObject = getProgram(program);
5904 ASSERT(programObject);
5905 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
5906}
5907
5908void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
5909{
5910 for (int i = 0; i < n; i++)
5911 {
5912 GLuint transformFeedback = ids[i];
5913 if (transformFeedback == 0)
5914 {
5915 continue;
5916 }
5917
5918 TransformFeedback *transformFeedbackObject = nullptr;
5919 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
5920 {
5921 if (transformFeedbackObject != nullptr)
5922 {
5923 detachTransformFeedback(transformFeedback);
5924 transformFeedbackObject->release(this);
5925 }
5926
5927 mTransformFeedbackHandleAllocator.release(transformFeedback);
5928 }
5929 }
5930}
5931
5932void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
5933{
5934 for (int i = 0; i < n; i++)
5935 {
5936 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
5937 mTransformFeedbackMap.assign(transformFeedback, nullptr);
5938 ids[i] = transformFeedback;
5939 }
5940}
5941
5942bool Context::isTransformFeedback(GLuint id)
5943{
5944 if (id == 0)
5945 {
5946 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
5947 // returns FALSE
5948 return GL_FALSE;
5949 }
5950
5951 const TransformFeedback *transformFeedback = getTransformFeedback(id);
5952 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
5953}
5954
5955void Context::pauseTransformFeedback()
5956{
5957 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5958 transformFeedback->pause();
5959}
5960
5961void Context::resumeTransformFeedback()
5962{
5963 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5964 transformFeedback->resume();
5965}
5966
Jamie Madill12e957f2017-08-26 21:42:26 -04005967void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
5968{
5969 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04005970 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04005971}
5972
Brandon Jones59770802018-04-02 13:18:42 -07005973void Context::getUniformuivRobust(GLuint program,
5974 GLint location,
5975 GLsizei bufSize,
5976 GLsizei *length,
5977 GLuint *params)
5978{
5979 getUniformuiv(program, location, params);
5980}
5981
Jamie Madill12e957f2017-08-26 21:42:26 -04005982GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
5983{
5984 const Program *programObject = getProgram(program);
5985 return programObject->getFragDataLocation(name);
5986}
5987
5988void Context::getUniformIndices(GLuint program,
5989 GLsizei uniformCount,
5990 const GLchar *const *uniformNames,
5991 GLuint *uniformIndices)
5992{
5993 const Program *programObject = getProgram(program);
5994 if (!programObject->isLinked())
5995 {
5996 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5997 {
5998 uniformIndices[uniformId] = GL_INVALID_INDEX;
5999 }
6000 }
6001 else
6002 {
6003 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6004 {
6005 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
6006 }
6007 }
6008}
6009
6010void Context::getActiveUniformsiv(GLuint program,
6011 GLsizei uniformCount,
6012 const GLuint *uniformIndices,
6013 GLenum pname,
6014 GLint *params)
6015{
6016 const Program *programObject = getProgram(program);
6017 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6018 {
6019 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08006020 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04006021 }
6022}
6023
6024GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
6025{
6026 const Program *programObject = getProgram(program);
6027 return programObject->getUniformBlockIndex(uniformBlockName);
6028}
6029
6030void Context::getActiveUniformBlockiv(GLuint program,
6031 GLuint uniformBlockIndex,
6032 GLenum pname,
6033 GLint *params)
6034{
6035 const Program *programObject = getProgram(program);
6036 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
6037}
6038
Brandon Jones59770802018-04-02 13:18:42 -07006039void Context::getActiveUniformBlockivRobust(GLuint program,
6040 GLuint uniformBlockIndex,
6041 GLenum pname,
6042 GLsizei bufSize,
6043 GLsizei *length,
6044 GLint *params)
6045{
6046 getActiveUniformBlockiv(program, uniformBlockIndex, pname, params);
6047}
6048
Jamie Madill12e957f2017-08-26 21:42:26 -04006049void Context::getActiveUniformBlockName(GLuint program,
6050 GLuint uniformBlockIndex,
6051 GLsizei bufSize,
6052 GLsizei *length,
6053 GLchar *uniformBlockName)
6054{
6055 const Program *programObject = getProgram(program);
6056 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
6057}
6058
6059void Context::uniformBlockBinding(GLuint program,
6060 GLuint uniformBlockIndex,
6061 GLuint uniformBlockBinding)
6062{
6063 Program *programObject = getProgram(program);
6064 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
6065}
6066
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006067GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
6068{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006069 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
6070 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006071
Jamie Madill70b5bb02017-08-28 13:32:37 -04006072 Sync *syncObject = getSync(syncHandle);
6073 Error error = syncObject->set(condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006074 if (error.isError())
6075 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04006076 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006077 handleError(error);
6078 return nullptr;
6079 }
6080
Jamie Madill70b5bb02017-08-28 13:32:37 -04006081 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006082}
6083
6084GLboolean Context::isSync(GLsync sync)
6085{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006086 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006087}
6088
6089GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6090{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006091 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006092
6093 GLenum result = GL_WAIT_FAILED;
6094 handleError(syncObject->clientWait(flags, timeout, &result));
6095 return result;
6096}
6097
6098void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6099{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006100 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006101 handleError(syncObject->serverWait(flags, timeout));
6102}
6103
6104void Context::getInteger64v(GLenum pname, GLint64 *params)
6105{
6106 GLenum nativeType = GL_NONE;
6107 unsigned int numParams = 0;
6108 getQueryParameterInfo(pname, &nativeType, &numParams);
6109
6110 if (nativeType == GL_INT_64_ANGLEX)
6111 {
6112 getInteger64vImpl(pname, params);
6113 }
6114 else
6115 {
6116 CastStateValues(this, nativeType, pname, numParams, params);
6117 }
6118}
6119
Brandon Jones59770802018-04-02 13:18:42 -07006120void Context::getInteger64vRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint64 *data)
6121{
6122 getInteger64v(pname, data);
6123}
6124
Corentin Wallez336129f2017-10-17 15:55:40 -04006125void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04006126{
6127 Buffer *buffer = mGLState.getTargetBuffer(target);
6128 QueryBufferParameteri64v(buffer, pname, params);
6129}
6130
Brandon Jones59770802018-04-02 13:18:42 -07006131void Context::getBufferParameteri64vRobust(BufferBinding target,
6132 GLenum pname,
6133 GLsizei bufSize,
6134 GLsizei *length,
6135 GLint64 *params)
6136{
6137 getBufferParameteri64v(target, pname, params);
6138}
6139
Jamie Madill3ef140a2017-08-26 23:11:21 -04006140void Context::genSamplers(GLsizei count, GLuint *samplers)
6141{
6142 for (int i = 0; i < count; i++)
6143 {
6144 samplers[i] = mState.mSamplers->createSampler();
6145 }
6146}
6147
6148void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
6149{
6150 for (int i = 0; i < count; i++)
6151 {
6152 GLuint sampler = samplers[i];
6153
6154 if (mState.mSamplers->getSampler(sampler))
6155 {
6156 detachSampler(sampler);
6157 }
6158
6159 mState.mSamplers->deleteObject(this, sampler);
6160 }
6161}
6162
6163void Context::getInternalformativ(GLenum target,
6164 GLenum internalformat,
6165 GLenum pname,
6166 GLsizei bufSize,
6167 GLint *params)
6168{
6169 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
6170 QueryInternalFormativ(formatCaps, pname, bufSize, params);
6171}
6172
Brandon Jones59770802018-04-02 13:18:42 -07006173void Context::getInternalformativRobust(GLenum target,
6174 GLenum internalformat,
6175 GLenum pname,
6176 GLsizei bufSize,
6177 GLsizei *length,
6178 GLint *params)
6179{
6180 getInternalformativ(target, internalformat, pname, bufSize, params);
6181}
6182
Jiajia Qin5451d532017-11-16 17:16:34 +08006183void Context::programUniform1i(GLuint program, GLint location, GLint v0)
6184{
6185 programUniform1iv(program, location, 1, &v0);
6186}
6187
6188void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
6189{
6190 GLint xy[2] = {v0, v1};
6191 programUniform2iv(program, location, 1, xy);
6192}
6193
6194void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
6195{
6196 GLint xyz[3] = {v0, v1, v2};
6197 programUniform3iv(program, location, 1, xyz);
6198}
6199
6200void Context::programUniform4i(GLuint program,
6201 GLint location,
6202 GLint v0,
6203 GLint v1,
6204 GLint v2,
6205 GLint v3)
6206{
6207 GLint xyzw[4] = {v0, v1, v2, v3};
6208 programUniform4iv(program, location, 1, xyzw);
6209}
6210
6211void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
6212{
6213 programUniform1uiv(program, location, 1, &v0);
6214}
6215
6216void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
6217{
6218 GLuint xy[2] = {v0, v1};
6219 programUniform2uiv(program, location, 1, xy);
6220}
6221
6222void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
6223{
6224 GLuint xyz[3] = {v0, v1, v2};
6225 programUniform3uiv(program, location, 1, xyz);
6226}
6227
6228void Context::programUniform4ui(GLuint program,
6229 GLint location,
6230 GLuint v0,
6231 GLuint v1,
6232 GLuint v2,
6233 GLuint v3)
6234{
6235 GLuint xyzw[4] = {v0, v1, v2, v3};
6236 programUniform4uiv(program, location, 1, xyzw);
6237}
6238
6239void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
6240{
6241 programUniform1fv(program, location, 1, &v0);
6242}
6243
6244void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
6245{
6246 GLfloat xy[2] = {v0, v1};
6247 programUniform2fv(program, location, 1, xy);
6248}
6249
6250void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
6251{
6252 GLfloat xyz[3] = {v0, v1, v2};
6253 programUniform3fv(program, location, 1, xyz);
6254}
6255
6256void Context::programUniform4f(GLuint program,
6257 GLint location,
6258 GLfloat v0,
6259 GLfloat v1,
6260 GLfloat v2,
6261 GLfloat v3)
6262{
6263 GLfloat xyzw[4] = {v0, v1, v2, v3};
6264 programUniform4fv(program, location, 1, xyzw);
6265}
6266
Jamie Madill81c2e252017-09-09 23:32:46 -04006267void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6268{
6269 Program *programObject = getProgram(program);
6270 ASSERT(programObject);
6271 if (programObject->setUniform1iv(location, count, value) ==
6272 Program::SetUniformResult::SamplerChanged)
6273 {
6274 mGLState.setObjectDirty(GL_PROGRAM);
6275 }
6276}
6277
Jiajia Qin5451d532017-11-16 17:16:34 +08006278void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6279{
6280 Program *programObject = getProgram(program);
6281 ASSERT(programObject);
6282 programObject->setUniform2iv(location, count, value);
6283}
6284
6285void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6286{
6287 Program *programObject = getProgram(program);
6288 ASSERT(programObject);
6289 programObject->setUniform3iv(location, count, value);
6290}
6291
6292void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6293{
6294 Program *programObject = getProgram(program);
6295 ASSERT(programObject);
6296 programObject->setUniform4iv(location, count, value);
6297}
6298
6299void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6300{
6301 Program *programObject = getProgram(program);
6302 ASSERT(programObject);
6303 programObject->setUniform1uiv(location, count, value);
6304}
6305
6306void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6307{
6308 Program *programObject = getProgram(program);
6309 ASSERT(programObject);
6310 programObject->setUniform2uiv(location, count, value);
6311}
6312
6313void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6314{
6315 Program *programObject = getProgram(program);
6316 ASSERT(programObject);
6317 programObject->setUniform3uiv(location, count, value);
6318}
6319
6320void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6321{
6322 Program *programObject = getProgram(program);
6323 ASSERT(programObject);
6324 programObject->setUniform4uiv(location, count, value);
6325}
6326
6327void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6328{
6329 Program *programObject = getProgram(program);
6330 ASSERT(programObject);
6331 programObject->setUniform1fv(location, count, value);
6332}
6333
6334void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6335{
6336 Program *programObject = getProgram(program);
6337 ASSERT(programObject);
6338 programObject->setUniform2fv(location, count, value);
6339}
6340
6341void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6342{
6343 Program *programObject = getProgram(program);
6344 ASSERT(programObject);
6345 programObject->setUniform3fv(location, count, value);
6346}
6347
6348void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6349{
6350 Program *programObject = getProgram(program);
6351 ASSERT(programObject);
6352 programObject->setUniform4fv(location, count, value);
6353}
6354
6355void Context::programUniformMatrix2fv(GLuint program,
6356 GLint location,
6357 GLsizei count,
6358 GLboolean transpose,
6359 const GLfloat *value)
6360{
6361 Program *programObject = getProgram(program);
6362 ASSERT(programObject);
6363 programObject->setUniformMatrix2fv(location, count, transpose, value);
6364}
6365
6366void Context::programUniformMatrix3fv(GLuint program,
6367 GLint location,
6368 GLsizei count,
6369 GLboolean transpose,
6370 const GLfloat *value)
6371{
6372 Program *programObject = getProgram(program);
6373 ASSERT(programObject);
6374 programObject->setUniformMatrix3fv(location, count, transpose, value);
6375}
6376
6377void Context::programUniformMatrix4fv(GLuint program,
6378 GLint location,
6379 GLsizei count,
6380 GLboolean transpose,
6381 const GLfloat *value)
6382{
6383 Program *programObject = getProgram(program);
6384 ASSERT(programObject);
6385 programObject->setUniformMatrix4fv(location, count, transpose, value);
6386}
6387
6388void Context::programUniformMatrix2x3fv(GLuint program,
6389 GLint location,
6390 GLsizei count,
6391 GLboolean transpose,
6392 const GLfloat *value)
6393{
6394 Program *programObject = getProgram(program);
6395 ASSERT(programObject);
6396 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
6397}
6398
6399void Context::programUniformMatrix3x2fv(GLuint program,
6400 GLint location,
6401 GLsizei count,
6402 GLboolean transpose,
6403 const GLfloat *value)
6404{
6405 Program *programObject = getProgram(program);
6406 ASSERT(programObject);
6407 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
6408}
6409
6410void Context::programUniformMatrix2x4fv(GLuint program,
6411 GLint location,
6412 GLsizei count,
6413 GLboolean transpose,
6414 const GLfloat *value)
6415{
6416 Program *programObject = getProgram(program);
6417 ASSERT(programObject);
6418 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
6419}
6420
6421void Context::programUniformMatrix4x2fv(GLuint program,
6422 GLint location,
6423 GLsizei count,
6424 GLboolean transpose,
6425 const GLfloat *value)
6426{
6427 Program *programObject = getProgram(program);
6428 ASSERT(programObject);
6429 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
6430}
6431
6432void Context::programUniformMatrix3x4fv(GLuint program,
6433 GLint location,
6434 GLsizei count,
6435 GLboolean transpose,
6436 const GLfloat *value)
6437{
6438 Program *programObject = getProgram(program);
6439 ASSERT(programObject);
6440 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
6441}
6442
6443void Context::programUniformMatrix4x3fv(GLuint program,
6444 GLint location,
6445 GLsizei count,
6446 GLboolean transpose,
6447 const GLfloat *value)
6448{
6449 Program *programObject = getProgram(program);
6450 ASSERT(programObject);
6451 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
6452}
6453
Jamie Madill81c2e252017-09-09 23:32:46 -04006454void Context::onTextureChange(const Texture *texture)
6455{
6456 // Conservatively assume all textures are dirty.
6457 // TODO(jmadill): More fine-grained update.
6458 mGLState.setObjectDirty(GL_TEXTURE);
6459}
6460
James Darpiniane8a93c62018-01-04 18:02:24 -08006461bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
6462{
6463 return mGLState.isCurrentTransformFeedback(tf);
6464}
6465bool Context::isCurrentVertexArray(const VertexArray *va) const
6466{
6467 return mGLState.isCurrentVertexArray(va);
6468}
6469
Yunchao Hea336b902017-08-02 16:05:21 +08006470void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
6471{
6472 for (int i = 0; i < count; i++)
6473 {
6474 pipelines[i] = createProgramPipeline();
6475 }
6476}
6477
6478void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
6479{
6480 for (int i = 0; i < count; i++)
6481 {
6482 if (pipelines[i] != 0)
6483 {
6484 deleteProgramPipeline(pipelines[i]);
6485 }
6486 }
6487}
6488
6489GLboolean Context::isProgramPipeline(GLuint pipeline)
6490{
6491 if (pipeline == 0)
6492 {
6493 return GL_FALSE;
6494 }
6495
6496 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
6497}
6498
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006499void Context::finishFenceNV(GLuint fence)
6500{
6501 FenceNV *fenceObject = getFenceNV(fence);
6502
6503 ASSERT(fenceObject && fenceObject->isSet());
6504 handleError(fenceObject->finish());
6505}
6506
6507void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
6508{
6509 FenceNV *fenceObject = getFenceNV(fence);
6510
6511 ASSERT(fenceObject && fenceObject->isSet());
6512
6513 switch (pname)
6514 {
6515 case GL_FENCE_STATUS_NV:
6516 {
6517 // GL_NV_fence spec:
6518 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
6519 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
6520 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
6521 GLboolean status = GL_TRUE;
6522 if (fenceObject->getStatus() != GL_TRUE)
6523 {
6524 ANGLE_CONTEXT_TRY(fenceObject->test(&status));
6525 }
6526 *params = status;
6527 break;
6528 }
6529
6530 case GL_FENCE_CONDITION_NV:
6531 {
6532 *params = static_cast<GLint>(fenceObject->getCondition());
6533 break;
6534 }
6535
6536 default:
6537 UNREACHABLE();
6538 }
6539}
6540
6541void Context::getTranslatedShaderSource(GLuint shader,
6542 GLsizei bufsize,
6543 GLsizei *length,
6544 GLchar *source)
6545{
6546 Shader *shaderObject = getShader(shader);
6547 ASSERT(shaderObject);
6548 shaderObject->getTranslatedSourceWithDebugInfo(this, bufsize, length, source);
6549}
6550
6551void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
6552{
6553 Program *programObject = getProgram(program);
6554 ASSERT(programObject);
6555
6556 programObject->getUniformfv(this, location, params);
6557}
6558
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006559void Context::getnUniformfvRobust(GLuint program,
6560 GLint location,
6561 GLsizei bufSize,
6562 GLsizei *length,
6563 GLfloat *params)
6564{
6565 UNIMPLEMENTED();
6566}
6567
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006568void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
6569{
6570 Program *programObject = getProgram(program);
6571 ASSERT(programObject);
6572
6573 programObject->getUniformiv(this, location, params);
6574}
6575
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006576void Context::getnUniformivRobust(GLuint program,
6577 GLint location,
6578 GLsizei bufSize,
6579 GLsizei *length,
6580 GLint *params)
6581{
6582 UNIMPLEMENTED();
6583}
6584
6585void Context::getnUniformuivRobust(GLuint program,
6586 GLint location,
6587 GLsizei bufSize,
6588 GLsizei *length,
6589 GLuint *params)
6590{
6591 UNIMPLEMENTED();
6592}
6593
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006594GLboolean Context::isFenceNV(GLuint fence)
6595{
6596 FenceNV *fenceObject = getFenceNV(fence);
6597
6598 if (fenceObject == nullptr)
6599 {
6600 return GL_FALSE;
6601 }
6602
6603 // GL_NV_fence spec:
6604 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
6605 // existing fence.
6606 return fenceObject->isSet();
6607}
6608
6609void Context::readnPixels(GLint x,
6610 GLint y,
6611 GLsizei width,
6612 GLsizei height,
6613 GLenum format,
6614 GLenum type,
6615 GLsizei bufSize,
6616 void *data)
6617{
6618 return readPixels(x, y, width, height, format, type, data);
6619}
6620
Jamie Madill007530e2017-12-28 14:27:04 -05006621void Context::setFenceNV(GLuint fence, GLenum condition)
6622{
6623 ASSERT(condition == GL_ALL_COMPLETED_NV);
6624
6625 FenceNV *fenceObject = getFenceNV(fence);
6626 ASSERT(fenceObject != nullptr);
6627 handleError(fenceObject->set(condition));
6628}
6629
6630GLboolean Context::testFenceNV(GLuint fence)
6631{
6632 FenceNV *fenceObject = getFenceNV(fence);
6633
6634 ASSERT(fenceObject != nullptr);
6635 ASSERT(fenceObject->isSet() == GL_TRUE);
6636
6637 GLboolean result = GL_TRUE;
6638 Error error = fenceObject->test(&result);
6639 if (error.isError())
6640 {
6641 handleError(error);
6642 return GL_TRUE;
6643 }
6644
6645 return result;
6646}
6647
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006648void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006649{
6650 Texture *texture = getTargetTexture(target);
Rafael Cintron05a449a2018-06-20 18:08:04 -07006651 egl::Image *imageObject = static_cast<egl::Image *>(image);
Corentin Wallez99d492c2018-02-27 15:17:10 -05006652 handleError(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05006653}
6654
Jamie Madillfa920eb2018-01-04 11:45:50 -05006655void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006656{
6657 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Rafael Cintron05a449a2018-06-20 18:08:04 -07006658 egl::Image *imageObject = static_cast<egl::Image *>(image);
Jamie Madill007530e2017-12-28 14:27:04 -05006659 handleError(renderbuffer->setStorageEGLImageTarget(this, imageObject));
6660}
6661
Jamie Madillfa920eb2018-01-04 11:45:50 -05006662void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
6663{
6664 UNIMPLEMENTED();
6665}
6666
Jamie Madill5b772312018-03-08 20:28:32 -05006667bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
6668{
6669 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
6670 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
6671 // to the fact that it is stored internally as a float, and so would require conversion
6672 // if returned from Context::getIntegerv. Since this conversion is already implemented
6673 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
6674 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
6675 // application.
6676 switch (pname)
6677 {
6678 case GL_COMPRESSED_TEXTURE_FORMATS:
6679 {
6680 *type = GL_INT;
6681 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
6682 return true;
6683 }
6684 case GL_SHADER_BINARY_FORMATS:
6685 {
6686 *type = GL_INT;
6687 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
6688 return true;
6689 }
6690
6691 case GL_MAX_VERTEX_ATTRIBS:
6692 case GL_MAX_VERTEX_UNIFORM_VECTORS:
6693 case GL_MAX_VARYING_VECTORS:
6694 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
6695 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
6696 case GL_MAX_TEXTURE_IMAGE_UNITS:
6697 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
6698 case GL_MAX_RENDERBUFFER_SIZE:
6699 case GL_NUM_SHADER_BINARY_FORMATS:
6700 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
6701 case GL_ARRAY_BUFFER_BINDING:
6702 case GL_FRAMEBUFFER_BINDING:
6703 case GL_RENDERBUFFER_BINDING:
6704 case GL_CURRENT_PROGRAM:
6705 case GL_PACK_ALIGNMENT:
6706 case GL_UNPACK_ALIGNMENT:
6707 case GL_GENERATE_MIPMAP_HINT:
6708 case GL_RED_BITS:
6709 case GL_GREEN_BITS:
6710 case GL_BLUE_BITS:
6711 case GL_ALPHA_BITS:
6712 case GL_DEPTH_BITS:
6713 case GL_STENCIL_BITS:
6714 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
6715 case GL_CULL_FACE_MODE:
6716 case GL_FRONT_FACE:
6717 case GL_ACTIVE_TEXTURE:
6718 case GL_STENCIL_FUNC:
6719 case GL_STENCIL_VALUE_MASK:
6720 case GL_STENCIL_REF:
6721 case GL_STENCIL_FAIL:
6722 case GL_STENCIL_PASS_DEPTH_FAIL:
6723 case GL_STENCIL_PASS_DEPTH_PASS:
6724 case GL_STENCIL_BACK_FUNC:
6725 case GL_STENCIL_BACK_VALUE_MASK:
6726 case GL_STENCIL_BACK_REF:
6727 case GL_STENCIL_BACK_FAIL:
6728 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
6729 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
6730 case GL_DEPTH_FUNC:
6731 case GL_BLEND_SRC_RGB:
6732 case GL_BLEND_SRC_ALPHA:
6733 case GL_BLEND_DST_RGB:
6734 case GL_BLEND_DST_ALPHA:
6735 case GL_BLEND_EQUATION_RGB:
6736 case GL_BLEND_EQUATION_ALPHA:
6737 case GL_STENCIL_WRITEMASK:
6738 case GL_STENCIL_BACK_WRITEMASK:
6739 case GL_STENCIL_CLEAR_VALUE:
6740 case GL_SUBPIXEL_BITS:
6741 case GL_MAX_TEXTURE_SIZE:
6742 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
6743 case GL_SAMPLE_BUFFERS:
6744 case GL_SAMPLES:
6745 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
6746 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
6747 case GL_TEXTURE_BINDING_2D:
6748 case GL_TEXTURE_BINDING_CUBE_MAP:
6749 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
6750 {
6751 *type = GL_INT;
6752 *numParams = 1;
6753 return true;
6754 }
6755 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6756 {
6757 if (!getExtensions().packReverseRowOrder)
6758 {
6759 return false;
6760 }
6761 *type = GL_INT;
6762 *numParams = 1;
6763 return true;
6764 }
6765 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
6766 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
6767 {
6768 if (!getExtensions().textureRectangle)
6769 {
6770 return false;
6771 }
6772 *type = GL_INT;
6773 *numParams = 1;
6774 return true;
6775 }
6776 case GL_MAX_DRAW_BUFFERS_EXT:
6777 case GL_MAX_COLOR_ATTACHMENTS_EXT:
6778 {
6779 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
6780 {
6781 return false;
6782 }
6783 *type = GL_INT;
6784 *numParams = 1;
6785 return true;
6786 }
6787 case GL_MAX_VIEWPORT_DIMS:
6788 {
6789 *type = GL_INT;
6790 *numParams = 2;
6791 return true;
6792 }
6793 case GL_VIEWPORT:
6794 case GL_SCISSOR_BOX:
6795 {
6796 *type = GL_INT;
6797 *numParams = 4;
6798 return true;
6799 }
6800 case GL_SHADER_COMPILER:
6801 case GL_SAMPLE_COVERAGE_INVERT:
6802 case GL_DEPTH_WRITEMASK:
6803 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
6804 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
6805 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
6806 // bool-natural
6807 case GL_SAMPLE_COVERAGE:
6808 case GL_SCISSOR_TEST:
6809 case GL_STENCIL_TEST:
6810 case GL_DEPTH_TEST:
6811 case GL_BLEND:
6812 case GL_DITHER:
6813 case GL_CONTEXT_ROBUST_ACCESS_EXT:
6814 {
6815 *type = GL_BOOL;
6816 *numParams = 1;
6817 return true;
6818 }
6819 case GL_COLOR_WRITEMASK:
6820 {
6821 *type = GL_BOOL;
6822 *numParams = 4;
6823 return true;
6824 }
6825 case GL_POLYGON_OFFSET_FACTOR:
6826 case GL_POLYGON_OFFSET_UNITS:
6827 case GL_SAMPLE_COVERAGE_VALUE:
6828 case GL_DEPTH_CLEAR_VALUE:
6829 case GL_LINE_WIDTH:
6830 {
6831 *type = GL_FLOAT;
6832 *numParams = 1;
6833 return true;
6834 }
6835 case GL_ALIASED_LINE_WIDTH_RANGE:
6836 case GL_ALIASED_POINT_SIZE_RANGE:
6837 case GL_DEPTH_RANGE:
6838 {
6839 *type = GL_FLOAT;
6840 *numParams = 2;
6841 return true;
6842 }
6843 case GL_COLOR_CLEAR_VALUE:
6844 case GL_BLEND_COLOR:
6845 {
6846 *type = GL_FLOAT;
6847 *numParams = 4;
6848 return true;
6849 }
6850 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
6851 if (!getExtensions().textureFilterAnisotropic)
6852 {
6853 return false;
6854 }
6855 *type = GL_FLOAT;
6856 *numParams = 1;
6857 return true;
6858 case GL_TIMESTAMP_EXT:
6859 if (!getExtensions().disjointTimerQuery)
6860 {
6861 return false;
6862 }
6863 *type = GL_INT_64_ANGLEX;
6864 *numParams = 1;
6865 return true;
6866 case GL_GPU_DISJOINT_EXT:
6867 if (!getExtensions().disjointTimerQuery)
6868 {
6869 return false;
6870 }
6871 *type = GL_INT;
6872 *numParams = 1;
6873 return true;
6874 case GL_COVERAGE_MODULATION_CHROMIUM:
6875 if (!getExtensions().framebufferMixedSamples)
6876 {
6877 return false;
6878 }
6879 *type = GL_INT;
6880 *numParams = 1;
6881 return true;
6882 case GL_TEXTURE_BINDING_EXTERNAL_OES:
6883 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
6884 {
6885 return false;
6886 }
6887 *type = GL_INT;
6888 *numParams = 1;
6889 return true;
6890 }
6891
6892 if (getExtensions().debug)
6893 {
6894 switch (pname)
6895 {
6896 case GL_DEBUG_LOGGED_MESSAGES:
6897 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
6898 case GL_DEBUG_GROUP_STACK_DEPTH:
6899 case GL_MAX_DEBUG_MESSAGE_LENGTH:
6900 case GL_MAX_DEBUG_LOGGED_MESSAGES:
6901 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
6902 case GL_MAX_LABEL_LENGTH:
6903 *type = GL_INT;
6904 *numParams = 1;
6905 return true;
6906
6907 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
6908 case GL_DEBUG_OUTPUT:
6909 *type = GL_BOOL;
6910 *numParams = 1;
6911 return true;
6912 }
6913 }
6914
6915 if (getExtensions().multisampleCompatibility)
6916 {
6917 switch (pname)
6918 {
6919 case GL_MULTISAMPLE_EXT:
6920 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
6921 *type = GL_BOOL;
6922 *numParams = 1;
6923 return true;
6924 }
6925 }
6926
6927 if (getExtensions().pathRendering)
6928 {
6929 switch (pname)
6930 {
6931 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
6932 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
6933 *type = GL_FLOAT;
6934 *numParams = 16;
6935 return true;
6936 }
6937 }
6938
6939 if (getExtensions().bindGeneratesResource)
6940 {
6941 switch (pname)
6942 {
6943 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
6944 *type = GL_BOOL;
6945 *numParams = 1;
6946 return true;
6947 }
6948 }
6949
6950 if (getExtensions().clientArrays)
6951 {
6952 switch (pname)
6953 {
6954 case GL_CLIENT_ARRAYS_ANGLE:
6955 *type = GL_BOOL;
6956 *numParams = 1;
6957 return true;
6958 }
6959 }
6960
6961 if (getExtensions().sRGBWriteControl)
6962 {
6963 switch (pname)
6964 {
6965 case GL_FRAMEBUFFER_SRGB_EXT:
6966 *type = GL_BOOL;
6967 *numParams = 1;
6968 return true;
6969 }
6970 }
6971
6972 if (getExtensions().robustResourceInitialization &&
6973 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
6974 {
6975 *type = GL_BOOL;
6976 *numParams = 1;
6977 return true;
6978 }
6979
6980 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
6981 {
6982 *type = GL_BOOL;
6983 *numParams = 1;
6984 return true;
6985 }
6986
6987 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
6988 switch (pname)
6989 {
6990 // case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE // equivalent to FRAMEBUFFER_BINDING
6991 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
6992 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
6993 {
6994 return false;
6995 }
6996 *type = GL_INT;
6997 *numParams = 1;
6998 return true;
6999
7000 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
7001 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7002 {
7003 return false;
7004 }
7005 *type = GL_INT;
7006 *numParams = 1;
7007 return true;
7008
7009 case GL_PROGRAM_BINARY_FORMATS_OES:
7010 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7011 {
7012 return false;
7013 }
7014 *type = GL_INT;
7015 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
7016 return true;
7017
7018 case GL_PACK_ROW_LENGTH:
7019 case GL_PACK_SKIP_ROWS:
7020 case GL_PACK_SKIP_PIXELS:
7021 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
7022 {
7023 return false;
7024 }
7025 *type = GL_INT;
7026 *numParams = 1;
7027 return true;
7028 case GL_UNPACK_ROW_LENGTH:
7029 case GL_UNPACK_SKIP_ROWS:
7030 case GL_UNPACK_SKIP_PIXELS:
7031 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
7032 {
7033 return false;
7034 }
7035 *type = GL_INT;
7036 *numParams = 1;
7037 return true;
7038 case GL_VERTEX_ARRAY_BINDING:
7039 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
7040 {
7041 return false;
7042 }
7043 *type = GL_INT;
7044 *numParams = 1;
7045 return true;
7046 case GL_PIXEL_PACK_BUFFER_BINDING:
7047 case GL_PIXEL_UNPACK_BUFFER_BINDING:
7048 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
7049 {
7050 return false;
7051 }
7052 *type = GL_INT;
7053 *numParams = 1;
7054 return true;
7055 case GL_MAX_SAMPLES:
7056 {
7057 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
7058 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
7059 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
7060 {
7061 return false;
7062 }
7063 *type = GL_INT;
7064 *numParams = 1;
7065 return true;
7066
7067 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
7068 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
7069 {
7070 return false;
7071 }
7072 *type = GL_INT;
7073 *numParams = 1;
7074 return true;
7075 }
7076 }
7077
7078 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
7079 {
7080 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
7081 {
7082 return false;
7083 }
7084 *type = GL_INT;
7085 *numParams = 1;
7086 return true;
7087 }
7088
7089 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
7090 {
7091 *type = GL_INT;
7092 *numParams = 1;
7093 return true;
7094 }
7095
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007096 if (getClientVersion() < Version(2, 0))
7097 {
7098 switch (pname)
7099 {
7100 case GL_ALPHA_TEST_FUNC:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007101 case GL_CLIENT_ACTIVE_TEXTURE:
7102 case GL_MATRIX_MODE:
7103 case GL_MAX_TEXTURE_UNITS:
7104 case GL_MAX_MODELVIEW_STACK_DEPTH:
7105 case GL_MAX_PROJECTION_STACK_DEPTH:
7106 case GL_MAX_TEXTURE_STACK_DEPTH:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007107 case GL_MAX_LIGHTS:
Lingfeng Yang060088a2018-05-30 20:40:57 -07007108 case GL_MAX_CLIP_PLANES:
Lingfeng Yangabb09f12018-04-16 10:43:53 -07007109 case GL_VERTEX_ARRAY_STRIDE:
7110 case GL_NORMAL_ARRAY_STRIDE:
7111 case GL_COLOR_ARRAY_STRIDE:
7112 case GL_TEXTURE_COORD_ARRAY_STRIDE:
7113 case GL_VERTEX_ARRAY_SIZE:
7114 case GL_COLOR_ARRAY_SIZE:
7115 case GL_TEXTURE_COORD_ARRAY_SIZE:
7116 case GL_VERTEX_ARRAY_TYPE:
7117 case GL_NORMAL_ARRAY_TYPE:
7118 case GL_COLOR_ARRAY_TYPE:
7119 case GL_TEXTURE_COORD_ARRAY_TYPE:
7120 case GL_VERTEX_ARRAY_BUFFER_BINDING:
7121 case GL_NORMAL_ARRAY_BUFFER_BINDING:
7122 case GL_COLOR_ARRAY_BUFFER_BINDING:
7123 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
7124 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
7125 case GL_POINT_SIZE_ARRAY_TYPE_OES:
7126 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
Lingfeng Yanga0cfa872018-05-30 21:12:17 -07007127 case GL_SHADE_MODEL:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007128 *type = GL_INT;
7129 *numParams = 1;
7130 return true;
7131 case GL_ALPHA_TEST_REF:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007132 case GL_FOG_DENSITY:
7133 case GL_FOG_START:
7134 case GL_FOG_END:
7135 case GL_FOG_MODE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007136 case GL_POINT_SIZE:
7137 case GL_POINT_SIZE_MIN:
7138 case GL_POINT_SIZE_MAX:
7139 case GL_POINT_FADE_THRESHOLD_SIZE:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007140 *type = GL_FLOAT;
7141 *numParams = 1;
7142 return true;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007143 case GL_SMOOTH_POINT_SIZE_RANGE:
7144 *type = GL_FLOAT;
7145 *numParams = 2;
7146 return true;
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007147 case GL_CURRENT_COLOR:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007148 case GL_CURRENT_TEXTURE_COORDS:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007149 case GL_LIGHT_MODEL_AMBIENT:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007150 case GL_FOG_COLOR:
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007151 *type = GL_FLOAT;
7152 *numParams = 4;
7153 return true;
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007154 case GL_CURRENT_NORMAL:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007155 case GL_POINT_DISTANCE_ATTENUATION:
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007156 *type = GL_FLOAT;
7157 *numParams = 3;
7158 return true;
Lingfeng Yang3a41af62018-04-09 07:28:56 -07007159 case GL_MODELVIEW_MATRIX:
7160 case GL_PROJECTION_MATRIX:
7161 case GL_TEXTURE_MATRIX:
7162 *type = GL_FLOAT;
7163 *numParams = 16;
7164 return true;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007165 case GL_LIGHT_MODEL_TWO_SIDE:
7166 *type = GL_BOOL;
7167 *numParams = 1;
7168 return true;
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007169 }
7170 }
7171
Jamie Madill5b772312018-03-08 20:28:32 -05007172 if (getClientVersion() < Version(3, 0))
7173 {
7174 return false;
7175 }
7176
7177 // Check for ES3.0+ parameter names
7178 switch (pname)
7179 {
7180 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
7181 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
7182 case GL_UNIFORM_BUFFER_BINDING:
7183 case GL_TRANSFORM_FEEDBACK_BINDING:
7184 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7185 case GL_COPY_READ_BUFFER_BINDING:
7186 case GL_COPY_WRITE_BUFFER_BINDING:
7187 case GL_SAMPLER_BINDING:
7188 case GL_READ_BUFFER:
7189 case GL_TEXTURE_BINDING_3D:
7190 case GL_TEXTURE_BINDING_2D_ARRAY:
7191 case GL_MAX_3D_TEXTURE_SIZE:
7192 case GL_MAX_ARRAY_TEXTURE_LAYERS:
7193 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
7194 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
7195 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
7196 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
7197 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
7198 case GL_MAX_VARYING_COMPONENTS:
7199 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
7200 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
7201 case GL_MIN_PROGRAM_TEXEL_OFFSET:
7202 case GL_MAX_PROGRAM_TEXEL_OFFSET:
7203 case GL_NUM_EXTENSIONS:
7204 case GL_MAJOR_VERSION:
7205 case GL_MINOR_VERSION:
7206 case GL_MAX_ELEMENTS_INDICES:
7207 case GL_MAX_ELEMENTS_VERTICES:
7208 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
7209 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
7210 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
7211 case GL_UNPACK_IMAGE_HEIGHT:
7212 case GL_UNPACK_SKIP_IMAGES:
7213 {
7214 *type = GL_INT;
7215 *numParams = 1;
7216 return true;
7217 }
7218
7219 case GL_MAX_ELEMENT_INDEX:
7220 case GL_MAX_UNIFORM_BLOCK_SIZE:
7221 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
7222 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
7223 case GL_MAX_SERVER_WAIT_TIMEOUT:
7224 {
7225 *type = GL_INT_64_ANGLEX;
7226 *numParams = 1;
7227 return true;
7228 }
7229
7230 case GL_TRANSFORM_FEEDBACK_ACTIVE:
7231 case GL_TRANSFORM_FEEDBACK_PAUSED:
7232 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
7233 case GL_RASTERIZER_DISCARD:
7234 {
7235 *type = GL_BOOL;
7236 *numParams = 1;
7237 return true;
7238 }
7239
7240 case GL_MAX_TEXTURE_LOD_BIAS:
7241 {
7242 *type = GL_FLOAT;
7243 *numParams = 1;
7244 return true;
7245 }
7246 }
7247
7248 if (getExtensions().requestExtension)
7249 {
7250 switch (pname)
7251 {
7252 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
7253 *type = GL_INT;
7254 *numParams = 1;
7255 return true;
7256 }
7257 }
7258
7259 if (getClientVersion() < Version(3, 1))
7260 {
7261 return false;
7262 }
7263
7264 switch (pname)
7265 {
7266 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7267 case GL_DRAW_INDIRECT_BUFFER_BINDING:
7268 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
7269 case GL_MAX_FRAMEBUFFER_WIDTH:
7270 case GL_MAX_FRAMEBUFFER_HEIGHT:
7271 case GL_MAX_FRAMEBUFFER_SAMPLES:
7272 case GL_MAX_SAMPLE_MASK_WORDS:
7273 case GL_MAX_COLOR_TEXTURE_SAMPLES:
7274 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
7275 case GL_MAX_INTEGER_SAMPLES:
7276 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
7277 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
7278 case GL_MAX_VERTEX_ATTRIB_STRIDE:
7279 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
7280 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
7281 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
7282 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
7283 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
7284 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
7285 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
7286 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
7287 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
7288 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
7289 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
7290 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
7291 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
7292 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
7293 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
7294 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
7295 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
7296 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
7297 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
7298 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
7299 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
7300 case GL_MAX_UNIFORM_LOCATIONS:
7301 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
7302 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
7303 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
7304 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
7305 case GL_MAX_IMAGE_UNITS:
7306 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
7307 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
7308 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
7309 case GL_SHADER_STORAGE_BUFFER_BINDING:
7310 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
7311 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
7312 *type = GL_INT;
7313 *numParams = 1;
7314 return true;
7315 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7316 *type = GL_INT_64_ANGLEX;
7317 *numParams = 1;
7318 return true;
7319 case GL_SAMPLE_MASK:
7320 *type = GL_BOOL;
7321 *numParams = 1;
7322 return true;
7323 }
7324
7325 if (getExtensions().geometryShader)
7326 {
7327 switch (pname)
7328 {
7329 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7330 case GL_LAYER_PROVOKING_VERTEX_EXT:
7331 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7332 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7333 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7334 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7335 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7336 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7337 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7338 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7339 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7340 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7341 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7342 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7343 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7344 *type = GL_INT;
7345 *numParams = 1;
7346 return true;
7347 }
7348 }
7349
7350 return false;
7351}
7352
7353bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7354{
7355 if (getClientVersion() < Version(3, 0))
7356 {
7357 return false;
7358 }
7359
7360 switch (target)
7361 {
7362 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7363 case GL_UNIFORM_BUFFER_BINDING:
7364 {
7365 *type = GL_INT;
7366 *numParams = 1;
7367 return true;
7368 }
7369 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7370 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7371 case GL_UNIFORM_BUFFER_START:
7372 case GL_UNIFORM_BUFFER_SIZE:
7373 {
7374 *type = GL_INT_64_ANGLEX;
7375 *numParams = 1;
7376 return true;
7377 }
7378 }
7379
7380 if (getClientVersion() < Version(3, 1))
7381 {
7382 return false;
7383 }
7384
7385 switch (target)
7386 {
7387 case GL_IMAGE_BINDING_LAYERED:
7388 {
7389 *type = GL_BOOL;
7390 *numParams = 1;
7391 return true;
7392 }
7393 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7394 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7395 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7396 case GL_SHADER_STORAGE_BUFFER_BINDING:
7397 case GL_VERTEX_BINDING_BUFFER:
7398 case GL_VERTEX_BINDING_DIVISOR:
7399 case GL_VERTEX_BINDING_OFFSET:
7400 case GL_VERTEX_BINDING_STRIDE:
7401 case GL_SAMPLE_MASK_VALUE:
7402 case GL_IMAGE_BINDING_NAME:
7403 case GL_IMAGE_BINDING_LEVEL:
7404 case GL_IMAGE_BINDING_LAYER:
7405 case GL_IMAGE_BINDING_ACCESS:
7406 case GL_IMAGE_BINDING_FORMAT:
7407 {
7408 *type = GL_INT;
7409 *numParams = 1;
7410 return true;
7411 }
7412 case GL_ATOMIC_COUNTER_BUFFER_START:
7413 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
7414 case GL_SHADER_STORAGE_BUFFER_START:
7415 case GL_SHADER_STORAGE_BUFFER_SIZE:
7416 {
7417 *type = GL_INT_64_ANGLEX;
7418 *numParams = 1;
7419 return true;
7420 }
7421 }
7422
7423 return false;
7424}
7425
7426Program *Context::getProgram(GLuint handle) const
7427{
7428 return mState.mShaderPrograms->getProgram(handle);
7429}
7430
7431Shader *Context::getShader(GLuint handle) const
7432{
7433 return mState.mShaderPrograms->getShader(handle);
7434}
7435
7436bool Context::isTextureGenerated(GLuint texture) const
7437{
7438 return mState.mTextures->isHandleGenerated(texture);
7439}
7440
7441bool Context::isBufferGenerated(GLuint buffer) const
7442{
7443 return mState.mBuffers->isHandleGenerated(buffer);
7444}
7445
7446bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
7447{
7448 return mState.mRenderbuffers->isHandleGenerated(renderbuffer);
7449}
7450
7451bool Context::isFramebufferGenerated(GLuint framebuffer) const
7452{
7453 return mState.mFramebuffers->isHandleGenerated(framebuffer);
7454}
7455
7456bool Context::isProgramPipelineGenerated(GLuint pipeline) const
7457{
7458 return mState.mPipelines->isHandleGenerated(pipeline);
7459}
7460
7461bool Context::usingDisplayTextureShareGroup() const
7462{
7463 return mDisplayTextureShareGroup;
7464}
7465
7466GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
7467{
7468 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
7469 internalformat == GL_DEPTH_STENCIL
7470 ? GL_DEPTH24_STENCIL8
7471 : internalformat;
7472}
7473
Jamie Madillc29968b2016-01-20 11:17:23 -05007474} // namespace gl