blob: 10abb77e4a978ee74573714db12f420ca8a7dc7a [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"
Markus Tavenrathcb9609f2018-12-26 00:52:44 +090011#include "libANGLE/Context.inl.h"
apatrick@chromium.org144f2802012-07-12 01:42:34 +000012
Jamie Madill231c7f52017-04-26 13:45:37 -040013#include <string.h>
Jamie Madillb9293972015-02-19 11:07:54 -050014#include <iterator>
15#include <sstream>
Sami Väisänend59ca052016-06-21 16:10:00 +030016#include <vector>
Jamie Madillb9293972015-02-19 11:07:54 -050017
Tobin Ehlisd7890bc2018-06-29 11:57:22 -060018#include "common/PackedEnums.h"
Sami Väisänene45e53b2016-05-25 10:36:04 +030019#include "common/matrix_utils.h"
Geoff Lang0b7eef72014-06-12 14:10:47 -040020#include "common/platform.h"
Jamie Madillb9293972015-02-19 11:07:54 -050021#include "common/utilities.h"
Geoff Langc339c4e2016-11-29 10:37:36 -050022#include "common/version.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050023#include "libANGLE/Buffer.h"
Jamie Madillb9293972015-02-19 11:07:54 -050024#include "libANGLE/Compiler.h"
Jamie Madill948bbe52017-06-01 13:10:42 -040025#include "libANGLE/Display.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050026#include "libANGLE/Fence.h"
27#include "libANGLE/Framebuffer.h"
28#include "libANGLE/FramebufferAttachment.h"
Sami Väisänene45e53b2016-05-25 10:36:04 +030029#include "libANGLE/Path.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050030#include "libANGLE/Program.h"
Yunchao Hea336b902017-08-02 16:05:21 +080031#include "libANGLE/ProgramPipeline.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050032#include "libANGLE/Query.h"
Jamie Madillb9293972015-02-19 11:07:54 -050033#include "libANGLE/Renderbuffer.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050034#include "libANGLE/ResourceManager.h"
35#include "libANGLE/Sampler.h"
Jamie Madill9dd0cf02014-11-24 11:38:51 -050036#include "libANGLE/Surface.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050037#include "libANGLE/Texture.h"
38#include "libANGLE/TransformFeedback.h"
39#include "libANGLE/VertexArray.h"
Kenneth Russellf2f6f652016-10-05 19:53:23 -070040#include "libANGLE/Workarounds.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040041#include "libANGLE/formatutils.h"
Martin Radev66fb8202016-07-28 11:45:20 +030042#include "libANGLE/queryconversions.h"
Geoff Langc1984ed2016-10-07 12:41:00 -040043#include "libANGLE/queryutils.h"
Jamie Madill6d32cef2018-08-14 02:34:28 -040044#include "libANGLE/renderer/BufferImpl.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040045#include "libANGLE/renderer/EGLImplFactory.h"
Jamie Madill7b62cf92017-11-02 15:20:49 -040046#include "libANGLE/renderer/Format.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040047#include "libANGLE/validationES.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000048
Jamie Madill752d2202018-11-27 13:29:48 -050049namespace gl
50{
Geoff Langf6db0982015-08-25 13:04:00 -040051namespace
52{
Ian Ewell3ffd78b2016-01-22 16:09:42 -050053template <typename T>
Jamie Madill752d2202018-11-27 13:29:48 -050054std::vector<Path *> GatherPaths(PathManager &resourceManager,
55 GLsizei numPaths,
56 const void *paths,
57 GLuint pathBase)
Sami Väisänend59ca052016-06-21 16:10:00 +030058{
Jamie Madill752d2202018-11-27 13:29:48 -050059 std::vector<Path *> ret;
Sami Väisänend59ca052016-06-21 16:10:00 +030060 ret.reserve(numPaths);
61
62 const auto *nameArray = static_cast<const T *>(paths);
63
64 for (GLsizei i = 0; i < numPaths; ++i)
65 {
66 const GLuint pathName = nameArray[i] + pathBase;
67
68 ret.push_back(resourceManager.getPath(pathName));
69 }
70
71 return ret;
72}
73
Jamie Madill752d2202018-11-27 13:29:48 -050074std::vector<Path *> GatherPaths(PathManager &resourceManager,
75 GLsizei numPaths,
76 GLenum pathNameType,
77 const void *paths,
78 GLuint pathBase)
Sami Väisänend59ca052016-06-21 16:10:00 +030079{
80 switch (pathNameType)
81 {
82 case GL_UNSIGNED_BYTE:
83 return GatherPaths<GLubyte>(resourceManager, numPaths, paths, pathBase);
84
85 case GL_BYTE:
86 return GatherPaths<GLbyte>(resourceManager, numPaths, paths, pathBase);
87
88 case GL_UNSIGNED_SHORT:
89 return GatherPaths<GLushort>(resourceManager, numPaths, paths, pathBase);
90
91 case GL_SHORT:
92 return GatherPaths<GLshort>(resourceManager, numPaths, paths, pathBase);
93
94 case GL_UNSIGNED_INT:
95 return GatherPaths<GLuint>(resourceManager, numPaths, paths, pathBase);
96
97 case GL_INT:
98 return GatherPaths<GLint>(resourceManager, numPaths, paths, pathBase);
99 }
100
101 UNREACHABLE();
Jamie Madill752d2202018-11-27 13:29:48 -0500102 return std::vector<Path *>();
Sami Väisänend59ca052016-06-21 16:10:00 +0300103}
104
105template <typename T>
Jamie Madill752d2202018-11-27 13:29:48 -0500106angle::Result GetQueryObjectParameter(const Context *context, Query *query, GLenum pname, T *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500107{
Geoff Lang2186c382016-10-14 10:54:54 -0400108 ASSERT(query != nullptr);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500109
110 switch (pname)
111 {
112 case GL_QUERY_RESULT_EXT:
Jamie Madill5188a272018-07-25 10:53:56 -0400113 return query->getResult(context, params);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500114 case GL_QUERY_RESULT_AVAILABLE_EXT:
115 {
116 bool available;
Jamie Madill666818e2018-11-14 09:54:33 -0500117 ANGLE_TRY(query->isResultAvailable(context, &available));
Jamie Madill752d2202018-11-27 13:29:48 -0500118 *params = CastFromStateValue<T>(pname, static_cast<GLuint>(available));
Jamie Madill7c985f52018-11-29 18:16:17 -0500119 return angle::Result::Continue;
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500120 }
121 default:
122 UNREACHABLE();
Jamie Madill7c985f52018-11-29 18:16:17 -0500123 return angle::Result::Stop;
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500124 }
125}
126
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500127// Attribute map queries.
Martin Radev1be913c2016-07-11 17:59:16 +0300128EGLint GetClientMajorVersion(const egl::AttributeMap &attribs)
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500129{
Ian Ewellec2c0c52016-04-05 13:46:26 -0400130 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_CLIENT_VERSION, 1));
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500131}
132
Martin Radev1be913c2016-07-11 17:59:16 +0300133EGLint GetClientMinorVersion(const egl::AttributeMap &attribs)
134{
135 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_MINOR_VERSION, 0));
136}
137
Jamie Madill752d2202018-11-27 13:29:48 -0500138Version GetClientVersion(const egl::AttributeMap &attribs)
Geoff Langeb66a6e2016-10-31 13:06:12 -0400139{
Jamie Madill752d2202018-11-27 13:29:48 -0500140 return Version(GetClientMajorVersion(attribs), GetClientMinorVersion(attribs));
Geoff Langeb66a6e2016-10-31 13:06:12 -0400141}
142
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500143GLenum GetResetStrategy(const egl::AttributeMap &attribs)
144{
Lingfeng Yangb27b03a2018-02-19 13:38:48 -0800145 EGLAttrib attrib =
146 attribs.get(EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT, EGL_NO_RESET_NOTIFICATION);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500147 switch (attrib)
148 {
149 case EGL_NO_RESET_NOTIFICATION:
150 return GL_NO_RESET_NOTIFICATION_EXT;
151 case EGL_LOSE_CONTEXT_ON_RESET:
152 return GL_LOSE_CONTEXT_ON_RESET_EXT;
153 default:
154 UNREACHABLE();
155 return GL_NONE;
156 }
157}
158
159bool GetRobustAccess(const egl::AttributeMap &attribs)
160{
Geoff Lang077f20a2016-11-01 10:08:02 -0400161 return (attribs.get(EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT, EGL_FALSE) == EGL_TRUE) ||
162 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR) !=
163 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500164}
165
166bool GetDebug(const egl::AttributeMap &attribs)
167{
Geoff Lang077f20a2016-11-01 10:08:02 -0400168 return (attribs.get(EGL_CONTEXT_OPENGL_DEBUG, EGL_FALSE) == EGL_TRUE) ||
169 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR) != 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500170}
171
172bool GetNoError(const egl::AttributeMap &attribs)
173{
174 return (attribs.get(EGL_CONTEXT_OPENGL_NO_ERROR_KHR, EGL_FALSE) == EGL_TRUE);
175}
176
Geoff Langc287ea62016-09-16 14:46:51 -0400177bool GetWebGLContext(const egl::AttributeMap &attribs)
178{
Jamie Madill4230d482018-09-14 10:14:45 -0400179 return (attribs.get(EGL_CONTEXT_WEBGL_COMPATIBILITY_ANGLE, EGL_FALSE) == EGL_TRUE);
Geoff Langc287ea62016-09-16 14:46:51 -0400180}
181
Geoff Lang0ab41fa2018-03-14 11:03:30 -0400182bool GetExtensionsEnabled(const egl::AttributeMap &attribs, bool webGLContext)
183{
184 // If the context is WebGL, extensions are disabled by default
185 EGLAttrib defaultValue = webGLContext ? EGL_FALSE : EGL_TRUE;
186 return (attribs.get(EGL_EXTENSIONS_ENABLED_ANGLE, defaultValue) == EGL_TRUE);
187}
188
Geoff Langf41a7152016-09-19 15:11:17 -0400189bool GetBindGeneratesResource(const egl::AttributeMap &attribs)
190{
Jamie Madill4230d482018-09-14 10:14:45 -0400191 return (attribs.get(EGL_CONTEXT_BIND_GENERATES_RESOURCE_CHROMIUM, EGL_TRUE) == EGL_TRUE);
Geoff Langf41a7152016-09-19 15:11:17 -0400192}
193
Geoff Langfeb8c682017-02-13 16:07:35 -0500194bool GetClientArraysEnabled(const egl::AttributeMap &attribs)
195{
196 return (attribs.get(EGL_CONTEXT_CLIENT_ARRAYS_ENABLED_ANGLE, EGL_TRUE) == EGL_TRUE);
197}
198
Geoff Langb433e872017-10-05 14:01:47 -0400199bool GetRobustResourceInit(const egl::AttributeMap &attribs)
200{
201 return (attribs.get(EGL_ROBUST_RESOURCE_INITIALIZATION_ANGLE, EGL_FALSE) == EGL_TRUE);
202}
203
Martin Radev9d901792016-07-15 15:58:58 +0300204std::string GetObjectLabelFromPointer(GLsizei length, const GLchar *label)
205{
206 std::string labelName;
207 if (label != nullptr)
208 {
209 size_t labelLength = length < 0 ? strlen(label) : length;
210 labelName = std::string(label, labelLength);
211 }
212 return labelName;
213}
214
215void GetObjectLabelBase(const std::string &objectLabel,
216 GLsizei bufSize,
217 GLsizei *length,
218 GLchar *label)
219{
220 size_t writeLength = objectLabel.length();
221 if (label != nullptr && bufSize > 0)
222 {
223 writeLength = std::min(static_cast<size_t>(bufSize) - 1, objectLabel.length());
224 std::copy(objectLabel.begin(), objectLabel.begin() + writeLength, label);
225 label[writeLength] = '\0';
226 }
227
228 if (length != nullptr)
229 {
230 *length = static_cast<GLsizei>(writeLength);
231 }
232}
233
Jamie Madill0f80ed82017-09-19 00:24:56 -0400234template <typename CapT, typename MaxT>
235void LimitCap(CapT *cap, MaxT maximum)
236{
237 *cap = std::min(*cap, static_cast<CapT>(maximum));
238}
239
Jamie Madill752d2202018-11-27 13:29:48 -0500240// The rest default to false.
241constexpr angle::PackedEnumMap<PrimitiveMode, bool, angle::EnumSize<PrimitiveMode>() + 1>
242 kValidBasicDrawModes = {{
243 {PrimitiveMode::Points, true},
244 {PrimitiveMode::Lines, true},
245 {PrimitiveMode::LineLoop, true},
246 {PrimitiveMode::LineStrip, true},
247 {PrimitiveMode::Triangles, true},
248 {PrimitiveMode::TriangleStrip, true},
249 {PrimitiveMode::TriangleFan, true},
250 }};
Tobin Ehlisd7890bc2018-06-29 11:57:22 -0600251
Jamie Madill6d32cef2018-08-14 02:34:28 -0400252enum SubjectIndexes : angle::SubjectIndex
253{
254 kTexture0SubjectIndex = 0,
Jamie Madille3e680c2018-12-03 17:49:08 -0500255 kTextureMaxSubjectIndex = kTexture0SubjectIndex + IMPLEMENTATION_MAX_ACTIVE_TEXTURES,
Qin Jiajia3f01f532018-12-11 15:13:51 +0800256 kUniformBuffer0SubjectIndex = kTextureMaxSubjectIndex,
Jamie Madill6d32cef2018-08-14 02:34:28 -0400257 kUniformBufferMaxSubjectIndex =
Jamie Madille3e680c2018-12-03 17:49:08 -0500258 kUniformBuffer0SubjectIndex + IMPLEMENTATION_MAX_UNIFORM_BUFFER_BINDINGS,
Jamie Madille25b8002018-09-20 13:39:49 -0400259 kSampler0SubjectIndex = kUniformBufferMaxSubjectIndex,
Jamie Madille3e680c2018-12-03 17:49:08 -0500260 kSamplerMaxSubjectIndex = kSampler0SubjectIndex + IMPLEMENTATION_MAX_ACTIVE_TEXTURES,
Jamie Madille25b8002018-09-20 13:39:49 -0400261 kVertexArraySubjectIndex = kSamplerMaxSubjectIndex,
Jamie Madill6d32cef2018-08-14 02:34:28 -0400262 kReadFramebufferSubjectIndex,
263 kDrawFramebufferSubjectIndex
264};
Geoff Langf6db0982015-08-25 13:04:00 -0400265} // anonymous namespace
266
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400267Context::Context(rx::EGLImplFactory *implFactory,
268 const egl::Config *config,
Corentin Wallez51706ea2015-08-07 14:39:22 -0400269 const Context *shareContext,
Geoff Langce02f082017-02-06 16:46:21 -0500270 TextureManager *shareTextures,
Jamie Madill32447362017-06-28 14:53:52 -0400271 MemoryProgramCache *memoryProgramCache,
Corentin Wallezc295e512017-01-27 17:47:50 -0500272 const egl::AttributeMap &attribs,
Brandon Jones2b0cdcc2018-05-02 08:02:50 -0700273 const egl::DisplayExtensions &displayExtensions,
274 const egl::ClientExtensions &clientExtensions)
Jamie Madill5b772312018-03-08 20:28:32 -0500275 : mState(reinterpret_cast<ContextID>(this),
276 shareContext ? &shareContext->mState : nullptr,
277 shareTextures,
278 GetClientVersion(attribs),
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500279 GetDebug(attribs),
280 GetBindGeneratesResource(attribs),
281 GetClientArraysEnabled(attribs),
282 GetRobustResourceInit(attribs),
283 memoryProgramCache != nullptr),
Jamie Madill5b772312018-03-08 20:28:32 -0500284 mSkipValidation(GetNoError(attribs)),
285 mDisplayTextureShareGroup(shareTextures != nullptr),
Jamie Madill0c667212019-01-01 14:40:36 -0500286 mErrors(this),
287 mImplementation(implFactory->createContext(mState, &mErrors, config, shareContext, attribs)),
Geoff Lang75359662018-04-11 01:42:27 -0400288 mLabel(nullptr),
Jamie Madill2f348d22017-06-05 10:50:59 -0400289 mCompiler(),
Corentin Walleze3b10e82015-05-20 11:06:25 -0400290 mConfig(config),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500291 mClientType(EGL_OPENGL_ES_API),
292 mHasBeenCurrent(false),
293 mContextLost(false),
294 mResetStatus(GL_NO_ERROR),
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700295 mContextLostForced(false),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500296 mResetStrategy(GetResetStrategy(attribs)),
297 mRobustAccess(GetRobustAccess(attribs)),
Geoff Lang33f11fb2018-05-07 13:42:47 -0400298 mSurfacelessSupported(displayExtensions.surfacelessContext),
299 mExplicitContextAvailable(clientExtensions.explicitContext),
Jamie Madill61e16b42017-06-19 11:13:23 -0400300 mCurrentSurface(static_cast<egl::Surface *>(EGL_NO_SURFACE)),
301 mCurrentDisplay(static_cast<egl::Display *>(EGL_NO_DISPLAY)),
Jamie Madille14951e2017-03-09 18:55:16 -0500302 mWebGLContext(GetWebGLContext(attribs)),
Jamie Madilld51fbe32019-01-25 15:03:39 -0500303 mBufferAccessValidationEnabled(false),
Geoff Lang0ab41fa2018-03-14 11:03:30 -0400304 mExtensionsEnabled(GetExtensionsEnabled(attribs, mWebGLContext)),
Jamie Madill32447362017-06-28 14:53:52 -0400305 mMemoryProgramCache(memoryProgramCache),
Jamie Madilla11819d2018-07-30 10:26:01 -0400306 mVertexArrayObserverBinding(this, kVertexArraySubjectIndex),
307 mDrawFramebufferObserverBinding(this, kDrawFramebufferSubjectIndex),
308 mReadFramebufferObserverBinding(this, kReadFramebufferSubjectIndex),
Jamie Madillb3f26b92017-07-19 15:07:41 -0400309 mScratchBuffer(1000u),
jchen107ae70d82018-07-06 13:47:01 +0800310 mZeroFilledBuffer(1000u),
311 mThreadPool(nullptr)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000312{
Jamie Madill6d32cef2018-08-14 02:34:28 -0400313 for (angle::SubjectIndex uboIndex = kUniformBuffer0SubjectIndex;
314 uboIndex < kUniformBufferMaxSubjectIndex; ++uboIndex)
315 {
316 mUniformBufferObserverBindings.emplace_back(this, uboIndex);
317 }
Jamie Madille25b8002018-09-20 13:39:49 -0400318
319 for (angle::SubjectIndex samplerIndex = kSampler0SubjectIndex;
320 samplerIndex < kSamplerMaxSubjectIndex; ++samplerIndex)
321 {
322 mSamplerObserverBindings.emplace_back(this, samplerIndex);
323 }
Geoff Lang33f11fb2018-05-07 13:42:47 -0400324}
Jamie Madill5b772312018-03-08 20:28:32 -0500325
Geoff Lang33f11fb2018-05-07 13:42:47 -0400326void Context::initialize()
327{
328 mImplementation->setMemoryProgramCache(mMemoryProgramCache);
Jamie Madill14bbb3f2017-09-12 15:23:01 -0400329
Geoff Lang33f11fb2018-05-07 13:42:47 -0400330 initCaps();
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700331 initWorkarounds();
Geoff Langc0b9ef42014-07-02 10:02:37 -0400332
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500333 mState.initialize(this);
Régis Fénéon83107972015-02-05 12:57:44 +0100334
Shannon Woods53a94a82014-06-24 15:20:36 -0400335 mFenceNVHandleAllocator.setBaseHandle(0);
Geoff Lang7dca1862013-07-30 16:30:46 -0400336
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000337 // [OpenGL ES 2.0.24] section 3.7 page 83:
Corentin Wallez336129f2017-10-17 15:55:40 -0400338 // In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have two-dimensional
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000339 // and cube map texture state vectors respectively associated with them.
340 // In order that access to these initial textures not be lost, they are treated as texture
341 // objects all of whose names are 0.
342
Corentin Wallez99d492c2018-02-27 15:17:10 -0500343 Texture *zeroTexture2D = new Texture(mImplementation.get(), 0, TextureType::_2D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800344 mZeroTextures[TextureType::_2D].set(this, zeroTexture2D);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500345
Corentin Wallez99d492c2018-02-27 15:17:10 -0500346 Texture *zeroTextureCube = new Texture(mImplementation.get(), 0, TextureType::CubeMap);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800347 mZeroTextures[TextureType::CubeMap].set(this, zeroTextureCube);
Geoff Lang76b10c92014-09-05 16:28:14 -0400348
Geoff Langeb66a6e2016-10-31 13:06:12 -0400349 if (getClientVersion() >= Version(3, 0))
Geoff Lang76b10c92014-09-05 16:28:14 -0400350 {
351 // TODO: These could also be enabled via extension
Corentin Wallez99d492c2018-02-27 15:17:10 -0500352 Texture *zeroTexture3D = new Texture(mImplementation.get(), 0, TextureType::_3D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800353 mZeroTextures[TextureType::_3D].set(this, zeroTexture3D);
Geoff Lang76b10c92014-09-05 16:28:14 -0400354
Corentin Wallez99d492c2018-02-27 15:17:10 -0500355 Texture *zeroTexture2DArray = new Texture(mImplementation.get(), 0, TextureType::_2DArray);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800356 mZeroTextures[TextureType::_2DArray].set(this, zeroTexture2DArray);
Geoff Lang76b10c92014-09-05 16:28:14 -0400357 }
Yizhou Jiang7818a852018-09-06 15:02:04 +0800358 if (getClientVersion() >= Version(3, 1) || mSupportedExtensions.textureMultisample)
Geoff Lang3b573612016-10-31 14:08:10 -0400359 {
360 Texture *zeroTexture2DMultisample =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500361 new Texture(mImplementation.get(), 0, TextureType::_2DMultisample);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800362 mZeroTextures[TextureType::_2DMultisample].set(this, zeroTexture2DMultisample);
Yizhou Jiang7818a852018-09-06 15:02:04 +0800363 }
364 if (getClientVersion() >= Version(3, 1))
365 {
Olli Etuahod310a432018-08-24 15:40:23 +0300366 Texture *zeroTexture2DMultisampleArray =
367 new Texture(mImplementation.get(), 0, TextureType::_2DMultisampleArray);
368 mZeroTextures[TextureType::_2DMultisampleArray].set(this, zeroTexture2DMultisampleArray);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800369
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500370 for (unsigned int i = 0; i < mState.mCaps.maxAtomicCounterBufferBindings; i++)
Jiajia Qin6eafb042016-12-27 17:04:07 +0800371 {
Qin Jiajia339f65b2018-02-27 12:52:48 +0800372 bindBufferRange(BufferBinding::AtomicCounter, i, 0, 0, 0);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800373 }
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800374
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500375 for (unsigned int i = 0; i < mState.mCaps.maxShaderStorageBufferBindings; i++)
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800376 {
Corentin Wallez336129f2017-10-17 15:55:40 -0400377 bindBufferRange(BufferBinding::ShaderStorage, i, 0, 0, 0);
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800378 }
Geoff Lang3b573612016-10-31 14:08:10 -0400379 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000380
Geoff Langb0f917f2017-12-05 13:41:54 -0500381 if (mSupportedExtensions.textureRectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400382 {
383 Texture *zeroTextureRectangle =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500384 new Texture(mImplementation.get(), 0, TextureType::Rectangle);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800385 mZeroTextures[TextureType::Rectangle].set(this, zeroTextureRectangle);
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400386 }
387
Geoff Langb0f917f2017-12-05 13:41:54 -0500388 if (mSupportedExtensions.eglImageExternal || mSupportedExtensions.eglStreamConsumerExternal)
Ian Ewellbda75592016-04-18 17:25:54 -0400389 {
Corentin Wallez99d492c2018-02-27 15:17:10 -0500390 Texture *zeroTextureExternal = new Texture(mImplementation.get(), 0, TextureType::External);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800391 mZeroTextures[TextureType::External].set(this, zeroTextureExternal);
Ian Ewellbda75592016-04-18 17:25:54 -0400392 }
393
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500394 mState.initializeZeroTextures(this, mZeroTextures);
Jamie Madille6382c32014-11-07 15:05:26 -0500395
Jamie Madill57a89722013-07-02 11:57:03 -0400396 bindVertexArray(0);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000397
Geoff Langeb66a6e2016-10-31 13:06:12 -0400398 if (getClientVersion() >= Version(3, 0))
Geoff Lang1a683462015-09-29 15:09:59 -0400399 {
400 // [OpenGL ES 3.0.2] section 2.14.1 pg 85:
401 // In the initial state, a default transform feedback object is bound and treated as
402 // a transform feedback object with a name of zero. That object is bound any time
403 // BindTransformFeedback is called with id of zero
Jamie Madillf0dcb8b2017-08-26 19:05:13 -0400404 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Geoff Lang1a683462015-09-29 15:09:59 -0400405 }
Geoff Langc8058452014-02-03 12:04:11 -0500406
Corentin Wallez336129f2017-10-17 15:55:40 -0400407 for (auto type : angle::AllEnums<BufferBinding>())
408 {
409 bindBuffer(type, 0);
410 }
411
412 bindRenderbuffer(GL_RENDERBUFFER, 0);
413
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500414 for (unsigned int i = 0; i < mState.mCaps.maxUniformBufferBindings; i++)
Corentin Wallez336129f2017-10-17 15:55:40 -0400415 {
416 bindBufferRange(BufferBinding::Uniform, i, 0, 0, -1);
417 }
418
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700419 // Initialize GLES1 renderer if appropriate.
420 if (getClientVersion() < Version(2, 0))
421 {
422 mGLES1Renderer.reset(new GLES1Renderer());
423 }
424
Jamie Madillad9f24e2016-02-12 09:27:24 -0500425 // Initialize dirty bit masks
Jamie Madill9d0bb3d2018-10-09 20:29:13 -0400426 mAllDirtyBits.set();
427
Geoff Lang9bf86f02018-07-26 11:46:34 -0400428 mDrawDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
429 mDrawDirtyObjects.set(State::DIRTY_OBJECT_VERTEX_ARRAY);
Jamie Madille3e680c2018-12-03 17:49:08 -0500430 mDrawDirtyObjects.set(State::DIRTY_OBJECT_TEXTURES);
Jamie Madill70aeda42018-08-20 12:17:40 -0400431 mDrawDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM);
Jamie Madille25b8002018-09-20 13:39:49 -0400432 mDrawDirtyObjects.set(State::DIRTY_OBJECT_SAMPLERS);
Geoff Lang9bf86f02018-07-26 11:46:34 -0400433
434 mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
435 mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_VERTEX_ARRAY);
Jamie Madille3e680c2018-12-03 17:49:08 -0500436 mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_TEXTURES);
Jamie Madille25b8002018-09-20 13:39:49 -0400437 mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_SAMPLERS);
Geoff Lang9bf86f02018-07-26 11:46:34 -0400438
Jamie Madillc67323a2017-11-02 23:11:41 -0400439 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500440 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500441 // No dirty objects.
442
443 // Readpixels uses the pack state and read FBO
Jamie Madillc67323a2017-11-02 23:11:41 -0400444 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500445 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_BUFFER_BINDING);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400446 mReadPixelsDirtyBits.set(State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500447 mReadPixelsDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
448
449 mClearDirtyBits.set(State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED);
450 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
451 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR);
452 mClearDirtyBits.set(State::DIRTY_BIT_VIEWPORT);
453 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_COLOR);
454 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_DEPTH);
455 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_STENCIL);
456 mClearDirtyBits.set(State::DIRTY_BIT_COLOR_MASK);
457 mClearDirtyBits.set(State::DIRTY_BIT_DEPTH_MASK);
458 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT);
459 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_BACK);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400460 mClearDirtyBits.set(State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500461 mClearDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
462
463 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
464 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR);
Geoff Lang1d2c41d2016-10-19 16:14:46 -0700465 mBlitDirtyBits.set(State::DIRTY_BIT_FRAMEBUFFER_SRGB);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400466 mBlitDirtyBits.set(State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
467 mBlitDirtyBits.set(State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500468 mBlitDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
469 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
Jamie Madill437fa652016-05-03 15:13:24 -0400470
Xinghua Cao10a4d432017-11-28 14:46:26 +0800471 mComputeDirtyBits.set(State::DIRTY_BIT_SHADER_STORAGE_BUFFER_BINDING);
jchen1099118c12018-09-10 16:28:51 +0800472 mComputeDirtyBits.set(State::DIRTY_BIT_UNIFORM_BUFFER_BINDINGS);
473 mComputeDirtyBits.set(State::DIRTY_BIT_ATOMIC_COUNTER_BUFFER_BINDING);
Xinghua Cao10a4d432017-11-28 14:46:26 +0800474 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_BINDING);
475 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_EXECUTABLE);
476 mComputeDirtyBits.set(State::DIRTY_BIT_TEXTURE_BINDINGS);
477 mComputeDirtyBits.set(State::DIRTY_BIT_SAMPLER_BINDINGS);
jchen1099118c12018-09-10 16:28:51 +0800478 mComputeDirtyBits.set(State::DIRTY_BIT_IMAGE_BINDINGS);
Qin Jiajia62fcf622017-11-30 16:16:12 +0800479 mComputeDirtyBits.set(State::DIRTY_BIT_DISPATCH_INDIRECT_BUFFER_BINDING);
Jamie Madille3e680c2018-12-03 17:49:08 -0500480 mComputeDirtyObjects.set(State::DIRTY_OBJECT_TEXTURES);
Jamie Madill70aeda42018-08-20 12:17:40 -0400481 mComputeDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM);
Jamie Madille25b8002018-09-20 13:39:49 -0400482 mComputeDirtyObjects.set(State::DIRTY_OBJECT_SAMPLERS);
Xinghua Cao10a4d432017-11-28 14:46:26 +0800483
Jamie Madill4f6592f2018-11-27 16:37:45 -0500484 ANGLE_CONTEXT_TRY(mImplementation->initialize());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000485}
486
Jamie Madill4928b7c2017-06-20 12:57:39 -0400487egl::Error Context::onDestroy(const egl::Display *display)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000488{
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700489 if (mGLES1Renderer)
490 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500491 mGLES1Renderer->onDestroy(this, &mState);
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700492 }
493
Jamie Madille7b3fe22018-04-05 09:42:46 -0400494 ANGLE_TRY(releaseSurface(display));
495
Corentin Wallez80b24112015-08-25 16:41:57 -0400496 for (auto fence : mFenceNVMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000497 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400498 SafeDelete(fence.second);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000499 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400500 mFenceNVMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000501
Corentin Wallez80b24112015-08-25 16:41:57 -0400502 for (auto query : mQueryMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000503 {
Geoff Langf0aa8422015-09-29 15:08:34 -0400504 if (query.second != nullptr)
505 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400506 query.second->release(this);
Geoff Langf0aa8422015-09-29 15:08:34 -0400507 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000508 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400509 mQueryMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000510
Corentin Wallez80b24112015-08-25 16:41:57 -0400511 for (auto vertexArray : mVertexArrayMap)
Jamie Madill57a89722013-07-02 11:57:03 -0400512 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400513 if (vertexArray.second)
514 {
515 vertexArray.second->onDestroy(this);
516 }
Jamie Madill57a89722013-07-02 11:57:03 -0400517 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400518 mVertexArrayMap.clear();
Jamie Madill57a89722013-07-02 11:57:03 -0400519
Corentin Wallez80b24112015-08-25 16:41:57 -0400520 for (auto transformFeedback : mTransformFeedbackMap)
Geoff Langc8058452014-02-03 12:04:11 -0500521 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500522 if (transformFeedback.second != nullptr)
523 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500524 transformFeedback.second->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500525 }
Geoff Langc8058452014-02-03 12:04:11 -0500526 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400527 mTransformFeedbackMap.clear();
Geoff Langc8058452014-02-03 12:04:11 -0500528
Jamie Madill5b772312018-03-08 20:28:32 -0500529 for (BindingPointer<Texture> &zeroTexture : mZeroTextures)
Geoff Lang76b10c92014-09-05 16:28:14 -0400530 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800531 if (zeroTexture.get() != nullptr)
532 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800533 zeroTexture.set(this, nullptr);
534 }
Geoff Lang76b10c92014-09-05 16:28:14 -0400535 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000536
Jamie Madill2f348d22017-06-05 10:50:59 -0400537 releaseShaderCompiler();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500538
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500539 mState.reset(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400540
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500541 mState.mBufferManager->release(this);
542 mState.mShaderProgramManager->release(this);
543 mState.mTextureManager->release(this);
544 mState.mRenderbufferManager->release(this);
545 mState.mSamplerManager->release(this);
546 mState.mSyncManager->release(this);
547 mState.mPathManager->release(this);
548 mState.mFramebufferManager->release(this);
549 mState.mProgramPipelineManager->release(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400550
jchen107ae70d82018-07-06 13:47:01 +0800551 mThreadPool.reset();
552
Jamie Madill76e471e2017-10-21 09:56:01 -0400553 mImplementation->onDestroy(this);
554
Jamie Madill4928b7c2017-06-20 12:57:39 -0400555 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000556}
557
Jamie Madillb980c562018-11-27 11:34:27 -0500558Context::~Context() {}
Jamie Madill70ee0f62017-02-06 16:04:20 -0500559
Geoff Lang75359662018-04-11 01:42:27 -0400560void Context::setLabel(EGLLabelKHR label)
561{
562 mLabel = label;
563}
564
565EGLLabelKHR Context::getLabel() const
566{
567 return mLabel;
568}
569
Jamie Madill4928b7c2017-06-20 12:57:39 -0400570egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000571{
Jamie Madill61e16b42017-06-19 11:13:23 -0400572 mCurrentDisplay = display;
573
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000574 if (!mHasBeenCurrent)
575 {
Geoff Lang33f11fb2018-05-07 13:42:47 -0400576 initialize();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000577 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500578 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400579 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000580
Corentin Wallezc295e512017-01-27 17:47:50 -0500581 int width = 0;
582 int height = 0;
583 if (surface != nullptr)
584 {
585 width = surface->getWidth();
586 height = surface->getHeight();
587 }
588
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500589 mState.setViewportParams(0, 0, width, height);
590 mState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000591
592 mHasBeenCurrent = true;
593 }
594
Jamie Madill1b94d432015-08-07 13:23:23 -0400595 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500596 mState.setAllDirtyBits();
597 mState.setAllDirtyObjects();
Jamie Madill1b94d432015-08-07 13:23:23 -0400598
Jamie Madill4928b7c2017-06-20 12:57:39 -0400599 ANGLE_TRY(releaseSurface(display));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500600
601 Framebuffer *newDefault = nullptr;
602 if (surface != nullptr)
603 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400604 ANGLE_TRY(surface->setIsCurrent(this, true));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500605 mCurrentSurface = surface;
Geoff Langbf7b95d2018-05-01 16:48:21 -0400606 newDefault = surface->createDefaultFramebuffer(this);
Corentin Wallezccab69d2017-01-27 16:57:15 -0500607 }
608 else
609 {
Geoff Langbf7b95d2018-05-01 16:48:21 -0400610 newDefault = new Framebuffer(mImplementation.get());
Corentin Wallezccab69d2017-01-27 16:57:15 -0500611 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000612
Corentin Wallez37c39792015-08-20 14:19:46 -0400613 // Update default framebuffer, the binding of the previous default
614 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400615 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500616 mState.mFramebufferManager->setDefaultFramebuffer(newDefault);
617 if (mState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400618 {
Jamie Madilla11819d2018-07-30 10:26:01 -0400619 bindReadFramebuffer(0);
Corentin Wallez37c39792015-08-20 14:19:46 -0400620 }
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500621 if (mState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400622 {
Jamie Madilla11819d2018-07-30 10:26:01 -0400623 bindDrawFramebuffer(0);
Corentin Wallez37c39792015-08-20 14:19:46 -0400624 }
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400625 }
Ian Ewell292f0052016-02-04 10:37:32 -0500626
Jamie Madill32643ce2018-10-19 11:38:03 -0400627 // Notify the renderer of a context switch.
Jamie Madill7c985f52018-11-29 18:16:17 -0500628 return angle::ResultToEGL(mImplementation->onMakeCurrent(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000629}
630
Jamie Madill4928b7c2017-06-20 12:57:39 -0400631egl::Error Context::releaseSurface(const egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400632{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500633 gl::Framebuffer *defaultFramebuffer = mState.mFramebufferManager->getFramebuffer(0);
Corentin Wallez51706ea2015-08-07 14:39:22 -0400634
Geoff Langbf7b95d2018-05-01 16:48:21 -0400635 // Remove the default framebuffer
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500636 if (mState.getReadFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500637 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500638 mState.setReadFramebufferBinding(nullptr);
Jamie Madilla11819d2018-07-30 10:26:01 -0400639 mReadFramebufferObserverBinding.bind(nullptr);
Corentin Wallezc295e512017-01-27 17:47:50 -0500640 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400641
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500642 if (mState.getDrawFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500643 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500644 mState.setDrawFramebufferBinding(nullptr);
Jamie Madilla11819d2018-07-30 10:26:01 -0400645 mDrawFramebufferObserverBinding.bind(nullptr);
Corentin Wallezc295e512017-01-27 17:47:50 -0500646 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400647
648 if (defaultFramebuffer)
649 {
650 defaultFramebuffer->onDestroy(this);
651 delete defaultFramebuffer;
652 }
653
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500654 mState.mFramebufferManager->setDefaultFramebuffer(nullptr);
Corentin Wallezc295e512017-01-27 17:47:50 -0500655
656 if (mCurrentSurface)
657 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400658 ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
Corentin Wallezc295e512017-01-27 17:47:50 -0500659 mCurrentSurface = nullptr;
660 }
Jamie Madill4928b7c2017-06-20 12:57:39 -0400661
662 return egl::NoError();
Jamie Madill77a72f62015-04-14 11:18:32 -0400663}
664
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000665GLuint Context::createBuffer()
666{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500667 return mState.mBufferManager->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000668}
669
670GLuint Context::createProgram()
671{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500672 return mState.mShaderProgramManager->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000673}
674
Jiawei Shao385b3e02018-03-21 09:43:28 +0800675GLuint Context::createShader(ShaderType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000676{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500677 return mState.mShaderProgramManager->createShader(mImplementation.get(), mState.mLimitations,
678 type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000679}
680
681GLuint Context::createTexture()
682{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500683 return mState.mTextureManager->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000684}
685
686GLuint Context::createRenderbuffer()
687{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500688 return mState.mRenderbufferManager->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000689}
690
Jamie Madill13951342018-09-30 15:24:28 -0400691void Context::tryGenPaths(GLsizei range, GLuint *createdOut)
692{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500693 ANGLE_CONTEXT_TRY(mState.mPathManager->createPaths(this, range, createdOut));
Jamie Madill13951342018-09-30 15:24:28 -0400694}
695
Brandon Jones59770802018-04-02 13:18:42 -0700696GLuint Context::genPaths(GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300697{
Jamie Madill13951342018-09-30 15:24:28 -0400698 GLuint created = 0;
699 tryGenPaths(range, &created);
700 return created;
Sami Väisänene45e53b2016-05-25 10:36:04 +0300701}
702
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000703// Returns an unused framebuffer name
704GLuint Context::createFramebuffer()
705{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500706 return mState.mFramebufferManager->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000707}
708
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500709void Context::genFencesNV(GLsizei n, GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000710{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500711 for (int i = 0; i < n; i++)
712 {
713 GLuint handle = mFenceNVHandleAllocator.allocate();
714 mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV()));
715 fences[i] = handle;
716 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000717}
718
Yunchao Hea336b902017-08-02 16:05:21 +0800719GLuint Context::createProgramPipeline()
720{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500721 return mState.mProgramPipelineManager->createProgramPipeline();
Yunchao Hea336b902017-08-02 16:05:21 +0800722}
723
Jiawei Shao385b3e02018-03-21 09:43:28 +0800724GLuint Context::createShaderProgramv(ShaderType type, GLsizei count, const GLchar *const *strings)
Jiajia Qin5451d532017-11-16 17:16:34 +0800725{
726 UNIMPLEMENTED();
727 return 0u;
728}
729
James Darpinian4d9d4832018-03-13 12:43:28 -0700730void Context::deleteBuffer(GLuint bufferName)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000731{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500732 Buffer *buffer = mState.mBufferManager->getBuffer(bufferName);
James Darpinian4d9d4832018-03-13 12:43:28 -0700733 if (buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000734 {
735 detachBuffer(buffer);
736 }
Jamie Madill893ab082014-05-16 16:56:10 -0400737
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500738 mState.mBufferManager->deleteObject(this, bufferName);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000739}
740
741void Context::deleteShader(GLuint shader)
742{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500743 mState.mShaderProgramManager->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000744}
745
746void Context::deleteProgram(GLuint program)
747{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500748 mState.mShaderProgramManager->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000749}
750
751void Context::deleteTexture(GLuint texture)
752{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500753 if (mState.mTextureManager->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000754 {
755 detachTexture(texture);
756 }
757
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500758 mState.mTextureManager->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000759}
760
761void Context::deleteRenderbuffer(GLuint renderbuffer)
762{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500763 if (mState.mRenderbufferManager->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000764 {
765 detachRenderbuffer(renderbuffer);
766 }
Jamie Madill893ab082014-05-16 16:56:10 -0400767
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500768 mState.mRenderbufferManager->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000769}
770
Jamie Madill7f0c5a42017-08-26 22:43:26 -0400771void Context::deleteSync(GLsync sync)
Jamie Madillcd055f82013-07-26 11:55:15 -0400772{
773 // The spec specifies the underlying Fence object is not deleted until all current
774 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
775 // and since our API is currently designed for being called from a single thread, we can delete
776 // the fence immediately.
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500777 mState.mSyncManager->deleteObject(this, static_cast<GLuint>(reinterpret_cast<uintptr_t>(sync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400778}
779
Yunchao Hea336b902017-08-02 16:05:21 +0800780void Context::deleteProgramPipeline(GLuint pipeline)
781{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500782 if (mState.mProgramPipelineManager->getProgramPipeline(pipeline))
Yunchao Hea336b902017-08-02 16:05:21 +0800783 {
784 detachProgramPipeline(pipeline);
785 }
786
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500787 mState.mProgramPipelineManager->deleteObject(this, pipeline);
Yunchao Hea336b902017-08-02 16:05:21 +0800788}
789
Sami Väisänene45e53b2016-05-25 10:36:04 +0300790void Context::deletePaths(GLuint first, GLsizei range)
791{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500792 mState.mPathManager->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300793}
794
Brandon Jones59770802018-04-02 13:18:42 -0700795bool Context::isPath(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300796{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500797 const auto *pathObj = mState.mPathManager->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300798 if (pathObj == nullptr)
799 return false;
800
801 return pathObj->hasPathData();
802}
803
Brandon Jones59770802018-04-02 13:18:42 -0700804bool Context::isPathGenerated(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300805{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500806 return mState.mPathManager->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300807}
808
Brandon Jones59770802018-04-02 13:18:42 -0700809void Context::pathCommands(GLuint path,
810 GLsizei numCommands,
811 const GLubyte *commands,
812 GLsizei numCoords,
813 GLenum coordType,
814 const void *coords)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300815{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500816 auto *pathObject = mState.mPathManager->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300817
Jamie Madill4f6592f2018-11-27 16:37:45 -0500818 ANGLE_CONTEXT_TRY(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
Sami Väisänene45e53b2016-05-25 10:36:04 +0300819}
820
Jamie Madill007530e2017-12-28 14:27:04 -0500821void Context::pathParameterf(GLuint path, GLenum pname, GLfloat value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300822{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500823 Path *pathObj = mState.mPathManager->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300824
825 switch (pname)
826 {
827 case GL_PATH_STROKE_WIDTH_CHROMIUM:
828 pathObj->setStrokeWidth(value);
829 break;
830 case GL_PATH_END_CAPS_CHROMIUM:
831 pathObj->setEndCaps(static_cast<GLenum>(value));
832 break;
833 case GL_PATH_JOIN_STYLE_CHROMIUM:
834 pathObj->setJoinStyle(static_cast<GLenum>(value));
835 break;
836 case GL_PATH_MITER_LIMIT_CHROMIUM:
837 pathObj->setMiterLimit(value);
838 break;
839 case GL_PATH_STROKE_BOUND_CHROMIUM:
840 pathObj->setStrokeBound(value);
841 break;
842 default:
843 UNREACHABLE();
844 break;
845 }
846}
847
Jamie Madill007530e2017-12-28 14:27:04 -0500848void Context::pathParameteri(GLuint path, GLenum pname, GLint value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300849{
Jamie Madill007530e2017-12-28 14:27:04 -0500850 // TODO(jmadill): Should use proper clamping/casting.
851 pathParameterf(path, pname, static_cast<GLfloat>(value));
852}
853
854void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value)
855{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500856 const Path *pathObj = mState.mPathManager->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300857
858 switch (pname)
859 {
860 case GL_PATH_STROKE_WIDTH_CHROMIUM:
861 *value = pathObj->getStrokeWidth();
862 break;
863 case GL_PATH_END_CAPS_CHROMIUM:
864 *value = static_cast<GLfloat>(pathObj->getEndCaps());
865 break;
866 case GL_PATH_JOIN_STYLE_CHROMIUM:
867 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
868 break;
869 case GL_PATH_MITER_LIMIT_CHROMIUM:
870 *value = pathObj->getMiterLimit();
871 break;
872 case GL_PATH_STROKE_BOUND_CHROMIUM:
873 *value = pathObj->getStrokeBound();
874 break;
875 default:
876 UNREACHABLE();
877 break;
878 }
879}
880
Jamie Madill007530e2017-12-28 14:27:04 -0500881void Context::getPathParameteriv(GLuint path, GLenum pname, GLint *value)
882{
883 GLfloat val = 0.0f;
884 getPathParameterfv(path, pname, value != nullptr ? &val : nullptr);
885 if (value)
886 *value = static_cast<GLint>(val);
887}
888
Brandon Jones59770802018-04-02 13:18:42 -0700889void Context::pathStencilFunc(GLenum func, GLint ref, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300890{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500891 mState.setPathStencilFunc(func, ref, mask);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300892}
893
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000894void Context::deleteFramebuffer(GLuint framebuffer)
895{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500896 if (mState.mFramebufferManager->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000897 {
898 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000899 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500900
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500901 mState.mFramebufferManager->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000902}
903
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500904void Context::deleteFencesNV(GLsizei n, const GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000905{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500906 for (int i = 0; i < n; i++)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000907 {
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500908 GLuint fence = fences[i];
909
910 FenceNV *fenceObject = nullptr;
911 if (mFenceNVMap.erase(fence, &fenceObject))
912 {
913 mFenceNVHandleAllocator.release(fence);
914 delete fenceObject;
915 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000916 }
917}
918
Geoff Lang70d0f492015-12-10 17:45:46 -0500919Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000920{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500921 return mState.mBufferManager->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000922}
923
Geoff Lang70d0f492015-12-10 17:45:46 -0500924Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000925{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500926 return mState.mRenderbufferManager->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000927}
928
Jamie Madill70b5bb02017-08-28 13:32:37 -0400929Sync *Context::getSync(GLsync handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400930{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500931 return mState.mSyncManager->getSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400932}
933
Jamie Madill57a89722013-07-02 11:57:03 -0400934VertexArray *Context::getVertexArray(GLuint handle) const
935{
Jamie Madill96a483b2017-06-27 16:49:21 -0400936 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -0400937}
938
Jamie Madilldc356042013-07-19 16:36:57 -0400939Sampler *Context::getSampler(GLuint handle) const
940{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500941 return mState.mSamplerManager->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400942}
943
Geoff Langc8058452014-02-03 12:04:11 -0500944TransformFeedback *Context::getTransformFeedback(GLuint handle) const
945{
Jamie Madill96a483b2017-06-27 16:49:21 -0400946 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -0500947}
948
Yunchao Hea336b902017-08-02 16:05:21 +0800949ProgramPipeline *Context::getProgramPipeline(GLuint handle) const
950{
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500951 return mState.mProgramPipelineManager->getProgramPipeline(handle);
Yunchao Hea336b902017-08-02 16:05:21 +0800952}
953
Geoff Lang75359662018-04-11 01:42:27 -0400954gl::LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
Geoff Lang70d0f492015-12-10 17:45:46 -0500955{
956 switch (identifier)
957 {
958 case GL_BUFFER:
959 return getBuffer(name);
960 case GL_SHADER:
961 return getShader(name);
962 case GL_PROGRAM:
Jamie Madill44a6fbf2018-10-02 13:38:56 -0400963 return getProgramNoResolveLink(name);
Geoff Lang70d0f492015-12-10 17:45:46 -0500964 case GL_VERTEX_ARRAY:
965 return getVertexArray(name);
966 case GL_QUERY:
967 return getQuery(name);
968 case GL_TRANSFORM_FEEDBACK:
969 return getTransformFeedback(name);
970 case GL_SAMPLER:
971 return getSampler(name);
972 case GL_TEXTURE:
973 return getTexture(name);
974 case GL_RENDERBUFFER:
975 return getRenderbuffer(name);
976 case GL_FRAMEBUFFER:
977 return getFramebuffer(name);
978 default:
979 UNREACHABLE();
980 return nullptr;
981 }
982}
983
Geoff Lang75359662018-04-11 01:42:27 -0400984gl::LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
Geoff Lang70d0f492015-12-10 17:45:46 -0500985{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400986 return getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
Geoff Lang70d0f492015-12-10 17:45:46 -0500987}
988
Martin Radev9d901792016-07-15 15:58:58 +0300989void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
990{
Geoff Lang75359662018-04-11 01:42:27 -0400991 gl::LabeledObject *object = getLabeledObject(identifier, name);
Martin Radev9d901792016-07-15 15:58:58 +0300992 ASSERT(object != nullptr);
993
994 std::string labelName = GetObjectLabelFromPointer(length, label);
Jamie Madille90d4ee2018-11-28 14:04:00 -0500995 object->setLabel(this, labelName);
Jamie Madill8693bdb2017-09-02 15:32:14 -0400996
997 // TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the
998 // specified object is active until we do this.
Jamie Madillc3dc5d42018-12-30 12:12:04 -0500999 mState.setObjectDirty(identifier);
Martin Radev9d901792016-07-15 15:58:58 +03001000}
1001
1002void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
1003{
Geoff Lang75359662018-04-11 01:42:27 -04001004 gl::LabeledObject *object = getLabeledObjectFromPtr(ptr);
Martin Radev9d901792016-07-15 15:58:58 +03001005 ASSERT(object != nullptr);
1006
1007 std::string labelName = GetObjectLabelFromPointer(length, label);
Jamie Madille90d4ee2018-11-28 14:04:00 -05001008 object->setLabel(this, labelName);
Martin Radev9d901792016-07-15 15:58:58 +03001009}
1010
1011void Context::getObjectLabel(GLenum identifier,
1012 GLuint name,
1013 GLsizei bufSize,
1014 GLsizei *length,
1015 GLchar *label) const
1016{
Geoff Lang75359662018-04-11 01:42:27 -04001017 gl::LabeledObject *object = getLabeledObject(identifier, name);
Martin Radev9d901792016-07-15 15:58:58 +03001018 ASSERT(object != nullptr);
1019
1020 const std::string &objectLabel = object->getLabel();
1021 GetObjectLabelBase(objectLabel, bufSize, length, label);
1022}
1023
1024void Context::getObjectPtrLabel(const void *ptr,
1025 GLsizei bufSize,
1026 GLsizei *length,
1027 GLchar *label) const
1028{
Geoff Lang75359662018-04-11 01:42:27 -04001029 gl::LabeledObject *object = getLabeledObjectFromPtr(ptr);
Martin Radev9d901792016-07-15 15:58:58 +03001030 ASSERT(object != nullptr);
1031
1032 const std::string &objectLabel = object->getLabel();
1033 GetObjectLabelBase(objectLabel, bufSize, length, label);
1034}
1035
Jamie Madilldc356042013-07-19 16:36:57 -04001036bool Context::isSampler(GLuint samplerName) const
1037{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001038 return mState.mSamplerManager->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -04001039}
1040
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001041void Context::bindTexture(TextureType target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001042{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001043 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001044
Jamie Madilldedd7b92014-11-05 16:30:36 -05001045 if (handle == 0)
1046 {
1047 texture = mZeroTextures[target].get();
1048 }
1049 else
1050 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001051 texture =
1052 mState.mTextureManager->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -05001053 }
1054
1055 ASSERT(texture);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001056 mState.setSamplerTexture(this, target, texture);
Jamie Madilld84b6732018-09-06 15:54:35 -04001057 mStateCache.onActiveTextureChange(this);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00001058}
1059
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001060void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001061{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001062 Framebuffer *framebuffer = mState.mFramebufferManager->checkFramebufferAllocation(
1063 mImplementation.get(), mState.mCaps, framebufferHandle);
1064 mState.setReadFramebufferBinding(framebuffer);
Jamie Madilla11819d2018-07-30 10:26:01 -04001065 mReadFramebufferObserverBinding.bind(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001066}
1067
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001068void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001069{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001070 Framebuffer *framebuffer = mState.mFramebufferManager->checkFramebufferAllocation(
1071 mImplementation.get(), mState.mCaps, framebufferHandle);
1072 mState.setDrawFramebufferBinding(framebuffer);
Jamie Madilla11819d2018-07-30 10:26:01 -04001073 mDrawFramebufferObserverBinding.bind(framebuffer);
Jamie Madilld84b6732018-09-06 15:54:35 -04001074 mStateCache.onDrawFramebufferChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001075}
1076
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001077void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -04001078{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001079 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001080 mState.setVertexArrayBinding(this, vertexArray);
Jamie Madilla11819d2018-07-30 10:26:01 -04001081 mVertexArrayObserverBinding.bind(vertexArray);
Jamie Madillc43cdad2018-08-08 15:49:25 -04001082 mStateCache.onVertexArrayBindingChange(this);
Jamie Madill57a89722013-07-02 11:57:03 -04001083}
1084
Shao80957d92017-02-20 21:25:59 +08001085void Context::bindVertexBuffer(GLuint bindingIndex,
1086 GLuint bufferHandle,
1087 GLintptr offset,
1088 GLsizei stride)
1089{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001090 Buffer *buffer =
1091 mState.mBufferManager->checkBufferAllocation(mImplementation.get(), bufferHandle);
1092 mState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Jamie Madillc43cdad2018-08-08 15:49:25 -04001093 mStateCache.onVertexArrayStateChange(this);
Shao80957d92017-02-20 21:25:59 +08001094}
1095
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001096void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -04001097{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001098 ASSERT(textureUnit < mState.mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -04001099 Sampler *sampler =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001100 mState.mSamplerManager->checkSamplerAllocation(mImplementation.get(), samplerHandle);
1101 mState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04001102 mSamplerObserverBindings[textureUnit].bind(sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04001103}
1104
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001105void Context::bindImageTexture(GLuint unit,
1106 GLuint texture,
1107 GLint level,
1108 GLboolean layered,
1109 GLint layer,
1110 GLenum access,
1111 GLenum format)
1112{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001113 Texture *tex = mState.mTextureManager->getTexture(texture);
1114 mState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001115}
1116
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001117void Context::useProgram(GLuint program)
1118{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001119 ANGLE_CONTEXT_TRY(mState.setProgram(this, getProgramResolveLink(program)));
Jamie Madillc43cdad2018-08-08 15:49:25 -04001120 mStateCache.onProgramExecutableChange(this);
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001121}
1122
Jiajia Qin5451d532017-11-16 17:16:34 +08001123void Context::useProgramStages(GLuint pipeline, GLbitfield stages, GLuint program)
1124{
1125 UNIMPLEMENTED();
1126}
1127
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001128void Context::bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001129{
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001130 ASSERT(target == GL_TRANSFORM_FEEDBACK);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001131 TransformFeedback *transformFeedback =
1132 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001133 mState.setTransformFeedbackBinding(this, transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -05001134}
1135
Yunchao Hea336b902017-08-02 16:05:21 +08001136void Context::bindProgramPipeline(GLuint pipelineHandle)
1137{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001138 ProgramPipeline *pipeline = mState.mProgramPipelineManager->checkProgramPipelineAllocation(
1139 mImplementation.get(), pipelineHandle);
1140 mState.setProgramPipelineBinding(this, pipeline);
Yunchao Hea336b902017-08-02 16:05:21 +08001141}
1142
Corentin Wallezad3ae902018-03-09 13:40:42 -05001143void Context::beginQuery(QueryType target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001144{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001145 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001146 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001147
Geoff Lang5aad9672014-09-08 11:10:42 -04001148 // begin query
Jamie Madill5188a272018-07-25 10:53:56 -04001149 ANGLE_CONTEXT_TRY(queryObject->begin(this));
Geoff Lang5aad9672014-09-08 11:10:42 -04001150
1151 // set query as active for specified target only if begin succeeded
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001152 mState.setActiveQuery(this, target, queryObject);
Jamie Madilld84b6732018-09-06 15:54:35 -04001153 mStateCache.onQueryChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001154}
1155
Corentin Wallezad3ae902018-03-09 13:40:42 -05001156void Context::endQuery(QueryType target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001157{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001158 Query *queryObject = mState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001159 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001160
Jamie Madill4f6592f2018-11-27 16:37:45 -05001161 // Intentionally don't call try here. We don't want an early return.
1162 (void)(queryObject->end(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001163
Geoff Lang5aad9672014-09-08 11:10:42 -04001164 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001165 mState.setActiveQuery(this, target, nullptr);
Jamie Madilld84b6732018-09-06 15:54:35 -04001166 mStateCache.onQueryChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001167}
1168
Corentin Wallezad3ae902018-03-09 13:40:42 -05001169void Context::queryCounter(GLuint id, QueryType target)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001170{
Corentin Wallezad3ae902018-03-09 13:40:42 -05001171 ASSERT(target == QueryType::Timestamp);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001172
1173 Query *queryObject = getQuery(id, true, target);
1174 ASSERT(queryObject);
1175
Jamie Madill4f6592f2018-11-27 16:37:45 -05001176 ANGLE_CONTEXT_TRY(queryObject->queryCounter(this));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001177}
1178
Corentin Wallezad3ae902018-03-09 13:40:42 -05001179void Context::getQueryiv(QueryType target, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001180{
1181 switch (pname)
1182 {
1183 case GL_CURRENT_QUERY_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001184 params[0] = mState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001185 break;
1186 case GL_QUERY_COUNTER_BITS_EXT:
1187 switch (target)
1188 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001189 case QueryType::TimeElapsed:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001190 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1191 break;
Corentin Wallezad3ae902018-03-09 13:40:42 -05001192 case QueryType::Timestamp:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001193 params[0] = getExtensions().queryCounterBitsTimestamp;
1194 break;
1195 default:
1196 UNREACHABLE();
1197 params[0] = 0;
1198 break;
1199 }
1200 break;
1201 default:
1202 UNREACHABLE();
1203 return;
1204 }
1205}
1206
Corentin Wallezad3ae902018-03-09 13:40:42 -05001207void Context::getQueryivRobust(QueryType target,
Brandon Jones59770802018-04-02 13:18:42 -07001208 GLenum pname,
1209 GLsizei bufSize,
1210 GLsizei *length,
1211 GLint *params)
1212{
1213 getQueryiv(target, pname, params);
1214}
1215
Geoff Lang2186c382016-10-14 10:54:54 -04001216void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001217{
Jamie Madill4f6592f2018-11-27 16:37:45 -05001218 ANGLE_CONTEXT_TRY(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001219}
1220
Brandon Jones59770802018-04-02 13:18:42 -07001221void Context::getQueryObjectivRobust(GLuint id,
1222 GLenum pname,
1223 GLsizei bufSize,
1224 GLsizei *length,
1225 GLint *params)
1226{
1227 getQueryObjectiv(id, pname, params);
1228}
1229
Geoff Lang2186c382016-10-14 10:54:54 -04001230void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001231{
Jamie Madill4f6592f2018-11-27 16:37:45 -05001232 ANGLE_CONTEXT_TRY(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001233}
1234
Brandon Jones59770802018-04-02 13:18:42 -07001235void Context::getQueryObjectuivRobust(GLuint id,
1236 GLenum pname,
1237 GLsizei bufSize,
1238 GLsizei *length,
1239 GLuint *params)
1240{
1241 getQueryObjectuiv(id, pname, params);
1242}
1243
Geoff Lang2186c382016-10-14 10:54:54 -04001244void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001245{
Jamie Madill4f6592f2018-11-27 16:37:45 -05001246 ANGLE_CONTEXT_TRY(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001247}
1248
Brandon Jones59770802018-04-02 13:18:42 -07001249void Context::getQueryObjecti64vRobust(GLuint id,
1250 GLenum pname,
1251 GLsizei bufSize,
1252 GLsizei *length,
1253 GLint64 *params)
1254{
1255 getQueryObjecti64v(id, pname, params);
1256}
1257
Geoff Lang2186c382016-10-14 10:54:54 -04001258void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001259{
Jamie Madill4f6592f2018-11-27 16:37:45 -05001260 ANGLE_CONTEXT_TRY(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001261}
1262
Brandon Jones59770802018-04-02 13:18:42 -07001263void Context::getQueryObjectui64vRobust(GLuint id,
1264 GLenum pname,
1265 GLsizei bufSize,
1266 GLsizei *length,
1267 GLuint64 *params)
1268{
1269 getQueryObjectui64v(id, pname, params);
1270}
1271
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001272Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001273{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001274 return mState.mFramebufferManager->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001275}
1276
Jamie Madill2f348d22017-06-05 10:50:59 -04001277FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001278{
Jamie Madill96a483b2017-06-27 16:49:21 -04001279 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001280}
1281
Corentin Wallezad3ae902018-03-09 13:40:42 -05001282Query *Context::getQuery(GLuint handle, bool create, QueryType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001283{
Jamie Madill96a483b2017-06-27 16:49:21 -04001284 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001285 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001286 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001287 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001288
1289 Query *query = mQueryMap.query(handle);
1290 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001291 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001292 ASSERT(type != QueryType::InvalidEnum);
Jamie Madill96a483b2017-06-27 16:49:21 -04001293 query = new Query(mImplementation->createQuery(type), handle);
1294 query->addRef();
1295 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001296 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001297 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001298}
1299
Geoff Lang70d0f492015-12-10 17:45:46 -05001300Query *Context::getQuery(GLuint handle) const
1301{
Jamie Madill96a483b2017-06-27 16:49:21 -04001302 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001303}
1304
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001305Texture *Context::getTargetTexture(TextureType type) const
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001306{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001307 ASSERT(ValidTextureTarget(this, type) || ValidTextureExternalTarget(this, type));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001308 return mState.getTargetTexture(type);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001309}
1310
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001311Texture *Context::getSamplerTexture(unsigned int sampler, TextureType type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001312{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001313 return mState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001314}
1315
Geoff Lang492a7e42014-11-05 13:27:06 -05001316Compiler *Context::getCompiler() const
1317{
Jamie Madill2f348d22017-06-05 10:50:59 -04001318 if (mCompiler.get() == nullptr)
1319 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001320 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001321 }
1322 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001323}
1324
Jamie Madillc1d770e2017-04-13 17:31:24 -04001325void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001326{
1327 switch (pname)
1328 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001329 case GL_SHADER_COMPILER:
1330 *params = GL_TRUE;
1331 break;
1332 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1333 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1334 break;
Jeff Gilbert465d6092019-01-02 16:21:18 -08001335
Jamie Madill231c7f52017-04-26 13:45:37 -04001336 default:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001337 mState.getBooleanv(pname, params);
Jamie Madill231c7f52017-04-26 13:45:37 -04001338 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001339 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001340}
1341
Jamie Madillc1d770e2017-04-13 17:31:24 -04001342void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001343{
Shannon Woods53a94a82014-06-24 15:20:36 -04001344 // Queries about context capabilities and maximums are answered by Context.
1345 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001346 switch (pname)
1347 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001348 case GL_ALIASED_LINE_WIDTH_RANGE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001349 params[0] = mState.mCaps.minAliasedLineWidth;
1350 params[1] = mState.mCaps.maxAliasedLineWidth;
Jamie Madill231c7f52017-04-26 13:45:37 -04001351 break;
1352 case GL_ALIASED_POINT_SIZE_RANGE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001353 params[0] = mState.mCaps.minAliasedPointSize;
1354 params[1] = mState.mCaps.maxAliasedPointSize;
Jamie Madill231c7f52017-04-26 13:45:37 -04001355 break;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07001356 case GL_SMOOTH_POINT_SIZE_RANGE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001357 params[0] = mState.mCaps.minSmoothPointSize;
1358 params[1] = mState.mCaps.maxSmoothPointSize;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07001359 break;
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07001360 case GL_SMOOTH_LINE_WIDTH_RANGE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001361 params[0] = mState.mCaps.minSmoothLineWidth;
1362 params[1] = mState.mCaps.maxSmoothLineWidth;
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07001363 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001364 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001365 ASSERT(mState.mExtensions.textureFilterAnisotropic);
1366 *params = mState.mExtensions.maxTextureAnisotropy;
Jamie Madill231c7f52017-04-26 13:45:37 -04001367 break;
1368 case GL_MAX_TEXTURE_LOD_BIAS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001369 *params = mState.mCaps.maxLODBias;
Jamie Madill231c7f52017-04-26 13:45:37 -04001370 break;
1371
1372 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1373 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1374 {
Lingfeng Yang3a41af62018-04-09 07:28:56 -07001375 // GLES1 emulation: // GL_PATH_(MODELVIEW|PROJECTION)_MATRIX_CHROMIUM collides with the
1376 // GLES1 constants for modelview/projection matrix.
1377 if (getClientVersion() < Version(2, 0))
1378 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001379 mState.getFloatv(pname, params);
Lingfeng Yang3a41af62018-04-09 07:28:56 -07001380 }
1381 else
1382 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001383 ASSERT(mState.mExtensions.pathRendering);
1384 const GLfloat *m = mState.getPathRenderingMatrix(pname);
Lingfeng Yang3a41af62018-04-09 07:28:56 -07001385 memcpy(params, m, 16 * sizeof(GLfloat));
1386 }
Jamie Madill231c7f52017-04-26 13:45:37 -04001387 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001388 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001389
Jamie Madill231c7f52017-04-26 13:45:37 -04001390 default:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001391 mState.getFloatv(pname, params);
Jamie Madill231c7f52017-04-26 13:45:37 -04001392 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001393 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001394}
1395
Jamie Madillc1d770e2017-04-13 17:31:24 -04001396void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001397{
Shannon Woods53a94a82014-06-24 15:20:36 -04001398 // Queries about context capabilities and maximums are answered by Context.
1399 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001400
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001401 switch (pname)
1402 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001403 case GL_MAX_VERTEX_ATTRIBS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001404 *params = mState.mCaps.maxVertexAttributes;
Jamie Madill231c7f52017-04-26 13:45:37 -04001405 break;
1406 case GL_MAX_VERTEX_UNIFORM_VECTORS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001407 *params = mState.mCaps.maxVertexUniformVectors;
Jamie Madill231c7f52017-04-26 13:45:37 -04001408 break;
1409 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001410 *params = mState.mCaps.maxShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001411 break;
1412 case GL_MAX_VARYING_VECTORS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001413 *params = mState.mCaps.maxVaryingVectors;
Jamie Madill231c7f52017-04-26 13:45:37 -04001414 break;
1415 case GL_MAX_VARYING_COMPONENTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001416 *params = mState.mCaps.maxVertexOutputComponents;
Jamie Madill231c7f52017-04-26 13:45:37 -04001417 break;
1418 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001419 *params = mState.mCaps.maxCombinedTextureImageUnits;
Jamie Madill231c7f52017-04-26 13:45:37 -04001420 break;
1421 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001422 *params = mState.mCaps.maxShaderTextureImageUnits[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001423 break;
1424 case GL_MAX_TEXTURE_IMAGE_UNITS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001425 *params = mState.mCaps.maxShaderTextureImageUnits[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001426 break;
1427 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001428 *params = mState.mCaps.maxFragmentUniformVectors;
Jamie Madill231c7f52017-04-26 13:45:37 -04001429 break;
1430 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001431 *params = mState.mCaps.maxShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001432 break;
1433 case GL_MAX_RENDERBUFFER_SIZE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001434 *params = mState.mCaps.maxRenderbufferSize;
Jamie Madill231c7f52017-04-26 13:45:37 -04001435 break;
1436 case GL_MAX_COLOR_ATTACHMENTS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001437 *params = mState.mCaps.maxColorAttachments;
Jamie Madill231c7f52017-04-26 13:45:37 -04001438 break;
1439 case GL_MAX_DRAW_BUFFERS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001440 *params = mState.mCaps.maxDrawBuffers;
Jamie Madill231c7f52017-04-26 13:45:37 -04001441 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001442 case GL_SUBPIXEL_BITS:
1443 *params = 4;
1444 break;
1445 case GL_MAX_TEXTURE_SIZE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001446 *params = mState.mCaps.max2DTextureSize;
Jamie Madill231c7f52017-04-26 13:45:37 -04001447 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001448 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001449 *params = mState.mCaps.maxRectangleTextureSize;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001450 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001451 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001452 *params = mState.mCaps.maxCubeMapTextureSize;
Jamie Madill231c7f52017-04-26 13:45:37 -04001453 break;
1454 case GL_MAX_3D_TEXTURE_SIZE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001455 *params = mState.mCaps.max3DTextureSize;
Jamie Madill231c7f52017-04-26 13:45:37 -04001456 break;
1457 case GL_MAX_ARRAY_TEXTURE_LAYERS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001458 *params = mState.mCaps.maxArrayTextureLayers;
Jamie Madill231c7f52017-04-26 13:45:37 -04001459 break;
1460 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001461 *params = mState.mCaps.uniformBufferOffsetAlignment;
Jamie Madill231c7f52017-04-26 13:45:37 -04001462 break;
1463 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001464 *params = mState.mCaps.maxUniformBufferBindings;
Jamie Madill231c7f52017-04-26 13:45:37 -04001465 break;
1466 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001467 *params = mState.mCaps.maxShaderUniformBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001468 break;
1469 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001470 *params = mState.mCaps.maxShaderUniformBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001471 break;
1472 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001473 *params = mState.mCaps.maxCombinedTextureImageUnits;
Jamie Madill231c7f52017-04-26 13:45:37 -04001474 break;
1475 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001476 *params = mState.mCaps.maxVertexOutputComponents;
Jamie Madill231c7f52017-04-26 13:45:37 -04001477 break;
1478 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001479 *params = mState.mCaps.maxFragmentInputComponents;
Jamie Madill231c7f52017-04-26 13:45:37 -04001480 break;
1481 case GL_MIN_PROGRAM_TEXEL_OFFSET:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001482 *params = mState.mCaps.minProgramTexelOffset;
Jamie Madill231c7f52017-04-26 13:45:37 -04001483 break;
1484 case GL_MAX_PROGRAM_TEXEL_OFFSET:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001485 *params = mState.mCaps.maxProgramTexelOffset;
Jamie Madill231c7f52017-04-26 13:45:37 -04001486 break;
1487 case GL_MAJOR_VERSION:
1488 *params = getClientVersion().major;
1489 break;
1490 case GL_MINOR_VERSION:
1491 *params = getClientVersion().minor;
1492 break;
1493 case GL_MAX_ELEMENTS_INDICES:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001494 *params = mState.mCaps.maxElementsIndices;
Jamie Madill231c7f52017-04-26 13:45:37 -04001495 break;
1496 case GL_MAX_ELEMENTS_VERTICES:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001497 *params = mState.mCaps.maxElementsVertices;
Jamie Madill231c7f52017-04-26 13:45:37 -04001498 break;
1499 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001500 *params = mState.mCaps.maxTransformFeedbackInterleavedComponents;
Jamie Madill231c7f52017-04-26 13:45:37 -04001501 break;
1502 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001503 *params = mState.mCaps.maxTransformFeedbackSeparateAttributes;
Jamie Madill231c7f52017-04-26 13:45:37 -04001504 break;
1505 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001506 *params = mState.mCaps.maxTransformFeedbackSeparateComponents;
Jamie Madill231c7f52017-04-26 13:45:37 -04001507 break;
1508 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001509 *params = static_cast<GLint>(mState.mCaps.compressedTextureFormats.size());
Jamie Madill231c7f52017-04-26 13:45:37 -04001510 break;
1511 case GL_MAX_SAMPLES_ANGLE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001512 *params = mState.mCaps.maxSamples;
Jamie Madill231c7f52017-04-26 13:45:37 -04001513 break;
1514 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001515 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001516 params[0] = mState.mCaps.maxViewportWidth;
1517 params[1] = mState.mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001518 }
1519 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001520 case GL_COMPRESSED_TEXTURE_FORMATS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001521 std::copy(mState.mCaps.compressedTextureFormats.begin(),
1522 mState.mCaps.compressedTextureFormats.end(), params);
Jamie Madill231c7f52017-04-26 13:45:37 -04001523 break;
1524 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1525 *params = mResetStrategy;
1526 break;
1527 case GL_NUM_SHADER_BINARY_FORMATS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001528 *params = static_cast<GLint>(mState.mCaps.shaderBinaryFormats.size());
Jamie Madill231c7f52017-04-26 13:45:37 -04001529 break;
1530 case GL_SHADER_BINARY_FORMATS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001531 std::copy(mState.mCaps.shaderBinaryFormats.begin(),
1532 mState.mCaps.shaderBinaryFormats.end(), params);
Jamie Madill231c7f52017-04-26 13:45:37 -04001533 break;
1534 case GL_NUM_PROGRAM_BINARY_FORMATS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001535 *params = static_cast<GLint>(mState.mCaps.programBinaryFormats.size());
Jamie Madill231c7f52017-04-26 13:45:37 -04001536 break;
1537 case GL_PROGRAM_BINARY_FORMATS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001538 std::copy(mState.mCaps.programBinaryFormats.begin(),
1539 mState.mCaps.programBinaryFormats.end(), params);
Jamie Madill231c7f52017-04-26 13:45:37 -04001540 break;
1541 case GL_NUM_EXTENSIONS:
1542 *params = static_cast<GLint>(mExtensionStrings.size());
1543 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001544
Geoff Lang38f24ee2018-10-01 13:04:59 -04001545 // GL_ANGLE_request_extension
1546 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
1547 *params = static_cast<GLint>(mRequestableExtensionStrings.size());
1548 break;
1549
Jamie Madill231c7f52017-04-26 13:45:37 -04001550 // GL_KHR_debug
1551 case GL_MAX_DEBUG_MESSAGE_LENGTH:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001552 *params = mState.mExtensions.maxDebugMessageLength;
Jamie Madill231c7f52017-04-26 13:45:37 -04001553 break;
1554 case GL_MAX_DEBUG_LOGGED_MESSAGES:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001555 *params = mState.mExtensions.maxDebugLoggedMessages;
Jamie Madill231c7f52017-04-26 13:45:37 -04001556 break;
1557 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001558 *params = mState.mExtensions.maxDebugGroupStackDepth;
Jamie Madill231c7f52017-04-26 13:45:37 -04001559 break;
1560 case GL_MAX_LABEL_LENGTH:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001561 *params = mState.mExtensions.maxLabelLength;
Jamie Madill231c7f52017-04-26 13:45:37 -04001562 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001563
Martin Radeve5285d22017-07-14 16:23:53 +03001564 // GL_ANGLE_multiview
1565 case GL_MAX_VIEWS_ANGLE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001566 *params = mState.mExtensions.maxViews;
Martin Radeve5285d22017-07-14 16:23:53 +03001567 break;
1568
Jamie Madill231c7f52017-04-26 13:45:37 -04001569 // GL_EXT_disjoint_timer_query
1570 case GL_GPU_DISJOINT_EXT:
1571 *params = mImplementation->getGPUDisjoint();
1572 break;
1573 case GL_MAX_FRAMEBUFFER_WIDTH:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001574 *params = mState.mCaps.maxFramebufferWidth;
Jamie Madill231c7f52017-04-26 13:45:37 -04001575 break;
1576 case GL_MAX_FRAMEBUFFER_HEIGHT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001577 *params = mState.mCaps.maxFramebufferHeight;
Jamie Madill231c7f52017-04-26 13:45:37 -04001578 break;
1579 case GL_MAX_FRAMEBUFFER_SAMPLES:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001580 *params = mState.mCaps.maxFramebufferSamples;
Jamie Madill231c7f52017-04-26 13:45:37 -04001581 break;
1582 case GL_MAX_SAMPLE_MASK_WORDS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001583 *params = mState.mCaps.maxSampleMaskWords;
Jamie Madill231c7f52017-04-26 13:45:37 -04001584 break;
1585 case GL_MAX_COLOR_TEXTURE_SAMPLES:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001586 *params = mState.mCaps.maxColorTextureSamples;
Jamie Madill231c7f52017-04-26 13:45:37 -04001587 break;
1588 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001589 *params = mState.mCaps.maxDepthTextureSamples;
Jamie Madill231c7f52017-04-26 13:45:37 -04001590 break;
1591 case GL_MAX_INTEGER_SAMPLES:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001592 *params = mState.mCaps.maxIntegerSamples;
Jamie Madill231c7f52017-04-26 13:45:37 -04001593 break;
1594 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001595 *params = mState.mCaps.maxVertexAttribRelativeOffset;
Jamie Madill231c7f52017-04-26 13:45:37 -04001596 break;
1597 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001598 *params = mState.mCaps.maxVertexAttribBindings;
Jamie Madill231c7f52017-04-26 13:45:37 -04001599 break;
1600 case GL_MAX_VERTEX_ATTRIB_STRIDE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001601 *params = mState.mCaps.maxVertexAttribStride;
Jamie Madill231c7f52017-04-26 13:45:37 -04001602 break;
1603 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001604 *params = mState.mCaps.maxShaderAtomicCounterBuffers[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001605 break;
1606 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001607 *params = mState.mCaps.maxShaderAtomicCounters[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001608 break;
1609 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001610 *params = mState.mCaps.maxShaderImageUniforms[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001611 break;
1612 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001613 *params = mState.mCaps.maxShaderStorageBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001614 break;
1615 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001616 *params = mState.mCaps.maxShaderAtomicCounterBuffers[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001617 break;
1618 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001619 *params = mState.mCaps.maxShaderAtomicCounters[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001620 break;
1621 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001622 *params = mState.mCaps.maxShaderImageUniforms[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001623 break;
1624 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001625 *params = mState.mCaps.maxShaderStorageBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001626 break;
1627 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001628 *params = mState.mCaps.minProgramTextureGatherOffset;
Jamie Madill231c7f52017-04-26 13:45:37 -04001629 break;
1630 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001631 *params = mState.mCaps.maxProgramTextureGatherOffset;
Jamie Madill231c7f52017-04-26 13:45:37 -04001632 break;
1633 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001634 *params = mState.mCaps.maxComputeWorkGroupInvocations;
Jamie Madill231c7f52017-04-26 13:45:37 -04001635 break;
1636 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001637 *params = mState.mCaps.maxShaderUniformBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001638 break;
1639 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001640 *params = mState.mCaps.maxShaderTextureImageUnits[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001641 break;
1642 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001643 *params = mState.mCaps.maxComputeSharedMemorySize;
Jamie Madill231c7f52017-04-26 13:45:37 -04001644 break;
1645 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001646 *params = mState.mCaps.maxShaderUniformComponents[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001647 break;
1648 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001649 *params = mState.mCaps.maxShaderAtomicCounterBuffers[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001650 break;
1651 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001652 *params = mState.mCaps.maxShaderAtomicCounters[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001653 break;
1654 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001655 *params = mState.mCaps.maxShaderImageUniforms[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001656 break;
1657 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001658 *params = static_cast<GLint>(
1659 mState.mCaps.maxCombinedShaderUniformComponents[ShaderType::Compute]);
Jamie Madill231c7f52017-04-26 13:45:37 -04001660 break;
1661 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001662 *params = mState.mCaps.maxShaderStorageBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001663 break;
1664 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001665 *params = mState.mCaps.maxCombinedShaderOutputResources;
Jamie Madill231c7f52017-04-26 13:45:37 -04001666 break;
1667 case GL_MAX_UNIFORM_LOCATIONS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001668 *params = mState.mCaps.maxUniformLocations;
Jamie Madill231c7f52017-04-26 13:45:37 -04001669 break;
1670 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001671 *params = mState.mCaps.maxAtomicCounterBufferBindings;
Jamie Madill231c7f52017-04-26 13:45:37 -04001672 break;
1673 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001674 *params = mState.mCaps.maxAtomicCounterBufferSize;
Jamie Madill231c7f52017-04-26 13:45:37 -04001675 break;
1676 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001677 *params = mState.mCaps.maxCombinedAtomicCounterBuffers;
Jamie Madill231c7f52017-04-26 13:45:37 -04001678 break;
1679 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001680 *params = mState.mCaps.maxCombinedAtomicCounters;
Jamie Madill231c7f52017-04-26 13:45:37 -04001681 break;
1682 case GL_MAX_IMAGE_UNITS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001683 *params = mState.mCaps.maxImageUnits;
Jamie Madill231c7f52017-04-26 13:45:37 -04001684 break;
1685 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001686 *params = mState.mCaps.maxCombinedImageUniforms;
Jamie Madill231c7f52017-04-26 13:45:37 -04001687 break;
1688 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001689 *params = mState.mCaps.maxShaderStorageBufferBindings;
Jamie Madill231c7f52017-04-26 13:45:37 -04001690 break;
1691 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001692 *params = mState.mCaps.maxCombinedShaderStorageBlocks;
Jamie Madill231c7f52017-04-26 13:45:37 -04001693 break;
1694 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001695 *params = mState.mCaps.shaderStorageBufferOffsetAlignment;
Jamie Madill231c7f52017-04-26 13:45:37 -04001696 break;
Jiawei Shao361df072017-11-22 09:33:59 +08001697
1698 // GL_EXT_geometry_shader
1699 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001700 *params = mState.mCaps.maxFramebufferLayers;
Jiawei Shao361df072017-11-22 09:33:59 +08001701 break;
1702 case GL_LAYER_PROVOKING_VERTEX_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001703 *params = mState.mCaps.layerProvokingVertex;
Jiawei Shao361df072017-11-22 09:33:59 +08001704 break;
1705 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001706 *params = mState.mCaps.maxShaderUniformComponents[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001707 break;
1708 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001709 *params = mState.mCaps.maxShaderUniformBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001710 break;
1711 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001712 *params = static_cast<GLint>(
1713 mState.mCaps.maxCombinedShaderUniformComponents[ShaderType::Geometry]);
Jiawei Shao361df072017-11-22 09:33:59 +08001714 break;
1715 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001716 *params = mState.mCaps.maxGeometryInputComponents;
Jiawei Shao361df072017-11-22 09:33:59 +08001717 break;
1718 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001719 *params = mState.mCaps.maxGeometryOutputComponents;
Jiawei Shao361df072017-11-22 09:33:59 +08001720 break;
1721 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001722 *params = mState.mCaps.maxGeometryOutputVertices;
Jiawei Shao361df072017-11-22 09:33:59 +08001723 break;
1724 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001725 *params = mState.mCaps.maxGeometryTotalOutputComponents;
Jiawei Shao361df072017-11-22 09:33:59 +08001726 break;
1727 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001728 *params = mState.mCaps.maxGeometryShaderInvocations;
Jiawei Shao361df072017-11-22 09:33:59 +08001729 break;
1730 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001731 *params = mState.mCaps.maxShaderTextureImageUnits[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001732 break;
1733 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001734 *params = mState.mCaps.maxShaderAtomicCounterBuffers[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001735 break;
1736 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001737 *params = mState.mCaps.maxShaderAtomicCounters[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001738 break;
1739 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001740 *params = mState.mCaps.maxShaderImageUniforms[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001741 break;
1742 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001743 *params = mState.mCaps.maxShaderStorageBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001744 break;
Lingfeng Yang96310cd2018-03-28 11:56:28 -07001745 // GLES1 emulation: Caps queries
1746 case GL_MAX_TEXTURE_UNITS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001747 *params = mState.mCaps.maxMultitextureUnits;
Lingfeng Yang96310cd2018-03-28 11:56:28 -07001748 break;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001749 case GL_MAX_MODELVIEW_STACK_DEPTH:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001750 *params = mState.mCaps.maxModelviewMatrixStackDepth;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001751 break;
1752 case GL_MAX_PROJECTION_STACK_DEPTH:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001753 *params = mState.mCaps.maxProjectionMatrixStackDepth;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001754 break;
1755 case GL_MAX_TEXTURE_STACK_DEPTH:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001756 *params = mState.mCaps.maxTextureMatrixStackDepth;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001757 break;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07001758 case GL_MAX_LIGHTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001759 *params = mState.mCaps.maxLights;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07001760 break;
Lingfeng Yang060088a2018-05-30 20:40:57 -07001761 case GL_MAX_CLIP_PLANES:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001762 *params = mState.mCaps.maxClipPlanes;
Lingfeng Yang060088a2018-05-30 20:40:57 -07001763 break;
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001764 // GLES1 emulation: Vertex attribute queries
1765 case GL_VERTEX_ARRAY_BUFFER_BINDING:
1766 case GL_NORMAL_ARRAY_BUFFER_BINDING:
1767 case GL_COLOR_ARRAY_BUFFER_BINDING:
1768 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
1769 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
1770 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1771 GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, params);
1772 break;
1773 case GL_VERTEX_ARRAY_STRIDE:
1774 case GL_NORMAL_ARRAY_STRIDE:
1775 case GL_COLOR_ARRAY_STRIDE:
1776 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
1777 case GL_TEXTURE_COORD_ARRAY_STRIDE:
1778 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1779 GL_VERTEX_ATTRIB_ARRAY_STRIDE, params);
1780 break;
1781 case GL_VERTEX_ARRAY_SIZE:
1782 case GL_COLOR_ARRAY_SIZE:
1783 case GL_TEXTURE_COORD_ARRAY_SIZE:
1784 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1785 GL_VERTEX_ATTRIB_ARRAY_SIZE, params);
1786 break;
1787 case GL_VERTEX_ARRAY_TYPE:
1788 case GL_COLOR_ARRAY_TYPE:
1789 case GL_NORMAL_ARRAY_TYPE:
1790 case GL_POINT_SIZE_ARRAY_TYPE_OES:
1791 case GL_TEXTURE_COORD_ARRAY_TYPE:
1792 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1793 GL_VERTEX_ATTRIB_ARRAY_TYPE, params);
1794 break;
1795
jchen1082af6202018-06-22 10:59:52 +08001796 // GL_KHR_parallel_shader_compile
1797 case GL_MAX_SHADER_COMPILER_THREADS_KHR:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001798 *params = mState.getMaxShaderCompilerThreads();
jchen1082af6202018-06-22 10:59:52 +08001799 break;
1800
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03001801 // GL_EXT_blend_func_extended
1802 case GL_MAX_DUAL_SOURCE_DRAW_BUFFERS_EXT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001803 *params = mState.mExtensions.maxDualSourceDrawBuffers;
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03001804 break;
1805
Jamie Madill231c7f52017-04-26 13:45:37 -04001806 default:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001807 ANGLE_CONTEXT_TRY(mState.getIntegerv(this, pname, params));
Jamie Madill231c7f52017-04-26 13:45:37 -04001808 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001809 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001810}
1811
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001812void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001813{
Shannon Woods53a94a82014-06-24 15:20:36 -04001814 // Queries about context capabilities and maximums are answered by Context.
1815 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001816 switch (pname)
1817 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001818 case GL_MAX_ELEMENT_INDEX:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001819 *params = mState.mCaps.maxElementIndex;
Jamie Madill231c7f52017-04-26 13:45:37 -04001820 break;
1821 case GL_MAX_UNIFORM_BLOCK_SIZE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001822 *params = mState.mCaps.maxUniformBlockSize;
Jamie Madill231c7f52017-04-26 13:45:37 -04001823 break;
1824 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001825 *params = mState.mCaps.maxCombinedShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001826 break;
1827 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001828 *params = mState.mCaps.maxCombinedShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001829 break;
1830 case GL_MAX_SERVER_WAIT_TIMEOUT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001831 *params = mState.mCaps.maxServerWaitTimeout;
Jamie Madill231c7f52017-04-26 13:45:37 -04001832 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001833
Jamie Madill231c7f52017-04-26 13:45:37 -04001834 // GL_EXT_disjoint_timer_query
1835 case GL_TIMESTAMP_EXT:
1836 *params = mImplementation->getTimestamp();
1837 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001838
Jamie Madill231c7f52017-04-26 13:45:37 -04001839 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001840 *params = mState.mCaps.maxShaderStorageBlockSize;
Jamie Madill231c7f52017-04-26 13:45:37 -04001841 break;
1842 default:
1843 UNREACHABLE();
1844 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001845 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001846}
1847
Geoff Lang70d0f492015-12-10 17:45:46 -05001848void Context::getPointerv(GLenum pname, void **params) const
1849{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001850 mState.getPointerv(this, pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001851}
1852
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001853void Context::getPointervRobustANGLERobust(GLenum pname,
1854 GLsizei bufSize,
1855 GLsizei *length,
1856 void **params)
1857{
1858 UNIMPLEMENTED();
1859}
1860
Martin Radev66fb8202016-07-28 11:45:20 +03001861void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001862{
Shannon Woods53a94a82014-06-24 15:20:36 -04001863 // Queries about context capabilities and maximums are answered by Context.
1864 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001865
1866 GLenum nativeType;
1867 unsigned int numParams;
1868 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1869 ASSERT(queryStatus);
1870
1871 if (nativeType == GL_INT)
1872 {
1873 switch (target)
1874 {
1875 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1876 ASSERT(index < 3u);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001877 *data = mState.mCaps.maxComputeWorkGroupCount[index];
Martin Radev66fb8202016-07-28 11:45:20 +03001878 break;
1879 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1880 ASSERT(index < 3u);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001881 *data = mState.mCaps.maxComputeWorkGroupSize[index];
Martin Radev66fb8202016-07-28 11:45:20 +03001882 break;
1883 default:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001884 mState.getIntegeri_v(target, index, data);
Martin Radev66fb8202016-07-28 11:45:20 +03001885 }
1886 }
1887 else
1888 {
1889 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1890 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001891}
1892
Brandon Jones59770802018-04-02 13:18:42 -07001893void Context::getIntegeri_vRobust(GLenum target,
1894 GLuint index,
1895 GLsizei bufSize,
1896 GLsizei *length,
1897 GLint *data)
1898{
1899 getIntegeri_v(target, index, data);
1900}
1901
Martin Radev66fb8202016-07-28 11:45:20 +03001902void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001903{
Shannon Woods53a94a82014-06-24 15:20:36 -04001904 // Queries about context capabilities and maximums are answered by Context.
1905 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001906
1907 GLenum nativeType;
1908 unsigned int numParams;
1909 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1910 ASSERT(queryStatus);
1911
1912 if (nativeType == GL_INT_64_ANGLEX)
1913 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001914 mState.getInteger64i_v(target, index, data);
Martin Radev66fb8202016-07-28 11:45:20 +03001915 }
1916 else
1917 {
1918 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1919 }
1920}
1921
Brandon Jones59770802018-04-02 13:18:42 -07001922void Context::getInteger64i_vRobust(GLenum target,
1923 GLuint index,
1924 GLsizei bufSize,
1925 GLsizei *length,
1926 GLint64 *data)
1927{
1928 getInteger64i_v(target, index, data);
1929}
1930
Martin Radev66fb8202016-07-28 11:45:20 +03001931void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1932{
1933 // Queries about context capabilities and maximums are answered by Context.
1934 // Queries about current GL state values are answered by State.
1935
1936 GLenum nativeType;
1937 unsigned int numParams;
1938 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1939 ASSERT(queryStatus);
1940
1941 if (nativeType == GL_BOOL)
1942 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001943 mState.getBooleani_v(target, index, data);
Martin Radev66fb8202016-07-28 11:45:20 +03001944 }
1945 else
1946 {
1947 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1948 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001949}
1950
Brandon Jones59770802018-04-02 13:18:42 -07001951void Context::getBooleani_vRobust(GLenum target,
1952 GLuint index,
1953 GLsizei bufSize,
1954 GLsizei *length,
1955 GLboolean *data)
1956{
1957 getBooleani_v(target, index, data);
1958}
1959
Corentin Wallez336129f2017-10-17 15:55:40 -04001960void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001961{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001962 Buffer *buffer = mState.getTargetBuffer(target);
He Yunchao010e4db2017-03-03 14:22:06 +08001963 QueryBufferParameteriv(buffer, pname, params);
1964}
1965
Brandon Jones59770802018-04-02 13:18:42 -07001966void Context::getBufferParameterivRobust(BufferBinding target,
1967 GLenum pname,
1968 GLsizei bufSize,
1969 GLsizei *length,
1970 GLint *params)
1971{
1972 getBufferParameteriv(target, pname, params);
1973}
1974
He Yunchao010e4db2017-03-03 14:22:06 +08001975void Context::getFramebufferAttachmentParameteriv(GLenum target,
1976 GLenum attachment,
1977 GLenum pname,
1978 GLint *params)
1979{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001980 const Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08001981 QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08001982}
1983
Brandon Jones59770802018-04-02 13:18:42 -07001984void Context::getFramebufferAttachmentParameterivRobust(GLenum target,
1985 GLenum attachment,
1986 GLenum pname,
1987 GLsizei bufSize,
1988 GLsizei *length,
1989 GLint *params)
1990{
1991 getFramebufferAttachmentParameteriv(target, attachment, pname, params);
1992}
1993
He Yunchao010e4db2017-03-03 14:22:06 +08001994void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
1995{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05001996 Renderbuffer *renderbuffer = mState.getCurrentRenderbuffer();
He Yunchao010e4db2017-03-03 14:22:06 +08001997 QueryRenderbufferiv(this, renderbuffer, pname, params);
1998}
1999
Brandon Jones59770802018-04-02 13:18:42 -07002000void Context::getRenderbufferParameterivRobust(GLenum target,
2001 GLenum pname,
2002 GLsizei bufSize,
2003 GLsizei *length,
2004 GLint *params)
2005{
2006 getRenderbufferParameteriv(target, pname, params);
2007}
2008
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002009void Context::getTexParameterfv(TextureType target, GLenum pname, GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002010{
Till Rathmannb8543632018-10-02 19:46:14 +02002011 const Texture *const texture = getTargetTexture(target);
He Yunchao010e4db2017-03-03 14:22:06 +08002012 QueryTexParameterfv(texture, pname, params);
2013}
2014
Brandon Jones59770802018-04-02 13:18:42 -07002015void Context::getTexParameterfvRobust(TextureType target,
2016 GLenum pname,
2017 GLsizei bufSize,
2018 GLsizei *length,
2019 GLfloat *params)
2020{
2021 getTexParameterfv(target, pname, params);
2022}
2023
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002024void Context::getTexParameteriv(TextureType target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002025{
Till Rathmannb8543632018-10-02 19:46:14 +02002026 const Texture *const texture = getTargetTexture(target);
He Yunchao010e4db2017-03-03 14:22:06 +08002027 QueryTexParameteriv(texture, pname, params);
2028}
Jiajia Qin5451d532017-11-16 17:16:34 +08002029
Till Rathmannb8543632018-10-02 19:46:14 +02002030void Context::getTexParameterIiv(TextureType target, GLenum pname, GLint *params)
2031{
2032 const Texture *const texture = getTargetTexture(target);
2033 QueryTexParameterIiv(texture, pname, params);
2034}
2035
2036void Context::getTexParameterIuiv(TextureType target, GLenum pname, GLuint *params)
2037{
2038 const Texture *const texture = getTargetTexture(target);
2039 QueryTexParameterIuiv(texture, pname, params);
2040}
2041
Brandon Jones59770802018-04-02 13:18:42 -07002042void Context::getTexParameterivRobust(TextureType target,
2043 GLenum pname,
2044 GLsizei bufSize,
2045 GLsizei *length,
2046 GLint *params)
2047{
2048 getTexParameteriv(target, pname, params);
2049}
2050
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002051void Context::getTexParameterIivRobust(TextureType target,
2052 GLenum pname,
2053 GLsizei bufSize,
2054 GLsizei *length,
2055 GLint *params)
2056{
2057 UNIMPLEMENTED();
2058}
2059
2060void Context::getTexParameterIuivRobust(TextureType target,
2061 GLenum pname,
2062 GLsizei bufSize,
2063 GLsizei *length,
2064 GLuint *params)
2065{
2066 UNIMPLEMENTED();
2067}
2068
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002069void Context::getTexLevelParameteriv(TextureTarget target, GLint level, GLenum pname, GLint *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002070{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002071 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002072 QueryTexLevelParameteriv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002073}
2074
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002075void Context::getTexLevelParameterivRobust(TextureTarget target,
2076 GLint level,
2077 GLenum pname,
2078 GLsizei bufSize,
2079 GLsizei *length,
2080 GLint *params)
2081{
2082 UNIMPLEMENTED();
2083}
2084
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002085void Context::getTexLevelParameterfv(TextureTarget target,
2086 GLint level,
2087 GLenum pname,
2088 GLfloat *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002089{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002090 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002091 QueryTexLevelParameterfv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002092}
2093
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002094void Context::getTexLevelParameterfvRobust(TextureTarget target,
2095 GLint level,
2096 GLenum pname,
2097 GLsizei bufSize,
2098 GLsizei *length,
2099 GLfloat *params)
2100{
2101 UNIMPLEMENTED();
2102}
2103
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002104void Context::texParameterf(TextureType target, GLenum pname, GLfloat param)
He Yunchao010e4db2017-03-03 14:22:06 +08002105{
Till Rathmannb8543632018-10-02 19:46:14 +02002106 Texture *const texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002107 SetTexParameterf(this, texture, pname, param);
He Yunchao010e4db2017-03-03 14:22:06 +08002108}
2109
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002110void Context::texParameterfv(TextureType target, GLenum pname, const GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002111{
Till Rathmannb8543632018-10-02 19:46:14 +02002112 Texture *const texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002113 SetTexParameterfv(this, texture, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08002114}
2115
Brandon Jones59770802018-04-02 13:18:42 -07002116void Context::texParameterfvRobust(TextureType target,
2117 GLenum pname,
2118 GLsizei bufSize,
2119 const GLfloat *params)
2120{
2121 texParameterfv(target, pname, params);
2122}
2123
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002124void Context::texParameteri(TextureType target, GLenum pname, GLint param)
He Yunchao010e4db2017-03-03 14:22:06 +08002125{
Till Rathmannb8543632018-10-02 19:46:14 +02002126 Texture *const texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002127 SetTexParameteri(this, texture, pname, param);
He Yunchao010e4db2017-03-03 14:22:06 +08002128}
2129
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002130void Context::texParameteriv(TextureType target, GLenum pname, const GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002131{
Till Rathmannb8543632018-10-02 19:46:14 +02002132 Texture *const texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002133 SetTexParameteriv(this, texture, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08002134}
2135
Till Rathmannb8543632018-10-02 19:46:14 +02002136void Context::texParameterIiv(TextureType target, GLenum pname, const GLint *params)
2137{
2138 Texture *const texture = getTargetTexture(target);
2139 SetTexParameterIiv(this, texture, pname, params);
Till Rathmannb8543632018-10-02 19:46:14 +02002140}
2141
2142void Context::texParameterIuiv(TextureType target, GLenum pname, const GLuint *params)
2143{
2144 Texture *const texture = getTargetTexture(target);
2145 SetTexParameterIuiv(this, texture, pname, params);
Till Rathmannb8543632018-10-02 19:46:14 +02002146}
2147
Brandon Jones59770802018-04-02 13:18:42 -07002148void Context::texParameterivRobust(TextureType target,
2149 GLenum pname,
2150 GLsizei bufSize,
2151 const GLint *params)
2152{
2153 texParameteriv(target, pname, params);
2154}
2155
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002156void Context::texParameterIivRobust(TextureType target,
2157 GLenum pname,
2158 GLsizei bufSize,
2159 const GLint *params)
2160{
2161 UNIMPLEMENTED();
2162}
2163
2164void Context::texParameterIuivRobust(TextureType target,
2165 GLenum pname,
2166 GLsizei bufSize,
2167 const GLuint *params)
2168{
2169 UNIMPLEMENTED();
2170}
2171
Jamie Madill493f9572018-05-24 19:52:15 -04002172void Context::drawArraysInstanced(PrimitiveMode mode,
2173 GLint first,
2174 GLsizei count,
2175 GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04002176{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002177 // No-op if count draws no primitives for given mode
2178 if (noopDrawInstanced(mode, count, instanceCount))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002179 {
2180 return;
2181 }
2182
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002183 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002184 ANGLE_CONTEXT_TRY(
2185 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
Jamie Madillae6ba9f2018-12-21 23:00:04 -05002186 MarkTransformFeedbackBufferUsage(this, count, instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -04002187}
2188
Jamie Madill493f9572018-05-24 19:52:15 -04002189void Context::drawElementsInstanced(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002190 GLsizei count,
Jamie Madill8dc27f92018-11-29 11:45:44 -05002191 DrawElementsType type,
Jamie Madill876429b2017-04-20 15:46:24 -04002192 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04002193 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04002194{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002195 // No-op if count draws no primitives for given mode
2196 if (noopDrawInstanced(mode, count, instances))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002197 {
2198 return;
2199 }
2200
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002201 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002202 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08002203 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04002204}
2205
Jamie Madill493f9572018-05-24 19:52:15 -04002206void Context::drawRangeElements(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002207 GLuint start,
2208 GLuint end,
2209 GLsizei count,
Jamie Madill8dc27f92018-11-29 11:45:44 -05002210 DrawElementsType type,
Jamie Madill876429b2017-04-20 15:46:24 -04002211 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04002212{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002213 // No-op if count draws no primitives for given mode
2214 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002215 {
2216 return;
2217 }
2218
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002219 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002220 ANGLE_CONTEXT_TRY(
2221 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002222}
2223
Jamie Madill493f9572018-05-24 19:52:15 -04002224void Context::drawArraysIndirect(PrimitiveMode mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002225{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002226 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002227 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002228}
2229
Jamie Madill8dc27f92018-11-29 11:45:44 -05002230void Context::drawElementsIndirect(PrimitiveMode mode, DrawElementsType type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002231{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002232 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002233 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002234}
2235
Jamie Madill675fe712016-12-19 13:07:54 -05002236void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002237{
Jamie Madill4f6592f2018-11-27 16:37:45 -05002238 ANGLE_CONTEXT_TRY(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05002239}
2240
Jamie Madill675fe712016-12-19 13:07:54 -05002241void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05002242{
Jamie Madill4f6592f2018-11-27 16:37:45 -05002243 ANGLE_CONTEXT_TRY(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002244}
2245
Austin Kinross6ee1e782015-05-29 17:05:37 -07002246void Context::insertEventMarker(GLsizei length, const char *marker)
2247{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002248 ASSERT(mImplementation);
2249 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07002250}
2251
2252void Context::pushGroupMarker(GLsizei length, const char *marker)
2253{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002254 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05002255
2256 if (marker == nullptr)
2257 {
2258 // From the EXT_debug_marker spec,
2259 // "If <marker> is null then an empty string is pushed on the stack."
2260 mImplementation->pushGroupMarker(length, "");
2261 }
2262 else
2263 {
2264 mImplementation->pushGroupMarker(length, marker);
2265 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07002266}
2267
2268void Context::popGroupMarker()
2269{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002270 ASSERT(mImplementation);
2271 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07002272}
2273
Geoff Langd8605522016-04-13 10:19:12 -04002274void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
2275{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002276 Program *programObject = getProgramResolveLink(program);
Geoff Langd8605522016-04-13 10:19:12 -04002277 ASSERT(programObject);
2278
2279 programObject->bindUniformLocation(location, name);
2280}
2281
Brandon Jones59770802018-04-02 13:18:42 -07002282void Context::coverageModulation(GLenum components)
Sami Väisänena797e062016-05-12 15:23:40 +03002283{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002284 mState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03002285}
2286
Brandon Jones59770802018-04-02 13:18:42 -07002287void Context::matrixLoadf(GLenum matrixMode, const GLfloat *matrix)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002288{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002289 mState.loadPathRenderingMatrix(matrixMode, matrix);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002290}
2291
Brandon Jones59770802018-04-02 13:18:42 -07002292void Context::matrixLoadIdentity(GLenum matrixMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002293{
2294 GLfloat I[16];
2295 angle::Matrix<GLfloat>::setToIdentity(I);
2296
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002297 mState.loadPathRenderingMatrix(matrixMode, I);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002298}
2299
2300void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
2301{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002302 const auto *pathObj = mState.mPathManager->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002303 if (!pathObj)
2304 return;
2305
Geoff Lang9bf86f02018-07-26 11:46:34 -04002306 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002307
2308 mImplementation->stencilFillPath(pathObj, fillMode, mask);
2309}
2310
2311void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
2312{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002313 const auto *pathObj = mState.mPathManager->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002314 if (!pathObj)
2315 return;
2316
Geoff Lang9bf86f02018-07-26 11:46:34 -04002317 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002318
2319 mImplementation->stencilStrokePath(pathObj, reference, mask);
2320}
2321
2322void Context::coverFillPath(GLuint path, GLenum coverMode)
2323{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002324 const auto *pathObj = mState.mPathManager->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002325 if (!pathObj)
2326 return;
2327
Geoff Lang9bf86f02018-07-26 11:46:34 -04002328 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002329
2330 mImplementation->coverFillPath(pathObj, coverMode);
2331}
2332
2333void Context::coverStrokePath(GLuint path, GLenum coverMode)
2334{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002335 const auto *pathObj = mState.mPathManager->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002336 if (!pathObj)
2337 return;
2338
Geoff Lang9bf86f02018-07-26 11:46:34 -04002339 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002340
2341 mImplementation->coverStrokePath(pathObj, coverMode);
2342}
2343
2344void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
2345{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002346 const auto *pathObj = mState.mPathManager->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002347 if (!pathObj)
2348 return;
2349
Geoff Lang9bf86f02018-07-26 11:46:34 -04002350 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002351
2352 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
2353}
2354
2355void Context::stencilThenCoverStrokePath(GLuint path,
2356 GLint reference,
2357 GLuint mask,
2358 GLenum coverMode)
2359{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002360 const auto *pathObj = mState.mPathManager->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002361 if (!pathObj)
2362 return;
2363
Geoff Lang9bf86f02018-07-26 11:46:34 -04002364 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002365
2366 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2367}
2368
Sami Väisänend59ca052016-06-21 16:10:00 +03002369void Context::coverFillPathInstanced(GLsizei numPaths,
2370 GLenum pathNameType,
2371 const void *paths,
2372 GLuint pathBase,
2373 GLenum coverMode,
2374 GLenum transformType,
2375 const GLfloat *transformValues)
2376{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002377 const auto &pathObjects =
2378 GatherPaths(*mState.mPathManager, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002379
Geoff Lang9bf86f02018-07-26 11:46:34 -04002380 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002381
2382 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2383}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002384
Sami Väisänend59ca052016-06-21 16:10:00 +03002385void Context::coverStrokePathInstanced(GLsizei numPaths,
2386 GLenum pathNameType,
2387 const void *paths,
2388 GLuint pathBase,
2389 GLenum coverMode,
2390 GLenum transformType,
2391 const GLfloat *transformValues)
2392{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002393 const auto &pathObjects =
2394 GatherPaths(*mState.mPathManager, 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 Lang9bf86f02018-07-26 11:46:34 -04002397 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002398
2399 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2400 transformValues);
2401}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002402
Sami Väisänend59ca052016-06-21 16:10:00 +03002403void Context::stencilFillPathInstanced(GLsizei numPaths,
2404 GLenum pathNameType,
2405 const void *paths,
2406 GLuint pathBase,
2407 GLenum fillMode,
2408 GLuint mask,
2409 GLenum transformType,
2410 const GLfloat *transformValues)
2411{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002412 const auto &pathObjects =
2413 GatherPaths(*mState.mPathManager, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002414
2415 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Lang9bf86f02018-07-26 11:46:34 -04002416 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002417
2418 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2419 transformValues);
2420}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002421
Sami Väisänend59ca052016-06-21 16:10:00 +03002422void Context::stencilStrokePathInstanced(GLsizei numPaths,
2423 GLenum pathNameType,
2424 const void *paths,
2425 GLuint pathBase,
2426 GLint reference,
2427 GLuint mask,
2428 GLenum transformType,
2429 const GLfloat *transformValues)
2430{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002431 const auto &pathObjects =
2432 GatherPaths(*mState.mPathManager, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002433
Geoff Lang9bf86f02018-07-26 11:46:34 -04002434 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002435
2436 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2437 transformValues);
2438}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002439
Sami Väisänend59ca052016-06-21 16:10:00 +03002440void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2441 GLenum pathNameType,
2442 const void *paths,
2443 GLuint pathBase,
2444 GLenum fillMode,
2445 GLuint mask,
2446 GLenum coverMode,
2447 GLenum transformType,
2448 const GLfloat *transformValues)
2449{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002450 const auto &pathObjects =
2451 GatherPaths(*mState.mPathManager, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002452
Geoff Lang9bf86f02018-07-26 11:46:34 -04002453 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002454
2455 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2456 transformType, transformValues);
2457}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002458
Sami Väisänend59ca052016-06-21 16:10:00 +03002459void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2460 GLenum pathNameType,
2461 const void *paths,
2462 GLuint pathBase,
2463 GLint reference,
2464 GLuint mask,
2465 GLenum coverMode,
2466 GLenum transformType,
2467 const GLfloat *transformValues)
2468{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002469 const auto &pathObjects =
2470 GatherPaths(*mState.mPathManager, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002471
Geoff Lang9bf86f02018-07-26 11:46:34 -04002472 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002473
2474 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2475 transformType, transformValues);
2476}
2477
Sami Väisänen46eaa942016-06-29 10:26:37 +03002478void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2479{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002480 auto *programObject = getProgramResolveLink(program);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002481
2482 programObject->bindFragmentInputLocation(location, name);
2483}
2484
2485void Context::programPathFragmentInputGen(GLuint program,
2486 GLint location,
2487 GLenum genMode,
2488 GLint components,
2489 const GLfloat *coeffs)
2490{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002491 auto *programObject = getProgramResolveLink(program);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002492
jchen103fd614d2018-08-13 12:21:58 +08002493 programObject->pathFragmentInputGen(location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002494}
2495
jchen1015015f72017-03-16 13:54:21 +08002496GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2497{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002498 const Program *programObject = getProgramResolveLink(program);
jchen1015015f72017-03-16 13:54:21 +08002499 return QueryProgramResourceIndex(programObject, programInterface, name);
2500}
2501
jchen10fd7c3b52017-03-21 15:36:03 +08002502void Context::getProgramResourceName(GLuint program,
2503 GLenum programInterface,
2504 GLuint index,
2505 GLsizei bufSize,
2506 GLsizei *length,
2507 GLchar *name)
2508{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002509 const Program *programObject = getProgramResolveLink(program);
jchen10fd7c3b52017-03-21 15:36:03 +08002510 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2511}
2512
jchen10191381f2017-04-11 13:59:04 +08002513GLint Context::getProgramResourceLocation(GLuint program,
2514 GLenum programInterface,
2515 const GLchar *name)
2516{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002517 const Program *programObject = getProgramResolveLink(program);
jchen10191381f2017-04-11 13:59:04 +08002518 return QueryProgramResourceLocation(programObject, programInterface, name);
2519}
2520
jchen10880683b2017-04-12 16:21:55 +08002521void Context::getProgramResourceiv(GLuint program,
2522 GLenum programInterface,
2523 GLuint index,
2524 GLsizei propCount,
2525 const GLenum *props,
2526 GLsizei bufSize,
2527 GLsizei *length,
2528 GLint *params)
2529{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002530 const Program *programObject = getProgramResolveLink(program);
jchen10880683b2017-04-12 16:21:55 +08002531 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2532 length, params);
2533}
2534
jchen10d9cd7b72017-08-30 15:04:25 +08002535void Context::getProgramInterfaceiv(GLuint program,
2536 GLenum programInterface,
2537 GLenum pname,
2538 GLint *params)
2539{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002540 const Program *programObject = getProgramResolveLink(program);
jchen10d9cd7b72017-08-30 15:04:25 +08002541 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2542}
2543
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002544void Context::getProgramInterfaceivRobust(GLuint program,
2545 GLenum programInterface,
2546 GLenum pname,
2547 GLsizei bufSize,
2548 GLsizei *length,
2549 GLint *params)
2550{
2551 UNIMPLEMENTED();
2552}
2553
Jamie Madillabfbc0f2018-10-09 12:48:52 -04002554void Context::handleError(GLenum errorCode,
2555 const char *message,
2556 const char *file,
2557 const char *function,
2558 unsigned int line)
2559{
2560 mErrors.handleError(errorCode, message, file, function, line);
2561}
2562
Jamie Madilla139f012018-10-10 16:13:03 -04002563void Context::validationError(GLenum errorCode, const char *message)
2564{
2565 mErrors.validationError(errorCode, message);
2566}
2567
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002568// Get one of the recorded errors and clear its flag, if any.
2569// [OpenGL ES 2.0.24] section 2.5 page 13.
2570GLenum Context::getError()
2571{
Geoff Langda5777c2014-07-11 09:52:58 -04002572 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002573 {
Geoff Langda5777c2014-07-11 09:52:58 -04002574 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002575 }
Geoff Langda5777c2014-07-11 09:52:58 -04002576 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002577 {
Jamie Madill6b873dd2018-07-12 23:56:30 -04002578 return mErrors.popError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002579 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002580}
2581
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002582// NOTE: this function should not assume that this context is current!
Jamie Madill6b873dd2018-07-12 23:56:30 -04002583void Context::markContextLost()
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002584{
2585 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002586 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002587 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002588 mContextLostForced = true;
2589 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002590 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002591}
2592
Jamie Madillfa920eb2018-01-04 11:45:50 -05002593GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002594{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002595 // Even if the application doesn't want to know about resets, we want to know
2596 // as it will allow us to skip all the calls.
2597 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002598 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002599 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002600 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002601 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002602 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002603
2604 // EXT_robustness, section 2.6: If the reset notification behavior is
2605 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2606 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2607 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002608 }
2609
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002610 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2611 // status should be returned at least once, and GL_NO_ERROR should be returned
2612 // once the device has finished resetting.
2613 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002614 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002615 ASSERT(mResetStatus == GL_NO_ERROR);
2616 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002617
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002618 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002619 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002620 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002621 }
2622 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002623 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002624 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002625 // If markContextLost was used to mark the context lost then
2626 // assume that is not recoverable, and continue to report the
2627 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002628 mResetStatus = mImplementation->getResetStatus();
2629 }
Jamie Madill893ab082014-05-16 16:56:10 -04002630
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002631 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002632}
2633
2634bool Context::isResetNotificationEnabled()
2635{
2636 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2637}
2638
Corentin Walleze3b10e82015-05-20 11:06:25 -04002639const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002640{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002641 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002642}
2643
2644EGLenum Context::getClientType() const
2645{
2646 return mClientType;
2647}
2648
2649EGLenum Context::getRenderBuffer() const
2650{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002651 const Framebuffer *framebuffer = mState.mFramebufferManager->getFramebuffer(0);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002652 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002653 {
2654 return EGL_NONE;
2655 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002656
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002657 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002658 ASSERT(backAttachment != nullptr);
2659 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002660}
2661
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002662VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002663{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002664 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002665 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2666 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002667 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002668 vertexArray =
2669 new VertexArray(mImplementation.get(), vertexArrayHandle,
2670 mState.mCaps.maxVertexAttributes, mState.mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002671
Jamie Madill96a483b2017-06-27 16:49:21 -04002672 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002673 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002674
2675 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002676}
2677
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002678TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002679{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002680 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002681 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2682 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002683 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002684 transformFeedback =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002685 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mState.mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002686 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002687 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002688 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002689
2690 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002691}
2692
2693bool Context::isVertexArrayGenerated(GLuint vertexArray)
2694{
Jamie Madill96a483b2017-06-27 16:49:21 -04002695 ASSERT(mVertexArrayMap.contains(0));
2696 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002697}
2698
2699bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2700{
Jamie Madill96a483b2017-06-27 16:49:21 -04002701 ASSERT(mTransformFeedbackMap.contains(0));
2702 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002703}
2704
Shannon Woods53a94a82014-06-24 15:20:36 -04002705void Context::detachTexture(GLuint texture)
2706{
2707 // Simple pass-through to State's detachTexture method, as textures do not require
2708 // allocation map management either here or in the resource manager at detach time.
2709 // Zero textures are held by the Context, and we don't attempt to request them from
2710 // the State.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002711 mState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002712}
2713
James Darpinian4d9d4832018-03-13 12:43:28 -07002714void Context::detachBuffer(Buffer *buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002715{
Yuly Novikov5807a532015-12-03 13:01:22 -05002716 // Simple pass-through to State's detachBuffer method, since
2717 // only buffer attachments to container objects that are bound to the current context
2718 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002719
Yuly Novikov5807a532015-12-03 13:01:22 -05002720 // [OpenGL ES 3.2] section 5.1.2 page 45:
2721 // Attachments to unbound container objects, such as
2722 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2723 // are not affected and continue to act as references on the deleted object
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002724 ANGLE_CONTEXT_TRY(mState.detachBuffer(this, buffer));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002725}
2726
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002727void Context::detachFramebuffer(GLuint framebuffer)
2728{
Shannon Woods53a94a82014-06-24 15:20:36 -04002729 // Framebuffer detachment is handled by Context, because 0 is a valid
2730 // Framebuffer object, and a pointer to it must be passed from Context
2731 // to State at binding time.
2732
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002733 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002734 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2735 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2736 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002737
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002738 if (mState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002739 {
2740 bindReadFramebuffer(0);
2741 }
2742
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002743 if (mState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002744 {
2745 bindDrawFramebuffer(0);
2746 }
2747}
2748
2749void Context::detachRenderbuffer(GLuint renderbuffer)
2750{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002751 mState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002752}
2753
Jamie Madill57a89722013-07-02 11:57:03 -04002754void Context::detachVertexArray(GLuint vertexArray)
2755{
Jamie Madill77a72f62015-04-14 11:18:32 -04002756 // Vertex array detachment is handled by Context, because 0 is a valid
2757 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002758 // binding time.
2759
Jamie Madill57a89722013-07-02 11:57:03 -04002760 // [OpenGL ES 3.0.2] section 2.10 page 43:
2761 // If a vertex array object that is currently bound is deleted, the binding
2762 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002763 if (mState.removeVertexArrayBinding(this, vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002764 {
2765 bindVertexArray(0);
2766 }
2767}
2768
Geoff Langc8058452014-02-03 12:04:11 -05002769void Context::detachTransformFeedback(GLuint transformFeedback)
2770{
Corentin Walleza2257da2016-04-19 16:43:12 -04002771 // Transform feedback detachment is handled by Context, because 0 is a valid
2772 // transform feedback, and a pointer to it must be passed from Context to State at
2773 // binding time.
2774
2775 // The OpenGL specification doesn't mention what should happen when the currently bound
2776 // transform feedback object is deleted. Since it is a container object, we treat it like
2777 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002778 if (mState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002779 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002780 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002781 }
Geoff Langc8058452014-02-03 12:04:11 -05002782}
2783
Jamie Madilldc356042013-07-19 16:36:57 -04002784void Context::detachSampler(GLuint sampler)
2785{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002786 mState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002787}
2788
Yunchao Hea336b902017-08-02 16:05:21 +08002789void Context::detachProgramPipeline(GLuint pipeline)
2790{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002791 mState.detachProgramPipeline(this, pipeline);
Yunchao Hea336b902017-08-02 16:05:21 +08002792}
2793
Jamie Madill3ef140a2017-08-26 23:11:21 -04002794void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002795{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002796 mState.setVertexAttribDivisor(this, index, divisor);
Jamie Madillc43cdad2018-08-08 15:49:25 -04002797 mStateCache.onVertexArrayStateChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002798}
2799
Jamie Madille29d1672013-07-19 16:36:57 -04002800void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2801{
Till Rathmannb8543632018-10-02 19:46:14 +02002802 Sampler *const samplerObject =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002803 mState.mSamplerManager->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002804 SetSamplerParameteri(this, samplerObject, pname, param);
Geoff Langc1984ed2016-10-07 12:41:00 -04002805}
Jamie Madille29d1672013-07-19 16:36:57 -04002806
Geoff Langc1984ed2016-10-07 12:41:00 -04002807void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2808{
Till Rathmannb8543632018-10-02 19:46:14 +02002809 Sampler *const samplerObject =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002810 mState.mSamplerManager->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002811 SetSamplerParameteriv(this, samplerObject, pname, param);
Jamie Madille29d1672013-07-19 16:36:57 -04002812}
2813
Till Rathmannb8543632018-10-02 19:46:14 +02002814void Context::samplerParameterIiv(GLuint sampler, GLenum pname, const GLint *param)
2815{
2816 Sampler *const samplerObject =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002817 mState.mSamplerManager->checkSamplerAllocation(mImplementation.get(), sampler);
Till Rathmannb8543632018-10-02 19:46:14 +02002818 SetSamplerParameterIiv(this, samplerObject, pname, param);
2819}
2820
2821void Context::samplerParameterIuiv(GLuint sampler, GLenum pname, const GLuint *param)
2822{
2823 Sampler *const samplerObject =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002824 mState.mSamplerManager->checkSamplerAllocation(mImplementation.get(), sampler);
Till Rathmannb8543632018-10-02 19:46:14 +02002825 SetSamplerParameterIuiv(this, samplerObject, pname, param);
2826}
2827
Brandon Jones59770802018-04-02 13:18:42 -07002828void Context::samplerParameterivRobust(GLuint sampler,
2829 GLenum pname,
2830 GLsizei bufSize,
2831 const GLint *param)
2832{
2833 samplerParameteriv(sampler, pname, param);
2834}
2835
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002836void Context::samplerParameterIivRobust(GLuint sampler,
2837 GLenum pname,
2838 GLsizei bufSize,
2839 const GLint *param)
2840{
2841 UNIMPLEMENTED();
2842}
2843
2844void Context::samplerParameterIuivRobust(GLuint sampler,
2845 GLenum pname,
2846 GLsizei bufSize,
2847 const GLuint *param)
2848{
2849 UNIMPLEMENTED();
2850}
2851
Jamie Madille29d1672013-07-19 16:36:57 -04002852void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2853{
Till Rathmannb8543632018-10-02 19:46:14 +02002854 Sampler *const samplerObject =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002855 mState.mSamplerManager->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002856 SetSamplerParameterf(this, samplerObject, pname, param);
Jamie Madille29d1672013-07-19 16:36:57 -04002857}
2858
Geoff Langc1984ed2016-10-07 12:41:00 -04002859void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002860{
Till Rathmannb8543632018-10-02 19:46:14 +02002861 Sampler *const samplerObject =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002862 mState.mSamplerManager->checkSamplerAllocation(mImplementation.get(), sampler);
Jamie Madille25b8002018-09-20 13:39:49 -04002863 SetSamplerParameterfv(this, samplerObject, pname, param);
Jamie Madill9675b802013-07-19 16:36:59 -04002864}
2865
Brandon Jones59770802018-04-02 13:18:42 -07002866void Context::samplerParameterfvRobust(GLuint sampler,
2867 GLenum pname,
2868 GLsizei bufSize,
2869 const GLfloat *param)
2870{
2871 samplerParameterfv(sampler, pname, param);
2872}
2873
Geoff Langc1984ed2016-10-07 12:41:00 -04002874void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002875{
Till Rathmannb8543632018-10-02 19:46:14 +02002876 const Sampler *const samplerObject =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002877 mState.mSamplerManager->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002878 QuerySamplerParameteriv(samplerObject, pname, params);
2879}
Jamie Madill9675b802013-07-19 16:36:59 -04002880
Till Rathmannb8543632018-10-02 19:46:14 +02002881void Context::getSamplerParameterIiv(GLuint sampler, GLenum pname, GLint *params)
2882{
2883 const Sampler *const samplerObject =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002884 mState.mSamplerManager->checkSamplerAllocation(mImplementation.get(), sampler);
Till Rathmannb8543632018-10-02 19:46:14 +02002885 QuerySamplerParameterIiv(samplerObject, pname, params);
2886}
2887
2888void Context::getSamplerParameterIuiv(GLuint sampler, GLenum pname, GLuint *params)
2889{
2890 const Sampler *const samplerObject =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002891 mState.mSamplerManager->checkSamplerAllocation(mImplementation.get(), sampler);
Till Rathmannb8543632018-10-02 19:46:14 +02002892 QuerySamplerParameterIuiv(samplerObject, pname, params);
2893}
2894
Brandon Jones59770802018-04-02 13:18:42 -07002895void Context::getSamplerParameterivRobust(GLuint sampler,
2896 GLenum pname,
2897 GLsizei bufSize,
2898 GLsizei *length,
2899 GLint *params)
2900{
2901 getSamplerParameteriv(sampler, pname, params);
2902}
2903
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002904void Context::getSamplerParameterIivRobust(GLuint sampler,
2905 GLenum pname,
2906 GLsizei bufSize,
2907 GLsizei *length,
2908 GLint *params)
2909{
2910 UNIMPLEMENTED();
2911}
2912
2913void Context::getSamplerParameterIuivRobust(GLuint sampler,
2914 GLenum pname,
2915 GLsizei bufSize,
2916 GLsizei *length,
2917 GLuint *params)
2918{
2919 UNIMPLEMENTED();
2920}
2921
Geoff Langc1984ed2016-10-07 12:41:00 -04002922void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2923{
Till Rathmannb8543632018-10-02 19:46:14 +02002924 const Sampler *const samplerObject =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002925 mState.mSamplerManager->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002926 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill9675b802013-07-19 16:36:59 -04002927}
2928
Brandon Jones59770802018-04-02 13:18:42 -07002929void Context::getSamplerParameterfvRobust(GLuint sampler,
2930 GLenum pname,
2931 GLsizei bufSize,
2932 GLsizei *length,
2933 GLfloat *params)
2934{
2935 getSamplerParameterfv(sampler, pname, params);
2936}
2937
Olli Etuahof0fee072016-03-30 15:11:58 +03002938void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2939{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04002940 gl::Program *programObject = getProgramResolveLink(program);
Yunchao He61afff12017-03-14 15:34:03 +08002941 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002942}
2943
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002944void Context::initRendererString()
2945{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002946 std::ostringstream rendererString;
2947 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002948 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002949 rendererString << ")";
2950
Geoff Langcec35902014-04-16 10:52:36 -04002951 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002952}
2953
Geoff Langc339c4e2016-11-29 10:37:36 -05002954void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002955{
Geoff Langc339c4e2016-11-29 10:37:36 -05002956 const Version &clientVersion = getClientVersion();
2957
2958 std::ostringstream versionString;
2959 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2960 << ANGLE_VERSION_STRING << ")";
2961 mVersionString = MakeStaticString(versionString.str());
2962
2963 std::ostringstream shadingLanguageVersionString;
2964 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2965 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2966 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2967 << ")";
2968 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002969}
2970
Geoff Langcec35902014-04-16 10:52:36 -04002971void Context::initExtensionStrings()
2972{
Geoff Langc339c4e2016-11-29 10:37:36 -05002973 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2974 std::ostringstream combinedStringStream;
2975 std::copy(strings.begin(), strings.end(),
2976 std::ostream_iterator<const char *>(combinedStringStream, " "));
2977 return MakeStaticString(combinedStringStream.str());
2978 };
2979
2980 mExtensionStrings.clear();
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002981 for (const auto &extensionString : mState.mExtensions.getStrings())
Geoff Langc287ea62016-09-16 14:46:51 -04002982 {
2983 mExtensionStrings.push_back(MakeStaticString(extensionString));
2984 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002985 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002986
Geoff Langc339c4e2016-11-29 10:37:36 -05002987 mRequestableExtensionStrings.clear();
2988 for (const auto &extensionInfo : GetExtensionInfoMap())
2989 {
2990 if (extensionInfo.second.Requestable &&
Jamie Madillc3dc5d42018-12-30 12:12:04 -05002991 !(mState.mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
Geoff Langb0f917f2017-12-05 13:41:54 -05002992 mSupportedExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002993 {
2994 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
2995 }
2996 }
2997 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002998}
2999
Geoff Langc339c4e2016-11-29 10:37:36 -05003000const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04003001{
Geoff Langc339c4e2016-11-29 10:37:36 -05003002 switch (name)
3003 {
3004 case GL_VENDOR:
3005 return reinterpret_cast<const GLubyte *>("Google Inc.");
3006
3007 case GL_RENDERER:
3008 return reinterpret_cast<const GLubyte *>(mRendererString);
3009
3010 case GL_VERSION:
3011 return reinterpret_cast<const GLubyte *>(mVersionString);
3012
3013 case GL_SHADING_LANGUAGE_VERSION:
3014 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
3015
3016 case GL_EXTENSIONS:
3017 return reinterpret_cast<const GLubyte *>(mExtensionString);
3018
3019 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
3020 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
3021
3022 default:
3023 UNREACHABLE();
3024 return nullptr;
3025 }
Geoff Langcec35902014-04-16 10:52:36 -04003026}
3027
Geoff Langc339c4e2016-11-29 10:37:36 -05003028const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04003029{
Geoff Langc339c4e2016-11-29 10:37:36 -05003030 switch (name)
3031 {
3032 case GL_EXTENSIONS:
3033 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
3034
3035 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
3036 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
3037
3038 default:
3039 UNREACHABLE();
3040 return nullptr;
3041 }
Geoff Langcec35902014-04-16 10:52:36 -04003042}
3043
3044size_t Context::getExtensionStringCount() const
3045{
3046 return mExtensionStrings.size();
3047}
3048
Geoff Lang111a99e2017-10-17 10:58:41 -04003049bool Context::isExtensionRequestable(const char *name)
3050{
3051 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3052 auto extension = extensionInfos.find(name);
3053
Geoff Lang111a99e2017-10-17 10:58:41 -04003054 return extension != extensionInfos.end() && extension->second.Requestable &&
Geoff Langb0f917f2017-12-05 13:41:54 -05003055 mSupportedExtensions.*(extension->second.ExtensionsMember);
Geoff Lang111a99e2017-10-17 10:58:41 -04003056}
3057
Geoff Langc339c4e2016-11-29 10:37:36 -05003058void Context::requestExtension(const char *name)
3059{
3060 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3061 ASSERT(extensionInfos.find(name) != extensionInfos.end());
3062 const auto &extension = extensionInfos.at(name);
3063 ASSERT(extension.Requestable);
Geoff Langb0f917f2017-12-05 13:41:54 -05003064 ASSERT(isExtensionRequestable(name));
Geoff Langc339c4e2016-11-29 10:37:36 -05003065
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003066 if (mState.mExtensions.*(extension.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05003067 {
3068 // Extension already enabled
3069 return;
3070 }
3071
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003072 mState.mExtensions.*(extension.ExtensionsMember) = true;
Geoff Langc339c4e2016-11-29 10:37:36 -05003073 updateCaps();
3074 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08003075
Jamie Madill2f348d22017-06-05 10:50:59 -04003076 // Release the shader compiler so it will be re-created with the requested extensions enabled.
3077 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04003078
Jamie Madill81c2e252017-09-09 23:32:46 -04003079 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
3080 // sampleable.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003081 mState.mTextureManager->signalAllTexturesDirty(this);
Geoff Lang9aded172017-04-05 11:07:56 -04003082 for (auto &zeroTexture : mZeroTextures)
3083 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003084 if (zeroTexture.get() != nullptr)
3085 {
Jamie Madille3e680c2018-12-03 17:49:08 -05003086 zeroTexture->signalDirtyStorage(this, InitState::Initialized);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003087 }
Geoff Lang9aded172017-04-05 11:07:56 -04003088 }
3089
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003090 mState.mFramebufferManager->invalidateFramebufferComplenessCache(this);
Geoff Langc339c4e2016-11-29 10:37:36 -05003091}
3092
3093size_t Context::getRequestableExtensionStringCount() const
3094{
3095 return mRequestableExtensionStrings.size();
3096}
3097
Jamie Madill493f9572018-05-24 19:52:15 -04003098void Context::beginTransformFeedback(PrimitiveMode primitiveMode)
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003099{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003100 TransformFeedback *transformFeedback = mState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003101 ASSERT(transformFeedback != nullptr);
3102 ASSERT(!transformFeedback->isPaused());
3103
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003104 ANGLE_CONTEXT_TRY(transformFeedback->begin(this, primitiveMode, mState.getProgram()));
Jamie Madill3a256222018-12-08 09:56:39 -05003105 mStateCache.onActiveTransformFeedbackChange(this);
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003106}
3107
3108bool Context::hasActiveTransformFeedback(GLuint program) const
3109{
3110 for (auto pair : mTransformFeedbackMap)
3111 {
3112 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
3113 {
3114 return true;
3115 }
3116 }
3117 return false;
3118}
3119
Geoff Lang33f11fb2018-05-07 13:42:47 -04003120Extensions Context::generateSupportedExtensions() const
Geoff Langb0f917f2017-12-05 13:41:54 -05003121{
3122 Extensions supportedExtensions = mImplementation->getNativeExtensions();
3123
jchen1082af6202018-06-22 10:59:52 +08003124 // Explicitly enable GL_KHR_parallel_shader_compile
3125 supportedExtensions.parallelShaderCompile = true;
3126
Geoff Langb0f917f2017-12-05 13:41:54 -05003127 if (getClientVersion() < ES_2_0)
3128 {
3129 // Default extensions for GLES1
Lingfeng Yang0df813c2018-07-12 12:52:06 -07003130 supportedExtensions.pointSizeArray = true;
3131 supportedExtensions.textureCubeMap = true;
3132 supportedExtensions.pointSprite = true;
3133 supportedExtensions.drawTexture = true;
jchen1082af6202018-06-22 10:59:52 +08003134 supportedExtensions.parallelShaderCompile = false;
Geoff Langb0f917f2017-12-05 13:41:54 -05003135 }
3136
3137 if (getClientVersion() < ES_3_0)
3138 {
3139 // Disable ES3+ extensions
3140 supportedExtensions.colorBufferFloat = false;
3141 supportedExtensions.eglImageExternalEssl3 = false;
3142 supportedExtensions.textureNorm16 = false;
3143 supportedExtensions.multiview = false;
3144 supportedExtensions.maxViews = 1u;
Brandon Jones4e6f2ae2018-09-19 11:09:51 -07003145 supportedExtensions.copyTexture3d = false;
Yizhou Jiang7818a852018-09-06 15:02:04 +08003146 supportedExtensions.textureMultisample = false;
Geoff Lang7198ebc2018-11-22 14:36:06 -05003147
3148 // Don't expose GL_EXT_texture_sRGB_decode without sRGB texture support
3149 if (!supportedExtensions.sRGB)
3150 {
3151 supportedExtensions.textureSRGBDecode = false;
3152 }
Geoff Langb0f917f2017-12-05 13:41:54 -05003153 }
3154
3155 if (getClientVersion() < ES_3_1)
3156 {
3157 // Disable ES3.1+ extensions
3158 supportedExtensions.geometryShader = false;
Olli Etuahod310a432018-08-24 15:40:23 +03003159
3160 // TODO(http://anglebug.com/2775): Multisample arrays could be supported on ES 3.0 as well
3161 // once 2D multisample texture extension is exposed there.
Olli Etuaho064458a2018-08-30 14:02:02 +03003162 supportedExtensions.textureStorageMultisample2DArray = false;
Geoff Langb0f917f2017-12-05 13:41:54 -05003163 }
3164
3165 if (getClientVersion() > ES_2_0)
3166 {
3167 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
3168 // supportedExtensions.sRGB = false;
3169 }
3170
3171 // Some extensions are always available because they are implemented in the GL layer.
3172 supportedExtensions.bindUniformLocation = true;
3173 supportedExtensions.vertexArrayObject = true;
3174 supportedExtensions.bindGeneratesResource = true;
3175 supportedExtensions.clientArrays = true;
3176 supportedExtensions.requestExtension = true;
Austin Eng7cf9cd22018-10-09 15:27:32 -07003177 supportedExtensions.multiDraw = true;
Geoff Langb0f917f2017-12-05 13:41:54 -05003178
3179 // Enable the no error extension if the context was created with the flag.
3180 supportedExtensions.noError = mSkipValidation;
3181
3182 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Geoff Lang33f11fb2018-05-07 13:42:47 -04003183 supportedExtensions.surfacelessContext = mSurfacelessSupported;
Geoff Langb0f917f2017-12-05 13:41:54 -05003184
3185 // Explicitly enable GL_KHR_debug
3186 supportedExtensions.debug = true;
3187 supportedExtensions.maxDebugMessageLength = 1024;
3188 supportedExtensions.maxDebugLoggedMessages = 1024;
3189 supportedExtensions.maxDebugGroupStackDepth = 1024;
3190 supportedExtensions.maxLabelLength = 1024;
3191
3192 // Explicitly enable GL_ANGLE_robust_client_memory
3193 supportedExtensions.robustClientMemory = true;
3194
3195 // Determine robust resource init availability from EGL.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003196 supportedExtensions.robustResourceInitialization = mState.isRobustResourceInitEnabled();
Geoff Langb0f917f2017-12-05 13:41:54 -05003197
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003198 // mState.mExtensions.robustBufferAccessBehavior is true only if robust access is true and the
3199 // backend supports it.
Geoff Langb0f917f2017-12-05 13:41:54 -05003200 supportedExtensions.robustBufferAccessBehavior =
3201 mRobustAccess && supportedExtensions.robustBufferAccessBehavior;
3202
3203 // Enable the cache control query unconditionally.
3204 supportedExtensions.programCacheControl = true;
3205
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003206 // Enable EGL_ANGLE_explicit_context subextensions
Geoff Lang33f11fb2018-05-07 13:42:47 -04003207 if (mExplicitContextAvailable)
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003208 {
3209 // GL_ANGLE_explicit_context_gles1
3210 supportedExtensions.explicitContextGles1 = true;
3211 // GL_ANGLE_explicit_context
3212 supportedExtensions.explicitContext = true;
3213 }
3214
Shahbaz Youssefi5313c8a2019-01-14 17:02:52 -05003215 // If EGL_KHR_fence_sync is not enabled, don't expose GL_OES_EGL_sync.
3216 ASSERT(mCurrentDisplay);
3217 if (!mCurrentDisplay->getExtensions().fenceSync)
3218 {
3219 supportedExtensions.eglSync = false;
3220 }
3221
Geoff Lang79b91402018-10-04 15:11:30 -04003222 supportedExtensions.memorySize = true;
3223
Geoff Langb0f917f2017-12-05 13:41:54 -05003224 return supportedExtensions;
3225}
3226
Geoff Lang33f11fb2018-05-07 13:42:47 -04003227void Context::initCaps()
Geoff Lang493daf52014-07-03 13:38:44 -04003228{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003229 mState.mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04003230
Geoff Lang33f11fb2018-05-07 13:42:47 -04003231 mSupportedExtensions = generateSupportedExtensions();
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003232 mState.mExtensions = mSupportedExtensions;
Lingfeng Yang01074432018-04-16 10:19:51 -07003233
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003234 mState.mLimitations = mImplementation->getNativeLimitations();
Lingfeng Yang01074432018-04-16 10:19:51 -07003235
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003236 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
3237 if (getClientVersion() < Version(2, 0))
3238 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003239 mState.mCaps.maxMultitextureUnits = 4;
3240 mState.mCaps.maxClipPlanes = 6;
3241 mState.mCaps.maxLights = 8;
3242 mState.mCaps.maxModelviewMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3243 mState.mCaps.maxProjectionMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3244 mState.mCaps.maxTextureMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3245 mState.mCaps.minSmoothPointSize = 1.0f;
3246 mState.mCaps.maxSmoothPointSize = 1.0f;
3247 mState.mCaps.minSmoothLineWidth = 1.0f;
3248 mState.mCaps.maxSmoothLineWidth = 1.0f;
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003249 }
3250
Luc Ferronad2ae932018-06-11 15:31:17 -04003251 // Apply/Verify implementation limits
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003252 LimitCap(&mState.mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003253
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003254 ASSERT(mState.mCaps.minAliasedPointSize >= 1.0f);
Luc Ferronad2ae932018-06-11 15:31:17 -04003255
Jamie Madill0f80ed82017-09-19 00:24:56 -04003256 if (getClientVersion() < ES_3_1)
3257 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003258 mState.mCaps.maxVertexAttribBindings = mState.mCaps.maxVertexAttributes;
Jamie Madill0f80ed82017-09-19 00:24:56 -04003259 }
3260 else
3261 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003262 LimitCap(&mState.mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
Jamie Madill0f80ed82017-09-19 00:24:56 -04003263 }
Geoff Lang301d1612014-07-09 10:34:37 -04003264
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003265 LimitCap(&mState.mCaps.maxShaderUniformBlocks[ShaderType::Vertex],
Jiawei Shao54aafe52018-04-27 14:54:57 +08003266 IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003267 LimitCap(&mState.mCaps.maxUniformBufferBindings, IMPLEMENTATION_MAX_UNIFORM_BUFFER_BINDINGS);
Jamie Madill6d32cef2018-08-14 02:34:28 -04003268
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003269 LimitCap(&mState.mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3270 LimitCap(&mState.mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
Jamie Madill0f80ed82017-09-19 00:24:56 -04003271
3272 // Limit textures as well, so we can use fast bitsets with texture bindings.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003273 LimitCap(&mState.mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
3274 LimitCap(&mState.mCaps.maxShaderTextureImageUnits[ShaderType::Vertex],
Jiawei Shao54aafe52018-04-27 14:54:57 +08003275 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003276 LimitCap(&mState.mCaps.maxShaderTextureImageUnits[ShaderType::Fragment],
Jiawei Shao54aafe52018-04-27 14:54:57 +08003277 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04003278
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003279 LimitCap(&mState.mCaps.maxImageUnits, IMPLEMENTATION_MAX_IMAGE_UNITS);
Jamie Madille3e680c2018-12-03 17:49:08 -05003280
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003281 mState.mCaps.maxSampleMaskWords =
3282 std::min<GLuint>(mState.mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
Jiawei Shaodb342272017-09-27 10:21:45 +08003283
Geoff Langc287ea62016-09-16 14:46:51 -04003284 // WebGL compatibility
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003285 mState.mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04003286 for (const auto &extensionInfo : GetExtensionInfoMap())
3287 {
Geoff Lang0ab41fa2018-03-14 11:03:30 -04003288 // If the user has requested that extensions start disabled and they are requestable,
3289 // disable them.
3290 if (!mExtensionsEnabled && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04003291 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003292 mState.mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
Geoff Langc287ea62016-09-16 14:46:51 -04003293 }
3294 }
3295
3296 // Generate texture caps
3297 updateCaps();
3298}
3299
3300void Context::updateCaps()
3301{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003302 mState.mCaps.compressedTextureFormats.clear();
3303 mState.mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04003304
Jamie Madill7b62cf92017-11-02 15:20:49 -04003305 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04003306 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04003307 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04003308 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003309
Geoff Lang0d8b7242015-09-09 14:56:53 -04003310 // Update the format caps based on the client version and extensions.
3311 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
3312 // ES3.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003313 formatCaps.texturable = formatCaps.texturable &&
3314 formatInfo.textureSupport(getClientVersion(), mState.mExtensions);
3315 formatCaps.filterable = formatCaps.filterable &&
3316 formatInfo.filterSupport(getClientVersion(), mState.mExtensions);
Yuly Novikovf15f8862018-06-04 18:59:41 -04003317 formatCaps.textureAttachment =
3318 formatCaps.textureAttachment &&
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003319 formatInfo.textureAttachmentSupport(getClientVersion(), mState.mExtensions);
3320 formatCaps.renderbuffer =
3321 formatCaps.renderbuffer &&
3322 formatInfo.renderbufferSupport(getClientVersion(), mState.mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04003323
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003324 // OpenGL ES does not support multisampling with non-rendererable formats
3325 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Yuly Novikovf15f8862018-06-04 18:59:41 -04003326 if (!formatCaps.renderbuffer ||
Yizhou Jiang2fa21472018-11-06 15:52:33 +08003327 (getClientVersion() < ES_3_1 && !mSupportedExtensions.textureMultisample &&
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003328 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04003329 {
Geoff Langd87878e2014-09-19 15:42:59 -04003330 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04003331 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03003332 else
3333 {
3334 // We may have limited the max samples for some required renderbuffer formats due to
3335 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
3336 GLuint formatMaxSamples = formatCaps.getMaxSamples();
3337
3338 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
3339 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
3340 // exception of signed and unsigned integer formats."
3341 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
3342 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
3343 {
3344 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003345 mState.mCaps.maxSamples = std::min(mState.mCaps.maxSamples, formatMaxSamples);
Olli Etuaho50c562d2017-06-06 14:43:30 +03003346 }
3347
3348 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
Yizhou Jiang2fa21472018-11-06 15:52:33 +08003349 if (getClientVersion() >= ES_3_1 || mSupportedExtensions.textureMultisample)
Olli Etuaho50c562d2017-06-06 14:43:30 +03003350 {
3351 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
3352 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
3353 // the exception that the signed and unsigned integer formats are required only to
3354 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
3355 // multisamples, which must be at least one."
3356 if (formatInfo.componentType == GL_INT ||
3357 formatInfo.componentType == GL_UNSIGNED_INT)
3358 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003359 mState.mCaps.maxIntegerSamples =
3360 std::min(mState.mCaps.maxIntegerSamples, formatMaxSamples);
Olli Etuaho50c562d2017-06-06 14:43:30 +03003361 }
3362
3363 // GLES 3.1 section 19.3.1.
3364 if (formatCaps.texturable)
3365 {
3366 if (formatInfo.depthBits > 0)
3367 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003368 mState.mCaps.maxDepthTextureSamples =
3369 std::min(mState.mCaps.maxDepthTextureSamples, formatMaxSamples);
Olli Etuaho50c562d2017-06-06 14:43:30 +03003370 }
3371 else if (formatInfo.redBits > 0)
3372 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003373 mState.mCaps.maxColorTextureSamples =
3374 std::min(mState.mCaps.maxColorTextureSamples, formatMaxSamples);
Olli Etuaho50c562d2017-06-06 14:43:30 +03003375 }
3376 }
3377 }
3378 }
Geoff Langd87878e2014-09-19 15:42:59 -04003379
3380 if (formatCaps.texturable && formatInfo.compressed)
3381 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003382 mState.mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003383 }
3384
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003385 mState.mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04003386 }
Jamie Madill32447362017-06-28 14:53:52 -04003387
3388 // If program binary is disabled, blank out the memory cache pointer.
Geoff Langb0f917f2017-12-05 13:41:54 -05003389 if (!mSupportedExtensions.getProgramBinary)
Jamie Madill32447362017-06-28 14:53:52 -04003390 {
3391 mMemoryProgramCache = nullptr;
3392 }
Corentin Walleze4477002017-12-01 14:39:58 -05003393
3394 // Compute which buffer types are allowed
3395 mValidBufferBindings.reset();
3396 mValidBufferBindings.set(BufferBinding::ElementArray);
3397 mValidBufferBindings.set(BufferBinding::Array);
3398
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003399 if (mState.mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
Corentin Walleze4477002017-12-01 14:39:58 -05003400 {
3401 mValidBufferBindings.set(BufferBinding::PixelPack);
3402 mValidBufferBindings.set(BufferBinding::PixelUnpack);
3403 }
3404
3405 if (getClientVersion() >= ES_3_0)
3406 {
3407 mValidBufferBindings.set(BufferBinding::CopyRead);
3408 mValidBufferBindings.set(BufferBinding::CopyWrite);
3409 mValidBufferBindings.set(BufferBinding::TransformFeedback);
3410 mValidBufferBindings.set(BufferBinding::Uniform);
3411 }
3412
3413 if (getClientVersion() >= ES_3_1)
3414 {
3415 mValidBufferBindings.set(BufferBinding::AtomicCounter);
3416 mValidBufferBindings.set(BufferBinding::ShaderStorage);
3417 mValidBufferBindings.set(BufferBinding::DrawIndirect);
3418 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
3419 }
jchen107ae70d82018-07-06 13:47:01 +08003420
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003421 mThreadPool = angle::WorkerThreadPool::Create(mState.mExtensions.parallelShaderCompile);
Jamie Madillac66f982018-10-09 18:30:01 -04003422
Jamie Madillef9fcd92018-11-28 14:03:59 -05003423 // Reinitialize some dirty bits that depend on extensions.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003424 bool robustInit = mState.isRobustResourceInitEnabled();
Jamie Madill132d15c2018-11-30 15:25:38 -05003425 mDrawDirtyObjects.set(State::DIRTY_OBJECT_DRAW_ATTACHMENTS, robustInit);
3426 mDrawDirtyObjects.set(State::DIRTY_OBJECT_TEXTURES_INIT, robustInit);
3427 mDrawDirtyObjects.set(State::DIRTY_OBJECT_IMAGES_INIT, robustInit);
3428 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_ATTACHMENTS, robustInit);
3429 mComputeDirtyObjects.set(State::DIRTY_OBJECT_TEXTURES_INIT, robustInit);
3430 mComputeDirtyObjects.set(State::DIRTY_OBJECT_IMAGES_INIT, robustInit);
Jamie Madillef9fcd92018-11-28 14:03:59 -05003431
Jamie Madilld51fbe32019-01-25 15:03:39 -05003432 // We need to validate buffer bounds if we are in a WebGL or robust access context and the
3433 // back-end does not support robust buffer access behaviour.
3434 if (!mSupportedExtensions.robustBufferAccessBehavior && (mState.isWebGL() || mRobustAccess))
3435 {
3436 mBufferAccessValidationEnabled = true;
3437 }
3438
Jamie Madillac66f982018-10-09 18:30:01 -04003439 // Reinitialize state cache after extension changes.
3440 mStateCache.initialize(this);
Geoff Lang493daf52014-07-03 13:38:44 -04003441}
3442
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003443void Context::initWorkarounds()
3444{
Jamie Madill761b02c2017-06-23 16:27:06 -04003445 // Apply back-end workarounds.
3446 mImplementation->applyNativeWorkarounds(&mWorkarounds);
3447
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003448 // Lose the context upon out of memory error if the application is
3449 // expecting to watch for those events.
3450 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
Jamie Madilld4f07762018-10-19 19:24:07 -04003451
3452 if (mWorkarounds.syncFramebufferBindingsOnTexImage)
3453 {
3454 // Update the Framebuffer bindings on TexImage to work around an Intel bug.
3455 mTexImageDirtyBits.set(State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
3456 mTexImageDirtyBits.set(State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
3457 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003458}
3459
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06003460bool Context::noopDrawInstanced(PrimitiveMode mode, GLsizei count, GLsizei instanceCount)
3461{
3462 return (instanceCount == 0) || noopDraw(mode, count);
3463}
3464
Jamie Madill526392d2018-11-16 09:35:14 -05003465angle::Result Context::prepareForClear(GLbitfield mask)
Geoff Langd4fff502017-09-22 11:28:28 -04003466{
Geoff Langa8cb2872018-03-09 16:09:40 -05003467 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003468 ANGLE_TRY(mState.getDrawFramebuffer()->ensureClearAttachmentsInitialized(this, mask));
Geoff Langa8cb2872018-03-09 16:09:40 -05003469 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill7c985f52018-11-29 18:16:17 -05003470 return angle::Result::Continue;
Geoff Langd4fff502017-09-22 11:28:28 -04003471}
3472
Jamie Madill526392d2018-11-16 09:35:14 -05003473angle::Result Context::prepareForClearBuffer(GLenum buffer, GLint drawbuffer)
Geoff Langd4fff502017-09-22 11:28:28 -04003474{
Geoff Langa8cb2872018-03-09 16:09:40 -05003475 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003476 ANGLE_TRY(mState.getDrawFramebuffer()->ensureClearBufferAttachmentsInitialized(this, buffer,
3477 drawbuffer));
Geoff Langa8cb2872018-03-09 16:09:40 -05003478 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill7c985f52018-11-29 18:16:17 -05003479 return angle::Result::Continue;
Jamie Madill05b35b22017-10-03 09:01:44 -04003480}
3481
Jamie Madill132d15c2018-11-30 15:25:38 -05003482ANGLE_INLINE angle::Result Context::prepareForDispatch()
3483{
3484 ANGLE_TRY(syncDirtyObjects(mComputeDirtyObjects));
3485 return syncDirtyBits(mComputeDirtyBits);
3486}
3487
Jamie Madill526392d2018-11-16 09:35:14 -05003488angle::Result Context::syncState(const State::DirtyBits &bitMask,
3489 const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04003490{
Geoff Langa8cb2872018-03-09 16:09:40 -05003491 ANGLE_TRY(syncDirtyObjects(objectMask));
3492 ANGLE_TRY(syncDirtyBits(bitMask));
Jamie Madill7c985f52018-11-29 18:16:17 -05003493 return angle::Result::Continue;
Geoff Langd4fff502017-09-22 11:28:28 -04003494}
3495
Jamie Madillc29968b2016-01-20 11:17:23 -05003496void Context::blitFramebuffer(GLint srcX0,
3497 GLint srcY0,
3498 GLint srcX1,
3499 GLint srcY1,
3500 GLint dstX0,
3501 GLint dstY0,
3502 GLint dstX1,
3503 GLint dstY1,
3504 GLbitfield mask,
3505 GLenum filter)
3506{
Qin Jiajiaaef92162018-02-27 13:51:44 +08003507 if (mask == 0)
3508 {
3509 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
3510 // buffers are copied.
3511 return;
3512 }
3513
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003514 Framebuffer *drawFramebuffer = mState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003515 ASSERT(drawFramebuffer);
3516
3517 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
3518 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
3519
Jamie Madillbc918e72018-03-08 09:47:21 -05003520 ANGLE_CONTEXT_TRY(syncStateForBlit());
Jamie Madillc29968b2016-01-20 11:17:23 -05003521
Jamie Madill4f6592f2018-11-27 16:37:45 -05003522 ANGLE_CONTEXT_TRY(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003523}
Jamie Madillc29968b2016-01-20 11:17:23 -05003524
3525void Context::clear(GLbitfield mask)
3526{
Geoff Langd4fff502017-09-22 11:28:28 -04003527 ANGLE_CONTEXT_TRY(prepareForClear(mask));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003528 ANGLE_CONTEXT_TRY(mState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05003529}
3530
3531void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
3532{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003533 Framebuffer *framebufferObject = mState.getDrawFramebuffer();
Olli Etuaho78df3362018-10-05 16:43:27 +03003534 const FramebufferAttachment *attachment = nullptr;
3535 if (buffer == GL_DEPTH)
3536 {
3537 attachment = framebufferObject->getDepthbuffer();
3538 }
3539 if (buffer == GL_COLOR &&
3540 static_cast<size_t>(drawbuffer) < framebufferObject->getNumColorBuffers())
3541 {
3542 attachment = framebufferObject->getColorbuffer(drawbuffer);
3543 }
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003544 // It's not an error to try to clear a non-existent buffer, but it's a no-op. We early out so
3545 // that the backend doesn't need to take this case into account.
Olli Etuaho78df3362018-10-05 16:43:27 +03003546 if (!attachment)
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003547 {
Olli Etuahodbce1f82018-09-19 15:32:17 +03003548 return;
3549 }
Geoff Langd4fff502017-09-22 11:28:28 -04003550 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
Olli Etuaho78df3362018-10-05 16:43:27 +03003551 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003552}
3553
3554void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3555{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003556 Framebuffer *framebufferObject = mState.getDrawFramebuffer();
Olli Etuaho78df3362018-10-05 16:43:27 +03003557 const FramebufferAttachment *attachment = nullptr;
3558 if (buffer == GL_COLOR &&
3559 static_cast<size_t>(drawbuffer) < framebufferObject->getNumColorBuffers())
3560 {
3561 attachment = framebufferObject->getColorbuffer(drawbuffer);
3562 }
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003563 // It's not an error to try to clear a non-existent buffer, but it's a no-op. We early out so
3564 // that the backend doesn't need to take this case into account.
Olli Etuaho78df3362018-10-05 16:43:27 +03003565 if (!attachment)
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003566 {
3567 return;
3568 }
Geoff Langd4fff502017-09-22 11:28:28 -04003569 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
Olli Etuaho78df3362018-10-05 16:43:27 +03003570 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003571}
3572
3573void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3574{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003575 Framebuffer *framebufferObject = mState.getDrawFramebuffer();
Olli Etuaho78df3362018-10-05 16:43:27 +03003576 const FramebufferAttachment *attachment = nullptr;
3577 if (buffer == GL_STENCIL)
3578 {
3579 attachment = framebufferObject->getStencilbuffer();
3580 }
3581 if (buffer == GL_COLOR &&
3582 static_cast<size_t>(drawbuffer) < framebufferObject->getNumColorBuffers())
3583 {
3584 attachment = framebufferObject->getColorbuffer(drawbuffer);
3585 }
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003586 // It's not an error to try to clear a non-existent buffer, but it's a no-op. We early out so
3587 // that the backend doesn't need to take this case into account.
Olli Etuaho78df3362018-10-05 16:43:27 +03003588 if (!attachment)
Olli Etuaho4ebd8f32018-09-20 11:12:46 +03003589 {
Olli Etuahodbce1f82018-09-19 15:32:17 +03003590 return;
3591 }
Geoff Langd4fff502017-09-22 11:28:28 -04003592 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
Olli Etuaho78df3362018-10-05 16:43:27 +03003593 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003594}
3595
3596void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3597{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003598 Framebuffer *framebufferObject = mState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003599 ASSERT(framebufferObject);
3600
3601 // If a buffer is not present, the clear has no effect
3602 if (framebufferObject->getDepthbuffer() == nullptr &&
3603 framebufferObject->getStencilbuffer() == nullptr)
3604 {
3605 return;
3606 }
3607
Geoff Langd4fff502017-09-22 11:28:28 -04003608 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3609 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003610}
3611
3612void Context::readPixels(GLint x,
3613 GLint y,
3614 GLsizei width,
3615 GLsizei height,
3616 GLenum format,
3617 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003618 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003619{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003620 if (width == 0 || height == 0)
3621 {
3622 return;
3623 }
3624
Jamie Madillbc918e72018-03-08 09:47:21 -05003625 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003626
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003627 Framebuffer *readFBO = mState.getReadFramebuffer();
Jamie Madillb6664922017-07-25 12:55:04 -04003628 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003629
3630 Rectangle area(x, y, width, height);
Jamie Madill4f6592f2018-11-27 16:37:45 -05003631 ANGLE_CONTEXT_TRY(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003632}
3633
Brandon Jones59770802018-04-02 13:18:42 -07003634void Context::readPixelsRobust(GLint x,
3635 GLint y,
3636 GLsizei width,
3637 GLsizei height,
3638 GLenum format,
3639 GLenum type,
3640 GLsizei bufSize,
3641 GLsizei *length,
3642 GLsizei *columns,
3643 GLsizei *rows,
3644 void *pixels)
3645{
3646 readPixels(x, y, width, height, format, type, pixels);
3647}
3648
3649void Context::readnPixelsRobust(GLint x,
3650 GLint y,
3651 GLsizei width,
3652 GLsizei height,
3653 GLenum format,
3654 GLenum type,
3655 GLsizei bufSize,
3656 GLsizei *length,
3657 GLsizei *columns,
3658 GLsizei *rows,
3659 void *data)
3660{
3661 readPixels(x, y, width, height, format, type, data);
3662}
3663
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003664void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003665 GLint level,
3666 GLenum internalformat,
3667 GLint x,
3668 GLint y,
3669 GLsizei width,
3670 GLsizei height,
3671 GLint border)
3672{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003673 // Only sync the read FBO
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003674 ANGLE_CONTEXT_TRY(mState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003675
Jamie Madillc29968b2016-01-20 11:17:23 -05003676 Rectangle sourceArea(x, y, width, height);
3677
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003678 Framebuffer *framebuffer = mState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003679 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill4f6592f2018-11-27 16:37:45 -05003680 ANGLE_CONTEXT_TRY(
3681 texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003682}
3683
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003684void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003685 GLint level,
3686 GLint xoffset,
3687 GLint yoffset,
3688 GLint x,
3689 GLint y,
3690 GLsizei width,
3691 GLsizei height)
3692{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003693 if (width == 0 || height == 0)
3694 {
3695 return;
3696 }
3697
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003698 // Only sync the read FBO
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003699 ANGLE_CONTEXT_TRY(mState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003700
Jamie Madillc29968b2016-01-20 11:17:23 -05003701 Offset destOffset(xoffset, yoffset, 0);
3702 Rectangle sourceArea(x, y, width, height);
3703
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003704 Framebuffer *framebuffer = mState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003705 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill4f6592f2018-11-27 16:37:45 -05003706 ANGLE_CONTEXT_TRY(
3707 texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003708}
3709
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003710void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003711 GLint level,
3712 GLint xoffset,
3713 GLint yoffset,
3714 GLint zoffset,
3715 GLint x,
3716 GLint y,
3717 GLsizei width,
3718 GLsizei height)
3719{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003720 if (width == 0 || height == 0)
3721 {
3722 return;
3723 }
3724
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003725 // Only sync the read FBO
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003726 ANGLE_CONTEXT_TRY(mState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003727
Jamie Madillc29968b2016-01-20 11:17:23 -05003728 Offset destOffset(xoffset, yoffset, zoffset);
3729 Rectangle sourceArea(x, y, width, height);
3730
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003731 Framebuffer *framebuffer = mState.getReadFramebuffer();
Jamie Madill05b35b22017-10-03 09:01:44 -04003732 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05003733 ANGLE_CONTEXT_TRY(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level,
3734 destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003735}
3736
3737void Context::framebufferTexture2D(GLenum target,
3738 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003739 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003740 GLuint texture,
3741 GLint level)
3742{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003743 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003744 ASSERT(framebuffer);
3745
3746 if (texture != 0)
3747 {
3748 Texture *textureObj = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003749 ImageIndex index = ImageIndex::MakeFromTarget(textarget, level);
Jamie Madilla02315b2017-02-23 14:14:47 -05003750 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003751 }
3752 else
3753 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003754 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003755 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003756
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003757 mState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003758}
3759
3760void Context::framebufferRenderbuffer(GLenum target,
3761 GLenum attachment,
3762 GLenum renderbuffertarget,
3763 GLuint renderbuffer)
3764{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003765 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003766 ASSERT(framebuffer);
3767
3768 if (renderbuffer != 0)
3769 {
3770 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003771
Jamie Madillcc129372018-04-12 09:13:18 -04003772 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003773 renderbufferObject);
3774 }
3775 else
3776 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003777 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003778 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003779
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003780 mState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003781}
3782
3783void Context::framebufferTextureLayer(GLenum target,
3784 GLenum attachment,
3785 GLuint texture,
3786 GLint level,
3787 GLint layer)
3788{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003789 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003790 ASSERT(framebuffer);
3791
3792 if (texture != 0)
3793 {
3794 Texture *textureObject = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003795 ImageIndex index = ImageIndex::MakeFromType(textureObject->getType(), level, layer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003796 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003797 }
3798 else
3799 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003800 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003801 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003802
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003803 mState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003804}
3805
Brandon Jones59770802018-04-02 13:18:42 -07003806void Context::framebufferTextureMultiviewLayered(GLenum target,
3807 GLenum attachment,
3808 GLuint texture,
3809 GLint level,
3810 GLint baseViewIndex,
3811 GLsizei numViews)
Martin Radev137032d2017-07-13 10:11:12 +03003812{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003813 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Martin Radev82ef7742017-08-08 17:44:58 +03003814 ASSERT(framebuffer);
3815
3816 if (texture != 0)
3817 {
3818 Texture *textureObj = getTexture(texture);
3819
Olli Etuaho2c8f0842018-09-12 14:44:55 +03003820 ImageIndex index;
3821 if (textureObj->getType() == TextureType::_2DArray)
3822 {
3823 index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
3824 }
3825 else
3826 {
3827 ASSERT(textureObj->getType() == TextureType::_2DMultisampleArray);
3828 ASSERT(level == 0);
3829 index = ImageIndex::Make2DMultisampleArrayRange(baseViewIndex, numViews);
3830 }
Martin Radev82ef7742017-08-08 17:44:58 +03003831 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3832 numViews, baseViewIndex);
3833 }
3834 else
3835 {
3836 framebuffer->resetAttachment(this, attachment);
3837 }
3838
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003839 mState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003840}
3841
Brandon Jones59770802018-04-02 13:18:42 -07003842void Context::framebufferTextureMultiviewSideBySide(GLenum target,
3843 GLenum attachment,
3844 GLuint texture,
3845 GLint level,
3846 GLsizei numViews,
3847 const GLint *viewportOffsets)
Martin Radev137032d2017-07-13 10:11:12 +03003848{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003849 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Martin Radev5dae57b2017-07-14 16:15:55 +03003850 ASSERT(framebuffer);
3851
3852 if (texture != 0)
3853 {
3854 Texture *textureObj = getTexture(texture);
3855
3856 ImageIndex index = ImageIndex::Make2D(level);
3857 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3858 textureObj, numViews, viewportOffsets);
3859 }
3860 else
3861 {
3862 framebuffer->resetAttachment(this, attachment);
3863 }
3864
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003865 mState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003866}
3867
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003868void Context::framebufferTexture(GLenum target, GLenum attachment, GLuint texture, GLint level)
3869{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003870 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Jiawei Shaoa8802472018-05-28 11:17:47 +08003871 ASSERT(framebuffer);
3872
3873 if (texture != 0)
3874 {
3875 Texture *textureObj = getTexture(texture);
3876
3877 ImageIndex index = ImageIndex::MakeFromType(
3878 textureObj->getType(), level, ImageIndex::kEntireLevel, ImageIndex::kEntireLevel);
3879 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
3880 }
3881 else
3882 {
3883 framebuffer->resetAttachment(this, attachment);
3884 }
3885
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003886 mState.setObjectDirty(target);
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003887}
3888
Jamie Madillc29968b2016-01-20 11:17:23 -05003889void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3890{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003891 Framebuffer *framebuffer = mState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003892 ASSERT(framebuffer);
3893 framebuffer->setDrawBuffers(n, bufs);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003894 mState.setDrawFramebufferDirty();
Jamie Madilld84b6732018-09-06 15:54:35 -04003895 mStateCache.onDrawFramebufferChange(this);
Jamie Madillc29968b2016-01-20 11:17:23 -05003896}
3897
3898void Context::readBuffer(GLenum mode)
3899{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003900 Framebuffer *readFBO = mState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003901 readFBO->setReadBuffer(mode);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003902 mState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003903}
3904
3905void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3906{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003907 // Only sync the FBO
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003908 ANGLE_CONTEXT_TRY(mState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003909
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003910 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003911 ASSERT(framebuffer);
3912
3913 // The specification isn't clear what should be done when the framebuffer isn't complete.
3914 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4f6592f2018-11-27 16:37:45 -05003915 ANGLE_CONTEXT_TRY(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003916}
3917
3918void Context::invalidateFramebuffer(GLenum target,
3919 GLsizei numAttachments,
3920 const GLenum *attachments)
3921{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003922 // Only sync the FBO
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003923 ANGLE_CONTEXT_TRY(mState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003924
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003925 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003926 ASSERT(framebuffer);
3927
Jamie Madill427064d2018-04-13 16:20:34 -04003928 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003929 {
Jamie Madill437fa652016-05-03 15:13:24 -04003930 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003931 }
Jamie Madill437fa652016-05-03 15:13:24 -04003932
Jamie Madill4f6592f2018-11-27 16:37:45 -05003933 ANGLE_CONTEXT_TRY(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003934}
3935
3936void Context::invalidateSubFramebuffer(GLenum target,
3937 GLsizei numAttachments,
3938 const GLenum *attachments,
3939 GLint x,
3940 GLint y,
3941 GLsizei width,
3942 GLsizei height)
3943{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003944 // Only sync the FBO
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003945 ANGLE_CONTEXT_TRY(mState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003946
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003947 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003948 ASSERT(framebuffer);
3949
Jamie Madill427064d2018-04-13 16:20:34 -04003950 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003951 {
Jamie Madill437fa652016-05-03 15:13:24 -04003952 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003953 }
Jamie Madill437fa652016-05-03 15:13:24 -04003954
3955 Rectangle area(x, y, width, height);
Jamie Madill4f6592f2018-11-27 16:37:45 -05003956 ANGLE_CONTEXT_TRY(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003957}
3958
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003959void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003960 GLint level,
3961 GLint internalformat,
3962 GLsizei width,
3963 GLsizei height,
3964 GLint border,
3965 GLenum format,
3966 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003967 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003968{
Jamie Madillbc918e72018-03-08 09:47:21 -05003969 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003970
3971 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003972 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05003973 ANGLE_CONTEXT_TRY(texture->setImage(this, mState.getUnpackState(), target, level,
Jamie Madill4f6592f2018-11-27 16:37:45 -05003974 internalformat, size, format, type,
3975 static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003976}
3977
Brandon Jones59770802018-04-02 13:18:42 -07003978void Context::texImage2DRobust(TextureTarget target,
3979 GLint level,
3980 GLint internalformat,
3981 GLsizei width,
3982 GLsizei height,
3983 GLint border,
3984 GLenum format,
3985 GLenum type,
3986 GLsizei bufSize,
3987 const void *pixels)
3988{
3989 texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
3990}
3991
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003992void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003993 GLint level,
3994 GLint internalformat,
3995 GLsizei width,
3996 GLsizei height,
3997 GLsizei depth,
3998 GLint border,
3999 GLenum format,
4000 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004001 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004002{
Jamie Madillbc918e72018-03-08 09:47:21 -05004003 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004004
4005 Extents size(width, height, depth);
4006 Texture *texture = getTargetTexture(target);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004007 ANGLE_CONTEXT_TRY(texture->setImage(this, mState.getUnpackState(),
Jamie Madill4f6592f2018-11-27 16:37:45 -05004008 NonCubeTextureTypeToTarget(target), level, internalformat,
4009 size, format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004010}
4011
Brandon Jones59770802018-04-02 13:18:42 -07004012void Context::texImage3DRobust(TextureType target,
4013 GLint level,
4014 GLint internalformat,
4015 GLsizei width,
4016 GLsizei height,
4017 GLsizei depth,
4018 GLint border,
4019 GLenum format,
4020 GLenum type,
4021 GLsizei bufSize,
4022 const void *pixels)
4023{
4024 texImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels);
4025}
4026
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004027void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004028 GLint level,
4029 GLint xoffset,
4030 GLint yoffset,
4031 GLsizei width,
4032 GLsizei height,
4033 GLenum format,
4034 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004035 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004036{
4037 // Zero sized uploads are valid but no-ops
4038 if (width == 0 || height == 0)
4039 {
4040 return;
4041 }
4042
Jamie Madillbc918e72018-03-08 09:47:21 -05004043 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004044
4045 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004046 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill0d0fb432018-09-07 17:43:32 -04004047
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004048 gl::Buffer *unpackBuffer = mState.getTargetBuffer(gl::BufferBinding::PixelUnpack);
Jamie Madill0d0fb432018-09-07 17:43:32 -04004049
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004050 ANGLE_CONTEXT_TRY(texture->setSubImage(this, mState.getUnpackState(), unpackBuffer, target,
Jamie Madill4f6592f2018-11-27 16:37:45 -05004051 level, area, format, type,
4052 static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004053}
4054
Brandon Jones59770802018-04-02 13:18:42 -07004055void Context::texSubImage2DRobust(TextureTarget target,
4056 GLint level,
4057 GLint xoffset,
4058 GLint yoffset,
4059 GLsizei width,
4060 GLsizei height,
4061 GLenum format,
4062 GLenum type,
4063 GLsizei bufSize,
4064 const void *pixels)
4065{
4066 texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
4067}
4068
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004069void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004070 GLint level,
4071 GLint xoffset,
4072 GLint yoffset,
4073 GLint zoffset,
4074 GLsizei width,
4075 GLsizei height,
4076 GLsizei depth,
4077 GLenum format,
4078 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004079 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004080{
4081 // Zero sized uploads are valid but no-ops
4082 if (width == 0 || height == 0 || depth == 0)
4083 {
4084 return;
4085 }
4086
Jamie Madillbc918e72018-03-08 09:47:21 -05004087 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004088
4089 Box area(xoffset, yoffset, zoffset, width, height, depth);
4090 Texture *texture = getTargetTexture(target);
Jamie Madill0d0fb432018-09-07 17:43:32 -04004091
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004092 gl::Buffer *unpackBuffer = mState.getTargetBuffer(gl::BufferBinding::PixelUnpack);
Jamie Madill0d0fb432018-09-07 17:43:32 -04004093
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004094 ANGLE_CONTEXT_TRY(texture->setSubImage(this, mState.getUnpackState(), unpackBuffer,
Jamie Madill4f6592f2018-11-27 16:37:45 -05004095 NonCubeTextureTypeToTarget(target), level, area, format,
4096 type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004097}
4098
Brandon Jones59770802018-04-02 13:18:42 -07004099void Context::texSubImage3DRobust(TextureType target,
4100 GLint level,
4101 GLint xoffset,
4102 GLint yoffset,
4103 GLint zoffset,
4104 GLsizei width,
4105 GLsizei height,
4106 GLsizei depth,
4107 GLenum format,
4108 GLenum type,
4109 GLsizei bufSize,
4110 const void *pixels)
4111{
4112 texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type,
4113 pixels);
4114}
4115
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004116void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004117 GLint level,
4118 GLenum internalformat,
4119 GLsizei width,
4120 GLsizei height,
4121 GLint border,
4122 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004123 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004124{
Jamie Madillbc918e72018-03-08 09:47:21 -05004125 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004126
4127 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004128 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004129 ANGLE_CONTEXT_TRY(texture->setCompressedImage(this, mState.getUnpackState(), target, level,
Jamie Madill4f6592f2018-11-27 16:37:45 -05004130 internalformat, size, imageSize,
4131 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004132}
4133
Brandon Jones59770802018-04-02 13:18:42 -07004134void Context::compressedTexImage2DRobust(TextureTarget target,
4135 GLint level,
4136 GLenum internalformat,
4137 GLsizei width,
4138 GLsizei height,
4139 GLint border,
4140 GLsizei imageSize,
4141 GLsizei dataSize,
4142 const GLvoid *data)
4143{
4144 compressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
4145}
4146
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004147void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004148 GLint level,
4149 GLenum internalformat,
4150 GLsizei width,
4151 GLsizei height,
4152 GLsizei depth,
4153 GLint border,
4154 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004155 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004156{
Jamie Madillbc918e72018-03-08 09:47:21 -05004157 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004158
4159 Extents size(width, height, depth);
4160 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004161 ANGLE_CONTEXT_TRY(texture->setCompressedImage(
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004162 this, mState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004163 size, imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004164}
4165
Brandon Jones59770802018-04-02 13:18:42 -07004166void Context::compressedTexImage3DRobust(TextureType target,
4167 GLint level,
4168 GLenum internalformat,
4169 GLsizei width,
4170 GLsizei height,
4171 GLsizei depth,
4172 GLint border,
4173 GLsizei imageSize,
4174 GLsizei dataSize,
4175 const GLvoid *data)
4176{
4177 compressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize,
4178 data);
4179}
4180
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004181void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004182 GLint level,
4183 GLint xoffset,
4184 GLint yoffset,
4185 GLsizei width,
4186 GLsizei height,
4187 GLenum format,
4188 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004189 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004190{
Jamie Madillbc918e72018-03-08 09:47:21 -05004191 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004192
4193 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004194 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004195 ANGLE_CONTEXT_TRY(texture->setCompressedSubImage(this, mState.getUnpackState(), target, level,
Jamie Madill4f6592f2018-11-27 16:37:45 -05004196 area, format, imageSize,
4197 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004198}
4199
Brandon Jones59770802018-04-02 13:18:42 -07004200void Context::compressedTexSubImage2DRobust(TextureTarget target,
4201 GLint level,
4202 GLint xoffset,
4203 GLint yoffset,
4204 GLsizei width,
4205 GLsizei height,
4206 GLenum format,
4207 GLsizei imageSize,
4208 GLsizei dataSize,
4209 const GLvoid *data)
4210{
4211 compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize,
4212 data);
4213}
4214
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004215void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004216 GLint level,
4217 GLint xoffset,
4218 GLint yoffset,
4219 GLint zoffset,
4220 GLsizei width,
4221 GLsizei height,
4222 GLsizei depth,
4223 GLenum format,
4224 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004225 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004226{
4227 // Zero sized uploads are valid but no-ops
4228 if (width == 0 || height == 0)
4229 {
4230 return;
4231 }
4232
Jamie Madillbc918e72018-03-08 09:47:21 -05004233 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004234
4235 Box area(xoffset, yoffset, zoffset, width, height, depth);
4236 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004237 ANGLE_CONTEXT_TRY(texture->setCompressedSubImage(
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004238 this, mState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004239 imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004240}
4241
Brandon Jones59770802018-04-02 13:18:42 -07004242void Context::compressedTexSubImage3DRobust(TextureType target,
4243 GLint level,
4244 GLint xoffset,
4245 GLint yoffset,
4246 GLint zoffset,
4247 GLsizei width,
4248 GLsizei height,
4249 GLsizei depth,
4250 GLenum format,
4251 GLsizei imageSize,
4252 GLsizei dataSize,
4253 const GLvoid *data)
4254{
4255 compressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format,
4256 imageSize, data);
4257}
4258
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004259void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004260{
4261 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004262 ANGLE_CONTEXT_TRY(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004263}
4264
Jamie Madill007530e2017-12-28 14:27:04 -05004265void Context::copyTexture(GLuint sourceId,
4266 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004267 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004268 GLuint destId,
4269 GLint destLevel,
4270 GLint internalFormat,
4271 GLenum destType,
4272 GLboolean unpackFlipY,
4273 GLboolean unpackPremultiplyAlpha,
4274 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004275{
Jamie Madillbc918e72018-03-08 09:47:21 -05004276 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004277
4278 gl::Texture *sourceTexture = getTexture(sourceId);
4279 gl::Texture *destTexture = getTexture(destId);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004280 ANGLE_CONTEXT_TRY(
4281 destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType, sourceLevel,
4282 ConvertToBool(unpackFlipY), ConvertToBool(unpackPremultiplyAlpha),
4283 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004284}
4285
Jamie Madill007530e2017-12-28 14:27:04 -05004286void Context::copySubTexture(GLuint sourceId,
4287 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004288 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004289 GLuint destId,
4290 GLint destLevel,
4291 GLint xoffset,
4292 GLint yoffset,
4293 GLint x,
4294 GLint y,
4295 GLsizei width,
4296 GLsizei height,
4297 GLboolean unpackFlipY,
4298 GLboolean unpackPremultiplyAlpha,
4299 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004300{
4301 // Zero sized copies are valid but no-ops
4302 if (width == 0 || height == 0)
4303 {
4304 return;
4305 }
4306
Jamie Madillbc918e72018-03-08 09:47:21 -05004307 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004308
4309 gl::Texture *sourceTexture = getTexture(sourceId);
4310 gl::Texture *destTexture = getTexture(destId);
4311 Offset offset(xoffset, yoffset, 0);
Brandon Jones4e6f2ae2018-09-19 11:09:51 -07004312 Box box(x, y, 0, width, height, 1);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004313 ANGLE_CONTEXT_TRY(destTexture->copySubTexture(
4314 this, destTarget, destLevel, offset, sourceLevel, box, ConvertToBool(unpackFlipY),
4315 ConvertToBool(unpackPremultiplyAlpha), ConvertToBool(unpackUnmultiplyAlpha),
4316 sourceTexture));
Brandon Jones4e6f2ae2018-09-19 11:09:51 -07004317}
4318
4319void Context::copyTexture3D(GLuint sourceId,
4320 GLint sourceLevel,
4321 TextureTarget destTarget,
4322 GLuint destId,
4323 GLint destLevel,
4324 GLint internalFormat,
4325 GLenum destType,
4326 GLboolean unpackFlipY,
4327 GLboolean unpackPremultiplyAlpha,
4328 GLboolean unpackUnmultiplyAlpha)
4329{
4330 ANGLE_CONTEXT_TRY(syncStateForTexImage());
4331
4332 Texture *sourceTexture = getTexture(sourceId);
4333 Texture *destTexture = getTexture(destId);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004334 ANGLE_CONTEXT_TRY(
4335 destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType, sourceLevel,
4336 ConvertToBool(unpackFlipY), ConvertToBool(unpackPremultiplyAlpha),
4337 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Brandon Jones4e6f2ae2018-09-19 11:09:51 -07004338}
4339
4340void Context::copySubTexture3D(GLuint sourceId,
4341 GLint sourceLevel,
4342 TextureTarget destTarget,
4343 GLuint destId,
4344 GLint destLevel,
4345 GLint xoffset,
4346 GLint yoffset,
4347 GLint zoffset,
4348 GLint x,
4349 GLint y,
4350 GLint z,
4351 GLsizei width,
4352 GLsizei height,
4353 GLsizei depth,
4354 GLboolean unpackFlipY,
4355 GLboolean unpackPremultiplyAlpha,
4356 GLboolean unpackUnmultiplyAlpha)
4357{
4358 // Zero sized copies are valid but no-ops
4359 if (width == 0 || height == 0 || depth == 0)
4360 {
4361 return;
4362 }
4363
4364 ANGLE_CONTEXT_TRY(syncStateForTexImage());
4365
4366 Texture *sourceTexture = getTexture(sourceId);
4367 Texture *destTexture = getTexture(destId);
4368 Offset offset(xoffset, yoffset, zoffset);
4369 Box box(x, y, z, width, height, depth);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004370 ANGLE_CONTEXT_TRY(destTexture->copySubTexture(
4371 this, destTarget, destLevel, offset, sourceLevel, box, ConvertToBool(unpackFlipY),
4372 ConvertToBool(unpackPremultiplyAlpha), ConvertToBool(unpackUnmultiplyAlpha),
4373 sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004374}
4375
Jamie Madill007530e2017-12-28 14:27:04 -05004376void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07004377{
Jamie Madillbc918e72018-03-08 09:47:21 -05004378 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07004379
4380 gl::Texture *sourceTexture = getTexture(sourceId);
4381 gl::Texture *destTexture = getTexture(destId);
Jamie Madill4f6592f2018-11-27 16:37:45 -05004382 ANGLE_CONTEXT_TRY(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07004383}
4384
Corentin Wallez336129f2017-10-17 15:55:40 -04004385void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03004386{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004387 Buffer *buffer = mState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004388 ASSERT(buffer);
4389
Geoff Lang496c02d2016-10-20 11:38:11 -07004390 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03004391}
4392
Brandon Jones59770802018-04-02 13:18:42 -07004393void Context::getBufferPointervRobust(BufferBinding target,
4394 GLenum pname,
4395 GLsizei bufSize,
4396 GLsizei *length,
4397 void **params)
4398{
4399 getBufferPointerv(target, pname, params);
4400}
4401
Corentin Wallez336129f2017-10-17 15:55:40 -04004402void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004403{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004404 Buffer *buffer = mState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004405 ASSERT(buffer);
4406
Jamie Madill7c985f52018-11-29 18:16:17 -05004407 if (buffer->map(this, access) == angle::Result::Stop)
Olli Etuaho4f667482016-03-30 15:56:35 +03004408 {
Olli Etuaho4f667482016-03-30 15:56:35 +03004409 return nullptr;
4410 }
4411
4412 return buffer->getMapPointer();
4413}
4414
Corentin Wallez336129f2017-10-17 15:55:40 -04004415GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03004416{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004417 Buffer *buffer = mState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004418 ASSERT(buffer);
4419
4420 GLboolean result;
Jamie Madill7c985f52018-11-29 18:16:17 -05004421 if (buffer->unmap(this, &result) == angle::Result::Stop)
Olli Etuaho4f667482016-03-30 15:56:35 +03004422 {
Olli Etuaho4f667482016-03-30 15:56:35 +03004423 return GL_FALSE;
4424 }
4425
4426 return result;
4427}
4428
Corentin Wallez336129f2017-10-17 15:55:40 -04004429void *Context::mapBufferRange(BufferBinding target,
4430 GLintptr offset,
4431 GLsizeiptr length,
4432 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004433{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004434 Buffer *buffer = mState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004435 ASSERT(buffer);
4436
Jamie Madill7c985f52018-11-29 18:16:17 -05004437 if (buffer->mapRange(this, offset, length, access) == angle::Result::Stop)
Olli Etuaho4f667482016-03-30 15:56:35 +03004438 {
Olli Etuaho4f667482016-03-30 15:56:35 +03004439 return nullptr;
4440 }
4441
4442 return buffer->getMapPointer();
4443}
4444
Corentin Wallez336129f2017-10-17 15:55:40 -04004445void Context::flushMappedBufferRange(BufferBinding /*target*/,
4446 GLintptr /*offset*/,
4447 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03004448{
4449 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
4450}
4451
Jamie Madill526392d2018-11-16 09:35:14 -05004452angle::Result Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004453{
Geoff Langa8cb2872018-03-09 16:09:40 -05004454 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004455}
4456
Jamie Madill526392d2018-11-16 09:35:14 -05004457angle::Result Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004458{
Geoff Langa8cb2872018-03-09 16:09:40 -05004459 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004460}
4461
Jamie Madill526392d2018-11-16 09:35:14 -05004462angle::Result Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004463{
Geoff Langa8cb2872018-03-09 16:09:40 -05004464 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004465}
4466
Jamie Madill526392d2018-11-16 09:35:14 -05004467angle::Result Context::syncStateForPathOperation()
Geoff Lang9bf86f02018-07-26 11:46:34 -04004468{
4469 ANGLE_TRY(syncDirtyObjects(mPathOperationDirtyObjects));
4470
4471 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
4472 ANGLE_TRY(syncDirtyBits());
4473
Jamie Madill7c985f52018-11-29 18:16:17 -05004474 return angle::Result::Continue;
Geoff Lang9bf86f02018-07-26 11:46:34 -04004475}
4476
Jiajia Qin5451d532017-11-16 17:16:34 +08004477void Context::activeShaderProgram(GLuint pipeline, GLuint program)
4478{
4479 UNIMPLEMENTED();
4480}
4481
Jamie Madillc20ab272016-06-09 07:20:46 -07004482void Context::activeTexture(GLenum texture)
4483{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004484 mState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004485}
4486
Jamie Madill876429b2017-04-20 15:46:24 -04004487void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004488{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004489 mState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004490}
4491
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004492void Context::blendEquation(GLenum mode)
4493{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004494 mState.setBlendEquation(mode, mode);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004495}
4496
Jamie Madillc20ab272016-06-09 07:20:46 -07004497void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
4498{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004499 mState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004500}
4501
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004502void Context::blendFunc(GLenum sfactor, GLenum dfactor)
4503{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004504 mState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004505}
4506
Jamie Madillc20ab272016-06-09 07:20:46 -07004507void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
4508{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004509 mState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004510}
4511
Jamie Madill876429b2017-04-20 15:46:24 -04004512void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004513{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004514 mState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004515}
4516
Jamie Madill876429b2017-04-20 15:46:24 -04004517void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07004518{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004519 mState.setDepthClearValue(clamp01(depth));
Jamie Madillc20ab272016-06-09 07:20:46 -07004520}
4521
4522void Context::clearStencil(GLint s)
4523{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004524 mState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07004525}
4526
4527void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
4528{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004529 mState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
4530 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004531}
4532
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004533void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07004534{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004535 mState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004536}
4537
4538void Context::depthFunc(GLenum func)
4539{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004540 mState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07004541}
4542
4543void Context::depthMask(GLboolean flag)
4544{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004545 mState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07004546}
4547
Jamie Madill876429b2017-04-20 15:46:24 -04004548void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07004549{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004550 mState.setDepthRange(clamp01(zNear), clamp01(zFar));
Jamie Madillc20ab272016-06-09 07:20:46 -07004551}
4552
4553void Context::disable(GLenum cap)
4554{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004555 mState.setEnableFeature(cap, false);
Jamie Madilld84b6732018-09-06 15:54:35 -04004556 mStateCache.onContextCapChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004557}
4558
4559void Context::disableVertexAttribArray(GLuint index)
4560{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004561 mState.setEnableVertexAttribArray(index, false);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004562 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004563}
4564
4565void Context::enable(GLenum cap)
4566{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004567 mState.setEnableFeature(cap, true);
Jamie Madilld84b6732018-09-06 15:54:35 -04004568 mStateCache.onContextCapChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004569}
4570
4571void Context::enableVertexAttribArray(GLuint index)
4572{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004573 mState.setEnableVertexAttribArray(index, true);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004574 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004575}
4576
4577void Context::frontFace(GLenum mode)
4578{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004579 mState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004580}
4581
4582void Context::hint(GLenum target, GLenum mode)
4583{
4584 switch (target)
4585 {
4586 case GL_GENERATE_MIPMAP_HINT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004587 mState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004588 break;
4589
4590 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004591 mState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004592 break;
4593
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07004594 case GL_PERSPECTIVE_CORRECTION_HINT:
4595 case GL_POINT_SMOOTH_HINT:
4596 case GL_LINE_SMOOTH_HINT:
4597 case GL_FOG_HINT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004598 mState.gles1().setHint(target, mode);
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07004599 break;
Jamie Madillc20ab272016-06-09 07:20:46 -07004600 default:
4601 UNREACHABLE();
4602 return;
4603 }
4604}
4605
4606void Context::lineWidth(GLfloat width)
4607{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004608 mState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07004609}
4610
4611void Context::pixelStorei(GLenum pname, GLint param)
4612{
4613 switch (pname)
4614 {
4615 case GL_UNPACK_ALIGNMENT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004616 mState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004617 break;
4618
4619 case GL_PACK_ALIGNMENT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004620 mState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004621 break;
4622
4623 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004624 mState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004625 break;
4626
4627 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004628 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004629 mState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004630 break;
4631
4632 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03004633 ASSERT(getClientMajorVersion() >= 3);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004634 mState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004635 break;
4636
4637 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03004638 ASSERT(getClientMajorVersion() >= 3);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004639 mState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004640 break;
4641
4642 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004643 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004644 mState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004645 break;
4646
4647 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004648 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004649 mState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004650 break;
4651
4652 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004653 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004654 mState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004655 break;
4656
4657 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004658 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004659 mState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004660 break;
4661
4662 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004663 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004664 mState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004665 break;
4666
4667 default:
4668 UNREACHABLE();
4669 return;
4670 }
4671}
4672
4673void Context::polygonOffset(GLfloat factor, GLfloat units)
4674{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004675 mState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07004676}
4677
Jamie Madill876429b2017-04-20 15:46:24 -04004678void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07004679{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004680 mState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07004681}
4682
Jiawei Shaodb342272017-09-27 10:21:45 +08004683void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
4684{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004685 mState.setSampleMaskParams(maskNumber, mask);
Jiawei Shaodb342272017-09-27 10:21:45 +08004686}
4687
Jamie Madillc20ab272016-06-09 07:20:46 -07004688void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
4689{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004690 mState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004691}
4692
4693void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
4694{
4695 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4696 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004697 mState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004698 }
4699
4700 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4701 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004702 mState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004703 }
Jamie Madilld84b6732018-09-06 15:54:35 -04004704
4705 mStateCache.onStencilStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004706}
4707
4708void Context::stencilMaskSeparate(GLenum face, GLuint mask)
4709{
4710 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4711 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004712 mState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004713 }
4714
4715 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4716 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004717 mState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004718 }
Jamie Madilld84b6732018-09-06 15:54:35 -04004719
4720 mStateCache.onStencilStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004721}
4722
4723void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4724{
4725 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4726 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004727 mState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004728 }
4729
4730 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4731 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004732 mState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004733 }
4734}
4735
4736void Context::vertexAttrib1f(GLuint index, GLfloat x)
4737{
4738 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004739 mState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004740 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004741}
4742
4743void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
4744{
4745 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004746 mState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004747 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004748}
4749
4750void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4751{
4752 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004753 mState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004754 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004755}
4756
4757void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
4758{
4759 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004760 mState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004761 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004762}
4763
4764void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4765{
4766 GLfloat vals[4] = {x, y, z, 1};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004767 mState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004768 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004769}
4770
4771void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
4772{
4773 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004774 mState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004775 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004776}
4777
4778void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4779{
4780 GLfloat vals[4] = {x, y, z, w};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004781 mState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004782 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004783}
4784
4785void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
4786{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004787 mState.setVertexAttribf(index, values);
Jamie Madilld84b6732018-09-06 15:54:35 -04004788 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004789}
4790
4791void Context::vertexAttribPointer(GLuint index,
4792 GLint size,
Jamie Madilldd34b3b2019-01-16 09:59:54 -05004793 VertexAttribType type,
Jamie Madillc20ab272016-06-09 07:20:46 -07004794 GLboolean normalized,
4795 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004796 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07004797{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004798 mState.setVertexAttribPointer(this, index, mState.getTargetBuffer(BufferBinding::Array), size,
Jamie Madill6e18a232019-01-16 13:27:14 -05004799 type, ConvertToBool(normalized), stride, ptr);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004800 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004801}
4802
Shao80957d92017-02-20 21:25:59 +08004803void Context::vertexAttribFormat(GLuint attribIndex,
4804 GLint size,
Jamie Madilldd34b3b2019-01-16 09:59:54 -05004805 VertexAttribType type,
Shao80957d92017-02-20 21:25:59 +08004806 GLboolean normalized,
4807 GLuint relativeOffset)
4808{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004809 mState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
4810 relativeOffset);
Jamie Madilld84b6732018-09-06 15:54:35 -04004811 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004812}
4813
4814void Context::vertexAttribIFormat(GLuint attribIndex,
4815 GLint size,
Jamie Madilldd34b3b2019-01-16 09:59:54 -05004816 VertexAttribType type,
Shao80957d92017-02-20 21:25:59 +08004817 GLuint relativeOffset)
4818{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004819 mState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
Jamie Madilld84b6732018-09-06 15:54:35 -04004820 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004821}
4822
4823void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4824{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004825 mState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004826 mStateCache.onVertexArrayStateChange(this);
Shao80957d92017-02-20 21:25:59 +08004827}
4828
Jiajia Qin5451d532017-11-16 17:16:34 +08004829void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004830{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004831 mState.setVertexBindingDivisor(bindingIndex, divisor);
Jamie Madilld84b6732018-09-06 15:54:35 -04004832 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004833}
4834
Jamie Madillc20ab272016-06-09 07:20:46 -07004835void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4836{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004837 mState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004838}
4839
4840void Context::vertexAttribIPointer(GLuint index,
4841 GLint size,
Jamie Madilldd34b3b2019-01-16 09:59:54 -05004842 VertexAttribType type,
Jamie Madillc20ab272016-06-09 07:20:46 -07004843 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004844 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004845{
Jamie Madill6e18a232019-01-16 13:27:14 -05004846 mState.setVertexAttribIPointer(this, index, mState.getTargetBuffer(BufferBinding::Array), size,
4847 type, stride, pointer);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004848 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004849}
4850
4851void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4852{
4853 GLint vals[4] = {x, y, z, w};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004854 mState.setVertexAttribi(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004855 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004856}
4857
4858void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4859{
4860 GLuint vals[4] = {x, y, z, w};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004861 mState.setVertexAttribu(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004862 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004863}
4864
4865void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4866{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004867 mState.setVertexAttribi(index, v);
Jamie Madilld84b6732018-09-06 15:54:35 -04004868 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004869}
4870
4871void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4872{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004873 mState.setVertexAttribu(index, v);
Jamie Madilld84b6732018-09-06 15:54:35 -04004874 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004875}
4876
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004877void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4878{
4879 const VertexAttribCurrentValueData &currentValues =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004880 getState().getVertexAttribCurrentValue(index);
4881 const VertexArray *vao = getState().getVertexArray();
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004882 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4883 currentValues, pname, params);
4884}
4885
Brandon Jones59770802018-04-02 13:18:42 -07004886void Context::getVertexAttribivRobust(GLuint index,
4887 GLenum pname,
4888 GLsizei bufSize,
4889 GLsizei *length,
4890 GLint *params)
4891{
4892 getVertexAttribiv(index, pname, params);
4893}
4894
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004895void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4896{
4897 const VertexAttribCurrentValueData &currentValues =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004898 getState().getVertexAttribCurrentValue(index);
4899 const VertexArray *vao = getState().getVertexArray();
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004900 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4901 currentValues, pname, params);
4902}
4903
Brandon Jones59770802018-04-02 13:18:42 -07004904void Context::getVertexAttribfvRobust(GLuint index,
4905 GLenum pname,
4906 GLsizei bufSize,
4907 GLsizei *length,
4908 GLfloat *params)
4909{
4910 getVertexAttribfv(index, pname, params);
4911}
4912
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004913void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4914{
4915 const VertexAttribCurrentValueData &currentValues =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004916 getState().getVertexAttribCurrentValue(index);
4917 const VertexArray *vao = getState().getVertexArray();
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004918 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4919 currentValues, pname, params);
4920}
4921
Brandon Jones59770802018-04-02 13:18:42 -07004922void Context::getVertexAttribIivRobust(GLuint index,
4923 GLenum pname,
4924 GLsizei bufSize,
4925 GLsizei *length,
4926 GLint *params)
4927{
4928 getVertexAttribIiv(index, pname, params);
4929}
4930
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004931void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4932{
4933 const VertexAttribCurrentValueData &currentValues =
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004934 getState().getVertexAttribCurrentValue(index);
4935 const VertexArray *vao = getState().getVertexArray();
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004936 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4937 currentValues, pname, params);
4938}
4939
Brandon Jones59770802018-04-02 13:18:42 -07004940void Context::getVertexAttribIuivRobust(GLuint index,
4941 GLenum pname,
4942 GLsizei bufSize,
4943 GLsizei *length,
4944 GLuint *params)
4945{
4946 getVertexAttribIuiv(index, pname, params);
4947}
4948
Jamie Madill876429b2017-04-20 15:46:24 -04004949void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004950{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004951 const VertexAttribute &attrib = getState().getVertexArray()->getVertexAttribute(index);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004952 QueryVertexAttribPointerv(attrib, pname, pointer);
4953}
4954
Brandon Jones59770802018-04-02 13:18:42 -07004955void Context::getVertexAttribPointervRobust(GLuint index,
4956 GLenum pname,
4957 GLsizei bufSize,
4958 GLsizei *length,
4959 void **pointer)
4960{
4961 getVertexAttribPointerv(index, pname, pointer);
4962}
4963
Jamie Madillc20ab272016-06-09 07:20:46 -07004964void Context::debugMessageControl(GLenum source,
4965 GLenum type,
4966 GLenum severity,
4967 GLsizei count,
4968 const GLuint *ids,
4969 GLboolean enabled)
4970{
4971 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004972 mState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
4973 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004974}
4975
4976void Context::debugMessageInsert(GLenum source,
4977 GLenum type,
4978 GLuint id,
4979 GLenum severity,
4980 GLsizei length,
4981 const GLchar *buf)
4982{
4983 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004984 mState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004985}
4986
4987void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4988{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05004989 mState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004990}
4991
4992GLuint Context::getDebugMessageLog(GLuint count,
4993 GLsizei bufSize,
4994 GLenum *sources,
4995 GLenum *types,
4996 GLuint *ids,
4997 GLenum *severities,
4998 GLsizei *lengths,
4999 GLchar *messageLog)
5000{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005001 return static_cast<GLuint>(mState.getDebug().getMessages(count, bufSize, sources, types, ids,
5002 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07005003}
5004
5005void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
5006{
5007 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005008 mState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05005009 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07005010}
5011
5012void Context::popDebugGroup()
5013{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005014 mState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05005015 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07005016}
5017
Corentin Wallez336129f2017-10-17 15:55:40 -04005018void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04005019{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005020 Buffer *buffer = mState.getTargetBuffer(target);
Jamie Madill29639852016-09-02 15:00:09 -04005021 ASSERT(buffer);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005022 ANGLE_CONTEXT_TRY(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04005023}
5024
Corentin Wallez336129f2017-10-17 15:55:40 -04005025void Context::bufferSubData(BufferBinding target,
5026 GLintptr offset,
5027 GLsizeiptr size,
5028 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04005029{
Courtney Goeltzenleuchter62114aa2018-08-28 09:36:46 -06005030 if (data == nullptr || size == 0)
Jamie Madill29639852016-09-02 15:00:09 -04005031 {
5032 return;
5033 }
5034
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005035 Buffer *buffer = mState.getTargetBuffer(target);
Jamie Madill29639852016-09-02 15:00:09 -04005036 ASSERT(buffer);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005037 ANGLE_CONTEXT_TRY(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04005038}
5039
Jamie Madillef300b12016-10-07 15:12:09 -04005040void Context::attachShader(GLuint program, GLuint shader)
5041{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005042 Program *programObject = mState.mShaderProgramManager->getProgram(program);
5043 Shader *shaderObject = mState.mShaderProgramManager->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04005044 ASSERT(programObject && shaderObject);
5045 programObject->attachShader(shaderObject);
5046}
5047
Kenneth Russellf2f6f652016-10-05 19:53:23 -07005048const Workarounds &Context::getWorkarounds() const
5049{
5050 return mWorkarounds;
5051}
5052
Corentin Wallez336129f2017-10-17 15:55:40 -04005053void Context::copyBufferSubData(BufferBinding readTarget,
5054 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04005055 GLintptr readOffset,
5056 GLintptr writeOffset,
5057 GLsizeiptr size)
5058{
5059 // if size is zero, the copy is a successful no-op
5060 if (size == 0)
5061 {
5062 return;
5063 }
5064
5065 // TODO(jmadill): cache these.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005066 Buffer *readBuffer = mState.getTargetBuffer(readTarget);
5067 Buffer *writeBuffer = mState.getTargetBuffer(writeTarget);
Jamie Madillb0817d12016-11-01 15:48:31 -04005068
Jamie Madill4f6592f2018-11-27 16:37:45 -05005069 ANGLE_CONTEXT_TRY(
5070 writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04005071}
5072
Jamie Madill01a80ee2016-11-07 12:06:18 -05005073void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
5074{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005075 // Ideally we could share the program query with the validation layer if possible.
5076 Program *programObject = getProgramResolveLink(program);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005077 ASSERT(programObject);
5078 programObject->bindAttributeLocation(index, name);
5079}
5080
Corentin Wallez336129f2017-10-17 15:55:40 -04005081void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08005082{
5083 bindBufferRange(target, index, buffer, 0, 0);
5084}
5085
Corentin Wallez336129f2017-10-17 15:55:40 -04005086void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08005087 GLuint index,
5088 GLuint buffer,
5089 GLintptr offset,
5090 GLsizeiptr size)
5091{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005092 Buffer *object = mState.mBufferManager->checkBufferAllocation(mImplementation.get(), buffer);
5093 ANGLE_CONTEXT_TRY(mState.setIndexedBufferBinding(this, target, index, object, offset, size));
Jamie Madill6d32cef2018-08-14 02:34:28 -04005094 if (target == BufferBinding::Uniform)
5095 {
Jamie Madill472ddc82018-10-18 18:41:56 -04005096 mUniformBufferObserverBindings[index].bind(object);
Jamie Madilld84b6732018-09-06 15:54:35 -04005097 mStateCache.onUniformBufferStateChange(this);
5098 }
5099 else
5100 {
5101 mStateCache.onBufferBindingChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04005102 }
Jiajia Qin6eafb042016-12-27 17:04:07 +08005103}
5104
Jamie Madill01a80ee2016-11-07 12:06:18 -05005105void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
5106{
5107 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
5108 {
5109 bindReadFramebuffer(framebuffer);
5110 }
5111
5112 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
5113 {
5114 bindDrawFramebuffer(framebuffer);
5115 }
5116}
5117
5118void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
5119{
5120 ASSERT(target == GL_RENDERBUFFER);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005121 Renderbuffer *object = mState.mRenderbufferManager->checkRenderbufferAllocation(
5122 mImplementation.get(), renderbuffer);
5123 mState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005124}
5125
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005126void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08005127 GLsizei samples,
5128 GLenum internalformat,
5129 GLsizei width,
5130 GLsizei height,
5131 GLboolean fixedsamplelocations)
5132{
5133 Extents size(width, height, 1);
5134 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005135 ANGLE_CONTEXT_TRY(texture->setStorageMultisample(this, target, samples, internalformat, size,
5136 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08005137}
5138
Olli Etuaho89664842018-08-24 14:45:36 +03005139void Context::texStorage3DMultisample(TextureType target,
5140 GLsizei samples,
5141 GLenum internalformat,
5142 GLsizei width,
5143 GLsizei height,
5144 GLsizei depth,
5145 GLboolean fixedsamplelocations)
5146{
Olli Etuaho0c5a9e22018-08-27 14:36:23 +03005147 Extents size(width, height, depth);
5148 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005149 ANGLE_CONTEXT_TRY(texture->setStorageMultisample(this, target, samples, internalformat, size,
5150 ConvertToBool(fixedsamplelocations)));
Olli Etuaho89664842018-08-24 14:45:36 +03005151}
5152
JiangYizhoubddc46b2016-12-09 09:50:51 +08005153void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
5154{
JiangYizhou5b03f472017-01-09 10:22:53 +08005155 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
5156 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005157 ANGLE_CONTEXT_TRY(mState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
5158 const Framebuffer *framebuffer = mState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08005159
5160 switch (pname)
5161 {
5162 case GL_SAMPLE_POSITION:
Jamie Madill4f6592f2018-11-27 16:37:45 -05005163 ANGLE_CONTEXT_TRY(framebuffer->getSamplePosition(this, index, val));
JiangYizhoubddc46b2016-12-09 09:50:51 +08005164 break;
5165 default:
5166 UNREACHABLE();
5167 }
5168}
5169
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07005170void Context::getMultisamplefvRobust(GLenum pname,
5171 GLuint index,
5172 GLsizei bufSize,
5173 GLsizei *length,
5174 GLfloat *val)
5175{
5176 UNIMPLEMENTED();
5177}
5178
Jamie Madille8fb6402017-02-14 17:56:40 -05005179void Context::renderbufferStorage(GLenum target,
5180 GLenum internalformat,
5181 GLsizei width,
5182 GLsizei height)
5183{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005184 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
5185 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
5186
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005187 Renderbuffer *renderbuffer = mState.getCurrentRenderbuffer();
Jamie Madill4f6592f2018-11-27 16:37:45 -05005188 ANGLE_CONTEXT_TRY(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05005189}
5190
5191void Context::renderbufferStorageMultisample(GLenum target,
5192 GLsizei samples,
5193 GLenum internalformat,
5194 GLsizei width,
5195 GLsizei height)
5196{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005197 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
5198 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05005199
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005200 Renderbuffer *renderbuffer = mState.getCurrentRenderbuffer();
Jamie Madill4f6592f2018-11-27 16:37:45 -05005201 ANGLE_CONTEXT_TRY(
Jamie Madill4928b7c2017-06-20 12:57:39 -04005202 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05005203}
5204
Geoff Lang38f2cfb2017-04-11 15:23:08 -04005205void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
5206{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005207 const Sync *syncObject = getSync(sync);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005208 ANGLE_CONTEXT_TRY(QuerySynciv(this, syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04005209}
5210
JiangYizhoue18e6392017-02-20 10:32:23 +08005211void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
5212{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005213 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
JiangYizhoue18e6392017-02-20 10:32:23 +08005214 QueryFramebufferParameteriv(framebuffer, pname, params);
5215}
5216
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07005217void Context::getFramebufferParameterivRobust(GLenum target,
5218 GLenum pname,
5219 GLsizei bufSize,
5220 GLsizei *length,
5221 GLint *params)
5222{
5223 UNIMPLEMENTED();
5224}
5225
Jiajia Qin5451d532017-11-16 17:16:34 +08005226void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08005227{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005228 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Jamie Madillb983a4b2018-08-01 11:34:51 -04005229 SetFramebufferParameteri(this, framebuffer, pname, param);
JiangYizhoue18e6392017-02-20 10:32:23 +08005230}
5231
Jamie Madilldec86232018-07-11 09:01:18 -04005232bool Context::getScratchBuffer(size_t requstedSizeBytes,
5233 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05005234{
Jamie Madilldec86232018-07-11 09:01:18 -04005235 return mScratchBuffer.get(requstedSizeBytes, scratchBufferOut);
Jamie Madillb3f26b92017-07-19 15:07:41 -04005236}
5237
Jamie Madilldec86232018-07-11 09:01:18 -04005238bool Context::getZeroFilledBuffer(size_t requstedSizeBytes,
5239 angle::MemoryBuffer **zeroBufferOut) const
Jamie Madillb3f26b92017-07-19 15:07:41 -04005240{
Jamie Madilldec86232018-07-11 09:01:18 -04005241 return mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0);
Jamie Madille14951e2017-03-09 18:55:16 -05005242}
5243
Xinghua Cao2b396592017-03-29 15:36:04 +08005244void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
5245{
5246 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
5247 {
5248 return;
5249 }
5250
Xinghua Cao10a4d432017-11-28 14:46:26 +08005251 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill4f6592f2018-11-27 16:37:45 -05005252 ANGLE_CONTEXT_TRY(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08005253}
5254
Jiajia Qin5451d532017-11-16 17:16:34 +08005255void Context::dispatchComputeIndirect(GLintptr indirect)
5256{
Qin Jiajia62fcf622017-11-30 16:16:12 +08005257 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill4f6592f2018-11-27 16:37:45 -05005258 ANGLE_CONTEXT_TRY(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08005259}
5260
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005261void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005262 GLsizei levels,
5263 GLenum internalFormat,
5264 GLsizei width,
5265 GLsizei height)
5266{
5267 Extents size(width, height, 1);
5268 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005269 ANGLE_CONTEXT_TRY(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005270}
5271
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005272void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005273 GLsizei levels,
5274 GLenum internalFormat,
5275 GLsizei width,
5276 GLsizei height,
5277 GLsizei depth)
5278{
5279 Extents size(width, height, depth);
5280 Texture *texture = getTargetTexture(target);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005281 ANGLE_CONTEXT_TRY(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005282}
5283
Jiajia Qin5451d532017-11-16 17:16:34 +08005284void Context::memoryBarrier(GLbitfield barriers)
5285{
Jamie Madill4f6592f2018-11-27 16:37:45 -05005286 ANGLE_CONTEXT_TRY(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005287}
5288
5289void Context::memoryBarrierByRegion(GLbitfield barriers)
5290{
Jamie Madill4f6592f2018-11-27 16:37:45 -05005291 ANGLE_CONTEXT_TRY(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005292}
5293
Austin Eng1bf18ce2018-10-19 15:34:02 -07005294void Context::multiDrawArrays(PrimitiveMode mode,
5295 const GLint *firsts,
5296 const GLsizei *counts,
5297 GLsizei drawcount)
5298{
5299 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005300 Program *programObject = mState.getLinkedProgram(this);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005301 const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
5302 if (hasDrawID)
5303 {
5304 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5305 {
5306 if (noopDraw(mode, counts[drawID]))
5307 {
5308 continue;
5309 }
5310 programObject->setDrawIDUniform(drawID);
5311 ANGLE_CONTEXT_TRY(
5312 mImplementation->drawArrays(this, mode, firsts[drawID], counts[drawID]));
Jamie Madillae6ba9f2018-12-21 23:00:04 -05005313 MarkTransformFeedbackBufferUsage(this, counts[drawID], 1);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005314 }
5315 }
5316 else
5317 {
5318 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5319 {
5320 if (noopDraw(mode, counts[drawID]))
5321 {
5322 continue;
5323 }
5324 ANGLE_CONTEXT_TRY(
5325 mImplementation->drawArrays(this, mode, firsts[drawID], counts[drawID]));
Jamie Madillae6ba9f2018-12-21 23:00:04 -05005326 MarkTransformFeedbackBufferUsage(this, counts[drawID], 1);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005327 }
5328 }
5329}
5330
5331void Context::multiDrawArraysInstanced(PrimitiveMode mode,
5332 const GLint *firsts,
5333 const GLsizei *counts,
5334 const GLsizei *instanceCounts,
5335 GLsizei drawcount)
5336{
5337 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005338 Program *programObject = mState.getLinkedProgram(this);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005339 const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
5340 if (hasDrawID)
5341 {
5342 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5343 {
5344 if (noopDrawInstanced(mode, counts[drawID], instanceCounts[drawID]))
5345 {
5346 continue;
5347 }
5348 programObject->setDrawIDUniform(drawID);
5349 ANGLE_CONTEXT_TRY(mImplementation->drawArraysInstanced(
5350 this, mode, firsts[drawID], counts[drawID], instanceCounts[drawID]));
Jamie Madillae6ba9f2018-12-21 23:00:04 -05005351 MarkTransformFeedbackBufferUsage(this, counts[drawID], instanceCounts[drawID]);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005352 }
5353 }
5354 else
5355 {
5356 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5357 {
5358 if (noopDrawInstanced(mode, counts[drawID], instanceCounts[drawID]))
5359 {
5360 continue;
5361 }
5362 ANGLE_CONTEXT_TRY(mImplementation->drawArraysInstanced(
5363 this, mode, firsts[drawID], counts[drawID], instanceCounts[drawID]));
Jamie Madillae6ba9f2018-12-21 23:00:04 -05005364 MarkTransformFeedbackBufferUsage(this, counts[drawID], instanceCounts[drawID]);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005365 }
5366 }
5367}
5368
5369void Context::multiDrawElements(PrimitiveMode mode,
5370 const GLsizei *counts,
Jamie Madill8dc27f92018-11-29 11:45:44 -05005371 DrawElementsType type,
Austin Eng3b7c9d02018-11-21 18:09:05 -08005372 const GLvoid *const *indices,
Austin Eng1bf18ce2018-10-19 15:34:02 -07005373 GLsizei drawcount)
5374{
5375 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005376 Program *programObject = mState.getLinkedProgram(this);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005377 const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
5378 if (hasDrawID)
5379 {
5380 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5381 {
5382 if (noopDraw(mode, counts[drawID]))
5383 {
5384 continue;
5385 }
5386 programObject->setDrawIDUniform(drawID);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005387 ANGLE_CONTEXT_TRY(
Austin Eng3b7c9d02018-11-21 18:09:05 -08005388 mImplementation->drawElements(this, mode, counts[drawID], type, indices[drawID]));
Austin Eng1bf18ce2018-10-19 15:34:02 -07005389 }
5390 }
5391 else
5392 {
5393 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5394 {
5395 if (noopDraw(mode, counts[drawID]))
5396 {
5397 continue;
5398 }
Austin Eng1bf18ce2018-10-19 15:34:02 -07005399 ANGLE_CONTEXT_TRY(
Austin Eng3b7c9d02018-11-21 18:09:05 -08005400 mImplementation->drawElements(this, mode, counts[drawID], type, indices[drawID]));
Austin Eng1bf18ce2018-10-19 15:34:02 -07005401 }
5402 }
5403}
5404
5405void Context::multiDrawElementsInstanced(PrimitiveMode mode,
5406 const GLsizei *counts,
Jamie Madill8dc27f92018-11-29 11:45:44 -05005407 DrawElementsType type,
Austin Eng3b7c9d02018-11-21 18:09:05 -08005408 const GLvoid *const *indices,
Austin Eng1bf18ce2018-10-19 15:34:02 -07005409 const GLsizei *instanceCounts,
5410 GLsizei drawcount)
5411{
5412 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005413 Program *programObject = mState.getLinkedProgram(this);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005414 const bool hasDrawID = programObject && programObject->hasDrawIDUniform();
5415 if (hasDrawID)
5416 {
5417 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5418 {
5419 if (noopDrawInstanced(mode, counts[drawID], instanceCounts[drawID]))
5420 {
5421 continue;
5422 }
5423 programObject->setDrawIDUniform(drawID);
Austin Eng1bf18ce2018-10-19 15:34:02 -07005424 ANGLE_CONTEXT_TRY(mImplementation->drawElementsInstanced(
Austin Eng3b7c9d02018-11-21 18:09:05 -08005425 this, mode, counts[drawID], type, indices[drawID], instanceCounts[drawID]));
Austin Eng1bf18ce2018-10-19 15:34:02 -07005426 }
5427 }
5428 else
5429 {
5430 for (GLsizei drawID = 0; drawID < drawcount; ++drawID)
5431 {
5432 if (noopDrawInstanced(mode, counts[drawID], instanceCounts[drawID]))
5433 {
5434 continue;
5435 }
Austin Eng1bf18ce2018-10-19 15:34:02 -07005436 ANGLE_CONTEXT_TRY(mImplementation->drawElementsInstanced(
Austin Eng3b7c9d02018-11-21 18:09:05 -08005437 this, mode, counts[drawID], type, indices[drawID], instanceCounts[drawID]));
Austin Eng1bf18ce2018-10-19 15:34:02 -07005438 }
5439 }
5440}
5441
Jeff Gilbert465d6092019-01-02 16:21:18 -08005442void Context::provokingVertex(ProvokingVertex provokeMode)
5443{
5444 mState.setProvokingVertex(provokeMode);
5445}
5446
Jamie Madillc1d770e2017-04-13 17:31:24 -04005447GLenum Context::checkFramebufferStatus(GLenum target)
5448{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005449 Framebuffer *framebuffer = mState.getTargetFramebuffer(target);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005450 ASSERT(framebuffer);
Jamie Madill427064d2018-04-13 16:20:34 -04005451 return framebuffer->checkStatus(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005452}
5453
5454void Context::compileShader(GLuint shader)
5455{
5456 Shader *shaderObject = GetValidShader(this, shader);
5457 if (!shaderObject)
5458 {
5459 return;
5460 }
5461 shaderObject->compile(this);
5462}
5463
5464void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
5465{
5466 for (int i = 0; i < n; i++)
5467 {
5468 deleteBuffer(buffers[i]);
5469 }
5470}
5471
5472void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
5473{
5474 for (int i = 0; i < n; i++)
5475 {
5476 if (framebuffers[i] != 0)
5477 {
5478 deleteFramebuffer(framebuffers[i]);
5479 }
5480 }
5481}
5482
5483void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
5484{
5485 for (int i = 0; i < n; i++)
5486 {
5487 deleteRenderbuffer(renderbuffers[i]);
5488 }
5489}
5490
5491void Context::deleteTextures(GLsizei n, const GLuint *textures)
5492{
5493 for (int i = 0; i < n; i++)
5494 {
5495 if (textures[i] != 0)
5496 {
5497 deleteTexture(textures[i]);
5498 }
5499 }
5500}
5501
5502void Context::detachShader(GLuint program, GLuint shader)
5503{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005504 Program *programObject = getProgramNoResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005505 ASSERT(programObject);
5506
5507 Shader *shaderObject = getShader(shader);
5508 ASSERT(shaderObject);
5509
5510 programObject->detachShader(this, shaderObject);
5511}
5512
5513void Context::genBuffers(GLsizei n, GLuint *buffers)
5514{
5515 for (int i = 0; i < n; i++)
5516 {
5517 buffers[i] = createBuffer();
5518 }
5519}
5520
5521void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
5522{
5523 for (int i = 0; i < n; i++)
5524 {
5525 framebuffers[i] = createFramebuffer();
5526 }
5527}
5528
5529void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
5530{
5531 for (int i = 0; i < n; i++)
5532 {
5533 renderbuffers[i] = createRenderbuffer();
5534 }
5535}
5536
5537void Context::genTextures(GLsizei n, GLuint *textures)
5538{
5539 for (int i = 0; i < n; i++)
5540 {
5541 textures[i] = createTexture();
5542 }
5543}
5544
5545void Context::getActiveAttrib(GLuint program,
5546 GLuint index,
5547 GLsizei bufsize,
5548 GLsizei *length,
5549 GLint *size,
5550 GLenum *type,
5551 GLchar *name)
5552{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005553 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005554 ASSERT(programObject);
5555 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
5556}
5557
5558void Context::getActiveUniform(GLuint program,
5559 GLuint index,
5560 GLsizei bufsize,
5561 GLsizei *length,
5562 GLint *size,
5563 GLenum *type,
5564 GLchar *name)
5565{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005566 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005567 ASSERT(programObject);
5568 programObject->getActiveUniform(index, bufsize, length, size, type, name);
5569}
5570
5571void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
5572{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005573 Program *programObject = getProgramNoResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005574 ASSERT(programObject);
5575 programObject->getAttachedShaders(maxcount, count, shaders);
5576}
5577
5578GLint Context::getAttribLocation(GLuint program, const GLchar *name)
5579{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005580 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005581 ASSERT(programObject);
5582 return programObject->getAttributeLocation(name);
5583}
5584
5585void Context::getBooleanv(GLenum pname, GLboolean *params)
5586{
5587 GLenum nativeType;
5588 unsigned int numParams = 0;
5589 getQueryParameterInfo(pname, &nativeType, &numParams);
5590
5591 if (nativeType == GL_BOOL)
5592 {
5593 getBooleanvImpl(pname, params);
5594 }
5595 else
5596 {
5597 CastStateValues(this, nativeType, pname, numParams, params);
5598 }
5599}
5600
Brandon Jones59770802018-04-02 13:18:42 -07005601void Context::getBooleanvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLboolean *params)
5602{
5603 getBooleanv(pname, params);
5604}
5605
Jamie Madillc1d770e2017-04-13 17:31:24 -04005606void Context::getFloatv(GLenum pname, GLfloat *params)
5607{
5608 GLenum nativeType;
5609 unsigned int numParams = 0;
5610 getQueryParameterInfo(pname, &nativeType, &numParams);
5611
5612 if (nativeType == GL_FLOAT)
5613 {
5614 getFloatvImpl(pname, params);
5615 }
5616 else
5617 {
5618 CastStateValues(this, nativeType, pname, numParams, params);
5619 }
5620}
5621
Brandon Jones59770802018-04-02 13:18:42 -07005622void Context::getFloatvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLfloat *params)
5623{
5624 getFloatv(pname, params);
5625}
5626
Jamie Madillc1d770e2017-04-13 17:31:24 -04005627void Context::getIntegerv(GLenum pname, GLint *params)
5628{
5629 GLenum nativeType;
5630 unsigned int numParams = 0;
5631 getQueryParameterInfo(pname, &nativeType, &numParams);
5632
5633 if (nativeType == GL_INT)
5634 {
5635 getIntegervImpl(pname, params);
5636 }
5637 else
5638 {
5639 CastStateValues(this, nativeType, pname, numParams, params);
5640 }
5641}
5642
Brandon Jones59770802018-04-02 13:18:42 -07005643void Context::getIntegervRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint *data)
5644{
5645 getIntegerv(pname, data);
5646}
5647
Jamie Madillc1d770e2017-04-13 17:31:24 -04005648void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
5649{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005650 // Don't resolve link if checking the link completion status.
5651 Program *programObject = (pname == GL_COMPLETION_STATUS_KHR ? getProgramNoResolveLink(program)
5652 : getProgramResolveLink(program));
Jamie Madillc1d770e2017-04-13 17:31:24 -04005653 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04005654 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005655}
5656
Brandon Jones59770802018-04-02 13:18:42 -07005657void Context::getProgramivRobust(GLuint program,
5658 GLenum pname,
5659 GLsizei bufSize,
5660 GLsizei *length,
5661 GLint *params)
5662{
5663 getProgramiv(program, pname, params);
5664}
5665
Jiajia Qin5451d532017-11-16 17:16:34 +08005666void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
5667{
5668 UNIMPLEMENTED();
5669}
5670
Jamie Madillbe849e42017-05-02 15:49:00 -04005671void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005672{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005673 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005674 ASSERT(programObject);
5675 programObject->getInfoLog(bufsize, length, infolog);
5676}
5677
Jiajia Qin5451d532017-11-16 17:16:34 +08005678void Context::getProgramPipelineInfoLog(GLuint pipeline,
5679 GLsizei bufSize,
5680 GLsizei *length,
5681 GLchar *infoLog)
5682{
5683 UNIMPLEMENTED();
5684}
5685
Jamie Madillc1d770e2017-04-13 17:31:24 -04005686void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
5687{
5688 Shader *shaderObject = getShader(shader);
5689 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08005690 QueryShaderiv(shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005691}
5692
Brandon Jones59770802018-04-02 13:18:42 -07005693void Context::getShaderivRobust(GLuint shader,
5694 GLenum pname,
5695 GLsizei bufSize,
5696 GLsizei *length,
5697 GLint *params)
5698{
5699 getShaderiv(shader, pname, params);
5700}
5701
Jamie Madillc1d770e2017-04-13 17:31:24 -04005702void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
5703{
5704 Shader *shaderObject = getShader(shader);
5705 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08005706 shaderObject->getInfoLog(bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005707}
5708
5709void Context::getShaderPrecisionFormat(GLenum shadertype,
5710 GLenum precisiontype,
5711 GLint *range,
5712 GLint *precision)
5713{
5714 // TODO(jmadill): Compute shaders.
5715
5716 switch (shadertype)
5717 {
5718 case GL_VERTEX_SHADER:
5719 switch (precisiontype)
5720 {
5721 case GL_LOW_FLOAT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005722 mState.mCaps.vertexLowpFloat.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005723 break;
5724 case GL_MEDIUM_FLOAT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005725 mState.mCaps.vertexMediumpFloat.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005726 break;
5727 case GL_HIGH_FLOAT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005728 mState.mCaps.vertexHighpFloat.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005729 break;
5730
5731 case GL_LOW_INT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005732 mState.mCaps.vertexLowpInt.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005733 break;
5734 case GL_MEDIUM_INT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005735 mState.mCaps.vertexMediumpInt.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005736 break;
5737 case GL_HIGH_INT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005738 mState.mCaps.vertexHighpInt.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005739 break;
5740
5741 default:
5742 UNREACHABLE();
5743 return;
5744 }
5745 break;
5746
5747 case GL_FRAGMENT_SHADER:
5748 switch (precisiontype)
5749 {
5750 case GL_LOW_FLOAT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005751 mState.mCaps.fragmentLowpFloat.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005752 break;
5753 case GL_MEDIUM_FLOAT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005754 mState.mCaps.fragmentMediumpFloat.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005755 break;
5756 case GL_HIGH_FLOAT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005757 mState.mCaps.fragmentHighpFloat.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005758 break;
5759
5760 case GL_LOW_INT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005761 mState.mCaps.fragmentLowpInt.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005762 break;
5763 case GL_MEDIUM_INT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005764 mState.mCaps.fragmentMediumpInt.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005765 break;
5766 case GL_HIGH_INT:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005767 mState.mCaps.fragmentHighpInt.get(range, precision);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005768 break;
5769
5770 default:
5771 UNREACHABLE();
5772 return;
5773 }
5774 break;
5775
5776 default:
5777 UNREACHABLE();
5778 return;
5779 }
5780}
5781
5782void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
5783{
5784 Shader *shaderObject = getShader(shader);
5785 ASSERT(shaderObject);
5786 shaderObject->getSource(bufsize, length, source);
5787}
5788
5789void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
5790{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005791 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005792 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005793 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005794}
5795
Brandon Jones59770802018-04-02 13:18:42 -07005796void Context::getUniformfvRobust(GLuint program,
5797 GLint location,
5798 GLsizei bufSize,
5799 GLsizei *length,
5800 GLfloat *params)
5801{
5802 getUniformfv(program, location, params);
5803}
5804
Jamie Madillc1d770e2017-04-13 17:31:24 -04005805void Context::getUniformiv(GLuint program, GLint location, GLint *params)
5806{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005807 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005808 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005809 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005810}
5811
Brandon Jones59770802018-04-02 13:18:42 -07005812void Context::getUniformivRobust(GLuint program,
5813 GLint location,
5814 GLsizei bufSize,
5815 GLsizei *length,
5816 GLint *params)
5817{
5818 getUniformiv(program, location, params);
5819}
5820
Jamie Madillc1d770e2017-04-13 17:31:24 -04005821GLint Context::getUniformLocation(GLuint program, const GLchar *name)
5822{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005823 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005824 ASSERT(programObject);
5825 return programObject->getUniformLocation(name);
5826}
5827
5828GLboolean Context::isBuffer(GLuint buffer)
5829{
5830 if (buffer == 0)
5831 {
5832 return GL_FALSE;
5833 }
5834
5835 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
5836}
5837
5838GLboolean Context::isEnabled(GLenum cap)
5839{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005840 return mState.getEnableFeature(cap);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005841}
5842
5843GLboolean Context::isFramebuffer(GLuint framebuffer)
5844{
5845 if (framebuffer == 0)
5846 {
5847 return GL_FALSE;
5848 }
5849
5850 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
5851}
5852
5853GLboolean Context::isProgram(GLuint program)
5854{
5855 if (program == 0)
5856 {
5857 return GL_FALSE;
5858 }
5859
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005860 return (getProgramNoResolveLink(program) ? GL_TRUE : GL_FALSE);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005861}
5862
5863GLboolean Context::isRenderbuffer(GLuint renderbuffer)
5864{
5865 if (renderbuffer == 0)
5866 {
5867 return GL_FALSE;
5868 }
5869
5870 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
5871}
5872
5873GLboolean Context::isShader(GLuint shader)
5874{
5875 if (shader == 0)
5876 {
5877 return GL_FALSE;
5878 }
5879
5880 return (getShader(shader) ? GL_TRUE : GL_FALSE);
5881}
5882
5883GLboolean Context::isTexture(GLuint texture)
5884{
5885 if (texture == 0)
5886 {
5887 return GL_FALSE;
5888 }
5889
5890 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
5891}
5892
5893void Context::linkProgram(GLuint program)
5894{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04005895 Program *programObject = getProgramNoResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005896 ASSERT(programObject);
Jamie Madill4f6592f2018-11-27 16:37:45 -05005897 ANGLE_CONTEXT_TRY(programObject->link(this));
jchen107ae70d82018-07-06 13:47:01 +08005898
5899 // Don't parallel link a program which is active in any GL contexts. With this assumption, we
5900 // don't need to worry that:
5901 // 1. Draw calls after link use the new executable code or the old one depending on the link
5902 // result.
5903 // 2. When a backend program, e.g., ProgramD3D is linking, other backend classes like
5904 // StateManager11, Renderer11, etc., may have a chance to make unexpected calls to
5905 // ProgramD3D.
5906 if (programObject->isInUse())
5907 {
Jamie Madill785e8a02018-10-04 17:42:00 -04005908 programObject->resolveLink(this);
Jamie Madilldf836ff2018-10-01 10:36:24 -04005909 if (programObject->isLinked())
5910 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005911 ANGLE_CONTEXT_TRY(mState.onProgramExecutableChange(this, programObject));
Jamie Madilldf836ff2018-10-01 10:36:24 -04005912 }
jchen107ae70d82018-07-06 13:47:01 +08005913 mStateCache.onProgramExecutableChange(this);
5914 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005915}
5916
5917void Context::releaseShaderCompiler()
5918{
Jamie Madill4928b7c2017-06-20 12:57:39 -04005919 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005920}
5921
5922void Context::shaderBinary(GLsizei n,
5923 const GLuint *shaders,
5924 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04005925 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005926 GLsizei length)
5927{
5928 // No binary shader formats are supported.
5929 UNIMPLEMENTED();
5930}
5931
Olli Etuaho0ca09752018-09-24 11:00:50 +03005932void Context::bindFragDataLocationIndexed(GLuint program,
5933 GLuint colorNumber,
5934 GLuint index,
5935 const char *name)
5936{
5937 Program *programObject = getProgramNoResolveLink(program);
5938 programObject->bindFragmentOutputLocation(colorNumber, name);
5939 programObject->bindFragmentOutputIndex(index, name);
5940}
5941
5942void Context::bindFragDataLocation(GLuint program, GLuint colorNumber, const char *name)
5943{
5944 bindFragDataLocationIndexed(program, colorNumber, 0u, name);
5945}
5946
5947int Context::getFragDataIndex(GLuint program, const char *name)
5948{
5949 Program *programObject = getProgramResolveLink(program);
5950 return programObject->getFragDataIndex(name);
5951}
5952
5953int Context::getProgramResourceLocationIndex(GLuint program,
5954 GLenum programInterface,
5955 const char *name)
5956{
5957 Program *programObject = getProgramResolveLink(program);
5958 ASSERT(programInterface == GL_PROGRAM_OUTPUT);
5959 return programObject->getFragDataIndex(name);
5960}
5961
Jamie Madillc1d770e2017-04-13 17:31:24 -04005962void Context::shaderSource(GLuint shader,
5963 GLsizei count,
5964 const GLchar *const *string,
5965 const GLint *length)
5966{
5967 Shader *shaderObject = getShader(shader);
5968 ASSERT(shaderObject);
5969 shaderObject->setSource(count, string, length);
5970}
5971
5972void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
5973{
5974 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
5975}
5976
5977void Context::stencilMask(GLuint mask)
5978{
5979 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
5980}
5981
5982void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
5983{
5984 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
5985}
5986
5987void Context::uniform1f(GLint location, GLfloat x)
5988{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005989 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04005990 program->setUniform1fv(location, 1, &x);
5991}
5992
5993void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
5994{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05005995 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04005996 program->setUniform1fv(location, count, v);
5997}
5998
Jamie Madill7e4eff12018-08-08 15:49:26 -04005999void Context::setUniform1iImpl(Program *program, GLint location, GLsizei count, const GLint *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04006000{
Jamie Madille3e680c2018-12-03 17:49:08 -05006001 program->setUniform1iv(this, location, count, v);
6002}
6003
6004void Context::onSamplerUniformChange(size_t textureUnitIndex)
6005{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006006 mState.onActiveTextureChange(this, textureUnitIndex);
Jamie Madille3e680c2018-12-03 17:49:08 -05006007 mStateCache.onActiveTextureChange(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006008}
6009
Jamie Madill7e4eff12018-08-08 15:49:26 -04006010void Context::uniform1i(GLint location, GLint x)
6011{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006012 setUniform1iImpl(mState.getProgram(), location, 1, &x);
Jamie Madill7e4eff12018-08-08 15:49:26 -04006013}
6014
Jamie Madillc1d770e2017-04-13 17:31:24 -04006015void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
6016{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006017 setUniform1iImpl(mState.getProgram(), location, count, v);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006018}
6019
6020void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
6021{
6022 GLfloat xy[2] = {x, y};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006023 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006024 program->setUniform2fv(location, 1, xy);
6025}
6026
6027void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
6028{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006029 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006030 program->setUniform2fv(location, count, v);
6031}
6032
6033void Context::uniform2i(GLint location, GLint x, GLint y)
6034{
6035 GLint xy[2] = {x, y};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006036 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006037 program->setUniform2iv(location, 1, xy);
6038}
6039
6040void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
6041{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006042 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006043 program->setUniform2iv(location, count, v);
6044}
6045
6046void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
6047{
6048 GLfloat xyz[3] = {x, y, z};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006049 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006050 program->setUniform3fv(location, 1, xyz);
6051}
6052
6053void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
6054{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006055 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006056 program->setUniform3fv(location, count, v);
6057}
6058
6059void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
6060{
6061 GLint xyz[3] = {x, y, z};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006062 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006063 program->setUniform3iv(location, 1, xyz);
6064}
6065
6066void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
6067{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006068 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006069 program->setUniform3iv(location, count, v);
6070}
6071
6072void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
6073{
6074 GLfloat xyzw[4] = {x, y, z, w};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006075 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006076 program->setUniform4fv(location, 1, xyzw);
6077}
6078
6079void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
6080{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006081 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006082 program->setUniform4fv(location, count, v);
6083}
6084
6085void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
6086{
6087 GLint xyzw[4] = {x, y, z, w};
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006088 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006089 program->setUniform4iv(location, 1, xyzw);
6090}
6091
6092void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
6093{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006094 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006095 program->setUniform4iv(location, count, v);
6096}
6097
6098void Context::uniformMatrix2fv(GLint location,
6099 GLsizei count,
6100 GLboolean transpose,
6101 const GLfloat *value)
6102{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006103 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006104 program->setUniformMatrix2fv(location, count, transpose, value);
6105}
6106
6107void Context::uniformMatrix3fv(GLint location,
6108 GLsizei count,
6109 GLboolean transpose,
6110 const GLfloat *value)
6111{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006112 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006113 program->setUniformMatrix3fv(location, count, transpose, value);
6114}
6115
6116void Context::uniformMatrix4fv(GLint location,
6117 GLsizei count,
6118 GLboolean transpose,
6119 const GLfloat *value)
6120{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006121 Program *program = mState.getProgram();
Jamie Madillc1d770e2017-04-13 17:31:24 -04006122 program->setUniformMatrix4fv(location, count, transpose, value);
6123}
6124
6125void Context::validateProgram(GLuint program)
6126{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006127 Program *programObject = getProgramResolveLink(program);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006128 ASSERT(programObject);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006129 programObject->validate(mState.mCaps);
Jamie Madillc1d770e2017-04-13 17:31:24 -04006130}
6131
Jiajia Qin5451d532017-11-16 17:16:34 +08006132void Context::validateProgramPipeline(GLuint pipeline)
6133{
6134 UNIMPLEMENTED();
6135}
6136
Jamie Madilld04908b2017-06-09 14:15:35 -04006137void Context::getProgramBinary(GLuint program,
6138 GLsizei bufSize,
6139 GLsizei *length,
6140 GLenum *binaryFormat,
6141 void *binary)
6142{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006143 Program *programObject = getProgramResolveLink(program);
Jamie Madilld04908b2017-06-09 14:15:35 -04006144 ASSERT(programObject != nullptr);
6145
Jamie Madill4f6592f2018-11-27 16:37:45 -05006146 ANGLE_CONTEXT_TRY(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
Jamie Madilld04908b2017-06-09 14:15:35 -04006147}
6148
6149void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
6150{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006151 Program *programObject = getProgramResolveLink(program);
Jamie Madilld04908b2017-06-09 14:15:35 -04006152 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04006153
Jamie Madill4f6592f2018-11-27 16:37:45 -05006154 ANGLE_CONTEXT_TRY(programObject->loadBinary(this, binaryFormat, binary, length));
Jamie Madill70aeda42018-08-20 12:17:40 -04006155 if (programObject->isInUse())
6156 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006157 ANGLE_CONTEXT_TRY(mState.onProgramExecutableChange(this, programObject));
Jamie Madilldf836ff2018-10-01 10:36:24 -04006158 mStateCache.onProgramExecutableChange(this);
Jamie Madill70aeda42018-08-20 12:17:40 -04006159 }
Jamie Madilld04908b2017-06-09 14:15:35 -04006160}
6161
Jamie Madillff325f12017-08-26 15:06:05 -04006162void Context::uniform1ui(GLint location, GLuint v0)
6163{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006164 Program *program = mState.getProgram();
Jamie Madillff325f12017-08-26 15:06:05 -04006165 program->setUniform1uiv(location, 1, &v0);
6166}
6167
6168void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
6169{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006170 Program *program = mState.getProgram();
Jamie Madillff325f12017-08-26 15:06:05 -04006171 const GLuint xy[] = {v0, v1};
6172 program->setUniform2uiv(location, 1, xy);
6173}
6174
6175void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
6176{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006177 Program *program = mState.getProgram();
Jamie Madillff325f12017-08-26 15:06:05 -04006178 const GLuint xyz[] = {v0, v1, v2};
6179 program->setUniform3uiv(location, 1, xyz);
6180}
6181
6182void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
6183{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006184 Program *program = mState.getProgram();
Jamie Madillff325f12017-08-26 15:06:05 -04006185 const GLuint xyzw[] = {v0, v1, v2, v3};
6186 program->setUniform4uiv(location, 1, xyzw);
6187}
6188
6189void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
6190{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006191 Program *program = mState.getProgram();
Jamie Madillff325f12017-08-26 15:06:05 -04006192 program->setUniform1uiv(location, count, value);
6193}
6194void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
6195{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006196 Program *program = mState.getProgram();
Jamie Madillff325f12017-08-26 15:06:05 -04006197 program->setUniform2uiv(location, count, value);
6198}
6199
6200void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
6201{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006202 Program *program = mState.getProgram();
Jamie Madillff325f12017-08-26 15:06:05 -04006203 program->setUniform3uiv(location, count, value);
6204}
6205
6206void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
6207{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006208 Program *program = mState.getProgram();
Jamie Madillff325f12017-08-26 15:06:05 -04006209 program->setUniform4uiv(location, count, value);
6210}
6211
Jamie Madillf0e04492017-08-26 15:28:42 -04006212void Context::genQueries(GLsizei n, GLuint *ids)
6213{
6214 for (GLsizei i = 0; i < n; i++)
6215 {
6216 GLuint handle = mQueryHandleAllocator.allocate();
6217 mQueryMap.assign(handle, nullptr);
6218 ids[i] = handle;
6219 }
6220}
6221
6222void Context::deleteQueries(GLsizei n, const GLuint *ids)
6223{
6224 for (int i = 0; i < n; i++)
6225 {
6226 GLuint query = ids[i];
6227
6228 Query *queryObject = nullptr;
6229 if (mQueryMap.erase(query, &queryObject))
6230 {
6231 mQueryHandleAllocator.release(query);
6232 if (queryObject)
6233 {
6234 queryObject->release(this);
6235 }
6236 }
6237 }
6238}
6239
6240GLboolean Context::isQuery(GLuint id)
6241{
Corentin Wallezad3ae902018-03-09 13:40:42 -05006242 return (getQuery(id, false, QueryType::InvalidEnum) != nullptr) ? GL_TRUE : GL_FALSE;
Jamie Madillf0e04492017-08-26 15:28:42 -04006243}
6244
Jamie Madillc8c95812017-08-26 18:40:09 -04006245void Context::uniformMatrix2x3fv(GLint location,
6246 GLsizei count,
6247 GLboolean transpose,
6248 const GLfloat *value)
6249{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006250 Program *program = mState.getProgram();
Jamie Madillc8c95812017-08-26 18:40:09 -04006251 program->setUniformMatrix2x3fv(location, count, transpose, value);
6252}
6253
6254void Context::uniformMatrix3x2fv(GLint location,
6255 GLsizei count,
6256 GLboolean transpose,
6257 const GLfloat *value)
6258{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006259 Program *program = mState.getProgram();
Jamie Madillc8c95812017-08-26 18:40:09 -04006260 program->setUniformMatrix3x2fv(location, count, transpose, value);
6261}
6262
6263void Context::uniformMatrix2x4fv(GLint location,
6264 GLsizei count,
6265 GLboolean transpose,
6266 const GLfloat *value)
6267{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006268 Program *program = mState.getProgram();
Jamie Madillc8c95812017-08-26 18:40:09 -04006269 program->setUniformMatrix2x4fv(location, count, transpose, value);
6270}
6271
6272void Context::uniformMatrix4x2fv(GLint location,
6273 GLsizei count,
6274 GLboolean transpose,
6275 const GLfloat *value)
6276{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006277 Program *program = mState.getProgram();
Jamie Madillc8c95812017-08-26 18:40:09 -04006278 program->setUniformMatrix4x2fv(location, count, transpose, value);
6279}
6280
6281void Context::uniformMatrix3x4fv(GLint location,
6282 GLsizei count,
6283 GLboolean transpose,
6284 const GLfloat *value)
6285{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006286 Program *program = mState.getProgram();
Jamie Madillc8c95812017-08-26 18:40:09 -04006287 program->setUniformMatrix3x4fv(location, count, transpose, value);
6288}
6289
6290void Context::uniformMatrix4x3fv(GLint location,
6291 GLsizei count,
6292 GLboolean transpose,
6293 const GLfloat *value)
6294{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006295 Program *program = mState.getProgram();
Jamie Madillc8c95812017-08-26 18:40:09 -04006296 program->setUniformMatrix4x3fv(location, count, transpose, value);
6297}
6298
Jamie Madilld7576732017-08-26 18:49:50 -04006299void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
6300{
6301 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
6302 {
6303 GLuint vertexArray = arrays[arrayIndex];
6304
6305 if (arrays[arrayIndex] != 0)
6306 {
6307 VertexArray *vertexArrayObject = nullptr;
6308 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
6309 {
6310 if (vertexArrayObject != nullptr)
6311 {
6312 detachVertexArray(vertexArray);
6313 vertexArrayObject->onDestroy(this);
6314 }
6315
6316 mVertexArrayHandleAllocator.release(vertexArray);
6317 }
6318 }
6319 }
6320}
6321
6322void Context::genVertexArrays(GLsizei n, GLuint *arrays)
6323{
6324 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
6325 {
6326 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
6327 mVertexArrayMap.assign(vertexArray, nullptr);
6328 arrays[arrayIndex] = vertexArray;
6329 }
6330}
6331
6332bool Context::isVertexArray(GLuint array)
6333{
6334 if (array == 0)
6335 {
6336 return GL_FALSE;
6337 }
6338
6339 VertexArray *vao = getVertexArray(array);
6340 return (vao != nullptr ? GL_TRUE : GL_FALSE);
6341}
6342
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006343void Context::endTransformFeedback()
6344{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006345 TransformFeedback *transformFeedback = mState.getCurrentTransformFeedback();
Geoff Lang91002262018-12-12 16:05:24 -05006346 ANGLE_CONTEXT_TRY(transformFeedback->end(this));
Jamie Madill3a256222018-12-08 09:56:39 -05006347 mStateCache.onActiveTransformFeedbackChange(this);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006348}
6349
6350void Context::transformFeedbackVaryings(GLuint program,
6351 GLsizei count,
6352 const GLchar *const *varyings,
6353 GLenum bufferMode)
6354{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006355 Program *programObject = getProgramResolveLink(program);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006356 ASSERT(programObject);
6357 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
6358}
6359
6360void Context::getTransformFeedbackVarying(GLuint program,
6361 GLuint index,
6362 GLsizei bufSize,
6363 GLsizei *length,
6364 GLsizei *size,
6365 GLenum *type,
6366 GLchar *name)
6367{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006368 Program *programObject = getProgramResolveLink(program);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006369 ASSERT(programObject);
6370 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
6371}
6372
6373void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
6374{
6375 for (int i = 0; i < n; i++)
6376 {
6377 GLuint transformFeedback = ids[i];
6378 if (transformFeedback == 0)
6379 {
6380 continue;
6381 }
6382
6383 TransformFeedback *transformFeedbackObject = nullptr;
6384 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
6385 {
6386 if (transformFeedbackObject != nullptr)
6387 {
6388 detachTransformFeedback(transformFeedback);
6389 transformFeedbackObject->release(this);
6390 }
6391
6392 mTransformFeedbackHandleAllocator.release(transformFeedback);
6393 }
6394 }
6395}
6396
6397void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
6398{
6399 for (int i = 0; i < n; i++)
6400 {
6401 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
6402 mTransformFeedbackMap.assign(transformFeedback, nullptr);
6403 ids[i] = transformFeedback;
6404 }
6405}
6406
6407bool Context::isTransformFeedback(GLuint id)
6408{
6409 if (id == 0)
6410 {
6411 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
6412 // returns FALSE
6413 return GL_FALSE;
6414 }
6415
6416 const TransformFeedback *transformFeedback = getTransformFeedback(id);
6417 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
6418}
6419
6420void Context::pauseTransformFeedback()
6421{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006422 TransformFeedback *transformFeedback = mState.getCurrentTransformFeedback();
Geoff Lang91002262018-12-12 16:05:24 -05006423 ANGLE_CONTEXT_TRY(transformFeedback->pause(this));
Jamie Madill3a256222018-12-08 09:56:39 -05006424 mStateCache.onActiveTransformFeedbackChange(this);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006425}
6426
6427void Context::resumeTransformFeedback()
6428{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006429 TransformFeedback *transformFeedback = mState.getCurrentTransformFeedback();
Geoff Lang91002262018-12-12 16:05:24 -05006430 ANGLE_CONTEXT_TRY(transformFeedback->resume(this));
Jamie Madill3a256222018-12-08 09:56:39 -05006431 mStateCache.onActiveTransformFeedbackChange(this);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006432}
6433
Jamie Madill12e957f2017-08-26 21:42:26 -04006434void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
6435{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006436 const Program *programObject = getProgramResolveLink(program);
Jamie Madill54164b02017-08-28 15:17:37 -04006437 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04006438}
6439
Brandon Jones59770802018-04-02 13:18:42 -07006440void Context::getUniformuivRobust(GLuint program,
6441 GLint location,
6442 GLsizei bufSize,
6443 GLsizei *length,
6444 GLuint *params)
6445{
6446 getUniformuiv(program, location, params);
6447}
6448
Jamie Madill12e957f2017-08-26 21:42:26 -04006449GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
6450{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006451 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006452 return programObject->getFragDataLocation(name);
6453}
6454
6455void Context::getUniformIndices(GLuint program,
6456 GLsizei uniformCount,
6457 const GLchar *const *uniformNames,
6458 GLuint *uniformIndices)
6459{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006460 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006461 if (!programObject->isLinked())
6462 {
6463 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6464 {
6465 uniformIndices[uniformId] = GL_INVALID_INDEX;
6466 }
6467 }
6468 else
6469 {
6470 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6471 {
6472 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
6473 }
6474 }
6475}
6476
6477void Context::getActiveUniformsiv(GLuint program,
6478 GLsizei uniformCount,
6479 const GLuint *uniformIndices,
6480 GLenum pname,
6481 GLint *params)
6482{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006483 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006484 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6485 {
6486 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08006487 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04006488 }
6489}
6490
6491GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
6492{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006493 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006494 return programObject->getUniformBlockIndex(uniformBlockName);
6495}
6496
6497void Context::getActiveUniformBlockiv(GLuint program,
6498 GLuint uniformBlockIndex,
6499 GLenum pname,
6500 GLint *params)
6501{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006502 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006503 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
6504}
6505
Brandon Jones59770802018-04-02 13:18:42 -07006506void Context::getActiveUniformBlockivRobust(GLuint program,
6507 GLuint uniformBlockIndex,
6508 GLenum pname,
6509 GLsizei bufSize,
6510 GLsizei *length,
6511 GLint *params)
6512{
6513 getActiveUniformBlockiv(program, uniformBlockIndex, pname, params);
6514}
6515
Jamie Madill12e957f2017-08-26 21:42:26 -04006516void Context::getActiveUniformBlockName(GLuint program,
6517 GLuint uniformBlockIndex,
6518 GLsizei bufSize,
6519 GLsizei *length,
6520 GLchar *uniformBlockName)
6521{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006522 const Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006523 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
6524}
6525
6526void Context::uniformBlockBinding(GLuint program,
6527 GLuint uniformBlockIndex,
6528 GLuint uniformBlockBinding)
6529{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006530 Program *programObject = getProgramResolveLink(program);
Jamie Madill12e957f2017-08-26 21:42:26 -04006531 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
Jamie Madill70aeda42018-08-20 12:17:40 -04006532
Jamie Madill956ab4d2018-10-10 16:13:03 -04006533 // Note: If the Program is shared between Contexts we would be better using Observer/Subject.
Jamie Madill70aeda42018-08-20 12:17:40 -04006534 if (programObject->isInUse())
6535 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006536 mState.setObjectDirty(GL_PROGRAM);
Jamie Madilld84b6732018-09-06 15:54:35 -04006537 mStateCache.onUniformBufferStateChange(this);
Jamie Madill70aeda42018-08-20 12:17:40 -04006538 }
Jamie Madill12e957f2017-08-26 21:42:26 -04006539}
6540
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006541GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
6542{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006543 GLuint handle = mState.mSyncManager->createSync(mImplementation.get());
Jamie Madill70b5bb02017-08-28 13:32:37 -04006544 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006545
Jamie Madill70b5bb02017-08-28 13:32:37 -04006546 Sync *syncObject = getSync(syncHandle);
Jamie Madill7c985f52018-11-29 18:16:17 -05006547 if (syncObject->set(this, condition, flags) == angle::Result::Stop)
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006548 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04006549 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006550 return nullptr;
6551 }
6552
Jamie Madill70b5bb02017-08-28 13:32:37 -04006553 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006554}
6555
6556GLboolean Context::isSync(GLsync sync)
6557{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006558 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006559}
6560
6561GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6562{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006563 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006564
6565 GLenum result = GL_WAIT_FAILED;
Jamie Madill7c985f52018-11-29 18:16:17 -05006566 if (syncObject->clientWait(this, flags, timeout, &result) == angle::Result::Stop)
Jamie Madill4f6592f2018-11-27 16:37:45 -05006567 {
6568 return GL_WAIT_FAILED;
6569 }
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006570 return result;
6571}
6572
6573void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6574{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006575 Sync *syncObject = getSync(sync);
Jamie Madill4f6592f2018-11-27 16:37:45 -05006576 ANGLE_CONTEXT_TRY(syncObject->serverWait(this, flags, timeout));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006577}
6578
6579void Context::getInteger64v(GLenum pname, GLint64 *params)
6580{
6581 GLenum nativeType = GL_NONE;
6582 unsigned int numParams = 0;
6583 getQueryParameterInfo(pname, &nativeType, &numParams);
6584
6585 if (nativeType == GL_INT_64_ANGLEX)
6586 {
6587 getInteger64vImpl(pname, params);
6588 }
6589 else
6590 {
6591 CastStateValues(this, nativeType, pname, numParams, params);
6592 }
6593}
6594
Brandon Jones59770802018-04-02 13:18:42 -07006595void Context::getInteger64vRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint64 *data)
6596{
6597 getInteger64v(pname, data);
6598}
6599
Corentin Wallez336129f2017-10-17 15:55:40 -04006600void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04006601{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006602 Buffer *buffer = mState.getTargetBuffer(target);
Jamie Madill3ef140a2017-08-26 23:11:21 -04006603 QueryBufferParameteri64v(buffer, pname, params);
6604}
6605
Brandon Jones59770802018-04-02 13:18:42 -07006606void Context::getBufferParameteri64vRobust(BufferBinding target,
6607 GLenum pname,
6608 GLsizei bufSize,
6609 GLsizei *length,
6610 GLint64 *params)
6611{
6612 getBufferParameteri64v(target, pname, params);
6613}
6614
Jamie Madill3ef140a2017-08-26 23:11:21 -04006615void Context::genSamplers(GLsizei count, GLuint *samplers)
6616{
6617 for (int i = 0; i < count; i++)
6618 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006619 samplers[i] = mState.mSamplerManager->createSampler();
Jamie Madill3ef140a2017-08-26 23:11:21 -04006620 }
6621}
6622
6623void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
6624{
6625 for (int i = 0; i < count; i++)
6626 {
6627 GLuint sampler = samplers[i];
6628
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006629 if (mState.mSamplerManager->getSampler(sampler))
Jamie Madill3ef140a2017-08-26 23:11:21 -04006630 {
6631 detachSampler(sampler);
6632 }
6633
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006634 mState.mSamplerManager->deleteObject(this, sampler);
Jamie Madill3ef140a2017-08-26 23:11:21 -04006635 }
6636}
6637
6638void Context::getInternalformativ(GLenum target,
6639 GLenum internalformat,
6640 GLenum pname,
6641 GLsizei bufSize,
6642 GLint *params)
6643{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006644 const TextureCaps &formatCaps = mState.mTextureCaps.get(internalformat);
Jamie Madill3ef140a2017-08-26 23:11:21 -04006645 QueryInternalFormativ(formatCaps, pname, bufSize, params);
6646}
6647
Brandon Jones59770802018-04-02 13:18:42 -07006648void Context::getInternalformativRobust(GLenum target,
6649 GLenum internalformat,
6650 GLenum pname,
6651 GLsizei bufSize,
6652 GLsizei *length,
6653 GLint *params)
6654{
6655 getInternalformativ(target, internalformat, pname, bufSize, params);
6656}
6657
Jiajia Qin5451d532017-11-16 17:16:34 +08006658void Context::programUniform1i(GLuint program, GLint location, GLint v0)
6659{
6660 programUniform1iv(program, location, 1, &v0);
6661}
6662
6663void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
6664{
6665 GLint xy[2] = {v0, v1};
6666 programUniform2iv(program, location, 1, xy);
6667}
6668
6669void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
6670{
6671 GLint xyz[3] = {v0, v1, v2};
6672 programUniform3iv(program, location, 1, xyz);
6673}
6674
6675void Context::programUniform4i(GLuint program,
6676 GLint location,
6677 GLint v0,
6678 GLint v1,
6679 GLint v2,
6680 GLint v3)
6681{
6682 GLint xyzw[4] = {v0, v1, v2, v3};
6683 programUniform4iv(program, location, 1, xyzw);
6684}
6685
6686void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
6687{
6688 programUniform1uiv(program, location, 1, &v0);
6689}
6690
6691void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
6692{
6693 GLuint xy[2] = {v0, v1};
6694 programUniform2uiv(program, location, 1, xy);
6695}
6696
6697void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
6698{
6699 GLuint xyz[3] = {v0, v1, v2};
6700 programUniform3uiv(program, location, 1, xyz);
6701}
6702
6703void Context::programUniform4ui(GLuint program,
6704 GLint location,
6705 GLuint v0,
6706 GLuint v1,
6707 GLuint v2,
6708 GLuint v3)
6709{
6710 GLuint xyzw[4] = {v0, v1, v2, v3};
6711 programUniform4uiv(program, location, 1, xyzw);
6712}
6713
6714void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
6715{
6716 programUniform1fv(program, location, 1, &v0);
6717}
6718
6719void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
6720{
6721 GLfloat xy[2] = {v0, v1};
6722 programUniform2fv(program, location, 1, xy);
6723}
6724
6725void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
6726{
6727 GLfloat xyz[3] = {v0, v1, v2};
6728 programUniform3fv(program, location, 1, xyz);
6729}
6730
6731void Context::programUniform4f(GLuint program,
6732 GLint location,
6733 GLfloat v0,
6734 GLfloat v1,
6735 GLfloat v2,
6736 GLfloat v3)
6737{
6738 GLfloat xyzw[4] = {v0, v1, v2, v3};
6739 programUniform4fv(program, location, 1, xyzw);
6740}
6741
Jamie Madill81c2e252017-09-09 23:32:46 -04006742void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6743{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006744 Program *programObject = getProgramResolveLink(program);
Jamie Madill81c2e252017-09-09 23:32:46 -04006745 ASSERT(programObject);
Jamie Madill7e4eff12018-08-08 15:49:26 -04006746 setUniform1iImpl(programObject, location, count, value);
Jamie Madill81c2e252017-09-09 23:32:46 -04006747}
6748
Jiajia Qin5451d532017-11-16 17:16:34 +08006749void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6750{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006751 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006752 ASSERT(programObject);
6753 programObject->setUniform2iv(location, count, value);
6754}
6755
6756void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6757{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006758 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006759 ASSERT(programObject);
6760 programObject->setUniform3iv(location, count, value);
6761}
6762
6763void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6764{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006765 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006766 ASSERT(programObject);
6767 programObject->setUniform4iv(location, count, value);
6768}
6769
6770void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6771{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006772 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006773 ASSERT(programObject);
6774 programObject->setUniform1uiv(location, count, value);
6775}
6776
6777void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6778{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006779 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006780 ASSERT(programObject);
6781 programObject->setUniform2uiv(location, count, value);
6782}
6783
6784void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6785{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006786 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006787 ASSERT(programObject);
6788 programObject->setUniform3uiv(location, count, value);
6789}
6790
6791void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6792{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006793 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006794 ASSERT(programObject);
6795 programObject->setUniform4uiv(location, count, value);
6796}
6797
6798void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6799{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006800 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006801 ASSERT(programObject);
6802 programObject->setUniform1fv(location, count, value);
6803}
6804
6805void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6806{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006807 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006808 ASSERT(programObject);
6809 programObject->setUniform2fv(location, count, value);
6810}
6811
6812void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6813{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006814 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006815 ASSERT(programObject);
6816 programObject->setUniform3fv(location, count, value);
6817}
6818
6819void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6820{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006821 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006822 ASSERT(programObject);
6823 programObject->setUniform4fv(location, count, value);
6824}
6825
6826void Context::programUniformMatrix2fv(GLuint program,
6827 GLint location,
6828 GLsizei count,
6829 GLboolean transpose,
6830 const GLfloat *value)
6831{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006832 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006833 ASSERT(programObject);
6834 programObject->setUniformMatrix2fv(location, count, transpose, value);
6835}
6836
6837void Context::programUniformMatrix3fv(GLuint program,
6838 GLint location,
6839 GLsizei count,
6840 GLboolean transpose,
6841 const GLfloat *value)
6842{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006843 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006844 ASSERT(programObject);
6845 programObject->setUniformMatrix3fv(location, count, transpose, value);
6846}
6847
6848void Context::programUniformMatrix4fv(GLuint program,
6849 GLint location,
6850 GLsizei count,
6851 GLboolean transpose,
6852 const GLfloat *value)
6853{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006854 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006855 ASSERT(programObject);
6856 programObject->setUniformMatrix4fv(location, count, transpose, value);
6857}
6858
6859void Context::programUniformMatrix2x3fv(GLuint program,
6860 GLint location,
6861 GLsizei count,
6862 GLboolean transpose,
6863 const GLfloat *value)
6864{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006865 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006866 ASSERT(programObject);
6867 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
6868}
6869
6870void Context::programUniformMatrix3x2fv(GLuint program,
6871 GLint location,
6872 GLsizei count,
6873 GLboolean transpose,
6874 const GLfloat *value)
6875{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006876 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006877 ASSERT(programObject);
6878 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
6879}
6880
6881void Context::programUniformMatrix2x4fv(GLuint program,
6882 GLint location,
6883 GLsizei count,
6884 GLboolean transpose,
6885 const GLfloat *value)
6886{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006887 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006888 ASSERT(programObject);
6889 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
6890}
6891
6892void Context::programUniformMatrix4x2fv(GLuint program,
6893 GLint location,
6894 GLsizei count,
6895 GLboolean transpose,
6896 const GLfloat *value)
6897{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006898 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006899 ASSERT(programObject);
6900 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
6901}
6902
6903void Context::programUniformMatrix3x4fv(GLuint program,
6904 GLint location,
6905 GLsizei count,
6906 GLboolean transpose,
6907 const GLfloat *value)
6908{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006909 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006910 ASSERT(programObject);
6911 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
6912}
6913
6914void Context::programUniformMatrix4x3fv(GLuint program,
6915 GLint location,
6916 GLsizei count,
6917 GLboolean transpose,
6918 const GLfloat *value)
6919{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04006920 Program *programObject = getProgramResolveLink(program);
Jiajia Qin5451d532017-11-16 17:16:34 +08006921 ASSERT(programObject);
6922 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
6923}
6924
James Darpiniane8a93c62018-01-04 18:02:24 -08006925bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
6926{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05006927 return mState.isCurrentTransformFeedback(tf);
James Darpiniane8a93c62018-01-04 18:02:24 -08006928}
James Darpiniane8a93c62018-01-04 18:02:24 -08006929
Yunchao Hea336b902017-08-02 16:05:21 +08006930void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
6931{
6932 for (int i = 0; i < count; i++)
6933 {
6934 pipelines[i] = createProgramPipeline();
6935 }
6936}
6937
6938void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
6939{
6940 for (int i = 0; i < count; i++)
6941 {
6942 if (pipelines[i] != 0)
6943 {
6944 deleteProgramPipeline(pipelines[i]);
6945 }
6946 }
6947}
6948
6949GLboolean Context::isProgramPipeline(GLuint pipeline)
6950{
6951 if (pipeline == 0)
6952 {
6953 return GL_FALSE;
6954 }
6955
6956 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
6957}
6958
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006959void Context::finishFenceNV(GLuint fence)
6960{
6961 FenceNV *fenceObject = getFenceNV(fence);
6962
6963 ASSERT(fenceObject && fenceObject->isSet());
Jamie Madill4f6592f2018-11-27 16:37:45 -05006964 ANGLE_CONTEXT_TRY(fenceObject->finish(this));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006965}
6966
6967void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
6968{
6969 FenceNV *fenceObject = getFenceNV(fence);
6970
6971 ASSERT(fenceObject && fenceObject->isSet());
6972
6973 switch (pname)
6974 {
6975 case GL_FENCE_STATUS_NV:
6976 {
6977 // GL_NV_fence spec:
6978 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
6979 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
6980 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
6981 GLboolean status = GL_TRUE;
6982 if (fenceObject->getStatus() != GL_TRUE)
6983 {
Jamie Madilla0691b72018-07-25 10:41:22 -04006984 ANGLE_CONTEXT_TRY(fenceObject->test(this, &status));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006985 }
6986 *params = status;
6987 break;
6988 }
6989
6990 case GL_FENCE_CONDITION_NV:
6991 {
6992 *params = static_cast<GLint>(fenceObject->getCondition());
6993 break;
6994 }
6995
6996 default:
6997 UNREACHABLE();
6998 }
6999}
7000
7001void Context::getTranslatedShaderSource(GLuint shader,
7002 GLsizei bufsize,
7003 GLsizei *length,
7004 GLchar *source)
7005{
7006 Shader *shaderObject = getShader(shader);
7007 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08007008 shaderObject->getTranslatedSourceWithDebugInfo(bufsize, length, source);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007009}
7010
7011void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
7012{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04007013 Program *programObject = getProgramResolveLink(program);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007014 ASSERT(programObject);
7015
7016 programObject->getUniformfv(this, location, params);
7017}
7018
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07007019void Context::getnUniformfvRobust(GLuint program,
7020 GLint location,
7021 GLsizei bufSize,
7022 GLsizei *length,
7023 GLfloat *params)
7024{
7025 UNIMPLEMENTED();
7026}
7027
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007028void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
7029{
Jamie Madill44a6fbf2018-10-02 13:38:56 -04007030 Program *programObject = getProgramResolveLink(program);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007031 ASSERT(programObject);
7032
7033 programObject->getUniformiv(this, location, params);
7034}
7035
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07007036void Context::getnUniformivRobust(GLuint program,
7037 GLint location,
7038 GLsizei bufSize,
7039 GLsizei *length,
7040 GLint *params)
7041{
7042 UNIMPLEMENTED();
7043}
7044
7045void Context::getnUniformuivRobust(GLuint program,
7046 GLint location,
7047 GLsizei bufSize,
7048 GLsizei *length,
7049 GLuint *params)
7050{
7051 UNIMPLEMENTED();
7052}
7053
Jamie Madill2b7bbc22017-12-21 17:30:38 -05007054GLboolean Context::isFenceNV(GLuint fence)
7055{
7056 FenceNV *fenceObject = getFenceNV(fence);
7057
7058 if (fenceObject == nullptr)
7059 {
7060 return GL_FALSE;
7061 }
7062
7063 // GL_NV_fence spec:
7064 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
7065 // existing fence.
7066 return fenceObject->isSet();
7067}
7068
7069void Context::readnPixels(GLint x,
7070 GLint y,
7071 GLsizei width,
7072 GLsizei height,
7073 GLenum format,
7074 GLenum type,
7075 GLsizei bufSize,
7076 void *data)
7077{
7078 return readPixels(x, y, width, height, format, type, data);
7079}
7080
Jamie Madill007530e2017-12-28 14:27:04 -05007081void Context::setFenceNV(GLuint fence, GLenum condition)
7082{
7083 ASSERT(condition == GL_ALL_COMPLETED_NV);
7084
7085 FenceNV *fenceObject = getFenceNV(fence);
7086 ASSERT(fenceObject != nullptr);
Jamie Madill4f6592f2018-11-27 16:37:45 -05007087 ANGLE_CONTEXT_TRY(fenceObject->set(this, condition));
Jamie Madill007530e2017-12-28 14:27:04 -05007088}
7089
7090GLboolean Context::testFenceNV(GLuint fence)
7091{
7092 FenceNV *fenceObject = getFenceNV(fence);
7093
7094 ASSERT(fenceObject != nullptr);
7095 ASSERT(fenceObject->isSet() == GL_TRUE);
7096
7097 GLboolean result = GL_TRUE;
Jamie Madill7c985f52018-11-29 18:16:17 -05007098 if (fenceObject->test(this, &result) == angle::Result::Stop)
Jamie Madill007530e2017-12-28 14:27:04 -05007099 {
Jamie Madill007530e2017-12-28 14:27:04 -05007100 return GL_TRUE;
7101 }
7102
7103 return result;
7104}
7105
Corentin Wallezf0e89be2017-11-08 14:00:32 -08007106void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05007107{
7108 Texture *texture = getTargetTexture(target);
Rafael Cintron05a449a2018-06-20 18:08:04 -07007109 egl::Image *imageObject = static_cast<egl::Image *>(image);
Jamie Madill4f6592f2018-11-27 16:37:45 -05007110 ANGLE_CONTEXT_TRY(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05007111}
7112
Jamie Madillfa920eb2018-01-04 11:45:50 -05007113void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05007114{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05007115 Renderbuffer *renderbuffer = mState.getCurrentRenderbuffer();
Rafael Cintron05a449a2018-06-20 18:08:04 -07007116 egl::Image *imageObject = static_cast<egl::Image *>(image);
Jamie Madill4f6592f2018-11-27 16:37:45 -05007117 ANGLE_CONTEXT_TRY(renderbuffer->setStorageEGLImageTarget(this, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05007118}
7119
Jamie Madillfa920eb2018-01-04 11:45:50 -05007120void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
7121{
7122 UNIMPLEMENTED();
7123}
7124
Jamie Madill5b772312018-03-08 20:28:32 -05007125bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
7126{
7127 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
7128 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
7129 // to the fact that it is stored internally as a float, and so would require conversion
7130 // if returned from Context::getIntegerv. Since this conversion is already implemented
7131 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
7132 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
7133 // application.
7134 switch (pname)
7135 {
7136 case GL_COMPRESSED_TEXTURE_FORMATS:
7137 {
7138 *type = GL_INT;
7139 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
7140 return true;
7141 }
7142 case GL_SHADER_BINARY_FORMATS:
7143 {
7144 *type = GL_INT;
7145 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
7146 return true;
7147 }
7148
7149 case GL_MAX_VERTEX_ATTRIBS:
7150 case GL_MAX_VERTEX_UNIFORM_VECTORS:
7151 case GL_MAX_VARYING_VECTORS:
7152 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
7153 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
7154 case GL_MAX_TEXTURE_IMAGE_UNITS:
7155 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
7156 case GL_MAX_RENDERBUFFER_SIZE:
7157 case GL_NUM_SHADER_BINARY_FORMATS:
7158 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
7159 case GL_ARRAY_BUFFER_BINDING:
Jamie Madillef9fcd92018-11-28 14:03:59 -05007160 case GL_FRAMEBUFFER_BINDING: // GL_FRAMEBUFFER_BINDING now equivalent to
7161 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
Jamie Madill5b772312018-03-08 20:28:32 -05007162 case GL_RENDERBUFFER_BINDING:
7163 case GL_CURRENT_PROGRAM:
7164 case GL_PACK_ALIGNMENT:
7165 case GL_UNPACK_ALIGNMENT:
7166 case GL_GENERATE_MIPMAP_HINT:
7167 case GL_RED_BITS:
7168 case GL_GREEN_BITS:
7169 case GL_BLUE_BITS:
7170 case GL_ALPHA_BITS:
7171 case GL_DEPTH_BITS:
7172 case GL_STENCIL_BITS:
7173 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
7174 case GL_CULL_FACE_MODE:
7175 case GL_FRONT_FACE:
7176 case GL_ACTIVE_TEXTURE:
7177 case GL_STENCIL_FUNC:
7178 case GL_STENCIL_VALUE_MASK:
7179 case GL_STENCIL_REF:
7180 case GL_STENCIL_FAIL:
7181 case GL_STENCIL_PASS_DEPTH_FAIL:
7182 case GL_STENCIL_PASS_DEPTH_PASS:
7183 case GL_STENCIL_BACK_FUNC:
7184 case GL_STENCIL_BACK_VALUE_MASK:
7185 case GL_STENCIL_BACK_REF:
7186 case GL_STENCIL_BACK_FAIL:
7187 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
7188 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
7189 case GL_DEPTH_FUNC:
7190 case GL_BLEND_SRC_RGB:
7191 case GL_BLEND_SRC_ALPHA:
7192 case GL_BLEND_DST_RGB:
7193 case GL_BLEND_DST_ALPHA:
7194 case GL_BLEND_EQUATION_RGB:
7195 case GL_BLEND_EQUATION_ALPHA:
7196 case GL_STENCIL_WRITEMASK:
7197 case GL_STENCIL_BACK_WRITEMASK:
7198 case GL_STENCIL_CLEAR_VALUE:
7199 case GL_SUBPIXEL_BITS:
7200 case GL_MAX_TEXTURE_SIZE:
7201 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
7202 case GL_SAMPLE_BUFFERS:
7203 case GL_SAMPLES:
7204 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
7205 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
7206 case GL_TEXTURE_BINDING_2D:
7207 case GL_TEXTURE_BINDING_CUBE_MAP:
7208 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
7209 {
7210 *type = GL_INT;
7211 *numParams = 1;
7212 return true;
7213 }
7214 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
7215 {
7216 if (!getExtensions().packReverseRowOrder)
7217 {
7218 return false;
7219 }
7220 *type = GL_INT;
7221 *numParams = 1;
7222 return true;
7223 }
7224 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
7225 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
7226 {
7227 if (!getExtensions().textureRectangle)
7228 {
7229 return false;
7230 }
7231 *type = GL_INT;
7232 *numParams = 1;
7233 return true;
7234 }
7235 case GL_MAX_DRAW_BUFFERS_EXT:
7236 case GL_MAX_COLOR_ATTACHMENTS_EXT:
7237 {
7238 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
7239 {
7240 return false;
7241 }
7242 *type = GL_INT;
7243 *numParams = 1;
7244 return true;
7245 }
7246 case GL_MAX_VIEWPORT_DIMS:
7247 {
7248 *type = GL_INT;
7249 *numParams = 2;
7250 return true;
7251 }
7252 case GL_VIEWPORT:
7253 case GL_SCISSOR_BOX:
7254 {
7255 *type = GL_INT;
7256 *numParams = 4;
7257 return true;
7258 }
7259 case GL_SHADER_COMPILER:
7260 case GL_SAMPLE_COVERAGE_INVERT:
7261 case GL_DEPTH_WRITEMASK:
7262 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
7263 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
7264 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
7265 // bool-natural
7266 case GL_SAMPLE_COVERAGE:
7267 case GL_SCISSOR_TEST:
7268 case GL_STENCIL_TEST:
7269 case GL_DEPTH_TEST:
7270 case GL_BLEND:
7271 case GL_DITHER:
7272 case GL_CONTEXT_ROBUST_ACCESS_EXT:
7273 {
7274 *type = GL_BOOL;
7275 *numParams = 1;
7276 return true;
7277 }
7278 case GL_COLOR_WRITEMASK:
7279 {
7280 *type = GL_BOOL;
7281 *numParams = 4;
7282 return true;
7283 }
7284 case GL_POLYGON_OFFSET_FACTOR:
7285 case GL_POLYGON_OFFSET_UNITS:
7286 case GL_SAMPLE_COVERAGE_VALUE:
7287 case GL_DEPTH_CLEAR_VALUE:
7288 case GL_LINE_WIDTH:
7289 {
7290 *type = GL_FLOAT;
7291 *numParams = 1;
7292 return true;
7293 }
7294 case GL_ALIASED_LINE_WIDTH_RANGE:
7295 case GL_ALIASED_POINT_SIZE_RANGE:
7296 case GL_DEPTH_RANGE:
7297 {
7298 *type = GL_FLOAT;
7299 *numParams = 2;
7300 return true;
7301 }
7302 case GL_COLOR_CLEAR_VALUE:
7303 case GL_BLEND_COLOR:
7304 {
7305 *type = GL_FLOAT;
7306 *numParams = 4;
7307 return true;
7308 }
7309 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
7310 if (!getExtensions().textureFilterAnisotropic)
7311 {
7312 return false;
7313 }
7314 *type = GL_FLOAT;
7315 *numParams = 1;
7316 return true;
7317 case GL_TIMESTAMP_EXT:
7318 if (!getExtensions().disjointTimerQuery)
7319 {
7320 return false;
7321 }
7322 *type = GL_INT_64_ANGLEX;
7323 *numParams = 1;
7324 return true;
7325 case GL_GPU_DISJOINT_EXT:
7326 if (!getExtensions().disjointTimerQuery)
7327 {
7328 return false;
7329 }
7330 *type = GL_INT;
7331 *numParams = 1;
7332 return true;
7333 case GL_COVERAGE_MODULATION_CHROMIUM:
7334 if (!getExtensions().framebufferMixedSamples)
7335 {
7336 return false;
7337 }
7338 *type = GL_INT;
7339 *numParams = 1;
7340 return true;
7341 case GL_TEXTURE_BINDING_EXTERNAL_OES:
7342 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
7343 {
7344 return false;
7345 }
7346 *type = GL_INT;
7347 *numParams = 1;
7348 return true;
7349 }
7350
7351 if (getExtensions().debug)
7352 {
7353 switch (pname)
7354 {
7355 case GL_DEBUG_LOGGED_MESSAGES:
7356 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
7357 case GL_DEBUG_GROUP_STACK_DEPTH:
7358 case GL_MAX_DEBUG_MESSAGE_LENGTH:
7359 case GL_MAX_DEBUG_LOGGED_MESSAGES:
7360 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
7361 case GL_MAX_LABEL_LENGTH:
7362 *type = GL_INT;
7363 *numParams = 1;
7364 return true;
7365
7366 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
7367 case GL_DEBUG_OUTPUT:
7368 *type = GL_BOOL;
7369 *numParams = 1;
7370 return true;
7371 }
7372 }
7373
7374 if (getExtensions().multisampleCompatibility)
7375 {
7376 switch (pname)
7377 {
7378 case GL_MULTISAMPLE_EXT:
7379 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
7380 *type = GL_BOOL;
7381 *numParams = 1;
7382 return true;
7383 }
7384 }
7385
7386 if (getExtensions().pathRendering)
7387 {
7388 switch (pname)
7389 {
7390 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
7391 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
7392 *type = GL_FLOAT;
7393 *numParams = 16;
7394 return true;
7395 }
7396 }
7397
7398 if (getExtensions().bindGeneratesResource)
7399 {
7400 switch (pname)
7401 {
7402 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
7403 *type = GL_BOOL;
7404 *numParams = 1;
7405 return true;
7406 }
7407 }
7408
7409 if (getExtensions().clientArrays)
7410 {
7411 switch (pname)
7412 {
7413 case GL_CLIENT_ARRAYS_ANGLE:
7414 *type = GL_BOOL;
7415 *numParams = 1;
7416 return true;
7417 }
7418 }
7419
7420 if (getExtensions().sRGBWriteControl)
7421 {
7422 switch (pname)
7423 {
7424 case GL_FRAMEBUFFER_SRGB_EXT:
7425 *type = GL_BOOL;
7426 *numParams = 1;
7427 return true;
7428 }
7429 }
7430
7431 if (getExtensions().robustResourceInitialization &&
7432 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
7433 {
7434 *type = GL_BOOL;
7435 *numParams = 1;
7436 return true;
7437 }
7438
7439 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
7440 {
7441 *type = GL_BOOL;
7442 *numParams = 1;
7443 return true;
7444 }
7445
jchen1082af6202018-06-22 10:59:52 +08007446 if (getExtensions().parallelShaderCompile && pname == GL_MAX_SHADER_COMPILER_THREADS_KHR)
7447 {
7448 *type = GL_INT;
7449 *numParams = 1;
7450 return true;
7451 }
7452
Olli Etuahoab5fb5e2018-09-18 17:23:28 +03007453 if (getExtensions().blendFuncExtended && pname == GL_MAX_DUAL_SOURCE_DRAW_BUFFERS_EXT)
7454 {
7455 *type = GL_INT;
7456 *numParams = 1;
7457 return true;
7458 }
7459
Jamie Madill5b772312018-03-08 20:28:32 -05007460 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
7461 switch (pname)
7462 {
Jamie Madillef9fcd92018-11-28 14:03:59 -05007463 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE equivalent to FRAMEBUFFER_BINDING
Jamie Madill5b772312018-03-08 20:28:32 -05007464 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
7465 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
7466 {
7467 return false;
7468 }
7469 *type = GL_INT;
7470 *numParams = 1;
7471 return true;
7472
7473 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
7474 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7475 {
7476 return false;
7477 }
7478 *type = GL_INT;
7479 *numParams = 1;
7480 return true;
7481
7482 case GL_PROGRAM_BINARY_FORMATS_OES:
7483 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7484 {
7485 return false;
7486 }
7487 *type = GL_INT;
7488 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
7489 return true;
7490
7491 case GL_PACK_ROW_LENGTH:
7492 case GL_PACK_SKIP_ROWS:
7493 case GL_PACK_SKIP_PIXELS:
7494 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
7495 {
7496 return false;
7497 }
7498 *type = GL_INT;
7499 *numParams = 1;
7500 return true;
7501 case GL_UNPACK_ROW_LENGTH:
7502 case GL_UNPACK_SKIP_ROWS:
7503 case GL_UNPACK_SKIP_PIXELS:
7504 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
7505 {
7506 return false;
7507 }
7508 *type = GL_INT;
7509 *numParams = 1;
7510 return true;
7511 case GL_VERTEX_ARRAY_BINDING:
7512 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
7513 {
7514 return false;
7515 }
7516 *type = GL_INT;
7517 *numParams = 1;
7518 return true;
7519 case GL_PIXEL_PACK_BUFFER_BINDING:
7520 case GL_PIXEL_UNPACK_BUFFER_BINDING:
7521 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
7522 {
7523 return false;
7524 }
7525 *type = GL_INT;
7526 *numParams = 1;
7527 return true;
7528 case GL_MAX_SAMPLES:
7529 {
7530 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
7531 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
7532 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
7533 {
7534 return false;
7535 }
7536 *type = GL_INT;
7537 *numParams = 1;
7538 return true;
7539
7540 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
7541 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
7542 {
7543 return false;
7544 }
7545 *type = GL_INT;
7546 *numParams = 1;
7547 return true;
7548 }
7549 }
7550
7551 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
7552 {
7553 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
7554 {
7555 return false;
7556 }
7557 *type = GL_INT;
7558 *numParams = 1;
7559 return true;
7560 }
7561
7562 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
7563 {
7564 *type = GL_INT;
7565 *numParams = 1;
7566 return true;
7567 }
7568
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007569 if (getClientVersion() < Version(2, 0))
7570 {
7571 switch (pname)
7572 {
7573 case GL_ALPHA_TEST_FUNC:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007574 case GL_CLIENT_ACTIVE_TEXTURE:
7575 case GL_MATRIX_MODE:
7576 case GL_MAX_TEXTURE_UNITS:
7577 case GL_MAX_MODELVIEW_STACK_DEPTH:
7578 case GL_MAX_PROJECTION_STACK_DEPTH:
7579 case GL_MAX_TEXTURE_STACK_DEPTH:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007580 case GL_MAX_LIGHTS:
Lingfeng Yang060088a2018-05-30 20:40:57 -07007581 case GL_MAX_CLIP_PLANES:
Lingfeng Yangabb09f12018-04-16 10:43:53 -07007582 case GL_VERTEX_ARRAY_STRIDE:
7583 case GL_NORMAL_ARRAY_STRIDE:
7584 case GL_COLOR_ARRAY_STRIDE:
7585 case GL_TEXTURE_COORD_ARRAY_STRIDE:
7586 case GL_VERTEX_ARRAY_SIZE:
7587 case GL_COLOR_ARRAY_SIZE:
7588 case GL_TEXTURE_COORD_ARRAY_SIZE:
7589 case GL_VERTEX_ARRAY_TYPE:
7590 case GL_NORMAL_ARRAY_TYPE:
7591 case GL_COLOR_ARRAY_TYPE:
7592 case GL_TEXTURE_COORD_ARRAY_TYPE:
7593 case GL_VERTEX_ARRAY_BUFFER_BINDING:
7594 case GL_NORMAL_ARRAY_BUFFER_BINDING:
7595 case GL_COLOR_ARRAY_BUFFER_BINDING:
7596 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
7597 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
7598 case GL_POINT_SIZE_ARRAY_TYPE_OES:
7599 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
Lingfeng Yanga0cfa872018-05-30 21:12:17 -07007600 case GL_SHADE_MODEL:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07007601 case GL_MODELVIEW_STACK_DEPTH:
7602 case GL_PROJECTION_STACK_DEPTH:
7603 case GL_TEXTURE_STACK_DEPTH:
7604 case GL_LOGIC_OP_MODE:
7605 case GL_BLEND_SRC:
7606 case GL_BLEND_DST:
7607 case GL_PERSPECTIVE_CORRECTION_HINT:
7608 case GL_POINT_SMOOTH_HINT:
7609 case GL_LINE_SMOOTH_HINT:
7610 case GL_FOG_HINT:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007611 *type = GL_INT;
7612 *numParams = 1;
7613 return true;
7614 case GL_ALPHA_TEST_REF:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007615 case GL_FOG_DENSITY:
7616 case GL_FOG_START:
7617 case GL_FOG_END:
7618 case GL_FOG_MODE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007619 case GL_POINT_SIZE:
7620 case GL_POINT_SIZE_MIN:
7621 case GL_POINT_SIZE_MAX:
7622 case GL_POINT_FADE_THRESHOLD_SIZE:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007623 *type = GL_FLOAT;
7624 *numParams = 1;
7625 return true;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007626 case GL_SMOOTH_POINT_SIZE_RANGE:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07007627 case GL_SMOOTH_LINE_WIDTH_RANGE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007628 *type = GL_FLOAT;
7629 *numParams = 2;
7630 return true;
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007631 case GL_CURRENT_COLOR:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007632 case GL_CURRENT_TEXTURE_COORDS:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007633 case GL_LIGHT_MODEL_AMBIENT:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007634 case GL_FOG_COLOR:
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007635 *type = GL_FLOAT;
7636 *numParams = 4;
7637 return true;
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007638 case GL_CURRENT_NORMAL:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007639 case GL_POINT_DISTANCE_ATTENUATION:
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007640 *type = GL_FLOAT;
7641 *numParams = 3;
7642 return true;
Lingfeng Yang3a41af62018-04-09 07:28:56 -07007643 case GL_MODELVIEW_MATRIX:
7644 case GL_PROJECTION_MATRIX:
7645 case GL_TEXTURE_MATRIX:
7646 *type = GL_FLOAT;
7647 *numParams = 16;
7648 return true;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007649 case GL_LIGHT_MODEL_TWO_SIDE:
7650 *type = GL_BOOL;
7651 *numParams = 1;
7652 return true;
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007653 }
7654 }
7655
Jamie Madill5b772312018-03-08 20:28:32 -05007656 if (getClientVersion() < Version(3, 0))
7657 {
7658 return false;
7659 }
7660
7661 // Check for ES3.0+ parameter names
7662 switch (pname)
7663 {
7664 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
7665 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
7666 case GL_UNIFORM_BUFFER_BINDING:
7667 case GL_TRANSFORM_FEEDBACK_BINDING:
7668 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7669 case GL_COPY_READ_BUFFER_BINDING:
7670 case GL_COPY_WRITE_BUFFER_BINDING:
7671 case GL_SAMPLER_BINDING:
7672 case GL_READ_BUFFER:
7673 case GL_TEXTURE_BINDING_3D:
7674 case GL_TEXTURE_BINDING_2D_ARRAY:
7675 case GL_MAX_3D_TEXTURE_SIZE:
7676 case GL_MAX_ARRAY_TEXTURE_LAYERS:
7677 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
7678 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
7679 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
7680 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
7681 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
7682 case GL_MAX_VARYING_COMPONENTS:
7683 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
7684 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
7685 case GL_MIN_PROGRAM_TEXEL_OFFSET:
7686 case GL_MAX_PROGRAM_TEXEL_OFFSET:
7687 case GL_NUM_EXTENSIONS:
7688 case GL_MAJOR_VERSION:
7689 case GL_MINOR_VERSION:
7690 case GL_MAX_ELEMENTS_INDICES:
7691 case GL_MAX_ELEMENTS_VERTICES:
7692 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
7693 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
7694 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
7695 case GL_UNPACK_IMAGE_HEIGHT:
7696 case GL_UNPACK_SKIP_IMAGES:
7697 {
7698 *type = GL_INT;
7699 *numParams = 1;
7700 return true;
7701 }
7702
7703 case GL_MAX_ELEMENT_INDEX:
7704 case GL_MAX_UNIFORM_BLOCK_SIZE:
7705 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
7706 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
7707 case GL_MAX_SERVER_WAIT_TIMEOUT:
7708 {
7709 *type = GL_INT_64_ANGLEX;
7710 *numParams = 1;
7711 return true;
7712 }
7713
7714 case GL_TRANSFORM_FEEDBACK_ACTIVE:
7715 case GL_TRANSFORM_FEEDBACK_PAUSED:
7716 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
7717 case GL_RASTERIZER_DISCARD:
7718 {
7719 *type = GL_BOOL;
7720 *numParams = 1;
7721 return true;
7722 }
7723
7724 case GL_MAX_TEXTURE_LOD_BIAS:
7725 {
7726 *type = GL_FLOAT;
7727 *numParams = 1;
7728 return true;
7729 }
7730 }
7731
7732 if (getExtensions().requestExtension)
7733 {
7734 switch (pname)
7735 {
7736 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
7737 *type = GL_INT;
7738 *numParams = 1;
7739 return true;
7740 }
7741 }
7742
Yizhou Jiang7818a852018-09-06 15:02:04 +08007743 if (getExtensions().textureMultisample)
7744 {
7745 switch (pname)
7746 {
7747 case GL_MAX_COLOR_TEXTURE_SAMPLES_ANGLE:
7748 case GL_MAX_INTEGER_SAMPLES_ANGLE:
7749 case GL_MAX_DEPTH_TEXTURE_SAMPLES_ANGLE:
7750 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ANGLE:
Yizhou Jiang7310da32018-11-05 14:40:01 +08007751 case GL_MAX_SAMPLE_MASK_WORDS:
Yizhou Jiang7818a852018-09-06 15:02:04 +08007752 *type = GL_INT;
7753 *numParams = 1;
7754 return true;
7755 }
7756 }
7757
Jamie Madill5b772312018-03-08 20:28:32 -05007758 if (getClientVersion() < Version(3, 1))
7759 {
7760 return false;
7761 }
7762
7763 switch (pname)
7764 {
7765 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7766 case GL_DRAW_INDIRECT_BUFFER_BINDING:
7767 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
7768 case GL_MAX_FRAMEBUFFER_WIDTH:
7769 case GL_MAX_FRAMEBUFFER_HEIGHT:
7770 case GL_MAX_FRAMEBUFFER_SAMPLES:
7771 case GL_MAX_SAMPLE_MASK_WORDS:
7772 case GL_MAX_COLOR_TEXTURE_SAMPLES:
7773 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
7774 case GL_MAX_INTEGER_SAMPLES:
7775 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
7776 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
7777 case GL_MAX_VERTEX_ATTRIB_STRIDE:
7778 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
7779 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
7780 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
7781 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
7782 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
7783 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
7784 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
7785 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
7786 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
7787 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
7788 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
7789 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
7790 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
7791 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
7792 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
7793 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
7794 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
7795 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
7796 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
7797 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
7798 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
7799 case GL_MAX_UNIFORM_LOCATIONS:
7800 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
7801 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
7802 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
7803 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
7804 case GL_MAX_IMAGE_UNITS:
7805 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
7806 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
7807 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
7808 case GL_SHADER_STORAGE_BUFFER_BINDING:
7809 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
7810 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
Olli Etuahodff32a02018-08-28 14:35:50 +03007811 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY:
Jamie Madill5b772312018-03-08 20:28:32 -05007812 *type = GL_INT;
7813 *numParams = 1;
7814 return true;
7815 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7816 *type = GL_INT_64_ANGLEX;
7817 *numParams = 1;
7818 return true;
7819 case GL_SAMPLE_MASK:
7820 *type = GL_BOOL;
7821 *numParams = 1;
7822 return true;
7823 }
7824
7825 if (getExtensions().geometryShader)
7826 {
7827 switch (pname)
7828 {
7829 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7830 case GL_LAYER_PROVOKING_VERTEX_EXT:
7831 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7832 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7833 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7834 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7835 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7836 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7837 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7838 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7839 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7840 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7841 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7842 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7843 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7844 *type = GL_INT;
7845 *numParams = 1;
7846 return true;
7847 }
7848 }
7849
7850 return false;
7851}
7852
7853bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7854{
7855 if (getClientVersion() < Version(3, 0))
7856 {
7857 return false;
7858 }
7859
7860 switch (target)
7861 {
7862 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7863 case GL_UNIFORM_BUFFER_BINDING:
7864 {
7865 *type = GL_INT;
7866 *numParams = 1;
7867 return true;
7868 }
7869 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7870 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7871 case GL_UNIFORM_BUFFER_START:
7872 case GL_UNIFORM_BUFFER_SIZE:
7873 {
7874 *type = GL_INT_64_ANGLEX;
7875 *numParams = 1;
7876 return true;
7877 }
7878 }
7879
7880 if (getClientVersion() < Version(3, 1))
7881 {
7882 return false;
7883 }
7884
7885 switch (target)
7886 {
7887 case GL_IMAGE_BINDING_LAYERED:
7888 {
7889 *type = GL_BOOL;
7890 *numParams = 1;
7891 return true;
7892 }
7893 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7894 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7895 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7896 case GL_SHADER_STORAGE_BUFFER_BINDING:
7897 case GL_VERTEX_BINDING_BUFFER:
7898 case GL_VERTEX_BINDING_DIVISOR:
7899 case GL_VERTEX_BINDING_OFFSET:
7900 case GL_VERTEX_BINDING_STRIDE:
7901 case GL_SAMPLE_MASK_VALUE:
7902 case GL_IMAGE_BINDING_NAME:
7903 case GL_IMAGE_BINDING_LEVEL:
7904 case GL_IMAGE_BINDING_LAYER:
7905 case GL_IMAGE_BINDING_ACCESS:
7906 case GL_IMAGE_BINDING_FORMAT:
7907 {
7908 *type = GL_INT;
7909 *numParams = 1;
7910 return true;
7911 }
7912 case GL_ATOMIC_COUNTER_BUFFER_START:
7913 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
7914 case GL_SHADER_STORAGE_BUFFER_START:
7915 case GL_SHADER_STORAGE_BUFFER_SIZE:
7916 {
7917 *type = GL_INT_64_ANGLEX;
7918 *numParams = 1;
7919 return true;
7920 }
7921 }
7922
7923 return false;
7924}
7925
Jamie Madill44a6fbf2018-10-02 13:38:56 -04007926Program *Context::getProgramNoResolveLink(GLuint handle) const
Jamie Madill5b772312018-03-08 20:28:32 -05007927{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05007928 return mState.mShaderProgramManager->getProgram(handle);
Jamie Madill5b772312018-03-08 20:28:32 -05007929}
7930
7931Shader *Context::getShader(GLuint handle) const
7932{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05007933 return mState.mShaderProgramManager->getShader(handle);
Jamie Madill5b772312018-03-08 20:28:32 -05007934}
7935
Jamie Madill5b772312018-03-08 20:28:32 -05007936bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
7937{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05007938 return mState.mRenderbufferManager->isHandleGenerated(renderbuffer);
Jamie Madill5b772312018-03-08 20:28:32 -05007939}
7940
7941bool Context::isFramebufferGenerated(GLuint framebuffer) const
7942{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05007943 return mState.mFramebufferManager->isHandleGenerated(framebuffer);
Jamie Madill5b772312018-03-08 20:28:32 -05007944}
7945
7946bool Context::isProgramPipelineGenerated(GLuint pipeline) const
7947{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05007948 return mState.mProgramPipelineManager->isHandleGenerated(pipeline);
Jamie Madill5b772312018-03-08 20:28:32 -05007949}
7950
7951bool Context::usingDisplayTextureShareGroup() const
7952{
7953 return mDisplayTextureShareGroup;
7954}
7955
7956GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
7957{
7958 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
7959 internalformat == GL_DEPTH_STENCIL
7960 ? GL_DEPTH24_STENCIL8
7961 : internalformat;
7962}
7963
jchen1082af6202018-06-22 10:59:52 +08007964void Context::maxShaderCompilerThreads(GLuint count)
7965{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05007966 GLuint oldCount = mState.getMaxShaderCompilerThreads();
7967 mState.setMaxShaderCompilerThreads(count);
jchen107ae70d82018-07-06 13:47:01 +08007968 // A count of zero specifies a request for no parallel compiling or linking.
7969 if ((oldCount == 0 || count == 0) && (oldCount != 0 || count != 0))
7970 {
7971 mThreadPool = angle::WorkerThreadPool::Create(count > 0);
7972 }
7973 mThreadPool->setMaxThreads(count);
jchen1082af6202018-06-22 10:59:52 +08007974}
7975
Jamie Madill2eb65032018-07-30 10:25:57 -04007976bool Context::isGLES1() const
7977{
7978 return mState.getClientVersion() < Version(2, 0);
7979}
7980
Jamie Madilla11819d2018-07-30 10:26:01 -04007981void Context::onSubjectStateChange(const Context *context,
7982 angle::SubjectIndex index,
7983 angle::SubjectMessage message)
7984{
Jamie Madilla11819d2018-07-30 10:26:01 -04007985 switch (index)
7986 {
7987 case kVertexArraySubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04007988 switch (message)
7989 {
7990 case angle::SubjectMessage::CONTENTS_CHANGED:
Jamie Madillc3dc5d42018-12-30 12:12:04 -05007991 mState.setObjectDirty(GL_VERTEX_ARRAY);
Jamie Madilld84b6732018-09-06 15:54:35 -04007992 mStateCache.onVertexArrayBufferContentsChange(this);
7993 break;
7994 case angle::SubjectMessage::RESOURCE_MAPPED:
7995 case angle::SubjectMessage::RESOURCE_UNMAPPED:
7996 case angle::SubjectMessage::BINDING_CHANGED:
7997 mStateCache.onVertexArrayBufferStateChange(this);
7998 break;
7999 default:
8000 break;
8001 }
Jamie Madilla11819d2018-07-30 10:26:01 -04008002 break;
8003
8004 case kReadFramebufferSubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04008005 if (message == angle::SubjectMessage::STORAGE_CHANGED)
8006 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008007 mState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madilld84b6732018-09-06 15:54:35 -04008008 }
Jamie Madilla11819d2018-07-30 10:26:01 -04008009 break;
8010
8011 case kDrawFramebufferSubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04008012 if (message == angle::SubjectMessage::STORAGE_CHANGED)
8013 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008014 mState.setDrawFramebufferDirty();
Jamie Madilld84b6732018-09-06 15:54:35 -04008015 }
8016 mStateCache.onDrawFramebufferChange(this);
Jamie Madilla11819d2018-07-30 10:26:01 -04008017 break;
8018
8019 default:
Jamie Madill6d32cef2018-08-14 02:34:28 -04008020 if (index < kTextureMaxSubjectIndex)
8021 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008022 mState.onActiveTextureStateChange(this, index);
Jamie Madilld84b6732018-09-06 15:54:35 -04008023 mStateCache.onActiveTextureChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04008024 }
Jamie Madille25b8002018-09-20 13:39:49 -04008025 else if (index < kUniformBufferMaxSubjectIndex)
Jamie Madill6d32cef2018-08-14 02:34:28 -04008026 {
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008027 mState.onUniformBufferStateChange(index - kUniformBuffer0SubjectIndex);
Jamie Madilld84b6732018-09-06 15:54:35 -04008028 mStateCache.onUniformBufferStateChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04008029 }
Jamie Madille25b8002018-09-20 13:39:49 -04008030 else
8031 {
8032 ASSERT(index < kSamplerMaxSubjectIndex);
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008033 mState.setSamplerDirty(index - kSampler0SubjectIndex);
Jamie Madille25b8002018-09-20 13:39:49 -04008034 }
Jamie Madilla11819d2018-07-30 10:26:01 -04008035 break;
8036 }
8037}
8038
Jamie Madill6b873dd2018-07-12 23:56:30 -04008039// ErrorSet implementation.
Jamie Madillb980c562018-11-27 11:34:27 -05008040ErrorSet::ErrorSet(Context *context) : mContext(context) {}
Jamie Madill6b873dd2018-07-12 23:56:30 -04008041
8042ErrorSet::~ErrorSet() = default;
8043
Jamie Madillabfbc0f2018-10-09 12:48:52 -04008044void ErrorSet::handleError(GLenum errorCode,
8045 const char *message,
8046 const char *file,
8047 const char *function,
8048 unsigned int line)
8049{
Jamie Madill4f6592f2018-11-27 16:37:45 -05008050 if (errorCode == GL_OUT_OF_MEMORY && mContext->getWorkarounds().loseContextOnOutOfMemory)
8051 {
8052 mContext->markContextLost();
8053 }
Jamie Madillabfbc0f2018-10-09 12:48:52 -04008054
Jamie Madill4f6592f2018-11-27 16:37:45 -05008055 std::stringstream errorStream;
8056 errorStream << "Error: " << gl::FmtHex(errorCode) << ", in " << file << ", " << function << ":"
8057 << line << ". " << message;
8058
Geoff Lang7139b432018-12-14 16:57:28 -05008059 std::string formattedMessage = errorStream.str();
8060
8061 // Always log a warning, this function is only called on unexpected internal errors.
8062 WARN() << formattedMessage;
8063
Jamie Madill4f6592f2018-11-27 16:37:45 -05008064 // validationError does the necessary work to process the error.
Geoff Lang7139b432018-12-14 16:57:28 -05008065 validationError(errorCode, formattedMessage.c_str());
Jamie Madillabfbc0f2018-10-09 12:48:52 -04008066}
8067
Jamie Madilla139f012018-10-10 16:13:03 -04008068void ErrorSet::validationError(GLenum errorCode, const char *message)
8069{
Jamie Madill4f6592f2018-11-27 16:37:45 -05008070 ASSERT(errorCode != GL_NO_ERROR);
8071 mErrors.insert(errorCode);
8072
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008073 mContext->getState().getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR,
8074 errorCode, GL_DEBUG_SEVERITY_HIGH, message);
Jamie Madilla139f012018-10-10 16:13:03 -04008075}
8076
Jamie Madill6b873dd2018-07-12 23:56:30 -04008077bool ErrorSet::empty() const
8078{
8079 return mErrors.empty();
8080}
8081
8082GLenum ErrorSet::popError()
8083{
8084 ASSERT(!empty());
8085 GLenum error = *mErrors.begin();
8086 mErrors.erase(mErrors.begin());
8087 return error;
8088}
Jamie Madilldc358af2018-07-31 11:22:13 -04008089
8090// StateCache implementation.
Jamie Madillac66f982018-10-09 18:30:01 -04008091StateCache::StateCache()
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04008092 : mCachedHasAnyEnabledClientAttrib(false),
8093 mCachedNonInstancedVertexElementLimit(0),
Jamie Madilld84b6732018-09-06 15:54:35 -04008094 mCachedInstancedVertexElementLimit(0),
Jamie Madill1e853262018-12-21 09:07:38 -05008095 mCachedBasicDrawStatesError(kInvalidPointer),
Jamie Madillae6ba9f2018-12-21 23:00:04 -05008096 mCachedBasicDrawElementsError(kInvalidPointer),
8097 mCachedTransformFeedbackActiveUnpaused(false)
Jamie Madillb980c562018-11-27 11:34:27 -05008098{}
Jamie Madilldc358af2018-07-31 11:22:13 -04008099
8100StateCache::~StateCache() = default;
8101
Jamie Madilld51fbe32019-01-25 15:03:39 -05008102ANGLE_INLINE void StateCache::updateVertexElementLimits(Context *context)
8103{
8104 if (context->isBufferAccessValidationEnabled())
8105 {
8106 updateVertexElementLimitsImpl(context);
8107 }
8108}
8109
Jamie Madillac66f982018-10-09 18:30:01 -04008110void StateCache::initialize(Context *context)
8111{
8112 updateValidDrawModes(context);
8113 updateValidBindTextureTypes(context);
Jamie Madill8dc27f92018-11-29 11:45:44 -05008114 updateValidDrawElementsTypes(context);
Jamie Madill1e853262018-12-21 09:07:38 -05008115 updateBasicDrawStatesError();
8116 updateBasicDrawElementsError();
Jamie Madillc8c7d402019-01-16 13:27:15 -05008117 updateVertexAttribTypesValidation(context);
Jamie Madillac66f982018-10-09 18:30:01 -04008118}
8119
Jamie Madilldc358af2018-07-31 11:22:13 -04008120void StateCache::updateActiveAttribsMask(Context *context)
8121{
8122 bool isGLES1 = context->isGLES1();
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008123 const State &glState = context->getState();
Jamie Madilldc358af2018-07-31 11:22:13 -04008124
8125 if (!isGLES1 && !glState.getProgram())
8126 {
8127 mCachedActiveBufferedAttribsMask = AttributesMask();
8128 mCachedActiveClientAttribsMask = AttributesMask();
Jamie Madill86792f42018-08-30 16:18:34 -04008129 mCachedActiveDefaultAttribsMask = AttributesMask();
Jamie Madilldc358af2018-07-31 11:22:13 -04008130 return;
8131 }
8132
8133 AttributesMask activeAttribs = isGLES1 ? glState.gles1().getVertexArraysAttributeMask()
8134 : glState.getProgram()->getActiveAttribLocationsMask();
8135
8136 const VertexArray *vao = glState.getVertexArray();
8137 ASSERT(vao);
8138
8139 const AttributesMask &clientAttribs = vao->getClientAttribsMask();
8140 const AttributesMask &enabledAttribs = vao->getEnabledAttributesMask();
Jamie Madill0a17e482018-08-31 17:19:11 -04008141 const AttributesMask &activeEnabled = activeAttribs & enabledAttribs;
Jamie Madilldc358af2018-07-31 11:22:13 -04008142
Jamie Madill0a17e482018-08-31 17:19:11 -04008143 mCachedActiveClientAttribsMask = activeEnabled & clientAttribs;
8144 mCachedActiveBufferedAttribsMask = activeEnabled & ~clientAttribs;
Jamie Madill86792f42018-08-30 16:18:34 -04008145 mCachedActiveDefaultAttribsMask = activeAttribs & ~enabledAttribs;
Jamie Madilldc358af2018-07-31 11:22:13 -04008146 mCachedHasAnyEnabledClientAttrib = (clientAttribs & enabledAttribs).any();
8147}
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04008148
Jamie Madilld51fbe32019-01-25 15:03:39 -05008149void StateCache::updateVertexElementLimitsImpl(Context *context)
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04008150{
Jamie Madilld51fbe32019-01-25 15:03:39 -05008151 ASSERT(context->isBufferAccessValidationEnabled());
8152
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008153 const VertexArray *vao = context->getState().getVertexArray();
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04008154
8155 mCachedNonInstancedVertexElementLimit = std::numeric_limits<GLint64>::max();
8156 mCachedInstancedVertexElementLimit = std::numeric_limits<GLint64>::max();
8157
8158 // VAO can be null on Context startup. If we make this computation lazier we could ASSERT.
8159 // If there are no buffered attributes then we should not limit the draw call count.
8160 if (!vao || !mCachedActiveBufferedAttribsMask.any())
8161 {
8162 return;
8163 }
8164
8165 const auto &vertexAttribs = vao->getVertexAttributes();
8166 const auto &vertexBindings = vao->getVertexBindings();
8167
8168 for (size_t attributeIndex : mCachedActiveBufferedAttribsMask)
8169 {
8170 const VertexAttribute &attrib = vertexAttribs[attributeIndex];
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04008171
8172 const VertexBinding &binding = vertexBindings[attrib.bindingIndex];
8173 ASSERT(context->isGLES1() ||
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008174 context->getState().getProgram()->isAttribLocationActive(attributeIndex));
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04008175
8176 GLint64 limit = attrib.getCachedElementLimit();
8177 if (binding.getDivisor() > 0)
8178 {
8179 mCachedInstancedVertexElementLimit =
8180 std::min(mCachedInstancedVertexElementLimit, limit);
8181 }
8182 else
8183 {
8184 mCachedNonInstancedVertexElementLimit =
8185 std::min(mCachedNonInstancedVertexElementLimit, limit);
8186 }
8187 }
8188}
Jamie Madillc43cdad2018-08-08 15:49:25 -04008189
Jamie Madilld84b6732018-09-06 15:54:35 -04008190void StateCache::updateBasicDrawStatesError()
8191{
8192 mCachedBasicDrawStatesError = kInvalidPointer;
8193}
8194
Jamie Madill1e853262018-12-21 09:07:38 -05008195void StateCache::updateBasicDrawElementsError()
8196{
8197 mCachedBasicDrawElementsError = kInvalidPointer;
8198}
8199
Jamie Madilld84b6732018-09-06 15:54:35 -04008200intptr_t StateCache::getBasicDrawStatesErrorImpl(Context *context) const
8201{
8202 ASSERT(mCachedBasicDrawStatesError == kInvalidPointer);
8203 mCachedBasicDrawStatesError = reinterpret_cast<intptr_t>(ValidateDrawStates(context));
8204 return mCachedBasicDrawStatesError;
8205}
8206
Jamie Madill1e853262018-12-21 09:07:38 -05008207intptr_t StateCache::getBasicDrawElementsErrorImpl(Context *context) const
8208{
8209 ASSERT(mCachedBasicDrawElementsError == kInvalidPointer);
8210 mCachedBasicDrawElementsError = reinterpret_cast<intptr_t>(ValidateDrawElementsStates(context));
8211 return mCachedBasicDrawElementsError;
8212}
8213
Jamie Madillc43cdad2018-08-08 15:49:25 -04008214void StateCache::onVertexArrayBindingChange(Context *context)
8215{
8216 updateActiveAttribsMask(context);
8217 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04008218 updateBasicDrawStatesError();
Jamie Madillc43cdad2018-08-08 15:49:25 -04008219}
8220
8221void StateCache::onProgramExecutableChange(Context *context)
8222{
8223 updateActiveAttribsMask(context);
8224 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04008225 updateBasicDrawStatesError();
Jamie Madill526a6f62018-09-12 11:03:05 -04008226 updateValidDrawModes(context);
Jamie Madillc43cdad2018-08-08 15:49:25 -04008227}
8228
Jamie Madilld84b6732018-09-06 15:54:35 -04008229void StateCache::onVertexArrayFormatChange(Context *context)
Jamie Madillc43cdad2018-08-08 15:49:25 -04008230{
8231 updateVertexElementLimits(context);
8232}
8233
Jamie Madilld84b6732018-09-06 15:54:35 -04008234void StateCache::onVertexArrayBufferContentsChange(Context *context)
8235{
8236 updateVertexElementLimits(context);
8237 updateBasicDrawStatesError();
8238}
8239
Jamie Madillc43cdad2018-08-08 15:49:25 -04008240void StateCache::onVertexArrayStateChange(Context *context)
8241{
8242 updateActiveAttribsMask(context);
8243 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04008244 updateBasicDrawStatesError();
8245}
8246
8247void StateCache::onVertexArrayBufferStateChange(Context *context)
8248{
8249 updateBasicDrawStatesError();
Jamie Madill1e853262018-12-21 09:07:38 -05008250 updateBasicDrawElementsError();
Jamie Madillc43cdad2018-08-08 15:49:25 -04008251}
8252
8253void StateCache::onGLES1ClientStateChange(Context *context)
8254{
8255 updateActiveAttribsMask(context);
8256}
Jamie Madilld84b6732018-09-06 15:54:35 -04008257
8258void StateCache::onDrawFramebufferChange(Context *context)
8259{
8260 updateBasicDrawStatesError();
8261}
8262
8263void StateCache::onContextCapChange(Context *context)
8264{
8265 updateBasicDrawStatesError();
8266}
8267
8268void StateCache::onStencilStateChange(Context *context)
8269{
8270 updateBasicDrawStatesError();
8271}
8272
8273void StateCache::onDefaultVertexAttributeChange(Context *context)
8274{
8275 updateBasicDrawStatesError();
8276}
8277
8278void StateCache::onActiveTextureChange(Context *context)
8279{
8280 updateBasicDrawStatesError();
8281}
8282
8283void StateCache::onQueryChange(Context *context)
8284{
8285 updateBasicDrawStatesError();
8286}
8287
Jamie Madill3a256222018-12-08 09:56:39 -05008288void StateCache::onActiveTransformFeedbackChange(Context *context)
Jamie Madilld84b6732018-09-06 15:54:35 -04008289{
Jamie Madillae6ba9f2018-12-21 23:00:04 -05008290 updateTransformFeedbackActiveUnpaused(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04008291 updateBasicDrawStatesError();
Jamie Madill1e853262018-12-21 09:07:38 -05008292 updateBasicDrawElementsError();
Jamie Madill9b025062018-12-12 15:44:12 -05008293 updateValidDrawModes(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04008294}
8295
8296void StateCache::onUniformBufferStateChange(Context *context)
8297{
8298 updateBasicDrawStatesError();
8299}
8300
Jamie Madill9b025062018-12-12 15:44:12 -05008301void StateCache::setValidDrawModes(bool pointsOK,
8302 bool linesOK,
8303 bool trisOK,
8304 bool lineAdjOK,
8305 bool triAdjOK)
8306{
8307 mCachedValidDrawModes[PrimitiveMode::Points] = pointsOK;
8308 mCachedValidDrawModes[PrimitiveMode::Lines] = linesOK;
8309 mCachedValidDrawModes[PrimitiveMode::LineStrip] = linesOK;
8310 mCachedValidDrawModes[PrimitiveMode::LineLoop] = linesOK;
8311 mCachedValidDrawModes[PrimitiveMode::Triangles] = trisOK;
8312 mCachedValidDrawModes[PrimitiveMode::TriangleFan] = trisOK;
8313 mCachedValidDrawModes[PrimitiveMode::TriangleStrip] = trisOK;
8314 mCachedValidDrawModes[PrimitiveMode::LinesAdjacency] = lineAdjOK;
8315 mCachedValidDrawModes[PrimitiveMode::LineStripAdjacency] = lineAdjOK;
8316 mCachedValidDrawModes[PrimitiveMode::TrianglesAdjacency] = triAdjOK;
8317 mCachedValidDrawModes[PrimitiveMode::TriangleStripAdjacency] = triAdjOK;
8318}
8319
Jamie Madill526a6f62018-09-12 11:03:05 -04008320void StateCache::updateValidDrawModes(Context *context)
8321{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008322 const State &state = context->getState();
Jamie Madill9b025062018-12-12 15:44:12 -05008323 Program *program = state.getProgram();
8324
Jamie Madillae6ba9f2018-12-21 23:00:04 -05008325 if (mCachedTransformFeedbackActiveUnpaused)
Jamie Madill9b025062018-12-12 15:44:12 -05008326 {
Jamie Madillae6ba9f2018-12-21 23:00:04 -05008327 TransformFeedback *curTransformFeedback = state.getCurrentTransformFeedback();
8328
Jamie Madill9b025062018-12-12 15:44:12 -05008329 // ES Spec 3.0 validation text:
8330 // When transform feedback is active and not paused, all geometric primitives generated must
8331 // match the value of primitiveMode passed to BeginTransformFeedback. The error
8332 // INVALID_OPERATION is generated by DrawArrays and DrawArraysInstanced if mode is not
8333 // identical to primitiveMode. The error INVALID_OPERATION is also generated by
8334 // DrawElements, DrawElementsInstanced, and DrawRangeElements while transform feedback is
8335 // active and not paused, regardless of mode. Any primitive type may be used while transform
8336 // feedback is paused.
8337 if (!context->getExtensions().geometryShader)
8338 {
8339 mCachedValidDrawModes.fill(false);
8340 mCachedValidDrawModes[curTransformFeedback->getPrimitiveMode()] = true;
8341 return;
8342 }
8343
8344 // EXT_geometry_shader validation text:
8345 // When transform feedback is active and not paused, all geometric primitives generated must
8346 // be compatible with the value of <primitiveMode> passed to BeginTransformFeedback. If a
8347 // geometry shader is active, the type of primitive emitted by that shader is used instead
8348 // of the <mode> parameter passed to drawing commands for the purposes of this error check.
8349 // Any primitive type may be used while transform feedback is paused.
8350 bool pointsOK = curTransformFeedback->getPrimitiveMode() == PrimitiveMode::Points;
8351 bool linesOK = curTransformFeedback->getPrimitiveMode() == PrimitiveMode::Lines;
8352 bool trisOK = curTransformFeedback->getPrimitiveMode() == PrimitiveMode::Triangles;
8353
8354 setValidDrawModes(pointsOK, linesOK, trisOK, false, false);
8355 return;
8356 }
8357
Jamie Madill526a6f62018-09-12 11:03:05 -04008358 if (!program || !program->hasLinkedShaderStage(ShaderType::Geometry))
8359 {
Jamie Madill752d2202018-11-27 13:29:48 -05008360 mCachedValidDrawModes = kValidBasicDrawModes;
Jamie Madill9b025062018-12-12 15:44:12 -05008361 return;
Jamie Madill526a6f62018-09-12 11:03:05 -04008362 }
Jamie Madill526a6f62018-09-12 11:03:05 -04008363
Jamie Madill9b025062018-12-12 15:44:12 -05008364 ASSERT(program && program->hasLinkedShaderStage(ShaderType::Geometry));
8365 PrimitiveMode gsMode = program->getGeometryShaderInputPrimitiveType();
Jamie Madill526a6f62018-09-12 11:03:05 -04008366
Jamie Madill9b025062018-12-12 15:44:12 -05008367 bool pointsOK = gsMode == PrimitiveMode::Points;
8368 bool linesOK = gsMode == PrimitiveMode::Lines;
8369 bool trisOK = gsMode == PrimitiveMode::Triangles;
8370 bool lineAdjOK = gsMode == PrimitiveMode::LinesAdjacency;
8371 bool triAdjOK = gsMode == PrimitiveMode::TrianglesAdjacency;
8372
8373 setValidDrawModes(pointsOK, linesOK, trisOK, lineAdjOK, triAdjOK);
Jamie Madill526a6f62018-09-12 11:03:05 -04008374}
Jamie Madillac66f982018-10-09 18:30:01 -04008375
8376void StateCache::updateValidBindTextureTypes(Context *context)
8377{
8378 const Extensions &exts = context->getExtensions();
8379 bool isGLES3 = context->getClientMajorVersion() >= 3;
8380 bool isGLES31 = context->getClientVersion() >= Version(3, 1);
8381
8382 mCachedValidBindTextureTypes = {{
Jamie Madill752d2202018-11-27 13:29:48 -05008383 {TextureType::_2D, true},
8384 {TextureType::_2DArray, isGLES3},
8385 {TextureType::_2DMultisample, isGLES31 || exts.textureMultisample},
8386 {TextureType::_2DMultisampleArray, exts.textureStorageMultisample2DArray},
8387 {TextureType::_3D, isGLES3},
8388 {TextureType::External, exts.eglImageExternal || exts.eglStreamConsumerExternal},
8389 {TextureType::Rectangle, exts.textureRectangle},
8390 {TextureType::CubeMap, true},
Jamie Madillac66f982018-10-09 18:30:01 -04008391 }};
8392}
Jamie Madill8dc27f92018-11-29 11:45:44 -05008393
8394void StateCache::updateValidDrawElementsTypes(Context *context)
8395{
8396 bool supportsUint =
8397 (context->getClientMajorVersion() >= 3 || context->getExtensions().elementIndexUint);
8398
8399 mCachedValidDrawElementsTypes = {{
8400 {DrawElementsType::UnsignedByte, true},
8401 {DrawElementsType::UnsignedShort, true},
8402 {DrawElementsType::UnsignedInt, supportsUint},
8403 }};
8404}
Jamie Madillae6ba9f2018-12-21 23:00:04 -05008405
8406void StateCache::updateTransformFeedbackActiveUnpaused(Context *context)
8407{
Jamie Madillc3dc5d42018-12-30 12:12:04 -05008408 TransformFeedback *xfb = context->getState().getCurrentTransformFeedback();
Jamie Madillae6ba9f2018-12-21 23:00:04 -05008409 mCachedTransformFeedbackActiveUnpaused = xfb && xfb->isActive() && !xfb->isPaused();
8410}
Jamie Madillc8c7d402019-01-16 13:27:15 -05008411
8412void StateCache::updateVertexAttribTypesValidation(Context *context)
8413{
8414 if (context->getClientMajorVersion() <= 2)
8415 {
8416 mCachedVertexAttribTypesValidation = {{
8417 {VertexAttribType::Byte, VertexAttribTypeCase::Valid},
8418 {VertexAttribType::Short, VertexAttribTypeCase::Valid},
8419 {VertexAttribType::UnsignedByte, VertexAttribTypeCase::Valid},
8420 {VertexAttribType::UnsignedShort, VertexAttribTypeCase::Valid},
8421 {VertexAttribType::Float, VertexAttribTypeCase::Valid},
8422 {VertexAttribType::Fixed, VertexAttribTypeCase::Valid},
8423 }};
8424 }
8425 else
8426 {
8427 mCachedVertexAttribTypesValidation = {{
8428 {VertexAttribType::Byte, VertexAttribTypeCase::Valid},
8429 {VertexAttribType::Short, VertexAttribTypeCase::Valid},
8430 {VertexAttribType::Int, VertexAttribTypeCase::Valid},
8431 {VertexAttribType::UnsignedByte, VertexAttribTypeCase::Valid},
8432 {VertexAttribType::UnsignedShort, VertexAttribTypeCase::Valid},
8433 {VertexAttribType::UnsignedInt, VertexAttribTypeCase::Valid},
8434 {VertexAttribType::Float, VertexAttribTypeCase::Valid},
8435 {VertexAttribType::HalfFloat, VertexAttribTypeCase::Valid},
8436 {VertexAttribType::Fixed, VertexAttribTypeCase::Valid},
8437 {VertexAttribType::Int2101010, VertexAttribTypeCase::ValidSize4Only},
8438 {VertexAttribType::UnsignedInt2101010, VertexAttribTypeCase::ValidSize4Only},
8439 }};
8440
8441 mCachedIntegerVertexAttribTypesValidation = {{
8442 {VertexAttribType::Byte, VertexAttribTypeCase::Valid},
8443 {VertexAttribType::Short, VertexAttribTypeCase::Valid},
8444 {VertexAttribType::Int, VertexAttribTypeCase::Valid},
8445 {VertexAttribType::UnsignedByte, VertexAttribTypeCase::Valid},
8446 {VertexAttribType::UnsignedShort, VertexAttribTypeCase::Valid},
8447 {VertexAttribType::UnsignedInt, VertexAttribTypeCase::Valid},
8448 }};
8449 }
8450}
Jamie Madillc29968b2016-01-20 11:17:23 -05008451} // namespace gl