blob: 54f8fd3bce793b2f0362cba2a1881ffda0d02c62 [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
3094 supportedExtensions.pointSizeArray = true;
Lingfeng Yang23dc90b2018-04-23 09:01:49 -07003095 supportedExtensions.textureCubeMap = true;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003096 supportedExtensions.pointSprite = true;
jchen1082af6202018-06-22 10:59:52 +08003097 supportedExtensions.parallelShaderCompile = false;
Geoff Langb0f917f2017-12-05 13:41:54 -05003098 }
3099
3100 if (getClientVersion() < ES_3_0)
3101 {
3102 // Disable ES3+ extensions
3103 supportedExtensions.colorBufferFloat = false;
3104 supportedExtensions.eglImageExternalEssl3 = false;
3105 supportedExtensions.textureNorm16 = false;
3106 supportedExtensions.multiview = false;
3107 supportedExtensions.maxViews = 1u;
3108 }
3109
3110 if (getClientVersion() < ES_3_1)
3111 {
3112 // Disable ES3.1+ extensions
3113 supportedExtensions.geometryShader = false;
3114 }
3115
3116 if (getClientVersion() > ES_2_0)
3117 {
3118 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
3119 // supportedExtensions.sRGB = false;
3120 }
3121
3122 // Some extensions are always available because they are implemented in the GL layer.
3123 supportedExtensions.bindUniformLocation = true;
3124 supportedExtensions.vertexArrayObject = true;
3125 supportedExtensions.bindGeneratesResource = true;
3126 supportedExtensions.clientArrays = true;
3127 supportedExtensions.requestExtension = true;
3128
3129 // Enable the no error extension if the context was created with the flag.
3130 supportedExtensions.noError = mSkipValidation;
3131
3132 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Geoff Lang33f11fb2018-05-07 13:42:47 -04003133 supportedExtensions.surfacelessContext = mSurfacelessSupported;
Geoff Langb0f917f2017-12-05 13:41:54 -05003134
3135 // Explicitly enable GL_KHR_debug
3136 supportedExtensions.debug = true;
3137 supportedExtensions.maxDebugMessageLength = 1024;
3138 supportedExtensions.maxDebugLoggedMessages = 1024;
3139 supportedExtensions.maxDebugGroupStackDepth = 1024;
3140 supportedExtensions.maxLabelLength = 1024;
3141
3142 // Explicitly enable GL_ANGLE_robust_client_memory
3143 supportedExtensions.robustClientMemory = true;
3144
3145 // Determine robust resource init availability from EGL.
Geoff Lang33f11fb2018-05-07 13:42:47 -04003146 supportedExtensions.robustResourceInitialization = mGLState.isRobustResourceInitEnabled();
Geoff Langb0f917f2017-12-05 13:41:54 -05003147
3148 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
3149 // supports it.
3150 supportedExtensions.robustBufferAccessBehavior =
3151 mRobustAccess && supportedExtensions.robustBufferAccessBehavior;
3152
3153 // Enable the cache control query unconditionally.
3154 supportedExtensions.programCacheControl = true;
3155
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003156 // Enable EGL_ANGLE_explicit_context subextensions
Geoff Lang33f11fb2018-05-07 13:42:47 -04003157 if (mExplicitContextAvailable)
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003158 {
3159 // GL_ANGLE_explicit_context_gles1
3160 supportedExtensions.explicitContextGles1 = true;
3161 // GL_ANGLE_explicit_context
3162 supportedExtensions.explicitContext = true;
3163 }
3164
Geoff Langb0f917f2017-12-05 13:41:54 -05003165 return supportedExtensions;
3166}
3167
Geoff Lang33f11fb2018-05-07 13:42:47 -04003168void Context::initCaps()
Geoff Lang493daf52014-07-03 13:38:44 -04003169{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04003170 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04003171
Geoff Lang33f11fb2018-05-07 13:42:47 -04003172 mSupportedExtensions = generateSupportedExtensions();
3173 mExtensions = mSupportedExtensions;
Lingfeng Yang01074432018-04-16 10:19:51 -07003174
3175 mLimitations = mImplementation->getNativeLimitations();
3176
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003177 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
3178 if (getClientVersion() < Version(2, 0))
3179 {
3180 mCaps.maxMultitextureUnits = 4;
3181 mCaps.maxClipPlanes = 6;
3182 mCaps.maxLights = 8;
Lingfeng Yange547aac2018-04-05 09:39:20 -07003183 mCaps.maxModelviewMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3184 mCaps.maxProjectionMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3185 mCaps.maxTextureMatrixStackDepth = Caps::GlobalMatrixStackDepth;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003186 mCaps.minSmoothPointSize = 1.0f;
3187 mCaps.maxSmoothPointSize = 1.0f;
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003188 }
3189
Luc Ferronad2ae932018-06-11 15:31:17 -04003190 // Apply/Verify implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04003191 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003192
Luc Ferronad2ae932018-06-11 15:31:17 -04003193 ASSERT(mCaps.minAliasedPointSize >= 1.0f);
3194
Jamie Madill0f80ed82017-09-19 00:24:56 -04003195 if (getClientVersion() < ES_3_1)
3196 {
3197 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
3198 }
3199 else
3200 {
3201 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
3202 }
Geoff Lang301d1612014-07-09 10:34:37 -04003203
Jiawei Shao54aafe52018-04-27 14:54:57 +08003204 LimitCap(&mCaps.maxShaderUniformBlocks[ShaderType::Vertex],
3205 IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
Jamie Madill0f80ed82017-09-19 00:24:56 -04003206 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3207 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3208
3209 // Limit textures as well, so we can use fast bitsets with texture bindings.
3210 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
Jiawei Shao54aafe52018-04-27 14:54:57 +08003211 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Vertex],
3212 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
3213 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Fragment],
3214 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04003215
Jiawei Shaodb342272017-09-27 10:21:45 +08003216 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
3217
Geoff Langc287ea62016-09-16 14:46:51 -04003218 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05003219 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04003220 for (const auto &extensionInfo : GetExtensionInfoMap())
3221 {
Geoff Lang0ab41fa2018-03-14 11:03:30 -04003222 // If the user has requested that extensions start disabled and they are requestable,
3223 // disable them.
3224 if (!mExtensionsEnabled && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04003225 {
3226 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
3227 }
3228 }
3229
3230 // Generate texture caps
3231 updateCaps();
3232}
3233
3234void Context::updateCaps()
3235{
Geoff Lang900013c2014-07-07 11:32:19 -04003236 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04003237 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04003238
Jamie Madill7b62cf92017-11-02 15:20:49 -04003239 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04003240 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04003241 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04003242 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003243
Geoff Lang0d8b7242015-09-09 14:56:53 -04003244 // Update the format caps based on the client version and extensions.
3245 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
3246 // ES3.
3247 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003248 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04003249 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003250 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Yuly Novikovf15f8862018-06-04 18:59:41 -04003251 formatCaps.textureAttachment =
3252 formatCaps.textureAttachment &&
3253 formatInfo.textureAttachmentSupport(getClientVersion(), mExtensions);
3254 formatCaps.renderbuffer = formatCaps.renderbuffer &&
3255 formatInfo.renderbufferSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04003256
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003257 // OpenGL ES does not support multisampling with non-rendererable formats
3258 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Yuly Novikovf15f8862018-06-04 18:59:41 -04003259 if (!formatCaps.renderbuffer ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003260 (getClientVersion() < ES_3_1 &&
3261 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04003262 {
Geoff Langd87878e2014-09-19 15:42:59 -04003263 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04003264 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03003265 else
3266 {
3267 // We may have limited the max samples for some required renderbuffer formats due to
3268 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
3269 GLuint formatMaxSamples = formatCaps.getMaxSamples();
3270
3271 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
3272 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
3273 // exception of signed and unsigned integer formats."
3274 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
3275 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
3276 {
3277 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
3278 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
3279 }
3280
3281 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
3282 if (getClientVersion() >= ES_3_1)
3283 {
3284 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
3285 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
3286 // the exception that the signed and unsigned integer formats are required only to
3287 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
3288 // multisamples, which must be at least one."
3289 if (formatInfo.componentType == GL_INT ||
3290 formatInfo.componentType == GL_UNSIGNED_INT)
3291 {
3292 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
3293 }
3294
3295 // GLES 3.1 section 19.3.1.
3296 if (formatCaps.texturable)
3297 {
3298 if (formatInfo.depthBits > 0)
3299 {
3300 mCaps.maxDepthTextureSamples =
3301 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
3302 }
3303 else if (formatInfo.redBits > 0)
3304 {
3305 mCaps.maxColorTextureSamples =
3306 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
3307 }
3308 }
3309 }
3310 }
Geoff Langd87878e2014-09-19 15:42:59 -04003311
3312 if (formatCaps.texturable && formatInfo.compressed)
3313 {
Geoff Langca271392017-04-05 12:30:00 -04003314 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003315 }
3316
Geoff Langca271392017-04-05 12:30:00 -04003317 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04003318 }
Jamie Madill32447362017-06-28 14:53:52 -04003319
3320 // If program binary is disabled, blank out the memory cache pointer.
Geoff Langb0f917f2017-12-05 13:41:54 -05003321 if (!mSupportedExtensions.getProgramBinary)
Jamie Madill32447362017-06-28 14:53:52 -04003322 {
3323 mMemoryProgramCache = nullptr;
3324 }
Corentin Walleze4477002017-12-01 14:39:58 -05003325
3326 // Compute which buffer types are allowed
3327 mValidBufferBindings.reset();
3328 mValidBufferBindings.set(BufferBinding::ElementArray);
3329 mValidBufferBindings.set(BufferBinding::Array);
3330
3331 if (mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
3332 {
3333 mValidBufferBindings.set(BufferBinding::PixelPack);
3334 mValidBufferBindings.set(BufferBinding::PixelUnpack);
3335 }
3336
3337 if (getClientVersion() >= ES_3_0)
3338 {
3339 mValidBufferBindings.set(BufferBinding::CopyRead);
3340 mValidBufferBindings.set(BufferBinding::CopyWrite);
3341 mValidBufferBindings.set(BufferBinding::TransformFeedback);
3342 mValidBufferBindings.set(BufferBinding::Uniform);
3343 }
3344
3345 if (getClientVersion() >= ES_3_1)
3346 {
3347 mValidBufferBindings.set(BufferBinding::AtomicCounter);
3348 mValidBufferBindings.set(BufferBinding::ShaderStorage);
3349 mValidBufferBindings.set(BufferBinding::DrawIndirect);
3350 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
3351 }
Geoff Lang493daf52014-07-03 13:38:44 -04003352}
3353
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003354void Context::initWorkarounds()
3355{
Jamie Madill761b02c2017-06-23 16:27:06 -04003356 // Apply back-end workarounds.
3357 mImplementation->applyNativeWorkarounds(&mWorkarounds);
3358
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003359 // Lose the context upon out of memory error if the application is
3360 // expecting to watch for those events.
3361 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
3362}
3363
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06003364// Return true if the draw is a no-op, else return false.
3365// A no-op draw occurs if the count of vertices is less than the minimum required to
3366// have a valid primitive for this mode (0 for points, 0-1 for lines, 0-2 for tris).
3367bool Context::noopDraw(PrimitiveMode mode, GLsizei count)
3368{
3369 return count < kMinimumPrimitiveCounts[mode];
3370}
3371
3372bool Context::noopDrawInstanced(PrimitiveMode mode, GLsizei count, GLsizei instanceCount)
3373{
3374 return (instanceCount == 0) || noopDraw(mode, count);
3375}
3376
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003377Error Context::prepareForDraw(PrimitiveMode mode)
Jamie Madill05b35b22017-10-03 09:01:44 -04003378{
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003379 if (mGLES1Renderer)
3380 {
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003381 ANGLE_TRY(mGLES1Renderer->prepareForDraw(mode, this, &mGLState));
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003382 }
3383
Geoff Langa8cb2872018-03-09 16:09:40 -05003384 ANGLE_TRY(syncDirtyObjects());
Jamie Madilla59fc192017-11-02 12:57:58 -04003385
3386 if (isRobustResourceInitEnabled())
3387 {
3388 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
3389 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
3390 }
3391
Geoff Langa8cb2872018-03-09 16:09:40 -05003392 ANGLE_TRY(syncDirtyBits());
Geoff Langd4fff502017-09-22 11:28:28 -04003393 return NoError();
3394}
3395
3396Error Context::prepareForClear(GLbitfield mask)
3397{
Geoff Langa8cb2872018-03-09 16:09:40 -05003398 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003399 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearAttachmentsInitialized(this, mask));
Geoff Langa8cb2872018-03-09 16:09:40 -05003400 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04003401 return NoError();
3402}
3403
3404Error Context::prepareForClearBuffer(GLenum buffer, GLint drawbuffer)
3405{
Geoff Langa8cb2872018-03-09 16:09:40 -05003406 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003407 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearBufferAttachmentsInitialized(this, buffer,
3408 drawbuffer));
Geoff Langa8cb2872018-03-09 16:09:40 -05003409 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill05b35b22017-10-03 09:01:44 -04003410 return NoError();
3411}
3412
Geoff Langa8cb2872018-03-09 16:09:40 -05003413Error Context::syncState()
Jamie Madill1b94d432015-08-07 13:23:23 -04003414{
Geoff Langa8cb2872018-03-09 16:09:40 -05003415 ANGLE_TRY(syncDirtyObjects());
3416 ANGLE_TRY(syncDirtyBits());
Jamie Madillbc918e72018-03-08 09:47:21 -05003417 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003418}
3419
Geoff Langa8cb2872018-03-09 16:09:40 -05003420Error Context::syncState(const State::DirtyBits &bitMask, const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04003421{
Geoff Langa8cb2872018-03-09 16:09:40 -05003422 ANGLE_TRY(syncDirtyObjects(objectMask));
3423 ANGLE_TRY(syncDirtyBits(bitMask));
Geoff Langd4fff502017-09-22 11:28:28 -04003424 return NoError();
3425}
3426
Geoff Langa8cb2872018-03-09 16:09:40 -05003427Error Context::syncDirtyBits()
Geoff Langd4fff502017-09-22 11:28:28 -04003428{
3429 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
Jamie Madill189ad872018-07-09 13:32:37 -04003430 ANGLE_TRY(mImplementation->syncState(this, dirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04003431 mGLState.clearDirtyBits();
3432 return NoError();
3433}
3434
Geoff Langa8cb2872018-03-09 16:09:40 -05003435Error Context::syncDirtyBits(const State::DirtyBits &bitMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003436{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003437 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madill189ad872018-07-09 13:32:37 -04003438 ANGLE_TRY(mImplementation->syncState(this, dirtyBits));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003439 mGLState.clearDirtyBits(dirtyBits);
Jamie Madillbc918e72018-03-08 09:47:21 -05003440 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003441}
Jamie Madillc29968b2016-01-20 11:17:23 -05003442
Geoff Langa8cb2872018-03-09 16:09:40 -05003443Error Context::syncDirtyObjects()
Geoff Langd4fff502017-09-22 11:28:28 -04003444{
3445 return mGLState.syncDirtyObjects(this);
3446}
3447
Geoff Langa8cb2872018-03-09 16:09:40 -05003448Error Context::syncDirtyObjects(const State::DirtyObjects &objectMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003449{
3450 return mGLState.syncDirtyObjects(this, objectMask);
3451}
3452
Jamie Madillc29968b2016-01-20 11:17:23 -05003453void Context::blitFramebuffer(GLint srcX0,
3454 GLint srcY0,
3455 GLint srcX1,
3456 GLint srcY1,
3457 GLint dstX0,
3458 GLint dstY0,
3459 GLint dstX1,
3460 GLint dstY1,
3461 GLbitfield mask,
3462 GLenum filter)
3463{
Qin Jiajiaaef92162018-02-27 13:51:44 +08003464 if (mask == 0)
3465 {
3466 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
3467 // buffers are copied.
3468 return;
3469 }
3470
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003471 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003472 ASSERT(drawFramebuffer);
3473
3474 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
3475 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
3476
Jamie Madillbc918e72018-03-08 09:47:21 -05003477 ANGLE_CONTEXT_TRY(syncStateForBlit());
Jamie Madillc29968b2016-01-20 11:17:23 -05003478
Jamie Madillc564c072017-06-01 12:45:42 -04003479 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003480}
Jamie Madillc29968b2016-01-20 11:17:23 -05003481
3482void Context::clear(GLbitfield mask)
3483{
Geoff Langd4fff502017-09-22 11:28:28 -04003484 ANGLE_CONTEXT_TRY(prepareForClear(mask));
3485 ANGLE_CONTEXT_TRY(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05003486}
3487
3488void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
3489{
Geoff Langd4fff502017-09-22 11:28:28 -04003490 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3491 ANGLE_CONTEXT_TRY(
3492 mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003493}
3494
3495void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3496{
Geoff Langd4fff502017-09-22 11:28:28 -04003497 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3498 ANGLE_CONTEXT_TRY(
3499 mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003500}
3501
3502void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3503{
Geoff Langd4fff502017-09-22 11:28:28 -04003504 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3505 ANGLE_CONTEXT_TRY(
3506 mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003507}
3508
3509void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3510{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003511 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003512 ASSERT(framebufferObject);
3513
3514 // If a buffer is not present, the clear has no effect
3515 if (framebufferObject->getDepthbuffer() == nullptr &&
3516 framebufferObject->getStencilbuffer() == nullptr)
3517 {
3518 return;
3519 }
3520
Geoff Langd4fff502017-09-22 11:28:28 -04003521 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3522 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003523}
3524
3525void Context::readPixels(GLint x,
3526 GLint y,
3527 GLsizei width,
3528 GLsizei height,
3529 GLenum format,
3530 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003531 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003532{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003533 if (width == 0 || height == 0)
3534 {
3535 return;
3536 }
3537
Jamie Madillbc918e72018-03-08 09:47:21 -05003538 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003539
Jamie Madillb6664922017-07-25 12:55:04 -04003540 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3541 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003542
3543 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04003544 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003545}
3546
Brandon Jones59770802018-04-02 13:18:42 -07003547void Context::readPixelsRobust(GLint x,
3548 GLint y,
3549 GLsizei width,
3550 GLsizei height,
3551 GLenum format,
3552 GLenum type,
3553 GLsizei bufSize,
3554 GLsizei *length,
3555 GLsizei *columns,
3556 GLsizei *rows,
3557 void *pixels)
3558{
3559 readPixels(x, y, width, height, format, type, pixels);
3560}
3561
3562void Context::readnPixelsRobust(GLint x,
3563 GLint y,
3564 GLsizei width,
3565 GLsizei height,
3566 GLenum format,
3567 GLenum type,
3568 GLsizei bufSize,
3569 GLsizei *length,
3570 GLsizei *columns,
3571 GLsizei *rows,
3572 void *data)
3573{
3574 readPixels(x, y, width, height, format, type, data);
3575}
3576
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003577void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003578 GLint level,
3579 GLenum internalformat,
3580 GLint x,
3581 GLint y,
3582 GLsizei width,
3583 GLsizei height,
3584 GLint border)
3585{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003586 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003587 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003588
Jamie Madillc29968b2016-01-20 11:17:23 -05003589 Rectangle sourceArea(x, y, width, height);
3590
Jamie Madill05b35b22017-10-03 09:01:44 -04003591 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003592 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003593 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003594}
3595
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003596void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003597 GLint level,
3598 GLint xoffset,
3599 GLint yoffset,
3600 GLint x,
3601 GLint y,
3602 GLsizei width,
3603 GLsizei height)
3604{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003605 if (width == 0 || height == 0)
3606 {
3607 return;
3608 }
3609
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003610 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003611 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003612
Jamie Madillc29968b2016-01-20 11:17:23 -05003613 Offset destOffset(xoffset, yoffset, 0);
3614 Rectangle sourceArea(x, y, width, height);
3615
Jamie Madill05b35b22017-10-03 09:01:44 -04003616 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003617 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003618 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003619}
3620
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003621void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003622 GLint level,
3623 GLint xoffset,
3624 GLint yoffset,
3625 GLint zoffset,
3626 GLint x,
3627 GLint y,
3628 GLsizei width,
3629 GLsizei height)
3630{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003631 if (width == 0 || height == 0)
3632 {
3633 return;
3634 }
3635
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003636 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003637 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003638
Jamie Madillc29968b2016-01-20 11:17:23 -05003639 Offset destOffset(xoffset, yoffset, zoffset);
3640 Rectangle sourceArea(x, y, width, height);
3641
Jamie Madill05b35b22017-10-03 09:01:44 -04003642 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3643 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003644 handleError(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level, destOffset,
3645 sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003646}
3647
3648void Context::framebufferTexture2D(GLenum target,
3649 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003650 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003651 GLuint texture,
3652 GLint level)
3653{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003654 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003655 ASSERT(framebuffer);
3656
3657 if (texture != 0)
3658 {
3659 Texture *textureObj = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003660 ImageIndex index = ImageIndex::MakeFromTarget(textarget, level);
Jamie Madilla02315b2017-02-23 14:14:47 -05003661 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003662 }
3663 else
3664 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003665 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003666 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003667
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003668 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003669}
3670
3671void Context::framebufferRenderbuffer(GLenum target,
3672 GLenum attachment,
3673 GLenum renderbuffertarget,
3674 GLuint renderbuffer)
3675{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003676 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003677 ASSERT(framebuffer);
3678
3679 if (renderbuffer != 0)
3680 {
3681 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003682
Jamie Madillcc129372018-04-12 09:13:18 -04003683 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003684 renderbufferObject);
3685 }
3686 else
3687 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003688 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003689 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003690
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003691 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003692}
3693
3694void Context::framebufferTextureLayer(GLenum target,
3695 GLenum attachment,
3696 GLuint texture,
3697 GLint level,
3698 GLint layer)
3699{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003700 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003701 ASSERT(framebuffer);
3702
3703 if (texture != 0)
3704 {
3705 Texture *textureObject = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003706 ImageIndex index = ImageIndex::MakeFromType(textureObject->getType(), level, layer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003707 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003708 }
3709 else
3710 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003711 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003712 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003713
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003714 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003715}
3716
Brandon Jones59770802018-04-02 13:18:42 -07003717void Context::framebufferTextureMultiviewLayered(GLenum target,
3718 GLenum attachment,
3719 GLuint texture,
3720 GLint level,
3721 GLint baseViewIndex,
3722 GLsizei numViews)
Martin Radev137032d2017-07-13 10:11:12 +03003723{
Martin Radev82ef7742017-08-08 17:44:58 +03003724 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3725 ASSERT(framebuffer);
3726
3727 if (texture != 0)
3728 {
3729 Texture *textureObj = getTexture(texture);
3730
Martin Radev18b75ba2017-08-15 15:50:40 +03003731 ImageIndex index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
Martin Radev82ef7742017-08-08 17:44:58 +03003732 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3733 numViews, baseViewIndex);
3734 }
3735 else
3736 {
3737 framebuffer->resetAttachment(this, attachment);
3738 }
3739
3740 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003741}
3742
Brandon Jones59770802018-04-02 13:18:42 -07003743void Context::framebufferTextureMultiviewSideBySide(GLenum target,
3744 GLenum attachment,
3745 GLuint texture,
3746 GLint level,
3747 GLsizei numViews,
3748 const GLint *viewportOffsets)
Martin Radev137032d2017-07-13 10:11:12 +03003749{
Martin Radev5dae57b2017-07-14 16:15:55 +03003750 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3751 ASSERT(framebuffer);
3752
3753 if (texture != 0)
3754 {
3755 Texture *textureObj = getTexture(texture);
3756
3757 ImageIndex index = ImageIndex::Make2D(level);
3758 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3759 textureObj, numViews, viewportOffsets);
3760 }
3761 else
3762 {
3763 framebuffer->resetAttachment(this, attachment);
3764 }
3765
3766 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003767}
3768
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003769void Context::framebufferTexture(GLenum target, GLenum attachment, GLuint texture, GLint level)
3770{
Jiawei Shaoa8802472018-05-28 11:17:47 +08003771 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3772 ASSERT(framebuffer);
3773
3774 if (texture != 0)
3775 {
3776 Texture *textureObj = getTexture(texture);
3777
3778 ImageIndex index = ImageIndex::MakeFromType(
3779 textureObj->getType(), level, ImageIndex::kEntireLevel, ImageIndex::kEntireLevel);
3780 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
3781 }
3782 else
3783 {
3784 framebuffer->resetAttachment(this, attachment);
3785 }
3786
3787 mGLState.setObjectDirty(target);
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003788}
3789
Jamie Madillc29968b2016-01-20 11:17:23 -05003790void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3791{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003792 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003793 ASSERT(framebuffer);
3794 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003795 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003796}
3797
3798void Context::readBuffer(GLenum mode)
3799{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003800 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003801 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003802 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003803}
3804
3805void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3806{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003807 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003808 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003809
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003810 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003811 ASSERT(framebuffer);
3812
3813 // The specification isn't clear what should be done when the framebuffer isn't complete.
3814 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003815 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003816}
3817
3818void Context::invalidateFramebuffer(GLenum target,
3819 GLsizei numAttachments,
3820 const GLenum *attachments)
3821{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003822 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003823 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003824
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003825 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003826 ASSERT(framebuffer);
3827
Jamie Madill427064d2018-04-13 16:20:34 -04003828 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003829 {
Jamie Madill437fa652016-05-03 15:13:24 -04003830 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003831 }
Jamie Madill437fa652016-05-03 15:13:24 -04003832
Jamie Madill4928b7c2017-06-20 12:57:39 -04003833 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003834}
3835
3836void Context::invalidateSubFramebuffer(GLenum target,
3837 GLsizei numAttachments,
3838 const GLenum *attachments,
3839 GLint x,
3840 GLint y,
3841 GLsizei width,
3842 GLsizei height)
3843{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003844 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003845 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003846
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003847 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003848 ASSERT(framebuffer);
3849
Jamie Madill427064d2018-04-13 16:20:34 -04003850 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003851 {
Jamie Madill437fa652016-05-03 15:13:24 -04003852 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003853 }
Jamie Madill437fa652016-05-03 15:13:24 -04003854
3855 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003856 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003857}
3858
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003859void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003860 GLint level,
3861 GLint internalformat,
3862 GLsizei width,
3863 GLsizei height,
3864 GLint border,
3865 GLenum format,
3866 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003867 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003868{
Jamie Madillbc918e72018-03-08 09:47:21 -05003869 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003870
3871 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003872 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003873 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003874 size, format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003875}
3876
Brandon Jones59770802018-04-02 13:18:42 -07003877void Context::texImage2DRobust(TextureTarget target,
3878 GLint level,
3879 GLint internalformat,
3880 GLsizei width,
3881 GLsizei height,
3882 GLint border,
3883 GLenum format,
3884 GLenum type,
3885 GLsizei bufSize,
3886 const void *pixels)
3887{
3888 texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
3889}
3890
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003891void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003892 GLint level,
3893 GLint internalformat,
3894 GLsizei width,
3895 GLsizei height,
3896 GLsizei depth,
3897 GLint border,
3898 GLenum format,
3899 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003900 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003901{
Jamie Madillbc918e72018-03-08 09:47:21 -05003902 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003903
3904 Extents size(width, height, depth);
3905 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003906 handleError(texture->setImage(this, mGLState.getUnpackState(),
3907 NonCubeTextureTypeToTarget(target), level, internalformat, size,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003908 format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003909}
3910
Brandon Jones59770802018-04-02 13:18:42 -07003911void Context::texImage3DRobust(TextureType target,
3912 GLint level,
3913 GLint internalformat,
3914 GLsizei width,
3915 GLsizei height,
3916 GLsizei depth,
3917 GLint border,
3918 GLenum format,
3919 GLenum type,
3920 GLsizei bufSize,
3921 const void *pixels)
3922{
3923 texImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels);
3924}
3925
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003926void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003927 GLint level,
3928 GLint xoffset,
3929 GLint yoffset,
3930 GLsizei width,
3931 GLsizei height,
3932 GLenum format,
3933 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003934 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003935{
3936 // Zero sized uploads are valid but no-ops
3937 if (width == 0 || height == 0)
3938 {
3939 return;
3940 }
3941
Jamie Madillbc918e72018-03-08 09:47:21 -05003942 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003943
3944 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003945 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003946 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003947 type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003948}
3949
Brandon Jones59770802018-04-02 13:18:42 -07003950void Context::texSubImage2DRobust(TextureTarget target,
3951 GLint level,
3952 GLint xoffset,
3953 GLint yoffset,
3954 GLsizei width,
3955 GLsizei height,
3956 GLenum format,
3957 GLenum type,
3958 GLsizei bufSize,
3959 const void *pixels)
3960{
3961 texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
3962}
3963
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003964void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003965 GLint level,
3966 GLint xoffset,
3967 GLint yoffset,
3968 GLint zoffset,
3969 GLsizei width,
3970 GLsizei height,
3971 GLsizei depth,
3972 GLenum format,
3973 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003974 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003975{
3976 // Zero sized uploads are valid but no-ops
3977 if (width == 0 || height == 0 || depth == 0)
3978 {
3979 return;
3980 }
3981
Jamie Madillbc918e72018-03-08 09:47:21 -05003982 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003983
3984 Box area(xoffset, yoffset, zoffset, width, height, depth);
3985 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003986 handleError(texture->setSubImage(this, mGLState.getUnpackState(),
3987 NonCubeTextureTypeToTarget(target), level, area, format, type,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003988 static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003989}
3990
Brandon Jones59770802018-04-02 13:18:42 -07003991void Context::texSubImage3DRobust(TextureType target,
3992 GLint level,
3993 GLint xoffset,
3994 GLint yoffset,
3995 GLint zoffset,
3996 GLsizei width,
3997 GLsizei height,
3998 GLsizei depth,
3999 GLenum format,
4000 GLenum type,
4001 GLsizei bufSize,
4002 const void *pixels)
4003{
4004 texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type,
4005 pixels);
4006}
4007
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004008void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004009 GLint level,
4010 GLenum internalformat,
4011 GLsizei width,
4012 GLsizei height,
4013 GLint border,
4014 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004015 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004016{
Jamie Madillbc918e72018-03-08 09:47:21 -05004017 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004018
4019 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004020 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05004021 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
4022 internalformat, size, imageSize,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004023 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004024}
4025
Brandon Jones59770802018-04-02 13:18:42 -07004026void Context::compressedTexImage2DRobust(TextureTarget target,
4027 GLint level,
4028 GLenum internalformat,
4029 GLsizei width,
4030 GLsizei height,
4031 GLint border,
4032 GLsizei imageSize,
4033 GLsizei dataSize,
4034 const GLvoid *data)
4035{
4036 compressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
4037}
4038
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004039void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004040 GLint level,
4041 GLenum internalformat,
4042 GLsizei width,
4043 GLsizei height,
4044 GLsizei depth,
4045 GLint border,
4046 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004047 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004048{
Jamie Madillbc918e72018-03-08 09:47:21 -05004049 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004050
4051 Extents size(width, height, depth);
4052 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004053 handleError(texture->setCompressedImage(
4054 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004055 size, imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004056}
4057
Brandon Jones59770802018-04-02 13:18:42 -07004058void Context::compressedTexImage3DRobust(TextureType target,
4059 GLint level,
4060 GLenum internalformat,
4061 GLsizei width,
4062 GLsizei height,
4063 GLsizei depth,
4064 GLint border,
4065 GLsizei imageSize,
4066 GLsizei dataSize,
4067 const GLvoid *data)
4068{
4069 compressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize,
4070 data);
4071}
4072
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004073void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004074 GLint level,
4075 GLint xoffset,
4076 GLint yoffset,
4077 GLsizei width,
4078 GLsizei height,
4079 GLenum format,
4080 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004081 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004082{
Jamie Madillbc918e72018-03-08 09:47:21 -05004083 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004084
4085 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004086 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05004087 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
4088 format, imageSize,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004089 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004090}
4091
Brandon Jones59770802018-04-02 13:18:42 -07004092void Context::compressedTexSubImage2DRobust(TextureTarget target,
4093 GLint level,
4094 GLint xoffset,
4095 GLint yoffset,
4096 GLsizei width,
4097 GLsizei height,
4098 GLenum format,
4099 GLsizei imageSize,
4100 GLsizei dataSize,
4101 const GLvoid *data)
4102{
4103 compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize,
4104 data);
4105}
4106
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004107void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004108 GLint level,
4109 GLint xoffset,
4110 GLint yoffset,
4111 GLint zoffset,
4112 GLsizei width,
4113 GLsizei height,
4114 GLsizei depth,
4115 GLenum format,
4116 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004117 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004118{
4119 // Zero sized uploads are valid but no-ops
4120 if (width == 0 || height == 0)
4121 {
4122 return;
4123 }
4124
Jamie Madillbc918e72018-03-08 09:47:21 -05004125 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004126
4127 Box area(xoffset, yoffset, zoffset, width, height, depth);
4128 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004129 handleError(texture->setCompressedSubImage(
4130 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004131 imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004132}
4133
Brandon Jones59770802018-04-02 13:18:42 -07004134void Context::compressedTexSubImage3DRobust(TextureType target,
4135 GLint level,
4136 GLint xoffset,
4137 GLint yoffset,
4138 GLint zoffset,
4139 GLsizei width,
4140 GLsizei height,
4141 GLsizei depth,
4142 GLenum format,
4143 GLsizei imageSize,
4144 GLsizei dataSize,
4145 const GLvoid *data)
4146{
4147 compressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format,
4148 imageSize, data);
4149}
4150
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004151void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004152{
4153 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05004154 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004155}
4156
Jamie Madill007530e2017-12-28 14:27:04 -05004157void Context::copyTexture(GLuint sourceId,
4158 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004159 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004160 GLuint destId,
4161 GLint destLevel,
4162 GLint internalFormat,
4163 GLenum destType,
4164 GLboolean unpackFlipY,
4165 GLboolean unpackPremultiplyAlpha,
4166 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004167{
Jamie Madillbc918e72018-03-08 09:47:21 -05004168 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004169
4170 gl::Texture *sourceTexture = getTexture(sourceId);
4171 gl::Texture *destTexture = getTexture(destId);
Geoff Lang92019432017-11-20 13:09:34 -05004172 handleError(destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType,
4173 sourceLevel, ConvertToBool(unpackFlipY),
4174 ConvertToBool(unpackPremultiplyAlpha),
4175 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004176}
4177
Jamie Madill007530e2017-12-28 14:27:04 -05004178void Context::copySubTexture(GLuint sourceId,
4179 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004180 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004181 GLuint destId,
4182 GLint destLevel,
4183 GLint xoffset,
4184 GLint yoffset,
4185 GLint x,
4186 GLint y,
4187 GLsizei width,
4188 GLsizei height,
4189 GLboolean unpackFlipY,
4190 GLboolean unpackPremultiplyAlpha,
4191 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004192{
4193 // Zero sized copies are valid but no-ops
4194 if (width == 0 || height == 0)
4195 {
4196 return;
4197 }
4198
Jamie Madillbc918e72018-03-08 09:47:21 -05004199 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004200
4201 gl::Texture *sourceTexture = getTexture(sourceId);
4202 gl::Texture *destTexture = getTexture(destId);
4203 Offset offset(xoffset, yoffset, 0);
4204 Rectangle area(x, y, width, height);
Geoff Lang92019432017-11-20 13:09:34 -05004205 handleError(destTexture->copySubTexture(this, destTarget, destLevel, offset, sourceLevel, area,
4206 ConvertToBool(unpackFlipY),
4207 ConvertToBool(unpackPremultiplyAlpha),
4208 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004209}
4210
Jamie Madill007530e2017-12-28 14:27:04 -05004211void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07004212{
Jamie Madillbc918e72018-03-08 09:47:21 -05004213 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07004214
4215 gl::Texture *sourceTexture = getTexture(sourceId);
4216 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05004217 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07004218}
4219
Corentin Wallez336129f2017-10-17 15:55:40 -04004220void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03004221{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004222 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004223 ASSERT(buffer);
4224
Geoff Lang496c02d2016-10-20 11:38:11 -07004225 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03004226}
4227
Brandon Jones59770802018-04-02 13:18:42 -07004228void Context::getBufferPointervRobust(BufferBinding target,
4229 GLenum pname,
4230 GLsizei bufSize,
4231 GLsizei *length,
4232 void **params)
4233{
4234 getBufferPointerv(target, pname, params);
4235}
4236
Corentin Wallez336129f2017-10-17 15:55:40 -04004237void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004238{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004239 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004240 ASSERT(buffer);
4241
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004242 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004243 if (error.isError())
4244 {
Jamie Madill437fa652016-05-03 15:13:24 -04004245 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004246 return nullptr;
4247 }
4248
4249 return buffer->getMapPointer();
4250}
4251
Corentin Wallez336129f2017-10-17 15:55:40 -04004252GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03004253{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004254 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004255 ASSERT(buffer);
4256
4257 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004258 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03004259 if (error.isError())
4260 {
Jamie Madill437fa652016-05-03 15:13:24 -04004261 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004262 return GL_FALSE;
4263 }
4264
4265 return result;
4266}
4267
Corentin Wallez336129f2017-10-17 15:55:40 -04004268void *Context::mapBufferRange(BufferBinding target,
4269 GLintptr offset,
4270 GLsizeiptr length,
4271 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004272{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004273 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004274 ASSERT(buffer);
4275
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004276 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004277 if (error.isError())
4278 {
Jamie Madill437fa652016-05-03 15:13:24 -04004279 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004280 return nullptr;
4281 }
4282
4283 return buffer->getMapPointer();
4284}
4285
Corentin Wallez336129f2017-10-17 15:55:40 -04004286void Context::flushMappedBufferRange(BufferBinding /*target*/,
4287 GLintptr /*offset*/,
4288 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03004289{
4290 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
4291}
4292
Jamie Madillbc918e72018-03-08 09:47:21 -05004293Error Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004294{
Geoff Langa8cb2872018-03-09 16:09:40 -05004295 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004296}
4297
Jamie Madillbc918e72018-03-08 09:47:21 -05004298Error Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004299{
Geoff Langa8cb2872018-03-09 16:09:40 -05004300 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004301}
4302
Jamie Madillbc918e72018-03-08 09:47:21 -05004303Error Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004304{
Geoff Langa8cb2872018-03-09 16:09:40 -05004305 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004306}
4307
Jiajia Qin5451d532017-11-16 17:16:34 +08004308void Context::activeShaderProgram(GLuint pipeline, GLuint program)
4309{
4310 UNIMPLEMENTED();
4311}
4312
Jamie Madillc20ab272016-06-09 07:20:46 -07004313void Context::activeTexture(GLenum texture)
4314{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004315 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004316}
4317
Jamie Madill876429b2017-04-20 15:46:24 -04004318void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004319{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004320 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004321}
4322
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004323void Context::blendEquation(GLenum mode)
4324{
4325 mGLState.setBlendEquation(mode, mode);
4326}
4327
Jamie Madillc20ab272016-06-09 07:20:46 -07004328void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
4329{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004330 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004331}
4332
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004333void Context::blendFunc(GLenum sfactor, GLenum dfactor)
4334{
4335 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
4336}
4337
Jamie Madillc20ab272016-06-09 07:20:46 -07004338void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
4339{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004340 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004341}
4342
Jamie Madill876429b2017-04-20 15:46:24 -04004343void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004344{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004345 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004346}
4347
Jamie Madill876429b2017-04-20 15:46:24 -04004348void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07004349{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004350 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07004351}
4352
4353void Context::clearStencil(GLint s)
4354{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004355 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07004356}
4357
4358void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
4359{
Geoff Lang92019432017-11-20 13:09:34 -05004360 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
4361 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004362}
4363
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004364void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07004365{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004366 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004367}
4368
4369void Context::depthFunc(GLenum func)
4370{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004371 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07004372}
4373
4374void Context::depthMask(GLboolean flag)
4375{
Geoff Lang92019432017-11-20 13:09:34 -05004376 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07004377}
4378
Jamie Madill876429b2017-04-20 15:46:24 -04004379void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07004380{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004381 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07004382}
4383
4384void Context::disable(GLenum cap)
4385{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004386 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07004387}
4388
4389void Context::disableVertexAttribArray(GLuint index)
4390{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004391 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07004392}
4393
4394void Context::enable(GLenum cap)
4395{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004396 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07004397}
4398
4399void Context::enableVertexAttribArray(GLuint index)
4400{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004401 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07004402}
4403
4404void Context::frontFace(GLenum mode)
4405{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004406 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004407}
4408
4409void Context::hint(GLenum target, GLenum mode)
4410{
4411 switch (target)
4412 {
4413 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004414 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004415 break;
4416
4417 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004418 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004419 break;
4420
4421 default:
4422 UNREACHABLE();
4423 return;
4424 }
4425}
4426
4427void Context::lineWidth(GLfloat width)
4428{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004429 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07004430}
4431
4432void Context::pixelStorei(GLenum pname, GLint param)
4433{
4434 switch (pname)
4435 {
4436 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004437 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004438 break;
4439
4440 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004441 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004442 break;
4443
4444 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004445 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004446 break;
4447
4448 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004449 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004450 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004451 break;
4452
4453 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03004454 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004455 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004456 break;
4457
4458 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03004459 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004460 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004461 break;
4462
4463 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004464 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004465 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004466 break;
4467
4468 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004469 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004470 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004471 break;
4472
4473 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004474 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004475 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004476 break;
4477
4478 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004479 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004480 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004481 break;
4482
4483 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004484 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004485 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004486 break;
4487
4488 default:
4489 UNREACHABLE();
4490 return;
4491 }
4492}
4493
4494void Context::polygonOffset(GLfloat factor, GLfloat units)
4495{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004496 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07004497}
4498
Jamie Madill876429b2017-04-20 15:46:24 -04004499void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07004500{
Geoff Lang92019432017-11-20 13:09:34 -05004501 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07004502}
4503
Jiawei Shaodb342272017-09-27 10:21:45 +08004504void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
4505{
4506 mGLState.setSampleMaskParams(maskNumber, mask);
4507}
4508
Jamie Madillc20ab272016-06-09 07:20:46 -07004509void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
4510{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004511 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004512}
4513
4514void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
4515{
4516 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4517 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004518 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004519 }
4520
4521 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4522 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004523 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004524 }
4525}
4526
4527void Context::stencilMaskSeparate(GLenum face, GLuint mask)
4528{
4529 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4530 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004531 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004532 }
4533
4534 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4535 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004536 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004537 }
4538}
4539
4540void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4541{
4542 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4543 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004544 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004545 }
4546
4547 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4548 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004549 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004550 }
4551}
4552
4553void Context::vertexAttrib1f(GLuint index, GLfloat x)
4554{
4555 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004556 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004557}
4558
4559void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
4560{
4561 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004562 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004563}
4564
4565void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4566{
4567 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004568 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004569}
4570
4571void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
4572{
4573 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004574 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004575}
4576
4577void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4578{
4579 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004580 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004581}
4582
4583void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
4584{
4585 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004586 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004587}
4588
4589void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4590{
4591 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004592 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004593}
4594
4595void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
4596{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004597 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07004598}
4599
4600void Context::vertexAttribPointer(GLuint index,
4601 GLint size,
4602 GLenum type,
4603 GLboolean normalized,
4604 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004605 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07004606{
Corentin Wallez336129f2017-10-17 15:55:40 -04004607 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05004608 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc20ab272016-06-09 07:20:46 -07004609}
4610
Shao80957d92017-02-20 21:25:59 +08004611void Context::vertexAttribFormat(GLuint attribIndex,
4612 GLint size,
4613 GLenum type,
4614 GLboolean normalized,
4615 GLuint relativeOffset)
4616{
Geoff Lang92019432017-11-20 13:09:34 -05004617 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08004618 relativeOffset);
4619}
4620
4621void Context::vertexAttribIFormat(GLuint attribIndex,
4622 GLint size,
4623 GLenum type,
4624 GLuint relativeOffset)
4625{
4626 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
4627}
4628
4629void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4630{
Shaodde78e82017-05-22 14:13:27 +08004631 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Shao80957d92017-02-20 21:25:59 +08004632}
4633
Jiajia Qin5451d532017-11-16 17:16:34 +08004634void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004635{
4636 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
4637}
4638
Jamie Madillc20ab272016-06-09 07:20:46 -07004639void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4640{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004641 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004642}
4643
4644void Context::vertexAttribIPointer(GLuint index,
4645 GLint size,
4646 GLenum type,
4647 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004648 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004649{
Corentin Wallez336129f2017-10-17 15:55:40 -04004650 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
4651 size, type, false, true, stride, pointer);
Jamie Madillc20ab272016-06-09 07:20:46 -07004652}
4653
4654void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4655{
4656 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004657 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004658}
4659
4660void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4661{
4662 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004663 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004664}
4665
4666void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4667{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004668 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004669}
4670
4671void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4672{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004673 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004674}
4675
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004676void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4677{
4678 const VertexAttribCurrentValueData &currentValues =
4679 getGLState().getVertexAttribCurrentValue(index);
4680 const VertexArray *vao = getGLState().getVertexArray();
4681 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4682 currentValues, pname, params);
4683}
4684
Brandon Jones59770802018-04-02 13:18:42 -07004685void Context::getVertexAttribivRobust(GLuint index,
4686 GLenum pname,
4687 GLsizei bufSize,
4688 GLsizei *length,
4689 GLint *params)
4690{
4691 getVertexAttribiv(index, pname, params);
4692}
4693
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004694void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4695{
4696 const VertexAttribCurrentValueData &currentValues =
4697 getGLState().getVertexAttribCurrentValue(index);
4698 const VertexArray *vao = getGLState().getVertexArray();
4699 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4700 currentValues, pname, params);
4701}
4702
Brandon Jones59770802018-04-02 13:18:42 -07004703void Context::getVertexAttribfvRobust(GLuint index,
4704 GLenum pname,
4705 GLsizei bufSize,
4706 GLsizei *length,
4707 GLfloat *params)
4708{
4709 getVertexAttribfv(index, pname, params);
4710}
4711
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004712void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4713{
4714 const VertexAttribCurrentValueData &currentValues =
4715 getGLState().getVertexAttribCurrentValue(index);
4716 const VertexArray *vao = getGLState().getVertexArray();
4717 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4718 currentValues, pname, params);
4719}
4720
Brandon Jones59770802018-04-02 13:18:42 -07004721void Context::getVertexAttribIivRobust(GLuint index,
4722 GLenum pname,
4723 GLsizei bufSize,
4724 GLsizei *length,
4725 GLint *params)
4726{
4727 getVertexAttribIiv(index, pname, params);
4728}
4729
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004730void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4731{
4732 const VertexAttribCurrentValueData &currentValues =
4733 getGLState().getVertexAttribCurrentValue(index);
4734 const VertexArray *vao = getGLState().getVertexArray();
4735 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4736 currentValues, pname, params);
4737}
4738
Brandon Jones59770802018-04-02 13:18:42 -07004739void Context::getVertexAttribIuivRobust(GLuint index,
4740 GLenum pname,
4741 GLsizei bufSize,
4742 GLsizei *length,
4743 GLuint *params)
4744{
4745 getVertexAttribIuiv(index, pname, params);
4746}
4747
Jamie Madill876429b2017-04-20 15:46:24 -04004748void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004749{
4750 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
4751 QueryVertexAttribPointerv(attrib, pname, pointer);
4752}
4753
Brandon Jones59770802018-04-02 13:18:42 -07004754void Context::getVertexAttribPointervRobust(GLuint index,
4755 GLenum pname,
4756 GLsizei bufSize,
4757 GLsizei *length,
4758 void **pointer)
4759{
4760 getVertexAttribPointerv(index, pname, pointer);
4761}
4762
Jamie Madillc20ab272016-06-09 07:20:46 -07004763void Context::debugMessageControl(GLenum source,
4764 GLenum type,
4765 GLenum severity,
4766 GLsizei count,
4767 const GLuint *ids,
4768 GLboolean enabled)
4769{
4770 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004771 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05004772 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004773}
4774
4775void Context::debugMessageInsert(GLenum source,
4776 GLenum type,
4777 GLuint id,
4778 GLenum severity,
4779 GLsizei length,
4780 const GLchar *buf)
4781{
4782 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004783 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004784}
4785
4786void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4787{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004788 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004789}
4790
4791GLuint Context::getDebugMessageLog(GLuint count,
4792 GLsizei bufSize,
4793 GLenum *sources,
4794 GLenum *types,
4795 GLuint *ids,
4796 GLenum *severities,
4797 GLsizei *lengths,
4798 GLchar *messageLog)
4799{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004800 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4801 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004802}
4803
4804void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4805{
4806 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004807 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05004808 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07004809}
4810
4811void Context::popDebugGroup()
4812{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004813 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05004814 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004815}
4816
Corentin Wallez336129f2017-10-17 15:55:40 -04004817void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004818{
4819 Buffer *buffer = mGLState.getTargetBuffer(target);
4820 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004821 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004822}
4823
Corentin Wallez336129f2017-10-17 15:55:40 -04004824void Context::bufferSubData(BufferBinding target,
4825 GLintptr offset,
4826 GLsizeiptr size,
4827 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004828{
4829 if (data == nullptr)
4830 {
4831 return;
4832 }
4833
4834 Buffer *buffer = mGLState.getTargetBuffer(target);
4835 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004836 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004837}
4838
Jamie Madillef300b12016-10-07 15:12:09 -04004839void Context::attachShader(GLuint program, GLuint shader)
4840{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05004841 Program *programObject = mState.mShaderPrograms->getProgram(program);
4842 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004843 ASSERT(programObject && shaderObject);
4844 programObject->attachShader(shaderObject);
4845}
4846
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004847const Workarounds &Context::getWorkarounds() const
4848{
4849 return mWorkarounds;
4850}
4851
Corentin Wallez336129f2017-10-17 15:55:40 -04004852void Context::copyBufferSubData(BufferBinding readTarget,
4853 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04004854 GLintptr readOffset,
4855 GLintptr writeOffset,
4856 GLsizeiptr size)
4857{
4858 // if size is zero, the copy is a successful no-op
4859 if (size == 0)
4860 {
4861 return;
4862 }
4863
4864 // TODO(jmadill): cache these.
4865 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4866 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4867
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004868 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004869}
4870
Jamie Madill01a80ee2016-11-07 12:06:18 -05004871void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4872{
4873 Program *programObject = getProgram(program);
4874 // TODO(jmadill): Re-use this from the validation if possible.
4875 ASSERT(programObject);
4876 programObject->bindAttributeLocation(index, name);
4877}
4878
Corentin Wallez336129f2017-10-17 15:55:40 -04004879void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004880{
Corentin Wallez336129f2017-10-17 15:55:40 -04004881 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4882 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004883}
4884
Corentin Wallez336129f2017-10-17 15:55:40 -04004885void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08004886{
4887 bindBufferRange(target, index, buffer, 0, 0);
4888}
4889
Corentin Wallez336129f2017-10-17 15:55:40 -04004890void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08004891 GLuint index,
4892 GLuint buffer,
4893 GLintptr offset,
4894 GLsizeiptr size)
4895{
Corentin Wallez336129f2017-10-17 15:55:40 -04004896 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4897 mGLState.setIndexedBufferBinding(this, target, index, bufferObject, offset, size);
Jiajia Qin6eafb042016-12-27 17:04:07 +08004898}
4899
Jamie Madill01a80ee2016-11-07 12:06:18 -05004900void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
4901{
4902 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4903 {
4904 bindReadFramebuffer(framebuffer);
4905 }
4906
4907 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4908 {
4909 bindDrawFramebuffer(framebuffer);
4910 }
4911}
4912
4913void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4914{
4915 ASSERT(target == GL_RENDERBUFFER);
4916 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004917 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04004918 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004919}
4920
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004921void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08004922 GLsizei samples,
4923 GLenum internalformat,
4924 GLsizei width,
4925 GLsizei height,
4926 GLboolean fixedsamplelocations)
4927{
4928 Extents size(width, height, 1);
4929 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004930 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
4931 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004932}
4933
4934void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4935{
JiangYizhou5b03f472017-01-09 10:22:53 +08004936 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
4937 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillbc918e72018-03-08 09:47:21 -05004938 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
JiangYizhou5b03f472017-01-09 10:22:53 +08004939 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08004940
4941 switch (pname)
4942 {
4943 case GL_SAMPLE_POSITION:
Geoff Lang13455072018-05-09 11:24:43 -04004944 handleError(framebuffer->getSamplePosition(this, index, val));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004945 break;
4946 default:
4947 UNREACHABLE();
4948 }
4949}
4950
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07004951void Context::getMultisamplefvRobust(GLenum pname,
4952 GLuint index,
4953 GLsizei bufSize,
4954 GLsizei *length,
4955 GLfloat *val)
4956{
4957 UNIMPLEMENTED();
4958}
4959
Jamie Madille8fb6402017-02-14 17:56:40 -05004960void Context::renderbufferStorage(GLenum target,
4961 GLenum internalformat,
4962 GLsizei width,
4963 GLsizei height)
4964{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004965 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4966 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
4967
Jamie Madille8fb6402017-02-14 17:56:40 -05004968 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04004969 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004970}
4971
4972void Context::renderbufferStorageMultisample(GLenum target,
4973 GLsizei samples,
4974 GLenum internalformat,
4975 GLsizei width,
4976 GLsizei height)
4977{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004978 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4979 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05004980
4981 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004982 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04004983 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004984}
4985
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004986void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
4987{
Jamie Madill70b5bb02017-08-28 13:32:37 -04004988 const Sync *syncObject = getSync(sync);
Geoff Lang82483b92017-04-11 15:33:00 -04004989 handleError(QuerySynciv(syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004990}
4991
JiangYizhoue18e6392017-02-20 10:32:23 +08004992void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
4993{
4994 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4995 QueryFramebufferParameteriv(framebuffer, pname, params);
4996}
4997
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07004998void Context::getFramebufferParameterivRobust(GLenum target,
4999 GLenum pname,
5000 GLsizei bufSize,
5001 GLsizei *length,
5002 GLint *params)
5003{
5004 UNIMPLEMENTED();
5005}
5006
Jiajia Qin5451d532017-11-16 17:16:34 +08005007void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08005008{
5009 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5010 SetFramebufferParameteri(framebuffer, pname, param);
5011}
5012
Jamie Madilldec86232018-07-11 09:01:18 -04005013bool Context::getScratchBuffer(size_t requstedSizeBytes,
5014 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05005015{
Jamie Madilldec86232018-07-11 09:01:18 -04005016 return mScratchBuffer.get(requstedSizeBytes, scratchBufferOut);
Jamie Madillb3f26b92017-07-19 15:07:41 -04005017}
5018
Jamie Madilldec86232018-07-11 09:01:18 -04005019bool Context::getZeroFilledBuffer(size_t requstedSizeBytes,
5020 angle::MemoryBuffer **zeroBufferOut) const
Jamie Madillb3f26b92017-07-19 15:07:41 -04005021{
Jamie Madilldec86232018-07-11 09:01:18 -04005022 return mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0);
Jamie Madille14951e2017-03-09 18:55:16 -05005023}
5024
Xinghua Cao10a4d432017-11-28 14:46:26 +08005025Error Context::prepareForDispatch()
5026{
Geoff Langa8cb2872018-03-09 16:09:40 -05005027 ANGLE_TRY(syncState(mComputeDirtyBits, mComputeDirtyObjects));
Xinghua Cao10a4d432017-11-28 14:46:26 +08005028
5029 if (isRobustResourceInitEnabled())
5030 {
5031 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
5032 }
5033
5034 return NoError();
5035}
5036
Xinghua Cao2b396592017-03-29 15:36:04 +08005037void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
5038{
5039 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
5040 {
5041 return;
5042 }
5043
Xinghua Cao10a4d432017-11-28 14:46:26 +08005044 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill71c88b32017-09-14 22:20:29 -04005045 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08005046}
5047
Jiajia Qin5451d532017-11-16 17:16:34 +08005048void Context::dispatchComputeIndirect(GLintptr indirect)
5049{
Qin Jiajia62fcf622017-11-30 16:16:12 +08005050 ANGLE_CONTEXT_TRY(prepareForDispatch());
5051 handleError(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08005052}
5053
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005054void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005055 GLsizei levels,
5056 GLenum internalFormat,
5057 GLsizei width,
5058 GLsizei height)
5059{
5060 Extents size(width, height, 1);
5061 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005062 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005063}
5064
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005065void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005066 GLsizei levels,
5067 GLenum internalFormat,
5068 GLsizei width,
5069 GLsizei height,
5070 GLsizei depth)
5071{
5072 Extents size(width, height, depth);
5073 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005074 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005075}
5076
Jiajia Qin5451d532017-11-16 17:16:34 +08005077void Context::memoryBarrier(GLbitfield barriers)
5078{
Xinghua Cao89c422a2017-11-29 18:24:20 +08005079 handleError(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005080}
5081
5082void Context::memoryBarrierByRegion(GLbitfield barriers)
5083{
Xinghua Cao89c422a2017-11-29 18:24:20 +08005084 handleError(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005085}
5086
Jamie Madillc1d770e2017-04-13 17:31:24 -04005087GLenum Context::checkFramebufferStatus(GLenum target)
5088{
5089 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5090 ASSERT(framebuffer);
Jamie Madill427064d2018-04-13 16:20:34 -04005091 return framebuffer->checkStatus(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005092}
5093
5094void Context::compileShader(GLuint shader)
5095{
5096 Shader *shaderObject = GetValidShader(this, shader);
5097 if (!shaderObject)
5098 {
5099 return;
5100 }
5101 shaderObject->compile(this);
5102}
5103
5104void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
5105{
5106 for (int i = 0; i < n; i++)
5107 {
5108 deleteBuffer(buffers[i]);
5109 }
5110}
5111
5112void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
5113{
5114 for (int i = 0; i < n; i++)
5115 {
5116 if (framebuffers[i] != 0)
5117 {
5118 deleteFramebuffer(framebuffers[i]);
5119 }
5120 }
5121}
5122
5123void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
5124{
5125 for (int i = 0; i < n; i++)
5126 {
5127 deleteRenderbuffer(renderbuffers[i]);
5128 }
5129}
5130
5131void Context::deleteTextures(GLsizei n, const GLuint *textures)
5132{
5133 for (int i = 0; i < n; i++)
5134 {
5135 if (textures[i] != 0)
5136 {
5137 deleteTexture(textures[i]);
5138 }
5139 }
5140}
5141
5142void Context::detachShader(GLuint program, GLuint shader)
5143{
5144 Program *programObject = getProgram(program);
5145 ASSERT(programObject);
5146
5147 Shader *shaderObject = getShader(shader);
5148 ASSERT(shaderObject);
5149
5150 programObject->detachShader(this, shaderObject);
5151}
5152
5153void Context::genBuffers(GLsizei n, GLuint *buffers)
5154{
5155 for (int i = 0; i < n; i++)
5156 {
5157 buffers[i] = createBuffer();
5158 }
5159}
5160
5161void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
5162{
5163 for (int i = 0; i < n; i++)
5164 {
5165 framebuffers[i] = createFramebuffer();
5166 }
5167}
5168
5169void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
5170{
5171 for (int i = 0; i < n; i++)
5172 {
5173 renderbuffers[i] = createRenderbuffer();
5174 }
5175}
5176
5177void Context::genTextures(GLsizei n, GLuint *textures)
5178{
5179 for (int i = 0; i < n; i++)
5180 {
5181 textures[i] = createTexture();
5182 }
5183}
5184
5185void Context::getActiveAttrib(GLuint program,
5186 GLuint index,
5187 GLsizei bufsize,
5188 GLsizei *length,
5189 GLint *size,
5190 GLenum *type,
5191 GLchar *name)
5192{
5193 Program *programObject = getProgram(program);
5194 ASSERT(programObject);
5195 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
5196}
5197
5198void Context::getActiveUniform(GLuint program,
5199 GLuint index,
5200 GLsizei bufsize,
5201 GLsizei *length,
5202 GLint *size,
5203 GLenum *type,
5204 GLchar *name)
5205{
5206 Program *programObject = getProgram(program);
5207 ASSERT(programObject);
5208 programObject->getActiveUniform(index, bufsize, length, size, type, name);
5209}
5210
5211void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
5212{
5213 Program *programObject = getProgram(program);
5214 ASSERT(programObject);
5215 programObject->getAttachedShaders(maxcount, count, shaders);
5216}
5217
5218GLint Context::getAttribLocation(GLuint program, const GLchar *name)
5219{
5220 Program *programObject = getProgram(program);
5221 ASSERT(programObject);
5222 return programObject->getAttributeLocation(name);
5223}
5224
5225void Context::getBooleanv(GLenum pname, GLboolean *params)
5226{
5227 GLenum nativeType;
5228 unsigned int numParams = 0;
5229 getQueryParameterInfo(pname, &nativeType, &numParams);
5230
5231 if (nativeType == GL_BOOL)
5232 {
5233 getBooleanvImpl(pname, params);
5234 }
5235 else
5236 {
5237 CastStateValues(this, nativeType, pname, numParams, params);
5238 }
5239}
5240
Brandon Jones59770802018-04-02 13:18:42 -07005241void Context::getBooleanvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLboolean *params)
5242{
5243 getBooleanv(pname, params);
5244}
5245
Jamie Madillc1d770e2017-04-13 17:31:24 -04005246void Context::getFloatv(GLenum pname, GLfloat *params)
5247{
5248 GLenum nativeType;
5249 unsigned int numParams = 0;
5250 getQueryParameterInfo(pname, &nativeType, &numParams);
5251
5252 if (nativeType == GL_FLOAT)
5253 {
5254 getFloatvImpl(pname, params);
5255 }
5256 else
5257 {
5258 CastStateValues(this, nativeType, pname, numParams, params);
5259 }
5260}
5261
Brandon Jones59770802018-04-02 13:18:42 -07005262void Context::getFloatvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLfloat *params)
5263{
5264 getFloatv(pname, params);
5265}
5266
Jamie Madillc1d770e2017-04-13 17:31:24 -04005267void Context::getIntegerv(GLenum pname, GLint *params)
5268{
5269 GLenum nativeType;
5270 unsigned int numParams = 0;
5271 getQueryParameterInfo(pname, &nativeType, &numParams);
5272
5273 if (nativeType == GL_INT)
5274 {
5275 getIntegervImpl(pname, params);
5276 }
5277 else
5278 {
5279 CastStateValues(this, nativeType, pname, numParams, params);
5280 }
5281}
5282
Brandon Jones59770802018-04-02 13:18:42 -07005283void Context::getIntegervRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint *data)
5284{
5285 getIntegerv(pname, data);
5286}
5287
Jamie Madillc1d770e2017-04-13 17:31:24 -04005288void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
5289{
5290 Program *programObject = getProgram(program);
5291 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04005292 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005293}
5294
Brandon Jones59770802018-04-02 13:18:42 -07005295void Context::getProgramivRobust(GLuint program,
5296 GLenum pname,
5297 GLsizei bufSize,
5298 GLsizei *length,
5299 GLint *params)
5300{
5301 getProgramiv(program, pname, params);
5302}
5303
Jiajia Qin5451d532017-11-16 17:16:34 +08005304void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
5305{
5306 UNIMPLEMENTED();
5307}
5308
Jamie Madillbe849e42017-05-02 15:49:00 -04005309void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005310{
5311 Program *programObject = getProgram(program);
5312 ASSERT(programObject);
5313 programObject->getInfoLog(bufsize, length, infolog);
5314}
5315
Jiajia Qin5451d532017-11-16 17:16:34 +08005316void Context::getProgramPipelineInfoLog(GLuint pipeline,
5317 GLsizei bufSize,
5318 GLsizei *length,
5319 GLchar *infoLog)
5320{
5321 UNIMPLEMENTED();
5322}
5323
Jamie Madillc1d770e2017-04-13 17:31:24 -04005324void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
5325{
5326 Shader *shaderObject = getShader(shader);
5327 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04005328 QueryShaderiv(this, shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005329}
5330
Brandon Jones59770802018-04-02 13:18:42 -07005331void Context::getShaderivRobust(GLuint shader,
5332 GLenum pname,
5333 GLsizei bufSize,
5334 GLsizei *length,
5335 GLint *params)
5336{
5337 getShaderiv(shader, pname, params);
5338}
5339
Jamie Madillc1d770e2017-04-13 17:31:24 -04005340void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
5341{
5342 Shader *shaderObject = getShader(shader);
5343 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04005344 shaderObject->getInfoLog(this, bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005345}
5346
5347void Context::getShaderPrecisionFormat(GLenum shadertype,
5348 GLenum precisiontype,
5349 GLint *range,
5350 GLint *precision)
5351{
5352 // TODO(jmadill): Compute shaders.
5353
5354 switch (shadertype)
5355 {
5356 case GL_VERTEX_SHADER:
5357 switch (precisiontype)
5358 {
5359 case GL_LOW_FLOAT:
5360 mCaps.vertexLowpFloat.get(range, precision);
5361 break;
5362 case GL_MEDIUM_FLOAT:
5363 mCaps.vertexMediumpFloat.get(range, precision);
5364 break;
5365 case GL_HIGH_FLOAT:
5366 mCaps.vertexHighpFloat.get(range, precision);
5367 break;
5368
5369 case GL_LOW_INT:
5370 mCaps.vertexLowpInt.get(range, precision);
5371 break;
5372 case GL_MEDIUM_INT:
5373 mCaps.vertexMediumpInt.get(range, precision);
5374 break;
5375 case GL_HIGH_INT:
5376 mCaps.vertexHighpInt.get(range, precision);
5377 break;
5378
5379 default:
5380 UNREACHABLE();
5381 return;
5382 }
5383 break;
5384
5385 case GL_FRAGMENT_SHADER:
5386 switch (precisiontype)
5387 {
5388 case GL_LOW_FLOAT:
5389 mCaps.fragmentLowpFloat.get(range, precision);
5390 break;
5391 case GL_MEDIUM_FLOAT:
5392 mCaps.fragmentMediumpFloat.get(range, precision);
5393 break;
5394 case GL_HIGH_FLOAT:
5395 mCaps.fragmentHighpFloat.get(range, precision);
5396 break;
5397
5398 case GL_LOW_INT:
5399 mCaps.fragmentLowpInt.get(range, precision);
5400 break;
5401 case GL_MEDIUM_INT:
5402 mCaps.fragmentMediumpInt.get(range, precision);
5403 break;
5404 case GL_HIGH_INT:
5405 mCaps.fragmentHighpInt.get(range, precision);
5406 break;
5407
5408 default:
5409 UNREACHABLE();
5410 return;
5411 }
5412 break;
5413
5414 default:
5415 UNREACHABLE();
5416 return;
5417 }
5418}
5419
5420void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
5421{
5422 Shader *shaderObject = getShader(shader);
5423 ASSERT(shaderObject);
5424 shaderObject->getSource(bufsize, length, source);
5425}
5426
5427void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
5428{
5429 Program *programObject = getProgram(program);
5430 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005431 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005432}
5433
Brandon Jones59770802018-04-02 13:18:42 -07005434void Context::getUniformfvRobust(GLuint program,
5435 GLint location,
5436 GLsizei bufSize,
5437 GLsizei *length,
5438 GLfloat *params)
5439{
5440 getUniformfv(program, location, params);
5441}
5442
Jamie Madillc1d770e2017-04-13 17:31:24 -04005443void Context::getUniformiv(GLuint program, GLint location, GLint *params)
5444{
5445 Program *programObject = getProgram(program);
5446 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005447 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005448}
5449
Brandon Jones59770802018-04-02 13:18:42 -07005450void Context::getUniformivRobust(GLuint program,
5451 GLint location,
5452 GLsizei bufSize,
5453 GLsizei *length,
5454 GLint *params)
5455{
5456 getUniformiv(program, location, params);
5457}
5458
Jamie Madillc1d770e2017-04-13 17:31:24 -04005459GLint Context::getUniformLocation(GLuint program, const GLchar *name)
5460{
5461 Program *programObject = getProgram(program);
5462 ASSERT(programObject);
5463 return programObject->getUniformLocation(name);
5464}
5465
5466GLboolean Context::isBuffer(GLuint buffer)
5467{
5468 if (buffer == 0)
5469 {
5470 return GL_FALSE;
5471 }
5472
5473 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
5474}
5475
5476GLboolean Context::isEnabled(GLenum cap)
5477{
5478 return mGLState.getEnableFeature(cap);
5479}
5480
5481GLboolean Context::isFramebuffer(GLuint framebuffer)
5482{
5483 if (framebuffer == 0)
5484 {
5485 return GL_FALSE;
5486 }
5487
5488 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
5489}
5490
5491GLboolean Context::isProgram(GLuint program)
5492{
5493 if (program == 0)
5494 {
5495 return GL_FALSE;
5496 }
5497
5498 return (getProgram(program) ? GL_TRUE : GL_FALSE);
5499}
5500
5501GLboolean Context::isRenderbuffer(GLuint renderbuffer)
5502{
5503 if (renderbuffer == 0)
5504 {
5505 return GL_FALSE;
5506 }
5507
5508 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
5509}
5510
5511GLboolean Context::isShader(GLuint shader)
5512{
5513 if (shader == 0)
5514 {
5515 return GL_FALSE;
5516 }
5517
5518 return (getShader(shader) ? GL_TRUE : GL_FALSE);
5519}
5520
5521GLboolean Context::isTexture(GLuint texture)
5522{
5523 if (texture == 0)
5524 {
5525 return GL_FALSE;
5526 }
5527
5528 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
5529}
5530
5531void Context::linkProgram(GLuint program)
5532{
5533 Program *programObject = getProgram(program);
5534 ASSERT(programObject);
5535 handleError(programObject->link(this));
Martin Radev0abb7a22017-08-28 15:34:45 +03005536 mGLState.onProgramExecutableChange(programObject);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005537}
5538
5539void Context::releaseShaderCompiler()
5540{
Jamie Madill4928b7c2017-06-20 12:57:39 -04005541 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005542}
5543
5544void Context::shaderBinary(GLsizei n,
5545 const GLuint *shaders,
5546 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04005547 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005548 GLsizei length)
5549{
5550 // No binary shader formats are supported.
5551 UNIMPLEMENTED();
5552}
5553
5554void Context::shaderSource(GLuint shader,
5555 GLsizei count,
5556 const GLchar *const *string,
5557 const GLint *length)
5558{
5559 Shader *shaderObject = getShader(shader);
5560 ASSERT(shaderObject);
5561 shaderObject->setSource(count, string, length);
5562}
5563
5564void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
5565{
5566 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
5567}
5568
5569void Context::stencilMask(GLuint mask)
5570{
5571 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
5572}
5573
5574void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
5575{
5576 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
5577}
5578
5579void Context::uniform1f(GLint location, GLfloat x)
5580{
5581 Program *program = mGLState.getProgram();
5582 program->setUniform1fv(location, 1, &x);
5583}
5584
5585void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
5586{
5587 Program *program = mGLState.getProgram();
5588 program->setUniform1fv(location, count, v);
5589}
5590
5591void Context::uniform1i(GLint location, GLint x)
5592{
5593 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04005594 if (program->setUniform1iv(location, 1, &x) == Program::SetUniformResult::SamplerChanged)
5595 {
5596 mGLState.setObjectDirty(GL_PROGRAM);
5597 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005598}
5599
5600void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
5601{
5602 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04005603 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
5604 {
5605 mGLState.setObjectDirty(GL_PROGRAM);
5606 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005607}
5608
5609void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
5610{
5611 GLfloat xy[2] = {x, y};
5612 Program *program = mGLState.getProgram();
5613 program->setUniform2fv(location, 1, xy);
5614}
5615
5616void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
5617{
5618 Program *program = mGLState.getProgram();
5619 program->setUniform2fv(location, count, v);
5620}
5621
5622void Context::uniform2i(GLint location, GLint x, GLint y)
5623{
5624 GLint xy[2] = {x, y};
5625 Program *program = mGLState.getProgram();
5626 program->setUniform2iv(location, 1, xy);
5627}
5628
5629void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
5630{
5631 Program *program = mGLState.getProgram();
5632 program->setUniform2iv(location, count, v);
5633}
5634
5635void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
5636{
5637 GLfloat xyz[3] = {x, y, z};
5638 Program *program = mGLState.getProgram();
5639 program->setUniform3fv(location, 1, xyz);
5640}
5641
5642void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
5643{
5644 Program *program = mGLState.getProgram();
5645 program->setUniform3fv(location, count, v);
5646}
5647
5648void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
5649{
5650 GLint xyz[3] = {x, y, z};
5651 Program *program = mGLState.getProgram();
5652 program->setUniform3iv(location, 1, xyz);
5653}
5654
5655void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
5656{
5657 Program *program = mGLState.getProgram();
5658 program->setUniform3iv(location, count, v);
5659}
5660
5661void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
5662{
5663 GLfloat xyzw[4] = {x, y, z, w};
5664 Program *program = mGLState.getProgram();
5665 program->setUniform4fv(location, 1, xyzw);
5666}
5667
5668void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
5669{
5670 Program *program = mGLState.getProgram();
5671 program->setUniform4fv(location, count, v);
5672}
5673
5674void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
5675{
5676 GLint xyzw[4] = {x, y, z, w};
5677 Program *program = mGLState.getProgram();
5678 program->setUniform4iv(location, 1, xyzw);
5679}
5680
5681void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
5682{
5683 Program *program = mGLState.getProgram();
5684 program->setUniform4iv(location, count, v);
5685}
5686
5687void Context::uniformMatrix2fv(GLint location,
5688 GLsizei count,
5689 GLboolean transpose,
5690 const GLfloat *value)
5691{
5692 Program *program = mGLState.getProgram();
5693 program->setUniformMatrix2fv(location, count, transpose, value);
5694}
5695
5696void Context::uniformMatrix3fv(GLint location,
5697 GLsizei count,
5698 GLboolean transpose,
5699 const GLfloat *value)
5700{
5701 Program *program = mGLState.getProgram();
5702 program->setUniformMatrix3fv(location, count, transpose, value);
5703}
5704
5705void Context::uniformMatrix4fv(GLint location,
5706 GLsizei count,
5707 GLboolean transpose,
5708 const GLfloat *value)
5709{
5710 Program *program = mGLState.getProgram();
5711 program->setUniformMatrix4fv(location, count, transpose, value);
5712}
5713
5714void Context::validateProgram(GLuint program)
5715{
5716 Program *programObject = getProgram(program);
5717 ASSERT(programObject);
5718 programObject->validate(mCaps);
5719}
5720
Jiajia Qin5451d532017-11-16 17:16:34 +08005721void Context::validateProgramPipeline(GLuint pipeline)
5722{
5723 UNIMPLEMENTED();
5724}
5725
Jamie Madilld04908b2017-06-09 14:15:35 -04005726void Context::getProgramBinary(GLuint program,
5727 GLsizei bufSize,
5728 GLsizei *length,
5729 GLenum *binaryFormat,
5730 void *binary)
5731{
5732 Program *programObject = getProgram(program);
5733 ASSERT(programObject != nullptr);
5734
5735 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
5736}
5737
5738void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
5739{
5740 Program *programObject = getProgram(program);
5741 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04005742
Jamie Madilld04908b2017-06-09 14:15:35 -04005743 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
5744}
5745
Jamie Madillff325f12017-08-26 15:06:05 -04005746void Context::uniform1ui(GLint location, GLuint v0)
5747{
5748 Program *program = mGLState.getProgram();
5749 program->setUniform1uiv(location, 1, &v0);
5750}
5751
5752void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
5753{
5754 Program *program = mGLState.getProgram();
5755 const GLuint xy[] = {v0, v1};
5756 program->setUniform2uiv(location, 1, xy);
5757}
5758
5759void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
5760{
5761 Program *program = mGLState.getProgram();
5762 const GLuint xyz[] = {v0, v1, v2};
5763 program->setUniform3uiv(location, 1, xyz);
5764}
5765
5766void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
5767{
5768 Program *program = mGLState.getProgram();
5769 const GLuint xyzw[] = {v0, v1, v2, v3};
5770 program->setUniform4uiv(location, 1, xyzw);
5771}
5772
5773void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
5774{
5775 Program *program = mGLState.getProgram();
5776 program->setUniform1uiv(location, count, value);
5777}
5778void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
5779{
5780 Program *program = mGLState.getProgram();
5781 program->setUniform2uiv(location, count, value);
5782}
5783
5784void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
5785{
5786 Program *program = mGLState.getProgram();
5787 program->setUniform3uiv(location, count, value);
5788}
5789
5790void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
5791{
5792 Program *program = mGLState.getProgram();
5793 program->setUniform4uiv(location, count, value);
5794}
5795
Jamie Madillf0e04492017-08-26 15:28:42 -04005796void Context::genQueries(GLsizei n, GLuint *ids)
5797{
5798 for (GLsizei i = 0; i < n; i++)
5799 {
5800 GLuint handle = mQueryHandleAllocator.allocate();
5801 mQueryMap.assign(handle, nullptr);
5802 ids[i] = handle;
5803 }
5804}
5805
5806void Context::deleteQueries(GLsizei n, const GLuint *ids)
5807{
5808 for (int i = 0; i < n; i++)
5809 {
5810 GLuint query = ids[i];
5811
5812 Query *queryObject = nullptr;
5813 if (mQueryMap.erase(query, &queryObject))
5814 {
5815 mQueryHandleAllocator.release(query);
5816 if (queryObject)
5817 {
5818 queryObject->release(this);
5819 }
5820 }
5821 }
5822}
5823
5824GLboolean Context::isQuery(GLuint id)
5825{
Corentin Wallezad3ae902018-03-09 13:40:42 -05005826 return (getQuery(id, false, QueryType::InvalidEnum) != nullptr) ? GL_TRUE : GL_FALSE;
Jamie Madillf0e04492017-08-26 15:28:42 -04005827}
5828
Jamie Madillc8c95812017-08-26 18:40:09 -04005829void Context::uniformMatrix2x3fv(GLint location,
5830 GLsizei count,
5831 GLboolean transpose,
5832 const GLfloat *value)
5833{
5834 Program *program = mGLState.getProgram();
5835 program->setUniformMatrix2x3fv(location, count, transpose, value);
5836}
5837
5838void Context::uniformMatrix3x2fv(GLint location,
5839 GLsizei count,
5840 GLboolean transpose,
5841 const GLfloat *value)
5842{
5843 Program *program = mGLState.getProgram();
5844 program->setUniformMatrix3x2fv(location, count, transpose, value);
5845}
5846
5847void Context::uniformMatrix2x4fv(GLint location,
5848 GLsizei count,
5849 GLboolean transpose,
5850 const GLfloat *value)
5851{
5852 Program *program = mGLState.getProgram();
5853 program->setUniformMatrix2x4fv(location, count, transpose, value);
5854}
5855
5856void Context::uniformMatrix4x2fv(GLint location,
5857 GLsizei count,
5858 GLboolean transpose,
5859 const GLfloat *value)
5860{
5861 Program *program = mGLState.getProgram();
5862 program->setUniformMatrix4x2fv(location, count, transpose, value);
5863}
5864
5865void Context::uniformMatrix3x4fv(GLint location,
5866 GLsizei count,
5867 GLboolean transpose,
5868 const GLfloat *value)
5869{
5870 Program *program = mGLState.getProgram();
5871 program->setUniformMatrix3x4fv(location, count, transpose, value);
5872}
5873
5874void Context::uniformMatrix4x3fv(GLint location,
5875 GLsizei count,
5876 GLboolean transpose,
5877 const GLfloat *value)
5878{
5879 Program *program = mGLState.getProgram();
5880 program->setUniformMatrix4x3fv(location, count, transpose, value);
5881}
5882
Jamie Madilld7576732017-08-26 18:49:50 -04005883void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
5884{
5885 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5886 {
5887 GLuint vertexArray = arrays[arrayIndex];
5888
5889 if (arrays[arrayIndex] != 0)
5890 {
5891 VertexArray *vertexArrayObject = nullptr;
5892 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
5893 {
5894 if (vertexArrayObject != nullptr)
5895 {
5896 detachVertexArray(vertexArray);
5897 vertexArrayObject->onDestroy(this);
5898 }
5899
5900 mVertexArrayHandleAllocator.release(vertexArray);
5901 }
5902 }
5903 }
5904}
5905
5906void Context::genVertexArrays(GLsizei n, GLuint *arrays)
5907{
5908 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5909 {
5910 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
5911 mVertexArrayMap.assign(vertexArray, nullptr);
5912 arrays[arrayIndex] = vertexArray;
5913 }
5914}
5915
5916bool Context::isVertexArray(GLuint array)
5917{
5918 if (array == 0)
5919 {
5920 return GL_FALSE;
5921 }
5922
5923 VertexArray *vao = getVertexArray(array);
5924 return (vao != nullptr ? GL_TRUE : GL_FALSE);
5925}
5926
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04005927void Context::endTransformFeedback()
5928{
5929 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5930 transformFeedback->end(this);
5931}
5932
5933void Context::transformFeedbackVaryings(GLuint program,
5934 GLsizei count,
5935 const GLchar *const *varyings,
5936 GLenum bufferMode)
5937{
5938 Program *programObject = getProgram(program);
5939 ASSERT(programObject);
5940 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
5941}
5942
5943void Context::getTransformFeedbackVarying(GLuint program,
5944 GLuint index,
5945 GLsizei bufSize,
5946 GLsizei *length,
5947 GLsizei *size,
5948 GLenum *type,
5949 GLchar *name)
5950{
5951 Program *programObject = getProgram(program);
5952 ASSERT(programObject);
5953 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
5954}
5955
5956void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
5957{
5958 for (int i = 0; i < n; i++)
5959 {
5960 GLuint transformFeedback = ids[i];
5961 if (transformFeedback == 0)
5962 {
5963 continue;
5964 }
5965
5966 TransformFeedback *transformFeedbackObject = nullptr;
5967 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
5968 {
5969 if (transformFeedbackObject != nullptr)
5970 {
5971 detachTransformFeedback(transformFeedback);
5972 transformFeedbackObject->release(this);
5973 }
5974
5975 mTransformFeedbackHandleAllocator.release(transformFeedback);
5976 }
5977 }
5978}
5979
5980void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
5981{
5982 for (int i = 0; i < n; i++)
5983 {
5984 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
5985 mTransformFeedbackMap.assign(transformFeedback, nullptr);
5986 ids[i] = transformFeedback;
5987 }
5988}
5989
5990bool Context::isTransformFeedback(GLuint id)
5991{
5992 if (id == 0)
5993 {
5994 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
5995 // returns FALSE
5996 return GL_FALSE;
5997 }
5998
5999 const TransformFeedback *transformFeedback = getTransformFeedback(id);
6000 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
6001}
6002
6003void Context::pauseTransformFeedback()
6004{
6005 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6006 transformFeedback->pause();
6007}
6008
6009void Context::resumeTransformFeedback()
6010{
6011 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6012 transformFeedback->resume();
6013}
6014
Jamie Madill12e957f2017-08-26 21:42:26 -04006015void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
6016{
6017 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04006018 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04006019}
6020
Brandon Jones59770802018-04-02 13:18:42 -07006021void Context::getUniformuivRobust(GLuint program,
6022 GLint location,
6023 GLsizei bufSize,
6024 GLsizei *length,
6025 GLuint *params)
6026{
6027 getUniformuiv(program, location, params);
6028}
6029
Jamie Madill12e957f2017-08-26 21:42:26 -04006030GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
6031{
6032 const Program *programObject = getProgram(program);
6033 return programObject->getFragDataLocation(name);
6034}
6035
6036void Context::getUniformIndices(GLuint program,
6037 GLsizei uniformCount,
6038 const GLchar *const *uniformNames,
6039 GLuint *uniformIndices)
6040{
6041 const Program *programObject = getProgram(program);
6042 if (!programObject->isLinked())
6043 {
6044 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6045 {
6046 uniformIndices[uniformId] = GL_INVALID_INDEX;
6047 }
6048 }
6049 else
6050 {
6051 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6052 {
6053 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
6054 }
6055 }
6056}
6057
6058void Context::getActiveUniformsiv(GLuint program,
6059 GLsizei uniformCount,
6060 const GLuint *uniformIndices,
6061 GLenum pname,
6062 GLint *params)
6063{
6064 const Program *programObject = getProgram(program);
6065 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6066 {
6067 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08006068 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04006069 }
6070}
6071
6072GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
6073{
6074 const Program *programObject = getProgram(program);
6075 return programObject->getUniformBlockIndex(uniformBlockName);
6076}
6077
6078void Context::getActiveUniformBlockiv(GLuint program,
6079 GLuint uniformBlockIndex,
6080 GLenum pname,
6081 GLint *params)
6082{
6083 const Program *programObject = getProgram(program);
6084 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
6085}
6086
Brandon Jones59770802018-04-02 13:18:42 -07006087void Context::getActiveUniformBlockivRobust(GLuint program,
6088 GLuint uniformBlockIndex,
6089 GLenum pname,
6090 GLsizei bufSize,
6091 GLsizei *length,
6092 GLint *params)
6093{
6094 getActiveUniformBlockiv(program, uniformBlockIndex, pname, params);
6095}
6096
Jamie Madill12e957f2017-08-26 21:42:26 -04006097void Context::getActiveUniformBlockName(GLuint program,
6098 GLuint uniformBlockIndex,
6099 GLsizei bufSize,
6100 GLsizei *length,
6101 GLchar *uniformBlockName)
6102{
6103 const Program *programObject = getProgram(program);
6104 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
6105}
6106
6107void Context::uniformBlockBinding(GLuint program,
6108 GLuint uniformBlockIndex,
6109 GLuint uniformBlockBinding)
6110{
6111 Program *programObject = getProgram(program);
6112 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
6113}
6114
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006115GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
6116{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006117 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
6118 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006119
Jamie Madill70b5bb02017-08-28 13:32:37 -04006120 Sync *syncObject = getSync(syncHandle);
6121 Error error = syncObject->set(condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006122 if (error.isError())
6123 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04006124 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006125 handleError(error);
6126 return nullptr;
6127 }
6128
Jamie Madill70b5bb02017-08-28 13:32:37 -04006129 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006130}
6131
6132GLboolean Context::isSync(GLsync sync)
6133{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006134 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006135}
6136
6137GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6138{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006139 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006140
6141 GLenum result = GL_WAIT_FAILED;
6142 handleError(syncObject->clientWait(flags, timeout, &result));
6143 return result;
6144}
6145
6146void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6147{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006148 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006149 handleError(syncObject->serverWait(flags, timeout));
6150}
6151
6152void Context::getInteger64v(GLenum pname, GLint64 *params)
6153{
6154 GLenum nativeType = GL_NONE;
6155 unsigned int numParams = 0;
6156 getQueryParameterInfo(pname, &nativeType, &numParams);
6157
6158 if (nativeType == GL_INT_64_ANGLEX)
6159 {
6160 getInteger64vImpl(pname, params);
6161 }
6162 else
6163 {
6164 CastStateValues(this, nativeType, pname, numParams, params);
6165 }
6166}
6167
Brandon Jones59770802018-04-02 13:18:42 -07006168void Context::getInteger64vRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint64 *data)
6169{
6170 getInteger64v(pname, data);
6171}
6172
Corentin Wallez336129f2017-10-17 15:55:40 -04006173void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04006174{
6175 Buffer *buffer = mGLState.getTargetBuffer(target);
6176 QueryBufferParameteri64v(buffer, pname, params);
6177}
6178
Brandon Jones59770802018-04-02 13:18:42 -07006179void Context::getBufferParameteri64vRobust(BufferBinding target,
6180 GLenum pname,
6181 GLsizei bufSize,
6182 GLsizei *length,
6183 GLint64 *params)
6184{
6185 getBufferParameteri64v(target, pname, params);
6186}
6187
Jamie Madill3ef140a2017-08-26 23:11:21 -04006188void Context::genSamplers(GLsizei count, GLuint *samplers)
6189{
6190 for (int i = 0; i < count; i++)
6191 {
6192 samplers[i] = mState.mSamplers->createSampler();
6193 }
6194}
6195
6196void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
6197{
6198 for (int i = 0; i < count; i++)
6199 {
6200 GLuint sampler = samplers[i];
6201
6202 if (mState.mSamplers->getSampler(sampler))
6203 {
6204 detachSampler(sampler);
6205 }
6206
6207 mState.mSamplers->deleteObject(this, sampler);
6208 }
6209}
6210
6211void Context::getInternalformativ(GLenum target,
6212 GLenum internalformat,
6213 GLenum pname,
6214 GLsizei bufSize,
6215 GLint *params)
6216{
6217 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
6218 QueryInternalFormativ(formatCaps, pname, bufSize, params);
6219}
6220
Brandon Jones59770802018-04-02 13:18:42 -07006221void Context::getInternalformativRobust(GLenum target,
6222 GLenum internalformat,
6223 GLenum pname,
6224 GLsizei bufSize,
6225 GLsizei *length,
6226 GLint *params)
6227{
6228 getInternalformativ(target, internalformat, pname, bufSize, params);
6229}
6230
Jiajia Qin5451d532017-11-16 17:16:34 +08006231void Context::programUniform1i(GLuint program, GLint location, GLint v0)
6232{
6233 programUniform1iv(program, location, 1, &v0);
6234}
6235
6236void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
6237{
6238 GLint xy[2] = {v0, v1};
6239 programUniform2iv(program, location, 1, xy);
6240}
6241
6242void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
6243{
6244 GLint xyz[3] = {v0, v1, v2};
6245 programUniform3iv(program, location, 1, xyz);
6246}
6247
6248void Context::programUniform4i(GLuint program,
6249 GLint location,
6250 GLint v0,
6251 GLint v1,
6252 GLint v2,
6253 GLint v3)
6254{
6255 GLint xyzw[4] = {v0, v1, v2, v3};
6256 programUniform4iv(program, location, 1, xyzw);
6257}
6258
6259void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
6260{
6261 programUniform1uiv(program, location, 1, &v0);
6262}
6263
6264void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
6265{
6266 GLuint xy[2] = {v0, v1};
6267 programUniform2uiv(program, location, 1, xy);
6268}
6269
6270void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
6271{
6272 GLuint xyz[3] = {v0, v1, v2};
6273 programUniform3uiv(program, location, 1, xyz);
6274}
6275
6276void Context::programUniform4ui(GLuint program,
6277 GLint location,
6278 GLuint v0,
6279 GLuint v1,
6280 GLuint v2,
6281 GLuint v3)
6282{
6283 GLuint xyzw[4] = {v0, v1, v2, v3};
6284 programUniform4uiv(program, location, 1, xyzw);
6285}
6286
6287void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
6288{
6289 programUniform1fv(program, location, 1, &v0);
6290}
6291
6292void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
6293{
6294 GLfloat xy[2] = {v0, v1};
6295 programUniform2fv(program, location, 1, xy);
6296}
6297
6298void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
6299{
6300 GLfloat xyz[3] = {v0, v1, v2};
6301 programUniform3fv(program, location, 1, xyz);
6302}
6303
6304void Context::programUniform4f(GLuint program,
6305 GLint location,
6306 GLfloat v0,
6307 GLfloat v1,
6308 GLfloat v2,
6309 GLfloat v3)
6310{
6311 GLfloat xyzw[4] = {v0, v1, v2, v3};
6312 programUniform4fv(program, location, 1, xyzw);
6313}
6314
Jamie Madill81c2e252017-09-09 23:32:46 -04006315void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6316{
6317 Program *programObject = getProgram(program);
6318 ASSERT(programObject);
6319 if (programObject->setUniform1iv(location, count, value) ==
6320 Program::SetUniformResult::SamplerChanged)
6321 {
6322 mGLState.setObjectDirty(GL_PROGRAM);
6323 }
6324}
6325
Jiajia Qin5451d532017-11-16 17:16:34 +08006326void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6327{
6328 Program *programObject = getProgram(program);
6329 ASSERT(programObject);
6330 programObject->setUniform2iv(location, count, value);
6331}
6332
6333void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6334{
6335 Program *programObject = getProgram(program);
6336 ASSERT(programObject);
6337 programObject->setUniform3iv(location, count, value);
6338}
6339
6340void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6341{
6342 Program *programObject = getProgram(program);
6343 ASSERT(programObject);
6344 programObject->setUniform4iv(location, count, value);
6345}
6346
6347void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6348{
6349 Program *programObject = getProgram(program);
6350 ASSERT(programObject);
6351 programObject->setUniform1uiv(location, count, value);
6352}
6353
6354void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6355{
6356 Program *programObject = getProgram(program);
6357 ASSERT(programObject);
6358 programObject->setUniform2uiv(location, count, value);
6359}
6360
6361void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6362{
6363 Program *programObject = getProgram(program);
6364 ASSERT(programObject);
6365 programObject->setUniform3uiv(location, count, value);
6366}
6367
6368void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6369{
6370 Program *programObject = getProgram(program);
6371 ASSERT(programObject);
6372 programObject->setUniform4uiv(location, count, value);
6373}
6374
6375void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6376{
6377 Program *programObject = getProgram(program);
6378 ASSERT(programObject);
6379 programObject->setUniform1fv(location, count, value);
6380}
6381
6382void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6383{
6384 Program *programObject = getProgram(program);
6385 ASSERT(programObject);
6386 programObject->setUniform2fv(location, count, value);
6387}
6388
6389void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6390{
6391 Program *programObject = getProgram(program);
6392 ASSERT(programObject);
6393 programObject->setUniform3fv(location, count, value);
6394}
6395
6396void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6397{
6398 Program *programObject = getProgram(program);
6399 ASSERT(programObject);
6400 programObject->setUniform4fv(location, count, value);
6401}
6402
6403void Context::programUniformMatrix2fv(GLuint program,
6404 GLint location,
6405 GLsizei count,
6406 GLboolean transpose,
6407 const GLfloat *value)
6408{
6409 Program *programObject = getProgram(program);
6410 ASSERT(programObject);
6411 programObject->setUniformMatrix2fv(location, count, transpose, value);
6412}
6413
6414void Context::programUniformMatrix3fv(GLuint program,
6415 GLint location,
6416 GLsizei count,
6417 GLboolean transpose,
6418 const GLfloat *value)
6419{
6420 Program *programObject = getProgram(program);
6421 ASSERT(programObject);
6422 programObject->setUniformMatrix3fv(location, count, transpose, value);
6423}
6424
6425void Context::programUniformMatrix4fv(GLuint program,
6426 GLint location,
6427 GLsizei count,
6428 GLboolean transpose,
6429 const GLfloat *value)
6430{
6431 Program *programObject = getProgram(program);
6432 ASSERT(programObject);
6433 programObject->setUniformMatrix4fv(location, count, transpose, value);
6434}
6435
6436void Context::programUniformMatrix2x3fv(GLuint program,
6437 GLint location,
6438 GLsizei count,
6439 GLboolean transpose,
6440 const GLfloat *value)
6441{
6442 Program *programObject = getProgram(program);
6443 ASSERT(programObject);
6444 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
6445}
6446
6447void Context::programUniformMatrix3x2fv(GLuint program,
6448 GLint location,
6449 GLsizei count,
6450 GLboolean transpose,
6451 const GLfloat *value)
6452{
6453 Program *programObject = getProgram(program);
6454 ASSERT(programObject);
6455 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
6456}
6457
6458void Context::programUniformMatrix2x4fv(GLuint program,
6459 GLint location,
6460 GLsizei count,
6461 GLboolean transpose,
6462 const GLfloat *value)
6463{
6464 Program *programObject = getProgram(program);
6465 ASSERT(programObject);
6466 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
6467}
6468
6469void Context::programUniformMatrix4x2fv(GLuint program,
6470 GLint location,
6471 GLsizei count,
6472 GLboolean transpose,
6473 const GLfloat *value)
6474{
6475 Program *programObject = getProgram(program);
6476 ASSERT(programObject);
6477 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
6478}
6479
6480void Context::programUniformMatrix3x4fv(GLuint program,
6481 GLint location,
6482 GLsizei count,
6483 GLboolean transpose,
6484 const GLfloat *value)
6485{
6486 Program *programObject = getProgram(program);
6487 ASSERT(programObject);
6488 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
6489}
6490
6491void Context::programUniformMatrix4x3fv(GLuint program,
6492 GLint location,
6493 GLsizei count,
6494 GLboolean transpose,
6495 const GLfloat *value)
6496{
6497 Program *programObject = getProgram(program);
6498 ASSERT(programObject);
6499 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
6500}
6501
Jamie Madill81c2e252017-09-09 23:32:46 -04006502void Context::onTextureChange(const Texture *texture)
6503{
6504 // Conservatively assume all textures are dirty.
6505 // TODO(jmadill): More fine-grained update.
6506 mGLState.setObjectDirty(GL_TEXTURE);
6507}
6508
James Darpiniane8a93c62018-01-04 18:02:24 -08006509bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
6510{
6511 return mGLState.isCurrentTransformFeedback(tf);
6512}
6513bool Context::isCurrentVertexArray(const VertexArray *va) const
6514{
6515 return mGLState.isCurrentVertexArray(va);
6516}
6517
Yunchao Hea336b902017-08-02 16:05:21 +08006518void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
6519{
6520 for (int i = 0; i < count; i++)
6521 {
6522 pipelines[i] = createProgramPipeline();
6523 }
6524}
6525
6526void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
6527{
6528 for (int i = 0; i < count; i++)
6529 {
6530 if (pipelines[i] != 0)
6531 {
6532 deleteProgramPipeline(pipelines[i]);
6533 }
6534 }
6535}
6536
6537GLboolean Context::isProgramPipeline(GLuint pipeline)
6538{
6539 if (pipeline == 0)
6540 {
6541 return GL_FALSE;
6542 }
6543
6544 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
6545}
6546
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006547void Context::finishFenceNV(GLuint fence)
6548{
6549 FenceNV *fenceObject = getFenceNV(fence);
6550
6551 ASSERT(fenceObject && fenceObject->isSet());
6552 handleError(fenceObject->finish());
6553}
6554
6555void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
6556{
6557 FenceNV *fenceObject = getFenceNV(fence);
6558
6559 ASSERT(fenceObject && fenceObject->isSet());
6560
6561 switch (pname)
6562 {
6563 case GL_FENCE_STATUS_NV:
6564 {
6565 // GL_NV_fence spec:
6566 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
6567 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
6568 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
6569 GLboolean status = GL_TRUE;
6570 if (fenceObject->getStatus() != GL_TRUE)
6571 {
6572 ANGLE_CONTEXT_TRY(fenceObject->test(&status));
6573 }
6574 *params = status;
6575 break;
6576 }
6577
6578 case GL_FENCE_CONDITION_NV:
6579 {
6580 *params = static_cast<GLint>(fenceObject->getCondition());
6581 break;
6582 }
6583
6584 default:
6585 UNREACHABLE();
6586 }
6587}
6588
6589void Context::getTranslatedShaderSource(GLuint shader,
6590 GLsizei bufsize,
6591 GLsizei *length,
6592 GLchar *source)
6593{
6594 Shader *shaderObject = getShader(shader);
6595 ASSERT(shaderObject);
6596 shaderObject->getTranslatedSourceWithDebugInfo(this, bufsize, length, source);
6597}
6598
6599void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
6600{
6601 Program *programObject = getProgram(program);
6602 ASSERT(programObject);
6603
6604 programObject->getUniformfv(this, location, params);
6605}
6606
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006607void Context::getnUniformfvRobust(GLuint program,
6608 GLint location,
6609 GLsizei bufSize,
6610 GLsizei *length,
6611 GLfloat *params)
6612{
6613 UNIMPLEMENTED();
6614}
6615
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006616void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
6617{
6618 Program *programObject = getProgram(program);
6619 ASSERT(programObject);
6620
6621 programObject->getUniformiv(this, location, params);
6622}
6623
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006624void Context::getnUniformivRobust(GLuint program,
6625 GLint location,
6626 GLsizei bufSize,
6627 GLsizei *length,
6628 GLint *params)
6629{
6630 UNIMPLEMENTED();
6631}
6632
6633void Context::getnUniformuivRobust(GLuint program,
6634 GLint location,
6635 GLsizei bufSize,
6636 GLsizei *length,
6637 GLuint *params)
6638{
6639 UNIMPLEMENTED();
6640}
6641
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006642GLboolean Context::isFenceNV(GLuint fence)
6643{
6644 FenceNV *fenceObject = getFenceNV(fence);
6645
6646 if (fenceObject == nullptr)
6647 {
6648 return GL_FALSE;
6649 }
6650
6651 // GL_NV_fence spec:
6652 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
6653 // existing fence.
6654 return fenceObject->isSet();
6655}
6656
6657void Context::readnPixels(GLint x,
6658 GLint y,
6659 GLsizei width,
6660 GLsizei height,
6661 GLenum format,
6662 GLenum type,
6663 GLsizei bufSize,
6664 void *data)
6665{
6666 return readPixels(x, y, width, height, format, type, data);
6667}
6668
Jamie Madill007530e2017-12-28 14:27:04 -05006669void Context::setFenceNV(GLuint fence, GLenum condition)
6670{
6671 ASSERT(condition == GL_ALL_COMPLETED_NV);
6672
6673 FenceNV *fenceObject = getFenceNV(fence);
6674 ASSERT(fenceObject != nullptr);
6675 handleError(fenceObject->set(condition));
6676}
6677
6678GLboolean Context::testFenceNV(GLuint fence)
6679{
6680 FenceNV *fenceObject = getFenceNV(fence);
6681
6682 ASSERT(fenceObject != nullptr);
6683 ASSERT(fenceObject->isSet() == GL_TRUE);
6684
6685 GLboolean result = GL_TRUE;
6686 Error error = fenceObject->test(&result);
6687 if (error.isError())
6688 {
6689 handleError(error);
6690 return GL_TRUE;
6691 }
6692
6693 return result;
6694}
6695
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006696void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006697{
6698 Texture *texture = getTargetTexture(target);
Rafael Cintron05a449a2018-06-20 18:08:04 -07006699 egl::Image *imageObject = static_cast<egl::Image *>(image);
Corentin Wallez99d492c2018-02-27 15:17:10 -05006700 handleError(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05006701}
6702
Jamie Madillfa920eb2018-01-04 11:45:50 -05006703void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006704{
6705 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Rafael Cintron05a449a2018-06-20 18:08:04 -07006706 egl::Image *imageObject = static_cast<egl::Image *>(image);
Jamie Madill007530e2017-12-28 14:27:04 -05006707 handleError(renderbuffer->setStorageEGLImageTarget(this, imageObject));
6708}
6709
Jamie Madillfa920eb2018-01-04 11:45:50 -05006710void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
6711{
6712 UNIMPLEMENTED();
6713}
6714
Jamie Madill5b772312018-03-08 20:28:32 -05006715bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
6716{
6717 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
6718 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
6719 // to the fact that it is stored internally as a float, and so would require conversion
6720 // if returned from Context::getIntegerv. Since this conversion is already implemented
6721 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
6722 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
6723 // application.
6724 switch (pname)
6725 {
6726 case GL_COMPRESSED_TEXTURE_FORMATS:
6727 {
6728 *type = GL_INT;
6729 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
6730 return true;
6731 }
6732 case GL_SHADER_BINARY_FORMATS:
6733 {
6734 *type = GL_INT;
6735 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
6736 return true;
6737 }
6738
6739 case GL_MAX_VERTEX_ATTRIBS:
6740 case GL_MAX_VERTEX_UNIFORM_VECTORS:
6741 case GL_MAX_VARYING_VECTORS:
6742 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
6743 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
6744 case GL_MAX_TEXTURE_IMAGE_UNITS:
6745 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
6746 case GL_MAX_RENDERBUFFER_SIZE:
6747 case GL_NUM_SHADER_BINARY_FORMATS:
6748 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
6749 case GL_ARRAY_BUFFER_BINDING:
6750 case GL_FRAMEBUFFER_BINDING:
6751 case GL_RENDERBUFFER_BINDING:
6752 case GL_CURRENT_PROGRAM:
6753 case GL_PACK_ALIGNMENT:
6754 case GL_UNPACK_ALIGNMENT:
6755 case GL_GENERATE_MIPMAP_HINT:
6756 case GL_RED_BITS:
6757 case GL_GREEN_BITS:
6758 case GL_BLUE_BITS:
6759 case GL_ALPHA_BITS:
6760 case GL_DEPTH_BITS:
6761 case GL_STENCIL_BITS:
6762 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
6763 case GL_CULL_FACE_MODE:
6764 case GL_FRONT_FACE:
6765 case GL_ACTIVE_TEXTURE:
6766 case GL_STENCIL_FUNC:
6767 case GL_STENCIL_VALUE_MASK:
6768 case GL_STENCIL_REF:
6769 case GL_STENCIL_FAIL:
6770 case GL_STENCIL_PASS_DEPTH_FAIL:
6771 case GL_STENCIL_PASS_DEPTH_PASS:
6772 case GL_STENCIL_BACK_FUNC:
6773 case GL_STENCIL_BACK_VALUE_MASK:
6774 case GL_STENCIL_BACK_REF:
6775 case GL_STENCIL_BACK_FAIL:
6776 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
6777 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
6778 case GL_DEPTH_FUNC:
6779 case GL_BLEND_SRC_RGB:
6780 case GL_BLEND_SRC_ALPHA:
6781 case GL_BLEND_DST_RGB:
6782 case GL_BLEND_DST_ALPHA:
6783 case GL_BLEND_EQUATION_RGB:
6784 case GL_BLEND_EQUATION_ALPHA:
6785 case GL_STENCIL_WRITEMASK:
6786 case GL_STENCIL_BACK_WRITEMASK:
6787 case GL_STENCIL_CLEAR_VALUE:
6788 case GL_SUBPIXEL_BITS:
6789 case GL_MAX_TEXTURE_SIZE:
6790 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
6791 case GL_SAMPLE_BUFFERS:
6792 case GL_SAMPLES:
6793 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
6794 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
6795 case GL_TEXTURE_BINDING_2D:
6796 case GL_TEXTURE_BINDING_CUBE_MAP:
6797 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
6798 {
6799 *type = GL_INT;
6800 *numParams = 1;
6801 return true;
6802 }
6803 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6804 {
6805 if (!getExtensions().packReverseRowOrder)
6806 {
6807 return false;
6808 }
6809 *type = GL_INT;
6810 *numParams = 1;
6811 return true;
6812 }
6813 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
6814 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
6815 {
6816 if (!getExtensions().textureRectangle)
6817 {
6818 return false;
6819 }
6820 *type = GL_INT;
6821 *numParams = 1;
6822 return true;
6823 }
6824 case GL_MAX_DRAW_BUFFERS_EXT:
6825 case GL_MAX_COLOR_ATTACHMENTS_EXT:
6826 {
6827 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
6828 {
6829 return false;
6830 }
6831 *type = GL_INT;
6832 *numParams = 1;
6833 return true;
6834 }
6835 case GL_MAX_VIEWPORT_DIMS:
6836 {
6837 *type = GL_INT;
6838 *numParams = 2;
6839 return true;
6840 }
6841 case GL_VIEWPORT:
6842 case GL_SCISSOR_BOX:
6843 {
6844 *type = GL_INT;
6845 *numParams = 4;
6846 return true;
6847 }
6848 case GL_SHADER_COMPILER:
6849 case GL_SAMPLE_COVERAGE_INVERT:
6850 case GL_DEPTH_WRITEMASK:
6851 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
6852 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
6853 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
6854 // bool-natural
6855 case GL_SAMPLE_COVERAGE:
6856 case GL_SCISSOR_TEST:
6857 case GL_STENCIL_TEST:
6858 case GL_DEPTH_TEST:
6859 case GL_BLEND:
6860 case GL_DITHER:
6861 case GL_CONTEXT_ROBUST_ACCESS_EXT:
6862 {
6863 *type = GL_BOOL;
6864 *numParams = 1;
6865 return true;
6866 }
6867 case GL_COLOR_WRITEMASK:
6868 {
6869 *type = GL_BOOL;
6870 *numParams = 4;
6871 return true;
6872 }
6873 case GL_POLYGON_OFFSET_FACTOR:
6874 case GL_POLYGON_OFFSET_UNITS:
6875 case GL_SAMPLE_COVERAGE_VALUE:
6876 case GL_DEPTH_CLEAR_VALUE:
6877 case GL_LINE_WIDTH:
6878 {
6879 *type = GL_FLOAT;
6880 *numParams = 1;
6881 return true;
6882 }
6883 case GL_ALIASED_LINE_WIDTH_RANGE:
6884 case GL_ALIASED_POINT_SIZE_RANGE:
6885 case GL_DEPTH_RANGE:
6886 {
6887 *type = GL_FLOAT;
6888 *numParams = 2;
6889 return true;
6890 }
6891 case GL_COLOR_CLEAR_VALUE:
6892 case GL_BLEND_COLOR:
6893 {
6894 *type = GL_FLOAT;
6895 *numParams = 4;
6896 return true;
6897 }
6898 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
6899 if (!getExtensions().textureFilterAnisotropic)
6900 {
6901 return false;
6902 }
6903 *type = GL_FLOAT;
6904 *numParams = 1;
6905 return true;
6906 case GL_TIMESTAMP_EXT:
6907 if (!getExtensions().disjointTimerQuery)
6908 {
6909 return false;
6910 }
6911 *type = GL_INT_64_ANGLEX;
6912 *numParams = 1;
6913 return true;
6914 case GL_GPU_DISJOINT_EXT:
6915 if (!getExtensions().disjointTimerQuery)
6916 {
6917 return false;
6918 }
6919 *type = GL_INT;
6920 *numParams = 1;
6921 return true;
6922 case GL_COVERAGE_MODULATION_CHROMIUM:
6923 if (!getExtensions().framebufferMixedSamples)
6924 {
6925 return false;
6926 }
6927 *type = GL_INT;
6928 *numParams = 1;
6929 return true;
6930 case GL_TEXTURE_BINDING_EXTERNAL_OES:
6931 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
6932 {
6933 return false;
6934 }
6935 *type = GL_INT;
6936 *numParams = 1;
6937 return true;
6938 }
6939
6940 if (getExtensions().debug)
6941 {
6942 switch (pname)
6943 {
6944 case GL_DEBUG_LOGGED_MESSAGES:
6945 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
6946 case GL_DEBUG_GROUP_STACK_DEPTH:
6947 case GL_MAX_DEBUG_MESSAGE_LENGTH:
6948 case GL_MAX_DEBUG_LOGGED_MESSAGES:
6949 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
6950 case GL_MAX_LABEL_LENGTH:
6951 *type = GL_INT;
6952 *numParams = 1;
6953 return true;
6954
6955 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
6956 case GL_DEBUG_OUTPUT:
6957 *type = GL_BOOL;
6958 *numParams = 1;
6959 return true;
6960 }
6961 }
6962
6963 if (getExtensions().multisampleCompatibility)
6964 {
6965 switch (pname)
6966 {
6967 case GL_MULTISAMPLE_EXT:
6968 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
6969 *type = GL_BOOL;
6970 *numParams = 1;
6971 return true;
6972 }
6973 }
6974
6975 if (getExtensions().pathRendering)
6976 {
6977 switch (pname)
6978 {
6979 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
6980 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
6981 *type = GL_FLOAT;
6982 *numParams = 16;
6983 return true;
6984 }
6985 }
6986
6987 if (getExtensions().bindGeneratesResource)
6988 {
6989 switch (pname)
6990 {
6991 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
6992 *type = GL_BOOL;
6993 *numParams = 1;
6994 return true;
6995 }
6996 }
6997
6998 if (getExtensions().clientArrays)
6999 {
7000 switch (pname)
7001 {
7002 case GL_CLIENT_ARRAYS_ANGLE:
7003 *type = GL_BOOL;
7004 *numParams = 1;
7005 return true;
7006 }
7007 }
7008
7009 if (getExtensions().sRGBWriteControl)
7010 {
7011 switch (pname)
7012 {
7013 case GL_FRAMEBUFFER_SRGB_EXT:
7014 *type = GL_BOOL;
7015 *numParams = 1;
7016 return true;
7017 }
7018 }
7019
7020 if (getExtensions().robustResourceInitialization &&
7021 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
7022 {
7023 *type = GL_BOOL;
7024 *numParams = 1;
7025 return true;
7026 }
7027
7028 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
7029 {
7030 *type = GL_BOOL;
7031 *numParams = 1;
7032 return true;
7033 }
7034
jchen1082af6202018-06-22 10:59:52 +08007035 if (getExtensions().parallelShaderCompile && pname == GL_MAX_SHADER_COMPILER_THREADS_KHR)
7036 {
7037 *type = GL_INT;
7038 *numParams = 1;
7039 return true;
7040 }
7041
Jamie Madill5b772312018-03-08 20:28:32 -05007042 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
7043 switch (pname)
7044 {
7045 // case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE // equivalent to FRAMEBUFFER_BINDING
7046 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
7047 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
7048 {
7049 return false;
7050 }
7051 *type = GL_INT;
7052 *numParams = 1;
7053 return true;
7054
7055 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
7056 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7057 {
7058 return false;
7059 }
7060 *type = GL_INT;
7061 *numParams = 1;
7062 return true;
7063
7064 case GL_PROGRAM_BINARY_FORMATS_OES:
7065 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7066 {
7067 return false;
7068 }
7069 *type = GL_INT;
7070 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
7071 return true;
7072
7073 case GL_PACK_ROW_LENGTH:
7074 case GL_PACK_SKIP_ROWS:
7075 case GL_PACK_SKIP_PIXELS:
7076 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
7077 {
7078 return false;
7079 }
7080 *type = GL_INT;
7081 *numParams = 1;
7082 return true;
7083 case GL_UNPACK_ROW_LENGTH:
7084 case GL_UNPACK_SKIP_ROWS:
7085 case GL_UNPACK_SKIP_PIXELS:
7086 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
7087 {
7088 return false;
7089 }
7090 *type = GL_INT;
7091 *numParams = 1;
7092 return true;
7093 case GL_VERTEX_ARRAY_BINDING:
7094 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
7095 {
7096 return false;
7097 }
7098 *type = GL_INT;
7099 *numParams = 1;
7100 return true;
7101 case GL_PIXEL_PACK_BUFFER_BINDING:
7102 case GL_PIXEL_UNPACK_BUFFER_BINDING:
7103 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
7104 {
7105 return false;
7106 }
7107 *type = GL_INT;
7108 *numParams = 1;
7109 return true;
7110 case GL_MAX_SAMPLES:
7111 {
7112 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
7113 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
7114 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
7115 {
7116 return false;
7117 }
7118 *type = GL_INT;
7119 *numParams = 1;
7120 return true;
7121
7122 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
7123 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
7124 {
7125 return false;
7126 }
7127 *type = GL_INT;
7128 *numParams = 1;
7129 return true;
7130 }
7131 }
7132
7133 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
7134 {
7135 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
7136 {
7137 return false;
7138 }
7139 *type = GL_INT;
7140 *numParams = 1;
7141 return true;
7142 }
7143
7144 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
7145 {
7146 *type = GL_INT;
7147 *numParams = 1;
7148 return true;
7149 }
7150
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007151 if (getClientVersion() < Version(2, 0))
7152 {
7153 switch (pname)
7154 {
7155 case GL_ALPHA_TEST_FUNC:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007156 case GL_CLIENT_ACTIVE_TEXTURE:
7157 case GL_MATRIX_MODE:
7158 case GL_MAX_TEXTURE_UNITS:
7159 case GL_MAX_MODELVIEW_STACK_DEPTH:
7160 case GL_MAX_PROJECTION_STACK_DEPTH:
7161 case GL_MAX_TEXTURE_STACK_DEPTH:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007162 case GL_MAX_LIGHTS:
Lingfeng Yang060088a2018-05-30 20:40:57 -07007163 case GL_MAX_CLIP_PLANES:
Lingfeng Yangabb09f12018-04-16 10:43:53 -07007164 case GL_VERTEX_ARRAY_STRIDE:
7165 case GL_NORMAL_ARRAY_STRIDE:
7166 case GL_COLOR_ARRAY_STRIDE:
7167 case GL_TEXTURE_COORD_ARRAY_STRIDE:
7168 case GL_VERTEX_ARRAY_SIZE:
7169 case GL_COLOR_ARRAY_SIZE:
7170 case GL_TEXTURE_COORD_ARRAY_SIZE:
7171 case GL_VERTEX_ARRAY_TYPE:
7172 case GL_NORMAL_ARRAY_TYPE:
7173 case GL_COLOR_ARRAY_TYPE:
7174 case GL_TEXTURE_COORD_ARRAY_TYPE:
7175 case GL_VERTEX_ARRAY_BUFFER_BINDING:
7176 case GL_NORMAL_ARRAY_BUFFER_BINDING:
7177 case GL_COLOR_ARRAY_BUFFER_BINDING:
7178 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
7179 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
7180 case GL_POINT_SIZE_ARRAY_TYPE_OES:
7181 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
Lingfeng Yanga0cfa872018-05-30 21:12:17 -07007182 case GL_SHADE_MODEL:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007183 *type = GL_INT;
7184 *numParams = 1;
7185 return true;
7186 case GL_ALPHA_TEST_REF:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007187 case GL_FOG_DENSITY:
7188 case GL_FOG_START:
7189 case GL_FOG_END:
7190 case GL_FOG_MODE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007191 case GL_POINT_SIZE:
7192 case GL_POINT_SIZE_MIN:
7193 case GL_POINT_SIZE_MAX:
7194 case GL_POINT_FADE_THRESHOLD_SIZE:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007195 *type = GL_FLOAT;
7196 *numParams = 1;
7197 return true;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007198 case GL_SMOOTH_POINT_SIZE_RANGE:
7199 *type = GL_FLOAT;
7200 *numParams = 2;
7201 return true;
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007202 case GL_CURRENT_COLOR:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007203 case GL_CURRENT_TEXTURE_COORDS:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007204 case GL_LIGHT_MODEL_AMBIENT:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007205 case GL_FOG_COLOR:
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007206 *type = GL_FLOAT;
7207 *numParams = 4;
7208 return true;
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007209 case GL_CURRENT_NORMAL:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007210 case GL_POINT_DISTANCE_ATTENUATION:
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007211 *type = GL_FLOAT;
7212 *numParams = 3;
7213 return true;
Lingfeng Yang3a41af62018-04-09 07:28:56 -07007214 case GL_MODELVIEW_MATRIX:
7215 case GL_PROJECTION_MATRIX:
7216 case GL_TEXTURE_MATRIX:
7217 *type = GL_FLOAT;
7218 *numParams = 16;
7219 return true;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007220 case GL_LIGHT_MODEL_TWO_SIDE:
7221 *type = GL_BOOL;
7222 *numParams = 1;
7223 return true;
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007224 }
7225 }
7226
Jamie Madill5b772312018-03-08 20:28:32 -05007227 if (getClientVersion() < Version(3, 0))
7228 {
7229 return false;
7230 }
7231
7232 // Check for ES3.0+ parameter names
7233 switch (pname)
7234 {
7235 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
7236 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
7237 case GL_UNIFORM_BUFFER_BINDING:
7238 case GL_TRANSFORM_FEEDBACK_BINDING:
7239 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7240 case GL_COPY_READ_BUFFER_BINDING:
7241 case GL_COPY_WRITE_BUFFER_BINDING:
7242 case GL_SAMPLER_BINDING:
7243 case GL_READ_BUFFER:
7244 case GL_TEXTURE_BINDING_3D:
7245 case GL_TEXTURE_BINDING_2D_ARRAY:
7246 case GL_MAX_3D_TEXTURE_SIZE:
7247 case GL_MAX_ARRAY_TEXTURE_LAYERS:
7248 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
7249 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
7250 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
7251 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
7252 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
7253 case GL_MAX_VARYING_COMPONENTS:
7254 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
7255 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
7256 case GL_MIN_PROGRAM_TEXEL_OFFSET:
7257 case GL_MAX_PROGRAM_TEXEL_OFFSET:
7258 case GL_NUM_EXTENSIONS:
7259 case GL_MAJOR_VERSION:
7260 case GL_MINOR_VERSION:
7261 case GL_MAX_ELEMENTS_INDICES:
7262 case GL_MAX_ELEMENTS_VERTICES:
7263 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
7264 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
7265 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
7266 case GL_UNPACK_IMAGE_HEIGHT:
7267 case GL_UNPACK_SKIP_IMAGES:
7268 {
7269 *type = GL_INT;
7270 *numParams = 1;
7271 return true;
7272 }
7273
7274 case GL_MAX_ELEMENT_INDEX:
7275 case GL_MAX_UNIFORM_BLOCK_SIZE:
7276 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
7277 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
7278 case GL_MAX_SERVER_WAIT_TIMEOUT:
7279 {
7280 *type = GL_INT_64_ANGLEX;
7281 *numParams = 1;
7282 return true;
7283 }
7284
7285 case GL_TRANSFORM_FEEDBACK_ACTIVE:
7286 case GL_TRANSFORM_FEEDBACK_PAUSED:
7287 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
7288 case GL_RASTERIZER_DISCARD:
7289 {
7290 *type = GL_BOOL;
7291 *numParams = 1;
7292 return true;
7293 }
7294
7295 case GL_MAX_TEXTURE_LOD_BIAS:
7296 {
7297 *type = GL_FLOAT;
7298 *numParams = 1;
7299 return true;
7300 }
7301 }
7302
7303 if (getExtensions().requestExtension)
7304 {
7305 switch (pname)
7306 {
7307 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
7308 *type = GL_INT;
7309 *numParams = 1;
7310 return true;
7311 }
7312 }
7313
7314 if (getClientVersion() < Version(3, 1))
7315 {
7316 return false;
7317 }
7318
7319 switch (pname)
7320 {
7321 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7322 case GL_DRAW_INDIRECT_BUFFER_BINDING:
7323 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
7324 case GL_MAX_FRAMEBUFFER_WIDTH:
7325 case GL_MAX_FRAMEBUFFER_HEIGHT:
7326 case GL_MAX_FRAMEBUFFER_SAMPLES:
7327 case GL_MAX_SAMPLE_MASK_WORDS:
7328 case GL_MAX_COLOR_TEXTURE_SAMPLES:
7329 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
7330 case GL_MAX_INTEGER_SAMPLES:
7331 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
7332 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
7333 case GL_MAX_VERTEX_ATTRIB_STRIDE:
7334 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
7335 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
7336 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
7337 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
7338 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
7339 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
7340 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
7341 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
7342 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
7343 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
7344 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
7345 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
7346 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
7347 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
7348 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
7349 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
7350 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
7351 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
7352 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
7353 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
7354 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
7355 case GL_MAX_UNIFORM_LOCATIONS:
7356 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
7357 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
7358 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
7359 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
7360 case GL_MAX_IMAGE_UNITS:
7361 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
7362 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
7363 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
7364 case GL_SHADER_STORAGE_BUFFER_BINDING:
7365 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
7366 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
7367 *type = GL_INT;
7368 *numParams = 1;
7369 return true;
7370 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7371 *type = GL_INT_64_ANGLEX;
7372 *numParams = 1;
7373 return true;
7374 case GL_SAMPLE_MASK:
7375 *type = GL_BOOL;
7376 *numParams = 1;
7377 return true;
7378 }
7379
7380 if (getExtensions().geometryShader)
7381 {
7382 switch (pname)
7383 {
7384 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7385 case GL_LAYER_PROVOKING_VERTEX_EXT:
7386 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7387 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7388 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7389 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7390 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7391 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7392 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7393 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7394 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7395 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7396 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7397 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7398 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7399 *type = GL_INT;
7400 *numParams = 1;
7401 return true;
7402 }
7403 }
7404
7405 return false;
7406}
7407
7408bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7409{
7410 if (getClientVersion() < Version(3, 0))
7411 {
7412 return false;
7413 }
7414
7415 switch (target)
7416 {
7417 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7418 case GL_UNIFORM_BUFFER_BINDING:
7419 {
7420 *type = GL_INT;
7421 *numParams = 1;
7422 return true;
7423 }
7424 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7425 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7426 case GL_UNIFORM_BUFFER_START:
7427 case GL_UNIFORM_BUFFER_SIZE:
7428 {
7429 *type = GL_INT_64_ANGLEX;
7430 *numParams = 1;
7431 return true;
7432 }
7433 }
7434
7435 if (getClientVersion() < Version(3, 1))
7436 {
7437 return false;
7438 }
7439
7440 switch (target)
7441 {
7442 case GL_IMAGE_BINDING_LAYERED:
7443 {
7444 *type = GL_BOOL;
7445 *numParams = 1;
7446 return true;
7447 }
7448 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7449 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7450 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7451 case GL_SHADER_STORAGE_BUFFER_BINDING:
7452 case GL_VERTEX_BINDING_BUFFER:
7453 case GL_VERTEX_BINDING_DIVISOR:
7454 case GL_VERTEX_BINDING_OFFSET:
7455 case GL_VERTEX_BINDING_STRIDE:
7456 case GL_SAMPLE_MASK_VALUE:
7457 case GL_IMAGE_BINDING_NAME:
7458 case GL_IMAGE_BINDING_LEVEL:
7459 case GL_IMAGE_BINDING_LAYER:
7460 case GL_IMAGE_BINDING_ACCESS:
7461 case GL_IMAGE_BINDING_FORMAT:
7462 {
7463 *type = GL_INT;
7464 *numParams = 1;
7465 return true;
7466 }
7467 case GL_ATOMIC_COUNTER_BUFFER_START:
7468 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
7469 case GL_SHADER_STORAGE_BUFFER_START:
7470 case GL_SHADER_STORAGE_BUFFER_SIZE:
7471 {
7472 *type = GL_INT_64_ANGLEX;
7473 *numParams = 1;
7474 return true;
7475 }
7476 }
7477
7478 return false;
7479}
7480
7481Program *Context::getProgram(GLuint handle) const
7482{
7483 return mState.mShaderPrograms->getProgram(handle);
7484}
7485
7486Shader *Context::getShader(GLuint handle) const
7487{
7488 return mState.mShaderPrograms->getShader(handle);
7489}
7490
7491bool Context::isTextureGenerated(GLuint texture) const
7492{
7493 return mState.mTextures->isHandleGenerated(texture);
7494}
7495
7496bool Context::isBufferGenerated(GLuint buffer) const
7497{
7498 return mState.mBuffers->isHandleGenerated(buffer);
7499}
7500
7501bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
7502{
7503 return mState.mRenderbuffers->isHandleGenerated(renderbuffer);
7504}
7505
7506bool Context::isFramebufferGenerated(GLuint framebuffer) const
7507{
7508 return mState.mFramebuffers->isHandleGenerated(framebuffer);
7509}
7510
7511bool Context::isProgramPipelineGenerated(GLuint pipeline) const
7512{
7513 return mState.mPipelines->isHandleGenerated(pipeline);
7514}
7515
7516bool Context::usingDisplayTextureShareGroup() const
7517{
7518 return mDisplayTextureShareGroup;
7519}
7520
7521GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
7522{
7523 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
7524 internalformat == GL_DEPTH_STENCIL
7525 ? GL_DEPTH24_STENCIL8
7526 : internalformat;
7527}
7528
jchen1082af6202018-06-22 10:59:52 +08007529void Context::maxShaderCompilerThreads(GLuint count)
7530{
7531 mGLState.setMaxShaderCompilerThreads(count);
7532}
7533
Jamie Madill6b873dd2018-07-12 23:56:30 -04007534// ErrorSet implementation.
7535ErrorSet::ErrorSet(Context *context) : mContext(context)
7536{
7537}
7538
7539ErrorSet::~ErrorSet() = default;
7540
7541void ErrorSet::handleError(const Error &error)
7542{
7543 // This internal enum is used to filter internal errors that are already handled.
7544 // TODO(jmadill): Remove this when refactor is done. http://anglebug.com/2491
7545 if (error.getCode() == GL_INTERNAL_ERROR_ANGLEX)
7546 {
7547 return;
7548 }
7549
7550 if (ANGLE_UNLIKELY(error.isError()))
7551 {
7552 GLenum code = error.getCode();
7553 mErrors.insert(code);
7554 if (code == GL_OUT_OF_MEMORY && mContext->getWorkarounds().loseContextOnOutOfMemory)
7555 {
7556 mContext->markContextLost();
7557 }
7558
7559 ASSERT(!error.getMessage().empty());
7560 mContext->getGLState().getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR,
7561 error.getID(), GL_DEBUG_SEVERITY_HIGH,
7562 error.getMessage());
7563 }
7564}
7565
7566bool ErrorSet::empty() const
7567{
7568 return mErrors.empty();
7569}
7570
7571GLenum ErrorSet::popError()
7572{
7573 ASSERT(!empty());
7574 GLenum error = *mErrors.begin();
7575 mErrors.erase(mErrors.begin());
7576 return error;
7577}
Jamie Madillc29968b2016-01-20 11:17:23 -05007578} // namespace gl