blob: d24178d20a86ca745664d0a9b80308d6995abcf7 [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 Madill231c7f52017-04-26 13:45:37 -040044#include "libANGLE/renderer/ContextImpl.h"
45#include "libANGLE/renderer/EGLImplFactory.h"
Jamie Madill7b62cf92017-11-02 15:20:49 -040046#include "libANGLE/renderer/Format.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040047#include "libANGLE/validationES.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000048
Geoff Langf6db0982015-08-25 13:04:00 -040049namespace
50{
51
Jamie Madillb6664922017-07-25 12:55:04 -040052#define ANGLE_HANDLE_ERR(X) \
53 handleError(X); \
54 return;
55#define ANGLE_CONTEXT_TRY(EXPR) ANGLE_TRY_TEMPLATE(EXPR, ANGLE_HANDLE_ERR);
56
Ian Ewell3ffd78b2016-01-22 16:09:42 -050057template <typename T>
Geoff Lang4ddf5af2016-12-01 14:30:44 -050058std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager,
Sami Väisänend59ca052016-06-21 16:10:00 +030059 GLsizei numPaths,
60 const void *paths,
61 GLuint pathBase)
62{
63 std::vector<gl::Path *> ret;
64 ret.reserve(numPaths);
65
66 const auto *nameArray = static_cast<const T *>(paths);
67
68 for (GLsizei i = 0; i < numPaths; ++i)
69 {
70 const GLuint pathName = nameArray[i] + pathBase;
71
72 ret.push_back(resourceManager.getPath(pathName));
73 }
74
75 return ret;
76}
77
Geoff Lang4ddf5af2016-12-01 14:30:44 -050078std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager,
Sami Väisänend59ca052016-06-21 16:10:00 +030079 GLsizei numPaths,
80 GLenum pathNameType,
81 const void *paths,
82 GLuint pathBase)
83{
84 switch (pathNameType)
85 {
86 case GL_UNSIGNED_BYTE:
87 return GatherPaths<GLubyte>(resourceManager, numPaths, paths, pathBase);
88
89 case GL_BYTE:
90 return GatherPaths<GLbyte>(resourceManager, numPaths, paths, pathBase);
91
92 case GL_UNSIGNED_SHORT:
93 return GatherPaths<GLushort>(resourceManager, numPaths, paths, pathBase);
94
95 case GL_SHORT:
96 return GatherPaths<GLshort>(resourceManager, numPaths, paths, pathBase);
97
98 case GL_UNSIGNED_INT:
99 return GatherPaths<GLuint>(resourceManager, numPaths, paths, pathBase);
100
101 case GL_INT:
102 return GatherPaths<GLint>(resourceManager, numPaths, paths, pathBase);
103 }
104
105 UNREACHABLE();
106 return std::vector<gl::Path *>();
107}
108
109template <typename T>
Jamie Madill5188a272018-07-25 10:53:56 -0400110gl::Error GetQueryObjectParameter(const gl::Context *context,
111 gl::Query *query,
112 GLenum pname,
113 T *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500114{
Geoff Lang2186c382016-10-14 10:54:54 -0400115 ASSERT(query != nullptr);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500116
117 switch (pname)
118 {
119 case GL_QUERY_RESULT_EXT:
Jamie Madill5188a272018-07-25 10:53:56 -0400120 return query->getResult(context, params);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500121 case GL_QUERY_RESULT_AVAILABLE_EXT:
122 {
123 bool available;
Jamie Madill5188a272018-07-25 10:53:56 -0400124 gl::Error error = query->isResultAvailable(context, &available);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500125 if (!error.isError())
126 {
jchen10a99ed552017-09-22 08:10:32 +0800127 *params = gl::CastFromStateValue<T>(pname, static_cast<GLuint>(available));
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500128 }
129 return error;
130 }
131 default:
132 UNREACHABLE();
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500133 return gl::InternalError() << "Unreachable Error";
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500134 }
135}
136
Jamie Madill09463932018-04-04 05:26:59 -0400137void MarkTransformFeedbackBufferUsage(const gl::Context *context,
138 gl::TransformFeedback *transformFeedback,
James Darpinian30b604d2018-03-12 17:26:57 -0700139 GLsizei count,
140 GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -0400141{
Geoff Lang1a683462015-09-29 15:09:59 -0400142 if (transformFeedback && transformFeedback->isActive() && !transformFeedback->isPaused())
Geoff Langf6db0982015-08-25 13:04:00 -0400143 {
Jamie Madill09463932018-04-04 05:26:59 -0400144 transformFeedback->onVerticesDrawn(context, count, instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -0400145 }
146}
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500147
148// Attribute map queries.
Martin Radev1be913c2016-07-11 17:59:16 +0300149EGLint GetClientMajorVersion(const egl::AttributeMap &attribs)
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500150{
Ian Ewellec2c0c52016-04-05 13:46:26 -0400151 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_CLIENT_VERSION, 1));
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500152}
153
Martin Radev1be913c2016-07-11 17:59:16 +0300154EGLint GetClientMinorVersion(const egl::AttributeMap &attribs)
155{
156 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_MINOR_VERSION, 0));
157}
158
Geoff Langeb66a6e2016-10-31 13:06:12 -0400159gl::Version GetClientVersion(const egl::AttributeMap &attribs)
160{
161 return gl::Version(GetClientMajorVersion(attribs), GetClientMinorVersion(attribs));
162}
163
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500164GLenum GetResetStrategy(const egl::AttributeMap &attribs)
165{
Lingfeng Yangb27b03a2018-02-19 13:38:48 -0800166 EGLAttrib attrib =
167 attribs.get(EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT, EGL_NO_RESET_NOTIFICATION);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500168 switch (attrib)
169 {
170 case EGL_NO_RESET_NOTIFICATION:
171 return GL_NO_RESET_NOTIFICATION_EXT;
172 case EGL_LOSE_CONTEXT_ON_RESET:
173 return GL_LOSE_CONTEXT_ON_RESET_EXT;
174 default:
175 UNREACHABLE();
176 return GL_NONE;
177 }
178}
179
180bool GetRobustAccess(const egl::AttributeMap &attribs)
181{
Geoff Lang077f20a2016-11-01 10:08:02 -0400182 return (attribs.get(EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT, EGL_FALSE) == EGL_TRUE) ||
183 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR) !=
184 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500185}
186
187bool GetDebug(const egl::AttributeMap &attribs)
188{
Geoff Lang077f20a2016-11-01 10:08:02 -0400189 return (attribs.get(EGL_CONTEXT_OPENGL_DEBUG, EGL_FALSE) == EGL_TRUE) ||
190 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR) != 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500191}
192
193bool GetNoError(const egl::AttributeMap &attribs)
194{
195 return (attribs.get(EGL_CONTEXT_OPENGL_NO_ERROR_KHR, EGL_FALSE) == EGL_TRUE);
196}
197
Geoff Langc287ea62016-09-16 14:46:51 -0400198bool GetWebGLContext(const egl::AttributeMap &attribs)
199{
200 return (attribs.get(EGL_CONTEXT_WEBGL_COMPATIBILITY_ANGLE, EGL_FALSE) == EGL_TRUE);
201}
202
Geoff Lang0ab41fa2018-03-14 11:03:30 -0400203bool GetExtensionsEnabled(const egl::AttributeMap &attribs, bool webGLContext)
204{
205 // If the context is WebGL, extensions are disabled by default
206 EGLAttrib defaultValue = webGLContext ? EGL_FALSE : EGL_TRUE;
207 return (attribs.get(EGL_EXTENSIONS_ENABLED_ANGLE, defaultValue) == EGL_TRUE);
208}
209
Geoff Langf41a7152016-09-19 15:11:17 -0400210bool GetBindGeneratesResource(const egl::AttributeMap &attribs)
211{
212 return (attribs.get(EGL_CONTEXT_BIND_GENERATES_RESOURCE_CHROMIUM, EGL_TRUE) == EGL_TRUE);
213}
214
Geoff Langfeb8c682017-02-13 16:07:35 -0500215bool GetClientArraysEnabled(const egl::AttributeMap &attribs)
216{
217 return (attribs.get(EGL_CONTEXT_CLIENT_ARRAYS_ENABLED_ANGLE, EGL_TRUE) == EGL_TRUE);
218}
219
Geoff Langb433e872017-10-05 14:01:47 -0400220bool GetRobustResourceInit(const egl::AttributeMap &attribs)
221{
222 return (attribs.get(EGL_ROBUST_RESOURCE_INITIALIZATION_ANGLE, EGL_FALSE) == EGL_TRUE);
223}
224
Martin Radev9d901792016-07-15 15:58:58 +0300225std::string GetObjectLabelFromPointer(GLsizei length, const GLchar *label)
226{
227 std::string labelName;
228 if (label != nullptr)
229 {
230 size_t labelLength = length < 0 ? strlen(label) : length;
231 labelName = std::string(label, labelLength);
232 }
233 return labelName;
234}
235
236void GetObjectLabelBase(const std::string &objectLabel,
237 GLsizei bufSize,
238 GLsizei *length,
239 GLchar *label)
240{
241 size_t writeLength = objectLabel.length();
242 if (label != nullptr && bufSize > 0)
243 {
244 writeLength = std::min(static_cast<size_t>(bufSize) - 1, objectLabel.length());
245 std::copy(objectLabel.begin(), objectLabel.begin() + writeLength, label);
246 label[writeLength] = '\0';
247 }
248
249 if (length != nullptr)
250 {
251 *length = static_cast<GLsizei>(writeLength);
252 }
253}
254
Jamie Madill0f80ed82017-09-19 00:24:56 -0400255template <typename CapT, typename MaxT>
256void LimitCap(CapT *cap, MaxT maximum)
257{
258 *cap = std::min(*cap, static_cast<CapT>(maximum));
259}
260
Tobin Ehlisd7890bc2018-06-29 11:57:22 -0600261constexpr angle::PackedEnumMap<gl::PrimitiveMode, GLsizei> kMinimumPrimitiveCounts = {{
262 /* Points */ 1,
263 /* Lines */ 2,
264 /* LineLoop */ 2,
265 /* LineStrip */ 2,
266 /* Triangles */ 3,
267 /* TriangleStrip */ 3,
268 /* TriangleFan */ 3,
269 /* LinesAdjacency */ 2,
270 /* LineStripAdjacency */ 2,
271 /* TrianglesAdjacency */ 3,
272 /* TriangleStripAdjacency */ 3,
273}};
274// Indices above are code-gen'd so make sure they don't change
275// if any of these static asserts are hit, must update kMinimumPrimitiveCounts abouve
276static_assert(static_cast<gl::PrimitiveMode>(0) == gl::PrimitiveMode::Points,
277 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
278static_assert(static_cast<gl::PrimitiveMode>(1) == gl::PrimitiveMode::Lines,
279 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
280static_assert(static_cast<gl::PrimitiveMode>(2) == gl::PrimitiveMode::LineLoop,
281 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
282static_assert(static_cast<gl::PrimitiveMode>(3) == gl::PrimitiveMode::LineStrip,
283 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
284static_assert(static_cast<gl::PrimitiveMode>(4) == gl::PrimitiveMode::Triangles,
285 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
286static_assert(static_cast<gl::PrimitiveMode>(5) == gl::PrimitiveMode::TriangleStrip,
287 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
288static_assert(static_cast<gl::PrimitiveMode>(6) == gl::PrimitiveMode::TriangleFan,
289 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
290static_assert(static_cast<gl::PrimitiveMode>(7) == gl::PrimitiveMode::LinesAdjacency,
291 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
292static_assert(static_cast<gl::PrimitiveMode>(8) == gl::PrimitiveMode::LineStripAdjacency,
293 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
294static_assert(static_cast<gl::PrimitiveMode>(9) == gl::PrimitiveMode::TrianglesAdjacency,
295 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
296static_assert(static_cast<gl::PrimitiveMode>(10) == gl::PrimitiveMode::TriangleStripAdjacency,
297 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
298static_assert(static_cast<gl::PrimitiveMode>(11) == gl::PrimitiveMode::EnumCount,
299 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
300
Jamie Madilla11819d2018-07-30 10:26:01 -0400301constexpr angle::SubjectIndex kVertexArraySubjectIndex = 0;
302constexpr angle::SubjectIndex kReadFramebufferSubjectIndex = 1;
303constexpr angle::SubjectIndex kDrawFramebufferSubjectIndex = 2;
Geoff Langf6db0982015-08-25 13:04:00 -0400304} // anonymous namespace
305
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000306namespace gl
307{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +0000308
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400309Context::Context(rx::EGLImplFactory *implFactory,
310 const egl::Config *config,
Corentin Wallez51706ea2015-08-07 14:39:22 -0400311 const Context *shareContext,
Geoff Langce02f082017-02-06 16:46:21 -0500312 TextureManager *shareTextures,
Jamie Madill32447362017-06-28 14:53:52 -0400313 MemoryProgramCache *memoryProgramCache,
Corentin Wallezc295e512017-01-27 17:47:50 -0500314 const egl::AttributeMap &attribs,
Brandon Jones2b0cdcc2018-05-02 08:02:50 -0700315 const egl::DisplayExtensions &displayExtensions,
316 const egl::ClientExtensions &clientExtensions)
Jamie Madill5b772312018-03-08 20:28:32 -0500317 : mState(reinterpret_cast<ContextID>(this),
318 shareContext ? &shareContext->mState : nullptr,
319 shareTextures,
320 GetClientVersion(attribs),
321 &mGLState,
322 mCaps,
323 mTextureCaps,
324 mExtensions,
325 mLimitations),
326 mSkipValidation(GetNoError(attribs)),
327 mDisplayTextureShareGroup(shareTextures != nullptr),
328 mSavedArgsType(nullptr),
Geoff Lang3cacf692018-06-20 16:49:57 -0400329 mImplementation(implFactory->createContext(mState, config, shareContext, attribs)),
Geoff Lang75359662018-04-11 01:42:27 -0400330 mLabel(nullptr),
Jamie Madill2f348d22017-06-05 10:50:59 -0400331 mCompiler(),
Geoff Lang4fb8a8b2018-06-01 16:47:57 -0400332 mGLState(GetDebug(attribs),
333 GetBindGeneratesResource(attribs),
334 GetClientArraysEnabled(attribs),
335 GetRobustResourceInit(attribs),
336 memoryProgramCache != nullptr),
Corentin Walleze3b10e82015-05-20 11:06:25 -0400337 mConfig(config),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500338 mClientType(EGL_OPENGL_ES_API),
Jamie Madill6b873dd2018-07-12 23:56:30 -0400339 mErrors(this),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500340 mHasBeenCurrent(false),
341 mContextLost(false),
342 mResetStatus(GL_NO_ERROR),
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700343 mContextLostForced(false),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500344 mResetStrategy(GetResetStrategy(attribs)),
345 mRobustAccess(GetRobustAccess(attribs)),
Geoff Lang33f11fb2018-05-07 13:42:47 -0400346 mSurfacelessSupported(displayExtensions.surfacelessContext),
347 mExplicitContextAvailable(clientExtensions.explicitContext),
Jamie Madill61e16b42017-06-19 11:13:23 -0400348 mCurrentSurface(static_cast<egl::Surface *>(EGL_NO_SURFACE)),
349 mCurrentDisplay(static_cast<egl::Display *>(EGL_NO_DISPLAY)),
Jamie Madille14951e2017-03-09 18:55:16 -0500350 mWebGLContext(GetWebGLContext(attribs)),
Geoff Lang0ab41fa2018-03-14 11:03:30 -0400351 mExtensionsEnabled(GetExtensionsEnabled(attribs, mWebGLContext)),
Jamie Madill32447362017-06-28 14:53:52 -0400352 mMemoryProgramCache(memoryProgramCache),
Jamie Madilla11819d2018-07-30 10:26:01 -0400353 mVertexArrayObserverBinding(this, kVertexArraySubjectIndex),
354 mDrawFramebufferObserverBinding(this, kDrawFramebufferSubjectIndex),
355 mReadFramebufferObserverBinding(this, kReadFramebufferSubjectIndex),
Jamie Madillb3f26b92017-07-19 15:07:41 -0400356 mScratchBuffer(1000u),
357 mZeroFilledBuffer(1000u)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000358{
Jamie Madill5b772312018-03-08 20:28:32 -0500359 // Needed to solve a Clang warning of unused variables.
Jamie Madillc6dbc252018-04-30 19:07:56 -0400360 ANGLE_UNUSED_VARIABLE(mSavedArgsType);
361 ANGLE_UNUSED_VARIABLE(mParamsBuffer);
Geoff Lang33f11fb2018-05-07 13:42:47 -0400362}
Jamie Madill5b772312018-03-08 20:28:32 -0500363
Geoff Lang33f11fb2018-05-07 13:42:47 -0400364void Context::initialize()
365{
366 mImplementation->setMemoryProgramCache(mMemoryProgramCache);
Jamie Madill14bbb3f2017-09-12 15:23:01 -0400367
Geoff Lang33f11fb2018-05-07 13:42:47 -0400368 initCaps();
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700369 initWorkarounds();
Geoff Langc0b9ef42014-07-02 10:02:37 -0400370
Geoff Lang4fb8a8b2018-06-01 16:47:57 -0400371 mGLState.initialize(this);
Régis Fénéon83107972015-02-05 12:57:44 +0100372
Shannon Woods53a94a82014-06-24 15:20:36 -0400373 mFenceNVHandleAllocator.setBaseHandle(0);
Geoff Lang7dca1862013-07-30 16:30:46 -0400374
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000375 // [OpenGL ES 2.0.24] section 3.7 page 83:
Corentin Wallez336129f2017-10-17 15:55:40 -0400376 // In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have two-dimensional
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000377 // and cube map texture state vectors respectively associated with them.
378 // In order that access to these initial textures not be lost, they are treated as texture
379 // objects all of whose names are 0.
380
Corentin Wallez99d492c2018-02-27 15:17:10 -0500381 Texture *zeroTexture2D = new Texture(mImplementation.get(), 0, TextureType::_2D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800382 mZeroTextures[TextureType::_2D].set(this, zeroTexture2D);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500383
Corentin Wallez99d492c2018-02-27 15:17:10 -0500384 Texture *zeroTextureCube = new Texture(mImplementation.get(), 0, TextureType::CubeMap);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800385 mZeroTextures[TextureType::CubeMap].set(this, zeroTextureCube);
Geoff Lang76b10c92014-09-05 16:28:14 -0400386
Geoff Langeb66a6e2016-10-31 13:06:12 -0400387 if (getClientVersion() >= Version(3, 0))
Geoff Lang76b10c92014-09-05 16:28:14 -0400388 {
389 // TODO: These could also be enabled via extension
Corentin Wallez99d492c2018-02-27 15:17:10 -0500390 Texture *zeroTexture3D = new Texture(mImplementation.get(), 0, TextureType::_3D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800391 mZeroTextures[TextureType::_3D].set(this, zeroTexture3D);
Geoff Lang76b10c92014-09-05 16:28:14 -0400392
Corentin Wallez99d492c2018-02-27 15:17:10 -0500393 Texture *zeroTexture2DArray = new Texture(mImplementation.get(), 0, TextureType::_2DArray);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800394 mZeroTextures[TextureType::_2DArray].set(this, zeroTexture2DArray);
Geoff Lang76b10c92014-09-05 16:28:14 -0400395 }
Geoff Lang3b573612016-10-31 14:08:10 -0400396 if (getClientVersion() >= Version(3, 1))
397 {
398 Texture *zeroTexture2DMultisample =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500399 new Texture(mImplementation.get(), 0, TextureType::_2DMultisample);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800400 mZeroTextures[TextureType::_2DMultisample].set(this, zeroTexture2DMultisample);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800401
Jiajia Qin6eafb042016-12-27 17:04:07 +0800402 for (unsigned int i = 0; i < mCaps.maxAtomicCounterBufferBindings; i++)
403 {
Qin Jiajia339f65b2018-02-27 12:52:48 +0800404 bindBufferRange(BufferBinding::AtomicCounter, i, 0, 0, 0);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800405 }
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800406
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800407 for (unsigned int i = 0; i < mCaps.maxShaderStorageBufferBindings; i++)
408 {
Corentin Wallez336129f2017-10-17 15:55:40 -0400409 bindBufferRange(BufferBinding::ShaderStorage, i, 0, 0, 0);
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800410 }
Geoff Lang3b573612016-10-31 14:08:10 -0400411 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000412
Geoff Langb0f917f2017-12-05 13:41:54 -0500413 if (mSupportedExtensions.textureRectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400414 {
415 Texture *zeroTextureRectangle =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500416 new Texture(mImplementation.get(), 0, TextureType::Rectangle);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800417 mZeroTextures[TextureType::Rectangle].set(this, zeroTextureRectangle);
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400418 }
419
Geoff Langb0f917f2017-12-05 13:41:54 -0500420 if (mSupportedExtensions.eglImageExternal || mSupportedExtensions.eglStreamConsumerExternal)
Ian Ewellbda75592016-04-18 17:25:54 -0400421 {
Corentin Wallez99d492c2018-02-27 15:17:10 -0500422 Texture *zeroTextureExternal = new Texture(mImplementation.get(), 0, TextureType::External);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800423 mZeroTextures[TextureType::External].set(this, zeroTextureExternal);
Ian Ewellbda75592016-04-18 17:25:54 -0400424 }
425
Jamie Madill4928b7c2017-06-20 12:57:39 -0400426 mGLState.initializeZeroTextures(this, mZeroTextures);
Jamie Madille6382c32014-11-07 15:05:26 -0500427
Jamie Madill57a89722013-07-02 11:57:03 -0400428 bindVertexArray(0);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000429
Geoff Langeb66a6e2016-10-31 13:06:12 -0400430 if (getClientVersion() >= Version(3, 0))
Geoff Lang1a683462015-09-29 15:09:59 -0400431 {
432 // [OpenGL ES 3.0.2] section 2.14.1 pg 85:
433 // In the initial state, a default transform feedback object is bound and treated as
434 // a transform feedback object with a name of zero. That object is bound any time
435 // BindTransformFeedback is called with id of zero
Jamie Madillf0dcb8b2017-08-26 19:05:13 -0400436 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Geoff Lang1a683462015-09-29 15:09:59 -0400437 }
Geoff Langc8058452014-02-03 12:04:11 -0500438
Corentin Wallez336129f2017-10-17 15:55:40 -0400439 for (auto type : angle::AllEnums<BufferBinding>())
440 {
441 bindBuffer(type, 0);
442 }
443
444 bindRenderbuffer(GL_RENDERBUFFER, 0);
445
446 for (unsigned int i = 0; i < mCaps.maxUniformBufferBindings; i++)
447 {
448 bindBufferRange(BufferBinding::Uniform, i, 0, 0, -1);
449 }
450
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700451 // Initialize GLES1 renderer if appropriate.
452 if (getClientVersion() < Version(2, 0))
453 {
454 mGLES1Renderer.reset(new GLES1Renderer());
455 }
456
Jamie Madillad9f24e2016-02-12 09:27:24 -0500457 // Initialize dirty bit masks
Geoff Lang9bf86f02018-07-26 11:46:34 -0400458 mDrawDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
459 mDrawDirtyObjects.set(State::DIRTY_OBJECT_VERTEX_ARRAY);
460 mDrawDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM_TEXTURES);
461
462 mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
463 mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_VERTEX_ARRAY);
464 mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM_TEXTURES);
465
Jamie Madillc67323a2017-11-02 23:11:41 -0400466 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500467 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500468 // No dirty objects.
469
470 // Readpixels uses the pack state and read FBO
Jamie Madillc67323a2017-11-02 23:11:41 -0400471 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500472 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_BUFFER_BINDING);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400473 mReadPixelsDirtyBits.set(State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500474 mReadPixelsDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
475
476 mClearDirtyBits.set(State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED);
477 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
478 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR);
479 mClearDirtyBits.set(State::DIRTY_BIT_VIEWPORT);
480 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_COLOR);
481 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_DEPTH);
482 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_STENCIL);
483 mClearDirtyBits.set(State::DIRTY_BIT_COLOR_MASK);
484 mClearDirtyBits.set(State::DIRTY_BIT_DEPTH_MASK);
485 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT);
486 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_BACK);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400487 mClearDirtyBits.set(State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500488 mClearDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
489
490 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
491 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR);
Geoff Lang1d2c41d2016-10-19 16:14:46 -0700492 mBlitDirtyBits.set(State::DIRTY_BIT_FRAMEBUFFER_SRGB);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400493 mBlitDirtyBits.set(State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
494 mBlitDirtyBits.set(State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500495 mBlitDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
496 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
Jamie Madill437fa652016-05-03 15:13:24 -0400497
Xinghua Cao10a4d432017-11-28 14:46:26 +0800498 // TODO(xinghua.cao@intel.com): add other dirty bits and dirty objects.
499 mComputeDirtyBits.set(State::DIRTY_BIT_SHADER_STORAGE_BUFFER_BINDING);
500 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_BINDING);
501 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_EXECUTABLE);
502 mComputeDirtyBits.set(State::DIRTY_BIT_TEXTURE_BINDINGS);
503 mComputeDirtyBits.set(State::DIRTY_BIT_SAMPLER_BINDINGS);
Qin Jiajia62fcf622017-11-30 16:16:12 +0800504 mComputeDirtyBits.set(State::DIRTY_BIT_DISPATCH_INDIRECT_BUFFER_BINDING);
Jiajia Qin5ae6ee42018-03-06 17:39:42 +0800505 mComputeDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM_TEXTURES);
Xinghua Cao10a4d432017-11-28 14:46:26 +0800506
Jamie Madillb4927eb2018-07-16 11:39:46 -0400507 mImplementation->setErrorSet(&mErrors);
508
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400509 handleError(mImplementation->initialize());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000510}
511
Jamie Madill4928b7c2017-06-20 12:57:39 -0400512egl::Error Context::onDestroy(const egl::Display *display)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000513{
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700514 if (mGLES1Renderer)
515 {
516 mGLES1Renderer->onDestroy(this, &mGLState);
517 }
518
Jamie Madille7b3fe22018-04-05 09:42:46 -0400519 // Delete the Surface first to trigger a finish() in Vulkan.
Jamie Madille7b3fe22018-04-05 09:42:46 -0400520 ANGLE_TRY(releaseSurface(display));
521
Corentin Wallez80b24112015-08-25 16:41:57 -0400522 for (auto fence : mFenceNVMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000523 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400524 SafeDelete(fence.second);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000525 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400526 mFenceNVMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000527
Corentin Wallez80b24112015-08-25 16:41:57 -0400528 for (auto query : mQueryMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000529 {
Geoff Langf0aa8422015-09-29 15:08:34 -0400530 if (query.second != nullptr)
531 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400532 query.second->release(this);
Geoff Langf0aa8422015-09-29 15:08:34 -0400533 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000534 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400535 mQueryMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000536
Corentin Wallez80b24112015-08-25 16:41:57 -0400537 for (auto vertexArray : mVertexArrayMap)
Jamie Madill57a89722013-07-02 11:57:03 -0400538 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400539 if (vertexArray.second)
540 {
541 vertexArray.second->onDestroy(this);
542 }
Jamie Madill57a89722013-07-02 11:57:03 -0400543 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400544 mVertexArrayMap.clear();
Jamie Madill57a89722013-07-02 11:57:03 -0400545
Corentin Wallez80b24112015-08-25 16:41:57 -0400546 for (auto transformFeedback : mTransformFeedbackMap)
Geoff Langc8058452014-02-03 12:04:11 -0500547 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500548 if (transformFeedback.second != nullptr)
549 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500550 transformFeedback.second->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500551 }
Geoff Langc8058452014-02-03 12:04:11 -0500552 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400553 mTransformFeedbackMap.clear();
Geoff Langc8058452014-02-03 12:04:11 -0500554
Jamie Madill5b772312018-03-08 20:28:32 -0500555 for (BindingPointer<Texture> &zeroTexture : mZeroTextures)
Geoff Lang76b10c92014-09-05 16:28:14 -0400556 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800557 if (zeroTexture.get() != nullptr)
558 {
559 ANGLE_TRY(zeroTexture->onDestroy(this));
560 zeroTexture.set(this, nullptr);
561 }
Geoff Lang76b10c92014-09-05 16:28:14 -0400562 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000563
Jamie Madill2f348d22017-06-05 10:50:59 -0400564 releaseShaderCompiler();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500565
Jamie Madill4928b7c2017-06-20 12:57:39 -0400566 mGLState.reset(this);
567
Jamie Madill6c1f6712017-02-14 19:08:04 -0500568 mState.mBuffers->release(this);
569 mState.mShaderPrograms->release(this);
570 mState.mTextures->release(this);
571 mState.mRenderbuffers->release(this);
572 mState.mSamplers->release(this);
Jamie Madill70b5bb02017-08-28 13:32:37 -0400573 mState.mSyncs->release(this);
Jamie Madill6c1f6712017-02-14 19:08:04 -0500574 mState.mPaths->release(this);
575 mState.mFramebuffers->release(this);
Yunchao Hea336b902017-08-02 16:05:21 +0800576 mState.mPipelines->release(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400577
Jamie Madill76e471e2017-10-21 09:56:01 -0400578 mImplementation->onDestroy(this);
579
Jamie Madill4928b7c2017-06-20 12:57:39 -0400580 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000581}
582
Jamie Madill70ee0f62017-02-06 16:04:20 -0500583Context::~Context()
584{
585}
586
Geoff Lang75359662018-04-11 01:42:27 -0400587void Context::setLabel(EGLLabelKHR label)
588{
589 mLabel = label;
590}
591
592EGLLabelKHR Context::getLabel() const
593{
594 return mLabel;
595}
596
Jamie Madill4928b7c2017-06-20 12:57:39 -0400597egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000598{
Jamie Madill61e16b42017-06-19 11:13:23 -0400599 mCurrentDisplay = display;
600
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000601 if (!mHasBeenCurrent)
602 {
Geoff Lang33f11fb2018-05-07 13:42:47 -0400603 initialize();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000604 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500605 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400606 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000607
Corentin Wallezc295e512017-01-27 17:47:50 -0500608 int width = 0;
609 int height = 0;
610 if (surface != nullptr)
611 {
612 width = surface->getWidth();
613 height = surface->getHeight();
614 }
615
616 mGLState.setViewportParams(0, 0, width, height);
617 mGLState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000618
619 mHasBeenCurrent = true;
620 }
621
Jamie Madill1b94d432015-08-07 13:23:23 -0400622 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700623 mGLState.setAllDirtyBits();
Jamie Madill81c2e252017-09-09 23:32:46 -0400624 mGLState.setAllDirtyObjects();
Jamie Madill1b94d432015-08-07 13:23:23 -0400625
Jamie Madill4928b7c2017-06-20 12:57:39 -0400626 ANGLE_TRY(releaseSurface(display));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500627
628 Framebuffer *newDefault = nullptr;
629 if (surface != nullptr)
630 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400631 ANGLE_TRY(surface->setIsCurrent(this, true));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500632 mCurrentSurface = surface;
Geoff Langbf7b95d2018-05-01 16:48:21 -0400633 newDefault = surface->createDefaultFramebuffer(this);
Corentin Wallezccab69d2017-01-27 16:57:15 -0500634 }
635 else
636 {
Geoff Langbf7b95d2018-05-01 16:48:21 -0400637 newDefault = new Framebuffer(mImplementation.get());
Corentin Wallezccab69d2017-01-27 16:57:15 -0500638 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000639
Corentin Wallez37c39792015-08-20 14:19:46 -0400640 // Update default framebuffer, the binding of the previous default
641 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400642 {
Jamie Madilla11819d2018-07-30 10:26:01 -0400643 mState.mFramebuffers->setDefaultFramebuffer(newDefault);
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700644 if (mGLState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400645 {
Jamie Madilla11819d2018-07-30 10:26:01 -0400646 bindReadFramebuffer(0);
Corentin Wallez37c39792015-08-20 14:19:46 -0400647 }
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700648 if (mGLState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400649 {
Jamie Madilla11819d2018-07-30 10:26:01 -0400650 bindDrawFramebuffer(0);
Corentin Wallez37c39792015-08-20 14:19:46 -0400651 }
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400652 }
Ian Ewell292f0052016-02-04 10:37:32 -0500653
654 // Notify the renderer of a context switch
Luc Ferron5396f2a2018-07-12 08:24:23 -0400655 ANGLE_TRY(mImplementation->onMakeCurrent(this));
Jamie Madill4928b7c2017-06-20 12:57:39 -0400656 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000657}
658
Jamie Madill4928b7c2017-06-20 12:57:39 -0400659egl::Error Context::releaseSurface(const egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400660{
Geoff Langbf7b95d2018-05-01 16:48:21 -0400661 gl::Framebuffer *defaultFramebuffer = mState.mFramebuffers->getFramebuffer(0);
Corentin Wallez51706ea2015-08-07 14:39:22 -0400662
Geoff Langbf7b95d2018-05-01 16:48:21 -0400663 // Remove the default framebuffer
664 if (mGLState.getReadFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500665 {
666 mGLState.setReadFramebufferBinding(nullptr);
Jamie Madilla11819d2018-07-30 10:26:01 -0400667 mReadFramebufferObserverBinding.bind(nullptr);
Corentin Wallezc295e512017-01-27 17:47:50 -0500668 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400669
670 if (mGLState.getDrawFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500671 {
672 mGLState.setDrawFramebufferBinding(nullptr);
Jamie Madilla11819d2018-07-30 10:26:01 -0400673 mDrawFramebufferObserverBinding.bind(nullptr);
Corentin Wallezc295e512017-01-27 17:47:50 -0500674 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400675
676 if (defaultFramebuffer)
677 {
678 defaultFramebuffer->onDestroy(this);
679 delete defaultFramebuffer;
680 }
681
Corentin Wallezc295e512017-01-27 17:47:50 -0500682 mState.mFramebuffers->setDefaultFramebuffer(nullptr);
683
684 if (mCurrentSurface)
685 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400686 ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
Corentin Wallezc295e512017-01-27 17:47:50 -0500687 mCurrentSurface = nullptr;
688 }
Jamie Madill4928b7c2017-06-20 12:57:39 -0400689
690 return egl::NoError();
Jamie Madill77a72f62015-04-14 11:18:32 -0400691}
692
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000693GLuint Context::createBuffer()
694{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500695 return mState.mBuffers->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000696}
697
698GLuint Context::createProgram()
699{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500700 return mState.mShaderPrograms->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000701}
702
Jiawei Shao385b3e02018-03-21 09:43:28 +0800703GLuint Context::createShader(ShaderType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000704{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500705 return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000706}
707
708GLuint Context::createTexture()
709{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500710 return mState.mTextures->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000711}
712
713GLuint Context::createRenderbuffer()
714{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500715 return mState.mRenderbuffers->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000716}
717
Brandon Jones59770802018-04-02 13:18:42 -0700718GLuint Context::genPaths(GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300719{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500720 auto resultOrError = mState.mPaths->createPaths(mImplementation.get(), range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300721 if (resultOrError.isError())
722 {
723 handleError(resultOrError.getError());
724 return 0;
725 }
726 return resultOrError.getResult();
727}
728
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000729// Returns an unused framebuffer name
730GLuint Context::createFramebuffer()
731{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500732 return mState.mFramebuffers->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000733}
734
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500735void Context::genFencesNV(GLsizei n, GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000736{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500737 for (int i = 0; i < n; i++)
738 {
739 GLuint handle = mFenceNVHandleAllocator.allocate();
740 mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV()));
741 fences[i] = handle;
742 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000743}
744
Yunchao Hea336b902017-08-02 16:05:21 +0800745GLuint Context::createProgramPipeline()
746{
747 return mState.mPipelines->createProgramPipeline();
748}
749
Jiawei Shao385b3e02018-03-21 09:43:28 +0800750GLuint Context::createShaderProgramv(ShaderType type, GLsizei count, const GLchar *const *strings)
Jiajia Qin5451d532017-11-16 17:16:34 +0800751{
752 UNIMPLEMENTED();
753 return 0u;
754}
755
James Darpinian4d9d4832018-03-13 12:43:28 -0700756void Context::deleteBuffer(GLuint bufferName)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000757{
James Darpinian4d9d4832018-03-13 12:43:28 -0700758 Buffer *buffer = mState.mBuffers->getBuffer(bufferName);
759 if (buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000760 {
761 detachBuffer(buffer);
762 }
Jamie Madill893ab082014-05-16 16:56:10 -0400763
James Darpinian4d9d4832018-03-13 12:43:28 -0700764 mState.mBuffers->deleteObject(this, bufferName);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000765}
766
767void Context::deleteShader(GLuint shader)
768{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500769 mState.mShaderPrograms->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000770}
771
772void Context::deleteProgram(GLuint program)
773{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500774 mState.mShaderPrograms->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000775}
776
777void Context::deleteTexture(GLuint texture)
778{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500779 if (mState.mTextures->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000780 {
781 detachTexture(texture);
782 }
783
Jamie Madill6c1f6712017-02-14 19:08:04 -0500784 mState.mTextures->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000785}
786
787void Context::deleteRenderbuffer(GLuint renderbuffer)
788{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500789 if (mState.mRenderbuffers->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000790 {
791 detachRenderbuffer(renderbuffer);
792 }
Jamie Madill893ab082014-05-16 16:56:10 -0400793
Jamie Madill6c1f6712017-02-14 19:08:04 -0500794 mState.mRenderbuffers->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000795}
796
Jamie Madill7f0c5a42017-08-26 22:43:26 -0400797void Context::deleteSync(GLsync sync)
Jamie Madillcd055f82013-07-26 11:55:15 -0400798{
799 // The spec specifies the underlying Fence object is not deleted until all current
800 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
801 // and since our API is currently designed for being called from a single thread, we can delete
802 // the fence immediately.
Jamie Madill70b5bb02017-08-28 13:32:37 -0400803 mState.mSyncs->deleteObject(this, static_cast<GLuint>(reinterpret_cast<uintptr_t>(sync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400804}
805
Yunchao Hea336b902017-08-02 16:05:21 +0800806void Context::deleteProgramPipeline(GLuint pipeline)
807{
808 if (mState.mPipelines->getProgramPipeline(pipeline))
809 {
810 detachProgramPipeline(pipeline);
811 }
812
813 mState.mPipelines->deleteObject(this, pipeline);
814}
815
Sami Väisänene45e53b2016-05-25 10:36:04 +0300816void Context::deletePaths(GLuint first, GLsizei range)
817{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500818 mState.mPaths->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300819}
820
Brandon Jones59770802018-04-02 13:18:42 -0700821bool Context::isPath(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300822{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500823 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300824 if (pathObj == nullptr)
825 return false;
826
827 return pathObj->hasPathData();
828}
829
Brandon Jones59770802018-04-02 13:18:42 -0700830bool Context::isPathGenerated(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300831{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500832 return mState.mPaths->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300833}
834
Brandon Jones59770802018-04-02 13:18:42 -0700835void Context::pathCommands(GLuint path,
836 GLsizei numCommands,
837 const GLubyte *commands,
838 GLsizei numCoords,
839 GLenum coordType,
840 const void *coords)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300841{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500842 auto *pathObject = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300843
844 handleError(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
845}
846
Jamie Madill007530e2017-12-28 14:27:04 -0500847void Context::pathParameterf(GLuint path, GLenum pname, GLfloat value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300848{
Jamie Madill007530e2017-12-28 14:27:04 -0500849 Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300850
851 switch (pname)
852 {
853 case GL_PATH_STROKE_WIDTH_CHROMIUM:
854 pathObj->setStrokeWidth(value);
855 break;
856 case GL_PATH_END_CAPS_CHROMIUM:
857 pathObj->setEndCaps(static_cast<GLenum>(value));
858 break;
859 case GL_PATH_JOIN_STYLE_CHROMIUM:
860 pathObj->setJoinStyle(static_cast<GLenum>(value));
861 break;
862 case GL_PATH_MITER_LIMIT_CHROMIUM:
863 pathObj->setMiterLimit(value);
864 break;
865 case GL_PATH_STROKE_BOUND_CHROMIUM:
866 pathObj->setStrokeBound(value);
867 break;
868 default:
869 UNREACHABLE();
870 break;
871 }
872}
873
Jamie Madill007530e2017-12-28 14:27:04 -0500874void Context::pathParameteri(GLuint path, GLenum pname, GLint value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300875{
Jamie Madill007530e2017-12-28 14:27:04 -0500876 // TODO(jmadill): Should use proper clamping/casting.
877 pathParameterf(path, pname, static_cast<GLfloat>(value));
878}
879
880void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value)
881{
882 const Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300883
884 switch (pname)
885 {
886 case GL_PATH_STROKE_WIDTH_CHROMIUM:
887 *value = pathObj->getStrokeWidth();
888 break;
889 case GL_PATH_END_CAPS_CHROMIUM:
890 *value = static_cast<GLfloat>(pathObj->getEndCaps());
891 break;
892 case GL_PATH_JOIN_STYLE_CHROMIUM:
893 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
894 break;
895 case GL_PATH_MITER_LIMIT_CHROMIUM:
896 *value = pathObj->getMiterLimit();
897 break;
898 case GL_PATH_STROKE_BOUND_CHROMIUM:
899 *value = pathObj->getStrokeBound();
900 break;
901 default:
902 UNREACHABLE();
903 break;
904 }
905}
906
Jamie Madill007530e2017-12-28 14:27:04 -0500907void Context::getPathParameteriv(GLuint path, GLenum pname, GLint *value)
908{
909 GLfloat val = 0.0f;
910 getPathParameterfv(path, pname, value != nullptr ? &val : nullptr);
911 if (value)
912 *value = static_cast<GLint>(val);
913}
914
Brandon Jones59770802018-04-02 13:18:42 -0700915void Context::pathStencilFunc(GLenum func, GLint ref, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300916{
917 mGLState.setPathStencilFunc(func, ref, mask);
918}
919
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000920void Context::deleteFramebuffer(GLuint framebuffer)
921{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500922 if (mState.mFramebuffers->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000923 {
924 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000925 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500926
Jamie Madill6c1f6712017-02-14 19:08:04 -0500927 mState.mFramebuffers->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000928}
929
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500930void Context::deleteFencesNV(GLsizei n, const GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000931{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500932 for (int i = 0; i < n; i++)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000933 {
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500934 GLuint fence = fences[i];
935
936 FenceNV *fenceObject = nullptr;
937 if (mFenceNVMap.erase(fence, &fenceObject))
938 {
939 mFenceNVHandleAllocator.release(fence);
940 delete fenceObject;
941 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000942 }
943}
944
Geoff Lang70d0f492015-12-10 17:45:46 -0500945Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000946{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500947 return mState.mBuffers->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000948}
949
Jamie Madill570f7c82014-07-03 10:38:54 -0400950Texture *Context::getTexture(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000951{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500952 return mState.mTextures->getTexture(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000953}
954
Geoff Lang70d0f492015-12-10 17:45:46 -0500955Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000956{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500957 return mState.mRenderbuffers->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000958}
959
Jamie Madill70b5bb02017-08-28 13:32:37 -0400960Sync *Context::getSync(GLsync handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400961{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400962 return mState.mSyncs->getSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400963}
964
Jamie Madill57a89722013-07-02 11:57:03 -0400965VertexArray *Context::getVertexArray(GLuint handle) const
966{
Jamie Madill96a483b2017-06-27 16:49:21 -0400967 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -0400968}
969
Jamie Madilldc356042013-07-19 16:36:57 -0400970Sampler *Context::getSampler(GLuint handle) const
971{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500972 return mState.mSamplers->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400973}
974
Geoff Langc8058452014-02-03 12:04:11 -0500975TransformFeedback *Context::getTransformFeedback(GLuint handle) const
976{
Jamie Madill96a483b2017-06-27 16:49:21 -0400977 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -0500978}
979
Yunchao Hea336b902017-08-02 16:05:21 +0800980ProgramPipeline *Context::getProgramPipeline(GLuint handle) const
981{
982 return mState.mPipelines->getProgramPipeline(handle);
983}
984
Geoff Lang75359662018-04-11 01:42:27 -0400985gl::LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
Geoff Lang70d0f492015-12-10 17:45:46 -0500986{
987 switch (identifier)
988 {
989 case GL_BUFFER:
990 return getBuffer(name);
991 case GL_SHADER:
992 return getShader(name);
993 case GL_PROGRAM:
994 return getProgram(name);
995 case GL_VERTEX_ARRAY:
996 return getVertexArray(name);
997 case GL_QUERY:
998 return getQuery(name);
999 case GL_TRANSFORM_FEEDBACK:
1000 return getTransformFeedback(name);
1001 case GL_SAMPLER:
1002 return getSampler(name);
1003 case GL_TEXTURE:
1004 return getTexture(name);
1005 case GL_RENDERBUFFER:
1006 return getRenderbuffer(name);
1007 case GL_FRAMEBUFFER:
1008 return getFramebuffer(name);
1009 default:
1010 UNREACHABLE();
1011 return nullptr;
1012 }
1013}
1014
Geoff Lang75359662018-04-11 01:42:27 -04001015gl::LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
Geoff Lang70d0f492015-12-10 17:45:46 -05001016{
Jamie Madill70b5bb02017-08-28 13:32:37 -04001017 return getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
Geoff Lang70d0f492015-12-10 17:45:46 -05001018}
1019
Martin Radev9d901792016-07-15 15:58:58 +03001020void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
1021{
Geoff Lang75359662018-04-11 01:42:27 -04001022 gl::LabeledObject *object = getLabeledObject(identifier, name);
Martin Radev9d901792016-07-15 15:58:58 +03001023 ASSERT(object != nullptr);
1024
1025 std::string labelName = GetObjectLabelFromPointer(length, label);
1026 object->setLabel(labelName);
Jamie Madill8693bdb2017-09-02 15:32:14 -04001027
1028 // TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the
1029 // specified object is active until we do this.
1030 mGLState.setObjectDirty(identifier);
Martin Radev9d901792016-07-15 15:58:58 +03001031}
1032
1033void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
1034{
Geoff Lang75359662018-04-11 01:42:27 -04001035 gl::LabeledObject *object = getLabeledObjectFromPtr(ptr);
Martin Radev9d901792016-07-15 15:58:58 +03001036 ASSERT(object != nullptr);
1037
1038 std::string labelName = GetObjectLabelFromPointer(length, label);
1039 object->setLabel(labelName);
1040}
1041
1042void Context::getObjectLabel(GLenum identifier,
1043 GLuint name,
1044 GLsizei bufSize,
1045 GLsizei *length,
1046 GLchar *label) const
1047{
Geoff Lang75359662018-04-11 01:42:27 -04001048 gl::LabeledObject *object = getLabeledObject(identifier, name);
Martin Radev9d901792016-07-15 15:58:58 +03001049 ASSERT(object != nullptr);
1050
1051 const std::string &objectLabel = object->getLabel();
1052 GetObjectLabelBase(objectLabel, bufSize, length, label);
1053}
1054
1055void Context::getObjectPtrLabel(const void *ptr,
1056 GLsizei bufSize,
1057 GLsizei *length,
1058 GLchar *label) const
1059{
Geoff Lang75359662018-04-11 01:42:27 -04001060 gl::LabeledObject *object = getLabeledObjectFromPtr(ptr);
Martin Radev9d901792016-07-15 15:58:58 +03001061 ASSERT(object != nullptr);
1062
1063 const std::string &objectLabel = object->getLabel();
1064 GetObjectLabelBase(objectLabel, bufSize, length, label);
1065}
1066
Jamie Madilldc356042013-07-19 16:36:57 -04001067bool Context::isSampler(GLuint samplerName) const
1068{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001069 return mState.mSamplers->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -04001070}
1071
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001072void Context::bindTexture(TextureType target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001073{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001074 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001075
Jamie Madilldedd7b92014-11-05 16:30:36 -05001076 if (handle == 0)
1077 {
1078 texture = mZeroTextures[target].get();
1079 }
1080 else
1081 {
Corentin Wallez99d492c2018-02-27 15:17:10 -05001082 texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -05001083 }
1084
1085 ASSERT(texture);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001086 mGLState.setSamplerTexture(this, target, texture);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00001087}
1088
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001089void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001090{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001091 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1092 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001093 mGLState.setReadFramebufferBinding(framebuffer);
Jamie Madilla11819d2018-07-30 10:26:01 -04001094 mReadFramebufferObserverBinding.bind(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001095}
1096
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001097void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001098{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001099 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1100 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001101 mGLState.setDrawFramebufferBinding(framebuffer);
Jamie Madilla11819d2018-07-30 10:26:01 -04001102 mDrawFramebufferObserverBinding.bind(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001103}
1104
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001105void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -04001106{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001107 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madill7267aa62018-04-17 15:28:21 -04001108 mGLState.setVertexArrayBinding(this, vertexArray);
Jamie Madilla11819d2018-07-30 10:26:01 -04001109 mVertexArrayObserverBinding.bind(vertexArray);
Jamie Madilldc358af2018-07-31 11:22:13 -04001110 mStateCache.updateActiveAttribsMask(this);
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04001111 mStateCache.updateVertexElementLimits(this);
Jamie Madill57a89722013-07-02 11:57:03 -04001112}
1113
Shao80957d92017-02-20 21:25:59 +08001114void Context::bindVertexBuffer(GLuint bindingIndex,
1115 GLuint bufferHandle,
1116 GLintptr offset,
1117 GLsizei stride)
1118{
1119 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001120 mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Jamie Madilldc358af2018-07-31 11:22:13 -04001121 mStateCache.updateActiveAttribsMask(this);
Shao80957d92017-02-20 21:25:59 +08001122}
1123
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001124void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -04001125{
Geoff Lang76b10c92014-09-05 16:28:14 -04001126 ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -04001127 Sampler *sampler =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001128 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001129 mGLState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04001130}
1131
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001132void Context::bindImageTexture(GLuint unit,
1133 GLuint texture,
1134 GLint level,
1135 GLboolean layered,
1136 GLint layer,
1137 GLenum access,
1138 GLenum format)
1139{
1140 Texture *tex = mState.mTextures->getTexture(texture);
1141 mGLState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
1142}
1143
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001144void Context::useProgram(GLuint program)
1145{
Jamie Madill6c1f6712017-02-14 19:08:04 -05001146 mGLState.setProgram(this, getProgram(program));
Jamie Madilldc358af2018-07-31 11:22:13 -04001147 mStateCache.updateActiveAttribsMask(this);
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04001148 mStateCache.updateVertexElementLimits(this);
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001149}
1150
Jiajia Qin5451d532017-11-16 17:16:34 +08001151void Context::useProgramStages(GLuint pipeline, GLbitfield stages, GLuint program)
1152{
1153 UNIMPLEMENTED();
1154}
1155
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001156void Context::bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001157{
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001158 ASSERT(target == GL_TRANSFORM_FEEDBACK);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001159 TransformFeedback *transformFeedback =
1160 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001161 mGLState.setTransformFeedbackBinding(this, transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -05001162}
1163
Yunchao Hea336b902017-08-02 16:05:21 +08001164void Context::bindProgramPipeline(GLuint pipelineHandle)
1165{
1166 ProgramPipeline *pipeline =
1167 mState.mPipelines->checkProgramPipelineAllocation(mImplementation.get(), pipelineHandle);
1168 mGLState.setProgramPipelineBinding(this, pipeline);
1169}
1170
Corentin Wallezad3ae902018-03-09 13:40:42 -05001171void Context::beginQuery(QueryType target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001172{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001173 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001174 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001175
Geoff Lang5aad9672014-09-08 11:10:42 -04001176 // begin query
Jamie Madill5188a272018-07-25 10:53:56 -04001177 ANGLE_CONTEXT_TRY(queryObject->begin(this));
Geoff Lang5aad9672014-09-08 11:10:42 -04001178
1179 // set query as active for specified target only if begin succeeded
Jamie Madill4928b7c2017-06-20 12:57:39 -04001180 mGLState.setActiveQuery(this, target, queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001181}
1182
Corentin Wallezad3ae902018-03-09 13:40:42 -05001183void Context::endQuery(QueryType target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001184{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001185 Query *queryObject = mGLState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001186 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001187
Jamie Madill5188a272018-07-25 10:53:56 -04001188 handleError(queryObject->end(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001189
Geoff Lang5aad9672014-09-08 11:10:42 -04001190 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madill4928b7c2017-06-20 12:57:39 -04001191 mGLState.setActiveQuery(this, target, nullptr);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001192}
1193
Corentin Wallezad3ae902018-03-09 13:40:42 -05001194void Context::queryCounter(GLuint id, QueryType target)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001195{
Corentin Wallezad3ae902018-03-09 13:40:42 -05001196 ASSERT(target == QueryType::Timestamp);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001197
1198 Query *queryObject = getQuery(id, true, target);
1199 ASSERT(queryObject);
1200
Jamie Madill5188a272018-07-25 10:53:56 -04001201 handleError(queryObject->queryCounter(this));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001202}
1203
Corentin Wallezad3ae902018-03-09 13:40:42 -05001204void Context::getQueryiv(QueryType target, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001205{
1206 switch (pname)
1207 {
1208 case GL_CURRENT_QUERY_EXT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001209 params[0] = mGLState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001210 break;
1211 case GL_QUERY_COUNTER_BITS_EXT:
1212 switch (target)
1213 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001214 case QueryType::TimeElapsed:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001215 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1216 break;
Corentin Wallezad3ae902018-03-09 13:40:42 -05001217 case QueryType::Timestamp:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001218 params[0] = getExtensions().queryCounterBitsTimestamp;
1219 break;
1220 default:
1221 UNREACHABLE();
1222 params[0] = 0;
1223 break;
1224 }
1225 break;
1226 default:
1227 UNREACHABLE();
1228 return;
1229 }
1230}
1231
Corentin Wallezad3ae902018-03-09 13:40:42 -05001232void Context::getQueryivRobust(QueryType target,
Brandon Jones59770802018-04-02 13:18:42 -07001233 GLenum pname,
1234 GLsizei bufSize,
1235 GLsizei *length,
1236 GLint *params)
1237{
1238 getQueryiv(target, pname, params);
1239}
1240
Geoff Lang2186c382016-10-14 10:54:54 -04001241void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001242{
Jamie Madill5188a272018-07-25 10:53:56 -04001243 handleError(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001244}
1245
Brandon Jones59770802018-04-02 13:18:42 -07001246void Context::getQueryObjectivRobust(GLuint id,
1247 GLenum pname,
1248 GLsizei bufSize,
1249 GLsizei *length,
1250 GLint *params)
1251{
1252 getQueryObjectiv(id, pname, params);
1253}
1254
Geoff Lang2186c382016-10-14 10:54:54 -04001255void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001256{
Jamie Madill5188a272018-07-25 10:53:56 -04001257 handleError(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001258}
1259
Brandon Jones59770802018-04-02 13:18:42 -07001260void Context::getQueryObjectuivRobust(GLuint id,
1261 GLenum pname,
1262 GLsizei bufSize,
1263 GLsizei *length,
1264 GLuint *params)
1265{
1266 getQueryObjectuiv(id, pname, params);
1267}
1268
Geoff Lang2186c382016-10-14 10:54:54 -04001269void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001270{
Jamie Madill5188a272018-07-25 10:53:56 -04001271 handleError(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001272}
1273
Brandon Jones59770802018-04-02 13:18:42 -07001274void Context::getQueryObjecti64vRobust(GLuint id,
1275 GLenum pname,
1276 GLsizei bufSize,
1277 GLsizei *length,
1278 GLint64 *params)
1279{
1280 getQueryObjecti64v(id, pname, params);
1281}
1282
Geoff Lang2186c382016-10-14 10:54:54 -04001283void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001284{
Jamie Madill5188a272018-07-25 10:53:56 -04001285 handleError(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001286}
1287
Brandon Jones59770802018-04-02 13:18:42 -07001288void Context::getQueryObjectui64vRobust(GLuint id,
1289 GLenum pname,
1290 GLsizei bufSize,
1291 GLsizei *length,
1292 GLuint64 *params)
1293{
1294 getQueryObjectui64v(id, pname, params);
1295}
1296
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001297Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001298{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001299 return mState.mFramebuffers->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001300}
1301
Jamie Madill2f348d22017-06-05 10:50:59 -04001302FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001303{
Jamie Madill96a483b2017-06-27 16:49:21 -04001304 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001305}
1306
Corentin Wallezad3ae902018-03-09 13:40:42 -05001307Query *Context::getQuery(GLuint handle, bool create, QueryType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001308{
Jamie Madill96a483b2017-06-27 16:49:21 -04001309 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001310 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001311 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001312 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001313
1314 Query *query = mQueryMap.query(handle);
1315 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001316 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001317 ASSERT(type != QueryType::InvalidEnum);
Jamie Madill96a483b2017-06-27 16:49:21 -04001318 query = new Query(mImplementation->createQuery(type), handle);
1319 query->addRef();
1320 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001321 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001322 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001323}
1324
Geoff Lang70d0f492015-12-10 17:45:46 -05001325Query *Context::getQuery(GLuint handle) const
1326{
Jamie Madill96a483b2017-06-27 16:49:21 -04001327 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001328}
1329
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001330Texture *Context::getTargetTexture(TextureType type) const
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001331{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001332 ASSERT(ValidTextureTarget(this, type) || ValidTextureExternalTarget(this, type));
1333 return mGLState.getTargetTexture(type);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001334}
1335
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001336Texture *Context::getSamplerTexture(unsigned int sampler, TextureType type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001337{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001338 return mGLState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001339}
1340
Geoff Lang492a7e42014-11-05 13:27:06 -05001341Compiler *Context::getCompiler() const
1342{
Jamie Madill2f348d22017-06-05 10:50:59 -04001343 if (mCompiler.get() == nullptr)
1344 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001345 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001346 }
1347 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001348}
1349
Jamie Madillc1d770e2017-04-13 17:31:24 -04001350void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001351{
1352 switch (pname)
1353 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001354 case GL_SHADER_COMPILER:
1355 *params = GL_TRUE;
1356 break;
1357 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1358 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1359 break;
1360 default:
1361 mGLState.getBooleanv(pname, params);
1362 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001363 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001364}
1365
Jamie Madillc1d770e2017-04-13 17:31:24 -04001366void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001367{
Shannon Woods53a94a82014-06-24 15:20:36 -04001368 // Queries about context capabilities and maximums are answered by Context.
1369 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001370 switch (pname)
1371 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001372 case GL_ALIASED_LINE_WIDTH_RANGE:
1373 params[0] = mCaps.minAliasedLineWidth;
1374 params[1] = mCaps.maxAliasedLineWidth;
1375 break;
1376 case GL_ALIASED_POINT_SIZE_RANGE:
1377 params[0] = mCaps.minAliasedPointSize;
1378 params[1] = mCaps.maxAliasedPointSize;
1379 break;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07001380 case GL_SMOOTH_POINT_SIZE_RANGE:
1381 params[0] = mCaps.minSmoothPointSize;
1382 params[1] = mCaps.maxSmoothPointSize;
1383 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001384 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1385 ASSERT(mExtensions.textureFilterAnisotropic);
1386 *params = mExtensions.maxTextureAnisotropy;
1387 break;
1388 case GL_MAX_TEXTURE_LOD_BIAS:
1389 *params = mCaps.maxLODBias;
1390 break;
1391
1392 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1393 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1394 {
Lingfeng Yang3a41af62018-04-09 07:28:56 -07001395 // GLES1 emulation: // GL_PATH_(MODELVIEW|PROJECTION)_MATRIX_CHROMIUM collides with the
1396 // GLES1 constants for modelview/projection matrix.
1397 if (getClientVersion() < Version(2, 0))
1398 {
1399 mGLState.getFloatv(pname, params);
1400 }
1401 else
1402 {
1403 ASSERT(mExtensions.pathRendering);
1404 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1405 memcpy(params, m, 16 * sizeof(GLfloat));
1406 }
Jamie Madill231c7f52017-04-26 13:45:37 -04001407 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001408 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001409
Jamie Madill231c7f52017-04-26 13:45:37 -04001410 default:
1411 mGLState.getFloatv(pname, params);
1412 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001413 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001414}
1415
Jamie Madillc1d770e2017-04-13 17:31:24 -04001416void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001417{
Shannon Woods53a94a82014-06-24 15:20:36 -04001418 // Queries about context capabilities and maximums are answered by Context.
1419 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001420
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001421 switch (pname)
1422 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001423 case GL_MAX_VERTEX_ATTRIBS:
1424 *params = mCaps.maxVertexAttributes;
1425 break;
1426 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1427 *params = mCaps.maxVertexUniformVectors;
1428 break;
1429 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001430 *params = mCaps.maxShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001431 break;
1432 case GL_MAX_VARYING_VECTORS:
1433 *params = mCaps.maxVaryingVectors;
1434 break;
1435 case GL_MAX_VARYING_COMPONENTS:
1436 *params = mCaps.maxVertexOutputComponents;
1437 break;
1438 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1439 *params = mCaps.maxCombinedTextureImageUnits;
1440 break;
1441 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001442 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001443 break;
1444 case GL_MAX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001445 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001446 break;
1447 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1448 *params = mCaps.maxFragmentUniformVectors;
1449 break;
1450 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001451 *params = mCaps.maxShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001452 break;
1453 case GL_MAX_RENDERBUFFER_SIZE:
1454 *params = mCaps.maxRenderbufferSize;
1455 break;
1456 case GL_MAX_COLOR_ATTACHMENTS_EXT:
1457 *params = mCaps.maxColorAttachments;
1458 break;
1459 case GL_MAX_DRAW_BUFFERS_EXT:
1460 *params = mCaps.maxDrawBuffers;
1461 break;
1462 // case GL_FRAMEBUFFER_BINDING: // now equivalent to
1463 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
1464 case GL_SUBPIXEL_BITS:
1465 *params = 4;
1466 break;
1467 case GL_MAX_TEXTURE_SIZE:
1468 *params = mCaps.max2DTextureSize;
1469 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001470 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
1471 *params = mCaps.maxRectangleTextureSize;
1472 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001473 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1474 *params = mCaps.maxCubeMapTextureSize;
1475 break;
1476 case GL_MAX_3D_TEXTURE_SIZE:
1477 *params = mCaps.max3DTextureSize;
1478 break;
1479 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1480 *params = mCaps.maxArrayTextureLayers;
1481 break;
1482 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1483 *params = mCaps.uniformBufferOffsetAlignment;
1484 break;
1485 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1486 *params = mCaps.maxUniformBufferBindings;
1487 break;
1488 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001489 *params = mCaps.maxShaderUniformBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001490 break;
1491 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001492 *params = mCaps.maxShaderUniformBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001493 break;
1494 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1495 *params = mCaps.maxCombinedTextureImageUnits;
1496 break;
1497 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1498 *params = mCaps.maxVertexOutputComponents;
1499 break;
1500 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1501 *params = mCaps.maxFragmentInputComponents;
1502 break;
1503 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1504 *params = mCaps.minProgramTexelOffset;
1505 break;
1506 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1507 *params = mCaps.maxProgramTexelOffset;
1508 break;
1509 case GL_MAJOR_VERSION:
1510 *params = getClientVersion().major;
1511 break;
1512 case GL_MINOR_VERSION:
1513 *params = getClientVersion().minor;
1514 break;
1515 case GL_MAX_ELEMENTS_INDICES:
1516 *params = mCaps.maxElementsIndices;
1517 break;
1518 case GL_MAX_ELEMENTS_VERTICES:
1519 *params = mCaps.maxElementsVertices;
1520 break;
1521 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1522 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1523 break;
1524 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1525 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1526 break;
1527 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1528 *params = mCaps.maxTransformFeedbackSeparateComponents;
1529 break;
1530 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1531 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1532 break;
1533 case GL_MAX_SAMPLES_ANGLE:
1534 *params = mCaps.maxSamples;
1535 break;
1536 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001537 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001538 params[0] = mCaps.maxViewportWidth;
1539 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001540 }
1541 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001542 case GL_COMPRESSED_TEXTURE_FORMATS:
1543 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1544 params);
1545 break;
1546 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1547 *params = mResetStrategy;
1548 break;
1549 case GL_NUM_SHADER_BINARY_FORMATS:
1550 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1551 break;
1552 case GL_SHADER_BINARY_FORMATS:
1553 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1554 break;
1555 case GL_NUM_PROGRAM_BINARY_FORMATS:
1556 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1557 break;
1558 case GL_PROGRAM_BINARY_FORMATS:
1559 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1560 break;
1561 case GL_NUM_EXTENSIONS:
1562 *params = static_cast<GLint>(mExtensionStrings.size());
1563 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001564
Jamie Madill231c7f52017-04-26 13:45:37 -04001565 // GL_KHR_debug
1566 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1567 *params = mExtensions.maxDebugMessageLength;
1568 break;
1569 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1570 *params = mExtensions.maxDebugLoggedMessages;
1571 break;
1572 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1573 *params = mExtensions.maxDebugGroupStackDepth;
1574 break;
1575 case GL_MAX_LABEL_LENGTH:
1576 *params = mExtensions.maxLabelLength;
1577 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001578
Martin Radeve5285d22017-07-14 16:23:53 +03001579 // GL_ANGLE_multiview
1580 case GL_MAX_VIEWS_ANGLE:
1581 *params = mExtensions.maxViews;
1582 break;
1583
Jamie Madill231c7f52017-04-26 13:45:37 -04001584 // GL_EXT_disjoint_timer_query
1585 case GL_GPU_DISJOINT_EXT:
1586 *params = mImplementation->getGPUDisjoint();
1587 break;
1588 case GL_MAX_FRAMEBUFFER_WIDTH:
1589 *params = mCaps.maxFramebufferWidth;
1590 break;
1591 case GL_MAX_FRAMEBUFFER_HEIGHT:
1592 *params = mCaps.maxFramebufferHeight;
1593 break;
1594 case GL_MAX_FRAMEBUFFER_SAMPLES:
1595 *params = mCaps.maxFramebufferSamples;
1596 break;
1597 case GL_MAX_SAMPLE_MASK_WORDS:
1598 *params = mCaps.maxSampleMaskWords;
1599 break;
1600 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1601 *params = mCaps.maxColorTextureSamples;
1602 break;
1603 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1604 *params = mCaps.maxDepthTextureSamples;
1605 break;
1606 case GL_MAX_INTEGER_SAMPLES:
1607 *params = mCaps.maxIntegerSamples;
1608 break;
1609 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1610 *params = mCaps.maxVertexAttribRelativeOffset;
1611 break;
1612 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1613 *params = mCaps.maxVertexAttribBindings;
1614 break;
1615 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1616 *params = mCaps.maxVertexAttribStride;
1617 break;
1618 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001619 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001620 break;
1621 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001622 *params = mCaps.maxShaderAtomicCounters[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001623 break;
1624 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001625 *params = mCaps.maxShaderImageUniforms[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001626 break;
1627 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001628 *params = mCaps.maxShaderStorageBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001629 break;
1630 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001631 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001632 break;
1633 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001634 *params = mCaps.maxShaderAtomicCounters[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001635 break;
1636 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001637 *params = mCaps.maxShaderImageUniforms[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001638 break;
1639 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001640 *params = mCaps.maxShaderStorageBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001641 break;
1642 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1643 *params = mCaps.minProgramTextureGatherOffset;
1644 break;
1645 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1646 *params = mCaps.maxProgramTextureGatherOffset;
1647 break;
1648 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1649 *params = mCaps.maxComputeWorkGroupInvocations;
1650 break;
1651 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001652 *params = mCaps.maxShaderUniformBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001653 break;
1654 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001655 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001656 break;
1657 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1658 *params = mCaps.maxComputeSharedMemorySize;
1659 break;
1660 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001661 *params = mCaps.maxShaderUniformComponents[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001662 break;
1663 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001664 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001665 break;
1666 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001667 *params = mCaps.maxShaderAtomicCounters[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001668 break;
1669 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001670 *params = mCaps.maxShaderImageUniforms[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001671 break;
1672 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001673 *params =
1674 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Compute]);
Jamie Madill231c7f52017-04-26 13:45:37 -04001675 break;
1676 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001677 *params = mCaps.maxShaderStorageBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001678 break;
1679 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1680 *params = mCaps.maxCombinedShaderOutputResources;
1681 break;
1682 case GL_MAX_UNIFORM_LOCATIONS:
1683 *params = mCaps.maxUniformLocations;
1684 break;
1685 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1686 *params = mCaps.maxAtomicCounterBufferBindings;
1687 break;
1688 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1689 *params = mCaps.maxAtomicCounterBufferSize;
1690 break;
1691 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1692 *params = mCaps.maxCombinedAtomicCounterBuffers;
1693 break;
1694 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1695 *params = mCaps.maxCombinedAtomicCounters;
1696 break;
1697 case GL_MAX_IMAGE_UNITS:
1698 *params = mCaps.maxImageUnits;
1699 break;
1700 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1701 *params = mCaps.maxCombinedImageUniforms;
1702 break;
1703 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1704 *params = mCaps.maxShaderStorageBufferBindings;
1705 break;
1706 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1707 *params = mCaps.maxCombinedShaderStorageBlocks;
1708 break;
1709 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1710 *params = mCaps.shaderStorageBufferOffsetAlignment;
1711 break;
Jiawei Shao361df072017-11-22 09:33:59 +08001712
1713 // GL_EXT_geometry_shader
1714 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
1715 *params = mCaps.maxFramebufferLayers;
1716 break;
1717 case GL_LAYER_PROVOKING_VERTEX_EXT:
1718 *params = mCaps.layerProvokingVertex;
1719 break;
1720 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001721 *params = mCaps.maxShaderUniformComponents[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001722 break;
1723 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001724 *params = mCaps.maxShaderUniformBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001725 break;
1726 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001727 *params =
1728 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Geometry]);
Jiawei Shao361df072017-11-22 09:33:59 +08001729 break;
1730 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
1731 *params = mCaps.maxGeometryInputComponents;
1732 break;
1733 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
1734 *params = mCaps.maxGeometryOutputComponents;
1735 break;
1736 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
1737 *params = mCaps.maxGeometryOutputVertices;
1738 break;
1739 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
1740 *params = mCaps.maxGeometryTotalOutputComponents;
1741 break;
1742 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
1743 *params = mCaps.maxGeometryShaderInvocations;
1744 break;
1745 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001746 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001747 break;
1748 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001749 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001750 break;
1751 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001752 *params = mCaps.maxShaderAtomicCounters[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001753 break;
1754 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001755 *params = mCaps.maxShaderImageUniforms[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001756 break;
1757 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001758 *params = mCaps.maxShaderStorageBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001759 break;
Lingfeng Yang96310cd2018-03-28 11:56:28 -07001760 // GLES1 emulation: Caps queries
1761 case GL_MAX_TEXTURE_UNITS:
1762 *params = mCaps.maxMultitextureUnits;
1763 break;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001764 case GL_MAX_MODELVIEW_STACK_DEPTH:
1765 *params = mCaps.maxModelviewMatrixStackDepth;
1766 break;
1767 case GL_MAX_PROJECTION_STACK_DEPTH:
1768 *params = mCaps.maxProjectionMatrixStackDepth;
1769 break;
1770 case GL_MAX_TEXTURE_STACK_DEPTH:
1771 *params = mCaps.maxTextureMatrixStackDepth;
1772 break;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07001773 case GL_MAX_LIGHTS:
1774 *params = mCaps.maxLights;
1775 break;
Lingfeng Yang060088a2018-05-30 20:40:57 -07001776 case GL_MAX_CLIP_PLANES:
1777 *params = mCaps.maxClipPlanes;
1778 break;
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001779 // GLES1 emulation: Vertex attribute queries
1780 case GL_VERTEX_ARRAY_BUFFER_BINDING:
1781 case GL_NORMAL_ARRAY_BUFFER_BINDING:
1782 case GL_COLOR_ARRAY_BUFFER_BINDING:
1783 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
1784 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
1785 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1786 GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, params);
1787 break;
1788 case GL_VERTEX_ARRAY_STRIDE:
1789 case GL_NORMAL_ARRAY_STRIDE:
1790 case GL_COLOR_ARRAY_STRIDE:
1791 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
1792 case GL_TEXTURE_COORD_ARRAY_STRIDE:
1793 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1794 GL_VERTEX_ATTRIB_ARRAY_STRIDE, params);
1795 break;
1796 case GL_VERTEX_ARRAY_SIZE:
1797 case GL_COLOR_ARRAY_SIZE:
1798 case GL_TEXTURE_COORD_ARRAY_SIZE:
1799 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1800 GL_VERTEX_ATTRIB_ARRAY_SIZE, params);
1801 break;
1802 case GL_VERTEX_ARRAY_TYPE:
1803 case GL_COLOR_ARRAY_TYPE:
1804 case GL_NORMAL_ARRAY_TYPE:
1805 case GL_POINT_SIZE_ARRAY_TYPE_OES:
1806 case GL_TEXTURE_COORD_ARRAY_TYPE:
1807 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1808 GL_VERTEX_ATTRIB_ARRAY_TYPE, params);
1809 break;
1810
jchen1082af6202018-06-22 10:59:52 +08001811 // GL_KHR_parallel_shader_compile
1812 case GL_MAX_SHADER_COMPILER_THREADS_KHR:
1813 *params = mGLState.getMaxShaderCompilerThreads();
1814 break;
1815
Jamie Madill231c7f52017-04-26 13:45:37 -04001816 default:
Jamie Madille98b1b52018-03-08 09:47:23 -05001817 handleError(mGLState.getIntegerv(this, pname, params));
Jamie Madill231c7f52017-04-26 13:45:37 -04001818 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001819 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001820}
1821
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001822void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001823{
Shannon Woods53a94a82014-06-24 15:20:36 -04001824 // Queries about context capabilities and maximums are answered by Context.
1825 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001826 switch (pname)
1827 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001828 case GL_MAX_ELEMENT_INDEX:
1829 *params = mCaps.maxElementIndex;
1830 break;
1831 case GL_MAX_UNIFORM_BLOCK_SIZE:
1832 *params = mCaps.maxUniformBlockSize;
1833 break;
1834 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001835 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001836 break;
1837 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001838 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001839 break;
1840 case GL_MAX_SERVER_WAIT_TIMEOUT:
1841 *params = mCaps.maxServerWaitTimeout;
1842 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001843
Jamie Madill231c7f52017-04-26 13:45:37 -04001844 // GL_EXT_disjoint_timer_query
1845 case GL_TIMESTAMP_EXT:
1846 *params = mImplementation->getTimestamp();
1847 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001848
Jamie Madill231c7f52017-04-26 13:45:37 -04001849 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1850 *params = mCaps.maxShaderStorageBlockSize;
1851 break;
1852 default:
1853 UNREACHABLE();
1854 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001855 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001856}
1857
Geoff Lang70d0f492015-12-10 17:45:46 -05001858void Context::getPointerv(GLenum pname, void **params) const
1859{
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001860 mGLState.getPointerv(this, pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001861}
1862
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001863void Context::getPointervRobustANGLERobust(GLenum pname,
1864 GLsizei bufSize,
1865 GLsizei *length,
1866 void **params)
1867{
1868 UNIMPLEMENTED();
1869}
1870
Martin Radev66fb8202016-07-28 11:45:20 +03001871void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001872{
Shannon Woods53a94a82014-06-24 15:20:36 -04001873 // Queries about context capabilities and maximums are answered by Context.
1874 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001875
1876 GLenum nativeType;
1877 unsigned int numParams;
1878 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1879 ASSERT(queryStatus);
1880
1881 if (nativeType == GL_INT)
1882 {
1883 switch (target)
1884 {
1885 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1886 ASSERT(index < 3u);
1887 *data = mCaps.maxComputeWorkGroupCount[index];
1888 break;
1889 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1890 ASSERT(index < 3u);
1891 *data = mCaps.maxComputeWorkGroupSize[index];
1892 break;
1893 default:
1894 mGLState.getIntegeri_v(target, index, data);
1895 }
1896 }
1897 else
1898 {
1899 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1900 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001901}
1902
Brandon Jones59770802018-04-02 13:18:42 -07001903void Context::getIntegeri_vRobust(GLenum target,
1904 GLuint index,
1905 GLsizei bufSize,
1906 GLsizei *length,
1907 GLint *data)
1908{
1909 getIntegeri_v(target, index, data);
1910}
1911
Martin Radev66fb8202016-07-28 11:45:20 +03001912void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001913{
Shannon Woods53a94a82014-06-24 15:20:36 -04001914 // Queries about context capabilities and maximums are answered by Context.
1915 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001916
1917 GLenum nativeType;
1918 unsigned int numParams;
1919 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1920 ASSERT(queryStatus);
1921
1922 if (nativeType == GL_INT_64_ANGLEX)
1923 {
1924 mGLState.getInteger64i_v(target, index, data);
1925 }
1926 else
1927 {
1928 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1929 }
1930}
1931
Brandon Jones59770802018-04-02 13:18:42 -07001932void Context::getInteger64i_vRobust(GLenum target,
1933 GLuint index,
1934 GLsizei bufSize,
1935 GLsizei *length,
1936 GLint64 *data)
1937{
1938 getInteger64i_v(target, index, data);
1939}
1940
Martin Radev66fb8202016-07-28 11:45:20 +03001941void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1942{
1943 // Queries about context capabilities and maximums are answered by Context.
1944 // Queries about current GL state values are answered by State.
1945
1946 GLenum nativeType;
1947 unsigned int numParams;
1948 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1949 ASSERT(queryStatus);
1950
1951 if (nativeType == GL_BOOL)
1952 {
1953 mGLState.getBooleani_v(target, index, data);
1954 }
1955 else
1956 {
1957 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1958 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001959}
1960
Brandon Jones59770802018-04-02 13:18:42 -07001961void Context::getBooleani_vRobust(GLenum target,
1962 GLuint index,
1963 GLsizei bufSize,
1964 GLsizei *length,
1965 GLboolean *data)
1966{
1967 getBooleani_v(target, index, data);
1968}
1969
Corentin Wallez336129f2017-10-17 15:55:40 -04001970void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001971{
1972 Buffer *buffer = mGLState.getTargetBuffer(target);
1973 QueryBufferParameteriv(buffer, pname, params);
1974}
1975
Brandon Jones59770802018-04-02 13:18:42 -07001976void Context::getBufferParameterivRobust(BufferBinding target,
1977 GLenum pname,
1978 GLsizei bufSize,
1979 GLsizei *length,
1980 GLint *params)
1981{
1982 getBufferParameteriv(target, pname, params);
1983}
1984
He Yunchao010e4db2017-03-03 14:22:06 +08001985void Context::getFramebufferAttachmentParameteriv(GLenum target,
1986 GLenum attachment,
1987 GLenum pname,
1988 GLint *params)
1989{
1990 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08001991 QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08001992}
1993
Brandon Jones59770802018-04-02 13:18:42 -07001994void Context::getFramebufferAttachmentParameterivRobust(GLenum target,
1995 GLenum attachment,
1996 GLenum pname,
1997 GLsizei bufSize,
1998 GLsizei *length,
1999 GLint *params)
2000{
2001 getFramebufferAttachmentParameteriv(target, attachment, pname, params);
2002}
2003
He Yunchao010e4db2017-03-03 14:22:06 +08002004void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
2005{
2006 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
2007 QueryRenderbufferiv(this, renderbuffer, pname, params);
2008}
2009
Brandon Jones59770802018-04-02 13:18:42 -07002010void Context::getRenderbufferParameterivRobust(GLenum target,
2011 GLenum pname,
2012 GLsizei bufSize,
2013 GLsizei *length,
2014 GLint *params)
2015{
2016 getRenderbufferParameteriv(target, pname, params);
2017}
2018
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002019void Context::getTexParameterfv(TextureType target, GLenum pname, GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002020{
2021 Texture *texture = getTargetTexture(target);
2022 QueryTexParameterfv(texture, pname, params);
2023}
2024
Brandon Jones59770802018-04-02 13:18:42 -07002025void Context::getTexParameterfvRobust(TextureType target,
2026 GLenum pname,
2027 GLsizei bufSize,
2028 GLsizei *length,
2029 GLfloat *params)
2030{
2031 getTexParameterfv(target, pname, params);
2032}
2033
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002034void Context::getTexParameteriv(TextureType target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002035{
2036 Texture *texture = getTargetTexture(target);
2037 QueryTexParameteriv(texture, pname, params);
2038}
Jiajia Qin5451d532017-11-16 17:16:34 +08002039
Brandon Jones59770802018-04-02 13:18:42 -07002040void Context::getTexParameterivRobust(TextureType target,
2041 GLenum pname,
2042 GLsizei bufSize,
2043 GLsizei *length,
2044 GLint *params)
2045{
2046 getTexParameteriv(target, pname, params);
2047}
2048
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002049void Context::getTexParameterIivRobust(TextureType target,
2050 GLenum pname,
2051 GLsizei bufSize,
2052 GLsizei *length,
2053 GLint *params)
2054{
2055 UNIMPLEMENTED();
2056}
2057
2058void Context::getTexParameterIuivRobust(TextureType target,
2059 GLenum pname,
2060 GLsizei bufSize,
2061 GLsizei *length,
2062 GLuint *params)
2063{
2064 UNIMPLEMENTED();
2065}
2066
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002067void Context::getTexLevelParameteriv(TextureTarget target, GLint level, GLenum pname, GLint *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002068{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002069 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002070 QueryTexLevelParameteriv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002071}
2072
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002073void Context::getTexLevelParameterivRobust(TextureTarget target,
2074 GLint level,
2075 GLenum pname,
2076 GLsizei bufSize,
2077 GLsizei *length,
2078 GLint *params)
2079{
2080 UNIMPLEMENTED();
2081}
2082
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002083void Context::getTexLevelParameterfv(TextureTarget target,
2084 GLint level,
2085 GLenum pname,
2086 GLfloat *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002087{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002088 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002089 QueryTexLevelParameterfv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002090}
2091
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002092void Context::getTexLevelParameterfvRobust(TextureTarget target,
2093 GLint level,
2094 GLenum pname,
2095 GLsizei bufSize,
2096 GLsizei *length,
2097 GLfloat *params)
2098{
2099 UNIMPLEMENTED();
2100}
2101
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002102void Context::texParameterf(TextureType target, GLenum pname, GLfloat param)
He Yunchao010e4db2017-03-03 14:22:06 +08002103{
2104 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002105 SetTexParameterf(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002106 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002107}
2108
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002109void Context::texParameterfv(TextureType target, GLenum pname, const GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002110{
2111 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002112 SetTexParameterfv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002113 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002114}
2115
Brandon Jones59770802018-04-02 13:18:42 -07002116void Context::texParameterfvRobust(TextureType target,
2117 GLenum pname,
2118 GLsizei bufSize,
2119 const GLfloat *params)
2120{
2121 texParameterfv(target, pname, params);
2122}
2123
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002124void Context::texParameteri(TextureType target, GLenum pname, GLint param)
He Yunchao010e4db2017-03-03 14:22:06 +08002125{
2126 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002127 SetTexParameteri(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002128 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002129}
2130
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002131void Context::texParameteriv(TextureType target, GLenum pname, const GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002132{
2133 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002134 SetTexParameteriv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002135 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002136}
2137
Brandon Jones59770802018-04-02 13:18:42 -07002138void Context::texParameterivRobust(TextureType target,
2139 GLenum pname,
2140 GLsizei bufSize,
2141 const GLint *params)
2142{
2143 texParameteriv(target, pname, params);
2144}
2145
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002146void Context::texParameterIivRobust(TextureType target,
2147 GLenum pname,
2148 GLsizei bufSize,
2149 const GLint *params)
2150{
2151 UNIMPLEMENTED();
2152}
2153
2154void Context::texParameterIuivRobust(TextureType target,
2155 GLenum pname,
2156 GLsizei bufSize,
2157 const GLuint *params)
2158{
2159 UNIMPLEMENTED();
2160}
2161
Jamie Madill493f9572018-05-24 19:52:15 -04002162void Context::drawArrays(PrimitiveMode mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002163{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002164 // No-op if count draws no primitives for given mode
2165 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002166 {
2167 return;
2168 }
2169
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002170 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002171 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
Jamie Madill09463932018-04-04 05:26:59 -04002172 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count, 1);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002173}
2174
Jamie Madill493f9572018-05-24 19:52:15 -04002175void Context::drawArraysInstanced(PrimitiveMode mode,
2176 GLint first,
2177 GLsizei count,
2178 GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04002179{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002180 // No-op if count draws no primitives for given mode
2181 if (noopDrawInstanced(mode, count, instanceCount))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002182 {
2183 return;
2184 }
2185
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002186 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002187 ANGLE_CONTEXT_TRY(
2188 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
Jamie Madill09463932018-04-04 05:26:59 -04002189 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count,
2190 instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -04002191}
2192
Jamie Madill493f9572018-05-24 19:52:15 -04002193void Context::drawElements(PrimitiveMode mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002194{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002195 // No-op if count draws no primitives for given mode
2196 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002197 {
2198 return;
2199 }
2200
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002201 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002202 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04002203}
2204
Jamie Madill493f9572018-05-24 19:52:15 -04002205void Context::drawElementsInstanced(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002206 GLsizei count,
2207 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002208 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04002209 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04002210{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002211 // No-op if count draws no primitives for given mode
2212 if (noopDrawInstanced(mode, count, instances))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002213 {
2214 return;
2215 }
2216
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002217 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002218 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08002219 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04002220}
2221
Jamie Madill493f9572018-05-24 19:52:15 -04002222void Context::drawRangeElements(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002223 GLuint start,
2224 GLuint end,
2225 GLsizei count,
2226 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002227 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04002228{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002229 // No-op if count draws no primitives for given mode
2230 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002231 {
2232 return;
2233 }
2234
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002235 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002236 ANGLE_CONTEXT_TRY(
2237 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002238}
2239
Jamie Madill493f9572018-05-24 19:52:15 -04002240void Context::drawArraysIndirect(PrimitiveMode mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002241{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002242 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002243 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002244}
2245
Jamie Madill493f9572018-05-24 19:52:15 -04002246void Context::drawElementsIndirect(PrimitiveMode mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002247{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002248 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002249 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002250}
2251
Jamie Madill675fe712016-12-19 13:07:54 -05002252void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002253{
Jamie Madillafa02a22017-11-23 12:57:38 -05002254 handleError(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05002255}
2256
Jamie Madill675fe712016-12-19 13:07:54 -05002257void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05002258{
Jamie Madillafa02a22017-11-23 12:57:38 -05002259 handleError(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002260}
2261
Austin Kinross6ee1e782015-05-29 17:05:37 -07002262void Context::insertEventMarker(GLsizei length, const char *marker)
2263{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002264 ASSERT(mImplementation);
2265 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07002266}
2267
2268void Context::pushGroupMarker(GLsizei length, const char *marker)
2269{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002270 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05002271
2272 if (marker == nullptr)
2273 {
2274 // From the EXT_debug_marker spec,
2275 // "If <marker> is null then an empty string is pushed on the stack."
2276 mImplementation->pushGroupMarker(length, "");
2277 }
2278 else
2279 {
2280 mImplementation->pushGroupMarker(length, marker);
2281 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07002282}
2283
2284void Context::popGroupMarker()
2285{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002286 ASSERT(mImplementation);
2287 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07002288}
2289
Geoff Langd8605522016-04-13 10:19:12 -04002290void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
2291{
2292 Program *programObject = getProgram(program);
2293 ASSERT(programObject);
2294
2295 programObject->bindUniformLocation(location, name);
2296}
2297
Brandon Jones59770802018-04-02 13:18:42 -07002298void Context::coverageModulation(GLenum components)
Sami Väisänena797e062016-05-12 15:23:40 +03002299{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002300 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03002301}
2302
Brandon Jones59770802018-04-02 13:18:42 -07002303void Context::matrixLoadf(GLenum matrixMode, const GLfloat *matrix)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002304{
2305 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
2306}
2307
Brandon Jones59770802018-04-02 13:18:42 -07002308void Context::matrixLoadIdentity(GLenum matrixMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002309{
2310 GLfloat I[16];
2311 angle::Matrix<GLfloat>::setToIdentity(I);
2312
2313 mGLState.loadPathRenderingMatrix(matrixMode, I);
2314}
2315
2316void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
2317{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002318 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002319 if (!pathObj)
2320 return;
2321
Geoff Lang9bf86f02018-07-26 11:46:34 -04002322 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002323
2324 mImplementation->stencilFillPath(pathObj, fillMode, mask);
2325}
2326
2327void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
2328{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002329 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002330 if (!pathObj)
2331 return;
2332
Geoff Lang9bf86f02018-07-26 11:46:34 -04002333 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002334
2335 mImplementation->stencilStrokePath(pathObj, reference, mask);
2336}
2337
2338void Context::coverFillPath(GLuint path, GLenum coverMode)
2339{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002340 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002341 if (!pathObj)
2342 return;
2343
Geoff Lang9bf86f02018-07-26 11:46:34 -04002344 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002345
2346 mImplementation->coverFillPath(pathObj, coverMode);
2347}
2348
2349void Context::coverStrokePath(GLuint path, GLenum coverMode)
2350{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002351 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002352 if (!pathObj)
2353 return;
2354
Geoff Lang9bf86f02018-07-26 11:46:34 -04002355 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002356
2357 mImplementation->coverStrokePath(pathObj, coverMode);
2358}
2359
2360void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
2361{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002362 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002363 if (!pathObj)
2364 return;
2365
Geoff Lang9bf86f02018-07-26 11:46:34 -04002366 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002367
2368 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
2369}
2370
2371void Context::stencilThenCoverStrokePath(GLuint path,
2372 GLint reference,
2373 GLuint mask,
2374 GLenum coverMode)
2375{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002376 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002377 if (!pathObj)
2378 return;
2379
Geoff Lang9bf86f02018-07-26 11:46:34 -04002380 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002381
2382 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2383}
2384
Sami Väisänend59ca052016-06-21 16:10:00 +03002385void Context::coverFillPathInstanced(GLsizei numPaths,
2386 GLenum pathNameType,
2387 const void *paths,
2388 GLuint pathBase,
2389 GLenum coverMode,
2390 GLenum transformType,
2391 const GLfloat *transformValues)
2392{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002393 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002394
Geoff Lang9bf86f02018-07-26 11:46:34 -04002395 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002396
2397 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2398}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002399
Sami Väisänend59ca052016-06-21 16:10:00 +03002400void Context::coverStrokePathInstanced(GLsizei numPaths,
2401 GLenum pathNameType,
2402 const void *paths,
2403 GLuint pathBase,
2404 GLenum coverMode,
2405 GLenum transformType,
2406 const GLfloat *transformValues)
2407{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002408 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002409
2410 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Lang9bf86f02018-07-26 11:46:34 -04002411 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002412
2413 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2414 transformValues);
2415}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002416
Sami Väisänend59ca052016-06-21 16:10:00 +03002417void Context::stencilFillPathInstanced(GLsizei numPaths,
2418 GLenum pathNameType,
2419 const void *paths,
2420 GLuint pathBase,
2421 GLenum fillMode,
2422 GLuint mask,
2423 GLenum transformType,
2424 const GLfloat *transformValues)
2425{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002426 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002427
2428 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Lang9bf86f02018-07-26 11:46:34 -04002429 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002430
2431 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2432 transformValues);
2433}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002434
Sami Väisänend59ca052016-06-21 16:10:00 +03002435void Context::stencilStrokePathInstanced(GLsizei numPaths,
2436 GLenum pathNameType,
2437 const void *paths,
2438 GLuint pathBase,
2439 GLint reference,
2440 GLuint mask,
2441 GLenum transformType,
2442 const GLfloat *transformValues)
2443{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002444 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002445
Geoff Lang9bf86f02018-07-26 11:46:34 -04002446 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002447
2448 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2449 transformValues);
2450}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002451
Sami Väisänend59ca052016-06-21 16:10:00 +03002452void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2453 GLenum pathNameType,
2454 const void *paths,
2455 GLuint pathBase,
2456 GLenum fillMode,
2457 GLuint mask,
2458 GLenum coverMode,
2459 GLenum transformType,
2460 const GLfloat *transformValues)
2461{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002462 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002463
Geoff Lang9bf86f02018-07-26 11:46:34 -04002464 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002465
2466 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2467 transformType, transformValues);
2468}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002469
Sami Väisänend59ca052016-06-21 16:10:00 +03002470void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2471 GLenum pathNameType,
2472 const void *paths,
2473 GLuint pathBase,
2474 GLint reference,
2475 GLuint mask,
2476 GLenum coverMode,
2477 GLenum transformType,
2478 const GLfloat *transformValues)
2479{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002480 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002481
Geoff Lang9bf86f02018-07-26 11:46:34 -04002482 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002483
2484 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2485 transformType, transformValues);
2486}
2487
Sami Väisänen46eaa942016-06-29 10:26:37 +03002488void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2489{
2490 auto *programObject = getProgram(program);
2491
2492 programObject->bindFragmentInputLocation(location, name);
2493}
2494
2495void Context::programPathFragmentInputGen(GLuint program,
2496 GLint location,
2497 GLenum genMode,
2498 GLint components,
2499 const GLfloat *coeffs)
2500{
2501 auto *programObject = getProgram(program);
2502
Jamie Madillbd044ed2017-06-05 12:59:21 -04002503 programObject->pathFragmentInputGen(this, location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002504}
2505
jchen1015015f72017-03-16 13:54:21 +08002506GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2507{
jchen10fd7c3b52017-03-21 15:36:03 +08002508 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002509 return QueryProgramResourceIndex(programObject, programInterface, name);
2510}
2511
jchen10fd7c3b52017-03-21 15:36:03 +08002512void Context::getProgramResourceName(GLuint program,
2513 GLenum programInterface,
2514 GLuint index,
2515 GLsizei bufSize,
2516 GLsizei *length,
2517 GLchar *name)
2518{
2519 const auto *programObject = getProgram(program);
2520 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2521}
2522
jchen10191381f2017-04-11 13:59:04 +08002523GLint Context::getProgramResourceLocation(GLuint program,
2524 GLenum programInterface,
2525 const GLchar *name)
2526{
2527 const auto *programObject = getProgram(program);
2528 return QueryProgramResourceLocation(programObject, programInterface, name);
2529}
2530
jchen10880683b2017-04-12 16:21:55 +08002531void Context::getProgramResourceiv(GLuint program,
2532 GLenum programInterface,
2533 GLuint index,
2534 GLsizei propCount,
2535 const GLenum *props,
2536 GLsizei bufSize,
2537 GLsizei *length,
2538 GLint *params)
2539{
2540 const auto *programObject = getProgram(program);
2541 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2542 length, params);
2543}
2544
jchen10d9cd7b72017-08-30 15:04:25 +08002545void Context::getProgramInterfaceiv(GLuint program,
2546 GLenum programInterface,
2547 GLenum pname,
2548 GLint *params)
2549{
2550 const auto *programObject = getProgram(program);
2551 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2552}
2553
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002554void Context::getProgramInterfaceivRobust(GLuint program,
2555 GLenum programInterface,
2556 GLenum pname,
2557 GLsizei bufSize,
2558 GLsizei *length,
2559 GLint *params)
2560{
2561 UNIMPLEMENTED();
2562}
2563
Jamie Madill306b6c12018-07-27 08:12:49 -04002564void Context::handleError(const Error &error) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002565{
Jamie Madill6b873dd2018-07-12 23:56:30 -04002566 mErrors.handleError(error);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002567}
2568
2569// Get one of the recorded errors and clear its flag, if any.
2570// [OpenGL ES 2.0.24] section 2.5 page 13.
2571GLenum Context::getError()
2572{
Geoff Langda5777c2014-07-11 09:52:58 -04002573 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002574 {
Geoff Langda5777c2014-07-11 09:52:58 -04002575 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002576 }
Geoff Langda5777c2014-07-11 09:52:58 -04002577 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002578 {
Jamie Madill6b873dd2018-07-12 23:56:30 -04002579 return mErrors.popError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002580 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002581}
2582
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002583// NOTE: this function should not assume that this context is current!
Jamie Madill6b873dd2018-07-12 23:56:30 -04002584void Context::markContextLost()
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002585{
2586 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002587 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002588 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002589 mContextLostForced = true;
2590 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002591 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002592}
2593
Jamie Madill427064d2018-04-13 16:20:34 -04002594bool Context::isContextLost() const
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002595{
2596 return mContextLost;
2597}
2598
Jamie Madillfa920eb2018-01-04 11:45:50 -05002599GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002600{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002601 // Even if the application doesn't want to know about resets, we want to know
2602 // as it will allow us to skip all the calls.
2603 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002604 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002605 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002606 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002607 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002608 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002609
2610 // EXT_robustness, section 2.6: If the reset notification behavior is
2611 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2612 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2613 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002614 }
2615
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002616 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2617 // status should be returned at least once, and GL_NO_ERROR should be returned
2618 // once the device has finished resetting.
2619 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002620 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002621 ASSERT(mResetStatus == GL_NO_ERROR);
2622 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002623
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002624 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002625 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002626 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002627 }
2628 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002629 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002630 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002631 // If markContextLost was used to mark the context lost then
2632 // assume that is not recoverable, and continue to report the
2633 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002634 mResetStatus = mImplementation->getResetStatus();
2635 }
Jamie Madill893ab082014-05-16 16:56:10 -04002636
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002637 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002638}
2639
2640bool Context::isResetNotificationEnabled()
2641{
2642 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2643}
2644
Corentin Walleze3b10e82015-05-20 11:06:25 -04002645const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002646{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002647 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002648}
2649
2650EGLenum Context::getClientType() const
2651{
2652 return mClientType;
2653}
2654
2655EGLenum Context::getRenderBuffer() const
2656{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002657 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2658 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002659 {
2660 return EGL_NONE;
2661 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002662
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002663 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002664 ASSERT(backAttachment != nullptr);
2665 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002666}
2667
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002668VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002669{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002670 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002671 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2672 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002673 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002674 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2675 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002676
Jamie Madill96a483b2017-06-27 16:49:21 -04002677 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002678 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002679
2680 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002681}
2682
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002683TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002684{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002685 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002686 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2687 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002688 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002689 transformFeedback =
2690 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002691 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002692 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002693 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002694
2695 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002696}
2697
2698bool Context::isVertexArrayGenerated(GLuint vertexArray)
2699{
Jamie Madill96a483b2017-06-27 16:49:21 -04002700 ASSERT(mVertexArrayMap.contains(0));
2701 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002702}
2703
2704bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2705{
Jamie Madill96a483b2017-06-27 16:49:21 -04002706 ASSERT(mTransformFeedbackMap.contains(0));
2707 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002708}
2709
Shannon Woods53a94a82014-06-24 15:20:36 -04002710void Context::detachTexture(GLuint texture)
2711{
2712 // Simple pass-through to State's detachTexture method, as textures do not require
2713 // allocation map management either here or in the resource manager at detach time.
2714 // Zero textures are held by the Context, and we don't attempt to request them from
2715 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002716 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002717}
2718
James Darpinian4d9d4832018-03-13 12:43:28 -07002719void Context::detachBuffer(Buffer *buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002720{
Yuly Novikov5807a532015-12-03 13:01:22 -05002721 // Simple pass-through to State's detachBuffer method, since
2722 // only buffer attachments to container objects that are bound to the current context
2723 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002724
Yuly Novikov5807a532015-12-03 13:01:22 -05002725 // [OpenGL ES 3.2] section 5.1.2 page 45:
2726 // Attachments to unbound container objects, such as
2727 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2728 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002729 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002730}
2731
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002732void Context::detachFramebuffer(GLuint framebuffer)
2733{
Shannon Woods53a94a82014-06-24 15:20:36 -04002734 // Framebuffer detachment is handled by Context, because 0 is a valid
2735 // Framebuffer object, and a pointer to it must be passed from Context
2736 // to State at binding time.
2737
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002738 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002739 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2740 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2741 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002742
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002743 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002744 {
2745 bindReadFramebuffer(0);
2746 }
2747
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002748 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002749 {
2750 bindDrawFramebuffer(0);
2751 }
2752}
2753
2754void Context::detachRenderbuffer(GLuint renderbuffer)
2755{
Jamie Madilla02315b2017-02-23 14:14:47 -05002756 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002757}
2758
Jamie Madill57a89722013-07-02 11:57:03 -04002759void Context::detachVertexArray(GLuint vertexArray)
2760{
Jamie Madill77a72f62015-04-14 11:18:32 -04002761 // Vertex array detachment is handled by Context, because 0 is a valid
2762 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002763 // binding time.
2764
Jamie Madill57a89722013-07-02 11:57:03 -04002765 // [OpenGL ES 3.0.2] section 2.10 page 43:
2766 // If a vertex array object that is currently bound is deleted, the binding
2767 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madill7267aa62018-04-17 15:28:21 -04002768 if (mGLState.removeVertexArrayBinding(this, vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002769 {
2770 bindVertexArray(0);
2771 }
2772}
2773
Geoff Langc8058452014-02-03 12:04:11 -05002774void Context::detachTransformFeedback(GLuint transformFeedback)
2775{
Corentin Walleza2257da2016-04-19 16:43:12 -04002776 // Transform feedback detachment is handled by Context, because 0 is a valid
2777 // transform feedback, and a pointer to it must be passed from Context to State at
2778 // binding time.
2779
2780 // The OpenGL specification doesn't mention what should happen when the currently bound
2781 // transform feedback object is deleted. Since it is a container object, we treat it like
2782 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002783 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002784 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002785 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002786 }
Geoff Langc8058452014-02-03 12:04:11 -05002787}
2788
Jamie Madilldc356042013-07-19 16:36:57 -04002789void Context::detachSampler(GLuint sampler)
2790{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002791 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002792}
2793
Yunchao Hea336b902017-08-02 16:05:21 +08002794void Context::detachProgramPipeline(GLuint pipeline)
2795{
2796 mGLState.detachProgramPipeline(this, pipeline);
2797}
2798
Jamie Madill3ef140a2017-08-26 23:11:21 -04002799void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002800{
Shaodde78e82017-05-22 14:13:27 +08002801 mGLState.setVertexAttribDivisor(this, index, divisor);
Jamie Madilldc358af2018-07-31 11:22:13 -04002802 mStateCache.updateActiveAttribsMask(this);
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04002803 mStateCache.updateVertexElementLimits(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002804}
2805
Jamie Madille29d1672013-07-19 16:36:57 -04002806void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2807{
Geoff Langc1984ed2016-10-07 12:41:00 -04002808 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002809 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002810 SetSamplerParameteri(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002811 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002812}
Jamie Madille29d1672013-07-19 16:36:57 -04002813
Geoff Langc1984ed2016-10-07 12:41:00 -04002814void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2815{
2816 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002817 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002818 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002819 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002820}
2821
Brandon Jones59770802018-04-02 13:18:42 -07002822void Context::samplerParameterivRobust(GLuint sampler,
2823 GLenum pname,
2824 GLsizei bufSize,
2825 const GLint *param)
2826{
2827 samplerParameteriv(sampler, pname, param);
2828}
2829
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002830void Context::samplerParameterIivRobust(GLuint sampler,
2831 GLenum pname,
2832 GLsizei bufSize,
2833 const GLint *param)
2834{
2835 UNIMPLEMENTED();
2836}
2837
2838void Context::samplerParameterIuivRobust(GLuint sampler,
2839 GLenum pname,
2840 GLsizei bufSize,
2841 const GLuint *param)
2842{
2843 UNIMPLEMENTED();
2844}
2845
Jamie Madille29d1672013-07-19 16:36:57 -04002846void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2847{
Geoff Langc1984ed2016-10-07 12:41:00 -04002848 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002849 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002850 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002851 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002852}
2853
Geoff Langc1984ed2016-10-07 12:41:00 -04002854void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002855{
Geoff Langc1984ed2016-10-07 12:41:00 -04002856 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002857 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002858 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002859 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002860}
2861
Brandon Jones59770802018-04-02 13:18:42 -07002862void Context::samplerParameterfvRobust(GLuint sampler,
2863 GLenum pname,
2864 GLsizei bufSize,
2865 const GLfloat *param)
2866{
2867 samplerParameterfv(sampler, pname, param);
2868}
2869
Geoff Langc1984ed2016-10-07 12:41:00 -04002870void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002871{
Geoff Langc1984ed2016-10-07 12:41:00 -04002872 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002873 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002874 QuerySamplerParameteriv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002875 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002876}
Jamie Madill9675b802013-07-19 16:36:59 -04002877
Brandon Jones59770802018-04-02 13:18:42 -07002878void Context::getSamplerParameterivRobust(GLuint sampler,
2879 GLenum pname,
2880 GLsizei bufSize,
2881 GLsizei *length,
2882 GLint *params)
2883{
2884 getSamplerParameteriv(sampler, pname, params);
2885}
2886
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002887void Context::getSamplerParameterIivRobust(GLuint sampler,
2888 GLenum pname,
2889 GLsizei bufSize,
2890 GLsizei *length,
2891 GLint *params)
2892{
2893 UNIMPLEMENTED();
2894}
2895
2896void Context::getSamplerParameterIuivRobust(GLuint sampler,
2897 GLenum pname,
2898 GLsizei bufSize,
2899 GLsizei *length,
2900 GLuint *params)
2901{
2902 UNIMPLEMENTED();
2903}
2904
Geoff Langc1984ed2016-10-07 12:41:00 -04002905void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2906{
2907 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002908 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002909 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002910 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002911}
2912
Brandon Jones59770802018-04-02 13:18:42 -07002913void Context::getSamplerParameterfvRobust(GLuint sampler,
2914 GLenum pname,
2915 GLsizei bufSize,
2916 GLsizei *length,
2917 GLfloat *params)
2918{
2919 getSamplerParameterfv(sampler, pname, params);
2920}
2921
Olli Etuahof0fee072016-03-30 15:11:58 +03002922void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2923{
2924 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002925 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002926}
2927
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002928void Context::initRendererString()
2929{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002930 std::ostringstream rendererString;
2931 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002932 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002933 rendererString << ")";
2934
Geoff Langcec35902014-04-16 10:52:36 -04002935 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002936}
2937
Geoff Langc339c4e2016-11-29 10:37:36 -05002938void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002939{
Geoff Langc339c4e2016-11-29 10:37:36 -05002940 const Version &clientVersion = getClientVersion();
2941
2942 std::ostringstream versionString;
2943 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2944 << ANGLE_VERSION_STRING << ")";
2945 mVersionString = MakeStaticString(versionString.str());
2946
2947 std::ostringstream shadingLanguageVersionString;
2948 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2949 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2950 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2951 << ")";
2952 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002953}
2954
Geoff Langcec35902014-04-16 10:52:36 -04002955void Context::initExtensionStrings()
2956{
Geoff Langc339c4e2016-11-29 10:37:36 -05002957 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2958 std::ostringstream combinedStringStream;
2959 std::copy(strings.begin(), strings.end(),
2960 std::ostream_iterator<const char *>(combinedStringStream, " "));
2961 return MakeStaticString(combinedStringStream.str());
2962 };
2963
2964 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002965 for (const auto &extensionString : mExtensions.getStrings())
2966 {
2967 mExtensionStrings.push_back(MakeStaticString(extensionString));
2968 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002969 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002970
Geoff Langc339c4e2016-11-29 10:37:36 -05002971 mRequestableExtensionStrings.clear();
2972 for (const auto &extensionInfo : GetExtensionInfoMap())
2973 {
2974 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08002975 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
Geoff Langb0f917f2017-12-05 13:41:54 -05002976 mSupportedExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002977 {
2978 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
2979 }
2980 }
2981 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002982}
2983
Geoff Langc339c4e2016-11-29 10:37:36 -05002984const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04002985{
Geoff Langc339c4e2016-11-29 10:37:36 -05002986 switch (name)
2987 {
2988 case GL_VENDOR:
2989 return reinterpret_cast<const GLubyte *>("Google Inc.");
2990
2991 case GL_RENDERER:
2992 return reinterpret_cast<const GLubyte *>(mRendererString);
2993
2994 case GL_VERSION:
2995 return reinterpret_cast<const GLubyte *>(mVersionString);
2996
2997 case GL_SHADING_LANGUAGE_VERSION:
2998 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
2999
3000 case GL_EXTENSIONS:
3001 return reinterpret_cast<const GLubyte *>(mExtensionString);
3002
3003 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
3004 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
3005
3006 default:
3007 UNREACHABLE();
3008 return nullptr;
3009 }
Geoff Langcec35902014-04-16 10:52:36 -04003010}
3011
Geoff Langc339c4e2016-11-29 10:37:36 -05003012const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04003013{
Geoff Langc339c4e2016-11-29 10:37:36 -05003014 switch (name)
3015 {
3016 case GL_EXTENSIONS:
3017 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
3018
3019 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
3020 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
3021
3022 default:
3023 UNREACHABLE();
3024 return nullptr;
3025 }
Geoff Langcec35902014-04-16 10:52:36 -04003026}
3027
3028size_t Context::getExtensionStringCount() const
3029{
3030 return mExtensionStrings.size();
3031}
3032
Geoff Lang111a99e2017-10-17 10:58:41 -04003033bool Context::isExtensionRequestable(const char *name)
3034{
3035 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3036 auto extension = extensionInfos.find(name);
3037
Geoff Lang111a99e2017-10-17 10:58:41 -04003038 return extension != extensionInfos.end() && extension->second.Requestable &&
Geoff Langb0f917f2017-12-05 13:41:54 -05003039 mSupportedExtensions.*(extension->second.ExtensionsMember);
Geoff Lang111a99e2017-10-17 10:58:41 -04003040}
3041
Geoff Langc339c4e2016-11-29 10:37:36 -05003042void Context::requestExtension(const char *name)
3043{
3044 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3045 ASSERT(extensionInfos.find(name) != extensionInfos.end());
3046 const auto &extension = extensionInfos.at(name);
3047 ASSERT(extension.Requestable);
Geoff Langb0f917f2017-12-05 13:41:54 -05003048 ASSERT(isExtensionRequestable(name));
Geoff Langc339c4e2016-11-29 10:37:36 -05003049
3050 if (mExtensions.*(extension.ExtensionsMember))
3051 {
3052 // Extension already enabled
3053 return;
3054 }
3055
3056 mExtensions.*(extension.ExtensionsMember) = true;
3057 updateCaps();
3058 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08003059
Jamie Madill2f348d22017-06-05 10:50:59 -04003060 // Release the shader compiler so it will be re-created with the requested extensions enabled.
3061 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04003062
Jamie Madill81c2e252017-09-09 23:32:46 -04003063 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
3064 // sampleable.
Jamie Madilld4442552018-02-27 22:03:47 -05003065 mState.mTextures->signalAllTexturesDirty(this);
Geoff Lang9aded172017-04-05 11:07:56 -04003066 for (auto &zeroTexture : mZeroTextures)
3067 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003068 if (zeroTexture.get() != nullptr)
3069 {
3070 zeroTexture->signalDirty(this, InitState::Initialized);
3071 }
Geoff Lang9aded172017-04-05 11:07:56 -04003072 }
3073
Jamie Madillb983a4b2018-08-01 11:34:51 -04003074 mState.mFramebuffers->invalidateFramebufferComplenessCache(this);
Geoff Langc339c4e2016-11-29 10:37:36 -05003075}
3076
3077size_t Context::getRequestableExtensionStringCount() const
3078{
3079 return mRequestableExtensionStrings.size();
3080}
3081
Jamie Madill493f9572018-05-24 19:52:15 -04003082void Context::beginTransformFeedback(PrimitiveMode primitiveMode)
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003083{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003084 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003085 ASSERT(transformFeedback != nullptr);
3086 ASSERT(!transformFeedback->isPaused());
3087
Jamie Madill6c1f6712017-02-14 19:08:04 -05003088 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003089}
3090
3091bool Context::hasActiveTransformFeedback(GLuint program) const
3092{
3093 for (auto pair : mTransformFeedbackMap)
3094 {
3095 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
3096 {
3097 return true;
3098 }
3099 }
3100 return false;
3101}
3102
Geoff Lang33f11fb2018-05-07 13:42:47 -04003103Extensions Context::generateSupportedExtensions() const
Geoff Langb0f917f2017-12-05 13:41:54 -05003104{
3105 Extensions supportedExtensions = mImplementation->getNativeExtensions();
3106
jchen1082af6202018-06-22 10:59:52 +08003107 // Explicitly enable GL_KHR_parallel_shader_compile
3108 supportedExtensions.parallelShaderCompile = true;
3109
Geoff Langb0f917f2017-12-05 13:41:54 -05003110 if (getClientVersion() < ES_2_0)
3111 {
3112 // Default extensions for GLES1
Lingfeng Yang0df813c2018-07-12 12:52:06 -07003113 supportedExtensions.pointSizeArray = true;
3114 supportedExtensions.textureCubeMap = true;
3115 supportedExtensions.pointSprite = true;
3116 supportedExtensions.drawTexture = true;
jchen1082af6202018-06-22 10:59:52 +08003117 supportedExtensions.parallelShaderCompile = false;
Geoff Langb0f917f2017-12-05 13:41:54 -05003118 }
3119
3120 if (getClientVersion() < ES_3_0)
3121 {
3122 // Disable ES3+ extensions
3123 supportedExtensions.colorBufferFloat = false;
3124 supportedExtensions.eglImageExternalEssl3 = false;
3125 supportedExtensions.textureNorm16 = false;
3126 supportedExtensions.multiview = false;
3127 supportedExtensions.maxViews = 1u;
3128 }
3129
3130 if (getClientVersion() < ES_3_1)
3131 {
3132 // Disable ES3.1+ extensions
3133 supportedExtensions.geometryShader = false;
3134 }
3135
3136 if (getClientVersion() > ES_2_0)
3137 {
3138 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
3139 // supportedExtensions.sRGB = false;
3140 }
3141
3142 // Some extensions are always available because they are implemented in the GL layer.
3143 supportedExtensions.bindUniformLocation = true;
3144 supportedExtensions.vertexArrayObject = true;
3145 supportedExtensions.bindGeneratesResource = true;
3146 supportedExtensions.clientArrays = true;
3147 supportedExtensions.requestExtension = true;
3148
3149 // Enable the no error extension if the context was created with the flag.
3150 supportedExtensions.noError = mSkipValidation;
3151
3152 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Geoff Lang33f11fb2018-05-07 13:42:47 -04003153 supportedExtensions.surfacelessContext = mSurfacelessSupported;
Geoff Langb0f917f2017-12-05 13:41:54 -05003154
3155 // Explicitly enable GL_KHR_debug
3156 supportedExtensions.debug = true;
3157 supportedExtensions.maxDebugMessageLength = 1024;
3158 supportedExtensions.maxDebugLoggedMessages = 1024;
3159 supportedExtensions.maxDebugGroupStackDepth = 1024;
3160 supportedExtensions.maxLabelLength = 1024;
3161
3162 // Explicitly enable GL_ANGLE_robust_client_memory
3163 supportedExtensions.robustClientMemory = true;
3164
3165 // Determine robust resource init availability from EGL.
Geoff Lang33f11fb2018-05-07 13:42:47 -04003166 supportedExtensions.robustResourceInitialization = mGLState.isRobustResourceInitEnabled();
Geoff Langb0f917f2017-12-05 13:41:54 -05003167
3168 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
3169 // supports it.
3170 supportedExtensions.robustBufferAccessBehavior =
3171 mRobustAccess && supportedExtensions.robustBufferAccessBehavior;
3172
3173 // Enable the cache control query unconditionally.
3174 supportedExtensions.programCacheControl = true;
3175
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003176 // Enable EGL_ANGLE_explicit_context subextensions
Geoff Lang33f11fb2018-05-07 13:42:47 -04003177 if (mExplicitContextAvailable)
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003178 {
3179 // GL_ANGLE_explicit_context_gles1
3180 supportedExtensions.explicitContextGles1 = true;
3181 // GL_ANGLE_explicit_context
3182 supportedExtensions.explicitContext = true;
3183 }
3184
Geoff Langb0f917f2017-12-05 13:41:54 -05003185 return supportedExtensions;
3186}
3187
Geoff Lang33f11fb2018-05-07 13:42:47 -04003188void Context::initCaps()
Geoff Lang493daf52014-07-03 13:38:44 -04003189{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04003190 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04003191
Geoff Lang33f11fb2018-05-07 13:42:47 -04003192 mSupportedExtensions = generateSupportedExtensions();
3193 mExtensions = mSupportedExtensions;
Lingfeng Yang01074432018-04-16 10:19:51 -07003194
3195 mLimitations = mImplementation->getNativeLimitations();
3196
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003197 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
3198 if (getClientVersion() < Version(2, 0))
3199 {
3200 mCaps.maxMultitextureUnits = 4;
3201 mCaps.maxClipPlanes = 6;
3202 mCaps.maxLights = 8;
Lingfeng Yange547aac2018-04-05 09:39:20 -07003203 mCaps.maxModelviewMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3204 mCaps.maxProjectionMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3205 mCaps.maxTextureMatrixStackDepth = Caps::GlobalMatrixStackDepth;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003206 mCaps.minSmoothPointSize = 1.0f;
3207 mCaps.maxSmoothPointSize = 1.0f;
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003208 }
3209
Luc Ferronad2ae932018-06-11 15:31:17 -04003210 // Apply/Verify implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04003211 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003212
Luc Ferronad2ae932018-06-11 15:31:17 -04003213 ASSERT(mCaps.minAliasedPointSize >= 1.0f);
3214
Jamie Madill0f80ed82017-09-19 00:24:56 -04003215 if (getClientVersion() < ES_3_1)
3216 {
3217 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
3218 }
3219 else
3220 {
3221 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
3222 }
Geoff Lang301d1612014-07-09 10:34:37 -04003223
Jiawei Shao54aafe52018-04-27 14:54:57 +08003224 LimitCap(&mCaps.maxShaderUniformBlocks[ShaderType::Vertex],
3225 IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
Jamie Madill0f80ed82017-09-19 00:24:56 -04003226 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3227 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3228
3229 // Limit textures as well, so we can use fast bitsets with texture bindings.
3230 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
Jiawei Shao54aafe52018-04-27 14:54:57 +08003231 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Vertex],
3232 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
3233 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Fragment],
3234 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04003235
Jiawei Shaodb342272017-09-27 10:21:45 +08003236 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
3237
Geoff Langc287ea62016-09-16 14:46:51 -04003238 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05003239 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04003240 for (const auto &extensionInfo : GetExtensionInfoMap())
3241 {
Geoff Lang0ab41fa2018-03-14 11:03:30 -04003242 // If the user has requested that extensions start disabled and they are requestable,
3243 // disable them.
3244 if (!mExtensionsEnabled && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04003245 {
3246 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
3247 }
3248 }
3249
3250 // Generate texture caps
3251 updateCaps();
3252}
3253
3254void Context::updateCaps()
3255{
Geoff Lang900013c2014-07-07 11:32:19 -04003256 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04003257 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04003258
Jamie Madill7b62cf92017-11-02 15:20:49 -04003259 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04003260 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04003261 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04003262 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003263
Geoff Lang0d8b7242015-09-09 14:56:53 -04003264 // Update the format caps based on the client version and extensions.
3265 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
3266 // ES3.
3267 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003268 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04003269 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003270 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Yuly Novikovf15f8862018-06-04 18:59:41 -04003271 formatCaps.textureAttachment =
3272 formatCaps.textureAttachment &&
3273 formatInfo.textureAttachmentSupport(getClientVersion(), mExtensions);
3274 formatCaps.renderbuffer = formatCaps.renderbuffer &&
3275 formatInfo.renderbufferSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04003276
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003277 // OpenGL ES does not support multisampling with non-rendererable formats
3278 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Yuly Novikovf15f8862018-06-04 18:59:41 -04003279 if (!formatCaps.renderbuffer ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003280 (getClientVersion() < ES_3_1 &&
3281 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04003282 {
Geoff Langd87878e2014-09-19 15:42:59 -04003283 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04003284 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03003285 else
3286 {
3287 // We may have limited the max samples for some required renderbuffer formats due to
3288 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
3289 GLuint formatMaxSamples = formatCaps.getMaxSamples();
3290
3291 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
3292 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
3293 // exception of signed and unsigned integer formats."
3294 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
3295 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
3296 {
3297 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
3298 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
3299 }
3300
3301 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
3302 if (getClientVersion() >= ES_3_1)
3303 {
3304 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
3305 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
3306 // the exception that the signed and unsigned integer formats are required only to
3307 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
3308 // multisamples, which must be at least one."
3309 if (formatInfo.componentType == GL_INT ||
3310 formatInfo.componentType == GL_UNSIGNED_INT)
3311 {
3312 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
3313 }
3314
3315 // GLES 3.1 section 19.3.1.
3316 if (formatCaps.texturable)
3317 {
3318 if (formatInfo.depthBits > 0)
3319 {
3320 mCaps.maxDepthTextureSamples =
3321 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
3322 }
3323 else if (formatInfo.redBits > 0)
3324 {
3325 mCaps.maxColorTextureSamples =
3326 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
3327 }
3328 }
3329 }
3330 }
Geoff Langd87878e2014-09-19 15:42:59 -04003331
3332 if (formatCaps.texturable && formatInfo.compressed)
3333 {
Geoff Langca271392017-04-05 12:30:00 -04003334 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003335 }
3336
Geoff Langca271392017-04-05 12:30:00 -04003337 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04003338 }
Jamie Madill32447362017-06-28 14:53:52 -04003339
3340 // If program binary is disabled, blank out the memory cache pointer.
Geoff Langb0f917f2017-12-05 13:41:54 -05003341 if (!mSupportedExtensions.getProgramBinary)
Jamie Madill32447362017-06-28 14:53:52 -04003342 {
3343 mMemoryProgramCache = nullptr;
3344 }
Corentin Walleze4477002017-12-01 14:39:58 -05003345
3346 // Compute which buffer types are allowed
3347 mValidBufferBindings.reset();
3348 mValidBufferBindings.set(BufferBinding::ElementArray);
3349 mValidBufferBindings.set(BufferBinding::Array);
3350
3351 if (mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
3352 {
3353 mValidBufferBindings.set(BufferBinding::PixelPack);
3354 mValidBufferBindings.set(BufferBinding::PixelUnpack);
3355 }
3356
3357 if (getClientVersion() >= ES_3_0)
3358 {
3359 mValidBufferBindings.set(BufferBinding::CopyRead);
3360 mValidBufferBindings.set(BufferBinding::CopyWrite);
3361 mValidBufferBindings.set(BufferBinding::TransformFeedback);
3362 mValidBufferBindings.set(BufferBinding::Uniform);
3363 }
3364
3365 if (getClientVersion() >= ES_3_1)
3366 {
3367 mValidBufferBindings.set(BufferBinding::AtomicCounter);
3368 mValidBufferBindings.set(BufferBinding::ShaderStorage);
3369 mValidBufferBindings.set(BufferBinding::DrawIndirect);
3370 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
3371 }
Geoff Lang493daf52014-07-03 13:38:44 -04003372}
3373
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003374void Context::initWorkarounds()
3375{
Jamie Madill761b02c2017-06-23 16:27:06 -04003376 // Apply back-end workarounds.
3377 mImplementation->applyNativeWorkarounds(&mWorkarounds);
3378
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003379 // Lose the context upon out of memory error if the application is
3380 // expecting to watch for those events.
3381 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
3382}
3383
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06003384// Return true if the draw is a no-op, else return false.
3385// A no-op draw occurs if the count of vertices is less than the minimum required to
3386// have a valid primitive for this mode (0 for points, 0-1 for lines, 0-2 for tris).
3387bool Context::noopDraw(PrimitiveMode mode, GLsizei count)
3388{
3389 return count < kMinimumPrimitiveCounts[mode];
3390}
3391
3392bool Context::noopDrawInstanced(PrimitiveMode mode, GLsizei count, GLsizei instanceCount)
3393{
3394 return (instanceCount == 0) || noopDraw(mode, count);
3395}
3396
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003397Error Context::prepareForDraw(PrimitiveMode mode)
Jamie Madill05b35b22017-10-03 09:01:44 -04003398{
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003399 if (mGLES1Renderer)
3400 {
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003401 ANGLE_TRY(mGLES1Renderer->prepareForDraw(mode, this, &mGLState));
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003402 }
3403
Geoff Lang9bf86f02018-07-26 11:46:34 -04003404 ANGLE_TRY(syncDirtyObjects(mDrawDirtyObjects));
Jamie Madilla59fc192017-11-02 12:57:58 -04003405
3406 if (isRobustResourceInitEnabled())
3407 {
3408 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
3409 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
3410 }
3411
Geoff Langa8cb2872018-03-09 16:09:40 -05003412 ANGLE_TRY(syncDirtyBits());
Geoff Langd4fff502017-09-22 11:28:28 -04003413 return NoError();
3414}
3415
3416Error Context::prepareForClear(GLbitfield mask)
3417{
Geoff Langa8cb2872018-03-09 16:09:40 -05003418 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003419 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearAttachmentsInitialized(this, mask));
Geoff Langa8cb2872018-03-09 16:09:40 -05003420 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04003421 return NoError();
3422}
3423
3424Error Context::prepareForClearBuffer(GLenum buffer, GLint drawbuffer)
3425{
Geoff Langa8cb2872018-03-09 16:09:40 -05003426 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003427 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearBufferAttachmentsInitialized(this, buffer,
3428 drawbuffer));
Geoff Langa8cb2872018-03-09 16:09:40 -05003429 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill05b35b22017-10-03 09:01:44 -04003430 return NoError();
3431}
3432
Geoff Langa8cb2872018-03-09 16:09:40 -05003433Error Context::syncState(const State::DirtyBits &bitMask, const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04003434{
Geoff Langa8cb2872018-03-09 16:09:40 -05003435 ANGLE_TRY(syncDirtyObjects(objectMask));
3436 ANGLE_TRY(syncDirtyBits(bitMask));
Geoff Langd4fff502017-09-22 11:28:28 -04003437 return NoError();
3438}
3439
Geoff Langa8cb2872018-03-09 16:09:40 -05003440Error Context::syncDirtyBits()
Geoff Langd4fff502017-09-22 11:28:28 -04003441{
3442 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
Jamie Madill189ad872018-07-09 13:32:37 -04003443 ANGLE_TRY(mImplementation->syncState(this, dirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04003444 mGLState.clearDirtyBits();
3445 return NoError();
3446}
3447
Geoff Langa8cb2872018-03-09 16:09:40 -05003448Error Context::syncDirtyBits(const State::DirtyBits &bitMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003449{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003450 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madill189ad872018-07-09 13:32:37 -04003451 ANGLE_TRY(mImplementation->syncState(this, dirtyBits));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003452 mGLState.clearDirtyBits(dirtyBits);
Jamie Madillbc918e72018-03-08 09:47:21 -05003453 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003454}
Jamie Madillc29968b2016-01-20 11:17:23 -05003455
Geoff Langa8cb2872018-03-09 16:09:40 -05003456Error Context::syncDirtyObjects(const State::DirtyObjects &objectMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003457{
3458 return mGLState.syncDirtyObjects(this, objectMask);
3459}
3460
Jamie Madillc29968b2016-01-20 11:17:23 -05003461void Context::blitFramebuffer(GLint srcX0,
3462 GLint srcY0,
3463 GLint srcX1,
3464 GLint srcY1,
3465 GLint dstX0,
3466 GLint dstY0,
3467 GLint dstX1,
3468 GLint dstY1,
3469 GLbitfield mask,
3470 GLenum filter)
3471{
Qin Jiajiaaef92162018-02-27 13:51:44 +08003472 if (mask == 0)
3473 {
3474 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
3475 // buffers are copied.
3476 return;
3477 }
3478
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003479 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003480 ASSERT(drawFramebuffer);
3481
3482 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
3483 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
3484
Jamie Madillbc918e72018-03-08 09:47:21 -05003485 ANGLE_CONTEXT_TRY(syncStateForBlit());
Jamie Madillc29968b2016-01-20 11:17:23 -05003486
Jamie Madillc564c072017-06-01 12:45:42 -04003487 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003488}
Jamie Madillc29968b2016-01-20 11:17:23 -05003489
3490void Context::clear(GLbitfield mask)
3491{
Geoff Langd4fff502017-09-22 11:28:28 -04003492 ANGLE_CONTEXT_TRY(prepareForClear(mask));
3493 ANGLE_CONTEXT_TRY(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05003494}
3495
3496void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
3497{
Geoff Langd4fff502017-09-22 11:28:28 -04003498 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3499 ANGLE_CONTEXT_TRY(
3500 mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003501}
3502
3503void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3504{
Geoff Langd4fff502017-09-22 11:28:28 -04003505 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3506 ANGLE_CONTEXT_TRY(
3507 mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003508}
3509
3510void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3511{
Geoff Langd4fff502017-09-22 11:28:28 -04003512 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3513 ANGLE_CONTEXT_TRY(
3514 mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003515}
3516
3517void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3518{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003519 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003520 ASSERT(framebufferObject);
3521
3522 // If a buffer is not present, the clear has no effect
3523 if (framebufferObject->getDepthbuffer() == nullptr &&
3524 framebufferObject->getStencilbuffer() == nullptr)
3525 {
3526 return;
3527 }
3528
Geoff Langd4fff502017-09-22 11:28:28 -04003529 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3530 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003531}
3532
3533void Context::readPixels(GLint x,
3534 GLint y,
3535 GLsizei width,
3536 GLsizei height,
3537 GLenum format,
3538 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003539 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003540{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003541 if (width == 0 || height == 0)
3542 {
3543 return;
3544 }
3545
Jamie Madillbc918e72018-03-08 09:47:21 -05003546 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003547
Jamie Madillb6664922017-07-25 12:55:04 -04003548 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3549 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003550
3551 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04003552 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003553}
3554
Brandon Jones59770802018-04-02 13:18:42 -07003555void Context::readPixelsRobust(GLint x,
3556 GLint y,
3557 GLsizei width,
3558 GLsizei height,
3559 GLenum format,
3560 GLenum type,
3561 GLsizei bufSize,
3562 GLsizei *length,
3563 GLsizei *columns,
3564 GLsizei *rows,
3565 void *pixels)
3566{
3567 readPixels(x, y, width, height, format, type, pixels);
3568}
3569
3570void Context::readnPixelsRobust(GLint x,
3571 GLint y,
3572 GLsizei width,
3573 GLsizei height,
3574 GLenum format,
3575 GLenum type,
3576 GLsizei bufSize,
3577 GLsizei *length,
3578 GLsizei *columns,
3579 GLsizei *rows,
3580 void *data)
3581{
3582 readPixels(x, y, width, height, format, type, data);
3583}
3584
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003585void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003586 GLint level,
3587 GLenum internalformat,
3588 GLint x,
3589 GLint y,
3590 GLsizei width,
3591 GLsizei height,
3592 GLint border)
3593{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003594 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003595 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003596
Jamie Madillc29968b2016-01-20 11:17:23 -05003597 Rectangle sourceArea(x, y, width, height);
3598
Jamie Madill05b35b22017-10-03 09:01:44 -04003599 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003600 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003601 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003602}
3603
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003604void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003605 GLint level,
3606 GLint xoffset,
3607 GLint yoffset,
3608 GLint x,
3609 GLint y,
3610 GLsizei width,
3611 GLsizei height)
3612{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003613 if (width == 0 || height == 0)
3614 {
3615 return;
3616 }
3617
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003618 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003619 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003620
Jamie Madillc29968b2016-01-20 11:17:23 -05003621 Offset destOffset(xoffset, yoffset, 0);
3622 Rectangle sourceArea(x, y, width, height);
3623
Jamie Madill05b35b22017-10-03 09:01:44 -04003624 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003625 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003626 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003627}
3628
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003629void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003630 GLint level,
3631 GLint xoffset,
3632 GLint yoffset,
3633 GLint zoffset,
3634 GLint x,
3635 GLint y,
3636 GLsizei width,
3637 GLsizei height)
3638{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003639 if (width == 0 || height == 0)
3640 {
3641 return;
3642 }
3643
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003644 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003645 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003646
Jamie Madillc29968b2016-01-20 11:17:23 -05003647 Offset destOffset(xoffset, yoffset, zoffset);
3648 Rectangle sourceArea(x, y, width, height);
3649
Jamie Madill05b35b22017-10-03 09:01:44 -04003650 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3651 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003652 handleError(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level, destOffset,
3653 sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003654}
3655
3656void Context::framebufferTexture2D(GLenum target,
3657 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003658 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003659 GLuint texture,
3660 GLint level)
3661{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003662 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003663 ASSERT(framebuffer);
3664
3665 if (texture != 0)
3666 {
3667 Texture *textureObj = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003668 ImageIndex index = ImageIndex::MakeFromTarget(textarget, level);
Jamie Madilla02315b2017-02-23 14:14:47 -05003669 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003670 }
3671 else
3672 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003673 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003674 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003675
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003676 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003677}
3678
3679void Context::framebufferRenderbuffer(GLenum target,
3680 GLenum attachment,
3681 GLenum renderbuffertarget,
3682 GLuint renderbuffer)
3683{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003684 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003685 ASSERT(framebuffer);
3686
3687 if (renderbuffer != 0)
3688 {
3689 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003690
Jamie Madillcc129372018-04-12 09:13:18 -04003691 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003692 renderbufferObject);
3693 }
3694 else
3695 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003696 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003697 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003698
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003699 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003700}
3701
3702void Context::framebufferTextureLayer(GLenum target,
3703 GLenum attachment,
3704 GLuint texture,
3705 GLint level,
3706 GLint layer)
3707{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003708 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003709 ASSERT(framebuffer);
3710
3711 if (texture != 0)
3712 {
3713 Texture *textureObject = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003714 ImageIndex index = ImageIndex::MakeFromType(textureObject->getType(), level, layer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003715 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003716 }
3717 else
3718 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003719 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003720 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003721
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003722 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003723}
3724
Brandon Jones59770802018-04-02 13:18:42 -07003725void Context::framebufferTextureMultiviewLayered(GLenum target,
3726 GLenum attachment,
3727 GLuint texture,
3728 GLint level,
3729 GLint baseViewIndex,
3730 GLsizei numViews)
Martin Radev137032d2017-07-13 10:11:12 +03003731{
Martin Radev82ef7742017-08-08 17:44:58 +03003732 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3733 ASSERT(framebuffer);
3734
3735 if (texture != 0)
3736 {
3737 Texture *textureObj = getTexture(texture);
3738
Martin Radev18b75ba2017-08-15 15:50:40 +03003739 ImageIndex index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
Martin Radev82ef7742017-08-08 17:44:58 +03003740 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3741 numViews, baseViewIndex);
3742 }
3743 else
3744 {
3745 framebuffer->resetAttachment(this, attachment);
3746 }
3747
3748 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003749}
3750
Brandon Jones59770802018-04-02 13:18:42 -07003751void Context::framebufferTextureMultiviewSideBySide(GLenum target,
3752 GLenum attachment,
3753 GLuint texture,
3754 GLint level,
3755 GLsizei numViews,
3756 const GLint *viewportOffsets)
Martin Radev137032d2017-07-13 10:11:12 +03003757{
Martin Radev5dae57b2017-07-14 16:15:55 +03003758 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3759 ASSERT(framebuffer);
3760
3761 if (texture != 0)
3762 {
3763 Texture *textureObj = getTexture(texture);
3764
3765 ImageIndex index = ImageIndex::Make2D(level);
3766 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3767 textureObj, numViews, viewportOffsets);
3768 }
3769 else
3770 {
3771 framebuffer->resetAttachment(this, attachment);
3772 }
3773
3774 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003775}
3776
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003777void Context::framebufferTexture(GLenum target, GLenum attachment, GLuint texture, GLint level)
3778{
Jiawei Shaoa8802472018-05-28 11:17:47 +08003779 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3780 ASSERT(framebuffer);
3781
3782 if (texture != 0)
3783 {
3784 Texture *textureObj = getTexture(texture);
3785
3786 ImageIndex index = ImageIndex::MakeFromType(
3787 textureObj->getType(), level, ImageIndex::kEntireLevel, ImageIndex::kEntireLevel);
3788 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
3789 }
3790 else
3791 {
3792 framebuffer->resetAttachment(this, attachment);
3793 }
3794
3795 mGLState.setObjectDirty(target);
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003796}
3797
Jamie Madillc29968b2016-01-20 11:17:23 -05003798void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3799{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003800 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003801 ASSERT(framebuffer);
3802 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003803 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003804}
3805
3806void Context::readBuffer(GLenum mode)
3807{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003808 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003809 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003810 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003811}
3812
3813void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3814{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003815 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003816 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003817
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003818 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003819 ASSERT(framebuffer);
3820
3821 // The specification isn't clear what should be done when the framebuffer isn't complete.
3822 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003823 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003824}
3825
3826void Context::invalidateFramebuffer(GLenum target,
3827 GLsizei numAttachments,
3828 const GLenum *attachments)
3829{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003830 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003831 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003832
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003833 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003834 ASSERT(framebuffer);
3835
Jamie Madill427064d2018-04-13 16:20:34 -04003836 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003837 {
Jamie Madill437fa652016-05-03 15:13:24 -04003838 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003839 }
Jamie Madill437fa652016-05-03 15:13:24 -04003840
Jamie Madill4928b7c2017-06-20 12:57:39 -04003841 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003842}
3843
3844void Context::invalidateSubFramebuffer(GLenum target,
3845 GLsizei numAttachments,
3846 const GLenum *attachments,
3847 GLint x,
3848 GLint y,
3849 GLsizei width,
3850 GLsizei height)
3851{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003852 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003853 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003854
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003855 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003856 ASSERT(framebuffer);
3857
Jamie Madill427064d2018-04-13 16:20:34 -04003858 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003859 {
Jamie Madill437fa652016-05-03 15:13:24 -04003860 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003861 }
Jamie Madill437fa652016-05-03 15:13:24 -04003862
3863 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003864 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003865}
3866
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003867void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003868 GLint level,
3869 GLint internalformat,
3870 GLsizei width,
3871 GLsizei height,
3872 GLint border,
3873 GLenum format,
3874 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003875 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003876{
Jamie Madillbc918e72018-03-08 09:47:21 -05003877 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003878
3879 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003880 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003881 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003882 size, format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003883}
3884
Brandon Jones59770802018-04-02 13:18:42 -07003885void Context::texImage2DRobust(TextureTarget target,
3886 GLint level,
3887 GLint internalformat,
3888 GLsizei width,
3889 GLsizei height,
3890 GLint border,
3891 GLenum format,
3892 GLenum type,
3893 GLsizei bufSize,
3894 const void *pixels)
3895{
3896 texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
3897}
3898
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003899void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003900 GLint level,
3901 GLint internalformat,
3902 GLsizei width,
3903 GLsizei height,
3904 GLsizei depth,
3905 GLint border,
3906 GLenum format,
3907 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003908 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003909{
Jamie Madillbc918e72018-03-08 09:47:21 -05003910 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003911
3912 Extents size(width, height, depth);
3913 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003914 handleError(texture->setImage(this, mGLState.getUnpackState(),
3915 NonCubeTextureTypeToTarget(target), level, internalformat, size,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003916 format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003917}
3918
Brandon Jones59770802018-04-02 13:18:42 -07003919void Context::texImage3DRobust(TextureType target,
3920 GLint level,
3921 GLint internalformat,
3922 GLsizei width,
3923 GLsizei height,
3924 GLsizei depth,
3925 GLint border,
3926 GLenum format,
3927 GLenum type,
3928 GLsizei bufSize,
3929 const void *pixels)
3930{
3931 texImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels);
3932}
3933
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003934void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003935 GLint level,
3936 GLint xoffset,
3937 GLint yoffset,
3938 GLsizei width,
3939 GLsizei height,
3940 GLenum format,
3941 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003942 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003943{
3944 // Zero sized uploads are valid but no-ops
3945 if (width == 0 || height == 0)
3946 {
3947 return;
3948 }
3949
Jamie Madillbc918e72018-03-08 09:47:21 -05003950 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003951
3952 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003953 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003954 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003955 type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003956}
3957
Brandon Jones59770802018-04-02 13:18:42 -07003958void Context::texSubImage2DRobust(TextureTarget target,
3959 GLint level,
3960 GLint xoffset,
3961 GLint yoffset,
3962 GLsizei width,
3963 GLsizei height,
3964 GLenum format,
3965 GLenum type,
3966 GLsizei bufSize,
3967 const void *pixels)
3968{
3969 texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
3970}
3971
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003972void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003973 GLint level,
3974 GLint xoffset,
3975 GLint yoffset,
3976 GLint zoffset,
3977 GLsizei width,
3978 GLsizei height,
3979 GLsizei depth,
3980 GLenum format,
3981 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003982 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003983{
3984 // Zero sized uploads are valid but no-ops
3985 if (width == 0 || height == 0 || depth == 0)
3986 {
3987 return;
3988 }
3989
Jamie Madillbc918e72018-03-08 09:47:21 -05003990 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003991
3992 Box area(xoffset, yoffset, zoffset, width, height, depth);
3993 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003994 handleError(texture->setSubImage(this, mGLState.getUnpackState(),
3995 NonCubeTextureTypeToTarget(target), level, area, format, type,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003996 static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003997}
3998
Brandon Jones59770802018-04-02 13:18:42 -07003999void Context::texSubImage3DRobust(TextureType target,
4000 GLint level,
4001 GLint xoffset,
4002 GLint yoffset,
4003 GLint zoffset,
4004 GLsizei width,
4005 GLsizei height,
4006 GLsizei depth,
4007 GLenum format,
4008 GLenum type,
4009 GLsizei bufSize,
4010 const void *pixels)
4011{
4012 texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type,
4013 pixels);
4014}
4015
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004016void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004017 GLint level,
4018 GLenum internalformat,
4019 GLsizei width,
4020 GLsizei height,
4021 GLint border,
4022 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004023 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004024{
Jamie Madillbc918e72018-03-08 09:47:21 -05004025 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004026
4027 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004028 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05004029 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
4030 internalformat, size, imageSize,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004031 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004032}
4033
Brandon Jones59770802018-04-02 13:18:42 -07004034void Context::compressedTexImage2DRobust(TextureTarget target,
4035 GLint level,
4036 GLenum internalformat,
4037 GLsizei width,
4038 GLsizei height,
4039 GLint border,
4040 GLsizei imageSize,
4041 GLsizei dataSize,
4042 const GLvoid *data)
4043{
4044 compressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
4045}
4046
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004047void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004048 GLint level,
4049 GLenum internalformat,
4050 GLsizei width,
4051 GLsizei height,
4052 GLsizei depth,
4053 GLint border,
4054 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004055 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004056{
Jamie Madillbc918e72018-03-08 09:47:21 -05004057 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004058
4059 Extents size(width, height, depth);
4060 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004061 handleError(texture->setCompressedImage(
4062 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004063 size, imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004064}
4065
Brandon Jones59770802018-04-02 13:18:42 -07004066void Context::compressedTexImage3DRobust(TextureType target,
4067 GLint level,
4068 GLenum internalformat,
4069 GLsizei width,
4070 GLsizei height,
4071 GLsizei depth,
4072 GLint border,
4073 GLsizei imageSize,
4074 GLsizei dataSize,
4075 const GLvoid *data)
4076{
4077 compressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize,
4078 data);
4079}
4080
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004081void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004082 GLint level,
4083 GLint xoffset,
4084 GLint yoffset,
4085 GLsizei width,
4086 GLsizei height,
4087 GLenum format,
4088 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004089 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004090{
Jamie Madillbc918e72018-03-08 09:47:21 -05004091 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004092
4093 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004094 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05004095 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
4096 format, imageSize,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004097 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004098}
4099
Brandon Jones59770802018-04-02 13:18:42 -07004100void Context::compressedTexSubImage2DRobust(TextureTarget target,
4101 GLint level,
4102 GLint xoffset,
4103 GLint yoffset,
4104 GLsizei width,
4105 GLsizei height,
4106 GLenum format,
4107 GLsizei imageSize,
4108 GLsizei dataSize,
4109 const GLvoid *data)
4110{
4111 compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize,
4112 data);
4113}
4114
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004115void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004116 GLint level,
4117 GLint xoffset,
4118 GLint yoffset,
4119 GLint zoffset,
4120 GLsizei width,
4121 GLsizei height,
4122 GLsizei depth,
4123 GLenum format,
4124 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004125 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004126{
4127 // Zero sized uploads are valid but no-ops
4128 if (width == 0 || height == 0)
4129 {
4130 return;
4131 }
4132
Jamie Madillbc918e72018-03-08 09:47:21 -05004133 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004134
4135 Box area(xoffset, yoffset, zoffset, width, height, depth);
4136 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004137 handleError(texture->setCompressedSubImage(
4138 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004139 imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004140}
4141
Brandon Jones59770802018-04-02 13:18:42 -07004142void Context::compressedTexSubImage3DRobust(TextureType target,
4143 GLint level,
4144 GLint xoffset,
4145 GLint yoffset,
4146 GLint zoffset,
4147 GLsizei width,
4148 GLsizei height,
4149 GLsizei depth,
4150 GLenum format,
4151 GLsizei imageSize,
4152 GLsizei dataSize,
4153 const GLvoid *data)
4154{
4155 compressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format,
4156 imageSize, data);
4157}
4158
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004159void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004160{
4161 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05004162 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004163}
4164
Jamie Madill007530e2017-12-28 14:27:04 -05004165void Context::copyTexture(GLuint sourceId,
4166 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004167 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004168 GLuint destId,
4169 GLint destLevel,
4170 GLint internalFormat,
4171 GLenum destType,
4172 GLboolean unpackFlipY,
4173 GLboolean unpackPremultiplyAlpha,
4174 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004175{
Jamie Madillbc918e72018-03-08 09:47:21 -05004176 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004177
4178 gl::Texture *sourceTexture = getTexture(sourceId);
4179 gl::Texture *destTexture = getTexture(destId);
Geoff Lang92019432017-11-20 13:09:34 -05004180 handleError(destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType,
4181 sourceLevel, ConvertToBool(unpackFlipY),
4182 ConvertToBool(unpackPremultiplyAlpha),
4183 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004184}
4185
Jamie Madill007530e2017-12-28 14:27:04 -05004186void Context::copySubTexture(GLuint sourceId,
4187 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004188 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004189 GLuint destId,
4190 GLint destLevel,
4191 GLint xoffset,
4192 GLint yoffset,
4193 GLint x,
4194 GLint y,
4195 GLsizei width,
4196 GLsizei height,
4197 GLboolean unpackFlipY,
4198 GLboolean unpackPremultiplyAlpha,
4199 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004200{
4201 // Zero sized copies are valid but no-ops
4202 if (width == 0 || height == 0)
4203 {
4204 return;
4205 }
4206
Jamie Madillbc918e72018-03-08 09:47:21 -05004207 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004208
4209 gl::Texture *sourceTexture = getTexture(sourceId);
4210 gl::Texture *destTexture = getTexture(destId);
4211 Offset offset(xoffset, yoffset, 0);
4212 Rectangle area(x, y, width, height);
Geoff Lang92019432017-11-20 13:09:34 -05004213 handleError(destTexture->copySubTexture(this, destTarget, destLevel, offset, sourceLevel, area,
4214 ConvertToBool(unpackFlipY),
4215 ConvertToBool(unpackPremultiplyAlpha),
4216 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004217}
4218
Jamie Madill007530e2017-12-28 14:27:04 -05004219void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07004220{
Jamie Madillbc918e72018-03-08 09:47:21 -05004221 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07004222
4223 gl::Texture *sourceTexture = getTexture(sourceId);
4224 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05004225 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07004226}
4227
Corentin Wallez336129f2017-10-17 15:55:40 -04004228void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03004229{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004230 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004231 ASSERT(buffer);
4232
Geoff Lang496c02d2016-10-20 11:38:11 -07004233 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03004234}
4235
Brandon Jones59770802018-04-02 13:18:42 -07004236void Context::getBufferPointervRobust(BufferBinding target,
4237 GLenum pname,
4238 GLsizei bufSize,
4239 GLsizei *length,
4240 void **params)
4241{
4242 getBufferPointerv(target, pname, params);
4243}
4244
Corentin Wallez336129f2017-10-17 15:55:40 -04004245void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004246{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004247 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004248 ASSERT(buffer);
4249
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004250 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004251 if (error.isError())
4252 {
Jamie Madill437fa652016-05-03 15:13:24 -04004253 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004254 return nullptr;
4255 }
4256
4257 return buffer->getMapPointer();
4258}
4259
Corentin Wallez336129f2017-10-17 15:55:40 -04004260GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03004261{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004262 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004263 ASSERT(buffer);
4264
4265 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004266 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03004267 if (error.isError())
4268 {
Jamie Madill437fa652016-05-03 15:13:24 -04004269 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004270 return GL_FALSE;
4271 }
4272
4273 return result;
4274}
4275
Corentin Wallez336129f2017-10-17 15:55:40 -04004276void *Context::mapBufferRange(BufferBinding target,
4277 GLintptr offset,
4278 GLsizeiptr length,
4279 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004280{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004281 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004282 ASSERT(buffer);
4283
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004284 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004285 if (error.isError())
4286 {
Jamie Madill437fa652016-05-03 15:13:24 -04004287 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004288 return nullptr;
4289 }
4290
4291 return buffer->getMapPointer();
4292}
4293
Corentin Wallez336129f2017-10-17 15:55:40 -04004294void Context::flushMappedBufferRange(BufferBinding /*target*/,
4295 GLintptr /*offset*/,
4296 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03004297{
4298 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
4299}
4300
Jamie Madillbc918e72018-03-08 09:47:21 -05004301Error Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004302{
Geoff Langa8cb2872018-03-09 16:09:40 -05004303 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004304}
4305
Jamie Madillbc918e72018-03-08 09:47:21 -05004306Error Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004307{
Geoff Langa8cb2872018-03-09 16:09:40 -05004308 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004309}
4310
Jamie Madillbc918e72018-03-08 09:47:21 -05004311Error Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004312{
Geoff Langa8cb2872018-03-09 16:09:40 -05004313 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004314}
4315
Geoff Lang9bf86f02018-07-26 11:46:34 -04004316Error Context::syncStateForPathOperation()
4317{
4318 ANGLE_TRY(syncDirtyObjects(mPathOperationDirtyObjects));
4319
4320 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
4321 ANGLE_TRY(syncDirtyBits());
4322
4323 return NoError();
4324}
4325
Jiajia Qin5451d532017-11-16 17:16:34 +08004326void Context::activeShaderProgram(GLuint pipeline, GLuint program)
4327{
4328 UNIMPLEMENTED();
4329}
4330
Jamie Madillc20ab272016-06-09 07:20:46 -07004331void Context::activeTexture(GLenum texture)
4332{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004333 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004334}
4335
Jamie Madill876429b2017-04-20 15:46:24 -04004336void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004337{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004338 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004339}
4340
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004341void Context::blendEquation(GLenum mode)
4342{
4343 mGLState.setBlendEquation(mode, mode);
4344}
4345
Jamie Madillc20ab272016-06-09 07:20:46 -07004346void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
4347{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004348 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004349}
4350
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004351void Context::blendFunc(GLenum sfactor, GLenum dfactor)
4352{
4353 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
4354}
4355
Jamie Madillc20ab272016-06-09 07:20:46 -07004356void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
4357{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004358 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004359}
4360
Jamie Madill876429b2017-04-20 15:46:24 -04004361void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004362{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004363 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004364}
4365
Jamie Madill876429b2017-04-20 15:46:24 -04004366void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07004367{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004368 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07004369}
4370
4371void Context::clearStencil(GLint s)
4372{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004373 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07004374}
4375
4376void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
4377{
Geoff Lang92019432017-11-20 13:09:34 -05004378 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
4379 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004380}
4381
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004382void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07004383{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004384 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004385}
4386
4387void Context::depthFunc(GLenum func)
4388{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004389 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07004390}
4391
4392void Context::depthMask(GLboolean flag)
4393{
Geoff Lang92019432017-11-20 13:09:34 -05004394 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07004395}
4396
Jamie Madill876429b2017-04-20 15:46:24 -04004397void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07004398{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004399 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07004400}
4401
4402void Context::disable(GLenum cap)
4403{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004404 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07004405}
4406
4407void Context::disableVertexAttribArray(GLuint index)
4408{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004409 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madilldc358af2018-07-31 11:22:13 -04004410 mStateCache.updateActiveAttribsMask(this);
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04004411 mStateCache.updateVertexElementLimits(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004412}
4413
4414void Context::enable(GLenum cap)
4415{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004416 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07004417}
4418
4419void Context::enableVertexAttribArray(GLuint index)
4420{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004421 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madilldc358af2018-07-31 11:22:13 -04004422 mStateCache.updateActiveAttribsMask(this);
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04004423 mStateCache.updateVertexElementLimits(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004424}
4425
4426void Context::frontFace(GLenum mode)
4427{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004428 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004429}
4430
4431void Context::hint(GLenum target, GLenum mode)
4432{
4433 switch (target)
4434 {
4435 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004436 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004437 break;
4438
4439 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004440 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004441 break;
4442
4443 default:
4444 UNREACHABLE();
4445 return;
4446 }
4447}
4448
4449void Context::lineWidth(GLfloat width)
4450{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004451 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07004452}
4453
4454void Context::pixelStorei(GLenum pname, GLint param)
4455{
4456 switch (pname)
4457 {
4458 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004459 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004460 break;
4461
4462 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004463 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004464 break;
4465
4466 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004467 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004468 break;
4469
4470 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004471 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004472 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004473 break;
4474
4475 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03004476 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004477 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004478 break;
4479
4480 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03004481 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004482 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004483 break;
4484
4485 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004486 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004487 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004488 break;
4489
4490 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004491 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004492 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004493 break;
4494
4495 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004496 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004497 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004498 break;
4499
4500 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004501 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004502 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004503 break;
4504
4505 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004506 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004507 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004508 break;
4509
4510 default:
4511 UNREACHABLE();
4512 return;
4513 }
4514}
4515
4516void Context::polygonOffset(GLfloat factor, GLfloat units)
4517{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004518 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07004519}
4520
Jamie Madill876429b2017-04-20 15:46:24 -04004521void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07004522{
Geoff Lang92019432017-11-20 13:09:34 -05004523 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07004524}
4525
Jiawei Shaodb342272017-09-27 10:21:45 +08004526void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
4527{
4528 mGLState.setSampleMaskParams(maskNumber, mask);
4529}
4530
Jamie Madillc20ab272016-06-09 07:20:46 -07004531void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
4532{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004533 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004534}
4535
4536void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
4537{
4538 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4539 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004540 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004541 }
4542
4543 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4544 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004545 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004546 }
4547}
4548
4549void Context::stencilMaskSeparate(GLenum face, GLuint mask)
4550{
4551 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4552 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004553 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004554 }
4555
4556 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4557 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004558 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004559 }
4560}
4561
4562void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4563{
4564 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4565 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004566 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004567 }
4568
4569 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4570 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004571 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004572 }
4573}
4574
4575void Context::vertexAttrib1f(GLuint index, GLfloat x)
4576{
4577 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004578 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004579}
4580
4581void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
4582{
4583 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004584 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004585}
4586
4587void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4588{
4589 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004590 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004591}
4592
4593void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
4594{
4595 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004596 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004597}
4598
4599void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4600{
4601 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004602 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004603}
4604
4605void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
4606{
4607 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004608 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004609}
4610
4611void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4612{
4613 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004614 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004615}
4616
4617void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
4618{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004619 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07004620}
4621
4622void Context::vertexAttribPointer(GLuint index,
4623 GLint size,
4624 GLenum type,
4625 GLboolean normalized,
4626 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004627 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07004628{
Corentin Wallez336129f2017-10-17 15:55:40 -04004629 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05004630 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madilldc358af2018-07-31 11:22:13 -04004631 mStateCache.updateActiveAttribsMask(this);
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04004632 mStateCache.updateVertexElementLimits(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004633}
4634
Shao80957d92017-02-20 21:25:59 +08004635void Context::vertexAttribFormat(GLuint attribIndex,
4636 GLint size,
4637 GLenum type,
4638 GLboolean normalized,
4639 GLuint relativeOffset)
4640{
Geoff Lang92019432017-11-20 13:09:34 -05004641 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08004642 relativeOffset);
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04004643 mStateCache.updateVertexElementLimits(this);
Shao80957d92017-02-20 21:25:59 +08004644}
4645
4646void Context::vertexAttribIFormat(GLuint attribIndex,
4647 GLint size,
4648 GLenum type,
4649 GLuint relativeOffset)
4650{
4651 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04004652 mStateCache.updateVertexElementLimits(this);
Shao80957d92017-02-20 21:25:59 +08004653}
4654
4655void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4656{
Shaodde78e82017-05-22 14:13:27 +08004657 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Jamie Madilldc358af2018-07-31 11:22:13 -04004658 mStateCache.updateActiveAttribsMask(this);
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04004659 mStateCache.updateVertexElementLimits(this);
Shao80957d92017-02-20 21:25:59 +08004660}
4661
Jiajia Qin5451d532017-11-16 17:16:34 +08004662void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004663{
4664 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04004665 mStateCache.updateVertexElementLimits(this);
Shao80957d92017-02-20 21:25:59 +08004666}
4667
Jamie Madillc20ab272016-06-09 07:20:46 -07004668void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4669{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004670 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004671}
4672
4673void Context::vertexAttribIPointer(GLuint index,
4674 GLint size,
4675 GLenum type,
4676 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004677 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004678{
Corentin Wallez336129f2017-10-17 15:55:40 -04004679 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
4680 size, type, false, true, stride, pointer);
Jamie Madilldc358af2018-07-31 11:22:13 -04004681 mStateCache.updateActiveAttribsMask(this);
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04004682 mStateCache.updateVertexElementLimits(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004683}
4684
4685void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4686{
4687 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004688 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004689}
4690
4691void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4692{
4693 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004694 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004695}
4696
4697void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4698{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004699 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004700}
4701
4702void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4703{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004704 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004705}
4706
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004707void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4708{
4709 const VertexAttribCurrentValueData &currentValues =
4710 getGLState().getVertexAttribCurrentValue(index);
4711 const VertexArray *vao = getGLState().getVertexArray();
4712 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4713 currentValues, pname, params);
4714}
4715
Brandon Jones59770802018-04-02 13:18:42 -07004716void Context::getVertexAttribivRobust(GLuint index,
4717 GLenum pname,
4718 GLsizei bufSize,
4719 GLsizei *length,
4720 GLint *params)
4721{
4722 getVertexAttribiv(index, pname, params);
4723}
4724
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004725void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4726{
4727 const VertexAttribCurrentValueData &currentValues =
4728 getGLState().getVertexAttribCurrentValue(index);
4729 const VertexArray *vao = getGLState().getVertexArray();
4730 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4731 currentValues, pname, params);
4732}
4733
Brandon Jones59770802018-04-02 13:18:42 -07004734void Context::getVertexAttribfvRobust(GLuint index,
4735 GLenum pname,
4736 GLsizei bufSize,
4737 GLsizei *length,
4738 GLfloat *params)
4739{
4740 getVertexAttribfv(index, pname, params);
4741}
4742
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004743void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4744{
4745 const VertexAttribCurrentValueData &currentValues =
4746 getGLState().getVertexAttribCurrentValue(index);
4747 const VertexArray *vao = getGLState().getVertexArray();
4748 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4749 currentValues, pname, params);
4750}
4751
Brandon Jones59770802018-04-02 13:18:42 -07004752void Context::getVertexAttribIivRobust(GLuint index,
4753 GLenum pname,
4754 GLsizei bufSize,
4755 GLsizei *length,
4756 GLint *params)
4757{
4758 getVertexAttribIiv(index, pname, params);
4759}
4760
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004761void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4762{
4763 const VertexAttribCurrentValueData &currentValues =
4764 getGLState().getVertexAttribCurrentValue(index);
4765 const VertexArray *vao = getGLState().getVertexArray();
4766 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4767 currentValues, pname, params);
4768}
4769
Brandon Jones59770802018-04-02 13:18:42 -07004770void Context::getVertexAttribIuivRobust(GLuint index,
4771 GLenum pname,
4772 GLsizei bufSize,
4773 GLsizei *length,
4774 GLuint *params)
4775{
4776 getVertexAttribIuiv(index, pname, params);
4777}
4778
Jamie Madill876429b2017-04-20 15:46:24 -04004779void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004780{
4781 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
4782 QueryVertexAttribPointerv(attrib, pname, pointer);
4783}
4784
Brandon Jones59770802018-04-02 13:18:42 -07004785void Context::getVertexAttribPointervRobust(GLuint index,
4786 GLenum pname,
4787 GLsizei bufSize,
4788 GLsizei *length,
4789 void **pointer)
4790{
4791 getVertexAttribPointerv(index, pname, pointer);
4792}
4793
Jamie Madillc20ab272016-06-09 07:20:46 -07004794void Context::debugMessageControl(GLenum source,
4795 GLenum type,
4796 GLenum severity,
4797 GLsizei count,
4798 const GLuint *ids,
4799 GLboolean enabled)
4800{
4801 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004802 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05004803 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004804}
4805
4806void Context::debugMessageInsert(GLenum source,
4807 GLenum type,
4808 GLuint id,
4809 GLenum severity,
4810 GLsizei length,
4811 const GLchar *buf)
4812{
4813 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004814 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004815}
4816
4817void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4818{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004819 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004820}
4821
4822GLuint Context::getDebugMessageLog(GLuint count,
4823 GLsizei bufSize,
4824 GLenum *sources,
4825 GLenum *types,
4826 GLuint *ids,
4827 GLenum *severities,
4828 GLsizei *lengths,
4829 GLchar *messageLog)
4830{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004831 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4832 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004833}
4834
4835void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4836{
4837 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004838 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05004839 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07004840}
4841
4842void Context::popDebugGroup()
4843{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004844 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05004845 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004846}
4847
Corentin Wallez336129f2017-10-17 15:55:40 -04004848void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004849{
4850 Buffer *buffer = mGLState.getTargetBuffer(target);
4851 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004852 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004853}
4854
Corentin Wallez336129f2017-10-17 15:55:40 -04004855void Context::bufferSubData(BufferBinding target,
4856 GLintptr offset,
4857 GLsizeiptr size,
4858 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004859{
4860 if (data == nullptr)
4861 {
4862 return;
4863 }
4864
4865 Buffer *buffer = mGLState.getTargetBuffer(target);
4866 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004867 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004868}
4869
Jamie Madillef300b12016-10-07 15:12:09 -04004870void Context::attachShader(GLuint program, GLuint shader)
4871{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05004872 Program *programObject = mState.mShaderPrograms->getProgram(program);
4873 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004874 ASSERT(programObject && shaderObject);
4875 programObject->attachShader(shaderObject);
4876}
4877
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004878const Workarounds &Context::getWorkarounds() const
4879{
4880 return mWorkarounds;
4881}
4882
Corentin Wallez336129f2017-10-17 15:55:40 -04004883void Context::copyBufferSubData(BufferBinding readTarget,
4884 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04004885 GLintptr readOffset,
4886 GLintptr writeOffset,
4887 GLsizeiptr size)
4888{
4889 // if size is zero, the copy is a successful no-op
4890 if (size == 0)
4891 {
4892 return;
4893 }
4894
4895 // TODO(jmadill): cache these.
4896 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4897 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4898
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004899 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004900}
4901
Jamie Madill01a80ee2016-11-07 12:06:18 -05004902void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4903{
4904 Program *programObject = getProgram(program);
4905 // TODO(jmadill): Re-use this from the validation if possible.
4906 ASSERT(programObject);
4907 programObject->bindAttributeLocation(index, name);
4908}
4909
Corentin Wallez336129f2017-10-17 15:55:40 -04004910void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004911{
Corentin Wallez336129f2017-10-17 15:55:40 -04004912 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4913 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004914}
4915
Corentin Wallez336129f2017-10-17 15:55:40 -04004916void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08004917{
4918 bindBufferRange(target, index, buffer, 0, 0);
4919}
4920
Corentin Wallez336129f2017-10-17 15:55:40 -04004921void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08004922 GLuint index,
4923 GLuint buffer,
4924 GLintptr offset,
4925 GLsizeiptr size)
4926{
Corentin Wallez336129f2017-10-17 15:55:40 -04004927 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4928 mGLState.setIndexedBufferBinding(this, target, index, bufferObject, offset, size);
Jiajia Qin6eafb042016-12-27 17:04:07 +08004929}
4930
Jamie Madill01a80ee2016-11-07 12:06:18 -05004931void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
4932{
4933 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4934 {
4935 bindReadFramebuffer(framebuffer);
4936 }
4937
4938 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4939 {
4940 bindDrawFramebuffer(framebuffer);
4941 }
4942}
4943
4944void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4945{
4946 ASSERT(target == GL_RENDERBUFFER);
4947 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004948 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04004949 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004950}
4951
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004952void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08004953 GLsizei samples,
4954 GLenum internalformat,
4955 GLsizei width,
4956 GLsizei height,
4957 GLboolean fixedsamplelocations)
4958{
4959 Extents size(width, height, 1);
4960 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004961 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
4962 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004963}
4964
4965void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4966{
JiangYizhou5b03f472017-01-09 10:22:53 +08004967 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
4968 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillbc918e72018-03-08 09:47:21 -05004969 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
JiangYizhou5b03f472017-01-09 10:22:53 +08004970 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08004971
4972 switch (pname)
4973 {
4974 case GL_SAMPLE_POSITION:
Geoff Lang13455072018-05-09 11:24:43 -04004975 handleError(framebuffer->getSamplePosition(this, index, val));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004976 break;
4977 default:
4978 UNREACHABLE();
4979 }
4980}
4981
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07004982void Context::getMultisamplefvRobust(GLenum pname,
4983 GLuint index,
4984 GLsizei bufSize,
4985 GLsizei *length,
4986 GLfloat *val)
4987{
4988 UNIMPLEMENTED();
4989}
4990
Jamie Madille8fb6402017-02-14 17:56:40 -05004991void Context::renderbufferStorage(GLenum target,
4992 GLenum internalformat,
4993 GLsizei width,
4994 GLsizei height)
4995{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004996 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4997 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
4998
Jamie Madille8fb6402017-02-14 17:56:40 -05004999 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04005000 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05005001}
5002
5003void Context::renderbufferStorageMultisample(GLenum target,
5004 GLsizei samples,
5005 GLenum internalformat,
5006 GLsizei width,
5007 GLsizei height)
5008{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005009 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
5010 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05005011
5012 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05005013 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04005014 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05005015}
5016
Geoff Lang38f2cfb2017-04-11 15:23:08 -04005017void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
5018{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005019 const Sync *syncObject = getSync(sync);
Jamie Madilla0691b72018-07-25 10:41:22 -04005020 handleError(QuerySynciv(this, syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04005021}
5022
JiangYizhoue18e6392017-02-20 10:32:23 +08005023void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
5024{
5025 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5026 QueryFramebufferParameteriv(framebuffer, pname, params);
5027}
5028
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07005029void Context::getFramebufferParameterivRobust(GLenum target,
5030 GLenum pname,
5031 GLsizei bufSize,
5032 GLsizei *length,
5033 GLint *params)
5034{
5035 UNIMPLEMENTED();
5036}
5037
Jiajia Qin5451d532017-11-16 17:16:34 +08005038void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08005039{
5040 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillb983a4b2018-08-01 11:34:51 -04005041 SetFramebufferParameteri(this, framebuffer, pname, param);
JiangYizhoue18e6392017-02-20 10:32:23 +08005042}
5043
Jamie Madilldec86232018-07-11 09:01:18 -04005044bool Context::getScratchBuffer(size_t requstedSizeBytes,
5045 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05005046{
Jamie Madilldec86232018-07-11 09:01:18 -04005047 return mScratchBuffer.get(requstedSizeBytes, scratchBufferOut);
Jamie Madillb3f26b92017-07-19 15:07:41 -04005048}
5049
Jamie Madilldec86232018-07-11 09:01:18 -04005050bool Context::getZeroFilledBuffer(size_t requstedSizeBytes,
5051 angle::MemoryBuffer **zeroBufferOut) const
Jamie Madillb3f26b92017-07-19 15:07:41 -04005052{
Jamie Madilldec86232018-07-11 09:01:18 -04005053 return mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0);
Jamie Madille14951e2017-03-09 18:55:16 -05005054}
5055
Xinghua Cao10a4d432017-11-28 14:46:26 +08005056Error Context::prepareForDispatch()
5057{
Geoff Langa8cb2872018-03-09 16:09:40 -05005058 ANGLE_TRY(syncState(mComputeDirtyBits, mComputeDirtyObjects));
Xinghua Cao10a4d432017-11-28 14:46:26 +08005059
5060 if (isRobustResourceInitEnabled())
5061 {
5062 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
5063 }
5064
5065 return NoError();
5066}
5067
Xinghua Cao2b396592017-03-29 15:36:04 +08005068void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
5069{
5070 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
5071 {
5072 return;
5073 }
5074
Xinghua Cao10a4d432017-11-28 14:46:26 +08005075 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill71c88b32017-09-14 22:20:29 -04005076 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08005077}
5078
Jiajia Qin5451d532017-11-16 17:16:34 +08005079void Context::dispatchComputeIndirect(GLintptr indirect)
5080{
Qin Jiajia62fcf622017-11-30 16:16:12 +08005081 ANGLE_CONTEXT_TRY(prepareForDispatch());
5082 handleError(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08005083}
5084
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005085void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005086 GLsizei levels,
5087 GLenum internalFormat,
5088 GLsizei width,
5089 GLsizei height)
5090{
5091 Extents size(width, height, 1);
5092 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005093 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005094}
5095
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005096void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005097 GLsizei levels,
5098 GLenum internalFormat,
5099 GLsizei width,
5100 GLsizei height,
5101 GLsizei depth)
5102{
5103 Extents size(width, height, depth);
5104 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005105 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005106}
5107
Jiajia Qin5451d532017-11-16 17:16:34 +08005108void Context::memoryBarrier(GLbitfield barriers)
5109{
Xinghua Cao89c422a2017-11-29 18:24:20 +08005110 handleError(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005111}
5112
5113void Context::memoryBarrierByRegion(GLbitfield barriers)
5114{
Xinghua Cao89c422a2017-11-29 18:24:20 +08005115 handleError(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005116}
5117
Jamie Madillc1d770e2017-04-13 17:31:24 -04005118GLenum Context::checkFramebufferStatus(GLenum target)
5119{
5120 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5121 ASSERT(framebuffer);
Jamie Madill427064d2018-04-13 16:20:34 -04005122 return framebuffer->checkStatus(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005123}
5124
5125void Context::compileShader(GLuint shader)
5126{
5127 Shader *shaderObject = GetValidShader(this, shader);
5128 if (!shaderObject)
5129 {
5130 return;
5131 }
5132 shaderObject->compile(this);
5133}
5134
5135void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
5136{
5137 for (int i = 0; i < n; i++)
5138 {
5139 deleteBuffer(buffers[i]);
5140 }
5141}
5142
5143void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
5144{
5145 for (int i = 0; i < n; i++)
5146 {
5147 if (framebuffers[i] != 0)
5148 {
5149 deleteFramebuffer(framebuffers[i]);
5150 }
5151 }
5152}
5153
5154void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
5155{
5156 for (int i = 0; i < n; i++)
5157 {
5158 deleteRenderbuffer(renderbuffers[i]);
5159 }
5160}
5161
5162void Context::deleteTextures(GLsizei n, const GLuint *textures)
5163{
5164 for (int i = 0; i < n; i++)
5165 {
5166 if (textures[i] != 0)
5167 {
5168 deleteTexture(textures[i]);
5169 }
5170 }
5171}
5172
5173void Context::detachShader(GLuint program, GLuint shader)
5174{
5175 Program *programObject = getProgram(program);
5176 ASSERT(programObject);
5177
5178 Shader *shaderObject = getShader(shader);
5179 ASSERT(shaderObject);
5180
5181 programObject->detachShader(this, shaderObject);
5182}
5183
5184void Context::genBuffers(GLsizei n, GLuint *buffers)
5185{
5186 for (int i = 0; i < n; i++)
5187 {
5188 buffers[i] = createBuffer();
5189 }
5190}
5191
5192void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
5193{
5194 for (int i = 0; i < n; i++)
5195 {
5196 framebuffers[i] = createFramebuffer();
5197 }
5198}
5199
5200void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
5201{
5202 for (int i = 0; i < n; i++)
5203 {
5204 renderbuffers[i] = createRenderbuffer();
5205 }
5206}
5207
5208void Context::genTextures(GLsizei n, GLuint *textures)
5209{
5210 for (int i = 0; i < n; i++)
5211 {
5212 textures[i] = createTexture();
5213 }
5214}
5215
5216void Context::getActiveAttrib(GLuint program,
5217 GLuint index,
5218 GLsizei bufsize,
5219 GLsizei *length,
5220 GLint *size,
5221 GLenum *type,
5222 GLchar *name)
5223{
5224 Program *programObject = getProgram(program);
5225 ASSERT(programObject);
5226 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
5227}
5228
5229void Context::getActiveUniform(GLuint program,
5230 GLuint index,
5231 GLsizei bufsize,
5232 GLsizei *length,
5233 GLint *size,
5234 GLenum *type,
5235 GLchar *name)
5236{
5237 Program *programObject = getProgram(program);
5238 ASSERT(programObject);
5239 programObject->getActiveUniform(index, bufsize, length, size, type, name);
5240}
5241
5242void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
5243{
5244 Program *programObject = getProgram(program);
5245 ASSERT(programObject);
5246 programObject->getAttachedShaders(maxcount, count, shaders);
5247}
5248
5249GLint Context::getAttribLocation(GLuint program, const GLchar *name)
5250{
5251 Program *programObject = getProgram(program);
5252 ASSERT(programObject);
5253 return programObject->getAttributeLocation(name);
5254}
5255
5256void Context::getBooleanv(GLenum pname, GLboolean *params)
5257{
5258 GLenum nativeType;
5259 unsigned int numParams = 0;
5260 getQueryParameterInfo(pname, &nativeType, &numParams);
5261
5262 if (nativeType == GL_BOOL)
5263 {
5264 getBooleanvImpl(pname, params);
5265 }
5266 else
5267 {
5268 CastStateValues(this, nativeType, pname, numParams, params);
5269 }
5270}
5271
Brandon Jones59770802018-04-02 13:18:42 -07005272void Context::getBooleanvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLboolean *params)
5273{
5274 getBooleanv(pname, params);
5275}
5276
Jamie Madillc1d770e2017-04-13 17:31:24 -04005277void Context::getFloatv(GLenum pname, GLfloat *params)
5278{
5279 GLenum nativeType;
5280 unsigned int numParams = 0;
5281 getQueryParameterInfo(pname, &nativeType, &numParams);
5282
5283 if (nativeType == GL_FLOAT)
5284 {
5285 getFloatvImpl(pname, params);
5286 }
5287 else
5288 {
5289 CastStateValues(this, nativeType, pname, numParams, params);
5290 }
5291}
5292
Brandon Jones59770802018-04-02 13:18:42 -07005293void Context::getFloatvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLfloat *params)
5294{
5295 getFloatv(pname, params);
5296}
5297
Jamie Madillc1d770e2017-04-13 17:31:24 -04005298void Context::getIntegerv(GLenum pname, GLint *params)
5299{
5300 GLenum nativeType;
5301 unsigned int numParams = 0;
5302 getQueryParameterInfo(pname, &nativeType, &numParams);
5303
5304 if (nativeType == GL_INT)
5305 {
5306 getIntegervImpl(pname, params);
5307 }
5308 else
5309 {
5310 CastStateValues(this, nativeType, pname, numParams, params);
5311 }
5312}
5313
Brandon Jones59770802018-04-02 13:18:42 -07005314void Context::getIntegervRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint *data)
5315{
5316 getIntegerv(pname, data);
5317}
5318
Jamie Madillc1d770e2017-04-13 17:31:24 -04005319void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
5320{
5321 Program *programObject = getProgram(program);
5322 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04005323 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005324}
5325
Brandon Jones59770802018-04-02 13:18:42 -07005326void Context::getProgramivRobust(GLuint program,
5327 GLenum pname,
5328 GLsizei bufSize,
5329 GLsizei *length,
5330 GLint *params)
5331{
5332 getProgramiv(program, pname, params);
5333}
5334
Jiajia Qin5451d532017-11-16 17:16:34 +08005335void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
5336{
5337 UNIMPLEMENTED();
5338}
5339
Jamie Madillbe849e42017-05-02 15:49:00 -04005340void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005341{
5342 Program *programObject = getProgram(program);
5343 ASSERT(programObject);
5344 programObject->getInfoLog(bufsize, length, infolog);
5345}
5346
Jiajia Qin5451d532017-11-16 17:16:34 +08005347void Context::getProgramPipelineInfoLog(GLuint pipeline,
5348 GLsizei bufSize,
5349 GLsizei *length,
5350 GLchar *infoLog)
5351{
5352 UNIMPLEMENTED();
5353}
5354
Jamie Madillc1d770e2017-04-13 17:31:24 -04005355void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
5356{
5357 Shader *shaderObject = getShader(shader);
5358 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04005359 QueryShaderiv(this, shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005360}
5361
Brandon Jones59770802018-04-02 13:18:42 -07005362void Context::getShaderivRobust(GLuint shader,
5363 GLenum pname,
5364 GLsizei bufSize,
5365 GLsizei *length,
5366 GLint *params)
5367{
5368 getShaderiv(shader, pname, params);
5369}
5370
Jamie Madillc1d770e2017-04-13 17:31:24 -04005371void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
5372{
5373 Shader *shaderObject = getShader(shader);
5374 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04005375 shaderObject->getInfoLog(this, bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005376}
5377
5378void Context::getShaderPrecisionFormat(GLenum shadertype,
5379 GLenum precisiontype,
5380 GLint *range,
5381 GLint *precision)
5382{
5383 // TODO(jmadill): Compute shaders.
5384
5385 switch (shadertype)
5386 {
5387 case GL_VERTEX_SHADER:
5388 switch (precisiontype)
5389 {
5390 case GL_LOW_FLOAT:
5391 mCaps.vertexLowpFloat.get(range, precision);
5392 break;
5393 case GL_MEDIUM_FLOAT:
5394 mCaps.vertexMediumpFloat.get(range, precision);
5395 break;
5396 case GL_HIGH_FLOAT:
5397 mCaps.vertexHighpFloat.get(range, precision);
5398 break;
5399
5400 case GL_LOW_INT:
5401 mCaps.vertexLowpInt.get(range, precision);
5402 break;
5403 case GL_MEDIUM_INT:
5404 mCaps.vertexMediumpInt.get(range, precision);
5405 break;
5406 case GL_HIGH_INT:
5407 mCaps.vertexHighpInt.get(range, precision);
5408 break;
5409
5410 default:
5411 UNREACHABLE();
5412 return;
5413 }
5414 break;
5415
5416 case GL_FRAGMENT_SHADER:
5417 switch (precisiontype)
5418 {
5419 case GL_LOW_FLOAT:
5420 mCaps.fragmentLowpFloat.get(range, precision);
5421 break;
5422 case GL_MEDIUM_FLOAT:
5423 mCaps.fragmentMediumpFloat.get(range, precision);
5424 break;
5425 case GL_HIGH_FLOAT:
5426 mCaps.fragmentHighpFloat.get(range, precision);
5427 break;
5428
5429 case GL_LOW_INT:
5430 mCaps.fragmentLowpInt.get(range, precision);
5431 break;
5432 case GL_MEDIUM_INT:
5433 mCaps.fragmentMediumpInt.get(range, precision);
5434 break;
5435 case GL_HIGH_INT:
5436 mCaps.fragmentHighpInt.get(range, precision);
5437 break;
5438
5439 default:
5440 UNREACHABLE();
5441 return;
5442 }
5443 break;
5444
5445 default:
5446 UNREACHABLE();
5447 return;
5448 }
5449}
5450
5451void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
5452{
5453 Shader *shaderObject = getShader(shader);
5454 ASSERT(shaderObject);
5455 shaderObject->getSource(bufsize, length, source);
5456}
5457
5458void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
5459{
5460 Program *programObject = getProgram(program);
5461 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005462 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005463}
5464
Brandon Jones59770802018-04-02 13:18:42 -07005465void Context::getUniformfvRobust(GLuint program,
5466 GLint location,
5467 GLsizei bufSize,
5468 GLsizei *length,
5469 GLfloat *params)
5470{
5471 getUniformfv(program, location, params);
5472}
5473
Jamie Madillc1d770e2017-04-13 17:31:24 -04005474void Context::getUniformiv(GLuint program, GLint location, GLint *params)
5475{
5476 Program *programObject = getProgram(program);
5477 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005478 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005479}
5480
Brandon Jones59770802018-04-02 13:18:42 -07005481void Context::getUniformivRobust(GLuint program,
5482 GLint location,
5483 GLsizei bufSize,
5484 GLsizei *length,
5485 GLint *params)
5486{
5487 getUniformiv(program, location, params);
5488}
5489
Jamie Madillc1d770e2017-04-13 17:31:24 -04005490GLint Context::getUniformLocation(GLuint program, const GLchar *name)
5491{
5492 Program *programObject = getProgram(program);
5493 ASSERT(programObject);
5494 return programObject->getUniformLocation(name);
5495}
5496
5497GLboolean Context::isBuffer(GLuint buffer)
5498{
5499 if (buffer == 0)
5500 {
5501 return GL_FALSE;
5502 }
5503
5504 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
5505}
5506
5507GLboolean Context::isEnabled(GLenum cap)
5508{
5509 return mGLState.getEnableFeature(cap);
5510}
5511
5512GLboolean Context::isFramebuffer(GLuint framebuffer)
5513{
5514 if (framebuffer == 0)
5515 {
5516 return GL_FALSE;
5517 }
5518
5519 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
5520}
5521
5522GLboolean Context::isProgram(GLuint program)
5523{
5524 if (program == 0)
5525 {
5526 return GL_FALSE;
5527 }
5528
5529 return (getProgram(program) ? GL_TRUE : GL_FALSE);
5530}
5531
5532GLboolean Context::isRenderbuffer(GLuint renderbuffer)
5533{
5534 if (renderbuffer == 0)
5535 {
5536 return GL_FALSE;
5537 }
5538
5539 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
5540}
5541
5542GLboolean Context::isShader(GLuint shader)
5543{
5544 if (shader == 0)
5545 {
5546 return GL_FALSE;
5547 }
5548
5549 return (getShader(shader) ? GL_TRUE : GL_FALSE);
5550}
5551
5552GLboolean Context::isTexture(GLuint texture)
5553{
5554 if (texture == 0)
5555 {
5556 return GL_FALSE;
5557 }
5558
5559 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
5560}
5561
5562void Context::linkProgram(GLuint program)
5563{
5564 Program *programObject = getProgram(program);
5565 ASSERT(programObject);
5566 handleError(programObject->link(this));
Martin Radev0abb7a22017-08-28 15:34:45 +03005567 mGLState.onProgramExecutableChange(programObject);
Jamie Madilldc358af2018-07-31 11:22:13 -04005568 mStateCache.updateActiveAttribsMask(this);
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04005569 mStateCache.updateVertexElementLimits(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005570}
5571
5572void Context::releaseShaderCompiler()
5573{
Jamie Madill4928b7c2017-06-20 12:57:39 -04005574 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005575}
5576
5577void Context::shaderBinary(GLsizei n,
5578 const GLuint *shaders,
5579 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04005580 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005581 GLsizei length)
5582{
5583 // No binary shader formats are supported.
5584 UNIMPLEMENTED();
5585}
5586
5587void Context::shaderSource(GLuint shader,
5588 GLsizei count,
5589 const GLchar *const *string,
5590 const GLint *length)
5591{
5592 Shader *shaderObject = getShader(shader);
5593 ASSERT(shaderObject);
5594 shaderObject->setSource(count, string, length);
5595}
5596
5597void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
5598{
5599 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
5600}
5601
5602void Context::stencilMask(GLuint mask)
5603{
5604 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
5605}
5606
5607void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
5608{
5609 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
5610}
5611
5612void Context::uniform1f(GLint location, GLfloat x)
5613{
5614 Program *program = mGLState.getProgram();
5615 program->setUniform1fv(location, 1, &x);
5616}
5617
5618void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
5619{
5620 Program *program = mGLState.getProgram();
5621 program->setUniform1fv(location, count, v);
5622}
5623
5624void Context::uniform1i(GLint location, GLint x)
5625{
5626 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04005627 if (program->setUniform1iv(location, 1, &x) == Program::SetUniformResult::SamplerChanged)
5628 {
5629 mGLState.setObjectDirty(GL_PROGRAM);
5630 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005631}
5632
5633void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
5634{
5635 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04005636 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
5637 {
5638 mGLState.setObjectDirty(GL_PROGRAM);
5639 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005640}
5641
5642void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
5643{
5644 GLfloat xy[2] = {x, y};
5645 Program *program = mGLState.getProgram();
5646 program->setUniform2fv(location, 1, xy);
5647}
5648
5649void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
5650{
5651 Program *program = mGLState.getProgram();
5652 program->setUniform2fv(location, count, v);
5653}
5654
5655void Context::uniform2i(GLint location, GLint x, GLint y)
5656{
5657 GLint xy[2] = {x, y};
5658 Program *program = mGLState.getProgram();
5659 program->setUniform2iv(location, 1, xy);
5660}
5661
5662void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
5663{
5664 Program *program = mGLState.getProgram();
5665 program->setUniform2iv(location, count, v);
5666}
5667
5668void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
5669{
5670 GLfloat xyz[3] = {x, y, z};
5671 Program *program = mGLState.getProgram();
5672 program->setUniform3fv(location, 1, xyz);
5673}
5674
5675void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
5676{
5677 Program *program = mGLState.getProgram();
5678 program->setUniform3fv(location, count, v);
5679}
5680
5681void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
5682{
5683 GLint xyz[3] = {x, y, z};
5684 Program *program = mGLState.getProgram();
5685 program->setUniform3iv(location, 1, xyz);
5686}
5687
5688void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
5689{
5690 Program *program = mGLState.getProgram();
5691 program->setUniform3iv(location, count, v);
5692}
5693
5694void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
5695{
5696 GLfloat xyzw[4] = {x, y, z, w};
5697 Program *program = mGLState.getProgram();
5698 program->setUniform4fv(location, 1, xyzw);
5699}
5700
5701void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
5702{
5703 Program *program = mGLState.getProgram();
5704 program->setUniform4fv(location, count, v);
5705}
5706
5707void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
5708{
5709 GLint xyzw[4] = {x, y, z, w};
5710 Program *program = mGLState.getProgram();
5711 program->setUniform4iv(location, 1, xyzw);
5712}
5713
5714void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
5715{
5716 Program *program = mGLState.getProgram();
5717 program->setUniform4iv(location, count, v);
5718}
5719
5720void Context::uniformMatrix2fv(GLint location,
5721 GLsizei count,
5722 GLboolean transpose,
5723 const GLfloat *value)
5724{
5725 Program *program = mGLState.getProgram();
5726 program->setUniformMatrix2fv(location, count, transpose, value);
5727}
5728
5729void Context::uniformMatrix3fv(GLint location,
5730 GLsizei count,
5731 GLboolean transpose,
5732 const GLfloat *value)
5733{
5734 Program *program = mGLState.getProgram();
5735 program->setUniformMatrix3fv(location, count, transpose, value);
5736}
5737
5738void Context::uniformMatrix4fv(GLint location,
5739 GLsizei count,
5740 GLboolean transpose,
5741 const GLfloat *value)
5742{
5743 Program *program = mGLState.getProgram();
5744 program->setUniformMatrix4fv(location, count, transpose, value);
5745}
5746
5747void Context::validateProgram(GLuint program)
5748{
5749 Program *programObject = getProgram(program);
5750 ASSERT(programObject);
5751 programObject->validate(mCaps);
5752}
5753
Jiajia Qin5451d532017-11-16 17:16:34 +08005754void Context::validateProgramPipeline(GLuint pipeline)
5755{
5756 UNIMPLEMENTED();
5757}
5758
Jamie Madilld04908b2017-06-09 14:15:35 -04005759void Context::getProgramBinary(GLuint program,
5760 GLsizei bufSize,
5761 GLsizei *length,
5762 GLenum *binaryFormat,
5763 void *binary)
5764{
5765 Program *programObject = getProgram(program);
5766 ASSERT(programObject != nullptr);
5767
5768 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
5769}
5770
5771void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
5772{
5773 Program *programObject = getProgram(program);
5774 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04005775
Jamie Madilld04908b2017-06-09 14:15:35 -04005776 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
Jamie Madilldc358af2018-07-31 11:22:13 -04005777 mStateCache.updateActiveAttribsMask(this);
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04005778 mStateCache.updateVertexElementLimits(this);
Jamie Madilld04908b2017-06-09 14:15:35 -04005779}
5780
Jamie Madillff325f12017-08-26 15:06:05 -04005781void Context::uniform1ui(GLint location, GLuint v0)
5782{
5783 Program *program = mGLState.getProgram();
5784 program->setUniform1uiv(location, 1, &v0);
5785}
5786
5787void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
5788{
5789 Program *program = mGLState.getProgram();
5790 const GLuint xy[] = {v0, v1};
5791 program->setUniform2uiv(location, 1, xy);
5792}
5793
5794void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
5795{
5796 Program *program = mGLState.getProgram();
5797 const GLuint xyz[] = {v0, v1, v2};
5798 program->setUniform3uiv(location, 1, xyz);
5799}
5800
5801void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
5802{
5803 Program *program = mGLState.getProgram();
5804 const GLuint xyzw[] = {v0, v1, v2, v3};
5805 program->setUniform4uiv(location, 1, xyzw);
5806}
5807
5808void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
5809{
5810 Program *program = mGLState.getProgram();
5811 program->setUniform1uiv(location, count, value);
5812}
5813void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
5814{
5815 Program *program = mGLState.getProgram();
5816 program->setUniform2uiv(location, count, value);
5817}
5818
5819void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
5820{
5821 Program *program = mGLState.getProgram();
5822 program->setUniform3uiv(location, count, value);
5823}
5824
5825void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
5826{
5827 Program *program = mGLState.getProgram();
5828 program->setUniform4uiv(location, count, value);
5829}
5830
Jamie Madillf0e04492017-08-26 15:28:42 -04005831void Context::genQueries(GLsizei n, GLuint *ids)
5832{
5833 for (GLsizei i = 0; i < n; i++)
5834 {
5835 GLuint handle = mQueryHandleAllocator.allocate();
5836 mQueryMap.assign(handle, nullptr);
5837 ids[i] = handle;
5838 }
5839}
5840
5841void Context::deleteQueries(GLsizei n, const GLuint *ids)
5842{
5843 for (int i = 0; i < n; i++)
5844 {
5845 GLuint query = ids[i];
5846
5847 Query *queryObject = nullptr;
5848 if (mQueryMap.erase(query, &queryObject))
5849 {
5850 mQueryHandleAllocator.release(query);
5851 if (queryObject)
5852 {
5853 queryObject->release(this);
5854 }
5855 }
5856 }
5857}
5858
5859GLboolean Context::isQuery(GLuint id)
5860{
Corentin Wallezad3ae902018-03-09 13:40:42 -05005861 return (getQuery(id, false, QueryType::InvalidEnum) != nullptr) ? GL_TRUE : GL_FALSE;
Jamie Madillf0e04492017-08-26 15:28:42 -04005862}
5863
Jamie Madillc8c95812017-08-26 18:40:09 -04005864void Context::uniformMatrix2x3fv(GLint location,
5865 GLsizei count,
5866 GLboolean transpose,
5867 const GLfloat *value)
5868{
5869 Program *program = mGLState.getProgram();
5870 program->setUniformMatrix2x3fv(location, count, transpose, value);
5871}
5872
5873void Context::uniformMatrix3x2fv(GLint location,
5874 GLsizei count,
5875 GLboolean transpose,
5876 const GLfloat *value)
5877{
5878 Program *program = mGLState.getProgram();
5879 program->setUniformMatrix3x2fv(location, count, transpose, value);
5880}
5881
5882void Context::uniformMatrix2x4fv(GLint location,
5883 GLsizei count,
5884 GLboolean transpose,
5885 const GLfloat *value)
5886{
5887 Program *program = mGLState.getProgram();
5888 program->setUniformMatrix2x4fv(location, count, transpose, value);
5889}
5890
5891void Context::uniformMatrix4x2fv(GLint location,
5892 GLsizei count,
5893 GLboolean transpose,
5894 const GLfloat *value)
5895{
5896 Program *program = mGLState.getProgram();
5897 program->setUniformMatrix4x2fv(location, count, transpose, value);
5898}
5899
5900void Context::uniformMatrix3x4fv(GLint location,
5901 GLsizei count,
5902 GLboolean transpose,
5903 const GLfloat *value)
5904{
5905 Program *program = mGLState.getProgram();
5906 program->setUniformMatrix3x4fv(location, count, transpose, value);
5907}
5908
5909void Context::uniformMatrix4x3fv(GLint location,
5910 GLsizei count,
5911 GLboolean transpose,
5912 const GLfloat *value)
5913{
5914 Program *program = mGLState.getProgram();
5915 program->setUniformMatrix4x3fv(location, count, transpose, value);
5916}
5917
Jamie Madilld7576732017-08-26 18:49:50 -04005918void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
5919{
5920 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5921 {
5922 GLuint vertexArray = arrays[arrayIndex];
5923
5924 if (arrays[arrayIndex] != 0)
5925 {
5926 VertexArray *vertexArrayObject = nullptr;
5927 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
5928 {
5929 if (vertexArrayObject != nullptr)
5930 {
5931 detachVertexArray(vertexArray);
5932 vertexArrayObject->onDestroy(this);
5933 }
5934
5935 mVertexArrayHandleAllocator.release(vertexArray);
5936 }
5937 }
5938 }
5939}
5940
5941void Context::genVertexArrays(GLsizei n, GLuint *arrays)
5942{
5943 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5944 {
5945 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
5946 mVertexArrayMap.assign(vertexArray, nullptr);
5947 arrays[arrayIndex] = vertexArray;
5948 }
5949}
5950
5951bool Context::isVertexArray(GLuint array)
5952{
5953 if (array == 0)
5954 {
5955 return GL_FALSE;
5956 }
5957
5958 VertexArray *vao = getVertexArray(array);
5959 return (vao != nullptr ? GL_TRUE : GL_FALSE);
5960}
5961
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04005962void Context::endTransformFeedback()
5963{
5964 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5965 transformFeedback->end(this);
5966}
5967
5968void Context::transformFeedbackVaryings(GLuint program,
5969 GLsizei count,
5970 const GLchar *const *varyings,
5971 GLenum bufferMode)
5972{
5973 Program *programObject = getProgram(program);
5974 ASSERT(programObject);
5975 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
5976}
5977
5978void Context::getTransformFeedbackVarying(GLuint program,
5979 GLuint index,
5980 GLsizei bufSize,
5981 GLsizei *length,
5982 GLsizei *size,
5983 GLenum *type,
5984 GLchar *name)
5985{
5986 Program *programObject = getProgram(program);
5987 ASSERT(programObject);
5988 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
5989}
5990
5991void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
5992{
5993 for (int i = 0; i < n; i++)
5994 {
5995 GLuint transformFeedback = ids[i];
5996 if (transformFeedback == 0)
5997 {
5998 continue;
5999 }
6000
6001 TransformFeedback *transformFeedbackObject = nullptr;
6002 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
6003 {
6004 if (transformFeedbackObject != nullptr)
6005 {
6006 detachTransformFeedback(transformFeedback);
6007 transformFeedbackObject->release(this);
6008 }
6009
6010 mTransformFeedbackHandleAllocator.release(transformFeedback);
6011 }
6012 }
6013}
6014
6015void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
6016{
6017 for (int i = 0; i < n; i++)
6018 {
6019 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
6020 mTransformFeedbackMap.assign(transformFeedback, nullptr);
6021 ids[i] = transformFeedback;
6022 }
6023}
6024
6025bool Context::isTransformFeedback(GLuint id)
6026{
6027 if (id == 0)
6028 {
6029 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
6030 // returns FALSE
6031 return GL_FALSE;
6032 }
6033
6034 const TransformFeedback *transformFeedback = getTransformFeedback(id);
6035 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
6036}
6037
6038void Context::pauseTransformFeedback()
6039{
6040 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6041 transformFeedback->pause();
6042}
6043
6044void Context::resumeTransformFeedback()
6045{
6046 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6047 transformFeedback->resume();
6048}
6049
Jamie Madill12e957f2017-08-26 21:42:26 -04006050void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
6051{
6052 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04006053 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04006054}
6055
Brandon Jones59770802018-04-02 13:18:42 -07006056void Context::getUniformuivRobust(GLuint program,
6057 GLint location,
6058 GLsizei bufSize,
6059 GLsizei *length,
6060 GLuint *params)
6061{
6062 getUniformuiv(program, location, params);
6063}
6064
Jamie Madill12e957f2017-08-26 21:42:26 -04006065GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
6066{
6067 const Program *programObject = getProgram(program);
6068 return programObject->getFragDataLocation(name);
6069}
6070
6071void Context::getUniformIndices(GLuint program,
6072 GLsizei uniformCount,
6073 const GLchar *const *uniformNames,
6074 GLuint *uniformIndices)
6075{
6076 const Program *programObject = getProgram(program);
6077 if (!programObject->isLinked())
6078 {
6079 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6080 {
6081 uniformIndices[uniformId] = GL_INVALID_INDEX;
6082 }
6083 }
6084 else
6085 {
6086 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6087 {
6088 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
6089 }
6090 }
6091}
6092
6093void Context::getActiveUniformsiv(GLuint program,
6094 GLsizei uniformCount,
6095 const GLuint *uniformIndices,
6096 GLenum pname,
6097 GLint *params)
6098{
6099 const Program *programObject = getProgram(program);
6100 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6101 {
6102 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08006103 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04006104 }
6105}
6106
6107GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
6108{
6109 const Program *programObject = getProgram(program);
6110 return programObject->getUniformBlockIndex(uniformBlockName);
6111}
6112
6113void Context::getActiveUniformBlockiv(GLuint program,
6114 GLuint uniformBlockIndex,
6115 GLenum pname,
6116 GLint *params)
6117{
6118 const Program *programObject = getProgram(program);
6119 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
6120}
6121
Brandon Jones59770802018-04-02 13:18:42 -07006122void Context::getActiveUniformBlockivRobust(GLuint program,
6123 GLuint uniformBlockIndex,
6124 GLenum pname,
6125 GLsizei bufSize,
6126 GLsizei *length,
6127 GLint *params)
6128{
6129 getActiveUniformBlockiv(program, uniformBlockIndex, pname, params);
6130}
6131
Jamie Madill12e957f2017-08-26 21:42:26 -04006132void Context::getActiveUniformBlockName(GLuint program,
6133 GLuint uniformBlockIndex,
6134 GLsizei bufSize,
6135 GLsizei *length,
6136 GLchar *uniformBlockName)
6137{
6138 const Program *programObject = getProgram(program);
6139 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
6140}
6141
6142void Context::uniformBlockBinding(GLuint program,
6143 GLuint uniformBlockIndex,
6144 GLuint uniformBlockBinding)
6145{
6146 Program *programObject = getProgram(program);
6147 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
6148}
6149
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006150GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
6151{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006152 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
6153 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006154
Jamie Madill70b5bb02017-08-28 13:32:37 -04006155 Sync *syncObject = getSync(syncHandle);
Jamie Madilla0691b72018-07-25 10:41:22 -04006156 Error error = syncObject->set(this, condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006157 if (error.isError())
6158 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04006159 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006160 handleError(error);
6161 return nullptr;
6162 }
6163
Jamie Madill70b5bb02017-08-28 13:32:37 -04006164 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006165}
6166
6167GLboolean Context::isSync(GLsync sync)
6168{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006169 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006170}
6171
6172GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6173{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006174 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006175
6176 GLenum result = GL_WAIT_FAILED;
Jamie Madilla0691b72018-07-25 10:41:22 -04006177 handleError(syncObject->clientWait(this, flags, timeout, &result));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006178 return result;
6179}
6180
6181void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6182{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006183 Sync *syncObject = getSync(sync);
Jamie Madilla0691b72018-07-25 10:41:22 -04006184 handleError(syncObject->serverWait(this, flags, timeout));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006185}
6186
6187void Context::getInteger64v(GLenum pname, GLint64 *params)
6188{
6189 GLenum nativeType = GL_NONE;
6190 unsigned int numParams = 0;
6191 getQueryParameterInfo(pname, &nativeType, &numParams);
6192
6193 if (nativeType == GL_INT_64_ANGLEX)
6194 {
6195 getInteger64vImpl(pname, params);
6196 }
6197 else
6198 {
6199 CastStateValues(this, nativeType, pname, numParams, params);
6200 }
6201}
6202
Brandon Jones59770802018-04-02 13:18:42 -07006203void Context::getInteger64vRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint64 *data)
6204{
6205 getInteger64v(pname, data);
6206}
6207
Corentin Wallez336129f2017-10-17 15:55:40 -04006208void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04006209{
6210 Buffer *buffer = mGLState.getTargetBuffer(target);
6211 QueryBufferParameteri64v(buffer, pname, params);
6212}
6213
Brandon Jones59770802018-04-02 13:18:42 -07006214void Context::getBufferParameteri64vRobust(BufferBinding target,
6215 GLenum pname,
6216 GLsizei bufSize,
6217 GLsizei *length,
6218 GLint64 *params)
6219{
6220 getBufferParameteri64v(target, pname, params);
6221}
6222
Jamie Madill3ef140a2017-08-26 23:11:21 -04006223void Context::genSamplers(GLsizei count, GLuint *samplers)
6224{
6225 for (int i = 0; i < count; i++)
6226 {
6227 samplers[i] = mState.mSamplers->createSampler();
6228 }
6229}
6230
6231void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
6232{
6233 for (int i = 0; i < count; i++)
6234 {
6235 GLuint sampler = samplers[i];
6236
6237 if (mState.mSamplers->getSampler(sampler))
6238 {
6239 detachSampler(sampler);
6240 }
6241
6242 mState.mSamplers->deleteObject(this, sampler);
6243 }
6244}
6245
6246void Context::getInternalformativ(GLenum target,
6247 GLenum internalformat,
6248 GLenum pname,
6249 GLsizei bufSize,
6250 GLint *params)
6251{
6252 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
6253 QueryInternalFormativ(formatCaps, pname, bufSize, params);
6254}
6255
Brandon Jones59770802018-04-02 13:18:42 -07006256void Context::getInternalformativRobust(GLenum target,
6257 GLenum internalformat,
6258 GLenum pname,
6259 GLsizei bufSize,
6260 GLsizei *length,
6261 GLint *params)
6262{
6263 getInternalformativ(target, internalformat, pname, bufSize, params);
6264}
6265
Jiajia Qin5451d532017-11-16 17:16:34 +08006266void Context::programUniform1i(GLuint program, GLint location, GLint v0)
6267{
6268 programUniform1iv(program, location, 1, &v0);
6269}
6270
6271void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
6272{
6273 GLint xy[2] = {v0, v1};
6274 programUniform2iv(program, location, 1, xy);
6275}
6276
6277void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
6278{
6279 GLint xyz[3] = {v0, v1, v2};
6280 programUniform3iv(program, location, 1, xyz);
6281}
6282
6283void Context::programUniform4i(GLuint program,
6284 GLint location,
6285 GLint v0,
6286 GLint v1,
6287 GLint v2,
6288 GLint v3)
6289{
6290 GLint xyzw[4] = {v0, v1, v2, v3};
6291 programUniform4iv(program, location, 1, xyzw);
6292}
6293
6294void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
6295{
6296 programUniform1uiv(program, location, 1, &v0);
6297}
6298
6299void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
6300{
6301 GLuint xy[2] = {v0, v1};
6302 programUniform2uiv(program, location, 1, xy);
6303}
6304
6305void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
6306{
6307 GLuint xyz[3] = {v0, v1, v2};
6308 programUniform3uiv(program, location, 1, xyz);
6309}
6310
6311void Context::programUniform4ui(GLuint program,
6312 GLint location,
6313 GLuint v0,
6314 GLuint v1,
6315 GLuint v2,
6316 GLuint v3)
6317{
6318 GLuint xyzw[4] = {v0, v1, v2, v3};
6319 programUniform4uiv(program, location, 1, xyzw);
6320}
6321
6322void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
6323{
6324 programUniform1fv(program, location, 1, &v0);
6325}
6326
6327void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
6328{
6329 GLfloat xy[2] = {v0, v1};
6330 programUniform2fv(program, location, 1, xy);
6331}
6332
6333void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
6334{
6335 GLfloat xyz[3] = {v0, v1, v2};
6336 programUniform3fv(program, location, 1, xyz);
6337}
6338
6339void Context::programUniform4f(GLuint program,
6340 GLint location,
6341 GLfloat v0,
6342 GLfloat v1,
6343 GLfloat v2,
6344 GLfloat v3)
6345{
6346 GLfloat xyzw[4] = {v0, v1, v2, v3};
6347 programUniform4fv(program, location, 1, xyzw);
6348}
6349
Jamie Madill81c2e252017-09-09 23:32:46 -04006350void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6351{
6352 Program *programObject = getProgram(program);
6353 ASSERT(programObject);
6354 if (programObject->setUniform1iv(location, count, value) ==
6355 Program::SetUniformResult::SamplerChanged)
6356 {
6357 mGLState.setObjectDirty(GL_PROGRAM);
6358 }
6359}
6360
Jiajia Qin5451d532017-11-16 17:16:34 +08006361void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6362{
6363 Program *programObject = getProgram(program);
6364 ASSERT(programObject);
6365 programObject->setUniform2iv(location, count, value);
6366}
6367
6368void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6369{
6370 Program *programObject = getProgram(program);
6371 ASSERT(programObject);
6372 programObject->setUniform3iv(location, count, value);
6373}
6374
6375void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6376{
6377 Program *programObject = getProgram(program);
6378 ASSERT(programObject);
6379 programObject->setUniform4iv(location, count, value);
6380}
6381
6382void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6383{
6384 Program *programObject = getProgram(program);
6385 ASSERT(programObject);
6386 programObject->setUniform1uiv(location, count, value);
6387}
6388
6389void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6390{
6391 Program *programObject = getProgram(program);
6392 ASSERT(programObject);
6393 programObject->setUniform2uiv(location, count, value);
6394}
6395
6396void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6397{
6398 Program *programObject = getProgram(program);
6399 ASSERT(programObject);
6400 programObject->setUniform3uiv(location, count, value);
6401}
6402
6403void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6404{
6405 Program *programObject = getProgram(program);
6406 ASSERT(programObject);
6407 programObject->setUniform4uiv(location, count, value);
6408}
6409
6410void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6411{
6412 Program *programObject = getProgram(program);
6413 ASSERT(programObject);
6414 programObject->setUniform1fv(location, count, value);
6415}
6416
6417void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6418{
6419 Program *programObject = getProgram(program);
6420 ASSERT(programObject);
6421 programObject->setUniform2fv(location, count, value);
6422}
6423
6424void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6425{
6426 Program *programObject = getProgram(program);
6427 ASSERT(programObject);
6428 programObject->setUniform3fv(location, count, value);
6429}
6430
6431void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6432{
6433 Program *programObject = getProgram(program);
6434 ASSERT(programObject);
6435 programObject->setUniform4fv(location, count, value);
6436}
6437
6438void Context::programUniformMatrix2fv(GLuint program,
6439 GLint location,
6440 GLsizei count,
6441 GLboolean transpose,
6442 const GLfloat *value)
6443{
6444 Program *programObject = getProgram(program);
6445 ASSERT(programObject);
6446 programObject->setUniformMatrix2fv(location, count, transpose, value);
6447}
6448
6449void Context::programUniformMatrix3fv(GLuint program,
6450 GLint location,
6451 GLsizei count,
6452 GLboolean transpose,
6453 const GLfloat *value)
6454{
6455 Program *programObject = getProgram(program);
6456 ASSERT(programObject);
6457 programObject->setUniformMatrix3fv(location, count, transpose, value);
6458}
6459
6460void Context::programUniformMatrix4fv(GLuint program,
6461 GLint location,
6462 GLsizei count,
6463 GLboolean transpose,
6464 const GLfloat *value)
6465{
6466 Program *programObject = getProgram(program);
6467 ASSERT(programObject);
6468 programObject->setUniformMatrix4fv(location, count, transpose, value);
6469}
6470
6471void Context::programUniformMatrix2x3fv(GLuint program,
6472 GLint location,
6473 GLsizei count,
6474 GLboolean transpose,
6475 const GLfloat *value)
6476{
6477 Program *programObject = getProgram(program);
6478 ASSERT(programObject);
6479 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
6480}
6481
6482void Context::programUniformMatrix3x2fv(GLuint program,
6483 GLint location,
6484 GLsizei count,
6485 GLboolean transpose,
6486 const GLfloat *value)
6487{
6488 Program *programObject = getProgram(program);
6489 ASSERT(programObject);
6490 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
6491}
6492
6493void Context::programUniformMatrix2x4fv(GLuint program,
6494 GLint location,
6495 GLsizei count,
6496 GLboolean transpose,
6497 const GLfloat *value)
6498{
6499 Program *programObject = getProgram(program);
6500 ASSERT(programObject);
6501 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
6502}
6503
6504void Context::programUniformMatrix4x2fv(GLuint program,
6505 GLint location,
6506 GLsizei count,
6507 GLboolean transpose,
6508 const GLfloat *value)
6509{
6510 Program *programObject = getProgram(program);
6511 ASSERT(programObject);
6512 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
6513}
6514
6515void Context::programUniformMatrix3x4fv(GLuint program,
6516 GLint location,
6517 GLsizei count,
6518 GLboolean transpose,
6519 const GLfloat *value)
6520{
6521 Program *programObject = getProgram(program);
6522 ASSERT(programObject);
6523 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
6524}
6525
6526void Context::programUniformMatrix4x3fv(GLuint program,
6527 GLint location,
6528 GLsizei count,
6529 GLboolean transpose,
6530 const GLfloat *value)
6531{
6532 Program *programObject = getProgram(program);
6533 ASSERT(programObject);
6534 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
6535}
6536
Jamie Madill81c2e252017-09-09 23:32:46 -04006537void Context::onTextureChange(const Texture *texture)
6538{
6539 // Conservatively assume all textures are dirty.
6540 // TODO(jmadill): More fine-grained update.
6541 mGLState.setObjectDirty(GL_TEXTURE);
6542}
6543
James Darpiniane8a93c62018-01-04 18:02:24 -08006544bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
6545{
6546 return mGLState.isCurrentTransformFeedback(tf);
6547}
6548bool Context::isCurrentVertexArray(const VertexArray *va) const
6549{
6550 return mGLState.isCurrentVertexArray(va);
6551}
6552
Yunchao Hea336b902017-08-02 16:05:21 +08006553void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
6554{
6555 for (int i = 0; i < count; i++)
6556 {
6557 pipelines[i] = createProgramPipeline();
6558 }
6559}
6560
6561void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
6562{
6563 for (int i = 0; i < count; i++)
6564 {
6565 if (pipelines[i] != 0)
6566 {
6567 deleteProgramPipeline(pipelines[i]);
6568 }
6569 }
6570}
6571
6572GLboolean Context::isProgramPipeline(GLuint pipeline)
6573{
6574 if (pipeline == 0)
6575 {
6576 return GL_FALSE;
6577 }
6578
6579 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
6580}
6581
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006582void Context::finishFenceNV(GLuint fence)
6583{
6584 FenceNV *fenceObject = getFenceNV(fence);
6585
6586 ASSERT(fenceObject && fenceObject->isSet());
Jamie Madilla0691b72018-07-25 10:41:22 -04006587 handleError(fenceObject->finish(this));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006588}
6589
6590void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
6591{
6592 FenceNV *fenceObject = getFenceNV(fence);
6593
6594 ASSERT(fenceObject && fenceObject->isSet());
6595
6596 switch (pname)
6597 {
6598 case GL_FENCE_STATUS_NV:
6599 {
6600 // GL_NV_fence spec:
6601 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
6602 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
6603 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
6604 GLboolean status = GL_TRUE;
6605 if (fenceObject->getStatus() != GL_TRUE)
6606 {
Jamie Madilla0691b72018-07-25 10:41:22 -04006607 ANGLE_CONTEXT_TRY(fenceObject->test(this, &status));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006608 }
6609 *params = status;
6610 break;
6611 }
6612
6613 case GL_FENCE_CONDITION_NV:
6614 {
6615 *params = static_cast<GLint>(fenceObject->getCondition());
6616 break;
6617 }
6618
6619 default:
6620 UNREACHABLE();
6621 }
6622}
6623
6624void Context::getTranslatedShaderSource(GLuint shader,
6625 GLsizei bufsize,
6626 GLsizei *length,
6627 GLchar *source)
6628{
6629 Shader *shaderObject = getShader(shader);
6630 ASSERT(shaderObject);
6631 shaderObject->getTranslatedSourceWithDebugInfo(this, bufsize, length, source);
6632}
6633
6634void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
6635{
6636 Program *programObject = getProgram(program);
6637 ASSERT(programObject);
6638
6639 programObject->getUniformfv(this, location, params);
6640}
6641
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006642void Context::getnUniformfvRobust(GLuint program,
6643 GLint location,
6644 GLsizei bufSize,
6645 GLsizei *length,
6646 GLfloat *params)
6647{
6648 UNIMPLEMENTED();
6649}
6650
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006651void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
6652{
6653 Program *programObject = getProgram(program);
6654 ASSERT(programObject);
6655
6656 programObject->getUniformiv(this, location, params);
6657}
6658
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006659void Context::getnUniformivRobust(GLuint program,
6660 GLint location,
6661 GLsizei bufSize,
6662 GLsizei *length,
6663 GLint *params)
6664{
6665 UNIMPLEMENTED();
6666}
6667
6668void Context::getnUniformuivRobust(GLuint program,
6669 GLint location,
6670 GLsizei bufSize,
6671 GLsizei *length,
6672 GLuint *params)
6673{
6674 UNIMPLEMENTED();
6675}
6676
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006677GLboolean Context::isFenceNV(GLuint fence)
6678{
6679 FenceNV *fenceObject = getFenceNV(fence);
6680
6681 if (fenceObject == nullptr)
6682 {
6683 return GL_FALSE;
6684 }
6685
6686 // GL_NV_fence spec:
6687 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
6688 // existing fence.
6689 return fenceObject->isSet();
6690}
6691
6692void Context::readnPixels(GLint x,
6693 GLint y,
6694 GLsizei width,
6695 GLsizei height,
6696 GLenum format,
6697 GLenum type,
6698 GLsizei bufSize,
6699 void *data)
6700{
6701 return readPixels(x, y, width, height, format, type, data);
6702}
6703
Jamie Madill007530e2017-12-28 14:27:04 -05006704void Context::setFenceNV(GLuint fence, GLenum condition)
6705{
6706 ASSERT(condition == GL_ALL_COMPLETED_NV);
6707
6708 FenceNV *fenceObject = getFenceNV(fence);
6709 ASSERT(fenceObject != nullptr);
Jamie Madilla0691b72018-07-25 10:41:22 -04006710 handleError(fenceObject->set(this, condition));
Jamie Madill007530e2017-12-28 14:27:04 -05006711}
6712
6713GLboolean Context::testFenceNV(GLuint fence)
6714{
6715 FenceNV *fenceObject = getFenceNV(fence);
6716
6717 ASSERT(fenceObject != nullptr);
6718 ASSERT(fenceObject->isSet() == GL_TRUE);
6719
6720 GLboolean result = GL_TRUE;
Jamie Madilla0691b72018-07-25 10:41:22 -04006721 Error error = fenceObject->test(this, &result);
Jamie Madill007530e2017-12-28 14:27:04 -05006722 if (error.isError())
6723 {
6724 handleError(error);
6725 return GL_TRUE;
6726 }
6727
6728 return result;
6729}
6730
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006731void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006732{
6733 Texture *texture = getTargetTexture(target);
Rafael Cintron05a449a2018-06-20 18:08:04 -07006734 egl::Image *imageObject = static_cast<egl::Image *>(image);
Corentin Wallez99d492c2018-02-27 15:17:10 -05006735 handleError(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05006736}
6737
Jamie Madillfa920eb2018-01-04 11:45:50 -05006738void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006739{
6740 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Rafael Cintron05a449a2018-06-20 18:08:04 -07006741 egl::Image *imageObject = static_cast<egl::Image *>(image);
Jamie Madill007530e2017-12-28 14:27:04 -05006742 handleError(renderbuffer->setStorageEGLImageTarget(this, imageObject));
6743}
6744
Jamie Madillfa920eb2018-01-04 11:45:50 -05006745void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
6746{
6747 UNIMPLEMENTED();
6748}
6749
Jamie Madill5b772312018-03-08 20:28:32 -05006750bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
6751{
6752 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
6753 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
6754 // to the fact that it is stored internally as a float, and so would require conversion
6755 // if returned from Context::getIntegerv. Since this conversion is already implemented
6756 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
6757 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
6758 // application.
6759 switch (pname)
6760 {
6761 case GL_COMPRESSED_TEXTURE_FORMATS:
6762 {
6763 *type = GL_INT;
6764 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
6765 return true;
6766 }
6767 case GL_SHADER_BINARY_FORMATS:
6768 {
6769 *type = GL_INT;
6770 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
6771 return true;
6772 }
6773
6774 case GL_MAX_VERTEX_ATTRIBS:
6775 case GL_MAX_VERTEX_UNIFORM_VECTORS:
6776 case GL_MAX_VARYING_VECTORS:
6777 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
6778 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
6779 case GL_MAX_TEXTURE_IMAGE_UNITS:
6780 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
6781 case GL_MAX_RENDERBUFFER_SIZE:
6782 case GL_NUM_SHADER_BINARY_FORMATS:
6783 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
6784 case GL_ARRAY_BUFFER_BINDING:
6785 case GL_FRAMEBUFFER_BINDING:
6786 case GL_RENDERBUFFER_BINDING:
6787 case GL_CURRENT_PROGRAM:
6788 case GL_PACK_ALIGNMENT:
6789 case GL_UNPACK_ALIGNMENT:
6790 case GL_GENERATE_MIPMAP_HINT:
6791 case GL_RED_BITS:
6792 case GL_GREEN_BITS:
6793 case GL_BLUE_BITS:
6794 case GL_ALPHA_BITS:
6795 case GL_DEPTH_BITS:
6796 case GL_STENCIL_BITS:
6797 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
6798 case GL_CULL_FACE_MODE:
6799 case GL_FRONT_FACE:
6800 case GL_ACTIVE_TEXTURE:
6801 case GL_STENCIL_FUNC:
6802 case GL_STENCIL_VALUE_MASK:
6803 case GL_STENCIL_REF:
6804 case GL_STENCIL_FAIL:
6805 case GL_STENCIL_PASS_DEPTH_FAIL:
6806 case GL_STENCIL_PASS_DEPTH_PASS:
6807 case GL_STENCIL_BACK_FUNC:
6808 case GL_STENCIL_BACK_VALUE_MASK:
6809 case GL_STENCIL_BACK_REF:
6810 case GL_STENCIL_BACK_FAIL:
6811 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
6812 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
6813 case GL_DEPTH_FUNC:
6814 case GL_BLEND_SRC_RGB:
6815 case GL_BLEND_SRC_ALPHA:
6816 case GL_BLEND_DST_RGB:
6817 case GL_BLEND_DST_ALPHA:
6818 case GL_BLEND_EQUATION_RGB:
6819 case GL_BLEND_EQUATION_ALPHA:
6820 case GL_STENCIL_WRITEMASK:
6821 case GL_STENCIL_BACK_WRITEMASK:
6822 case GL_STENCIL_CLEAR_VALUE:
6823 case GL_SUBPIXEL_BITS:
6824 case GL_MAX_TEXTURE_SIZE:
6825 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
6826 case GL_SAMPLE_BUFFERS:
6827 case GL_SAMPLES:
6828 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
6829 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
6830 case GL_TEXTURE_BINDING_2D:
6831 case GL_TEXTURE_BINDING_CUBE_MAP:
6832 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
6833 {
6834 *type = GL_INT;
6835 *numParams = 1;
6836 return true;
6837 }
6838 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6839 {
6840 if (!getExtensions().packReverseRowOrder)
6841 {
6842 return false;
6843 }
6844 *type = GL_INT;
6845 *numParams = 1;
6846 return true;
6847 }
6848 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
6849 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
6850 {
6851 if (!getExtensions().textureRectangle)
6852 {
6853 return false;
6854 }
6855 *type = GL_INT;
6856 *numParams = 1;
6857 return true;
6858 }
6859 case GL_MAX_DRAW_BUFFERS_EXT:
6860 case GL_MAX_COLOR_ATTACHMENTS_EXT:
6861 {
6862 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
6863 {
6864 return false;
6865 }
6866 *type = GL_INT;
6867 *numParams = 1;
6868 return true;
6869 }
6870 case GL_MAX_VIEWPORT_DIMS:
6871 {
6872 *type = GL_INT;
6873 *numParams = 2;
6874 return true;
6875 }
6876 case GL_VIEWPORT:
6877 case GL_SCISSOR_BOX:
6878 {
6879 *type = GL_INT;
6880 *numParams = 4;
6881 return true;
6882 }
6883 case GL_SHADER_COMPILER:
6884 case GL_SAMPLE_COVERAGE_INVERT:
6885 case GL_DEPTH_WRITEMASK:
6886 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
6887 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
6888 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
6889 // bool-natural
6890 case GL_SAMPLE_COVERAGE:
6891 case GL_SCISSOR_TEST:
6892 case GL_STENCIL_TEST:
6893 case GL_DEPTH_TEST:
6894 case GL_BLEND:
6895 case GL_DITHER:
6896 case GL_CONTEXT_ROBUST_ACCESS_EXT:
6897 {
6898 *type = GL_BOOL;
6899 *numParams = 1;
6900 return true;
6901 }
6902 case GL_COLOR_WRITEMASK:
6903 {
6904 *type = GL_BOOL;
6905 *numParams = 4;
6906 return true;
6907 }
6908 case GL_POLYGON_OFFSET_FACTOR:
6909 case GL_POLYGON_OFFSET_UNITS:
6910 case GL_SAMPLE_COVERAGE_VALUE:
6911 case GL_DEPTH_CLEAR_VALUE:
6912 case GL_LINE_WIDTH:
6913 {
6914 *type = GL_FLOAT;
6915 *numParams = 1;
6916 return true;
6917 }
6918 case GL_ALIASED_LINE_WIDTH_RANGE:
6919 case GL_ALIASED_POINT_SIZE_RANGE:
6920 case GL_DEPTH_RANGE:
6921 {
6922 *type = GL_FLOAT;
6923 *numParams = 2;
6924 return true;
6925 }
6926 case GL_COLOR_CLEAR_VALUE:
6927 case GL_BLEND_COLOR:
6928 {
6929 *type = GL_FLOAT;
6930 *numParams = 4;
6931 return true;
6932 }
6933 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
6934 if (!getExtensions().textureFilterAnisotropic)
6935 {
6936 return false;
6937 }
6938 *type = GL_FLOAT;
6939 *numParams = 1;
6940 return true;
6941 case GL_TIMESTAMP_EXT:
6942 if (!getExtensions().disjointTimerQuery)
6943 {
6944 return false;
6945 }
6946 *type = GL_INT_64_ANGLEX;
6947 *numParams = 1;
6948 return true;
6949 case GL_GPU_DISJOINT_EXT:
6950 if (!getExtensions().disjointTimerQuery)
6951 {
6952 return false;
6953 }
6954 *type = GL_INT;
6955 *numParams = 1;
6956 return true;
6957 case GL_COVERAGE_MODULATION_CHROMIUM:
6958 if (!getExtensions().framebufferMixedSamples)
6959 {
6960 return false;
6961 }
6962 *type = GL_INT;
6963 *numParams = 1;
6964 return true;
6965 case GL_TEXTURE_BINDING_EXTERNAL_OES:
6966 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
6967 {
6968 return false;
6969 }
6970 *type = GL_INT;
6971 *numParams = 1;
6972 return true;
6973 }
6974
6975 if (getExtensions().debug)
6976 {
6977 switch (pname)
6978 {
6979 case GL_DEBUG_LOGGED_MESSAGES:
6980 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
6981 case GL_DEBUG_GROUP_STACK_DEPTH:
6982 case GL_MAX_DEBUG_MESSAGE_LENGTH:
6983 case GL_MAX_DEBUG_LOGGED_MESSAGES:
6984 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
6985 case GL_MAX_LABEL_LENGTH:
6986 *type = GL_INT;
6987 *numParams = 1;
6988 return true;
6989
6990 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
6991 case GL_DEBUG_OUTPUT:
6992 *type = GL_BOOL;
6993 *numParams = 1;
6994 return true;
6995 }
6996 }
6997
6998 if (getExtensions().multisampleCompatibility)
6999 {
7000 switch (pname)
7001 {
7002 case GL_MULTISAMPLE_EXT:
7003 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
7004 *type = GL_BOOL;
7005 *numParams = 1;
7006 return true;
7007 }
7008 }
7009
7010 if (getExtensions().pathRendering)
7011 {
7012 switch (pname)
7013 {
7014 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
7015 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
7016 *type = GL_FLOAT;
7017 *numParams = 16;
7018 return true;
7019 }
7020 }
7021
7022 if (getExtensions().bindGeneratesResource)
7023 {
7024 switch (pname)
7025 {
7026 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
7027 *type = GL_BOOL;
7028 *numParams = 1;
7029 return true;
7030 }
7031 }
7032
7033 if (getExtensions().clientArrays)
7034 {
7035 switch (pname)
7036 {
7037 case GL_CLIENT_ARRAYS_ANGLE:
7038 *type = GL_BOOL;
7039 *numParams = 1;
7040 return true;
7041 }
7042 }
7043
7044 if (getExtensions().sRGBWriteControl)
7045 {
7046 switch (pname)
7047 {
7048 case GL_FRAMEBUFFER_SRGB_EXT:
7049 *type = GL_BOOL;
7050 *numParams = 1;
7051 return true;
7052 }
7053 }
7054
7055 if (getExtensions().robustResourceInitialization &&
7056 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
7057 {
7058 *type = GL_BOOL;
7059 *numParams = 1;
7060 return true;
7061 }
7062
7063 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
7064 {
7065 *type = GL_BOOL;
7066 *numParams = 1;
7067 return true;
7068 }
7069
jchen1082af6202018-06-22 10:59:52 +08007070 if (getExtensions().parallelShaderCompile && pname == GL_MAX_SHADER_COMPILER_THREADS_KHR)
7071 {
7072 *type = GL_INT;
7073 *numParams = 1;
7074 return true;
7075 }
7076
Jamie Madill5b772312018-03-08 20:28:32 -05007077 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
7078 switch (pname)
7079 {
7080 // case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE // equivalent to FRAMEBUFFER_BINDING
7081 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
7082 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
7083 {
7084 return false;
7085 }
7086 *type = GL_INT;
7087 *numParams = 1;
7088 return true;
7089
7090 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
7091 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7092 {
7093 return false;
7094 }
7095 *type = GL_INT;
7096 *numParams = 1;
7097 return true;
7098
7099 case GL_PROGRAM_BINARY_FORMATS_OES:
7100 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7101 {
7102 return false;
7103 }
7104 *type = GL_INT;
7105 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
7106 return true;
7107
7108 case GL_PACK_ROW_LENGTH:
7109 case GL_PACK_SKIP_ROWS:
7110 case GL_PACK_SKIP_PIXELS:
7111 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
7112 {
7113 return false;
7114 }
7115 *type = GL_INT;
7116 *numParams = 1;
7117 return true;
7118 case GL_UNPACK_ROW_LENGTH:
7119 case GL_UNPACK_SKIP_ROWS:
7120 case GL_UNPACK_SKIP_PIXELS:
7121 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
7122 {
7123 return false;
7124 }
7125 *type = GL_INT;
7126 *numParams = 1;
7127 return true;
7128 case GL_VERTEX_ARRAY_BINDING:
7129 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
7130 {
7131 return false;
7132 }
7133 *type = GL_INT;
7134 *numParams = 1;
7135 return true;
7136 case GL_PIXEL_PACK_BUFFER_BINDING:
7137 case GL_PIXEL_UNPACK_BUFFER_BINDING:
7138 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
7139 {
7140 return false;
7141 }
7142 *type = GL_INT;
7143 *numParams = 1;
7144 return true;
7145 case GL_MAX_SAMPLES:
7146 {
7147 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
7148 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
7149 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
7150 {
7151 return false;
7152 }
7153 *type = GL_INT;
7154 *numParams = 1;
7155 return true;
7156
7157 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
7158 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
7159 {
7160 return false;
7161 }
7162 *type = GL_INT;
7163 *numParams = 1;
7164 return true;
7165 }
7166 }
7167
7168 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
7169 {
7170 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
7171 {
7172 return false;
7173 }
7174 *type = GL_INT;
7175 *numParams = 1;
7176 return true;
7177 }
7178
7179 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
7180 {
7181 *type = GL_INT;
7182 *numParams = 1;
7183 return true;
7184 }
7185
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007186 if (getClientVersion() < Version(2, 0))
7187 {
7188 switch (pname)
7189 {
7190 case GL_ALPHA_TEST_FUNC:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007191 case GL_CLIENT_ACTIVE_TEXTURE:
7192 case GL_MATRIX_MODE:
7193 case GL_MAX_TEXTURE_UNITS:
7194 case GL_MAX_MODELVIEW_STACK_DEPTH:
7195 case GL_MAX_PROJECTION_STACK_DEPTH:
7196 case GL_MAX_TEXTURE_STACK_DEPTH:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007197 case GL_MAX_LIGHTS:
Lingfeng Yang060088a2018-05-30 20:40:57 -07007198 case GL_MAX_CLIP_PLANES:
Lingfeng Yangabb09f12018-04-16 10:43:53 -07007199 case GL_VERTEX_ARRAY_STRIDE:
7200 case GL_NORMAL_ARRAY_STRIDE:
7201 case GL_COLOR_ARRAY_STRIDE:
7202 case GL_TEXTURE_COORD_ARRAY_STRIDE:
7203 case GL_VERTEX_ARRAY_SIZE:
7204 case GL_COLOR_ARRAY_SIZE:
7205 case GL_TEXTURE_COORD_ARRAY_SIZE:
7206 case GL_VERTEX_ARRAY_TYPE:
7207 case GL_NORMAL_ARRAY_TYPE:
7208 case GL_COLOR_ARRAY_TYPE:
7209 case GL_TEXTURE_COORD_ARRAY_TYPE:
7210 case GL_VERTEX_ARRAY_BUFFER_BINDING:
7211 case GL_NORMAL_ARRAY_BUFFER_BINDING:
7212 case GL_COLOR_ARRAY_BUFFER_BINDING:
7213 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
7214 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
7215 case GL_POINT_SIZE_ARRAY_TYPE_OES:
7216 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
Lingfeng Yanga0cfa872018-05-30 21:12:17 -07007217 case GL_SHADE_MODEL:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007218 *type = GL_INT;
7219 *numParams = 1;
7220 return true;
7221 case GL_ALPHA_TEST_REF:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007222 case GL_FOG_DENSITY:
7223 case GL_FOG_START:
7224 case GL_FOG_END:
7225 case GL_FOG_MODE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007226 case GL_POINT_SIZE:
7227 case GL_POINT_SIZE_MIN:
7228 case GL_POINT_SIZE_MAX:
7229 case GL_POINT_FADE_THRESHOLD_SIZE:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007230 *type = GL_FLOAT;
7231 *numParams = 1;
7232 return true;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007233 case GL_SMOOTH_POINT_SIZE_RANGE:
7234 *type = GL_FLOAT;
7235 *numParams = 2;
7236 return true;
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007237 case GL_CURRENT_COLOR:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007238 case GL_CURRENT_TEXTURE_COORDS:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007239 case GL_LIGHT_MODEL_AMBIENT:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007240 case GL_FOG_COLOR:
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007241 *type = GL_FLOAT;
7242 *numParams = 4;
7243 return true;
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007244 case GL_CURRENT_NORMAL:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007245 case GL_POINT_DISTANCE_ATTENUATION:
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007246 *type = GL_FLOAT;
7247 *numParams = 3;
7248 return true;
Lingfeng Yang3a41af62018-04-09 07:28:56 -07007249 case GL_MODELVIEW_MATRIX:
7250 case GL_PROJECTION_MATRIX:
7251 case GL_TEXTURE_MATRIX:
7252 *type = GL_FLOAT;
7253 *numParams = 16;
7254 return true;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007255 case GL_LIGHT_MODEL_TWO_SIDE:
7256 *type = GL_BOOL;
7257 *numParams = 1;
7258 return true;
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007259 }
7260 }
7261
Jamie Madill5b772312018-03-08 20:28:32 -05007262 if (getClientVersion() < Version(3, 0))
7263 {
7264 return false;
7265 }
7266
7267 // Check for ES3.0+ parameter names
7268 switch (pname)
7269 {
7270 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
7271 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
7272 case GL_UNIFORM_BUFFER_BINDING:
7273 case GL_TRANSFORM_FEEDBACK_BINDING:
7274 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7275 case GL_COPY_READ_BUFFER_BINDING:
7276 case GL_COPY_WRITE_BUFFER_BINDING:
7277 case GL_SAMPLER_BINDING:
7278 case GL_READ_BUFFER:
7279 case GL_TEXTURE_BINDING_3D:
7280 case GL_TEXTURE_BINDING_2D_ARRAY:
7281 case GL_MAX_3D_TEXTURE_SIZE:
7282 case GL_MAX_ARRAY_TEXTURE_LAYERS:
7283 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
7284 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
7285 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
7286 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
7287 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
7288 case GL_MAX_VARYING_COMPONENTS:
7289 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
7290 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
7291 case GL_MIN_PROGRAM_TEXEL_OFFSET:
7292 case GL_MAX_PROGRAM_TEXEL_OFFSET:
7293 case GL_NUM_EXTENSIONS:
7294 case GL_MAJOR_VERSION:
7295 case GL_MINOR_VERSION:
7296 case GL_MAX_ELEMENTS_INDICES:
7297 case GL_MAX_ELEMENTS_VERTICES:
7298 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
7299 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
7300 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
7301 case GL_UNPACK_IMAGE_HEIGHT:
7302 case GL_UNPACK_SKIP_IMAGES:
7303 {
7304 *type = GL_INT;
7305 *numParams = 1;
7306 return true;
7307 }
7308
7309 case GL_MAX_ELEMENT_INDEX:
7310 case GL_MAX_UNIFORM_BLOCK_SIZE:
7311 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
7312 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
7313 case GL_MAX_SERVER_WAIT_TIMEOUT:
7314 {
7315 *type = GL_INT_64_ANGLEX;
7316 *numParams = 1;
7317 return true;
7318 }
7319
7320 case GL_TRANSFORM_FEEDBACK_ACTIVE:
7321 case GL_TRANSFORM_FEEDBACK_PAUSED:
7322 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
7323 case GL_RASTERIZER_DISCARD:
7324 {
7325 *type = GL_BOOL;
7326 *numParams = 1;
7327 return true;
7328 }
7329
7330 case GL_MAX_TEXTURE_LOD_BIAS:
7331 {
7332 *type = GL_FLOAT;
7333 *numParams = 1;
7334 return true;
7335 }
7336 }
7337
7338 if (getExtensions().requestExtension)
7339 {
7340 switch (pname)
7341 {
7342 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
7343 *type = GL_INT;
7344 *numParams = 1;
7345 return true;
7346 }
7347 }
7348
7349 if (getClientVersion() < Version(3, 1))
7350 {
7351 return false;
7352 }
7353
7354 switch (pname)
7355 {
7356 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7357 case GL_DRAW_INDIRECT_BUFFER_BINDING:
7358 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
7359 case GL_MAX_FRAMEBUFFER_WIDTH:
7360 case GL_MAX_FRAMEBUFFER_HEIGHT:
7361 case GL_MAX_FRAMEBUFFER_SAMPLES:
7362 case GL_MAX_SAMPLE_MASK_WORDS:
7363 case GL_MAX_COLOR_TEXTURE_SAMPLES:
7364 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
7365 case GL_MAX_INTEGER_SAMPLES:
7366 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
7367 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
7368 case GL_MAX_VERTEX_ATTRIB_STRIDE:
7369 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
7370 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
7371 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
7372 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
7373 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
7374 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
7375 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
7376 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
7377 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
7378 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
7379 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
7380 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
7381 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
7382 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
7383 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
7384 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
7385 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
7386 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
7387 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
7388 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
7389 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
7390 case GL_MAX_UNIFORM_LOCATIONS:
7391 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
7392 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
7393 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
7394 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
7395 case GL_MAX_IMAGE_UNITS:
7396 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
7397 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
7398 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
7399 case GL_SHADER_STORAGE_BUFFER_BINDING:
7400 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
7401 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
7402 *type = GL_INT;
7403 *numParams = 1;
7404 return true;
7405 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7406 *type = GL_INT_64_ANGLEX;
7407 *numParams = 1;
7408 return true;
7409 case GL_SAMPLE_MASK:
7410 *type = GL_BOOL;
7411 *numParams = 1;
7412 return true;
7413 }
7414
7415 if (getExtensions().geometryShader)
7416 {
7417 switch (pname)
7418 {
7419 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7420 case GL_LAYER_PROVOKING_VERTEX_EXT:
7421 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7422 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7423 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7424 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7425 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7426 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7427 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7428 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7429 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7430 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7431 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7432 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7433 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7434 *type = GL_INT;
7435 *numParams = 1;
7436 return true;
7437 }
7438 }
7439
7440 return false;
7441}
7442
7443bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7444{
7445 if (getClientVersion() < Version(3, 0))
7446 {
7447 return false;
7448 }
7449
7450 switch (target)
7451 {
7452 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7453 case GL_UNIFORM_BUFFER_BINDING:
7454 {
7455 *type = GL_INT;
7456 *numParams = 1;
7457 return true;
7458 }
7459 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7460 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7461 case GL_UNIFORM_BUFFER_START:
7462 case GL_UNIFORM_BUFFER_SIZE:
7463 {
7464 *type = GL_INT_64_ANGLEX;
7465 *numParams = 1;
7466 return true;
7467 }
7468 }
7469
7470 if (getClientVersion() < Version(3, 1))
7471 {
7472 return false;
7473 }
7474
7475 switch (target)
7476 {
7477 case GL_IMAGE_BINDING_LAYERED:
7478 {
7479 *type = GL_BOOL;
7480 *numParams = 1;
7481 return true;
7482 }
7483 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7484 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7485 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7486 case GL_SHADER_STORAGE_BUFFER_BINDING:
7487 case GL_VERTEX_BINDING_BUFFER:
7488 case GL_VERTEX_BINDING_DIVISOR:
7489 case GL_VERTEX_BINDING_OFFSET:
7490 case GL_VERTEX_BINDING_STRIDE:
7491 case GL_SAMPLE_MASK_VALUE:
7492 case GL_IMAGE_BINDING_NAME:
7493 case GL_IMAGE_BINDING_LEVEL:
7494 case GL_IMAGE_BINDING_LAYER:
7495 case GL_IMAGE_BINDING_ACCESS:
7496 case GL_IMAGE_BINDING_FORMAT:
7497 {
7498 *type = GL_INT;
7499 *numParams = 1;
7500 return true;
7501 }
7502 case GL_ATOMIC_COUNTER_BUFFER_START:
7503 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
7504 case GL_SHADER_STORAGE_BUFFER_START:
7505 case GL_SHADER_STORAGE_BUFFER_SIZE:
7506 {
7507 *type = GL_INT_64_ANGLEX;
7508 *numParams = 1;
7509 return true;
7510 }
7511 }
7512
7513 return false;
7514}
7515
7516Program *Context::getProgram(GLuint handle) const
7517{
7518 return mState.mShaderPrograms->getProgram(handle);
7519}
7520
7521Shader *Context::getShader(GLuint handle) const
7522{
7523 return mState.mShaderPrograms->getShader(handle);
7524}
7525
7526bool Context::isTextureGenerated(GLuint texture) const
7527{
7528 return mState.mTextures->isHandleGenerated(texture);
7529}
7530
7531bool Context::isBufferGenerated(GLuint buffer) const
7532{
7533 return mState.mBuffers->isHandleGenerated(buffer);
7534}
7535
7536bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
7537{
7538 return mState.mRenderbuffers->isHandleGenerated(renderbuffer);
7539}
7540
7541bool Context::isFramebufferGenerated(GLuint framebuffer) const
7542{
7543 return mState.mFramebuffers->isHandleGenerated(framebuffer);
7544}
7545
7546bool Context::isProgramPipelineGenerated(GLuint pipeline) const
7547{
7548 return mState.mPipelines->isHandleGenerated(pipeline);
7549}
7550
7551bool Context::usingDisplayTextureShareGroup() const
7552{
7553 return mDisplayTextureShareGroup;
7554}
7555
7556GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
7557{
7558 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
7559 internalformat == GL_DEPTH_STENCIL
7560 ? GL_DEPTH24_STENCIL8
7561 : internalformat;
7562}
7563
jchen1082af6202018-06-22 10:59:52 +08007564void Context::maxShaderCompilerThreads(GLuint count)
7565{
7566 mGLState.setMaxShaderCompilerThreads(count);
7567}
7568
Jamie Madill2eb65032018-07-30 10:25:57 -04007569bool Context::isGLES1() const
7570{
7571 return mState.getClientVersion() < Version(2, 0);
7572}
7573
Jamie Madilla11819d2018-07-30 10:26:01 -04007574void Context::onSubjectStateChange(const Context *context,
7575 angle::SubjectIndex index,
7576 angle::SubjectMessage message)
7577{
7578 ASSERT(message == angle::SubjectMessage::CONTENTS_CHANGED);
7579 switch (index)
7580 {
7581 case kVertexArraySubjectIndex:
7582 mGLState.setObjectDirty(GL_VERTEX_ARRAY);
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04007583 mStateCache.updateVertexElementLimits(this);
Jamie Madilla11819d2018-07-30 10:26:01 -04007584 break;
7585
7586 case kReadFramebufferSubjectIndex:
7587 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
7588 break;
7589
7590 case kDrawFramebufferSubjectIndex:
7591 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
7592 break;
7593
7594 default:
7595 UNREACHABLE();
7596 break;
7597 }
7598}
7599
Jamie Madill6b873dd2018-07-12 23:56:30 -04007600// ErrorSet implementation.
7601ErrorSet::ErrorSet(Context *context) : mContext(context)
7602{
7603}
7604
7605ErrorSet::~ErrorSet() = default;
7606
Jamie Madill306b6c12018-07-27 08:12:49 -04007607void ErrorSet::handleError(const Error &error) const
Jamie Madill6b873dd2018-07-12 23:56:30 -04007608{
7609 // This internal enum is used to filter internal errors that are already handled.
7610 // TODO(jmadill): Remove this when refactor is done. http://anglebug.com/2491
7611 if (error.getCode() == GL_INTERNAL_ERROR_ANGLEX)
7612 {
7613 return;
7614 }
7615
7616 if (ANGLE_UNLIKELY(error.isError()))
7617 {
7618 GLenum code = error.getCode();
7619 mErrors.insert(code);
7620 if (code == GL_OUT_OF_MEMORY && mContext->getWorkarounds().loseContextOnOutOfMemory)
7621 {
7622 mContext->markContextLost();
7623 }
7624
7625 ASSERT(!error.getMessage().empty());
7626 mContext->getGLState().getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR,
7627 error.getID(), GL_DEBUG_SEVERITY_HIGH,
7628 error.getMessage());
7629 }
7630}
7631
7632bool ErrorSet::empty() const
7633{
7634 return mErrors.empty();
7635}
7636
7637GLenum ErrorSet::popError()
7638{
7639 ASSERT(!empty());
7640 GLenum error = *mErrors.begin();
7641 mErrors.erase(mErrors.begin());
7642 return error;
7643}
Jamie Madilldc358af2018-07-31 11:22:13 -04007644
7645// StateCache implementation.
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04007646StateCache::StateCache()
7647 : mCachedHasAnyEnabledClientAttrib(false),
7648 mCachedNonInstancedVertexElementLimit(0),
7649 mCachedInstancedVertexElementLimit(0)
Jamie Madilldc358af2018-07-31 11:22:13 -04007650{
7651}
7652
7653StateCache::~StateCache() = default;
7654
7655void StateCache::updateActiveAttribsMask(Context *context)
7656{
7657 bool isGLES1 = context->isGLES1();
7658 const State &glState = context->getGLState();
7659
7660 if (!isGLES1 && !glState.getProgram())
7661 {
7662 mCachedActiveBufferedAttribsMask = AttributesMask();
7663 mCachedActiveClientAttribsMask = AttributesMask();
7664 return;
7665 }
7666
7667 AttributesMask activeAttribs = isGLES1 ? glState.gles1().getVertexArraysAttributeMask()
7668 : glState.getProgram()->getActiveAttribLocationsMask();
7669
7670 const VertexArray *vao = glState.getVertexArray();
7671 ASSERT(vao);
7672
7673 const AttributesMask &clientAttribs = vao->getClientAttribsMask();
7674 const AttributesMask &enabledAttribs = vao->getEnabledAttributesMask();
7675
7676 activeAttribs &= enabledAttribs;
7677
7678 mCachedActiveClientAttribsMask = activeAttribs & clientAttribs;
7679 mCachedActiveBufferedAttribsMask = activeAttribs & ~clientAttribs;
7680 mCachedHasAnyEnabledClientAttrib = (clientAttribs & enabledAttribs).any();
7681}
Jamie Madilla2d1d2d2018-08-01 11:34:46 -04007682
7683void StateCache::updateVertexElementLimits(Context *context)
7684{
7685 const VertexArray *vao = context->getGLState().getVertexArray();
7686
7687 mCachedNonInstancedVertexElementLimit = std::numeric_limits<GLint64>::max();
7688 mCachedInstancedVertexElementLimit = std::numeric_limits<GLint64>::max();
7689
7690 // VAO can be null on Context startup. If we make this computation lazier we could ASSERT.
7691 // If there are no buffered attributes then we should not limit the draw call count.
7692 if (!vao || !mCachedActiveBufferedAttribsMask.any())
7693 {
7694 return;
7695 }
7696
7697 const auto &vertexAttribs = vao->getVertexAttributes();
7698 const auto &vertexBindings = vao->getVertexBindings();
7699
7700 for (size_t attributeIndex : mCachedActiveBufferedAttribsMask)
7701 {
7702 const VertexAttribute &attrib = vertexAttribs[attributeIndex];
7703 ASSERT(attrib.enabled);
7704
7705 const VertexBinding &binding = vertexBindings[attrib.bindingIndex];
7706 ASSERT(context->isGLES1() ||
7707 context->getGLState().getProgram()->isAttribLocationActive(attributeIndex));
7708
7709 GLint64 limit = attrib.getCachedElementLimit();
7710 if (binding.getDivisor() > 0)
7711 {
7712 mCachedInstancedVertexElementLimit =
7713 std::min(mCachedInstancedVertexElementLimit, limit);
7714 }
7715 else
7716 {
7717 mCachedNonInstancedVertexElementLimit =
7718 std::min(mCachedNonInstancedVertexElementLimit, limit);
7719 }
7720 }
7721}
Jamie Madillc29968b2016-01-20 11:17:23 -05007722} // namespace gl