blob: 1ca65fed43e3a0a6e04d81eb901e5c08a6318c7e [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),
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700282 mImplementation(implFactory->createContext(mState)),
Jamie Madill2f348d22017-06-05 10:50:59 -0400283 mCompiler(),
Geoff Lang4fb8a8b2018-06-01 16:47:57 -0400284 mGLState(GetDebug(attribs),
285 GetBindGeneratesResource(attribs),
286 GetClientArraysEnabled(attribs),
287 GetRobustResourceInit(attribs),
288 memoryProgramCache != nullptr),
Corentin Walleze3b10e82015-05-20 11:06:25 -0400289 mConfig(config),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500290 mClientType(EGL_OPENGL_ES_API),
291 mHasBeenCurrent(false),
292 mContextLost(false),
293 mResetStatus(GL_NO_ERROR),
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700294 mContextLostForced(false),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500295 mResetStrategy(GetResetStrategy(attribs)),
296 mRobustAccess(GetRobustAccess(attribs)),
Geoff Lang33f11fb2018-05-07 13:42:47 -0400297 mSurfacelessSupported(displayExtensions.surfacelessContext),
298 mExplicitContextAvailable(clientExtensions.explicitContext),
Jamie Madill61e16b42017-06-19 11:13:23 -0400299 mCurrentSurface(static_cast<egl::Surface *>(EGL_NO_SURFACE)),
300 mCurrentDisplay(static_cast<egl::Display *>(EGL_NO_DISPLAY)),
Jamie Madille14951e2017-03-09 18:55:16 -0500301 mWebGLContext(GetWebGLContext(attribs)),
Geoff Lang0ab41fa2018-03-14 11:03:30 -0400302 mExtensionsEnabled(GetExtensionsEnabled(attribs, mWebGLContext)),
Jamie Madill32447362017-06-28 14:53:52 -0400303 mMemoryProgramCache(memoryProgramCache),
Jamie Madillb3f26b92017-07-19 15:07:41 -0400304 mScratchBuffer(1000u),
305 mZeroFilledBuffer(1000u)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000306{
Jamie Madill5b772312018-03-08 20:28:32 -0500307 // Needed to solve a Clang warning of unused variables.
Jamie Madillc6dbc252018-04-30 19:07:56 -0400308 ANGLE_UNUSED_VARIABLE(mSavedArgsType);
309 ANGLE_UNUSED_VARIABLE(mParamsBuffer);
Geoff Lang33f11fb2018-05-07 13:42:47 -0400310}
Jamie Madill5b772312018-03-08 20:28:32 -0500311
Geoff Lang33f11fb2018-05-07 13:42:47 -0400312void Context::initialize()
313{
314 mImplementation->setMemoryProgramCache(mMemoryProgramCache);
Jamie Madill14bbb3f2017-09-12 15:23:01 -0400315
Geoff Lang33f11fb2018-05-07 13:42:47 -0400316 initCaps();
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700317 initWorkarounds();
Geoff Langc0b9ef42014-07-02 10:02:37 -0400318
Geoff Lang4fb8a8b2018-06-01 16:47:57 -0400319 mGLState.initialize(this);
Régis Fénéon83107972015-02-05 12:57:44 +0100320
Shannon Woods53a94a82014-06-24 15:20:36 -0400321 mFenceNVHandleAllocator.setBaseHandle(0);
Geoff Lang7dca1862013-07-30 16:30:46 -0400322
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000323 // [OpenGL ES 2.0.24] section 3.7 page 83:
Corentin Wallez336129f2017-10-17 15:55:40 -0400324 // In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have two-dimensional
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000325 // and cube map texture state vectors respectively associated with them.
326 // In order that access to these initial textures not be lost, they are treated as texture
327 // objects all of whose names are 0.
328
Corentin Wallez99d492c2018-02-27 15:17:10 -0500329 Texture *zeroTexture2D = new Texture(mImplementation.get(), 0, TextureType::_2D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800330 mZeroTextures[TextureType::_2D].set(this, zeroTexture2D);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500331
Corentin Wallez99d492c2018-02-27 15:17:10 -0500332 Texture *zeroTextureCube = new Texture(mImplementation.get(), 0, TextureType::CubeMap);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800333 mZeroTextures[TextureType::CubeMap].set(this, zeroTextureCube);
Geoff Lang76b10c92014-09-05 16:28:14 -0400334
Geoff Langeb66a6e2016-10-31 13:06:12 -0400335 if (getClientVersion() >= Version(3, 0))
Geoff Lang76b10c92014-09-05 16:28:14 -0400336 {
337 // TODO: These could also be enabled via extension
Corentin Wallez99d492c2018-02-27 15:17:10 -0500338 Texture *zeroTexture3D = new Texture(mImplementation.get(), 0, TextureType::_3D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800339 mZeroTextures[TextureType::_3D].set(this, zeroTexture3D);
Geoff Lang76b10c92014-09-05 16:28:14 -0400340
Corentin Wallez99d492c2018-02-27 15:17:10 -0500341 Texture *zeroTexture2DArray = new Texture(mImplementation.get(), 0, TextureType::_2DArray);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800342 mZeroTextures[TextureType::_2DArray].set(this, zeroTexture2DArray);
Geoff Lang76b10c92014-09-05 16:28:14 -0400343 }
Geoff Lang3b573612016-10-31 14:08:10 -0400344 if (getClientVersion() >= Version(3, 1))
345 {
346 Texture *zeroTexture2DMultisample =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500347 new Texture(mImplementation.get(), 0, TextureType::_2DMultisample);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800348 mZeroTextures[TextureType::_2DMultisample].set(this, zeroTexture2DMultisample);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800349
Jiajia Qin6eafb042016-12-27 17:04:07 +0800350 for (unsigned int i = 0; i < mCaps.maxAtomicCounterBufferBindings; i++)
351 {
Qin Jiajia339f65b2018-02-27 12:52:48 +0800352 bindBufferRange(BufferBinding::AtomicCounter, i, 0, 0, 0);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800353 }
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800354
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800355 for (unsigned int i = 0; i < mCaps.maxShaderStorageBufferBindings; i++)
356 {
Corentin Wallez336129f2017-10-17 15:55:40 -0400357 bindBufferRange(BufferBinding::ShaderStorage, i, 0, 0, 0);
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800358 }
Geoff Lang3b573612016-10-31 14:08:10 -0400359 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000360
Geoff Langb0f917f2017-12-05 13:41:54 -0500361 if (mSupportedExtensions.textureRectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400362 {
363 Texture *zeroTextureRectangle =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500364 new Texture(mImplementation.get(), 0, TextureType::Rectangle);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800365 mZeroTextures[TextureType::Rectangle].set(this, zeroTextureRectangle);
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400366 }
367
Geoff Langb0f917f2017-12-05 13:41:54 -0500368 if (mSupportedExtensions.eglImageExternal || mSupportedExtensions.eglStreamConsumerExternal)
Ian Ewellbda75592016-04-18 17:25:54 -0400369 {
Corentin Wallez99d492c2018-02-27 15:17:10 -0500370 Texture *zeroTextureExternal = new Texture(mImplementation.get(), 0, TextureType::External);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800371 mZeroTextures[TextureType::External].set(this, zeroTextureExternal);
Ian Ewellbda75592016-04-18 17:25:54 -0400372 }
373
Jamie Madill4928b7c2017-06-20 12:57:39 -0400374 mGLState.initializeZeroTextures(this, mZeroTextures);
Jamie Madille6382c32014-11-07 15:05:26 -0500375
Jamie Madill57a89722013-07-02 11:57:03 -0400376 bindVertexArray(0);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000377
Geoff Langeb66a6e2016-10-31 13:06:12 -0400378 if (getClientVersion() >= Version(3, 0))
Geoff Lang1a683462015-09-29 15:09:59 -0400379 {
380 // [OpenGL ES 3.0.2] section 2.14.1 pg 85:
381 // In the initial state, a default transform feedback object is bound and treated as
382 // a transform feedback object with a name of zero. That object is bound any time
383 // BindTransformFeedback is called with id of zero
Jamie Madillf0dcb8b2017-08-26 19:05:13 -0400384 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Geoff Lang1a683462015-09-29 15:09:59 -0400385 }
Geoff Langc8058452014-02-03 12:04:11 -0500386
Corentin Wallez336129f2017-10-17 15:55:40 -0400387 for (auto type : angle::AllEnums<BufferBinding>())
388 {
389 bindBuffer(type, 0);
390 }
391
392 bindRenderbuffer(GL_RENDERBUFFER, 0);
393
394 for (unsigned int i = 0; i < mCaps.maxUniformBufferBindings; i++)
395 {
396 bindBufferRange(BufferBinding::Uniform, i, 0, 0, -1);
397 }
398
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700399 // Initialize GLES1 renderer if appropriate.
400 if (getClientVersion() < Version(2, 0))
401 {
402 mGLES1Renderer.reset(new GLES1Renderer());
403 }
404
Jamie Madillad9f24e2016-02-12 09:27:24 -0500405 // Initialize dirty bit masks
Jamie Madillc67323a2017-11-02 23:11:41 -0400406 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500407 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500408 // No dirty objects.
409
410 // Readpixels uses the pack state and read FBO
Jamie Madillc67323a2017-11-02 23:11:41 -0400411 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500412 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500413 mReadPixelsDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
414
415 mClearDirtyBits.set(State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED);
416 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
417 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR);
418 mClearDirtyBits.set(State::DIRTY_BIT_VIEWPORT);
419 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_COLOR);
420 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_DEPTH);
421 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_STENCIL);
422 mClearDirtyBits.set(State::DIRTY_BIT_COLOR_MASK);
423 mClearDirtyBits.set(State::DIRTY_BIT_DEPTH_MASK);
424 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT);
425 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_BACK);
426 mClearDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
427
428 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
429 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR);
Geoff Lang1d2c41d2016-10-19 16:14:46 -0700430 mBlitDirtyBits.set(State::DIRTY_BIT_FRAMEBUFFER_SRGB);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500431 mBlitDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
432 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
Jamie Madill437fa652016-05-03 15:13:24 -0400433
Xinghua Cao10a4d432017-11-28 14:46:26 +0800434 // TODO(xinghua.cao@intel.com): add other dirty bits and dirty objects.
435 mComputeDirtyBits.set(State::DIRTY_BIT_SHADER_STORAGE_BUFFER_BINDING);
436 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_BINDING);
437 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_EXECUTABLE);
438 mComputeDirtyBits.set(State::DIRTY_BIT_TEXTURE_BINDINGS);
439 mComputeDirtyBits.set(State::DIRTY_BIT_SAMPLER_BINDINGS);
Qin Jiajia62fcf622017-11-30 16:16:12 +0800440 mComputeDirtyBits.set(State::DIRTY_BIT_DISPATCH_INDIRECT_BUFFER_BINDING);
Jiajia Qin5ae6ee42018-03-06 17:39:42 +0800441 mComputeDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM_TEXTURES);
Xinghua Cao10a4d432017-11-28 14:46:26 +0800442
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400443 handleError(mImplementation->initialize());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000444}
445
Jamie Madill4928b7c2017-06-20 12:57:39 -0400446egl::Error Context::onDestroy(const egl::Display *display)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000447{
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700448 if (mGLES1Renderer)
449 {
450 mGLES1Renderer->onDestroy(this, &mGLState);
451 }
452
Jamie Madille7b3fe22018-04-05 09:42:46 -0400453 // Delete the Surface first to trigger a finish() in Vulkan.
Jamie Madille7b3fe22018-04-05 09:42:46 -0400454 ANGLE_TRY(releaseSurface(display));
455
Corentin Wallez80b24112015-08-25 16:41:57 -0400456 for (auto fence : mFenceNVMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000457 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400458 SafeDelete(fence.second);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000459 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400460 mFenceNVMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000461
Corentin Wallez80b24112015-08-25 16:41:57 -0400462 for (auto query : mQueryMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000463 {
Geoff Langf0aa8422015-09-29 15:08:34 -0400464 if (query.second != nullptr)
465 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400466 query.second->release(this);
Geoff Langf0aa8422015-09-29 15:08:34 -0400467 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000468 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400469 mQueryMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000470
Corentin Wallez80b24112015-08-25 16:41:57 -0400471 for (auto vertexArray : mVertexArrayMap)
Jamie Madill57a89722013-07-02 11:57:03 -0400472 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400473 if (vertexArray.second)
474 {
475 vertexArray.second->onDestroy(this);
476 }
Jamie Madill57a89722013-07-02 11:57:03 -0400477 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400478 mVertexArrayMap.clear();
Jamie Madill57a89722013-07-02 11:57:03 -0400479
Corentin Wallez80b24112015-08-25 16:41:57 -0400480 for (auto transformFeedback : mTransformFeedbackMap)
Geoff Langc8058452014-02-03 12:04:11 -0500481 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500482 if (transformFeedback.second != nullptr)
483 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500484 transformFeedback.second->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500485 }
Geoff Langc8058452014-02-03 12:04:11 -0500486 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400487 mTransformFeedbackMap.clear();
Geoff Langc8058452014-02-03 12:04:11 -0500488
Jamie Madill5b772312018-03-08 20:28:32 -0500489 for (BindingPointer<Texture> &zeroTexture : mZeroTextures)
Geoff Lang76b10c92014-09-05 16:28:14 -0400490 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800491 if (zeroTexture.get() != nullptr)
492 {
493 ANGLE_TRY(zeroTexture->onDestroy(this));
494 zeroTexture.set(this, nullptr);
495 }
Geoff Lang76b10c92014-09-05 16:28:14 -0400496 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000497
Jamie Madill2f348d22017-06-05 10:50:59 -0400498 releaseShaderCompiler();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500499
Jamie Madill4928b7c2017-06-20 12:57:39 -0400500 mGLState.reset(this);
501
Jamie Madill6c1f6712017-02-14 19:08:04 -0500502 mState.mBuffers->release(this);
503 mState.mShaderPrograms->release(this);
504 mState.mTextures->release(this);
505 mState.mRenderbuffers->release(this);
506 mState.mSamplers->release(this);
Jamie Madill70b5bb02017-08-28 13:32:37 -0400507 mState.mSyncs->release(this);
Jamie Madill6c1f6712017-02-14 19:08:04 -0500508 mState.mPaths->release(this);
509 mState.mFramebuffers->release(this);
Yunchao Hea336b902017-08-02 16:05:21 +0800510 mState.mPipelines->release(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400511
Jamie Madill76e471e2017-10-21 09:56:01 -0400512 mImplementation->onDestroy(this);
513
Jamie Madill4928b7c2017-06-20 12:57:39 -0400514 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000515}
516
Jamie Madill70ee0f62017-02-06 16:04:20 -0500517Context::~Context()
518{
519}
520
Jamie Madill4928b7c2017-06-20 12:57:39 -0400521egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000522{
Jamie Madill61e16b42017-06-19 11:13:23 -0400523 mCurrentDisplay = display;
524
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000525 if (!mHasBeenCurrent)
526 {
Geoff Lang33f11fb2018-05-07 13:42:47 -0400527 initialize();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000528 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500529 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400530 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000531
Corentin Wallezc295e512017-01-27 17:47:50 -0500532 int width = 0;
533 int height = 0;
534 if (surface != nullptr)
535 {
536 width = surface->getWidth();
537 height = surface->getHeight();
538 }
539
540 mGLState.setViewportParams(0, 0, width, height);
541 mGLState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000542
543 mHasBeenCurrent = true;
544 }
545
Jamie Madill1b94d432015-08-07 13:23:23 -0400546 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700547 mGLState.setAllDirtyBits();
Jamie Madill81c2e252017-09-09 23:32:46 -0400548 mGLState.setAllDirtyObjects();
Jamie Madill1b94d432015-08-07 13:23:23 -0400549
Jamie Madill4928b7c2017-06-20 12:57:39 -0400550 ANGLE_TRY(releaseSurface(display));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500551
552 Framebuffer *newDefault = nullptr;
553 if (surface != nullptr)
554 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400555 ANGLE_TRY(surface->setIsCurrent(this, true));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500556 mCurrentSurface = surface;
Geoff Langbf7b95d2018-05-01 16:48:21 -0400557 newDefault = surface->createDefaultFramebuffer(this);
Corentin Wallezccab69d2017-01-27 16:57:15 -0500558 }
559 else
560 {
Geoff Langbf7b95d2018-05-01 16:48:21 -0400561 newDefault = new Framebuffer(mImplementation.get());
Corentin Wallezccab69d2017-01-27 16:57:15 -0500562 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000563
Corentin Wallez37c39792015-08-20 14:19:46 -0400564 // Update default framebuffer, the binding of the previous default
565 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400566 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700567 if (mGLState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400568 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700569 mGLState.setReadFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400570 }
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700571 if (mGLState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400572 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700573 mGLState.setDrawFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400574 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500575 mState.mFramebuffers->setDefaultFramebuffer(newDefault);
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400576 }
Ian Ewell292f0052016-02-04 10:37:32 -0500577
578 // Notify the renderer of a context switch
Jamie Madill4928b7c2017-06-20 12:57:39 -0400579 mImplementation->onMakeCurrent(this);
580 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000581}
582
Jamie Madill4928b7c2017-06-20 12:57:39 -0400583egl::Error Context::releaseSurface(const egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400584{
Geoff Langbf7b95d2018-05-01 16:48:21 -0400585 gl::Framebuffer *defaultFramebuffer = mState.mFramebuffers->getFramebuffer(0);
Corentin Wallez51706ea2015-08-07 14:39:22 -0400586
Geoff Langbf7b95d2018-05-01 16:48:21 -0400587 // Remove the default framebuffer
588 if (mGLState.getReadFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500589 {
590 mGLState.setReadFramebufferBinding(nullptr);
591 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400592
593 if (mGLState.getDrawFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500594 {
595 mGLState.setDrawFramebufferBinding(nullptr);
596 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400597
598 if (defaultFramebuffer)
599 {
600 defaultFramebuffer->onDestroy(this);
601 delete defaultFramebuffer;
602 }
603
Corentin Wallezc295e512017-01-27 17:47:50 -0500604 mState.mFramebuffers->setDefaultFramebuffer(nullptr);
605
606 if (mCurrentSurface)
607 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400608 ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
Corentin Wallezc295e512017-01-27 17:47:50 -0500609 mCurrentSurface = nullptr;
610 }
Jamie Madill4928b7c2017-06-20 12:57:39 -0400611
612 return egl::NoError();
Jamie Madill77a72f62015-04-14 11:18:32 -0400613}
614
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000615GLuint Context::createBuffer()
616{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500617 return mState.mBuffers->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000618}
619
620GLuint Context::createProgram()
621{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500622 return mState.mShaderPrograms->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000623}
624
Jiawei Shao385b3e02018-03-21 09:43:28 +0800625GLuint Context::createShader(ShaderType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000626{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500627 return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000628}
629
630GLuint Context::createTexture()
631{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500632 return mState.mTextures->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000633}
634
635GLuint Context::createRenderbuffer()
636{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500637 return mState.mRenderbuffers->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000638}
639
Brandon Jones59770802018-04-02 13:18:42 -0700640GLuint Context::genPaths(GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300641{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500642 auto resultOrError = mState.mPaths->createPaths(mImplementation.get(), range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300643 if (resultOrError.isError())
644 {
645 handleError(resultOrError.getError());
646 return 0;
647 }
648 return resultOrError.getResult();
649}
650
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000651// Returns an unused framebuffer name
652GLuint Context::createFramebuffer()
653{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500654 return mState.mFramebuffers->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000655}
656
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500657void Context::genFencesNV(GLsizei n, GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000658{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500659 for (int i = 0; i < n; i++)
660 {
661 GLuint handle = mFenceNVHandleAllocator.allocate();
662 mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV()));
663 fences[i] = handle;
664 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000665}
666
Yunchao Hea336b902017-08-02 16:05:21 +0800667GLuint Context::createProgramPipeline()
668{
669 return mState.mPipelines->createProgramPipeline();
670}
671
Jiawei Shao385b3e02018-03-21 09:43:28 +0800672GLuint Context::createShaderProgramv(ShaderType type, GLsizei count, const GLchar *const *strings)
Jiajia Qin5451d532017-11-16 17:16:34 +0800673{
674 UNIMPLEMENTED();
675 return 0u;
676}
677
James Darpinian4d9d4832018-03-13 12:43:28 -0700678void Context::deleteBuffer(GLuint bufferName)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000679{
James Darpinian4d9d4832018-03-13 12:43:28 -0700680 Buffer *buffer = mState.mBuffers->getBuffer(bufferName);
681 if (buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000682 {
683 detachBuffer(buffer);
684 }
Jamie Madill893ab082014-05-16 16:56:10 -0400685
James Darpinian4d9d4832018-03-13 12:43:28 -0700686 mState.mBuffers->deleteObject(this, bufferName);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000687}
688
689void Context::deleteShader(GLuint shader)
690{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500691 mState.mShaderPrograms->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000692}
693
694void Context::deleteProgram(GLuint program)
695{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500696 mState.mShaderPrograms->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000697}
698
699void Context::deleteTexture(GLuint texture)
700{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500701 if (mState.mTextures->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000702 {
703 detachTexture(texture);
704 }
705
Jamie Madill6c1f6712017-02-14 19:08:04 -0500706 mState.mTextures->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000707}
708
709void Context::deleteRenderbuffer(GLuint renderbuffer)
710{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500711 if (mState.mRenderbuffers->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000712 {
713 detachRenderbuffer(renderbuffer);
714 }
Jamie Madill893ab082014-05-16 16:56:10 -0400715
Jamie Madill6c1f6712017-02-14 19:08:04 -0500716 mState.mRenderbuffers->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000717}
718
Jamie Madill7f0c5a42017-08-26 22:43:26 -0400719void Context::deleteSync(GLsync sync)
Jamie Madillcd055f82013-07-26 11:55:15 -0400720{
721 // The spec specifies the underlying Fence object is not deleted until all current
722 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
723 // and since our API is currently designed for being called from a single thread, we can delete
724 // the fence immediately.
Jamie Madill70b5bb02017-08-28 13:32:37 -0400725 mState.mSyncs->deleteObject(this, static_cast<GLuint>(reinterpret_cast<uintptr_t>(sync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400726}
727
Yunchao Hea336b902017-08-02 16:05:21 +0800728void Context::deleteProgramPipeline(GLuint pipeline)
729{
730 if (mState.mPipelines->getProgramPipeline(pipeline))
731 {
732 detachProgramPipeline(pipeline);
733 }
734
735 mState.mPipelines->deleteObject(this, pipeline);
736}
737
Sami Väisänene45e53b2016-05-25 10:36:04 +0300738void Context::deletePaths(GLuint first, GLsizei range)
739{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500740 mState.mPaths->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300741}
742
Brandon Jones59770802018-04-02 13:18:42 -0700743bool Context::isPath(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300744{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500745 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300746 if (pathObj == nullptr)
747 return false;
748
749 return pathObj->hasPathData();
750}
751
Brandon Jones59770802018-04-02 13:18:42 -0700752bool Context::isPathGenerated(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300753{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500754 return mState.mPaths->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300755}
756
Brandon Jones59770802018-04-02 13:18:42 -0700757void Context::pathCommands(GLuint path,
758 GLsizei numCommands,
759 const GLubyte *commands,
760 GLsizei numCoords,
761 GLenum coordType,
762 const void *coords)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300763{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500764 auto *pathObject = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300765
766 handleError(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
767}
768
Jamie Madill007530e2017-12-28 14:27:04 -0500769void Context::pathParameterf(GLuint path, GLenum pname, GLfloat value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300770{
Jamie Madill007530e2017-12-28 14:27:04 -0500771 Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300772
773 switch (pname)
774 {
775 case GL_PATH_STROKE_WIDTH_CHROMIUM:
776 pathObj->setStrokeWidth(value);
777 break;
778 case GL_PATH_END_CAPS_CHROMIUM:
779 pathObj->setEndCaps(static_cast<GLenum>(value));
780 break;
781 case GL_PATH_JOIN_STYLE_CHROMIUM:
782 pathObj->setJoinStyle(static_cast<GLenum>(value));
783 break;
784 case GL_PATH_MITER_LIMIT_CHROMIUM:
785 pathObj->setMiterLimit(value);
786 break;
787 case GL_PATH_STROKE_BOUND_CHROMIUM:
788 pathObj->setStrokeBound(value);
789 break;
790 default:
791 UNREACHABLE();
792 break;
793 }
794}
795
Jamie Madill007530e2017-12-28 14:27:04 -0500796void Context::pathParameteri(GLuint path, GLenum pname, GLint value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300797{
Jamie Madill007530e2017-12-28 14:27:04 -0500798 // TODO(jmadill): Should use proper clamping/casting.
799 pathParameterf(path, pname, static_cast<GLfloat>(value));
800}
801
802void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value)
803{
804 const Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300805
806 switch (pname)
807 {
808 case GL_PATH_STROKE_WIDTH_CHROMIUM:
809 *value = pathObj->getStrokeWidth();
810 break;
811 case GL_PATH_END_CAPS_CHROMIUM:
812 *value = static_cast<GLfloat>(pathObj->getEndCaps());
813 break;
814 case GL_PATH_JOIN_STYLE_CHROMIUM:
815 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
816 break;
817 case GL_PATH_MITER_LIMIT_CHROMIUM:
818 *value = pathObj->getMiterLimit();
819 break;
820 case GL_PATH_STROKE_BOUND_CHROMIUM:
821 *value = pathObj->getStrokeBound();
822 break;
823 default:
824 UNREACHABLE();
825 break;
826 }
827}
828
Jamie Madill007530e2017-12-28 14:27:04 -0500829void Context::getPathParameteriv(GLuint path, GLenum pname, GLint *value)
830{
831 GLfloat val = 0.0f;
832 getPathParameterfv(path, pname, value != nullptr ? &val : nullptr);
833 if (value)
834 *value = static_cast<GLint>(val);
835}
836
Brandon Jones59770802018-04-02 13:18:42 -0700837void Context::pathStencilFunc(GLenum func, GLint ref, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300838{
839 mGLState.setPathStencilFunc(func, ref, mask);
840}
841
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000842void Context::deleteFramebuffer(GLuint framebuffer)
843{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500844 if (mState.mFramebuffers->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000845 {
846 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000847 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500848
Jamie Madill6c1f6712017-02-14 19:08:04 -0500849 mState.mFramebuffers->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000850}
851
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500852void Context::deleteFencesNV(GLsizei n, const GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000853{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500854 for (int i = 0; i < n; i++)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000855 {
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500856 GLuint fence = fences[i];
857
858 FenceNV *fenceObject = nullptr;
859 if (mFenceNVMap.erase(fence, &fenceObject))
860 {
861 mFenceNVHandleAllocator.release(fence);
862 delete fenceObject;
863 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000864 }
865}
866
Geoff Lang70d0f492015-12-10 17:45:46 -0500867Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000868{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500869 return mState.mBuffers->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000870}
871
Jamie Madill570f7c82014-07-03 10:38:54 -0400872Texture *Context::getTexture(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000873{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500874 return mState.mTextures->getTexture(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000875}
876
Geoff Lang70d0f492015-12-10 17:45:46 -0500877Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000878{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500879 return mState.mRenderbuffers->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000880}
881
Jamie Madill70b5bb02017-08-28 13:32:37 -0400882Sync *Context::getSync(GLsync handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400883{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400884 return mState.mSyncs->getSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400885}
886
Jamie Madill57a89722013-07-02 11:57:03 -0400887VertexArray *Context::getVertexArray(GLuint handle) const
888{
Jamie Madill96a483b2017-06-27 16:49:21 -0400889 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -0400890}
891
Jamie Madilldc356042013-07-19 16:36:57 -0400892Sampler *Context::getSampler(GLuint handle) const
893{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500894 return mState.mSamplers->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400895}
896
Geoff Langc8058452014-02-03 12:04:11 -0500897TransformFeedback *Context::getTransformFeedback(GLuint handle) const
898{
Jamie Madill96a483b2017-06-27 16:49:21 -0400899 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -0500900}
901
Yunchao Hea336b902017-08-02 16:05:21 +0800902ProgramPipeline *Context::getProgramPipeline(GLuint handle) const
903{
904 return mState.mPipelines->getProgramPipeline(handle);
905}
906
Geoff Lang70d0f492015-12-10 17:45:46 -0500907LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
908{
909 switch (identifier)
910 {
911 case GL_BUFFER:
912 return getBuffer(name);
913 case GL_SHADER:
914 return getShader(name);
915 case GL_PROGRAM:
916 return getProgram(name);
917 case GL_VERTEX_ARRAY:
918 return getVertexArray(name);
919 case GL_QUERY:
920 return getQuery(name);
921 case GL_TRANSFORM_FEEDBACK:
922 return getTransformFeedback(name);
923 case GL_SAMPLER:
924 return getSampler(name);
925 case GL_TEXTURE:
926 return getTexture(name);
927 case GL_RENDERBUFFER:
928 return getRenderbuffer(name);
929 case GL_FRAMEBUFFER:
930 return getFramebuffer(name);
931 default:
932 UNREACHABLE();
933 return nullptr;
934 }
935}
936
937LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
938{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400939 return getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
Geoff Lang70d0f492015-12-10 17:45:46 -0500940}
941
Martin Radev9d901792016-07-15 15:58:58 +0300942void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
943{
944 LabeledObject *object = getLabeledObject(identifier, name);
945 ASSERT(object != nullptr);
946
947 std::string labelName = GetObjectLabelFromPointer(length, label);
948 object->setLabel(labelName);
Jamie Madill8693bdb2017-09-02 15:32:14 -0400949
950 // TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the
951 // specified object is active until we do this.
952 mGLState.setObjectDirty(identifier);
Martin Radev9d901792016-07-15 15:58:58 +0300953}
954
955void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
956{
957 LabeledObject *object = getLabeledObjectFromPtr(ptr);
958 ASSERT(object != nullptr);
959
960 std::string labelName = GetObjectLabelFromPointer(length, label);
961 object->setLabel(labelName);
962}
963
964void Context::getObjectLabel(GLenum identifier,
965 GLuint name,
966 GLsizei bufSize,
967 GLsizei *length,
968 GLchar *label) const
969{
970 LabeledObject *object = getLabeledObject(identifier, name);
971 ASSERT(object != nullptr);
972
973 const std::string &objectLabel = object->getLabel();
974 GetObjectLabelBase(objectLabel, bufSize, length, label);
975}
976
977void Context::getObjectPtrLabel(const void *ptr,
978 GLsizei bufSize,
979 GLsizei *length,
980 GLchar *label) const
981{
982 LabeledObject *object = getLabeledObjectFromPtr(ptr);
983 ASSERT(object != nullptr);
984
985 const std::string &objectLabel = object->getLabel();
986 GetObjectLabelBase(objectLabel, bufSize, length, label);
987}
988
Jamie Madilldc356042013-07-19 16:36:57 -0400989bool Context::isSampler(GLuint samplerName) const
990{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500991 return mState.mSamplers->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -0400992}
993
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800994void Context::bindTexture(TextureType target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000995{
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500996 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000997
Jamie Madilldedd7b92014-11-05 16:30:36 -0500998 if (handle == 0)
999 {
1000 texture = mZeroTextures[target].get();
1001 }
1002 else
1003 {
Corentin Wallez99d492c2018-02-27 15:17:10 -05001004 texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -05001005 }
1006
1007 ASSERT(texture);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001008 mGLState.setSamplerTexture(this, target, texture);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00001009}
1010
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001011void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001012{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001013 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1014 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001015 mGLState.setReadFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001016}
1017
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001018void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001019{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001020 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1021 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001022 mGLState.setDrawFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001023}
1024
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001025void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -04001026{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001027 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madill7267aa62018-04-17 15:28:21 -04001028 mGLState.setVertexArrayBinding(this, vertexArray);
Jamie Madill57a89722013-07-02 11:57:03 -04001029}
1030
Shao80957d92017-02-20 21:25:59 +08001031void Context::bindVertexBuffer(GLuint bindingIndex,
1032 GLuint bufferHandle,
1033 GLintptr offset,
1034 GLsizei stride)
1035{
1036 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001037 mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Shao80957d92017-02-20 21:25:59 +08001038}
1039
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001040void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -04001041{
Geoff Lang76b10c92014-09-05 16:28:14 -04001042 ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -04001043 Sampler *sampler =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001044 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001045 mGLState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04001046}
1047
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001048void Context::bindImageTexture(GLuint unit,
1049 GLuint texture,
1050 GLint level,
1051 GLboolean layered,
1052 GLint layer,
1053 GLenum access,
1054 GLenum format)
1055{
1056 Texture *tex = mState.mTextures->getTexture(texture);
1057 mGLState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
1058}
1059
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001060void Context::useProgram(GLuint program)
1061{
Jamie Madill6c1f6712017-02-14 19:08:04 -05001062 mGLState.setProgram(this, getProgram(program));
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001063}
1064
Jiajia Qin5451d532017-11-16 17:16:34 +08001065void Context::useProgramStages(GLuint pipeline, GLbitfield stages, GLuint program)
1066{
1067 UNIMPLEMENTED();
1068}
1069
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001070void Context::bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001071{
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001072 ASSERT(target == GL_TRANSFORM_FEEDBACK);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001073 TransformFeedback *transformFeedback =
1074 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001075 mGLState.setTransformFeedbackBinding(this, transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -05001076}
1077
Yunchao Hea336b902017-08-02 16:05:21 +08001078void Context::bindProgramPipeline(GLuint pipelineHandle)
1079{
1080 ProgramPipeline *pipeline =
1081 mState.mPipelines->checkProgramPipelineAllocation(mImplementation.get(), pipelineHandle);
1082 mGLState.setProgramPipelineBinding(this, pipeline);
1083}
1084
Corentin Wallezad3ae902018-03-09 13:40:42 -05001085void Context::beginQuery(QueryType target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001086{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001087 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001088 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001089
Geoff Lang5aad9672014-09-08 11:10:42 -04001090 // begin query
Jamie Madillf0e04492017-08-26 15:28:42 -04001091 ANGLE_CONTEXT_TRY(queryObject->begin());
Geoff Lang5aad9672014-09-08 11:10:42 -04001092
1093 // set query as active for specified target only if begin succeeded
Jamie Madill4928b7c2017-06-20 12:57:39 -04001094 mGLState.setActiveQuery(this, target, queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001095}
1096
Corentin Wallezad3ae902018-03-09 13:40:42 -05001097void Context::endQuery(QueryType target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001098{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001099 Query *queryObject = mGLState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001100 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001101
Jamie Madillf0e04492017-08-26 15:28:42 -04001102 handleError(queryObject->end());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001103
Geoff Lang5aad9672014-09-08 11:10:42 -04001104 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madill4928b7c2017-06-20 12:57:39 -04001105 mGLState.setActiveQuery(this, target, nullptr);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001106}
1107
Corentin Wallezad3ae902018-03-09 13:40:42 -05001108void Context::queryCounter(GLuint id, QueryType target)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001109{
Corentin Wallezad3ae902018-03-09 13:40:42 -05001110 ASSERT(target == QueryType::Timestamp);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001111
1112 Query *queryObject = getQuery(id, true, target);
1113 ASSERT(queryObject);
1114
Jamie Madillf0e04492017-08-26 15:28:42 -04001115 handleError(queryObject->queryCounter());
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001116}
1117
Corentin Wallezad3ae902018-03-09 13:40:42 -05001118void Context::getQueryiv(QueryType target, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001119{
1120 switch (pname)
1121 {
1122 case GL_CURRENT_QUERY_EXT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001123 params[0] = mGLState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001124 break;
1125 case GL_QUERY_COUNTER_BITS_EXT:
1126 switch (target)
1127 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001128 case QueryType::TimeElapsed:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001129 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1130 break;
Corentin Wallezad3ae902018-03-09 13:40:42 -05001131 case QueryType::Timestamp:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001132 params[0] = getExtensions().queryCounterBitsTimestamp;
1133 break;
1134 default:
1135 UNREACHABLE();
1136 params[0] = 0;
1137 break;
1138 }
1139 break;
1140 default:
1141 UNREACHABLE();
1142 return;
1143 }
1144}
1145
Corentin Wallezad3ae902018-03-09 13:40:42 -05001146void Context::getQueryivRobust(QueryType target,
Brandon Jones59770802018-04-02 13:18:42 -07001147 GLenum pname,
1148 GLsizei bufSize,
1149 GLsizei *length,
1150 GLint *params)
1151{
1152 getQueryiv(target, pname, params);
1153}
1154
Geoff Lang2186c382016-10-14 10:54:54 -04001155void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001156{
Geoff Lang2186c382016-10-14 10:54:54 -04001157 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001158}
1159
Brandon Jones59770802018-04-02 13:18:42 -07001160void Context::getQueryObjectivRobust(GLuint id,
1161 GLenum pname,
1162 GLsizei bufSize,
1163 GLsizei *length,
1164 GLint *params)
1165{
1166 getQueryObjectiv(id, pname, params);
1167}
1168
Geoff Lang2186c382016-10-14 10:54:54 -04001169void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001170{
Geoff Lang2186c382016-10-14 10:54:54 -04001171 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001172}
1173
Brandon Jones59770802018-04-02 13:18:42 -07001174void Context::getQueryObjectuivRobust(GLuint id,
1175 GLenum pname,
1176 GLsizei bufSize,
1177 GLsizei *length,
1178 GLuint *params)
1179{
1180 getQueryObjectuiv(id, pname, params);
1181}
1182
Geoff Lang2186c382016-10-14 10:54:54 -04001183void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001184{
Geoff Lang2186c382016-10-14 10:54:54 -04001185 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001186}
1187
Brandon Jones59770802018-04-02 13:18:42 -07001188void Context::getQueryObjecti64vRobust(GLuint id,
1189 GLenum pname,
1190 GLsizei bufSize,
1191 GLsizei *length,
1192 GLint64 *params)
1193{
1194 getQueryObjecti64v(id, pname, params);
1195}
1196
Geoff Lang2186c382016-10-14 10:54:54 -04001197void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001198{
Geoff Lang2186c382016-10-14 10:54:54 -04001199 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001200}
1201
Brandon Jones59770802018-04-02 13:18:42 -07001202void Context::getQueryObjectui64vRobust(GLuint id,
1203 GLenum pname,
1204 GLsizei bufSize,
1205 GLsizei *length,
1206 GLuint64 *params)
1207{
1208 getQueryObjectui64v(id, pname, params);
1209}
1210
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001211Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001212{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001213 return mState.mFramebuffers->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001214}
1215
Jamie Madill2f348d22017-06-05 10:50:59 -04001216FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001217{
Jamie Madill96a483b2017-06-27 16:49:21 -04001218 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001219}
1220
Corentin Wallezad3ae902018-03-09 13:40:42 -05001221Query *Context::getQuery(GLuint handle, bool create, QueryType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001222{
Jamie Madill96a483b2017-06-27 16:49:21 -04001223 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001224 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001225 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001226 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001227
1228 Query *query = mQueryMap.query(handle);
1229 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001230 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001231 ASSERT(type != QueryType::InvalidEnum);
Jamie Madill96a483b2017-06-27 16:49:21 -04001232 query = new Query(mImplementation->createQuery(type), handle);
1233 query->addRef();
1234 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001235 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001236 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001237}
1238
Geoff Lang70d0f492015-12-10 17:45:46 -05001239Query *Context::getQuery(GLuint handle) const
1240{
Jamie Madill96a483b2017-06-27 16:49:21 -04001241 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001242}
1243
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001244Texture *Context::getTargetTexture(TextureType type) const
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001245{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001246 ASSERT(ValidTextureTarget(this, type) || ValidTextureExternalTarget(this, type));
1247 return mGLState.getTargetTexture(type);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001248}
1249
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001250Texture *Context::getSamplerTexture(unsigned int sampler, TextureType type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001251{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001252 return mGLState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001253}
1254
Geoff Lang492a7e42014-11-05 13:27:06 -05001255Compiler *Context::getCompiler() const
1256{
Jamie Madill2f348d22017-06-05 10:50:59 -04001257 if (mCompiler.get() == nullptr)
1258 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001259 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001260 }
1261 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001262}
1263
Jamie Madillc1d770e2017-04-13 17:31:24 -04001264void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001265{
1266 switch (pname)
1267 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001268 case GL_SHADER_COMPILER:
1269 *params = GL_TRUE;
1270 break;
1271 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1272 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1273 break;
1274 default:
1275 mGLState.getBooleanv(pname, params);
1276 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001277 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001278}
1279
Jamie Madillc1d770e2017-04-13 17:31:24 -04001280void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001281{
Shannon Woods53a94a82014-06-24 15:20:36 -04001282 // Queries about context capabilities and maximums are answered by Context.
1283 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001284 switch (pname)
1285 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001286 case GL_ALIASED_LINE_WIDTH_RANGE:
1287 params[0] = mCaps.minAliasedLineWidth;
1288 params[1] = mCaps.maxAliasedLineWidth;
1289 break;
1290 case GL_ALIASED_POINT_SIZE_RANGE:
1291 params[0] = mCaps.minAliasedPointSize;
1292 params[1] = mCaps.maxAliasedPointSize;
1293 break;
1294 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1295 ASSERT(mExtensions.textureFilterAnisotropic);
1296 *params = mExtensions.maxTextureAnisotropy;
1297 break;
1298 case GL_MAX_TEXTURE_LOD_BIAS:
1299 *params = mCaps.maxLODBias;
1300 break;
1301
1302 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1303 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1304 {
Lingfeng Yang3a41af62018-04-09 07:28:56 -07001305 // GLES1 emulation: // GL_PATH_(MODELVIEW|PROJECTION)_MATRIX_CHROMIUM collides with the
1306 // GLES1 constants for modelview/projection matrix.
1307 if (getClientVersion() < Version(2, 0))
1308 {
1309 mGLState.getFloatv(pname, params);
1310 }
1311 else
1312 {
1313 ASSERT(mExtensions.pathRendering);
1314 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1315 memcpy(params, m, 16 * sizeof(GLfloat));
1316 }
Jamie Madill231c7f52017-04-26 13:45:37 -04001317 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001318 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001319
Jamie Madill231c7f52017-04-26 13:45:37 -04001320 default:
1321 mGLState.getFloatv(pname, params);
1322 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001323 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001324}
1325
Jamie Madillc1d770e2017-04-13 17:31:24 -04001326void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001327{
Shannon Woods53a94a82014-06-24 15:20:36 -04001328 // Queries about context capabilities and maximums are answered by Context.
1329 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001330
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001331 switch (pname)
1332 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001333 case GL_MAX_VERTEX_ATTRIBS:
1334 *params = mCaps.maxVertexAttributes;
1335 break;
1336 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1337 *params = mCaps.maxVertexUniformVectors;
1338 break;
1339 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001340 *params = mCaps.maxShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001341 break;
1342 case GL_MAX_VARYING_VECTORS:
1343 *params = mCaps.maxVaryingVectors;
1344 break;
1345 case GL_MAX_VARYING_COMPONENTS:
1346 *params = mCaps.maxVertexOutputComponents;
1347 break;
1348 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1349 *params = mCaps.maxCombinedTextureImageUnits;
1350 break;
1351 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001352 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001353 break;
1354 case GL_MAX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001355 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001356 break;
1357 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1358 *params = mCaps.maxFragmentUniformVectors;
1359 break;
1360 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001361 *params = mCaps.maxShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001362 break;
1363 case GL_MAX_RENDERBUFFER_SIZE:
1364 *params = mCaps.maxRenderbufferSize;
1365 break;
1366 case GL_MAX_COLOR_ATTACHMENTS_EXT:
1367 *params = mCaps.maxColorAttachments;
1368 break;
1369 case GL_MAX_DRAW_BUFFERS_EXT:
1370 *params = mCaps.maxDrawBuffers;
1371 break;
1372 // case GL_FRAMEBUFFER_BINDING: // now equivalent to
1373 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
1374 case GL_SUBPIXEL_BITS:
1375 *params = 4;
1376 break;
1377 case GL_MAX_TEXTURE_SIZE:
1378 *params = mCaps.max2DTextureSize;
1379 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001380 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
1381 *params = mCaps.maxRectangleTextureSize;
1382 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001383 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1384 *params = mCaps.maxCubeMapTextureSize;
1385 break;
1386 case GL_MAX_3D_TEXTURE_SIZE:
1387 *params = mCaps.max3DTextureSize;
1388 break;
1389 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1390 *params = mCaps.maxArrayTextureLayers;
1391 break;
1392 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1393 *params = mCaps.uniformBufferOffsetAlignment;
1394 break;
1395 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1396 *params = mCaps.maxUniformBufferBindings;
1397 break;
1398 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001399 *params = mCaps.maxShaderUniformBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001400 break;
1401 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001402 *params = mCaps.maxShaderUniformBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001403 break;
1404 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1405 *params = mCaps.maxCombinedTextureImageUnits;
1406 break;
1407 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1408 *params = mCaps.maxVertexOutputComponents;
1409 break;
1410 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1411 *params = mCaps.maxFragmentInputComponents;
1412 break;
1413 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1414 *params = mCaps.minProgramTexelOffset;
1415 break;
1416 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1417 *params = mCaps.maxProgramTexelOffset;
1418 break;
1419 case GL_MAJOR_VERSION:
1420 *params = getClientVersion().major;
1421 break;
1422 case GL_MINOR_VERSION:
1423 *params = getClientVersion().minor;
1424 break;
1425 case GL_MAX_ELEMENTS_INDICES:
1426 *params = mCaps.maxElementsIndices;
1427 break;
1428 case GL_MAX_ELEMENTS_VERTICES:
1429 *params = mCaps.maxElementsVertices;
1430 break;
1431 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1432 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1433 break;
1434 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1435 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1436 break;
1437 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1438 *params = mCaps.maxTransformFeedbackSeparateComponents;
1439 break;
1440 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1441 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1442 break;
1443 case GL_MAX_SAMPLES_ANGLE:
1444 *params = mCaps.maxSamples;
1445 break;
1446 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001447 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001448 params[0] = mCaps.maxViewportWidth;
1449 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001450 }
1451 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001452 case GL_COMPRESSED_TEXTURE_FORMATS:
1453 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1454 params);
1455 break;
1456 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1457 *params = mResetStrategy;
1458 break;
1459 case GL_NUM_SHADER_BINARY_FORMATS:
1460 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1461 break;
1462 case GL_SHADER_BINARY_FORMATS:
1463 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1464 break;
1465 case GL_NUM_PROGRAM_BINARY_FORMATS:
1466 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1467 break;
1468 case GL_PROGRAM_BINARY_FORMATS:
1469 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1470 break;
1471 case GL_NUM_EXTENSIONS:
1472 *params = static_cast<GLint>(mExtensionStrings.size());
1473 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001474
Jamie Madill231c7f52017-04-26 13:45:37 -04001475 // GL_KHR_debug
1476 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1477 *params = mExtensions.maxDebugMessageLength;
1478 break;
1479 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1480 *params = mExtensions.maxDebugLoggedMessages;
1481 break;
1482 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1483 *params = mExtensions.maxDebugGroupStackDepth;
1484 break;
1485 case GL_MAX_LABEL_LENGTH:
1486 *params = mExtensions.maxLabelLength;
1487 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001488
Martin Radeve5285d22017-07-14 16:23:53 +03001489 // GL_ANGLE_multiview
1490 case GL_MAX_VIEWS_ANGLE:
1491 *params = mExtensions.maxViews;
1492 break;
1493
Jamie Madill231c7f52017-04-26 13:45:37 -04001494 // GL_EXT_disjoint_timer_query
1495 case GL_GPU_DISJOINT_EXT:
1496 *params = mImplementation->getGPUDisjoint();
1497 break;
1498 case GL_MAX_FRAMEBUFFER_WIDTH:
1499 *params = mCaps.maxFramebufferWidth;
1500 break;
1501 case GL_MAX_FRAMEBUFFER_HEIGHT:
1502 *params = mCaps.maxFramebufferHeight;
1503 break;
1504 case GL_MAX_FRAMEBUFFER_SAMPLES:
1505 *params = mCaps.maxFramebufferSamples;
1506 break;
1507 case GL_MAX_SAMPLE_MASK_WORDS:
1508 *params = mCaps.maxSampleMaskWords;
1509 break;
1510 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1511 *params = mCaps.maxColorTextureSamples;
1512 break;
1513 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1514 *params = mCaps.maxDepthTextureSamples;
1515 break;
1516 case GL_MAX_INTEGER_SAMPLES:
1517 *params = mCaps.maxIntegerSamples;
1518 break;
1519 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1520 *params = mCaps.maxVertexAttribRelativeOffset;
1521 break;
1522 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1523 *params = mCaps.maxVertexAttribBindings;
1524 break;
1525 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1526 *params = mCaps.maxVertexAttribStride;
1527 break;
1528 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001529 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001530 break;
1531 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001532 *params = mCaps.maxShaderAtomicCounters[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001533 break;
1534 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001535 *params = mCaps.maxShaderImageUniforms[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001536 break;
1537 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001538 *params = mCaps.maxShaderStorageBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001539 break;
1540 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001541 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001542 break;
1543 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001544 *params = mCaps.maxShaderAtomicCounters[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001545 break;
1546 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001547 *params = mCaps.maxShaderImageUniforms[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001548 break;
1549 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001550 *params = mCaps.maxShaderStorageBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001551 break;
1552 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1553 *params = mCaps.minProgramTextureGatherOffset;
1554 break;
1555 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1556 *params = mCaps.maxProgramTextureGatherOffset;
1557 break;
1558 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1559 *params = mCaps.maxComputeWorkGroupInvocations;
1560 break;
1561 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001562 *params = mCaps.maxShaderUniformBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001563 break;
1564 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001565 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001566 break;
1567 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1568 *params = mCaps.maxComputeSharedMemorySize;
1569 break;
1570 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001571 *params = mCaps.maxShaderUniformComponents[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001572 break;
1573 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001574 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001575 break;
1576 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001577 *params = mCaps.maxShaderAtomicCounters[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001578 break;
1579 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001580 *params = mCaps.maxShaderImageUniforms[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001581 break;
1582 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001583 *params =
1584 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Compute]);
Jamie Madill231c7f52017-04-26 13:45:37 -04001585 break;
1586 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001587 *params = mCaps.maxShaderStorageBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001588 break;
1589 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1590 *params = mCaps.maxCombinedShaderOutputResources;
1591 break;
1592 case GL_MAX_UNIFORM_LOCATIONS:
1593 *params = mCaps.maxUniformLocations;
1594 break;
1595 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1596 *params = mCaps.maxAtomicCounterBufferBindings;
1597 break;
1598 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1599 *params = mCaps.maxAtomicCounterBufferSize;
1600 break;
1601 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1602 *params = mCaps.maxCombinedAtomicCounterBuffers;
1603 break;
1604 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1605 *params = mCaps.maxCombinedAtomicCounters;
1606 break;
1607 case GL_MAX_IMAGE_UNITS:
1608 *params = mCaps.maxImageUnits;
1609 break;
1610 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1611 *params = mCaps.maxCombinedImageUniforms;
1612 break;
1613 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1614 *params = mCaps.maxShaderStorageBufferBindings;
1615 break;
1616 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1617 *params = mCaps.maxCombinedShaderStorageBlocks;
1618 break;
1619 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1620 *params = mCaps.shaderStorageBufferOffsetAlignment;
1621 break;
Jiawei Shao361df072017-11-22 09:33:59 +08001622
1623 // GL_EXT_geometry_shader
1624 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
1625 *params = mCaps.maxFramebufferLayers;
1626 break;
1627 case GL_LAYER_PROVOKING_VERTEX_EXT:
1628 *params = mCaps.layerProvokingVertex;
1629 break;
1630 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001631 *params = mCaps.maxShaderUniformComponents[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001632 break;
1633 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001634 *params = mCaps.maxShaderUniformBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001635 break;
1636 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001637 *params =
1638 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Geometry]);
Jiawei Shao361df072017-11-22 09:33:59 +08001639 break;
1640 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
1641 *params = mCaps.maxGeometryInputComponents;
1642 break;
1643 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
1644 *params = mCaps.maxGeometryOutputComponents;
1645 break;
1646 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
1647 *params = mCaps.maxGeometryOutputVertices;
1648 break;
1649 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
1650 *params = mCaps.maxGeometryTotalOutputComponents;
1651 break;
1652 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
1653 *params = mCaps.maxGeometryShaderInvocations;
1654 break;
1655 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001656 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001657 break;
1658 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001659 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001660 break;
1661 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001662 *params = mCaps.maxShaderAtomicCounters[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001663 break;
1664 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001665 *params = mCaps.maxShaderImageUniforms[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001666 break;
1667 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001668 *params = mCaps.maxShaderStorageBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001669 break;
Lingfeng Yang96310cd2018-03-28 11:56:28 -07001670 // GLES1 emulation: Caps queries
1671 case GL_MAX_TEXTURE_UNITS:
1672 *params = mCaps.maxMultitextureUnits;
1673 break;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001674 case GL_MAX_MODELVIEW_STACK_DEPTH:
1675 *params = mCaps.maxModelviewMatrixStackDepth;
1676 break;
1677 case GL_MAX_PROJECTION_STACK_DEPTH:
1678 *params = mCaps.maxProjectionMatrixStackDepth;
1679 break;
1680 case GL_MAX_TEXTURE_STACK_DEPTH:
1681 *params = mCaps.maxTextureMatrixStackDepth;
1682 break;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07001683 case GL_MAX_LIGHTS:
1684 *params = mCaps.maxLights;
1685 break;
Lingfeng Yang060088a2018-05-30 20:40:57 -07001686 case GL_MAX_CLIP_PLANES:
1687 *params = mCaps.maxClipPlanes;
1688 break;
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001689 // GLES1 emulation: Vertex attribute queries
1690 case GL_VERTEX_ARRAY_BUFFER_BINDING:
1691 case GL_NORMAL_ARRAY_BUFFER_BINDING:
1692 case GL_COLOR_ARRAY_BUFFER_BINDING:
1693 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
1694 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
1695 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1696 GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, params);
1697 break;
1698 case GL_VERTEX_ARRAY_STRIDE:
1699 case GL_NORMAL_ARRAY_STRIDE:
1700 case GL_COLOR_ARRAY_STRIDE:
1701 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
1702 case GL_TEXTURE_COORD_ARRAY_STRIDE:
1703 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1704 GL_VERTEX_ATTRIB_ARRAY_STRIDE, params);
1705 break;
1706 case GL_VERTEX_ARRAY_SIZE:
1707 case GL_COLOR_ARRAY_SIZE:
1708 case GL_TEXTURE_COORD_ARRAY_SIZE:
1709 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1710 GL_VERTEX_ATTRIB_ARRAY_SIZE, params);
1711 break;
1712 case GL_VERTEX_ARRAY_TYPE:
1713 case GL_COLOR_ARRAY_TYPE:
1714 case GL_NORMAL_ARRAY_TYPE:
1715 case GL_POINT_SIZE_ARRAY_TYPE_OES:
1716 case GL_TEXTURE_COORD_ARRAY_TYPE:
1717 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1718 GL_VERTEX_ATTRIB_ARRAY_TYPE, params);
1719 break;
1720
Jamie Madill231c7f52017-04-26 13:45:37 -04001721 default:
Jamie Madille98b1b52018-03-08 09:47:23 -05001722 handleError(mGLState.getIntegerv(this, pname, params));
Jamie Madill231c7f52017-04-26 13:45:37 -04001723 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001724 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001725}
1726
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001727void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001728{
Shannon Woods53a94a82014-06-24 15:20:36 -04001729 // Queries about context capabilities and maximums are answered by Context.
1730 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001731 switch (pname)
1732 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001733 case GL_MAX_ELEMENT_INDEX:
1734 *params = mCaps.maxElementIndex;
1735 break;
1736 case GL_MAX_UNIFORM_BLOCK_SIZE:
1737 *params = mCaps.maxUniformBlockSize;
1738 break;
1739 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001740 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001741 break;
1742 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001743 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001744 break;
1745 case GL_MAX_SERVER_WAIT_TIMEOUT:
1746 *params = mCaps.maxServerWaitTimeout;
1747 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001748
Jamie Madill231c7f52017-04-26 13:45:37 -04001749 // GL_EXT_disjoint_timer_query
1750 case GL_TIMESTAMP_EXT:
1751 *params = mImplementation->getTimestamp();
1752 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001753
Jamie Madill231c7f52017-04-26 13:45:37 -04001754 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1755 *params = mCaps.maxShaderStorageBlockSize;
1756 break;
1757 default:
1758 UNREACHABLE();
1759 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001760 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001761}
1762
Geoff Lang70d0f492015-12-10 17:45:46 -05001763void Context::getPointerv(GLenum pname, void **params) const
1764{
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001765 mGLState.getPointerv(this, pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001766}
1767
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001768void Context::getPointervRobustANGLERobust(GLenum pname,
1769 GLsizei bufSize,
1770 GLsizei *length,
1771 void **params)
1772{
1773 UNIMPLEMENTED();
1774}
1775
Martin Radev66fb8202016-07-28 11:45:20 +03001776void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001777{
Shannon Woods53a94a82014-06-24 15:20:36 -04001778 // Queries about context capabilities and maximums are answered by Context.
1779 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001780
1781 GLenum nativeType;
1782 unsigned int numParams;
1783 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1784 ASSERT(queryStatus);
1785
1786 if (nativeType == GL_INT)
1787 {
1788 switch (target)
1789 {
1790 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1791 ASSERT(index < 3u);
1792 *data = mCaps.maxComputeWorkGroupCount[index];
1793 break;
1794 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1795 ASSERT(index < 3u);
1796 *data = mCaps.maxComputeWorkGroupSize[index];
1797 break;
1798 default:
1799 mGLState.getIntegeri_v(target, index, data);
1800 }
1801 }
1802 else
1803 {
1804 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1805 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001806}
1807
Brandon Jones59770802018-04-02 13:18:42 -07001808void Context::getIntegeri_vRobust(GLenum target,
1809 GLuint index,
1810 GLsizei bufSize,
1811 GLsizei *length,
1812 GLint *data)
1813{
1814 getIntegeri_v(target, index, data);
1815}
1816
Martin Radev66fb8202016-07-28 11:45:20 +03001817void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001818{
Shannon Woods53a94a82014-06-24 15:20:36 -04001819 // Queries about context capabilities and maximums are answered by Context.
1820 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001821
1822 GLenum nativeType;
1823 unsigned int numParams;
1824 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1825 ASSERT(queryStatus);
1826
1827 if (nativeType == GL_INT_64_ANGLEX)
1828 {
1829 mGLState.getInteger64i_v(target, index, data);
1830 }
1831 else
1832 {
1833 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1834 }
1835}
1836
Brandon Jones59770802018-04-02 13:18:42 -07001837void Context::getInteger64i_vRobust(GLenum target,
1838 GLuint index,
1839 GLsizei bufSize,
1840 GLsizei *length,
1841 GLint64 *data)
1842{
1843 getInteger64i_v(target, index, data);
1844}
1845
Martin Radev66fb8202016-07-28 11:45:20 +03001846void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1847{
1848 // Queries about context capabilities and maximums are answered by Context.
1849 // Queries about current GL state values are answered by State.
1850
1851 GLenum nativeType;
1852 unsigned int numParams;
1853 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1854 ASSERT(queryStatus);
1855
1856 if (nativeType == GL_BOOL)
1857 {
1858 mGLState.getBooleani_v(target, index, data);
1859 }
1860 else
1861 {
1862 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1863 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001864}
1865
Brandon Jones59770802018-04-02 13:18:42 -07001866void Context::getBooleani_vRobust(GLenum target,
1867 GLuint index,
1868 GLsizei bufSize,
1869 GLsizei *length,
1870 GLboolean *data)
1871{
1872 getBooleani_v(target, index, data);
1873}
1874
Corentin Wallez336129f2017-10-17 15:55:40 -04001875void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001876{
1877 Buffer *buffer = mGLState.getTargetBuffer(target);
1878 QueryBufferParameteriv(buffer, pname, params);
1879}
1880
Brandon Jones59770802018-04-02 13:18:42 -07001881void Context::getBufferParameterivRobust(BufferBinding target,
1882 GLenum pname,
1883 GLsizei bufSize,
1884 GLsizei *length,
1885 GLint *params)
1886{
1887 getBufferParameteriv(target, pname, params);
1888}
1889
He Yunchao010e4db2017-03-03 14:22:06 +08001890void Context::getFramebufferAttachmentParameteriv(GLenum target,
1891 GLenum attachment,
1892 GLenum pname,
1893 GLint *params)
1894{
1895 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08001896 QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08001897}
1898
Brandon Jones59770802018-04-02 13:18:42 -07001899void Context::getFramebufferAttachmentParameterivRobust(GLenum target,
1900 GLenum attachment,
1901 GLenum pname,
1902 GLsizei bufSize,
1903 GLsizei *length,
1904 GLint *params)
1905{
1906 getFramebufferAttachmentParameteriv(target, attachment, pname, params);
1907}
1908
He Yunchao010e4db2017-03-03 14:22:06 +08001909void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
1910{
1911 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
1912 QueryRenderbufferiv(this, renderbuffer, pname, params);
1913}
1914
Brandon Jones59770802018-04-02 13:18:42 -07001915void Context::getRenderbufferParameterivRobust(GLenum target,
1916 GLenum pname,
1917 GLsizei bufSize,
1918 GLsizei *length,
1919 GLint *params)
1920{
1921 getRenderbufferParameteriv(target, pname, params);
1922}
1923
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001924void Context::getTexParameterfv(TextureType target, GLenum pname, GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001925{
1926 Texture *texture = getTargetTexture(target);
1927 QueryTexParameterfv(texture, pname, params);
1928}
1929
Brandon Jones59770802018-04-02 13:18:42 -07001930void Context::getTexParameterfvRobust(TextureType target,
1931 GLenum pname,
1932 GLsizei bufSize,
1933 GLsizei *length,
1934 GLfloat *params)
1935{
1936 getTexParameterfv(target, pname, params);
1937}
1938
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001939void Context::getTexParameteriv(TextureType target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001940{
1941 Texture *texture = getTargetTexture(target);
1942 QueryTexParameteriv(texture, pname, params);
1943}
Jiajia Qin5451d532017-11-16 17:16:34 +08001944
Brandon Jones59770802018-04-02 13:18:42 -07001945void Context::getTexParameterivRobust(TextureType target,
1946 GLenum pname,
1947 GLsizei bufSize,
1948 GLsizei *length,
1949 GLint *params)
1950{
1951 getTexParameteriv(target, pname, params);
1952}
1953
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001954void Context::getTexParameterIivRobust(TextureType target,
1955 GLenum pname,
1956 GLsizei bufSize,
1957 GLsizei *length,
1958 GLint *params)
1959{
1960 UNIMPLEMENTED();
1961}
1962
1963void Context::getTexParameterIuivRobust(TextureType target,
1964 GLenum pname,
1965 GLsizei bufSize,
1966 GLsizei *length,
1967 GLuint *params)
1968{
1969 UNIMPLEMENTED();
1970}
1971
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001972void Context::getTexLevelParameteriv(TextureTarget target, GLint level, GLenum pname, GLint *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08001973{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001974 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05001975 QueryTexLevelParameteriv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08001976}
1977
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001978void Context::getTexLevelParameterivRobust(TextureTarget target,
1979 GLint level,
1980 GLenum pname,
1981 GLsizei bufSize,
1982 GLsizei *length,
1983 GLint *params)
1984{
1985 UNIMPLEMENTED();
1986}
1987
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001988void Context::getTexLevelParameterfv(TextureTarget target,
1989 GLint level,
1990 GLenum pname,
1991 GLfloat *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 QueryTexLevelParameterfv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08001995}
1996
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001997void Context::getTexLevelParameterfvRobust(TextureTarget target,
1998 GLint level,
1999 GLenum pname,
2000 GLsizei bufSize,
2001 GLsizei *length,
2002 GLfloat *params)
2003{
2004 UNIMPLEMENTED();
2005}
2006
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002007void Context::texParameterf(TextureType target, GLenum pname, GLfloat param)
He Yunchao010e4db2017-03-03 14:22:06 +08002008{
2009 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002010 SetTexParameterf(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002011 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002012}
2013
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002014void Context::texParameterfv(TextureType target, GLenum pname, const GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002015{
2016 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002017 SetTexParameterfv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002018 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002019}
2020
Brandon Jones59770802018-04-02 13:18:42 -07002021void Context::texParameterfvRobust(TextureType target,
2022 GLenum pname,
2023 GLsizei bufSize,
2024 const GLfloat *params)
2025{
2026 texParameterfv(target, pname, params);
2027}
2028
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002029void Context::texParameteri(TextureType target, GLenum pname, GLint param)
He Yunchao010e4db2017-03-03 14:22:06 +08002030{
2031 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002032 SetTexParameteri(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002033 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002034}
2035
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002036void Context::texParameteriv(TextureType target, GLenum pname, const GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002037{
2038 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002039 SetTexParameteriv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002040 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002041}
2042
Brandon Jones59770802018-04-02 13:18:42 -07002043void Context::texParameterivRobust(TextureType target,
2044 GLenum pname,
2045 GLsizei bufSize,
2046 const GLint *params)
2047{
2048 texParameteriv(target, pname, params);
2049}
2050
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002051void Context::texParameterIivRobust(TextureType target,
2052 GLenum pname,
2053 GLsizei bufSize,
2054 const GLint *params)
2055{
2056 UNIMPLEMENTED();
2057}
2058
2059void Context::texParameterIuivRobust(TextureType target,
2060 GLenum pname,
2061 GLsizei bufSize,
2062 const GLuint *params)
2063{
2064 UNIMPLEMENTED();
2065}
2066
Jamie Madill493f9572018-05-24 19:52:15 -04002067void Context::drawArrays(PrimitiveMode mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002068{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002069 // No-op if zero count
2070 if (count == 0)
2071 {
2072 return;
2073 }
2074
Jamie Madill05b35b22017-10-03 09:01:44 -04002075 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002076 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
Jamie Madill09463932018-04-04 05:26:59 -04002077 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count, 1);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002078}
2079
Jamie Madill493f9572018-05-24 19:52:15 -04002080void Context::drawArraysInstanced(PrimitiveMode mode,
2081 GLint first,
2082 GLsizei count,
2083 GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04002084{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002085 // No-op if zero count
2086 if (count == 0 || instanceCount == 0)
2087 {
2088 return;
2089 }
2090
Jamie Madill05b35b22017-10-03 09:01:44 -04002091 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002092 ANGLE_CONTEXT_TRY(
2093 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
Jamie Madill09463932018-04-04 05:26:59 -04002094 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count,
2095 instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -04002096}
2097
Jamie Madill493f9572018-05-24 19:52:15 -04002098void Context::drawElements(PrimitiveMode mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002099{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002100 // No-op if zero count
2101 if (count == 0)
2102 {
2103 return;
2104 }
2105
Jamie Madill05b35b22017-10-03 09:01:44 -04002106 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002107 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04002108}
2109
Jamie Madill493f9572018-05-24 19:52:15 -04002110void Context::drawElementsInstanced(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002111 GLsizei count,
2112 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002113 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04002114 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04002115{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002116 // No-op if zero count
2117 if (count == 0 || instances == 0)
2118 {
2119 return;
2120 }
2121
Jamie Madill05b35b22017-10-03 09:01:44 -04002122 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002123 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08002124 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04002125}
2126
Jamie Madill493f9572018-05-24 19:52:15 -04002127void Context::drawRangeElements(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002128 GLuint start,
2129 GLuint end,
2130 GLsizei count,
2131 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002132 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04002133{
Jamie Madill9fdaa492018-02-16 10:52:11 -05002134 // No-op if zero count
2135 if (count == 0)
2136 {
2137 return;
2138 }
2139
Jamie Madill05b35b22017-10-03 09:01:44 -04002140 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002141 ANGLE_CONTEXT_TRY(
2142 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002143}
2144
Jamie Madill493f9572018-05-24 19:52:15 -04002145void Context::drawArraysIndirect(PrimitiveMode mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002146{
Jamie Madill05b35b22017-10-03 09:01:44 -04002147 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002148 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002149}
2150
Jamie Madill493f9572018-05-24 19:52:15 -04002151void Context::drawElementsIndirect(PrimitiveMode mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002152{
Jamie Madill05b35b22017-10-03 09:01:44 -04002153 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04002154 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002155}
2156
Jamie Madill675fe712016-12-19 13:07:54 -05002157void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002158{
Jamie Madillafa02a22017-11-23 12:57:38 -05002159 handleError(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05002160}
2161
Jamie Madill675fe712016-12-19 13:07:54 -05002162void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05002163{
Jamie Madillafa02a22017-11-23 12:57:38 -05002164 handleError(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002165}
2166
Austin Kinross6ee1e782015-05-29 17:05:37 -07002167void Context::insertEventMarker(GLsizei length, const char *marker)
2168{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002169 ASSERT(mImplementation);
2170 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07002171}
2172
2173void Context::pushGroupMarker(GLsizei length, const char *marker)
2174{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002175 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05002176
2177 if (marker == nullptr)
2178 {
2179 // From the EXT_debug_marker spec,
2180 // "If <marker> is null then an empty string is pushed on the stack."
2181 mImplementation->pushGroupMarker(length, "");
2182 }
2183 else
2184 {
2185 mImplementation->pushGroupMarker(length, marker);
2186 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07002187}
2188
2189void Context::popGroupMarker()
2190{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002191 ASSERT(mImplementation);
2192 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07002193}
2194
Geoff Langd8605522016-04-13 10:19:12 -04002195void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
2196{
2197 Program *programObject = getProgram(program);
2198 ASSERT(programObject);
2199
2200 programObject->bindUniformLocation(location, name);
2201}
2202
Brandon Jones59770802018-04-02 13:18:42 -07002203void Context::coverageModulation(GLenum components)
Sami Väisänena797e062016-05-12 15:23:40 +03002204{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002205 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03002206}
2207
Brandon Jones59770802018-04-02 13:18:42 -07002208void Context::matrixLoadf(GLenum matrixMode, const GLfloat *matrix)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002209{
2210 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
2211}
2212
Brandon Jones59770802018-04-02 13:18:42 -07002213void Context::matrixLoadIdentity(GLenum matrixMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002214{
2215 GLfloat I[16];
2216 angle::Matrix<GLfloat>::setToIdentity(I);
2217
2218 mGLState.loadPathRenderingMatrix(matrixMode, I);
2219}
2220
2221void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
2222{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002223 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002224 if (!pathObj)
2225 return;
2226
2227 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002228 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002229
2230 mImplementation->stencilFillPath(pathObj, fillMode, mask);
2231}
2232
2233void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
2234{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002235 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002236 if (!pathObj)
2237 return;
2238
2239 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002240 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002241
2242 mImplementation->stencilStrokePath(pathObj, reference, mask);
2243}
2244
2245void Context::coverFillPath(GLuint path, GLenum coverMode)
2246{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002247 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002248 if (!pathObj)
2249 return;
2250
2251 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002252 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002253
2254 mImplementation->coverFillPath(pathObj, coverMode);
2255}
2256
2257void Context::coverStrokePath(GLuint path, GLenum coverMode)
2258{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002259 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002260 if (!pathObj)
2261 return;
2262
2263 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002264 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002265
2266 mImplementation->coverStrokePath(pathObj, coverMode);
2267}
2268
2269void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
2270{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002271 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002272 if (!pathObj)
2273 return;
2274
2275 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002276 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002277
2278 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
2279}
2280
2281void Context::stencilThenCoverStrokePath(GLuint path,
2282 GLint reference,
2283 GLuint mask,
2284 GLenum coverMode)
2285{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002286 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002287 if (!pathObj)
2288 return;
2289
2290 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002291 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002292
2293 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2294}
2295
Sami Väisänend59ca052016-06-21 16:10:00 +03002296void Context::coverFillPathInstanced(GLsizei numPaths,
2297 GLenum pathNameType,
2298 const void *paths,
2299 GLuint pathBase,
2300 GLenum coverMode,
2301 GLenum transformType,
2302 const GLfloat *transformValues)
2303{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002304 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002305
2306 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002307 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002308
2309 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2310}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002311
Sami Väisänend59ca052016-06-21 16:10:00 +03002312void Context::coverStrokePathInstanced(GLsizei numPaths,
2313 GLenum pathNameType,
2314 const void *paths,
2315 GLuint pathBase,
2316 GLenum coverMode,
2317 GLenum transformType,
2318 const GLfloat *transformValues)
2319{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002320 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002321
2322 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002323 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002324
2325 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2326 transformValues);
2327}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002328
Sami Väisänend59ca052016-06-21 16:10:00 +03002329void Context::stencilFillPathInstanced(GLsizei numPaths,
2330 GLenum pathNameType,
2331 const void *paths,
2332 GLuint pathBase,
2333 GLenum fillMode,
2334 GLuint mask,
2335 GLenum transformType,
2336 const GLfloat *transformValues)
2337{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002338 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002339
2340 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002341 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002342
2343 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2344 transformValues);
2345}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002346
Sami Väisänend59ca052016-06-21 16:10:00 +03002347void Context::stencilStrokePathInstanced(GLsizei numPaths,
2348 GLenum pathNameType,
2349 const void *paths,
2350 GLuint pathBase,
2351 GLint reference,
2352 GLuint mask,
2353 GLenum transformType,
2354 const GLfloat *transformValues)
2355{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002356 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002357
2358 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002359 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002360
2361 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2362 transformValues);
2363}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002364
Sami Väisänend59ca052016-06-21 16:10:00 +03002365void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2366 GLenum pathNameType,
2367 const void *paths,
2368 GLuint pathBase,
2369 GLenum fillMode,
2370 GLuint mask,
2371 GLenum coverMode,
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->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2381 transformType, transformValues);
2382}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002383
Sami Väisänend59ca052016-06-21 16:10:00 +03002384void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2385 GLenum pathNameType,
2386 const void *paths,
2387 GLuint pathBase,
2388 GLint reference,
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->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2400 transformType, transformValues);
2401}
2402
Sami Väisänen46eaa942016-06-29 10:26:37 +03002403void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2404{
2405 auto *programObject = getProgram(program);
2406
2407 programObject->bindFragmentInputLocation(location, name);
2408}
2409
2410void Context::programPathFragmentInputGen(GLuint program,
2411 GLint location,
2412 GLenum genMode,
2413 GLint components,
2414 const GLfloat *coeffs)
2415{
2416 auto *programObject = getProgram(program);
2417
Jamie Madillbd044ed2017-06-05 12:59:21 -04002418 programObject->pathFragmentInputGen(this, location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002419}
2420
jchen1015015f72017-03-16 13:54:21 +08002421GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2422{
jchen10fd7c3b52017-03-21 15:36:03 +08002423 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002424 return QueryProgramResourceIndex(programObject, programInterface, name);
2425}
2426
jchen10fd7c3b52017-03-21 15:36:03 +08002427void Context::getProgramResourceName(GLuint program,
2428 GLenum programInterface,
2429 GLuint index,
2430 GLsizei bufSize,
2431 GLsizei *length,
2432 GLchar *name)
2433{
2434 const auto *programObject = getProgram(program);
2435 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2436}
2437
jchen10191381f2017-04-11 13:59:04 +08002438GLint Context::getProgramResourceLocation(GLuint program,
2439 GLenum programInterface,
2440 const GLchar *name)
2441{
2442 const auto *programObject = getProgram(program);
2443 return QueryProgramResourceLocation(programObject, programInterface, name);
2444}
2445
jchen10880683b2017-04-12 16:21:55 +08002446void Context::getProgramResourceiv(GLuint program,
2447 GLenum programInterface,
2448 GLuint index,
2449 GLsizei propCount,
2450 const GLenum *props,
2451 GLsizei bufSize,
2452 GLsizei *length,
2453 GLint *params)
2454{
2455 const auto *programObject = getProgram(program);
2456 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2457 length, params);
2458}
2459
jchen10d9cd7b72017-08-30 15:04:25 +08002460void Context::getProgramInterfaceiv(GLuint program,
2461 GLenum programInterface,
2462 GLenum pname,
2463 GLint *params)
2464{
2465 const auto *programObject = getProgram(program);
2466 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2467}
2468
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002469void Context::getProgramInterfaceivRobust(GLuint program,
2470 GLenum programInterface,
2471 GLenum pname,
2472 GLsizei bufSize,
2473 GLsizei *length,
2474 GLint *params)
2475{
2476 UNIMPLEMENTED();
2477}
2478
Jamie Madill427064d2018-04-13 16:20:34 -04002479void Context::handleError(const Error &error) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002480{
Geoff Lang7b19a492018-04-20 09:31:52 -04002481 if (ANGLE_UNLIKELY(error.isError()))
Geoff Langda5777c2014-07-11 09:52:58 -04002482 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002483 GLenum code = error.getCode();
2484 mErrors.insert(code);
2485 if (code == GL_OUT_OF_MEMORY && getWorkarounds().loseContextOnOutOfMemory)
2486 {
2487 markContextLost();
2488 }
Geoff Lang70d0f492015-12-10 17:45:46 -05002489
Geoff Langee6884e2017-11-09 16:51:11 -05002490 ASSERT(!error.getMessage().empty());
2491 mGLState.getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, error.getID(),
2492 GL_DEBUG_SEVERITY_HIGH, error.getMessage());
Geoff Langda5777c2014-07-11 09:52:58 -04002493 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002494}
2495
2496// Get one of the recorded errors and clear its flag, if any.
2497// [OpenGL ES 2.0.24] section 2.5 page 13.
2498GLenum Context::getError()
2499{
Geoff Langda5777c2014-07-11 09:52:58 -04002500 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002501 {
Geoff Langda5777c2014-07-11 09:52:58 -04002502 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002503 }
Geoff Langda5777c2014-07-11 09:52:58 -04002504 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002505 {
Geoff Langda5777c2014-07-11 09:52:58 -04002506 GLenum error = *mErrors.begin();
2507 mErrors.erase(mErrors.begin());
2508 return error;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002509 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002510}
2511
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002512// NOTE: this function should not assume that this context is current!
Jamie Madill427064d2018-04-13 16:20:34 -04002513void Context::markContextLost() const
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002514{
2515 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002516 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002517 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002518 mContextLostForced = true;
2519 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002520 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002521}
2522
Jamie Madill427064d2018-04-13 16:20:34 -04002523bool Context::isContextLost() const
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002524{
2525 return mContextLost;
2526}
2527
Jamie Madillfa920eb2018-01-04 11:45:50 -05002528GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002529{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002530 // Even if the application doesn't want to know about resets, we want to know
2531 // as it will allow us to skip all the calls.
2532 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002533 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002534 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002535 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002536 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002537 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002538
2539 // EXT_robustness, section 2.6: If the reset notification behavior is
2540 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2541 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2542 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002543 }
2544
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002545 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2546 // status should be returned at least once, and GL_NO_ERROR should be returned
2547 // once the device has finished resetting.
2548 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002549 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002550 ASSERT(mResetStatus == GL_NO_ERROR);
2551 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002552
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002553 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002554 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002555 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002556 }
2557 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002558 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002559 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002560 // If markContextLost was used to mark the context lost then
2561 // assume that is not recoverable, and continue to report the
2562 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002563 mResetStatus = mImplementation->getResetStatus();
2564 }
Jamie Madill893ab082014-05-16 16:56:10 -04002565
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002566 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002567}
2568
2569bool Context::isResetNotificationEnabled()
2570{
2571 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2572}
2573
Corentin Walleze3b10e82015-05-20 11:06:25 -04002574const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002575{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002576 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002577}
2578
2579EGLenum Context::getClientType() const
2580{
2581 return mClientType;
2582}
2583
2584EGLenum Context::getRenderBuffer() const
2585{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002586 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2587 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002588 {
2589 return EGL_NONE;
2590 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002591
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002592 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002593 ASSERT(backAttachment != nullptr);
2594 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002595}
2596
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002597VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002598{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002599 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002600 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2601 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002602 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002603 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2604 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002605
Jamie Madill96a483b2017-06-27 16:49:21 -04002606 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002607 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002608
2609 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002610}
2611
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002612TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002613{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002614 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002615 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2616 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002617 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002618 transformFeedback =
2619 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002620 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002621 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002622 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002623
2624 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002625}
2626
2627bool Context::isVertexArrayGenerated(GLuint vertexArray)
2628{
Jamie Madill96a483b2017-06-27 16:49:21 -04002629 ASSERT(mVertexArrayMap.contains(0));
2630 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002631}
2632
2633bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2634{
Jamie Madill96a483b2017-06-27 16:49:21 -04002635 ASSERT(mTransformFeedbackMap.contains(0));
2636 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002637}
2638
Shannon Woods53a94a82014-06-24 15:20:36 -04002639void Context::detachTexture(GLuint texture)
2640{
2641 // Simple pass-through to State's detachTexture method, as textures do not require
2642 // allocation map management either here or in the resource manager at detach time.
2643 // Zero textures are held by the Context, and we don't attempt to request them from
2644 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002645 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002646}
2647
James Darpinian4d9d4832018-03-13 12:43:28 -07002648void Context::detachBuffer(Buffer *buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002649{
Yuly Novikov5807a532015-12-03 13:01:22 -05002650 // Simple pass-through to State's detachBuffer method, since
2651 // only buffer attachments to container objects that are bound to the current context
2652 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002653
Yuly Novikov5807a532015-12-03 13:01:22 -05002654 // [OpenGL ES 3.2] section 5.1.2 page 45:
2655 // Attachments to unbound container objects, such as
2656 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2657 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002658 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002659}
2660
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002661void Context::detachFramebuffer(GLuint framebuffer)
2662{
Shannon Woods53a94a82014-06-24 15:20:36 -04002663 // Framebuffer detachment is handled by Context, because 0 is a valid
2664 // Framebuffer object, and a pointer to it must be passed from Context
2665 // to State at binding time.
2666
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002667 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002668 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2669 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2670 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002671
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002672 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002673 {
2674 bindReadFramebuffer(0);
2675 }
2676
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002677 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002678 {
2679 bindDrawFramebuffer(0);
2680 }
2681}
2682
2683void Context::detachRenderbuffer(GLuint renderbuffer)
2684{
Jamie Madilla02315b2017-02-23 14:14:47 -05002685 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002686}
2687
Jamie Madill57a89722013-07-02 11:57:03 -04002688void Context::detachVertexArray(GLuint vertexArray)
2689{
Jamie Madill77a72f62015-04-14 11:18:32 -04002690 // Vertex array detachment is handled by Context, because 0 is a valid
2691 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002692 // binding time.
2693
Jamie Madill57a89722013-07-02 11:57:03 -04002694 // [OpenGL ES 3.0.2] section 2.10 page 43:
2695 // If a vertex array object that is currently bound is deleted, the binding
2696 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madill7267aa62018-04-17 15:28:21 -04002697 if (mGLState.removeVertexArrayBinding(this, vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002698 {
2699 bindVertexArray(0);
2700 }
2701}
2702
Geoff Langc8058452014-02-03 12:04:11 -05002703void Context::detachTransformFeedback(GLuint transformFeedback)
2704{
Corentin Walleza2257da2016-04-19 16:43:12 -04002705 // Transform feedback detachment is handled by Context, because 0 is a valid
2706 // transform feedback, and a pointer to it must be passed from Context to State at
2707 // binding time.
2708
2709 // The OpenGL specification doesn't mention what should happen when the currently bound
2710 // transform feedback object is deleted. Since it is a container object, we treat it like
2711 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002712 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002713 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002714 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002715 }
Geoff Langc8058452014-02-03 12:04:11 -05002716}
2717
Jamie Madilldc356042013-07-19 16:36:57 -04002718void Context::detachSampler(GLuint sampler)
2719{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002720 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002721}
2722
Yunchao Hea336b902017-08-02 16:05:21 +08002723void Context::detachProgramPipeline(GLuint pipeline)
2724{
2725 mGLState.detachProgramPipeline(this, pipeline);
2726}
2727
Jamie Madill3ef140a2017-08-26 23:11:21 -04002728void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002729{
Shaodde78e82017-05-22 14:13:27 +08002730 mGLState.setVertexAttribDivisor(this, index, divisor);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002731}
2732
Jamie Madille29d1672013-07-19 16:36:57 -04002733void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2734{
Geoff Langc1984ed2016-10-07 12:41:00 -04002735 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002736 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002737 SetSamplerParameteri(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002738 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002739}
Jamie Madille29d1672013-07-19 16:36:57 -04002740
Geoff Langc1984ed2016-10-07 12:41:00 -04002741void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2742{
2743 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002744 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002745 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002746 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002747}
2748
Brandon Jones59770802018-04-02 13:18:42 -07002749void Context::samplerParameterivRobust(GLuint sampler,
2750 GLenum pname,
2751 GLsizei bufSize,
2752 const GLint *param)
2753{
2754 samplerParameteriv(sampler, pname, param);
2755}
2756
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002757void Context::samplerParameterIivRobust(GLuint sampler,
2758 GLenum pname,
2759 GLsizei bufSize,
2760 const GLint *param)
2761{
2762 UNIMPLEMENTED();
2763}
2764
2765void Context::samplerParameterIuivRobust(GLuint sampler,
2766 GLenum pname,
2767 GLsizei bufSize,
2768 const GLuint *param)
2769{
2770 UNIMPLEMENTED();
2771}
2772
Jamie Madille29d1672013-07-19 16:36:57 -04002773void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2774{
Geoff Langc1984ed2016-10-07 12:41:00 -04002775 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002776 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002777 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002778 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002779}
2780
Geoff Langc1984ed2016-10-07 12:41:00 -04002781void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002782{
Geoff Langc1984ed2016-10-07 12:41:00 -04002783 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002784 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002785 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002786 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002787}
2788
Brandon Jones59770802018-04-02 13:18:42 -07002789void Context::samplerParameterfvRobust(GLuint sampler,
2790 GLenum pname,
2791 GLsizei bufSize,
2792 const GLfloat *param)
2793{
2794 samplerParameterfv(sampler, pname, param);
2795}
2796
Geoff Langc1984ed2016-10-07 12:41:00 -04002797void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002798{
Geoff Langc1984ed2016-10-07 12:41:00 -04002799 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002800 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002801 QuerySamplerParameteriv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002802 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002803}
Jamie Madill9675b802013-07-19 16:36:59 -04002804
Brandon Jones59770802018-04-02 13:18:42 -07002805void Context::getSamplerParameterivRobust(GLuint sampler,
2806 GLenum pname,
2807 GLsizei bufSize,
2808 GLsizei *length,
2809 GLint *params)
2810{
2811 getSamplerParameteriv(sampler, pname, params);
2812}
2813
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002814void Context::getSamplerParameterIivRobust(GLuint sampler,
2815 GLenum pname,
2816 GLsizei bufSize,
2817 GLsizei *length,
2818 GLint *params)
2819{
2820 UNIMPLEMENTED();
2821}
2822
2823void Context::getSamplerParameterIuivRobust(GLuint sampler,
2824 GLenum pname,
2825 GLsizei bufSize,
2826 GLsizei *length,
2827 GLuint *params)
2828{
2829 UNIMPLEMENTED();
2830}
2831
Geoff Langc1984ed2016-10-07 12:41:00 -04002832void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2833{
2834 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002835 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002836 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002837 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002838}
2839
Brandon Jones59770802018-04-02 13:18:42 -07002840void Context::getSamplerParameterfvRobust(GLuint sampler,
2841 GLenum pname,
2842 GLsizei bufSize,
2843 GLsizei *length,
2844 GLfloat *params)
2845{
2846 getSamplerParameterfv(sampler, pname, params);
2847}
2848
Olli Etuahof0fee072016-03-30 15:11:58 +03002849void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2850{
2851 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002852 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002853}
2854
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002855void Context::initRendererString()
2856{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002857 std::ostringstream rendererString;
2858 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002859 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002860 rendererString << ")";
2861
Geoff Langcec35902014-04-16 10:52:36 -04002862 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002863}
2864
Geoff Langc339c4e2016-11-29 10:37:36 -05002865void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002866{
Geoff Langc339c4e2016-11-29 10:37:36 -05002867 const Version &clientVersion = getClientVersion();
2868
2869 std::ostringstream versionString;
2870 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2871 << ANGLE_VERSION_STRING << ")";
2872 mVersionString = MakeStaticString(versionString.str());
2873
2874 std::ostringstream shadingLanguageVersionString;
2875 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2876 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2877 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2878 << ")";
2879 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002880}
2881
Geoff Langcec35902014-04-16 10:52:36 -04002882void Context::initExtensionStrings()
2883{
Geoff Langc339c4e2016-11-29 10:37:36 -05002884 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2885 std::ostringstream combinedStringStream;
2886 std::copy(strings.begin(), strings.end(),
2887 std::ostream_iterator<const char *>(combinedStringStream, " "));
2888 return MakeStaticString(combinedStringStream.str());
2889 };
2890
2891 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002892 for (const auto &extensionString : mExtensions.getStrings())
2893 {
2894 mExtensionStrings.push_back(MakeStaticString(extensionString));
2895 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002896 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002897
Geoff Langc339c4e2016-11-29 10:37:36 -05002898 mRequestableExtensionStrings.clear();
2899 for (const auto &extensionInfo : GetExtensionInfoMap())
2900 {
2901 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08002902 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
Geoff Langb0f917f2017-12-05 13:41:54 -05002903 mSupportedExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002904 {
2905 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
2906 }
2907 }
2908 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002909}
2910
Geoff Langc339c4e2016-11-29 10:37:36 -05002911const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04002912{
Geoff Langc339c4e2016-11-29 10:37:36 -05002913 switch (name)
2914 {
2915 case GL_VENDOR:
2916 return reinterpret_cast<const GLubyte *>("Google Inc.");
2917
2918 case GL_RENDERER:
2919 return reinterpret_cast<const GLubyte *>(mRendererString);
2920
2921 case GL_VERSION:
2922 return reinterpret_cast<const GLubyte *>(mVersionString);
2923
2924 case GL_SHADING_LANGUAGE_VERSION:
2925 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
2926
2927 case GL_EXTENSIONS:
2928 return reinterpret_cast<const GLubyte *>(mExtensionString);
2929
2930 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2931 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
2932
2933 default:
2934 UNREACHABLE();
2935 return nullptr;
2936 }
Geoff Langcec35902014-04-16 10:52:36 -04002937}
2938
Geoff Langc339c4e2016-11-29 10:37:36 -05002939const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04002940{
Geoff Langc339c4e2016-11-29 10:37:36 -05002941 switch (name)
2942 {
2943 case GL_EXTENSIONS:
2944 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
2945
2946 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2947 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
2948
2949 default:
2950 UNREACHABLE();
2951 return nullptr;
2952 }
Geoff Langcec35902014-04-16 10:52:36 -04002953}
2954
2955size_t Context::getExtensionStringCount() const
2956{
2957 return mExtensionStrings.size();
2958}
2959
Geoff Lang111a99e2017-10-17 10:58:41 -04002960bool Context::isExtensionRequestable(const char *name)
2961{
2962 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2963 auto extension = extensionInfos.find(name);
2964
Geoff Lang111a99e2017-10-17 10:58:41 -04002965 return extension != extensionInfos.end() && extension->second.Requestable &&
Geoff Langb0f917f2017-12-05 13:41:54 -05002966 mSupportedExtensions.*(extension->second.ExtensionsMember);
Geoff Lang111a99e2017-10-17 10:58:41 -04002967}
2968
Geoff Langc339c4e2016-11-29 10:37:36 -05002969void Context::requestExtension(const char *name)
2970{
2971 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2972 ASSERT(extensionInfos.find(name) != extensionInfos.end());
2973 const auto &extension = extensionInfos.at(name);
2974 ASSERT(extension.Requestable);
Geoff Langb0f917f2017-12-05 13:41:54 -05002975 ASSERT(isExtensionRequestable(name));
Geoff Langc339c4e2016-11-29 10:37:36 -05002976
2977 if (mExtensions.*(extension.ExtensionsMember))
2978 {
2979 // Extension already enabled
2980 return;
2981 }
2982
2983 mExtensions.*(extension.ExtensionsMember) = true;
2984 updateCaps();
2985 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08002986
Jamie Madill2f348d22017-06-05 10:50:59 -04002987 // Release the shader compiler so it will be re-created with the requested extensions enabled.
2988 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04002989
Jamie Madill81c2e252017-09-09 23:32:46 -04002990 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
2991 // sampleable.
Jamie Madilld4442552018-02-27 22:03:47 -05002992 mState.mTextures->signalAllTexturesDirty(this);
Geoff Lang9aded172017-04-05 11:07:56 -04002993 for (auto &zeroTexture : mZeroTextures)
2994 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002995 if (zeroTexture.get() != nullptr)
2996 {
2997 zeroTexture->signalDirty(this, InitState::Initialized);
2998 }
Geoff Lang9aded172017-04-05 11:07:56 -04002999 }
3000
3001 mState.mFramebuffers->invalidateFramebufferComplenessCache();
Geoff Langc339c4e2016-11-29 10:37:36 -05003002}
3003
3004size_t Context::getRequestableExtensionStringCount() const
3005{
3006 return mRequestableExtensionStrings.size();
3007}
3008
Jamie Madill493f9572018-05-24 19:52:15 -04003009void Context::beginTransformFeedback(PrimitiveMode primitiveMode)
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003010{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003011 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003012 ASSERT(transformFeedback != nullptr);
3013 ASSERT(!transformFeedback->isPaused());
3014
Jamie Madill6c1f6712017-02-14 19:08:04 -05003015 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003016}
3017
3018bool Context::hasActiveTransformFeedback(GLuint program) const
3019{
3020 for (auto pair : mTransformFeedbackMap)
3021 {
3022 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
3023 {
3024 return true;
3025 }
3026 }
3027 return false;
3028}
3029
Geoff Lang33f11fb2018-05-07 13:42:47 -04003030Extensions Context::generateSupportedExtensions() const
Geoff Langb0f917f2017-12-05 13:41:54 -05003031{
3032 Extensions supportedExtensions = mImplementation->getNativeExtensions();
3033
3034 if (getClientVersion() < ES_2_0)
3035 {
3036 // Default extensions for GLES1
3037 supportedExtensions.pointSizeArray = true;
Lingfeng Yang23dc90b2018-04-23 09:01:49 -07003038 supportedExtensions.textureCubeMap = true;
Geoff Langb0f917f2017-12-05 13:41:54 -05003039 }
3040
3041 if (getClientVersion() < ES_3_0)
3042 {
3043 // Disable ES3+ extensions
3044 supportedExtensions.colorBufferFloat = false;
3045 supportedExtensions.eglImageExternalEssl3 = false;
3046 supportedExtensions.textureNorm16 = false;
3047 supportedExtensions.multiview = false;
3048 supportedExtensions.maxViews = 1u;
3049 }
3050
3051 if (getClientVersion() < ES_3_1)
3052 {
3053 // Disable ES3.1+ extensions
3054 supportedExtensions.geometryShader = false;
3055 }
3056
3057 if (getClientVersion() > ES_2_0)
3058 {
3059 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
3060 // supportedExtensions.sRGB = false;
3061 }
3062
3063 // Some extensions are always available because they are implemented in the GL layer.
3064 supportedExtensions.bindUniformLocation = true;
3065 supportedExtensions.vertexArrayObject = true;
3066 supportedExtensions.bindGeneratesResource = true;
3067 supportedExtensions.clientArrays = true;
3068 supportedExtensions.requestExtension = true;
3069
3070 // Enable the no error extension if the context was created with the flag.
3071 supportedExtensions.noError = mSkipValidation;
3072
3073 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Geoff Lang33f11fb2018-05-07 13:42:47 -04003074 supportedExtensions.surfacelessContext = mSurfacelessSupported;
Geoff Langb0f917f2017-12-05 13:41:54 -05003075
3076 // Explicitly enable GL_KHR_debug
3077 supportedExtensions.debug = true;
3078 supportedExtensions.maxDebugMessageLength = 1024;
3079 supportedExtensions.maxDebugLoggedMessages = 1024;
3080 supportedExtensions.maxDebugGroupStackDepth = 1024;
3081 supportedExtensions.maxLabelLength = 1024;
3082
3083 // Explicitly enable GL_ANGLE_robust_client_memory
3084 supportedExtensions.robustClientMemory = true;
3085
3086 // Determine robust resource init availability from EGL.
Geoff Lang33f11fb2018-05-07 13:42:47 -04003087 supportedExtensions.robustResourceInitialization = mGLState.isRobustResourceInitEnabled();
Geoff Langb0f917f2017-12-05 13:41:54 -05003088
3089 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
3090 // supports it.
3091 supportedExtensions.robustBufferAccessBehavior =
3092 mRobustAccess && supportedExtensions.robustBufferAccessBehavior;
3093
3094 // Enable the cache control query unconditionally.
3095 supportedExtensions.programCacheControl = true;
3096
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003097 // Enable EGL_ANGLE_explicit_context subextensions
Geoff Lang33f11fb2018-05-07 13:42:47 -04003098 if (mExplicitContextAvailable)
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003099 {
3100 // GL_ANGLE_explicit_context_gles1
3101 supportedExtensions.explicitContextGles1 = true;
3102 // GL_ANGLE_explicit_context
3103 supportedExtensions.explicitContext = true;
3104 }
3105
Geoff Langb0f917f2017-12-05 13:41:54 -05003106 return supportedExtensions;
3107}
3108
Geoff Lang33f11fb2018-05-07 13:42:47 -04003109void Context::initCaps()
Geoff Lang493daf52014-07-03 13:38:44 -04003110{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04003111 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04003112
Geoff Lang33f11fb2018-05-07 13:42:47 -04003113 mSupportedExtensions = generateSupportedExtensions();
3114 mExtensions = mSupportedExtensions;
Lingfeng Yang01074432018-04-16 10:19:51 -07003115
3116 mLimitations = mImplementation->getNativeLimitations();
3117
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003118 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
3119 if (getClientVersion() < Version(2, 0))
3120 {
3121 mCaps.maxMultitextureUnits = 4;
3122 mCaps.maxClipPlanes = 6;
3123 mCaps.maxLights = 8;
Lingfeng Yange547aac2018-04-05 09:39:20 -07003124 mCaps.maxModelviewMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3125 mCaps.maxProjectionMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3126 mCaps.maxTextureMatrixStackDepth = Caps::GlobalMatrixStackDepth;
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003127 }
3128
Geoff Lang301d1612014-07-09 10:34:37 -04003129 // Apply implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04003130 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003131
Jamie Madill0f80ed82017-09-19 00:24:56 -04003132 if (getClientVersion() < ES_3_1)
3133 {
3134 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
3135 }
3136 else
3137 {
3138 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
3139 }
Geoff Lang301d1612014-07-09 10:34:37 -04003140
Jiawei Shao54aafe52018-04-27 14:54:57 +08003141 LimitCap(&mCaps.maxShaderUniformBlocks[ShaderType::Vertex],
3142 IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
Jamie Madill0f80ed82017-09-19 00:24:56 -04003143 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3144 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3145
3146 // Limit textures as well, so we can use fast bitsets with texture bindings.
3147 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
Jiawei Shao54aafe52018-04-27 14:54:57 +08003148 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Vertex],
3149 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
3150 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Fragment],
3151 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04003152
Jiawei Shaodb342272017-09-27 10:21:45 +08003153 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
3154
Geoff Langc287ea62016-09-16 14:46:51 -04003155 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05003156 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04003157 for (const auto &extensionInfo : GetExtensionInfoMap())
3158 {
Geoff Lang0ab41fa2018-03-14 11:03:30 -04003159 // If the user has requested that extensions start disabled and they are requestable,
3160 // disable them.
3161 if (!mExtensionsEnabled && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04003162 {
3163 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
3164 }
3165 }
3166
3167 // Generate texture caps
3168 updateCaps();
3169}
3170
3171void Context::updateCaps()
3172{
Geoff Lang900013c2014-07-07 11:32:19 -04003173 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04003174 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04003175
Jamie Madill7b62cf92017-11-02 15:20:49 -04003176 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04003177 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04003178 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04003179 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003180
Geoff Lang0d8b7242015-09-09 14:56:53 -04003181 // Update the format caps based on the client version and extensions.
3182 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
3183 // ES3.
3184 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003185 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04003186 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003187 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Yuly Novikovf15f8862018-06-04 18:59:41 -04003188 formatCaps.textureAttachment =
3189 formatCaps.textureAttachment &&
3190 formatInfo.textureAttachmentSupport(getClientVersion(), mExtensions);
3191 formatCaps.renderbuffer = formatCaps.renderbuffer &&
3192 formatInfo.renderbufferSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04003193
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003194 // OpenGL ES does not support multisampling with non-rendererable formats
3195 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Yuly Novikovf15f8862018-06-04 18:59:41 -04003196 if (!formatCaps.renderbuffer ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003197 (getClientVersion() < ES_3_1 &&
3198 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04003199 {
Geoff Langd87878e2014-09-19 15:42:59 -04003200 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04003201 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03003202 else
3203 {
3204 // We may have limited the max samples for some required renderbuffer formats due to
3205 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
3206 GLuint formatMaxSamples = formatCaps.getMaxSamples();
3207
3208 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
3209 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
3210 // exception of signed and unsigned integer formats."
3211 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
3212 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
3213 {
3214 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
3215 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
3216 }
3217
3218 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
3219 if (getClientVersion() >= ES_3_1)
3220 {
3221 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
3222 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
3223 // the exception that the signed and unsigned integer formats are required only to
3224 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
3225 // multisamples, which must be at least one."
3226 if (formatInfo.componentType == GL_INT ||
3227 formatInfo.componentType == GL_UNSIGNED_INT)
3228 {
3229 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
3230 }
3231
3232 // GLES 3.1 section 19.3.1.
3233 if (formatCaps.texturable)
3234 {
3235 if (formatInfo.depthBits > 0)
3236 {
3237 mCaps.maxDepthTextureSamples =
3238 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
3239 }
3240 else if (formatInfo.redBits > 0)
3241 {
3242 mCaps.maxColorTextureSamples =
3243 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
3244 }
3245 }
3246 }
3247 }
Geoff Langd87878e2014-09-19 15:42:59 -04003248
3249 if (formatCaps.texturable && formatInfo.compressed)
3250 {
Geoff Langca271392017-04-05 12:30:00 -04003251 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003252 }
3253
Geoff Langca271392017-04-05 12:30:00 -04003254 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04003255 }
Jamie Madill32447362017-06-28 14:53:52 -04003256
3257 // If program binary is disabled, blank out the memory cache pointer.
Geoff Langb0f917f2017-12-05 13:41:54 -05003258 if (!mSupportedExtensions.getProgramBinary)
Jamie Madill32447362017-06-28 14:53:52 -04003259 {
3260 mMemoryProgramCache = nullptr;
3261 }
Corentin Walleze4477002017-12-01 14:39:58 -05003262
3263 // Compute which buffer types are allowed
3264 mValidBufferBindings.reset();
3265 mValidBufferBindings.set(BufferBinding::ElementArray);
3266 mValidBufferBindings.set(BufferBinding::Array);
3267
3268 if (mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
3269 {
3270 mValidBufferBindings.set(BufferBinding::PixelPack);
3271 mValidBufferBindings.set(BufferBinding::PixelUnpack);
3272 }
3273
3274 if (getClientVersion() >= ES_3_0)
3275 {
3276 mValidBufferBindings.set(BufferBinding::CopyRead);
3277 mValidBufferBindings.set(BufferBinding::CopyWrite);
3278 mValidBufferBindings.set(BufferBinding::TransformFeedback);
3279 mValidBufferBindings.set(BufferBinding::Uniform);
3280 }
3281
3282 if (getClientVersion() >= ES_3_1)
3283 {
3284 mValidBufferBindings.set(BufferBinding::AtomicCounter);
3285 mValidBufferBindings.set(BufferBinding::ShaderStorage);
3286 mValidBufferBindings.set(BufferBinding::DrawIndirect);
3287 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
3288 }
Geoff Lang493daf52014-07-03 13:38:44 -04003289}
3290
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003291void Context::initWorkarounds()
3292{
Jamie Madill761b02c2017-06-23 16:27:06 -04003293 // Apply back-end workarounds.
3294 mImplementation->applyNativeWorkarounds(&mWorkarounds);
3295
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003296 // Lose the context upon out of memory error if the application is
3297 // expecting to watch for those events.
3298 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
3299}
3300
Jamie Madill05b35b22017-10-03 09:01:44 -04003301Error Context::prepareForDraw()
3302{
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003303 if (mGLES1Renderer)
3304 {
3305 ANGLE_TRY(mGLES1Renderer->prepareForDraw(this, &mGLState));
3306 }
3307
Geoff Langa8cb2872018-03-09 16:09:40 -05003308 ANGLE_TRY(syncDirtyObjects());
Jamie Madilla59fc192017-11-02 12:57:58 -04003309
3310 if (isRobustResourceInitEnabled())
3311 {
3312 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
3313 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
3314 }
3315
Geoff Langa8cb2872018-03-09 16:09:40 -05003316 ANGLE_TRY(syncDirtyBits());
Geoff Langd4fff502017-09-22 11:28:28 -04003317 return NoError();
3318}
3319
3320Error Context::prepareForClear(GLbitfield mask)
3321{
Geoff Langa8cb2872018-03-09 16:09:40 -05003322 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003323 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearAttachmentsInitialized(this, mask));
Geoff Langa8cb2872018-03-09 16:09:40 -05003324 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04003325 return NoError();
3326}
3327
3328Error Context::prepareForClearBuffer(GLenum buffer, GLint drawbuffer)
3329{
Geoff Langa8cb2872018-03-09 16:09:40 -05003330 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003331 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearBufferAttachmentsInitialized(this, buffer,
3332 drawbuffer));
Geoff Langa8cb2872018-03-09 16:09:40 -05003333 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill05b35b22017-10-03 09:01:44 -04003334 return NoError();
3335}
3336
Geoff Langa8cb2872018-03-09 16:09:40 -05003337Error Context::syncState()
Jamie Madill1b94d432015-08-07 13:23:23 -04003338{
Geoff Langa8cb2872018-03-09 16:09:40 -05003339 ANGLE_TRY(syncDirtyObjects());
3340 ANGLE_TRY(syncDirtyBits());
Jamie Madillbc918e72018-03-08 09:47:21 -05003341 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003342}
3343
Geoff Langa8cb2872018-03-09 16:09:40 -05003344Error Context::syncState(const State::DirtyBits &bitMask, const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04003345{
Geoff Langa8cb2872018-03-09 16:09:40 -05003346 ANGLE_TRY(syncDirtyObjects(objectMask));
3347 ANGLE_TRY(syncDirtyBits(bitMask));
Geoff Langd4fff502017-09-22 11:28:28 -04003348 return NoError();
3349}
3350
Geoff Langa8cb2872018-03-09 16:09:40 -05003351Error Context::syncDirtyBits()
Geoff Langd4fff502017-09-22 11:28:28 -04003352{
3353 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
3354 mImplementation->syncState(this, dirtyBits);
3355 mGLState.clearDirtyBits();
3356 return NoError();
3357}
3358
Geoff Langa8cb2872018-03-09 16:09:40 -05003359Error Context::syncDirtyBits(const State::DirtyBits &bitMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003360{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003361 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madillfe548342017-06-19 11:13:24 -04003362 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003363 mGLState.clearDirtyBits(dirtyBits);
Jamie Madillbc918e72018-03-08 09:47:21 -05003364 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003365}
Jamie Madillc29968b2016-01-20 11:17:23 -05003366
Geoff Langa8cb2872018-03-09 16:09:40 -05003367Error Context::syncDirtyObjects()
Geoff Langd4fff502017-09-22 11:28:28 -04003368{
3369 return mGLState.syncDirtyObjects(this);
3370}
3371
Geoff Langa8cb2872018-03-09 16:09:40 -05003372Error Context::syncDirtyObjects(const State::DirtyObjects &objectMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003373{
3374 return mGLState.syncDirtyObjects(this, objectMask);
3375}
3376
Jamie Madillc29968b2016-01-20 11:17:23 -05003377void Context::blitFramebuffer(GLint srcX0,
3378 GLint srcY0,
3379 GLint srcX1,
3380 GLint srcY1,
3381 GLint dstX0,
3382 GLint dstY0,
3383 GLint dstX1,
3384 GLint dstY1,
3385 GLbitfield mask,
3386 GLenum filter)
3387{
Qin Jiajiaaef92162018-02-27 13:51:44 +08003388 if (mask == 0)
3389 {
3390 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
3391 // buffers are copied.
3392 return;
3393 }
3394
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003395 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003396 ASSERT(drawFramebuffer);
3397
3398 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
3399 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
3400
Jamie Madillbc918e72018-03-08 09:47:21 -05003401 ANGLE_CONTEXT_TRY(syncStateForBlit());
Jamie Madillc29968b2016-01-20 11:17:23 -05003402
Jamie Madillc564c072017-06-01 12:45:42 -04003403 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003404}
Jamie Madillc29968b2016-01-20 11:17:23 -05003405
3406void Context::clear(GLbitfield mask)
3407{
Geoff Langd4fff502017-09-22 11:28:28 -04003408 ANGLE_CONTEXT_TRY(prepareForClear(mask));
3409 ANGLE_CONTEXT_TRY(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05003410}
3411
3412void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
3413{
Geoff Langd4fff502017-09-22 11:28:28 -04003414 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3415 ANGLE_CONTEXT_TRY(
3416 mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003417}
3418
3419void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3420{
Geoff Langd4fff502017-09-22 11:28:28 -04003421 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3422 ANGLE_CONTEXT_TRY(
3423 mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003424}
3425
3426void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3427{
Geoff Langd4fff502017-09-22 11:28:28 -04003428 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3429 ANGLE_CONTEXT_TRY(
3430 mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003431}
3432
3433void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3434{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003435 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003436 ASSERT(framebufferObject);
3437
3438 // If a buffer is not present, the clear has no effect
3439 if (framebufferObject->getDepthbuffer() == nullptr &&
3440 framebufferObject->getStencilbuffer() == nullptr)
3441 {
3442 return;
3443 }
3444
Geoff Langd4fff502017-09-22 11:28:28 -04003445 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3446 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003447}
3448
3449void Context::readPixels(GLint x,
3450 GLint y,
3451 GLsizei width,
3452 GLsizei height,
3453 GLenum format,
3454 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003455 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003456{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003457 if (width == 0 || height == 0)
3458 {
3459 return;
3460 }
3461
Jamie Madillbc918e72018-03-08 09:47:21 -05003462 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003463
Jamie Madillb6664922017-07-25 12:55:04 -04003464 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3465 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003466
3467 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04003468 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003469}
3470
Brandon Jones59770802018-04-02 13:18:42 -07003471void Context::readPixelsRobust(GLint x,
3472 GLint y,
3473 GLsizei width,
3474 GLsizei height,
3475 GLenum format,
3476 GLenum type,
3477 GLsizei bufSize,
3478 GLsizei *length,
3479 GLsizei *columns,
3480 GLsizei *rows,
3481 void *pixels)
3482{
3483 readPixels(x, y, width, height, format, type, pixels);
3484}
3485
3486void Context::readnPixelsRobust(GLint x,
3487 GLint y,
3488 GLsizei width,
3489 GLsizei height,
3490 GLenum format,
3491 GLenum type,
3492 GLsizei bufSize,
3493 GLsizei *length,
3494 GLsizei *columns,
3495 GLsizei *rows,
3496 void *data)
3497{
3498 readPixels(x, y, width, height, format, type, data);
3499}
3500
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003501void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003502 GLint level,
3503 GLenum internalformat,
3504 GLint x,
3505 GLint y,
3506 GLsizei width,
3507 GLsizei height,
3508 GLint border)
3509{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003510 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003511 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003512
Jamie Madillc29968b2016-01-20 11:17:23 -05003513 Rectangle sourceArea(x, y, width, height);
3514
Jamie Madill05b35b22017-10-03 09:01:44 -04003515 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003516 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003517 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003518}
3519
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003520void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003521 GLint level,
3522 GLint xoffset,
3523 GLint yoffset,
3524 GLint x,
3525 GLint y,
3526 GLsizei width,
3527 GLsizei height)
3528{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003529 if (width == 0 || height == 0)
3530 {
3531 return;
3532 }
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 Offset destOffset(xoffset, yoffset, 0);
3538 Rectangle sourceArea(x, y, width, height);
3539
Jamie Madill05b35b22017-10-03 09:01:44 -04003540 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003541 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003542 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003543}
3544
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003545void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003546 GLint level,
3547 GLint xoffset,
3548 GLint yoffset,
3549 GLint zoffset,
3550 GLint x,
3551 GLint y,
3552 GLsizei width,
3553 GLsizei height)
3554{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003555 if (width == 0 || height == 0)
3556 {
3557 return;
3558 }
3559
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003560 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003561 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003562
Jamie Madillc29968b2016-01-20 11:17:23 -05003563 Offset destOffset(xoffset, yoffset, zoffset);
3564 Rectangle sourceArea(x, y, width, height);
3565
Jamie Madill05b35b22017-10-03 09:01:44 -04003566 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3567 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003568 handleError(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level, destOffset,
3569 sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003570}
3571
3572void Context::framebufferTexture2D(GLenum target,
3573 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003574 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003575 GLuint texture,
3576 GLint level)
3577{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003578 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003579 ASSERT(framebuffer);
3580
3581 if (texture != 0)
3582 {
3583 Texture *textureObj = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003584 ImageIndex index = ImageIndex::MakeFromTarget(textarget, level);
Jamie Madilla02315b2017-02-23 14:14:47 -05003585 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003586 }
3587 else
3588 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003589 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003590 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003591
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003592 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003593}
3594
3595void Context::framebufferRenderbuffer(GLenum target,
3596 GLenum attachment,
3597 GLenum renderbuffertarget,
3598 GLuint renderbuffer)
3599{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003600 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003601 ASSERT(framebuffer);
3602
3603 if (renderbuffer != 0)
3604 {
3605 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003606
Jamie Madillcc129372018-04-12 09:13:18 -04003607 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003608 renderbufferObject);
3609 }
3610 else
3611 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003612 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003613 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003614
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003615 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003616}
3617
3618void Context::framebufferTextureLayer(GLenum target,
3619 GLenum attachment,
3620 GLuint texture,
3621 GLint level,
3622 GLint layer)
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 (texture != 0)
3628 {
3629 Texture *textureObject = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003630 ImageIndex index = ImageIndex::MakeFromType(textureObject->getType(), level, layer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003631 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003632 }
3633 else
3634 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003635 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003636 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003637
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003638 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003639}
3640
Brandon Jones59770802018-04-02 13:18:42 -07003641void Context::framebufferTextureMultiviewLayered(GLenum target,
3642 GLenum attachment,
3643 GLuint texture,
3644 GLint level,
3645 GLint baseViewIndex,
3646 GLsizei numViews)
Martin Radev137032d2017-07-13 10:11:12 +03003647{
Martin Radev82ef7742017-08-08 17:44:58 +03003648 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3649 ASSERT(framebuffer);
3650
3651 if (texture != 0)
3652 {
3653 Texture *textureObj = getTexture(texture);
3654
Martin Radev18b75ba2017-08-15 15:50:40 +03003655 ImageIndex index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
Martin Radev82ef7742017-08-08 17:44:58 +03003656 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3657 numViews, baseViewIndex);
3658 }
3659 else
3660 {
3661 framebuffer->resetAttachment(this, attachment);
3662 }
3663
3664 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003665}
3666
Brandon Jones59770802018-04-02 13:18:42 -07003667void Context::framebufferTextureMultiviewSideBySide(GLenum target,
3668 GLenum attachment,
3669 GLuint texture,
3670 GLint level,
3671 GLsizei numViews,
3672 const GLint *viewportOffsets)
Martin Radev137032d2017-07-13 10:11:12 +03003673{
Martin Radev5dae57b2017-07-14 16:15:55 +03003674 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3675 ASSERT(framebuffer);
3676
3677 if (texture != 0)
3678 {
3679 Texture *textureObj = getTexture(texture);
3680
3681 ImageIndex index = ImageIndex::Make2D(level);
3682 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3683 textureObj, numViews, viewportOffsets);
3684 }
3685 else
3686 {
3687 framebuffer->resetAttachment(this, attachment);
3688 }
3689
3690 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003691}
3692
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003693// TODO(jiawei.shao@intel.com): implement framebufferTextureEXT
3694void Context::framebufferTexture(GLenum target, GLenum attachment, GLuint texture, GLint level)
3695{
3696 UNIMPLEMENTED();
3697}
3698
Jamie Madillc29968b2016-01-20 11:17:23 -05003699void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3700{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003701 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003702 ASSERT(framebuffer);
3703 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003704 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003705}
3706
3707void Context::readBuffer(GLenum mode)
3708{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003709 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003710 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003711 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003712}
3713
3714void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3715{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003716 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003717 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003718
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003719 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003720 ASSERT(framebuffer);
3721
3722 // The specification isn't clear what should be done when the framebuffer isn't complete.
3723 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003724 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003725}
3726
3727void Context::invalidateFramebuffer(GLenum target,
3728 GLsizei numAttachments,
3729 const GLenum *attachments)
3730{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003731 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003732 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003733
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003734 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003735 ASSERT(framebuffer);
3736
Jamie Madill427064d2018-04-13 16:20:34 -04003737 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003738 {
Jamie Madill437fa652016-05-03 15:13:24 -04003739 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003740 }
Jamie Madill437fa652016-05-03 15:13:24 -04003741
Jamie Madill4928b7c2017-06-20 12:57:39 -04003742 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003743}
3744
3745void Context::invalidateSubFramebuffer(GLenum target,
3746 GLsizei numAttachments,
3747 const GLenum *attachments,
3748 GLint x,
3749 GLint y,
3750 GLsizei width,
3751 GLsizei height)
3752{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003753 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003754 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003755
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003756 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003757 ASSERT(framebuffer);
3758
Jamie Madill427064d2018-04-13 16:20:34 -04003759 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003760 {
Jamie Madill437fa652016-05-03 15:13:24 -04003761 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003762 }
Jamie Madill437fa652016-05-03 15:13:24 -04003763
3764 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003765 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003766}
3767
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003768void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003769 GLint level,
3770 GLint internalformat,
3771 GLsizei width,
3772 GLsizei height,
3773 GLint border,
3774 GLenum format,
3775 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003776 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003777{
Jamie Madillbc918e72018-03-08 09:47:21 -05003778 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003779
3780 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003781 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003782 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3783 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003784}
3785
Brandon Jones59770802018-04-02 13:18:42 -07003786void Context::texImage2DRobust(TextureTarget target,
3787 GLint level,
3788 GLint internalformat,
3789 GLsizei width,
3790 GLsizei height,
3791 GLint border,
3792 GLenum format,
3793 GLenum type,
3794 GLsizei bufSize,
3795 const void *pixels)
3796{
3797 texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
3798}
3799
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003800void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003801 GLint level,
3802 GLint internalformat,
3803 GLsizei width,
3804 GLsizei height,
3805 GLsizei depth,
3806 GLint border,
3807 GLenum format,
3808 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003809 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003810{
Jamie Madillbc918e72018-03-08 09:47:21 -05003811 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003812
3813 Extents size(width, height, depth);
3814 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003815 handleError(texture->setImage(this, mGLState.getUnpackState(),
3816 NonCubeTextureTypeToTarget(target), level, internalformat, size,
3817 format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003818}
3819
Brandon Jones59770802018-04-02 13:18:42 -07003820void Context::texImage3DRobust(TextureType target,
3821 GLint level,
3822 GLint internalformat,
3823 GLsizei width,
3824 GLsizei height,
3825 GLsizei depth,
3826 GLint border,
3827 GLenum format,
3828 GLenum type,
3829 GLsizei bufSize,
3830 const void *pixels)
3831{
3832 texImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels);
3833}
3834
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003835void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003836 GLint level,
3837 GLint xoffset,
3838 GLint yoffset,
3839 GLsizei width,
3840 GLsizei height,
3841 GLenum format,
3842 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003843 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003844{
3845 // Zero sized uploads are valid but no-ops
3846 if (width == 0 || height == 0)
3847 {
3848 return;
3849 }
3850
Jamie Madillbc918e72018-03-08 09:47:21 -05003851 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003852
3853 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003854 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003855 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3856 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003857}
3858
Brandon Jones59770802018-04-02 13:18:42 -07003859void Context::texSubImage2DRobust(TextureTarget target,
3860 GLint level,
3861 GLint xoffset,
3862 GLint yoffset,
3863 GLsizei width,
3864 GLsizei height,
3865 GLenum format,
3866 GLenum type,
3867 GLsizei bufSize,
3868 const void *pixels)
3869{
3870 texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
3871}
3872
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003873void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003874 GLint level,
3875 GLint xoffset,
3876 GLint yoffset,
3877 GLint zoffset,
3878 GLsizei width,
3879 GLsizei height,
3880 GLsizei depth,
3881 GLenum format,
3882 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003883 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003884{
3885 // Zero sized uploads are valid but no-ops
3886 if (width == 0 || height == 0 || depth == 0)
3887 {
3888 return;
3889 }
3890
Jamie Madillbc918e72018-03-08 09:47:21 -05003891 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003892
3893 Box area(xoffset, yoffset, zoffset, width, height, depth);
3894 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003895 handleError(texture->setSubImage(this, mGLState.getUnpackState(),
3896 NonCubeTextureTypeToTarget(target), level, area, format, type,
3897 reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003898}
3899
Brandon Jones59770802018-04-02 13:18:42 -07003900void Context::texSubImage3DRobust(TextureType target,
3901 GLint level,
3902 GLint xoffset,
3903 GLint yoffset,
3904 GLint zoffset,
3905 GLsizei width,
3906 GLsizei height,
3907 GLsizei depth,
3908 GLenum format,
3909 GLenum type,
3910 GLsizei bufSize,
3911 const void *pixels)
3912{
3913 texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type,
3914 pixels);
3915}
3916
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003917void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003918 GLint level,
3919 GLenum internalformat,
3920 GLsizei width,
3921 GLsizei height,
3922 GLint border,
3923 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003924 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003925{
Jamie Madillbc918e72018-03-08 09:47:21 -05003926 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003927
3928 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003929 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003930 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
3931 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003932 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003933}
3934
Brandon Jones59770802018-04-02 13:18:42 -07003935void Context::compressedTexImage2DRobust(TextureTarget target,
3936 GLint level,
3937 GLenum internalformat,
3938 GLsizei width,
3939 GLsizei height,
3940 GLint border,
3941 GLsizei imageSize,
3942 GLsizei dataSize,
3943 const GLvoid *data)
3944{
3945 compressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
3946}
3947
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003948void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003949 GLint level,
3950 GLenum internalformat,
3951 GLsizei width,
3952 GLsizei height,
3953 GLsizei depth,
3954 GLint border,
3955 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003956 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003957{
Jamie Madillbc918e72018-03-08 09:47:21 -05003958 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003959
3960 Extents size(width, height, depth);
3961 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003962 handleError(texture->setCompressedImage(
3963 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
3964 size, imageSize, reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003965}
3966
Brandon Jones59770802018-04-02 13:18:42 -07003967void Context::compressedTexImage3DRobust(TextureType target,
3968 GLint level,
3969 GLenum internalformat,
3970 GLsizei width,
3971 GLsizei height,
3972 GLsizei depth,
3973 GLint border,
3974 GLsizei imageSize,
3975 GLsizei dataSize,
3976 const GLvoid *data)
3977{
3978 compressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize,
3979 data);
3980}
3981
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003982void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003983 GLint level,
3984 GLint xoffset,
3985 GLint yoffset,
3986 GLsizei width,
3987 GLsizei height,
3988 GLenum format,
3989 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003990 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003991{
Jamie Madillbc918e72018-03-08 09:47:21 -05003992 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003993
3994 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003995 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003996 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
3997 format, imageSize,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003998 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003999}
4000
Brandon Jones59770802018-04-02 13:18:42 -07004001void Context::compressedTexSubImage2DRobust(TextureTarget target,
4002 GLint level,
4003 GLint xoffset,
4004 GLint yoffset,
4005 GLsizei width,
4006 GLsizei height,
4007 GLenum format,
4008 GLsizei imageSize,
4009 GLsizei dataSize,
4010 const GLvoid *data)
4011{
4012 compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize,
4013 data);
4014}
4015
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004016void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004017 GLint level,
4018 GLint xoffset,
4019 GLint yoffset,
4020 GLint zoffset,
4021 GLsizei width,
4022 GLsizei height,
4023 GLsizei depth,
4024 GLenum format,
4025 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004026 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004027{
4028 // Zero sized uploads are valid but no-ops
4029 if (width == 0 || height == 0)
4030 {
4031 return;
4032 }
4033
Jamie Madillbc918e72018-03-08 09:47:21 -05004034 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004035
4036 Box area(xoffset, yoffset, zoffset, width, height, depth);
4037 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004038 handleError(texture->setCompressedSubImage(
4039 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
4040 imageSize, reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004041}
4042
Brandon Jones59770802018-04-02 13:18:42 -07004043void Context::compressedTexSubImage3DRobust(TextureType target,
4044 GLint level,
4045 GLint xoffset,
4046 GLint yoffset,
4047 GLint zoffset,
4048 GLsizei width,
4049 GLsizei height,
4050 GLsizei depth,
4051 GLenum format,
4052 GLsizei imageSize,
4053 GLsizei dataSize,
4054 const GLvoid *data)
4055{
4056 compressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format,
4057 imageSize, data);
4058}
4059
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004060void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004061{
4062 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05004063 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004064}
4065
Jamie Madill007530e2017-12-28 14:27:04 -05004066void Context::copyTexture(GLuint sourceId,
4067 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004068 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004069 GLuint destId,
4070 GLint destLevel,
4071 GLint internalFormat,
4072 GLenum destType,
4073 GLboolean unpackFlipY,
4074 GLboolean unpackPremultiplyAlpha,
4075 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004076{
Jamie Madillbc918e72018-03-08 09:47:21 -05004077 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004078
4079 gl::Texture *sourceTexture = getTexture(sourceId);
4080 gl::Texture *destTexture = getTexture(destId);
Geoff Lang92019432017-11-20 13:09:34 -05004081 handleError(destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType,
4082 sourceLevel, ConvertToBool(unpackFlipY),
4083 ConvertToBool(unpackPremultiplyAlpha),
4084 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004085}
4086
Jamie Madill007530e2017-12-28 14:27:04 -05004087void Context::copySubTexture(GLuint sourceId,
4088 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004089 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004090 GLuint destId,
4091 GLint destLevel,
4092 GLint xoffset,
4093 GLint yoffset,
4094 GLint x,
4095 GLint y,
4096 GLsizei width,
4097 GLsizei height,
4098 GLboolean unpackFlipY,
4099 GLboolean unpackPremultiplyAlpha,
4100 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004101{
4102 // Zero sized copies are valid but no-ops
4103 if (width == 0 || height == 0)
4104 {
4105 return;
4106 }
4107
Jamie Madillbc918e72018-03-08 09:47:21 -05004108 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004109
4110 gl::Texture *sourceTexture = getTexture(sourceId);
4111 gl::Texture *destTexture = getTexture(destId);
4112 Offset offset(xoffset, yoffset, 0);
4113 Rectangle area(x, y, width, height);
Geoff Lang92019432017-11-20 13:09:34 -05004114 handleError(destTexture->copySubTexture(this, destTarget, destLevel, offset, sourceLevel, area,
4115 ConvertToBool(unpackFlipY),
4116 ConvertToBool(unpackPremultiplyAlpha),
4117 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004118}
4119
Jamie Madill007530e2017-12-28 14:27:04 -05004120void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07004121{
Jamie Madillbc918e72018-03-08 09:47:21 -05004122 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07004123
4124 gl::Texture *sourceTexture = getTexture(sourceId);
4125 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05004126 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07004127}
4128
Corentin Wallez336129f2017-10-17 15:55:40 -04004129void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03004130{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004131 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004132 ASSERT(buffer);
4133
Geoff Lang496c02d2016-10-20 11:38:11 -07004134 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03004135}
4136
Brandon Jones59770802018-04-02 13:18:42 -07004137void Context::getBufferPointervRobust(BufferBinding target,
4138 GLenum pname,
4139 GLsizei bufSize,
4140 GLsizei *length,
4141 void **params)
4142{
4143 getBufferPointerv(target, pname, params);
4144}
4145
Corentin Wallez336129f2017-10-17 15:55:40 -04004146void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004147{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004148 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004149 ASSERT(buffer);
4150
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004151 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004152 if (error.isError())
4153 {
Jamie Madill437fa652016-05-03 15:13:24 -04004154 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004155 return nullptr;
4156 }
4157
4158 return buffer->getMapPointer();
4159}
4160
Corentin Wallez336129f2017-10-17 15:55:40 -04004161GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03004162{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004163 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004164 ASSERT(buffer);
4165
4166 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004167 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03004168 if (error.isError())
4169 {
Jamie Madill437fa652016-05-03 15:13:24 -04004170 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004171 return GL_FALSE;
4172 }
4173
4174 return result;
4175}
4176
Corentin Wallez336129f2017-10-17 15:55:40 -04004177void *Context::mapBufferRange(BufferBinding target,
4178 GLintptr offset,
4179 GLsizeiptr length,
4180 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004181{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004182 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004183 ASSERT(buffer);
4184
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004185 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004186 if (error.isError())
4187 {
Jamie Madill437fa652016-05-03 15:13:24 -04004188 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004189 return nullptr;
4190 }
4191
4192 return buffer->getMapPointer();
4193}
4194
Corentin Wallez336129f2017-10-17 15:55:40 -04004195void Context::flushMappedBufferRange(BufferBinding /*target*/,
4196 GLintptr /*offset*/,
4197 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03004198{
4199 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
4200}
4201
Jamie Madillbc918e72018-03-08 09:47:21 -05004202Error Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004203{
Geoff Langa8cb2872018-03-09 16:09:40 -05004204 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004205}
4206
Jamie Madillbc918e72018-03-08 09:47:21 -05004207Error Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004208{
Geoff Langa8cb2872018-03-09 16:09:40 -05004209 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004210}
4211
Jamie Madillbc918e72018-03-08 09:47:21 -05004212Error Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004213{
Geoff Langa8cb2872018-03-09 16:09:40 -05004214 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004215}
4216
Jiajia Qin5451d532017-11-16 17:16:34 +08004217void Context::activeShaderProgram(GLuint pipeline, GLuint program)
4218{
4219 UNIMPLEMENTED();
4220}
4221
Jamie Madillc20ab272016-06-09 07:20:46 -07004222void Context::activeTexture(GLenum texture)
4223{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004224 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004225}
4226
Jamie Madill876429b2017-04-20 15:46:24 -04004227void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004228{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004229 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004230}
4231
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004232void Context::blendEquation(GLenum mode)
4233{
4234 mGLState.setBlendEquation(mode, mode);
4235}
4236
Jamie Madillc20ab272016-06-09 07:20:46 -07004237void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
4238{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004239 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004240}
4241
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004242void Context::blendFunc(GLenum sfactor, GLenum dfactor)
4243{
4244 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
4245}
4246
Jamie Madillc20ab272016-06-09 07:20:46 -07004247void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
4248{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004249 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004250}
4251
Jamie Madill876429b2017-04-20 15:46:24 -04004252void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004253{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004254 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004255}
4256
Jamie Madill876429b2017-04-20 15:46:24 -04004257void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07004258{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004259 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07004260}
4261
4262void Context::clearStencil(GLint s)
4263{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004264 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07004265}
4266
4267void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
4268{
Geoff Lang92019432017-11-20 13:09:34 -05004269 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
4270 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004271}
4272
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004273void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07004274{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004275 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004276}
4277
4278void Context::depthFunc(GLenum func)
4279{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004280 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07004281}
4282
4283void Context::depthMask(GLboolean flag)
4284{
Geoff Lang92019432017-11-20 13:09:34 -05004285 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07004286}
4287
Jamie Madill876429b2017-04-20 15:46:24 -04004288void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07004289{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004290 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07004291}
4292
4293void Context::disable(GLenum cap)
4294{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004295 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07004296}
4297
4298void Context::disableVertexAttribArray(GLuint index)
4299{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004300 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07004301}
4302
4303void Context::enable(GLenum cap)
4304{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004305 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07004306}
4307
4308void Context::enableVertexAttribArray(GLuint index)
4309{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004310 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07004311}
4312
4313void Context::frontFace(GLenum mode)
4314{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004315 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004316}
4317
4318void Context::hint(GLenum target, GLenum mode)
4319{
4320 switch (target)
4321 {
4322 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004323 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004324 break;
4325
4326 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004327 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004328 break;
4329
4330 default:
4331 UNREACHABLE();
4332 return;
4333 }
4334}
4335
4336void Context::lineWidth(GLfloat width)
4337{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004338 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07004339}
4340
4341void Context::pixelStorei(GLenum pname, GLint param)
4342{
4343 switch (pname)
4344 {
4345 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004346 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004347 break;
4348
4349 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004350 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004351 break;
4352
4353 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004354 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004355 break;
4356
4357 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004358 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004359 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004360 break;
4361
4362 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03004363 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004364 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004365 break;
4366
4367 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03004368 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004369 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004370 break;
4371
4372 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004373 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004374 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004375 break;
4376
4377 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004378 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004379 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004380 break;
4381
4382 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004383 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004384 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004385 break;
4386
4387 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004388 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004389 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004390 break;
4391
4392 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004393 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004394 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004395 break;
4396
4397 default:
4398 UNREACHABLE();
4399 return;
4400 }
4401}
4402
4403void Context::polygonOffset(GLfloat factor, GLfloat units)
4404{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004405 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07004406}
4407
Jamie Madill876429b2017-04-20 15:46:24 -04004408void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07004409{
Geoff Lang92019432017-11-20 13:09:34 -05004410 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07004411}
4412
Jiawei Shaodb342272017-09-27 10:21:45 +08004413void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
4414{
4415 mGLState.setSampleMaskParams(maskNumber, mask);
4416}
4417
Jamie Madillc20ab272016-06-09 07:20:46 -07004418void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
4419{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004420 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004421}
4422
4423void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
4424{
4425 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4426 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004427 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004428 }
4429
4430 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4431 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004432 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004433 }
4434}
4435
4436void Context::stencilMaskSeparate(GLenum face, GLuint mask)
4437{
4438 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4439 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004440 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004441 }
4442
4443 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4444 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004445 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004446 }
4447}
4448
4449void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4450{
4451 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4452 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004453 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004454 }
4455
4456 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4457 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004458 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004459 }
4460}
4461
4462void Context::vertexAttrib1f(GLuint index, GLfloat x)
4463{
4464 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004465 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004466}
4467
4468void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
4469{
4470 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004471 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004472}
4473
4474void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4475{
4476 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004477 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004478}
4479
4480void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
4481{
4482 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004483 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004484}
4485
4486void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4487{
4488 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004489 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004490}
4491
4492void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
4493{
4494 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004495 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004496}
4497
4498void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4499{
4500 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004501 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004502}
4503
4504void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
4505{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004506 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07004507}
4508
4509void Context::vertexAttribPointer(GLuint index,
4510 GLint size,
4511 GLenum type,
4512 GLboolean normalized,
4513 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004514 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07004515{
Corentin Wallez336129f2017-10-17 15:55:40 -04004516 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05004517 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc20ab272016-06-09 07:20:46 -07004518}
4519
Shao80957d92017-02-20 21:25:59 +08004520void Context::vertexAttribFormat(GLuint attribIndex,
4521 GLint size,
4522 GLenum type,
4523 GLboolean normalized,
4524 GLuint relativeOffset)
4525{
Geoff Lang92019432017-11-20 13:09:34 -05004526 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08004527 relativeOffset);
4528}
4529
4530void Context::vertexAttribIFormat(GLuint attribIndex,
4531 GLint size,
4532 GLenum type,
4533 GLuint relativeOffset)
4534{
4535 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
4536}
4537
4538void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4539{
Shaodde78e82017-05-22 14:13:27 +08004540 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Shao80957d92017-02-20 21:25:59 +08004541}
4542
Jiajia Qin5451d532017-11-16 17:16:34 +08004543void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004544{
4545 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
4546}
4547
Jamie Madillc20ab272016-06-09 07:20:46 -07004548void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4549{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004550 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004551}
4552
4553void Context::vertexAttribIPointer(GLuint index,
4554 GLint size,
4555 GLenum type,
4556 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004557 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004558{
Corentin Wallez336129f2017-10-17 15:55:40 -04004559 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
4560 size, type, false, true, stride, pointer);
Jamie Madillc20ab272016-06-09 07:20:46 -07004561}
4562
4563void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4564{
4565 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004566 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004567}
4568
4569void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4570{
4571 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004572 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004573}
4574
4575void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4576{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004577 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004578}
4579
4580void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4581{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004582 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004583}
4584
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004585void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4586{
4587 const VertexAttribCurrentValueData &currentValues =
4588 getGLState().getVertexAttribCurrentValue(index);
4589 const VertexArray *vao = getGLState().getVertexArray();
4590 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4591 currentValues, pname, params);
4592}
4593
Brandon Jones59770802018-04-02 13:18:42 -07004594void Context::getVertexAttribivRobust(GLuint index,
4595 GLenum pname,
4596 GLsizei bufSize,
4597 GLsizei *length,
4598 GLint *params)
4599{
4600 getVertexAttribiv(index, pname, params);
4601}
4602
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004603void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4604{
4605 const VertexAttribCurrentValueData &currentValues =
4606 getGLState().getVertexAttribCurrentValue(index);
4607 const VertexArray *vao = getGLState().getVertexArray();
4608 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4609 currentValues, pname, params);
4610}
4611
Brandon Jones59770802018-04-02 13:18:42 -07004612void Context::getVertexAttribfvRobust(GLuint index,
4613 GLenum pname,
4614 GLsizei bufSize,
4615 GLsizei *length,
4616 GLfloat *params)
4617{
4618 getVertexAttribfv(index, pname, params);
4619}
4620
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004621void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4622{
4623 const VertexAttribCurrentValueData &currentValues =
4624 getGLState().getVertexAttribCurrentValue(index);
4625 const VertexArray *vao = getGLState().getVertexArray();
4626 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4627 currentValues, pname, params);
4628}
4629
Brandon Jones59770802018-04-02 13:18:42 -07004630void Context::getVertexAttribIivRobust(GLuint index,
4631 GLenum pname,
4632 GLsizei bufSize,
4633 GLsizei *length,
4634 GLint *params)
4635{
4636 getVertexAttribIiv(index, pname, params);
4637}
4638
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004639void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4640{
4641 const VertexAttribCurrentValueData &currentValues =
4642 getGLState().getVertexAttribCurrentValue(index);
4643 const VertexArray *vao = getGLState().getVertexArray();
4644 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4645 currentValues, pname, params);
4646}
4647
Brandon Jones59770802018-04-02 13:18:42 -07004648void Context::getVertexAttribIuivRobust(GLuint index,
4649 GLenum pname,
4650 GLsizei bufSize,
4651 GLsizei *length,
4652 GLuint *params)
4653{
4654 getVertexAttribIuiv(index, pname, params);
4655}
4656
Jamie Madill876429b2017-04-20 15:46:24 -04004657void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004658{
4659 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
4660 QueryVertexAttribPointerv(attrib, pname, pointer);
4661}
4662
Brandon Jones59770802018-04-02 13:18:42 -07004663void Context::getVertexAttribPointervRobust(GLuint index,
4664 GLenum pname,
4665 GLsizei bufSize,
4666 GLsizei *length,
4667 void **pointer)
4668{
4669 getVertexAttribPointerv(index, pname, pointer);
4670}
4671
Jamie Madillc20ab272016-06-09 07:20:46 -07004672void Context::debugMessageControl(GLenum source,
4673 GLenum type,
4674 GLenum severity,
4675 GLsizei count,
4676 const GLuint *ids,
4677 GLboolean enabled)
4678{
4679 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004680 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05004681 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004682}
4683
4684void Context::debugMessageInsert(GLenum source,
4685 GLenum type,
4686 GLuint id,
4687 GLenum severity,
4688 GLsizei length,
4689 const GLchar *buf)
4690{
4691 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004692 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004693}
4694
4695void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4696{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004697 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004698}
4699
4700GLuint Context::getDebugMessageLog(GLuint count,
4701 GLsizei bufSize,
4702 GLenum *sources,
4703 GLenum *types,
4704 GLuint *ids,
4705 GLenum *severities,
4706 GLsizei *lengths,
4707 GLchar *messageLog)
4708{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004709 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4710 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004711}
4712
4713void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4714{
4715 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004716 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05004717 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07004718}
4719
4720void Context::popDebugGroup()
4721{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004722 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05004723 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004724}
4725
Corentin Wallez336129f2017-10-17 15:55:40 -04004726void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004727{
4728 Buffer *buffer = mGLState.getTargetBuffer(target);
4729 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004730 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004731}
4732
Corentin Wallez336129f2017-10-17 15:55:40 -04004733void Context::bufferSubData(BufferBinding target,
4734 GLintptr offset,
4735 GLsizeiptr size,
4736 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004737{
4738 if (data == nullptr)
4739 {
4740 return;
4741 }
4742
4743 Buffer *buffer = mGLState.getTargetBuffer(target);
4744 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004745 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004746}
4747
Jamie Madillef300b12016-10-07 15:12:09 -04004748void Context::attachShader(GLuint program, GLuint shader)
4749{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05004750 Program *programObject = mState.mShaderPrograms->getProgram(program);
4751 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004752 ASSERT(programObject && shaderObject);
4753 programObject->attachShader(shaderObject);
4754}
4755
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004756const Workarounds &Context::getWorkarounds() const
4757{
4758 return mWorkarounds;
4759}
4760
Corentin Wallez336129f2017-10-17 15:55:40 -04004761void Context::copyBufferSubData(BufferBinding readTarget,
4762 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04004763 GLintptr readOffset,
4764 GLintptr writeOffset,
4765 GLsizeiptr size)
4766{
4767 // if size is zero, the copy is a successful no-op
4768 if (size == 0)
4769 {
4770 return;
4771 }
4772
4773 // TODO(jmadill): cache these.
4774 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4775 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4776
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004777 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004778}
4779
Jamie Madill01a80ee2016-11-07 12:06:18 -05004780void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4781{
4782 Program *programObject = getProgram(program);
4783 // TODO(jmadill): Re-use this from the validation if possible.
4784 ASSERT(programObject);
4785 programObject->bindAttributeLocation(index, name);
4786}
4787
Corentin Wallez336129f2017-10-17 15:55:40 -04004788void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004789{
Corentin Wallez336129f2017-10-17 15:55:40 -04004790 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4791 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004792}
4793
Corentin Wallez336129f2017-10-17 15:55:40 -04004794void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08004795{
4796 bindBufferRange(target, index, buffer, 0, 0);
4797}
4798
Corentin Wallez336129f2017-10-17 15:55:40 -04004799void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08004800 GLuint index,
4801 GLuint buffer,
4802 GLintptr offset,
4803 GLsizeiptr size)
4804{
Corentin Wallez336129f2017-10-17 15:55:40 -04004805 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4806 mGLState.setIndexedBufferBinding(this, target, index, bufferObject, offset, size);
Jiajia Qin6eafb042016-12-27 17:04:07 +08004807}
4808
Jamie Madill01a80ee2016-11-07 12:06:18 -05004809void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
4810{
4811 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4812 {
4813 bindReadFramebuffer(framebuffer);
4814 }
4815
4816 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4817 {
4818 bindDrawFramebuffer(framebuffer);
4819 }
4820}
4821
4822void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4823{
4824 ASSERT(target == GL_RENDERBUFFER);
4825 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004826 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04004827 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004828}
4829
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004830void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08004831 GLsizei samples,
4832 GLenum internalformat,
4833 GLsizei width,
4834 GLsizei height,
4835 GLboolean fixedsamplelocations)
4836{
4837 Extents size(width, height, 1);
4838 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004839 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
4840 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004841}
4842
4843void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4844{
JiangYizhou5b03f472017-01-09 10:22:53 +08004845 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
4846 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillbc918e72018-03-08 09:47:21 -05004847 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
JiangYizhou5b03f472017-01-09 10:22:53 +08004848 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08004849
4850 switch (pname)
4851 {
4852 case GL_SAMPLE_POSITION:
Geoff Lang13455072018-05-09 11:24:43 -04004853 handleError(framebuffer->getSamplePosition(this, index, val));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004854 break;
4855 default:
4856 UNREACHABLE();
4857 }
4858}
4859
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07004860void Context::getMultisamplefvRobust(GLenum pname,
4861 GLuint index,
4862 GLsizei bufSize,
4863 GLsizei *length,
4864 GLfloat *val)
4865{
4866 UNIMPLEMENTED();
4867}
4868
Jamie Madille8fb6402017-02-14 17:56:40 -05004869void Context::renderbufferStorage(GLenum target,
4870 GLenum internalformat,
4871 GLsizei width,
4872 GLsizei height)
4873{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004874 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4875 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
4876
Jamie Madille8fb6402017-02-14 17:56:40 -05004877 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04004878 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004879}
4880
4881void Context::renderbufferStorageMultisample(GLenum target,
4882 GLsizei samples,
4883 GLenum internalformat,
4884 GLsizei width,
4885 GLsizei height)
4886{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004887 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4888 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05004889
4890 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004891 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04004892 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004893}
4894
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004895void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
4896{
Jamie Madill70b5bb02017-08-28 13:32:37 -04004897 const Sync *syncObject = getSync(sync);
Geoff Lang82483b92017-04-11 15:33:00 -04004898 handleError(QuerySynciv(syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004899}
4900
JiangYizhoue18e6392017-02-20 10:32:23 +08004901void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
4902{
4903 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4904 QueryFramebufferParameteriv(framebuffer, pname, params);
4905}
4906
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07004907void Context::getFramebufferParameterivRobust(GLenum target,
4908 GLenum pname,
4909 GLsizei bufSize,
4910 GLsizei *length,
4911 GLint *params)
4912{
4913 UNIMPLEMENTED();
4914}
4915
Jiajia Qin5451d532017-11-16 17:16:34 +08004916void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08004917{
4918 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4919 SetFramebufferParameteri(framebuffer, pname, param);
4920}
4921
Jamie Madillb3f26b92017-07-19 15:07:41 -04004922Error Context::getScratchBuffer(size_t requstedSizeBytes,
4923 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05004924{
Jamie Madillb3f26b92017-07-19 15:07:41 -04004925 if (!mScratchBuffer.get(requstedSizeBytes, scratchBufferOut))
4926 {
4927 return OutOfMemory() << "Failed to allocate internal buffer.";
4928 }
4929 return NoError();
4930}
4931
4932Error Context::getZeroFilledBuffer(size_t requstedSizeBytes,
4933 angle::MemoryBuffer **zeroBufferOut) const
4934{
4935 if (!mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0))
Jamie Madille14951e2017-03-09 18:55:16 -05004936 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004937 return OutOfMemory() << "Failed to allocate internal buffer.";
Jamie Madille14951e2017-03-09 18:55:16 -05004938 }
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004939 return NoError();
Jamie Madille14951e2017-03-09 18:55:16 -05004940}
4941
Xinghua Cao10a4d432017-11-28 14:46:26 +08004942Error Context::prepareForDispatch()
4943{
Geoff Langa8cb2872018-03-09 16:09:40 -05004944 ANGLE_TRY(syncState(mComputeDirtyBits, mComputeDirtyObjects));
Xinghua Cao10a4d432017-11-28 14:46:26 +08004945
4946 if (isRobustResourceInitEnabled())
4947 {
4948 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
4949 }
4950
4951 return NoError();
4952}
4953
Xinghua Cao2b396592017-03-29 15:36:04 +08004954void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
4955{
4956 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
4957 {
4958 return;
4959 }
4960
Xinghua Cao10a4d432017-11-28 14:46:26 +08004961 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill71c88b32017-09-14 22:20:29 -04004962 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08004963}
4964
Jiajia Qin5451d532017-11-16 17:16:34 +08004965void Context::dispatchComputeIndirect(GLintptr indirect)
4966{
Qin Jiajia62fcf622017-11-30 16:16:12 +08004967 ANGLE_CONTEXT_TRY(prepareForDispatch());
4968 handleError(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08004969}
4970
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004971void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08004972 GLsizei levels,
4973 GLenum internalFormat,
4974 GLsizei width,
4975 GLsizei height)
4976{
4977 Extents size(width, height, 1);
4978 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004979 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08004980}
4981
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004982void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08004983 GLsizei levels,
4984 GLenum internalFormat,
4985 GLsizei width,
4986 GLsizei height,
4987 GLsizei depth)
4988{
4989 Extents size(width, height, depth);
4990 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004991 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08004992}
4993
Jiajia Qin5451d532017-11-16 17:16:34 +08004994void Context::memoryBarrier(GLbitfield barriers)
4995{
Xinghua Cao89c422a2017-11-29 18:24:20 +08004996 handleError(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08004997}
4998
4999void Context::memoryBarrierByRegion(GLbitfield barriers)
5000{
Xinghua Cao89c422a2017-11-29 18:24:20 +08005001 handleError(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005002}
5003
Jamie Madillc1d770e2017-04-13 17:31:24 -04005004GLenum Context::checkFramebufferStatus(GLenum target)
5005{
5006 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5007 ASSERT(framebuffer);
Jamie Madill427064d2018-04-13 16:20:34 -04005008 return framebuffer->checkStatus(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005009}
5010
5011void Context::compileShader(GLuint shader)
5012{
5013 Shader *shaderObject = GetValidShader(this, shader);
5014 if (!shaderObject)
5015 {
5016 return;
5017 }
5018 shaderObject->compile(this);
5019}
5020
5021void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
5022{
5023 for (int i = 0; i < n; i++)
5024 {
5025 deleteBuffer(buffers[i]);
5026 }
5027}
5028
5029void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
5030{
5031 for (int i = 0; i < n; i++)
5032 {
5033 if (framebuffers[i] != 0)
5034 {
5035 deleteFramebuffer(framebuffers[i]);
5036 }
5037 }
5038}
5039
5040void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
5041{
5042 for (int i = 0; i < n; i++)
5043 {
5044 deleteRenderbuffer(renderbuffers[i]);
5045 }
5046}
5047
5048void Context::deleteTextures(GLsizei n, const GLuint *textures)
5049{
5050 for (int i = 0; i < n; i++)
5051 {
5052 if (textures[i] != 0)
5053 {
5054 deleteTexture(textures[i]);
5055 }
5056 }
5057}
5058
5059void Context::detachShader(GLuint program, GLuint shader)
5060{
5061 Program *programObject = getProgram(program);
5062 ASSERT(programObject);
5063
5064 Shader *shaderObject = getShader(shader);
5065 ASSERT(shaderObject);
5066
5067 programObject->detachShader(this, shaderObject);
5068}
5069
5070void Context::genBuffers(GLsizei n, GLuint *buffers)
5071{
5072 for (int i = 0; i < n; i++)
5073 {
5074 buffers[i] = createBuffer();
5075 }
5076}
5077
5078void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
5079{
5080 for (int i = 0; i < n; i++)
5081 {
5082 framebuffers[i] = createFramebuffer();
5083 }
5084}
5085
5086void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
5087{
5088 for (int i = 0; i < n; i++)
5089 {
5090 renderbuffers[i] = createRenderbuffer();
5091 }
5092}
5093
5094void Context::genTextures(GLsizei n, GLuint *textures)
5095{
5096 for (int i = 0; i < n; i++)
5097 {
5098 textures[i] = createTexture();
5099 }
5100}
5101
5102void Context::getActiveAttrib(GLuint program,
5103 GLuint index,
5104 GLsizei bufsize,
5105 GLsizei *length,
5106 GLint *size,
5107 GLenum *type,
5108 GLchar *name)
5109{
5110 Program *programObject = getProgram(program);
5111 ASSERT(programObject);
5112 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
5113}
5114
5115void Context::getActiveUniform(GLuint program,
5116 GLuint index,
5117 GLsizei bufsize,
5118 GLsizei *length,
5119 GLint *size,
5120 GLenum *type,
5121 GLchar *name)
5122{
5123 Program *programObject = getProgram(program);
5124 ASSERT(programObject);
5125 programObject->getActiveUniform(index, bufsize, length, size, type, name);
5126}
5127
5128void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
5129{
5130 Program *programObject = getProgram(program);
5131 ASSERT(programObject);
5132 programObject->getAttachedShaders(maxcount, count, shaders);
5133}
5134
5135GLint Context::getAttribLocation(GLuint program, const GLchar *name)
5136{
5137 Program *programObject = getProgram(program);
5138 ASSERT(programObject);
5139 return programObject->getAttributeLocation(name);
5140}
5141
5142void Context::getBooleanv(GLenum pname, GLboolean *params)
5143{
5144 GLenum nativeType;
5145 unsigned int numParams = 0;
5146 getQueryParameterInfo(pname, &nativeType, &numParams);
5147
5148 if (nativeType == GL_BOOL)
5149 {
5150 getBooleanvImpl(pname, params);
5151 }
5152 else
5153 {
5154 CastStateValues(this, nativeType, pname, numParams, params);
5155 }
5156}
5157
Brandon Jones59770802018-04-02 13:18:42 -07005158void Context::getBooleanvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLboolean *params)
5159{
5160 getBooleanv(pname, params);
5161}
5162
Jamie Madillc1d770e2017-04-13 17:31:24 -04005163void Context::getFloatv(GLenum pname, GLfloat *params)
5164{
5165 GLenum nativeType;
5166 unsigned int numParams = 0;
5167 getQueryParameterInfo(pname, &nativeType, &numParams);
5168
5169 if (nativeType == GL_FLOAT)
5170 {
5171 getFloatvImpl(pname, params);
5172 }
5173 else
5174 {
5175 CastStateValues(this, nativeType, pname, numParams, params);
5176 }
5177}
5178
Brandon Jones59770802018-04-02 13:18:42 -07005179void Context::getFloatvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLfloat *params)
5180{
5181 getFloatv(pname, params);
5182}
5183
Jamie Madillc1d770e2017-04-13 17:31:24 -04005184void Context::getIntegerv(GLenum pname, GLint *params)
5185{
5186 GLenum nativeType;
5187 unsigned int numParams = 0;
5188 getQueryParameterInfo(pname, &nativeType, &numParams);
5189
5190 if (nativeType == GL_INT)
5191 {
5192 getIntegervImpl(pname, params);
5193 }
5194 else
5195 {
5196 CastStateValues(this, nativeType, pname, numParams, params);
5197 }
5198}
5199
Brandon Jones59770802018-04-02 13:18:42 -07005200void Context::getIntegervRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint *data)
5201{
5202 getIntegerv(pname, data);
5203}
5204
Jamie Madillc1d770e2017-04-13 17:31:24 -04005205void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
5206{
5207 Program *programObject = getProgram(program);
5208 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04005209 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005210}
5211
Brandon Jones59770802018-04-02 13:18:42 -07005212void Context::getProgramivRobust(GLuint program,
5213 GLenum pname,
5214 GLsizei bufSize,
5215 GLsizei *length,
5216 GLint *params)
5217{
5218 getProgramiv(program, pname, params);
5219}
5220
Jiajia Qin5451d532017-11-16 17:16:34 +08005221void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
5222{
5223 UNIMPLEMENTED();
5224}
5225
Jamie Madillbe849e42017-05-02 15:49:00 -04005226void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005227{
5228 Program *programObject = getProgram(program);
5229 ASSERT(programObject);
5230 programObject->getInfoLog(bufsize, length, infolog);
5231}
5232
Jiajia Qin5451d532017-11-16 17:16:34 +08005233void Context::getProgramPipelineInfoLog(GLuint pipeline,
5234 GLsizei bufSize,
5235 GLsizei *length,
5236 GLchar *infoLog)
5237{
5238 UNIMPLEMENTED();
5239}
5240
Jamie Madillc1d770e2017-04-13 17:31:24 -04005241void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
5242{
5243 Shader *shaderObject = getShader(shader);
5244 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04005245 QueryShaderiv(this, shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005246}
5247
Brandon Jones59770802018-04-02 13:18:42 -07005248void Context::getShaderivRobust(GLuint shader,
5249 GLenum pname,
5250 GLsizei bufSize,
5251 GLsizei *length,
5252 GLint *params)
5253{
5254 getShaderiv(shader, pname, params);
5255}
5256
Jamie Madillc1d770e2017-04-13 17:31:24 -04005257void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
5258{
5259 Shader *shaderObject = getShader(shader);
5260 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04005261 shaderObject->getInfoLog(this, bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005262}
5263
5264void Context::getShaderPrecisionFormat(GLenum shadertype,
5265 GLenum precisiontype,
5266 GLint *range,
5267 GLint *precision)
5268{
5269 // TODO(jmadill): Compute shaders.
5270
5271 switch (shadertype)
5272 {
5273 case GL_VERTEX_SHADER:
5274 switch (precisiontype)
5275 {
5276 case GL_LOW_FLOAT:
5277 mCaps.vertexLowpFloat.get(range, precision);
5278 break;
5279 case GL_MEDIUM_FLOAT:
5280 mCaps.vertexMediumpFloat.get(range, precision);
5281 break;
5282 case GL_HIGH_FLOAT:
5283 mCaps.vertexHighpFloat.get(range, precision);
5284 break;
5285
5286 case GL_LOW_INT:
5287 mCaps.vertexLowpInt.get(range, precision);
5288 break;
5289 case GL_MEDIUM_INT:
5290 mCaps.vertexMediumpInt.get(range, precision);
5291 break;
5292 case GL_HIGH_INT:
5293 mCaps.vertexHighpInt.get(range, precision);
5294 break;
5295
5296 default:
5297 UNREACHABLE();
5298 return;
5299 }
5300 break;
5301
5302 case GL_FRAGMENT_SHADER:
5303 switch (precisiontype)
5304 {
5305 case GL_LOW_FLOAT:
5306 mCaps.fragmentLowpFloat.get(range, precision);
5307 break;
5308 case GL_MEDIUM_FLOAT:
5309 mCaps.fragmentMediumpFloat.get(range, precision);
5310 break;
5311 case GL_HIGH_FLOAT:
5312 mCaps.fragmentHighpFloat.get(range, precision);
5313 break;
5314
5315 case GL_LOW_INT:
5316 mCaps.fragmentLowpInt.get(range, precision);
5317 break;
5318 case GL_MEDIUM_INT:
5319 mCaps.fragmentMediumpInt.get(range, precision);
5320 break;
5321 case GL_HIGH_INT:
5322 mCaps.fragmentHighpInt.get(range, precision);
5323 break;
5324
5325 default:
5326 UNREACHABLE();
5327 return;
5328 }
5329 break;
5330
5331 default:
5332 UNREACHABLE();
5333 return;
5334 }
5335}
5336
5337void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
5338{
5339 Shader *shaderObject = getShader(shader);
5340 ASSERT(shaderObject);
5341 shaderObject->getSource(bufsize, length, source);
5342}
5343
5344void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
5345{
5346 Program *programObject = getProgram(program);
5347 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005348 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005349}
5350
Brandon Jones59770802018-04-02 13:18:42 -07005351void Context::getUniformfvRobust(GLuint program,
5352 GLint location,
5353 GLsizei bufSize,
5354 GLsizei *length,
5355 GLfloat *params)
5356{
5357 getUniformfv(program, location, params);
5358}
5359
Jamie Madillc1d770e2017-04-13 17:31:24 -04005360void Context::getUniformiv(GLuint program, GLint location, GLint *params)
5361{
5362 Program *programObject = getProgram(program);
5363 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005364 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005365}
5366
Brandon Jones59770802018-04-02 13:18:42 -07005367void Context::getUniformivRobust(GLuint program,
5368 GLint location,
5369 GLsizei bufSize,
5370 GLsizei *length,
5371 GLint *params)
5372{
5373 getUniformiv(program, location, params);
5374}
5375
Jamie Madillc1d770e2017-04-13 17:31:24 -04005376GLint Context::getUniformLocation(GLuint program, const GLchar *name)
5377{
5378 Program *programObject = getProgram(program);
5379 ASSERT(programObject);
5380 return programObject->getUniformLocation(name);
5381}
5382
5383GLboolean Context::isBuffer(GLuint buffer)
5384{
5385 if (buffer == 0)
5386 {
5387 return GL_FALSE;
5388 }
5389
5390 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
5391}
5392
5393GLboolean Context::isEnabled(GLenum cap)
5394{
5395 return mGLState.getEnableFeature(cap);
5396}
5397
5398GLboolean Context::isFramebuffer(GLuint framebuffer)
5399{
5400 if (framebuffer == 0)
5401 {
5402 return GL_FALSE;
5403 }
5404
5405 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
5406}
5407
5408GLboolean Context::isProgram(GLuint program)
5409{
5410 if (program == 0)
5411 {
5412 return GL_FALSE;
5413 }
5414
5415 return (getProgram(program) ? GL_TRUE : GL_FALSE);
5416}
5417
5418GLboolean Context::isRenderbuffer(GLuint renderbuffer)
5419{
5420 if (renderbuffer == 0)
5421 {
5422 return GL_FALSE;
5423 }
5424
5425 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
5426}
5427
5428GLboolean Context::isShader(GLuint shader)
5429{
5430 if (shader == 0)
5431 {
5432 return GL_FALSE;
5433 }
5434
5435 return (getShader(shader) ? GL_TRUE : GL_FALSE);
5436}
5437
5438GLboolean Context::isTexture(GLuint texture)
5439{
5440 if (texture == 0)
5441 {
5442 return GL_FALSE;
5443 }
5444
5445 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
5446}
5447
5448void Context::linkProgram(GLuint program)
5449{
5450 Program *programObject = getProgram(program);
5451 ASSERT(programObject);
5452 handleError(programObject->link(this));
Martin Radev0abb7a22017-08-28 15:34:45 +03005453 mGLState.onProgramExecutableChange(programObject);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005454}
5455
5456void Context::releaseShaderCompiler()
5457{
Jamie Madill4928b7c2017-06-20 12:57:39 -04005458 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005459}
5460
5461void Context::shaderBinary(GLsizei n,
5462 const GLuint *shaders,
5463 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04005464 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005465 GLsizei length)
5466{
5467 // No binary shader formats are supported.
5468 UNIMPLEMENTED();
5469}
5470
5471void Context::shaderSource(GLuint shader,
5472 GLsizei count,
5473 const GLchar *const *string,
5474 const GLint *length)
5475{
5476 Shader *shaderObject = getShader(shader);
5477 ASSERT(shaderObject);
5478 shaderObject->setSource(count, string, length);
5479}
5480
5481void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
5482{
5483 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
5484}
5485
5486void Context::stencilMask(GLuint mask)
5487{
5488 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
5489}
5490
5491void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
5492{
5493 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
5494}
5495
5496void Context::uniform1f(GLint location, GLfloat x)
5497{
5498 Program *program = mGLState.getProgram();
5499 program->setUniform1fv(location, 1, &x);
5500}
5501
5502void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
5503{
5504 Program *program = mGLState.getProgram();
5505 program->setUniform1fv(location, count, v);
5506}
5507
5508void Context::uniform1i(GLint location, GLint x)
5509{
5510 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04005511 if (program->setUniform1iv(location, 1, &x) == Program::SetUniformResult::SamplerChanged)
5512 {
5513 mGLState.setObjectDirty(GL_PROGRAM);
5514 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005515}
5516
5517void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
5518{
5519 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04005520 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
5521 {
5522 mGLState.setObjectDirty(GL_PROGRAM);
5523 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005524}
5525
5526void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
5527{
5528 GLfloat xy[2] = {x, y};
5529 Program *program = mGLState.getProgram();
5530 program->setUniform2fv(location, 1, xy);
5531}
5532
5533void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
5534{
5535 Program *program = mGLState.getProgram();
5536 program->setUniform2fv(location, count, v);
5537}
5538
5539void Context::uniform2i(GLint location, GLint x, GLint y)
5540{
5541 GLint xy[2] = {x, y};
5542 Program *program = mGLState.getProgram();
5543 program->setUniform2iv(location, 1, xy);
5544}
5545
5546void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
5547{
5548 Program *program = mGLState.getProgram();
5549 program->setUniform2iv(location, count, v);
5550}
5551
5552void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
5553{
5554 GLfloat xyz[3] = {x, y, z};
5555 Program *program = mGLState.getProgram();
5556 program->setUniform3fv(location, 1, xyz);
5557}
5558
5559void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
5560{
5561 Program *program = mGLState.getProgram();
5562 program->setUniform3fv(location, count, v);
5563}
5564
5565void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
5566{
5567 GLint xyz[3] = {x, y, z};
5568 Program *program = mGLState.getProgram();
5569 program->setUniform3iv(location, 1, xyz);
5570}
5571
5572void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
5573{
5574 Program *program = mGLState.getProgram();
5575 program->setUniform3iv(location, count, v);
5576}
5577
5578void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
5579{
5580 GLfloat xyzw[4] = {x, y, z, w};
5581 Program *program = mGLState.getProgram();
5582 program->setUniform4fv(location, 1, xyzw);
5583}
5584
5585void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
5586{
5587 Program *program = mGLState.getProgram();
5588 program->setUniform4fv(location, count, v);
5589}
5590
5591void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
5592{
5593 GLint xyzw[4] = {x, y, z, w};
5594 Program *program = mGLState.getProgram();
5595 program->setUniform4iv(location, 1, xyzw);
5596}
5597
5598void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
5599{
5600 Program *program = mGLState.getProgram();
5601 program->setUniform4iv(location, count, v);
5602}
5603
5604void Context::uniformMatrix2fv(GLint location,
5605 GLsizei count,
5606 GLboolean transpose,
5607 const GLfloat *value)
5608{
5609 Program *program = mGLState.getProgram();
5610 program->setUniformMatrix2fv(location, count, transpose, value);
5611}
5612
5613void Context::uniformMatrix3fv(GLint location,
5614 GLsizei count,
5615 GLboolean transpose,
5616 const GLfloat *value)
5617{
5618 Program *program = mGLState.getProgram();
5619 program->setUniformMatrix3fv(location, count, transpose, value);
5620}
5621
5622void Context::uniformMatrix4fv(GLint location,
5623 GLsizei count,
5624 GLboolean transpose,
5625 const GLfloat *value)
5626{
5627 Program *program = mGLState.getProgram();
5628 program->setUniformMatrix4fv(location, count, transpose, value);
5629}
5630
5631void Context::validateProgram(GLuint program)
5632{
5633 Program *programObject = getProgram(program);
5634 ASSERT(programObject);
5635 programObject->validate(mCaps);
5636}
5637
Jiajia Qin5451d532017-11-16 17:16:34 +08005638void Context::validateProgramPipeline(GLuint pipeline)
5639{
5640 UNIMPLEMENTED();
5641}
5642
Jamie Madilld04908b2017-06-09 14:15:35 -04005643void Context::getProgramBinary(GLuint program,
5644 GLsizei bufSize,
5645 GLsizei *length,
5646 GLenum *binaryFormat,
5647 void *binary)
5648{
5649 Program *programObject = getProgram(program);
5650 ASSERT(programObject != nullptr);
5651
5652 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
5653}
5654
5655void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
5656{
5657 Program *programObject = getProgram(program);
5658 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04005659
Jamie Madilld04908b2017-06-09 14:15:35 -04005660 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
5661}
5662
Jamie Madillff325f12017-08-26 15:06:05 -04005663void Context::uniform1ui(GLint location, GLuint v0)
5664{
5665 Program *program = mGLState.getProgram();
5666 program->setUniform1uiv(location, 1, &v0);
5667}
5668
5669void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
5670{
5671 Program *program = mGLState.getProgram();
5672 const GLuint xy[] = {v0, v1};
5673 program->setUniform2uiv(location, 1, xy);
5674}
5675
5676void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
5677{
5678 Program *program = mGLState.getProgram();
5679 const GLuint xyz[] = {v0, v1, v2};
5680 program->setUniform3uiv(location, 1, xyz);
5681}
5682
5683void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
5684{
5685 Program *program = mGLState.getProgram();
5686 const GLuint xyzw[] = {v0, v1, v2, v3};
5687 program->setUniform4uiv(location, 1, xyzw);
5688}
5689
5690void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
5691{
5692 Program *program = mGLState.getProgram();
5693 program->setUniform1uiv(location, count, value);
5694}
5695void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
5696{
5697 Program *program = mGLState.getProgram();
5698 program->setUniform2uiv(location, count, value);
5699}
5700
5701void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
5702{
5703 Program *program = mGLState.getProgram();
5704 program->setUniform3uiv(location, count, value);
5705}
5706
5707void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
5708{
5709 Program *program = mGLState.getProgram();
5710 program->setUniform4uiv(location, count, value);
5711}
5712
Jamie Madillf0e04492017-08-26 15:28:42 -04005713void Context::genQueries(GLsizei n, GLuint *ids)
5714{
5715 for (GLsizei i = 0; i < n; i++)
5716 {
5717 GLuint handle = mQueryHandleAllocator.allocate();
5718 mQueryMap.assign(handle, nullptr);
5719 ids[i] = handle;
5720 }
5721}
5722
5723void Context::deleteQueries(GLsizei n, const GLuint *ids)
5724{
5725 for (int i = 0; i < n; i++)
5726 {
5727 GLuint query = ids[i];
5728
5729 Query *queryObject = nullptr;
5730 if (mQueryMap.erase(query, &queryObject))
5731 {
5732 mQueryHandleAllocator.release(query);
5733 if (queryObject)
5734 {
5735 queryObject->release(this);
5736 }
5737 }
5738 }
5739}
5740
5741GLboolean Context::isQuery(GLuint id)
5742{
Corentin Wallezad3ae902018-03-09 13:40:42 -05005743 return (getQuery(id, false, QueryType::InvalidEnum) != nullptr) ? GL_TRUE : GL_FALSE;
Jamie Madillf0e04492017-08-26 15:28:42 -04005744}
5745
Jamie Madillc8c95812017-08-26 18:40:09 -04005746void Context::uniformMatrix2x3fv(GLint location,
5747 GLsizei count,
5748 GLboolean transpose,
5749 const GLfloat *value)
5750{
5751 Program *program = mGLState.getProgram();
5752 program->setUniformMatrix2x3fv(location, count, transpose, value);
5753}
5754
5755void Context::uniformMatrix3x2fv(GLint location,
5756 GLsizei count,
5757 GLboolean transpose,
5758 const GLfloat *value)
5759{
5760 Program *program = mGLState.getProgram();
5761 program->setUniformMatrix3x2fv(location, count, transpose, value);
5762}
5763
5764void Context::uniformMatrix2x4fv(GLint location,
5765 GLsizei count,
5766 GLboolean transpose,
5767 const GLfloat *value)
5768{
5769 Program *program = mGLState.getProgram();
5770 program->setUniformMatrix2x4fv(location, count, transpose, value);
5771}
5772
5773void Context::uniformMatrix4x2fv(GLint location,
5774 GLsizei count,
5775 GLboolean transpose,
5776 const GLfloat *value)
5777{
5778 Program *program = mGLState.getProgram();
5779 program->setUniformMatrix4x2fv(location, count, transpose, value);
5780}
5781
5782void Context::uniformMatrix3x4fv(GLint location,
5783 GLsizei count,
5784 GLboolean transpose,
5785 const GLfloat *value)
5786{
5787 Program *program = mGLState.getProgram();
5788 program->setUniformMatrix3x4fv(location, count, transpose, value);
5789}
5790
5791void Context::uniformMatrix4x3fv(GLint location,
5792 GLsizei count,
5793 GLboolean transpose,
5794 const GLfloat *value)
5795{
5796 Program *program = mGLState.getProgram();
5797 program->setUniformMatrix4x3fv(location, count, transpose, value);
5798}
5799
Jamie Madilld7576732017-08-26 18:49:50 -04005800void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
5801{
5802 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5803 {
5804 GLuint vertexArray = arrays[arrayIndex];
5805
5806 if (arrays[arrayIndex] != 0)
5807 {
5808 VertexArray *vertexArrayObject = nullptr;
5809 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
5810 {
5811 if (vertexArrayObject != nullptr)
5812 {
5813 detachVertexArray(vertexArray);
5814 vertexArrayObject->onDestroy(this);
5815 }
5816
5817 mVertexArrayHandleAllocator.release(vertexArray);
5818 }
5819 }
5820 }
5821}
5822
5823void Context::genVertexArrays(GLsizei n, GLuint *arrays)
5824{
5825 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5826 {
5827 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
5828 mVertexArrayMap.assign(vertexArray, nullptr);
5829 arrays[arrayIndex] = vertexArray;
5830 }
5831}
5832
5833bool Context::isVertexArray(GLuint array)
5834{
5835 if (array == 0)
5836 {
5837 return GL_FALSE;
5838 }
5839
5840 VertexArray *vao = getVertexArray(array);
5841 return (vao != nullptr ? GL_TRUE : GL_FALSE);
5842}
5843
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04005844void Context::endTransformFeedback()
5845{
5846 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5847 transformFeedback->end(this);
5848}
5849
5850void Context::transformFeedbackVaryings(GLuint program,
5851 GLsizei count,
5852 const GLchar *const *varyings,
5853 GLenum bufferMode)
5854{
5855 Program *programObject = getProgram(program);
5856 ASSERT(programObject);
5857 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
5858}
5859
5860void Context::getTransformFeedbackVarying(GLuint program,
5861 GLuint index,
5862 GLsizei bufSize,
5863 GLsizei *length,
5864 GLsizei *size,
5865 GLenum *type,
5866 GLchar *name)
5867{
5868 Program *programObject = getProgram(program);
5869 ASSERT(programObject);
5870 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
5871}
5872
5873void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
5874{
5875 for (int i = 0; i < n; i++)
5876 {
5877 GLuint transformFeedback = ids[i];
5878 if (transformFeedback == 0)
5879 {
5880 continue;
5881 }
5882
5883 TransformFeedback *transformFeedbackObject = nullptr;
5884 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
5885 {
5886 if (transformFeedbackObject != nullptr)
5887 {
5888 detachTransformFeedback(transformFeedback);
5889 transformFeedbackObject->release(this);
5890 }
5891
5892 mTransformFeedbackHandleAllocator.release(transformFeedback);
5893 }
5894 }
5895}
5896
5897void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
5898{
5899 for (int i = 0; i < n; i++)
5900 {
5901 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
5902 mTransformFeedbackMap.assign(transformFeedback, nullptr);
5903 ids[i] = transformFeedback;
5904 }
5905}
5906
5907bool Context::isTransformFeedback(GLuint id)
5908{
5909 if (id == 0)
5910 {
5911 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
5912 // returns FALSE
5913 return GL_FALSE;
5914 }
5915
5916 const TransformFeedback *transformFeedback = getTransformFeedback(id);
5917 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
5918}
5919
5920void Context::pauseTransformFeedback()
5921{
5922 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5923 transformFeedback->pause();
5924}
5925
5926void Context::resumeTransformFeedback()
5927{
5928 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5929 transformFeedback->resume();
5930}
5931
Jamie Madill12e957f2017-08-26 21:42:26 -04005932void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
5933{
5934 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04005935 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04005936}
5937
Brandon Jones59770802018-04-02 13:18:42 -07005938void Context::getUniformuivRobust(GLuint program,
5939 GLint location,
5940 GLsizei bufSize,
5941 GLsizei *length,
5942 GLuint *params)
5943{
5944 getUniformuiv(program, location, params);
5945}
5946
Jamie Madill12e957f2017-08-26 21:42:26 -04005947GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
5948{
5949 const Program *programObject = getProgram(program);
5950 return programObject->getFragDataLocation(name);
5951}
5952
5953void Context::getUniformIndices(GLuint program,
5954 GLsizei uniformCount,
5955 const GLchar *const *uniformNames,
5956 GLuint *uniformIndices)
5957{
5958 const Program *programObject = getProgram(program);
5959 if (!programObject->isLinked())
5960 {
5961 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5962 {
5963 uniformIndices[uniformId] = GL_INVALID_INDEX;
5964 }
5965 }
5966 else
5967 {
5968 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5969 {
5970 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
5971 }
5972 }
5973}
5974
5975void Context::getActiveUniformsiv(GLuint program,
5976 GLsizei uniformCount,
5977 const GLuint *uniformIndices,
5978 GLenum pname,
5979 GLint *params)
5980{
5981 const Program *programObject = getProgram(program);
5982 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5983 {
5984 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08005985 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04005986 }
5987}
5988
5989GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
5990{
5991 const Program *programObject = getProgram(program);
5992 return programObject->getUniformBlockIndex(uniformBlockName);
5993}
5994
5995void Context::getActiveUniformBlockiv(GLuint program,
5996 GLuint uniformBlockIndex,
5997 GLenum pname,
5998 GLint *params)
5999{
6000 const Program *programObject = getProgram(program);
6001 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
6002}
6003
Brandon Jones59770802018-04-02 13:18:42 -07006004void Context::getActiveUniformBlockivRobust(GLuint program,
6005 GLuint uniformBlockIndex,
6006 GLenum pname,
6007 GLsizei bufSize,
6008 GLsizei *length,
6009 GLint *params)
6010{
6011 getActiveUniformBlockiv(program, uniformBlockIndex, pname, params);
6012}
6013
Jamie Madill12e957f2017-08-26 21:42:26 -04006014void Context::getActiveUniformBlockName(GLuint program,
6015 GLuint uniformBlockIndex,
6016 GLsizei bufSize,
6017 GLsizei *length,
6018 GLchar *uniformBlockName)
6019{
6020 const Program *programObject = getProgram(program);
6021 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
6022}
6023
6024void Context::uniformBlockBinding(GLuint program,
6025 GLuint uniformBlockIndex,
6026 GLuint uniformBlockBinding)
6027{
6028 Program *programObject = getProgram(program);
6029 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
6030}
6031
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006032GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
6033{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006034 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
6035 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006036
Jamie Madill70b5bb02017-08-28 13:32:37 -04006037 Sync *syncObject = getSync(syncHandle);
6038 Error error = syncObject->set(condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006039 if (error.isError())
6040 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04006041 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006042 handleError(error);
6043 return nullptr;
6044 }
6045
Jamie Madill70b5bb02017-08-28 13:32:37 -04006046 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006047}
6048
6049GLboolean Context::isSync(GLsync sync)
6050{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006051 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006052}
6053
6054GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6055{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006056 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006057
6058 GLenum result = GL_WAIT_FAILED;
6059 handleError(syncObject->clientWait(flags, timeout, &result));
6060 return result;
6061}
6062
6063void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6064{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006065 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006066 handleError(syncObject->serverWait(flags, timeout));
6067}
6068
6069void Context::getInteger64v(GLenum pname, GLint64 *params)
6070{
6071 GLenum nativeType = GL_NONE;
6072 unsigned int numParams = 0;
6073 getQueryParameterInfo(pname, &nativeType, &numParams);
6074
6075 if (nativeType == GL_INT_64_ANGLEX)
6076 {
6077 getInteger64vImpl(pname, params);
6078 }
6079 else
6080 {
6081 CastStateValues(this, nativeType, pname, numParams, params);
6082 }
6083}
6084
Brandon Jones59770802018-04-02 13:18:42 -07006085void Context::getInteger64vRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint64 *data)
6086{
6087 getInteger64v(pname, data);
6088}
6089
Corentin Wallez336129f2017-10-17 15:55:40 -04006090void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04006091{
6092 Buffer *buffer = mGLState.getTargetBuffer(target);
6093 QueryBufferParameteri64v(buffer, pname, params);
6094}
6095
Brandon Jones59770802018-04-02 13:18:42 -07006096void Context::getBufferParameteri64vRobust(BufferBinding target,
6097 GLenum pname,
6098 GLsizei bufSize,
6099 GLsizei *length,
6100 GLint64 *params)
6101{
6102 getBufferParameteri64v(target, pname, params);
6103}
6104
Jamie Madill3ef140a2017-08-26 23:11:21 -04006105void Context::genSamplers(GLsizei count, GLuint *samplers)
6106{
6107 for (int i = 0; i < count; i++)
6108 {
6109 samplers[i] = mState.mSamplers->createSampler();
6110 }
6111}
6112
6113void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
6114{
6115 for (int i = 0; i < count; i++)
6116 {
6117 GLuint sampler = samplers[i];
6118
6119 if (mState.mSamplers->getSampler(sampler))
6120 {
6121 detachSampler(sampler);
6122 }
6123
6124 mState.mSamplers->deleteObject(this, sampler);
6125 }
6126}
6127
6128void Context::getInternalformativ(GLenum target,
6129 GLenum internalformat,
6130 GLenum pname,
6131 GLsizei bufSize,
6132 GLint *params)
6133{
6134 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
6135 QueryInternalFormativ(formatCaps, pname, bufSize, params);
6136}
6137
Brandon Jones59770802018-04-02 13:18:42 -07006138void Context::getInternalformativRobust(GLenum target,
6139 GLenum internalformat,
6140 GLenum pname,
6141 GLsizei bufSize,
6142 GLsizei *length,
6143 GLint *params)
6144{
6145 getInternalformativ(target, internalformat, pname, bufSize, params);
6146}
6147
Jiajia Qin5451d532017-11-16 17:16:34 +08006148void Context::programUniform1i(GLuint program, GLint location, GLint v0)
6149{
6150 programUniform1iv(program, location, 1, &v0);
6151}
6152
6153void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
6154{
6155 GLint xy[2] = {v0, v1};
6156 programUniform2iv(program, location, 1, xy);
6157}
6158
6159void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
6160{
6161 GLint xyz[3] = {v0, v1, v2};
6162 programUniform3iv(program, location, 1, xyz);
6163}
6164
6165void Context::programUniform4i(GLuint program,
6166 GLint location,
6167 GLint v0,
6168 GLint v1,
6169 GLint v2,
6170 GLint v3)
6171{
6172 GLint xyzw[4] = {v0, v1, v2, v3};
6173 programUniform4iv(program, location, 1, xyzw);
6174}
6175
6176void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
6177{
6178 programUniform1uiv(program, location, 1, &v0);
6179}
6180
6181void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
6182{
6183 GLuint xy[2] = {v0, v1};
6184 programUniform2uiv(program, location, 1, xy);
6185}
6186
6187void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
6188{
6189 GLuint xyz[3] = {v0, v1, v2};
6190 programUniform3uiv(program, location, 1, xyz);
6191}
6192
6193void Context::programUniform4ui(GLuint program,
6194 GLint location,
6195 GLuint v0,
6196 GLuint v1,
6197 GLuint v2,
6198 GLuint v3)
6199{
6200 GLuint xyzw[4] = {v0, v1, v2, v3};
6201 programUniform4uiv(program, location, 1, xyzw);
6202}
6203
6204void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
6205{
6206 programUniform1fv(program, location, 1, &v0);
6207}
6208
6209void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
6210{
6211 GLfloat xy[2] = {v0, v1};
6212 programUniform2fv(program, location, 1, xy);
6213}
6214
6215void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
6216{
6217 GLfloat xyz[3] = {v0, v1, v2};
6218 programUniform3fv(program, location, 1, xyz);
6219}
6220
6221void Context::programUniform4f(GLuint program,
6222 GLint location,
6223 GLfloat v0,
6224 GLfloat v1,
6225 GLfloat v2,
6226 GLfloat v3)
6227{
6228 GLfloat xyzw[4] = {v0, v1, v2, v3};
6229 programUniform4fv(program, location, 1, xyzw);
6230}
6231
Jamie Madill81c2e252017-09-09 23:32:46 -04006232void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6233{
6234 Program *programObject = getProgram(program);
6235 ASSERT(programObject);
6236 if (programObject->setUniform1iv(location, count, value) ==
6237 Program::SetUniformResult::SamplerChanged)
6238 {
6239 mGLState.setObjectDirty(GL_PROGRAM);
6240 }
6241}
6242
Jiajia Qin5451d532017-11-16 17:16:34 +08006243void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6244{
6245 Program *programObject = getProgram(program);
6246 ASSERT(programObject);
6247 programObject->setUniform2iv(location, count, value);
6248}
6249
6250void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6251{
6252 Program *programObject = getProgram(program);
6253 ASSERT(programObject);
6254 programObject->setUniform3iv(location, count, value);
6255}
6256
6257void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6258{
6259 Program *programObject = getProgram(program);
6260 ASSERT(programObject);
6261 programObject->setUniform4iv(location, count, value);
6262}
6263
6264void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6265{
6266 Program *programObject = getProgram(program);
6267 ASSERT(programObject);
6268 programObject->setUniform1uiv(location, count, value);
6269}
6270
6271void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6272{
6273 Program *programObject = getProgram(program);
6274 ASSERT(programObject);
6275 programObject->setUniform2uiv(location, count, value);
6276}
6277
6278void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6279{
6280 Program *programObject = getProgram(program);
6281 ASSERT(programObject);
6282 programObject->setUniform3uiv(location, count, value);
6283}
6284
6285void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6286{
6287 Program *programObject = getProgram(program);
6288 ASSERT(programObject);
6289 programObject->setUniform4uiv(location, count, value);
6290}
6291
6292void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6293{
6294 Program *programObject = getProgram(program);
6295 ASSERT(programObject);
6296 programObject->setUniform1fv(location, count, value);
6297}
6298
6299void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6300{
6301 Program *programObject = getProgram(program);
6302 ASSERT(programObject);
6303 programObject->setUniform2fv(location, count, value);
6304}
6305
6306void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6307{
6308 Program *programObject = getProgram(program);
6309 ASSERT(programObject);
6310 programObject->setUniform3fv(location, count, value);
6311}
6312
6313void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6314{
6315 Program *programObject = getProgram(program);
6316 ASSERT(programObject);
6317 programObject->setUniform4fv(location, count, value);
6318}
6319
6320void Context::programUniformMatrix2fv(GLuint program,
6321 GLint location,
6322 GLsizei count,
6323 GLboolean transpose,
6324 const GLfloat *value)
6325{
6326 Program *programObject = getProgram(program);
6327 ASSERT(programObject);
6328 programObject->setUniformMatrix2fv(location, count, transpose, value);
6329}
6330
6331void Context::programUniformMatrix3fv(GLuint program,
6332 GLint location,
6333 GLsizei count,
6334 GLboolean transpose,
6335 const GLfloat *value)
6336{
6337 Program *programObject = getProgram(program);
6338 ASSERT(programObject);
6339 programObject->setUniformMatrix3fv(location, count, transpose, value);
6340}
6341
6342void Context::programUniformMatrix4fv(GLuint program,
6343 GLint location,
6344 GLsizei count,
6345 GLboolean transpose,
6346 const GLfloat *value)
6347{
6348 Program *programObject = getProgram(program);
6349 ASSERT(programObject);
6350 programObject->setUniformMatrix4fv(location, count, transpose, value);
6351}
6352
6353void Context::programUniformMatrix2x3fv(GLuint program,
6354 GLint location,
6355 GLsizei count,
6356 GLboolean transpose,
6357 const GLfloat *value)
6358{
6359 Program *programObject = getProgram(program);
6360 ASSERT(programObject);
6361 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
6362}
6363
6364void Context::programUniformMatrix3x2fv(GLuint program,
6365 GLint location,
6366 GLsizei count,
6367 GLboolean transpose,
6368 const GLfloat *value)
6369{
6370 Program *programObject = getProgram(program);
6371 ASSERT(programObject);
6372 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
6373}
6374
6375void Context::programUniformMatrix2x4fv(GLuint program,
6376 GLint location,
6377 GLsizei count,
6378 GLboolean transpose,
6379 const GLfloat *value)
6380{
6381 Program *programObject = getProgram(program);
6382 ASSERT(programObject);
6383 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
6384}
6385
6386void Context::programUniformMatrix4x2fv(GLuint program,
6387 GLint location,
6388 GLsizei count,
6389 GLboolean transpose,
6390 const GLfloat *value)
6391{
6392 Program *programObject = getProgram(program);
6393 ASSERT(programObject);
6394 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
6395}
6396
6397void Context::programUniformMatrix3x4fv(GLuint program,
6398 GLint location,
6399 GLsizei count,
6400 GLboolean transpose,
6401 const GLfloat *value)
6402{
6403 Program *programObject = getProgram(program);
6404 ASSERT(programObject);
6405 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
6406}
6407
6408void Context::programUniformMatrix4x3fv(GLuint program,
6409 GLint location,
6410 GLsizei count,
6411 GLboolean transpose,
6412 const GLfloat *value)
6413{
6414 Program *programObject = getProgram(program);
6415 ASSERT(programObject);
6416 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
6417}
6418
Jamie Madill81c2e252017-09-09 23:32:46 -04006419void Context::onTextureChange(const Texture *texture)
6420{
6421 // Conservatively assume all textures are dirty.
6422 // TODO(jmadill): More fine-grained update.
6423 mGLState.setObjectDirty(GL_TEXTURE);
6424}
6425
James Darpiniane8a93c62018-01-04 18:02:24 -08006426bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
6427{
6428 return mGLState.isCurrentTransformFeedback(tf);
6429}
6430bool Context::isCurrentVertexArray(const VertexArray *va) const
6431{
6432 return mGLState.isCurrentVertexArray(va);
6433}
6434
Yunchao Hea336b902017-08-02 16:05:21 +08006435void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
6436{
6437 for (int i = 0; i < count; i++)
6438 {
6439 pipelines[i] = createProgramPipeline();
6440 }
6441}
6442
6443void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
6444{
6445 for (int i = 0; i < count; i++)
6446 {
6447 if (pipelines[i] != 0)
6448 {
6449 deleteProgramPipeline(pipelines[i]);
6450 }
6451 }
6452}
6453
6454GLboolean Context::isProgramPipeline(GLuint pipeline)
6455{
6456 if (pipeline == 0)
6457 {
6458 return GL_FALSE;
6459 }
6460
6461 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
6462}
6463
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006464void Context::finishFenceNV(GLuint fence)
6465{
6466 FenceNV *fenceObject = getFenceNV(fence);
6467
6468 ASSERT(fenceObject && fenceObject->isSet());
6469 handleError(fenceObject->finish());
6470}
6471
6472void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
6473{
6474 FenceNV *fenceObject = getFenceNV(fence);
6475
6476 ASSERT(fenceObject && fenceObject->isSet());
6477
6478 switch (pname)
6479 {
6480 case GL_FENCE_STATUS_NV:
6481 {
6482 // GL_NV_fence spec:
6483 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
6484 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
6485 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
6486 GLboolean status = GL_TRUE;
6487 if (fenceObject->getStatus() != GL_TRUE)
6488 {
6489 ANGLE_CONTEXT_TRY(fenceObject->test(&status));
6490 }
6491 *params = status;
6492 break;
6493 }
6494
6495 case GL_FENCE_CONDITION_NV:
6496 {
6497 *params = static_cast<GLint>(fenceObject->getCondition());
6498 break;
6499 }
6500
6501 default:
6502 UNREACHABLE();
6503 }
6504}
6505
6506void Context::getTranslatedShaderSource(GLuint shader,
6507 GLsizei bufsize,
6508 GLsizei *length,
6509 GLchar *source)
6510{
6511 Shader *shaderObject = getShader(shader);
6512 ASSERT(shaderObject);
6513 shaderObject->getTranslatedSourceWithDebugInfo(this, bufsize, length, source);
6514}
6515
6516void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
6517{
6518 Program *programObject = getProgram(program);
6519 ASSERT(programObject);
6520
6521 programObject->getUniformfv(this, location, params);
6522}
6523
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006524void Context::getnUniformfvRobust(GLuint program,
6525 GLint location,
6526 GLsizei bufSize,
6527 GLsizei *length,
6528 GLfloat *params)
6529{
6530 UNIMPLEMENTED();
6531}
6532
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006533void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
6534{
6535 Program *programObject = getProgram(program);
6536 ASSERT(programObject);
6537
6538 programObject->getUniformiv(this, location, params);
6539}
6540
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006541void Context::getnUniformivRobust(GLuint program,
6542 GLint location,
6543 GLsizei bufSize,
6544 GLsizei *length,
6545 GLint *params)
6546{
6547 UNIMPLEMENTED();
6548}
6549
6550void Context::getnUniformuivRobust(GLuint program,
6551 GLint location,
6552 GLsizei bufSize,
6553 GLsizei *length,
6554 GLuint *params)
6555{
6556 UNIMPLEMENTED();
6557}
6558
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006559GLboolean Context::isFenceNV(GLuint fence)
6560{
6561 FenceNV *fenceObject = getFenceNV(fence);
6562
6563 if (fenceObject == nullptr)
6564 {
6565 return GL_FALSE;
6566 }
6567
6568 // GL_NV_fence spec:
6569 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
6570 // existing fence.
6571 return fenceObject->isSet();
6572}
6573
6574void Context::readnPixels(GLint x,
6575 GLint y,
6576 GLsizei width,
6577 GLsizei height,
6578 GLenum format,
6579 GLenum type,
6580 GLsizei bufSize,
6581 void *data)
6582{
6583 return readPixels(x, y, width, height, format, type, data);
6584}
6585
Jamie Madill007530e2017-12-28 14:27:04 -05006586void Context::setFenceNV(GLuint fence, GLenum condition)
6587{
6588 ASSERT(condition == GL_ALL_COMPLETED_NV);
6589
6590 FenceNV *fenceObject = getFenceNV(fence);
6591 ASSERT(fenceObject != nullptr);
6592 handleError(fenceObject->set(condition));
6593}
6594
6595GLboolean Context::testFenceNV(GLuint fence)
6596{
6597 FenceNV *fenceObject = getFenceNV(fence);
6598
6599 ASSERT(fenceObject != nullptr);
6600 ASSERT(fenceObject->isSet() == GL_TRUE);
6601
6602 GLboolean result = GL_TRUE;
6603 Error error = fenceObject->test(&result);
6604 if (error.isError())
6605 {
6606 handleError(error);
6607 return GL_TRUE;
6608 }
6609
6610 return result;
6611}
6612
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006613void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006614{
6615 Texture *texture = getTargetTexture(target);
6616 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
Corentin Wallez99d492c2018-02-27 15:17:10 -05006617 handleError(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05006618}
6619
Jamie Madillfa920eb2018-01-04 11:45:50 -05006620void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006621{
6622 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
6623 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
6624 handleError(renderbuffer->setStorageEGLImageTarget(this, imageObject));
6625}
6626
Jamie Madillfa920eb2018-01-04 11:45:50 -05006627void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
6628{
6629 UNIMPLEMENTED();
6630}
6631
Jamie Madill5b772312018-03-08 20:28:32 -05006632bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
6633{
6634 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
6635 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
6636 // to the fact that it is stored internally as a float, and so would require conversion
6637 // if returned from Context::getIntegerv. Since this conversion is already implemented
6638 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
6639 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
6640 // application.
6641 switch (pname)
6642 {
6643 case GL_COMPRESSED_TEXTURE_FORMATS:
6644 {
6645 *type = GL_INT;
6646 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
6647 return true;
6648 }
6649 case GL_SHADER_BINARY_FORMATS:
6650 {
6651 *type = GL_INT;
6652 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
6653 return true;
6654 }
6655
6656 case GL_MAX_VERTEX_ATTRIBS:
6657 case GL_MAX_VERTEX_UNIFORM_VECTORS:
6658 case GL_MAX_VARYING_VECTORS:
6659 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
6660 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
6661 case GL_MAX_TEXTURE_IMAGE_UNITS:
6662 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
6663 case GL_MAX_RENDERBUFFER_SIZE:
6664 case GL_NUM_SHADER_BINARY_FORMATS:
6665 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
6666 case GL_ARRAY_BUFFER_BINDING:
6667 case GL_FRAMEBUFFER_BINDING:
6668 case GL_RENDERBUFFER_BINDING:
6669 case GL_CURRENT_PROGRAM:
6670 case GL_PACK_ALIGNMENT:
6671 case GL_UNPACK_ALIGNMENT:
6672 case GL_GENERATE_MIPMAP_HINT:
6673 case GL_RED_BITS:
6674 case GL_GREEN_BITS:
6675 case GL_BLUE_BITS:
6676 case GL_ALPHA_BITS:
6677 case GL_DEPTH_BITS:
6678 case GL_STENCIL_BITS:
6679 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
6680 case GL_CULL_FACE_MODE:
6681 case GL_FRONT_FACE:
6682 case GL_ACTIVE_TEXTURE:
6683 case GL_STENCIL_FUNC:
6684 case GL_STENCIL_VALUE_MASK:
6685 case GL_STENCIL_REF:
6686 case GL_STENCIL_FAIL:
6687 case GL_STENCIL_PASS_DEPTH_FAIL:
6688 case GL_STENCIL_PASS_DEPTH_PASS:
6689 case GL_STENCIL_BACK_FUNC:
6690 case GL_STENCIL_BACK_VALUE_MASK:
6691 case GL_STENCIL_BACK_REF:
6692 case GL_STENCIL_BACK_FAIL:
6693 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
6694 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
6695 case GL_DEPTH_FUNC:
6696 case GL_BLEND_SRC_RGB:
6697 case GL_BLEND_SRC_ALPHA:
6698 case GL_BLEND_DST_RGB:
6699 case GL_BLEND_DST_ALPHA:
6700 case GL_BLEND_EQUATION_RGB:
6701 case GL_BLEND_EQUATION_ALPHA:
6702 case GL_STENCIL_WRITEMASK:
6703 case GL_STENCIL_BACK_WRITEMASK:
6704 case GL_STENCIL_CLEAR_VALUE:
6705 case GL_SUBPIXEL_BITS:
6706 case GL_MAX_TEXTURE_SIZE:
6707 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
6708 case GL_SAMPLE_BUFFERS:
6709 case GL_SAMPLES:
6710 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
6711 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
6712 case GL_TEXTURE_BINDING_2D:
6713 case GL_TEXTURE_BINDING_CUBE_MAP:
6714 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
6715 {
6716 *type = GL_INT;
6717 *numParams = 1;
6718 return true;
6719 }
6720 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6721 {
6722 if (!getExtensions().packReverseRowOrder)
6723 {
6724 return false;
6725 }
6726 *type = GL_INT;
6727 *numParams = 1;
6728 return true;
6729 }
6730 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
6731 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
6732 {
6733 if (!getExtensions().textureRectangle)
6734 {
6735 return false;
6736 }
6737 *type = GL_INT;
6738 *numParams = 1;
6739 return true;
6740 }
6741 case GL_MAX_DRAW_BUFFERS_EXT:
6742 case GL_MAX_COLOR_ATTACHMENTS_EXT:
6743 {
6744 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
6745 {
6746 return false;
6747 }
6748 *type = GL_INT;
6749 *numParams = 1;
6750 return true;
6751 }
6752 case GL_MAX_VIEWPORT_DIMS:
6753 {
6754 *type = GL_INT;
6755 *numParams = 2;
6756 return true;
6757 }
6758 case GL_VIEWPORT:
6759 case GL_SCISSOR_BOX:
6760 {
6761 *type = GL_INT;
6762 *numParams = 4;
6763 return true;
6764 }
6765 case GL_SHADER_COMPILER:
6766 case GL_SAMPLE_COVERAGE_INVERT:
6767 case GL_DEPTH_WRITEMASK:
6768 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
6769 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
6770 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
6771 // bool-natural
6772 case GL_SAMPLE_COVERAGE:
6773 case GL_SCISSOR_TEST:
6774 case GL_STENCIL_TEST:
6775 case GL_DEPTH_TEST:
6776 case GL_BLEND:
6777 case GL_DITHER:
6778 case GL_CONTEXT_ROBUST_ACCESS_EXT:
6779 {
6780 *type = GL_BOOL;
6781 *numParams = 1;
6782 return true;
6783 }
6784 case GL_COLOR_WRITEMASK:
6785 {
6786 *type = GL_BOOL;
6787 *numParams = 4;
6788 return true;
6789 }
6790 case GL_POLYGON_OFFSET_FACTOR:
6791 case GL_POLYGON_OFFSET_UNITS:
6792 case GL_SAMPLE_COVERAGE_VALUE:
6793 case GL_DEPTH_CLEAR_VALUE:
6794 case GL_LINE_WIDTH:
6795 {
6796 *type = GL_FLOAT;
6797 *numParams = 1;
6798 return true;
6799 }
6800 case GL_ALIASED_LINE_WIDTH_RANGE:
6801 case GL_ALIASED_POINT_SIZE_RANGE:
6802 case GL_DEPTH_RANGE:
6803 {
6804 *type = GL_FLOAT;
6805 *numParams = 2;
6806 return true;
6807 }
6808 case GL_COLOR_CLEAR_VALUE:
6809 case GL_BLEND_COLOR:
6810 {
6811 *type = GL_FLOAT;
6812 *numParams = 4;
6813 return true;
6814 }
6815 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
6816 if (!getExtensions().textureFilterAnisotropic)
6817 {
6818 return false;
6819 }
6820 *type = GL_FLOAT;
6821 *numParams = 1;
6822 return true;
6823 case GL_TIMESTAMP_EXT:
6824 if (!getExtensions().disjointTimerQuery)
6825 {
6826 return false;
6827 }
6828 *type = GL_INT_64_ANGLEX;
6829 *numParams = 1;
6830 return true;
6831 case GL_GPU_DISJOINT_EXT:
6832 if (!getExtensions().disjointTimerQuery)
6833 {
6834 return false;
6835 }
6836 *type = GL_INT;
6837 *numParams = 1;
6838 return true;
6839 case GL_COVERAGE_MODULATION_CHROMIUM:
6840 if (!getExtensions().framebufferMixedSamples)
6841 {
6842 return false;
6843 }
6844 *type = GL_INT;
6845 *numParams = 1;
6846 return true;
6847 case GL_TEXTURE_BINDING_EXTERNAL_OES:
6848 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
6849 {
6850 return false;
6851 }
6852 *type = GL_INT;
6853 *numParams = 1;
6854 return true;
6855 }
6856
6857 if (getExtensions().debug)
6858 {
6859 switch (pname)
6860 {
6861 case GL_DEBUG_LOGGED_MESSAGES:
6862 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
6863 case GL_DEBUG_GROUP_STACK_DEPTH:
6864 case GL_MAX_DEBUG_MESSAGE_LENGTH:
6865 case GL_MAX_DEBUG_LOGGED_MESSAGES:
6866 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
6867 case GL_MAX_LABEL_LENGTH:
6868 *type = GL_INT;
6869 *numParams = 1;
6870 return true;
6871
6872 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
6873 case GL_DEBUG_OUTPUT:
6874 *type = GL_BOOL;
6875 *numParams = 1;
6876 return true;
6877 }
6878 }
6879
6880 if (getExtensions().multisampleCompatibility)
6881 {
6882 switch (pname)
6883 {
6884 case GL_MULTISAMPLE_EXT:
6885 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
6886 *type = GL_BOOL;
6887 *numParams = 1;
6888 return true;
6889 }
6890 }
6891
6892 if (getExtensions().pathRendering)
6893 {
6894 switch (pname)
6895 {
6896 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
6897 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
6898 *type = GL_FLOAT;
6899 *numParams = 16;
6900 return true;
6901 }
6902 }
6903
6904 if (getExtensions().bindGeneratesResource)
6905 {
6906 switch (pname)
6907 {
6908 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
6909 *type = GL_BOOL;
6910 *numParams = 1;
6911 return true;
6912 }
6913 }
6914
6915 if (getExtensions().clientArrays)
6916 {
6917 switch (pname)
6918 {
6919 case GL_CLIENT_ARRAYS_ANGLE:
6920 *type = GL_BOOL;
6921 *numParams = 1;
6922 return true;
6923 }
6924 }
6925
6926 if (getExtensions().sRGBWriteControl)
6927 {
6928 switch (pname)
6929 {
6930 case GL_FRAMEBUFFER_SRGB_EXT:
6931 *type = GL_BOOL;
6932 *numParams = 1;
6933 return true;
6934 }
6935 }
6936
6937 if (getExtensions().robustResourceInitialization &&
6938 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
6939 {
6940 *type = GL_BOOL;
6941 *numParams = 1;
6942 return true;
6943 }
6944
6945 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
6946 {
6947 *type = GL_BOOL;
6948 *numParams = 1;
6949 return true;
6950 }
6951
6952 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
6953 switch (pname)
6954 {
6955 // case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE // equivalent to FRAMEBUFFER_BINDING
6956 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
6957 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
6958 {
6959 return false;
6960 }
6961 *type = GL_INT;
6962 *numParams = 1;
6963 return true;
6964
6965 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
6966 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
6967 {
6968 return false;
6969 }
6970 *type = GL_INT;
6971 *numParams = 1;
6972 return true;
6973
6974 case GL_PROGRAM_BINARY_FORMATS_OES:
6975 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
6976 {
6977 return false;
6978 }
6979 *type = GL_INT;
6980 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
6981 return true;
6982
6983 case GL_PACK_ROW_LENGTH:
6984 case GL_PACK_SKIP_ROWS:
6985 case GL_PACK_SKIP_PIXELS:
6986 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
6987 {
6988 return false;
6989 }
6990 *type = GL_INT;
6991 *numParams = 1;
6992 return true;
6993 case GL_UNPACK_ROW_LENGTH:
6994 case GL_UNPACK_SKIP_ROWS:
6995 case GL_UNPACK_SKIP_PIXELS:
6996 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
6997 {
6998 return false;
6999 }
7000 *type = GL_INT;
7001 *numParams = 1;
7002 return true;
7003 case GL_VERTEX_ARRAY_BINDING:
7004 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
7005 {
7006 return false;
7007 }
7008 *type = GL_INT;
7009 *numParams = 1;
7010 return true;
7011 case GL_PIXEL_PACK_BUFFER_BINDING:
7012 case GL_PIXEL_UNPACK_BUFFER_BINDING:
7013 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
7014 {
7015 return false;
7016 }
7017 *type = GL_INT;
7018 *numParams = 1;
7019 return true;
7020 case GL_MAX_SAMPLES:
7021 {
7022 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
7023 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
7024 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
7025 {
7026 return false;
7027 }
7028 *type = GL_INT;
7029 *numParams = 1;
7030 return true;
7031
7032 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
7033 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
7034 {
7035 return false;
7036 }
7037 *type = GL_INT;
7038 *numParams = 1;
7039 return true;
7040 }
7041 }
7042
7043 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
7044 {
7045 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
7046 {
7047 return false;
7048 }
7049 *type = GL_INT;
7050 *numParams = 1;
7051 return true;
7052 }
7053
7054 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
7055 {
7056 *type = GL_INT;
7057 *numParams = 1;
7058 return true;
7059 }
7060
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007061 if (getClientVersion() < Version(2, 0))
7062 {
7063 switch (pname)
7064 {
7065 case GL_ALPHA_TEST_FUNC:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007066 case GL_CLIENT_ACTIVE_TEXTURE:
7067 case GL_MATRIX_MODE:
7068 case GL_MAX_TEXTURE_UNITS:
7069 case GL_MAX_MODELVIEW_STACK_DEPTH:
7070 case GL_MAX_PROJECTION_STACK_DEPTH:
7071 case GL_MAX_TEXTURE_STACK_DEPTH:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007072 case GL_MAX_LIGHTS:
Lingfeng Yang060088a2018-05-30 20:40:57 -07007073 case GL_MAX_CLIP_PLANES:
Lingfeng Yangabb09f12018-04-16 10:43:53 -07007074 case GL_VERTEX_ARRAY_STRIDE:
7075 case GL_NORMAL_ARRAY_STRIDE:
7076 case GL_COLOR_ARRAY_STRIDE:
7077 case GL_TEXTURE_COORD_ARRAY_STRIDE:
7078 case GL_VERTEX_ARRAY_SIZE:
7079 case GL_COLOR_ARRAY_SIZE:
7080 case GL_TEXTURE_COORD_ARRAY_SIZE:
7081 case GL_VERTEX_ARRAY_TYPE:
7082 case GL_NORMAL_ARRAY_TYPE:
7083 case GL_COLOR_ARRAY_TYPE:
7084 case GL_TEXTURE_COORD_ARRAY_TYPE:
7085 case GL_VERTEX_ARRAY_BUFFER_BINDING:
7086 case GL_NORMAL_ARRAY_BUFFER_BINDING:
7087 case GL_COLOR_ARRAY_BUFFER_BINDING:
7088 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
7089 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
7090 case GL_POINT_SIZE_ARRAY_TYPE_OES:
7091 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
Lingfeng Yanga0cfa872018-05-30 21:12:17 -07007092 case GL_SHADE_MODEL:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007093 *type = GL_INT;
7094 *numParams = 1;
7095 return true;
7096 case GL_ALPHA_TEST_REF:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007097 case GL_FOG_DENSITY:
7098 case GL_FOG_START:
7099 case GL_FOG_END:
7100 case GL_FOG_MODE:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007101 *type = GL_FLOAT;
7102 *numParams = 1;
7103 return true;
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007104 case GL_CURRENT_COLOR:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007105 case GL_CURRENT_TEXTURE_COORDS:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007106 case GL_LIGHT_MODEL_AMBIENT:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007107 case GL_FOG_COLOR:
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007108 *type = GL_FLOAT;
7109 *numParams = 4;
7110 return true;
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007111 case GL_CURRENT_NORMAL:
7112 *type = GL_FLOAT;
7113 *numParams = 3;
7114 return true;
Lingfeng Yang3a41af62018-04-09 07:28:56 -07007115 case GL_MODELVIEW_MATRIX:
7116 case GL_PROJECTION_MATRIX:
7117 case GL_TEXTURE_MATRIX:
7118 *type = GL_FLOAT;
7119 *numParams = 16;
7120 return true;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007121 case GL_LIGHT_MODEL_TWO_SIDE:
7122 *type = GL_BOOL;
7123 *numParams = 1;
7124 return true;
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007125 }
7126 }
7127
Jamie Madill5b772312018-03-08 20:28:32 -05007128 if (getClientVersion() < Version(3, 0))
7129 {
7130 return false;
7131 }
7132
7133 // Check for ES3.0+ parameter names
7134 switch (pname)
7135 {
7136 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
7137 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
7138 case GL_UNIFORM_BUFFER_BINDING:
7139 case GL_TRANSFORM_FEEDBACK_BINDING:
7140 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7141 case GL_COPY_READ_BUFFER_BINDING:
7142 case GL_COPY_WRITE_BUFFER_BINDING:
7143 case GL_SAMPLER_BINDING:
7144 case GL_READ_BUFFER:
7145 case GL_TEXTURE_BINDING_3D:
7146 case GL_TEXTURE_BINDING_2D_ARRAY:
7147 case GL_MAX_3D_TEXTURE_SIZE:
7148 case GL_MAX_ARRAY_TEXTURE_LAYERS:
7149 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
7150 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
7151 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
7152 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
7153 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
7154 case GL_MAX_VARYING_COMPONENTS:
7155 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
7156 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
7157 case GL_MIN_PROGRAM_TEXEL_OFFSET:
7158 case GL_MAX_PROGRAM_TEXEL_OFFSET:
7159 case GL_NUM_EXTENSIONS:
7160 case GL_MAJOR_VERSION:
7161 case GL_MINOR_VERSION:
7162 case GL_MAX_ELEMENTS_INDICES:
7163 case GL_MAX_ELEMENTS_VERTICES:
7164 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
7165 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
7166 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
7167 case GL_UNPACK_IMAGE_HEIGHT:
7168 case GL_UNPACK_SKIP_IMAGES:
7169 {
7170 *type = GL_INT;
7171 *numParams = 1;
7172 return true;
7173 }
7174
7175 case GL_MAX_ELEMENT_INDEX:
7176 case GL_MAX_UNIFORM_BLOCK_SIZE:
7177 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
7178 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
7179 case GL_MAX_SERVER_WAIT_TIMEOUT:
7180 {
7181 *type = GL_INT_64_ANGLEX;
7182 *numParams = 1;
7183 return true;
7184 }
7185
7186 case GL_TRANSFORM_FEEDBACK_ACTIVE:
7187 case GL_TRANSFORM_FEEDBACK_PAUSED:
7188 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
7189 case GL_RASTERIZER_DISCARD:
7190 {
7191 *type = GL_BOOL;
7192 *numParams = 1;
7193 return true;
7194 }
7195
7196 case GL_MAX_TEXTURE_LOD_BIAS:
7197 {
7198 *type = GL_FLOAT;
7199 *numParams = 1;
7200 return true;
7201 }
7202 }
7203
7204 if (getExtensions().requestExtension)
7205 {
7206 switch (pname)
7207 {
7208 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
7209 *type = GL_INT;
7210 *numParams = 1;
7211 return true;
7212 }
7213 }
7214
7215 if (getClientVersion() < Version(3, 1))
7216 {
7217 return false;
7218 }
7219
7220 switch (pname)
7221 {
7222 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7223 case GL_DRAW_INDIRECT_BUFFER_BINDING:
7224 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
7225 case GL_MAX_FRAMEBUFFER_WIDTH:
7226 case GL_MAX_FRAMEBUFFER_HEIGHT:
7227 case GL_MAX_FRAMEBUFFER_SAMPLES:
7228 case GL_MAX_SAMPLE_MASK_WORDS:
7229 case GL_MAX_COLOR_TEXTURE_SAMPLES:
7230 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
7231 case GL_MAX_INTEGER_SAMPLES:
7232 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
7233 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
7234 case GL_MAX_VERTEX_ATTRIB_STRIDE:
7235 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
7236 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
7237 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
7238 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
7239 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
7240 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
7241 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
7242 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
7243 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
7244 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
7245 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
7246 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
7247 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
7248 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
7249 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
7250 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
7251 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
7252 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
7253 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
7254 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
7255 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
7256 case GL_MAX_UNIFORM_LOCATIONS:
7257 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
7258 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
7259 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
7260 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
7261 case GL_MAX_IMAGE_UNITS:
7262 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
7263 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
7264 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
7265 case GL_SHADER_STORAGE_BUFFER_BINDING:
7266 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
7267 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
7268 *type = GL_INT;
7269 *numParams = 1;
7270 return true;
7271 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7272 *type = GL_INT_64_ANGLEX;
7273 *numParams = 1;
7274 return true;
7275 case GL_SAMPLE_MASK:
7276 *type = GL_BOOL;
7277 *numParams = 1;
7278 return true;
7279 }
7280
7281 if (getExtensions().geometryShader)
7282 {
7283 switch (pname)
7284 {
7285 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7286 case GL_LAYER_PROVOKING_VERTEX_EXT:
7287 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7288 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7289 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7290 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7291 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7292 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7293 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7294 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7295 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7296 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7297 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7298 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7299 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7300 *type = GL_INT;
7301 *numParams = 1;
7302 return true;
7303 }
7304 }
7305
7306 return false;
7307}
7308
7309bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7310{
7311 if (getClientVersion() < Version(3, 0))
7312 {
7313 return false;
7314 }
7315
7316 switch (target)
7317 {
7318 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7319 case GL_UNIFORM_BUFFER_BINDING:
7320 {
7321 *type = GL_INT;
7322 *numParams = 1;
7323 return true;
7324 }
7325 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7326 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7327 case GL_UNIFORM_BUFFER_START:
7328 case GL_UNIFORM_BUFFER_SIZE:
7329 {
7330 *type = GL_INT_64_ANGLEX;
7331 *numParams = 1;
7332 return true;
7333 }
7334 }
7335
7336 if (getClientVersion() < Version(3, 1))
7337 {
7338 return false;
7339 }
7340
7341 switch (target)
7342 {
7343 case GL_IMAGE_BINDING_LAYERED:
7344 {
7345 *type = GL_BOOL;
7346 *numParams = 1;
7347 return true;
7348 }
7349 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7350 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7351 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7352 case GL_SHADER_STORAGE_BUFFER_BINDING:
7353 case GL_VERTEX_BINDING_BUFFER:
7354 case GL_VERTEX_BINDING_DIVISOR:
7355 case GL_VERTEX_BINDING_OFFSET:
7356 case GL_VERTEX_BINDING_STRIDE:
7357 case GL_SAMPLE_MASK_VALUE:
7358 case GL_IMAGE_BINDING_NAME:
7359 case GL_IMAGE_BINDING_LEVEL:
7360 case GL_IMAGE_BINDING_LAYER:
7361 case GL_IMAGE_BINDING_ACCESS:
7362 case GL_IMAGE_BINDING_FORMAT:
7363 {
7364 *type = GL_INT;
7365 *numParams = 1;
7366 return true;
7367 }
7368 case GL_ATOMIC_COUNTER_BUFFER_START:
7369 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
7370 case GL_SHADER_STORAGE_BUFFER_START:
7371 case GL_SHADER_STORAGE_BUFFER_SIZE:
7372 {
7373 *type = GL_INT_64_ANGLEX;
7374 *numParams = 1;
7375 return true;
7376 }
7377 }
7378
7379 return false;
7380}
7381
7382Program *Context::getProgram(GLuint handle) const
7383{
7384 return mState.mShaderPrograms->getProgram(handle);
7385}
7386
7387Shader *Context::getShader(GLuint handle) const
7388{
7389 return mState.mShaderPrograms->getShader(handle);
7390}
7391
7392bool Context::isTextureGenerated(GLuint texture) const
7393{
7394 return mState.mTextures->isHandleGenerated(texture);
7395}
7396
7397bool Context::isBufferGenerated(GLuint buffer) const
7398{
7399 return mState.mBuffers->isHandleGenerated(buffer);
7400}
7401
7402bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
7403{
7404 return mState.mRenderbuffers->isHandleGenerated(renderbuffer);
7405}
7406
7407bool Context::isFramebufferGenerated(GLuint framebuffer) const
7408{
7409 return mState.mFramebuffers->isHandleGenerated(framebuffer);
7410}
7411
7412bool Context::isProgramPipelineGenerated(GLuint pipeline) const
7413{
7414 return mState.mPipelines->isHandleGenerated(pipeline);
7415}
7416
7417bool Context::usingDisplayTextureShareGroup() const
7418{
7419 return mDisplayTextureShareGroup;
7420}
7421
7422GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
7423{
7424 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
7425 internalformat == GL_DEPTH_STENCIL
7426 ? GL_DEPTH24_STENCIL8
7427 : internalformat;
7428}
7429
Jamie Madillc29968b2016-01-20 11:17:23 -05007430} // namespace gl