blob: 4c9d49db3025aa5106f39befc967a594f1ebd678 [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
Geoff Langf6db0982015-08-25 13:04:00 -0400301} // anonymous namespace
302
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000303namespace gl
304{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +0000305
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400306Context::Context(rx::EGLImplFactory *implFactory,
307 const egl::Config *config,
Corentin Wallez51706ea2015-08-07 14:39:22 -0400308 const Context *shareContext,
Geoff Langce02f082017-02-06 16:46:21 -0500309 TextureManager *shareTextures,
Jamie Madill32447362017-06-28 14:53:52 -0400310 MemoryProgramCache *memoryProgramCache,
Corentin Wallezc295e512017-01-27 17:47:50 -0500311 const egl::AttributeMap &attribs,
Brandon Jones2b0cdcc2018-05-02 08:02:50 -0700312 const egl::DisplayExtensions &displayExtensions,
313 const egl::ClientExtensions &clientExtensions)
Jamie Madill5b772312018-03-08 20:28:32 -0500314 : mState(reinterpret_cast<ContextID>(this),
315 shareContext ? &shareContext->mState : nullptr,
316 shareTextures,
317 GetClientVersion(attribs),
318 &mGLState,
319 mCaps,
320 mTextureCaps,
321 mExtensions,
322 mLimitations),
323 mSkipValidation(GetNoError(attribs)),
324 mDisplayTextureShareGroup(shareTextures != nullptr),
325 mSavedArgsType(nullptr),
Geoff Lang3cacf692018-06-20 16:49:57 -0400326 mImplementation(implFactory->createContext(mState, config, shareContext, attribs)),
Geoff Lang75359662018-04-11 01:42:27 -0400327 mLabel(nullptr),
Jamie Madill2f348d22017-06-05 10:50:59 -0400328 mCompiler(),
Geoff Lang4fb8a8b2018-06-01 16:47:57 -0400329 mGLState(GetDebug(attribs),
330 GetBindGeneratesResource(attribs),
331 GetClientArraysEnabled(attribs),
332 GetRobustResourceInit(attribs),
333 memoryProgramCache != nullptr),
Corentin Walleze3b10e82015-05-20 11:06:25 -0400334 mConfig(config),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500335 mClientType(EGL_OPENGL_ES_API),
Jamie Madill6b873dd2018-07-12 23:56:30 -0400336 mErrors(this),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500337 mHasBeenCurrent(false),
338 mContextLost(false),
339 mResetStatus(GL_NO_ERROR),
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700340 mContextLostForced(false),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500341 mResetStrategy(GetResetStrategy(attribs)),
342 mRobustAccess(GetRobustAccess(attribs)),
Geoff Lang33f11fb2018-05-07 13:42:47 -0400343 mSurfacelessSupported(displayExtensions.surfacelessContext),
344 mExplicitContextAvailable(clientExtensions.explicitContext),
Jamie Madill61e16b42017-06-19 11:13:23 -0400345 mCurrentSurface(static_cast<egl::Surface *>(EGL_NO_SURFACE)),
346 mCurrentDisplay(static_cast<egl::Display *>(EGL_NO_DISPLAY)),
Jamie Madille14951e2017-03-09 18:55:16 -0500347 mWebGLContext(GetWebGLContext(attribs)),
Geoff Lang0ab41fa2018-03-14 11:03:30 -0400348 mExtensionsEnabled(GetExtensionsEnabled(attribs, mWebGLContext)),
Jamie Madill32447362017-06-28 14:53:52 -0400349 mMemoryProgramCache(memoryProgramCache),
Jamie Madillb3f26b92017-07-19 15:07:41 -0400350 mScratchBuffer(1000u),
351 mZeroFilledBuffer(1000u)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000352{
Jamie Madill5b772312018-03-08 20:28:32 -0500353 // Needed to solve a Clang warning of unused variables.
Jamie Madillc6dbc252018-04-30 19:07:56 -0400354 ANGLE_UNUSED_VARIABLE(mSavedArgsType);
355 ANGLE_UNUSED_VARIABLE(mParamsBuffer);
Geoff Lang33f11fb2018-05-07 13:42:47 -0400356}
Jamie Madill5b772312018-03-08 20:28:32 -0500357
Geoff Lang33f11fb2018-05-07 13:42:47 -0400358void Context::initialize()
359{
360 mImplementation->setMemoryProgramCache(mMemoryProgramCache);
Jamie Madill14bbb3f2017-09-12 15:23:01 -0400361
Geoff Lang33f11fb2018-05-07 13:42:47 -0400362 initCaps();
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700363 initWorkarounds();
Geoff Langc0b9ef42014-07-02 10:02:37 -0400364
Geoff Lang4fb8a8b2018-06-01 16:47:57 -0400365 mGLState.initialize(this);
Régis Fénéon83107972015-02-05 12:57:44 +0100366
Shannon Woods53a94a82014-06-24 15:20:36 -0400367 mFenceNVHandleAllocator.setBaseHandle(0);
Geoff Lang7dca1862013-07-30 16:30:46 -0400368
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000369 // [OpenGL ES 2.0.24] section 3.7 page 83:
Corentin Wallez336129f2017-10-17 15:55:40 -0400370 // In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have two-dimensional
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000371 // and cube map texture state vectors respectively associated with them.
372 // In order that access to these initial textures not be lost, they are treated as texture
373 // objects all of whose names are 0.
374
Corentin Wallez99d492c2018-02-27 15:17:10 -0500375 Texture *zeroTexture2D = new Texture(mImplementation.get(), 0, TextureType::_2D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800376 mZeroTextures[TextureType::_2D].set(this, zeroTexture2D);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500377
Corentin Wallez99d492c2018-02-27 15:17:10 -0500378 Texture *zeroTextureCube = new Texture(mImplementation.get(), 0, TextureType::CubeMap);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800379 mZeroTextures[TextureType::CubeMap].set(this, zeroTextureCube);
Geoff Lang76b10c92014-09-05 16:28:14 -0400380
Geoff Langeb66a6e2016-10-31 13:06:12 -0400381 if (getClientVersion() >= Version(3, 0))
Geoff Lang76b10c92014-09-05 16:28:14 -0400382 {
383 // TODO: These could also be enabled via extension
Corentin Wallez99d492c2018-02-27 15:17:10 -0500384 Texture *zeroTexture3D = new Texture(mImplementation.get(), 0, TextureType::_3D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800385 mZeroTextures[TextureType::_3D].set(this, zeroTexture3D);
Geoff Lang76b10c92014-09-05 16:28:14 -0400386
Corentin Wallez99d492c2018-02-27 15:17:10 -0500387 Texture *zeroTexture2DArray = new Texture(mImplementation.get(), 0, TextureType::_2DArray);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800388 mZeroTextures[TextureType::_2DArray].set(this, zeroTexture2DArray);
Geoff Lang76b10c92014-09-05 16:28:14 -0400389 }
Geoff Lang3b573612016-10-31 14:08:10 -0400390 if (getClientVersion() >= Version(3, 1))
391 {
392 Texture *zeroTexture2DMultisample =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500393 new Texture(mImplementation.get(), 0, TextureType::_2DMultisample);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800394 mZeroTextures[TextureType::_2DMultisample].set(this, zeroTexture2DMultisample);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800395
Jiajia Qin6eafb042016-12-27 17:04:07 +0800396 for (unsigned int i = 0; i < mCaps.maxAtomicCounterBufferBindings; i++)
397 {
Qin Jiajia339f65b2018-02-27 12:52:48 +0800398 bindBufferRange(BufferBinding::AtomicCounter, i, 0, 0, 0);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800399 }
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800400
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800401 for (unsigned int i = 0; i < mCaps.maxShaderStorageBufferBindings; i++)
402 {
Corentin Wallez336129f2017-10-17 15:55:40 -0400403 bindBufferRange(BufferBinding::ShaderStorage, i, 0, 0, 0);
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800404 }
Geoff Lang3b573612016-10-31 14:08:10 -0400405 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000406
Geoff Langb0f917f2017-12-05 13:41:54 -0500407 if (mSupportedExtensions.textureRectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400408 {
409 Texture *zeroTextureRectangle =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500410 new Texture(mImplementation.get(), 0, TextureType::Rectangle);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800411 mZeroTextures[TextureType::Rectangle].set(this, zeroTextureRectangle);
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400412 }
413
Geoff Langb0f917f2017-12-05 13:41:54 -0500414 if (mSupportedExtensions.eglImageExternal || mSupportedExtensions.eglStreamConsumerExternal)
Ian Ewellbda75592016-04-18 17:25:54 -0400415 {
Corentin Wallez99d492c2018-02-27 15:17:10 -0500416 Texture *zeroTextureExternal = new Texture(mImplementation.get(), 0, TextureType::External);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800417 mZeroTextures[TextureType::External].set(this, zeroTextureExternal);
Ian Ewellbda75592016-04-18 17:25:54 -0400418 }
419
Jamie Madill4928b7c2017-06-20 12:57:39 -0400420 mGLState.initializeZeroTextures(this, mZeroTextures);
Jamie Madille6382c32014-11-07 15:05:26 -0500421
Jamie Madill57a89722013-07-02 11:57:03 -0400422 bindVertexArray(0);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000423
Geoff Langeb66a6e2016-10-31 13:06:12 -0400424 if (getClientVersion() >= Version(3, 0))
Geoff Lang1a683462015-09-29 15:09:59 -0400425 {
426 // [OpenGL ES 3.0.2] section 2.14.1 pg 85:
427 // In the initial state, a default transform feedback object is bound and treated as
428 // a transform feedback object with a name of zero. That object is bound any time
429 // BindTransformFeedback is called with id of zero
Jamie Madillf0dcb8b2017-08-26 19:05:13 -0400430 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Geoff Lang1a683462015-09-29 15:09:59 -0400431 }
Geoff Langc8058452014-02-03 12:04:11 -0500432
Corentin Wallez336129f2017-10-17 15:55:40 -0400433 for (auto type : angle::AllEnums<BufferBinding>())
434 {
435 bindBuffer(type, 0);
436 }
437
438 bindRenderbuffer(GL_RENDERBUFFER, 0);
439
440 for (unsigned int i = 0; i < mCaps.maxUniformBufferBindings; i++)
441 {
442 bindBufferRange(BufferBinding::Uniform, i, 0, 0, -1);
443 }
444
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700445 // Initialize GLES1 renderer if appropriate.
446 if (getClientVersion() < Version(2, 0))
447 {
448 mGLES1Renderer.reset(new GLES1Renderer());
449 }
450
Jamie Madillad9f24e2016-02-12 09:27:24 -0500451 // Initialize dirty bit masks
Geoff Lang9bf86f02018-07-26 11:46:34 -0400452 mDrawDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
453 mDrawDirtyObjects.set(State::DIRTY_OBJECT_VERTEX_ARRAY);
454 mDrawDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM_TEXTURES);
455
456 mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
457 mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_VERTEX_ARRAY);
458 mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM_TEXTURES);
459
Jamie Madillc67323a2017-11-02 23:11:41 -0400460 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500461 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500462 // No dirty objects.
463
464 // Readpixels uses the pack state and read FBO
Jamie Madillc67323a2017-11-02 23:11:41 -0400465 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500466 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_BUFFER_BINDING);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400467 mReadPixelsDirtyBits.set(State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500468 mReadPixelsDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
469
470 mClearDirtyBits.set(State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED);
471 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
472 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR);
473 mClearDirtyBits.set(State::DIRTY_BIT_VIEWPORT);
474 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_COLOR);
475 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_DEPTH);
476 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_STENCIL);
477 mClearDirtyBits.set(State::DIRTY_BIT_COLOR_MASK);
478 mClearDirtyBits.set(State::DIRTY_BIT_DEPTH_MASK);
479 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT);
480 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_BACK);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400481 mClearDirtyBits.set(State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500482 mClearDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
483
484 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
485 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR);
Geoff Lang1d2c41d2016-10-19 16:14:46 -0700486 mBlitDirtyBits.set(State::DIRTY_BIT_FRAMEBUFFER_SRGB);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400487 mBlitDirtyBits.set(State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
488 mBlitDirtyBits.set(State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500489 mBlitDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
490 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
Jamie Madill437fa652016-05-03 15:13:24 -0400491
Xinghua Cao10a4d432017-11-28 14:46:26 +0800492 // TODO(xinghua.cao@intel.com): add other dirty bits and dirty objects.
493 mComputeDirtyBits.set(State::DIRTY_BIT_SHADER_STORAGE_BUFFER_BINDING);
494 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_BINDING);
495 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_EXECUTABLE);
496 mComputeDirtyBits.set(State::DIRTY_BIT_TEXTURE_BINDINGS);
497 mComputeDirtyBits.set(State::DIRTY_BIT_SAMPLER_BINDINGS);
Qin Jiajia62fcf622017-11-30 16:16:12 +0800498 mComputeDirtyBits.set(State::DIRTY_BIT_DISPATCH_INDIRECT_BUFFER_BINDING);
Jiajia Qin5ae6ee42018-03-06 17:39:42 +0800499 mComputeDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM_TEXTURES);
Xinghua Cao10a4d432017-11-28 14:46:26 +0800500
Jamie Madillb4927eb2018-07-16 11:39:46 -0400501 mImplementation->setErrorSet(&mErrors);
502
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400503 handleError(mImplementation->initialize());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000504}
505
Jamie Madill4928b7c2017-06-20 12:57:39 -0400506egl::Error Context::onDestroy(const egl::Display *display)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000507{
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700508 if (mGLES1Renderer)
509 {
510 mGLES1Renderer->onDestroy(this, &mGLState);
511 }
512
Jamie Madille7b3fe22018-04-05 09:42:46 -0400513 // Delete the Surface first to trigger a finish() in Vulkan.
Jamie Madille7b3fe22018-04-05 09:42:46 -0400514 ANGLE_TRY(releaseSurface(display));
515
Corentin Wallez80b24112015-08-25 16:41:57 -0400516 for (auto fence : mFenceNVMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000517 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400518 SafeDelete(fence.second);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000519 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400520 mFenceNVMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000521
Corentin Wallez80b24112015-08-25 16:41:57 -0400522 for (auto query : mQueryMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000523 {
Geoff Langf0aa8422015-09-29 15:08:34 -0400524 if (query.second != nullptr)
525 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400526 query.second->release(this);
Geoff Langf0aa8422015-09-29 15:08:34 -0400527 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000528 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400529 mQueryMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000530
Corentin Wallez80b24112015-08-25 16:41:57 -0400531 for (auto vertexArray : mVertexArrayMap)
Jamie Madill57a89722013-07-02 11:57:03 -0400532 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400533 if (vertexArray.second)
534 {
535 vertexArray.second->onDestroy(this);
536 }
Jamie Madill57a89722013-07-02 11:57:03 -0400537 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400538 mVertexArrayMap.clear();
Jamie Madill57a89722013-07-02 11:57:03 -0400539
Corentin Wallez80b24112015-08-25 16:41:57 -0400540 for (auto transformFeedback : mTransformFeedbackMap)
Geoff Langc8058452014-02-03 12:04:11 -0500541 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500542 if (transformFeedback.second != nullptr)
543 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500544 transformFeedback.second->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500545 }
Geoff Langc8058452014-02-03 12:04:11 -0500546 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400547 mTransformFeedbackMap.clear();
Geoff Langc8058452014-02-03 12:04:11 -0500548
Jamie Madill5b772312018-03-08 20:28:32 -0500549 for (BindingPointer<Texture> &zeroTexture : mZeroTextures)
Geoff Lang76b10c92014-09-05 16:28:14 -0400550 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800551 if (zeroTexture.get() != nullptr)
552 {
553 ANGLE_TRY(zeroTexture->onDestroy(this));
554 zeroTexture.set(this, nullptr);
555 }
Geoff Lang76b10c92014-09-05 16:28:14 -0400556 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000557
Jamie Madill2f348d22017-06-05 10:50:59 -0400558 releaseShaderCompiler();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500559
Jamie Madill4928b7c2017-06-20 12:57:39 -0400560 mGLState.reset(this);
561
Jamie Madill6c1f6712017-02-14 19:08:04 -0500562 mState.mBuffers->release(this);
563 mState.mShaderPrograms->release(this);
564 mState.mTextures->release(this);
565 mState.mRenderbuffers->release(this);
566 mState.mSamplers->release(this);
Jamie Madill70b5bb02017-08-28 13:32:37 -0400567 mState.mSyncs->release(this);
Jamie Madill6c1f6712017-02-14 19:08:04 -0500568 mState.mPaths->release(this);
569 mState.mFramebuffers->release(this);
Yunchao Hea336b902017-08-02 16:05:21 +0800570 mState.mPipelines->release(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400571
Jamie Madill76e471e2017-10-21 09:56:01 -0400572 mImplementation->onDestroy(this);
573
Jamie Madill4928b7c2017-06-20 12:57:39 -0400574 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000575}
576
Jamie Madill70ee0f62017-02-06 16:04:20 -0500577Context::~Context()
578{
579}
580
Geoff Lang75359662018-04-11 01:42:27 -0400581void Context::setLabel(EGLLabelKHR label)
582{
583 mLabel = label;
584}
585
586EGLLabelKHR Context::getLabel() const
587{
588 return mLabel;
589}
590
Jamie Madill4928b7c2017-06-20 12:57:39 -0400591egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000592{
Jamie Madill61e16b42017-06-19 11:13:23 -0400593 mCurrentDisplay = display;
594
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000595 if (!mHasBeenCurrent)
596 {
Geoff Lang33f11fb2018-05-07 13:42:47 -0400597 initialize();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000598 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500599 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400600 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000601
Corentin Wallezc295e512017-01-27 17:47:50 -0500602 int width = 0;
603 int height = 0;
604 if (surface != nullptr)
605 {
606 width = surface->getWidth();
607 height = surface->getHeight();
608 }
609
610 mGLState.setViewportParams(0, 0, width, height);
611 mGLState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000612
613 mHasBeenCurrent = true;
614 }
615
Jamie Madill1b94d432015-08-07 13:23:23 -0400616 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700617 mGLState.setAllDirtyBits();
Jamie Madill81c2e252017-09-09 23:32:46 -0400618 mGLState.setAllDirtyObjects();
Jamie Madill1b94d432015-08-07 13:23:23 -0400619
Jamie Madill4928b7c2017-06-20 12:57:39 -0400620 ANGLE_TRY(releaseSurface(display));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500621
622 Framebuffer *newDefault = nullptr;
623 if (surface != nullptr)
624 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400625 ANGLE_TRY(surface->setIsCurrent(this, true));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500626 mCurrentSurface = surface;
Geoff Langbf7b95d2018-05-01 16:48:21 -0400627 newDefault = surface->createDefaultFramebuffer(this);
Corentin Wallezccab69d2017-01-27 16:57:15 -0500628 }
629 else
630 {
Geoff Langbf7b95d2018-05-01 16:48:21 -0400631 newDefault = new Framebuffer(mImplementation.get());
Corentin Wallezccab69d2017-01-27 16:57:15 -0500632 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000633
Corentin Wallez37c39792015-08-20 14:19:46 -0400634 // Update default framebuffer, the binding of the previous default
635 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400636 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700637 if (mGLState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400638 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700639 mGLState.setReadFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400640 }
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700641 if (mGLState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400642 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700643 mGLState.setDrawFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400644 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500645 mState.mFramebuffers->setDefaultFramebuffer(newDefault);
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400646 }
Ian Ewell292f0052016-02-04 10:37:32 -0500647
648 // Notify the renderer of a context switch
Luc Ferron5396f2a2018-07-12 08:24:23 -0400649 ANGLE_TRY(mImplementation->onMakeCurrent(this));
Jamie Madill4928b7c2017-06-20 12:57:39 -0400650 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000651}
652
Jamie Madill4928b7c2017-06-20 12:57:39 -0400653egl::Error Context::releaseSurface(const egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400654{
Geoff Langbf7b95d2018-05-01 16:48:21 -0400655 gl::Framebuffer *defaultFramebuffer = mState.mFramebuffers->getFramebuffer(0);
Corentin Wallez51706ea2015-08-07 14:39:22 -0400656
Geoff Langbf7b95d2018-05-01 16:48:21 -0400657 // Remove the default framebuffer
658 if (mGLState.getReadFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500659 {
660 mGLState.setReadFramebufferBinding(nullptr);
661 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400662
663 if (mGLState.getDrawFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500664 {
665 mGLState.setDrawFramebufferBinding(nullptr);
666 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400667
668 if (defaultFramebuffer)
669 {
670 defaultFramebuffer->onDestroy(this);
671 delete defaultFramebuffer;
672 }
673
Corentin Wallezc295e512017-01-27 17:47:50 -0500674 mState.mFramebuffers->setDefaultFramebuffer(nullptr);
675
676 if (mCurrentSurface)
677 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400678 ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
Corentin Wallezc295e512017-01-27 17:47:50 -0500679 mCurrentSurface = nullptr;
680 }
Jamie Madill4928b7c2017-06-20 12:57:39 -0400681
682 return egl::NoError();
Jamie Madill77a72f62015-04-14 11:18:32 -0400683}
684
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000685GLuint Context::createBuffer()
686{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500687 return mState.mBuffers->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000688}
689
690GLuint Context::createProgram()
691{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500692 return mState.mShaderPrograms->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000693}
694
Jiawei Shao385b3e02018-03-21 09:43:28 +0800695GLuint Context::createShader(ShaderType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000696{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500697 return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000698}
699
700GLuint Context::createTexture()
701{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500702 return mState.mTextures->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000703}
704
705GLuint Context::createRenderbuffer()
706{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500707 return mState.mRenderbuffers->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000708}
709
Brandon Jones59770802018-04-02 13:18:42 -0700710GLuint Context::genPaths(GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300711{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500712 auto resultOrError = mState.mPaths->createPaths(mImplementation.get(), range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300713 if (resultOrError.isError())
714 {
715 handleError(resultOrError.getError());
716 return 0;
717 }
718 return resultOrError.getResult();
719}
720
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000721// Returns an unused framebuffer name
722GLuint Context::createFramebuffer()
723{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500724 return mState.mFramebuffers->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000725}
726
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500727void Context::genFencesNV(GLsizei n, GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000728{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500729 for (int i = 0; i < n; i++)
730 {
731 GLuint handle = mFenceNVHandleAllocator.allocate();
732 mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV()));
733 fences[i] = handle;
734 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000735}
736
Yunchao Hea336b902017-08-02 16:05:21 +0800737GLuint Context::createProgramPipeline()
738{
739 return mState.mPipelines->createProgramPipeline();
740}
741
Jiawei Shao385b3e02018-03-21 09:43:28 +0800742GLuint Context::createShaderProgramv(ShaderType type, GLsizei count, const GLchar *const *strings)
Jiajia Qin5451d532017-11-16 17:16:34 +0800743{
744 UNIMPLEMENTED();
745 return 0u;
746}
747
James Darpinian4d9d4832018-03-13 12:43:28 -0700748void Context::deleteBuffer(GLuint bufferName)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000749{
James Darpinian4d9d4832018-03-13 12:43:28 -0700750 Buffer *buffer = mState.mBuffers->getBuffer(bufferName);
751 if (buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000752 {
753 detachBuffer(buffer);
754 }
Jamie Madill893ab082014-05-16 16:56:10 -0400755
James Darpinian4d9d4832018-03-13 12:43:28 -0700756 mState.mBuffers->deleteObject(this, bufferName);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000757}
758
759void Context::deleteShader(GLuint shader)
760{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500761 mState.mShaderPrograms->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000762}
763
764void Context::deleteProgram(GLuint program)
765{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500766 mState.mShaderPrograms->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000767}
768
769void Context::deleteTexture(GLuint texture)
770{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500771 if (mState.mTextures->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000772 {
773 detachTexture(texture);
774 }
775
Jamie Madill6c1f6712017-02-14 19:08:04 -0500776 mState.mTextures->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000777}
778
779void Context::deleteRenderbuffer(GLuint renderbuffer)
780{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500781 if (mState.mRenderbuffers->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000782 {
783 detachRenderbuffer(renderbuffer);
784 }
Jamie Madill893ab082014-05-16 16:56:10 -0400785
Jamie Madill6c1f6712017-02-14 19:08:04 -0500786 mState.mRenderbuffers->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000787}
788
Jamie Madill7f0c5a42017-08-26 22:43:26 -0400789void Context::deleteSync(GLsync sync)
Jamie Madillcd055f82013-07-26 11:55:15 -0400790{
791 // The spec specifies the underlying Fence object is not deleted until all current
792 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
793 // and since our API is currently designed for being called from a single thread, we can delete
794 // the fence immediately.
Jamie Madill70b5bb02017-08-28 13:32:37 -0400795 mState.mSyncs->deleteObject(this, static_cast<GLuint>(reinterpret_cast<uintptr_t>(sync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400796}
797
Yunchao Hea336b902017-08-02 16:05:21 +0800798void Context::deleteProgramPipeline(GLuint pipeline)
799{
800 if (mState.mPipelines->getProgramPipeline(pipeline))
801 {
802 detachProgramPipeline(pipeline);
803 }
804
805 mState.mPipelines->deleteObject(this, pipeline);
806}
807
Sami Väisänene45e53b2016-05-25 10:36:04 +0300808void Context::deletePaths(GLuint first, GLsizei range)
809{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500810 mState.mPaths->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300811}
812
Brandon Jones59770802018-04-02 13:18:42 -0700813bool Context::isPath(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300814{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500815 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300816 if (pathObj == nullptr)
817 return false;
818
819 return pathObj->hasPathData();
820}
821
Brandon Jones59770802018-04-02 13:18:42 -0700822bool Context::isPathGenerated(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300823{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500824 return mState.mPaths->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300825}
826
Brandon Jones59770802018-04-02 13:18:42 -0700827void Context::pathCommands(GLuint path,
828 GLsizei numCommands,
829 const GLubyte *commands,
830 GLsizei numCoords,
831 GLenum coordType,
832 const void *coords)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300833{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500834 auto *pathObject = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300835
836 handleError(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
837}
838
Jamie Madill007530e2017-12-28 14:27:04 -0500839void Context::pathParameterf(GLuint path, GLenum pname, GLfloat value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300840{
Jamie Madill007530e2017-12-28 14:27:04 -0500841 Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300842
843 switch (pname)
844 {
845 case GL_PATH_STROKE_WIDTH_CHROMIUM:
846 pathObj->setStrokeWidth(value);
847 break;
848 case GL_PATH_END_CAPS_CHROMIUM:
849 pathObj->setEndCaps(static_cast<GLenum>(value));
850 break;
851 case GL_PATH_JOIN_STYLE_CHROMIUM:
852 pathObj->setJoinStyle(static_cast<GLenum>(value));
853 break;
854 case GL_PATH_MITER_LIMIT_CHROMIUM:
855 pathObj->setMiterLimit(value);
856 break;
857 case GL_PATH_STROKE_BOUND_CHROMIUM:
858 pathObj->setStrokeBound(value);
859 break;
860 default:
861 UNREACHABLE();
862 break;
863 }
864}
865
Jamie Madill007530e2017-12-28 14:27:04 -0500866void Context::pathParameteri(GLuint path, GLenum pname, GLint value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300867{
Jamie Madill007530e2017-12-28 14:27:04 -0500868 // TODO(jmadill): Should use proper clamping/casting.
869 pathParameterf(path, pname, static_cast<GLfloat>(value));
870}
871
872void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value)
873{
874 const Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300875
876 switch (pname)
877 {
878 case GL_PATH_STROKE_WIDTH_CHROMIUM:
879 *value = pathObj->getStrokeWidth();
880 break;
881 case GL_PATH_END_CAPS_CHROMIUM:
882 *value = static_cast<GLfloat>(pathObj->getEndCaps());
883 break;
884 case GL_PATH_JOIN_STYLE_CHROMIUM:
885 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
886 break;
887 case GL_PATH_MITER_LIMIT_CHROMIUM:
888 *value = pathObj->getMiterLimit();
889 break;
890 case GL_PATH_STROKE_BOUND_CHROMIUM:
891 *value = pathObj->getStrokeBound();
892 break;
893 default:
894 UNREACHABLE();
895 break;
896 }
897}
898
Jamie Madill007530e2017-12-28 14:27:04 -0500899void Context::getPathParameteriv(GLuint path, GLenum pname, GLint *value)
900{
901 GLfloat val = 0.0f;
902 getPathParameterfv(path, pname, value != nullptr ? &val : nullptr);
903 if (value)
904 *value = static_cast<GLint>(val);
905}
906
Brandon Jones59770802018-04-02 13:18:42 -0700907void Context::pathStencilFunc(GLenum func, GLint ref, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300908{
909 mGLState.setPathStencilFunc(func, ref, mask);
910}
911
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000912void Context::deleteFramebuffer(GLuint framebuffer)
913{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500914 if (mState.mFramebuffers->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000915 {
916 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000917 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500918
Jamie Madill6c1f6712017-02-14 19:08:04 -0500919 mState.mFramebuffers->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000920}
921
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500922void Context::deleteFencesNV(GLsizei n, const GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000923{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500924 for (int i = 0; i < n; i++)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000925 {
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500926 GLuint fence = fences[i];
927
928 FenceNV *fenceObject = nullptr;
929 if (mFenceNVMap.erase(fence, &fenceObject))
930 {
931 mFenceNVHandleAllocator.release(fence);
932 delete fenceObject;
933 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000934 }
935}
936
Geoff Lang70d0f492015-12-10 17:45:46 -0500937Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000938{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500939 return mState.mBuffers->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000940}
941
Jamie Madill570f7c82014-07-03 10:38:54 -0400942Texture *Context::getTexture(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000943{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500944 return mState.mTextures->getTexture(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000945}
946
Geoff Lang70d0f492015-12-10 17:45:46 -0500947Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000948{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500949 return mState.mRenderbuffers->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000950}
951
Jamie Madill70b5bb02017-08-28 13:32:37 -0400952Sync *Context::getSync(GLsync handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400953{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400954 return mState.mSyncs->getSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400955}
956
Jamie Madill57a89722013-07-02 11:57:03 -0400957VertexArray *Context::getVertexArray(GLuint handle) const
958{
Jamie Madill96a483b2017-06-27 16:49:21 -0400959 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -0400960}
961
Jamie Madilldc356042013-07-19 16:36:57 -0400962Sampler *Context::getSampler(GLuint handle) const
963{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500964 return mState.mSamplers->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400965}
966
Geoff Langc8058452014-02-03 12:04:11 -0500967TransformFeedback *Context::getTransformFeedback(GLuint handle) const
968{
Jamie Madill96a483b2017-06-27 16:49:21 -0400969 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -0500970}
971
Yunchao Hea336b902017-08-02 16:05:21 +0800972ProgramPipeline *Context::getProgramPipeline(GLuint handle) const
973{
974 return mState.mPipelines->getProgramPipeline(handle);
975}
976
Geoff Lang75359662018-04-11 01:42:27 -0400977gl::LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
Geoff Lang70d0f492015-12-10 17:45:46 -0500978{
979 switch (identifier)
980 {
981 case GL_BUFFER:
982 return getBuffer(name);
983 case GL_SHADER:
984 return getShader(name);
985 case GL_PROGRAM:
986 return getProgram(name);
987 case GL_VERTEX_ARRAY:
988 return getVertexArray(name);
989 case GL_QUERY:
990 return getQuery(name);
991 case GL_TRANSFORM_FEEDBACK:
992 return getTransformFeedback(name);
993 case GL_SAMPLER:
994 return getSampler(name);
995 case GL_TEXTURE:
996 return getTexture(name);
997 case GL_RENDERBUFFER:
998 return getRenderbuffer(name);
999 case GL_FRAMEBUFFER:
1000 return getFramebuffer(name);
1001 default:
1002 UNREACHABLE();
1003 return nullptr;
1004 }
1005}
1006
Geoff Lang75359662018-04-11 01:42:27 -04001007gl::LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
Geoff Lang70d0f492015-12-10 17:45:46 -05001008{
Jamie Madill70b5bb02017-08-28 13:32:37 -04001009 return getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
Geoff Lang70d0f492015-12-10 17:45:46 -05001010}
1011
Martin Radev9d901792016-07-15 15:58:58 +03001012void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
1013{
Geoff Lang75359662018-04-11 01:42:27 -04001014 gl::LabeledObject *object = getLabeledObject(identifier, name);
Martin Radev9d901792016-07-15 15:58:58 +03001015 ASSERT(object != nullptr);
1016
1017 std::string labelName = GetObjectLabelFromPointer(length, label);
1018 object->setLabel(labelName);
Jamie Madill8693bdb2017-09-02 15:32:14 -04001019
1020 // TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the
1021 // specified object is active until we do this.
1022 mGLState.setObjectDirty(identifier);
Martin Radev9d901792016-07-15 15:58:58 +03001023}
1024
1025void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
1026{
Geoff Lang75359662018-04-11 01:42:27 -04001027 gl::LabeledObject *object = getLabeledObjectFromPtr(ptr);
Martin Radev9d901792016-07-15 15:58:58 +03001028 ASSERT(object != nullptr);
1029
1030 std::string labelName = GetObjectLabelFromPointer(length, label);
1031 object->setLabel(labelName);
1032}
1033
1034void Context::getObjectLabel(GLenum identifier,
1035 GLuint name,
1036 GLsizei bufSize,
1037 GLsizei *length,
1038 GLchar *label) const
1039{
Geoff Lang75359662018-04-11 01:42:27 -04001040 gl::LabeledObject *object = getLabeledObject(identifier, name);
Martin Radev9d901792016-07-15 15:58:58 +03001041 ASSERT(object != nullptr);
1042
1043 const std::string &objectLabel = object->getLabel();
1044 GetObjectLabelBase(objectLabel, bufSize, length, label);
1045}
1046
1047void Context::getObjectPtrLabel(const void *ptr,
1048 GLsizei bufSize,
1049 GLsizei *length,
1050 GLchar *label) const
1051{
Geoff Lang75359662018-04-11 01:42:27 -04001052 gl::LabeledObject *object = getLabeledObjectFromPtr(ptr);
Martin Radev9d901792016-07-15 15:58:58 +03001053 ASSERT(object != nullptr);
1054
1055 const std::string &objectLabel = object->getLabel();
1056 GetObjectLabelBase(objectLabel, bufSize, length, label);
1057}
1058
Jamie Madilldc356042013-07-19 16:36:57 -04001059bool Context::isSampler(GLuint samplerName) const
1060{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001061 return mState.mSamplers->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -04001062}
1063
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001064void Context::bindTexture(TextureType target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001065{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001066 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001067
Jamie Madilldedd7b92014-11-05 16:30:36 -05001068 if (handle == 0)
1069 {
1070 texture = mZeroTextures[target].get();
1071 }
1072 else
1073 {
Corentin Wallez99d492c2018-02-27 15:17:10 -05001074 texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -05001075 }
1076
1077 ASSERT(texture);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001078 mGLState.setSamplerTexture(this, target, texture);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00001079}
1080
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001081void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001082{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001083 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1084 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001085 mGLState.setReadFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001086}
1087
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001088void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001089{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001090 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1091 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001092 mGLState.setDrawFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001093}
1094
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001095void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -04001096{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001097 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madill7267aa62018-04-17 15:28:21 -04001098 mGLState.setVertexArrayBinding(this, vertexArray);
Jamie Madilldc358af2018-07-31 11:22:13 -04001099 mStateCache.updateActiveAttribsMask(this);
Jamie Madill57a89722013-07-02 11:57:03 -04001100}
1101
Shao80957d92017-02-20 21:25:59 +08001102void Context::bindVertexBuffer(GLuint bindingIndex,
1103 GLuint bufferHandle,
1104 GLintptr offset,
1105 GLsizei stride)
1106{
1107 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001108 mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Jamie Madilldc358af2018-07-31 11:22:13 -04001109 mStateCache.updateActiveAttribsMask(this);
Shao80957d92017-02-20 21:25:59 +08001110}
1111
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001112void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -04001113{
Geoff Lang76b10c92014-09-05 16:28:14 -04001114 ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -04001115 Sampler *sampler =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001116 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001117 mGLState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04001118}
1119
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001120void Context::bindImageTexture(GLuint unit,
1121 GLuint texture,
1122 GLint level,
1123 GLboolean layered,
1124 GLint layer,
1125 GLenum access,
1126 GLenum format)
1127{
1128 Texture *tex = mState.mTextures->getTexture(texture);
1129 mGLState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
1130}
1131
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001132void Context::useProgram(GLuint program)
1133{
Jamie Madill6c1f6712017-02-14 19:08:04 -05001134 mGLState.setProgram(this, getProgram(program));
Jamie Madilldc358af2018-07-31 11:22:13 -04001135 mStateCache.updateActiveAttribsMask(this);
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001136}
1137
Jiajia Qin5451d532017-11-16 17:16:34 +08001138void Context::useProgramStages(GLuint pipeline, GLbitfield stages, GLuint program)
1139{
1140 UNIMPLEMENTED();
1141}
1142
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001143void Context::bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001144{
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001145 ASSERT(target == GL_TRANSFORM_FEEDBACK);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001146 TransformFeedback *transformFeedback =
1147 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001148 mGLState.setTransformFeedbackBinding(this, transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -05001149}
1150
Yunchao Hea336b902017-08-02 16:05:21 +08001151void Context::bindProgramPipeline(GLuint pipelineHandle)
1152{
1153 ProgramPipeline *pipeline =
1154 mState.mPipelines->checkProgramPipelineAllocation(mImplementation.get(), pipelineHandle);
1155 mGLState.setProgramPipelineBinding(this, pipeline);
1156}
1157
Corentin Wallezad3ae902018-03-09 13:40:42 -05001158void Context::beginQuery(QueryType target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001159{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001160 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001161 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001162
Geoff Lang5aad9672014-09-08 11:10:42 -04001163 // begin query
Jamie Madill5188a272018-07-25 10:53:56 -04001164 ANGLE_CONTEXT_TRY(queryObject->begin(this));
Geoff Lang5aad9672014-09-08 11:10:42 -04001165
1166 // set query as active for specified target only if begin succeeded
Jamie Madill4928b7c2017-06-20 12:57:39 -04001167 mGLState.setActiveQuery(this, target, queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001168}
1169
Corentin Wallezad3ae902018-03-09 13:40:42 -05001170void Context::endQuery(QueryType target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001171{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001172 Query *queryObject = mGLState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001173 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001174
Jamie Madill5188a272018-07-25 10:53:56 -04001175 handleError(queryObject->end(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001176
Geoff Lang5aad9672014-09-08 11:10:42 -04001177 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madill4928b7c2017-06-20 12:57:39 -04001178 mGLState.setActiveQuery(this, target, nullptr);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001179}
1180
Corentin Wallezad3ae902018-03-09 13:40:42 -05001181void Context::queryCounter(GLuint id, QueryType target)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001182{
Corentin Wallezad3ae902018-03-09 13:40:42 -05001183 ASSERT(target == QueryType::Timestamp);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001184
1185 Query *queryObject = getQuery(id, true, target);
1186 ASSERT(queryObject);
1187
Jamie Madill5188a272018-07-25 10:53:56 -04001188 handleError(queryObject->queryCounter(this));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001189}
1190
Corentin Wallezad3ae902018-03-09 13:40:42 -05001191void Context::getQueryiv(QueryType target, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001192{
1193 switch (pname)
1194 {
1195 case GL_CURRENT_QUERY_EXT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001196 params[0] = mGLState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001197 break;
1198 case GL_QUERY_COUNTER_BITS_EXT:
1199 switch (target)
1200 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001201 case QueryType::TimeElapsed:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001202 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1203 break;
Corentin Wallezad3ae902018-03-09 13:40:42 -05001204 case QueryType::Timestamp:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001205 params[0] = getExtensions().queryCounterBitsTimestamp;
1206 break;
1207 default:
1208 UNREACHABLE();
1209 params[0] = 0;
1210 break;
1211 }
1212 break;
1213 default:
1214 UNREACHABLE();
1215 return;
1216 }
1217}
1218
Corentin Wallezad3ae902018-03-09 13:40:42 -05001219void Context::getQueryivRobust(QueryType target,
Brandon Jones59770802018-04-02 13:18:42 -07001220 GLenum pname,
1221 GLsizei bufSize,
1222 GLsizei *length,
1223 GLint *params)
1224{
1225 getQueryiv(target, pname, params);
1226}
1227
Geoff Lang2186c382016-10-14 10:54:54 -04001228void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001229{
Jamie Madill5188a272018-07-25 10:53:56 -04001230 handleError(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001231}
1232
Brandon Jones59770802018-04-02 13:18:42 -07001233void Context::getQueryObjectivRobust(GLuint id,
1234 GLenum pname,
1235 GLsizei bufSize,
1236 GLsizei *length,
1237 GLint *params)
1238{
1239 getQueryObjectiv(id, pname, params);
1240}
1241
Geoff Lang2186c382016-10-14 10:54:54 -04001242void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001243{
Jamie Madill5188a272018-07-25 10:53:56 -04001244 handleError(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001245}
1246
Brandon Jones59770802018-04-02 13:18:42 -07001247void Context::getQueryObjectuivRobust(GLuint id,
1248 GLenum pname,
1249 GLsizei bufSize,
1250 GLsizei *length,
1251 GLuint *params)
1252{
1253 getQueryObjectuiv(id, pname, params);
1254}
1255
Geoff Lang2186c382016-10-14 10:54:54 -04001256void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001257{
Jamie Madill5188a272018-07-25 10:53:56 -04001258 handleError(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001259}
1260
Brandon Jones59770802018-04-02 13:18:42 -07001261void Context::getQueryObjecti64vRobust(GLuint id,
1262 GLenum pname,
1263 GLsizei bufSize,
1264 GLsizei *length,
1265 GLint64 *params)
1266{
1267 getQueryObjecti64v(id, pname, params);
1268}
1269
Geoff Lang2186c382016-10-14 10:54:54 -04001270void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001271{
Jamie Madill5188a272018-07-25 10:53:56 -04001272 handleError(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001273}
1274
Brandon Jones59770802018-04-02 13:18:42 -07001275void Context::getQueryObjectui64vRobust(GLuint id,
1276 GLenum pname,
1277 GLsizei bufSize,
1278 GLsizei *length,
1279 GLuint64 *params)
1280{
1281 getQueryObjectui64v(id, pname, params);
1282}
1283
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001284Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001285{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001286 return mState.mFramebuffers->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001287}
1288
Jamie Madill2f348d22017-06-05 10:50:59 -04001289FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001290{
Jamie Madill96a483b2017-06-27 16:49:21 -04001291 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001292}
1293
Corentin Wallezad3ae902018-03-09 13:40:42 -05001294Query *Context::getQuery(GLuint handle, bool create, QueryType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001295{
Jamie Madill96a483b2017-06-27 16:49:21 -04001296 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001297 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001298 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001299 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001300
1301 Query *query = mQueryMap.query(handle);
1302 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001303 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001304 ASSERT(type != QueryType::InvalidEnum);
Jamie Madill96a483b2017-06-27 16:49:21 -04001305 query = new Query(mImplementation->createQuery(type), handle);
1306 query->addRef();
1307 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001308 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001309 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001310}
1311
Geoff Lang70d0f492015-12-10 17:45:46 -05001312Query *Context::getQuery(GLuint handle) const
1313{
Jamie Madill96a483b2017-06-27 16:49:21 -04001314 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001315}
1316
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001317Texture *Context::getTargetTexture(TextureType type) const
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001318{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001319 ASSERT(ValidTextureTarget(this, type) || ValidTextureExternalTarget(this, type));
1320 return mGLState.getTargetTexture(type);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001321}
1322
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001323Texture *Context::getSamplerTexture(unsigned int sampler, TextureType type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001324{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001325 return mGLState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001326}
1327
Geoff Lang492a7e42014-11-05 13:27:06 -05001328Compiler *Context::getCompiler() const
1329{
Jamie Madill2f348d22017-06-05 10:50:59 -04001330 if (mCompiler.get() == nullptr)
1331 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001332 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001333 }
1334 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001335}
1336
Jamie Madillc1d770e2017-04-13 17:31:24 -04001337void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001338{
1339 switch (pname)
1340 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001341 case GL_SHADER_COMPILER:
1342 *params = GL_TRUE;
1343 break;
1344 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1345 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1346 break;
1347 default:
1348 mGLState.getBooleanv(pname, params);
1349 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001350 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001351}
1352
Jamie Madillc1d770e2017-04-13 17:31:24 -04001353void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001354{
Shannon Woods53a94a82014-06-24 15:20:36 -04001355 // Queries about context capabilities and maximums are answered by Context.
1356 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001357 switch (pname)
1358 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001359 case GL_ALIASED_LINE_WIDTH_RANGE:
1360 params[0] = mCaps.minAliasedLineWidth;
1361 params[1] = mCaps.maxAliasedLineWidth;
1362 break;
1363 case GL_ALIASED_POINT_SIZE_RANGE:
1364 params[0] = mCaps.minAliasedPointSize;
1365 params[1] = mCaps.maxAliasedPointSize;
1366 break;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07001367 case GL_SMOOTH_POINT_SIZE_RANGE:
1368 params[0] = mCaps.minSmoothPointSize;
1369 params[1] = mCaps.maxSmoothPointSize;
1370 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001371 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1372 ASSERT(mExtensions.textureFilterAnisotropic);
1373 *params = mExtensions.maxTextureAnisotropy;
1374 break;
1375 case GL_MAX_TEXTURE_LOD_BIAS:
1376 *params = mCaps.maxLODBias;
1377 break;
1378
1379 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1380 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1381 {
Lingfeng Yang3a41af62018-04-09 07:28:56 -07001382 // GLES1 emulation: // GL_PATH_(MODELVIEW|PROJECTION)_MATRIX_CHROMIUM collides with the
1383 // GLES1 constants for modelview/projection matrix.
1384 if (getClientVersion() < Version(2, 0))
1385 {
1386 mGLState.getFloatv(pname, params);
1387 }
1388 else
1389 {
1390 ASSERT(mExtensions.pathRendering);
1391 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1392 memcpy(params, m, 16 * sizeof(GLfloat));
1393 }
Jamie Madill231c7f52017-04-26 13:45:37 -04001394 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001395 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001396
Jamie Madill231c7f52017-04-26 13:45:37 -04001397 default:
1398 mGLState.getFloatv(pname, params);
1399 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001400 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001401}
1402
Jamie Madillc1d770e2017-04-13 17:31:24 -04001403void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001404{
Shannon Woods53a94a82014-06-24 15:20:36 -04001405 // Queries about context capabilities and maximums are answered by Context.
1406 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001407
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001408 switch (pname)
1409 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001410 case GL_MAX_VERTEX_ATTRIBS:
1411 *params = mCaps.maxVertexAttributes;
1412 break;
1413 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1414 *params = mCaps.maxVertexUniformVectors;
1415 break;
1416 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001417 *params = mCaps.maxShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001418 break;
1419 case GL_MAX_VARYING_VECTORS:
1420 *params = mCaps.maxVaryingVectors;
1421 break;
1422 case GL_MAX_VARYING_COMPONENTS:
1423 *params = mCaps.maxVertexOutputComponents;
1424 break;
1425 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1426 *params = mCaps.maxCombinedTextureImageUnits;
1427 break;
1428 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001429 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001430 break;
1431 case GL_MAX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001432 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001433 break;
1434 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1435 *params = mCaps.maxFragmentUniformVectors;
1436 break;
1437 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001438 *params = mCaps.maxShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001439 break;
1440 case GL_MAX_RENDERBUFFER_SIZE:
1441 *params = mCaps.maxRenderbufferSize;
1442 break;
1443 case GL_MAX_COLOR_ATTACHMENTS_EXT:
1444 *params = mCaps.maxColorAttachments;
1445 break;
1446 case GL_MAX_DRAW_BUFFERS_EXT:
1447 *params = mCaps.maxDrawBuffers;
1448 break;
1449 // case GL_FRAMEBUFFER_BINDING: // now equivalent to
1450 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
1451 case GL_SUBPIXEL_BITS:
1452 *params = 4;
1453 break;
1454 case GL_MAX_TEXTURE_SIZE:
1455 *params = mCaps.max2DTextureSize;
1456 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001457 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
1458 *params = mCaps.maxRectangleTextureSize;
1459 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001460 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1461 *params = mCaps.maxCubeMapTextureSize;
1462 break;
1463 case GL_MAX_3D_TEXTURE_SIZE:
1464 *params = mCaps.max3DTextureSize;
1465 break;
1466 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1467 *params = mCaps.maxArrayTextureLayers;
1468 break;
1469 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1470 *params = mCaps.uniformBufferOffsetAlignment;
1471 break;
1472 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1473 *params = mCaps.maxUniformBufferBindings;
1474 break;
1475 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001476 *params = mCaps.maxShaderUniformBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001477 break;
1478 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001479 *params = mCaps.maxShaderUniformBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001480 break;
1481 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1482 *params = mCaps.maxCombinedTextureImageUnits;
1483 break;
1484 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1485 *params = mCaps.maxVertexOutputComponents;
1486 break;
1487 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1488 *params = mCaps.maxFragmentInputComponents;
1489 break;
1490 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1491 *params = mCaps.minProgramTexelOffset;
1492 break;
1493 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1494 *params = mCaps.maxProgramTexelOffset;
1495 break;
1496 case GL_MAJOR_VERSION:
1497 *params = getClientVersion().major;
1498 break;
1499 case GL_MINOR_VERSION:
1500 *params = getClientVersion().minor;
1501 break;
1502 case GL_MAX_ELEMENTS_INDICES:
1503 *params = mCaps.maxElementsIndices;
1504 break;
1505 case GL_MAX_ELEMENTS_VERTICES:
1506 *params = mCaps.maxElementsVertices;
1507 break;
1508 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1509 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1510 break;
1511 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1512 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1513 break;
1514 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1515 *params = mCaps.maxTransformFeedbackSeparateComponents;
1516 break;
1517 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1518 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1519 break;
1520 case GL_MAX_SAMPLES_ANGLE:
1521 *params = mCaps.maxSamples;
1522 break;
1523 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001524 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001525 params[0] = mCaps.maxViewportWidth;
1526 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001527 }
1528 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001529 case GL_COMPRESSED_TEXTURE_FORMATS:
1530 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1531 params);
1532 break;
1533 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1534 *params = mResetStrategy;
1535 break;
1536 case GL_NUM_SHADER_BINARY_FORMATS:
1537 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1538 break;
1539 case GL_SHADER_BINARY_FORMATS:
1540 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1541 break;
1542 case GL_NUM_PROGRAM_BINARY_FORMATS:
1543 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1544 break;
1545 case GL_PROGRAM_BINARY_FORMATS:
1546 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1547 break;
1548 case GL_NUM_EXTENSIONS:
1549 *params = static_cast<GLint>(mExtensionStrings.size());
1550 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001551
Jamie Madill231c7f52017-04-26 13:45:37 -04001552 // GL_KHR_debug
1553 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1554 *params = mExtensions.maxDebugMessageLength;
1555 break;
1556 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1557 *params = mExtensions.maxDebugLoggedMessages;
1558 break;
1559 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1560 *params = mExtensions.maxDebugGroupStackDepth;
1561 break;
1562 case GL_MAX_LABEL_LENGTH:
1563 *params = mExtensions.maxLabelLength;
1564 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001565
Martin Radeve5285d22017-07-14 16:23:53 +03001566 // GL_ANGLE_multiview
1567 case GL_MAX_VIEWS_ANGLE:
1568 *params = mExtensions.maxViews;
1569 break;
1570
Jamie Madill231c7f52017-04-26 13:45:37 -04001571 // GL_EXT_disjoint_timer_query
1572 case GL_GPU_DISJOINT_EXT:
1573 *params = mImplementation->getGPUDisjoint();
1574 break;
1575 case GL_MAX_FRAMEBUFFER_WIDTH:
1576 *params = mCaps.maxFramebufferWidth;
1577 break;
1578 case GL_MAX_FRAMEBUFFER_HEIGHT:
1579 *params = mCaps.maxFramebufferHeight;
1580 break;
1581 case GL_MAX_FRAMEBUFFER_SAMPLES:
1582 *params = mCaps.maxFramebufferSamples;
1583 break;
1584 case GL_MAX_SAMPLE_MASK_WORDS:
1585 *params = mCaps.maxSampleMaskWords;
1586 break;
1587 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1588 *params = mCaps.maxColorTextureSamples;
1589 break;
1590 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1591 *params = mCaps.maxDepthTextureSamples;
1592 break;
1593 case GL_MAX_INTEGER_SAMPLES:
1594 *params = mCaps.maxIntegerSamples;
1595 break;
1596 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1597 *params = mCaps.maxVertexAttribRelativeOffset;
1598 break;
1599 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1600 *params = mCaps.maxVertexAttribBindings;
1601 break;
1602 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1603 *params = mCaps.maxVertexAttribStride;
1604 break;
1605 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001606 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001607 break;
1608 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001609 *params = mCaps.maxShaderAtomicCounters[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001610 break;
1611 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001612 *params = mCaps.maxShaderImageUniforms[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001613 break;
1614 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001615 *params = mCaps.maxShaderStorageBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001616 break;
1617 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001618 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001619 break;
1620 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001621 *params = mCaps.maxShaderAtomicCounters[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001622 break;
1623 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001624 *params = mCaps.maxShaderImageUniforms[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001625 break;
1626 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001627 *params = mCaps.maxShaderStorageBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001628 break;
1629 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1630 *params = mCaps.minProgramTextureGatherOffset;
1631 break;
1632 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1633 *params = mCaps.maxProgramTextureGatherOffset;
1634 break;
1635 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1636 *params = mCaps.maxComputeWorkGroupInvocations;
1637 break;
1638 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001639 *params = mCaps.maxShaderUniformBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001640 break;
1641 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001642 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001643 break;
1644 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1645 *params = mCaps.maxComputeSharedMemorySize;
1646 break;
1647 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001648 *params = mCaps.maxShaderUniformComponents[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001649 break;
1650 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001651 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001652 break;
1653 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001654 *params = mCaps.maxShaderAtomicCounters[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001655 break;
1656 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001657 *params = mCaps.maxShaderImageUniforms[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001658 break;
1659 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001660 *params =
1661 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Compute]);
Jamie Madill231c7f52017-04-26 13:45:37 -04001662 break;
1663 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001664 *params = mCaps.maxShaderStorageBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001665 break;
1666 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1667 *params = mCaps.maxCombinedShaderOutputResources;
1668 break;
1669 case GL_MAX_UNIFORM_LOCATIONS:
1670 *params = mCaps.maxUniformLocations;
1671 break;
1672 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1673 *params = mCaps.maxAtomicCounterBufferBindings;
1674 break;
1675 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1676 *params = mCaps.maxAtomicCounterBufferSize;
1677 break;
1678 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1679 *params = mCaps.maxCombinedAtomicCounterBuffers;
1680 break;
1681 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1682 *params = mCaps.maxCombinedAtomicCounters;
1683 break;
1684 case GL_MAX_IMAGE_UNITS:
1685 *params = mCaps.maxImageUnits;
1686 break;
1687 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1688 *params = mCaps.maxCombinedImageUniforms;
1689 break;
1690 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1691 *params = mCaps.maxShaderStorageBufferBindings;
1692 break;
1693 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1694 *params = mCaps.maxCombinedShaderStorageBlocks;
1695 break;
1696 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1697 *params = mCaps.shaderStorageBufferOffsetAlignment;
1698 break;
Jiawei Shao361df072017-11-22 09:33:59 +08001699
1700 // GL_EXT_geometry_shader
1701 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
1702 *params = mCaps.maxFramebufferLayers;
1703 break;
1704 case GL_LAYER_PROVOKING_VERTEX_EXT:
1705 *params = mCaps.layerProvokingVertex;
1706 break;
1707 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001708 *params = mCaps.maxShaderUniformComponents[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001709 break;
1710 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001711 *params = mCaps.maxShaderUniformBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001712 break;
1713 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001714 *params =
1715 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Geometry]);
Jiawei Shao361df072017-11-22 09:33:59 +08001716 break;
1717 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
1718 *params = mCaps.maxGeometryInputComponents;
1719 break;
1720 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
1721 *params = mCaps.maxGeometryOutputComponents;
1722 break;
1723 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
1724 *params = mCaps.maxGeometryOutputVertices;
1725 break;
1726 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
1727 *params = mCaps.maxGeometryTotalOutputComponents;
1728 break;
1729 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
1730 *params = mCaps.maxGeometryShaderInvocations;
1731 break;
1732 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001733 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001734 break;
1735 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001736 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001737 break;
1738 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001739 *params = mCaps.maxShaderAtomicCounters[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001740 break;
1741 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001742 *params = mCaps.maxShaderImageUniforms[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001743 break;
1744 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001745 *params = mCaps.maxShaderStorageBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001746 break;
Lingfeng Yang96310cd2018-03-28 11:56:28 -07001747 // GLES1 emulation: Caps queries
1748 case GL_MAX_TEXTURE_UNITS:
1749 *params = mCaps.maxMultitextureUnits;
1750 break;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001751 case GL_MAX_MODELVIEW_STACK_DEPTH:
1752 *params = mCaps.maxModelviewMatrixStackDepth;
1753 break;
1754 case GL_MAX_PROJECTION_STACK_DEPTH:
1755 *params = mCaps.maxProjectionMatrixStackDepth;
1756 break;
1757 case GL_MAX_TEXTURE_STACK_DEPTH:
1758 *params = mCaps.maxTextureMatrixStackDepth;
1759 break;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07001760 case GL_MAX_LIGHTS:
1761 *params = mCaps.maxLights;
1762 break;
Lingfeng Yang060088a2018-05-30 20:40:57 -07001763 case GL_MAX_CLIP_PLANES:
1764 *params = mCaps.maxClipPlanes;
1765 break;
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001766 // GLES1 emulation: Vertex attribute queries
1767 case GL_VERTEX_ARRAY_BUFFER_BINDING:
1768 case GL_NORMAL_ARRAY_BUFFER_BINDING:
1769 case GL_COLOR_ARRAY_BUFFER_BINDING:
1770 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
1771 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
1772 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1773 GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, params);
1774 break;
1775 case GL_VERTEX_ARRAY_STRIDE:
1776 case GL_NORMAL_ARRAY_STRIDE:
1777 case GL_COLOR_ARRAY_STRIDE:
1778 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
1779 case GL_TEXTURE_COORD_ARRAY_STRIDE:
1780 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1781 GL_VERTEX_ATTRIB_ARRAY_STRIDE, params);
1782 break;
1783 case GL_VERTEX_ARRAY_SIZE:
1784 case GL_COLOR_ARRAY_SIZE:
1785 case GL_TEXTURE_COORD_ARRAY_SIZE:
1786 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1787 GL_VERTEX_ATTRIB_ARRAY_SIZE, params);
1788 break;
1789 case GL_VERTEX_ARRAY_TYPE:
1790 case GL_COLOR_ARRAY_TYPE:
1791 case GL_NORMAL_ARRAY_TYPE:
1792 case GL_POINT_SIZE_ARRAY_TYPE_OES:
1793 case GL_TEXTURE_COORD_ARRAY_TYPE:
1794 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1795 GL_VERTEX_ATTRIB_ARRAY_TYPE, params);
1796 break;
1797
jchen1082af6202018-06-22 10:59:52 +08001798 // GL_KHR_parallel_shader_compile
1799 case GL_MAX_SHADER_COMPILER_THREADS_KHR:
1800 *params = mGLState.getMaxShaderCompilerThreads();
1801 break;
1802
Jamie Madill231c7f52017-04-26 13:45:37 -04001803 default:
Jamie Madille98b1b52018-03-08 09:47:23 -05001804 handleError(mGLState.getIntegerv(this, pname, params));
Jamie Madill231c7f52017-04-26 13:45:37 -04001805 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001806 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001807}
1808
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001809void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001810{
Shannon Woods53a94a82014-06-24 15:20:36 -04001811 // Queries about context capabilities and maximums are answered by Context.
1812 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001813 switch (pname)
1814 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001815 case GL_MAX_ELEMENT_INDEX:
1816 *params = mCaps.maxElementIndex;
1817 break;
1818 case GL_MAX_UNIFORM_BLOCK_SIZE:
1819 *params = mCaps.maxUniformBlockSize;
1820 break;
1821 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001822 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001823 break;
1824 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001825 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001826 break;
1827 case GL_MAX_SERVER_WAIT_TIMEOUT:
1828 *params = mCaps.maxServerWaitTimeout;
1829 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001830
Jamie Madill231c7f52017-04-26 13:45:37 -04001831 // GL_EXT_disjoint_timer_query
1832 case GL_TIMESTAMP_EXT:
1833 *params = mImplementation->getTimestamp();
1834 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001835
Jamie Madill231c7f52017-04-26 13:45:37 -04001836 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1837 *params = mCaps.maxShaderStorageBlockSize;
1838 break;
1839 default:
1840 UNREACHABLE();
1841 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001842 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001843}
1844
Geoff Lang70d0f492015-12-10 17:45:46 -05001845void Context::getPointerv(GLenum pname, void **params) const
1846{
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001847 mGLState.getPointerv(this, pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001848}
1849
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001850void Context::getPointervRobustANGLERobust(GLenum pname,
1851 GLsizei bufSize,
1852 GLsizei *length,
1853 void **params)
1854{
1855 UNIMPLEMENTED();
1856}
1857
Martin Radev66fb8202016-07-28 11:45:20 +03001858void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001859{
Shannon Woods53a94a82014-06-24 15:20:36 -04001860 // Queries about context capabilities and maximums are answered by Context.
1861 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001862
1863 GLenum nativeType;
1864 unsigned int numParams;
1865 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1866 ASSERT(queryStatus);
1867
1868 if (nativeType == GL_INT)
1869 {
1870 switch (target)
1871 {
1872 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1873 ASSERT(index < 3u);
1874 *data = mCaps.maxComputeWorkGroupCount[index];
1875 break;
1876 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1877 ASSERT(index < 3u);
1878 *data = mCaps.maxComputeWorkGroupSize[index];
1879 break;
1880 default:
1881 mGLState.getIntegeri_v(target, index, data);
1882 }
1883 }
1884 else
1885 {
1886 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1887 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001888}
1889
Brandon Jones59770802018-04-02 13:18:42 -07001890void Context::getIntegeri_vRobust(GLenum target,
1891 GLuint index,
1892 GLsizei bufSize,
1893 GLsizei *length,
1894 GLint *data)
1895{
1896 getIntegeri_v(target, index, data);
1897}
1898
Martin Radev66fb8202016-07-28 11:45:20 +03001899void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001900{
Shannon Woods53a94a82014-06-24 15:20:36 -04001901 // Queries about context capabilities and maximums are answered by Context.
1902 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001903
1904 GLenum nativeType;
1905 unsigned int numParams;
1906 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1907 ASSERT(queryStatus);
1908
1909 if (nativeType == GL_INT_64_ANGLEX)
1910 {
1911 mGLState.getInteger64i_v(target, index, data);
1912 }
1913 else
1914 {
1915 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1916 }
1917}
1918
Brandon Jones59770802018-04-02 13:18:42 -07001919void Context::getInteger64i_vRobust(GLenum target,
1920 GLuint index,
1921 GLsizei bufSize,
1922 GLsizei *length,
1923 GLint64 *data)
1924{
1925 getInteger64i_v(target, index, data);
1926}
1927
Martin Radev66fb8202016-07-28 11:45:20 +03001928void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1929{
1930 // Queries about context capabilities and maximums are answered by Context.
1931 // Queries about current GL state values are answered by State.
1932
1933 GLenum nativeType;
1934 unsigned int numParams;
1935 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1936 ASSERT(queryStatus);
1937
1938 if (nativeType == GL_BOOL)
1939 {
1940 mGLState.getBooleani_v(target, index, data);
1941 }
1942 else
1943 {
1944 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1945 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001946}
1947
Brandon Jones59770802018-04-02 13:18:42 -07001948void Context::getBooleani_vRobust(GLenum target,
1949 GLuint index,
1950 GLsizei bufSize,
1951 GLsizei *length,
1952 GLboolean *data)
1953{
1954 getBooleani_v(target, index, data);
1955}
1956
Corentin Wallez336129f2017-10-17 15:55:40 -04001957void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001958{
1959 Buffer *buffer = mGLState.getTargetBuffer(target);
1960 QueryBufferParameteriv(buffer, pname, params);
1961}
1962
Brandon Jones59770802018-04-02 13:18:42 -07001963void Context::getBufferParameterivRobust(BufferBinding target,
1964 GLenum pname,
1965 GLsizei bufSize,
1966 GLsizei *length,
1967 GLint *params)
1968{
1969 getBufferParameteriv(target, pname, params);
1970}
1971
He Yunchao010e4db2017-03-03 14:22:06 +08001972void Context::getFramebufferAttachmentParameteriv(GLenum target,
1973 GLenum attachment,
1974 GLenum pname,
1975 GLint *params)
1976{
1977 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08001978 QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08001979}
1980
Brandon Jones59770802018-04-02 13:18:42 -07001981void Context::getFramebufferAttachmentParameterivRobust(GLenum target,
1982 GLenum attachment,
1983 GLenum pname,
1984 GLsizei bufSize,
1985 GLsizei *length,
1986 GLint *params)
1987{
1988 getFramebufferAttachmentParameteriv(target, attachment, pname, params);
1989}
1990
He Yunchao010e4db2017-03-03 14:22:06 +08001991void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
1992{
1993 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
1994 QueryRenderbufferiv(this, renderbuffer, pname, params);
1995}
1996
Brandon Jones59770802018-04-02 13:18:42 -07001997void Context::getRenderbufferParameterivRobust(GLenum target,
1998 GLenum pname,
1999 GLsizei bufSize,
2000 GLsizei *length,
2001 GLint *params)
2002{
2003 getRenderbufferParameteriv(target, pname, params);
2004}
2005
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002006void Context::getTexParameterfv(TextureType target, GLenum pname, GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002007{
2008 Texture *texture = getTargetTexture(target);
2009 QueryTexParameterfv(texture, pname, params);
2010}
2011
Brandon Jones59770802018-04-02 13:18:42 -07002012void Context::getTexParameterfvRobust(TextureType target,
2013 GLenum pname,
2014 GLsizei bufSize,
2015 GLsizei *length,
2016 GLfloat *params)
2017{
2018 getTexParameterfv(target, pname, params);
2019}
2020
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002021void Context::getTexParameteriv(TextureType target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002022{
2023 Texture *texture = getTargetTexture(target);
2024 QueryTexParameteriv(texture, pname, params);
2025}
Jiajia Qin5451d532017-11-16 17:16:34 +08002026
Brandon Jones59770802018-04-02 13:18:42 -07002027void Context::getTexParameterivRobust(TextureType target,
2028 GLenum pname,
2029 GLsizei bufSize,
2030 GLsizei *length,
2031 GLint *params)
2032{
2033 getTexParameteriv(target, pname, params);
2034}
2035
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002036void Context::getTexParameterIivRobust(TextureType target,
2037 GLenum pname,
2038 GLsizei bufSize,
2039 GLsizei *length,
2040 GLint *params)
2041{
2042 UNIMPLEMENTED();
2043}
2044
2045void Context::getTexParameterIuivRobust(TextureType target,
2046 GLenum pname,
2047 GLsizei bufSize,
2048 GLsizei *length,
2049 GLuint *params)
2050{
2051 UNIMPLEMENTED();
2052}
2053
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002054void Context::getTexLevelParameteriv(TextureTarget target, GLint level, GLenum pname, GLint *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002055{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002056 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002057 QueryTexLevelParameteriv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002058}
2059
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002060void Context::getTexLevelParameterivRobust(TextureTarget target,
2061 GLint level,
2062 GLenum pname,
2063 GLsizei bufSize,
2064 GLsizei *length,
2065 GLint *params)
2066{
2067 UNIMPLEMENTED();
2068}
2069
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002070void Context::getTexLevelParameterfv(TextureTarget target,
2071 GLint level,
2072 GLenum pname,
2073 GLfloat *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002074{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002075 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002076 QueryTexLevelParameterfv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002077}
2078
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002079void Context::getTexLevelParameterfvRobust(TextureTarget target,
2080 GLint level,
2081 GLenum pname,
2082 GLsizei bufSize,
2083 GLsizei *length,
2084 GLfloat *params)
2085{
2086 UNIMPLEMENTED();
2087}
2088
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002089void Context::texParameterf(TextureType target, GLenum pname, GLfloat param)
He Yunchao010e4db2017-03-03 14:22:06 +08002090{
2091 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002092 SetTexParameterf(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002093 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002094}
2095
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002096void Context::texParameterfv(TextureType target, GLenum pname, const GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002097{
2098 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002099 SetTexParameterfv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002100 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002101}
2102
Brandon Jones59770802018-04-02 13:18:42 -07002103void Context::texParameterfvRobust(TextureType target,
2104 GLenum pname,
2105 GLsizei bufSize,
2106 const GLfloat *params)
2107{
2108 texParameterfv(target, pname, params);
2109}
2110
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002111void Context::texParameteri(TextureType target, GLenum pname, GLint param)
He Yunchao010e4db2017-03-03 14:22:06 +08002112{
2113 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002114 SetTexParameteri(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002115 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002116}
2117
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002118void Context::texParameteriv(TextureType target, GLenum pname, const GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002119{
2120 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002121 SetTexParameteriv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002122 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002123}
2124
Brandon Jones59770802018-04-02 13:18:42 -07002125void Context::texParameterivRobust(TextureType target,
2126 GLenum pname,
2127 GLsizei bufSize,
2128 const GLint *params)
2129{
2130 texParameteriv(target, pname, params);
2131}
2132
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002133void Context::texParameterIivRobust(TextureType target,
2134 GLenum pname,
2135 GLsizei bufSize,
2136 const GLint *params)
2137{
2138 UNIMPLEMENTED();
2139}
2140
2141void Context::texParameterIuivRobust(TextureType target,
2142 GLenum pname,
2143 GLsizei bufSize,
2144 const GLuint *params)
2145{
2146 UNIMPLEMENTED();
2147}
2148
Jamie Madill493f9572018-05-24 19:52:15 -04002149void Context::drawArrays(PrimitiveMode mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002150{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002151 // No-op if count draws no primitives for given mode
2152 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002153 {
2154 return;
2155 }
2156
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002157 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002158 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
Jamie Madill09463932018-04-04 05:26:59 -04002159 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count, 1);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002160}
2161
Jamie Madill493f9572018-05-24 19:52:15 -04002162void Context::drawArraysInstanced(PrimitiveMode mode,
2163 GLint first,
2164 GLsizei count,
2165 GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04002166{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002167 // No-op if count draws no primitives for given mode
2168 if (noopDrawInstanced(mode, count, instanceCount))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002169 {
2170 return;
2171 }
2172
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002173 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002174 ANGLE_CONTEXT_TRY(
2175 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
Jamie Madill09463932018-04-04 05:26:59 -04002176 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count,
2177 instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -04002178}
2179
Jamie Madill493f9572018-05-24 19:52:15 -04002180void Context::drawElements(PrimitiveMode mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002181{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002182 // No-op if count draws no primitives for given mode
2183 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002184 {
2185 return;
2186 }
2187
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002188 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002189 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04002190}
2191
Jamie Madill493f9572018-05-24 19:52:15 -04002192void Context::drawElementsInstanced(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002193 GLsizei count,
2194 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002195 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04002196 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04002197{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002198 // No-op if count draws no primitives for given mode
2199 if (noopDrawInstanced(mode, count, instances))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002200 {
2201 return;
2202 }
2203
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002204 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002205 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08002206 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04002207}
2208
Jamie Madill493f9572018-05-24 19:52:15 -04002209void Context::drawRangeElements(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002210 GLuint start,
2211 GLuint end,
2212 GLsizei count,
2213 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002214 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04002215{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002216 // No-op if count draws no primitives for given mode
2217 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002218 {
2219 return;
2220 }
2221
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002222 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002223 ANGLE_CONTEXT_TRY(
2224 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002225}
2226
Jamie Madill493f9572018-05-24 19:52:15 -04002227void Context::drawArraysIndirect(PrimitiveMode mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002228{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002229 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002230 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002231}
2232
Jamie Madill493f9572018-05-24 19:52:15 -04002233void Context::drawElementsIndirect(PrimitiveMode mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002234{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002235 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002236 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002237}
2238
Jamie Madill675fe712016-12-19 13:07:54 -05002239void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002240{
Jamie Madillafa02a22017-11-23 12:57:38 -05002241 handleError(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05002242}
2243
Jamie Madill675fe712016-12-19 13:07:54 -05002244void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05002245{
Jamie Madillafa02a22017-11-23 12:57:38 -05002246 handleError(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002247}
2248
Austin Kinross6ee1e782015-05-29 17:05:37 -07002249void Context::insertEventMarker(GLsizei length, const char *marker)
2250{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002251 ASSERT(mImplementation);
2252 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07002253}
2254
2255void Context::pushGroupMarker(GLsizei length, const char *marker)
2256{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002257 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05002258
2259 if (marker == nullptr)
2260 {
2261 // From the EXT_debug_marker spec,
2262 // "If <marker> is null then an empty string is pushed on the stack."
2263 mImplementation->pushGroupMarker(length, "");
2264 }
2265 else
2266 {
2267 mImplementation->pushGroupMarker(length, marker);
2268 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07002269}
2270
2271void Context::popGroupMarker()
2272{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002273 ASSERT(mImplementation);
2274 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07002275}
2276
Geoff Langd8605522016-04-13 10:19:12 -04002277void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
2278{
2279 Program *programObject = getProgram(program);
2280 ASSERT(programObject);
2281
2282 programObject->bindUniformLocation(location, name);
2283}
2284
Brandon Jones59770802018-04-02 13:18:42 -07002285void Context::coverageModulation(GLenum components)
Sami Väisänena797e062016-05-12 15:23:40 +03002286{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002287 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03002288}
2289
Brandon Jones59770802018-04-02 13:18:42 -07002290void Context::matrixLoadf(GLenum matrixMode, const GLfloat *matrix)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002291{
2292 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
2293}
2294
Brandon Jones59770802018-04-02 13:18:42 -07002295void Context::matrixLoadIdentity(GLenum matrixMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002296{
2297 GLfloat I[16];
2298 angle::Matrix<GLfloat>::setToIdentity(I);
2299
2300 mGLState.loadPathRenderingMatrix(matrixMode, I);
2301}
2302
2303void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
2304{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002305 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002306 if (!pathObj)
2307 return;
2308
Geoff Lang9bf86f02018-07-26 11:46:34 -04002309 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002310
2311 mImplementation->stencilFillPath(pathObj, fillMode, mask);
2312}
2313
2314void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
2315{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002316 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002317 if (!pathObj)
2318 return;
2319
Geoff Lang9bf86f02018-07-26 11:46:34 -04002320 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002321
2322 mImplementation->stencilStrokePath(pathObj, reference, mask);
2323}
2324
2325void Context::coverFillPath(GLuint path, GLenum coverMode)
2326{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002327 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002328 if (!pathObj)
2329 return;
2330
Geoff Lang9bf86f02018-07-26 11:46:34 -04002331 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002332
2333 mImplementation->coverFillPath(pathObj, coverMode);
2334}
2335
2336void Context::coverStrokePath(GLuint path, GLenum coverMode)
2337{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002338 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002339 if (!pathObj)
2340 return;
2341
Geoff Lang9bf86f02018-07-26 11:46:34 -04002342 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002343
2344 mImplementation->coverStrokePath(pathObj, coverMode);
2345}
2346
2347void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
2348{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002349 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002350 if (!pathObj)
2351 return;
2352
Geoff Lang9bf86f02018-07-26 11:46:34 -04002353 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002354
2355 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
2356}
2357
2358void Context::stencilThenCoverStrokePath(GLuint path,
2359 GLint reference,
2360 GLuint mask,
2361 GLenum coverMode)
2362{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002363 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002364 if (!pathObj)
2365 return;
2366
Geoff Lang9bf86f02018-07-26 11:46:34 -04002367 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002368
2369 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2370}
2371
Sami Väisänend59ca052016-06-21 16:10:00 +03002372void Context::coverFillPathInstanced(GLsizei numPaths,
2373 GLenum pathNameType,
2374 const void *paths,
2375 GLuint pathBase,
2376 GLenum coverMode,
2377 GLenum transformType,
2378 const GLfloat *transformValues)
2379{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002380 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002381
Geoff Lang9bf86f02018-07-26 11:46:34 -04002382 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002383
2384 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2385}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002386
Sami Väisänend59ca052016-06-21 16:10:00 +03002387void Context::coverStrokePathInstanced(GLsizei numPaths,
2388 GLenum pathNameType,
2389 const void *paths,
2390 GLuint pathBase,
2391 GLenum coverMode,
2392 GLenum transformType,
2393 const GLfloat *transformValues)
2394{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002395 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002396
2397 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Lang9bf86f02018-07-26 11:46:34 -04002398 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002399
2400 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2401 transformValues);
2402}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002403
Sami Väisänend59ca052016-06-21 16:10:00 +03002404void Context::stencilFillPathInstanced(GLsizei numPaths,
2405 GLenum pathNameType,
2406 const void *paths,
2407 GLuint pathBase,
2408 GLenum fillMode,
2409 GLuint mask,
2410 GLenum transformType,
2411 const GLfloat *transformValues)
2412{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002413 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002414
2415 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Lang9bf86f02018-07-26 11:46:34 -04002416 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002417
2418 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2419 transformValues);
2420}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002421
Sami Väisänend59ca052016-06-21 16:10:00 +03002422void Context::stencilStrokePathInstanced(GLsizei numPaths,
2423 GLenum pathNameType,
2424 const void *paths,
2425 GLuint pathBase,
2426 GLint reference,
2427 GLuint mask,
2428 GLenum transformType,
2429 const GLfloat *transformValues)
2430{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002431 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002432
Geoff Lang9bf86f02018-07-26 11:46:34 -04002433 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002434
2435 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2436 transformValues);
2437}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002438
Sami Väisänend59ca052016-06-21 16:10:00 +03002439void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2440 GLenum pathNameType,
2441 const void *paths,
2442 GLuint pathBase,
2443 GLenum fillMode,
2444 GLuint mask,
2445 GLenum coverMode,
2446 GLenum transformType,
2447 const GLfloat *transformValues)
2448{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002449 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002450
Geoff Lang9bf86f02018-07-26 11:46:34 -04002451 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002452
2453 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2454 transformType, transformValues);
2455}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002456
Sami Väisänend59ca052016-06-21 16:10:00 +03002457void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2458 GLenum pathNameType,
2459 const void *paths,
2460 GLuint pathBase,
2461 GLint reference,
2462 GLuint mask,
2463 GLenum coverMode,
2464 GLenum transformType,
2465 const GLfloat *transformValues)
2466{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002467 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002468
Geoff Lang9bf86f02018-07-26 11:46:34 -04002469 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002470
2471 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2472 transformType, transformValues);
2473}
2474
Sami Väisänen46eaa942016-06-29 10:26:37 +03002475void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2476{
2477 auto *programObject = getProgram(program);
2478
2479 programObject->bindFragmentInputLocation(location, name);
2480}
2481
2482void Context::programPathFragmentInputGen(GLuint program,
2483 GLint location,
2484 GLenum genMode,
2485 GLint components,
2486 const GLfloat *coeffs)
2487{
2488 auto *programObject = getProgram(program);
2489
Jamie Madillbd044ed2017-06-05 12:59:21 -04002490 programObject->pathFragmentInputGen(this, location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002491}
2492
jchen1015015f72017-03-16 13:54:21 +08002493GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2494{
jchen10fd7c3b52017-03-21 15:36:03 +08002495 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002496 return QueryProgramResourceIndex(programObject, programInterface, name);
2497}
2498
jchen10fd7c3b52017-03-21 15:36:03 +08002499void Context::getProgramResourceName(GLuint program,
2500 GLenum programInterface,
2501 GLuint index,
2502 GLsizei bufSize,
2503 GLsizei *length,
2504 GLchar *name)
2505{
2506 const auto *programObject = getProgram(program);
2507 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2508}
2509
jchen10191381f2017-04-11 13:59:04 +08002510GLint Context::getProgramResourceLocation(GLuint program,
2511 GLenum programInterface,
2512 const GLchar *name)
2513{
2514 const auto *programObject = getProgram(program);
2515 return QueryProgramResourceLocation(programObject, programInterface, name);
2516}
2517
jchen10880683b2017-04-12 16:21:55 +08002518void Context::getProgramResourceiv(GLuint program,
2519 GLenum programInterface,
2520 GLuint index,
2521 GLsizei propCount,
2522 const GLenum *props,
2523 GLsizei bufSize,
2524 GLsizei *length,
2525 GLint *params)
2526{
2527 const auto *programObject = getProgram(program);
2528 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2529 length, params);
2530}
2531
jchen10d9cd7b72017-08-30 15:04:25 +08002532void Context::getProgramInterfaceiv(GLuint program,
2533 GLenum programInterface,
2534 GLenum pname,
2535 GLint *params)
2536{
2537 const auto *programObject = getProgram(program);
2538 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2539}
2540
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002541void Context::getProgramInterfaceivRobust(GLuint program,
2542 GLenum programInterface,
2543 GLenum pname,
2544 GLsizei bufSize,
2545 GLsizei *length,
2546 GLint *params)
2547{
2548 UNIMPLEMENTED();
2549}
2550
Jamie Madill306b6c12018-07-27 08:12:49 -04002551void Context::handleError(const Error &error) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002552{
Jamie Madill6b873dd2018-07-12 23:56:30 -04002553 mErrors.handleError(error);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002554}
2555
2556// Get one of the recorded errors and clear its flag, if any.
2557// [OpenGL ES 2.0.24] section 2.5 page 13.
2558GLenum Context::getError()
2559{
Geoff Langda5777c2014-07-11 09:52:58 -04002560 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002561 {
Geoff Langda5777c2014-07-11 09:52:58 -04002562 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002563 }
Geoff Langda5777c2014-07-11 09:52:58 -04002564 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002565 {
Jamie Madill6b873dd2018-07-12 23:56:30 -04002566 return mErrors.popError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002567 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002568}
2569
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002570// NOTE: this function should not assume that this context is current!
Jamie Madill6b873dd2018-07-12 23:56:30 -04002571void Context::markContextLost()
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002572{
2573 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002574 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002575 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002576 mContextLostForced = true;
2577 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002578 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002579}
2580
Jamie Madill427064d2018-04-13 16:20:34 -04002581bool Context::isContextLost() const
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002582{
2583 return mContextLost;
2584}
2585
Jamie Madillfa920eb2018-01-04 11:45:50 -05002586GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002587{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002588 // Even if the application doesn't want to know about resets, we want to know
2589 // as it will allow us to skip all the calls.
2590 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002591 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002592 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002593 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002594 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002595 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002596
2597 // EXT_robustness, section 2.6: If the reset notification behavior is
2598 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2599 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2600 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002601 }
2602
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002603 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2604 // status should be returned at least once, and GL_NO_ERROR should be returned
2605 // once the device has finished resetting.
2606 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002607 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002608 ASSERT(mResetStatus == GL_NO_ERROR);
2609 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002610
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002611 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002612 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002613 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002614 }
2615 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002616 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002617 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002618 // If markContextLost was used to mark the context lost then
2619 // assume that is not recoverable, and continue to report the
2620 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002621 mResetStatus = mImplementation->getResetStatus();
2622 }
Jamie Madill893ab082014-05-16 16:56:10 -04002623
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002624 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002625}
2626
2627bool Context::isResetNotificationEnabled()
2628{
2629 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2630}
2631
Corentin Walleze3b10e82015-05-20 11:06:25 -04002632const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002633{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002634 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002635}
2636
2637EGLenum Context::getClientType() const
2638{
2639 return mClientType;
2640}
2641
2642EGLenum Context::getRenderBuffer() const
2643{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002644 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2645 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002646 {
2647 return EGL_NONE;
2648 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002649
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002650 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002651 ASSERT(backAttachment != nullptr);
2652 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002653}
2654
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002655VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002656{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002657 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002658 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2659 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002660 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002661 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2662 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002663
Jamie Madill96a483b2017-06-27 16:49:21 -04002664 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002665 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002666
2667 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002668}
2669
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002670TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002671{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002672 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002673 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2674 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002675 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002676 transformFeedback =
2677 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002678 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002679 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002680 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002681
2682 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002683}
2684
2685bool Context::isVertexArrayGenerated(GLuint vertexArray)
2686{
Jamie Madill96a483b2017-06-27 16:49:21 -04002687 ASSERT(mVertexArrayMap.contains(0));
2688 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002689}
2690
2691bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2692{
Jamie Madill96a483b2017-06-27 16:49:21 -04002693 ASSERT(mTransformFeedbackMap.contains(0));
2694 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002695}
2696
Shannon Woods53a94a82014-06-24 15:20:36 -04002697void Context::detachTexture(GLuint texture)
2698{
2699 // Simple pass-through to State's detachTexture method, as textures do not require
2700 // allocation map management either here or in the resource manager at detach time.
2701 // Zero textures are held by the Context, and we don't attempt to request them from
2702 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002703 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002704}
2705
James Darpinian4d9d4832018-03-13 12:43:28 -07002706void Context::detachBuffer(Buffer *buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002707{
Yuly Novikov5807a532015-12-03 13:01:22 -05002708 // Simple pass-through to State's detachBuffer method, since
2709 // only buffer attachments to container objects that are bound to the current context
2710 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002711
Yuly Novikov5807a532015-12-03 13:01:22 -05002712 // [OpenGL ES 3.2] section 5.1.2 page 45:
2713 // Attachments to unbound container objects, such as
2714 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2715 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002716 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002717}
2718
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002719void Context::detachFramebuffer(GLuint framebuffer)
2720{
Shannon Woods53a94a82014-06-24 15:20:36 -04002721 // Framebuffer detachment is handled by Context, because 0 is a valid
2722 // Framebuffer object, and a pointer to it must be passed from Context
2723 // to State at binding time.
2724
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002725 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002726 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2727 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2728 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002729
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002730 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002731 {
2732 bindReadFramebuffer(0);
2733 }
2734
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002735 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002736 {
2737 bindDrawFramebuffer(0);
2738 }
2739}
2740
2741void Context::detachRenderbuffer(GLuint renderbuffer)
2742{
Jamie Madilla02315b2017-02-23 14:14:47 -05002743 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002744}
2745
Jamie Madill57a89722013-07-02 11:57:03 -04002746void Context::detachVertexArray(GLuint vertexArray)
2747{
Jamie Madill77a72f62015-04-14 11:18:32 -04002748 // Vertex array detachment is handled by Context, because 0 is a valid
2749 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002750 // binding time.
2751
Jamie Madill57a89722013-07-02 11:57:03 -04002752 // [OpenGL ES 3.0.2] section 2.10 page 43:
2753 // If a vertex array object that is currently bound is deleted, the binding
2754 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madill7267aa62018-04-17 15:28:21 -04002755 if (mGLState.removeVertexArrayBinding(this, vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002756 {
2757 bindVertexArray(0);
2758 }
2759}
2760
Geoff Langc8058452014-02-03 12:04:11 -05002761void Context::detachTransformFeedback(GLuint transformFeedback)
2762{
Corentin Walleza2257da2016-04-19 16:43:12 -04002763 // Transform feedback detachment is handled by Context, because 0 is a valid
2764 // transform feedback, and a pointer to it must be passed from Context to State at
2765 // binding time.
2766
2767 // The OpenGL specification doesn't mention what should happen when the currently bound
2768 // transform feedback object is deleted. Since it is a container object, we treat it like
2769 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002770 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002771 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002772 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002773 }
Geoff Langc8058452014-02-03 12:04:11 -05002774}
2775
Jamie Madilldc356042013-07-19 16:36:57 -04002776void Context::detachSampler(GLuint sampler)
2777{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002778 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002779}
2780
Yunchao Hea336b902017-08-02 16:05:21 +08002781void Context::detachProgramPipeline(GLuint pipeline)
2782{
2783 mGLState.detachProgramPipeline(this, pipeline);
2784}
2785
Jamie Madill3ef140a2017-08-26 23:11:21 -04002786void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002787{
Shaodde78e82017-05-22 14:13:27 +08002788 mGLState.setVertexAttribDivisor(this, index, divisor);
Jamie Madilldc358af2018-07-31 11:22:13 -04002789 mStateCache.updateActiveAttribsMask(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002790}
2791
Jamie Madille29d1672013-07-19 16:36:57 -04002792void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2793{
Geoff Langc1984ed2016-10-07 12:41:00 -04002794 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002795 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002796 SetSamplerParameteri(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002797 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002798}
Jamie Madille29d1672013-07-19 16:36:57 -04002799
Geoff Langc1984ed2016-10-07 12:41:00 -04002800void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2801{
2802 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002803 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002804 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002805 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002806}
2807
Brandon Jones59770802018-04-02 13:18:42 -07002808void Context::samplerParameterivRobust(GLuint sampler,
2809 GLenum pname,
2810 GLsizei bufSize,
2811 const GLint *param)
2812{
2813 samplerParameteriv(sampler, pname, param);
2814}
2815
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002816void Context::samplerParameterIivRobust(GLuint sampler,
2817 GLenum pname,
2818 GLsizei bufSize,
2819 const GLint *param)
2820{
2821 UNIMPLEMENTED();
2822}
2823
2824void Context::samplerParameterIuivRobust(GLuint sampler,
2825 GLenum pname,
2826 GLsizei bufSize,
2827 const GLuint *param)
2828{
2829 UNIMPLEMENTED();
2830}
2831
Jamie Madille29d1672013-07-19 16:36:57 -04002832void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2833{
Geoff Langc1984ed2016-10-07 12:41:00 -04002834 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002835 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002836 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002837 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002838}
2839
Geoff Langc1984ed2016-10-07 12:41:00 -04002840void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002841{
Geoff Langc1984ed2016-10-07 12:41:00 -04002842 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002843 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002844 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002845 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002846}
2847
Brandon Jones59770802018-04-02 13:18:42 -07002848void Context::samplerParameterfvRobust(GLuint sampler,
2849 GLenum pname,
2850 GLsizei bufSize,
2851 const GLfloat *param)
2852{
2853 samplerParameterfv(sampler, pname, param);
2854}
2855
Geoff Langc1984ed2016-10-07 12:41:00 -04002856void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002857{
Geoff Langc1984ed2016-10-07 12:41:00 -04002858 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002859 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002860 QuerySamplerParameteriv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002861 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002862}
Jamie Madill9675b802013-07-19 16:36:59 -04002863
Brandon Jones59770802018-04-02 13:18:42 -07002864void Context::getSamplerParameterivRobust(GLuint sampler,
2865 GLenum pname,
2866 GLsizei bufSize,
2867 GLsizei *length,
2868 GLint *params)
2869{
2870 getSamplerParameteriv(sampler, pname, params);
2871}
2872
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002873void Context::getSamplerParameterIivRobust(GLuint sampler,
2874 GLenum pname,
2875 GLsizei bufSize,
2876 GLsizei *length,
2877 GLint *params)
2878{
2879 UNIMPLEMENTED();
2880}
2881
2882void Context::getSamplerParameterIuivRobust(GLuint sampler,
2883 GLenum pname,
2884 GLsizei bufSize,
2885 GLsizei *length,
2886 GLuint *params)
2887{
2888 UNIMPLEMENTED();
2889}
2890
Geoff Langc1984ed2016-10-07 12:41:00 -04002891void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2892{
2893 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002894 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002895 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002896 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002897}
2898
Brandon Jones59770802018-04-02 13:18:42 -07002899void Context::getSamplerParameterfvRobust(GLuint sampler,
2900 GLenum pname,
2901 GLsizei bufSize,
2902 GLsizei *length,
2903 GLfloat *params)
2904{
2905 getSamplerParameterfv(sampler, pname, params);
2906}
2907
Olli Etuahof0fee072016-03-30 15:11:58 +03002908void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2909{
2910 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002911 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002912}
2913
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002914void Context::initRendererString()
2915{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002916 std::ostringstream rendererString;
2917 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002918 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002919 rendererString << ")";
2920
Geoff Langcec35902014-04-16 10:52:36 -04002921 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002922}
2923
Geoff Langc339c4e2016-11-29 10:37:36 -05002924void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002925{
Geoff Langc339c4e2016-11-29 10:37:36 -05002926 const Version &clientVersion = getClientVersion();
2927
2928 std::ostringstream versionString;
2929 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2930 << ANGLE_VERSION_STRING << ")";
2931 mVersionString = MakeStaticString(versionString.str());
2932
2933 std::ostringstream shadingLanguageVersionString;
2934 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2935 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2936 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2937 << ")";
2938 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002939}
2940
Geoff Langcec35902014-04-16 10:52:36 -04002941void Context::initExtensionStrings()
2942{
Geoff Langc339c4e2016-11-29 10:37:36 -05002943 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2944 std::ostringstream combinedStringStream;
2945 std::copy(strings.begin(), strings.end(),
2946 std::ostream_iterator<const char *>(combinedStringStream, " "));
2947 return MakeStaticString(combinedStringStream.str());
2948 };
2949
2950 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002951 for (const auto &extensionString : mExtensions.getStrings())
2952 {
2953 mExtensionStrings.push_back(MakeStaticString(extensionString));
2954 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002955 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002956
Geoff Langc339c4e2016-11-29 10:37:36 -05002957 mRequestableExtensionStrings.clear();
2958 for (const auto &extensionInfo : GetExtensionInfoMap())
2959 {
2960 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08002961 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
Geoff Langb0f917f2017-12-05 13:41:54 -05002962 mSupportedExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002963 {
2964 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
2965 }
2966 }
2967 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002968}
2969
Geoff Langc339c4e2016-11-29 10:37:36 -05002970const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04002971{
Geoff Langc339c4e2016-11-29 10:37:36 -05002972 switch (name)
2973 {
2974 case GL_VENDOR:
2975 return reinterpret_cast<const GLubyte *>("Google Inc.");
2976
2977 case GL_RENDERER:
2978 return reinterpret_cast<const GLubyte *>(mRendererString);
2979
2980 case GL_VERSION:
2981 return reinterpret_cast<const GLubyte *>(mVersionString);
2982
2983 case GL_SHADING_LANGUAGE_VERSION:
2984 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
2985
2986 case GL_EXTENSIONS:
2987 return reinterpret_cast<const GLubyte *>(mExtensionString);
2988
2989 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2990 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
2991
2992 default:
2993 UNREACHABLE();
2994 return nullptr;
2995 }
Geoff Langcec35902014-04-16 10:52:36 -04002996}
2997
Geoff Langc339c4e2016-11-29 10:37:36 -05002998const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04002999{
Geoff Langc339c4e2016-11-29 10:37:36 -05003000 switch (name)
3001 {
3002 case GL_EXTENSIONS:
3003 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
3004
3005 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
3006 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
3007
3008 default:
3009 UNREACHABLE();
3010 return nullptr;
3011 }
Geoff Langcec35902014-04-16 10:52:36 -04003012}
3013
3014size_t Context::getExtensionStringCount() const
3015{
3016 return mExtensionStrings.size();
3017}
3018
Geoff Lang111a99e2017-10-17 10:58:41 -04003019bool Context::isExtensionRequestable(const char *name)
3020{
3021 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3022 auto extension = extensionInfos.find(name);
3023
Geoff Lang111a99e2017-10-17 10:58:41 -04003024 return extension != extensionInfos.end() && extension->second.Requestable &&
Geoff Langb0f917f2017-12-05 13:41:54 -05003025 mSupportedExtensions.*(extension->second.ExtensionsMember);
Geoff Lang111a99e2017-10-17 10:58:41 -04003026}
3027
Geoff Langc339c4e2016-11-29 10:37:36 -05003028void Context::requestExtension(const char *name)
3029{
3030 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3031 ASSERT(extensionInfos.find(name) != extensionInfos.end());
3032 const auto &extension = extensionInfos.at(name);
3033 ASSERT(extension.Requestable);
Geoff Langb0f917f2017-12-05 13:41:54 -05003034 ASSERT(isExtensionRequestable(name));
Geoff Langc339c4e2016-11-29 10:37:36 -05003035
3036 if (mExtensions.*(extension.ExtensionsMember))
3037 {
3038 // Extension already enabled
3039 return;
3040 }
3041
3042 mExtensions.*(extension.ExtensionsMember) = true;
3043 updateCaps();
3044 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08003045
Jamie Madill2f348d22017-06-05 10:50:59 -04003046 // Release the shader compiler so it will be re-created with the requested extensions enabled.
3047 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04003048
Jamie Madill81c2e252017-09-09 23:32:46 -04003049 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
3050 // sampleable.
Jamie Madilld4442552018-02-27 22:03:47 -05003051 mState.mTextures->signalAllTexturesDirty(this);
Geoff Lang9aded172017-04-05 11:07:56 -04003052 for (auto &zeroTexture : mZeroTextures)
3053 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003054 if (zeroTexture.get() != nullptr)
3055 {
3056 zeroTexture->signalDirty(this, InitState::Initialized);
3057 }
Geoff Lang9aded172017-04-05 11:07:56 -04003058 }
3059
3060 mState.mFramebuffers->invalidateFramebufferComplenessCache();
Geoff Langc339c4e2016-11-29 10:37:36 -05003061}
3062
3063size_t Context::getRequestableExtensionStringCount() const
3064{
3065 return mRequestableExtensionStrings.size();
3066}
3067
Jamie Madill493f9572018-05-24 19:52:15 -04003068void Context::beginTransformFeedback(PrimitiveMode primitiveMode)
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003069{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003070 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003071 ASSERT(transformFeedback != nullptr);
3072 ASSERT(!transformFeedback->isPaused());
3073
Jamie Madill6c1f6712017-02-14 19:08:04 -05003074 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003075}
3076
3077bool Context::hasActiveTransformFeedback(GLuint program) const
3078{
3079 for (auto pair : mTransformFeedbackMap)
3080 {
3081 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
3082 {
3083 return true;
3084 }
3085 }
3086 return false;
3087}
3088
Geoff Lang33f11fb2018-05-07 13:42:47 -04003089Extensions Context::generateSupportedExtensions() const
Geoff Langb0f917f2017-12-05 13:41:54 -05003090{
3091 Extensions supportedExtensions = mImplementation->getNativeExtensions();
3092
jchen1082af6202018-06-22 10:59:52 +08003093 // Explicitly enable GL_KHR_parallel_shader_compile
3094 supportedExtensions.parallelShaderCompile = true;
3095
Geoff Langb0f917f2017-12-05 13:41:54 -05003096 if (getClientVersion() < ES_2_0)
3097 {
3098 // Default extensions for GLES1
Lingfeng Yang0df813c2018-07-12 12:52:06 -07003099 supportedExtensions.pointSizeArray = true;
3100 supportedExtensions.textureCubeMap = true;
3101 supportedExtensions.pointSprite = true;
3102 supportedExtensions.drawTexture = true;
jchen1082af6202018-06-22 10:59:52 +08003103 supportedExtensions.parallelShaderCompile = false;
Geoff Langb0f917f2017-12-05 13:41:54 -05003104 }
3105
3106 if (getClientVersion() < ES_3_0)
3107 {
3108 // Disable ES3+ extensions
3109 supportedExtensions.colorBufferFloat = false;
3110 supportedExtensions.eglImageExternalEssl3 = false;
3111 supportedExtensions.textureNorm16 = false;
3112 supportedExtensions.multiview = false;
3113 supportedExtensions.maxViews = 1u;
3114 }
3115
3116 if (getClientVersion() < ES_3_1)
3117 {
3118 // Disable ES3.1+ extensions
3119 supportedExtensions.geometryShader = false;
3120 }
3121
3122 if (getClientVersion() > ES_2_0)
3123 {
3124 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
3125 // supportedExtensions.sRGB = false;
3126 }
3127
3128 // Some extensions are always available because they are implemented in the GL layer.
3129 supportedExtensions.bindUniformLocation = true;
3130 supportedExtensions.vertexArrayObject = true;
3131 supportedExtensions.bindGeneratesResource = true;
3132 supportedExtensions.clientArrays = true;
3133 supportedExtensions.requestExtension = true;
3134
3135 // Enable the no error extension if the context was created with the flag.
3136 supportedExtensions.noError = mSkipValidation;
3137
3138 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Geoff Lang33f11fb2018-05-07 13:42:47 -04003139 supportedExtensions.surfacelessContext = mSurfacelessSupported;
Geoff Langb0f917f2017-12-05 13:41:54 -05003140
3141 // Explicitly enable GL_KHR_debug
3142 supportedExtensions.debug = true;
3143 supportedExtensions.maxDebugMessageLength = 1024;
3144 supportedExtensions.maxDebugLoggedMessages = 1024;
3145 supportedExtensions.maxDebugGroupStackDepth = 1024;
3146 supportedExtensions.maxLabelLength = 1024;
3147
3148 // Explicitly enable GL_ANGLE_robust_client_memory
3149 supportedExtensions.robustClientMemory = true;
3150
3151 // Determine robust resource init availability from EGL.
Geoff Lang33f11fb2018-05-07 13:42:47 -04003152 supportedExtensions.robustResourceInitialization = mGLState.isRobustResourceInitEnabled();
Geoff Langb0f917f2017-12-05 13:41:54 -05003153
3154 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
3155 // supports it.
3156 supportedExtensions.robustBufferAccessBehavior =
3157 mRobustAccess && supportedExtensions.robustBufferAccessBehavior;
3158
3159 // Enable the cache control query unconditionally.
3160 supportedExtensions.programCacheControl = true;
3161
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003162 // Enable EGL_ANGLE_explicit_context subextensions
Geoff Lang33f11fb2018-05-07 13:42:47 -04003163 if (mExplicitContextAvailable)
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003164 {
3165 // GL_ANGLE_explicit_context_gles1
3166 supportedExtensions.explicitContextGles1 = true;
3167 // GL_ANGLE_explicit_context
3168 supportedExtensions.explicitContext = true;
3169 }
3170
Geoff Langb0f917f2017-12-05 13:41:54 -05003171 return supportedExtensions;
3172}
3173
Geoff Lang33f11fb2018-05-07 13:42:47 -04003174void Context::initCaps()
Geoff Lang493daf52014-07-03 13:38:44 -04003175{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04003176 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04003177
Geoff Lang33f11fb2018-05-07 13:42:47 -04003178 mSupportedExtensions = generateSupportedExtensions();
3179 mExtensions = mSupportedExtensions;
Lingfeng Yang01074432018-04-16 10:19:51 -07003180
3181 mLimitations = mImplementation->getNativeLimitations();
3182
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003183 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
3184 if (getClientVersion() < Version(2, 0))
3185 {
3186 mCaps.maxMultitextureUnits = 4;
3187 mCaps.maxClipPlanes = 6;
3188 mCaps.maxLights = 8;
Lingfeng Yange547aac2018-04-05 09:39:20 -07003189 mCaps.maxModelviewMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3190 mCaps.maxProjectionMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3191 mCaps.maxTextureMatrixStackDepth = Caps::GlobalMatrixStackDepth;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003192 mCaps.minSmoothPointSize = 1.0f;
3193 mCaps.maxSmoothPointSize = 1.0f;
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003194 }
3195
Luc Ferronad2ae932018-06-11 15:31:17 -04003196 // Apply/Verify implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04003197 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003198
Luc Ferronad2ae932018-06-11 15:31:17 -04003199 ASSERT(mCaps.minAliasedPointSize >= 1.0f);
3200
Jamie Madill0f80ed82017-09-19 00:24:56 -04003201 if (getClientVersion() < ES_3_1)
3202 {
3203 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
3204 }
3205 else
3206 {
3207 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
3208 }
Geoff Lang301d1612014-07-09 10:34:37 -04003209
Jiawei Shao54aafe52018-04-27 14:54:57 +08003210 LimitCap(&mCaps.maxShaderUniformBlocks[ShaderType::Vertex],
3211 IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
Jamie Madill0f80ed82017-09-19 00:24:56 -04003212 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3213 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3214
3215 // Limit textures as well, so we can use fast bitsets with texture bindings.
3216 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
Jiawei Shao54aafe52018-04-27 14:54:57 +08003217 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Vertex],
3218 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
3219 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Fragment],
3220 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04003221
Jiawei Shaodb342272017-09-27 10:21:45 +08003222 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
3223
Geoff Langc287ea62016-09-16 14:46:51 -04003224 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05003225 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04003226 for (const auto &extensionInfo : GetExtensionInfoMap())
3227 {
Geoff Lang0ab41fa2018-03-14 11:03:30 -04003228 // If the user has requested that extensions start disabled and they are requestable,
3229 // disable them.
3230 if (!mExtensionsEnabled && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04003231 {
3232 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
3233 }
3234 }
3235
3236 // Generate texture caps
3237 updateCaps();
3238}
3239
3240void Context::updateCaps()
3241{
Geoff Lang900013c2014-07-07 11:32:19 -04003242 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04003243 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04003244
Jamie Madill7b62cf92017-11-02 15:20:49 -04003245 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04003246 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04003247 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04003248 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003249
Geoff Lang0d8b7242015-09-09 14:56:53 -04003250 // Update the format caps based on the client version and extensions.
3251 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
3252 // ES3.
3253 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003254 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04003255 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003256 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Yuly Novikovf15f8862018-06-04 18:59:41 -04003257 formatCaps.textureAttachment =
3258 formatCaps.textureAttachment &&
3259 formatInfo.textureAttachmentSupport(getClientVersion(), mExtensions);
3260 formatCaps.renderbuffer = formatCaps.renderbuffer &&
3261 formatInfo.renderbufferSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04003262
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003263 // OpenGL ES does not support multisampling with non-rendererable formats
3264 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Yuly Novikovf15f8862018-06-04 18:59:41 -04003265 if (!formatCaps.renderbuffer ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003266 (getClientVersion() < ES_3_1 &&
3267 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04003268 {
Geoff Langd87878e2014-09-19 15:42:59 -04003269 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04003270 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03003271 else
3272 {
3273 // We may have limited the max samples for some required renderbuffer formats due to
3274 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
3275 GLuint formatMaxSamples = formatCaps.getMaxSamples();
3276
3277 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
3278 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
3279 // exception of signed and unsigned integer formats."
3280 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
3281 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
3282 {
3283 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
3284 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
3285 }
3286
3287 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
3288 if (getClientVersion() >= ES_3_1)
3289 {
3290 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
3291 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
3292 // the exception that the signed and unsigned integer formats are required only to
3293 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
3294 // multisamples, which must be at least one."
3295 if (formatInfo.componentType == GL_INT ||
3296 formatInfo.componentType == GL_UNSIGNED_INT)
3297 {
3298 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
3299 }
3300
3301 // GLES 3.1 section 19.3.1.
3302 if (formatCaps.texturable)
3303 {
3304 if (formatInfo.depthBits > 0)
3305 {
3306 mCaps.maxDepthTextureSamples =
3307 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
3308 }
3309 else if (formatInfo.redBits > 0)
3310 {
3311 mCaps.maxColorTextureSamples =
3312 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
3313 }
3314 }
3315 }
3316 }
Geoff Langd87878e2014-09-19 15:42:59 -04003317
3318 if (formatCaps.texturable && formatInfo.compressed)
3319 {
Geoff Langca271392017-04-05 12:30:00 -04003320 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003321 }
3322
Geoff Langca271392017-04-05 12:30:00 -04003323 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04003324 }
Jamie Madill32447362017-06-28 14:53:52 -04003325
3326 // If program binary is disabled, blank out the memory cache pointer.
Geoff Langb0f917f2017-12-05 13:41:54 -05003327 if (!mSupportedExtensions.getProgramBinary)
Jamie Madill32447362017-06-28 14:53:52 -04003328 {
3329 mMemoryProgramCache = nullptr;
3330 }
Corentin Walleze4477002017-12-01 14:39:58 -05003331
3332 // Compute which buffer types are allowed
3333 mValidBufferBindings.reset();
3334 mValidBufferBindings.set(BufferBinding::ElementArray);
3335 mValidBufferBindings.set(BufferBinding::Array);
3336
3337 if (mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
3338 {
3339 mValidBufferBindings.set(BufferBinding::PixelPack);
3340 mValidBufferBindings.set(BufferBinding::PixelUnpack);
3341 }
3342
3343 if (getClientVersion() >= ES_3_0)
3344 {
3345 mValidBufferBindings.set(BufferBinding::CopyRead);
3346 mValidBufferBindings.set(BufferBinding::CopyWrite);
3347 mValidBufferBindings.set(BufferBinding::TransformFeedback);
3348 mValidBufferBindings.set(BufferBinding::Uniform);
3349 }
3350
3351 if (getClientVersion() >= ES_3_1)
3352 {
3353 mValidBufferBindings.set(BufferBinding::AtomicCounter);
3354 mValidBufferBindings.set(BufferBinding::ShaderStorage);
3355 mValidBufferBindings.set(BufferBinding::DrawIndirect);
3356 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
3357 }
Geoff Lang493daf52014-07-03 13:38:44 -04003358}
3359
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003360void Context::initWorkarounds()
3361{
Jamie Madill761b02c2017-06-23 16:27:06 -04003362 // Apply back-end workarounds.
3363 mImplementation->applyNativeWorkarounds(&mWorkarounds);
3364
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003365 // Lose the context upon out of memory error if the application is
3366 // expecting to watch for those events.
3367 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
3368}
3369
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06003370// Return true if the draw is a no-op, else return false.
3371// A no-op draw occurs if the count of vertices is less than the minimum required to
3372// have a valid primitive for this mode (0 for points, 0-1 for lines, 0-2 for tris).
3373bool Context::noopDraw(PrimitiveMode mode, GLsizei count)
3374{
3375 return count < kMinimumPrimitiveCounts[mode];
3376}
3377
3378bool Context::noopDrawInstanced(PrimitiveMode mode, GLsizei count, GLsizei instanceCount)
3379{
3380 return (instanceCount == 0) || noopDraw(mode, count);
3381}
3382
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003383Error Context::prepareForDraw(PrimitiveMode mode)
Jamie Madill05b35b22017-10-03 09:01:44 -04003384{
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003385 if (mGLES1Renderer)
3386 {
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003387 ANGLE_TRY(mGLES1Renderer->prepareForDraw(mode, this, &mGLState));
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003388 }
3389
Geoff Lang9bf86f02018-07-26 11:46:34 -04003390 ANGLE_TRY(syncDirtyObjects(mDrawDirtyObjects));
Jamie Madilla59fc192017-11-02 12:57:58 -04003391
3392 if (isRobustResourceInitEnabled())
3393 {
3394 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
3395 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
3396 }
3397
Geoff Langa8cb2872018-03-09 16:09:40 -05003398 ANGLE_TRY(syncDirtyBits());
Geoff Langd4fff502017-09-22 11:28:28 -04003399 return NoError();
3400}
3401
3402Error Context::prepareForClear(GLbitfield mask)
3403{
Geoff Langa8cb2872018-03-09 16:09:40 -05003404 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003405 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearAttachmentsInitialized(this, mask));
Geoff Langa8cb2872018-03-09 16:09:40 -05003406 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04003407 return NoError();
3408}
3409
3410Error Context::prepareForClearBuffer(GLenum buffer, GLint drawbuffer)
3411{
Geoff Langa8cb2872018-03-09 16:09:40 -05003412 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003413 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearBufferAttachmentsInitialized(this, buffer,
3414 drawbuffer));
Geoff Langa8cb2872018-03-09 16:09:40 -05003415 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill05b35b22017-10-03 09:01:44 -04003416 return NoError();
3417}
3418
Geoff Langa8cb2872018-03-09 16:09:40 -05003419Error Context::syncState(const State::DirtyBits &bitMask, const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04003420{
Geoff Langa8cb2872018-03-09 16:09:40 -05003421 ANGLE_TRY(syncDirtyObjects(objectMask));
3422 ANGLE_TRY(syncDirtyBits(bitMask));
Geoff Langd4fff502017-09-22 11:28:28 -04003423 return NoError();
3424}
3425
Geoff Langa8cb2872018-03-09 16:09:40 -05003426Error Context::syncDirtyBits()
Geoff Langd4fff502017-09-22 11:28:28 -04003427{
3428 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
Jamie Madill189ad872018-07-09 13:32:37 -04003429 ANGLE_TRY(mImplementation->syncState(this, dirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04003430 mGLState.clearDirtyBits();
3431 return NoError();
3432}
3433
Geoff Langa8cb2872018-03-09 16:09:40 -05003434Error Context::syncDirtyBits(const State::DirtyBits &bitMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003435{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003436 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madill189ad872018-07-09 13:32:37 -04003437 ANGLE_TRY(mImplementation->syncState(this, dirtyBits));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003438 mGLState.clearDirtyBits(dirtyBits);
Jamie Madillbc918e72018-03-08 09:47:21 -05003439 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003440}
Jamie Madillc29968b2016-01-20 11:17:23 -05003441
Geoff Langa8cb2872018-03-09 16:09:40 -05003442Error Context::syncDirtyObjects(const State::DirtyObjects &objectMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003443{
3444 return mGLState.syncDirtyObjects(this, objectMask);
3445}
3446
Jamie Madillc29968b2016-01-20 11:17:23 -05003447void Context::blitFramebuffer(GLint srcX0,
3448 GLint srcY0,
3449 GLint srcX1,
3450 GLint srcY1,
3451 GLint dstX0,
3452 GLint dstY0,
3453 GLint dstX1,
3454 GLint dstY1,
3455 GLbitfield mask,
3456 GLenum filter)
3457{
Qin Jiajiaaef92162018-02-27 13:51:44 +08003458 if (mask == 0)
3459 {
3460 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
3461 // buffers are copied.
3462 return;
3463 }
3464
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003465 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003466 ASSERT(drawFramebuffer);
3467
3468 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
3469 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
3470
Jamie Madillbc918e72018-03-08 09:47:21 -05003471 ANGLE_CONTEXT_TRY(syncStateForBlit());
Jamie Madillc29968b2016-01-20 11:17:23 -05003472
Jamie Madillc564c072017-06-01 12:45:42 -04003473 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003474}
Jamie Madillc29968b2016-01-20 11:17:23 -05003475
3476void Context::clear(GLbitfield mask)
3477{
Geoff Langd4fff502017-09-22 11:28:28 -04003478 ANGLE_CONTEXT_TRY(prepareForClear(mask));
3479 ANGLE_CONTEXT_TRY(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05003480}
3481
3482void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
3483{
Geoff Langd4fff502017-09-22 11:28:28 -04003484 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3485 ANGLE_CONTEXT_TRY(
3486 mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003487}
3488
3489void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3490{
Geoff Langd4fff502017-09-22 11:28:28 -04003491 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3492 ANGLE_CONTEXT_TRY(
3493 mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003494}
3495
3496void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3497{
Geoff Langd4fff502017-09-22 11:28:28 -04003498 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3499 ANGLE_CONTEXT_TRY(
3500 mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003501}
3502
3503void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3504{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003505 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003506 ASSERT(framebufferObject);
3507
3508 // If a buffer is not present, the clear has no effect
3509 if (framebufferObject->getDepthbuffer() == nullptr &&
3510 framebufferObject->getStencilbuffer() == nullptr)
3511 {
3512 return;
3513 }
3514
Geoff Langd4fff502017-09-22 11:28:28 -04003515 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3516 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003517}
3518
3519void Context::readPixels(GLint x,
3520 GLint y,
3521 GLsizei width,
3522 GLsizei height,
3523 GLenum format,
3524 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003525 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003526{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003527 if (width == 0 || height == 0)
3528 {
3529 return;
3530 }
3531
Jamie Madillbc918e72018-03-08 09:47:21 -05003532 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003533
Jamie Madillb6664922017-07-25 12:55:04 -04003534 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3535 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003536
3537 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04003538 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003539}
3540
Brandon Jones59770802018-04-02 13:18:42 -07003541void Context::readPixelsRobust(GLint x,
3542 GLint y,
3543 GLsizei width,
3544 GLsizei height,
3545 GLenum format,
3546 GLenum type,
3547 GLsizei bufSize,
3548 GLsizei *length,
3549 GLsizei *columns,
3550 GLsizei *rows,
3551 void *pixels)
3552{
3553 readPixels(x, y, width, height, format, type, pixels);
3554}
3555
3556void Context::readnPixelsRobust(GLint x,
3557 GLint y,
3558 GLsizei width,
3559 GLsizei height,
3560 GLenum format,
3561 GLenum type,
3562 GLsizei bufSize,
3563 GLsizei *length,
3564 GLsizei *columns,
3565 GLsizei *rows,
3566 void *data)
3567{
3568 readPixels(x, y, width, height, format, type, data);
3569}
3570
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003571void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003572 GLint level,
3573 GLenum internalformat,
3574 GLint x,
3575 GLint y,
3576 GLsizei width,
3577 GLsizei height,
3578 GLint border)
3579{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003580 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003581 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003582
Jamie Madillc29968b2016-01-20 11:17:23 -05003583 Rectangle sourceArea(x, y, width, height);
3584
Jamie Madill05b35b22017-10-03 09:01:44 -04003585 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003586 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003587 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003588}
3589
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003590void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003591 GLint level,
3592 GLint xoffset,
3593 GLint yoffset,
3594 GLint x,
3595 GLint y,
3596 GLsizei width,
3597 GLsizei height)
3598{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003599 if (width == 0 || height == 0)
3600 {
3601 return;
3602 }
3603
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003604 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003605 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003606
Jamie Madillc29968b2016-01-20 11:17:23 -05003607 Offset destOffset(xoffset, yoffset, 0);
3608 Rectangle sourceArea(x, y, width, height);
3609
Jamie Madill05b35b22017-10-03 09:01:44 -04003610 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003611 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003612 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003613}
3614
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003615void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003616 GLint level,
3617 GLint xoffset,
3618 GLint yoffset,
3619 GLint zoffset,
3620 GLint x,
3621 GLint y,
3622 GLsizei width,
3623 GLsizei height)
3624{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003625 if (width == 0 || height == 0)
3626 {
3627 return;
3628 }
3629
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003630 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003631 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003632
Jamie Madillc29968b2016-01-20 11:17:23 -05003633 Offset destOffset(xoffset, yoffset, zoffset);
3634 Rectangle sourceArea(x, y, width, height);
3635
Jamie Madill05b35b22017-10-03 09:01:44 -04003636 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3637 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003638 handleError(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level, destOffset,
3639 sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003640}
3641
3642void Context::framebufferTexture2D(GLenum target,
3643 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003644 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003645 GLuint texture,
3646 GLint level)
3647{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003648 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003649 ASSERT(framebuffer);
3650
3651 if (texture != 0)
3652 {
3653 Texture *textureObj = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003654 ImageIndex index = ImageIndex::MakeFromTarget(textarget, level);
Jamie Madilla02315b2017-02-23 14:14:47 -05003655 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003656 }
3657 else
3658 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003659 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003660 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003661
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003662 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003663}
3664
3665void Context::framebufferRenderbuffer(GLenum target,
3666 GLenum attachment,
3667 GLenum renderbuffertarget,
3668 GLuint renderbuffer)
3669{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003670 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003671 ASSERT(framebuffer);
3672
3673 if (renderbuffer != 0)
3674 {
3675 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003676
Jamie Madillcc129372018-04-12 09:13:18 -04003677 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003678 renderbufferObject);
3679 }
3680 else
3681 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003682 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003683 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003684
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003685 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003686}
3687
3688void Context::framebufferTextureLayer(GLenum target,
3689 GLenum attachment,
3690 GLuint texture,
3691 GLint level,
3692 GLint layer)
3693{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003694 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003695 ASSERT(framebuffer);
3696
3697 if (texture != 0)
3698 {
3699 Texture *textureObject = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003700 ImageIndex index = ImageIndex::MakeFromType(textureObject->getType(), level, layer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003701 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003702 }
3703 else
3704 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003705 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003706 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003707
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003708 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003709}
3710
Brandon Jones59770802018-04-02 13:18:42 -07003711void Context::framebufferTextureMultiviewLayered(GLenum target,
3712 GLenum attachment,
3713 GLuint texture,
3714 GLint level,
3715 GLint baseViewIndex,
3716 GLsizei numViews)
Martin Radev137032d2017-07-13 10:11:12 +03003717{
Martin Radev82ef7742017-08-08 17:44:58 +03003718 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3719 ASSERT(framebuffer);
3720
3721 if (texture != 0)
3722 {
3723 Texture *textureObj = getTexture(texture);
3724
Martin Radev18b75ba2017-08-15 15:50:40 +03003725 ImageIndex index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
Martin Radev82ef7742017-08-08 17:44:58 +03003726 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3727 numViews, baseViewIndex);
3728 }
3729 else
3730 {
3731 framebuffer->resetAttachment(this, attachment);
3732 }
3733
3734 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003735}
3736
Brandon Jones59770802018-04-02 13:18:42 -07003737void Context::framebufferTextureMultiviewSideBySide(GLenum target,
3738 GLenum attachment,
3739 GLuint texture,
3740 GLint level,
3741 GLsizei numViews,
3742 const GLint *viewportOffsets)
Martin Radev137032d2017-07-13 10:11:12 +03003743{
Martin Radev5dae57b2017-07-14 16:15:55 +03003744 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3745 ASSERT(framebuffer);
3746
3747 if (texture != 0)
3748 {
3749 Texture *textureObj = getTexture(texture);
3750
3751 ImageIndex index = ImageIndex::Make2D(level);
3752 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3753 textureObj, numViews, viewportOffsets);
3754 }
3755 else
3756 {
3757 framebuffer->resetAttachment(this, attachment);
3758 }
3759
3760 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003761}
3762
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003763void Context::framebufferTexture(GLenum target, GLenum attachment, GLuint texture, GLint level)
3764{
Jiawei Shaoa8802472018-05-28 11:17:47 +08003765 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3766 ASSERT(framebuffer);
3767
3768 if (texture != 0)
3769 {
3770 Texture *textureObj = getTexture(texture);
3771
3772 ImageIndex index = ImageIndex::MakeFromType(
3773 textureObj->getType(), level, ImageIndex::kEntireLevel, ImageIndex::kEntireLevel);
3774 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
3775 }
3776 else
3777 {
3778 framebuffer->resetAttachment(this, attachment);
3779 }
3780
3781 mGLState.setObjectDirty(target);
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003782}
3783
Jamie Madillc29968b2016-01-20 11:17:23 -05003784void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3785{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003786 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003787 ASSERT(framebuffer);
3788 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003789 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003790}
3791
3792void Context::readBuffer(GLenum mode)
3793{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003794 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003795 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003796 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003797}
3798
3799void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3800{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003801 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003802 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003803
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003804 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003805 ASSERT(framebuffer);
3806
3807 // The specification isn't clear what should be done when the framebuffer isn't complete.
3808 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003809 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003810}
3811
3812void Context::invalidateFramebuffer(GLenum target,
3813 GLsizei numAttachments,
3814 const GLenum *attachments)
3815{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003816 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003817 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003818
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003819 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003820 ASSERT(framebuffer);
3821
Jamie Madill427064d2018-04-13 16:20:34 -04003822 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003823 {
Jamie Madill437fa652016-05-03 15:13:24 -04003824 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003825 }
Jamie Madill437fa652016-05-03 15:13:24 -04003826
Jamie Madill4928b7c2017-06-20 12:57:39 -04003827 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003828}
3829
3830void Context::invalidateSubFramebuffer(GLenum target,
3831 GLsizei numAttachments,
3832 const GLenum *attachments,
3833 GLint x,
3834 GLint y,
3835 GLsizei width,
3836 GLsizei height)
3837{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003838 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003839 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003840
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003841 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003842 ASSERT(framebuffer);
3843
Jamie Madill427064d2018-04-13 16:20:34 -04003844 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003845 {
Jamie Madill437fa652016-05-03 15:13:24 -04003846 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003847 }
Jamie Madill437fa652016-05-03 15:13:24 -04003848
3849 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003850 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003851}
3852
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003853void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003854 GLint level,
3855 GLint internalformat,
3856 GLsizei width,
3857 GLsizei height,
3858 GLint border,
3859 GLenum format,
3860 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003861 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003862{
Jamie Madillbc918e72018-03-08 09:47:21 -05003863 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003864
3865 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003866 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003867 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003868 size, format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003869}
3870
Brandon Jones59770802018-04-02 13:18:42 -07003871void Context::texImage2DRobust(TextureTarget target,
3872 GLint level,
3873 GLint internalformat,
3874 GLsizei width,
3875 GLsizei height,
3876 GLint border,
3877 GLenum format,
3878 GLenum type,
3879 GLsizei bufSize,
3880 const void *pixels)
3881{
3882 texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
3883}
3884
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003885void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003886 GLint level,
3887 GLint internalformat,
3888 GLsizei width,
3889 GLsizei height,
3890 GLsizei depth,
3891 GLint border,
3892 GLenum format,
3893 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003894 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003895{
Jamie Madillbc918e72018-03-08 09:47:21 -05003896 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003897
3898 Extents size(width, height, depth);
3899 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003900 handleError(texture->setImage(this, mGLState.getUnpackState(),
3901 NonCubeTextureTypeToTarget(target), level, internalformat, size,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003902 format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003903}
3904
Brandon Jones59770802018-04-02 13:18:42 -07003905void Context::texImage3DRobust(TextureType target,
3906 GLint level,
3907 GLint internalformat,
3908 GLsizei width,
3909 GLsizei height,
3910 GLsizei depth,
3911 GLint border,
3912 GLenum format,
3913 GLenum type,
3914 GLsizei bufSize,
3915 const void *pixels)
3916{
3917 texImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels);
3918}
3919
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003920void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003921 GLint level,
3922 GLint xoffset,
3923 GLint yoffset,
3924 GLsizei width,
3925 GLsizei height,
3926 GLenum format,
3927 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003928 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003929{
3930 // Zero sized uploads are valid but no-ops
3931 if (width == 0 || height == 0)
3932 {
3933 return;
3934 }
3935
Jamie Madillbc918e72018-03-08 09:47:21 -05003936 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003937
3938 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003939 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003940 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003941 type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003942}
3943
Brandon Jones59770802018-04-02 13:18:42 -07003944void Context::texSubImage2DRobust(TextureTarget target,
3945 GLint level,
3946 GLint xoffset,
3947 GLint yoffset,
3948 GLsizei width,
3949 GLsizei height,
3950 GLenum format,
3951 GLenum type,
3952 GLsizei bufSize,
3953 const void *pixels)
3954{
3955 texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
3956}
3957
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003958void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003959 GLint level,
3960 GLint xoffset,
3961 GLint yoffset,
3962 GLint zoffset,
3963 GLsizei width,
3964 GLsizei height,
3965 GLsizei depth,
3966 GLenum format,
3967 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003968 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003969{
3970 // Zero sized uploads are valid but no-ops
3971 if (width == 0 || height == 0 || depth == 0)
3972 {
3973 return;
3974 }
3975
Jamie Madillbc918e72018-03-08 09:47:21 -05003976 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003977
3978 Box area(xoffset, yoffset, zoffset, width, height, depth);
3979 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003980 handleError(texture->setSubImage(this, mGLState.getUnpackState(),
3981 NonCubeTextureTypeToTarget(target), level, area, format, type,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003982 static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003983}
3984
Brandon Jones59770802018-04-02 13:18:42 -07003985void Context::texSubImage3DRobust(TextureType target,
3986 GLint level,
3987 GLint xoffset,
3988 GLint yoffset,
3989 GLint zoffset,
3990 GLsizei width,
3991 GLsizei height,
3992 GLsizei depth,
3993 GLenum format,
3994 GLenum type,
3995 GLsizei bufSize,
3996 const void *pixels)
3997{
3998 texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type,
3999 pixels);
4000}
4001
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004002void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004003 GLint level,
4004 GLenum internalformat,
4005 GLsizei width,
4006 GLsizei height,
4007 GLint border,
4008 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004009 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004010{
Jamie Madillbc918e72018-03-08 09:47:21 -05004011 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004012
4013 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004014 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05004015 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
4016 internalformat, size, imageSize,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004017 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004018}
4019
Brandon Jones59770802018-04-02 13:18:42 -07004020void Context::compressedTexImage2DRobust(TextureTarget target,
4021 GLint level,
4022 GLenum internalformat,
4023 GLsizei width,
4024 GLsizei height,
4025 GLint border,
4026 GLsizei imageSize,
4027 GLsizei dataSize,
4028 const GLvoid *data)
4029{
4030 compressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
4031}
4032
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004033void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004034 GLint level,
4035 GLenum internalformat,
4036 GLsizei width,
4037 GLsizei height,
4038 GLsizei depth,
4039 GLint border,
4040 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004041 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004042{
Jamie Madillbc918e72018-03-08 09:47:21 -05004043 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004044
4045 Extents size(width, height, depth);
4046 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004047 handleError(texture->setCompressedImage(
4048 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004049 size, imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004050}
4051
Brandon Jones59770802018-04-02 13:18:42 -07004052void Context::compressedTexImage3DRobust(TextureType target,
4053 GLint level,
4054 GLenum internalformat,
4055 GLsizei width,
4056 GLsizei height,
4057 GLsizei depth,
4058 GLint border,
4059 GLsizei imageSize,
4060 GLsizei dataSize,
4061 const GLvoid *data)
4062{
4063 compressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize,
4064 data);
4065}
4066
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004067void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004068 GLint level,
4069 GLint xoffset,
4070 GLint yoffset,
4071 GLsizei width,
4072 GLsizei height,
4073 GLenum format,
4074 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004075 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004076{
Jamie Madillbc918e72018-03-08 09:47:21 -05004077 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004078
4079 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004080 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05004081 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
4082 format, imageSize,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004083 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004084}
4085
Brandon Jones59770802018-04-02 13:18:42 -07004086void Context::compressedTexSubImage2DRobust(TextureTarget target,
4087 GLint level,
4088 GLint xoffset,
4089 GLint yoffset,
4090 GLsizei width,
4091 GLsizei height,
4092 GLenum format,
4093 GLsizei imageSize,
4094 GLsizei dataSize,
4095 const GLvoid *data)
4096{
4097 compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize,
4098 data);
4099}
4100
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004101void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004102 GLint level,
4103 GLint xoffset,
4104 GLint yoffset,
4105 GLint zoffset,
4106 GLsizei width,
4107 GLsizei height,
4108 GLsizei depth,
4109 GLenum format,
4110 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004111 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004112{
4113 // Zero sized uploads are valid but no-ops
4114 if (width == 0 || height == 0)
4115 {
4116 return;
4117 }
4118
Jamie Madillbc918e72018-03-08 09:47:21 -05004119 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004120
4121 Box area(xoffset, yoffset, zoffset, width, height, depth);
4122 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004123 handleError(texture->setCompressedSubImage(
4124 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004125 imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004126}
4127
Brandon Jones59770802018-04-02 13:18:42 -07004128void Context::compressedTexSubImage3DRobust(TextureType target,
4129 GLint level,
4130 GLint xoffset,
4131 GLint yoffset,
4132 GLint zoffset,
4133 GLsizei width,
4134 GLsizei height,
4135 GLsizei depth,
4136 GLenum format,
4137 GLsizei imageSize,
4138 GLsizei dataSize,
4139 const GLvoid *data)
4140{
4141 compressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format,
4142 imageSize, data);
4143}
4144
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004145void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004146{
4147 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05004148 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004149}
4150
Jamie Madill007530e2017-12-28 14:27:04 -05004151void Context::copyTexture(GLuint sourceId,
4152 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004153 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004154 GLuint destId,
4155 GLint destLevel,
4156 GLint internalFormat,
4157 GLenum destType,
4158 GLboolean unpackFlipY,
4159 GLboolean unpackPremultiplyAlpha,
4160 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004161{
Jamie Madillbc918e72018-03-08 09:47:21 -05004162 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004163
4164 gl::Texture *sourceTexture = getTexture(sourceId);
4165 gl::Texture *destTexture = getTexture(destId);
Geoff Lang92019432017-11-20 13:09:34 -05004166 handleError(destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType,
4167 sourceLevel, ConvertToBool(unpackFlipY),
4168 ConvertToBool(unpackPremultiplyAlpha),
4169 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004170}
4171
Jamie Madill007530e2017-12-28 14:27:04 -05004172void Context::copySubTexture(GLuint sourceId,
4173 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004174 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004175 GLuint destId,
4176 GLint destLevel,
4177 GLint xoffset,
4178 GLint yoffset,
4179 GLint x,
4180 GLint y,
4181 GLsizei width,
4182 GLsizei height,
4183 GLboolean unpackFlipY,
4184 GLboolean unpackPremultiplyAlpha,
4185 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004186{
4187 // Zero sized copies are valid but no-ops
4188 if (width == 0 || height == 0)
4189 {
4190 return;
4191 }
4192
Jamie Madillbc918e72018-03-08 09:47:21 -05004193 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004194
4195 gl::Texture *sourceTexture = getTexture(sourceId);
4196 gl::Texture *destTexture = getTexture(destId);
4197 Offset offset(xoffset, yoffset, 0);
4198 Rectangle area(x, y, width, height);
Geoff Lang92019432017-11-20 13:09:34 -05004199 handleError(destTexture->copySubTexture(this, destTarget, destLevel, offset, sourceLevel, area,
4200 ConvertToBool(unpackFlipY),
4201 ConvertToBool(unpackPremultiplyAlpha),
4202 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004203}
4204
Jamie Madill007530e2017-12-28 14:27:04 -05004205void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07004206{
Jamie Madillbc918e72018-03-08 09:47:21 -05004207 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07004208
4209 gl::Texture *sourceTexture = getTexture(sourceId);
4210 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05004211 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07004212}
4213
Corentin Wallez336129f2017-10-17 15:55:40 -04004214void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03004215{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004216 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004217 ASSERT(buffer);
4218
Geoff Lang496c02d2016-10-20 11:38:11 -07004219 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03004220}
4221
Brandon Jones59770802018-04-02 13:18:42 -07004222void Context::getBufferPointervRobust(BufferBinding target,
4223 GLenum pname,
4224 GLsizei bufSize,
4225 GLsizei *length,
4226 void **params)
4227{
4228 getBufferPointerv(target, pname, params);
4229}
4230
Corentin Wallez336129f2017-10-17 15:55:40 -04004231void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004232{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004233 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004234 ASSERT(buffer);
4235
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004236 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004237 if (error.isError())
4238 {
Jamie Madill437fa652016-05-03 15:13:24 -04004239 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004240 return nullptr;
4241 }
4242
4243 return buffer->getMapPointer();
4244}
4245
Corentin Wallez336129f2017-10-17 15:55:40 -04004246GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03004247{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004248 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004249 ASSERT(buffer);
4250
4251 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004252 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03004253 if (error.isError())
4254 {
Jamie Madill437fa652016-05-03 15:13:24 -04004255 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004256 return GL_FALSE;
4257 }
4258
4259 return result;
4260}
4261
Corentin Wallez336129f2017-10-17 15:55:40 -04004262void *Context::mapBufferRange(BufferBinding target,
4263 GLintptr offset,
4264 GLsizeiptr length,
4265 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004266{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004267 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004268 ASSERT(buffer);
4269
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004270 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004271 if (error.isError())
4272 {
Jamie Madill437fa652016-05-03 15:13:24 -04004273 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004274 return nullptr;
4275 }
4276
4277 return buffer->getMapPointer();
4278}
4279
Corentin Wallez336129f2017-10-17 15:55:40 -04004280void Context::flushMappedBufferRange(BufferBinding /*target*/,
4281 GLintptr /*offset*/,
4282 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03004283{
4284 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
4285}
4286
Jamie Madillbc918e72018-03-08 09:47:21 -05004287Error Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004288{
Geoff Langa8cb2872018-03-09 16:09:40 -05004289 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004290}
4291
Jamie Madillbc918e72018-03-08 09:47:21 -05004292Error Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004293{
Geoff Langa8cb2872018-03-09 16:09:40 -05004294 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004295}
4296
Jamie Madillbc918e72018-03-08 09:47:21 -05004297Error Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004298{
Geoff Langa8cb2872018-03-09 16:09:40 -05004299 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004300}
4301
Geoff Lang9bf86f02018-07-26 11:46:34 -04004302Error Context::syncStateForPathOperation()
4303{
4304 ANGLE_TRY(syncDirtyObjects(mPathOperationDirtyObjects));
4305
4306 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
4307 ANGLE_TRY(syncDirtyBits());
4308
4309 return NoError();
4310}
4311
Jiajia Qin5451d532017-11-16 17:16:34 +08004312void Context::activeShaderProgram(GLuint pipeline, GLuint program)
4313{
4314 UNIMPLEMENTED();
4315}
4316
Jamie Madillc20ab272016-06-09 07:20:46 -07004317void Context::activeTexture(GLenum texture)
4318{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004319 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004320}
4321
Jamie Madill876429b2017-04-20 15:46:24 -04004322void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004323{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004324 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004325}
4326
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004327void Context::blendEquation(GLenum mode)
4328{
4329 mGLState.setBlendEquation(mode, mode);
4330}
4331
Jamie Madillc20ab272016-06-09 07:20:46 -07004332void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
4333{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004334 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004335}
4336
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004337void Context::blendFunc(GLenum sfactor, GLenum dfactor)
4338{
4339 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
4340}
4341
Jamie Madillc20ab272016-06-09 07:20:46 -07004342void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
4343{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004344 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004345}
4346
Jamie Madill876429b2017-04-20 15:46:24 -04004347void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004348{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004349 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004350}
4351
Jamie Madill876429b2017-04-20 15:46:24 -04004352void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07004353{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004354 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07004355}
4356
4357void Context::clearStencil(GLint s)
4358{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004359 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07004360}
4361
4362void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
4363{
Geoff Lang92019432017-11-20 13:09:34 -05004364 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
4365 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004366}
4367
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004368void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07004369{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004370 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004371}
4372
4373void Context::depthFunc(GLenum func)
4374{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004375 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07004376}
4377
4378void Context::depthMask(GLboolean flag)
4379{
Geoff Lang92019432017-11-20 13:09:34 -05004380 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07004381}
4382
Jamie Madill876429b2017-04-20 15:46:24 -04004383void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07004384{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004385 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07004386}
4387
4388void Context::disable(GLenum cap)
4389{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004390 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07004391}
4392
4393void Context::disableVertexAttribArray(GLuint index)
4394{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004395 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madilldc358af2018-07-31 11:22:13 -04004396 mStateCache.updateActiveAttribsMask(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004397}
4398
4399void Context::enable(GLenum cap)
4400{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004401 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07004402}
4403
4404void Context::enableVertexAttribArray(GLuint index)
4405{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004406 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madilldc358af2018-07-31 11:22:13 -04004407 mStateCache.updateActiveAttribsMask(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004408}
4409
4410void Context::frontFace(GLenum mode)
4411{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004412 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004413}
4414
4415void Context::hint(GLenum target, GLenum mode)
4416{
4417 switch (target)
4418 {
4419 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004420 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004421 break;
4422
4423 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004424 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004425 break;
4426
4427 default:
4428 UNREACHABLE();
4429 return;
4430 }
4431}
4432
4433void Context::lineWidth(GLfloat width)
4434{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004435 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07004436}
4437
4438void Context::pixelStorei(GLenum pname, GLint param)
4439{
4440 switch (pname)
4441 {
4442 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004443 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004444 break;
4445
4446 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004447 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004448 break;
4449
4450 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004451 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004452 break;
4453
4454 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004455 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004456 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004457 break;
4458
4459 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03004460 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004461 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004462 break;
4463
4464 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03004465 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004466 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004467 break;
4468
4469 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004470 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004471 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004472 break;
4473
4474 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004475 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004476 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004477 break;
4478
4479 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004480 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004481 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004482 break;
4483
4484 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004485 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004486 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004487 break;
4488
4489 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004490 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004491 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004492 break;
4493
4494 default:
4495 UNREACHABLE();
4496 return;
4497 }
4498}
4499
4500void Context::polygonOffset(GLfloat factor, GLfloat units)
4501{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004502 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07004503}
4504
Jamie Madill876429b2017-04-20 15:46:24 -04004505void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07004506{
Geoff Lang92019432017-11-20 13:09:34 -05004507 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07004508}
4509
Jiawei Shaodb342272017-09-27 10:21:45 +08004510void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
4511{
4512 mGLState.setSampleMaskParams(maskNumber, mask);
4513}
4514
Jamie Madillc20ab272016-06-09 07:20:46 -07004515void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
4516{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004517 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004518}
4519
4520void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
4521{
4522 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4523 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004524 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004525 }
4526
4527 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4528 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004529 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004530 }
4531}
4532
4533void Context::stencilMaskSeparate(GLenum face, GLuint mask)
4534{
4535 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4536 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004537 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004538 }
4539
4540 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4541 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004542 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004543 }
4544}
4545
4546void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4547{
4548 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4549 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004550 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004551 }
4552
4553 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4554 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004555 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004556 }
4557}
4558
4559void Context::vertexAttrib1f(GLuint index, GLfloat x)
4560{
4561 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004562 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004563}
4564
4565void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
4566{
4567 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004568 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004569}
4570
4571void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4572{
4573 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004574 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004575}
4576
4577void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
4578{
4579 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004580 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004581}
4582
4583void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4584{
4585 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004586 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004587}
4588
4589void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
4590{
4591 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004592 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004593}
4594
4595void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4596{
4597 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004598 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004599}
4600
4601void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
4602{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004603 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07004604}
4605
4606void Context::vertexAttribPointer(GLuint index,
4607 GLint size,
4608 GLenum type,
4609 GLboolean normalized,
4610 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004611 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07004612{
Corentin Wallez336129f2017-10-17 15:55:40 -04004613 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05004614 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madilldc358af2018-07-31 11:22:13 -04004615 mStateCache.updateActiveAttribsMask(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004616}
4617
Shao80957d92017-02-20 21:25:59 +08004618void Context::vertexAttribFormat(GLuint attribIndex,
4619 GLint size,
4620 GLenum type,
4621 GLboolean normalized,
4622 GLuint relativeOffset)
4623{
Geoff Lang92019432017-11-20 13:09:34 -05004624 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08004625 relativeOffset);
4626}
4627
4628void Context::vertexAttribIFormat(GLuint attribIndex,
4629 GLint size,
4630 GLenum type,
4631 GLuint relativeOffset)
4632{
4633 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
4634}
4635
4636void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4637{
Shaodde78e82017-05-22 14:13:27 +08004638 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Jamie Madilldc358af2018-07-31 11:22:13 -04004639 mStateCache.updateActiveAttribsMask(this);
Shao80957d92017-02-20 21:25:59 +08004640}
4641
Jiajia Qin5451d532017-11-16 17:16:34 +08004642void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004643{
4644 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
4645}
4646
Jamie Madillc20ab272016-06-09 07:20:46 -07004647void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4648{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004649 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004650}
4651
4652void Context::vertexAttribIPointer(GLuint index,
4653 GLint size,
4654 GLenum type,
4655 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004656 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004657{
Corentin Wallez336129f2017-10-17 15:55:40 -04004658 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
4659 size, type, false, true, stride, pointer);
Jamie Madilldc358af2018-07-31 11:22:13 -04004660 mStateCache.updateActiveAttribsMask(this);
Jamie Madillc20ab272016-06-09 07:20:46 -07004661}
4662
4663void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4664{
4665 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004666 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004667}
4668
4669void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4670{
4671 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004672 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004673}
4674
4675void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4676{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004677 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004678}
4679
4680void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4681{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004682 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004683}
4684
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004685void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4686{
4687 const VertexAttribCurrentValueData &currentValues =
4688 getGLState().getVertexAttribCurrentValue(index);
4689 const VertexArray *vao = getGLState().getVertexArray();
4690 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4691 currentValues, pname, params);
4692}
4693
Brandon Jones59770802018-04-02 13:18:42 -07004694void Context::getVertexAttribivRobust(GLuint index,
4695 GLenum pname,
4696 GLsizei bufSize,
4697 GLsizei *length,
4698 GLint *params)
4699{
4700 getVertexAttribiv(index, pname, params);
4701}
4702
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004703void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4704{
4705 const VertexAttribCurrentValueData &currentValues =
4706 getGLState().getVertexAttribCurrentValue(index);
4707 const VertexArray *vao = getGLState().getVertexArray();
4708 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4709 currentValues, pname, params);
4710}
4711
Brandon Jones59770802018-04-02 13:18:42 -07004712void Context::getVertexAttribfvRobust(GLuint index,
4713 GLenum pname,
4714 GLsizei bufSize,
4715 GLsizei *length,
4716 GLfloat *params)
4717{
4718 getVertexAttribfv(index, pname, params);
4719}
4720
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004721void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4722{
4723 const VertexAttribCurrentValueData &currentValues =
4724 getGLState().getVertexAttribCurrentValue(index);
4725 const VertexArray *vao = getGLState().getVertexArray();
4726 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4727 currentValues, pname, params);
4728}
4729
Brandon Jones59770802018-04-02 13:18:42 -07004730void Context::getVertexAttribIivRobust(GLuint index,
4731 GLenum pname,
4732 GLsizei bufSize,
4733 GLsizei *length,
4734 GLint *params)
4735{
4736 getVertexAttribIiv(index, pname, params);
4737}
4738
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004739void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4740{
4741 const VertexAttribCurrentValueData &currentValues =
4742 getGLState().getVertexAttribCurrentValue(index);
4743 const VertexArray *vao = getGLState().getVertexArray();
4744 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4745 currentValues, pname, params);
4746}
4747
Brandon Jones59770802018-04-02 13:18:42 -07004748void Context::getVertexAttribIuivRobust(GLuint index,
4749 GLenum pname,
4750 GLsizei bufSize,
4751 GLsizei *length,
4752 GLuint *params)
4753{
4754 getVertexAttribIuiv(index, pname, params);
4755}
4756
Jamie Madill876429b2017-04-20 15:46:24 -04004757void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004758{
4759 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
4760 QueryVertexAttribPointerv(attrib, pname, pointer);
4761}
4762
Brandon Jones59770802018-04-02 13:18:42 -07004763void Context::getVertexAttribPointervRobust(GLuint index,
4764 GLenum pname,
4765 GLsizei bufSize,
4766 GLsizei *length,
4767 void **pointer)
4768{
4769 getVertexAttribPointerv(index, pname, pointer);
4770}
4771
Jamie Madillc20ab272016-06-09 07:20:46 -07004772void Context::debugMessageControl(GLenum source,
4773 GLenum type,
4774 GLenum severity,
4775 GLsizei count,
4776 const GLuint *ids,
4777 GLboolean enabled)
4778{
4779 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004780 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05004781 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004782}
4783
4784void Context::debugMessageInsert(GLenum source,
4785 GLenum type,
4786 GLuint id,
4787 GLenum severity,
4788 GLsizei length,
4789 const GLchar *buf)
4790{
4791 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004792 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004793}
4794
4795void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4796{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004797 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004798}
4799
4800GLuint Context::getDebugMessageLog(GLuint count,
4801 GLsizei bufSize,
4802 GLenum *sources,
4803 GLenum *types,
4804 GLuint *ids,
4805 GLenum *severities,
4806 GLsizei *lengths,
4807 GLchar *messageLog)
4808{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004809 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4810 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004811}
4812
4813void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4814{
4815 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004816 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05004817 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07004818}
4819
4820void Context::popDebugGroup()
4821{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004822 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05004823 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004824}
4825
Corentin Wallez336129f2017-10-17 15:55:40 -04004826void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004827{
4828 Buffer *buffer = mGLState.getTargetBuffer(target);
4829 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004830 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004831}
4832
Corentin Wallez336129f2017-10-17 15:55:40 -04004833void Context::bufferSubData(BufferBinding target,
4834 GLintptr offset,
4835 GLsizeiptr size,
4836 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004837{
4838 if (data == nullptr)
4839 {
4840 return;
4841 }
4842
4843 Buffer *buffer = mGLState.getTargetBuffer(target);
4844 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004845 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004846}
4847
Jamie Madillef300b12016-10-07 15:12:09 -04004848void Context::attachShader(GLuint program, GLuint shader)
4849{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05004850 Program *programObject = mState.mShaderPrograms->getProgram(program);
4851 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004852 ASSERT(programObject && shaderObject);
4853 programObject->attachShader(shaderObject);
4854}
4855
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004856const Workarounds &Context::getWorkarounds() const
4857{
4858 return mWorkarounds;
4859}
4860
Corentin Wallez336129f2017-10-17 15:55:40 -04004861void Context::copyBufferSubData(BufferBinding readTarget,
4862 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04004863 GLintptr readOffset,
4864 GLintptr writeOffset,
4865 GLsizeiptr size)
4866{
4867 // if size is zero, the copy is a successful no-op
4868 if (size == 0)
4869 {
4870 return;
4871 }
4872
4873 // TODO(jmadill): cache these.
4874 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4875 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4876
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004877 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004878}
4879
Jamie Madill01a80ee2016-11-07 12:06:18 -05004880void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4881{
4882 Program *programObject = getProgram(program);
4883 // TODO(jmadill): Re-use this from the validation if possible.
4884 ASSERT(programObject);
4885 programObject->bindAttributeLocation(index, name);
4886}
4887
Corentin Wallez336129f2017-10-17 15:55:40 -04004888void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004889{
Corentin Wallez336129f2017-10-17 15:55:40 -04004890 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4891 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004892}
4893
Corentin Wallez336129f2017-10-17 15:55:40 -04004894void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08004895{
4896 bindBufferRange(target, index, buffer, 0, 0);
4897}
4898
Corentin Wallez336129f2017-10-17 15:55:40 -04004899void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08004900 GLuint index,
4901 GLuint buffer,
4902 GLintptr offset,
4903 GLsizeiptr size)
4904{
Corentin Wallez336129f2017-10-17 15:55:40 -04004905 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4906 mGLState.setIndexedBufferBinding(this, target, index, bufferObject, offset, size);
Jiajia Qin6eafb042016-12-27 17:04:07 +08004907}
4908
Jamie Madill01a80ee2016-11-07 12:06:18 -05004909void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
4910{
4911 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4912 {
4913 bindReadFramebuffer(framebuffer);
4914 }
4915
4916 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4917 {
4918 bindDrawFramebuffer(framebuffer);
4919 }
4920}
4921
4922void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4923{
4924 ASSERT(target == GL_RENDERBUFFER);
4925 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004926 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04004927 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004928}
4929
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004930void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08004931 GLsizei samples,
4932 GLenum internalformat,
4933 GLsizei width,
4934 GLsizei height,
4935 GLboolean fixedsamplelocations)
4936{
4937 Extents size(width, height, 1);
4938 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004939 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
4940 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004941}
4942
4943void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4944{
JiangYizhou5b03f472017-01-09 10:22:53 +08004945 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
4946 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillbc918e72018-03-08 09:47:21 -05004947 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
JiangYizhou5b03f472017-01-09 10:22:53 +08004948 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08004949
4950 switch (pname)
4951 {
4952 case GL_SAMPLE_POSITION:
Geoff Lang13455072018-05-09 11:24:43 -04004953 handleError(framebuffer->getSamplePosition(this, index, val));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004954 break;
4955 default:
4956 UNREACHABLE();
4957 }
4958}
4959
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07004960void Context::getMultisamplefvRobust(GLenum pname,
4961 GLuint index,
4962 GLsizei bufSize,
4963 GLsizei *length,
4964 GLfloat *val)
4965{
4966 UNIMPLEMENTED();
4967}
4968
Jamie Madille8fb6402017-02-14 17:56:40 -05004969void Context::renderbufferStorage(GLenum target,
4970 GLenum internalformat,
4971 GLsizei width,
4972 GLsizei height)
4973{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004974 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4975 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
4976
Jamie Madille8fb6402017-02-14 17:56:40 -05004977 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04004978 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004979}
4980
4981void Context::renderbufferStorageMultisample(GLenum target,
4982 GLsizei samples,
4983 GLenum internalformat,
4984 GLsizei width,
4985 GLsizei height)
4986{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004987 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4988 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05004989
4990 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004991 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04004992 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004993}
4994
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004995void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
4996{
Jamie Madill70b5bb02017-08-28 13:32:37 -04004997 const Sync *syncObject = getSync(sync);
Jamie Madilla0691b72018-07-25 10:41:22 -04004998 handleError(QuerySynciv(this, syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004999}
5000
JiangYizhoue18e6392017-02-20 10:32:23 +08005001void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
5002{
5003 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5004 QueryFramebufferParameteriv(framebuffer, pname, params);
5005}
5006
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07005007void Context::getFramebufferParameterivRobust(GLenum target,
5008 GLenum pname,
5009 GLsizei bufSize,
5010 GLsizei *length,
5011 GLint *params)
5012{
5013 UNIMPLEMENTED();
5014}
5015
Jiajia Qin5451d532017-11-16 17:16:34 +08005016void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08005017{
5018 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5019 SetFramebufferParameteri(framebuffer, pname, param);
5020}
5021
Jamie Madilldec86232018-07-11 09:01:18 -04005022bool Context::getScratchBuffer(size_t requstedSizeBytes,
5023 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05005024{
Jamie Madilldec86232018-07-11 09:01:18 -04005025 return mScratchBuffer.get(requstedSizeBytes, scratchBufferOut);
Jamie Madillb3f26b92017-07-19 15:07:41 -04005026}
5027
Jamie Madilldec86232018-07-11 09:01:18 -04005028bool Context::getZeroFilledBuffer(size_t requstedSizeBytes,
5029 angle::MemoryBuffer **zeroBufferOut) const
Jamie Madillb3f26b92017-07-19 15:07:41 -04005030{
Jamie Madilldec86232018-07-11 09:01:18 -04005031 return mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0);
Jamie Madille14951e2017-03-09 18:55:16 -05005032}
5033
Xinghua Cao10a4d432017-11-28 14:46:26 +08005034Error Context::prepareForDispatch()
5035{
Geoff Langa8cb2872018-03-09 16:09:40 -05005036 ANGLE_TRY(syncState(mComputeDirtyBits, mComputeDirtyObjects));
Xinghua Cao10a4d432017-11-28 14:46:26 +08005037
5038 if (isRobustResourceInitEnabled())
5039 {
5040 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
5041 }
5042
5043 return NoError();
5044}
5045
Xinghua Cao2b396592017-03-29 15:36:04 +08005046void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
5047{
5048 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
5049 {
5050 return;
5051 }
5052
Xinghua Cao10a4d432017-11-28 14:46:26 +08005053 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill71c88b32017-09-14 22:20:29 -04005054 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08005055}
5056
Jiajia Qin5451d532017-11-16 17:16:34 +08005057void Context::dispatchComputeIndirect(GLintptr indirect)
5058{
Qin Jiajia62fcf622017-11-30 16:16:12 +08005059 ANGLE_CONTEXT_TRY(prepareForDispatch());
5060 handleError(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08005061}
5062
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005063void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005064 GLsizei levels,
5065 GLenum internalFormat,
5066 GLsizei width,
5067 GLsizei height)
5068{
5069 Extents size(width, height, 1);
5070 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005071 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005072}
5073
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005074void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005075 GLsizei levels,
5076 GLenum internalFormat,
5077 GLsizei width,
5078 GLsizei height,
5079 GLsizei depth)
5080{
5081 Extents size(width, height, depth);
5082 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005083 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005084}
5085
Jiajia Qin5451d532017-11-16 17:16:34 +08005086void Context::memoryBarrier(GLbitfield barriers)
5087{
Xinghua Cao89c422a2017-11-29 18:24:20 +08005088 handleError(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005089}
5090
5091void Context::memoryBarrierByRegion(GLbitfield barriers)
5092{
Xinghua Cao89c422a2017-11-29 18:24:20 +08005093 handleError(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005094}
5095
Jamie Madillc1d770e2017-04-13 17:31:24 -04005096GLenum Context::checkFramebufferStatus(GLenum target)
5097{
5098 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5099 ASSERT(framebuffer);
Jamie Madill427064d2018-04-13 16:20:34 -04005100 return framebuffer->checkStatus(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005101}
5102
5103void Context::compileShader(GLuint shader)
5104{
5105 Shader *shaderObject = GetValidShader(this, shader);
5106 if (!shaderObject)
5107 {
5108 return;
5109 }
5110 shaderObject->compile(this);
5111}
5112
5113void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
5114{
5115 for (int i = 0; i < n; i++)
5116 {
5117 deleteBuffer(buffers[i]);
5118 }
5119}
5120
5121void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
5122{
5123 for (int i = 0; i < n; i++)
5124 {
5125 if (framebuffers[i] != 0)
5126 {
5127 deleteFramebuffer(framebuffers[i]);
5128 }
5129 }
5130}
5131
5132void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
5133{
5134 for (int i = 0; i < n; i++)
5135 {
5136 deleteRenderbuffer(renderbuffers[i]);
5137 }
5138}
5139
5140void Context::deleteTextures(GLsizei n, const GLuint *textures)
5141{
5142 for (int i = 0; i < n; i++)
5143 {
5144 if (textures[i] != 0)
5145 {
5146 deleteTexture(textures[i]);
5147 }
5148 }
5149}
5150
5151void Context::detachShader(GLuint program, GLuint shader)
5152{
5153 Program *programObject = getProgram(program);
5154 ASSERT(programObject);
5155
5156 Shader *shaderObject = getShader(shader);
5157 ASSERT(shaderObject);
5158
5159 programObject->detachShader(this, shaderObject);
5160}
5161
5162void Context::genBuffers(GLsizei n, GLuint *buffers)
5163{
5164 for (int i = 0; i < n; i++)
5165 {
5166 buffers[i] = createBuffer();
5167 }
5168}
5169
5170void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
5171{
5172 for (int i = 0; i < n; i++)
5173 {
5174 framebuffers[i] = createFramebuffer();
5175 }
5176}
5177
5178void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
5179{
5180 for (int i = 0; i < n; i++)
5181 {
5182 renderbuffers[i] = createRenderbuffer();
5183 }
5184}
5185
5186void Context::genTextures(GLsizei n, GLuint *textures)
5187{
5188 for (int i = 0; i < n; i++)
5189 {
5190 textures[i] = createTexture();
5191 }
5192}
5193
5194void Context::getActiveAttrib(GLuint program,
5195 GLuint index,
5196 GLsizei bufsize,
5197 GLsizei *length,
5198 GLint *size,
5199 GLenum *type,
5200 GLchar *name)
5201{
5202 Program *programObject = getProgram(program);
5203 ASSERT(programObject);
5204 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
5205}
5206
5207void Context::getActiveUniform(GLuint program,
5208 GLuint index,
5209 GLsizei bufsize,
5210 GLsizei *length,
5211 GLint *size,
5212 GLenum *type,
5213 GLchar *name)
5214{
5215 Program *programObject = getProgram(program);
5216 ASSERT(programObject);
5217 programObject->getActiveUniform(index, bufsize, length, size, type, name);
5218}
5219
5220void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
5221{
5222 Program *programObject = getProgram(program);
5223 ASSERT(programObject);
5224 programObject->getAttachedShaders(maxcount, count, shaders);
5225}
5226
5227GLint Context::getAttribLocation(GLuint program, const GLchar *name)
5228{
5229 Program *programObject = getProgram(program);
5230 ASSERT(programObject);
5231 return programObject->getAttributeLocation(name);
5232}
5233
5234void Context::getBooleanv(GLenum pname, GLboolean *params)
5235{
5236 GLenum nativeType;
5237 unsigned int numParams = 0;
5238 getQueryParameterInfo(pname, &nativeType, &numParams);
5239
5240 if (nativeType == GL_BOOL)
5241 {
5242 getBooleanvImpl(pname, params);
5243 }
5244 else
5245 {
5246 CastStateValues(this, nativeType, pname, numParams, params);
5247 }
5248}
5249
Brandon Jones59770802018-04-02 13:18:42 -07005250void Context::getBooleanvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLboolean *params)
5251{
5252 getBooleanv(pname, params);
5253}
5254
Jamie Madillc1d770e2017-04-13 17:31:24 -04005255void Context::getFloatv(GLenum pname, GLfloat *params)
5256{
5257 GLenum nativeType;
5258 unsigned int numParams = 0;
5259 getQueryParameterInfo(pname, &nativeType, &numParams);
5260
5261 if (nativeType == GL_FLOAT)
5262 {
5263 getFloatvImpl(pname, params);
5264 }
5265 else
5266 {
5267 CastStateValues(this, nativeType, pname, numParams, params);
5268 }
5269}
5270
Brandon Jones59770802018-04-02 13:18:42 -07005271void Context::getFloatvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLfloat *params)
5272{
5273 getFloatv(pname, params);
5274}
5275
Jamie Madillc1d770e2017-04-13 17:31:24 -04005276void Context::getIntegerv(GLenum pname, GLint *params)
5277{
5278 GLenum nativeType;
5279 unsigned int numParams = 0;
5280 getQueryParameterInfo(pname, &nativeType, &numParams);
5281
5282 if (nativeType == GL_INT)
5283 {
5284 getIntegervImpl(pname, params);
5285 }
5286 else
5287 {
5288 CastStateValues(this, nativeType, pname, numParams, params);
5289 }
5290}
5291
Brandon Jones59770802018-04-02 13:18:42 -07005292void Context::getIntegervRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint *data)
5293{
5294 getIntegerv(pname, data);
5295}
5296
Jamie Madillc1d770e2017-04-13 17:31:24 -04005297void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
5298{
5299 Program *programObject = getProgram(program);
5300 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04005301 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005302}
5303
Brandon Jones59770802018-04-02 13:18:42 -07005304void Context::getProgramivRobust(GLuint program,
5305 GLenum pname,
5306 GLsizei bufSize,
5307 GLsizei *length,
5308 GLint *params)
5309{
5310 getProgramiv(program, pname, params);
5311}
5312
Jiajia Qin5451d532017-11-16 17:16:34 +08005313void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
5314{
5315 UNIMPLEMENTED();
5316}
5317
Jamie Madillbe849e42017-05-02 15:49:00 -04005318void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005319{
5320 Program *programObject = getProgram(program);
5321 ASSERT(programObject);
5322 programObject->getInfoLog(bufsize, length, infolog);
5323}
5324
Jiajia Qin5451d532017-11-16 17:16:34 +08005325void Context::getProgramPipelineInfoLog(GLuint pipeline,
5326 GLsizei bufSize,
5327 GLsizei *length,
5328 GLchar *infoLog)
5329{
5330 UNIMPLEMENTED();
5331}
5332
Jamie Madillc1d770e2017-04-13 17:31:24 -04005333void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
5334{
5335 Shader *shaderObject = getShader(shader);
5336 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04005337 QueryShaderiv(this, shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005338}
5339
Brandon Jones59770802018-04-02 13:18:42 -07005340void Context::getShaderivRobust(GLuint shader,
5341 GLenum pname,
5342 GLsizei bufSize,
5343 GLsizei *length,
5344 GLint *params)
5345{
5346 getShaderiv(shader, pname, params);
5347}
5348
Jamie Madillc1d770e2017-04-13 17:31:24 -04005349void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
5350{
5351 Shader *shaderObject = getShader(shader);
5352 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04005353 shaderObject->getInfoLog(this, bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005354}
5355
5356void Context::getShaderPrecisionFormat(GLenum shadertype,
5357 GLenum precisiontype,
5358 GLint *range,
5359 GLint *precision)
5360{
5361 // TODO(jmadill): Compute shaders.
5362
5363 switch (shadertype)
5364 {
5365 case GL_VERTEX_SHADER:
5366 switch (precisiontype)
5367 {
5368 case GL_LOW_FLOAT:
5369 mCaps.vertexLowpFloat.get(range, precision);
5370 break;
5371 case GL_MEDIUM_FLOAT:
5372 mCaps.vertexMediumpFloat.get(range, precision);
5373 break;
5374 case GL_HIGH_FLOAT:
5375 mCaps.vertexHighpFloat.get(range, precision);
5376 break;
5377
5378 case GL_LOW_INT:
5379 mCaps.vertexLowpInt.get(range, precision);
5380 break;
5381 case GL_MEDIUM_INT:
5382 mCaps.vertexMediumpInt.get(range, precision);
5383 break;
5384 case GL_HIGH_INT:
5385 mCaps.vertexHighpInt.get(range, precision);
5386 break;
5387
5388 default:
5389 UNREACHABLE();
5390 return;
5391 }
5392 break;
5393
5394 case GL_FRAGMENT_SHADER:
5395 switch (precisiontype)
5396 {
5397 case GL_LOW_FLOAT:
5398 mCaps.fragmentLowpFloat.get(range, precision);
5399 break;
5400 case GL_MEDIUM_FLOAT:
5401 mCaps.fragmentMediumpFloat.get(range, precision);
5402 break;
5403 case GL_HIGH_FLOAT:
5404 mCaps.fragmentHighpFloat.get(range, precision);
5405 break;
5406
5407 case GL_LOW_INT:
5408 mCaps.fragmentLowpInt.get(range, precision);
5409 break;
5410 case GL_MEDIUM_INT:
5411 mCaps.fragmentMediumpInt.get(range, precision);
5412 break;
5413 case GL_HIGH_INT:
5414 mCaps.fragmentHighpInt.get(range, precision);
5415 break;
5416
5417 default:
5418 UNREACHABLE();
5419 return;
5420 }
5421 break;
5422
5423 default:
5424 UNREACHABLE();
5425 return;
5426 }
5427}
5428
5429void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
5430{
5431 Shader *shaderObject = getShader(shader);
5432 ASSERT(shaderObject);
5433 shaderObject->getSource(bufsize, length, source);
5434}
5435
5436void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
5437{
5438 Program *programObject = getProgram(program);
5439 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005440 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005441}
5442
Brandon Jones59770802018-04-02 13:18:42 -07005443void Context::getUniformfvRobust(GLuint program,
5444 GLint location,
5445 GLsizei bufSize,
5446 GLsizei *length,
5447 GLfloat *params)
5448{
5449 getUniformfv(program, location, params);
5450}
5451
Jamie Madillc1d770e2017-04-13 17:31:24 -04005452void Context::getUniformiv(GLuint program, GLint location, GLint *params)
5453{
5454 Program *programObject = getProgram(program);
5455 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005456 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005457}
5458
Brandon Jones59770802018-04-02 13:18:42 -07005459void Context::getUniformivRobust(GLuint program,
5460 GLint location,
5461 GLsizei bufSize,
5462 GLsizei *length,
5463 GLint *params)
5464{
5465 getUniformiv(program, location, params);
5466}
5467
Jamie Madillc1d770e2017-04-13 17:31:24 -04005468GLint Context::getUniformLocation(GLuint program, const GLchar *name)
5469{
5470 Program *programObject = getProgram(program);
5471 ASSERT(programObject);
5472 return programObject->getUniformLocation(name);
5473}
5474
5475GLboolean Context::isBuffer(GLuint buffer)
5476{
5477 if (buffer == 0)
5478 {
5479 return GL_FALSE;
5480 }
5481
5482 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
5483}
5484
5485GLboolean Context::isEnabled(GLenum cap)
5486{
5487 return mGLState.getEnableFeature(cap);
5488}
5489
5490GLboolean Context::isFramebuffer(GLuint framebuffer)
5491{
5492 if (framebuffer == 0)
5493 {
5494 return GL_FALSE;
5495 }
5496
5497 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
5498}
5499
5500GLboolean Context::isProgram(GLuint program)
5501{
5502 if (program == 0)
5503 {
5504 return GL_FALSE;
5505 }
5506
5507 return (getProgram(program) ? GL_TRUE : GL_FALSE);
5508}
5509
5510GLboolean Context::isRenderbuffer(GLuint renderbuffer)
5511{
5512 if (renderbuffer == 0)
5513 {
5514 return GL_FALSE;
5515 }
5516
5517 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
5518}
5519
5520GLboolean Context::isShader(GLuint shader)
5521{
5522 if (shader == 0)
5523 {
5524 return GL_FALSE;
5525 }
5526
5527 return (getShader(shader) ? GL_TRUE : GL_FALSE);
5528}
5529
5530GLboolean Context::isTexture(GLuint texture)
5531{
5532 if (texture == 0)
5533 {
5534 return GL_FALSE;
5535 }
5536
5537 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
5538}
5539
5540void Context::linkProgram(GLuint program)
5541{
5542 Program *programObject = getProgram(program);
5543 ASSERT(programObject);
5544 handleError(programObject->link(this));
Martin Radev0abb7a22017-08-28 15:34:45 +03005545 mGLState.onProgramExecutableChange(programObject);
Jamie Madilldc358af2018-07-31 11:22:13 -04005546 mStateCache.updateActiveAttribsMask(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005547}
5548
5549void Context::releaseShaderCompiler()
5550{
Jamie Madill4928b7c2017-06-20 12:57:39 -04005551 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005552}
5553
5554void Context::shaderBinary(GLsizei n,
5555 const GLuint *shaders,
5556 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04005557 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005558 GLsizei length)
5559{
5560 // No binary shader formats are supported.
5561 UNIMPLEMENTED();
5562}
5563
5564void Context::shaderSource(GLuint shader,
5565 GLsizei count,
5566 const GLchar *const *string,
5567 const GLint *length)
5568{
5569 Shader *shaderObject = getShader(shader);
5570 ASSERT(shaderObject);
5571 shaderObject->setSource(count, string, length);
5572}
5573
5574void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
5575{
5576 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
5577}
5578
5579void Context::stencilMask(GLuint mask)
5580{
5581 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
5582}
5583
5584void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
5585{
5586 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
5587}
5588
5589void Context::uniform1f(GLint location, GLfloat x)
5590{
5591 Program *program = mGLState.getProgram();
5592 program->setUniform1fv(location, 1, &x);
5593}
5594
5595void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
5596{
5597 Program *program = mGLState.getProgram();
5598 program->setUniform1fv(location, count, v);
5599}
5600
5601void Context::uniform1i(GLint location, GLint x)
5602{
5603 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04005604 if (program->setUniform1iv(location, 1, &x) == Program::SetUniformResult::SamplerChanged)
5605 {
5606 mGLState.setObjectDirty(GL_PROGRAM);
5607 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005608}
5609
5610void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
5611{
5612 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04005613 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
5614 {
5615 mGLState.setObjectDirty(GL_PROGRAM);
5616 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005617}
5618
5619void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
5620{
5621 GLfloat xy[2] = {x, y};
5622 Program *program = mGLState.getProgram();
5623 program->setUniform2fv(location, 1, xy);
5624}
5625
5626void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
5627{
5628 Program *program = mGLState.getProgram();
5629 program->setUniform2fv(location, count, v);
5630}
5631
5632void Context::uniform2i(GLint location, GLint x, GLint y)
5633{
5634 GLint xy[2] = {x, y};
5635 Program *program = mGLState.getProgram();
5636 program->setUniform2iv(location, 1, xy);
5637}
5638
5639void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
5640{
5641 Program *program = mGLState.getProgram();
5642 program->setUniform2iv(location, count, v);
5643}
5644
5645void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
5646{
5647 GLfloat xyz[3] = {x, y, z};
5648 Program *program = mGLState.getProgram();
5649 program->setUniform3fv(location, 1, xyz);
5650}
5651
5652void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
5653{
5654 Program *program = mGLState.getProgram();
5655 program->setUniform3fv(location, count, v);
5656}
5657
5658void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
5659{
5660 GLint xyz[3] = {x, y, z};
5661 Program *program = mGLState.getProgram();
5662 program->setUniform3iv(location, 1, xyz);
5663}
5664
5665void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
5666{
5667 Program *program = mGLState.getProgram();
5668 program->setUniform3iv(location, count, v);
5669}
5670
5671void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
5672{
5673 GLfloat xyzw[4] = {x, y, z, w};
5674 Program *program = mGLState.getProgram();
5675 program->setUniform4fv(location, 1, xyzw);
5676}
5677
5678void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
5679{
5680 Program *program = mGLState.getProgram();
5681 program->setUniform4fv(location, count, v);
5682}
5683
5684void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
5685{
5686 GLint xyzw[4] = {x, y, z, w};
5687 Program *program = mGLState.getProgram();
5688 program->setUniform4iv(location, 1, xyzw);
5689}
5690
5691void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
5692{
5693 Program *program = mGLState.getProgram();
5694 program->setUniform4iv(location, count, v);
5695}
5696
5697void Context::uniformMatrix2fv(GLint location,
5698 GLsizei count,
5699 GLboolean transpose,
5700 const GLfloat *value)
5701{
5702 Program *program = mGLState.getProgram();
5703 program->setUniformMatrix2fv(location, count, transpose, value);
5704}
5705
5706void Context::uniformMatrix3fv(GLint location,
5707 GLsizei count,
5708 GLboolean transpose,
5709 const GLfloat *value)
5710{
5711 Program *program = mGLState.getProgram();
5712 program->setUniformMatrix3fv(location, count, transpose, value);
5713}
5714
5715void Context::uniformMatrix4fv(GLint location,
5716 GLsizei count,
5717 GLboolean transpose,
5718 const GLfloat *value)
5719{
5720 Program *program = mGLState.getProgram();
5721 program->setUniformMatrix4fv(location, count, transpose, value);
5722}
5723
5724void Context::validateProgram(GLuint program)
5725{
5726 Program *programObject = getProgram(program);
5727 ASSERT(programObject);
5728 programObject->validate(mCaps);
5729}
5730
Jiajia Qin5451d532017-11-16 17:16:34 +08005731void Context::validateProgramPipeline(GLuint pipeline)
5732{
5733 UNIMPLEMENTED();
5734}
5735
Jamie Madilld04908b2017-06-09 14:15:35 -04005736void Context::getProgramBinary(GLuint program,
5737 GLsizei bufSize,
5738 GLsizei *length,
5739 GLenum *binaryFormat,
5740 void *binary)
5741{
5742 Program *programObject = getProgram(program);
5743 ASSERT(programObject != nullptr);
5744
5745 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
5746}
5747
5748void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
5749{
5750 Program *programObject = getProgram(program);
5751 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04005752
Jamie Madilld04908b2017-06-09 14:15:35 -04005753 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
Jamie Madilldc358af2018-07-31 11:22:13 -04005754 mStateCache.updateActiveAttribsMask(this);
Jamie Madilld04908b2017-06-09 14:15:35 -04005755}
5756
Jamie Madillff325f12017-08-26 15:06:05 -04005757void Context::uniform1ui(GLint location, GLuint v0)
5758{
5759 Program *program = mGLState.getProgram();
5760 program->setUniform1uiv(location, 1, &v0);
5761}
5762
5763void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
5764{
5765 Program *program = mGLState.getProgram();
5766 const GLuint xy[] = {v0, v1};
5767 program->setUniform2uiv(location, 1, xy);
5768}
5769
5770void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
5771{
5772 Program *program = mGLState.getProgram();
5773 const GLuint xyz[] = {v0, v1, v2};
5774 program->setUniform3uiv(location, 1, xyz);
5775}
5776
5777void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
5778{
5779 Program *program = mGLState.getProgram();
5780 const GLuint xyzw[] = {v0, v1, v2, v3};
5781 program->setUniform4uiv(location, 1, xyzw);
5782}
5783
5784void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
5785{
5786 Program *program = mGLState.getProgram();
5787 program->setUniform1uiv(location, count, value);
5788}
5789void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
5790{
5791 Program *program = mGLState.getProgram();
5792 program->setUniform2uiv(location, count, value);
5793}
5794
5795void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
5796{
5797 Program *program = mGLState.getProgram();
5798 program->setUniform3uiv(location, count, value);
5799}
5800
5801void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
5802{
5803 Program *program = mGLState.getProgram();
5804 program->setUniform4uiv(location, count, value);
5805}
5806
Jamie Madillf0e04492017-08-26 15:28:42 -04005807void Context::genQueries(GLsizei n, GLuint *ids)
5808{
5809 for (GLsizei i = 0; i < n; i++)
5810 {
5811 GLuint handle = mQueryHandleAllocator.allocate();
5812 mQueryMap.assign(handle, nullptr);
5813 ids[i] = handle;
5814 }
5815}
5816
5817void Context::deleteQueries(GLsizei n, const GLuint *ids)
5818{
5819 for (int i = 0; i < n; i++)
5820 {
5821 GLuint query = ids[i];
5822
5823 Query *queryObject = nullptr;
5824 if (mQueryMap.erase(query, &queryObject))
5825 {
5826 mQueryHandleAllocator.release(query);
5827 if (queryObject)
5828 {
5829 queryObject->release(this);
5830 }
5831 }
5832 }
5833}
5834
5835GLboolean Context::isQuery(GLuint id)
5836{
Corentin Wallezad3ae902018-03-09 13:40:42 -05005837 return (getQuery(id, false, QueryType::InvalidEnum) != nullptr) ? GL_TRUE : GL_FALSE;
Jamie Madillf0e04492017-08-26 15:28:42 -04005838}
5839
Jamie Madillc8c95812017-08-26 18:40:09 -04005840void Context::uniformMatrix2x3fv(GLint location,
5841 GLsizei count,
5842 GLboolean transpose,
5843 const GLfloat *value)
5844{
5845 Program *program = mGLState.getProgram();
5846 program->setUniformMatrix2x3fv(location, count, transpose, value);
5847}
5848
5849void Context::uniformMatrix3x2fv(GLint location,
5850 GLsizei count,
5851 GLboolean transpose,
5852 const GLfloat *value)
5853{
5854 Program *program = mGLState.getProgram();
5855 program->setUniformMatrix3x2fv(location, count, transpose, value);
5856}
5857
5858void Context::uniformMatrix2x4fv(GLint location,
5859 GLsizei count,
5860 GLboolean transpose,
5861 const GLfloat *value)
5862{
5863 Program *program = mGLState.getProgram();
5864 program->setUniformMatrix2x4fv(location, count, transpose, value);
5865}
5866
5867void Context::uniformMatrix4x2fv(GLint location,
5868 GLsizei count,
5869 GLboolean transpose,
5870 const GLfloat *value)
5871{
5872 Program *program = mGLState.getProgram();
5873 program->setUniformMatrix4x2fv(location, count, transpose, value);
5874}
5875
5876void Context::uniformMatrix3x4fv(GLint location,
5877 GLsizei count,
5878 GLboolean transpose,
5879 const GLfloat *value)
5880{
5881 Program *program = mGLState.getProgram();
5882 program->setUniformMatrix3x4fv(location, count, transpose, value);
5883}
5884
5885void Context::uniformMatrix4x3fv(GLint location,
5886 GLsizei count,
5887 GLboolean transpose,
5888 const GLfloat *value)
5889{
5890 Program *program = mGLState.getProgram();
5891 program->setUniformMatrix4x3fv(location, count, transpose, value);
5892}
5893
Jamie Madilld7576732017-08-26 18:49:50 -04005894void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
5895{
5896 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5897 {
5898 GLuint vertexArray = arrays[arrayIndex];
5899
5900 if (arrays[arrayIndex] != 0)
5901 {
5902 VertexArray *vertexArrayObject = nullptr;
5903 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
5904 {
5905 if (vertexArrayObject != nullptr)
5906 {
5907 detachVertexArray(vertexArray);
5908 vertexArrayObject->onDestroy(this);
5909 }
5910
5911 mVertexArrayHandleAllocator.release(vertexArray);
5912 }
5913 }
5914 }
5915}
5916
5917void Context::genVertexArrays(GLsizei n, GLuint *arrays)
5918{
5919 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5920 {
5921 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
5922 mVertexArrayMap.assign(vertexArray, nullptr);
5923 arrays[arrayIndex] = vertexArray;
5924 }
5925}
5926
5927bool Context::isVertexArray(GLuint array)
5928{
5929 if (array == 0)
5930 {
5931 return GL_FALSE;
5932 }
5933
5934 VertexArray *vao = getVertexArray(array);
5935 return (vao != nullptr ? GL_TRUE : GL_FALSE);
5936}
5937
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04005938void Context::endTransformFeedback()
5939{
5940 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5941 transformFeedback->end(this);
5942}
5943
5944void Context::transformFeedbackVaryings(GLuint program,
5945 GLsizei count,
5946 const GLchar *const *varyings,
5947 GLenum bufferMode)
5948{
5949 Program *programObject = getProgram(program);
5950 ASSERT(programObject);
5951 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
5952}
5953
5954void Context::getTransformFeedbackVarying(GLuint program,
5955 GLuint index,
5956 GLsizei bufSize,
5957 GLsizei *length,
5958 GLsizei *size,
5959 GLenum *type,
5960 GLchar *name)
5961{
5962 Program *programObject = getProgram(program);
5963 ASSERT(programObject);
5964 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
5965}
5966
5967void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
5968{
5969 for (int i = 0; i < n; i++)
5970 {
5971 GLuint transformFeedback = ids[i];
5972 if (transformFeedback == 0)
5973 {
5974 continue;
5975 }
5976
5977 TransformFeedback *transformFeedbackObject = nullptr;
5978 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
5979 {
5980 if (transformFeedbackObject != nullptr)
5981 {
5982 detachTransformFeedback(transformFeedback);
5983 transformFeedbackObject->release(this);
5984 }
5985
5986 mTransformFeedbackHandleAllocator.release(transformFeedback);
5987 }
5988 }
5989}
5990
5991void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
5992{
5993 for (int i = 0; i < n; i++)
5994 {
5995 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
5996 mTransformFeedbackMap.assign(transformFeedback, nullptr);
5997 ids[i] = transformFeedback;
5998 }
5999}
6000
6001bool Context::isTransformFeedback(GLuint id)
6002{
6003 if (id == 0)
6004 {
6005 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
6006 // returns FALSE
6007 return GL_FALSE;
6008 }
6009
6010 const TransformFeedback *transformFeedback = getTransformFeedback(id);
6011 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
6012}
6013
6014void Context::pauseTransformFeedback()
6015{
6016 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6017 transformFeedback->pause();
6018}
6019
6020void Context::resumeTransformFeedback()
6021{
6022 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6023 transformFeedback->resume();
6024}
6025
Jamie Madill12e957f2017-08-26 21:42:26 -04006026void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
6027{
6028 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04006029 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04006030}
6031
Brandon Jones59770802018-04-02 13:18:42 -07006032void Context::getUniformuivRobust(GLuint program,
6033 GLint location,
6034 GLsizei bufSize,
6035 GLsizei *length,
6036 GLuint *params)
6037{
6038 getUniformuiv(program, location, params);
6039}
6040
Jamie Madill12e957f2017-08-26 21:42:26 -04006041GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
6042{
6043 const Program *programObject = getProgram(program);
6044 return programObject->getFragDataLocation(name);
6045}
6046
6047void Context::getUniformIndices(GLuint program,
6048 GLsizei uniformCount,
6049 const GLchar *const *uniformNames,
6050 GLuint *uniformIndices)
6051{
6052 const Program *programObject = getProgram(program);
6053 if (!programObject->isLinked())
6054 {
6055 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6056 {
6057 uniformIndices[uniformId] = GL_INVALID_INDEX;
6058 }
6059 }
6060 else
6061 {
6062 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6063 {
6064 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
6065 }
6066 }
6067}
6068
6069void Context::getActiveUniformsiv(GLuint program,
6070 GLsizei uniformCount,
6071 const GLuint *uniformIndices,
6072 GLenum pname,
6073 GLint *params)
6074{
6075 const Program *programObject = getProgram(program);
6076 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6077 {
6078 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08006079 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04006080 }
6081}
6082
6083GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
6084{
6085 const Program *programObject = getProgram(program);
6086 return programObject->getUniformBlockIndex(uniformBlockName);
6087}
6088
6089void Context::getActiveUniformBlockiv(GLuint program,
6090 GLuint uniformBlockIndex,
6091 GLenum pname,
6092 GLint *params)
6093{
6094 const Program *programObject = getProgram(program);
6095 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
6096}
6097
Brandon Jones59770802018-04-02 13:18:42 -07006098void Context::getActiveUniformBlockivRobust(GLuint program,
6099 GLuint uniformBlockIndex,
6100 GLenum pname,
6101 GLsizei bufSize,
6102 GLsizei *length,
6103 GLint *params)
6104{
6105 getActiveUniformBlockiv(program, uniformBlockIndex, pname, params);
6106}
6107
Jamie Madill12e957f2017-08-26 21:42:26 -04006108void Context::getActiveUniformBlockName(GLuint program,
6109 GLuint uniformBlockIndex,
6110 GLsizei bufSize,
6111 GLsizei *length,
6112 GLchar *uniformBlockName)
6113{
6114 const Program *programObject = getProgram(program);
6115 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
6116}
6117
6118void Context::uniformBlockBinding(GLuint program,
6119 GLuint uniformBlockIndex,
6120 GLuint uniformBlockBinding)
6121{
6122 Program *programObject = getProgram(program);
6123 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
6124}
6125
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006126GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
6127{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006128 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
6129 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006130
Jamie Madill70b5bb02017-08-28 13:32:37 -04006131 Sync *syncObject = getSync(syncHandle);
Jamie Madilla0691b72018-07-25 10:41:22 -04006132 Error error = syncObject->set(this, condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006133 if (error.isError())
6134 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04006135 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006136 handleError(error);
6137 return nullptr;
6138 }
6139
Jamie Madill70b5bb02017-08-28 13:32:37 -04006140 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006141}
6142
6143GLboolean Context::isSync(GLsync sync)
6144{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006145 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006146}
6147
6148GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6149{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006150 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006151
6152 GLenum result = GL_WAIT_FAILED;
Jamie Madilla0691b72018-07-25 10:41:22 -04006153 handleError(syncObject->clientWait(this, flags, timeout, &result));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006154 return result;
6155}
6156
6157void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6158{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006159 Sync *syncObject = getSync(sync);
Jamie Madilla0691b72018-07-25 10:41:22 -04006160 handleError(syncObject->serverWait(this, flags, timeout));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006161}
6162
6163void Context::getInteger64v(GLenum pname, GLint64 *params)
6164{
6165 GLenum nativeType = GL_NONE;
6166 unsigned int numParams = 0;
6167 getQueryParameterInfo(pname, &nativeType, &numParams);
6168
6169 if (nativeType == GL_INT_64_ANGLEX)
6170 {
6171 getInteger64vImpl(pname, params);
6172 }
6173 else
6174 {
6175 CastStateValues(this, nativeType, pname, numParams, params);
6176 }
6177}
6178
Brandon Jones59770802018-04-02 13:18:42 -07006179void Context::getInteger64vRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint64 *data)
6180{
6181 getInteger64v(pname, data);
6182}
6183
Corentin Wallez336129f2017-10-17 15:55:40 -04006184void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04006185{
6186 Buffer *buffer = mGLState.getTargetBuffer(target);
6187 QueryBufferParameteri64v(buffer, pname, params);
6188}
6189
Brandon Jones59770802018-04-02 13:18:42 -07006190void Context::getBufferParameteri64vRobust(BufferBinding target,
6191 GLenum pname,
6192 GLsizei bufSize,
6193 GLsizei *length,
6194 GLint64 *params)
6195{
6196 getBufferParameteri64v(target, pname, params);
6197}
6198
Jamie Madill3ef140a2017-08-26 23:11:21 -04006199void Context::genSamplers(GLsizei count, GLuint *samplers)
6200{
6201 for (int i = 0; i < count; i++)
6202 {
6203 samplers[i] = mState.mSamplers->createSampler();
6204 }
6205}
6206
6207void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
6208{
6209 for (int i = 0; i < count; i++)
6210 {
6211 GLuint sampler = samplers[i];
6212
6213 if (mState.mSamplers->getSampler(sampler))
6214 {
6215 detachSampler(sampler);
6216 }
6217
6218 mState.mSamplers->deleteObject(this, sampler);
6219 }
6220}
6221
6222void Context::getInternalformativ(GLenum target,
6223 GLenum internalformat,
6224 GLenum pname,
6225 GLsizei bufSize,
6226 GLint *params)
6227{
6228 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
6229 QueryInternalFormativ(formatCaps, pname, bufSize, params);
6230}
6231
Brandon Jones59770802018-04-02 13:18:42 -07006232void Context::getInternalformativRobust(GLenum target,
6233 GLenum internalformat,
6234 GLenum pname,
6235 GLsizei bufSize,
6236 GLsizei *length,
6237 GLint *params)
6238{
6239 getInternalformativ(target, internalformat, pname, bufSize, params);
6240}
6241
Jiajia Qin5451d532017-11-16 17:16:34 +08006242void Context::programUniform1i(GLuint program, GLint location, GLint v0)
6243{
6244 programUniform1iv(program, location, 1, &v0);
6245}
6246
6247void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
6248{
6249 GLint xy[2] = {v0, v1};
6250 programUniform2iv(program, location, 1, xy);
6251}
6252
6253void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
6254{
6255 GLint xyz[3] = {v0, v1, v2};
6256 programUniform3iv(program, location, 1, xyz);
6257}
6258
6259void Context::programUniform4i(GLuint program,
6260 GLint location,
6261 GLint v0,
6262 GLint v1,
6263 GLint v2,
6264 GLint v3)
6265{
6266 GLint xyzw[4] = {v0, v1, v2, v3};
6267 programUniform4iv(program, location, 1, xyzw);
6268}
6269
6270void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
6271{
6272 programUniform1uiv(program, location, 1, &v0);
6273}
6274
6275void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
6276{
6277 GLuint xy[2] = {v0, v1};
6278 programUniform2uiv(program, location, 1, xy);
6279}
6280
6281void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
6282{
6283 GLuint xyz[3] = {v0, v1, v2};
6284 programUniform3uiv(program, location, 1, xyz);
6285}
6286
6287void Context::programUniform4ui(GLuint program,
6288 GLint location,
6289 GLuint v0,
6290 GLuint v1,
6291 GLuint v2,
6292 GLuint v3)
6293{
6294 GLuint xyzw[4] = {v0, v1, v2, v3};
6295 programUniform4uiv(program, location, 1, xyzw);
6296}
6297
6298void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
6299{
6300 programUniform1fv(program, location, 1, &v0);
6301}
6302
6303void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
6304{
6305 GLfloat xy[2] = {v0, v1};
6306 programUniform2fv(program, location, 1, xy);
6307}
6308
6309void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
6310{
6311 GLfloat xyz[3] = {v0, v1, v2};
6312 programUniform3fv(program, location, 1, xyz);
6313}
6314
6315void Context::programUniform4f(GLuint program,
6316 GLint location,
6317 GLfloat v0,
6318 GLfloat v1,
6319 GLfloat v2,
6320 GLfloat v3)
6321{
6322 GLfloat xyzw[4] = {v0, v1, v2, v3};
6323 programUniform4fv(program, location, 1, xyzw);
6324}
6325
Jamie Madill81c2e252017-09-09 23:32:46 -04006326void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6327{
6328 Program *programObject = getProgram(program);
6329 ASSERT(programObject);
6330 if (programObject->setUniform1iv(location, count, value) ==
6331 Program::SetUniformResult::SamplerChanged)
6332 {
6333 mGLState.setObjectDirty(GL_PROGRAM);
6334 }
6335}
6336
Jiajia Qin5451d532017-11-16 17:16:34 +08006337void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6338{
6339 Program *programObject = getProgram(program);
6340 ASSERT(programObject);
6341 programObject->setUniform2iv(location, count, value);
6342}
6343
6344void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6345{
6346 Program *programObject = getProgram(program);
6347 ASSERT(programObject);
6348 programObject->setUniform3iv(location, count, value);
6349}
6350
6351void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6352{
6353 Program *programObject = getProgram(program);
6354 ASSERT(programObject);
6355 programObject->setUniform4iv(location, count, value);
6356}
6357
6358void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6359{
6360 Program *programObject = getProgram(program);
6361 ASSERT(programObject);
6362 programObject->setUniform1uiv(location, count, value);
6363}
6364
6365void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6366{
6367 Program *programObject = getProgram(program);
6368 ASSERT(programObject);
6369 programObject->setUniform2uiv(location, count, value);
6370}
6371
6372void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6373{
6374 Program *programObject = getProgram(program);
6375 ASSERT(programObject);
6376 programObject->setUniform3uiv(location, count, value);
6377}
6378
6379void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6380{
6381 Program *programObject = getProgram(program);
6382 ASSERT(programObject);
6383 programObject->setUniform4uiv(location, count, value);
6384}
6385
6386void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6387{
6388 Program *programObject = getProgram(program);
6389 ASSERT(programObject);
6390 programObject->setUniform1fv(location, count, value);
6391}
6392
6393void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6394{
6395 Program *programObject = getProgram(program);
6396 ASSERT(programObject);
6397 programObject->setUniform2fv(location, count, value);
6398}
6399
6400void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6401{
6402 Program *programObject = getProgram(program);
6403 ASSERT(programObject);
6404 programObject->setUniform3fv(location, count, value);
6405}
6406
6407void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6408{
6409 Program *programObject = getProgram(program);
6410 ASSERT(programObject);
6411 programObject->setUniform4fv(location, count, value);
6412}
6413
6414void Context::programUniformMatrix2fv(GLuint program,
6415 GLint location,
6416 GLsizei count,
6417 GLboolean transpose,
6418 const GLfloat *value)
6419{
6420 Program *programObject = getProgram(program);
6421 ASSERT(programObject);
6422 programObject->setUniformMatrix2fv(location, count, transpose, value);
6423}
6424
6425void Context::programUniformMatrix3fv(GLuint program,
6426 GLint location,
6427 GLsizei count,
6428 GLboolean transpose,
6429 const GLfloat *value)
6430{
6431 Program *programObject = getProgram(program);
6432 ASSERT(programObject);
6433 programObject->setUniformMatrix3fv(location, count, transpose, value);
6434}
6435
6436void Context::programUniformMatrix4fv(GLuint program,
6437 GLint location,
6438 GLsizei count,
6439 GLboolean transpose,
6440 const GLfloat *value)
6441{
6442 Program *programObject = getProgram(program);
6443 ASSERT(programObject);
6444 programObject->setUniformMatrix4fv(location, count, transpose, value);
6445}
6446
6447void Context::programUniformMatrix2x3fv(GLuint program,
6448 GLint location,
6449 GLsizei count,
6450 GLboolean transpose,
6451 const GLfloat *value)
6452{
6453 Program *programObject = getProgram(program);
6454 ASSERT(programObject);
6455 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
6456}
6457
6458void Context::programUniformMatrix3x2fv(GLuint program,
6459 GLint location,
6460 GLsizei count,
6461 GLboolean transpose,
6462 const GLfloat *value)
6463{
6464 Program *programObject = getProgram(program);
6465 ASSERT(programObject);
6466 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
6467}
6468
6469void Context::programUniformMatrix2x4fv(GLuint program,
6470 GLint location,
6471 GLsizei count,
6472 GLboolean transpose,
6473 const GLfloat *value)
6474{
6475 Program *programObject = getProgram(program);
6476 ASSERT(programObject);
6477 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
6478}
6479
6480void Context::programUniformMatrix4x2fv(GLuint program,
6481 GLint location,
6482 GLsizei count,
6483 GLboolean transpose,
6484 const GLfloat *value)
6485{
6486 Program *programObject = getProgram(program);
6487 ASSERT(programObject);
6488 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
6489}
6490
6491void Context::programUniformMatrix3x4fv(GLuint program,
6492 GLint location,
6493 GLsizei count,
6494 GLboolean transpose,
6495 const GLfloat *value)
6496{
6497 Program *programObject = getProgram(program);
6498 ASSERT(programObject);
6499 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
6500}
6501
6502void Context::programUniformMatrix4x3fv(GLuint program,
6503 GLint location,
6504 GLsizei count,
6505 GLboolean transpose,
6506 const GLfloat *value)
6507{
6508 Program *programObject = getProgram(program);
6509 ASSERT(programObject);
6510 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
6511}
6512
Jamie Madill81c2e252017-09-09 23:32:46 -04006513void Context::onTextureChange(const Texture *texture)
6514{
6515 // Conservatively assume all textures are dirty.
6516 // TODO(jmadill): More fine-grained update.
6517 mGLState.setObjectDirty(GL_TEXTURE);
6518}
6519
James Darpiniane8a93c62018-01-04 18:02:24 -08006520bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
6521{
6522 return mGLState.isCurrentTransformFeedback(tf);
6523}
6524bool Context::isCurrentVertexArray(const VertexArray *va) const
6525{
6526 return mGLState.isCurrentVertexArray(va);
6527}
6528
Yunchao Hea336b902017-08-02 16:05:21 +08006529void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
6530{
6531 for (int i = 0; i < count; i++)
6532 {
6533 pipelines[i] = createProgramPipeline();
6534 }
6535}
6536
6537void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
6538{
6539 for (int i = 0; i < count; i++)
6540 {
6541 if (pipelines[i] != 0)
6542 {
6543 deleteProgramPipeline(pipelines[i]);
6544 }
6545 }
6546}
6547
6548GLboolean Context::isProgramPipeline(GLuint pipeline)
6549{
6550 if (pipeline == 0)
6551 {
6552 return GL_FALSE;
6553 }
6554
6555 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
6556}
6557
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006558void Context::finishFenceNV(GLuint fence)
6559{
6560 FenceNV *fenceObject = getFenceNV(fence);
6561
6562 ASSERT(fenceObject && fenceObject->isSet());
Jamie Madilla0691b72018-07-25 10:41:22 -04006563 handleError(fenceObject->finish(this));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006564}
6565
6566void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
6567{
6568 FenceNV *fenceObject = getFenceNV(fence);
6569
6570 ASSERT(fenceObject && fenceObject->isSet());
6571
6572 switch (pname)
6573 {
6574 case GL_FENCE_STATUS_NV:
6575 {
6576 // GL_NV_fence spec:
6577 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
6578 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
6579 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
6580 GLboolean status = GL_TRUE;
6581 if (fenceObject->getStatus() != GL_TRUE)
6582 {
Jamie Madilla0691b72018-07-25 10:41:22 -04006583 ANGLE_CONTEXT_TRY(fenceObject->test(this, &status));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006584 }
6585 *params = status;
6586 break;
6587 }
6588
6589 case GL_FENCE_CONDITION_NV:
6590 {
6591 *params = static_cast<GLint>(fenceObject->getCondition());
6592 break;
6593 }
6594
6595 default:
6596 UNREACHABLE();
6597 }
6598}
6599
6600void Context::getTranslatedShaderSource(GLuint shader,
6601 GLsizei bufsize,
6602 GLsizei *length,
6603 GLchar *source)
6604{
6605 Shader *shaderObject = getShader(shader);
6606 ASSERT(shaderObject);
6607 shaderObject->getTranslatedSourceWithDebugInfo(this, bufsize, length, source);
6608}
6609
6610void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
6611{
6612 Program *programObject = getProgram(program);
6613 ASSERT(programObject);
6614
6615 programObject->getUniformfv(this, location, params);
6616}
6617
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006618void Context::getnUniformfvRobust(GLuint program,
6619 GLint location,
6620 GLsizei bufSize,
6621 GLsizei *length,
6622 GLfloat *params)
6623{
6624 UNIMPLEMENTED();
6625}
6626
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006627void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
6628{
6629 Program *programObject = getProgram(program);
6630 ASSERT(programObject);
6631
6632 programObject->getUniformiv(this, location, params);
6633}
6634
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006635void Context::getnUniformivRobust(GLuint program,
6636 GLint location,
6637 GLsizei bufSize,
6638 GLsizei *length,
6639 GLint *params)
6640{
6641 UNIMPLEMENTED();
6642}
6643
6644void Context::getnUniformuivRobust(GLuint program,
6645 GLint location,
6646 GLsizei bufSize,
6647 GLsizei *length,
6648 GLuint *params)
6649{
6650 UNIMPLEMENTED();
6651}
6652
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006653GLboolean Context::isFenceNV(GLuint fence)
6654{
6655 FenceNV *fenceObject = getFenceNV(fence);
6656
6657 if (fenceObject == nullptr)
6658 {
6659 return GL_FALSE;
6660 }
6661
6662 // GL_NV_fence spec:
6663 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
6664 // existing fence.
6665 return fenceObject->isSet();
6666}
6667
6668void Context::readnPixels(GLint x,
6669 GLint y,
6670 GLsizei width,
6671 GLsizei height,
6672 GLenum format,
6673 GLenum type,
6674 GLsizei bufSize,
6675 void *data)
6676{
6677 return readPixels(x, y, width, height, format, type, data);
6678}
6679
Jamie Madill007530e2017-12-28 14:27:04 -05006680void Context::setFenceNV(GLuint fence, GLenum condition)
6681{
6682 ASSERT(condition == GL_ALL_COMPLETED_NV);
6683
6684 FenceNV *fenceObject = getFenceNV(fence);
6685 ASSERT(fenceObject != nullptr);
Jamie Madilla0691b72018-07-25 10:41:22 -04006686 handleError(fenceObject->set(this, condition));
Jamie Madill007530e2017-12-28 14:27:04 -05006687}
6688
6689GLboolean Context::testFenceNV(GLuint fence)
6690{
6691 FenceNV *fenceObject = getFenceNV(fence);
6692
6693 ASSERT(fenceObject != nullptr);
6694 ASSERT(fenceObject->isSet() == GL_TRUE);
6695
6696 GLboolean result = GL_TRUE;
Jamie Madilla0691b72018-07-25 10:41:22 -04006697 Error error = fenceObject->test(this, &result);
Jamie Madill007530e2017-12-28 14:27:04 -05006698 if (error.isError())
6699 {
6700 handleError(error);
6701 return GL_TRUE;
6702 }
6703
6704 return result;
6705}
6706
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006707void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006708{
6709 Texture *texture = getTargetTexture(target);
Rafael Cintron05a449a2018-06-20 18:08:04 -07006710 egl::Image *imageObject = static_cast<egl::Image *>(image);
Corentin Wallez99d492c2018-02-27 15:17:10 -05006711 handleError(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05006712}
6713
Jamie Madillfa920eb2018-01-04 11:45:50 -05006714void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006715{
6716 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Rafael Cintron05a449a2018-06-20 18:08:04 -07006717 egl::Image *imageObject = static_cast<egl::Image *>(image);
Jamie Madill007530e2017-12-28 14:27:04 -05006718 handleError(renderbuffer->setStorageEGLImageTarget(this, imageObject));
6719}
6720
Jamie Madillfa920eb2018-01-04 11:45:50 -05006721void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
6722{
6723 UNIMPLEMENTED();
6724}
6725
Jamie Madill5b772312018-03-08 20:28:32 -05006726bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
6727{
6728 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
6729 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
6730 // to the fact that it is stored internally as a float, and so would require conversion
6731 // if returned from Context::getIntegerv. Since this conversion is already implemented
6732 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
6733 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
6734 // application.
6735 switch (pname)
6736 {
6737 case GL_COMPRESSED_TEXTURE_FORMATS:
6738 {
6739 *type = GL_INT;
6740 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
6741 return true;
6742 }
6743 case GL_SHADER_BINARY_FORMATS:
6744 {
6745 *type = GL_INT;
6746 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
6747 return true;
6748 }
6749
6750 case GL_MAX_VERTEX_ATTRIBS:
6751 case GL_MAX_VERTEX_UNIFORM_VECTORS:
6752 case GL_MAX_VARYING_VECTORS:
6753 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
6754 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
6755 case GL_MAX_TEXTURE_IMAGE_UNITS:
6756 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
6757 case GL_MAX_RENDERBUFFER_SIZE:
6758 case GL_NUM_SHADER_BINARY_FORMATS:
6759 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
6760 case GL_ARRAY_BUFFER_BINDING:
6761 case GL_FRAMEBUFFER_BINDING:
6762 case GL_RENDERBUFFER_BINDING:
6763 case GL_CURRENT_PROGRAM:
6764 case GL_PACK_ALIGNMENT:
6765 case GL_UNPACK_ALIGNMENT:
6766 case GL_GENERATE_MIPMAP_HINT:
6767 case GL_RED_BITS:
6768 case GL_GREEN_BITS:
6769 case GL_BLUE_BITS:
6770 case GL_ALPHA_BITS:
6771 case GL_DEPTH_BITS:
6772 case GL_STENCIL_BITS:
6773 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
6774 case GL_CULL_FACE_MODE:
6775 case GL_FRONT_FACE:
6776 case GL_ACTIVE_TEXTURE:
6777 case GL_STENCIL_FUNC:
6778 case GL_STENCIL_VALUE_MASK:
6779 case GL_STENCIL_REF:
6780 case GL_STENCIL_FAIL:
6781 case GL_STENCIL_PASS_DEPTH_FAIL:
6782 case GL_STENCIL_PASS_DEPTH_PASS:
6783 case GL_STENCIL_BACK_FUNC:
6784 case GL_STENCIL_BACK_VALUE_MASK:
6785 case GL_STENCIL_BACK_REF:
6786 case GL_STENCIL_BACK_FAIL:
6787 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
6788 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
6789 case GL_DEPTH_FUNC:
6790 case GL_BLEND_SRC_RGB:
6791 case GL_BLEND_SRC_ALPHA:
6792 case GL_BLEND_DST_RGB:
6793 case GL_BLEND_DST_ALPHA:
6794 case GL_BLEND_EQUATION_RGB:
6795 case GL_BLEND_EQUATION_ALPHA:
6796 case GL_STENCIL_WRITEMASK:
6797 case GL_STENCIL_BACK_WRITEMASK:
6798 case GL_STENCIL_CLEAR_VALUE:
6799 case GL_SUBPIXEL_BITS:
6800 case GL_MAX_TEXTURE_SIZE:
6801 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
6802 case GL_SAMPLE_BUFFERS:
6803 case GL_SAMPLES:
6804 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
6805 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
6806 case GL_TEXTURE_BINDING_2D:
6807 case GL_TEXTURE_BINDING_CUBE_MAP:
6808 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
6809 {
6810 *type = GL_INT;
6811 *numParams = 1;
6812 return true;
6813 }
6814 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6815 {
6816 if (!getExtensions().packReverseRowOrder)
6817 {
6818 return false;
6819 }
6820 *type = GL_INT;
6821 *numParams = 1;
6822 return true;
6823 }
6824 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
6825 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
6826 {
6827 if (!getExtensions().textureRectangle)
6828 {
6829 return false;
6830 }
6831 *type = GL_INT;
6832 *numParams = 1;
6833 return true;
6834 }
6835 case GL_MAX_DRAW_BUFFERS_EXT:
6836 case GL_MAX_COLOR_ATTACHMENTS_EXT:
6837 {
6838 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
6839 {
6840 return false;
6841 }
6842 *type = GL_INT;
6843 *numParams = 1;
6844 return true;
6845 }
6846 case GL_MAX_VIEWPORT_DIMS:
6847 {
6848 *type = GL_INT;
6849 *numParams = 2;
6850 return true;
6851 }
6852 case GL_VIEWPORT:
6853 case GL_SCISSOR_BOX:
6854 {
6855 *type = GL_INT;
6856 *numParams = 4;
6857 return true;
6858 }
6859 case GL_SHADER_COMPILER:
6860 case GL_SAMPLE_COVERAGE_INVERT:
6861 case GL_DEPTH_WRITEMASK:
6862 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
6863 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
6864 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
6865 // bool-natural
6866 case GL_SAMPLE_COVERAGE:
6867 case GL_SCISSOR_TEST:
6868 case GL_STENCIL_TEST:
6869 case GL_DEPTH_TEST:
6870 case GL_BLEND:
6871 case GL_DITHER:
6872 case GL_CONTEXT_ROBUST_ACCESS_EXT:
6873 {
6874 *type = GL_BOOL;
6875 *numParams = 1;
6876 return true;
6877 }
6878 case GL_COLOR_WRITEMASK:
6879 {
6880 *type = GL_BOOL;
6881 *numParams = 4;
6882 return true;
6883 }
6884 case GL_POLYGON_OFFSET_FACTOR:
6885 case GL_POLYGON_OFFSET_UNITS:
6886 case GL_SAMPLE_COVERAGE_VALUE:
6887 case GL_DEPTH_CLEAR_VALUE:
6888 case GL_LINE_WIDTH:
6889 {
6890 *type = GL_FLOAT;
6891 *numParams = 1;
6892 return true;
6893 }
6894 case GL_ALIASED_LINE_WIDTH_RANGE:
6895 case GL_ALIASED_POINT_SIZE_RANGE:
6896 case GL_DEPTH_RANGE:
6897 {
6898 *type = GL_FLOAT;
6899 *numParams = 2;
6900 return true;
6901 }
6902 case GL_COLOR_CLEAR_VALUE:
6903 case GL_BLEND_COLOR:
6904 {
6905 *type = GL_FLOAT;
6906 *numParams = 4;
6907 return true;
6908 }
6909 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
6910 if (!getExtensions().textureFilterAnisotropic)
6911 {
6912 return false;
6913 }
6914 *type = GL_FLOAT;
6915 *numParams = 1;
6916 return true;
6917 case GL_TIMESTAMP_EXT:
6918 if (!getExtensions().disjointTimerQuery)
6919 {
6920 return false;
6921 }
6922 *type = GL_INT_64_ANGLEX;
6923 *numParams = 1;
6924 return true;
6925 case GL_GPU_DISJOINT_EXT:
6926 if (!getExtensions().disjointTimerQuery)
6927 {
6928 return false;
6929 }
6930 *type = GL_INT;
6931 *numParams = 1;
6932 return true;
6933 case GL_COVERAGE_MODULATION_CHROMIUM:
6934 if (!getExtensions().framebufferMixedSamples)
6935 {
6936 return false;
6937 }
6938 *type = GL_INT;
6939 *numParams = 1;
6940 return true;
6941 case GL_TEXTURE_BINDING_EXTERNAL_OES:
6942 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
6943 {
6944 return false;
6945 }
6946 *type = GL_INT;
6947 *numParams = 1;
6948 return true;
6949 }
6950
6951 if (getExtensions().debug)
6952 {
6953 switch (pname)
6954 {
6955 case GL_DEBUG_LOGGED_MESSAGES:
6956 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
6957 case GL_DEBUG_GROUP_STACK_DEPTH:
6958 case GL_MAX_DEBUG_MESSAGE_LENGTH:
6959 case GL_MAX_DEBUG_LOGGED_MESSAGES:
6960 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
6961 case GL_MAX_LABEL_LENGTH:
6962 *type = GL_INT;
6963 *numParams = 1;
6964 return true;
6965
6966 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
6967 case GL_DEBUG_OUTPUT:
6968 *type = GL_BOOL;
6969 *numParams = 1;
6970 return true;
6971 }
6972 }
6973
6974 if (getExtensions().multisampleCompatibility)
6975 {
6976 switch (pname)
6977 {
6978 case GL_MULTISAMPLE_EXT:
6979 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
6980 *type = GL_BOOL;
6981 *numParams = 1;
6982 return true;
6983 }
6984 }
6985
6986 if (getExtensions().pathRendering)
6987 {
6988 switch (pname)
6989 {
6990 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
6991 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
6992 *type = GL_FLOAT;
6993 *numParams = 16;
6994 return true;
6995 }
6996 }
6997
6998 if (getExtensions().bindGeneratesResource)
6999 {
7000 switch (pname)
7001 {
7002 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
7003 *type = GL_BOOL;
7004 *numParams = 1;
7005 return true;
7006 }
7007 }
7008
7009 if (getExtensions().clientArrays)
7010 {
7011 switch (pname)
7012 {
7013 case GL_CLIENT_ARRAYS_ANGLE:
7014 *type = GL_BOOL;
7015 *numParams = 1;
7016 return true;
7017 }
7018 }
7019
7020 if (getExtensions().sRGBWriteControl)
7021 {
7022 switch (pname)
7023 {
7024 case GL_FRAMEBUFFER_SRGB_EXT:
7025 *type = GL_BOOL;
7026 *numParams = 1;
7027 return true;
7028 }
7029 }
7030
7031 if (getExtensions().robustResourceInitialization &&
7032 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
7033 {
7034 *type = GL_BOOL;
7035 *numParams = 1;
7036 return true;
7037 }
7038
7039 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
7040 {
7041 *type = GL_BOOL;
7042 *numParams = 1;
7043 return true;
7044 }
7045
jchen1082af6202018-06-22 10:59:52 +08007046 if (getExtensions().parallelShaderCompile && pname == GL_MAX_SHADER_COMPILER_THREADS_KHR)
7047 {
7048 *type = GL_INT;
7049 *numParams = 1;
7050 return true;
7051 }
7052
Jamie Madill5b772312018-03-08 20:28:32 -05007053 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
7054 switch (pname)
7055 {
7056 // case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE // equivalent to FRAMEBUFFER_BINDING
7057 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
7058 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
7059 {
7060 return false;
7061 }
7062 *type = GL_INT;
7063 *numParams = 1;
7064 return true;
7065
7066 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
7067 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7068 {
7069 return false;
7070 }
7071 *type = GL_INT;
7072 *numParams = 1;
7073 return true;
7074
7075 case GL_PROGRAM_BINARY_FORMATS_OES:
7076 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7077 {
7078 return false;
7079 }
7080 *type = GL_INT;
7081 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
7082 return true;
7083
7084 case GL_PACK_ROW_LENGTH:
7085 case GL_PACK_SKIP_ROWS:
7086 case GL_PACK_SKIP_PIXELS:
7087 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
7088 {
7089 return false;
7090 }
7091 *type = GL_INT;
7092 *numParams = 1;
7093 return true;
7094 case GL_UNPACK_ROW_LENGTH:
7095 case GL_UNPACK_SKIP_ROWS:
7096 case GL_UNPACK_SKIP_PIXELS:
7097 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
7098 {
7099 return false;
7100 }
7101 *type = GL_INT;
7102 *numParams = 1;
7103 return true;
7104 case GL_VERTEX_ARRAY_BINDING:
7105 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
7106 {
7107 return false;
7108 }
7109 *type = GL_INT;
7110 *numParams = 1;
7111 return true;
7112 case GL_PIXEL_PACK_BUFFER_BINDING:
7113 case GL_PIXEL_UNPACK_BUFFER_BINDING:
7114 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
7115 {
7116 return false;
7117 }
7118 *type = GL_INT;
7119 *numParams = 1;
7120 return true;
7121 case GL_MAX_SAMPLES:
7122 {
7123 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
7124 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
7125 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
7126 {
7127 return false;
7128 }
7129 *type = GL_INT;
7130 *numParams = 1;
7131 return true;
7132
7133 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
7134 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
7135 {
7136 return false;
7137 }
7138 *type = GL_INT;
7139 *numParams = 1;
7140 return true;
7141 }
7142 }
7143
7144 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
7145 {
7146 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
7147 {
7148 return false;
7149 }
7150 *type = GL_INT;
7151 *numParams = 1;
7152 return true;
7153 }
7154
7155 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
7156 {
7157 *type = GL_INT;
7158 *numParams = 1;
7159 return true;
7160 }
7161
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007162 if (getClientVersion() < Version(2, 0))
7163 {
7164 switch (pname)
7165 {
7166 case GL_ALPHA_TEST_FUNC:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007167 case GL_CLIENT_ACTIVE_TEXTURE:
7168 case GL_MATRIX_MODE:
7169 case GL_MAX_TEXTURE_UNITS:
7170 case GL_MAX_MODELVIEW_STACK_DEPTH:
7171 case GL_MAX_PROJECTION_STACK_DEPTH:
7172 case GL_MAX_TEXTURE_STACK_DEPTH:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007173 case GL_MAX_LIGHTS:
Lingfeng Yang060088a2018-05-30 20:40:57 -07007174 case GL_MAX_CLIP_PLANES:
Lingfeng Yangabb09f12018-04-16 10:43:53 -07007175 case GL_VERTEX_ARRAY_STRIDE:
7176 case GL_NORMAL_ARRAY_STRIDE:
7177 case GL_COLOR_ARRAY_STRIDE:
7178 case GL_TEXTURE_COORD_ARRAY_STRIDE:
7179 case GL_VERTEX_ARRAY_SIZE:
7180 case GL_COLOR_ARRAY_SIZE:
7181 case GL_TEXTURE_COORD_ARRAY_SIZE:
7182 case GL_VERTEX_ARRAY_TYPE:
7183 case GL_NORMAL_ARRAY_TYPE:
7184 case GL_COLOR_ARRAY_TYPE:
7185 case GL_TEXTURE_COORD_ARRAY_TYPE:
7186 case GL_VERTEX_ARRAY_BUFFER_BINDING:
7187 case GL_NORMAL_ARRAY_BUFFER_BINDING:
7188 case GL_COLOR_ARRAY_BUFFER_BINDING:
7189 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
7190 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
7191 case GL_POINT_SIZE_ARRAY_TYPE_OES:
7192 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
Lingfeng Yanga0cfa872018-05-30 21:12:17 -07007193 case GL_SHADE_MODEL:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007194 *type = GL_INT;
7195 *numParams = 1;
7196 return true;
7197 case GL_ALPHA_TEST_REF:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007198 case GL_FOG_DENSITY:
7199 case GL_FOG_START:
7200 case GL_FOG_END:
7201 case GL_FOG_MODE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007202 case GL_POINT_SIZE:
7203 case GL_POINT_SIZE_MIN:
7204 case GL_POINT_SIZE_MAX:
7205 case GL_POINT_FADE_THRESHOLD_SIZE:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007206 *type = GL_FLOAT;
7207 *numParams = 1;
7208 return true;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007209 case GL_SMOOTH_POINT_SIZE_RANGE:
7210 *type = GL_FLOAT;
7211 *numParams = 2;
7212 return true;
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007213 case GL_CURRENT_COLOR:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007214 case GL_CURRENT_TEXTURE_COORDS:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007215 case GL_LIGHT_MODEL_AMBIENT:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007216 case GL_FOG_COLOR:
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007217 *type = GL_FLOAT;
7218 *numParams = 4;
7219 return true;
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007220 case GL_CURRENT_NORMAL:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007221 case GL_POINT_DISTANCE_ATTENUATION:
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007222 *type = GL_FLOAT;
7223 *numParams = 3;
7224 return true;
Lingfeng Yang3a41af62018-04-09 07:28:56 -07007225 case GL_MODELVIEW_MATRIX:
7226 case GL_PROJECTION_MATRIX:
7227 case GL_TEXTURE_MATRIX:
7228 *type = GL_FLOAT;
7229 *numParams = 16;
7230 return true;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007231 case GL_LIGHT_MODEL_TWO_SIDE:
7232 *type = GL_BOOL;
7233 *numParams = 1;
7234 return true;
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007235 }
7236 }
7237
Jamie Madill5b772312018-03-08 20:28:32 -05007238 if (getClientVersion() < Version(3, 0))
7239 {
7240 return false;
7241 }
7242
7243 // Check for ES3.0+ parameter names
7244 switch (pname)
7245 {
7246 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
7247 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
7248 case GL_UNIFORM_BUFFER_BINDING:
7249 case GL_TRANSFORM_FEEDBACK_BINDING:
7250 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7251 case GL_COPY_READ_BUFFER_BINDING:
7252 case GL_COPY_WRITE_BUFFER_BINDING:
7253 case GL_SAMPLER_BINDING:
7254 case GL_READ_BUFFER:
7255 case GL_TEXTURE_BINDING_3D:
7256 case GL_TEXTURE_BINDING_2D_ARRAY:
7257 case GL_MAX_3D_TEXTURE_SIZE:
7258 case GL_MAX_ARRAY_TEXTURE_LAYERS:
7259 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
7260 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
7261 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
7262 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
7263 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
7264 case GL_MAX_VARYING_COMPONENTS:
7265 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
7266 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
7267 case GL_MIN_PROGRAM_TEXEL_OFFSET:
7268 case GL_MAX_PROGRAM_TEXEL_OFFSET:
7269 case GL_NUM_EXTENSIONS:
7270 case GL_MAJOR_VERSION:
7271 case GL_MINOR_VERSION:
7272 case GL_MAX_ELEMENTS_INDICES:
7273 case GL_MAX_ELEMENTS_VERTICES:
7274 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
7275 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
7276 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
7277 case GL_UNPACK_IMAGE_HEIGHT:
7278 case GL_UNPACK_SKIP_IMAGES:
7279 {
7280 *type = GL_INT;
7281 *numParams = 1;
7282 return true;
7283 }
7284
7285 case GL_MAX_ELEMENT_INDEX:
7286 case GL_MAX_UNIFORM_BLOCK_SIZE:
7287 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
7288 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
7289 case GL_MAX_SERVER_WAIT_TIMEOUT:
7290 {
7291 *type = GL_INT_64_ANGLEX;
7292 *numParams = 1;
7293 return true;
7294 }
7295
7296 case GL_TRANSFORM_FEEDBACK_ACTIVE:
7297 case GL_TRANSFORM_FEEDBACK_PAUSED:
7298 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
7299 case GL_RASTERIZER_DISCARD:
7300 {
7301 *type = GL_BOOL;
7302 *numParams = 1;
7303 return true;
7304 }
7305
7306 case GL_MAX_TEXTURE_LOD_BIAS:
7307 {
7308 *type = GL_FLOAT;
7309 *numParams = 1;
7310 return true;
7311 }
7312 }
7313
7314 if (getExtensions().requestExtension)
7315 {
7316 switch (pname)
7317 {
7318 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
7319 *type = GL_INT;
7320 *numParams = 1;
7321 return true;
7322 }
7323 }
7324
7325 if (getClientVersion() < Version(3, 1))
7326 {
7327 return false;
7328 }
7329
7330 switch (pname)
7331 {
7332 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7333 case GL_DRAW_INDIRECT_BUFFER_BINDING:
7334 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
7335 case GL_MAX_FRAMEBUFFER_WIDTH:
7336 case GL_MAX_FRAMEBUFFER_HEIGHT:
7337 case GL_MAX_FRAMEBUFFER_SAMPLES:
7338 case GL_MAX_SAMPLE_MASK_WORDS:
7339 case GL_MAX_COLOR_TEXTURE_SAMPLES:
7340 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
7341 case GL_MAX_INTEGER_SAMPLES:
7342 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
7343 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
7344 case GL_MAX_VERTEX_ATTRIB_STRIDE:
7345 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
7346 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
7347 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
7348 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
7349 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
7350 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
7351 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
7352 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
7353 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
7354 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
7355 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
7356 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
7357 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
7358 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
7359 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
7360 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
7361 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
7362 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
7363 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
7364 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
7365 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
7366 case GL_MAX_UNIFORM_LOCATIONS:
7367 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
7368 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
7369 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
7370 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
7371 case GL_MAX_IMAGE_UNITS:
7372 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
7373 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
7374 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
7375 case GL_SHADER_STORAGE_BUFFER_BINDING:
7376 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
7377 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
7378 *type = GL_INT;
7379 *numParams = 1;
7380 return true;
7381 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7382 *type = GL_INT_64_ANGLEX;
7383 *numParams = 1;
7384 return true;
7385 case GL_SAMPLE_MASK:
7386 *type = GL_BOOL;
7387 *numParams = 1;
7388 return true;
7389 }
7390
7391 if (getExtensions().geometryShader)
7392 {
7393 switch (pname)
7394 {
7395 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7396 case GL_LAYER_PROVOKING_VERTEX_EXT:
7397 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7398 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7399 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7400 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7401 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7402 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7403 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7404 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7405 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7406 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7407 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7408 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7409 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7410 *type = GL_INT;
7411 *numParams = 1;
7412 return true;
7413 }
7414 }
7415
7416 return false;
7417}
7418
7419bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7420{
7421 if (getClientVersion() < Version(3, 0))
7422 {
7423 return false;
7424 }
7425
7426 switch (target)
7427 {
7428 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7429 case GL_UNIFORM_BUFFER_BINDING:
7430 {
7431 *type = GL_INT;
7432 *numParams = 1;
7433 return true;
7434 }
7435 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7436 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7437 case GL_UNIFORM_BUFFER_START:
7438 case GL_UNIFORM_BUFFER_SIZE:
7439 {
7440 *type = GL_INT_64_ANGLEX;
7441 *numParams = 1;
7442 return true;
7443 }
7444 }
7445
7446 if (getClientVersion() < Version(3, 1))
7447 {
7448 return false;
7449 }
7450
7451 switch (target)
7452 {
7453 case GL_IMAGE_BINDING_LAYERED:
7454 {
7455 *type = GL_BOOL;
7456 *numParams = 1;
7457 return true;
7458 }
7459 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7460 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7461 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7462 case GL_SHADER_STORAGE_BUFFER_BINDING:
7463 case GL_VERTEX_BINDING_BUFFER:
7464 case GL_VERTEX_BINDING_DIVISOR:
7465 case GL_VERTEX_BINDING_OFFSET:
7466 case GL_VERTEX_BINDING_STRIDE:
7467 case GL_SAMPLE_MASK_VALUE:
7468 case GL_IMAGE_BINDING_NAME:
7469 case GL_IMAGE_BINDING_LEVEL:
7470 case GL_IMAGE_BINDING_LAYER:
7471 case GL_IMAGE_BINDING_ACCESS:
7472 case GL_IMAGE_BINDING_FORMAT:
7473 {
7474 *type = GL_INT;
7475 *numParams = 1;
7476 return true;
7477 }
7478 case GL_ATOMIC_COUNTER_BUFFER_START:
7479 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
7480 case GL_SHADER_STORAGE_BUFFER_START:
7481 case GL_SHADER_STORAGE_BUFFER_SIZE:
7482 {
7483 *type = GL_INT_64_ANGLEX;
7484 *numParams = 1;
7485 return true;
7486 }
7487 }
7488
7489 return false;
7490}
7491
7492Program *Context::getProgram(GLuint handle) const
7493{
7494 return mState.mShaderPrograms->getProgram(handle);
7495}
7496
7497Shader *Context::getShader(GLuint handle) const
7498{
7499 return mState.mShaderPrograms->getShader(handle);
7500}
7501
7502bool Context::isTextureGenerated(GLuint texture) const
7503{
7504 return mState.mTextures->isHandleGenerated(texture);
7505}
7506
7507bool Context::isBufferGenerated(GLuint buffer) const
7508{
7509 return mState.mBuffers->isHandleGenerated(buffer);
7510}
7511
7512bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
7513{
7514 return mState.mRenderbuffers->isHandleGenerated(renderbuffer);
7515}
7516
7517bool Context::isFramebufferGenerated(GLuint framebuffer) const
7518{
7519 return mState.mFramebuffers->isHandleGenerated(framebuffer);
7520}
7521
7522bool Context::isProgramPipelineGenerated(GLuint pipeline) const
7523{
7524 return mState.mPipelines->isHandleGenerated(pipeline);
7525}
7526
7527bool Context::usingDisplayTextureShareGroup() const
7528{
7529 return mDisplayTextureShareGroup;
7530}
7531
7532GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
7533{
7534 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
7535 internalformat == GL_DEPTH_STENCIL
7536 ? GL_DEPTH24_STENCIL8
7537 : internalformat;
7538}
7539
jchen1082af6202018-06-22 10:59:52 +08007540void Context::maxShaderCompilerThreads(GLuint count)
7541{
7542 mGLState.setMaxShaderCompilerThreads(count);
7543}
7544
Jamie Madill2eb65032018-07-30 10:25:57 -04007545bool Context::isGLES1() const
7546{
7547 return mState.getClientVersion() < Version(2, 0);
7548}
7549
Jamie Madill6b873dd2018-07-12 23:56:30 -04007550// ErrorSet implementation.
7551ErrorSet::ErrorSet(Context *context) : mContext(context)
7552{
7553}
7554
7555ErrorSet::~ErrorSet() = default;
7556
Jamie Madill306b6c12018-07-27 08:12:49 -04007557void ErrorSet::handleError(const Error &error) const
Jamie Madill6b873dd2018-07-12 23:56:30 -04007558{
7559 // This internal enum is used to filter internal errors that are already handled.
7560 // TODO(jmadill): Remove this when refactor is done. http://anglebug.com/2491
7561 if (error.getCode() == GL_INTERNAL_ERROR_ANGLEX)
7562 {
7563 return;
7564 }
7565
7566 if (ANGLE_UNLIKELY(error.isError()))
7567 {
7568 GLenum code = error.getCode();
7569 mErrors.insert(code);
7570 if (code == GL_OUT_OF_MEMORY && mContext->getWorkarounds().loseContextOnOutOfMemory)
7571 {
7572 mContext->markContextLost();
7573 }
7574
7575 ASSERT(!error.getMessage().empty());
7576 mContext->getGLState().getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR,
7577 error.getID(), GL_DEBUG_SEVERITY_HIGH,
7578 error.getMessage());
7579 }
7580}
7581
7582bool ErrorSet::empty() const
7583{
7584 return mErrors.empty();
7585}
7586
7587GLenum ErrorSet::popError()
7588{
7589 ASSERT(!empty());
7590 GLenum error = *mErrors.begin();
7591 mErrors.erase(mErrors.begin());
7592 return error;
7593}
Jamie Madilldc358af2018-07-31 11:22:13 -04007594
7595// StateCache implementation.
7596StateCache::StateCache() : mCachedHasAnyEnabledClientAttrib(false)
7597{
7598}
7599
7600StateCache::~StateCache() = default;
7601
7602void StateCache::updateActiveAttribsMask(Context *context)
7603{
7604 bool isGLES1 = context->isGLES1();
7605 const State &glState = context->getGLState();
7606
7607 if (!isGLES1 && !glState.getProgram())
7608 {
7609 mCachedActiveBufferedAttribsMask = AttributesMask();
7610 mCachedActiveClientAttribsMask = AttributesMask();
7611 return;
7612 }
7613
7614 AttributesMask activeAttribs = isGLES1 ? glState.gles1().getVertexArraysAttributeMask()
7615 : glState.getProgram()->getActiveAttribLocationsMask();
7616
7617 const VertexArray *vao = glState.getVertexArray();
7618 ASSERT(vao);
7619
7620 const AttributesMask &clientAttribs = vao->getClientAttribsMask();
7621 const AttributesMask &enabledAttribs = vao->getEnabledAttributesMask();
7622
7623 activeAttribs &= enabledAttribs;
7624
7625 mCachedActiveClientAttribsMask = activeAttribs & clientAttribs;
7626 mCachedActiveBufferedAttribsMask = activeAttribs & ~clientAttribs;
7627 mCachedHasAnyEnabledClientAttrib = (clientAttribs & enabledAttribs).any();
7628}
Jamie Madillc29968b2016-01-20 11:17:23 -05007629} // namespace gl