blob: a4ef88b51b10d5422ceed77792521dc99342daf2 [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);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400414 mReadPixelsDirtyBits.set(State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500415 mReadPixelsDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
416
417 mClearDirtyBits.set(State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED);
418 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
419 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR);
420 mClearDirtyBits.set(State::DIRTY_BIT_VIEWPORT);
421 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_COLOR);
422 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_DEPTH);
423 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_STENCIL);
424 mClearDirtyBits.set(State::DIRTY_BIT_COLOR_MASK);
425 mClearDirtyBits.set(State::DIRTY_BIT_DEPTH_MASK);
426 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT);
427 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_BACK);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400428 mClearDirtyBits.set(State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500429 mClearDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
430
431 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
432 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR);
Geoff Lang1d2c41d2016-10-19 16:14:46 -0700433 mBlitDirtyBits.set(State::DIRTY_BIT_FRAMEBUFFER_SRGB);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400434 mBlitDirtyBits.set(State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
435 mBlitDirtyBits.set(State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500436 mBlitDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
437 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
Jamie Madill437fa652016-05-03 15:13:24 -0400438
Xinghua Cao10a4d432017-11-28 14:46:26 +0800439 // TODO(xinghua.cao@intel.com): add other dirty bits and dirty objects.
440 mComputeDirtyBits.set(State::DIRTY_BIT_SHADER_STORAGE_BUFFER_BINDING);
441 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_BINDING);
442 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_EXECUTABLE);
443 mComputeDirtyBits.set(State::DIRTY_BIT_TEXTURE_BINDINGS);
444 mComputeDirtyBits.set(State::DIRTY_BIT_SAMPLER_BINDINGS);
Qin Jiajia62fcf622017-11-30 16:16:12 +0800445 mComputeDirtyBits.set(State::DIRTY_BIT_DISPATCH_INDIRECT_BUFFER_BINDING);
Jiajia Qin5ae6ee42018-03-06 17:39:42 +0800446 mComputeDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM_TEXTURES);
Xinghua Cao10a4d432017-11-28 14:46:26 +0800447
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400448 handleError(mImplementation->initialize());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000449}
450
Jamie Madill4928b7c2017-06-20 12:57:39 -0400451egl::Error Context::onDestroy(const egl::Display *display)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000452{
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700453 if (mGLES1Renderer)
454 {
455 mGLES1Renderer->onDestroy(this, &mGLState);
456 }
457
Jamie Madille7b3fe22018-04-05 09:42:46 -0400458 // Delete the Surface first to trigger a finish() in Vulkan.
Jamie Madille7b3fe22018-04-05 09:42:46 -0400459 ANGLE_TRY(releaseSurface(display));
460
Corentin Wallez80b24112015-08-25 16:41:57 -0400461 for (auto fence : mFenceNVMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000462 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400463 SafeDelete(fence.second);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000464 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400465 mFenceNVMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000466
Corentin Wallez80b24112015-08-25 16:41:57 -0400467 for (auto query : mQueryMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000468 {
Geoff Langf0aa8422015-09-29 15:08:34 -0400469 if (query.second != nullptr)
470 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400471 query.second->release(this);
Geoff Langf0aa8422015-09-29 15:08:34 -0400472 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000473 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400474 mQueryMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000475
Corentin Wallez80b24112015-08-25 16:41:57 -0400476 for (auto vertexArray : mVertexArrayMap)
Jamie Madill57a89722013-07-02 11:57:03 -0400477 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400478 if (vertexArray.second)
479 {
480 vertexArray.second->onDestroy(this);
481 }
Jamie Madill57a89722013-07-02 11:57:03 -0400482 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400483 mVertexArrayMap.clear();
Jamie Madill57a89722013-07-02 11:57:03 -0400484
Corentin Wallez80b24112015-08-25 16:41:57 -0400485 for (auto transformFeedback : mTransformFeedbackMap)
Geoff Langc8058452014-02-03 12:04:11 -0500486 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500487 if (transformFeedback.second != nullptr)
488 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500489 transformFeedback.second->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500490 }
Geoff Langc8058452014-02-03 12:04:11 -0500491 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400492 mTransformFeedbackMap.clear();
Geoff Langc8058452014-02-03 12:04:11 -0500493
Jamie Madill5b772312018-03-08 20:28:32 -0500494 for (BindingPointer<Texture> &zeroTexture : mZeroTextures)
Geoff Lang76b10c92014-09-05 16:28:14 -0400495 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800496 if (zeroTexture.get() != nullptr)
497 {
498 ANGLE_TRY(zeroTexture->onDestroy(this));
499 zeroTexture.set(this, nullptr);
500 }
Geoff Lang76b10c92014-09-05 16:28:14 -0400501 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000502
Jamie Madill2f348d22017-06-05 10:50:59 -0400503 releaseShaderCompiler();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500504
Jamie Madill4928b7c2017-06-20 12:57:39 -0400505 mGLState.reset(this);
506
Jamie Madill6c1f6712017-02-14 19:08:04 -0500507 mState.mBuffers->release(this);
508 mState.mShaderPrograms->release(this);
509 mState.mTextures->release(this);
510 mState.mRenderbuffers->release(this);
511 mState.mSamplers->release(this);
Jamie Madill70b5bb02017-08-28 13:32:37 -0400512 mState.mSyncs->release(this);
Jamie Madill6c1f6712017-02-14 19:08:04 -0500513 mState.mPaths->release(this);
514 mState.mFramebuffers->release(this);
Yunchao Hea336b902017-08-02 16:05:21 +0800515 mState.mPipelines->release(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400516
Jamie Madill76e471e2017-10-21 09:56:01 -0400517 mImplementation->onDestroy(this);
518
Jamie Madill4928b7c2017-06-20 12:57:39 -0400519 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000520}
521
Jamie Madill70ee0f62017-02-06 16:04:20 -0500522Context::~Context()
523{
524}
525
Geoff Lang75359662018-04-11 01:42:27 -0400526void Context::setLabel(EGLLabelKHR label)
527{
528 mLabel = label;
529}
530
531EGLLabelKHR Context::getLabel() const
532{
533 return mLabel;
534}
535
Jamie Madill4928b7c2017-06-20 12:57:39 -0400536egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000537{
Jamie Madill61e16b42017-06-19 11:13:23 -0400538 mCurrentDisplay = display;
539
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000540 if (!mHasBeenCurrent)
541 {
Geoff Lang33f11fb2018-05-07 13:42:47 -0400542 initialize();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000543 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500544 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400545 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000546
Corentin Wallezc295e512017-01-27 17:47:50 -0500547 int width = 0;
548 int height = 0;
549 if (surface != nullptr)
550 {
551 width = surface->getWidth();
552 height = surface->getHeight();
553 }
554
555 mGLState.setViewportParams(0, 0, width, height);
556 mGLState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000557
558 mHasBeenCurrent = true;
559 }
560
Jamie Madill1b94d432015-08-07 13:23:23 -0400561 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700562 mGLState.setAllDirtyBits();
Jamie Madill81c2e252017-09-09 23:32:46 -0400563 mGLState.setAllDirtyObjects();
Jamie Madill1b94d432015-08-07 13:23:23 -0400564
Jamie Madill4928b7c2017-06-20 12:57:39 -0400565 ANGLE_TRY(releaseSurface(display));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500566
567 Framebuffer *newDefault = nullptr;
568 if (surface != nullptr)
569 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400570 ANGLE_TRY(surface->setIsCurrent(this, true));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500571 mCurrentSurface = surface;
Geoff Langbf7b95d2018-05-01 16:48:21 -0400572 newDefault = surface->createDefaultFramebuffer(this);
Corentin Wallezccab69d2017-01-27 16:57:15 -0500573 }
574 else
575 {
Geoff Langbf7b95d2018-05-01 16:48:21 -0400576 newDefault = new Framebuffer(mImplementation.get());
Corentin Wallezccab69d2017-01-27 16:57:15 -0500577 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000578
Corentin Wallez37c39792015-08-20 14:19:46 -0400579 // Update default framebuffer, the binding of the previous default
580 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400581 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700582 if (mGLState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400583 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700584 mGLState.setReadFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400585 }
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700586 if (mGLState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400587 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700588 mGLState.setDrawFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400589 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500590 mState.mFramebuffers->setDefaultFramebuffer(newDefault);
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400591 }
Ian Ewell292f0052016-02-04 10:37:32 -0500592
593 // Notify the renderer of a context switch
Jamie Madill4928b7c2017-06-20 12:57:39 -0400594 mImplementation->onMakeCurrent(this);
595 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000596}
597
Jamie Madill4928b7c2017-06-20 12:57:39 -0400598egl::Error Context::releaseSurface(const egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400599{
Geoff Langbf7b95d2018-05-01 16:48:21 -0400600 gl::Framebuffer *defaultFramebuffer = mState.mFramebuffers->getFramebuffer(0);
Corentin Wallez51706ea2015-08-07 14:39:22 -0400601
Geoff Langbf7b95d2018-05-01 16:48:21 -0400602 // Remove the default framebuffer
603 if (mGLState.getReadFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500604 {
605 mGLState.setReadFramebufferBinding(nullptr);
606 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400607
608 if (mGLState.getDrawFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500609 {
610 mGLState.setDrawFramebufferBinding(nullptr);
611 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400612
613 if (defaultFramebuffer)
614 {
615 defaultFramebuffer->onDestroy(this);
616 delete defaultFramebuffer;
617 }
618
Corentin Wallezc295e512017-01-27 17:47:50 -0500619 mState.mFramebuffers->setDefaultFramebuffer(nullptr);
620
621 if (mCurrentSurface)
622 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400623 ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
Corentin Wallezc295e512017-01-27 17:47:50 -0500624 mCurrentSurface = nullptr;
625 }
Jamie Madill4928b7c2017-06-20 12:57:39 -0400626
627 return egl::NoError();
Jamie Madill77a72f62015-04-14 11:18:32 -0400628}
629
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000630GLuint Context::createBuffer()
631{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500632 return mState.mBuffers->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000633}
634
635GLuint Context::createProgram()
636{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500637 return mState.mShaderPrograms->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000638}
639
Jiawei Shao385b3e02018-03-21 09:43:28 +0800640GLuint Context::createShader(ShaderType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000641{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500642 return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000643}
644
645GLuint Context::createTexture()
646{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500647 return mState.mTextures->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000648}
649
650GLuint Context::createRenderbuffer()
651{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500652 return mState.mRenderbuffers->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000653}
654
Brandon Jones59770802018-04-02 13:18:42 -0700655GLuint Context::genPaths(GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300656{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500657 auto resultOrError = mState.mPaths->createPaths(mImplementation.get(), range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300658 if (resultOrError.isError())
659 {
660 handleError(resultOrError.getError());
661 return 0;
662 }
663 return resultOrError.getResult();
664}
665
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000666// Returns an unused framebuffer name
667GLuint Context::createFramebuffer()
668{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500669 return mState.mFramebuffers->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000670}
671
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500672void Context::genFencesNV(GLsizei n, GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000673{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500674 for (int i = 0; i < n; i++)
675 {
676 GLuint handle = mFenceNVHandleAllocator.allocate();
677 mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV()));
678 fences[i] = handle;
679 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000680}
681
Yunchao Hea336b902017-08-02 16:05:21 +0800682GLuint Context::createProgramPipeline()
683{
684 return mState.mPipelines->createProgramPipeline();
685}
686
Jiawei Shao385b3e02018-03-21 09:43:28 +0800687GLuint Context::createShaderProgramv(ShaderType type, GLsizei count, const GLchar *const *strings)
Jiajia Qin5451d532017-11-16 17:16:34 +0800688{
689 UNIMPLEMENTED();
690 return 0u;
691}
692
James Darpinian4d9d4832018-03-13 12:43:28 -0700693void Context::deleteBuffer(GLuint bufferName)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000694{
James Darpinian4d9d4832018-03-13 12:43:28 -0700695 Buffer *buffer = mState.mBuffers->getBuffer(bufferName);
696 if (buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000697 {
698 detachBuffer(buffer);
699 }
Jamie Madill893ab082014-05-16 16:56:10 -0400700
James Darpinian4d9d4832018-03-13 12:43:28 -0700701 mState.mBuffers->deleteObject(this, bufferName);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000702}
703
704void Context::deleteShader(GLuint shader)
705{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500706 mState.mShaderPrograms->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000707}
708
709void Context::deleteProgram(GLuint program)
710{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500711 mState.mShaderPrograms->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000712}
713
714void Context::deleteTexture(GLuint texture)
715{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500716 if (mState.mTextures->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000717 {
718 detachTexture(texture);
719 }
720
Jamie Madill6c1f6712017-02-14 19:08:04 -0500721 mState.mTextures->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000722}
723
724void Context::deleteRenderbuffer(GLuint renderbuffer)
725{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500726 if (mState.mRenderbuffers->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000727 {
728 detachRenderbuffer(renderbuffer);
729 }
Jamie Madill893ab082014-05-16 16:56:10 -0400730
Jamie Madill6c1f6712017-02-14 19:08:04 -0500731 mState.mRenderbuffers->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000732}
733
Jamie Madill7f0c5a42017-08-26 22:43:26 -0400734void Context::deleteSync(GLsync sync)
Jamie Madillcd055f82013-07-26 11:55:15 -0400735{
736 // The spec specifies the underlying Fence object is not deleted until all current
737 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
738 // and since our API is currently designed for being called from a single thread, we can delete
739 // the fence immediately.
Jamie Madill70b5bb02017-08-28 13:32:37 -0400740 mState.mSyncs->deleteObject(this, static_cast<GLuint>(reinterpret_cast<uintptr_t>(sync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400741}
742
Yunchao Hea336b902017-08-02 16:05:21 +0800743void Context::deleteProgramPipeline(GLuint pipeline)
744{
745 if (mState.mPipelines->getProgramPipeline(pipeline))
746 {
747 detachProgramPipeline(pipeline);
748 }
749
750 mState.mPipelines->deleteObject(this, pipeline);
751}
752
Sami Väisänene45e53b2016-05-25 10:36:04 +0300753void Context::deletePaths(GLuint first, GLsizei range)
754{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500755 mState.mPaths->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300756}
757
Brandon Jones59770802018-04-02 13:18:42 -0700758bool Context::isPath(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300759{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500760 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300761 if (pathObj == nullptr)
762 return false;
763
764 return pathObj->hasPathData();
765}
766
Brandon Jones59770802018-04-02 13:18:42 -0700767bool Context::isPathGenerated(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300768{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500769 return mState.mPaths->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300770}
771
Brandon Jones59770802018-04-02 13:18:42 -0700772void Context::pathCommands(GLuint path,
773 GLsizei numCommands,
774 const GLubyte *commands,
775 GLsizei numCoords,
776 GLenum coordType,
777 const void *coords)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300778{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500779 auto *pathObject = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300780
781 handleError(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
782}
783
Jamie Madill007530e2017-12-28 14:27:04 -0500784void Context::pathParameterf(GLuint path, GLenum pname, GLfloat value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300785{
Jamie Madill007530e2017-12-28 14:27:04 -0500786 Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300787
788 switch (pname)
789 {
790 case GL_PATH_STROKE_WIDTH_CHROMIUM:
791 pathObj->setStrokeWidth(value);
792 break;
793 case GL_PATH_END_CAPS_CHROMIUM:
794 pathObj->setEndCaps(static_cast<GLenum>(value));
795 break;
796 case GL_PATH_JOIN_STYLE_CHROMIUM:
797 pathObj->setJoinStyle(static_cast<GLenum>(value));
798 break;
799 case GL_PATH_MITER_LIMIT_CHROMIUM:
800 pathObj->setMiterLimit(value);
801 break;
802 case GL_PATH_STROKE_BOUND_CHROMIUM:
803 pathObj->setStrokeBound(value);
804 break;
805 default:
806 UNREACHABLE();
807 break;
808 }
809}
810
Jamie Madill007530e2017-12-28 14:27:04 -0500811void Context::pathParameteri(GLuint path, GLenum pname, GLint value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300812{
Jamie Madill007530e2017-12-28 14:27:04 -0500813 // TODO(jmadill): Should use proper clamping/casting.
814 pathParameterf(path, pname, static_cast<GLfloat>(value));
815}
816
817void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value)
818{
819 const Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300820
821 switch (pname)
822 {
823 case GL_PATH_STROKE_WIDTH_CHROMIUM:
824 *value = pathObj->getStrokeWidth();
825 break;
826 case GL_PATH_END_CAPS_CHROMIUM:
827 *value = static_cast<GLfloat>(pathObj->getEndCaps());
828 break;
829 case GL_PATH_JOIN_STYLE_CHROMIUM:
830 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
831 break;
832 case GL_PATH_MITER_LIMIT_CHROMIUM:
833 *value = pathObj->getMiterLimit();
834 break;
835 case GL_PATH_STROKE_BOUND_CHROMIUM:
836 *value = pathObj->getStrokeBound();
837 break;
838 default:
839 UNREACHABLE();
840 break;
841 }
842}
843
Jamie Madill007530e2017-12-28 14:27:04 -0500844void Context::getPathParameteriv(GLuint path, GLenum pname, GLint *value)
845{
846 GLfloat val = 0.0f;
847 getPathParameterfv(path, pname, value != nullptr ? &val : nullptr);
848 if (value)
849 *value = static_cast<GLint>(val);
850}
851
Brandon Jones59770802018-04-02 13:18:42 -0700852void Context::pathStencilFunc(GLenum func, GLint ref, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300853{
854 mGLState.setPathStencilFunc(func, ref, mask);
855}
856
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000857void Context::deleteFramebuffer(GLuint framebuffer)
858{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500859 if (mState.mFramebuffers->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000860 {
861 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000862 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500863
Jamie Madill6c1f6712017-02-14 19:08:04 -0500864 mState.mFramebuffers->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000865}
866
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500867void Context::deleteFencesNV(GLsizei n, const GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000868{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500869 for (int i = 0; i < n; i++)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000870 {
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500871 GLuint fence = fences[i];
872
873 FenceNV *fenceObject = nullptr;
874 if (mFenceNVMap.erase(fence, &fenceObject))
875 {
876 mFenceNVHandleAllocator.release(fence);
877 delete fenceObject;
878 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000879 }
880}
881
Geoff Lang70d0f492015-12-10 17:45:46 -0500882Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000883{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500884 return mState.mBuffers->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000885}
886
Jamie Madill570f7c82014-07-03 10:38:54 -0400887Texture *Context::getTexture(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000888{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500889 return mState.mTextures->getTexture(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000890}
891
Geoff Lang70d0f492015-12-10 17:45:46 -0500892Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000893{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500894 return mState.mRenderbuffers->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000895}
896
Jamie Madill70b5bb02017-08-28 13:32:37 -0400897Sync *Context::getSync(GLsync handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400898{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400899 return mState.mSyncs->getSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400900}
901
Jamie Madill57a89722013-07-02 11:57:03 -0400902VertexArray *Context::getVertexArray(GLuint handle) const
903{
Jamie Madill96a483b2017-06-27 16:49:21 -0400904 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -0400905}
906
Jamie Madilldc356042013-07-19 16:36:57 -0400907Sampler *Context::getSampler(GLuint handle) const
908{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500909 return mState.mSamplers->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400910}
911
Geoff Langc8058452014-02-03 12:04:11 -0500912TransformFeedback *Context::getTransformFeedback(GLuint handle) const
913{
Jamie Madill96a483b2017-06-27 16:49:21 -0400914 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -0500915}
916
Yunchao Hea336b902017-08-02 16:05:21 +0800917ProgramPipeline *Context::getProgramPipeline(GLuint handle) const
918{
919 return mState.mPipelines->getProgramPipeline(handle);
920}
921
Geoff Lang75359662018-04-11 01:42:27 -0400922gl::LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
Geoff Lang70d0f492015-12-10 17:45:46 -0500923{
924 switch (identifier)
925 {
926 case GL_BUFFER:
927 return getBuffer(name);
928 case GL_SHADER:
929 return getShader(name);
930 case GL_PROGRAM:
931 return getProgram(name);
932 case GL_VERTEX_ARRAY:
933 return getVertexArray(name);
934 case GL_QUERY:
935 return getQuery(name);
936 case GL_TRANSFORM_FEEDBACK:
937 return getTransformFeedback(name);
938 case GL_SAMPLER:
939 return getSampler(name);
940 case GL_TEXTURE:
941 return getTexture(name);
942 case GL_RENDERBUFFER:
943 return getRenderbuffer(name);
944 case GL_FRAMEBUFFER:
945 return getFramebuffer(name);
946 default:
947 UNREACHABLE();
948 return nullptr;
949 }
950}
951
Geoff Lang75359662018-04-11 01:42:27 -0400952gl::LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
Geoff Lang70d0f492015-12-10 17:45:46 -0500953{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400954 return getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
Geoff Lang70d0f492015-12-10 17:45:46 -0500955}
956
Martin Radev9d901792016-07-15 15:58:58 +0300957void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
958{
Geoff Lang75359662018-04-11 01:42:27 -0400959 gl::LabeledObject *object = getLabeledObject(identifier, name);
Martin Radev9d901792016-07-15 15:58:58 +0300960 ASSERT(object != nullptr);
961
962 std::string labelName = GetObjectLabelFromPointer(length, label);
963 object->setLabel(labelName);
Jamie Madill8693bdb2017-09-02 15:32:14 -0400964
965 // TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the
966 // specified object is active until we do this.
967 mGLState.setObjectDirty(identifier);
Martin Radev9d901792016-07-15 15:58:58 +0300968}
969
970void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
971{
Geoff Lang75359662018-04-11 01:42:27 -0400972 gl::LabeledObject *object = getLabeledObjectFromPtr(ptr);
Martin Radev9d901792016-07-15 15:58:58 +0300973 ASSERT(object != nullptr);
974
975 std::string labelName = GetObjectLabelFromPointer(length, label);
976 object->setLabel(labelName);
977}
978
979void Context::getObjectLabel(GLenum identifier,
980 GLuint name,
981 GLsizei bufSize,
982 GLsizei *length,
983 GLchar *label) const
984{
Geoff Lang75359662018-04-11 01:42:27 -0400985 gl::LabeledObject *object = getLabeledObject(identifier, name);
Martin Radev9d901792016-07-15 15:58:58 +0300986 ASSERT(object != nullptr);
987
988 const std::string &objectLabel = object->getLabel();
989 GetObjectLabelBase(objectLabel, bufSize, length, label);
990}
991
992void Context::getObjectPtrLabel(const void *ptr,
993 GLsizei bufSize,
994 GLsizei *length,
995 GLchar *label) const
996{
Geoff Lang75359662018-04-11 01:42:27 -0400997 gl::LabeledObject *object = getLabeledObjectFromPtr(ptr);
Martin Radev9d901792016-07-15 15:58:58 +0300998 ASSERT(object != nullptr);
999
1000 const std::string &objectLabel = object->getLabel();
1001 GetObjectLabelBase(objectLabel, bufSize, length, label);
1002}
1003
Jamie Madilldc356042013-07-19 16:36:57 -04001004bool Context::isSampler(GLuint samplerName) const
1005{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001006 return mState.mSamplers->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -04001007}
1008
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001009void Context::bindTexture(TextureType target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001010{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001011 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001012
Jamie Madilldedd7b92014-11-05 16:30:36 -05001013 if (handle == 0)
1014 {
1015 texture = mZeroTextures[target].get();
1016 }
1017 else
1018 {
Corentin Wallez99d492c2018-02-27 15:17:10 -05001019 texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -05001020 }
1021
1022 ASSERT(texture);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001023 mGLState.setSamplerTexture(this, target, texture);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00001024}
1025
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001026void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001027{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001028 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1029 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001030 mGLState.setReadFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001031}
1032
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001033void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001034{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001035 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1036 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001037 mGLState.setDrawFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001038}
1039
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001040void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -04001041{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001042 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madill7267aa62018-04-17 15:28:21 -04001043 mGLState.setVertexArrayBinding(this, vertexArray);
Jamie Madill57a89722013-07-02 11:57:03 -04001044}
1045
Shao80957d92017-02-20 21:25:59 +08001046void Context::bindVertexBuffer(GLuint bindingIndex,
1047 GLuint bufferHandle,
1048 GLintptr offset,
1049 GLsizei stride)
1050{
1051 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001052 mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Shao80957d92017-02-20 21:25:59 +08001053}
1054
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001055void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -04001056{
Geoff Lang76b10c92014-09-05 16:28:14 -04001057 ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -04001058 Sampler *sampler =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001059 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001060 mGLState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04001061}
1062
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001063void Context::bindImageTexture(GLuint unit,
1064 GLuint texture,
1065 GLint level,
1066 GLboolean layered,
1067 GLint layer,
1068 GLenum access,
1069 GLenum format)
1070{
1071 Texture *tex = mState.mTextures->getTexture(texture);
1072 mGLState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
1073}
1074
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001075void Context::useProgram(GLuint program)
1076{
Jamie Madill6c1f6712017-02-14 19:08:04 -05001077 mGLState.setProgram(this, getProgram(program));
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001078}
1079
Jiajia Qin5451d532017-11-16 17:16:34 +08001080void Context::useProgramStages(GLuint pipeline, GLbitfield stages, GLuint program)
1081{
1082 UNIMPLEMENTED();
1083}
1084
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001085void Context::bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001086{
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001087 ASSERT(target == GL_TRANSFORM_FEEDBACK);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001088 TransformFeedback *transformFeedback =
1089 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001090 mGLState.setTransformFeedbackBinding(this, transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -05001091}
1092
Yunchao Hea336b902017-08-02 16:05:21 +08001093void Context::bindProgramPipeline(GLuint pipelineHandle)
1094{
1095 ProgramPipeline *pipeline =
1096 mState.mPipelines->checkProgramPipelineAllocation(mImplementation.get(), pipelineHandle);
1097 mGLState.setProgramPipelineBinding(this, pipeline);
1098}
1099
Corentin Wallezad3ae902018-03-09 13:40:42 -05001100void Context::beginQuery(QueryType target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001101{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001102 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001103 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001104
Geoff Lang5aad9672014-09-08 11:10:42 -04001105 // begin query
Jamie Madillf0e04492017-08-26 15:28:42 -04001106 ANGLE_CONTEXT_TRY(queryObject->begin());
Geoff Lang5aad9672014-09-08 11:10:42 -04001107
1108 // set query as active for specified target only if begin succeeded
Jamie Madill4928b7c2017-06-20 12:57:39 -04001109 mGLState.setActiveQuery(this, target, queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001110}
1111
Corentin Wallezad3ae902018-03-09 13:40:42 -05001112void Context::endQuery(QueryType target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001113{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001114 Query *queryObject = mGLState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001115 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001116
Jamie Madillf0e04492017-08-26 15:28:42 -04001117 handleError(queryObject->end());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001118
Geoff Lang5aad9672014-09-08 11:10:42 -04001119 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madill4928b7c2017-06-20 12:57:39 -04001120 mGLState.setActiveQuery(this, target, nullptr);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001121}
1122
Corentin Wallezad3ae902018-03-09 13:40:42 -05001123void Context::queryCounter(GLuint id, QueryType target)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001124{
Corentin Wallezad3ae902018-03-09 13:40:42 -05001125 ASSERT(target == QueryType::Timestamp);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001126
1127 Query *queryObject = getQuery(id, true, target);
1128 ASSERT(queryObject);
1129
Jamie Madillf0e04492017-08-26 15:28:42 -04001130 handleError(queryObject->queryCounter());
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001131}
1132
Corentin Wallezad3ae902018-03-09 13:40:42 -05001133void Context::getQueryiv(QueryType target, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001134{
1135 switch (pname)
1136 {
1137 case GL_CURRENT_QUERY_EXT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001138 params[0] = mGLState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001139 break;
1140 case GL_QUERY_COUNTER_BITS_EXT:
1141 switch (target)
1142 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001143 case QueryType::TimeElapsed:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001144 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1145 break;
Corentin Wallezad3ae902018-03-09 13:40:42 -05001146 case QueryType::Timestamp:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001147 params[0] = getExtensions().queryCounterBitsTimestamp;
1148 break;
1149 default:
1150 UNREACHABLE();
1151 params[0] = 0;
1152 break;
1153 }
1154 break;
1155 default:
1156 UNREACHABLE();
1157 return;
1158 }
1159}
1160
Corentin Wallezad3ae902018-03-09 13:40:42 -05001161void Context::getQueryivRobust(QueryType target,
Brandon Jones59770802018-04-02 13:18:42 -07001162 GLenum pname,
1163 GLsizei bufSize,
1164 GLsizei *length,
1165 GLint *params)
1166{
1167 getQueryiv(target, pname, params);
1168}
1169
Geoff Lang2186c382016-10-14 10:54:54 -04001170void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001171{
Geoff Lang2186c382016-10-14 10:54:54 -04001172 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001173}
1174
Brandon Jones59770802018-04-02 13:18:42 -07001175void Context::getQueryObjectivRobust(GLuint id,
1176 GLenum pname,
1177 GLsizei bufSize,
1178 GLsizei *length,
1179 GLint *params)
1180{
1181 getQueryObjectiv(id, pname, params);
1182}
1183
Geoff Lang2186c382016-10-14 10:54:54 -04001184void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001185{
Geoff Lang2186c382016-10-14 10:54:54 -04001186 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001187}
1188
Brandon Jones59770802018-04-02 13:18:42 -07001189void Context::getQueryObjectuivRobust(GLuint id,
1190 GLenum pname,
1191 GLsizei bufSize,
1192 GLsizei *length,
1193 GLuint *params)
1194{
1195 getQueryObjectuiv(id, pname, params);
1196}
1197
Geoff Lang2186c382016-10-14 10:54:54 -04001198void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001199{
Geoff Lang2186c382016-10-14 10:54:54 -04001200 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001201}
1202
Brandon Jones59770802018-04-02 13:18:42 -07001203void Context::getQueryObjecti64vRobust(GLuint id,
1204 GLenum pname,
1205 GLsizei bufSize,
1206 GLsizei *length,
1207 GLint64 *params)
1208{
1209 getQueryObjecti64v(id, pname, params);
1210}
1211
Geoff Lang2186c382016-10-14 10:54:54 -04001212void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001213{
Geoff Lang2186c382016-10-14 10:54:54 -04001214 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001215}
1216
Brandon Jones59770802018-04-02 13:18:42 -07001217void Context::getQueryObjectui64vRobust(GLuint id,
1218 GLenum pname,
1219 GLsizei bufSize,
1220 GLsizei *length,
1221 GLuint64 *params)
1222{
1223 getQueryObjectui64v(id, pname, params);
1224}
1225
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001226Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001227{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001228 return mState.mFramebuffers->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001229}
1230
Jamie Madill2f348d22017-06-05 10:50:59 -04001231FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001232{
Jamie Madill96a483b2017-06-27 16:49:21 -04001233 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001234}
1235
Corentin Wallezad3ae902018-03-09 13:40:42 -05001236Query *Context::getQuery(GLuint handle, bool create, QueryType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001237{
Jamie Madill96a483b2017-06-27 16:49:21 -04001238 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001239 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001240 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001241 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001242
1243 Query *query = mQueryMap.query(handle);
1244 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001245 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001246 ASSERT(type != QueryType::InvalidEnum);
Jamie Madill96a483b2017-06-27 16:49:21 -04001247 query = new Query(mImplementation->createQuery(type), handle);
1248 query->addRef();
1249 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001250 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001251 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001252}
1253
Geoff Lang70d0f492015-12-10 17:45:46 -05001254Query *Context::getQuery(GLuint handle) const
1255{
Jamie Madill96a483b2017-06-27 16:49:21 -04001256 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001257}
1258
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001259Texture *Context::getTargetTexture(TextureType type) const
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001260{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001261 ASSERT(ValidTextureTarget(this, type) || ValidTextureExternalTarget(this, type));
1262 return mGLState.getTargetTexture(type);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001263}
1264
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001265Texture *Context::getSamplerTexture(unsigned int sampler, TextureType type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001266{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001267 return mGLState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001268}
1269
Geoff Lang492a7e42014-11-05 13:27:06 -05001270Compiler *Context::getCompiler() const
1271{
Jamie Madill2f348d22017-06-05 10:50:59 -04001272 if (mCompiler.get() == nullptr)
1273 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001274 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001275 }
1276 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001277}
1278
Jamie Madillc1d770e2017-04-13 17:31:24 -04001279void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001280{
1281 switch (pname)
1282 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001283 case GL_SHADER_COMPILER:
1284 *params = GL_TRUE;
1285 break;
1286 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1287 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1288 break;
1289 default:
1290 mGLState.getBooleanv(pname, params);
1291 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001292 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001293}
1294
Jamie Madillc1d770e2017-04-13 17:31:24 -04001295void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001296{
Shannon Woods53a94a82014-06-24 15:20:36 -04001297 // Queries about context capabilities and maximums are answered by Context.
1298 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001299 switch (pname)
1300 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001301 case GL_ALIASED_LINE_WIDTH_RANGE:
1302 params[0] = mCaps.minAliasedLineWidth;
1303 params[1] = mCaps.maxAliasedLineWidth;
1304 break;
1305 case GL_ALIASED_POINT_SIZE_RANGE:
1306 params[0] = mCaps.minAliasedPointSize;
1307 params[1] = mCaps.maxAliasedPointSize;
1308 break;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07001309 case GL_SMOOTH_POINT_SIZE_RANGE:
1310 params[0] = mCaps.minSmoothPointSize;
1311 params[1] = mCaps.maxSmoothPointSize;
1312 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001313 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1314 ASSERT(mExtensions.textureFilterAnisotropic);
1315 *params = mExtensions.maxTextureAnisotropy;
1316 break;
1317 case GL_MAX_TEXTURE_LOD_BIAS:
1318 *params = mCaps.maxLODBias;
1319 break;
1320
1321 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1322 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1323 {
Lingfeng Yang3a41af62018-04-09 07:28:56 -07001324 // GLES1 emulation: // GL_PATH_(MODELVIEW|PROJECTION)_MATRIX_CHROMIUM collides with the
1325 // GLES1 constants for modelview/projection matrix.
1326 if (getClientVersion() < Version(2, 0))
1327 {
1328 mGLState.getFloatv(pname, params);
1329 }
1330 else
1331 {
1332 ASSERT(mExtensions.pathRendering);
1333 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1334 memcpy(params, m, 16 * sizeof(GLfloat));
1335 }
Jamie Madill231c7f52017-04-26 13:45:37 -04001336 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001337 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001338
Jamie Madill231c7f52017-04-26 13:45:37 -04001339 default:
1340 mGLState.getFloatv(pname, params);
1341 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001342 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001343}
1344
Jamie Madillc1d770e2017-04-13 17:31:24 -04001345void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001346{
Shannon Woods53a94a82014-06-24 15:20:36 -04001347 // Queries about context capabilities and maximums are answered by Context.
1348 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001349
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001350 switch (pname)
1351 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001352 case GL_MAX_VERTEX_ATTRIBS:
1353 *params = mCaps.maxVertexAttributes;
1354 break;
1355 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1356 *params = mCaps.maxVertexUniformVectors;
1357 break;
1358 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001359 *params = mCaps.maxShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001360 break;
1361 case GL_MAX_VARYING_VECTORS:
1362 *params = mCaps.maxVaryingVectors;
1363 break;
1364 case GL_MAX_VARYING_COMPONENTS:
1365 *params = mCaps.maxVertexOutputComponents;
1366 break;
1367 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1368 *params = mCaps.maxCombinedTextureImageUnits;
1369 break;
1370 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001371 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001372 break;
1373 case GL_MAX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001374 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001375 break;
1376 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1377 *params = mCaps.maxFragmentUniformVectors;
1378 break;
1379 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001380 *params = mCaps.maxShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001381 break;
1382 case GL_MAX_RENDERBUFFER_SIZE:
1383 *params = mCaps.maxRenderbufferSize;
1384 break;
1385 case GL_MAX_COLOR_ATTACHMENTS_EXT:
1386 *params = mCaps.maxColorAttachments;
1387 break;
1388 case GL_MAX_DRAW_BUFFERS_EXT:
1389 *params = mCaps.maxDrawBuffers;
1390 break;
1391 // case GL_FRAMEBUFFER_BINDING: // now equivalent to
1392 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
1393 case GL_SUBPIXEL_BITS:
1394 *params = 4;
1395 break;
1396 case GL_MAX_TEXTURE_SIZE:
1397 *params = mCaps.max2DTextureSize;
1398 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001399 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
1400 *params = mCaps.maxRectangleTextureSize;
1401 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001402 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1403 *params = mCaps.maxCubeMapTextureSize;
1404 break;
1405 case GL_MAX_3D_TEXTURE_SIZE:
1406 *params = mCaps.max3DTextureSize;
1407 break;
1408 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1409 *params = mCaps.maxArrayTextureLayers;
1410 break;
1411 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1412 *params = mCaps.uniformBufferOffsetAlignment;
1413 break;
1414 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1415 *params = mCaps.maxUniformBufferBindings;
1416 break;
1417 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001418 *params = mCaps.maxShaderUniformBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001419 break;
1420 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001421 *params = mCaps.maxShaderUniformBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001422 break;
1423 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1424 *params = mCaps.maxCombinedTextureImageUnits;
1425 break;
1426 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1427 *params = mCaps.maxVertexOutputComponents;
1428 break;
1429 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1430 *params = mCaps.maxFragmentInputComponents;
1431 break;
1432 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1433 *params = mCaps.minProgramTexelOffset;
1434 break;
1435 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1436 *params = mCaps.maxProgramTexelOffset;
1437 break;
1438 case GL_MAJOR_VERSION:
1439 *params = getClientVersion().major;
1440 break;
1441 case GL_MINOR_VERSION:
1442 *params = getClientVersion().minor;
1443 break;
1444 case GL_MAX_ELEMENTS_INDICES:
1445 *params = mCaps.maxElementsIndices;
1446 break;
1447 case GL_MAX_ELEMENTS_VERTICES:
1448 *params = mCaps.maxElementsVertices;
1449 break;
1450 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1451 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1452 break;
1453 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1454 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1455 break;
1456 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1457 *params = mCaps.maxTransformFeedbackSeparateComponents;
1458 break;
1459 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1460 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1461 break;
1462 case GL_MAX_SAMPLES_ANGLE:
1463 *params = mCaps.maxSamples;
1464 break;
1465 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001466 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001467 params[0] = mCaps.maxViewportWidth;
1468 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001469 }
1470 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001471 case GL_COMPRESSED_TEXTURE_FORMATS:
1472 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1473 params);
1474 break;
1475 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1476 *params = mResetStrategy;
1477 break;
1478 case GL_NUM_SHADER_BINARY_FORMATS:
1479 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1480 break;
1481 case GL_SHADER_BINARY_FORMATS:
1482 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1483 break;
1484 case GL_NUM_PROGRAM_BINARY_FORMATS:
1485 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1486 break;
1487 case GL_PROGRAM_BINARY_FORMATS:
1488 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1489 break;
1490 case GL_NUM_EXTENSIONS:
1491 *params = static_cast<GLint>(mExtensionStrings.size());
1492 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001493
Jamie Madill231c7f52017-04-26 13:45:37 -04001494 // GL_KHR_debug
1495 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1496 *params = mExtensions.maxDebugMessageLength;
1497 break;
1498 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1499 *params = mExtensions.maxDebugLoggedMessages;
1500 break;
1501 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1502 *params = mExtensions.maxDebugGroupStackDepth;
1503 break;
1504 case GL_MAX_LABEL_LENGTH:
1505 *params = mExtensions.maxLabelLength;
1506 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001507
Martin Radeve5285d22017-07-14 16:23:53 +03001508 // GL_ANGLE_multiview
1509 case GL_MAX_VIEWS_ANGLE:
1510 *params = mExtensions.maxViews;
1511 break;
1512
Jamie Madill231c7f52017-04-26 13:45:37 -04001513 // GL_EXT_disjoint_timer_query
1514 case GL_GPU_DISJOINT_EXT:
1515 *params = mImplementation->getGPUDisjoint();
1516 break;
1517 case GL_MAX_FRAMEBUFFER_WIDTH:
1518 *params = mCaps.maxFramebufferWidth;
1519 break;
1520 case GL_MAX_FRAMEBUFFER_HEIGHT:
1521 *params = mCaps.maxFramebufferHeight;
1522 break;
1523 case GL_MAX_FRAMEBUFFER_SAMPLES:
1524 *params = mCaps.maxFramebufferSamples;
1525 break;
1526 case GL_MAX_SAMPLE_MASK_WORDS:
1527 *params = mCaps.maxSampleMaskWords;
1528 break;
1529 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1530 *params = mCaps.maxColorTextureSamples;
1531 break;
1532 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1533 *params = mCaps.maxDepthTextureSamples;
1534 break;
1535 case GL_MAX_INTEGER_SAMPLES:
1536 *params = mCaps.maxIntegerSamples;
1537 break;
1538 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1539 *params = mCaps.maxVertexAttribRelativeOffset;
1540 break;
1541 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1542 *params = mCaps.maxVertexAttribBindings;
1543 break;
1544 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1545 *params = mCaps.maxVertexAttribStride;
1546 break;
1547 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001548 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001549 break;
1550 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001551 *params = mCaps.maxShaderAtomicCounters[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001552 break;
1553 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001554 *params = mCaps.maxShaderImageUniforms[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001555 break;
1556 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001557 *params = mCaps.maxShaderStorageBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001558 break;
1559 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001560 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001561 break;
1562 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001563 *params = mCaps.maxShaderAtomicCounters[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001564 break;
1565 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001566 *params = mCaps.maxShaderImageUniforms[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001567 break;
1568 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001569 *params = mCaps.maxShaderStorageBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001570 break;
1571 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1572 *params = mCaps.minProgramTextureGatherOffset;
1573 break;
1574 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1575 *params = mCaps.maxProgramTextureGatherOffset;
1576 break;
1577 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1578 *params = mCaps.maxComputeWorkGroupInvocations;
1579 break;
1580 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001581 *params = mCaps.maxShaderUniformBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001582 break;
1583 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001584 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001585 break;
1586 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1587 *params = mCaps.maxComputeSharedMemorySize;
1588 break;
1589 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001590 *params = mCaps.maxShaderUniformComponents[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001591 break;
1592 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001593 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001594 break;
1595 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001596 *params = mCaps.maxShaderAtomicCounters[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001597 break;
1598 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001599 *params = mCaps.maxShaderImageUniforms[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001600 break;
1601 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001602 *params =
1603 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Compute]);
Jamie Madill231c7f52017-04-26 13:45:37 -04001604 break;
1605 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001606 *params = mCaps.maxShaderStorageBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001607 break;
1608 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1609 *params = mCaps.maxCombinedShaderOutputResources;
1610 break;
1611 case GL_MAX_UNIFORM_LOCATIONS:
1612 *params = mCaps.maxUniformLocations;
1613 break;
1614 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1615 *params = mCaps.maxAtomicCounterBufferBindings;
1616 break;
1617 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1618 *params = mCaps.maxAtomicCounterBufferSize;
1619 break;
1620 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1621 *params = mCaps.maxCombinedAtomicCounterBuffers;
1622 break;
1623 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1624 *params = mCaps.maxCombinedAtomicCounters;
1625 break;
1626 case GL_MAX_IMAGE_UNITS:
1627 *params = mCaps.maxImageUnits;
1628 break;
1629 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1630 *params = mCaps.maxCombinedImageUniforms;
1631 break;
1632 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1633 *params = mCaps.maxShaderStorageBufferBindings;
1634 break;
1635 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1636 *params = mCaps.maxCombinedShaderStorageBlocks;
1637 break;
1638 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1639 *params = mCaps.shaderStorageBufferOffsetAlignment;
1640 break;
Jiawei Shao361df072017-11-22 09:33:59 +08001641
1642 // GL_EXT_geometry_shader
1643 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
1644 *params = mCaps.maxFramebufferLayers;
1645 break;
1646 case GL_LAYER_PROVOKING_VERTEX_EXT:
1647 *params = mCaps.layerProvokingVertex;
1648 break;
1649 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001650 *params = mCaps.maxShaderUniformComponents[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001651 break;
1652 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001653 *params = mCaps.maxShaderUniformBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001654 break;
1655 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001656 *params =
1657 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Geometry]);
Jiawei Shao361df072017-11-22 09:33:59 +08001658 break;
1659 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
1660 *params = mCaps.maxGeometryInputComponents;
1661 break;
1662 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
1663 *params = mCaps.maxGeometryOutputComponents;
1664 break;
1665 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
1666 *params = mCaps.maxGeometryOutputVertices;
1667 break;
1668 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
1669 *params = mCaps.maxGeometryTotalOutputComponents;
1670 break;
1671 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
1672 *params = mCaps.maxGeometryShaderInvocations;
1673 break;
1674 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001675 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001676 break;
1677 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001678 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001679 break;
1680 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001681 *params = mCaps.maxShaderAtomicCounters[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001682 break;
1683 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001684 *params = mCaps.maxShaderImageUniforms[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001685 break;
1686 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001687 *params = mCaps.maxShaderStorageBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001688 break;
Lingfeng Yang96310cd2018-03-28 11:56:28 -07001689 // GLES1 emulation: Caps queries
1690 case GL_MAX_TEXTURE_UNITS:
1691 *params = mCaps.maxMultitextureUnits;
1692 break;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001693 case GL_MAX_MODELVIEW_STACK_DEPTH:
1694 *params = mCaps.maxModelviewMatrixStackDepth;
1695 break;
1696 case GL_MAX_PROJECTION_STACK_DEPTH:
1697 *params = mCaps.maxProjectionMatrixStackDepth;
1698 break;
1699 case GL_MAX_TEXTURE_STACK_DEPTH:
1700 *params = mCaps.maxTextureMatrixStackDepth;
1701 break;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07001702 case GL_MAX_LIGHTS:
1703 *params = mCaps.maxLights;
1704 break;
Lingfeng Yang060088a2018-05-30 20:40:57 -07001705 case GL_MAX_CLIP_PLANES:
1706 *params = mCaps.maxClipPlanes;
1707 break;
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001708 // GLES1 emulation: Vertex attribute queries
1709 case GL_VERTEX_ARRAY_BUFFER_BINDING:
1710 case GL_NORMAL_ARRAY_BUFFER_BINDING:
1711 case GL_COLOR_ARRAY_BUFFER_BINDING:
1712 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
1713 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
1714 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1715 GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, params);
1716 break;
1717 case GL_VERTEX_ARRAY_STRIDE:
1718 case GL_NORMAL_ARRAY_STRIDE:
1719 case GL_COLOR_ARRAY_STRIDE:
1720 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
1721 case GL_TEXTURE_COORD_ARRAY_STRIDE:
1722 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1723 GL_VERTEX_ATTRIB_ARRAY_STRIDE, params);
1724 break;
1725 case GL_VERTEX_ARRAY_SIZE:
1726 case GL_COLOR_ARRAY_SIZE:
1727 case GL_TEXTURE_COORD_ARRAY_SIZE:
1728 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1729 GL_VERTEX_ATTRIB_ARRAY_SIZE, params);
1730 break;
1731 case GL_VERTEX_ARRAY_TYPE:
1732 case GL_COLOR_ARRAY_TYPE:
1733 case GL_NORMAL_ARRAY_TYPE:
1734 case GL_POINT_SIZE_ARRAY_TYPE_OES:
1735 case GL_TEXTURE_COORD_ARRAY_TYPE:
1736 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1737 GL_VERTEX_ATTRIB_ARRAY_TYPE, params);
1738 break;
1739
Jamie Madill231c7f52017-04-26 13:45:37 -04001740 default:
Jamie Madille98b1b52018-03-08 09:47:23 -05001741 handleError(mGLState.getIntegerv(this, pname, params));
Jamie Madill231c7f52017-04-26 13:45:37 -04001742 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001743 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001744}
1745
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001746void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001747{
Shannon Woods53a94a82014-06-24 15:20:36 -04001748 // Queries about context capabilities and maximums are answered by Context.
1749 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001750 switch (pname)
1751 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001752 case GL_MAX_ELEMENT_INDEX:
1753 *params = mCaps.maxElementIndex;
1754 break;
1755 case GL_MAX_UNIFORM_BLOCK_SIZE:
1756 *params = mCaps.maxUniformBlockSize;
1757 break;
1758 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001759 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001760 break;
1761 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001762 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001763 break;
1764 case GL_MAX_SERVER_WAIT_TIMEOUT:
1765 *params = mCaps.maxServerWaitTimeout;
1766 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001767
Jamie Madill231c7f52017-04-26 13:45:37 -04001768 // GL_EXT_disjoint_timer_query
1769 case GL_TIMESTAMP_EXT:
1770 *params = mImplementation->getTimestamp();
1771 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001772
Jamie Madill231c7f52017-04-26 13:45:37 -04001773 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1774 *params = mCaps.maxShaderStorageBlockSize;
1775 break;
1776 default:
1777 UNREACHABLE();
1778 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001779 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001780}
1781
Geoff Lang70d0f492015-12-10 17:45:46 -05001782void Context::getPointerv(GLenum pname, void **params) const
1783{
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001784 mGLState.getPointerv(this, pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001785}
1786
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001787void Context::getPointervRobustANGLERobust(GLenum pname,
1788 GLsizei bufSize,
1789 GLsizei *length,
1790 void **params)
1791{
1792 UNIMPLEMENTED();
1793}
1794
Martin Radev66fb8202016-07-28 11:45:20 +03001795void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001796{
Shannon Woods53a94a82014-06-24 15:20:36 -04001797 // Queries about context capabilities and maximums are answered by Context.
1798 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001799
1800 GLenum nativeType;
1801 unsigned int numParams;
1802 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1803 ASSERT(queryStatus);
1804
1805 if (nativeType == GL_INT)
1806 {
1807 switch (target)
1808 {
1809 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1810 ASSERT(index < 3u);
1811 *data = mCaps.maxComputeWorkGroupCount[index];
1812 break;
1813 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1814 ASSERT(index < 3u);
1815 *data = mCaps.maxComputeWorkGroupSize[index];
1816 break;
1817 default:
1818 mGLState.getIntegeri_v(target, index, data);
1819 }
1820 }
1821 else
1822 {
1823 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1824 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001825}
1826
Brandon Jones59770802018-04-02 13:18:42 -07001827void Context::getIntegeri_vRobust(GLenum target,
1828 GLuint index,
1829 GLsizei bufSize,
1830 GLsizei *length,
1831 GLint *data)
1832{
1833 getIntegeri_v(target, index, data);
1834}
1835
Martin Radev66fb8202016-07-28 11:45:20 +03001836void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001837{
Shannon Woods53a94a82014-06-24 15:20:36 -04001838 // Queries about context capabilities and maximums are answered by Context.
1839 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001840
1841 GLenum nativeType;
1842 unsigned int numParams;
1843 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1844 ASSERT(queryStatus);
1845
1846 if (nativeType == GL_INT_64_ANGLEX)
1847 {
1848 mGLState.getInteger64i_v(target, index, data);
1849 }
1850 else
1851 {
1852 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1853 }
1854}
1855
Brandon Jones59770802018-04-02 13:18:42 -07001856void Context::getInteger64i_vRobust(GLenum target,
1857 GLuint index,
1858 GLsizei bufSize,
1859 GLsizei *length,
1860 GLint64 *data)
1861{
1862 getInteger64i_v(target, index, data);
1863}
1864
Martin Radev66fb8202016-07-28 11:45:20 +03001865void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1866{
1867 // Queries about context capabilities and maximums are answered by Context.
1868 // Queries about current GL state values are answered by State.
1869
1870 GLenum nativeType;
1871 unsigned int numParams;
1872 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1873 ASSERT(queryStatus);
1874
1875 if (nativeType == GL_BOOL)
1876 {
1877 mGLState.getBooleani_v(target, index, data);
1878 }
1879 else
1880 {
1881 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1882 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001883}
1884
Brandon Jones59770802018-04-02 13:18:42 -07001885void Context::getBooleani_vRobust(GLenum target,
1886 GLuint index,
1887 GLsizei bufSize,
1888 GLsizei *length,
1889 GLboolean *data)
1890{
1891 getBooleani_v(target, index, data);
1892}
1893
Corentin Wallez336129f2017-10-17 15:55:40 -04001894void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001895{
1896 Buffer *buffer = mGLState.getTargetBuffer(target);
1897 QueryBufferParameteriv(buffer, pname, params);
1898}
1899
Brandon Jones59770802018-04-02 13:18:42 -07001900void Context::getBufferParameterivRobust(BufferBinding target,
1901 GLenum pname,
1902 GLsizei bufSize,
1903 GLsizei *length,
1904 GLint *params)
1905{
1906 getBufferParameteriv(target, pname, params);
1907}
1908
He Yunchao010e4db2017-03-03 14:22:06 +08001909void Context::getFramebufferAttachmentParameteriv(GLenum target,
1910 GLenum attachment,
1911 GLenum pname,
1912 GLint *params)
1913{
1914 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08001915 QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08001916}
1917
Brandon Jones59770802018-04-02 13:18:42 -07001918void Context::getFramebufferAttachmentParameterivRobust(GLenum target,
1919 GLenum attachment,
1920 GLenum pname,
1921 GLsizei bufSize,
1922 GLsizei *length,
1923 GLint *params)
1924{
1925 getFramebufferAttachmentParameteriv(target, attachment, pname, params);
1926}
1927
He Yunchao010e4db2017-03-03 14:22:06 +08001928void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
1929{
1930 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
1931 QueryRenderbufferiv(this, renderbuffer, pname, params);
1932}
1933
Brandon Jones59770802018-04-02 13:18:42 -07001934void Context::getRenderbufferParameterivRobust(GLenum target,
1935 GLenum pname,
1936 GLsizei bufSize,
1937 GLsizei *length,
1938 GLint *params)
1939{
1940 getRenderbufferParameteriv(target, pname, params);
1941}
1942
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001943void Context::getTexParameterfv(TextureType target, GLenum pname, GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001944{
1945 Texture *texture = getTargetTexture(target);
1946 QueryTexParameterfv(texture, pname, params);
1947}
1948
Brandon Jones59770802018-04-02 13:18:42 -07001949void Context::getTexParameterfvRobust(TextureType target,
1950 GLenum pname,
1951 GLsizei bufSize,
1952 GLsizei *length,
1953 GLfloat *params)
1954{
1955 getTexParameterfv(target, pname, params);
1956}
1957
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001958void Context::getTexParameteriv(TextureType target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001959{
1960 Texture *texture = getTargetTexture(target);
1961 QueryTexParameteriv(texture, pname, params);
1962}
Jiajia Qin5451d532017-11-16 17:16:34 +08001963
Brandon Jones59770802018-04-02 13:18:42 -07001964void Context::getTexParameterivRobust(TextureType target,
1965 GLenum pname,
1966 GLsizei bufSize,
1967 GLsizei *length,
1968 GLint *params)
1969{
1970 getTexParameteriv(target, pname, params);
1971}
1972
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001973void Context::getTexParameterIivRobust(TextureType target,
1974 GLenum pname,
1975 GLsizei bufSize,
1976 GLsizei *length,
1977 GLint *params)
1978{
1979 UNIMPLEMENTED();
1980}
1981
1982void Context::getTexParameterIuivRobust(TextureType target,
1983 GLenum pname,
1984 GLsizei bufSize,
1985 GLsizei *length,
1986 GLuint *params)
1987{
1988 UNIMPLEMENTED();
1989}
1990
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001991void Context::getTexLevelParameteriv(TextureTarget target, GLint level, GLenum pname, GLint *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08001992{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001993 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05001994 QueryTexLevelParameteriv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08001995}
1996
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001997void Context::getTexLevelParameterivRobust(TextureTarget target,
1998 GLint level,
1999 GLenum pname,
2000 GLsizei bufSize,
2001 GLsizei *length,
2002 GLint *params)
2003{
2004 UNIMPLEMENTED();
2005}
2006
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002007void Context::getTexLevelParameterfv(TextureTarget target,
2008 GLint level,
2009 GLenum pname,
2010 GLfloat *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002011{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002012 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002013 QueryTexLevelParameterfv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002014}
2015
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002016void Context::getTexLevelParameterfvRobust(TextureTarget target,
2017 GLint level,
2018 GLenum pname,
2019 GLsizei bufSize,
2020 GLsizei *length,
2021 GLfloat *params)
2022{
2023 UNIMPLEMENTED();
2024}
2025
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002026void Context::texParameterf(TextureType target, GLenum pname, GLfloat param)
He Yunchao010e4db2017-03-03 14:22:06 +08002027{
2028 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002029 SetTexParameterf(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002030 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002031}
2032
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002033void Context::texParameterfv(TextureType target, GLenum pname, const GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002034{
2035 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002036 SetTexParameterfv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002037 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002038}
2039
Brandon Jones59770802018-04-02 13:18:42 -07002040void Context::texParameterfvRobust(TextureType target,
2041 GLenum pname,
2042 GLsizei bufSize,
2043 const GLfloat *params)
2044{
2045 texParameterfv(target, pname, params);
2046}
2047
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002048void Context::texParameteri(TextureType target, GLenum pname, GLint param)
He Yunchao010e4db2017-03-03 14:22:06 +08002049{
2050 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002051 SetTexParameteri(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002052 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002053}
2054
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002055void Context::texParameteriv(TextureType target, GLenum pname, const GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002056{
2057 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002058 SetTexParameteriv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002059 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002060}
2061
Brandon Jones59770802018-04-02 13:18:42 -07002062void Context::texParameterivRobust(TextureType target,
2063 GLenum pname,
2064 GLsizei bufSize,
2065 const GLint *params)
2066{
2067 texParameteriv(target, pname, params);
2068}
2069
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002070void Context::texParameterIivRobust(TextureType target,
2071 GLenum pname,
2072 GLsizei bufSize,
2073 const GLint *params)
2074{
2075 UNIMPLEMENTED();
2076}
2077
2078void Context::texParameterIuivRobust(TextureType target,
2079 GLenum pname,
2080 GLsizei bufSize,
2081 const GLuint *params)
2082{
2083 UNIMPLEMENTED();
2084}
2085
Jamie Madill493f9572018-05-24 19:52:15 -04002086void Context::drawArrays(PrimitiveMode mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002087{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002088 // No-op if zero count
2089 if (count == 0)
2090 {
2091 return;
2092 }
2093
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002094 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002095 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
Jamie Madill09463932018-04-04 05:26:59 -04002096 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count, 1);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002097}
2098
Jamie Madill493f9572018-05-24 19:52:15 -04002099void Context::drawArraysInstanced(PrimitiveMode mode,
2100 GLint first,
2101 GLsizei count,
2102 GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04002103{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002104 // No-op if zero count
2105 if (count == 0 || instanceCount == 0)
2106 {
2107 return;
2108 }
2109
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002110 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002111 ANGLE_CONTEXT_TRY(
2112 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
Jamie Madill09463932018-04-04 05:26:59 -04002113 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count,
2114 instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -04002115}
2116
Jamie Madill493f9572018-05-24 19:52:15 -04002117void Context::drawElements(PrimitiveMode mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002118{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002119 // No-op if zero count
2120 if (count == 0)
2121 {
2122 return;
2123 }
2124
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002125 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002126 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04002127}
2128
Jamie Madill493f9572018-05-24 19:52:15 -04002129void Context::drawElementsInstanced(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002130 GLsizei count,
2131 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002132 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04002133 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04002134{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002135 // No-op if zero count
2136 if (count == 0 || instances == 0)
2137 {
2138 return;
2139 }
2140
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002141 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002142 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08002143 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04002144}
2145
Jamie Madill493f9572018-05-24 19:52:15 -04002146void Context::drawRangeElements(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002147 GLuint start,
2148 GLuint end,
2149 GLsizei count,
2150 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002151 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04002152{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002153 // No-op if zero count
2154 if (count == 0)
2155 {
2156 return;
2157 }
2158
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002159 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002160 ANGLE_CONTEXT_TRY(
2161 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002162}
2163
Jamie Madill493f9572018-05-24 19:52:15 -04002164void Context::drawArraysIndirect(PrimitiveMode mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002165{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002166 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002167 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002168}
2169
Jamie Madill493f9572018-05-24 19:52:15 -04002170void Context::drawElementsIndirect(PrimitiveMode mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002171{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002172 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002173 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002174}
2175
Jamie Madill675fe712016-12-19 13:07:54 -05002176void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002177{
Jamie Madillafa02a22017-11-23 12:57:38 -05002178 handleError(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05002179}
2180
Jamie Madill675fe712016-12-19 13:07:54 -05002181void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05002182{
Jamie Madillafa02a22017-11-23 12:57:38 -05002183 handleError(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002184}
2185
Austin Kinross6ee1e782015-05-29 17:05:37 -07002186void Context::insertEventMarker(GLsizei length, const char *marker)
2187{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002188 ASSERT(mImplementation);
2189 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07002190}
2191
2192void Context::pushGroupMarker(GLsizei length, const char *marker)
2193{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002194 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05002195
2196 if (marker == nullptr)
2197 {
2198 // From the EXT_debug_marker spec,
2199 // "If <marker> is null then an empty string is pushed on the stack."
2200 mImplementation->pushGroupMarker(length, "");
2201 }
2202 else
2203 {
2204 mImplementation->pushGroupMarker(length, marker);
2205 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07002206}
2207
2208void Context::popGroupMarker()
2209{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002210 ASSERT(mImplementation);
2211 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07002212}
2213
Geoff Langd8605522016-04-13 10:19:12 -04002214void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
2215{
2216 Program *programObject = getProgram(program);
2217 ASSERT(programObject);
2218
2219 programObject->bindUniformLocation(location, name);
2220}
2221
Brandon Jones59770802018-04-02 13:18:42 -07002222void Context::coverageModulation(GLenum components)
Sami Väisänena797e062016-05-12 15:23:40 +03002223{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002224 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03002225}
2226
Brandon Jones59770802018-04-02 13:18:42 -07002227void Context::matrixLoadf(GLenum matrixMode, const GLfloat *matrix)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002228{
2229 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
2230}
2231
Brandon Jones59770802018-04-02 13:18:42 -07002232void Context::matrixLoadIdentity(GLenum matrixMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002233{
2234 GLfloat I[16];
2235 angle::Matrix<GLfloat>::setToIdentity(I);
2236
2237 mGLState.loadPathRenderingMatrix(matrixMode, I);
2238}
2239
2240void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
2241{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002242 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002243 if (!pathObj)
2244 return;
2245
2246 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002247 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002248
2249 mImplementation->stencilFillPath(pathObj, fillMode, mask);
2250}
2251
2252void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
2253{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002254 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002255 if (!pathObj)
2256 return;
2257
2258 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002259 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002260
2261 mImplementation->stencilStrokePath(pathObj, reference, mask);
2262}
2263
2264void Context::coverFillPath(GLuint path, GLenum coverMode)
2265{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002266 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002267 if (!pathObj)
2268 return;
2269
2270 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002271 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002272
2273 mImplementation->coverFillPath(pathObj, coverMode);
2274}
2275
2276void Context::coverStrokePath(GLuint path, GLenum coverMode)
2277{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002278 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002279 if (!pathObj)
2280 return;
2281
2282 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002283 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002284
2285 mImplementation->coverStrokePath(pathObj, coverMode);
2286}
2287
2288void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
2289{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002290 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002291 if (!pathObj)
2292 return;
2293
2294 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002295 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002296
2297 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
2298}
2299
2300void Context::stencilThenCoverStrokePath(GLuint path,
2301 GLint reference,
2302 GLuint mask,
2303 GLenum coverMode)
2304{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002305 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002306 if (!pathObj)
2307 return;
2308
2309 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002310 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002311
2312 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2313}
2314
Sami Väisänend59ca052016-06-21 16:10:00 +03002315void Context::coverFillPathInstanced(GLsizei numPaths,
2316 GLenum pathNameType,
2317 const void *paths,
2318 GLuint pathBase,
2319 GLenum coverMode,
2320 GLenum transformType,
2321 const GLfloat *transformValues)
2322{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002323 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002324
2325 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002326 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002327
2328 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2329}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002330
Sami Väisänend59ca052016-06-21 16:10:00 +03002331void Context::coverStrokePathInstanced(GLsizei numPaths,
2332 GLenum pathNameType,
2333 const void *paths,
2334 GLuint pathBase,
2335 GLenum coverMode,
2336 GLenum transformType,
2337 const GLfloat *transformValues)
2338{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002339 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002340
2341 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002342 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002343
2344 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2345 transformValues);
2346}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002347
Sami Väisänend59ca052016-06-21 16:10:00 +03002348void Context::stencilFillPathInstanced(GLsizei numPaths,
2349 GLenum pathNameType,
2350 const void *paths,
2351 GLuint pathBase,
2352 GLenum fillMode,
2353 GLuint mask,
2354 GLenum transformType,
2355 const GLfloat *transformValues)
2356{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002357 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002358
2359 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002360 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002361
2362 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2363 transformValues);
2364}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002365
Sami Väisänend59ca052016-06-21 16:10:00 +03002366void Context::stencilStrokePathInstanced(GLsizei numPaths,
2367 GLenum pathNameType,
2368 const void *paths,
2369 GLuint pathBase,
2370 GLint reference,
2371 GLuint mask,
2372 GLenum transformType,
2373 const GLfloat *transformValues)
2374{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002375 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002376
2377 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002378 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002379
2380 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2381 transformValues);
2382}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002383
Sami Väisänend59ca052016-06-21 16:10:00 +03002384void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2385 GLenum pathNameType,
2386 const void *paths,
2387 GLuint pathBase,
2388 GLenum fillMode,
2389 GLuint mask,
2390 GLenum coverMode,
2391 GLenum transformType,
2392 const GLfloat *transformValues)
2393{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002394 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002395
2396 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002397 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002398
2399 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2400 transformType, transformValues);
2401}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002402
Sami Väisänend59ca052016-06-21 16:10:00 +03002403void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2404 GLenum pathNameType,
2405 const void *paths,
2406 GLuint pathBase,
2407 GLint reference,
2408 GLuint mask,
2409 GLenum coverMode,
2410 GLenum transformType,
2411 const GLfloat *transformValues)
2412{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002413 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002414
2415 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002416 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002417
2418 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2419 transformType, transformValues);
2420}
2421
Sami Väisänen46eaa942016-06-29 10:26:37 +03002422void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2423{
2424 auto *programObject = getProgram(program);
2425
2426 programObject->bindFragmentInputLocation(location, name);
2427}
2428
2429void Context::programPathFragmentInputGen(GLuint program,
2430 GLint location,
2431 GLenum genMode,
2432 GLint components,
2433 const GLfloat *coeffs)
2434{
2435 auto *programObject = getProgram(program);
2436
Jamie Madillbd044ed2017-06-05 12:59:21 -04002437 programObject->pathFragmentInputGen(this, location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002438}
2439
jchen1015015f72017-03-16 13:54:21 +08002440GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2441{
jchen10fd7c3b52017-03-21 15:36:03 +08002442 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002443 return QueryProgramResourceIndex(programObject, programInterface, name);
2444}
2445
jchen10fd7c3b52017-03-21 15:36:03 +08002446void Context::getProgramResourceName(GLuint program,
2447 GLenum programInterface,
2448 GLuint index,
2449 GLsizei bufSize,
2450 GLsizei *length,
2451 GLchar *name)
2452{
2453 const auto *programObject = getProgram(program);
2454 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2455}
2456
jchen10191381f2017-04-11 13:59:04 +08002457GLint Context::getProgramResourceLocation(GLuint program,
2458 GLenum programInterface,
2459 const GLchar *name)
2460{
2461 const auto *programObject = getProgram(program);
2462 return QueryProgramResourceLocation(programObject, programInterface, name);
2463}
2464
jchen10880683b2017-04-12 16:21:55 +08002465void Context::getProgramResourceiv(GLuint program,
2466 GLenum programInterface,
2467 GLuint index,
2468 GLsizei propCount,
2469 const GLenum *props,
2470 GLsizei bufSize,
2471 GLsizei *length,
2472 GLint *params)
2473{
2474 const auto *programObject = getProgram(program);
2475 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2476 length, params);
2477}
2478
jchen10d9cd7b72017-08-30 15:04:25 +08002479void Context::getProgramInterfaceiv(GLuint program,
2480 GLenum programInterface,
2481 GLenum pname,
2482 GLint *params)
2483{
2484 const auto *programObject = getProgram(program);
2485 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2486}
2487
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002488void Context::getProgramInterfaceivRobust(GLuint program,
2489 GLenum programInterface,
2490 GLenum pname,
2491 GLsizei bufSize,
2492 GLsizei *length,
2493 GLint *params)
2494{
2495 UNIMPLEMENTED();
2496}
2497
Jamie Madill427064d2018-04-13 16:20:34 -04002498void Context::handleError(const Error &error) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002499{
Geoff Lang7b19a492018-04-20 09:31:52 -04002500 if (ANGLE_UNLIKELY(error.isError()))
Geoff Langda5777c2014-07-11 09:52:58 -04002501 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002502 GLenum code = error.getCode();
2503 mErrors.insert(code);
2504 if (code == GL_OUT_OF_MEMORY && getWorkarounds().loseContextOnOutOfMemory)
2505 {
2506 markContextLost();
2507 }
Geoff Lang70d0f492015-12-10 17:45:46 -05002508
Geoff Langee6884e2017-11-09 16:51:11 -05002509 ASSERT(!error.getMessage().empty());
2510 mGLState.getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, error.getID(),
2511 GL_DEBUG_SEVERITY_HIGH, error.getMessage());
Geoff Langda5777c2014-07-11 09:52:58 -04002512 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002513}
2514
2515// Get one of the recorded errors and clear its flag, if any.
2516// [OpenGL ES 2.0.24] section 2.5 page 13.
2517GLenum Context::getError()
2518{
Geoff Langda5777c2014-07-11 09:52:58 -04002519 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002520 {
Geoff Langda5777c2014-07-11 09:52:58 -04002521 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002522 }
Geoff Langda5777c2014-07-11 09:52:58 -04002523 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002524 {
Geoff Langda5777c2014-07-11 09:52:58 -04002525 GLenum error = *mErrors.begin();
2526 mErrors.erase(mErrors.begin());
2527 return error;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002528 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002529}
2530
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002531// NOTE: this function should not assume that this context is current!
Jamie Madill427064d2018-04-13 16:20:34 -04002532void Context::markContextLost() const
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002533{
2534 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002535 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002536 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002537 mContextLostForced = true;
2538 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002539 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002540}
2541
Jamie Madill427064d2018-04-13 16:20:34 -04002542bool Context::isContextLost() const
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002543{
2544 return mContextLost;
2545}
2546
Jamie Madillfa920eb2018-01-04 11:45:50 -05002547GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002548{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002549 // Even if the application doesn't want to know about resets, we want to know
2550 // as it will allow us to skip all the calls.
2551 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002552 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002553 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002554 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002555 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002556 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002557
2558 // EXT_robustness, section 2.6: If the reset notification behavior is
2559 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2560 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2561 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002562 }
2563
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002564 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2565 // status should be returned at least once, and GL_NO_ERROR should be returned
2566 // once the device has finished resetting.
2567 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002568 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002569 ASSERT(mResetStatus == GL_NO_ERROR);
2570 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002571
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002572 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002573 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002574 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002575 }
2576 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002577 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002578 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002579 // If markContextLost was used to mark the context lost then
2580 // assume that is not recoverable, and continue to report the
2581 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002582 mResetStatus = mImplementation->getResetStatus();
2583 }
Jamie Madill893ab082014-05-16 16:56:10 -04002584
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002585 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002586}
2587
2588bool Context::isResetNotificationEnabled()
2589{
2590 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2591}
2592
Corentin Walleze3b10e82015-05-20 11:06:25 -04002593const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002594{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002595 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002596}
2597
2598EGLenum Context::getClientType() const
2599{
2600 return mClientType;
2601}
2602
2603EGLenum Context::getRenderBuffer() const
2604{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002605 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2606 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002607 {
2608 return EGL_NONE;
2609 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002610
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002611 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002612 ASSERT(backAttachment != nullptr);
2613 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002614}
2615
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002616VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002617{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002618 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002619 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2620 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002621 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002622 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2623 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002624
Jamie Madill96a483b2017-06-27 16:49:21 -04002625 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002626 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002627
2628 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002629}
2630
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002631TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002632{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002633 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002634 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2635 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002636 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002637 transformFeedback =
2638 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002639 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002640 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002641 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002642
2643 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002644}
2645
2646bool Context::isVertexArrayGenerated(GLuint vertexArray)
2647{
Jamie Madill96a483b2017-06-27 16:49:21 -04002648 ASSERT(mVertexArrayMap.contains(0));
2649 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002650}
2651
2652bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2653{
Jamie Madill96a483b2017-06-27 16:49:21 -04002654 ASSERT(mTransformFeedbackMap.contains(0));
2655 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002656}
2657
Shannon Woods53a94a82014-06-24 15:20:36 -04002658void Context::detachTexture(GLuint texture)
2659{
2660 // Simple pass-through to State's detachTexture method, as textures do not require
2661 // allocation map management either here or in the resource manager at detach time.
2662 // Zero textures are held by the Context, and we don't attempt to request them from
2663 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002664 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002665}
2666
James Darpinian4d9d4832018-03-13 12:43:28 -07002667void Context::detachBuffer(Buffer *buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002668{
Yuly Novikov5807a532015-12-03 13:01:22 -05002669 // Simple pass-through to State's detachBuffer method, since
2670 // only buffer attachments to container objects that are bound to the current context
2671 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002672
Yuly Novikov5807a532015-12-03 13:01:22 -05002673 // [OpenGL ES 3.2] section 5.1.2 page 45:
2674 // Attachments to unbound container objects, such as
2675 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2676 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002677 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002678}
2679
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002680void Context::detachFramebuffer(GLuint framebuffer)
2681{
Shannon Woods53a94a82014-06-24 15:20:36 -04002682 // Framebuffer detachment is handled by Context, because 0 is a valid
2683 // Framebuffer object, and a pointer to it must be passed from Context
2684 // to State at binding time.
2685
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002686 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002687 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2688 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2689 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002690
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002691 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002692 {
2693 bindReadFramebuffer(0);
2694 }
2695
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002696 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002697 {
2698 bindDrawFramebuffer(0);
2699 }
2700}
2701
2702void Context::detachRenderbuffer(GLuint renderbuffer)
2703{
Jamie Madilla02315b2017-02-23 14:14:47 -05002704 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002705}
2706
Jamie Madill57a89722013-07-02 11:57:03 -04002707void Context::detachVertexArray(GLuint vertexArray)
2708{
Jamie Madill77a72f62015-04-14 11:18:32 -04002709 // Vertex array detachment is handled by Context, because 0 is a valid
2710 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002711 // binding time.
2712
Jamie Madill57a89722013-07-02 11:57:03 -04002713 // [OpenGL ES 3.0.2] section 2.10 page 43:
2714 // If a vertex array object that is currently bound is deleted, the binding
2715 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madill7267aa62018-04-17 15:28:21 -04002716 if (mGLState.removeVertexArrayBinding(this, vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002717 {
2718 bindVertexArray(0);
2719 }
2720}
2721
Geoff Langc8058452014-02-03 12:04:11 -05002722void Context::detachTransformFeedback(GLuint transformFeedback)
2723{
Corentin Walleza2257da2016-04-19 16:43:12 -04002724 // Transform feedback detachment is handled by Context, because 0 is a valid
2725 // transform feedback, and a pointer to it must be passed from Context to State at
2726 // binding time.
2727
2728 // The OpenGL specification doesn't mention what should happen when the currently bound
2729 // transform feedback object is deleted. Since it is a container object, we treat it like
2730 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002731 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002732 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002733 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002734 }
Geoff Langc8058452014-02-03 12:04:11 -05002735}
2736
Jamie Madilldc356042013-07-19 16:36:57 -04002737void Context::detachSampler(GLuint sampler)
2738{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002739 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002740}
2741
Yunchao Hea336b902017-08-02 16:05:21 +08002742void Context::detachProgramPipeline(GLuint pipeline)
2743{
2744 mGLState.detachProgramPipeline(this, pipeline);
2745}
2746
Jamie Madill3ef140a2017-08-26 23:11:21 -04002747void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002748{
Shaodde78e82017-05-22 14:13:27 +08002749 mGLState.setVertexAttribDivisor(this, index, divisor);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002750}
2751
Jamie Madille29d1672013-07-19 16:36:57 -04002752void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2753{
Geoff Langc1984ed2016-10-07 12:41:00 -04002754 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002755 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002756 SetSamplerParameteri(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002757 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002758}
Jamie Madille29d1672013-07-19 16:36:57 -04002759
Geoff Langc1984ed2016-10-07 12:41:00 -04002760void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2761{
2762 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002763 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002764 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002765 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002766}
2767
Brandon Jones59770802018-04-02 13:18:42 -07002768void Context::samplerParameterivRobust(GLuint sampler,
2769 GLenum pname,
2770 GLsizei bufSize,
2771 const GLint *param)
2772{
2773 samplerParameteriv(sampler, pname, param);
2774}
2775
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002776void Context::samplerParameterIivRobust(GLuint sampler,
2777 GLenum pname,
2778 GLsizei bufSize,
2779 const GLint *param)
2780{
2781 UNIMPLEMENTED();
2782}
2783
2784void Context::samplerParameterIuivRobust(GLuint sampler,
2785 GLenum pname,
2786 GLsizei bufSize,
2787 const GLuint *param)
2788{
2789 UNIMPLEMENTED();
2790}
2791
Jamie Madille29d1672013-07-19 16:36:57 -04002792void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2793{
Geoff Langc1984ed2016-10-07 12:41:00 -04002794 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002795 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002796 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002797 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002798}
2799
Geoff Langc1984ed2016-10-07 12:41:00 -04002800void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002801{
Geoff Langc1984ed2016-10-07 12:41:00 -04002802 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002803 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002804 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002805 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002806}
2807
Brandon Jones59770802018-04-02 13:18:42 -07002808void Context::samplerParameterfvRobust(GLuint sampler,
2809 GLenum pname,
2810 GLsizei bufSize,
2811 const GLfloat *param)
2812{
2813 samplerParameterfv(sampler, pname, param);
2814}
2815
Geoff Langc1984ed2016-10-07 12:41:00 -04002816void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002817{
Geoff Langc1984ed2016-10-07 12:41:00 -04002818 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002819 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002820 QuerySamplerParameteriv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002821 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002822}
Jamie Madill9675b802013-07-19 16:36:59 -04002823
Brandon Jones59770802018-04-02 13:18:42 -07002824void Context::getSamplerParameterivRobust(GLuint sampler,
2825 GLenum pname,
2826 GLsizei bufSize,
2827 GLsizei *length,
2828 GLint *params)
2829{
2830 getSamplerParameteriv(sampler, pname, params);
2831}
2832
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002833void Context::getSamplerParameterIivRobust(GLuint sampler,
2834 GLenum pname,
2835 GLsizei bufSize,
2836 GLsizei *length,
2837 GLint *params)
2838{
2839 UNIMPLEMENTED();
2840}
2841
2842void Context::getSamplerParameterIuivRobust(GLuint sampler,
2843 GLenum pname,
2844 GLsizei bufSize,
2845 GLsizei *length,
2846 GLuint *params)
2847{
2848 UNIMPLEMENTED();
2849}
2850
Geoff Langc1984ed2016-10-07 12:41:00 -04002851void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2852{
2853 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002854 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002855 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002856 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002857}
2858
Brandon Jones59770802018-04-02 13:18:42 -07002859void Context::getSamplerParameterfvRobust(GLuint sampler,
2860 GLenum pname,
2861 GLsizei bufSize,
2862 GLsizei *length,
2863 GLfloat *params)
2864{
2865 getSamplerParameterfv(sampler, pname, params);
2866}
2867
Olli Etuahof0fee072016-03-30 15:11:58 +03002868void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2869{
2870 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002871 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002872}
2873
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002874void Context::initRendererString()
2875{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002876 std::ostringstream rendererString;
2877 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002878 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002879 rendererString << ")";
2880
Geoff Langcec35902014-04-16 10:52:36 -04002881 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002882}
2883
Geoff Langc339c4e2016-11-29 10:37:36 -05002884void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002885{
Geoff Langc339c4e2016-11-29 10:37:36 -05002886 const Version &clientVersion = getClientVersion();
2887
2888 std::ostringstream versionString;
2889 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2890 << ANGLE_VERSION_STRING << ")";
2891 mVersionString = MakeStaticString(versionString.str());
2892
2893 std::ostringstream shadingLanguageVersionString;
2894 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2895 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2896 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2897 << ")";
2898 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002899}
2900
Geoff Langcec35902014-04-16 10:52:36 -04002901void Context::initExtensionStrings()
2902{
Geoff Langc339c4e2016-11-29 10:37:36 -05002903 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2904 std::ostringstream combinedStringStream;
2905 std::copy(strings.begin(), strings.end(),
2906 std::ostream_iterator<const char *>(combinedStringStream, " "));
2907 return MakeStaticString(combinedStringStream.str());
2908 };
2909
2910 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002911 for (const auto &extensionString : mExtensions.getStrings())
2912 {
2913 mExtensionStrings.push_back(MakeStaticString(extensionString));
2914 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002915 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002916
Geoff Langc339c4e2016-11-29 10:37:36 -05002917 mRequestableExtensionStrings.clear();
2918 for (const auto &extensionInfo : GetExtensionInfoMap())
2919 {
2920 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08002921 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
Geoff Langb0f917f2017-12-05 13:41:54 -05002922 mSupportedExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002923 {
2924 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
2925 }
2926 }
2927 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002928}
2929
Geoff Langc339c4e2016-11-29 10:37:36 -05002930const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04002931{
Geoff Langc339c4e2016-11-29 10:37:36 -05002932 switch (name)
2933 {
2934 case GL_VENDOR:
2935 return reinterpret_cast<const GLubyte *>("Google Inc.");
2936
2937 case GL_RENDERER:
2938 return reinterpret_cast<const GLubyte *>(mRendererString);
2939
2940 case GL_VERSION:
2941 return reinterpret_cast<const GLubyte *>(mVersionString);
2942
2943 case GL_SHADING_LANGUAGE_VERSION:
2944 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
2945
2946 case GL_EXTENSIONS:
2947 return reinterpret_cast<const GLubyte *>(mExtensionString);
2948
2949 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2950 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
2951
2952 default:
2953 UNREACHABLE();
2954 return nullptr;
2955 }
Geoff Langcec35902014-04-16 10:52:36 -04002956}
2957
Geoff Langc339c4e2016-11-29 10:37:36 -05002958const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04002959{
Geoff Langc339c4e2016-11-29 10:37:36 -05002960 switch (name)
2961 {
2962 case GL_EXTENSIONS:
2963 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
2964
2965 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2966 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
2967
2968 default:
2969 UNREACHABLE();
2970 return nullptr;
2971 }
Geoff Langcec35902014-04-16 10:52:36 -04002972}
2973
2974size_t Context::getExtensionStringCount() const
2975{
2976 return mExtensionStrings.size();
2977}
2978
Geoff Lang111a99e2017-10-17 10:58:41 -04002979bool Context::isExtensionRequestable(const char *name)
2980{
2981 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2982 auto extension = extensionInfos.find(name);
2983
Geoff Lang111a99e2017-10-17 10:58:41 -04002984 return extension != extensionInfos.end() && extension->second.Requestable &&
Geoff Langb0f917f2017-12-05 13:41:54 -05002985 mSupportedExtensions.*(extension->second.ExtensionsMember);
Geoff Lang111a99e2017-10-17 10:58:41 -04002986}
2987
Geoff Langc339c4e2016-11-29 10:37:36 -05002988void Context::requestExtension(const char *name)
2989{
2990 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2991 ASSERT(extensionInfos.find(name) != extensionInfos.end());
2992 const auto &extension = extensionInfos.at(name);
2993 ASSERT(extension.Requestable);
Geoff Langb0f917f2017-12-05 13:41:54 -05002994 ASSERT(isExtensionRequestable(name));
Geoff Langc339c4e2016-11-29 10:37:36 -05002995
2996 if (mExtensions.*(extension.ExtensionsMember))
2997 {
2998 // Extension already enabled
2999 return;
3000 }
3001
3002 mExtensions.*(extension.ExtensionsMember) = true;
3003 updateCaps();
3004 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08003005
Jamie Madill2f348d22017-06-05 10:50:59 -04003006 // Release the shader compiler so it will be re-created with the requested extensions enabled.
3007 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04003008
Jamie Madill81c2e252017-09-09 23:32:46 -04003009 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
3010 // sampleable.
Jamie Madilld4442552018-02-27 22:03:47 -05003011 mState.mTextures->signalAllTexturesDirty(this);
Geoff Lang9aded172017-04-05 11:07:56 -04003012 for (auto &zeroTexture : mZeroTextures)
3013 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003014 if (zeroTexture.get() != nullptr)
3015 {
3016 zeroTexture->signalDirty(this, InitState::Initialized);
3017 }
Geoff Lang9aded172017-04-05 11:07:56 -04003018 }
3019
3020 mState.mFramebuffers->invalidateFramebufferComplenessCache();
Geoff Langc339c4e2016-11-29 10:37:36 -05003021}
3022
3023size_t Context::getRequestableExtensionStringCount() const
3024{
3025 return mRequestableExtensionStrings.size();
3026}
3027
Jamie Madill493f9572018-05-24 19:52:15 -04003028void Context::beginTransformFeedback(PrimitiveMode primitiveMode)
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003029{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003030 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003031 ASSERT(transformFeedback != nullptr);
3032 ASSERT(!transformFeedback->isPaused());
3033
Jamie Madill6c1f6712017-02-14 19:08:04 -05003034 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003035}
3036
3037bool Context::hasActiveTransformFeedback(GLuint program) const
3038{
3039 for (auto pair : mTransformFeedbackMap)
3040 {
3041 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
3042 {
3043 return true;
3044 }
3045 }
3046 return false;
3047}
3048
Geoff Lang33f11fb2018-05-07 13:42:47 -04003049Extensions Context::generateSupportedExtensions() const
Geoff Langb0f917f2017-12-05 13:41:54 -05003050{
3051 Extensions supportedExtensions = mImplementation->getNativeExtensions();
3052
3053 if (getClientVersion() < ES_2_0)
3054 {
3055 // Default extensions for GLES1
3056 supportedExtensions.pointSizeArray = true;
Lingfeng Yang23dc90b2018-04-23 09:01:49 -07003057 supportedExtensions.textureCubeMap = true;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003058 supportedExtensions.pointSprite = true;
Geoff Langb0f917f2017-12-05 13:41:54 -05003059 }
3060
3061 if (getClientVersion() < ES_3_0)
3062 {
3063 // Disable ES3+ extensions
3064 supportedExtensions.colorBufferFloat = false;
3065 supportedExtensions.eglImageExternalEssl3 = false;
3066 supportedExtensions.textureNorm16 = false;
3067 supportedExtensions.multiview = false;
3068 supportedExtensions.maxViews = 1u;
3069 }
3070
3071 if (getClientVersion() < ES_3_1)
3072 {
3073 // Disable ES3.1+ extensions
3074 supportedExtensions.geometryShader = false;
3075 }
3076
3077 if (getClientVersion() > ES_2_0)
3078 {
3079 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
3080 // supportedExtensions.sRGB = false;
3081 }
3082
3083 // Some extensions are always available because they are implemented in the GL layer.
3084 supportedExtensions.bindUniformLocation = true;
3085 supportedExtensions.vertexArrayObject = true;
3086 supportedExtensions.bindGeneratesResource = true;
3087 supportedExtensions.clientArrays = true;
3088 supportedExtensions.requestExtension = true;
3089
3090 // Enable the no error extension if the context was created with the flag.
3091 supportedExtensions.noError = mSkipValidation;
3092
3093 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Geoff Lang33f11fb2018-05-07 13:42:47 -04003094 supportedExtensions.surfacelessContext = mSurfacelessSupported;
Geoff Langb0f917f2017-12-05 13:41:54 -05003095
3096 // Explicitly enable GL_KHR_debug
3097 supportedExtensions.debug = true;
3098 supportedExtensions.maxDebugMessageLength = 1024;
3099 supportedExtensions.maxDebugLoggedMessages = 1024;
3100 supportedExtensions.maxDebugGroupStackDepth = 1024;
3101 supportedExtensions.maxLabelLength = 1024;
3102
3103 // Explicitly enable GL_ANGLE_robust_client_memory
3104 supportedExtensions.robustClientMemory = true;
3105
3106 // Determine robust resource init availability from EGL.
Geoff Lang33f11fb2018-05-07 13:42:47 -04003107 supportedExtensions.robustResourceInitialization = mGLState.isRobustResourceInitEnabled();
Geoff Langb0f917f2017-12-05 13:41:54 -05003108
3109 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
3110 // supports it.
3111 supportedExtensions.robustBufferAccessBehavior =
3112 mRobustAccess && supportedExtensions.robustBufferAccessBehavior;
3113
3114 // Enable the cache control query unconditionally.
3115 supportedExtensions.programCacheControl = true;
3116
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003117 // Enable EGL_ANGLE_explicit_context subextensions
Geoff Lang33f11fb2018-05-07 13:42:47 -04003118 if (mExplicitContextAvailable)
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003119 {
3120 // GL_ANGLE_explicit_context_gles1
3121 supportedExtensions.explicitContextGles1 = true;
3122 // GL_ANGLE_explicit_context
3123 supportedExtensions.explicitContext = true;
3124 }
3125
Geoff Langb0f917f2017-12-05 13:41:54 -05003126 return supportedExtensions;
3127}
3128
Geoff Lang33f11fb2018-05-07 13:42:47 -04003129void Context::initCaps()
Geoff Lang493daf52014-07-03 13:38:44 -04003130{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04003131 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04003132
Geoff Lang33f11fb2018-05-07 13:42:47 -04003133 mSupportedExtensions = generateSupportedExtensions();
3134 mExtensions = mSupportedExtensions;
Lingfeng Yang01074432018-04-16 10:19:51 -07003135
3136 mLimitations = mImplementation->getNativeLimitations();
3137
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003138 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
3139 if (getClientVersion() < Version(2, 0))
3140 {
3141 mCaps.maxMultitextureUnits = 4;
3142 mCaps.maxClipPlanes = 6;
3143 mCaps.maxLights = 8;
Lingfeng Yange547aac2018-04-05 09:39:20 -07003144 mCaps.maxModelviewMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3145 mCaps.maxProjectionMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3146 mCaps.maxTextureMatrixStackDepth = Caps::GlobalMatrixStackDepth;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003147 mCaps.minSmoothPointSize = 1.0f;
3148 mCaps.maxSmoothPointSize = 1.0f;
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003149 }
3150
Luc Ferronad2ae932018-06-11 15:31:17 -04003151 // Apply/Verify implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04003152 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003153
Luc Ferronad2ae932018-06-11 15:31:17 -04003154 ASSERT(mCaps.minAliasedPointSize >= 1.0f);
3155
Jamie Madill0f80ed82017-09-19 00:24:56 -04003156 if (getClientVersion() < ES_3_1)
3157 {
3158 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
3159 }
3160 else
3161 {
3162 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
3163 }
Geoff Lang301d1612014-07-09 10:34:37 -04003164
Jiawei Shao54aafe52018-04-27 14:54:57 +08003165 LimitCap(&mCaps.maxShaderUniformBlocks[ShaderType::Vertex],
3166 IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
Jamie Madill0f80ed82017-09-19 00:24:56 -04003167 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3168 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3169
3170 // Limit textures as well, so we can use fast bitsets with texture bindings.
3171 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
Jiawei Shao54aafe52018-04-27 14:54:57 +08003172 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Vertex],
3173 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
3174 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Fragment],
3175 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04003176
Jiawei Shaodb342272017-09-27 10:21:45 +08003177 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
3178
Geoff Langc287ea62016-09-16 14:46:51 -04003179 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05003180 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04003181 for (const auto &extensionInfo : GetExtensionInfoMap())
3182 {
Geoff Lang0ab41fa2018-03-14 11:03:30 -04003183 // If the user has requested that extensions start disabled and they are requestable,
3184 // disable them.
3185 if (!mExtensionsEnabled && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04003186 {
3187 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
3188 }
3189 }
3190
3191 // Generate texture caps
3192 updateCaps();
3193}
3194
3195void Context::updateCaps()
3196{
Geoff Lang900013c2014-07-07 11:32:19 -04003197 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04003198 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04003199
Jamie Madill7b62cf92017-11-02 15:20:49 -04003200 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04003201 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04003202 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04003203 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003204
Geoff Lang0d8b7242015-09-09 14:56:53 -04003205 // Update the format caps based on the client version and extensions.
3206 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
3207 // ES3.
3208 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003209 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04003210 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003211 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Yuly Novikovf15f8862018-06-04 18:59:41 -04003212 formatCaps.textureAttachment =
3213 formatCaps.textureAttachment &&
3214 formatInfo.textureAttachmentSupport(getClientVersion(), mExtensions);
3215 formatCaps.renderbuffer = formatCaps.renderbuffer &&
3216 formatInfo.renderbufferSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04003217
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003218 // OpenGL ES does not support multisampling with non-rendererable formats
3219 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Yuly Novikovf15f8862018-06-04 18:59:41 -04003220 if (!formatCaps.renderbuffer ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003221 (getClientVersion() < ES_3_1 &&
3222 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04003223 {
Geoff Langd87878e2014-09-19 15:42:59 -04003224 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04003225 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03003226 else
3227 {
3228 // We may have limited the max samples for some required renderbuffer formats due to
3229 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
3230 GLuint formatMaxSamples = formatCaps.getMaxSamples();
3231
3232 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
3233 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
3234 // exception of signed and unsigned integer formats."
3235 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
3236 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
3237 {
3238 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
3239 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
3240 }
3241
3242 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
3243 if (getClientVersion() >= ES_3_1)
3244 {
3245 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
3246 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
3247 // the exception that the signed and unsigned integer formats are required only to
3248 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
3249 // multisamples, which must be at least one."
3250 if (formatInfo.componentType == GL_INT ||
3251 formatInfo.componentType == GL_UNSIGNED_INT)
3252 {
3253 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
3254 }
3255
3256 // GLES 3.1 section 19.3.1.
3257 if (formatCaps.texturable)
3258 {
3259 if (formatInfo.depthBits > 0)
3260 {
3261 mCaps.maxDepthTextureSamples =
3262 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
3263 }
3264 else if (formatInfo.redBits > 0)
3265 {
3266 mCaps.maxColorTextureSamples =
3267 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
3268 }
3269 }
3270 }
3271 }
Geoff Langd87878e2014-09-19 15:42:59 -04003272
3273 if (formatCaps.texturable && formatInfo.compressed)
3274 {
Geoff Langca271392017-04-05 12:30:00 -04003275 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003276 }
3277
Geoff Langca271392017-04-05 12:30:00 -04003278 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04003279 }
Jamie Madill32447362017-06-28 14:53:52 -04003280
3281 // If program binary is disabled, blank out the memory cache pointer.
Geoff Langb0f917f2017-12-05 13:41:54 -05003282 if (!mSupportedExtensions.getProgramBinary)
Jamie Madill32447362017-06-28 14:53:52 -04003283 {
3284 mMemoryProgramCache = nullptr;
3285 }
Corentin Walleze4477002017-12-01 14:39:58 -05003286
3287 // Compute which buffer types are allowed
3288 mValidBufferBindings.reset();
3289 mValidBufferBindings.set(BufferBinding::ElementArray);
3290 mValidBufferBindings.set(BufferBinding::Array);
3291
3292 if (mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
3293 {
3294 mValidBufferBindings.set(BufferBinding::PixelPack);
3295 mValidBufferBindings.set(BufferBinding::PixelUnpack);
3296 }
3297
3298 if (getClientVersion() >= ES_3_0)
3299 {
3300 mValidBufferBindings.set(BufferBinding::CopyRead);
3301 mValidBufferBindings.set(BufferBinding::CopyWrite);
3302 mValidBufferBindings.set(BufferBinding::TransformFeedback);
3303 mValidBufferBindings.set(BufferBinding::Uniform);
3304 }
3305
3306 if (getClientVersion() >= ES_3_1)
3307 {
3308 mValidBufferBindings.set(BufferBinding::AtomicCounter);
3309 mValidBufferBindings.set(BufferBinding::ShaderStorage);
3310 mValidBufferBindings.set(BufferBinding::DrawIndirect);
3311 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
3312 }
Geoff Lang493daf52014-07-03 13:38:44 -04003313}
3314
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003315void Context::initWorkarounds()
3316{
Jamie Madill761b02c2017-06-23 16:27:06 -04003317 // Apply back-end workarounds.
3318 mImplementation->applyNativeWorkarounds(&mWorkarounds);
3319
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003320 // Lose the context upon out of memory error if the application is
3321 // expecting to watch for those events.
3322 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
3323}
3324
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003325Error Context::prepareForDraw(PrimitiveMode mode)
Jamie Madill05b35b22017-10-03 09:01:44 -04003326{
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003327 if (mGLES1Renderer)
3328 {
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003329 ANGLE_TRY(mGLES1Renderer->prepareForDraw(mode, this, &mGLState));
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003330 }
3331
Geoff Langa8cb2872018-03-09 16:09:40 -05003332 ANGLE_TRY(syncDirtyObjects());
Jamie Madilla59fc192017-11-02 12:57:58 -04003333
3334 if (isRobustResourceInitEnabled())
3335 {
3336 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
3337 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
3338 }
3339
Geoff Langa8cb2872018-03-09 16:09:40 -05003340 ANGLE_TRY(syncDirtyBits());
Geoff Langd4fff502017-09-22 11:28:28 -04003341 return NoError();
3342}
3343
3344Error Context::prepareForClear(GLbitfield mask)
3345{
Geoff Langa8cb2872018-03-09 16:09:40 -05003346 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003347 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearAttachmentsInitialized(this, mask));
Geoff Langa8cb2872018-03-09 16:09:40 -05003348 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04003349 return NoError();
3350}
3351
3352Error Context::prepareForClearBuffer(GLenum buffer, GLint drawbuffer)
3353{
Geoff Langa8cb2872018-03-09 16:09:40 -05003354 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003355 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearBufferAttachmentsInitialized(this, buffer,
3356 drawbuffer));
Geoff Langa8cb2872018-03-09 16:09:40 -05003357 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill05b35b22017-10-03 09:01:44 -04003358 return NoError();
3359}
3360
Geoff Langa8cb2872018-03-09 16:09:40 -05003361Error Context::syncState()
Jamie Madill1b94d432015-08-07 13:23:23 -04003362{
Geoff Langa8cb2872018-03-09 16:09:40 -05003363 ANGLE_TRY(syncDirtyObjects());
3364 ANGLE_TRY(syncDirtyBits());
Jamie Madillbc918e72018-03-08 09:47:21 -05003365 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003366}
3367
Geoff Langa8cb2872018-03-09 16:09:40 -05003368Error Context::syncState(const State::DirtyBits &bitMask, const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04003369{
Geoff Langa8cb2872018-03-09 16:09:40 -05003370 ANGLE_TRY(syncDirtyObjects(objectMask));
3371 ANGLE_TRY(syncDirtyBits(bitMask));
Geoff Langd4fff502017-09-22 11:28:28 -04003372 return NoError();
3373}
3374
Geoff Langa8cb2872018-03-09 16:09:40 -05003375Error Context::syncDirtyBits()
Geoff Langd4fff502017-09-22 11:28:28 -04003376{
3377 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
3378 mImplementation->syncState(this, dirtyBits);
3379 mGLState.clearDirtyBits();
3380 return NoError();
3381}
3382
Geoff Langa8cb2872018-03-09 16:09:40 -05003383Error Context::syncDirtyBits(const State::DirtyBits &bitMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003384{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003385 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madillfe548342017-06-19 11:13:24 -04003386 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003387 mGLState.clearDirtyBits(dirtyBits);
Jamie Madillbc918e72018-03-08 09:47:21 -05003388 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003389}
Jamie Madillc29968b2016-01-20 11:17:23 -05003390
Geoff Langa8cb2872018-03-09 16:09:40 -05003391Error Context::syncDirtyObjects()
Geoff Langd4fff502017-09-22 11:28:28 -04003392{
3393 return mGLState.syncDirtyObjects(this);
3394}
3395
Geoff Langa8cb2872018-03-09 16:09:40 -05003396Error Context::syncDirtyObjects(const State::DirtyObjects &objectMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003397{
3398 return mGLState.syncDirtyObjects(this, objectMask);
3399}
3400
Jamie Madillc29968b2016-01-20 11:17:23 -05003401void Context::blitFramebuffer(GLint srcX0,
3402 GLint srcY0,
3403 GLint srcX1,
3404 GLint srcY1,
3405 GLint dstX0,
3406 GLint dstY0,
3407 GLint dstX1,
3408 GLint dstY1,
3409 GLbitfield mask,
3410 GLenum filter)
3411{
Qin Jiajiaaef92162018-02-27 13:51:44 +08003412 if (mask == 0)
3413 {
3414 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
3415 // buffers are copied.
3416 return;
3417 }
3418
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003419 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003420 ASSERT(drawFramebuffer);
3421
3422 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
3423 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
3424
Jamie Madillbc918e72018-03-08 09:47:21 -05003425 ANGLE_CONTEXT_TRY(syncStateForBlit());
Jamie Madillc29968b2016-01-20 11:17:23 -05003426
Jamie Madillc564c072017-06-01 12:45:42 -04003427 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003428}
Jamie Madillc29968b2016-01-20 11:17:23 -05003429
3430void Context::clear(GLbitfield mask)
3431{
Geoff Langd4fff502017-09-22 11:28:28 -04003432 ANGLE_CONTEXT_TRY(prepareForClear(mask));
3433 ANGLE_CONTEXT_TRY(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05003434}
3435
3436void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
3437{
Geoff Langd4fff502017-09-22 11:28:28 -04003438 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3439 ANGLE_CONTEXT_TRY(
3440 mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003441}
3442
3443void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3444{
Geoff Langd4fff502017-09-22 11:28:28 -04003445 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3446 ANGLE_CONTEXT_TRY(
3447 mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003448}
3449
3450void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3451{
Geoff Langd4fff502017-09-22 11:28:28 -04003452 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3453 ANGLE_CONTEXT_TRY(
3454 mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003455}
3456
3457void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3458{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003459 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003460 ASSERT(framebufferObject);
3461
3462 // If a buffer is not present, the clear has no effect
3463 if (framebufferObject->getDepthbuffer() == nullptr &&
3464 framebufferObject->getStencilbuffer() == nullptr)
3465 {
3466 return;
3467 }
3468
Geoff Langd4fff502017-09-22 11:28:28 -04003469 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3470 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003471}
3472
3473void Context::readPixels(GLint x,
3474 GLint y,
3475 GLsizei width,
3476 GLsizei height,
3477 GLenum format,
3478 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003479 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003480{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003481 if (width == 0 || height == 0)
3482 {
3483 return;
3484 }
3485
Jamie Madillbc918e72018-03-08 09:47:21 -05003486 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003487
Jamie Madillb6664922017-07-25 12:55:04 -04003488 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3489 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003490
3491 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04003492 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003493}
3494
Brandon Jones59770802018-04-02 13:18:42 -07003495void Context::readPixelsRobust(GLint x,
3496 GLint y,
3497 GLsizei width,
3498 GLsizei height,
3499 GLenum format,
3500 GLenum type,
3501 GLsizei bufSize,
3502 GLsizei *length,
3503 GLsizei *columns,
3504 GLsizei *rows,
3505 void *pixels)
3506{
3507 readPixels(x, y, width, height, format, type, pixels);
3508}
3509
3510void Context::readnPixelsRobust(GLint x,
3511 GLint y,
3512 GLsizei width,
3513 GLsizei height,
3514 GLenum format,
3515 GLenum type,
3516 GLsizei bufSize,
3517 GLsizei *length,
3518 GLsizei *columns,
3519 GLsizei *rows,
3520 void *data)
3521{
3522 readPixels(x, y, width, height, format, type, data);
3523}
3524
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003525void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003526 GLint level,
3527 GLenum internalformat,
3528 GLint x,
3529 GLint y,
3530 GLsizei width,
3531 GLsizei height,
3532 GLint border)
3533{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003534 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003535 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003536
Jamie Madillc29968b2016-01-20 11:17:23 -05003537 Rectangle sourceArea(x, y, width, height);
3538
Jamie Madill05b35b22017-10-03 09:01:44 -04003539 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003540 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003541 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003542}
3543
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003544void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003545 GLint level,
3546 GLint xoffset,
3547 GLint yoffset,
3548 GLint x,
3549 GLint y,
3550 GLsizei width,
3551 GLsizei height)
3552{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003553 if (width == 0 || height == 0)
3554 {
3555 return;
3556 }
3557
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003558 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003559 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003560
Jamie Madillc29968b2016-01-20 11:17:23 -05003561 Offset destOffset(xoffset, yoffset, 0);
3562 Rectangle sourceArea(x, y, width, height);
3563
Jamie Madill05b35b22017-10-03 09:01:44 -04003564 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003565 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003566 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003567}
3568
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003569void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003570 GLint level,
3571 GLint xoffset,
3572 GLint yoffset,
3573 GLint zoffset,
3574 GLint x,
3575 GLint y,
3576 GLsizei width,
3577 GLsizei height)
3578{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003579 if (width == 0 || height == 0)
3580 {
3581 return;
3582 }
3583
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003584 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003585 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003586
Jamie Madillc29968b2016-01-20 11:17:23 -05003587 Offset destOffset(xoffset, yoffset, zoffset);
3588 Rectangle sourceArea(x, y, width, height);
3589
Jamie Madill05b35b22017-10-03 09:01:44 -04003590 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3591 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003592 handleError(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level, destOffset,
3593 sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003594}
3595
3596void Context::framebufferTexture2D(GLenum target,
3597 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003598 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003599 GLuint texture,
3600 GLint level)
3601{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003602 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003603 ASSERT(framebuffer);
3604
3605 if (texture != 0)
3606 {
3607 Texture *textureObj = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003608 ImageIndex index = ImageIndex::MakeFromTarget(textarget, level);
Jamie Madilla02315b2017-02-23 14:14:47 -05003609 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003610 }
3611 else
3612 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003613 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003614 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003615
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003616 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003617}
3618
3619void Context::framebufferRenderbuffer(GLenum target,
3620 GLenum attachment,
3621 GLenum renderbuffertarget,
3622 GLuint renderbuffer)
3623{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003624 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003625 ASSERT(framebuffer);
3626
3627 if (renderbuffer != 0)
3628 {
3629 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003630
Jamie Madillcc129372018-04-12 09:13:18 -04003631 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003632 renderbufferObject);
3633 }
3634 else
3635 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003636 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003637 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003638
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003639 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003640}
3641
3642void Context::framebufferTextureLayer(GLenum target,
3643 GLenum attachment,
3644 GLuint texture,
3645 GLint level,
3646 GLint layer)
3647{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003648 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003649 ASSERT(framebuffer);
3650
3651 if (texture != 0)
3652 {
3653 Texture *textureObject = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003654 ImageIndex index = ImageIndex::MakeFromType(textureObject->getType(), level, layer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003655 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003656 }
3657 else
3658 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003659 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003660 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003661
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003662 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003663}
3664
Brandon Jones59770802018-04-02 13:18:42 -07003665void Context::framebufferTextureMultiviewLayered(GLenum target,
3666 GLenum attachment,
3667 GLuint texture,
3668 GLint level,
3669 GLint baseViewIndex,
3670 GLsizei numViews)
Martin Radev137032d2017-07-13 10:11:12 +03003671{
Martin Radev82ef7742017-08-08 17:44:58 +03003672 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3673 ASSERT(framebuffer);
3674
3675 if (texture != 0)
3676 {
3677 Texture *textureObj = getTexture(texture);
3678
Martin Radev18b75ba2017-08-15 15:50:40 +03003679 ImageIndex index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
Martin Radev82ef7742017-08-08 17:44:58 +03003680 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3681 numViews, baseViewIndex);
3682 }
3683 else
3684 {
3685 framebuffer->resetAttachment(this, attachment);
3686 }
3687
3688 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003689}
3690
Brandon Jones59770802018-04-02 13:18:42 -07003691void Context::framebufferTextureMultiviewSideBySide(GLenum target,
3692 GLenum attachment,
3693 GLuint texture,
3694 GLint level,
3695 GLsizei numViews,
3696 const GLint *viewportOffsets)
Martin Radev137032d2017-07-13 10:11:12 +03003697{
Martin Radev5dae57b2017-07-14 16:15:55 +03003698 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3699 ASSERT(framebuffer);
3700
3701 if (texture != 0)
3702 {
3703 Texture *textureObj = getTexture(texture);
3704
3705 ImageIndex index = ImageIndex::Make2D(level);
3706 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3707 textureObj, numViews, viewportOffsets);
3708 }
3709 else
3710 {
3711 framebuffer->resetAttachment(this, attachment);
3712 }
3713
3714 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003715}
3716
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003717void Context::framebufferTexture(GLenum target, GLenum attachment, GLuint texture, GLint level)
3718{
Jiawei Shaoa8802472018-05-28 11:17:47 +08003719 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3720 ASSERT(framebuffer);
3721
3722 if (texture != 0)
3723 {
3724 Texture *textureObj = getTexture(texture);
3725
3726 ImageIndex index = ImageIndex::MakeFromType(
3727 textureObj->getType(), level, ImageIndex::kEntireLevel, ImageIndex::kEntireLevel);
3728 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
3729 }
3730 else
3731 {
3732 framebuffer->resetAttachment(this, attachment);
3733 }
3734
3735 mGLState.setObjectDirty(target);
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003736}
3737
Jamie Madillc29968b2016-01-20 11:17:23 -05003738void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3739{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003740 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003741 ASSERT(framebuffer);
3742 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003743 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003744}
3745
3746void Context::readBuffer(GLenum mode)
3747{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003748 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003749 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003750 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003751}
3752
3753void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3754{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003755 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003756 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003757
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003758 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003759 ASSERT(framebuffer);
3760
3761 // The specification isn't clear what should be done when the framebuffer isn't complete.
3762 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003763 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003764}
3765
3766void Context::invalidateFramebuffer(GLenum target,
3767 GLsizei numAttachments,
3768 const GLenum *attachments)
3769{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003770 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003771 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003772
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003773 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003774 ASSERT(framebuffer);
3775
Jamie Madill427064d2018-04-13 16:20:34 -04003776 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003777 {
Jamie Madill437fa652016-05-03 15:13:24 -04003778 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003779 }
Jamie Madill437fa652016-05-03 15:13:24 -04003780
Jamie Madill4928b7c2017-06-20 12:57:39 -04003781 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003782}
3783
3784void Context::invalidateSubFramebuffer(GLenum target,
3785 GLsizei numAttachments,
3786 const GLenum *attachments,
3787 GLint x,
3788 GLint y,
3789 GLsizei width,
3790 GLsizei height)
3791{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003792 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003793 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003794
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003795 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003796 ASSERT(framebuffer);
3797
Jamie Madill427064d2018-04-13 16:20:34 -04003798 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003799 {
Jamie Madill437fa652016-05-03 15:13:24 -04003800 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003801 }
Jamie Madill437fa652016-05-03 15:13:24 -04003802
3803 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003804 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003805}
3806
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003807void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003808 GLint level,
3809 GLint internalformat,
3810 GLsizei width,
3811 GLsizei height,
3812 GLint border,
3813 GLenum format,
3814 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003815 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003816{
Jamie Madillbc918e72018-03-08 09:47:21 -05003817 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003818
3819 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003820 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003821 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003822 size, format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003823}
3824
Brandon Jones59770802018-04-02 13:18:42 -07003825void Context::texImage2DRobust(TextureTarget target,
3826 GLint level,
3827 GLint internalformat,
3828 GLsizei width,
3829 GLsizei height,
3830 GLint border,
3831 GLenum format,
3832 GLenum type,
3833 GLsizei bufSize,
3834 const void *pixels)
3835{
3836 texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
3837}
3838
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003839void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003840 GLint level,
3841 GLint internalformat,
3842 GLsizei width,
3843 GLsizei height,
3844 GLsizei depth,
3845 GLint border,
3846 GLenum format,
3847 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003848 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003849{
Jamie Madillbc918e72018-03-08 09:47:21 -05003850 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003851
3852 Extents size(width, height, depth);
3853 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003854 handleError(texture->setImage(this, mGLState.getUnpackState(),
3855 NonCubeTextureTypeToTarget(target), level, internalformat, size,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003856 format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003857}
3858
Brandon Jones59770802018-04-02 13:18:42 -07003859void Context::texImage3DRobust(TextureType target,
3860 GLint level,
3861 GLint internalformat,
3862 GLsizei width,
3863 GLsizei height,
3864 GLsizei depth,
3865 GLint border,
3866 GLenum format,
3867 GLenum type,
3868 GLsizei bufSize,
3869 const void *pixels)
3870{
3871 texImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels);
3872}
3873
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003874void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003875 GLint level,
3876 GLint xoffset,
3877 GLint yoffset,
3878 GLsizei width,
3879 GLsizei height,
3880 GLenum format,
3881 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003882 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003883{
3884 // Zero sized uploads are valid but no-ops
3885 if (width == 0 || height == 0)
3886 {
3887 return;
3888 }
3889
Jamie Madillbc918e72018-03-08 09:47:21 -05003890 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003891
3892 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003893 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003894 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003895 type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003896}
3897
Brandon Jones59770802018-04-02 13:18:42 -07003898void Context::texSubImage2DRobust(TextureTarget target,
3899 GLint level,
3900 GLint xoffset,
3901 GLint yoffset,
3902 GLsizei width,
3903 GLsizei height,
3904 GLenum format,
3905 GLenum type,
3906 GLsizei bufSize,
3907 const void *pixels)
3908{
3909 texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
3910}
3911
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003912void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003913 GLint level,
3914 GLint xoffset,
3915 GLint yoffset,
3916 GLint zoffset,
3917 GLsizei width,
3918 GLsizei height,
3919 GLsizei depth,
3920 GLenum format,
3921 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003922 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003923{
3924 // Zero sized uploads are valid but no-ops
3925 if (width == 0 || height == 0 || depth == 0)
3926 {
3927 return;
3928 }
3929
Jamie Madillbc918e72018-03-08 09:47:21 -05003930 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003931
3932 Box area(xoffset, yoffset, zoffset, width, height, depth);
3933 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003934 handleError(texture->setSubImage(this, mGLState.getUnpackState(),
3935 NonCubeTextureTypeToTarget(target), level, area, format, type,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003936 static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003937}
3938
Brandon Jones59770802018-04-02 13:18:42 -07003939void Context::texSubImage3DRobust(TextureType target,
3940 GLint level,
3941 GLint xoffset,
3942 GLint yoffset,
3943 GLint zoffset,
3944 GLsizei width,
3945 GLsizei height,
3946 GLsizei depth,
3947 GLenum format,
3948 GLenum type,
3949 GLsizei bufSize,
3950 const void *pixels)
3951{
3952 texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type,
3953 pixels);
3954}
3955
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003956void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003957 GLint level,
3958 GLenum internalformat,
3959 GLsizei width,
3960 GLsizei height,
3961 GLint border,
3962 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003963 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003964{
Jamie Madillbc918e72018-03-08 09:47:21 -05003965 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003966
3967 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003968 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003969 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
3970 internalformat, size, imageSize,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003971 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003972}
3973
Brandon Jones59770802018-04-02 13:18:42 -07003974void Context::compressedTexImage2DRobust(TextureTarget target,
3975 GLint level,
3976 GLenum internalformat,
3977 GLsizei width,
3978 GLsizei height,
3979 GLint border,
3980 GLsizei imageSize,
3981 GLsizei dataSize,
3982 const GLvoid *data)
3983{
3984 compressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
3985}
3986
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003987void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003988 GLint level,
3989 GLenum internalformat,
3990 GLsizei width,
3991 GLsizei height,
3992 GLsizei depth,
3993 GLint border,
3994 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003995 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003996{
Jamie Madillbc918e72018-03-08 09:47:21 -05003997 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003998
3999 Extents size(width, height, depth);
4000 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004001 handleError(texture->setCompressedImage(
4002 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004003 size, imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004004}
4005
Brandon Jones59770802018-04-02 13:18:42 -07004006void Context::compressedTexImage3DRobust(TextureType target,
4007 GLint level,
4008 GLenum internalformat,
4009 GLsizei width,
4010 GLsizei height,
4011 GLsizei depth,
4012 GLint border,
4013 GLsizei imageSize,
4014 GLsizei dataSize,
4015 const GLvoid *data)
4016{
4017 compressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize,
4018 data);
4019}
4020
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004021void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004022 GLint level,
4023 GLint xoffset,
4024 GLint yoffset,
4025 GLsizei width,
4026 GLsizei height,
4027 GLenum format,
4028 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004029 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004030{
Jamie Madillbc918e72018-03-08 09:47:21 -05004031 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004032
4033 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004034 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05004035 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
4036 format, imageSize,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004037 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004038}
4039
Brandon Jones59770802018-04-02 13:18:42 -07004040void Context::compressedTexSubImage2DRobust(TextureTarget target,
4041 GLint level,
4042 GLint xoffset,
4043 GLint yoffset,
4044 GLsizei width,
4045 GLsizei height,
4046 GLenum format,
4047 GLsizei imageSize,
4048 GLsizei dataSize,
4049 const GLvoid *data)
4050{
4051 compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize,
4052 data);
4053}
4054
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004055void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004056 GLint level,
4057 GLint xoffset,
4058 GLint yoffset,
4059 GLint zoffset,
4060 GLsizei width,
4061 GLsizei height,
4062 GLsizei depth,
4063 GLenum format,
4064 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004065 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004066{
4067 // Zero sized uploads are valid but no-ops
4068 if (width == 0 || height == 0)
4069 {
4070 return;
4071 }
4072
Jamie Madillbc918e72018-03-08 09:47:21 -05004073 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004074
4075 Box area(xoffset, yoffset, zoffset, width, height, depth);
4076 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004077 handleError(texture->setCompressedSubImage(
4078 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004079 imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004080}
4081
Brandon Jones59770802018-04-02 13:18:42 -07004082void Context::compressedTexSubImage3DRobust(TextureType target,
4083 GLint level,
4084 GLint xoffset,
4085 GLint yoffset,
4086 GLint zoffset,
4087 GLsizei width,
4088 GLsizei height,
4089 GLsizei depth,
4090 GLenum format,
4091 GLsizei imageSize,
4092 GLsizei dataSize,
4093 const GLvoid *data)
4094{
4095 compressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format,
4096 imageSize, data);
4097}
4098
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004099void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004100{
4101 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05004102 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004103}
4104
Jamie Madill007530e2017-12-28 14:27:04 -05004105void Context::copyTexture(GLuint sourceId,
4106 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004107 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004108 GLuint destId,
4109 GLint destLevel,
4110 GLint internalFormat,
4111 GLenum destType,
4112 GLboolean unpackFlipY,
4113 GLboolean unpackPremultiplyAlpha,
4114 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004115{
Jamie Madillbc918e72018-03-08 09:47:21 -05004116 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004117
4118 gl::Texture *sourceTexture = getTexture(sourceId);
4119 gl::Texture *destTexture = getTexture(destId);
Geoff Lang92019432017-11-20 13:09:34 -05004120 handleError(destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType,
4121 sourceLevel, ConvertToBool(unpackFlipY),
4122 ConvertToBool(unpackPremultiplyAlpha),
4123 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004124}
4125
Jamie Madill007530e2017-12-28 14:27:04 -05004126void Context::copySubTexture(GLuint sourceId,
4127 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004128 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004129 GLuint destId,
4130 GLint destLevel,
4131 GLint xoffset,
4132 GLint yoffset,
4133 GLint x,
4134 GLint y,
4135 GLsizei width,
4136 GLsizei height,
4137 GLboolean unpackFlipY,
4138 GLboolean unpackPremultiplyAlpha,
4139 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004140{
4141 // Zero sized copies are valid but no-ops
4142 if (width == 0 || height == 0)
4143 {
4144 return;
4145 }
4146
Jamie Madillbc918e72018-03-08 09:47:21 -05004147 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004148
4149 gl::Texture *sourceTexture = getTexture(sourceId);
4150 gl::Texture *destTexture = getTexture(destId);
4151 Offset offset(xoffset, yoffset, 0);
4152 Rectangle area(x, y, width, height);
Geoff Lang92019432017-11-20 13:09:34 -05004153 handleError(destTexture->copySubTexture(this, destTarget, destLevel, offset, sourceLevel, area,
4154 ConvertToBool(unpackFlipY),
4155 ConvertToBool(unpackPremultiplyAlpha),
4156 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004157}
4158
Jamie Madill007530e2017-12-28 14:27:04 -05004159void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07004160{
Jamie Madillbc918e72018-03-08 09:47:21 -05004161 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07004162
4163 gl::Texture *sourceTexture = getTexture(sourceId);
4164 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05004165 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07004166}
4167
Corentin Wallez336129f2017-10-17 15:55:40 -04004168void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03004169{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004170 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004171 ASSERT(buffer);
4172
Geoff Lang496c02d2016-10-20 11:38:11 -07004173 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03004174}
4175
Brandon Jones59770802018-04-02 13:18:42 -07004176void Context::getBufferPointervRobust(BufferBinding target,
4177 GLenum pname,
4178 GLsizei bufSize,
4179 GLsizei *length,
4180 void **params)
4181{
4182 getBufferPointerv(target, pname, params);
4183}
4184
Corentin Wallez336129f2017-10-17 15:55:40 -04004185void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004186{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004187 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004188 ASSERT(buffer);
4189
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004190 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004191 if (error.isError())
4192 {
Jamie Madill437fa652016-05-03 15:13:24 -04004193 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004194 return nullptr;
4195 }
4196
4197 return buffer->getMapPointer();
4198}
4199
Corentin Wallez336129f2017-10-17 15:55:40 -04004200GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03004201{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004202 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004203 ASSERT(buffer);
4204
4205 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004206 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03004207 if (error.isError())
4208 {
Jamie Madill437fa652016-05-03 15:13:24 -04004209 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004210 return GL_FALSE;
4211 }
4212
4213 return result;
4214}
4215
Corentin Wallez336129f2017-10-17 15:55:40 -04004216void *Context::mapBufferRange(BufferBinding target,
4217 GLintptr offset,
4218 GLsizeiptr length,
4219 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004220{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004221 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004222 ASSERT(buffer);
4223
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004224 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004225 if (error.isError())
4226 {
Jamie Madill437fa652016-05-03 15:13:24 -04004227 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004228 return nullptr;
4229 }
4230
4231 return buffer->getMapPointer();
4232}
4233
Corentin Wallez336129f2017-10-17 15:55:40 -04004234void Context::flushMappedBufferRange(BufferBinding /*target*/,
4235 GLintptr /*offset*/,
4236 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03004237{
4238 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
4239}
4240
Jamie Madillbc918e72018-03-08 09:47:21 -05004241Error Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004242{
Geoff Langa8cb2872018-03-09 16:09:40 -05004243 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004244}
4245
Jamie Madillbc918e72018-03-08 09:47:21 -05004246Error Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004247{
Geoff Langa8cb2872018-03-09 16:09:40 -05004248 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004249}
4250
Jamie Madillbc918e72018-03-08 09:47:21 -05004251Error Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004252{
Geoff Langa8cb2872018-03-09 16:09:40 -05004253 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004254}
4255
Jiajia Qin5451d532017-11-16 17:16:34 +08004256void Context::activeShaderProgram(GLuint pipeline, GLuint program)
4257{
4258 UNIMPLEMENTED();
4259}
4260
Jamie Madillc20ab272016-06-09 07:20:46 -07004261void Context::activeTexture(GLenum texture)
4262{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004263 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004264}
4265
Jamie Madill876429b2017-04-20 15:46:24 -04004266void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004267{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004268 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004269}
4270
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004271void Context::blendEquation(GLenum mode)
4272{
4273 mGLState.setBlendEquation(mode, mode);
4274}
4275
Jamie Madillc20ab272016-06-09 07:20:46 -07004276void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
4277{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004278 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004279}
4280
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004281void Context::blendFunc(GLenum sfactor, GLenum dfactor)
4282{
4283 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
4284}
4285
Jamie Madillc20ab272016-06-09 07:20:46 -07004286void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
4287{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004288 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004289}
4290
Jamie Madill876429b2017-04-20 15:46:24 -04004291void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004292{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004293 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004294}
4295
Jamie Madill876429b2017-04-20 15:46:24 -04004296void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07004297{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004298 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07004299}
4300
4301void Context::clearStencil(GLint s)
4302{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004303 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07004304}
4305
4306void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
4307{
Geoff Lang92019432017-11-20 13:09:34 -05004308 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
4309 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004310}
4311
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004312void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07004313{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004314 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004315}
4316
4317void Context::depthFunc(GLenum func)
4318{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004319 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07004320}
4321
4322void Context::depthMask(GLboolean flag)
4323{
Geoff Lang92019432017-11-20 13:09:34 -05004324 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07004325}
4326
Jamie Madill876429b2017-04-20 15:46:24 -04004327void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07004328{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004329 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07004330}
4331
4332void Context::disable(GLenum cap)
4333{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004334 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07004335}
4336
4337void Context::disableVertexAttribArray(GLuint index)
4338{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004339 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07004340}
4341
4342void Context::enable(GLenum cap)
4343{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004344 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07004345}
4346
4347void Context::enableVertexAttribArray(GLuint index)
4348{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004349 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07004350}
4351
4352void Context::frontFace(GLenum mode)
4353{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004354 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004355}
4356
4357void Context::hint(GLenum target, GLenum mode)
4358{
4359 switch (target)
4360 {
4361 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004362 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004363 break;
4364
4365 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004366 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004367 break;
4368
4369 default:
4370 UNREACHABLE();
4371 return;
4372 }
4373}
4374
4375void Context::lineWidth(GLfloat width)
4376{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004377 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07004378}
4379
4380void Context::pixelStorei(GLenum pname, GLint param)
4381{
4382 switch (pname)
4383 {
4384 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004385 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004386 break;
4387
4388 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004389 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004390 break;
4391
4392 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004393 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004394 break;
4395
4396 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004397 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004398 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004399 break;
4400
4401 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03004402 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004403 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004404 break;
4405
4406 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03004407 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004408 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004409 break;
4410
4411 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004412 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004413 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004414 break;
4415
4416 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004417 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004418 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004419 break;
4420
4421 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004422 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004423 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004424 break;
4425
4426 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004427 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004428 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004429 break;
4430
4431 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004432 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004433 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004434 break;
4435
4436 default:
4437 UNREACHABLE();
4438 return;
4439 }
4440}
4441
4442void Context::polygonOffset(GLfloat factor, GLfloat units)
4443{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004444 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07004445}
4446
Jamie Madill876429b2017-04-20 15:46:24 -04004447void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07004448{
Geoff Lang92019432017-11-20 13:09:34 -05004449 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07004450}
4451
Jiawei Shaodb342272017-09-27 10:21:45 +08004452void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
4453{
4454 mGLState.setSampleMaskParams(maskNumber, mask);
4455}
4456
Jamie Madillc20ab272016-06-09 07:20:46 -07004457void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
4458{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004459 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004460}
4461
4462void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
4463{
4464 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4465 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004466 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004467 }
4468
4469 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4470 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004471 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004472 }
4473}
4474
4475void Context::stencilMaskSeparate(GLenum face, GLuint mask)
4476{
4477 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4478 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004479 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004480 }
4481
4482 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4483 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004484 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004485 }
4486}
4487
4488void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4489{
4490 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4491 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004492 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004493 }
4494
4495 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4496 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004497 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004498 }
4499}
4500
4501void Context::vertexAttrib1f(GLuint index, GLfloat x)
4502{
4503 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004504 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004505}
4506
4507void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
4508{
4509 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004510 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004511}
4512
4513void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4514{
4515 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004516 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004517}
4518
4519void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
4520{
4521 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004522 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004523}
4524
4525void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4526{
4527 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004528 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004529}
4530
4531void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
4532{
4533 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004534 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004535}
4536
4537void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4538{
4539 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004540 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004541}
4542
4543void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
4544{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004545 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07004546}
4547
4548void Context::vertexAttribPointer(GLuint index,
4549 GLint size,
4550 GLenum type,
4551 GLboolean normalized,
4552 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004553 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07004554{
Corentin Wallez336129f2017-10-17 15:55:40 -04004555 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05004556 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc20ab272016-06-09 07:20:46 -07004557}
4558
Shao80957d92017-02-20 21:25:59 +08004559void Context::vertexAttribFormat(GLuint attribIndex,
4560 GLint size,
4561 GLenum type,
4562 GLboolean normalized,
4563 GLuint relativeOffset)
4564{
Geoff Lang92019432017-11-20 13:09:34 -05004565 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08004566 relativeOffset);
4567}
4568
4569void Context::vertexAttribIFormat(GLuint attribIndex,
4570 GLint size,
4571 GLenum type,
4572 GLuint relativeOffset)
4573{
4574 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
4575}
4576
4577void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4578{
Shaodde78e82017-05-22 14:13:27 +08004579 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Shao80957d92017-02-20 21:25:59 +08004580}
4581
Jiajia Qin5451d532017-11-16 17:16:34 +08004582void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004583{
4584 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
4585}
4586
Jamie Madillc20ab272016-06-09 07:20:46 -07004587void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4588{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004589 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004590}
4591
4592void Context::vertexAttribIPointer(GLuint index,
4593 GLint size,
4594 GLenum type,
4595 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004596 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004597{
Corentin Wallez336129f2017-10-17 15:55:40 -04004598 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
4599 size, type, false, true, stride, pointer);
Jamie Madillc20ab272016-06-09 07:20:46 -07004600}
4601
4602void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4603{
4604 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004605 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004606}
4607
4608void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4609{
4610 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004611 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004612}
4613
4614void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4615{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004616 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004617}
4618
4619void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4620{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004621 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004622}
4623
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004624void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4625{
4626 const VertexAttribCurrentValueData &currentValues =
4627 getGLState().getVertexAttribCurrentValue(index);
4628 const VertexArray *vao = getGLState().getVertexArray();
4629 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4630 currentValues, pname, params);
4631}
4632
Brandon Jones59770802018-04-02 13:18:42 -07004633void Context::getVertexAttribivRobust(GLuint index,
4634 GLenum pname,
4635 GLsizei bufSize,
4636 GLsizei *length,
4637 GLint *params)
4638{
4639 getVertexAttribiv(index, pname, params);
4640}
4641
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004642void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4643{
4644 const VertexAttribCurrentValueData &currentValues =
4645 getGLState().getVertexAttribCurrentValue(index);
4646 const VertexArray *vao = getGLState().getVertexArray();
4647 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4648 currentValues, pname, params);
4649}
4650
Brandon Jones59770802018-04-02 13:18:42 -07004651void Context::getVertexAttribfvRobust(GLuint index,
4652 GLenum pname,
4653 GLsizei bufSize,
4654 GLsizei *length,
4655 GLfloat *params)
4656{
4657 getVertexAttribfv(index, pname, params);
4658}
4659
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004660void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4661{
4662 const VertexAttribCurrentValueData &currentValues =
4663 getGLState().getVertexAttribCurrentValue(index);
4664 const VertexArray *vao = getGLState().getVertexArray();
4665 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4666 currentValues, pname, params);
4667}
4668
Brandon Jones59770802018-04-02 13:18:42 -07004669void Context::getVertexAttribIivRobust(GLuint index,
4670 GLenum pname,
4671 GLsizei bufSize,
4672 GLsizei *length,
4673 GLint *params)
4674{
4675 getVertexAttribIiv(index, pname, params);
4676}
4677
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004678void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4679{
4680 const VertexAttribCurrentValueData &currentValues =
4681 getGLState().getVertexAttribCurrentValue(index);
4682 const VertexArray *vao = getGLState().getVertexArray();
4683 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4684 currentValues, pname, params);
4685}
4686
Brandon Jones59770802018-04-02 13:18:42 -07004687void Context::getVertexAttribIuivRobust(GLuint index,
4688 GLenum pname,
4689 GLsizei bufSize,
4690 GLsizei *length,
4691 GLuint *params)
4692{
4693 getVertexAttribIuiv(index, pname, params);
4694}
4695
Jamie Madill876429b2017-04-20 15:46:24 -04004696void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004697{
4698 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
4699 QueryVertexAttribPointerv(attrib, pname, pointer);
4700}
4701
Brandon Jones59770802018-04-02 13:18:42 -07004702void Context::getVertexAttribPointervRobust(GLuint index,
4703 GLenum pname,
4704 GLsizei bufSize,
4705 GLsizei *length,
4706 void **pointer)
4707{
4708 getVertexAttribPointerv(index, pname, pointer);
4709}
4710
Jamie Madillc20ab272016-06-09 07:20:46 -07004711void Context::debugMessageControl(GLenum source,
4712 GLenum type,
4713 GLenum severity,
4714 GLsizei count,
4715 const GLuint *ids,
4716 GLboolean enabled)
4717{
4718 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004719 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05004720 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004721}
4722
4723void Context::debugMessageInsert(GLenum source,
4724 GLenum type,
4725 GLuint id,
4726 GLenum severity,
4727 GLsizei length,
4728 const GLchar *buf)
4729{
4730 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004731 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004732}
4733
4734void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4735{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004736 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004737}
4738
4739GLuint Context::getDebugMessageLog(GLuint count,
4740 GLsizei bufSize,
4741 GLenum *sources,
4742 GLenum *types,
4743 GLuint *ids,
4744 GLenum *severities,
4745 GLsizei *lengths,
4746 GLchar *messageLog)
4747{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004748 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4749 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004750}
4751
4752void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4753{
4754 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004755 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05004756 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07004757}
4758
4759void Context::popDebugGroup()
4760{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004761 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05004762 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004763}
4764
Corentin Wallez336129f2017-10-17 15:55:40 -04004765void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004766{
4767 Buffer *buffer = mGLState.getTargetBuffer(target);
4768 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004769 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004770}
4771
Corentin Wallez336129f2017-10-17 15:55:40 -04004772void Context::bufferSubData(BufferBinding target,
4773 GLintptr offset,
4774 GLsizeiptr size,
4775 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004776{
4777 if (data == nullptr)
4778 {
4779 return;
4780 }
4781
4782 Buffer *buffer = mGLState.getTargetBuffer(target);
4783 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004784 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004785}
4786
Jamie Madillef300b12016-10-07 15:12:09 -04004787void Context::attachShader(GLuint program, GLuint shader)
4788{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05004789 Program *programObject = mState.mShaderPrograms->getProgram(program);
4790 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004791 ASSERT(programObject && shaderObject);
4792 programObject->attachShader(shaderObject);
4793}
4794
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004795const Workarounds &Context::getWorkarounds() const
4796{
4797 return mWorkarounds;
4798}
4799
Corentin Wallez336129f2017-10-17 15:55:40 -04004800void Context::copyBufferSubData(BufferBinding readTarget,
4801 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04004802 GLintptr readOffset,
4803 GLintptr writeOffset,
4804 GLsizeiptr size)
4805{
4806 // if size is zero, the copy is a successful no-op
4807 if (size == 0)
4808 {
4809 return;
4810 }
4811
4812 // TODO(jmadill): cache these.
4813 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4814 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4815
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004816 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004817}
4818
Jamie Madill01a80ee2016-11-07 12:06:18 -05004819void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4820{
4821 Program *programObject = getProgram(program);
4822 // TODO(jmadill): Re-use this from the validation if possible.
4823 ASSERT(programObject);
4824 programObject->bindAttributeLocation(index, name);
4825}
4826
Corentin Wallez336129f2017-10-17 15:55:40 -04004827void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004828{
Corentin Wallez336129f2017-10-17 15:55:40 -04004829 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4830 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004831}
4832
Corentin Wallez336129f2017-10-17 15:55:40 -04004833void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08004834{
4835 bindBufferRange(target, index, buffer, 0, 0);
4836}
4837
Corentin Wallez336129f2017-10-17 15:55:40 -04004838void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08004839 GLuint index,
4840 GLuint buffer,
4841 GLintptr offset,
4842 GLsizeiptr size)
4843{
Corentin Wallez336129f2017-10-17 15:55:40 -04004844 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4845 mGLState.setIndexedBufferBinding(this, target, index, bufferObject, offset, size);
Jiajia Qin6eafb042016-12-27 17:04:07 +08004846}
4847
Jamie Madill01a80ee2016-11-07 12:06:18 -05004848void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
4849{
4850 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4851 {
4852 bindReadFramebuffer(framebuffer);
4853 }
4854
4855 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4856 {
4857 bindDrawFramebuffer(framebuffer);
4858 }
4859}
4860
4861void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4862{
4863 ASSERT(target == GL_RENDERBUFFER);
4864 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004865 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04004866 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004867}
4868
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004869void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08004870 GLsizei samples,
4871 GLenum internalformat,
4872 GLsizei width,
4873 GLsizei height,
4874 GLboolean fixedsamplelocations)
4875{
4876 Extents size(width, height, 1);
4877 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004878 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
4879 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004880}
4881
4882void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4883{
JiangYizhou5b03f472017-01-09 10:22:53 +08004884 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
4885 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillbc918e72018-03-08 09:47:21 -05004886 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
JiangYizhou5b03f472017-01-09 10:22:53 +08004887 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08004888
4889 switch (pname)
4890 {
4891 case GL_SAMPLE_POSITION:
Geoff Lang13455072018-05-09 11:24:43 -04004892 handleError(framebuffer->getSamplePosition(this, index, val));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004893 break;
4894 default:
4895 UNREACHABLE();
4896 }
4897}
4898
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07004899void Context::getMultisamplefvRobust(GLenum pname,
4900 GLuint index,
4901 GLsizei bufSize,
4902 GLsizei *length,
4903 GLfloat *val)
4904{
4905 UNIMPLEMENTED();
4906}
4907
Jamie Madille8fb6402017-02-14 17:56:40 -05004908void Context::renderbufferStorage(GLenum target,
4909 GLenum internalformat,
4910 GLsizei width,
4911 GLsizei height)
4912{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004913 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4914 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
4915
Jamie Madille8fb6402017-02-14 17:56:40 -05004916 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04004917 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004918}
4919
4920void Context::renderbufferStorageMultisample(GLenum target,
4921 GLsizei samples,
4922 GLenum internalformat,
4923 GLsizei width,
4924 GLsizei height)
4925{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004926 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4927 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05004928
4929 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004930 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04004931 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004932}
4933
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004934void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
4935{
Jamie Madill70b5bb02017-08-28 13:32:37 -04004936 const Sync *syncObject = getSync(sync);
Geoff Lang82483b92017-04-11 15:33:00 -04004937 handleError(QuerySynciv(syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004938}
4939
JiangYizhoue18e6392017-02-20 10:32:23 +08004940void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
4941{
4942 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4943 QueryFramebufferParameteriv(framebuffer, pname, params);
4944}
4945
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07004946void Context::getFramebufferParameterivRobust(GLenum target,
4947 GLenum pname,
4948 GLsizei bufSize,
4949 GLsizei *length,
4950 GLint *params)
4951{
4952 UNIMPLEMENTED();
4953}
4954
Jiajia Qin5451d532017-11-16 17:16:34 +08004955void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08004956{
4957 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4958 SetFramebufferParameteri(framebuffer, pname, param);
4959}
4960
Jamie Madillb3f26b92017-07-19 15:07:41 -04004961Error Context::getScratchBuffer(size_t requstedSizeBytes,
4962 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05004963{
Jamie Madillb3f26b92017-07-19 15:07:41 -04004964 if (!mScratchBuffer.get(requstedSizeBytes, scratchBufferOut))
4965 {
4966 return OutOfMemory() << "Failed to allocate internal buffer.";
4967 }
4968 return NoError();
4969}
4970
4971Error Context::getZeroFilledBuffer(size_t requstedSizeBytes,
4972 angle::MemoryBuffer **zeroBufferOut) const
4973{
4974 if (!mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0))
Jamie Madille14951e2017-03-09 18:55:16 -05004975 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004976 return OutOfMemory() << "Failed to allocate internal buffer.";
Jamie Madille14951e2017-03-09 18:55:16 -05004977 }
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004978 return NoError();
Jamie Madille14951e2017-03-09 18:55:16 -05004979}
4980
Xinghua Cao10a4d432017-11-28 14:46:26 +08004981Error Context::prepareForDispatch()
4982{
Geoff Langa8cb2872018-03-09 16:09:40 -05004983 ANGLE_TRY(syncState(mComputeDirtyBits, mComputeDirtyObjects));
Xinghua Cao10a4d432017-11-28 14:46:26 +08004984
4985 if (isRobustResourceInitEnabled())
4986 {
4987 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
4988 }
4989
4990 return NoError();
4991}
4992
Xinghua Cao2b396592017-03-29 15:36:04 +08004993void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
4994{
4995 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
4996 {
4997 return;
4998 }
4999
Xinghua Cao10a4d432017-11-28 14:46:26 +08005000 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill71c88b32017-09-14 22:20:29 -04005001 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08005002}
5003
Jiajia Qin5451d532017-11-16 17:16:34 +08005004void Context::dispatchComputeIndirect(GLintptr indirect)
5005{
Qin Jiajia62fcf622017-11-30 16:16:12 +08005006 ANGLE_CONTEXT_TRY(prepareForDispatch());
5007 handleError(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08005008}
5009
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005010void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005011 GLsizei levels,
5012 GLenum internalFormat,
5013 GLsizei width,
5014 GLsizei height)
5015{
5016 Extents size(width, height, 1);
5017 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005018 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005019}
5020
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005021void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005022 GLsizei levels,
5023 GLenum internalFormat,
5024 GLsizei width,
5025 GLsizei height,
5026 GLsizei depth)
5027{
5028 Extents size(width, height, depth);
5029 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005030 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005031}
5032
Jiajia Qin5451d532017-11-16 17:16:34 +08005033void Context::memoryBarrier(GLbitfield barriers)
5034{
Xinghua Cao89c422a2017-11-29 18:24:20 +08005035 handleError(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005036}
5037
5038void Context::memoryBarrierByRegion(GLbitfield barriers)
5039{
Xinghua Cao89c422a2017-11-29 18:24:20 +08005040 handleError(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005041}
5042
Jamie Madillc1d770e2017-04-13 17:31:24 -04005043GLenum Context::checkFramebufferStatus(GLenum target)
5044{
5045 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5046 ASSERT(framebuffer);
Jamie Madill427064d2018-04-13 16:20:34 -04005047 return framebuffer->checkStatus(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005048}
5049
5050void Context::compileShader(GLuint shader)
5051{
5052 Shader *shaderObject = GetValidShader(this, shader);
5053 if (!shaderObject)
5054 {
5055 return;
5056 }
5057 shaderObject->compile(this);
5058}
5059
5060void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
5061{
5062 for (int i = 0; i < n; i++)
5063 {
5064 deleteBuffer(buffers[i]);
5065 }
5066}
5067
5068void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
5069{
5070 for (int i = 0; i < n; i++)
5071 {
5072 if (framebuffers[i] != 0)
5073 {
5074 deleteFramebuffer(framebuffers[i]);
5075 }
5076 }
5077}
5078
5079void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
5080{
5081 for (int i = 0; i < n; i++)
5082 {
5083 deleteRenderbuffer(renderbuffers[i]);
5084 }
5085}
5086
5087void Context::deleteTextures(GLsizei n, const GLuint *textures)
5088{
5089 for (int i = 0; i < n; i++)
5090 {
5091 if (textures[i] != 0)
5092 {
5093 deleteTexture(textures[i]);
5094 }
5095 }
5096}
5097
5098void Context::detachShader(GLuint program, GLuint shader)
5099{
5100 Program *programObject = getProgram(program);
5101 ASSERT(programObject);
5102
5103 Shader *shaderObject = getShader(shader);
5104 ASSERT(shaderObject);
5105
5106 programObject->detachShader(this, shaderObject);
5107}
5108
5109void Context::genBuffers(GLsizei n, GLuint *buffers)
5110{
5111 for (int i = 0; i < n; i++)
5112 {
5113 buffers[i] = createBuffer();
5114 }
5115}
5116
5117void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
5118{
5119 for (int i = 0; i < n; i++)
5120 {
5121 framebuffers[i] = createFramebuffer();
5122 }
5123}
5124
5125void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
5126{
5127 for (int i = 0; i < n; i++)
5128 {
5129 renderbuffers[i] = createRenderbuffer();
5130 }
5131}
5132
5133void Context::genTextures(GLsizei n, GLuint *textures)
5134{
5135 for (int i = 0; i < n; i++)
5136 {
5137 textures[i] = createTexture();
5138 }
5139}
5140
5141void Context::getActiveAttrib(GLuint program,
5142 GLuint index,
5143 GLsizei bufsize,
5144 GLsizei *length,
5145 GLint *size,
5146 GLenum *type,
5147 GLchar *name)
5148{
5149 Program *programObject = getProgram(program);
5150 ASSERT(programObject);
5151 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
5152}
5153
5154void Context::getActiveUniform(GLuint program,
5155 GLuint index,
5156 GLsizei bufsize,
5157 GLsizei *length,
5158 GLint *size,
5159 GLenum *type,
5160 GLchar *name)
5161{
5162 Program *programObject = getProgram(program);
5163 ASSERT(programObject);
5164 programObject->getActiveUniform(index, bufsize, length, size, type, name);
5165}
5166
5167void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
5168{
5169 Program *programObject = getProgram(program);
5170 ASSERT(programObject);
5171 programObject->getAttachedShaders(maxcount, count, shaders);
5172}
5173
5174GLint Context::getAttribLocation(GLuint program, const GLchar *name)
5175{
5176 Program *programObject = getProgram(program);
5177 ASSERT(programObject);
5178 return programObject->getAttributeLocation(name);
5179}
5180
5181void Context::getBooleanv(GLenum pname, GLboolean *params)
5182{
5183 GLenum nativeType;
5184 unsigned int numParams = 0;
5185 getQueryParameterInfo(pname, &nativeType, &numParams);
5186
5187 if (nativeType == GL_BOOL)
5188 {
5189 getBooleanvImpl(pname, params);
5190 }
5191 else
5192 {
5193 CastStateValues(this, nativeType, pname, numParams, params);
5194 }
5195}
5196
Brandon Jones59770802018-04-02 13:18:42 -07005197void Context::getBooleanvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLboolean *params)
5198{
5199 getBooleanv(pname, params);
5200}
5201
Jamie Madillc1d770e2017-04-13 17:31:24 -04005202void Context::getFloatv(GLenum pname, GLfloat *params)
5203{
5204 GLenum nativeType;
5205 unsigned int numParams = 0;
5206 getQueryParameterInfo(pname, &nativeType, &numParams);
5207
5208 if (nativeType == GL_FLOAT)
5209 {
5210 getFloatvImpl(pname, params);
5211 }
5212 else
5213 {
5214 CastStateValues(this, nativeType, pname, numParams, params);
5215 }
5216}
5217
Brandon Jones59770802018-04-02 13:18:42 -07005218void Context::getFloatvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLfloat *params)
5219{
5220 getFloatv(pname, params);
5221}
5222
Jamie Madillc1d770e2017-04-13 17:31:24 -04005223void Context::getIntegerv(GLenum pname, GLint *params)
5224{
5225 GLenum nativeType;
5226 unsigned int numParams = 0;
5227 getQueryParameterInfo(pname, &nativeType, &numParams);
5228
5229 if (nativeType == GL_INT)
5230 {
5231 getIntegervImpl(pname, params);
5232 }
5233 else
5234 {
5235 CastStateValues(this, nativeType, pname, numParams, params);
5236 }
5237}
5238
Brandon Jones59770802018-04-02 13:18:42 -07005239void Context::getIntegervRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint *data)
5240{
5241 getIntegerv(pname, data);
5242}
5243
Jamie Madillc1d770e2017-04-13 17:31:24 -04005244void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
5245{
5246 Program *programObject = getProgram(program);
5247 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04005248 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005249}
5250
Brandon Jones59770802018-04-02 13:18:42 -07005251void Context::getProgramivRobust(GLuint program,
5252 GLenum pname,
5253 GLsizei bufSize,
5254 GLsizei *length,
5255 GLint *params)
5256{
5257 getProgramiv(program, pname, params);
5258}
5259
Jiajia Qin5451d532017-11-16 17:16:34 +08005260void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
5261{
5262 UNIMPLEMENTED();
5263}
5264
Jamie Madillbe849e42017-05-02 15:49:00 -04005265void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005266{
5267 Program *programObject = getProgram(program);
5268 ASSERT(programObject);
5269 programObject->getInfoLog(bufsize, length, infolog);
5270}
5271
Jiajia Qin5451d532017-11-16 17:16:34 +08005272void Context::getProgramPipelineInfoLog(GLuint pipeline,
5273 GLsizei bufSize,
5274 GLsizei *length,
5275 GLchar *infoLog)
5276{
5277 UNIMPLEMENTED();
5278}
5279
Jamie Madillc1d770e2017-04-13 17:31:24 -04005280void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
5281{
5282 Shader *shaderObject = getShader(shader);
5283 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04005284 QueryShaderiv(this, shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005285}
5286
Brandon Jones59770802018-04-02 13:18:42 -07005287void Context::getShaderivRobust(GLuint shader,
5288 GLenum pname,
5289 GLsizei bufSize,
5290 GLsizei *length,
5291 GLint *params)
5292{
5293 getShaderiv(shader, pname, params);
5294}
5295
Jamie Madillc1d770e2017-04-13 17:31:24 -04005296void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
5297{
5298 Shader *shaderObject = getShader(shader);
5299 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04005300 shaderObject->getInfoLog(this, bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005301}
5302
5303void Context::getShaderPrecisionFormat(GLenum shadertype,
5304 GLenum precisiontype,
5305 GLint *range,
5306 GLint *precision)
5307{
5308 // TODO(jmadill): Compute shaders.
5309
5310 switch (shadertype)
5311 {
5312 case GL_VERTEX_SHADER:
5313 switch (precisiontype)
5314 {
5315 case GL_LOW_FLOAT:
5316 mCaps.vertexLowpFloat.get(range, precision);
5317 break;
5318 case GL_MEDIUM_FLOAT:
5319 mCaps.vertexMediumpFloat.get(range, precision);
5320 break;
5321 case GL_HIGH_FLOAT:
5322 mCaps.vertexHighpFloat.get(range, precision);
5323 break;
5324
5325 case GL_LOW_INT:
5326 mCaps.vertexLowpInt.get(range, precision);
5327 break;
5328 case GL_MEDIUM_INT:
5329 mCaps.vertexMediumpInt.get(range, precision);
5330 break;
5331 case GL_HIGH_INT:
5332 mCaps.vertexHighpInt.get(range, precision);
5333 break;
5334
5335 default:
5336 UNREACHABLE();
5337 return;
5338 }
5339 break;
5340
5341 case GL_FRAGMENT_SHADER:
5342 switch (precisiontype)
5343 {
5344 case GL_LOW_FLOAT:
5345 mCaps.fragmentLowpFloat.get(range, precision);
5346 break;
5347 case GL_MEDIUM_FLOAT:
5348 mCaps.fragmentMediumpFloat.get(range, precision);
5349 break;
5350 case GL_HIGH_FLOAT:
5351 mCaps.fragmentHighpFloat.get(range, precision);
5352 break;
5353
5354 case GL_LOW_INT:
5355 mCaps.fragmentLowpInt.get(range, precision);
5356 break;
5357 case GL_MEDIUM_INT:
5358 mCaps.fragmentMediumpInt.get(range, precision);
5359 break;
5360 case GL_HIGH_INT:
5361 mCaps.fragmentHighpInt.get(range, precision);
5362 break;
5363
5364 default:
5365 UNREACHABLE();
5366 return;
5367 }
5368 break;
5369
5370 default:
5371 UNREACHABLE();
5372 return;
5373 }
5374}
5375
5376void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
5377{
5378 Shader *shaderObject = getShader(shader);
5379 ASSERT(shaderObject);
5380 shaderObject->getSource(bufsize, length, source);
5381}
5382
5383void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
5384{
5385 Program *programObject = getProgram(program);
5386 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005387 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005388}
5389
Brandon Jones59770802018-04-02 13:18:42 -07005390void Context::getUniformfvRobust(GLuint program,
5391 GLint location,
5392 GLsizei bufSize,
5393 GLsizei *length,
5394 GLfloat *params)
5395{
5396 getUniformfv(program, location, params);
5397}
5398
Jamie Madillc1d770e2017-04-13 17:31:24 -04005399void Context::getUniformiv(GLuint program, GLint location, GLint *params)
5400{
5401 Program *programObject = getProgram(program);
5402 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005403 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005404}
5405
Brandon Jones59770802018-04-02 13:18:42 -07005406void Context::getUniformivRobust(GLuint program,
5407 GLint location,
5408 GLsizei bufSize,
5409 GLsizei *length,
5410 GLint *params)
5411{
5412 getUniformiv(program, location, params);
5413}
5414
Jamie Madillc1d770e2017-04-13 17:31:24 -04005415GLint Context::getUniformLocation(GLuint program, const GLchar *name)
5416{
5417 Program *programObject = getProgram(program);
5418 ASSERT(programObject);
5419 return programObject->getUniformLocation(name);
5420}
5421
5422GLboolean Context::isBuffer(GLuint buffer)
5423{
5424 if (buffer == 0)
5425 {
5426 return GL_FALSE;
5427 }
5428
5429 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
5430}
5431
5432GLboolean Context::isEnabled(GLenum cap)
5433{
5434 return mGLState.getEnableFeature(cap);
5435}
5436
5437GLboolean Context::isFramebuffer(GLuint framebuffer)
5438{
5439 if (framebuffer == 0)
5440 {
5441 return GL_FALSE;
5442 }
5443
5444 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
5445}
5446
5447GLboolean Context::isProgram(GLuint program)
5448{
5449 if (program == 0)
5450 {
5451 return GL_FALSE;
5452 }
5453
5454 return (getProgram(program) ? GL_TRUE : GL_FALSE);
5455}
5456
5457GLboolean Context::isRenderbuffer(GLuint renderbuffer)
5458{
5459 if (renderbuffer == 0)
5460 {
5461 return GL_FALSE;
5462 }
5463
5464 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
5465}
5466
5467GLboolean Context::isShader(GLuint shader)
5468{
5469 if (shader == 0)
5470 {
5471 return GL_FALSE;
5472 }
5473
5474 return (getShader(shader) ? GL_TRUE : GL_FALSE);
5475}
5476
5477GLboolean Context::isTexture(GLuint texture)
5478{
5479 if (texture == 0)
5480 {
5481 return GL_FALSE;
5482 }
5483
5484 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
5485}
5486
5487void Context::linkProgram(GLuint program)
5488{
5489 Program *programObject = getProgram(program);
5490 ASSERT(programObject);
5491 handleError(programObject->link(this));
Martin Radev0abb7a22017-08-28 15:34:45 +03005492 mGLState.onProgramExecutableChange(programObject);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005493}
5494
5495void Context::releaseShaderCompiler()
5496{
Jamie Madill4928b7c2017-06-20 12:57:39 -04005497 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005498}
5499
5500void Context::shaderBinary(GLsizei n,
5501 const GLuint *shaders,
5502 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04005503 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005504 GLsizei length)
5505{
5506 // No binary shader formats are supported.
5507 UNIMPLEMENTED();
5508}
5509
5510void Context::shaderSource(GLuint shader,
5511 GLsizei count,
5512 const GLchar *const *string,
5513 const GLint *length)
5514{
5515 Shader *shaderObject = getShader(shader);
5516 ASSERT(shaderObject);
5517 shaderObject->setSource(count, string, length);
5518}
5519
5520void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
5521{
5522 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
5523}
5524
5525void Context::stencilMask(GLuint mask)
5526{
5527 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
5528}
5529
5530void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
5531{
5532 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
5533}
5534
5535void Context::uniform1f(GLint location, GLfloat x)
5536{
5537 Program *program = mGLState.getProgram();
5538 program->setUniform1fv(location, 1, &x);
5539}
5540
5541void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
5542{
5543 Program *program = mGLState.getProgram();
5544 program->setUniform1fv(location, count, v);
5545}
5546
5547void Context::uniform1i(GLint location, GLint x)
5548{
5549 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04005550 if (program->setUniform1iv(location, 1, &x) == Program::SetUniformResult::SamplerChanged)
5551 {
5552 mGLState.setObjectDirty(GL_PROGRAM);
5553 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005554}
5555
5556void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
5557{
5558 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04005559 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
5560 {
5561 mGLState.setObjectDirty(GL_PROGRAM);
5562 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005563}
5564
5565void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
5566{
5567 GLfloat xy[2] = {x, y};
5568 Program *program = mGLState.getProgram();
5569 program->setUniform2fv(location, 1, xy);
5570}
5571
5572void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
5573{
5574 Program *program = mGLState.getProgram();
5575 program->setUniform2fv(location, count, v);
5576}
5577
5578void Context::uniform2i(GLint location, GLint x, GLint y)
5579{
5580 GLint xy[2] = {x, y};
5581 Program *program = mGLState.getProgram();
5582 program->setUniform2iv(location, 1, xy);
5583}
5584
5585void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
5586{
5587 Program *program = mGLState.getProgram();
5588 program->setUniform2iv(location, count, v);
5589}
5590
5591void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
5592{
5593 GLfloat xyz[3] = {x, y, z};
5594 Program *program = mGLState.getProgram();
5595 program->setUniform3fv(location, 1, xyz);
5596}
5597
5598void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
5599{
5600 Program *program = mGLState.getProgram();
5601 program->setUniform3fv(location, count, v);
5602}
5603
5604void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
5605{
5606 GLint xyz[3] = {x, y, z};
5607 Program *program = mGLState.getProgram();
5608 program->setUniform3iv(location, 1, xyz);
5609}
5610
5611void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
5612{
5613 Program *program = mGLState.getProgram();
5614 program->setUniform3iv(location, count, v);
5615}
5616
5617void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
5618{
5619 GLfloat xyzw[4] = {x, y, z, w};
5620 Program *program = mGLState.getProgram();
5621 program->setUniform4fv(location, 1, xyzw);
5622}
5623
5624void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
5625{
5626 Program *program = mGLState.getProgram();
5627 program->setUniform4fv(location, count, v);
5628}
5629
5630void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
5631{
5632 GLint xyzw[4] = {x, y, z, w};
5633 Program *program = mGLState.getProgram();
5634 program->setUniform4iv(location, 1, xyzw);
5635}
5636
5637void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
5638{
5639 Program *program = mGLState.getProgram();
5640 program->setUniform4iv(location, count, v);
5641}
5642
5643void Context::uniformMatrix2fv(GLint location,
5644 GLsizei count,
5645 GLboolean transpose,
5646 const GLfloat *value)
5647{
5648 Program *program = mGLState.getProgram();
5649 program->setUniformMatrix2fv(location, count, transpose, value);
5650}
5651
5652void Context::uniformMatrix3fv(GLint location,
5653 GLsizei count,
5654 GLboolean transpose,
5655 const GLfloat *value)
5656{
5657 Program *program = mGLState.getProgram();
5658 program->setUniformMatrix3fv(location, count, transpose, value);
5659}
5660
5661void Context::uniformMatrix4fv(GLint location,
5662 GLsizei count,
5663 GLboolean transpose,
5664 const GLfloat *value)
5665{
5666 Program *program = mGLState.getProgram();
5667 program->setUniformMatrix4fv(location, count, transpose, value);
5668}
5669
5670void Context::validateProgram(GLuint program)
5671{
5672 Program *programObject = getProgram(program);
5673 ASSERT(programObject);
5674 programObject->validate(mCaps);
5675}
5676
Jiajia Qin5451d532017-11-16 17:16:34 +08005677void Context::validateProgramPipeline(GLuint pipeline)
5678{
5679 UNIMPLEMENTED();
5680}
5681
Jamie Madilld04908b2017-06-09 14:15:35 -04005682void Context::getProgramBinary(GLuint program,
5683 GLsizei bufSize,
5684 GLsizei *length,
5685 GLenum *binaryFormat,
5686 void *binary)
5687{
5688 Program *programObject = getProgram(program);
5689 ASSERT(programObject != nullptr);
5690
5691 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
5692}
5693
5694void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
5695{
5696 Program *programObject = getProgram(program);
5697 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04005698
Jamie Madilld04908b2017-06-09 14:15:35 -04005699 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
5700}
5701
Jamie Madillff325f12017-08-26 15:06:05 -04005702void Context::uniform1ui(GLint location, GLuint v0)
5703{
5704 Program *program = mGLState.getProgram();
5705 program->setUniform1uiv(location, 1, &v0);
5706}
5707
5708void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
5709{
5710 Program *program = mGLState.getProgram();
5711 const GLuint xy[] = {v0, v1};
5712 program->setUniform2uiv(location, 1, xy);
5713}
5714
5715void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
5716{
5717 Program *program = mGLState.getProgram();
5718 const GLuint xyz[] = {v0, v1, v2};
5719 program->setUniform3uiv(location, 1, xyz);
5720}
5721
5722void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
5723{
5724 Program *program = mGLState.getProgram();
5725 const GLuint xyzw[] = {v0, v1, v2, v3};
5726 program->setUniform4uiv(location, 1, xyzw);
5727}
5728
5729void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
5730{
5731 Program *program = mGLState.getProgram();
5732 program->setUniform1uiv(location, count, value);
5733}
5734void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
5735{
5736 Program *program = mGLState.getProgram();
5737 program->setUniform2uiv(location, count, value);
5738}
5739
5740void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
5741{
5742 Program *program = mGLState.getProgram();
5743 program->setUniform3uiv(location, count, value);
5744}
5745
5746void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
5747{
5748 Program *program = mGLState.getProgram();
5749 program->setUniform4uiv(location, count, value);
5750}
5751
Jamie Madillf0e04492017-08-26 15:28:42 -04005752void Context::genQueries(GLsizei n, GLuint *ids)
5753{
5754 for (GLsizei i = 0; i < n; i++)
5755 {
5756 GLuint handle = mQueryHandleAllocator.allocate();
5757 mQueryMap.assign(handle, nullptr);
5758 ids[i] = handle;
5759 }
5760}
5761
5762void Context::deleteQueries(GLsizei n, const GLuint *ids)
5763{
5764 for (int i = 0; i < n; i++)
5765 {
5766 GLuint query = ids[i];
5767
5768 Query *queryObject = nullptr;
5769 if (mQueryMap.erase(query, &queryObject))
5770 {
5771 mQueryHandleAllocator.release(query);
5772 if (queryObject)
5773 {
5774 queryObject->release(this);
5775 }
5776 }
5777 }
5778}
5779
5780GLboolean Context::isQuery(GLuint id)
5781{
Corentin Wallezad3ae902018-03-09 13:40:42 -05005782 return (getQuery(id, false, QueryType::InvalidEnum) != nullptr) ? GL_TRUE : GL_FALSE;
Jamie Madillf0e04492017-08-26 15:28:42 -04005783}
5784
Jamie Madillc8c95812017-08-26 18:40:09 -04005785void Context::uniformMatrix2x3fv(GLint location,
5786 GLsizei count,
5787 GLboolean transpose,
5788 const GLfloat *value)
5789{
5790 Program *program = mGLState.getProgram();
5791 program->setUniformMatrix2x3fv(location, count, transpose, value);
5792}
5793
5794void Context::uniformMatrix3x2fv(GLint location,
5795 GLsizei count,
5796 GLboolean transpose,
5797 const GLfloat *value)
5798{
5799 Program *program = mGLState.getProgram();
5800 program->setUniformMatrix3x2fv(location, count, transpose, value);
5801}
5802
5803void Context::uniformMatrix2x4fv(GLint location,
5804 GLsizei count,
5805 GLboolean transpose,
5806 const GLfloat *value)
5807{
5808 Program *program = mGLState.getProgram();
5809 program->setUniformMatrix2x4fv(location, count, transpose, value);
5810}
5811
5812void Context::uniformMatrix4x2fv(GLint location,
5813 GLsizei count,
5814 GLboolean transpose,
5815 const GLfloat *value)
5816{
5817 Program *program = mGLState.getProgram();
5818 program->setUniformMatrix4x2fv(location, count, transpose, value);
5819}
5820
5821void Context::uniformMatrix3x4fv(GLint location,
5822 GLsizei count,
5823 GLboolean transpose,
5824 const GLfloat *value)
5825{
5826 Program *program = mGLState.getProgram();
5827 program->setUniformMatrix3x4fv(location, count, transpose, value);
5828}
5829
5830void Context::uniformMatrix4x3fv(GLint location,
5831 GLsizei count,
5832 GLboolean transpose,
5833 const GLfloat *value)
5834{
5835 Program *program = mGLState.getProgram();
5836 program->setUniformMatrix4x3fv(location, count, transpose, value);
5837}
5838
Jamie Madilld7576732017-08-26 18:49:50 -04005839void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
5840{
5841 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5842 {
5843 GLuint vertexArray = arrays[arrayIndex];
5844
5845 if (arrays[arrayIndex] != 0)
5846 {
5847 VertexArray *vertexArrayObject = nullptr;
5848 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
5849 {
5850 if (vertexArrayObject != nullptr)
5851 {
5852 detachVertexArray(vertexArray);
5853 vertexArrayObject->onDestroy(this);
5854 }
5855
5856 mVertexArrayHandleAllocator.release(vertexArray);
5857 }
5858 }
5859 }
5860}
5861
5862void Context::genVertexArrays(GLsizei n, GLuint *arrays)
5863{
5864 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5865 {
5866 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
5867 mVertexArrayMap.assign(vertexArray, nullptr);
5868 arrays[arrayIndex] = vertexArray;
5869 }
5870}
5871
5872bool Context::isVertexArray(GLuint array)
5873{
5874 if (array == 0)
5875 {
5876 return GL_FALSE;
5877 }
5878
5879 VertexArray *vao = getVertexArray(array);
5880 return (vao != nullptr ? GL_TRUE : GL_FALSE);
5881}
5882
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04005883void Context::endTransformFeedback()
5884{
5885 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5886 transformFeedback->end(this);
5887}
5888
5889void Context::transformFeedbackVaryings(GLuint program,
5890 GLsizei count,
5891 const GLchar *const *varyings,
5892 GLenum bufferMode)
5893{
5894 Program *programObject = getProgram(program);
5895 ASSERT(programObject);
5896 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
5897}
5898
5899void Context::getTransformFeedbackVarying(GLuint program,
5900 GLuint index,
5901 GLsizei bufSize,
5902 GLsizei *length,
5903 GLsizei *size,
5904 GLenum *type,
5905 GLchar *name)
5906{
5907 Program *programObject = getProgram(program);
5908 ASSERT(programObject);
5909 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
5910}
5911
5912void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
5913{
5914 for (int i = 0; i < n; i++)
5915 {
5916 GLuint transformFeedback = ids[i];
5917 if (transformFeedback == 0)
5918 {
5919 continue;
5920 }
5921
5922 TransformFeedback *transformFeedbackObject = nullptr;
5923 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
5924 {
5925 if (transformFeedbackObject != nullptr)
5926 {
5927 detachTransformFeedback(transformFeedback);
5928 transformFeedbackObject->release(this);
5929 }
5930
5931 mTransformFeedbackHandleAllocator.release(transformFeedback);
5932 }
5933 }
5934}
5935
5936void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
5937{
5938 for (int i = 0; i < n; i++)
5939 {
5940 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
5941 mTransformFeedbackMap.assign(transformFeedback, nullptr);
5942 ids[i] = transformFeedback;
5943 }
5944}
5945
5946bool Context::isTransformFeedback(GLuint id)
5947{
5948 if (id == 0)
5949 {
5950 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
5951 // returns FALSE
5952 return GL_FALSE;
5953 }
5954
5955 const TransformFeedback *transformFeedback = getTransformFeedback(id);
5956 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
5957}
5958
5959void Context::pauseTransformFeedback()
5960{
5961 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5962 transformFeedback->pause();
5963}
5964
5965void Context::resumeTransformFeedback()
5966{
5967 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5968 transformFeedback->resume();
5969}
5970
Jamie Madill12e957f2017-08-26 21:42:26 -04005971void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
5972{
5973 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04005974 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04005975}
5976
Brandon Jones59770802018-04-02 13:18:42 -07005977void Context::getUniformuivRobust(GLuint program,
5978 GLint location,
5979 GLsizei bufSize,
5980 GLsizei *length,
5981 GLuint *params)
5982{
5983 getUniformuiv(program, location, params);
5984}
5985
Jamie Madill12e957f2017-08-26 21:42:26 -04005986GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
5987{
5988 const Program *programObject = getProgram(program);
5989 return programObject->getFragDataLocation(name);
5990}
5991
5992void Context::getUniformIndices(GLuint program,
5993 GLsizei uniformCount,
5994 const GLchar *const *uniformNames,
5995 GLuint *uniformIndices)
5996{
5997 const Program *programObject = getProgram(program);
5998 if (!programObject->isLinked())
5999 {
6000 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6001 {
6002 uniformIndices[uniformId] = GL_INVALID_INDEX;
6003 }
6004 }
6005 else
6006 {
6007 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6008 {
6009 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
6010 }
6011 }
6012}
6013
6014void Context::getActiveUniformsiv(GLuint program,
6015 GLsizei uniformCount,
6016 const GLuint *uniformIndices,
6017 GLenum pname,
6018 GLint *params)
6019{
6020 const Program *programObject = getProgram(program);
6021 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6022 {
6023 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08006024 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04006025 }
6026}
6027
6028GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
6029{
6030 const Program *programObject = getProgram(program);
6031 return programObject->getUniformBlockIndex(uniformBlockName);
6032}
6033
6034void Context::getActiveUniformBlockiv(GLuint program,
6035 GLuint uniformBlockIndex,
6036 GLenum pname,
6037 GLint *params)
6038{
6039 const Program *programObject = getProgram(program);
6040 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
6041}
6042
Brandon Jones59770802018-04-02 13:18:42 -07006043void Context::getActiveUniformBlockivRobust(GLuint program,
6044 GLuint uniformBlockIndex,
6045 GLenum pname,
6046 GLsizei bufSize,
6047 GLsizei *length,
6048 GLint *params)
6049{
6050 getActiveUniformBlockiv(program, uniformBlockIndex, pname, params);
6051}
6052
Jamie Madill12e957f2017-08-26 21:42:26 -04006053void Context::getActiveUniformBlockName(GLuint program,
6054 GLuint uniformBlockIndex,
6055 GLsizei bufSize,
6056 GLsizei *length,
6057 GLchar *uniformBlockName)
6058{
6059 const Program *programObject = getProgram(program);
6060 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
6061}
6062
6063void Context::uniformBlockBinding(GLuint program,
6064 GLuint uniformBlockIndex,
6065 GLuint uniformBlockBinding)
6066{
6067 Program *programObject = getProgram(program);
6068 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
6069}
6070
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006071GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
6072{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006073 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
6074 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006075
Jamie Madill70b5bb02017-08-28 13:32:37 -04006076 Sync *syncObject = getSync(syncHandle);
6077 Error error = syncObject->set(condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006078 if (error.isError())
6079 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04006080 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006081 handleError(error);
6082 return nullptr;
6083 }
6084
Jamie Madill70b5bb02017-08-28 13:32:37 -04006085 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006086}
6087
6088GLboolean Context::isSync(GLsync sync)
6089{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006090 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006091}
6092
6093GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6094{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006095 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006096
6097 GLenum result = GL_WAIT_FAILED;
6098 handleError(syncObject->clientWait(flags, timeout, &result));
6099 return result;
6100}
6101
6102void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6103{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006104 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006105 handleError(syncObject->serverWait(flags, timeout));
6106}
6107
6108void Context::getInteger64v(GLenum pname, GLint64 *params)
6109{
6110 GLenum nativeType = GL_NONE;
6111 unsigned int numParams = 0;
6112 getQueryParameterInfo(pname, &nativeType, &numParams);
6113
6114 if (nativeType == GL_INT_64_ANGLEX)
6115 {
6116 getInteger64vImpl(pname, params);
6117 }
6118 else
6119 {
6120 CastStateValues(this, nativeType, pname, numParams, params);
6121 }
6122}
6123
Brandon Jones59770802018-04-02 13:18:42 -07006124void Context::getInteger64vRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint64 *data)
6125{
6126 getInteger64v(pname, data);
6127}
6128
Corentin Wallez336129f2017-10-17 15:55:40 -04006129void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04006130{
6131 Buffer *buffer = mGLState.getTargetBuffer(target);
6132 QueryBufferParameteri64v(buffer, pname, params);
6133}
6134
Brandon Jones59770802018-04-02 13:18:42 -07006135void Context::getBufferParameteri64vRobust(BufferBinding target,
6136 GLenum pname,
6137 GLsizei bufSize,
6138 GLsizei *length,
6139 GLint64 *params)
6140{
6141 getBufferParameteri64v(target, pname, params);
6142}
6143
Jamie Madill3ef140a2017-08-26 23:11:21 -04006144void Context::genSamplers(GLsizei count, GLuint *samplers)
6145{
6146 for (int i = 0; i < count; i++)
6147 {
6148 samplers[i] = mState.mSamplers->createSampler();
6149 }
6150}
6151
6152void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
6153{
6154 for (int i = 0; i < count; i++)
6155 {
6156 GLuint sampler = samplers[i];
6157
6158 if (mState.mSamplers->getSampler(sampler))
6159 {
6160 detachSampler(sampler);
6161 }
6162
6163 mState.mSamplers->deleteObject(this, sampler);
6164 }
6165}
6166
6167void Context::getInternalformativ(GLenum target,
6168 GLenum internalformat,
6169 GLenum pname,
6170 GLsizei bufSize,
6171 GLint *params)
6172{
6173 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
6174 QueryInternalFormativ(formatCaps, pname, bufSize, params);
6175}
6176
Brandon Jones59770802018-04-02 13:18:42 -07006177void Context::getInternalformativRobust(GLenum target,
6178 GLenum internalformat,
6179 GLenum pname,
6180 GLsizei bufSize,
6181 GLsizei *length,
6182 GLint *params)
6183{
6184 getInternalformativ(target, internalformat, pname, bufSize, params);
6185}
6186
Jiajia Qin5451d532017-11-16 17:16:34 +08006187void Context::programUniform1i(GLuint program, GLint location, GLint v0)
6188{
6189 programUniform1iv(program, location, 1, &v0);
6190}
6191
6192void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
6193{
6194 GLint xy[2] = {v0, v1};
6195 programUniform2iv(program, location, 1, xy);
6196}
6197
6198void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
6199{
6200 GLint xyz[3] = {v0, v1, v2};
6201 programUniform3iv(program, location, 1, xyz);
6202}
6203
6204void Context::programUniform4i(GLuint program,
6205 GLint location,
6206 GLint v0,
6207 GLint v1,
6208 GLint v2,
6209 GLint v3)
6210{
6211 GLint xyzw[4] = {v0, v1, v2, v3};
6212 programUniform4iv(program, location, 1, xyzw);
6213}
6214
6215void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
6216{
6217 programUniform1uiv(program, location, 1, &v0);
6218}
6219
6220void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
6221{
6222 GLuint xy[2] = {v0, v1};
6223 programUniform2uiv(program, location, 1, xy);
6224}
6225
6226void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
6227{
6228 GLuint xyz[3] = {v0, v1, v2};
6229 programUniform3uiv(program, location, 1, xyz);
6230}
6231
6232void Context::programUniform4ui(GLuint program,
6233 GLint location,
6234 GLuint v0,
6235 GLuint v1,
6236 GLuint v2,
6237 GLuint v3)
6238{
6239 GLuint xyzw[4] = {v0, v1, v2, v3};
6240 programUniform4uiv(program, location, 1, xyzw);
6241}
6242
6243void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
6244{
6245 programUniform1fv(program, location, 1, &v0);
6246}
6247
6248void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
6249{
6250 GLfloat xy[2] = {v0, v1};
6251 programUniform2fv(program, location, 1, xy);
6252}
6253
6254void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
6255{
6256 GLfloat xyz[3] = {v0, v1, v2};
6257 programUniform3fv(program, location, 1, xyz);
6258}
6259
6260void Context::programUniform4f(GLuint program,
6261 GLint location,
6262 GLfloat v0,
6263 GLfloat v1,
6264 GLfloat v2,
6265 GLfloat v3)
6266{
6267 GLfloat xyzw[4] = {v0, v1, v2, v3};
6268 programUniform4fv(program, location, 1, xyzw);
6269}
6270
Jamie Madill81c2e252017-09-09 23:32:46 -04006271void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6272{
6273 Program *programObject = getProgram(program);
6274 ASSERT(programObject);
6275 if (programObject->setUniform1iv(location, count, value) ==
6276 Program::SetUniformResult::SamplerChanged)
6277 {
6278 mGLState.setObjectDirty(GL_PROGRAM);
6279 }
6280}
6281
Jiajia Qin5451d532017-11-16 17:16:34 +08006282void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6283{
6284 Program *programObject = getProgram(program);
6285 ASSERT(programObject);
6286 programObject->setUniform2iv(location, count, value);
6287}
6288
6289void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6290{
6291 Program *programObject = getProgram(program);
6292 ASSERT(programObject);
6293 programObject->setUniform3iv(location, count, value);
6294}
6295
6296void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6297{
6298 Program *programObject = getProgram(program);
6299 ASSERT(programObject);
6300 programObject->setUniform4iv(location, count, value);
6301}
6302
6303void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6304{
6305 Program *programObject = getProgram(program);
6306 ASSERT(programObject);
6307 programObject->setUniform1uiv(location, count, value);
6308}
6309
6310void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6311{
6312 Program *programObject = getProgram(program);
6313 ASSERT(programObject);
6314 programObject->setUniform2uiv(location, count, value);
6315}
6316
6317void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6318{
6319 Program *programObject = getProgram(program);
6320 ASSERT(programObject);
6321 programObject->setUniform3uiv(location, count, value);
6322}
6323
6324void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6325{
6326 Program *programObject = getProgram(program);
6327 ASSERT(programObject);
6328 programObject->setUniform4uiv(location, count, value);
6329}
6330
6331void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6332{
6333 Program *programObject = getProgram(program);
6334 ASSERT(programObject);
6335 programObject->setUniform1fv(location, count, value);
6336}
6337
6338void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6339{
6340 Program *programObject = getProgram(program);
6341 ASSERT(programObject);
6342 programObject->setUniform2fv(location, count, value);
6343}
6344
6345void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6346{
6347 Program *programObject = getProgram(program);
6348 ASSERT(programObject);
6349 programObject->setUniform3fv(location, count, value);
6350}
6351
6352void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6353{
6354 Program *programObject = getProgram(program);
6355 ASSERT(programObject);
6356 programObject->setUniform4fv(location, count, value);
6357}
6358
6359void Context::programUniformMatrix2fv(GLuint program,
6360 GLint location,
6361 GLsizei count,
6362 GLboolean transpose,
6363 const GLfloat *value)
6364{
6365 Program *programObject = getProgram(program);
6366 ASSERT(programObject);
6367 programObject->setUniformMatrix2fv(location, count, transpose, value);
6368}
6369
6370void Context::programUniformMatrix3fv(GLuint program,
6371 GLint location,
6372 GLsizei count,
6373 GLboolean transpose,
6374 const GLfloat *value)
6375{
6376 Program *programObject = getProgram(program);
6377 ASSERT(programObject);
6378 programObject->setUniformMatrix3fv(location, count, transpose, value);
6379}
6380
6381void Context::programUniformMatrix4fv(GLuint program,
6382 GLint location,
6383 GLsizei count,
6384 GLboolean transpose,
6385 const GLfloat *value)
6386{
6387 Program *programObject = getProgram(program);
6388 ASSERT(programObject);
6389 programObject->setUniformMatrix4fv(location, count, transpose, value);
6390}
6391
6392void Context::programUniformMatrix2x3fv(GLuint program,
6393 GLint location,
6394 GLsizei count,
6395 GLboolean transpose,
6396 const GLfloat *value)
6397{
6398 Program *programObject = getProgram(program);
6399 ASSERT(programObject);
6400 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
6401}
6402
6403void Context::programUniformMatrix3x2fv(GLuint program,
6404 GLint location,
6405 GLsizei count,
6406 GLboolean transpose,
6407 const GLfloat *value)
6408{
6409 Program *programObject = getProgram(program);
6410 ASSERT(programObject);
6411 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
6412}
6413
6414void Context::programUniformMatrix2x4fv(GLuint program,
6415 GLint location,
6416 GLsizei count,
6417 GLboolean transpose,
6418 const GLfloat *value)
6419{
6420 Program *programObject = getProgram(program);
6421 ASSERT(programObject);
6422 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
6423}
6424
6425void Context::programUniformMatrix4x2fv(GLuint program,
6426 GLint location,
6427 GLsizei count,
6428 GLboolean transpose,
6429 const GLfloat *value)
6430{
6431 Program *programObject = getProgram(program);
6432 ASSERT(programObject);
6433 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
6434}
6435
6436void Context::programUniformMatrix3x4fv(GLuint program,
6437 GLint location,
6438 GLsizei count,
6439 GLboolean transpose,
6440 const GLfloat *value)
6441{
6442 Program *programObject = getProgram(program);
6443 ASSERT(programObject);
6444 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
6445}
6446
6447void Context::programUniformMatrix4x3fv(GLuint program,
6448 GLint location,
6449 GLsizei count,
6450 GLboolean transpose,
6451 const GLfloat *value)
6452{
6453 Program *programObject = getProgram(program);
6454 ASSERT(programObject);
6455 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
6456}
6457
Jamie Madill81c2e252017-09-09 23:32:46 -04006458void Context::onTextureChange(const Texture *texture)
6459{
6460 // Conservatively assume all textures are dirty.
6461 // TODO(jmadill): More fine-grained update.
6462 mGLState.setObjectDirty(GL_TEXTURE);
6463}
6464
James Darpiniane8a93c62018-01-04 18:02:24 -08006465bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
6466{
6467 return mGLState.isCurrentTransformFeedback(tf);
6468}
6469bool Context::isCurrentVertexArray(const VertexArray *va) const
6470{
6471 return mGLState.isCurrentVertexArray(va);
6472}
6473
Yunchao Hea336b902017-08-02 16:05:21 +08006474void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
6475{
6476 for (int i = 0; i < count; i++)
6477 {
6478 pipelines[i] = createProgramPipeline();
6479 }
6480}
6481
6482void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
6483{
6484 for (int i = 0; i < count; i++)
6485 {
6486 if (pipelines[i] != 0)
6487 {
6488 deleteProgramPipeline(pipelines[i]);
6489 }
6490 }
6491}
6492
6493GLboolean Context::isProgramPipeline(GLuint pipeline)
6494{
6495 if (pipeline == 0)
6496 {
6497 return GL_FALSE;
6498 }
6499
6500 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
6501}
6502
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006503void Context::finishFenceNV(GLuint fence)
6504{
6505 FenceNV *fenceObject = getFenceNV(fence);
6506
6507 ASSERT(fenceObject && fenceObject->isSet());
6508 handleError(fenceObject->finish());
6509}
6510
6511void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
6512{
6513 FenceNV *fenceObject = getFenceNV(fence);
6514
6515 ASSERT(fenceObject && fenceObject->isSet());
6516
6517 switch (pname)
6518 {
6519 case GL_FENCE_STATUS_NV:
6520 {
6521 // GL_NV_fence spec:
6522 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
6523 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
6524 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
6525 GLboolean status = GL_TRUE;
6526 if (fenceObject->getStatus() != GL_TRUE)
6527 {
6528 ANGLE_CONTEXT_TRY(fenceObject->test(&status));
6529 }
6530 *params = status;
6531 break;
6532 }
6533
6534 case GL_FENCE_CONDITION_NV:
6535 {
6536 *params = static_cast<GLint>(fenceObject->getCondition());
6537 break;
6538 }
6539
6540 default:
6541 UNREACHABLE();
6542 }
6543}
6544
6545void Context::getTranslatedShaderSource(GLuint shader,
6546 GLsizei bufsize,
6547 GLsizei *length,
6548 GLchar *source)
6549{
6550 Shader *shaderObject = getShader(shader);
6551 ASSERT(shaderObject);
6552 shaderObject->getTranslatedSourceWithDebugInfo(this, bufsize, length, source);
6553}
6554
6555void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
6556{
6557 Program *programObject = getProgram(program);
6558 ASSERT(programObject);
6559
6560 programObject->getUniformfv(this, location, params);
6561}
6562
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006563void Context::getnUniformfvRobust(GLuint program,
6564 GLint location,
6565 GLsizei bufSize,
6566 GLsizei *length,
6567 GLfloat *params)
6568{
6569 UNIMPLEMENTED();
6570}
6571
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006572void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
6573{
6574 Program *programObject = getProgram(program);
6575 ASSERT(programObject);
6576
6577 programObject->getUniformiv(this, location, params);
6578}
6579
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006580void Context::getnUniformivRobust(GLuint program,
6581 GLint location,
6582 GLsizei bufSize,
6583 GLsizei *length,
6584 GLint *params)
6585{
6586 UNIMPLEMENTED();
6587}
6588
6589void Context::getnUniformuivRobust(GLuint program,
6590 GLint location,
6591 GLsizei bufSize,
6592 GLsizei *length,
6593 GLuint *params)
6594{
6595 UNIMPLEMENTED();
6596}
6597
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006598GLboolean Context::isFenceNV(GLuint fence)
6599{
6600 FenceNV *fenceObject = getFenceNV(fence);
6601
6602 if (fenceObject == nullptr)
6603 {
6604 return GL_FALSE;
6605 }
6606
6607 // GL_NV_fence spec:
6608 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
6609 // existing fence.
6610 return fenceObject->isSet();
6611}
6612
6613void Context::readnPixels(GLint x,
6614 GLint y,
6615 GLsizei width,
6616 GLsizei height,
6617 GLenum format,
6618 GLenum type,
6619 GLsizei bufSize,
6620 void *data)
6621{
6622 return readPixels(x, y, width, height, format, type, data);
6623}
6624
Jamie Madill007530e2017-12-28 14:27:04 -05006625void Context::setFenceNV(GLuint fence, GLenum condition)
6626{
6627 ASSERT(condition == GL_ALL_COMPLETED_NV);
6628
6629 FenceNV *fenceObject = getFenceNV(fence);
6630 ASSERT(fenceObject != nullptr);
6631 handleError(fenceObject->set(condition));
6632}
6633
6634GLboolean Context::testFenceNV(GLuint fence)
6635{
6636 FenceNV *fenceObject = getFenceNV(fence);
6637
6638 ASSERT(fenceObject != nullptr);
6639 ASSERT(fenceObject->isSet() == GL_TRUE);
6640
6641 GLboolean result = GL_TRUE;
6642 Error error = fenceObject->test(&result);
6643 if (error.isError())
6644 {
6645 handleError(error);
6646 return GL_TRUE;
6647 }
6648
6649 return result;
6650}
6651
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006652void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006653{
6654 Texture *texture = getTargetTexture(target);
Rafael Cintron05a449a2018-06-20 18:08:04 -07006655 egl::Image *imageObject = static_cast<egl::Image *>(image);
Corentin Wallez99d492c2018-02-27 15:17:10 -05006656 handleError(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05006657}
6658
Jamie Madillfa920eb2018-01-04 11:45:50 -05006659void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006660{
6661 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Rafael Cintron05a449a2018-06-20 18:08:04 -07006662 egl::Image *imageObject = static_cast<egl::Image *>(image);
Jamie Madill007530e2017-12-28 14:27:04 -05006663 handleError(renderbuffer->setStorageEGLImageTarget(this, imageObject));
6664}
6665
Jamie Madillfa920eb2018-01-04 11:45:50 -05006666void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
6667{
6668 UNIMPLEMENTED();
6669}
6670
Jamie Madill5b772312018-03-08 20:28:32 -05006671bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
6672{
6673 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
6674 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
6675 // to the fact that it is stored internally as a float, and so would require conversion
6676 // if returned from Context::getIntegerv. Since this conversion is already implemented
6677 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
6678 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
6679 // application.
6680 switch (pname)
6681 {
6682 case GL_COMPRESSED_TEXTURE_FORMATS:
6683 {
6684 *type = GL_INT;
6685 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
6686 return true;
6687 }
6688 case GL_SHADER_BINARY_FORMATS:
6689 {
6690 *type = GL_INT;
6691 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
6692 return true;
6693 }
6694
6695 case GL_MAX_VERTEX_ATTRIBS:
6696 case GL_MAX_VERTEX_UNIFORM_VECTORS:
6697 case GL_MAX_VARYING_VECTORS:
6698 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
6699 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
6700 case GL_MAX_TEXTURE_IMAGE_UNITS:
6701 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
6702 case GL_MAX_RENDERBUFFER_SIZE:
6703 case GL_NUM_SHADER_BINARY_FORMATS:
6704 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
6705 case GL_ARRAY_BUFFER_BINDING:
6706 case GL_FRAMEBUFFER_BINDING:
6707 case GL_RENDERBUFFER_BINDING:
6708 case GL_CURRENT_PROGRAM:
6709 case GL_PACK_ALIGNMENT:
6710 case GL_UNPACK_ALIGNMENT:
6711 case GL_GENERATE_MIPMAP_HINT:
6712 case GL_RED_BITS:
6713 case GL_GREEN_BITS:
6714 case GL_BLUE_BITS:
6715 case GL_ALPHA_BITS:
6716 case GL_DEPTH_BITS:
6717 case GL_STENCIL_BITS:
6718 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
6719 case GL_CULL_FACE_MODE:
6720 case GL_FRONT_FACE:
6721 case GL_ACTIVE_TEXTURE:
6722 case GL_STENCIL_FUNC:
6723 case GL_STENCIL_VALUE_MASK:
6724 case GL_STENCIL_REF:
6725 case GL_STENCIL_FAIL:
6726 case GL_STENCIL_PASS_DEPTH_FAIL:
6727 case GL_STENCIL_PASS_DEPTH_PASS:
6728 case GL_STENCIL_BACK_FUNC:
6729 case GL_STENCIL_BACK_VALUE_MASK:
6730 case GL_STENCIL_BACK_REF:
6731 case GL_STENCIL_BACK_FAIL:
6732 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
6733 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
6734 case GL_DEPTH_FUNC:
6735 case GL_BLEND_SRC_RGB:
6736 case GL_BLEND_SRC_ALPHA:
6737 case GL_BLEND_DST_RGB:
6738 case GL_BLEND_DST_ALPHA:
6739 case GL_BLEND_EQUATION_RGB:
6740 case GL_BLEND_EQUATION_ALPHA:
6741 case GL_STENCIL_WRITEMASK:
6742 case GL_STENCIL_BACK_WRITEMASK:
6743 case GL_STENCIL_CLEAR_VALUE:
6744 case GL_SUBPIXEL_BITS:
6745 case GL_MAX_TEXTURE_SIZE:
6746 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
6747 case GL_SAMPLE_BUFFERS:
6748 case GL_SAMPLES:
6749 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
6750 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
6751 case GL_TEXTURE_BINDING_2D:
6752 case GL_TEXTURE_BINDING_CUBE_MAP:
6753 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
6754 {
6755 *type = GL_INT;
6756 *numParams = 1;
6757 return true;
6758 }
6759 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6760 {
6761 if (!getExtensions().packReverseRowOrder)
6762 {
6763 return false;
6764 }
6765 *type = GL_INT;
6766 *numParams = 1;
6767 return true;
6768 }
6769 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
6770 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
6771 {
6772 if (!getExtensions().textureRectangle)
6773 {
6774 return false;
6775 }
6776 *type = GL_INT;
6777 *numParams = 1;
6778 return true;
6779 }
6780 case GL_MAX_DRAW_BUFFERS_EXT:
6781 case GL_MAX_COLOR_ATTACHMENTS_EXT:
6782 {
6783 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
6784 {
6785 return false;
6786 }
6787 *type = GL_INT;
6788 *numParams = 1;
6789 return true;
6790 }
6791 case GL_MAX_VIEWPORT_DIMS:
6792 {
6793 *type = GL_INT;
6794 *numParams = 2;
6795 return true;
6796 }
6797 case GL_VIEWPORT:
6798 case GL_SCISSOR_BOX:
6799 {
6800 *type = GL_INT;
6801 *numParams = 4;
6802 return true;
6803 }
6804 case GL_SHADER_COMPILER:
6805 case GL_SAMPLE_COVERAGE_INVERT:
6806 case GL_DEPTH_WRITEMASK:
6807 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
6808 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
6809 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
6810 // bool-natural
6811 case GL_SAMPLE_COVERAGE:
6812 case GL_SCISSOR_TEST:
6813 case GL_STENCIL_TEST:
6814 case GL_DEPTH_TEST:
6815 case GL_BLEND:
6816 case GL_DITHER:
6817 case GL_CONTEXT_ROBUST_ACCESS_EXT:
6818 {
6819 *type = GL_BOOL;
6820 *numParams = 1;
6821 return true;
6822 }
6823 case GL_COLOR_WRITEMASK:
6824 {
6825 *type = GL_BOOL;
6826 *numParams = 4;
6827 return true;
6828 }
6829 case GL_POLYGON_OFFSET_FACTOR:
6830 case GL_POLYGON_OFFSET_UNITS:
6831 case GL_SAMPLE_COVERAGE_VALUE:
6832 case GL_DEPTH_CLEAR_VALUE:
6833 case GL_LINE_WIDTH:
6834 {
6835 *type = GL_FLOAT;
6836 *numParams = 1;
6837 return true;
6838 }
6839 case GL_ALIASED_LINE_WIDTH_RANGE:
6840 case GL_ALIASED_POINT_SIZE_RANGE:
6841 case GL_DEPTH_RANGE:
6842 {
6843 *type = GL_FLOAT;
6844 *numParams = 2;
6845 return true;
6846 }
6847 case GL_COLOR_CLEAR_VALUE:
6848 case GL_BLEND_COLOR:
6849 {
6850 *type = GL_FLOAT;
6851 *numParams = 4;
6852 return true;
6853 }
6854 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
6855 if (!getExtensions().textureFilterAnisotropic)
6856 {
6857 return false;
6858 }
6859 *type = GL_FLOAT;
6860 *numParams = 1;
6861 return true;
6862 case GL_TIMESTAMP_EXT:
6863 if (!getExtensions().disjointTimerQuery)
6864 {
6865 return false;
6866 }
6867 *type = GL_INT_64_ANGLEX;
6868 *numParams = 1;
6869 return true;
6870 case GL_GPU_DISJOINT_EXT:
6871 if (!getExtensions().disjointTimerQuery)
6872 {
6873 return false;
6874 }
6875 *type = GL_INT;
6876 *numParams = 1;
6877 return true;
6878 case GL_COVERAGE_MODULATION_CHROMIUM:
6879 if (!getExtensions().framebufferMixedSamples)
6880 {
6881 return false;
6882 }
6883 *type = GL_INT;
6884 *numParams = 1;
6885 return true;
6886 case GL_TEXTURE_BINDING_EXTERNAL_OES:
6887 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
6888 {
6889 return false;
6890 }
6891 *type = GL_INT;
6892 *numParams = 1;
6893 return true;
6894 }
6895
6896 if (getExtensions().debug)
6897 {
6898 switch (pname)
6899 {
6900 case GL_DEBUG_LOGGED_MESSAGES:
6901 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
6902 case GL_DEBUG_GROUP_STACK_DEPTH:
6903 case GL_MAX_DEBUG_MESSAGE_LENGTH:
6904 case GL_MAX_DEBUG_LOGGED_MESSAGES:
6905 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
6906 case GL_MAX_LABEL_LENGTH:
6907 *type = GL_INT;
6908 *numParams = 1;
6909 return true;
6910
6911 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
6912 case GL_DEBUG_OUTPUT:
6913 *type = GL_BOOL;
6914 *numParams = 1;
6915 return true;
6916 }
6917 }
6918
6919 if (getExtensions().multisampleCompatibility)
6920 {
6921 switch (pname)
6922 {
6923 case GL_MULTISAMPLE_EXT:
6924 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
6925 *type = GL_BOOL;
6926 *numParams = 1;
6927 return true;
6928 }
6929 }
6930
6931 if (getExtensions().pathRendering)
6932 {
6933 switch (pname)
6934 {
6935 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
6936 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
6937 *type = GL_FLOAT;
6938 *numParams = 16;
6939 return true;
6940 }
6941 }
6942
6943 if (getExtensions().bindGeneratesResource)
6944 {
6945 switch (pname)
6946 {
6947 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
6948 *type = GL_BOOL;
6949 *numParams = 1;
6950 return true;
6951 }
6952 }
6953
6954 if (getExtensions().clientArrays)
6955 {
6956 switch (pname)
6957 {
6958 case GL_CLIENT_ARRAYS_ANGLE:
6959 *type = GL_BOOL;
6960 *numParams = 1;
6961 return true;
6962 }
6963 }
6964
6965 if (getExtensions().sRGBWriteControl)
6966 {
6967 switch (pname)
6968 {
6969 case GL_FRAMEBUFFER_SRGB_EXT:
6970 *type = GL_BOOL;
6971 *numParams = 1;
6972 return true;
6973 }
6974 }
6975
6976 if (getExtensions().robustResourceInitialization &&
6977 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
6978 {
6979 *type = GL_BOOL;
6980 *numParams = 1;
6981 return true;
6982 }
6983
6984 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
6985 {
6986 *type = GL_BOOL;
6987 *numParams = 1;
6988 return true;
6989 }
6990
6991 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
6992 switch (pname)
6993 {
6994 // case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE // equivalent to FRAMEBUFFER_BINDING
6995 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
6996 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
6997 {
6998 return false;
6999 }
7000 *type = GL_INT;
7001 *numParams = 1;
7002 return true;
7003
7004 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
7005 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7006 {
7007 return false;
7008 }
7009 *type = GL_INT;
7010 *numParams = 1;
7011 return true;
7012
7013 case GL_PROGRAM_BINARY_FORMATS_OES:
7014 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7015 {
7016 return false;
7017 }
7018 *type = GL_INT;
7019 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
7020 return true;
7021
7022 case GL_PACK_ROW_LENGTH:
7023 case GL_PACK_SKIP_ROWS:
7024 case GL_PACK_SKIP_PIXELS:
7025 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
7026 {
7027 return false;
7028 }
7029 *type = GL_INT;
7030 *numParams = 1;
7031 return true;
7032 case GL_UNPACK_ROW_LENGTH:
7033 case GL_UNPACK_SKIP_ROWS:
7034 case GL_UNPACK_SKIP_PIXELS:
7035 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
7036 {
7037 return false;
7038 }
7039 *type = GL_INT;
7040 *numParams = 1;
7041 return true;
7042 case GL_VERTEX_ARRAY_BINDING:
7043 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
7044 {
7045 return false;
7046 }
7047 *type = GL_INT;
7048 *numParams = 1;
7049 return true;
7050 case GL_PIXEL_PACK_BUFFER_BINDING:
7051 case GL_PIXEL_UNPACK_BUFFER_BINDING:
7052 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
7053 {
7054 return false;
7055 }
7056 *type = GL_INT;
7057 *numParams = 1;
7058 return true;
7059 case GL_MAX_SAMPLES:
7060 {
7061 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
7062 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
7063 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
7064 {
7065 return false;
7066 }
7067 *type = GL_INT;
7068 *numParams = 1;
7069 return true;
7070
7071 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
7072 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
7073 {
7074 return false;
7075 }
7076 *type = GL_INT;
7077 *numParams = 1;
7078 return true;
7079 }
7080 }
7081
7082 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
7083 {
7084 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
7085 {
7086 return false;
7087 }
7088 *type = GL_INT;
7089 *numParams = 1;
7090 return true;
7091 }
7092
7093 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
7094 {
7095 *type = GL_INT;
7096 *numParams = 1;
7097 return true;
7098 }
7099
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007100 if (getClientVersion() < Version(2, 0))
7101 {
7102 switch (pname)
7103 {
7104 case GL_ALPHA_TEST_FUNC:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007105 case GL_CLIENT_ACTIVE_TEXTURE:
7106 case GL_MATRIX_MODE:
7107 case GL_MAX_TEXTURE_UNITS:
7108 case GL_MAX_MODELVIEW_STACK_DEPTH:
7109 case GL_MAX_PROJECTION_STACK_DEPTH:
7110 case GL_MAX_TEXTURE_STACK_DEPTH:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007111 case GL_MAX_LIGHTS:
Lingfeng Yang060088a2018-05-30 20:40:57 -07007112 case GL_MAX_CLIP_PLANES:
Lingfeng Yangabb09f12018-04-16 10:43:53 -07007113 case GL_VERTEX_ARRAY_STRIDE:
7114 case GL_NORMAL_ARRAY_STRIDE:
7115 case GL_COLOR_ARRAY_STRIDE:
7116 case GL_TEXTURE_COORD_ARRAY_STRIDE:
7117 case GL_VERTEX_ARRAY_SIZE:
7118 case GL_COLOR_ARRAY_SIZE:
7119 case GL_TEXTURE_COORD_ARRAY_SIZE:
7120 case GL_VERTEX_ARRAY_TYPE:
7121 case GL_NORMAL_ARRAY_TYPE:
7122 case GL_COLOR_ARRAY_TYPE:
7123 case GL_TEXTURE_COORD_ARRAY_TYPE:
7124 case GL_VERTEX_ARRAY_BUFFER_BINDING:
7125 case GL_NORMAL_ARRAY_BUFFER_BINDING:
7126 case GL_COLOR_ARRAY_BUFFER_BINDING:
7127 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
7128 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
7129 case GL_POINT_SIZE_ARRAY_TYPE_OES:
7130 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
Lingfeng Yanga0cfa872018-05-30 21:12:17 -07007131 case GL_SHADE_MODEL:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007132 *type = GL_INT;
7133 *numParams = 1;
7134 return true;
7135 case GL_ALPHA_TEST_REF:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007136 case GL_FOG_DENSITY:
7137 case GL_FOG_START:
7138 case GL_FOG_END:
7139 case GL_FOG_MODE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007140 case GL_POINT_SIZE:
7141 case GL_POINT_SIZE_MIN:
7142 case GL_POINT_SIZE_MAX:
7143 case GL_POINT_FADE_THRESHOLD_SIZE:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007144 *type = GL_FLOAT;
7145 *numParams = 1;
7146 return true;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007147 case GL_SMOOTH_POINT_SIZE_RANGE:
7148 *type = GL_FLOAT;
7149 *numParams = 2;
7150 return true;
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007151 case GL_CURRENT_COLOR:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007152 case GL_CURRENT_TEXTURE_COORDS:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007153 case GL_LIGHT_MODEL_AMBIENT:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007154 case GL_FOG_COLOR:
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007155 *type = GL_FLOAT;
7156 *numParams = 4;
7157 return true;
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007158 case GL_CURRENT_NORMAL:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007159 case GL_POINT_DISTANCE_ATTENUATION:
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007160 *type = GL_FLOAT;
7161 *numParams = 3;
7162 return true;
Lingfeng Yang3a41af62018-04-09 07:28:56 -07007163 case GL_MODELVIEW_MATRIX:
7164 case GL_PROJECTION_MATRIX:
7165 case GL_TEXTURE_MATRIX:
7166 *type = GL_FLOAT;
7167 *numParams = 16;
7168 return true;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007169 case GL_LIGHT_MODEL_TWO_SIDE:
7170 *type = GL_BOOL;
7171 *numParams = 1;
7172 return true;
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007173 }
7174 }
7175
Jamie Madill5b772312018-03-08 20:28:32 -05007176 if (getClientVersion() < Version(3, 0))
7177 {
7178 return false;
7179 }
7180
7181 // Check for ES3.0+ parameter names
7182 switch (pname)
7183 {
7184 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
7185 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
7186 case GL_UNIFORM_BUFFER_BINDING:
7187 case GL_TRANSFORM_FEEDBACK_BINDING:
7188 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7189 case GL_COPY_READ_BUFFER_BINDING:
7190 case GL_COPY_WRITE_BUFFER_BINDING:
7191 case GL_SAMPLER_BINDING:
7192 case GL_READ_BUFFER:
7193 case GL_TEXTURE_BINDING_3D:
7194 case GL_TEXTURE_BINDING_2D_ARRAY:
7195 case GL_MAX_3D_TEXTURE_SIZE:
7196 case GL_MAX_ARRAY_TEXTURE_LAYERS:
7197 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
7198 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
7199 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
7200 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
7201 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
7202 case GL_MAX_VARYING_COMPONENTS:
7203 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
7204 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
7205 case GL_MIN_PROGRAM_TEXEL_OFFSET:
7206 case GL_MAX_PROGRAM_TEXEL_OFFSET:
7207 case GL_NUM_EXTENSIONS:
7208 case GL_MAJOR_VERSION:
7209 case GL_MINOR_VERSION:
7210 case GL_MAX_ELEMENTS_INDICES:
7211 case GL_MAX_ELEMENTS_VERTICES:
7212 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
7213 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
7214 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
7215 case GL_UNPACK_IMAGE_HEIGHT:
7216 case GL_UNPACK_SKIP_IMAGES:
7217 {
7218 *type = GL_INT;
7219 *numParams = 1;
7220 return true;
7221 }
7222
7223 case GL_MAX_ELEMENT_INDEX:
7224 case GL_MAX_UNIFORM_BLOCK_SIZE:
7225 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
7226 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
7227 case GL_MAX_SERVER_WAIT_TIMEOUT:
7228 {
7229 *type = GL_INT_64_ANGLEX;
7230 *numParams = 1;
7231 return true;
7232 }
7233
7234 case GL_TRANSFORM_FEEDBACK_ACTIVE:
7235 case GL_TRANSFORM_FEEDBACK_PAUSED:
7236 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
7237 case GL_RASTERIZER_DISCARD:
7238 {
7239 *type = GL_BOOL;
7240 *numParams = 1;
7241 return true;
7242 }
7243
7244 case GL_MAX_TEXTURE_LOD_BIAS:
7245 {
7246 *type = GL_FLOAT;
7247 *numParams = 1;
7248 return true;
7249 }
7250 }
7251
7252 if (getExtensions().requestExtension)
7253 {
7254 switch (pname)
7255 {
7256 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
7257 *type = GL_INT;
7258 *numParams = 1;
7259 return true;
7260 }
7261 }
7262
7263 if (getClientVersion() < Version(3, 1))
7264 {
7265 return false;
7266 }
7267
7268 switch (pname)
7269 {
7270 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7271 case GL_DRAW_INDIRECT_BUFFER_BINDING:
7272 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
7273 case GL_MAX_FRAMEBUFFER_WIDTH:
7274 case GL_MAX_FRAMEBUFFER_HEIGHT:
7275 case GL_MAX_FRAMEBUFFER_SAMPLES:
7276 case GL_MAX_SAMPLE_MASK_WORDS:
7277 case GL_MAX_COLOR_TEXTURE_SAMPLES:
7278 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
7279 case GL_MAX_INTEGER_SAMPLES:
7280 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
7281 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
7282 case GL_MAX_VERTEX_ATTRIB_STRIDE:
7283 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
7284 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
7285 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
7286 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
7287 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
7288 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
7289 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
7290 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
7291 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
7292 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
7293 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
7294 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
7295 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
7296 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
7297 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
7298 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
7299 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
7300 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
7301 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
7302 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
7303 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
7304 case GL_MAX_UNIFORM_LOCATIONS:
7305 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
7306 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
7307 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
7308 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
7309 case GL_MAX_IMAGE_UNITS:
7310 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
7311 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
7312 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
7313 case GL_SHADER_STORAGE_BUFFER_BINDING:
7314 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
7315 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
7316 *type = GL_INT;
7317 *numParams = 1;
7318 return true;
7319 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7320 *type = GL_INT_64_ANGLEX;
7321 *numParams = 1;
7322 return true;
7323 case GL_SAMPLE_MASK:
7324 *type = GL_BOOL;
7325 *numParams = 1;
7326 return true;
7327 }
7328
7329 if (getExtensions().geometryShader)
7330 {
7331 switch (pname)
7332 {
7333 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7334 case GL_LAYER_PROVOKING_VERTEX_EXT:
7335 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7336 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7337 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7338 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7339 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7340 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7341 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7342 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7343 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7344 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7345 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7346 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7347 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7348 *type = GL_INT;
7349 *numParams = 1;
7350 return true;
7351 }
7352 }
7353
7354 return false;
7355}
7356
7357bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7358{
7359 if (getClientVersion() < Version(3, 0))
7360 {
7361 return false;
7362 }
7363
7364 switch (target)
7365 {
7366 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7367 case GL_UNIFORM_BUFFER_BINDING:
7368 {
7369 *type = GL_INT;
7370 *numParams = 1;
7371 return true;
7372 }
7373 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7374 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7375 case GL_UNIFORM_BUFFER_START:
7376 case GL_UNIFORM_BUFFER_SIZE:
7377 {
7378 *type = GL_INT_64_ANGLEX;
7379 *numParams = 1;
7380 return true;
7381 }
7382 }
7383
7384 if (getClientVersion() < Version(3, 1))
7385 {
7386 return false;
7387 }
7388
7389 switch (target)
7390 {
7391 case GL_IMAGE_BINDING_LAYERED:
7392 {
7393 *type = GL_BOOL;
7394 *numParams = 1;
7395 return true;
7396 }
7397 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7398 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7399 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7400 case GL_SHADER_STORAGE_BUFFER_BINDING:
7401 case GL_VERTEX_BINDING_BUFFER:
7402 case GL_VERTEX_BINDING_DIVISOR:
7403 case GL_VERTEX_BINDING_OFFSET:
7404 case GL_VERTEX_BINDING_STRIDE:
7405 case GL_SAMPLE_MASK_VALUE:
7406 case GL_IMAGE_BINDING_NAME:
7407 case GL_IMAGE_BINDING_LEVEL:
7408 case GL_IMAGE_BINDING_LAYER:
7409 case GL_IMAGE_BINDING_ACCESS:
7410 case GL_IMAGE_BINDING_FORMAT:
7411 {
7412 *type = GL_INT;
7413 *numParams = 1;
7414 return true;
7415 }
7416 case GL_ATOMIC_COUNTER_BUFFER_START:
7417 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
7418 case GL_SHADER_STORAGE_BUFFER_START:
7419 case GL_SHADER_STORAGE_BUFFER_SIZE:
7420 {
7421 *type = GL_INT_64_ANGLEX;
7422 *numParams = 1;
7423 return true;
7424 }
7425 }
7426
7427 return false;
7428}
7429
7430Program *Context::getProgram(GLuint handle) const
7431{
7432 return mState.mShaderPrograms->getProgram(handle);
7433}
7434
7435Shader *Context::getShader(GLuint handle) const
7436{
7437 return mState.mShaderPrograms->getShader(handle);
7438}
7439
7440bool Context::isTextureGenerated(GLuint texture) const
7441{
7442 return mState.mTextures->isHandleGenerated(texture);
7443}
7444
7445bool Context::isBufferGenerated(GLuint buffer) const
7446{
7447 return mState.mBuffers->isHandleGenerated(buffer);
7448}
7449
7450bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
7451{
7452 return mState.mRenderbuffers->isHandleGenerated(renderbuffer);
7453}
7454
7455bool Context::isFramebufferGenerated(GLuint framebuffer) const
7456{
7457 return mState.mFramebuffers->isHandleGenerated(framebuffer);
7458}
7459
7460bool Context::isProgramPipelineGenerated(GLuint pipeline) const
7461{
7462 return mState.mPipelines->isHandleGenerated(pipeline);
7463}
7464
7465bool Context::usingDisplayTextureShareGroup() const
7466{
7467 return mDisplayTextureShareGroup;
7468}
7469
7470GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
7471{
7472 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
7473 internalformat == GL_DEPTH_STENCIL
7474 ? GL_DEPTH24_STENCIL8
7475 : internalformat;
7476}
7477
Jamie Madillc29968b2016-01-20 11:17:23 -05007478} // namespace gl