blob: eb9195861db75602868c9469550afdab65d352c9 [file] [log] [blame]
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001//
Geoff Langeeba6e12014-02-03 13:12:30 -05002// Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7// Context.cpp: Implements the gl::Context class, managing all GL state and performing
8// rendering operations. It is the GLES2 specific implementation of EGLContext.
9
Geoff Lang2b5420c2014-11-19 14:20:15 -050010#include "libANGLE/Context.h"
apatrick@chromium.org144f2802012-07-12 01:42:34 +000011
Jamie Madill231c7f52017-04-26 13:45:37 -040012#include <string.h>
Jamie Madillb9293972015-02-19 11:07:54 -050013#include <iterator>
14#include <sstream>
Sami Väisänend59ca052016-06-21 16:10:00 +030015#include <vector>
Jamie Madillb9293972015-02-19 11:07:54 -050016
Tobin Ehlisd7890bc2018-06-29 11:57:22 -060017#include "common/PackedEnums.h"
Sami Väisänene45e53b2016-05-25 10:36:04 +030018#include "common/matrix_utils.h"
Geoff Lang0b7eef72014-06-12 14:10:47 -040019#include "common/platform.h"
Jamie Madillb9293972015-02-19 11:07:54 -050020#include "common/utilities.h"
Geoff Langc339c4e2016-11-29 10:37:36 -050021#include "common/version.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050022#include "libANGLE/Buffer.h"
Jamie Madillb9293972015-02-19 11:07:54 -050023#include "libANGLE/Compiler.h"
Jamie Madill948bbe52017-06-01 13:10:42 -040024#include "libANGLE/Display.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050025#include "libANGLE/Fence.h"
26#include "libANGLE/Framebuffer.h"
27#include "libANGLE/FramebufferAttachment.h"
Lingfeng Yang461b09a2018-04-23 09:02:09 -070028#include "libANGLE/GLES1Renderer.h"
Sami Väisänene45e53b2016-05-25 10:36:04 +030029#include "libANGLE/Path.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050030#include "libANGLE/Program.h"
Yunchao Hea336b902017-08-02 16:05:21 +080031#include "libANGLE/ProgramPipeline.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050032#include "libANGLE/Query.h"
Jamie Madillb9293972015-02-19 11:07:54 -050033#include "libANGLE/Renderbuffer.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050034#include "libANGLE/ResourceManager.h"
35#include "libANGLE/Sampler.h"
Jamie Madill9dd0cf02014-11-24 11:38:51 -050036#include "libANGLE/Surface.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050037#include "libANGLE/Texture.h"
38#include "libANGLE/TransformFeedback.h"
39#include "libANGLE/VertexArray.h"
Kenneth Russellf2f6f652016-10-05 19:53:23 -070040#include "libANGLE/Workarounds.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040041#include "libANGLE/formatutils.h"
Martin Radev66fb8202016-07-28 11:45:20 +030042#include "libANGLE/queryconversions.h"
Geoff Langc1984ed2016-10-07 12:41:00 -040043#include "libANGLE/queryutils.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040044#include "libANGLE/renderer/ContextImpl.h"
45#include "libANGLE/renderer/EGLImplFactory.h"
Jamie Madill7b62cf92017-11-02 15:20:49 -040046#include "libANGLE/renderer/Format.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040047#include "libANGLE/validationES.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000048
Geoff Langf6db0982015-08-25 13:04:00 -040049namespace
50{
51
Jamie Madillb6664922017-07-25 12:55:04 -040052#define ANGLE_HANDLE_ERR(X) \
53 handleError(X); \
54 return;
55#define ANGLE_CONTEXT_TRY(EXPR) ANGLE_TRY_TEMPLATE(EXPR, ANGLE_HANDLE_ERR);
56
Ian Ewell3ffd78b2016-01-22 16:09:42 -050057template <typename T>
Geoff Lang4ddf5af2016-12-01 14:30:44 -050058std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager,
Sami Väisänend59ca052016-06-21 16:10:00 +030059 GLsizei numPaths,
60 const void *paths,
61 GLuint pathBase)
62{
63 std::vector<gl::Path *> ret;
64 ret.reserve(numPaths);
65
66 const auto *nameArray = static_cast<const T *>(paths);
67
68 for (GLsizei i = 0; i < numPaths; ++i)
69 {
70 const GLuint pathName = nameArray[i] + pathBase;
71
72 ret.push_back(resourceManager.getPath(pathName));
73 }
74
75 return ret;
76}
77
Geoff Lang4ddf5af2016-12-01 14:30:44 -050078std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager,
Sami Väisänend59ca052016-06-21 16:10:00 +030079 GLsizei numPaths,
80 GLenum pathNameType,
81 const void *paths,
82 GLuint pathBase)
83{
84 switch (pathNameType)
85 {
86 case GL_UNSIGNED_BYTE:
87 return GatherPaths<GLubyte>(resourceManager, numPaths, paths, pathBase);
88
89 case GL_BYTE:
90 return GatherPaths<GLbyte>(resourceManager, numPaths, paths, pathBase);
91
92 case GL_UNSIGNED_SHORT:
93 return GatherPaths<GLushort>(resourceManager, numPaths, paths, pathBase);
94
95 case GL_SHORT:
96 return GatherPaths<GLshort>(resourceManager, numPaths, paths, pathBase);
97
98 case GL_UNSIGNED_INT:
99 return GatherPaths<GLuint>(resourceManager, numPaths, paths, pathBase);
100
101 case GL_INT:
102 return GatherPaths<GLint>(resourceManager, numPaths, paths, pathBase);
103 }
104
105 UNREACHABLE();
106 return std::vector<gl::Path *>();
107}
108
109template <typename T>
Jamie Madill5188a272018-07-25 10:53:56 -0400110gl::Error GetQueryObjectParameter(const gl::Context *context,
111 gl::Query *query,
112 GLenum pname,
113 T *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500114{
Geoff Lang2186c382016-10-14 10:54:54 -0400115 ASSERT(query != nullptr);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500116
117 switch (pname)
118 {
119 case GL_QUERY_RESULT_EXT:
Jamie Madill5188a272018-07-25 10:53:56 -0400120 return query->getResult(context, params);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500121 case GL_QUERY_RESULT_AVAILABLE_EXT:
122 {
123 bool available;
Jamie Madill5188a272018-07-25 10:53:56 -0400124 gl::Error error = query->isResultAvailable(context, &available);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500125 if (!error.isError())
126 {
jchen10a99ed552017-09-22 08:10:32 +0800127 *params = gl::CastFromStateValue<T>(pname, static_cast<GLuint>(available));
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500128 }
129 return error;
130 }
131 default:
132 UNREACHABLE();
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500133 return gl::InternalError() << "Unreachable Error";
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500134 }
135}
136
Jamie Madill09463932018-04-04 05:26:59 -0400137void MarkTransformFeedbackBufferUsage(const gl::Context *context,
138 gl::TransformFeedback *transformFeedback,
James Darpinian30b604d2018-03-12 17:26:57 -0700139 GLsizei count,
140 GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -0400141{
Geoff Lang1a683462015-09-29 15:09:59 -0400142 if (transformFeedback && transformFeedback->isActive() && !transformFeedback->isPaused())
Geoff Langf6db0982015-08-25 13:04:00 -0400143 {
Jamie Madill09463932018-04-04 05:26:59 -0400144 transformFeedback->onVerticesDrawn(context, count, instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -0400145 }
146}
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500147
148// Attribute map queries.
Martin Radev1be913c2016-07-11 17:59:16 +0300149EGLint GetClientMajorVersion(const egl::AttributeMap &attribs)
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500150{
Ian Ewellec2c0c52016-04-05 13:46:26 -0400151 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_CLIENT_VERSION, 1));
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500152}
153
Martin Radev1be913c2016-07-11 17:59:16 +0300154EGLint GetClientMinorVersion(const egl::AttributeMap &attribs)
155{
156 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_MINOR_VERSION, 0));
157}
158
Geoff Langeb66a6e2016-10-31 13:06:12 -0400159gl::Version GetClientVersion(const egl::AttributeMap &attribs)
160{
161 return gl::Version(GetClientMajorVersion(attribs), GetClientMinorVersion(attribs));
162}
163
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500164GLenum GetResetStrategy(const egl::AttributeMap &attribs)
165{
Lingfeng Yangb27b03a2018-02-19 13:38:48 -0800166 EGLAttrib attrib =
167 attribs.get(EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT, EGL_NO_RESET_NOTIFICATION);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500168 switch (attrib)
169 {
170 case EGL_NO_RESET_NOTIFICATION:
171 return GL_NO_RESET_NOTIFICATION_EXT;
172 case EGL_LOSE_CONTEXT_ON_RESET:
173 return GL_LOSE_CONTEXT_ON_RESET_EXT;
174 default:
175 UNREACHABLE();
176 return GL_NONE;
177 }
178}
179
180bool GetRobustAccess(const egl::AttributeMap &attribs)
181{
Geoff Lang077f20a2016-11-01 10:08:02 -0400182 return (attribs.get(EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT, EGL_FALSE) == EGL_TRUE) ||
183 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR) !=
184 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500185}
186
187bool GetDebug(const egl::AttributeMap &attribs)
188{
Geoff Lang077f20a2016-11-01 10:08:02 -0400189 return (attribs.get(EGL_CONTEXT_OPENGL_DEBUG, EGL_FALSE) == EGL_TRUE) ||
190 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR) != 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500191}
192
193bool GetNoError(const egl::AttributeMap &attribs)
194{
195 return (attribs.get(EGL_CONTEXT_OPENGL_NO_ERROR_KHR, EGL_FALSE) == EGL_TRUE);
196}
197
Geoff Langc287ea62016-09-16 14:46:51 -0400198bool GetWebGLContext(const egl::AttributeMap &attribs)
199{
200 return (attribs.get(EGL_CONTEXT_WEBGL_COMPATIBILITY_ANGLE, EGL_FALSE) == EGL_TRUE);
201}
202
Geoff Lang0ab41fa2018-03-14 11:03:30 -0400203bool GetExtensionsEnabled(const egl::AttributeMap &attribs, bool webGLContext)
204{
205 // If the context is WebGL, extensions are disabled by default
206 EGLAttrib defaultValue = webGLContext ? EGL_FALSE : EGL_TRUE;
207 return (attribs.get(EGL_EXTENSIONS_ENABLED_ANGLE, defaultValue) == EGL_TRUE);
208}
209
Geoff Langf41a7152016-09-19 15:11:17 -0400210bool GetBindGeneratesResource(const egl::AttributeMap &attribs)
211{
212 return (attribs.get(EGL_CONTEXT_BIND_GENERATES_RESOURCE_CHROMIUM, EGL_TRUE) == EGL_TRUE);
213}
214
Geoff Langfeb8c682017-02-13 16:07:35 -0500215bool GetClientArraysEnabled(const egl::AttributeMap &attribs)
216{
217 return (attribs.get(EGL_CONTEXT_CLIENT_ARRAYS_ENABLED_ANGLE, EGL_TRUE) == EGL_TRUE);
218}
219
Geoff Langb433e872017-10-05 14:01:47 -0400220bool GetRobustResourceInit(const egl::AttributeMap &attribs)
221{
222 return (attribs.get(EGL_ROBUST_RESOURCE_INITIALIZATION_ANGLE, EGL_FALSE) == EGL_TRUE);
223}
224
Martin Radev9d901792016-07-15 15:58:58 +0300225std::string GetObjectLabelFromPointer(GLsizei length, const GLchar *label)
226{
227 std::string labelName;
228 if (label != nullptr)
229 {
230 size_t labelLength = length < 0 ? strlen(label) : length;
231 labelName = std::string(label, labelLength);
232 }
233 return labelName;
234}
235
236void GetObjectLabelBase(const std::string &objectLabel,
237 GLsizei bufSize,
238 GLsizei *length,
239 GLchar *label)
240{
241 size_t writeLength = objectLabel.length();
242 if (label != nullptr && bufSize > 0)
243 {
244 writeLength = std::min(static_cast<size_t>(bufSize) - 1, objectLabel.length());
245 std::copy(objectLabel.begin(), objectLabel.begin() + writeLength, label);
246 label[writeLength] = '\0';
247 }
248
249 if (length != nullptr)
250 {
251 *length = static_cast<GLsizei>(writeLength);
252 }
253}
254
Jamie Madill0f80ed82017-09-19 00:24:56 -0400255template <typename CapT, typename MaxT>
256void LimitCap(CapT *cap, MaxT maximum)
257{
258 *cap = std::min(*cap, static_cast<CapT>(maximum));
259}
260
Tobin Ehlisd7890bc2018-06-29 11:57:22 -0600261constexpr angle::PackedEnumMap<gl::PrimitiveMode, GLsizei> kMinimumPrimitiveCounts = {{
262 /* Points */ 1,
263 /* Lines */ 2,
264 /* LineLoop */ 2,
265 /* LineStrip */ 2,
266 /* Triangles */ 3,
267 /* TriangleStrip */ 3,
268 /* TriangleFan */ 3,
269 /* LinesAdjacency */ 2,
270 /* LineStripAdjacency */ 2,
271 /* TrianglesAdjacency */ 3,
272 /* TriangleStripAdjacency */ 3,
273}};
274// Indices above are code-gen'd so make sure they don't change
275// if any of these static asserts are hit, must update kMinimumPrimitiveCounts abouve
276static_assert(static_cast<gl::PrimitiveMode>(0) == gl::PrimitiveMode::Points,
277 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
278static_assert(static_cast<gl::PrimitiveMode>(1) == gl::PrimitiveMode::Lines,
279 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
280static_assert(static_cast<gl::PrimitiveMode>(2) == gl::PrimitiveMode::LineLoop,
281 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
282static_assert(static_cast<gl::PrimitiveMode>(3) == gl::PrimitiveMode::LineStrip,
283 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
284static_assert(static_cast<gl::PrimitiveMode>(4) == gl::PrimitiveMode::Triangles,
285 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
286static_assert(static_cast<gl::PrimitiveMode>(5) == gl::PrimitiveMode::TriangleStrip,
287 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
288static_assert(static_cast<gl::PrimitiveMode>(6) == gl::PrimitiveMode::TriangleFan,
289 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
290static_assert(static_cast<gl::PrimitiveMode>(7) == gl::PrimitiveMode::LinesAdjacency,
291 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
292static_assert(static_cast<gl::PrimitiveMode>(8) == gl::PrimitiveMode::LineStripAdjacency,
293 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
294static_assert(static_cast<gl::PrimitiveMode>(9) == gl::PrimitiveMode::TrianglesAdjacency,
295 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
296static_assert(static_cast<gl::PrimitiveMode>(10) == gl::PrimitiveMode::TriangleStripAdjacency,
297 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
298static_assert(static_cast<gl::PrimitiveMode>(11) == gl::PrimitiveMode::EnumCount,
299 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
300
Geoff Langf6db0982015-08-25 13:04:00 -0400301} // anonymous namespace
302
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000303namespace gl
304{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +0000305
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400306Context::Context(rx::EGLImplFactory *implFactory,
307 const egl::Config *config,
Corentin Wallez51706ea2015-08-07 14:39:22 -0400308 const Context *shareContext,
Geoff Langce02f082017-02-06 16:46:21 -0500309 TextureManager *shareTextures,
Jamie Madill32447362017-06-28 14:53:52 -0400310 MemoryProgramCache *memoryProgramCache,
Corentin Wallezc295e512017-01-27 17:47:50 -0500311 const egl::AttributeMap &attribs,
Brandon Jones2b0cdcc2018-05-02 08:02:50 -0700312 const egl::DisplayExtensions &displayExtensions,
313 const egl::ClientExtensions &clientExtensions)
Jamie Madill5b772312018-03-08 20:28:32 -0500314 : mState(reinterpret_cast<ContextID>(this),
315 shareContext ? &shareContext->mState : nullptr,
316 shareTextures,
317 GetClientVersion(attribs),
318 &mGLState,
319 mCaps,
320 mTextureCaps,
321 mExtensions,
322 mLimitations),
323 mSkipValidation(GetNoError(attribs)),
324 mDisplayTextureShareGroup(shareTextures != nullptr),
325 mSavedArgsType(nullptr),
Geoff Lang3cacf692018-06-20 16:49:57 -0400326 mImplementation(implFactory->createContext(mState, config, shareContext, attribs)),
Geoff Lang75359662018-04-11 01:42:27 -0400327 mLabel(nullptr),
Jamie Madill2f348d22017-06-05 10:50:59 -0400328 mCompiler(),
Geoff Lang4fb8a8b2018-06-01 16:47:57 -0400329 mGLState(GetDebug(attribs),
330 GetBindGeneratesResource(attribs),
331 GetClientArraysEnabled(attribs),
332 GetRobustResourceInit(attribs),
333 memoryProgramCache != nullptr),
Corentin Walleze3b10e82015-05-20 11:06:25 -0400334 mConfig(config),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500335 mClientType(EGL_OPENGL_ES_API),
Jamie Madill6b873dd2018-07-12 23:56:30 -0400336 mErrors(this),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500337 mHasBeenCurrent(false),
338 mContextLost(false),
339 mResetStatus(GL_NO_ERROR),
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700340 mContextLostForced(false),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500341 mResetStrategy(GetResetStrategy(attribs)),
342 mRobustAccess(GetRobustAccess(attribs)),
Geoff Lang33f11fb2018-05-07 13:42:47 -0400343 mSurfacelessSupported(displayExtensions.surfacelessContext),
344 mExplicitContextAvailable(clientExtensions.explicitContext),
Jamie Madill61e16b42017-06-19 11:13:23 -0400345 mCurrentSurface(static_cast<egl::Surface *>(EGL_NO_SURFACE)),
346 mCurrentDisplay(static_cast<egl::Display *>(EGL_NO_DISPLAY)),
Jamie Madille14951e2017-03-09 18:55:16 -0500347 mWebGLContext(GetWebGLContext(attribs)),
Geoff Lang0ab41fa2018-03-14 11:03:30 -0400348 mExtensionsEnabled(GetExtensionsEnabled(attribs, mWebGLContext)),
Jamie Madill32447362017-06-28 14:53:52 -0400349 mMemoryProgramCache(memoryProgramCache),
Jamie Madillb3f26b92017-07-19 15:07:41 -0400350 mScratchBuffer(1000u),
351 mZeroFilledBuffer(1000u)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000352{
Jamie Madill5b772312018-03-08 20:28:32 -0500353 // Needed to solve a Clang warning of unused variables.
Jamie Madillc6dbc252018-04-30 19:07:56 -0400354 ANGLE_UNUSED_VARIABLE(mSavedArgsType);
355 ANGLE_UNUSED_VARIABLE(mParamsBuffer);
Geoff Lang33f11fb2018-05-07 13:42:47 -0400356}
Jamie Madill5b772312018-03-08 20:28:32 -0500357
Geoff Lang33f11fb2018-05-07 13:42:47 -0400358void Context::initialize()
359{
360 mImplementation->setMemoryProgramCache(mMemoryProgramCache);
Jamie Madill14bbb3f2017-09-12 15:23:01 -0400361
Geoff Lang33f11fb2018-05-07 13:42:47 -0400362 initCaps();
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700363 initWorkarounds();
Geoff Langc0b9ef42014-07-02 10:02:37 -0400364
Geoff Lang4fb8a8b2018-06-01 16:47:57 -0400365 mGLState.initialize(this);
Régis Fénéon83107972015-02-05 12:57:44 +0100366
Shannon Woods53a94a82014-06-24 15:20:36 -0400367 mFenceNVHandleAllocator.setBaseHandle(0);
Geoff Lang7dca1862013-07-30 16:30:46 -0400368
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000369 // [OpenGL ES 2.0.24] section 3.7 page 83:
Corentin Wallez336129f2017-10-17 15:55:40 -0400370 // In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have two-dimensional
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000371 // and cube map texture state vectors respectively associated with them.
372 // In order that access to these initial textures not be lost, they are treated as texture
373 // objects all of whose names are 0.
374
Corentin Wallez99d492c2018-02-27 15:17:10 -0500375 Texture *zeroTexture2D = new Texture(mImplementation.get(), 0, TextureType::_2D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800376 mZeroTextures[TextureType::_2D].set(this, zeroTexture2D);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500377
Corentin Wallez99d492c2018-02-27 15:17:10 -0500378 Texture *zeroTextureCube = new Texture(mImplementation.get(), 0, TextureType::CubeMap);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800379 mZeroTextures[TextureType::CubeMap].set(this, zeroTextureCube);
Geoff Lang76b10c92014-09-05 16:28:14 -0400380
Geoff Langeb66a6e2016-10-31 13:06:12 -0400381 if (getClientVersion() >= Version(3, 0))
Geoff Lang76b10c92014-09-05 16:28:14 -0400382 {
383 // TODO: These could also be enabled via extension
Corentin Wallez99d492c2018-02-27 15:17:10 -0500384 Texture *zeroTexture3D = new Texture(mImplementation.get(), 0, TextureType::_3D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800385 mZeroTextures[TextureType::_3D].set(this, zeroTexture3D);
Geoff Lang76b10c92014-09-05 16:28:14 -0400386
Corentin Wallez99d492c2018-02-27 15:17:10 -0500387 Texture *zeroTexture2DArray = new Texture(mImplementation.get(), 0, TextureType::_2DArray);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800388 mZeroTextures[TextureType::_2DArray].set(this, zeroTexture2DArray);
Geoff Lang76b10c92014-09-05 16:28:14 -0400389 }
Geoff Lang3b573612016-10-31 14:08:10 -0400390 if (getClientVersion() >= Version(3, 1))
391 {
392 Texture *zeroTexture2DMultisample =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500393 new Texture(mImplementation.get(), 0, TextureType::_2DMultisample);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800394 mZeroTextures[TextureType::_2DMultisample].set(this, zeroTexture2DMultisample);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800395
Jiajia Qin6eafb042016-12-27 17:04:07 +0800396 for (unsigned int i = 0; i < mCaps.maxAtomicCounterBufferBindings; i++)
397 {
Qin Jiajia339f65b2018-02-27 12:52:48 +0800398 bindBufferRange(BufferBinding::AtomicCounter, i, 0, 0, 0);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800399 }
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800400
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800401 for (unsigned int i = 0; i < mCaps.maxShaderStorageBufferBindings; i++)
402 {
Corentin Wallez336129f2017-10-17 15:55:40 -0400403 bindBufferRange(BufferBinding::ShaderStorage, i, 0, 0, 0);
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800404 }
Geoff Lang3b573612016-10-31 14:08:10 -0400405 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000406
Geoff Langb0f917f2017-12-05 13:41:54 -0500407 if (mSupportedExtensions.textureRectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400408 {
409 Texture *zeroTextureRectangle =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500410 new Texture(mImplementation.get(), 0, TextureType::Rectangle);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800411 mZeroTextures[TextureType::Rectangle].set(this, zeroTextureRectangle);
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400412 }
413
Geoff Langb0f917f2017-12-05 13:41:54 -0500414 if (mSupportedExtensions.eglImageExternal || mSupportedExtensions.eglStreamConsumerExternal)
Ian Ewellbda75592016-04-18 17:25:54 -0400415 {
Corentin Wallez99d492c2018-02-27 15:17:10 -0500416 Texture *zeroTextureExternal = new Texture(mImplementation.get(), 0, TextureType::External);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800417 mZeroTextures[TextureType::External].set(this, zeroTextureExternal);
Ian Ewellbda75592016-04-18 17:25:54 -0400418 }
419
Jamie Madill4928b7c2017-06-20 12:57:39 -0400420 mGLState.initializeZeroTextures(this, mZeroTextures);
Jamie Madille6382c32014-11-07 15:05:26 -0500421
Jamie Madill57a89722013-07-02 11:57:03 -0400422 bindVertexArray(0);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000423
Geoff Langeb66a6e2016-10-31 13:06:12 -0400424 if (getClientVersion() >= Version(3, 0))
Geoff Lang1a683462015-09-29 15:09:59 -0400425 {
426 // [OpenGL ES 3.0.2] section 2.14.1 pg 85:
427 // In the initial state, a default transform feedback object is bound and treated as
428 // a transform feedback object with a name of zero. That object is bound any time
429 // BindTransformFeedback is called with id of zero
Jamie Madillf0dcb8b2017-08-26 19:05:13 -0400430 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Geoff Lang1a683462015-09-29 15:09:59 -0400431 }
Geoff Langc8058452014-02-03 12:04:11 -0500432
Corentin Wallez336129f2017-10-17 15:55:40 -0400433 for (auto type : angle::AllEnums<BufferBinding>())
434 {
435 bindBuffer(type, 0);
436 }
437
438 bindRenderbuffer(GL_RENDERBUFFER, 0);
439
440 for (unsigned int i = 0; i < mCaps.maxUniformBufferBindings; i++)
441 {
442 bindBufferRange(BufferBinding::Uniform, i, 0, 0, -1);
443 }
444
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700445 // Initialize GLES1 renderer if appropriate.
446 if (getClientVersion() < Version(2, 0))
447 {
448 mGLES1Renderer.reset(new GLES1Renderer());
449 }
450
Jamie Madillad9f24e2016-02-12 09:27:24 -0500451 // Initialize dirty bit masks
Geoff Lang9bf86f02018-07-26 11:46:34 -0400452 mDrawDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
453 mDrawDirtyObjects.set(State::DIRTY_OBJECT_VERTEX_ARRAY);
454 mDrawDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM_TEXTURES);
455
456 mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
457 mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_VERTEX_ARRAY);
458 mPathOperationDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM_TEXTURES);
459
Jamie Madillc67323a2017-11-02 23:11:41 -0400460 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500461 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500462 // No dirty objects.
463
464 // Readpixels uses the pack state and read FBO
Jamie Madillc67323a2017-11-02 23:11:41 -0400465 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500466 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_BUFFER_BINDING);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400467 mReadPixelsDirtyBits.set(State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500468 mReadPixelsDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
469
470 mClearDirtyBits.set(State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED);
471 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
472 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR);
473 mClearDirtyBits.set(State::DIRTY_BIT_VIEWPORT);
474 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_COLOR);
475 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_DEPTH);
476 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_STENCIL);
477 mClearDirtyBits.set(State::DIRTY_BIT_COLOR_MASK);
478 mClearDirtyBits.set(State::DIRTY_BIT_DEPTH_MASK);
479 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT);
480 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_BACK);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400481 mClearDirtyBits.set(State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500482 mClearDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
483
484 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
485 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR);
Geoff Lang1d2c41d2016-10-19 16:14:46 -0700486 mBlitDirtyBits.set(State::DIRTY_BIT_FRAMEBUFFER_SRGB);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400487 mBlitDirtyBits.set(State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
488 mBlitDirtyBits.set(State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500489 mBlitDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
490 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
Jamie Madill437fa652016-05-03 15:13:24 -0400491
Xinghua Cao10a4d432017-11-28 14:46:26 +0800492 // TODO(xinghua.cao@intel.com): add other dirty bits and dirty objects.
493 mComputeDirtyBits.set(State::DIRTY_BIT_SHADER_STORAGE_BUFFER_BINDING);
494 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_BINDING);
495 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_EXECUTABLE);
496 mComputeDirtyBits.set(State::DIRTY_BIT_TEXTURE_BINDINGS);
497 mComputeDirtyBits.set(State::DIRTY_BIT_SAMPLER_BINDINGS);
Qin Jiajia62fcf622017-11-30 16:16:12 +0800498 mComputeDirtyBits.set(State::DIRTY_BIT_DISPATCH_INDIRECT_BUFFER_BINDING);
Jiajia Qin5ae6ee42018-03-06 17:39:42 +0800499 mComputeDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM_TEXTURES);
Xinghua Cao10a4d432017-11-28 14:46:26 +0800500
Jamie Madillb4927eb2018-07-16 11:39:46 -0400501 mImplementation->setErrorSet(&mErrors);
502
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400503 handleError(mImplementation->initialize());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000504}
505
Jamie Madill4928b7c2017-06-20 12:57:39 -0400506egl::Error Context::onDestroy(const egl::Display *display)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000507{
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700508 if (mGLES1Renderer)
509 {
510 mGLES1Renderer->onDestroy(this, &mGLState);
511 }
512
Jamie Madille7b3fe22018-04-05 09:42:46 -0400513 // Delete the Surface first to trigger a finish() in Vulkan.
Jamie Madille7b3fe22018-04-05 09:42:46 -0400514 ANGLE_TRY(releaseSurface(display));
515
Corentin Wallez80b24112015-08-25 16:41:57 -0400516 for (auto fence : mFenceNVMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000517 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400518 SafeDelete(fence.second);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000519 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400520 mFenceNVMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000521
Corentin Wallez80b24112015-08-25 16:41:57 -0400522 for (auto query : mQueryMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000523 {
Geoff Langf0aa8422015-09-29 15:08:34 -0400524 if (query.second != nullptr)
525 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400526 query.second->release(this);
Geoff Langf0aa8422015-09-29 15:08:34 -0400527 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000528 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400529 mQueryMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000530
Corentin Wallez80b24112015-08-25 16:41:57 -0400531 for (auto vertexArray : mVertexArrayMap)
Jamie Madill57a89722013-07-02 11:57:03 -0400532 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400533 if (vertexArray.second)
534 {
535 vertexArray.second->onDestroy(this);
536 }
Jamie Madill57a89722013-07-02 11:57:03 -0400537 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400538 mVertexArrayMap.clear();
Jamie Madill57a89722013-07-02 11:57:03 -0400539
Corentin Wallez80b24112015-08-25 16:41:57 -0400540 for (auto transformFeedback : mTransformFeedbackMap)
Geoff Langc8058452014-02-03 12:04:11 -0500541 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500542 if (transformFeedback.second != nullptr)
543 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500544 transformFeedback.second->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500545 }
Geoff Langc8058452014-02-03 12:04:11 -0500546 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400547 mTransformFeedbackMap.clear();
Geoff Langc8058452014-02-03 12:04:11 -0500548
Jamie Madill5b772312018-03-08 20:28:32 -0500549 for (BindingPointer<Texture> &zeroTexture : mZeroTextures)
Geoff Lang76b10c92014-09-05 16:28:14 -0400550 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800551 if (zeroTexture.get() != nullptr)
552 {
553 ANGLE_TRY(zeroTexture->onDestroy(this));
554 zeroTexture.set(this, nullptr);
555 }
Geoff Lang76b10c92014-09-05 16:28:14 -0400556 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000557
Jamie Madill2f348d22017-06-05 10:50:59 -0400558 releaseShaderCompiler();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500559
Jamie Madill4928b7c2017-06-20 12:57:39 -0400560 mGLState.reset(this);
561
Jamie Madill6c1f6712017-02-14 19:08:04 -0500562 mState.mBuffers->release(this);
563 mState.mShaderPrograms->release(this);
564 mState.mTextures->release(this);
565 mState.mRenderbuffers->release(this);
566 mState.mSamplers->release(this);
Jamie Madill70b5bb02017-08-28 13:32:37 -0400567 mState.mSyncs->release(this);
Jamie Madill6c1f6712017-02-14 19:08:04 -0500568 mState.mPaths->release(this);
569 mState.mFramebuffers->release(this);
Yunchao Hea336b902017-08-02 16:05:21 +0800570 mState.mPipelines->release(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400571
Jamie Madill76e471e2017-10-21 09:56:01 -0400572 mImplementation->onDestroy(this);
573
Jamie Madill4928b7c2017-06-20 12:57:39 -0400574 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000575}
576
Jamie Madill70ee0f62017-02-06 16:04:20 -0500577Context::~Context()
578{
579}
580
Geoff Lang75359662018-04-11 01:42:27 -0400581void Context::setLabel(EGLLabelKHR label)
582{
583 mLabel = label;
584}
585
586EGLLabelKHR Context::getLabel() const
587{
588 return mLabel;
589}
590
Jamie Madill4928b7c2017-06-20 12:57:39 -0400591egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000592{
Jamie Madill61e16b42017-06-19 11:13:23 -0400593 mCurrentDisplay = display;
594
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000595 if (!mHasBeenCurrent)
596 {
Geoff Lang33f11fb2018-05-07 13:42:47 -0400597 initialize();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000598 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500599 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400600 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000601
Corentin Wallezc295e512017-01-27 17:47:50 -0500602 int width = 0;
603 int height = 0;
604 if (surface != nullptr)
605 {
606 width = surface->getWidth();
607 height = surface->getHeight();
608 }
609
610 mGLState.setViewportParams(0, 0, width, height);
611 mGLState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000612
613 mHasBeenCurrent = true;
614 }
615
Jamie Madill1b94d432015-08-07 13:23:23 -0400616 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700617 mGLState.setAllDirtyBits();
Jamie Madill81c2e252017-09-09 23:32:46 -0400618 mGLState.setAllDirtyObjects();
Jamie Madill1b94d432015-08-07 13:23:23 -0400619
Jamie Madill4928b7c2017-06-20 12:57:39 -0400620 ANGLE_TRY(releaseSurface(display));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500621
622 Framebuffer *newDefault = nullptr;
623 if (surface != nullptr)
624 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400625 ANGLE_TRY(surface->setIsCurrent(this, true));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500626 mCurrentSurface = surface;
Geoff Langbf7b95d2018-05-01 16:48:21 -0400627 newDefault = surface->createDefaultFramebuffer(this);
Corentin Wallezccab69d2017-01-27 16:57:15 -0500628 }
629 else
630 {
Geoff Langbf7b95d2018-05-01 16:48:21 -0400631 newDefault = new Framebuffer(mImplementation.get());
Corentin Wallezccab69d2017-01-27 16:57:15 -0500632 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000633
Corentin Wallez37c39792015-08-20 14:19:46 -0400634 // Update default framebuffer, the binding of the previous default
635 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400636 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700637 if (mGLState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400638 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700639 mGLState.setReadFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400640 }
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700641 if (mGLState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400642 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700643 mGLState.setDrawFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400644 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500645 mState.mFramebuffers->setDefaultFramebuffer(newDefault);
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400646 }
Ian Ewell292f0052016-02-04 10:37:32 -0500647
648 // Notify the renderer of a context switch
Luc Ferron5396f2a2018-07-12 08:24:23 -0400649 ANGLE_TRY(mImplementation->onMakeCurrent(this));
Jamie Madill4928b7c2017-06-20 12:57:39 -0400650 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000651}
652
Jamie Madill4928b7c2017-06-20 12:57:39 -0400653egl::Error Context::releaseSurface(const egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400654{
Geoff Langbf7b95d2018-05-01 16:48:21 -0400655 gl::Framebuffer *defaultFramebuffer = mState.mFramebuffers->getFramebuffer(0);
Corentin Wallez51706ea2015-08-07 14:39:22 -0400656
Geoff Langbf7b95d2018-05-01 16:48:21 -0400657 // Remove the default framebuffer
658 if (mGLState.getReadFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500659 {
660 mGLState.setReadFramebufferBinding(nullptr);
661 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400662
663 if (mGLState.getDrawFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500664 {
665 mGLState.setDrawFramebufferBinding(nullptr);
666 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400667
668 if (defaultFramebuffer)
669 {
670 defaultFramebuffer->onDestroy(this);
671 delete defaultFramebuffer;
672 }
673
Corentin Wallezc295e512017-01-27 17:47:50 -0500674 mState.mFramebuffers->setDefaultFramebuffer(nullptr);
675
676 if (mCurrentSurface)
677 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400678 ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
Corentin Wallezc295e512017-01-27 17:47:50 -0500679 mCurrentSurface = nullptr;
680 }
Jamie Madill4928b7c2017-06-20 12:57:39 -0400681
682 return egl::NoError();
Jamie Madill77a72f62015-04-14 11:18:32 -0400683}
684
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000685GLuint Context::createBuffer()
686{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500687 return mState.mBuffers->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000688}
689
690GLuint Context::createProgram()
691{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500692 return mState.mShaderPrograms->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000693}
694
Jiawei Shao385b3e02018-03-21 09:43:28 +0800695GLuint Context::createShader(ShaderType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000696{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500697 return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000698}
699
700GLuint Context::createTexture()
701{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500702 return mState.mTextures->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000703}
704
705GLuint Context::createRenderbuffer()
706{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500707 return mState.mRenderbuffers->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000708}
709
Brandon Jones59770802018-04-02 13:18:42 -0700710GLuint Context::genPaths(GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300711{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500712 auto resultOrError = mState.mPaths->createPaths(mImplementation.get(), range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300713 if (resultOrError.isError())
714 {
715 handleError(resultOrError.getError());
716 return 0;
717 }
718 return resultOrError.getResult();
719}
720
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000721// Returns an unused framebuffer name
722GLuint Context::createFramebuffer()
723{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500724 return mState.mFramebuffers->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000725}
726
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500727void Context::genFencesNV(GLsizei n, GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000728{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500729 for (int i = 0; i < n; i++)
730 {
731 GLuint handle = mFenceNVHandleAllocator.allocate();
732 mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV()));
733 fences[i] = handle;
734 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000735}
736
Yunchao Hea336b902017-08-02 16:05:21 +0800737GLuint Context::createProgramPipeline()
738{
739 return mState.mPipelines->createProgramPipeline();
740}
741
Jiawei Shao385b3e02018-03-21 09:43:28 +0800742GLuint Context::createShaderProgramv(ShaderType type, GLsizei count, const GLchar *const *strings)
Jiajia Qin5451d532017-11-16 17:16:34 +0800743{
744 UNIMPLEMENTED();
745 return 0u;
746}
747
James Darpinian4d9d4832018-03-13 12:43:28 -0700748void Context::deleteBuffer(GLuint bufferName)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000749{
James Darpinian4d9d4832018-03-13 12:43:28 -0700750 Buffer *buffer = mState.mBuffers->getBuffer(bufferName);
751 if (buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000752 {
753 detachBuffer(buffer);
754 }
Jamie Madill893ab082014-05-16 16:56:10 -0400755
James Darpinian4d9d4832018-03-13 12:43:28 -0700756 mState.mBuffers->deleteObject(this, bufferName);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000757}
758
759void Context::deleteShader(GLuint shader)
760{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500761 mState.mShaderPrograms->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000762}
763
764void Context::deleteProgram(GLuint program)
765{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500766 mState.mShaderPrograms->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000767}
768
769void Context::deleteTexture(GLuint texture)
770{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500771 if (mState.mTextures->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000772 {
773 detachTexture(texture);
774 }
775
Jamie Madill6c1f6712017-02-14 19:08:04 -0500776 mState.mTextures->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000777}
778
779void Context::deleteRenderbuffer(GLuint renderbuffer)
780{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500781 if (mState.mRenderbuffers->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000782 {
783 detachRenderbuffer(renderbuffer);
784 }
Jamie Madill893ab082014-05-16 16:56:10 -0400785
Jamie Madill6c1f6712017-02-14 19:08:04 -0500786 mState.mRenderbuffers->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000787}
788
Jamie Madill7f0c5a42017-08-26 22:43:26 -0400789void Context::deleteSync(GLsync sync)
Jamie Madillcd055f82013-07-26 11:55:15 -0400790{
791 // The spec specifies the underlying Fence object is not deleted until all current
792 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
793 // and since our API is currently designed for being called from a single thread, we can delete
794 // the fence immediately.
Jamie Madill70b5bb02017-08-28 13:32:37 -0400795 mState.mSyncs->deleteObject(this, static_cast<GLuint>(reinterpret_cast<uintptr_t>(sync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400796}
797
Yunchao Hea336b902017-08-02 16:05:21 +0800798void Context::deleteProgramPipeline(GLuint pipeline)
799{
800 if (mState.mPipelines->getProgramPipeline(pipeline))
801 {
802 detachProgramPipeline(pipeline);
803 }
804
805 mState.mPipelines->deleteObject(this, pipeline);
806}
807
Sami Väisänene45e53b2016-05-25 10:36:04 +0300808void Context::deletePaths(GLuint first, GLsizei range)
809{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500810 mState.mPaths->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300811}
812
Brandon Jones59770802018-04-02 13:18:42 -0700813bool Context::isPath(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300814{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500815 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300816 if (pathObj == nullptr)
817 return false;
818
819 return pathObj->hasPathData();
820}
821
Brandon Jones59770802018-04-02 13:18:42 -0700822bool Context::isPathGenerated(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300823{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500824 return mState.mPaths->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300825}
826
Brandon Jones59770802018-04-02 13:18:42 -0700827void Context::pathCommands(GLuint path,
828 GLsizei numCommands,
829 const GLubyte *commands,
830 GLsizei numCoords,
831 GLenum coordType,
832 const void *coords)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300833{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500834 auto *pathObject = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300835
836 handleError(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
837}
838
Jamie Madill007530e2017-12-28 14:27:04 -0500839void Context::pathParameterf(GLuint path, GLenum pname, GLfloat value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300840{
Jamie Madill007530e2017-12-28 14:27:04 -0500841 Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300842
843 switch (pname)
844 {
845 case GL_PATH_STROKE_WIDTH_CHROMIUM:
846 pathObj->setStrokeWidth(value);
847 break;
848 case GL_PATH_END_CAPS_CHROMIUM:
849 pathObj->setEndCaps(static_cast<GLenum>(value));
850 break;
851 case GL_PATH_JOIN_STYLE_CHROMIUM:
852 pathObj->setJoinStyle(static_cast<GLenum>(value));
853 break;
854 case GL_PATH_MITER_LIMIT_CHROMIUM:
855 pathObj->setMiterLimit(value);
856 break;
857 case GL_PATH_STROKE_BOUND_CHROMIUM:
858 pathObj->setStrokeBound(value);
859 break;
860 default:
861 UNREACHABLE();
862 break;
863 }
864}
865
Jamie Madill007530e2017-12-28 14:27:04 -0500866void Context::pathParameteri(GLuint path, GLenum pname, GLint value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300867{
Jamie Madill007530e2017-12-28 14:27:04 -0500868 // TODO(jmadill): Should use proper clamping/casting.
869 pathParameterf(path, pname, static_cast<GLfloat>(value));
870}
871
872void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value)
873{
874 const Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300875
876 switch (pname)
877 {
878 case GL_PATH_STROKE_WIDTH_CHROMIUM:
879 *value = pathObj->getStrokeWidth();
880 break;
881 case GL_PATH_END_CAPS_CHROMIUM:
882 *value = static_cast<GLfloat>(pathObj->getEndCaps());
883 break;
884 case GL_PATH_JOIN_STYLE_CHROMIUM:
885 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
886 break;
887 case GL_PATH_MITER_LIMIT_CHROMIUM:
888 *value = pathObj->getMiterLimit();
889 break;
890 case GL_PATH_STROKE_BOUND_CHROMIUM:
891 *value = pathObj->getStrokeBound();
892 break;
893 default:
894 UNREACHABLE();
895 break;
896 }
897}
898
Jamie Madill007530e2017-12-28 14:27:04 -0500899void Context::getPathParameteriv(GLuint path, GLenum pname, GLint *value)
900{
901 GLfloat val = 0.0f;
902 getPathParameterfv(path, pname, value != nullptr ? &val : nullptr);
903 if (value)
904 *value = static_cast<GLint>(val);
905}
906
Brandon Jones59770802018-04-02 13:18:42 -0700907void Context::pathStencilFunc(GLenum func, GLint ref, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300908{
909 mGLState.setPathStencilFunc(func, ref, mask);
910}
911
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000912void Context::deleteFramebuffer(GLuint framebuffer)
913{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500914 if (mState.mFramebuffers->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000915 {
916 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000917 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500918
Jamie Madill6c1f6712017-02-14 19:08:04 -0500919 mState.mFramebuffers->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000920}
921
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500922void Context::deleteFencesNV(GLsizei n, const GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000923{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500924 for (int i = 0; i < n; i++)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000925 {
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500926 GLuint fence = fences[i];
927
928 FenceNV *fenceObject = nullptr;
929 if (mFenceNVMap.erase(fence, &fenceObject))
930 {
931 mFenceNVHandleAllocator.release(fence);
932 delete fenceObject;
933 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000934 }
935}
936
Geoff Lang70d0f492015-12-10 17:45:46 -0500937Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000938{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500939 return mState.mBuffers->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000940}
941
Jamie Madill570f7c82014-07-03 10:38:54 -0400942Texture *Context::getTexture(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000943{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500944 return mState.mTextures->getTexture(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000945}
946
Geoff Lang70d0f492015-12-10 17:45:46 -0500947Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000948{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500949 return mState.mRenderbuffers->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000950}
951
Jamie Madill70b5bb02017-08-28 13:32:37 -0400952Sync *Context::getSync(GLsync handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400953{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400954 return mState.mSyncs->getSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400955}
956
Jamie Madill57a89722013-07-02 11:57:03 -0400957VertexArray *Context::getVertexArray(GLuint handle) const
958{
Jamie Madill96a483b2017-06-27 16:49:21 -0400959 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -0400960}
961
Jamie Madilldc356042013-07-19 16:36:57 -0400962Sampler *Context::getSampler(GLuint handle) const
963{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500964 return mState.mSamplers->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400965}
966
Geoff Langc8058452014-02-03 12:04:11 -0500967TransformFeedback *Context::getTransformFeedback(GLuint handle) const
968{
Jamie Madill96a483b2017-06-27 16:49:21 -0400969 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -0500970}
971
Yunchao Hea336b902017-08-02 16:05:21 +0800972ProgramPipeline *Context::getProgramPipeline(GLuint handle) const
973{
974 return mState.mPipelines->getProgramPipeline(handle);
975}
976
Geoff Lang75359662018-04-11 01:42:27 -0400977gl::LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
Geoff Lang70d0f492015-12-10 17:45:46 -0500978{
979 switch (identifier)
980 {
981 case GL_BUFFER:
982 return getBuffer(name);
983 case GL_SHADER:
984 return getShader(name);
985 case GL_PROGRAM:
986 return getProgram(name);
987 case GL_VERTEX_ARRAY:
988 return getVertexArray(name);
989 case GL_QUERY:
990 return getQuery(name);
991 case GL_TRANSFORM_FEEDBACK:
992 return getTransformFeedback(name);
993 case GL_SAMPLER:
994 return getSampler(name);
995 case GL_TEXTURE:
996 return getTexture(name);
997 case GL_RENDERBUFFER:
998 return getRenderbuffer(name);
999 case GL_FRAMEBUFFER:
1000 return getFramebuffer(name);
1001 default:
1002 UNREACHABLE();
1003 return nullptr;
1004 }
1005}
1006
Geoff Lang75359662018-04-11 01:42:27 -04001007gl::LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
Geoff Lang70d0f492015-12-10 17:45:46 -05001008{
Jamie Madill70b5bb02017-08-28 13:32:37 -04001009 return getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
Geoff Lang70d0f492015-12-10 17:45:46 -05001010}
1011
Martin Radev9d901792016-07-15 15:58:58 +03001012void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
1013{
Geoff Lang75359662018-04-11 01:42:27 -04001014 gl::LabeledObject *object = getLabeledObject(identifier, name);
Martin Radev9d901792016-07-15 15:58:58 +03001015 ASSERT(object != nullptr);
1016
1017 std::string labelName = GetObjectLabelFromPointer(length, label);
1018 object->setLabel(labelName);
Jamie Madill8693bdb2017-09-02 15:32:14 -04001019
1020 // TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the
1021 // specified object is active until we do this.
1022 mGLState.setObjectDirty(identifier);
Martin Radev9d901792016-07-15 15:58:58 +03001023}
1024
1025void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
1026{
Geoff Lang75359662018-04-11 01:42:27 -04001027 gl::LabeledObject *object = getLabeledObjectFromPtr(ptr);
Martin Radev9d901792016-07-15 15:58:58 +03001028 ASSERT(object != nullptr);
1029
1030 std::string labelName = GetObjectLabelFromPointer(length, label);
1031 object->setLabel(labelName);
1032}
1033
1034void Context::getObjectLabel(GLenum identifier,
1035 GLuint name,
1036 GLsizei bufSize,
1037 GLsizei *length,
1038 GLchar *label) const
1039{
Geoff Lang75359662018-04-11 01:42:27 -04001040 gl::LabeledObject *object = getLabeledObject(identifier, name);
Martin Radev9d901792016-07-15 15:58:58 +03001041 ASSERT(object != nullptr);
1042
1043 const std::string &objectLabel = object->getLabel();
1044 GetObjectLabelBase(objectLabel, bufSize, length, label);
1045}
1046
1047void Context::getObjectPtrLabel(const void *ptr,
1048 GLsizei bufSize,
1049 GLsizei *length,
1050 GLchar *label) const
1051{
Geoff Lang75359662018-04-11 01:42:27 -04001052 gl::LabeledObject *object = getLabeledObjectFromPtr(ptr);
Martin Radev9d901792016-07-15 15:58:58 +03001053 ASSERT(object != nullptr);
1054
1055 const std::string &objectLabel = object->getLabel();
1056 GetObjectLabelBase(objectLabel, bufSize, length, label);
1057}
1058
Jamie Madilldc356042013-07-19 16:36:57 -04001059bool Context::isSampler(GLuint samplerName) const
1060{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001061 return mState.mSamplers->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -04001062}
1063
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001064void Context::bindTexture(TextureType target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001065{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001066 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001067
Jamie Madilldedd7b92014-11-05 16:30:36 -05001068 if (handle == 0)
1069 {
1070 texture = mZeroTextures[target].get();
1071 }
1072 else
1073 {
Corentin Wallez99d492c2018-02-27 15:17:10 -05001074 texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -05001075 }
1076
1077 ASSERT(texture);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001078 mGLState.setSamplerTexture(this, target, texture);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00001079}
1080
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001081void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001082{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001083 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1084 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001085 mGLState.setReadFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001086}
1087
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001088void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001089{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001090 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1091 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001092 mGLState.setDrawFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001093}
1094
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001095void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -04001096{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001097 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madill7267aa62018-04-17 15:28:21 -04001098 mGLState.setVertexArrayBinding(this, vertexArray);
Jamie Madill57a89722013-07-02 11:57:03 -04001099}
1100
Shao80957d92017-02-20 21:25:59 +08001101void Context::bindVertexBuffer(GLuint bindingIndex,
1102 GLuint bufferHandle,
1103 GLintptr offset,
1104 GLsizei stride)
1105{
1106 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001107 mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Shao80957d92017-02-20 21:25:59 +08001108}
1109
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001110void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -04001111{
Geoff Lang76b10c92014-09-05 16:28:14 -04001112 ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -04001113 Sampler *sampler =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001114 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001115 mGLState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04001116}
1117
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001118void Context::bindImageTexture(GLuint unit,
1119 GLuint texture,
1120 GLint level,
1121 GLboolean layered,
1122 GLint layer,
1123 GLenum access,
1124 GLenum format)
1125{
1126 Texture *tex = mState.mTextures->getTexture(texture);
1127 mGLState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
1128}
1129
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001130void Context::useProgram(GLuint program)
1131{
Jamie Madill6c1f6712017-02-14 19:08:04 -05001132 mGLState.setProgram(this, getProgram(program));
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001133}
1134
Jiajia Qin5451d532017-11-16 17:16:34 +08001135void Context::useProgramStages(GLuint pipeline, GLbitfield stages, GLuint program)
1136{
1137 UNIMPLEMENTED();
1138}
1139
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001140void Context::bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001141{
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001142 ASSERT(target == GL_TRANSFORM_FEEDBACK);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001143 TransformFeedback *transformFeedback =
1144 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001145 mGLState.setTransformFeedbackBinding(this, transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -05001146}
1147
Yunchao Hea336b902017-08-02 16:05:21 +08001148void Context::bindProgramPipeline(GLuint pipelineHandle)
1149{
1150 ProgramPipeline *pipeline =
1151 mState.mPipelines->checkProgramPipelineAllocation(mImplementation.get(), pipelineHandle);
1152 mGLState.setProgramPipelineBinding(this, pipeline);
1153}
1154
Corentin Wallezad3ae902018-03-09 13:40:42 -05001155void Context::beginQuery(QueryType target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001156{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001157 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001158 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001159
Geoff Lang5aad9672014-09-08 11:10:42 -04001160 // begin query
Jamie Madill5188a272018-07-25 10:53:56 -04001161 ANGLE_CONTEXT_TRY(queryObject->begin(this));
Geoff Lang5aad9672014-09-08 11:10:42 -04001162
1163 // set query as active for specified target only if begin succeeded
Jamie Madill4928b7c2017-06-20 12:57:39 -04001164 mGLState.setActiveQuery(this, target, queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001165}
1166
Corentin Wallezad3ae902018-03-09 13:40:42 -05001167void Context::endQuery(QueryType target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001168{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001169 Query *queryObject = mGLState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001170 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001171
Jamie Madill5188a272018-07-25 10:53:56 -04001172 handleError(queryObject->end(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001173
Geoff Lang5aad9672014-09-08 11:10:42 -04001174 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madill4928b7c2017-06-20 12:57:39 -04001175 mGLState.setActiveQuery(this, target, nullptr);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001176}
1177
Corentin Wallezad3ae902018-03-09 13:40:42 -05001178void Context::queryCounter(GLuint id, QueryType target)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001179{
Corentin Wallezad3ae902018-03-09 13:40:42 -05001180 ASSERT(target == QueryType::Timestamp);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001181
1182 Query *queryObject = getQuery(id, true, target);
1183 ASSERT(queryObject);
1184
Jamie Madill5188a272018-07-25 10:53:56 -04001185 handleError(queryObject->queryCounter(this));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001186}
1187
Corentin Wallezad3ae902018-03-09 13:40:42 -05001188void Context::getQueryiv(QueryType target, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001189{
1190 switch (pname)
1191 {
1192 case GL_CURRENT_QUERY_EXT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001193 params[0] = mGLState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001194 break;
1195 case GL_QUERY_COUNTER_BITS_EXT:
1196 switch (target)
1197 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001198 case QueryType::TimeElapsed:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001199 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1200 break;
Corentin Wallezad3ae902018-03-09 13:40:42 -05001201 case QueryType::Timestamp:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001202 params[0] = getExtensions().queryCounterBitsTimestamp;
1203 break;
1204 default:
1205 UNREACHABLE();
1206 params[0] = 0;
1207 break;
1208 }
1209 break;
1210 default:
1211 UNREACHABLE();
1212 return;
1213 }
1214}
1215
Corentin Wallezad3ae902018-03-09 13:40:42 -05001216void Context::getQueryivRobust(QueryType target,
Brandon Jones59770802018-04-02 13:18:42 -07001217 GLenum pname,
1218 GLsizei bufSize,
1219 GLsizei *length,
1220 GLint *params)
1221{
1222 getQueryiv(target, pname, params);
1223}
1224
Geoff Lang2186c382016-10-14 10:54:54 -04001225void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001226{
Jamie Madill5188a272018-07-25 10:53:56 -04001227 handleError(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001228}
1229
Brandon Jones59770802018-04-02 13:18:42 -07001230void Context::getQueryObjectivRobust(GLuint id,
1231 GLenum pname,
1232 GLsizei bufSize,
1233 GLsizei *length,
1234 GLint *params)
1235{
1236 getQueryObjectiv(id, pname, params);
1237}
1238
Geoff Lang2186c382016-10-14 10:54:54 -04001239void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001240{
Jamie Madill5188a272018-07-25 10:53:56 -04001241 handleError(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001242}
1243
Brandon Jones59770802018-04-02 13:18:42 -07001244void Context::getQueryObjectuivRobust(GLuint id,
1245 GLenum pname,
1246 GLsizei bufSize,
1247 GLsizei *length,
1248 GLuint *params)
1249{
1250 getQueryObjectuiv(id, pname, params);
1251}
1252
Geoff Lang2186c382016-10-14 10:54:54 -04001253void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001254{
Jamie Madill5188a272018-07-25 10:53:56 -04001255 handleError(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001256}
1257
Brandon Jones59770802018-04-02 13:18:42 -07001258void Context::getQueryObjecti64vRobust(GLuint id,
1259 GLenum pname,
1260 GLsizei bufSize,
1261 GLsizei *length,
1262 GLint64 *params)
1263{
1264 getQueryObjecti64v(id, pname, params);
1265}
1266
Geoff Lang2186c382016-10-14 10:54:54 -04001267void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001268{
Jamie Madill5188a272018-07-25 10:53:56 -04001269 handleError(GetQueryObjectParameter(this, getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001270}
1271
Brandon Jones59770802018-04-02 13:18:42 -07001272void Context::getQueryObjectui64vRobust(GLuint id,
1273 GLenum pname,
1274 GLsizei bufSize,
1275 GLsizei *length,
1276 GLuint64 *params)
1277{
1278 getQueryObjectui64v(id, pname, params);
1279}
1280
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001281Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001282{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001283 return mState.mFramebuffers->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001284}
1285
Jamie Madill2f348d22017-06-05 10:50:59 -04001286FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001287{
Jamie Madill96a483b2017-06-27 16:49:21 -04001288 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001289}
1290
Corentin Wallezad3ae902018-03-09 13:40:42 -05001291Query *Context::getQuery(GLuint handle, bool create, QueryType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001292{
Jamie Madill96a483b2017-06-27 16:49:21 -04001293 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001294 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001295 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001296 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001297
1298 Query *query = mQueryMap.query(handle);
1299 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001300 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001301 ASSERT(type != QueryType::InvalidEnum);
Jamie Madill96a483b2017-06-27 16:49:21 -04001302 query = new Query(mImplementation->createQuery(type), handle);
1303 query->addRef();
1304 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001305 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001306 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001307}
1308
Geoff Lang70d0f492015-12-10 17:45:46 -05001309Query *Context::getQuery(GLuint handle) const
1310{
Jamie Madill96a483b2017-06-27 16:49:21 -04001311 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001312}
1313
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001314Texture *Context::getTargetTexture(TextureType type) const
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001315{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001316 ASSERT(ValidTextureTarget(this, type) || ValidTextureExternalTarget(this, type));
1317 return mGLState.getTargetTexture(type);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001318}
1319
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001320Texture *Context::getSamplerTexture(unsigned int sampler, TextureType type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001321{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001322 return mGLState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001323}
1324
Geoff Lang492a7e42014-11-05 13:27:06 -05001325Compiler *Context::getCompiler() const
1326{
Jamie Madill2f348d22017-06-05 10:50:59 -04001327 if (mCompiler.get() == nullptr)
1328 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001329 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001330 }
1331 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001332}
1333
Jamie Madillc1d770e2017-04-13 17:31:24 -04001334void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001335{
1336 switch (pname)
1337 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001338 case GL_SHADER_COMPILER:
1339 *params = GL_TRUE;
1340 break;
1341 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1342 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1343 break;
1344 default:
1345 mGLState.getBooleanv(pname, params);
1346 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001347 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001348}
1349
Jamie Madillc1d770e2017-04-13 17:31:24 -04001350void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001351{
Shannon Woods53a94a82014-06-24 15:20:36 -04001352 // Queries about context capabilities and maximums are answered by Context.
1353 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001354 switch (pname)
1355 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001356 case GL_ALIASED_LINE_WIDTH_RANGE:
1357 params[0] = mCaps.minAliasedLineWidth;
1358 params[1] = mCaps.maxAliasedLineWidth;
1359 break;
1360 case GL_ALIASED_POINT_SIZE_RANGE:
1361 params[0] = mCaps.minAliasedPointSize;
1362 params[1] = mCaps.maxAliasedPointSize;
1363 break;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07001364 case GL_SMOOTH_POINT_SIZE_RANGE:
1365 params[0] = mCaps.minSmoothPointSize;
1366 params[1] = mCaps.maxSmoothPointSize;
1367 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001368 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1369 ASSERT(mExtensions.textureFilterAnisotropic);
1370 *params = mExtensions.maxTextureAnisotropy;
1371 break;
1372 case GL_MAX_TEXTURE_LOD_BIAS:
1373 *params = mCaps.maxLODBias;
1374 break;
1375
1376 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1377 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1378 {
Lingfeng Yang3a41af62018-04-09 07:28:56 -07001379 // GLES1 emulation: // GL_PATH_(MODELVIEW|PROJECTION)_MATRIX_CHROMIUM collides with the
1380 // GLES1 constants for modelview/projection matrix.
1381 if (getClientVersion() < Version(2, 0))
1382 {
1383 mGLState.getFloatv(pname, params);
1384 }
1385 else
1386 {
1387 ASSERT(mExtensions.pathRendering);
1388 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1389 memcpy(params, m, 16 * sizeof(GLfloat));
1390 }
Jamie Madill231c7f52017-04-26 13:45:37 -04001391 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001392 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001393
Jamie Madill231c7f52017-04-26 13:45:37 -04001394 default:
1395 mGLState.getFloatv(pname, params);
1396 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001397 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001398}
1399
Jamie Madillc1d770e2017-04-13 17:31:24 -04001400void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001401{
Shannon Woods53a94a82014-06-24 15:20:36 -04001402 // Queries about context capabilities and maximums are answered by Context.
1403 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001404
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001405 switch (pname)
1406 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001407 case GL_MAX_VERTEX_ATTRIBS:
1408 *params = mCaps.maxVertexAttributes;
1409 break;
1410 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1411 *params = mCaps.maxVertexUniformVectors;
1412 break;
1413 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001414 *params = mCaps.maxShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001415 break;
1416 case GL_MAX_VARYING_VECTORS:
1417 *params = mCaps.maxVaryingVectors;
1418 break;
1419 case GL_MAX_VARYING_COMPONENTS:
1420 *params = mCaps.maxVertexOutputComponents;
1421 break;
1422 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1423 *params = mCaps.maxCombinedTextureImageUnits;
1424 break;
1425 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001426 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001427 break;
1428 case GL_MAX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001429 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001430 break;
1431 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1432 *params = mCaps.maxFragmentUniformVectors;
1433 break;
1434 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001435 *params = mCaps.maxShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001436 break;
1437 case GL_MAX_RENDERBUFFER_SIZE:
1438 *params = mCaps.maxRenderbufferSize;
1439 break;
1440 case GL_MAX_COLOR_ATTACHMENTS_EXT:
1441 *params = mCaps.maxColorAttachments;
1442 break;
1443 case GL_MAX_DRAW_BUFFERS_EXT:
1444 *params = mCaps.maxDrawBuffers;
1445 break;
1446 // case GL_FRAMEBUFFER_BINDING: // now equivalent to
1447 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
1448 case GL_SUBPIXEL_BITS:
1449 *params = 4;
1450 break;
1451 case GL_MAX_TEXTURE_SIZE:
1452 *params = mCaps.max2DTextureSize;
1453 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001454 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
1455 *params = mCaps.maxRectangleTextureSize;
1456 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001457 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1458 *params = mCaps.maxCubeMapTextureSize;
1459 break;
1460 case GL_MAX_3D_TEXTURE_SIZE:
1461 *params = mCaps.max3DTextureSize;
1462 break;
1463 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1464 *params = mCaps.maxArrayTextureLayers;
1465 break;
1466 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1467 *params = mCaps.uniformBufferOffsetAlignment;
1468 break;
1469 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1470 *params = mCaps.maxUniformBufferBindings;
1471 break;
1472 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001473 *params = mCaps.maxShaderUniformBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001474 break;
1475 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001476 *params = mCaps.maxShaderUniformBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001477 break;
1478 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1479 *params = mCaps.maxCombinedTextureImageUnits;
1480 break;
1481 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1482 *params = mCaps.maxVertexOutputComponents;
1483 break;
1484 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1485 *params = mCaps.maxFragmentInputComponents;
1486 break;
1487 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1488 *params = mCaps.minProgramTexelOffset;
1489 break;
1490 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1491 *params = mCaps.maxProgramTexelOffset;
1492 break;
1493 case GL_MAJOR_VERSION:
1494 *params = getClientVersion().major;
1495 break;
1496 case GL_MINOR_VERSION:
1497 *params = getClientVersion().minor;
1498 break;
1499 case GL_MAX_ELEMENTS_INDICES:
1500 *params = mCaps.maxElementsIndices;
1501 break;
1502 case GL_MAX_ELEMENTS_VERTICES:
1503 *params = mCaps.maxElementsVertices;
1504 break;
1505 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1506 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1507 break;
1508 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1509 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1510 break;
1511 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1512 *params = mCaps.maxTransformFeedbackSeparateComponents;
1513 break;
1514 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1515 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1516 break;
1517 case GL_MAX_SAMPLES_ANGLE:
1518 *params = mCaps.maxSamples;
1519 break;
1520 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001521 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001522 params[0] = mCaps.maxViewportWidth;
1523 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001524 }
1525 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001526 case GL_COMPRESSED_TEXTURE_FORMATS:
1527 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1528 params);
1529 break;
1530 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1531 *params = mResetStrategy;
1532 break;
1533 case GL_NUM_SHADER_BINARY_FORMATS:
1534 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1535 break;
1536 case GL_SHADER_BINARY_FORMATS:
1537 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1538 break;
1539 case GL_NUM_PROGRAM_BINARY_FORMATS:
1540 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1541 break;
1542 case GL_PROGRAM_BINARY_FORMATS:
1543 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1544 break;
1545 case GL_NUM_EXTENSIONS:
1546 *params = static_cast<GLint>(mExtensionStrings.size());
1547 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001548
Jamie Madill231c7f52017-04-26 13:45:37 -04001549 // GL_KHR_debug
1550 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1551 *params = mExtensions.maxDebugMessageLength;
1552 break;
1553 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1554 *params = mExtensions.maxDebugLoggedMessages;
1555 break;
1556 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1557 *params = mExtensions.maxDebugGroupStackDepth;
1558 break;
1559 case GL_MAX_LABEL_LENGTH:
1560 *params = mExtensions.maxLabelLength;
1561 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001562
Martin Radeve5285d22017-07-14 16:23:53 +03001563 // GL_ANGLE_multiview
1564 case GL_MAX_VIEWS_ANGLE:
1565 *params = mExtensions.maxViews;
1566 break;
1567
Jamie Madill231c7f52017-04-26 13:45:37 -04001568 // GL_EXT_disjoint_timer_query
1569 case GL_GPU_DISJOINT_EXT:
1570 *params = mImplementation->getGPUDisjoint();
1571 break;
1572 case GL_MAX_FRAMEBUFFER_WIDTH:
1573 *params = mCaps.maxFramebufferWidth;
1574 break;
1575 case GL_MAX_FRAMEBUFFER_HEIGHT:
1576 *params = mCaps.maxFramebufferHeight;
1577 break;
1578 case GL_MAX_FRAMEBUFFER_SAMPLES:
1579 *params = mCaps.maxFramebufferSamples;
1580 break;
1581 case GL_MAX_SAMPLE_MASK_WORDS:
1582 *params = mCaps.maxSampleMaskWords;
1583 break;
1584 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1585 *params = mCaps.maxColorTextureSamples;
1586 break;
1587 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1588 *params = mCaps.maxDepthTextureSamples;
1589 break;
1590 case GL_MAX_INTEGER_SAMPLES:
1591 *params = mCaps.maxIntegerSamples;
1592 break;
1593 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1594 *params = mCaps.maxVertexAttribRelativeOffset;
1595 break;
1596 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1597 *params = mCaps.maxVertexAttribBindings;
1598 break;
1599 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1600 *params = mCaps.maxVertexAttribStride;
1601 break;
1602 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001603 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001604 break;
1605 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001606 *params = mCaps.maxShaderAtomicCounters[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001607 break;
1608 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001609 *params = mCaps.maxShaderImageUniforms[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001610 break;
1611 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001612 *params = mCaps.maxShaderStorageBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001613 break;
1614 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001615 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001616 break;
1617 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001618 *params = mCaps.maxShaderAtomicCounters[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001619 break;
1620 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001621 *params = mCaps.maxShaderImageUniforms[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001622 break;
1623 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001624 *params = mCaps.maxShaderStorageBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001625 break;
1626 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1627 *params = mCaps.minProgramTextureGatherOffset;
1628 break;
1629 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1630 *params = mCaps.maxProgramTextureGatherOffset;
1631 break;
1632 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1633 *params = mCaps.maxComputeWorkGroupInvocations;
1634 break;
1635 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001636 *params = mCaps.maxShaderUniformBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001637 break;
1638 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001639 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001640 break;
1641 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1642 *params = mCaps.maxComputeSharedMemorySize;
1643 break;
1644 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001645 *params = mCaps.maxShaderUniformComponents[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001646 break;
1647 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001648 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001649 break;
1650 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001651 *params = mCaps.maxShaderAtomicCounters[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001652 break;
1653 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001654 *params = mCaps.maxShaderImageUniforms[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001655 break;
1656 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001657 *params =
1658 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Compute]);
Jamie Madill231c7f52017-04-26 13:45:37 -04001659 break;
1660 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001661 *params = mCaps.maxShaderStorageBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001662 break;
1663 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1664 *params = mCaps.maxCombinedShaderOutputResources;
1665 break;
1666 case GL_MAX_UNIFORM_LOCATIONS:
1667 *params = mCaps.maxUniformLocations;
1668 break;
1669 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1670 *params = mCaps.maxAtomicCounterBufferBindings;
1671 break;
1672 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1673 *params = mCaps.maxAtomicCounterBufferSize;
1674 break;
1675 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1676 *params = mCaps.maxCombinedAtomicCounterBuffers;
1677 break;
1678 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1679 *params = mCaps.maxCombinedAtomicCounters;
1680 break;
1681 case GL_MAX_IMAGE_UNITS:
1682 *params = mCaps.maxImageUnits;
1683 break;
1684 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1685 *params = mCaps.maxCombinedImageUniforms;
1686 break;
1687 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1688 *params = mCaps.maxShaderStorageBufferBindings;
1689 break;
1690 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1691 *params = mCaps.maxCombinedShaderStorageBlocks;
1692 break;
1693 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1694 *params = mCaps.shaderStorageBufferOffsetAlignment;
1695 break;
Jiawei Shao361df072017-11-22 09:33:59 +08001696
1697 // GL_EXT_geometry_shader
1698 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
1699 *params = mCaps.maxFramebufferLayers;
1700 break;
1701 case GL_LAYER_PROVOKING_VERTEX_EXT:
1702 *params = mCaps.layerProvokingVertex;
1703 break;
1704 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001705 *params = mCaps.maxShaderUniformComponents[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001706 break;
1707 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001708 *params = mCaps.maxShaderUniformBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001709 break;
1710 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001711 *params =
1712 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Geometry]);
Jiawei Shao361df072017-11-22 09:33:59 +08001713 break;
1714 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
1715 *params = mCaps.maxGeometryInputComponents;
1716 break;
1717 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
1718 *params = mCaps.maxGeometryOutputComponents;
1719 break;
1720 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
1721 *params = mCaps.maxGeometryOutputVertices;
1722 break;
1723 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
1724 *params = mCaps.maxGeometryTotalOutputComponents;
1725 break;
1726 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
1727 *params = mCaps.maxGeometryShaderInvocations;
1728 break;
1729 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001730 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001731 break;
1732 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001733 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001734 break;
1735 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001736 *params = mCaps.maxShaderAtomicCounters[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001737 break;
1738 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001739 *params = mCaps.maxShaderImageUniforms[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001740 break;
1741 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001742 *params = mCaps.maxShaderStorageBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001743 break;
Lingfeng Yang96310cd2018-03-28 11:56:28 -07001744 // GLES1 emulation: Caps queries
1745 case GL_MAX_TEXTURE_UNITS:
1746 *params = mCaps.maxMultitextureUnits;
1747 break;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001748 case GL_MAX_MODELVIEW_STACK_DEPTH:
1749 *params = mCaps.maxModelviewMatrixStackDepth;
1750 break;
1751 case GL_MAX_PROJECTION_STACK_DEPTH:
1752 *params = mCaps.maxProjectionMatrixStackDepth;
1753 break;
1754 case GL_MAX_TEXTURE_STACK_DEPTH:
1755 *params = mCaps.maxTextureMatrixStackDepth;
1756 break;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07001757 case GL_MAX_LIGHTS:
1758 *params = mCaps.maxLights;
1759 break;
Lingfeng Yang060088a2018-05-30 20:40:57 -07001760 case GL_MAX_CLIP_PLANES:
1761 *params = mCaps.maxClipPlanes;
1762 break;
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001763 // GLES1 emulation: Vertex attribute queries
1764 case GL_VERTEX_ARRAY_BUFFER_BINDING:
1765 case GL_NORMAL_ARRAY_BUFFER_BINDING:
1766 case GL_COLOR_ARRAY_BUFFER_BINDING:
1767 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
1768 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
1769 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1770 GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, params);
1771 break;
1772 case GL_VERTEX_ARRAY_STRIDE:
1773 case GL_NORMAL_ARRAY_STRIDE:
1774 case GL_COLOR_ARRAY_STRIDE:
1775 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
1776 case GL_TEXTURE_COORD_ARRAY_STRIDE:
1777 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1778 GL_VERTEX_ATTRIB_ARRAY_STRIDE, params);
1779 break;
1780 case GL_VERTEX_ARRAY_SIZE:
1781 case GL_COLOR_ARRAY_SIZE:
1782 case GL_TEXTURE_COORD_ARRAY_SIZE:
1783 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1784 GL_VERTEX_ATTRIB_ARRAY_SIZE, params);
1785 break;
1786 case GL_VERTEX_ARRAY_TYPE:
1787 case GL_COLOR_ARRAY_TYPE:
1788 case GL_NORMAL_ARRAY_TYPE:
1789 case GL_POINT_SIZE_ARRAY_TYPE_OES:
1790 case GL_TEXTURE_COORD_ARRAY_TYPE:
1791 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1792 GL_VERTEX_ATTRIB_ARRAY_TYPE, params);
1793 break;
1794
jchen1082af6202018-06-22 10:59:52 +08001795 // GL_KHR_parallel_shader_compile
1796 case GL_MAX_SHADER_COMPILER_THREADS_KHR:
1797 *params = mGLState.getMaxShaderCompilerThreads();
1798 break;
1799
Jamie Madill231c7f52017-04-26 13:45:37 -04001800 default:
Jamie Madille98b1b52018-03-08 09:47:23 -05001801 handleError(mGLState.getIntegerv(this, pname, params));
Jamie Madill231c7f52017-04-26 13:45:37 -04001802 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001803 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001804}
1805
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001806void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001807{
Shannon Woods53a94a82014-06-24 15:20:36 -04001808 // Queries about context capabilities and maximums are answered by Context.
1809 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001810 switch (pname)
1811 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001812 case GL_MAX_ELEMENT_INDEX:
1813 *params = mCaps.maxElementIndex;
1814 break;
1815 case GL_MAX_UNIFORM_BLOCK_SIZE:
1816 *params = mCaps.maxUniformBlockSize;
1817 break;
1818 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001819 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001820 break;
1821 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001822 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001823 break;
1824 case GL_MAX_SERVER_WAIT_TIMEOUT:
1825 *params = mCaps.maxServerWaitTimeout;
1826 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001827
Jamie Madill231c7f52017-04-26 13:45:37 -04001828 // GL_EXT_disjoint_timer_query
1829 case GL_TIMESTAMP_EXT:
1830 *params = mImplementation->getTimestamp();
1831 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001832
Jamie Madill231c7f52017-04-26 13:45:37 -04001833 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1834 *params = mCaps.maxShaderStorageBlockSize;
1835 break;
1836 default:
1837 UNREACHABLE();
1838 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001839 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001840}
1841
Geoff Lang70d0f492015-12-10 17:45:46 -05001842void Context::getPointerv(GLenum pname, void **params) const
1843{
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001844 mGLState.getPointerv(this, pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001845}
1846
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001847void Context::getPointervRobustANGLERobust(GLenum pname,
1848 GLsizei bufSize,
1849 GLsizei *length,
1850 void **params)
1851{
1852 UNIMPLEMENTED();
1853}
1854
Martin Radev66fb8202016-07-28 11:45:20 +03001855void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001856{
Shannon Woods53a94a82014-06-24 15:20:36 -04001857 // Queries about context capabilities and maximums are answered by Context.
1858 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001859
1860 GLenum nativeType;
1861 unsigned int numParams;
1862 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1863 ASSERT(queryStatus);
1864
1865 if (nativeType == GL_INT)
1866 {
1867 switch (target)
1868 {
1869 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1870 ASSERT(index < 3u);
1871 *data = mCaps.maxComputeWorkGroupCount[index];
1872 break;
1873 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1874 ASSERT(index < 3u);
1875 *data = mCaps.maxComputeWorkGroupSize[index];
1876 break;
1877 default:
1878 mGLState.getIntegeri_v(target, index, data);
1879 }
1880 }
1881 else
1882 {
1883 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1884 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001885}
1886
Brandon Jones59770802018-04-02 13:18:42 -07001887void Context::getIntegeri_vRobust(GLenum target,
1888 GLuint index,
1889 GLsizei bufSize,
1890 GLsizei *length,
1891 GLint *data)
1892{
1893 getIntegeri_v(target, index, data);
1894}
1895
Martin Radev66fb8202016-07-28 11:45:20 +03001896void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001897{
Shannon Woods53a94a82014-06-24 15:20:36 -04001898 // Queries about context capabilities and maximums are answered by Context.
1899 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001900
1901 GLenum nativeType;
1902 unsigned int numParams;
1903 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1904 ASSERT(queryStatus);
1905
1906 if (nativeType == GL_INT_64_ANGLEX)
1907 {
1908 mGLState.getInteger64i_v(target, index, data);
1909 }
1910 else
1911 {
1912 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1913 }
1914}
1915
Brandon Jones59770802018-04-02 13:18:42 -07001916void Context::getInteger64i_vRobust(GLenum target,
1917 GLuint index,
1918 GLsizei bufSize,
1919 GLsizei *length,
1920 GLint64 *data)
1921{
1922 getInteger64i_v(target, index, data);
1923}
1924
Martin Radev66fb8202016-07-28 11:45:20 +03001925void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1926{
1927 // Queries about context capabilities and maximums are answered by Context.
1928 // Queries about current GL state values are answered by State.
1929
1930 GLenum nativeType;
1931 unsigned int numParams;
1932 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1933 ASSERT(queryStatus);
1934
1935 if (nativeType == GL_BOOL)
1936 {
1937 mGLState.getBooleani_v(target, index, data);
1938 }
1939 else
1940 {
1941 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1942 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001943}
1944
Brandon Jones59770802018-04-02 13:18:42 -07001945void Context::getBooleani_vRobust(GLenum target,
1946 GLuint index,
1947 GLsizei bufSize,
1948 GLsizei *length,
1949 GLboolean *data)
1950{
1951 getBooleani_v(target, index, data);
1952}
1953
Corentin Wallez336129f2017-10-17 15:55:40 -04001954void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001955{
1956 Buffer *buffer = mGLState.getTargetBuffer(target);
1957 QueryBufferParameteriv(buffer, pname, params);
1958}
1959
Brandon Jones59770802018-04-02 13:18:42 -07001960void Context::getBufferParameterivRobust(BufferBinding target,
1961 GLenum pname,
1962 GLsizei bufSize,
1963 GLsizei *length,
1964 GLint *params)
1965{
1966 getBufferParameteriv(target, pname, params);
1967}
1968
He Yunchao010e4db2017-03-03 14:22:06 +08001969void Context::getFramebufferAttachmentParameteriv(GLenum target,
1970 GLenum attachment,
1971 GLenum pname,
1972 GLint *params)
1973{
1974 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08001975 QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08001976}
1977
Brandon Jones59770802018-04-02 13:18:42 -07001978void Context::getFramebufferAttachmentParameterivRobust(GLenum target,
1979 GLenum attachment,
1980 GLenum pname,
1981 GLsizei bufSize,
1982 GLsizei *length,
1983 GLint *params)
1984{
1985 getFramebufferAttachmentParameteriv(target, attachment, pname, params);
1986}
1987
He Yunchao010e4db2017-03-03 14:22:06 +08001988void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
1989{
1990 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
1991 QueryRenderbufferiv(this, renderbuffer, pname, params);
1992}
1993
Brandon Jones59770802018-04-02 13:18:42 -07001994void Context::getRenderbufferParameterivRobust(GLenum target,
1995 GLenum pname,
1996 GLsizei bufSize,
1997 GLsizei *length,
1998 GLint *params)
1999{
2000 getRenderbufferParameteriv(target, pname, params);
2001}
2002
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002003void Context::getTexParameterfv(TextureType target, GLenum pname, GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002004{
2005 Texture *texture = getTargetTexture(target);
2006 QueryTexParameterfv(texture, pname, params);
2007}
2008
Brandon Jones59770802018-04-02 13:18:42 -07002009void Context::getTexParameterfvRobust(TextureType target,
2010 GLenum pname,
2011 GLsizei bufSize,
2012 GLsizei *length,
2013 GLfloat *params)
2014{
2015 getTexParameterfv(target, pname, params);
2016}
2017
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002018void Context::getTexParameteriv(TextureType target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002019{
2020 Texture *texture = getTargetTexture(target);
2021 QueryTexParameteriv(texture, pname, params);
2022}
Jiajia Qin5451d532017-11-16 17:16:34 +08002023
Brandon Jones59770802018-04-02 13:18:42 -07002024void Context::getTexParameterivRobust(TextureType target,
2025 GLenum pname,
2026 GLsizei bufSize,
2027 GLsizei *length,
2028 GLint *params)
2029{
2030 getTexParameteriv(target, pname, params);
2031}
2032
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002033void Context::getTexParameterIivRobust(TextureType target,
2034 GLenum pname,
2035 GLsizei bufSize,
2036 GLsizei *length,
2037 GLint *params)
2038{
2039 UNIMPLEMENTED();
2040}
2041
2042void Context::getTexParameterIuivRobust(TextureType target,
2043 GLenum pname,
2044 GLsizei bufSize,
2045 GLsizei *length,
2046 GLuint *params)
2047{
2048 UNIMPLEMENTED();
2049}
2050
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002051void Context::getTexLevelParameteriv(TextureTarget target, GLint level, GLenum pname, GLint *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002052{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002053 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002054 QueryTexLevelParameteriv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002055}
2056
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002057void Context::getTexLevelParameterivRobust(TextureTarget target,
2058 GLint level,
2059 GLenum pname,
2060 GLsizei bufSize,
2061 GLsizei *length,
2062 GLint *params)
2063{
2064 UNIMPLEMENTED();
2065}
2066
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002067void Context::getTexLevelParameterfv(TextureTarget target,
2068 GLint level,
2069 GLenum pname,
2070 GLfloat *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002071{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002072 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002073 QueryTexLevelParameterfv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002074}
2075
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002076void Context::getTexLevelParameterfvRobust(TextureTarget target,
2077 GLint level,
2078 GLenum pname,
2079 GLsizei bufSize,
2080 GLsizei *length,
2081 GLfloat *params)
2082{
2083 UNIMPLEMENTED();
2084}
2085
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002086void Context::texParameterf(TextureType target, GLenum pname, GLfloat param)
He Yunchao010e4db2017-03-03 14:22:06 +08002087{
2088 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002089 SetTexParameterf(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002090 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002091}
2092
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002093void Context::texParameterfv(TextureType target, GLenum pname, const GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002094{
2095 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002096 SetTexParameterfv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002097 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002098}
2099
Brandon Jones59770802018-04-02 13:18:42 -07002100void Context::texParameterfvRobust(TextureType target,
2101 GLenum pname,
2102 GLsizei bufSize,
2103 const GLfloat *params)
2104{
2105 texParameterfv(target, pname, params);
2106}
2107
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002108void Context::texParameteri(TextureType target, GLenum pname, GLint param)
He Yunchao010e4db2017-03-03 14:22:06 +08002109{
2110 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002111 SetTexParameteri(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002112 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002113}
2114
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002115void Context::texParameteriv(TextureType target, GLenum pname, const GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002116{
2117 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002118 SetTexParameteriv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002119 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002120}
2121
Brandon Jones59770802018-04-02 13:18:42 -07002122void Context::texParameterivRobust(TextureType target,
2123 GLenum pname,
2124 GLsizei bufSize,
2125 const GLint *params)
2126{
2127 texParameteriv(target, pname, params);
2128}
2129
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002130void Context::texParameterIivRobust(TextureType target,
2131 GLenum pname,
2132 GLsizei bufSize,
2133 const GLint *params)
2134{
2135 UNIMPLEMENTED();
2136}
2137
2138void Context::texParameterIuivRobust(TextureType target,
2139 GLenum pname,
2140 GLsizei bufSize,
2141 const GLuint *params)
2142{
2143 UNIMPLEMENTED();
2144}
2145
Jamie Madill493f9572018-05-24 19:52:15 -04002146void Context::drawArrays(PrimitiveMode mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002147{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002148 // No-op if count draws no primitives for given mode
2149 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002150 {
2151 return;
2152 }
2153
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002154 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002155 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
Jamie Madill09463932018-04-04 05:26:59 -04002156 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count, 1);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002157}
2158
Jamie Madill493f9572018-05-24 19:52:15 -04002159void Context::drawArraysInstanced(PrimitiveMode mode,
2160 GLint first,
2161 GLsizei count,
2162 GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04002163{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002164 // No-op if count draws no primitives for given mode
2165 if (noopDrawInstanced(mode, count, instanceCount))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002166 {
2167 return;
2168 }
2169
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002170 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002171 ANGLE_CONTEXT_TRY(
2172 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
Jamie Madill09463932018-04-04 05:26:59 -04002173 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count,
2174 instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -04002175}
2176
Jamie Madill493f9572018-05-24 19:52:15 -04002177void Context::drawElements(PrimitiveMode mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002178{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002179 // No-op if count draws no primitives for given mode
2180 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002181 {
2182 return;
2183 }
2184
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002185 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002186 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04002187}
2188
Jamie Madill493f9572018-05-24 19:52:15 -04002189void Context::drawElementsInstanced(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002190 GLsizei count,
2191 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002192 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04002193 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04002194{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002195 // No-op if count draws no primitives for given mode
2196 if (noopDrawInstanced(mode, count, instances))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002197 {
2198 return;
2199 }
2200
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002201 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002202 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08002203 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04002204}
2205
Jamie Madill493f9572018-05-24 19:52:15 -04002206void Context::drawRangeElements(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002207 GLuint start,
2208 GLuint end,
2209 GLsizei count,
2210 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002211 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04002212{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002213 // No-op if count draws no primitives for given mode
2214 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002215 {
2216 return;
2217 }
2218
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002219 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002220 ANGLE_CONTEXT_TRY(
2221 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002222}
2223
Jamie Madill493f9572018-05-24 19:52:15 -04002224void Context::drawArraysIndirect(PrimitiveMode mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002225{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002226 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002227 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002228}
2229
Jamie Madill493f9572018-05-24 19:52:15 -04002230void Context::drawElementsIndirect(PrimitiveMode mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002231{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002232 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002233 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002234}
2235
Jamie Madill675fe712016-12-19 13:07:54 -05002236void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002237{
Jamie Madillafa02a22017-11-23 12:57:38 -05002238 handleError(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05002239}
2240
Jamie Madill675fe712016-12-19 13:07:54 -05002241void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05002242{
Jamie Madillafa02a22017-11-23 12:57:38 -05002243 handleError(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002244}
2245
Austin Kinross6ee1e782015-05-29 17:05:37 -07002246void Context::insertEventMarker(GLsizei length, const char *marker)
2247{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002248 ASSERT(mImplementation);
2249 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07002250}
2251
2252void Context::pushGroupMarker(GLsizei length, const char *marker)
2253{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002254 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05002255
2256 if (marker == nullptr)
2257 {
2258 // From the EXT_debug_marker spec,
2259 // "If <marker> is null then an empty string is pushed on the stack."
2260 mImplementation->pushGroupMarker(length, "");
2261 }
2262 else
2263 {
2264 mImplementation->pushGroupMarker(length, marker);
2265 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07002266}
2267
2268void Context::popGroupMarker()
2269{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002270 ASSERT(mImplementation);
2271 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07002272}
2273
Geoff Langd8605522016-04-13 10:19:12 -04002274void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
2275{
2276 Program *programObject = getProgram(program);
2277 ASSERT(programObject);
2278
2279 programObject->bindUniformLocation(location, name);
2280}
2281
Brandon Jones59770802018-04-02 13:18:42 -07002282void Context::coverageModulation(GLenum components)
Sami Väisänena797e062016-05-12 15:23:40 +03002283{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002284 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03002285}
2286
Brandon Jones59770802018-04-02 13:18:42 -07002287void Context::matrixLoadf(GLenum matrixMode, const GLfloat *matrix)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002288{
2289 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
2290}
2291
Brandon Jones59770802018-04-02 13:18:42 -07002292void Context::matrixLoadIdentity(GLenum matrixMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002293{
2294 GLfloat I[16];
2295 angle::Matrix<GLfloat>::setToIdentity(I);
2296
2297 mGLState.loadPathRenderingMatrix(matrixMode, I);
2298}
2299
2300void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
2301{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002302 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002303 if (!pathObj)
2304 return;
2305
Geoff Lang9bf86f02018-07-26 11:46:34 -04002306 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002307
2308 mImplementation->stencilFillPath(pathObj, fillMode, mask);
2309}
2310
2311void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
2312{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002313 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002314 if (!pathObj)
2315 return;
2316
Geoff Lang9bf86f02018-07-26 11:46:34 -04002317 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002318
2319 mImplementation->stencilStrokePath(pathObj, reference, mask);
2320}
2321
2322void Context::coverFillPath(GLuint path, GLenum coverMode)
2323{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002324 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002325 if (!pathObj)
2326 return;
2327
Geoff Lang9bf86f02018-07-26 11:46:34 -04002328 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002329
2330 mImplementation->coverFillPath(pathObj, coverMode);
2331}
2332
2333void Context::coverStrokePath(GLuint path, GLenum coverMode)
2334{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002335 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002336 if (!pathObj)
2337 return;
2338
Geoff Lang9bf86f02018-07-26 11:46:34 -04002339 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002340
2341 mImplementation->coverStrokePath(pathObj, coverMode);
2342}
2343
2344void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
2345{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002346 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002347 if (!pathObj)
2348 return;
2349
Geoff Lang9bf86f02018-07-26 11:46:34 -04002350 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002351
2352 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
2353}
2354
2355void Context::stencilThenCoverStrokePath(GLuint path,
2356 GLint reference,
2357 GLuint mask,
2358 GLenum coverMode)
2359{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002360 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002361 if (!pathObj)
2362 return;
2363
Geoff Lang9bf86f02018-07-26 11:46:34 -04002364 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002365
2366 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2367}
2368
Sami Väisänend59ca052016-06-21 16:10:00 +03002369void Context::coverFillPathInstanced(GLsizei numPaths,
2370 GLenum pathNameType,
2371 const void *paths,
2372 GLuint pathBase,
2373 GLenum coverMode,
2374 GLenum transformType,
2375 const GLfloat *transformValues)
2376{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002377 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002378
Geoff Lang9bf86f02018-07-26 11:46:34 -04002379 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002380
2381 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2382}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002383
Sami Väisänend59ca052016-06-21 16:10:00 +03002384void Context::coverStrokePathInstanced(GLsizei numPaths,
2385 GLenum pathNameType,
2386 const void *paths,
2387 GLuint pathBase,
2388 GLenum coverMode,
2389 GLenum transformType,
2390 const GLfloat *transformValues)
2391{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002392 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002393
2394 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Lang9bf86f02018-07-26 11:46:34 -04002395 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002396
2397 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2398 transformValues);
2399}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002400
Sami Väisänend59ca052016-06-21 16:10:00 +03002401void Context::stencilFillPathInstanced(GLsizei numPaths,
2402 GLenum pathNameType,
2403 const void *paths,
2404 GLuint pathBase,
2405 GLenum fillMode,
2406 GLuint mask,
2407 GLenum transformType,
2408 const GLfloat *transformValues)
2409{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002410 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002411
2412 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Lang9bf86f02018-07-26 11:46:34 -04002413 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002414
2415 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2416 transformValues);
2417}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002418
Sami Väisänend59ca052016-06-21 16:10:00 +03002419void Context::stencilStrokePathInstanced(GLsizei numPaths,
2420 GLenum pathNameType,
2421 const void *paths,
2422 GLuint pathBase,
2423 GLint reference,
2424 GLuint mask,
2425 GLenum transformType,
2426 const GLfloat *transformValues)
2427{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002428 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002429
Geoff Lang9bf86f02018-07-26 11:46:34 -04002430 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
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
Geoff Lang9bf86f02018-07-26 11:46:34 -04002448 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002449
2450 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2451 transformType, transformValues);
2452}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002453
Sami Väisänend59ca052016-06-21 16:10:00 +03002454void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2455 GLenum pathNameType,
2456 const void *paths,
2457 GLuint pathBase,
2458 GLint reference,
2459 GLuint mask,
2460 GLenum coverMode,
2461 GLenum transformType,
2462 const GLfloat *transformValues)
2463{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002464 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002465
Geoff Lang9bf86f02018-07-26 11:46:34 -04002466 ANGLE_CONTEXT_TRY(syncStateForPathOperation());
Sami Väisänend59ca052016-06-21 16:10:00 +03002467
2468 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2469 transformType, transformValues);
2470}
2471
Sami Väisänen46eaa942016-06-29 10:26:37 +03002472void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2473{
2474 auto *programObject = getProgram(program);
2475
2476 programObject->bindFragmentInputLocation(location, name);
2477}
2478
2479void Context::programPathFragmentInputGen(GLuint program,
2480 GLint location,
2481 GLenum genMode,
2482 GLint components,
2483 const GLfloat *coeffs)
2484{
2485 auto *programObject = getProgram(program);
2486
Jamie Madillbd044ed2017-06-05 12:59:21 -04002487 programObject->pathFragmentInputGen(this, location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002488}
2489
jchen1015015f72017-03-16 13:54:21 +08002490GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2491{
jchen10fd7c3b52017-03-21 15:36:03 +08002492 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002493 return QueryProgramResourceIndex(programObject, programInterface, name);
2494}
2495
jchen10fd7c3b52017-03-21 15:36:03 +08002496void Context::getProgramResourceName(GLuint program,
2497 GLenum programInterface,
2498 GLuint index,
2499 GLsizei bufSize,
2500 GLsizei *length,
2501 GLchar *name)
2502{
2503 const auto *programObject = getProgram(program);
2504 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2505}
2506
jchen10191381f2017-04-11 13:59:04 +08002507GLint Context::getProgramResourceLocation(GLuint program,
2508 GLenum programInterface,
2509 const GLchar *name)
2510{
2511 const auto *programObject = getProgram(program);
2512 return QueryProgramResourceLocation(programObject, programInterface, name);
2513}
2514
jchen10880683b2017-04-12 16:21:55 +08002515void Context::getProgramResourceiv(GLuint program,
2516 GLenum programInterface,
2517 GLuint index,
2518 GLsizei propCount,
2519 const GLenum *props,
2520 GLsizei bufSize,
2521 GLsizei *length,
2522 GLint *params)
2523{
2524 const auto *programObject = getProgram(program);
2525 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2526 length, params);
2527}
2528
jchen10d9cd7b72017-08-30 15:04:25 +08002529void Context::getProgramInterfaceiv(GLuint program,
2530 GLenum programInterface,
2531 GLenum pname,
2532 GLint *params)
2533{
2534 const auto *programObject = getProgram(program);
2535 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2536}
2537
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002538void Context::getProgramInterfaceivRobust(GLuint program,
2539 GLenum programInterface,
2540 GLenum pname,
2541 GLsizei bufSize,
2542 GLsizei *length,
2543 GLint *params)
2544{
2545 UNIMPLEMENTED();
2546}
2547
Jamie Madill6b873dd2018-07-12 23:56:30 -04002548void Context::handleError(const Error &error)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002549{
Jamie Madill6b873dd2018-07-12 23:56:30 -04002550 mErrors.handleError(error);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002551}
2552
2553// Get one of the recorded errors and clear its flag, if any.
2554// [OpenGL ES 2.0.24] section 2.5 page 13.
2555GLenum Context::getError()
2556{
Geoff Langda5777c2014-07-11 09:52:58 -04002557 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002558 {
Geoff Langda5777c2014-07-11 09:52:58 -04002559 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002560 }
Geoff Langda5777c2014-07-11 09:52:58 -04002561 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002562 {
Jamie Madill6b873dd2018-07-12 23:56:30 -04002563 return mErrors.popError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002564 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002565}
2566
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002567// NOTE: this function should not assume that this context is current!
Jamie Madill6b873dd2018-07-12 23:56:30 -04002568void Context::markContextLost()
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002569{
2570 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002571 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002572 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002573 mContextLostForced = true;
2574 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002575 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002576}
2577
Jamie Madill427064d2018-04-13 16:20:34 -04002578bool Context::isContextLost() const
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002579{
2580 return mContextLost;
2581}
2582
Jamie Madillfa920eb2018-01-04 11:45:50 -05002583GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002584{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002585 // Even if the application doesn't want to know about resets, we want to know
2586 // as it will allow us to skip all the calls.
2587 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002588 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002589 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002590 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002591 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002592 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002593
2594 // EXT_robustness, section 2.6: If the reset notification behavior is
2595 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2596 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2597 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002598 }
2599
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002600 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2601 // status should be returned at least once, and GL_NO_ERROR should be returned
2602 // once the device has finished resetting.
2603 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002604 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002605 ASSERT(mResetStatus == GL_NO_ERROR);
2606 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002607
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002608 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002609 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002610 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002611 }
2612 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002613 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002614 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002615 // If markContextLost was used to mark the context lost then
2616 // assume that is not recoverable, and continue to report the
2617 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002618 mResetStatus = mImplementation->getResetStatus();
2619 }
Jamie Madill893ab082014-05-16 16:56:10 -04002620
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002621 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002622}
2623
2624bool Context::isResetNotificationEnabled()
2625{
2626 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2627}
2628
Corentin Walleze3b10e82015-05-20 11:06:25 -04002629const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002630{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002631 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002632}
2633
2634EGLenum Context::getClientType() const
2635{
2636 return mClientType;
2637}
2638
2639EGLenum Context::getRenderBuffer() const
2640{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002641 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2642 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002643 {
2644 return EGL_NONE;
2645 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002646
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002647 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002648 ASSERT(backAttachment != nullptr);
2649 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002650}
2651
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002652VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002653{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002654 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002655 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2656 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002657 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002658 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2659 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002660
Jamie Madill96a483b2017-06-27 16:49:21 -04002661 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002662 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002663
2664 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002665}
2666
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002667TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002668{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002669 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002670 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2671 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002672 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002673 transformFeedback =
2674 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002675 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002676 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002677 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002678
2679 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002680}
2681
2682bool Context::isVertexArrayGenerated(GLuint vertexArray)
2683{
Jamie Madill96a483b2017-06-27 16:49:21 -04002684 ASSERT(mVertexArrayMap.contains(0));
2685 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002686}
2687
2688bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2689{
Jamie Madill96a483b2017-06-27 16:49:21 -04002690 ASSERT(mTransformFeedbackMap.contains(0));
2691 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002692}
2693
Shannon Woods53a94a82014-06-24 15:20:36 -04002694void Context::detachTexture(GLuint texture)
2695{
2696 // Simple pass-through to State's detachTexture method, as textures do not require
2697 // allocation map management either here or in the resource manager at detach time.
2698 // Zero textures are held by the Context, and we don't attempt to request them from
2699 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002700 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002701}
2702
James Darpinian4d9d4832018-03-13 12:43:28 -07002703void Context::detachBuffer(Buffer *buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002704{
Yuly Novikov5807a532015-12-03 13:01:22 -05002705 // Simple pass-through to State's detachBuffer method, since
2706 // only buffer attachments to container objects that are bound to the current context
2707 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002708
Yuly Novikov5807a532015-12-03 13:01:22 -05002709 // [OpenGL ES 3.2] section 5.1.2 page 45:
2710 // Attachments to unbound container objects, such as
2711 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2712 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002713 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002714}
2715
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002716void Context::detachFramebuffer(GLuint framebuffer)
2717{
Shannon Woods53a94a82014-06-24 15:20:36 -04002718 // Framebuffer detachment is handled by Context, because 0 is a valid
2719 // Framebuffer object, and a pointer to it must be passed from Context
2720 // to State at binding time.
2721
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002722 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002723 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2724 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2725 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002726
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002727 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002728 {
2729 bindReadFramebuffer(0);
2730 }
2731
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002732 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002733 {
2734 bindDrawFramebuffer(0);
2735 }
2736}
2737
2738void Context::detachRenderbuffer(GLuint renderbuffer)
2739{
Jamie Madilla02315b2017-02-23 14:14:47 -05002740 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002741}
2742
Jamie Madill57a89722013-07-02 11:57:03 -04002743void Context::detachVertexArray(GLuint vertexArray)
2744{
Jamie Madill77a72f62015-04-14 11:18:32 -04002745 // Vertex array detachment is handled by Context, because 0 is a valid
2746 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002747 // binding time.
2748
Jamie Madill57a89722013-07-02 11:57:03 -04002749 // [OpenGL ES 3.0.2] section 2.10 page 43:
2750 // If a vertex array object that is currently bound is deleted, the binding
2751 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madill7267aa62018-04-17 15:28:21 -04002752 if (mGLState.removeVertexArrayBinding(this, vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002753 {
2754 bindVertexArray(0);
2755 }
2756}
2757
Geoff Langc8058452014-02-03 12:04:11 -05002758void Context::detachTransformFeedback(GLuint transformFeedback)
2759{
Corentin Walleza2257da2016-04-19 16:43:12 -04002760 // Transform feedback detachment is handled by Context, because 0 is a valid
2761 // transform feedback, and a pointer to it must be passed from Context to State at
2762 // binding time.
2763
2764 // The OpenGL specification doesn't mention what should happen when the currently bound
2765 // transform feedback object is deleted. Since it is a container object, we treat it like
2766 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002767 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002768 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002769 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002770 }
Geoff Langc8058452014-02-03 12:04:11 -05002771}
2772
Jamie Madilldc356042013-07-19 16:36:57 -04002773void Context::detachSampler(GLuint sampler)
2774{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002775 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002776}
2777
Yunchao Hea336b902017-08-02 16:05:21 +08002778void Context::detachProgramPipeline(GLuint pipeline)
2779{
2780 mGLState.detachProgramPipeline(this, pipeline);
2781}
2782
Jamie Madill3ef140a2017-08-26 23:11:21 -04002783void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002784{
Shaodde78e82017-05-22 14:13:27 +08002785 mGLState.setVertexAttribDivisor(this, index, divisor);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002786}
2787
Jamie Madille29d1672013-07-19 16:36:57 -04002788void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2789{
Geoff Langc1984ed2016-10-07 12:41:00 -04002790 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002791 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002792 SetSamplerParameteri(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002793 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002794}
Jamie Madille29d1672013-07-19 16:36:57 -04002795
Geoff Langc1984ed2016-10-07 12:41:00 -04002796void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2797{
2798 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002799 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002800 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002801 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002802}
2803
Brandon Jones59770802018-04-02 13:18:42 -07002804void Context::samplerParameterivRobust(GLuint sampler,
2805 GLenum pname,
2806 GLsizei bufSize,
2807 const GLint *param)
2808{
2809 samplerParameteriv(sampler, pname, param);
2810}
2811
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002812void Context::samplerParameterIivRobust(GLuint sampler,
2813 GLenum pname,
2814 GLsizei bufSize,
2815 const GLint *param)
2816{
2817 UNIMPLEMENTED();
2818}
2819
2820void Context::samplerParameterIuivRobust(GLuint sampler,
2821 GLenum pname,
2822 GLsizei bufSize,
2823 const GLuint *param)
2824{
2825 UNIMPLEMENTED();
2826}
2827
Jamie Madille29d1672013-07-19 16:36:57 -04002828void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2829{
Geoff Langc1984ed2016-10-07 12:41:00 -04002830 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002831 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002832 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002833 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002834}
2835
Geoff Langc1984ed2016-10-07 12:41:00 -04002836void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002837{
Geoff Langc1984ed2016-10-07 12:41:00 -04002838 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002839 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002840 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002841 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002842}
2843
Brandon Jones59770802018-04-02 13:18:42 -07002844void Context::samplerParameterfvRobust(GLuint sampler,
2845 GLenum pname,
2846 GLsizei bufSize,
2847 const GLfloat *param)
2848{
2849 samplerParameterfv(sampler, pname, param);
2850}
2851
Geoff Langc1984ed2016-10-07 12:41:00 -04002852void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002853{
Geoff Langc1984ed2016-10-07 12:41:00 -04002854 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002855 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002856 QuerySamplerParameteriv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002857 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002858}
Jamie Madill9675b802013-07-19 16:36:59 -04002859
Brandon Jones59770802018-04-02 13:18:42 -07002860void Context::getSamplerParameterivRobust(GLuint sampler,
2861 GLenum pname,
2862 GLsizei bufSize,
2863 GLsizei *length,
2864 GLint *params)
2865{
2866 getSamplerParameteriv(sampler, pname, params);
2867}
2868
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002869void Context::getSamplerParameterIivRobust(GLuint sampler,
2870 GLenum pname,
2871 GLsizei bufSize,
2872 GLsizei *length,
2873 GLint *params)
2874{
2875 UNIMPLEMENTED();
2876}
2877
2878void Context::getSamplerParameterIuivRobust(GLuint sampler,
2879 GLenum pname,
2880 GLsizei bufSize,
2881 GLsizei *length,
2882 GLuint *params)
2883{
2884 UNIMPLEMENTED();
2885}
2886
Geoff Langc1984ed2016-10-07 12:41:00 -04002887void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2888{
2889 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002890 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002891 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002892 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002893}
2894
Brandon Jones59770802018-04-02 13:18:42 -07002895void Context::getSamplerParameterfvRobust(GLuint sampler,
2896 GLenum pname,
2897 GLsizei bufSize,
2898 GLsizei *length,
2899 GLfloat *params)
2900{
2901 getSamplerParameterfv(sampler, pname, params);
2902}
2903
Olli Etuahof0fee072016-03-30 15:11:58 +03002904void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2905{
2906 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002907 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002908}
2909
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002910void Context::initRendererString()
2911{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002912 std::ostringstream rendererString;
2913 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002914 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002915 rendererString << ")";
2916
Geoff Langcec35902014-04-16 10:52:36 -04002917 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002918}
2919
Geoff Langc339c4e2016-11-29 10:37:36 -05002920void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002921{
Geoff Langc339c4e2016-11-29 10:37:36 -05002922 const Version &clientVersion = getClientVersion();
2923
2924 std::ostringstream versionString;
2925 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2926 << ANGLE_VERSION_STRING << ")";
2927 mVersionString = MakeStaticString(versionString.str());
2928
2929 std::ostringstream shadingLanguageVersionString;
2930 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2931 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2932 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2933 << ")";
2934 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002935}
2936
Geoff Langcec35902014-04-16 10:52:36 -04002937void Context::initExtensionStrings()
2938{
Geoff Langc339c4e2016-11-29 10:37:36 -05002939 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2940 std::ostringstream combinedStringStream;
2941 std::copy(strings.begin(), strings.end(),
2942 std::ostream_iterator<const char *>(combinedStringStream, " "));
2943 return MakeStaticString(combinedStringStream.str());
2944 };
2945
2946 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002947 for (const auto &extensionString : mExtensions.getStrings())
2948 {
2949 mExtensionStrings.push_back(MakeStaticString(extensionString));
2950 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002951 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002952
Geoff Langc339c4e2016-11-29 10:37:36 -05002953 mRequestableExtensionStrings.clear();
2954 for (const auto &extensionInfo : GetExtensionInfoMap())
2955 {
2956 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08002957 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
Geoff Langb0f917f2017-12-05 13:41:54 -05002958 mSupportedExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002959 {
2960 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
2961 }
2962 }
2963 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002964}
2965
Geoff Langc339c4e2016-11-29 10:37:36 -05002966const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04002967{
Geoff Langc339c4e2016-11-29 10:37:36 -05002968 switch (name)
2969 {
2970 case GL_VENDOR:
2971 return reinterpret_cast<const GLubyte *>("Google Inc.");
2972
2973 case GL_RENDERER:
2974 return reinterpret_cast<const GLubyte *>(mRendererString);
2975
2976 case GL_VERSION:
2977 return reinterpret_cast<const GLubyte *>(mVersionString);
2978
2979 case GL_SHADING_LANGUAGE_VERSION:
2980 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
2981
2982 case GL_EXTENSIONS:
2983 return reinterpret_cast<const GLubyte *>(mExtensionString);
2984
2985 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2986 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
2987
2988 default:
2989 UNREACHABLE();
2990 return nullptr;
2991 }
Geoff Langcec35902014-04-16 10:52:36 -04002992}
2993
Geoff Langc339c4e2016-11-29 10:37:36 -05002994const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04002995{
Geoff Langc339c4e2016-11-29 10:37:36 -05002996 switch (name)
2997 {
2998 case GL_EXTENSIONS:
2999 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
3000
3001 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
3002 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
3003
3004 default:
3005 UNREACHABLE();
3006 return nullptr;
3007 }
Geoff Langcec35902014-04-16 10:52:36 -04003008}
3009
3010size_t Context::getExtensionStringCount() const
3011{
3012 return mExtensionStrings.size();
3013}
3014
Geoff Lang111a99e2017-10-17 10:58:41 -04003015bool Context::isExtensionRequestable(const char *name)
3016{
3017 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3018 auto extension = extensionInfos.find(name);
3019
Geoff Lang111a99e2017-10-17 10:58:41 -04003020 return extension != extensionInfos.end() && extension->second.Requestable &&
Geoff Langb0f917f2017-12-05 13:41:54 -05003021 mSupportedExtensions.*(extension->second.ExtensionsMember);
Geoff Lang111a99e2017-10-17 10:58:41 -04003022}
3023
Geoff Langc339c4e2016-11-29 10:37:36 -05003024void Context::requestExtension(const char *name)
3025{
3026 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3027 ASSERT(extensionInfos.find(name) != extensionInfos.end());
3028 const auto &extension = extensionInfos.at(name);
3029 ASSERT(extension.Requestable);
Geoff Langb0f917f2017-12-05 13:41:54 -05003030 ASSERT(isExtensionRequestable(name));
Geoff Langc339c4e2016-11-29 10:37:36 -05003031
3032 if (mExtensions.*(extension.ExtensionsMember))
3033 {
3034 // Extension already enabled
3035 return;
3036 }
3037
3038 mExtensions.*(extension.ExtensionsMember) = true;
3039 updateCaps();
3040 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08003041
Jamie Madill2f348d22017-06-05 10:50:59 -04003042 // Release the shader compiler so it will be re-created with the requested extensions enabled.
3043 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04003044
Jamie Madill81c2e252017-09-09 23:32:46 -04003045 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
3046 // sampleable.
Jamie Madilld4442552018-02-27 22:03:47 -05003047 mState.mTextures->signalAllTexturesDirty(this);
Geoff Lang9aded172017-04-05 11:07:56 -04003048 for (auto &zeroTexture : mZeroTextures)
3049 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003050 if (zeroTexture.get() != nullptr)
3051 {
3052 zeroTexture->signalDirty(this, InitState::Initialized);
3053 }
Geoff Lang9aded172017-04-05 11:07:56 -04003054 }
3055
3056 mState.mFramebuffers->invalidateFramebufferComplenessCache();
Geoff Langc339c4e2016-11-29 10:37:36 -05003057}
3058
3059size_t Context::getRequestableExtensionStringCount() const
3060{
3061 return mRequestableExtensionStrings.size();
3062}
3063
Jamie Madill493f9572018-05-24 19:52:15 -04003064void Context::beginTransformFeedback(PrimitiveMode primitiveMode)
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003065{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003066 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003067 ASSERT(transformFeedback != nullptr);
3068 ASSERT(!transformFeedback->isPaused());
3069
Jamie Madill6c1f6712017-02-14 19:08:04 -05003070 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003071}
3072
3073bool Context::hasActiveTransformFeedback(GLuint program) const
3074{
3075 for (auto pair : mTransformFeedbackMap)
3076 {
3077 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
3078 {
3079 return true;
3080 }
3081 }
3082 return false;
3083}
3084
Geoff Lang33f11fb2018-05-07 13:42:47 -04003085Extensions Context::generateSupportedExtensions() const
Geoff Langb0f917f2017-12-05 13:41:54 -05003086{
3087 Extensions supportedExtensions = mImplementation->getNativeExtensions();
3088
jchen1082af6202018-06-22 10:59:52 +08003089 // Explicitly enable GL_KHR_parallel_shader_compile
3090 supportedExtensions.parallelShaderCompile = true;
3091
Geoff Langb0f917f2017-12-05 13:41:54 -05003092 if (getClientVersion() < ES_2_0)
3093 {
3094 // Default extensions for GLES1
Lingfeng Yang0df813c2018-07-12 12:52:06 -07003095 supportedExtensions.pointSizeArray = true;
3096 supportedExtensions.textureCubeMap = true;
3097 supportedExtensions.pointSprite = true;
3098 supportedExtensions.drawTexture = true;
jchen1082af6202018-06-22 10:59:52 +08003099 supportedExtensions.parallelShaderCompile = false;
Geoff Langb0f917f2017-12-05 13:41:54 -05003100 }
3101
3102 if (getClientVersion() < ES_3_0)
3103 {
3104 // Disable ES3+ extensions
3105 supportedExtensions.colorBufferFloat = false;
3106 supportedExtensions.eglImageExternalEssl3 = false;
3107 supportedExtensions.textureNorm16 = false;
3108 supportedExtensions.multiview = false;
3109 supportedExtensions.maxViews = 1u;
3110 }
3111
3112 if (getClientVersion() < ES_3_1)
3113 {
3114 // Disable ES3.1+ extensions
3115 supportedExtensions.geometryShader = false;
3116 }
3117
3118 if (getClientVersion() > ES_2_0)
3119 {
3120 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
3121 // supportedExtensions.sRGB = false;
3122 }
3123
3124 // Some extensions are always available because they are implemented in the GL layer.
3125 supportedExtensions.bindUniformLocation = true;
3126 supportedExtensions.vertexArrayObject = true;
3127 supportedExtensions.bindGeneratesResource = true;
3128 supportedExtensions.clientArrays = true;
3129 supportedExtensions.requestExtension = true;
3130
3131 // Enable the no error extension if the context was created with the flag.
3132 supportedExtensions.noError = mSkipValidation;
3133
3134 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Geoff Lang33f11fb2018-05-07 13:42:47 -04003135 supportedExtensions.surfacelessContext = mSurfacelessSupported;
Geoff Langb0f917f2017-12-05 13:41:54 -05003136
3137 // Explicitly enable GL_KHR_debug
3138 supportedExtensions.debug = true;
3139 supportedExtensions.maxDebugMessageLength = 1024;
3140 supportedExtensions.maxDebugLoggedMessages = 1024;
3141 supportedExtensions.maxDebugGroupStackDepth = 1024;
3142 supportedExtensions.maxLabelLength = 1024;
3143
3144 // Explicitly enable GL_ANGLE_robust_client_memory
3145 supportedExtensions.robustClientMemory = true;
3146
3147 // Determine robust resource init availability from EGL.
Geoff Lang33f11fb2018-05-07 13:42:47 -04003148 supportedExtensions.robustResourceInitialization = mGLState.isRobustResourceInitEnabled();
Geoff Langb0f917f2017-12-05 13:41:54 -05003149
3150 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
3151 // supports it.
3152 supportedExtensions.robustBufferAccessBehavior =
3153 mRobustAccess && supportedExtensions.robustBufferAccessBehavior;
3154
3155 // Enable the cache control query unconditionally.
3156 supportedExtensions.programCacheControl = true;
3157
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003158 // Enable EGL_ANGLE_explicit_context subextensions
Geoff Lang33f11fb2018-05-07 13:42:47 -04003159 if (mExplicitContextAvailable)
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003160 {
3161 // GL_ANGLE_explicit_context_gles1
3162 supportedExtensions.explicitContextGles1 = true;
3163 // GL_ANGLE_explicit_context
3164 supportedExtensions.explicitContext = true;
3165 }
3166
Geoff Langb0f917f2017-12-05 13:41:54 -05003167 return supportedExtensions;
3168}
3169
Geoff Lang33f11fb2018-05-07 13:42:47 -04003170void Context::initCaps()
Geoff Lang493daf52014-07-03 13:38:44 -04003171{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04003172 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04003173
Geoff Lang33f11fb2018-05-07 13:42:47 -04003174 mSupportedExtensions = generateSupportedExtensions();
3175 mExtensions = mSupportedExtensions;
Lingfeng Yang01074432018-04-16 10:19:51 -07003176
3177 mLimitations = mImplementation->getNativeLimitations();
3178
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003179 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
3180 if (getClientVersion() < Version(2, 0))
3181 {
3182 mCaps.maxMultitextureUnits = 4;
3183 mCaps.maxClipPlanes = 6;
3184 mCaps.maxLights = 8;
Lingfeng Yange547aac2018-04-05 09:39:20 -07003185 mCaps.maxModelviewMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3186 mCaps.maxProjectionMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3187 mCaps.maxTextureMatrixStackDepth = Caps::GlobalMatrixStackDepth;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003188 mCaps.minSmoothPointSize = 1.0f;
3189 mCaps.maxSmoothPointSize = 1.0f;
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003190 }
3191
Luc Ferronad2ae932018-06-11 15:31:17 -04003192 // Apply/Verify implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04003193 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003194
Luc Ferronad2ae932018-06-11 15:31:17 -04003195 ASSERT(mCaps.minAliasedPointSize >= 1.0f);
3196
Jamie Madill0f80ed82017-09-19 00:24:56 -04003197 if (getClientVersion() < ES_3_1)
3198 {
3199 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
3200 }
3201 else
3202 {
3203 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
3204 }
Geoff Lang301d1612014-07-09 10:34:37 -04003205
Jiawei Shao54aafe52018-04-27 14:54:57 +08003206 LimitCap(&mCaps.maxShaderUniformBlocks[ShaderType::Vertex],
3207 IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
Jamie Madill0f80ed82017-09-19 00:24:56 -04003208 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3209 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3210
3211 // Limit textures as well, so we can use fast bitsets with texture bindings.
3212 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
Jiawei Shao54aafe52018-04-27 14:54:57 +08003213 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Vertex],
3214 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
3215 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Fragment],
3216 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04003217
Jiawei Shaodb342272017-09-27 10:21:45 +08003218 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
3219
Geoff Langc287ea62016-09-16 14:46:51 -04003220 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05003221 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04003222 for (const auto &extensionInfo : GetExtensionInfoMap())
3223 {
Geoff Lang0ab41fa2018-03-14 11:03:30 -04003224 // If the user has requested that extensions start disabled and they are requestable,
3225 // disable them.
3226 if (!mExtensionsEnabled && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04003227 {
3228 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
3229 }
3230 }
3231
3232 // Generate texture caps
3233 updateCaps();
3234}
3235
3236void Context::updateCaps()
3237{
Geoff Lang900013c2014-07-07 11:32:19 -04003238 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04003239 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04003240
Jamie Madill7b62cf92017-11-02 15:20:49 -04003241 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04003242 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04003243 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04003244 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003245
Geoff Lang0d8b7242015-09-09 14:56:53 -04003246 // Update the format caps based on the client version and extensions.
3247 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
3248 // ES3.
3249 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003250 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04003251 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003252 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Yuly Novikovf15f8862018-06-04 18:59:41 -04003253 formatCaps.textureAttachment =
3254 formatCaps.textureAttachment &&
3255 formatInfo.textureAttachmentSupport(getClientVersion(), mExtensions);
3256 formatCaps.renderbuffer = formatCaps.renderbuffer &&
3257 formatInfo.renderbufferSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04003258
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003259 // OpenGL ES does not support multisampling with non-rendererable formats
3260 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Yuly Novikovf15f8862018-06-04 18:59:41 -04003261 if (!formatCaps.renderbuffer ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003262 (getClientVersion() < ES_3_1 &&
3263 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04003264 {
Geoff Langd87878e2014-09-19 15:42:59 -04003265 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04003266 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03003267 else
3268 {
3269 // We may have limited the max samples for some required renderbuffer formats due to
3270 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
3271 GLuint formatMaxSamples = formatCaps.getMaxSamples();
3272
3273 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
3274 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
3275 // exception of signed and unsigned integer formats."
3276 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
3277 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
3278 {
3279 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
3280 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
3281 }
3282
3283 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
3284 if (getClientVersion() >= ES_3_1)
3285 {
3286 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
3287 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
3288 // the exception that the signed and unsigned integer formats are required only to
3289 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
3290 // multisamples, which must be at least one."
3291 if (formatInfo.componentType == GL_INT ||
3292 formatInfo.componentType == GL_UNSIGNED_INT)
3293 {
3294 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
3295 }
3296
3297 // GLES 3.1 section 19.3.1.
3298 if (formatCaps.texturable)
3299 {
3300 if (formatInfo.depthBits > 0)
3301 {
3302 mCaps.maxDepthTextureSamples =
3303 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
3304 }
3305 else if (formatInfo.redBits > 0)
3306 {
3307 mCaps.maxColorTextureSamples =
3308 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
3309 }
3310 }
3311 }
3312 }
Geoff Langd87878e2014-09-19 15:42:59 -04003313
3314 if (formatCaps.texturable && formatInfo.compressed)
3315 {
Geoff Langca271392017-04-05 12:30:00 -04003316 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003317 }
3318
Geoff Langca271392017-04-05 12:30:00 -04003319 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04003320 }
Jamie Madill32447362017-06-28 14:53:52 -04003321
3322 // If program binary is disabled, blank out the memory cache pointer.
Geoff Langb0f917f2017-12-05 13:41:54 -05003323 if (!mSupportedExtensions.getProgramBinary)
Jamie Madill32447362017-06-28 14:53:52 -04003324 {
3325 mMemoryProgramCache = nullptr;
3326 }
Corentin Walleze4477002017-12-01 14:39:58 -05003327
3328 // Compute which buffer types are allowed
3329 mValidBufferBindings.reset();
3330 mValidBufferBindings.set(BufferBinding::ElementArray);
3331 mValidBufferBindings.set(BufferBinding::Array);
3332
3333 if (mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
3334 {
3335 mValidBufferBindings.set(BufferBinding::PixelPack);
3336 mValidBufferBindings.set(BufferBinding::PixelUnpack);
3337 }
3338
3339 if (getClientVersion() >= ES_3_0)
3340 {
3341 mValidBufferBindings.set(BufferBinding::CopyRead);
3342 mValidBufferBindings.set(BufferBinding::CopyWrite);
3343 mValidBufferBindings.set(BufferBinding::TransformFeedback);
3344 mValidBufferBindings.set(BufferBinding::Uniform);
3345 }
3346
3347 if (getClientVersion() >= ES_3_1)
3348 {
3349 mValidBufferBindings.set(BufferBinding::AtomicCounter);
3350 mValidBufferBindings.set(BufferBinding::ShaderStorage);
3351 mValidBufferBindings.set(BufferBinding::DrawIndirect);
3352 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
3353 }
Geoff Lang493daf52014-07-03 13:38:44 -04003354}
3355
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003356void Context::initWorkarounds()
3357{
Jamie Madill761b02c2017-06-23 16:27:06 -04003358 // Apply back-end workarounds.
3359 mImplementation->applyNativeWorkarounds(&mWorkarounds);
3360
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003361 // Lose the context upon out of memory error if the application is
3362 // expecting to watch for those events.
3363 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
3364}
3365
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06003366// Return true if the draw is a no-op, else return false.
3367// A no-op draw occurs if the count of vertices is less than the minimum required to
3368// have a valid primitive for this mode (0 for points, 0-1 for lines, 0-2 for tris).
3369bool Context::noopDraw(PrimitiveMode mode, GLsizei count)
3370{
3371 return count < kMinimumPrimitiveCounts[mode];
3372}
3373
3374bool Context::noopDrawInstanced(PrimitiveMode mode, GLsizei count, GLsizei instanceCount)
3375{
3376 return (instanceCount == 0) || noopDraw(mode, count);
3377}
3378
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003379Error Context::prepareForDraw(PrimitiveMode mode)
Jamie Madill05b35b22017-10-03 09:01:44 -04003380{
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003381 if (mGLES1Renderer)
3382 {
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003383 ANGLE_TRY(mGLES1Renderer->prepareForDraw(mode, this, &mGLState));
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003384 }
3385
Geoff Lang9bf86f02018-07-26 11:46:34 -04003386 ANGLE_TRY(syncDirtyObjects(mDrawDirtyObjects));
Jamie Madilla59fc192017-11-02 12:57:58 -04003387
3388 if (isRobustResourceInitEnabled())
3389 {
3390 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
3391 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
3392 }
3393
Geoff Langa8cb2872018-03-09 16:09:40 -05003394 ANGLE_TRY(syncDirtyBits());
Geoff Langd4fff502017-09-22 11:28:28 -04003395 return NoError();
3396}
3397
3398Error Context::prepareForClear(GLbitfield mask)
3399{
Geoff Langa8cb2872018-03-09 16:09:40 -05003400 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003401 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearAttachmentsInitialized(this, mask));
Geoff Langa8cb2872018-03-09 16:09:40 -05003402 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04003403 return NoError();
3404}
3405
3406Error Context::prepareForClearBuffer(GLenum buffer, GLint drawbuffer)
3407{
Geoff Langa8cb2872018-03-09 16:09:40 -05003408 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003409 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearBufferAttachmentsInitialized(this, buffer,
3410 drawbuffer));
Geoff Langa8cb2872018-03-09 16:09:40 -05003411 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill05b35b22017-10-03 09:01:44 -04003412 return NoError();
3413}
3414
Geoff Langa8cb2872018-03-09 16:09:40 -05003415Error Context::syncState(const State::DirtyBits &bitMask, const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04003416{
Geoff Langa8cb2872018-03-09 16:09:40 -05003417 ANGLE_TRY(syncDirtyObjects(objectMask));
3418 ANGLE_TRY(syncDirtyBits(bitMask));
Geoff Langd4fff502017-09-22 11:28:28 -04003419 return NoError();
3420}
3421
Geoff Langa8cb2872018-03-09 16:09:40 -05003422Error Context::syncDirtyBits()
Geoff Langd4fff502017-09-22 11:28:28 -04003423{
3424 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
Jamie Madill189ad872018-07-09 13:32:37 -04003425 ANGLE_TRY(mImplementation->syncState(this, dirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04003426 mGLState.clearDirtyBits();
3427 return NoError();
3428}
3429
Geoff Langa8cb2872018-03-09 16:09:40 -05003430Error Context::syncDirtyBits(const State::DirtyBits &bitMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003431{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003432 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madill189ad872018-07-09 13:32:37 -04003433 ANGLE_TRY(mImplementation->syncState(this, dirtyBits));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003434 mGLState.clearDirtyBits(dirtyBits);
Jamie Madillbc918e72018-03-08 09:47:21 -05003435 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003436}
Jamie Madillc29968b2016-01-20 11:17:23 -05003437
Geoff Langa8cb2872018-03-09 16:09:40 -05003438Error Context::syncDirtyObjects(const State::DirtyObjects &objectMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003439{
3440 return mGLState.syncDirtyObjects(this, objectMask);
3441}
3442
Jamie Madillc29968b2016-01-20 11:17:23 -05003443void Context::blitFramebuffer(GLint srcX0,
3444 GLint srcY0,
3445 GLint srcX1,
3446 GLint srcY1,
3447 GLint dstX0,
3448 GLint dstY0,
3449 GLint dstX1,
3450 GLint dstY1,
3451 GLbitfield mask,
3452 GLenum filter)
3453{
Qin Jiajiaaef92162018-02-27 13:51:44 +08003454 if (mask == 0)
3455 {
3456 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
3457 // buffers are copied.
3458 return;
3459 }
3460
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003461 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003462 ASSERT(drawFramebuffer);
3463
3464 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
3465 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
3466
Jamie Madillbc918e72018-03-08 09:47:21 -05003467 ANGLE_CONTEXT_TRY(syncStateForBlit());
Jamie Madillc29968b2016-01-20 11:17:23 -05003468
Jamie Madillc564c072017-06-01 12:45:42 -04003469 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003470}
Jamie Madillc29968b2016-01-20 11:17:23 -05003471
3472void Context::clear(GLbitfield mask)
3473{
Geoff Langd4fff502017-09-22 11:28:28 -04003474 ANGLE_CONTEXT_TRY(prepareForClear(mask));
3475 ANGLE_CONTEXT_TRY(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05003476}
3477
3478void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
3479{
Geoff Langd4fff502017-09-22 11:28:28 -04003480 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3481 ANGLE_CONTEXT_TRY(
3482 mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003483}
3484
3485void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3486{
Geoff Langd4fff502017-09-22 11:28:28 -04003487 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3488 ANGLE_CONTEXT_TRY(
3489 mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003490}
3491
3492void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3493{
Geoff Langd4fff502017-09-22 11:28:28 -04003494 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3495 ANGLE_CONTEXT_TRY(
3496 mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003497}
3498
3499void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3500{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003501 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003502 ASSERT(framebufferObject);
3503
3504 // If a buffer is not present, the clear has no effect
3505 if (framebufferObject->getDepthbuffer() == nullptr &&
3506 framebufferObject->getStencilbuffer() == nullptr)
3507 {
3508 return;
3509 }
3510
Geoff Langd4fff502017-09-22 11:28:28 -04003511 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3512 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003513}
3514
3515void Context::readPixels(GLint x,
3516 GLint y,
3517 GLsizei width,
3518 GLsizei height,
3519 GLenum format,
3520 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003521 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003522{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003523 if (width == 0 || height == 0)
3524 {
3525 return;
3526 }
3527
Jamie Madillbc918e72018-03-08 09:47:21 -05003528 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003529
Jamie Madillb6664922017-07-25 12:55:04 -04003530 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3531 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003532
3533 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04003534 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003535}
3536
Brandon Jones59770802018-04-02 13:18:42 -07003537void Context::readPixelsRobust(GLint x,
3538 GLint y,
3539 GLsizei width,
3540 GLsizei height,
3541 GLenum format,
3542 GLenum type,
3543 GLsizei bufSize,
3544 GLsizei *length,
3545 GLsizei *columns,
3546 GLsizei *rows,
3547 void *pixels)
3548{
3549 readPixels(x, y, width, height, format, type, pixels);
3550}
3551
3552void Context::readnPixelsRobust(GLint x,
3553 GLint y,
3554 GLsizei width,
3555 GLsizei height,
3556 GLenum format,
3557 GLenum type,
3558 GLsizei bufSize,
3559 GLsizei *length,
3560 GLsizei *columns,
3561 GLsizei *rows,
3562 void *data)
3563{
3564 readPixels(x, y, width, height, format, type, data);
3565}
3566
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003567void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003568 GLint level,
3569 GLenum internalformat,
3570 GLint x,
3571 GLint y,
3572 GLsizei width,
3573 GLsizei height,
3574 GLint border)
3575{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003576 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003577 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003578
Jamie Madillc29968b2016-01-20 11:17:23 -05003579 Rectangle sourceArea(x, y, width, height);
3580
Jamie Madill05b35b22017-10-03 09:01:44 -04003581 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003582 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003583 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003584}
3585
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003586void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003587 GLint level,
3588 GLint xoffset,
3589 GLint yoffset,
3590 GLint x,
3591 GLint y,
3592 GLsizei width,
3593 GLsizei height)
3594{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003595 if (width == 0 || height == 0)
3596 {
3597 return;
3598 }
3599
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003600 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003601 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003602
Jamie Madillc29968b2016-01-20 11:17:23 -05003603 Offset destOffset(xoffset, yoffset, 0);
3604 Rectangle sourceArea(x, y, width, height);
3605
Jamie Madill05b35b22017-10-03 09:01:44 -04003606 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003607 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003608 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003609}
3610
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003611void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003612 GLint level,
3613 GLint xoffset,
3614 GLint yoffset,
3615 GLint zoffset,
3616 GLint x,
3617 GLint y,
3618 GLsizei width,
3619 GLsizei height)
3620{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003621 if (width == 0 || height == 0)
3622 {
3623 return;
3624 }
3625
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003626 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003627 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003628
Jamie Madillc29968b2016-01-20 11:17:23 -05003629 Offset destOffset(xoffset, yoffset, zoffset);
3630 Rectangle sourceArea(x, y, width, height);
3631
Jamie Madill05b35b22017-10-03 09:01:44 -04003632 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3633 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003634 handleError(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level, destOffset,
3635 sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003636}
3637
3638void Context::framebufferTexture2D(GLenum target,
3639 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003640 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003641 GLuint texture,
3642 GLint level)
3643{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003644 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003645 ASSERT(framebuffer);
3646
3647 if (texture != 0)
3648 {
3649 Texture *textureObj = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003650 ImageIndex index = ImageIndex::MakeFromTarget(textarget, level);
Jamie Madilla02315b2017-02-23 14:14:47 -05003651 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003652 }
3653 else
3654 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003655 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003656 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003657
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003658 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003659}
3660
3661void Context::framebufferRenderbuffer(GLenum target,
3662 GLenum attachment,
3663 GLenum renderbuffertarget,
3664 GLuint renderbuffer)
3665{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003666 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003667 ASSERT(framebuffer);
3668
3669 if (renderbuffer != 0)
3670 {
3671 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003672
Jamie Madillcc129372018-04-12 09:13:18 -04003673 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003674 renderbufferObject);
3675 }
3676 else
3677 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003678 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003679 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003680
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003681 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003682}
3683
3684void Context::framebufferTextureLayer(GLenum target,
3685 GLenum attachment,
3686 GLuint texture,
3687 GLint level,
3688 GLint layer)
3689{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003690 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003691 ASSERT(framebuffer);
3692
3693 if (texture != 0)
3694 {
3695 Texture *textureObject = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003696 ImageIndex index = ImageIndex::MakeFromType(textureObject->getType(), level, layer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003697 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003698 }
3699 else
3700 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003701 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003702 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003703
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003704 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003705}
3706
Brandon Jones59770802018-04-02 13:18:42 -07003707void Context::framebufferTextureMultiviewLayered(GLenum target,
3708 GLenum attachment,
3709 GLuint texture,
3710 GLint level,
3711 GLint baseViewIndex,
3712 GLsizei numViews)
Martin Radev137032d2017-07-13 10:11:12 +03003713{
Martin Radev82ef7742017-08-08 17:44:58 +03003714 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3715 ASSERT(framebuffer);
3716
3717 if (texture != 0)
3718 {
3719 Texture *textureObj = getTexture(texture);
3720
Martin Radev18b75ba2017-08-15 15:50:40 +03003721 ImageIndex index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
Martin Radev82ef7742017-08-08 17:44:58 +03003722 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3723 numViews, baseViewIndex);
3724 }
3725 else
3726 {
3727 framebuffer->resetAttachment(this, attachment);
3728 }
3729
3730 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003731}
3732
Brandon Jones59770802018-04-02 13:18:42 -07003733void Context::framebufferTextureMultiviewSideBySide(GLenum target,
3734 GLenum attachment,
3735 GLuint texture,
3736 GLint level,
3737 GLsizei numViews,
3738 const GLint *viewportOffsets)
Martin Radev137032d2017-07-13 10:11:12 +03003739{
Martin Radev5dae57b2017-07-14 16:15:55 +03003740 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3741 ASSERT(framebuffer);
3742
3743 if (texture != 0)
3744 {
3745 Texture *textureObj = getTexture(texture);
3746
3747 ImageIndex index = ImageIndex::Make2D(level);
3748 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3749 textureObj, numViews, viewportOffsets);
3750 }
3751 else
3752 {
3753 framebuffer->resetAttachment(this, attachment);
3754 }
3755
3756 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003757}
3758
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003759void Context::framebufferTexture(GLenum target, GLenum attachment, GLuint texture, GLint level)
3760{
Jiawei Shaoa8802472018-05-28 11:17:47 +08003761 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3762 ASSERT(framebuffer);
3763
3764 if (texture != 0)
3765 {
3766 Texture *textureObj = getTexture(texture);
3767
3768 ImageIndex index = ImageIndex::MakeFromType(
3769 textureObj->getType(), level, ImageIndex::kEntireLevel, ImageIndex::kEntireLevel);
3770 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
3771 }
3772 else
3773 {
3774 framebuffer->resetAttachment(this, attachment);
3775 }
3776
3777 mGLState.setObjectDirty(target);
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003778}
3779
Jamie Madillc29968b2016-01-20 11:17:23 -05003780void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3781{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003782 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003783 ASSERT(framebuffer);
3784 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003785 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003786}
3787
3788void Context::readBuffer(GLenum mode)
3789{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003790 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003791 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003792 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003793}
3794
3795void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3796{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003797 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003798 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003799
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003800 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003801 ASSERT(framebuffer);
3802
3803 // The specification isn't clear what should be done when the framebuffer isn't complete.
3804 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003805 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003806}
3807
3808void Context::invalidateFramebuffer(GLenum target,
3809 GLsizei numAttachments,
3810 const GLenum *attachments)
3811{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003812 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003813 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003814
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003815 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003816 ASSERT(framebuffer);
3817
Jamie Madill427064d2018-04-13 16:20:34 -04003818 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003819 {
Jamie Madill437fa652016-05-03 15:13:24 -04003820 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003821 }
Jamie Madill437fa652016-05-03 15:13:24 -04003822
Jamie Madill4928b7c2017-06-20 12:57:39 -04003823 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003824}
3825
3826void Context::invalidateSubFramebuffer(GLenum target,
3827 GLsizei numAttachments,
3828 const GLenum *attachments,
3829 GLint x,
3830 GLint y,
3831 GLsizei width,
3832 GLsizei height)
3833{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003834 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003835 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003836
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003837 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003838 ASSERT(framebuffer);
3839
Jamie Madill427064d2018-04-13 16:20:34 -04003840 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003841 {
Jamie Madill437fa652016-05-03 15:13:24 -04003842 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003843 }
Jamie Madill437fa652016-05-03 15:13:24 -04003844
3845 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003846 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003847}
3848
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003849void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003850 GLint level,
3851 GLint internalformat,
3852 GLsizei width,
3853 GLsizei height,
3854 GLint border,
3855 GLenum format,
3856 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003857 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003858{
Jamie Madillbc918e72018-03-08 09:47:21 -05003859 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003860
3861 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003862 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003863 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003864 size, format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003865}
3866
Brandon Jones59770802018-04-02 13:18:42 -07003867void Context::texImage2DRobust(TextureTarget target,
3868 GLint level,
3869 GLint internalformat,
3870 GLsizei width,
3871 GLsizei height,
3872 GLint border,
3873 GLenum format,
3874 GLenum type,
3875 GLsizei bufSize,
3876 const void *pixels)
3877{
3878 texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
3879}
3880
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003881void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003882 GLint level,
3883 GLint internalformat,
3884 GLsizei width,
3885 GLsizei height,
3886 GLsizei depth,
3887 GLint border,
3888 GLenum format,
3889 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003890 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003891{
Jamie Madillbc918e72018-03-08 09:47:21 -05003892 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003893
3894 Extents size(width, height, depth);
3895 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003896 handleError(texture->setImage(this, mGLState.getUnpackState(),
3897 NonCubeTextureTypeToTarget(target), level, internalformat, size,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003898 format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003899}
3900
Brandon Jones59770802018-04-02 13:18:42 -07003901void Context::texImage3DRobust(TextureType target,
3902 GLint level,
3903 GLint internalformat,
3904 GLsizei width,
3905 GLsizei height,
3906 GLsizei depth,
3907 GLint border,
3908 GLenum format,
3909 GLenum type,
3910 GLsizei bufSize,
3911 const void *pixels)
3912{
3913 texImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels);
3914}
3915
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003916void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003917 GLint level,
3918 GLint xoffset,
3919 GLint yoffset,
3920 GLsizei width,
3921 GLsizei height,
3922 GLenum format,
3923 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003924 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003925{
3926 // Zero sized uploads are valid but no-ops
3927 if (width == 0 || height == 0)
3928 {
3929 return;
3930 }
3931
Jamie Madillbc918e72018-03-08 09:47:21 -05003932 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003933
3934 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003935 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003936 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003937 type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003938}
3939
Brandon Jones59770802018-04-02 13:18:42 -07003940void Context::texSubImage2DRobust(TextureTarget target,
3941 GLint level,
3942 GLint xoffset,
3943 GLint yoffset,
3944 GLsizei width,
3945 GLsizei height,
3946 GLenum format,
3947 GLenum type,
3948 GLsizei bufSize,
3949 const void *pixels)
3950{
3951 texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
3952}
3953
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003954void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003955 GLint level,
3956 GLint xoffset,
3957 GLint yoffset,
3958 GLint zoffset,
3959 GLsizei width,
3960 GLsizei height,
3961 GLsizei depth,
3962 GLenum format,
3963 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003964 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003965{
3966 // Zero sized uploads are valid but no-ops
3967 if (width == 0 || height == 0 || depth == 0)
3968 {
3969 return;
3970 }
3971
Jamie Madillbc918e72018-03-08 09:47:21 -05003972 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003973
3974 Box area(xoffset, yoffset, zoffset, width, height, depth);
3975 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003976 handleError(texture->setSubImage(this, mGLState.getUnpackState(),
3977 NonCubeTextureTypeToTarget(target), level, area, format, type,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003978 static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003979}
3980
Brandon Jones59770802018-04-02 13:18:42 -07003981void Context::texSubImage3DRobust(TextureType target,
3982 GLint level,
3983 GLint xoffset,
3984 GLint yoffset,
3985 GLint zoffset,
3986 GLsizei width,
3987 GLsizei height,
3988 GLsizei depth,
3989 GLenum format,
3990 GLenum type,
3991 GLsizei bufSize,
3992 const void *pixels)
3993{
3994 texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type,
3995 pixels);
3996}
3997
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003998void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003999 GLint level,
4000 GLenum internalformat,
4001 GLsizei width,
4002 GLsizei height,
4003 GLint border,
4004 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004005 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004006{
Jamie Madillbc918e72018-03-08 09:47:21 -05004007 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004008
4009 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004010 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05004011 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
4012 internalformat, size, imageSize,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004013 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004014}
4015
Brandon Jones59770802018-04-02 13:18:42 -07004016void Context::compressedTexImage2DRobust(TextureTarget target,
4017 GLint level,
4018 GLenum internalformat,
4019 GLsizei width,
4020 GLsizei height,
4021 GLint border,
4022 GLsizei imageSize,
4023 GLsizei dataSize,
4024 const GLvoid *data)
4025{
4026 compressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
4027}
4028
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004029void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004030 GLint level,
4031 GLenum internalformat,
4032 GLsizei width,
4033 GLsizei height,
4034 GLsizei depth,
4035 GLint border,
4036 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004037 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004038{
Jamie Madillbc918e72018-03-08 09:47:21 -05004039 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004040
4041 Extents size(width, height, depth);
4042 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004043 handleError(texture->setCompressedImage(
4044 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004045 size, imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004046}
4047
Brandon Jones59770802018-04-02 13:18:42 -07004048void Context::compressedTexImage3DRobust(TextureType target,
4049 GLint level,
4050 GLenum internalformat,
4051 GLsizei width,
4052 GLsizei height,
4053 GLsizei depth,
4054 GLint border,
4055 GLsizei imageSize,
4056 GLsizei dataSize,
4057 const GLvoid *data)
4058{
4059 compressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize,
4060 data);
4061}
4062
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004063void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004064 GLint level,
4065 GLint xoffset,
4066 GLint yoffset,
4067 GLsizei width,
4068 GLsizei height,
4069 GLenum format,
4070 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004071 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004072{
Jamie Madillbc918e72018-03-08 09:47:21 -05004073 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004074
4075 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004076 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05004077 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
4078 format, imageSize,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004079 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004080}
4081
Brandon Jones59770802018-04-02 13:18:42 -07004082void Context::compressedTexSubImage2DRobust(TextureTarget target,
4083 GLint level,
4084 GLint xoffset,
4085 GLint yoffset,
4086 GLsizei width,
4087 GLsizei height,
4088 GLenum format,
4089 GLsizei imageSize,
4090 GLsizei dataSize,
4091 const GLvoid *data)
4092{
4093 compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize,
4094 data);
4095}
4096
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004097void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004098 GLint level,
4099 GLint xoffset,
4100 GLint yoffset,
4101 GLint zoffset,
4102 GLsizei width,
4103 GLsizei height,
4104 GLsizei depth,
4105 GLenum format,
4106 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004107 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004108{
4109 // Zero sized uploads are valid but no-ops
4110 if (width == 0 || height == 0)
4111 {
4112 return;
4113 }
4114
Jamie Madillbc918e72018-03-08 09:47:21 -05004115 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004116
4117 Box area(xoffset, yoffset, zoffset, width, height, depth);
4118 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004119 handleError(texture->setCompressedSubImage(
4120 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004121 imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004122}
4123
Brandon Jones59770802018-04-02 13:18:42 -07004124void Context::compressedTexSubImage3DRobust(TextureType target,
4125 GLint level,
4126 GLint xoffset,
4127 GLint yoffset,
4128 GLint zoffset,
4129 GLsizei width,
4130 GLsizei height,
4131 GLsizei depth,
4132 GLenum format,
4133 GLsizei imageSize,
4134 GLsizei dataSize,
4135 const GLvoid *data)
4136{
4137 compressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format,
4138 imageSize, data);
4139}
4140
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004141void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004142{
4143 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05004144 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004145}
4146
Jamie Madill007530e2017-12-28 14:27:04 -05004147void Context::copyTexture(GLuint sourceId,
4148 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004149 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004150 GLuint destId,
4151 GLint destLevel,
4152 GLint internalFormat,
4153 GLenum destType,
4154 GLboolean unpackFlipY,
4155 GLboolean unpackPremultiplyAlpha,
4156 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004157{
Jamie Madillbc918e72018-03-08 09:47:21 -05004158 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004159
4160 gl::Texture *sourceTexture = getTexture(sourceId);
4161 gl::Texture *destTexture = getTexture(destId);
Geoff Lang92019432017-11-20 13:09:34 -05004162 handleError(destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType,
4163 sourceLevel, ConvertToBool(unpackFlipY),
4164 ConvertToBool(unpackPremultiplyAlpha),
4165 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004166}
4167
Jamie Madill007530e2017-12-28 14:27:04 -05004168void Context::copySubTexture(GLuint sourceId,
4169 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004170 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004171 GLuint destId,
4172 GLint destLevel,
4173 GLint xoffset,
4174 GLint yoffset,
4175 GLint x,
4176 GLint y,
4177 GLsizei width,
4178 GLsizei height,
4179 GLboolean unpackFlipY,
4180 GLboolean unpackPremultiplyAlpha,
4181 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004182{
4183 // Zero sized copies are valid but no-ops
4184 if (width == 0 || height == 0)
4185 {
4186 return;
4187 }
4188
Jamie Madillbc918e72018-03-08 09:47:21 -05004189 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004190
4191 gl::Texture *sourceTexture = getTexture(sourceId);
4192 gl::Texture *destTexture = getTexture(destId);
4193 Offset offset(xoffset, yoffset, 0);
4194 Rectangle area(x, y, width, height);
Geoff Lang92019432017-11-20 13:09:34 -05004195 handleError(destTexture->copySubTexture(this, destTarget, destLevel, offset, sourceLevel, area,
4196 ConvertToBool(unpackFlipY),
4197 ConvertToBool(unpackPremultiplyAlpha),
4198 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004199}
4200
Jamie Madill007530e2017-12-28 14:27:04 -05004201void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07004202{
Jamie Madillbc918e72018-03-08 09:47:21 -05004203 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07004204
4205 gl::Texture *sourceTexture = getTexture(sourceId);
4206 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05004207 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07004208}
4209
Corentin Wallez336129f2017-10-17 15:55:40 -04004210void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03004211{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004212 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004213 ASSERT(buffer);
4214
Geoff Lang496c02d2016-10-20 11:38:11 -07004215 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03004216}
4217
Brandon Jones59770802018-04-02 13:18:42 -07004218void Context::getBufferPointervRobust(BufferBinding target,
4219 GLenum pname,
4220 GLsizei bufSize,
4221 GLsizei *length,
4222 void **params)
4223{
4224 getBufferPointerv(target, pname, params);
4225}
4226
Corentin Wallez336129f2017-10-17 15:55:40 -04004227void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004228{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004229 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004230 ASSERT(buffer);
4231
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004232 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004233 if (error.isError())
4234 {
Jamie Madill437fa652016-05-03 15:13:24 -04004235 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004236 return nullptr;
4237 }
4238
4239 return buffer->getMapPointer();
4240}
4241
Corentin Wallez336129f2017-10-17 15:55:40 -04004242GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03004243{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004244 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004245 ASSERT(buffer);
4246
4247 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004248 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03004249 if (error.isError())
4250 {
Jamie Madill437fa652016-05-03 15:13:24 -04004251 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004252 return GL_FALSE;
4253 }
4254
4255 return result;
4256}
4257
Corentin Wallez336129f2017-10-17 15:55:40 -04004258void *Context::mapBufferRange(BufferBinding target,
4259 GLintptr offset,
4260 GLsizeiptr length,
4261 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004262{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004263 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004264 ASSERT(buffer);
4265
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004266 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004267 if (error.isError())
4268 {
Jamie Madill437fa652016-05-03 15:13:24 -04004269 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004270 return nullptr;
4271 }
4272
4273 return buffer->getMapPointer();
4274}
4275
Corentin Wallez336129f2017-10-17 15:55:40 -04004276void Context::flushMappedBufferRange(BufferBinding /*target*/,
4277 GLintptr /*offset*/,
4278 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03004279{
4280 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
4281}
4282
Jamie Madillbc918e72018-03-08 09:47:21 -05004283Error Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004284{
Geoff Langa8cb2872018-03-09 16:09:40 -05004285 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004286}
4287
Jamie Madillbc918e72018-03-08 09:47:21 -05004288Error Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004289{
Geoff Langa8cb2872018-03-09 16:09:40 -05004290 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004291}
4292
Jamie Madillbc918e72018-03-08 09:47:21 -05004293Error Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004294{
Geoff Langa8cb2872018-03-09 16:09:40 -05004295 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004296}
4297
Geoff Lang9bf86f02018-07-26 11:46:34 -04004298Error Context::syncStateForPathOperation()
4299{
4300 ANGLE_TRY(syncDirtyObjects(mPathOperationDirtyObjects));
4301
4302 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
4303 ANGLE_TRY(syncDirtyBits());
4304
4305 return NoError();
4306}
4307
Jiajia Qin5451d532017-11-16 17:16:34 +08004308void Context::activeShaderProgram(GLuint pipeline, GLuint program)
4309{
4310 UNIMPLEMENTED();
4311}
4312
Jamie Madillc20ab272016-06-09 07:20:46 -07004313void Context::activeTexture(GLenum texture)
4314{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004315 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004316}
4317
Jamie Madill876429b2017-04-20 15:46:24 -04004318void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004319{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004320 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004321}
4322
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004323void Context::blendEquation(GLenum mode)
4324{
4325 mGLState.setBlendEquation(mode, mode);
4326}
4327
Jamie Madillc20ab272016-06-09 07:20:46 -07004328void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
4329{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004330 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004331}
4332
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004333void Context::blendFunc(GLenum sfactor, GLenum dfactor)
4334{
4335 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
4336}
4337
Jamie Madillc20ab272016-06-09 07:20:46 -07004338void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
4339{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004340 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004341}
4342
Jamie Madill876429b2017-04-20 15:46:24 -04004343void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004344{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004345 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004346}
4347
Jamie Madill876429b2017-04-20 15:46:24 -04004348void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07004349{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004350 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07004351}
4352
4353void Context::clearStencil(GLint s)
4354{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004355 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07004356}
4357
4358void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
4359{
Geoff Lang92019432017-11-20 13:09:34 -05004360 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
4361 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004362}
4363
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004364void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07004365{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004366 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004367}
4368
4369void Context::depthFunc(GLenum func)
4370{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004371 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07004372}
4373
4374void Context::depthMask(GLboolean flag)
4375{
Geoff Lang92019432017-11-20 13:09:34 -05004376 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07004377}
4378
Jamie Madill876429b2017-04-20 15:46:24 -04004379void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07004380{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004381 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07004382}
4383
4384void Context::disable(GLenum cap)
4385{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004386 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07004387}
4388
4389void Context::disableVertexAttribArray(GLuint index)
4390{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004391 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07004392}
4393
4394void Context::enable(GLenum cap)
4395{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004396 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07004397}
4398
4399void Context::enableVertexAttribArray(GLuint index)
4400{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004401 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07004402}
4403
4404void Context::frontFace(GLenum mode)
4405{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004406 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004407}
4408
4409void Context::hint(GLenum target, GLenum mode)
4410{
4411 switch (target)
4412 {
4413 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004414 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004415 break;
4416
4417 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004418 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004419 break;
4420
4421 default:
4422 UNREACHABLE();
4423 return;
4424 }
4425}
4426
4427void Context::lineWidth(GLfloat width)
4428{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004429 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07004430}
4431
4432void Context::pixelStorei(GLenum pname, GLint param)
4433{
4434 switch (pname)
4435 {
4436 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004437 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004438 break;
4439
4440 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004441 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004442 break;
4443
4444 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004445 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004446 break;
4447
4448 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004449 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004450 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004451 break;
4452
4453 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03004454 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004455 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004456 break;
4457
4458 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03004459 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004460 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004461 break;
4462
4463 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004464 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004465 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004466 break;
4467
4468 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004469 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004470 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004471 break;
4472
4473 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004474 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004475 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004476 break;
4477
4478 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004479 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004480 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004481 break;
4482
4483 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004484 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004485 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004486 break;
4487
4488 default:
4489 UNREACHABLE();
4490 return;
4491 }
4492}
4493
4494void Context::polygonOffset(GLfloat factor, GLfloat units)
4495{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004496 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07004497}
4498
Jamie Madill876429b2017-04-20 15:46:24 -04004499void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07004500{
Geoff Lang92019432017-11-20 13:09:34 -05004501 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07004502}
4503
Jiawei Shaodb342272017-09-27 10:21:45 +08004504void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
4505{
4506 mGLState.setSampleMaskParams(maskNumber, mask);
4507}
4508
Jamie Madillc20ab272016-06-09 07:20:46 -07004509void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
4510{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004511 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004512}
4513
4514void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
4515{
4516 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4517 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004518 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004519 }
4520
4521 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4522 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004523 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004524 }
4525}
4526
4527void Context::stencilMaskSeparate(GLenum face, GLuint mask)
4528{
4529 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4530 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004531 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004532 }
4533
4534 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4535 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004536 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004537 }
4538}
4539
4540void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4541{
4542 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4543 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004544 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004545 }
4546
4547 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4548 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004549 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004550 }
4551}
4552
4553void Context::vertexAttrib1f(GLuint index, GLfloat x)
4554{
4555 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004556 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004557}
4558
4559void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
4560{
4561 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004562 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004563}
4564
4565void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4566{
4567 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004568 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004569}
4570
4571void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
4572{
4573 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004574 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004575}
4576
4577void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4578{
4579 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004580 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004581}
4582
4583void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
4584{
4585 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004586 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004587}
4588
4589void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4590{
4591 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004592 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004593}
4594
4595void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
4596{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004597 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07004598}
4599
4600void Context::vertexAttribPointer(GLuint index,
4601 GLint size,
4602 GLenum type,
4603 GLboolean normalized,
4604 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004605 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07004606{
Corentin Wallez336129f2017-10-17 15:55:40 -04004607 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05004608 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc20ab272016-06-09 07:20:46 -07004609}
4610
Shao80957d92017-02-20 21:25:59 +08004611void Context::vertexAttribFormat(GLuint attribIndex,
4612 GLint size,
4613 GLenum type,
4614 GLboolean normalized,
4615 GLuint relativeOffset)
4616{
Geoff Lang92019432017-11-20 13:09:34 -05004617 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08004618 relativeOffset);
4619}
4620
4621void Context::vertexAttribIFormat(GLuint attribIndex,
4622 GLint size,
4623 GLenum type,
4624 GLuint relativeOffset)
4625{
4626 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
4627}
4628
4629void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4630{
Shaodde78e82017-05-22 14:13:27 +08004631 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Shao80957d92017-02-20 21:25:59 +08004632}
4633
Jiajia Qin5451d532017-11-16 17:16:34 +08004634void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004635{
4636 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
4637}
4638
Jamie Madillc20ab272016-06-09 07:20:46 -07004639void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4640{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004641 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004642}
4643
4644void Context::vertexAttribIPointer(GLuint index,
4645 GLint size,
4646 GLenum type,
4647 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004648 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004649{
Corentin Wallez336129f2017-10-17 15:55:40 -04004650 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
4651 size, type, false, true, stride, pointer);
Jamie Madillc20ab272016-06-09 07:20:46 -07004652}
4653
4654void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4655{
4656 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004657 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004658}
4659
4660void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4661{
4662 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004663 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004664}
4665
4666void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4667{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004668 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004669}
4670
4671void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4672{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004673 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004674}
4675
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004676void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4677{
4678 const VertexAttribCurrentValueData &currentValues =
4679 getGLState().getVertexAttribCurrentValue(index);
4680 const VertexArray *vao = getGLState().getVertexArray();
4681 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4682 currentValues, pname, params);
4683}
4684
Brandon Jones59770802018-04-02 13:18:42 -07004685void Context::getVertexAttribivRobust(GLuint index,
4686 GLenum pname,
4687 GLsizei bufSize,
4688 GLsizei *length,
4689 GLint *params)
4690{
4691 getVertexAttribiv(index, pname, params);
4692}
4693
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004694void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4695{
4696 const VertexAttribCurrentValueData &currentValues =
4697 getGLState().getVertexAttribCurrentValue(index);
4698 const VertexArray *vao = getGLState().getVertexArray();
4699 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4700 currentValues, pname, params);
4701}
4702
Brandon Jones59770802018-04-02 13:18:42 -07004703void Context::getVertexAttribfvRobust(GLuint index,
4704 GLenum pname,
4705 GLsizei bufSize,
4706 GLsizei *length,
4707 GLfloat *params)
4708{
4709 getVertexAttribfv(index, pname, params);
4710}
4711
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004712void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4713{
4714 const VertexAttribCurrentValueData &currentValues =
4715 getGLState().getVertexAttribCurrentValue(index);
4716 const VertexArray *vao = getGLState().getVertexArray();
4717 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4718 currentValues, pname, params);
4719}
4720
Brandon Jones59770802018-04-02 13:18:42 -07004721void Context::getVertexAttribIivRobust(GLuint index,
4722 GLenum pname,
4723 GLsizei bufSize,
4724 GLsizei *length,
4725 GLint *params)
4726{
4727 getVertexAttribIiv(index, pname, params);
4728}
4729
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004730void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4731{
4732 const VertexAttribCurrentValueData &currentValues =
4733 getGLState().getVertexAttribCurrentValue(index);
4734 const VertexArray *vao = getGLState().getVertexArray();
4735 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4736 currentValues, pname, params);
4737}
4738
Brandon Jones59770802018-04-02 13:18:42 -07004739void Context::getVertexAttribIuivRobust(GLuint index,
4740 GLenum pname,
4741 GLsizei bufSize,
4742 GLsizei *length,
4743 GLuint *params)
4744{
4745 getVertexAttribIuiv(index, pname, params);
4746}
4747
Jamie Madill876429b2017-04-20 15:46:24 -04004748void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004749{
4750 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
4751 QueryVertexAttribPointerv(attrib, pname, pointer);
4752}
4753
Brandon Jones59770802018-04-02 13:18:42 -07004754void Context::getVertexAttribPointervRobust(GLuint index,
4755 GLenum pname,
4756 GLsizei bufSize,
4757 GLsizei *length,
4758 void **pointer)
4759{
4760 getVertexAttribPointerv(index, pname, pointer);
4761}
4762
Jamie Madillc20ab272016-06-09 07:20:46 -07004763void Context::debugMessageControl(GLenum source,
4764 GLenum type,
4765 GLenum severity,
4766 GLsizei count,
4767 const GLuint *ids,
4768 GLboolean enabled)
4769{
4770 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004771 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05004772 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004773}
4774
4775void Context::debugMessageInsert(GLenum source,
4776 GLenum type,
4777 GLuint id,
4778 GLenum severity,
4779 GLsizei length,
4780 const GLchar *buf)
4781{
4782 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004783 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004784}
4785
4786void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4787{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004788 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004789}
4790
4791GLuint Context::getDebugMessageLog(GLuint count,
4792 GLsizei bufSize,
4793 GLenum *sources,
4794 GLenum *types,
4795 GLuint *ids,
4796 GLenum *severities,
4797 GLsizei *lengths,
4798 GLchar *messageLog)
4799{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004800 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4801 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004802}
4803
4804void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4805{
4806 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004807 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05004808 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07004809}
4810
4811void Context::popDebugGroup()
4812{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004813 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05004814 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004815}
4816
Corentin Wallez336129f2017-10-17 15:55:40 -04004817void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004818{
4819 Buffer *buffer = mGLState.getTargetBuffer(target);
4820 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004821 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004822}
4823
Corentin Wallez336129f2017-10-17 15:55:40 -04004824void Context::bufferSubData(BufferBinding target,
4825 GLintptr offset,
4826 GLsizeiptr size,
4827 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004828{
4829 if (data == nullptr)
4830 {
4831 return;
4832 }
4833
4834 Buffer *buffer = mGLState.getTargetBuffer(target);
4835 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004836 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004837}
4838
Jamie Madillef300b12016-10-07 15:12:09 -04004839void Context::attachShader(GLuint program, GLuint shader)
4840{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05004841 Program *programObject = mState.mShaderPrograms->getProgram(program);
4842 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004843 ASSERT(programObject && shaderObject);
4844 programObject->attachShader(shaderObject);
4845}
4846
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004847const Workarounds &Context::getWorkarounds() const
4848{
4849 return mWorkarounds;
4850}
4851
Corentin Wallez336129f2017-10-17 15:55:40 -04004852void Context::copyBufferSubData(BufferBinding readTarget,
4853 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04004854 GLintptr readOffset,
4855 GLintptr writeOffset,
4856 GLsizeiptr size)
4857{
4858 // if size is zero, the copy is a successful no-op
4859 if (size == 0)
4860 {
4861 return;
4862 }
4863
4864 // TODO(jmadill): cache these.
4865 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4866 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4867
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004868 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004869}
4870
Jamie Madill01a80ee2016-11-07 12:06:18 -05004871void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4872{
4873 Program *programObject = getProgram(program);
4874 // TODO(jmadill): Re-use this from the validation if possible.
4875 ASSERT(programObject);
4876 programObject->bindAttributeLocation(index, name);
4877}
4878
Corentin Wallez336129f2017-10-17 15:55:40 -04004879void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004880{
Corentin Wallez336129f2017-10-17 15:55:40 -04004881 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4882 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004883}
4884
Corentin Wallez336129f2017-10-17 15:55:40 -04004885void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08004886{
4887 bindBufferRange(target, index, buffer, 0, 0);
4888}
4889
Corentin Wallez336129f2017-10-17 15:55:40 -04004890void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08004891 GLuint index,
4892 GLuint buffer,
4893 GLintptr offset,
4894 GLsizeiptr size)
4895{
Corentin Wallez336129f2017-10-17 15:55:40 -04004896 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4897 mGLState.setIndexedBufferBinding(this, target, index, bufferObject, offset, size);
Jiajia Qin6eafb042016-12-27 17:04:07 +08004898}
4899
Jamie Madill01a80ee2016-11-07 12:06:18 -05004900void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
4901{
4902 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4903 {
4904 bindReadFramebuffer(framebuffer);
4905 }
4906
4907 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4908 {
4909 bindDrawFramebuffer(framebuffer);
4910 }
4911}
4912
4913void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4914{
4915 ASSERT(target == GL_RENDERBUFFER);
4916 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004917 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04004918 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004919}
4920
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004921void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08004922 GLsizei samples,
4923 GLenum internalformat,
4924 GLsizei width,
4925 GLsizei height,
4926 GLboolean fixedsamplelocations)
4927{
4928 Extents size(width, height, 1);
4929 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004930 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
4931 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004932}
4933
4934void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4935{
JiangYizhou5b03f472017-01-09 10:22:53 +08004936 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
4937 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillbc918e72018-03-08 09:47:21 -05004938 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
JiangYizhou5b03f472017-01-09 10:22:53 +08004939 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08004940
4941 switch (pname)
4942 {
4943 case GL_SAMPLE_POSITION:
Geoff Lang13455072018-05-09 11:24:43 -04004944 handleError(framebuffer->getSamplePosition(this, index, val));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004945 break;
4946 default:
4947 UNREACHABLE();
4948 }
4949}
4950
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07004951void Context::getMultisamplefvRobust(GLenum pname,
4952 GLuint index,
4953 GLsizei bufSize,
4954 GLsizei *length,
4955 GLfloat *val)
4956{
4957 UNIMPLEMENTED();
4958}
4959
Jamie Madille8fb6402017-02-14 17:56:40 -05004960void Context::renderbufferStorage(GLenum target,
4961 GLenum internalformat,
4962 GLsizei width,
4963 GLsizei height)
4964{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004965 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4966 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
4967
Jamie Madille8fb6402017-02-14 17:56:40 -05004968 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04004969 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004970}
4971
4972void Context::renderbufferStorageMultisample(GLenum target,
4973 GLsizei samples,
4974 GLenum internalformat,
4975 GLsizei width,
4976 GLsizei height)
4977{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004978 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4979 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05004980
4981 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004982 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04004983 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004984}
4985
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004986void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
4987{
Jamie Madill70b5bb02017-08-28 13:32:37 -04004988 const Sync *syncObject = getSync(sync);
Jamie Madilla0691b72018-07-25 10:41:22 -04004989 handleError(QuerySynciv(this, syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004990}
4991
JiangYizhoue18e6392017-02-20 10:32:23 +08004992void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
4993{
4994 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4995 QueryFramebufferParameteriv(framebuffer, pname, params);
4996}
4997
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07004998void Context::getFramebufferParameterivRobust(GLenum target,
4999 GLenum pname,
5000 GLsizei bufSize,
5001 GLsizei *length,
5002 GLint *params)
5003{
5004 UNIMPLEMENTED();
5005}
5006
Jiajia Qin5451d532017-11-16 17:16:34 +08005007void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08005008{
5009 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5010 SetFramebufferParameteri(framebuffer, pname, param);
5011}
5012
Jamie Madilldec86232018-07-11 09:01:18 -04005013bool Context::getScratchBuffer(size_t requstedSizeBytes,
5014 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05005015{
Jamie Madilldec86232018-07-11 09:01:18 -04005016 return mScratchBuffer.get(requstedSizeBytes, scratchBufferOut);
Jamie Madillb3f26b92017-07-19 15:07:41 -04005017}
5018
Jamie Madilldec86232018-07-11 09:01:18 -04005019bool Context::getZeroFilledBuffer(size_t requstedSizeBytes,
5020 angle::MemoryBuffer **zeroBufferOut) const
Jamie Madillb3f26b92017-07-19 15:07:41 -04005021{
Jamie Madilldec86232018-07-11 09:01:18 -04005022 return mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0);
Jamie Madille14951e2017-03-09 18:55:16 -05005023}
5024
Xinghua Cao10a4d432017-11-28 14:46:26 +08005025Error Context::prepareForDispatch()
5026{
Geoff Langa8cb2872018-03-09 16:09:40 -05005027 ANGLE_TRY(syncState(mComputeDirtyBits, mComputeDirtyObjects));
Xinghua Cao10a4d432017-11-28 14:46:26 +08005028
5029 if (isRobustResourceInitEnabled())
5030 {
5031 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
5032 }
5033
5034 return NoError();
5035}
5036
Xinghua Cao2b396592017-03-29 15:36:04 +08005037void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
5038{
5039 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
5040 {
5041 return;
5042 }
5043
Xinghua Cao10a4d432017-11-28 14:46:26 +08005044 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill71c88b32017-09-14 22:20:29 -04005045 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08005046}
5047
Jiajia Qin5451d532017-11-16 17:16:34 +08005048void Context::dispatchComputeIndirect(GLintptr indirect)
5049{
Qin Jiajia62fcf622017-11-30 16:16:12 +08005050 ANGLE_CONTEXT_TRY(prepareForDispatch());
5051 handleError(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08005052}
5053
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005054void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005055 GLsizei levels,
5056 GLenum internalFormat,
5057 GLsizei width,
5058 GLsizei height)
5059{
5060 Extents size(width, height, 1);
5061 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005062 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005063}
5064
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005065void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005066 GLsizei levels,
5067 GLenum internalFormat,
5068 GLsizei width,
5069 GLsizei height,
5070 GLsizei depth)
5071{
5072 Extents size(width, height, depth);
5073 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005074 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005075}
5076
Jiajia Qin5451d532017-11-16 17:16:34 +08005077void Context::memoryBarrier(GLbitfield barriers)
5078{
Xinghua Cao89c422a2017-11-29 18:24:20 +08005079 handleError(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005080}
5081
5082void Context::memoryBarrierByRegion(GLbitfield barriers)
5083{
Xinghua Cao89c422a2017-11-29 18:24:20 +08005084 handleError(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005085}
5086
Jamie Madillc1d770e2017-04-13 17:31:24 -04005087GLenum Context::checkFramebufferStatus(GLenum target)
5088{
5089 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5090 ASSERT(framebuffer);
Jamie Madill427064d2018-04-13 16:20:34 -04005091 return framebuffer->checkStatus(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005092}
5093
5094void Context::compileShader(GLuint shader)
5095{
5096 Shader *shaderObject = GetValidShader(this, shader);
5097 if (!shaderObject)
5098 {
5099 return;
5100 }
5101 shaderObject->compile(this);
5102}
5103
5104void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
5105{
5106 for (int i = 0; i < n; i++)
5107 {
5108 deleteBuffer(buffers[i]);
5109 }
5110}
5111
5112void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
5113{
5114 for (int i = 0; i < n; i++)
5115 {
5116 if (framebuffers[i] != 0)
5117 {
5118 deleteFramebuffer(framebuffers[i]);
5119 }
5120 }
5121}
5122
5123void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
5124{
5125 for (int i = 0; i < n; i++)
5126 {
5127 deleteRenderbuffer(renderbuffers[i]);
5128 }
5129}
5130
5131void Context::deleteTextures(GLsizei n, const GLuint *textures)
5132{
5133 for (int i = 0; i < n; i++)
5134 {
5135 if (textures[i] != 0)
5136 {
5137 deleteTexture(textures[i]);
5138 }
5139 }
5140}
5141
5142void Context::detachShader(GLuint program, GLuint shader)
5143{
5144 Program *programObject = getProgram(program);
5145 ASSERT(programObject);
5146
5147 Shader *shaderObject = getShader(shader);
5148 ASSERT(shaderObject);
5149
5150 programObject->detachShader(this, shaderObject);
5151}
5152
5153void Context::genBuffers(GLsizei n, GLuint *buffers)
5154{
5155 for (int i = 0; i < n; i++)
5156 {
5157 buffers[i] = createBuffer();
5158 }
5159}
5160
5161void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
5162{
5163 for (int i = 0; i < n; i++)
5164 {
5165 framebuffers[i] = createFramebuffer();
5166 }
5167}
5168
5169void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
5170{
5171 for (int i = 0; i < n; i++)
5172 {
5173 renderbuffers[i] = createRenderbuffer();
5174 }
5175}
5176
5177void Context::genTextures(GLsizei n, GLuint *textures)
5178{
5179 for (int i = 0; i < n; i++)
5180 {
5181 textures[i] = createTexture();
5182 }
5183}
5184
5185void Context::getActiveAttrib(GLuint program,
5186 GLuint index,
5187 GLsizei bufsize,
5188 GLsizei *length,
5189 GLint *size,
5190 GLenum *type,
5191 GLchar *name)
5192{
5193 Program *programObject = getProgram(program);
5194 ASSERT(programObject);
5195 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
5196}
5197
5198void Context::getActiveUniform(GLuint program,
5199 GLuint index,
5200 GLsizei bufsize,
5201 GLsizei *length,
5202 GLint *size,
5203 GLenum *type,
5204 GLchar *name)
5205{
5206 Program *programObject = getProgram(program);
5207 ASSERT(programObject);
5208 programObject->getActiveUniform(index, bufsize, length, size, type, name);
5209}
5210
5211void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
5212{
5213 Program *programObject = getProgram(program);
5214 ASSERT(programObject);
5215 programObject->getAttachedShaders(maxcount, count, shaders);
5216}
5217
5218GLint Context::getAttribLocation(GLuint program, const GLchar *name)
5219{
5220 Program *programObject = getProgram(program);
5221 ASSERT(programObject);
5222 return programObject->getAttributeLocation(name);
5223}
5224
5225void Context::getBooleanv(GLenum pname, GLboolean *params)
5226{
5227 GLenum nativeType;
5228 unsigned int numParams = 0;
5229 getQueryParameterInfo(pname, &nativeType, &numParams);
5230
5231 if (nativeType == GL_BOOL)
5232 {
5233 getBooleanvImpl(pname, params);
5234 }
5235 else
5236 {
5237 CastStateValues(this, nativeType, pname, numParams, params);
5238 }
5239}
5240
Brandon Jones59770802018-04-02 13:18:42 -07005241void Context::getBooleanvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLboolean *params)
5242{
5243 getBooleanv(pname, params);
5244}
5245
Jamie Madillc1d770e2017-04-13 17:31:24 -04005246void Context::getFloatv(GLenum pname, GLfloat *params)
5247{
5248 GLenum nativeType;
5249 unsigned int numParams = 0;
5250 getQueryParameterInfo(pname, &nativeType, &numParams);
5251
5252 if (nativeType == GL_FLOAT)
5253 {
5254 getFloatvImpl(pname, params);
5255 }
5256 else
5257 {
5258 CastStateValues(this, nativeType, pname, numParams, params);
5259 }
5260}
5261
Brandon Jones59770802018-04-02 13:18:42 -07005262void Context::getFloatvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLfloat *params)
5263{
5264 getFloatv(pname, params);
5265}
5266
Jamie Madillc1d770e2017-04-13 17:31:24 -04005267void Context::getIntegerv(GLenum pname, GLint *params)
5268{
5269 GLenum nativeType;
5270 unsigned int numParams = 0;
5271 getQueryParameterInfo(pname, &nativeType, &numParams);
5272
5273 if (nativeType == GL_INT)
5274 {
5275 getIntegervImpl(pname, params);
5276 }
5277 else
5278 {
5279 CastStateValues(this, nativeType, pname, numParams, params);
5280 }
5281}
5282
Brandon Jones59770802018-04-02 13:18:42 -07005283void Context::getIntegervRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint *data)
5284{
5285 getIntegerv(pname, data);
5286}
5287
Jamie Madillc1d770e2017-04-13 17:31:24 -04005288void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
5289{
5290 Program *programObject = getProgram(program);
5291 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04005292 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005293}
5294
Brandon Jones59770802018-04-02 13:18:42 -07005295void Context::getProgramivRobust(GLuint program,
5296 GLenum pname,
5297 GLsizei bufSize,
5298 GLsizei *length,
5299 GLint *params)
5300{
5301 getProgramiv(program, pname, params);
5302}
5303
Jiajia Qin5451d532017-11-16 17:16:34 +08005304void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
5305{
5306 UNIMPLEMENTED();
5307}
5308
Jamie Madillbe849e42017-05-02 15:49:00 -04005309void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005310{
5311 Program *programObject = getProgram(program);
5312 ASSERT(programObject);
5313 programObject->getInfoLog(bufsize, length, infolog);
5314}
5315
Jiajia Qin5451d532017-11-16 17:16:34 +08005316void Context::getProgramPipelineInfoLog(GLuint pipeline,
5317 GLsizei bufSize,
5318 GLsizei *length,
5319 GLchar *infoLog)
5320{
5321 UNIMPLEMENTED();
5322}
5323
Jamie Madillc1d770e2017-04-13 17:31:24 -04005324void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
5325{
5326 Shader *shaderObject = getShader(shader);
5327 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04005328 QueryShaderiv(this, shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005329}
5330
Brandon Jones59770802018-04-02 13:18:42 -07005331void Context::getShaderivRobust(GLuint shader,
5332 GLenum pname,
5333 GLsizei bufSize,
5334 GLsizei *length,
5335 GLint *params)
5336{
5337 getShaderiv(shader, pname, params);
5338}
5339
Jamie Madillc1d770e2017-04-13 17:31:24 -04005340void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
5341{
5342 Shader *shaderObject = getShader(shader);
5343 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04005344 shaderObject->getInfoLog(this, bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005345}
5346
5347void Context::getShaderPrecisionFormat(GLenum shadertype,
5348 GLenum precisiontype,
5349 GLint *range,
5350 GLint *precision)
5351{
5352 // TODO(jmadill): Compute shaders.
5353
5354 switch (shadertype)
5355 {
5356 case GL_VERTEX_SHADER:
5357 switch (precisiontype)
5358 {
5359 case GL_LOW_FLOAT:
5360 mCaps.vertexLowpFloat.get(range, precision);
5361 break;
5362 case GL_MEDIUM_FLOAT:
5363 mCaps.vertexMediumpFloat.get(range, precision);
5364 break;
5365 case GL_HIGH_FLOAT:
5366 mCaps.vertexHighpFloat.get(range, precision);
5367 break;
5368
5369 case GL_LOW_INT:
5370 mCaps.vertexLowpInt.get(range, precision);
5371 break;
5372 case GL_MEDIUM_INT:
5373 mCaps.vertexMediumpInt.get(range, precision);
5374 break;
5375 case GL_HIGH_INT:
5376 mCaps.vertexHighpInt.get(range, precision);
5377 break;
5378
5379 default:
5380 UNREACHABLE();
5381 return;
5382 }
5383 break;
5384
5385 case GL_FRAGMENT_SHADER:
5386 switch (precisiontype)
5387 {
5388 case GL_LOW_FLOAT:
5389 mCaps.fragmentLowpFloat.get(range, precision);
5390 break;
5391 case GL_MEDIUM_FLOAT:
5392 mCaps.fragmentMediumpFloat.get(range, precision);
5393 break;
5394 case GL_HIGH_FLOAT:
5395 mCaps.fragmentHighpFloat.get(range, precision);
5396 break;
5397
5398 case GL_LOW_INT:
5399 mCaps.fragmentLowpInt.get(range, precision);
5400 break;
5401 case GL_MEDIUM_INT:
5402 mCaps.fragmentMediumpInt.get(range, precision);
5403 break;
5404 case GL_HIGH_INT:
5405 mCaps.fragmentHighpInt.get(range, precision);
5406 break;
5407
5408 default:
5409 UNREACHABLE();
5410 return;
5411 }
5412 break;
5413
5414 default:
5415 UNREACHABLE();
5416 return;
5417 }
5418}
5419
5420void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
5421{
5422 Shader *shaderObject = getShader(shader);
5423 ASSERT(shaderObject);
5424 shaderObject->getSource(bufsize, length, source);
5425}
5426
5427void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
5428{
5429 Program *programObject = getProgram(program);
5430 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005431 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005432}
5433
Brandon Jones59770802018-04-02 13:18:42 -07005434void Context::getUniformfvRobust(GLuint program,
5435 GLint location,
5436 GLsizei bufSize,
5437 GLsizei *length,
5438 GLfloat *params)
5439{
5440 getUniformfv(program, location, params);
5441}
5442
Jamie Madillc1d770e2017-04-13 17:31:24 -04005443void Context::getUniformiv(GLuint program, GLint location, GLint *params)
5444{
5445 Program *programObject = getProgram(program);
5446 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005447 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005448}
5449
Brandon Jones59770802018-04-02 13:18:42 -07005450void Context::getUniformivRobust(GLuint program,
5451 GLint location,
5452 GLsizei bufSize,
5453 GLsizei *length,
5454 GLint *params)
5455{
5456 getUniformiv(program, location, params);
5457}
5458
Jamie Madillc1d770e2017-04-13 17:31:24 -04005459GLint Context::getUniformLocation(GLuint program, const GLchar *name)
5460{
5461 Program *programObject = getProgram(program);
5462 ASSERT(programObject);
5463 return programObject->getUniformLocation(name);
5464}
5465
5466GLboolean Context::isBuffer(GLuint buffer)
5467{
5468 if (buffer == 0)
5469 {
5470 return GL_FALSE;
5471 }
5472
5473 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
5474}
5475
5476GLboolean Context::isEnabled(GLenum cap)
5477{
5478 return mGLState.getEnableFeature(cap);
5479}
5480
5481GLboolean Context::isFramebuffer(GLuint framebuffer)
5482{
5483 if (framebuffer == 0)
5484 {
5485 return GL_FALSE;
5486 }
5487
5488 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
5489}
5490
5491GLboolean Context::isProgram(GLuint program)
5492{
5493 if (program == 0)
5494 {
5495 return GL_FALSE;
5496 }
5497
5498 return (getProgram(program) ? GL_TRUE : GL_FALSE);
5499}
5500
5501GLboolean Context::isRenderbuffer(GLuint renderbuffer)
5502{
5503 if (renderbuffer == 0)
5504 {
5505 return GL_FALSE;
5506 }
5507
5508 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
5509}
5510
5511GLboolean Context::isShader(GLuint shader)
5512{
5513 if (shader == 0)
5514 {
5515 return GL_FALSE;
5516 }
5517
5518 return (getShader(shader) ? GL_TRUE : GL_FALSE);
5519}
5520
5521GLboolean Context::isTexture(GLuint texture)
5522{
5523 if (texture == 0)
5524 {
5525 return GL_FALSE;
5526 }
5527
5528 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
5529}
5530
5531void Context::linkProgram(GLuint program)
5532{
5533 Program *programObject = getProgram(program);
5534 ASSERT(programObject);
5535 handleError(programObject->link(this));
Martin Radev0abb7a22017-08-28 15:34:45 +03005536 mGLState.onProgramExecutableChange(programObject);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005537}
5538
5539void Context::releaseShaderCompiler()
5540{
Jamie Madill4928b7c2017-06-20 12:57:39 -04005541 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005542}
5543
5544void Context::shaderBinary(GLsizei n,
5545 const GLuint *shaders,
5546 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04005547 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005548 GLsizei length)
5549{
5550 // No binary shader formats are supported.
5551 UNIMPLEMENTED();
5552}
5553
5554void Context::shaderSource(GLuint shader,
5555 GLsizei count,
5556 const GLchar *const *string,
5557 const GLint *length)
5558{
5559 Shader *shaderObject = getShader(shader);
5560 ASSERT(shaderObject);
5561 shaderObject->setSource(count, string, length);
5562}
5563
5564void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
5565{
5566 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
5567}
5568
5569void Context::stencilMask(GLuint mask)
5570{
5571 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
5572}
5573
5574void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
5575{
5576 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
5577}
5578
5579void Context::uniform1f(GLint location, GLfloat x)
5580{
5581 Program *program = mGLState.getProgram();
5582 program->setUniform1fv(location, 1, &x);
5583}
5584
5585void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
5586{
5587 Program *program = mGLState.getProgram();
5588 program->setUniform1fv(location, count, v);
5589}
5590
5591void Context::uniform1i(GLint location, GLint x)
5592{
5593 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04005594 if (program->setUniform1iv(location, 1, &x) == Program::SetUniformResult::SamplerChanged)
5595 {
5596 mGLState.setObjectDirty(GL_PROGRAM);
5597 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005598}
5599
5600void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
5601{
5602 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04005603 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
5604 {
5605 mGLState.setObjectDirty(GL_PROGRAM);
5606 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005607}
5608
5609void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
5610{
5611 GLfloat xy[2] = {x, y};
5612 Program *program = mGLState.getProgram();
5613 program->setUniform2fv(location, 1, xy);
5614}
5615
5616void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
5617{
5618 Program *program = mGLState.getProgram();
5619 program->setUniform2fv(location, count, v);
5620}
5621
5622void Context::uniform2i(GLint location, GLint x, GLint y)
5623{
5624 GLint xy[2] = {x, y};
5625 Program *program = mGLState.getProgram();
5626 program->setUniform2iv(location, 1, xy);
5627}
5628
5629void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
5630{
5631 Program *program = mGLState.getProgram();
5632 program->setUniform2iv(location, count, v);
5633}
5634
5635void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
5636{
5637 GLfloat xyz[3] = {x, y, z};
5638 Program *program = mGLState.getProgram();
5639 program->setUniform3fv(location, 1, xyz);
5640}
5641
5642void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
5643{
5644 Program *program = mGLState.getProgram();
5645 program->setUniform3fv(location, count, v);
5646}
5647
5648void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
5649{
5650 GLint xyz[3] = {x, y, z};
5651 Program *program = mGLState.getProgram();
5652 program->setUniform3iv(location, 1, xyz);
5653}
5654
5655void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
5656{
5657 Program *program = mGLState.getProgram();
5658 program->setUniform3iv(location, count, v);
5659}
5660
5661void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
5662{
5663 GLfloat xyzw[4] = {x, y, z, w};
5664 Program *program = mGLState.getProgram();
5665 program->setUniform4fv(location, 1, xyzw);
5666}
5667
5668void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
5669{
5670 Program *program = mGLState.getProgram();
5671 program->setUniform4fv(location, count, v);
5672}
5673
5674void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
5675{
5676 GLint xyzw[4] = {x, y, z, w};
5677 Program *program = mGLState.getProgram();
5678 program->setUniform4iv(location, 1, xyzw);
5679}
5680
5681void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
5682{
5683 Program *program = mGLState.getProgram();
5684 program->setUniform4iv(location, count, v);
5685}
5686
5687void Context::uniformMatrix2fv(GLint location,
5688 GLsizei count,
5689 GLboolean transpose,
5690 const GLfloat *value)
5691{
5692 Program *program = mGLState.getProgram();
5693 program->setUniformMatrix2fv(location, count, transpose, value);
5694}
5695
5696void Context::uniformMatrix3fv(GLint location,
5697 GLsizei count,
5698 GLboolean transpose,
5699 const GLfloat *value)
5700{
5701 Program *program = mGLState.getProgram();
5702 program->setUniformMatrix3fv(location, count, transpose, value);
5703}
5704
5705void Context::uniformMatrix4fv(GLint location,
5706 GLsizei count,
5707 GLboolean transpose,
5708 const GLfloat *value)
5709{
5710 Program *program = mGLState.getProgram();
5711 program->setUniformMatrix4fv(location, count, transpose, value);
5712}
5713
5714void Context::validateProgram(GLuint program)
5715{
5716 Program *programObject = getProgram(program);
5717 ASSERT(programObject);
5718 programObject->validate(mCaps);
5719}
5720
Jiajia Qin5451d532017-11-16 17:16:34 +08005721void Context::validateProgramPipeline(GLuint pipeline)
5722{
5723 UNIMPLEMENTED();
5724}
5725
Jamie Madilld04908b2017-06-09 14:15:35 -04005726void Context::getProgramBinary(GLuint program,
5727 GLsizei bufSize,
5728 GLsizei *length,
5729 GLenum *binaryFormat,
5730 void *binary)
5731{
5732 Program *programObject = getProgram(program);
5733 ASSERT(programObject != nullptr);
5734
5735 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
5736}
5737
5738void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
5739{
5740 Program *programObject = getProgram(program);
5741 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04005742
Jamie Madilld04908b2017-06-09 14:15:35 -04005743 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
5744}
5745
Jamie Madillff325f12017-08-26 15:06:05 -04005746void Context::uniform1ui(GLint location, GLuint v0)
5747{
5748 Program *program = mGLState.getProgram();
5749 program->setUniform1uiv(location, 1, &v0);
5750}
5751
5752void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
5753{
5754 Program *program = mGLState.getProgram();
5755 const GLuint xy[] = {v0, v1};
5756 program->setUniform2uiv(location, 1, xy);
5757}
5758
5759void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
5760{
5761 Program *program = mGLState.getProgram();
5762 const GLuint xyz[] = {v0, v1, v2};
5763 program->setUniform3uiv(location, 1, xyz);
5764}
5765
5766void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
5767{
5768 Program *program = mGLState.getProgram();
5769 const GLuint xyzw[] = {v0, v1, v2, v3};
5770 program->setUniform4uiv(location, 1, xyzw);
5771}
5772
5773void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
5774{
5775 Program *program = mGLState.getProgram();
5776 program->setUniform1uiv(location, count, value);
5777}
5778void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
5779{
5780 Program *program = mGLState.getProgram();
5781 program->setUniform2uiv(location, count, value);
5782}
5783
5784void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
5785{
5786 Program *program = mGLState.getProgram();
5787 program->setUniform3uiv(location, count, value);
5788}
5789
5790void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
5791{
5792 Program *program = mGLState.getProgram();
5793 program->setUniform4uiv(location, count, value);
5794}
5795
Jamie Madillf0e04492017-08-26 15:28:42 -04005796void Context::genQueries(GLsizei n, GLuint *ids)
5797{
5798 for (GLsizei i = 0; i < n; i++)
5799 {
5800 GLuint handle = mQueryHandleAllocator.allocate();
5801 mQueryMap.assign(handle, nullptr);
5802 ids[i] = handle;
5803 }
5804}
5805
5806void Context::deleteQueries(GLsizei n, const GLuint *ids)
5807{
5808 for (int i = 0; i < n; i++)
5809 {
5810 GLuint query = ids[i];
5811
5812 Query *queryObject = nullptr;
5813 if (mQueryMap.erase(query, &queryObject))
5814 {
5815 mQueryHandleAllocator.release(query);
5816 if (queryObject)
5817 {
5818 queryObject->release(this);
5819 }
5820 }
5821 }
5822}
5823
5824GLboolean Context::isQuery(GLuint id)
5825{
Corentin Wallezad3ae902018-03-09 13:40:42 -05005826 return (getQuery(id, false, QueryType::InvalidEnum) != nullptr) ? GL_TRUE : GL_FALSE;
Jamie Madillf0e04492017-08-26 15:28:42 -04005827}
5828
Jamie Madillc8c95812017-08-26 18:40:09 -04005829void Context::uniformMatrix2x3fv(GLint location,
5830 GLsizei count,
5831 GLboolean transpose,
5832 const GLfloat *value)
5833{
5834 Program *program = mGLState.getProgram();
5835 program->setUniformMatrix2x3fv(location, count, transpose, value);
5836}
5837
5838void Context::uniformMatrix3x2fv(GLint location,
5839 GLsizei count,
5840 GLboolean transpose,
5841 const GLfloat *value)
5842{
5843 Program *program = mGLState.getProgram();
5844 program->setUniformMatrix3x2fv(location, count, transpose, value);
5845}
5846
5847void Context::uniformMatrix2x4fv(GLint location,
5848 GLsizei count,
5849 GLboolean transpose,
5850 const GLfloat *value)
5851{
5852 Program *program = mGLState.getProgram();
5853 program->setUniformMatrix2x4fv(location, count, transpose, value);
5854}
5855
5856void Context::uniformMatrix4x2fv(GLint location,
5857 GLsizei count,
5858 GLboolean transpose,
5859 const GLfloat *value)
5860{
5861 Program *program = mGLState.getProgram();
5862 program->setUniformMatrix4x2fv(location, count, transpose, value);
5863}
5864
5865void Context::uniformMatrix3x4fv(GLint location,
5866 GLsizei count,
5867 GLboolean transpose,
5868 const GLfloat *value)
5869{
5870 Program *program = mGLState.getProgram();
5871 program->setUniformMatrix3x4fv(location, count, transpose, value);
5872}
5873
5874void Context::uniformMatrix4x3fv(GLint location,
5875 GLsizei count,
5876 GLboolean transpose,
5877 const GLfloat *value)
5878{
5879 Program *program = mGLState.getProgram();
5880 program->setUniformMatrix4x3fv(location, count, transpose, value);
5881}
5882
Jamie Madilld7576732017-08-26 18:49:50 -04005883void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
5884{
5885 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5886 {
5887 GLuint vertexArray = arrays[arrayIndex];
5888
5889 if (arrays[arrayIndex] != 0)
5890 {
5891 VertexArray *vertexArrayObject = nullptr;
5892 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
5893 {
5894 if (vertexArrayObject != nullptr)
5895 {
5896 detachVertexArray(vertexArray);
5897 vertexArrayObject->onDestroy(this);
5898 }
5899
5900 mVertexArrayHandleAllocator.release(vertexArray);
5901 }
5902 }
5903 }
5904}
5905
5906void Context::genVertexArrays(GLsizei n, GLuint *arrays)
5907{
5908 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5909 {
5910 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
5911 mVertexArrayMap.assign(vertexArray, nullptr);
5912 arrays[arrayIndex] = vertexArray;
5913 }
5914}
5915
5916bool Context::isVertexArray(GLuint array)
5917{
5918 if (array == 0)
5919 {
5920 return GL_FALSE;
5921 }
5922
5923 VertexArray *vao = getVertexArray(array);
5924 return (vao != nullptr ? GL_TRUE : GL_FALSE);
5925}
5926
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04005927void Context::endTransformFeedback()
5928{
5929 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5930 transformFeedback->end(this);
5931}
5932
5933void Context::transformFeedbackVaryings(GLuint program,
5934 GLsizei count,
5935 const GLchar *const *varyings,
5936 GLenum bufferMode)
5937{
5938 Program *programObject = getProgram(program);
5939 ASSERT(programObject);
5940 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
5941}
5942
5943void Context::getTransformFeedbackVarying(GLuint program,
5944 GLuint index,
5945 GLsizei bufSize,
5946 GLsizei *length,
5947 GLsizei *size,
5948 GLenum *type,
5949 GLchar *name)
5950{
5951 Program *programObject = getProgram(program);
5952 ASSERT(programObject);
5953 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
5954}
5955
5956void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
5957{
5958 for (int i = 0; i < n; i++)
5959 {
5960 GLuint transformFeedback = ids[i];
5961 if (transformFeedback == 0)
5962 {
5963 continue;
5964 }
5965
5966 TransformFeedback *transformFeedbackObject = nullptr;
5967 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
5968 {
5969 if (transformFeedbackObject != nullptr)
5970 {
5971 detachTransformFeedback(transformFeedback);
5972 transformFeedbackObject->release(this);
5973 }
5974
5975 mTransformFeedbackHandleAllocator.release(transformFeedback);
5976 }
5977 }
5978}
5979
5980void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
5981{
5982 for (int i = 0; i < n; i++)
5983 {
5984 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
5985 mTransformFeedbackMap.assign(transformFeedback, nullptr);
5986 ids[i] = transformFeedback;
5987 }
5988}
5989
5990bool Context::isTransformFeedback(GLuint id)
5991{
5992 if (id == 0)
5993 {
5994 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
5995 // returns FALSE
5996 return GL_FALSE;
5997 }
5998
5999 const TransformFeedback *transformFeedback = getTransformFeedback(id);
6000 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
6001}
6002
6003void Context::pauseTransformFeedback()
6004{
6005 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6006 transformFeedback->pause();
6007}
6008
6009void Context::resumeTransformFeedback()
6010{
6011 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6012 transformFeedback->resume();
6013}
6014
Jamie Madill12e957f2017-08-26 21:42:26 -04006015void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
6016{
6017 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04006018 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04006019}
6020
Brandon Jones59770802018-04-02 13:18:42 -07006021void Context::getUniformuivRobust(GLuint program,
6022 GLint location,
6023 GLsizei bufSize,
6024 GLsizei *length,
6025 GLuint *params)
6026{
6027 getUniformuiv(program, location, params);
6028}
6029
Jamie Madill12e957f2017-08-26 21:42:26 -04006030GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
6031{
6032 const Program *programObject = getProgram(program);
6033 return programObject->getFragDataLocation(name);
6034}
6035
6036void Context::getUniformIndices(GLuint program,
6037 GLsizei uniformCount,
6038 const GLchar *const *uniformNames,
6039 GLuint *uniformIndices)
6040{
6041 const Program *programObject = getProgram(program);
6042 if (!programObject->isLinked())
6043 {
6044 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6045 {
6046 uniformIndices[uniformId] = GL_INVALID_INDEX;
6047 }
6048 }
6049 else
6050 {
6051 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6052 {
6053 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
6054 }
6055 }
6056}
6057
6058void Context::getActiveUniformsiv(GLuint program,
6059 GLsizei uniformCount,
6060 const GLuint *uniformIndices,
6061 GLenum pname,
6062 GLint *params)
6063{
6064 const Program *programObject = getProgram(program);
6065 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6066 {
6067 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08006068 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04006069 }
6070}
6071
6072GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
6073{
6074 const Program *programObject = getProgram(program);
6075 return programObject->getUniformBlockIndex(uniformBlockName);
6076}
6077
6078void Context::getActiveUniformBlockiv(GLuint program,
6079 GLuint uniformBlockIndex,
6080 GLenum pname,
6081 GLint *params)
6082{
6083 const Program *programObject = getProgram(program);
6084 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
6085}
6086
Brandon Jones59770802018-04-02 13:18:42 -07006087void Context::getActiveUniformBlockivRobust(GLuint program,
6088 GLuint uniformBlockIndex,
6089 GLenum pname,
6090 GLsizei bufSize,
6091 GLsizei *length,
6092 GLint *params)
6093{
6094 getActiveUniformBlockiv(program, uniformBlockIndex, pname, params);
6095}
6096
Jamie Madill12e957f2017-08-26 21:42:26 -04006097void Context::getActiveUniformBlockName(GLuint program,
6098 GLuint uniformBlockIndex,
6099 GLsizei bufSize,
6100 GLsizei *length,
6101 GLchar *uniformBlockName)
6102{
6103 const Program *programObject = getProgram(program);
6104 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
6105}
6106
6107void Context::uniformBlockBinding(GLuint program,
6108 GLuint uniformBlockIndex,
6109 GLuint uniformBlockBinding)
6110{
6111 Program *programObject = getProgram(program);
6112 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
6113}
6114
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006115GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
6116{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006117 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
6118 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006119
Jamie Madill70b5bb02017-08-28 13:32:37 -04006120 Sync *syncObject = getSync(syncHandle);
Jamie Madilla0691b72018-07-25 10:41:22 -04006121 Error error = syncObject->set(this, condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006122 if (error.isError())
6123 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04006124 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006125 handleError(error);
6126 return nullptr;
6127 }
6128
Jamie Madill70b5bb02017-08-28 13:32:37 -04006129 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006130}
6131
6132GLboolean Context::isSync(GLsync sync)
6133{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006134 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006135}
6136
6137GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6138{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006139 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006140
6141 GLenum result = GL_WAIT_FAILED;
Jamie Madilla0691b72018-07-25 10:41:22 -04006142 handleError(syncObject->clientWait(this, flags, timeout, &result));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006143 return result;
6144}
6145
6146void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6147{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006148 Sync *syncObject = getSync(sync);
Jamie Madilla0691b72018-07-25 10:41:22 -04006149 handleError(syncObject->serverWait(this, flags, timeout));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006150}
6151
6152void Context::getInteger64v(GLenum pname, GLint64 *params)
6153{
6154 GLenum nativeType = GL_NONE;
6155 unsigned int numParams = 0;
6156 getQueryParameterInfo(pname, &nativeType, &numParams);
6157
6158 if (nativeType == GL_INT_64_ANGLEX)
6159 {
6160 getInteger64vImpl(pname, params);
6161 }
6162 else
6163 {
6164 CastStateValues(this, nativeType, pname, numParams, params);
6165 }
6166}
6167
Brandon Jones59770802018-04-02 13:18:42 -07006168void Context::getInteger64vRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint64 *data)
6169{
6170 getInteger64v(pname, data);
6171}
6172
Corentin Wallez336129f2017-10-17 15:55:40 -04006173void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04006174{
6175 Buffer *buffer = mGLState.getTargetBuffer(target);
6176 QueryBufferParameteri64v(buffer, pname, params);
6177}
6178
Brandon Jones59770802018-04-02 13:18:42 -07006179void Context::getBufferParameteri64vRobust(BufferBinding target,
6180 GLenum pname,
6181 GLsizei bufSize,
6182 GLsizei *length,
6183 GLint64 *params)
6184{
6185 getBufferParameteri64v(target, pname, params);
6186}
6187
Jamie Madill3ef140a2017-08-26 23:11:21 -04006188void Context::genSamplers(GLsizei count, GLuint *samplers)
6189{
6190 for (int i = 0; i < count; i++)
6191 {
6192 samplers[i] = mState.mSamplers->createSampler();
6193 }
6194}
6195
6196void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
6197{
6198 for (int i = 0; i < count; i++)
6199 {
6200 GLuint sampler = samplers[i];
6201
6202 if (mState.mSamplers->getSampler(sampler))
6203 {
6204 detachSampler(sampler);
6205 }
6206
6207 mState.mSamplers->deleteObject(this, sampler);
6208 }
6209}
6210
6211void Context::getInternalformativ(GLenum target,
6212 GLenum internalformat,
6213 GLenum pname,
6214 GLsizei bufSize,
6215 GLint *params)
6216{
6217 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
6218 QueryInternalFormativ(formatCaps, pname, bufSize, params);
6219}
6220
Brandon Jones59770802018-04-02 13:18:42 -07006221void Context::getInternalformativRobust(GLenum target,
6222 GLenum internalformat,
6223 GLenum pname,
6224 GLsizei bufSize,
6225 GLsizei *length,
6226 GLint *params)
6227{
6228 getInternalformativ(target, internalformat, pname, bufSize, params);
6229}
6230
Jiajia Qin5451d532017-11-16 17:16:34 +08006231void Context::programUniform1i(GLuint program, GLint location, GLint v0)
6232{
6233 programUniform1iv(program, location, 1, &v0);
6234}
6235
6236void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
6237{
6238 GLint xy[2] = {v0, v1};
6239 programUniform2iv(program, location, 1, xy);
6240}
6241
6242void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
6243{
6244 GLint xyz[3] = {v0, v1, v2};
6245 programUniform3iv(program, location, 1, xyz);
6246}
6247
6248void Context::programUniform4i(GLuint program,
6249 GLint location,
6250 GLint v0,
6251 GLint v1,
6252 GLint v2,
6253 GLint v3)
6254{
6255 GLint xyzw[4] = {v0, v1, v2, v3};
6256 programUniform4iv(program, location, 1, xyzw);
6257}
6258
6259void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
6260{
6261 programUniform1uiv(program, location, 1, &v0);
6262}
6263
6264void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
6265{
6266 GLuint xy[2] = {v0, v1};
6267 programUniform2uiv(program, location, 1, xy);
6268}
6269
6270void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
6271{
6272 GLuint xyz[3] = {v0, v1, v2};
6273 programUniform3uiv(program, location, 1, xyz);
6274}
6275
6276void Context::programUniform4ui(GLuint program,
6277 GLint location,
6278 GLuint v0,
6279 GLuint v1,
6280 GLuint v2,
6281 GLuint v3)
6282{
6283 GLuint xyzw[4] = {v0, v1, v2, v3};
6284 programUniform4uiv(program, location, 1, xyzw);
6285}
6286
6287void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
6288{
6289 programUniform1fv(program, location, 1, &v0);
6290}
6291
6292void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
6293{
6294 GLfloat xy[2] = {v0, v1};
6295 programUniform2fv(program, location, 1, xy);
6296}
6297
6298void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
6299{
6300 GLfloat xyz[3] = {v0, v1, v2};
6301 programUniform3fv(program, location, 1, xyz);
6302}
6303
6304void Context::programUniform4f(GLuint program,
6305 GLint location,
6306 GLfloat v0,
6307 GLfloat v1,
6308 GLfloat v2,
6309 GLfloat v3)
6310{
6311 GLfloat xyzw[4] = {v0, v1, v2, v3};
6312 programUniform4fv(program, location, 1, xyzw);
6313}
6314
Jamie Madill81c2e252017-09-09 23:32:46 -04006315void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6316{
6317 Program *programObject = getProgram(program);
6318 ASSERT(programObject);
6319 if (programObject->setUniform1iv(location, count, value) ==
6320 Program::SetUniformResult::SamplerChanged)
6321 {
6322 mGLState.setObjectDirty(GL_PROGRAM);
6323 }
6324}
6325
Jiajia Qin5451d532017-11-16 17:16:34 +08006326void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6327{
6328 Program *programObject = getProgram(program);
6329 ASSERT(programObject);
6330 programObject->setUniform2iv(location, count, value);
6331}
6332
6333void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6334{
6335 Program *programObject = getProgram(program);
6336 ASSERT(programObject);
6337 programObject->setUniform3iv(location, count, value);
6338}
6339
6340void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6341{
6342 Program *programObject = getProgram(program);
6343 ASSERT(programObject);
6344 programObject->setUniform4iv(location, count, value);
6345}
6346
6347void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6348{
6349 Program *programObject = getProgram(program);
6350 ASSERT(programObject);
6351 programObject->setUniform1uiv(location, count, value);
6352}
6353
6354void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6355{
6356 Program *programObject = getProgram(program);
6357 ASSERT(programObject);
6358 programObject->setUniform2uiv(location, count, value);
6359}
6360
6361void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6362{
6363 Program *programObject = getProgram(program);
6364 ASSERT(programObject);
6365 programObject->setUniform3uiv(location, count, value);
6366}
6367
6368void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6369{
6370 Program *programObject = getProgram(program);
6371 ASSERT(programObject);
6372 programObject->setUniform4uiv(location, count, value);
6373}
6374
6375void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6376{
6377 Program *programObject = getProgram(program);
6378 ASSERT(programObject);
6379 programObject->setUniform1fv(location, count, value);
6380}
6381
6382void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6383{
6384 Program *programObject = getProgram(program);
6385 ASSERT(programObject);
6386 programObject->setUniform2fv(location, count, value);
6387}
6388
6389void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6390{
6391 Program *programObject = getProgram(program);
6392 ASSERT(programObject);
6393 programObject->setUniform3fv(location, count, value);
6394}
6395
6396void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6397{
6398 Program *programObject = getProgram(program);
6399 ASSERT(programObject);
6400 programObject->setUniform4fv(location, count, value);
6401}
6402
6403void Context::programUniformMatrix2fv(GLuint program,
6404 GLint location,
6405 GLsizei count,
6406 GLboolean transpose,
6407 const GLfloat *value)
6408{
6409 Program *programObject = getProgram(program);
6410 ASSERT(programObject);
6411 programObject->setUniformMatrix2fv(location, count, transpose, value);
6412}
6413
6414void Context::programUniformMatrix3fv(GLuint program,
6415 GLint location,
6416 GLsizei count,
6417 GLboolean transpose,
6418 const GLfloat *value)
6419{
6420 Program *programObject = getProgram(program);
6421 ASSERT(programObject);
6422 programObject->setUniformMatrix3fv(location, count, transpose, value);
6423}
6424
6425void Context::programUniformMatrix4fv(GLuint program,
6426 GLint location,
6427 GLsizei count,
6428 GLboolean transpose,
6429 const GLfloat *value)
6430{
6431 Program *programObject = getProgram(program);
6432 ASSERT(programObject);
6433 programObject->setUniformMatrix4fv(location, count, transpose, value);
6434}
6435
6436void Context::programUniformMatrix2x3fv(GLuint program,
6437 GLint location,
6438 GLsizei count,
6439 GLboolean transpose,
6440 const GLfloat *value)
6441{
6442 Program *programObject = getProgram(program);
6443 ASSERT(programObject);
6444 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
6445}
6446
6447void Context::programUniformMatrix3x2fv(GLuint program,
6448 GLint location,
6449 GLsizei count,
6450 GLboolean transpose,
6451 const GLfloat *value)
6452{
6453 Program *programObject = getProgram(program);
6454 ASSERT(programObject);
6455 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
6456}
6457
6458void Context::programUniformMatrix2x4fv(GLuint program,
6459 GLint location,
6460 GLsizei count,
6461 GLboolean transpose,
6462 const GLfloat *value)
6463{
6464 Program *programObject = getProgram(program);
6465 ASSERT(programObject);
6466 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
6467}
6468
6469void Context::programUniformMatrix4x2fv(GLuint program,
6470 GLint location,
6471 GLsizei count,
6472 GLboolean transpose,
6473 const GLfloat *value)
6474{
6475 Program *programObject = getProgram(program);
6476 ASSERT(programObject);
6477 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
6478}
6479
6480void Context::programUniformMatrix3x4fv(GLuint program,
6481 GLint location,
6482 GLsizei count,
6483 GLboolean transpose,
6484 const GLfloat *value)
6485{
6486 Program *programObject = getProgram(program);
6487 ASSERT(programObject);
6488 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
6489}
6490
6491void Context::programUniformMatrix4x3fv(GLuint program,
6492 GLint location,
6493 GLsizei count,
6494 GLboolean transpose,
6495 const GLfloat *value)
6496{
6497 Program *programObject = getProgram(program);
6498 ASSERT(programObject);
6499 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
6500}
6501
Jamie Madill81c2e252017-09-09 23:32:46 -04006502void Context::onTextureChange(const Texture *texture)
6503{
6504 // Conservatively assume all textures are dirty.
6505 // TODO(jmadill): More fine-grained update.
6506 mGLState.setObjectDirty(GL_TEXTURE);
6507}
6508
James Darpiniane8a93c62018-01-04 18:02:24 -08006509bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
6510{
6511 return mGLState.isCurrentTransformFeedback(tf);
6512}
6513bool Context::isCurrentVertexArray(const VertexArray *va) const
6514{
6515 return mGLState.isCurrentVertexArray(va);
6516}
6517
Yunchao Hea336b902017-08-02 16:05:21 +08006518void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
6519{
6520 for (int i = 0; i < count; i++)
6521 {
6522 pipelines[i] = createProgramPipeline();
6523 }
6524}
6525
6526void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
6527{
6528 for (int i = 0; i < count; i++)
6529 {
6530 if (pipelines[i] != 0)
6531 {
6532 deleteProgramPipeline(pipelines[i]);
6533 }
6534 }
6535}
6536
6537GLboolean Context::isProgramPipeline(GLuint pipeline)
6538{
6539 if (pipeline == 0)
6540 {
6541 return GL_FALSE;
6542 }
6543
6544 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
6545}
6546
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006547void Context::finishFenceNV(GLuint fence)
6548{
6549 FenceNV *fenceObject = getFenceNV(fence);
6550
6551 ASSERT(fenceObject && fenceObject->isSet());
Jamie Madilla0691b72018-07-25 10:41:22 -04006552 handleError(fenceObject->finish(this));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006553}
6554
6555void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
6556{
6557 FenceNV *fenceObject = getFenceNV(fence);
6558
6559 ASSERT(fenceObject && fenceObject->isSet());
6560
6561 switch (pname)
6562 {
6563 case GL_FENCE_STATUS_NV:
6564 {
6565 // GL_NV_fence spec:
6566 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
6567 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
6568 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
6569 GLboolean status = GL_TRUE;
6570 if (fenceObject->getStatus() != GL_TRUE)
6571 {
Jamie Madilla0691b72018-07-25 10:41:22 -04006572 ANGLE_CONTEXT_TRY(fenceObject->test(this, &status));
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006573 }
6574 *params = status;
6575 break;
6576 }
6577
6578 case GL_FENCE_CONDITION_NV:
6579 {
6580 *params = static_cast<GLint>(fenceObject->getCondition());
6581 break;
6582 }
6583
6584 default:
6585 UNREACHABLE();
6586 }
6587}
6588
6589void Context::getTranslatedShaderSource(GLuint shader,
6590 GLsizei bufsize,
6591 GLsizei *length,
6592 GLchar *source)
6593{
6594 Shader *shaderObject = getShader(shader);
6595 ASSERT(shaderObject);
6596 shaderObject->getTranslatedSourceWithDebugInfo(this, bufsize, length, source);
6597}
6598
6599void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
6600{
6601 Program *programObject = getProgram(program);
6602 ASSERT(programObject);
6603
6604 programObject->getUniformfv(this, location, params);
6605}
6606
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006607void Context::getnUniformfvRobust(GLuint program,
6608 GLint location,
6609 GLsizei bufSize,
6610 GLsizei *length,
6611 GLfloat *params)
6612{
6613 UNIMPLEMENTED();
6614}
6615
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006616void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
6617{
6618 Program *programObject = getProgram(program);
6619 ASSERT(programObject);
6620
6621 programObject->getUniformiv(this, location, params);
6622}
6623
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006624void Context::getnUniformivRobust(GLuint program,
6625 GLint location,
6626 GLsizei bufSize,
6627 GLsizei *length,
6628 GLint *params)
6629{
6630 UNIMPLEMENTED();
6631}
6632
6633void Context::getnUniformuivRobust(GLuint program,
6634 GLint location,
6635 GLsizei bufSize,
6636 GLsizei *length,
6637 GLuint *params)
6638{
6639 UNIMPLEMENTED();
6640}
6641
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006642GLboolean Context::isFenceNV(GLuint fence)
6643{
6644 FenceNV *fenceObject = getFenceNV(fence);
6645
6646 if (fenceObject == nullptr)
6647 {
6648 return GL_FALSE;
6649 }
6650
6651 // GL_NV_fence spec:
6652 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
6653 // existing fence.
6654 return fenceObject->isSet();
6655}
6656
6657void Context::readnPixels(GLint x,
6658 GLint y,
6659 GLsizei width,
6660 GLsizei height,
6661 GLenum format,
6662 GLenum type,
6663 GLsizei bufSize,
6664 void *data)
6665{
6666 return readPixels(x, y, width, height, format, type, data);
6667}
6668
Jamie Madill007530e2017-12-28 14:27:04 -05006669void Context::setFenceNV(GLuint fence, GLenum condition)
6670{
6671 ASSERT(condition == GL_ALL_COMPLETED_NV);
6672
6673 FenceNV *fenceObject = getFenceNV(fence);
6674 ASSERT(fenceObject != nullptr);
Jamie Madilla0691b72018-07-25 10:41:22 -04006675 handleError(fenceObject->set(this, condition));
Jamie Madill007530e2017-12-28 14:27:04 -05006676}
6677
6678GLboolean Context::testFenceNV(GLuint fence)
6679{
6680 FenceNV *fenceObject = getFenceNV(fence);
6681
6682 ASSERT(fenceObject != nullptr);
6683 ASSERT(fenceObject->isSet() == GL_TRUE);
6684
6685 GLboolean result = GL_TRUE;
Jamie Madilla0691b72018-07-25 10:41:22 -04006686 Error error = fenceObject->test(this, &result);
Jamie Madill007530e2017-12-28 14:27:04 -05006687 if (error.isError())
6688 {
6689 handleError(error);
6690 return GL_TRUE;
6691 }
6692
6693 return result;
6694}
6695
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006696void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006697{
6698 Texture *texture = getTargetTexture(target);
Rafael Cintron05a449a2018-06-20 18:08:04 -07006699 egl::Image *imageObject = static_cast<egl::Image *>(image);
Corentin Wallez99d492c2018-02-27 15:17:10 -05006700 handleError(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05006701}
6702
Jamie Madillfa920eb2018-01-04 11:45:50 -05006703void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006704{
6705 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Rafael Cintron05a449a2018-06-20 18:08:04 -07006706 egl::Image *imageObject = static_cast<egl::Image *>(image);
Jamie Madill007530e2017-12-28 14:27:04 -05006707 handleError(renderbuffer->setStorageEGLImageTarget(this, imageObject));
6708}
6709
Jamie Madillfa920eb2018-01-04 11:45:50 -05006710void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
6711{
6712 UNIMPLEMENTED();
6713}
6714
Jamie Madill5b772312018-03-08 20:28:32 -05006715bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
6716{
6717 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
6718 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
6719 // to the fact that it is stored internally as a float, and so would require conversion
6720 // if returned from Context::getIntegerv. Since this conversion is already implemented
6721 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
6722 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
6723 // application.
6724 switch (pname)
6725 {
6726 case GL_COMPRESSED_TEXTURE_FORMATS:
6727 {
6728 *type = GL_INT;
6729 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
6730 return true;
6731 }
6732 case GL_SHADER_BINARY_FORMATS:
6733 {
6734 *type = GL_INT;
6735 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
6736 return true;
6737 }
6738
6739 case GL_MAX_VERTEX_ATTRIBS:
6740 case GL_MAX_VERTEX_UNIFORM_VECTORS:
6741 case GL_MAX_VARYING_VECTORS:
6742 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
6743 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
6744 case GL_MAX_TEXTURE_IMAGE_UNITS:
6745 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
6746 case GL_MAX_RENDERBUFFER_SIZE:
6747 case GL_NUM_SHADER_BINARY_FORMATS:
6748 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
6749 case GL_ARRAY_BUFFER_BINDING:
6750 case GL_FRAMEBUFFER_BINDING:
6751 case GL_RENDERBUFFER_BINDING:
6752 case GL_CURRENT_PROGRAM:
6753 case GL_PACK_ALIGNMENT:
6754 case GL_UNPACK_ALIGNMENT:
6755 case GL_GENERATE_MIPMAP_HINT:
6756 case GL_RED_BITS:
6757 case GL_GREEN_BITS:
6758 case GL_BLUE_BITS:
6759 case GL_ALPHA_BITS:
6760 case GL_DEPTH_BITS:
6761 case GL_STENCIL_BITS:
6762 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
6763 case GL_CULL_FACE_MODE:
6764 case GL_FRONT_FACE:
6765 case GL_ACTIVE_TEXTURE:
6766 case GL_STENCIL_FUNC:
6767 case GL_STENCIL_VALUE_MASK:
6768 case GL_STENCIL_REF:
6769 case GL_STENCIL_FAIL:
6770 case GL_STENCIL_PASS_DEPTH_FAIL:
6771 case GL_STENCIL_PASS_DEPTH_PASS:
6772 case GL_STENCIL_BACK_FUNC:
6773 case GL_STENCIL_BACK_VALUE_MASK:
6774 case GL_STENCIL_BACK_REF:
6775 case GL_STENCIL_BACK_FAIL:
6776 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
6777 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
6778 case GL_DEPTH_FUNC:
6779 case GL_BLEND_SRC_RGB:
6780 case GL_BLEND_SRC_ALPHA:
6781 case GL_BLEND_DST_RGB:
6782 case GL_BLEND_DST_ALPHA:
6783 case GL_BLEND_EQUATION_RGB:
6784 case GL_BLEND_EQUATION_ALPHA:
6785 case GL_STENCIL_WRITEMASK:
6786 case GL_STENCIL_BACK_WRITEMASK:
6787 case GL_STENCIL_CLEAR_VALUE:
6788 case GL_SUBPIXEL_BITS:
6789 case GL_MAX_TEXTURE_SIZE:
6790 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
6791 case GL_SAMPLE_BUFFERS:
6792 case GL_SAMPLES:
6793 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
6794 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
6795 case GL_TEXTURE_BINDING_2D:
6796 case GL_TEXTURE_BINDING_CUBE_MAP:
6797 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
6798 {
6799 *type = GL_INT;
6800 *numParams = 1;
6801 return true;
6802 }
6803 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6804 {
6805 if (!getExtensions().packReverseRowOrder)
6806 {
6807 return false;
6808 }
6809 *type = GL_INT;
6810 *numParams = 1;
6811 return true;
6812 }
6813 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
6814 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
6815 {
6816 if (!getExtensions().textureRectangle)
6817 {
6818 return false;
6819 }
6820 *type = GL_INT;
6821 *numParams = 1;
6822 return true;
6823 }
6824 case GL_MAX_DRAW_BUFFERS_EXT:
6825 case GL_MAX_COLOR_ATTACHMENTS_EXT:
6826 {
6827 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
6828 {
6829 return false;
6830 }
6831 *type = GL_INT;
6832 *numParams = 1;
6833 return true;
6834 }
6835 case GL_MAX_VIEWPORT_DIMS:
6836 {
6837 *type = GL_INT;
6838 *numParams = 2;
6839 return true;
6840 }
6841 case GL_VIEWPORT:
6842 case GL_SCISSOR_BOX:
6843 {
6844 *type = GL_INT;
6845 *numParams = 4;
6846 return true;
6847 }
6848 case GL_SHADER_COMPILER:
6849 case GL_SAMPLE_COVERAGE_INVERT:
6850 case GL_DEPTH_WRITEMASK:
6851 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
6852 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
6853 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
6854 // bool-natural
6855 case GL_SAMPLE_COVERAGE:
6856 case GL_SCISSOR_TEST:
6857 case GL_STENCIL_TEST:
6858 case GL_DEPTH_TEST:
6859 case GL_BLEND:
6860 case GL_DITHER:
6861 case GL_CONTEXT_ROBUST_ACCESS_EXT:
6862 {
6863 *type = GL_BOOL;
6864 *numParams = 1;
6865 return true;
6866 }
6867 case GL_COLOR_WRITEMASK:
6868 {
6869 *type = GL_BOOL;
6870 *numParams = 4;
6871 return true;
6872 }
6873 case GL_POLYGON_OFFSET_FACTOR:
6874 case GL_POLYGON_OFFSET_UNITS:
6875 case GL_SAMPLE_COVERAGE_VALUE:
6876 case GL_DEPTH_CLEAR_VALUE:
6877 case GL_LINE_WIDTH:
6878 {
6879 *type = GL_FLOAT;
6880 *numParams = 1;
6881 return true;
6882 }
6883 case GL_ALIASED_LINE_WIDTH_RANGE:
6884 case GL_ALIASED_POINT_SIZE_RANGE:
6885 case GL_DEPTH_RANGE:
6886 {
6887 *type = GL_FLOAT;
6888 *numParams = 2;
6889 return true;
6890 }
6891 case GL_COLOR_CLEAR_VALUE:
6892 case GL_BLEND_COLOR:
6893 {
6894 *type = GL_FLOAT;
6895 *numParams = 4;
6896 return true;
6897 }
6898 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
6899 if (!getExtensions().textureFilterAnisotropic)
6900 {
6901 return false;
6902 }
6903 *type = GL_FLOAT;
6904 *numParams = 1;
6905 return true;
6906 case GL_TIMESTAMP_EXT:
6907 if (!getExtensions().disjointTimerQuery)
6908 {
6909 return false;
6910 }
6911 *type = GL_INT_64_ANGLEX;
6912 *numParams = 1;
6913 return true;
6914 case GL_GPU_DISJOINT_EXT:
6915 if (!getExtensions().disjointTimerQuery)
6916 {
6917 return false;
6918 }
6919 *type = GL_INT;
6920 *numParams = 1;
6921 return true;
6922 case GL_COVERAGE_MODULATION_CHROMIUM:
6923 if (!getExtensions().framebufferMixedSamples)
6924 {
6925 return false;
6926 }
6927 *type = GL_INT;
6928 *numParams = 1;
6929 return true;
6930 case GL_TEXTURE_BINDING_EXTERNAL_OES:
6931 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
6932 {
6933 return false;
6934 }
6935 *type = GL_INT;
6936 *numParams = 1;
6937 return true;
6938 }
6939
6940 if (getExtensions().debug)
6941 {
6942 switch (pname)
6943 {
6944 case GL_DEBUG_LOGGED_MESSAGES:
6945 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
6946 case GL_DEBUG_GROUP_STACK_DEPTH:
6947 case GL_MAX_DEBUG_MESSAGE_LENGTH:
6948 case GL_MAX_DEBUG_LOGGED_MESSAGES:
6949 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
6950 case GL_MAX_LABEL_LENGTH:
6951 *type = GL_INT;
6952 *numParams = 1;
6953 return true;
6954
6955 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
6956 case GL_DEBUG_OUTPUT:
6957 *type = GL_BOOL;
6958 *numParams = 1;
6959 return true;
6960 }
6961 }
6962
6963 if (getExtensions().multisampleCompatibility)
6964 {
6965 switch (pname)
6966 {
6967 case GL_MULTISAMPLE_EXT:
6968 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
6969 *type = GL_BOOL;
6970 *numParams = 1;
6971 return true;
6972 }
6973 }
6974
6975 if (getExtensions().pathRendering)
6976 {
6977 switch (pname)
6978 {
6979 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
6980 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
6981 *type = GL_FLOAT;
6982 *numParams = 16;
6983 return true;
6984 }
6985 }
6986
6987 if (getExtensions().bindGeneratesResource)
6988 {
6989 switch (pname)
6990 {
6991 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
6992 *type = GL_BOOL;
6993 *numParams = 1;
6994 return true;
6995 }
6996 }
6997
6998 if (getExtensions().clientArrays)
6999 {
7000 switch (pname)
7001 {
7002 case GL_CLIENT_ARRAYS_ANGLE:
7003 *type = GL_BOOL;
7004 *numParams = 1;
7005 return true;
7006 }
7007 }
7008
7009 if (getExtensions().sRGBWriteControl)
7010 {
7011 switch (pname)
7012 {
7013 case GL_FRAMEBUFFER_SRGB_EXT:
7014 *type = GL_BOOL;
7015 *numParams = 1;
7016 return true;
7017 }
7018 }
7019
7020 if (getExtensions().robustResourceInitialization &&
7021 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
7022 {
7023 *type = GL_BOOL;
7024 *numParams = 1;
7025 return true;
7026 }
7027
7028 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
7029 {
7030 *type = GL_BOOL;
7031 *numParams = 1;
7032 return true;
7033 }
7034
jchen1082af6202018-06-22 10:59:52 +08007035 if (getExtensions().parallelShaderCompile && pname == GL_MAX_SHADER_COMPILER_THREADS_KHR)
7036 {
7037 *type = GL_INT;
7038 *numParams = 1;
7039 return true;
7040 }
7041
Jamie Madill5b772312018-03-08 20:28:32 -05007042 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
7043 switch (pname)
7044 {
7045 // case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE // equivalent to FRAMEBUFFER_BINDING
7046 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
7047 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
7048 {
7049 return false;
7050 }
7051 *type = GL_INT;
7052 *numParams = 1;
7053 return true;
7054
7055 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
7056 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7057 {
7058 return false;
7059 }
7060 *type = GL_INT;
7061 *numParams = 1;
7062 return true;
7063
7064 case GL_PROGRAM_BINARY_FORMATS_OES:
7065 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7066 {
7067 return false;
7068 }
7069 *type = GL_INT;
7070 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
7071 return true;
7072
7073 case GL_PACK_ROW_LENGTH:
7074 case GL_PACK_SKIP_ROWS:
7075 case GL_PACK_SKIP_PIXELS:
7076 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
7077 {
7078 return false;
7079 }
7080 *type = GL_INT;
7081 *numParams = 1;
7082 return true;
7083 case GL_UNPACK_ROW_LENGTH:
7084 case GL_UNPACK_SKIP_ROWS:
7085 case GL_UNPACK_SKIP_PIXELS:
7086 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
7087 {
7088 return false;
7089 }
7090 *type = GL_INT;
7091 *numParams = 1;
7092 return true;
7093 case GL_VERTEX_ARRAY_BINDING:
7094 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
7095 {
7096 return false;
7097 }
7098 *type = GL_INT;
7099 *numParams = 1;
7100 return true;
7101 case GL_PIXEL_PACK_BUFFER_BINDING:
7102 case GL_PIXEL_UNPACK_BUFFER_BINDING:
7103 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
7104 {
7105 return false;
7106 }
7107 *type = GL_INT;
7108 *numParams = 1;
7109 return true;
7110 case GL_MAX_SAMPLES:
7111 {
7112 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
7113 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
7114 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
7115 {
7116 return false;
7117 }
7118 *type = GL_INT;
7119 *numParams = 1;
7120 return true;
7121
7122 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
7123 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
7124 {
7125 return false;
7126 }
7127 *type = GL_INT;
7128 *numParams = 1;
7129 return true;
7130 }
7131 }
7132
7133 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
7134 {
7135 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
7136 {
7137 return false;
7138 }
7139 *type = GL_INT;
7140 *numParams = 1;
7141 return true;
7142 }
7143
7144 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
7145 {
7146 *type = GL_INT;
7147 *numParams = 1;
7148 return true;
7149 }
7150
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007151 if (getClientVersion() < Version(2, 0))
7152 {
7153 switch (pname)
7154 {
7155 case GL_ALPHA_TEST_FUNC:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007156 case GL_CLIENT_ACTIVE_TEXTURE:
7157 case GL_MATRIX_MODE:
7158 case GL_MAX_TEXTURE_UNITS:
7159 case GL_MAX_MODELVIEW_STACK_DEPTH:
7160 case GL_MAX_PROJECTION_STACK_DEPTH:
7161 case GL_MAX_TEXTURE_STACK_DEPTH:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007162 case GL_MAX_LIGHTS:
Lingfeng Yang060088a2018-05-30 20:40:57 -07007163 case GL_MAX_CLIP_PLANES:
Lingfeng Yangabb09f12018-04-16 10:43:53 -07007164 case GL_VERTEX_ARRAY_STRIDE:
7165 case GL_NORMAL_ARRAY_STRIDE:
7166 case GL_COLOR_ARRAY_STRIDE:
7167 case GL_TEXTURE_COORD_ARRAY_STRIDE:
7168 case GL_VERTEX_ARRAY_SIZE:
7169 case GL_COLOR_ARRAY_SIZE:
7170 case GL_TEXTURE_COORD_ARRAY_SIZE:
7171 case GL_VERTEX_ARRAY_TYPE:
7172 case GL_NORMAL_ARRAY_TYPE:
7173 case GL_COLOR_ARRAY_TYPE:
7174 case GL_TEXTURE_COORD_ARRAY_TYPE:
7175 case GL_VERTEX_ARRAY_BUFFER_BINDING:
7176 case GL_NORMAL_ARRAY_BUFFER_BINDING:
7177 case GL_COLOR_ARRAY_BUFFER_BINDING:
7178 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
7179 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
7180 case GL_POINT_SIZE_ARRAY_TYPE_OES:
7181 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
Lingfeng Yanga0cfa872018-05-30 21:12:17 -07007182 case GL_SHADE_MODEL:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007183 *type = GL_INT;
7184 *numParams = 1;
7185 return true;
7186 case GL_ALPHA_TEST_REF:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007187 case GL_FOG_DENSITY:
7188 case GL_FOG_START:
7189 case GL_FOG_END:
7190 case GL_FOG_MODE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007191 case GL_POINT_SIZE:
7192 case GL_POINT_SIZE_MIN:
7193 case GL_POINT_SIZE_MAX:
7194 case GL_POINT_FADE_THRESHOLD_SIZE:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007195 *type = GL_FLOAT;
7196 *numParams = 1;
7197 return true;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007198 case GL_SMOOTH_POINT_SIZE_RANGE:
7199 *type = GL_FLOAT;
7200 *numParams = 2;
7201 return true;
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007202 case GL_CURRENT_COLOR:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007203 case GL_CURRENT_TEXTURE_COORDS:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007204 case GL_LIGHT_MODEL_AMBIENT:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007205 case GL_FOG_COLOR:
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007206 *type = GL_FLOAT;
7207 *numParams = 4;
7208 return true;
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007209 case GL_CURRENT_NORMAL:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007210 case GL_POINT_DISTANCE_ATTENUATION:
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007211 *type = GL_FLOAT;
7212 *numParams = 3;
7213 return true;
Lingfeng Yang3a41af62018-04-09 07:28:56 -07007214 case GL_MODELVIEW_MATRIX:
7215 case GL_PROJECTION_MATRIX:
7216 case GL_TEXTURE_MATRIX:
7217 *type = GL_FLOAT;
7218 *numParams = 16;
7219 return true;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007220 case GL_LIGHT_MODEL_TWO_SIDE:
7221 *type = GL_BOOL;
7222 *numParams = 1;
7223 return true;
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007224 }
7225 }
7226
Jamie Madill5b772312018-03-08 20:28:32 -05007227 if (getClientVersion() < Version(3, 0))
7228 {
7229 return false;
7230 }
7231
7232 // Check for ES3.0+ parameter names
7233 switch (pname)
7234 {
7235 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
7236 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
7237 case GL_UNIFORM_BUFFER_BINDING:
7238 case GL_TRANSFORM_FEEDBACK_BINDING:
7239 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7240 case GL_COPY_READ_BUFFER_BINDING:
7241 case GL_COPY_WRITE_BUFFER_BINDING:
7242 case GL_SAMPLER_BINDING:
7243 case GL_READ_BUFFER:
7244 case GL_TEXTURE_BINDING_3D:
7245 case GL_TEXTURE_BINDING_2D_ARRAY:
7246 case GL_MAX_3D_TEXTURE_SIZE:
7247 case GL_MAX_ARRAY_TEXTURE_LAYERS:
7248 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
7249 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
7250 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
7251 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
7252 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
7253 case GL_MAX_VARYING_COMPONENTS:
7254 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
7255 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
7256 case GL_MIN_PROGRAM_TEXEL_OFFSET:
7257 case GL_MAX_PROGRAM_TEXEL_OFFSET:
7258 case GL_NUM_EXTENSIONS:
7259 case GL_MAJOR_VERSION:
7260 case GL_MINOR_VERSION:
7261 case GL_MAX_ELEMENTS_INDICES:
7262 case GL_MAX_ELEMENTS_VERTICES:
7263 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
7264 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
7265 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
7266 case GL_UNPACK_IMAGE_HEIGHT:
7267 case GL_UNPACK_SKIP_IMAGES:
7268 {
7269 *type = GL_INT;
7270 *numParams = 1;
7271 return true;
7272 }
7273
7274 case GL_MAX_ELEMENT_INDEX:
7275 case GL_MAX_UNIFORM_BLOCK_SIZE:
7276 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
7277 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
7278 case GL_MAX_SERVER_WAIT_TIMEOUT:
7279 {
7280 *type = GL_INT_64_ANGLEX;
7281 *numParams = 1;
7282 return true;
7283 }
7284
7285 case GL_TRANSFORM_FEEDBACK_ACTIVE:
7286 case GL_TRANSFORM_FEEDBACK_PAUSED:
7287 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
7288 case GL_RASTERIZER_DISCARD:
7289 {
7290 *type = GL_BOOL;
7291 *numParams = 1;
7292 return true;
7293 }
7294
7295 case GL_MAX_TEXTURE_LOD_BIAS:
7296 {
7297 *type = GL_FLOAT;
7298 *numParams = 1;
7299 return true;
7300 }
7301 }
7302
7303 if (getExtensions().requestExtension)
7304 {
7305 switch (pname)
7306 {
7307 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
7308 *type = GL_INT;
7309 *numParams = 1;
7310 return true;
7311 }
7312 }
7313
7314 if (getClientVersion() < Version(3, 1))
7315 {
7316 return false;
7317 }
7318
7319 switch (pname)
7320 {
7321 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7322 case GL_DRAW_INDIRECT_BUFFER_BINDING:
7323 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
7324 case GL_MAX_FRAMEBUFFER_WIDTH:
7325 case GL_MAX_FRAMEBUFFER_HEIGHT:
7326 case GL_MAX_FRAMEBUFFER_SAMPLES:
7327 case GL_MAX_SAMPLE_MASK_WORDS:
7328 case GL_MAX_COLOR_TEXTURE_SAMPLES:
7329 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
7330 case GL_MAX_INTEGER_SAMPLES:
7331 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
7332 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
7333 case GL_MAX_VERTEX_ATTRIB_STRIDE:
7334 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
7335 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
7336 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
7337 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
7338 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
7339 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
7340 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
7341 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
7342 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
7343 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
7344 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
7345 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
7346 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
7347 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
7348 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
7349 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
7350 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
7351 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
7352 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
7353 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
7354 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
7355 case GL_MAX_UNIFORM_LOCATIONS:
7356 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
7357 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
7358 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
7359 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
7360 case GL_MAX_IMAGE_UNITS:
7361 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
7362 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
7363 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
7364 case GL_SHADER_STORAGE_BUFFER_BINDING:
7365 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
7366 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
7367 *type = GL_INT;
7368 *numParams = 1;
7369 return true;
7370 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7371 *type = GL_INT_64_ANGLEX;
7372 *numParams = 1;
7373 return true;
7374 case GL_SAMPLE_MASK:
7375 *type = GL_BOOL;
7376 *numParams = 1;
7377 return true;
7378 }
7379
7380 if (getExtensions().geometryShader)
7381 {
7382 switch (pname)
7383 {
7384 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7385 case GL_LAYER_PROVOKING_VERTEX_EXT:
7386 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7387 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7388 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7389 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7390 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7391 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7392 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7393 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7394 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7395 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7396 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7397 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7398 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7399 *type = GL_INT;
7400 *numParams = 1;
7401 return true;
7402 }
7403 }
7404
7405 return false;
7406}
7407
7408bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7409{
7410 if (getClientVersion() < Version(3, 0))
7411 {
7412 return false;
7413 }
7414
7415 switch (target)
7416 {
7417 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7418 case GL_UNIFORM_BUFFER_BINDING:
7419 {
7420 *type = GL_INT;
7421 *numParams = 1;
7422 return true;
7423 }
7424 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7425 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7426 case GL_UNIFORM_BUFFER_START:
7427 case GL_UNIFORM_BUFFER_SIZE:
7428 {
7429 *type = GL_INT_64_ANGLEX;
7430 *numParams = 1;
7431 return true;
7432 }
7433 }
7434
7435 if (getClientVersion() < Version(3, 1))
7436 {
7437 return false;
7438 }
7439
7440 switch (target)
7441 {
7442 case GL_IMAGE_BINDING_LAYERED:
7443 {
7444 *type = GL_BOOL;
7445 *numParams = 1;
7446 return true;
7447 }
7448 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7449 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7450 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7451 case GL_SHADER_STORAGE_BUFFER_BINDING:
7452 case GL_VERTEX_BINDING_BUFFER:
7453 case GL_VERTEX_BINDING_DIVISOR:
7454 case GL_VERTEX_BINDING_OFFSET:
7455 case GL_VERTEX_BINDING_STRIDE:
7456 case GL_SAMPLE_MASK_VALUE:
7457 case GL_IMAGE_BINDING_NAME:
7458 case GL_IMAGE_BINDING_LEVEL:
7459 case GL_IMAGE_BINDING_LAYER:
7460 case GL_IMAGE_BINDING_ACCESS:
7461 case GL_IMAGE_BINDING_FORMAT:
7462 {
7463 *type = GL_INT;
7464 *numParams = 1;
7465 return true;
7466 }
7467 case GL_ATOMIC_COUNTER_BUFFER_START:
7468 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
7469 case GL_SHADER_STORAGE_BUFFER_START:
7470 case GL_SHADER_STORAGE_BUFFER_SIZE:
7471 {
7472 *type = GL_INT_64_ANGLEX;
7473 *numParams = 1;
7474 return true;
7475 }
7476 }
7477
7478 return false;
7479}
7480
7481Program *Context::getProgram(GLuint handle) const
7482{
7483 return mState.mShaderPrograms->getProgram(handle);
7484}
7485
7486Shader *Context::getShader(GLuint handle) const
7487{
7488 return mState.mShaderPrograms->getShader(handle);
7489}
7490
7491bool Context::isTextureGenerated(GLuint texture) const
7492{
7493 return mState.mTextures->isHandleGenerated(texture);
7494}
7495
7496bool Context::isBufferGenerated(GLuint buffer) const
7497{
7498 return mState.mBuffers->isHandleGenerated(buffer);
7499}
7500
7501bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
7502{
7503 return mState.mRenderbuffers->isHandleGenerated(renderbuffer);
7504}
7505
7506bool Context::isFramebufferGenerated(GLuint framebuffer) const
7507{
7508 return mState.mFramebuffers->isHandleGenerated(framebuffer);
7509}
7510
7511bool Context::isProgramPipelineGenerated(GLuint pipeline) const
7512{
7513 return mState.mPipelines->isHandleGenerated(pipeline);
7514}
7515
7516bool Context::usingDisplayTextureShareGroup() const
7517{
7518 return mDisplayTextureShareGroup;
7519}
7520
7521GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
7522{
7523 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
7524 internalformat == GL_DEPTH_STENCIL
7525 ? GL_DEPTH24_STENCIL8
7526 : internalformat;
7527}
7528
jchen1082af6202018-06-22 10:59:52 +08007529void Context::maxShaderCompilerThreads(GLuint count)
7530{
7531 mGLState.setMaxShaderCompilerThreads(count);
7532}
7533
Jamie Madill6b873dd2018-07-12 23:56:30 -04007534// ErrorSet implementation.
7535ErrorSet::ErrorSet(Context *context) : mContext(context)
7536{
7537}
7538
7539ErrorSet::~ErrorSet() = default;
7540
7541void ErrorSet::handleError(const Error &error)
7542{
7543 // This internal enum is used to filter internal errors that are already handled.
7544 // TODO(jmadill): Remove this when refactor is done. http://anglebug.com/2491
7545 if (error.getCode() == GL_INTERNAL_ERROR_ANGLEX)
7546 {
7547 return;
7548 }
7549
7550 if (ANGLE_UNLIKELY(error.isError()))
7551 {
7552 GLenum code = error.getCode();
7553 mErrors.insert(code);
7554 if (code == GL_OUT_OF_MEMORY && mContext->getWorkarounds().loseContextOnOutOfMemory)
7555 {
7556 mContext->markContextLost();
7557 }
7558
7559 ASSERT(!error.getMessage().empty());
7560 mContext->getGLState().getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR,
7561 error.getID(), GL_DEBUG_SEVERITY_HIGH,
7562 error.getMessage());
7563 }
7564}
7565
7566bool ErrorSet::empty() const
7567{
7568 return mErrors.empty();
7569}
7570
7571GLenum ErrorSet::popError()
7572{
7573 ASSERT(!empty());
7574 GLenum error = *mErrors.begin();
7575 mErrors.erase(mErrors.begin());
7576 return error;
7577}
Jamie Madillc29968b2016-01-20 11:17:23 -05007578} // namespace gl