blob: a307400a32e74c020e7067211ac48d0e1827fdc2 [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{
Jamie Madillf4d429c2018-09-13 11:20:52 -0400201 // TODO(jmadill): Remove this. http://anglebug.com/2806
202 return (attribs.get(EGL_CONTEXT_WEBGL_COMPATIBILITY_ANGLE, EGL_FALSE) == EGL_TRUE) ||
203 (attribs.get(EGL_CONTEXT_WEBGL_COMPATIBILITY_ANGLE_OLD, EGL_FALSE) == EGL_TRUE);
Geoff Langc287ea62016-09-16 14:46:51 -0400204}
205
Geoff Lang0ab41fa2018-03-14 11:03:30 -0400206bool GetExtensionsEnabled(const egl::AttributeMap &attribs, bool webGLContext)
207{
208 // If the context is WebGL, extensions are disabled by default
209 EGLAttrib defaultValue = webGLContext ? EGL_FALSE : EGL_TRUE;
210 return (attribs.get(EGL_EXTENSIONS_ENABLED_ANGLE, defaultValue) == EGL_TRUE);
211}
212
Geoff Langf41a7152016-09-19 15:11:17 -0400213bool GetBindGeneratesResource(const egl::AttributeMap &attribs)
214{
Jamie Madillf4d429c2018-09-13 11:20:52 -0400215 // TODO(jmadill): Remove this. http://anglebug.com/2806
216 if (attribs.contains(EGL_CONTEXT_BIND_GENERATES_RESOURCE_CHROMIUM))
217 {
218 return (attribs.get(EGL_CONTEXT_BIND_GENERATES_RESOURCE_CHROMIUM, EGL_TRUE) == EGL_TRUE);
219 }
220 else
221 {
222 return (attribs.get(EGL_CONTEXT_BIND_GENERATES_RESOURCE_CHROMIUM_OLD, EGL_TRUE) ==
223 EGL_TRUE);
224 }
Geoff Langf41a7152016-09-19 15:11:17 -0400225}
226
Geoff Langfeb8c682017-02-13 16:07:35 -0500227bool GetClientArraysEnabled(const egl::AttributeMap &attribs)
228{
229 return (attribs.get(EGL_CONTEXT_CLIENT_ARRAYS_ENABLED_ANGLE, EGL_TRUE) == EGL_TRUE);
230}
231
Geoff Langb433e872017-10-05 14:01:47 -0400232bool GetRobustResourceInit(const egl::AttributeMap &attribs)
233{
234 return (attribs.get(EGL_ROBUST_RESOURCE_INITIALIZATION_ANGLE, EGL_FALSE) == EGL_TRUE);
235}
236
Martin Radev9d901792016-07-15 15:58:58 +0300237std::string GetObjectLabelFromPointer(GLsizei length, const GLchar *label)
238{
239 std::string labelName;
240 if (label != nullptr)
241 {
242 size_t labelLength = length < 0 ? strlen(label) : length;
243 labelName = std::string(label, labelLength);
244 }
245 return labelName;
246}
247
248void GetObjectLabelBase(const std::string &objectLabel,
249 GLsizei bufSize,
250 GLsizei *length,
251 GLchar *label)
252{
253 size_t writeLength = objectLabel.length();
254 if (label != nullptr && bufSize > 0)
255 {
256 writeLength = std::min(static_cast<size_t>(bufSize) - 1, objectLabel.length());
257 std::copy(objectLabel.begin(), objectLabel.begin() + writeLength, label);
258 label[writeLength] = '\0';
259 }
260
261 if (length != nullptr)
262 {
263 *length = static_cast<GLsizei>(writeLength);
264 }
265}
266
Jamie Madill0f80ed82017-09-19 00:24:56 -0400267template <typename CapT, typename MaxT>
268void LimitCap(CapT *cap, MaxT maximum)
269{
270 *cap = std::min(*cap, static_cast<CapT>(maximum));
271}
272
Tobin Ehlisd7890bc2018-06-29 11:57:22 -0600273constexpr angle::PackedEnumMap<gl::PrimitiveMode, GLsizei> kMinimumPrimitiveCounts = {{
Jamie Madill526a6f62018-09-12 11:03:05 -0400274 1, /* Points */
275 2, /* Lines */
276 2, /* LineLoop */
277 2, /* LineStrip */
278 3, /* Triangles */
279 3, /* TriangleStrip */
280 3, /* TriangleFan */
281 2, /* LinesAdjacency */
282 2, /* LineStripAdjacency */
283 3, /* TrianglesAdjacency */
284 3, /* TriangleStripAdjacency */
Tobin Ehlisd7890bc2018-06-29 11:57:22 -0600285}};
286// Indices above are code-gen'd so make sure they don't change
287// if any of these static asserts are hit, must update kMinimumPrimitiveCounts abouve
288static_assert(static_cast<gl::PrimitiveMode>(0) == gl::PrimitiveMode::Points,
289 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
290static_assert(static_cast<gl::PrimitiveMode>(1) == gl::PrimitiveMode::Lines,
291 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
292static_assert(static_cast<gl::PrimitiveMode>(2) == gl::PrimitiveMode::LineLoop,
293 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
294static_assert(static_cast<gl::PrimitiveMode>(3) == gl::PrimitiveMode::LineStrip,
295 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
296static_assert(static_cast<gl::PrimitiveMode>(4) == gl::PrimitiveMode::Triangles,
297 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
298static_assert(static_cast<gl::PrimitiveMode>(5) == gl::PrimitiveMode::TriangleStrip,
299 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
300static_assert(static_cast<gl::PrimitiveMode>(6) == gl::PrimitiveMode::TriangleFan,
301 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
302static_assert(static_cast<gl::PrimitiveMode>(7) == gl::PrimitiveMode::LinesAdjacency,
303 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
304static_assert(static_cast<gl::PrimitiveMode>(8) == gl::PrimitiveMode::LineStripAdjacency,
305 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
306static_assert(static_cast<gl::PrimitiveMode>(9) == gl::PrimitiveMode::TrianglesAdjacency,
307 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
308static_assert(static_cast<gl::PrimitiveMode>(10) == gl::PrimitiveMode::TriangleStripAdjacency,
309 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
310static_assert(static_cast<gl::PrimitiveMode>(11) == gl::PrimitiveMode::EnumCount,
311 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
312
Jamie Madill6d32cef2018-08-14 02:34:28 -0400313enum SubjectIndexes : angle::SubjectIndex
314{
315 kTexture0SubjectIndex = 0,
316 kTextureMaxSubjectIndex = kTexture0SubjectIndex + gl::IMPLEMENTATION_MAX_ACTIVE_TEXTURES,
317 kUniformBuffer0SubjectIndex = kTextureMaxSubjectIndex,
318 kUniformBufferMaxSubjectIndex =
319 kUniformBuffer0SubjectIndex + gl::IMPLEMENTATION_MAX_UNIFORM_BUFFER_BINDINGS,
320 kVertexArraySubjectIndex = kUniformBufferMaxSubjectIndex,
321 kReadFramebufferSubjectIndex,
322 kDrawFramebufferSubjectIndex
323};
Geoff Langf6db0982015-08-25 13:04:00 -0400324} // anonymous namespace
325
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000326namespace gl
327{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +0000328
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400329Context::Context(rx::EGLImplFactory *implFactory,
330 const egl::Config *config,
Corentin Wallez51706ea2015-08-07 14:39:22 -0400331 const Context *shareContext,
Geoff Langce02f082017-02-06 16:46:21 -0500332 TextureManager *shareTextures,
Jamie Madill32447362017-06-28 14:53:52 -0400333 MemoryProgramCache *memoryProgramCache,
Corentin Wallezc295e512017-01-27 17:47:50 -0500334 const egl::AttributeMap &attribs,
Brandon Jones2b0cdcc2018-05-02 08:02:50 -0700335 const egl::DisplayExtensions &displayExtensions,
336 const egl::ClientExtensions &clientExtensions)
Jamie Madill5b772312018-03-08 20:28:32 -0500337 : mState(reinterpret_cast<ContextID>(this),
338 shareContext ? &shareContext->mState : nullptr,
339 shareTextures,
340 GetClientVersion(attribs),
341 &mGLState,
342 mCaps,
343 mTextureCaps,
344 mExtensions,
345 mLimitations),
346 mSkipValidation(GetNoError(attribs)),
347 mDisplayTextureShareGroup(shareTextures != nullptr),
348 mSavedArgsType(nullptr),
Geoff Lang3cacf692018-06-20 16:49:57 -0400349 mImplementation(implFactory->createContext(mState, config, shareContext, attribs)),
Geoff Lang75359662018-04-11 01:42:27 -0400350 mLabel(nullptr),
Jamie Madill2f348d22017-06-05 10:50:59 -0400351 mCompiler(),
Geoff Lang4fb8a8b2018-06-01 16:47:57 -0400352 mGLState(GetDebug(attribs),
353 GetBindGeneratesResource(attribs),
354 GetClientArraysEnabled(attribs),
355 GetRobustResourceInit(attribs),
356 memoryProgramCache != nullptr),
Corentin Walleze3b10e82015-05-20 11:06:25 -0400357 mConfig(config),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500358 mClientType(EGL_OPENGL_ES_API),
Jamie Madill6b873dd2018-07-12 23:56:30 -0400359 mErrors(this),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500360 mHasBeenCurrent(false),
361 mContextLost(false),
362 mResetStatus(GL_NO_ERROR),
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700363 mContextLostForced(false),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500364 mResetStrategy(GetResetStrategy(attribs)),
365 mRobustAccess(GetRobustAccess(attribs)),
Geoff Lang33f11fb2018-05-07 13:42:47 -0400366 mSurfacelessSupported(displayExtensions.surfacelessContext),
367 mExplicitContextAvailable(clientExtensions.explicitContext),
Jamie Madill61e16b42017-06-19 11:13:23 -0400368 mCurrentSurface(static_cast<egl::Surface *>(EGL_NO_SURFACE)),
369 mCurrentDisplay(static_cast<egl::Display *>(EGL_NO_DISPLAY)),
Jamie Madille14951e2017-03-09 18:55:16 -0500370 mWebGLContext(GetWebGLContext(attribs)),
Geoff Lang0ab41fa2018-03-14 11:03:30 -0400371 mExtensionsEnabled(GetExtensionsEnabled(attribs, mWebGLContext)),
Jamie Madill32447362017-06-28 14:53:52 -0400372 mMemoryProgramCache(memoryProgramCache),
Jamie Madill16e28fd2018-09-12 11:03:05 -0400373 mStateCache(this),
Jamie Madilla11819d2018-07-30 10:26:01 -0400374 mVertexArrayObserverBinding(this, kVertexArraySubjectIndex),
375 mDrawFramebufferObserverBinding(this, kDrawFramebufferSubjectIndex),
376 mReadFramebufferObserverBinding(this, kReadFramebufferSubjectIndex),
Jamie Madillb3f26b92017-07-19 15:07:41 -0400377 mScratchBuffer(1000u),
jchen107ae70d82018-07-06 13:47:01 +0800378 mZeroFilledBuffer(1000u),
379 mThreadPool(nullptr)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000380{
Jamie Madill5b772312018-03-08 20:28:32 -0500381 // Needed to solve a Clang warning of unused variables.
Jamie Madillc6dbc252018-04-30 19:07:56 -0400382 ANGLE_UNUSED_VARIABLE(mSavedArgsType);
383 ANGLE_UNUSED_VARIABLE(mParamsBuffer);
Jamie Madill6d32cef2018-08-14 02:34:28 -0400384
385 for (angle::SubjectIndex uboIndex = kUniformBuffer0SubjectIndex;
386 uboIndex < kUniformBufferMaxSubjectIndex; ++uboIndex)
387 {
388 mUniformBufferObserverBindings.emplace_back(this, uboIndex);
389 }
Geoff Lang33f11fb2018-05-07 13:42:47 -0400390}
Jamie Madill5b772312018-03-08 20:28:32 -0500391
Geoff Lang33f11fb2018-05-07 13:42:47 -0400392void Context::initialize()
393{
394 mImplementation->setMemoryProgramCache(mMemoryProgramCache);
Jamie Madill14bbb3f2017-09-12 15:23:01 -0400395
Geoff Lang33f11fb2018-05-07 13:42:47 -0400396 initCaps();
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700397 initWorkarounds();
Geoff Langc0b9ef42014-07-02 10:02:37 -0400398
Geoff Lang4fb8a8b2018-06-01 16:47:57 -0400399 mGLState.initialize(this);
Régis Fénéon83107972015-02-05 12:57:44 +0100400
Shannon Woods53a94a82014-06-24 15:20:36 -0400401 mFenceNVHandleAllocator.setBaseHandle(0);
Geoff Lang7dca1862013-07-30 16:30:46 -0400402
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000403 // [OpenGL ES 2.0.24] section 3.7 page 83:
Corentin Wallez336129f2017-10-17 15:55:40 -0400404 // In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have two-dimensional
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000405 // and cube map texture state vectors respectively associated with them.
406 // In order that access to these initial textures not be lost, they are treated as texture
407 // objects all of whose names are 0.
408
Corentin Wallez99d492c2018-02-27 15:17:10 -0500409 Texture *zeroTexture2D = new Texture(mImplementation.get(), 0, TextureType::_2D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800410 mZeroTextures[TextureType::_2D].set(this, zeroTexture2D);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500411
Corentin Wallez99d492c2018-02-27 15:17:10 -0500412 Texture *zeroTextureCube = new Texture(mImplementation.get(), 0, TextureType::CubeMap);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800413 mZeroTextures[TextureType::CubeMap].set(this, zeroTextureCube);
Geoff Lang76b10c92014-09-05 16:28:14 -0400414
Geoff Langeb66a6e2016-10-31 13:06:12 -0400415 if (getClientVersion() >= Version(3, 0))
Geoff Lang76b10c92014-09-05 16:28:14 -0400416 {
417 // TODO: These could also be enabled via extension
Corentin Wallez99d492c2018-02-27 15:17:10 -0500418 Texture *zeroTexture3D = new Texture(mImplementation.get(), 0, TextureType::_3D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800419 mZeroTextures[TextureType::_3D].set(this, zeroTexture3D);
Geoff Lang76b10c92014-09-05 16:28:14 -0400420
Corentin Wallez99d492c2018-02-27 15:17:10 -0500421 Texture *zeroTexture2DArray = new Texture(mImplementation.get(), 0, TextureType::_2DArray);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800422 mZeroTextures[TextureType::_2DArray].set(this, zeroTexture2DArray);
Geoff Lang76b10c92014-09-05 16:28:14 -0400423 }
Geoff Lang3b573612016-10-31 14:08:10 -0400424 if (getClientVersion() >= Version(3, 1))
425 {
Olli Etuahod310a432018-08-24 15:40:23 +0300426 // TODO(http://anglebug.com/2775): These could also be enabled via extension
Geoff Lang3b573612016-10-31 14:08:10 -0400427 Texture *zeroTexture2DMultisample =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500428 new Texture(mImplementation.get(), 0, TextureType::_2DMultisample);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800429 mZeroTextures[TextureType::_2DMultisample].set(this, zeroTexture2DMultisample);
Olli Etuahod310a432018-08-24 15:40:23 +0300430 Texture *zeroTexture2DMultisampleArray =
431 new Texture(mImplementation.get(), 0, TextureType::_2DMultisampleArray);
432 mZeroTextures[TextureType::_2DMultisampleArray].set(this, zeroTexture2DMultisampleArray);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800433
Jiajia Qin6eafb042016-12-27 17:04:07 +0800434 for (unsigned int i = 0; i < mCaps.maxAtomicCounterBufferBindings; i++)
435 {
Qin Jiajia339f65b2018-02-27 12:52:48 +0800436 bindBufferRange(BufferBinding::AtomicCounter, i, 0, 0, 0);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800437 }
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800438
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800439 for (unsigned int i = 0; i < mCaps.maxShaderStorageBufferBindings; i++)
440 {
Corentin Wallez336129f2017-10-17 15:55:40 -0400441 bindBufferRange(BufferBinding::ShaderStorage, i, 0, 0, 0);
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800442 }
Geoff Lang3b573612016-10-31 14:08:10 -0400443 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000444
Geoff Langb0f917f2017-12-05 13:41:54 -0500445 if (mSupportedExtensions.textureRectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400446 {
447 Texture *zeroTextureRectangle =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500448 new Texture(mImplementation.get(), 0, TextureType::Rectangle);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800449 mZeroTextures[TextureType::Rectangle].set(this, zeroTextureRectangle);
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400450 }
451
Geoff Langb0f917f2017-12-05 13:41:54 -0500452 if (mSupportedExtensions.eglImageExternal || mSupportedExtensions.eglStreamConsumerExternal)
Ian Ewellbda75592016-04-18 17:25:54 -0400453 {
Corentin Wallez99d492c2018-02-27 15:17:10 -0500454 Texture *zeroTextureExternal = new Texture(mImplementation.get(), 0, TextureType::External);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800455 mZeroTextures[TextureType::External].set(this, zeroTextureExternal);
Ian Ewellbda75592016-04-18 17:25:54 -0400456 }
457
Jamie Madill4928b7c2017-06-20 12:57:39 -0400458 mGLState.initializeZeroTextures(this, mZeroTextures);
Jamie Madille6382c32014-11-07 15:05:26 -0500459
Jamie Madill57a89722013-07-02 11:57:03 -0400460 bindVertexArray(0);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000461
Geoff Langeb66a6e2016-10-31 13:06:12 -0400462 if (getClientVersion() >= Version(3, 0))
Geoff Lang1a683462015-09-29 15:09:59 -0400463 {
464 // [OpenGL ES 3.0.2] section 2.14.1 pg 85:
465 // In the initial state, a default transform feedback object is bound and treated as
466 // a transform feedback object with a name of zero. That object is bound any time
467 // BindTransformFeedback is called with id of zero
Jamie Madillf0dcb8b2017-08-26 19:05:13 -0400468 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Geoff Lang1a683462015-09-29 15:09:59 -0400469 }
Geoff Langc8058452014-02-03 12:04:11 -0500470
Corentin Wallez336129f2017-10-17 15:55:40 -0400471 for (auto type : angle::AllEnums<BufferBinding>())
472 {
473 bindBuffer(type, 0);
474 }
475
476 bindRenderbuffer(GL_RENDERBUFFER, 0);
477
478 for (unsigned int i = 0; i < mCaps.maxUniformBufferBindings; i++)
479 {
480 bindBufferRange(BufferBinding::Uniform, i, 0, 0, -1);
481 }
482
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700483 // Initialize GLES1 renderer if appropriate.
484 if (getClientVersion() < Version(2, 0))
485 {
486 mGLES1Renderer.reset(new GLES1Renderer());
487 }
488
Jamie Madillad9f24e2016-02-12 09:27:24 -0500489 // Initialize dirty bit masks
Geoff Lang9bf86f02018-07-26 11:46:34 -0400490 mDrawDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
491 mDrawDirtyObjects.set(State::DIRTY_OBJECT_VERTEX_ARRAY);
492 mDrawDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM_TEXTURES);
Jamie Madill70aeda42018-08-20 12:17:40 -0400493 mDrawDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM);
Geoff Lang9bf86f02018-07-26 11:46:34 -0400494
495 mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
496 mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_VERTEX_ARRAY);
497 mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM_TEXTURES);
498
Jamie Madillc67323a2017-11-02 23:11:41 -0400499 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500500 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500501 // No dirty objects.
502
503 // Readpixels uses the pack state and read FBO
Jamie Madillc67323a2017-11-02 23:11:41 -0400504 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500505 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_BUFFER_BINDING);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400506 mReadPixelsDirtyBits.set(State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500507 mReadPixelsDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
508
509 mClearDirtyBits.set(State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED);
510 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
511 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR);
512 mClearDirtyBits.set(State::DIRTY_BIT_VIEWPORT);
513 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_COLOR);
514 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_DEPTH);
515 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_STENCIL);
516 mClearDirtyBits.set(State::DIRTY_BIT_COLOR_MASK);
517 mClearDirtyBits.set(State::DIRTY_BIT_DEPTH_MASK);
518 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT);
519 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_BACK);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400520 mClearDirtyBits.set(State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500521 mClearDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
522
523 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
524 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR);
Geoff Lang1d2c41d2016-10-19 16:14:46 -0700525 mBlitDirtyBits.set(State::DIRTY_BIT_FRAMEBUFFER_SRGB);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400526 mBlitDirtyBits.set(State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
527 mBlitDirtyBits.set(State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500528 mBlitDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
529 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
Jamie Madill437fa652016-05-03 15:13:24 -0400530
Xinghua Cao10a4d432017-11-28 14:46:26 +0800531 // TODO(xinghua.cao@intel.com): add other dirty bits and dirty objects.
532 mComputeDirtyBits.set(State::DIRTY_BIT_SHADER_STORAGE_BUFFER_BINDING);
533 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_BINDING);
534 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_EXECUTABLE);
535 mComputeDirtyBits.set(State::DIRTY_BIT_TEXTURE_BINDINGS);
536 mComputeDirtyBits.set(State::DIRTY_BIT_SAMPLER_BINDINGS);
Qin Jiajia62fcf622017-11-30 16:16:12 +0800537 mComputeDirtyBits.set(State::DIRTY_BIT_DISPATCH_INDIRECT_BUFFER_BINDING);
Jiajia Qin5ae6ee42018-03-06 17:39:42 +0800538 mComputeDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM_TEXTURES);
Jamie Madill70aeda42018-08-20 12:17:40 -0400539 mComputeDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM);
Xinghua Cao10a4d432017-11-28 14:46:26 +0800540
Jamie Madillb4927eb2018-07-16 11:39:46 -0400541 mImplementation->setErrorSet(&mErrors);
542
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400543 handleError(mImplementation->initialize());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000544}
545
Jamie Madill4928b7c2017-06-20 12:57:39 -0400546egl::Error Context::onDestroy(const egl::Display *display)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000547{
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700548 if (mGLES1Renderer)
549 {
550 mGLES1Renderer->onDestroy(this, &mGLState);
551 }
552
Jamie Madille7b3fe22018-04-05 09:42:46 -0400553 // Delete the Surface first to trigger a finish() in Vulkan.
Jamie Madille7b3fe22018-04-05 09:42:46 -0400554 ANGLE_TRY(releaseSurface(display));
555
Corentin Wallez80b24112015-08-25 16:41:57 -0400556 for (auto fence : mFenceNVMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000557 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400558 SafeDelete(fence.second);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000559 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400560 mFenceNVMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000561
Corentin Wallez80b24112015-08-25 16:41:57 -0400562 for (auto query : mQueryMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000563 {
Geoff Langf0aa8422015-09-29 15:08:34 -0400564 if (query.second != nullptr)
565 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400566 query.second->release(this);
Geoff Langf0aa8422015-09-29 15:08:34 -0400567 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000568 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400569 mQueryMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000570
Corentin Wallez80b24112015-08-25 16:41:57 -0400571 for (auto vertexArray : mVertexArrayMap)
Jamie Madill57a89722013-07-02 11:57:03 -0400572 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400573 if (vertexArray.second)
574 {
575 vertexArray.second->onDestroy(this);
576 }
Jamie Madill57a89722013-07-02 11:57:03 -0400577 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400578 mVertexArrayMap.clear();
Jamie Madill57a89722013-07-02 11:57:03 -0400579
Corentin Wallez80b24112015-08-25 16:41:57 -0400580 for (auto transformFeedback : mTransformFeedbackMap)
Geoff Langc8058452014-02-03 12:04:11 -0500581 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500582 if (transformFeedback.second != nullptr)
583 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500584 transformFeedback.second->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500585 }
Geoff Langc8058452014-02-03 12:04:11 -0500586 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400587 mTransformFeedbackMap.clear();
Geoff Langc8058452014-02-03 12:04:11 -0500588
Jamie Madill5b772312018-03-08 20:28:32 -0500589 for (BindingPointer<Texture> &zeroTexture : mZeroTextures)
Geoff Lang76b10c92014-09-05 16:28:14 -0400590 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800591 if (zeroTexture.get() != nullptr)
592 {
593 ANGLE_TRY(zeroTexture->onDestroy(this));
594 zeroTexture.set(this, nullptr);
595 }
Geoff Lang76b10c92014-09-05 16:28:14 -0400596 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000597
Jamie Madill2f348d22017-06-05 10:50:59 -0400598 releaseShaderCompiler();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500599
Jamie Madill4928b7c2017-06-20 12:57:39 -0400600 mGLState.reset(this);
601
Jamie Madill6c1f6712017-02-14 19:08:04 -0500602 mState.mBuffers->release(this);
603 mState.mShaderPrograms->release(this);
604 mState.mTextures->release(this);
605 mState.mRenderbuffers->release(this);
606 mState.mSamplers->release(this);
Jamie Madill70b5bb02017-08-28 13:32:37 -0400607 mState.mSyncs->release(this);
Jamie Madill6c1f6712017-02-14 19:08:04 -0500608 mState.mPaths->release(this);
609 mState.mFramebuffers->release(this);
Yunchao Hea336b902017-08-02 16:05:21 +0800610 mState.mPipelines->release(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400611
jchen107ae70d82018-07-06 13:47:01 +0800612 mThreadPool.reset();
613
Jamie Madill76e471e2017-10-21 09:56:01 -0400614 mImplementation->onDestroy(this);
615
Jamie Madill4928b7c2017-06-20 12:57:39 -0400616 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000617}
618
Jamie Madill70ee0f62017-02-06 16:04:20 -0500619Context::~Context()
620{
621}
622
Geoff Lang75359662018-04-11 01:42:27 -0400623void Context::setLabel(EGLLabelKHR label)
624{
625 mLabel = label;
626}
627
628EGLLabelKHR Context::getLabel() const
629{
630 return mLabel;
631}
632
Jamie Madill4928b7c2017-06-20 12:57:39 -0400633egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000634{
Jamie Madill61e16b42017-06-19 11:13:23 -0400635 mCurrentDisplay = display;
636
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000637 if (!mHasBeenCurrent)
638 {
Geoff Lang33f11fb2018-05-07 13:42:47 -0400639 initialize();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000640 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500641 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400642 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000643
Corentin Wallezc295e512017-01-27 17:47:50 -0500644 int width = 0;
645 int height = 0;
646 if (surface != nullptr)
647 {
648 width = surface->getWidth();
649 height = surface->getHeight();
650 }
651
652 mGLState.setViewportParams(0, 0, width, height);
653 mGLState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000654
655 mHasBeenCurrent = true;
656 }
657
Jamie Madill1b94d432015-08-07 13:23:23 -0400658 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700659 mGLState.setAllDirtyBits();
Jamie Madill81c2e252017-09-09 23:32:46 -0400660 mGLState.setAllDirtyObjects();
Jamie Madill1b94d432015-08-07 13:23:23 -0400661
Jamie Madill4928b7c2017-06-20 12:57:39 -0400662 ANGLE_TRY(releaseSurface(display));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500663
664 Framebuffer *newDefault = nullptr;
665 if (surface != nullptr)
666 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400667 ANGLE_TRY(surface->setIsCurrent(this, true));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500668 mCurrentSurface = surface;
Geoff Langbf7b95d2018-05-01 16:48:21 -0400669 newDefault = surface->createDefaultFramebuffer(this);
Corentin Wallezccab69d2017-01-27 16:57:15 -0500670 }
671 else
672 {
Geoff Langbf7b95d2018-05-01 16:48:21 -0400673 newDefault = new Framebuffer(mImplementation.get());
Corentin Wallezccab69d2017-01-27 16:57:15 -0500674 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000675
Corentin Wallez37c39792015-08-20 14:19:46 -0400676 // Update default framebuffer, the binding of the previous default
677 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400678 {
Jamie Madilla11819d2018-07-30 10:26:01 -0400679 mState.mFramebuffers->setDefaultFramebuffer(newDefault);
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700680 if (mGLState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400681 {
Jamie Madilla11819d2018-07-30 10:26:01 -0400682 bindReadFramebuffer(0);
Corentin Wallez37c39792015-08-20 14:19:46 -0400683 }
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700684 if (mGLState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400685 {
Jamie Madilla11819d2018-07-30 10:26:01 -0400686 bindDrawFramebuffer(0);
Corentin Wallez37c39792015-08-20 14:19:46 -0400687 }
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400688 }
Ian Ewell292f0052016-02-04 10:37:32 -0500689
690 // Notify the renderer of a context switch
Luc Ferron5396f2a2018-07-12 08:24:23 -0400691 ANGLE_TRY(mImplementation->onMakeCurrent(this));
Jamie Madill4928b7c2017-06-20 12:57:39 -0400692 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000693}
694
Jamie Madill4928b7c2017-06-20 12:57:39 -0400695egl::Error Context::releaseSurface(const egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400696{
Geoff Langbf7b95d2018-05-01 16:48:21 -0400697 gl::Framebuffer *defaultFramebuffer = mState.mFramebuffers->getFramebuffer(0);
Corentin Wallez51706ea2015-08-07 14:39:22 -0400698
Geoff Langbf7b95d2018-05-01 16:48:21 -0400699 // Remove the default framebuffer
700 if (mGLState.getReadFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500701 {
702 mGLState.setReadFramebufferBinding(nullptr);
Jamie Madilla11819d2018-07-30 10:26:01 -0400703 mReadFramebufferObserverBinding.bind(nullptr);
Corentin Wallezc295e512017-01-27 17:47:50 -0500704 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400705
706 if (mGLState.getDrawFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500707 {
708 mGLState.setDrawFramebufferBinding(nullptr);
Jamie Madilla11819d2018-07-30 10:26:01 -0400709 mDrawFramebufferObserverBinding.bind(nullptr);
Corentin Wallezc295e512017-01-27 17:47:50 -0500710 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400711
712 if (defaultFramebuffer)
713 {
714 defaultFramebuffer->onDestroy(this);
715 delete defaultFramebuffer;
716 }
717
Corentin Wallezc295e512017-01-27 17:47:50 -0500718 mState.mFramebuffers->setDefaultFramebuffer(nullptr);
719
720 if (mCurrentSurface)
721 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400722 ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
Corentin Wallezc295e512017-01-27 17:47:50 -0500723 mCurrentSurface = nullptr;
724 }
Jamie Madill4928b7c2017-06-20 12:57:39 -0400725
726 return egl::NoError();
Jamie Madill77a72f62015-04-14 11:18:32 -0400727}
728
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000729GLuint Context::createBuffer()
730{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500731 return mState.mBuffers->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000732}
733
734GLuint Context::createProgram()
735{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500736 return mState.mShaderPrograms->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000737}
738
Jiawei Shao385b3e02018-03-21 09:43:28 +0800739GLuint Context::createShader(ShaderType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000740{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500741 return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000742}
743
744GLuint Context::createTexture()
745{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500746 return mState.mTextures->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000747}
748
749GLuint Context::createRenderbuffer()
750{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500751 return mState.mRenderbuffers->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000752}
753
Brandon Jones59770802018-04-02 13:18:42 -0700754GLuint Context::genPaths(GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300755{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500756 auto resultOrError = mState.mPaths->createPaths(mImplementation.get(), range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300757 if (resultOrError.isError())
758 {
759 handleError(resultOrError.getError());
760 return 0;
761 }
762 return resultOrError.getResult();
763}
764
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000765// Returns an unused framebuffer name
766GLuint Context::createFramebuffer()
767{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500768 return mState.mFramebuffers->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000769}
770
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500771void Context::genFencesNV(GLsizei n, GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000772{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500773 for (int i = 0; i < n; i++)
774 {
775 GLuint handle = mFenceNVHandleAllocator.allocate();
776 mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV()));
777 fences[i] = handle;
778 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000779}
780
Yunchao Hea336b902017-08-02 16:05:21 +0800781GLuint Context::createProgramPipeline()
782{
783 return mState.mPipelines->createProgramPipeline();
784}
785
Jiawei Shao385b3e02018-03-21 09:43:28 +0800786GLuint Context::createShaderProgramv(ShaderType type, GLsizei count, const GLchar *const *strings)
Jiajia Qin5451d532017-11-16 17:16:34 +0800787{
788 UNIMPLEMENTED();
789 return 0u;
790}
791
James Darpinian4d9d4832018-03-13 12:43:28 -0700792void Context::deleteBuffer(GLuint bufferName)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000793{
James Darpinian4d9d4832018-03-13 12:43:28 -0700794 Buffer *buffer = mState.mBuffers->getBuffer(bufferName);
795 if (buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000796 {
797 detachBuffer(buffer);
798 }
Jamie Madill893ab082014-05-16 16:56:10 -0400799
James Darpinian4d9d4832018-03-13 12:43:28 -0700800 mState.mBuffers->deleteObject(this, bufferName);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000801}
802
803void Context::deleteShader(GLuint shader)
804{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500805 mState.mShaderPrograms->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000806}
807
808void Context::deleteProgram(GLuint program)
809{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500810 mState.mShaderPrograms->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000811}
812
813void Context::deleteTexture(GLuint texture)
814{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500815 if (mState.mTextures->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000816 {
817 detachTexture(texture);
818 }
819
Jamie Madill6c1f6712017-02-14 19:08:04 -0500820 mState.mTextures->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000821}
822
823void Context::deleteRenderbuffer(GLuint renderbuffer)
824{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500825 if (mState.mRenderbuffers->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000826 {
827 detachRenderbuffer(renderbuffer);
828 }
Jamie Madill893ab082014-05-16 16:56:10 -0400829
Jamie Madill6c1f6712017-02-14 19:08:04 -0500830 mState.mRenderbuffers->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000831}
832
Jamie Madill7f0c5a42017-08-26 22:43:26 -0400833void Context::deleteSync(GLsync sync)
Jamie Madillcd055f82013-07-26 11:55:15 -0400834{
835 // The spec specifies the underlying Fence object is not deleted until all current
836 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
837 // and since our API is currently designed for being called from a single thread, we can delete
838 // the fence immediately.
Jamie Madill70b5bb02017-08-28 13:32:37 -0400839 mState.mSyncs->deleteObject(this, static_cast<GLuint>(reinterpret_cast<uintptr_t>(sync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400840}
841
Yunchao Hea336b902017-08-02 16:05:21 +0800842void Context::deleteProgramPipeline(GLuint pipeline)
843{
844 if (mState.mPipelines->getProgramPipeline(pipeline))
845 {
846 detachProgramPipeline(pipeline);
847 }
848
849 mState.mPipelines->deleteObject(this, pipeline);
850}
851
Sami Väisänene45e53b2016-05-25 10:36:04 +0300852void Context::deletePaths(GLuint first, GLsizei range)
853{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500854 mState.mPaths->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300855}
856
Brandon Jones59770802018-04-02 13:18:42 -0700857bool Context::isPath(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300858{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500859 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300860 if (pathObj == nullptr)
861 return false;
862
863 return pathObj->hasPathData();
864}
865
Brandon Jones59770802018-04-02 13:18:42 -0700866bool Context::isPathGenerated(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300867{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500868 return mState.mPaths->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300869}
870
Brandon Jones59770802018-04-02 13:18:42 -0700871void Context::pathCommands(GLuint path,
872 GLsizei numCommands,
873 const GLubyte *commands,
874 GLsizei numCoords,
875 GLenum coordType,
876 const void *coords)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300877{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500878 auto *pathObject = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300879
880 handleError(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
881}
882
Jamie Madill007530e2017-12-28 14:27:04 -0500883void Context::pathParameterf(GLuint path, GLenum pname, GLfloat value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300884{
Jamie Madill007530e2017-12-28 14:27:04 -0500885 Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300886
887 switch (pname)
888 {
889 case GL_PATH_STROKE_WIDTH_CHROMIUM:
890 pathObj->setStrokeWidth(value);
891 break;
892 case GL_PATH_END_CAPS_CHROMIUM:
893 pathObj->setEndCaps(static_cast<GLenum>(value));
894 break;
895 case GL_PATH_JOIN_STYLE_CHROMIUM:
896 pathObj->setJoinStyle(static_cast<GLenum>(value));
897 break;
898 case GL_PATH_MITER_LIMIT_CHROMIUM:
899 pathObj->setMiterLimit(value);
900 break;
901 case GL_PATH_STROKE_BOUND_CHROMIUM:
902 pathObj->setStrokeBound(value);
903 break;
904 default:
905 UNREACHABLE();
906 break;
907 }
908}
909
Jamie Madill007530e2017-12-28 14:27:04 -0500910void Context::pathParameteri(GLuint path, GLenum pname, GLint value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300911{
Jamie Madill007530e2017-12-28 14:27:04 -0500912 // TODO(jmadill): Should use proper clamping/casting.
913 pathParameterf(path, pname, static_cast<GLfloat>(value));
914}
915
916void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value)
917{
918 const Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300919
920 switch (pname)
921 {
922 case GL_PATH_STROKE_WIDTH_CHROMIUM:
923 *value = pathObj->getStrokeWidth();
924 break;
925 case GL_PATH_END_CAPS_CHROMIUM:
926 *value = static_cast<GLfloat>(pathObj->getEndCaps());
927 break;
928 case GL_PATH_JOIN_STYLE_CHROMIUM:
929 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
930 break;
931 case GL_PATH_MITER_LIMIT_CHROMIUM:
932 *value = pathObj->getMiterLimit();
933 break;
934 case GL_PATH_STROKE_BOUND_CHROMIUM:
935 *value = pathObj->getStrokeBound();
936 break;
937 default:
938 UNREACHABLE();
939 break;
940 }
941}
942
Jamie Madill007530e2017-12-28 14:27:04 -0500943void Context::getPathParameteriv(GLuint path, GLenum pname, GLint *value)
944{
945 GLfloat val = 0.0f;
946 getPathParameterfv(path, pname, value != nullptr ? &val : nullptr);
947 if (value)
948 *value = static_cast<GLint>(val);
949}
950
Brandon Jones59770802018-04-02 13:18:42 -0700951void Context::pathStencilFunc(GLenum func, GLint ref, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300952{
953 mGLState.setPathStencilFunc(func, ref, mask);
954}
955
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000956void Context::deleteFramebuffer(GLuint framebuffer)
957{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500958 if (mState.mFramebuffers->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000959 {
960 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000961 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500962
Jamie Madill6c1f6712017-02-14 19:08:04 -0500963 mState.mFramebuffers->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000964}
965
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500966void Context::deleteFencesNV(GLsizei n, const GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000967{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500968 for (int i = 0; i < n; i++)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000969 {
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500970 GLuint fence = fences[i];
971
972 FenceNV *fenceObject = nullptr;
973 if (mFenceNVMap.erase(fence, &fenceObject))
974 {
975 mFenceNVHandleAllocator.release(fence);
976 delete fenceObject;
977 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000978 }
979}
980
Geoff Lang70d0f492015-12-10 17:45:46 -0500981Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000982{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500983 return mState.mBuffers->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000984}
985
Jamie Madill570f7c82014-07-03 10:38:54 -0400986Texture *Context::getTexture(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000987{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500988 return mState.mTextures->getTexture(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000989}
990
Geoff Lang70d0f492015-12-10 17:45:46 -0500991Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000992{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500993 return mState.mRenderbuffers->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000994}
995
Jamie Madill70b5bb02017-08-28 13:32:37 -0400996Sync *Context::getSync(GLsync handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400997{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400998 return mState.mSyncs->getSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400999}
1000
Jamie Madill57a89722013-07-02 11:57:03 -04001001VertexArray *Context::getVertexArray(GLuint handle) const
1002{
Jamie Madill96a483b2017-06-27 16:49:21 -04001003 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -04001004}
1005
Jamie Madilldc356042013-07-19 16:36:57 -04001006Sampler *Context::getSampler(GLuint handle) const
1007{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001008 return mState.mSamplers->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -04001009}
1010
Geoff Langc8058452014-02-03 12:04:11 -05001011TransformFeedback *Context::getTransformFeedback(GLuint handle) const
1012{
Jamie Madill96a483b2017-06-27 16:49:21 -04001013 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -05001014}
1015
Yunchao Hea336b902017-08-02 16:05:21 +08001016ProgramPipeline *Context::getProgramPipeline(GLuint handle) const
1017{
1018 return mState.mPipelines->getProgramPipeline(handle);
1019}
1020
Geoff Lang75359662018-04-11 01:42:27 -04001021gl::LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
Geoff Lang70d0f492015-12-10 17:45:46 -05001022{
1023 switch (identifier)
1024 {
1025 case GL_BUFFER:
1026 return getBuffer(name);
1027 case GL_SHADER:
1028 return getShader(name);
1029 case GL_PROGRAM:
1030 return getProgram(name);
1031 case GL_VERTEX_ARRAY:
1032 return getVertexArray(name);
1033 case GL_QUERY:
1034 return getQuery(name);
1035 case GL_TRANSFORM_FEEDBACK:
1036 return getTransformFeedback(name);
1037 case GL_SAMPLER:
1038 return getSampler(name);
1039 case GL_TEXTURE:
1040 return getTexture(name);
1041 case GL_RENDERBUFFER:
1042 return getRenderbuffer(name);
1043 case GL_FRAMEBUFFER:
1044 return getFramebuffer(name);
1045 default:
1046 UNREACHABLE();
1047 return nullptr;
1048 }
1049}
1050
Geoff Lang75359662018-04-11 01:42:27 -04001051gl::LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
Geoff Lang70d0f492015-12-10 17:45:46 -05001052{
Jamie Madill70b5bb02017-08-28 13:32:37 -04001053 return getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
Geoff Lang70d0f492015-12-10 17:45:46 -05001054}
1055
Martin Radev9d901792016-07-15 15:58:58 +03001056void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
1057{
Geoff Lang75359662018-04-11 01:42:27 -04001058 gl::LabeledObject *object = getLabeledObject(identifier, name);
Martin Radev9d901792016-07-15 15:58:58 +03001059 ASSERT(object != nullptr);
1060
1061 std::string labelName = GetObjectLabelFromPointer(length, label);
1062 object->setLabel(labelName);
Jamie Madill8693bdb2017-09-02 15:32:14 -04001063
1064 // TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the
1065 // specified object is active until we do this.
1066 mGLState.setObjectDirty(identifier);
Martin Radev9d901792016-07-15 15:58:58 +03001067}
1068
1069void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
1070{
Geoff Lang75359662018-04-11 01:42:27 -04001071 gl::LabeledObject *object = getLabeledObjectFromPtr(ptr);
Martin Radev9d901792016-07-15 15:58:58 +03001072 ASSERT(object != nullptr);
1073
1074 std::string labelName = GetObjectLabelFromPointer(length, label);
1075 object->setLabel(labelName);
1076}
1077
1078void Context::getObjectLabel(GLenum identifier,
1079 GLuint name,
1080 GLsizei bufSize,
1081 GLsizei *length,
1082 GLchar *label) const
1083{
Geoff Lang75359662018-04-11 01:42:27 -04001084 gl::LabeledObject *object = getLabeledObject(identifier, name);
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
1091void Context::getObjectPtrLabel(const void *ptr,
1092 GLsizei bufSize,
1093 GLsizei *length,
1094 GLchar *label) const
1095{
Geoff Lang75359662018-04-11 01:42:27 -04001096 gl::LabeledObject *object = getLabeledObjectFromPtr(ptr);
Martin Radev9d901792016-07-15 15:58:58 +03001097 ASSERT(object != nullptr);
1098
1099 const std::string &objectLabel = object->getLabel();
1100 GetObjectLabelBase(objectLabel, bufSize, length, label);
1101}
1102
Jamie Madilldc356042013-07-19 16:36:57 -04001103bool Context::isSampler(GLuint samplerName) const
1104{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001105 return mState.mSamplers->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -04001106}
1107
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001108void Context::bindTexture(TextureType target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001109{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001110 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001111
Jamie Madilldedd7b92014-11-05 16:30:36 -05001112 if (handle == 0)
1113 {
1114 texture = mZeroTextures[target].get();
1115 }
1116 else
1117 {
Corentin Wallez99d492c2018-02-27 15:17:10 -05001118 texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -05001119 }
1120
1121 ASSERT(texture);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001122 mGLState.setSamplerTexture(this, target, texture);
Jamie Madilld84b6732018-09-06 15:54:35 -04001123 mStateCache.onActiveTextureChange(this);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00001124}
1125
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001126void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001127{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001128 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1129 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001130 mGLState.setReadFramebufferBinding(framebuffer);
Jamie Madilla11819d2018-07-30 10:26:01 -04001131 mReadFramebufferObserverBinding.bind(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001132}
1133
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001134void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001135{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001136 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1137 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001138 mGLState.setDrawFramebufferBinding(framebuffer);
Jamie Madilla11819d2018-07-30 10:26:01 -04001139 mDrawFramebufferObserverBinding.bind(framebuffer);
Jamie Madilld84b6732018-09-06 15:54:35 -04001140 mStateCache.onDrawFramebufferChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001141}
1142
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001143void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -04001144{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001145 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madill7267aa62018-04-17 15:28:21 -04001146 mGLState.setVertexArrayBinding(this, vertexArray);
Jamie Madilla11819d2018-07-30 10:26:01 -04001147 mVertexArrayObserverBinding.bind(vertexArray);
Jamie Madillc43cdad2018-08-08 15:49:25 -04001148 mStateCache.onVertexArrayBindingChange(this);
Jamie Madill57a89722013-07-02 11:57:03 -04001149}
1150
Shao80957d92017-02-20 21:25:59 +08001151void Context::bindVertexBuffer(GLuint bindingIndex,
1152 GLuint bufferHandle,
1153 GLintptr offset,
1154 GLsizei stride)
1155{
1156 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001157 mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Jamie Madillc43cdad2018-08-08 15:49:25 -04001158 mStateCache.onVertexArrayStateChange(this);
Shao80957d92017-02-20 21:25:59 +08001159}
1160
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001161void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -04001162{
Geoff Lang76b10c92014-09-05 16:28:14 -04001163 ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -04001164 Sampler *sampler =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001165 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001166 mGLState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04001167}
1168
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001169void Context::bindImageTexture(GLuint unit,
1170 GLuint texture,
1171 GLint level,
1172 GLboolean layered,
1173 GLint layer,
1174 GLenum access,
1175 GLenum format)
1176{
1177 Texture *tex = mState.mTextures->getTexture(texture);
1178 mGLState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
1179}
1180
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001181void Context::useProgram(GLuint program)
1182{
Jamie Madill6c1f6712017-02-14 19:08:04 -05001183 mGLState.setProgram(this, getProgram(program));
Jamie Madillc43cdad2018-08-08 15:49:25 -04001184 mStateCache.onProgramExecutableChange(this);
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001185}
1186
Jiajia Qin5451d532017-11-16 17:16:34 +08001187void Context::useProgramStages(GLuint pipeline, GLbitfield stages, GLuint program)
1188{
1189 UNIMPLEMENTED();
1190}
1191
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001192void Context::bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001193{
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001194 ASSERT(target == GL_TRANSFORM_FEEDBACK);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001195 TransformFeedback *transformFeedback =
1196 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001197 mGLState.setTransformFeedbackBinding(this, transformFeedback);
Jamie Madilld84b6732018-09-06 15:54:35 -04001198 mStateCache.onTransformFeedbackChange(this);
Geoff Langc8058452014-02-03 12:04:11 -05001199}
1200
Yunchao Hea336b902017-08-02 16:05:21 +08001201void Context::bindProgramPipeline(GLuint pipelineHandle)
1202{
1203 ProgramPipeline *pipeline =
1204 mState.mPipelines->checkProgramPipelineAllocation(mImplementation.get(), pipelineHandle);
1205 mGLState.setProgramPipelineBinding(this, pipeline);
1206}
1207
Corentin Wallezad3ae902018-03-09 13:40:42 -05001208void Context::beginQuery(QueryType target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001209{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001210 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001211 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001212
Geoff Lang5aad9672014-09-08 11:10:42 -04001213 // begin query
Jamie Madill5188a272018-07-25 10:53:56 -04001214 ANGLE_CONTEXT_TRY(queryObject->begin(this));
Geoff Lang5aad9672014-09-08 11:10:42 -04001215
1216 // set query as active for specified target only if begin succeeded
Jamie Madill4928b7c2017-06-20 12:57:39 -04001217 mGLState.setActiveQuery(this, target, queryObject);
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::endQuery(QueryType target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001222{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001223 Query *queryObject = mGLState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001224 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001225
Jamie Madill5188a272018-07-25 10:53:56 -04001226 handleError(queryObject->end(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001227
Geoff Lang5aad9672014-09-08 11:10:42 -04001228 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madill4928b7c2017-06-20 12:57:39 -04001229 mGLState.setActiveQuery(this, target, nullptr);
Jamie Madilld84b6732018-09-06 15:54:35 -04001230 mStateCache.onQueryChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001231}
1232
Corentin Wallezad3ae902018-03-09 13:40:42 -05001233void Context::queryCounter(GLuint id, QueryType target)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001234{
Corentin Wallezad3ae902018-03-09 13:40:42 -05001235 ASSERT(target == QueryType::Timestamp);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001236
1237 Query *queryObject = getQuery(id, true, target);
1238 ASSERT(queryObject);
1239
Jamie Madill5188a272018-07-25 10:53:56 -04001240 handleError(queryObject->queryCounter(this));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001241}
1242
Corentin Wallezad3ae902018-03-09 13:40:42 -05001243void Context::getQueryiv(QueryType target, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001244{
1245 switch (pname)
1246 {
1247 case GL_CURRENT_QUERY_EXT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001248 params[0] = mGLState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001249 break;
1250 case GL_QUERY_COUNTER_BITS_EXT:
1251 switch (target)
1252 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001253 case QueryType::TimeElapsed:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001254 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1255 break;
Corentin Wallezad3ae902018-03-09 13:40:42 -05001256 case QueryType::Timestamp:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001257 params[0] = getExtensions().queryCounterBitsTimestamp;
1258 break;
1259 default:
1260 UNREACHABLE();
1261 params[0] = 0;
1262 break;
1263 }
1264 break;
1265 default:
1266 UNREACHABLE();
1267 return;
1268 }
1269}
1270
Corentin Wallezad3ae902018-03-09 13:40:42 -05001271void Context::getQueryivRobust(QueryType target,
Brandon Jones59770802018-04-02 13:18:42 -07001272 GLenum pname,
1273 GLsizei bufSize,
1274 GLsizei *length,
1275 GLint *params)
1276{
1277 getQueryiv(target, pname, params);
1278}
1279
Geoff Lang2186c382016-10-14 10:54:54 -04001280void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001281{
Jamie Madill5188a272018-07-25 10:53:56 -04001282 handleError(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001283}
1284
Brandon Jones59770802018-04-02 13:18:42 -07001285void Context::getQueryObjectivRobust(GLuint id,
1286 GLenum pname,
1287 GLsizei bufSize,
1288 GLsizei *length,
1289 GLint *params)
1290{
1291 getQueryObjectiv(id, pname, params);
1292}
1293
Geoff Lang2186c382016-10-14 10:54:54 -04001294void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001295{
Jamie Madill5188a272018-07-25 10:53:56 -04001296 handleError(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001297}
1298
Brandon Jones59770802018-04-02 13:18:42 -07001299void Context::getQueryObjectuivRobust(GLuint id,
1300 GLenum pname,
1301 GLsizei bufSize,
1302 GLsizei *length,
1303 GLuint *params)
1304{
1305 getQueryObjectuiv(id, pname, params);
1306}
1307
Geoff Lang2186c382016-10-14 10:54:54 -04001308void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001309{
Jamie Madill5188a272018-07-25 10:53:56 -04001310 handleError(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001311}
1312
Brandon Jones59770802018-04-02 13:18:42 -07001313void Context::getQueryObjecti64vRobust(GLuint id,
1314 GLenum pname,
1315 GLsizei bufSize,
1316 GLsizei *length,
1317 GLint64 *params)
1318{
1319 getQueryObjecti64v(id, pname, params);
1320}
1321
Geoff Lang2186c382016-10-14 10:54:54 -04001322void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001323{
Jamie Madill5188a272018-07-25 10:53:56 -04001324 handleError(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001325}
1326
Brandon Jones59770802018-04-02 13:18:42 -07001327void Context::getQueryObjectui64vRobust(GLuint id,
1328 GLenum pname,
1329 GLsizei bufSize,
1330 GLsizei *length,
1331 GLuint64 *params)
1332{
1333 getQueryObjectui64v(id, pname, params);
1334}
1335
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001336Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001337{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001338 return mState.mFramebuffers->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001339}
1340
Jamie Madill2f348d22017-06-05 10:50:59 -04001341FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001342{
Jamie Madill96a483b2017-06-27 16:49:21 -04001343 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001344}
1345
Corentin Wallezad3ae902018-03-09 13:40:42 -05001346Query *Context::getQuery(GLuint handle, bool create, QueryType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001347{
Jamie Madill96a483b2017-06-27 16:49:21 -04001348 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001349 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001350 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001351 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001352
1353 Query *query = mQueryMap.query(handle);
1354 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001355 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001356 ASSERT(type != QueryType::InvalidEnum);
Jamie Madill96a483b2017-06-27 16:49:21 -04001357 query = new Query(mImplementation->createQuery(type), handle);
1358 query->addRef();
1359 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001360 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001361 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001362}
1363
Geoff Lang70d0f492015-12-10 17:45:46 -05001364Query *Context::getQuery(GLuint handle) const
1365{
Jamie Madill96a483b2017-06-27 16:49:21 -04001366 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001367}
1368
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001369Texture *Context::getTargetTexture(TextureType type) const
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001370{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001371 ASSERT(ValidTextureTarget(this, type) || ValidTextureExternalTarget(this, type));
1372 return mGLState.getTargetTexture(type);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001373}
1374
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001375Texture *Context::getSamplerTexture(unsigned int sampler, TextureType type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001376{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001377 return mGLState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001378}
1379
Geoff Lang492a7e42014-11-05 13:27:06 -05001380Compiler *Context::getCompiler() const
1381{
Jamie Madill2f348d22017-06-05 10:50:59 -04001382 if (mCompiler.get() == nullptr)
1383 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001384 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001385 }
1386 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001387}
1388
Jamie Madillc1d770e2017-04-13 17:31:24 -04001389void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001390{
1391 switch (pname)
1392 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001393 case GL_SHADER_COMPILER:
1394 *params = GL_TRUE;
1395 break;
1396 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1397 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1398 break;
1399 default:
1400 mGLState.getBooleanv(pname, params);
1401 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001402 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001403}
1404
Jamie Madillc1d770e2017-04-13 17:31:24 -04001405void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001406{
Shannon Woods53a94a82014-06-24 15:20:36 -04001407 // Queries about context capabilities and maximums are answered by Context.
1408 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001409 switch (pname)
1410 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001411 case GL_ALIASED_LINE_WIDTH_RANGE:
1412 params[0] = mCaps.minAliasedLineWidth;
1413 params[1] = mCaps.maxAliasedLineWidth;
1414 break;
1415 case GL_ALIASED_POINT_SIZE_RANGE:
1416 params[0] = mCaps.minAliasedPointSize;
1417 params[1] = mCaps.maxAliasedPointSize;
1418 break;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07001419 case GL_SMOOTH_POINT_SIZE_RANGE:
1420 params[0] = mCaps.minSmoothPointSize;
1421 params[1] = mCaps.maxSmoothPointSize;
1422 break;
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07001423 case GL_SMOOTH_LINE_WIDTH_RANGE:
1424 params[0] = mCaps.minSmoothLineWidth;
1425 params[1] = mCaps.maxSmoothLineWidth;
1426 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001427 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1428 ASSERT(mExtensions.textureFilterAnisotropic);
1429 *params = mExtensions.maxTextureAnisotropy;
1430 break;
1431 case GL_MAX_TEXTURE_LOD_BIAS:
1432 *params = mCaps.maxLODBias;
1433 break;
1434
1435 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1436 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1437 {
Lingfeng Yang3a41af62018-04-09 07:28:56 -07001438 // GLES1 emulation: // GL_PATH_(MODELVIEW|PROJECTION)_MATRIX_CHROMIUM collides with the
1439 // GLES1 constants for modelview/projection matrix.
1440 if (getClientVersion() < Version(2, 0))
1441 {
1442 mGLState.getFloatv(pname, params);
1443 }
1444 else
1445 {
1446 ASSERT(mExtensions.pathRendering);
1447 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1448 memcpy(params, m, 16 * sizeof(GLfloat));
1449 }
Jamie Madill231c7f52017-04-26 13:45:37 -04001450 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001451 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001452
Jamie Madill231c7f52017-04-26 13:45:37 -04001453 default:
1454 mGLState.getFloatv(pname, params);
1455 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001456 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001457}
1458
Jamie Madillc1d770e2017-04-13 17:31:24 -04001459void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001460{
Shannon Woods53a94a82014-06-24 15:20:36 -04001461 // Queries about context capabilities and maximums are answered by Context.
1462 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001463
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001464 switch (pname)
1465 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001466 case GL_MAX_VERTEX_ATTRIBS:
1467 *params = mCaps.maxVertexAttributes;
1468 break;
1469 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1470 *params = mCaps.maxVertexUniformVectors;
1471 break;
1472 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001473 *params = mCaps.maxShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001474 break;
1475 case GL_MAX_VARYING_VECTORS:
1476 *params = mCaps.maxVaryingVectors;
1477 break;
1478 case GL_MAX_VARYING_COMPONENTS:
1479 *params = mCaps.maxVertexOutputComponents;
1480 break;
1481 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1482 *params = mCaps.maxCombinedTextureImageUnits;
1483 break;
1484 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001485 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001486 break;
1487 case GL_MAX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001488 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001489 break;
1490 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1491 *params = mCaps.maxFragmentUniformVectors;
1492 break;
1493 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001494 *params = mCaps.maxShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001495 break;
1496 case GL_MAX_RENDERBUFFER_SIZE:
1497 *params = mCaps.maxRenderbufferSize;
1498 break;
1499 case GL_MAX_COLOR_ATTACHMENTS_EXT:
1500 *params = mCaps.maxColorAttachments;
1501 break;
1502 case GL_MAX_DRAW_BUFFERS_EXT:
1503 *params = mCaps.maxDrawBuffers;
1504 break;
1505 // case GL_FRAMEBUFFER_BINDING: // now equivalent to
1506 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
1507 case GL_SUBPIXEL_BITS:
1508 *params = 4;
1509 break;
1510 case GL_MAX_TEXTURE_SIZE:
1511 *params = mCaps.max2DTextureSize;
1512 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001513 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
1514 *params = mCaps.maxRectangleTextureSize;
1515 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001516 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1517 *params = mCaps.maxCubeMapTextureSize;
1518 break;
1519 case GL_MAX_3D_TEXTURE_SIZE:
1520 *params = mCaps.max3DTextureSize;
1521 break;
1522 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1523 *params = mCaps.maxArrayTextureLayers;
1524 break;
1525 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1526 *params = mCaps.uniformBufferOffsetAlignment;
1527 break;
1528 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1529 *params = mCaps.maxUniformBufferBindings;
1530 break;
1531 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001532 *params = mCaps.maxShaderUniformBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001533 break;
1534 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001535 *params = mCaps.maxShaderUniformBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001536 break;
1537 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1538 *params = mCaps.maxCombinedTextureImageUnits;
1539 break;
1540 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1541 *params = mCaps.maxVertexOutputComponents;
1542 break;
1543 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1544 *params = mCaps.maxFragmentInputComponents;
1545 break;
1546 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1547 *params = mCaps.minProgramTexelOffset;
1548 break;
1549 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1550 *params = mCaps.maxProgramTexelOffset;
1551 break;
1552 case GL_MAJOR_VERSION:
1553 *params = getClientVersion().major;
1554 break;
1555 case GL_MINOR_VERSION:
1556 *params = getClientVersion().minor;
1557 break;
1558 case GL_MAX_ELEMENTS_INDICES:
1559 *params = mCaps.maxElementsIndices;
1560 break;
1561 case GL_MAX_ELEMENTS_VERTICES:
1562 *params = mCaps.maxElementsVertices;
1563 break;
1564 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1565 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1566 break;
1567 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1568 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1569 break;
1570 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1571 *params = mCaps.maxTransformFeedbackSeparateComponents;
1572 break;
1573 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1574 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1575 break;
1576 case GL_MAX_SAMPLES_ANGLE:
1577 *params = mCaps.maxSamples;
1578 break;
1579 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001580 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001581 params[0] = mCaps.maxViewportWidth;
1582 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001583 }
1584 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001585 case GL_COMPRESSED_TEXTURE_FORMATS:
1586 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1587 params);
1588 break;
1589 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1590 *params = mResetStrategy;
1591 break;
1592 case GL_NUM_SHADER_BINARY_FORMATS:
1593 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1594 break;
1595 case GL_SHADER_BINARY_FORMATS:
1596 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1597 break;
1598 case GL_NUM_PROGRAM_BINARY_FORMATS:
1599 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1600 break;
1601 case GL_PROGRAM_BINARY_FORMATS:
1602 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1603 break;
1604 case GL_NUM_EXTENSIONS:
1605 *params = static_cast<GLint>(mExtensionStrings.size());
1606 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001607
Jamie Madill231c7f52017-04-26 13:45:37 -04001608 // GL_KHR_debug
1609 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1610 *params = mExtensions.maxDebugMessageLength;
1611 break;
1612 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1613 *params = mExtensions.maxDebugLoggedMessages;
1614 break;
1615 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1616 *params = mExtensions.maxDebugGroupStackDepth;
1617 break;
1618 case GL_MAX_LABEL_LENGTH:
1619 *params = mExtensions.maxLabelLength;
1620 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001621
Martin Radeve5285d22017-07-14 16:23:53 +03001622 // GL_ANGLE_multiview
1623 case GL_MAX_VIEWS_ANGLE:
1624 *params = mExtensions.maxViews;
1625 break;
1626
Jamie Madill231c7f52017-04-26 13:45:37 -04001627 // GL_EXT_disjoint_timer_query
1628 case GL_GPU_DISJOINT_EXT:
1629 *params = mImplementation->getGPUDisjoint();
1630 break;
1631 case GL_MAX_FRAMEBUFFER_WIDTH:
1632 *params = mCaps.maxFramebufferWidth;
1633 break;
1634 case GL_MAX_FRAMEBUFFER_HEIGHT:
1635 *params = mCaps.maxFramebufferHeight;
1636 break;
1637 case GL_MAX_FRAMEBUFFER_SAMPLES:
1638 *params = mCaps.maxFramebufferSamples;
1639 break;
1640 case GL_MAX_SAMPLE_MASK_WORDS:
1641 *params = mCaps.maxSampleMaskWords;
1642 break;
1643 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1644 *params = mCaps.maxColorTextureSamples;
1645 break;
1646 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1647 *params = mCaps.maxDepthTextureSamples;
1648 break;
1649 case GL_MAX_INTEGER_SAMPLES:
1650 *params = mCaps.maxIntegerSamples;
1651 break;
1652 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1653 *params = mCaps.maxVertexAttribRelativeOffset;
1654 break;
1655 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1656 *params = mCaps.maxVertexAttribBindings;
1657 break;
1658 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1659 *params = mCaps.maxVertexAttribStride;
1660 break;
1661 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001662 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001663 break;
1664 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001665 *params = mCaps.maxShaderAtomicCounters[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001666 break;
1667 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001668 *params = mCaps.maxShaderImageUniforms[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001669 break;
1670 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001671 *params = mCaps.maxShaderStorageBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001672 break;
1673 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001674 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001675 break;
1676 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001677 *params = mCaps.maxShaderAtomicCounters[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001678 break;
1679 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001680 *params = mCaps.maxShaderImageUniforms[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001681 break;
1682 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001683 *params = mCaps.maxShaderStorageBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001684 break;
1685 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1686 *params = mCaps.minProgramTextureGatherOffset;
1687 break;
1688 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1689 *params = mCaps.maxProgramTextureGatherOffset;
1690 break;
1691 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1692 *params = mCaps.maxComputeWorkGroupInvocations;
1693 break;
1694 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001695 *params = mCaps.maxShaderUniformBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001696 break;
1697 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001698 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001699 break;
1700 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1701 *params = mCaps.maxComputeSharedMemorySize;
1702 break;
1703 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001704 *params = mCaps.maxShaderUniformComponents[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001705 break;
1706 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001707 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001708 break;
1709 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001710 *params = mCaps.maxShaderAtomicCounters[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001711 break;
1712 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001713 *params = mCaps.maxShaderImageUniforms[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001714 break;
1715 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001716 *params =
1717 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Compute]);
Jamie Madill231c7f52017-04-26 13:45:37 -04001718 break;
1719 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001720 *params = mCaps.maxShaderStorageBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001721 break;
1722 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1723 *params = mCaps.maxCombinedShaderOutputResources;
1724 break;
1725 case GL_MAX_UNIFORM_LOCATIONS:
1726 *params = mCaps.maxUniformLocations;
1727 break;
1728 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1729 *params = mCaps.maxAtomicCounterBufferBindings;
1730 break;
1731 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1732 *params = mCaps.maxAtomicCounterBufferSize;
1733 break;
1734 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1735 *params = mCaps.maxCombinedAtomicCounterBuffers;
1736 break;
1737 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1738 *params = mCaps.maxCombinedAtomicCounters;
1739 break;
1740 case GL_MAX_IMAGE_UNITS:
1741 *params = mCaps.maxImageUnits;
1742 break;
1743 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1744 *params = mCaps.maxCombinedImageUniforms;
1745 break;
1746 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1747 *params = mCaps.maxShaderStorageBufferBindings;
1748 break;
1749 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1750 *params = mCaps.maxCombinedShaderStorageBlocks;
1751 break;
1752 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1753 *params = mCaps.shaderStorageBufferOffsetAlignment;
1754 break;
Jiawei Shao361df072017-11-22 09:33:59 +08001755
1756 // GL_EXT_geometry_shader
1757 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
1758 *params = mCaps.maxFramebufferLayers;
1759 break;
1760 case GL_LAYER_PROVOKING_VERTEX_EXT:
1761 *params = mCaps.layerProvokingVertex;
1762 break;
1763 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001764 *params = mCaps.maxShaderUniformComponents[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001765 break;
1766 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001767 *params = mCaps.maxShaderUniformBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001768 break;
1769 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001770 *params =
1771 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Geometry]);
Jiawei Shao361df072017-11-22 09:33:59 +08001772 break;
1773 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
1774 *params = mCaps.maxGeometryInputComponents;
1775 break;
1776 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
1777 *params = mCaps.maxGeometryOutputComponents;
1778 break;
1779 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
1780 *params = mCaps.maxGeometryOutputVertices;
1781 break;
1782 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
1783 *params = mCaps.maxGeometryTotalOutputComponents;
1784 break;
1785 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
1786 *params = mCaps.maxGeometryShaderInvocations;
1787 break;
1788 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001789 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001790 break;
1791 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001792 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001793 break;
1794 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001795 *params = mCaps.maxShaderAtomicCounters[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001796 break;
1797 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001798 *params = mCaps.maxShaderImageUniforms[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001799 break;
1800 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001801 *params = mCaps.maxShaderStorageBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001802 break;
Lingfeng Yang96310cd2018-03-28 11:56:28 -07001803 // GLES1 emulation: Caps queries
1804 case GL_MAX_TEXTURE_UNITS:
1805 *params = mCaps.maxMultitextureUnits;
1806 break;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001807 case GL_MAX_MODELVIEW_STACK_DEPTH:
1808 *params = mCaps.maxModelviewMatrixStackDepth;
1809 break;
1810 case GL_MAX_PROJECTION_STACK_DEPTH:
1811 *params = mCaps.maxProjectionMatrixStackDepth;
1812 break;
1813 case GL_MAX_TEXTURE_STACK_DEPTH:
1814 *params = mCaps.maxTextureMatrixStackDepth;
1815 break;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07001816 case GL_MAX_LIGHTS:
1817 *params = mCaps.maxLights;
1818 break;
Lingfeng Yang060088a2018-05-30 20:40:57 -07001819 case GL_MAX_CLIP_PLANES:
1820 *params = mCaps.maxClipPlanes;
1821 break;
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001822 // GLES1 emulation: Vertex attribute queries
1823 case GL_VERTEX_ARRAY_BUFFER_BINDING:
1824 case GL_NORMAL_ARRAY_BUFFER_BINDING:
1825 case GL_COLOR_ARRAY_BUFFER_BINDING:
1826 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
1827 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
1828 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1829 GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, params);
1830 break;
1831 case GL_VERTEX_ARRAY_STRIDE:
1832 case GL_NORMAL_ARRAY_STRIDE:
1833 case GL_COLOR_ARRAY_STRIDE:
1834 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
1835 case GL_TEXTURE_COORD_ARRAY_STRIDE:
1836 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1837 GL_VERTEX_ATTRIB_ARRAY_STRIDE, params);
1838 break;
1839 case GL_VERTEX_ARRAY_SIZE:
1840 case GL_COLOR_ARRAY_SIZE:
1841 case GL_TEXTURE_COORD_ARRAY_SIZE:
1842 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1843 GL_VERTEX_ATTRIB_ARRAY_SIZE, params);
1844 break;
1845 case GL_VERTEX_ARRAY_TYPE:
1846 case GL_COLOR_ARRAY_TYPE:
1847 case GL_NORMAL_ARRAY_TYPE:
1848 case GL_POINT_SIZE_ARRAY_TYPE_OES:
1849 case GL_TEXTURE_COORD_ARRAY_TYPE:
1850 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1851 GL_VERTEX_ATTRIB_ARRAY_TYPE, params);
1852 break;
1853
jchen1082af6202018-06-22 10:59:52 +08001854 // GL_KHR_parallel_shader_compile
1855 case GL_MAX_SHADER_COMPILER_THREADS_KHR:
1856 *params = mGLState.getMaxShaderCompilerThreads();
1857 break;
1858
Jamie Madill231c7f52017-04-26 13:45:37 -04001859 default:
Jamie Madille98b1b52018-03-08 09:47:23 -05001860 handleError(mGLState.getIntegerv(this, pname, params));
Jamie Madill231c7f52017-04-26 13:45:37 -04001861 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001862 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001863}
1864
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001865void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001866{
Shannon Woods53a94a82014-06-24 15:20:36 -04001867 // Queries about context capabilities and maximums are answered by Context.
1868 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001869 switch (pname)
1870 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001871 case GL_MAX_ELEMENT_INDEX:
1872 *params = mCaps.maxElementIndex;
1873 break;
1874 case GL_MAX_UNIFORM_BLOCK_SIZE:
1875 *params = mCaps.maxUniformBlockSize;
1876 break;
1877 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001878 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001879 break;
1880 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001881 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001882 break;
1883 case GL_MAX_SERVER_WAIT_TIMEOUT:
1884 *params = mCaps.maxServerWaitTimeout;
1885 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001886
Jamie Madill231c7f52017-04-26 13:45:37 -04001887 // GL_EXT_disjoint_timer_query
1888 case GL_TIMESTAMP_EXT:
1889 *params = mImplementation->getTimestamp();
1890 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001891
Jamie Madill231c7f52017-04-26 13:45:37 -04001892 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1893 *params = mCaps.maxShaderStorageBlockSize;
1894 break;
1895 default:
1896 UNREACHABLE();
1897 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001898 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001899}
1900
Geoff Lang70d0f492015-12-10 17:45:46 -05001901void Context::getPointerv(GLenum pname, void **params) const
1902{
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001903 mGLState.getPointerv(this, pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001904}
1905
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001906void Context::getPointervRobustANGLERobust(GLenum pname,
1907 GLsizei bufSize,
1908 GLsizei *length,
1909 void **params)
1910{
1911 UNIMPLEMENTED();
1912}
1913
Martin Radev66fb8202016-07-28 11:45:20 +03001914void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001915{
Shannon Woods53a94a82014-06-24 15:20:36 -04001916 // Queries about context capabilities and maximums are answered by Context.
1917 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001918
1919 GLenum nativeType;
1920 unsigned int numParams;
1921 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1922 ASSERT(queryStatus);
1923
1924 if (nativeType == GL_INT)
1925 {
1926 switch (target)
1927 {
1928 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1929 ASSERT(index < 3u);
1930 *data = mCaps.maxComputeWorkGroupCount[index];
1931 break;
1932 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1933 ASSERT(index < 3u);
1934 *data = mCaps.maxComputeWorkGroupSize[index];
1935 break;
1936 default:
1937 mGLState.getIntegeri_v(target, index, data);
1938 }
1939 }
1940 else
1941 {
1942 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1943 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001944}
1945
Brandon Jones59770802018-04-02 13:18:42 -07001946void Context::getIntegeri_vRobust(GLenum target,
1947 GLuint index,
1948 GLsizei bufSize,
1949 GLsizei *length,
1950 GLint *data)
1951{
1952 getIntegeri_v(target, index, data);
1953}
1954
Martin Radev66fb8202016-07-28 11:45:20 +03001955void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001956{
Shannon Woods53a94a82014-06-24 15:20:36 -04001957 // Queries about context capabilities and maximums are answered by Context.
1958 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001959
1960 GLenum nativeType;
1961 unsigned int numParams;
1962 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1963 ASSERT(queryStatus);
1964
1965 if (nativeType == GL_INT_64_ANGLEX)
1966 {
1967 mGLState.getInteger64i_v(target, index, data);
1968 }
1969 else
1970 {
1971 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1972 }
1973}
1974
Brandon Jones59770802018-04-02 13:18:42 -07001975void Context::getInteger64i_vRobust(GLenum target,
1976 GLuint index,
1977 GLsizei bufSize,
1978 GLsizei *length,
1979 GLint64 *data)
1980{
1981 getInteger64i_v(target, index, data);
1982}
1983
Martin Radev66fb8202016-07-28 11:45:20 +03001984void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1985{
1986 // Queries about context capabilities and maximums are answered by Context.
1987 // Queries about current GL state values are answered by State.
1988
1989 GLenum nativeType;
1990 unsigned int numParams;
1991 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1992 ASSERT(queryStatus);
1993
1994 if (nativeType == GL_BOOL)
1995 {
1996 mGLState.getBooleani_v(target, index, data);
1997 }
1998 else
1999 {
2000 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
2001 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04002002}
2003
Brandon Jones59770802018-04-02 13:18:42 -07002004void Context::getBooleani_vRobust(GLenum target,
2005 GLuint index,
2006 GLsizei bufSize,
2007 GLsizei *length,
2008 GLboolean *data)
2009{
2010 getBooleani_v(target, index, data);
2011}
2012
Corentin Wallez336129f2017-10-17 15:55:40 -04002013void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002014{
2015 Buffer *buffer = mGLState.getTargetBuffer(target);
2016 QueryBufferParameteriv(buffer, pname, params);
2017}
2018
Brandon Jones59770802018-04-02 13:18:42 -07002019void Context::getBufferParameterivRobust(BufferBinding target,
2020 GLenum pname,
2021 GLsizei bufSize,
2022 GLsizei *length,
2023 GLint *params)
2024{
2025 getBufferParameteriv(target, pname, params);
2026}
2027
He Yunchao010e4db2017-03-03 14:22:06 +08002028void Context::getFramebufferAttachmentParameteriv(GLenum target,
2029 GLenum attachment,
2030 GLenum pname,
2031 GLint *params)
2032{
2033 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002034 QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08002035}
2036
Brandon Jones59770802018-04-02 13:18:42 -07002037void Context::getFramebufferAttachmentParameterivRobust(GLenum target,
2038 GLenum attachment,
2039 GLenum pname,
2040 GLsizei bufSize,
2041 GLsizei *length,
2042 GLint *params)
2043{
2044 getFramebufferAttachmentParameteriv(target, attachment, pname, params);
2045}
2046
He Yunchao010e4db2017-03-03 14:22:06 +08002047void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
2048{
2049 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
2050 QueryRenderbufferiv(this, renderbuffer, pname, params);
2051}
2052
Brandon Jones59770802018-04-02 13:18:42 -07002053void Context::getRenderbufferParameterivRobust(GLenum target,
2054 GLenum pname,
2055 GLsizei bufSize,
2056 GLsizei *length,
2057 GLint *params)
2058{
2059 getRenderbufferParameteriv(target, pname, params);
2060}
2061
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002062void Context::getTexParameterfv(TextureType target, GLenum pname, GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002063{
2064 Texture *texture = getTargetTexture(target);
2065 QueryTexParameterfv(texture, pname, params);
2066}
2067
Brandon Jones59770802018-04-02 13:18:42 -07002068void Context::getTexParameterfvRobust(TextureType target,
2069 GLenum pname,
2070 GLsizei bufSize,
2071 GLsizei *length,
2072 GLfloat *params)
2073{
2074 getTexParameterfv(target, pname, params);
2075}
2076
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002077void Context::getTexParameteriv(TextureType target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002078{
2079 Texture *texture = getTargetTexture(target);
2080 QueryTexParameteriv(texture, pname, params);
2081}
Jiajia Qin5451d532017-11-16 17:16:34 +08002082
Brandon Jones59770802018-04-02 13:18:42 -07002083void Context::getTexParameterivRobust(TextureType target,
2084 GLenum pname,
2085 GLsizei bufSize,
2086 GLsizei *length,
2087 GLint *params)
2088{
2089 getTexParameteriv(target, pname, params);
2090}
2091
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002092void Context::getTexParameterIivRobust(TextureType target,
2093 GLenum pname,
2094 GLsizei bufSize,
2095 GLsizei *length,
2096 GLint *params)
2097{
2098 UNIMPLEMENTED();
2099}
2100
2101void Context::getTexParameterIuivRobust(TextureType target,
2102 GLenum pname,
2103 GLsizei bufSize,
2104 GLsizei *length,
2105 GLuint *params)
2106{
2107 UNIMPLEMENTED();
2108}
2109
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002110void Context::getTexLevelParameteriv(TextureTarget target, GLint level, GLenum pname, GLint *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002111{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002112 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002113 QueryTexLevelParameteriv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002114}
2115
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002116void Context::getTexLevelParameterivRobust(TextureTarget target,
2117 GLint level,
2118 GLenum pname,
2119 GLsizei bufSize,
2120 GLsizei *length,
2121 GLint *params)
2122{
2123 UNIMPLEMENTED();
2124}
2125
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002126void Context::getTexLevelParameterfv(TextureTarget target,
2127 GLint level,
2128 GLenum pname,
2129 GLfloat *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002130{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002131 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002132 QueryTexLevelParameterfv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002133}
2134
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002135void Context::getTexLevelParameterfvRobust(TextureTarget target,
2136 GLint level,
2137 GLenum pname,
2138 GLsizei bufSize,
2139 GLsizei *length,
2140 GLfloat *params)
2141{
2142 UNIMPLEMENTED();
2143}
2144
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002145void Context::texParameterf(TextureType target, GLenum pname, GLfloat param)
He Yunchao010e4db2017-03-03 14:22:06 +08002146{
2147 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002148 SetTexParameterf(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002149 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002150}
2151
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002152void Context::texParameterfv(TextureType target, GLenum pname, const GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002153{
2154 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002155 SetTexParameterfv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002156 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002157}
2158
Brandon Jones59770802018-04-02 13:18:42 -07002159void Context::texParameterfvRobust(TextureType target,
2160 GLenum pname,
2161 GLsizei bufSize,
2162 const GLfloat *params)
2163{
2164 texParameterfv(target, pname, params);
2165}
2166
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002167void Context::texParameteri(TextureType target, GLenum pname, GLint param)
He Yunchao010e4db2017-03-03 14:22:06 +08002168{
2169 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002170 SetTexParameteri(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002171 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002172}
2173
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002174void Context::texParameteriv(TextureType target, GLenum pname, const GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002175{
2176 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002177 SetTexParameteriv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002178 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002179}
2180
Brandon Jones59770802018-04-02 13:18:42 -07002181void Context::texParameterivRobust(TextureType target,
2182 GLenum pname,
2183 GLsizei bufSize,
2184 const GLint *params)
2185{
2186 texParameteriv(target, pname, params);
2187}
2188
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002189void Context::texParameterIivRobust(TextureType target,
2190 GLenum pname,
2191 GLsizei bufSize,
2192 const GLint *params)
2193{
2194 UNIMPLEMENTED();
2195}
2196
2197void Context::texParameterIuivRobust(TextureType target,
2198 GLenum pname,
2199 GLsizei bufSize,
2200 const GLuint *params)
2201{
2202 UNIMPLEMENTED();
2203}
2204
Jamie Madill493f9572018-05-24 19:52:15 -04002205void Context::drawArrays(PrimitiveMode mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002206{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002207 // No-op if count draws no primitives for given mode
2208 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002209 {
2210 return;
2211 }
2212
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002213 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002214 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
Jamie Madill09463932018-04-04 05:26:59 -04002215 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count, 1);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002216}
2217
Jamie Madill493f9572018-05-24 19:52:15 -04002218void Context::drawArraysInstanced(PrimitiveMode mode,
2219 GLint first,
2220 GLsizei count,
2221 GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04002222{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002223 // No-op if count draws no primitives for given mode
2224 if (noopDrawInstanced(mode, count, instanceCount))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002225 {
2226 return;
2227 }
2228
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002229 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002230 ANGLE_CONTEXT_TRY(
2231 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
Jamie Madill09463932018-04-04 05:26:59 -04002232 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count,
2233 instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -04002234}
2235
Jamie Madill493f9572018-05-24 19:52:15 -04002236void Context::drawElements(PrimitiveMode mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002237{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002238 // No-op if count draws no primitives for given mode
2239 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002240 {
2241 return;
2242 }
2243
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002244 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002245 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04002246}
2247
Jamie Madill493f9572018-05-24 19:52:15 -04002248void Context::drawElementsInstanced(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002249 GLsizei count,
2250 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002251 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04002252 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04002253{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002254 // No-op if count draws no primitives for given mode
2255 if (noopDrawInstanced(mode, count, instances))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002256 {
2257 return;
2258 }
2259
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002260 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002261 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08002262 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04002263}
2264
Jamie Madill493f9572018-05-24 19:52:15 -04002265void Context::drawRangeElements(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002266 GLuint start,
2267 GLuint end,
2268 GLsizei count,
2269 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002270 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04002271{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002272 // No-op if count draws no primitives for given mode
2273 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002274 {
2275 return;
2276 }
2277
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002278 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002279 ANGLE_CONTEXT_TRY(
2280 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002281}
2282
Jamie Madill493f9572018-05-24 19:52:15 -04002283void Context::drawArraysIndirect(PrimitiveMode mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002284{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002285 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002286 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002287}
2288
Jamie Madill493f9572018-05-24 19:52:15 -04002289void Context::drawElementsIndirect(PrimitiveMode mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002290{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002291 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002292 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002293}
2294
Jamie Madill675fe712016-12-19 13:07:54 -05002295void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002296{
Jamie Madillafa02a22017-11-23 12:57:38 -05002297 handleError(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05002298}
2299
Jamie Madill675fe712016-12-19 13:07:54 -05002300void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05002301{
Jamie Madillafa02a22017-11-23 12:57:38 -05002302 handleError(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002303}
2304
Austin Kinross6ee1e782015-05-29 17:05:37 -07002305void Context::insertEventMarker(GLsizei length, const char *marker)
2306{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002307 ASSERT(mImplementation);
2308 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07002309}
2310
2311void Context::pushGroupMarker(GLsizei length, const char *marker)
2312{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002313 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05002314
2315 if (marker == nullptr)
2316 {
2317 // From the EXT_debug_marker spec,
2318 // "If <marker> is null then an empty string is pushed on the stack."
2319 mImplementation->pushGroupMarker(length, "");
2320 }
2321 else
2322 {
2323 mImplementation->pushGroupMarker(length, marker);
2324 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07002325}
2326
2327void Context::popGroupMarker()
2328{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002329 ASSERT(mImplementation);
2330 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07002331}
2332
Geoff Langd8605522016-04-13 10:19:12 -04002333void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
2334{
2335 Program *programObject = getProgram(program);
2336 ASSERT(programObject);
2337
2338 programObject->bindUniformLocation(location, name);
2339}
2340
Brandon Jones59770802018-04-02 13:18:42 -07002341void Context::coverageModulation(GLenum components)
Sami Väisänena797e062016-05-12 15:23:40 +03002342{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002343 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03002344}
2345
Brandon Jones59770802018-04-02 13:18:42 -07002346void Context::matrixLoadf(GLenum matrixMode, const GLfloat *matrix)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002347{
2348 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
2349}
2350
Brandon Jones59770802018-04-02 13:18:42 -07002351void Context::matrixLoadIdentity(GLenum matrixMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002352{
2353 GLfloat I[16];
2354 angle::Matrix<GLfloat>::setToIdentity(I);
2355
2356 mGLState.loadPathRenderingMatrix(matrixMode, I);
2357}
2358
2359void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
2360{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002361 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002362 if (!pathObj)
2363 return;
2364
Geoff Lang9bf86f02018-07-26 11:46:34 -04002365 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002366
2367 mImplementation->stencilFillPath(pathObj, fillMode, mask);
2368}
2369
2370void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
2371{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002372 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002373 if (!pathObj)
2374 return;
2375
Geoff Lang9bf86f02018-07-26 11:46:34 -04002376 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002377
2378 mImplementation->stencilStrokePath(pathObj, reference, mask);
2379}
2380
2381void Context::coverFillPath(GLuint path, GLenum coverMode)
2382{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002383 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002384 if (!pathObj)
2385 return;
2386
Geoff Lang9bf86f02018-07-26 11:46:34 -04002387 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002388
2389 mImplementation->coverFillPath(pathObj, coverMode);
2390}
2391
2392void Context::coverStrokePath(GLuint path, GLenum coverMode)
2393{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002394 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002395 if (!pathObj)
2396 return;
2397
Geoff Lang9bf86f02018-07-26 11:46:34 -04002398 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002399
2400 mImplementation->coverStrokePath(pathObj, coverMode);
2401}
2402
2403void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
2404{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002405 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002406 if (!pathObj)
2407 return;
2408
Geoff Lang9bf86f02018-07-26 11:46:34 -04002409 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002410
2411 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
2412}
2413
2414void Context::stencilThenCoverStrokePath(GLuint path,
2415 GLint reference,
2416 GLuint mask,
2417 GLenum coverMode)
2418{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002419 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002420 if (!pathObj)
2421 return;
2422
Geoff Lang9bf86f02018-07-26 11:46:34 -04002423 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002424
2425 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2426}
2427
Sami Väisänend59ca052016-06-21 16:10:00 +03002428void Context::coverFillPathInstanced(GLsizei numPaths,
2429 GLenum pathNameType,
2430 const void *paths,
2431 GLuint pathBase,
2432 GLenum coverMode,
2433 GLenum transformType,
2434 const GLfloat *transformValues)
2435{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002436 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002437
Geoff Lang9bf86f02018-07-26 11:46:34 -04002438 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002439
2440 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2441}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002442
Sami Väisänend59ca052016-06-21 16:10:00 +03002443void Context::coverStrokePathInstanced(GLsizei numPaths,
2444 GLenum pathNameType,
2445 const void *paths,
2446 GLuint pathBase,
2447 GLenum coverMode,
2448 GLenum transformType,
2449 const GLfloat *transformValues)
2450{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002451 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002452
2453 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Lang9bf86f02018-07-26 11:46:34 -04002454 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002455
2456 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2457 transformValues);
2458}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002459
Sami Väisänend59ca052016-06-21 16:10:00 +03002460void Context::stencilFillPathInstanced(GLsizei numPaths,
2461 GLenum pathNameType,
2462 const void *paths,
2463 GLuint pathBase,
2464 GLenum fillMode,
2465 GLuint mask,
2466 GLenum transformType,
2467 const GLfloat *transformValues)
2468{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002469 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002470
2471 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Lang9bf86f02018-07-26 11:46:34 -04002472 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002473
2474 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2475 transformValues);
2476}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002477
Sami Väisänend59ca052016-06-21 16:10:00 +03002478void Context::stencilStrokePathInstanced(GLsizei numPaths,
2479 GLenum pathNameType,
2480 const void *paths,
2481 GLuint pathBase,
2482 GLint reference,
2483 GLuint mask,
2484 GLenum transformType,
2485 const GLfloat *transformValues)
2486{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002487 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002488
Geoff Lang9bf86f02018-07-26 11:46:34 -04002489 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002490
2491 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2492 transformValues);
2493}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002494
Sami Väisänend59ca052016-06-21 16:10:00 +03002495void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2496 GLenum pathNameType,
2497 const void *paths,
2498 GLuint pathBase,
2499 GLenum fillMode,
2500 GLuint mask,
2501 GLenum coverMode,
2502 GLenum transformType,
2503 const GLfloat *transformValues)
2504{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002505 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002506
Geoff Lang9bf86f02018-07-26 11:46:34 -04002507 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002508
2509 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2510 transformType, transformValues);
2511}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002512
Sami Väisänend59ca052016-06-21 16:10:00 +03002513void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2514 GLenum pathNameType,
2515 const void *paths,
2516 GLuint pathBase,
2517 GLint reference,
2518 GLuint mask,
2519 GLenum coverMode,
2520 GLenum transformType,
2521 const GLfloat *transformValues)
2522{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002523 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002524
Geoff Lang9bf86f02018-07-26 11:46:34 -04002525 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002526
2527 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2528 transformType, transformValues);
2529}
2530
Sami Väisänen46eaa942016-06-29 10:26:37 +03002531void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2532{
2533 auto *programObject = getProgram(program);
2534
2535 programObject->bindFragmentInputLocation(location, name);
2536}
2537
2538void Context::programPathFragmentInputGen(GLuint program,
2539 GLint location,
2540 GLenum genMode,
2541 GLint components,
2542 const GLfloat *coeffs)
2543{
2544 auto *programObject = getProgram(program);
2545
jchen103fd614d2018-08-13 12:21:58 +08002546 programObject->pathFragmentInputGen(location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002547}
2548
jchen1015015f72017-03-16 13:54:21 +08002549GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2550{
jchen10fd7c3b52017-03-21 15:36:03 +08002551 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002552 return QueryProgramResourceIndex(programObject, programInterface, name);
2553}
2554
jchen10fd7c3b52017-03-21 15:36:03 +08002555void Context::getProgramResourceName(GLuint program,
2556 GLenum programInterface,
2557 GLuint index,
2558 GLsizei bufSize,
2559 GLsizei *length,
2560 GLchar *name)
2561{
2562 const auto *programObject = getProgram(program);
2563 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2564}
2565
jchen10191381f2017-04-11 13:59:04 +08002566GLint Context::getProgramResourceLocation(GLuint program,
2567 GLenum programInterface,
2568 const GLchar *name)
2569{
2570 const auto *programObject = getProgram(program);
2571 return QueryProgramResourceLocation(programObject, programInterface, name);
2572}
2573
jchen10880683b2017-04-12 16:21:55 +08002574void Context::getProgramResourceiv(GLuint program,
2575 GLenum programInterface,
2576 GLuint index,
2577 GLsizei propCount,
2578 const GLenum *props,
2579 GLsizei bufSize,
2580 GLsizei *length,
2581 GLint *params)
2582{
2583 const auto *programObject = getProgram(program);
2584 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2585 length, params);
2586}
2587
jchen10d9cd7b72017-08-30 15:04:25 +08002588void Context::getProgramInterfaceiv(GLuint program,
2589 GLenum programInterface,
2590 GLenum pname,
2591 GLint *params)
2592{
2593 const auto *programObject = getProgram(program);
2594 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2595}
2596
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002597void Context::getProgramInterfaceivRobust(GLuint program,
2598 GLenum programInterface,
2599 GLenum pname,
2600 GLsizei bufSize,
2601 GLsizei *length,
2602 GLint *params)
2603{
2604 UNIMPLEMENTED();
2605}
2606
Jamie Madill306b6c12018-07-27 08:12:49 -04002607void Context::handleError(const Error &error) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002608{
Jamie Madill6b873dd2018-07-12 23:56:30 -04002609 mErrors.handleError(error);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002610}
2611
2612// Get one of the recorded errors and clear its flag, if any.
2613// [OpenGL ES 2.0.24] section 2.5 page 13.
2614GLenum Context::getError()
2615{
Geoff Langda5777c2014-07-11 09:52:58 -04002616 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002617 {
Geoff Langda5777c2014-07-11 09:52:58 -04002618 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002619 }
Geoff Langda5777c2014-07-11 09:52:58 -04002620 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002621 {
Jamie Madill6b873dd2018-07-12 23:56:30 -04002622 return mErrors.popError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002623 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002624}
2625
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002626// NOTE: this function should not assume that this context is current!
Jamie Madill6b873dd2018-07-12 23:56:30 -04002627void Context::markContextLost()
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002628{
2629 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002630 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002631 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002632 mContextLostForced = true;
2633 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002634 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002635}
2636
Jamie Madill427064d2018-04-13 16:20:34 -04002637bool Context::isContextLost() const
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002638{
2639 return mContextLost;
2640}
2641
Jamie Madillfa920eb2018-01-04 11:45:50 -05002642GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002643{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002644 // Even if the application doesn't want to know about resets, we want to know
2645 // as it will allow us to skip all the calls.
2646 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002647 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002648 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002649 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002650 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002651 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002652
2653 // EXT_robustness, section 2.6: If the reset notification behavior is
2654 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2655 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2656 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002657 }
2658
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002659 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2660 // status should be returned at least once, and GL_NO_ERROR should be returned
2661 // once the device has finished resetting.
2662 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002663 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002664 ASSERT(mResetStatus == GL_NO_ERROR);
2665 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002666
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002667 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002668 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002669 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002670 }
2671 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002672 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002673 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002674 // If markContextLost was used to mark the context lost then
2675 // assume that is not recoverable, and continue to report the
2676 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002677 mResetStatus = mImplementation->getResetStatus();
2678 }
Jamie Madill893ab082014-05-16 16:56:10 -04002679
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002680 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002681}
2682
2683bool Context::isResetNotificationEnabled()
2684{
2685 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2686}
2687
Corentin Walleze3b10e82015-05-20 11:06:25 -04002688const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002689{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002690 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002691}
2692
2693EGLenum Context::getClientType() const
2694{
2695 return mClientType;
2696}
2697
2698EGLenum Context::getRenderBuffer() const
2699{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002700 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2701 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002702 {
2703 return EGL_NONE;
2704 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002705
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002706 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002707 ASSERT(backAttachment != nullptr);
2708 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002709}
2710
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002711VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002712{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002713 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002714 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2715 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002716 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002717 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2718 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002719
Jamie Madill96a483b2017-06-27 16:49:21 -04002720 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002721 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002722
2723 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002724}
2725
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002726TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002727{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002728 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002729 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2730 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002731 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002732 transformFeedback =
2733 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002734 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002735 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002736 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002737
2738 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002739}
2740
2741bool Context::isVertexArrayGenerated(GLuint vertexArray)
2742{
Jamie Madill96a483b2017-06-27 16:49:21 -04002743 ASSERT(mVertexArrayMap.contains(0));
2744 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002745}
2746
2747bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2748{
Jamie Madill96a483b2017-06-27 16:49:21 -04002749 ASSERT(mTransformFeedbackMap.contains(0));
2750 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002751}
2752
Shannon Woods53a94a82014-06-24 15:20:36 -04002753void Context::detachTexture(GLuint texture)
2754{
2755 // Simple pass-through to State's detachTexture method, as textures do not require
2756 // allocation map management either here or in the resource manager at detach time.
2757 // Zero textures are held by the Context, and we don't attempt to request them from
2758 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002759 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002760}
2761
James Darpinian4d9d4832018-03-13 12:43:28 -07002762void Context::detachBuffer(Buffer *buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002763{
Yuly Novikov5807a532015-12-03 13:01:22 -05002764 // Simple pass-through to State's detachBuffer method, since
2765 // only buffer attachments to container objects that are bound to the current context
2766 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002767
Yuly Novikov5807a532015-12-03 13:01:22 -05002768 // [OpenGL ES 3.2] section 5.1.2 page 45:
2769 // Attachments to unbound container objects, such as
2770 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2771 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002772 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002773}
2774
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002775void Context::detachFramebuffer(GLuint framebuffer)
2776{
Shannon Woods53a94a82014-06-24 15:20:36 -04002777 // Framebuffer detachment is handled by Context, because 0 is a valid
2778 // Framebuffer object, and a pointer to it must be passed from Context
2779 // to State at binding time.
2780
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002781 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002782 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2783 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2784 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002785
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002786 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002787 {
2788 bindReadFramebuffer(0);
2789 }
2790
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002791 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002792 {
2793 bindDrawFramebuffer(0);
2794 }
2795}
2796
2797void Context::detachRenderbuffer(GLuint renderbuffer)
2798{
Jamie Madilla02315b2017-02-23 14:14:47 -05002799 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002800}
2801
Jamie Madill57a89722013-07-02 11:57:03 -04002802void Context::detachVertexArray(GLuint vertexArray)
2803{
Jamie Madill77a72f62015-04-14 11:18:32 -04002804 // Vertex array detachment is handled by Context, because 0 is a valid
2805 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002806 // binding time.
2807
Jamie Madill57a89722013-07-02 11:57:03 -04002808 // [OpenGL ES 3.0.2] section 2.10 page 43:
2809 // If a vertex array object that is currently bound is deleted, the binding
2810 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madill7267aa62018-04-17 15:28:21 -04002811 if (mGLState.removeVertexArrayBinding(this, vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002812 {
2813 bindVertexArray(0);
2814 }
2815}
2816
Geoff Langc8058452014-02-03 12:04:11 -05002817void Context::detachTransformFeedback(GLuint transformFeedback)
2818{
Corentin Walleza2257da2016-04-19 16:43:12 -04002819 // Transform feedback detachment is handled by Context, because 0 is a valid
2820 // transform feedback, and a pointer to it must be passed from Context to State at
2821 // binding time.
2822
2823 // The OpenGL specification doesn't mention what should happen when the currently bound
2824 // transform feedback object is deleted. Since it is a container object, we treat it like
2825 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002826 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002827 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002828 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002829 }
Geoff Langc8058452014-02-03 12:04:11 -05002830}
2831
Jamie Madilldc356042013-07-19 16:36:57 -04002832void Context::detachSampler(GLuint sampler)
2833{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002834 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002835}
2836
Yunchao Hea336b902017-08-02 16:05:21 +08002837void Context::detachProgramPipeline(GLuint pipeline)
2838{
2839 mGLState.detachProgramPipeline(this, pipeline);
2840}
2841
Jamie Madill3ef140a2017-08-26 23:11:21 -04002842void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002843{
Shaodde78e82017-05-22 14:13:27 +08002844 mGLState.setVertexAttribDivisor(this, index, divisor);
Jamie Madillc43cdad2018-08-08 15:49:25 -04002845 mStateCache.onVertexArrayStateChange(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002846}
2847
Jamie Madille29d1672013-07-19 16:36:57 -04002848void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2849{
Geoff Langc1984ed2016-10-07 12:41:00 -04002850 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002851 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002852 SetSamplerParameteri(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002853 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002854}
Jamie Madille29d1672013-07-19 16:36:57 -04002855
Geoff Langc1984ed2016-10-07 12:41:00 -04002856void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2857{
2858 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002859 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002860 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002861 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002862}
2863
Brandon Jones59770802018-04-02 13:18:42 -07002864void Context::samplerParameterivRobust(GLuint sampler,
2865 GLenum pname,
2866 GLsizei bufSize,
2867 const GLint *param)
2868{
2869 samplerParameteriv(sampler, pname, param);
2870}
2871
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002872void Context::samplerParameterIivRobust(GLuint sampler,
2873 GLenum pname,
2874 GLsizei bufSize,
2875 const GLint *param)
2876{
2877 UNIMPLEMENTED();
2878}
2879
2880void Context::samplerParameterIuivRobust(GLuint sampler,
2881 GLenum pname,
2882 GLsizei bufSize,
2883 const GLuint *param)
2884{
2885 UNIMPLEMENTED();
2886}
2887
Jamie Madille29d1672013-07-19 16:36:57 -04002888void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2889{
Geoff Langc1984ed2016-10-07 12:41:00 -04002890 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002891 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002892 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002893 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002894}
2895
Geoff Langc1984ed2016-10-07 12:41:00 -04002896void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002897{
Geoff Langc1984ed2016-10-07 12:41:00 -04002898 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002899 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002900 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002901 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002902}
2903
Brandon Jones59770802018-04-02 13:18:42 -07002904void Context::samplerParameterfvRobust(GLuint sampler,
2905 GLenum pname,
2906 GLsizei bufSize,
2907 const GLfloat *param)
2908{
2909 samplerParameterfv(sampler, pname, param);
2910}
2911
Geoff Langc1984ed2016-10-07 12:41:00 -04002912void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002913{
Geoff Langc1984ed2016-10-07 12:41:00 -04002914 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002915 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002916 QuerySamplerParameteriv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002917 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002918}
Jamie Madill9675b802013-07-19 16:36:59 -04002919
Brandon Jones59770802018-04-02 13:18:42 -07002920void Context::getSamplerParameterivRobust(GLuint sampler,
2921 GLenum pname,
2922 GLsizei bufSize,
2923 GLsizei *length,
2924 GLint *params)
2925{
2926 getSamplerParameteriv(sampler, pname, params);
2927}
2928
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002929void Context::getSamplerParameterIivRobust(GLuint sampler,
2930 GLenum pname,
2931 GLsizei bufSize,
2932 GLsizei *length,
2933 GLint *params)
2934{
2935 UNIMPLEMENTED();
2936}
2937
2938void Context::getSamplerParameterIuivRobust(GLuint sampler,
2939 GLenum pname,
2940 GLsizei bufSize,
2941 GLsizei *length,
2942 GLuint *params)
2943{
2944 UNIMPLEMENTED();
2945}
2946
Geoff Langc1984ed2016-10-07 12:41:00 -04002947void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2948{
2949 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002950 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002951 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002952 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002953}
2954
Brandon Jones59770802018-04-02 13:18:42 -07002955void Context::getSamplerParameterfvRobust(GLuint sampler,
2956 GLenum pname,
2957 GLsizei bufSize,
2958 GLsizei *length,
2959 GLfloat *params)
2960{
2961 getSamplerParameterfv(sampler, pname, params);
2962}
2963
Olli Etuahof0fee072016-03-30 15:11:58 +03002964void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2965{
2966 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002967 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002968}
2969
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002970void Context::initRendererString()
2971{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002972 std::ostringstream rendererString;
2973 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002974 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002975 rendererString << ")";
2976
Geoff Langcec35902014-04-16 10:52:36 -04002977 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002978}
2979
Geoff Langc339c4e2016-11-29 10:37:36 -05002980void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002981{
Geoff Langc339c4e2016-11-29 10:37:36 -05002982 const Version &clientVersion = getClientVersion();
2983
2984 std::ostringstream versionString;
2985 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2986 << ANGLE_VERSION_STRING << ")";
2987 mVersionString = MakeStaticString(versionString.str());
2988
2989 std::ostringstream shadingLanguageVersionString;
2990 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2991 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2992 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2993 << ")";
2994 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002995}
2996
Geoff Langcec35902014-04-16 10:52:36 -04002997void Context::initExtensionStrings()
2998{
Geoff Langc339c4e2016-11-29 10:37:36 -05002999 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
3000 std::ostringstream combinedStringStream;
3001 std::copy(strings.begin(), strings.end(),
3002 std::ostream_iterator<const char *>(combinedStringStream, " "));
3003 return MakeStaticString(combinedStringStream.str());
3004 };
3005
3006 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04003007 for (const auto &extensionString : mExtensions.getStrings())
3008 {
3009 mExtensionStrings.push_back(MakeStaticString(extensionString));
3010 }
Geoff Langc339c4e2016-11-29 10:37:36 -05003011 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04003012
Geoff Langc339c4e2016-11-29 10:37:36 -05003013 mRequestableExtensionStrings.clear();
3014 for (const auto &extensionInfo : GetExtensionInfoMap())
3015 {
3016 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08003017 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
Geoff Langb0f917f2017-12-05 13:41:54 -05003018 mSupportedExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05003019 {
3020 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
3021 }
3022 }
3023 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04003024}
3025
Geoff Langc339c4e2016-11-29 10:37:36 -05003026const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04003027{
Geoff Langc339c4e2016-11-29 10:37:36 -05003028 switch (name)
3029 {
3030 case GL_VENDOR:
3031 return reinterpret_cast<const GLubyte *>("Google Inc.");
3032
3033 case GL_RENDERER:
3034 return reinterpret_cast<const GLubyte *>(mRendererString);
3035
3036 case GL_VERSION:
3037 return reinterpret_cast<const GLubyte *>(mVersionString);
3038
3039 case GL_SHADING_LANGUAGE_VERSION:
3040 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
3041
3042 case GL_EXTENSIONS:
3043 return reinterpret_cast<const GLubyte *>(mExtensionString);
3044
3045 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
3046 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
3047
3048 default:
3049 UNREACHABLE();
3050 return nullptr;
3051 }
Geoff Langcec35902014-04-16 10:52:36 -04003052}
3053
Geoff Langc339c4e2016-11-29 10:37:36 -05003054const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04003055{
Geoff Langc339c4e2016-11-29 10:37:36 -05003056 switch (name)
3057 {
3058 case GL_EXTENSIONS:
3059 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
3060
3061 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
3062 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
3063
3064 default:
3065 UNREACHABLE();
3066 return nullptr;
3067 }
Geoff Langcec35902014-04-16 10:52:36 -04003068}
3069
3070size_t Context::getExtensionStringCount() const
3071{
3072 return mExtensionStrings.size();
3073}
3074
Geoff Lang111a99e2017-10-17 10:58:41 -04003075bool Context::isExtensionRequestable(const char *name)
3076{
3077 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3078 auto extension = extensionInfos.find(name);
3079
Geoff Lang111a99e2017-10-17 10:58:41 -04003080 return extension != extensionInfos.end() && extension->second.Requestable &&
Geoff Langb0f917f2017-12-05 13:41:54 -05003081 mSupportedExtensions.*(extension->second.ExtensionsMember);
Geoff Lang111a99e2017-10-17 10:58:41 -04003082}
3083
Geoff Langc339c4e2016-11-29 10:37:36 -05003084void Context::requestExtension(const char *name)
3085{
3086 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3087 ASSERT(extensionInfos.find(name) != extensionInfos.end());
3088 const auto &extension = extensionInfos.at(name);
3089 ASSERT(extension.Requestable);
Geoff Langb0f917f2017-12-05 13:41:54 -05003090 ASSERT(isExtensionRequestable(name));
Geoff Langc339c4e2016-11-29 10:37:36 -05003091
3092 if (mExtensions.*(extension.ExtensionsMember))
3093 {
3094 // Extension already enabled
3095 return;
3096 }
3097
3098 mExtensions.*(extension.ExtensionsMember) = true;
3099 updateCaps();
3100 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08003101
Jamie Madill2f348d22017-06-05 10:50:59 -04003102 // Release the shader compiler so it will be re-created with the requested extensions enabled.
3103 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04003104
Jamie Madill81c2e252017-09-09 23:32:46 -04003105 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
3106 // sampleable.
Jamie Madilld4442552018-02-27 22:03:47 -05003107 mState.mTextures->signalAllTexturesDirty(this);
Geoff Lang9aded172017-04-05 11:07:56 -04003108 for (auto &zeroTexture : mZeroTextures)
3109 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003110 if (zeroTexture.get() != nullptr)
3111 {
3112 zeroTexture->signalDirty(this, InitState::Initialized);
3113 }
Geoff Lang9aded172017-04-05 11:07:56 -04003114 }
3115
Jamie Madillb983a4b2018-08-01 11:34:51 -04003116 mState.mFramebuffers->invalidateFramebufferComplenessCache(this);
Geoff Langc339c4e2016-11-29 10:37:36 -05003117}
3118
3119size_t Context::getRequestableExtensionStringCount() const
3120{
3121 return mRequestableExtensionStrings.size();
3122}
3123
Jamie Madill493f9572018-05-24 19:52:15 -04003124void Context::beginTransformFeedback(PrimitiveMode primitiveMode)
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003125{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003126 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003127 ASSERT(transformFeedback != nullptr);
3128 ASSERT(!transformFeedback->isPaused());
3129
Jamie Madill6c1f6712017-02-14 19:08:04 -05003130 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Jamie Madilld84b6732018-09-06 15:54:35 -04003131 mStateCache.onTransformFeedbackChange(this);
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003132}
3133
3134bool Context::hasActiveTransformFeedback(GLuint program) const
3135{
3136 for (auto pair : mTransformFeedbackMap)
3137 {
3138 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
3139 {
3140 return true;
3141 }
3142 }
3143 return false;
3144}
3145
Geoff Lang33f11fb2018-05-07 13:42:47 -04003146Extensions Context::generateSupportedExtensions() const
Geoff Langb0f917f2017-12-05 13:41:54 -05003147{
3148 Extensions supportedExtensions = mImplementation->getNativeExtensions();
3149
jchen1082af6202018-06-22 10:59:52 +08003150 // Explicitly enable GL_KHR_parallel_shader_compile
3151 supportedExtensions.parallelShaderCompile = true;
3152
Geoff Langb0f917f2017-12-05 13:41:54 -05003153 if (getClientVersion() < ES_2_0)
3154 {
3155 // Default extensions for GLES1
Lingfeng Yang0df813c2018-07-12 12:52:06 -07003156 supportedExtensions.pointSizeArray = true;
3157 supportedExtensions.textureCubeMap = true;
3158 supportedExtensions.pointSprite = true;
3159 supportedExtensions.drawTexture = true;
jchen1082af6202018-06-22 10:59:52 +08003160 supportedExtensions.parallelShaderCompile = false;
Geoff Langb0f917f2017-12-05 13:41:54 -05003161 }
3162
3163 if (getClientVersion() < ES_3_0)
3164 {
3165 // Disable ES3+ extensions
3166 supportedExtensions.colorBufferFloat = false;
3167 supportedExtensions.eglImageExternalEssl3 = false;
3168 supportedExtensions.textureNorm16 = false;
3169 supportedExtensions.multiview = false;
3170 supportedExtensions.maxViews = 1u;
3171 }
3172
3173 if (getClientVersion() < ES_3_1)
3174 {
3175 // Disable ES3.1+ extensions
3176 supportedExtensions.geometryShader = false;
Olli Etuahod310a432018-08-24 15:40:23 +03003177
3178 // TODO(http://anglebug.com/2775): Multisample arrays could be supported on ES 3.0 as well
3179 // once 2D multisample texture extension is exposed there.
Olli Etuaho064458a2018-08-30 14:02:02 +03003180 supportedExtensions.textureStorageMultisample2DArray = false;
Geoff Langb0f917f2017-12-05 13:41:54 -05003181 }
3182
3183 if (getClientVersion() > ES_2_0)
3184 {
3185 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
3186 // supportedExtensions.sRGB = false;
3187 }
3188
3189 // Some extensions are always available because they are implemented in the GL layer.
3190 supportedExtensions.bindUniformLocation = true;
3191 supportedExtensions.vertexArrayObject = true;
3192 supportedExtensions.bindGeneratesResource = true;
3193 supportedExtensions.clientArrays = true;
3194 supportedExtensions.requestExtension = true;
3195
3196 // Enable the no error extension if the context was created with the flag.
3197 supportedExtensions.noError = mSkipValidation;
3198
3199 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Geoff Lang33f11fb2018-05-07 13:42:47 -04003200 supportedExtensions.surfacelessContext = mSurfacelessSupported;
Geoff Langb0f917f2017-12-05 13:41:54 -05003201
3202 // Explicitly enable GL_KHR_debug
3203 supportedExtensions.debug = true;
3204 supportedExtensions.maxDebugMessageLength = 1024;
3205 supportedExtensions.maxDebugLoggedMessages = 1024;
3206 supportedExtensions.maxDebugGroupStackDepth = 1024;
3207 supportedExtensions.maxLabelLength = 1024;
3208
3209 // Explicitly enable GL_ANGLE_robust_client_memory
3210 supportedExtensions.robustClientMemory = true;
3211
3212 // Determine robust resource init availability from EGL.
Geoff Lang33f11fb2018-05-07 13:42:47 -04003213 supportedExtensions.robustResourceInitialization = mGLState.isRobustResourceInitEnabled();
Geoff Langb0f917f2017-12-05 13:41:54 -05003214
3215 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
3216 // supports it.
3217 supportedExtensions.robustBufferAccessBehavior =
3218 mRobustAccess && supportedExtensions.robustBufferAccessBehavior;
3219
3220 // Enable the cache control query unconditionally.
3221 supportedExtensions.programCacheControl = true;
3222
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003223 // Enable EGL_ANGLE_explicit_context subextensions
Geoff Lang33f11fb2018-05-07 13:42:47 -04003224 if (mExplicitContextAvailable)
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003225 {
3226 // GL_ANGLE_explicit_context_gles1
3227 supportedExtensions.explicitContextGles1 = true;
3228 // GL_ANGLE_explicit_context
3229 supportedExtensions.explicitContext = true;
3230 }
3231
Geoff Langb0f917f2017-12-05 13:41:54 -05003232 return supportedExtensions;
3233}
3234
Geoff Lang33f11fb2018-05-07 13:42:47 -04003235void Context::initCaps()
Geoff Lang493daf52014-07-03 13:38:44 -04003236{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04003237 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04003238
Geoff Lang33f11fb2018-05-07 13:42:47 -04003239 mSupportedExtensions = generateSupportedExtensions();
3240 mExtensions = mSupportedExtensions;
Lingfeng Yang01074432018-04-16 10:19:51 -07003241
3242 mLimitations = mImplementation->getNativeLimitations();
3243
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003244 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
3245 if (getClientVersion() < Version(2, 0))
3246 {
3247 mCaps.maxMultitextureUnits = 4;
3248 mCaps.maxClipPlanes = 6;
3249 mCaps.maxLights = 8;
Lingfeng Yange547aac2018-04-05 09:39:20 -07003250 mCaps.maxModelviewMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3251 mCaps.maxProjectionMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3252 mCaps.maxTextureMatrixStackDepth = Caps::GlobalMatrixStackDepth;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003253 mCaps.minSmoothPointSize = 1.0f;
3254 mCaps.maxSmoothPointSize = 1.0f;
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07003255 mCaps.minSmoothLineWidth = 1.0f;
3256 mCaps.maxSmoothLineWidth = 1.0f;
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003257 }
3258
Luc Ferronad2ae932018-06-11 15:31:17 -04003259 // Apply/Verify implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04003260 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003261
Luc Ferronad2ae932018-06-11 15:31:17 -04003262 ASSERT(mCaps.minAliasedPointSize >= 1.0f);
3263
Jamie Madill0f80ed82017-09-19 00:24:56 -04003264 if (getClientVersion() < ES_3_1)
3265 {
3266 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
3267 }
3268 else
3269 {
3270 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
3271 }
Geoff Lang301d1612014-07-09 10:34:37 -04003272
Jiawei Shao54aafe52018-04-27 14:54:57 +08003273 LimitCap(&mCaps.maxShaderUniformBlocks[ShaderType::Vertex],
3274 IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
Jamie Madill6d32cef2018-08-14 02:34:28 -04003275 LimitCap(&mCaps.maxUniformBufferBindings, IMPLEMENTATION_MAX_UNIFORM_BUFFER_BINDINGS);
3276
Jamie Madill0f80ed82017-09-19 00:24:56 -04003277 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3278 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3279
3280 // Limit textures as well, so we can use fast bitsets with texture bindings.
3281 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
Jiawei Shao54aafe52018-04-27 14:54:57 +08003282 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Vertex],
3283 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
3284 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Fragment],
3285 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04003286
Jiawei Shaodb342272017-09-27 10:21:45 +08003287 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
3288
Geoff Langc287ea62016-09-16 14:46:51 -04003289 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05003290 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04003291 for (const auto &extensionInfo : GetExtensionInfoMap())
3292 {
Geoff Lang0ab41fa2018-03-14 11:03:30 -04003293 // If the user has requested that extensions start disabled and they are requestable,
3294 // disable them.
3295 if (!mExtensionsEnabled && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04003296 {
3297 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
3298 }
3299 }
3300
3301 // Generate texture caps
3302 updateCaps();
3303}
3304
3305void Context::updateCaps()
3306{
Geoff Lang900013c2014-07-07 11:32:19 -04003307 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04003308 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04003309
Jamie Madill7b62cf92017-11-02 15:20:49 -04003310 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04003311 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04003312 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04003313 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003314
Geoff Lang0d8b7242015-09-09 14:56:53 -04003315 // Update the format caps based on the client version and extensions.
3316 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
3317 // ES3.
3318 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003319 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04003320 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003321 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Yuly Novikovf15f8862018-06-04 18:59:41 -04003322 formatCaps.textureAttachment =
3323 formatCaps.textureAttachment &&
3324 formatInfo.textureAttachmentSupport(getClientVersion(), mExtensions);
3325 formatCaps.renderbuffer = formatCaps.renderbuffer &&
3326 formatInfo.renderbufferSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04003327
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003328 // OpenGL ES does not support multisampling with non-rendererable formats
3329 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Yuly Novikovf15f8862018-06-04 18:59:41 -04003330 if (!formatCaps.renderbuffer ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003331 (getClientVersion() < ES_3_1 &&
3332 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04003333 {
Geoff Langd87878e2014-09-19 15:42:59 -04003334 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04003335 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03003336 else
3337 {
3338 // We may have limited the max samples for some required renderbuffer formats due to
3339 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
3340 GLuint formatMaxSamples = formatCaps.getMaxSamples();
3341
3342 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
3343 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
3344 // exception of signed and unsigned integer formats."
3345 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
3346 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
3347 {
3348 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
3349 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
3350 }
3351
3352 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
3353 if (getClientVersion() >= ES_3_1)
3354 {
3355 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
3356 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
3357 // the exception that the signed and unsigned integer formats are required only to
3358 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
3359 // multisamples, which must be at least one."
3360 if (formatInfo.componentType == GL_INT ||
3361 formatInfo.componentType == GL_UNSIGNED_INT)
3362 {
3363 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
3364 }
3365
3366 // GLES 3.1 section 19.3.1.
3367 if (formatCaps.texturable)
3368 {
3369 if (formatInfo.depthBits > 0)
3370 {
3371 mCaps.maxDepthTextureSamples =
3372 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
3373 }
3374 else if (formatInfo.redBits > 0)
3375 {
3376 mCaps.maxColorTextureSamples =
3377 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
3378 }
3379 }
3380 }
3381 }
Geoff Langd87878e2014-09-19 15:42:59 -04003382
3383 if (formatCaps.texturable && formatInfo.compressed)
3384 {
Geoff Langca271392017-04-05 12:30:00 -04003385 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003386 }
3387
Geoff Langca271392017-04-05 12:30:00 -04003388 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04003389 }
Jamie Madill32447362017-06-28 14:53:52 -04003390
3391 // If program binary is disabled, blank out the memory cache pointer.
Geoff Langb0f917f2017-12-05 13:41:54 -05003392 if (!mSupportedExtensions.getProgramBinary)
Jamie Madill32447362017-06-28 14:53:52 -04003393 {
3394 mMemoryProgramCache = nullptr;
3395 }
Corentin Walleze4477002017-12-01 14:39:58 -05003396
3397 // Compute which buffer types are allowed
3398 mValidBufferBindings.reset();
3399 mValidBufferBindings.set(BufferBinding::ElementArray);
3400 mValidBufferBindings.set(BufferBinding::Array);
3401
3402 if (mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
3403 {
3404 mValidBufferBindings.set(BufferBinding::PixelPack);
3405 mValidBufferBindings.set(BufferBinding::PixelUnpack);
3406 }
3407
3408 if (getClientVersion() >= ES_3_0)
3409 {
3410 mValidBufferBindings.set(BufferBinding::CopyRead);
3411 mValidBufferBindings.set(BufferBinding::CopyWrite);
3412 mValidBufferBindings.set(BufferBinding::TransformFeedback);
3413 mValidBufferBindings.set(BufferBinding::Uniform);
3414 }
3415
3416 if (getClientVersion() >= ES_3_1)
3417 {
3418 mValidBufferBindings.set(BufferBinding::AtomicCounter);
3419 mValidBufferBindings.set(BufferBinding::ShaderStorage);
3420 mValidBufferBindings.set(BufferBinding::DrawIndirect);
3421 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
3422 }
jchen107ae70d82018-07-06 13:47:01 +08003423
3424 mThreadPool = angle::WorkerThreadPool::Create(mExtensions.parallelShaderCompile);
Geoff Lang493daf52014-07-03 13:38:44 -04003425}
3426
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003427void Context::initWorkarounds()
3428{
Jamie Madill761b02c2017-06-23 16:27:06 -04003429 // Apply back-end workarounds.
3430 mImplementation->applyNativeWorkarounds(&mWorkarounds);
3431
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003432 // Lose the context upon out of memory error if the application is
3433 // expecting to watch for those events.
3434 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
3435}
3436
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06003437// Return true if the draw is a no-op, else return false.
3438// A no-op draw occurs if the count of vertices is less than the minimum required to
3439// have a valid primitive for this mode (0 for points, 0-1 for lines, 0-2 for tris).
3440bool Context::noopDraw(PrimitiveMode mode, GLsizei count)
3441{
3442 return count < kMinimumPrimitiveCounts[mode];
3443}
3444
3445bool Context::noopDrawInstanced(PrimitiveMode mode, GLsizei count, GLsizei instanceCount)
3446{
3447 return (instanceCount == 0) || noopDraw(mode, count);
3448}
3449
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003450Error Context::prepareForDraw(PrimitiveMode mode)
Jamie Madill05b35b22017-10-03 09:01:44 -04003451{
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003452 if (mGLES1Renderer)
3453 {
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003454 ANGLE_TRY(mGLES1Renderer->prepareForDraw(mode, this, &mGLState));
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003455 }
3456
Geoff Lang9bf86f02018-07-26 11:46:34 -04003457 ANGLE_TRY(syncDirtyObjects(mDrawDirtyObjects));
Jamie Madilla59fc192017-11-02 12:57:58 -04003458
3459 if (isRobustResourceInitEnabled())
3460 {
3461 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
3462 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
3463 }
3464
Geoff Langa8cb2872018-03-09 16:09:40 -05003465 ANGLE_TRY(syncDirtyBits());
Geoff Langd4fff502017-09-22 11:28:28 -04003466 return NoError();
3467}
3468
3469Error Context::prepareForClear(GLbitfield mask)
3470{
Geoff Langa8cb2872018-03-09 16:09:40 -05003471 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003472 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearAttachmentsInitialized(this, mask));
Geoff Langa8cb2872018-03-09 16:09:40 -05003473 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04003474 return NoError();
3475}
3476
3477Error Context::prepareForClearBuffer(GLenum buffer, GLint drawbuffer)
3478{
Geoff Langa8cb2872018-03-09 16:09:40 -05003479 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003480 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearBufferAttachmentsInitialized(this, buffer,
3481 drawbuffer));
Geoff Langa8cb2872018-03-09 16:09:40 -05003482 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill05b35b22017-10-03 09:01:44 -04003483 return NoError();
3484}
3485
Geoff Langa8cb2872018-03-09 16:09:40 -05003486Error Context::syncState(const State::DirtyBits &bitMask, const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04003487{
Geoff Langa8cb2872018-03-09 16:09:40 -05003488 ANGLE_TRY(syncDirtyObjects(objectMask));
3489 ANGLE_TRY(syncDirtyBits(bitMask));
Geoff Langd4fff502017-09-22 11:28:28 -04003490 return NoError();
3491}
3492
Geoff Langa8cb2872018-03-09 16:09:40 -05003493Error Context::syncDirtyBits()
Geoff Langd4fff502017-09-22 11:28:28 -04003494{
3495 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
Jamie Madill189ad872018-07-09 13:32:37 -04003496 ANGLE_TRY(mImplementation->syncState(this, dirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04003497 mGLState.clearDirtyBits();
3498 return NoError();
3499}
3500
Geoff Langa8cb2872018-03-09 16:09:40 -05003501Error Context::syncDirtyBits(const State::DirtyBits &bitMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003502{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003503 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madill189ad872018-07-09 13:32:37 -04003504 ANGLE_TRY(mImplementation->syncState(this, dirtyBits));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003505 mGLState.clearDirtyBits(dirtyBits);
Jamie Madillbc918e72018-03-08 09:47:21 -05003506 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003507}
Jamie Madillc29968b2016-01-20 11:17:23 -05003508
Geoff Langa8cb2872018-03-09 16:09:40 -05003509Error Context::syncDirtyObjects(const State::DirtyObjects &objectMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003510{
3511 return mGLState.syncDirtyObjects(this, objectMask);
3512}
3513
Jamie Madillc29968b2016-01-20 11:17:23 -05003514void Context::blitFramebuffer(GLint srcX0,
3515 GLint srcY0,
3516 GLint srcX1,
3517 GLint srcY1,
3518 GLint dstX0,
3519 GLint dstY0,
3520 GLint dstX1,
3521 GLint dstY1,
3522 GLbitfield mask,
3523 GLenum filter)
3524{
Qin Jiajiaaef92162018-02-27 13:51:44 +08003525 if (mask == 0)
3526 {
3527 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
3528 // buffers are copied.
3529 return;
3530 }
3531
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003532 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003533 ASSERT(drawFramebuffer);
3534
3535 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
3536 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
3537
Jamie Madillbc918e72018-03-08 09:47:21 -05003538 ANGLE_CONTEXT_TRY(syncStateForBlit());
Jamie Madillc29968b2016-01-20 11:17:23 -05003539
Jamie Madillc564c072017-06-01 12:45:42 -04003540 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003541}
Jamie Madillc29968b2016-01-20 11:17:23 -05003542
3543void Context::clear(GLbitfield mask)
3544{
Geoff Langd4fff502017-09-22 11:28:28 -04003545 ANGLE_CONTEXT_TRY(prepareForClear(mask));
3546 ANGLE_CONTEXT_TRY(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05003547}
3548
3549void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
3550{
Geoff Langd4fff502017-09-22 11:28:28 -04003551 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3552 ANGLE_CONTEXT_TRY(
3553 mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003554}
3555
3556void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3557{
Geoff Langd4fff502017-09-22 11:28:28 -04003558 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3559 ANGLE_CONTEXT_TRY(
3560 mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003561}
3562
3563void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3564{
Geoff Langd4fff502017-09-22 11:28:28 -04003565 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3566 ANGLE_CONTEXT_TRY(
3567 mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003568}
3569
3570void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3571{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003572 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003573 ASSERT(framebufferObject);
3574
3575 // If a buffer is not present, the clear has no effect
3576 if (framebufferObject->getDepthbuffer() == nullptr &&
3577 framebufferObject->getStencilbuffer() == nullptr)
3578 {
3579 return;
3580 }
3581
Geoff Langd4fff502017-09-22 11:28:28 -04003582 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3583 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003584}
3585
3586void Context::readPixels(GLint x,
3587 GLint y,
3588 GLsizei width,
3589 GLsizei height,
3590 GLenum format,
3591 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003592 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003593{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003594 if (width == 0 || height == 0)
3595 {
3596 return;
3597 }
3598
Jamie Madillbc918e72018-03-08 09:47:21 -05003599 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003600
Jamie Madillb6664922017-07-25 12:55:04 -04003601 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3602 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003603
3604 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04003605 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003606}
3607
Brandon Jones59770802018-04-02 13:18:42 -07003608void Context::readPixelsRobust(GLint x,
3609 GLint y,
3610 GLsizei width,
3611 GLsizei height,
3612 GLenum format,
3613 GLenum type,
3614 GLsizei bufSize,
3615 GLsizei *length,
3616 GLsizei *columns,
3617 GLsizei *rows,
3618 void *pixels)
3619{
3620 readPixels(x, y, width, height, format, type, pixels);
3621}
3622
3623void Context::readnPixelsRobust(GLint x,
3624 GLint y,
3625 GLsizei width,
3626 GLsizei height,
3627 GLenum format,
3628 GLenum type,
3629 GLsizei bufSize,
3630 GLsizei *length,
3631 GLsizei *columns,
3632 GLsizei *rows,
3633 void *data)
3634{
3635 readPixels(x, y, width, height, format, type, data);
3636}
3637
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003638void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003639 GLint level,
3640 GLenum internalformat,
3641 GLint x,
3642 GLint y,
3643 GLsizei width,
3644 GLsizei height,
3645 GLint border)
3646{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003647 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003648 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003649
Jamie Madillc29968b2016-01-20 11:17:23 -05003650 Rectangle sourceArea(x, y, width, height);
3651
Jamie Madill05b35b22017-10-03 09:01:44 -04003652 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003653 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003654 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003655}
3656
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003657void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003658 GLint level,
3659 GLint xoffset,
3660 GLint yoffset,
3661 GLint x,
3662 GLint y,
3663 GLsizei width,
3664 GLsizei height)
3665{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003666 if (width == 0 || height == 0)
3667 {
3668 return;
3669 }
3670
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003671 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003672 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003673
Jamie Madillc29968b2016-01-20 11:17:23 -05003674 Offset destOffset(xoffset, yoffset, 0);
3675 Rectangle sourceArea(x, y, width, height);
3676
Jamie Madill05b35b22017-10-03 09:01:44 -04003677 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003678 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003679 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003680}
3681
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003682void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003683 GLint level,
3684 GLint xoffset,
3685 GLint yoffset,
3686 GLint zoffset,
3687 GLint x,
3688 GLint y,
3689 GLsizei width,
3690 GLsizei height)
3691{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003692 if (width == 0 || height == 0)
3693 {
3694 return;
3695 }
3696
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003697 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003698 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003699
Jamie Madillc29968b2016-01-20 11:17:23 -05003700 Offset destOffset(xoffset, yoffset, zoffset);
3701 Rectangle sourceArea(x, y, width, height);
3702
Jamie Madill05b35b22017-10-03 09:01:44 -04003703 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3704 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003705 handleError(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level, destOffset,
3706 sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003707}
3708
3709void Context::framebufferTexture2D(GLenum target,
3710 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003711 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003712 GLuint texture,
3713 GLint level)
3714{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003715 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003716 ASSERT(framebuffer);
3717
3718 if (texture != 0)
3719 {
3720 Texture *textureObj = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003721 ImageIndex index = ImageIndex::MakeFromTarget(textarget, level);
Jamie Madilla02315b2017-02-23 14:14:47 -05003722 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003723 }
3724 else
3725 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003726 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003727 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003728
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003729 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003730}
3731
3732void Context::framebufferRenderbuffer(GLenum target,
3733 GLenum attachment,
3734 GLenum renderbuffertarget,
3735 GLuint renderbuffer)
3736{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003737 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003738 ASSERT(framebuffer);
3739
3740 if (renderbuffer != 0)
3741 {
3742 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003743
Jamie Madillcc129372018-04-12 09:13:18 -04003744 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003745 renderbufferObject);
3746 }
3747 else
3748 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003749 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003750 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003751
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003752 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003753}
3754
3755void Context::framebufferTextureLayer(GLenum target,
3756 GLenum attachment,
3757 GLuint texture,
3758 GLint level,
3759 GLint layer)
3760{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003761 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003762 ASSERT(framebuffer);
3763
3764 if (texture != 0)
3765 {
3766 Texture *textureObject = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003767 ImageIndex index = ImageIndex::MakeFromType(textureObject->getType(), level, layer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003768 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003769 }
3770 else
3771 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003772 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003773 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003774
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003775 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003776}
3777
Brandon Jones59770802018-04-02 13:18:42 -07003778void Context::framebufferTextureMultiviewLayered(GLenum target,
3779 GLenum attachment,
3780 GLuint texture,
3781 GLint level,
3782 GLint baseViewIndex,
3783 GLsizei numViews)
Martin Radev137032d2017-07-13 10:11:12 +03003784{
Martin Radev82ef7742017-08-08 17:44:58 +03003785 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3786 ASSERT(framebuffer);
3787
3788 if (texture != 0)
3789 {
3790 Texture *textureObj = getTexture(texture);
3791
Martin Radev18b75ba2017-08-15 15:50:40 +03003792 ImageIndex index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
Martin Radev82ef7742017-08-08 17:44:58 +03003793 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3794 numViews, baseViewIndex);
3795 }
3796 else
3797 {
3798 framebuffer->resetAttachment(this, attachment);
3799 }
3800
3801 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003802}
3803
Brandon Jones59770802018-04-02 13:18:42 -07003804void Context::framebufferTextureMultiviewSideBySide(GLenum target,
3805 GLenum attachment,
3806 GLuint texture,
3807 GLint level,
3808 GLsizei numViews,
3809 const GLint *viewportOffsets)
Martin Radev137032d2017-07-13 10:11:12 +03003810{
Martin Radev5dae57b2017-07-14 16:15:55 +03003811 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3812 ASSERT(framebuffer);
3813
3814 if (texture != 0)
3815 {
3816 Texture *textureObj = getTexture(texture);
3817
3818 ImageIndex index = ImageIndex::Make2D(level);
3819 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3820 textureObj, numViews, viewportOffsets);
3821 }
3822 else
3823 {
3824 framebuffer->resetAttachment(this, attachment);
3825 }
3826
3827 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003828}
3829
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003830void Context::framebufferTexture(GLenum target, GLenum attachment, GLuint texture, GLint level)
3831{
Jiawei Shaoa8802472018-05-28 11:17:47 +08003832 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3833 ASSERT(framebuffer);
3834
3835 if (texture != 0)
3836 {
3837 Texture *textureObj = getTexture(texture);
3838
3839 ImageIndex index = ImageIndex::MakeFromType(
3840 textureObj->getType(), level, ImageIndex::kEntireLevel, ImageIndex::kEntireLevel);
3841 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
3842 }
3843 else
3844 {
3845 framebuffer->resetAttachment(this, attachment);
3846 }
3847
3848 mGLState.setObjectDirty(target);
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003849}
3850
Jamie Madillc29968b2016-01-20 11:17:23 -05003851void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3852{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003853 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003854 ASSERT(framebuffer);
3855 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003856 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madilld84b6732018-09-06 15:54:35 -04003857 mStateCache.onDrawFramebufferChange(this);
Jamie Madillc29968b2016-01-20 11:17:23 -05003858}
3859
3860void Context::readBuffer(GLenum mode)
3861{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003862 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003863 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003864 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003865}
3866
3867void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3868{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003869 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003870 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003871
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003872 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003873 ASSERT(framebuffer);
3874
3875 // The specification isn't clear what should be done when the framebuffer isn't complete.
3876 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003877 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003878}
3879
3880void Context::invalidateFramebuffer(GLenum target,
3881 GLsizei numAttachments,
3882 const GLenum *attachments)
3883{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003884 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003885 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003886
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003887 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003888 ASSERT(framebuffer);
3889
Jamie Madill427064d2018-04-13 16:20:34 -04003890 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003891 {
Jamie Madill437fa652016-05-03 15:13:24 -04003892 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003893 }
Jamie Madill437fa652016-05-03 15:13:24 -04003894
Jamie Madill4928b7c2017-06-20 12:57:39 -04003895 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003896}
3897
3898void Context::invalidateSubFramebuffer(GLenum target,
3899 GLsizei numAttachments,
3900 const GLenum *attachments,
3901 GLint x,
3902 GLint y,
3903 GLsizei width,
3904 GLsizei height)
3905{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003906 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003907 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003908
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003909 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003910 ASSERT(framebuffer);
3911
Jamie Madill427064d2018-04-13 16:20:34 -04003912 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003913 {
Jamie Madill437fa652016-05-03 15:13:24 -04003914 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003915 }
Jamie Madill437fa652016-05-03 15:13:24 -04003916
3917 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003918 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003919}
3920
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003921void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003922 GLint level,
3923 GLint internalformat,
3924 GLsizei width,
3925 GLsizei height,
3926 GLint border,
3927 GLenum format,
3928 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003929 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003930{
Jamie Madillbc918e72018-03-08 09:47:21 -05003931 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003932
3933 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003934 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003935 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003936 size, format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003937}
3938
Brandon Jones59770802018-04-02 13:18:42 -07003939void Context::texImage2DRobust(TextureTarget target,
3940 GLint level,
3941 GLint internalformat,
3942 GLsizei width,
3943 GLsizei height,
3944 GLint border,
3945 GLenum format,
3946 GLenum type,
3947 GLsizei bufSize,
3948 const void *pixels)
3949{
3950 texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
3951}
3952
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003953void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003954 GLint level,
3955 GLint internalformat,
3956 GLsizei width,
3957 GLsizei height,
3958 GLsizei depth,
3959 GLint border,
3960 GLenum format,
3961 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003962 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003963{
Jamie Madillbc918e72018-03-08 09:47:21 -05003964 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003965
3966 Extents size(width, height, depth);
3967 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003968 handleError(texture->setImage(this, mGLState.getUnpackState(),
3969 NonCubeTextureTypeToTarget(target), level, internalformat, size,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003970 format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003971}
3972
Brandon Jones59770802018-04-02 13:18:42 -07003973void Context::texImage3DRobust(TextureType target,
3974 GLint level,
3975 GLint internalformat,
3976 GLsizei width,
3977 GLsizei height,
3978 GLsizei depth,
3979 GLint border,
3980 GLenum format,
3981 GLenum type,
3982 GLsizei bufSize,
3983 const void *pixels)
3984{
3985 texImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels);
3986}
3987
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003988void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003989 GLint level,
3990 GLint xoffset,
3991 GLint yoffset,
3992 GLsizei width,
3993 GLsizei height,
3994 GLenum format,
3995 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003996 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003997{
3998 // Zero sized uploads are valid but no-ops
3999 if (width == 0 || height == 0)
4000 {
4001 return;
4002 }
4003
Jamie Madillbc918e72018-03-08 09:47:21 -05004004 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004005
4006 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004007 Texture *texture = getTargetTexture(TextureTargetToType(target));
Jamie Madill0d0fb432018-09-07 17:43:32 -04004008
4009 gl::Buffer *unpackBuffer = mGLState.getTargetBuffer(gl::BufferBinding::PixelUnpack);
4010
4011 handleError(texture->setSubImage(this, mGLState.getUnpackState(), unpackBuffer, target, level,
4012 area, format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004013}
4014
Brandon Jones59770802018-04-02 13:18:42 -07004015void Context::texSubImage2DRobust(TextureTarget target,
4016 GLint level,
4017 GLint xoffset,
4018 GLint yoffset,
4019 GLsizei width,
4020 GLsizei height,
4021 GLenum format,
4022 GLenum type,
4023 GLsizei bufSize,
4024 const void *pixels)
4025{
4026 texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
4027}
4028
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004029void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004030 GLint level,
4031 GLint xoffset,
4032 GLint yoffset,
4033 GLint zoffset,
4034 GLsizei width,
4035 GLsizei height,
4036 GLsizei depth,
4037 GLenum format,
4038 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04004039 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05004040{
4041 // Zero sized uploads are valid but no-ops
4042 if (width == 0 || height == 0 || depth == 0)
4043 {
4044 return;
4045 }
4046
Jamie Madillbc918e72018-03-08 09:47:21 -05004047 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004048
4049 Box area(xoffset, yoffset, zoffset, width, height, depth);
4050 Texture *texture = getTargetTexture(target);
Jamie Madill0d0fb432018-09-07 17:43:32 -04004051
4052 gl::Buffer *unpackBuffer = mGLState.getTargetBuffer(gl::BufferBinding::PixelUnpack);
4053
4054 handleError(texture->setSubImage(this, mGLState.getUnpackState(), unpackBuffer,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004055 NonCubeTextureTypeToTarget(target), level, area, format, type,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004056 static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004057}
4058
Brandon Jones59770802018-04-02 13:18:42 -07004059void Context::texSubImage3DRobust(TextureType target,
4060 GLint level,
4061 GLint xoffset,
4062 GLint yoffset,
4063 GLint zoffset,
4064 GLsizei width,
4065 GLsizei height,
4066 GLsizei depth,
4067 GLenum format,
4068 GLenum type,
4069 GLsizei bufSize,
4070 const void *pixels)
4071{
4072 texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type,
4073 pixels);
4074}
4075
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004076void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004077 GLint level,
4078 GLenum internalformat,
4079 GLsizei width,
4080 GLsizei height,
4081 GLint border,
4082 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004083 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004084{
Jamie Madillbc918e72018-03-08 09:47:21 -05004085 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004086
4087 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004088 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05004089 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
4090 internalformat, size, imageSize,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004091 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004092}
4093
Brandon Jones59770802018-04-02 13:18:42 -07004094void Context::compressedTexImage2DRobust(TextureTarget target,
4095 GLint level,
4096 GLenum internalformat,
4097 GLsizei width,
4098 GLsizei height,
4099 GLint border,
4100 GLsizei imageSize,
4101 GLsizei dataSize,
4102 const GLvoid *data)
4103{
4104 compressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
4105}
4106
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004107void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004108 GLint level,
4109 GLenum internalformat,
4110 GLsizei width,
4111 GLsizei height,
4112 GLsizei depth,
4113 GLint border,
4114 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004115 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004116{
Jamie Madillbc918e72018-03-08 09:47:21 -05004117 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004118
4119 Extents size(width, height, depth);
4120 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004121 handleError(texture->setCompressedImage(
4122 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004123 size, imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004124}
4125
Brandon Jones59770802018-04-02 13:18:42 -07004126void Context::compressedTexImage3DRobust(TextureType target,
4127 GLint level,
4128 GLenum internalformat,
4129 GLsizei width,
4130 GLsizei height,
4131 GLsizei depth,
4132 GLint border,
4133 GLsizei imageSize,
4134 GLsizei dataSize,
4135 const GLvoid *data)
4136{
4137 compressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize,
4138 data);
4139}
4140
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004141void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004142 GLint level,
4143 GLint xoffset,
4144 GLint yoffset,
4145 GLsizei width,
4146 GLsizei height,
4147 GLenum format,
4148 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004149 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004150{
Jamie Madillbc918e72018-03-08 09:47:21 -05004151 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004152
4153 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004154 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05004155 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
4156 format, imageSize,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004157 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004158}
4159
Brandon Jones59770802018-04-02 13:18:42 -07004160void Context::compressedTexSubImage2DRobust(TextureTarget target,
4161 GLint level,
4162 GLint xoffset,
4163 GLint yoffset,
4164 GLsizei width,
4165 GLsizei height,
4166 GLenum format,
4167 GLsizei imageSize,
4168 GLsizei dataSize,
4169 const GLvoid *data)
4170{
4171 compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize,
4172 data);
4173}
4174
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004175void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004176 GLint level,
4177 GLint xoffset,
4178 GLint yoffset,
4179 GLint zoffset,
4180 GLsizei width,
4181 GLsizei height,
4182 GLsizei depth,
4183 GLenum format,
4184 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004185 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004186{
4187 // Zero sized uploads are valid but no-ops
4188 if (width == 0 || height == 0)
4189 {
4190 return;
4191 }
4192
Jamie Madillbc918e72018-03-08 09:47:21 -05004193 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004194
4195 Box area(xoffset, yoffset, zoffset, width, height, depth);
4196 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004197 handleError(texture->setCompressedSubImage(
4198 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004199 imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004200}
4201
Brandon Jones59770802018-04-02 13:18:42 -07004202void Context::compressedTexSubImage3DRobust(TextureType target,
4203 GLint level,
4204 GLint xoffset,
4205 GLint yoffset,
4206 GLint zoffset,
4207 GLsizei width,
4208 GLsizei height,
4209 GLsizei depth,
4210 GLenum format,
4211 GLsizei imageSize,
4212 GLsizei dataSize,
4213 const GLvoid *data)
4214{
4215 compressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format,
4216 imageSize, data);
4217}
4218
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004219void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004220{
4221 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05004222 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004223}
4224
Jamie Madill007530e2017-12-28 14:27:04 -05004225void Context::copyTexture(GLuint sourceId,
4226 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004227 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004228 GLuint destId,
4229 GLint destLevel,
4230 GLint internalFormat,
4231 GLenum destType,
4232 GLboolean unpackFlipY,
4233 GLboolean unpackPremultiplyAlpha,
4234 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004235{
Jamie Madillbc918e72018-03-08 09:47:21 -05004236 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004237
4238 gl::Texture *sourceTexture = getTexture(sourceId);
4239 gl::Texture *destTexture = getTexture(destId);
Geoff Lang92019432017-11-20 13:09:34 -05004240 handleError(destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType,
4241 sourceLevel, ConvertToBool(unpackFlipY),
4242 ConvertToBool(unpackPremultiplyAlpha),
4243 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004244}
4245
Jamie Madill007530e2017-12-28 14:27:04 -05004246void Context::copySubTexture(GLuint sourceId,
4247 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004248 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004249 GLuint destId,
4250 GLint destLevel,
4251 GLint xoffset,
4252 GLint yoffset,
4253 GLint x,
4254 GLint y,
4255 GLsizei width,
4256 GLsizei height,
4257 GLboolean unpackFlipY,
4258 GLboolean unpackPremultiplyAlpha,
4259 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004260{
4261 // Zero sized copies are valid but no-ops
4262 if (width == 0 || height == 0)
4263 {
4264 return;
4265 }
4266
Jamie Madillbc918e72018-03-08 09:47:21 -05004267 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004268
4269 gl::Texture *sourceTexture = getTexture(sourceId);
4270 gl::Texture *destTexture = getTexture(destId);
4271 Offset offset(xoffset, yoffset, 0);
4272 Rectangle area(x, y, width, height);
Geoff Lang92019432017-11-20 13:09:34 -05004273 handleError(destTexture->copySubTexture(this, destTarget, destLevel, offset, sourceLevel, area,
4274 ConvertToBool(unpackFlipY),
4275 ConvertToBool(unpackPremultiplyAlpha),
4276 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004277}
4278
Jamie Madill007530e2017-12-28 14:27:04 -05004279void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07004280{
Jamie Madillbc918e72018-03-08 09:47:21 -05004281 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07004282
4283 gl::Texture *sourceTexture = getTexture(sourceId);
4284 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05004285 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07004286}
4287
Corentin Wallez336129f2017-10-17 15:55:40 -04004288void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03004289{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004290 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004291 ASSERT(buffer);
4292
Geoff Lang496c02d2016-10-20 11:38:11 -07004293 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03004294}
4295
Brandon Jones59770802018-04-02 13:18:42 -07004296void Context::getBufferPointervRobust(BufferBinding target,
4297 GLenum pname,
4298 GLsizei bufSize,
4299 GLsizei *length,
4300 void **params)
4301{
4302 getBufferPointerv(target, pname, params);
4303}
4304
Corentin Wallez336129f2017-10-17 15:55:40 -04004305void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004306{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004307 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004308 ASSERT(buffer);
4309
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004310 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004311 if (error.isError())
4312 {
Jamie Madill437fa652016-05-03 15:13:24 -04004313 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004314 return nullptr;
4315 }
4316
4317 return buffer->getMapPointer();
4318}
4319
Corentin Wallez336129f2017-10-17 15:55:40 -04004320GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03004321{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004322 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004323 ASSERT(buffer);
4324
4325 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004326 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03004327 if (error.isError())
4328 {
Jamie Madill437fa652016-05-03 15:13:24 -04004329 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004330 return GL_FALSE;
4331 }
4332
4333 return result;
4334}
4335
Corentin Wallez336129f2017-10-17 15:55:40 -04004336void *Context::mapBufferRange(BufferBinding target,
4337 GLintptr offset,
4338 GLsizeiptr length,
4339 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004340{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004341 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004342 ASSERT(buffer);
4343
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004344 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004345 if (error.isError())
4346 {
Jamie Madill437fa652016-05-03 15:13:24 -04004347 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004348 return nullptr;
4349 }
4350
4351 return buffer->getMapPointer();
4352}
4353
Corentin Wallez336129f2017-10-17 15:55:40 -04004354void Context::flushMappedBufferRange(BufferBinding /*target*/,
4355 GLintptr /*offset*/,
4356 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03004357{
4358 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
4359}
4360
Jamie Madillbc918e72018-03-08 09:47:21 -05004361Error Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004362{
Geoff Langa8cb2872018-03-09 16:09:40 -05004363 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004364}
4365
Jamie Madillbc918e72018-03-08 09:47:21 -05004366Error Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004367{
Geoff Langa8cb2872018-03-09 16:09:40 -05004368 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004369}
4370
Jamie Madillbc918e72018-03-08 09:47:21 -05004371Error Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004372{
Geoff Langa8cb2872018-03-09 16:09:40 -05004373 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004374}
4375
Geoff Lang9bf86f02018-07-26 11:46:34 -04004376Error Context::syncStateForPathOperation()
4377{
4378 ANGLE_TRY(syncDirtyObjects(mPathOperationDirtyObjects));
4379
4380 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
4381 ANGLE_TRY(syncDirtyBits());
4382
4383 return NoError();
4384}
4385
Jiajia Qin5451d532017-11-16 17:16:34 +08004386void Context::activeShaderProgram(GLuint pipeline, GLuint program)
4387{
4388 UNIMPLEMENTED();
4389}
4390
Jamie Madillc20ab272016-06-09 07:20:46 -07004391void Context::activeTexture(GLenum texture)
4392{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004393 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004394}
4395
Jamie Madill876429b2017-04-20 15:46:24 -04004396void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004397{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004398 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004399}
4400
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004401void Context::blendEquation(GLenum mode)
4402{
4403 mGLState.setBlendEquation(mode, mode);
4404}
4405
Jamie Madillc20ab272016-06-09 07:20:46 -07004406void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
4407{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004408 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004409}
4410
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004411void Context::blendFunc(GLenum sfactor, GLenum dfactor)
4412{
4413 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
4414}
4415
Jamie Madillc20ab272016-06-09 07:20:46 -07004416void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
4417{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004418 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004419}
4420
Jamie Madill876429b2017-04-20 15:46:24 -04004421void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004422{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004423 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004424}
4425
Jamie Madill876429b2017-04-20 15:46:24 -04004426void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07004427{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004428 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07004429}
4430
4431void Context::clearStencil(GLint s)
4432{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004433 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07004434}
4435
4436void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
4437{
Geoff Lang92019432017-11-20 13:09:34 -05004438 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
4439 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004440}
4441
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004442void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07004443{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004444 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004445}
4446
4447void Context::depthFunc(GLenum func)
4448{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004449 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07004450}
4451
4452void Context::depthMask(GLboolean flag)
4453{
Geoff Lang92019432017-11-20 13:09:34 -05004454 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07004455}
4456
Jamie Madill876429b2017-04-20 15:46:24 -04004457void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07004458{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004459 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07004460}
4461
4462void Context::disable(GLenum cap)
4463{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004464 mGLState.setEnableFeature(cap, false);
Jamie Madilld84b6732018-09-06 15:54:35 -04004465 mStateCache.onContextCapChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004466}
4467
4468void Context::disableVertexAttribArray(GLuint index)
4469{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004470 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004471 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004472}
4473
4474void Context::enable(GLenum cap)
4475{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004476 mGLState.setEnableFeature(cap, true);
Jamie Madilld84b6732018-09-06 15:54:35 -04004477 mStateCache.onContextCapChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004478}
4479
4480void Context::enableVertexAttribArray(GLuint index)
4481{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004482 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004483 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004484}
4485
4486void Context::frontFace(GLenum mode)
4487{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004488 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004489}
4490
4491void Context::hint(GLenum target, GLenum mode)
4492{
4493 switch (target)
4494 {
4495 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004496 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004497 break;
4498
4499 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004500 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004501 break;
4502
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07004503 case GL_PERSPECTIVE_CORRECTION_HINT:
4504 case GL_POINT_SMOOTH_HINT:
4505 case GL_LINE_SMOOTH_HINT:
4506 case GL_FOG_HINT:
4507 mGLState.gles1().setHint(target, mode);
4508 break;
Jamie Madillc20ab272016-06-09 07:20:46 -07004509 default:
4510 UNREACHABLE();
4511 return;
4512 }
4513}
4514
4515void Context::lineWidth(GLfloat width)
4516{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004517 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07004518}
4519
4520void Context::pixelStorei(GLenum pname, GLint param)
4521{
4522 switch (pname)
4523 {
4524 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004525 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004526 break;
4527
4528 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004529 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004530 break;
4531
4532 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004533 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004534 break;
4535
4536 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004537 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004538 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004539 break;
4540
4541 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03004542 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004543 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004544 break;
4545
4546 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03004547 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004548 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004549 break;
4550
4551 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004552 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004553 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004554 break;
4555
4556 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004557 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004558 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004559 break;
4560
4561 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004562 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004563 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004564 break;
4565
4566 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004567 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004568 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004569 break;
4570
4571 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004572 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004573 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004574 break;
4575
4576 default:
4577 UNREACHABLE();
4578 return;
4579 }
4580}
4581
4582void Context::polygonOffset(GLfloat factor, GLfloat units)
4583{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004584 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07004585}
4586
Jamie Madill876429b2017-04-20 15:46:24 -04004587void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07004588{
Geoff Lang92019432017-11-20 13:09:34 -05004589 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07004590}
4591
Jiawei Shaodb342272017-09-27 10:21:45 +08004592void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
4593{
4594 mGLState.setSampleMaskParams(maskNumber, mask);
4595}
4596
Jamie Madillc20ab272016-06-09 07:20:46 -07004597void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
4598{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004599 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004600}
4601
4602void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
4603{
4604 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4605 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004606 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004607 }
4608
4609 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4610 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004611 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004612 }
Jamie Madilld84b6732018-09-06 15:54:35 -04004613
4614 mStateCache.onStencilStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004615}
4616
4617void Context::stencilMaskSeparate(GLenum face, GLuint mask)
4618{
4619 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4620 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004621 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004622 }
4623
4624 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4625 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004626 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004627 }
Jamie Madilld84b6732018-09-06 15:54:35 -04004628
4629 mStateCache.onStencilStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004630}
4631
4632void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4633{
4634 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4635 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004636 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004637 }
4638
4639 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4640 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004641 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004642 }
4643}
4644
4645void Context::vertexAttrib1f(GLuint index, GLfloat x)
4646{
4647 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004648 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004649 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004650}
4651
4652void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
4653{
4654 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004655 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004656 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004657}
4658
4659void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4660{
4661 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004662 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004663 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004664}
4665
4666void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
4667{
4668 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004669 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004670 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004671}
4672
4673void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4674{
4675 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004676 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004677 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004678}
4679
4680void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
4681{
4682 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004683 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004684 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004685}
4686
4687void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4688{
4689 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004690 mGLState.setVertexAttribf(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004691 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004692}
4693
4694void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
4695{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004696 mGLState.setVertexAttribf(index, values);
Jamie Madilld84b6732018-09-06 15:54:35 -04004697 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004698}
4699
4700void Context::vertexAttribPointer(GLuint index,
4701 GLint size,
4702 GLenum type,
4703 GLboolean normalized,
4704 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004705 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07004706{
Corentin Wallez336129f2017-10-17 15:55:40 -04004707 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05004708 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004709 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004710}
4711
Shao80957d92017-02-20 21:25:59 +08004712void Context::vertexAttribFormat(GLuint attribIndex,
4713 GLint size,
4714 GLenum type,
4715 GLboolean normalized,
4716 GLuint relativeOffset)
4717{
Geoff Lang92019432017-11-20 13:09:34 -05004718 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08004719 relativeOffset);
Jamie Madilld84b6732018-09-06 15:54:35 -04004720 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004721}
4722
4723void Context::vertexAttribIFormat(GLuint attribIndex,
4724 GLint size,
4725 GLenum type,
4726 GLuint relativeOffset)
4727{
4728 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
Jamie Madilld84b6732018-09-06 15:54:35 -04004729 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004730}
4731
4732void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4733{
Shaodde78e82017-05-22 14:13:27 +08004734 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004735 mStateCache.onVertexArrayStateChange(this);
Shao80957d92017-02-20 21:25:59 +08004736}
4737
Jiajia Qin5451d532017-11-16 17:16:34 +08004738void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004739{
4740 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
Jamie Madilld84b6732018-09-06 15:54:35 -04004741 mStateCache.onVertexArrayFormatChange(this);
Shao80957d92017-02-20 21:25:59 +08004742}
4743
Jamie Madillc20ab272016-06-09 07:20:46 -07004744void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4745{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004746 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004747}
4748
4749void Context::vertexAttribIPointer(GLuint index,
4750 GLint size,
4751 GLenum type,
4752 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004753 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004754{
Corentin Wallez336129f2017-10-17 15:55:40 -04004755 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
4756 size, type, false, true, stride, pointer);
Jamie Madillc43cdad2018-08-08 15:49:25 -04004757 mStateCache.onVertexArrayStateChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004758}
4759
4760void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4761{
4762 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004763 mGLState.setVertexAttribi(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004764 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004765}
4766
4767void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4768{
4769 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004770 mGLState.setVertexAttribu(index, vals);
Jamie Madilld84b6732018-09-06 15:54:35 -04004771 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004772}
4773
4774void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4775{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004776 mGLState.setVertexAttribi(index, v);
Jamie Madilld84b6732018-09-06 15:54:35 -04004777 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004778}
4779
4780void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4781{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004782 mGLState.setVertexAttribu(index, v);
Jamie Madilld84b6732018-09-06 15:54:35 -04004783 mStateCache.onDefaultVertexAttributeChange(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004784}
4785
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004786void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4787{
4788 const VertexAttribCurrentValueData &currentValues =
4789 getGLState().getVertexAttribCurrentValue(index);
4790 const VertexArray *vao = getGLState().getVertexArray();
4791 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4792 currentValues, pname, params);
4793}
4794
Brandon Jones59770802018-04-02 13:18:42 -07004795void Context::getVertexAttribivRobust(GLuint index,
4796 GLenum pname,
4797 GLsizei bufSize,
4798 GLsizei *length,
4799 GLint *params)
4800{
4801 getVertexAttribiv(index, pname, params);
4802}
4803
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004804void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4805{
4806 const VertexAttribCurrentValueData &currentValues =
4807 getGLState().getVertexAttribCurrentValue(index);
4808 const VertexArray *vao = getGLState().getVertexArray();
4809 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4810 currentValues, pname, params);
4811}
4812
Brandon Jones59770802018-04-02 13:18:42 -07004813void Context::getVertexAttribfvRobust(GLuint index,
4814 GLenum pname,
4815 GLsizei bufSize,
4816 GLsizei *length,
4817 GLfloat *params)
4818{
4819 getVertexAttribfv(index, pname, params);
4820}
4821
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004822void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4823{
4824 const VertexAttribCurrentValueData &currentValues =
4825 getGLState().getVertexAttribCurrentValue(index);
4826 const VertexArray *vao = getGLState().getVertexArray();
4827 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4828 currentValues, pname, params);
4829}
4830
Brandon Jones59770802018-04-02 13:18:42 -07004831void Context::getVertexAttribIivRobust(GLuint index,
4832 GLenum pname,
4833 GLsizei bufSize,
4834 GLsizei *length,
4835 GLint *params)
4836{
4837 getVertexAttribIiv(index, pname, params);
4838}
4839
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004840void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4841{
4842 const VertexAttribCurrentValueData &currentValues =
4843 getGLState().getVertexAttribCurrentValue(index);
4844 const VertexArray *vao = getGLState().getVertexArray();
4845 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4846 currentValues, pname, params);
4847}
4848
Brandon Jones59770802018-04-02 13:18:42 -07004849void Context::getVertexAttribIuivRobust(GLuint index,
4850 GLenum pname,
4851 GLsizei bufSize,
4852 GLsizei *length,
4853 GLuint *params)
4854{
4855 getVertexAttribIuiv(index, pname, params);
4856}
4857
Jamie Madill876429b2017-04-20 15:46:24 -04004858void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004859{
4860 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
4861 QueryVertexAttribPointerv(attrib, pname, pointer);
4862}
4863
Brandon Jones59770802018-04-02 13:18:42 -07004864void Context::getVertexAttribPointervRobust(GLuint index,
4865 GLenum pname,
4866 GLsizei bufSize,
4867 GLsizei *length,
4868 void **pointer)
4869{
4870 getVertexAttribPointerv(index, pname, pointer);
4871}
4872
Jamie Madillc20ab272016-06-09 07:20:46 -07004873void Context::debugMessageControl(GLenum source,
4874 GLenum type,
4875 GLenum severity,
4876 GLsizei count,
4877 const GLuint *ids,
4878 GLboolean enabled)
4879{
4880 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004881 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05004882 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004883}
4884
4885void Context::debugMessageInsert(GLenum source,
4886 GLenum type,
4887 GLuint id,
4888 GLenum severity,
4889 GLsizei length,
4890 const GLchar *buf)
4891{
4892 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004893 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004894}
4895
4896void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4897{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004898 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004899}
4900
4901GLuint Context::getDebugMessageLog(GLuint count,
4902 GLsizei bufSize,
4903 GLenum *sources,
4904 GLenum *types,
4905 GLuint *ids,
4906 GLenum *severities,
4907 GLsizei *lengths,
4908 GLchar *messageLog)
4909{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004910 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4911 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004912}
4913
4914void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4915{
4916 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004917 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05004918 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07004919}
4920
4921void Context::popDebugGroup()
4922{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004923 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05004924 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004925}
4926
Corentin Wallez336129f2017-10-17 15:55:40 -04004927void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004928{
4929 Buffer *buffer = mGLState.getTargetBuffer(target);
4930 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004931 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004932}
4933
Corentin Wallez336129f2017-10-17 15:55:40 -04004934void Context::bufferSubData(BufferBinding target,
4935 GLintptr offset,
4936 GLsizeiptr size,
4937 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004938{
4939 if (data == nullptr)
4940 {
4941 return;
4942 }
4943
4944 Buffer *buffer = mGLState.getTargetBuffer(target);
4945 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004946 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004947}
4948
Jamie Madillef300b12016-10-07 15:12:09 -04004949void Context::attachShader(GLuint program, GLuint shader)
4950{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05004951 Program *programObject = mState.mShaderPrograms->getProgram(program);
4952 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004953 ASSERT(programObject && shaderObject);
4954 programObject->attachShader(shaderObject);
4955}
4956
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004957const Workarounds &Context::getWorkarounds() const
4958{
4959 return mWorkarounds;
4960}
4961
Corentin Wallez336129f2017-10-17 15:55:40 -04004962void Context::copyBufferSubData(BufferBinding readTarget,
4963 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04004964 GLintptr readOffset,
4965 GLintptr writeOffset,
4966 GLsizeiptr size)
4967{
4968 // if size is zero, the copy is a successful no-op
4969 if (size == 0)
4970 {
4971 return;
4972 }
4973
4974 // TODO(jmadill): cache these.
4975 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4976 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4977
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004978 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004979}
4980
Jamie Madill01a80ee2016-11-07 12:06:18 -05004981void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4982{
4983 Program *programObject = getProgram(program);
4984 // TODO(jmadill): Re-use this from the validation if possible.
4985 ASSERT(programObject);
4986 programObject->bindAttributeLocation(index, name);
4987}
4988
Corentin Wallez336129f2017-10-17 15:55:40 -04004989void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004990{
Corentin Wallez336129f2017-10-17 15:55:40 -04004991 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4992 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madilld84b6732018-09-06 15:54:35 -04004993 mStateCache.onBufferBindingChange(this);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004994}
4995
Corentin Wallez336129f2017-10-17 15:55:40 -04004996void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08004997{
4998 bindBufferRange(target, index, buffer, 0, 0);
4999}
5000
Corentin Wallez336129f2017-10-17 15:55:40 -04005001void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08005002 GLuint index,
5003 GLuint buffer,
5004 GLintptr offset,
5005 GLsizeiptr size)
5006{
Jamie Madill6d32cef2018-08-14 02:34:28 -04005007 Buffer *object = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
5008 mGLState.setIndexedBufferBinding(this, target, index, object, offset, size);
5009 if (target == BufferBinding::Uniform)
5010 {
5011 mUniformBufferObserverBindings[index].bind(object ? object->getImplementation() : nullptr);
Jamie Madilld84b6732018-09-06 15:54:35 -04005012 mStateCache.onUniformBufferStateChange(this);
5013 }
5014 else
5015 {
5016 mStateCache.onBufferBindingChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04005017 }
Jiajia Qin6eafb042016-12-27 17:04:07 +08005018}
5019
Jamie Madill01a80ee2016-11-07 12:06:18 -05005020void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
5021{
5022 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
5023 {
5024 bindReadFramebuffer(framebuffer);
5025 }
5026
5027 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
5028 {
5029 bindDrawFramebuffer(framebuffer);
5030 }
5031}
5032
5033void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
5034{
5035 ASSERT(target == GL_RENDERBUFFER);
5036 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05005037 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04005038 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05005039}
5040
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005041void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08005042 GLsizei samples,
5043 GLenum internalformat,
5044 GLsizei width,
5045 GLsizei height,
5046 GLboolean fixedsamplelocations)
5047{
5048 Extents size(width, height, 1);
5049 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005050 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
5051 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08005052}
5053
Olli Etuaho89664842018-08-24 14:45:36 +03005054void Context::texStorage3DMultisample(TextureType target,
5055 GLsizei samples,
5056 GLenum internalformat,
5057 GLsizei width,
5058 GLsizei height,
5059 GLsizei depth,
5060 GLboolean fixedsamplelocations)
5061{
Olli Etuaho0c5a9e22018-08-27 14:36:23 +03005062 Extents size(width, height, depth);
5063 Texture *texture = getTargetTexture(target);
5064 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
5065 ConvertToBool(fixedsamplelocations)));
Olli Etuaho89664842018-08-24 14:45:36 +03005066}
5067
JiangYizhoubddc46b2016-12-09 09:50:51 +08005068void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
5069{
JiangYizhou5b03f472017-01-09 10:22:53 +08005070 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
5071 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillbc918e72018-03-08 09:47:21 -05005072 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
JiangYizhou5b03f472017-01-09 10:22:53 +08005073 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08005074
5075 switch (pname)
5076 {
5077 case GL_SAMPLE_POSITION:
Geoff Lang13455072018-05-09 11:24:43 -04005078 handleError(framebuffer->getSamplePosition(this, index, val));
JiangYizhoubddc46b2016-12-09 09:50:51 +08005079 break;
5080 default:
5081 UNREACHABLE();
5082 }
5083}
5084
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07005085void Context::getMultisamplefvRobust(GLenum pname,
5086 GLuint index,
5087 GLsizei bufSize,
5088 GLsizei *length,
5089 GLfloat *val)
5090{
5091 UNIMPLEMENTED();
5092}
5093
Jamie Madille8fb6402017-02-14 17:56:40 -05005094void Context::renderbufferStorage(GLenum target,
5095 GLenum internalformat,
5096 GLsizei width,
5097 GLsizei height)
5098{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005099 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
5100 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
5101
Jamie Madille8fb6402017-02-14 17:56:40 -05005102 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04005103 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05005104}
5105
5106void Context::renderbufferStorageMultisample(GLenum target,
5107 GLsizei samples,
5108 GLenum internalformat,
5109 GLsizei width,
5110 GLsizei height)
5111{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005112 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
5113 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05005114
5115 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005116 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04005117 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05005118}
5119
Geoff Lang38f2cfb2017-04-11 15:23:08 -04005120void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
5121{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005122 const Sync *syncObject = getSync(sync);
Jamie Madilla0691b72018-07-25 10:41:22 -04005123 handleError(QuerySynciv(this, syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04005124}
5125
JiangYizhoue18e6392017-02-20 10:32:23 +08005126void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
5127{
5128 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5129 QueryFramebufferParameteriv(framebuffer, pname, params);
5130}
5131
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07005132void Context::getFramebufferParameterivRobust(GLenum target,
5133 GLenum pname,
5134 GLsizei bufSize,
5135 GLsizei *length,
5136 GLint *params)
5137{
5138 UNIMPLEMENTED();
5139}
5140
Jiajia Qin5451d532017-11-16 17:16:34 +08005141void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08005142{
5143 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillb983a4b2018-08-01 11:34:51 -04005144 SetFramebufferParameteri(this, framebuffer, pname, param);
JiangYizhoue18e6392017-02-20 10:32:23 +08005145}
5146
Jamie Madilldec86232018-07-11 09:01:18 -04005147bool Context::getScratchBuffer(size_t requstedSizeBytes,
5148 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05005149{
Jamie Madilldec86232018-07-11 09:01:18 -04005150 return mScratchBuffer.get(requstedSizeBytes, scratchBufferOut);
Jamie Madillb3f26b92017-07-19 15:07:41 -04005151}
5152
Jamie Madilldec86232018-07-11 09:01:18 -04005153bool Context::getZeroFilledBuffer(size_t requstedSizeBytes,
5154 angle::MemoryBuffer **zeroBufferOut) const
Jamie Madillb3f26b92017-07-19 15:07:41 -04005155{
Jamie Madilldec86232018-07-11 09:01:18 -04005156 return mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0);
Jamie Madille14951e2017-03-09 18:55:16 -05005157}
5158
Xinghua Cao10a4d432017-11-28 14:46:26 +08005159Error Context::prepareForDispatch()
5160{
Geoff Langa8cb2872018-03-09 16:09:40 -05005161 ANGLE_TRY(syncState(mComputeDirtyBits, mComputeDirtyObjects));
Xinghua Cao10a4d432017-11-28 14:46:26 +08005162
5163 if (isRobustResourceInitEnabled())
5164 {
5165 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
5166 }
5167
5168 return NoError();
5169}
5170
Xinghua Cao2b396592017-03-29 15:36:04 +08005171void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
5172{
5173 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
5174 {
5175 return;
5176 }
5177
Xinghua Cao10a4d432017-11-28 14:46:26 +08005178 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill71c88b32017-09-14 22:20:29 -04005179 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08005180}
5181
Jiajia Qin5451d532017-11-16 17:16:34 +08005182void Context::dispatchComputeIndirect(GLintptr indirect)
5183{
Qin Jiajia62fcf622017-11-30 16:16:12 +08005184 ANGLE_CONTEXT_TRY(prepareForDispatch());
5185 handleError(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08005186}
5187
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005188void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005189 GLsizei levels,
5190 GLenum internalFormat,
5191 GLsizei width,
5192 GLsizei height)
5193{
5194 Extents size(width, height, 1);
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
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005199void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005200 GLsizei levels,
5201 GLenum internalFormat,
5202 GLsizei width,
5203 GLsizei height,
5204 GLsizei depth)
5205{
5206 Extents size(width, height, depth);
5207 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005208 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005209}
5210
Jiajia Qin5451d532017-11-16 17:16:34 +08005211void Context::memoryBarrier(GLbitfield barriers)
5212{
Xinghua Cao89c422a2017-11-29 18:24:20 +08005213 handleError(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005214}
5215
5216void Context::memoryBarrierByRegion(GLbitfield barriers)
5217{
Xinghua Cao89c422a2017-11-29 18:24:20 +08005218 handleError(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005219}
5220
Jamie Madillc1d770e2017-04-13 17:31:24 -04005221GLenum Context::checkFramebufferStatus(GLenum target)
5222{
5223 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5224 ASSERT(framebuffer);
Jamie Madill427064d2018-04-13 16:20:34 -04005225 return framebuffer->checkStatus(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005226}
5227
5228void Context::compileShader(GLuint shader)
5229{
5230 Shader *shaderObject = GetValidShader(this, shader);
5231 if (!shaderObject)
5232 {
5233 return;
5234 }
5235 shaderObject->compile(this);
5236}
5237
5238void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
5239{
5240 for (int i = 0; i < n; i++)
5241 {
5242 deleteBuffer(buffers[i]);
5243 }
5244}
5245
5246void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
5247{
5248 for (int i = 0; i < n; i++)
5249 {
5250 if (framebuffers[i] != 0)
5251 {
5252 deleteFramebuffer(framebuffers[i]);
5253 }
5254 }
5255}
5256
5257void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
5258{
5259 for (int i = 0; i < n; i++)
5260 {
5261 deleteRenderbuffer(renderbuffers[i]);
5262 }
5263}
5264
5265void Context::deleteTextures(GLsizei n, const GLuint *textures)
5266{
5267 for (int i = 0; i < n; i++)
5268 {
5269 if (textures[i] != 0)
5270 {
5271 deleteTexture(textures[i]);
5272 }
5273 }
5274}
5275
5276void Context::detachShader(GLuint program, GLuint shader)
5277{
5278 Program *programObject = getProgram(program);
5279 ASSERT(programObject);
5280
5281 Shader *shaderObject = getShader(shader);
5282 ASSERT(shaderObject);
5283
5284 programObject->detachShader(this, shaderObject);
5285}
5286
5287void Context::genBuffers(GLsizei n, GLuint *buffers)
5288{
5289 for (int i = 0; i < n; i++)
5290 {
5291 buffers[i] = createBuffer();
5292 }
5293}
5294
5295void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
5296{
5297 for (int i = 0; i < n; i++)
5298 {
5299 framebuffers[i] = createFramebuffer();
5300 }
5301}
5302
5303void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
5304{
5305 for (int i = 0; i < n; i++)
5306 {
5307 renderbuffers[i] = createRenderbuffer();
5308 }
5309}
5310
5311void Context::genTextures(GLsizei n, GLuint *textures)
5312{
5313 for (int i = 0; i < n; i++)
5314 {
5315 textures[i] = createTexture();
5316 }
5317}
5318
5319void Context::getActiveAttrib(GLuint program,
5320 GLuint index,
5321 GLsizei bufsize,
5322 GLsizei *length,
5323 GLint *size,
5324 GLenum *type,
5325 GLchar *name)
5326{
5327 Program *programObject = getProgram(program);
5328 ASSERT(programObject);
5329 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
5330}
5331
5332void Context::getActiveUniform(GLuint program,
5333 GLuint index,
5334 GLsizei bufsize,
5335 GLsizei *length,
5336 GLint *size,
5337 GLenum *type,
5338 GLchar *name)
5339{
5340 Program *programObject = getProgram(program);
5341 ASSERT(programObject);
5342 programObject->getActiveUniform(index, bufsize, length, size, type, name);
5343}
5344
5345void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
5346{
5347 Program *programObject = getProgram(program);
5348 ASSERT(programObject);
5349 programObject->getAttachedShaders(maxcount, count, shaders);
5350}
5351
5352GLint Context::getAttribLocation(GLuint program, const GLchar *name)
5353{
5354 Program *programObject = getProgram(program);
5355 ASSERT(programObject);
5356 return programObject->getAttributeLocation(name);
5357}
5358
5359void Context::getBooleanv(GLenum pname, GLboolean *params)
5360{
5361 GLenum nativeType;
5362 unsigned int numParams = 0;
5363 getQueryParameterInfo(pname, &nativeType, &numParams);
5364
5365 if (nativeType == GL_BOOL)
5366 {
5367 getBooleanvImpl(pname, params);
5368 }
5369 else
5370 {
5371 CastStateValues(this, nativeType, pname, numParams, params);
5372 }
5373}
5374
Brandon Jones59770802018-04-02 13:18:42 -07005375void Context::getBooleanvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLboolean *params)
5376{
5377 getBooleanv(pname, params);
5378}
5379
Jamie Madillc1d770e2017-04-13 17:31:24 -04005380void Context::getFloatv(GLenum pname, GLfloat *params)
5381{
5382 GLenum nativeType;
5383 unsigned int numParams = 0;
5384 getQueryParameterInfo(pname, &nativeType, &numParams);
5385
5386 if (nativeType == GL_FLOAT)
5387 {
5388 getFloatvImpl(pname, params);
5389 }
5390 else
5391 {
5392 CastStateValues(this, nativeType, pname, numParams, params);
5393 }
5394}
5395
Brandon Jones59770802018-04-02 13:18:42 -07005396void Context::getFloatvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLfloat *params)
5397{
5398 getFloatv(pname, params);
5399}
5400
Jamie Madillc1d770e2017-04-13 17:31:24 -04005401void Context::getIntegerv(GLenum pname, GLint *params)
5402{
5403 GLenum nativeType;
5404 unsigned int numParams = 0;
5405 getQueryParameterInfo(pname, &nativeType, &numParams);
5406
5407 if (nativeType == GL_INT)
5408 {
5409 getIntegervImpl(pname, params);
5410 }
5411 else
5412 {
5413 CastStateValues(this, nativeType, pname, numParams, params);
5414 }
5415}
5416
Brandon Jones59770802018-04-02 13:18:42 -07005417void Context::getIntegervRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint *data)
5418{
5419 getIntegerv(pname, data);
5420}
5421
Jamie Madillc1d770e2017-04-13 17:31:24 -04005422void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
5423{
5424 Program *programObject = getProgram(program);
5425 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04005426 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005427}
5428
Brandon Jones59770802018-04-02 13:18:42 -07005429void Context::getProgramivRobust(GLuint program,
5430 GLenum pname,
5431 GLsizei bufSize,
5432 GLsizei *length,
5433 GLint *params)
5434{
5435 getProgramiv(program, pname, params);
5436}
5437
Jiajia Qin5451d532017-11-16 17:16:34 +08005438void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
5439{
5440 UNIMPLEMENTED();
5441}
5442
Jamie Madillbe849e42017-05-02 15:49:00 -04005443void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005444{
5445 Program *programObject = getProgram(program);
5446 ASSERT(programObject);
5447 programObject->getInfoLog(bufsize, length, infolog);
5448}
5449
Jiajia Qin5451d532017-11-16 17:16:34 +08005450void Context::getProgramPipelineInfoLog(GLuint pipeline,
5451 GLsizei bufSize,
5452 GLsizei *length,
5453 GLchar *infoLog)
5454{
5455 UNIMPLEMENTED();
5456}
5457
Jamie Madillc1d770e2017-04-13 17:31:24 -04005458void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
5459{
5460 Shader *shaderObject = getShader(shader);
5461 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08005462 QueryShaderiv(shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005463}
5464
Brandon Jones59770802018-04-02 13:18:42 -07005465void Context::getShaderivRobust(GLuint shader,
5466 GLenum pname,
5467 GLsizei bufSize,
5468 GLsizei *length,
5469 GLint *params)
5470{
5471 getShaderiv(shader, pname, params);
5472}
5473
Jamie Madillc1d770e2017-04-13 17:31:24 -04005474void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
5475{
5476 Shader *shaderObject = getShader(shader);
5477 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08005478 shaderObject->getInfoLog(bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005479}
5480
5481void Context::getShaderPrecisionFormat(GLenum shadertype,
5482 GLenum precisiontype,
5483 GLint *range,
5484 GLint *precision)
5485{
5486 // TODO(jmadill): Compute shaders.
5487
5488 switch (shadertype)
5489 {
5490 case GL_VERTEX_SHADER:
5491 switch (precisiontype)
5492 {
5493 case GL_LOW_FLOAT:
5494 mCaps.vertexLowpFloat.get(range, precision);
5495 break;
5496 case GL_MEDIUM_FLOAT:
5497 mCaps.vertexMediumpFloat.get(range, precision);
5498 break;
5499 case GL_HIGH_FLOAT:
5500 mCaps.vertexHighpFloat.get(range, precision);
5501 break;
5502
5503 case GL_LOW_INT:
5504 mCaps.vertexLowpInt.get(range, precision);
5505 break;
5506 case GL_MEDIUM_INT:
5507 mCaps.vertexMediumpInt.get(range, precision);
5508 break;
5509 case GL_HIGH_INT:
5510 mCaps.vertexHighpInt.get(range, precision);
5511 break;
5512
5513 default:
5514 UNREACHABLE();
5515 return;
5516 }
5517 break;
5518
5519 case GL_FRAGMENT_SHADER:
5520 switch (precisiontype)
5521 {
5522 case GL_LOW_FLOAT:
5523 mCaps.fragmentLowpFloat.get(range, precision);
5524 break;
5525 case GL_MEDIUM_FLOAT:
5526 mCaps.fragmentMediumpFloat.get(range, precision);
5527 break;
5528 case GL_HIGH_FLOAT:
5529 mCaps.fragmentHighpFloat.get(range, precision);
5530 break;
5531
5532 case GL_LOW_INT:
5533 mCaps.fragmentLowpInt.get(range, precision);
5534 break;
5535 case GL_MEDIUM_INT:
5536 mCaps.fragmentMediumpInt.get(range, precision);
5537 break;
5538 case GL_HIGH_INT:
5539 mCaps.fragmentHighpInt.get(range, precision);
5540 break;
5541
5542 default:
5543 UNREACHABLE();
5544 return;
5545 }
5546 break;
5547
5548 default:
5549 UNREACHABLE();
5550 return;
5551 }
5552}
5553
5554void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
5555{
5556 Shader *shaderObject = getShader(shader);
5557 ASSERT(shaderObject);
5558 shaderObject->getSource(bufsize, length, source);
5559}
5560
5561void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
5562{
5563 Program *programObject = getProgram(program);
5564 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005565 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005566}
5567
Brandon Jones59770802018-04-02 13:18:42 -07005568void Context::getUniformfvRobust(GLuint program,
5569 GLint location,
5570 GLsizei bufSize,
5571 GLsizei *length,
5572 GLfloat *params)
5573{
5574 getUniformfv(program, location, params);
5575}
5576
Jamie Madillc1d770e2017-04-13 17:31:24 -04005577void Context::getUniformiv(GLuint program, GLint location, GLint *params)
5578{
5579 Program *programObject = getProgram(program);
5580 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005581 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005582}
5583
Brandon Jones59770802018-04-02 13:18:42 -07005584void Context::getUniformivRobust(GLuint program,
5585 GLint location,
5586 GLsizei bufSize,
5587 GLsizei *length,
5588 GLint *params)
5589{
5590 getUniformiv(program, location, params);
5591}
5592
Jamie Madillc1d770e2017-04-13 17:31:24 -04005593GLint Context::getUniformLocation(GLuint program, const GLchar *name)
5594{
5595 Program *programObject = getProgram(program);
5596 ASSERT(programObject);
5597 return programObject->getUniformLocation(name);
5598}
5599
5600GLboolean Context::isBuffer(GLuint buffer)
5601{
5602 if (buffer == 0)
5603 {
5604 return GL_FALSE;
5605 }
5606
5607 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
5608}
5609
5610GLboolean Context::isEnabled(GLenum cap)
5611{
5612 return mGLState.getEnableFeature(cap);
5613}
5614
5615GLboolean Context::isFramebuffer(GLuint framebuffer)
5616{
5617 if (framebuffer == 0)
5618 {
5619 return GL_FALSE;
5620 }
5621
5622 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
5623}
5624
5625GLboolean Context::isProgram(GLuint program)
5626{
5627 if (program == 0)
5628 {
5629 return GL_FALSE;
5630 }
5631
5632 return (getProgram(program) ? GL_TRUE : GL_FALSE);
5633}
5634
5635GLboolean Context::isRenderbuffer(GLuint renderbuffer)
5636{
5637 if (renderbuffer == 0)
5638 {
5639 return GL_FALSE;
5640 }
5641
5642 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
5643}
5644
5645GLboolean Context::isShader(GLuint shader)
5646{
5647 if (shader == 0)
5648 {
5649 return GL_FALSE;
5650 }
5651
5652 return (getShader(shader) ? GL_TRUE : GL_FALSE);
5653}
5654
5655GLboolean Context::isTexture(GLuint texture)
5656{
5657 if (texture == 0)
5658 {
5659 return GL_FALSE;
5660 }
5661
5662 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
5663}
5664
5665void Context::linkProgram(GLuint program)
5666{
5667 Program *programObject = getProgram(program);
5668 ASSERT(programObject);
5669 handleError(programObject->link(this));
jchen107ae70d82018-07-06 13:47:01 +08005670
5671 // Don't parallel link a program which is active in any GL contexts. With this assumption, we
5672 // don't need to worry that:
5673 // 1. Draw calls after link use the new executable code or the old one depending on the link
5674 // result.
5675 // 2. When a backend program, e.g., ProgramD3D is linking, other backend classes like
5676 // StateManager11, Renderer11, etc., may have a chance to make unexpected calls to
5677 // ProgramD3D.
5678 if (programObject->isInUse())
5679 {
5680 // isLinked() which forces to resolve linking, will be called.
5681 mGLState.onProgramExecutableChange(programObject);
5682 mStateCache.onProgramExecutableChange(this);
5683 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005684}
5685
5686void Context::releaseShaderCompiler()
5687{
Jamie Madill4928b7c2017-06-20 12:57:39 -04005688 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005689}
5690
5691void Context::shaderBinary(GLsizei n,
5692 const GLuint *shaders,
5693 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04005694 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005695 GLsizei length)
5696{
5697 // No binary shader formats are supported.
5698 UNIMPLEMENTED();
5699}
5700
5701void Context::shaderSource(GLuint shader,
5702 GLsizei count,
5703 const GLchar *const *string,
5704 const GLint *length)
5705{
5706 Shader *shaderObject = getShader(shader);
5707 ASSERT(shaderObject);
5708 shaderObject->setSource(count, string, length);
5709}
5710
5711void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
5712{
5713 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
5714}
5715
5716void Context::stencilMask(GLuint mask)
5717{
5718 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
5719}
5720
5721void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
5722{
5723 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
5724}
5725
5726void Context::uniform1f(GLint location, GLfloat x)
5727{
5728 Program *program = mGLState.getProgram();
5729 program->setUniform1fv(location, 1, &x);
5730}
5731
5732void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
5733{
5734 Program *program = mGLState.getProgram();
5735 program->setUniform1fv(location, count, v);
5736}
5737
Jamie Madill7e4eff12018-08-08 15:49:26 -04005738void Context::setUniform1iImpl(Program *program, GLint location, GLsizei count, const GLint *v)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005739{
Jamie Madill7e4eff12018-08-08 15:49:26 -04005740 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
Jamie Madill81c2e252017-09-09 23:32:46 -04005741 {
5742 mGLState.setObjectDirty(GL_PROGRAM);
Jamie Madilld84b6732018-09-06 15:54:35 -04005743 mStateCache.onActiveTextureChange(this);
Jamie Madill81c2e252017-09-09 23:32:46 -04005744 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005745}
5746
Jamie Madill7e4eff12018-08-08 15:49:26 -04005747void Context::uniform1i(GLint location, GLint x)
5748{
5749 setUniform1iImpl(mGLState.getProgram(), location, 1, &x);
5750}
5751
Jamie Madillc1d770e2017-04-13 17:31:24 -04005752void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
5753{
Jamie Madill7e4eff12018-08-08 15:49:26 -04005754 setUniform1iImpl(mGLState.getProgram(), location, count, v);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005755}
5756
5757void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
5758{
5759 GLfloat xy[2] = {x, y};
5760 Program *program = mGLState.getProgram();
5761 program->setUniform2fv(location, 1, xy);
5762}
5763
5764void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
5765{
5766 Program *program = mGLState.getProgram();
5767 program->setUniform2fv(location, count, v);
5768}
5769
5770void Context::uniform2i(GLint location, GLint x, GLint y)
5771{
5772 GLint xy[2] = {x, y};
5773 Program *program = mGLState.getProgram();
5774 program->setUniform2iv(location, 1, xy);
5775}
5776
5777void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
5778{
5779 Program *program = mGLState.getProgram();
5780 program->setUniform2iv(location, count, v);
5781}
5782
5783void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
5784{
5785 GLfloat xyz[3] = {x, y, z};
5786 Program *program = mGLState.getProgram();
5787 program->setUniform3fv(location, 1, xyz);
5788}
5789
5790void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
5791{
5792 Program *program = mGLState.getProgram();
5793 program->setUniform3fv(location, count, v);
5794}
5795
5796void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
5797{
5798 GLint xyz[3] = {x, y, z};
5799 Program *program = mGLState.getProgram();
5800 program->setUniform3iv(location, 1, xyz);
5801}
5802
5803void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
5804{
5805 Program *program = mGLState.getProgram();
5806 program->setUniform3iv(location, count, v);
5807}
5808
5809void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
5810{
5811 GLfloat xyzw[4] = {x, y, z, w};
5812 Program *program = mGLState.getProgram();
5813 program->setUniform4fv(location, 1, xyzw);
5814}
5815
5816void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
5817{
5818 Program *program = mGLState.getProgram();
5819 program->setUniform4fv(location, count, v);
5820}
5821
5822void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
5823{
5824 GLint xyzw[4] = {x, y, z, w};
5825 Program *program = mGLState.getProgram();
5826 program->setUniform4iv(location, 1, xyzw);
5827}
5828
5829void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
5830{
5831 Program *program = mGLState.getProgram();
5832 program->setUniform4iv(location, count, v);
5833}
5834
5835void Context::uniformMatrix2fv(GLint location,
5836 GLsizei count,
5837 GLboolean transpose,
5838 const GLfloat *value)
5839{
5840 Program *program = mGLState.getProgram();
5841 program->setUniformMatrix2fv(location, count, transpose, value);
5842}
5843
5844void Context::uniformMatrix3fv(GLint location,
5845 GLsizei count,
5846 GLboolean transpose,
5847 const GLfloat *value)
5848{
5849 Program *program = mGLState.getProgram();
5850 program->setUniformMatrix3fv(location, count, transpose, value);
5851}
5852
5853void Context::uniformMatrix4fv(GLint location,
5854 GLsizei count,
5855 GLboolean transpose,
5856 const GLfloat *value)
5857{
5858 Program *program = mGLState.getProgram();
5859 program->setUniformMatrix4fv(location, count, transpose, value);
5860}
5861
5862void Context::validateProgram(GLuint program)
5863{
5864 Program *programObject = getProgram(program);
5865 ASSERT(programObject);
5866 programObject->validate(mCaps);
5867}
5868
Jiajia Qin5451d532017-11-16 17:16:34 +08005869void Context::validateProgramPipeline(GLuint pipeline)
5870{
5871 UNIMPLEMENTED();
5872}
5873
Jamie Madilld04908b2017-06-09 14:15:35 -04005874void Context::getProgramBinary(GLuint program,
5875 GLsizei bufSize,
5876 GLsizei *length,
5877 GLenum *binaryFormat,
5878 void *binary)
5879{
5880 Program *programObject = getProgram(program);
5881 ASSERT(programObject != nullptr);
5882
5883 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
5884}
5885
5886void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
5887{
5888 Program *programObject = getProgram(program);
5889 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04005890
Jamie Madilld04908b2017-06-09 14:15:35 -04005891 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
Jamie Madillc43cdad2018-08-08 15:49:25 -04005892 mStateCache.onProgramExecutableChange(this);
Jamie Madill70aeda42018-08-20 12:17:40 -04005893 if (programObject->isInUse())
5894 {
5895 mGLState.setObjectDirty(GL_PROGRAM);
5896 }
Jamie Madilld04908b2017-06-09 14:15:35 -04005897}
5898
Jamie Madillff325f12017-08-26 15:06:05 -04005899void Context::uniform1ui(GLint location, GLuint v0)
5900{
5901 Program *program = mGLState.getProgram();
5902 program->setUniform1uiv(location, 1, &v0);
5903}
5904
5905void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
5906{
5907 Program *program = mGLState.getProgram();
5908 const GLuint xy[] = {v0, v1};
5909 program->setUniform2uiv(location, 1, xy);
5910}
5911
5912void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
5913{
5914 Program *program = mGLState.getProgram();
5915 const GLuint xyz[] = {v0, v1, v2};
5916 program->setUniform3uiv(location, 1, xyz);
5917}
5918
5919void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
5920{
5921 Program *program = mGLState.getProgram();
5922 const GLuint xyzw[] = {v0, v1, v2, v3};
5923 program->setUniform4uiv(location, 1, xyzw);
5924}
5925
5926void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
5927{
5928 Program *program = mGLState.getProgram();
5929 program->setUniform1uiv(location, count, value);
5930}
5931void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
5932{
5933 Program *program = mGLState.getProgram();
5934 program->setUniform2uiv(location, count, value);
5935}
5936
5937void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
5938{
5939 Program *program = mGLState.getProgram();
5940 program->setUniform3uiv(location, count, value);
5941}
5942
5943void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
5944{
5945 Program *program = mGLState.getProgram();
5946 program->setUniform4uiv(location, count, value);
5947}
5948
Jamie Madillf0e04492017-08-26 15:28:42 -04005949void Context::genQueries(GLsizei n, GLuint *ids)
5950{
5951 for (GLsizei i = 0; i < n; i++)
5952 {
5953 GLuint handle = mQueryHandleAllocator.allocate();
5954 mQueryMap.assign(handle, nullptr);
5955 ids[i] = handle;
5956 }
5957}
5958
5959void Context::deleteQueries(GLsizei n, const GLuint *ids)
5960{
5961 for (int i = 0; i < n; i++)
5962 {
5963 GLuint query = ids[i];
5964
5965 Query *queryObject = nullptr;
5966 if (mQueryMap.erase(query, &queryObject))
5967 {
5968 mQueryHandleAllocator.release(query);
5969 if (queryObject)
5970 {
5971 queryObject->release(this);
5972 }
5973 }
5974 }
5975}
5976
5977GLboolean Context::isQuery(GLuint id)
5978{
Corentin Wallezad3ae902018-03-09 13:40:42 -05005979 return (getQuery(id, false, QueryType::InvalidEnum) != nullptr) ? GL_TRUE : GL_FALSE;
Jamie Madillf0e04492017-08-26 15:28:42 -04005980}
5981
Jamie Madillc8c95812017-08-26 18:40:09 -04005982void Context::uniformMatrix2x3fv(GLint location,
5983 GLsizei count,
5984 GLboolean transpose,
5985 const GLfloat *value)
5986{
5987 Program *program = mGLState.getProgram();
5988 program->setUniformMatrix2x3fv(location, count, transpose, value);
5989}
5990
5991void Context::uniformMatrix3x2fv(GLint location,
5992 GLsizei count,
5993 GLboolean transpose,
5994 const GLfloat *value)
5995{
5996 Program *program = mGLState.getProgram();
5997 program->setUniformMatrix3x2fv(location, count, transpose, value);
5998}
5999
6000void Context::uniformMatrix2x4fv(GLint location,
6001 GLsizei count,
6002 GLboolean transpose,
6003 const GLfloat *value)
6004{
6005 Program *program = mGLState.getProgram();
6006 program->setUniformMatrix2x4fv(location, count, transpose, value);
6007}
6008
6009void Context::uniformMatrix4x2fv(GLint location,
6010 GLsizei count,
6011 GLboolean transpose,
6012 const GLfloat *value)
6013{
6014 Program *program = mGLState.getProgram();
6015 program->setUniformMatrix4x2fv(location, count, transpose, value);
6016}
6017
6018void Context::uniformMatrix3x4fv(GLint location,
6019 GLsizei count,
6020 GLboolean transpose,
6021 const GLfloat *value)
6022{
6023 Program *program = mGLState.getProgram();
6024 program->setUniformMatrix3x4fv(location, count, transpose, value);
6025}
6026
6027void Context::uniformMatrix4x3fv(GLint location,
6028 GLsizei count,
6029 GLboolean transpose,
6030 const GLfloat *value)
6031{
6032 Program *program = mGLState.getProgram();
6033 program->setUniformMatrix4x3fv(location, count, transpose, value);
6034}
6035
Jamie Madilld7576732017-08-26 18:49:50 -04006036void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
6037{
6038 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
6039 {
6040 GLuint vertexArray = arrays[arrayIndex];
6041
6042 if (arrays[arrayIndex] != 0)
6043 {
6044 VertexArray *vertexArrayObject = nullptr;
6045 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
6046 {
6047 if (vertexArrayObject != nullptr)
6048 {
6049 detachVertexArray(vertexArray);
6050 vertexArrayObject->onDestroy(this);
6051 }
6052
6053 mVertexArrayHandleAllocator.release(vertexArray);
6054 }
6055 }
6056 }
6057}
6058
6059void Context::genVertexArrays(GLsizei n, GLuint *arrays)
6060{
6061 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
6062 {
6063 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
6064 mVertexArrayMap.assign(vertexArray, nullptr);
6065 arrays[arrayIndex] = vertexArray;
6066 }
6067}
6068
6069bool Context::isVertexArray(GLuint array)
6070{
6071 if (array == 0)
6072 {
6073 return GL_FALSE;
6074 }
6075
6076 VertexArray *vao = getVertexArray(array);
6077 return (vao != nullptr ? GL_TRUE : GL_FALSE);
6078}
6079
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006080void Context::endTransformFeedback()
6081{
6082 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6083 transformFeedback->end(this);
Jamie Madilld84b6732018-09-06 15:54:35 -04006084 mStateCache.onTransformFeedbackChange(this);
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04006085}
6086
6087void Context::transformFeedbackVaryings(GLuint program,
6088 GLsizei count,
6089 const GLchar *const *varyings,
6090 GLenum bufferMode)
6091{
6092 Program *programObject = getProgram(program);
6093 ASSERT(programObject);
6094 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
6095}
6096
6097void Context::getTransformFeedbackVarying(GLuint program,
6098 GLuint index,
6099 GLsizei bufSize,
6100 GLsizei *length,
6101 GLsizei *size,
6102 GLenum *type,
6103 GLchar *name)
6104{
6105 Program *programObject = getProgram(program);
6106 ASSERT(programObject);
6107 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
6108}
6109
6110void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
6111{
6112 for (int i = 0; i < n; i++)
6113 {
6114 GLuint transformFeedback = ids[i];
6115 if (transformFeedback == 0)
6116 {
6117 continue;
6118 }
6119
6120 TransformFeedback *transformFeedbackObject = nullptr;
6121 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
6122 {
6123 if (transformFeedbackObject != nullptr)
6124 {
6125 detachTransformFeedback(transformFeedback);
6126 transformFeedbackObject->release(this);
6127 }
6128
6129 mTransformFeedbackHandleAllocator.release(transformFeedback);
6130 }
6131 }
6132}
6133
6134void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
6135{
6136 for (int i = 0; i < n; i++)
6137 {
6138 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
6139 mTransformFeedbackMap.assign(transformFeedback, nullptr);
6140 ids[i] = transformFeedback;
6141 }
6142}
6143
6144bool Context::isTransformFeedback(GLuint id)
6145{
6146 if (id == 0)
6147 {
6148 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
6149 // returns FALSE
6150 return GL_FALSE;
6151 }
6152
6153 const TransformFeedback *transformFeedback = getTransformFeedback(id);
6154 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
6155}
6156
6157void Context::pauseTransformFeedback()
6158{
6159 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6160 transformFeedback->pause();
6161}
6162
6163void Context::resumeTransformFeedback()
6164{
6165 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6166 transformFeedback->resume();
6167}
6168
Jamie Madill12e957f2017-08-26 21:42:26 -04006169void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
6170{
6171 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04006172 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04006173}
6174
Brandon Jones59770802018-04-02 13:18:42 -07006175void Context::getUniformuivRobust(GLuint program,
6176 GLint location,
6177 GLsizei bufSize,
6178 GLsizei *length,
6179 GLuint *params)
6180{
6181 getUniformuiv(program, location, params);
6182}
6183
Jamie Madill12e957f2017-08-26 21:42:26 -04006184GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
6185{
6186 const Program *programObject = getProgram(program);
6187 return programObject->getFragDataLocation(name);
6188}
6189
6190void Context::getUniformIndices(GLuint program,
6191 GLsizei uniformCount,
6192 const GLchar *const *uniformNames,
6193 GLuint *uniformIndices)
6194{
6195 const Program *programObject = getProgram(program);
6196 if (!programObject->isLinked())
6197 {
6198 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6199 {
6200 uniformIndices[uniformId] = GL_INVALID_INDEX;
6201 }
6202 }
6203 else
6204 {
6205 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6206 {
6207 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
6208 }
6209 }
6210}
6211
6212void Context::getActiveUniformsiv(GLuint program,
6213 GLsizei uniformCount,
6214 const GLuint *uniformIndices,
6215 GLenum pname,
6216 GLint *params)
6217{
6218 const Program *programObject = getProgram(program);
6219 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6220 {
6221 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08006222 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04006223 }
6224}
6225
6226GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
6227{
6228 const Program *programObject = getProgram(program);
6229 return programObject->getUniformBlockIndex(uniformBlockName);
6230}
6231
6232void Context::getActiveUniformBlockiv(GLuint program,
6233 GLuint uniformBlockIndex,
6234 GLenum pname,
6235 GLint *params)
6236{
6237 const Program *programObject = getProgram(program);
6238 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
6239}
6240
Brandon Jones59770802018-04-02 13:18:42 -07006241void Context::getActiveUniformBlockivRobust(GLuint program,
6242 GLuint uniformBlockIndex,
6243 GLenum pname,
6244 GLsizei bufSize,
6245 GLsizei *length,
6246 GLint *params)
6247{
6248 getActiveUniformBlockiv(program, uniformBlockIndex, pname, params);
6249}
6250
Jamie Madill12e957f2017-08-26 21:42:26 -04006251void Context::getActiveUniformBlockName(GLuint program,
6252 GLuint uniformBlockIndex,
6253 GLsizei bufSize,
6254 GLsizei *length,
6255 GLchar *uniformBlockName)
6256{
6257 const Program *programObject = getProgram(program);
6258 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
6259}
6260
6261void Context::uniformBlockBinding(GLuint program,
6262 GLuint uniformBlockIndex,
6263 GLuint uniformBlockBinding)
6264{
6265 Program *programObject = getProgram(program);
6266 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
Jamie Madill70aeda42018-08-20 12:17:40 -04006267
6268 if (programObject->isInUse())
6269 {
6270 mGLState.setObjectDirty(GL_PROGRAM);
Jamie Madilld84b6732018-09-06 15:54:35 -04006271 mStateCache.onUniformBufferStateChange(this);
Jamie Madill70aeda42018-08-20 12:17:40 -04006272 }
Jamie Madill12e957f2017-08-26 21:42:26 -04006273}
6274
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006275GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
6276{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006277 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
6278 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006279
Jamie Madill70b5bb02017-08-28 13:32:37 -04006280 Sync *syncObject = getSync(syncHandle);
Jamie Madilla0691b72018-07-25 10:41:22 -04006281 Error error = syncObject->set(this, condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006282 if (error.isError())
6283 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04006284 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006285 handleError(error);
6286 return nullptr;
6287 }
6288
Jamie Madill70b5bb02017-08-28 13:32:37 -04006289 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006290}
6291
6292GLboolean Context::isSync(GLsync sync)
6293{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006294 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006295}
6296
6297GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6298{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006299 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006300
6301 GLenum result = GL_WAIT_FAILED;
Jamie Madilla0691b72018-07-25 10:41:22 -04006302 handleError(syncObject->clientWait(this, flags, timeout, &result));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006303 return result;
6304}
6305
6306void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6307{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006308 Sync *syncObject = getSync(sync);
Jamie Madilla0691b72018-07-25 10:41:22 -04006309 handleError(syncObject->serverWait(this, flags, timeout));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006310}
6311
6312void Context::getInteger64v(GLenum pname, GLint64 *params)
6313{
6314 GLenum nativeType = GL_NONE;
6315 unsigned int numParams = 0;
6316 getQueryParameterInfo(pname, &nativeType, &numParams);
6317
6318 if (nativeType == GL_INT_64_ANGLEX)
6319 {
6320 getInteger64vImpl(pname, params);
6321 }
6322 else
6323 {
6324 CastStateValues(this, nativeType, pname, numParams, params);
6325 }
6326}
6327
Brandon Jones59770802018-04-02 13:18:42 -07006328void Context::getInteger64vRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint64 *data)
6329{
6330 getInteger64v(pname, data);
6331}
6332
Corentin Wallez336129f2017-10-17 15:55:40 -04006333void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04006334{
6335 Buffer *buffer = mGLState.getTargetBuffer(target);
6336 QueryBufferParameteri64v(buffer, pname, params);
6337}
6338
Brandon Jones59770802018-04-02 13:18:42 -07006339void Context::getBufferParameteri64vRobust(BufferBinding target,
6340 GLenum pname,
6341 GLsizei bufSize,
6342 GLsizei *length,
6343 GLint64 *params)
6344{
6345 getBufferParameteri64v(target, pname, params);
6346}
6347
Jamie Madill3ef140a2017-08-26 23:11:21 -04006348void Context::genSamplers(GLsizei count, GLuint *samplers)
6349{
6350 for (int i = 0; i < count; i++)
6351 {
6352 samplers[i] = mState.mSamplers->createSampler();
6353 }
6354}
6355
6356void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
6357{
6358 for (int i = 0; i < count; i++)
6359 {
6360 GLuint sampler = samplers[i];
6361
6362 if (mState.mSamplers->getSampler(sampler))
6363 {
6364 detachSampler(sampler);
6365 }
6366
6367 mState.mSamplers->deleteObject(this, sampler);
6368 }
6369}
6370
6371void Context::getInternalformativ(GLenum target,
6372 GLenum internalformat,
6373 GLenum pname,
6374 GLsizei bufSize,
6375 GLint *params)
6376{
6377 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
6378 QueryInternalFormativ(formatCaps, pname, bufSize, params);
6379}
6380
Brandon Jones59770802018-04-02 13:18:42 -07006381void Context::getInternalformativRobust(GLenum target,
6382 GLenum internalformat,
6383 GLenum pname,
6384 GLsizei bufSize,
6385 GLsizei *length,
6386 GLint *params)
6387{
6388 getInternalformativ(target, internalformat, pname, bufSize, params);
6389}
6390
Jiajia Qin5451d532017-11-16 17:16:34 +08006391void Context::programUniform1i(GLuint program, GLint location, GLint v0)
6392{
6393 programUniform1iv(program, location, 1, &v0);
6394}
6395
6396void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
6397{
6398 GLint xy[2] = {v0, v1};
6399 programUniform2iv(program, location, 1, xy);
6400}
6401
6402void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
6403{
6404 GLint xyz[3] = {v0, v1, v2};
6405 programUniform3iv(program, location, 1, xyz);
6406}
6407
6408void Context::programUniform4i(GLuint program,
6409 GLint location,
6410 GLint v0,
6411 GLint v1,
6412 GLint v2,
6413 GLint v3)
6414{
6415 GLint xyzw[4] = {v0, v1, v2, v3};
6416 programUniform4iv(program, location, 1, xyzw);
6417}
6418
6419void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
6420{
6421 programUniform1uiv(program, location, 1, &v0);
6422}
6423
6424void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
6425{
6426 GLuint xy[2] = {v0, v1};
6427 programUniform2uiv(program, location, 1, xy);
6428}
6429
6430void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
6431{
6432 GLuint xyz[3] = {v0, v1, v2};
6433 programUniform3uiv(program, location, 1, xyz);
6434}
6435
6436void Context::programUniform4ui(GLuint program,
6437 GLint location,
6438 GLuint v0,
6439 GLuint v1,
6440 GLuint v2,
6441 GLuint v3)
6442{
6443 GLuint xyzw[4] = {v0, v1, v2, v3};
6444 programUniform4uiv(program, location, 1, xyzw);
6445}
6446
6447void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
6448{
6449 programUniform1fv(program, location, 1, &v0);
6450}
6451
6452void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
6453{
6454 GLfloat xy[2] = {v0, v1};
6455 programUniform2fv(program, location, 1, xy);
6456}
6457
6458void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
6459{
6460 GLfloat xyz[3] = {v0, v1, v2};
6461 programUniform3fv(program, location, 1, xyz);
6462}
6463
6464void Context::programUniform4f(GLuint program,
6465 GLint location,
6466 GLfloat v0,
6467 GLfloat v1,
6468 GLfloat v2,
6469 GLfloat v3)
6470{
6471 GLfloat xyzw[4] = {v0, v1, v2, v3};
6472 programUniform4fv(program, location, 1, xyzw);
6473}
6474
Jamie Madill81c2e252017-09-09 23:32:46 -04006475void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6476{
6477 Program *programObject = getProgram(program);
6478 ASSERT(programObject);
Jamie Madill7e4eff12018-08-08 15:49:26 -04006479 setUniform1iImpl(programObject, location, count, value);
Jamie Madill81c2e252017-09-09 23:32:46 -04006480}
6481
Jiajia Qin5451d532017-11-16 17:16:34 +08006482void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6483{
6484 Program *programObject = getProgram(program);
6485 ASSERT(programObject);
6486 programObject->setUniform2iv(location, count, value);
6487}
6488
6489void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6490{
6491 Program *programObject = getProgram(program);
6492 ASSERT(programObject);
6493 programObject->setUniform3iv(location, count, value);
6494}
6495
6496void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6497{
6498 Program *programObject = getProgram(program);
6499 ASSERT(programObject);
6500 programObject->setUniform4iv(location, count, value);
6501}
6502
6503void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6504{
6505 Program *programObject = getProgram(program);
6506 ASSERT(programObject);
6507 programObject->setUniform1uiv(location, count, value);
6508}
6509
6510void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6511{
6512 Program *programObject = getProgram(program);
6513 ASSERT(programObject);
6514 programObject->setUniform2uiv(location, count, value);
6515}
6516
6517void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6518{
6519 Program *programObject = getProgram(program);
6520 ASSERT(programObject);
6521 programObject->setUniform3uiv(location, count, value);
6522}
6523
6524void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6525{
6526 Program *programObject = getProgram(program);
6527 ASSERT(programObject);
6528 programObject->setUniform4uiv(location, count, value);
6529}
6530
6531void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6532{
6533 Program *programObject = getProgram(program);
6534 ASSERT(programObject);
6535 programObject->setUniform1fv(location, count, value);
6536}
6537
6538void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6539{
6540 Program *programObject = getProgram(program);
6541 ASSERT(programObject);
6542 programObject->setUniform2fv(location, count, value);
6543}
6544
6545void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6546{
6547 Program *programObject = getProgram(program);
6548 ASSERT(programObject);
6549 programObject->setUniform3fv(location, count, value);
6550}
6551
6552void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6553{
6554 Program *programObject = getProgram(program);
6555 ASSERT(programObject);
6556 programObject->setUniform4fv(location, count, value);
6557}
6558
6559void Context::programUniformMatrix2fv(GLuint program,
6560 GLint location,
6561 GLsizei count,
6562 GLboolean transpose,
6563 const GLfloat *value)
6564{
6565 Program *programObject = getProgram(program);
6566 ASSERT(programObject);
6567 programObject->setUniformMatrix2fv(location, count, transpose, value);
6568}
6569
6570void Context::programUniformMatrix3fv(GLuint program,
6571 GLint location,
6572 GLsizei count,
6573 GLboolean transpose,
6574 const GLfloat *value)
6575{
6576 Program *programObject = getProgram(program);
6577 ASSERT(programObject);
6578 programObject->setUniformMatrix3fv(location, count, transpose, value);
6579}
6580
6581void Context::programUniformMatrix4fv(GLuint program,
6582 GLint location,
6583 GLsizei count,
6584 GLboolean transpose,
6585 const GLfloat *value)
6586{
6587 Program *programObject = getProgram(program);
6588 ASSERT(programObject);
6589 programObject->setUniformMatrix4fv(location, count, transpose, value);
6590}
6591
6592void Context::programUniformMatrix2x3fv(GLuint program,
6593 GLint location,
6594 GLsizei count,
6595 GLboolean transpose,
6596 const GLfloat *value)
6597{
6598 Program *programObject = getProgram(program);
6599 ASSERT(programObject);
6600 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
6601}
6602
6603void Context::programUniformMatrix3x2fv(GLuint program,
6604 GLint location,
6605 GLsizei count,
6606 GLboolean transpose,
6607 const GLfloat *value)
6608{
6609 Program *programObject = getProgram(program);
6610 ASSERT(programObject);
6611 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
6612}
6613
6614void Context::programUniformMatrix2x4fv(GLuint program,
6615 GLint location,
6616 GLsizei count,
6617 GLboolean transpose,
6618 const GLfloat *value)
6619{
6620 Program *programObject = getProgram(program);
6621 ASSERT(programObject);
6622 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
6623}
6624
6625void Context::programUniformMatrix4x2fv(GLuint program,
6626 GLint location,
6627 GLsizei count,
6628 GLboolean transpose,
6629 const GLfloat *value)
6630{
6631 Program *programObject = getProgram(program);
6632 ASSERT(programObject);
6633 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
6634}
6635
6636void Context::programUniformMatrix3x4fv(GLuint program,
6637 GLint location,
6638 GLsizei count,
6639 GLboolean transpose,
6640 const GLfloat *value)
6641{
6642 Program *programObject = getProgram(program);
6643 ASSERT(programObject);
6644 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
6645}
6646
6647void Context::programUniformMatrix4x3fv(GLuint program,
6648 GLint location,
6649 GLsizei count,
6650 GLboolean transpose,
6651 const GLfloat *value)
6652{
6653 Program *programObject = getProgram(program);
6654 ASSERT(programObject);
6655 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
6656}
6657
Jamie Madill81c2e252017-09-09 23:32:46 -04006658void Context::onTextureChange(const Texture *texture)
6659{
6660 // Conservatively assume all textures are dirty.
6661 // TODO(jmadill): More fine-grained update.
6662 mGLState.setObjectDirty(GL_TEXTURE);
6663}
6664
James Darpiniane8a93c62018-01-04 18:02:24 -08006665bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
6666{
6667 return mGLState.isCurrentTransformFeedback(tf);
6668}
James Darpiniane8a93c62018-01-04 18:02:24 -08006669
Yunchao Hea336b902017-08-02 16:05:21 +08006670void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
6671{
6672 for (int i = 0; i < count; i++)
6673 {
6674 pipelines[i] = createProgramPipeline();
6675 }
6676}
6677
6678void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
6679{
6680 for (int i = 0; i < count; i++)
6681 {
6682 if (pipelines[i] != 0)
6683 {
6684 deleteProgramPipeline(pipelines[i]);
6685 }
6686 }
6687}
6688
6689GLboolean Context::isProgramPipeline(GLuint pipeline)
6690{
6691 if (pipeline == 0)
6692 {
6693 return GL_FALSE;
6694 }
6695
6696 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
6697}
6698
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006699void Context::finishFenceNV(GLuint fence)
6700{
6701 FenceNV *fenceObject = getFenceNV(fence);
6702
6703 ASSERT(fenceObject && fenceObject->isSet());
Jamie Madilla0691b72018-07-25 10:41:22 -04006704 handleError(fenceObject->finish(this));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006705}
6706
6707void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
6708{
6709 FenceNV *fenceObject = getFenceNV(fence);
6710
6711 ASSERT(fenceObject && fenceObject->isSet());
6712
6713 switch (pname)
6714 {
6715 case GL_FENCE_STATUS_NV:
6716 {
6717 // GL_NV_fence spec:
6718 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
6719 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
6720 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
6721 GLboolean status = GL_TRUE;
6722 if (fenceObject->getStatus() != GL_TRUE)
6723 {
Jamie Madilla0691b72018-07-25 10:41:22 -04006724 ANGLE_CONTEXT_TRY(fenceObject->test(this, &status));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006725 }
6726 *params = status;
6727 break;
6728 }
6729
6730 case GL_FENCE_CONDITION_NV:
6731 {
6732 *params = static_cast<GLint>(fenceObject->getCondition());
6733 break;
6734 }
6735
6736 default:
6737 UNREACHABLE();
6738 }
6739}
6740
6741void Context::getTranslatedShaderSource(GLuint shader,
6742 GLsizei bufsize,
6743 GLsizei *length,
6744 GLchar *source)
6745{
6746 Shader *shaderObject = getShader(shader);
6747 ASSERT(shaderObject);
jchen103fd614d2018-08-13 12:21:58 +08006748 shaderObject->getTranslatedSourceWithDebugInfo(bufsize, length, source);
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006749}
6750
6751void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
6752{
6753 Program *programObject = getProgram(program);
6754 ASSERT(programObject);
6755
6756 programObject->getUniformfv(this, location, params);
6757}
6758
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006759void Context::getnUniformfvRobust(GLuint program,
6760 GLint location,
6761 GLsizei bufSize,
6762 GLsizei *length,
6763 GLfloat *params)
6764{
6765 UNIMPLEMENTED();
6766}
6767
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006768void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
6769{
6770 Program *programObject = getProgram(program);
6771 ASSERT(programObject);
6772
6773 programObject->getUniformiv(this, location, params);
6774}
6775
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006776void Context::getnUniformivRobust(GLuint program,
6777 GLint location,
6778 GLsizei bufSize,
6779 GLsizei *length,
6780 GLint *params)
6781{
6782 UNIMPLEMENTED();
6783}
6784
6785void Context::getnUniformuivRobust(GLuint program,
6786 GLint location,
6787 GLsizei bufSize,
6788 GLsizei *length,
6789 GLuint *params)
6790{
6791 UNIMPLEMENTED();
6792}
6793
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006794GLboolean Context::isFenceNV(GLuint fence)
6795{
6796 FenceNV *fenceObject = getFenceNV(fence);
6797
6798 if (fenceObject == nullptr)
6799 {
6800 return GL_FALSE;
6801 }
6802
6803 // GL_NV_fence spec:
6804 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
6805 // existing fence.
6806 return fenceObject->isSet();
6807}
6808
6809void Context::readnPixels(GLint x,
6810 GLint y,
6811 GLsizei width,
6812 GLsizei height,
6813 GLenum format,
6814 GLenum type,
6815 GLsizei bufSize,
6816 void *data)
6817{
6818 return readPixels(x, y, width, height, format, type, data);
6819}
6820
Jamie Madill007530e2017-12-28 14:27:04 -05006821void Context::setFenceNV(GLuint fence, GLenum condition)
6822{
6823 ASSERT(condition == GL_ALL_COMPLETED_NV);
6824
6825 FenceNV *fenceObject = getFenceNV(fence);
6826 ASSERT(fenceObject != nullptr);
Jamie Madilla0691b72018-07-25 10:41:22 -04006827 handleError(fenceObject->set(this, condition));
Jamie Madill007530e2017-12-28 14:27:04 -05006828}
6829
6830GLboolean Context::testFenceNV(GLuint fence)
6831{
6832 FenceNV *fenceObject = getFenceNV(fence);
6833
6834 ASSERT(fenceObject != nullptr);
6835 ASSERT(fenceObject->isSet() == GL_TRUE);
6836
6837 GLboolean result = GL_TRUE;
Jamie Madilla0691b72018-07-25 10:41:22 -04006838 Error error = fenceObject->test(this, &result);
Jamie Madill007530e2017-12-28 14:27:04 -05006839 if (error.isError())
6840 {
6841 handleError(error);
6842 return GL_TRUE;
6843 }
6844
6845 return result;
6846}
6847
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006848void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006849{
6850 Texture *texture = getTargetTexture(target);
Rafael Cintron05a449a2018-06-20 18:08:04 -07006851 egl::Image *imageObject = static_cast<egl::Image *>(image);
Corentin Wallez99d492c2018-02-27 15:17:10 -05006852 handleError(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05006853}
6854
Jamie Madillfa920eb2018-01-04 11:45:50 -05006855void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006856{
6857 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Rafael Cintron05a449a2018-06-20 18:08:04 -07006858 egl::Image *imageObject = static_cast<egl::Image *>(image);
Jamie Madill007530e2017-12-28 14:27:04 -05006859 handleError(renderbuffer->setStorageEGLImageTarget(this, imageObject));
6860}
6861
Jamie Madillfa920eb2018-01-04 11:45:50 -05006862void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
6863{
6864 UNIMPLEMENTED();
6865}
6866
Jamie Madill5b772312018-03-08 20:28:32 -05006867bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
6868{
6869 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
6870 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
6871 // to the fact that it is stored internally as a float, and so would require conversion
6872 // if returned from Context::getIntegerv. Since this conversion is already implemented
6873 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
6874 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
6875 // application.
6876 switch (pname)
6877 {
6878 case GL_COMPRESSED_TEXTURE_FORMATS:
6879 {
6880 *type = GL_INT;
6881 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
6882 return true;
6883 }
6884 case GL_SHADER_BINARY_FORMATS:
6885 {
6886 *type = GL_INT;
6887 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
6888 return true;
6889 }
6890
6891 case GL_MAX_VERTEX_ATTRIBS:
6892 case GL_MAX_VERTEX_UNIFORM_VECTORS:
6893 case GL_MAX_VARYING_VECTORS:
6894 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
6895 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
6896 case GL_MAX_TEXTURE_IMAGE_UNITS:
6897 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
6898 case GL_MAX_RENDERBUFFER_SIZE:
6899 case GL_NUM_SHADER_BINARY_FORMATS:
6900 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
6901 case GL_ARRAY_BUFFER_BINDING:
6902 case GL_FRAMEBUFFER_BINDING:
6903 case GL_RENDERBUFFER_BINDING:
6904 case GL_CURRENT_PROGRAM:
6905 case GL_PACK_ALIGNMENT:
6906 case GL_UNPACK_ALIGNMENT:
6907 case GL_GENERATE_MIPMAP_HINT:
6908 case GL_RED_BITS:
6909 case GL_GREEN_BITS:
6910 case GL_BLUE_BITS:
6911 case GL_ALPHA_BITS:
6912 case GL_DEPTH_BITS:
6913 case GL_STENCIL_BITS:
6914 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
6915 case GL_CULL_FACE_MODE:
6916 case GL_FRONT_FACE:
6917 case GL_ACTIVE_TEXTURE:
6918 case GL_STENCIL_FUNC:
6919 case GL_STENCIL_VALUE_MASK:
6920 case GL_STENCIL_REF:
6921 case GL_STENCIL_FAIL:
6922 case GL_STENCIL_PASS_DEPTH_FAIL:
6923 case GL_STENCIL_PASS_DEPTH_PASS:
6924 case GL_STENCIL_BACK_FUNC:
6925 case GL_STENCIL_BACK_VALUE_MASK:
6926 case GL_STENCIL_BACK_REF:
6927 case GL_STENCIL_BACK_FAIL:
6928 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
6929 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
6930 case GL_DEPTH_FUNC:
6931 case GL_BLEND_SRC_RGB:
6932 case GL_BLEND_SRC_ALPHA:
6933 case GL_BLEND_DST_RGB:
6934 case GL_BLEND_DST_ALPHA:
6935 case GL_BLEND_EQUATION_RGB:
6936 case GL_BLEND_EQUATION_ALPHA:
6937 case GL_STENCIL_WRITEMASK:
6938 case GL_STENCIL_BACK_WRITEMASK:
6939 case GL_STENCIL_CLEAR_VALUE:
6940 case GL_SUBPIXEL_BITS:
6941 case GL_MAX_TEXTURE_SIZE:
6942 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
6943 case GL_SAMPLE_BUFFERS:
6944 case GL_SAMPLES:
6945 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
6946 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
6947 case GL_TEXTURE_BINDING_2D:
6948 case GL_TEXTURE_BINDING_CUBE_MAP:
6949 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
6950 {
6951 *type = GL_INT;
6952 *numParams = 1;
6953 return true;
6954 }
6955 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6956 {
6957 if (!getExtensions().packReverseRowOrder)
6958 {
6959 return false;
6960 }
6961 *type = GL_INT;
6962 *numParams = 1;
6963 return true;
6964 }
6965 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
6966 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
6967 {
6968 if (!getExtensions().textureRectangle)
6969 {
6970 return false;
6971 }
6972 *type = GL_INT;
6973 *numParams = 1;
6974 return true;
6975 }
6976 case GL_MAX_DRAW_BUFFERS_EXT:
6977 case GL_MAX_COLOR_ATTACHMENTS_EXT:
6978 {
6979 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
6980 {
6981 return false;
6982 }
6983 *type = GL_INT;
6984 *numParams = 1;
6985 return true;
6986 }
6987 case GL_MAX_VIEWPORT_DIMS:
6988 {
6989 *type = GL_INT;
6990 *numParams = 2;
6991 return true;
6992 }
6993 case GL_VIEWPORT:
6994 case GL_SCISSOR_BOX:
6995 {
6996 *type = GL_INT;
6997 *numParams = 4;
6998 return true;
6999 }
7000 case GL_SHADER_COMPILER:
7001 case GL_SAMPLE_COVERAGE_INVERT:
7002 case GL_DEPTH_WRITEMASK:
7003 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
7004 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
7005 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
7006 // bool-natural
7007 case GL_SAMPLE_COVERAGE:
7008 case GL_SCISSOR_TEST:
7009 case GL_STENCIL_TEST:
7010 case GL_DEPTH_TEST:
7011 case GL_BLEND:
7012 case GL_DITHER:
7013 case GL_CONTEXT_ROBUST_ACCESS_EXT:
7014 {
7015 *type = GL_BOOL;
7016 *numParams = 1;
7017 return true;
7018 }
7019 case GL_COLOR_WRITEMASK:
7020 {
7021 *type = GL_BOOL;
7022 *numParams = 4;
7023 return true;
7024 }
7025 case GL_POLYGON_OFFSET_FACTOR:
7026 case GL_POLYGON_OFFSET_UNITS:
7027 case GL_SAMPLE_COVERAGE_VALUE:
7028 case GL_DEPTH_CLEAR_VALUE:
7029 case GL_LINE_WIDTH:
7030 {
7031 *type = GL_FLOAT;
7032 *numParams = 1;
7033 return true;
7034 }
7035 case GL_ALIASED_LINE_WIDTH_RANGE:
7036 case GL_ALIASED_POINT_SIZE_RANGE:
7037 case GL_DEPTH_RANGE:
7038 {
7039 *type = GL_FLOAT;
7040 *numParams = 2;
7041 return true;
7042 }
7043 case GL_COLOR_CLEAR_VALUE:
7044 case GL_BLEND_COLOR:
7045 {
7046 *type = GL_FLOAT;
7047 *numParams = 4;
7048 return true;
7049 }
7050 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
7051 if (!getExtensions().textureFilterAnisotropic)
7052 {
7053 return false;
7054 }
7055 *type = GL_FLOAT;
7056 *numParams = 1;
7057 return true;
7058 case GL_TIMESTAMP_EXT:
7059 if (!getExtensions().disjointTimerQuery)
7060 {
7061 return false;
7062 }
7063 *type = GL_INT_64_ANGLEX;
7064 *numParams = 1;
7065 return true;
7066 case GL_GPU_DISJOINT_EXT:
7067 if (!getExtensions().disjointTimerQuery)
7068 {
7069 return false;
7070 }
7071 *type = GL_INT;
7072 *numParams = 1;
7073 return true;
7074 case GL_COVERAGE_MODULATION_CHROMIUM:
7075 if (!getExtensions().framebufferMixedSamples)
7076 {
7077 return false;
7078 }
7079 *type = GL_INT;
7080 *numParams = 1;
7081 return true;
7082 case GL_TEXTURE_BINDING_EXTERNAL_OES:
7083 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
7084 {
7085 return false;
7086 }
7087 *type = GL_INT;
7088 *numParams = 1;
7089 return true;
7090 }
7091
7092 if (getExtensions().debug)
7093 {
7094 switch (pname)
7095 {
7096 case GL_DEBUG_LOGGED_MESSAGES:
7097 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
7098 case GL_DEBUG_GROUP_STACK_DEPTH:
7099 case GL_MAX_DEBUG_MESSAGE_LENGTH:
7100 case GL_MAX_DEBUG_LOGGED_MESSAGES:
7101 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
7102 case GL_MAX_LABEL_LENGTH:
7103 *type = GL_INT;
7104 *numParams = 1;
7105 return true;
7106
7107 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
7108 case GL_DEBUG_OUTPUT:
7109 *type = GL_BOOL;
7110 *numParams = 1;
7111 return true;
7112 }
7113 }
7114
7115 if (getExtensions().multisampleCompatibility)
7116 {
7117 switch (pname)
7118 {
7119 case GL_MULTISAMPLE_EXT:
7120 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
7121 *type = GL_BOOL;
7122 *numParams = 1;
7123 return true;
7124 }
7125 }
7126
7127 if (getExtensions().pathRendering)
7128 {
7129 switch (pname)
7130 {
7131 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
7132 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
7133 *type = GL_FLOAT;
7134 *numParams = 16;
7135 return true;
7136 }
7137 }
7138
7139 if (getExtensions().bindGeneratesResource)
7140 {
7141 switch (pname)
7142 {
7143 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
7144 *type = GL_BOOL;
7145 *numParams = 1;
7146 return true;
7147 }
7148 }
7149
7150 if (getExtensions().clientArrays)
7151 {
7152 switch (pname)
7153 {
7154 case GL_CLIENT_ARRAYS_ANGLE:
7155 *type = GL_BOOL;
7156 *numParams = 1;
7157 return true;
7158 }
7159 }
7160
7161 if (getExtensions().sRGBWriteControl)
7162 {
7163 switch (pname)
7164 {
7165 case GL_FRAMEBUFFER_SRGB_EXT:
7166 *type = GL_BOOL;
7167 *numParams = 1;
7168 return true;
7169 }
7170 }
7171
7172 if (getExtensions().robustResourceInitialization &&
7173 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
7174 {
7175 *type = GL_BOOL;
7176 *numParams = 1;
7177 return true;
7178 }
7179
7180 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
7181 {
7182 *type = GL_BOOL;
7183 *numParams = 1;
7184 return true;
7185 }
7186
jchen1082af6202018-06-22 10:59:52 +08007187 if (getExtensions().parallelShaderCompile && pname == GL_MAX_SHADER_COMPILER_THREADS_KHR)
7188 {
7189 *type = GL_INT;
7190 *numParams = 1;
7191 return true;
7192 }
7193
Jamie Madill5b772312018-03-08 20:28:32 -05007194 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
7195 switch (pname)
7196 {
7197 // case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE // equivalent to FRAMEBUFFER_BINDING
7198 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
7199 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
7200 {
7201 return false;
7202 }
7203 *type = GL_INT;
7204 *numParams = 1;
7205 return true;
7206
7207 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
7208 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7209 {
7210 return false;
7211 }
7212 *type = GL_INT;
7213 *numParams = 1;
7214 return true;
7215
7216 case GL_PROGRAM_BINARY_FORMATS_OES:
7217 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7218 {
7219 return false;
7220 }
7221 *type = GL_INT;
7222 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
7223 return true;
7224
7225 case GL_PACK_ROW_LENGTH:
7226 case GL_PACK_SKIP_ROWS:
7227 case GL_PACK_SKIP_PIXELS:
7228 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
7229 {
7230 return false;
7231 }
7232 *type = GL_INT;
7233 *numParams = 1;
7234 return true;
7235 case GL_UNPACK_ROW_LENGTH:
7236 case GL_UNPACK_SKIP_ROWS:
7237 case GL_UNPACK_SKIP_PIXELS:
7238 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
7239 {
7240 return false;
7241 }
7242 *type = GL_INT;
7243 *numParams = 1;
7244 return true;
7245 case GL_VERTEX_ARRAY_BINDING:
7246 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
7247 {
7248 return false;
7249 }
7250 *type = GL_INT;
7251 *numParams = 1;
7252 return true;
7253 case GL_PIXEL_PACK_BUFFER_BINDING:
7254 case GL_PIXEL_UNPACK_BUFFER_BINDING:
7255 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
7256 {
7257 return false;
7258 }
7259 *type = GL_INT;
7260 *numParams = 1;
7261 return true;
7262 case GL_MAX_SAMPLES:
7263 {
7264 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
7265 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
7266 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
7267 {
7268 return false;
7269 }
7270 *type = GL_INT;
7271 *numParams = 1;
7272 return true;
7273
7274 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
7275 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
7276 {
7277 return false;
7278 }
7279 *type = GL_INT;
7280 *numParams = 1;
7281 return true;
7282 }
7283 }
7284
7285 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
7286 {
7287 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
7288 {
7289 return false;
7290 }
7291 *type = GL_INT;
7292 *numParams = 1;
7293 return true;
7294 }
7295
7296 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
7297 {
7298 *type = GL_INT;
7299 *numParams = 1;
7300 return true;
7301 }
7302
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007303 if (getClientVersion() < Version(2, 0))
7304 {
7305 switch (pname)
7306 {
7307 case GL_ALPHA_TEST_FUNC:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007308 case GL_CLIENT_ACTIVE_TEXTURE:
7309 case GL_MATRIX_MODE:
7310 case GL_MAX_TEXTURE_UNITS:
7311 case GL_MAX_MODELVIEW_STACK_DEPTH:
7312 case GL_MAX_PROJECTION_STACK_DEPTH:
7313 case GL_MAX_TEXTURE_STACK_DEPTH:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007314 case GL_MAX_LIGHTS:
Lingfeng Yang060088a2018-05-30 20:40:57 -07007315 case GL_MAX_CLIP_PLANES:
Lingfeng Yangabb09f12018-04-16 10:43:53 -07007316 case GL_VERTEX_ARRAY_STRIDE:
7317 case GL_NORMAL_ARRAY_STRIDE:
7318 case GL_COLOR_ARRAY_STRIDE:
7319 case GL_TEXTURE_COORD_ARRAY_STRIDE:
7320 case GL_VERTEX_ARRAY_SIZE:
7321 case GL_COLOR_ARRAY_SIZE:
7322 case GL_TEXTURE_COORD_ARRAY_SIZE:
7323 case GL_VERTEX_ARRAY_TYPE:
7324 case GL_NORMAL_ARRAY_TYPE:
7325 case GL_COLOR_ARRAY_TYPE:
7326 case GL_TEXTURE_COORD_ARRAY_TYPE:
7327 case GL_VERTEX_ARRAY_BUFFER_BINDING:
7328 case GL_NORMAL_ARRAY_BUFFER_BINDING:
7329 case GL_COLOR_ARRAY_BUFFER_BINDING:
7330 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
7331 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
7332 case GL_POINT_SIZE_ARRAY_TYPE_OES:
7333 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
Lingfeng Yanga0cfa872018-05-30 21:12:17 -07007334 case GL_SHADE_MODEL:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07007335 case GL_MODELVIEW_STACK_DEPTH:
7336 case GL_PROJECTION_STACK_DEPTH:
7337 case GL_TEXTURE_STACK_DEPTH:
7338 case GL_LOGIC_OP_MODE:
7339 case GL_BLEND_SRC:
7340 case GL_BLEND_DST:
7341 case GL_PERSPECTIVE_CORRECTION_HINT:
7342 case GL_POINT_SMOOTH_HINT:
7343 case GL_LINE_SMOOTH_HINT:
7344 case GL_FOG_HINT:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007345 *type = GL_INT;
7346 *numParams = 1;
7347 return true;
7348 case GL_ALPHA_TEST_REF:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007349 case GL_FOG_DENSITY:
7350 case GL_FOG_START:
7351 case GL_FOG_END:
7352 case GL_FOG_MODE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007353 case GL_POINT_SIZE:
7354 case GL_POINT_SIZE_MIN:
7355 case GL_POINT_SIZE_MAX:
7356 case GL_POINT_FADE_THRESHOLD_SIZE:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007357 *type = GL_FLOAT;
7358 *numParams = 1;
7359 return true;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007360 case GL_SMOOTH_POINT_SIZE_RANGE:
Lingfeng Yang6e5bf362018-08-15 09:53:17 -07007361 case GL_SMOOTH_LINE_WIDTH_RANGE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007362 *type = GL_FLOAT;
7363 *numParams = 2;
7364 return true;
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007365 case GL_CURRENT_COLOR:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007366 case GL_CURRENT_TEXTURE_COORDS:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007367 case GL_LIGHT_MODEL_AMBIENT:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007368 case GL_FOG_COLOR:
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007369 *type = GL_FLOAT;
7370 *numParams = 4;
7371 return true;
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007372 case GL_CURRENT_NORMAL:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007373 case GL_POINT_DISTANCE_ATTENUATION:
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007374 *type = GL_FLOAT;
7375 *numParams = 3;
7376 return true;
Lingfeng Yang3a41af62018-04-09 07:28:56 -07007377 case GL_MODELVIEW_MATRIX:
7378 case GL_PROJECTION_MATRIX:
7379 case GL_TEXTURE_MATRIX:
7380 *type = GL_FLOAT;
7381 *numParams = 16;
7382 return true;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007383 case GL_LIGHT_MODEL_TWO_SIDE:
7384 *type = GL_BOOL;
7385 *numParams = 1;
7386 return true;
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007387 }
7388 }
7389
Jamie Madill5b772312018-03-08 20:28:32 -05007390 if (getClientVersion() < Version(3, 0))
7391 {
7392 return false;
7393 }
7394
7395 // Check for ES3.0+ parameter names
7396 switch (pname)
7397 {
7398 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
7399 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
7400 case GL_UNIFORM_BUFFER_BINDING:
7401 case GL_TRANSFORM_FEEDBACK_BINDING:
7402 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7403 case GL_COPY_READ_BUFFER_BINDING:
7404 case GL_COPY_WRITE_BUFFER_BINDING:
7405 case GL_SAMPLER_BINDING:
7406 case GL_READ_BUFFER:
7407 case GL_TEXTURE_BINDING_3D:
7408 case GL_TEXTURE_BINDING_2D_ARRAY:
7409 case GL_MAX_3D_TEXTURE_SIZE:
7410 case GL_MAX_ARRAY_TEXTURE_LAYERS:
7411 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
7412 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
7413 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
7414 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
7415 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
7416 case GL_MAX_VARYING_COMPONENTS:
7417 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
7418 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
7419 case GL_MIN_PROGRAM_TEXEL_OFFSET:
7420 case GL_MAX_PROGRAM_TEXEL_OFFSET:
7421 case GL_NUM_EXTENSIONS:
7422 case GL_MAJOR_VERSION:
7423 case GL_MINOR_VERSION:
7424 case GL_MAX_ELEMENTS_INDICES:
7425 case GL_MAX_ELEMENTS_VERTICES:
7426 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
7427 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
7428 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
7429 case GL_UNPACK_IMAGE_HEIGHT:
7430 case GL_UNPACK_SKIP_IMAGES:
7431 {
7432 *type = GL_INT;
7433 *numParams = 1;
7434 return true;
7435 }
7436
7437 case GL_MAX_ELEMENT_INDEX:
7438 case GL_MAX_UNIFORM_BLOCK_SIZE:
7439 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
7440 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
7441 case GL_MAX_SERVER_WAIT_TIMEOUT:
7442 {
7443 *type = GL_INT_64_ANGLEX;
7444 *numParams = 1;
7445 return true;
7446 }
7447
7448 case GL_TRANSFORM_FEEDBACK_ACTIVE:
7449 case GL_TRANSFORM_FEEDBACK_PAUSED:
7450 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
7451 case GL_RASTERIZER_DISCARD:
7452 {
7453 *type = GL_BOOL;
7454 *numParams = 1;
7455 return true;
7456 }
7457
7458 case GL_MAX_TEXTURE_LOD_BIAS:
7459 {
7460 *type = GL_FLOAT;
7461 *numParams = 1;
7462 return true;
7463 }
7464 }
7465
7466 if (getExtensions().requestExtension)
7467 {
7468 switch (pname)
7469 {
7470 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
7471 *type = GL_INT;
7472 *numParams = 1;
7473 return true;
7474 }
7475 }
7476
7477 if (getClientVersion() < Version(3, 1))
7478 {
7479 return false;
7480 }
7481
7482 switch (pname)
7483 {
7484 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7485 case GL_DRAW_INDIRECT_BUFFER_BINDING:
7486 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
7487 case GL_MAX_FRAMEBUFFER_WIDTH:
7488 case GL_MAX_FRAMEBUFFER_HEIGHT:
7489 case GL_MAX_FRAMEBUFFER_SAMPLES:
7490 case GL_MAX_SAMPLE_MASK_WORDS:
7491 case GL_MAX_COLOR_TEXTURE_SAMPLES:
7492 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
7493 case GL_MAX_INTEGER_SAMPLES:
7494 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
7495 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
7496 case GL_MAX_VERTEX_ATTRIB_STRIDE:
7497 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
7498 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
7499 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
7500 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
7501 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
7502 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
7503 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
7504 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
7505 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
7506 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
7507 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
7508 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
7509 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
7510 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
7511 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
7512 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
7513 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
7514 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
7515 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
7516 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
7517 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
7518 case GL_MAX_UNIFORM_LOCATIONS:
7519 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
7520 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
7521 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
7522 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
7523 case GL_MAX_IMAGE_UNITS:
7524 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
7525 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
7526 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
7527 case GL_SHADER_STORAGE_BUFFER_BINDING:
7528 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
7529 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
Olli Etuahodff32a02018-08-28 14:35:50 +03007530 case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY:
Jamie Madill5b772312018-03-08 20:28:32 -05007531 *type = GL_INT;
7532 *numParams = 1;
7533 return true;
7534 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7535 *type = GL_INT_64_ANGLEX;
7536 *numParams = 1;
7537 return true;
7538 case GL_SAMPLE_MASK:
7539 *type = GL_BOOL;
7540 *numParams = 1;
7541 return true;
7542 }
7543
7544 if (getExtensions().geometryShader)
7545 {
7546 switch (pname)
7547 {
7548 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7549 case GL_LAYER_PROVOKING_VERTEX_EXT:
7550 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7551 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7552 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7553 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7554 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7555 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7556 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7557 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7558 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7559 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7560 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7561 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7562 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7563 *type = GL_INT;
7564 *numParams = 1;
7565 return true;
7566 }
7567 }
7568
7569 return false;
7570}
7571
7572bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7573{
7574 if (getClientVersion() < Version(3, 0))
7575 {
7576 return false;
7577 }
7578
7579 switch (target)
7580 {
7581 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7582 case GL_UNIFORM_BUFFER_BINDING:
7583 {
7584 *type = GL_INT;
7585 *numParams = 1;
7586 return true;
7587 }
7588 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7589 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7590 case GL_UNIFORM_BUFFER_START:
7591 case GL_UNIFORM_BUFFER_SIZE:
7592 {
7593 *type = GL_INT_64_ANGLEX;
7594 *numParams = 1;
7595 return true;
7596 }
7597 }
7598
7599 if (getClientVersion() < Version(3, 1))
7600 {
7601 return false;
7602 }
7603
7604 switch (target)
7605 {
7606 case GL_IMAGE_BINDING_LAYERED:
7607 {
7608 *type = GL_BOOL;
7609 *numParams = 1;
7610 return true;
7611 }
7612 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7613 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7614 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7615 case GL_SHADER_STORAGE_BUFFER_BINDING:
7616 case GL_VERTEX_BINDING_BUFFER:
7617 case GL_VERTEX_BINDING_DIVISOR:
7618 case GL_VERTEX_BINDING_OFFSET:
7619 case GL_VERTEX_BINDING_STRIDE:
7620 case GL_SAMPLE_MASK_VALUE:
7621 case GL_IMAGE_BINDING_NAME:
7622 case GL_IMAGE_BINDING_LEVEL:
7623 case GL_IMAGE_BINDING_LAYER:
7624 case GL_IMAGE_BINDING_ACCESS:
7625 case GL_IMAGE_BINDING_FORMAT:
7626 {
7627 *type = GL_INT;
7628 *numParams = 1;
7629 return true;
7630 }
7631 case GL_ATOMIC_COUNTER_BUFFER_START:
7632 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
7633 case GL_SHADER_STORAGE_BUFFER_START:
7634 case GL_SHADER_STORAGE_BUFFER_SIZE:
7635 {
7636 *type = GL_INT_64_ANGLEX;
7637 *numParams = 1;
7638 return true;
7639 }
7640 }
7641
7642 return false;
7643}
7644
7645Program *Context::getProgram(GLuint handle) const
7646{
7647 return mState.mShaderPrograms->getProgram(handle);
7648}
7649
7650Shader *Context::getShader(GLuint handle) const
7651{
7652 return mState.mShaderPrograms->getShader(handle);
7653}
7654
7655bool Context::isTextureGenerated(GLuint texture) const
7656{
7657 return mState.mTextures->isHandleGenerated(texture);
7658}
7659
Jamie Madill5b772312018-03-08 20:28:32 -05007660bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
7661{
7662 return mState.mRenderbuffers->isHandleGenerated(renderbuffer);
7663}
7664
7665bool Context::isFramebufferGenerated(GLuint framebuffer) const
7666{
7667 return mState.mFramebuffers->isHandleGenerated(framebuffer);
7668}
7669
7670bool Context::isProgramPipelineGenerated(GLuint pipeline) const
7671{
7672 return mState.mPipelines->isHandleGenerated(pipeline);
7673}
7674
7675bool Context::usingDisplayTextureShareGroup() const
7676{
7677 return mDisplayTextureShareGroup;
7678}
7679
7680GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
7681{
7682 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
7683 internalformat == GL_DEPTH_STENCIL
7684 ? GL_DEPTH24_STENCIL8
7685 : internalformat;
7686}
7687
jchen1082af6202018-06-22 10:59:52 +08007688void Context::maxShaderCompilerThreads(GLuint count)
7689{
jchen107ae70d82018-07-06 13:47:01 +08007690 GLuint oldCount = mGLState.getMaxShaderCompilerThreads();
jchen1082af6202018-06-22 10:59:52 +08007691 mGLState.setMaxShaderCompilerThreads(count);
jchen107ae70d82018-07-06 13:47:01 +08007692 // A count of zero specifies a request for no parallel compiling or linking.
7693 if ((oldCount == 0 || count == 0) && (oldCount != 0 || count != 0))
7694 {
7695 mThreadPool = angle::WorkerThreadPool::Create(count > 0);
7696 }
7697 mThreadPool->setMaxThreads(count);
jchen1082af6202018-06-22 10:59:52 +08007698}
7699
Jamie Madill2eb65032018-07-30 10:25:57 -04007700bool Context::isGLES1() const
7701{
7702 return mState.getClientVersion() < Version(2, 0);
7703}
7704
Jamie Madilla11819d2018-07-30 10:26:01 -04007705void Context::onSubjectStateChange(const Context *context,
7706 angle::SubjectIndex index,
7707 angle::SubjectMessage message)
7708{
Jamie Madilla11819d2018-07-30 10:26:01 -04007709 switch (index)
7710 {
7711 case kVertexArraySubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04007712 switch (message)
7713 {
7714 case angle::SubjectMessage::CONTENTS_CHANGED:
7715 mGLState.setObjectDirty(GL_VERTEX_ARRAY);
7716 mStateCache.onVertexArrayBufferContentsChange(this);
7717 break;
7718 case angle::SubjectMessage::RESOURCE_MAPPED:
7719 case angle::SubjectMessage::RESOURCE_UNMAPPED:
7720 case angle::SubjectMessage::BINDING_CHANGED:
7721 mStateCache.onVertexArrayBufferStateChange(this);
7722 break;
7723 default:
7724 break;
7725 }
Jamie Madilla11819d2018-07-30 10:26:01 -04007726 break;
7727
7728 case kReadFramebufferSubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04007729 if (message == angle::SubjectMessage::STORAGE_CHANGED)
7730 {
7731 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
7732 }
Jamie Madilla11819d2018-07-30 10:26:01 -04007733 break;
7734
7735 case kDrawFramebufferSubjectIndex:
Jamie Madilld84b6732018-09-06 15:54:35 -04007736 if (message == angle::SubjectMessage::STORAGE_CHANGED)
7737 {
7738 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
7739 }
7740 mStateCache.onDrawFramebufferChange(this);
Jamie Madilla11819d2018-07-30 10:26:01 -04007741 break;
7742
7743 default:
Jamie Madill6d32cef2018-08-14 02:34:28 -04007744 if (index < kTextureMaxSubjectIndex)
7745 {
7746 mGLState.onActiveTextureStateChange(index);
Jamie Madilld84b6732018-09-06 15:54:35 -04007747 mStateCache.onActiveTextureChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04007748 }
7749 else
7750 {
7751 ASSERT(index < kUniformBufferMaxSubjectIndex);
7752 mGLState.onUniformBufferStateChange(index - kUniformBuffer0SubjectIndex);
Jamie Madilld84b6732018-09-06 15:54:35 -04007753 mStateCache.onUniformBufferStateChange(this);
Jamie Madill6d32cef2018-08-14 02:34:28 -04007754 }
Jamie Madilla11819d2018-07-30 10:26:01 -04007755 break;
7756 }
7757}
7758
Jamie Madill6b873dd2018-07-12 23:56:30 -04007759// ErrorSet implementation.
7760ErrorSet::ErrorSet(Context *context) : mContext(context)
7761{
7762}
7763
7764ErrorSet::~ErrorSet() = default;
7765
Jamie Madill306b6c12018-07-27 08:12:49 -04007766void ErrorSet::handleError(const Error &error) const
Jamie Madill6b873dd2018-07-12 23:56:30 -04007767{
7768 // This internal enum is used to filter internal errors that are already handled.
7769 // TODO(jmadill): Remove this when refactor is done. http://anglebug.com/2491
7770 if (error.getCode() == GL_INTERNAL_ERROR_ANGLEX)
7771 {
7772 return;
7773 }
7774
7775 if (ANGLE_UNLIKELY(error.isError()))
7776 {
7777 GLenum code = error.getCode();
7778 mErrors.insert(code);
7779 if (code == GL_OUT_OF_MEMORY && mContext->getWorkarounds().loseContextOnOutOfMemory)
7780 {
7781 mContext->markContextLost();
7782 }
7783
7784 ASSERT(!error.getMessage().empty());
7785 mContext->getGLState().getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR,
7786 error.getID(), GL_DEBUG_SEVERITY_HIGH,
7787 error.getMessage());
7788 }
7789}
7790
7791bool ErrorSet::empty() const
7792{
7793 return mErrors.empty();
7794}
7795
7796GLenum ErrorSet::popError()
7797{
7798 ASSERT(!empty());
7799 GLenum error = *mErrors.begin();
7800 mErrors.erase(mErrors.begin());
7801 return error;
7802}
Jamie Madilldc358af2018-07-31 11:22:13 -04007803
7804// StateCache implementation.
Jamie Madill16e28fd2018-09-12 11:03:05 -04007805StateCache::StateCache(Context *context)
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04007806 : mCachedHasAnyEnabledClientAttrib(false),
7807 mCachedNonInstancedVertexElementLimit(0),
Jamie Madilld84b6732018-09-06 15:54:35 -04007808 mCachedInstancedVertexElementLimit(0),
7809 mCachedBasicDrawStatesError(kInvalidPointer)
Jamie Madilldc358af2018-07-31 11:22:13 -04007810{
Jamie Madill16e28fd2018-09-12 11:03:05 -04007811 updateValidDrawModes(context);
Jamie Madilldc358af2018-07-31 11:22:13 -04007812}
7813
7814StateCache::~StateCache() = default;
7815
7816void StateCache::updateActiveAttribsMask(Context *context)
7817{
7818 bool isGLES1 = context->isGLES1();
7819 const State &glState = context->getGLState();
7820
7821 if (!isGLES1 && !glState.getProgram())
7822 {
7823 mCachedActiveBufferedAttribsMask = AttributesMask();
7824 mCachedActiveClientAttribsMask = AttributesMask();
Jamie Madill86792f42018-08-30 16:18:34 -04007825 mCachedActiveDefaultAttribsMask = AttributesMask();
Jamie Madilldc358af2018-07-31 11:22:13 -04007826 return;
7827 }
7828
7829 AttributesMask activeAttribs = isGLES1 ? glState.gles1().getVertexArraysAttributeMask()
7830 : glState.getProgram()->getActiveAttribLocationsMask();
7831
7832 const VertexArray *vao = glState.getVertexArray();
7833 ASSERT(vao);
7834
7835 const AttributesMask &clientAttribs = vao->getClientAttribsMask();
7836 const AttributesMask &enabledAttribs = vao->getEnabledAttributesMask();
Jamie Madill0a17e482018-08-31 17:19:11 -04007837 const AttributesMask &activeEnabled = activeAttribs & enabledAttribs;
Jamie Madilldc358af2018-07-31 11:22:13 -04007838
Jamie Madill0a17e482018-08-31 17:19:11 -04007839 mCachedActiveClientAttribsMask = activeEnabled & clientAttribs;
7840 mCachedActiveBufferedAttribsMask = activeEnabled & ~clientAttribs;
Jamie Madill86792f42018-08-30 16:18:34 -04007841 mCachedActiveDefaultAttribsMask = activeAttribs & ~enabledAttribs;
Jamie Madilldc358af2018-07-31 11:22:13 -04007842 mCachedHasAnyEnabledClientAttrib = (clientAttribs & enabledAttribs).any();
7843}
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04007844
7845void StateCache::updateVertexElementLimits(Context *context)
7846{
7847 const VertexArray *vao = context->getGLState().getVertexArray();
7848
7849 mCachedNonInstancedVertexElementLimit = std::numeric_limits<GLint64>::max();
7850 mCachedInstancedVertexElementLimit = std::numeric_limits<GLint64>::max();
7851
7852 // VAO can be null on Context startup. If we make this computation lazier we could ASSERT.
7853 // If there are no buffered attributes then we should not limit the draw call count.
7854 if (!vao || !mCachedActiveBufferedAttribsMask.any())
7855 {
7856 return;
7857 }
7858
7859 const auto &vertexAttribs = vao->getVertexAttributes();
7860 const auto &vertexBindings = vao->getVertexBindings();
7861
7862 for (size_t attributeIndex : mCachedActiveBufferedAttribsMask)
7863 {
7864 const VertexAttribute &attrib = vertexAttribs[attributeIndex];
7865 ASSERT(attrib.enabled);
7866
7867 const VertexBinding &binding = vertexBindings[attrib.bindingIndex];
7868 ASSERT(context->isGLES1() ||
7869 context->getGLState().getProgram()->isAttribLocationActive(attributeIndex));
7870
7871 GLint64 limit = attrib.getCachedElementLimit();
7872 if (binding.getDivisor() > 0)
7873 {
7874 mCachedInstancedVertexElementLimit =
7875 std::min(mCachedInstancedVertexElementLimit, limit);
7876 }
7877 else
7878 {
7879 mCachedNonInstancedVertexElementLimit =
7880 std::min(mCachedNonInstancedVertexElementLimit, limit);
7881 }
7882 }
7883}
Jamie Madillc43cdad2018-08-08 15:49:25 -04007884
Jamie Madilld84b6732018-09-06 15:54:35 -04007885void StateCache::updateBasicDrawStatesError()
7886{
7887 mCachedBasicDrawStatesError = kInvalidPointer;
7888}
7889
7890intptr_t StateCache::getBasicDrawStatesErrorImpl(Context *context) const
7891{
7892 ASSERT(mCachedBasicDrawStatesError == kInvalidPointer);
7893 mCachedBasicDrawStatesError = reinterpret_cast<intptr_t>(ValidateDrawStates(context));
7894 return mCachedBasicDrawStatesError;
7895}
7896
Jamie Madillc43cdad2018-08-08 15:49:25 -04007897void StateCache::onVertexArrayBindingChange(Context *context)
7898{
7899 updateActiveAttribsMask(context);
7900 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04007901 updateBasicDrawStatesError();
Jamie Madillc43cdad2018-08-08 15:49:25 -04007902}
7903
7904void StateCache::onProgramExecutableChange(Context *context)
7905{
7906 updateActiveAttribsMask(context);
7907 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04007908 updateBasicDrawStatesError();
Jamie Madill526a6f62018-09-12 11:03:05 -04007909 updateValidDrawModes(context);
Jamie Madillc43cdad2018-08-08 15:49:25 -04007910}
7911
Jamie Madilld84b6732018-09-06 15:54:35 -04007912void StateCache::onVertexArrayFormatChange(Context *context)
Jamie Madillc43cdad2018-08-08 15:49:25 -04007913{
7914 updateVertexElementLimits(context);
7915}
7916
Jamie Madilld84b6732018-09-06 15:54:35 -04007917void StateCache::onVertexArrayBufferContentsChange(Context *context)
7918{
7919 updateVertexElementLimits(context);
7920 updateBasicDrawStatesError();
7921}
7922
Jamie Madillc43cdad2018-08-08 15:49:25 -04007923void StateCache::onVertexArrayStateChange(Context *context)
7924{
7925 updateActiveAttribsMask(context);
7926 updateVertexElementLimits(context);
Jamie Madilld84b6732018-09-06 15:54:35 -04007927 updateBasicDrawStatesError();
7928}
7929
7930void StateCache::onVertexArrayBufferStateChange(Context *context)
7931{
7932 updateBasicDrawStatesError();
Jamie Madillc43cdad2018-08-08 15:49:25 -04007933}
7934
7935void StateCache::onGLES1ClientStateChange(Context *context)
7936{
7937 updateActiveAttribsMask(context);
7938}
Jamie Madilld84b6732018-09-06 15:54:35 -04007939
7940void StateCache::onDrawFramebufferChange(Context *context)
7941{
7942 updateBasicDrawStatesError();
7943}
7944
7945void StateCache::onContextCapChange(Context *context)
7946{
7947 updateBasicDrawStatesError();
7948}
7949
7950void StateCache::onStencilStateChange(Context *context)
7951{
7952 updateBasicDrawStatesError();
7953}
7954
7955void StateCache::onDefaultVertexAttributeChange(Context *context)
7956{
7957 updateBasicDrawStatesError();
7958}
7959
7960void StateCache::onActiveTextureChange(Context *context)
7961{
7962 updateBasicDrawStatesError();
7963}
7964
7965void StateCache::onQueryChange(Context *context)
7966{
7967 updateBasicDrawStatesError();
7968}
7969
7970void StateCache::onTransformFeedbackChange(Context *context)
7971{
7972 updateBasicDrawStatesError();
7973}
7974
7975void StateCache::onUniformBufferStateChange(Context *context)
7976{
7977 updateBasicDrawStatesError();
7978}
7979
7980void StateCache::onBufferBindingChange(Context *context)
7981{
7982 updateBasicDrawStatesError();
7983}
Jamie Madill526a6f62018-09-12 11:03:05 -04007984
7985void StateCache::updateValidDrawModes(Context *context)
7986{
7987 Program *program = context->getGLState().getProgram();
7988 if (!program || !program->hasLinkedShaderStage(ShaderType::Geometry))
7989 {
7990 mCachedValidDrawModes = {{
7991 true, /* Points */
7992 true, /* Lines */
7993 true, /* LineLoop */
7994 true, /* LineStrip */
7995 true, /* Triangles */
7996 true, /* TriangleStrip */
7997 true, /* TriangleFan */
7998 false, /* LinesAdjacency */
7999 false, /* LineStripAdjacency */
8000 false, /* TrianglesAdjacency */
8001 false, /* TriangleStripAdjacency */
8002 false, /* InvalidEnum */
8003 }};
8004 }
8005 else
8006 {
8007 ASSERT(program && program->hasLinkedShaderStage(ShaderType::Geometry));
8008
8009 PrimitiveMode gsMode = program->getGeometryShaderInputPrimitiveType();
8010
8011 mCachedValidDrawModes = {{
8012 gsMode == PrimitiveMode::Points, /* Points */
8013 gsMode == PrimitiveMode::Lines, /* Lines */
8014 gsMode == PrimitiveMode::Lines, /* LineLoop */
8015 gsMode == PrimitiveMode::Lines, /* LineStrip */
8016 gsMode == PrimitiveMode::Triangles, /* Triangles */
8017 gsMode == PrimitiveMode::Triangles, /* TriangleStrip */
8018 gsMode == PrimitiveMode::Triangles, /* TriangleFan */
8019 gsMode == PrimitiveMode::LinesAdjacency, /* LinesAdjacency */
8020 gsMode == PrimitiveMode::LinesAdjacency, /* LineStripAdjacency */
8021 gsMode == PrimitiveMode::TrianglesAdjacency, /* TrianglesAdjacency */
8022 gsMode == PrimitiveMode::TrianglesAdjacency, /* TriangleStripAdjacency */
8023 false, /* InvalidEnum */
8024 }};
8025 }
8026}
Jamie Madillc29968b2016-01-20 11:17:23 -05008027} // namespace gl