blob: f15fad09b775a2e5d59f1ddca421118805182bd5 [file] [log] [blame]
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001//
Geoff Langeeba6e12014-02-03 13:12:30 -05002// Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7// Context.cpp: Implements the gl::Context class, managing all GL state and performing
8// rendering operations. It is the GLES2 specific implementation of EGLContext.
9
Geoff Lang2b5420c2014-11-19 14:20:15 -050010#include "libANGLE/Context.h"
apatrick@chromium.org144f2802012-07-12 01:42:34 +000011
Jamie Madill231c7f52017-04-26 13:45:37 -040012#include <string.h>
Jamie Madillb9293972015-02-19 11:07:54 -050013#include <iterator>
14#include <sstream>
Sami Väisänend59ca052016-06-21 16:10:00 +030015#include <vector>
Jamie Madillb9293972015-02-19 11:07:54 -050016
Tobin Ehlisd7890bc2018-06-29 11:57:22 -060017#include "common/PackedEnums.h"
Sami Väisänene45e53b2016-05-25 10:36:04 +030018#include "common/matrix_utils.h"
Geoff Lang0b7eef72014-06-12 14:10:47 -040019#include "common/platform.h"
Jamie Madillb9293972015-02-19 11:07:54 -050020#include "common/utilities.h"
Geoff Langc339c4e2016-11-29 10:37:36 -050021#include "common/version.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050022#include "libANGLE/Buffer.h"
Jamie Madillb9293972015-02-19 11:07:54 -050023#include "libANGLE/Compiler.h"
Jamie Madill948bbe52017-06-01 13:10:42 -040024#include "libANGLE/Display.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050025#include "libANGLE/Fence.h"
26#include "libANGLE/Framebuffer.h"
27#include "libANGLE/FramebufferAttachment.h"
Lingfeng Yang461b09a2018-04-23 09:02:09 -070028#include "libANGLE/GLES1Renderer.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/ContextImpl.h"
46#include "libANGLE/renderer/EGLImplFactory.h"
Jamie Madill7b62cf92017-11-02 15:20:49 -040047#include "libANGLE/renderer/Format.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040048#include "libANGLE/validationES.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000049
Geoff Langf6db0982015-08-25 13:04:00 -040050namespace
51{
52
Jamie Madillb6664922017-07-25 12:55:04 -040053#define ANGLE_HANDLE_ERR(X) \
54 handleError(X); \
55 return;
56#define ANGLE_CONTEXT_TRY(EXPR) ANGLE_TRY_TEMPLATE(EXPR, ANGLE_HANDLE_ERR);
57
Ian Ewell3ffd78b2016-01-22 16:09:42 -050058template <typename T>
Geoff Lang4ddf5af2016-12-01 14:30:44 -050059std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager,
Sami Väisänend59ca052016-06-21 16:10:00 +030060 GLsizei numPaths,
61 const void *paths,
62 GLuint pathBase)
63{
64 std::vector<gl::Path *> ret;
65 ret.reserve(numPaths);
66
67 const auto *nameArray = static_cast<const T *>(paths);
68
69 for (GLsizei i = 0; i < numPaths; ++i)
70 {
71 const GLuint pathName = nameArray[i] + pathBase;
72
73 ret.push_back(resourceManager.getPath(pathName));
74 }
75
76 return ret;
77}
78
Geoff Lang4ddf5af2016-12-01 14:30:44 -050079std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager,
Sami Väisänend59ca052016-06-21 16:10:00 +030080 GLsizei numPaths,
81 GLenum pathNameType,
82 const void *paths,
83 GLuint pathBase)
84{
85 switch (pathNameType)
86 {
87 case GL_UNSIGNED_BYTE:
88 return GatherPaths<GLubyte>(resourceManager, numPaths, paths, pathBase);
89
90 case GL_BYTE:
91 return GatherPaths<GLbyte>(resourceManager, numPaths, paths, pathBase);
92
93 case GL_UNSIGNED_SHORT:
94 return GatherPaths<GLushort>(resourceManager, numPaths, paths, pathBase);
95
96 case GL_SHORT:
97 return GatherPaths<GLshort>(resourceManager, numPaths, paths, pathBase);
98
99 case GL_UNSIGNED_INT:
100 return GatherPaths<GLuint>(resourceManager, numPaths, paths, pathBase);
101
102 case GL_INT:
103 return GatherPaths<GLint>(resourceManager, numPaths, paths, pathBase);
104 }
105
106 UNREACHABLE();
107 return std::vector<gl::Path *>();
108}
109
110template <typename T>
Jamie Madill5188a272018-07-25 10:53:56 -0400111gl::Error GetQueryObjectParameter(const gl::Context *context,
112 gl::Query *query,
113 GLenum pname,
114 T *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500115{
Geoff Lang2186c382016-10-14 10:54:54 -0400116 ASSERT(query != nullptr);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500117
118 switch (pname)
119 {
120 case GL_QUERY_RESULT_EXT:
Jamie Madill5188a272018-07-25 10:53:56 -0400121 return query->getResult(context, params);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500122 case GL_QUERY_RESULT_AVAILABLE_EXT:
123 {
124 bool available;
Jamie Madill5188a272018-07-25 10:53:56 -0400125 gl::Error error = query->isResultAvailable(context, &available);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500126 if (!error.isError())
127 {
jchen10a99ed552017-09-22 08:10:32 +0800128 *params = gl::CastFromStateValue<T>(pname, static_cast<GLuint>(available));
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500129 }
130 return error;
131 }
132 default:
133 UNREACHABLE();
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500134 return gl::InternalError() << "Unreachable Error";
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500135 }
136}
137
Jamie Madill09463932018-04-04 05:26:59 -0400138void MarkTransformFeedbackBufferUsage(const gl::Context *context,
139 gl::TransformFeedback *transformFeedback,
James Darpinian30b604d2018-03-12 17:26:57 -0700140 GLsizei count,
141 GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -0400142{
Geoff Lang1a683462015-09-29 15:09:59 -0400143 if (transformFeedback && transformFeedback->isActive() && !transformFeedback->isPaused())
Geoff Langf6db0982015-08-25 13:04:00 -0400144 {
Jamie Madill09463932018-04-04 05:26:59 -0400145 transformFeedback->onVerticesDrawn(context, count, instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -0400146 }
147}
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500148
149// Attribute map queries.
Martin Radev1be913c2016-07-11 17:59:16 +0300150EGLint GetClientMajorVersion(const egl::AttributeMap &attribs)
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500151{
Ian Ewellec2c0c52016-04-05 13:46:26 -0400152 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_CLIENT_VERSION, 1));
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500153}
154
Martin Radev1be913c2016-07-11 17:59:16 +0300155EGLint GetClientMinorVersion(const egl::AttributeMap &attribs)
156{
157 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_MINOR_VERSION, 0));
158}
159
Geoff Langeb66a6e2016-10-31 13:06:12 -0400160gl::Version GetClientVersion(const egl::AttributeMap &attribs)
161{
162 return gl::Version(GetClientMajorVersion(attribs), GetClientMinorVersion(attribs));
163}
164
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500165GLenum GetResetStrategy(const egl::AttributeMap &attribs)
166{
Lingfeng Yangb27b03a2018-02-19 13:38:48 -0800167 EGLAttrib attrib =
168 attribs.get(EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT, EGL_NO_RESET_NOTIFICATION);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500169 switch (attrib)
170 {
171 case EGL_NO_RESET_NOTIFICATION:
172 return GL_NO_RESET_NOTIFICATION_EXT;
173 case EGL_LOSE_CONTEXT_ON_RESET:
174 return GL_LOSE_CONTEXT_ON_RESET_EXT;
175 default:
176 UNREACHABLE();
177 return GL_NONE;
178 }
179}
180
181bool GetRobustAccess(const egl::AttributeMap &attribs)
182{
Geoff Lang077f20a2016-11-01 10:08:02 -0400183 return (attribs.get(EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT, EGL_FALSE) == EGL_TRUE) ||
184 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR) !=
185 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500186}
187
188bool GetDebug(const egl::AttributeMap &attribs)
189{
Geoff Lang077f20a2016-11-01 10:08:02 -0400190 return (attribs.get(EGL_CONTEXT_OPENGL_DEBUG, EGL_FALSE) == EGL_TRUE) ||
191 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR) != 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500192}
193
194bool GetNoError(const egl::AttributeMap &attribs)
195{
196 return (attribs.get(EGL_CONTEXT_OPENGL_NO_ERROR_KHR, EGL_FALSE) == EGL_TRUE);
197}
198
Geoff Langc287ea62016-09-16 14:46:51 -0400199bool GetWebGLContext(const egl::AttributeMap &attribs)
200{
201 return (attribs.get(EGL_CONTEXT_WEBGL_COMPATIBILITY_ANGLE, EGL_FALSE) == EGL_TRUE);
202}
203
Geoff Lang0ab41fa2018-03-14 11:03:30 -0400204bool GetExtensionsEnabled(const egl::AttributeMap &attribs, bool webGLContext)
205{
206 // If the context is WebGL, extensions are disabled by default
207 EGLAttrib defaultValue = webGLContext ? EGL_FALSE : EGL_TRUE;
208 return (attribs.get(EGL_EXTENSIONS_ENABLED_ANGLE, defaultValue) == EGL_TRUE);
209}
210
Geoff Langf41a7152016-09-19 15:11:17 -0400211bool GetBindGeneratesResource(const egl::AttributeMap &attribs)
212{
213 return (attribs.get(EGL_CONTEXT_BIND_GENERATES_RESOURCE_CHROMIUM, EGL_TRUE) == EGL_TRUE);
214}
215
Geoff Langfeb8c682017-02-13 16:07:35 -0500216bool GetClientArraysEnabled(const egl::AttributeMap &attribs)
217{
218 return (attribs.get(EGL_CONTEXT_CLIENT_ARRAYS_ENABLED_ANGLE, EGL_TRUE) == EGL_TRUE);
219}
220
Geoff Langb433e872017-10-05 14:01:47 -0400221bool GetRobustResourceInit(const egl::AttributeMap &attribs)
222{
223 return (attribs.get(EGL_ROBUST_RESOURCE_INITIALIZATION_ANGLE, EGL_FALSE) == EGL_TRUE);
224}
225
Martin Radev9d901792016-07-15 15:58:58 +0300226std::string GetObjectLabelFromPointer(GLsizei length, const GLchar *label)
227{
228 std::string labelName;
229 if (label != nullptr)
230 {
231 size_t labelLength = length < 0 ? strlen(label) : length;
232 labelName = std::string(label, labelLength);
233 }
234 return labelName;
235}
236
237void GetObjectLabelBase(const std::string &objectLabel,
238 GLsizei bufSize,
239 GLsizei *length,
240 GLchar *label)
241{
242 size_t writeLength = objectLabel.length();
243 if (label != nullptr && bufSize > 0)
244 {
245 writeLength = std::min(static_cast<size_t>(bufSize) - 1, objectLabel.length());
246 std::copy(objectLabel.begin(), objectLabel.begin() + writeLength, label);
247 label[writeLength] = '\0';
248 }
249
250 if (length != nullptr)
251 {
252 *length = static_cast<GLsizei>(writeLength);
253 }
254}
255
Jamie Madill0f80ed82017-09-19 00:24:56 -0400256template <typename CapT, typename MaxT>
257void LimitCap(CapT *cap, MaxT maximum)
258{
259 *cap = std::min(*cap, static_cast<CapT>(maximum));
260}
261
Tobin Ehlisd7890bc2018-06-29 11:57:22 -0600262constexpr angle::PackedEnumMap<gl::PrimitiveMode, GLsizei> kMinimumPrimitiveCounts = {{
Jamie Madill526a6f62018-09-12 11:03:05 -0400263 1, /* Points */
264 2, /* Lines */
265 2, /* LineLoop */
266 2, /* LineStrip */
267 3, /* Triangles */
268 3, /* TriangleStrip */
269 3, /* TriangleFan */
270 2, /* LinesAdjacency */
271 2, /* LineStripAdjacency */
272 3, /* TrianglesAdjacency */
273 3, /* TriangleStripAdjacency */
Tobin Ehlisd7890bc2018-06-29 11:57:22 -0600274}};
275// Indices above are code-gen'd so make sure they don't change
276// if any of these static asserts are hit, must update kMinimumPrimitiveCounts abouve
277static_assert(static_cast<gl::PrimitiveMode>(0) == gl::PrimitiveMode::Points,
278 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
279static_assert(static_cast<gl::PrimitiveMode>(1) == gl::PrimitiveMode::Lines,
280 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
281static_assert(static_cast<gl::PrimitiveMode>(2) == gl::PrimitiveMode::LineLoop,
282 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
283static_assert(static_cast<gl::PrimitiveMode>(3) == gl::PrimitiveMode::LineStrip,
284 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
285static_assert(static_cast<gl::PrimitiveMode>(4) == gl::PrimitiveMode::Triangles,
286 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
287static_assert(static_cast<gl::PrimitiveMode>(5) == gl::PrimitiveMode::TriangleStrip,
288 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
289static_assert(static_cast<gl::PrimitiveMode>(6) == gl::PrimitiveMode::TriangleFan,
290 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
291static_assert(static_cast<gl::PrimitiveMode>(7) == gl::PrimitiveMode::LinesAdjacency,
292 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
293static_assert(static_cast<gl::PrimitiveMode>(8) == gl::PrimitiveMode::LineStripAdjacency,
294 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
295static_assert(static_cast<gl::PrimitiveMode>(9) == gl::PrimitiveMode::TrianglesAdjacency,
296 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
297static_assert(static_cast<gl::PrimitiveMode>(10) == gl::PrimitiveMode::TriangleStripAdjacency,
298 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
299static_assert(static_cast<gl::PrimitiveMode>(11) == gl::PrimitiveMode::EnumCount,
300 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
301
Jamie Madill6d32cef2018-08-14 02:34:28 -0400302enum SubjectIndexes : angle::SubjectIndex
303{
304 kTexture0SubjectIndex = 0,
305 kTextureMaxSubjectIndex = kTexture0SubjectIndex + gl::IMPLEMENTATION_MAX_ACTIVE_TEXTURES,
306 kUniformBuffer0SubjectIndex = kTextureMaxSubjectIndex,
307 kUniformBufferMaxSubjectIndex =
308 kUniformBuffer0SubjectIndex + gl::IMPLEMENTATION_MAX_UNIFORM_BUFFER_BINDINGS,
309 kVertexArraySubjectIndex = kUniformBufferMaxSubjectIndex,
310 kReadFramebufferSubjectIndex,
311 kDrawFramebufferSubjectIndex
312};
Geoff Langf6db0982015-08-25 13:04:00 -0400313} // anonymous namespace
314
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000315namespace gl
316{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +0000317
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400318Context::Context(rx::EGLImplFactory *implFactory,
319 const egl::Config *config,
Corentin Wallez51706ea2015-08-07 14:39:22 -0400320 const Context *shareContext,
Geoff Langce02f082017-02-06 16:46:21 -0500321 TextureManager *shareTextures,
Jamie Madill32447362017-06-28 14:53:52 -0400322 MemoryProgramCache *memoryProgramCache,
Corentin Wallezc295e512017-01-27 17:47:50 -0500323 const egl::AttributeMap &attribs,
Brandon Jones2b0cdcc2018-05-02 08:02:50 -0700324 const egl::DisplayExtensions &displayExtensions,
325 const egl::ClientExtensions &clientExtensions)
Jamie Madill5b772312018-03-08 20:28:32 -0500326 : mState(reinterpret_cast<ContextID>(this),
327 shareContext ? &shareContext->mState : nullptr,
328 shareTextures,
329 GetClientVersion(attribs),
330 &mGLState,
331 mCaps,
332 mTextureCaps,
333 mExtensions,
334 mLimitations),
335 mSkipValidation(GetNoError(attribs)),
336 mDisplayTextureShareGroup(shareTextures != nullptr),
337 mSavedArgsType(nullptr),
Geoff Lang3cacf692018-06-20 16:49:57 -0400338 mImplementation(implFactory->createContext(mState, config, shareContext, attribs)),
Geoff Lang75359662018-04-11 01:42:27 -0400339 mLabel(nullptr),
Jamie Madill2f348d22017-06-05 10:50:59 -0400340 mCompiler(),
Geoff Lang4fb8a8b2018-06-01 16:47:57 -0400341 mGLState(GetDebug(attribs),
342 GetBindGeneratesResource(attribs),
343 GetClientArraysEnabled(attribs),
344 GetRobustResourceInit(attribs),
345 memoryProgramCache != nullptr),
Corentin Walleze3b10e82015-05-20 11:06:25 -0400346 mConfig(config),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500347 mClientType(EGL_OPENGL_ES_API),
Jamie Madill6b873dd2018-07-12 23:56:30 -0400348 mErrors(this),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500349 mHasBeenCurrent(false),
350 mContextLost(false),
351 mResetStatus(GL_NO_ERROR),
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700352 mContextLostForced(false),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500353 mResetStrategy(GetResetStrategy(attribs)),
354 mRobustAccess(GetRobustAccess(attribs)),
Geoff Lang33f11fb2018-05-07 13:42:47 -0400355 mSurfacelessSupported(displayExtensions.surfacelessContext),
356 mExplicitContextAvailable(clientExtensions.explicitContext),
Jamie Madill61e16b42017-06-19 11:13:23 -0400357 mCurrentSurface(static_cast<egl::Surface *>(EGL_NO_SURFACE)),
358 mCurrentDisplay(static_cast<egl::Display *>(EGL_NO_DISPLAY)),
Jamie Madille14951e2017-03-09 18:55:16 -0500359 mWebGLContext(GetWebGLContext(attribs)),
Geoff Lang0ab41fa2018-03-14 11:03:30 -0400360 mExtensionsEnabled(GetExtensionsEnabled(attribs, mWebGLContext)),
Jamie Madill32447362017-06-28 14:53:52 -0400361 mMemoryProgramCache(memoryProgramCache),
Jamie Madilla11819d2018-07-30 10:26:01 -0400362 mVertexArrayObserverBinding(this, kVertexArraySubjectIndex),
363 mDrawFramebufferObserverBinding(this, kDrawFramebufferSubjectIndex),
364 mReadFramebufferObserverBinding(this, kReadFramebufferSubjectIndex),
Jamie Madillb3f26b92017-07-19 15:07:41 -0400365 mScratchBuffer(1000u),
jchen107ae70d82018-07-06 13:47:01 +0800366 mZeroFilledBuffer(1000u),
367 mThreadPool(nullptr)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000368{
Jamie Madill5b772312018-03-08 20:28:32 -0500369 // Needed to solve a Clang warning of unused variables.
Jamie Madillc6dbc252018-04-30 19:07:56 -0400370 ANGLE_UNUSED_VARIABLE(mSavedArgsType);
371 ANGLE_UNUSED_VARIABLE(mParamsBuffer);
Jamie Madill6d32cef2018-08-14 02:34:28 -0400372
373 for (angle::SubjectIndex uboIndex = kUniformBuffer0SubjectIndex;
374 uboIndex < kUniformBufferMaxSubjectIndex; ++uboIndex)
375 {
376 mUniformBufferObserverBindings.emplace_back(this, uboIndex);
377 }
Geoff Lang33f11fb2018-05-07 13:42:47 -0400378}
Jamie Madill5b772312018-03-08 20:28:32 -0500379
Geoff Lang33f11fb2018-05-07 13:42:47 -0400380void Context::initialize()
381{
382 mImplementation->setMemoryProgramCache(mMemoryProgramCache);
Jamie Madill14bbb3f2017-09-12 15:23:01 -0400383
Geoff Lang33f11fb2018-05-07 13:42:47 -0400384 initCaps();
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700385 initWorkarounds();
Geoff Langc0b9ef42014-07-02 10:02:37 -0400386
Geoff Lang4fb8a8b2018-06-01 16:47:57 -0400387 mGLState.initialize(this);
Régis Fénéon83107972015-02-05 12:57:44 +0100388
Shannon Woods53a94a82014-06-24 15:20:36 -0400389 mFenceNVHandleAllocator.setBaseHandle(0);
Geoff Lang7dca1862013-07-30 16:30:46 -0400390
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000391 // [OpenGL ES 2.0.24] section 3.7 page 83:
Corentin Wallez336129f2017-10-17 15:55:40 -0400392 // In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have two-dimensional
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000393 // and cube map texture state vectors respectively associated with them.
394 // In order that access to these initial textures not be lost, they are treated as texture
395 // objects all of whose names are 0.
396
Corentin Wallez99d492c2018-02-27 15:17:10 -0500397 Texture *zeroTexture2D = new Texture(mImplementation.get(), 0, TextureType::_2D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800398 mZeroTextures[TextureType::_2D].set(this, zeroTexture2D);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500399
Corentin Wallez99d492c2018-02-27 15:17:10 -0500400 Texture *zeroTextureCube = new Texture(mImplementation.get(), 0, TextureType::CubeMap);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800401 mZeroTextures[TextureType::CubeMap].set(this, zeroTextureCube);
Geoff Lang76b10c92014-09-05 16:28:14 -0400402
Geoff Langeb66a6e2016-10-31 13:06:12 -0400403 if (getClientVersion() >= Version(3, 0))
Geoff Lang76b10c92014-09-05 16:28:14 -0400404 {
405 // TODO: These could also be enabled via extension
Corentin Wallez99d492c2018-02-27 15:17:10 -0500406 Texture *zeroTexture3D = new Texture(mImplementation.get(), 0, TextureType::_3D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800407 mZeroTextures[TextureType::_3D].set(this, zeroTexture3D);
Geoff Lang76b10c92014-09-05 16:28:14 -0400408
Corentin Wallez99d492c2018-02-27 15:17:10 -0500409 Texture *zeroTexture2DArray = new Texture(mImplementation.get(), 0, TextureType::_2DArray);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800410 mZeroTextures[TextureType::_2DArray].set(this, zeroTexture2DArray);
Geoff Lang76b10c92014-09-05 16:28:14 -0400411 }
Geoff Lang3b573612016-10-31 14:08:10 -0400412 if (getClientVersion() >= Version(3, 1))
413 {
Olli Etuahod310a432018-08-24 15:40:23 +0300414 // TODO(http://anglebug.com/2775): These could also be enabled via extension
Geoff Lang3b573612016-10-31 14:08:10 -0400415 Texture *zeroTexture2DMultisample =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500416 new Texture(mImplementation.get(), 0, TextureType::_2DMultisample);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800417 mZeroTextures[TextureType::_2DMultisample].set(this, zeroTexture2DMultisample);
Olli Etuahod310a432018-08-24 15:40:23 +0300418 Texture *zeroTexture2DMultisampleArray =
419 new Texture(mImplementation.get(), 0, TextureType::_2DMultisampleArray);
420 mZeroTextures[TextureType::_2DMultisampleArray].set(this, zeroTexture2DMultisampleArray);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800421
Jiajia Qin6eafb042016-12-27 17:04:07 +0800422 for (unsigned int i = 0; i < mCaps.maxAtomicCounterBufferBindings; i++)
423 {
Qin Jiajia339f65b2018-02-27 12:52:48 +0800424 bindBufferRange(BufferBinding::AtomicCounter, i, 0, 0, 0);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800425 }
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800426
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800427 for (unsigned int i = 0; i < mCaps.maxShaderStorageBufferBindings; i++)
428 {
Corentin Wallez336129f2017-10-17 15:55:40 -0400429 bindBufferRange(BufferBinding::ShaderStorage, i, 0, 0, 0);
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800430 }
Geoff Lang3b573612016-10-31 14:08:10 -0400431 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000432
Geoff Langb0f917f2017-12-05 13:41:54 -0500433 if (mSupportedExtensions.textureRectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400434 {
435 Texture *zeroTextureRectangle =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500436 new Texture(mImplementation.get(), 0, TextureType::Rectangle);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800437 mZeroTextures[TextureType::Rectangle].set(this, zeroTextureRectangle);
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400438 }
439
Geoff Langb0f917f2017-12-05 13:41:54 -0500440 if (mSupportedExtensions.eglImageExternal || mSupportedExtensions.eglStreamConsumerExternal)
Ian Ewellbda75592016-04-18 17:25:54 -0400441 {
Corentin Wallez99d492c2018-02-27 15:17:10 -0500442 Texture *zeroTextureExternal = new Texture(mImplementation.get(), 0, TextureType::External);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800443 mZeroTextures[TextureType::External].set(this, zeroTextureExternal);
Ian Ewellbda75592016-04-18 17:25:54 -0400444 }
445
Jamie Madill4928b7c2017-06-20 12:57:39 -0400446 mGLState.initializeZeroTextures(this, mZeroTextures);
Jamie Madille6382c32014-11-07 15:05:26 -0500447
Jamie Madill57a89722013-07-02 11:57:03 -0400448 bindVertexArray(0);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000449
Geoff Langeb66a6e2016-10-31 13:06:12 -0400450 if (getClientVersion() >= Version(3, 0))
Geoff Lang1a683462015-09-29 15:09:59 -0400451 {
452 // [OpenGL ES 3.0.2] section 2.14.1 pg 85:
453 // In the initial state, a default transform feedback object is bound and treated as
454 // a transform feedback object with a name of zero. That object is bound any time
455 // BindTransformFeedback is called with id of zero
Jamie Madillf0dcb8b2017-08-26 19:05:13 -0400456 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Geoff Lang1a683462015-09-29 15:09:59 -0400457 }
Geoff Langc8058452014-02-03 12:04:11 -0500458
Corentin Wallez336129f2017-10-17 15:55:40 -0400459 for (auto type : angle::AllEnums<BufferBinding>())
460 {
461 bindBuffer(type, 0);
462 }
463
464 bindRenderbuffer(GL_RENDERBUFFER, 0);
465
466 for (unsigned int i = 0; i < mCaps.maxUniformBufferBindings; i++)
467 {
468 bindBufferRange(BufferBinding::Uniform, i, 0, 0, -1);
469 }
470
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700471 // Initialize GLES1 renderer if appropriate.
472 if (getClientVersion() < Version(2, 0))
473 {
474 mGLES1Renderer.reset(new GLES1Renderer());
475 }
476
Jamie Madillad9f24e2016-02-12 09:27:24 -0500477 // Initialize dirty bit masks
Geoff Lang9bf86f02018-07-26 11:46:34 -0400478 mDrawDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
479 mDrawDirtyObjects.set(State::DIRTY_OBJECT_VERTEX_ARRAY);
480 mDrawDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM_TEXTURES);
Jamie Madill70aeda42018-08-20 12:17:40 -0400481 mDrawDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM);
Geoff Lang9bf86f02018-07-26 11:46:34 -0400482
483 mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
484 mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_VERTEX_ARRAY);
485 mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM_TEXTURES);
486
Jamie Madillc67323a2017-11-02 23:11:41 -0400487 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500488 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500489 // No dirty objects.
490
491 // Readpixels uses the pack state and read FBO
Jamie Madillc67323a2017-11-02 23:11:41 -0400492 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500493 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_BUFFER_BINDING);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400494 mReadPixelsDirtyBits.set(State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500495 mReadPixelsDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
496
497 mClearDirtyBits.set(State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED);
498 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
499 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR);
500 mClearDirtyBits.set(State::DIRTY_BIT_VIEWPORT);
501 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_COLOR);
502 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_DEPTH);
503 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_STENCIL);
504 mClearDirtyBits.set(State::DIRTY_BIT_COLOR_MASK);
505 mClearDirtyBits.set(State::DIRTY_BIT_DEPTH_MASK);
506 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT);
507 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_BACK);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400508 mClearDirtyBits.set(State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500509 mClearDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
510
511 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
512 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR);
Geoff Lang1d2c41d2016-10-19 16:14:46 -0700513 mBlitDirtyBits.set(State::DIRTY_BIT_FRAMEBUFFER_SRGB);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400514 mBlitDirtyBits.set(State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
515 mBlitDirtyBits.set(State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500516 mBlitDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
517 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
Jamie Madill437fa652016-05-03 15:13:24 -0400518
Xinghua Cao10a4d432017-11-28 14:46:26 +0800519 // TODO(xinghua.cao@intel.com): add other dirty bits and dirty objects.
520 mComputeDirtyBits.set(State::DIRTY_BIT_SHADER_STORAGE_BUFFER_BINDING);
521 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_BINDING);
522 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_EXECUTABLE);
523 mComputeDirtyBits.set(State::DIRTY_BIT_TEXTURE_BINDINGS);
524 mComputeDirtyBits.set(State::DIRTY_BIT_SAMPLER_BINDINGS);
Qin Jiajia62fcf622017-11-30 16:16:12 +0800525 mComputeDirtyBits.set(State::DIRTY_BIT_DISPATCH_INDIRECT_BUFFER_BINDING);
Jiajia Qin5ae6ee42018-03-06 17:39:42 +0800526 mComputeDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM_TEXTURES);
Jamie Madill70aeda42018-08-20 12:17:40 -0400527 mComputeDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM);
Xinghua Cao10a4d432017-11-28 14:46:26 +0800528
Jamie Madillb4927eb2018-07-16 11:39:46 -0400529 mImplementation->setErrorSet(&mErrors);
530
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400531 handleError(mImplementation->initialize());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000532}
533
Jamie Madill4928b7c2017-06-20 12:57:39 -0400534egl::Error Context::onDestroy(const egl::Display *display)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000535{
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700536 if (mGLES1Renderer)
537 {
538 mGLES1Renderer->onDestroy(this, &mGLState);
539 }
540
Jamie Madille7b3fe22018-04-05 09:42:46 -0400541 // Delete the Surface first to trigger a finish() in Vulkan.
Jamie Madille7b3fe22018-04-05 09:42:46 -0400542 ANGLE_TRY(releaseSurface(display));
543
Corentin Wallez80b24112015-08-25 16:41:57 -0400544 for (auto fence : mFenceNVMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000545 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400546 SafeDelete(fence.second);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000547 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400548 mFenceNVMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000549
Corentin Wallez80b24112015-08-25 16:41:57 -0400550 for (auto query : mQueryMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000551 {
Geoff Langf0aa8422015-09-29 15:08:34 -0400552 if (query.second != nullptr)
553 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400554 query.second->release(this);
Geoff Langf0aa8422015-09-29 15:08:34 -0400555 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000556 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400557 mQueryMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000558
Corentin Wallez80b24112015-08-25 16:41:57 -0400559 for (auto vertexArray : mVertexArrayMap)
Jamie Madill57a89722013-07-02 11:57:03 -0400560 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400561 if (vertexArray.second)
562 {
563 vertexArray.second->onDestroy(this);
564 }
Jamie Madill57a89722013-07-02 11:57:03 -0400565 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400566 mVertexArrayMap.clear();
Jamie Madill57a89722013-07-02 11:57:03 -0400567
Corentin Wallez80b24112015-08-25 16:41:57 -0400568 for (auto transformFeedback : mTransformFeedbackMap)
Geoff Langc8058452014-02-03 12:04:11 -0500569 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500570 if (transformFeedback.second != nullptr)
571 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500572 transformFeedback.second->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500573 }
Geoff Langc8058452014-02-03 12:04:11 -0500574 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400575 mTransformFeedbackMap.clear();
Geoff Langc8058452014-02-03 12:04:11 -0500576
Jamie Madill5b772312018-03-08 20:28:32 -0500577 for (BindingPointer<Texture> &zeroTexture : mZeroTextures)
Geoff Lang76b10c92014-09-05 16:28:14 -0400578 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800579 if (zeroTexture.get() != nullptr)
580 {
581 ANGLE_TRY(zeroTexture->onDestroy(this));
582 zeroTexture.set(this, nullptr);
583 }
Geoff Lang76b10c92014-09-05 16:28:14 -0400584 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000585
Jamie Madill2f348d22017-06-05 10:50:59 -0400586 releaseShaderCompiler();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500587
Jamie Madill4928b7c2017-06-20 12:57:39 -0400588 mGLState.reset(this);
589
Jamie Madill6c1f6712017-02-14 19:08:04 -0500590 mState.mBuffers->release(this);
591 mState.mShaderPrograms->release(this);
592 mState.mTextures->release(this);
593 mState.mRenderbuffers->release(this);
594 mState.mSamplers->release(this);
Jamie Madill70b5bb02017-08-28 13:32:37 -0400595 mState.mSyncs->release(this);
Jamie Madill6c1f6712017-02-14 19:08:04 -0500596 mState.mPaths->release(this);
597 mState.mFramebuffers->release(this);
Yunchao Hea336b902017-08-02 16:05:21 +0800598 mState.mPipelines->release(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400599
jchen107ae70d82018-07-06 13:47:01 +0800600 mThreadPool.reset();
601
Jamie Madill76e471e2017-10-21 09:56:01 -0400602 mImplementation->onDestroy(this);
603
Jamie Madill4928b7c2017-06-20 12:57:39 -0400604 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000605}
606
Jamie Madill70ee0f62017-02-06 16:04:20 -0500607Context::~Context()
608{
609}
610
Geoff Lang75359662018-04-11 01:42:27 -0400611void Context::setLabel(EGLLabelKHR label)
612{
613 mLabel = label;
614}
615
616EGLLabelKHR Context::getLabel() const
617{
618 return mLabel;
619}
620
Jamie Madill4928b7c2017-06-20 12:57:39 -0400621egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000622{
Jamie Madill61e16b42017-06-19 11:13:23 -0400623 mCurrentDisplay = display;
624
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000625 if (!mHasBeenCurrent)
626 {
Geoff Lang33f11fb2018-05-07 13:42:47 -0400627 initialize();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000628 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500629 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400630 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000631
Corentin Wallezc295e512017-01-27 17:47:50 -0500632 int width = 0;
633 int height = 0;
634 if (surface != nullptr)
635 {
636 width = surface->getWidth();
637 height = surface->getHeight();
638 }
639
640 mGLState.setViewportParams(0, 0, width, height);
641 mGLState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000642
643 mHasBeenCurrent = true;
644 }
645
Jamie Madill1b94d432015-08-07 13:23:23 -0400646 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700647 mGLState.setAllDirtyBits();
Jamie Madill81c2e252017-09-09 23:32:46 -0400648 mGLState.setAllDirtyObjects();
Jamie Madill1b94d432015-08-07 13:23:23 -0400649
Jamie Madill4928b7c2017-06-20 12:57:39 -0400650 ANGLE_TRY(releaseSurface(display));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500651
652 Framebuffer *newDefault = nullptr;
653 if (surface != nullptr)
654 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400655 ANGLE_TRY(surface->setIsCurrent(this, true));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500656 mCurrentSurface = surface;
Geoff Langbf7b95d2018-05-01 16:48:21 -0400657 newDefault = surface->createDefaultFramebuffer(this);
Corentin Wallezccab69d2017-01-27 16:57:15 -0500658 }
659 else
660 {
Geoff Langbf7b95d2018-05-01 16:48:21 -0400661 newDefault = new Framebuffer(mImplementation.get());
Corentin Wallezccab69d2017-01-27 16:57:15 -0500662 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000663
Corentin Wallez37c39792015-08-20 14:19:46 -0400664 // Update default framebuffer, the binding of the previous default
665 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400666 {
Jamie Madilla11819d2018-07-30 10:26:01 -0400667 mState.mFramebuffers->setDefaultFramebuffer(newDefault);
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700668 if (mGLState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400669 {
Jamie Madilla11819d2018-07-30 10:26:01 -0400670 bindReadFramebuffer(0);
Corentin Wallez37c39792015-08-20 14:19:46 -0400671 }
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700672 if (mGLState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400673 {
Jamie Madilla11819d2018-07-30 10:26:01 -0400674 bindDrawFramebuffer(0);
Corentin Wallez37c39792015-08-20 14:19:46 -0400675 }
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400676 }
Ian Ewell292f0052016-02-04 10:37:32 -0500677
678 // Notify the renderer of a context switch
Luc Ferron5396f2a2018-07-12 08:24:23 -0400679 ANGLE_TRY(mImplementation->onMakeCurrent(this));
Jamie Madill4928b7c2017-06-20 12:57:39 -0400680 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000681}
682
Jamie Madill4928b7c2017-06-20 12:57:39 -0400683egl::Error Context::releaseSurface(const egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400684{
Geoff Langbf7b95d2018-05-01 16:48:21 -0400685 gl::Framebuffer *defaultFramebuffer = mState.mFramebuffers->getFramebuffer(0);
Corentin Wallez51706ea2015-08-07 14:39:22 -0400686
Geoff Langbf7b95d2018-05-01 16:48:21 -0400687 // Remove the default framebuffer
688 if (mGLState.getReadFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500689 {
690 mGLState.setReadFramebufferBinding(nullptr);
Jamie Madilla11819d2018-07-30 10:26:01 -0400691 mReadFramebufferObserverBinding.bind(nullptr);
Corentin Wallezc295e512017-01-27 17:47:50 -0500692 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400693
694 if (mGLState.getDrawFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500695 {
696 mGLState.setDrawFramebufferBinding(nullptr);
Jamie Madilla11819d2018-07-30 10:26:01 -0400697 mDrawFramebufferObserverBinding.bind(nullptr);
Corentin Wallezc295e512017-01-27 17:47:50 -0500698 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400699
700 if (defaultFramebuffer)
701 {
702 defaultFramebuffer->onDestroy(this);
703 delete defaultFramebuffer;
704 }
705
Corentin Wallezc295e512017-01-27 17:47:50 -0500706 mState.mFramebuffers->setDefaultFramebuffer(nullptr);
707
708 if (mCurrentSurface)
709 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400710 ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
Corentin Wallezc295e512017-01-27 17:47:50 -0500711 mCurrentSurface = nullptr;
712 }
Jamie Madill4928b7c2017-06-20 12:57:39 -0400713
714 return egl::NoError();
Jamie Madill77a72f62015-04-14 11:18:32 -0400715}
716
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000717GLuint Context::createBuffer()
718{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500719 return mState.mBuffers->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000720}
721
722GLuint Context::createProgram()
723{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500724 return mState.mShaderPrograms->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000725}
726
Jiawei Shao385b3e02018-03-21 09:43:28 +0800727GLuint Context::createShader(ShaderType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000728{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500729 return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000730}
731
732GLuint Context::createTexture()
733{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500734 return mState.mTextures->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000735}
736
737GLuint Context::createRenderbuffer()
738{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500739 return mState.mRenderbuffers->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000740}
741
Brandon Jones59770802018-04-02 13:18:42 -0700742GLuint Context::genPaths(GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300743{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500744 auto resultOrError = mState.mPaths->createPaths(mImplementation.get(), range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300745 if (resultOrError.isError())
746 {
747 handleError(resultOrError.getError());
748 return 0;
749 }
750 return resultOrError.getResult();
751}
752
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000753// Returns an unused framebuffer name
754GLuint Context::createFramebuffer()
755{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500756 return mState.mFramebuffers->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000757}
758
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500759void Context::genFencesNV(GLsizei n, GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000760{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500761 for (int i = 0; i < n; i++)
762 {
763 GLuint handle = mFenceNVHandleAllocator.allocate();
764 mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV()));
765 fences[i] = handle;
766 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000767}
768
Yunchao Hea336b902017-08-02 16:05:21 +0800769GLuint Context::createProgramPipeline()
770{
771 return mState.mPipelines->createProgramPipeline();
772}
773
Jiawei Shao385b3e02018-03-21 09:43:28 +0800774GLuint Context::createShaderProgramv(ShaderType type, GLsizei count, const GLchar *const *strings)
Jiajia Qin5451d532017-11-16 17:16:34 +0800775{
776 UNIMPLEMENTED();
777 return 0u;
778}
779
James Darpinian4d9d4832018-03-13 12:43:28 -0700780void Context::deleteBuffer(GLuint bufferName)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000781{
James Darpinian4d9d4832018-03-13 12:43:28 -0700782 Buffer *buffer = mState.mBuffers->getBuffer(bufferName);
783 if (buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000784 {
785 detachBuffer(buffer);
786 }
Jamie Madill893ab082014-05-16 16:56:10 -0400787
James Darpinian4d9d4832018-03-13 12:43:28 -0700788 mState.mBuffers->deleteObject(this, bufferName);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000789}
790
791void Context::deleteShader(GLuint shader)
792{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500793 mState.mShaderPrograms->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000794}
795
796void Context::deleteProgram(GLuint program)
797{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500798 mState.mShaderPrograms->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000799}
800
801void Context::deleteTexture(GLuint texture)
802{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500803 if (mState.mTextures->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000804 {
805 detachTexture(texture);
806 }
807
Jamie Madill6c1f6712017-02-14 19:08:04 -0500808 mState.mTextures->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000809}
810
811void Context::deleteRenderbuffer(GLuint renderbuffer)
812{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500813 if (mState.mRenderbuffers->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000814 {
815 detachRenderbuffer(renderbuffer);
816 }
Jamie Madill893ab082014-05-16 16:56:10 -0400817
Jamie Madill6c1f6712017-02-14 19:08:04 -0500818 mState.mRenderbuffers->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000819}
820
Jamie Madill7f0c5a42017-08-26 22:43:26 -0400821void Context::deleteSync(GLsync sync)
Jamie Madillcd055f82013-07-26 11:55:15 -0400822{
823 // The spec specifies the underlying Fence object is not deleted until all current
824 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
825 // and since our API is currently designed for being called from a single thread, we can delete
826 // the fence immediately.
Jamie Madill70b5bb02017-08-28 13:32:37 -0400827 mState.mSyncs->deleteObject(this, static_cast<GLuint>(reinterpret_cast<uintptr_t>(sync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400828}
829
Yunchao Hea336b902017-08-02 16:05:21 +0800830void Context::deleteProgramPipeline(GLuint pipeline)
831{
832 if (mState.mPipelines->getProgramPipeline(pipeline))
833 {
834 detachProgramPipeline(pipeline);
835 }
836
837 mState.mPipelines->deleteObject(this, pipeline);
838}
839
Sami Väisänene45e53b2016-05-25 10:36:04 +0300840void Context::deletePaths(GLuint first, GLsizei range)
841{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500842 mState.mPaths->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300843}
844
Brandon Jones59770802018-04-02 13:18:42 -0700845bool Context::isPath(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300846{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500847 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300848 if (pathObj == nullptr)
849 return false;
850
851 return pathObj->hasPathData();
852}
853
Brandon Jones59770802018-04-02 13:18:42 -0700854bool Context::isPathGenerated(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300855{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500856 return mState.mPaths->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300857}
858
Brandon Jones59770802018-04-02 13:18:42 -0700859void Context::pathCommands(GLuint path,
860 GLsizei numCommands,
861 const GLubyte *commands,
862 GLsizei numCoords,
863 GLenum coordType,
864 const void *coords)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300865{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500866 auto *pathObject = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300867
868 handleError(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
869}
870
Jamie Madill007530e2017-12-28 14:27:04 -0500871void Context::pathParameterf(GLuint path, GLenum pname, GLfloat value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300872{
Jamie Madill007530e2017-12-28 14:27:04 -0500873 Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300874
875 switch (pname)
876 {
877 case GL_PATH_STROKE_WIDTH_CHROMIUM:
878 pathObj->setStrokeWidth(value);
879 break;
880 case GL_PATH_END_CAPS_CHROMIUM:
881 pathObj->setEndCaps(static_cast<GLenum>(value));
882 break;
883 case GL_PATH_JOIN_STYLE_CHROMIUM:
884 pathObj->setJoinStyle(static_cast<GLenum>(value));
885 break;
886 case GL_PATH_MITER_LIMIT_CHROMIUM:
887 pathObj->setMiterLimit(value);
888 break;
889 case GL_PATH_STROKE_BOUND_CHROMIUM:
890 pathObj->setStrokeBound(value);
891 break;
892 default:
893 UNREACHABLE();
894 break;
895 }
896}
897
Jamie Madill007530e2017-12-28 14:27:04 -0500898void Context::pathParameteri(GLuint path, GLenum pname, GLint value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300899{
Jamie Madill007530e2017-12-28 14:27:04 -0500900 // TODO(jmadill): Should use proper clamping/casting.
901 pathParameterf(path, pname, static_cast<GLfloat>(value));
902}
903
904void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value)
905{
906 const Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300907
908 switch (pname)
909 {
910 case GL_PATH_STROKE_WIDTH_CHROMIUM:
911 *value = pathObj->getStrokeWidth();
912 break;
913 case GL_PATH_END_CAPS_CHROMIUM:
914 *value = static_cast<GLfloat>(pathObj->getEndCaps());
915 break;
916 case GL_PATH_JOIN_STYLE_CHROMIUM:
917 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
918 break;
919 case GL_PATH_MITER_LIMIT_CHROMIUM:
920 *value = pathObj->getMiterLimit();
921 break;
922 case GL_PATH_STROKE_BOUND_CHROMIUM:
923 *value = pathObj->getStrokeBound();
924 break;
925 default:
926 UNREACHABLE();
927 break;
928 }
929}
930
Jamie Madill007530e2017-12-28 14:27:04 -0500931void Context::getPathParameteriv(GLuint path, GLenum pname, GLint *value)
932{
933 GLfloat val = 0.0f;
934 getPathParameterfv(path, pname, value != nullptr ? &val : nullptr);
935 if (value)
936 *value = static_cast<GLint>(val);
937}
938
Brandon Jones59770802018-04-02 13:18:42 -0700939void Context::pathStencilFunc(GLenum func, GLint ref, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300940{
941 mGLState.setPathStencilFunc(func, ref, mask);
942}
943
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000944void Context::deleteFramebuffer(GLuint framebuffer)
945{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500946 if (mState.mFramebuffers->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000947 {
948 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000949 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500950
Jamie Madill6c1f6712017-02-14 19:08:04 -0500951 mState.mFramebuffers->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000952}
953
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500954void Context::deleteFencesNV(GLsizei n, const GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000955{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500956 for (int i = 0; i < n; i++)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000957 {
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500958 GLuint fence = fences[i];
959
960 FenceNV *fenceObject = nullptr;
961 if (mFenceNVMap.erase(fence, &fenceObject))
962 {
963 mFenceNVHandleAllocator.release(fence);
964 delete fenceObject;
965 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000966 }
967}
968
Geoff Lang70d0f492015-12-10 17:45:46 -0500969Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000970{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500971 return mState.mBuffers->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000972}
973
Jamie Madill570f7c82014-07-03 10:38:54 -0400974Texture *Context::getTexture(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000975{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500976 return mState.mTextures->getTexture(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000977}
978
Geoff Lang70d0f492015-12-10 17:45:46 -0500979Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000980{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500981 return mState.mRenderbuffers->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000982}
983
Jamie Madill70b5bb02017-08-28 13:32:37 -0400984Sync *Context::getSync(GLsync handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400985{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400986 return mState.mSyncs->getSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400987}
988
Jamie Madill57a89722013-07-02 11:57:03 -0400989VertexArray *Context::getVertexArray(GLuint handle) const
990{
Jamie Madill96a483b2017-06-27 16:49:21 -0400991 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -0400992}
993
Jamie Madilldc356042013-07-19 16:36:57 -0400994Sampler *Context::getSampler(GLuint handle) const
995{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500996 return mState.mSamplers->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400997}
998
Geoff Langc8058452014-02-03 12:04:11 -0500999TransformFeedback *Context::getTransformFeedback(GLuint handle) const
1000{
Jamie Madill96a483b2017-06-27 16:49:21 -04001001 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -05001002}
1003
Yunchao Hea336b902017-08-02 16:05:21 +08001004ProgramPipeline *Context::getProgramPipeline(GLuint handle) const
1005{
1006 return mState.mPipelines->getProgramPipeline(handle);
1007}
1008
Geoff Lang75359662018-04-11 01:42:27 -04001009gl::LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
Geoff Lang70d0f492015-12-10 17:45:46 -05001010{
1011 switch (identifier)
1012 {
1013 case GL_BUFFER:
1014 return getBuffer(name);
1015 case GL_SHADER:
1016 return getShader(name);
1017 case GL_PROGRAM:
1018 return getProgram(name);
1019 case GL_VERTEX_ARRAY:
1020 return getVertexArray(name);
1021 case GL_QUERY:
1022 return getQuery(name);
1023 case GL_TRANSFORM_FEEDBACK:
1024 return getTransformFeedback(name);
1025 case GL_SAMPLER:
1026 return getSampler(name);
1027 case GL_TEXTURE:
1028 return getTexture(name);
1029 case GL_RENDERBUFFER:
1030 return getRenderbuffer(name);
1031 case GL_FRAMEBUFFER:
1032 return getFramebuffer(name);
1033 default:
1034 UNREACHABLE();
1035 return nullptr;
1036 }
1037}
1038
Geoff Lang75359662018-04-11 01:42:27 -04001039gl::LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
Geoff Lang70d0f492015-12-10 17:45:46 -05001040{
Jamie Madill70b5bb02017-08-28 13:32:37 -04001041 return getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
Geoff Lang70d0f492015-12-10 17:45:46 -05001042}
1043
Martin Radev9d901792016-07-15 15:58:58 +03001044void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
1045{
Geoff Lang75359662018-04-11 01:42:27 -04001046 gl::LabeledObject *object = getLabeledObject(identifier, name);
Martin Radev9d901792016-07-15 15:58:58 +03001047 ASSERT(object != nullptr);
1048
1049 std::string labelName = GetObjectLabelFromPointer(length, label);
1050 object->setLabel(labelName);
Jamie Madill8693bdb2017-09-02 15:32:14 -04001051
1052 // TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the
1053 // specified object is active until we do this.
1054 mGLState.setObjectDirty(identifier);
Martin Radev9d901792016-07-15 15:58:58 +03001055}
1056
1057void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
1058{
Geoff Lang75359662018-04-11 01:42:27 -04001059 gl::LabeledObject *object = getLabeledObjectFromPtr(ptr);
Martin Radev9d901792016-07-15 15:58:58 +03001060 ASSERT(object != nullptr);
1061
1062 std::string labelName = GetObjectLabelFromPointer(length, label);
1063 object->setLabel(labelName);
1064}
1065
1066void Context::getObjectLabel(GLenum identifier,
1067 GLuint name,
1068 GLsizei bufSize,
1069 GLsizei *length,
1070 GLchar *label) const
1071{
Geoff Lang75359662018-04-11 01:42:27 -04001072 gl::LabeledObject *object = getLabeledObject(identifier, name);
Martin Radev9d901792016-07-15 15:58:58 +03001073 ASSERT(object != nullptr);
1074
1075 const std::string &objectLabel = object->getLabel();
1076 GetObjectLabelBase(objectLabel, bufSize, length, label);
1077}
1078
1079void Context::getObjectPtrLabel(const void *ptr,
1080 GLsizei bufSize,
1081 GLsizei *length,
1082 GLchar *label) const
1083{
Geoff Lang75359662018-04-11 01:42:27 -04001084 gl::LabeledObject *object = getLabeledObjectFromPtr(ptr);
Martin Radev9d901792016-07-15 15:58:58 +03001085 ASSERT(object != nullptr);
1086
1087 const std::string &objectLabel = object->getLabel();
1088 GetObjectLabelBase(objectLabel, bufSize, length, label);
1089}
1090
Jamie Madilldc356042013-07-19 16:36:57 -04001091bool Context::isSampler(GLuint samplerName) const
1092{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001093 return mState.mSamplers->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -04001094}
1095
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001096void Context::bindTexture(TextureType target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001097{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001098 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001099
Jamie Madilldedd7b92014-11-05 16:30:36 -05001100 if (handle == 0)
1101 {
1102 texture = mZeroTextures[target].get();
1103 }
1104 else
1105 {
Corentin Wallez99d492c2018-02-27 15:17:10 -05001106 texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -05001107 }
1108
1109 ASSERT(texture);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001110 mGLState.setSamplerTexture(this, target, texture);
Jamie Madilld84b6732018-09-06 15:54:35 -04001111 mStateCache.onActiveTextureChange(this);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00001112}
1113
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001114void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001115{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001116 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1117 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001118 mGLState.setReadFramebufferBinding(framebuffer);
Jamie Madilla11819d2018-07-30 10:26:01 -04001119 mReadFramebufferObserverBinding.bind(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001120}
1121
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001122void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001123{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001124 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1125 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001126 mGLState.setDrawFramebufferBinding(framebuffer);
Jamie Madilla11819d2018-07-30 10:26:01 -04001127 mDrawFramebufferObserverBinding.bind(framebuffer);
Jamie Madilld84b6732018-09-06 15:54:35 -04001128 mStateCache.onDrawFramebufferChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001129}
1130
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001131void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -04001132{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001133 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madill7267aa62018-04-17 15:28:21 -04001134 mGLState.setVertexArrayBinding(this, vertexArray);
Jamie Madilla11819d2018-07-30 10:26:01 -04001135 mVertexArrayObserverBinding.bind(vertexArray);
Jamie Madillc43cdad2018-08-08 15:49:25 -04001136 mStateCache.onVertexArrayBindingChange(this);
Jamie Madill57a89722013-07-02 11:57:03 -04001137}
1138
Shao80957d92017-02-20 21:25:59 +08001139void Context::bindVertexBuffer(GLuint bindingIndex,
1140 GLuint bufferHandle,
1141 GLintptr offset,
1142 GLsizei stride)
1143{
1144 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001145 mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Jamie Madillc43cdad2018-08-08 15:49:25 -04001146 mStateCache.onVertexArrayStateChange(this);
Shao80957d92017-02-20 21:25:59 +08001147}
1148
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001149void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -04001150{
Geoff Lang76b10c92014-09-05 16:28:14 -04001151 ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -04001152 Sampler *sampler =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001153 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001154 mGLState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04001155}
1156
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001157void Context::bindImageTexture(GLuint unit,
1158 GLuint texture,
1159 GLint level,
1160 GLboolean layered,
1161 GLint layer,
1162 GLenum access,
1163 GLenum format)
1164{
1165 Texture *tex = mState.mTextures->getTexture(texture);
1166 mGLState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
1167}
1168
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001169void Context::useProgram(GLuint program)
1170{
Jamie Madill6c1f6712017-02-14 19:08:04 -05001171 mGLState.setProgram(this, getProgram(program));
Jamie Madillc43cdad2018-08-08 15:49:25 -04001172 mStateCache.onProgramExecutableChange(this);
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001173}
1174
Jiajia Qin5451d532017-11-16 17:16:34 +08001175void Context::useProgramStages(GLuint pipeline, GLbitfield stages, GLuint program)
1176{
1177 UNIMPLEMENTED();
1178}
1179
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001180void Context::bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001181{
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001182 ASSERT(target == GL_TRANSFORM_FEEDBACK);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001183 TransformFeedback *transformFeedback =
1184 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001185 mGLState.setTransformFeedbackBinding(this, transformFeedback);
Jamie Madilld84b6732018-09-06 15:54:35 -04001186 mStateCache.onTransformFeedbackChange(this);
Geoff Langc8058452014-02-03 12:04:11 -05001187}
1188
Yunchao Hea336b902017-08-02 16:05:21 +08001189void Context::bindProgramPipeline(GLuint pipelineHandle)
1190{
1191 ProgramPipeline *pipeline =
1192 mState.mPipelines->checkProgramPipelineAllocation(mImplementation.get(), pipelineHandle);
1193 mGLState.setProgramPipelineBinding(this, pipeline);
1194}
1195
Corentin Wallezad3ae902018-03-09 13:40:42 -05001196void Context::beginQuery(QueryType target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001197{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001198 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001199 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001200
Geoff Lang5aad9672014-09-08 11:10:42 -04001201 // begin query
Jamie Madill5188a272018-07-25 10:53:56 -04001202 ANGLE_CONTEXT_TRY(queryObject->begin(this));
Geoff Lang5aad9672014-09-08 11:10:42 -04001203
1204 // set query as active for specified target only if begin succeeded
Jamie Madill4928b7c2017-06-20 12:57:39 -04001205 mGLState.setActiveQuery(this, target, queryObject);
Jamie Madilld84b6732018-09-06 15:54:35 -04001206 mStateCache.onQueryChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001207}
1208
Corentin Wallezad3ae902018-03-09 13:40:42 -05001209void Context::endQuery(QueryType target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001210{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001211 Query *queryObject = mGLState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001212 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001213
Jamie Madill5188a272018-07-25 10:53:56 -04001214 handleError(queryObject->end(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001215
Geoff Lang5aad9672014-09-08 11:10:42 -04001216 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madill4928b7c2017-06-20 12:57:39 -04001217 mGLState.setActiveQuery(this, target, nullptr);
Jamie Madilld84b6732018-09-06 15:54:35 -04001218 mStateCache.onQueryChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001219}
1220
Corentin Wallezad3ae902018-03-09 13:40:42 -05001221void Context::queryCounter(GLuint id, QueryType target)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001222{
Corentin Wallezad3ae902018-03-09 13:40:42 -05001223 ASSERT(target == QueryType::Timestamp);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001224
1225 Query *queryObject = getQuery(id, true, target);
1226 ASSERT(queryObject);
1227
Jamie Madill5188a272018-07-25 10:53:56 -04001228 handleError(queryObject->queryCounter(this));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001229}
1230
Corentin Wallezad3ae902018-03-09 13:40:42 -05001231void Context::getQueryiv(QueryType target, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001232{
1233 switch (pname)
1234 {
1235 case GL_CURRENT_QUERY_EXT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001236 params[0] = mGLState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001237 break;
1238 case GL_QUERY_COUNTER_BITS_EXT:
1239 switch (target)
1240 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001241 case QueryType::TimeElapsed:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001242 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1243 break;
Corentin Wallezad3ae902018-03-09 13:40:42 -05001244 case QueryType::Timestamp:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001245 params[0] = getExtensions().queryCounterBitsTimestamp;
1246 break;
1247 default:
1248 UNREACHABLE();
1249 params[0] = 0;
1250 break;
1251 }
1252 break;
1253 default:
1254 UNREACHABLE();
1255 return;
1256 }
1257}
1258
Corentin Wallezad3ae902018-03-09 13:40:42 -05001259void Context::getQueryivRobust(QueryType target,
Brandon Jones59770802018-04-02 13:18:42 -07001260 GLenum pname,
1261 GLsizei bufSize,
1262 GLsizei *length,
1263 GLint *params)
1264{
1265 getQueryiv(target, pname, params);
1266}
1267
Geoff Lang2186c382016-10-14 10:54:54 -04001268void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001269{
Jamie Madill5188a272018-07-25 10:53:56 -04001270 handleError(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001271}
1272
Brandon Jones59770802018-04-02 13:18:42 -07001273void Context::getQueryObjectivRobust(GLuint id,
1274 GLenum pname,
1275 GLsizei bufSize,
1276 GLsizei *length,
1277 GLint *params)
1278{
1279 getQueryObjectiv(id, pname, params);
1280}
1281
Geoff Lang2186c382016-10-14 10:54:54 -04001282void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001283{
Jamie Madill5188a272018-07-25 10:53:56 -04001284 handleError(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001285}
1286
Brandon Jones59770802018-04-02 13:18:42 -07001287void Context::getQueryObjectuivRobust(GLuint id,
1288 GLenum pname,
1289 GLsizei bufSize,
1290 GLsizei *length,
1291 GLuint *params)
1292{
1293 getQueryObjectuiv(id, pname, params);
1294}
1295
Geoff Lang2186c382016-10-14 10:54:54 -04001296void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001297{
Jamie Madill5188a272018-07-25 10:53:56 -04001298 handleError(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001299}
1300
Brandon Jones59770802018-04-02 13:18:42 -07001301void Context::getQueryObjecti64vRobust(GLuint id,
1302 GLenum pname,
1303 GLsizei bufSize,
1304 GLsizei *length,
1305 GLint64 *params)
1306{
1307 getQueryObjecti64v(id, pname, params);
1308}
1309
Geoff Lang2186c382016-10-14 10:54:54 -04001310void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001311{
Jamie Madill5188a272018-07-25 10:53:56 -04001312 handleError(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001313}
1314
Brandon Jones59770802018-04-02 13:18:42 -07001315void Context::getQueryObjectui64vRobust(GLuint id,
1316 GLenum pname,
1317 GLsizei bufSize,
1318 GLsizei *length,
1319 GLuint64 *params)
1320{
1321 getQueryObjectui64v(id, pname, params);
1322}
1323
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001324Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001325{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001326 return mState.mFramebuffers->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001327}
1328
Jamie Madill2f348d22017-06-05 10:50:59 -04001329FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001330{
Jamie Madill96a483b2017-06-27 16:49:21 -04001331 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001332}
1333
Corentin Wallezad3ae902018-03-09 13:40:42 -05001334Query *Context::getQuery(GLuint handle, bool create, QueryType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001335{
Jamie Madill96a483b2017-06-27 16:49:21 -04001336 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001337 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001338 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001339 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001340
1341 Query *query = mQueryMap.query(handle);
1342 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001343 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001344 ASSERT(type != QueryType::InvalidEnum);
Jamie Madill96a483b2017-06-27 16:49:21 -04001345 query = new Query(mImplementation->createQuery(type), handle);
1346 query->addRef();
1347 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001348 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001349 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001350}
1351
Geoff Lang70d0f492015-12-10 17:45:46 -05001352Query *Context::getQuery(GLuint handle) const
1353{
Jamie Madill96a483b2017-06-27 16:49:21 -04001354 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001355}
1356
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001357Texture *Context::getTargetTexture(TextureType type) const
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001358{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001359 ASSERT(ValidTextureTarget(this, type) || ValidTextureExternalTarget(this, type));
1360 return mGLState.getTargetTexture(type);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001361}
1362
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001363Texture *Context::getSamplerTexture(unsigned int sampler, TextureType type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001364{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001365 return mGLState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001366}
1367
Geoff Lang492a7e42014-11-05 13:27:06 -05001368Compiler *Context::getCompiler() const
1369{
Jamie Madill2f348d22017-06-05 10:50:59 -04001370 if (mCompiler.get() == nullptr)
1371 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001372 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001373 }
1374 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001375}
1376
Jamie Madillc1d770e2017-04-13 17:31:24 -04001377void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001378{
1379 switch (pname)
1380 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001381 case GL_SHADER_COMPILER:
1382 *params = GL_TRUE;
1383 break;
1384 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1385 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1386 break;
1387 default:
1388 mGLState.getBooleanv(pname, params);
1389 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001390 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001391}
1392
Jamie Madillc1d770e2017-04-13 17:31:24 -04001393void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001394{
Shannon Woods53a94a82014-06-24 15:20:36 -04001395 // Queries about context capabilities and maximums are answered by Context.
1396 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001397 switch (pname)
1398 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001399 case GL_ALIASED_LINE_WIDTH_RANGE:
1400 params[0] = mCaps.minAliasedLineWidth;
1401 params[1] = mCaps.maxAliasedLineWidth;
1402 break;
1403 case GL_ALIASED_POINT_SIZE_RANGE:
1404 params[0] = mCaps.minAliasedPointSize;
1405 params[1] = mCaps.maxAliasedPointSize;
1406 break;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07001407 case GL_SMOOTH_POINT_SIZE_RANGE:
1408 params[0] = mCaps.minSmoothPointSize;
1409 params[1] = mCaps.maxSmoothPointSize;
1410 break;
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07001411 case GL_SMOOTH_LINE_WIDTH_RANGE:
1412 params[0] = mCaps.minSmoothLineWidth;
1413 params[1] = mCaps.maxSmoothLineWidth;
1414 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001415 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1416 ASSERT(mExtensions.textureFilterAnisotropic);
1417 *params = mExtensions.maxTextureAnisotropy;
1418 break;
1419 case GL_MAX_TEXTURE_LOD_BIAS:
1420 *params = mCaps.maxLODBias;
1421 break;
1422
1423 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1424 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1425 {
Lingfeng Yang3a41af62018-04-09 07:28:56 -07001426 // GLES1 emulation: // GL_PATH_(MODELVIEW|PROJECTION)_MATRIX_CHROMIUM collides with the
1427 // GLES1 constants for modelview/projection matrix.
1428 if (getClientVersion() < Version(2, 0))
1429 {
1430 mGLState.getFloatv(pname, params);
1431 }
1432 else
1433 {
1434 ASSERT(mExtensions.pathRendering);
1435 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1436 memcpy(params, m, 16 * sizeof(GLfloat));
1437 }
Jamie Madill231c7f52017-04-26 13:45:37 -04001438 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001439 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001440
Jamie Madill231c7f52017-04-26 13:45:37 -04001441 default:
1442 mGLState.getFloatv(pname, params);
1443 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001444 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001445}
1446
Jamie Madillc1d770e2017-04-13 17:31:24 -04001447void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001448{
Shannon Woods53a94a82014-06-24 15:20:36 -04001449 // Queries about context capabilities and maximums are answered by Context.
1450 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001451
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001452 switch (pname)
1453 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001454 case GL_MAX_VERTEX_ATTRIBS:
1455 *params = mCaps.maxVertexAttributes;
1456 break;
1457 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1458 *params = mCaps.maxVertexUniformVectors;
1459 break;
1460 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001461 *params = mCaps.maxShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001462 break;
1463 case GL_MAX_VARYING_VECTORS:
1464 *params = mCaps.maxVaryingVectors;
1465 break;
1466 case GL_MAX_VARYING_COMPONENTS:
1467 *params = mCaps.maxVertexOutputComponents;
1468 break;
1469 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1470 *params = mCaps.maxCombinedTextureImageUnits;
1471 break;
1472 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001473 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001474 break;
1475 case GL_MAX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001476 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001477 break;
1478 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1479 *params = mCaps.maxFragmentUniformVectors;
1480 break;
1481 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001482 *params = mCaps.maxShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001483 break;
1484 case GL_MAX_RENDERBUFFER_SIZE:
1485 *params = mCaps.maxRenderbufferSize;
1486 break;
1487 case GL_MAX_COLOR_ATTACHMENTS_EXT:
1488 *params = mCaps.maxColorAttachments;
1489 break;
1490 case GL_MAX_DRAW_BUFFERS_EXT:
1491 *params = mCaps.maxDrawBuffers;
1492 break;
1493 // case GL_FRAMEBUFFER_BINDING: // now equivalent to
1494 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
1495 case GL_SUBPIXEL_BITS:
1496 *params = 4;
1497 break;
1498 case GL_MAX_TEXTURE_SIZE:
1499 *params = mCaps.max2DTextureSize;
1500 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001501 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
1502 *params = mCaps.maxRectangleTextureSize;
1503 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001504 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1505 *params = mCaps.maxCubeMapTextureSize;
1506 break;
1507 case GL_MAX_3D_TEXTURE_SIZE:
1508 *params = mCaps.max3DTextureSize;
1509 break;
1510 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1511 *params = mCaps.maxArrayTextureLayers;
1512 break;
1513 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1514 *params = mCaps.uniformBufferOffsetAlignment;
1515 break;
1516 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1517 *params = mCaps.maxUniformBufferBindings;
1518 break;
1519 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001520 *params = mCaps.maxShaderUniformBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001521 break;
1522 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001523 *params = mCaps.maxShaderUniformBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001524 break;
1525 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1526 *params = mCaps.maxCombinedTextureImageUnits;
1527 break;
1528 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1529 *params = mCaps.maxVertexOutputComponents;
1530 break;
1531 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1532 *params = mCaps.maxFragmentInputComponents;
1533 break;
1534 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1535 *params = mCaps.minProgramTexelOffset;
1536 break;
1537 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1538 *params = mCaps.maxProgramTexelOffset;
1539 break;
1540 case GL_MAJOR_VERSION:
1541 *params = getClientVersion().major;
1542 break;
1543 case GL_MINOR_VERSION:
1544 *params = getClientVersion().minor;
1545 break;
1546 case GL_MAX_ELEMENTS_INDICES:
1547 *params = mCaps.maxElementsIndices;
1548 break;
1549 case GL_MAX_ELEMENTS_VERTICES:
1550 *params = mCaps.maxElementsVertices;
1551 break;
1552 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1553 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1554 break;
1555 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1556 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1557 break;
1558 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1559 *params = mCaps.maxTransformFeedbackSeparateComponents;
1560 break;
1561 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1562 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1563 break;
1564 case GL_MAX_SAMPLES_ANGLE:
1565 *params = mCaps.maxSamples;
1566 break;
1567 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001568 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001569 params[0] = mCaps.maxViewportWidth;
1570 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001571 }
1572 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001573 case GL_COMPRESSED_TEXTURE_FORMATS:
1574 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1575 params);
1576 break;
1577 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1578 *params = mResetStrategy;
1579 break;
1580 case GL_NUM_SHADER_BINARY_FORMATS:
1581 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1582 break;
1583 case GL_SHADER_BINARY_FORMATS:
1584 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1585 break;
1586 case GL_NUM_PROGRAM_BINARY_FORMATS:
1587 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1588 break;
1589 case GL_PROGRAM_BINARY_FORMATS:
1590 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1591 break;
1592 case GL_NUM_EXTENSIONS:
1593 *params = static_cast<GLint>(mExtensionStrings.size());
1594 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001595
Jamie Madill231c7f52017-04-26 13:45:37 -04001596 // GL_KHR_debug
1597 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1598 *params = mExtensions.maxDebugMessageLength;
1599 break;
1600 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1601 *params = mExtensions.maxDebugLoggedMessages;
1602 break;
1603 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1604 *params = mExtensions.maxDebugGroupStackDepth;
1605 break;
1606 case GL_MAX_LABEL_LENGTH:
1607 *params = mExtensions.maxLabelLength;
1608 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001609
Martin Radeve5285d22017-07-14 16:23:53 +03001610 // GL_ANGLE_multiview
1611 case GL_MAX_VIEWS_ANGLE:
1612 *params = mExtensions.maxViews;
1613 break;
1614
Jamie Madill231c7f52017-04-26 13:45:37 -04001615 // GL_EXT_disjoint_timer_query
1616 case GL_GPU_DISJOINT_EXT:
1617 *params = mImplementation->getGPUDisjoint();
1618 break;
1619 case GL_MAX_FRAMEBUFFER_WIDTH:
1620 *params = mCaps.maxFramebufferWidth;
1621 break;
1622 case GL_MAX_FRAMEBUFFER_HEIGHT:
1623 *params = mCaps.maxFramebufferHeight;
1624 break;
1625 case GL_MAX_FRAMEBUFFER_SAMPLES:
1626 *params = mCaps.maxFramebufferSamples;
1627 break;
1628 case GL_MAX_SAMPLE_MASK_WORDS:
1629 *params = mCaps.maxSampleMaskWords;
1630 break;
1631 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1632 *params = mCaps.maxColorTextureSamples;
1633 break;
1634 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1635 *params = mCaps.maxDepthTextureSamples;
1636 break;
1637 case GL_MAX_INTEGER_SAMPLES:
1638 *params = mCaps.maxIntegerSamples;
1639 break;
1640 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1641 *params = mCaps.maxVertexAttribRelativeOffset;
1642 break;
1643 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1644 *params = mCaps.maxVertexAttribBindings;
1645 break;
1646 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1647 *params = mCaps.maxVertexAttribStride;
1648 break;
1649 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001650 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001651 break;
1652 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001653 *params = mCaps.maxShaderAtomicCounters[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001654 break;
1655 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001656 *params = mCaps.maxShaderImageUniforms[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001657 break;
1658 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001659 *params = mCaps.maxShaderStorageBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001660 break;
1661 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001662 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001663 break;
1664 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001665 *params = mCaps.maxShaderAtomicCounters[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001666 break;
1667 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001668 *params = mCaps.maxShaderImageUniforms[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001669 break;
1670 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001671 *params = mCaps.maxShaderStorageBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001672 break;
1673 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1674 *params = mCaps.minProgramTextureGatherOffset;
1675 break;
1676 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1677 *params = mCaps.maxProgramTextureGatherOffset;
1678 break;
1679 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1680 *params = mCaps.maxComputeWorkGroupInvocations;
1681 break;
1682 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001683 *params = mCaps.maxShaderUniformBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001684 break;
1685 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001686 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001687 break;
1688 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1689 *params = mCaps.maxComputeSharedMemorySize;
1690 break;
1691 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001692 *params = mCaps.maxShaderUniformComponents[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001693 break;
1694 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001695 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001696 break;
1697 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001698 *params = mCaps.maxShaderAtomicCounters[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001699 break;
1700 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001701 *params = mCaps.maxShaderImageUniforms[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001702 break;
1703 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001704 *params =
1705 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Compute]);
Jamie Madill231c7f52017-04-26 13:45:37 -04001706 break;
1707 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001708 *params = mCaps.maxShaderStorageBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001709 break;
1710 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1711 *params = mCaps.maxCombinedShaderOutputResources;
1712 break;
1713 case GL_MAX_UNIFORM_LOCATIONS:
1714 *params = mCaps.maxUniformLocations;
1715 break;
1716 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1717 *params = mCaps.maxAtomicCounterBufferBindings;
1718 break;
1719 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1720 *params = mCaps.maxAtomicCounterBufferSize;
1721 break;
1722 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1723 *params = mCaps.maxCombinedAtomicCounterBuffers;
1724 break;
1725 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1726 *params = mCaps.maxCombinedAtomicCounters;
1727 break;
1728 case GL_MAX_IMAGE_UNITS:
1729 *params = mCaps.maxImageUnits;
1730 break;
1731 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1732 *params = mCaps.maxCombinedImageUniforms;
1733 break;
1734 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1735 *params = mCaps.maxShaderStorageBufferBindings;
1736 break;
1737 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1738 *params = mCaps.maxCombinedShaderStorageBlocks;
1739 break;
1740 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1741 *params = mCaps.shaderStorageBufferOffsetAlignment;
1742 break;
Jiawei Shao361df072017-11-22 09:33:59 +08001743
1744 // GL_EXT_geometry_shader
1745 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
1746 *params = mCaps.maxFramebufferLayers;
1747 break;
1748 case GL_LAYER_PROVOKING_VERTEX_EXT:
1749 *params = mCaps.layerProvokingVertex;
1750 break;
1751 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001752 *params = mCaps.maxShaderUniformComponents[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001753 break;
1754 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001755 *params = mCaps.maxShaderUniformBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001756 break;
1757 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001758 *params =
1759 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Geometry]);
Jiawei Shao361df072017-11-22 09:33:59 +08001760 break;
1761 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
1762 *params = mCaps.maxGeometryInputComponents;
1763 break;
1764 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
1765 *params = mCaps.maxGeometryOutputComponents;
1766 break;
1767 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
1768 *params = mCaps.maxGeometryOutputVertices;
1769 break;
1770 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
1771 *params = mCaps.maxGeometryTotalOutputComponents;
1772 break;
1773 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
1774 *params = mCaps.maxGeometryShaderInvocations;
1775 break;
1776 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001777 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001778 break;
1779 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001780 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001781 break;
1782 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001783 *params = mCaps.maxShaderAtomicCounters[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001784 break;
1785 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001786 *params = mCaps.maxShaderImageUniforms[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001787 break;
1788 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001789 *params = mCaps.maxShaderStorageBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001790 break;
Lingfeng Yang96310cd2018-03-28 11:56:28 -07001791 // GLES1 emulation: Caps queries
1792 case GL_MAX_TEXTURE_UNITS:
1793 *params = mCaps.maxMultitextureUnits;
1794 break;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001795 case GL_MAX_MODELVIEW_STACK_DEPTH:
1796 *params = mCaps.maxModelviewMatrixStackDepth;
1797 break;
1798 case GL_MAX_PROJECTION_STACK_DEPTH:
1799 *params = mCaps.maxProjectionMatrixStackDepth;
1800 break;
1801 case GL_MAX_TEXTURE_STACK_DEPTH:
1802 *params = mCaps.maxTextureMatrixStackDepth;
1803 break;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07001804 case GL_MAX_LIGHTS:
1805 *params = mCaps.maxLights;
1806 break;
Lingfeng Yang060088a2018-05-30 20:40:57 -07001807 case GL_MAX_CLIP_PLANES:
1808 *params = mCaps.maxClipPlanes;
1809 break;
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001810 // GLES1 emulation: Vertex attribute queries
1811 case GL_VERTEX_ARRAY_BUFFER_BINDING:
1812 case GL_NORMAL_ARRAY_BUFFER_BINDING:
1813 case GL_COLOR_ARRAY_BUFFER_BINDING:
1814 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
1815 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
1816 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1817 GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, params);
1818 break;
1819 case GL_VERTEX_ARRAY_STRIDE:
1820 case GL_NORMAL_ARRAY_STRIDE:
1821 case GL_COLOR_ARRAY_STRIDE:
1822 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
1823 case GL_TEXTURE_COORD_ARRAY_STRIDE:
1824 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1825 GL_VERTEX_ATTRIB_ARRAY_STRIDE, params);
1826 break;
1827 case GL_VERTEX_ARRAY_SIZE:
1828 case GL_COLOR_ARRAY_SIZE:
1829 case GL_TEXTURE_COORD_ARRAY_SIZE:
1830 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1831 GL_VERTEX_ATTRIB_ARRAY_SIZE, params);
1832 break;
1833 case GL_VERTEX_ARRAY_TYPE:
1834 case GL_COLOR_ARRAY_TYPE:
1835 case GL_NORMAL_ARRAY_TYPE:
1836 case GL_POINT_SIZE_ARRAY_TYPE_OES:
1837 case GL_TEXTURE_COORD_ARRAY_TYPE:
1838 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1839 GL_VERTEX_ATTRIB_ARRAY_TYPE, params);
1840 break;
1841
jchen1082af6202018-06-22 10:59:52 +08001842 // GL_KHR_parallel_shader_compile
1843 case GL_MAX_SHADER_COMPILER_THREADS_KHR:
1844 *params = mGLState.getMaxShaderCompilerThreads();
1845 break;
1846
Jamie Madill231c7f52017-04-26 13:45:37 -04001847 default:
Jamie Madille98b1b52018-03-08 09:47:23 -05001848 handleError(mGLState.getIntegerv(this, pname, params));
Jamie Madill231c7f52017-04-26 13:45:37 -04001849 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001850 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001851}
1852
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001853void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001854{
Shannon Woods53a94a82014-06-24 15:20:36 -04001855 // Queries about context capabilities and maximums are answered by Context.
1856 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001857 switch (pname)
1858 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001859 case GL_MAX_ELEMENT_INDEX:
1860 *params = mCaps.maxElementIndex;
1861 break;
1862 case GL_MAX_UNIFORM_BLOCK_SIZE:
1863 *params = mCaps.maxUniformBlockSize;
1864 break;
1865 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001866 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001867 break;
1868 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001869 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001870 break;
1871 case GL_MAX_SERVER_WAIT_TIMEOUT:
1872 *params = mCaps.maxServerWaitTimeout;
1873 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001874
Jamie Madill231c7f52017-04-26 13:45:37 -04001875 // GL_EXT_disjoint_timer_query
1876 case GL_TIMESTAMP_EXT:
1877 *params = mImplementation->getTimestamp();
1878 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001879
Jamie Madill231c7f52017-04-26 13:45:37 -04001880 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1881 *params = mCaps.maxShaderStorageBlockSize;
1882 break;
1883 default:
1884 UNREACHABLE();
1885 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001886 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001887}
1888
Geoff Lang70d0f492015-12-10 17:45:46 -05001889void Context::getPointerv(GLenum pname, void **params) const
1890{
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001891 mGLState.getPointerv(this, pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001892}
1893
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001894void Context::getPointervRobustANGLERobust(GLenum pname,
1895 GLsizei bufSize,
1896 GLsizei *length,
1897 void **params)
1898{
1899 UNIMPLEMENTED();
1900}
1901
Martin Radev66fb8202016-07-28 11:45:20 +03001902void Context::getIntegeri_v(GLenum target, GLuint index, GLint *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)
1913 {
1914 switch (target)
1915 {
1916 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1917 ASSERT(index < 3u);
1918 *data = mCaps.maxComputeWorkGroupCount[index];
1919 break;
1920 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1921 ASSERT(index < 3u);
1922 *data = mCaps.maxComputeWorkGroupSize[index];
1923 break;
1924 default:
1925 mGLState.getIntegeri_v(target, index, data);
1926 }
1927 }
1928 else
1929 {
1930 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1931 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001932}
1933
Brandon Jones59770802018-04-02 13:18:42 -07001934void Context::getIntegeri_vRobust(GLenum target,
1935 GLuint index,
1936 GLsizei bufSize,
1937 GLsizei *length,
1938 GLint *data)
1939{
1940 getIntegeri_v(target, index, data);
1941}
1942
Martin Radev66fb8202016-07-28 11:45:20 +03001943void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001944{
Shannon Woods53a94a82014-06-24 15:20:36 -04001945 // Queries about context capabilities and maximums are answered by Context.
1946 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001947
1948 GLenum nativeType;
1949 unsigned int numParams;
1950 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1951 ASSERT(queryStatus);
1952
1953 if (nativeType == GL_INT_64_ANGLEX)
1954 {
1955 mGLState.getInteger64i_v(target, index, data);
1956 }
1957 else
1958 {
1959 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1960 }
1961}
1962
Brandon Jones59770802018-04-02 13:18:42 -07001963void Context::getInteger64i_vRobust(GLenum target,
1964 GLuint index,
1965 GLsizei bufSize,
1966 GLsizei *length,
1967 GLint64 *data)
1968{
1969 getInteger64i_v(target, index, data);
1970}
1971
Martin Radev66fb8202016-07-28 11:45:20 +03001972void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1973{
1974 // Queries about context capabilities and maximums are answered by Context.
1975 // Queries about current GL state values are answered by State.
1976
1977 GLenum nativeType;
1978 unsigned int numParams;
1979 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1980 ASSERT(queryStatus);
1981
1982 if (nativeType == GL_BOOL)
1983 {
1984 mGLState.getBooleani_v(target, index, data);
1985 }
1986 else
1987 {
1988 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1989 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001990}
1991
Brandon Jones59770802018-04-02 13:18:42 -07001992void Context::getBooleani_vRobust(GLenum target,
1993 GLuint index,
1994 GLsizei bufSize,
1995 GLsizei *length,
1996 GLboolean *data)
1997{
1998 getBooleani_v(target, index, data);
1999}
2000
Corentin Wallez336129f2017-10-17 15:55:40 -04002001void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002002{
2003 Buffer *buffer = mGLState.getTargetBuffer(target);
2004 QueryBufferParameteriv(buffer, pname, params);
2005}
2006
Brandon Jones59770802018-04-02 13:18:42 -07002007void Context::getBufferParameterivRobust(BufferBinding target,
2008 GLenum pname,
2009 GLsizei bufSize,
2010 GLsizei *length,
2011 GLint *params)
2012{
2013 getBufferParameteriv(target, pname, params);
2014}
2015
He Yunchao010e4db2017-03-03 14:22:06 +08002016void Context::getFramebufferAttachmentParameteriv(GLenum target,
2017 GLenum attachment,
2018 GLenum pname,
2019 GLint *params)
2020{
2021 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002022 QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08002023}
2024
Brandon Jones59770802018-04-02 13:18:42 -07002025void Context::getFramebufferAttachmentParameterivRobust(GLenum target,
2026 GLenum attachment,
2027 GLenum pname,
2028 GLsizei bufSize,
2029 GLsizei *length,
2030 GLint *params)
2031{
2032 getFramebufferAttachmentParameteriv(target, attachment, pname, params);
2033}
2034
He Yunchao010e4db2017-03-03 14:22:06 +08002035void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
2036{
2037 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
2038 QueryRenderbufferiv(this, renderbuffer, pname, params);
2039}
2040
Brandon Jones59770802018-04-02 13:18:42 -07002041void Context::getRenderbufferParameterivRobust(GLenum target,
2042 GLenum pname,
2043 GLsizei bufSize,
2044 GLsizei *length,
2045 GLint *params)
2046{
2047 getRenderbufferParameteriv(target, pname, params);
2048}
2049
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002050void Context::getTexParameterfv(TextureType target, GLenum pname, GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002051{
2052 Texture *texture = getTargetTexture(target);
2053 QueryTexParameterfv(texture, pname, params);
2054}
2055
Brandon Jones59770802018-04-02 13:18:42 -07002056void Context::getTexParameterfvRobust(TextureType target,
2057 GLenum pname,
2058 GLsizei bufSize,
2059 GLsizei *length,
2060 GLfloat *params)
2061{
2062 getTexParameterfv(target, pname, params);
2063}
2064
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002065void Context::getTexParameteriv(TextureType target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002066{
2067 Texture *texture = getTargetTexture(target);
2068 QueryTexParameteriv(texture, pname, params);
2069}
Jiajia Qin5451d532017-11-16 17:16:34 +08002070
Brandon Jones59770802018-04-02 13:18:42 -07002071void Context::getTexParameterivRobust(TextureType target,
2072 GLenum pname,
2073 GLsizei bufSize,
2074 GLsizei *length,
2075 GLint *params)
2076{
2077 getTexParameteriv(target, pname, params);
2078}
2079
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002080void Context::getTexParameterIivRobust(TextureType target,
2081 GLenum pname,
2082 GLsizei bufSize,
2083 GLsizei *length,
2084 GLint *params)
2085{
2086 UNIMPLEMENTED();
2087}
2088
2089void Context::getTexParameterIuivRobust(TextureType target,
2090 GLenum pname,
2091 GLsizei bufSize,
2092 GLsizei *length,
2093 GLuint *params)
2094{
2095 UNIMPLEMENTED();
2096}
2097
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002098void Context::getTexLevelParameteriv(TextureTarget target, GLint level, GLenum pname, GLint *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002099{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002100 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002101 QueryTexLevelParameteriv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002102}
2103
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002104void Context::getTexLevelParameterivRobust(TextureTarget target,
2105 GLint level,
2106 GLenum pname,
2107 GLsizei bufSize,
2108 GLsizei *length,
2109 GLint *params)
2110{
2111 UNIMPLEMENTED();
2112}
2113
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002114void Context::getTexLevelParameterfv(TextureTarget target,
2115 GLint level,
2116 GLenum pname,
2117 GLfloat *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002118{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002119 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002120 QueryTexLevelParameterfv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002121}
2122
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002123void Context::getTexLevelParameterfvRobust(TextureTarget target,
2124 GLint level,
2125 GLenum pname,
2126 GLsizei bufSize,
2127 GLsizei *length,
2128 GLfloat *params)
2129{
2130 UNIMPLEMENTED();
2131}
2132
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002133void Context::texParameterf(TextureType target, GLenum pname, GLfloat param)
He Yunchao010e4db2017-03-03 14:22:06 +08002134{
2135 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002136 SetTexParameterf(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002137 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002138}
2139
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002140void Context::texParameterfv(TextureType target, GLenum pname, const GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002141{
2142 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002143 SetTexParameterfv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002144 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002145}
2146
Brandon Jones59770802018-04-02 13:18:42 -07002147void Context::texParameterfvRobust(TextureType target,
2148 GLenum pname,
2149 GLsizei bufSize,
2150 const GLfloat *params)
2151{
2152 texParameterfv(target, pname, params);
2153}
2154
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002155void Context::texParameteri(TextureType target, GLenum pname, GLint param)
He Yunchao010e4db2017-03-03 14:22:06 +08002156{
2157 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002158 SetTexParameteri(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002159 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002160}
2161
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002162void Context::texParameteriv(TextureType target, GLenum pname, const GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002163{
2164 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002165 SetTexParameteriv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002166 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002167}
2168
Brandon Jones59770802018-04-02 13:18:42 -07002169void Context::texParameterivRobust(TextureType target,
2170 GLenum pname,
2171 GLsizei bufSize,
2172 const GLint *params)
2173{
2174 texParameteriv(target, pname, params);
2175}
2176
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002177void Context::texParameterIivRobust(TextureType target,
2178 GLenum pname,
2179 GLsizei bufSize,
2180 const GLint *params)
2181{
2182 UNIMPLEMENTED();
2183}
2184
2185void Context::texParameterIuivRobust(TextureType target,
2186 GLenum pname,
2187 GLsizei bufSize,
2188 const GLuint *params)
2189{
2190 UNIMPLEMENTED();
2191}
2192
Jamie Madill493f9572018-05-24 19:52:15 -04002193void Context::drawArrays(PrimitiveMode mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002194{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002195 // No-op if count draws no primitives for given mode
2196 if (noopDraw(mode, count))
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(mImplementation->drawArrays(this, mode, first, count));
Jamie Madill09463932018-04-04 05:26:59 -04002203 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count, 1);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002204}
2205
Jamie Madill493f9572018-05-24 19:52:15 -04002206void Context::drawArraysInstanced(PrimitiveMode mode,
2207 GLint first,
2208 GLsizei count,
2209 GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04002210{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002211 // No-op if count draws no primitives for given mode
2212 if (noopDrawInstanced(mode, count, instanceCount))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002213 {
2214 return;
2215 }
2216
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002217 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002218 ANGLE_CONTEXT_TRY(
2219 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
Jamie Madill09463932018-04-04 05:26:59 -04002220 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count,
2221 instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -04002222}
2223
Jamie Madill493f9572018-05-24 19:52:15 -04002224void Context::drawElements(PrimitiveMode mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002225{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002226 // No-op if count draws no primitives for given mode
2227 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002228 {
2229 return;
2230 }
2231
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->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04002234}
2235
Jamie Madill493f9572018-05-24 19:52:15 -04002236void Context::drawElementsInstanced(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002237 GLsizei count,
2238 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002239 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04002240 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04002241{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002242 // No-op if count draws no primitives for given mode
2243 if (noopDrawInstanced(mode, count, instances))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002244 {
2245 return;
2246 }
2247
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002248 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002249 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08002250 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04002251}
2252
Jamie Madill493f9572018-05-24 19:52:15 -04002253void Context::drawRangeElements(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002254 GLuint start,
2255 GLuint end,
2256 GLsizei count,
2257 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002258 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04002259{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002260 // No-op if count draws no primitives for given mode
2261 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002262 {
2263 return;
2264 }
2265
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002266 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002267 ANGLE_CONTEXT_TRY(
2268 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002269}
2270
Jamie Madill493f9572018-05-24 19:52:15 -04002271void Context::drawArraysIndirect(PrimitiveMode mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002272{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002273 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002274 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002275}
2276
Jamie Madill493f9572018-05-24 19:52:15 -04002277void Context::drawElementsIndirect(PrimitiveMode mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002278{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002279 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002280 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002281}
2282
Jamie Madill675fe712016-12-19 13:07:54 -05002283void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002284{
Jamie Madillafa02a22017-11-23 12:57:38 -05002285 handleError(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05002286}
2287
Jamie Madill675fe712016-12-19 13:07:54 -05002288void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05002289{
Jamie Madillafa02a22017-11-23 12:57:38 -05002290 handleError(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002291}
2292
Austin Kinross6ee1e782015-05-29 17:05:37 -07002293void Context::insertEventMarker(GLsizei length, const char *marker)
2294{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002295 ASSERT(mImplementation);
2296 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07002297}
2298
2299void Context::pushGroupMarker(GLsizei length, const char *marker)
2300{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002301 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05002302
2303 if (marker == nullptr)
2304 {
2305 // From the EXT_debug_marker spec,
2306 // "If <marker> is null then an empty string is pushed on the stack."
2307 mImplementation->pushGroupMarker(length, "");
2308 }
2309 else
2310 {
2311 mImplementation->pushGroupMarker(length, marker);
2312 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07002313}
2314
2315void Context::popGroupMarker()
2316{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002317 ASSERT(mImplementation);
2318 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07002319}
2320
Geoff Langd8605522016-04-13 10:19:12 -04002321void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
2322{
2323 Program *programObject = getProgram(program);
2324 ASSERT(programObject);
2325
2326 programObject->bindUniformLocation(location, name);
2327}
2328
Brandon Jones59770802018-04-02 13:18:42 -07002329void Context::coverageModulation(GLenum components)
Sami Väisänena797e062016-05-12 15:23:40 +03002330{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002331 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03002332}
2333
Brandon Jones59770802018-04-02 13:18:42 -07002334void Context::matrixLoadf(GLenum matrixMode, const GLfloat *matrix)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002335{
2336 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
2337}
2338
Brandon Jones59770802018-04-02 13:18:42 -07002339void Context::matrixLoadIdentity(GLenum matrixMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002340{
2341 GLfloat I[16];
2342 angle::Matrix<GLfloat>::setToIdentity(I);
2343
2344 mGLState.loadPathRenderingMatrix(matrixMode, I);
2345}
2346
2347void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
2348{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002349 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002350 if (!pathObj)
2351 return;
2352
Geoff Lang9bf86f02018-07-26 11:46:34 -04002353 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002354
2355 mImplementation->stencilFillPath(pathObj, fillMode, mask);
2356}
2357
2358void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
2359{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002360 const auto *pathObj = mState.mPaths->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->stencilStrokePath(pathObj, reference, mask);
2367}
2368
2369void Context::coverFillPath(GLuint path, GLenum coverMode)
2370{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002371 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002372 if (!pathObj)
2373 return;
2374
Geoff Lang9bf86f02018-07-26 11:46:34 -04002375 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002376
2377 mImplementation->coverFillPath(pathObj, coverMode);
2378}
2379
2380void Context::coverStrokePath(GLuint path, GLenum coverMode)
2381{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002382 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002383 if (!pathObj)
2384 return;
2385
Geoff Lang9bf86f02018-07-26 11:46:34 -04002386 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002387
2388 mImplementation->coverStrokePath(pathObj, coverMode);
2389}
2390
2391void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
2392{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002393 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002394 if (!pathObj)
2395 return;
2396
Geoff Lang9bf86f02018-07-26 11:46:34 -04002397 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002398
2399 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
2400}
2401
2402void Context::stencilThenCoverStrokePath(GLuint path,
2403 GLint reference,
2404 GLuint mask,
2405 GLenum coverMode)
2406{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002407 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002408 if (!pathObj)
2409 return;
2410
Geoff Lang9bf86f02018-07-26 11:46:34 -04002411 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002412
2413 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2414}
2415
Sami Väisänend59ca052016-06-21 16:10:00 +03002416void Context::coverFillPathInstanced(GLsizei numPaths,
2417 GLenum pathNameType,
2418 const void *paths,
2419 GLuint pathBase,
2420 GLenum coverMode,
2421 GLenum transformType,
2422 const GLfloat *transformValues)
2423{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002424 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002425
Geoff Lang9bf86f02018-07-26 11:46:34 -04002426 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002427
2428 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2429}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002430
Sami Väisänend59ca052016-06-21 16:10:00 +03002431void Context::coverStrokePathInstanced(GLsizei numPaths,
2432 GLenum pathNameType,
2433 const void *paths,
2434 GLuint pathBase,
2435 GLenum coverMode,
2436 GLenum transformType,
2437 const GLfloat *transformValues)
2438{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002439 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002440
2441 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Lang9bf86f02018-07-26 11:46:34 -04002442 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002443
2444 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2445 transformValues);
2446}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002447
Sami Väisänend59ca052016-06-21 16:10:00 +03002448void Context::stencilFillPathInstanced(GLsizei numPaths,
2449 GLenum pathNameType,
2450 const void *paths,
2451 GLuint pathBase,
2452 GLenum fillMode,
2453 GLuint mask,
2454 GLenum transformType,
2455 const GLfloat *transformValues)
2456{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002457 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002458
2459 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Lang9bf86f02018-07-26 11:46:34 -04002460 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002461
2462 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2463 transformValues);
2464}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002465
Sami Väisänend59ca052016-06-21 16:10:00 +03002466void Context::stencilStrokePathInstanced(GLsizei numPaths,
2467 GLenum pathNameType,
2468 const void *paths,
2469 GLuint pathBase,
2470 GLint reference,
2471 GLuint mask,
2472 GLenum transformType,
2473 const GLfloat *transformValues)
2474{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002475 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002476
Geoff Lang9bf86f02018-07-26 11:46:34 -04002477 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002478
2479 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2480 transformValues);
2481}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002482
Sami Väisänend59ca052016-06-21 16:10:00 +03002483void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2484 GLenum pathNameType,
2485 const void *paths,
2486 GLuint pathBase,
2487 GLenum fillMode,
2488 GLuint mask,
2489 GLenum coverMode,
2490 GLenum transformType,
2491 const GLfloat *transformValues)
2492{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002493 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002494
Geoff Lang9bf86f02018-07-26 11:46:34 -04002495 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002496
2497 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2498 transformType, transformValues);
2499}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002500
Sami Väisänend59ca052016-06-21 16:10:00 +03002501void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2502 GLenum pathNameType,
2503 const void *paths,
2504 GLuint pathBase,
2505 GLint reference,
2506 GLuint mask,
2507 GLenum coverMode,
2508 GLenum transformType,
2509 const GLfloat *transformValues)
2510{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002511 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002512
Geoff Lang9bf86f02018-07-26 11:46:34 -04002513 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002514
2515 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2516 transformType, transformValues);
2517}
2518
Sami Väisänen46eaa942016-06-29 10:26:37 +03002519void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2520{
2521 auto *programObject = getProgram(program);
2522
2523 programObject->bindFragmentInputLocation(location, name);
2524}
2525
2526void Context::programPathFragmentInputGen(GLuint program,
2527 GLint location,
2528 GLenum genMode,
2529 GLint components,
2530 const GLfloat *coeffs)
2531{
2532 auto *programObject = getProgram(program);
2533
jchen103fd614d2018-08-13 12:21:58 +08002534 programObject->pathFragmentInputGen(location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002535}
2536
jchen1015015f72017-03-16 13:54:21 +08002537GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2538{
jchen10fd7c3b52017-03-21 15:36:03 +08002539 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002540 return QueryProgramResourceIndex(programObject, programInterface, name);
2541}
2542
jchen10fd7c3b52017-03-21 15:36:03 +08002543void Context::getProgramResourceName(GLuint program,
2544 GLenum programInterface,
2545 GLuint index,
2546 GLsizei bufSize,
2547 GLsizei *length,
2548 GLchar *name)
2549{
2550 const auto *programObject = getProgram(program);
2551 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2552}
2553
jchen10191381f2017-04-11 13:59:04 +08002554GLint Context::getProgramResourceLocation(GLuint program,
2555 GLenum programInterface,
2556 const GLchar *name)
2557{
2558 const auto *programObject = getProgram(program);
2559 return QueryProgramResourceLocation(programObject, programInterface, name);
2560}
2561
jchen10880683b2017-04-12 16:21:55 +08002562void Context::getProgramResourceiv(GLuint program,
2563 GLenum programInterface,
2564 GLuint index,
2565 GLsizei propCount,
2566 const GLenum *props,
2567 GLsizei bufSize,
2568 GLsizei *length,
2569 GLint *params)
2570{
2571 const auto *programObject = getProgram(program);
2572 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2573 length, params);
2574}
2575
jchen10d9cd7b72017-08-30 15:04:25 +08002576void Context::getProgramInterfaceiv(GLuint program,
2577 GLenum programInterface,
2578 GLenum pname,
2579 GLint *params)
2580{
2581 const auto *programObject = getProgram(program);
2582 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2583}
2584
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002585void Context::getProgramInterfaceivRobust(GLuint program,
2586 GLenum programInterface,
2587 GLenum pname,
2588 GLsizei bufSize,
2589 GLsizei *length,
2590 GLint *params)
2591{
2592 UNIMPLEMENTED();
2593}
2594
Jamie Madill306b6c12018-07-27 08:12:49 -04002595void Context::handleError(const Error &error) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002596{
Jamie Madill6b873dd2018-07-12 23:56:30 -04002597 mErrors.handleError(error);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002598}
2599
2600// Get one of the recorded errors and clear its flag, if any.
2601// [OpenGL ES 2.0.24] section 2.5 page 13.
2602GLenum Context::getError()
2603{
Geoff Langda5777c2014-07-11 09:52:58 -04002604 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002605 {
Geoff Langda5777c2014-07-11 09:52:58 -04002606 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002607 }
Geoff Langda5777c2014-07-11 09:52:58 -04002608 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002609 {
Jamie Madill6b873dd2018-07-12 23:56:30 -04002610 return mErrors.popError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002611 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002612}
2613
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002614// NOTE: this function should not assume that this context is current!
Jamie Madill6b873dd2018-07-12 23:56:30 -04002615void Context::markContextLost()
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002616{
2617 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002618 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002619 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002620 mContextLostForced = true;
2621 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002622 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002623}
2624
Jamie Madill427064d2018-04-13 16:20:34 -04002625bool Context::isContextLost() const
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002626{
2627 return mContextLost;
2628}
2629
Jamie Madillfa920eb2018-01-04 11:45:50 -05002630GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002631{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002632 // Even if the application doesn't want to know about resets, we want to know
2633 // as it will allow us to skip all the calls.
2634 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002635 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002636 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002637 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002638 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002639 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002640
2641 // EXT_robustness, section 2.6: If the reset notification behavior is
2642 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2643 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2644 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002645 }
2646
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002647 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2648 // status should be returned at least once, and GL_NO_ERROR should be returned
2649 // once the device has finished resetting.
2650 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002651 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002652 ASSERT(mResetStatus == GL_NO_ERROR);
2653 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002654
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002655 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002656 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002657 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002658 }
2659 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002660 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002661 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002662 // If markContextLost was used to mark the context lost then
2663 // assume that is not recoverable, and continue to report the
2664 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002665 mResetStatus = mImplementation->getResetStatus();
2666 }
Jamie Madill893ab082014-05-16 16:56:10 -04002667
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002668 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002669}
2670
2671bool Context::isResetNotificationEnabled()
2672{
2673 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2674}
2675
Corentin Walleze3b10e82015-05-20 11:06:25 -04002676const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002677{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002678 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002679}
2680
2681EGLenum Context::getClientType() const
2682{
2683 return mClientType;
2684}
2685
2686EGLenum Context::getRenderBuffer() const
2687{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002688 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2689 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002690 {
2691 return EGL_NONE;
2692 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002693
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002694 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002695 ASSERT(backAttachment != nullptr);
2696 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002697}
2698
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002699VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002700{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002701 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002702 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2703 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002704 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002705 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2706 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002707
Jamie Madill96a483b2017-06-27 16:49:21 -04002708 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002709 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002710
2711 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002712}
2713
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002714TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002715{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002716 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002717 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2718 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002719 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002720 transformFeedback =
2721 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002722 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002723 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002724 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002725
2726 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002727}
2728
2729bool Context::isVertexArrayGenerated(GLuint vertexArray)
2730{
Jamie Madill96a483b2017-06-27 16:49:21 -04002731 ASSERT(mVertexArrayMap.contains(0));
2732 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002733}
2734
2735bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2736{
Jamie Madill96a483b2017-06-27 16:49:21 -04002737 ASSERT(mTransformFeedbackMap.contains(0));
2738 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002739}
2740
Shannon Woods53a94a82014-06-24 15:20:36 -04002741void Context::detachTexture(GLuint texture)
2742{
2743 // Simple pass-through to State's detachTexture method, as textures do not require
2744 // allocation map management either here or in the resource manager at detach time.
2745 // Zero textures are held by the Context, and we don't attempt to request them from
2746 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002747 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002748}
2749
James Darpinian4d9d4832018-03-13 12:43:28 -07002750void Context::detachBuffer(Buffer *buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002751{
Yuly Novikov5807a532015-12-03 13:01:22 -05002752 // Simple pass-through to State's detachBuffer method, since
2753 // only buffer attachments to container objects that are bound to the current context
2754 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002755
Yuly Novikov5807a532015-12-03 13:01:22 -05002756 // [OpenGL ES 3.2] section 5.1.2 page 45:
2757 // Attachments to unbound container objects, such as
2758 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2759 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002760 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002761}
2762
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002763void Context::detachFramebuffer(GLuint framebuffer)
2764{
Shannon Woods53a94a82014-06-24 15:20:36 -04002765 // Framebuffer detachment is handled by Context, because 0 is a valid
2766 // Framebuffer object, and a pointer to it must be passed from Context
2767 // to State at binding time.
2768
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002769 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002770 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2771 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2772 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002773
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002774 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002775 {
2776 bindReadFramebuffer(0);
2777 }
2778
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002779 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002780 {
2781 bindDrawFramebuffer(0);
2782 }
2783}
2784
2785void Context::detachRenderbuffer(GLuint renderbuffer)
2786{
Jamie Madilla02315b2017-02-23 14:14:47 -05002787 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002788}
2789
Jamie Madill57a89722013-07-02 11:57:03 -04002790void Context::detachVertexArray(GLuint vertexArray)
2791{
Jamie Madill77a72f62015-04-14 11:18:32 -04002792 // Vertex array detachment is handled by Context, because 0 is a valid
2793 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002794 // binding time.
2795
Jamie Madill57a89722013-07-02 11:57:03 -04002796 // [OpenGL ES 3.0.2] section 2.10 page 43:
2797 // If a vertex array object that is currently bound is deleted, the binding
2798 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madill7267aa62018-04-17 15:28:21 -04002799 if (mGLState.removeVertexArrayBinding(this, vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002800 {
2801 bindVertexArray(0);
2802 }
2803}
2804
Geoff Langc8058452014-02-03 12:04:11 -05002805void Context::detachTransformFeedback(GLuint transformFeedback)
2806{
Corentin Walleza2257da2016-04-19 16:43:12 -04002807 // Transform feedback detachment is handled by Context, because 0 is a valid
2808 // transform feedback, and a pointer to it must be passed from Context to State at
2809 // binding time.
2810
2811 // The OpenGL specification doesn't mention what should happen when the currently bound
2812 // transform feedback object is deleted. Since it is a container object, we treat it like
2813 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002814 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002815 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002816 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002817 }
Geoff Langc8058452014-02-03 12:04:11 -05002818}
2819
Jamie Madilldc356042013-07-19 16:36:57 -04002820void Context::detachSampler(GLuint sampler)
2821{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002822 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002823}
2824
Yunchao Hea336b902017-08-02 16:05:21 +08002825void Context::detachProgramPipeline(GLuint pipeline)
2826{
2827 mGLState.detachProgramPipeline(this, pipeline);
2828}
2829
Jamie Madill3ef140a2017-08-26 23:11:21 -04002830void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002831{
Shaodde78e82017-05-22 14:13:27 +08002832 mGLState.setVertexAttribDivisor(this, index, divisor);
Jamie Madillc43cdad2018-08-08 15:49:25 -04002833 mStateCache.onVertexArrayStateChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002834}
2835
Jamie Madille29d1672013-07-19 16:36:57 -04002836void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2837{
Geoff Langc1984ed2016-10-07 12:41:00 -04002838 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002839 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002840 SetSamplerParameteri(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002841 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002842}
Jamie Madille29d1672013-07-19 16:36:57 -04002843
Geoff Langc1984ed2016-10-07 12:41:00 -04002844void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2845{
2846 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002847 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002848 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002849 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002850}
2851
Brandon Jones59770802018-04-02 13:18:42 -07002852void Context::samplerParameterivRobust(GLuint sampler,
2853 GLenum pname,
2854 GLsizei bufSize,
2855 const GLint *param)
2856{
2857 samplerParameteriv(sampler, pname, param);
2858}
2859
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002860void Context::samplerParameterIivRobust(GLuint sampler,
2861 GLenum pname,
2862 GLsizei bufSize,
2863 const GLint *param)
2864{
2865 UNIMPLEMENTED();
2866}
2867
2868void Context::samplerParameterIuivRobust(GLuint sampler,
2869 GLenum pname,
2870 GLsizei bufSize,
2871 const GLuint *param)
2872{
2873 UNIMPLEMENTED();
2874}
2875
Jamie Madille29d1672013-07-19 16:36:57 -04002876void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2877{
Geoff Langc1984ed2016-10-07 12:41:00 -04002878 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002879 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002880 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002881 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002882}
2883
Geoff Langc1984ed2016-10-07 12:41:00 -04002884void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002885{
Geoff Langc1984ed2016-10-07 12:41:00 -04002886 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002887 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002888 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002889 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002890}
2891
Brandon Jones59770802018-04-02 13:18:42 -07002892void Context::samplerParameterfvRobust(GLuint sampler,
2893 GLenum pname,
2894 GLsizei bufSize,
2895 const GLfloat *param)
2896{
2897 samplerParameterfv(sampler, pname, param);
2898}
2899
Geoff Langc1984ed2016-10-07 12:41:00 -04002900void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002901{
Geoff Langc1984ed2016-10-07 12:41:00 -04002902 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002903 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002904 QuerySamplerParameteriv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002905 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002906}
Jamie Madill9675b802013-07-19 16:36:59 -04002907
Brandon Jones59770802018-04-02 13:18:42 -07002908void Context::getSamplerParameterivRobust(GLuint sampler,
2909 GLenum pname,
2910 GLsizei bufSize,
2911 GLsizei *length,
2912 GLint *params)
2913{
2914 getSamplerParameteriv(sampler, pname, params);
2915}
2916
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002917void Context::getSamplerParameterIivRobust(GLuint sampler,
2918 GLenum pname,
2919 GLsizei bufSize,
2920 GLsizei *length,
2921 GLint *params)
2922{
2923 UNIMPLEMENTED();
2924}
2925
2926void Context::getSamplerParameterIuivRobust(GLuint sampler,
2927 GLenum pname,
2928 GLsizei bufSize,
2929 GLsizei *length,
2930 GLuint *params)
2931{
2932 UNIMPLEMENTED();
2933}
2934
Geoff Langc1984ed2016-10-07 12:41:00 -04002935void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2936{
2937 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002938 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002939 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002940 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002941}
2942
Brandon Jones59770802018-04-02 13:18:42 -07002943void Context::getSamplerParameterfvRobust(GLuint sampler,
2944 GLenum pname,
2945 GLsizei bufSize,
2946 GLsizei *length,
2947 GLfloat *params)
2948{
2949 getSamplerParameterfv(sampler, pname, params);
2950}
2951
Olli Etuahof0fee072016-03-30 15:11:58 +03002952void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2953{
2954 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002955 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002956}
2957
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002958void Context::initRendererString()
2959{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002960 std::ostringstream rendererString;
2961 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002962 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002963 rendererString << ")";
2964
Geoff Langcec35902014-04-16 10:52:36 -04002965 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002966}
2967
Geoff Langc339c4e2016-11-29 10:37:36 -05002968void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002969{
Geoff Langc339c4e2016-11-29 10:37:36 -05002970 const Version &clientVersion = getClientVersion();
2971
2972 std::ostringstream versionString;
2973 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2974 << ANGLE_VERSION_STRING << ")";
2975 mVersionString = MakeStaticString(versionString.str());
2976
2977 std::ostringstream shadingLanguageVersionString;
2978 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2979 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2980 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2981 << ")";
2982 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002983}
2984
Geoff Langcec35902014-04-16 10:52:36 -04002985void Context::initExtensionStrings()
2986{
Geoff Langc339c4e2016-11-29 10:37:36 -05002987 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2988 std::ostringstream combinedStringStream;
2989 std::copy(strings.begin(), strings.end(),
2990 std::ostream_iterator<const char *>(combinedStringStream, " "));
2991 return MakeStaticString(combinedStringStream.str());
2992 };
2993
2994 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002995 for (const auto &extensionString : mExtensions.getStrings())
2996 {
2997 mExtensionStrings.push_back(MakeStaticString(extensionString));
2998 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002999 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04003000
Geoff Langc339c4e2016-11-29 10:37:36 -05003001 mRequestableExtensionStrings.clear();
3002 for (const auto &extensionInfo : GetExtensionInfoMap())
3003 {
3004 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08003005 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
Geoff Langb0f917f2017-12-05 13:41:54 -05003006 mSupportedExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05003007 {
3008 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
3009 }
3010 }
3011 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04003012}
3013
Geoff Langc339c4e2016-11-29 10:37:36 -05003014const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04003015{
Geoff Langc339c4e2016-11-29 10:37:36 -05003016 switch (name)
3017 {
3018 case GL_VENDOR:
3019 return reinterpret_cast<const GLubyte *>("Google Inc.");
3020
3021 case GL_RENDERER:
3022 return reinterpret_cast<const GLubyte *>(mRendererString);
3023
3024 case GL_VERSION:
3025 return reinterpret_cast<const GLubyte *>(mVersionString);
3026
3027 case GL_SHADING_LANGUAGE_VERSION:
3028 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
3029
3030 case GL_EXTENSIONS:
3031 return reinterpret_cast<const GLubyte *>(mExtensionString);
3032
3033 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
3034 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
3035
3036 default:
3037 UNREACHABLE();
3038 return nullptr;
3039 }
Geoff Langcec35902014-04-16 10:52:36 -04003040}
3041
Geoff Langc339c4e2016-11-29 10:37:36 -05003042const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04003043{
Geoff Langc339c4e2016-11-29 10:37:36 -05003044 switch (name)
3045 {
3046 case GL_EXTENSIONS:
3047 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
3048
3049 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
3050 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
3051
3052 default:
3053 UNREACHABLE();
3054 return nullptr;
3055 }
Geoff Langcec35902014-04-16 10:52:36 -04003056}
3057
3058size_t Context::getExtensionStringCount() const
3059{
3060 return mExtensionStrings.size();
3061}
3062
Geoff Lang111a99e2017-10-17 10:58:41 -04003063bool Context::isExtensionRequestable(const char *name)
3064{
3065 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3066 auto extension = extensionInfos.find(name);
3067
Geoff Lang111a99e2017-10-17 10:58:41 -04003068 return extension != extensionInfos.end() && extension->second.Requestable &&
Geoff Langb0f917f2017-12-05 13:41:54 -05003069 mSupportedExtensions.*(extension->second.ExtensionsMember);
Geoff Lang111a99e2017-10-17 10:58:41 -04003070}
3071
Geoff Langc339c4e2016-11-29 10:37:36 -05003072void Context::requestExtension(const char *name)
3073{
3074 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3075 ASSERT(extensionInfos.find(name) != extensionInfos.end());
3076 const auto &extension = extensionInfos.at(name);
3077 ASSERT(extension.Requestable);
Geoff Langb0f917f2017-12-05 13:41:54 -05003078 ASSERT(isExtensionRequestable(name));
Geoff Langc339c4e2016-11-29 10:37:36 -05003079
3080 if (mExtensions.*(extension.ExtensionsMember))
3081 {
3082 // Extension already enabled
3083 return;
3084 }
3085
3086 mExtensions.*(extension.ExtensionsMember) = true;
3087 updateCaps();
3088 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08003089
Jamie Madill2f348d22017-06-05 10:50:59 -04003090 // Release the shader compiler so it will be re-created with the requested extensions enabled.
3091 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04003092
Jamie Madill81c2e252017-09-09 23:32:46 -04003093 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
3094 // sampleable.
Jamie Madilld4442552018-02-27 22:03:47 -05003095 mState.mTextures->signalAllTexturesDirty(this);
Geoff Lang9aded172017-04-05 11:07:56 -04003096 for (auto &zeroTexture : mZeroTextures)
3097 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003098 if (zeroTexture.get() != nullptr)
3099 {
3100 zeroTexture->signalDirty(this, InitState::Initialized);
3101 }
Geoff Lang9aded172017-04-05 11:07:56 -04003102 }
3103
Jamie Madillb983a4b2018-08-01 11:34:51 -04003104 mState.mFramebuffers->invalidateFramebufferComplenessCache(this);
Geoff Langc339c4e2016-11-29 10:37:36 -05003105}
3106
3107size_t Context::getRequestableExtensionStringCount() const
3108{
3109 return mRequestableExtensionStrings.size();
3110}
3111
Jamie Madill493f9572018-05-24 19:52:15 -04003112void Context::beginTransformFeedback(PrimitiveMode primitiveMode)
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003113{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003114 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003115 ASSERT(transformFeedback != nullptr);
3116 ASSERT(!transformFeedback->isPaused());
3117
Jamie Madill6c1f6712017-02-14 19:08:04 -05003118 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Jamie Madilld84b6732018-09-06 15:54:35 -04003119 mStateCache.onTransformFeedbackChange(this);
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003120}
3121
3122bool Context::hasActiveTransformFeedback(GLuint program) const
3123{
3124 for (auto pair : mTransformFeedbackMap)
3125 {
3126 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
3127 {
3128 return true;
3129 }
3130 }
3131 return false;
3132}
3133
Geoff Lang33f11fb2018-05-07 13:42:47 -04003134Extensions Context::generateSupportedExtensions() const
Geoff Langb0f917f2017-12-05 13:41:54 -05003135{
3136 Extensions supportedExtensions = mImplementation->getNativeExtensions();
3137
jchen1082af6202018-06-22 10:59:52 +08003138 // Explicitly enable GL_KHR_parallel_shader_compile
3139 supportedExtensions.parallelShaderCompile = true;
3140
Geoff Langb0f917f2017-12-05 13:41:54 -05003141 if (getClientVersion() < ES_2_0)
3142 {
3143 // Default extensions for GLES1
Lingfeng Yang0df813c2018-07-12 12:52:06 -07003144 supportedExtensions.pointSizeArray = true;
3145 supportedExtensions.textureCubeMap = true;
3146 supportedExtensions.pointSprite = true;
3147 supportedExtensions.drawTexture = true;
jchen1082af6202018-06-22 10:59:52 +08003148 supportedExtensions.parallelShaderCompile = false;
Geoff Langb0f917f2017-12-05 13:41:54 -05003149 }
3150
3151 if (getClientVersion() < ES_3_0)
3152 {
3153 // Disable ES3+ extensions
3154 supportedExtensions.colorBufferFloat = false;
3155 supportedExtensions.eglImageExternalEssl3 = false;
3156 supportedExtensions.textureNorm16 = false;
3157 supportedExtensions.multiview = false;
3158 supportedExtensions.maxViews = 1u;
3159 }
3160
3161 if (getClientVersion() < ES_3_1)
3162 {
3163 // Disable ES3.1+ extensions
3164 supportedExtensions.geometryShader = false;
Olli Etuahod310a432018-08-24 15:40:23 +03003165
3166 // TODO(http://anglebug.com/2775): Multisample arrays could be supported on ES 3.0 as well
3167 // once 2D multisample texture extension is exposed there.
Olli Etuaho064458a2018-08-30 14:02:02 +03003168 supportedExtensions.textureStorageMultisample2DArray = false;
Geoff Langb0f917f2017-12-05 13:41:54 -05003169 }
3170
3171 if (getClientVersion() > ES_2_0)
3172 {
3173 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
3174 // supportedExtensions.sRGB = false;
3175 }
3176
3177 // Some extensions are always available because they are implemented in the GL layer.
3178 supportedExtensions.bindUniformLocation = true;
3179 supportedExtensions.vertexArrayObject = true;
3180 supportedExtensions.bindGeneratesResource = true;
3181 supportedExtensions.clientArrays = true;
3182 supportedExtensions.requestExtension = true;
3183
3184 // Enable the no error extension if the context was created with the flag.
3185 supportedExtensions.noError = mSkipValidation;
3186
3187 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Geoff Lang33f11fb2018-05-07 13:42:47 -04003188 supportedExtensions.surfacelessContext = mSurfacelessSupported;
Geoff Langb0f917f2017-12-05 13:41:54 -05003189
3190 // Explicitly enable GL_KHR_debug
3191 supportedExtensions.debug = true;
3192 supportedExtensions.maxDebugMessageLength = 1024;
3193 supportedExtensions.maxDebugLoggedMessages = 1024;
3194 supportedExtensions.maxDebugGroupStackDepth = 1024;
3195 supportedExtensions.maxLabelLength = 1024;
3196
3197 // Explicitly enable GL_ANGLE_robust_client_memory
3198 supportedExtensions.robustClientMemory = true;
3199
3200 // Determine robust resource init availability from EGL.
Geoff Lang33f11fb2018-05-07 13:42:47 -04003201 supportedExtensions.robustResourceInitialization = mGLState.isRobustResourceInitEnabled();
Geoff Langb0f917f2017-12-05 13:41:54 -05003202
3203 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
3204 // supports it.
3205 supportedExtensions.robustBufferAccessBehavior =
3206 mRobustAccess && supportedExtensions.robustBufferAccessBehavior;
3207
3208 // Enable the cache control query unconditionally.
3209 supportedExtensions.programCacheControl = true;
3210
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003211 // Enable EGL_ANGLE_explicit_context subextensions
Geoff Lang33f11fb2018-05-07 13:42:47 -04003212 if (mExplicitContextAvailable)
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003213 {
3214 // GL_ANGLE_explicit_context_gles1
3215 supportedExtensions.explicitContextGles1 = true;
3216 // GL_ANGLE_explicit_context
3217 supportedExtensions.explicitContext = true;
3218 }
3219
Geoff Langb0f917f2017-12-05 13:41:54 -05003220 return supportedExtensions;
3221}
3222
Geoff Lang33f11fb2018-05-07 13:42:47 -04003223void Context::initCaps()
Geoff Lang493daf52014-07-03 13:38:44 -04003224{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04003225 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04003226
Geoff Lang33f11fb2018-05-07 13:42:47 -04003227 mSupportedExtensions = generateSupportedExtensions();
3228 mExtensions = mSupportedExtensions;
Lingfeng Yang01074432018-04-16 10:19:51 -07003229
3230 mLimitations = mImplementation->getNativeLimitations();
3231
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003232 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
3233 if (getClientVersion() < Version(2, 0))
3234 {
3235 mCaps.maxMultitextureUnits = 4;
3236 mCaps.maxClipPlanes = 6;
3237 mCaps.maxLights = 8;
Lingfeng Yange547aac2018-04-05 09:39:20 -07003238 mCaps.maxModelviewMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3239 mCaps.maxProjectionMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3240 mCaps.maxTextureMatrixStackDepth = Caps::GlobalMatrixStackDepth;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003241 mCaps.minSmoothPointSize = 1.0f;
3242 mCaps.maxSmoothPointSize = 1.0f;
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07003243 mCaps.minSmoothLineWidth = 1.0f;
3244 mCaps.maxSmoothLineWidth = 1.0f;
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003245 }
3246
Luc Ferronad2ae932018-06-11 15:31:17 -04003247 // Apply/Verify implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04003248 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003249
Luc Ferronad2ae932018-06-11 15:31:17 -04003250 ASSERT(mCaps.minAliasedPointSize >= 1.0f);
3251
Jamie Madill0f80ed82017-09-19 00:24:56 -04003252 if (getClientVersion() < ES_3_1)
3253 {
3254 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
3255 }
3256 else
3257 {
3258 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
3259 }
Geoff Lang301d1612014-07-09 10:34:37 -04003260
Jiawei Shao54aafe52018-04-27 14:54:57 +08003261 LimitCap(&mCaps.maxShaderUniformBlocks[ShaderType::Vertex],
3262 IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
Jamie Madill6d32cef2018-08-14 02:34:28 -04003263 LimitCap(&mCaps.maxUniformBufferBindings, IMPLEMENTATION_MAX_UNIFORM_BUFFER_BINDINGS);
3264
Jamie Madill0f80ed82017-09-19 00:24:56 -04003265 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3266 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3267
3268 // Limit textures as well, so we can use fast bitsets with texture bindings.
3269 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
Jiawei Shao54aafe52018-04-27 14:54:57 +08003270 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Vertex],
3271 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
3272 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Fragment],
3273 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04003274
Jiawei Shaodb342272017-09-27 10:21:45 +08003275 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
3276
Geoff Langc287ea62016-09-16 14:46:51 -04003277 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05003278 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04003279 for (const auto &extensionInfo : GetExtensionInfoMap())
3280 {
Geoff Lang0ab41fa2018-03-14 11:03:30 -04003281 // If the user has requested that extensions start disabled and they are requestable,
3282 // disable them.
3283 if (!mExtensionsEnabled && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04003284 {
3285 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
3286 }
3287 }
3288
3289 // Generate texture caps
3290 updateCaps();
3291}
3292
3293void Context::updateCaps()
3294{
Geoff Lang900013c2014-07-07 11:32:19 -04003295 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04003296 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04003297
Jamie Madill7b62cf92017-11-02 15:20:49 -04003298 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04003299 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04003300 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04003301 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003302
Geoff Lang0d8b7242015-09-09 14:56:53 -04003303 // Update the format caps based on the client version and extensions.
3304 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
3305 // ES3.
3306 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003307 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04003308 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003309 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Yuly Novikovf15f8862018-06-04 18:59:41 -04003310 formatCaps.textureAttachment =
3311 formatCaps.textureAttachment &&
3312 formatInfo.textureAttachmentSupport(getClientVersion(), mExtensions);
3313 formatCaps.renderbuffer = formatCaps.renderbuffer &&
3314 formatInfo.renderbufferSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04003315
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003316 // OpenGL ES does not support multisampling with non-rendererable formats
3317 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Yuly Novikovf15f8862018-06-04 18:59:41 -04003318 if (!formatCaps.renderbuffer ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003319 (getClientVersion() < ES_3_1 &&
3320 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04003321 {
Geoff Langd87878e2014-09-19 15:42:59 -04003322 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04003323 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03003324 else
3325 {
3326 // We may have limited the max samples for some required renderbuffer formats due to
3327 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
3328 GLuint formatMaxSamples = formatCaps.getMaxSamples();
3329
3330 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
3331 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
3332 // exception of signed and unsigned integer formats."
3333 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
3334 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
3335 {
3336 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
3337 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
3338 }
3339
3340 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
3341 if (getClientVersion() >= ES_3_1)
3342 {
3343 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
3344 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
3345 // the exception that the signed and unsigned integer formats are required only to
3346 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
3347 // multisamples, which must be at least one."
3348 if (formatInfo.componentType == GL_INT ||
3349 formatInfo.componentType == GL_UNSIGNED_INT)
3350 {
3351 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
3352 }
3353
3354 // GLES 3.1 section 19.3.1.
3355 if (formatCaps.texturable)
3356 {
3357 if (formatInfo.depthBits > 0)
3358 {
3359 mCaps.maxDepthTextureSamples =
3360 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
3361 }
3362 else if (formatInfo.redBits > 0)
3363 {
3364 mCaps.maxColorTextureSamples =
3365 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
3366 }
3367 }
3368 }
3369 }
Geoff Langd87878e2014-09-19 15:42:59 -04003370
3371 if (formatCaps.texturable && formatInfo.compressed)
3372 {
Geoff Langca271392017-04-05 12:30:00 -04003373 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003374 }
3375
Geoff Langca271392017-04-05 12:30:00 -04003376 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04003377 }
Jamie Madill32447362017-06-28 14:53:52 -04003378
3379 // If program binary is disabled, blank out the memory cache pointer.
Geoff Langb0f917f2017-12-05 13:41:54 -05003380 if (!mSupportedExtensions.getProgramBinary)
Jamie Madill32447362017-06-28 14:53:52 -04003381 {
3382 mMemoryProgramCache = nullptr;
3383 }
Corentin Walleze4477002017-12-01 14:39:58 -05003384
3385 // Compute which buffer types are allowed
3386 mValidBufferBindings.reset();
3387 mValidBufferBindings.set(BufferBinding::ElementArray);
3388 mValidBufferBindings.set(BufferBinding::Array);
3389
3390 if (mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
3391 {
3392 mValidBufferBindings.set(BufferBinding::PixelPack);
3393 mValidBufferBindings.set(BufferBinding::PixelUnpack);
3394 }
3395
3396 if (getClientVersion() >= ES_3_0)
3397 {
3398 mValidBufferBindings.set(BufferBinding::CopyRead);
3399 mValidBufferBindings.set(BufferBinding::CopyWrite);
3400 mValidBufferBindings.set(BufferBinding::TransformFeedback);
3401 mValidBufferBindings.set(BufferBinding::Uniform);
3402 }
3403
3404 if (getClientVersion() >= ES_3_1)
3405 {
3406 mValidBufferBindings.set(BufferBinding::AtomicCounter);
3407 mValidBufferBindings.set(BufferBinding::ShaderStorage);
3408 mValidBufferBindings.set(BufferBinding::DrawIndirect);
3409 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
3410 }
jchen107ae70d82018-07-06 13:47:01 +08003411
3412 mThreadPool = angle::WorkerThreadPool::Create(mExtensions.parallelShaderCompile);
Geoff Lang493daf52014-07-03 13:38:44 -04003413}
3414
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003415void Context::initWorkarounds()
3416{
Jamie Madill761b02c2017-06-23 16:27:06 -04003417 // Apply back-end workarounds.
3418 mImplementation->applyNativeWorkarounds(&mWorkarounds);
3419
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003420 // Lose the context upon out of memory error if the application is
3421 // expecting to watch for those events.
3422 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
3423}
3424
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06003425// Return true if the draw is a no-op, else return false.
3426// A no-op draw occurs if the count of vertices is less than the minimum required to
3427// have a valid primitive for this mode (0 for points, 0-1 for lines, 0-2 for tris).
3428bool Context::noopDraw(PrimitiveMode mode, GLsizei count)
3429{
3430 return count < kMinimumPrimitiveCounts[mode];
3431}
3432
3433bool Context::noopDrawInstanced(PrimitiveMode mode, GLsizei count, GLsizei instanceCount)
3434{
3435 return (instanceCount == 0) || noopDraw(mode, count);
3436}
3437
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003438Error Context::prepareForDraw(PrimitiveMode mode)
Jamie Madill05b35b22017-10-03 09:01:44 -04003439{
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003440 if (mGLES1Renderer)
3441 {
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003442 ANGLE_TRY(mGLES1Renderer->prepareForDraw(mode, this, &mGLState));
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003443 }
3444
Geoff Lang9bf86f02018-07-26 11:46:34 -04003445 ANGLE_TRY(syncDirtyObjects(mDrawDirtyObjects));
Jamie Madilla59fc192017-11-02 12:57:58 -04003446
3447 if (isRobustResourceInitEnabled())
3448 {
3449 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
3450 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
3451 }
3452
Geoff Langa8cb2872018-03-09 16:09:40 -05003453 ANGLE_TRY(syncDirtyBits());
Geoff Langd4fff502017-09-22 11:28:28 -04003454 return NoError();
3455}
3456
3457Error Context::prepareForClear(GLbitfield mask)
3458{
Geoff Langa8cb2872018-03-09 16:09:40 -05003459 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003460 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearAttachmentsInitialized(this, mask));
Geoff Langa8cb2872018-03-09 16:09:40 -05003461 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04003462 return NoError();
3463}
3464
3465Error Context::prepareForClearBuffer(GLenum buffer, GLint drawbuffer)
3466{
Geoff Langa8cb2872018-03-09 16:09:40 -05003467 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003468 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearBufferAttachmentsInitialized(this, buffer,
3469 drawbuffer));
Geoff Langa8cb2872018-03-09 16:09:40 -05003470 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill05b35b22017-10-03 09:01:44 -04003471 return NoError();
3472}
3473
Geoff Langa8cb2872018-03-09 16:09:40 -05003474Error Context::syncState(const State::DirtyBits &bitMask, const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04003475{
Geoff Langa8cb2872018-03-09 16:09:40 -05003476 ANGLE_TRY(syncDirtyObjects(objectMask));
3477 ANGLE_TRY(syncDirtyBits(bitMask));
Geoff Langd4fff502017-09-22 11:28:28 -04003478 return NoError();
3479}
3480
Geoff Langa8cb2872018-03-09 16:09:40 -05003481Error Context::syncDirtyBits()
Geoff Langd4fff502017-09-22 11:28:28 -04003482{
3483 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
Jamie Madill189ad872018-07-09 13:32:37 -04003484 ANGLE_TRY(mImplementation->syncState(this, dirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04003485 mGLState.clearDirtyBits();
3486 return NoError();
3487}
3488
Geoff Langa8cb2872018-03-09 16:09:40 -05003489Error Context::syncDirtyBits(const State::DirtyBits &bitMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003490{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003491 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madill189ad872018-07-09 13:32:37 -04003492 ANGLE_TRY(mImplementation->syncState(this, dirtyBits));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003493 mGLState.clearDirtyBits(dirtyBits);
Jamie Madillbc918e72018-03-08 09:47:21 -05003494 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003495}
Jamie Madillc29968b2016-01-20 11:17:23 -05003496
Geoff Langa8cb2872018-03-09 16:09:40 -05003497Error Context::syncDirtyObjects(const State::DirtyObjects &objectMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003498{
3499 return mGLState.syncDirtyObjects(this, objectMask);
3500}
3501
Jamie Madillc29968b2016-01-20 11:17:23 -05003502void Context::blitFramebuffer(GLint srcX0,
3503 GLint srcY0,
3504 GLint srcX1,
3505 GLint srcY1,
3506 GLint dstX0,
3507 GLint dstY0,
3508 GLint dstX1,
3509 GLint dstY1,
3510 GLbitfield mask,
3511 GLenum filter)
3512{
Qin Jiajiaaef92162018-02-27 13:51:44 +08003513 if (mask == 0)
3514 {
3515 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
3516 // buffers are copied.
3517 return;
3518 }
3519
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003520 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003521 ASSERT(drawFramebuffer);
3522
3523 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
3524 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
3525
Jamie Madillbc918e72018-03-08 09:47:21 -05003526 ANGLE_CONTEXT_TRY(syncStateForBlit());
Jamie Madillc29968b2016-01-20 11:17:23 -05003527
Jamie Madillc564c072017-06-01 12:45:42 -04003528 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003529}
Jamie Madillc29968b2016-01-20 11:17:23 -05003530
3531void Context::clear(GLbitfield mask)
3532{
Geoff Langd4fff502017-09-22 11:28:28 -04003533 ANGLE_CONTEXT_TRY(prepareForClear(mask));
3534 ANGLE_CONTEXT_TRY(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05003535}
3536
3537void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
3538{
Geoff Langd4fff502017-09-22 11:28:28 -04003539 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3540 ANGLE_CONTEXT_TRY(
3541 mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003542}
3543
3544void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3545{
Geoff Langd4fff502017-09-22 11:28:28 -04003546 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3547 ANGLE_CONTEXT_TRY(
3548 mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003549}
3550
3551void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3552{
Geoff Langd4fff502017-09-22 11:28:28 -04003553 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3554 ANGLE_CONTEXT_TRY(
3555 mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003556}
3557
3558void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3559{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003560 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003561 ASSERT(framebufferObject);
3562
3563 // If a buffer is not present, the clear has no effect
3564 if (framebufferObject->getDepthbuffer() == nullptr &&
3565 framebufferObject->getStencilbuffer() == nullptr)
3566 {
3567 return;
3568 }
3569
Geoff Langd4fff502017-09-22 11:28:28 -04003570 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3571 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003572}
3573
3574void Context::readPixels(GLint x,
3575 GLint y,
3576 GLsizei width,
3577 GLsizei height,
3578 GLenum format,
3579 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003580 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003581{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003582 if (width == 0 || height == 0)
3583 {
3584 return;
3585 }
3586
Jamie Madillbc918e72018-03-08 09:47:21 -05003587 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003588
Jamie Madillb6664922017-07-25 12:55:04 -04003589 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3590 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003591
3592 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04003593 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003594}
3595
Brandon Jones59770802018-04-02 13:18:42 -07003596void Context::readPixelsRobust(GLint x,
3597 GLint y,
3598 GLsizei width,
3599 GLsizei height,
3600 GLenum format,
3601 GLenum type,
3602 GLsizei bufSize,
3603 GLsizei *length,
3604 GLsizei *columns,
3605 GLsizei *rows,
3606 void *pixels)
3607{
3608 readPixels(x, y, width, height, format, type, pixels);
3609}
3610
3611void Context::readnPixelsRobust(GLint x,
3612 GLint y,
3613 GLsizei width,
3614 GLsizei height,
3615 GLenum format,
3616 GLenum type,
3617 GLsizei bufSize,
3618 GLsizei *length,
3619 GLsizei *columns,
3620 GLsizei *rows,
3621 void *data)
3622{
3623 readPixels(x, y, width, height, format, type, data);
3624}
3625
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003626void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003627 GLint level,
3628 GLenum internalformat,
3629 GLint x,
3630 GLint y,
3631 GLsizei width,
3632 GLsizei height,
3633 GLint border)
3634{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003635 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003636 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003637
Jamie Madillc29968b2016-01-20 11:17:23 -05003638 Rectangle sourceArea(x, y, width, height);
3639
Jamie Madill05b35b22017-10-03 09:01:44 -04003640 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003641 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003642 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003643}
3644
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003645void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003646 GLint level,
3647 GLint xoffset,
3648 GLint yoffset,
3649 GLint x,
3650 GLint y,
3651 GLsizei width,
3652 GLsizei height)
3653{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003654 if (width == 0 || height == 0)
3655 {
3656 return;
3657 }
3658
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003659 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003660 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003661
Jamie Madillc29968b2016-01-20 11:17:23 -05003662 Offset destOffset(xoffset, yoffset, 0);
3663 Rectangle sourceArea(x, y, width, height);
3664
Jamie Madill05b35b22017-10-03 09:01:44 -04003665 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003666 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003667 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003668}
3669
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003670void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003671 GLint level,
3672 GLint xoffset,
3673 GLint yoffset,
3674 GLint zoffset,
3675 GLint x,
3676 GLint y,
3677 GLsizei width,
3678 GLsizei height)
3679{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003680 if (width == 0 || height == 0)
3681 {
3682 return;
3683 }
3684
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003685 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003686 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003687
Jamie Madillc29968b2016-01-20 11:17:23 -05003688 Offset destOffset(xoffset, yoffset, zoffset);
3689 Rectangle sourceArea(x, y, width, height);
3690
Jamie Madill05b35b22017-10-03 09:01:44 -04003691 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3692 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003693 handleError(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level, destOffset,
3694 sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003695}
3696
3697void Context::framebufferTexture2D(GLenum target,
3698 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003699 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003700 GLuint texture,
3701 GLint level)
3702{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003703 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003704 ASSERT(framebuffer);
3705
3706 if (texture != 0)
3707 {
3708 Texture *textureObj = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003709 ImageIndex index = ImageIndex::MakeFromTarget(textarget, level);
Jamie Madilla02315b2017-02-23 14:14:47 -05003710 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003711 }
3712 else
3713 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003714 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003715 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003716
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003717 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003718}
3719
3720void Context::framebufferRenderbuffer(GLenum target,
3721 GLenum attachment,
3722 GLenum renderbuffertarget,
3723 GLuint renderbuffer)
3724{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003725 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003726 ASSERT(framebuffer);
3727
3728 if (renderbuffer != 0)
3729 {
3730 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003731
Jamie Madillcc129372018-04-12 09:13:18 -04003732 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003733 renderbufferObject);
3734 }
3735 else
3736 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003737 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003738 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003739
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003740 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003741}
3742
3743void Context::framebufferTextureLayer(GLenum target,
3744 GLenum attachment,
3745 GLuint texture,
3746 GLint level,
3747 GLint layer)
3748{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003749 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003750 ASSERT(framebuffer);
3751
3752 if (texture != 0)
3753 {
3754 Texture *textureObject = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003755 ImageIndex index = ImageIndex::MakeFromType(textureObject->getType(), level, layer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003756 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003757 }
3758 else
3759 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003760 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003761 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003762
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003763 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003764}
3765
Brandon Jones59770802018-04-02 13:18:42 -07003766void Context::framebufferTextureMultiviewLayered(GLenum target,
3767 GLenum attachment,
3768 GLuint texture,
3769 GLint level,
3770 GLint baseViewIndex,
3771 GLsizei numViews)
Martin Radev137032d2017-07-13 10:11:12 +03003772{
Martin Radev82ef7742017-08-08 17:44:58 +03003773 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3774 ASSERT(framebuffer);
3775
3776 if (texture != 0)
3777 {
3778 Texture *textureObj = getTexture(texture);
3779
Martin Radev18b75ba2017-08-15 15:50:40 +03003780 ImageIndex index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
Martin Radev82ef7742017-08-08 17:44:58 +03003781 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3782 numViews, baseViewIndex);
3783 }
3784 else
3785 {
3786 framebuffer->resetAttachment(this, attachment);
3787 }
3788
3789 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003790}
3791
Brandon Jones59770802018-04-02 13:18:42 -07003792void Context::framebufferTextureMultiviewSideBySide(GLenum target,
3793 GLenum attachment,
3794 GLuint texture,
3795 GLint level,
3796 GLsizei numViews,
3797 const GLint *viewportOffsets)
Martin Radev137032d2017-07-13 10:11:12 +03003798{
Martin Radev5dae57b2017-07-14 16:15:55 +03003799 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3800 ASSERT(framebuffer);
3801
3802 if (texture != 0)
3803 {
3804 Texture *textureObj = getTexture(texture);
3805
3806 ImageIndex index = ImageIndex::Make2D(level);
3807 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3808 textureObj, numViews, viewportOffsets);
3809 }
3810 else
3811 {
3812 framebuffer->resetAttachment(this, attachment);
3813 }
3814
3815 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003816}
3817
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003818void Context::framebufferTexture(GLenum target, GLenum attachment, GLuint texture, GLint level)
3819{
Jiawei Shaoa8802472018-05-28 11:17:47 +08003820 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3821 ASSERT(framebuffer);
3822
3823 if (texture != 0)
3824 {
3825 Texture *textureObj = getTexture(texture);
3826
3827 ImageIndex index = ImageIndex::MakeFromType(
3828 textureObj->getType(), level, ImageIndex::kEntireLevel, ImageIndex::kEntireLevel);
3829 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
3830 }
3831 else
3832 {
3833 framebuffer->resetAttachment(this, attachment);
3834 }
3835
3836 mGLState.setObjectDirty(target);
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003837}
3838
Jamie Madillc29968b2016-01-20 11:17:23 -05003839void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3840{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003841 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003842 ASSERT(framebuffer);
3843 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003844 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madilld84b6732018-09-06 15:54:35 -04003845 mStateCache.onDrawFramebufferChange(this);
Jamie Madillc29968b2016-01-20 11:17:23 -05003846}
3847
3848void Context::readBuffer(GLenum mode)
3849{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003850 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003851 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003852 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003853}
3854
3855void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3856{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003857 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003858 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003859
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003860 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003861 ASSERT(framebuffer);
3862
3863 // The specification isn't clear what should be done when the framebuffer isn't complete.
3864 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003865 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003866}
3867
3868void Context::invalidateFramebuffer(GLenum target,
3869 GLsizei numAttachments,
3870 const GLenum *attachments)
3871{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003872 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003873 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003874
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003875 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003876 ASSERT(framebuffer);
3877
Jamie Madill427064d2018-04-13 16:20:34 -04003878 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003879 {
Jamie Madill437fa652016-05-03 15:13:24 -04003880 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003881 }
Jamie Madill437fa652016-05-03 15:13:24 -04003882
Jamie Madill4928b7c2017-06-20 12:57:39 -04003883 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003884}
3885
3886void Context::invalidateSubFramebuffer(GLenum target,
3887 GLsizei numAttachments,
3888 const GLenum *attachments,
3889 GLint x,
3890 GLint y,
3891 GLsizei width,
3892 GLsizei height)
3893{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003894 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003895 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003896
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003897 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003898 ASSERT(framebuffer);
3899
Jamie Madill427064d2018-04-13 16:20:34 -04003900 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003901 {
Jamie Madill437fa652016-05-03 15:13:24 -04003902 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003903 }
Jamie Madill437fa652016-05-03 15:13:24 -04003904
3905 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003906 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003907}
3908
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003909void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003910 GLint level,
3911 GLint internalformat,
3912 GLsizei width,
3913 GLsizei height,
3914 GLint border,
3915 GLenum format,
3916 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003917 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003918{
Jamie Madillbc918e72018-03-08 09:47:21 -05003919 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003920
3921 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003922 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003923 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003924 size, format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003925}
3926
Brandon Jones59770802018-04-02 13:18:42 -07003927void Context::texImage2DRobust(TextureTarget target,
3928 GLint level,
3929 GLint internalformat,
3930 GLsizei width,
3931 GLsizei height,
3932 GLint border,
3933 GLenum format,
3934 GLenum type,
3935 GLsizei bufSize,
3936 const void *pixels)
3937{
3938 texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
3939}
3940
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003941void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003942 GLint level,
3943 GLint internalformat,
3944 GLsizei width,
3945 GLsizei height,
3946 GLsizei depth,
3947 GLint border,
3948 GLenum format,
3949 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003950 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003951{
Jamie Madillbc918e72018-03-08 09:47:21 -05003952 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003953
3954 Extents size(width, height, depth);
3955 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003956 handleError(texture->setImage(this, mGLState.getUnpackState(),
3957 NonCubeTextureTypeToTarget(target), level, internalformat, size,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003958 format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003959}
3960
Brandon Jones59770802018-04-02 13:18:42 -07003961void Context::texImage3DRobust(TextureType target,
3962 GLint level,
3963 GLint internalformat,
3964 GLsizei width,
3965 GLsizei height,
3966 GLsizei depth,
3967 GLint border,
3968 GLenum format,
3969 GLenum type,
3970 GLsizei bufSize,
3971 const void *pixels)
3972{
3973 texImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels);
3974}
3975
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003976void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003977 GLint level,
3978 GLint xoffset,
3979 GLint yoffset,
3980 GLsizei width,
3981 GLsizei height,
3982 GLenum format,
3983 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003984 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003985{
3986 // Zero sized uploads are valid but no-ops
3987 if (width == 0 || height == 0)
3988 {
3989 return;
3990 }
3991
Jamie Madillbc918e72018-03-08 09:47:21 -05003992 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003993
3994 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003995 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill0d0fb432018-09-07 17:43:32 -04003996
3997 gl::Buffer *unpackBuffer = mGLState.getTargetBuffer(gl::BufferBinding::PixelUnpack);
3998
3999 handleError(texture->setSubImage(this, mGLState.getUnpackState(), unpackBuffer, target, level,
4000 area, format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004001}
4002
Brandon Jones59770802018-04-02 13:18:42 -07004003void Context::texSubImage2DRobust(TextureTarget target,
4004 GLint level,
4005 GLint xoffset,
4006 GLint yoffset,
4007 GLsizei width,
4008 GLsizei height,
4009 GLenum format,
4010 GLenum type,
4011 GLsizei bufSize,
4012 const void *pixels)
4013{
4014 texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
4015}
4016
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004017void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004018 GLint level,
4019 GLint xoffset,
4020 GLint yoffset,
4021 GLint zoffset,
4022 GLsizei width,
4023 GLsizei height,
4024 GLsizei depth,
4025 GLenum format,
4026 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004027 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004028{
4029 // Zero sized uploads are valid but no-ops
4030 if (width == 0 || height == 0 || depth == 0)
4031 {
4032 return;
4033 }
4034
Jamie Madillbc918e72018-03-08 09:47:21 -05004035 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004036
4037 Box area(xoffset, yoffset, zoffset, width, height, depth);
4038 Texture *texture = getTargetTexture(target);
Jamie Madill0d0fb432018-09-07 17:43:32 -04004039
4040 gl::Buffer *unpackBuffer = mGLState.getTargetBuffer(gl::BufferBinding::PixelUnpack);
4041
4042 handleError(texture->setSubImage(this, mGLState.getUnpackState(), unpackBuffer,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004043 NonCubeTextureTypeToTarget(target), level, area, format, type,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004044 static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004045}
4046
Brandon Jones59770802018-04-02 13:18:42 -07004047void Context::texSubImage3DRobust(TextureType target,
4048 GLint level,
4049 GLint xoffset,
4050 GLint yoffset,
4051 GLint zoffset,
4052 GLsizei width,
4053 GLsizei height,
4054 GLsizei depth,
4055 GLenum format,
4056 GLenum type,
4057 GLsizei bufSize,
4058 const void *pixels)
4059{
4060 texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type,
4061 pixels);
4062}
4063
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004064void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004065 GLint level,
4066 GLenum internalformat,
4067 GLsizei width,
4068 GLsizei height,
4069 GLint border,
4070 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004071 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004072{
Jamie Madillbc918e72018-03-08 09:47:21 -05004073 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004074
4075 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004076 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05004077 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
4078 internalformat, size, imageSize,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004079 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004080}
4081
Brandon Jones59770802018-04-02 13:18:42 -07004082void Context::compressedTexImage2DRobust(TextureTarget target,
4083 GLint level,
4084 GLenum internalformat,
4085 GLsizei width,
4086 GLsizei height,
4087 GLint border,
4088 GLsizei imageSize,
4089 GLsizei dataSize,
4090 const GLvoid *data)
4091{
4092 compressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
4093}
4094
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004095void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004096 GLint level,
4097 GLenum internalformat,
4098 GLsizei width,
4099 GLsizei height,
4100 GLsizei depth,
4101 GLint border,
4102 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004103 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004104{
Jamie Madillbc918e72018-03-08 09:47:21 -05004105 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004106
4107 Extents size(width, height, depth);
4108 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004109 handleError(texture->setCompressedImage(
4110 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004111 size, imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004112}
4113
Brandon Jones59770802018-04-02 13:18:42 -07004114void Context::compressedTexImage3DRobust(TextureType target,
4115 GLint level,
4116 GLenum internalformat,
4117 GLsizei width,
4118 GLsizei height,
4119 GLsizei depth,
4120 GLint border,
4121 GLsizei imageSize,
4122 GLsizei dataSize,
4123 const GLvoid *data)
4124{
4125 compressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize,
4126 data);
4127}
4128
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004129void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004130 GLint level,
4131 GLint xoffset,
4132 GLint yoffset,
4133 GLsizei width,
4134 GLsizei height,
4135 GLenum format,
4136 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004137 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004138{
Jamie Madillbc918e72018-03-08 09:47:21 -05004139 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004140
4141 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004142 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05004143 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
4144 format, imageSize,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004145 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004146}
4147
Brandon Jones59770802018-04-02 13:18:42 -07004148void Context::compressedTexSubImage2DRobust(TextureTarget target,
4149 GLint level,
4150 GLint xoffset,
4151 GLint yoffset,
4152 GLsizei width,
4153 GLsizei height,
4154 GLenum format,
4155 GLsizei imageSize,
4156 GLsizei dataSize,
4157 const GLvoid *data)
4158{
4159 compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize,
4160 data);
4161}
4162
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004163void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004164 GLint level,
4165 GLint xoffset,
4166 GLint yoffset,
4167 GLint zoffset,
4168 GLsizei width,
4169 GLsizei height,
4170 GLsizei depth,
4171 GLenum format,
4172 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004173 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004174{
4175 // Zero sized uploads are valid but no-ops
4176 if (width == 0 || height == 0)
4177 {
4178 return;
4179 }
4180
Jamie Madillbc918e72018-03-08 09:47:21 -05004181 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004182
4183 Box area(xoffset, yoffset, zoffset, width, height, depth);
4184 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004185 handleError(texture->setCompressedSubImage(
4186 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004187 imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004188}
4189
Brandon Jones59770802018-04-02 13:18:42 -07004190void Context::compressedTexSubImage3DRobust(TextureType target,
4191 GLint level,
4192 GLint xoffset,
4193 GLint yoffset,
4194 GLint zoffset,
4195 GLsizei width,
4196 GLsizei height,
4197 GLsizei depth,
4198 GLenum format,
4199 GLsizei imageSize,
4200 GLsizei dataSize,
4201 const GLvoid *data)
4202{
4203 compressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format,
4204 imageSize, data);
4205}
4206
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004207void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004208{
4209 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05004210 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004211}
4212
Jamie Madill007530e2017-12-28 14:27:04 -05004213void Context::copyTexture(GLuint sourceId,
4214 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004215 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004216 GLuint destId,
4217 GLint destLevel,
4218 GLint internalFormat,
4219 GLenum destType,
4220 GLboolean unpackFlipY,
4221 GLboolean unpackPremultiplyAlpha,
4222 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004223{
Jamie Madillbc918e72018-03-08 09:47:21 -05004224 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004225
4226 gl::Texture *sourceTexture = getTexture(sourceId);
4227 gl::Texture *destTexture = getTexture(destId);
Geoff Lang92019432017-11-20 13:09:34 -05004228 handleError(destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType,
4229 sourceLevel, ConvertToBool(unpackFlipY),
4230 ConvertToBool(unpackPremultiplyAlpha),
4231 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004232}
4233
Jamie Madill007530e2017-12-28 14:27:04 -05004234void Context::copySubTexture(GLuint sourceId,
4235 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004236 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004237 GLuint destId,
4238 GLint destLevel,
4239 GLint xoffset,
4240 GLint yoffset,
4241 GLint x,
4242 GLint y,
4243 GLsizei width,
4244 GLsizei height,
4245 GLboolean unpackFlipY,
4246 GLboolean unpackPremultiplyAlpha,
4247 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004248{
4249 // Zero sized copies are valid but no-ops
4250 if (width == 0 || height == 0)
4251 {
4252 return;
4253 }
4254
Jamie Madillbc918e72018-03-08 09:47:21 -05004255 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004256
4257 gl::Texture *sourceTexture = getTexture(sourceId);
4258 gl::Texture *destTexture = getTexture(destId);
4259 Offset offset(xoffset, yoffset, 0);
4260 Rectangle area(x, y, width, height);
Geoff Lang92019432017-11-20 13:09:34 -05004261 handleError(destTexture->copySubTexture(this, destTarget, destLevel, offset, sourceLevel, area,
4262 ConvertToBool(unpackFlipY),
4263 ConvertToBool(unpackPremultiplyAlpha),
4264 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004265}
4266
Jamie Madill007530e2017-12-28 14:27:04 -05004267void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07004268{
Jamie Madillbc918e72018-03-08 09:47:21 -05004269 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07004270
4271 gl::Texture *sourceTexture = getTexture(sourceId);
4272 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05004273 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07004274}
4275
Corentin Wallez336129f2017-10-17 15:55:40 -04004276void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03004277{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004278 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004279 ASSERT(buffer);
4280
Geoff Lang496c02d2016-10-20 11:38:11 -07004281 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03004282}
4283
Brandon Jones59770802018-04-02 13:18:42 -07004284void Context::getBufferPointervRobust(BufferBinding target,
4285 GLenum pname,
4286 GLsizei bufSize,
4287 GLsizei *length,
4288 void **params)
4289{
4290 getBufferPointerv(target, pname, params);
4291}
4292
Corentin Wallez336129f2017-10-17 15:55:40 -04004293void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004294{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004295 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004296 ASSERT(buffer);
4297
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004298 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004299 if (error.isError())
4300 {
Jamie Madill437fa652016-05-03 15:13:24 -04004301 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004302 return nullptr;
4303 }
4304
4305 return buffer->getMapPointer();
4306}
4307
Corentin Wallez336129f2017-10-17 15:55:40 -04004308GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03004309{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004310 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004311 ASSERT(buffer);
4312
4313 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004314 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03004315 if (error.isError())
4316 {
Jamie Madill437fa652016-05-03 15:13:24 -04004317 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004318 return GL_FALSE;
4319 }
4320
4321 return result;
4322}
4323
Corentin Wallez336129f2017-10-17 15:55:40 -04004324void *Context::mapBufferRange(BufferBinding target,
4325 GLintptr offset,
4326 GLsizeiptr length,
4327 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004328{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004329 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004330 ASSERT(buffer);
4331
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004332 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004333 if (error.isError())
4334 {
Jamie Madill437fa652016-05-03 15:13:24 -04004335 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004336 return nullptr;
4337 }
4338
4339 return buffer->getMapPointer();
4340}
4341
Corentin Wallez336129f2017-10-17 15:55:40 -04004342void Context::flushMappedBufferRange(BufferBinding /*target*/,
4343 GLintptr /*offset*/,
4344 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03004345{
4346 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
4347}
4348
Jamie Madillbc918e72018-03-08 09:47:21 -05004349Error Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004350{
Geoff Langa8cb2872018-03-09 16:09:40 -05004351 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004352}
4353
Jamie Madillbc918e72018-03-08 09:47:21 -05004354Error Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004355{
Geoff Langa8cb2872018-03-09 16:09:40 -05004356 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004357}
4358
Jamie Madillbc918e72018-03-08 09:47:21 -05004359Error Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004360{
Geoff Langa8cb2872018-03-09 16:09:40 -05004361 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004362}
4363
Geoff Lang9bf86f02018-07-26 11:46:34 -04004364Error Context::syncStateForPathOperation()
4365{
4366 ANGLE_TRY(syncDirtyObjects(mPathOperationDirtyObjects));
4367
4368 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
4369 ANGLE_TRY(syncDirtyBits());
4370
4371 return NoError();
4372}
4373
Jiajia Qin5451d532017-11-16 17:16:34 +08004374void Context::activeShaderProgram(GLuint pipeline, GLuint program)
4375{
4376 UNIMPLEMENTED();
4377}
4378
Jamie Madillc20ab272016-06-09 07:20:46 -07004379void Context::activeTexture(GLenum texture)
4380{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004381 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004382}
4383
Jamie Madill876429b2017-04-20 15:46:24 -04004384void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004385{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004386 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004387}
4388
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004389void Context::blendEquation(GLenum mode)
4390{
4391 mGLState.setBlendEquation(mode, mode);
4392}
4393
Jamie Madillc20ab272016-06-09 07:20:46 -07004394void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
4395{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004396 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004397}
4398
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004399void Context::blendFunc(GLenum sfactor, GLenum dfactor)
4400{
4401 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
4402}
4403
Jamie Madillc20ab272016-06-09 07:20:46 -07004404void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
4405{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004406 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004407}
4408
Jamie Madill876429b2017-04-20 15:46:24 -04004409void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004410{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004411 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004412}
4413
Jamie Madill876429b2017-04-20 15:46:24 -04004414void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07004415{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004416 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07004417}
4418
4419void Context::clearStencil(GLint s)
4420{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004421 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07004422}
4423
4424void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
4425{
Geoff Lang92019432017-11-20 13:09:34 -05004426 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
4427 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004428}
4429
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004430void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07004431{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004432 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004433}
4434
4435void Context::depthFunc(GLenum func)
4436{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004437 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07004438}
4439
4440void Context::depthMask(GLboolean flag)
4441{
Geoff Lang92019432017-11-20 13:09:34 -05004442 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07004443}
4444
Jamie Madill876429b2017-04-20 15:46:24 -04004445void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07004446{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004447 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07004448}
4449
4450void Context::disable(GLenum cap)
4451{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004452 mGLState.setEnableFeature(cap, false);
Jamie Madilld84b6732018-09-06 15:54:35 -04004453 mStateCache.onContextCapChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004454}
4455
4456void Context::disableVertexAttribArray(GLuint index)
4457{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004458 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004459 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004460}
4461
4462void Context::enable(GLenum cap)
4463{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004464 mGLState.setEnableFeature(cap, true);
Jamie Madilld84b6732018-09-06 15:54:35 -04004465 mStateCache.onContextCapChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004466}
4467
4468void Context::enableVertexAttribArray(GLuint index)
4469{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004470 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004471 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004472}
4473
4474void Context::frontFace(GLenum mode)
4475{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004476 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004477}
4478
4479void Context::hint(GLenum target, GLenum mode)
4480{
4481 switch (target)
4482 {
4483 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004484 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004485 break;
4486
4487 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004488 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004489 break;
4490
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07004491 case GL_PERSPECTIVE_CORRECTION_HINT:
4492 case GL_POINT_SMOOTH_HINT:
4493 case GL_LINE_SMOOTH_HINT:
4494 case GL_FOG_HINT:
4495 mGLState.gles1().setHint(target, mode);
4496 break;
Jamie Madillc20ab272016-06-09 07:20:46 -07004497 default:
4498 UNREACHABLE();
4499 return;
4500 }
4501}
4502
4503void Context::lineWidth(GLfloat width)
4504{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004505 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07004506}
4507
4508void Context::pixelStorei(GLenum pname, GLint param)
4509{
4510 switch (pname)
4511 {
4512 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004513 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004514 break;
4515
4516 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004517 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004518 break;
4519
4520 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004521 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004522 break;
4523
4524 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004525 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004526 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004527 break;
4528
4529 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03004530 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004531 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004532 break;
4533
4534 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03004535 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004536 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004537 break;
4538
4539 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004540 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004541 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004542 break;
4543
4544 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004545 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004546 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004547 break;
4548
4549 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004550 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004551 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004552 break;
4553
4554 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004555 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004556 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004557 break;
4558
4559 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004560 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004561 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004562 break;
4563
4564 default:
4565 UNREACHABLE();
4566 return;
4567 }
4568}
4569
4570void Context::polygonOffset(GLfloat factor, GLfloat units)
4571{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004572 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07004573}
4574
Jamie Madill876429b2017-04-20 15:46:24 -04004575void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07004576{
Geoff Lang92019432017-11-20 13:09:34 -05004577 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07004578}
4579
Jiawei Shaodb342272017-09-27 10:21:45 +08004580void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
4581{
4582 mGLState.setSampleMaskParams(maskNumber, mask);
4583}
4584
Jamie Madillc20ab272016-06-09 07:20:46 -07004585void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
4586{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004587 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004588}
4589
4590void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
4591{
4592 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4593 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004594 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004595 }
4596
4597 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4598 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004599 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004600 }
Jamie Madilld84b6732018-09-06 15:54:35 -04004601
4602 mStateCache.onStencilStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004603}
4604
4605void Context::stencilMaskSeparate(GLenum face, GLuint mask)
4606{
4607 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4608 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004609 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004610 }
4611
4612 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4613 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004614 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004615 }
Jamie Madilld84b6732018-09-06 15:54:35 -04004616
4617 mStateCache.onStencilStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004618}
4619
4620void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4621{
4622 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4623 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004624 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004625 }
4626
4627 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4628 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004629 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004630 }
4631}
4632
4633void Context::vertexAttrib1f(GLuint index, GLfloat x)
4634{
4635 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004636 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004637 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004638}
4639
4640void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
4641{
4642 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004643 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004644 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004645}
4646
4647void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4648{
4649 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004650 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004651 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004652}
4653
4654void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
4655{
4656 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004657 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004658 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004659}
4660
4661void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4662{
4663 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004664 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004665 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004666}
4667
4668void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
4669{
4670 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004671 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004672 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004673}
4674
4675void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4676{
4677 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004678 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004679 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004680}
4681
4682void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
4683{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004684 mGLState.setVertexAttribf(index, values);
Jamie Madilld84b6732018-09-06 15:54:35 -04004685 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004686}
4687
4688void Context::vertexAttribPointer(GLuint index,
4689 GLint size,
4690 GLenum type,
4691 GLboolean normalized,
4692 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004693 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07004694{
Corentin Wallez336129f2017-10-17 15:55:40 -04004695 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05004696 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004697 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004698}
4699
Shao80957d92017-02-20 21:25:59 +08004700void Context::vertexAttribFormat(GLuint attribIndex,
4701 GLint size,
4702 GLenum type,
4703 GLboolean normalized,
4704 GLuint relativeOffset)
4705{
Geoff Lang92019432017-11-20 13:09:34 -05004706 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08004707 relativeOffset);
Jamie Madilld84b6732018-09-06 15:54:35 -04004708 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004709}
4710
4711void Context::vertexAttribIFormat(GLuint attribIndex,
4712 GLint size,
4713 GLenum type,
4714 GLuint relativeOffset)
4715{
4716 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
Jamie Madilld84b6732018-09-06 15:54:35 -04004717 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004718}
4719
4720void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4721{
Shaodde78e82017-05-22 14:13:27 +08004722 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004723 mStateCache.onVertexArrayStateChange(this);
Shao80957d92017-02-20 21:25:59 +08004724}
4725
Jiajia Qin5451d532017-11-16 17:16:34 +08004726void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004727{
4728 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
Jamie Madilld84b6732018-09-06 15:54:35 -04004729 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004730}
4731
Jamie Madillc20ab272016-06-09 07:20:46 -07004732void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4733{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004734 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004735}
4736
4737void Context::vertexAttribIPointer(GLuint index,
4738 GLint size,
4739 GLenum type,
4740 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004741 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004742{
Corentin Wallez336129f2017-10-17 15:55:40 -04004743 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
4744 size, type, false, true, stride, pointer);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004745 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004746}
4747
4748void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4749{
4750 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004751 mGLState.setVertexAttribi(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004752 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004753}
4754
4755void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4756{
4757 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004758 mGLState.setVertexAttribu(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004759 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004760}
4761
4762void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4763{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004764 mGLState.setVertexAttribi(index, v);
Jamie Madilld84b6732018-09-06 15:54:35 -04004765 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004766}
4767
4768void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4769{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004770 mGLState.setVertexAttribu(index, v);
Jamie Madilld84b6732018-09-06 15:54:35 -04004771 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004772}
4773
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004774void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4775{
4776 const VertexAttribCurrentValueData &currentValues =
4777 getGLState().getVertexAttribCurrentValue(index);
4778 const VertexArray *vao = getGLState().getVertexArray();
4779 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4780 currentValues, pname, params);
4781}
4782
Brandon Jones59770802018-04-02 13:18:42 -07004783void Context::getVertexAttribivRobust(GLuint index,
4784 GLenum pname,
4785 GLsizei bufSize,
4786 GLsizei *length,
4787 GLint *params)
4788{
4789 getVertexAttribiv(index, pname, params);
4790}
4791
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004792void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4793{
4794 const VertexAttribCurrentValueData &currentValues =
4795 getGLState().getVertexAttribCurrentValue(index);
4796 const VertexArray *vao = getGLState().getVertexArray();
4797 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4798 currentValues, pname, params);
4799}
4800
Brandon Jones59770802018-04-02 13:18:42 -07004801void Context::getVertexAttribfvRobust(GLuint index,
4802 GLenum pname,
4803 GLsizei bufSize,
4804 GLsizei *length,
4805 GLfloat *params)
4806{
4807 getVertexAttribfv(index, pname, params);
4808}
4809
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004810void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4811{
4812 const VertexAttribCurrentValueData &currentValues =
4813 getGLState().getVertexAttribCurrentValue(index);
4814 const VertexArray *vao = getGLState().getVertexArray();
4815 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4816 currentValues, pname, params);
4817}
4818
Brandon Jones59770802018-04-02 13:18:42 -07004819void Context::getVertexAttribIivRobust(GLuint index,
4820 GLenum pname,
4821 GLsizei bufSize,
4822 GLsizei *length,
4823 GLint *params)
4824{
4825 getVertexAttribIiv(index, pname, params);
4826}
4827
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004828void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4829{
4830 const VertexAttribCurrentValueData &currentValues =
4831 getGLState().getVertexAttribCurrentValue(index);
4832 const VertexArray *vao = getGLState().getVertexArray();
4833 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4834 currentValues, pname, params);
4835}
4836
Brandon Jones59770802018-04-02 13:18:42 -07004837void Context::getVertexAttribIuivRobust(GLuint index,
4838 GLenum pname,
4839 GLsizei bufSize,
4840 GLsizei *length,
4841 GLuint *params)
4842{
4843 getVertexAttribIuiv(index, pname, params);
4844}
4845
Jamie Madill876429b2017-04-20 15:46:24 -04004846void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004847{
4848 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
4849 QueryVertexAttribPointerv(attrib, pname, pointer);
4850}
4851
Brandon Jones59770802018-04-02 13:18:42 -07004852void Context::getVertexAttribPointervRobust(GLuint index,
4853 GLenum pname,
4854 GLsizei bufSize,
4855 GLsizei *length,
4856 void **pointer)
4857{
4858 getVertexAttribPointerv(index, pname, pointer);
4859}
4860
Jamie Madillc20ab272016-06-09 07:20:46 -07004861void Context::debugMessageControl(GLenum source,
4862 GLenum type,
4863 GLenum severity,
4864 GLsizei count,
4865 const GLuint *ids,
4866 GLboolean enabled)
4867{
4868 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004869 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05004870 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004871}
4872
4873void Context::debugMessageInsert(GLenum source,
4874 GLenum type,
4875 GLuint id,
4876 GLenum severity,
4877 GLsizei length,
4878 const GLchar *buf)
4879{
4880 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004881 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004882}
4883
4884void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4885{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004886 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004887}
4888
4889GLuint Context::getDebugMessageLog(GLuint count,
4890 GLsizei bufSize,
4891 GLenum *sources,
4892 GLenum *types,
4893 GLuint *ids,
4894 GLenum *severities,
4895 GLsizei *lengths,
4896 GLchar *messageLog)
4897{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004898 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4899 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004900}
4901
4902void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4903{
4904 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004905 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05004906 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07004907}
4908
4909void Context::popDebugGroup()
4910{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004911 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05004912 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004913}
4914
Corentin Wallez336129f2017-10-17 15:55:40 -04004915void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004916{
4917 Buffer *buffer = mGLState.getTargetBuffer(target);
4918 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004919 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004920}
4921
Corentin Wallez336129f2017-10-17 15:55:40 -04004922void Context::bufferSubData(BufferBinding target,
4923 GLintptr offset,
4924 GLsizeiptr size,
4925 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004926{
4927 if (data == nullptr)
4928 {
4929 return;
4930 }
4931
4932 Buffer *buffer = mGLState.getTargetBuffer(target);
4933 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004934 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004935}
4936
Jamie Madillef300b12016-10-07 15:12:09 -04004937void Context::attachShader(GLuint program, GLuint shader)
4938{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05004939 Program *programObject = mState.mShaderPrograms->getProgram(program);
4940 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004941 ASSERT(programObject && shaderObject);
4942 programObject->attachShader(shaderObject);
4943}
4944
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004945const Workarounds &Context::getWorkarounds() const
4946{
4947 return mWorkarounds;
4948}
4949
Corentin Wallez336129f2017-10-17 15:55:40 -04004950void Context::copyBufferSubData(BufferBinding readTarget,
4951 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04004952 GLintptr readOffset,
4953 GLintptr writeOffset,
4954 GLsizeiptr size)
4955{
4956 // if size is zero, the copy is a successful no-op
4957 if (size == 0)
4958 {
4959 return;
4960 }
4961
4962 // TODO(jmadill): cache these.
4963 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4964 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4965
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004966 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004967}
4968
Jamie Madill01a80ee2016-11-07 12:06:18 -05004969void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4970{
4971 Program *programObject = getProgram(program);
4972 // TODO(jmadill): Re-use this from the validation if possible.
4973 ASSERT(programObject);
4974 programObject->bindAttributeLocation(index, name);
4975}
4976
Corentin Wallez336129f2017-10-17 15:55:40 -04004977void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004978{
Corentin Wallez336129f2017-10-17 15:55:40 -04004979 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4980 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madilld84b6732018-09-06 15:54:35 -04004981 mStateCache.onBufferBindingChange(this);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004982}
4983
Corentin Wallez336129f2017-10-17 15:55:40 -04004984void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08004985{
4986 bindBufferRange(target, index, buffer, 0, 0);
4987}
4988
Corentin Wallez336129f2017-10-17 15:55:40 -04004989void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08004990 GLuint index,
4991 GLuint buffer,
4992 GLintptr offset,
4993 GLsizeiptr size)
4994{
Jamie Madill6d32cef2018-08-14 02:34:28 -04004995 Buffer *object = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4996 mGLState.setIndexedBufferBinding(this, target, index, object, offset, size);
4997 if (target == BufferBinding::Uniform)
4998 {
4999 mUniformBufferObserverBindings[index].bind(object ? object->getImplementation() : nullptr);
Jamie Madilld84b6732018-09-06 15:54:35 -04005000 mStateCache.onUniformBufferStateChange(this);
5001 }
5002 else
5003 {
5004 mStateCache.onBufferBindingChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04005005 }
Jiajia Qin6eafb042016-12-27 17:04:07 +08005006}
5007
Jamie Madill01a80ee2016-11-07 12:06:18 -05005008void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
5009{
5010 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
5011 {
5012 bindReadFramebuffer(framebuffer);
5013 }
5014
5015 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
5016 {
5017 bindDrawFramebuffer(framebuffer);
5018 }
5019}
5020
5021void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
5022{
5023 ASSERT(target == GL_RENDERBUFFER);
5024 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05005025 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04005026 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005027}
5028
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005029void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08005030 GLsizei samples,
5031 GLenum internalformat,
5032 GLsizei width,
5033 GLsizei height,
5034 GLboolean fixedsamplelocations)
5035{
5036 Extents size(width, height, 1);
5037 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005038 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
5039 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08005040}
5041
Olli Etuaho89664842018-08-24 14:45:36 +03005042void Context::texStorage3DMultisample(TextureType target,
5043 GLsizei samples,
5044 GLenum internalformat,
5045 GLsizei width,
5046 GLsizei height,
5047 GLsizei depth,
5048 GLboolean fixedsamplelocations)
5049{
Olli Etuaho0c5a9e22018-08-27 14:36:23 +03005050 Extents size(width, height, depth);
5051 Texture *texture = getTargetTexture(target);
5052 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
5053 ConvertToBool(fixedsamplelocations)));
Olli Etuaho89664842018-08-24 14:45:36 +03005054}
5055
JiangYizhoubddc46b2016-12-09 09:50:51 +08005056void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
5057{
JiangYizhou5b03f472017-01-09 10:22:53 +08005058 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
5059 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillbc918e72018-03-08 09:47:21 -05005060 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
JiangYizhou5b03f472017-01-09 10:22:53 +08005061 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08005062
5063 switch (pname)
5064 {
5065 case GL_SAMPLE_POSITION:
Geoff Lang13455072018-05-09 11:24:43 -04005066 handleError(framebuffer->getSamplePosition(this, index, val));
JiangYizhoubddc46b2016-12-09 09:50:51 +08005067 break;
5068 default:
5069 UNREACHABLE();
5070 }
5071}
5072
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07005073void Context::getMultisamplefvRobust(GLenum pname,
5074 GLuint index,
5075 GLsizei bufSize,
5076 GLsizei *length,
5077 GLfloat *val)
5078{
5079 UNIMPLEMENTED();
5080}
5081
Jamie Madille8fb6402017-02-14 17:56:40 -05005082void Context::renderbufferStorage(GLenum target,
5083 GLenum internalformat,
5084 GLsizei width,
5085 GLsizei height)
5086{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005087 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
5088 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
5089
Jamie Madille8fb6402017-02-14 17:56:40 -05005090 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04005091 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05005092}
5093
5094void Context::renderbufferStorageMultisample(GLenum target,
5095 GLsizei samples,
5096 GLenum internalformat,
5097 GLsizei width,
5098 GLsizei height)
5099{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005100 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
5101 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05005102
5103 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005104 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04005105 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05005106}
5107
Geoff Lang38f2cfb2017-04-11 15:23:08 -04005108void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
5109{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005110 const Sync *syncObject = getSync(sync);
Jamie Madilla0691b72018-07-25 10:41:22 -04005111 handleError(QuerySynciv(this, syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04005112}
5113
JiangYizhoue18e6392017-02-20 10:32:23 +08005114void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
5115{
5116 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5117 QueryFramebufferParameteriv(framebuffer, pname, params);
5118}
5119
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07005120void Context::getFramebufferParameterivRobust(GLenum target,
5121 GLenum pname,
5122 GLsizei bufSize,
5123 GLsizei *length,
5124 GLint *params)
5125{
5126 UNIMPLEMENTED();
5127}
5128
Jiajia Qin5451d532017-11-16 17:16:34 +08005129void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08005130{
5131 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillb983a4b2018-08-01 11:34:51 -04005132 SetFramebufferParameteri(this, framebuffer, pname, param);
JiangYizhoue18e6392017-02-20 10:32:23 +08005133}
5134
Jamie Madilldec86232018-07-11 09:01:18 -04005135bool Context::getScratchBuffer(size_t requstedSizeBytes,
5136 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05005137{
Jamie Madilldec86232018-07-11 09:01:18 -04005138 return mScratchBuffer.get(requstedSizeBytes, scratchBufferOut);
Jamie Madillb3f26b92017-07-19 15:07:41 -04005139}
5140
Jamie Madilldec86232018-07-11 09:01:18 -04005141bool Context::getZeroFilledBuffer(size_t requstedSizeBytes,
5142 angle::MemoryBuffer **zeroBufferOut) const
Jamie Madillb3f26b92017-07-19 15:07:41 -04005143{
Jamie Madilldec86232018-07-11 09:01:18 -04005144 return mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0);
Jamie Madille14951e2017-03-09 18:55:16 -05005145}
5146
Xinghua Cao10a4d432017-11-28 14:46:26 +08005147Error Context::prepareForDispatch()
5148{
Geoff Langa8cb2872018-03-09 16:09:40 -05005149 ANGLE_TRY(syncState(mComputeDirtyBits, mComputeDirtyObjects));
Xinghua Cao10a4d432017-11-28 14:46:26 +08005150
5151 if (isRobustResourceInitEnabled())
5152 {
5153 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
5154 }
5155
5156 return NoError();
5157}
5158
Xinghua Cao2b396592017-03-29 15:36:04 +08005159void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
5160{
5161 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
5162 {
5163 return;
5164 }
5165
Xinghua Cao10a4d432017-11-28 14:46:26 +08005166 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill71c88b32017-09-14 22:20:29 -04005167 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08005168}
5169
Jiajia Qin5451d532017-11-16 17:16:34 +08005170void Context::dispatchComputeIndirect(GLintptr indirect)
5171{
Qin Jiajia62fcf622017-11-30 16:16:12 +08005172 ANGLE_CONTEXT_TRY(prepareForDispatch());
5173 handleError(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08005174}
5175
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005176void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005177 GLsizei levels,
5178 GLenum internalFormat,
5179 GLsizei width,
5180 GLsizei height)
5181{
5182 Extents size(width, height, 1);
5183 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005184 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005185}
5186
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005187void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005188 GLsizei levels,
5189 GLenum internalFormat,
5190 GLsizei width,
5191 GLsizei height,
5192 GLsizei depth)
5193{
5194 Extents size(width, height, depth);
5195 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005196 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005197}
5198
Jiajia Qin5451d532017-11-16 17:16:34 +08005199void Context::memoryBarrier(GLbitfield barriers)
5200{
Xinghua Cao89c422a2017-11-29 18:24:20 +08005201 handleError(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005202}
5203
5204void Context::memoryBarrierByRegion(GLbitfield barriers)
5205{
Xinghua Cao89c422a2017-11-29 18:24:20 +08005206 handleError(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005207}
5208
Jamie Madillc1d770e2017-04-13 17:31:24 -04005209GLenum Context::checkFramebufferStatus(GLenum target)
5210{
5211 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5212 ASSERT(framebuffer);
Jamie Madill427064d2018-04-13 16:20:34 -04005213 return framebuffer->checkStatus(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005214}
5215
5216void Context::compileShader(GLuint shader)
5217{
5218 Shader *shaderObject = GetValidShader(this, shader);
5219 if (!shaderObject)
5220 {
5221 return;
5222 }
5223 shaderObject->compile(this);
5224}
5225
5226void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
5227{
5228 for (int i = 0; i < n; i++)
5229 {
5230 deleteBuffer(buffers[i]);
5231 }
5232}
5233
5234void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
5235{
5236 for (int i = 0; i < n; i++)
5237 {
5238 if (framebuffers[i] != 0)
5239 {
5240 deleteFramebuffer(framebuffers[i]);
5241 }
5242 }
5243}
5244
5245void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
5246{
5247 for (int i = 0; i < n; i++)
5248 {
5249 deleteRenderbuffer(renderbuffers[i]);
5250 }
5251}
5252
5253void Context::deleteTextures(GLsizei n, const GLuint *textures)
5254{
5255 for (int i = 0; i < n; i++)
5256 {
5257 if (textures[i] != 0)
5258 {
5259 deleteTexture(textures[i]);
5260 }
5261 }
5262}
5263
5264void Context::detachShader(GLuint program, GLuint shader)
5265{
5266 Program *programObject = getProgram(program);
5267 ASSERT(programObject);
5268
5269 Shader *shaderObject = getShader(shader);
5270 ASSERT(shaderObject);
5271
5272 programObject->detachShader(this, shaderObject);
5273}
5274
5275void Context::genBuffers(GLsizei n, GLuint *buffers)
5276{
5277 for (int i = 0; i < n; i++)
5278 {
5279 buffers[i] = createBuffer();
5280 }
5281}
5282
5283void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
5284{
5285 for (int i = 0; i < n; i++)
5286 {
5287 framebuffers[i] = createFramebuffer();
5288 }
5289}
5290
5291void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
5292{
5293 for (int i = 0; i < n; i++)
5294 {
5295 renderbuffers[i] = createRenderbuffer();
5296 }
5297}
5298
5299void Context::genTextures(GLsizei n, GLuint *textures)
5300{
5301 for (int i = 0; i < n; i++)
5302 {
5303 textures[i] = createTexture();
5304 }
5305}
5306
5307void Context::getActiveAttrib(GLuint program,
5308 GLuint index,
5309 GLsizei bufsize,
5310 GLsizei *length,
5311 GLint *size,
5312 GLenum *type,
5313 GLchar *name)
5314{
5315 Program *programObject = getProgram(program);
5316 ASSERT(programObject);
5317 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
5318}
5319
5320void Context::getActiveUniform(GLuint program,
5321 GLuint index,
5322 GLsizei bufsize,
5323 GLsizei *length,
5324 GLint *size,
5325 GLenum *type,
5326 GLchar *name)
5327{
5328 Program *programObject = getProgram(program);
5329 ASSERT(programObject);
5330 programObject->getActiveUniform(index, bufsize, length, size, type, name);
5331}
5332
5333void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
5334{
5335 Program *programObject = getProgram(program);
5336 ASSERT(programObject);
5337 programObject->getAttachedShaders(maxcount, count, shaders);
5338}
5339
5340GLint Context::getAttribLocation(GLuint program, const GLchar *name)
5341{
5342 Program *programObject = getProgram(program);
5343 ASSERT(programObject);
5344 return programObject->getAttributeLocation(name);
5345}
5346
5347void Context::getBooleanv(GLenum pname, GLboolean *params)
5348{
5349 GLenum nativeType;
5350 unsigned int numParams = 0;
5351 getQueryParameterInfo(pname, &nativeType, &numParams);
5352
5353 if (nativeType == GL_BOOL)
5354 {
5355 getBooleanvImpl(pname, params);
5356 }
5357 else
5358 {
5359 CastStateValues(this, nativeType, pname, numParams, params);
5360 }
5361}
5362
Brandon Jones59770802018-04-02 13:18:42 -07005363void Context::getBooleanvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLboolean *params)
5364{
5365 getBooleanv(pname, params);
5366}
5367
Jamie Madillc1d770e2017-04-13 17:31:24 -04005368void Context::getFloatv(GLenum pname, GLfloat *params)
5369{
5370 GLenum nativeType;
5371 unsigned int numParams = 0;
5372 getQueryParameterInfo(pname, &nativeType, &numParams);
5373
5374 if (nativeType == GL_FLOAT)
5375 {
5376 getFloatvImpl(pname, params);
5377 }
5378 else
5379 {
5380 CastStateValues(this, nativeType, pname, numParams, params);
5381 }
5382}
5383
Brandon Jones59770802018-04-02 13:18:42 -07005384void Context::getFloatvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLfloat *params)
5385{
5386 getFloatv(pname, params);
5387}
5388
Jamie Madillc1d770e2017-04-13 17:31:24 -04005389void Context::getIntegerv(GLenum pname, GLint *params)
5390{
5391 GLenum nativeType;
5392 unsigned int numParams = 0;
5393 getQueryParameterInfo(pname, &nativeType, &numParams);
5394
5395 if (nativeType == GL_INT)
5396 {
5397 getIntegervImpl(pname, params);
5398 }
5399 else
5400 {
5401 CastStateValues(this, nativeType, pname, numParams, params);
5402 }
5403}
5404
Brandon Jones59770802018-04-02 13:18:42 -07005405void Context::getIntegervRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint *data)
5406{
5407 getIntegerv(pname, data);
5408}
5409
Jamie Madillc1d770e2017-04-13 17:31:24 -04005410void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
5411{
5412 Program *programObject = getProgram(program);
5413 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04005414 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005415}
5416
Brandon Jones59770802018-04-02 13:18:42 -07005417void Context::getProgramivRobust(GLuint program,
5418 GLenum pname,
5419 GLsizei bufSize,
5420 GLsizei *length,
5421 GLint *params)
5422{
5423 getProgramiv(program, pname, params);
5424}
5425
Jiajia Qin5451d532017-11-16 17:16:34 +08005426void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
5427{
5428 UNIMPLEMENTED();
5429}
5430
Jamie Madillbe849e42017-05-02 15:49:00 -04005431void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005432{
5433 Program *programObject = getProgram(program);
5434 ASSERT(programObject);
5435 programObject->getInfoLog(bufsize, length, infolog);
5436}
5437
Jiajia Qin5451d532017-11-16 17:16:34 +08005438void Context::getProgramPipelineInfoLog(GLuint pipeline,
5439 GLsizei bufSize,
5440 GLsizei *length,
5441 GLchar *infoLog)
5442{
5443 UNIMPLEMENTED();
5444}
5445
Jamie Madillc1d770e2017-04-13 17:31:24 -04005446void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
5447{
5448 Shader *shaderObject = getShader(shader);
5449 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08005450 QueryShaderiv(shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005451}
5452
Brandon Jones59770802018-04-02 13:18:42 -07005453void Context::getShaderivRobust(GLuint shader,
5454 GLenum pname,
5455 GLsizei bufSize,
5456 GLsizei *length,
5457 GLint *params)
5458{
5459 getShaderiv(shader, pname, params);
5460}
5461
Jamie Madillc1d770e2017-04-13 17:31:24 -04005462void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
5463{
5464 Shader *shaderObject = getShader(shader);
5465 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08005466 shaderObject->getInfoLog(bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005467}
5468
5469void Context::getShaderPrecisionFormat(GLenum shadertype,
5470 GLenum precisiontype,
5471 GLint *range,
5472 GLint *precision)
5473{
5474 // TODO(jmadill): Compute shaders.
5475
5476 switch (shadertype)
5477 {
5478 case GL_VERTEX_SHADER:
5479 switch (precisiontype)
5480 {
5481 case GL_LOW_FLOAT:
5482 mCaps.vertexLowpFloat.get(range, precision);
5483 break;
5484 case GL_MEDIUM_FLOAT:
5485 mCaps.vertexMediumpFloat.get(range, precision);
5486 break;
5487 case GL_HIGH_FLOAT:
5488 mCaps.vertexHighpFloat.get(range, precision);
5489 break;
5490
5491 case GL_LOW_INT:
5492 mCaps.vertexLowpInt.get(range, precision);
5493 break;
5494 case GL_MEDIUM_INT:
5495 mCaps.vertexMediumpInt.get(range, precision);
5496 break;
5497 case GL_HIGH_INT:
5498 mCaps.vertexHighpInt.get(range, precision);
5499 break;
5500
5501 default:
5502 UNREACHABLE();
5503 return;
5504 }
5505 break;
5506
5507 case GL_FRAGMENT_SHADER:
5508 switch (precisiontype)
5509 {
5510 case GL_LOW_FLOAT:
5511 mCaps.fragmentLowpFloat.get(range, precision);
5512 break;
5513 case GL_MEDIUM_FLOAT:
5514 mCaps.fragmentMediumpFloat.get(range, precision);
5515 break;
5516 case GL_HIGH_FLOAT:
5517 mCaps.fragmentHighpFloat.get(range, precision);
5518 break;
5519
5520 case GL_LOW_INT:
5521 mCaps.fragmentLowpInt.get(range, precision);
5522 break;
5523 case GL_MEDIUM_INT:
5524 mCaps.fragmentMediumpInt.get(range, precision);
5525 break;
5526 case GL_HIGH_INT:
5527 mCaps.fragmentHighpInt.get(range, precision);
5528 break;
5529
5530 default:
5531 UNREACHABLE();
5532 return;
5533 }
5534 break;
5535
5536 default:
5537 UNREACHABLE();
5538 return;
5539 }
5540}
5541
5542void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
5543{
5544 Shader *shaderObject = getShader(shader);
5545 ASSERT(shaderObject);
5546 shaderObject->getSource(bufsize, length, source);
5547}
5548
5549void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
5550{
5551 Program *programObject = getProgram(program);
5552 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005553 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005554}
5555
Brandon Jones59770802018-04-02 13:18:42 -07005556void Context::getUniformfvRobust(GLuint program,
5557 GLint location,
5558 GLsizei bufSize,
5559 GLsizei *length,
5560 GLfloat *params)
5561{
5562 getUniformfv(program, location, params);
5563}
5564
Jamie Madillc1d770e2017-04-13 17:31:24 -04005565void Context::getUniformiv(GLuint program, GLint location, GLint *params)
5566{
5567 Program *programObject = getProgram(program);
5568 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005569 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005570}
5571
Brandon Jones59770802018-04-02 13:18:42 -07005572void Context::getUniformivRobust(GLuint program,
5573 GLint location,
5574 GLsizei bufSize,
5575 GLsizei *length,
5576 GLint *params)
5577{
5578 getUniformiv(program, location, params);
5579}
5580
Jamie Madillc1d770e2017-04-13 17:31:24 -04005581GLint Context::getUniformLocation(GLuint program, const GLchar *name)
5582{
5583 Program *programObject = getProgram(program);
5584 ASSERT(programObject);
5585 return programObject->getUniformLocation(name);
5586}
5587
5588GLboolean Context::isBuffer(GLuint buffer)
5589{
5590 if (buffer == 0)
5591 {
5592 return GL_FALSE;
5593 }
5594
5595 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
5596}
5597
5598GLboolean Context::isEnabled(GLenum cap)
5599{
5600 return mGLState.getEnableFeature(cap);
5601}
5602
5603GLboolean Context::isFramebuffer(GLuint framebuffer)
5604{
5605 if (framebuffer == 0)
5606 {
5607 return GL_FALSE;
5608 }
5609
5610 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
5611}
5612
5613GLboolean Context::isProgram(GLuint program)
5614{
5615 if (program == 0)
5616 {
5617 return GL_FALSE;
5618 }
5619
5620 return (getProgram(program) ? GL_TRUE : GL_FALSE);
5621}
5622
5623GLboolean Context::isRenderbuffer(GLuint renderbuffer)
5624{
5625 if (renderbuffer == 0)
5626 {
5627 return GL_FALSE;
5628 }
5629
5630 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
5631}
5632
5633GLboolean Context::isShader(GLuint shader)
5634{
5635 if (shader == 0)
5636 {
5637 return GL_FALSE;
5638 }
5639
5640 return (getShader(shader) ? GL_TRUE : GL_FALSE);
5641}
5642
5643GLboolean Context::isTexture(GLuint texture)
5644{
5645 if (texture == 0)
5646 {
5647 return GL_FALSE;
5648 }
5649
5650 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
5651}
5652
5653void Context::linkProgram(GLuint program)
5654{
5655 Program *programObject = getProgram(program);
5656 ASSERT(programObject);
5657 handleError(programObject->link(this));
jchen107ae70d82018-07-06 13:47:01 +08005658
5659 // Don't parallel link a program which is active in any GL contexts. With this assumption, we
5660 // don't need to worry that:
5661 // 1. Draw calls after link use the new executable code or the old one depending on the link
5662 // result.
5663 // 2. When a backend program, e.g., ProgramD3D is linking, other backend classes like
5664 // StateManager11, Renderer11, etc., may have a chance to make unexpected calls to
5665 // ProgramD3D.
5666 if (programObject->isInUse())
5667 {
5668 // isLinked() which forces to resolve linking, will be called.
5669 mGLState.onProgramExecutableChange(programObject);
5670 mStateCache.onProgramExecutableChange(this);
5671 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005672}
5673
5674void Context::releaseShaderCompiler()
5675{
Jamie Madill4928b7c2017-06-20 12:57:39 -04005676 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005677}
5678
5679void Context::shaderBinary(GLsizei n,
5680 const GLuint *shaders,
5681 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04005682 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005683 GLsizei length)
5684{
5685 // No binary shader formats are supported.
5686 UNIMPLEMENTED();
5687}
5688
5689void Context::shaderSource(GLuint shader,
5690 GLsizei count,
5691 const GLchar *const *string,
5692 const GLint *length)
5693{
5694 Shader *shaderObject = getShader(shader);
5695 ASSERT(shaderObject);
5696 shaderObject->setSource(count, string, length);
5697}
5698
5699void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
5700{
5701 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
5702}
5703
5704void Context::stencilMask(GLuint mask)
5705{
5706 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
5707}
5708
5709void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
5710{
5711 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
5712}
5713
5714void Context::uniform1f(GLint location, GLfloat x)
5715{
5716 Program *program = mGLState.getProgram();
5717 program->setUniform1fv(location, 1, &x);
5718}
5719
5720void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
5721{
5722 Program *program = mGLState.getProgram();
5723 program->setUniform1fv(location, count, v);
5724}
5725
Jamie Madill7e4eff12018-08-08 15:49:26 -04005726void Context::setUniform1iImpl(Program *program, GLint location, GLsizei count, const GLint *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005727{
Jamie Madill7e4eff12018-08-08 15:49:26 -04005728 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
Jamie Madill81c2e252017-09-09 23:32:46 -04005729 {
5730 mGLState.setObjectDirty(GL_PROGRAM);
Jamie Madilld84b6732018-09-06 15:54:35 -04005731 mStateCache.onActiveTextureChange(this);
Jamie Madill81c2e252017-09-09 23:32:46 -04005732 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005733}
5734
Jamie Madill7e4eff12018-08-08 15:49:26 -04005735void Context::uniform1i(GLint location, GLint x)
5736{
5737 setUniform1iImpl(mGLState.getProgram(), location, 1, &x);
5738}
5739
Jamie Madillc1d770e2017-04-13 17:31:24 -04005740void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
5741{
Jamie Madill7e4eff12018-08-08 15:49:26 -04005742 setUniform1iImpl(mGLState.getProgram(), location, count, v);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005743}
5744
5745void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
5746{
5747 GLfloat xy[2] = {x, y};
5748 Program *program = mGLState.getProgram();
5749 program->setUniform2fv(location, 1, xy);
5750}
5751
5752void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
5753{
5754 Program *program = mGLState.getProgram();
5755 program->setUniform2fv(location, count, v);
5756}
5757
5758void Context::uniform2i(GLint location, GLint x, GLint y)
5759{
5760 GLint xy[2] = {x, y};
5761 Program *program = mGLState.getProgram();
5762 program->setUniform2iv(location, 1, xy);
5763}
5764
5765void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
5766{
5767 Program *program = mGLState.getProgram();
5768 program->setUniform2iv(location, count, v);
5769}
5770
5771void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
5772{
5773 GLfloat xyz[3] = {x, y, z};
5774 Program *program = mGLState.getProgram();
5775 program->setUniform3fv(location, 1, xyz);
5776}
5777
5778void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
5779{
5780 Program *program = mGLState.getProgram();
5781 program->setUniform3fv(location, count, v);
5782}
5783
5784void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
5785{
5786 GLint xyz[3] = {x, y, z};
5787 Program *program = mGLState.getProgram();
5788 program->setUniform3iv(location, 1, xyz);
5789}
5790
5791void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
5792{
5793 Program *program = mGLState.getProgram();
5794 program->setUniform3iv(location, count, v);
5795}
5796
5797void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
5798{
5799 GLfloat xyzw[4] = {x, y, z, w};
5800 Program *program = mGLState.getProgram();
5801 program->setUniform4fv(location, 1, xyzw);
5802}
5803
5804void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
5805{
5806 Program *program = mGLState.getProgram();
5807 program->setUniform4fv(location, count, v);
5808}
5809
5810void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
5811{
5812 GLint xyzw[4] = {x, y, z, w};
5813 Program *program = mGLState.getProgram();
5814 program->setUniform4iv(location, 1, xyzw);
5815}
5816
5817void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
5818{
5819 Program *program = mGLState.getProgram();
5820 program->setUniform4iv(location, count, v);
5821}
5822
5823void Context::uniformMatrix2fv(GLint location,
5824 GLsizei count,
5825 GLboolean transpose,
5826 const GLfloat *value)
5827{
5828 Program *program = mGLState.getProgram();
5829 program->setUniformMatrix2fv(location, count, transpose, value);
5830}
5831
5832void Context::uniformMatrix3fv(GLint location,
5833 GLsizei count,
5834 GLboolean transpose,
5835 const GLfloat *value)
5836{
5837 Program *program = mGLState.getProgram();
5838 program->setUniformMatrix3fv(location, count, transpose, value);
5839}
5840
5841void Context::uniformMatrix4fv(GLint location,
5842 GLsizei count,
5843 GLboolean transpose,
5844 const GLfloat *value)
5845{
5846 Program *program = mGLState.getProgram();
5847 program->setUniformMatrix4fv(location, count, transpose, value);
5848}
5849
5850void Context::validateProgram(GLuint program)
5851{
5852 Program *programObject = getProgram(program);
5853 ASSERT(programObject);
5854 programObject->validate(mCaps);
5855}
5856
Jiajia Qin5451d532017-11-16 17:16:34 +08005857void Context::validateProgramPipeline(GLuint pipeline)
5858{
5859 UNIMPLEMENTED();
5860}
5861
Jamie Madilld04908b2017-06-09 14:15:35 -04005862void Context::getProgramBinary(GLuint program,
5863 GLsizei bufSize,
5864 GLsizei *length,
5865 GLenum *binaryFormat,
5866 void *binary)
5867{
5868 Program *programObject = getProgram(program);
5869 ASSERT(programObject != nullptr);
5870
5871 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
5872}
5873
5874void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
5875{
5876 Program *programObject = getProgram(program);
5877 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04005878
Jamie Madilld04908b2017-06-09 14:15:35 -04005879 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
Jamie Madillc43cdad2018-08-08 15:49:25 -04005880 mStateCache.onProgramExecutableChange(this);
Jamie Madill70aeda42018-08-20 12:17:40 -04005881 if (programObject->isInUse())
5882 {
5883 mGLState.setObjectDirty(GL_PROGRAM);
5884 }
Jamie Madilld04908b2017-06-09 14:15:35 -04005885}
5886
Jamie Madillff325f12017-08-26 15:06:05 -04005887void Context::uniform1ui(GLint location, GLuint v0)
5888{
5889 Program *program = mGLState.getProgram();
5890 program->setUniform1uiv(location, 1, &v0);
5891}
5892
5893void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
5894{
5895 Program *program = mGLState.getProgram();
5896 const GLuint xy[] = {v0, v1};
5897 program->setUniform2uiv(location, 1, xy);
5898}
5899
5900void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
5901{
5902 Program *program = mGLState.getProgram();
5903 const GLuint xyz[] = {v0, v1, v2};
5904 program->setUniform3uiv(location, 1, xyz);
5905}
5906
5907void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
5908{
5909 Program *program = mGLState.getProgram();
5910 const GLuint xyzw[] = {v0, v1, v2, v3};
5911 program->setUniform4uiv(location, 1, xyzw);
5912}
5913
5914void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
5915{
5916 Program *program = mGLState.getProgram();
5917 program->setUniform1uiv(location, count, value);
5918}
5919void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
5920{
5921 Program *program = mGLState.getProgram();
5922 program->setUniform2uiv(location, count, value);
5923}
5924
5925void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
5926{
5927 Program *program = mGLState.getProgram();
5928 program->setUniform3uiv(location, count, value);
5929}
5930
5931void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
5932{
5933 Program *program = mGLState.getProgram();
5934 program->setUniform4uiv(location, count, value);
5935}
5936
Jamie Madillf0e04492017-08-26 15:28:42 -04005937void Context::genQueries(GLsizei n, GLuint *ids)
5938{
5939 for (GLsizei i = 0; i < n; i++)
5940 {
5941 GLuint handle = mQueryHandleAllocator.allocate();
5942 mQueryMap.assign(handle, nullptr);
5943 ids[i] = handle;
5944 }
5945}
5946
5947void Context::deleteQueries(GLsizei n, const GLuint *ids)
5948{
5949 for (int i = 0; i < n; i++)
5950 {
5951 GLuint query = ids[i];
5952
5953 Query *queryObject = nullptr;
5954 if (mQueryMap.erase(query, &queryObject))
5955 {
5956 mQueryHandleAllocator.release(query);
5957 if (queryObject)
5958 {
5959 queryObject->release(this);
5960 }
5961 }
5962 }
5963}
5964
5965GLboolean Context::isQuery(GLuint id)
5966{
Corentin Wallezad3ae902018-03-09 13:40:42 -05005967 return (getQuery(id, false, QueryType::InvalidEnum) != nullptr) ? GL_TRUE : GL_FALSE;
Jamie Madillf0e04492017-08-26 15:28:42 -04005968}
5969
Jamie Madillc8c95812017-08-26 18:40:09 -04005970void Context::uniformMatrix2x3fv(GLint location,
5971 GLsizei count,
5972 GLboolean transpose,
5973 const GLfloat *value)
5974{
5975 Program *program = mGLState.getProgram();
5976 program->setUniformMatrix2x3fv(location, count, transpose, value);
5977}
5978
5979void Context::uniformMatrix3x2fv(GLint location,
5980 GLsizei count,
5981 GLboolean transpose,
5982 const GLfloat *value)
5983{
5984 Program *program = mGLState.getProgram();
5985 program->setUniformMatrix3x2fv(location, count, transpose, value);
5986}
5987
5988void Context::uniformMatrix2x4fv(GLint location,
5989 GLsizei count,
5990 GLboolean transpose,
5991 const GLfloat *value)
5992{
5993 Program *program = mGLState.getProgram();
5994 program->setUniformMatrix2x4fv(location, count, transpose, value);
5995}
5996
5997void Context::uniformMatrix4x2fv(GLint location,
5998 GLsizei count,
5999 GLboolean transpose,
6000 const GLfloat *value)
6001{
6002 Program *program = mGLState.getProgram();
6003 program->setUniformMatrix4x2fv(location, count, transpose, value);
6004}
6005
6006void Context::uniformMatrix3x4fv(GLint location,
6007 GLsizei count,
6008 GLboolean transpose,
6009 const GLfloat *value)
6010{
6011 Program *program = mGLState.getProgram();
6012 program->setUniformMatrix3x4fv(location, count, transpose, value);
6013}
6014
6015void Context::uniformMatrix4x3fv(GLint location,
6016 GLsizei count,
6017 GLboolean transpose,
6018 const GLfloat *value)
6019{
6020 Program *program = mGLState.getProgram();
6021 program->setUniformMatrix4x3fv(location, count, transpose, value);
6022}
6023
Jamie Madilld7576732017-08-26 18:49:50 -04006024void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
6025{
6026 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
6027 {
6028 GLuint vertexArray = arrays[arrayIndex];
6029
6030 if (arrays[arrayIndex] != 0)
6031 {
6032 VertexArray *vertexArrayObject = nullptr;
6033 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
6034 {
6035 if (vertexArrayObject != nullptr)
6036 {
6037 detachVertexArray(vertexArray);
6038 vertexArrayObject->onDestroy(this);
6039 }
6040
6041 mVertexArrayHandleAllocator.release(vertexArray);
6042 }
6043 }
6044 }
6045}
6046
6047void Context::genVertexArrays(GLsizei n, GLuint *arrays)
6048{
6049 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
6050 {
6051 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
6052 mVertexArrayMap.assign(vertexArray, nullptr);
6053 arrays[arrayIndex] = vertexArray;
6054 }
6055}
6056
6057bool Context::isVertexArray(GLuint array)
6058{
6059 if (array == 0)
6060 {
6061 return GL_FALSE;
6062 }
6063
6064 VertexArray *vao = getVertexArray(array);
6065 return (vao != nullptr ? GL_TRUE : GL_FALSE);
6066}
6067
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006068void Context::endTransformFeedback()
6069{
6070 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6071 transformFeedback->end(this);
Jamie Madilld84b6732018-09-06 15:54:35 -04006072 mStateCache.onTransformFeedbackChange(this);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006073}
6074
6075void Context::transformFeedbackVaryings(GLuint program,
6076 GLsizei count,
6077 const GLchar *const *varyings,
6078 GLenum bufferMode)
6079{
6080 Program *programObject = getProgram(program);
6081 ASSERT(programObject);
6082 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
6083}
6084
6085void Context::getTransformFeedbackVarying(GLuint program,
6086 GLuint index,
6087 GLsizei bufSize,
6088 GLsizei *length,
6089 GLsizei *size,
6090 GLenum *type,
6091 GLchar *name)
6092{
6093 Program *programObject = getProgram(program);
6094 ASSERT(programObject);
6095 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
6096}
6097
6098void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
6099{
6100 for (int i = 0; i < n; i++)
6101 {
6102 GLuint transformFeedback = ids[i];
6103 if (transformFeedback == 0)
6104 {
6105 continue;
6106 }
6107
6108 TransformFeedback *transformFeedbackObject = nullptr;
6109 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
6110 {
6111 if (transformFeedbackObject != nullptr)
6112 {
6113 detachTransformFeedback(transformFeedback);
6114 transformFeedbackObject->release(this);
6115 }
6116
6117 mTransformFeedbackHandleAllocator.release(transformFeedback);
6118 }
6119 }
6120}
6121
6122void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
6123{
6124 for (int i = 0; i < n; i++)
6125 {
6126 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
6127 mTransformFeedbackMap.assign(transformFeedback, nullptr);
6128 ids[i] = transformFeedback;
6129 }
6130}
6131
6132bool Context::isTransformFeedback(GLuint id)
6133{
6134 if (id == 0)
6135 {
6136 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
6137 // returns FALSE
6138 return GL_FALSE;
6139 }
6140
6141 const TransformFeedback *transformFeedback = getTransformFeedback(id);
6142 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
6143}
6144
6145void Context::pauseTransformFeedback()
6146{
6147 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6148 transformFeedback->pause();
6149}
6150
6151void Context::resumeTransformFeedback()
6152{
6153 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6154 transformFeedback->resume();
6155}
6156
Jamie Madill12e957f2017-08-26 21:42:26 -04006157void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
6158{
6159 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04006160 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04006161}
6162
Brandon Jones59770802018-04-02 13:18:42 -07006163void Context::getUniformuivRobust(GLuint program,
6164 GLint location,
6165 GLsizei bufSize,
6166 GLsizei *length,
6167 GLuint *params)
6168{
6169 getUniformuiv(program, location, params);
6170}
6171
Jamie Madill12e957f2017-08-26 21:42:26 -04006172GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
6173{
6174 const Program *programObject = getProgram(program);
6175 return programObject->getFragDataLocation(name);
6176}
6177
6178void Context::getUniformIndices(GLuint program,
6179 GLsizei uniformCount,
6180 const GLchar *const *uniformNames,
6181 GLuint *uniformIndices)
6182{
6183 const Program *programObject = getProgram(program);
6184 if (!programObject->isLinked())
6185 {
6186 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6187 {
6188 uniformIndices[uniformId] = GL_INVALID_INDEX;
6189 }
6190 }
6191 else
6192 {
6193 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6194 {
6195 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
6196 }
6197 }
6198}
6199
6200void Context::getActiveUniformsiv(GLuint program,
6201 GLsizei uniformCount,
6202 const GLuint *uniformIndices,
6203 GLenum pname,
6204 GLint *params)
6205{
6206 const Program *programObject = getProgram(program);
6207 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6208 {
6209 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08006210 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04006211 }
6212}
6213
6214GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
6215{
6216 const Program *programObject = getProgram(program);
6217 return programObject->getUniformBlockIndex(uniformBlockName);
6218}
6219
6220void Context::getActiveUniformBlockiv(GLuint program,
6221 GLuint uniformBlockIndex,
6222 GLenum pname,
6223 GLint *params)
6224{
6225 const Program *programObject = getProgram(program);
6226 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
6227}
6228
Brandon Jones59770802018-04-02 13:18:42 -07006229void Context::getActiveUniformBlockivRobust(GLuint program,
6230 GLuint uniformBlockIndex,
6231 GLenum pname,
6232 GLsizei bufSize,
6233 GLsizei *length,
6234 GLint *params)
6235{
6236 getActiveUniformBlockiv(program, uniformBlockIndex, pname, params);
6237}
6238
Jamie Madill12e957f2017-08-26 21:42:26 -04006239void Context::getActiveUniformBlockName(GLuint program,
6240 GLuint uniformBlockIndex,
6241 GLsizei bufSize,
6242 GLsizei *length,
6243 GLchar *uniformBlockName)
6244{
6245 const Program *programObject = getProgram(program);
6246 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
6247}
6248
6249void Context::uniformBlockBinding(GLuint program,
6250 GLuint uniformBlockIndex,
6251 GLuint uniformBlockBinding)
6252{
6253 Program *programObject = getProgram(program);
6254 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
Jamie Madill70aeda42018-08-20 12:17:40 -04006255
6256 if (programObject->isInUse())
6257 {
6258 mGLState.setObjectDirty(GL_PROGRAM);
Jamie Madilld84b6732018-09-06 15:54:35 -04006259 mStateCache.onUniformBufferStateChange(this);
Jamie Madill70aeda42018-08-20 12:17:40 -04006260 }
Jamie Madill12e957f2017-08-26 21:42:26 -04006261}
6262
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006263GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
6264{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006265 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
6266 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006267
Jamie Madill70b5bb02017-08-28 13:32:37 -04006268 Sync *syncObject = getSync(syncHandle);
Jamie Madilla0691b72018-07-25 10:41:22 -04006269 Error error = syncObject->set(this, condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006270 if (error.isError())
6271 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04006272 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006273 handleError(error);
6274 return nullptr;
6275 }
6276
Jamie Madill70b5bb02017-08-28 13:32:37 -04006277 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006278}
6279
6280GLboolean Context::isSync(GLsync sync)
6281{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006282 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006283}
6284
6285GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6286{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006287 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006288
6289 GLenum result = GL_WAIT_FAILED;
Jamie Madilla0691b72018-07-25 10:41:22 -04006290 handleError(syncObject->clientWait(this, flags, timeout, &result));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006291 return result;
6292}
6293
6294void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6295{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006296 Sync *syncObject = getSync(sync);
Jamie Madilla0691b72018-07-25 10:41:22 -04006297 handleError(syncObject->serverWait(this, flags, timeout));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006298}
6299
6300void Context::getInteger64v(GLenum pname, GLint64 *params)
6301{
6302 GLenum nativeType = GL_NONE;
6303 unsigned int numParams = 0;
6304 getQueryParameterInfo(pname, &nativeType, &numParams);
6305
6306 if (nativeType == GL_INT_64_ANGLEX)
6307 {
6308 getInteger64vImpl(pname, params);
6309 }
6310 else
6311 {
6312 CastStateValues(this, nativeType, pname, numParams, params);
6313 }
6314}
6315
Brandon Jones59770802018-04-02 13:18:42 -07006316void Context::getInteger64vRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint64 *data)
6317{
6318 getInteger64v(pname, data);
6319}
6320
Corentin Wallez336129f2017-10-17 15:55:40 -04006321void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04006322{
6323 Buffer *buffer = mGLState.getTargetBuffer(target);
6324 QueryBufferParameteri64v(buffer, pname, params);
6325}
6326
Brandon Jones59770802018-04-02 13:18:42 -07006327void Context::getBufferParameteri64vRobust(BufferBinding target,
6328 GLenum pname,
6329 GLsizei bufSize,
6330 GLsizei *length,
6331 GLint64 *params)
6332{
6333 getBufferParameteri64v(target, pname, params);
6334}
6335
Jamie Madill3ef140a2017-08-26 23:11:21 -04006336void Context::genSamplers(GLsizei count, GLuint *samplers)
6337{
6338 for (int i = 0; i < count; i++)
6339 {
6340 samplers[i] = mState.mSamplers->createSampler();
6341 }
6342}
6343
6344void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
6345{
6346 for (int i = 0; i < count; i++)
6347 {
6348 GLuint sampler = samplers[i];
6349
6350 if (mState.mSamplers->getSampler(sampler))
6351 {
6352 detachSampler(sampler);
6353 }
6354
6355 mState.mSamplers->deleteObject(this, sampler);
6356 }
6357}
6358
6359void Context::getInternalformativ(GLenum target,
6360 GLenum internalformat,
6361 GLenum pname,
6362 GLsizei bufSize,
6363 GLint *params)
6364{
6365 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
6366 QueryInternalFormativ(formatCaps, pname, bufSize, params);
6367}
6368
Brandon Jones59770802018-04-02 13:18:42 -07006369void Context::getInternalformativRobust(GLenum target,
6370 GLenum internalformat,
6371 GLenum pname,
6372 GLsizei bufSize,
6373 GLsizei *length,
6374 GLint *params)
6375{
6376 getInternalformativ(target, internalformat, pname, bufSize, params);
6377}
6378
Jiajia Qin5451d532017-11-16 17:16:34 +08006379void Context::programUniform1i(GLuint program, GLint location, GLint v0)
6380{
6381 programUniform1iv(program, location, 1, &v0);
6382}
6383
6384void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
6385{
6386 GLint xy[2] = {v0, v1};
6387 programUniform2iv(program, location, 1, xy);
6388}
6389
6390void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
6391{
6392 GLint xyz[3] = {v0, v1, v2};
6393 programUniform3iv(program, location, 1, xyz);
6394}
6395
6396void Context::programUniform4i(GLuint program,
6397 GLint location,
6398 GLint v0,
6399 GLint v1,
6400 GLint v2,
6401 GLint v3)
6402{
6403 GLint xyzw[4] = {v0, v1, v2, v3};
6404 programUniform4iv(program, location, 1, xyzw);
6405}
6406
6407void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
6408{
6409 programUniform1uiv(program, location, 1, &v0);
6410}
6411
6412void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
6413{
6414 GLuint xy[2] = {v0, v1};
6415 programUniform2uiv(program, location, 1, xy);
6416}
6417
6418void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
6419{
6420 GLuint xyz[3] = {v0, v1, v2};
6421 programUniform3uiv(program, location, 1, xyz);
6422}
6423
6424void Context::programUniform4ui(GLuint program,
6425 GLint location,
6426 GLuint v0,
6427 GLuint v1,
6428 GLuint v2,
6429 GLuint v3)
6430{
6431 GLuint xyzw[4] = {v0, v1, v2, v3};
6432 programUniform4uiv(program, location, 1, xyzw);
6433}
6434
6435void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
6436{
6437 programUniform1fv(program, location, 1, &v0);
6438}
6439
6440void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
6441{
6442 GLfloat xy[2] = {v0, v1};
6443 programUniform2fv(program, location, 1, xy);
6444}
6445
6446void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
6447{
6448 GLfloat xyz[3] = {v0, v1, v2};
6449 programUniform3fv(program, location, 1, xyz);
6450}
6451
6452void Context::programUniform4f(GLuint program,
6453 GLint location,
6454 GLfloat v0,
6455 GLfloat v1,
6456 GLfloat v2,
6457 GLfloat v3)
6458{
6459 GLfloat xyzw[4] = {v0, v1, v2, v3};
6460 programUniform4fv(program, location, 1, xyzw);
6461}
6462
Jamie Madill81c2e252017-09-09 23:32:46 -04006463void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6464{
6465 Program *programObject = getProgram(program);
6466 ASSERT(programObject);
Jamie Madill7e4eff12018-08-08 15:49:26 -04006467 setUniform1iImpl(programObject, location, count, value);
Jamie Madill81c2e252017-09-09 23:32:46 -04006468}
6469
Jiajia Qin5451d532017-11-16 17:16:34 +08006470void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6471{
6472 Program *programObject = getProgram(program);
6473 ASSERT(programObject);
6474 programObject->setUniform2iv(location, count, value);
6475}
6476
6477void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6478{
6479 Program *programObject = getProgram(program);
6480 ASSERT(programObject);
6481 programObject->setUniform3iv(location, count, value);
6482}
6483
6484void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6485{
6486 Program *programObject = getProgram(program);
6487 ASSERT(programObject);
6488 programObject->setUniform4iv(location, count, value);
6489}
6490
6491void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6492{
6493 Program *programObject = getProgram(program);
6494 ASSERT(programObject);
6495 programObject->setUniform1uiv(location, count, value);
6496}
6497
6498void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6499{
6500 Program *programObject = getProgram(program);
6501 ASSERT(programObject);
6502 programObject->setUniform2uiv(location, count, value);
6503}
6504
6505void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6506{
6507 Program *programObject = getProgram(program);
6508 ASSERT(programObject);
6509 programObject->setUniform3uiv(location, count, value);
6510}
6511
6512void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6513{
6514 Program *programObject = getProgram(program);
6515 ASSERT(programObject);
6516 programObject->setUniform4uiv(location, count, value);
6517}
6518
6519void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6520{
6521 Program *programObject = getProgram(program);
6522 ASSERT(programObject);
6523 programObject->setUniform1fv(location, count, value);
6524}
6525
6526void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6527{
6528 Program *programObject = getProgram(program);
6529 ASSERT(programObject);
6530 programObject->setUniform2fv(location, count, value);
6531}
6532
6533void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6534{
6535 Program *programObject = getProgram(program);
6536 ASSERT(programObject);
6537 programObject->setUniform3fv(location, count, value);
6538}
6539
6540void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6541{
6542 Program *programObject = getProgram(program);
6543 ASSERT(programObject);
6544 programObject->setUniform4fv(location, count, value);
6545}
6546
6547void Context::programUniformMatrix2fv(GLuint program,
6548 GLint location,
6549 GLsizei count,
6550 GLboolean transpose,
6551 const GLfloat *value)
6552{
6553 Program *programObject = getProgram(program);
6554 ASSERT(programObject);
6555 programObject->setUniformMatrix2fv(location, count, transpose, value);
6556}
6557
6558void Context::programUniformMatrix3fv(GLuint program,
6559 GLint location,
6560 GLsizei count,
6561 GLboolean transpose,
6562 const GLfloat *value)
6563{
6564 Program *programObject = getProgram(program);
6565 ASSERT(programObject);
6566 programObject->setUniformMatrix3fv(location, count, transpose, value);
6567}
6568
6569void Context::programUniformMatrix4fv(GLuint program,
6570 GLint location,
6571 GLsizei count,
6572 GLboolean transpose,
6573 const GLfloat *value)
6574{
6575 Program *programObject = getProgram(program);
6576 ASSERT(programObject);
6577 programObject->setUniformMatrix4fv(location, count, transpose, value);
6578}
6579
6580void Context::programUniformMatrix2x3fv(GLuint program,
6581 GLint location,
6582 GLsizei count,
6583 GLboolean transpose,
6584 const GLfloat *value)
6585{
6586 Program *programObject = getProgram(program);
6587 ASSERT(programObject);
6588 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
6589}
6590
6591void Context::programUniformMatrix3x2fv(GLuint program,
6592 GLint location,
6593 GLsizei count,
6594 GLboolean transpose,
6595 const GLfloat *value)
6596{
6597 Program *programObject = getProgram(program);
6598 ASSERT(programObject);
6599 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
6600}
6601
6602void Context::programUniformMatrix2x4fv(GLuint program,
6603 GLint location,
6604 GLsizei count,
6605 GLboolean transpose,
6606 const GLfloat *value)
6607{
6608 Program *programObject = getProgram(program);
6609 ASSERT(programObject);
6610 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
6611}
6612
6613void Context::programUniformMatrix4x2fv(GLuint program,
6614 GLint location,
6615 GLsizei count,
6616 GLboolean transpose,
6617 const GLfloat *value)
6618{
6619 Program *programObject = getProgram(program);
6620 ASSERT(programObject);
6621 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
6622}
6623
6624void Context::programUniformMatrix3x4fv(GLuint program,
6625 GLint location,
6626 GLsizei count,
6627 GLboolean transpose,
6628 const GLfloat *value)
6629{
6630 Program *programObject = getProgram(program);
6631 ASSERT(programObject);
6632 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
6633}
6634
6635void Context::programUniformMatrix4x3fv(GLuint program,
6636 GLint location,
6637 GLsizei count,
6638 GLboolean transpose,
6639 const GLfloat *value)
6640{
6641 Program *programObject = getProgram(program);
6642 ASSERT(programObject);
6643 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
6644}
6645
Jamie Madill81c2e252017-09-09 23:32:46 -04006646void Context::onTextureChange(const Texture *texture)
6647{
6648 // Conservatively assume all textures are dirty.
6649 // TODO(jmadill): More fine-grained update.
6650 mGLState.setObjectDirty(GL_TEXTURE);
6651}
6652
James Darpiniane8a93c62018-01-04 18:02:24 -08006653bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
6654{
6655 return mGLState.isCurrentTransformFeedback(tf);
6656}
James Darpiniane8a93c62018-01-04 18:02:24 -08006657
Yunchao Hea336b902017-08-02 16:05:21 +08006658void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
6659{
6660 for (int i = 0; i < count; i++)
6661 {
6662 pipelines[i] = createProgramPipeline();
6663 }
6664}
6665
6666void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
6667{
6668 for (int i = 0; i < count; i++)
6669 {
6670 if (pipelines[i] != 0)
6671 {
6672 deleteProgramPipeline(pipelines[i]);
6673 }
6674 }
6675}
6676
6677GLboolean Context::isProgramPipeline(GLuint pipeline)
6678{
6679 if (pipeline == 0)
6680 {
6681 return GL_FALSE;
6682 }
6683
6684 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
6685}
6686
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006687void Context::finishFenceNV(GLuint fence)
6688{
6689 FenceNV *fenceObject = getFenceNV(fence);
6690
6691 ASSERT(fenceObject && fenceObject->isSet());
Jamie Madilla0691b72018-07-25 10:41:22 -04006692 handleError(fenceObject->finish(this));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006693}
6694
6695void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
6696{
6697 FenceNV *fenceObject = getFenceNV(fence);
6698
6699 ASSERT(fenceObject && fenceObject->isSet());
6700
6701 switch (pname)
6702 {
6703 case GL_FENCE_STATUS_NV:
6704 {
6705 // GL_NV_fence spec:
6706 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
6707 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
6708 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
6709 GLboolean status = GL_TRUE;
6710 if (fenceObject->getStatus() != GL_TRUE)
6711 {
Jamie Madilla0691b72018-07-25 10:41:22 -04006712 ANGLE_CONTEXT_TRY(fenceObject->test(this, &status));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006713 }
6714 *params = status;
6715 break;
6716 }
6717
6718 case GL_FENCE_CONDITION_NV:
6719 {
6720 *params = static_cast<GLint>(fenceObject->getCondition());
6721 break;
6722 }
6723
6724 default:
6725 UNREACHABLE();
6726 }
6727}
6728
6729void Context::getTranslatedShaderSource(GLuint shader,
6730 GLsizei bufsize,
6731 GLsizei *length,
6732 GLchar *source)
6733{
6734 Shader *shaderObject = getShader(shader);
6735 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08006736 shaderObject->getTranslatedSourceWithDebugInfo(bufsize, length, source);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006737}
6738
6739void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
6740{
6741 Program *programObject = getProgram(program);
6742 ASSERT(programObject);
6743
6744 programObject->getUniformfv(this, location, params);
6745}
6746
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006747void Context::getnUniformfvRobust(GLuint program,
6748 GLint location,
6749 GLsizei bufSize,
6750 GLsizei *length,
6751 GLfloat *params)
6752{
6753 UNIMPLEMENTED();
6754}
6755
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006756void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
6757{
6758 Program *programObject = getProgram(program);
6759 ASSERT(programObject);
6760
6761 programObject->getUniformiv(this, location, params);
6762}
6763
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006764void Context::getnUniformivRobust(GLuint program,
6765 GLint location,
6766 GLsizei bufSize,
6767 GLsizei *length,
6768 GLint *params)
6769{
6770 UNIMPLEMENTED();
6771}
6772
6773void Context::getnUniformuivRobust(GLuint program,
6774 GLint location,
6775 GLsizei bufSize,
6776 GLsizei *length,
6777 GLuint *params)
6778{
6779 UNIMPLEMENTED();
6780}
6781
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006782GLboolean Context::isFenceNV(GLuint fence)
6783{
6784 FenceNV *fenceObject = getFenceNV(fence);
6785
6786 if (fenceObject == nullptr)
6787 {
6788 return GL_FALSE;
6789 }
6790
6791 // GL_NV_fence spec:
6792 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
6793 // existing fence.
6794 return fenceObject->isSet();
6795}
6796
6797void Context::readnPixels(GLint x,
6798 GLint y,
6799 GLsizei width,
6800 GLsizei height,
6801 GLenum format,
6802 GLenum type,
6803 GLsizei bufSize,
6804 void *data)
6805{
6806 return readPixels(x, y, width, height, format, type, data);
6807}
6808
Jamie Madill007530e2017-12-28 14:27:04 -05006809void Context::setFenceNV(GLuint fence, GLenum condition)
6810{
6811 ASSERT(condition == GL_ALL_COMPLETED_NV);
6812
6813 FenceNV *fenceObject = getFenceNV(fence);
6814 ASSERT(fenceObject != nullptr);
Jamie Madilla0691b72018-07-25 10:41:22 -04006815 handleError(fenceObject->set(this, condition));
Jamie Madill007530e2017-12-28 14:27:04 -05006816}
6817
6818GLboolean Context::testFenceNV(GLuint fence)
6819{
6820 FenceNV *fenceObject = getFenceNV(fence);
6821
6822 ASSERT(fenceObject != nullptr);
6823 ASSERT(fenceObject->isSet() == GL_TRUE);
6824
6825 GLboolean result = GL_TRUE;
Jamie Madilla0691b72018-07-25 10:41:22 -04006826 Error error = fenceObject->test(this, &result);
Jamie Madill007530e2017-12-28 14:27:04 -05006827 if (error.isError())
6828 {
6829 handleError(error);
6830 return GL_TRUE;
6831 }
6832
6833 return result;
6834}
6835
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006836void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006837{
6838 Texture *texture = getTargetTexture(target);
Rafael Cintron05a449a2018-06-20 18:08:04 -07006839 egl::Image *imageObject = static_cast<egl::Image *>(image);
Corentin Wallez99d492c2018-02-27 15:17:10 -05006840 handleError(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05006841}
6842
Jamie Madillfa920eb2018-01-04 11:45:50 -05006843void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006844{
6845 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Rafael Cintron05a449a2018-06-20 18:08:04 -07006846 egl::Image *imageObject = static_cast<egl::Image *>(image);
Jamie Madill007530e2017-12-28 14:27:04 -05006847 handleError(renderbuffer->setStorageEGLImageTarget(this, imageObject));
6848}
6849
Jamie Madillfa920eb2018-01-04 11:45:50 -05006850void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
6851{
6852 UNIMPLEMENTED();
6853}
6854
Jamie Madill5b772312018-03-08 20:28:32 -05006855bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
6856{
6857 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
6858 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
6859 // to the fact that it is stored internally as a float, and so would require conversion
6860 // if returned from Context::getIntegerv. Since this conversion is already implemented
6861 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
6862 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
6863 // application.
6864 switch (pname)
6865 {
6866 case GL_COMPRESSED_TEXTURE_FORMATS:
6867 {
6868 *type = GL_INT;
6869 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
6870 return true;
6871 }
6872 case GL_SHADER_BINARY_FORMATS:
6873 {
6874 *type = GL_INT;
6875 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
6876 return true;
6877 }
6878
6879 case GL_MAX_VERTEX_ATTRIBS:
6880 case GL_MAX_VERTEX_UNIFORM_VECTORS:
6881 case GL_MAX_VARYING_VECTORS:
6882 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
6883 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
6884 case GL_MAX_TEXTURE_IMAGE_UNITS:
6885 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
6886 case GL_MAX_RENDERBUFFER_SIZE:
6887 case GL_NUM_SHADER_BINARY_FORMATS:
6888 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
6889 case GL_ARRAY_BUFFER_BINDING:
6890 case GL_FRAMEBUFFER_BINDING:
6891 case GL_RENDERBUFFER_BINDING:
6892 case GL_CURRENT_PROGRAM:
6893 case GL_PACK_ALIGNMENT:
6894 case GL_UNPACK_ALIGNMENT:
6895 case GL_GENERATE_MIPMAP_HINT:
6896 case GL_RED_BITS:
6897 case GL_GREEN_BITS:
6898 case GL_BLUE_BITS:
6899 case GL_ALPHA_BITS:
6900 case GL_DEPTH_BITS:
6901 case GL_STENCIL_BITS:
6902 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
6903 case GL_CULL_FACE_MODE:
6904 case GL_FRONT_FACE:
6905 case GL_ACTIVE_TEXTURE:
6906 case GL_STENCIL_FUNC:
6907 case GL_STENCIL_VALUE_MASK:
6908 case GL_STENCIL_REF:
6909 case GL_STENCIL_FAIL:
6910 case GL_STENCIL_PASS_DEPTH_FAIL:
6911 case GL_STENCIL_PASS_DEPTH_PASS:
6912 case GL_STENCIL_BACK_FUNC:
6913 case GL_STENCIL_BACK_VALUE_MASK:
6914 case GL_STENCIL_BACK_REF:
6915 case GL_STENCIL_BACK_FAIL:
6916 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
6917 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
6918 case GL_DEPTH_FUNC:
6919 case GL_BLEND_SRC_RGB:
6920 case GL_BLEND_SRC_ALPHA:
6921 case GL_BLEND_DST_RGB:
6922 case GL_BLEND_DST_ALPHA:
6923 case GL_BLEND_EQUATION_RGB:
6924 case GL_BLEND_EQUATION_ALPHA:
6925 case GL_STENCIL_WRITEMASK:
6926 case GL_STENCIL_BACK_WRITEMASK:
6927 case GL_STENCIL_CLEAR_VALUE:
6928 case GL_SUBPIXEL_BITS:
6929 case GL_MAX_TEXTURE_SIZE:
6930 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
6931 case GL_SAMPLE_BUFFERS:
6932 case GL_SAMPLES:
6933 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
6934 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
6935 case GL_TEXTURE_BINDING_2D:
6936 case GL_TEXTURE_BINDING_CUBE_MAP:
6937 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
6938 {
6939 *type = GL_INT;
6940 *numParams = 1;
6941 return true;
6942 }
6943 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6944 {
6945 if (!getExtensions().packReverseRowOrder)
6946 {
6947 return false;
6948 }
6949 *type = GL_INT;
6950 *numParams = 1;
6951 return true;
6952 }
6953 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
6954 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
6955 {
6956 if (!getExtensions().textureRectangle)
6957 {
6958 return false;
6959 }
6960 *type = GL_INT;
6961 *numParams = 1;
6962 return true;
6963 }
6964 case GL_MAX_DRAW_BUFFERS_EXT:
6965 case GL_MAX_COLOR_ATTACHMENTS_EXT:
6966 {
6967 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
6968 {
6969 return false;
6970 }
6971 *type = GL_INT;
6972 *numParams = 1;
6973 return true;
6974 }
6975 case GL_MAX_VIEWPORT_DIMS:
6976 {
6977 *type = GL_INT;
6978 *numParams = 2;
6979 return true;
6980 }
6981 case GL_VIEWPORT:
6982 case GL_SCISSOR_BOX:
6983 {
6984 *type = GL_INT;
6985 *numParams = 4;
6986 return true;
6987 }
6988 case GL_SHADER_COMPILER:
6989 case GL_SAMPLE_COVERAGE_INVERT:
6990 case GL_DEPTH_WRITEMASK:
6991 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
6992 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
6993 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
6994 // bool-natural
6995 case GL_SAMPLE_COVERAGE:
6996 case GL_SCISSOR_TEST:
6997 case GL_STENCIL_TEST:
6998 case GL_DEPTH_TEST:
6999 case GL_BLEND:
7000 case GL_DITHER:
7001 case GL_CONTEXT_ROBUST_ACCESS_EXT:
7002 {
7003 *type = GL_BOOL;
7004 *numParams = 1;
7005 return true;
7006 }
7007 case GL_COLOR_WRITEMASK:
7008 {
7009 *type = GL_BOOL;
7010 *numParams = 4;
7011 return true;
7012 }
7013 case GL_POLYGON_OFFSET_FACTOR:
7014 case GL_POLYGON_OFFSET_UNITS:
7015 case GL_SAMPLE_COVERAGE_VALUE:
7016 case GL_DEPTH_CLEAR_VALUE:
7017 case GL_LINE_WIDTH:
7018 {
7019 *type = GL_FLOAT;
7020 *numParams = 1;
7021 return true;
7022 }
7023 case GL_ALIASED_LINE_WIDTH_RANGE:
7024 case GL_ALIASED_POINT_SIZE_RANGE:
7025 case GL_DEPTH_RANGE:
7026 {
7027 *type = GL_FLOAT;
7028 *numParams = 2;
7029 return true;
7030 }
7031 case GL_COLOR_CLEAR_VALUE:
7032 case GL_BLEND_COLOR:
7033 {
7034 *type = GL_FLOAT;
7035 *numParams = 4;
7036 return true;
7037 }
7038 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
7039 if (!getExtensions().textureFilterAnisotropic)
7040 {
7041 return false;
7042 }
7043 *type = GL_FLOAT;
7044 *numParams = 1;
7045 return true;
7046 case GL_TIMESTAMP_EXT:
7047 if (!getExtensions().disjointTimerQuery)
7048 {
7049 return false;
7050 }
7051 *type = GL_INT_64_ANGLEX;
7052 *numParams = 1;
7053 return true;
7054 case GL_GPU_DISJOINT_EXT:
7055 if (!getExtensions().disjointTimerQuery)
7056 {
7057 return false;
7058 }
7059 *type = GL_INT;
7060 *numParams = 1;
7061 return true;
7062 case GL_COVERAGE_MODULATION_CHROMIUM:
7063 if (!getExtensions().framebufferMixedSamples)
7064 {
7065 return false;
7066 }
7067 *type = GL_INT;
7068 *numParams = 1;
7069 return true;
7070 case GL_TEXTURE_BINDING_EXTERNAL_OES:
7071 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
7072 {
7073 return false;
7074 }
7075 *type = GL_INT;
7076 *numParams = 1;
7077 return true;
7078 }
7079
7080 if (getExtensions().debug)
7081 {
7082 switch (pname)
7083 {
7084 case GL_DEBUG_LOGGED_MESSAGES:
7085 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
7086 case GL_DEBUG_GROUP_STACK_DEPTH:
7087 case GL_MAX_DEBUG_MESSAGE_LENGTH:
7088 case GL_MAX_DEBUG_LOGGED_MESSAGES:
7089 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
7090 case GL_MAX_LABEL_LENGTH:
7091 *type = GL_INT;
7092 *numParams = 1;
7093 return true;
7094
7095 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
7096 case GL_DEBUG_OUTPUT:
7097 *type = GL_BOOL;
7098 *numParams = 1;
7099 return true;
7100 }
7101 }
7102
7103 if (getExtensions().multisampleCompatibility)
7104 {
7105 switch (pname)
7106 {
7107 case GL_MULTISAMPLE_EXT:
7108 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
7109 *type = GL_BOOL;
7110 *numParams = 1;
7111 return true;
7112 }
7113 }
7114
7115 if (getExtensions().pathRendering)
7116 {
7117 switch (pname)
7118 {
7119 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
7120 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
7121 *type = GL_FLOAT;
7122 *numParams = 16;
7123 return true;
7124 }
7125 }
7126
7127 if (getExtensions().bindGeneratesResource)
7128 {
7129 switch (pname)
7130 {
7131 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
7132 *type = GL_BOOL;
7133 *numParams = 1;
7134 return true;
7135 }
7136 }
7137
7138 if (getExtensions().clientArrays)
7139 {
7140 switch (pname)
7141 {
7142 case GL_CLIENT_ARRAYS_ANGLE:
7143 *type = GL_BOOL;
7144 *numParams = 1;
7145 return true;
7146 }
7147 }
7148
7149 if (getExtensions().sRGBWriteControl)
7150 {
7151 switch (pname)
7152 {
7153 case GL_FRAMEBUFFER_SRGB_EXT:
7154 *type = GL_BOOL;
7155 *numParams = 1;
7156 return true;
7157 }
7158 }
7159
7160 if (getExtensions().robustResourceInitialization &&
7161 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
7162 {
7163 *type = GL_BOOL;
7164 *numParams = 1;
7165 return true;
7166 }
7167
7168 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
7169 {
7170 *type = GL_BOOL;
7171 *numParams = 1;
7172 return true;
7173 }
7174
jchen1082af6202018-06-22 10:59:52 +08007175 if (getExtensions().parallelShaderCompile && pname == GL_MAX_SHADER_COMPILER_THREADS_KHR)
7176 {
7177 *type = GL_INT;
7178 *numParams = 1;
7179 return true;
7180 }
7181
Jamie Madill5b772312018-03-08 20:28:32 -05007182 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
7183 switch (pname)
7184 {
7185 // case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE // equivalent to FRAMEBUFFER_BINDING
7186 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
7187 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
7188 {
7189 return false;
7190 }
7191 *type = GL_INT;
7192 *numParams = 1;
7193 return true;
7194
7195 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
7196 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7197 {
7198 return false;
7199 }
7200 *type = GL_INT;
7201 *numParams = 1;
7202 return true;
7203
7204 case GL_PROGRAM_BINARY_FORMATS_OES:
7205 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7206 {
7207 return false;
7208 }
7209 *type = GL_INT;
7210 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
7211 return true;
7212
7213 case GL_PACK_ROW_LENGTH:
7214 case GL_PACK_SKIP_ROWS:
7215 case GL_PACK_SKIP_PIXELS:
7216 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
7217 {
7218 return false;
7219 }
7220 *type = GL_INT;
7221 *numParams = 1;
7222 return true;
7223 case GL_UNPACK_ROW_LENGTH:
7224 case GL_UNPACK_SKIP_ROWS:
7225 case GL_UNPACK_SKIP_PIXELS:
7226 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
7227 {
7228 return false;
7229 }
7230 *type = GL_INT;
7231 *numParams = 1;
7232 return true;
7233 case GL_VERTEX_ARRAY_BINDING:
7234 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
7235 {
7236 return false;
7237 }
7238 *type = GL_INT;
7239 *numParams = 1;
7240 return true;
7241 case GL_PIXEL_PACK_BUFFER_BINDING:
7242 case GL_PIXEL_UNPACK_BUFFER_BINDING:
7243 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
7244 {
7245 return false;
7246 }
7247 *type = GL_INT;
7248 *numParams = 1;
7249 return true;
7250 case GL_MAX_SAMPLES:
7251 {
7252 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
7253 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
7254 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
7255 {
7256 return false;
7257 }
7258 *type = GL_INT;
7259 *numParams = 1;
7260 return true;
7261
7262 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
7263 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
7264 {
7265 return false;
7266 }
7267 *type = GL_INT;
7268 *numParams = 1;
7269 return true;
7270 }
7271 }
7272
7273 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
7274 {
7275 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
7276 {
7277 return false;
7278 }
7279 *type = GL_INT;
7280 *numParams = 1;
7281 return true;
7282 }
7283
7284 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
7285 {
7286 *type = GL_INT;
7287 *numParams = 1;
7288 return true;
7289 }
7290
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007291 if (getClientVersion() < Version(2, 0))
7292 {
7293 switch (pname)
7294 {
7295 case GL_ALPHA_TEST_FUNC:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007296 case GL_CLIENT_ACTIVE_TEXTURE:
7297 case GL_MATRIX_MODE:
7298 case GL_MAX_TEXTURE_UNITS:
7299 case GL_MAX_MODELVIEW_STACK_DEPTH:
7300 case GL_MAX_PROJECTION_STACK_DEPTH:
7301 case GL_MAX_TEXTURE_STACK_DEPTH:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007302 case GL_MAX_LIGHTS:
Lingfeng Yang060088a2018-05-30 20:40:57 -07007303 case GL_MAX_CLIP_PLANES:
Lingfeng Yangabb09f12018-04-16 10:43:53 -07007304 case GL_VERTEX_ARRAY_STRIDE:
7305 case GL_NORMAL_ARRAY_STRIDE:
7306 case GL_COLOR_ARRAY_STRIDE:
7307 case GL_TEXTURE_COORD_ARRAY_STRIDE:
7308 case GL_VERTEX_ARRAY_SIZE:
7309 case GL_COLOR_ARRAY_SIZE:
7310 case GL_TEXTURE_COORD_ARRAY_SIZE:
7311 case GL_VERTEX_ARRAY_TYPE:
7312 case GL_NORMAL_ARRAY_TYPE:
7313 case GL_COLOR_ARRAY_TYPE:
7314 case GL_TEXTURE_COORD_ARRAY_TYPE:
7315 case GL_VERTEX_ARRAY_BUFFER_BINDING:
7316 case GL_NORMAL_ARRAY_BUFFER_BINDING:
7317 case GL_COLOR_ARRAY_BUFFER_BINDING:
7318 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
7319 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
7320 case GL_POINT_SIZE_ARRAY_TYPE_OES:
7321 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
Lingfeng Yanga0cfa872018-05-30 21:12:17 -07007322 case GL_SHADE_MODEL:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07007323 case GL_MODELVIEW_STACK_DEPTH:
7324 case GL_PROJECTION_STACK_DEPTH:
7325 case GL_TEXTURE_STACK_DEPTH:
7326 case GL_LOGIC_OP_MODE:
7327 case GL_BLEND_SRC:
7328 case GL_BLEND_DST:
7329 case GL_PERSPECTIVE_CORRECTION_HINT:
7330 case GL_POINT_SMOOTH_HINT:
7331 case GL_LINE_SMOOTH_HINT:
7332 case GL_FOG_HINT:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007333 *type = GL_INT;
7334 *numParams = 1;
7335 return true;
7336 case GL_ALPHA_TEST_REF:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007337 case GL_FOG_DENSITY:
7338 case GL_FOG_START:
7339 case GL_FOG_END:
7340 case GL_FOG_MODE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007341 case GL_POINT_SIZE:
7342 case GL_POINT_SIZE_MIN:
7343 case GL_POINT_SIZE_MAX:
7344 case GL_POINT_FADE_THRESHOLD_SIZE:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007345 *type = GL_FLOAT;
7346 *numParams = 1;
7347 return true;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007348 case GL_SMOOTH_POINT_SIZE_RANGE:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07007349 case GL_SMOOTH_LINE_WIDTH_RANGE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007350 *type = GL_FLOAT;
7351 *numParams = 2;
7352 return true;
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007353 case GL_CURRENT_COLOR:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007354 case GL_CURRENT_TEXTURE_COORDS:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007355 case GL_LIGHT_MODEL_AMBIENT:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007356 case GL_FOG_COLOR:
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007357 *type = GL_FLOAT;
7358 *numParams = 4;
7359 return true;
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007360 case GL_CURRENT_NORMAL:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007361 case GL_POINT_DISTANCE_ATTENUATION:
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007362 *type = GL_FLOAT;
7363 *numParams = 3;
7364 return true;
Lingfeng Yang3a41af62018-04-09 07:28:56 -07007365 case GL_MODELVIEW_MATRIX:
7366 case GL_PROJECTION_MATRIX:
7367 case GL_TEXTURE_MATRIX:
7368 *type = GL_FLOAT;
7369 *numParams = 16;
7370 return true;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007371 case GL_LIGHT_MODEL_TWO_SIDE:
7372 *type = GL_BOOL;
7373 *numParams = 1;
7374 return true;
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007375 }
7376 }
7377
Jamie Madill5b772312018-03-08 20:28:32 -05007378 if (getClientVersion() < Version(3, 0))
7379 {
7380 return false;
7381 }
7382
7383 // Check for ES3.0+ parameter names
7384 switch (pname)
7385 {
7386 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
7387 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
7388 case GL_UNIFORM_BUFFER_BINDING:
7389 case GL_TRANSFORM_FEEDBACK_BINDING:
7390 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7391 case GL_COPY_READ_BUFFER_BINDING:
7392 case GL_COPY_WRITE_BUFFER_BINDING:
7393 case GL_SAMPLER_BINDING:
7394 case GL_READ_BUFFER:
7395 case GL_TEXTURE_BINDING_3D:
7396 case GL_TEXTURE_BINDING_2D_ARRAY:
7397 case GL_MAX_3D_TEXTURE_SIZE:
7398 case GL_MAX_ARRAY_TEXTURE_LAYERS:
7399 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
7400 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
7401 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
7402 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
7403 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
7404 case GL_MAX_VARYING_COMPONENTS:
7405 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
7406 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
7407 case GL_MIN_PROGRAM_TEXEL_OFFSET:
7408 case GL_MAX_PROGRAM_TEXEL_OFFSET:
7409 case GL_NUM_EXTENSIONS:
7410 case GL_MAJOR_VERSION:
7411 case GL_MINOR_VERSION:
7412 case GL_MAX_ELEMENTS_INDICES:
7413 case GL_MAX_ELEMENTS_VERTICES:
7414 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
7415 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
7416 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
7417 case GL_UNPACK_IMAGE_HEIGHT:
7418 case GL_UNPACK_SKIP_IMAGES:
7419 {
7420 *type = GL_INT;
7421 *numParams = 1;
7422 return true;
7423 }
7424
7425 case GL_MAX_ELEMENT_INDEX:
7426 case GL_MAX_UNIFORM_BLOCK_SIZE:
7427 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
7428 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
7429 case GL_MAX_SERVER_WAIT_TIMEOUT:
7430 {
7431 *type = GL_INT_64_ANGLEX;
7432 *numParams = 1;
7433 return true;
7434 }
7435
7436 case GL_TRANSFORM_FEEDBACK_ACTIVE:
7437 case GL_TRANSFORM_FEEDBACK_PAUSED:
7438 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
7439 case GL_RASTERIZER_DISCARD:
7440 {
7441 *type = GL_BOOL;
7442 *numParams = 1;
7443 return true;
7444 }
7445
7446 case GL_MAX_TEXTURE_LOD_BIAS:
7447 {
7448 *type = GL_FLOAT;
7449 *numParams = 1;
7450 return true;
7451 }
7452 }
7453
7454 if (getExtensions().requestExtension)
7455 {
7456 switch (pname)
7457 {
7458 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
7459 *type = GL_INT;
7460 *numParams = 1;
7461 return true;
7462 }
7463 }
7464
7465 if (getClientVersion() < Version(3, 1))
7466 {
7467 return false;
7468 }
7469
7470 switch (pname)
7471 {
7472 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7473 case GL_DRAW_INDIRECT_BUFFER_BINDING:
7474 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
7475 case GL_MAX_FRAMEBUFFER_WIDTH:
7476 case GL_MAX_FRAMEBUFFER_HEIGHT:
7477 case GL_MAX_FRAMEBUFFER_SAMPLES:
7478 case GL_MAX_SAMPLE_MASK_WORDS:
7479 case GL_MAX_COLOR_TEXTURE_SAMPLES:
7480 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
7481 case GL_MAX_INTEGER_SAMPLES:
7482 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
7483 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
7484 case GL_MAX_VERTEX_ATTRIB_STRIDE:
7485 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
7486 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
7487 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
7488 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
7489 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
7490 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
7491 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
7492 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
7493 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
7494 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
7495 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
7496 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
7497 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
7498 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
7499 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
7500 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
7501 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
7502 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
7503 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
7504 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
7505 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
7506 case GL_MAX_UNIFORM_LOCATIONS:
7507 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
7508 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
7509 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
7510 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
7511 case GL_MAX_IMAGE_UNITS:
7512 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
7513 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
7514 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
7515 case GL_SHADER_STORAGE_BUFFER_BINDING:
7516 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
7517 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
Olli Etuahodff32a02018-08-28 14:35:50 +03007518 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY:
Jamie Madill5b772312018-03-08 20:28:32 -05007519 *type = GL_INT;
7520 *numParams = 1;
7521 return true;
7522 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7523 *type = GL_INT_64_ANGLEX;
7524 *numParams = 1;
7525 return true;
7526 case GL_SAMPLE_MASK:
7527 *type = GL_BOOL;
7528 *numParams = 1;
7529 return true;
7530 }
7531
7532 if (getExtensions().geometryShader)
7533 {
7534 switch (pname)
7535 {
7536 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7537 case GL_LAYER_PROVOKING_VERTEX_EXT:
7538 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7539 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7540 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7541 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7542 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7543 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7544 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7545 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7546 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7547 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7548 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7549 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7550 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7551 *type = GL_INT;
7552 *numParams = 1;
7553 return true;
7554 }
7555 }
7556
7557 return false;
7558}
7559
7560bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7561{
7562 if (getClientVersion() < Version(3, 0))
7563 {
7564 return false;
7565 }
7566
7567 switch (target)
7568 {
7569 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7570 case GL_UNIFORM_BUFFER_BINDING:
7571 {
7572 *type = GL_INT;
7573 *numParams = 1;
7574 return true;
7575 }
7576 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7577 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7578 case GL_UNIFORM_BUFFER_START:
7579 case GL_UNIFORM_BUFFER_SIZE:
7580 {
7581 *type = GL_INT_64_ANGLEX;
7582 *numParams = 1;
7583 return true;
7584 }
7585 }
7586
7587 if (getClientVersion() < Version(3, 1))
7588 {
7589 return false;
7590 }
7591
7592 switch (target)
7593 {
7594 case GL_IMAGE_BINDING_LAYERED:
7595 {
7596 *type = GL_BOOL;
7597 *numParams = 1;
7598 return true;
7599 }
7600 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7601 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7602 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7603 case GL_SHADER_STORAGE_BUFFER_BINDING:
7604 case GL_VERTEX_BINDING_BUFFER:
7605 case GL_VERTEX_BINDING_DIVISOR:
7606 case GL_VERTEX_BINDING_OFFSET:
7607 case GL_VERTEX_BINDING_STRIDE:
7608 case GL_SAMPLE_MASK_VALUE:
7609 case GL_IMAGE_BINDING_NAME:
7610 case GL_IMAGE_BINDING_LEVEL:
7611 case GL_IMAGE_BINDING_LAYER:
7612 case GL_IMAGE_BINDING_ACCESS:
7613 case GL_IMAGE_BINDING_FORMAT:
7614 {
7615 *type = GL_INT;
7616 *numParams = 1;
7617 return true;
7618 }
7619 case GL_ATOMIC_COUNTER_BUFFER_START:
7620 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
7621 case GL_SHADER_STORAGE_BUFFER_START:
7622 case GL_SHADER_STORAGE_BUFFER_SIZE:
7623 {
7624 *type = GL_INT_64_ANGLEX;
7625 *numParams = 1;
7626 return true;
7627 }
7628 }
7629
7630 return false;
7631}
7632
7633Program *Context::getProgram(GLuint handle) const
7634{
7635 return mState.mShaderPrograms->getProgram(handle);
7636}
7637
7638Shader *Context::getShader(GLuint handle) const
7639{
7640 return mState.mShaderPrograms->getShader(handle);
7641}
7642
7643bool Context::isTextureGenerated(GLuint texture) const
7644{
7645 return mState.mTextures->isHandleGenerated(texture);
7646}
7647
Jamie Madill5b772312018-03-08 20:28:32 -05007648bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
7649{
7650 return mState.mRenderbuffers->isHandleGenerated(renderbuffer);
7651}
7652
7653bool Context::isFramebufferGenerated(GLuint framebuffer) const
7654{
7655 return mState.mFramebuffers->isHandleGenerated(framebuffer);
7656}
7657
7658bool Context::isProgramPipelineGenerated(GLuint pipeline) const
7659{
7660 return mState.mPipelines->isHandleGenerated(pipeline);
7661}
7662
7663bool Context::usingDisplayTextureShareGroup() const
7664{
7665 return mDisplayTextureShareGroup;
7666}
7667
7668GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
7669{
7670 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
7671 internalformat == GL_DEPTH_STENCIL
7672 ? GL_DEPTH24_STENCIL8
7673 : internalformat;
7674}
7675
jchen1082af6202018-06-22 10:59:52 +08007676void Context::maxShaderCompilerThreads(GLuint count)
7677{
jchen107ae70d82018-07-06 13:47:01 +08007678 GLuint oldCount = mGLState.getMaxShaderCompilerThreads();
jchen1082af6202018-06-22 10:59:52 +08007679 mGLState.setMaxShaderCompilerThreads(count);
jchen107ae70d82018-07-06 13:47:01 +08007680 // A count of zero specifies a request for no parallel compiling or linking.
7681 if ((oldCount == 0 || count == 0) && (oldCount != 0 || count != 0))
7682 {
7683 mThreadPool = angle::WorkerThreadPool::Create(count > 0);
7684 }
7685 mThreadPool->setMaxThreads(count);
jchen1082af6202018-06-22 10:59:52 +08007686}
7687
Jamie Madill2eb65032018-07-30 10:25:57 -04007688bool Context::isGLES1() const
7689{
7690 return mState.getClientVersion() < Version(2, 0);
7691}
7692
Jamie Madilla11819d2018-07-30 10:26:01 -04007693void Context::onSubjectStateChange(const Context *context,
7694 angle::SubjectIndex index,
7695 angle::SubjectMessage message)
7696{
Jamie Madilla11819d2018-07-30 10:26:01 -04007697 switch (index)
7698 {
7699 case kVertexArraySubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04007700 switch (message)
7701 {
7702 case angle::SubjectMessage::CONTENTS_CHANGED:
7703 mGLState.setObjectDirty(GL_VERTEX_ARRAY);
7704 mStateCache.onVertexArrayBufferContentsChange(this);
7705 break;
7706 case angle::SubjectMessage::RESOURCE_MAPPED:
7707 case angle::SubjectMessage::RESOURCE_UNMAPPED:
7708 case angle::SubjectMessage::BINDING_CHANGED:
7709 mStateCache.onVertexArrayBufferStateChange(this);
7710 break;
7711 default:
7712 break;
7713 }
Jamie Madilla11819d2018-07-30 10:26:01 -04007714 break;
7715
7716 case kReadFramebufferSubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04007717 if (message == angle::SubjectMessage::STORAGE_CHANGED)
7718 {
7719 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
7720 }
Jamie Madilla11819d2018-07-30 10:26:01 -04007721 break;
7722
7723 case kDrawFramebufferSubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04007724 if (message == angle::SubjectMessage::STORAGE_CHANGED)
7725 {
7726 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
7727 }
7728 mStateCache.onDrawFramebufferChange(this);
Jamie Madilla11819d2018-07-30 10:26:01 -04007729 break;
7730
7731 default:
Jamie Madill6d32cef2018-08-14 02:34:28 -04007732 if (index < kTextureMaxSubjectIndex)
7733 {
7734 mGLState.onActiveTextureStateChange(index);
Jamie Madilld84b6732018-09-06 15:54:35 -04007735 mStateCache.onActiveTextureChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04007736 }
7737 else
7738 {
7739 ASSERT(index < kUniformBufferMaxSubjectIndex);
7740 mGLState.onUniformBufferStateChange(index - kUniformBuffer0SubjectIndex);
Jamie Madilld84b6732018-09-06 15:54:35 -04007741 mStateCache.onUniformBufferStateChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04007742 }
Jamie Madilla11819d2018-07-30 10:26:01 -04007743 break;
7744 }
7745}
7746
Jamie Madill6b873dd2018-07-12 23:56:30 -04007747// ErrorSet implementation.
7748ErrorSet::ErrorSet(Context *context) : mContext(context)
7749{
7750}
7751
7752ErrorSet::~ErrorSet() = default;
7753
Jamie Madill306b6c12018-07-27 08:12:49 -04007754void ErrorSet::handleError(const Error &error) const
Jamie Madill6b873dd2018-07-12 23:56:30 -04007755{
7756 // This internal enum is used to filter internal errors that are already handled.
7757 // TODO(jmadill): Remove this when refactor is done. http://anglebug.com/2491
7758 if (error.getCode() == GL_INTERNAL_ERROR_ANGLEX)
7759 {
7760 return;
7761 }
7762
7763 if (ANGLE_UNLIKELY(error.isError()))
7764 {
7765 GLenum code = error.getCode();
7766 mErrors.insert(code);
7767 if (code == GL_OUT_OF_MEMORY && mContext->getWorkarounds().loseContextOnOutOfMemory)
7768 {
7769 mContext->markContextLost();
7770 }
7771
7772 ASSERT(!error.getMessage().empty());
7773 mContext->getGLState().getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR,
7774 error.getID(), GL_DEBUG_SEVERITY_HIGH,
7775 error.getMessage());
7776 }
7777}
7778
7779bool ErrorSet::empty() const
7780{
7781 return mErrors.empty();
7782}
7783
7784GLenum ErrorSet::popError()
7785{
7786 ASSERT(!empty());
7787 GLenum error = *mErrors.begin();
7788 mErrors.erase(mErrors.begin());
7789 return error;
7790}
Jamie Madilldc358af2018-07-31 11:22:13 -04007791
7792// StateCache implementation.
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04007793StateCache::StateCache()
7794 : mCachedHasAnyEnabledClientAttrib(false),
7795 mCachedNonInstancedVertexElementLimit(0),
Jamie Madilld84b6732018-09-06 15:54:35 -04007796 mCachedInstancedVertexElementLimit(0),
7797 mCachedBasicDrawStatesError(kInvalidPointer)
Jamie Madilldc358af2018-07-31 11:22:13 -04007798{
7799}
7800
7801StateCache::~StateCache() = default;
7802
7803void StateCache::updateActiveAttribsMask(Context *context)
7804{
7805 bool isGLES1 = context->isGLES1();
7806 const State &glState = context->getGLState();
7807
7808 if (!isGLES1 && !glState.getProgram())
7809 {
7810 mCachedActiveBufferedAttribsMask = AttributesMask();
7811 mCachedActiveClientAttribsMask = AttributesMask();
Jamie Madill86792f42018-08-30 16:18:34 -04007812 mCachedActiveDefaultAttribsMask = AttributesMask();
Jamie Madilldc358af2018-07-31 11:22:13 -04007813 return;
7814 }
7815
7816 AttributesMask activeAttribs = isGLES1 ? glState.gles1().getVertexArraysAttributeMask()
7817 : glState.getProgram()->getActiveAttribLocationsMask();
7818
7819 const VertexArray *vao = glState.getVertexArray();
7820 ASSERT(vao);
7821
7822 const AttributesMask &clientAttribs = vao->getClientAttribsMask();
7823 const AttributesMask &enabledAttribs = vao->getEnabledAttributesMask();
Jamie Madill0a17e482018-08-31 17:19:11 -04007824 const AttributesMask &activeEnabled = activeAttribs & enabledAttribs;
Jamie Madilldc358af2018-07-31 11:22:13 -04007825
Jamie Madill0a17e482018-08-31 17:19:11 -04007826 mCachedActiveClientAttribsMask = activeEnabled & clientAttribs;
7827 mCachedActiveBufferedAttribsMask = activeEnabled & ~clientAttribs;
Jamie Madill86792f42018-08-30 16:18:34 -04007828 mCachedActiveDefaultAttribsMask = activeAttribs & ~enabledAttribs;
Jamie Madilldc358af2018-07-31 11:22:13 -04007829 mCachedHasAnyEnabledClientAttrib = (clientAttribs & enabledAttribs).any();
7830}
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04007831
7832void StateCache::updateVertexElementLimits(Context *context)
7833{
7834 const VertexArray *vao = context->getGLState().getVertexArray();
7835
7836 mCachedNonInstancedVertexElementLimit = std::numeric_limits<GLint64>::max();
7837 mCachedInstancedVertexElementLimit = std::numeric_limits<GLint64>::max();
7838
7839 // VAO can be null on Context startup. If we make this computation lazier we could ASSERT.
7840 // If there are no buffered attributes then we should not limit the draw call count.
7841 if (!vao || !mCachedActiveBufferedAttribsMask.any())
7842 {
7843 return;
7844 }
7845
7846 const auto &vertexAttribs = vao->getVertexAttributes();
7847 const auto &vertexBindings = vao->getVertexBindings();
7848
7849 for (size_t attributeIndex : mCachedActiveBufferedAttribsMask)
7850 {
7851 const VertexAttribute &attrib = vertexAttribs[attributeIndex];
7852 ASSERT(attrib.enabled);
7853
7854 const VertexBinding &binding = vertexBindings[attrib.bindingIndex];
7855 ASSERT(context->isGLES1() ||
7856 context->getGLState().getProgram()->isAttribLocationActive(attributeIndex));
7857
7858 GLint64 limit = attrib.getCachedElementLimit();
7859 if (binding.getDivisor() > 0)
7860 {
7861 mCachedInstancedVertexElementLimit =
7862 std::min(mCachedInstancedVertexElementLimit, limit);
7863 }
7864 else
7865 {
7866 mCachedNonInstancedVertexElementLimit =
7867 std::min(mCachedNonInstancedVertexElementLimit, limit);
7868 }
7869 }
7870}
Jamie Madillc43cdad2018-08-08 15:49:25 -04007871
Jamie Madilld84b6732018-09-06 15:54:35 -04007872void StateCache::updateBasicDrawStatesError()
7873{
7874 mCachedBasicDrawStatesError = kInvalidPointer;
7875}
7876
7877intptr_t StateCache::getBasicDrawStatesErrorImpl(Context *context) const
7878{
7879 ASSERT(mCachedBasicDrawStatesError == kInvalidPointer);
7880 mCachedBasicDrawStatesError = reinterpret_cast<intptr_t>(ValidateDrawStates(context));
7881 return mCachedBasicDrawStatesError;
7882}
7883
Jamie Madillc43cdad2018-08-08 15:49:25 -04007884void StateCache::onVertexArrayBindingChange(Context *context)
7885{
7886 updateActiveAttribsMask(context);
7887 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04007888 updateBasicDrawStatesError();
Jamie Madillc43cdad2018-08-08 15:49:25 -04007889}
7890
7891void StateCache::onProgramExecutableChange(Context *context)
7892{
7893 updateActiveAttribsMask(context);
7894 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04007895 updateBasicDrawStatesError();
Jamie Madill526a6f62018-09-12 11:03:05 -04007896 updateValidDrawModes(context);
Jamie Madillc43cdad2018-08-08 15:49:25 -04007897}
7898
Jamie Madilld84b6732018-09-06 15:54:35 -04007899void StateCache::onVertexArrayFormatChange(Context *context)
Jamie Madillc43cdad2018-08-08 15:49:25 -04007900{
7901 updateVertexElementLimits(context);
7902}
7903
Jamie Madilld84b6732018-09-06 15:54:35 -04007904void StateCache::onVertexArrayBufferContentsChange(Context *context)
7905{
7906 updateVertexElementLimits(context);
7907 updateBasicDrawStatesError();
7908}
7909
Jamie Madillc43cdad2018-08-08 15:49:25 -04007910void StateCache::onVertexArrayStateChange(Context *context)
7911{
7912 updateActiveAttribsMask(context);
7913 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04007914 updateBasicDrawStatesError();
7915}
7916
7917void StateCache::onVertexArrayBufferStateChange(Context *context)
7918{
7919 updateBasicDrawStatesError();
Jamie Madillc43cdad2018-08-08 15:49:25 -04007920}
7921
7922void StateCache::onGLES1ClientStateChange(Context *context)
7923{
7924 updateActiveAttribsMask(context);
7925}
Jamie Madilld84b6732018-09-06 15:54:35 -04007926
7927void StateCache::onDrawFramebufferChange(Context *context)
7928{
7929 updateBasicDrawStatesError();
7930}
7931
7932void StateCache::onContextCapChange(Context *context)
7933{
7934 updateBasicDrawStatesError();
7935}
7936
7937void StateCache::onStencilStateChange(Context *context)
7938{
7939 updateBasicDrawStatesError();
7940}
7941
7942void StateCache::onDefaultVertexAttributeChange(Context *context)
7943{
7944 updateBasicDrawStatesError();
7945}
7946
7947void StateCache::onActiveTextureChange(Context *context)
7948{
7949 updateBasicDrawStatesError();
7950}
7951
7952void StateCache::onQueryChange(Context *context)
7953{
7954 updateBasicDrawStatesError();
7955}
7956
7957void StateCache::onTransformFeedbackChange(Context *context)
7958{
7959 updateBasicDrawStatesError();
7960}
7961
7962void StateCache::onUniformBufferStateChange(Context *context)
7963{
7964 updateBasicDrawStatesError();
7965}
7966
7967void StateCache::onBufferBindingChange(Context *context)
7968{
7969 updateBasicDrawStatesError();
7970}
Jamie Madill526a6f62018-09-12 11:03:05 -04007971
7972void StateCache::updateValidDrawModes(Context *context)
7973{
7974 Program *program = context->getGLState().getProgram();
7975 if (!program || !program->hasLinkedShaderStage(ShaderType::Geometry))
7976 {
7977 mCachedValidDrawModes = {{
7978 true, /* Points */
7979 true, /* Lines */
7980 true, /* LineLoop */
7981 true, /* LineStrip */
7982 true, /* Triangles */
7983 true, /* TriangleStrip */
7984 true, /* TriangleFan */
7985 false, /* LinesAdjacency */
7986 false, /* LineStripAdjacency */
7987 false, /* TrianglesAdjacency */
7988 false, /* TriangleStripAdjacency */
7989 false, /* InvalidEnum */
7990 }};
7991 }
7992 else
7993 {
7994 ASSERT(program && program->hasLinkedShaderStage(ShaderType::Geometry));
7995
7996 PrimitiveMode gsMode = program->getGeometryShaderInputPrimitiveType();
7997
7998 mCachedValidDrawModes = {{
7999 gsMode == PrimitiveMode::Points, /* Points */
8000 gsMode == PrimitiveMode::Lines, /* Lines */
8001 gsMode == PrimitiveMode::Lines, /* LineLoop */
8002 gsMode == PrimitiveMode::Lines, /* LineStrip */
8003 gsMode == PrimitiveMode::Triangles, /* Triangles */
8004 gsMode == PrimitiveMode::Triangles, /* TriangleStrip */
8005 gsMode == PrimitiveMode::Triangles, /* TriangleFan */
8006 gsMode == PrimitiveMode::LinesAdjacency, /* LinesAdjacency */
8007 gsMode == PrimitiveMode::LinesAdjacency, /* LineStripAdjacency */
8008 gsMode == PrimitiveMode::TrianglesAdjacency, /* TrianglesAdjacency */
8009 gsMode == PrimitiveMode::TrianglesAdjacency, /* TriangleStripAdjacency */
8010 false, /* InvalidEnum */
8011 }};
8012 }
8013}
Jamie Madillc29968b2016-01-20 11:17:23 -05008014} // namespace gl