blob: 10f85c5d4bfec2f33bd3395f69158e290c47f697 [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.renderable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003187 formatCaps.renderable && formatInfo.renderSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04003188 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003189 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04003190
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003191 // OpenGL ES does not support multisampling with non-rendererable formats
3192 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Olli Etuaho50c562d2017-06-06 14:43:30 +03003193 if (!formatCaps.renderable ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003194 (getClientVersion() < ES_3_1 &&
3195 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04003196 {
Geoff Langd87878e2014-09-19 15:42:59 -04003197 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04003198 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03003199 else
3200 {
3201 // We may have limited the max samples for some required renderbuffer formats due to
3202 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
3203 GLuint formatMaxSamples = formatCaps.getMaxSamples();
3204
3205 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
3206 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
3207 // exception of signed and unsigned integer formats."
3208 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
3209 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
3210 {
3211 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
3212 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
3213 }
3214
3215 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
3216 if (getClientVersion() >= ES_3_1)
3217 {
3218 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
3219 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
3220 // the exception that the signed and unsigned integer formats are required only to
3221 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
3222 // multisamples, which must be at least one."
3223 if (formatInfo.componentType == GL_INT ||
3224 formatInfo.componentType == GL_UNSIGNED_INT)
3225 {
3226 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
3227 }
3228
3229 // GLES 3.1 section 19.3.1.
3230 if (formatCaps.texturable)
3231 {
3232 if (formatInfo.depthBits > 0)
3233 {
3234 mCaps.maxDepthTextureSamples =
3235 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
3236 }
3237 else if (formatInfo.redBits > 0)
3238 {
3239 mCaps.maxColorTextureSamples =
3240 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
3241 }
3242 }
3243 }
3244 }
Geoff Langd87878e2014-09-19 15:42:59 -04003245
3246 if (formatCaps.texturable && formatInfo.compressed)
3247 {
Geoff Langca271392017-04-05 12:30:00 -04003248 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003249 }
3250
Geoff Langca271392017-04-05 12:30:00 -04003251 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04003252 }
Jamie Madill32447362017-06-28 14:53:52 -04003253
3254 // If program binary is disabled, blank out the memory cache pointer.
Geoff Langb0f917f2017-12-05 13:41:54 -05003255 if (!mSupportedExtensions.getProgramBinary)
Jamie Madill32447362017-06-28 14:53:52 -04003256 {
3257 mMemoryProgramCache = nullptr;
3258 }
Corentin Walleze4477002017-12-01 14:39:58 -05003259
3260 // Compute which buffer types are allowed
3261 mValidBufferBindings.reset();
3262 mValidBufferBindings.set(BufferBinding::ElementArray);
3263 mValidBufferBindings.set(BufferBinding::Array);
3264
3265 if (mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
3266 {
3267 mValidBufferBindings.set(BufferBinding::PixelPack);
3268 mValidBufferBindings.set(BufferBinding::PixelUnpack);
3269 }
3270
3271 if (getClientVersion() >= ES_3_0)
3272 {
3273 mValidBufferBindings.set(BufferBinding::CopyRead);
3274 mValidBufferBindings.set(BufferBinding::CopyWrite);
3275 mValidBufferBindings.set(BufferBinding::TransformFeedback);
3276 mValidBufferBindings.set(BufferBinding::Uniform);
3277 }
3278
3279 if (getClientVersion() >= ES_3_1)
3280 {
3281 mValidBufferBindings.set(BufferBinding::AtomicCounter);
3282 mValidBufferBindings.set(BufferBinding::ShaderStorage);
3283 mValidBufferBindings.set(BufferBinding::DrawIndirect);
3284 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
3285 }
Geoff Lang493daf52014-07-03 13:38:44 -04003286}
3287
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003288void Context::initWorkarounds()
3289{
Jamie Madill761b02c2017-06-23 16:27:06 -04003290 // Apply back-end workarounds.
3291 mImplementation->applyNativeWorkarounds(&mWorkarounds);
3292
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003293 // Lose the context upon out of memory error if the application is
3294 // expecting to watch for those events.
3295 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
3296}
3297
Jamie Madill05b35b22017-10-03 09:01:44 -04003298Error Context::prepareForDraw()
3299{
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003300 if (mGLES1Renderer)
3301 {
3302 ANGLE_TRY(mGLES1Renderer->prepareForDraw(this, &mGLState));
3303 }
3304
Geoff Langa8cb2872018-03-09 16:09:40 -05003305 ANGLE_TRY(syncDirtyObjects());
Jamie Madilla59fc192017-11-02 12:57:58 -04003306
3307 if (isRobustResourceInitEnabled())
3308 {
3309 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
3310 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
3311 }
3312
Geoff Langa8cb2872018-03-09 16:09:40 -05003313 ANGLE_TRY(syncDirtyBits());
Geoff Langd4fff502017-09-22 11:28:28 -04003314 return NoError();
3315}
3316
3317Error Context::prepareForClear(GLbitfield mask)
3318{
Geoff Langa8cb2872018-03-09 16:09:40 -05003319 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003320 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearAttachmentsInitialized(this, mask));
Geoff Langa8cb2872018-03-09 16:09:40 -05003321 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04003322 return NoError();
3323}
3324
3325Error Context::prepareForClearBuffer(GLenum buffer, GLint drawbuffer)
3326{
Geoff Langa8cb2872018-03-09 16:09:40 -05003327 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003328 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearBufferAttachmentsInitialized(this, buffer,
3329 drawbuffer));
Geoff Langa8cb2872018-03-09 16:09:40 -05003330 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill05b35b22017-10-03 09:01:44 -04003331 return NoError();
3332}
3333
Geoff Langa8cb2872018-03-09 16:09:40 -05003334Error Context::syncState()
Jamie Madill1b94d432015-08-07 13:23:23 -04003335{
Geoff Langa8cb2872018-03-09 16:09:40 -05003336 ANGLE_TRY(syncDirtyObjects());
3337 ANGLE_TRY(syncDirtyBits());
Jamie Madillbc918e72018-03-08 09:47:21 -05003338 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003339}
3340
Geoff Langa8cb2872018-03-09 16:09:40 -05003341Error Context::syncState(const State::DirtyBits &bitMask, const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04003342{
Geoff Langa8cb2872018-03-09 16:09:40 -05003343 ANGLE_TRY(syncDirtyObjects(objectMask));
3344 ANGLE_TRY(syncDirtyBits(bitMask));
Geoff Langd4fff502017-09-22 11:28:28 -04003345 return NoError();
3346}
3347
Geoff Langa8cb2872018-03-09 16:09:40 -05003348Error Context::syncDirtyBits()
Geoff Langd4fff502017-09-22 11:28:28 -04003349{
3350 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
3351 mImplementation->syncState(this, dirtyBits);
3352 mGLState.clearDirtyBits();
3353 return NoError();
3354}
3355
Geoff Langa8cb2872018-03-09 16:09:40 -05003356Error Context::syncDirtyBits(const State::DirtyBits &bitMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003357{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003358 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madillfe548342017-06-19 11:13:24 -04003359 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003360 mGLState.clearDirtyBits(dirtyBits);
Jamie Madillbc918e72018-03-08 09:47:21 -05003361 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003362}
Jamie Madillc29968b2016-01-20 11:17:23 -05003363
Geoff Langa8cb2872018-03-09 16:09:40 -05003364Error Context::syncDirtyObjects()
Geoff Langd4fff502017-09-22 11:28:28 -04003365{
3366 return mGLState.syncDirtyObjects(this);
3367}
3368
Geoff Langa8cb2872018-03-09 16:09:40 -05003369Error Context::syncDirtyObjects(const State::DirtyObjects &objectMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003370{
3371 return mGLState.syncDirtyObjects(this, objectMask);
3372}
3373
Jamie Madillc29968b2016-01-20 11:17:23 -05003374void Context::blitFramebuffer(GLint srcX0,
3375 GLint srcY0,
3376 GLint srcX1,
3377 GLint srcY1,
3378 GLint dstX0,
3379 GLint dstY0,
3380 GLint dstX1,
3381 GLint dstY1,
3382 GLbitfield mask,
3383 GLenum filter)
3384{
Qin Jiajiaaef92162018-02-27 13:51:44 +08003385 if (mask == 0)
3386 {
3387 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
3388 // buffers are copied.
3389 return;
3390 }
3391
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003392 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003393 ASSERT(drawFramebuffer);
3394
3395 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
3396 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
3397
Jamie Madillbc918e72018-03-08 09:47:21 -05003398 ANGLE_CONTEXT_TRY(syncStateForBlit());
Jamie Madillc29968b2016-01-20 11:17:23 -05003399
Jamie Madillc564c072017-06-01 12:45:42 -04003400 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003401}
Jamie Madillc29968b2016-01-20 11:17:23 -05003402
3403void Context::clear(GLbitfield mask)
3404{
Geoff Langd4fff502017-09-22 11:28:28 -04003405 ANGLE_CONTEXT_TRY(prepareForClear(mask));
3406 ANGLE_CONTEXT_TRY(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05003407}
3408
3409void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
3410{
Geoff Langd4fff502017-09-22 11:28:28 -04003411 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3412 ANGLE_CONTEXT_TRY(
3413 mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003414}
3415
3416void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3417{
Geoff Langd4fff502017-09-22 11:28:28 -04003418 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3419 ANGLE_CONTEXT_TRY(
3420 mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003421}
3422
3423void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3424{
Geoff Langd4fff502017-09-22 11:28:28 -04003425 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3426 ANGLE_CONTEXT_TRY(
3427 mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003428}
3429
3430void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3431{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003432 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003433 ASSERT(framebufferObject);
3434
3435 // If a buffer is not present, the clear has no effect
3436 if (framebufferObject->getDepthbuffer() == nullptr &&
3437 framebufferObject->getStencilbuffer() == nullptr)
3438 {
3439 return;
3440 }
3441
Geoff Langd4fff502017-09-22 11:28:28 -04003442 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3443 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003444}
3445
3446void Context::readPixels(GLint x,
3447 GLint y,
3448 GLsizei width,
3449 GLsizei height,
3450 GLenum format,
3451 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003452 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003453{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003454 if (width == 0 || height == 0)
3455 {
3456 return;
3457 }
3458
Jamie Madillbc918e72018-03-08 09:47:21 -05003459 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003460
Jamie Madillb6664922017-07-25 12:55:04 -04003461 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3462 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003463
3464 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04003465 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003466}
3467
Brandon Jones59770802018-04-02 13:18:42 -07003468void Context::readPixelsRobust(GLint x,
3469 GLint y,
3470 GLsizei width,
3471 GLsizei height,
3472 GLenum format,
3473 GLenum type,
3474 GLsizei bufSize,
3475 GLsizei *length,
3476 GLsizei *columns,
3477 GLsizei *rows,
3478 void *pixels)
3479{
3480 readPixels(x, y, width, height, format, type, pixels);
3481}
3482
3483void Context::readnPixelsRobust(GLint x,
3484 GLint y,
3485 GLsizei width,
3486 GLsizei height,
3487 GLenum format,
3488 GLenum type,
3489 GLsizei bufSize,
3490 GLsizei *length,
3491 GLsizei *columns,
3492 GLsizei *rows,
3493 void *data)
3494{
3495 readPixels(x, y, width, height, format, type, data);
3496}
3497
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003498void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003499 GLint level,
3500 GLenum internalformat,
3501 GLint x,
3502 GLint y,
3503 GLsizei width,
3504 GLsizei height,
3505 GLint border)
3506{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003507 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003508 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003509
Jamie Madillc29968b2016-01-20 11:17:23 -05003510 Rectangle sourceArea(x, y, width, height);
3511
Jamie Madill05b35b22017-10-03 09:01:44 -04003512 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003513 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003514 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003515}
3516
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003517void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003518 GLint level,
3519 GLint xoffset,
3520 GLint yoffset,
3521 GLint x,
3522 GLint y,
3523 GLsizei width,
3524 GLsizei height)
3525{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003526 if (width == 0 || height == 0)
3527 {
3528 return;
3529 }
3530
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003531 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003532 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003533
Jamie Madillc29968b2016-01-20 11:17:23 -05003534 Offset destOffset(xoffset, yoffset, 0);
3535 Rectangle sourceArea(x, y, width, height);
3536
Jamie Madill05b35b22017-10-03 09:01:44 -04003537 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003538 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003539 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003540}
3541
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003542void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003543 GLint level,
3544 GLint xoffset,
3545 GLint yoffset,
3546 GLint zoffset,
3547 GLint x,
3548 GLint y,
3549 GLsizei width,
3550 GLsizei height)
3551{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003552 if (width == 0 || height == 0)
3553 {
3554 return;
3555 }
3556
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003557 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003558 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003559
Jamie Madillc29968b2016-01-20 11:17:23 -05003560 Offset destOffset(xoffset, yoffset, zoffset);
3561 Rectangle sourceArea(x, y, width, height);
3562
Jamie Madill05b35b22017-10-03 09:01:44 -04003563 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3564 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003565 handleError(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level, destOffset,
3566 sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003567}
3568
3569void Context::framebufferTexture2D(GLenum target,
3570 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003571 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003572 GLuint texture,
3573 GLint level)
3574{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003575 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003576 ASSERT(framebuffer);
3577
3578 if (texture != 0)
3579 {
3580 Texture *textureObj = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003581 ImageIndex index = ImageIndex::MakeFromTarget(textarget, level);
Jamie Madilla02315b2017-02-23 14:14:47 -05003582 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003583 }
3584 else
3585 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003586 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003587 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003588
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003589 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003590}
3591
3592void Context::framebufferRenderbuffer(GLenum target,
3593 GLenum attachment,
3594 GLenum renderbuffertarget,
3595 GLuint renderbuffer)
3596{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003597 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003598 ASSERT(framebuffer);
3599
3600 if (renderbuffer != 0)
3601 {
3602 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003603
Jamie Madillcc129372018-04-12 09:13:18 -04003604 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003605 renderbufferObject);
3606 }
3607 else
3608 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003609 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003610 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003611
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003612 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003613}
3614
3615void Context::framebufferTextureLayer(GLenum target,
3616 GLenum attachment,
3617 GLuint texture,
3618 GLint level,
3619 GLint layer)
3620{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003621 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003622 ASSERT(framebuffer);
3623
3624 if (texture != 0)
3625 {
3626 Texture *textureObject = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003627 ImageIndex index = ImageIndex::MakeFromType(textureObject->getType(), level, layer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003628 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003629 }
3630 else
3631 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003632 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003633 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003634
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003635 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003636}
3637
Brandon Jones59770802018-04-02 13:18:42 -07003638void Context::framebufferTextureMultiviewLayered(GLenum target,
3639 GLenum attachment,
3640 GLuint texture,
3641 GLint level,
3642 GLint baseViewIndex,
3643 GLsizei numViews)
Martin Radev137032d2017-07-13 10:11:12 +03003644{
Martin Radev82ef7742017-08-08 17:44:58 +03003645 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3646 ASSERT(framebuffer);
3647
3648 if (texture != 0)
3649 {
3650 Texture *textureObj = getTexture(texture);
3651
Martin Radev18b75ba2017-08-15 15:50:40 +03003652 ImageIndex index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
Martin Radev82ef7742017-08-08 17:44:58 +03003653 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3654 numViews, baseViewIndex);
3655 }
3656 else
3657 {
3658 framebuffer->resetAttachment(this, attachment);
3659 }
3660
3661 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003662}
3663
Brandon Jones59770802018-04-02 13:18:42 -07003664void Context::framebufferTextureMultiviewSideBySide(GLenum target,
3665 GLenum attachment,
3666 GLuint texture,
3667 GLint level,
3668 GLsizei numViews,
3669 const GLint *viewportOffsets)
Martin Radev137032d2017-07-13 10:11:12 +03003670{
Martin Radev5dae57b2017-07-14 16:15:55 +03003671 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3672 ASSERT(framebuffer);
3673
3674 if (texture != 0)
3675 {
3676 Texture *textureObj = getTexture(texture);
3677
3678 ImageIndex index = ImageIndex::Make2D(level);
3679 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3680 textureObj, numViews, viewportOffsets);
3681 }
3682 else
3683 {
3684 framebuffer->resetAttachment(this, attachment);
3685 }
3686
3687 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003688}
3689
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003690// TODO(jiawei.shao@intel.com): implement framebufferTextureEXT
3691void Context::framebufferTexture(GLenum target, GLenum attachment, GLuint texture, GLint level)
3692{
3693 UNIMPLEMENTED();
3694}
3695
Jamie Madillc29968b2016-01-20 11:17:23 -05003696void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3697{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003698 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003699 ASSERT(framebuffer);
3700 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003701 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003702}
3703
3704void Context::readBuffer(GLenum mode)
3705{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003706 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003707 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003708 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003709}
3710
3711void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3712{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003713 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003714 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003715
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003716 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003717 ASSERT(framebuffer);
3718
3719 // The specification isn't clear what should be done when the framebuffer isn't complete.
3720 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003721 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003722}
3723
3724void Context::invalidateFramebuffer(GLenum target,
3725 GLsizei numAttachments,
3726 const GLenum *attachments)
3727{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003728 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003729 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003730
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003731 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003732 ASSERT(framebuffer);
3733
Jamie Madill427064d2018-04-13 16:20:34 -04003734 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003735 {
Jamie Madill437fa652016-05-03 15:13:24 -04003736 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003737 }
Jamie Madill437fa652016-05-03 15:13:24 -04003738
Jamie Madill4928b7c2017-06-20 12:57:39 -04003739 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003740}
3741
3742void Context::invalidateSubFramebuffer(GLenum target,
3743 GLsizei numAttachments,
3744 const GLenum *attachments,
3745 GLint x,
3746 GLint y,
3747 GLsizei width,
3748 GLsizei height)
3749{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003750 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003751 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003752
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003753 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003754 ASSERT(framebuffer);
3755
Jamie Madill427064d2018-04-13 16:20:34 -04003756 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003757 {
Jamie Madill437fa652016-05-03 15:13:24 -04003758 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003759 }
Jamie Madill437fa652016-05-03 15:13:24 -04003760
3761 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003762 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003763}
3764
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003765void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003766 GLint level,
3767 GLint internalformat,
3768 GLsizei width,
3769 GLsizei height,
3770 GLint border,
3771 GLenum format,
3772 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003773 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003774{
Jamie Madillbc918e72018-03-08 09:47:21 -05003775 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003776
3777 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003778 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003779 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3780 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003781}
3782
Brandon Jones59770802018-04-02 13:18:42 -07003783void Context::texImage2DRobust(TextureTarget target,
3784 GLint level,
3785 GLint internalformat,
3786 GLsizei width,
3787 GLsizei height,
3788 GLint border,
3789 GLenum format,
3790 GLenum type,
3791 GLsizei bufSize,
3792 const void *pixels)
3793{
3794 texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
3795}
3796
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003797void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003798 GLint level,
3799 GLint internalformat,
3800 GLsizei width,
3801 GLsizei height,
3802 GLsizei depth,
3803 GLint border,
3804 GLenum format,
3805 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003806 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003807{
Jamie Madillbc918e72018-03-08 09:47:21 -05003808 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003809
3810 Extents size(width, height, depth);
3811 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003812 handleError(texture->setImage(this, mGLState.getUnpackState(),
3813 NonCubeTextureTypeToTarget(target), level, internalformat, size,
3814 format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003815}
3816
Brandon Jones59770802018-04-02 13:18:42 -07003817void Context::texImage3DRobust(TextureType target,
3818 GLint level,
3819 GLint internalformat,
3820 GLsizei width,
3821 GLsizei height,
3822 GLsizei depth,
3823 GLint border,
3824 GLenum format,
3825 GLenum type,
3826 GLsizei bufSize,
3827 const void *pixels)
3828{
3829 texImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels);
3830}
3831
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003832void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003833 GLint level,
3834 GLint xoffset,
3835 GLint yoffset,
3836 GLsizei width,
3837 GLsizei height,
3838 GLenum format,
3839 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003840 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003841{
3842 // Zero sized uploads are valid but no-ops
3843 if (width == 0 || height == 0)
3844 {
3845 return;
3846 }
3847
Jamie Madillbc918e72018-03-08 09:47:21 -05003848 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003849
3850 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003851 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003852 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3853 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003854}
3855
Brandon Jones59770802018-04-02 13:18:42 -07003856void Context::texSubImage2DRobust(TextureTarget target,
3857 GLint level,
3858 GLint xoffset,
3859 GLint yoffset,
3860 GLsizei width,
3861 GLsizei height,
3862 GLenum format,
3863 GLenum type,
3864 GLsizei bufSize,
3865 const void *pixels)
3866{
3867 texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
3868}
3869
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003870void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003871 GLint level,
3872 GLint xoffset,
3873 GLint yoffset,
3874 GLint zoffset,
3875 GLsizei width,
3876 GLsizei height,
3877 GLsizei depth,
3878 GLenum format,
3879 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003880 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003881{
3882 // Zero sized uploads are valid but no-ops
3883 if (width == 0 || height == 0 || depth == 0)
3884 {
3885 return;
3886 }
3887
Jamie Madillbc918e72018-03-08 09:47:21 -05003888 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003889
3890 Box area(xoffset, yoffset, zoffset, width, height, depth);
3891 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003892 handleError(texture->setSubImage(this, mGLState.getUnpackState(),
3893 NonCubeTextureTypeToTarget(target), level, area, format, type,
3894 reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003895}
3896
Brandon Jones59770802018-04-02 13:18:42 -07003897void Context::texSubImage3DRobust(TextureType target,
3898 GLint level,
3899 GLint xoffset,
3900 GLint yoffset,
3901 GLint zoffset,
3902 GLsizei width,
3903 GLsizei height,
3904 GLsizei depth,
3905 GLenum format,
3906 GLenum type,
3907 GLsizei bufSize,
3908 const void *pixels)
3909{
3910 texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type,
3911 pixels);
3912}
3913
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003914void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003915 GLint level,
3916 GLenum internalformat,
3917 GLsizei width,
3918 GLsizei height,
3919 GLint border,
3920 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003921 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003922{
Jamie Madillbc918e72018-03-08 09:47:21 -05003923 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003924
3925 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003926 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003927 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
3928 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003929 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003930}
3931
Brandon Jones59770802018-04-02 13:18:42 -07003932void Context::compressedTexImage2DRobust(TextureTarget target,
3933 GLint level,
3934 GLenum internalformat,
3935 GLsizei width,
3936 GLsizei height,
3937 GLint border,
3938 GLsizei imageSize,
3939 GLsizei dataSize,
3940 const GLvoid *data)
3941{
3942 compressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
3943}
3944
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003945void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003946 GLint level,
3947 GLenum internalformat,
3948 GLsizei width,
3949 GLsizei height,
3950 GLsizei depth,
3951 GLint border,
3952 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003953 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003954{
Jamie Madillbc918e72018-03-08 09:47:21 -05003955 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003956
3957 Extents size(width, height, depth);
3958 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003959 handleError(texture->setCompressedImage(
3960 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
3961 size, imageSize, reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003962}
3963
Brandon Jones59770802018-04-02 13:18:42 -07003964void Context::compressedTexImage3DRobust(TextureType target,
3965 GLint level,
3966 GLenum internalformat,
3967 GLsizei width,
3968 GLsizei height,
3969 GLsizei depth,
3970 GLint border,
3971 GLsizei imageSize,
3972 GLsizei dataSize,
3973 const GLvoid *data)
3974{
3975 compressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize,
3976 data);
3977}
3978
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003979void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003980 GLint level,
3981 GLint xoffset,
3982 GLint yoffset,
3983 GLsizei width,
3984 GLsizei height,
3985 GLenum format,
3986 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003987 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003988{
Jamie Madillbc918e72018-03-08 09:47:21 -05003989 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003990
3991 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003992 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003993 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
3994 format, imageSize,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003995 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003996}
3997
Brandon Jones59770802018-04-02 13:18:42 -07003998void Context::compressedTexSubImage2DRobust(TextureTarget target,
3999 GLint level,
4000 GLint xoffset,
4001 GLint yoffset,
4002 GLsizei width,
4003 GLsizei height,
4004 GLenum format,
4005 GLsizei imageSize,
4006 GLsizei dataSize,
4007 const GLvoid *data)
4008{
4009 compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize,
4010 data);
4011}
4012
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004013void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004014 GLint level,
4015 GLint xoffset,
4016 GLint yoffset,
4017 GLint zoffset,
4018 GLsizei width,
4019 GLsizei height,
4020 GLsizei depth,
4021 GLenum format,
4022 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004023 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004024{
4025 // Zero sized uploads are valid but no-ops
4026 if (width == 0 || height == 0)
4027 {
4028 return;
4029 }
4030
Jamie Madillbc918e72018-03-08 09:47:21 -05004031 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004032
4033 Box area(xoffset, yoffset, zoffset, width, height, depth);
4034 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004035 handleError(texture->setCompressedSubImage(
4036 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
4037 imageSize, reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004038}
4039
Brandon Jones59770802018-04-02 13:18:42 -07004040void Context::compressedTexSubImage3DRobust(TextureType target,
4041 GLint level,
4042 GLint xoffset,
4043 GLint yoffset,
4044 GLint zoffset,
4045 GLsizei width,
4046 GLsizei height,
4047 GLsizei depth,
4048 GLenum format,
4049 GLsizei imageSize,
4050 GLsizei dataSize,
4051 const GLvoid *data)
4052{
4053 compressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format,
4054 imageSize, data);
4055}
4056
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004057void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004058{
4059 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05004060 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004061}
4062
Jamie Madill007530e2017-12-28 14:27:04 -05004063void Context::copyTexture(GLuint sourceId,
4064 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004065 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004066 GLuint destId,
4067 GLint destLevel,
4068 GLint internalFormat,
4069 GLenum destType,
4070 GLboolean unpackFlipY,
4071 GLboolean unpackPremultiplyAlpha,
4072 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004073{
Jamie Madillbc918e72018-03-08 09:47:21 -05004074 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004075
4076 gl::Texture *sourceTexture = getTexture(sourceId);
4077 gl::Texture *destTexture = getTexture(destId);
Geoff Lang92019432017-11-20 13:09:34 -05004078 handleError(destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType,
4079 sourceLevel, ConvertToBool(unpackFlipY),
4080 ConvertToBool(unpackPremultiplyAlpha),
4081 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004082}
4083
Jamie Madill007530e2017-12-28 14:27:04 -05004084void Context::copySubTexture(GLuint sourceId,
4085 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004086 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004087 GLuint destId,
4088 GLint destLevel,
4089 GLint xoffset,
4090 GLint yoffset,
4091 GLint x,
4092 GLint y,
4093 GLsizei width,
4094 GLsizei height,
4095 GLboolean unpackFlipY,
4096 GLboolean unpackPremultiplyAlpha,
4097 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004098{
4099 // Zero sized copies are valid but no-ops
4100 if (width == 0 || height == 0)
4101 {
4102 return;
4103 }
4104
Jamie Madillbc918e72018-03-08 09:47:21 -05004105 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004106
4107 gl::Texture *sourceTexture = getTexture(sourceId);
4108 gl::Texture *destTexture = getTexture(destId);
4109 Offset offset(xoffset, yoffset, 0);
4110 Rectangle area(x, y, width, height);
Geoff Lang92019432017-11-20 13:09:34 -05004111 handleError(destTexture->copySubTexture(this, destTarget, destLevel, offset, sourceLevel, area,
4112 ConvertToBool(unpackFlipY),
4113 ConvertToBool(unpackPremultiplyAlpha),
4114 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004115}
4116
Jamie Madill007530e2017-12-28 14:27:04 -05004117void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07004118{
Jamie Madillbc918e72018-03-08 09:47:21 -05004119 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07004120
4121 gl::Texture *sourceTexture = getTexture(sourceId);
4122 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05004123 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07004124}
4125
Corentin Wallez336129f2017-10-17 15:55:40 -04004126void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03004127{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004128 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004129 ASSERT(buffer);
4130
Geoff Lang496c02d2016-10-20 11:38:11 -07004131 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03004132}
4133
Brandon Jones59770802018-04-02 13:18:42 -07004134void Context::getBufferPointervRobust(BufferBinding target,
4135 GLenum pname,
4136 GLsizei bufSize,
4137 GLsizei *length,
4138 void **params)
4139{
4140 getBufferPointerv(target, pname, params);
4141}
4142
Corentin Wallez336129f2017-10-17 15:55:40 -04004143void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004144{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004145 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004146 ASSERT(buffer);
4147
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004148 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004149 if (error.isError())
4150 {
Jamie Madill437fa652016-05-03 15:13:24 -04004151 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004152 return nullptr;
4153 }
4154
4155 return buffer->getMapPointer();
4156}
4157
Corentin Wallez336129f2017-10-17 15:55:40 -04004158GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03004159{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004160 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004161 ASSERT(buffer);
4162
4163 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004164 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03004165 if (error.isError())
4166 {
Jamie Madill437fa652016-05-03 15:13:24 -04004167 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004168 return GL_FALSE;
4169 }
4170
4171 return result;
4172}
4173
Corentin Wallez336129f2017-10-17 15:55:40 -04004174void *Context::mapBufferRange(BufferBinding target,
4175 GLintptr offset,
4176 GLsizeiptr length,
4177 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004178{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004179 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004180 ASSERT(buffer);
4181
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004182 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004183 if (error.isError())
4184 {
Jamie Madill437fa652016-05-03 15:13:24 -04004185 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004186 return nullptr;
4187 }
4188
4189 return buffer->getMapPointer();
4190}
4191
Corentin Wallez336129f2017-10-17 15:55:40 -04004192void Context::flushMappedBufferRange(BufferBinding /*target*/,
4193 GLintptr /*offset*/,
4194 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03004195{
4196 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
4197}
4198
Jamie Madillbc918e72018-03-08 09:47:21 -05004199Error Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004200{
Geoff Langa8cb2872018-03-09 16:09:40 -05004201 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004202}
4203
Jamie Madillbc918e72018-03-08 09:47:21 -05004204Error Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004205{
Geoff Langa8cb2872018-03-09 16:09:40 -05004206 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004207}
4208
Jamie Madillbc918e72018-03-08 09:47:21 -05004209Error Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004210{
Geoff Langa8cb2872018-03-09 16:09:40 -05004211 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004212}
4213
Jiajia Qin5451d532017-11-16 17:16:34 +08004214void Context::activeShaderProgram(GLuint pipeline, GLuint program)
4215{
4216 UNIMPLEMENTED();
4217}
4218
Jamie Madillc20ab272016-06-09 07:20:46 -07004219void Context::activeTexture(GLenum texture)
4220{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004221 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004222}
4223
Jamie Madill876429b2017-04-20 15:46:24 -04004224void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004225{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004226 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004227}
4228
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004229void Context::blendEquation(GLenum mode)
4230{
4231 mGLState.setBlendEquation(mode, mode);
4232}
4233
Jamie Madillc20ab272016-06-09 07:20:46 -07004234void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
4235{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004236 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004237}
4238
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004239void Context::blendFunc(GLenum sfactor, GLenum dfactor)
4240{
4241 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
4242}
4243
Jamie Madillc20ab272016-06-09 07:20:46 -07004244void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
4245{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004246 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004247}
4248
Jamie Madill876429b2017-04-20 15:46:24 -04004249void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004250{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004251 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004252}
4253
Jamie Madill876429b2017-04-20 15:46:24 -04004254void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07004255{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004256 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07004257}
4258
4259void Context::clearStencil(GLint s)
4260{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004261 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07004262}
4263
4264void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
4265{
Geoff Lang92019432017-11-20 13:09:34 -05004266 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
4267 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004268}
4269
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004270void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07004271{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004272 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004273}
4274
4275void Context::depthFunc(GLenum func)
4276{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004277 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07004278}
4279
4280void Context::depthMask(GLboolean flag)
4281{
Geoff Lang92019432017-11-20 13:09:34 -05004282 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07004283}
4284
Jamie Madill876429b2017-04-20 15:46:24 -04004285void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07004286{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004287 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07004288}
4289
4290void Context::disable(GLenum cap)
4291{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004292 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07004293}
4294
4295void Context::disableVertexAttribArray(GLuint index)
4296{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004297 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07004298}
4299
4300void Context::enable(GLenum cap)
4301{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004302 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07004303}
4304
4305void Context::enableVertexAttribArray(GLuint index)
4306{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004307 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07004308}
4309
4310void Context::frontFace(GLenum mode)
4311{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004312 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004313}
4314
4315void Context::hint(GLenum target, GLenum mode)
4316{
4317 switch (target)
4318 {
4319 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004320 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004321 break;
4322
4323 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004324 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004325 break;
4326
4327 default:
4328 UNREACHABLE();
4329 return;
4330 }
4331}
4332
4333void Context::lineWidth(GLfloat width)
4334{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004335 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07004336}
4337
4338void Context::pixelStorei(GLenum pname, GLint param)
4339{
4340 switch (pname)
4341 {
4342 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004343 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004344 break;
4345
4346 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004347 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004348 break;
4349
4350 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004351 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004352 break;
4353
4354 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004355 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004356 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004357 break;
4358
4359 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03004360 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004361 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004362 break;
4363
4364 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03004365 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004366 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004367 break;
4368
4369 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004370 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004371 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004372 break;
4373
4374 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004375 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004376 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004377 break;
4378
4379 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004380 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004381 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004382 break;
4383
4384 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004385 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004386 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004387 break;
4388
4389 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004390 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004391 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004392 break;
4393
4394 default:
4395 UNREACHABLE();
4396 return;
4397 }
4398}
4399
4400void Context::polygonOffset(GLfloat factor, GLfloat units)
4401{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004402 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07004403}
4404
Jamie Madill876429b2017-04-20 15:46:24 -04004405void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07004406{
Geoff Lang92019432017-11-20 13:09:34 -05004407 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07004408}
4409
Jiawei Shaodb342272017-09-27 10:21:45 +08004410void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
4411{
4412 mGLState.setSampleMaskParams(maskNumber, mask);
4413}
4414
Jamie Madillc20ab272016-06-09 07:20:46 -07004415void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
4416{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004417 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004418}
4419
4420void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
4421{
4422 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4423 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004424 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004425 }
4426
4427 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4428 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004429 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004430 }
4431}
4432
4433void Context::stencilMaskSeparate(GLenum face, GLuint mask)
4434{
4435 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4436 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004437 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004438 }
4439
4440 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4441 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004442 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004443 }
4444}
4445
4446void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4447{
4448 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4449 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004450 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004451 }
4452
4453 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4454 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004455 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004456 }
4457}
4458
4459void Context::vertexAttrib1f(GLuint index, GLfloat x)
4460{
4461 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004462 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004463}
4464
4465void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
4466{
4467 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004468 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004469}
4470
4471void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4472{
4473 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004474 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004475}
4476
4477void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
4478{
4479 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004480 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004481}
4482
4483void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4484{
4485 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004486 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004487}
4488
4489void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
4490{
4491 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004492 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004493}
4494
4495void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4496{
4497 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004498 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004499}
4500
4501void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
4502{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004503 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07004504}
4505
4506void Context::vertexAttribPointer(GLuint index,
4507 GLint size,
4508 GLenum type,
4509 GLboolean normalized,
4510 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004511 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07004512{
Corentin Wallez336129f2017-10-17 15:55:40 -04004513 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05004514 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc20ab272016-06-09 07:20:46 -07004515}
4516
Shao80957d92017-02-20 21:25:59 +08004517void Context::vertexAttribFormat(GLuint attribIndex,
4518 GLint size,
4519 GLenum type,
4520 GLboolean normalized,
4521 GLuint relativeOffset)
4522{
Geoff Lang92019432017-11-20 13:09:34 -05004523 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08004524 relativeOffset);
4525}
4526
4527void Context::vertexAttribIFormat(GLuint attribIndex,
4528 GLint size,
4529 GLenum type,
4530 GLuint relativeOffset)
4531{
4532 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
4533}
4534
4535void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4536{
Shaodde78e82017-05-22 14:13:27 +08004537 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Shao80957d92017-02-20 21:25:59 +08004538}
4539
Jiajia Qin5451d532017-11-16 17:16:34 +08004540void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004541{
4542 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
4543}
4544
Jamie Madillc20ab272016-06-09 07:20:46 -07004545void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4546{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004547 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004548}
4549
4550void Context::vertexAttribIPointer(GLuint index,
4551 GLint size,
4552 GLenum type,
4553 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004554 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004555{
Corentin Wallez336129f2017-10-17 15:55:40 -04004556 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
4557 size, type, false, true, stride, pointer);
Jamie Madillc20ab272016-06-09 07:20:46 -07004558}
4559
4560void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4561{
4562 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004563 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004564}
4565
4566void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4567{
4568 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004569 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004570}
4571
4572void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4573{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004574 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004575}
4576
4577void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4578{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004579 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004580}
4581
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004582void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4583{
4584 const VertexAttribCurrentValueData &currentValues =
4585 getGLState().getVertexAttribCurrentValue(index);
4586 const VertexArray *vao = getGLState().getVertexArray();
4587 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4588 currentValues, pname, params);
4589}
4590
Brandon Jones59770802018-04-02 13:18:42 -07004591void Context::getVertexAttribivRobust(GLuint index,
4592 GLenum pname,
4593 GLsizei bufSize,
4594 GLsizei *length,
4595 GLint *params)
4596{
4597 getVertexAttribiv(index, pname, params);
4598}
4599
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004600void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4601{
4602 const VertexAttribCurrentValueData &currentValues =
4603 getGLState().getVertexAttribCurrentValue(index);
4604 const VertexArray *vao = getGLState().getVertexArray();
4605 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4606 currentValues, pname, params);
4607}
4608
Brandon Jones59770802018-04-02 13:18:42 -07004609void Context::getVertexAttribfvRobust(GLuint index,
4610 GLenum pname,
4611 GLsizei bufSize,
4612 GLsizei *length,
4613 GLfloat *params)
4614{
4615 getVertexAttribfv(index, pname, params);
4616}
4617
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004618void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4619{
4620 const VertexAttribCurrentValueData &currentValues =
4621 getGLState().getVertexAttribCurrentValue(index);
4622 const VertexArray *vao = getGLState().getVertexArray();
4623 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4624 currentValues, pname, params);
4625}
4626
Brandon Jones59770802018-04-02 13:18:42 -07004627void Context::getVertexAttribIivRobust(GLuint index,
4628 GLenum pname,
4629 GLsizei bufSize,
4630 GLsizei *length,
4631 GLint *params)
4632{
4633 getVertexAttribIiv(index, pname, params);
4634}
4635
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004636void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4637{
4638 const VertexAttribCurrentValueData &currentValues =
4639 getGLState().getVertexAttribCurrentValue(index);
4640 const VertexArray *vao = getGLState().getVertexArray();
4641 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4642 currentValues, pname, params);
4643}
4644
Brandon Jones59770802018-04-02 13:18:42 -07004645void Context::getVertexAttribIuivRobust(GLuint index,
4646 GLenum pname,
4647 GLsizei bufSize,
4648 GLsizei *length,
4649 GLuint *params)
4650{
4651 getVertexAttribIuiv(index, pname, params);
4652}
4653
Jamie Madill876429b2017-04-20 15:46:24 -04004654void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004655{
4656 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
4657 QueryVertexAttribPointerv(attrib, pname, pointer);
4658}
4659
Brandon Jones59770802018-04-02 13:18:42 -07004660void Context::getVertexAttribPointervRobust(GLuint index,
4661 GLenum pname,
4662 GLsizei bufSize,
4663 GLsizei *length,
4664 void **pointer)
4665{
4666 getVertexAttribPointerv(index, pname, pointer);
4667}
4668
Jamie Madillc20ab272016-06-09 07:20:46 -07004669void Context::debugMessageControl(GLenum source,
4670 GLenum type,
4671 GLenum severity,
4672 GLsizei count,
4673 const GLuint *ids,
4674 GLboolean enabled)
4675{
4676 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004677 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05004678 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004679}
4680
4681void Context::debugMessageInsert(GLenum source,
4682 GLenum type,
4683 GLuint id,
4684 GLenum severity,
4685 GLsizei length,
4686 const GLchar *buf)
4687{
4688 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004689 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004690}
4691
4692void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4693{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004694 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004695}
4696
4697GLuint Context::getDebugMessageLog(GLuint count,
4698 GLsizei bufSize,
4699 GLenum *sources,
4700 GLenum *types,
4701 GLuint *ids,
4702 GLenum *severities,
4703 GLsizei *lengths,
4704 GLchar *messageLog)
4705{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004706 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4707 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004708}
4709
4710void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4711{
4712 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004713 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05004714 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07004715}
4716
4717void Context::popDebugGroup()
4718{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004719 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05004720 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004721}
4722
Corentin Wallez336129f2017-10-17 15:55:40 -04004723void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004724{
4725 Buffer *buffer = mGLState.getTargetBuffer(target);
4726 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004727 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004728}
4729
Corentin Wallez336129f2017-10-17 15:55:40 -04004730void Context::bufferSubData(BufferBinding target,
4731 GLintptr offset,
4732 GLsizeiptr size,
4733 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004734{
4735 if (data == nullptr)
4736 {
4737 return;
4738 }
4739
4740 Buffer *buffer = mGLState.getTargetBuffer(target);
4741 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004742 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004743}
4744
Jamie Madillef300b12016-10-07 15:12:09 -04004745void Context::attachShader(GLuint program, GLuint shader)
4746{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05004747 Program *programObject = mState.mShaderPrograms->getProgram(program);
4748 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004749 ASSERT(programObject && shaderObject);
4750 programObject->attachShader(shaderObject);
4751}
4752
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004753const Workarounds &Context::getWorkarounds() const
4754{
4755 return mWorkarounds;
4756}
4757
Corentin Wallez336129f2017-10-17 15:55:40 -04004758void Context::copyBufferSubData(BufferBinding readTarget,
4759 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04004760 GLintptr readOffset,
4761 GLintptr writeOffset,
4762 GLsizeiptr size)
4763{
4764 // if size is zero, the copy is a successful no-op
4765 if (size == 0)
4766 {
4767 return;
4768 }
4769
4770 // TODO(jmadill): cache these.
4771 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4772 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4773
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004774 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004775}
4776
Jamie Madill01a80ee2016-11-07 12:06:18 -05004777void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4778{
4779 Program *programObject = getProgram(program);
4780 // TODO(jmadill): Re-use this from the validation if possible.
4781 ASSERT(programObject);
4782 programObject->bindAttributeLocation(index, name);
4783}
4784
Corentin Wallez336129f2017-10-17 15:55:40 -04004785void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004786{
Corentin Wallez336129f2017-10-17 15:55:40 -04004787 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4788 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004789}
4790
Corentin Wallez336129f2017-10-17 15:55:40 -04004791void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08004792{
4793 bindBufferRange(target, index, buffer, 0, 0);
4794}
4795
Corentin Wallez336129f2017-10-17 15:55:40 -04004796void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08004797 GLuint index,
4798 GLuint buffer,
4799 GLintptr offset,
4800 GLsizeiptr size)
4801{
Corentin Wallez336129f2017-10-17 15:55:40 -04004802 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4803 mGLState.setIndexedBufferBinding(this, target, index, bufferObject, offset, size);
Jiajia Qin6eafb042016-12-27 17:04:07 +08004804}
4805
Jamie Madill01a80ee2016-11-07 12:06:18 -05004806void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
4807{
4808 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4809 {
4810 bindReadFramebuffer(framebuffer);
4811 }
4812
4813 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4814 {
4815 bindDrawFramebuffer(framebuffer);
4816 }
4817}
4818
4819void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4820{
4821 ASSERT(target == GL_RENDERBUFFER);
4822 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004823 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04004824 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004825}
4826
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004827void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08004828 GLsizei samples,
4829 GLenum internalformat,
4830 GLsizei width,
4831 GLsizei height,
4832 GLboolean fixedsamplelocations)
4833{
4834 Extents size(width, height, 1);
4835 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004836 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
4837 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004838}
4839
4840void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4841{
JiangYizhou5b03f472017-01-09 10:22:53 +08004842 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
4843 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillbc918e72018-03-08 09:47:21 -05004844 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
JiangYizhou5b03f472017-01-09 10:22:53 +08004845 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08004846
4847 switch (pname)
4848 {
4849 case GL_SAMPLE_POSITION:
Geoff Lang13455072018-05-09 11:24:43 -04004850 handleError(framebuffer->getSamplePosition(this, index, val));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004851 break;
4852 default:
4853 UNREACHABLE();
4854 }
4855}
4856
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07004857void Context::getMultisamplefvRobust(GLenum pname,
4858 GLuint index,
4859 GLsizei bufSize,
4860 GLsizei *length,
4861 GLfloat *val)
4862{
4863 UNIMPLEMENTED();
4864}
4865
Jamie Madille8fb6402017-02-14 17:56:40 -05004866void Context::renderbufferStorage(GLenum target,
4867 GLenum internalformat,
4868 GLsizei width,
4869 GLsizei height)
4870{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004871 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4872 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
4873
Jamie Madille8fb6402017-02-14 17:56:40 -05004874 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04004875 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004876}
4877
4878void Context::renderbufferStorageMultisample(GLenum target,
4879 GLsizei samples,
4880 GLenum internalformat,
4881 GLsizei width,
4882 GLsizei height)
4883{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004884 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4885 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05004886
4887 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004888 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04004889 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004890}
4891
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004892void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
4893{
Jamie Madill70b5bb02017-08-28 13:32:37 -04004894 const Sync *syncObject = getSync(sync);
Geoff Lang82483b92017-04-11 15:33:00 -04004895 handleError(QuerySynciv(syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004896}
4897
JiangYizhoue18e6392017-02-20 10:32:23 +08004898void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
4899{
4900 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4901 QueryFramebufferParameteriv(framebuffer, pname, params);
4902}
4903
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07004904void Context::getFramebufferParameterivRobust(GLenum target,
4905 GLenum pname,
4906 GLsizei bufSize,
4907 GLsizei *length,
4908 GLint *params)
4909{
4910 UNIMPLEMENTED();
4911}
4912
Jiajia Qin5451d532017-11-16 17:16:34 +08004913void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08004914{
4915 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4916 SetFramebufferParameteri(framebuffer, pname, param);
4917}
4918
Jamie Madillb3f26b92017-07-19 15:07:41 -04004919Error Context::getScratchBuffer(size_t requstedSizeBytes,
4920 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05004921{
Jamie Madillb3f26b92017-07-19 15:07:41 -04004922 if (!mScratchBuffer.get(requstedSizeBytes, scratchBufferOut))
4923 {
4924 return OutOfMemory() << "Failed to allocate internal buffer.";
4925 }
4926 return NoError();
4927}
4928
4929Error Context::getZeroFilledBuffer(size_t requstedSizeBytes,
4930 angle::MemoryBuffer **zeroBufferOut) const
4931{
4932 if (!mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0))
Jamie Madille14951e2017-03-09 18:55:16 -05004933 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004934 return OutOfMemory() << "Failed to allocate internal buffer.";
Jamie Madille14951e2017-03-09 18:55:16 -05004935 }
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004936 return NoError();
Jamie Madille14951e2017-03-09 18:55:16 -05004937}
4938
Xinghua Cao10a4d432017-11-28 14:46:26 +08004939Error Context::prepareForDispatch()
4940{
Geoff Langa8cb2872018-03-09 16:09:40 -05004941 ANGLE_TRY(syncState(mComputeDirtyBits, mComputeDirtyObjects));
Xinghua Cao10a4d432017-11-28 14:46:26 +08004942
4943 if (isRobustResourceInitEnabled())
4944 {
4945 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
4946 }
4947
4948 return NoError();
4949}
4950
Xinghua Cao2b396592017-03-29 15:36:04 +08004951void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
4952{
4953 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
4954 {
4955 return;
4956 }
4957
Xinghua Cao10a4d432017-11-28 14:46:26 +08004958 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill71c88b32017-09-14 22:20:29 -04004959 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08004960}
4961
Jiajia Qin5451d532017-11-16 17:16:34 +08004962void Context::dispatchComputeIndirect(GLintptr indirect)
4963{
Qin Jiajia62fcf622017-11-30 16:16:12 +08004964 ANGLE_CONTEXT_TRY(prepareForDispatch());
4965 handleError(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08004966}
4967
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004968void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08004969 GLsizei levels,
4970 GLenum internalFormat,
4971 GLsizei width,
4972 GLsizei height)
4973{
4974 Extents size(width, height, 1);
4975 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004976 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08004977}
4978
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004979void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08004980 GLsizei levels,
4981 GLenum internalFormat,
4982 GLsizei width,
4983 GLsizei height,
4984 GLsizei depth)
4985{
4986 Extents size(width, height, depth);
4987 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004988 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08004989}
4990
Jiajia Qin5451d532017-11-16 17:16:34 +08004991void Context::memoryBarrier(GLbitfield barriers)
4992{
Xinghua Cao89c422a2017-11-29 18:24:20 +08004993 handleError(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08004994}
4995
4996void Context::memoryBarrierByRegion(GLbitfield barriers)
4997{
Xinghua Cao89c422a2017-11-29 18:24:20 +08004998 handleError(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08004999}
5000
Jamie Madillc1d770e2017-04-13 17:31:24 -04005001GLenum Context::checkFramebufferStatus(GLenum target)
5002{
5003 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5004 ASSERT(framebuffer);
Jamie Madill427064d2018-04-13 16:20:34 -04005005 return framebuffer->checkStatus(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005006}
5007
5008void Context::compileShader(GLuint shader)
5009{
5010 Shader *shaderObject = GetValidShader(this, shader);
5011 if (!shaderObject)
5012 {
5013 return;
5014 }
5015 shaderObject->compile(this);
5016}
5017
5018void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
5019{
5020 for (int i = 0; i < n; i++)
5021 {
5022 deleteBuffer(buffers[i]);
5023 }
5024}
5025
5026void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
5027{
5028 for (int i = 0; i < n; i++)
5029 {
5030 if (framebuffers[i] != 0)
5031 {
5032 deleteFramebuffer(framebuffers[i]);
5033 }
5034 }
5035}
5036
5037void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
5038{
5039 for (int i = 0; i < n; i++)
5040 {
5041 deleteRenderbuffer(renderbuffers[i]);
5042 }
5043}
5044
5045void Context::deleteTextures(GLsizei n, const GLuint *textures)
5046{
5047 for (int i = 0; i < n; i++)
5048 {
5049 if (textures[i] != 0)
5050 {
5051 deleteTexture(textures[i]);
5052 }
5053 }
5054}
5055
5056void Context::detachShader(GLuint program, GLuint shader)
5057{
5058 Program *programObject = getProgram(program);
5059 ASSERT(programObject);
5060
5061 Shader *shaderObject = getShader(shader);
5062 ASSERT(shaderObject);
5063
5064 programObject->detachShader(this, shaderObject);
5065}
5066
5067void Context::genBuffers(GLsizei n, GLuint *buffers)
5068{
5069 for (int i = 0; i < n; i++)
5070 {
5071 buffers[i] = createBuffer();
5072 }
5073}
5074
5075void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
5076{
5077 for (int i = 0; i < n; i++)
5078 {
5079 framebuffers[i] = createFramebuffer();
5080 }
5081}
5082
5083void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
5084{
5085 for (int i = 0; i < n; i++)
5086 {
5087 renderbuffers[i] = createRenderbuffer();
5088 }
5089}
5090
5091void Context::genTextures(GLsizei n, GLuint *textures)
5092{
5093 for (int i = 0; i < n; i++)
5094 {
5095 textures[i] = createTexture();
5096 }
5097}
5098
5099void Context::getActiveAttrib(GLuint program,
5100 GLuint index,
5101 GLsizei bufsize,
5102 GLsizei *length,
5103 GLint *size,
5104 GLenum *type,
5105 GLchar *name)
5106{
5107 Program *programObject = getProgram(program);
5108 ASSERT(programObject);
5109 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
5110}
5111
5112void Context::getActiveUniform(GLuint program,
5113 GLuint index,
5114 GLsizei bufsize,
5115 GLsizei *length,
5116 GLint *size,
5117 GLenum *type,
5118 GLchar *name)
5119{
5120 Program *programObject = getProgram(program);
5121 ASSERT(programObject);
5122 programObject->getActiveUniform(index, bufsize, length, size, type, name);
5123}
5124
5125void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
5126{
5127 Program *programObject = getProgram(program);
5128 ASSERT(programObject);
5129 programObject->getAttachedShaders(maxcount, count, shaders);
5130}
5131
5132GLint Context::getAttribLocation(GLuint program, const GLchar *name)
5133{
5134 Program *programObject = getProgram(program);
5135 ASSERT(programObject);
5136 return programObject->getAttributeLocation(name);
5137}
5138
5139void Context::getBooleanv(GLenum pname, GLboolean *params)
5140{
5141 GLenum nativeType;
5142 unsigned int numParams = 0;
5143 getQueryParameterInfo(pname, &nativeType, &numParams);
5144
5145 if (nativeType == GL_BOOL)
5146 {
5147 getBooleanvImpl(pname, params);
5148 }
5149 else
5150 {
5151 CastStateValues(this, nativeType, pname, numParams, params);
5152 }
5153}
5154
Brandon Jones59770802018-04-02 13:18:42 -07005155void Context::getBooleanvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLboolean *params)
5156{
5157 getBooleanv(pname, params);
5158}
5159
Jamie Madillc1d770e2017-04-13 17:31:24 -04005160void Context::getFloatv(GLenum pname, GLfloat *params)
5161{
5162 GLenum nativeType;
5163 unsigned int numParams = 0;
5164 getQueryParameterInfo(pname, &nativeType, &numParams);
5165
5166 if (nativeType == GL_FLOAT)
5167 {
5168 getFloatvImpl(pname, params);
5169 }
5170 else
5171 {
5172 CastStateValues(this, nativeType, pname, numParams, params);
5173 }
5174}
5175
Brandon Jones59770802018-04-02 13:18:42 -07005176void Context::getFloatvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLfloat *params)
5177{
5178 getFloatv(pname, params);
5179}
5180
Jamie Madillc1d770e2017-04-13 17:31:24 -04005181void Context::getIntegerv(GLenum pname, GLint *params)
5182{
5183 GLenum nativeType;
5184 unsigned int numParams = 0;
5185 getQueryParameterInfo(pname, &nativeType, &numParams);
5186
5187 if (nativeType == GL_INT)
5188 {
5189 getIntegervImpl(pname, params);
5190 }
5191 else
5192 {
5193 CastStateValues(this, nativeType, pname, numParams, params);
5194 }
5195}
5196
Brandon Jones59770802018-04-02 13:18:42 -07005197void Context::getIntegervRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint *data)
5198{
5199 getIntegerv(pname, data);
5200}
5201
Jamie Madillc1d770e2017-04-13 17:31:24 -04005202void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
5203{
5204 Program *programObject = getProgram(program);
5205 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04005206 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005207}
5208
Brandon Jones59770802018-04-02 13:18:42 -07005209void Context::getProgramivRobust(GLuint program,
5210 GLenum pname,
5211 GLsizei bufSize,
5212 GLsizei *length,
5213 GLint *params)
5214{
5215 getProgramiv(program, pname, params);
5216}
5217
Jiajia Qin5451d532017-11-16 17:16:34 +08005218void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
5219{
5220 UNIMPLEMENTED();
5221}
5222
Jamie Madillbe849e42017-05-02 15:49:00 -04005223void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005224{
5225 Program *programObject = getProgram(program);
5226 ASSERT(programObject);
5227 programObject->getInfoLog(bufsize, length, infolog);
5228}
5229
Jiajia Qin5451d532017-11-16 17:16:34 +08005230void Context::getProgramPipelineInfoLog(GLuint pipeline,
5231 GLsizei bufSize,
5232 GLsizei *length,
5233 GLchar *infoLog)
5234{
5235 UNIMPLEMENTED();
5236}
5237
Jamie Madillc1d770e2017-04-13 17:31:24 -04005238void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
5239{
5240 Shader *shaderObject = getShader(shader);
5241 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04005242 QueryShaderiv(this, shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005243}
5244
Brandon Jones59770802018-04-02 13:18:42 -07005245void Context::getShaderivRobust(GLuint shader,
5246 GLenum pname,
5247 GLsizei bufSize,
5248 GLsizei *length,
5249 GLint *params)
5250{
5251 getShaderiv(shader, pname, params);
5252}
5253
Jamie Madillc1d770e2017-04-13 17:31:24 -04005254void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
5255{
5256 Shader *shaderObject = getShader(shader);
5257 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04005258 shaderObject->getInfoLog(this, bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005259}
5260
5261void Context::getShaderPrecisionFormat(GLenum shadertype,
5262 GLenum precisiontype,
5263 GLint *range,
5264 GLint *precision)
5265{
5266 // TODO(jmadill): Compute shaders.
5267
5268 switch (shadertype)
5269 {
5270 case GL_VERTEX_SHADER:
5271 switch (precisiontype)
5272 {
5273 case GL_LOW_FLOAT:
5274 mCaps.vertexLowpFloat.get(range, precision);
5275 break;
5276 case GL_MEDIUM_FLOAT:
5277 mCaps.vertexMediumpFloat.get(range, precision);
5278 break;
5279 case GL_HIGH_FLOAT:
5280 mCaps.vertexHighpFloat.get(range, precision);
5281 break;
5282
5283 case GL_LOW_INT:
5284 mCaps.vertexLowpInt.get(range, precision);
5285 break;
5286 case GL_MEDIUM_INT:
5287 mCaps.vertexMediumpInt.get(range, precision);
5288 break;
5289 case GL_HIGH_INT:
5290 mCaps.vertexHighpInt.get(range, precision);
5291 break;
5292
5293 default:
5294 UNREACHABLE();
5295 return;
5296 }
5297 break;
5298
5299 case GL_FRAGMENT_SHADER:
5300 switch (precisiontype)
5301 {
5302 case GL_LOW_FLOAT:
5303 mCaps.fragmentLowpFloat.get(range, precision);
5304 break;
5305 case GL_MEDIUM_FLOAT:
5306 mCaps.fragmentMediumpFloat.get(range, precision);
5307 break;
5308 case GL_HIGH_FLOAT:
5309 mCaps.fragmentHighpFloat.get(range, precision);
5310 break;
5311
5312 case GL_LOW_INT:
5313 mCaps.fragmentLowpInt.get(range, precision);
5314 break;
5315 case GL_MEDIUM_INT:
5316 mCaps.fragmentMediumpInt.get(range, precision);
5317 break;
5318 case GL_HIGH_INT:
5319 mCaps.fragmentHighpInt.get(range, precision);
5320 break;
5321
5322 default:
5323 UNREACHABLE();
5324 return;
5325 }
5326 break;
5327
5328 default:
5329 UNREACHABLE();
5330 return;
5331 }
5332}
5333
5334void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
5335{
5336 Shader *shaderObject = getShader(shader);
5337 ASSERT(shaderObject);
5338 shaderObject->getSource(bufsize, length, source);
5339}
5340
5341void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
5342{
5343 Program *programObject = getProgram(program);
5344 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005345 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005346}
5347
Brandon Jones59770802018-04-02 13:18:42 -07005348void Context::getUniformfvRobust(GLuint program,
5349 GLint location,
5350 GLsizei bufSize,
5351 GLsizei *length,
5352 GLfloat *params)
5353{
5354 getUniformfv(program, location, params);
5355}
5356
Jamie Madillc1d770e2017-04-13 17:31:24 -04005357void Context::getUniformiv(GLuint program, GLint location, GLint *params)
5358{
5359 Program *programObject = getProgram(program);
5360 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005361 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005362}
5363
Brandon Jones59770802018-04-02 13:18:42 -07005364void Context::getUniformivRobust(GLuint program,
5365 GLint location,
5366 GLsizei bufSize,
5367 GLsizei *length,
5368 GLint *params)
5369{
5370 getUniformiv(program, location, params);
5371}
5372
Jamie Madillc1d770e2017-04-13 17:31:24 -04005373GLint Context::getUniformLocation(GLuint program, const GLchar *name)
5374{
5375 Program *programObject = getProgram(program);
5376 ASSERT(programObject);
5377 return programObject->getUniformLocation(name);
5378}
5379
5380GLboolean Context::isBuffer(GLuint buffer)
5381{
5382 if (buffer == 0)
5383 {
5384 return GL_FALSE;
5385 }
5386
5387 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
5388}
5389
5390GLboolean Context::isEnabled(GLenum cap)
5391{
5392 return mGLState.getEnableFeature(cap);
5393}
5394
5395GLboolean Context::isFramebuffer(GLuint framebuffer)
5396{
5397 if (framebuffer == 0)
5398 {
5399 return GL_FALSE;
5400 }
5401
5402 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
5403}
5404
5405GLboolean Context::isProgram(GLuint program)
5406{
5407 if (program == 0)
5408 {
5409 return GL_FALSE;
5410 }
5411
5412 return (getProgram(program) ? GL_TRUE : GL_FALSE);
5413}
5414
5415GLboolean Context::isRenderbuffer(GLuint renderbuffer)
5416{
5417 if (renderbuffer == 0)
5418 {
5419 return GL_FALSE;
5420 }
5421
5422 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
5423}
5424
5425GLboolean Context::isShader(GLuint shader)
5426{
5427 if (shader == 0)
5428 {
5429 return GL_FALSE;
5430 }
5431
5432 return (getShader(shader) ? GL_TRUE : GL_FALSE);
5433}
5434
5435GLboolean Context::isTexture(GLuint texture)
5436{
5437 if (texture == 0)
5438 {
5439 return GL_FALSE;
5440 }
5441
5442 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
5443}
5444
5445void Context::linkProgram(GLuint program)
5446{
5447 Program *programObject = getProgram(program);
5448 ASSERT(programObject);
5449 handleError(programObject->link(this));
Martin Radev0abb7a22017-08-28 15:34:45 +03005450 mGLState.onProgramExecutableChange(programObject);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005451}
5452
5453void Context::releaseShaderCompiler()
5454{
Jamie Madill4928b7c2017-06-20 12:57:39 -04005455 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005456}
5457
5458void Context::shaderBinary(GLsizei n,
5459 const GLuint *shaders,
5460 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04005461 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005462 GLsizei length)
5463{
5464 // No binary shader formats are supported.
5465 UNIMPLEMENTED();
5466}
5467
5468void Context::shaderSource(GLuint shader,
5469 GLsizei count,
5470 const GLchar *const *string,
5471 const GLint *length)
5472{
5473 Shader *shaderObject = getShader(shader);
5474 ASSERT(shaderObject);
5475 shaderObject->setSource(count, string, length);
5476}
5477
5478void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
5479{
5480 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
5481}
5482
5483void Context::stencilMask(GLuint mask)
5484{
5485 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
5486}
5487
5488void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
5489{
5490 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
5491}
5492
5493void Context::uniform1f(GLint location, GLfloat x)
5494{
5495 Program *program = mGLState.getProgram();
5496 program->setUniform1fv(location, 1, &x);
5497}
5498
5499void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
5500{
5501 Program *program = mGLState.getProgram();
5502 program->setUniform1fv(location, count, v);
5503}
5504
5505void Context::uniform1i(GLint location, GLint x)
5506{
5507 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04005508 if (program->setUniform1iv(location, 1, &x) == Program::SetUniformResult::SamplerChanged)
5509 {
5510 mGLState.setObjectDirty(GL_PROGRAM);
5511 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005512}
5513
5514void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
5515{
5516 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04005517 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
5518 {
5519 mGLState.setObjectDirty(GL_PROGRAM);
5520 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005521}
5522
5523void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
5524{
5525 GLfloat xy[2] = {x, y};
5526 Program *program = mGLState.getProgram();
5527 program->setUniform2fv(location, 1, xy);
5528}
5529
5530void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
5531{
5532 Program *program = mGLState.getProgram();
5533 program->setUniform2fv(location, count, v);
5534}
5535
5536void Context::uniform2i(GLint location, GLint x, GLint y)
5537{
5538 GLint xy[2] = {x, y};
5539 Program *program = mGLState.getProgram();
5540 program->setUniform2iv(location, 1, xy);
5541}
5542
5543void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
5544{
5545 Program *program = mGLState.getProgram();
5546 program->setUniform2iv(location, count, v);
5547}
5548
5549void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
5550{
5551 GLfloat xyz[3] = {x, y, z};
5552 Program *program = mGLState.getProgram();
5553 program->setUniform3fv(location, 1, xyz);
5554}
5555
5556void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
5557{
5558 Program *program = mGLState.getProgram();
5559 program->setUniform3fv(location, count, v);
5560}
5561
5562void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
5563{
5564 GLint xyz[3] = {x, y, z};
5565 Program *program = mGLState.getProgram();
5566 program->setUniform3iv(location, 1, xyz);
5567}
5568
5569void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
5570{
5571 Program *program = mGLState.getProgram();
5572 program->setUniform3iv(location, count, v);
5573}
5574
5575void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
5576{
5577 GLfloat xyzw[4] = {x, y, z, w};
5578 Program *program = mGLState.getProgram();
5579 program->setUniform4fv(location, 1, xyzw);
5580}
5581
5582void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
5583{
5584 Program *program = mGLState.getProgram();
5585 program->setUniform4fv(location, count, v);
5586}
5587
5588void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
5589{
5590 GLint xyzw[4] = {x, y, z, w};
5591 Program *program = mGLState.getProgram();
5592 program->setUniform4iv(location, 1, xyzw);
5593}
5594
5595void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
5596{
5597 Program *program = mGLState.getProgram();
5598 program->setUniform4iv(location, count, v);
5599}
5600
5601void Context::uniformMatrix2fv(GLint location,
5602 GLsizei count,
5603 GLboolean transpose,
5604 const GLfloat *value)
5605{
5606 Program *program = mGLState.getProgram();
5607 program->setUniformMatrix2fv(location, count, transpose, value);
5608}
5609
5610void Context::uniformMatrix3fv(GLint location,
5611 GLsizei count,
5612 GLboolean transpose,
5613 const GLfloat *value)
5614{
5615 Program *program = mGLState.getProgram();
5616 program->setUniformMatrix3fv(location, count, transpose, value);
5617}
5618
5619void Context::uniformMatrix4fv(GLint location,
5620 GLsizei count,
5621 GLboolean transpose,
5622 const GLfloat *value)
5623{
5624 Program *program = mGLState.getProgram();
5625 program->setUniformMatrix4fv(location, count, transpose, value);
5626}
5627
5628void Context::validateProgram(GLuint program)
5629{
5630 Program *programObject = getProgram(program);
5631 ASSERT(programObject);
5632 programObject->validate(mCaps);
5633}
5634
Jiajia Qin5451d532017-11-16 17:16:34 +08005635void Context::validateProgramPipeline(GLuint pipeline)
5636{
5637 UNIMPLEMENTED();
5638}
5639
Jamie Madilld04908b2017-06-09 14:15:35 -04005640void Context::getProgramBinary(GLuint program,
5641 GLsizei bufSize,
5642 GLsizei *length,
5643 GLenum *binaryFormat,
5644 void *binary)
5645{
5646 Program *programObject = getProgram(program);
5647 ASSERT(programObject != nullptr);
5648
5649 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
5650}
5651
5652void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
5653{
5654 Program *programObject = getProgram(program);
5655 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04005656
Jamie Madilld04908b2017-06-09 14:15:35 -04005657 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
5658}
5659
Jamie Madillff325f12017-08-26 15:06:05 -04005660void Context::uniform1ui(GLint location, GLuint v0)
5661{
5662 Program *program = mGLState.getProgram();
5663 program->setUniform1uiv(location, 1, &v0);
5664}
5665
5666void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
5667{
5668 Program *program = mGLState.getProgram();
5669 const GLuint xy[] = {v0, v1};
5670 program->setUniform2uiv(location, 1, xy);
5671}
5672
5673void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
5674{
5675 Program *program = mGLState.getProgram();
5676 const GLuint xyz[] = {v0, v1, v2};
5677 program->setUniform3uiv(location, 1, xyz);
5678}
5679
5680void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
5681{
5682 Program *program = mGLState.getProgram();
5683 const GLuint xyzw[] = {v0, v1, v2, v3};
5684 program->setUniform4uiv(location, 1, xyzw);
5685}
5686
5687void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
5688{
5689 Program *program = mGLState.getProgram();
5690 program->setUniform1uiv(location, count, value);
5691}
5692void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
5693{
5694 Program *program = mGLState.getProgram();
5695 program->setUniform2uiv(location, count, value);
5696}
5697
5698void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
5699{
5700 Program *program = mGLState.getProgram();
5701 program->setUniform3uiv(location, count, value);
5702}
5703
5704void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
5705{
5706 Program *program = mGLState.getProgram();
5707 program->setUniform4uiv(location, count, value);
5708}
5709
Jamie Madillf0e04492017-08-26 15:28:42 -04005710void Context::genQueries(GLsizei n, GLuint *ids)
5711{
5712 for (GLsizei i = 0; i < n; i++)
5713 {
5714 GLuint handle = mQueryHandleAllocator.allocate();
5715 mQueryMap.assign(handle, nullptr);
5716 ids[i] = handle;
5717 }
5718}
5719
5720void Context::deleteQueries(GLsizei n, const GLuint *ids)
5721{
5722 for (int i = 0; i < n; i++)
5723 {
5724 GLuint query = ids[i];
5725
5726 Query *queryObject = nullptr;
5727 if (mQueryMap.erase(query, &queryObject))
5728 {
5729 mQueryHandleAllocator.release(query);
5730 if (queryObject)
5731 {
5732 queryObject->release(this);
5733 }
5734 }
5735 }
5736}
5737
5738GLboolean Context::isQuery(GLuint id)
5739{
Corentin Wallezad3ae902018-03-09 13:40:42 -05005740 return (getQuery(id, false, QueryType::InvalidEnum) != nullptr) ? GL_TRUE : GL_FALSE;
Jamie Madillf0e04492017-08-26 15:28:42 -04005741}
5742
Jamie Madillc8c95812017-08-26 18:40:09 -04005743void Context::uniformMatrix2x3fv(GLint location,
5744 GLsizei count,
5745 GLboolean transpose,
5746 const GLfloat *value)
5747{
5748 Program *program = mGLState.getProgram();
5749 program->setUniformMatrix2x3fv(location, count, transpose, value);
5750}
5751
5752void Context::uniformMatrix3x2fv(GLint location,
5753 GLsizei count,
5754 GLboolean transpose,
5755 const GLfloat *value)
5756{
5757 Program *program = mGLState.getProgram();
5758 program->setUniformMatrix3x2fv(location, count, transpose, value);
5759}
5760
5761void Context::uniformMatrix2x4fv(GLint location,
5762 GLsizei count,
5763 GLboolean transpose,
5764 const GLfloat *value)
5765{
5766 Program *program = mGLState.getProgram();
5767 program->setUniformMatrix2x4fv(location, count, transpose, value);
5768}
5769
5770void Context::uniformMatrix4x2fv(GLint location,
5771 GLsizei count,
5772 GLboolean transpose,
5773 const GLfloat *value)
5774{
5775 Program *program = mGLState.getProgram();
5776 program->setUniformMatrix4x2fv(location, count, transpose, value);
5777}
5778
5779void Context::uniformMatrix3x4fv(GLint location,
5780 GLsizei count,
5781 GLboolean transpose,
5782 const GLfloat *value)
5783{
5784 Program *program = mGLState.getProgram();
5785 program->setUniformMatrix3x4fv(location, count, transpose, value);
5786}
5787
5788void Context::uniformMatrix4x3fv(GLint location,
5789 GLsizei count,
5790 GLboolean transpose,
5791 const GLfloat *value)
5792{
5793 Program *program = mGLState.getProgram();
5794 program->setUniformMatrix4x3fv(location, count, transpose, value);
5795}
5796
Jamie Madilld7576732017-08-26 18:49:50 -04005797void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
5798{
5799 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5800 {
5801 GLuint vertexArray = arrays[arrayIndex];
5802
5803 if (arrays[arrayIndex] != 0)
5804 {
5805 VertexArray *vertexArrayObject = nullptr;
5806 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
5807 {
5808 if (vertexArrayObject != nullptr)
5809 {
5810 detachVertexArray(vertexArray);
5811 vertexArrayObject->onDestroy(this);
5812 }
5813
5814 mVertexArrayHandleAllocator.release(vertexArray);
5815 }
5816 }
5817 }
5818}
5819
5820void Context::genVertexArrays(GLsizei n, GLuint *arrays)
5821{
5822 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5823 {
5824 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
5825 mVertexArrayMap.assign(vertexArray, nullptr);
5826 arrays[arrayIndex] = vertexArray;
5827 }
5828}
5829
5830bool Context::isVertexArray(GLuint array)
5831{
5832 if (array == 0)
5833 {
5834 return GL_FALSE;
5835 }
5836
5837 VertexArray *vao = getVertexArray(array);
5838 return (vao != nullptr ? GL_TRUE : GL_FALSE);
5839}
5840
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04005841void Context::endTransformFeedback()
5842{
5843 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5844 transformFeedback->end(this);
5845}
5846
5847void Context::transformFeedbackVaryings(GLuint program,
5848 GLsizei count,
5849 const GLchar *const *varyings,
5850 GLenum bufferMode)
5851{
5852 Program *programObject = getProgram(program);
5853 ASSERT(programObject);
5854 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
5855}
5856
5857void Context::getTransformFeedbackVarying(GLuint program,
5858 GLuint index,
5859 GLsizei bufSize,
5860 GLsizei *length,
5861 GLsizei *size,
5862 GLenum *type,
5863 GLchar *name)
5864{
5865 Program *programObject = getProgram(program);
5866 ASSERT(programObject);
5867 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
5868}
5869
5870void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
5871{
5872 for (int i = 0; i < n; i++)
5873 {
5874 GLuint transformFeedback = ids[i];
5875 if (transformFeedback == 0)
5876 {
5877 continue;
5878 }
5879
5880 TransformFeedback *transformFeedbackObject = nullptr;
5881 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
5882 {
5883 if (transformFeedbackObject != nullptr)
5884 {
5885 detachTransformFeedback(transformFeedback);
5886 transformFeedbackObject->release(this);
5887 }
5888
5889 mTransformFeedbackHandleAllocator.release(transformFeedback);
5890 }
5891 }
5892}
5893
5894void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
5895{
5896 for (int i = 0; i < n; i++)
5897 {
5898 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
5899 mTransformFeedbackMap.assign(transformFeedback, nullptr);
5900 ids[i] = transformFeedback;
5901 }
5902}
5903
5904bool Context::isTransformFeedback(GLuint id)
5905{
5906 if (id == 0)
5907 {
5908 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
5909 // returns FALSE
5910 return GL_FALSE;
5911 }
5912
5913 const TransformFeedback *transformFeedback = getTransformFeedback(id);
5914 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
5915}
5916
5917void Context::pauseTransformFeedback()
5918{
5919 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5920 transformFeedback->pause();
5921}
5922
5923void Context::resumeTransformFeedback()
5924{
5925 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5926 transformFeedback->resume();
5927}
5928
Jamie Madill12e957f2017-08-26 21:42:26 -04005929void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
5930{
5931 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04005932 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04005933}
5934
Brandon Jones59770802018-04-02 13:18:42 -07005935void Context::getUniformuivRobust(GLuint program,
5936 GLint location,
5937 GLsizei bufSize,
5938 GLsizei *length,
5939 GLuint *params)
5940{
5941 getUniformuiv(program, location, params);
5942}
5943
Jamie Madill12e957f2017-08-26 21:42:26 -04005944GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
5945{
5946 const Program *programObject = getProgram(program);
5947 return programObject->getFragDataLocation(name);
5948}
5949
5950void Context::getUniformIndices(GLuint program,
5951 GLsizei uniformCount,
5952 const GLchar *const *uniformNames,
5953 GLuint *uniformIndices)
5954{
5955 const Program *programObject = getProgram(program);
5956 if (!programObject->isLinked())
5957 {
5958 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5959 {
5960 uniformIndices[uniformId] = GL_INVALID_INDEX;
5961 }
5962 }
5963 else
5964 {
5965 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5966 {
5967 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
5968 }
5969 }
5970}
5971
5972void Context::getActiveUniformsiv(GLuint program,
5973 GLsizei uniformCount,
5974 const GLuint *uniformIndices,
5975 GLenum pname,
5976 GLint *params)
5977{
5978 const Program *programObject = getProgram(program);
5979 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5980 {
5981 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08005982 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04005983 }
5984}
5985
5986GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
5987{
5988 const Program *programObject = getProgram(program);
5989 return programObject->getUniformBlockIndex(uniformBlockName);
5990}
5991
5992void Context::getActiveUniformBlockiv(GLuint program,
5993 GLuint uniformBlockIndex,
5994 GLenum pname,
5995 GLint *params)
5996{
5997 const Program *programObject = getProgram(program);
5998 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
5999}
6000
Brandon Jones59770802018-04-02 13:18:42 -07006001void Context::getActiveUniformBlockivRobust(GLuint program,
6002 GLuint uniformBlockIndex,
6003 GLenum pname,
6004 GLsizei bufSize,
6005 GLsizei *length,
6006 GLint *params)
6007{
6008 getActiveUniformBlockiv(program, uniformBlockIndex, pname, params);
6009}
6010
Jamie Madill12e957f2017-08-26 21:42:26 -04006011void Context::getActiveUniformBlockName(GLuint program,
6012 GLuint uniformBlockIndex,
6013 GLsizei bufSize,
6014 GLsizei *length,
6015 GLchar *uniformBlockName)
6016{
6017 const Program *programObject = getProgram(program);
6018 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
6019}
6020
6021void Context::uniformBlockBinding(GLuint program,
6022 GLuint uniformBlockIndex,
6023 GLuint uniformBlockBinding)
6024{
6025 Program *programObject = getProgram(program);
6026 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
6027}
6028
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006029GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
6030{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006031 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
6032 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006033
Jamie Madill70b5bb02017-08-28 13:32:37 -04006034 Sync *syncObject = getSync(syncHandle);
6035 Error error = syncObject->set(condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006036 if (error.isError())
6037 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04006038 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006039 handleError(error);
6040 return nullptr;
6041 }
6042
Jamie Madill70b5bb02017-08-28 13:32:37 -04006043 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006044}
6045
6046GLboolean Context::isSync(GLsync sync)
6047{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006048 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006049}
6050
6051GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6052{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006053 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006054
6055 GLenum result = GL_WAIT_FAILED;
6056 handleError(syncObject->clientWait(flags, timeout, &result));
6057 return result;
6058}
6059
6060void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6061{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006062 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006063 handleError(syncObject->serverWait(flags, timeout));
6064}
6065
6066void Context::getInteger64v(GLenum pname, GLint64 *params)
6067{
6068 GLenum nativeType = GL_NONE;
6069 unsigned int numParams = 0;
6070 getQueryParameterInfo(pname, &nativeType, &numParams);
6071
6072 if (nativeType == GL_INT_64_ANGLEX)
6073 {
6074 getInteger64vImpl(pname, params);
6075 }
6076 else
6077 {
6078 CastStateValues(this, nativeType, pname, numParams, params);
6079 }
6080}
6081
Brandon Jones59770802018-04-02 13:18:42 -07006082void Context::getInteger64vRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint64 *data)
6083{
6084 getInteger64v(pname, data);
6085}
6086
Corentin Wallez336129f2017-10-17 15:55:40 -04006087void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04006088{
6089 Buffer *buffer = mGLState.getTargetBuffer(target);
6090 QueryBufferParameteri64v(buffer, pname, params);
6091}
6092
Brandon Jones59770802018-04-02 13:18:42 -07006093void Context::getBufferParameteri64vRobust(BufferBinding target,
6094 GLenum pname,
6095 GLsizei bufSize,
6096 GLsizei *length,
6097 GLint64 *params)
6098{
6099 getBufferParameteri64v(target, pname, params);
6100}
6101
Jamie Madill3ef140a2017-08-26 23:11:21 -04006102void Context::genSamplers(GLsizei count, GLuint *samplers)
6103{
6104 for (int i = 0; i < count; i++)
6105 {
6106 samplers[i] = mState.mSamplers->createSampler();
6107 }
6108}
6109
6110void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
6111{
6112 for (int i = 0; i < count; i++)
6113 {
6114 GLuint sampler = samplers[i];
6115
6116 if (mState.mSamplers->getSampler(sampler))
6117 {
6118 detachSampler(sampler);
6119 }
6120
6121 mState.mSamplers->deleteObject(this, sampler);
6122 }
6123}
6124
6125void Context::getInternalformativ(GLenum target,
6126 GLenum internalformat,
6127 GLenum pname,
6128 GLsizei bufSize,
6129 GLint *params)
6130{
6131 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
6132 QueryInternalFormativ(formatCaps, pname, bufSize, params);
6133}
6134
Brandon Jones59770802018-04-02 13:18:42 -07006135void Context::getInternalformativRobust(GLenum target,
6136 GLenum internalformat,
6137 GLenum pname,
6138 GLsizei bufSize,
6139 GLsizei *length,
6140 GLint *params)
6141{
6142 getInternalformativ(target, internalformat, pname, bufSize, params);
6143}
6144
Jiajia Qin5451d532017-11-16 17:16:34 +08006145void Context::programUniform1i(GLuint program, GLint location, GLint v0)
6146{
6147 programUniform1iv(program, location, 1, &v0);
6148}
6149
6150void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
6151{
6152 GLint xy[2] = {v0, v1};
6153 programUniform2iv(program, location, 1, xy);
6154}
6155
6156void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
6157{
6158 GLint xyz[3] = {v0, v1, v2};
6159 programUniform3iv(program, location, 1, xyz);
6160}
6161
6162void Context::programUniform4i(GLuint program,
6163 GLint location,
6164 GLint v0,
6165 GLint v1,
6166 GLint v2,
6167 GLint v3)
6168{
6169 GLint xyzw[4] = {v0, v1, v2, v3};
6170 programUniform4iv(program, location, 1, xyzw);
6171}
6172
6173void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
6174{
6175 programUniform1uiv(program, location, 1, &v0);
6176}
6177
6178void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
6179{
6180 GLuint xy[2] = {v0, v1};
6181 programUniform2uiv(program, location, 1, xy);
6182}
6183
6184void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
6185{
6186 GLuint xyz[3] = {v0, v1, v2};
6187 programUniform3uiv(program, location, 1, xyz);
6188}
6189
6190void Context::programUniform4ui(GLuint program,
6191 GLint location,
6192 GLuint v0,
6193 GLuint v1,
6194 GLuint v2,
6195 GLuint v3)
6196{
6197 GLuint xyzw[4] = {v0, v1, v2, v3};
6198 programUniform4uiv(program, location, 1, xyzw);
6199}
6200
6201void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
6202{
6203 programUniform1fv(program, location, 1, &v0);
6204}
6205
6206void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
6207{
6208 GLfloat xy[2] = {v0, v1};
6209 programUniform2fv(program, location, 1, xy);
6210}
6211
6212void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
6213{
6214 GLfloat xyz[3] = {v0, v1, v2};
6215 programUniform3fv(program, location, 1, xyz);
6216}
6217
6218void Context::programUniform4f(GLuint program,
6219 GLint location,
6220 GLfloat v0,
6221 GLfloat v1,
6222 GLfloat v2,
6223 GLfloat v3)
6224{
6225 GLfloat xyzw[4] = {v0, v1, v2, v3};
6226 programUniform4fv(program, location, 1, xyzw);
6227}
6228
Jamie Madill81c2e252017-09-09 23:32:46 -04006229void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6230{
6231 Program *programObject = getProgram(program);
6232 ASSERT(programObject);
6233 if (programObject->setUniform1iv(location, count, value) ==
6234 Program::SetUniformResult::SamplerChanged)
6235 {
6236 mGLState.setObjectDirty(GL_PROGRAM);
6237 }
6238}
6239
Jiajia Qin5451d532017-11-16 17:16:34 +08006240void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6241{
6242 Program *programObject = getProgram(program);
6243 ASSERT(programObject);
6244 programObject->setUniform2iv(location, count, value);
6245}
6246
6247void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6248{
6249 Program *programObject = getProgram(program);
6250 ASSERT(programObject);
6251 programObject->setUniform3iv(location, count, value);
6252}
6253
6254void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6255{
6256 Program *programObject = getProgram(program);
6257 ASSERT(programObject);
6258 programObject->setUniform4iv(location, count, value);
6259}
6260
6261void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6262{
6263 Program *programObject = getProgram(program);
6264 ASSERT(programObject);
6265 programObject->setUniform1uiv(location, count, value);
6266}
6267
6268void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6269{
6270 Program *programObject = getProgram(program);
6271 ASSERT(programObject);
6272 programObject->setUniform2uiv(location, count, value);
6273}
6274
6275void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6276{
6277 Program *programObject = getProgram(program);
6278 ASSERT(programObject);
6279 programObject->setUniform3uiv(location, count, value);
6280}
6281
6282void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6283{
6284 Program *programObject = getProgram(program);
6285 ASSERT(programObject);
6286 programObject->setUniform4uiv(location, count, value);
6287}
6288
6289void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6290{
6291 Program *programObject = getProgram(program);
6292 ASSERT(programObject);
6293 programObject->setUniform1fv(location, count, value);
6294}
6295
6296void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6297{
6298 Program *programObject = getProgram(program);
6299 ASSERT(programObject);
6300 programObject->setUniform2fv(location, count, value);
6301}
6302
6303void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6304{
6305 Program *programObject = getProgram(program);
6306 ASSERT(programObject);
6307 programObject->setUniform3fv(location, count, value);
6308}
6309
6310void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6311{
6312 Program *programObject = getProgram(program);
6313 ASSERT(programObject);
6314 programObject->setUniform4fv(location, count, value);
6315}
6316
6317void Context::programUniformMatrix2fv(GLuint program,
6318 GLint location,
6319 GLsizei count,
6320 GLboolean transpose,
6321 const GLfloat *value)
6322{
6323 Program *programObject = getProgram(program);
6324 ASSERT(programObject);
6325 programObject->setUniformMatrix2fv(location, count, transpose, value);
6326}
6327
6328void Context::programUniformMatrix3fv(GLuint program,
6329 GLint location,
6330 GLsizei count,
6331 GLboolean transpose,
6332 const GLfloat *value)
6333{
6334 Program *programObject = getProgram(program);
6335 ASSERT(programObject);
6336 programObject->setUniformMatrix3fv(location, count, transpose, value);
6337}
6338
6339void Context::programUniformMatrix4fv(GLuint program,
6340 GLint location,
6341 GLsizei count,
6342 GLboolean transpose,
6343 const GLfloat *value)
6344{
6345 Program *programObject = getProgram(program);
6346 ASSERT(programObject);
6347 programObject->setUniformMatrix4fv(location, count, transpose, value);
6348}
6349
6350void Context::programUniformMatrix2x3fv(GLuint program,
6351 GLint location,
6352 GLsizei count,
6353 GLboolean transpose,
6354 const GLfloat *value)
6355{
6356 Program *programObject = getProgram(program);
6357 ASSERT(programObject);
6358 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
6359}
6360
6361void Context::programUniformMatrix3x2fv(GLuint program,
6362 GLint location,
6363 GLsizei count,
6364 GLboolean transpose,
6365 const GLfloat *value)
6366{
6367 Program *programObject = getProgram(program);
6368 ASSERT(programObject);
6369 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
6370}
6371
6372void Context::programUniformMatrix2x4fv(GLuint program,
6373 GLint location,
6374 GLsizei count,
6375 GLboolean transpose,
6376 const GLfloat *value)
6377{
6378 Program *programObject = getProgram(program);
6379 ASSERT(programObject);
6380 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
6381}
6382
6383void Context::programUniformMatrix4x2fv(GLuint program,
6384 GLint location,
6385 GLsizei count,
6386 GLboolean transpose,
6387 const GLfloat *value)
6388{
6389 Program *programObject = getProgram(program);
6390 ASSERT(programObject);
6391 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
6392}
6393
6394void Context::programUniformMatrix3x4fv(GLuint program,
6395 GLint location,
6396 GLsizei count,
6397 GLboolean transpose,
6398 const GLfloat *value)
6399{
6400 Program *programObject = getProgram(program);
6401 ASSERT(programObject);
6402 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
6403}
6404
6405void Context::programUniformMatrix4x3fv(GLuint program,
6406 GLint location,
6407 GLsizei count,
6408 GLboolean transpose,
6409 const GLfloat *value)
6410{
6411 Program *programObject = getProgram(program);
6412 ASSERT(programObject);
6413 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
6414}
6415
Jamie Madill81c2e252017-09-09 23:32:46 -04006416void Context::onTextureChange(const Texture *texture)
6417{
6418 // Conservatively assume all textures are dirty.
6419 // TODO(jmadill): More fine-grained update.
6420 mGLState.setObjectDirty(GL_TEXTURE);
6421}
6422
James Darpiniane8a93c62018-01-04 18:02:24 -08006423bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
6424{
6425 return mGLState.isCurrentTransformFeedback(tf);
6426}
6427bool Context::isCurrentVertexArray(const VertexArray *va) const
6428{
6429 return mGLState.isCurrentVertexArray(va);
6430}
6431
Yunchao Hea336b902017-08-02 16:05:21 +08006432void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
6433{
6434 for (int i = 0; i < count; i++)
6435 {
6436 pipelines[i] = createProgramPipeline();
6437 }
6438}
6439
6440void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
6441{
6442 for (int i = 0; i < count; i++)
6443 {
6444 if (pipelines[i] != 0)
6445 {
6446 deleteProgramPipeline(pipelines[i]);
6447 }
6448 }
6449}
6450
6451GLboolean Context::isProgramPipeline(GLuint pipeline)
6452{
6453 if (pipeline == 0)
6454 {
6455 return GL_FALSE;
6456 }
6457
6458 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
6459}
6460
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006461void Context::finishFenceNV(GLuint fence)
6462{
6463 FenceNV *fenceObject = getFenceNV(fence);
6464
6465 ASSERT(fenceObject && fenceObject->isSet());
6466 handleError(fenceObject->finish());
6467}
6468
6469void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
6470{
6471 FenceNV *fenceObject = getFenceNV(fence);
6472
6473 ASSERT(fenceObject && fenceObject->isSet());
6474
6475 switch (pname)
6476 {
6477 case GL_FENCE_STATUS_NV:
6478 {
6479 // GL_NV_fence spec:
6480 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
6481 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
6482 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
6483 GLboolean status = GL_TRUE;
6484 if (fenceObject->getStatus() != GL_TRUE)
6485 {
6486 ANGLE_CONTEXT_TRY(fenceObject->test(&status));
6487 }
6488 *params = status;
6489 break;
6490 }
6491
6492 case GL_FENCE_CONDITION_NV:
6493 {
6494 *params = static_cast<GLint>(fenceObject->getCondition());
6495 break;
6496 }
6497
6498 default:
6499 UNREACHABLE();
6500 }
6501}
6502
6503void Context::getTranslatedShaderSource(GLuint shader,
6504 GLsizei bufsize,
6505 GLsizei *length,
6506 GLchar *source)
6507{
6508 Shader *shaderObject = getShader(shader);
6509 ASSERT(shaderObject);
6510 shaderObject->getTranslatedSourceWithDebugInfo(this, bufsize, length, source);
6511}
6512
6513void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
6514{
6515 Program *programObject = getProgram(program);
6516 ASSERT(programObject);
6517
6518 programObject->getUniformfv(this, location, params);
6519}
6520
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006521void Context::getnUniformfvRobust(GLuint program,
6522 GLint location,
6523 GLsizei bufSize,
6524 GLsizei *length,
6525 GLfloat *params)
6526{
6527 UNIMPLEMENTED();
6528}
6529
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006530void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
6531{
6532 Program *programObject = getProgram(program);
6533 ASSERT(programObject);
6534
6535 programObject->getUniformiv(this, location, params);
6536}
6537
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006538void Context::getnUniformivRobust(GLuint program,
6539 GLint location,
6540 GLsizei bufSize,
6541 GLsizei *length,
6542 GLint *params)
6543{
6544 UNIMPLEMENTED();
6545}
6546
6547void Context::getnUniformuivRobust(GLuint program,
6548 GLint location,
6549 GLsizei bufSize,
6550 GLsizei *length,
6551 GLuint *params)
6552{
6553 UNIMPLEMENTED();
6554}
6555
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006556GLboolean Context::isFenceNV(GLuint fence)
6557{
6558 FenceNV *fenceObject = getFenceNV(fence);
6559
6560 if (fenceObject == nullptr)
6561 {
6562 return GL_FALSE;
6563 }
6564
6565 // GL_NV_fence spec:
6566 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
6567 // existing fence.
6568 return fenceObject->isSet();
6569}
6570
6571void Context::readnPixels(GLint x,
6572 GLint y,
6573 GLsizei width,
6574 GLsizei height,
6575 GLenum format,
6576 GLenum type,
6577 GLsizei bufSize,
6578 void *data)
6579{
6580 return readPixels(x, y, width, height, format, type, data);
6581}
6582
Jamie Madill007530e2017-12-28 14:27:04 -05006583void Context::setFenceNV(GLuint fence, GLenum condition)
6584{
6585 ASSERT(condition == GL_ALL_COMPLETED_NV);
6586
6587 FenceNV *fenceObject = getFenceNV(fence);
6588 ASSERT(fenceObject != nullptr);
6589 handleError(fenceObject->set(condition));
6590}
6591
6592GLboolean Context::testFenceNV(GLuint fence)
6593{
6594 FenceNV *fenceObject = getFenceNV(fence);
6595
6596 ASSERT(fenceObject != nullptr);
6597 ASSERT(fenceObject->isSet() == GL_TRUE);
6598
6599 GLboolean result = GL_TRUE;
6600 Error error = fenceObject->test(&result);
6601 if (error.isError())
6602 {
6603 handleError(error);
6604 return GL_TRUE;
6605 }
6606
6607 return result;
6608}
6609
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006610void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006611{
6612 Texture *texture = getTargetTexture(target);
6613 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
Corentin Wallez99d492c2018-02-27 15:17:10 -05006614 handleError(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05006615}
6616
Jamie Madillfa920eb2018-01-04 11:45:50 -05006617void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006618{
6619 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
6620 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
6621 handleError(renderbuffer->setStorageEGLImageTarget(this, imageObject));
6622}
6623
Jamie Madillfa920eb2018-01-04 11:45:50 -05006624void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
6625{
6626 UNIMPLEMENTED();
6627}
6628
Jamie Madill5b772312018-03-08 20:28:32 -05006629bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
6630{
6631 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
6632 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
6633 // to the fact that it is stored internally as a float, and so would require conversion
6634 // if returned from Context::getIntegerv. Since this conversion is already implemented
6635 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
6636 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
6637 // application.
6638 switch (pname)
6639 {
6640 case GL_COMPRESSED_TEXTURE_FORMATS:
6641 {
6642 *type = GL_INT;
6643 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
6644 return true;
6645 }
6646 case GL_SHADER_BINARY_FORMATS:
6647 {
6648 *type = GL_INT;
6649 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
6650 return true;
6651 }
6652
6653 case GL_MAX_VERTEX_ATTRIBS:
6654 case GL_MAX_VERTEX_UNIFORM_VECTORS:
6655 case GL_MAX_VARYING_VECTORS:
6656 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
6657 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
6658 case GL_MAX_TEXTURE_IMAGE_UNITS:
6659 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
6660 case GL_MAX_RENDERBUFFER_SIZE:
6661 case GL_NUM_SHADER_BINARY_FORMATS:
6662 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
6663 case GL_ARRAY_BUFFER_BINDING:
6664 case GL_FRAMEBUFFER_BINDING:
6665 case GL_RENDERBUFFER_BINDING:
6666 case GL_CURRENT_PROGRAM:
6667 case GL_PACK_ALIGNMENT:
6668 case GL_UNPACK_ALIGNMENT:
6669 case GL_GENERATE_MIPMAP_HINT:
6670 case GL_RED_BITS:
6671 case GL_GREEN_BITS:
6672 case GL_BLUE_BITS:
6673 case GL_ALPHA_BITS:
6674 case GL_DEPTH_BITS:
6675 case GL_STENCIL_BITS:
6676 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
6677 case GL_CULL_FACE_MODE:
6678 case GL_FRONT_FACE:
6679 case GL_ACTIVE_TEXTURE:
6680 case GL_STENCIL_FUNC:
6681 case GL_STENCIL_VALUE_MASK:
6682 case GL_STENCIL_REF:
6683 case GL_STENCIL_FAIL:
6684 case GL_STENCIL_PASS_DEPTH_FAIL:
6685 case GL_STENCIL_PASS_DEPTH_PASS:
6686 case GL_STENCIL_BACK_FUNC:
6687 case GL_STENCIL_BACK_VALUE_MASK:
6688 case GL_STENCIL_BACK_REF:
6689 case GL_STENCIL_BACK_FAIL:
6690 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
6691 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
6692 case GL_DEPTH_FUNC:
6693 case GL_BLEND_SRC_RGB:
6694 case GL_BLEND_SRC_ALPHA:
6695 case GL_BLEND_DST_RGB:
6696 case GL_BLEND_DST_ALPHA:
6697 case GL_BLEND_EQUATION_RGB:
6698 case GL_BLEND_EQUATION_ALPHA:
6699 case GL_STENCIL_WRITEMASK:
6700 case GL_STENCIL_BACK_WRITEMASK:
6701 case GL_STENCIL_CLEAR_VALUE:
6702 case GL_SUBPIXEL_BITS:
6703 case GL_MAX_TEXTURE_SIZE:
6704 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
6705 case GL_SAMPLE_BUFFERS:
6706 case GL_SAMPLES:
6707 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
6708 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
6709 case GL_TEXTURE_BINDING_2D:
6710 case GL_TEXTURE_BINDING_CUBE_MAP:
6711 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
6712 {
6713 *type = GL_INT;
6714 *numParams = 1;
6715 return true;
6716 }
6717 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6718 {
6719 if (!getExtensions().packReverseRowOrder)
6720 {
6721 return false;
6722 }
6723 *type = GL_INT;
6724 *numParams = 1;
6725 return true;
6726 }
6727 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
6728 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
6729 {
6730 if (!getExtensions().textureRectangle)
6731 {
6732 return false;
6733 }
6734 *type = GL_INT;
6735 *numParams = 1;
6736 return true;
6737 }
6738 case GL_MAX_DRAW_BUFFERS_EXT:
6739 case GL_MAX_COLOR_ATTACHMENTS_EXT:
6740 {
6741 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
6742 {
6743 return false;
6744 }
6745 *type = GL_INT;
6746 *numParams = 1;
6747 return true;
6748 }
6749 case GL_MAX_VIEWPORT_DIMS:
6750 {
6751 *type = GL_INT;
6752 *numParams = 2;
6753 return true;
6754 }
6755 case GL_VIEWPORT:
6756 case GL_SCISSOR_BOX:
6757 {
6758 *type = GL_INT;
6759 *numParams = 4;
6760 return true;
6761 }
6762 case GL_SHADER_COMPILER:
6763 case GL_SAMPLE_COVERAGE_INVERT:
6764 case GL_DEPTH_WRITEMASK:
6765 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
6766 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
6767 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
6768 // bool-natural
6769 case GL_SAMPLE_COVERAGE:
6770 case GL_SCISSOR_TEST:
6771 case GL_STENCIL_TEST:
6772 case GL_DEPTH_TEST:
6773 case GL_BLEND:
6774 case GL_DITHER:
6775 case GL_CONTEXT_ROBUST_ACCESS_EXT:
6776 {
6777 *type = GL_BOOL;
6778 *numParams = 1;
6779 return true;
6780 }
6781 case GL_COLOR_WRITEMASK:
6782 {
6783 *type = GL_BOOL;
6784 *numParams = 4;
6785 return true;
6786 }
6787 case GL_POLYGON_OFFSET_FACTOR:
6788 case GL_POLYGON_OFFSET_UNITS:
6789 case GL_SAMPLE_COVERAGE_VALUE:
6790 case GL_DEPTH_CLEAR_VALUE:
6791 case GL_LINE_WIDTH:
6792 {
6793 *type = GL_FLOAT;
6794 *numParams = 1;
6795 return true;
6796 }
6797 case GL_ALIASED_LINE_WIDTH_RANGE:
6798 case GL_ALIASED_POINT_SIZE_RANGE:
6799 case GL_DEPTH_RANGE:
6800 {
6801 *type = GL_FLOAT;
6802 *numParams = 2;
6803 return true;
6804 }
6805 case GL_COLOR_CLEAR_VALUE:
6806 case GL_BLEND_COLOR:
6807 {
6808 *type = GL_FLOAT;
6809 *numParams = 4;
6810 return true;
6811 }
6812 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
6813 if (!getExtensions().textureFilterAnisotropic)
6814 {
6815 return false;
6816 }
6817 *type = GL_FLOAT;
6818 *numParams = 1;
6819 return true;
6820 case GL_TIMESTAMP_EXT:
6821 if (!getExtensions().disjointTimerQuery)
6822 {
6823 return false;
6824 }
6825 *type = GL_INT_64_ANGLEX;
6826 *numParams = 1;
6827 return true;
6828 case GL_GPU_DISJOINT_EXT:
6829 if (!getExtensions().disjointTimerQuery)
6830 {
6831 return false;
6832 }
6833 *type = GL_INT;
6834 *numParams = 1;
6835 return true;
6836 case GL_COVERAGE_MODULATION_CHROMIUM:
6837 if (!getExtensions().framebufferMixedSamples)
6838 {
6839 return false;
6840 }
6841 *type = GL_INT;
6842 *numParams = 1;
6843 return true;
6844 case GL_TEXTURE_BINDING_EXTERNAL_OES:
6845 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
6846 {
6847 return false;
6848 }
6849 *type = GL_INT;
6850 *numParams = 1;
6851 return true;
6852 }
6853
6854 if (getExtensions().debug)
6855 {
6856 switch (pname)
6857 {
6858 case GL_DEBUG_LOGGED_MESSAGES:
6859 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
6860 case GL_DEBUG_GROUP_STACK_DEPTH:
6861 case GL_MAX_DEBUG_MESSAGE_LENGTH:
6862 case GL_MAX_DEBUG_LOGGED_MESSAGES:
6863 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
6864 case GL_MAX_LABEL_LENGTH:
6865 *type = GL_INT;
6866 *numParams = 1;
6867 return true;
6868
6869 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
6870 case GL_DEBUG_OUTPUT:
6871 *type = GL_BOOL;
6872 *numParams = 1;
6873 return true;
6874 }
6875 }
6876
6877 if (getExtensions().multisampleCompatibility)
6878 {
6879 switch (pname)
6880 {
6881 case GL_MULTISAMPLE_EXT:
6882 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
6883 *type = GL_BOOL;
6884 *numParams = 1;
6885 return true;
6886 }
6887 }
6888
6889 if (getExtensions().pathRendering)
6890 {
6891 switch (pname)
6892 {
6893 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
6894 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
6895 *type = GL_FLOAT;
6896 *numParams = 16;
6897 return true;
6898 }
6899 }
6900
6901 if (getExtensions().bindGeneratesResource)
6902 {
6903 switch (pname)
6904 {
6905 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
6906 *type = GL_BOOL;
6907 *numParams = 1;
6908 return true;
6909 }
6910 }
6911
6912 if (getExtensions().clientArrays)
6913 {
6914 switch (pname)
6915 {
6916 case GL_CLIENT_ARRAYS_ANGLE:
6917 *type = GL_BOOL;
6918 *numParams = 1;
6919 return true;
6920 }
6921 }
6922
6923 if (getExtensions().sRGBWriteControl)
6924 {
6925 switch (pname)
6926 {
6927 case GL_FRAMEBUFFER_SRGB_EXT:
6928 *type = GL_BOOL;
6929 *numParams = 1;
6930 return true;
6931 }
6932 }
6933
6934 if (getExtensions().robustResourceInitialization &&
6935 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
6936 {
6937 *type = GL_BOOL;
6938 *numParams = 1;
6939 return true;
6940 }
6941
6942 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
6943 {
6944 *type = GL_BOOL;
6945 *numParams = 1;
6946 return true;
6947 }
6948
6949 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
6950 switch (pname)
6951 {
6952 // case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE // equivalent to FRAMEBUFFER_BINDING
6953 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
6954 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
6955 {
6956 return false;
6957 }
6958 *type = GL_INT;
6959 *numParams = 1;
6960 return true;
6961
6962 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
6963 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
6964 {
6965 return false;
6966 }
6967 *type = GL_INT;
6968 *numParams = 1;
6969 return true;
6970
6971 case GL_PROGRAM_BINARY_FORMATS_OES:
6972 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
6973 {
6974 return false;
6975 }
6976 *type = GL_INT;
6977 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
6978 return true;
6979
6980 case GL_PACK_ROW_LENGTH:
6981 case GL_PACK_SKIP_ROWS:
6982 case GL_PACK_SKIP_PIXELS:
6983 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
6984 {
6985 return false;
6986 }
6987 *type = GL_INT;
6988 *numParams = 1;
6989 return true;
6990 case GL_UNPACK_ROW_LENGTH:
6991 case GL_UNPACK_SKIP_ROWS:
6992 case GL_UNPACK_SKIP_PIXELS:
6993 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
6994 {
6995 return false;
6996 }
6997 *type = GL_INT;
6998 *numParams = 1;
6999 return true;
7000 case GL_VERTEX_ARRAY_BINDING:
7001 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
7002 {
7003 return false;
7004 }
7005 *type = GL_INT;
7006 *numParams = 1;
7007 return true;
7008 case GL_PIXEL_PACK_BUFFER_BINDING:
7009 case GL_PIXEL_UNPACK_BUFFER_BINDING:
7010 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
7011 {
7012 return false;
7013 }
7014 *type = GL_INT;
7015 *numParams = 1;
7016 return true;
7017 case GL_MAX_SAMPLES:
7018 {
7019 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
7020 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
7021 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
7022 {
7023 return false;
7024 }
7025 *type = GL_INT;
7026 *numParams = 1;
7027 return true;
7028
7029 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
7030 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
7031 {
7032 return false;
7033 }
7034 *type = GL_INT;
7035 *numParams = 1;
7036 return true;
7037 }
7038 }
7039
7040 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
7041 {
7042 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
7043 {
7044 return false;
7045 }
7046 *type = GL_INT;
7047 *numParams = 1;
7048 return true;
7049 }
7050
7051 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
7052 {
7053 *type = GL_INT;
7054 *numParams = 1;
7055 return true;
7056 }
7057
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007058 if (getClientVersion() < Version(2, 0))
7059 {
7060 switch (pname)
7061 {
7062 case GL_ALPHA_TEST_FUNC:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007063 case GL_CLIENT_ACTIVE_TEXTURE:
7064 case GL_MATRIX_MODE:
7065 case GL_MAX_TEXTURE_UNITS:
7066 case GL_MAX_MODELVIEW_STACK_DEPTH:
7067 case GL_MAX_PROJECTION_STACK_DEPTH:
7068 case GL_MAX_TEXTURE_STACK_DEPTH:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007069 case GL_MAX_LIGHTS:
Lingfeng Yang060088a2018-05-30 20:40:57 -07007070 case GL_MAX_CLIP_PLANES:
Lingfeng Yangabb09f12018-04-16 10:43:53 -07007071 case GL_VERTEX_ARRAY_STRIDE:
7072 case GL_NORMAL_ARRAY_STRIDE:
7073 case GL_COLOR_ARRAY_STRIDE:
7074 case GL_TEXTURE_COORD_ARRAY_STRIDE:
7075 case GL_VERTEX_ARRAY_SIZE:
7076 case GL_COLOR_ARRAY_SIZE:
7077 case GL_TEXTURE_COORD_ARRAY_SIZE:
7078 case GL_VERTEX_ARRAY_TYPE:
7079 case GL_NORMAL_ARRAY_TYPE:
7080 case GL_COLOR_ARRAY_TYPE:
7081 case GL_TEXTURE_COORD_ARRAY_TYPE:
7082 case GL_VERTEX_ARRAY_BUFFER_BINDING:
7083 case GL_NORMAL_ARRAY_BUFFER_BINDING:
7084 case GL_COLOR_ARRAY_BUFFER_BINDING:
7085 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
7086 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
7087 case GL_POINT_SIZE_ARRAY_TYPE_OES:
7088 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
Lingfeng Yanga0cfa872018-05-30 21:12:17 -07007089 case GL_SHADE_MODEL:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007090 *type = GL_INT;
7091 *numParams = 1;
7092 return true;
7093 case GL_ALPHA_TEST_REF:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007094 case GL_FOG_DENSITY:
7095 case GL_FOG_START:
7096 case GL_FOG_END:
7097 case GL_FOG_MODE:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007098 *type = GL_FLOAT;
7099 *numParams = 1;
7100 return true;
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007101 case GL_CURRENT_COLOR:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007102 case GL_CURRENT_TEXTURE_COORDS:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007103 case GL_LIGHT_MODEL_AMBIENT:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007104 case GL_FOG_COLOR:
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007105 *type = GL_FLOAT;
7106 *numParams = 4;
7107 return true;
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007108 case GL_CURRENT_NORMAL:
7109 *type = GL_FLOAT;
7110 *numParams = 3;
7111 return true;
Lingfeng Yang3a41af62018-04-09 07:28:56 -07007112 case GL_MODELVIEW_MATRIX:
7113 case GL_PROJECTION_MATRIX:
7114 case GL_TEXTURE_MATRIX:
7115 *type = GL_FLOAT;
7116 *numParams = 16;
7117 return true;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007118 case GL_LIGHT_MODEL_TWO_SIDE:
7119 *type = GL_BOOL;
7120 *numParams = 1;
7121 return true;
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007122 }
7123 }
7124
Jamie Madill5b772312018-03-08 20:28:32 -05007125 if (getClientVersion() < Version(3, 0))
7126 {
7127 return false;
7128 }
7129
7130 // Check for ES3.0+ parameter names
7131 switch (pname)
7132 {
7133 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
7134 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
7135 case GL_UNIFORM_BUFFER_BINDING:
7136 case GL_TRANSFORM_FEEDBACK_BINDING:
7137 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7138 case GL_COPY_READ_BUFFER_BINDING:
7139 case GL_COPY_WRITE_BUFFER_BINDING:
7140 case GL_SAMPLER_BINDING:
7141 case GL_READ_BUFFER:
7142 case GL_TEXTURE_BINDING_3D:
7143 case GL_TEXTURE_BINDING_2D_ARRAY:
7144 case GL_MAX_3D_TEXTURE_SIZE:
7145 case GL_MAX_ARRAY_TEXTURE_LAYERS:
7146 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
7147 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
7148 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
7149 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
7150 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
7151 case GL_MAX_VARYING_COMPONENTS:
7152 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
7153 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
7154 case GL_MIN_PROGRAM_TEXEL_OFFSET:
7155 case GL_MAX_PROGRAM_TEXEL_OFFSET:
7156 case GL_NUM_EXTENSIONS:
7157 case GL_MAJOR_VERSION:
7158 case GL_MINOR_VERSION:
7159 case GL_MAX_ELEMENTS_INDICES:
7160 case GL_MAX_ELEMENTS_VERTICES:
7161 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
7162 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
7163 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
7164 case GL_UNPACK_IMAGE_HEIGHT:
7165 case GL_UNPACK_SKIP_IMAGES:
7166 {
7167 *type = GL_INT;
7168 *numParams = 1;
7169 return true;
7170 }
7171
7172 case GL_MAX_ELEMENT_INDEX:
7173 case GL_MAX_UNIFORM_BLOCK_SIZE:
7174 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
7175 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
7176 case GL_MAX_SERVER_WAIT_TIMEOUT:
7177 {
7178 *type = GL_INT_64_ANGLEX;
7179 *numParams = 1;
7180 return true;
7181 }
7182
7183 case GL_TRANSFORM_FEEDBACK_ACTIVE:
7184 case GL_TRANSFORM_FEEDBACK_PAUSED:
7185 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
7186 case GL_RASTERIZER_DISCARD:
7187 {
7188 *type = GL_BOOL;
7189 *numParams = 1;
7190 return true;
7191 }
7192
7193 case GL_MAX_TEXTURE_LOD_BIAS:
7194 {
7195 *type = GL_FLOAT;
7196 *numParams = 1;
7197 return true;
7198 }
7199 }
7200
7201 if (getExtensions().requestExtension)
7202 {
7203 switch (pname)
7204 {
7205 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
7206 *type = GL_INT;
7207 *numParams = 1;
7208 return true;
7209 }
7210 }
7211
7212 if (getClientVersion() < Version(3, 1))
7213 {
7214 return false;
7215 }
7216
7217 switch (pname)
7218 {
7219 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7220 case GL_DRAW_INDIRECT_BUFFER_BINDING:
7221 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
7222 case GL_MAX_FRAMEBUFFER_WIDTH:
7223 case GL_MAX_FRAMEBUFFER_HEIGHT:
7224 case GL_MAX_FRAMEBUFFER_SAMPLES:
7225 case GL_MAX_SAMPLE_MASK_WORDS:
7226 case GL_MAX_COLOR_TEXTURE_SAMPLES:
7227 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
7228 case GL_MAX_INTEGER_SAMPLES:
7229 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
7230 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
7231 case GL_MAX_VERTEX_ATTRIB_STRIDE:
7232 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
7233 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
7234 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
7235 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
7236 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
7237 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
7238 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
7239 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
7240 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
7241 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
7242 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
7243 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
7244 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
7245 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
7246 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
7247 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
7248 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
7249 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
7250 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
7251 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
7252 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
7253 case GL_MAX_UNIFORM_LOCATIONS:
7254 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
7255 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
7256 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
7257 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
7258 case GL_MAX_IMAGE_UNITS:
7259 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
7260 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
7261 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
7262 case GL_SHADER_STORAGE_BUFFER_BINDING:
7263 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
7264 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
7265 *type = GL_INT;
7266 *numParams = 1;
7267 return true;
7268 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7269 *type = GL_INT_64_ANGLEX;
7270 *numParams = 1;
7271 return true;
7272 case GL_SAMPLE_MASK:
7273 *type = GL_BOOL;
7274 *numParams = 1;
7275 return true;
7276 }
7277
7278 if (getExtensions().geometryShader)
7279 {
7280 switch (pname)
7281 {
7282 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7283 case GL_LAYER_PROVOKING_VERTEX_EXT:
7284 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7285 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7286 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7287 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7288 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7289 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7290 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7291 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7292 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7293 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7294 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7295 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7296 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7297 *type = GL_INT;
7298 *numParams = 1;
7299 return true;
7300 }
7301 }
7302
7303 return false;
7304}
7305
7306bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7307{
7308 if (getClientVersion() < Version(3, 0))
7309 {
7310 return false;
7311 }
7312
7313 switch (target)
7314 {
7315 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7316 case GL_UNIFORM_BUFFER_BINDING:
7317 {
7318 *type = GL_INT;
7319 *numParams = 1;
7320 return true;
7321 }
7322 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7323 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7324 case GL_UNIFORM_BUFFER_START:
7325 case GL_UNIFORM_BUFFER_SIZE:
7326 {
7327 *type = GL_INT_64_ANGLEX;
7328 *numParams = 1;
7329 return true;
7330 }
7331 }
7332
7333 if (getClientVersion() < Version(3, 1))
7334 {
7335 return false;
7336 }
7337
7338 switch (target)
7339 {
7340 case GL_IMAGE_BINDING_LAYERED:
7341 {
7342 *type = GL_BOOL;
7343 *numParams = 1;
7344 return true;
7345 }
7346 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7347 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7348 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7349 case GL_SHADER_STORAGE_BUFFER_BINDING:
7350 case GL_VERTEX_BINDING_BUFFER:
7351 case GL_VERTEX_BINDING_DIVISOR:
7352 case GL_VERTEX_BINDING_OFFSET:
7353 case GL_VERTEX_BINDING_STRIDE:
7354 case GL_SAMPLE_MASK_VALUE:
7355 case GL_IMAGE_BINDING_NAME:
7356 case GL_IMAGE_BINDING_LEVEL:
7357 case GL_IMAGE_BINDING_LAYER:
7358 case GL_IMAGE_BINDING_ACCESS:
7359 case GL_IMAGE_BINDING_FORMAT:
7360 {
7361 *type = GL_INT;
7362 *numParams = 1;
7363 return true;
7364 }
7365 case GL_ATOMIC_COUNTER_BUFFER_START:
7366 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
7367 case GL_SHADER_STORAGE_BUFFER_START:
7368 case GL_SHADER_STORAGE_BUFFER_SIZE:
7369 {
7370 *type = GL_INT_64_ANGLEX;
7371 *numParams = 1;
7372 return true;
7373 }
7374 }
7375
7376 return false;
7377}
7378
7379Program *Context::getProgram(GLuint handle) const
7380{
7381 return mState.mShaderPrograms->getProgram(handle);
7382}
7383
7384Shader *Context::getShader(GLuint handle) const
7385{
7386 return mState.mShaderPrograms->getShader(handle);
7387}
7388
7389bool Context::isTextureGenerated(GLuint texture) const
7390{
7391 return mState.mTextures->isHandleGenerated(texture);
7392}
7393
7394bool Context::isBufferGenerated(GLuint buffer) const
7395{
7396 return mState.mBuffers->isHandleGenerated(buffer);
7397}
7398
7399bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
7400{
7401 return mState.mRenderbuffers->isHandleGenerated(renderbuffer);
7402}
7403
7404bool Context::isFramebufferGenerated(GLuint framebuffer) const
7405{
7406 return mState.mFramebuffers->isHandleGenerated(framebuffer);
7407}
7408
7409bool Context::isProgramPipelineGenerated(GLuint pipeline) const
7410{
7411 return mState.mPipelines->isHandleGenerated(pipeline);
7412}
7413
7414bool Context::usingDisplayTextureShareGroup() const
7415{
7416 return mDisplayTextureShareGroup;
7417}
7418
7419GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
7420{
7421 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
7422 internalformat == GL_DEPTH_STENCIL
7423 ? GL_DEPTH24_STENCIL8
7424 : internalformat;
7425}
7426
Jamie Madillc29968b2016-01-20 11:17:23 -05007427} // namespace gl