blob: 19d3100a8c0f8e6828d83d5b8a880080c5759551 [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
Jamie Madillc67323a2017-11-02 23:11:41 -0400452 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500453 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500454 // No dirty objects.
455
456 // Readpixels uses the pack state and read FBO
Jamie Madillc67323a2017-11-02 23:11:41 -0400457 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500458 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_BUFFER_BINDING);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400459 mReadPixelsDirtyBits.set(State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500460 mReadPixelsDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
461
462 mClearDirtyBits.set(State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED);
463 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
464 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR);
465 mClearDirtyBits.set(State::DIRTY_BIT_VIEWPORT);
466 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_COLOR);
467 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_DEPTH);
468 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_STENCIL);
469 mClearDirtyBits.set(State::DIRTY_BIT_COLOR_MASK);
470 mClearDirtyBits.set(State::DIRTY_BIT_DEPTH_MASK);
471 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT);
472 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_BACK);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400473 mClearDirtyBits.set(State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500474 mClearDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
475
476 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
477 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR);
Geoff Lang1d2c41d2016-10-19 16:14:46 -0700478 mBlitDirtyBits.set(State::DIRTY_BIT_FRAMEBUFFER_SRGB);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400479 mBlitDirtyBits.set(State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
480 mBlitDirtyBits.set(State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500481 mBlitDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
482 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
Jamie Madill437fa652016-05-03 15:13:24 -0400483
Xinghua Cao10a4d432017-11-28 14:46:26 +0800484 // TODO(xinghua.cao@intel.com): add other dirty bits and dirty objects.
485 mComputeDirtyBits.set(State::DIRTY_BIT_SHADER_STORAGE_BUFFER_BINDING);
486 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_BINDING);
487 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_EXECUTABLE);
488 mComputeDirtyBits.set(State::DIRTY_BIT_TEXTURE_BINDINGS);
489 mComputeDirtyBits.set(State::DIRTY_BIT_SAMPLER_BINDINGS);
Qin Jiajia62fcf622017-11-30 16:16:12 +0800490 mComputeDirtyBits.set(State::DIRTY_BIT_DISPATCH_INDIRECT_BUFFER_BINDING);
Jiajia Qin5ae6ee42018-03-06 17:39:42 +0800491 mComputeDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM_TEXTURES);
Xinghua Cao10a4d432017-11-28 14:46:26 +0800492
Jamie Madillb4927eb2018-07-16 11:39:46 -0400493 mImplementation->setErrorSet(&mErrors);
494
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400495 handleError(mImplementation->initialize());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000496}
497
Jamie Madill4928b7c2017-06-20 12:57:39 -0400498egl::Error Context::onDestroy(const egl::Display *display)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000499{
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700500 if (mGLES1Renderer)
501 {
502 mGLES1Renderer->onDestroy(this, &mGLState);
503 }
504
Jamie Madille7b3fe22018-04-05 09:42:46 -0400505 // Delete the Surface first to trigger a finish() in Vulkan.
Jamie Madille7b3fe22018-04-05 09:42:46 -0400506 ANGLE_TRY(releaseSurface(display));
507
Corentin Wallez80b24112015-08-25 16:41:57 -0400508 for (auto fence : mFenceNVMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000509 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400510 SafeDelete(fence.second);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000511 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400512 mFenceNVMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000513
Corentin Wallez80b24112015-08-25 16:41:57 -0400514 for (auto query : mQueryMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000515 {
Geoff Langf0aa8422015-09-29 15:08:34 -0400516 if (query.second != nullptr)
517 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400518 query.second->release(this);
Geoff Langf0aa8422015-09-29 15:08:34 -0400519 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000520 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400521 mQueryMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000522
Corentin Wallez80b24112015-08-25 16:41:57 -0400523 for (auto vertexArray : mVertexArrayMap)
Jamie Madill57a89722013-07-02 11:57:03 -0400524 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400525 if (vertexArray.second)
526 {
527 vertexArray.second->onDestroy(this);
528 }
Jamie Madill57a89722013-07-02 11:57:03 -0400529 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400530 mVertexArrayMap.clear();
Jamie Madill57a89722013-07-02 11:57:03 -0400531
Corentin Wallez80b24112015-08-25 16:41:57 -0400532 for (auto transformFeedback : mTransformFeedbackMap)
Geoff Langc8058452014-02-03 12:04:11 -0500533 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500534 if (transformFeedback.second != nullptr)
535 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500536 transformFeedback.second->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500537 }
Geoff Langc8058452014-02-03 12:04:11 -0500538 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400539 mTransformFeedbackMap.clear();
Geoff Langc8058452014-02-03 12:04:11 -0500540
Jamie Madill5b772312018-03-08 20:28:32 -0500541 for (BindingPointer<Texture> &zeroTexture : mZeroTextures)
Geoff Lang76b10c92014-09-05 16:28:14 -0400542 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800543 if (zeroTexture.get() != nullptr)
544 {
545 ANGLE_TRY(zeroTexture->onDestroy(this));
546 zeroTexture.set(this, nullptr);
547 }
Geoff Lang76b10c92014-09-05 16:28:14 -0400548 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000549
Jamie Madill2f348d22017-06-05 10:50:59 -0400550 releaseShaderCompiler();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500551
Jamie Madill4928b7c2017-06-20 12:57:39 -0400552 mGLState.reset(this);
553
Jamie Madill6c1f6712017-02-14 19:08:04 -0500554 mState.mBuffers->release(this);
555 mState.mShaderPrograms->release(this);
556 mState.mTextures->release(this);
557 mState.mRenderbuffers->release(this);
558 mState.mSamplers->release(this);
Jamie Madill70b5bb02017-08-28 13:32:37 -0400559 mState.mSyncs->release(this);
Jamie Madill6c1f6712017-02-14 19:08:04 -0500560 mState.mPaths->release(this);
561 mState.mFramebuffers->release(this);
Yunchao Hea336b902017-08-02 16:05:21 +0800562 mState.mPipelines->release(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400563
Jamie Madill76e471e2017-10-21 09:56:01 -0400564 mImplementation->onDestroy(this);
565
Jamie Madill4928b7c2017-06-20 12:57:39 -0400566 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000567}
568
Jamie Madill70ee0f62017-02-06 16:04:20 -0500569Context::~Context()
570{
571}
572
Geoff Lang75359662018-04-11 01:42:27 -0400573void Context::setLabel(EGLLabelKHR label)
574{
575 mLabel = label;
576}
577
578EGLLabelKHR Context::getLabel() const
579{
580 return mLabel;
581}
582
Jamie Madill4928b7c2017-06-20 12:57:39 -0400583egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000584{
Jamie Madill61e16b42017-06-19 11:13:23 -0400585 mCurrentDisplay = display;
586
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000587 if (!mHasBeenCurrent)
588 {
Geoff Lang33f11fb2018-05-07 13:42:47 -0400589 initialize();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000590 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500591 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400592 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000593
Corentin Wallezc295e512017-01-27 17:47:50 -0500594 int width = 0;
595 int height = 0;
596 if (surface != nullptr)
597 {
598 width = surface->getWidth();
599 height = surface->getHeight();
600 }
601
602 mGLState.setViewportParams(0, 0, width, height);
603 mGLState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000604
605 mHasBeenCurrent = true;
606 }
607
Jamie Madill1b94d432015-08-07 13:23:23 -0400608 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700609 mGLState.setAllDirtyBits();
Jamie Madill81c2e252017-09-09 23:32:46 -0400610 mGLState.setAllDirtyObjects();
Jamie Madill1b94d432015-08-07 13:23:23 -0400611
Jamie Madill4928b7c2017-06-20 12:57:39 -0400612 ANGLE_TRY(releaseSurface(display));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500613
614 Framebuffer *newDefault = nullptr;
615 if (surface != nullptr)
616 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400617 ANGLE_TRY(surface->setIsCurrent(this, true));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500618 mCurrentSurface = surface;
Geoff Langbf7b95d2018-05-01 16:48:21 -0400619 newDefault = surface->createDefaultFramebuffer(this);
Corentin Wallezccab69d2017-01-27 16:57:15 -0500620 }
621 else
622 {
Geoff Langbf7b95d2018-05-01 16:48:21 -0400623 newDefault = new Framebuffer(mImplementation.get());
Corentin Wallezccab69d2017-01-27 16:57:15 -0500624 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000625
Corentin Wallez37c39792015-08-20 14:19:46 -0400626 // Update default framebuffer, the binding of the previous default
627 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400628 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700629 if (mGLState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400630 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700631 mGLState.setReadFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400632 }
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700633 if (mGLState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400634 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700635 mGLState.setDrawFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400636 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500637 mState.mFramebuffers->setDefaultFramebuffer(newDefault);
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400638 }
Ian Ewell292f0052016-02-04 10:37:32 -0500639
640 // Notify the renderer of a context switch
Luc Ferron5396f2a2018-07-12 08:24:23 -0400641 ANGLE_TRY(mImplementation->onMakeCurrent(this));
Jamie Madill4928b7c2017-06-20 12:57:39 -0400642 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000643}
644
Jamie Madill4928b7c2017-06-20 12:57:39 -0400645egl::Error Context::releaseSurface(const egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400646{
Geoff Langbf7b95d2018-05-01 16:48:21 -0400647 gl::Framebuffer *defaultFramebuffer = mState.mFramebuffers->getFramebuffer(0);
Corentin Wallez51706ea2015-08-07 14:39:22 -0400648
Geoff Langbf7b95d2018-05-01 16:48:21 -0400649 // Remove the default framebuffer
650 if (mGLState.getReadFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500651 {
652 mGLState.setReadFramebufferBinding(nullptr);
653 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400654
655 if (mGLState.getDrawFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500656 {
657 mGLState.setDrawFramebufferBinding(nullptr);
658 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400659
660 if (defaultFramebuffer)
661 {
662 defaultFramebuffer->onDestroy(this);
663 delete defaultFramebuffer;
664 }
665
Corentin Wallezc295e512017-01-27 17:47:50 -0500666 mState.mFramebuffers->setDefaultFramebuffer(nullptr);
667
668 if (mCurrentSurface)
669 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400670 ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
Corentin Wallezc295e512017-01-27 17:47:50 -0500671 mCurrentSurface = nullptr;
672 }
Jamie Madill4928b7c2017-06-20 12:57:39 -0400673
674 return egl::NoError();
Jamie Madill77a72f62015-04-14 11:18:32 -0400675}
676
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000677GLuint Context::createBuffer()
678{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500679 return mState.mBuffers->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000680}
681
682GLuint Context::createProgram()
683{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500684 return mState.mShaderPrograms->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000685}
686
Jiawei Shao385b3e02018-03-21 09:43:28 +0800687GLuint Context::createShader(ShaderType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000688{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500689 return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000690}
691
692GLuint Context::createTexture()
693{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500694 return mState.mTextures->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000695}
696
697GLuint Context::createRenderbuffer()
698{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500699 return mState.mRenderbuffers->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000700}
701
Brandon Jones59770802018-04-02 13:18:42 -0700702GLuint Context::genPaths(GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300703{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500704 auto resultOrError = mState.mPaths->createPaths(mImplementation.get(), range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300705 if (resultOrError.isError())
706 {
707 handleError(resultOrError.getError());
708 return 0;
709 }
710 return resultOrError.getResult();
711}
712
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000713// Returns an unused framebuffer name
714GLuint Context::createFramebuffer()
715{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500716 return mState.mFramebuffers->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000717}
718
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500719void Context::genFencesNV(GLsizei n, GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000720{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500721 for (int i = 0; i < n; i++)
722 {
723 GLuint handle = mFenceNVHandleAllocator.allocate();
724 mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV()));
725 fences[i] = handle;
726 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000727}
728
Yunchao Hea336b902017-08-02 16:05:21 +0800729GLuint Context::createProgramPipeline()
730{
731 return mState.mPipelines->createProgramPipeline();
732}
733
Jiawei Shao385b3e02018-03-21 09:43:28 +0800734GLuint Context::createShaderProgramv(ShaderType type, GLsizei count, const GLchar *const *strings)
Jiajia Qin5451d532017-11-16 17:16:34 +0800735{
736 UNIMPLEMENTED();
737 return 0u;
738}
739
James Darpinian4d9d4832018-03-13 12:43:28 -0700740void Context::deleteBuffer(GLuint bufferName)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000741{
James Darpinian4d9d4832018-03-13 12:43:28 -0700742 Buffer *buffer = mState.mBuffers->getBuffer(bufferName);
743 if (buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000744 {
745 detachBuffer(buffer);
746 }
Jamie Madill893ab082014-05-16 16:56:10 -0400747
James Darpinian4d9d4832018-03-13 12:43:28 -0700748 mState.mBuffers->deleteObject(this, bufferName);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000749}
750
751void Context::deleteShader(GLuint shader)
752{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500753 mState.mShaderPrograms->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000754}
755
756void Context::deleteProgram(GLuint program)
757{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500758 mState.mShaderPrograms->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000759}
760
761void Context::deleteTexture(GLuint texture)
762{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500763 if (mState.mTextures->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000764 {
765 detachTexture(texture);
766 }
767
Jamie Madill6c1f6712017-02-14 19:08:04 -0500768 mState.mTextures->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000769}
770
771void Context::deleteRenderbuffer(GLuint renderbuffer)
772{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500773 if (mState.mRenderbuffers->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000774 {
775 detachRenderbuffer(renderbuffer);
776 }
Jamie Madill893ab082014-05-16 16:56:10 -0400777
Jamie Madill6c1f6712017-02-14 19:08:04 -0500778 mState.mRenderbuffers->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000779}
780
Jamie Madill7f0c5a42017-08-26 22:43:26 -0400781void Context::deleteSync(GLsync sync)
Jamie Madillcd055f82013-07-26 11:55:15 -0400782{
783 // The spec specifies the underlying Fence object is not deleted until all current
784 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
785 // and since our API is currently designed for being called from a single thread, we can delete
786 // the fence immediately.
Jamie Madill70b5bb02017-08-28 13:32:37 -0400787 mState.mSyncs->deleteObject(this, static_cast<GLuint>(reinterpret_cast<uintptr_t>(sync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400788}
789
Yunchao Hea336b902017-08-02 16:05:21 +0800790void Context::deleteProgramPipeline(GLuint pipeline)
791{
792 if (mState.mPipelines->getProgramPipeline(pipeline))
793 {
794 detachProgramPipeline(pipeline);
795 }
796
797 mState.mPipelines->deleteObject(this, pipeline);
798}
799
Sami Väisänene45e53b2016-05-25 10:36:04 +0300800void Context::deletePaths(GLuint first, GLsizei range)
801{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500802 mState.mPaths->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300803}
804
Brandon Jones59770802018-04-02 13:18:42 -0700805bool Context::isPath(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300806{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500807 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300808 if (pathObj == nullptr)
809 return false;
810
811 return pathObj->hasPathData();
812}
813
Brandon Jones59770802018-04-02 13:18:42 -0700814bool Context::isPathGenerated(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300815{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500816 return mState.mPaths->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300817}
818
Brandon Jones59770802018-04-02 13:18:42 -0700819void Context::pathCommands(GLuint path,
820 GLsizei numCommands,
821 const GLubyte *commands,
822 GLsizei numCoords,
823 GLenum coordType,
824 const void *coords)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300825{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500826 auto *pathObject = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300827
828 handleError(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
829}
830
Jamie Madill007530e2017-12-28 14:27:04 -0500831void Context::pathParameterf(GLuint path, GLenum pname, GLfloat value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300832{
Jamie Madill007530e2017-12-28 14:27:04 -0500833 Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300834
835 switch (pname)
836 {
837 case GL_PATH_STROKE_WIDTH_CHROMIUM:
838 pathObj->setStrokeWidth(value);
839 break;
840 case GL_PATH_END_CAPS_CHROMIUM:
841 pathObj->setEndCaps(static_cast<GLenum>(value));
842 break;
843 case GL_PATH_JOIN_STYLE_CHROMIUM:
844 pathObj->setJoinStyle(static_cast<GLenum>(value));
845 break;
846 case GL_PATH_MITER_LIMIT_CHROMIUM:
847 pathObj->setMiterLimit(value);
848 break;
849 case GL_PATH_STROKE_BOUND_CHROMIUM:
850 pathObj->setStrokeBound(value);
851 break;
852 default:
853 UNREACHABLE();
854 break;
855 }
856}
857
Jamie Madill007530e2017-12-28 14:27:04 -0500858void Context::pathParameteri(GLuint path, GLenum pname, GLint value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300859{
Jamie Madill007530e2017-12-28 14:27:04 -0500860 // TODO(jmadill): Should use proper clamping/casting.
861 pathParameterf(path, pname, static_cast<GLfloat>(value));
862}
863
864void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value)
865{
866 const Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300867
868 switch (pname)
869 {
870 case GL_PATH_STROKE_WIDTH_CHROMIUM:
871 *value = pathObj->getStrokeWidth();
872 break;
873 case GL_PATH_END_CAPS_CHROMIUM:
874 *value = static_cast<GLfloat>(pathObj->getEndCaps());
875 break;
876 case GL_PATH_JOIN_STYLE_CHROMIUM:
877 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
878 break;
879 case GL_PATH_MITER_LIMIT_CHROMIUM:
880 *value = pathObj->getMiterLimit();
881 break;
882 case GL_PATH_STROKE_BOUND_CHROMIUM:
883 *value = pathObj->getStrokeBound();
884 break;
885 default:
886 UNREACHABLE();
887 break;
888 }
889}
890
Jamie Madill007530e2017-12-28 14:27:04 -0500891void Context::getPathParameteriv(GLuint path, GLenum pname, GLint *value)
892{
893 GLfloat val = 0.0f;
894 getPathParameterfv(path, pname, value != nullptr ? &val : nullptr);
895 if (value)
896 *value = static_cast<GLint>(val);
897}
898
Brandon Jones59770802018-04-02 13:18:42 -0700899void Context::pathStencilFunc(GLenum func, GLint ref, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300900{
901 mGLState.setPathStencilFunc(func, ref, mask);
902}
903
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000904void Context::deleteFramebuffer(GLuint framebuffer)
905{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500906 if (mState.mFramebuffers->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000907 {
908 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000909 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500910
Jamie Madill6c1f6712017-02-14 19:08:04 -0500911 mState.mFramebuffers->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000912}
913
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500914void Context::deleteFencesNV(GLsizei n, const GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000915{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500916 for (int i = 0; i < n; i++)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000917 {
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500918 GLuint fence = fences[i];
919
920 FenceNV *fenceObject = nullptr;
921 if (mFenceNVMap.erase(fence, &fenceObject))
922 {
923 mFenceNVHandleAllocator.release(fence);
924 delete fenceObject;
925 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000926 }
927}
928
Geoff Lang70d0f492015-12-10 17:45:46 -0500929Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000930{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500931 return mState.mBuffers->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000932}
933
Jamie Madill570f7c82014-07-03 10:38:54 -0400934Texture *Context::getTexture(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000935{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500936 return mState.mTextures->getTexture(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000937}
938
Geoff Lang70d0f492015-12-10 17:45:46 -0500939Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000940{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500941 return mState.mRenderbuffers->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000942}
943
Jamie Madill70b5bb02017-08-28 13:32:37 -0400944Sync *Context::getSync(GLsync handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400945{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400946 return mState.mSyncs->getSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400947}
948
Jamie Madill57a89722013-07-02 11:57:03 -0400949VertexArray *Context::getVertexArray(GLuint handle) const
950{
Jamie Madill96a483b2017-06-27 16:49:21 -0400951 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -0400952}
953
Jamie Madilldc356042013-07-19 16:36:57 -0400954Sampler *Context::getSampler(GLuint handle) const
955{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500956 return mState.mSamplers->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400957}
958
Geoff Langc8058452014-02-03 12:04:11 -0500959TransformFeedback *Context::getTransformFeedback(GLuint handle) const
960{
Jamie Madill96a483b2017-06-27 16:49:21 -0400961 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -0500962}
963
Yunchao Hea336b902017-08-02 16:05:21 +0800964ProgramPipeline *Context::getProgramPipeline(GLuint handle) const
965{
966 return mState.mPipelines->getProgramPipeline(handle);
967}
968
Geoff Lang75359662018-04-11 01:42:27 -0400969gl::LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
Geoff Lang70d0f492015-12-10 17:45:46 -0500970{
971 switch (identifier)
972 {
973 case GL_BUFFER:
974 return getBuffer(name);
975 case GL_SHADER:
976 return getShader(name);
977 case GL_PROGRAM:
978 return getProgram(name);
979 case GL_VERTEX_ARRAY:
980 return getVertexArray(name);
981 case GL_QUERY:
982 return getQuery(name);
983 case GL_TRANSFORM_FEEDBACK:
984 return getTransformFeedback(name);
985 case GL_SAMPLER:
986 return getSampler(name);
987 case GL_TEXTURE:
988 return getTexture(name);
989 case GL_RENDERBUFFER:
990 return getRenderbuffer(name);
991 case GL_FRAMEBUFFER:
992 return getFramebuffer(name);
993 default:
994 UNREACHABLE();
995 return nullptr;
996 }
997}
998
Geoff Lang75359662018-04-11 01:42:27 -0400999gl::LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
Geoff Lang70d0f492015-12-10 17:45:46 -05001000{
Jamie Madill70b5bb02017-08-28 13:32:37 -04001001 return getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
Geoff Lang70d0f492015-12-10 17:45:46 -05001002}
1003
Martin Radev9d901792016-07-15 15:58:58 +03001004void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
1005{
Geoff Lang75359662018-04-11 01:42:27 -04001006 gl::LabeledObject *object = getLabeledObject(identifier, name);
Martin Radev9d901792016-07-15 15:58:58 +03001007 ASSERT(object != nullptr);
1008
1009 std::string labelName = GetObjectLabelFromPointer(length, label);
1010 object->setLabel(labelName);
Jamie Madill8693bdb2017-09-02 15:32:14 -04001011
1012 // TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the
1013 // specified object is active until we do this.
1014 mGLState.setObjectDirty(identifier);
Martin Radev9d901792016-07-15 15:58:58 +03001015}
1016
1017void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
1018{
Geoff Lang75359662018-04-11 01:42:27 -04001019 gl::LabeledObject *object = getLabeledObjectFromPtr(ptr);
Martin Radev9d901792016-07-15 15:58:58 +03001020 ASSERT(object != nullptr);
1021
1022 std::string labelName = GetObjectLabelFromPointer(length, label);
1023 object->setLabel(labelName);
1024}
1025
1026void Context::getObjectLabel(GLenum identifier,
1027 GLuint name,
1028 GLsizei bufSize,
1029 GLsizei *length,
1030 GLchar *label) const
1031{
Geoff Lang75359662018-04-11 01:42:27 -04001032 gl::LabeledObject *object = getLabeledObject(identifier, name);
Martin Radev9d901792016-07-15 15:58:58 +03001033 ASSERT(object != nullptr);
1034
1035 const std::string &objectLabel = object->getLabel();
1036 GetObjectLabelBase(objectLabel, bufSize, length, label);
1037}
1038
1039void Context::getObjectPtrLabel(const void *ptr,
1040 GLsizei bufSize,
1041 GLsizei *length,
1042 GLchar *label) const
1043{
Geoff Lang75359662018-04-11 01:42:27 -04001044 gl::LabeledObject *object = getLabeledObjectFromPtr(ptr);
Martin Radev9d901792016-07-15 15:58:58 +03001045 ASSERT(object != nullptr);
1046
1047 const std::string &objectLabel = object->getLabel();
1048 GetObjectLabelBase(objectLabel, bufSize, length, label);
1049}
1050
Jamie Madilldc356042013-07-19 16:36:57 -04001051bool Context::isSampler(GLuint samplerName) const
1052{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001053 return mState.mSamplers->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -04001054}
1055
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001056void Context::bindTexture(TextureType target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001057{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001058 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001059
Jamie Madilldedd7b92014-11-05 16:30:36 -05001060 if (handle == 0)
1061 {
1062 texture = mZeroTextures[target].get();
1063 }
1064 else
1065 {
Corentin Wallez99d492c2018-02-27 15:17:10 -05001066 texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -05001067 }
1068
1069 ASSERT(texture);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001070 mGLState.setSamplerTexture(this, target, texture);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00001071}
1072
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001073void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001074{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001075 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1076 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001077 mGLState.setReadFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001078}
1079
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001080void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001081{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001082 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1083 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001084 mGLState.setDrawFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001085}
1086
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001087void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -04001088{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001089 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madill7267aa62018-04-17 15:28:21 -04001090 mGLState.setVertexArrayBinding(this, vertexArray);
Jamie Madill57a89722013-07-02 11:57:03 -04001091}
1092
Shao80957d92017-02-20 21:25:59 +08001093void Context::bindVertexBuffer(GLuint bindingIndex,
1094 GLuint bufferHandle,
1095 GLintptr offset,
1096 GLsizei stride)
1097{
1098 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001099 mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Shao80957d92017-02-20 21:25:59 +08001100}
1101
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001102void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -04001103{
Geoff Lang76b10c92014-09-05 16:28:14 -04001104 ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -04001105 Sampler *sampler =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001106 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001107 mGLState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04001108}
1109
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001110void Context::bindImageTexture(GLuint unit,
1111 GLuint texture,
1112 GLint level,
1113 GLboolean layered,
1114 GLint layer,
1115 GLenum access,
1116 GLenum format)
1117{
1118 Texture *tex = mState.mTextures->getTexture(texture);
1119 mGLState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
1120}
1121
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001122void Context::useProgram(GLuint program)
1123{
Jamie Madill6c1f6712017-02-14 19:08:04 -05001124 mGLState.setProgram(this, getProgram(program));
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001125}
1126
Jiajia Qin5451d532017-11-16 17:16:34 +08001127void Context::useProgramStages(GLuint pipeline, GLbitfield stages, GLuint program)
1128{
1129 UNIMPLEMENTED();
1130}
1131
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001132void Context::bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001133{
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001134 ASSERT(target == GL_TRANSFORM_FEEDBACK);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001135 TransformFeedback *transformFeedback =
1136 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001137 mGLState.setTransformFeedbackBinding(this, transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -05001138}
1139
Yunchao Hea336b902017-08-02 16:05:21 +08001140void Context::bindProgramPipeline(GLuint pipelineHandle)
1141{
1142 ProgramPipeline *pipeline =
1143 mState.mPipelines->checkProgramPipelineAllocation(mImplementation.get(), pipelineHandle);
1144 mGLState.setProgramPipelineBinding(this, pipeline);
1145}
1146
Corentin Wallezad3ae902018-03-09 13:40:42 -05001147void Context::beginQuery(QueryType target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001148{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001149 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001150 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001151
Geoff Lang5aad9672014-09-08 11:10:42 -04001152 // begin query
Jamie Madill5188a272018-07-25 10:53:56 -04001153 ANGLE_CONTEXT_TRY(queryObject->begin(this));
Geoff Lang5aad9672014-09-08 11:10:42 -04001154
1155 // set query as active for specified target only if begin succeeded
Jamie Madill4928b7c2017-06-20 12:57:39 -04001156 mGLState.setActiveQuery(this, target, queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001157}
1158
Corentin Wallezad3ae902018-03-09 13:40:42 -05001159void Context::endQuery(QueryType target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001160{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001161 Query *queryObject = mGLState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001162 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001163
Jamie Madill5188a272018-07-25 10:53:56 -04001164 handleError(queryObject->end(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001165
Geoff Lang5aad9672014-09-08 11:10:42 -04001166 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madill4928b7c2017-06-20 12:57:39 -04001167 mGLState.setActiveQuery(this, target, nullptr);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001168}
1169
Corentin Wallezad3ae902018-03-09 13:40:42 -05001170void Context::queryCounter(GLuint id, QueryType target)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001171{
Corentin Wallezad3ae902018-03-09 13:40:42 -05001172 ASSERT(target == QueryType::Timestamp);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001173
1174 Query *queryObject = getQuery(id, true, target);
1175 ASSERT(queryObject);
1176
Jamie Madill5188a272018-07-25 10:53:56 -04001177 handleError(queryObject->queryCounter(this));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001178}
1179
Corentin Wallezad3ae902018-03-09 13:40:42 -05001180void Context::getQueryiv(QueryType target, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001181{
1182 switch (pname)
1183 {
1184 case GL_CURRENT_QUERY_EXT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001185 params[0] = mGLState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001186 break;
1187 case GL_QUERY_COUNTER_BITS_EXT:
1188 switch (target)
1189 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001190 case QueryType::TimeElapsed:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001191 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1192 break;
Corentin Wallezad3ae902018-03-09 13:40:42 -05001193 case QueryType::Timestamp:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001194 params[0] = getExtensions().queryCounterBitsTimestamp;
1195 break;
1196 default:
1197 UNREACHABLE();
1198 params[0] = 0;
1199 break;
1200 }
1201 break;
1202 default:
1203 UNREACHABLE();
1204 return;
1205 }
1206}
1207
Corentin Wallezad3ae902018-03-09 13:40:42 -05001208void Context::getQueryivRobust(QueryType target,
Brandon Jones59770802018-04-02 13:18:42 -07001209 GLenum pname,
1210 GLsizei bufSize,
1211 GLsizei *length,
1212 GLint *params)
1213{
1214 getQueryiv(target, pname, params);
1215}
1216
Geoff Lang2186c382016-10-14 10:54:54 -04001217void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001218{
Jamie Madill5188a272018-07-25 10:53:56 -04001219 handleError(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001220}
1221
Brandon Jones59770802018-04-02 13:18:42 -07001222void Context::getQueryObjectivRobust(GLuint id,
1223 GLenum pname,
1224 GLsizei bufSize,
1225 GLsizei *length,
1226 GLint *params)
1227{
1228 getQueryObjectiv(id, pname, params);
1229}
1230
Geoff Lang2186c382016-10-14 10:54:54 -04001231void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001232{
Jamie Madill5188a272018-07-25 10:53:56 -04001233 handleError(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001234}
1235
Brandon Jones59770802018-04-02 13:18:42 -07001236void Context::getQueryObjectuivRobust(GLuint id,
1237 GLenum pname,
1238 GLsizei bufSize,
1239 GLsizei *length,
1240 GLuint *params)
1241{
1242 getQueryObjectuiv(id, pname, params);
1243}
1244
Geoff Lang2186c382016-10-14 10:54:54 -04001245void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001246{
Jamie Madill5188a272018-07-25 10:53:56 -04001247 handleError(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001248}
1249
Brandon Jones59770802018-04-02 13:18:42 -07001250void Context::getQueryObjecti64vRobust(GLuint id,
1251 GLenum pname,
1252 GLsizei bufSize,
1253 GLsizei *length,
1254 GLint64 *params)
1255{
1256 getQueryObjecti64v(id, pname, params);
1257}
1258
Geoff Lang2186c382016-10-14 10:54:54 -04001259void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001260{
Jamie Madill5188a272018-07-25 10:53:56 -04001261 handleError(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001262}
1263
Brandon Jones59770802018-04-02 13:18:42 -07001264void Context::getQueryObjectui64vRobust(GLuint id,
1265 GLenum pname,
1266 GLsizei bufSize,
1267 GLsizei *length,
1268 GLuint64 *params)
1269{
1270 getQueryObjectui64v(id, pname, params);
1271}
1272
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001273Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001274{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001275 return mState.mFramebuffers->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001276}
1277
Jamie Madill2f348d22017-06-05 10:50:59 -04001278FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001279{
Jamie Madill96a483b2017-06-27 16:49:21 -04001280 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001281}
1282
Corentin Wallezad3ae902018-03-09 13:40:42 -05001283Query *Context::getQuery(GLuint handle, bool create, QueryType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001284{
Jamie Madill96a483b2017-06-27 16:49:21 -04001285 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001286 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001287 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001288 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001289
1290 Query *query = mQueryMap.query(handle);
1291 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001292 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001293 ASSERT(type != QueryType::InvalidEnum);
Jamie Madill96a483b2017-06-27 16:49:21 -04001294 query = new Query(mImplementation->createQuery(type), handle);
1295 query->addRef();
1296 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001297 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001298 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001299}
1300
Geoff Lang70d0f492015-12-10 17:45:46 -05001301Query *Context::getQuery(GLuint handle) const
1302{
Jamie Madill96a483b2017-06-27 16:49:21 -04001303 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001304}
1305
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001306Texture *Context::getTargetTexture(TextureType type) const
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001307{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001308 ASSERT(ValidTextureTarget(this, type) || ValidTextureExternalTarget(this, type));
1309 return mGLState.getTargetTexture(type);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001310}
1311
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001312Texture *Context::getSamplerTexture(unsigned int sampler, TextureType type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001313{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001314 return mGLState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001315}
1316
Geoff Lang492a7e42014-11-05 13:27:06 -05001317Compiler *Context::getCompiler() const
1318{
Jamie Madill2f348d22017-06-05 10:50:59 -04001319 if (mCompiler.get() == nullptr)
1320 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001321 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001322 }
1323 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001324}
1325
Jamie Madillc1d770e2017-04-13 17:31:24 -04001326void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001327{
1328 switch (pname)
1329 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001330 case GL_SHADER_COMPILER:
1331 *params = GL_TRUE;
1332 break;
1333 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1334 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1335 break;
1336 default:
1337 mGLState.getBooleanv(pname, params);
1338 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001339 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001340}
1341
Jamie Madillc1d770e2017-04-13 17:31:24 -04001342void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001343{
Shannon Woods53a94a82014-06-24 15:20:36 -04001344 // Queries about context capabilities and maximums are answered by Context.
1345 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001346 switch (pname)
1347 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001348 case GL_ALIASED_LINE_WIDTH_RANGE:
1349 params[0] = mCaps.minAliasedLineWidth;
1350 params[1] = mCaps.maxAliasedLineWidth;
1351 break;
1352 case GL_ALIASED_POINT_SIZE_RANGE:
1353 params[0] = mCaps.minAliasedPointSize;
1354 params[1] = mCaps.maxAliasedPointSize;
1355 break;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07001356 case GL_SMOOTH_POINT_SIZE_RANGE:
1357 params[0] = mCaps.minSmoothPointSize;
1358 params[1] = mCaps.maxSmoothPointSize;
1359 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001360 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1361 ASSERT(mExtensions.textureFilterAnisotropic);
1362 *params = mExtensions.maxTextureAnisotropy;
1363 break;
1364 case GL_MAX_TEXTURE_LOD_BIAS:
1365 *params = mCaps.maxLODBias;
1366 break;
1367
1368 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1369 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1370 {
Lingfeng Yang3a41af62018-04-09 07:28:56 -07001371 // GLES1 emulation: // GL_PATH_(MODELVIEW|PROJECTION)_MATRIX_CHROMIUM collides with the
1372 // GLES1 constants for modelview/projection matrix.
1373 if (getClientVersion() < Version(2, 0))
1374 {
1375 mGLState.getFloatv(pname, params);
1376 }
1377 else
1378 {
1379 ASSERT(mExtensions.pathRendering);
1380 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1381 memcpy(params, m, 16 * sizeof(GLfloat));
1382 }
Jamie Madill231c7f52017-04-26 13:45:37 -04001383 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001384 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001385
Jamie Madill231c7f52017-04-26 13:45:37 -04001386 default:
1387 mGLState.getFloatv(pname, params);
1388 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001389 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001390}
1391
Jamie Madillc1d770e2017-04-13 17:31:24 -04001392void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001393{
Shannon Woods53a94a82014-06-24 15:20:36 -04001394 // Queries about context capabilities and maximums are answered by Context.
1395 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001396
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001397 switch (pname)
1398 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001399 case GL_MAX_VERTEX_ATTRIBS:
1400 *params = mCaps.maxVertexAttributes;
1401 break;
1402 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1403 *params = mCaps.maxVertexUniformVectors;
1404 break;
1405 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001406 *params = mCaps.maxShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001407 break;
1408 case GL_MAX_VARYING_VECTORS:
1409 *params = mCaps.maxVaryingVectors;
1410 break;
1411 case GL_MAX_VARYING_COMPONENTS:
1412 *params = mCaps.maxVertexOutputComponents;
1413 break;
1414 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1415 *params = mCaps.maxCombinedTextureImageUnits;
1416 break;
1417 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001418 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001419 break;
1420 case GL_MAX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001421 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001422 break;
1423 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1424 *params = mCaps.maxFragmentUniformVectors;
1425 break;
1426 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001427 *params = mCaps.maxShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001428 break;
1429 case GL_MAX_RENDERBUFFER_SIZE:
1430 *params = mCaps.maxRenderbufferSize;
1431 break;
1432 case GL_MAX_COLOR_ATTACHMENTS_EXT:
1433 *params = mCaps.maxColorAttachments;
1434 break;
1435 case GL_MAX_DRAW_BUFFERS_EXT:
1436 *params = mCaps.maxDrawBuffers;
1437 break;
1438 // case GL_FRAMEBUFFER_BINDING: // now equivalent to
1439 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
1440 case GL_SUBPIXEL_BITS:
1441 *params = 4;
1442 break;
1443 case GL_MAX_TEXTURE_SIZE:
1444 *params = mCaps.max2DTextureSize;
1445 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001446 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
1447 *params = mCaps.maxRectangleTextureSize;
1448 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001449 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1450 *params = mCaps.maxCubeMapTextureSize;
1451 break;
1452 case GL_MAX_3D_TEXTURE_SIZE:
1453 *params = mCaps.max3DTextureSize;
1454 break;
1455 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1456 *params = mCaps.maxArrayTextureLayers;
1457 break;
1458 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1459 *params = mCaps.uniformBufferOffsetAlignment;
1460 break;
1461 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1462 *params = mCaps.maxUniformBufferBindings;
1463 break;
1464 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001465 *params = mCaps.maxShaderUniformBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001466 break;
1467 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001468 *params = mCaps.maxShaderUniformBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001469 break;
1470 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1471 *params = mCaps.maxCombinedTextureImageUnits;
1472 break;
1473 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1474 *params = mCaps.maxVertexOutputComponents;
1475 break;
1476 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1477 *params = mCaps.maxFragmentInputComponents;
1478 break;
1479 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1480 *params = mCaps.minProgramTexelOffset;
1481 break;
1482 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1483 *params = mCaps.maxProgramTexelOffset;
1484 break;
1485 case GL_MAJOR_VERSION:
1486 *params = getClientVersion().major;
1487 break;
1488 case GL_MINOR_VERSION:
1489 *params = getClientVersion().minor;
1490 break;
1491 case GL_MAX_ELEMENTS_INDICES:
1492 *params = mCaps.maxElementsIndices;
1493 break;
1494 case GL_MAX_ELEMENTS_VERTICES:
1495 *params = mCaps.maxElementsVertices;
1496 break;
1497 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1498 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1499 break;
1500 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1501 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1502 break;
1503 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1504 *params = mCaps.maxTransformFeedbackSeparateComponents;
1505 break;
1506 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1507 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1508 break;
1509 case GL_MAX_SAMPLES_ANGLE:
1510 *params = mCaps.maxSamples;
1511 break;
1512 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001513 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001514 params[0] = mCaps.maxViewportWidth;
1515 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001516 }
1517 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001518 case GL_COMPRESSED_TEXTURE_FORMATS:
1519 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1520 params);
1521 break;
1522 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1523 *params = mResetStrategy;
1524 break;
1525 case GL_NUM_SHADER_BINARY_FORMATS:
1526 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1527 break;
1528 case GL_SHADER_BINARY_FORMATS:
1529 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1530 break;
1531 case GL_NUM_PROGRAM_BINARY_FORMATS:
1532 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1533 break;
1534 case GL_PROGRAM_BINARY_FORMATS:
1535 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1536 break;
1537 case GL_NUM_EXTENSIONS:
1538 *params = static_cast<GLint>(mExtensionStrings.size());
1539 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001540
Jamie Madill231c7f52017-04-26 13:45:37 -04001541 // GL_KHR_debug
1542 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1543 *params = mExtensions.maxDebugMessageLength;
1544 break;
1545 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1546 *params = mExtensions.maxDebugLoggedMessages;
1547 break;
1548 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1549 *params = mExtensions.maxDebugGroupStackDepth;
1550 break;
1551 case GL_MAX_LABEL_LENGTH:
1552 *params = mExtensions.maxLabelLength;
1553 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001554
Martin Radeve5285d22017-07-14 16:23:53 +03001555 // GL_ANGLE_multiview
1556 case GL_MAX_VIEWS_ANGLE:
1557 *params = mExtensions.maxViews;
1558 break;
1559
Jamie Madill231c7f52017-04-26 13:45:37 -04001560 // GL_EXT_disjoint_timer_query
1561 case GL_GPU_DISJOINT_EXT:
1562 *params = mImplementation->getGPUDisjoint();
1563 break;
1564 case GL_MAX_FRAMEBUFFER_WIDTH:
1565 *params = mCaps.maxFramebufferWidth;
1566 break;
1567 case GL_MAX_FRAMEBUFFER_HEIGHT:
1568 *params = mCaps.maxFramebufferHeight;
1569 break;
1570 case GL_MAX_FRAMEBUFFER_SAMPLES:
1571 *params = mCaps.maxFramebufferSamples;
1572 break;
1573 case GL_MAX_SAMPLE_MASK_WORDS:
1574 *params = mCaps.maxSampleMaskWords;
1575 break;
1576 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1577 *params = mCaps.maxColorTextureSamples;
1578 break;
1579 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1580 *params = mCaps.maxDepthTextureSamples;
1581 break;
1582 case GL_MAX_INTEGER_SAMPLES:
1583 *params = mCaps.maxIntegerSamples;
1584 break;
1585 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1586 *params = mCaps.maxVertexAttribRelativeOffset;
1587 break;
1588 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1589 *params = mCaps.maxVertexAttribBindings;
1590 break;
1591 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1592 *params = mCaps.maxVertexAttribStride;
1593 break;
1594 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001595 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001596 break;
1597 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001598 *params = mCaps.maxShaderAtomicCounters[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001599 break;
1600 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001601 *params = mCaps.maxShaderImageUniforms[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001602 break;
1603 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001604 *params = mCaps.maxShaderStorageBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001605 break;
1606 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001607 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001608 break;
1609 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001610 *params = mCaps.maxShaderAtomicCounters[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001611 break;
1612 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001613 *params = mCaps.maxShaderImageUniforms[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001614 break;
1615 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001616 *params = mCaps.maxShaderStorageBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001617 break;
1618 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1619 *params = mCaps.minProgramTextureGatherOffset;
1620 break;
1621 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1622 *params = mCaps.maxProgramTextureGatherOffset;
1623 break;
1624 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1625 *params = mCaps.maxComputeWorkGroupInvocations;
1626 break;
1627 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001628 *params = mCaps.maxShaderUniformBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001629 break;
1630 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001631 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001632 break;
1633 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1634 *params = mCaps.maxComputeSharedMemorySize;
1635 break;
1636 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001637 *params = mCaps.maxShaderUniformComponents[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001638 break;
1639 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001640 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001641 break;
1642 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001643 *params = mCaps.maxShaderAtomicCounters[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001644 break;
1645 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001646 *params = mCaps.maxShaderImageUniforms[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001647 break;
1648 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001649 *params =
1650 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Compute]);
Jamie Madill231c7f52017-04-26 13:45:37 -04001651 break;
1652 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001653 *params = mCaps.maxShaderStorageBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001654 break;
1655 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1656 *params = mCaps.maxCombinedShaderOutputResources;
1657 break;
1658 case GL_MAX_UNIFORM_LOCATIONS:
1659 *params = mCaps.maxUniformLocations;
1660 break;
1661 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1662 *params = mCaps.maxAtomicCounterBufferBindings;
1663 break;
1664 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1665 *params = mCaps.maxAtomicCounterBufferSize;
1666 break;
1667 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1668 *params = mCaps.maxCombinedAtomicCounterBuffers;
1669 break;
1670 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1671 *params = mCaps.maxCombinedAtomicCounters;
1672 break;
1673 case GL_MAX_IMAGE_UNITS:
1674 *params = mCaps.maxImageUnits;
1675 break;
1676 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1677 *params = mCaps.maxCombinedImageUniforms;
1678 break;
1679 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1680 *params = mCaps.maxShaderStorageBufferBindings;
1681 break;
1682 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1683 *params = mCaps.maxCombinedShaderStorageBlocks;
1684 break;
1685 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1686 *params = mCaps.shaderStorageBufferOffsetAlignment;
1687 break;
Jiawei Shao361df072017-11-22 09:33:59 +08001688
1689 // GL_EXT_geometry_shader
1690 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
1691 *params = mCaps.maxFramebufferLayers;
1692 break;
1693 case GL_LAYER_PROVOKING_VERTEX_EXT:
1694 *params = mCaps.layerProvokingVertex;
1695 break;
1696 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001697 *params = mCaps.maxShaderUniformComponents[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001698 break;
1699 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001700 *params = mCaps.maxShaderUniformBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001701 break;
1702 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001703 *params =
1704 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Geometry]);
Jiawei Shao361df072017-11-22 09:33:59 +08001705 break;
1706 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
1707 *params = mCaps.maxGeometryInputComponents;
1708 break;
1709 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
1710 *params = mCaps.maxGeometryOutputComponents;
1711 break;
1712 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
1713 *params = mCaps.maxGeometryOutputVertices;
1714 break;
1715 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
1716 *params = mCaps.maxGeometryTotalOutputComponents;
1717 break;
1718 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
1719 *params = mCaps.maxGeometryShaderInvocations;
1720 break;
1721 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001722 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001723 break;
1724 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001725 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001726 break;
1727 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001728 *params = mCaps.maxShaderAtomicCounters[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001729 break;
1730 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001731 *params = mCaps.maxShaderImageUniforms[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001732 break;
1733 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001734 *params = mCaps.maxShaderStorageBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001735 break;
Lingfeng Yang96310cd2018-03-28 11:56:28 -07001736 // GLES1 emulation: Caps queries
1737 case GL_MAX_TEXTURE_UNITS:
1738 *params = mCaps.maxMultitextureUnits;
1739 break;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001740 case GL_MAX_MODELVIEW_STACK_DEPTH:
1741 *params = mCaps.maxModelviewMatrixStackDepth;
1742 break;
1743 case GL_MAX_PROJECTION_STACK_DEPTH:
1744 *params = mCaps.maxProjectionMatrixStackDepth;
1745 break;
1746 case GL_MAX_TEXTURE_STACK_DEPTH:
1747 *params = mCaps.maxTextureMatrixStackDepth;
1748 break;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07001749 case GL_MAX_LIGHTS:
1750 *params = mCaps.maxLights;
1751 break;
Lingfeng Yang060088a2018-05-30 20:40:57 -07001752 case GL_MAX_CLIP_PLANES:
1753 *params = mCaps.maxClipPlanes;
1754 break;
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001755 // GLES1 emulation: Vertex attribute queries
1756 case GL_VERTEX_ARRAY_BUFFER_BINDING:
1757 case GL_NORMAL_ARRAY_BUFFER_BINDING:
1758 case GL_COLOR_ARRAY_BUFFER_BINDING:
1759 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
1760 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
1761 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1762 GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, params);
1763 break;
1764 case GL_VERTEX_ARRAY_STRIDE:
1765 case GL_NORMAL_ARRAY_STRIDE:
1766 case GL_COLOR_ARRAY_STRIDE:
1767 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
1768 case GL_TEXTURE_COORD_ARRAY_STRIDE:
1769 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1770 GL_VERTEX_ATTRIB_ARRAY_STRIDE, params);
1771 break;
1772 case GL_VERTEX_ARRAY_SIZE:
1773 case GL_COLOR_ARRAY_SIZE:
1774 case GL_TEXTURE_COORD_ARRAY_SIZE:
1775 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1776 GL_VERTEX_ATTRIB_ARRAY_SIZE, params);
1777 break;
1778 case GL_VERTEX_ARRAY_TYPE:
1779 case GL_COLOR_ARRAY_TYPE:
1780 case GL_NORMAL_ARRAY_TYPE:
1781 case GL_POINT_SIZE_ARRAY_TYPE_OES:
1782 case GL_TEXTURE_COORD_ARRAY_TYPE:
1783 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1784 GL_VERTEX_ATTRIB_ARRAY_TYPE, params);
1785 break;
1786
jchen1082af6202018-06-22 10:59:52 +08001787 // GL_KHR_parallel_shader_compile
1788 case GL_MAX_SHADER_COMPILER_THREADS_KHR:
1789 *params = mGLState.getMaxShaderCompilerThreads();
1790 break;
1791
Jamie Madill231c7f52017-04-26 13:45:37 -04001792 default:
Jamie Madille98b1b52018-03-08 09:47:23 -05001793 handleError(mGLState.getIntegerv(this, pname, params));
Jamie Madill231c7f52017-04-26 13:45:37 -04001794 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001795 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001796}
1797
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001798void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001799{
Shannon Woods53a94a82014-06-24 15:20:36 -04001800 // Queries about context capabilities and maximums are answered by Context.
1801 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001802 switch (pname)
1803 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001804 case GL_MAX_ELEMENT_INDEX:
1805 *params = mCaps.maxElementIndex;
1806 break;
1807 case GL_MAX_UNIFORM_BLOCK_SIZE:
1808 *params = mCaps.maxUniformBlockSize;
1809 break;
1810 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001811 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001812 break;
1813 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001814 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001815 break;
1816 case GL_MAX_SERVER_WAIT_TIMEOUT:
1817 *params = mCaps.maxServerWaitTimeout;
1818 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001819
Jamie Madill231c7f52017-04-26 13:45:37 -04001820 // GL_EXT_disjoint_timer_query
1821 case GL_TIMESTAMP_EXT:
1822 *params = mImplementation->getTimestamp();
1823 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001824
Jamie Madill231c7f52017-04-26 13:45:37 -04001825 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1826 *params = mCaps.maxShaderStorageBlockSize;
1827 break;
1828 default:
1829 UNREACHABLE();
1830 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001831 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001832}
1833
Geoff Lang70d0f492015-12-10 17:45:46 -05001834void Context::getPointerv(GLenum pname, void **params) const
1835{
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001836 mGLState.getPointerv(this, pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001837}
1838
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001839void Context::getPointervRobustANGLERobust(GLenum pname,
1840 GLsizei bufSize,
1841 GLsizei *length,
1842 void **params)
1843{
1844 UNIMPLEMENTED();
1845}
1846
Martin Radev66fb8202016-07-28 11:45:20 +03001847void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001848{
Shannon Woods53a94a82014-06-24 15:20:36 -04001849 // Queries about context capabilities and maximums are answered by Context.
1850 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001851
1852 GLenum nativeType;
1853 unsigned int numParams;
1854 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1855 ASSERT(queryStatus);
1856
1857 if (nativeType == GL_INT)
1858 {
1859 switch (target)
1860 {
1861 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1862 ASSERT(index < 3u);
1863 *data = mCaps.maxComputeWorkGroupCount[index];
1864 break;
1865 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1866 ASSERT(index < 3u);
1867 *data = mCaps.maxComputeWorkGroupSize[index];
1868 break;
1869 default:
1870 mGLState.getIntegeri_v(target, index, data);
1871 }
1872 }
1873 else
1874 {
1875 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1876 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001877}
1878
Brandon Jones59770802018-04-02 13:18:42 -07001879void Context::getIntegeri_vRobust(GLenum target,
1880 GLuint index,
1881 GLsizei bufSize,
1882 GLsizei *length,
1883 GLint *data)
1884{
1885 getIntegeri_v(target, index, data);
1886}
1887
Martin Radev66fb8202016-07-28 11:45:20 +03001888void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001889{
Shannon Woods53a94a82014-06-24 15:20:36 -04001890 // Queries about context capabilities and maximums are answered by Context.
1891 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001892
1893 GLenum nativeType;
1894 unsigned int numParams;
1895 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1896 ASSERT(queryStatus);
1897
1898 if (nativeType == GL_INT_64_ANGLEX)
1899 {
1900 mGLState.getInteger64i_v(target, index, data);
1901 }
1902 else
1903 {
1904 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1905 }
1906}
1907
Brandon Jones59770802018-04-02 13:18:42 -07001908void Context::getInteger64i_vRobust(GLenum target,
1909 GLuint index,
1910 GLsizei bufSize,
1911 GLsizei *length,
1912 GLint64 *data)
1913{
1914 getInteger64i_v(target, index, data);
1915}
1916
Martin Radev66fb8202016-07-28 11:45:20 +03001917void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1918{
1919 // Queries about context capabilities and maximums are answered by Context.
1920 // Queries about current GL state values are answered by State.
1921
1922 GLenum nativeType;
1923 unsigned int numParams;
1924 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1925 ASSERT(queryStatus);
1926
1927 if (nativeType == GL_BOOL)
1928 {
1929 mGLState.getBooleani_v(target, index, data);
1930 }
1931 else
1932 {
1933 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1934 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001935}
1936
Brandon Jones59770802018-04-02 13:18:42 -07001937void Context::getBooleani_vRobust(GLenum target,
1938 GLuint index,
1939 GLsizei bufSize,
1940 GLsizei *length,
1941 GLboolean *data)
1942{
1943 getBooleani_v(target, index, data);
1944}
1945
Corentin Wallez336129f2017-10-17 15:55:40 -04001946void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001947{
1948 Buffer *buffer = mGLState.getTargetBuffer(target);
1949 QueryBufferParameteriv(buffer, pname, params);
1950}
1951
Brandon Jones59770802018-04-02 13:18:42 -07001952void Context::getBufferParameterivRobust(BufferBinding target,
1953 GLenum pname,
1954 GLsizei bufSize,
1955 GLsizei *length,
1956 GLint *params)
1957{
1958 getBufferParameteriv(target, pname, params);
1959}
1960
He Yunchao010e4db2017-03-03 14:22:06 +08001961void Context::getFramebufferAttachmentParameteriv(GLenum target,
1962 GLenum attachment,
1963 GLenum pname,
1964 GLint *params)
1965{
1966 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08001967 QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08001968}
1969
Brandon Jones59770802018-04-02 13:18:42 -07001970void Context::getFramebufferAttachmentParameterivRobust(GLenum target,
1971 GLenum attachment,
1972 GLenum pname,
1973 GLsizei bufSize,
1974 GLsizei *length,
1975 GLint *params)
1976{
1977 getFramebufferAttachmentParameteriv(target, attachment, pname, params);
1978}
1979
He Yunchao010e4db2017-03-03 14:22:06 +08001980void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
1981{
1982 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
1983 QueryRenderbufferiv(this, renderbuffer, pname, params);
1984}
1985
Brandon Jones59770802018-04-02 13:18:42 -07001986void Context::getRenderbufferParameterivRobust(GLenum target,
1987 GLenum pname,
1988 GLsizei bufSize,
1989 GLsizei *length,
1990 GLint *params)
1991{
1992 getRenderbufferParameteriv(target, pname, params);
1993}
1994
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001995void Context::getTexParameterfv(TextureType target, GLenum pname, GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001996{
1997 Texture *texture = getTargetTexture(target);
1998 QueryTexParameterfv(texture, pname, params);
1999}
2000
Brandon Jones59770802018-04-02 13:18:42 -07002001void Context::getTexParameterfvRobust(TextureType target,
2002 GLenum pname,
2003 GLsizei bufSize,
2004 GLsizei *length,
2005 GLfloat *params)
2006{
2007 getTexParameterfv(target, pname, params);
2008}
2009
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002010void Context::getTexParameteriv(TextureType target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002011{
2012 Texture *texture = getTargetTexture(target);
2013 QueryTexParameteriv(texture, pname, params);
2014}
Jiajia Qin5451d532017-11-16 17:16:34 +08002015
Brandon Jones59770802018-04-02 13:18:42 -07002016void Context::getTexParameterivRobust(TextureType target,
2017 GLenum pname,
2018 GLsizei bufSize,
2019 GLsizei *length,
2020 GLint *params)
2021{
2022 getTexParameteriv(target, pname, params);
2023}
2024
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002025void Context::getTexParameterIivRobust(TextureType target,
2026 GLenum pname,
2027 GLsizei bufSize,
2028 GLsizei *length,
2029 GLint *params)
2030{
2031 UNIMPLEMENTED();
2032}
2033
2034void Context::getTexParameterIuivRobust(TextureType target,
2035 GLenum pname,
2036 GLsizei bufSize,
2037 GLsizei *length,
2038 GLuint *params)
2039{
2040 UNIMPLEMENTED();
2041}
2042
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002043void Context::getTexLevelParameteriv(TextureTarget target, GLint level, GLenum pname, GLint *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002044{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002045 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002046 QueryTexLevelParameteriv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002047}
2048
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002049void Context::getTexLevelParameterivRobust(TextureTarget target,
2050 GLint level,
2051 GLenum pname,
2052 GLsizei bufSize,
2053 GLsizei *length,
2054 GLint *params)
2055{
2056 UNIMPLEMENTED();
2057}
2058
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002059void Context::getTexLevelParameterfv(TextureTarget target,
2060 GLint level,
2061 GLenum pname,
2062 GLfloat *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002063{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002064 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002065 QueryTexLevelParameterfv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002066}
2067
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002068void Context::getTexLevelParameterfvRobust(TextureTarget target,
2069 GLint level,
2070 GLenum pname,
2071 GLsizei bufSize,
2072 GLsizei *length,
2073 GLfloat *params)
2074{
2075 UNIMPLEMENTED();
2076}
2077
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002078void Context::texParameterf(TextureType target, GLenum pname, GLfloat param)
He Yunchao010e4db2017-03-03 14:22:06 +08002079{
2080 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002081 SetTexParameterf(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002082 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002083}
2084
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002085void Context::texParameterfv(TextureType target, GLenum pname, const GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002086{
2087 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002088 SetTexParameterfv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002089 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002090}
2091
Brandon Jones59770802018-04-02 13:18:42 -07002092void Context::texParameterfvRobust(TextureType target,
2093 GLenum pname,
2094 GLsizei bufSize,
2095 const GLfloat *params)
2096{
2097 texParameterfv(target, pname, params);
2098}
2099
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002100void Context::texParameteri(TextureType target, GLenum pname, GLint param)
He Yunchao010e4db2017-03-03 14:22:06 +08002101{
2102 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002103 SetTexParameteri(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002104 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002105}
2106
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002107void Context::texParameteriv(TextureType target, GLenum pname, const GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002108{
2109 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002110 SetTexParameteriv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002111 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002112}
2113
Brandon Jones59770802018-04-02 13:18:42 -07002114void Context::texParameterivRobust(TextureType target,
2115 GLenum pname,
2116 GLsizei bufSize,
2117 const GLint *params)
2118{
2119 texParameteriv(target, pname, params);
2120}
2121
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002122void Context::texParameterIivRobust(TextureType target,
2123 GLenum pname,
2124 GLsizei bufSize,
2125 const GLint *params)
2126{
2127 UNIMPLEMENTED();
2128}
2129
2130void Context::texParameterIuivRobust(TextureType target,
2131 GLenum pname,
2132 GLsizei bufSize,
2133 const GLuint *params)
2134{
2135 UNIMPLEMENTED();
2136}
2137
Jamie Madill493f9572018-05-24 19:52:15 -04002138void Context::drawArrays(PrimitiveMode mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002139{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002140 // No-op if count draws no primitives for given mode
2141 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002142 {
2143 return;
2144 }
2145
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002146 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002147 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
Jamie Madill09463932018-04-04 05:26:59 -04002148 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count, 1);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002149}
2150
Jamie Madill493f9572018-05-24 19:52:15 -04002151void Context::drawArraysInstanced(PrimitiveMode mode,
2152 GLint first,
2153 GLsizei count,
2154 GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04002155{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002156 // No-op if count draws no primitives for given mode
2157 if (noopDrawInstanced(mode, count, instanceCount))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002158 {
2159 return;
2160 }
2161
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002162 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002163 ANGLE_CONTEXT_TRY(
2164 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
Jamie Madill09463932018-04-04 05:26:59 -04002165 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count,
2166 instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -04002167}
2168
Jamie Madill493f9572018-05-24 19:52:15 -04002169void Context::drawElements(PrimitiveMode mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002170{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002171 // No-op if count draws no primitives for given mode
2172 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002173 {
2174 return;
2175 }
2176
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002177 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002178 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04002179}
2180
Jamie Madill493f9572018-05-24 19:52:15 -04002181void Context::drawElementsInstanced(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002182 GLsizei count,
2183 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002184 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04002185 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04002186{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002187 // No-op if count draws no primitives for given mode
2188 if (noopDrawInstanced(mode, count, instances))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002189 {
2190 return;
2191 }
2192
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002193 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002194 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08002195 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04002196}
2197
Jamie Madill493f9572018-05-24 19:52:15 -04002198void Context::drawRangeElements(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002199 GLuint start,
2200 GLuint end,
2201 GLsizei count,
2202 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002203 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04002204{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002205 // No-op if count draws no primitives for given mode
2206 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002207 {
2208 return;
2209 }
2210
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002211 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002212 ANGLE_CONTEXT_TRY(
2213 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002214}
2215
Jamie Madill493f9572018-05-24 19:52:15 -04002216void Context::drawArraysIndirect(PrimitiveMode mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002217{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002218 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002219 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002220}
2221
Jamie Madill493f9572018-05-24 19:52:15 -04002222void Context::drawElementsIndirect(PrimitiveMode mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002223{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002224 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002225 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002226}
2227
Jamie Madill675fe712016-12-19 13:07:54 -05002228void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002229{
Jamie Madillafa02a22017-11-23 12:57:38 -05002230 handleError(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05002231}
2232
Jamie Madill675fe712016-12-19 13:07:54 -05002233void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05002234{
Jamie Madillafa02a22017-11-23 12:57:38 -05002235 handleError(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002236}
2237
Austin Kinross6ee1e782015-05-29 17:05:37 -07002238void Context::insertEventMarker(GLsizei length, const char *marker)
2239{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002240 ASSERT(mImplementation);
2241 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07002242}
2243
2244void Context::pushGroupMarker(GLsizei length, const char *marker)
2245{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002246 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05002247
2248 if (marker == nullptr)
2249 {
2250 // From the EXT_debug_marker spec,
2251 // "If <marker> is null then an empty string is pushed on the stack."
2252 mImplementation->pushGroupMarker(length, "");
2253 }
2254 else
2255 {
2256 mImplementation->pushGroupMarker(length, marker);
2257 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07002258}
2259
2260void Context::popGroupMarker()
2261{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002262 ASSERT(mImplementation);
2263 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07002264}
2265
Geoff Langd8605522016-04-13 10:19:12 -04002266void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
2267{
2268 Program *programObject = getProgram(program);
2269 ASSERT(programObject);
2270
2271 programObject->bindUniformLocation(location, name);
2272}
2273
Brandon Jones59770802018-04-02 13:18:42 -07002274void Context::coverageModulation(GLenum components)
Sami Väisänena797e062016-05-12 15:23:40 +03002275{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002276 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03002277}
2278
Brandon Jones59770802018-04-02 13:18:42 -07002279void Context::matrixLoadf(GLenum matrixMode, const GLfloat *matrix)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002280{
2281 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
2282}
2283
Brandon Jones59770802018-04-02 13:18:42 -07002284void Context::matrixLoadIdentity(GLenum matrixMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002285{
2286 GLfloat I[16];
2287 angle::Matrix<GLfloat>::setToIdentity(I);
2288
2289 mGLState.loadPathRenderingMatrix(matrixMode, I);
2290}
2291
2292void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
2293{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002294 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002295 if (!pathObj)
2296 return;
2297
2298 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002299 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002300
2301 mImplementation->stencilFillPath(pathObj, fillMode, mask);
2302}
2303
2304void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
2305{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002306 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002307 if (!pathObj)
2308 return;
2309
2310 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002311 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002312
2313 mImplementation->stencilStrokePath(pathObj, reference, mask);
2314}
2315
2316void Context::coverFillPath(GLuint path, GLenum coverMode)
2317{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002318 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002319 if (!pathObj)
2320 return;
2321
2322 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002323 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002324
2325 mImplementation->coverFillPath(pathObj, coverMode);
2326}
2327
2328void Context::coverStrokePath(GLuint path, GLenum coverMode)
2329{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002330 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002331 if (!pathObj)
2332 return;
2333
2334 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002335 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002336
2337 mImplementation->coverStrokePath(pathObj, coverMode);
2338}
2339
2340void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
2341{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002342 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002343 if (!pathObj)
2344 return;
2345
2346 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002347 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002348
2349 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
2350}
2351
2352void Context::stencilThenCoverStrokePath(GLuint path,
2353 GLint reference,
2354 GLuint mask,
2355 GLenum coverMode)
2356{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002357 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002358 if (!pathObj)
2359 return;
2360
2361 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002362 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002363
2364 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2365}
2366
Sami Väisänend59ca052016-06-21 16:10:00 +03002367void Context::coverFillPathInstanced(GLsizei numPaths,
2368 GLenum pathNameType,
2369 const void *paths,
2370 GLuint pathBase,
2371 GLenum coverMode,
2372 GLenum transformType,
2373 const GLfloat *transformValues)
2374{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002375 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002376
2377 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002378 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002379
2380 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2381}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002382
Sami Väisänend59ca052016-06-21 16:10:00 +03002383void Context::coverStrokePathInstanced(GLsizei numPaths,
2384 GLenum pathNameType,
2385 const void *paths,
2386 GLuint pathBase,
2387 GLenum coverMode,
2388 GLenum transformType,
2389 const GLfloat *transformValues)
2390{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002391 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002392
2393 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002394 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002395
2396 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2397 transformValues);
2398}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002399
Sami Väisänend59ca052016-06-21 16:10:00 +03002400void Context::stencilFillPathInstanced(GLsizei numPaths,
2401 GLenum pathNameType,
2402 const void *paths,
2403 GLuint pathBase,
2404 GLenum fillMode,
2405 GLuint mask,
2406 GLenum transformType,
2407 const GLfloat *transformValues)
2408{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002409 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002410
2411 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002412 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002413
2414 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2415 transformValues);
2416}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002417
Sami Väisänend59ca052016-06-21 16:10:00 +03002418void Context::stencilStrokePathInstanced(GLsizei numPaths,
2419 GLenum pathNameType,
2420 const void *paths,
2421 GLuint pathBase,
2422 GLint reference,
2423 GLuint mask,
2424 GLenum transformType,
2425 const GLfloat *transformValues)
2426{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002427 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002428
2429 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002430 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002431
2432 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2433 transformValues);
2434}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002435
Sami Väisänend59ca052016-06-21 16:10:00 +03002436void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2437 GLenum pathNameType,
2438 const void *paths,
2439 GLuint pathBase,
2440 GLenum fillMode,
2441 GLuint mask,
2442 GLenum coverMode,
2443 GLenum transformType,
2444 const GLfloat *transformValues)
2445{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002446 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002447
2448 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002449 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002450
2451 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2452 transformType, transformValues);
2453}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002454
Sami Väisänend59ca052016-06-21 16:10:00 +03002455void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2456 GLenum pathNameType,
2457 const void *paths,
2458 GLuint pathBase,
2459 GLint reference,
2460 GLuint mask,
2461 GLenum coverMode,
2462 GLenum transformType,
2463 const GLfloat *transformValues)
2464{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002465 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002466
2467 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002468 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002469
2470 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2471 transformType, transformValues);
2472}
2473
Sami Väisänen46eaa942016-06-29 10:26:37 +03002474void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2475{
2476 auto *programObject = getProgram(program);
2477
2478 programObject->bindFragmentInputLocation(location, name);
2479}
2480
2481void Context::programPathFragmentInputGen(GLuint program,
2482 GLint location,
2483 GLenum genMode,
2484 GLint components,
2485 const GLfloat *coeffs)
2486{
2487 auto *programObject = getProgram(program);
2488
Jamie Madillbd044ed2017-06-05 12:59:21 -04002489 programObject->pathFragmentInputGen(this, location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002490}
2491
jchen1015015f72017-03-16 13:54:21 +08002492GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2493{
jchen10fd7c3b52017-03-21 15:36:03 +08002494 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002495 return QueryProgramResourceIndex(programObject, programInterface, name);
2496}
2497
jchen10fd7c3b52017-03-21 15:36:03 +08002498void Context::getProgramResourceName(GLuint program,
2499 GLenum programInterface,
2500 GLuint index,
2501 GLsizei bufSize,
2502 GLsizei *length,
2503 GLchar *name)
2504{
2505 const auto *programObject = getProgram(program);
2506 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2507}
2508
jchen10191381f2017-04-11 13:59:04 +08002509GLint Context::getProgramResourceLocation(GLuint program,
2510 GLenum programInterface,
2511 const GLchar *name)
2512{
2513 const auto *programObject = getProgram(program);
2514 return QueryProgramResourceLocation(programObject, programInterface, name);
2515}
2516
jchen10880683b2017-04-12 16:21:55 +08002517void Context::getProgramResourceiv(GLuint program,
2518 GLenum programInterface,
2519 GLuint index,
2520 GLsizei propCount,
2521 const GLenum *props,
2522 GLsizei bufSize,
2523 GLsizei *length,
2524 GLint *params)
2525{
2526 const auto *programObject = getProgram(program);
2527 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2528 length, params);
2529}
2530
jchen10d9cd7b72017-08-30 15:04:25 +08002531void Context::getProgramInterfaceiv(GLuint program,
2532 GLenum programInterface,
2533 GLenum pname,
2534 GLint *params)
2535{
2536 const auto *programObject = getProgram(program);
2537 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2538}
2539
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002540void Context::getProgramInterfaceivRobust(GLuint program,
2541 GLenum programInterface,
2542 GLenum pname,
2543 GLsizei bufSize,
2544 GLsizei *length,
2545 GLint *params)
2546{
2547 UNIMPLEMENTED();
2548}
2549
Jamie Madill6b873dd2018-07-12 23:56:30 -04002550void Context::handleError(const Error &error)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002551{
Jamie Madill6b873dd2018-07-12 23:56:30 -04002552 mErrors.handleError(error);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002553}
2554
2555// Get one of the recorded errors and clear its flag, if any.
2556// [OpenGL ES 2.0.24] section 2.5 page 13.
2557GLenum Context::getError()
2558{
Geoff Langda5777c2014-07-11 09:52:58 -04002559 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002560 {
Geoff Langda5777c2014-07-11 09:52:58 -04002561 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002562 }
Geoff Langda5777c2014-07-11 09:52:58 -04002563 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002564 {
Jamie Madill6b873dd2018-07-12 23:56:30 -04002565 return mErrors.popError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002566 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002567}
2568
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002569// NOTE: this function should not assume that this context is current!
Jamie Madill6b873dd2018-07-12 23:56:30 -04002570void Context::markContextLost()
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002571{
2572 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002573 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002574 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002575 mContextLostForced = true;
2576 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002577 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002578}
2579
Jamie Madill427064d2018-04-13 16:20:34 -04002580bool Context::isContextLost() const
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002581{
2582 return mContextLost;
2583}
2584
Jamie Madillfa920eb2018-01-04 11:45:50 -05002585GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002586{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002587 // Even if the application doesn't want to know about resets, we want to know
2588 // as it will allow us to skip all the calls.
2589 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002590 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002591 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002592 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002593 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002594 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002595
2596 // EXT_robustness, section 2.6: If the reset notification behavior is
2597 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2598 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2599 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002600 }
2601
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002602 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2603 // status should be returned at least once, and GL_NO_ERROR should be returned
2604 // once the device has finished resetting.
2605 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002606 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002607 ASSERT(mResetStatus == GL_NO_ERROR);
2608 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002609
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002610 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002611 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002612 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002613 }
2614 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002615 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002616 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002617 // If markContextLost was used to mark the context lost then
2618 // assume that is not recoverable, and continue to report the
2619 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002620 mResetStatus = mImplementation->getResetStatus();
2621 }
Jamie Madill893ab082014-05-16 16:56:10 -04002622
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002623 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002624}
2625
2626bool Context::isResetNotificationEnabled()
2627{
2628 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2629}
2630
Corentin Walleze3b10e82015-05-20 11:06:25 -04002631const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002632{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002633 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002634}
2635
2636EGLenum Context::getClientType() const
2637{
2638 return mClientType;
2639}
2640
2641EGLenum Context::getRenderBuffer() const
2642{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002643 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2644 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002645 {
2646 return EGL_NONE;
2647 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002648
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002649 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002650 ASSERT(backAttachment != nullptr);
2651 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002652}
2653
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002654VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002655{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002656 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002657 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2658 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002659 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002660 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2661 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002662
Jamie Madill96a483b2017-06-27 16:49:21 -04002663 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002664 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002665
2666 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002667}
2668
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002669TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002670{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002671 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002672 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2673 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002674 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002675 transformFeedback =
2676 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002677 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002678 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002679 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002680
2681 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002682}
2683
2684bool Context::isVertexArrayGenerated(GLuint vertexArray)
2685{
Jamie Madill96a483b2017-06-27 16:49:21 -04002686 ASSERT(mVertexArrayMap.contains(0));
2687 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002688}
2689
2690bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2691{
Jamie Madill96a483b2017-06-27 16:49:21 -04002692 ASSERT(mTransformFeedbackMap.contains(0));
2693 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002694}
2695
Shannon Woods53a94a82014-06-24 15:20:36 -04002696void Context::detachTexture(GLuint texture)
2697{
2698 // Simple pass-through to State's detachTexture method, as textures do not require
2699 // allocation map management either here or in the resource manager at detach time.
2700 // Zero textures are held by the Context, and we don't attempt to request them from
2701 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002702 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002703}
2704
James Darpinian4d9d4832018-03-13 12:43:28 -07002705void Context::detachBuffer(Buffer *buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002706{
Yuly Novikov5807a532015-12-03 13:01:22 -05002707 // Simple pass-through to State's detachBuffer method, since
2708 // only buffer attachments to container objects that are bound to the current context
2709 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002710
Yuly Novikov5807a532015-12-03 13:01:22 -05002711 // [OpenGL ES 3.2] section 5.1.2 page 45:
2712 // Attachments to unbound container objects, such as
2713 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2714 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002715 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002716}
2717
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002718void Context::detachFramebuffer(GLuint framebuffer)
2719{
Shannon Woods53a94a82014-06-24 15:20:36 -04002720 // Framebuffer detachment is handled by Context, because 0 is a valid
2721 // Framebuffer object, and a pointer to it must be passed from Context
2722 // to State at binding time.
2723
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002724 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002725 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2726 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2727 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002728
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002729 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002730 {
2731 bindReadFramebuffer(0);
2732 }
2733
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002734 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002735 {
2736 bindDrawFramebuffer(0);
2737 }
2738}
2739
2740void Context::detachRenderbuffer(GLuint renderbuffer)
2741{
Jamie Madilla02315b2017-02-23 14:14:47 -05002742 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002743}
2744
Jamie Madill57a89722013-07-02 11:57:03 -04002745void Context::detachVertexArray(GLuint vertexArray)
2746{
Jamie Madill77a72f62015-04-14 11:18:32 -04002747 // Vertex array detachment is handled by Context, because 0 is a valid
2748 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002749 // binding time.
2750
Jamie Madill57a89722013-07-02 11:57:03 -04002751 // [OpenGL ES 3.0.2] section 2.10 page 43:
2752 // If a vertex array object that is currently bound is deleted, the binding
2753 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madill7267aa62018-04-17 15:28:21 -04002754 if (mGLState.removeVertexArrayBinding(this, vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002755 {
2756 bindVertexArray(0);
2757 }
2758}
2759
Geoff Langc8058452014-02-03 12:04:11 -05002760void Context::detachTransformFeedback(GLuint transformFeedback)
2761{
Corentin Walleza2257da2016-04-19 16:43:12 -04002762 // Transform feedback detachment is handled by Context, because 0 is a valid
2763 // transform feedback, and a pointer to it must be passed from Context to State at
2764 // binding time.
2765
2766 // The OpenGL specification doesn't mention what should happen when the currently bound
2767 // transform feedback object is deleted. Since it is a container object, we treat it like
2768 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002769 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002770 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002771 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002772 }
Geoff Langc8058452014-02-03 12:04:11 -05002773}
2774
Jamie Madilldc356042013-07-19 16:36:57 -04002775void Context::detachSampler(GLuint sampler)
2776{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002777 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002778}
2779
Yunchao Hea336b902017-08-02 16:05:21 +08002780void Context::detachProgramPipeline(GLuint pipeline)
2781{
2782 mGLState.detachProgramPipeline(this, pipeline);
2783}
2784
Jamie Madill3ef140a2017-08-26 23:11:21 -04002785void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002786{
Shaodde78e82017-05-22 14:13:27 +08002787 mGLState.setVertexAttribDivisor(this, index, divisor);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002788}
2789
Jamie Madille29d1672013-07-19 16:36:57 -04002790void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2791{
Geoff Langc1984ed2016-10-07 12:41:00 -04002792 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002793 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002794 SetSamplerParameteri(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002795 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002796}
Jamie Madille29d1672013-07-19 16:36:57 -04002797
Geoff Langc1984ed2016-10-07 12:41:00 -04002798void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2799{
2800 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002801 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002802 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002803 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002804}
2805
Brandon Jones59770802018-04-02 13:18:42 -07002806void Context::samplerParameterivRobust(GLuint sampler,
2807 GLenum pname,
2808 GLsizei bufSize,
2809 const GLint *param)
2810{
2811 samplerParameteriv(sampler, pname, param);
2812}
2813
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002814void Context::samplerParameterIivRobust(GLuint sampler,
2815 GLenum pname,
2816 GLsizei bufSize,
2817 const GLint *param)
2818{
2819 UNIMPLEMENTED();
2820}
2821
2822void Context::samplerParameterIuivRobust(GLuint sampler,
2823 GLenum pname,
2824 GLsizei bufSize,
2825 const GLuint *param)
2826{
2827 UNIMPLEMENTED();
2828}
2829
Jamie Madille29d1672013-07-19 16:36:57 -04002830void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2831{
Geoff Langc1984ed2016-10-07 12:41:00 -04002832 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002833 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002834 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002835 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002836}
2837
Geoff Langc1984ed2016-10-07 12:41:00 -04002838void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002839{
Geoff Langc1984ed2016-10-07 12:41:00 -04002840 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002841 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002842 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002843 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002844}
2845
Brandon Jones59770802018-04-02 13:18:42 -07002846void Context::samplerParameterfvRobust(GLuint sampler,
2847 GLenum pname,
2848 GLsizei bufSize,
2849 const GLfloat *param)
2850{
2851 samplerParameterfv(sampler, pname, param);
2852}
2853
Geoff Langc1984ed2016-10-07 12:41:00 -04002854void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002855{
Geoff Langc1984ed2016-10-07 12:41:00 -04002856 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002857 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002858 QuerySamplerParameteriv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002859 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002860}
Jamie Madill9675b802013-07-19 16:36:59 -04002861
Brandon Jones59770802018-04-02 13:18:42 -07002862void Context::getSamplerParameterivRobust(GLuint sampler,
2863 GLenum pname,
2864 GLsizei bufSize,
2865 GLsizei *length,
2866 GLint *params)
2867{
2868 getSamplerParameteriv(sampler, pname, params);
2869}
2870
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002871void Context::getSamplerParameterIivRobust(GLuint sampler,
2872 GLenum pname,
2873 GLsizei bufSize,
2874 GLsizei *length,
2875 GLint *params)
2876{
2877 UNIMPLEMENTED();
2878}
2879
2880void Context::getSamplerParameterIuivRobust(GLuint sampler,
2881 GLenum pname,
2882 GLsizei bufSize,
2883 GLsizei *length,
2884 GLuint *params)
2885{
2886 UNIMPLEMENTED();
2887}
2888
Geoff Langc1984ed2016-10-07 12:41:00 -04002889void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2890{
2891 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002892 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002893 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002894 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002895}
2896
Brandon Jones59770802018-04-02 13:18:42 -07002897void Context::getSamplerParameterfvRobust(GLuint sampler,
2898 GLenum pname,
2899 GLsizei bufSize,
2900 GLsizei *length,
2901 GLfloat *params)
2902{
2903 getSamplerParameterfv(sampler, pname, params);
2904}
2905
Olli Etuahof0fee072016-03-30 15:11:58 +03002906void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2907{
2908 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002909 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002910}
2911
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002912void Context::initRendererString()
2913{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002914 std::ostringstream rendererString;
2915 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002916 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002917 rendererString << ")";
2918
Geoff Langcec35902014-04-16 10:52:36 -04002919 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002920}
2921
Geoff Langc339c4e2016-11-29 10:37:36 -05002922void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002923{
Geoff Langc339c4e2016-11-29 10:37:36 -05002924 const Version &clientVersion = getClientVersion();
2925
2926 std::ostringstream versionString;
2927 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2928 << ANGLE_VERSION_STRING << ")";
2929 mVersionString = MakeStaticString(versionString.str());
2930
2931 std::ostringstream shadingLanguageVersionString;
2932 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2933 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2934 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2935 << ")";
2936 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002937}
2938
Geoff Langcec35902014-04-16 10:52:36 -04002939void Context::initExtensionStrings()
2940{
Geoff Langc339c4e2016-11-29 10:37:36 -05002941 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2942 std::ostringstream combinedStringStream;
2943 std::copy(strings.begin(), strings.end(),
2944 std::ostream_iterator<const char *>(combinedStringStream, " "));
2945 return MakeStaticString(combinedStringStream.str());
2946 };
2947
2948 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002949 for (const auto &extensionString : mExtensions.getStrings())
2950 {
2951 mExtensionStrings.push_back(MakeStaticString(extensionString));
2952 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002953 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002954
Geoff Langc339c4e2016-11-29 10:37:36 -05002955 mRequestableExtensionStrings.clear();
2956 for (const auto &extensionInfo : GetExtensionInfoMap())
2957 {
2958 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08002959 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
Geoff Langb0f917f2017-12-05 13:41:54 -05002960 mSupportedExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002961 {
2962 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
2963 }
2964 }
2965 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002966}
2967
Geoff Langc339c4e2016-11-29 10:37:36 -05002968const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04002969{
Geoff Langc339c4e2016-11-29 10:37:36 -05002970 switch (name)
2971 {
2972 case GL_VENDOR:
2973 return reinterpret_cast<const GLubyte *>("Google Inc.");
2974
2975 case GL_RENDERER:
2976 return reinterpret_cast<const GLubyte *>(mRendererString);
2977
2978 case GL_VERSION:
2979 return reinterpret_cast<const GLubyte *>(mVersionString);
2980
2981 case GL_SHADING_LANGUAGE_VERSION:
2982 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
2983
2984 case GL_EXTENSIONS:
2985 return reinterpret_cast<const GLubyte *>(mExtensionString);
2986
2987 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2988 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
2989
2990 default:
2991 UNREACHABLE();
2992 return nullptr;
2993 }
Geoff Langcec35902014-04-16 10:52:36 -04002994}
2995
Geoff Langc339c4e2016-11-29 10:37:36 -05002996const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04002997{
Geoff Langc339c4e2016-11-29 10:37:36 -05002998 switch (name)
2999 {
3000 case GL_EXTENSIONS:
3001 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
3002
3003 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
3004 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
3005
3006 default:
3007 UNREACHABLE();
3008 return nullptr;
3009 }
Geoff Langcec35902014-04-16 10:52:36 -04003010}
3011
3012size_t Context::getExtensionStringCount() const
3013{
3014 return mExtensionStrings.size();
3015}
3016
Geoff Lang111a99e2017-10-17 10:58:41 -04003017bool Context::isExtensionRequestable(const char *name)
3018{
3019 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3020 auto extension = extensionInfos.find(name);
3021
Geoff Lang111a99e2017-10-17 10:58:41 -04003022 return extension != extensionInfos.end() && extension->second.Requestable &&
Geoff Langb0f917f2017-12-05 13:41:54 -05003023 mSupportedExtensions.*(extension->second.ExtensionsMember);
Geoff Lang111a99e2017-10-17 10:58:41 -04003024}
3025
Geoff Langc339c4e2016-11-29 10:37:36 -05003026void Context::requestExtension(const char *name)
3027{
3028 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3029 ASSERT(extensionInfos.find(name) != extensionInfos.end());
3030 const auto &extension = extensionInfos.at(name);
3031 ASSERT(extension.Requestable);
Geoff Langb0f917f2017-12-05 13:41:54 -05003032 ASSERT(isExtensionRequestable(name));
Geoff Langc339c4e2016-11-29 10:37:36 -05003033
3034 if (mExtensions.*(extension.ExtensionsMember))
3035 {
3036 // Extension already enabled
3037 return;
3038 }
3039
3040 mExtensions.*(extension.ExtensionsMember) = true;
3041 updateCaps();
3042 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08003043
Jamie Madill2f348d22017-06-05 10:50:59 -04003044 // Release the shader compiler so it will be re-created with the requested extensions enabled.
3045 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04003046
Jamie Madill81c2e252017-09-09 23:32:46 -04003047 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
3048 // sampleable.
Jamie Madilld4442552018-02-27 22:03:47 -05003049 mState.mTextures->signalAllTexturesDirty(this);
Geoff Lang9aded172017-04-05 11:07:56 -04003050 for (auto &zeroTexture : mZeroTextures)
3051 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003052 if (zeroTexture.get() != nullptr)
3053 {
3054 zeroTexture->signalDirty(this, InitState::Initialized);
3055 }
Geoff Lang9aded172017-04-05 11:07:56 -04003056 }
3057
3058 mState.mFramebuffers->invalidateFramebufferComplenessCache();
Geoff Langc339c4e2016-11-29 10:37:36 -05003059}
3060
3061size_t Context::getRequestableExtensionStringCount() const
3062{
3063 return mRequestableExtensionStrings.size();
3064}
3065
Jamie Madill493f9572018-05-24 19:52:15 -04003066void Context::beginTransformFeedback(PrimitiveMode primitiveMode)
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003067{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003068 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003069 ASSERT(transformFeedback != nullptr);
3070 ASSERT(!transformFeedback->isPaused());
3071
Jamie Madill6c1f6712017-02-14 19:08:04 -05003072 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003073}
3074
3075bool Context::hasActiveTransformFeedback(GLuint program) const
3076{
3077 for (auto pair : mTransformFeedbackMap)
3078 {
3079 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
3080 {
3081 return true;
3082 }
3083 }
3084 return false;
3085}
3086
Geoff Lang33f11fb2018-05-07 13:42:47 -04003087Extensions Context::generateSupportedExtensions() const
Geoff Langb0f917f2017-12-05 13:41:54 -05003088{
3089 Extensions supportedExtensions = mImplementation->getNativeExtensions();
3090
jchen1082af6202018-06-22 10:59:52 +08003091 // Explicitly enable GL_KHR_parallel_shader_compile
3092 supportedExtensions.parallelShaderCompile = true;
3093
Geoff Langb0f917f2017-12-05 13:41:54 -05003094 if (getClientVersion() < ES_2_0)
3095 {
3096 // Default extensions for GLES1
Lingfeng Yang0df813c2018-07-12 12:52:06 -07003097 supportedExtensions.pointSizeArray = true;
3098 supportedExtensions.textureCubeMap = true;
3099 supportedExtensions.pointSprite = true;
3100 supportedExtensions.drawTexture = true;
jchen1082af6202018-06-22 10:59:52 +08003101 supportedExtensions.parallelShaderCompile = false;
Geoff Langb0f917f2017-12-05 13:41:54 -05003102 }
3103
3104 if (getClientVersion() < ES_3_0)
3105 {
3106 // Disable ES3+ extensions
3107 supportedExtensions.colorBufferFloat = false;
3108 supportedExtensions.eglImageExternalEssl3 = false;
3109 supportedExtensions.textureNorm16 = false;
3110 supportedExtensions.multiview = false;
3111 supportedExtensions.maxViews = 1u;
3112 }
3113
3114 if (getClientVersion() < ES_3_1)
3115 {
3116 // Disable ES3.1+ extensions
3117 supportedExtensions.geometryShader = false;
3118 }
3119
3120 if (getClientVersion() > ES_2_0)
3121 {
3122 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
3123 // supportedExtensions.sRGB = false;
3124 }
3125
3126 // Some extensions are always available because they are implemented in the GL layer.
3127 supportedExtensions.bindUniformLocation = true;
3128 supportedExtensions.vertexArrayObject = true;
3129 supportedExtensions.bindGeneratesResource = true;
3130 supportedExtensions.clientArrays = true;
3131 supportedExtensions.requestExtension = true;
3132
3133 // Enable the no error extension if the context was created with the flag.
3134 supportedExtensions.noError = mSkipValidation;
3135
3136 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Geoff Lang33f11fb2018-05-07 13:42:47 -04003137 supportedExtensions.surfacelessContext = mSurfacelessSupported;
Geoff Langb0f917f2017-12-05 13:41:54 -05003138
3139 // Explicitly enable GL_KHR_debug
3140 supportedExtensions.debug = true;
3141 supportedExtensions.maxDebugMessageLength = 1024;
3142 supportedExtensions.maxDebugLoggedMessages = 1024;
3143 supportedExtensions.maxDebugGroupStackDepth = 1024;
3144 supportedExtensions.maxLabelLength = 1024;
3145
3146 // Explicitly enable GL_ANGLE_robust_client_memory
3147 supportedExtensions.robustClientMemory = true;
3148
3149 // Determine robust resource init availability from EGL.
Geoff Lang33f11fb2018-05-07 13:42:47 -04003150 supportedExtensions.robustResourceInitialization = mGLState.isRobustResourceInitEnabled();
Geoff Langb0f917f2017-12-05 13:41:54 -05003151
3152 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
3153 // supports it.
3154 supportedExtensions.robustBufferAccessBehavior =
3155 mRobustAccess && supportedExtensions.robustBufferAccessBehavior;
3156
3157 // Enable the cache control query unconditionally.
3158 supportedExtensions.programCacheControl = true;
3159
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003160 // Enable EGL_ANGLE_explicit_context subextensions
Geoff Lang33f11fb2018-05-07 13:42:47 -04003161 if (mExplicitContextAvailable)
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003162 {
3163 // GL_ANGLE_explicit_context_gles1
3164 supportedExtensions.explicitContextGles1 = true;
3165 // GL_ANGLE_explicit_context
3166 supportedExtensions.explicitContext = true;
3167 }
3168
Geoff Langb0f917f2017-12-05 13:41:54 -05003169 return supportedExtensions;
3170}
3171
Geoff Lang33f11fb2018-05-07 13:42:47 -04003172void Context::initCaps()
Geoff Lang493daf52014-07-03 13:38:44 -04003173{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04003174 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04003175
Geoff Lang33f11fb2018-05-07 13:42:47 -04003176 mSupportedExtensions = generateSupportedExtensions();
3177 mExtensions = mSupportedExtensions;
Lingfeng Yang01074432018-04-16 10:19:51 -07003178
3179 mLimitations = mImplementation->getNativeLimitations();
3180
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003181 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
3182 if (getClientVersion() < Version(2, 0))
3183 {
3184 mCaps.maxMultitextureUnits = 4;
3185 mCaps.maxClipPlanes = 6;
3186 mCaps.maxLights = 8;
Lingfeng Yange547aac2018-04-05 09:39:20 -07003187 mCaps.maxModelviewMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3188 mCaps.maxProjectionMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3189 mCaps.maxTextureMatrixStackDepth = Caps::GlobalMatrixStackDepth;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003190 mCaps.minSmoothPointSize = 1.0f;
3191 mCaps.maxSmoothPointSize = 1.0f;
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003192 }
3193
Luc Ferronad2ae932018-06-11 15:31:17 -04003194 // Apply/Verify implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04003195 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003196
Luc Ferronad2ae932018-06-11 15:31:17 -04003197 ASSERT(mCaps.minAliasedPointSize >= 1.0f);
3198
Jamie Madill0f80ed82017-09-19 00:24:56 -04003199 if (getClientVersion() < ES_3_1)
3200 {
3201 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
3202 }
3203 else
3204 {
3205 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
3206 }
Geoff Lang301d1612014-07-09 10:34:37 -04003207
Jiawei Shao54aafe52018-04-27 14:54:57 +08003208 LimitCap(&mCaps.maxShaderUniformBlocks[ShaderType::Vertex],
3209 IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
Jamie Madill0f80ed82017-09-19 00:24:56 -04003210 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3211 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3212
3213 // Limit textures as well, so we can use fast bitsets with texture bindings.
3214 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
Jiawei Shao54aafe52018-04-27 14:54:57 +08003215 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Vertex],
3216 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
3217 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Fragment],
3218 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04003219
Jiawei Shaodb342272017-09-27 10:21:45 +08003220 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
3221
Geoff Langc287ea62016-09-16 14:46:51 -04003222 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05003223 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04003224 for (const auto &extensionInfo : GetExtensionInfoMap())
3225 {
Geoff Lang0ab41fa2018-03-14 11:03:30 -04003226 // If the user has requested that extensions start disabled and they are requestable,
3227 // disable them.
3228 if (!mExtensionsEnabled && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04003229 {
3230 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
3231 }
3232 }
3233
3234 // Generate texture caps
3235 updateCaps();
3236}
3237
3238void Context::updateCaps()
3239{
Geoff Lang900013c2014-07-07 11:32:19 -04003240 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04003241 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04003242
Jamie Madill7b62cf92017-11-02 15:20:49 -04003243 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04003244 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04003245 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04003246 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003247
Geoff Lang0d8b7242015-09-09 14:56:53 -04003248 // Update the format caps based on the client version and extensions.
3249 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
3250 // ES3.
3251 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003252 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04003253 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003254 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Yuly Novikovf15f8862018-06-04 18:59:41 -04003255 formatCaps.textureAttachment =
3256 formatCaps.textureAttachment &&
3257 formatInfo.textureAttachmentSupport(getClientVersion(), mExtensions);
3258 formatCaps.renderbuffer = formatCaps.renderbuffer &&
3259 formatInfo.renderbufferSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04003260
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003261 // OpenGL ES does not support multisampling with non-rendererable formats
3262 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Yuly Novikovf15f8862018-06-04 18:59:41 -04003263 if (!formatCaps.renderbuffer ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003264 (getClientVersion() < ES_3_1 &&
3265 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04003266 {
Geoff Langd87878e2014-09-19 15:42:59 -04003267 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04003268 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03003269 else
3270 {
3271 // We may have limited the max samples for some required renderbuffer formats due to
3272 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
3273 GLuint formatMaxSamples = formatCaps.getMaxSamples();
3274
3275 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
3276 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
3277 // exception of signed and unsigned integer formats."
3278 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
3279 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
3280 {
3281 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
3282 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
3283 }
3284
3285 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
3286 if (getClientVersion() >= ES_3_1)
3287 {
3288 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
3289 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
3290 // the exception that the signed and unsigned integer formats are required only to
3291 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
3292 // multisamples, which must be at least one."
3293 if (formatInfo.componentType == GL_INT ||
3294 formatInfo.componentType == GL_UNSIGNED_INT)
3295 {
3296 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
3297 }
3298
3299 // GLES 3.1 section 19.3.1.
3300 if (formatCaps.texturable)
3301 {
3302 if (formatInfo.depthBits > 0)
3303 {
3304 mCaps.maxDepthTextureSamples =
3305 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
3306 }
3307 else if (formatInfo.redBits > 0)
3308 {
3309 mCaps.maxColorTextureSamples =
3310 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
3311 }
3312 }
3313 }
3314 }
Geoff Langd87878e2014-09-19 15:42:59 -04003315
3316 if (formatCaps.texturable && formatInfo.compressed)
3317 {
Geoff Langca271392017-04-05 12:30:00 -04003318 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003319 }
3320
Geoff Langca271392017-04-05 12:30:00 -04003321 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04003322 }
Jamie Madill32447362017-06-28 14:53:52 -04003323
3324 // If program binary is disabled, blank out the memory cache pointer.
Geoff Langb0f917f2017-12-05 13:41:54 -05003325 if (!mSupportedExtensions.getProgramBinary)
Jamie Madill32447362017-06-28 14:53:52 -04003326 {
3327 mMemoryProgramCache = nullptr;
3328 }
Corentin Walleze4477002017-12-01 14:39:58 -05003329
3330 // Compute which buffer types are allowed
3331 mValidBufferBindings.reset();
3332 mValidBufferBindings.set(BufferBinding::ElementArray);
3333 mValidBufferBindings.set(BufferBinding::Array);
3334
3335 if (mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
3336 {
3337 mValidBufferBindings.set(BufferBinding::PixelPack);
3338 mValidBufferBindings.set(BufferBinding::PixelUnpack);
3339 }
3340
3341 if (getClientVersion() >= ES_3_0)
3342 {
3343 mValidBufferBindings.set(BufferBinding::CopyRead);
3344 mValidBufferBindings.set(BufferBinding::CopyWrite);
3345 mValidBufferBindings.set(BufferBinding::TransformFeedback);
3346 mValidBufferBindings.set(BufferBinding::Uniform);
3347 }
3348
3349 if (getClientVersion() >= ES_3_1)
3350 {
3351 mValidBufferBindings.set(BufferBinding::AtomicCounter);
3352 mValidBufferBindings.set(BufferBinding::ShaderStorage);
3353 mValidBufferBindings.set(BufferBinding::DrawIndirect);
3354 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
3355 }
Geoff Lang493daf52014-07-03 13:38:44 -04003356}
3357
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003358void Context::initWorkarounds()
3359{
Jamie Madill761b02c2017-06-23 16:27:06 -04003360 // Apply back-end workarounds.
3361 mImplementation->applyNativeWorkarounds(&mWorkarounds);
3362
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003363 // Lose the context upon out of memory error if the application is
3364 // expecting to watch for those events.
3365 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
3366}
3367
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06003368// Return true if the draw is a no-op, else return false.
3369// A no-op draw occurs if the count of vertices is less than the minimum required to
3370// have a valid primitive for this mode (0 for points, 0-1 for lines, 0-2 for tris).
3371bool Context::noopDraw(PrimitiveMode mode, GLsizei count)
3372{
3373 return count < kMinimumPrimitiveCounts[mode];
3374}
3375
3376bool Context::noopDrawInstanced(PrimitiveMode mode, GLsizei count, GLsizei instanceCount)
3377{
3378 return (instanceCount == 0) || noopDraw(mode, count);
3379}
3380
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003381Error Context::prepareForDraw(PrimitiveMode mode)
Jamie Madill05b35b22017-10-03 09:01:44 -04003382{
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003383 if (mGLES1Renderer)
3384 {
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003385 ANGLE_TRY(mGLES1Renderer->prepareForDraw(mode, this, &mGLState));
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003386 }
3387
Geoff Langa8cb2872018-03-09 16:09:40 -05003388 ANGLE_TRY(syncDirtyObjects());
Jamie Madilla59fc192017-11-02 12:57:58 -04003389
3390 if (isRobustResourceInitEnabled())
3391 {
3392 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
3393 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
3394 }
3395
Geoff Langa8cb2872018-03-09 16:09:40 -05003396 ANGLE_TRY(syncDirtyBits());
Geoff Langd4fff502017-09-22 11:28:28 -04003397 return NoError();
3398}
3399
3400Error Context::prepareForClear(GLbitfield mask)
3401{
Geoff Langa8cb2872018-03-09 16:09:40 -05003402 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003403 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearAttachmentsInitialized(this, mask));
Geoff Langa8cb2872018-03-09 16:09:40 -05003404 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04003405 return NoError();
3406}
3407
3408Error Context::prepareForClearBuffer(GLenum buffer, GLint drawbuffer)
3409{
Geoff Langa8cb2872018-03-09 16:09:40 -05003410 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003411 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearBufferAttachmentsInitialized(this, buffer,
3412 drawbuffer));
Geoff Langa8cb2872018-03-09 16:09:40 -05003413 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill05b35b22017-10-03 09:01:44 -04003414 return NoError();
3415}
3416
Geoff Langa8cb2872018-03-09 16:09:40 -05003417Error Context::syncState()
Jamie Madill1b94d432015-08-07 13:23:23 -04003418{
Geoff Langa8cb2872018-03-09 16:09:40 -05003419 ANGLE_TRY(syncDirtyObjects());
3420 ANGLE_TRY(syncDirtyBits());
Jamie Madillbc918e72018-03-08 09:47:21 -05003421 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003422}
3423
Geoff Langa8cb2872018-03-09 16:09:40 -05003424Error Context::syncState(const State::DirtyBits &bitMask, const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04003425{
Geoff Langa8cb2872018-03-09 16:09:40 -05003426 ANGLE_TRY(syncDirtyObjects(objectMask));
3427 ANGLE_TRY(syncDirtyBits(bitMask));
Geoff Langd4fff502017-09-22 11:28:28 -04003428 return NoError();
3429}
3430
Geoff Langa8cb2872018-03-09 16:09:40 -05003431Error Context::syncDirtyBits()
Geoff Langd4fff502017-09-22 11:28:28 -04003432{
3433 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
Jamie Madill189ad872018-07-09 13:32:37 -04003434 ANGLE_TRY(mImplementation->syncState(this, dirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04003435 mGLState.clearDirtyBits();
3436 return NoError();
3437}
3438
Geoff Langa8cb2872018-03-09 16:09:40 -05003439Error Context::syncDirtyBits(const State::DirtyBits &bitMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003440{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003441 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madill189ad872018-07-09 13:32:37 -04003442 ANGLE_TRY(mImplementation->syncState(this, dirtyBits));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003443 mGLState.clearDirtyBits(dirtyBits);
Jamie Madillbc918e72018-03-08 09:47:21 -05003444 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003445}
Jamie Madillc29968b2016-01-20 11:17:23 -05003446
Geoff Langa8cb2872018-03-09 16:09:40 -05003447Error Context::syncDirtyObjects()
Geoff Langd4fff502017-09-22 11:28:28 -04003448{
3449 return mGLState.syncDirtyObjects(this);
3450}
3451
Geoff Langa8cb2872018-03-09 16:09:40 -05003452Error Context::syncDirtyObjects(const State::DirtyObjects &objectMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003453{
3454 return mGLState.syncDirtyObjects(this, objectMask);
3455}
3456
Jamie Madillc29968b2016-01-20 11:17:23 -05003457void Context::blitFramebuffer(GLint srcX0,
3458 GLint srcY0,
3459 GLint srcX1,
3460 GLint srcY1,
3461 GLint dstX0,
3462 GLint dstY0,
3463 GLint dstX1,
3464 GLint dstY1,
3465 GLbitfield mask,
3466 GLenum filter)
3467{
Qin Jiajiaaef92162018-02-27 13:51:44 +08003468 if (mask == 0)
3469 {
3470 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
3471 // buffers are copied.
3472 return;
3473 }
3474
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003475 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003476 ASSERT(drawFramebuffer);
3477
3478 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
3479 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
3480
Jamie Madillbc918e72018-03-08 09:47:21 -05003481 ANGLE_CONTEXT_TRY(syncStateForBlit());
Jamie Madillc29968b2016-01-20 11:17:23 -05003482
Jamie Madillc564c072017-06-01 12:45:42 -04003483 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003484}
Jamie Madillc29968b2016-01-20 11:17:23 -05003485
3486void Context::clear(GLbitfield mask)
3487{
Geoff Langd4fff502017-09-22 11:28:28 -04003488 ANGLE_CONTEXT_TRY(prepareForClear(mask));
3489 ANGLE_CONTEXT_TRY(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05003490}
3491
3492void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
3493{
Geoff Langd4fff502017-09-22 11:28:28 -04003494 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3495 ANGLE_CONTEXT_TRY(
3496 mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003497}
3498
3499void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3500{
Geoff Langd4fff502017-09-22 11:28:28 -04003501 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3502 ANGLE_CONTEXT_TRY(
3503 mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003504}
3505
3506void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3507{
Geoff Langd4fff502017-09-22 11:28:28 -04003508 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3509 ANGLE_CONTEXT_TRY(
3510 mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003511}
3512
3513void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3514{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003515 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003516 ASSERT(framebufferObject);
3517
3518 // If a buffer is not present, the clear has no effect
3519 if (framebufferObject->getDepthbuffer() == nullptr &&
3520 framebufferObject->getStencilbuffer() == nullptr)
3521 {
3522 return;
3523 }
3524
Geoff Langd4fff502017-09-22 11:28:28 -04003525 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3526 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003527}
3528
3529void Context::readPixels(GLint x,
3530 GLint y,
3531 GLsizei width,
3532 GLsizei height,
3533 GLenum format,
3534 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003535 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003536{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003537 if (width == 0 || height == 0)
3538 {
3539 return;
3540 }
3541
Jamie Madillbc918e72018-03-08 09:47:21 -05003542 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003543
Jamie Madillb6664922017-07-25 12:55:04 -04003544 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3545 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003546
3547 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04003548 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003549}
3550
Brandon Jones59770802018-04-02 13:18:42 -07003551void Context::readPixelsRobust(GLint x,
3552 GLint y,
3553 GLsizei width,
3554 GLsizei height,
3555 GLenum format,
3556 GLenum type,
3557 GLsizei bufSize,
3558 GLsizei *length,
3559 GLsizei *columns,
3560 GLsizei *rows,
3561 void *pixels)
3562{
3563 readPixels(x, y, width, height, format, type, pixels);
3564}
3565
3566void Context::readnPixelsRobust(GLint x,
3567 GLint y,
3568 GLsizei width,
3569 GLsizei height,
3570 GLenum format,
3571 GLenum type,
3572 GLsizei bufSize,
3573 GLsizei *length,
3574 GLsizei *columns,
3575 GLsizei *rows,
3576 void *data)
3577{
3578 readPixels(x, y, width, height, format, type, data);
3579}
3580
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003581void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003582 GLint level,
3583 GLenum internalformat,
3584 GLint x,
3585 GLint y,
3586 GLsizei width,
3587 GLsizei height,
3588 GLint border)
3589{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003590 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003591 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003592
Jamie Madillc29968b2016-01-20 11:17:23 -05003593 Rectangle sourceArea(x, y, width, height);
3594
Jamie Madill05b35b22017-10-03 09:01:44 -04003595 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003596 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003597 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003598}
3599
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003600void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003601 GLint level,
3602 GLint xoffset,
3603 GLint yoffset,
3604 GLint x,
3605 GLint y,
3606 GLsizei width,
3607 GLsizei height)
3608{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003609 if (width == 0 || height == 0)
3610 {
3611 return;
3612 }
3613
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003614 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003615 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003616
Jamie Madillc29968b2016-01-20 11:17:23 -05003617 Offset destOffset(xoffset, yoffset, 0);
3618 Rectangle sourceArea(x, y, width, height);
3619
Jamie Madill05b35b22017-10-03 09:01:44 -04003620 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003621 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003622 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003623}
3624
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003625void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003626 GLint level,
3627 GLint xoffset,
3628 GLint yoffset,
3629 GLint zoffset,
3630 GLint x,
3631 GLint y,
3632 GLsizei width,
3633 GLsizei height)
3634{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003635 if (width == 0 || height == 0)
3636 {
3637 return;
3638 }
3639
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003640 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003641 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003642
Jamie Madillc29968b2016-01-20 11:17:23 -05003643 Offset destOffset(xoffset, yoffset, zoffset);
3644 Rectangle sourceArea(x, y, width, height);
3645
Jamie Madill05b35b22017-10-03 09:01:44 -04003646 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3647 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003648 handleError(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level, destOffset,
3649 sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003650}
3651
3652void Context::framebufferTexture2D(GLenum target,
3653 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003654 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003655 GLuint texture,
3656 GLint level)
3657{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003658 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003659 ASSERT(framebuffer);
3660
3661 if (texture != 0)
3662 {
3663 Texture *textureObj = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003664 ImageIndex index = ImageIndex::MakeFromTarget(textarget, level);
Jamie Madilla02315b2017-02-23 14:14:47 -05003665 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003666 }
3667 else
3668 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003669 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003670 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003671
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003672 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003673}
3674
3675void Context::framebufferRenderbuffer(GLenum target,
3676 GLenum attachment,
3677 GLenum renderbuffertarget,
3678 GLuint renderbuffer)
3679{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003680 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003681 ASSERT(framebuffer);
3682
3683 if (renderbuffer != 0)
3684 {
3685 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003686
Jamie Madillcc129372018-04-12 09:13:18 -04003687 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003688 renderbufferObject);
3689 }
3690 else
3691 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003692 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003693 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003694
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003695 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003696}
3697
3698void Context::framebufferTextureLayer(GLenum target,
3699 GLenum attachment,
3700 GLuint texture,
3701 GLint level,
3702 GLint layer)
3703{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003704 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003705 ASSERT(framebuffer);
3706
3707 if (texture != 0)
3708 {
3709 Texture *textureObject = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003710 ImageIndex index = ImageIndex::MakeFromType(textureObject->getType(), level, layer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003711 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003712 }
3713 else
3714 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003715 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003716 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003717
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003718 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003719}
3720
Brandon Jones59770802018-04-02 13:18:42 -07003721void Context::framebufferTextureMultiviewLayered(GLenum target,
3722 GLenum attachment,
3723 GLuint texture,
3724 GLint level,
3725 GLint baseViewIndex,
3726 GLsizei numViews)
Martin Radev137032d2017-07-13 10:11:12 +03003727{
Martin Radev82ef7742017-08-08 17:44:58 +03003728 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3729 ASSERT(framebuffer);
3730
3731 if (texture != 0)
3732 {
3733 Texture *textureObj = getTexture(texture);
3734
Martin Radev18b75ba2017-08-15 15:50:40 +03003735 ImageIndex index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
Martin Radev82ef7742017-08-08 17:44:58 +03003736 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3737 numViews, baseViewIndex);
3738 }
3739 else
3740 {
3741 framebuffer->resetAttachment(this, attachment);
3742 }
3743
3744 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003745}
3746
Brandon Jones59770802018-04-02 13:18:42 -07003747void Context::framebufferTextureMultiviewSideBySide(GLenum target,
3748 GLenum attachment,
3749 GLuint texture,
3750 GLint level,
3751 GLsizei numViews,
3752 const GLint *viewportOffsets)
Martin Radev137032d2017-07-13 10:11:12 +03003753{
Martin Radev5dae57b2017-07-14 16:15:55 +03003754 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3755 ASSERT(framebuffer);
3756
3757 if (texture != 0)
3758 {
3759 Texture *textureObj = getTexture(texture);
3760
3761 ImageIndex index = ImageIndex::Make2D(level);
3762 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3763 textureObj, numViews, viewportOffsets);
3764 }
3765 else
3766 {
3767 framebuffer->resetAttachment(this, attachment);
3768 }
3769
3770 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003771}
3772
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003773void Context::framebufferTexture(GLenum target, GLenum attachment, GLuint texture, GLint level)
3774{
Jiawei Shaoa8802472018-05-28 11:17:47 +08003775 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3776 ASSERT(framebuffer);
3777
3778 if (texture != 0)
3779 {
3780 Texture *textureObj = getTexture(texture);
3781
3782 ImageIndex index = ImageIndex::MakeFromType(
3783 textureObj->getType(), level, ImageIndex::kEntireLevel, ImageIndex::kEntireLevel);
3784 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
3785 }
3786 else
3787 {
3788 framebuffer->resetAttachment(this, attachment);
3789 }
3790
3791 mGLState.setObjectDirty(target);
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003792}
3793
Jamie Madillc29968b2016-01-20 11:17:23 -05003794void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3795{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003796 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003797 ASSERT(framebuffer);
3798 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003799 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003800}
3801
3802void Context::readBuffer(GLenum mode)
3803{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003804 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003805 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003806 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003807}
3808
3809void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3810{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003811 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003812 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003813
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003814 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003815 ASSERT(framebuffer);
3816
3817 // The specification isn't clear what should be done when the framebuffer isn't complete.
3818 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003819 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003820}
3821
3822void Context::invalidateFramebuffer(GLenum target,
3823 GLsizei numAttachments,
3824 const GLenum *attachments)
3825{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003826 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003827 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003828
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003829 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003830 ASSERT(framebuffer);
3831
Jamie Madill427064d2018-04-13 16:20:34 -04003832 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003833 {
Jamie Madill437fa652016-05-03 15:13:24 -04003834 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003835 }
Jamie Madill437fa652016-05-03 15:13:24 -04003836
Jamie Madill4928b7c2017-06-20 12:57:39 -04003837 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003838}
3839
3840void Context::invalidateSubFramebuffer(GLenum target,
3841 GLsizei numAttachments,
3842 const GLenum *attachments,
3843 GLint x,
3844 GLint y,
3845 GLsizei width,
3846 GLsizei height)
3847{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003848 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003849 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003850
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003851 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003852 ASSERT(framebuffer);
3853
Jamie Madill427064d2018-04-13 16:20:34 -04003854 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003855 {
Jamie Madill437fa652016-05-03 15:13:24 -04003856 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003857 }
Jamie Madill437fa652016-05-03 15:13:24 -04003858
3859 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003860 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003861}
3862
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003863void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003864 GLint level,
3865 GLint internalformat,
3866 GLsizei width,
3867 GLsizei height,
3868 GLint border,
3869 GLenum format,
3870 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003871 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003872{
Jamie Madillbc918e72018-03-08 09:47:21 -05003873 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003874
3875 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003876 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003877 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003878 size, format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003879}
3880
Brandon Jones59770802018-04-02 13:18:42 -07003881void Context::texImage2DRobust(TextureTarget target,
3882 GLint level,
3883 GLint internalformat,
3884 GLsizei width,
3885 GLsizei height,
3886 GLint border,
3887 GLenum format,
3888 GLenum type,
3889 GLsizei bufSize,
3890 const void *pixels)
3891{
3892 texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
3893}
3894
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003895void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003896 GLint level,
3897 GLint internalformat,
3898 GLsizei width,
3899 GLsizei height,
3900 GLsizei depth,
3901 GLint border,
3902 GLenum format,
3903 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003904 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003905{
Jamie Madillbc918e72018-03-08 09:47:21 -05003906 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003907
3908 Extents size(width, height, depth);
3909 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003910 handleError(texture->setImage(this, mGLState.getUnpackState(),
3911 NonCubeTextureTypeToTarget(target), level, internalformat, size,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003912 format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003913}
3914
Brandon Jones59770802018-04-02 13:18:42 -07003915void Context::texImage3DRobust(TextureType target,
3916 GLint level,
3917 GLint internalformat,
3918 GLsizei width,
3919 GLsizei height,
3920 GLsizei depth,
3921 GLint border,
3922 GLenum format,
3923 GLenum type,
3924 GLsizei bufSize,
3925 const void *pixels)
3926{
3927 texImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels);
3928}
3929
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003930void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003931 GLint level,
3932 GLint xoffset,
3933 GLint yoffset,
3934 GLsizei width,
3935 GLsizei height,
3936 GLenum format,
3937 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003938 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003939{
3940 // Zero sized uploads are valid but no-ops
3941 if (width == 0 || height == 0)
3942 {
3943 return;
3944 }
3945
Jamie Madillbc918e72018-03-08 09:47:21 -05003946 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003947
3948 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003949 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003950 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003951 type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003952}
3953
Brandon Jones59770802018-04-02 13:18:42 -07003954void Context::texSubImage2DRobust(TextureTarget target,
3955 GLint level,
3956 GLint xoffset,
3957 GLint yoffset,
3958 GLsizei width,
3959 GLsizei height,
3960 GLenum format,
3961 GLenum type,
3962 GLsizei bufSize,
3963 const void *pixels)
3964{
3965 texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
3966}
3967
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003968void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003969 GLint level,
3970 GLint xoffset,
3971 GLint yoffset,
3972 GLint zoffset,
3973 GLsizei width,
3974 GLsizei height,
3975 GLsizei depth,
3976 GLenum format,
3977 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003978 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003979{
3980 // Zero sized uploads are valid but no-ops
3981 if (width == 0 || height == 0 || depth == 0)
3982 {
3983 return;
3984 }
3985
Jamie Madillbc918e72018-03-08 09:47:21 -05003986 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003987
3988 Box area(xoffset, yoffset, zoffset, width, height, depth);
3989 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003990 handleError(texture->setSubImage(this, mGLState.getUnpackState(),
3991 NonCubeTextureTypeToTarget(target), level, area, format, type,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003992 static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003993}
3994
Brandon Jones59770802018-04-02 13:18:42 -07003995void Context::texSubImage3DRobust(TextureType target,
3996 GLint level,
3997 GLint xoffset,
3998 GLint yoffset,
3999 GLint zoffset,
4000 GLsizei width,
4001 GLsizei height,
4002 GLsizei depth,
4003 GLenum format,
4004 GLenum type,
4005 GLsizei bufSize,
4006 const void *pixels)
4007{
4008 texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type,
4009 pixels);
4010}
4011
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004012void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004013 GLint level,
4014 GLenum internalformat,
4015 GLsizei width,
4016 GLsizei height,
4017 GLint border,
4018 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004019 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004020{
Jamie Madillbc918e72018-03-08 09:47:21 -05004021 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004022
4023 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004024 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05004025 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
4026 internalformat, size, imageSize,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004027 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004028}
4029
Brandon Jones59770802018-04-02 13:18:42 -07004030void Context::compressedTexImage2DRobust(TextureTarget target,
4031 GLint level,
4032 GLenum internalformat,
4033 GLsizei width,
4034 GLsizei height,
4035 GLint border,
4036 GLsizei imageSize,
4037 GLsizei dataSize,
4038 const GLvoid *data)
4039{
4040 compressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
4041}
4042
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004043void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004044 GLint level,
4045 GLenum internalformat,
4046 GLsizei width,
4047 GLsizei height,
4048 GLsizei depth,
4049 GLint border,
4050 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004051 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004052{
Jamie Madillbc918e72018-03-08 09:47:21 -05004053 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004054
4055 Extents size(width, height, depth);
4056 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004057 handleError(texture->setCompressedImage(
4058 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004059 size, imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004060}
4061
Brandon Jones59770802018-04-02 13:18:42 -07004062void Context::compressedTexImage3DRobust(TextureType target,
4063 GLint level,
4064 GLenum internalformat,
4065 GLsizei width,
4066 GLsizei height,
4067 GLsizei depth,
4068 GLint border,
4069 GLsizei imageSize,
4070 GLsizei dataSize,
4071 const GLvoid *data)
4072{
4073 compressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize,
4074 data);
4075}
4076
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004077void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004078 GLint level,
4079 GLint xoffset,
4080 GLint yoffset,
4081 GLsizei width,
4082 GLsizei height,
4083 GLenum format,
4084 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004085 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004086{
Jamie Madillbc918e72018-03-08 09:47:21 -05004087 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004088
4089 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004090 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05004091 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
4092 format, imageSize,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004093 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004094}
4095
Brandon Jones59770802018-04-02 13:18:42 -07004096void Context::compressedTexSubImage2DRobust(TextureTarget target,
4097 GLint level,
4098 GLint xoffset,
4099 GLint yoffset,
4100 GLsizei width,
4101 GLsizei height,
4102 GLenum format,
4103 GLsizei imageSize,
4104 GLsizei dataSize,
4105 const GLvoid *data)
4106{
4107 compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize,
4108 data);
4109}
4110
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004111void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004112 GLint level,
4113 GLint xoffset,
4114 GLint yoffset,
4115 GLint zoffset,
4116 GLsizei width,
4117 GLsizei height,
4118 GLsizei depth,
4119 GLenum format,
4120 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004121 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004122{
4123 // Zero sized uploads are valid but no-ops
4124 if (width == 0 || height == 0)
4125 {
4126 return;
4127 }
4128
Jamie Madillbc918e72018-03-08 09:47:21 -05004129 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004130
4131 Box area(xoffset, yoffset, zoffset, width, height, depth);
4132 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004133 handleError(texture->setCompressedSubImage(
4134 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004135 imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004136}
4137
Brandon Jones59770802018-04-02 13:18:42 -07004138void Context::compressedTexSubImage3DRobust(TextureType target,
4139 GLint level,
4140 GLint xoffset,
4141 GLint yoffset,
4142 GLint zoffset,
4143 GLsizei width,
4144 GLsizei height,
4145 GLsizei depth,
4146 GLenum format,
4147 GLsizei imageSize,
4148 GLsizei dataSize,
4149 const GLvoid *data)
4150{
4151 compressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format,
4152 imageSize, data);
4153}
4154
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004155void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004156{
4157 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05004158 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004159}
4160
Jamie Madill007530e2017-12-28 14:27:04 -05004161void Context::copyTexture(GLuint sourceId,
4162 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004163 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004164 GLuint destId,
4165 GLint destLevel,
4166 GLint internalFormat,
4167 GLenum destType,
4168 GLboolean unpackFlipY,
4169 GLboolean unpackPremultiplyAlpha,
4170 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004171{
Jamie Madillbc918e72018-03-08 09:47:21 -05004172 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004173
4174 gl::Texture *sourceTexture = getTexture(sourceId);
4175 gl::Texture *destTexture = getTexture(destId);
Geoff Lang92019432017-11-20 13:09:34 -05004176 handleError(destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType,
4177 sourceLevel, ConvertToBool(unpackFlipY),
4178 ConvertToBool(unpackPremultiplyAlpha),
4179 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004180}
4181
Jamie Madill007530e2017-12-28 14:27:04 -05004182void Context::copySubTexture(GLuint sourceId,
4183 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004184 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004185 GLuint destId,
4186 GLint destLevel,
4187 GLint xoffset,
4188 GLint yoffset,
4189 GLint x,
4190 GLint y,
4191 GLsizei width,
4192 GLsizei height,
4193 GLboolean unpackFlipY,
4194 GLboolean unpackPremultiplyAlpha,
4195 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004196{
4197 // Zero sized copies are valid but no-ops
4198 if (width == 0 || height == 0)
4199 {
4200 return;
4201 }
4202
Jamie Madillbc918e72018-03-08 09:47:21 -05004203 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004204
4205 gl::Texture *sourceTexture = getTexture(sourceId);
4206 gl::Texture *destTexture = getTexture(destId);
4207 Offset offset(xoffset, yoffset, 0);
4208 Rectangle area(x, y, width, height);
Geoff Lang92019432017-11-20 13:09:34 -05004209 handleError(destTexture->copySubTexture(this, destTarget, destLevel, offset, sourceLevel, area,
4210 ConvertToBool(unpackFlipY),
4211 ConvertToBool(unpackPremultiplyAlpha),
4212 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004213}
4214
Jamie Madill007530e2017-12-28 14:27:04 -05004215void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07004216{
Jamie Madillbc918e72018-03-08 09:47:21 -05004217 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07004218
4219 gl::Texture *sourceTexture = getTexture(sourceId);
4220 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05004221 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07004222}
4223
Corentin Wallez336129f2017-10-17 15:55:40 -04004224void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03004225{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004226 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004227 ASSERT(buffer);
4228
Geoff Lang496c02d2016-10-20 11:38:11 -07004229 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03004230}
4231
Brandon Jones59770802018-04-02 13:18:42 -07004232void Context::getBufferPointervRobust(BufferBinding target,
4233 GLenum pname,
4234 GLsizei bufSize,
4235 GLsizei *length,
4236 void **params)
4237{
4238 getBufferPointerv(target, pname, params);
4239}
4240
Corentin Wallez336129f2017-10-17 15:55:40 -04004241void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004242{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004243 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004244 ASSERT(buffer);
4245
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004246 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004247 if (error.isError())
4248 {
Jamie Madill437fa652016-05-03 15:13:24 -04004249 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004250 return nullptr;
4251 }
4252
4253 return buffer->getMapPointer();
4254}
4255
Corentin Wallez336129f2017-10-17 15:55:40 -04004256GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03004257{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004258 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004259 ASSERT(buffer);
4260
4261 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004262 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03004263 if (error.isError())
4264 {
Jamie Madill437fa652016-05-03 15:13:24 -04004265 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004266 return GL_FALSE;
4267 }
4268
4269 return result;
4270}
4271
Corentin Wallez336129f2017-10-17 15:55:40 -04004272void *Context::mapBufferRange(BufferBinding target,
4273 GLintptr offset,
4274 GLsizeiptr length,
4275 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004276{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004277 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004278 ASSERT(buffer);
4279
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004280 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004281 if (error.isError())
4282 {
Jamie Madill437fa652016-05-03 15:13:24 -04004283 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004284 return nullptr;
4285 }
4286
4287 return buffer->getMapPointer();
4288}
4289
Corentin Wallez336129f2017-10-17 15:55:40 -04004290void Context::flushMappedBufferRange(BufferBinding /*target*/,
4291 GLintptr /*offset*/,
4292 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03004293{
4294 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
4295}
4296
Jamie Madillbc918e72018-03-08 09:47:21 -05004297Error Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004298{
Geoff Langa8cb2872018-03-09 16:09:40 -05004299 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004300}
4301
Jamie Madillbc918e72018-03-08 09:47:21 -05004302Error Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004303{
Geoff Langa8cb2872018-03-09 16:09:40 -05004304 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004305}
4306
Jamie Madillbc918e72018-03-08 09:47:21 -05004307Error Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004308{
Geoff Langa8cb2872018-03-09 16:09:40 -05004309 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004310}
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 Madillc20ab272016-06-09 07:20:46 -07004396}
4397
4398void Context::enable(GLenum cap)
4399{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004400 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07004401}
4402
4403void Context::enableVertexAttribArray(GLuint index)
4404{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004405 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07004406}
4407
4408void Context::frontFace(GLenum mode)
4409{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004410 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004411}
4412
4413void Context::hint(GLenum target, GLenum mode)
4414{
4415 switch (target)
4416 {
4417 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004418 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004419 break;
4420
4421 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004422 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004423 break;
4424
4425 default:
4426 UNREACHABLE();
4427 return;
4428 }
4429}
4430
4431void Context::lineWidth(GLfloat width)
4432{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004433 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07004434}
4435
4436void Context::pixelStorei(GLenum pname, GLint param)
4437{
4438 switch (pname)
4439 {
4440 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004441 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004442 break;
4443
4444 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004445 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004446 break;
4447
4448 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004449 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004450 break;
4451
4452 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004453 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004454 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004455 break;
4456
4457 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03004458 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004459 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004460 break;
4461
4462 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03004463 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004464 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004465 break;
4466
4467 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004468 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004469 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004470 break;
4471
4472 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004473 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004474 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004475 break;
4476
4477 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004478 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004479 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004480 break;
4481
4482 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004483 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004484 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004485 break;
4486
4487 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004488 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004489 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004490 break;
4491
4492 default:
4493 UNREACHABLE();
4494 return;
4495 }
4496}
4497
4498void Context::polygonOffset(GLfloat factor, GLfloat units)
4499{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004500 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07004501}
4502
Jamie Madill876429b2017-04-20 15:46:24 -04004503void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07004504{
Geoff Lang92019432017-11-20 13:09:34 -05004505 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07004506}
4507
Jiawei Shaodb342272017-09-27 10:21:45 +08004508void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
4509{
4510 mGLState.setSampleMaskParams(maskNumber, mask);
4511}
4512
Jamie Madillc20ab272016-06-09 07:20:46 -07004513void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
4514{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004515 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004516}
4517
4518void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
4519{
4520 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4521 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004522 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004523 }
4524
4525 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4526 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004527 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004528 }
4529}
4530
4531void Context::stencilMaskSeparate(GLenum face, GLuint mask)
4532{
4533 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4534 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004535 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004536 }
4537
4538 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4539 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004540 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004541 }
4542}
4543
4544void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4545{
4546 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4547 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004548 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004549 }
4550
4551 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4552 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004553 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004554 }
4555}
4556
4557void Context::vertexAttrib1f(GLuint index, GLfloat x)
4558{
4559 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004560 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004561}
4562
4563void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
4564{
4565 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004566 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004567}
4568
4569void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4570{
4571 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004572 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004573}
4574
4575void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
4576{
4577 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004578 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004579}
4580
4581void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4582{
4583 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004584 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004585}
4586
4587void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
4588{
4589 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004590 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004591}
4592
4593void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4594{
4595 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004596 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004597}
4598
4599void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
4600{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004601 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07004602}
4603
4604void Context::vertexAttribPointer(GLuint index,
4605 GLint size,
4606 GLenum type,
4607 GLboolean normalized,
4608 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004609 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07004610{
Corentin Wallez336129f2017-10-17 15:55:40 -04004611 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05004612 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc20ab272016-06-09 07:20:46 -07004613}
4614
Shao80957d92017-02-20 21:25:59 +08004615void Context::vertexAttribFormat(GLuint attribIndex,
4616 GLint size,
4617 GLenum type,
4618 GLboolean normalized,
4619 GLuint relativeOffset)
4620{
Geoff Lang92019432017-11-20 13:09:34 -05004621 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08004622 relativeOffset);
4623}
4624
4625void Context::vertexAttribIFormat(GLuint attribIndex,
4626 GLint size,
4627 GLenum type,
4628 GLuint relativeOffset)
4629{
4630 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
4631}
4632
4633void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4634{
Shaodde78e82017-05-22 14:13:27 +08004635 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Shao80957d92017-02-20 21:25:59 +08004636}
4637
Jiajia Qin5451d532017-11-16 17:16:34 +08004638void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004639{
4640 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
4641}
4642
Jamie Madillc20ab272016-06-09 07:20:46 -07004643void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4644{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004645 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004646}
4647
4648void Context::vertexAttribIPointer(GLuint index,
4649 GLint size,
4650 GLenum type,
4651 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004652 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004653{
Corentin Wallez336129f2017-10-17 15:55:40 -04004654 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
4655 size, type, false, true, stride, pointer);
Jamie Madillc20ab272016-06-09 07:20:46 -07004656}
4657
4658void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4659{
4660 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004661 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004662}
4663
4664void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4665{
4666 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004667 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004668}
4669
4670void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4671{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004672 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004673}
4674
4675void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4676{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004677 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004678}
4679
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004680void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4681{
4682 const VertexAttribCurrentValueData &currentValues =
4683 getGLState().getVertexAttribCurrentValue(index);
4684 const VertexArray *vao = getGLState().getVertexArray();
4685 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4686 currentValues, pname, params);
4687}
4688
Brandon Jones59770802018-04-02 13:18:42 -07004689void Context::getVertexAttribivRobust(GLuint index,
4690 GLenum pname,
4691 GLsizei bufSize,
4692 GLsizei *length,
4693 GLint *params)
4694{
4695 getVertexAttribiv(index, pname, params);
4696}
4697
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004698void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4699{
4700 const VertexAttribCurrentValueData &currentValues =
4701 getGLState().getVertexAttribCurrentValue(index);
4702 const VertexArray *vao = getGLState().getVertexArray();
4703 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4704 currentValues, pname, params);
4705}
4706
Brandon Jones59770802018-04-02 13:18:42 -07004707void Context::getVertexAttribfvRobust(GLuint index,
4708 GLenum pname,
4709 GLsizei bufSize,
4710 GLsizei *length,
4711 GLfloat *params)
4712{
4713 getVertexAttribfv(index, pname, params);
4714}
4715
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004716void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4717{
4718 const VertexAttribCurrentValueData &currentValues =
4719 getGLState().getVertexAttribCurrentValue(index);
4720 const VertexArray *vao = getGLState().getVertexArray();
4721 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4722 currentValues, pname, params);
4723}
4724
Brandon Jones59770802018-04-02 13:18:42 -07004725void Context::getVertexAttribIivRobust(GLuint index,
4726 GLenum pname,
4727 GLsizei bufSize,
4728 GLsizei *length,
4729 GLint *params)
4730{
4731 getVertexAttribIiv(index, pname, params);
4732}
4733
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004734void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4735{
4736 const VertexAttribCurrentValueData &currentValues =
4737 getGLState().getVertexAttribCurrentValue(index);
4738 const VertexArray *vao = getGLState().getVertexArray();
4739 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4740 currentValues, pname, params);
4741}
4742
Brandon Jones59770802018-04-02 13:18:42 -07004743void Context::getVertexAttribIuivRobust(GLuint index,
4744 GLenum pname,
4745 GLsizei bufSize,
4746 GLsizei *length,
4747 GLuint *params)
4748{
4749 getVertexAttribIuiv(index, pname, params);
4750}
4751
Jamie Madill876429b2017-04-20 15:46:24 -04004752void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004753{
4754 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
4755 QueryVertexAttribPointerv(attrib, pname, pointer);
4756}
4757
Brandon Jones59770802018-04-02 13:18:42 -07004758void Context::getVertexAttribPointervRobust(GLuint index,
4759 GLenum pname,
4760 GLsizei bufSize,
4761 GLsizei *length,
4762 void **pointer)
4763{
4764 getVertexAttribPointerv(index, pname, pointer);
4765}
4766
Jamie Madillc20ab272016-06-09 07:20:46 -07004767void Context::debugMessageControl(GLenum source,
4768 GLenum type,
4769 GLenum severity,
4770 GLsizei count,
4771 const GLuint *ids,
4772 GLboolean enabled)
4773{
4774 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004775 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05004776 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004777}
4778
4779void Context::debugMessageInsert(GLenum source,
4780 GLenum type,
4781 GLuint id,
4782 GLenum severity,
4783 GLsizei length,
4784 const GLchar *buf)
4785{
4786 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004787 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004788}
4789
4790void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4791{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004792 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004793}
4794
4795GLuint Context::getDebugMessageLog(GLuint count,
4796 GLsizei bufSize,
4797 GLenum *sources,
4798 GLenum *types,
4799 GLuint *ids,
4800 GLenum *severities,
4801 GLsizei *lengths,
4802 GLchar *messageLog)
4803{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004804 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4805 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004806}
4807
4808void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4809{
4810 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004811 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05004812 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07004813}
4814
4815void Context::popDebugGroup()
4816{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004817 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05004818 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004819}
4820
Corentin Wallez336129f2017-10-17 15:55:40 -04004821void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004822{
4823 Buffer *buffer = mGLState.getTargetBuffer(target);
4824 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004825 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004826}
4827
Corentin Wallez336129f2017-10-17 15:55:40 -04004828void Context::bufferSubData(BufferBinding target,
4829 GLintptr offset,
4830 GLsizeiptr size,
4831 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004832{
4833 if (data == nullptr)
4834 {
4835 return;
4836 }
4837
4838 Buffer *buffer = mGLState.getTargetBuffer(target);
4839 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004840 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004841}
4842
Jamie Madillef300b12016-10-07 15:12:09 -04004843void Context::attachShader(GLuint program, GLuint shader)
4844{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05004845 Program *programObject = mState.mShaderPrograms->getProgram(program);
4846 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004847 ASSERT(programObject && shaderObject);
4848 programObject->attachShader(shaderObject);
4849}
4850
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004851const Workarounds &Context::getWorkarounds() const
4852{
4853 return mWorkarounds;
4854}
4855
Corentin Wallez336129f2017-10-17 15:55:40 -04004856void Context::copyBufferSubData(BufferBinding readTarget,
4857 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04004858 GLintptr readOffset,
4859 GLintptr writeOffset,
4860 GLsizeiptr size)
4861{
4862 // if size is zero, the copy is a successful no-op
4863 if (size == 0)
4864 {
4865 return;
4866 }
4867
4868 // TODO(jmadill): cache these.
4869 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4870 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4871
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004872 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004873}
4874
Jamie Madill01a80ee2016-11-07 12:06:18 -05004875void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4876{
4877 Program *programObject = getProgram(program);
4878 // TODO(jmadill): Re-use this from the validation if possible.
4879 ASSERT(programObject);
4880 programObject->bindAttributeLocation(index, name);
4881}
4882
Corentin Wallez336129f2017-10-17 15:55:40 -04004883void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004884{
Corentin Wallez336129f2017-10-17 15:55:40 -04004885 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4886 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004887}
4888
Corentin Wallez336129f2017-10-17 15:55:40 -04004889void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08004890{
4891 bindBufferRange(target, index, buffer, 0, 0);
4892}
4893
Corentin Wallez336129f2017-10-17 15:55:40 -04004894void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08004895 GLuint index,
4896 GLuint buffer,
4897 GLintptr offset,
4898 GLsizeiptr size)
4899{
Corentin Wallez336129f2017-10-17 15:55:40 -04004900 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4901 mGLState.setIndexedBufferBinding(this, target, index, bufferObject, offset, size);
Jiajia Qin6eafb042016-12-27 17:04:07 +08004902}
4903
Jamie Madill01a80ee2016-11-07 12:06:18 -05004904void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
4905{
4906 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4907 {
4908 bindReadFramebuffer(framebuffer);
4909 }
4910
4911 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4912 {
4913 bindDrawFramebuffer(framebuffer);
4914 }
4915}
4916
4917void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4918{
4919 ASSERT(target == GL_RENDERBUFFER);
4920 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004921 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04004922 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004923}
4924
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004925void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08004926 GLsizei samples,
4927 GLenum internalformat,
4928 GLsizei width,
4929 GLsizei height,
4930 GLboolean fixedsamplelocations)
4931{
4932 Extents size(width, height, 1);
4933 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004934 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
4935 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004936}
4937
4938void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4939{
JiangYizhou5b03f472017-01-09 10:22:53 +08004940 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
4941 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillbc918e72018-03-08 09:47:21 -05004942 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
JiangYizhou5b03f472017-01-09 10:22:53 +08004943 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08004944
4945 switch (pname)
4946 {
4947 case GL_SAMPLE_POSITION:
Geoff Lang13455072018-05-09 11:24:43 -04004948 handleError(framebuffer->getSamplePosition(this, index, val));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004949 break;
4950 default:
4951 UNREACHABLE();
4952 }
4953}
4954
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07004955void Context::getMultisamplefvRobust(GLenum pname,
4956 GLuint index,
4957 GLsizei bufSize,
4958 GLsizei *length,
4959 GLfloat *val)
4960{
4961 UNIMPLEMENTED();
4962}
4963
Jamie Madille8fb6402017-02-14 17:56:40 -05004964void Context::renderbufferStorage(GLenum target,
4965 GLenum internalformat,
4966 GLsizei width,
4967 GLsizei height)
4968{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004969 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4970 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
4971
Jamie Madille8fb6402017-02-14 17:56:40 -05004972 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04004973 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004974}
4975
4976void Context::renderbufferStorageMultisample(GLenum target,
4977 GLsizei samples,
4978 GLenum internalformat,
4979 GLsizei width,
4980 GLsizei height)
4981{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004982 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4983 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05004984
4985 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004986 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04004987 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004988}
4989
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004990void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
4991{
Jamie Madill70b5bb02017-08-28 13:32:37 -04004992 const Sync *syncObject = getSync(sync);
Jamie Madilla0691b72018-07-25 10:41:22 -04004993 handleError(QuerySynciv(this, syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004994}
4995
JiangYizhoue18e6392017-02-20 10:32:23 +08004996void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
4997{
4998 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4999 QueryFramebufferParameteriv(framebuffer, pname, params);
5000}
5001
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07005002void Context::getFramebufferParameterivRobust(GLenum target,
5003 GLenum pname,
5004 GLsizei bufSize,
5005 GLsizei *length,
5006 GLint *params)
5007{
5008 UNIMPLEMENTED();
5009}
5010
Jiajia Qin5451d532017-11-16 17:16:34 +08005011void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08005012{
5013 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5014 SetFramebufferParameteri(framebuffer, pname, param);
5015}
5016
Jamie Madilldec86232018-07-11 09:01:18 -04005017bool Context::getScratchBuffer(size_t requstedSizeBytes,
5018 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05005019{
Jamie Madilldec86232018-07-11 09:01:18 -04005020 return mScratchBuffer.get(requstedSizeBytes, scratchBufferOut);
Jamie Madillb3f26b92017-07-19 15:07:41 -04005021}
5022
Jamie Madilldec86232018-07-11 09:01:18 -04005023bool Context::getZeroFilledBuffer(size_t requstedSizeBytes,
5024 angle::MemoryBuffer **zeroBufferOut) const
Jamie Madillb3f26b92017-07-19 15:07:41 -04005025{
Jamie Madilldec86232018-07-11 09:01:18 -04005026 return mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0);
Jamie Madille14951e2017-03-09 18:55:16 -05005027}
5028
Xinghua Cao10a4d432017-11-28 14:46:26 +08005029Error Context::prepareForDispatch()
5030{
Geoff Langa8cb2872018-03-09 16:09:40 -05005031 ANGLE_TRY(syncState(mComputeDirtyBits, mComputeDirtyObjects));
Xinghua Cao10a4d432017-11-28 14:46:26 +08005032
5033 if (isRobustResourceInitEnabled())
5034 {
5035 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
5036 }
5037
5038 return NoError();
5039}
5040
Xinghua Cao2b396592017-03-29 15:36:04 +08005041void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
5042{
5043 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
5044 {
5045 return;
5046 }
5047
Xinghua Cao10a4d432017-11-28 14:46:26 +08005048 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill71c88b32017-09-14 22:20:29 -04005049 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08005050}
5051
Jiajia Qin5451d532017-11-16 17:16:34 +08005052void Context::dispatchComputeIndirect(GLintptr indirect)
5053{
Qin Jiajia62fcf622017-11-30 16:16:12 +08005054 ANGLE_CONTEXT_TRY(prepareForDispatch());
5055 handleError(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08005056}
5057
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005058void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005059 GLsizei levels,
5060 GLenum internalFormat,
5061 GLsizei width,
5062 GLsizei height)
5063{
5064 Extents size(width, height, 1);
5065 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005066 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005067}
5068
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005069void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005070 GLsizei levels,
5071 GLenum internalFormat,
5072 GLsizei width,
5073 GLsizei height,
5074 GLsizei depth)
5075{
5076 Extents size(width, height, depth);
5077 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005078 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005079}
5080
Jiajia Qin5451d532017-11-16 17:16:34 +08005081void Context::memoryBarrier(GLbitfield barriers)
5082{
Xinghua Cao89c422a2017-11-29 18:24:20 +08005083 handleError(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005084}
5085
5086void Context::memoryBarrierByRegion(GLbitfield barriers)
5087{
Xinghua Cao89c422a2017-11-29 18:24:20 +08005088 handleError(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005089}
5090
Jamie Madillc1d770e2017-04-13 17:31:24 -04005091GLenum Context::checkFramebufferStatus(GLenum target)
5092{
5093 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5094 ASSERT(framebuffer);
Jamie Madill427064d2018-04-13 16:20:34 -04005095 return framebuffer->checkStatus(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005096}
5097
5098void Context::compileShader(GLuint shader)
5099{
5100 Shader *shaderObject = GetValidShader(this, shader);
5101 if (!shaderObject)
5102 {
5103 return;
5104 }
5105 shaderObject->compile(this);
5106}
5107
5108void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
5109{
5110 for (int i = 0; i < n; i++)
5111 {
5112 deleteBuffer(buffers[i]);
5113 }
5114}
5115
5116void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
5117{
5118 for (int i = 0; i < n; i++)
5119 {
5120 if (framebuffers[i] != 0)
5121 {
5122 deleteFramebuffer(framebuffers[i]);
5123 }
5124 }
5125}
5126
5127void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
5128{
5129 for (int i = 0; i < n; i++)
5130 {
5131 deleteRenderbuffer(renderbuffers[i]);
5132 }
5133}
5134
5135void Context::deleteTextures(GLsizei n, const GLuint *textures)
5136{
5137 for (int i = 0; i < n; i++)
5138 {
5139 if (textures[i] != 0)
5140 {
5141 deleteTexture(textures[i]);
5142 }
5143 }
5144}
5145
5146void Context::detachShader(GLuint program, GLuint shader)
5147{
5148 Program *programObject = getProgram(program);
5149 ASSERT(programObject);
5150
5151 Shader *shaderObject = getShader(shader);
5152 ASSERT(shaderObject);
5153
5154 programObject->detachShader(this, shaderObject);
5155}
5156
5157void Context::genBuffers(GLsizei n, GLuint *buffers)
5158{
5159 for (int i = 0; i < n; i++)
5160 {
5161 buffers[i] = createBuffer();
5162 }
5163}
5164
5165void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
5166{
5167 for (int i = 0; i < n; i++)
5168 {
5169 framebuffers[i] = createFramebuffer();
5170 }
5171}
5172
5173void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
5174{
5175 for (int i = 0; i < n; i++)
5176 {
5177 renderbuffers[i] = createRenderbuffer();
5178 }
5179}
5180
5181void Context::genTextures(GLsizei n, GLuint *textures)
5182{
5183 for (int i = 0; i < n; i++)
5184 {
5185 textures[i] = createTexture();
5186 }
5187}
5188
5189void Context::getActiveAttrib(GLuint program,
5190 GLuint index,
5191 GLsizei bufsize,
5192 GLsizei *length,
5193 GLint *size,
5194 GLenum *type,
5195 GLchar *name)
5196{
5197 Program *programObject = getProgram(program);
5198 ASSERT(programObject);
5199 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
5200}
5201
5202void Context::getActiveUniform(GLuint program,
5203 GLuint index,
5204 GLsizei bufsize,
5205 GLsizei *length,
5206 GLint *size,
5207 GLenum *type,
5208 GLchar *name)
5209{
5210 Program *programObject = getProgram(program);
5211 ASSERT(programObject);
5212 programObject->getActiveUniform(index, bufsize, length, size, type, name);
5213}
5214
5215void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
5216{
5217 Program *programObject = getProgram(program);
5218 ASSERT(programObject);
5219 programObject->getAttachedShaders(maxcount, count, shaders);
5220}
5221
5222GLint Context::getAttribLocation(GLuint program, const GLchar *name)
5223{
5224 Program *programObject = getProgram(program);
5225 ASSERT(programObject);
5226 return programObject->getAttributeLocation(name);
5227}
5228
5229void Context::getBooleanv(GLenum pname, GLboolean *params)
5230{
5231 GLenum nativeType;
5232 unsigned int numParams = 0;
5233 getQueryParameterInfo(pname, &nativeType, &numParams);
5234
5235 if (nativeType == GL_BOOL)
5236 {
5237 getBooleanvImpl(pname, params);
5238 }
5239 else
5240 {
5241 CastStateValues(this, nativeType, pname, numParams, params);
5242 }
5243}
5244
Brandon Jones59770802018-04-02 13:18:42 -07005245void Context::getBooleanvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLboolean *params)
5246{
5247 getBooleanv(pname, params);
5248}
5249
Jamie Madillc1d770e2017-04-13 17:31:24 -04005250void Context::getFloatv(GLenum pname, GLfloat *params)
5251{
5252 GLenum nativeType;
5253 unsigned int numParams = 0;
5254 getQueryParameterInfo(pname, &nativeType, &numParams);
5255
5256 if (nativeType == GL_FLOAT)
5257 {
5258 getFloatvImpl(pname, params);
5259 }
5260 else
5261 {
5262 CastStateValues(this, nativeType, pname, numParams, params);
5263 }
5264}
5265
Brandon Jones59770802018-04-02 13:18:42 -07005266void Context::getFloatvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLfloat *params)
5267{
5268 getFloatv(pname, params);
5269}
5270
Jamie Madillc1d770e2017-04-13 17:31:24 -04005271void Context::getIntegerv(GLenum pname, GLint *params)
5272{
5273 GLenum nativeType;
5274 unsigned int numParams = 0;
5275 getQueryParameterInfo(pname, &nativeType, &numParams);
5276
5277 if (nativeType == GL_INT)
5278 {
5279 getIntegervImpl(pname, params);
5280 }
5281 else
5282 {
5283 CastStateValues(this, nativeType, pname, numParams, params);
5284 }
5285}
5286
Brandon Jones59770802018-04-02 13:18:42 -07005287void Context::getIntegervRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint *data)
5288{
5289 getIntegerv(pname, data);
5290}
5291
Jamie Madillc1d770e2017-04-13 17:31:24 -04005292void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
5293{
5294 Program *programObject = getProgram(program);
5295 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04005296 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005297}
5298
Brandon Jones59770802018-04-02 13:18:42 -07005299void Context::getProgramivRobust(GLuint program,
5300 GLenum pname,
5301 GLsizei bufSize,
5302 GLsizei *length,
5303 GLint *params)
5304{
5305 getProgramiv(program, pname, params);
5306}
5307
Jiajia Qin5451d532017-11-16 17:16:34 +08005308void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
5309{
5310 UNIMPLEMENTED();
5311}
5312
Jamie Madillbe849e42017-05-02 15:49:00 -04005313void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005314{
5315 Program *programObject = getProgram(program);
5316 ASSERT(programObject);
5317 programObject->getInfoLog(bufsize, length, infolog);
5318}
5319
Jiajia Qin5451d532017-11-16 17:16:34 +08005320void Context::getProgramPipelineInfoLog(GLuint pipeline,
5321 GLsizei bufSize,
5322 GLsizei *length,
5323 GLchar *infoLog)
5324{
5325 UNIMPLEMENTED();
5326}
5327
Jamie Madillc1d770e2017-04-13 17:31:24 -04005328void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
5329{
5330 Shader *shaderObject = getShader(shader);
5331 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04005332 QueryShaderiv(this, shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005333}
5334
Brandon Jones59770802018-04-02 13:18:42 -07005335void Context::getShaderivRobust(GLuint shader,
5336 GLenum pname,
5337 GLsizei bufSize,
5338 GLsizei *length,
5339 GLint *params)
5340{
5341 getShaderiv(shader, pname, params);
5342}
5343
Jamie Madillc1d770e2017-04-13 17:31:24 -04005344void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
5345{
5346 Shader *shaderObject = getShader(shader);
5347 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04005348 shaderObject->getInfoLog(this, bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005349}
5350
5351void Context::getShaderPrecisionFormat(GLenum shadertype,
5352 GLenum precisiontype,
5353 GLint *range,
5354 GLint *precision)
5355{
5356 // TODO(jmadill): Compute shaders.
5357
5358 switch (shadertype)
5359 {
5360 case GL_VERTEX_SHADER:
5361 switch (precisiontype)
5362 {
5363 case GL_LOW_FLOAT:
5364 mCaps.vertexLowpFloat.get(range, precision);
5365 break;
5366 case GL_MEDIUM_FLOAT:
5367 mCaps.vertexMediumpFloat.get(range, precision);
5368 break;
5369 case GL_HIGH_FLOAT:
5370 mCaps.vertexHighpFloat.get(range, precision);
5371 break;
5372
5373 case GL_LOW_INT:
5374 mCaps.vertexLowpInt.get(range, precision);
5375 break;
5376 case GL_MEDIUM_INT:
5377 mCaps.vertexMediumpInt.get(range, precision);
5378 break;
5379 case GL_HIGH_INT:
5380 mCaps.vertexHighpInt.get(range, precision);
5381 break;
5382
5383 default:
5384 UNREACHABLE();
5385 return;
5386 }
5387 break;
5388
5389 case GL_FRAGMENT_SHADER:
5390 switch (precisiontype)
5391 {
5392 case GL_LOW_FLOAT:
5393 mCaps.fragmentLowpFloat.get(range, precision);
5394 break;
5395 case GL_MEDIUM_FLOAT:
5396 mCaps.fragmentMediumpFloat.get(range, precision);
5397 break;
5398 case GL_HIGH_FLOAT:
5399 mCaps.fragmentHighpFloat.get(range, precision);
5400 break;
5401
5402 case GL_LOW_INT:
5403 mCaps.fragmentLowpInt.get(range, precision);
5404 break;
5405 case GL_MEDIUM_INT:
5406 mCaps.fragmentMediumpInt.get(range, precision);
5407 break;
5408 case GL_HIGH_INT:
5409 mCaps.fragmentHighpInt.get(range, precision);
5410 break;
5411
5412 default:
5413 UNREACHABLE();
5414 return;
5415 }
5416 break;
5417
5418 default:
5419 UNREACHABLE();
5420 return;
5421 }
5422}
5423
5424void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
5425{
5426 Shader *shaderObject = getShader(shader);
5427 ASSERT(shaderObject);
5428 shaderObject->getSource(bufsize, length, source);
5429}
5430
5431void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
5432{
5433 Program *programObject = getProgram(program);
5434 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005435 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005436}
5437
Brandon Jones59770802018-04-02 13:18:42 -07005438void Context::getUniformfvRobust(GLuint program,
5439 GLint location,
5440 GLsizei bufSize,
5441 GLsizei *length,
5442 GLfloat *params)
5443{
5444 getUniformfv(program, location, params);
5445}
5446
Jamie Madillc1d770e2017-04-13 17:31:24 -04005447void Context::getUniformiv(GLuint program, GLint location, GLint *params)
5448{
5449 Program *programObject = getProgram(program);
5450 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005451 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005452}
5453
Brandon Jones59770802018-04-02 13:18:42 -07005454void Context::getUniformivRobust(GLuint program,
5455 GLint location,
5456 GLsizei bufSize,
5457 GLsizei *length,
5458 GLint *params)
5459{
5460 getUniformiv(program, location, params);
5461}
5462
Jamie Madillc1d770e2017-04-13 17:31:24 -04005463GLint Context::getUniformLocation(GLuint program, const GLchar *name)
5464{
5465 Program *programObject = getProgram(program);
5466 ASSERT(programObject);
5467 return programObject->getUniformLocation(name);
5468}
5469
5470GLboolean Context::isBuffer(GLuint buffer)
5471{
5472 if (buffer == 0)
5473 {
5474 return GL_FALSE;
5475 }
5476
5477 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
5478}
5479
5480GLboolean Context::isEnabled(GLenum cap)
5481{
5482 return mGLState.getEnableFeature(cap);
5483}
5484
5485GLboolean Context::isFramebuffer(GLuint framebuffer)
5486{
5487 if (framebuffer == 0)
5488 {
5489 return GL_FALSE;
5490 }
5491
5492 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
5493}
5494
5495GLboolean Context::isProgram(GLuint program)
5496{
5497 if (program == 0)
5498 {
5499 return GL_FALSE;
5500 }
5501
5502 return (getProgram(program) ? GL_TRUE : GL_FALSE);
5503}
5504
5505GLboolean Context::isRenderbuffer(GLuint renderbuffer)
5506{
5507 if (renderbuffer == 0)
5508 {
5509 return GL_FALSE;
5510 }
5511
5512 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
5513}
5514
5515GLboolean Context::isShader(GLuint shader)
5516{
5517 if (shader == 0)
5518 {
5519 return GL_FALSE;
5520 }
5521
5522 return (getShader(shader) ? GL_TRUE : GL_FALSE);
5523}
5524
5525GLboolean Context::isTexture(GLuint texture)
5526{
5527 if (texture == 0)
5528 {
5529 return GL_FALSE;
5530 }
5531
5532 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
5533}
5534
5535void Context::linkProgram(GLuint program)
5536{
5537 Program *programObject = getProgram(program);
5538 ASSERT(programObject);
5539 handleError(programObject->link(this));
Martin Radev0abb7a22017-08-28 15:34:45 +03005540 mGLState.onProgramExecutableChange(programObject);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005541}
5542
5543void Context::releaseShaderCompiler()
5544{
Jamie Madill4928b7c2017-06-20 12:57:39 -04005545 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005546}
5547
5548void Context::shaderBinary(GLsizei n,
5549 const GLuint *shaders,
5550 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04005551 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005552 GLsizei length)
5553{
5554 // No binary shader formats are supported.
5555 UNIMPLEMENTED();
5556}
5557
5558void Context::shaderSource(GLuint shader,
5559 GLsizei count,
5560 const GLchar *const *string,
5561 const GLint *length)
5562{
5563 Shader *shaderObject = getShader(shader);
5564 ASSERT(shaderObject);
5565 shaderObject->setSource(count, string, length);
5566}
5567
5568void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
5569{
5570 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
5571}
5572
5573void Context::stencilMask(GLuint mask)
5574{
5575 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
5576}
5577
5578void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
5579{
5580 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
5581}
5582
5583void Context::uniform1f(GLint location, GLfloat x)
5584{
5585 Program *program = mGLState.getProgram();
5586 program->setUniform1fv(location, 1, &x);
5587}
5588
5589void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
5590{
5591 Program *program = mGLState.getProgram();
5592 program->setUniform1fv(location, count, v);
5593}
5594
5595void Context::uniform1i(GLint location, GLint x)
5596{
5597 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04005598 if (program->setUniform1iv(location, 1, &x) == Program::SetUniformResult::SamplerChanged)
5599 {
5600 mGLState.setObjectDirty(GL_PROGRAM);
5601 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005602}
5603
5604void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
5605{
5606 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04005607 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
5608 {
5609 mGLState.setObjectDirty(GL_PROGRAM);
5610 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005611}
5612
5613void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
5614{
5615 GLfloat xy[2] = {x, y};
5616 Program *program = mGLState.getProgram();
5617 program->setUniform2fv(location, 1, xy);
5618}
5619
5620void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
5621{
5622 Program *program = mGLState.getProgram();
5623 program->setUniform2fv(location, count, v);
5624}
5625
5626void Context::uniform2i(GLint location, GLint x, GLint y)
5627{
5628 GLint xy[2] = {x, y};
5629 Program *program = mGLState.getProgram();
5630 program->setUniform2iv(location, 1, xy);
5631}
5632
5633void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
5634{
5635 Program *program = mGLState.getProgram();
5636 program->setUniform2iv(location, count, v);
5637}
5638
5639void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
5640{
5641 GLfloat xyz[3] = {x, y, z};
5642 Program *program = mGLState.getProgram();
5643 program->setUniform3fv(location, 1, xyz);
5644}
5645
5646void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
5647{
5648 Program *program = mGLState.getProgram();
5649 program->setUniform3fv(location, count, v);
5650}
5651
5652void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
5653{
5654 GLint xyz[3] = {x, y, z};
5655 Program *program = mGLState.getProgram();
5656 program->setUniform3iv(location, 1, xyz);
5657}
5658
5659void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
5660{
5661 Program *program = mGLState.getProgram();
5662 program->setUniform3iv(location, count, v);
5663}
5664
5665void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
5666{
5667 GLfloat xyzw[4] = {x, y, z, w};
5668 Program *program = mGLState.getProgram();
5669 program->setUniform4fv(location, 1, xyzw);
5670}
5671
5672void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
5673{
5674 Program *program = mGLState.getProgram();
5675 program->setUniform4fv(location, count, v);
5676}
5677
5678void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
5679{
5680 GLint xyzw[4] = {x, y, z, w};
5681 Program *program = mGLState.getProgram();
5682 program->setUniform4iv(location, 1, xyzw);
5683}
5684
5685void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
5686{
5687 Program *program = mGLState.getProgram();
5688 program->setUniform4iv(location, count, v);
5689}
5690
5691void Context::uniformMatrix2fv(GLint location,
5692 GLsizei count,
5693 GLboolean transpose,
5694 const GLfloat *value)
5695{
5696 Program *program = mGLState.getProgram();
5697 program->setUniformMatrix2fv(location, count, transpose, value);
5698}
5699
5700void Context::uniformMatrix3fv(GLint location,
5701 GLsizei count,
5702 GLboolean transpose,
5703 const GLfloat *value)
5704{
5705 Program *program = mGLState.getProgram();
5706 program->setUniformMatrix3fv(location, count, transpose, value);
5707}
5708
5709void Context::uniformMatrix4fv(GLint location,
5710 GLsizei count,
5711 GLboolean transpose,
5712 const GLfloat *value)
5713{
5714 Program *program = mGLState.getProgram();
5715 program->setUniformMatrix4fv(location, count, transpose, value);
5716}
5717
5718void Context::validateProgram(GLuint program)
5719{
5720 Program *programObject = getProgram(program);
5721 ASSERT(programObject);
5722 programObject->validate(mCaps);
5723}
5724
Jiajia Qin5451d532017-11-16 17:16:34 +08005725void Context::validateProgramPipeline(GLuint pipeline)
5726{
5727 UNIMPLEMENTED();
5728}
5729
Jamie Madilld04908b2017-06-09 14:15:35 -04005730void Context::getProgramBinary(GLuint program,
5731 GLsizei bufSize,
5732 GLsizei *length,
5733 GLenum *binaryFormat,
5734 void *binary)
5735{
5736 Program *programObject = getProgram(program);
5737 ASSERT(programObject != nullptr);
5738
5739 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
5740}
5741
5742void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
5743{
5744 Program *programObject = getProgram(program);
5745 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04005746
Jamie Madilld04908b2017-06-09 14:15:35 -04005747 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
5748}
5749
Jamie Madillff325f12017-08-26 15:06:05 -04005750void Context::uniform1ui(GLint location, GLuint v0)
5751{
5752 Program *program = mGLState.getProgram();
5753 program->setUniform1uiv(location, 1, &v0);
5754}
5755
5756void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
5757{
5758 Program *program = mGLState.getProgram();
5759 const GLuint xy[] = {v0, v1};
5760 program->setUniform2uiv(location, 1, xy);
5761}
5762
5763void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
5764{
5765 Program *program = mGLState.getProgram();
5766 const GLuint xyz[] = {v0, v1, v2};
5767 program->setUniform3uiv(location, 1, xyz);
5768}
5769
5770void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
5771{
5772 Program *program = mGLState.getProgram();
5773 const GLuint xyzw[] = {v0, v1, v2, v3};
5774 program->setUniform4uiv(location, 1, xyzw);
5775}
5776
5777void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
5778{
5779 Program *program = mGLState.getProgram();
5780 program->setUniform1uiv(location, count, value);
5781}
5782void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
5783{
5784 Program *program = mGLState.getProgram();
5785 program->setUniform2uiv(location, count, value);
5786}
5787
5788void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
5789{
5790 Program *program = mGLState.getProgram();
5791 program->setUniform3uiv(location, count, value);
5792}
5793
5794void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
5795{
5796 Program *program = mGLState.getProgram();
5797 program->setUniform4uiv(location, count, value);
5798}
5799
Jamie Madillf0e04492017-08-26 15:28:42 -04005800void Context::genQueries(GLsizei n, GLuint *ids)
5801{
5802 for (GLsizei i = 0; i < n; i++)
5803 {
5804 GLuint handle = mQueryHandleAllocator.allocate();
5805 mQueryMap.assign(handle, nullptr);
5806 ids[i] = handle;
5807 }
5808}
5809
5810void Context::deleteQueries(GLsizei n, const GLuint *ids)
5811{
5812 for (int i = 0; i < n; i++)
5813 {
5814 GLuint query = ids[i];
5815
5816 Query *queryObject = nullptr;
5817 if (mQueryMap.erase(query, &queryObject))
5818 {
5819 mQueryHandleAllocator.release(query);
5820 if (queryObject)
5821 {
5822 queryObject->release(this);
5823 }
5824 }
5825 }
5826}
5827
5828GLboolean Context::isQuery(GLuint id)
5829{
Corentin Wallezad3ae902018-03-09 13:40:42 -05005830 return (getQuery(id, false, QueryType::InvalidEnum) != nullptr) ? GL_TRUE : GL_FALSE;
Jamie Madillf0e04492017-08-26 15:28:42 -04005831}
5832
Jamie Madillc8c95812017-08-26 18:40:09 -04005833void Context::uniformMatrix2x3fv(GLint location,
5834 GLsizei count,
5835 GLboolean transpose,
5836 const GLfloat *value)
5837{
5838 Program *program = mGLState.getProgram();
5839 program->setUniformMatrix2x3fv(location, count, transpose, value);
5840}
5841
5842void Context::uniformMatrix3x2fv(GLint location,
5843 GLsizei count,
5844 GLboolean transpose,
5845 const GLfloat *value)
5846{
5847 Program *program = mGLState.getProgram();
5848 program->setUniformMatrix3x2fv(location, count, transpose, value);
5849}
5850
5851void Context::uniformMatrix2x4fv(GLint location,
5852 GLsizei count,
5853 GLboolean transpose,
5854 const GLfloat *value)
5855{
5856 Program *program = mGLState.getProgram();
5857 program->setUniformMatrix2x4fv(location, count, transpose, value);
5858}
5859
5860void Context::uniformMatrix4x2fv(GLint location,
5861 GLsizei count,
5862 GLboolean transpose,
5863 const GLfloat *value)
5864{
5865 Program *program = mGLState.getProgram();
5866 program->setUniformMatrix4x2fv(location, count, transpose, value);
5867}
5868
5869void Context::uniformMatrix3x4fv(GLint location,
5870 GLsizei count,
5871 GLboolean transpose,
5872 const GLfloat *value)
5873{
5874 Program *program = mGLState.getProgram();
5875 program->setUniformMatrix3x4fv(location, count, transpose, value);
5876}
5877
5878void Context::uniformMatrix4x3fv(GLint location,
5879 GLsizei count,
5880 GLboolean transpose,
5881 const GLfloat *value)
5882{
5883 Program *program = mGLState.getProgram();
5884 program->setUniformMatrix4x3fv(location, count, transpose, value);
5885}
5886
Jamie Madilld7576732017-08-26 18:49:50 -04005887void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
5888{
5889 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5890 {
5891 GLuint vertexArray = arrays[arrayIndex];
5892
5893 if (arrays[arrayIndex] != 0)
5894 {
5895 VertexArray *vertexArrayObject = nullptr;
5896 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
5897 {
5898 if (vertexArrayObject != nullptr)
5899 {
5900 detachVertexArray(vertexArray);
5901 vertexArrayObject->onDestroy(this);
5902 }
5903
5904 mVertexArrayHandleAllocator.release(vertexArray);
5905 }
5906 }
5907 }
5908}
5909
5910void Context::genVertexArrays(GLsizei n, GLuint *arrays)
5911{
5912 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5913 {
5914 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
5915 mVertexArrayMap.assign(vertexArray, nullptr);
5916 arrays[arrayIndex] = vertexArray;
5917 }
5918}
5919
5920bool Context::isVertexArray(GLuint array)
5921{
5922 if (array == 0)
5923 {
5924 return GL_FALSE;
5925 }
5926
5927 VertexArray *vao = getVertexArray(array);
5928 return (vao != nullptr ? GL_TRUE : GL_FALSE);
5929}
5930
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04005931void Context::endTransformFeedback()
5932{
5933 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5934 transformFeedback->end(this);
5935}
5936
5937void Context::transformFeedbackVaryings(GLuint program,
5938 GLsizei count,
5939 const GLchar *const *varyings,
5940 GLenum bufferMode)
5941{
5942 Program *programObject = getProgram(program);
5943 ASSERT(programObject);
5944 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
5945}
5946
5947void Context::getTransformFeedbackVarying(GLuint program,
5948 GLuint index,
5949 GLsizei bufSize,
5950 GLsizei *length,
5951 GLsizei *size,
5952 GLenum *type,
5953 GLchar *name)
5954{
5955 Program *programObject = getProgram(program);
5956 ASSERT(programObject);
5957 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
5958}
5959
5960void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
5961{
5962 for (int i = 0; i < n; i++)
5963 {
5964 GLuint transformFeedback = ids[i];
5965 if (transformFeedback == 0)
5966 {
5967 continue;
5968 }
5969
5970 TransformFeedback *transformFeedbackObject = nullptr;
5971 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
5972 {
5973 if (transformFeedbackObject != nullptr)
5974 {
5975 detachTransformFeedback(transformFeedback);
5976 transformFeedbackObject->release(this);
5977 }
5978
5979 mTransformFeedbackHandleAllocator.release(transformFeedback);
5980 }
5981 }
5982}
5983
5984void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
5985{
5986 for (int i = 0; i < n; i++)
5987 {
5988 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
5989 mTransformFeedbackMap.assign(transformFeedback, nullptr);
5990 ids[i] = transformFeedback;
5991 }
5992}
5993
5994bool Context::isTransformFeedback(GLuint id)
5995{
5996 if (id == 0)
5997 {
5998 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
5999 // returns FALSE
6000 return GL_FALSE;
6001 }
6002
6003 const TransformFeedback *transformFeedback = getTransformFeedback(id);
6004 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
6005}
6006
6007void Context::pauseTransformFeedback()
6008{
6009 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6010 transformFeedback->pause();
6011}
6012
6013void Context::resumeTransformFeedback()
6014{
6015 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6016 transformFeedback->resume();
6017}
6018
Jamie Madill12e957f2017-08-26 21:42:26 -04006019void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
6020{
6021 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04006022 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04006023}
6024
Brandon Jones59770802018-04-02 13:18:42 -07006025void Context::getUniformuivRobust(GLuint program,
6026 GLint location,
6027 GLsizei bufSize,
6028 GLsizei *length,
6029 GLuint *params)
6030{
6031 getUniformuiv(program, location, params);
6032}
6033
Jamie Madill12e957f2017-08-26 21:42:26 -04006034GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
6035{
6036 const Program *programObject = getProgram(program);
6037 return programObject->getFragDataLocation(name);
6038}
6039
6040void Context::getUniformIndices(GLuint program,
6041 GLsizei uniformCount,
6042 const GLchar *const *uniformNames,
6043 GLuint *uniformIndices)
6044{
6045 const Program *programObject = getProgram(program);
6046 if (!programObject->isLinked())
6047 {
6048 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6049 {
6050 uniformIndices[uniformId] = GL_INVALID_INDEX;
6051 }
6052 }
6053 else
6054 {
6055 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6056 {
6057 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
6058 }
6059 }
6060}
6061
6062void Context::getActiveUniformsiv(GLuint program,
6063 GLsizei uniformCount,
6064 const GLuint *uniformIndices,
6065 GLenum pname,
6066 GLint *params)
6067{
6068 const Program *programObject = getProgram(program);
6069 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6070 {
6071 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08006072 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04006073 }
6074}
6075
6076GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
6077{
6078 const Program *programObject = getProgram(program);
6079 return programObject->getUniformBlockIndex(uniformBlockName);
6080}
6081
6082void Context::getActiveUniformBlockiv(GLuint program,
6083 GLuint uniformBlockIndex,
6084 GLenum pname,
6085 GLint *params)
6086{
6087 const Program *programObject = getProgram(program);
6088 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
6089}
6090
Brandon Jones59770802018-04-02 13:18:42 -07006091void Context::getActiveUniformBlockivRobust(GLuint program,
6092 GLuint uniformBlockIndex,
6093 GLenum pname,
6094 GLsizei bufSize,
6095 GLsizei *length,
6096 GLint *params)
6097{
6098 getActiveUniformBlockiv(program, uniformBlockIndex, pname, params);
6099}
6100
Jamie Madill12e957f2017-08-26 21:42:26 -04006101void Context::getActiveUniformBlockName(GLuint program,
6102 GLuint uniformBlockIndex,
6103 GLsizei bufSize,
6104 GLsizei *length,
6105 GLchar *uniformBlockName)
6106{
6107 const Program *programObject = getProgram(program);
6108 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
6109}
6110
6111void Context::uniformBlockBinding(GLuint program,
6112 GLuint uniformBlockIndex,
6113 GLuint uniformBlockBinding)
6114{
6115 Program *programObject = getProgram(program);
6116 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
6117}
6118
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006119GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
6120{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006121 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
6122 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006123
Jamie Madill70b5bb02017-08-28 13:32:37 -04006124 Sync *syncObject = getSync(syncHandle);
Jamie Madilla0691b72018-07-25 10:41:22 -04006125 Error error = syncObject->set(this, condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006126 if (error.isError())
6127 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04006128 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006129 handleError(error);
6130 return nullptr;
6131 }
6132
Jamie Madill70b5bb02017-08-28 13:32:37 -04006133 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006134}
6135
6136GLboolean Context::isSync(GLsync sync)
6137{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006138 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006139}
6140
6141GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6142{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006143 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006144
6145 GLenum result = GL_WAIT_FAILED;
Jamie Madilla0691b72018-07-25 10:41:22 -04006146 handleError(syncObject->clientWait(this, flags, timeout, &result));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006147 return result;
6148}
6149
6150void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6151{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006152 Sync *syncObject = getSync(sync);
Jamie Madilla0691b72018-07-25 10:41:22 -04006153 handleError(syncObject->serverWait(this, flags, timeout));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006154}
6155
6156void Context::getInteger64v(GLenum pname, GLint64 *params)
6157{
6158 GLenum nativeType = GL_NONE;
6159 unsigned int numParams = 0;
6160 getQueryParameterInfo(pname, &nativeType, &numParams);
6161
6162 if (nativeType == GL_INT_64_ANGLEX)
6163 {
6164 getInteger64vImpl(pname, params);
6165 }
6166 else
6167 {
6168 CastStateValues(this, nativeType, pname, numParams, params);
6169 }
6170}
6171
Brandon Jones59770802018-04-02 13:18:42 -07006172void Context::getInteger64vRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint64 *data)
6173{
6174 getInteger64v(pname, data);
6175}
6176
Corentin Wallez336129f2017-10-17 15:55:40 -04006177void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04006178{
6179 Buffer *buffer = mGLState.getTargetBuffer(target);
6180 QueryBufferParameteri64v(buffer, pname, params);
6181}
6182
Brandon Jones59770802018-04-02 13:18:42 -07006183void Context::getBufferParameteri64vRobust(BufferBinding target,
6184 GLenum pname,
6185 GLsizei bufSize,
6186 GLsizei *length,
6187 GLint64 *params)
6188{
6189 getBufferParameteri64v(target, pname, params);
6190}
6191
Jamie Madill3ef140a2017-08-26 23:11:21 -04006192void Context::genSamplers(GLsizei count, GLuint *samplers)
6193{
6194 for (int i = 0; i < count; i++)
6195 {
6196 samplers[i] = mState.mSamplers->createSampler();
6197 }
6198}
6199
6200void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
6201{
6202 for (int i = 0; i < count; i++)
6203 {
6204 GLuint sampler = samplers[i];
6205
6206 if (mState.mSamplers->getSampler(sampler))
6207 {
6208 detachSampler(sampler);
6209 }
6210
6211 mState.mSamplers->deleteObject(this, sampler);
6212 }
6213}
6214
6215void Context::getInternalformativ(GLenum target,
6216 GLenum internalformat,
6217 GLenum pname,
6218 GLsizei bufSize,
6219 GLint *params)
6220{
6221 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
6222 QueryInternalFormativ(formatCaps, pname, bufSize, params);
6223}
6224
Brandon Jones59770802018-04-02 13:18:42 -07006225void Context::getInternalformativRobust(GLenum target,
6226 GLenum internalformat,
6227 GLenum pname,
6228 GLsizei bufSize,
6229 GLsizei *length,
6230 GLint *params)
6231{
6232 getInternalformativ(target, internalformat, pname, bufSize, params);
6233}
6234
Jiajia Qin5451d532017-11-16 17:16:34 +08006235void Context::programUniform1i(GLuint program, GLint location, GLint v0)
6236{
6237 programUniform1iv(program, location, 1, &v0);
6238}
6239
6240void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
6241{
6242 GLint xy[2] = {v0, v1};
6243 programUniform2iv(program, location, 1, xy);
6244}
6245
6246void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
6247{
6248 GLint xyz[3] = {v0, v1, v2};
6249 programUniform3iv(program, location, 1, xyz);
6250}
6251
6252void Context::programUniform4i(GLuint program,
6253 GLint location,
6254 GLint v0,
6255 GLint v1,
6256 GLint v2,
6257 GLint v3)
6258{
6259 GLint xyzw[4] = {v0, v1, v2, v3};
6260 programUniform4iv(program, location, 1, xyzw);
6261}
6262
6263void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
6264{
6265 programUniform1uiv(program, location, 1, &v0);
6266}
6267
6268void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
6269{
6270 GLuint xy[2] = {v0, v1};
6271 programUniform2uiv(program, location, 1, xy);
6272}
6273
6274void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
6275{
6276 GLuint xyz[3] = {v0, v1, v2};
6277 programUniform3uiv(program, location, 1, xyz);
6278}
6279
6280void Context::programUniform4ui(GLuint program,
6281 GLint location,
6282 GLuint v0,
6283 GLuint v1,
6284 GLuint v2,
6285 GLuint v3)
6286{
6287 GLuint xyzw[4] = {v0, v1, v2, v3};
6288 programUniform4uiv(program, location, 1, xyzw);
6289}
6290
6291void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
6292{
6293 programUniform1fv(program, location, 1, &v0);
6294}
6295
6296void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
6297{
6298 GLfloat xy[2] = {v0, v1};
6299 programUniform2fv(program, location, 1, xy);
6300}
6301
6302void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
6303{
6304 GLfloat xyz[3] = {v0, v1, v2};
6305 programUniform3fv(program, location, 1, xyz);
6306}
6307
6308void Context::programUniform4f(GLuint program,
6309 GLint location,
6310 GLfloat v0,
6311 GLfloat v1,
6312 GLfloat v2,
6313 GLfloat v3)
6314{
6315 GLfloat xyzw[4] = {v0, v1, v2, v3};
6316 programUniform4fv(program, location, 1, xyzw);
6317}
6318
Jamie Madill81c2e252017-09-09 23:32:46 -04006319void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6320{
6321 Program *programObject = getProgram(program);
6322 ASSERT(programObject);
6323 if (programObject->setUniform1iv(location, count, value) ==
6324 Program::SetUniformResult::SamplerChanged)
6325 {
6326 mGLState.setObjectDirty(GL_PROGRAM);
6327 }
6328}
6329
Jiajia Qin5451d532017-11-16 17:16:34 +08006330void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6331{
6332 Program *programObject = getProgram(program);
6333 ASSERT(programObject);
6334 programObject->setUniform2iv(location, count, value);
6335}
6336
6337void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6338{
6339 Program *programObject = getProgram(program);
6340 ASSERT(programObject);
6341 programObject->setUniform3iv(location, count, value);
6342}
6343
6344void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6345{
6346 Program *programObject = getProgram(program);
6347 ASSERT(programObject);
6348 programObject->setUniform4iv(location, count, value);
6349}
6350
6351void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6352{
6353 Program *programObject = getProgram(program);
6354 ASSERT(programObject);
6355 programObject->setUniform1uiv(location, count, value);
6356}
6357
6358void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6359{
6360 Program *programObject = getProgram(program);
6361 ASSERT(programObject);
6362 programObject->setUniform2uiv(location, count, value);
6363}
6364
6365void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6366{
6367 Program *programObject = getProgram(program);
6368 ASSERT(programObject);
6369 programObject->setUniform3uiv(location, count, value);
6370}
6371
6372void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6373{
6374 Program *programObject = getProgram(program);
6375 ASSERT(programObject);
6376 programObject->setUniform4uiv(location, count, value);
6377}
6378
6379void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6380{
6381 Program *programObject = getProgram(program);
6382 ASSERT(programObject);
6383 programObject->setUniform1fv(location, count, value);
6384}
6385
6386void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6387{
6388 Program *programObject = getProgram(program);
6389 ASSERT(programObject);
6390 programObject->setUniform2fv(location, count, value);
6391}
6392
6393void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6394{
6395 Program *programObject = getProgram(program);
6396 ASSERT(programObject);
6397 programObject->setUniform3fv(location, count, value);
6398}
6399
6400void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6401{
6402 Program *programObject = getProgram(program);
6403 ASSERT(programObject);
6404 programObject->setUniform4fv(location, count, value);
6405}
6406
6407void Context::programUniformMatrix2fv(GLuint program,
6408 GLint location,
6409 GLsizei count,
6410 GLboolean transpose,
6411 const GLfloat *value)
6412{
6413 Program *programObject = getProgram(program);
6414 ASSERT(programObject);
6415 programObject->setUniformMatrix2fv(location, count, transpose, value);
6416}
6417
6418void Context::programUniformMatrix3fv(GLuint program,
6419 GLint location,
6420 GLsizei count,
6421 GLboolean transpose,
6422 const GLfloat *value)
6423{
6424 Program *programObject = getProgram(program);
6425 ASSERT(programObject);
6426 programObject->setUniformMatrix3fv(location, count, transpose, value);
6427}
6428
6429void Context::programUniformMatrix4fv(GLuint program,
6430 GLint location,
6431 GLsizei count,
6432 GLboolean transpose,
6433 const GLfloat *value)
6434{
6435 Program *programObject = getProgram(program);
6436 ASSERT(programObject);
6437 programObject->setUniformMatrix4fv(location, count, transpose, value);
6438}
6439
6440void Context::programUniformMatrix2x3fv(GLuint program,
6441 GLint location,
6442 GLsizei count,
6443 GLboolean transpose,
6444 const GLfloat *value)
6445{
6446 Program *programObject = getProgram(program);
6447 ASSERT(programObject);
6448 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
6449}
6450
6451void Context::programUniformMatrix3x2fv(GLuint program,
6452 GLint location,
6453 GLsizei count,
6454 GLboolean transpose,
6455 const GLfloat *value)
6456{
6457 Program *programObject = getProgram(program);
6458 ASSERT(programObject);
6459 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
6460}
6461
6462void Context::programUniformMatrix2x4fv(GLuint program,
6463 GLint location,
6464 GLsizei count,
6465 GLboolean transpose,
6466 const GLfloat *value)
6467{
6468 Program *programObject = getProgram(program);
6469 ASSERT(programObject);
6470 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
6471}
6472
6473void Context::programUniformMatrix4x2fv(GLuint program,
6474 GLint location,
6475 GLsizei count,
6476 GLboolean transpose,
6477 const GLfloat *value)
6478{
6479 Program *programObject = getProgram(program);
6480 ASSERT(programObject);
6481 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
6482}
6483
6484void Context::programUniformMatrix3x4fv(GLuint program,
6485 GLint location,
6486 GLsizei count,
6487 GLboolean transpose,
6488 const GLfloat *value)
6489{
6490 Program *programObject = getProgram(program);
6491 ASSERT(programObject);
6492 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
6493}
6494
6495void Context::programUniformMatrix4x3fv(GLuint program,
6496 GLint location,
6497 GLsizei count,
6498 GLboolean transpose,
6499 const GLfloat *value)
6500{
6501 Program *programObject = getProgram(program);
6502 ASSERT(programObject);
6503 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
6504}
6505
Jamie Madill81c2e252017-09-09 23:32:46 -04006506void Context::onTextureChange(const Texture *texture)
6507{
6508 // Conservatively assume all textures are dirty.
6509 // TODO(jmadill): More fine-grained update.
6510 mGLState.setObjectDirty(GL_TEXTURE);
6511}
6512
James Darpiniane8a93c62018-01-04 18:02:24 -08006513bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
6514{
6515 return mGLState.isCurrentTransformFeedback(tf);
6516}
6517bool Context::isCurrentVertexArray(const VertexArray *va) const
6518{
6519 return mGLState.isCurrentVertexArray(va);
6520}
6521
Yunchao Hea336b902017-08-02 16:05:21 +08006522void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
6523{
6524 for (int i = 0; i < count; i++)
6525 {
6526 pipelines[i] = createProgramPipeline();
6527 }
6528}
6529
6530void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
6531{
6532 for (int i = 0; i < count; i++)
6533 {
6534 if (pipelines[i] != 0)
6535 {
6536 deleteProgramPipeline(pipelines[i]);
6537 }
6538 }
6539}
6540
6541GLboolean Context::isProgramPipeline(GLuint pipeline)
6542{
6543 if (pipeline == 0)
6544 {
6545 return GL_FALSE;
6546 }
6547
6548 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
6549}
6550
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006551void Context::finishFenceNV(GLuint fence)
6552{
6553 FenceNV *fenceObject = getFenceNV(fence);
6554
6555 ASSERT(fenceObject && fenceObject->isSet());
Jamie Madilla0691b72018-07-25 10:41:22 -04006556 handleError(fenceObject->finish(this));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006557}
6558
6559void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
6560{
6561 FenceNV *fenceObject = getFenceNV(fence);
6562
6563 ASSERT(fenceObject && fenceObject->isSet());
6564
6565 switch (pname)
6566 {
6567 case GL_FENCE_STATUS_NV:
6568 {
6569 // GL_NV_fence spec:
6570 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
6571 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
6572 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
6573 GLboolean status = GL_TRUE;
6574 if (fenceObject->getStatus() != GL_TRUE)
6575 {
Jamie Madilla0691b72018-07-25 10:41:22 -04006576 ANGLE_CONTEXT_TRY(fenceObject->test(this, &status));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006577 }
6578 *params = status;
6579 break;
6580 }
6581
6582 case GL_FENCE_CONDITION_NV:
6583 {
6584 *params = static_cast<GLint>(fenceObject->getCondition());
6585 break;
6586 }
6587
6588 default:
6589 UNREACHABLE();
6590 }
6591}
6592
6593void Context::getTranslatedShaderSource(GLuint shader,
6594 GLsizei bufsize,
6595 GLsizei *length,
6596 GLchar *source)
6597{
6598 Shader *shaderObject = getShader(shader);
6599 ASSERT(shaderObject);
6600 shaderObject->getTranslatedSourceWithDebugInfo(this, bufsize, length, source);
6601}
6602
6603void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
6604{
6605 Program *programObject = getProgram(program);
6606 ASSERT(programObject);
6607
6608 programObject->getUniformfv(this, location, params);
6609}
6610
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006611void Context::getnUniformfvRobust(GLuint program,
6612 GLint location,
6613 GLsizei bufSize,
6614 GLsizei *length,
6615 GLfloat *params)
6616{
6617 UNIMPLEMENTED();
6618}
6619
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006620void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
6621{
6622 Program *programObject = getProgram(program);
6623 ASSERT(programObject);
6624
6625 programObject->getUniformiv(this, location, params);
6626}
6627
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006628void Context::getnUniformivRobust(GLuint program,
6629 GLint location,
6630 GLsizei bufSize,
6631 GLsizei *length,
6632 GLint *params)
6633{
6634 UNIMPLEMENTED();
6635}
6636
6637void Context::getnUniformuivRobust(GLuint program,
6638 GLint location,
6639 GLsizei bufSize,
6640 GLsizei *length,
6641 GLuint *params)
6642{
6643 UNIMPLEMENTED();
6644}
6645
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006646GLboolean Context::isFenceNV(GLuint fence)
6647{
6648 FenceNV *fenceObject = getFenceNV(fence);
6649
6650 if (fenceObject == nullptr)
6651 {
6652 return GL_FALSE;
6653 }
6654
6655 // GL_NV_fence spec:
6656 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
6657 // existing fence.
6658 return fenceObject->isSet();
6659}
6660
6661void Context::readnPixels(GLint x,
6662 GLint y,
6663 GLsizei width,
6664 GLsizei height,
6665 GLenum format,
6666 GLenum type,
6667 GLsizei bufSize,
6668 void *data)
6669{
6670 return readPixels(x, y, width, height, format, type, data);
6671}
6672
Jamie Madill007530e2017-12-28 14:27:04 -05006673void Context::setFenceNV(GLuint fence, GLenum condition)
6674{
6675 ASSERT(condition == GL_ALL_COMPLETED_NV);
6676
6677 FenceNV *fenceObject = getFenceNV(fence);
6678 ASSERT(fenceObject != nullptr);
Jamie Madilla0691b72018-07-25 10:41:22 -04006679 handleError(fenceObject->set(this, condition));
Jamie Madill007530e2017-12-28 14:27:04 -05006680}
6681
6682GLboolean Context::testFenceNV(GLuint fence)
6683{
6684 FenceNV *fenceObject = getFenceNV(fence);
6685
6686 ASSERT(fenceObject != nullptr);
6687 ASSERT(fenceObject->isSet() == GL_TRUE);
6688
6689 GLboolean result = GL_TRUE;
Jamie Madilla0691b72018-07-25 10:41:22 -04006690 Error error = fenceObject->test(this, &result);
Jamie Madill007530e2017-12-28 14:27:04 -05006691 if (error.isError())
6692 {
6693 handleError(error);
6694 return GL_TRUE;
6695 }
6696
6697 return result;
6698}
6699
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006700void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006701{
6702 Texture *texture = getTargetTexture(target);
Rafael Cintron05a449a2018-06-20 18:08:04 -07006703 egl::Image *imageObject = static_cast<egl::Image *>(image);
Corentin Wallez99d492c2018-02-27 15:17:10 -05006704 handleError(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05006705}
6706
Jamie Madillfa920eb2018-01-04 11:45:50 -05006707void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006708{
6709 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Rafael Cintron05a449a2018-06-20 18:08:04 -07006710 egl::Image *imageObject = static_cast<egl::Image *>(image);
Jamie Madill007530e2017-12-28 14:27:04 -05006711 handleError(renderbuffer->setStorageEGLImageTarget(this, imageObject));
6712}
6713
Jamie Madillfa920eb2018-01-04 11:45:50 -05006714void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
6715{
6716 UNIMPLEMENTED();
6717}
6718
Jamie Madill5b772312018-03-08 20:28:32 -05006719bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
6720{
6721 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
6722 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
6723 // to the fact that it is stored internally as a float, and so would require conversion
6724 // if returned from Context::getIntegerv. Since this conversion is already implemented
6725 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
6726 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
6727 // application.
6728 switch (pname)
6729 {
6730 case GL_COMPRESSED_TEXTURE_FORMATS:
6731 {
6732 *type = GL_INT;
6733 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
6734 return true;
6735 }
6736 case GL_SHADER_BINARY_FORMATS:
6737 {
6738 *type = GL_INT;
6739 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
6740 return true;
6741 }
6742
6743 case GL_MAX_VERTEX_ATTRIBS:
6744 case GL_MAX_VERTEX_UNIFORM_VECTORS:
6745 case GL_MAX_VARYING_VECTORS:
6746 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
6747 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
6748 case GL_MAX_TEXTURE_IMAGE_UNITS:
6749 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
6750 case GL_MAX_RENDERBUFFER_SIZE:
6751 case GL_NUM_SHADER_BINARY_FORMATS:
6752 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
6753 case GL_ARRAY_BUFFER_BINDING:
6754 case GL_FRAMEBUFFER_BINDING:
6755 case GL_RENDERBUFFER_BINDING:
6756 case GL_CURRENT_PROGRAM:
6757 case GL_PACK_ALIGNMENT:
6758 case GL_UNPACK_ALIGNMENT:
6759 case GL_GENERATE_MIPMAP_HINT:
6760 case GL_RED_BITS:
6761 case GL_GREEN_BITS:
6762 case GL_BLUE_BITS:
6763 case GL_ALPHA_BITS:
6764 case GL_DEPTH_BITS:
6765 case GL_STENCIL_BITS:
6766 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
6767 case GL_CULL_FACE_MODE:
6768 case GL_FRONT_FACE:
6769 case GL_ACTIVE_TEXTURE:
6770 case GL_STENCIL_FUNC:
6771 case GL_STENCIL_VALUE_MASK:
6772 case GL_STENCIL_REF:
6773 case GL_STENCIL_FAIL:
6774 case GL_STENCIL_PASS_DEPTH_FAIL:
6775 case GL_STENCIL_PASS_DEPTH_PASS:
6776 case GL_STENCIL_BACK_FUNC:
6777 case GL_STENCIL_BACK_VALUE_MASK:
6778 case GL_STENCIL_BACK_REF:
6779 case GL_STENCIL_BACK_FAIL:
6780 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
6781 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
6782 case GL_DEPTH_FUNC:
6783 case GL_BLEND_SRC_RGB:
6784 case GL_BLEND_SRC_ALPHA:
6785 case GL_BLEND_DST_RGB:
6786 case GL_BLEND_DST_ALPHA:
6787 case GL_BLEND_EQUATION_RGB:
6788 case GL_BLEND_EQUATION_ALPHA:
6789 case GL_STENCIL_WRITEMASK:
6790 case GL_STENCIL_BACK_WRITEMASK:
6791 case GL_STENCIL_CLEAR_VALUE:
6792 case GL_SUBPIXEL_BITS:
6793 case GL_MAX_TEXTURE_SIZE:
6794 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
6795 case GL_SAMPLE_BUFFERS:
6796 case GL_SAMPLES:
6797 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
6798 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
6799 case GL_TEXTURE_BINDING_2D:
6800 case GL_TEXTURE_BINDING_CUBE_MAP:
6801 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
6802 {
6803 *type = GL_INT;
6804 *numParams = 1;
6805 return true;
6806 }
6807 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6808 {
6809 if (!getExtensions().packReverseRowOrder)
6810 {
6811 return false;
6812 }
6813 *type = GL_INT;
6814 *numParams = 1;
6815 return true;
6816 }
6817 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
6818 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
6819 {
6820 if (!getExtensions().textureRectangle)
6821 {
6822 return false;
6823 }
6824 *type = GL_INT;
6825 *numParams = 1;
6826 return true;
6827 }
6828 case GL_MAX_DRAW_BUFFERS_EXT:
6829 case GL_MAX_COLOR_ATTACHMENTS_EXT:
6830 {
6831 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
6832 {
6833 return false;
6834 }
6835 *type = GL_INT;
6836 *numParams = 1;
6837 return true;
6838 }
6839 case GL_MAX_VIEWPORT_DIMS:
6840 {
6841 *type = GL_INT;
6842 *numParams = 2;
6843 return true;
6844 }
6845 case GL_VIEWPORT:
6846 case GL_SCISSOR_BOX:
6847 {
6848 *type = GL_INT;
6849 *numParams = 4;
6850 return true;
6851 }
6852 case GL_SHADER_COMPILER:
6853 case GL_SAMPLE_COVERAGE_INVERT:
6854 case GL_DEPTH_WRITEMASK:
6855 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
6856 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
6857 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
6858 // bool-natural
6859 case GL_SAMPLE_COVERAGE:
6860 case GL_SCISSOR_TEST:
6861 case GL_STENCIL_TEST:
6862 case GL_DEPTH_TEST:
6863 case GL_BLEND:
6864 case GL_DITHER:
6865 case GL_CONTEXT_ROBUST_ACCESS_EXT:
6866 {
6867 *type = GL_BOOL;
6868 *numParams = 1;
6869 return true;
6870 }
6871 case GL_COLOR_WRITEMASK:
6872 {
6873 *type = GL_BOOL;
6874 *numParams = 4;
6875 return true;
6876 }
6877 case GL_POLYGON_OFFSET_FACTOR:
6878 case GL_POLYGON_OFFSET_UNITS:
6879 case GL_SAMPLE_COVERAGE_VALUE:
6880 case GL_DEPTH_CLEAR_VALUE:
6881 case GL_LINE_WIDTH:
6882 {
6883 *type = GL_FLOAT;
6884 *numParams = 1;
6885 return true;
6886 }
6887 case GL_ALIASED_LINE_WIDTH_RANGE:
6888 case GL_ALIASED_POINT_SIZE_RANGE:
6889 case GL_DEPTH_RANGE:
6890 {
6891 *type = GL_FLOAT;
6892 *numParams = 2;
6893 return true;
6894 }
6895 case GL_COLOR_CLEAR_VALUE:
6896 case GL_BLEND_COLOR:
6897 {
6898 *type = GL_FLOAT;
6899 *numParams = 4;
6900 return true;
6901 }
6902 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
6903 if (!getExtensions().textureFilterAnisotropic)
6904 {
6905 return false;
6906 }
6907 *type = GL_FLOAT;
6908 *numParams = 1;
6909 return true;
6910 case GL_TIMESTAMP_EXT:
6911 if (!getExtensions().disjointTimerQuery)
6912 {
6913 return false;
6914 }
6915 *type = GL_INT_64_ANGLEX;
6916 *numParams = 1;
6917 return true;
6918 case GL_GPU_DISJOINT_EXT:
6919 if (!getExtensions().disjointTimerQuery)
6920 {
6921 return false;
6922 }
6923 *type = GL_INT;
6924 *numParams = 1;
6925 return true;
6926 case GL_COVERAGE_MODULATION_CHROMIUM:
6927 if (!getExtensions().framebufferMixedSamples)
6928 {
6929 return false;
6930 }
6931 *type = GL_INT;
6932 *numParams = 1;
6933 return true;
6934 case GL_TEXTURE_BINDING_EXTERNAL_OES:
6935 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
6936 {
6937 return false;
6938 }
6939 *type = GL_INT;
6940 *numParams = 1;
6941 return true;
6942 }
6943
6944 if (getExtensions().debug)
6945 {
6946 switch (pname)
6947 {
6948 case GL_DEBUG_LOGGED_MESSAGES:
6949 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
6950 case GL_DEBUG_GROUP_STACK_DEPTH:
6951 case GL_MAX_DEBUG_MESSAGE_LENGTH:
6952 case GL_MAX_DEBUG_LOGGED_MESSAGES:
6953 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
6954 case GL_MAX_LABEL_LENGTH:
6955 *type = GL_INT;
6956 *numParams = 1;
6957 return true;
6958
6959 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
6960 case GL_DEBUG_OUTPUT:
6961 *type = GL_BOOL;
6962 *numParams = 1;
6963 return true;
6964 }
6965 }
6966
6967 if (getExtensions().multisampleCompatibility)
6968 {
6969 switch (pname)
6970 {
6971 case GL_MULTISAMPLE_EXT:
6972 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
6973 *type = GL_BOOL;
6974 *numParams = 1;
6975 return true;
6976 }
6977 }
6978
6979 if (getExtensions().pathRendering)
6980 {
6981 switch (pname)
6982 {
6983 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
6984 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
6985 *type = GL_FLOAT;
6986 *numParams = 16;
6987 return true;
6988 }
6989 }
6990
6991 if (getExtensions().bindGeneratesResource)
6992 {
6993 switch (pname)
6994 {
6995 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
6996 *type = GL_BOOL;
6997 *numParams = 1;
6998 return true;
6999 }
7000 }
7001
7002 if (getExtensions().clientArrays)
7003 {
7004 switch (pname)
7005 {
7006 case GL_CLIENT_ARRAYS_ANGLE:
7007 *type = GL_BOOL;
7008 *numParams = 1;
7009 return true;
7010 }
7011 }
7012
7013 if (getExtensions().sRGBWriteControl)
7014 {
7015 switch (pname)
7016 {
7017 case GL_FRAMEBUFFER_SRGB_EXT:
7018 *type = GL_BOOL;
7019 *numParams = 1;
7020 return true;
7021 }
7022 }
7023
7024 if (getExtensions().robustResourceInitialization &&
7025 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
7026 {
7027 *type = GL_BOOL;
7028 *numParams = 1;
7029 return true;
7030 }
7031
7032 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
7033 {
7034 *type = GL_BOOL;
7035 *numParams = 1;
7036 return true;
7037 }
7038
jchen1082af6202018-06-22 10:59:52 +08007039 if (getExtensions().parallelShaderCompile && pname == GL_MAX_SHADER_COMPILER_THREADS_KHR)
7040 {
7041 *type = GL_INT;
7042 *numParams = 1;
7043 return true;
7044 }
7045
Jamie Madill5b772312018-03-08 20:28:32 -05007046 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
7047 switch (pname)
7048 {
7049 // case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE // equivalent to FRAMEBUFFER_BINDING
7050 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
7051 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
7052 {
7053 return false;
7054 }
7055 *type = GL_INT;
7056 *numParams = 1;
7057 return true;
7058
7059 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
7060 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7061 {
7062 return false;
7063 }
7064 *type = GL_INT;
7065 *numParams = 1;
7066 return true;
7067
7068 case GL_PROGRAM_BINARY_FORMATS_OES:
7069 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7070 {
7071 return false;
7072 }
7073 *type = GL_INT;
7074 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
7075 return true;
7076
7077 case GL_PACK_ROW_LENGTH:
7078 case GL_PACK_SKIP_ROWS:
7079 case GL_PACK_SKIP_PIXELS:
7080 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
7081 {
7082 return false;
7083 }
7084 *type = GL_INT;
7085 *numParams = 1;
7086 return true;
7087 case GL_UNPACK_ROW_LENGTH:
7088 case GL_UNPACK_SKIP_ROWS:
7089 case GL_UNPACK_SKIP_PIXELS:
7090 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
7091 {
7092 return false;
7093 }
7094 *type = GL_INT;
7095 *numParams = 1;
7096 return true;
7097 case GL_VERTEX_ARRAY_BINDING:
7098 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
7099 {
7100 return false;
7101 }
7102 *type = GL_INT;
7103 *numParams = 1;
7104 return true;
7105 case GL_PIXEL_PACK_BUFFER_BINDING:
7106 case GL_PIXEL_UNPACK_BUFFER_BINDING:
7107 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
7108 {
7109 return false;
7110 }
7111 *type = GL_INT;
7112 *numParams = 1;
7113 return true;
7114 case GL_MAX_SAMPLES:
7115 {
7116 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
7117 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
7118 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
7119 {
7120 return false;
7121 }
7122 *type = GL_INT;
7123 *numParams = 1;
7124 return true;
7125
7126 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
7127 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
7128 {
7129 return false;
7130 }
7131 *type = GL_INT;
7132 *numParams = 1;
7133 return true;
7134 }
7135 }
7136
7137 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
7138 {
7139 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
7140 {
7141 return false;
7142 }
7143 *type = GL_INT;
7144 *numParams = 1;
7145 return true;
7146 }
7147
7148 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
7149 {
7150 *type = GL_INT;
7151 *numParams = 1;
7152 return true;
7153 }
7154
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007155 if (getClientVersion() < Version(2, 0))
7156 {
7157 switch (pname)
7158 {
7159 case GL_ALPHA_TEST_FUNC:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007160 case GL_CLIENT_ACTIVE_TEXTURE:
7161 case GL_MATRIX_MODE:
7162 case GL_MAX_TEXTURE_UNITS:
7163 case GL_MAX_MODELVIEW_STACK_DEPTH:
7164 case GL_MAX_PROJECTION_STACK_DEPTH:
7165 case GL_MAX_TEXTURE_STACK_DEPTH:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007166 case GL_MAX_LIGHTS:
Lingfeng Yang060088a2018-05-30 20:40:57 -07007167 case GL_MAX_CLIP_PLANES:
Lingfeng Yangabb09f12018-04-16 10:43:53 -07007168 case GL_VERTEX_ARRAY_STRIDE:
7169 case GL_NORMAL_ARRAY_STRIDE:
7170 case GL_COLOR_ARRAY_STRIDE:
7171 case GL_TEXTURE_COORD_ARRAY_STRIDE:
7172 case GL_VERTEX_ARRAY_SIZE:
7173 case GL_COLOR_ARRAY_SIZE:
7174 case GL_TEXTURE_COORD_ARRAY_SIZE:
7175 case GL_VERTEX_ARRAY_TYPE:
7176 case GL_NORMAL_ARRAY_TYPE:
7177 case GL_COLOR_ARRAY_TYPE:
7178 case GL_TEXTURE_COORD_ARRAY_TYPE:
7179 case GL_VERTEX_ARRAY_BUFFER_BINDING:
7180 case GL_NORMAL_ARRAY_BUFFER_BINDING:
7181 case GL_COLOR_ARRAY_BUFFER_BINDING:
7182 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
7183 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
7184 case GL_POINT_SIZE_ARRAY_TYPE_OES:
7185 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
Lingfeng Yanga0cfa872018-05-30 21:12:17 -07007186 case GL_SHADE_MODEL:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007187 *type = GL_INT;
7188 *numParams = 1;
7189 return true;
7190 case GL_ALPHA_TEST_REF:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007191 case GL_FOG_DENSITY:
7192 case GL_FOG_START:
7193 case GL_FOG_END:
7194 case GL_FOG_MODE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007195 case GL_POINT_SIZE:
7196 case GL_POINT_SIZE_MIN:
7197 case GL_POINT_SIZE_MAX:
7198 case GL_POINT_FADE_THRESHOLD_SIZE:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007199 *type = GL_FLOAT;
7200 *numParams = 1;
7201 return true;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007202 case GL_SMOOTH_POINT_SIZE_RANGE:
7203 *type = GL_FLOAT;
7204 *numParams = 2;
7205 return true;
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007206 case GL_CURRENT_COLOR:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007207 case GL_CURRENT_TEXTURE_COORDS:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007208 case GL_LIGHT_MODEL_AMBIENT:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007209 case GL_FOG_COLOR:
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007210 *type = GL_FLOAT;
7211 *numParams = 4;
7212 return true;
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007213 case GL_CURRENT_NORMAL:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007214 case GL_POINT_DISTANCE_ATTENUATION:
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007215 *type = GL_FLOAT;
7216 *numParams = 3;
7217 return true;
Lingfeng Yang3a41af62018-04-09 07:28:56 -07007218 case GL_MODELVIEW_MATRIX:
7219 case GL_PROJECTION_MATRIX:
7220 case GL_TEXTURE_MATRIX:
7221 *type = GL_FLOAT;
7222 *numParams = 16;
7223 return true;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007224 case GL_LIGHT_MODEL_TWO_SIDE:
7225 *type = GL_BOOL;
7226 *numParams = 1;
7227 return true;
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007228 }
7229 }
7230
Jamie Madill5b772312018-03-08 20:28:32 -05007231 if (getClientVersion() < Version(3, 0))
7232 {
7233 return false;
7234 }
7235
7236 // Check for ES3.0+ parameter names
7237 switch (pname)
7238 {
7239 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
7240 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
7241 case GL_UNIFORM_BUFFER_BINDING:
7242 case GL_TRANSFORM_FEEDBACK_BINDING:
7243 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7244 case GL_COPY_READ_BUFFER_BINDING:
7245 case GL_COPY_WRITE_BUFFER_BINDING:
7246 case GL_SAMPLER_BINDING:
7247 case GL_READ_BUFFER:
7248 case GL_TEXTURE_BINDING_3D:
7249 case GL_TEXTURE_BINDING_2D_ARRAY:
7250 case GL_MAX_3D_TEXTURE_SIZE:
7251 case GL_MAX_ARRAY_TEXTURE_LAYERS:
7252 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
7253 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
7254 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
7255 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
7256 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
7257 case GL_MAX_VARYING_COMPONENTS:
7258 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
7259 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
7260 case GL_MIN_PROGRAM_TEXEL_OFFSET:
7261 case GL_MAX_PROGRAM_TEXEL_OFFSET:
7262 case GL_NUM_EXTENSIONS:
7263 case GL_MAJOR_VERSION:
7264 case GL_MINOR_VERSION:
7265 case GL_MAX_ELEMENTS_INDICES:
7266 case GL_MAX_ELEMENTS_VERTICES:
7267 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
7268 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
7269 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
7270 case GL_UNPACK_IMAGE_HEIGHT:
7271 case GL_UNPACK_SKIP_IMAGES:
7272 {
7273 *type = GL_INT;
7274 *numParams = 1;
7275 return true;
7276 }
7277
7278 case GL_MAX_ELEMENT_INDEX:
7279 case GL_MAX_UNIFORM_BLOCK_SIZE:
7280 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
7281 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
7282 case GL_MAX_SERVER_WAIT_TIMEOUT:
7283 {
7284 *type = GL_INT_64_ANGLEX;
7285 *numParams = 1;
7286 return true;
7287 }
7288
7289 case GL_TRANSFORM_FEEDBACK_ACTIVE:
7290 case GL_TRANSFORM_FEEDBACK_PAUSED:
7291 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
7292 case GL_RASTERIZER_DISCARD:
7293 {
7294 *type = GL_BOOL;
7295 *numParams = 1;
7296 return true;
7297 }
7298
7299 case GL_MAX_TEXTURE_LOD_BIAS:
7300 {
7301 *type = GL_FLOAT;
7302 *numParams = 1;
7303 return true;
7304 }
7305 }
7306
7307 if (getExtensions().requestExtension)
7308 {
7309 switch (pname)
7310 {
7311 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
7312 *type = GL_INT;
7313 *numParams = 1;
7314 return true;
7315 }
7316 }
7317
7318 if (getClientVersion() < Version(3, 1))
7319 {
7320 return false;
7321 }
7322
7323 switch (pname)
7324 {
7325 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7326 case GL_DRAW_INDIRECT_BUFFER_BINDING:
7327 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
7328 case GL_MAX_FRAMEBUFFER_WIDTH:
7329 case GL_MAX_FRAMEBUFFER_HEIGHT:
7330 case GL_MAX_FRAMEBUFFER_SAMPLES:
7331 case GL_MAX_SAMPLE_MASK_WORDS:
7332 case GL_MAX_COLOR_TEXTURE_SAMPLES:
7333 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
7334 case GL_MAX_INTEGER_SAMPLES:
7335 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
7336 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
7337 case GL_MAX_VERTEX_ATTRIB_STRIDE:
7338 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
7339 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
7340 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
7341 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
7342 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
7343 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
7344 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
7345 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
7346 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
7347 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
7348 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
7349 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
7350 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
7351 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
7352 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
7353 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
7354 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
7355 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
7356 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
7357 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
7358 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
7359 case GL_MAX_UNIFORM_LOCATIONS:
7360 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
7361 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
7362 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
7363 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
7364 case GL_MAX_IMAGE_UNITS:
7365 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
7366 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
7367 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
7368 case GL_SHADER_STORAGE_BUFFER_BINDING:
7369 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
7370 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
7371 *type = GL_INT;
7372 *numParams = 1;
7373 return true;
7374 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7375 *type = GL_INT_64_ANGLEX;
7376 *numParams = 1;
7377 return true;
7378 case GL_SAMPLE_MASK:
7379 *type = GL_BOOL;
7380 *numParams = 1;
7381 return true;
7382 }
7383
7384 if (getExtensions().geometryShader)
7385 {
7386 switch (pname)
7387 {
7388 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7389 case GL_LAYER_PROVOKING_VERTEX_EXT:
7390 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7391 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7392 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7393 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7394 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7395 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7396 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7397 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7398 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7399 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7400 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7401 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7402 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7403 *type = GL_INT;
7404 *numParams = 1;
7405 return true;
7406 }
7407 }
7408
7409 return false;
7410}
7411
7412bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7413{
7414 if (getClientVersion() < Version(3, 0))
7415 {
7416 return false;
7417 }
7418
7419 switch (target)
7420 {
7421 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7422 case GL_UNIFORM_BUFFER_BINDING:
7423 {
7424 *type = GL_INT;
7425 *numParams = 1;
7426 return true;
7427 }
7428 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7429 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7430 case GL_UNIFORM_BUFFER_START:
7431 case GL_UNIFORM_BUFFER_SIZE:
7432 {
7433 *type = GL_INT_64_ANGLEX;
7434 *numParams = 1;
7435 return true;
7436 }
7437 }
7438
7439 if (getClientVersion() < Version(3, 1))
7440 {
7441 return false;
7442 }
7443
7444 switch (target)
7445 {
7446 case GL_IMAGE_BINDING_LAYERED:
7447 {
7448 *type = GL_BOOL;
7449 *numParams = 1;
7450 return true;
7451 }
7452 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7453 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7454 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7455 case GL_SHADER_STORAGE_BUFFER_BINDING:
7456 case GL_VERTEX_BINDING_BUFFER:
7457 case GL_VERTEX_BINDING_DIVISOR:
7458 case GL_VERTEX_BINDING_OFFSET:
7459 case GL_VERTEX_BINDING_STRIDE:
7460 case GL_SAMPLE_MASK_VALUE:
7461 case GL_IMAGE_BINDING_NAME:
7462 case GL_IMAGE_BINDING_LEVEL:
7463 case GL_IMAGE_BINDING_LAYER:
7464 case GL_IMAGE_BINDING_ACCESS:
7465 case GL_IMAGE_BINDING_FORMAT:
7466 {
7467 *type = GL_INT;
7468 *numParams = 1;
7469 return true;
7470 }
7471 case GL_ATOMIC_COUNTER_BUFFER_START:
7472 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
7473 case GL_SHADER_STORAGE_BUFFER_START:
7474 case GL_SHADER_STORAGE_BUFFER_SIZE:
7475 {
7476 *type = GL_INT_64_ANGLEX;
7477 *numParams = 1;
7478 return true;
7479 }
7480 }
7481
7482 return false;
7483}
7484
7485Program *Context::getProgram(GLuint handle) const
7486{
7487 return mState.mShaderPrograms->getProgram(handle);
7488}
7489
7490Shader *Context::getShader(GLuint handle) const
7491{
7492 return mState.mShaderPrograms->getShader(handle);
7493}
7494
7495bool Context::isTextureGenerated(GLuint texture) const
7496{
7497 return mState.mTextures->isHandleGenerated(texture);
7498}
7499
7500bool Context::isBufferGenerated(GLuint buffer) const
7501{
7502 return mState.mBuffers->isHandleGenerated(buffer);
7503}
7504
7505bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
7506{
7507 return mState.mRenderbuffers->isHandleGenerated(renderbuffer);
7508}
7509
7510bool Context::isFramebufferGenerated(GLuint framebuffer) const
7511{
7512 return mState.mFramebuffers->isHandleGenerated(framebuffer);
7513}
7514
7515bool Context::isProgramPipelineGenerated(GLuint pipeline) const
7516{
7517 return mState.mPipelines->isHandleGenerated(pipeline);
7518}
7519
7520bool Context::usingDisplayTextureShareGroup() const
7521{
7522 return mDisplayTextureShareGroup;
7523}
7524
7525GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
7526{
7527 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
7528 internalformat == GL_DEPTH_STENCIL
7529 ? GL_DEPTH24_STENCIL8
7530 : internalformat;
7531}
7532
jchen1082af6202018-06-22 10:59:52 +08007533void Context::maxShaderCompilerThreads(GLuint count)
7534{
7535 mGLState.setMaxShaderCompilerThreads(count);
7536}
7537
Jamie Madill6b873dd2018-07-12 23:56:30 -04007538// ErrorSet implementation.
7539ErrorSet::ErrorSet(Context *context) : mContext(context)
7540{
7541}
7542
7543ErrorSet::~ErrorSet() = default;
7544
7545void ErrorSet::handleError(const Error &error)
7546{
7547 // This internal enum is used to filter internal errors that are already handled.
7548 // TODO(jmadill): Remove this when refactor is done. http://anglebug.com/2491
7549 if (error.getCode() == GL_INTERNAL_ERROR_ANGLEX)
7550 {
7551 return;
7552 }
7553
7554 if (ANGLE_UNLIKELY(error.isError()))
7555 {
7556 GLenum code = error.getCode();
7557 mErrors.insert(code);
7558 if (code == GL_OUT_OF_MEMORY && mContext->getWorkarounds().loseContextOnOutOfMemory)
7559 {
7560 mContext->markContextLost();
7561 }
7562
7563 ASSERT(!error.getMessage().empty());
7564 mContext->getGLState().getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR,
7565 error.getID(), GL_DEBUG_SEVERITY_HIGH,
7566 error.getMessage());
7567 }
7568}
7569
7570bool ErrorSet::empty() const
7571{
7572 return mErrors.empty();
7573}
7574
7575GLenum ErrorSet::popError()
7576{
7577 ASSERT(!empty());
7578 GLenum error = *mErrors.begin();
7579 mErrors.erase(mErrors.begin());
7580 return error;
7581}
Jamie Madillc29968b2016-01-20 11:17:23 -05007582} // namespace gl