blob: d081a379b4cd4b6d1a33c828a5458b404cb135e1 [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>
Geoff Lang2186c382016-10-14 10:54:54 -0400110gl::Error GetQueryObjectParameter(gl::Query *query, GLenum pname, T *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500111{
Geoff Lang2186c382016-10-14 10:54:54 -0400112 ASSERT(query != nullptr);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500113
114 switch (pname)
115 {
116 case GL_QUERY_RESULT_EXT:
Geoff Lang2186c382016-10-14 10:54:54 -0400117 return query->getResult(params);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500118 case GL_QUERY_RESULT_AVAILABLE_EXT:
119 {
120 bool available;
Geoff Lang2186c382016-10-14 10:54:54 -0400121 gl::Error error = query->isResultAvailable(&available);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500122 if (!error.isError())
123 {
jchen10a99ed552017-09-22 08:10:32 +0800124 *params = gl::CastFromStateValue<T>(pname, static_cast<GLuint>(available));
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500125 }
126 return error;
127 }
128 default:
129 UNREACHABLE();
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500130 return gl::InternalError() << "Unreachable Error";
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500131 }
132}
133
Jamie Madill09463932018-04-04 05:26:59 -0400134void MarkTransformFeedbackBufferUsage(const gl::Context *context,
135 gl::TransformFeedback *transformFeedback,
James Darpinian30b604d2018-03-12 17:26:57 -0700136 GLsizei count,
137 GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -0400138{
Geoff Lang1a683462015-09-29 15:09:59 -0400139 if (transformFeedback && transformFeedback->isActive() && !transformFeedback->isPaused())
Geoff Langf6db0982015-08-25 13:04:00 -0400140 {
Jamie Madill09463932018-04-04 05:26:59 -0400141 transformFeedback->onVerticesDrawn(context, count, instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -0400142 }
143}
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500144
145// Attribute map queries.
Martin Radev1be913c2016-07-11 17:59:16 +0300146EGLint GetClientMajorVersion(const egl::AttributeMap &attribs)
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500147{
Ian Ewellec2c0c52016-04-05 13:46:26 -0400148 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_CLIENT_VERSION, 1));
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500149}
150
Martin Radev1be913c2016-07-11 17:59:16 +0300151EGLint GetClientMinorVersion(const egl::AttributeMap &attribs)
152{
153 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_MINOR_VERSION, 0));
154}
155
Geoff Langeb66a6e2016-10-31 13:06:12 -0400156gl::Version GetClientVersion(const egl::AttributeMap &attribs)
157{
158 return gl::Version(GetClientMajorVersion(attribs), GetClientMinorVersion(attribs));
159}
160
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500161GLenum GetResetStrategy(const egl::AttributeMap &attribs)
162{
Lingfeng Yangb27b03a2018-02-19 13:38:48 -0800163 EGLAttrib attrib =
164 attribs.get(EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT, EGL_NO_RESET_NOTIFICATION);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500165 switch (attrib)
166 {
167 case EGL_NO_RESET_NOTIFICATION:
168 return GL_NO_RESET_NOTIFICATION_EXT;
169 case EGL_LOSE_CONTEXT_ON_RESET:
170 return GL_LOSE_CONTEXT_ON_RESET_EXT;
171 default:
172 UNREACHABLE();
173 return GL_NONE;
174 }
175}
176
177bool GetRobustAccess(const egl::AttributeMap &attribs)
178{
Geoff Lang077f20a2016-11-01 10:08:02 -0400179 return (attribs.get(EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT, EGL_FALSE) == EGL_TRUE) ||
180 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR) !=
181 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500182}
183
184bool GetDebug(const egl::AttributeMap &attribs)
185{
Geoff Lang077f20a2016-11-01 10:08:02 -0400186 return (attribs.get(EGL_CONTEXT_OPENGL_DEBUG, EGL_FALSE) == EGL_TRUE) ||
187 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR) != 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500188}
189
190bool GetNoError(const egl::AttributeMap &attribs)
191{
192 return (attribs.get(EGL_CONTEXT_OPENGL_NO_ERROR_KHR, EGL_FALSE) == EGL_TRUE);
193}
194
Geoff Langc287ea62016-09-16 14:46:51 -0400195bool GetWebGLContext(const egl::AttributeMap &attribs)
196{
197 return (attribs.get(EGL_CONTEXT_WEBGL_COMPATIBILITY_ANGLE, EGL_FALSE) == EGL_TRUE);
198}
199
Geoff Lang0ab41fa2018-03-14 11:03:30 -0400200bool GetExtensionsEnabled(const egl::AttributeMap &attribs, bool webGLContext)
201{
202 // If the context is WebGL, extensions are disabled by default
203 EGLAttrib defaultValue = webGLContext ? EGL_FALSE : EGL_TRUE;
204 return (attribs.get(EGL_EXTENSIONS_ENABLED_ANGLE, defaultValue) == EGL_TRUE);
205}
206
Geoff Langf41a7152016-09-19 15:11:17 -0400207bool GetBindGeneratesResource(const egl::AttributeMap &attribs)
208{
209 return (attribs.get(EGL_CONTEXT_BIND_GENERATES_RESOURCE_CHROMIUM, EGL_TRUE) == EGL_TRUE);
210}
211
Geoff Langfeb8c682017-02-13 16:07:35 -0500212bool GetClientArraysEnabled(const egl::AttributeMap &attribs)
213{
214 return (attribs.get(EGL_CONTEXT_CLIENT_ARRAYS_ENABLED_ANGLE, EGL_TRUE) == EGL_TRUE);
215}
216
Geoff Langb433e872017-10-05 14:01:47 -0400217bool GetRobustResourceInit(const egl::AttributeMap &attribs)
218{
219 return (attribs.get(EGL_ROBUST_RESOURCE_INITIALIZATION_ANGLE, EGL_FALSE) == EGL_TRUE);
220}
221
Martin Radev9d901792016-07-15 15:58:58 +0300222std::string GetObjectLabelFromPointer(GLsizei length, const GLchar *label)
223{
224 std::string labelName;
225 if (label != nullptr)
226 {
227 size_t labelLength = length < 0 ? strlen(label) : length;
228 labelName = std::string(label, labelLength);
229 }
230 return labelName;
231}
232
233void GetObjectLabelBase(const std::string &objectLabel,
234 GLsizei bufSize,
235 GLsizei *length,
236 GLchar *label)
237{
238 size_t writeLength = objectLabel.length();
239 if (label != nullptr && bufSize > 0)
240 {
241 writeLength = std::min(static_cast<size_t>(bufSize) - 1, objectLabel.length());
242 std::copy(objectLabel.begin(), objectLabel.begin() + writeLength, label);
243 label[writeLength] = '\0';
244 }
245
246 if (length != nullptr)
247 {
248 *length = static_cast<GLsizei>(writeLength);
249 }
250}
251
Jamie Madill0f80ed82017-09-19 00:24:56 -0400252template <typename CapT, typename MaxT>
253void LimitCap(CapT *cap, MaxT maximum)
254{
255 *cap = std::min(*cap, static_cast<CapT>(maximum));
256}
257
Tobin Ehlisd7890bc2018-06-29 11:57:22 -0600258constexpr angle::PackedEnumMap<gl::PrimitiveMode, GLsizei> kMinimumPrimitiveCounts = {{
259 /* Points */ 1,
260 /* Lines */ 2,
261 /* LineLoop */ 2,
262 /* LineStrip */ 2,
263 /* Triangles */ 3,
264 /* TriangleStrip */ 3,
265 /* TriangleFan */ 3,
266 /* LinesAdjacency */ 2,
267 /* LineStripAdjacency */ 2,
268 /* TrianglesAdjacency */ 3,
269 /* TriangleStripAdjacency */ 3,
270}};
271// Indices above are code-gen'd so make sure they don't change
272// if any of these static asserts are hit, must update kMinimumPrimitiveCounts abouve
273static_assert(static_cast<gl::PrimitiveMode>(0) == gl::PrimitiveMode::Points,
274 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
275static_assert(static_cast<gl::PrimitiveMode>(1) == gl::PrimitiveMode::Lines,
276 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
277static_assert(static_cast<gl::PrimitiveMode>(2) == gl::PrimitiveMode::LineLoop,
278 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
279static_assert(static_cast<gl::PrimitiveMode>(3) == gl::PrimitiveMode::LineStrip,
280 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
281static_assert(static_cast<gl::PrimitiveMode>(4) == gl::PrimitiveMode::Triangles,
282 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
283static_assert(static_cast<gl::PrimitiveMode>(5) == gl::PrimitiveMode::TriangleStrip,
284 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
285static_assert(static_cast<gl::PrimitiveMode>(6) == gl::PrimitiveMode::TriangleFan,
286 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
287static_assert(static_cast<gl::PrimitiveMode>(7) == gl::PrimitiveMode::LinesAdjacency,
288 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
289static_assert(static_cast<gl::PrimitiveMode>(8) == gl::PrimitiveMode::LineStripAdjacency,
290 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
291static_assert(static_cast<gl::PrimitiveMode>(9) == gl::PrimitiveMode::TrianglesAdjacency,
292 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
293static_assert(static_cast<gl::PrimitiveMode>(10) == gl::PrimitiveMode::TriangleStripAdjacency,
294 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
295static_assert(static_cast<gl::PrimitiveMode>(11) == gl::PrimitiveMode::EnumCount,
296 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
297
Geoff Langf6db0982015-08-25 13:04:00 -0400298} // anonymous namespace
299
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000300namespace gl
301{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +0000302
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400303Context::Context(rx::EGLImplFactory *implFactory,
304 const egl::Config *config,
Corentin Wallez51706ea2015-08-07 14:39:22 -0400305 const Context *shareContext,
Geoff Langce02f082017-02-06 16:46:21 -0500306 TextureManager *shareTextures,
Jamie Madill32447362017-06-28 14:53:52 -0400307 MemoryProgramCache *memoryProgramCache,
Corentin Wallezc295e512017-01-27 17:47:50 -0500308 const egl::AttributeMap &attribs,
Brandon Jones2b0cdcc2018-05-02 08:02:50 -0700309 const egl::DisplayExtensions &displayExtensions,
310 const egl::ClientExtensions &clientExtensions)
Jamie Madill5b772312018-03-08 20:28:32 -0500311 : mState(reinterpret_cast<ContextID>(this),
312 shareContext ? &shareContext->mState : nullptr,
313 shareTextures,
314 GetClientVersion(attribs),
315 &mGLState,
316 mCaps,
317 mTextureCaps,
318 mExtensions,
319 mLimitations),
320 mSkipValidation(GetNoError(attribs)),
321 mDisplayTextureShareGroup(shareTextures != nullptr),
322 mSavedArgsType(nullptr),
Geoff Lang3cacf692018-06-20 16:49:57 -0400323 mImplementation(implFactory->createContext(mState, config, shareContext, attribs)),
Geoff Lang75359662018-04-11 01:42:27 -0400324 mLabel(nullptr),
Jamie Madill2f348d22017-06-05 10:50:59 -0400325 mCompiler(),
Geoff Lang4fb8a8b2018-06-01 16:47:57 -0400326 mGLState(GetDebug(attribs),
327 GetBindGeneratesResource(attribs),
328 GetClientArraysEnabled(attribs),
329 GetRobustResourceInit(attribs),
330 memoryProgramCache != nullptr),
Corentin Walleze3b10e82015-05-20 11:06:25 -0400331 mConfig(config),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500332 mClientType(EGL_OPENGL_ES_API),
Jamie Madill6b873dd2018-07-12 23:56:30 -0400333 mErrors(this),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500334 mHasBeenCurrent(false),
335 mContextLost(false),
336 mResetStatus(GL_NO_ERROR),
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700337 mContextLostForced(false),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500338 mResetStrategy(GetResetStrategy(attribs)),
339 mRobustAccess(GetRobustAccess(attribs)),
Geoff Lang33f11fb2018-05-07 13:42:47 -0400340 mSurfacelessSupported(displayExtensions.surfacelessContext),
341 mExplicitContextAvailable(clientExtensions.explicitContext),
Jamie Madill61e16b42017-06-19 11:13:23 -0400342 mCurrentSurface(static_cast<egl::Surface *>(EGL_NO_SURFACE)),
343 mCurrentDisplay(static_cast<egl::Display *>(EGL_NO_DISPLAY)),
Jamie Madille14951e2017-03-09 18:55:16 -0500344 mWebGLContext(GetWebGLContext(attribs)),
Geoff Lang0ab41fa2018-03-14 11:03:30 -0400345 mExtensionsEnabled(GetExtensionsEnabled(attribs, mWebGLContext)),
Jamie Madill32447362017-06-28 14:53:52 -0400346 mMemoryProgramCache(memoryProgramCache),
Jamie Madillb3f26b92017-07-19 15:07:41 -0400347 mScratchBuffer(1000u),
348 mZeroFilledBuffer(1000u)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000349{
Jamie Madill5b772312018-03-08 20:28:32 -0500350 // Needed to solve a Clang warning of unused variables.
Jamie Madillc6dbc252018-04-30 19:07:56 -0400351 ANGLE_UNUSED_VARIABLE(mSavedArgsType);
352 ANGLE_UNUSED_VARIABLE(mParamsBuffer);
Geoff Lang33f11fb2018-05-07 13:42:47 -0400353}
Jamie Madill5b772312018-03-08 20:28:32 -0500354
Geoff Lang33f11fb2018-05-07 13:42:47 -0400355void Context::initialize()
356{
357 mImplementation->setMemoryProgramCache(mMemoryProgramCache);
Jamie Madill14bbb3f2017-09-12 15:23:01 -0400358
Geoff Lang33f11fb2018-05-07 13:42:47 -0400359 initCaps();
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700360 initWorkarounds();
Geoff Langc0b9ef42014-07-02 10:02:37 -0400361
Geoff Lang4fb8a8b2018-06-01 16:47:57 -0400362 mGLState.initialize(this);
Régis Fénéon83107972015-02-05 12:57:44 +0100363
Shannon Woods53a94a82014-06-24 15:20:36 -0400364 mFenceNVHandleAllocator.setBaseHandle(0);
Geoff Lang7dca1862013-07-30 16:30:46 -0400365
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000366 // [OpenGL ES 2.0.24] section 3.7 page 83:
Corentin Wallez336129f2017-10-17 15:55:40 -0400367 // In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have two-dimensional
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000368 // and cube map texture state vectors respectively associated with them.
369 // In order that access to these initial textures not be lost, they are treated as texture
370 // objects all of whose names are 0.
371
Corentin Wallez99d492c2018-02-27 15:17:10 -0500372 Texture *zeroTexture2D = new Texture(mImplementation.get(), 0, TextureType::_2D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800373 mZeroTextures[TextureType::_2D].set(this, zeroTexture2D);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500374
Corentin Wallez99d492c2018-02-27 15:17:10 -0500375 Texture *zeroTextureCube = new Texture(mImplementation.get(), 0, TextureType::CubeMap);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800376 mZeroTextures[TextureType::CubeMap].set(this, zeroTextureCube);
Geoff Lang76b10c92014-09-05 16:28:14 -0400377
Geoff Langeb66a6e2016-10-31 13:06:12 -0400378 if (getClientVersion() >= Version(3, 0))
Geoff Lang76b10c92014-09-05 16:28:14 -0400379 {
380 // TODO: These could also be enabled via extension
Corentin Wallez99d492c2018-02-27 15:17:10 -0500381 Texture *zeroTexture3D = new Texture(mImplementation.get(), 0, TextureType::_3D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800382 mZeroTextures[TextureType::_3D].set(this, zeroTexture3D);
Geoff Lang76b10c92014-09-05 16:28:14 -0400383
Corentin Wallez99d492c2018-02-27 15:17:10 -0500384 Texture *zeroTexture2DArray = new Texture(mImplementation.get(), 0, TextureType::_2DArray);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800385 mZeroTextures[TextureType::_2DArray].set(this, zeroTexture2DArray);
Geoff Lang76b10c92014-09-05 16:28:14 -0400386 }
Geoff Lang3b573612016-10-31 14:08:10 -0400387 if (getClientVersion() >= Version(3, 1))
388 {
389 Texture *zeroTexture2DMultisample =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500390 new Texture(mImplementation.get(), 0, TextureType::_2DMultisample);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800391 mZeroTextures[TextureType::_2DMultisample].set(this, zeroTexture2DMultisample);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800392
Jiajia Qin6eafb042016-12-27 17:04:07 +0800393 for (unsigned int i = 0; i < mCaps.maxAtomicCounterBufferBindings; i++)
394 {
Qin Jiajia339f65b2018-02-27 12:52:48 +0800395 bindBufferRange(BufferBinding::AtomicCounter, i, 0, 0, 0);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800396 }
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800397
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800398 for (unsigned int i = 0; i < mCaps.maxShaderStorageBufferBindings; i++)
399 {
Corentin Wallez336129f2017-10-17 15:55:40 -0400400 bindBufferRange(BufferBinding::ShaderStorage, i, 0, 0, 0);
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800401 }
Geoff Lang3b573612016-10-31 14:08:10 -0400402 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000403
Geoff Langb0f917f2017-12-05 13:41:54 -0500404 if (mSupportedExtensions.textureRectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400405 {
406 Texture *zeroTextureRectangle =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500407 new Texture(mImplementation.get(), 0, TextureType::Rectangle);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800408 mZeroTextures[TextureType::Rectangle].set(this, zeroTextureRectangle);
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400409 }
410
Geoff Langb0f917f2017-12-05 13:41:54 -0500411 if (mSupportedExtensions.eglImageExternal || mSupportedExtensions.eglStreamConsumerExternal)
Ian Ewellbda75592016-04-18 17:25:54 -0400412 {
Corentin Wallez99d492c2018-02-27 15:17:10 -0500413 Texture *zeroTextureExternal = new Texture(mImplementation.get(), 0, TextureType::External);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800414 mZeroTextures[TextureType::External].set(this, zeroTextureExternal);
Ian Ewellbda75592016-04-18 17:25:54 -0400415 }
416
Jamie Madill4928b7c2017-06-20 12:57:39 -0400417 mGLState.initializeZeroTextures(this, mZeroTextures);
Jamie Madille6382c32014-11-07 15:05:26 -0500418
Jamie Madill57a89722013-07-02 11:57:03 -0400419 bindVertexArray(0);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000420
Geoff Langeb66a6e2016-10-31 13:06:12 -0400421 if (getClientVersion() >= Version(3, 0))
Geoff Lang1a683462015-09-29 15:09:59 -0400422 {
423 // [OpenGL ES 3.0.2] section 2.14.1 pg 85:
424 // In the initial state, a default transform feedback object is bound and treated as
425 // a transform feedback object with a name of zero. That object is bound any time
426 // BindTransformFeedback is called with id of zero
Jamie Madillf0dcb8b2017-08-26 19:05:13 -0400427 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Geoff Lang1a683462015-09-29 15:09:59 -0400428 }
Geoff Langc8058452014-02-03 12:04:11 -0500429
Corentin Wallez336129f2017-10-17 15:55:40 -0400430 for (auto type : angle::AllEnums<BufferBinding>())
431 {
432 bindBuffer(type, 0);
433 }
434
435 bindRenderbuffer(GL_RENDERBUFFER, 0);
436
437 for (unsigned int i = 0; i < mCaps.maxUniformBufferBindings; i++)
438 {
439 bindBufferRange(BufferBinding::Uniform, i, 0, 0, -1);
440 }
441
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700442 // Initialize GLES1 renderer if appropriate.
443 if (getClientVersion() < Version(2, 0))
444 {
445 mGLES1Renderer.reset(new GLES1Renderer());
446 }
447
Jamie Madillad9f24e2016-02-12 09:27:24 -0500448 // Initialize dirty bit masks
Jamie Madillc67323a2017-11-02 23:11:41 -0400449 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500450 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500451 // No dirty objects.
452
453 // Readpixels uses the pack state and read FBO
Jamie Madillc67323a2017-11-02 23:11:41 -0400454 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500455 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_BUFFER_BINDING);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400456 mReadPixelsDirtyBits.set(State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500457 mReadPixelsDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
458
459 mClearDirtyBits.set(State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED);
460 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
461 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR);
462 mClearDirtyBits.set(State::DIRTY_BIT_VIEWPORT);
463 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_COLOR);
464 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_DEPTH);
465 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_STENCIL);
466 mClearDirtyBits.set(State::DIRTY_BIT_COLOR_MASK);
467 mClearDirtyBits.set(State::DIRTY_BIT_DEPTH_MASK);
468 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT);
469 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_BACK);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400470 mClearDirtyBits.set(State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500471 mClearDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
472
473 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
474 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR);
Geoff Lang1d2c41d2016-10-19 16:14:46 -0700475 mBlitDirtyBits.set(State::DIRTY_BIT_FRAMEBUFFER_SRGB);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400476 mBlitDirtyBits.set(State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
477 mBlitDirtyBits.set(State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500478 mBlitDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
479 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
Jamie Madill437fa652016-05-03 15:13:24 -0400480
Xinghua Cao10a4d432017-11-28 14:46:26 +0800481 // TODO(xinghua.cao@intel.com): add other dirty bits and dirty objects.
482 mComputeDirtyBits.set(State::DIRTY_BIT_SHADER_STORAGE_BUFFER_BINDING);
483 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_BINDING);
484 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_EXECUTABLE);
485 mComputeDirtyBits.set(State::DIRTY_BIT_TEXTURE_BINDINGS);
486 mComputeDirtyBits.set(State::DIRTY_BIT_SAMPLER_BINDINGS);
Qin Jiajia62fcf622017-11-30 16:16:12 +0800487 mComputeDirtyBits.set(State::DIRTY_BIT_DISPATCH_INDIRECT_BUFFER_BINDING);
Jiajia Qin5ae6ee42018-03-06 17:39:42 +0800488 mComputeDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM_TEXTURES);
Xinghua Cao10a4d432017-11-28 14:46:26 +0800489
Jamie Madillb4927eb2018-07-16 11:39:46 -0400490 mImplementation->setErrorSet(&mErrors);
491
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400492 handleError(mImplementation->initialize());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000493}
494
Jamie Madill4928b7c2017-06-20 12:57:39 -0400495egl::Error Context::onDestroy(const egl::Display *display)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000496{
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700497 if (mGLES1Renderer)
498 {
499 mGLES1Renderer->onDestroy(this, &mGLState);
500 }
501
Jamie Madille7b3fe22018-04-05 09:42:46 -0400502 // Delete the Surface first to trigger a finish() in Vulkan.
Jamie Madille7b3fe22018-04-05 09:42:46 -0400503 ANGLE_TRY(releaseSurface(display));
504
Corentin Wallez80b24112015-08-25 16:41:57 -0400505 for (auto fence : mFenceNVMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000506 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400507 SafeDelete(fence.second);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000508 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400509 mFenceNVMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000510
Corentin Wallez80b24112015-08-25 16:41:57 -0400511 for (auto query : mQueryMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000512 {
Geoff Langf0aa8422015-09-29 15:08:34 -0400513 if (query.second != nullptr)
514 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400515 query.second->release(this);
Geoff Langf0aa8422015-09-29 15:08:34 -0400516 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000517 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400518 mQueryMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000519
Corentin Wallez80b24112015-08-25 16:41:57 -0400520 for (auto vertexArray : mVertexArrayMap)
Jamie Madill57a89722013-07-02 11:57:03 -0400521 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400522 if (vertexArray.second)
523 {
524 vertexArray.second->onDestroy(this);
525 }
Jamie Madill57a89722013-07-02 11:57:03 -0400526 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400527 mVertexArrayMap.clear();
Jamie Madill57a89722013-07-02 11:57:03 -0400528
Corentin Wallez80b24112015-08-25 16:41:57 -0400529 for (auto transformFeedback : mTransformFeedbackMap)
Geoff Langc8058452014-02-03 12:04:11 -0500530 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500531 if (transformFeedback.second != nullptr)
532 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500533 transformFeedback.second->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500534 }
Geoff Langc8058452014-02-03 12:04:11 -0500535 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400536 mTransformFeedbackMap.clear();
Geoff Langc8058452014-02-03 12:04:11 -0500537
Jamie Madill5b772312018-03-08 20:28:32 -0500538 for (BindingPointer<Texture> &zeroTexture : mZeroTextures)
Geoff Lang76b10c92014-09-05 16:28:14 -0400539 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800540 if (zeroTexture.get() != nullptr)
541 {
542 ANGLE_TRY(zeroTexture->onDestroy(this));
543 zeroTexture.set(this, nullptr);
544 }
Geoff Lang76b10c92014-09-05 16:28:14 -0400545 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000546
Jamie Madill2f348d22017-06-05 10:50:59 -0400547 releaseShaderCompiler();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500548
Jamie Madill4928b7c2017-06-20 12:57:39 -0400549 mGLState.reset(this);
550
Jamie Madill6c1f6712017-02-14 19:08:04 -0500551 mState.mBuffers->release(this);
552 mState.mShaderPrograms->release(this);
553 mState.mTextures->release(this);
554 mState.mRenderbuffers->release(this);
555 mState.mSamplers->release(this);
Jamie Madill70b5bb02017-08-28 13:32:37 -0400556 mState.mSyncs->release(this);
Jamie Madill6c1f6712017-02-14 19:08:04 -0500557 mState.mPaths->release(this);
558 mState.mFramebuffers->release(this);
Yunchao Hea336b902017-08-02 16:05:21 +0800559 mState.mPipelines->release(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400560
Jamie Madill76e471e2017-10-21 09:56:01 -0400561 mImplementation->onDestroy(this);
562
Jamie Madill4928b7c2017-06-20 12:57:39 -0400563 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000564}
565
Jamie Madill70ee0f62017-02-06 16:04:20 -0500566Context::~Context()
567{
568}
569
Geoff Lang75359662018-04-11 01:42:27 -0400570void Context::setLabel(EGLLabelKHR label)
571{
572 mLabel = label;
573}
574
575EGLLabelKHR Context::getLabel() const
576{
577 return mLabel;
578}
579
Jamie Madill4928b7c2017-06-20 12:57:39 -0400580egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000581{
Jamie Madill61e16b42017-06-19 11:13:23 -0400582 mCurrentDisplay = display;
583
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000584 if (!mHasBeenCurrent)
585 {
Geoff Lang33f11fb2018-05-07 13:42:47 -0400586 initialize();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000587 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500588 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400589 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000590
Corentin Wallezc295e512017-01-27 17:47:50 -0500591 int width = 0;
592 int height = 0;
593 if (surface != nullptr)
594 {
595 width = surface->getWidth();
596 height = surface->getHeight();
597 }
598
599 mGLState.setViewportParams(0, 0, width, height);
600 mGLState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000601
602 mHasBeenCurrent = true;
603 }
604
Jamie Madill1b94d432015-08-07 13:23:23 -0400605 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700606 mGLState.setAllDirtyBits();
Jamie Madill81c2e252017-09-09 23:32:46 -0400607 mGLState.setAllDirtyObjects();
Jamie Madill1b94d432015-08-07 13:23:23 -0400608
Jamie Madill4928b7c2017-06-20 12:57:39 -0400609 ANGLE_TRY(releaseSurface(display));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500610
611 Framebuffer *newDefault = nullptr;
612 if (surface != nullptr)
613 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400614 ANGLE_TRY(surface->setIsCurrent(this, true));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500615 mCurrentSurface = surface;
Geoff Langbf7b95d2018-05-01 16:48:21 -0400616 newDefault = surface->createDefaultFramebuffer(this);
Corentin Wallezccab69d2017-01-27 16:57:15 -0500617 }
618 else
619 {
Geoff Langbf7b95d2018-05-01 16:48:21 -0400620 newDefault = new Framebuffer(mImplementation.get());
Corentin Wallezccab69d2017-01-27 16:57:15 -0500621 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000622
Corentin Wallez37c39792015-08-20 14:19:46 -0400623 // Update default framebuffer, the binding of the previous default
624 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400625 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700626 if (mGLState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400627 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700628 mGLState.setReadFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400629 }
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700630 if (mGLState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400631 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700632 mGLState.setDrawFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400633 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500634 mState.mFramebuffers->setDefaultFramebuffer(newDefault);
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400635 }
Ian Ewell292f0052016-02-04 10:37:32 -0500636
637 // Notify the renderer of a context switch
Luc Ferron5396f2a2018-07-12 08:24:23 -0400638 ANGLE_TRY(mImplementation->onMakeCurrent(this));
Jamie Madill4928b7c2017-06-20 12:57:39 -0400639 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000640}
641
Jamie Madill4928b7c2017-06-20 12:57:39 -0400642egl::Error Context::releaseSurface(const egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400643{
Geoff Langbf7b95d2018-05-01 16:48:21 -0400644 gl::Framebuffer *defaultFramebuffer = mState.mFramebuffers->getFramebuffer(0);
Corentin Wallez51706ea2015-08-07 14:39:22 -0400645
Geoff Langbf7b95d2018-05-01 16:48:21 -0400646 // Remove the default framebuffer
647 if (mGLState.getReadFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500648 {
649 mGLState.setReadFramebufferBinding(nullptr);
650 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400651
652 if (mGLState.getDrawFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500653 {
654 mGLState.setDrawFramebufferBinding(nullptr);
655 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400656
657 if (defaultFramebuffer)
658 {
659 defaultFramebuffer->onDestroy(this);
660 delete defaultFramebuffer;
661 }
662
Corentin Wallezc295e512017-01-27 17:47:50 -0500663 mState.mFramebuffers->setDefaultFramebuffer(nullptr);
664
665 if (mCurrentSurface)
666 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400667 ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
Corentin Wallezc295e512017-01-27 17:47:50 -0500668 mCurrentSurface = nullptr;
669 }
Jamie Madill4928b7c2017-06-20 12:57:39 -0400670
671 return egl::NoError();
Jamie Madill77a72f62015-04-14 11:18:32 -0400672}
673
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000674GLuint Context::createBuffer()
675{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500676 return mState.mBuffers->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000677}
678
679GLuint Context::createProgram()
680{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500681 return mState.mShaderPrograms->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000682}
683
Jiawei Shao385b3e02018-03-21 09:43:28 +0800684GLuint Context::createShader(ShaderType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000685{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500686 return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000687}
688
689GLuint Context::createTexture()
690{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500691 return mState.mTextures->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000692}
693
694GLuint Context::createRenderbuffer()
695{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500696 return mState.mRenderbuffers->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000697}
698
Brandon Jones59770802018-04-02 13:18:42 -0700699GLuint Context::genPaths(GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300700{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500701 auto resultOrError = mState.mPaths->createPaths(mImplementation.get(), range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300702 if (resultOrError.isError())
703 {
704 handleError(resultOrError.getError());
705 return 0;
706 }
707 return resultOrError.getResult();
708}
709
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000710// Returns an unused framebuffer name
711GLuint Context::createFramebuffer()
712{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500713 return mState.mFramebuffers->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000714}
715
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500716void Context::genFencesNV(GLsizei n, GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000717{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500718 for (int i = 0; i < n; i++)
719 {
720 GLuint handle = mFenceNVHandleAllocator.allocate();
721 mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV()));
722 fences[i] = handle;
723 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000724}
725
Yunchao Hea336b902017-08-02 16:05:21 +0800726GLuint Context::createProgramPipeline()
727{
728 return mState.mPipelines->createProgramPipeline();
729}
730
Jiawei Shao385b3e02018-03-21 09:43:28 +0800731GLuint Context::createShaderProgramv(ShaderType type, GLsizei count, const GLchar *const *strings)
Jiajia Qin5451d532017-11-16 17:16:34 +0800732{
733 UNIMPLEMENTED();
734 return 0u;
735}
736
James Darpinian4d9d4832018-03-13 12:43:28 -0700737void Context::deleteBuffer(GLuint bufferName)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000738{
James Darpinian4d9d4832018-03-13 12:43:28 -0700739 Buffer *buffer = mState.mBuffers->getBuffer(bufferName);
740 if (buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000741 {
742 detachBuffer(buffer);
743 }
Jamie Madill893ab082014-05-16 16:56:10 -0400744
James Darpinian4d9d4832018-03-13 12:43:28 -0700745 mState.mBuffers->deleteObject(this, bufferName);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000746}
747
748void Context::deleteShader(GLuint shader)
749{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500750 mState.mShaderPrograms->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000751}
752
753void Context::deleteProgram(GLuint program)
754{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500755 mState.mShaderPrograms->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000756}
757
758void Context::deleteTexture(GLuint texture)
759{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500760 if (mState.mTextures->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000761 {
762 detachTexture(texture);
763 }
764
Jamie Madill6c1f6712017-02-14 19:08:04 -0500765 mState.mTextures->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000766}
767
768void Context::deleteRenderbuffer(GLuint renderbuffer)
769{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500770 if (mState.mRenderbuffers->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000771 {
772 detachRenderbuffer(renderbuffer);
773 }
Jamie Madill893ab082014-05-16 16:56:10 -0400774
Jamie Madill6c1f6712017-02-14 19:08:04 -0500775 mState.mRenderbuffers->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000776}
777
Jamie Madill7f0c5a42017-08-26 22:43:26 -0400778void Context::deleteSync(GLsync sync)
Jamie Madillcd055f82013-07-26 11:55:15 -0400779{
780 // The spec specifies the underlying Fence object is not deleted until all current
781 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
782 // and since our API is currently designed for being called from a single thread, we can delete
783 // the fence immediately.
Jamie Madill70b5bb02017-08-28 13:32:37 -0400784 mState.mSyncs->deleteObject(this, static_cast<GLuint>(reinterpret_cast<uintptr_t>(sync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400785}
786
Yunchao Hea336b902017-08-02 16:05:21 +0800787void Context::deleteProgramPipeline(GLuint pipeline)
788{
789 if (mState.mPipelines->getProgramPipeline(pipeline))
790 {
791 detachProgramPipeline(pipeline);
792 }
793
794 mState.mPipelines->deleteObject(this, pipeline);
795}
796
Sami Väisänene45e53b2016-05-25 10:36:04 +0300797void Context::deletePaths(GLuint first, GLsizei range)
798{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500799 mState.mPaths->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300800}
801
Brandon Jones59770802018-04-02 13:18:42 -0700802bool Context::isPath(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300803{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500804 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300805 if (pathObj == nullptr)
806 return false;
807
808 return pathObj->hasPathData();
809}
810
Brandon Jones59770802018-04-02 13:18:42 -0700811bool Context::isPathGenerated(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300812{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500813 return mState.mPaths->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300814}
815
Brandon Jones59770802018-04-02 13:18:42 -0700816void Context::pathCommands(GLuint path,
817 GLsizei numCommands,
818 const GLubyte *commands,
819 GLsizei numCoords,
820 GLenum coordType,
821 const void *coords)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300822{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500823 auto *pathObject = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300824
825 handleError(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
826}
827
Jamie Madill007530e2017-12-28 14:27:04 -0500828void Context::pathParameterf(GLuint path, GLenum pname, GLfloat value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300829{
Jamie Madill007530e2017-12-28 14:27:04 -0500830 Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300831
832 switch (pname)
833 {
834 case GL_PATH_STROKE_WIDTH_CHROMIUM:
835 pathObj->setStrokeWidth(value);
836 break;
837 case GL_PATH_END_CAPS_CHROMIUM:
838 pathObj->setEndCaps(static_cast<GLenum>(value));
839 break;
840 case GL_PATH_JOIN_STYLE_CHROMIUM:
841 pathObj->setJoinStyle(static_cast<GLenum>(value));
842 break;
843 case GL_PATH_MITER_LIMIT_CHROMIUM:
844 pathObj->setMiterLimit(value);
845 break;
846 case GL_PATH_STROKE_BOUND_CHROMIUM:
847 pathObj->setStrokeBound(value);
848 break;
849 default:
850 UNREACHABLE();
851 break;
852 }
853}
854
Jamie Madill007530e2017-12-28 14:27:04 -0500855void Context::pathParameteri(GLuint path, GLenum pname, GLint value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300856{
Jamie Madill007530e2017-12-28 14:27:04 -0500857 // TODO(jmadill): Should use proper clamping/casting.
858 pathParameterf(path, pname, static_cast<GLfloat>(value));
859}
860
861void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value)
862{
863 const Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300864
865 switch (pname)
866 {
867 case GL_PATH_STROKE_WIDTH_CHROMIUM:
868 *value = pathObj->getStrokeWidth();
869 break;
870 case GL_PATH_END_CAPS_CHROMIUM:
871 *value = static_cast<GLfloat>(pathObj->getEndCaps());
872 break;
873 case GL_PATH_JOIN_STYLE_CHROMIUM:
874 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
875 break;
876 case GL_PATH_MITER_LIMIT_CHROMIUM:
877 *value = pathObj->getMiterLimit();
878 break;
879 case GL_PATH_STROKE_BOUND_CHROMIUM:
880 *value = pathObj->getStrokeBound();
881 break;
882 default:
883 UNREACHABLE();
884 break;
885 }
886}
887
Jamie Madill007530e2017-12-28 14:27:04 -0500888void Context::getPathParameteriv(GLuint path, GLenum pname, GLint *value)
889{
890 GLfloat val = 0.0f;
891 getPathParameterfv(path, pname, value != nullptr ? &val : nullptr);
892 if (value)
893 *value = static_cast<GLint>(val);
894}
895
Brandon Jones59770802018-04-02 13:18:42 -0700896void Context::pathStencilFunc(GLenum func, GLint ref, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300897{
898 mGLState.setPathStencilFunc(func, ref, mask);
899}
900
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000901void Context::deleteFramebuffer(GLuint framebuffer)
902{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500903 if (mState.mFramebuffers->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000904 {
905 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000906 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500907
Jamie Madill6c1f6712017-02-14 19:08:04 -0500908 mState.mFramebuffers->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000909}
910
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500911void Context::deleteFencesNV(GLsizei n, const GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000912{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500913 for (int i = 0; i < n; i++)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000914 {
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500915 GLuint fence = fences[i];
916
917 FenceNV *fenceObject = nullptr;
918 if (mFenceNVMap.erase(fence, &fenceObject))
919 {
920 mFenceNVHandleAllocator.release(fence);
921 delete fenceObject;
922 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000923 }
924}
925
Geoff Lang70d0f492015-12-10 17:45:46 -0500926Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000927{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500928 return mState.mBuffers->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000929}
930
Jamie Madill570f7c82014-07-03 10:38:54 -0400931Texture *Context::getTexture(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000932{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500933 return mState.mTextures->getTexture(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000934}
935
Geoff Lang70d0f492015-12-10 17:45:46 -0500936Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000937{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500938 return mState.mRenderbuffers->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000939}
940
Jamie Madill70b5bb02017-08-28 13:32:37 -0400941Sync *Context::getSync(GLsync handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400942{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400943 return mState.mSyncs->getSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400944}
945
Jamie Madill57a89722013-07-02 11:57:03 -0400946VertexArray *Context::getVertexArray(GLuint handle) const
947{
Jamie Madill96a483b2017-06-27 16:49:21 -0400948 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -0400949}
950
Jamie Madilldc356042013-07-19 16:36:57 -0400951Sampler *Context::getSampler(GLuint handle) const
952{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500953 return mState.mSamplers->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400954}
955
Geoff Langc8058452014-02-03 12:04:11 -0500956TransformFeedback *Context::getTransformFeedback(GLuint handle) const
957{
Jamie Madill96a483b2017-06-27 16:49:21 -0400958 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -0500959}
960
Yunchao Hea336b902017-08-02 16:05:21 +0800961ProgramPipeline *Context::getProgramPipeline(GLuint handle) const
962{
963 return mState.mPipelines->getProgramPipeline(handle);
964}
965
Geoff Lang75359662018-04-11 01:42:27 -0400966gl::LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
Geoff Lang70d0f492015-12-10 17:45:46 -0500967{
968 switch (identifier)
969 {
970 case GL_BUFFER:
971 return getBuffer(name);
972 case GL_SHADER:
973 return getShader(name);
974 case GL_PROGRAM:
975 return getProgram(name);
976 case GL_VERTEX_ARRAY:
977 return getVertexArray(name);
978 case GL_QUERY:
979 return getQuery(name);
980 case GL_TRANSFORM_FEEDBACK:
981 return getTransformFeedback(name);
982 case GL_SAMPLER:
983 return getSampler(name);
984 case GL_TEXTURE:
985 return getTexture(name);
986 case GL_RENDERBUFFER:
987 return getRenderbuffer(name);
988 case GL_FRAMEBUFFER:
989 return getFramebuffer(name);
990 default:
991 UNREACHABLE();
992 return nullptr;
993 }
994}
995
Geoff Lang75359662018-04-11 01:42:27 -0400996gl::LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
Geoff Lang70d0f492015-12-10 17:45:46 -0500997{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400998 return getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
Geoff Lang70d0f492015-12-10 17:45:46 -0500999}
1000
Martin Radev9d901792016-07-15 15:58:58 +03001001void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
1002{
Geoff Lang75359662018-04-11 01:42:27 -04001003 gl::LabeledObject *object = getLabeledObject(identifier, name);
Martin Radev9d901792016-07-15 15:58:58 +03001004 ASSERT(object != nullptr);
1005
1006 std::string labelName = GetObjectLabelFromPointer(length, label);
1007 object->setLabel(labelName);
Jamie Madill8693bdb2017-09-02 15:32:14 -04001008
1009 // TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the
1010 // specified object is active until we do this.
1011 mGLState.setObjectDirty(identifier);
Martin Radev9d901792016-07-15 15:58:58 +03001012}
1013
1014void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
1015{
Geoff Lang75359662018-04-11 01:42:27 -04001016 gl::LabeledObject *object = getLabeledObjectFromPtr(ptr);
Martin Radev9d901792016-07-15 15:58:58 +03001017 ASSERT(object != nullptr);
1018
1019 std::string labelName = GetObjectLabelFromPointer(length, label);
1020 object->setLabel(labelName);
1021}
1022
1023void Context::getObjectLabel(GLenum identifier,
1024 GLuint name,
1025 GLsizei bufSize,
1026 GLsizei *length,
1027 GLchar *label) const
1028{
Geoff Lang75359662018-04-11 01:42:27 -04001029 gl::LabeledObject *object = getLabeledObject(identifier, name);
Martin Radev9d901792016-07-15 15:58:58 +03001030 ASSERT(object != nullptr);
1031
1032 const std::string &objectLabel = object->getLabel();
1033 GetObjectLabelBase(objectLabel, bufSize, length, label);
1034}
1035
1036void Context::getObjectPtrLabel(const void *ptr,
1037 GLsizei bufSize,
1038 GLsizei *length,
1039 GLchar *label) const
1040{
Geoff Lang75359662018-04-11 01:42:27 -04001041 gl::LabeledObject *object = getLabeledObjectFromPtr(ptr);
Martin Radev9d901792016-07-15 15:58:58 +03001042 ASSERT(object != nullptr);
1043
1044 const std::string &objectLabel = object->getLabel();
1045 GetObjectLabelBase(objectLabel, bufSize, length, label);
1046}
1047
Jamie Madilldc356042013-07-19 16:36:57 -04001048bool Context::isSampler(GLuint samplerName) const
1049{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001050 return mState.mSamplers->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -04001051}
1052
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001053void Context::bindTexture(TextureType target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001054{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001055 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001056
Jamie Madilldedd7b92014-11-05 16:30:36 -05001057 if (handle == 0)
1058 {
1059 texture = mZeroTextures[target].get();
1060 }
1061 else
1062 {
Corentin Wallez99d492c2018-02-27 15:17:10 -05001063 texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -05001064 }
1065
1066 ASSERT(texture);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001067 mGLState.setSamplerTexture(this, target, texture);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00001068}
1069
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001070void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001071{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001072 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1073 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001074 mGLState.setReadFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001075}
1076
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001077void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001078{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001079 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1080 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001081 mGLState.setDrawFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001082}
1083
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001084void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -04001085{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001086 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madill7267aa62018-04-17 15:28:21 -04001087 mGLState.setVertexArrayBinding(this, vertexArray);
Jamie Madill57a89722013-07-02 11:57:03 -04001088}
1089
Shao80957d92017-02-20 21:25:59 +08001090void Context::bindVertexBuffer(GLuint bindingIndex,
1091 GLuint bufferHandle,
1092 GLintptr offset,
1093 GLsizei stride)
1094{
1095 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001096 mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Shao80957d92017-02-20 21:25:59 +08001097}
1098
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001099void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -04001100{
Geoff Lang76b10c92014-09-05 16:28:14 -04001101 ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -04001102 Sampler *sampler =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001103 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001104 mGLState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04001105}
1106
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001107void Context::bindImageTexture(GLuint unit,
1108 GLuint texture,
1109 GLint level,
1110 GLboolean layered,
1111 GLint layer,
1112 GLenum access,
1113 GLenum format)
1114{
1115 Texture *tex = mState.mTextures->getTexture(texture);
1116 mGLState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
1117}
1118
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001119void Context::useProgram(GLuint program)
1120{
Jamie Madill6c1f6712017-02-14 19:08:04 -05001121 mGLState.setProgram(this, getProgram(program));
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001122}
1123
Jiajia Qin5451d532017-11-16 17:16:34 +08001124void Context::useProgramStages(GLuint pipeline, GLbitfield stages, GLuint program)
1125{
1126 UNIMPLEMENTED();
1127}
1128
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001129void Context::bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001130{
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001131 ASSERT(target == GL_TRANSFORM_FEEDBACK);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001132 TransformFeedback *transformFeedback =
1133 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001134 mGLState.setTransformFeedbackBinding(this, transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -05001135}
1136
Yunchao Hea336b902017-08-02 16:05:21 +08001137void Context::bindProgramPipeline(GLuint pipelineHandle)
1138{
1139 ProgramPipeline *pipeline =
1140 mState.mPipelines->checkProgramPipelineAllocation(mImplementation.get(), pipelineHandle);
1141 mGLState.setProgramPipelineBinding(this, pipeline);
1142}
1143
Corentin Wallezad3ae902018-03-09 13:40:42 -05001144void Context::beginQuery(QueryType target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001145{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001146 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001147 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001148
Geoff Lang5aad9672014-09-08 11:10:42 -04001149 // begin query
Jamie Madillf0e04492017-08-26 15:28:42 -04001150 ANGLE_CONTEXT_TRY(queryObject->begin());
Geoff Lang5aad9672014-09-08 11:10:42 -04001151
1152 // set query as active for specified target only if begin succeeded
Jamie Madill4928b7c2017-06-20 12:57:39 -04001153 mGLState.setActiveQuery(this, target, queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001154}
1155
Corentin Wallezad3ae902018-03-09 13:40:42 -05001156void Context::endQuery(QueryType target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001157{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001158 Query *queryObject = mGLState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001159 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001160
Jamie Madillf0e04492017-08-26 15:28:42 -04001161 handleError(queryObject->end());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001162
Geoff Lang5aad9672014-09-08 11:10:42 -04001163 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madill4928b7c2017-06-20 12:57:39 -04001164 mGLState.setActiveQuery(this, target, nullptr);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001165}
1166
Corentin Wallezad3ae902018-03-09 13:40:42 -05001167void Context::queryCounter(GLuint id, QueryType target)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001168{
Corentin Wallezad3ae902018-03-09 13:40:42 -05001169 ASSERT(target == QueryType::Timestamp);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001170
1171 Query *queryObject = getQuery(id, true, target);
1172 ASSERT(queryObject);
1173
Jamie Madillf0e04492017-08-26 15:28:42 -04001174 handleError(queryObject->queryCounter());
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001175}
1176
Corentin Wallezad3ae902018-03-09 13:40:42 -05001177void Context::getQueryiv(QueryType target, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001178{
1179 switch (pname)
1180 {
1181 case GL_CURRENT_QUERY_EXT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001182 params[0] = mGLState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001183 break;
1184 case GL_QUERY_COUNTER_BITS_EXT:
1185 switch (target)
1186 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001187 case QueryType::TimeElapsed:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001188 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1189 break;
Corentin Wallezad3ae902018-03-09 13:40:42 -05001190 case QueryType::Timestamp:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001191 params[0] = getExtensions().queryCounterBitsTimestamp;
1192 break;
1193 default:
1194 UNREACHABLE();
1195 params[0] = 0;
1196 break;
1197 }
1198 break;
1199 default:
1200 UNREACHABLE();
1201 return;
1202 }
1203}
1204
Corentin Wallezad3ae902018-03-09 13:40:42 -05001205void Context::getQueryivRobust(QueryType target,
Brandon Jones59770802018-04-02 13:18:42 -07001206 GLenum pname,
1207 GLsizei bufSize,
1208 GLsizei *length,
1209 GLint *params)
1210{
1211 getQueryiv(target, pname, params);
1212}
1213
Geoff Lang2186c382016-10-14 10:54:54 -04001214void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001215{
Geoff Lang2186c382016-10-14 10:54:54 -04001216 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001217}
1218
Brandon Jones59770802018-04-02 13:18:42 -07001219void Context::getQueryObjectivRobust(GLuint id,
1220 GLenum pname,
1221 GLsizei bufSize,
1222 GLsizei *length,
1223 GLint *params)
1224{
1225 getQueryObjectiv(id, pname, params);
1226}
1227
Geoff Lang2186c382016-10-14 10:54:54 -04001228void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001229{
Geoff Lang2186c382016-10-14 10:54:54 -04001230 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001231}
1232
Brandon Jones59770802018-04-02 13:18:42 -07001233void Context::getQueryObjectuivRobust(GLuint id,
1234 GLenum pname,
1235 GLsizei bufSize,
1236 GLsizei *length,
1237 GLuint *params)
1238{
1239 getQueryObjectuiv(id, pname, params);
1240}
1241
Geoff Lang2186c382016-10-14 10:54:54 -04001242void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001243{
Geoff Lang2186c382016-10-14 10:54:54 -04001244 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001245}
1246
Brandon Jones59770802018-04-02 13:18:42 -07001247void Context::getQueryObjecti64vRobust(GLuint id,
1248 GLenum pname,
1249 GLsizei bufSize,
1250 GLsizei *length,
1251 GLint64 *params)
1252{
1253 getQueryObjecti64v(id, pname, params);
1254}
1255
Geoff Lang2186c382016-10-14 10:54:54 -04001256void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001257{
Geoff Lang2186c382016-10-14 10:54:54 -04001258 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001259}
1260
Brandon Jones59770802018-04-02 13:18:42 -07001261void Context::getQueryObjectui64vRobust(GLuint id,
1262 GLenum pname,
1263 GLsizei bufSize,
1264 GLsizei *length,
1265 GLuint64 *params)
1266{
1267 getQueryObjectui64v(id, pname, params);
1268}
1269
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001270Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001271{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001272 return mState.mFramebuffers->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001273}
1274
Jamie Madill2f348d22017-06-05 10:50:59 -04001275FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001276{
Jamie Madill96a483b2017-06-27 16:49:21 -04001277 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001278}
1279
Corentin Wallezad3ae902018-03-09 13:40:42 -05001280Query *Context::getQuery(GLuint handle, bool create, QueryType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001281{
Jamie Madill96a483b2017-06-27 16:49:21 -04001282 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001283 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001284 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001285 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001286
1287 Query *query = mQueryMap.query(handle);
1288 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001289 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001290 ASSERT(type != QueryType::InvalidEnum);
Jamie Madill96a483b2017-06-27 16:49:21 -04001291 query = new Query(mImplementation->createQuery(type), handle);
1292 query->addRef();
1293 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001294 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001295 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001296}
1297
Geoff Lang70d0f492015-12-10 17:45:46 -05001298Query *Context::getQuery(GLuint handle) const
1299{
Jamie Madill96a483b2017-06-27 16:49:21 -04001300 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001301}
1302
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001303Texture *Context::getTargetTexture(TextureType type) const
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001304{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001305 ASSERT(ValidTextureTarget(this, type) || ValidTextureExternalTarget(this, type));
1306 return mGLState.getTargetTexture(type);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001307}
1308
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001309Texture *Context::getSamplerTexture(unsigned int sampler, TextureType type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001310{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001311 return mGLState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001312}
1313
Geoff Lang492a7e42014-11-05 13:27:06 -05001314Compiler *Context::getCompiler() const
1315{
Jamie Madill2f348d22017-06-05 10:50:59 -04001316 if (mCompiler.get() == nullptr)
1317 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001318 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001319 }
1320 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001321}
1322
Jamie Madillc1d770e2017-04-13 17:31:24 -04001323void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001324{
1325 switch (pname)
1326 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001327 case GL_SHADER_COMPILER:
1328 *params = GL_TRUE;
1329 break;
1330 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1331 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1332 break;
1333 default:
1334 mGLState.getBooleanv(pname, params);
1335 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001336 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001337}
1338
Jamie Madillc1d770e2017-04-13 17:31:24 -04001339void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001340{
Shannon Woods53a94a82014-06-24 15:20:36 -04001341 // Queries about context capabilities and maximums are answered by Context.
1342 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001343 switch (pname)
1344 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001345 case GL_ALIASED_LINE_WIDTH_RANGE:
1346 params[0] = mCaps.minAliasedLineWidth;
1347 params[1] = mCaps.maxAliasedLineWidth;
1348 break;
1349 case GL_ALIASED_POINT_SIZE_RANGE:
1350 params[0] = mCaps.minAliasedPointSize;
1351 params[1] = mCaps.maxAliasedPointSize;
1352 break;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07001353 case GL_SMOOTH_POINT_SIZE_RANGE:
1354 params[0] = mCaps.minSmoothPointSize;
1355 params[1] = mCaps.maxSmoothPointSize;
1356 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001357 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1358 ASSERT(mExtensions.textureFilterAnisotropic);
1359 *params = mExtensions.maxTextureAnisotropy;
1360 break;
1361 case GL_MAX_TEXTURE_LOD_BIAS:
1362 *params = mCaps.maxLODBias;
1363 break;
1364
1365 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1366 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1367 {
Lingfeng Yang3a41af62018-04-09 07:28:56 -07001368 // GLES1 emulation: // GL_PATH_(MODELVIEW|PROJECTION)_MATRIX_CHROMIUM collides with the
1369 // GLES1 constants for modelview/projection matrix.
1370 if (getClientVersion() < Version(2, 0))
1371 {
1372 mGLState.getFloatv(pname, params);
1373 }
1374 else
1375 {
1376 ASSERT(mExtensions.pathRendering);
1377 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1378 memcpy(params, m, 16 * sizeof(GLfloat));
1379 }
Jamie Madill231c7f52017-04-26 13:45:37 -04001380 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001381 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001382
Jamie Madill231c7f52017-04-26 13:45:37 -04001383 default:
1384 mGLState.getFloatv(pname, params);
1385 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001386 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001387}
1388
Jamie Madillc1d770e2017-04-13 17:31:24 -04001389void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001390{
Shannon Woods53a94a82014-06-24 15:20:36 -04001391 // Queries about context capabilities and maximums are answered by Context.
1392 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001393
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001394 switch (pname)
1395 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001396 case GL_MAX_VERTEX_ATTRIBS:
1397 *params = mCaps.maxVertexAttributes;
1398 break;
1399 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1400 *params = mCaps.maxVertexUniformVectors;
1401 break;
1402 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001403 *params = mCaps.maxShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001404 break;
1405 case GL_MAX_VARYING_VECTORS:
1406 *params = mCaps.maxVaryingVectors;
1407 break;
1408 case GL_MAX_VARYING_COMPONENTS:
1409 *params = mCaps.maxVertexOutputComponents;
1410 break;
1411 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1412 *params = mCaps.maxCombinedTextureImageUnits;
1413 break;
1414 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001415 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001416 break;
1417 case GL_MAX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001418 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001419 break;
1420 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1421 *params = mCaps.maxFragmentUniformVectors;
1422 break;
1423 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001424 *params = mCaps.maxShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001425 break;
1426 case GL_MAX_RENDERBUFFER_SIZE:
1427 *params = mCaps.maxRenderbufferSize;
1428 break;
1429 case GL_MAX_COLOR_ATTACHMENTS_EXT:
1430 *params = mCaps.maxColorAttachments;
1431 break;
1432 case GL_MAX_DRAW_BUFFERS_EXT:
1433 *params = mCaps.maxDrawBuffers;
1434 break;
1435 // case GL_FRAMEBUFFER_BINDING: // now equivalent to
1436 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
1437 case GL_SUBPIXEL_BITS:
1438 *params = 4;
1439 break;
1440 case GL_MAX_TEXTURE_SIZE:
1441 *params = mCaps.max2DTextureSize;
1442 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001443 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
1444 *params = mCaps.maxRectangleTextureSize;
1445 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001446 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1447 *params = mCaps.maxCubeMapTextureSize;
1448 break;
1449 case GL_MAX_3D_TEXTURE_SIZE:
1450 *params = mCaps.max3DTextureSize;
1451 break;
1452 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1453 *params = mCaps.maxArrayTextureLayers;
1454 break;
1455 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1456 *params = mCaps.uniformBufferOffsetAlignment;
1457 break;
1458 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1459 *params = mCaps.maxUniformBufferBindings;
1460 break;
1461 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001462 *params = mCaps.maxShaderUniformBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001463 break;
1464 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001465 *params = mCaps.maxShaderUniformBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001466 break;
1467 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1468 *params = mCaps.maxCombinedTextureImageUnits;
1469 break;
1470 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1471 *params = mCaps.maxVertexOutputComponents;
1472 break;
1473 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1474 *params = mCaps.maxFragmentInputComponents;
1475 break;
1476 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1477 *params = mCaps.minProgramTexelOffset;
1478 break;
1479 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1480 *params = mCaps.maxProgramTexelOffset;
1481 break;
1482 case GL_MAJOR_VERSION:
1483 *params = getClientVersion().major;
1484 break;
1485 case GL_MINOR_VERSION:
1486 *params = getClientVersion().minor;
1487 break;
1488 case GL_MAX_ELEMENTS_INDICES:
1489 *params = mCaps.maxElementsIndices;
1490 break;
1491 case GL_MAX_ELEMENTS_VERTICES:
1492 *params = mCaps.maxElementsVertices;
1493 break;
1494 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1495 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1496 break;
1497 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1498 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1499 break;
1500 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1501 *params = mCaps.maxTransformFeedbackSeparateComponents;
1502 break;
1503 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1504 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1505 break;
1506 case GL_MAX_SAMPLES_ANGLE:
1507 *params = mCaps.maxSamples;
1508 break;
1509 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001510 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001511 params[0] = mCaps.maxViewportWidth;
1512 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001513 }
1514 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001515 case GL_COMPRESSED_TEXTURE_FORMATS:
1516 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1517 params);
1518 break;
1519 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1520 *params = mResetStrategy;
1521 break;
1522 case GL_NUM_SHADER_BINARY_FORMATS:
1523 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1524 break;
1525 case GL_SHADER_BINARY_FORMATS:
1526 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1527 break;
1528 case GL_NUM_PROGRAM_BINARY_FORMATS:
1529 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1530 break;
1531 case GL_PROGRAM_BINARY_FORMATS:
1532 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1533 break;
1534 case GL_NUM_EXTENSIONS:
1535 *params = static_cast<GLint>(mExtensionStrings.size());
1536 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001537
Jamie Madill231c7f52017-04-26 13:45:37 -04001538 // GL_KHR_debug
1539 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1540 *params = mExtensions.maxDebugMessageLength;
1541 break;
1542 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1543 *params = mExtensions.maxDebugLoggedMessages;
1544 break;
1545 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1546 *params = mExtensions.maxDebugGroupStackDepth;
1547 break;
1548 case GL_MAX_LABEL_LENGTH:
1549 *params = mExtensions.maxLabelLength;
1550 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001551
Martin Radeve5285d22017-07-14 16:23:53 +03001552 // GL_ANGLE_multiview
1553 case GL_MAX_VIEWS_ANGLE:
1554 *params = mExtensions.maxViews;
1555 break;
1556
Jamie Madill231c7f52017-04-26 13:45:37 -04001557 // GL_EXT_disjoint_timer_query
1558 case GL_GPU_DISJOINT_EXT:
1559 *params = mImplementation->getGPUDisjoint();
1560 break;
1561 case GL_MAX_FRAMEBUFFER_WIDTH:
1562 *params = mCaps.maxFramebufferWidth;
1563 break;
1564 case GL_MAX_FRAMEBUFFER_HEIGHT:
1565 *params = mCaps.maxFramebufferHeight;
1566 break;
1567 case GL_MAX_FRAMEBUFFER_SAMPLES:
1568 *params = mCaps.maxFramebufferSamples;
1569 break;
1570 case GL_MAX_SAMPLE_MASK_WORDS:
1571 *params = mCaps.maxSampleMaskWords;
1572 break;
1573 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1574 *params = mCaps.maxColorTextureSamples;
1575 break;
1576 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1577 *params = mCaps.maxDepthTextureSamples;
1578 break;
1579 case GL_MAX_INTEGER_SAMPLES:
1580 *params = mCaps.maxIntegerSamples;
1581 break;
1582 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1583 *params = mCaps.maxVertexAttribRelativeOffset;
1584 break;
1585 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1586 *params = mCaps.maxVertexAttribBindings;
1587 break;
1588 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1589 *params = mCaps.maxVertexAttribStride;
1590 break;
1591 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001592 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001593 break;
1594 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001595 *params = mCaps.maxShaderAtomicCounters[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001596 break;
1597 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001598 *params = mCaps.maxShaderImageUniforms[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001599 break;
1600 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001601 *params = mCaps.maxShaderStorageBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001602 break;
1603 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001604 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001605 break;
1606 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001607 *params = mCaps.maxShaderAtomicCounters[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001608 break;
1609 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001610 *params = mCaps.maxShaderImageUniforms[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001611 break;
1612 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001613 *params = mCaps.maxShaderStorageBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001614 break;
1615 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1616 *params = mCaps.minProgramTextureGatherOffset;
1617 break;
1618 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1619 *params = mCaps.maxProgramTextureGatherOffset;
1620 break;
1621 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1622 *params = mCaps.maxComputeWorkGroupInvocations;
1623 break;
1624 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001625 *params = mCaps.maxShaderUniformBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001626 break;
1627 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001628 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001629 break;
1630 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1631 *params = mCaps.maxComputeSharedMemorySize;
1632 break;
1633 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001634 *params = mCaps.maxShaderUniformComponents[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001635 break;
1636 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001637 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001638 break;
1639 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001640 *params = mCaps.maxShaderAtomicCounters[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001641 break;
1642 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001643 *params = mCaps.maxShaderImageUniforms[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001644 break;
1645 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001646 *params =
1647 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Compute]);
Jamie Madill231c7f52017-04-26 13:45:37 -04001648 break;
1649 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001650 *params = mCaps.maxShaderStorageBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001651 break;
1652 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1653 *params = mCaps.maxCombinedShaderOutputResources;
1654 break;
1655 case GL_MAX_UNIFORM_LOCATIONS:
1656 *params = mCaps.maxUniformLocations;
1657 break;
1658 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1659 *params = mCaps.maxAtomicCounterBufferBindings;
1660 break;
1661 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1662 *params = mCaps.maxAtomicCounterBufferSize;
1663 break;
1664 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1665 *params = mCaps.maxCombinedAtomicCounterBuffers;
1666 break;
1667 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1668 *params = mCaps.maxCombinedAtomicCounters;
1669 break;
1670 case GL_MAX_IMAGE_UNITS:
1671 *params = mCaps.maxImageUnits;
1672 break;
1673 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1674 *params = mCaps.maxCombinedImageUniforms;
1675 break;
1676 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1677 *params = mCaps.maxShaderStorageBufferBindings;
1678 break;
1679 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1680 *params = mCaps.maxCombinedShaderStorageBlocks;
1681 break;
1682 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1683 *params = mCaps.shaderStorageBufferOffsetAlignment;
1684 break;
Jiawei Shao361df072017-11-22 09:33:59 +08001685
1686 // GL_EXT_geometry_shader
1687 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
1688 *params = mCaps.maxFramebufferLayers;
1689 break;
1690 case GL_LAYER_PROVOKING_VERTEX_EXT:
1691 *params = mCaps.layerProvokingVertex;
1692 break;
1693 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001694 *params = mCaps.maxShaderUniformComponents[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001695 break;
1696 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001697 *params = mCaps.maxShaderUniformBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001698 break;
1699 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001700 *params =
1701 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Geometry]);
Jiawei Shao361df072017-11-22 09:33:59 +08001702 break;
1703 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
1704 *params = mCaps.maxGeometryInputComponents;
1705 break;
1706 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
1707 *params = mCaps.maxGeometryOutputComponents;
1708 break;
1709 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
1710 *params = mCaps.maxGeometryOutputVertices;
1711 break;
1712 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
1713 *params = mCaps.maxGeometryTotalOutputComponents;
1714 break;
1715 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
1716 *params = mCaps.maxGeometryShaderInvocations;
1717 break;
1718 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001719 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001720 break;
1721 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001722 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001723 break;
1724 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001725 *params = mCaps.maxShaderAtomicCounters[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001726 break;
1727 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001728 *params = mCaps.maxShaderImageUniforms[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001729 break;
1730 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001731 *params = mCaps.maxShaderStorageBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001732 break;
Lingfeng Yang96310cd2018-03-28 11:56:28 -07001733 // GLES1 emulation: Caps queries
1734 case GL_MAX_TEXTURE_UNITS:
1735 *params = mCaps.maxMultitextureUnits;
1736 break;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001737 case GL_MAX_MODELVIEW_STACK_DEPTH:
1738 *params = mCaps.maxModelviewMatrixStackDepth;
1739 break;
1740 case GL_MAX_PROJECTION_STACK_DEPTH:
1741 *params = mCaps.maxProjectionMatrixStackDepth;
1742 break;
1743 case GL_MAX_TEXTURE_STACK_DEPTH:
1744 *params = mCaps.maxTextureMatrixStackDepth;
1745 break;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07001746 case GL_MAX_LIGHTS:
1747 *params = mCaps.maxLights;
1748 break;
Lingfeng Yang060088a2018-05-30 20:40:57 -07001749 case GL_MAX_CLIP_PLANES:
1750 *params = mCaps.maxClipPlanes;
1751 break;
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001752 // GLES1 emulation: Vertex attribute queries
1753 case GL_VERTEX_ARRAY_BUFFER_BINDING:
1754 case GL_NORMAL_ARRAY_BUFFER_BINDING:
1755 case GL_COLOR_ARRAY_BUFFER_BINDING:
1756 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
1757 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
1758 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1759 GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, params);
1760 break;
1761 case GL_VERTEX_ARRAY_STRIDE:
1762 case GL_NORMAL_ARRAY_STRIDE:
1763 case GL_COLOR_ARRAY_STRIDE:
1764 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
1765 case GL_TEXTURE_COORD_ARRAY_STRIDE:
1766 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1767 GL_VERTEX_ATTRIB_ARRAY_STRIDE, params);
1768 break;
1769 case GL_VERTEX_ARRAY_SIZE:
1770 case GL_COLOR_ARRAY_SIZE:
1771 case GL_TEXTURE_COORD_ARRAY_SIZE:
1772 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1773 GL_VERTEX_ATTRIB_ARRAY_SIZE, params);
1774 break;
1775 case GL_VERTEX_ARRAY_TYPE:
1776 case GL_COLOR_ARRAY_TYPE:
1777 case GL_NORMAL_ARRAY_TYPE:
1778 case GL_POINT_SIZE_ARRAY_TYPE_OES:
1779 case GL_TEXTURE_COORD_ARRAY_TYPE:
1780 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1781 GL_VERTEX_ATTRIB_ARRAY_TYPE, params);
1782 break;
1783
jchen1082af6202018-06-22 10:59:52 +08001784 // GL_KHR_parallel_shader_compile
1785 case GL_MAX_SHADER_COMPILER_THREADS_KHR:
1786 *params = mGLState.getMaxShaderCompilerThreads();
1787 break;
1788
Jamie Madill231c7f52017-04-26 13:45:37 -04001789 default:
Jamie Madille98b1b52018-03-08 09:47:23 -05001790 handleError(mGLState.getIntegerv(this, pname, params));
Jamie Madill231c7f52017-04-26 13:45:37 -04001791 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001792 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001793}
1794
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001795void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001796{
Shannon Woods53a94a82014-06-24 15:20:36 -04001797 // Queries about context capabilities and maximums are answered by Context.
1798 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001799 switch (pname)
1800 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001801 case GL_MAX_ELEMENT_INDEX:
1802 *params = mCaps.maxElementIndex;
1803 break;
1804 case GL_MAX_UNIFORM_BLOCK_SIZE:
1805 *params = mCaps.maxUniformBlockSize;
1806 break;
1807 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001808 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001809 break;
1810 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001811 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001812 break;
1813 case GL_MAX_SERVER_WAIT_TIMEOUT:
1814 *params = mCaps.maxServerWaitTimeout;
1815 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001816
Jamie Madill231c7f52017-04-26 13:45:37 -04001817 // GL_EXT_disjoint_timer_query
1818 case GL_TIMESTAMP_EXT:
1819 *params = mImplementation->getTimestamp();
1820 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001821
Jamie Madill231c7f52017-04-26 13:45:37 -04001822 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1823 *params = mCaps.maxShaderStorageBlockSize;
1824 break;
1825 default:
1826 UNREACHABLE();
1827 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001828 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001829}
1830
Geoff Lang70d0f492015-12-10 17:45:46 -05001831void Context::getPointerv(GLenum pname, void **params) const
1832{
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001833 mGLState.getPointerv(this, pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001834}
1835
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001836void Context::getPointervRobustANGLERobust(GLenum pname,
1837 GLsizei bufSize,
1838 GLsizei *length,
1839 void **params)
1840{
1841 UNIMPLEMENTED();
1842}
1843
Martin Radev66fb8202016-07-28 11:45:20 +03001844void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001845{
Shannon Woods53a94a82014-06-24 15:20:36 -04001846 // Queries about context capabilities and maximums are answered by Context.
1847 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001848
1849 GLenum nativeType;
1850 unsigned int numParams;
1851 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1852 ASSERT(queryStatus);
1853
1854 if (nativeType == GL_INT)
1855 {
1856 switch (target)
1857 {
1858 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1859 ASSERT(index < 3u);
1860 *data = mCaps.maxComputeWorkGroupCount[index];
1861 break;
1862 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1863 ASSERT(index < 3u);
1864 *data = mCaps.maxComputeWorkGroupSize[index];
1865 break;
1866 default:
1867 mGLState.getIntegeri_v(target, index, data);
1868 }
1869 }
1870 else
1871 {
1872 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1873 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001874}
1875
Brandon Jones59770802018-04-02 13:18:42 -07001876void Context::getIntegeri_vRobust(GLenum target,
1877 GLuint index,
1878 GLsizei bufSize,
1879 GLsizei *length,
1880 GLint *data)
1881{
1882 getIntegeri_v(target, index, data);
1883}
1884
Martin Radev66fb8202016-07-28 11:45:20 +03001885void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001886{
Shannon Woods53a94a82014-06-24 15:20:36 -04001887 // Queries about context capabilities and maximums are answered by Context.
1888 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001889
1890 GLenum nativeType;
1891 unsigned int numParams;
1892 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1893 ASSERT(queryStatus);
1894
1895 if (nativeType == GL_INT_64_ANGLEX)
1896 {
1897 mGLState.getInteger64i_v(target, index, data);
1898 }
1899 else
1900 {
1901 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1902 }
1903}
1904
Brandon Jones59770802018-04-02 13:18:42 -07001905void Context::getInteger64i_vRobust(GLenum target,
1906 GLuint index,
1907 GLsizei bufSize,
1908 GLsizei *length,
1909 GLint64 *data)
1910{
1911 getInteger64i_v(target, index, data);
1912}
1913
Martin Radev66fb8202016-07-28 11:45:20 +03001914void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1915{
1916 // Queries about context capabilities and maximums are answered by Context.
1917 // Queries about current GL state values are answered by State.
1918
1919 GLenum nativeType;
1920 unsigned int numParams;
1921 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1922 ASSERT(queryStatus);
1923
1924 if (nativeType == GL_BOOL)
1925 {
1926 mGLState.getBooleani_v(target, index, data);
1927 }
1928 else
1929 {
1930 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1931 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001932}
1933
Brandon Jones59770802018-04-02 13:18:42 -07001934void Context::getBooleani_vRobust(GLenum target,
1935 GLuint index,
1936 GLsizei bufSize,
1937 GLsizei *length,
1938 GLboolean *data)
1939{
1940 getBooleani_v(target, index, data);
1941}
1942
Corentin Wallez336129f2017-10-17 15:55:40 -04001943void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001944{
1945 Buffer *buffer = mGLState.getTargetBuffer(target);
1946 QueryBufferParameteriv(buffer, pname, params);
1947}
1948
Brandon Jones59770802018-04-02 13:18:42 -07001949void Context::getBufferParameterivRobust(BufferBinding target,
1950 GLenum pname,
1951 GLsizei bufSize,
1952 GLsizei *length,
1953 GLint *params)
1954{
1955 getBufferParameteriv(target, pname, params);
1956}
1957
He Yunchao010e4db2017-03-03 14:22:06 +08001958void Context::getFramebufferAttachmentParameteriv(GLenum target,
1959 GLenum attachment,
1960 GLenum pname,
1961 GLint *params)
1962{
1963 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08001964 QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08001965}
1966
Brandon Jones59770802018-04-02 13:18:42 -07001967void Context::getFramebufferAttachmentParameterivRobust(GLenum target,
1968 GLenum attachment,
1969 GLenum pname,
1970 GLsizei bufSize,
1971 GLsizei *length,
1972 GLint *params)
1973{
1974 getFramebufferAttachmentParameteriv(target, attachment, pname, params);
1975}
1976
He Yunchao010e4db2017-03-03 14:22:06 +08001977void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
1978{
1979 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
1980 QueryRenderbufferiv(this, renderbuffer, pname, params);
1981}
1982
Brandon Jones59770802018-04-02 13:18:42 -07001983void Context::getRenderbufferParameterivRobust(GLenum target,
1984 GLenum pname,
1985 GLsizei bufSize,
1986 GLsizei *length,
1987 GLint *params)
1988{
1989 getRenderbufferParameteriv(target, pname, params);
1990}
1991
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001992void Context::getTexParameterfv(TextureType target, GLenum pname, GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001993{
1994 Texture *texture = getTargetTexture(target);
1995 QueryTexParameterfv(texture, pname, params);
1996}
1997
Brandon Jones59770802018-04-02 13:18:42 -07001998void Context::getTexParameterfvRobust(TextureType target,
1999 GLenum pname,
2000 GLsizei bufSize,
2001 GLsizei *length,
2002 GLfloat *params)
2003{
2004 getTexParameterfv(target, pname, params);
2005}
2006
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002007void Context::getTexParameteriv(TextureType target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002008{
2009 Texture *texture = getTargetTexture(target);
2010 QueryTexParameteriv(texture, pname, params);
2011}
Jiajia Qin5451d532017-11-16 17:16:34 +08002012
Brandon Jones59770802018-04-02 13:18:42 -07002013void Context::getTexParameterivRobust(TextureType target,
2014 GLenum pname,
2015 GLsizei bufSize,
2016 GLsizei *length,
2017 GLint *params)
2018{
2019 getTexParameteriv(target, pname, params);
2020}
2021
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002022void Context::getTexParameterIivRobust(TextureType target,
2023 GLenum pname,
2024 GLsizei bufSize,
2025 GLsizei *length,
2026 GLint *params)
2027{
2028 UNIMPLEMENTED();
2029}
2030
2031void Context::getTexParameterIuivRobust(TextureType target,
2032 GLenum pname,
2033 GLsizei bufSize,
2034 GLsizei *length,
2035 GLuint *params)
2036{
2037 UNIMPLEMENTED();
2038}
2039
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002040void Context::getTexLevelParameteriv(TextureTarget target, GLint level, GLenum pname, GLint *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002041{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002042 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002043 QueryTexLevelParameteriv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002044}
2045
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002046void Context::getTexLevelParameterivRobust(TextureTarget target,
2047 GLint level,
2048 GLenum pname,
2049 GLsizei bufSize,
2050 GLsizei *length,
2051 GLint *params)
2052{
2053 UNIMPLEMENTED();
2054}
2055
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002056void Context::getTexLevelParameterfv(TextureTarget target,
2057 GLint level,
2058 GLenum pname,
2059 GLfloat *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002060{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002061 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002062 QueryTexLevelParameterfv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002063}
2064
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002065void Context::getTexLevelParameterfvRobust(TextureTarget target,
2066 GLint level,
2067 GLenum pname,
2068 GLsizei bufSize,
2069 GLsizei *length,
2070 GLfloat *params)
2071{
2072 UNIMPLEMENTED();
2073}
2074
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002075void Context::texParameterf(TextureType target, GLenum pname, GLfloat param)
He Yunchao010e4db2017-03-03 14:22:06 +08002076{
2077 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002078 SetTexParameterf(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002079 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002080}
2081
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002082void Context::texParameterfv(TextureType target, GLenum pname, const GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002083{
2084 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002085 SetTexParameterfv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002086 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002087}
2088
Brandon Jones59770802018-04-02 13:18:42 -07002089void Context::texParameterfvRobust(TextureType target,
2090 GLenum pname,
2091 GLsizei bufSize,
2092 const GLfloat *params)
2093{
2094 texParameterfv(target, pname, params);
2095}
2096
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002097void Context::texParameteri(TextureType target, GLenum pname, GLint param)
He Yunchao010e4db2017-03-03 14:22:06 +08002098{
2099 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002100 SetTexParameteri(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002101 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002102}
2103
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002104void Context::texParameteriv(TextureType target, GLenum pname, const GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002105{
2106 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002107 SetTexParameteriv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002108 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002109}
2110
Brandon Jones59770802018-04-02 13:18:42 -07002111void Context::texParameterivRobust(TextureType target,
2112 GLenum pname,
2113 GLsizei bufSize,
2114 const GLint *params)
2115{
2116 texParameteriv(target, pname, params);
2117}
2118
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002119void Context::texParameterIivRobust(TextureType target,
2120 GLenum pname,
2121 GLsizei bufSize,
2122 const GLint *params)
2123{
2124 UNIMPLEMENTED();
2125}
2126
2127void Context::texParameterIuivRobust(TextureType target,
2128 GLenum pname,
2129 GLsizei bufSize,
2130 const GLuint *params)
2131{
2132 UNIMPLEMENTED();
2133}
2134
Jamie Madill493f9572018-05-24 19:52:15 -04002135void Context::drawArrays(PrimitiveMode mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002136{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002137 // No-op if count draws no primitives for given mode
2138 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002139 {
2140 return;
2141 }
2142
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002143 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002144 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
Jamie Madill09463932018-04-04 05:26:59 -04002145 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count, 1);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002146}
2147
Jamie Madill493f9572018-05-24 19:52:15 -04002148void Context::drawArraysInstanced(PrimitiveMode mode,
2149 GLint first,
2150 GLsizei count,
2151 GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04002152{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002153 // No-op if count draws no primitives for given mode
2154 if (noopDrawInstanced(mode, count, instanceCount))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002155 {
2156 return;
2157 }
2158
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002159 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002160 ANGLE_CONTEXT_TRY(
2161 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
Jamie Madill09463932018-04-04 05:26:59 -04002162 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count,
2163 instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -04002164}
2165
Jamie Madill493f9572018-05-24 19:52:15 -04002166void Context::drawElements(PrimitiveMode mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002167{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002168 // No-op if count draws no primitives for given mode
2169 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002170 {
2171 return;
2172 }
2173
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002174 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002175 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04002176}
2177
Jamie Madill493f9572018-05-24 19:52:15 -04002178void Context::drawElementsInstanced(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002179 GLsizei count,
2180 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002181 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04002182 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04002183{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002184 // No-op if count draws no primitives for given mode
2185 if (noopDrawInstanced(mode, count, instances))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002186 {
2187 return;
2188 }
2189
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002190 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002191 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08002192 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04002193}
2194
Jamie Madill493f9572018-05-24 19:52:15 -04002195void Context::drawRangeElements(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002196 GLuint start,
2197 GLuint end,
2198 GLsizei count,
2199 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002200 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04002201{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002202 // No-op if count draws no primitives for given mode
2203 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002204 {
2205 return;
2206 }
2207
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002208 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002209 ANGLE_CONTEXT_TRY(
2210 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002211}
2212
Jamie Madill493f9572018-05-24 19:52:15 -04002213void Context::drawArraysIndirect(PrimitiveMode mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002214{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002215 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002216 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002217}
2218
Jamie Madill493f9572018-05-24 19:52:15 -04002219void Context::drawElementsIndirect(PrimitiveMode mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002220{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002221 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002222 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002223}
2224
Jamie Madill675fe712016-12-19 13:07:54 -05002225void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002226{
Jamie Madillafa02a22017-11-23 12:57:38 -05002227 handleError(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05002228}
2229
Jamie Madill675fe712016-12-19 13:07:54 -05002230void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05002231{
Jamie Madillafa02a22017-11-23 12:57:38 -05002232 handleError(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002233}
2234
Austin Kinross6ee1e782015-05-29 17:05:37 -07002235void Context::insertEventMarker(GLsizei length, const char *marker)
2236{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002237 ASSERT(mImplementation);
2238 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07002239}
2240
2241void Context::pushGroupMarker(GLsizei length, const char *marker)
2242{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002243 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05002244
2245 if (marker == nullptr)
2246 {
2247 // From the EXT_debug_marker spec,
2248 // "If <marker> is null then an empty string is pushed on the stack."
2249 mImplementation->pushGroupMarker(length, "");
2250 }
2251 else
2252 {
2253 mImplementation->pushGroupMarker(length, marker);
2254 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07002255}
2256
2257void Context::popGroupMarker()
2258{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002259 ASSERT(mImplementation);
2260 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07002261}
2262
Geoff Langd8605522016-04-13 10:19:12 -04002263void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
2264{
2265 Program *programObject = getProgram(program);
2266 ASSERT(programObject);
2267
2268 programObject->bindUniformLocation(location, name);
2269}
2270
Brandon Jones59770802018-04-02 13:18:42 -07002271void Context::coverageModulation(GLenum components)
Sami Väisänena797e062016-05-12 15:23:40 +03002272{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002273 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03002274}
2275
Brandon Jones59770802018-04-02 13:18:42 -07002276void Context::matrixLoadf(GLenum matrixMode, const GLfloat *matrix)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002277{
2278 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
2279}
2280
Brandon Jones59770802018-04-02 13:18:42 -07002281void Context::matrixLoadIdentity(GLenum matrixMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002282{
2283 GLfloat I[16];
2284 angle::Matrix<GLfloat>::setToIdentity(I);
2285
2286 mGLState.loadPathRenderingMatrix(matrixMode, I);
2287}
2288
2289void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
2290{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002291 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002292 if (!pathObj)
2293 return;
2294
2295 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002296 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002297
2298 mImplementation->stencilFillPath(pathObj, fillMode, mask);
2299}
2300
2301void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
2302{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002303 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002304 if (!pathObj)
2305 return;
2306
2307 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002308 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002309
2310 mImplementation->stencilStrokePath(pathObj, reference, mask);
2311}
2312
2313void Context::coverFillPath(GLuint path, GLenum coverMode)
2314{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002315 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002316 if (!pathObj)
2317 return;
2318
2319 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002320 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002321
2322 mImplementation->coverFillPath(pathObj, coverMode);
2323}
2324
2325void Context::coverStrokePath(GLuint path, GLenum coverMode)
2326{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002327 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002328 if (!pathObj)
2329 return;
2330
2331 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002332 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002333
2334 mImplementation->coverStrokePath(pathObj, coverMode);
2335}
2336
2337void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
2338{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002339 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002340 if (!pathObj)
2341 return;
2342
2343 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002344 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002345
2346 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
2347}
2348
2349void Context::stencilThenCoverStrokePath(GLuint path,
2350 GLint reference,
2351 GLuint mask,
2352 GLenum coverMode)
2353{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002354 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002355 if (!pathObj)
2356 return;
2357
2358 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002359 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002360
2361 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2362}
2363
Sami Väisänend59ca052016-06-21 16:10:00 +03002364void Context::coverFillPathInstanced(GLsizei numPaths,
2365 GLenum pathNameType,
2366 const void *paths,
2367 GLuint pathBase,
2368 GLenum coverMode,
2369 GLenum transformType,
2370 const GLfloat *transformValues)
2371{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002372 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002373
2374 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002375 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002376
2377 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2378}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002379
Sami Väisänend59ca052016-06-21 16:10:00 +03002380void Context::coverStrokePathInstanced(GLsizei numPaths,
2381 GLenum pathNameType,
2382 const void *paths,
2383 GLuint pathBase,
2384 GLenum coverMode,
2385 GLenum transformType,
2386 const GLfloat *transformValues)
2387{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002388 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002389
2390 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002391 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002392
2393 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2394 transformValues);
2395}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002396
Sami Väisänend59ca052016-06-21 16:10:00 +03002397void Context::stencilFillPathInstanced(GLsizei numPaths,
2398 GLenum pathNameType,
2399 const void *paths,
2400 GLuint pathBase,
2401 GLenum fillMode,
2402 GLuint mask,
2403 GLenum transformType,
2404 const GLfloat *transformValues)
2405{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002406 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002407
2408 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002409 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002410
2411 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2412 transformValues);
2413}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002414
Sami Väisänend59ca052016-06-21 16:10:00 +03002415void Context::stencilStrokePathInstanced(GLsizei numPaths,
2416 GLenum pathNameType,
2417 const void *paths,
2418 GLuint pathBase,
2419 GLint reference,
2420 GLuint mask,
2421 GLenum transformType,
2422 const GLfloat *transformValues)
2423{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002424 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002425
2426 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002427 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002428
2429 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2430 transformValues);
2431}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002432
Sami Väisänend59ca052016-06-21 16:10:00 +03002433void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2434 GLenum pathNameType,
2435 const void *paths,
2436 GLuint pathBase,
2437 GLenum fillMode,
2438 GLuint mask,
2439 GLenum coverMode,
2440 GLenum transformType,
2441 const GLfloat *transformValues)
2442{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002443 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002444
2445 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002446 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002447
2448 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2449 transformType, transformValues);
2450}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002451
Sami Väisänend59ca052016-06-21 16:10:00 +03002452void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2453 GLenum pathNameType,
2454 const void *paths,
2455 GLuint pathBase,
2456 GLint reference,
2457 GLuint mask,
2458 GLenum coverMode,
2459 GLenum transformType,
2460 const GLfloat *transformValues)
2461{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002462 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002463
2464 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002465 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002466
2467 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2468 transformType, transformValues);
2469}
2470
Sami Väisänen46eaa942016-06-29 10:26:37 +03002471void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2472{
2473 auto *programObject = getProgram(program);
2474
2475 programObject->bindFragmentInputLocation(location, name);
2476}
2477
2478void Context::programPathFragmentInputGen(GLuint program,
2479 GLint location,
2480 GLenum genMode,
2481 GLint components,
2482 const GLfloat *coeffs)
2483{
2484 auto *programObject = getProgram(program);
2485
Jamie Madillbd044ed2017-06-05 12:59:21 -04002486 programObject->pathFragmentInputGen(this, location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002487}
2488
jchen1015015f72017-03-16 13:54:21 +08002489GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2490{
jchen10fd7c3b52017-03-21 15:36:03 +08002491 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002492 return QueryProgramResourceIndex(programObject, programInterface, name);
2493}
2494
jchen10fd7c3b52017-03-21 15:36:03 +08002495void Context::getProgramResourceName(GLuint program,
2496 GLenum programInterface,
2497 GLuint index,
2498 GLsizei bufSize,
2499 GLsizei *length,
2500 GLchar *name)
2501{
2502 const auto *programObject = getProgram(program);
2503 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2504}
2505
jchen10191381f2017-04-11 13:59:04 +08002506GLint Context::getProgramResourceLocation(GLuint program,
2507 GLenum programInterface,
2508 const GLchar *name)
2509{
2510 const auto *programObject = getProgram(program);
2511 return QueryProgramResourceLocation(programObject, programInterface, name);
2512}
2513
jchen10880683b2017-04-12 16:21:55 +08002514void Context::getProgramResourceiv(GLuint program,
2515 GLenum programInterface,
2516 GLuint index,
2517 GLsizei propCount,
2518 const GLenum *props,
2519 GLsizei bufSize,
2520 GLsizei *length,
2521 GLint *params)
2522{
2523 const auto *programObject = getProgram(program);
2524 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2525 length, params);
2526}
2527
jchen10d9cd7b72017-08-30 15:04:25 +08002528void Context::getProgramInterfaceiv(GLuint program,
2529 GLenum programInterface,
2530 GLenum pname,
2531 GLint *params)
2532{
2533 const auto *programObject = getProgram(program);
2534 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2535}
2536
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002537void Context::getProgramInterfaceivRobust(GLuint program,
2538 GLenum programInterface,
2539 GLenum pname,
2540 GLsizei bufSize,
2541 GLsizei *length,
2542 GLint *params)
2543{
2544 UNIMPLEMENTED();
2545}
2546
Jamie Madill6b873dd2018-07-12 23:56:30 -04002547void Context::handleError(const Error &error)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002548{
Jamie Madill6b873dd2018-07-12 23:56:30 -04002549 mErrors.handleError(error);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002550}
2551
2552// Get one of the recorded errors and clear its flag, if any.
2553// [OpenGL ES 2.0.24] section 2.5 page 13.
2554GLenum Context::getError()
2555{
Geoff Langda5777c2014-07-11 09:52:58 -04002556 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002557 {
Geoff Langda5777c2014-07-11 09:52:58 -04002558 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002559 }
Geoff Langda5777c2014-07-11 09:52:58 -04002560 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002561 {
Jamie Madill6b873dd2018-07-12 23:56:30 -04002562 return mErrors.popError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002563 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002564}
2565
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002566// NOTE: this function should not assume that this context is current!
Jamie Madill6b873dd2018-07-12 23:56:30 -04002567void Context::markContextLost()
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002568{
2569 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002570 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002571 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002572 mContextLostForced = true;
2573 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002574 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002575}
2576
Jamie Madill427064d2018-04-13 16:20:34 -04002577bool Context::isContextLost() const
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002578{
2579 return mContextLost;
2580}
2581
Jamie Madillfa920eb2018-01-04 11:45:50 -05002582GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002583{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002584 // Even if the application doesn't want to know about resets, we want to know
2585 // as it will allow us to skip all the calls.
2586 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002587 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002588 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002589 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002590 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002591 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002592
2593 // EXT_robustness, section 2.6: If the reset notification behavior is
2594 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2595 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2596 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002597 }
2598
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002599 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2600 // status should be returned at least once, and GL_NO_ERROR should be returned
2601 // once the device has finished resetting.
2602 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002603 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002604 ASSERT(mResetStatus == GL_NO_ERROR);
2605 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002606
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002607 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002608 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002609 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002610 }
2611 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002612 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002613 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002614 // If markContextLost was used to mark the context lost then
2615 // assume that is not recoverable, and continue to report the
2616 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002617 mResetStatus = mImplementation->getResetStatus();
2618 }
Jamie Madill893ab082014-05-16 16:56:10 -04002619
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002620 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002621}
2622
2623bool Context::isResetNotificationEnabled()
2624{
2625 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2626}
2627
Corentin Walleze3b10e82015-05-20 11:06:25 -04002628const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002629{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002630 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002631}
2632
2633EGLenum Context::getClientType() const
2634{
2635 return mClientType;
2636}
2637
2638EGLenum Context::getRenderBuffer() const
2639{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002640 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2641 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002642 {
2643 return EGL_NONE;
2644 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002645
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002646 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002647 ASSERT(backAttachment != nullptr);
2648 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002649}
2650
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002651VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002652{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002653 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002654 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2655 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002656 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002657 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2658 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002659
Jamie Madill96a483b2017-06-27 16:49:21 -04002660 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002661 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002662
2663 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002664}
2665
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002666TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002667{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002668 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002669 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2670 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002671 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002672 transformFeedback =
2673 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002674 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002675 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002676 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002677
2678 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002679}
2680
2681bool Context::isVertexArrayGenerated(GLuint vertexArray)
2682{
Jamie Madill96a483b2017-06-27 16:49:21 -04002683 ASSERT(mVertexArrayMap.contains(0));
2684 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002685}
2686
2687bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2688{
Jamie Madill96a483b2017-06-27 16:49:21 -04002689 ASSERT(mTransformFeedbackMap.contains(0));
2690 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002691}
2692
Shannon Woods53a94a82014-06-24 15:20:36 -04002693void Context::detachTexture(GLuint texture)
2694{
2695 // Simple pass-through to State's detachTexture method, as textures do not require
2696 // allocation map management either here or in the resource manager at detach time.
2697 // Zero textures are held by the Context, and we don't attempt to request them from
2698 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002699 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002700}
2701
James Darpinian4d9d4832018-03-13 12:43:28 -07002702void Context::detachBuffer(Buffer *buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002703{
Yuly Novikov5807a532015-12-03 13:01:22 -05002704 // Simple pass-through to State's detachBuffer method, since
2705 // only buffer attachments to container objects that are bound to the current context
2706 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002707
Yuly Novikov5807a532015-12-03 13:01:22 -05002708 // [OpenGL ES 3.2] section 5.1.2 page 45:
2709 // Attachments to unbound container objects, such as
2710 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2711 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002712 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002713}
2714
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002715void Context::detachFramebuffer(GLuint framebuffer)
2716{
Shannon Woods53a94a82014-06-24 15:20:36 -04002717 // Framebuffer detachment is handled by Context, because 0 is a valid
2718 // Framebuffer object, and a pointer to it must be passed from Context
2719 // to State at binding time.
2720
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002721 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002722 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2723 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2724 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002725
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002726 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002727 {
2728 bindReadFramebuffer(0);
2729 }
2730
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002731 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002732 {
2733 bindDrawFramebuffer(0);
2734 }
2735}
2736
2737void Context::detachRenderbuffer(GLuint renderbuffer)
2738{
Jamie Madilla02315b2017-02-23 14:14:47 -05002739 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002740}
2741
Jamie Madill57a89722013-07-02 11:57:03 -04002742void Context::detachVertexArray(GLuint vertexArray)
2743{
Jamie Madill77a72f62015-04-14 11:18:32 -04002744 // Vertex array detachment is handled by Context, because 0 is a valid
2745 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002746 // binding time.
2747
Jamie Madill57a89722013-07-02 11:57:03 -04002748 // [OpenGL ES 3.0.2] section 2.10 page 43:
2749 // If a vertex array object that is currently bound is deleted, the binding
2750 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madill7267aa62018-04-17 15:28:21 -04002751 if (mGLState.removeVertexArrayBinding(this, vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002752 {
2753 bindVertexArray(0);
2754 }
2755}
2756
Geoff Langc8058452014-02-03 12:04:11 -05002757void Context::detachTransformFeedback(GLuint transformFeedback)
2758{
Corentin Walleza2257da2016-04-19 16:43:12 -04002759 // Transform feedback detachment is handled by Context, because 0 is a valid
2760 // transform feedback, and a pointer to it must be passed from Context to State at
2761 // binding time.
2762
2763 // The OpenGL specification doesn't mention what should happen when the currently bound
2764 // transform feedback object is deleted. Since it is a container object, we treat it like
2765 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002766 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002767 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002768 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002769 }
Geoff Langc8058452014-02-03 12:04:11 -05002770}
2771
Jamie Madilldc356042013-07-19 16:36:57 -04002772void Context::detachSampler(GLuint sampler)
2773{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002774 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002775}
2776
Yunchao Hea336b902017-08-02 16:05:21 +08002777void Context::detachProgramPipeline(GLuint pipeline)
2778{
2779 mGLState.detachProgramPipeline(this, pipeline);
2780}
2781
Jamie Madill3ef140a2017-08-26 23:11:21 -04002782void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002783{
Shaodde78e82017-05-22 14:13:27 +08002784 mGLState.setVertexAttribDivisor(this, index, divisor);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002785}
2786
Jamie Madille29d1672013-07-19 16:36:57 -04002787void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2788{
Geoff Langc1984ed2016-10-07 12:41:00 -04002789 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002790 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002791 SetSamplerParameteri(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002792 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002793}
Jamie Madille29d1672013-07-19 16:36:57 -04002794
Geoff Langc1984ed2016-10-07 12:41:00 -04002795void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2796{
2797 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002798 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002799 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002800 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002801}
2802
Brandon Jones59770802018-04-02 13:18:42 -07002803void Context::samplerParameterivRobust(GLuint sampler,
2804 GLenum pname,
2805 GLsizei bufSize,
2806 const GLint *param)
2807{
2808 samplerParameteriv(sampler, pname, param);
2809}
2810
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002811void Context::samplerParameterIivRobust(GLuint sampler,
2812 GLenum pname,
2813 GLsizei bufSize,
2814 const GLint *param)
2815{
2816 UNIMPLEMENTED();
2817}
2818
2819void Context::samplerParameterIuivRobust(GLuint sampler,
2820 GLenum pname,
2821 GLsizei bufSize,
2822 const GLuint *param)
2823{
2824 UNIMPLEMENTED();
2825}
2826
Jamie Madille29d1672013-07-19 16:36:57 -04002827void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2828{
Geoff Langc1984ed2016-10-07 12:41:00 -04002829 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002830 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002831 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002832 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002833}
2834
Geoff Langc1984ed2016-10-07 12:41:00 -04002835void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002836{
Geoff Langc1984ed2016-10-07 12:41:00 -04002837 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002838 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002839 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002840 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002841}
2842
Brandon Jones59770802018-04-02 13:18:42 -07002843void Context::samplerParameterfvRobust(GLuint sampler,
2844 GLenum pname,
2845 GLsizei bufSize,
2846 const GLfloat *param)
2847{
2848 samplerParameterfv(sampler, pname, param);
2849}
2850
Geoff Langc1984ed2016-10-07 12:41:00 -04002851void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002852{
Geoff Langc1984ed2016-10-07 12:41:00 -04002853 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002854 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002855 QuerySamplerParameteriv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002856 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002857}
Jamie Madill9675b802013-07-19 16:36:59 -04002858
Brandon Jones59770802018-04-02 13:18:42 -07002859void Context::getSamplerParameterivRobust(GLuint sampler,
2860 GLenum pname,
2861 GLsizei bufSize,
2862 GLsizei *length,
2863 GLint *params)
2864{
2865 getSamplerParameteriv(sampler, pname, params);
2866}
2867
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002868void Context::getSamplerParameterIivRobust(GLuint sampler,
2869 GLenum pname,
2870 GLsizei bufSize,
2871 GLsizei *length,
2872 GLint *params)
2873{
2874 UNIMPLEMENTED();
2875}
2876
2877void Context::getSamplerParameterIuivRobust(GLuint sampler,
2878 GLenum pname,
2879 GLsizei bufSize,
2880 GLsizei *length,
2881 GLuint *params)
2882{
2883 UNIMPLEMENTED();
2884}
2885
Geoff Langc1984ed2016-10-07 12:41:00 -04002886void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2887{
2888 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002889 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002890 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002891 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002892}
2893
Brandon Jones59770802018-04-02 13:18:42 -07002894void Context::getSamplerParameterfvRobust(GLuint sampler,
2895 GLenum pname,
2896 GLsizei bufSize,
2897 GLsizei *length,
2898 GLfloat *params)
2899{
2900 getSamplerParameterfv(sampler, pname, params);
2901}
2902
Olli Etuahof0fee072016-03-30 15:11:58 +03002903void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2904{
2905 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002906 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002907}
2908
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002909void Context::initRendererString()
2910{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002911 std::ostringstream rendererString;
2912 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002913 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002914 rendererString << ")";
2915
Geoff Langcec35902014-04-16 10:52:36 -04002916 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002917}
2918
Geoff Langc339c4e2016-11-29 10:37:36 -05002919void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002920{
Geoff Langc339c4e2016-11-29 10:37:36 -05002921 const Version &clientVersion = getClientVersion();
2922
2923 std::ostringstream versionString;
2924 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2925 << ANGLE_VERSION_STRING << ")";
2926 mVersionString = MakeStaticString(versionString.str());
2927
2928 std::ostringstream shadingLanguageVersionString;
2929 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2930 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2931 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2932 << ")";
2933 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002934}
2935
Geoff Langcec35902014-04-16 10:52:36 -04002936void Context::initExtensionStrings()
2937{
Geoff Langc339c4e2016-11-29 10:37:36 -05002938 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2939 std::ostringstream combinedStringStream;
2940 std::copy(strings.begin(), strings.end(),
2941 std::ostream_iterator<const char *>(combinedStringStream, " "));
2942 return MakeStaticString(combinedStringStream.str());
2943 };
2944
2945 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002946 for (const auto &extensionString : mExtensions.getStrings())
2947 {
2948 mExtensionStrings.push_back(MakeStaticString(extensionString));
2949 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002950 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002951
Geoff Langc339c4e2016-11-29 10:37:36 -05002952 mRequestableExtensionStrings.clear();
2953 for (const auto &extensionInfo : GetExtensionInfoMap())
2954 {
2955 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08002956 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
Geoff Langb0f917f2017-12-05 13:41:54 -05002957 mSupportedExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002958 {
2959 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
2960 }
2961 }
2962 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002963}
2964
Geoff Langc339c4e2016-11-29 10:37:36 -05002965const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04002966{
Geoff Langc339c4e2016-11-29 10:37:36 -05002967 switch (name)
2968 {
2969 case GL_VENDOR:
2970 return reinterpret_cast<const GLubyte *>("Google Inc.");
2971
2972 case GL_RENDERER:
2973 return reinterpret_cast<const GLubyte *>(mRendererString);
2974
2975 case GL_VERSION:
2976 return reinterpret_cast<const GLubyte *>(mVersionString);
2977
2978 case GL_SHADING_LANGUAGE_VERSION:
2979 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
2980
2981 case GL_EXTENSIONS:
2982 return reinterpret_cast<const GLubyte *>(mExtensionString);
2983
2984 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2985 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
2986
2987 default:
2988 UNREACHABLE();
2989 return nullptr;
2990 }
Geoff Langcec35902014-04-16 10:52:36 -04002991}
2992
Geoff Langc339c4e2016-11-29 10:37:36 -05002993const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04002994{
Geoff Langc339c4e2016-11-29 10:37:36 -05002995 switch (name)
2996 {
2997 case GL_EXTENSIONS:
2998 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
2999
3000 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
3001 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
3002
3003 default:
3004 UNREACHABLE();
3005 return nullptr;
3006 }
Geoff Langcec35902014-04-16 10:52:36 -04003007}
3008
3009size_t Context::getExtensionStringCount() const
3010{
3011 return mExtensionStrings.size();
3012}
3013
Geoff Lang111a99e2017-10-17 10:58:41 -04003014bool Context::isExtensionRequestable(const char *name)
3015{
3016 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3017 auto extension = extensionInfos.find(name);
3018
Geoff Lang111a99e2017-10-17 10:58:41 -04003019 return extension != extensionInfos.end() && extension->second.Requestable &&
Geoff Langb0f917f2017-12-05 13:41:54 -05003020 mSupportedExtensions.*(extension->second.ExtensionsMember);
Geoff Lang111a99e2017-10-17 10:58:41 -04003021}
3022
Geoff Langc339c4e2016-11-29 10:37:36 -05003023void Context::requestExtension(const char *name)
3024{
3025 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3026 ASSERT(extensionInfos.find(name) != extensionInfos.end());
3027 const auto &extension = extensionInfos.at(name);
3028 ASSERT(extension.Requestable);
Geoff Langb0f917f2017-12-05 13:41:54 -05003029 ASSERT(isExtensionRequestable(name));
Geoff Langc339c4e2016-11-29 10:37:36 -05003030
3031 if (mExtensions.*(extension.ExtensionsMember))
3032 {
3033 // Extension already enabled
3034 return;
3035 }
3036
3037 mExtensions.*(extension.ExtensionsMember) = true;
3038 updateCaps();
3039 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08003040
Jamie Madill2f348d22017-06-05 10:50:59 -04003041 // Release the shader compiler so it will be re-created with the requested extensions enabled.
3042 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04003043
Jamie Madill81c2e252017-09-09 23:32:46 -04003044 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
3045 // sampleable.
Jamie Madilld4442552018-02-27 22:03:47 -05003046 mState.mTextures->signalAllTexturesDirty(this);
Geoff Lang9aded172017-04-05 11:07:56 -04003047 for (auto &zeroTexture : mZeroTextures)
3048 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003049 if (zeroTexture.get() != nullptr)
3050 {
3051 zeroTexture->signalDirty(this, InitState::Initialized);
3052 }
Geoff Lang9aded172017-04-05 11:07:56 -04003053 }
3054
3055 mState.mFramebuffers->invalidateFramebufferComplenessCache();
Geoff Langc339c4e2016-11-29 10:37:36 -05003056}
3057
3058size_t Context::getRequestableExtensionStringCount() const
3059{
3060 return mRequestableExtensionStrings.size();
3061}
3062
Jamie Madill493f9572018-05-24 19:52:15 -04003063void Context::beginTransformFeedback(PrimitiveMode primitiveMode)
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003064{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003065 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003066 ASSERT(transformFeedback != nullptr);
3067 ASSERT(!transformFeedback->isPaused());
3068
Jamie Madill6c1f6712017-02-14 19:08:04 -05003069 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003070}
3071
3072bool Context::hasActiveTransformFeedback(GLuint program) const
3073{
3074 for (auto pair : mTransformFeedbackMap)
3075 {
3076 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
3077 {
3078 return true;
3079 }
3080 }
3081 return false;
3082}
3083
Geoff Lang33f11fb2018-05-07 13:42:47 -04003084Extensions Context::generateSupportedExtensions() const
Geoff Langb0f917f2017-12-05 13:41:54 -05003085{
3086 Extensions supportedExtensions = mImplementation->getNativeExtensions();
3087
jchen1082af6202018-06-22 10:59:52 +08003088 // Explicitly enable GL_KHR_parallel_shader_compile
3089 supportedExtensions.parallelShaderCompile = true;
3090
Geoff Langb0f917f2017-12-05 13:41:54 -05003091 if (getClientVersion() < ES_2_0)
3092 {
3093 // Default extensions for GLES1
Lingfeng Yang0df813c2018-07-12 12:52:06 -07003094 supportedExtensions.pointSizeArray = true;
3095 supportedExtensions.textureCubeMap = true;
3096 supportedExtensions.pointSprite = true;
3097 supportedExtensions.drawTexture = true;
jchen1082af6202018-06-22 10:59:52 +08003098 supportedExtensions.parallelShaderCompile = false;
Geoff Langb0f917f2017-12-05 13:41:54 -05003099 }
3100
3101 if (getClientVersion() < ES_3_0)
3102 {
3103 // Disable ES3+ extensions
3104 supportedExtensions.colorBufferFloat = false;
3105 supportedExtensions.eglImageExternalEssl3 = false;
3106 supportedExtensions.textureNorm16 = false;
3107 supportedExtensions.multiview = false;
3108 supportedExtensions.maxViews = 1u;
3109 }
3110
3111 if (getClientVersion() < ES_3_1)
3112 {
3113 // Disable ES3.1+ extensions
3114 supportedExtensions.geometryShader = false;
3115 }
3116
3117 if (getClientVersion() > ES_2_0)
3118 {
3119 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
3120 // supportedExtensions.sRGB = false;
3121 }
3122
3123 // Some extensions are always available because they are implemented in the GL layer.
3124 supportedExtensions.bindUniformLocation = true;
3125 supportedExtensions.vertexArrayObject = true;
3126 supportedExtensions.bindGeneratesResource = true;
3127 supportedExtensions.clientArrays = true;
3128 supportedExtensions.requestExtension = true;
3129
3130 // Enable the no error extension if the context was created with the flag.
3131 supportedExtensions.noError = mSkipValidation;
3132
3133 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Geoff Lang33f11fb2018-05-07 13:42:47 -04003134 supportedExtensions.surfacelessContext = mSurfacelessSupported;
Geoff Langb0f917f2017-12-05 13:41:54 -05003135
3136 // Explicitly enable GL_KHR_debug
3137 supportedExtensions.debug = true;
3138 supportedExtensions.maxDebugMessageLength = 1024;
3139 supportedExtensions.maxDebugLoggedMessages = 1024;
3140 supportedExtensions.maxDebugGroupStackDepth = 1024;
3141 supportedExtensions.maxLabelLength = 1024;
3142
3143 // Explicitly enable GL_ANGLE_robust_client_memory
3144 supportedExtensions.robustClientMemory = true;
3145
3146 // Determine robust resource init availability from EGL.
Geoff Lang33f11fb2018-05-07 13:42:47 -04003147 supportedExtensions.robustResourceInitialization = mGLState.isRobustResourceInitEnabled();
Geoff Langb0f917f2017-12-05 13:41:54 -05003148
3149 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
3150 // supports it.
3151 supportedExtensions.robustBufferAccessBehavior =
3152 mRobustAccess && supportedExtensions.robustBufferAccessBehavior;
3153
3154 // Enable the cache control query unconditionally.
3155 supportedExtensions.programCacheControl = true;
3156
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003157 // Enable EGL_ANGLE_explicit_context subextensions
Geoff Lang33f11fb2018-05-07 13:42:47 -04003158 if (mExplicitContextAvailable)
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003159 {
3160 // GL_ANGLE_explicit_context_gles1
3161 supportedExtensions.explicitContextGles1 = true;
3162 // GL_ANGLE_explicit_context
3163 supportedExtensions.explicitContext = true;
3164 }
3165
Geoff Langb0f917f2017-12-05 13:41:54 -05003166 return supportedExtensions;
3167}
3168
Geoff Lang33f11fb2018-05-07 13:42:47 -04003169void Context::initCaps()
Geoff Lang493daf52014-07-03 13:38:44 -04003170{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04003171 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04003172
Geoff Lang33f11fb2018-05-07 13:42:47 -04003173 mSupportedExtensions = generateSupportedExtensions();
3174 mExtensions = mSupportedExtensions;
Lingfeng Yang01074432018-04-16 10:19:51 -07003175
3176 mLimitations = mImplementation->getNativeLimitations();
3177
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003178 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
3179 if (getClientVersion() < Version(2, 0))
3180 {
3181 mCaps.maxMultitextureUnits = 4;
3182 mCaps.maxClipPlanes = 6;
3183 mCaps.maxLights = 8;
Lingfeng Yange547aac2018-04-05 09:39:20 -07003184 mCaps.maxModelviewMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3185 mCaps.maxProjectionMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3186 mCaps.maxTextureMatrixStackDepth = Caps::GlobalMatrixStackDepth;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003187 mCaps.minSmoothPointSize = 1.0f;
3188 mCaps.maxSmoothPointSize = 1.0f;
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003189 }
3190
Luc Ferronad2ae932018-06-11 15:31:17 -04003191 // Apply/Verify implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04003192 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003193
Luc Ferronad2ae932018-06-11 15:31:17 -04003194 ASSERT(mCaps.minAliasedPointSize >= 1.0f);
3195
Jamie Madill0f80ed82017-09-19 00:24:56 -04003196 if (getClientVersion() < ES_3_1)
3197 {
3198 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
3199 }
3200 else
3201 {
3202 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
3203 }
Geoff Lang301d1612014-07-09 10:34:37 -04003204
Jiawei Shao54aafe52018-04-27 14:54:57 +08003205 LimitCap(&mCaps.maxShaderUniformBlocks[ShaderType::Vertex],
3206 IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
Jamie Madill0f80ed82017-09-19 00:24:56 -04003207 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3208 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3209
3210 // Limit textures as well, so we can use fast bitsets with texture bindings.
3211 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
Jiawei Shao54aafe52018-04-27 14:54:57 +08003212 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Vertex],
3213 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
3214 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Fragment],
3215 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04003216
Jiawei Shaodb342272017-09-27 10:21:45 +08003217 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
3218
Geoff Langc287ea62016-09-16 14:46:51 -04003219 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05003220 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04003221 for (const auto &extensionInfo : GetExtensionInfoMap())
3222 {
Geoff Lang0ab41fa2018-03-14 11:03:30 -04003223 // If the user has requested that extensions start disabled and they are requestable,
3224 // disable them.
3225 if (!mExtensionsEnabled && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04003226 {
3227 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
3228 }
3229 }
3230
3231 // Generate texture caps
3232 updateCaps();
3233}
3234
3235void Context::updateCaps()
3236{
Geoff Lang900013c2014-07-07 11:32:19 -04003237 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04003238 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04003239
Jamie Madill7b62cf92017-11-02 15:20:49 -04003240 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04003241 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04003242 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04003243 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003244
Geoff Lang0d8b7242015-09-09 14:56:53 -04003245 // Update the format caps based on the client version and extensions.
3246 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
3247 // ES3.
3248 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003249 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04003250 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003251 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Yuly Novikovf15f8862018-06-04 18:59:41 -04003252 formatCaps.textureAttachment =
3253 formatCaps.textureAttachment &&
3254 formatInfo.textureAttachmentSupport(getClientVersion(), mExtensions);
3255 formatCaps.renderbuffer = formatCaps.renderbuffer &&
3256 formatInfo.renderbufferSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04003257
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003258 // OpenGL ES does not support multisampling with non-rendererable formats
3259 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Yuly Novikovf15f8862018-06-04 18:59:41 -04003260 if (!formatCaps.renderbuffer ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003261 (getClientVersion() < ES_3_1 &&
3262 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04003263 {
Geoff Langd87878e2014-09-19 15:42:59 -04003264 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04003265 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03003266 else
3267 {
3268 // We may have limited the max samples for some required renderbuffer formats due to
3269 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
3270 GLuint formatMaxSamples = formatCaps.getMaxSamples();
3271
3272 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
3273 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
3274 // exception of signed and unsigned integer formats."
3275 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
3276 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
3277 {
3278 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
3279 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
3280 }
3281
3282 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
3283 if (getClientVersion() >= ES_3_1)
3284 {
3285 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
3286 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
3287 // the exception that the signed and unsigned integer formats are required only to
3288 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
3289 // multisamples, which must be at least one."
3290 if (formatInfo.componentType == GL_INT ||
3291 formatInfo.componentType == GL_UNSIGNED_INT)
3292 {
3293 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
3294 }
3295
3296 // GLES 3.1 section 19.3.1.
3297 if (formatCaps.texturable)
3298 {
3299 if (formatInfo.depthBits > 0)
3300 {
3301 mCaps.maxDepthTextureSamples =
3302 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
3303 }
3304 else if (formatInfo.redBits > 0)
3305 {
3306 mCaps.maxColorTextureSamples =
3307 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
3308 }
3309 }
3310 }
3311 }
Geoff Langd87878e2014-09-19 15:42:59 -04003312
3313 if (formatCaps.texturable && formatInfo.compressed)
3314 {
Geoff Langca271392017-04-05 12:30:00 -04003315 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003316 }
3317
Geoff Langca271392017-04-05 12:30:00 -04003318 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04003319 }
Jamie Madill32447362017-06-28 14:53:52 -04003320
3321 // If program binary is disabled, blank out the memory cache pointer.
Geoff Langb0f917f2017-12-05 13:41:54 -05003322 if (!mSupportedExtensions.getProgramBinary)
Jamie Madill32447362017-06-28 14:53:52 -04003323 {
3324 mMemoryProgramCache = nullptr;
3325 }
Corentin Walleze4477002017-12-01 14:39:58 -05003326
3327 // Compute which buffer types are allowed
3328 mValidBufferBindings.reset();
3329 mValidBufferBindings.set(BufferBinding::ElementArray);
3330 mValidBufferBindings.set(BufferBinding::Array);
3331
3332 if (mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
3333 {
3334 mValidBufferBindings.set(BufferBinding::PixelPack);
3335 mValidBufferBindings.set(BufferBinding::PixelUnpack);
3336 }
3337
3338 if (getClientVersion() >= ES_3_0)
3339 {
3340 mValidBufferBindings.set(BufferBinding::CopyRead);
3341 mValidBufferBindings.set(BufferBinding::CopyWrite);
3342 mValidBufferBindings.set(BufferBinding::TransformFeedback);
3343 mValidBufferBindings.set(BufferBinding::Uniform);
3344 }
3345
3346 if (getClientVersion() >= ES_3_1)
3347 {
3348 mValidBufferBindings.set(BufferBinding::AtomicCounter);
3349 mValidBufferBindings.set(BufferBinding::ShaderStorage);
3350 mValidBufferBindings.set(BufferBinding::DrawIndirect);
3351 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
3352 }
Geoff Lang493daf52014-07-03 13:38:44 -04003353}
3354
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003355void Context::initWorkarounds()
3356{
Jamie Madill761b02c2017-06-23 16:27:06 -04003357 // Apply back-end workarounds.
3358 mImplementation->applyNativeWorkarounds(&mWorkarounds);
3359
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003360 // Lose the context upon out of memory error if the application is
3361 // expecting to watch for those events.
3362 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
3363}
3364
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06003365// Return true if the draw is a no-op, else return false.
3366// A no-op draw occurs if the count of vertices is less than the minimum required to
3367// have a valid primitive for this mode (0 for points, 0-1 for lines, 0-2 for tris).
3368bool Context::noopDraw(PrimitiveMode mode, GLsizei count)
3369{
3370 return count < kMinimumPrimitiveCounts[mode];
3371}
3372
3373bool Context::noopDrawInstanced(PrimitiveMode mode, GLsizei count, GLsizei instanceCount)
3374{
3375 return (instanceCount == 0) || noopDraw(mode, count);
3376}
3377
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003378Error Context::prepareForDraw(PrimitiveMode mode)
Jamie Madill05b35b22017-10-03 09:01:44 -04003379{
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003380 if (mGLES1Renderer)
3381 {
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003382 ANGLE_TRY(mGLES1Renderer->prepareForDraw(mode, this, &mGLState));
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003383 }
3384
Geoff Langa8cb2872018-03-09 16:09:40 -05003385 ANGLE_TRY(syncDirtyObjects());
Jamie Madilla59fc192017-11-02 12:57:58 -04003386
3387 if (isRobustResourceInitEnabled())
3388 {
3389 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
3390 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
3391 }
3392
Geoff Langa8cb2872018-03-09 16:09:40 -05003393 ANGLE_TRY(syncDirtyBits());
Geoff Langd4fff502017-09-22 11:28:28 -04003394 return NoError();
3395}
3396
3397Error Context::prepareForClear(GLbitfield mask)
3398{
Geoff Langa8cb2872018-03-09 16:09:40 -05003399 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003400 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearAttachmentsInitialized(this, mask));
Geoff Langa8cb2872018-03-09 16:09:40 -05003401 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04003402 return NoError();
3403}
3404
3405Error Context::prepareForClearBuffer(GLenum buffer, GLint drawbuffer)
3406{
Geoff Langa8cb2872018-03-09 16:09:40 -05003407 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003408 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearBufferAttachmentsInitialized(this, buffer,
3409 drawbuffer));
Geoff Langa8cb2872018-03-09 16:09:40 -05003410 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill05b35b22017-10-03 09:01:44 -04003411 return NoError();
3412}
3413
Geoff Langa8cb2872018-03-09 16:09:40 -05003414Error Context::syncState()
Jamie Madill1b94d432015-08-07 13:23:23 -04003415{
Geoff Langa8cb2872018-03-09 16:09:40 -05003416 ANGLE_TRY(syncDirtyObjects());
3417 ANGLE_TRY(syncDirtyBits());
Jamie Madillbc918e72018-03-08 09:47:21 -05003418 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003419}
3420
Geoff Langa8cb2872018-03-09 16:09:40 -05003421Error Context::syncState(const State::DirtyBits &bitMask, const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04003422{
Geoff Langa8cb2872018-03-09 16:09:40 -05003423 ANGLE_TRY(syncDirtyObjects(objectMask));
3424 ANGLE_TRY(syncDirtyBits(bitMask));
Geoff Langd4fff502017-09-22 11:28:28 -04003425 return NoError();
3426}
3427
Geoff Langa8cb2872018-03-09 16:09:40 -05003428Error Context::syncDirtyBits()
Geoff Langd4fff502017-09-22 11:28:28 -04003429{
3430 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
Jamie Madill189ad872018-07-09 13:32:37 -04003431 ANGLE_TRY(mImplementation->syncState(this, dirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04003432 mGLState.clearDirtyBits();
3433 return NoError();
3434}
3435
Geoff Langa8cb2872018-03-09 16:09:40 -05003436Error Context::syncDirtyBits(const State::DirtyBits &bitMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003437{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003438 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madill189ad872018-07-09 13:32:37 -04003439 ANGLE_TRY(mImplementation->syncState(this, dirtyBits));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003440 mGLState.clearDirtyBits(dirtyBits);
Jamie Madillbc918e72018-03-08 09:47:21 -05003441 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003442}
Jamie Madillc29968b2016-01-20 11:17:23 -05003443
Geoff Langa8cb2872018-03-09 16:09:40 -05003444Error Context::syncDirtyObjects()
Geoff Langd4fff502017-09-22 11:28:28 -04003445{
3446 return mGLState.syncDirtyObjects(this);
3447}
3448
Geoff Langa8cb2872018-03-09 16:09:40 -05003449Error Context::syncDirtyObjects(const State::DirtyObjects &objectMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003450{
3451 return mGLState.syncDirtyObjects(this, objectMask);
3452}
3453
Jamie Madillc29968b2016-01-20 11:17:23 -05003454void Context::blitFramebuffer(GLint srcX0,
3455 GLint srcY0,
3456 GLint srcX1,
3457 GLint srcY1,
3458 GLint dstX0,
3459 GLint dstY0,
3460 GLint dstX1,
3461 GLint dstY1,
3462 GLbitfield mask,
3463 GLenum filter)
3464{
Qin Jiajiaaef92162018-02-27 13:51:44 +08003465 if (mask == 0)
3466 {
3467 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
3468 // buffers are copied.
3469 return;
3470 }
3471
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003472 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003473 ASSERT(drawFramebuffer);
3474
3475 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
3476 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
3477
Jamie Madillbc918e72018-03-08 09:47:21 -05003478 ANGLE_CONTEXT_TRY(syncStateForBlit());
Jamie Madillc29968b2016-01-20 11:17:23 -05003479
Jamie Madillc564c072017-06-01 12:45:42 -04003480 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003481}
Jamie Madillc29968b2016-01-20 11:17:23 -05003482
3483void Context::clear(GLbitfield mask)
3484{
Geoff Langd4fff502017-09-22 11:28:28 -04003485 ANGLE_CONTEXT_TRY(prepareForClear(mask));
3486 ANGLE_CONTEXT_TRY(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05003487}
3488
3489void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
3490{
Geoff Langd4fff502017-09-22 11:28:28 -04003491 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3492 ANGLE_CONTEXT_TRY(
3493 mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003494}
3495
3496void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3497{
Geoff Langd4fff502017-09-22 11:28:28 -04003498 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3499 ANGLE_CONTEXT_TRY(
3500 mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003501}
3502
3503void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3504{
Geoff Langd4fff502017-09-22 11:28:28 -04003505 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3506 ANGLE_CONTEXT_TRY(
3507 mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003508}
3509
3510void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3511{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003512 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003513 ASSERT(framebufferObject);
3514
3515 // If a buffer is not present, the clear has no effect
3516 if (framebufferObject->getDepthbuffer() == nullptr &&
3517 framebufferObject->getStencilbuffer() == nullptr)
3518 {
3519 return;
3520 }
3521
Geoff Langd4fff502017-09-22 11:28:28 -04003522 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3523 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003524}
3525
3526void Context::readPixels(GLint x,
3527 GLint y,
3528 GLsizei width,
3529 GLsizei height,
3530 GLenum format,
3531 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003532 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003533{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003534 if (width == 0 || height == 0)
3535 {
3536 return;
3537 }
3538
Jamie Madillbc918e72018-03-08 09:47:21 -05003539 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003540
Jamie Madillb6664922017-07-25 12:55:04 -04003541 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3542 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003543
3544 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04003545 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003546}
3547
Brandon Jones59770802018-04-02 13:18:42 -07003548void Context::readPixelsRobust(GLint x,
3549 GLint y,
3550 GLsizei width,
3551 GLsizei height,
3552 GLenum format,
3553 GLenum type,
3554 GLsizei bufSize,
3555 GLsizei *length,
3556 GLsizei *columns,
3557 GLsizei *rows,
3558 void *pixels)
3559{
3560 readPixels(x, y, width, height, format, type, pixels);
3561}
3562
3563void Context::readnPixelsRobust(GLint x,
3564 GLint y,
3565 GLsizei width,
3566 GLsizei height,
3567 GLenum format,
3568 GLenum type,
3569 GLsizei bufSize,
3570 GLsizei *length,
3571 GLsizei *columns,
3572 GLsizei *rows,
3573 void *data)
3574{
3575 readPixels(x, y, width, height, format, type, data);
3576}
3577
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003578void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003579 GLint level,
3580 GLenum internalformat,
3581 GLint x,
3582 GLint y,
3583 GLsizei width,
3584 GLsizei height,
3585 GLint border)
3586{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003587 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003588 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003589
Jamie Madillc29968b2016-01-20 11:17:23 -05003590 Rectangle sourceArea(x, y, width, height);
3591
Jamie Madill05b35b22017-10-03 09:01:44 -04003592 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003593 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003594 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003595}
3596
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003597void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003598 GLint level,
3599 GLint xoffset,
3600 GLint yoffset,
3601 GLint x,
3602 GLint y,
3603 GLsizei width,
3604 GLsizei height)
3605{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003606 if (width == 0 || height == 0)
3607 {
3608 return;
3609 }
3610
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003611 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003612 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003613
Jamie Madillc29968b2016-01-20 11:17:23 -05003614 Offset destOffset(xoffset, yoffset, 0);
3615 Rectangle sourceArea(x, y, width, height);
3616
Jamie Madill05b35b22017-10-03 09:01:44 -04003617 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003618 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003619 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003620}
3621
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003622void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003623 GLint level,
3624 GLint xoffset,
3625 GLint yoffset,
3626 GLint zoffset,
3627 GLint x,
3628 GLint y,
3629 GLsizei width,
3630 GLsizei height)
3631{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003632 if (width == 0 || height == 0)
3633 {
3634 return;
3635 }
3636
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003637 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003638 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003639
Jamie Madillc29968b2016-01-20 11:17:23 -05003640 Offset destOffset(xoffset, yoffset, zoffset);
3641 Rectangle sourceArea(x, y, width, height);
3642
Jamie Madill05b35b22017-10-03 09:01:44 -04003643 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3644 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003645 handleError(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level, destOffset,
3646 sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003647}
3648
3649void Context::framebufferTexture2D(GLenum target,
3650 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003651 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003652 GLuint texture,
3653 GLint level)
3654{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003655 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003656 ASSERT(framebuffer);
3657
3658 if (texture != 0)
3659 {
3660 Texture *textureObj = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003661 ImageIndex index = ImageIndex::MakeFromTarget(textarget, level);
Jamie Madilla02315b2017-02-23 14:14:47 -05003662 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003663 }
3664 else
3665 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003666 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003667 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003668
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003669 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003670}
3671
3672void Context::framebufferRenderbuffer(GLenum target,
3673 GLenum attachment,
3674 GLenum renderbuffertarget,
3675 GLuint renderbuffer)
3676{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003677 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003678 ASSERT(framebuffer);
3679
3680 if (renderbuffer != 0)
3681 {
3682 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003683
Jamie Madillcc129372018-04-12 09:13:18 -04003684 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003685 renderbufferObject);
3686 }
3687 else
3688 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003689 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003690 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003691
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003692 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003693}
3694
3695void Context::framebufferTextureLayer(GLenum target,
3696 GLenum attachment,
3697 GLuint texture,
3698 GLint level,
3699 GLint layer)
3700{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003701 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003702 ASSERT(framebuffer);
3703
3704 if (texture != 0)
3705 {
3706 Texture *textureObject = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003707 ImageIndex index = ImageIndex::MakeFromType(textureObject->getType(), level, layer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003708 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003709 }
3710 else
3711 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003712 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003713 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003714
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003715 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003716}
3717
Brandon Jones59770802018-04-02 13:18:42 -07003718void Context::framebufferTextureMultiviewLayered(GLenum target,
3719 GLenum attachment,
3720 GLuint texture,
3721 GLint level,
3722 GLint baseViewIndex,
3723 GLsizei numViews)
Martin Radev137032d2017-07-13 10:11:12 +03003724{
Martin Radev82ef7742017-08-08 17:44:58 +03003725 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3726 ASSERT(framebuffer);
3727
3728 if (texture != 0)
3729 {
3730 Texture *textureObj = getTexture(texture);
3731
Martin Radev18b75ba2017-08-15 15:50:40 +03003732 ImageIndex index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
Martin Radev82ef7742017-08-08 17:44:58 +03003733 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3734 numViews, baseViewIndex);
3735 }
3736 else
3737 {
3738 framebuffer->resetAttachment(this, attachment);
3739 }
3740
3741 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003742}
3743
Brandon Jones59770802018-04-02 13:18:42 -07003744void Context::framebufferTextureMultiviewSideBySide(GLenum target,
3745 GLenum attachment,
3746 GLuint texture,
3747 GLint level,
3748 GLsizei numViews,
3749 const GLint *viewportOffsets)
Martin Radev137032d2017-07-13 10:11:12 +03003750{
Martin Radev5dae57b2017-07-14 16:15:55 +03003751 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3752 ASSERT(framebuffer);
3753
3754 if (texture != 0)
3755 {
3756 Texture *textureObj = getTexture(texture);
3757
3758 ImageIndex index = ImageIndex::Make2D(level);
3759 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3760 textureObj, numViews, viewportOffsets);
3761 }
3762 else
3763 {
3764 framebuffer->resetAttachment(this, attachment);
3765 }
3766
3767 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003768}
3769
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003770void Context::framebufferTexture(GLenum target, GLenum attachment, GLuint texture, GLint level)
3771{
Jiawei Shaoa8802472018-05-28 11:17:47 +08003772 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3773 ASSERT(framebuffer);
3774
3775 if (texture != 0)
3776 {
3777 Texture *textureObj = getTexture(texture);
3778
3779 ImageIndex index = ImageIndex::MakeFromType(
3780 textureObj->getType(), level, ImageIndex::kEntireLevel, ImageIndex::kEntireLevel);
3781 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
3782 }
3783 else
3784 {
3785 framebuffer->resetAttachment(this, attachment);
3786 }
3787
3788 mGLState.setObjectDirty(target);
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003789}
3790
Jamie Madillc29968b2016-01-20 11:17:23 -05003791void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3792{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003793 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003794 ASSERT(framebuffer);
3795 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003796 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003797}
3798
3799void Context::readBuffer(GLenum mode)
3800{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003801 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003802 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003803 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003804}
3805
3806void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3807{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003808 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003809 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003810
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003811 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003812 ASSERT(framebuffer);
3813
3814 // The specification isn't clear what should be done when the framebuffer isn't complete.
3815 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003816 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003817}
3818
3819void Context::invalidateFramebuffer(GLenum target,
3820 GLsizei numAttachments,
3821 const GLenum *attachments)
3822{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003823 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003824 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003825
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003826 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003827 ASSERT(framebuffer);
3828
Jamie Madill427064d2018-04-13 16:20:34 -04003829 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003830 {
Jamie Madill437fa652016-05-03 15:13:24 -04003831 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003832 }
Jamie Madill437fa652016-05-03 15:13:24 -04003833
Jamie Madill4928b7c2017-06-20 12:57:39 -04003834 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003835}
3836
3837void Context::invalidateSubFramebuffer(GLenum target,
3838 GLsizei numAttachments,
3839 const GLenum *attachments,
3840 GLint x,
3841 GLint y,
3842 GLsizei width,
3843 GLsizei height)
3844{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003845 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003846 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003847
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003848 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003849 ASSERT(framebuffer);
3850
Jamie Madill427064d2018-04-13 16:20:34 -04003851 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003852 {
Jamie Madill437fa652016-05-03 15:13:24 -04003853 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003854 }
Jamie Madill437fa652016-05-03 15:13:24 -04003855
3856 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003857 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003858}
3859
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003860void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003861 GLint level,
3862 GLint internalformat,
3863 GLsizei width,
3864 GLsizei height,
3865 GLint border,
3866 GLenum format,
3867 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003868 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003869{
Jamie Madillbc918e72018-03-08 09:47:21 -05003870 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003871
3872 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003873 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003874 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003875 size, format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003876}
3877
Brandon Jones59770802018-04-02 13:18:42 -07003878void Context::texImage2DRobust(TextureTarget target,
3879 GLint level,
3880 GLint internalformat,
3881 GLsizei width,
3882 GLsizei height,
3883 GLint border,
3884 GLenum format,
3885 GLenum type,
3886 GLsizei bufSize,
3887 const void *pixels)
3888{
3889 texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
3890}
3891
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003892void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003893 GLint level,
3894 GLint internalformat,
3895 GLsizei width,
3896 GLsizei height,
3897 GLsizei depth,
3898 GLint border,
3899 GLenum format,
3900 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003901 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003902{
Jamie Madillbc918e72018-03-08 09:47:21 -05003903 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003904
3905 Extents size(width, height, depth);
3906 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003907 handleError(texture->setImage(this, mGLState.getUnpackState(),
3908 NonCubeTextureTypeToTarget(target), level, internalformat, size,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003909 format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003910}
3911
Brandon Jones59770802018-04-02 13:18:42 -07003912void Context::texImage3DRobust(TextureType target,
3913 GLint level,
3914 GLint internalformat,
3915 GLsizei width,
3916 GLsizei height,
3917 GLsizei depth,
3918 GLint border,
3919 GLenum format,
3920 GLenum type,
3921 GLsizei bufSize,
3922 const void *pixels)
3923{
3924 texImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels);
3925}
3926
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003927void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003928 GLint level,
3929 GLint xoffset,
3930 GLint yoffset,
3931 GLsizei width,
3932 GLsizei height,
3933 GLenum format,
3934 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003935 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003936{
3937 // Zero sized uploads are valid but no-ops
3938 if (width == 0 || height == 0)
3939 {
3940 return;
3941 }
3942
Jamie Madillbc918e72018-03-08 09:47:21 -05003943 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003944
3945 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003946 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003947 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003948 type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003949}
3950
Brandon Jones59770802018-04-02 13:18:42 -07003951void Context::texSubImage2DRobust(TextureTarget target,
3952 GLint level,
3953 GLint xoffset,
3954 GLint yoffset,
3955 GLsizei width,
3956 GLsizei height,
3957 GLenum format,
3958 GLenum type,
3959 GLsizei bufSize,
3960 const void *pixels)
3961{
3962 texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
3963}
3964
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003965void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003966 GLint level,
3967 GLint xoffset,
3968 GLint yoffset,
3969 GLint zoffset,
3970 GLsizei width,
3971 GLsizei height,
3972 GLsizei depth,
3973 GLenum format,
3974 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003975 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003976{
3977 // Zero sized uploads are valid but no-ops
3978 if (width == 0 || height == 0 || depth == 0)
3979 {
3980 return;
3981 }
3982
Jamie Madillbc918e72018-03-08 09:47:21 -05003983 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003984
3985 Box area(xoffset, yoffset, zoffset, width, height, depth);
3986 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003987 handleError(texture->setSubImage(this, mGLState.getUnpackState(),
3988 NonCubeTextureTypeToTarget(target), level, area, format, type,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003989 static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003990}
3991
Brandon Jones59770802018-04-02 13:18:42 -07003992void Context::texSubImage3DRobust(TextureType target,
3993 GLint level,
3994 GLint xoffset,
3995 GLint yoffset,
3996 GLint zoffset,
3997 GLsizei width,
3998 GLsizei height,
3999 GLsizei depth,
4000 GLenum format,
4001 GLenum type,
4002 GLsizei bufSize,
4003 const void *pixels)
4004{
4005 texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type,
4006 pixels);
4007}
4008
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004009void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004010 GLint level,
4011 GLenum internalformat,
4012 GLsizei width,
4013 GLsizei height,
4014 GLint border,
4015 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004016 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004017{
Jamie Madillbc918e72018-03-08 09:47:21 -05004018 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004019
4020 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004021 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05004022 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
4023 internalformat, size, imageSize,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004024 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004025}
4026
Brandon Jones59770802018-04-02 13:18:42 -07004027void Context::compressedTexImage2DRobust(TextureTarget target,
4028 GLint level,
4029 GLenum internalformat,
4030 GLsizei width,
4031 GLsizei height,
4032 GLint border,
4033 GLsizei imageSize,
4034 GLsizei dataSize,
4035 const GLvoid *data)
4036{
4037 compressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
4038}
4039
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004040void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004041 GLint level,
4042 GLenum internalformat,
4043 GLsizei width,
4044 GLsizei height,
4045 GLsizei depth,
4046 GLint border,
4047 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004048 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004049{
Jamie Madillbc918e72018-03-08 09:47:21 -05004050 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004051
4052 Extents size(width, height, depth);
4053 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004054 handleError(texture->setCompressedImage(
4055 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004056 size, imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004057}
4058
Brandon Jones59770802018-04-02 13:18:42 -07004059void Context::compressedTexImage3DRobust(TextureType target,
4060 GLint level,
4061 GLenum internalformat,
4062 GLsizei width,
4063 GLsizei height,
4064 GLsizei depth,
4065 GLint border,
4066 GLsizei imageSize,
4067 GLsizei dataSize,
4068 const GLvoid *data)
4069{
4070 compressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize,
4071 data);
4072}
4073
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004074void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004075 GLint level,
4076 GLint xoffset,
4077 GLint yoffset,
4078 GLsizei width,
4079 GLsizei height,
4080 GLenum format,
4081 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004082 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004083{
Jamie Madillbc918e72018-03-08 09:47:21 -05004084 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004085
4086 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004087 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05004088 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
4089 format, imageSize,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004090 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004091}
4092
Brandon Jones59770802018-04-02 13:18:42 -07004093void Context::compressedTexSubImage2DRobust(TextureTarget target,
4094 GLint level,
4095 GLint xoffset,
4096 GLint yoffset,
4097 GLsizei width,
4098 GLsizei height,
4099 GLenum format,
4100 GLsizei imageSize,
4101 GLsizei dataSize,
4102 const GLvoid *data)
4103{
4104 compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize,
4105 data);
4106}
4107
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004108void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004109 GLint level,
4110 GLint xoffset,
4111 GLint yoffset,
4112 GLint zoffset,
4113 GLsizei width,
4114 GLsizei height,
4115 GLsizei depth,
4116 GLenum format,
4117 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004118 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004119{
4120 // Zero sized uploads are valid but no-ops
4121 if (width == 0 || height == 0)
4122 {
4123 return;
4124 }
4125
Jamie Madillbc918e72018-03-08 09:47:21 -05004126 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004127
4128 Box area(xoffset, yoffset, zoffset, width, height, depth);
4129 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004130 handleError(texture->setCompressedSubImage(
4131 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004132 imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004133}
4134
Brandon Jones59770802018-04-02 13:18:42 -07004135void Context::compressedTexSubImage3DRobust(TextureType target,
4136 GLint level,
4137 GLint xoffset,
4138 GLint yoffset,
4139 GLint zoffset,
4140 GLsizei width,
4141 GLsizei height,
4142 GLsizei depth,
4143 GLenum format,
4144 GLsizei imageSize,
4145 GLsizei dataSize,
4146 const GLvoid *data)
4147{
4148 compressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format,
4149 imageSize, data);
4150}
4151
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004152void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004153{
4154 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05004155 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004156}
4157
Jamie Madill007530e2017-12-28 14:27:04 -05004158void Context::copyTexture(GLuint sourceId,
4159 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004160 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004161 GLuint destId,
4162 GLint destLevel,
4163 GLint internalFormat,
4164 GLenum destType,
4165 GLboolean unpackFlipY,
4166 GLboolean unpackPremultiplyAlpha,
4167 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004168{
Jamie Madillbc918e72018-03-08 09:47:21 -05004169 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004170
4171 gl::Texture *sourceTexture = getTexture(sourceId);
4172 gl::Texture *destTexture = getTexture(destId);
Geoff Lang92019432017-11-20 13:09:34 -05004173 handleError(destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType,
4174 sourceLevel, ConvertToBool(unpackFlipY),
4175 ConvertToBool(unpackPremultiplyAlpha),
4176 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004177}
4178
Jamie Madill007530e2017-12-28 14:27:04 -05004179void Context::copySubTexture(GLuint sourceId,
4180 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004181 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004182 GLuint destId,
4183 GLint destLevel,
4184 GLint xoffset,
4185 GLint yoffset,
4186 GLint x,
4187 GLint y,
4188 GLsizei width,
4189 GLsizei height,
4190 GLboolean unpackFlipY,
4191 GLboolean unpackPremultiplyAlpha,
4192 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004193{
4194 // Zero sized copies are valid but no-ops
4195 if (width == 0 || height == 0)
4196 {
4197 return;
4198 }
4199
Jamie Madillbc918e72018-03-08 09:47:21 -05004200 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004201
4202 gl::Texture *sourceTexture = getTexture(sourceId);
4203 gl::Texture *destTexture = getTexture(destId);
4204 Offset offset(xoffset, yoffset, 0);
4205 Rectangle area(x, y, width, height);
Geoff Lang92019432017-11-20 13:09:34 -05004206 handleError(destTexture->copySubTexture(this, destTarget, destLevel, offset, sourceLevel, area,
4207 ConvertToBool(unpackFlipY),
4208 ConvertToBool(unpackPremultiplyAlpha),
4209 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004210}
4211
Jamie Madill007530e2017-12-28 14:27:04 -05004212void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07004213{
Jamie Madillbc918e72018-03-08 09:47:21 -05004214 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07004215
4216 gl::Texture *sourceTexture = getTexture(sourceId);
4217 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05004218 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07004219}
4220
Corentin Wallez336129f2017-10-17 15:55:40 -04004221void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03004222{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004223 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004224 ASSERT(buffer);
4225
Geoff Lang496c02d2016-10-20 11:38:11 -07004226 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03004227}
4228
Brandon Jones59770802018-04-02 13:18:42 -07004229void Context::getBufferPointervRobust(BufferBinding target,
4230 GLenum pname,
4231 GLsizei bufSize,
4232 GLsizei *length,
4233 void **params)
4234{
4235 getBufferPointerv(target, pname, params);
4236}
4237
Corentin Wallez336129f2017-10-17 15:55:40 -04004238void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004239{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004240 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004241 ASSERT(buffer);
4242
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004243 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004244 if (error.isError())
4245 {
Jamie Madill437fa652016-05-03 15:13:24 -04004246 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004247 return nullptr;
4248 }
4249
4250 return buffer->getMapPointer();
4251}
4252
Corentin Wallez336129f2017-10-17 15:55:40 -04004253GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03004254{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004255 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004256 ASSERT(buffer);
4257
4258 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004259 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03004260 if (error.isError())
4261 {
Jamie Madill437fa652016-05-03 15:13:24 -04004262 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004263 return GL_FALSE;
4264 }
4265
4266 return result;
4267}
4268
Corentin Wallez336129f2017-10-17 15:55:40 -04004269void *Context::mapBufferRange(BufferBinding target,
4270 GLintptr offset,
4271 GLsizeiptr length,
4272 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004273{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004274 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004275 ASSERT(buffer);
4276
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004277 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004278 if (error.isError())
4279 {
Jamie Madill437fa652016-05-03 15:13:24 -04004280 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004281 return nullptr;
4282 }
4283
4284 return buffer->getMapPointer();
4285}
4286
Corentin Wallez336129f2017-10-17 15:55:40 -04004287void Context::flushMappedBufferRange(BufferBinding /*target*/,
4288 GLintptr /*offset*/,
4289 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03004290{
4291 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
4292}
4293
Jamie Madillbc918e72018-03-08 09:47:21 -05004294Error Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004295{
Geoff Langa8cb2872018-03-09 16:09:40 -05004296 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004297}
4298
Jamie Madillbc918e72018-03-08 09:47:21 -05004299Error Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004300{
Geoff Langa8cb2872018-03-09 16:09:40 -05004301 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004302}
4303
Jamie Madillbc918e72018-03-08 09:47:21 -05004304Error Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004305{
Geoff Langa8cb2872018-03-09 16:09:40 -05004306 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004307}
4308
Jiajia Qin5451d532017-11-16 17:16:34 +08004309void Context::activeShaderProgram(GLuint pipeline, GLuint program)
4310{
4311 UNIMPLEMENTED();
4312}
4313
Jamie Madillc20ab272016-06-09 07:20:46 -07004314void Context::activeTexture(GLenum texture)
4315{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004316 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004317}
4318
Jamie Madill876429b2017-04-20 15:46:24 -04004319void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004320{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004321 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004322}
4323
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004324void Context::blendEquation(GLenum mode)
4325{
4326 mGLState.setBlendEquation(mode, mode);
4327}
4328
Jamie Madillc20ab272016-06-09 07:20:46 -07004329void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
4330{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004331 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004332}
4333
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004334void Context::blendFunc(GLenum sfactor, GLenum dfactor)
4335{
4336 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
4337}
4338
Jamie Madillc20ab272016-06-09 07:20:46 -07004339void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
4340{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004341 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004342}
4343
Jamie Madill876429b2017-04-20 15:46:24 -04004344void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004345{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004346 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004347}
4348
Jamie Madill876429b2017-04-20 15:46:24 -04004349void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07004350{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004351 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07004352}
4353
4354void Context::clearStencil(GLint s)
4355{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004356 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07004357}
4358
4359void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
4360{
Geoff Lang92019432017-11-20 13:09:34 -05004361 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
4362 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004363}
4364
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004365void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07004366{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004367 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004368}
4369
4370void Context::depthFunc(GLenum func)
4371{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004372 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07004373}
4374
4375void Context::depthMask(GLboolean flag)
4376{
Geoff Lang92019432017-11-20 13:09:34 -05004377 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07004378}
4379
Jamie Madill876429b2017-04-20 15:46:24 -04004380void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07004381{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004382 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07004383}
4384
4385void Context::disable(GLenum cap)
4386{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004387 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07004388}
4389
4390void Context::disableVertexAttribArray(GLuint index)
4391{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004392 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07004393}
4394
4395void Context::enable(GLenum cap)
4396{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004397 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07004398}
4399
4400void Context::enableVertexAttribArray(GLuint index)
4401{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004402 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07004403}
4404
4405void Context::frontFace(GLenum mode)
4406{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004407 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004408}
4409
4410void Context::hint(GLenum target, GLenum mode)
4411{
4412 switch (target)
4413 {
4414 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004415 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004416 break;
4417
4418 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004419 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004420 break;
4421
4422 default:
4423 UNREACHABLE();
4424 return;
4425 }
4426}
4427
4428void Context::lineWidth(GLfloat width)
4429{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004430 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07004431}
4432
4433void Context::pixelStorei(GLenum pname, GLint param)
4434{
4435 switch (pname)
4436 {
4437 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004438 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004439 break;
4440
4441 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004442 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004443 break;
4444
4445 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004446 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004447 break;
4448
4449 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004450 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004451 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004452 break;
4453
4454 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03004455 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004456 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004457 break;
4458
4459 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03004460 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004461 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004462 break;
4463
4464 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004465 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004466 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004467 break;
4468
4469 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004470 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004471 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004472 break;
4473
4474 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004475 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004476 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004477 break;
4478
4479 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004480 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004481 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004482 break;
4483
4484 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004485 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004486 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004487 break;
4488
4489 default:
4490 UNREACHABLE();
4491 return;
4492 }
4493}
4494
4495void Context::polygonOffset(GLfloat factor, GLfloat units)
4496{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004497 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07004498}
4499
Jamie Madill876429b2017-04-20 15:46:24 -04004500void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07004501{
Geoff Lang92019432017-11-20 13:09:34 -05004502 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07004503}
4504
Jiawei Shaodb342272017-09-27 10:21:45 +08004505void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
4506{
4507 mGLState.setSampleMaskParams(maskNumber, mask);
4508}
4509
Jamie Madillc20ab272016-06-09 07:20:46 -07004510void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
4511{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004512 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004513}
4514
4515void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
4516{
4517 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4518 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004519 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004520 }
4521
4522 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4523 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004524 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004525 }
4526}
4527
4528void Context::stencilMaskSeparate(GLenum face, GLuint mask)
4529{
4530 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4531 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004532 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004533 }
4534
4535 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4536 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004537 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004538 }
4539}
4540
4541void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4542{
4543 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4544 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004545 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004546 }
4547
4548 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4549 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004550 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004551 }
4552}
4553
4554void Context::vertexAttrib1f(GLuint index, GLfloat x)
4555{
4556 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004557 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004558}
4559
4560void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
4561{
4562 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004563 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004564}
4565
4566void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4567{
4568 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004569 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004570}
4571
4572void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
4573{
4574 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004575 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004576}
4577
4578void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4579{
4580 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004581 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004582}
4583
4584void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
4585{
4586 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004587 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004588}
4589
4590void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4591{
4592 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004593 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004594}
4595
4596void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
4597{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004598 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07004599}
4600
4601void Context::vertexAttribPointer(GLuint index,
4602 GLint size,
4603 GLenum type,
4604 GLboolean normalized,
4605 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004606 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07004607{
Corentin Wallez336129f2017-10-17 15:55:40 -04004608 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05004609 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc20ab272016-06-09 07:20:46 -07004610}
4611
Shao80957d92017-02-20 21:25:59 +08004612void Context::vertexAttribFormat(GLuint attribIndex,
4613 GLint size,
4614 GLenum type,
4615 GLboolean normalized,
4616 GLuint relativeOffset)
4617{
Geoff Lang92019432017-11-20 13:09:34 -05004618 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08004619 relativeOffset);
4620}
4621
4622void Context::vertexAttribIFormat(GLuint attribIndex,
4623 GLint size,
4624 GLenum type,
4625 GLuint relativeOffset)
4626{
4627 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
4628}
4629
4630void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4631{
Shaodde78e82017-05-22 14:13:27 +08004632 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Shao80957d92017-02-20 21:25:59 +08004633}
4634
Jiajia Qin5451d532017-11-16 17:16:34 +08004635void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004636{
4637 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
4638}
4639
Jamie Madillc20ab272016-06-09 07:20:46 -07004640void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4641{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004642 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004643}
4644
4645void Context::vertexAttribIPointer(GLuint index,
4646 GLint size,
4647 GLenum type,
4648 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004649 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004650{
Corentin Wallez336129f2017-10-17 15:55:40 -04004651 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
4652 size, type, false, true, stride, pointer);
Jamie Madillc20ab272016-06-09 07:20:46 -07004653}
4654
4655void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4656{
4657 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004658 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004659}
4660
4661void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4662{
4663 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004664 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004665}
4666
4667void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4668{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004669 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004670}
4671
4672void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4673{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004674 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004675}
4676
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004677void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4678{
4679 const VertexAttribCurrentValueData &currentValues =
4680 getGLState().getVertexAttribCurrentValue(index);
4681 const VertexArray *vao = getGLState().getVertexArray();
4682 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4683 currentValues, pname, params);
4684}
4685
Brandon Jones59770802018-04-02 13:18:42 -07004686void Context::getVertexAttribivRobust(GLuint index,
4687 GLenum pname,
4688 GLsizei bufSize,
4689 GLsizei *length,
4690 GLint *params)
4691{
4692 getVertexAttribiv(index, pname, params);
4693}
4694
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004695void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4696{
4697 const VertexAttribCurrentValueData &currentValues =
4698 getGLState().getVertexAttribCurrentValue(index);
4699 const VertexArray *vao = getGLState().getVertexArray();
4700 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4701 currentValues, pname, params);
4702}
4703
Brandon Jones59770802018-04-02 13:18:42 -07004704void Context::getVertexAttribfvRobust(GLuint index,
4705 GLenum pname,
4706 GLsizei bufSize,
4707 GLsizei *length,
4708 GLfloat *params)
4709{
4710 getVertexAttribfv(index, pname, params);
4711}
4712
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004713void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4714{
4715 const VertexAttribCurrentValueData &currentValues =
4716 getGLState().getVertexAttribCurrentValue(index);
4717 const VertexArray *vao = getGLState().getVertexArray();
4718 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4719 currentValues, pname, params);
4720}
4721
Brandon Jones59770802018-04-02 13:18:42 -07004722void Context::getVertexAttribIivRobust(GLuint index,
4723 GLenum pname,
4724 GLsizei bufSize,
4725 GLsizei *length,
4726 GLint *params)
4727{
4728 getVertexAttribIiv(index, pname, params);
4729}
4730
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004731void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4732{
4733 const VertexAttribCurrentValueData &currentValues =
4734 getGLState().getVertexAttribCurrentValue(index);
4735 const VertexArray *vao = getGLState().getVertexArray();
4736 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4737 currentValues, pname, params);
4738}
4739
Brandon Jones59770802018-04-02 13:18:42 -07004740void Context::getVertexAttribIuivRobust(GLuint index,
4741 GLenum pname,
4742 GLsizei bufSize,
4743 GLsizei *length,
4744 GLuint *params)
4745{
4746 getVertexAttribIuiv(index, pname, params);
4747}
4748
Jamie Madill876429b2017-04-20 15:46:24 -04004749void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004750{
4751 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
4752 QueryVertexAttribPointerv(attrib, pname, pointer);
4753}
4754
Brandon Jones59770802018-04-02 13:18:42 -07004755void Context::getVertexAttribPointervRobust(GLuint index,
4756 GLenum pname,
4757 GLsizei bufSize,
4758 GLsizei *length,
4759 void **pointer)
4760{
4761 getVertexAttribPointerv(index, pname, pointer);
4762}
4763
Jamie Madillc20ab272016-06-09 07:20:46 -07004764void Context::debugMessageControl(GLenum source,
4765 GLenum type,
4766 GLenum severity,
4767 GLsizei count,
4768 const GLuint *ids,
4769 GLboolean enabled)
4770{
4771 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004772 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05004773 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004774}
4775
4776void Context::debugMessageInsert(GLenum source,
4777 GLenum type,
4778 GLuint id,
4779 GLenum severity,
4780 GLsizei length,
4781 const GLchar *buf)
4782{
4783 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004784 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004785}
4786
4787void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4788{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004789 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004790}
4791
4792GLuint Context::getDebugMessageLog(GLuint count,
4793 GLsizei bufSize,
4794 GLenum *sources,
4795 GLenum *types,
4796 GLuint *ids,
4797 GLenum *severities,
4798 GLsizei *lengths,
4799 GLchar *messageLog)
4800{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004801 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4802 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004803}
4804
4805void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4806{
4807 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004808 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05004809 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07004810}
4811
4812void Context::popDebugGroup()
4813{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004814 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05004815 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004816}
4817
Corentin Wallez336129f2017-10-17 15:55:40 -04004818void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004819{
4820 Buffer *buffer = mGLState.getTargetBuffer(target);
4821 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004822 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004823}
4824
Corentin Wallez336129f2017-10-17 15:55:40 -04004825void Context::bufferSubData(BufferBinding target,
4826 GLintptr offset,
4827 GLsizeiptr size,
4828 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004829{
4830 if (data == nullptr)
4831 {
4832 return;
4833 }
4834
4835 Buffer *buffer = mGLState.getTargetBuffer(target);
4836 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004837 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004838}
4839
Jamie Madillef300b12016-10-07 15:12:09 -04004840void Context::attachShader(GLuint program, GLuint shader)
4841{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05004842 Program *programObject = mState.mShaderPrograms->getProgram(program);
4843 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004844 ASSERT(programObject && shaderObject);
4845 programObject->attachShader(shaderObject);
4846}
4847
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004848const Workarounds &Context::getWorkarounds() const
4849{
4850 return mWorkarounds;
4851}
4852
Corentin Wallez336129f2017-10-17 15:55:40 -04004853void Context::copyBufferSubData(BufferBinding readTarget,
4854 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04004855 GLintptr readOffset,
4856 GLintptr writeOffset,
4857 GLsizeiptr size)
4858{
4859 // if size is zero, the copy is a successful no-op
4860 if (size == 0)
4861 {
4862 return;
4863 }
4864
4865 // TODO(jmadill): cache these.
4866 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4867 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4868
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004869 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004870}
4871
Jamie Madill01a80ee2016-11-07 12:06:18 -05004872void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4873{
4874 Program *programObject = getProgram(program);
4875 // TODO(jmadill): Re-use this from the validation if possible.
4876 ASSERT(programObject);
4877 programObject->bindAttributeLocation(index, name);
4878}
4879
Corentin Wallez336129f2017-10-17 15:55:40 -04004880void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004881{
Corentin Wallez336129f2017-10-17 15:55:40 -04004882 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4883 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004884}
4885
Corentin Wallez336129f2017-10-17 15:55:40 -04004886void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08004887{
4888 bindBufferRange(target, index, buffer, 0, 0);
4889}
4890
Corentin Wallez336129f2017-10-17 15:55:40 -04004891void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08004892 GLuint index,
4893 GLuint buffer,
4894 GLintptr offset,
4895 GLsizeiptr size)
4896{
Corentin Wallez336129f2017-10-17 15:55:40 -04004897 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4898 mGLState.setIndexedBufferBinding(this, target, index, bufferObject, offset, size);
Jiajia Qin6eafb042016-12-27 17:04:07 +08004899}
4900
Jamie Madill01a80ee2016-11-07 12:06:18 -05004901void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
4902{
4903 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4904 {
4905 bindReadFramebuffer(framebuffer);
4906 }
4907
4908 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4909 {
4910 bindDrawFramebuffer(framebuffer);
4911 }
4912}
4913
4914void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4915{
4916 ASSERT(target == GL_RENDERBUFFER);
4917 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004918 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04004919 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004920}
4921
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004922void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08004923 GLsizei samples,
4924 GLenum internalformat,
4925 GLsizei width,
4926 GLsizei height,
4927 GLboolean fixedsamplelocations)
4928{
4929 Extents size(width, height, 1);
4930 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004931 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
4932 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004933}
4934
4935void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4936{
JiangYizhou5b03f472017-01-09 10:22:53 +08004937 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
4938 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillbc918e72018-03-08 09:47:21 -05004939 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
JiangYizhou5b03f472017-01-09 10:22:53 +08004940 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08004941
4942 switch (pname)
4943 {
4944 case GL_SAMPLE_POSITION:
Geoff Lang13455072018-05-09 11:24:43 -04004945 handleError(framebuffer->getSamplePosition(this, index, val));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004946 break;
4947 default:
4948 UNREACHABLE();
4949 }
4950}
4951
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07004952void Context::getMultisamplefvRobust(GLenum pname,
4953 GLuint index,
4954 GLsizei bufSize,
4955 GLsizei *length,
4956 GLfloat *val)
4957{
4958 UNIMPLEMENTED();
4959}
4960
Jamie Madille8fb6402017-02-14 17:56:40 -05004961void Context::renderbufferStorage(GLenum target,
4962 GLenum internalformat,
4963 GLsizei width,
4964 GLsizei height)
4965{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004966 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4967 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
4968
Jamie Madille8fb6402017-02-14 17:56:40 -05004969 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04004970 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004971}
4972
4973void Context::renderbufferStorageMultisample(GLenum target,
4974 GLsizei samples,
4975 GLenum internalformat,
4976 GLsizei width,
4977 GLsizei height)
4978{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004979 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4980 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05004981
4982 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004983 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04004984 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004985}
4986
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004987void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
4988{
Jamie Madill70b5bb02017-08-28 13:32:37 -04004989 const Sync *syncObject = getSync(sync);
Geoff Lang82483b92017-04-11 15:33:00 -04004990 handleError(QuerySynciv(syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004991}
4992
JiangYizhoue18e6392017-02-20 10:32:23 +08004993void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
4994{
4995 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4996 QueryFramebufferParameteriv(framebuffer, pname, params);
4997}
4998
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07004999void Context::getFramebufferParameterivRobust(GLenum target,
5000 GLenum pname,
5001 GLsizei bufSize,
5002 GLsizei *length,
5003 GLint *params)
5004{
5005 UNIMPLEMENTED();
5006}
5007
Jiajia Qin5451d532017-11-16 17:16:34 +08005008void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08005009{
5010 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5011 SetFramebufferParameteri(framebuffer, pname, param);
5012}
5013
Jamie Madilldec86232018-07-11 09:01:18 -04005014bool Context::getScratchBuffer(size_t requstedSizeBytes,
5015 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05005016{
Jamie Madilldec86232018-07-11 09:01:18 -04005017 return mScratchBuffer.get(requstedSizeBytes, scratchBufferOut);
Jamie Madillb3f26b92017-07-19 15:07:41 -04005018}
5019
Jamie Madilldec86232018-07-11 09:01:18 -04005020bool Context::getZeroFilledBuffer(size_t requstedSizeBytes,
5021 angle::MemoryBuffer **zeroBufferOut) const
Jamie Madillb3f26b92017-07-19 15:07:41 -04005022{
Jamie Madilldec86232018-07-11 09:01:18 -04005023 return mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0);
Jamie Madille14951e2017-03-09 18:55:16 -05005024}
5025
Xinghua Cao10a4d432017-11-28 14:46:26 +08005026Error Context::prepareForDispatch()
5027{
Geoff Langa8cb2872018-03-09 16:09:40 -05005028 ANGLE_TRY(syncState(mComputeDirtyBits, mComputeDirtyObjects));
Xinghua Cao10a4d432017-11-28 14:46:26 +08005029
5030 if (isRobustResourceInitEnabled())
5031 {
5032 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
5033 }
5034
5035 return NoError();
5036}
5037
Xinghua Cao2b396592017-03-29 15:36:04 +08005038void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
5039{
5040 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
5041 {
5042 return;
5043 }
5044
Xinghua Cao10a4d432017-11-28 14:46:26 +08005045 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill71c88b32017-09-14 22:20:29 -04005046 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08005047}
5048
Jiajia Qin5451d532017-11-16 17:16:34 +08005049void Context::dispatchComputeIndirect(GLintptr indirect)
5050{
Qin Jiajia62fcf622017-11-30 16:16:12 +08005051 ANGLE_CONTEXT_TRY(prepareForDispatch());
5052 handleError(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08005053}
5054
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005055void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005056 GLsizei levels,
5057 GLenum internalFormat,
5058 GLsizei width,
5059 GLsizei height)
5060{
5061 Extents size(width, height, 1);
5062 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005063 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005064}
5065
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005066void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005067 GLsizei levels,
5068 GLenum internalFormat,
5069 GLsizei width,
5070 GLsizei height,
5071 GLsizei depth)
5072{
5073 Extents size(width, height, depth);
5074 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005075 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005076}
5077
Jiajia Qin5451d532017-11-16 17:16:34 +08005078void Context::memoryBarrier(GLbitfield barriers)
5079{
Xinghua Cao89c422a2017-11-29 18:24:20 +08005080 handleError(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005081}
5082
5083void Context::memoryBarrierByRegion(GLbitfield barriers)
5084{
Xinghua Cao89c422a2017-11-29 18:24:20 +08005085 handleError(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005086}
5087
Jamie Madillc1d770e2017-04-13 17:31:24 -04005088GLenum Context::checkFramebufferStatus(GLenum target)
5089{
5090 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5091 ASSERT(framebuffer);
Jamie Madill427064d2018-04-13 16:20:34 -04005092 return framebuffer->checkStatus(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005093}
5094
5095void Context::compileShader(GLuint shader)
5096{
5097 Shader *shaderObject = GetValidShader(this, shader);
5098 if (!shaderObject)
5099 {
5100 return;
5101 }
5102 shaderObject->compile(this);
5103}
5104
5105void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
5106{
5107 for (int i = 0; i < n; i++)
5108 {
5109 deleteBuffer(buffers[i]);
5110 }
5111}
5112
5113void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
5114{
5115 for (int i = 0; i < n; i++)
5116 {
5117 if (framebuffers[i] != 0)
5118 {
5119 deleteFramebuffer(framebuffers[i]);
5120 }
5121 }
5122}
5123
5124void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
5125{
5126 for (int i = 0; i < n; i++)
5127 {
5128 deleteRenderbuffer(renderbuffers[i]);
5129 }
5130}
5131
5132void Context::deleteTextures(GLsizei n, const GLuint *textures)
5133{
5134 for (int i = 0; i < n; i++)
5135 {
5136 if (textures[i] != 0)
5137 {
5138 deleteTexture(textures[i]);
5139 }
5140 }
5141}
5142
5143void Context::detachShader(GLuint program, GLuint shader)
5144{
5145 Program *programObject = getProgram(program);
5146 ASSERT(programObject);
5147
5148 Shader *shaderObject = getShader(shader);
5149 ASSERT(shaderObject);
5150
5151 programObject->detachShader(this, shaderObject);
5152}
5153
5154void Context::genBuffers(GLsizei n, GLuint *buffers)
5155{
5156 for (int i = 0; i < n; i++)
5157 {
5158 buffers[i] = createBuffer();
5159 }
5160}
5161
5162void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
5163{
5164 for (int i = 0; i < n; i++)
5165 {
5166 framebuffers[i] = createFramebuffer();
5167 }
5168}
5169
5170void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
5171{
5172 for (int i = 0; i < n; i++)
5173 {
5174 renderbuffers[i] = createRenderbuffer();
5175 }
5176}
5177
5178void Context::genTextures(GLsizei n, GLuint *textures)
5179{
5180 for (int i = 0; i < n; i++)
5181 {
5182 textures[i] = createTexture();
5183 }
5184}
5185
5186void Context::getActiveAttrib(GLuint program,
5187 GLuint index,
5188 GLsizei bufsize,
5189 GLsizei *length,
5190 GLint *size,
5191 GLenum *type,
5192 GLchar *name)
5193{
5194 Program *programObject = getProgram(program);
5195 ASSERT(programObject);
5196 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
5197}
5198
5199void Context::getActiveUniform(GLuint program,
5200 GLuint index,
5201 GLsizei bufsize,
5202 GLsizei *length,
5203 GLint *size,
5204 GLenum *type,
5205 GLchar *name)
5206{
5207 Program *programObject = getProgram(program);
5208 ASSERT(programObject);
5209 programObject->getActiveUniform(index, bufsize, length, size, type, name);
5210}
5211
5212void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
5213{
5214 Program *programObject = getProgram(program);
5215 ASSERT(programObject);
5216 programObject->getAttachedShaders(maxcount, count, shaders);
5217}
5218
5219GLint Context::getAttribLocation(GLuint program, const GLchar *name)
5220{
5221 Program *programObject = getProgram(program);
5222 ASSERT(programObject);
5223 return programObject->getAttributeLocation(name);
5224}
5225
5226void Context::getBooleanv(GLenum pname, GLboolean *params)
5227{
5228 GLenum nativeType;
5229 unsigned int numParams = 0;
5230 getQueryParameterInfo(pname, &nativeType, &numParams);
5231
5232 if (nativeType == GL_BOOL)
5233 {
5234 getBooleanvImpl(pname, params);
5235 }
5236 else
5237 {
5238 CastStateValues(this, nativeType, pname, numParams, params);
5239 }
5240}
5241
Brandon Jones59770802018-04-02 13:18:42 -07005242void Context::getBooleanvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLboolean *params)
5243{
5244 getBooleanv(pname, params);
5245}
5246
Jamie Madillc1d770e2017-04-13 17:31:24 -04005247void Context::getFloatv(GLenum pname, GLfloat *params)
5248{
5249 GLenum nativeType;
5250 unsigned int numParams = 0;
5251 getQueryParameterInfo(pname, &nativeType, &numParams);
5252
5253 if (nativeType == GL_FLOAT)
5254 {
5255 getFloatvImpl(pname, params);
5256 }
5257 else
5258 {
5259 CastStateValues(this, nativeType, pname, numParams, params);
5260 }
5261}
5262
Brandon Jones59770802018-04-02 13:18:42 -07005263void Context::getFloatvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLfloat *params)
5264{
5265 getFloatv(pname, params);
5266}
5267
Jamie Madillc1d770e2017-04-13 17:31:24 -04005268void Context::getIntegerv(GLenum pname, GLint *params)
5269{
5270 GLenum nativeType;
5271 unsigned int numParams = 0;
5272 getQueryParameterInfo(pname, &nativeType, &numParams);
5273
5274 if (nativeType == GL_INT)
5275 {
5276 getIntegervImpl(pname, params);
5277 }
5278 else
5279 {
5280 CastStateValues(this, nativeType, pname, numParams, params);
5281 }
5282}
5283
Brandon Jones59770802018-04-02 13:18:42 -07005284void Context::getIntegervRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint *data)
5285{
5286 getIntegerv(pname, data);
5287}
5288
Jamie Madillc1d770e2017-04-13 17:31:24 -04005289void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
5290{
5291 Program *programObject = getProgram(program);
5292 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04005293 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005294}
5295
Brandon Jones59770802018-04-02 13:18:42 -07005296void Context::getProgramivRobust(GLuint program,
5297 GLenum pname,
5298 GLsizei bufSize,
5299 GLsizei *length,
5300 GLint *params)
5301{
5302 getProgramiv(program, pname, params);
5303}
5304
Jiajia Qin5451d532017-11-16 17:16:34 +08005305void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
5306{
5307 UNIMPLEMENTED();
5308}
5309
Jamie Madillbe849e42017-05-02 15:49:00 -04005310void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005311{
5312 Program *programObject = getProgram(program);
5313 ASSERT(programObject);
5314 programObject->getInfoLog(bufsize, length, infolog);
5315}
5316
Jiajia Qin5451d532017-11-16 17:16:34 +08005317void Context::getProgramPipelineInfoLog(GLuint pipeline,
5318 GLsizei bufSize,
5319 GLsizei *length,
5320 GLchar *infoLog)
5321{
5322 UNIMPLEMENTED();
5323}
5324
Jamie Madillc1d770e2017-04-13 17:31:24 -04005325void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
5326{
5327 Shader *shaderObject = getShader(shader);
5328 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04005329 QueryShaderiv(this, shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005330}
5331
Brandon Jones59770802018-04-02 13:18:42 -07005332void Context::getShaderivRobust(GLuint shader,
5333 GLenum pname,
5334 GLsizei bufSize,
5335 GLsizei *length,
5336 GLint *params)
5337{
5338 getShaderiv(shader, pname, params);
5339}
5340
Jamie Madillc1d770e2017-04-13 17:31:24 -04005341void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
5342{
5343 Shader *shaderObject = getShader(shader);
5344 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04005345 shaderObject->getInfoLog(this, bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005346}
5347
5348void Context::getShaderPrecisionFormat(GLenum shadertype,
5349 GLenum precisiontype,
5350 GLint *range,
5351 GLint *precision)
5352{
5353 // TODO(jmadill): Compute shaders.
5354
5355 switch (shadertype)
5356 {
5357 case GL_VERTEX_SHADER:
5358 switch (precisiontype)
5359 {
5360 case GL_LOW_FLOAT:
5361 mCaps.vertexLowpFloat.get(range, precision);
5362 break;
5363 case GL_MEDIUM_FLOAT:
5364 mCaps.vertexMediumpFloat.get(range, precision);
5365 break;
5366 case GL_HIGH_FLOAT:
5367 mCaps.vertexHighpFloat.get(range, precision);
5368 break;
5369
5370 case GL_LOW_INT:
5371 mCaps.vertexLowpInt.get(range, precision);
5372 break;
5373 case GL_MEDIUM_INT:
5374 mCaps.vertexMediumpInt.get(range, precision);
5375 break;
5376 case GL_HIGH_INT:
5377 mCaps.vertexHighpInt.get(range, precision);
5378 break;
5379
5380 default:
5381 UNREACHABLE();
5382 return;
5383 }
5384 break;
5385
5386 case GL_FRAGMENT_SHADER:
5387 switch (precisiontype)
5388 {
5389 case GL_LOW_FLOAT:
5390 mCaps.fragmentLowpFloat.get(range, precision);
5391 break;
5392 case GL_MEDIUM_FLOAT:
5393 mCaps.fragmentMediumpFloat.get(range, precision);
5394 break;
5395 case GL_HIGH_FLOAT:
5396 mCaps.fragmentHighpFloat.get(range, precision);
5397 break;
5398
5399 case GL_LOW_INT:
5400 mCaps.fragmentLowpInt.get(range, precision);
5401 break;
5402 case GL_MEDIUM_INT:
5403 mCaps.fragmentMediumpInt.get(range, precision);
5404 break;
5405 case GL_HIGH_INT:
5406 mCaps.fragmentHighpInt.get(range, precision);
5407 break;
5408
5409 default:
5410 UNREACHABLE();
5411 return;
5412 }
5413 break;
5414
5415 default:
5416 UNREACHABLE();
5417 return;
5418 }
5419}
5420
5421void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
5422{
5423 Shader *shaderObject = getShader(shader);
5424 ASSERT(shaderObject);
5425 shaderObject->getSource(bufsize, length, source);
5426}
5427
5428void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
5429{
5430 Program *programObject = getProgram(program);
5431 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005432 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005433}
5434
Brandon Jones59770802018-04-02 13:18:42 -07005435void Context::getUniformfvRobust(GLuint program,
5436 GLint location,
5437 GLsizei bufSize,
5438 GLsizei *length,
5439 GLfloat *params)
5440{
5441 getUniformfv(program, location, params);
5442}
5443
Jamie Madillc1d770e2017-04-13 17:31:24 -04005444void Context::getUniformiv(GLuint program, GLint location, GLint *params)
5445{
5446 Program *programObject = getProgram(program);
5447 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005448 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005449}
5450
Brandon Jones59770802018-04-02 13:18:42 -07005451void Context::getUniformivRobust(GLuint program,
5452 GLint location,
5453 GLsizei bufSize,
5454 GLsizei *length,
5455 GLint *params)
5456{
5457 getUniformiv(program, location, params);
5458}
5459
Jamie Madillc1d770e2017-04-13 17:31:24 -04005460GLint Context::getUniformLocation(GLuint program, const GLchar *name)
5461{
5462 Program *programObject = getProgram(program);
5463 ASSERT(programObject);
5464 return programObject->getUniformLocation(name);
5465}
5466
5467GLboolean Context::isBuffer(GLuint buffer)
5468{
5469 if (buffer == 0)
5470 {
5471 return GL_FALSE;
5472 }
5473
5474 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
5475}
5476
5477GLboolean Context::isEnabled(GLenum cap)
5478{
5479 return mGLState.getEnableFeature(cap);
5480}
5481
5482GLboolean Context::isFramebuffer(GLuint framebuffer)
5483{
5484 if (framebuffer == 0)
5485 {
5486 return GL_FALSE;
5487 }
5488
5489 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
5490}
5491
5492GLboolean Context::isProgram(GLuint program)
5493{
5494 if (program == 0)
5495 {
5496 return GL_FALSE;
5497 }
5498
5499 return (getProgram(program) ? GL_TRUE : GL_FALSE);
5500}
5501
5502GLboolean Context::isRenderbuffer(GLuint renderbuffer)
5503{
5504 if (renderbuffer == 0)
5505 {
5506 return GL_FALSE;
5507 }
5508
5509 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
5510}
5511
5512GLboolean Context::isShader(GLuint shader)
5513{
5514 if (shader == 0)
5515 {
5516 return GL_FALSE;
5517 }
5518
5519 return (getShader(shader) ? GL_TRUE : GL_FALSE);
5520}
5521
5522GLboolean Context::isTexture(GLuint texture)
5523{
5524 if (texture == 0)
5525 {
5526 return GL_FALSE;
5527 }
5528
5529 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
5530}
5531
5532void Context::linkProgram(GLuint program)
5533{
5534 Program *programObject = getProgram(program);
5535 ASSERT(programObject);
5536 handleError(programObject->link(this));
Martin Radev0abb7a22017-08-28 15:34:45 +03005537 mGLState.onProgramExecutableChange(programObject);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005538}
5539
5540void Context::releaseShaderCompiler()
5541{
Jamie Madill4928b7c2017-06-20 12:57:39 -04005542 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005543}
5544
5545void Context::shaderBinary(GLsizei n,
5546 const GLuint *shaders,
5547 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04005548 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005549 GLsizei length)
5550{
5551 // No binary shader formats are supported.
5552 UNIMPLEMENTED();
5553}
5554
5555void Context::shaderSource(GLuint shader,
5556 GLsizei count,
5557 const GLchar *const *string,
5558 const GLint *length)
5559{
5560 Shader *shaderObject = getShader(shader);
5561 ASSERT(shaderObject);
5562 shaderObject->setSource(count, string, length);
5563}
5564
5565void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
5566{
5567 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
5568}
5569
5570void Context::stencilMask(GLuint mask)
5571{
5572 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
5573}
5574
5575void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
5576{
5577 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
5578}
5579
5580void Context::uniform1f(GLint location, GLfloat x)
5581{
5582 Program *program = mGLState.getProgram();
5583 program->setUniform1fv(location, 1, &x);
5584}
5585
5586void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
5587{
5588 Program *program = mGLState.getProgram();
5589 program->setUniform1fv(location, count, v);
5590}
5591
5592void Context::uniform1i(GLint location, GLint x)
5593{
5594 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04005595 if (program->setUniform1iv(location, 1, &x) == Program::SetUniformResult::SamplerChanged)
5596 {
5597 mGLState.setObjectDirty(GL_PROGRAM);
5598 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005599}
5600
5601void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
5602{
5603 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04005604 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
5605 {
5606 mGLState.setObjectDirty(GL_PROGRAM);
5607 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005608}
5609
5610void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
5611{
5612 GLfloat xy[2] = {x, y};
5613 Program *program = mGLState.getProgram();
5614 program->setUniform2fv(location, 1, xy);
5615}
5616
5617void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
5618{
5619 Program *program = mGLState.getProgram();
5620 program->setUniform2fv(location, count, v);
5621}
5622
5623void Context::uniform2i(GLint location, GLint x, GLint y)
5624{
5625 GLint xy[2] = {x, y};
5626 Program *program = mGLState.getProgram();
5627 program->setUniform2iv(location, 1, xy);
5628}
5629
5630void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
5631{
5632 Program *program = mGLState.getProgram();
5633 program->setUniform2iv(location, count, v);
5634}
5635
5636void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
5637{
5638 GLfloat xyz[3] = {x, y, z};
5639 Program *program = mGLState.getProgram();
5640 program->setUniform3fv(location, 1, xyz);
5641}
5642
5643void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
5644{
5645 Program *program = mGLState.getProgram();
5646 program->setUniform3fv(location, count, v);
5647}
5648
5649void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
5650{
5651 GLint xyz[3] = {x, y, z};
5652 Program *program = mGLState.getProgram();
5653 program->setUniform3iv(location, 1, xyz);
5654}
5655
5656void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
5657{
5658 Program *program = mGLState.getProgram();
5659 program->setUniform3iv(location, count, v);
5660}
5661
5662void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
5663{
5664 GLfloat xyzw[4] = {x, y, z, w};
5665 Program *program = mGLState.getProgram();
5666 program->setUniform4fv(location, 1, xyzw);
5667}
5668
5669void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
5670{
5671 Program *program = mGLState.getProgram();
5672 program->setUniform4fv(location, count, v);
5673}
5674
5675void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
5676{
5677 GLint xyzw[4] = {x, y, z, w};
5678 Program *program = mGLState.getProgram();
5679 program->setUniform4iv(location, 1, xyzw);
5680}
5681
5682void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
5683{
5684 Program *program = mGLState.getProgram();
5685 program->setUniform4iv(location, count, v);
5686}
5687
5688void Context::uniformMatrix2fv(GLint location,
5689 GLsizei count,
5690 GLboolean transpose,
5691 const GLfloat *value)
5692{
5693 Program *program = mGLState.getProgram();
5694 program->setUniformMatrix2fv(location, count, transpose, value);
5695}
5696
5697void Context::uniformMatrix3fv(GLint location,
5698 GLsizei count,
5699 GLboolean transpose,
5700 const GLfloat *value)
5701{
5702 Program *program = mGLState.getProgram();
5703 program->setUniformMatrix3fv(location, count, transpose, value);
5704}
5705
5706void Context::uniformMatrix4fv(GLint location,
5707 GLsizei count,
5708 GLboolean transpose,
5709 const GLfloat *value)
5710{
5711 Program *program = mGLState.getProgram();
5712 program->setUniformMatrix4fv(location, count, transpose, value);
5713}
5714
5715void Context::validateProgram(GLuint program)
5716{
5717 Program *programObject = getProgram(program);
5718 ASSERT(programObject);
5719 programObject->validate(mCaps);
5720}
5721
Jiajia Qin5451d532017-11-16 17:16:34 +08005722void Context::validateProgramPipeline(GLuint pipeline)
5723{
5724 UNIMPLEMENTED();
5725}
5726
Jamie Madilld04908b2017-06-09 14:15:35 -04005727void Context::getProgramBinary(GLuint program,
5728 GLsizei bufSize,
5729 GLsizei *length,
5730 GLenum *binaryFormat,
5731 void *binary)
5732{
5733 Program *programObject = getProgram(program);
5734 ASSERT(programObject != nullptr);
5735
5736 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
5737}
5738
5739void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
5740{
5741 Program *programObject = getProgram(program);
5742 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04005743
Jamie Madilld04908b2017-06-09 14:15:35 -04005744 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
5745}
5746
Jamie Madillff325f12017-08-26 15:06:05 -04005747void Context::uniform1ui(GLint location, GLuint v0)
5748{
5749 Program *program = mGLState.getProgram();
5750 program->setUniform1uiv(location, 1, &v0);
5751}
5752
5753void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
5754{
5755 Program *program = mGLState.getProgram();
5756 const GLuint xy[] = {v0, v1};
5757 program->setUniform2uiv(location, 1, xy);
5758}
5759
5760void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
5761{
5762 Program *program = mGLState.getProgram();
5763 const GLuint xyz[] = {v0, v1, v2};
5764 program->setUniform3uiv(location, 1, xyz);
5765}
5766
5767void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
5768{
5769 Program *program = mGLState.getProgram();
5770 const GLuint xyzw[] = {v0, v1, v2, v3};
5771 program->setUniform4uiv(location, 1, xyzw);
5772}
5773
5774void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
5775{
5776 Program *program = mGLState.getProgram();
5777 program->setUniform1uiv(location, count, value);
5778}
5779void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
5780{
5781 Program *program = mGLState.getProgram();
5782 program->setUniform2uiv(location, count, value);
5783}
5784
5785void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
5786{
5787 Program *program = mGLState.getProgram();
5788 program->setUniform3uiv(location, count, value);
5789}
5790
5791void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
5792{
5793 Program *program = mGLState.getProgram();
5794 program->setUniform4uiv(location, count, value);
5795}
5796
Jamie Madillf0e04492017-08-26 15:28:42 -04005797void Context::genQueries(GLsizei n, GLuint *ids)
5798{
5799 for (GLsizei i = 0; i < n; i++)
5800 {
5801 GLuint handle = mQueryHandleAllocator.allocate();
5802 mQueryMap.assign(handle, nullptr);
5803 ids[i] = handle;
5804 }
5805}
5806
5807void Context::deleteQueries(GLsizei n, const GLuint *ids)
5808{
5809 for (int i = 0; i < n; i++)
5810 {
5811 GLuint query = ids[i];
5812
5813 Query *queryObject = nullptr;
5814 if (mQueryMap.erase(query, &queryObject))
5815 {
5816 mQueryHandleAllocator.release(query);
5817 if (queryObject)
5818 {
5819 queryObject->release(this);
5820 }
5821 }
5822 }
5823}
5824
5825GLboolean Context::isQuery(GLuint id)
5826{
Corentin Wallezad3ae902018-03-09 13:40:42 -05005827 return (getQuery(id, false, QueryType::InvalidEnum) != nullptr) ? GL_TRUE : GL_FALSE;
Jamie Madillf0e04492017-08-26 15:28:42 -04005828}
5829
Jamie Madillc8c95812017-08-26 18:40:09 -04005830void Context::uniformMatrix2x3fv(GLint location,
5831 GLsizei count,
5832 GLboolean transpose,
5833 const GLfloat *value)
5834{
5835 Program *program = mGLState.getProgram();
5836 program->setUniformMatrix2x3fv(location, count, transpose, value);
5837}
5838
5839void Context::uniformMatrix3x2fv(GLint location,
5840 GLsizei count,
5841 GLboolean transpose,
5842 const GLfloat *value)
5843{
5844 Program *program = mGLState.getProgram();
5845 program->setUniformMatrix3x2fv(location, count, transpose, value);
5846}
5847
5848void Context::uniformMatrix2x4fv(GLint location,
5849 GLsizei count,
5850 GLboolean transpose,
5851 const GLfloat *value)
5852{
5853 Program *program = mGLState.getProgram();
5854 program->setUniformMatrix2x4fv(location, count, transpose, value);
5855}
5856
5857void Context::uniformMatrix4x2fv(GLint location,
5858 GLsizei count,
5859 GLboolean transpose,
5860 const GLfloat *value)
5861{
5862 Program *program = mGLState.getProgram();
5863 program->setUniformMatrix4x2fv(location, count, transpose, value);
5864}
5865
5866void Context::uniformMatrix3x4fv(GLint location,
5867 GLsizei count,
5868 GLboolean transpose,
5869 const GLfloat *value)
5870{
5871 Program *program = mGLState.getProgram();
5872 program->setUniformMatrix3x4fv(location, count, transpose, value);
5873}
5874
5875void Context::uniformMatrix4x3fv(GLint location,
5876 GLsizei count,
5877 GLboolean transpose,
5878 const GLfloat *value)
5879{
5880 Program *program = mGLState.getProgram();
5881 program->setUniformMatrix4x3fv(location, count, transpose, value);
5882}
5883
Jamie Madilld7576732017-08-26 18:49:50 -04005884void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
5885{
5886 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5887 {
5888 GLuint vertexArray = arrays[arrayIndex];
5889
5890 if (arrays[arrayIndex] != 0)
5891 {
5892 VertexArray *vertexArrayObject = nullptr;
5893 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
5894 {
5895 if (vertexArrayObject != nullptr)
5896 {
5897 detachVertexArray(vertexArray);
5898 vertexArrayObject->onDestroy(this);
5899 }
5900
5901 mVertexArrayHandleAllocator.release(vertexArray);
5902 }
5903 }
5904 }
5905}
5906
5907void Context::genVertexArrays(GLsizei n, GLuint *arrays)
5908{
5909 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5910 {
5911 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
5912 mVertexArrayMap.assign(vertexArray, nullptr);
5913 arrays[arrayIndex] = vertexArray;
5914 }
5915}
5916
5917bool Context::isVertexArray(GLuint array)
5918{
5919 if (array == 0)
5920 {
5921 return GL_FALSE;
5922 }
5923
5924 VertexArray *vao = getVertexArray(array);
5925 return (vao != nullptr ? GL_TRUE : GL_FALSE);
5926}
5927
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04005928void Context::endTransformFeedback()
5929{
5930 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5931 transformFeedback->end(this);
5932}
5933
5934void Context::transformFeedbackVaryings(GLuint program,
5935 GLsizei count,
5936 const GLchar *const *varyings,
5937 GLenum bufferMode)
5938{
5939 Program *programObject = getProgram(program);
5940 ASSERT(programObject);
5941 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
5942}
5943
5944void Context::getTransformFeedbackVarying(GLuint program,
5945 GLuint index,
5946 GLsizei bufSize,
5947 GLsizei *length,
5948 GLsizei *size,
5949 GLenum *type,
5950 GLchar *name)
5951{
5952 Program *programObject = getProgram(program);
5953 ASSERT(programObject);
5954 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
5955}
5956
5957void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
5958{
5959 for (int i = 0; i < n; i++)
5960 {
5961 GLuint transformFeedback = ids[i];
5962 if (transformFeedback == 0)
5963 {
5964 continue;
5965 }
5966
5967 TransformFeedback *transformFeedbackObject = nullptr;
5968 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
5969 {
5970 if (transformFeedbackObject != nullptr)
5971 {
5972 detachTransformFeedback(transformFeedback);
5973 transformFeedbackObject->release(this);
5974 }
5975
5976 mTransformFeedbackHandleAllocator.release(transformFeedback);
5977 }
5978 }
5979}
5980
5981void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
5982{
5983 for (int i = 0; i < n; i++)
5984 {
5985 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
5986 mTransformFeedbackMap.assign(transformFeedback, nullptr);
5987 ids[i] = transformFeedback;
5988 }
5989}
5990
5991bool Context::isTransformFeedback(GLuint id)
5992{
5993 if (id == 0)
5994 {
5995 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
5996 // returns FALSE
5997 return GL_FALSE;
5998 }
5999
6000 const TransformFeedback *transformFeedback = getTransformFeedback(id);
6001 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
6002}
6003
6004void Context::pauseTransformFeedback()
6005{
6006 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6007 transformFeedback->pause();
6008}
6009
6010void Context::resumeTransformFeedback()
6011{
6012 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6013 transformFeedback->resume();
6014}
6015
Jamie Madill12e957f2017-08-26 21:42:26 -04006016void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
6017{
6018 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04006019 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04006020}
6021
Brandon Jones59770802018-04-02 13:18:42 -07006022void Context::getUniformuivRobust(GLuint program,
6023 GLint location,
6024 GLsizei bufSize,
6025 GLsizei *length,
6026 GLuint *params)
6027{
6028 getUniformuiv(program, location, params);
6029}
6030
Jamie Madill12e957f2017-08-26 21:42:26 -04006031GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
6032{
6033 const Program *programObject = getProgram(program);
6034 return programObject->getFragDataLocation(name);
6035}
6036
6037void Context::getUniformIndices(GLuint program,
6038 GLsizei uniformCount,
6039 const GLchar *const *uniformNames,
6040 GLuint *uniformIndices)
6041{
6042 const Program *programObject = getProgram(program);
6043 if (!programObject->isLinked())
6044 {
6045 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6046 {
6047 uniformIndices[uniformId] = GL_INVALID_INDEX;
6048 }
6049 }
6050 else
6051 {
6052 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6053 {
6054 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
6055 }
6056 }
6057}
6058
6059void Context::getActiveUniformsiv(GLuint program,
6060 GLsizei uniformCount,
6061 const GLuint *uniformIndices,
6062 GLenum pname,
6063 GLint *params)
6064{
6065 const Program *programObject = getProgram(program);
6066 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6067 {
6068 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08006069 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04006070 }
6071}
6072
6073GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
6074{
6075 const Program *programObject = getProgram(program);
6076 return programObject->getUniformBlockIndex(uniformBlockName);
6077}
6078
6079void Context::getActiveUniformBlockiv(GLuint program,
6080 GLuint uniformBlockIndex,
6081 GLenum pname,
6082 GLint *params)
6083{
6084 const Program *programObject = getProgram(program);
6085 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
6086}
6087
Brandon Jones59770802018-04-02 13:18:42 -07006088void Context::getActiveUniformBlockivRobust(GLuint program,
6089 GLuint uniformBlockIndex,
6090 GLenum pname,
6091 GLsizei bufSize,
6092 GLsizei *length,
6093 GLint *params)
6094{
6095 getActiveUniformBlockiv(program, uniformBlockIndex, pname, params);
6096}
6097
Jamie Madill12e957f2017-08-26 21:42:26 -04006098void Context::getActiveUniformBlockName(GLuint program,
6099 GLuint uniformBlockIndex,
6100 GLsizei bufSize,
6101 GLsizei *length,
6102 GLchar *uniformBlockName)
6103{
6104 const Program *programObject = getProgram(program);
6105 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
6106}
6107
6108void Context::uniformBlockBinding(GLuint program,
6109 GLuint uniformBlockIndex,
6110 GLuint uniformBlockBinding)
6111{
6112 Program *programObject = getProgram(program);
6113 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
6114}
6115
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006116GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
6117{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006118 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
6119 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006120
Jamie Madill70b5bb02017-08-28 13:32:37 -04006121 Sync *syncObject = getSync(syncHandle);
6122 Error error = syncObject->set(condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006123 if (error.isError())
6124 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04006125 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006126 handleError(error);
6127 return nullptr;
6128 }
6129
Jamie Madill70b5bb02017-08-28 13:32:37 -04006130 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006131}
6132
6133GLboolean Context::isSync(GLsync sync)
6134{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006135 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006136}
6137
6138GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6139{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006140 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006141
6142 GLenum result = GL_WAIT_FAILED;
6143 handleError(syncObject->clientWait(flags, timeout, &result));
6144 return result;
6145}
6146
6147void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6148{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006149 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006150 handleError(syncObject->serverWait(flags, timeout));
6151}
6152
6153void Context::getInteger64v(GLenum pname, GLint64 *params)
6154{
6155 GLenum nativeType = GL_NONE;
6156 unsigned int numParams = 0;
6157 getQueryParameterInfo(pname, &nativeType, &numParams);
6158
6159 if (nativeType == GL_INT_64_ANGLEX)
6160 {
6161 getInteger64vImpl(pname, params);
6162 }
6163 else
6164 {
6165 CastStateValues(this, nativeType, pname, numParams, params);
6166 }
6167}
6168
Brandon Jones59770802018-04-02 13:18:42 -07006169void Context::getInteger64vRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint64 *data)
6170{
6171 getInteger64v(pname, data);
6172}
6173
Corentin Wallez336129f2017-10-17 15:55:40 -04006174void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04006175{
6176 Buffer *buffer = mGLState.getTargetBuffer(target);
6177 QueryBufferParameteri64v(buffer, pname, params);
6178}
6179
Brandon Jones59770802018-04-02 13:18:42 -07006180void Context::getBufferParameteri64vRobust(BufferBinding target,
6181 GLenum pname,
6182 GLsizei bufSize,
6183 GLsizei *length,
6184 GLint64 *params)
6185{
6186 getBufferParameteri64v(target, pname, params);
6187}
6188
Jamie Madill3ef140a2017-08-26 23:11:21 -04006189void Context::genSamplers(GLsizei count, GLuint *samplers)
6190{
6191 for (int i = 0; i < count; i++)
6192 {
6193 samplers[i] = mState.mSamplers->createSampler();
6194 }
6195}
6196
6197void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
6198{
6199 for (int i = 0; i < count; i++)
6200 {
6201 GLuint sampler = samplers[i];
6202
6203 if (mState.mSamplers->getSampler(sampler))
6204 {
6205 detachSampler(sampler);
6206 }
6207
6208 mState.mSamplers->deleteObject(this, sampler);
6209 }
6210}
6211
6212void Context::getInternalformativ(GLenum target,
6213 GLenum internalformat,
6214 GLenum pname,
6215 GLsizei bufSize,
6216 GLint *params)
6217{
6218 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
6219 QueryInternalFormativ(formatCaps, pname, bufSize, params);
6220}
6221
Brandon Jones59770802018-04-02 13:18:42 -07006222void Context::getInternalformativRobust(GLenum target,
6223 GLenum internalformat,
6224 GLenum pname,
6225 GLsizei bufSize,
6226 GLsizei *length,
6227 GLint *params)
6228{
6229 getInternalformativ(target, internalformat, pname, bufSize, params);
6230}
6231
Jiajia Qin5451d532017-11-16 17:16:34 +08006232void Context::programUniform1i(GLuint program, GLint location, GLint v0)
6233{
6234 programUniform1iv(program, location, 1, &v0);
6235}
6236
6237void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
6238{
6239 GLint xy[2] = {v0, v1};
6240 programUniform2iv(program, location, 1, xy);
6241}
6242
6243void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
6244{
6245 GLint xyz[3] = {v0, v1, v2};
6246 programUniform3iv(program, location, 1, xyz);
6247}
6248
6249void Context::programUniform4i(GLuint program,
6250 GLint location,
6251 GLint v0,
6252 GLint v1,
6253 GLint v2,
6254 GLint v3)
6255{
6256 GLint xyzw[4] = {v0, v1, v2, v3};
6257 programUniform4iv(program, location, 1, xyzw);
6258}
6259
6260void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
6261{
6262 programUniform1uiv(program, location, 1, &v0);
6263}
6264
6265void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
6266{
6267 GLuint xy[2] = {v0, v1};
6268 programUniform2uiv(program, location, 1, xy);
6269}
6270
6271void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
6272{
6273 GLuint xyz[3] = {v0, v1, v2};
6274 programUniform3uiv(program, location, 1, xyz);
6275}
6276
6277void Context::programUniform4ui(GLuint program,
6278 GLint location,
6279 GLuint v0,
6280 GLuint v1,
6281 GLuint v2,
6282 GLuint v3)
6283{
6284 GLuint xyzw[4] = {v0, v1, v2, v3};
6285 programUniform4uiv(program, location, 1, xyzw);
6286}
6287
6288void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
6289{
6290 programUniform1fv(program, location, 1, &v0);
6291}
6292
6293void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
6294{
6295 GLfloat xy[2] = {v0, v1};
6296 programUniform2fv(program, location, 1, xy);
6297}
6298
6299void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
6300{
6301 GLfloat xyz[3] = {v0, v1, v2};
6302 programUniform3fv(program, location, 1, xyz);
6303}
6304
6305void Context::programUniform4f(GLuint program,
6306 GLint location,
6307 GLfloat v0,
6308 GLfloat v1,
6309 GLfloat v2,
6310 GLfloat v3)
6311{
6312 GLfloat xyzw[4] = {v0, v1, v2, v3};
6313 programUniform4fv(program, location, 1, xyzw);
6314}
6315
Jamie Madill81c2e252017-09-09 23:32:46 -04006316void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6317{
6318 Program *programObject = getProgram(program);
6319 ASSERT(programObject);
6320 if (programObject->setUniform1iv(location, count, value) ==
6321 Program::SetUniformResult::SamplerChanged)
6322 {
6323 mGLState.setObjectDirty(GL_PROGRAM);
6324 }
6325}
6326
Jiajia Qin5451d532017-11-16 17:16:34 +08006327void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6328{
6329 Program *programObject = getProgram(program);
6330 ASSERT(programObject);
6331 programObject->setUniform2iv(location, count, value);
6332}
6333
6334void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6335{
6336 Program *programObject = getProgram(program);
6337 ASSERT(programObject);
6338 programObject->setUniform3iv(location, count, value);
6339}
6340
6341void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6342{
6343 Program *programObject = getProgram(program);
6344 ASSERT(programObject);
6345 programObject->setUniform4iv(location, count, value);
6346}
6347
6348void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6349{
6350 Program *programObject = getProgram(program);
6351 ASSERT(programObject);
6352 programObject->setUniform1uiv(location, count, value);
6353}
6354
6355void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6356{
6357 Program *programObject = getProgram(program);
6358 ASSERT(programObject);
6359 programObject->setUniform2uiv(location, count, value);
6360}
6361
6362void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6363{
6364 Program *programObject = getProgram(program);
6365 ASSERT(programObject);
6366 programObject->setUniform3uiv(location, count, value);
6367}
6368
6369void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6370{
6371 Program *programObject = getProgram(program);
6372 ASSERT(programObject);
6373 programObject->setUniform4uiv(location, count, value);
6374}
6375
6376void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6377{
6378 Program *programObject = getProgram(program);
6379 ASSERT(programObject);
6380 programObject->setUniform1fv(location, count, value);
6381}
6382
6383void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6384{
6385 Program *programObject = getProgram(program);
6386 ASSERT(programObject);
6387 programObject->setUniform2fv(location, count, value);
6388}
6389
6390void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6391{
6392 Program *programObject = getProgram(program);
6393 ASSERT(programObject);
6394 programObject->setUniform3fv(location, count, value);
6395}
6396
6397void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6398{
6399 Program *programObject = getProgram(program);
6400 ASSERT(programObject);
6401 programObject->setUniform4fv(location, count, value);
6402}
6403
6404void Context::programUniformMatrix2fv(GLuint program,
6405 GLint location,
6406 GLsizei count,
6407 GLboolean transpose,
6408 const GLfloat *value)
6409{
6410 Program *programObject = getProgram(program);
6411 ASSERT(programObject);
6412 programObject->setUniformMatrix2fv(location, count, transpose, value);
6413}
6414
6415void Context::programUniformMatrix3fv(GLuint program,
6416 GLint location,
6417 GLsizei count,
6418 GLboolean transpose,
6419 const GLfloat *value)
6420{
6421 Program *programObject = getProgram(program);
6422 ASSERT(programObject);
6423 programObject->setUniformMatrix3fv(location, count, transpose, value);
6424}
6425
6426void Context::programUniformMatrix4fv(GLuint program,
6427 GLint location,
6428 GLsizei count,
6429 GLboolean transpose,
6430 const GLfloat *value)
6431{
6432 Program *programObject = getProgram(program);
6433 ASSERT(programObject);
6434 programObject->setUniformMatrix4fv(location, count, transpose, value);
6435}
6436
6437void Context::programUniformMatrix2x3fv(GLuint program,
6438 GLint location,
6439 GLsizei count,
6440 GLboolean transpose,
6441 const GLfloat *value)
6442{
6443 Program *programObject = getProgram(program);
6444 ASSERT(programObject);
6445 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
6446}
6447
6448void Context::programUniformMatrix3x2fv(GLuint program,
6449 GLint location,
6450 GLsizei count,
6451 GLboolean transpose,
6452 const GLfloat *value)
6453{
6454 Program *programObject = getProgram(program);
6455 ASSERT(programObject);
6456 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
6457}
6458
6459void Context::programUniformMatrix2x4fv(GLuint program,
6460 GLint location,
6461 GLsizei count,
6462 GLboolean transpose,
6463 const GLfloat *value)
6464{
6465 Program *programObject = getProgram(program);
6466 ASSERT(programObject);
6467 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
6468}
6469
6470void Context::programUniformMatrix4x2fv(GLuint program,
6471 GLint location,
6472 GLsizei count,
6473 GLboolean transpose,
6474 const GLfloat *value)
6475{
6476 Program *programObject = getProgram(program);
6477 ASSERT(programObject);
6478 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
6479}
6480
6481void Context::programUniformMatrix3x4fv(GLuint program,
6482 GLint location,
6483 GLsizei count,
6484 GLboolean transpose,
6485 const GLfloat *value)
6486{
6487 Program *programObject = getProgram(program);
6488 ASSERT(programObject);
6489 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
6490}
6491
6492void Context::programUniformMatrix4x3fv(GLuint program,
6493 GLint location,
6494 GLsizei count,
6495 GLboolean transpose,
6496 const GLfloat *value)
6497{
6498 Program *programObject = getProgram(program);
6499 ASSERT(programObject);
6500 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
6501}
6502
Jamie Madill81c2e252017-09-09 23:32:46 -04006503void Context::onTextureChange(const Texture *texture)
6504{
6505 // Conservatively assume all textures are dirty.
6506 // TODO(jmadill): More fine-grained update.
6507 mGLState.setObjectDirty(GL_TEXTURE);
6508}
6509
James Darpiniane8a93c62018-01-04 18:02:24 -08006510bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
6511{
6512 return mGLState.isCurrentTransformFeedback(tf);
6513}
6514bool Context::isCurrentVertexArray(const VertexArray *va) const
6515{
6516 return mGLState.isCurrentVertexArray(va);
6517}
6518
Yunchao Hea336b902017-08-02 16:05:21 +08006519void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
6520{
6521 for (int i = 0; i < count; i++)
6522 {
6523 pipelines[i] = createProgramPipeline();
6524 }
6525}
6526
6527void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
6528{
6529 for (int i = 0; i < count; i++)
6530 {
6531 if (pipelines[i] != 0)
6532 {
6533 deleteProgramPipeline(pipelines[i]);
6534 }
6535 }
6536}
6537
6538GLboolean Context::isProgramPipeline(GLuint pipeline)
6539{
6540 if (pipeline == 0)
6541 {
6542 return GL_FALSE;
6543 }
6544
6545 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
6546}
6547
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006548void Context::finishFenceNV(GLuint fence)
6549{
6550 FenceNV *fenceObject = getFenceNV(fence);
6551
6552 ASSERT(fenceObject && fenceObject->isSet());
6553 handleError(fenceObject->finish());
6554}
6555
6556void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
6557{
6558 FenceNV *fenceObject = getFenceNV(fence);
6559
6560 ASSERT(fenceObject && fenceObject->isSet());
6561
6562 switch (pname)
6563 {
6564 case GL_FENCE_STATUS_NV:
6565 {
6566 // GL_NV_fence spec:
6567 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
6568 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
6569 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
6570 GLboolean status = GL_TRUE;
6571 if (fenceObject->getStatus() != GL_TRUE)
6572 {
6573 ANGLE_CONTEXT_TRY(fenceObject->test(&status));
6574 }
6575 *params = status;
6576 break;
6577 }
6578
6579 case GL_FENCE_CONDITION_NV:
6580 {
6581 *params = static_cast<GLint>(fenceObject->getCondition());
6582 break;
6583 }
6584
6585 default:
6586 UNREACHABLE();
6587 }
6588}
6589
6590void Context::getTranslatedShaderSource(GLuint shader,
6591 GLsizei bufsize,
6592 GLsizei *length,
6593 GLchar *source)
6594{
6595 Shader *shaderObject = getShader(shader);
6596 ASSERT(shaderObject);
6597 shaderObject->getTranslatedSourceWithDebugInfo(this, bufsize, length, source);
6598}
6599
6600void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
6601{
6602 Program *programObject = getProgram(program);
6603 ASSERT(programObject);
6604
6605 programObject->getUniformfv(this, location, params);
6606}
6607
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006608void Context::getnUniformfvRobust(GLuint program,
6609 GLint location,
6610 GLsizei bufSize,
6611 GLsizei *length,
6612 GLfloat *params)
6613{
6614 UNIMPLEMENTED();
6615}
6616
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006617void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
6618{
6619 Program *programObject = getProgram(program);
6620 ASSERT(programObject);
6621
6622 programObject->getUniformiv(this, location, params);
6623}
6624
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006625void Context::getnUniformivRobust(GLuint program,
6626 GLint location,
6627 GLsizei bufSize,
6628 GLsizei *length,
6629 GLint *params)
6630{
6631 UNIMPLEMENTED();
6632}
6633
6634void Context::getnUniformuivRobust(GLuint program,
6635 GLint location,
6636 GLsizei bufSize,
6637 GLsizei *length,
6638 GLuint *params)
6639{
6640 UNIMPLEMENTED();
6641}
6642
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006643GLboolean Context::isFenceNV(GLuint fence)
6644{
6645 FenceNV *fenceObject = getFenceNV(fence);
6646
6647 if (fenceObject == nullptr)
6648 {
6649 return GL_FALSE;
6650 }
6651
6652 // GL_NV_fence spec:
6653 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
6654 // existing fence.
6655 return fenceObject->isSet();
6656}
6657
6658void Context::readnPixels(GLint x,
6659 GLint y,
6660 GLsizei width,
6661 GLsizei height,
6662 GLenum format,
6663 GLenum type,
6664 GLsizei bufSize,
6665 void *data)
6666{
6667 return readPixels(x, y, width, height, format, type, data);
6668}
6669
Jamie Madill007530e2017-12-28 14:27:04 -05006670void Context::setFenceNV(GLuint fence, GLenum condition)
6671{
6672 ASSERT(condition == GL_ALL_COMPLETED_NV);
6673
6674 FenceNV *fenceObject = getFenceNV(fence);
6675 ASSERT(fenceObject != nullptr);
6676 handleError(fenceObject->set(condition));
6677}
6678
6679GLboolean Context::testFenceNV(GLuint fence)
6680{
6681 FenceNV *fenceObject = getFenceNV(fence);
6682
6683 ASSERT(fenceObject != nullptr);
6684 ASSERT(fenceObject->isSet() == GL_TRUE);
6685
6686 GLboolean result = GL_TRUE;
6687 Error error = fenceObject->test(&result);
6688 if (error.isError())
6689 {
6690 handleError(error);
6691 return GL_TRUE;
6692 }
6693
6694 return result;
6695}
6696
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006697void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006698{
6699 Texture *texture = getTargetTexture(target);
Rafael Cintron05a449a2018-06-20 18:08:04 -07006700 egl::Image *imageObject = static_cast<egl::Image *>(image);
Corentin Wallez99d492c2018-02-27 15:17:10 -05006701 handleError(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05006702}
6703
Jamie Madillfa920eb2018-01-04 11:45:50 -05006704void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006705{
6706 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Rafael Cintron05a449a2018-06-20 18:08:04 -07006707 egl::Image *imageObject = static_cast<egl::Image *>(image);
Jamie Madill007530e2017-12-28 14:27:04 -05006708 handleError(renderbuffer->setStorageEGLImageTarget(this, imageObject));
6709}
6710
Jamie Madillfa920eb2018-01-04 11:45:50 -05006711void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
6712{
6713 UNIMPLEMENTED();
6714}
6715
Jamie Madill5b772312018-03-08 20:28:32 -05006716bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
6717{
6718 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
6719 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
6720 // to the fact that it is stored internally as a float, and so would require conversion
6721 // if returned from Context::getIntegerv. Since this conversion is already implemented
6722 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
6723 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
6724 // application.
6725 switch (pname)
6726 {
6727 case GL_COMPRESSED_TEXTURE_FORMATS:
6728 {
6729 *type = GL_INT;
6730 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
6731 return true;
6732 }
6733 case GL_SHADER_BINARY_FORMATS:
6734 {
6735 *type = GL_INT;
6736 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
6737 return true;
6738 }
6739
6740 case GL_MAX_VERTEX_ATTRIBS:
6741 case GL_MAX_VERTEX_UNIFORM_VECTORS:
6742 case GL_MAX_VARYING_VECTORS:
6743 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
6744 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
6745 case GL_MAX_TEXTURE_IMAGE_UNITS:
6746 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
6747 case GL_MAX_RENDERBUFFER_SIZE:
6748 case GL_NUM_SHADER_BINARY_FORMATS:
6749 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
6750 case GL_ARRAY_BUFFER_BINDING:
6751 case GL_FRAMEBUFFER_BINDING:
6752 case GL_RENDERBUFFER_BINDING:
6753 case GL_CURRENT_PROGRAM:
6754 case GL_PACK_ALIGNMENT:
6755 case GL_UNPACK_ALIGNMENT:
6756 case GL_GENERATE_MIPMAP_HINT:
6757 case GL_RED_BITS:
6758 case GL_GREEN_BITS:
6759 case GL_BLUE_BITS:
6760 case GL_ALPHA_BITS:
6761 case GL_DEPTH_BITS:
6762 case GL_STENCIL_BITS:
6763 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
6764 case GL_CULL_FACE_MODE:
6765 case GL_FRONT_FACE:
6766 case GL_ACTIVE_TEXTURE:
6767 case GL_STENCIL_FUNC:
6768 case GL_STENCIL_VALUE_MASK:
6769 case GL_STENCIL_REF:
6770 case GL_STENCIL_FAIL:
6771 case GL_STENCIL_PASS_DEPTH_FAIL:
6772 case GL_STENCIL_PASS_DEPTH_PASS:
6773 case GL_STENCIL_BACK_FUNC:
6774 case GL_STENCIL_BACK_VALUE_MASK:
6775 case GL_STENCIL_BACK_REF:
6776 case GL_STENCIL_BACK_FAIL:
6777 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
6778 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
6779 case GL_DEPTH_FUNC:
6780 case GL_BLEND_SRC_RGB:
6781 case GL_BLEND_SRC_ALPHA:
6782 case GL_BLEND_DST_RGB:
6783 case GL_BLEND_DST_ALPHA:
6784 case GL_BLEND_EQUATION_RGB:
6785 case GL_BLEND_EQUATION_ALPHA:
6786 case GL_STENCIL_WRITEMASK:
6787 case GL_STENCIL_BACK_WRITEMASK:
6788 case GL_STENCIL_CLEAR_VALUE:
6789 case GL_SUBPIXEL_BITS:
6790 case GL_MAX_TEXTURE_SIZE:
6791 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
6792 case GL_SAMPLE_BUFFERS:
6793 case GL_SAMPLES:
6794 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
6795 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
6796 case GL_TEXTURE_BINDING_2D:
6797 case GL_TEXTURE_BINDING_CUBE_MAP:
6798 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
6799 {
6800 *type = GL_INT;
6801 *numParams = 1;
6802 return true;
6803 }
6804 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6805 {
6806 if (!getExtensions().packReverseRowOrder)
6807 {
6808 return false;
6809 }
6810 *type = GL_INT;
6811 *numParams = 1;
6812 return true;
6813 }
6814 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
6815 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
6816 {
6817 if (!getExtensions().textureRectangle)
6818 {
6819 return false;
6820 }
6821 *type = GL_INT;
6822 *numParams = 1;
6823 return true;
6824 }
6825 case GL_MAX_DRAW_BUFFERS_EXT:
6826 case GL_MAX_COLOR_ATTACHMENTS_EXT:
6827 {
6828 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
6829 {
6830 return false;
6831 }
6832 *type = GL_INT;
6833 *numParams = 1;
6834 return true;
6835 }
6836 case GL_MAX_VIEWPORT_DIMS:
6837 {
6838 *type = GL_INT;
6839 *numParams = 2;
6840 return true;
6841 }
6842 case GL_VIEWPORT:
6843 case GL_SCISSOR_BOX:
6844 {
6845 *type = GL_INT;
6846 *numParams = 4;
6847 return true;
6848 }
6849 case GL_SHADER_COMPILER:
6850 case GL_SAMPLE_COVERAGE_INVERT:
6851 case GL_DEPTH_WRITEMASK:
6852 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
6853 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
6854 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
6855 // bool-natural
6856 case GL_SAMPLE_COVERAGE:
6857 case GL_SCISSOR_TEST:
6858 case GL_STENCIL_TEST:
6859 case GL_DEPTH_TEST:
6860 case GL_BLEND:
6861 case GL_DITHER:
6862 case GL_CONTEXT_ROBUST_ACCESS_EXT:
6863 {
6864 *type = GL_BOOL;
6865 *numParams = 1;
6866 return true;
6867 }
6868 case GL_COLOR_WRITEMASK:
6869 {
6870 *type = GL_BOOL;
6871 *numParams = 4;
6872 return true;
6873 }
6874 case GL_POLYGON_OFFSET_FACTOR:
6875 case GL_POLYGON_OFFSET_UNITS:
6876 case GL_SAMPLE_COVERAGE_VALUE:
6877 case GL_DEPTH_CLEAR_VALUE:
6878 case GL_LINE_WIDTH:
6879 {
6880 *type = GL_FLOAT;
6881 *numParams = 1;
6882 return true;
6883 }
6884 case GL_ALIASED_LINE_WIDTH_RANGE:
6885 case GL_ALIASED_POINT_SIZE_RANGE:
6886 case GL_DEPTH_RANGE:
6887 {
6888 *type = GL_FLOAT;
6889 *numParams = 2;
6890 return true;
6891 }
6892 case GL_COLOR_CLEAR_VALUE:
6893 case GL_BLEND_COLOR:
6894 {
6895 *type = GL_FLOAT;
6896 *numParams = 4;
6897 return true;
6898 }
6899 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
6900 if (!getExtensions().textureFilterAnisotropic)
6901 {
6902 return false;
6903 }
6904 *type = GL_FLOAT;
6905 *numParams = 1;
6906 return true;
6907 case GL_TIMESTAMP_EXT:
6908 if (!getExtensions().disjointTimerQuery)
6909 {
6910 return false;
6911 }
6912 *type = GL_INT_64_ANGLEX;
6913 *numParams = 1;
6914 return true;
6915 case GL_GPU_DISJOINT_EXT:
6916 if (!getExtensions().disjointTimerQuery)
6917 {
6918 return false;
6919 }
6920 *type = GL_INT;
6921 *numParams = 1;
6922 return true;
6923 case GL_COVERAGE_MODULATION_CHROMIUM:
6924 if (!getExtensions().framebufferMixedSamples)
6925 {
6926 return false;
6927 }
6928 *type = GL_INT;
6929 *numParams = 1;
6930 return true;
6931 case GL_TEXTURE_BINDING_EXTERNAL_OES:
6932 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
6933 {
6934 return false;
6935 }
6936 *type = GL_INT;
6937 *numParams = 1;
6938 return true;
6939 }
6940
6941 if (getExtensions().debug)
6942 {
6943 switch (pname)
6944 {
6945 case GL_DEBUG_LOGGED_MESSAGES:
6946 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
6947 case GL_DEBUG_GROUP_STACK_DEPTH:
6948 case GL_MAX_DEBUG_MESSAGE_LENGTH:
6949 case GL_MAX_DEBUG_LOGGED_MESSAGES:
6950 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
6951 case GL_MAX_LABEL_LENGTH:
6952 *type = GL_INT;
6953 *numParams = 1;
6954 return true;
6955
6956 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
6957 case GL_DEBUG_OUTPUT:
6958 *type = GL_BOOL;
6959 *numParams = 1;
6960 return true;
6961 }
6962 }
6963
6964 if (getExtensions().multisampleCompatibility)
6965 {
6966 switch (pname)
6967 {
6968 case GL_MULTISAMPLE_EXT:
6969 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
6970 *type = GL_BOOL;
6971 *numParams = 1;
6972 return true;
6973 }
6974 }
6975
6976 if (getExtensions().pathRendering)
6977 {
6978 switch (pname)
6979 {
6980 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
6981 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
6982 *type = GL_FLOAT;
6983 *numParams = 16;
6984 return true;
6985 }
6986 }
6987
6988 if (getExtensions().bindGeneratesResource)
6989 {
6990 switch (pname)
6991 {
6992 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
6993 *type = GL_BOOL;
6994 *numParams = 1;
6995 return true;
6996 }
6997 }
6998
6999 if (getExtensions().clientArrays)
7000 {
7001 switch (pname)
7002 {
7003 case GL_CLIENT_ARRAYS_ANGLE:
7004 *type = GL_BOOL;
7005 *numParams = 1;
7006 return true;
7007 }
7008 }
7009
7010 if (getExtensions().sRGBWriteControl)
7011 {
7012 switch (pname)
7013 {
7014 case GL_FRAMEBUFFER_SRGB_EXT:
7015 *type = GL_BOOL;
7016 *numParams = 1;
7017 return true;
7018 }
7019 }
7020
7021 if (getExtensions().robustResourceInitialization &&
7022 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
7023 {
7024 *type = GL_BOOL;
7025 *numParams = 1;
7026 return true;
7027 }
7028
7029 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
7030 {
7031 *type = GL_BOOL;
7032 *numParams = 1;
7033 return true;
7034 }
7035
jchen1082af6202018-06-22 10:59:52 +08007036 if (getExtensions().parallelShaderCompile && pname == GL_MAX_SHADER_COMPILER_THREADS_KHR)
7037 {
7038 *type = GL_INT;
7039 *numParams = 1;
7040 return true;
7041 }
7042
Jamie Madill5b772312018-03-08 20:28:32 -05007043 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
7044 switch (pname)
7045 {
7046 // case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE // equivalent to FRAMEBUFFER_BINDING
7047 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
7048 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
7049 {
7050 return false;
7051 }
7052 *type = GL_INT;
7053 *numParams = 1;
7054 return true;
7055
7056 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
7057 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7058 {
7059 return false;
7060 }
7061 *type = GL_INT;
7062 *numParams = 1;
7063 return true;
7064
7065 case GL_PROGRAM_BINARY_FORMATS_OES:
7066 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7067 {
7068 return false;
7069 }
7070 *type = GL_INT;
7071 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
7072 return true;
7073
7074 case GL_PACK_ROW_LENGTH:
7075 case GL_PACK_SKIP_ROWS:
7076 case GL_PACK_SKIP_PIXELS:
7077 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
7078 {
7079 return false;
7080 }
7081 *type = GL_INT;
7082 *numParams = 1;
7083 return true;
7084 case GL_UNPACK_ROW_LENGTH:
7085 case GL_UNPACK_SKIP_ROWS:
7086 case GL_UNPACK_SKIP_PIXELS:
7087 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
7088 {
7089 return false;
7090 }
7091 *type = GL_INT;
7092 *numParams = 1;
7093 return true;
7094 case GL_VERTEX_ARRAY_BINDING:
7095 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
7096 {
7097 return false;
7098 }
7099 *type = GL_INT;
7100 *numParams = 1;
7101 return true;
7102 case GL_PIXEL_PACK_BUFFER_BINDING:
7103 case GL_PIXEL_UNPACK_BUFFER_BINDING:
7104 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
7105 {
7106 return false;
7107 }
7108 *type = GL_INT;
7109 *numParams = 1;
7110 return true;
7111 case GL_MAX_SAMPLES:
7112 {
7113 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
7114 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
7115 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
7116 {
7117 return false;
7118 }
7119 *type = GL_INT;
7120 *numParams = 1;
7121 return true;
7122
7123 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
7124 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
7125 {
7126 return false;
7127 }
7128 *type = GL_INT;
7129 *numParams = 1;
7130 return true;
7131 }
7132 }
7133
7134 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
7135 {
7136 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
7137 {
7138 return false;
7139 }
7140 *type = GL_INT;
7141 *numParams = 1;
7142 return true;
7143 }
7144
7145 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
7146 {
7147 *type = GL_INT;
7148 *numParams = 1;
7149 return true;
7150 }
7151
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007152 if (getClientVersion() < Version(2, 0))
7153 {
7154 switch (pname)
7155 {
7156 case GL_ALPHA_TEST_FUNC:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007157 case GL_CLIENT_ACTIVE_TEXTURE:
7158 case GL_MATRIX_MODE:
7159 case GL_MAX_TEXTURE_UNITS:
7160 case GL_MAX_MODELVIEW_STACK_DEPTH:
7161 case GL_MAX_PROJECTION_STACK_DEPTH:
7162 case GL_MAX_TEXTURE_STACK_DEPTH:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007163 case GL_MAX_LIGHTS:
Lingfeng Yang060088a2018-05-30 20:40:57 -07007164 case GL_MAX_CLIP_PLANES:
Lingfeng Yangabb09f12018-04-16 10:43:53 -07007165 case GL_VERTEX_ARRAY_STRIDE:
7166 case GL_NORMAL_ARRAY_STRIDE:
7167 case GL_COLOR_ARRAY_STRIDE:
7168 case GL_TEXTURE_COORD_ARRAY_STRIDE:
7169 case GL_VERTEX_ARRAY_SIZE:
7170 case GL_COLOR_ARRAY_SIZE:
7171 case GL_TEXTURE_COORD_ARRAY_SIZE:
7172 case GL_VERTEX_ARRAY_TYPE:
7173 case GL_NORMAL_ARRAY_TYPE:
7174 case GL_COLOR_ARRAY_TYPE:
7175 case GL_TEXTURE_COORD_ARRAY_TYPE:
7176 case GL_VERTEX_ARRAY_BUFFER_BINDING:
7177 case GL_NORMAL_ARRAY_BUFFER_BINDING:
7178 case GL_COLOR_ARRAY_BUFFER_BINDING:
7179 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
7180 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
7181 case GL_POINT_SIZE_ARRAY_TYPE_OES:
7182 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
Lingfeng Yanga0cfa872018-05-30 21:12:17 -07007183 case GL_SHADE_MODEL:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007184 *type = GL_INT;
7185 *numParams = 1;
7186 return true;
7187 case GL_ALPHA_TEST_REF:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007188 case GL_FOG_DENSITY:
7189 case GL_FOG_START:
7190 case GL_FOG_END:
7191 case GL_FOG_MODE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007192 case GL_POINT_SIZE:
7193 case GL_POINT_SIZE_MIN:
7194 case GL_POINT_SIZE_MAX:
7195 case GL_POINT_FADE_THRESHOLD_SIZE:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007196 *type = GL_FLOAT;
7197 *numParams = 1;
7198 return true;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007199 case GL_SMOOTH_POINT_SIZE_RANGE:
7200 *type = GL_FLOAT;
7201 *numParams = 2;
7202 return true;
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007203 case GL_CURRENT_COLOR:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007204 case GL_CURRENT_TEXTURE_COORDS:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007205 case GL_LIGHT_MODEL_AMBIENT:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007206 case GL_FOG_COLOR:
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007207 *type = GL_FLOAT;
7208 *numParams = 4;
7209 return true;
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007210 case GL_CURRENT_NORMAL:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007211 case GL_POINT_DISTANCE_ATTENUATION:
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007212 *type = GL_FLOAT;
7213 *numParams = 3;
7214 return true;
Lingfeng Yang3a41af62018-04-09 07:28:56 -07007215 case GL_MODELVIEW_MATRIX:
7216 case GL_PROJECTION_MATRIX:
7217 case GL_TEXTURE_MATRIX:
7218 *type = GL_FLOAT;
7219 *numParams = 16;
7220 return true;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007221 case GL_LIGHT_MODEL_TWO_SIDE:
7222 *type = GL_BOOL;
7223 *numParams = 1;
7224 return true;
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007225 }
7226 }
7227
Jamie Madill5b772312018-03-08 20:28:32 -05007228 if (getClientVersion() < Version(3, 0))
7229 {
7230 return false;
7231 }
7232
7233 // Check for ES3.0+ parameter names
7234 switch (pname)
7235 {
7236 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
7237 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
7238 case GL_UNIFORM_BUFFER_BINDING:
7239 case GL_TRANSFORM_FEEDBACK_BINDING:
7240 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7241 case GL_COPY_READ_BUFFER_BINDING:
7242 case GL_COPY_WRITE_BUFFER_BINDING:
7243 case GL_SAMPLER_BINDING:
7244 case GL_READ_BUFFER:
7245 case GL_TEXTURE_BINDING_3D:
7246 case GL_TEXTURE_BINDING_2D_ARRAY:
7247 case GL_MAX_3D_TEXTURE_SIZE:
7248 case GL_MAX_ARRAY_TEXTURE_LAYERS:
7249 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
7250 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
7251 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
7252 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
7253 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
7254 case GL_MAX_VARYING_COMPONENTS:
7255 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
7256 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
7257 case GL_MIN_PROGRAM_TEXEL_OFFSET:
7258 case GL_MAX_PROGRAM_TEXEL_OFFSET:
7259 case GL_NUM_EXTENSIONS:
7260 case GL_MAJOR_VERSION:
7261 case GL_MINOR_VERSION:
7262 case GL_MAX_ELEMENTS_INDICES:
7263 case GL_MAX_ELEMENTS_VERTICES:
7264 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
7265 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
7266 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
7267 case GL_UNPACK_IMAGE_HEIGHT:
7268 case GL_UNPACK_SKIP_IMAGES:
7269 {
7270 *type = GL_INT;
7271 *numParams = 1;
7272 return true;
7273 }
7274
7275 case GL_MAX_ELEMENT_INDEX:
7276 case GL_MAX_UNIFORM_BLOCK_SIZE:
7277 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
7278 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
7279 case GL_MAX_SERVER_WAIT_TIMEOUT:
7280 {
7281 *type = GL_INT_64_ANGLEX;
7282 *numParams = 1;
7283 return true;
7284 }
7285
7286 case GL_TRANSFORM_FEEDBACK_ACTIVE:
7287 case GL_TRANSFORM_FEEDBACK_PAUSED:
7288 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
7289 case GL_RASTERIZER_DISCARD:
7290 {
7291 *type = GL_BOOL;
7292 *numParams = 1;
7293 return true;
7294 }
7295
7296 case GL_MAX_TEXTURE_LOD_BIAS:
7297 {
7298 *type = GL_FLOAT;
7299 *numParams = 1;
7300 return true;
7301 }
7302 }
7303
7304 if (getExtensions().requestExtension)
7305 {
7306 switch (pname)
7307 {
7308 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
7309 *type = GL_INT;
7310 *numParams = 1;
7311 return true;
7312 }
7313 }
7314
7315 if (getClientVersion() < Version(3, 1))
7316 {
7317 return false;
7318 }
7319
7320 switch (pname)
7321 {
7322 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7323 case GL_DRAW_INDIRECT_BUFFER_BINDING:
7324 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
7325 case GL_MAX_FRAMEBUFFER_WIDTH:
7326 case GL_MAX_FRAMEBUFFER_HEIGHT:
7327 case GL_MAX_FRAMEBUFFER_SAMPLES:
7328 case GL_MAX_SAMPLE_MASK_WORDS:
7329 case GL_MAX_COLOR_TEXTURE_SAMPLES:
7330 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
7331 case GL_MAX_INTEGER_SAMPLES:
7332 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
7333 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
7334 case GL_MAX_VERTEX_ATTRIB_STRIDE:
7335 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
7336 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
7337 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
7338 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
7339 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
7340 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
7341 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
7342 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
7343 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
7344 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
7345 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
7346 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
7347 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
7348 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
7349 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
7350 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
7351 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
7352 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
7353 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
7354 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
7355 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
7356 case GL_MAX_UNIFORM_LOCATIONS:
7357 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
7358 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
7359 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
7360 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
7361 case GL_MAX_IMAGE_UNITS:
7362 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
7363 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
7364 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
7365 case GL_SHADER_STORAGE_BUFFER_BINDING:
7366 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
7367 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
7368 *type = GL_INT;
7369 *numParams = 1;
7370 return true;
7371 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7372 *type = GL_INT_64_ANGLEX;
7373 *numParams = 1;
7374 return true;
7375 case GL_SAMPLE_MASK:
7376 *type = GL_BOOL;
7377 *numParams = 1;
7378 return true;
7379 }
7380
7381 if (getExtensions().geometryShader)
7382 {
7383 switch (pname)
7384 {
7385 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7386 case GL_LAYER_PROVOKING_VERTEX_EXT:
7387 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7388 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7389 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7390 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7391 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7392 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7393 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7394 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7395 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7396 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7397 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7398 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7399 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7400 *type = GL_INT;
7401 *numParams = 1;
7402 return true;
7403 }
7404 }
7405
7406 return false;
7407}
7408
7409bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7410{
7411 if (getClientVersion() < Version(3, 0))
7412 {
7413 return false;
7414 }
7415
7416 switch (target)
7417 {
7418 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7419 case GL_UNIFORM_BUFFER_BINDING:
7420 {
7421 *type = GL_INT;
7422 *numParams = 1;
7423 return true;
7424 }
7425 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7426 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7427 case GL_UNIFORM_BUFFER_START:
7428 case GL_UNIFORM_BUFFER_SIZE:
7429 {
7430 *type = GL_INT_64_ANGLEX;
7431 *numParams = 1;
7432 return true;
7433 }
7434 }
7435
7436 if (getClientVersion() < Version(3, 1))
7437 {
7438 return false;
7439 }
7440
7441 switch (target)
7442 {
7443 case GL_IMAGE_BINDING_LAYERED:
7444 {
7445 *type = GL_BOOL;
7446 *numParams = 1;
7447 return true;
7448 }
7449 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7450 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7451 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7452 case GL_SHADER_STORAGE_BUFFER_BINDING:
7453 case GL_VERTEX_BINDING_BUFFER:
7454 case GL_VERTEX_BINDING_DIVISOR:
7455 case GL_VERTEX_BINDING_OFFSET:
7456 case GL_VERTEX_BINDING_STRIDE:
7457 case GL_SAMPLE_MASK_VALUE:
7458 case GL_IMAGE_BINDING_NAME:
7459 case GL_IMAGE_BINDING_LEVEL:
7460 case GL_IMAGE_BINDING_LAYER:
7461 case GL_IMAGE_BINDING_ACCESS:
7462 case GL_IMAGE_BINDING_FORMAT:
7463 {
7464 *type = GL_INT;
7465 *numParams = 1;
7466 return true;
7467 }
7468 case GL_ATOMIC_COUNTER_BUFFER_START:
7469 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
7470 case GL_SHADER_STORAGE_BUFFER_START:
7471 case GL_SHADER_STORAGE_BUFFER_SIZE:
7472 {
7473 *type = GL_INT_64_ANGLEX;
7474 *numParams = 1;
7475 return true;
7476 }
7477 }
7478
7479 return false;
7480}
7481
7482Program *Context::getProgram(GLuint handle) const
7483{
7484 return mState.mShaderPrograms->getProgram(handle);
7485}
7486
7487Shader *Context::getShader(GLuint handle) const
7488{
7489 return mState.mShaderPrograms->getShader(handle);
7490}
7491
7492bool Context::isTextureGenerated(GLuint texture) const
7493{
7494 return mState.mTextures->isHandleGenerated(texture);
7495}
7496
7497bool Context::isBufferGenerated(GLuint buffer) const
7498{
7499 return mState.mBuffers->isHandleGenerated(buffer);
7500}
7501
7502bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
7503{
7504 return mState.mRenderbuffers->isHandleGenerated(renderbuffer);
7505}
7506
7507bool Context::isFramebufferGenerated(GLuint framebuffer) const
7508{
7509 return mState.mFramebuffers->isHandleGenerated(framebuffer);
7510}
7511
7512bool Context::isProgramPipelineGenerated(GLuint pipeline) const
7513{
7514 return mState.mPipelines->isHandleGenerated(pipeline);
7515}
7516
7517bool Context::usingDisplayTextureShareGroup() const
7518{
7519 return mDisplayTextureShareGroup;
7520}
7521
7522GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
7523{
7524 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
7525 internalformat == GL_DEPTH_STENCIL
7526 ? GL_DEPTH24_STENCIL8
7527 : internalformat;
7528}
7529
jchen1082af6202018-06-22 10:59:52 +08007530void Context::maxShaderCompilerThreads(GLuint count)
7531{
7532 mGLState.setMaxShaderCompilerThreads(count);
7533}
7534
Jamie Madill6b873dd2018-07-12 23:56:30 -04007535// ErrorSet implementation.
7536ErrorSet::ErrorSet(Context *context) : mContext(context)
7537{
7538}
7539
7540ErrorSet::~ErrorSet() = default;
7541
7542void ErrorSet::handleError(const Error &error)
7543{
7544 // This internal enum is used to filter internal errors that are already handled.
7545 // TODO(jmadill): Remove this when refactor is done. http://anglebug.com/2491
7546 if (error.getCode() == GL_INTERNAL_ERROR_ANGLEX)
7547 {
7548 return;
7549 }
7550
7551 if (ANGLE_UNLIKELY(error.isError()))
7552 {
7553 GLenum code = error.getCode();
7554 mErrors.insert(code);
7555 if (code == GL_OUT_OF_MEMORY && mContext->getWorkarounds().loseContextOnOutOfMemory)
7556 {
7557 mContext->markContextLost();
7558 }
7559
7560 ASSERT(!error.getMessage().empty());
7561 mContext->getGLState().getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR,
7562 error.getID(), GL_DEBUG_SEVERITY_HIGH,
7563 error.getMessage());
7564 }
7565}
7566
7567bool ErrorSet::empty() const
7568{
7569 return mErrors.empty();
7570}
7571
7572GLenum ErrorSet::popError()
7573{
7574 ASSERT(!empty());
7575 GLenum error = *mErrors.begin();
7576 mErrors.erase(mErrors.begin());
7577 return error;
7578}
Jamie Madillc29968b2016-01-20 11:17:23 -05007579} // namespace gl