blob: a263510671f9bd10e77925c281cca0b5c903b341 [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),
333 mHasBeenCurrent(false),
334 mContextLost(false),
335 mResetStatus(GL_NO_ERROR),
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700336 mContextLostForced(false),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500337 mResetStrategy(GetResetStrategy(attribs)),
338 mRobustAccess(GetRobustAccess(attribs)),
Geoff Lang33f11fb2018-05-07 13:42:47 -0400339 mSurfacelessSupported(displayExtensions.surfacelessContext),
340 mExplicitContextAvailable(clientExtensions.explicitContext),
Jamie Madill61e16b42017-06-19 11:13:23 -0400341 mCurrentSurface(static_cast<egl::Surface *>(EGL_NO_SURFACE)),
342 mCurrentDisplay(static_cast<egl::Display *>(EGL_NO_DISPLAY)),
Jamie Madille14951e2017-03-09 18:55:16 -0500343 mWebGLContext(GetWebGLContext(attribs)),
Geoff Lang0ab41fa2018-03-14 11:03:30 -0400344 mExtensionsEnabled(GetExtensionsEnabled(attribs, mWebGLContext)),
Jamie Madill32447362017-06-28 14:53:52 -0400345 mMemoryProgramCache(memoryProgramCache),
Jamie Madillb3f26b92017-07-19 15:07:41 -0400346 mScratchBuffer(1000u),
347 mZeroFilledBuffer(1000u)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000348{
Jamie Madill5b772312018-03-08 20:28:32 -0500349 // Needed to solve a Clang warning of unused variables.
Jamie Madillc6dbc252018-04-30 19:07:56 -0400350 ANGLE_UNUSED_VARIABLE(mSavedArgsType);
351 ANGLE_UNUSED_VARIABLE(mParamsBuffer);
Geoff Lang33f11fb2018-05-07 13:42:47 -0400352}
Jamie Madill5b772312018-03-08 20:28:32 -0500353
Geoff Lang33f11fb2018-05-07 13:42:47 -0400354void Context::initialize()
355{
356 mImplementation->setMemoryProgramCache(mMemoryProgramCache);
Jamie Madill14bbb3f2017-09-12 15:23:01 -0400357
Geoff Lang33f11fb2018-05-07 13:42:47 -0400358 initCaps();
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700359 initWorkarounds();
Geoff Langc0b9ef42014-07-02 10:02:37 -0400360
Geoff Lang4fb8a8b2018-06-01 16:47:57 -0400361 mGLState.initialize(this);
Régis Fénéon83107972015-02-05 12:57:44 +0100362
Shannon Woods53a94a82014-06-24 15:20:36 -0400363 mFenceNVHandleAllocator.setBaseHandle(0);
Geoff Lang7dca1862013-07-30 16:30:46 -0400364
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000365 // [OpenGL ES 2.0.24] section 3.7 page 83:
Corentin Wallez336129f2017-10-17 15:55:40 -0400366 // In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have two-dimensional
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000367 // and cube map texture state vectors respectively associated with them.
368 // In order that access to these initial textures not be lost, they are treated as texture
369 // objects all of whose names are 0.
370
Corentin Wallez99d492c2018-02-27 15:17:10 -0500371 Texture *zeroTexture2D = new Texture(mImplementation.get(), 0, TextureType::_2D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800372 mZeroTextures[TextureType::_2D].set(this, zeroTexture2D);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500373
Corentin Wallez99d492c2018-02-27 15:17:10 -0500374 Texture *zeroTextureCube = new Texture(mImplementation.get(), 0, TextureType::CubeMap);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800375 mZeroTextures[TextureType::CubeMap].set(this, zeroTextureCube);
Geoff Lang76b10c92014-09-05 16:28:14 -0400376
Geoff Langeb66a6e2016-10-31 13:06:12 -0400377 if (getClientVersion() >= Version(3, 0))
Geoff Lang76b10c92014-09-05 16:28:14 -0400378 {
379 // TODO: These could also be enabled via extension
Corentin Wallez99d492c2018-02-27 15:17:10 -0500380 Texture *zeroTexture3D = new Texture(mImplementation.get(), 0, TextureType::_3D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800381 mZeroTextures[TextureType::_3D].set(this, zeroTexture3D);
Geoff Lang76b10c92014-09-05 16:28:14 -0400382
Corentin Wallez99d492c2018-02-27 15:17:10 -0500383 Texture *zeroTexture2DArray = new Texture(mImplementation.get(), 0, TextureType::_2DArray);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800384 mZeroTextures[TextureType::_2DArray].set(this, zeroTexture2DArray);
Geoff Lang76b10c92014-09-05 16:28:14 -0400385 }
Geoff Lang3b573612016-10-31 14:08:10 -0400386 if (getClientVersion() >= Version(3, 1))
387 {
388 Texture *zeroTexture2DMultisample =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500389 new Texture(mImplementation.get(), 0, TextureType::_2DMultisample);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800390 mZeroTextures[TextureType::_2DMultisample].set(this, zeroTexture2DMultisample);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800391
Jiajia Qin6eafb042016-12-27 17:04:07 +0800392 for (unsigned int i = 0; i < mCaps.maxAtomicCounterBufferBindings; i++)
393 {
Qin Jiajia339f65b2018-02-27 12:52:48 +0800394 bindBufferRange(BufferBinding::AtomicCounter, i, 0, 0, 0);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800395 }
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800396
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800397 for (unsigned int i = 0; i < mCaps.maxShaderStorageBufferBindings; i++)
398 {
Corentin Wallez336129f2017-10-17 15:55:40 -0400399 bindBufferRange(BufferBinding::ShaderStorage, i, 0, 0, 0);
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800400 }
Geoff Lang3b573612016-10-31 14:08:10 -0400401 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000402
Geoff Langb0f917f2017-12-05 13:41:54 -0500403 if (mSupportedExtensions.textureRectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400404 {
405 Texture *zeroTextureRectangle =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500406 new Texture(mImplementation.get(), 0, TextureType::Rectangle);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800407 mZeroTextures[TextureType::Rectangle].set(this, zeroTextureRectangle);
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400408 }
409
Geoff Langb0f917f2017-12-05 13:41:54 -0500410 if (mSupportedExtensions.eglImageExternal || mSupportedExtensions.eglStreamConsumerExternal)
Ian Ewellbda75592016-04-18 17:25:54 -0400411 {
Corentin Wallez99d492c2018-02-27 15:17:10 -0500412 Texture *zeroTextureExternal = new Texture(mImplementation.get(), 0, TextureType::External);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800413 mZeroTextures[TextureType::External].set(this, zeroTextureExternal);
Ian Ewellbda75592016-04-18 17:25:54 -0400414 }
415
Jamie Madill4928b7c2017-06-20 12:57:39 -0400416 mGLState.initializeZeroTextures(this, mZeroTextures);
Jamie Madille6382c32014-11-07 15:05:26 -0500417
Jamie Madill57a89722013-07-02 11:57:03 -0400418 bindVertexArray(0);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000419
Geoff Langeb66a6e2016-10-31 13:06:12 -0400420 if (getClientVersion() >= Version(3, 0))
Geoff Lang1a683462015-09-29 15:09:59 -0400421 {
422 // [OpenGL ES 3.0.2] section 2.14.1 pg 85:
423 // In the initial state, a default transform feedback object is bound and treated as
424 // a transform feedback object with a name of zero. That object is bound any time
425 // BindTransformFeedback is called with id of zero
Jamie Madillf0dcb8b2017-08-26 19:05:13 -0400426 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Geoff Lang1a683462015-09-29 15:09:59 -0400427 }
Geoff Langc8058452014-02-03 12:04:11 -0500428
Corentin Wallez336129f2017-10-17 15:55:40 -0400429 for (auto type : angle::AllEnums<BufferBinding>())
430 {
431 bindBuffer(type, 0);
432 }
433
434 bindRenderbuffer(GL_RENDERBUFFER, 0);
435
436 for (unsigned int i = 0; i < mCaps.maxUniformBufferBindings; i++)
437 {
438 bindBufferRange(BufferBinding::Uniform, i, 0, 0, -1);
439 }
440
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700441 // Initialize GLES1 renderer if appropriate.
442 if (getClientVersion() < Version(2, 0))
443 {
444 mGLES1Renderer.reset(new GLES1Renderer());
445 }
446
Jamie Madillad9f24e2016-02-12 09:27:24 -0500447 // Initialize dirty bit masks
Jamie Madillc67323a2017-11-02 23:11:41 -0400448 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500449 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500450 // No dirty objects.
451
452 // Readpixels uses the pack state and read FBO
Jamie Madillc67323a2017-11-02 23:11:41 -0400453 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500454 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_BUFFER_BINDING);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400455 mReadPixelsDirtyBits.set(State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500456 mReadPixelsDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
457
458 mClearDirtyBits.set(State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED);
459 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
460 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR);
461 mClearDirtyBits.set(State::DIRTY_BIT_VIEWPORT);
462 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_COLOR);
463 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_DEPTH);
464 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_STENCIL);
465 mClearDirtyBits.set(State::DIRTY_BIT_COLOR_MASK);
466 mClearDirtyBits.set(State::DIRTY_BIT_DEPTH_MASK);
467 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT);
468 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_BACK);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400469 mClearDirtyBits.set(State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500470 mClearDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
471
472 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
473 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR);
Geoff Lang1d2c41d2016-10-19 16:14:46 -0700474 mBlitDirtyBits.set(State::DIRTY_BIT_FRAMEBUFFER_SRGB);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400475 mBlitDirtyBits.set(State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
476 mBlitDirtyBits.set(State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500477 mBlitDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
478 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
Jamie Madill437fa652016-05-03 15:13:24 -0400479
Xinghua Cao10a4d432017-11-28 14:46:26 +0800480 // TODO(xinghua.cao@intel.com): add other dirty bits and dirty objects.
481 mComputeDirtyBits.set(State::DIRTY_BIT_SHADER_STORAGE_BUFFER_BINDING);
482 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_BINDING);
483 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_EXECUTABLE);
484 mComputeDirtyBits.set(State::DIRTY_BIT_TEXTURE_BINDINGS);
485 mComputeDirtyBits.set(State::DIRTY_BIT_SAMPLER_BINDINGS);
Qin Jiajia62fcf622017-11-30 16:16:12 +0800486 mComputeDirtyBits.set(State::DIRTY_BIT_DISPATCH_INDIRECT_BUFFER_BINDING);
Jiajia Qin5ae6ee42018-03-06 17:39:42 +0800487 mComputeDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM_TEXTURES);
Xinghua Cao10a4d432017-11-28 14:46:26 +0800488
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400489 handleError(mImplementation->initialize());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000490}
491
Jamie Madill4928b7c2017-06-20 12:57:39 -0400492egl::Error Context::onDestroy(const egl::Display *display)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000493{
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700494 if (mGLES1Renderer)
495 {
496 mGLES1Renderer->onDestroy(this, &mGLState);
497 }
498
Jamie Madille7b3fe22018-04-05 09:42:46 -0400499 // Delete the Surface first to trigger a finish() in Vulkan.
Jamie Madille7b3fe22018-04-05 09:42:46 -0400500 ANGLE_TRY(releaseSurface(display));
501
Corentin Wallez80b24112015-08-25 16:41:57 -0400502 for (auto fence : mFenceNVMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000503 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400504 SafeDelete(fence.second);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000505 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400506 mFenceNVMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000507
Corentin Wallez80b24112015-08-25 16:41:57 -0400508 for (auto query : mQueryMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000509 {
Geoff Langf0aa8422015-09-29 15:08:34 -0400510 if (query.second != nullptr)
511 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400512 query.second->release(this);
Geoff Langf0aa8422015-09-29 15:08:34 -0400513 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000514 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400515 mQueryMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000516
Corentin Wallez80b24112015-08-25 16:41:57 -0400517 for (auto vertexArray : mVertexArrayMap)
Jamie Madill57a89722013-07-02 11:57:03 -0400518 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400519 if (vertexArray.second)
520 {
521 vertexArray.second->onDestroy(this);
522 }
Jamie Madill57a89722013-07-02 11:57:03 -0400523 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400524 mVertexArrayMap.clear();
Jamie Madill57a89722013-07-02 11:57:03 -0400525
Corentin Wallez80b24112015-08-25 16:41:57 -0400526 for (auto transformFeedback : mTransformFeedbackMap)
Geoff Langc8058452014-02-03 12:04:11 -0500527 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500528 if (transformFeedback.second != nullptr)
529 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500530 transformFeedback.second->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500531 }
Geoff Langc8058452014-02-03 12:04:11 -0500532 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400533 mTransformFeedbackMap.clear();
Geoff Langc8058452014-02-03 12:04:11 -0500534
Jamie Madill5b772312018-03-08 20:28:32 -0500535 for (BindingPointer<Texture> &zeroTexture : mZeroTextures)
Geoff Lang76b10c92014-09-05 16:28:14 -0400536 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800537 if (zeroTexture.get() != nullptr)
538 {
539 ANGLE_TRY(zeroTexture->onDestroy(this));
540 zeroTexture.set(this, nullptr);
541 }
Geoff Lang76b10c92014-09-05 16:28:14 -0400542 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000543
Jamie Madill2f348d22017-06-05 10:50:59 -0400544 releaseShaderCompiler();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500545
Jamie Madill4928b7c2017-06-20 12:57:39 -0400546 mGLState.reset(this);
547
Jamie Madill6c1f6712017-02-14 19:08:04 -0500548 mState.mBuffers->release(this);
549 mState.mShaderPrograms->release(this);
550 mState.mTextures->release(this);
551 mState.mRenderbuffers->release(this);
552 mState.mSamplers->release(this);
Jamie Madill70b5bb02017-08-28 13:32:37 -0400553 mState.mSyncs->release(this);
Jamie Madill6c1f6712017-02-14 19:08:04 -0500554 mState.mPaths->release(this);
555 mState.mFramebuffers->release(this);
Yunchao Hea336b902017-08-02 16:05:21 +0800556 mState.mPipelines->release(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400557
Jamie Madill76e471e2017-10-21 09:56:01 -0400558 mImplementation->onDestroy(this);
559
Jamie Madill4928b7c2017-06-20 12:57:39 -0400560 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000561}
562
Jamie Madill70ee0f62017-02-06 16:04:20 -0500563Context::~Context()
564{
565}
566
Geoff Lang75359662018-04-11 01:42:27 -0400567void Context::setLabel(EGLLabelKHR label)
568{
569 mLabel = label;
570}
571
572EGLLabelKHR Context::getLabel() const
573{
574 return mLabel;
575}
576
Jamie Madill4928b7c2017-06-20 12:57:39 -0400577egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000578{
Jamie Madill61e16b42017-06-19 11:13:23 -0400579 mCurrentDisplay = display;
580
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000581 if (!mHasBeenCurrent)
582 {
Geoff Lang33f11fb2018-05-07 13:42:47 -0400583 initialize();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000584 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500585 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400586 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000587
Corentin Wallezc295e512017-01-27 17:47:50 -0500588 int width = 0;
589 int height = 0;
590 if (surface != nullptr)
591 {
592 width = surface->getWidth();
593 height = surface->getHeight();
594 }
595
596 mGLState.setViewportParams(0, 0, width, height);
597 mGLState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000598
599 mHasBeenCurrent = true;
600 }
601
Jamie Madill1b94d432015-08-07 13:23:23 -0400602 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700603 mGLState.setAllDirtyBits();
Jamie Madill81c2e252017-09-09 23:32:46 -0400604 mGLState.setAllDirtyObjects();
Jamie Madill1b94d432015-08-07 13:23:23 -0400605
Jamie Madill4928b7c2017-06-20 12:57:39 -0400606 ANGLE_TRY(releaseSurface(display));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500607
608 Framebuffer *newDefault = nullptr;
609 if (surface != nullptr)
610 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400611 ANGLE_TRY(surface->setIsCurrent(this, true));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500612 mCurrentSurface = surface;
Geoff Langbf7b95d2018-05-01 16:48:21 -0400613 newDefault = surface->createDefaultFramebuffer(this);
Corentin Wallezccab69d2017-01-27 16:57:15 -0500614 }
615 else
616 {
Geoff Langbf7b95d2018-05-01 16:48:21 -0400617 newDefault = new Framebuffer(mImplementation.get());
Corentin Wallezccab69d2017-01-27 16:57:15 -0500618 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000619
Corentin Wallez37c39792015-08-20 14:19:46 -0400620 // Update default framebuffer, the binding of the previous default
621 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400622 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700623 if (mGLState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400624 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700625 mGLState.setReadFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400626 }
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700627 if (mGLState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400628 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700629 mGLState.setDrawFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400630 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500631 mState.mFramebuffers->setDefaultFramebuffer(newDefault);
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400632 }
Ian Ewell292f0052016-02-04 10:37:32 -0500633
634 // Notify the renderer of a context switch
Luc Ferron5396f2a2018-07-12 08:24:23 -0400635 ANGLE_TRY(mImplementation->onMakeCurrent(this));
Jamie Madill4928b7c2017-06-20 12:57:39 -0400636 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000637}
638
Jamie Madill4928b7c2017-06-20 12:57:39 -0400639egl::Error Context::releaseSurface(const egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400640{
Geoff Langbf7b95d2018-05-01 16:48:21 -0400641 gl::Framebuffer *defaultFramebuffer = mState.mFramebuffers->getFramebuffer(0);
Corentin Wallez51706ea2015-08-07 14:39:22 -0400642
Geoff Langbf7b95d2018-05-01 16:48:21 -0400643 // Remove the default framebuffer
644 if (mGLState.getReadFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500645 {
646 mGLState.setReadFramebufferBinding(nullptr);
647 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400648
649 if (mGLState.getDrawFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500650 {
651 mGLState.setDrawFramebufferBinding(nullptr);
652 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400653
654 if (defaultFramebuffer)
655 {
656 defaultFramebuffer->onDestroy(this);
657 delete defaultFramebuffer;
658 }
659
Corentin Wallezc295e512017-01-27 17:47:50 -0500660 mState.mFramebuffers->setDefaultFramebuffer(nullptr);
661
662 if (mCurrentSurface)
663 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400664 ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
Corentin Wallezc295e512017-01-27 17:47:50 -0500665 mCurrentSurface = nullptr;
666 }
Jamie Madill4928b7c2017-06-20 12:57:39 -0400667
668 return egl::NoError();
Jamie Madill77a72f62015-04-14 11:18:32 -0400669}
670
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000671GLuint Context::createBuffer()
672{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500673 return mState.mBuffers->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000674}
675
676GLuint Context::createProgram()
677{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500678 return mState.mShaderPrograms->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000679}
680
Jiawei Shao385b3e02018-03-21 09:43:28 +0800681GLuint Context::createShader(ShaderType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000682{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500683 return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000684}
685
686GLuint Context::createTexture()
687{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500688 return mState.mTextures->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000689}
690
691GLuint Context::createRenderbuffer()
692{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500693 return mState.mRenderbuffers->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000694}
695
Brandon Jones59770802018-04-02 13:18:42 -0700696GLuint Context::genPaths(GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300697{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500698 auto resultOrError = mState.mPaths->createPaths(mImplementation.get(), range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300699 if (resultOrError.isError())
700 {
701 handleError(resultOrError.getError());
702 return 0;
703 }
704 return resultOrError.getResult();
705}
706
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000707// Returns an unused framebuffer name
708GLuint Context::createFramebuffer()
709{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500710 return mState.mFramebuffers->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000711}
712
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500713void Context::genFencesNV(GLsizei n, GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000714{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500715 for (int i = 0; i < n; i++)
716 {
717 GLuint handle = mFenceNVHandleAllocator.allocate();
718 mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV()));
719 fences[i] = handle;
720 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000721}
722
Yunchao Hea336b902017-08-02 16:05:21 +0800723GLuint Context::createProgramPipeline()
724{
725 return mState.mPipelines->createProgramPipeline();
726}
727
Jiawei Shao385b3e02018-03-21 09:43:28 +0800728GLuint Context::createShaderProgramv(ShaderType type, GLsizei count, const GLchar *const *strings)
Jiajia Qin5451d532017-11-16 17:16:34 +0800729{
730 UNIMPLEMENTED();
731 return 0u;
732}
733
James Darpinian4d9d4832018-03-13 12:43:28 -0700734void Context::deleteBuffer(GLuint bufferName)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000735{
James Darpinian4d9d4832018-03-13 12:43:28 -0700736 Buffer *buffer = mState.mBuffers->getBuffer(bufferName);
737 if (buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000738 {
739 detachBuffer(buffer);
740 }
Jamie Madill893ab082014-05-16 16:56:10 -0400741
James Darpinian4d9d4832018-03-13 12:43:28 -0700742 mState.mBuffers->deleteObject(this, bufferName);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000743}
744
745void Context::deleteShader(GLuint shader)
746{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500747 mState.mShaderPrograms->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000748}
749
750void Context::deleteProgram(GLuint program)
751{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500752 mState.mShaderPrograms->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000753}
754
755void Context::deleteTexture(GLuint texture)
756{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500757 if (mState.mTextures->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000758 {
759 detachTexture(texture);
760 }
761
Jamie Madill6c1f6712017-02-14 19:08:04 -0500762 mState.mTextures->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000763}
764
765void Context::deleteRenderbuffer(GLuint renderbuffer)
766{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500767 if (mState.mRenderbuffers->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000768 {
769 detachRenderbuffer(renderbuffer);
770 }
Jamie Madill893ab082014-05-16 16:56:10 -0400771
Jamie Madill6c1f6712017-02-14 19:08:04 -0500772 mState.mRenderbuffers->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000773}
774
Jamie Madill7f0c5a42017-08-26 22:43:26 -0400775void Context::deleteSync(GLsync sync)
Jamie Madillcd055f82013-07-26 11:55:15 -0400776{
777 // The spec specifies the underlying Fence object is not deleted until all current
778 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
779 // and since our API is currently designed for being called from a single thread, we can delete
780 // the fence immediately.
Jamie Madill70b5bb02017-08-28 13:32:37 -0400781 mState.mSyncs->deleteObject(this, static_cast<GLuint>(reinterpret_cast<uintptr_t>(sync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400782}
783
Yunchao Hea336b902017-08-02 16:05:21 +0800784void Context::deleteProgramPipeline(GLuint pipeline)
785{
786 if (mState.mPipelines->getProgramPipeline(pipeline))
787 {
788 detachProgramPipeline(pipeline);
789 }
790
791 mState.mPipelines->deleteObject(this, pipeline);
792}
793
Sami Väisänene45e53b2016-05-25 10:36:04 +0300794void Context::deletePaths(GLuint first, GLsizei range)
795{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500796 mState.mPaths->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300797}
798
Brandon Jones59770802018-04-02 13:18:42 -0700799bool Context::isPath(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300800{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500801 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300802 if (pathObj == nullptr)
803 return false;
804
805 return pathObj->hasPathData();
806}
807
Brandon Jones59770802018-04-02 13:18:42 -0700808bool Context::isPathGenerated(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300809{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500810 return mState.mPaths->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300811}
812
Brandon Jones59770802018-04-02 13:18:42 -0700813void Context::pathCommands(GLuint path,
814 GLsizei numCommands,
815 const GLubyte *commands,
816 GLsizei numCoords,
817 GLenum coordType,
818 const void *coords)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300819{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500820 auto *pathObject = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300821
822 handleError(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
823}
824
Jamie Madill007530e2017-12-28 14:27:04 -0500825void Context::pathParameterf(GLuint path, GLenum pname, GLfloat value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300826{
Jamie Madill007530e2017-12-28 14:27:04 -0500827 Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300828
829 switch (pname)
830 {
831 case GL_PATH_STROKE_WIDTH_CHROMIUM:
832 pathObj->setStrokeWidth(value);
833 break;
834 case GL_PATH_END_CAPS_CHROMIUM:
835 pathObj->setEndCaps(static_cast<GLenum>(value));
836 break;
837 case GL_PATH_JOIN_STYLE_CHROMIUM:
838 pathObj->setJoinStyle(static_cast<GLenum>(value));
839 break;
840 case GL_PATH_MITER_LIMIT_CHROMIUM:
841 pathObj->setMiterLimit(value);
842 break;
843 case GL_PATH_STROKE_BOUND_CHROMIUM:
844 pathObj->setStrokeBound(value);
845 break;
846 default:
847 UNREACHABLE();
848 break;
849 }
850}
851
Jamie Madill007530e2017-12-28 14:27:04 -0500852void Context::pathParameteri(GLuint path, GLenum pname, GLint value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300853{
Jamie Madill007530e2017-12-28 14:27:04 -0500854 // TODO(jmadill): Should use proper clamping/casting.
855 pathParameterf(path, pname, static_cast<GLfloat>(value));
856}
857
858void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value)
859{
860 const Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300861
862 switch (pname)
863 {
864 case GL_PATH_STROKE_WIDTH_CHROMIUM:
865 *value = pathObj->getStrokeWidth();
866 break;
867 case GL_PATH_END_CAPS_CHROMIUM:
868 *value = static_cast<GLfloat>(pathObj->getEndCaps());
869 break;
870 case GL_PATH_JOIN_STYLE_CHROMIUM:
871 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
872 break;
873 case GL_PATH_MITER_LIMIT_CHROMIUM:
874 *value = pathObj->getMiterLimit();
875 break;
876 case GL_PATH_STROKE_BOUND_CHROMIUM:
877 *value = pathObj->getStrokeBound();
878 break;
879 default:
880 UNREACHABLE();
881 break;
882 }
883}
884
Jamie Madill007530e2017-12-28 14:27:04 -0500885void Context::getPathParameteriv(GLuint path, GLenum pname, GLint *value)
886{
887 GLfloat val = 0.0f;
888 getPathParameterfv(path, pname, value != nullptr ? &val : nullptr);
889 if (value)
890 *value = static_cast<GLint>(val);
891}
892
Brandon Jones59770802018-04-02 13:18:42 -0700893void Context::pathStencilFunc(GLenum func, GLint ref, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300894{
895 mGLState.setPathStencilFunc(func, ref, mask);
896}
897
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000898void Context::deleteFramebuffer(GLuint framebuffer)
899{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500900 if (mState.mFramebuffers->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000901 {
902 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000903 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500904
Jamie Madill6c1f6712017-02-14 19:08:04 -0500905 mState.mFramebuffers->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000906}
907
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500908void Context::deleteFencesNV(GLsizei n, const GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000909{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500910 for (int i = 0; i < n; i++)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000911 {
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500912 GLuint fence = fences[i];
913
914 FenceNV *fenceObject = nullptr;
915 if (mFenceNVMap.erase(fence, &fenceObject))
916 {
917 mFenceNVHandleAllocator.release(fence);
918 delete fenceObject;
919 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000920 }
921}
922
Geoff Lang70d0f492015-12-10 17:45:46 -0500923Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000924{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500925 return mState.mBuffers->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000926}
927
Jamie Madill570f7c82014-07-03 10:38:54 -0400928Texture *Context::getTexture(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000929{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500930 return mState.mTextures->getTexture(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000931}
932
Geoff Lang70d0f492015-12-10 17:45:46 -0500933Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000934{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500935 return mState.mRenderbuffers->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000936}
937
Jamie Madill70b5bb02017-08-28 13:32:37 -0400938Sync *Context::getSync(GLsync handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400939{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400940 return mState.mSyncs->getSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400941}
942
Jamie Madill57a89722013-07-02 11:57:03 -0400943VertexArray *Context::getVertexArray(GLuint handle) const
944{
Jamie Madill96a483b2017-06-27 16:49:21 -0400945 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -0400946}
947
Jamie Madilldc356042013-07-19 16:36:57 -0400948Sampler *Context::getSampler(GLuint handle) const
949{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500950 return mState.mSamplers->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400951}
952
Geoff Langc8058452014-02-03 12:04:11 -0500953TransformFeedback *Context::getTransformFeedback(GLuint handle) const
954{
Jamie Madill96a483b2017-06-27 16:49:21 -0400955 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -0500956}
957
Yunchao Hea336b902017-08-02 16:05:21 +0800958ProgramPipeline *Context::getProgramPipeline(GLuint handle) const
959{
960 return mState.mPipelines->getProgramPipeline(handle);
961}
962
Geoff Lang75359662018-04-11 01:42:27 -0400963gl::LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
Geoff Lang70d0f492015-12-10 17:45:46 -0500964{
965 switch (identifier)
966 {
967 case GL_BUFFER:
968 return getBuffer(name);
969 case GL_SHADER:
970 return getShader(name);
971 case GL_PROGRAM:
972 return getProgram(name);
973 case GL_VERTEX_ARRAY:
974 return getVertexArray(name);
975 case GL_QUERY:
976 return getQuery(name);
977 case GL_TRANSFORM_FEEDBACK:
978 return getTransformFeedback(name);
979 case GL_SAMPLER:
980 return getSampler(name);
981 case GL_TEXTURE:
982 return getTexture(name);
983 case GL_RENDERBUFFER:
984 return getRenderbuffer(name);
985 case GL_FRAMEBUFFER:
986 return getFramebuffer(name);
987 default:
988 UNREACHABLE();
989 return nullptr;
990 }
991}
992
Geoff Lang75359662018-04-11 01:42:27 -0400993gl::LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
Geoff Lang70d0f492015-12-10 17:45:46 -0500994{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400995 return getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
Geoff Lang70d0f492015-12-10 17:45:46 -0500996}
997
Martin Radev9d901792016-07-15 15:58:58 +0300998void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
999{
Geoff Lang75359662018-04-11 01:42:27 -04001000 gl::LabeledObject *object = getLabeledObject(identifier, name);
Martin Radev9d901792016-07-15 15:58:58 +03001001 ASSERT(object != nullptr);
1002
1003 std::string labelName = GetObjectLabelFromPointer(length, label);
1004 object->setLabel(labelName);
Jamie Madill8693bdb2017-09-02 15:32:14 -04001005
1006 // TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the
1007 // specified object is active until we do this.
1008 mGLState.setObjectDirty(identifier);
Martin Radev9d901792016-07-15 15:58:58 +03001009}
1010
1011void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
1012{
Geoff Lang75359662018-04-11 01:42:27 -04001013 gl::LabeledObject *object = getLabeledObjectFromPtr(ptr);
Martin Radev9d901792016-07-15 15:58:58 +03001014 ASSERT(object != nullptr);
1015
1016 std::string labelName = GetObjectLabelFromPointer(length, label);
1017 object->setLabel(labelName);
1018}
1019
1020void Context::getObjectLabel(GLenum identifier,
1021 GLuint name,
1022 GLsizei bufSize,
1023 GLsizei *length,
1024 GLchar *label) const
1025{
Geoff Lang75359662018-04-11 01:42:27 -04001026 gl::LabeledObject *object = getLabeledObject(identifier, name);
Martin Radev9d901792016-07-15 15:58:58 +03001027 ASSERT(object != nullptr);
1028
1029 const std::string &objectLabel = object->getLabel();
1030 GetObjectLabelBase(objectLabel, bufSize, length, label);
1031}
1032
1033void Context::getObjectPtrLabel(const void *ptr,
1034 GLsizei bufSize,
1035 GLsizei *length,
1036 GLchar *label) const
1037{
Geoff Lang75359662018-04-11 01:42:27 -04001038 gl::LabeledObject *object = getLabeledObjectFromPtr(ptr);
Martin Radev9d901792016-07-15 15:58:58 +03001039 ASSERT(object != nullptr);
1040
1041 const std::string &objectLabel = object->getLabel();
1042 GetObjectLabelBase(objectLabel, bufSize, length, label);
1043}
1044
Jamie Madilldc356042013-07-19 16:36:57 -04001045bool Context::isSampler(GLuint samplerName) const
1046{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001047 return mState.mSamplers->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -04001048}
1049
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001050void Context::bindTexture(TextureType target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001051{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001052 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001053
Jamie Madilldedd7b92014-11-05 16:30:36 -05001054 if (handle == 0)
1055 {
1056 texture = mZeroTextures[target].get();
1057 }
1058 else
1059 {
Corentin Wallez99d492c2018-02-27 15:17:10 -05001060 texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -05001061 }
1062
1063 ASSERT(texture);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001064 mGLState.setSamplerTexture(this, target, texture);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00001065}
1066
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001067void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001068{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001069 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1070 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001071 mGLState.setReadFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001072}
1073
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001074void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001075{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001076 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1077 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001078 mGLState.setDrawFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001079}
1080
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001081void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -04001082{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001083 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madill7267aa62018-04-17 15:28:21 -04001084 mGLState.setVertexArrayBinding(this, vertexArray);
Jamie Madill57a89722013-07-02 11:57:03 -04001085}
1086
Shao80957d92017-02-20 21:25:59 +08001087void Context::bindVertexBuffer(GLuint bindingIndex,
1088 GLuint bufferHandle,
1089 GLintptr offset,
1090 GLsizei stride)
1091{
1092 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001093 mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Shao80957d92017-02-20 21:25:59 +08001094}
1095
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001096void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -04001097{
Geoff Lang76b10c92014-09-05 16:28:14 -04001098 ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -04001099 Sampler *sampler =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001100 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001101 mGLState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04001102}
1103
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001104void Context::bindImageTexture(GLuint unit,
1105 GLuint texture,
1106 GLint level,
1107 GLboolean layered,
1108 GLint layer,
1109 GLenum access,
1110 GLenum format)
1111{
1112 Texture *tex = mState.mTextures->getTexture(texture);
1113 mGLState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
1114}
1115
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001116void Context::useProgram(GLuint program)
1117{
Jamie Madill6c1f6712017-02-14 19:08:04 -05001118 mGLState.setProgram(this, getProgram(program));
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001119}
1120
Jiajia Qin5451d532017-11-16 17:16:34 +08001121void Context::useProgramStages(GLuint pipeline, GLbitfield stages, GLuint program)
1122{
1123 UNIMPLEMENTED();
1124}
1125
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001126void Context::bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001127{
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001128 ASSERT(target == GL_TRANSFORM_FEEDBACK);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001129 TransformFeedback *transformFeedback =
1130 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001131 mGLState.setTransformFeedbackBinding(this, transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -05001132}
1133
Yunchao Hea336b902017-08-02 16:05:21 +08001134void Context::bindProgramPipeline(GLuint pipelineHandle)
1135{
1136 ProgramPipeline *pipeline =
1137 mState.mPipelines->checkProgramPipelineAllocation(mImplementation.get(), pipelineHandle);
1138 mGLState.setProgramPipelineBinding(this, pipeline);
1139}
1140
Corentin Wallezad3ae902018-03-09 13:40:42 -05001141void Context::beginQuery(QueryType target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001142{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001143 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001144 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001145
Geoff Lang5aad9672014-09-08 11:10:42 -04001146 // begin query
Jamie Madillf0e04492017-08-26 15:28:42 -04001147 ANGLE_CONTEXT_TRY(queryObject->begin());
Geoff Lang5aad9672014-09-08 11:10:42 -04001148
1149 // set query as active for specified target only if begin succeeded
Jamie Madill4928b7c2017-06-20 12:57:39 -04001150 mGLState.setActiveQuery(this, target, queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001151}
1152
Corentin Wallezad3ae902018-03-09 13:40:42 -05001153void Context::endQuery(QueryType target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001154{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001155 Query *queryObject = mGLState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001156 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001157
Jamie Madillf0e04492017-08-26 15:28:42 -04001158 handleError(queryObject->end());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001159
Geoff Lang5aad9672014-09-08 11:10:42 -04001160 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madill4928b7c2017-06-20 12:57:39 -04001161 mGLState.setActiveQuery(this, target, nullptr);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001162}
1163
Corentin Wallezad3ae902018-03-09 13:40:42 -05001164void Context::queryCounter(GLuint id, QueryType target)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001165{
Corentin Wallezad3ae902018-03-09 13:40:42 -05001166 ASSERT(target == QueryType::Timestamp);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001167
1168 Query *queryObject = getQuery(id, true, target);
1169 ASSERT(queryObject);
1170
Jamie Madillf0e04492017-08-26 15:28:42 -04001171 handleError(queryObject->queryCounter());
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001172}
1173
Corentin Wallezad3ae902018-03-09 13:40:42 -05001174void Context::getQueryiv(QueryType target, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001175{
1176 switch (pname)
1177 {
1178 case GL_CURRENT_QUERY_EXT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001179 params[0] = mGLState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001180 break;
1181 case GL_QUERY_COUNTER_BITS_EXT:
1182 switch (target)
1183 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001184 case QueryType::TimeElapsed:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001185 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1186 break;
Corentin Wallezad3ae902018-03-09 13:40:42 -05001187 case QueryType::Timestamp:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001188 params[0] = getExtensions().queryCounterBitsTimestamp;
1189 break;
1190 default:
1191 UNREACHABLE();
1192 params[0] = 0;
1193 break;
1194 }
1195 break;
1196 default:
1197 UNREACHABLE();
1198 return;
1199 }
1200}
1201
Corentin Wallezad3ae902018-03-09 13:40:42 -05001202void Context::getQueryivRobust(QueryType target,
Brandon Jones59770802018-04-02 13:18:42 -07001203 GLenum pname,
1204 GLsizei bufSize,
1205 GLsizei *length,
1206 GLint *params)
1207{
1208 getQueryiv(target, pname, params);
1209}
1210
Geoff Lang2186c382016-10-14 10:54:54 -04001211void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001212{
Geoff Lang2186c382016-10-14 10:54:54 -04001213 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001214}
1215
Brandon Jones59770802018-04-02 13:18:42 -07001216void Context::getQueryObjectivRobust(GLuint id,
1217 GLenum pname,
1218 GLsizei bufSize,
1219 GLsizei *length,
1220 GLint *params)
1221{
1222 getQueryObjectiv(id, pname, params);
1223}
1224
Geoff Lang2186c382016-10-14 10:54:54 -04001225void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001226{
Geoff Lang2186c382016-10-14 10:54:54 -04001227 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001228}
1229
Brandon Jones59770802018-04-02 13:18:42 -07001230void Context::getQueryObjectuivRobust(GLuint id,
1231 GLenum pname,
1232 GLsizei bufSize,
1233 GLsizei *length,
1234 GLuint *params)
1235{
1236 getQueryObjectuiv(id, pname, params);
1237}
1238
Geoff Lang2186c382016-10-14 10:54:54 -04001239void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001240{
Geoff Lang2186c382016-10-14 10:54:54 -04001241 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001242}
1243
Brandon Jones59770802018-04-02 13:18:42 -07001244void Context::getQueryObjecti64vRobust(GLuint id,
1245 GLenum pname,
1246 GLsizei bufSize,
1247 GLsizei *length,
1248 GLint64 *params)
1249{
1250 getQueryObjecti64v(id, pname, params);
1251}
1252
Geoff Lang2186c382016-10-14 10:54:54 -04001253void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001254{
Geoff Lang2186c382016-10-14 10:54:54 -04001255 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001256}
1257
Brandon Jones59770802018-04-02 13:18:42 -07001258void Context::getQueryObjectui64vRobust(GLuint id,
1259 GLenum pname,
1260 GLsizei bufSize,
1261 GLsizei *length,
1262 GLuint64 *params)
1263{
1264 getQueryObjectui64v(id, pname, params);
1265}
1266
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001267Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001268{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001269 return mState.mFramebuffers->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001270}
1271
Jamie Madill2f348d22017-06-05 10:50:59 -04001272FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001273{
Jamie Madill96a483b2017-06-27 16:49:21 -04001274 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001275}
1276
Corentin Wallezad3ae902018-03-09 13:40:42 -05001277Query *Context::getQuery(GLuint handle, bool create, QueryType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001278{
Jamie Madill96a483b2017-06-27 16:49:21 -04001279 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001280 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001281 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001282 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001283
1284 Query *query = mQueryMap.query(handle);
1285 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001286 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001287 ASSERT(type != QueryType::InvalidEnum);
Jamie Madill96a483b2017-06-27 16:49:21 -04001288 query = new Query(mImplementation->createQuery(type), handle);
1289 query->addRef();
1290 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001291 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001292 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001293}
1294
Geoff Lang70d0f492015-12-10 17:45:46 -05001295Query *Context::getQuery(GLuint handle) const
1296{
Jamie Madill96a483b2017-06-27 16:49:21 -04001297 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001298}
1299
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001300Texture *Context::getTargetTexture(TextureType type) const
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001301{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001302 ASSERT(ValidTextureTarget(this, type) || ValidTextureExternalTarget(this, type));
1303 return mGLState.getTargetTexture(type);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001304}
1305
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001306Texture *Context::getSamplerTexture(unsigned int sampler, TextureType type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001307{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001308 return mGLState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001309}
1310
Geoff Lang492a7e42014-11-05 13:27:06 -05001311Compiler *Context::getCompiler() const
1312{
Jamie Madill2f348d22017-06-05 10:50:59 -04001313 if (mCompiler.get() == nullptr)
1314 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001315 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001316 }
1317 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001318}
1319
Jamie Madillc1d770e2017-04-13 17:31:24 -04001320void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001321{
1322 switch (pname)
1323 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001324 case GL_SHADER_COMPILER:
1325 *params = GL_TRUE;
1326 break;
1327 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1328 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1329 break;
1330 default:
1331 mGLState.getBooleanv(pname, params);
1332 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001333 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001334}
1335
Jamie Madillc1d770e2017-04-13 17:31:24 -04001336void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001337{
Shannon Woods53a94a82014-06-24 15:20:36 -04001338 // Queries about context capabilities and maximums are answered by Context.
1339 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001340 switch (pname)
1341 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001342 case GL_ALIASED_LINE_WIDTH_RANGE:
1343 params[0] = mCaps.minAliasedLineWidth;
1344 params[1] = mCaps.maxAliasedLineWidth;
1345 break;
1346 case GL_ALIASED_POINT_SIZE_RANGE:
1347 params[0] = mCaps.minAliasedPointSize;
1348 params[1] = mCaps.maxAliasedPointSize;
1349 break;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07001350 case GL_SMOOTH_POINT_SIZE_RANGE:
1351 params[0] = mCaps.minSmoothPointSize;
1352 params[1] = mCaps.maxSmoothPointSize;
1353 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001354 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1355 ASSERT(mExtensions.textureFilterAnisotropic);
1356 *params = mExtensions.maxTextureAnisotropy;
1357 break;
1358 case GL_MAX_TEXTURE_LOD_BIAS:
1359 *params = mCaps.maxLODBias;
1360 break;
1361
1362 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1363 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1364 {
Lingfeng Yang3a41af62018-04-09 07:28:56 -07001365 // GLES1 emulation: // GL_PATH_(MODELVIEW|PROJECTION)_MATRIX_CHROMIUM collides with the
1366 // GLES1 constants for modelview/projection matrix.
1367 if (getClientVersion() < Version(2, 0))
1368 {
1369 mGLState.getFloatv(pname, params);
1370 }
1371 else
1372 {
1373 ASSERT(mExtensions.pathRendering);
1374 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1375 memcpy(params, m, 16 * sizeof(GLfloat));
1376 }
Jamie Madill231c7f52017-04-26 13:45:37 -04001377 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001378 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001379
Jamie Madill231c7f52017-04-26 13:45:37 -04001380 default:
1381 mGLState.getFloatv(pname, params);
1382 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001383 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001384}
1385
Jamie Madillc1d770e2017-04-13 17:31:24 -04001386void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001387{
Shannon Woods53a94a82014-06-24 15:20:36 -04001388 // Queries about context capabilities and maximums are answered by Context.
1389 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001390
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001391 switch (pname)
1392 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001393 case GL_MAX_VERTEX_ATTRIBS:
1394 *params = mCaps.maxVertexAttributes;
1395 break;
1396 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1397 *params = mCaps.maxVertexUniformVectors;
1398 break;
1399 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001400 *params = mCaps.maxShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001401 break;
1402 case GL_MAX_VARYING_VECTORS:
1403 *params = mCaps.maxVaryingVectors;
1404 break;
1405 case GL_MAX_VARYING_COMPONENTS:
1406 *params = mCaps.maxVertexOutputComponents;
1407 break;
1408 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1409 *params = mCaps.maxCombinedTextureImageUnits;
1410 break;
1411 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001412 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001413 break;
1414 case GL_MAX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001415 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001416 break;
1417 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1418 *params = mCaps.maxFragmentUniformVectors;
1419 break;
1420 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001421 *params = mCaps.maxShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001422 break;
1423 case GL_MAX_RENDERBUFFER_SIZE:
1424 *params = mCaps.maxRenderbufferSize;
1425 break;
1426 case GL_MAX_COLOR_ATTACHMENTS_EXT:
1427 *params = mCaps.maxColorAttachments;
1428 break;
1429 case GL_MAX_DRAW_BUFFERS_EXT:
1430 *params = mCaps.maxDrawBuffers;
1431 break;
1432 // case GL_FRAMEBUFFER_BINDING: // now equivalent to
1433 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
1434 case GL_SUBPIXEL_BITS:
1435 *params = 4;
1436 break;
1437 case GL_MAX_TEXTURE_SIZE:
1438 *params = mCaps.max2DTextureSize;
1439 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001440 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
1441 *params = mCaps.maxRectangleTextureSize;
1442 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001443 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1444 *params = mCaps.maxCubeMapTextureSize;
1445 break;
1446 case GL_MAX_3D_TEXTURE_SIZE:
1447 *params = mCaps.max3DTextureSize;
1448 break;
1449 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1450 *params = mCaps.maxArrayTextureLayers;
1451 break;
1452 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1453 *params = mCaps.uniformBufferOffsetAlignment;
1454 break;
1455 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1456 *params = mCaps.maxUniformBufferBindings;
1457 break;
1458 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001459 *params = mCaps.maxShaderUniformBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001460 break;
1461 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001462 *params = mCaps.maxShaderUniformBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001463 break;
1464 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1465 *params = mCaps.maxCombinedTextureImageUnits;
1466 break;
1467 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1468 *params = mCaps.maxVertexOutputComponents;
1469 break;
1470 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1471 *params = mCaps.maxFragmentInputComponents;
1472 break;
1473 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1474 *params = mCaps.minProgramTexelOffset;
1475 break;
1476 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1477 *params = mCaps.maxProgramTexelOffset;
1478 break;
1479 case GL_MAJOR_VERSION:
1480 *params = getClientVersion().major;
1481 break;
1482 case GL_MINOR_VERSION:
1483 *params = getClientVersion().minor;
1484 break;
1485 case GL_MAX_ELEMENTS_INDICES:
1486 *params = mCaps.maxElementsIndices;
1487 break;
1488 case GL_MAX_ELEMENTS_VERTICES:
1489 *params = mCaps.maxElementsVertices;
1490 break;
1491 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1492 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1493 break;
1494 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1495 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1496 break;
1497 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1498 *params = mCaps.maxTransformFeedbackSeparateComponents;
1499 break;
1500 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1501 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1502 break;
1503 case GL_MAX_SAMPLES_ANGLE:
1504 *params = mCaps.maxSamples;
1505 break;
1506 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001507 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001508 params[0] = mCaps.maxViewportWidth;
1509 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001510 }
1511 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001512 case GL_COMPRESSED_TEXTURE_FORMATS:
1513 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1514 params);
1515 break;
1516 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1517 *params = mResetStrategy;
1518 break;
1519 case GL_NUM_SHADER_BINARY_FORMATS:
1520 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1521 break;
1522 case GL_SHADER_BINARY_FORMATS:
1523 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1524 break;
1525 case GL_NUM_PROGRAM_BINARY_FORMATS:
1526 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1527 break;
1528 case GL_PROGRAM_BINARY_FORMATS:
1529 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1530 break;
1531 case GL_NUM_EXTENSIONS:
1532 *params = static_cast<GLint>(mExtensionStrings.size());
1533 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001534
Jamie Madill231c7f52017-04-26 13:45:37 -04001535 // GL_KHR_debug
1536 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1537 *params = mExtensions.maxDebugMessageLength;
1538 break;
1539 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1540 *params = mExtensions.maxDebugLoggedMessages;
1541 break;
1542 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1543 *params = mExtensions.maxDebugGroupStackDepth;
1544 break;
1545 case GL_MAX_LABEL_LENGTH:
1546 *params = mExtensions.maxLabelLength;
1547 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001548
Martin Radeve5285d22017-07-14 16:23:53 +03001549 // GL_ANGLE_multiview
1550 case GL_MAX_VIEWS_ANGLE:
1551 *params = mExtensions.maxViews;
1552 break;
1553
Jamie Madill231c7f52017-04-26 13:45:37 -04001554 // GL_EXT_disjoint_timer_query
1555 case GL_GPU_DISJOINT_EXT:
1556 *params = mImplementation->getGPUDisjoint();
1557 break;
1558 case GL_MAX_FRAMEBUFFER_WIDTH:
1559 *params = mCaps.maxFramebufferWidth;
1560 break;
1561 case GL_MAX_FRAMEBUFFER_HEIGHT:
1562 *params = mCaps.maxFramebufferHeight;
1563 break;
1564 case GL_MAX_FRAMEBUFFER_SAMPLES:
1565 *params = mCaps.maxFramebufferSamples;
1566 break;
1567 case GL_MAX_SAMPLE_MASK_WORDS:
1568 *params = mCaps.maxSampleMaskWords;
1569 break;
1570 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1571 *params = mCaps.maxColorTextureSamples;
1572 break;
1573 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1574 *params = mCaps.maxDepthTextureSamples;
1575 break;
1576 case GL_MAX_INTEGER_SAMPLES:
1577 *params = mCaps.maxIntegerSamples;
1578 break;
1579 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1580 *params = mCaps.maxVertexAttribRelativeOffset;
1581 break;
1582 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1583 *params = mCaps.maxVertexAttribBindings;
1584 break;
1585 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1586 *params = mCaps.maxVertexAttribStride;
1587 break;
1588 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001589 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001590 break;
1591 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001592 *params = mCaps.maxShaderAtomicCounters[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001593 break;
1594 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001595 *params = mCaps.maxShaderImageUniforms[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001596 break;
1597 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001598 *params = mCaps.maxShaderStorageBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001599 break;
1600 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001601 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001602 break;
1603 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001604 *params = mCaps.maxShaderAtomicCounters[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001605 break;
1606 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001607 *params = mCaps.maxShaderImageUniforms[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001608 break;
1609 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001610 *params = mCaps.maxShaderStorageBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001611 break;
1612 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1613 *params = mCaps.minProgramTextureGatherOffset;
1614 break;
1615 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1616 *params = mCaps.maxProgramTextureGatherOffset;
1617 break;
1618 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1619 *params = mCaps.maxComputeWorkGroupInvocations;
1620 break;
1621 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001622 *params = mCaps.maxShaderUniformBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001623 break;
1624 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001625 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001626 break;
1627 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1628 *params = mCaps.maxComputeSharedMemorySize;
1629 break;
1630 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001631 *params = mCaps.maxShaderUniformComponents[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001632 break;
1633 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001634 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001635 break;
1636 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001637 *params = mCaps.maxShaderAtomicCounters[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001638 break;
1639 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001640 *params = mCaps.maxShaderImageUniforms[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001641 break;
1642 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001643 *params =
1644 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Compute]);
Jamie Madill231c7f52017-04-26 13:45:37 -04001645 break;
1646 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001647 *params = mCaps.maxShaderStorageBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001648 break;
1649 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1650 *params = mCaps.maxCombinedShaderOutputResources;
1651 break;
1652 case GL_MAX_UNIFORM_LOCATIONS:
1653 *params = mCaps.maxUniformLocations;
1654 break;
1655 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1656 *params = mCaps.maxAtomicCounterBufferBindings;
1657 break;
1658 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1659 *params = mCaps.maxAtomicCounterBufferSize;
1660 break;
1661 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1662 *params = mCaps.maxCombinedAtomicCounterBuffers;
1663 break;
1664 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1665 *params = mCaps.maxCombinedAtomicCounters;
1666 break;
1667 case GL_MAX_IMAGE_UNITS:
1668 *params = mCaps.maxImageUnits;
1669 break;
1670 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1671 *params = mCaps.maxCombinedImageUniforms;
1672 break;
1673 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1674 *params = mCaps.maxShaderStorageBufferBindings;
1675 break;
1676 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1677 *params = mCaps.maxCombinedShaderStorageBlocks;
1678 break;
1679 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1680 *params = mCaps.shaderStorageBufferOffsetAlignment;
1681 break;
Jiawei Shao361df072017-11-22 09:33:59 +08001682
1683 // GL_EXT_geometry_shader
1684 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
1685 *params = mCaps.maxFramebufferLayers;
1686 break;
1687 case GL_LAYER_PROVOKING_VERTEX_EXT:
1688 *params = mCaps.layerProvokingVertex;
1689 break;
1690 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001691 *params = mCaps.maxShaderUniformComponents[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001692 break;
1693 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001694 *params = mCaps.maxShaderUniformBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001695 break;
1696 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001697 *params =
1698 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Geometry]);
Jiawei Shao361df072017-11-22 09:33:59 +08001699 break;
1700 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
1701 *params = mCaps.maxGeometryInputComponents;
1702 break;
1703 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
1704 *params = mCaps.maxGeometryOutputComponents;
1705 break;
1706 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
1707 *params = mCaps.maxGeometryOutputVertices;
1708 break;
1709 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
1710 *params = mCaps.maxGeometryTotalOutputComponents;
1711 break;
1712 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
1713 *params = mCaps.maxGeometryShaderInvocations;
1714 break;
1715 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001716 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001717 break;
1718 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001719 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001720 break;
1721 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001722 *params = mCaps.maxShaderAtomicCounters[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001723 break;
1724 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001725 *params = mCaps.maxShaderImageUniforms[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001726 break;
1727 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001728 *params = mCaps.maxShaderStorageBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001729 break;
Lingfeng Yang96310cd2018-03-28 11:56:28 -07001730 // GLES1 emulation: Caps queries
1731 case GL_MAX_TEXTURE_UNITS:
1732 *params = mCaps.maxMultitextureUnits;
1733 break;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001734 case GL_MAX_MODELVIEW_STACK_DEPTH:
1735 *params = mCaps.maxModelviewMatrixStackDepth;
1736 break;
1737 case GL_MAX_PROJECTION_STACK_DEPTH:
1738 *params = mCaps.maxProjectionMatrixStackDepth;
1739 break;
1740 case GL_MAX_TEXTURE_STACK_DEPTH:
1741 *params = mCaps.maxTextureMatrixStackDepth;
1742 break;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07001743 case GL_MAX_LIGHTS:
1744 *params = mCaps.maxLights;
1745 break;
Lingfeng Yang060088a2018-05-30 20:40:57 -07001746 case GL_MAX_CLIP_PLANES:
1747 *params = mCaps.maxClipPlanes;
1748 break;
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001749 // GLES1 emulation: Vertex attribute queries
1750 case GL_VERTEX_ARRAY_BUFFER_BINDING:
1751 case GL_NORMAL_ARRAY_BUFFER_BINDING:
1752 case GL_COLOR_ARRAY_BUFFER_BINDING:
1753 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
1754 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
1755 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1756 GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, params);
1757 break;
1758 case GL_VERTEX_ARRAY_STRIDE:
1759 case GL_NORMAL_ARRAY_STRIDE:
1760 case GL_COLOR_ARRAY_STRIDE:
1761 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
1762 case GL_TEXTURE_COORD_ARRAY_STRIDE:
1763 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1764 GL_VERTEX_ATTRIB_ARRAY_STRIDE, params);
1765 break;
1766 case GL_VERTEX_ARRAY_SIZE:
1767 case GL_COLOR_ARRAY_SIZE:
1768 case GL_TEXTURE_COORD_ARRAY_SIZE:
1769 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1770 GL_VERTEX_ATTRIB_ARRAY_SIZE, params);
1771 break;
1772 case GL_VERTEX_ARRAY_TYPE:
1773 case GL_COLOR_ARRAY_TYPE:
1774 case GL_NORMAL_ARRAY_TYPE:
1775 case GL_POINT_SIZE_ARRAY_TYPE_OES:
1776 case GL_TEXTURE_COORD_ARRAY_TYPE:
1777 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1778 GL_VERTEX_ATTRIB_ARRAY_TYPE, params);
1779 break;
1780
jchen1082af6202018-06-22 10:59:52 +08001781 // GL_KHR_parallel_shader_compile
1782 case GL_MAX_SHADER_COMPILER_THREADS_KHR:
1783 *params = mGLState.getMaxShaderCompilerThreads();
1784 break;
1785
Jamie Madill231c7f52017-04-26 13:45:37 -04001786 default:
Jamie Madille98b1b52018-03-08 09:47:23 -05001787 handleError(mGLState.getIntegerv(this, pname, params));
Jamie Madill231c7f52017-04-26 13:45:37 -04001788 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001789 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001790}
1791
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001792void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001793{
Shannon Woods53a94a82014-06-24 15:20:36 -04001794 // Queries about context capabilities and maximums are answered by Context.
1795 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001796 switch (pname)
1797 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001798 case GL_MAX_ELEMENT_INDEX:
1799 *params = mCaps.maxElementIndex;
1800 break;
1801 case GL_MAX_UNIFORM_BLOCK_SIZE:
1802 *params = mCaps.maxUniformBlockSize;
1803 break;
1804 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001805 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001806 break;
1807 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001808 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001809 break;
1810 case GL_MAX_SERVER_WAIT_TIMEOUT:
1811 *params = mCaps.maxServerWaitTimeout;
1812 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001813
Jamie Madill231c7f52017-04-26 13:45:37 -04001814 // GL_EXT_disjoint_timer_query
1815 case GL_TIMESTAMP_EXT:
1816 *params = mImplementation->getTimestamp();
1817 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001818
Jamie Madill231c7f52017-04-26 13:45:37 -04001819 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1820 *params = mCaps.maxShaderStorageBlockSize;
1821 break;
1822 default:
1823 UNREACHABLE();
1824 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001825 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001826}
1827
Geoff Lang70d0f492015-12-10 17:45:46 -05001828void Context::getPointerv(GLenum pname, void **params) const
1829{
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001830 mGLState.getPointerv(this, pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001831}
1832
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001833void Context::getPointervRobustANGLERobust(GLenum pname,
1834 GLsizei bufSize,
1835 GLsizei *length,
1836 void **params)
1837{
1838 UNIMPLEMENTED();
1839}
1840
Martin Radev66fb8202016-07-28 11:45:20 +03001841void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001842{
Shannon Woods53a94a82014-06-24 15:20:36 -04001843 // Queries about context capabilities and maximums are answered by Context.
1844 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001845
1846 GLenum nativeType;
1847 unsigned int numParams;
1848 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1849 ASSERT(queryStatus);
1850
1851 if (nativeType == GL_INT)
1852 {
1853 switch (target)
1854 {
1855 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1856 ASSERT(index < 3u);
1857 *data = mCaps.maxComputeWorkGroupCount[index];
1858 break;
1859 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1860 ASSERT(index < 3u);
1861 *data = mCaps.maxComputeWorkGroupSize[index];
1862 break;
1863 default:
1864 mGLState.getIntegeri_v(target, index, data);
1865 }
1866 }
1867 else
1868 {
1869 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1870 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001871}
1872
Brandon Jones59770802018-04-02 13:18:42 -07001873void Context::getIntegeri_vRobust(GLenum target,
1874 GLuint index,
1875 GLsizei bufSize,
1876 GLsizei *length,
1877 GLint *data)
1878{
1879 getIntegeri_v(target, index, data);
1880}
1881
Martin Radev66fb8202016-07-28 11:45:20 +03001882void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001883{
Shannon Woods53a94a82014-06-24 15:20:36 -04001884 // Queries about context capabilities and maximums are answered by Context.
1885 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001886
1887 GLenum nativeType;
1888 unsigned int numParams;
1889 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1890 ASSERT(queryStatus);
1891
1892 if (nativeType == GL_INT_64_ANGLEX)
1893 {
1894 mGLState.getInteger64i_v(target, index, data);
1895 }
1896 else
1897 {
1898 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1899 }
1900}
1901
Brandon Jones59770802018-04-02 13:18:42 -07001902void Context::getInteger64i_vRobust(GLenum target,
1903 GLuint index,
1904 GLsizei bufSize,
1905 GLsizei *length,
1906 GLint64 *data)
1907{
1908 getInteger64i_v(target, index, data);
1909}
1910
Martin Radev66fb8202016-07-28 11:45:20 +03001911void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1912{
1913 // Queries about context capabilities and maximums are answered by Context.
1914 // Queries about current GL state values are answered by State.
1915
1916 GLenum nativeType;
1917 unsigned int numParams;
1918 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1919 ASSERT(queryStatus);
1920
1921 if (nativeType == GL_BOOL)
1922 {
1923 mGLState.getBooleani_v(target, index, data);
1924 }
1925 else
1926 {
1927 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1928 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001929}
1930
Brandon Jones59770802018-04-02 13:18:42 -07001931void Context::getBooleani_vRobust(GLenum target,
1932 GLuint index,
1933 GLsizei bufSize,
1934 GLsizei *length,
1935 GLboolean *data)
1936{
1937 getBooleani_v(target, index, data);
1938}
1939
Corentin Wallez336129f2017-10-17 15:55:40 -04001940void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001941{
1942 Buffer *buffer = mGLState.getTargetBuffer(target);
1943 QueryBufferParameteriv(buffer, pname, params);
1944}
1945
Brandon Jones59770802018-04-02 13:18:42 -07001946void Context::getBufferParameterivRobust(BufferBinding target,
1947 GLenum pname,
1948 GLsizei bufSize,
1949 GLsizei *length,
1950 GLint *params)
1951{
1952 getBufferParameteriv(target, pname, params);
1953}
1954
He Yunchao010e4db2017-03-03 14:22:06 +08001955void Context::getFramebufferAttachmentParameteriv(GLenum target,
1956 GLenum attachment,
1957 GLenum pname,
1958 GLint *params)
1959{
1960 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08001961 QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08001962}
1963
Brandon Jones59770802018-04-02 13:18:42 -07001964void Context::getFramebufferAttachmentParameterivRobust(GLenum target,
1965 GLenum attachment,
1966 GLenum pname,
1967 GLsizei bufSize,
1968 GLsizei *length,
1969 GLint *params)
1970{
1971 getFramebufferAttachmentParameteriv(target, attachment, pname, params);
1972}
1973
He Yunchao010e4db2017-03-03 14:22:06 +08001974void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
1975{
1976 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
1977 QueryRenderbufferiv(this, renderbuffer, pname, params);
1978}
1979
Brandon Jones59770802018-04-02 13:18:42 -07001980void Context::getRenderbufferParameterivRobust(GLenum target,
1981 GLenum pname,
1982 GLsizei bufSize,
1983 GLsizei *length,
1984 GLint *params)
1985{
1986 getRenderbufferParameteriv(target, pname, params);
1987}
1988
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001989void Context::getTexParameterfv(TextureType target, GLenum pname, GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001990{
1991 Texture *texture = getTargetTexture(target);
1992 QueryTexParameterfv(texture, pname, params);
1993}
1994
Brandon Jones59770802018-04-02 13:18:42 -07001995void Context::getTexParameterfvRobust(TextureType target,
1996 GLenum pname,
1997 GLsizei bufSize,
1998 GLsizei *length,
1999 GLfloat *params)
2000{
2001 getTexParameterfv(target, pname, params);
2002}
2003
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002004void Context::getTexParameteriv(TextureType target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002005{
2006 Texture *texture = getTargetTexture(target);
2007 QueryTexParameteriv(texture, pname, params);
2008}
Jiajia Qin5451d532017-11-16 17:16:34 +08002009
Brandon Jones59770802018-04-02 13:18:42 -07002010void Context::getTexParameterivRobust(TextureType target,
2011 GLenum pname,
2012 GLsizei bufSize,
2013 GLsizei *length,
2014 GLint *params)
2015{
2016 getTexParameteriv(target, pname, params);
2017}
2018
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002019void Context::getTexParameterIivRobust(TextureType target,
2020 GLenum pname,
2021 GLsizei bufSize,
2022 GLsizei *length,
2023 GLint *params)
2024{
2025 UNIMPLEMENTED();
2026}
2027
2028void Context::getTexParameterIuivRobust(TextureType target,
2029 GLenum pname,
2030 GLsizei bufSize,
2031 GLsizei *length,
2032 GLuint *params)
2033{
2034 UNIMPLEMENTED();
2035}
2036
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002037void Context::getTexLevelParameteriv(TextureTarget target, GLint level, GLenum pname, GLint *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002038{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002039 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002040 QueryTexLevelParameteriv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002041}
2042
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002043void Context::getTexLevelParameterivRobust(TextureTarget target,
2044 GLint level,
2045 GLenum pname,
2046 GLsizei bufSize,
2047 GLsizei *length,
2048 GLint *params)
2049{
2050 UNIMPLEMENTED();
2051}
2052
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002053void Context::getTexLevelParameterfv(TextureTarget target,
2054 GLint level,
2055 GLenum pname,
2056 GLfloat *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002057{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002058 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002059 QueryTexLevelParameterfv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002060}
2061
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002062void Context::getTexLevelParameterfvRobust(TextureTarget target,
2063 GLint level,
2064 GLenum pname,
2065 GLsizei bufSize,
2066 GLsizei *length,
2067 GLfloat *params)
2068{
2069 UNIMPLEMENTED();
2070}
2071
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002072void Context::texParameterf(TextureType target, GLenum pname, GLfloat param)
He Yunchao010e4db2017-03-03 14:22:06 +08002073{
2074 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002075 SetTexParameterf(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002076 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002077}
2078
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002079void Context::texParameterfv(TextureType target, GLenum pname, const GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002080{
2081 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002082 SetTexParameterfv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002083 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002084}
2085
Brandon Jones59770802018-04-02 13:18:42 -07002086void Context::texParameterfvRobust(TextureType target,
2087 GLenum pname,
2088 GLsizei bufSize,
2089 const GLfloat *params)
2090{
2091 texParameterfv(target, pname, params);
2092}
2093
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002094void Context::texParameteri(TextureType target, GLenum pname, GLint param)
He Yunchao010e4db2017-03-03 14:22:06 +08002095{
2096 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002097 SetTexParameteri(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002098 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002099}
2100
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002101void Context::texParameteriv(TextureType target, GLenum pname, const GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002102{
2103 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002104 SetTexParameteriv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002105 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002106}
2107
Brandon Jones59770802018-04-02 13:18:42 -07002108void Context::texParameterivRobust(TextureType target,
2109 GLenum pname,
2110 GLsizei bufSize,
2111 const GLint *params)
2112{
2113 texParameteriv(target, pname, params);
2114}
2115
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002116void Context::texParameterIivRobust(TextureType target,
2117 GLenum pname,
2118 GLsizei bufSize,
2119 const GLint *params)
2120{
2121 UNIMPLEMENTED();
2122}
2123
2124void Context::texParameterIuivRobust(TextureType target,
2125 GLenum pname,
2126 GLsizei bufSize,
2127 const GLuint *params)
2128{
2129 UNIMPLEMENTED();
2130}
2131
Jamie Madill493f9572018-05-24 19:52:15 -04002132void Context::drawArrays(PrimitiveMode mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002133{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002134 // No-op if count draws no primitives for given mode
2135 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002136 {
2137 return;
2138 }
2139
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002140 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002141 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
Jamie Madill09463932018-04-04 05:26:59 -04002142 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count, 1);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002143}
2144
Jamie Madill493f9572018-05-24 19:52:15 -04002145void Context::drawArraysInstanced(PrimitiveMode mode,
2146 GLint first,
2147 GLsizei count,
2148 GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04002149{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002150 // No-op if count draws no primitives for given mode
2151 if (noopDrawInstanced(mode, count, instanceCount))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002152 {
2153 return;
2154 }
2155
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002156 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002157 ANGLE_CONTEXT_TRY(
2158 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
Jamie Madill09463932018-04-04 05:26:59 -04002159 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count,
2160 instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -04002161}
2162
Jamie Madill493f9572018-05-24 19:52:15 -04002163void Context::drawElements(PrimitiveMode mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002164{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002165 // No-op if count draws no primitives for given mode
2166 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002167 {
2168 return;
2169 }
2170
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002171 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002172 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04002173}
2174
Jamie Madill493f9572018-05-24 19:52:15 -04002175void Context::drawElementsInstanced(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002176 GLsizei count,
2177 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002178 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04002179 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04002180{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002181 // No-op if count draws no primitives for given mode
2182 if (noopDrawInstanced(mode, count, instances))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002183 {
2184 return;
2185 }
2186
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002187 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002188 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08002189 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04002190}
2191
Jamie Madill493f9572018-05-24 19:52:15 -04002192void Context::drawRangeElements(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002193 GLuint start,
2194 GLuint end,
2195 GLsizei count,
2196 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002197 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04002198{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002199 // No-op if count draws no primitives for given mode
2200 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002201 {
2202 return;
2203 }
2204
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002205 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002206 ANGLE_CONTEXT_TRY(
2207 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002208}
2209
Jamie Madill493f9572018-05-24 19:52:15 -04002210void Context::drawArraysIndirect(PrimitiveMode mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002211{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002212 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002213 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002214}
2215
Jamie Madill493f9572018-05-24 19:52:15 -04002216void Context::drawElementsIndirect(PrimitiveMode mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002217{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002218 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002219 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002220}
2221
Jamie Madill675fe712016-12-19 13:07:54 -05002222void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002223{
Jamie Madillafa02a22017-11-23 12:57:38 -05002224 handleError(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05002225}
2226
Jamie Madill675fe712016-12-19 13:07:54 -05002227void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05002228{
Jamie Madillafa02a22017-11-23 12:57:38 -05002229 handleError(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002230}
2231
Austin Kinross6ee1e782015-05-29 17:05:37 -07002232void Context::insertEventMarker(GLsizei length, const char *marker)
2233{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002234 ASSERT(mImplementation);
2235 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07002236}
2237
2238void Context::pushGroupMarker(GLsizei length, const char *marker)
2239{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002240 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05002241
2242 if (marker == nullptr)
2243 {
2244 // From the EXT_debug_marker spec,
2245 // "If <marker> is null then an empty string is pushed on the stack."
2246 mImplementation->pushGroupMarker(length, "");
2247 }
2248 else
2249 {
2250 mImplementation->pushGroupMarker(length, marker);
2251 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07002252}
2253
2254void Context::popGroupMarker()
2255{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002256 ASSERT(mImplementation);
2257 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07002258}
2259
Geoff Langd8605522016-04-13 10:19:12 -04002260void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
2261{
2262 Program *programObject = getProgram(program);
2263 ASSERT(programObject);
2264
2265 programObject->bindUniformLocation(location, name);
2266}
2267
Brandon Jones59770802018-04-02 13:18:42 -07002268void Context::coverageModulation(GLenum components)
Sami Väisänena797e062016-05-12 15:23:40 +03002269{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002270 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03002271}
2272
Brandon Jones59770802018-04-02 13:18:42 -07002273void Context::matrixLoadf(GLenum matrixMode, const GLfloat *matrix)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002274{
2275 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
2276}
2277
Brandon Jones59770802018-04-02 13:18:42 -07002278void Context::matrixLoadIdentity(GLenum matrixMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002279{
2280 GLfloat I[16];
2281 angle::Matrix<GLfloat>::setToIdentity(I);
2282
2283 mGLState.loadPathRenderingMatrix(matrixMode, I);
2284}
2285
2286void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
2287{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002288 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002289 if (!pathObj)
2290 return;
2291
2292 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002293 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002294
2295 mImplementation->stencilFillPath(pathObj, fillMode, mask);
2296}
2297
2298void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
2299{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002300 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002301 if (!pathObj)
2302 return;
2303
2304 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002305 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002306
2307 mImplementation->stencilStrokePath(pathObj, reference, mask);
2308}
2309
2310void Context::coverFillPath(GLuint path, GLenum coverMode)
2311{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002312 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002313 if (!pathObj)
2314 return;
2315
2316 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002317 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002318
2319 mImplementation->coverFillPath(pathObj, coverMode);
2320}
2321
2322void Context::coverStrokePath(GLuint path, GLenum coverMode)
2323{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002324 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002325 if (!pathObj)
2326 return;
2327
2328 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002329 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002330
2331 mImplementation->coverStrokePath(pathObj, coverMode);
2332}
2333
2334void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
2335{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002336 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002337 if (!pathObj)
2338 return;
2339
2340 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002341 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002342
2343 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
2344}
2345
2346void Context::stencilThenCoverStrokePath(GLuint path,
2347 GLint reference,
2348 GLuint mask,
2349 GLenum coverMode)
2350{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002351 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002352 if (!pathObj)
2353 return;
2354
2355 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002356 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002357
2358 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2359}
2360
Sami Väisänend59ca052016-06-21 16:10:00 +03002361void Context::coverFillPathInstanced(GLsizei numPaths,
2362 GLenum pathNameType,
2363 const void *paths,
2364 GLuint pathBase,
2365 GLenum coverMode,
2366 GLenum transformType,
2367 const GLfloat *transformValues)
2368{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002369 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002370
2371 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002372 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002373
2374 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2375}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002376
Sami Väisänend59ca052016-06-21 16:10:00 +03002377void Context::coverStrokePathInstanced(GLsizei numPaths,
2378 GLenum pathNameType,
2379 const void *paths,
2380 GLuint pathBase,
2381 GLenum coverMode,
2382 GLenum transformType,
2383 const GLfloat *transformValues)
2384{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002385 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002386
2387 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002388 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002389
2390 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2391 transformValues);
2392}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002393
Sami Väisänend59ca052016-06-21 16:10:00 +03002394void Context::stencilFillPathInstanced(GLsizei numPaths,
2395 GLenum pathNameType,
2396 const void *paths,
2397 GLuint pathBase,
2398 GLenum fillMode,
2399 GLuint mask,
2400 GLenum transformType,
2401 const GLfloat *transformValues)
2402{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002403 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002404
2405 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002406 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002407
2408 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2409 transformValues);
2410}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002411
Sami Väisänend59ca052016-06-21 16:10:00 +03002412void Context::stencilStrokePathInstanced(GLsizei numPaths,
2413 GLenum pathNameType,
2414 const void *paths,
2415 GLuint pathBase,
2416 GLint reference,
2417 GLuint mask,
2418 GLenum transformType,
2419 const GLfloat *transformValues)
2420{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002421 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002422
2423 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002424 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002425
2426 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2427 transformValues);
2428}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002429
Sami Väisänend59ca052016-06-21 16:10:00 +03002430void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2431 GLenum pathNameType,
2432 const void *paths,
2433 GLuint pathBase,
2434 GLenum fillMode,
2435 GLuint mask,
2436 GLenum coverMode,
2437 GLenum transformType,
2438 const GLfloat *transformValues)
2439{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002440 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002441
2442 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002443 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002444
2445 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2446 transformType, transformValues);
2447}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002448
Sami Väisänend59ca052016-06-21 16:10:00 +03002449void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2450 GLenum pathNameType,
2451 const void *paths,
2452 GLuint pathBase,
2453 GLint reference,
2454 GLuint mask,
2455 GLenum coverMode,
2456 GLenum transformType,
2457 const GLfloat *transformValues)
2458{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002459 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002460
2461 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002462 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002463
2464 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2465 transformType, transformValues);
2466}
2467
Sami Väisänen46eaa942016-06-29 10:26:37 +03002468void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2469{
2470 auto *programObject = getProgram(program);
2471
2472 programObject->bindFragmentInputLocation(location, name);
2473}
2474
2475void Context::programPathFragmentInputGen(GLuint program,
2476 GLint location,
2477 GLenum genMode,
2478 GLint components,
2479 const GLfloat *coeffs)
2480{
2481 auto *programObject = getProgram(program);
2482
Jamie Madillbd044ed2017-06-05 12:59:21 -04002483 programObject->pathFragmentInputGen(this, location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002484}
2485
jchen1015015f72017-03-16 13:54:21 +08002486GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2487{
jchen10fd7c3b52017-03-21 15:36:03 +08002488 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002489 return QueryProgramResourceIndex(programObject, programInterface, name);
2490}
2491
jchen10fd7c3b52017-03-21 15:36:03 +08002492void Context::getProgramResourceName(GLuint program,
2493 GLenum programInterface,
2494 GLuint index,
2495 GLsizei bufSize,
2496 GLsizei *length,
2497 GLchar *name)
2498{
2499 const auto *programObject = getProgram(program);
2500 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2501}
2502
jchen10191381f2017-04-11 13:59:04 +08002503GLint Context::getProgramResourceLocation(GLuint program,
2504 GLenum programInterface,
2505 const GLchar *name)
2506{
2507 const auto *programObject = getProgram(program);
2508 return QueryProgramResourceLocation(programObject, programInterface, name);
2509}
2510
jchen10880683b2017-04-12 16:21:55 +08002511void Context::getProgramResourceiv(GLuint program,
2512 GLenum programInterface,
2513 GLuint index,
2514 GLsizei propCount,
2515 const GLenum *props,
2516 GLsizei bufSize,
2517 GLsizei *length,
2518 GLint *params)
2519{
2520 const auto *programObject = getProgram(program);
2521 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2522 length, params);
2523}
2524
jchen10d9cd7b72017-08-30 15:04:25 +08002525void Context::getProgramInterfaceiv(GLuint program,
2526 GLenum programInterface,
2527 GLenum pname,
2528 GLint *params)
2529{
2530 const auto *programObject = getProgram(program);
2531 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2532}
2533
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002534void Context::getProgramInterfaceivRobust(GLuint program,
2535 GLenum programInterface,
2536 GLenum pname,
2537 GLsizei bufSize,
2538 GLsizei *length,
2539 GLint *params)
2540{
2541 UNIMPLEMENTED();
2542}
2543
Jamie Madill427064d2018-04-13 16:20:34 -04002544void Context::handleError(const Error &error) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002545{
Geoff Lang7b19a492018-04-20 09:31:52 -04002546 if (ANGLE_UNLIKELY(error.isError()))
Geoff Langda5777c2014-07-11 09:52:58 -04002547 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002548 GLenum code = error.getCode();
2549 mErrors.insert(code);
2550 if (code == GL_OUT_OF_MEMORY && getWorkarounds().loseContextOnOutOfMemory)
2551 {
2552 markContextLost();
2553 }
Geoff Lang70d0f492015-12-10 17:45:46 -05002554
Geoff Langee6884e2017-11-09 16:51:11 -05002555 ASSERT(!error.getMessage().empty());
2556 mGLState.getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, error.getID(),
2557 GL_DEBUG_SEVERITY_HIGH, error.getMessage());
Geoff Langda5777c2014-07-11 09:52:58 -04002558 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002559}
2560
2561// Get one of the recorded errors and clear its flag, if any.
2562// [OpenGL ES 2.0.24] section 2.5 page 13.
2563GLenum Context::getError()
2564{
Geoff Langda5777c2014-07-11 09:52:58 -04002565 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002566 {
Geoff Langda5777c2014-07-11 09:52:58 -04002567 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002568 }
Geoff Langda5777c2014-07-11 09:52:58 -04002569 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002570 {
Geoff Langda5777c2014-07-11 09:52:58 -04002571 GLenum error = *mErrors.begin();
2572 mErrors.erase(mErrors.begin());
2573 return error;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002574 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002575}
2576
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002577// NOTE: this function should not assume that this context is current!
Jamie Madill427064d2018-04-13 16:20:34 -04002578void Context::markContextLost() const
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002579{
2580 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002581 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002582 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002583 mContextLostForced = true;
2584 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002585 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002586}
2587
Jamie Madill427064d2018-04-13 16:20:34 -04002588bool Context::isContextLost() const
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002589{
2590 return mContextLost;
2591}
2592
Jamie Madillfa920eb2018-01-04 11:45:50 -05002593GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002594{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002595 // Even if the application doesn't want to know about resets, we want to know
2596 // as it will allow us to skip all the calls.
2597 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002598 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002599 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002600 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002601 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002602 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002603
2604 // EXT_robustness, section 2.6: If the reset notification behavior is
2605 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2606 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2607 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002608 }
2609
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002610 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2611 // status should be returned at least once, and GL_NO_ERROR should be returned
2612 // once the device has finished resetting.
2613 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002614 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002615 ASSERT(mResetStatus == GL_NO_ERROR);
2616 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002617
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002618 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002619 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002620 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002621 }
2622 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002623 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002624 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002625 // If markContextLost was used to mark the context lost then
2626 // assume that is not recoverable, and continue to report the
2627 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002628 mResetStatus = mImplementation->getResetStatus();
2629 }
Jamie Madill893ab082014-05-16 16:56:10 -04002630
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002631 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002632}
2633
2634bool Context::isResetNotificationEnabled()
2635{
2636 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2637}
2638
Corentin Walleze3b10e82015-05-20 11:06:25 -04002639const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002640{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002641 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002642}
2643
2644EGLenum Context::getClientType() const
2645{
2646 return mClientType;
2647}
2648
2649EGLenum Context::getRenderBuffer() const
2650{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002651 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2652 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002653 {
2654 return EGL_NONE;
2655 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002656
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002657 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002658 ASSERT(backAttachment != nullptr);
2659 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002660}
2661
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002662VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002663{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002664 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002665 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2666 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002667 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002668 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2669 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002670
Jamie Madill96a483b2017-06-27 16:49:21 -04002671 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002672 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002673
2674 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002675}
2676
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002677TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002678{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002679 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002680 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2681 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002682 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002683 transformFeedback =
2684 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002685 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002686 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002687 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002688
2689 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002690}
2691
2692bool Context::isVertexArrayGenerated(GLuint vertexArray)
2693{
Jamie Madill96a483b2017-06-27 16:49:21 -04002694 ASSERT(mVertexArrayMap.contains(0));
2695 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002696}
2697
2698bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2699{
Jamie Madill96a483b2017-06-27 16:49:21 -04002700 ASSERT(mTransformFeedbackMap.contains(0));
2701 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002702}
2703
Shannon Woods53a94a82014-06-24 15:20:36 -04002704void Context::detachTexture(GLuint texture)
2705{
2706 // Simple pass-through to State's detachTexture method, as textures do not require
2707 // allocation map management either here or in the resource manager at detach time.
2708 // Zero textures are held by the Context, and we don't attempt to request them from
2709 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002710 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002711}
2712
James Darpinian4d9d4832018-03-13 12:43:28 -07002713void Context::detachBuffer(Buffer *buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002714{
Yuly Novikov5807a532015-12-03 13:01:22 -05002715 // Simple pass-through to State's detachBuffer method, since
2716 // only buffer attachments to container objects that are bound to the current context
2717 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002718
Yuly Novikov5807a532015-12-03 13:01:22 -05002719 // [OpenGL ES 3.2] section 5.1.2 page 45:
2720 // Attachments to unbound container objects, such as
2721 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2722 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002723 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002724}
2725
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002726void Context::detachFramebuffer(GLuint framebuffer)
2727{
Shannon Woods53a94a82014-06-24 15:20:36 -04002728 // Framebuffer detachment is handled by Context, because 0 is a valid
2729 // Framebuffer object, and a pointer to it must be passed from Context
2730 // to State at binding time.
2731
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002732 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002733 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2734 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2735 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002736
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002737 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002738 {
2739 bindReadFramebuffer(0);
2740 }
2741
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002742 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002743 {
2744 bindDrawFramebuffer(0);
2745 }
2746}
2747
2748void Context::detachRenderbuffer(GLuint renderbuffer)
2749{
Jamie Madilla02315b2017-02-23 14:14:47 -05002750 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002751}
2752
Jamie Madill57a89722013-07-02 11:57:03 -04002753void Context::detachVertexArray(GLuint vertexArray)
2754{
Jamie Madill77a72f62015-04-14 11:18:32 -04002755 // Vertex array detachment is handled by Context, because 0 is a valid
2756 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002757 // binding time.
2758
Jamie Madill57a89722013-07-02 11:57:03 -04002759 // [OpenGL ES 3.0.2] section 2.10 page 43:
2760 // If a vertex array object that is currently bound is deleted, the binding
2761 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madill7267aa62018-04-17 15:28:21 -04002762 if (mGLState.removeVertexArrayBinding(this, vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002763 {
2764 bindVertexArray(0);
2765 }
2766}
2767
Geoff Langc8058452014-02-03 12:04:11 -05002768void Context::detachTransformFeedback(GLuint transformFeedback)
2769{
Corentin Walleza2257da2016-04-19 16:43:12 -04002770 // Transform feedback detachment is handled by Context, because 0 is a valid
2771 // transform feedback, and a pointer to it must be passed from Context to State at
2772 // binding time.
2773
2774 // The OpenGL specification doesn't mention what should happen when the currently bound
2775 // transform feedback object is deleted. Since it is a container object, we treat it like
2776 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002777 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002778 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002779 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002780 }
Geoff Langc8058452014-02-03 12:04:11 -05002781}
2782
Jamie Madilldc356042013-07-19 16:36:57 -04002783void Context::detachSampler(GLuint sampler)
2784{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002785 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002786}
2787
Yunchao Hea336b902017-08-02 16:05:21 +08002788void Context::detachProgramPipeline(GLuint pipeline)
2789{
2790 mGLState.detachProgramPipeline(this, pipeline);
2791}
2792
Jamie Madill3ef140a2017-08-26 23:11:21 -04002793void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002794{
Shaodde78e82017-05-22 14:13:27 +08002795 mGLState.setVertexAttribDivisor(this, index, divisor);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002796}
2797
Jamie Madille29d1672013-07-19 16:36:57 -04002798void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2799{
Geoff Langc1984ed2016-10-07 12:41:00 -04002800 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002801 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002802 SetSamplerParameteri(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002803 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002804}
Jamie Madille29d1672013-07-19 16:36:57 -04002805
Geoff Langc1984ed2016-10-07 12:41:00 -04002806void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2807{
2808 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002809 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002810 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002811 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002812}
2813
Brandon Jones59770802018-04-02 13:18:42 -07002814void Context::samplerParameterivRobust(GLuint sampler,
2815 GLenum pname,
2816 GLsizei bufSize,
2817 const GLint *param)
2818{
2819 samplerParameteriv(sampler, pname, param);
2820}
2821
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002822void Context::samplerParameterIivRobust(GLuint sampler,
2823 GLenum pname,
2824 GLsizei bufSize,
2825 const GLint *param)
2826{
2827 UNIMPLEMENTED();
2828}
2829
2830void Context::samplerParameterIuivRobust(GLuint sampler,
2831 GLenum pname,
2832 GLsizei bufSize,
2833 const GLuint *param)
2834{
2835 UNIMPLEMENTED();
2836}
2837
Jamie Madille29d1672013-07-19 16:36:57 -04002838void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2839{
Geoff Langc1984ed2016-10-07 12:41:00 -04002840 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002841 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002842 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002843 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002844}
2845
Geoff Langc1984ed2016-10-07 12:41:00 -04002846void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002847{
Geoff Langc1984ed2016-10-07 12:41:00 -04002848 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002849 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002850 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002851 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002852}
2853
Brandon Jones59770802018-04-02 13:18:42 -07002854void Context::samplerParameterfvRobust(GLuint sampler,
2855 GLenum pname,
2856 GLsizei bufSize,
2857 const GLfloat *param)
2858{
2859 samplerParameterfv(sampler, pname, param);
2860}
2861
Geoff Langc1984ed2016-10-07 12:41:00 -04002862void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002863{
Geoff Langc1984ed2016-10-07 12:41:00 -04002864 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002865 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002866 QuerySamplerParameteriv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002867 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002868}
Jamie Madill9675b802013-07-19 16:36:59 -04002869
Brandon Jones59770802018-04-02 13:18:42 -07002870void Context::getSamplerParameterivRobust(GLuint sampler,
2871 GLenum pname,
2872 GLsizei bufSize,
2873 GLsizei *length,
2874 GLint *params)
2875{
2876 getSamplerParameteriv(sampler, pname, params);
2877}
2878
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002879void Context::getSamplerParameterIivRobust(GLuint sampler,
2880 GLenum pname,
2881 GLsizei bufSize,
2882 GLsizei *length,
2883 GLint *params)
2884{
2885 UNIMPLEMENTED();
2886}
2887
2888void Context::getSamplerParameterIuivRobust(GLuint sampler,
2889 GLenum pname,
2890 GLsizei bufSize,
2891 GLsizei *length,
2892 GLuint *params)
2893{
2894 UNIMPLEMENTED();
2895}
2896
Geoff Langc1984ed2016-10-07 12:41:00 -04002897void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2898{
2899 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002900 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002901 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002902 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002903}
2904
Brandon Jones59770802018-04-02 13:18:42 -07002905void Context::getSamplerParameterfvRobust(GLuint sampler,
2906 GLenum pname,
2907 GLsizei bufSize,
2908 GLsizei *length,
2909 GLfloat *params)
2910{
2911 getSamplerParameterfv(sampler, pname, params);
2912}
2913
Olli Etuahof0fee072016-03-30 15:11:58 +03002914void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2915{
2916 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002917 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002918}
2919
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002920void Context::initRendererString()
2921{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002922 std::ostringstream rendererString;
2923 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002924 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002925 rendererString << ")";
2926
Geoff Langcec35902014-04-16 10:52:36 -04002927 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002928}
2929
Geoff Langc339c4e2016-11-29 10:37:36 -05002930void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002931{
Geoff Langc339c4e2016-11-29 10:37:36 -05002932 const Version &clientVersion = getClientVersion();
2933
2934 std::ostringstream versionString;
2935 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2936 << ANGLE_VERSION_STRING << ")";
2937 mVersionString = MakeStaticString(versionString.str());
2938
2939 std::ostringstream shadingLanguageVersionString;
2940 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2941 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2942 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2943 << ")";
2944 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002945}
2946
Geoff Langcec35902014-04-16 10:52:36 -04002947void Context::initExtensionStrings()
2948{
Geoff Langc339c4e2016-11-29 10:37:36 -05002949 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2950 std::ostringstream combinedStringStream;
2951 std::copy(strings.begin(), strings.end(),
2952 std::ostream_iterator<const char *>(combinedStringStream, " "));
2953 return MakeStaticString(combinedStringStream.str());
2954 };
2955
2956 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002957 for (const auto &extensionString : mExtensions.getStrings())
2958 {
2959 mExtensionStrings.push_back(MakeStaticString(extensionString));
2960 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002961 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002962
Geoff Langc339c4e2016-11-29 10:37:36 -05002963 mRequestableExtensionStrings.clear();
2964 for (const auto &extensionInfo : GetExtensionInfoMap())
2965 {
2966 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08002967 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
Geoff Langb0f917f2017-12-05 13:41:54 -05002968 mSupportedExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002969 {
2970 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
2971 }
2972 }
2973 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002974}
2975
Geoff Langc339c4e2016-11-29 10:37:36 -05002976const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04002977{
Geoff Langc339c4e2016-11-29 10:37:36 -05002978 switch (name)
2979 {
2980 case GL_VENDOR:
2981 return reinterpret_cast<const GLubyte *>("Google Inc.");
2982
2983 case GL_RENDERER:
2984 return reinterpret_cast<const GLubyte *>(mRendererString);
2985
2986 case GL_VERSION:
2987 return reinterpret_cast<const GLubyte *>(mVersionString);
2988
2989 case GL_SHADING_LANGUAGE_VERSION:
2990 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
2991
2992 case GL_EXTENSIONS:
2993 return reinterpret_cast<const GLubyte *>(mExtensionString);
2994
2995 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2996 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
2997
2998 default:
2999 UNREACHABLE();
3000 return nullptr;
3001 }
Geoff Langcec35902014-04-16 10:52:36 -04003002}
3003
Geoff Langc339c4e2016-11-29 10:37:36 -05003004const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04003005{
Geoff Langc339c4e2016-11-29 10:37:36 -05003006 switch (name)
3007 {
3008 case GL_EXTENSIONS:
3009 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
3010
3011 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
3012 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
3013
3014 default:
3015 UNREACHABLE();
3016 return nullptr;
3017 }
Geoff Langcec35902014-04-16 10:52:36 -04003018}
3019
3020size_t Context::getExtensionStringCount() const
3021{
3022 return mExtensionStrings.size();
3023}
3024
Geoff Lang111a99e2017-10-17 10:58:41 -04003025bool Context::isExtensionRequestable(const char *name)
3026{
3027 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3028 auto extension = extensionInfos.find(name);
3029
Geoff Lang111a99e2017-10-17 10:58:41 -04003030 return extension != extensionInfos.end() && extension->second.Requestable &&
Geoff Langb0f917f2017-12-05 13:41:54 -05003031 mSupportedExtensions.*(extension->second.ExtensionsMember);
Geoff Lang111a99e2017-10-17 10:58:41 -04003032}
3033
Geoff Langc339c4e2016-11-29 10:37:36 -05003034void Context::requestExtension(const char *name)
3035{
3036 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3037 ASSERT(extensionInfos.find(name) != extensionInfos.end());
3038 const auto &extension = extensionInfos.at(name);
3039 ASSERT(extension.Requestable);
Geoff Langb0f917f2017-12-05 13:41:54 -05003040 ASSERT(isExtensionRequestable(name));
Geoff Langc339c4e2016-11-29 10:37:36 -05003041
3042 if (mExtensions.*(extension.ExtensionsMember))
3043 {
3044 // Extension already enabled
3045 return;
3046 }
3047
3048 mExtensions.*(extension.ExtensionsMember) = true;
3049 updateCaps();
3050 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08003051
Jamie Madill2f348d22017-06-05 10:50:59 -04003052 // Release the shader compiler so it will be re-created with the requested extensions enabled.
3053 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04003054
Jamie Madill81c2e252017-09-09 23:32:46 -04003055 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
3056 // sampleable.
Jamie Madilld4442552018-02-27 22:03:47 -05003057 mState.mTextures->signalAllTexturesDirty(this);
Geoff Lang9aded172017-04-05 11:07:56 -04003058 for (auto &zeroTexture : mZeroTextures)
3059 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003060 if (zeroTexture.get() != nullptr)
3061 {
3062 zeroTexture->signalDirty(this, InitState::Initialized);
3063 }
Geoff Lang9aded172017-04-05 11:07:56 -04003064 }
3065
3066 mState.mFramebuffers->invalidateFramebufferComplenessCache();
Geoff Langc339c4e2016-11-29 10:37:36 -05003067}
3068
3069size_t Context::getRequestableExtensionStringCount() const
3070{
3071 return mRequestableExtensionStrings.size();
3072}
3073
Jamie Madill493f9572018-05-24 19:52:15 -04003074void Context::beginTransformFeedback(PrimitiveMode primitiveMode)
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003075{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003076 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003077 ASSERT(transformFeedback != nullptr);
3078 ASSERT(!transformFeedback->isPaused());
3079
Jamie Madill6c1f6712017-02-14 19:08:04 -05003080 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003081}
3082
3083bool Context::hasActiveTransformFeedback(GLuint program) const
3084{
3085 for (auto pair : mTransformFeedbackMap)
3086 {
3087 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
3088 {
3089 return true;
3090 }
3091 }
3092 return false;
3093}
3094
Geoff Lang33f11fb2018-05-07 13:42:47 -04003095Extensions Context::generateSupportedExtensions() const
Geoff Langb0f917f2017-12-05 13:41:54 -05003096{
3097 Extensions supportedExtensions = mImplementation->getNativeExtensions();
3098
jchen1082af6202018-06-22 10:59:52 +08003099 // Explicitly enable GL_KHR_parallel_shader_compile
3100 supportedExtensions.parallelShaderCompile = true;
3101
Geoff Langb0f917f2017-12-05 13:41:54 -05003102 if (getClientVersion() < ES_2_0)
3103 {
3104 // Default extensions for GLES1
3105 supportedExtensions.pointSizeArray = true;
Lingfeng Yang23dc90b2018-04-23 09:01:49 -07003106 supportedExtensions.textureCubeMap = true;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003107 supportedExtensions.pointSprite = true;
jchen1082af6202018-06-22 10:59:52 +08003108 supportedExtensions.parallelShaderCompile = false;
Geoff Langb0f917f2017-12-05 13:41:54 -05003109 }
3110
3111 if (getClientVersion() < ES_3_0)
3112 {
3113 // Disable ES3+ extensions
3114 supportedExtensions.colorBufferFloat = false;
3115 supportedExtensions.eglImageExternalEssl3 = false;
3116 supportedExtensions.textureNorm16 = false;
3117 supportedExtensions.multiview = false;
3118 supportedExtensions.maxViews = 1u;
3119 }
3120
3121 if (getClientVersion() < ES_3_1)
3122 {
3123 // Disable ES3.1+ extensions
3124 supportedExtensions.geometryShader = false;
3125 }
3126
3127 if (getClientVersion() > ES_2_0)
3128 {
3129 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
3130 // supportedExtensions.sRGB = false;
3131 }
3132
3133 // Some extensions are always available because they are implemented in the GL layer.
3134 supportedExtensions.bindUniformLocation = true;
3135 supportedExtensions.vertexArrayObject = true;
3136 supportedExtensions.bindGeneratesResource = true;
3137 supportedExtensions.clientArrays = true;
3138 supportedExtensions.requestExtension = true;
3139
3140 // Enable the no error extension if the context was created with the flag.
3141 supportedExtensions.noError = mSkipValidation;
3142
3143 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Geoff Lang33f11fb2018-05-07 13:42:47 -04003144 supportedExtensions.surfacelessContext = mSurfacelessSupported;
Geoff Langb0f917f2017-12-05 13:41:54 -05003145
3146 // Explicitly enable GL_KHR_debug
3147 supportedExtensions.debug = true;
3148 supportedExtensions.maxDebugMessageLength = 1024;
3149 supportedExtensions.maxDebugLoggedMessages = 1024;
3150 supportedExtensions.maxDebugGroupStackDepth = 1024;
3151 supportedExtensions.maxLabelLength = 1024;
3152
3153 // Explicitly enable GL_ANGLE_robust_client_memory
3154 supportedExtensions.robustClientMemory = true;
3155
3156 // Determine robust resource init availability from EGL.
Geoff Lang33f11fb2018-05-07 13:42:47 -04003157 supportedExtensions.robustResourceInitialization = mGLState.isRobustResourceInitEnabled();
Geoff Langb0f917f2017-12-05 13:41:54 -05003158
3159 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
3160 // supports it.
3161 supportedExtensions.robustBufferAccessBehavior =
3162 mRobustAccess && supportedExtensions.robustBufferAccessBehavior;
3163
3164 // Enable the cache control query unconditionally.
3165 supportedExtensions.programCacheControl = true;
3166
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003167 // Enable EGL_ANGLE_explicit_context subextensions
Geoff Lang33f11fb2018-05-07 13:42:47 -04003168 if (mExplicitContextAvailable)
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003169 {
3170 // GL_ANGLE_explicit_context_gles1
3171 supportedExtensions.explicitContextGles1 = true;
3172 // GL_ANGLE_explicit_context
3173 supportedExtensions.explicitContext = true;
3174 }
3175
Geoff Langb0f917f2017-12-05 13:41:54 -05003176 return supportedExtensions;
3177}
3178
Geoff Lang33f11fb2018-05-07 13:42:47 -04003179void Context::initCaps()
Geoff Lang493daf52014-07-03 13:38:44 -04003180{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04003181 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04003182
Geoff Lang33f11fb2018-05-07 13:42:47 -04003183 mSupportedExtensions = generateSupportedExtensions();
3184 mExtensions = mSupportedExtensions;
Lingfeng Yang01074432018-04-16 10:19:51 -07003185
3186 mLimitations = mImplementation->getNativeLimitations();
3187
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003188 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
3189 if (getClientVersion() < Version(2, 0))
3190 {
3191 mCaps.maxMultitextureUnits = 4;
3192 mCaps.maxClipPlanes = 6;
3193 mCaps.maxLights = 8;
Lingfeng Yange547aac2018-04-05 09:39:20 -07003194 mCaps.maxModelviewMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3195 mCaps.maxProjectionMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3196 mCaps.maxTextureMatrixStackDepth = Caps::GlobalMatrixStackDepth;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003197 mCaps.minSmoothPointSize = 1.0f;
3198 mCaps.maxSmoothPointSize = 1.0f;
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003199 }
3200
Luc Ferronad2ae932018-06-11 15:31:17 -04003201 // Apply/Verify implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04003202 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003203
Luc Ferronad2ae932018-06-11 15:31:17 -04003204 ASSERT(mCaps.minAliasedPointSize >= 1.0f);
3205
Jamie Madill0f80ed82017-09-19 00:24:56 -04003206 if (getClientVersion() < ES_3_1)
3207 {
3208 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
3209 }
3210 else
3211 {
3212 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
3213 }
Geoff Lang301d1612014-07-09 10:34:37 -04003214
Jiawei Shao54aafe52018-04-27 14:54:57 +08003215 LimitCap(&mCaps.maxShaderUniformBlocks[ShaderType::Vertex],
3216 IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
Jamie Madill0f80ed82017-09-19 00:24:56 -04003217 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3218 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3219
3220 // Limit textures as well, so we can use fast bitsets with texture bindings.
3221 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
Jiawei Shao54aafe52018-04-27 14:54:57 +08003222 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Vertex],
3223 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
3224 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Fragment],
3225 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04003226
Jiawei Shaodb342272017-09-27 10:21:45 +08003227 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
3228
Geoff Langc287ea62016-09-16 14:46:51 -04003229 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05003230 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04003231 for (const auto &extensionInfo : GetExtensionInfoMap())
3232 {
Geoff Lang0ab41fa2018-03-14 11:03:30 -04003233 // If the user has requested that extensions start disabled and they are requestable,
3234 // disable them.
3235 if (!mExtensionsEnabled && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04003236 {
3237 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
3238 }
3239 }
3240
3241 // Generate texture caps
3242 updateCaps();
3243}
3244
3245void Context::updateCaps()
3246{
Geoff Lang900013c2014-07-07 11:32:19 -04003247 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04003248 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04003249
Jamie Madill7b62cf92017-11-02 15:20:49 -04003250 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04003251 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04003252 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04003253 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003254
Geoff Lang0d8b7242015-09-09 14:56:53 -04003255 // Update the format caps based on the client version and extensions.
3256 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
3257 // ES3.
3258 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003259 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04003260 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003261 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Yuly Novikovf15f8862018-06-04 18:59:41 -04003262 formatCaps.textureAttachment =
3263 formatCaps.textureAttachment &&
3264 formatInfo.textureAttachmentSupport(getClientVersion(), mExtensions);
3265 formatCaps.renderbuffer = formatCaps.renderbuffer &&
3266 formatInfo.renderbufferSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04003267
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003268 // OpenGL ES does not support multisampling with non-rendererable formats
3269 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Yuly Novikovf15f8862018-06-04 18:59:41 -04003270 if (!formatCaps.renderbuffer ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003271 (getClientVersion() < ES_3_1 &&
3272 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04003273 {
Geoff Langd87878e2014-09-19 15:42:59 -04003274 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04003275 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03003276 else
3277 {
3278 // We may have limited the max samples for some required renderbuffer formats due to
3279 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
3280 GLuint formatMaxSamples = formatCaps.getMaxSamples();
3281
3282 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
3283 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
3284 // exception of signed and unsigned integer formats."
3285 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
3286 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
3287 {
3288 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
3289 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
3290 }
3291
3292 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
3293 if (getClientVersion() >= ES_3_1)
3294 {
3295 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
3296 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
3297 // the exception that the signed and unsigned integer formats are required only to
3298 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
3299 // multisamples, which must be at least one."
3300 if (formatInfo.componentType == GL_INT ||
3301 formatInfo.componentType == GL_UNSIGNED_INT)
3302 {
3303 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
3304 }
3305
3306 // GLES 3.1 section 19.3.1.
3307 if (formatCaps.texturable)
3308 {
3309 if (formatInfo.depthBits > 0)
3310 {
3311 mCaps.maxDepthTextureSamples =
3312 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
3313 }
3314 else if (formatInfo.redBits > 0)
3315 {
3316 mCaps.maxColorTextureSamples =
3317 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
3318 }
3319 }
3320 }
3321 }
Geoff Langd87878e2014-09-19 15:42:59 -04003322
3323 if (formatCaps.texturable && formatInfo.compressed)
3324 {
Geoff Langca271392017-04-05 12:30:00 -04003325 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003326 }
3327
Geoff Langca271392017-04-05 12:30:00 -04003328 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04003329 }
Jamie Madill32447362017-06-28 14:53:52 -04003330
3331 // If program binary is disabled, blank out the memory cache pointer.
Geoff Langb0f917f2017-12-05 13:41:54 -05003332 if (!mSupportedExtensions.getProgramBinary)
Jamie Madill32447362017-06-28 14:53:52 -04003333 {
3334 mMemoryProgramCache = nullptr;
3335 }
Corentin Walleze4477002017-12-01 14:39:58 -05003336
3337 // Compute which buffer types are allowed
3338 mValidBufferBindings.reset();
3339 mValidBufferBindings.set(BufferBinding::ElementArray);
3340 mValidBufferBindings.set(BufferBinding::Array);
3341
3342 if (mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
3343 {
3344 mValidBufferBindings.set(BufferBinding::PixelPack);
3345 mValidBufferBindings.set(BufferBinding::PixelUnpack);
3346 }
3347
3348 if (getClientVersion() >= ES_3_0)
3349 {
3350 mValidBufferBindings.set(BufferBinding::CopyRead);
3351 mValidBufferBindings.set(BufferBinding::CopyWrite);
3352 mValidBufferBindings.set(BufferBinding::TransformFeedback);
3353 mValidBufferBindings.set(BufferBinding::Uniform);
3354 }
3355
3356 if (getClientVersion() >= ES_3_1)
3357 {
3358 mValidBufferBindings.set(BufferBinding::AtomicCounter);
3359 mValidBufferBindings.set(BufferBinding::ShaderStorage);
3360 mValidBufferBindings.set(BufferBinding::DrawIndirect);
3361 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
3362 }
Geoff Lang493daf52014-07-03 13:38:44 -04003363}
3364
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003365void Context::initWorkarounds()
3366{
Jamie Madill761b02c2017-06-23 16:27:06 -04003367 // Apply back-end workarounds.
3368 mImplementation->applyNativeWorkarounds(&mWorkarounds);
3369
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003370 // Lose the context upon out of memory error if the application is
3371 // expecting to watch for those events.
3372 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
3373}
3374
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06003375// Return true if the draw is a no-op, else return false.
3376// A no-op draw occurs if the count of vertices is less than the minimum required to
3377// have a valid primitive for this mode (0 for points, 0-1 for lines, 0-2 for tris).
3378bool Context::noopDraw(PrimitiveMode mode, GLsizei count)
3379{
3380 return count < kMinimumPrimitiveCounts[mode];
3381}
3382
3383bool Context::noopDrawInstanced(PrimitiveMode mode, GLsizei count, GLsizei instanceCount)
3384{
3385 return (instanceCount == 0) || noopDraw(mode, count);
3386}
3387
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003388Error Context::prepareForDraw(PrimitiveMode mode)
Jamie Madill05b35b22017-10-03 09:01:44 -04003389{
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003390 if (mGLES1Renderer)
3391 {
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003392 ANGLE_TRY(mGLES1Renderer->prepareForDraw(mode, this, &mGLState));
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003393 }
3394
Geoff Langa8cb2872018-03-09 16:09:40 -05003395 ANGLE_TRY(syncDirtyObjects());
Jamie Madilla59fc192017-11-02 12:57:58 -04003396
3397 if (isRobustResourceInitEnabled())
3398 {
3399 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
3400 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
3401 }
3402
Geoff Langa8cb2872018-03-09 16:09:40 -05003403 ANGLE_TRY(syncDirtyBits());
Geoff Langd4fff502017-09-22 11:28:28 -04003404 return NoError();
3405}
3406
3407Error Context::prepareForClear(GLbitfield mask)
3408{
Geoff Langa8cb2872018-03-09 16:09:40 -05003409 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003410 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearAttachmentsInitialized(this, mask));
Geoff Langa8cb2872018-03-09 16:09:40 -05003411 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04003412 return NoError();
3413}
3414
3415Error Context::prepareForClearBuffer(GLenum buffer, GLint drawbuffer)
3416{
Geoff Langa8cb2872018-03-09 16:09:40 -05003417 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003418 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearBufferAttachmentsInitialized(this, buffer,
3419 drawbuffer));
Geoff Langa8cb2872018-03-09 16:09:40 -05003420 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill05b35b22017-10-03 09:01:44 -04003421 return NoError();
3422}
3423
Geoff Langa8cb2872018-03-09 16:09:40 -05003424Error Context::syncState()
Jamie Madill1b94d432015-08-07 13:23:23 -04003425{
Geoff Langa8cb2872018-03-09 16:09:40 -05003426 ANGLE_TRY(syncDirtyObjects());
3427 ANGLE_TRY(syncDirtyBits());
Jamie Madillbc918e72018-03-08 09:47:21 -05003428 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003429}
3430
Geoff Langa8cb2872018-03-09 16:09:40 -05003431Error Context::syncState(const State::DirtyBits &bitMask, const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04003432{
Geoff Langa8cb2872018-03-09 16:09:40 -05003433 ANGLE_TRY(syncDirtyObjects(objectMask));
3434 ANGLE_TRY(syncDirtyBits(bitMask));
Geoff Langd4fff502017-09-22 11:28:28 -04003435 return NoError();
3436}
3437
Geoff Langa8cb2872018-03-09 16:09:40 -05003438Error Context::syncDirtyBits()
Geoff Langd4fff502017-09-22 11:28:28 -04003439{
3440 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
Jamie Madill189ad872018-07-09 13:32:37 -04003441 ANGLE_TRY(mImplementation->syncState(this, dirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04003442 mGLState.clearDirtyBits();
3443 return NoError();
3444}
3445
Geoff Langa8cb2872018-03-09 16:09:40 -05003446Error Context::syncDirtyBits(const State::DirtyBits &bitMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003447{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003448 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madill189ad872018-07-09 13:32:37 -04003449 ANGLE_TRY(mImplementation->syncState(this, dirtyBits));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003450 mGLState.clearDirtyBits(dirtyBits);
Jamie Madillbc918e72018-03-08 09:47:21 -05003451 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003452}
Jamie Madillc29968b2016-01-20 11:17:23 -05003453
Geoff Langa8cb2872018-03-09 16:09:40 -05003454Error Context::syncDirtyObjects()
Geoff Langd4fff502017-09-22 11:28:28 -04003455{
3456 return mGLState.syncDirtyObjects(this);
3457}
3458
Geoff Langa8cb2872018-03-09 16:09:40 -05003459Error Context::syncDirtyObjects(const State::DirtyObjects &objectMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003460{
3461 return mGLState.syncDirtyObjects(this, objectMask);
3462}
3463
Jamie Madillc29968b2016-01-20 11:17:23 -05003464void Context::blitFramebuffer(GLint srcX0,
3465 GLint srcY0,
3466 GLint srcX1,
3467 GLint srcY1,
3468 GLint dstX0,
3469 GLint dstY0,
3470 GLint dstX1,
3471 GLint dstY1,
3472 GLbitfield mask,
3473 GLenum filter)
3474{
Qin Jiajiaaef92162018-02-27 13:51:44 +08003475 if (mask == 0)
3476 {
3477 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
3478 // buffers are copied.
3479 return;
3480 }
3481
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003482 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003483 ASSERT(drawFramebuffer);
3484
3485 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
3486 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
3487
Jamie Madillbc918e72018-03-08 09:47:21 -05003488 ANGLE_CONTEXT_TRY(syncStateForBlit());
Jamie Madillc29968b2016-01-20 11:17:23 -05003489
Jamie Madillc564c072017-06-01 12:45:42 -04003490 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003491}
Jamie Madillc29968b2016-01-20 11:17:23 -05003492
3493void Context::clear(GLbitfield mask)
3494{
Geoff Langd4fff502017-09-22 11:28:28 -04003495 ANGLE_CONTEXT_TRY(prepareForClear(mask));
3496 ANGLE_CONTEXT_TRY(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05003497}
3498
3499void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
3500{
Geoff Langd4fff502017-09-22 11:28:28 -04003501 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3502 ANGLE_CONTEXT_TRY(
3503 mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003504}
3505
3506void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3507{
Geoff Langd4fff502017-09-22 11:28:28 -04003508 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3509 ANGLE_CONTEXT_TRY(
3510 mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003511}
3512
3513void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3514{
Geoff Langd4fff502017-09-22 11:28:28 -04003515 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3516 ANGLE_CONTEXT_TRY(
3517 mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003518}
3519
3520void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3521{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003522 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003523 ASSERT(framebufferObject);
3524
3525 // If a buffer is not present, the clear has no effect
3526 if (framebufferObject->getDepthbuffer() == nullptr &&
3527 framebufferObject->getStencilbuffer() == nullptr)
3528 {
3529 return;
3530 }
3531
Geoff Langd4fff502017-09-22 11:28:28 -04003532 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3533 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003534}
3535
3536void Context::readPixels(GLint x,
3537 GLint y,
3538 GLsizei width,
3539 GLsizei height,
3540 GLenum format,
3541 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003542 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003543{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003544 if (width == 0 || height == 0)
3545 {
3546 return;
3547 }
3548
Jamie Madillbc918e72018-03-08 09:47:21 -05003549 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003550
Jamie Madillb6664922017-07-25 12:55:04 -04003551 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3552 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003553
3554 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04003555 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003556}
3557
Brandon Jones59770802018-04-02 13:18:42 -07003558void Context::readPixelsRobust(GLint x,
3559 GLint y,
3560 GLsizei width,
3561 GLsizei height,
3562 GLenum format,
3563 GLenum type,
3564 GLsizei bufSize,
3565 GLsizei *length,
3566 GLsizei *columns,
3567 GLsizei *rows,
3568 void *pixels)
3569{
3570 readPixels(x, y, width, height, format, type, pixels);
3571}
3572
3573void Context::readnPixelsRobust(GLint x,
3574 GLint y,
3575 GLsizei width,
3576 GLsizei height,
3577 GLenum format,
3578 GLenum type,
3579 GLsizei bufSize,
3580 GLsizei *length,
3581 GLsizei *columns,
3582 GLsizei *rows,
3583 void *data)
3584{
3585 readPixels(x, y, width, height, format, type, data);
3586}
3587
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003588void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003589 GLint level,
3590 GLenum internalformat,
3591 GLint x,
3592 GLint y,
3593 GLsizei width,
3594 GLsizei height,
3595 GLint border)
3596{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003597 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003598 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003599
Jamie Madillc29968b2016-01-20 11:17:23 -05003600 Rectangle sourceArea(x, y, width, height);
3601
Jamie Madill05b35b22017-10-03 09:01:44 -04003602 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003603 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003604 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003605}
3606
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003607void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003608 GLint level,
3609 GLint xoffset,
3610 GLint yoffset,
3611 GLint x,
3612 GLint y,
3613 GLsizei width,
3614 GLsizei height)
3615{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003616 if (width == 0 || height == 0)
3617 {
3618 return;
3619 }
3620
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003621 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003622 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003623
Jamie Madillc29968b2016-01-20 11:17:23 -05003624 Offset destOffset(xoffset, yoffset, 0);
3625 Rectangle sourceArea(x, y, width, height);
3626
Jamie Madill05b35b22017-10-03 09:01:44 -04003627 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003628 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003629 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003630}
3631
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003632void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003633 GLint level,
3634 GLint xoffset,
3635 GLint yoffset,
3636 GLint zoffset,
3637 GLint x,
3638 GLint y,
3639 GLsizei width,
3640 GLsizei height)
3641{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003642 if (width == 0 || height == 0)
3643 {
3644 return;
3645 }
3646
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003647 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003648 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003649
Jamie Madillc29968b2016-01-20 11:17:23 -05003650 Offset destOffset(xoffset, yoffset, zoffset);
3651 Rectangle sourceArea(x, y, width, height);
3652
Jamie Madill05b35b22017-10-03 09:01:44 -04003653 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3654 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003655 handleError(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level, destOffset,
3656 sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003657}
3658
3659void Context::framebufferTexture2D(GLenum target,
3660 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003661 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003662 GLuint texture,
3663 GLint level)
3664{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003665 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003666 ASSERT(framebuffer);
3667
3668 if (texture != 0)
3669 {
3670 Texture *textureObj = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003671 ImageIndex index = ImageIndex::MakeFromTarget(textarget, level);
Jamie Madilla02315b2017-02-23 14:14:47 -05003672 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003673 }
3674 else
3675 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003676 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003677 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003678
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003679 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003680}
3681
3682void Context::framebufferRenderbuffer(GLenum target,
3683 GLenum attachment,
3684 GLenum renderbuffertarget,
3685 GLuint renderbuffer)
3686{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003687 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003688 ASSERT(framebuffer);
3689
3690 if (renderbuffer != 0)
3691 {
3692 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003693
Jamie Madillcc129372018-04-12 09:13:18 -04003694 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003695 renderbufferObject);
3696 }
3697 else
3698 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003699 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003700 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003701
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003702 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003703}
3704
3705void Context::framebufferTextureLayer(GLenum target,
3706 GLenum attachment,
3707 GLuint texture,
3708 GLint level,
3709 GLint layer)
3710{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003711 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003712 ASSERT(framebuffer);
3713
3714 if (texture != 0)
3715 {
3716 Texture *textureObject = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003717 ImageIndex index = ImageIndex::MakeFromType(textureObject->getType(), level, layer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003718 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003719 }
3720 else
3721 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003722 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003723 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003724
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003725 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003726}
3727
Brandon Jones59770802018-04-02 13:18:42 -07003728void Context::framebufferTextureMultiviewLayered(GLenum target,
3729 GLenum attachment,
3730 GLuint texture,
3731 GLint level,
3732 GLint baseViewIndex,
3733 GLsizei numViews)
Martin Radev137032d2017-07-13 10:11:12 +03003734{
Martin Radev82ef7742017-08-08 17:44:58 +03003735 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3736 ASSERT(framebuffer);
3737
3738 if (texture != 0)
3739 {
3740 Texture *textureObj = getTexture(texture);
3741
Martin Radev18b75ba2017-08-15 15:50:40 +03003742 ImageIndex index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
Martin Radev82ef7742017-08-08 17:44:58 +03003743 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3744 numViews, baseViewIndex);
3745 }
3746 else
3747 {
3748 framebuffer->resetAttachment(this, attachment);
3749 }
3750
3751 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003752}
3753
Brandon Jones59770802018-04-02 13:18:42 -07003754void Context::framebufferTextureMultiviewSideBySide(GLenum target,
3755 GLenum attachment,
3756 GLuint texture,
3757 GLint level,
3758 GLsizei numViews,
3759 const GLint *viewportOffsets)
Martin Radev137032d2017-07-13 10:11:12 +03003760{
Martin Radev5dae57b2017-07-14 16:15:55 +03003761 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3762 ASSERT(framebuffer);
3763
3764 if (texture != 0)
3765 {
3766 Texture *textureObj = getTexture(texture);
3767
3768 ImageIndex index = ImageIndex::Make2D(level);
3769 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3770 textureObj, numViews, viewportOffsets);
3771 }
3772 else
3773 {
3774 framebuffer->resetAttachment(this, attachment);
3775 }
3776
3777 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003778}
3779
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003780void Context::framebufferTexture(GLenum target, GLenum attachment, GLuint texture, GLint level)
3781{
Jiawei Shaoa8802472018-05-28 11:17:47 +08003782 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3783 ASSERT(framebuffer);
3784
3785 if (texture != 0)
3786 {
3787 Texture *textureObj = getTexture(texture);
3788
3789 ImageIndex index = ImageIndex::MakeFromType(
3790 textureObj->getType(), level, ImageIndex::kEntireLevel, ImageIndex::kEntireLevel);
3791 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
3792 }
3793 else
3794 {
3795 framebuffer->resetAttachment(this, attachment);
3796 }
3797
3798 mGLState.setObjectDirty(target);
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003799}
3800
Jamie Madillc29968b2016-01-20 11:17:23 -05003801void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3802{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003803 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003804 ASSERT(framebuffer);
3805 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003806 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003807}
3808
3809void Context::readBuffer(GLenum mode)
3810{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003811 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003812 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003813 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003814}
3815
3816void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3817{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003818 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003819 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003820
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003821 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003822 ASSERT(framebuffer);
3823
3824 // The specification isn't clear what should be done when the framebuffer isn't complete.
3825 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003826 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003827}
3828
3829void Context::invalidateFramebuffer(GLenum target,
3830 GLsizei numAttachments,
3831 const GLenum *attachments)
3832{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003833 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003834 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003835
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003836 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003837 ASSERT(framebuffer);
3838
Jamie Madill427064d2018-04-13 16:20:34 -04003839 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003840 {
Jamie Madill437fa652016-05-03 15:13:24 -04003841 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003842 }
Jamie Madill437fa652016-05-03 15:13:24 -04003843
Jamie Madill4928b7c2017-06-20 12:57:39 -04003844 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003845}
3846
3847void Context::invalidateSubFramebuffer(GLenum target,
3848 GLsizei numAttachments,
3849 const GLenum *attachments,
3850 GLint x,
3851 GLint y,
3852 GLsizei width,
3853 GLsizei height)
3854{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003855 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003856 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003857
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003858 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003859 ASSERT(framebuffer);
3860
Jamie Madill427064d2018-04-13 16:20:34 -04003861 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003862 {
Jamie Madill437fa652016-05-03 15:13:24 -04003863 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003864 }
Jamie Madill437fa652016-05-03 15:13:24 -04003865
3866 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003867 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003868}
3869
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003870void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003871 GLint level,
3872 GLint internalformat,
3873 GLsizei width,
3874 GLsizei height,
3875 GLint border,
3876 GLenum format,
3877 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003878 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003879{
Jamie Madillbc918e72018-03-08 09:47:21 -05003880 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003881
3882 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003883 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003884 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003885 size, format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003886}
3887
Brandon Jones59770802018-04-02 13:18:42 -07003888void Context::texImage2DRobust(TextureTarget target,
3889 GLint level,
3890 GLint internalformat,
3891 GLsizei width,
3892 GLsizei height,
3893 GLint border,
3894 GLenum format,
3895 GLenum type,
3896 GLsizei bufSize,
3897 const void *pixels)
3898{
3899 texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
3900}
3901
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003902void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003903 GLint level,
3904 GLint internalformat,
3905 GLsizei width,
3906 GLsizei height,
3907 GLsizei depth,
3908 GLint border,
3909 GLenum format,
3910 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003911 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003912{
Jamie Madillbc918e72018-03-08 09:47:21 -05003913 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003914
3915 Extents size(width, height, depth);
3916 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003917 handleError(texture->setImage(this, mGLState.getUnpackState(),
3918 NonCubeTextureTypeToTarget(target), level, internalformat, size,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003919 format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003920}
3921
Brandon Jones59770802018-04-02 13:18:42 -07003922void Context::texImage3DRobust(TextureType target,
3923 GLint level,
3924 GLint internalformat,
3925 GLsizei width,
3926 GLsizei height,
3927 GLsizei depth,
3928 GLint border,
3929 GLenum format,
3930 GLenum type,
3931 GLsizei bufSize,
3932 const void *pixels)
3933{
3934 texImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels);
3935}
3936
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003937void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003938 GLint level,
3939 GLint xoffset,
3940 GLint yoffset,
3941 GLsizei width,
3942 GLsizei height,
3943 GLenum format,
3944 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003945 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003946{
3947 // Zero sized uploads are valid but no-ops
3948 if (width == 0 || height == 0)
3949 {
3950 return;
3951 }
3952
Jamie Madillbc918e72018-03-08 09:47:21 -05003953 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003954
3955 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003956 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003957 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003958 type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003959}
3960
Brandon Jones59770802018-04-02 13:18:42 -07003961void Context::texSubImage2DRobust(TextureTarget target,
3962 GLint level,
3963 GLint xoffset,
3964 GLint yoffset,
3965 GLsizei width,
3966 GLsizei height,
3967 GLenum format,
3968 GLenum type,
3969 GLsizei bufSize,
3970 const void *pixels)
3971{
3972 texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
3973}
3974
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003975void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003976 GLint level,
3977 GLint xoffset,
3978 GLint yoffset,
3979 GLint zoffset,
3980 GLsizei width,
3981 GLsizei height,
3982 GLsizei depth,
3983 GLenum format,
3984 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003985 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003986{
3987 // Zero sized uploads are valid but no-ops
3988 if (width == 0 || height == 0 || depth == 0)
3989 {
3990 return;
3991 }
3992
Jamie Madillbc918e72018-03-08 09:47:21 -05003993 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003994
3995 Box area(xoffset, yoffset, zoffset, width, height, depth);
3996 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003997 handleError(texture->setSubImage(this, mGLState.getUnpackState(),
3998 NonCubeTextureTypeToTarget(target), level, area, format, type,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003999 static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05004000}
4001
Brandon Jones59770802018-04-02 13:18:42 -07004002void Context::texSubImage3DRobust(TextureType target,
4003 GLint level,
4004 GLint xoffset,
4005 GLint yoffset,
4006 GLint zoffset,
4007 GLsizei width,
4008 GLsizei height,
4009 GLsizei depth,
4010 GLenum format,
4011 GLenum type,
4012 GLsizei bufSize,
4013 const void *pixels)
4014{
4015 texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type,
4016 pixels);
4017}
4018
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004019void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004020 GLint level,
4021 GLenum internalformat,
4022 GLsizei width,
4023 GLsizei height,
4024 GLint border,
4025 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004026 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004027{
Jamie Madillbc918e72018-03-08 09:47:21 -05004028 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004029
4030 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004031 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05004032 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
4033 internalformat, size, imageSize,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004034 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004035}
4036
Brandon Jones59770802018-04-02 13:18:42 -07004037void Context::compressedTexImage2DRobust(TextureTarget target,
4038 GLint level,
4039 GLenum internalformat,
4040 GLsizei width,
4041 GLsizei height,
4042 GLint border,
4043 GLsizei imageSize,
4044 GLsizei dataSize,
4045 const GLvoid *data)
4046{
4047 compressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
4048}
4049
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004050void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004051 GLint level,
4052 GLenum internalformat,
4053 GLsizei width,
4054 GLsizei height,
4055 GLsizei depth,
4056 GLint border,
4057 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004058 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004059{
Jamie Madillbc918e72018-03-08 09:47:21 -05004060 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004061
4062 Extents size(width, height, depth);
4063 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004064 handleError(texture->setCompressedImage(
4065 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004066 size, imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004067}
4068
Brandon Jones59770802018-04-02 13:18:42 -07004069void Context::compressedTexImage3DRobust(TextureType target,
4070 GLint level,
4071 GLenum internalformat,
4072 GLsizei width,
4073 GLsizei height,
4074 GLsizei depth,
4075 GLint border,
4076 GLsizei imageSize,
4077 GLsizei dataSize,
4078 const GLvoid *data)
4079{
4080 compressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize,
4081 data);
4082}
4083
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004084void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004085 GLint level,
4086 GLint xoffset,
4087 GLint yoffset,
4088 GLsizei width,
4089 GLsizei height,
4090 GLenum format,
4091 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004092 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004093{
Jamie Madillbc918e72018-03-08 09:47:21 -05004094 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004095
4096 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004097 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05004098 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
4099 format, imageSize,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004100 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004101}
4102
Brandon Jones59770802018-04-02 13:18:42 -07004103void Context::compressedTexSubImage2DRobust(TextureTarget target,
4104 GLint level,
4105 GLint xoffset,
4106 GLint yoffset,
4107 GLsizei width,
4108 GLsizei height,
4109 GLenum format,
4110 GLsizei imageSize,
4111 GLsizei dataSize,
4112 const GLvoid *data)
4113{
4114 compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize,
4115 data);
4116}
4117
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004118void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004119 GLint level,
4120 GLint xoffset,
4121 GLint yoffset,
4122 GLint zoffset,
4123 GLsizei width,
4124 GLsizei height,
4125 GLsizei depth,
4126 GLenum format,
4127 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004128 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004129{
4130 // Zero sized uploads are valid but no-ops
4131 if (width == 0 || height == 0)
4132 {
4133 return;
4134 }
4135
Jamie Madillbc918e72018-03-08 09:47:21 -05004136 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004137
4138 Box area(xoffset, yoffset, zoffset, width, height, depth);
4139 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004140 handleError(texture->setCompressedSubImage(
4141 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004142 imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004143}
4144
Brandon Jones59770802018-04-02 13:18:42 -07004145void Context::compressedTexSubImage3DRobust(TextureType target,
4146 GLint level,
4147 GLint xoffset,
4148 GLint yoffset,
4149 GLint zoffset,
4150 GLsizei width,
4151 GLsizei height,
4152 GLsizei depth,
4153 GLenum format,
4154 GLsizei imageSize,
4155 GLsizei dataSize,
4156 const GLvoid *data)
4157{
4158 compressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format,
4159 imageSize, data);
4160}
4161
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004162void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004163{
4164 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05004165 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004166}
4167
Jamie Madill007530e2017-12-28 14:27:04 -05004168void Context::copyTexture(GLuint sourceId,
4169 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004170 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004171 GLuint destId,
4172 GLint destLevel,
4173 GLint internalFormat,
4174 GLenum destType,
4175 GLboolean unpackFlipY,
4176 GLboolean unpackPremultiplyAlpha,
4177 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004178{
Jamie Madillbc918e72018-03-08 09:47:21 -05004179 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004180
4181 gl::Texture *sourceTexture = getTexture(sourceId);
4182 gl::Texture *destTexture = getTexture(destId);
Geoff Lang92019432017-11-20 13:09:34 -05004183 handleError(destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType,
4184 sourceLevel, ConvertToBool(unpackFlipY),
4185 ConvertToBool(unpackPremultiplyAlpha),
4186 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004187}
4188
Jamie Madill007530e2017-12-28 14:27:04 -05004189void Context::copySubTexture(GLuint sourceId,
4190 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004191 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004192 GLuint destId,
4193 GLint destLevel,
4194 GLint xoffset,
4195 GLint yoffset,
4196 GLint x,
4197 GLint y,
4198 GLsizei width,
4199 GLsizei height,
4200 GLboolean unpackFlipY,
4201 GLboolean unpackPremultiplyAlpha,
4202 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004203{
4204 // Zero sized copies are valid but no-ops
4205 if (width == 0 || height == 0)
4206 {
4207 return;
4208 }
4209
Jamie Madillbc918e72018-03-08 09:47:21 -05004210 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004211
4212 gl::Texture *sourceTexture = getTexture(sourceId);
4213 gl::Texture *destTexture = getTexture(destId);
4214 Offset offset(xoffset, yoffset, 0);
4215 Rectangle area(x, y, width, height);
Geoff Lang92019432017-11-20 13:09:34 -05004216 handleError(destTexture->copySubTexture(this, destTarget, destLevel, offset, sourceLevel, area,
4217 ConvertToBool(unpackFlipY),
4218 ConvertToBool(unpackPremultiplyAlpha),
4219 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004220}
4221
Jamie Madill007530e2017-12-28 14:27:04 -05004222void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07004223{
Jamie Madillbc918e72018-03-08 09:47:21 -05004224 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07004225
4226 gl::Texture *sourceTexture = getTexture(sourceId);
4227 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05004228 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07004229}
4230
Corentin Wallez336129f2017-10-17 15:55:40 -04004231void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03004232{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004233 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004234 ASSERT(buffer);
4235
Geoff Lang496c02d2016-10-20 11:38:11 -07004236 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03004237}
4238
Brandon Jones59770802018-04-02 13:18:42 -07004239void Context::getBufferPointervRobust(BufferBinding target,
4240 GLenum pname,
4241 GLsizei bufSize,
4242 GLsizei *length,
4243 void **params)
4244{
4245 getBufferPointerv(target, pname, params);
4246}
4247
Corentin Wallez336129f2017-10-17 15:55:40 -04004248void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004249{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004250 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004251 ASSERT(buffer);
4252
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004253 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004254 if (error.isError())
4255 {
Jamie Madill437fa652016-05-03 15:13:24 -04004256 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004257 return nullptr;
4258 }
4259
4260 return buffer->getMapPointer();
4261}
4262
Corentin Wallez336129f2017-10-17 15:55:40 -04004263GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03004264{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004265 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004266 ASSERT(buffer);
4267
4268 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004269 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03004270 if (error.isError())
4271 {
Jamie Madill437fa652016-05-03 15:13:24 -04004272 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004273 return GL_FALSE;
4274 }
4275
4276 return result;
4277}
4278
Corentin Wallez336129f2017-10-17 15:55:40 -04004279void *Context::mapBufferRange(BufferBinding target,
4280 GLintptr offset,
4281 GLsizeiptr length,
4282 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004283{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004284 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004285 ASSERT(buffer);
4286
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004287 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004288 if (error.isError())
4289 {
Jamie Madill437fa652016-05-03 15:13:24 -04004290 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004291 return nullptr;
4292 }
4293
4294 return buffer->getMapPointer();
4295}
4296
Corentin Wallez336129f2017-10-17 15:55:40 -04004297void Context::flushMappedBufferRange(BufferBinding /*target*/,
4298 GLintptr /*offset*/,
4299 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03004300{
4301 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
4302}
4303
Jamie Madillbc918e72018-03-08 09:47:21 -05004304Error Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004305{
Geoff Langa8cb2872018-03-09 16:09:40 -05004306 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004307}
4308
Jamie Madillbc918e72018-03-08 09:47:21 -05004309Error Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004310{
Geoff Langa8cb2872018-03-09 16:09:40 -05004311 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004312}
4313
Jamie Madillbc918e72018-03-08 09:47:21 -05004314Error Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004315{
Geoff Langa8cb2872018-03-09 16:09:40 -05004316 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004317}
4318
Jiajia Qin5451d532017-11-16 17:16:34 +08004319void Context::activeShaderProgram(GLuint pipeline, GLuint program)
4320{
4321 UNIMPLEMENTED();
4322}
4323
Jamie Madillc20ab272016-06-09 07:20:46 -07004324void Context::activeTexture(GLenum texture)
4325{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004326 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004327}
4328
Jamie Madill876429b2017-04-20 15:46:24 -04004329void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004330{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004331 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004332}
4333
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004334void Context::blendEquation(GLenum mode)
4335{
4336 mGLState.setBlendEquation(mode, mode);
4337}
4338
Jamie Madillc20ab272016-06-09 07:20:46 -07004339void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
4340{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004341 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004342}
4343
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004344void Context::blendFunc(GLenum sfactor, GLenum dfactor)
4345{
4346 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
4347}
4348
Jamie Madillc20ab272016-06-09 07:20:46 -07004349void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
4350{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004351 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004352}
4353
Jamie Madill876429b2017-04-20 15:46:24 -04004354void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004355{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004356 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004357}
4358
Jamie Madill876429b2017-04-20 15:46:24 -04004359void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07004360{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004361 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07004362}
4363
4364void Context::clearStencil(GLint s)
4365{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004366 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07004367}
4368
4369void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
4370{
Geoff Lang92019432017-11-20 13:09:34 -05004371 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
4372 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004373}
4374
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004375void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07004376{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004377 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004378}
4379
4380void Context::depthFunc(GLenum func)
4381{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004382 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07004383}
4384
4385void Context::depthMask(GLboolean flag)
4386{
Geoff Lang92019432017-11-20 13:09:34 -05004387 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07004388}
4389
Jamie Madill876429b2017-04-20 15:46:24 -04004390void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07004391{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004392 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07004393}
4394
4395void Context::disable(GLenum cap)
4396{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004397 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07004398}
4399
4400void Context::disableVertexAttribArray(GLuint index)
4401{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004402 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07004403}
4404
4405void Context::enable(GLenum cap)
4406{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004407 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07004408}
4409
4410void Context::enableVertexAttribArray(GLuint index)
4411{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004412 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07004413}
4414
4415void Context::frontFace(GLenum mode)
4416{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004417 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004418}
4419
4420void Context::hint(GLenum target, GLenum mode)
4421{
4422 switch (target)
4423 {
4424 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004425 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004426 break;
4427
4428 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004429 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004430 break;
4431
4432 default:
4433 UNREACHABLE();
4434 return;
4435 }
4436}
4437
4438void Context::lineWidth(GLfloat width)
4439{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004440 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07004441}
4442
4443void Context::pixelStorei(GLenum pname, GLint param)
4444{
4445 switch (pname)
4446 {
4447 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004448 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004449 break;
4450
4451 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004452 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004453 break;
4454
4455 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004456 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004457 break;
4458
4459 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004460 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004461 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004462 break;
4463
4464 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03004465 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004466 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004467 break;
4468
4469 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03004470 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004471 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004472 break;
4473
4474 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004475 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004476 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004477 break;
4478
4479 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004480 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004481 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004482 break;
4483
4484 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004485 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004486 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004487 break;
4488
4489 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004490 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004491 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004492 break;
4493
4494 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004495 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004496 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004497 break;
4498
4499 default:
4500 UNREACHABLE();
4501 return;
4502 }
4503}
4504
4505void Context::polygonOffset(GLfloat factor, GLfloat units)
4506{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004507 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07004508}
4509
Jamie Madill876429b2017-04-20 15:46:24 -04004510void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07004511{
Geoff Lang92019432017-11-20 13:09:34 -05004512 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07004513}
4514
Jiawei Shaodb342272017-09-27 10:21:45 +08004515void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
4516{
4517 mGLState.setSampleMaskParams(maskNumber, mask);
4518}
4519
Jamie Madillc20ab272016-06-09 07:20:46 -07004520void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
4521{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004522 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004523}
4524
4525void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
4526{
4527 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4528 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004529 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004530 }
4531
4532 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4533 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004534 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004535 }
4536}
4537
4538void Context::stencilMaskSeparate(GLenum face, GLuint mask)
4539{
4540 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4541 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004542 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004543 }
4544
4545 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4546 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004547 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004548 }
4549}
4550
4551void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4552{
4553 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4554 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004555 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004556 }
4557
4558 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4559 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004560 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004561 }
4562}
4563
4564void Context::vertexAttrib1f(GLuint index, GLfloat x)
4565{
4566 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004567 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004568}
4569
4570void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
4571{
4572 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004573 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004574}
4575
4576void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4577{
4578 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004579 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004580}
4581
4582void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
4583{
4584 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004585 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004586}
4587
4588void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4589{
4590 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004591 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004592}
4593
4594void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
4595{
4596 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004597 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004598}
4599
4600void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4601{
4602 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004603 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004604}
4605
4606void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
4607{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004608 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07004609}
4610
4611void Context::vertexAttribPointer(GLuint index,
4612 GLint size,
4613 GLenum type,
4614 GLboolean normalized,
4615 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004616 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07004617{
Corentin Wallez336129f2017-10-17 15:55:40 -04004618 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05004619 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc20ab272016-06-09 07:20:46 -07004620}
4621
Shao80957d92017-02-20 21:25:59 +08004622void Context::vertexAttribFormat(GLuint attribIndex,
4623 GLint size,
4624 GLenum type,
4625 GLboolean normalized,
4626 GLuint relativeOffset)
4627{
Geoff Lang92019432017-11-20 13:09:34 -05004628 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08004629 relativeOffset);
4630}
4631
4632void Context::vertexAttribIFormat(GLuint attribIndex,
4633 GLint size,
4634 GLenum type,
4635 GLuint relativeOffset)
4636{
4637 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
4638}
4639
4640void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4641{
Shaodde78e82017-05-22 14:13:27 +08004642 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Shao80957d92017-02-20 21:25:59 +08004643}
4644
Jiajia Qin5451d532017-11-16 17:16:34 +08004645void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004646{
4647 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
4648}
4649
Jamie Madillc20ab272016-06-09 07:20:46 -07004650void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4651{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004652 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004653}
4654
4655void Context::vertexAttribIPointer(GLuint index,
4656 GLint size,
4657 GLenum type,
4658 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004659 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004660{
Corentin Wallez336129f2017-10-17 15:55:40 -04004661 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
4662 size, type, false, true, stride, pointer);
Jamie Madillc20ab272016-06-09 07:20:46 -07004663}
4664
4665void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4666{
4667 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004668 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004669}
4670
4671void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4672{
4673 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004674 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004675}
4676
4677void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4678{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004679 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004680}
4681
4682void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4683{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004684 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004685}
4686
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004687void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4688{
4689 const VertexAttribCurrentValueData &currentValues =
4690 getGLState().getVertexAttribCurrentValue(index);
4691 const VertexArray *vao = getGLState().getVertexArray();
4692 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4693 currentValues, pname, params);
4694}
4695
Brandon Jones59770802018-04-02 13:18:42 -07004696void Context::getVertexAttribivRobust(GLuint index,
4697 GLenum pname,
4698 GLsizei bufSize,
4699 GLsizei *length,
4700 GLint *params)
4701{
4702 getVertexAttribiv(index, pname, params);
4703}
4704
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004705void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4706{
4707 const VertexAttribCurrentValueData &currentValues =
4708 getGLState().getVertexAttribCurrentValue(index);
4709 const VertexArray *vao = getGLState().getVertexArray();
4710 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4711 currentValues, pname, params);
4712}
4713
Brandon Jones59770802018-04-02 13:18:42 -07004714void Context::getVertexAttribfvRobust(GLuint index,
4715 GLenum pname,
4716 GLsizei bufSize,
4717 GLsizei *length,
4718 GLfloat *params)
4719{
4720 getVertexAttribfv(index, pname, params);
4721}
4722
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004723void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4724{
4725 const VertexAttribCurrentValueData &currentValues =
4726 getGLState().getVertexAttribCurrentValue(index);
4727 const VertexArray *vao = getGLState().getVertexArray();
4728 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4729 currentValues, pname, params);
4730}
4731
Brandon Jones59770802018-04-02 13:18:42 -07004732void Context::getVertexAttribIivRobust(GLuint index,
4733 GLenum pname,
4734 GLsizei bufSize,
4735 GLsizei *length,
4736 GLint *params)
4737{
4738 getVertexAttribIiv(index, pname, params);
4739}
4740
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004741void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4742{
4743 const VertexAttribCurrentValueData &currentValues =
4744 getGLState().getVertexAttribCurrentValue(index);
4745 const VertexArray *vao = getGLState().getVertexArray();
4746 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4747 currentValues, pname, params);
4748}
4749
Brandon Jones59770802018-04-02 13:18:42 -07004750void Context::getVertexAttribIuivRobust(GLuint index,
4751 GLenum pname,
4752 GLsizei bufSize,
4753 GLsizei *length,
4754 GLuint *params)
4755{
4756 getVertexAttribIuiv(index, pname, params);
4757}
4758
Jamie Madill876429b2017-04-20 15:46:24 -04004759void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004760{
4761 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
4762 QueryVertexAttribPointerv(attrib, pname, pointer);
4763}
4764
Brandon Jones59770802018-04-02 13:18:42 -07004765void Context::getVertexAttribPointervRobust(GLuint index,
4766 GLenum pname,
4767 GLsizei bufSize,
4768 GLsizei *length,
4769 void **pointer)
4770{
4771 getVertexAttribPointerv(index, pname, pointer);
4772}
4773
Jamie Madillc20ab272016-06-09 07:20:46 -07004774void Context::debugMessageControl(GLenum source,
4775 GLenum type,
4776 GLenum severity,
4777 GLsizei count,
4778 const GLuint *ids,
4779 GLboolean enabled)
4780{
4781 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004782 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05004783 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004784}
4785
4786void Context::debugMessageInsert(GLenum source,
4787 GLenum type,
4788 GLuint id,
4789 GLenum severity,
4790 GLsizei length,
4791 const GLchar *buf)
4792{
4793 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004794 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004795}
4796
4797void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4798{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004799 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004800}
4801
4802GLuint Context::getDebugMessageLog(GLuint count,
4803 GLsizei bufSize,
4804 GLenum *sources,
4805 GLenum *types,
4806 GLuint *ids,
4807 GLenum *severities,
4808 GLsizei *lengths,
4809 GLchar *messageLog)
4810{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004811 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4812 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004813}
4814
4815void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4816{
4817 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004818 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05004819 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07004820}
4821
4822void Context::popDebugGroup()
4823{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004824 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05004825 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004826}
4827
Corentin Wallez336129f2017-10-17 15:55:40 -04004828void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004829{
4830 Buffer *buffer = mGLState.getTargetBuffer(target);
4831 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004832 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004833}
4834
Corentin Wallez336129f2017-10-17 15:55:40 -04004835void Context::bufferSubData(BufferBinding target,
4836 GLintptr offset,
4837 GLsizeiptr size,
4838 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004839{
4840 if (data == nullptr)
4841 {
4842 return;
4843 }
4844
4845 Buffer *buffer = mGLState.getTargetBuffer(target);
4846 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004847 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004848}
4849
Jamie Madillef300b12016-10-07 15:12:09 -04004850void Context::attachShader(GLuint program, GLuint shader)
4851{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05004852 Program *programObject = mState.mShaderPrograms->getProgram(program);
4853 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004854 ASSERT(programObject && shaderObject);
4855 programObject->attachShader(shaderObject);
4856}
4857
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004858const Workarounds &Context::getWorkarounds() const
4859{
4860 return mWorkarounds;
4861}
4862
Corentin Wallez336129f2017-10-17 15:55:40 -04004863void Context::copyBufferSubData(BufferBinding readTarget,
4864 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04004865 GLintptr readOffset,
4866 GLintptr writeOffset,
4867 GLsizeiptr size)
4868{
4869 // if size is zero, the copy is a successful no-op
4870 if (size == 0)
4871 {
4872 return;
4873 }
4874
4875 // TODO(jmadill): cache these.
4876 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4877 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4878
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004879 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004880}
4881
Jamie Madill01a80ee2016-11-07 12:06:18 -05004882void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4883{
4884 Program *programObject = getProgram(program);
4885 // TODO(jmadill): Re-use this from the validation if possible.
4886 ASSERT(programObject);
4887 programObject->bindAttributeLocation(index, name);
4888}
4889
Corentin Wallez336129f2017-10-17 15:55:40 -04004890void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004891{
Corentin Wallez336129f2017-10-17 15:55:40 -04004892 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4893 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004894}
4895
Corentin Wallez336129f2017-10-17 15:55:40 -04004896void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08004897{
4898 bindBufferRange(target, index, buffer, 0, 0);
4899}
4900
Corentin Wallez336129f2017-10-17 15:55:40 -04004901void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08004902 GLuint index,
4903 GLuint buffer,
4904 GLintptr offset,
4905 GLsizeiptr size)
4906{
Corentin Wallez336129f2017-10-17 15:55:40 -04004907 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4908 mGLState.setIndexedBufferBinding(this, target, index, bufferObject, offset, size);
Jiajia Qin6eafb042016-12-27 17:04:07 +08004909}
4910
Jamie Madill01a80ee2016-11-07 12:06:18 -05004911void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
4912{
4913 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4914 {
4915 bindReadFramebuffer(framebuffer);
4916 }
4917
4918 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4919 {
4920 bindDrawFramebuffer(framebuffer);
4921 }
4922}
4923
4924void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4925{
4926 ASSERT(target == GL_RENDERBUFFER);
4927 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004928 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04004929 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004930}
4931
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004932void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08004933 GLsizei samples,
4934 GLenum internalformat,
4935 GLsizei width,
4936 GLsizei height,
4937 GLboolean fixedsamplelocations)
4938{
4939 Extents size(width, height, 1);
4940 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004941 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
4942 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004943}
4944
4945void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4946{
JiangYizhou5b03f472017-01-09 10:22:53 +08004947 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
4948 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillbc918e72018-03-08 09:47:21 -05004949 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
JiangYizhou5b03f472017-01-09 10:22:53 +08004950 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08004951
4952 switch (pname)
4953 {
4954 case GL_SAMPLE_POSITION:
Geoff Lang13455072018-05-09 11:24:43 -04004955 handleError(framebuffer->getSamplePosition(this, index, val));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004956 break;
4957 default:
4958 UNREACHABLE();
4959 }
4960}
4961
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07004962void Context::getMultisamplefvRobust(GLenum pname,
4963 GLuint index,
4964 GLsizei bufSize,
4965 GLsizei *length,
4966 GLfloat *val)
4967{
4968 UNIMPLEMENTED();
4969}
4970
Jamie Madille8fb6402017-02-14 17:56:40 -05004971void Context::renderbufferStorage(GLenum target,
4972 GLenum internalformat,
4973 GLsizei width,
4974 GLsizei height)
4975{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004976 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4977 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
4978
Jamie Madille8fb6402017-02-14 17:56:40 -05004979 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04004980 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004981}
4982
4983void Context::renderbufferStorageMultisample(GLenum target,
4984 GLsizei samples,
4985 GLenum internalformat,
4986 GLsizei width,
4987 GLsizei height)
4988{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004989 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4990 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05004991
4992 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004993 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04004994 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004995}
4996
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004997void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
4998{
Jamie Madill70b5bb02017-08-28 13:32:37 -04004999 const Sync *syncObject = getSync(sync);
Geoff Lang82483b92017-04-11 15:33:00 -04005000 handleError(QuerySynciv(syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04005001}
5002
JiangYizhoue18e6392017-02-20 10:32:23 +08005003void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
5004{
5005 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5006 QueryFramebufferParameteriv(framebuffer, pname, params);
5007}
5008
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07005009void Context::getFramebufferParameterivRobust(GLenum target,
5010 GLenum pname,
5011 GLsizei bufSize,
5012 GLsizei *length,
5013 GLint *params)
5014{
5015 UNIMPLEMENTED();
5016}
5017
Jiajia Qin5451d532017-11-16 17:16:34 +08005018void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08005019{
5020 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5021 SetFramebufferParameteri(framebuffer, pname, param);
5022}
5023
Jamie Madilldec86232018-07-11 09:01:18 -04005024bool Context::getScratchBuffer(size_t requstedSizeBytes,
5025 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05005026{
Jamie Madilldec86232018-07-11 09:01:18 -04005027 return mScratchBuffer.get(requstedSizeBytes, scratchBufferOut);
Jamie Madillb3f26b92017-07-19 15:07:41 -04005028}
5029
Jamie Madilldec86232018-07-11 09:01:18 -04005030bool Context::getZeroFilledBuffer(size_t requstedSizeBytes,
5031 angle::MemoryBuffer **zeroBufferOut) const
Jamie Madillb3f26b92017-07-19 15:07:41 -04005032{
Jamie Madilldec86232018-07-11 09:01:18 -04005033 return mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0);
Jamie Madille14951e2017-03-09 18:55:16 -05005034}
5035
Xinghua Cao10a4d432017-11-28 14:46:26 +08005036Error Context::prepareForDispatch()
5037{
Geoff Langa8cb2872018-03-09 16:09:40 -05005038 ANGLE_TRY(syncState(mComputeDirtyBits, mComputeDirtyObjects));
Xinghua Cao10a4d432017-11-28 14:46:26 +08005039
5040 if (isRobustResourceInitEnabled())
5041 {
5042 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
5043 }
5044
5045 return NoError();
5046}
5047
Xinghua Cao2b396592017-03-29 15:36:04 +08005048void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
5049{
5050 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
5051 {
5052 return;
5053 }
5054
Xinghua Cao10a4d432017-11-28 14:46:26 +08005055 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill71c88b32017-09-14 22:20:29 -04005056 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08005057}
5058
Jiajia Qin5451d532017-11-16 17:16:34 +08005059void Context::dispatchComputeIndirect(GLintptr indirect)
5060{
Qin Jiajia62fcf622017-11-30 16:16:12 +08005061 ANGLE_CONTEXT_TRY(prepareForDispatch());
5062 handleError(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08005063}
5064
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005065void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005066 GLsizei levels,
5067 GLenum internalFormat,
5068 GLsizei width,
5069 GLsizei height)
5070{
5071 Extents size(width, height, 1);
5072 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005073 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005074}
5075
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005076void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005077 GLsizei levels,
5078 GLenum internalFormat,
5079 GLsizei width,
5080 GLsizei height,
5081 GLsizei depth)
5082{
5083 Extents size(width, height, depth);
5084 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005085 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005086}
5087
Jiajia Qin5451d532017-11-16 17:16:34 +08005088void Context::memoryBarrier(GLbitfield barriers)
5089{
Xinghua Cao89c422a2017-11-29 18:24:20 +08005090 handleError(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005091}
5092
5093void Context::memoryBarrierByRegion(GLbitfield barriers)
5094{
Xinghua Cao89c422a2017-11-29 18:24:20 +08005095 handleError(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005096}
5097
Jamie Madillc1d770e2017-04-13 17:31:24 -04005098GLenum Context::checkFramebufferStatus(GLenum target)
5099{
5100 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5101 ASSERT(framebuffer);
Jamie Madill427064d2018-04-13 16:20:34 -04005102 return framebuffer->checkStatus(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005103}
5104
5105void Context::compileShader(GLuint shader)
5106{
5107 Shader *shaderObject = GetValidShader(this, shader);
5108 if (!shaderObject)
5109 {
5110 return;
5111 }
5112 shaderObject->compile(this);
5113}
5114
5115void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
5116{
5117 for (int i = 0; i < n; i++)
5118 {
5119 deleteBuffer(buffers[i]);
5120 }
5121}
5122
5123void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
5124{
5125 for (int i = 0; i < n; i++)
5126 {
5127 if (framebuffers[i] != 0)
5128 {
5129 deleteFramebuffer(framebuffers[i]);
5130 }
5131 }
5132}
5133
5134void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
5135{
5136 for (int i = 0; i < n; i++)
5137 {
5138 deleteRenderbuffer(renderbuffers[i]);
5139 }
5140}
5141
5142void Context::deleteTextures(GLsizei n, const GLuint *textures)
5143{
5144 for (int i = 0; i < n; i++)
5145 {
5146 if (textures[i] != 0)
5147 {
5148 deleteTexture(textures[i]);
5149 }
5150 }
5151}
5152
5153void Context::detachShader(GLuint program, GLuint shader)
5154{
5155 Program *programObject = getProgram(program);
5156 ASSERT(programObject);
5157
5158 Shader *shaderObject = getShader(shader);
5159 ASSERT(shaderObject);
5160
5161 programObject->detachShader(this, shaderObject);
5162}
5163
5164void Context::genBuffers(GLsizei n, GLuint *buffers)
5165{
5166 for (int i = 0; i < n; i++)
5167 {
5168 buffers[i] = createBuffer();
5169 }
5170}
5171
5172void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
5173{
5174 for (int i = 0; i < n; i++)
5175 {
5176 framebuffers[i] = createFramebuffer();
5177 }
5178}
5179
5180void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
5181{
5182 for (int i = 0; i < n; i++)
5183 {
5184 renderbuffers[i] = createRenderbuffer();
5185 }
5186}
5187
5188void Context::genTextures(GLsizei n, GLuint *textures)
5189{
5190 for (int i = 0; i < n; i++)
5191 {
5192 textures[i] = createTexture();
5193 }
5194}
5195
5196void Context::getActiveAttrib(GLuint program,
5197 GLuint index,
5198 GLsizei bufsize,
5199 GLsizei *length,
5200 GLint *size,
5201 GLenum *type,
5202 GLchar *name)
5203{
5204 Program *programObject = getProgram(program);
5205 ASSERT(programObject);
5206 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
5207}
5208
5209void Context::getActiveUniform(GLuint program,
5210 GLuint index,
5211 GLsizei bufsize,
5212 GLsizei *length,
5213 GLint *size,
5214 GLenum *type,
5215 GLchar *name)
5216{
5217 Program *programObject = getProgram(program);
5218 ASSERT(programObject);
5219 programObject->getActiveUniform(index, bufsize, length, size, type, name);
5220}
5221
5222void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
5223{
5224 Program *programObject = getProgram(program);
5225 ASSERT(programObject);
5226 programObject->getAttachedShaders(maxcount, count, shaders);
5227}
5228
5229GLint Context::getAttribLocation(GLuint program, const GLchar *name)
5230{
5231 Program *programObject = getProgram(program);
5232 ASSERT(programObject);
5233 return programObject->getAttributeLocation(name);
5234}
5235
5236void Context::getBooleanv(GLenum pname, GLboolean *params)
5237{
5238 GLenum nativeType;
5239 unsigned int numParams = 0;
5240 getQueryParameterInfo(pname, &nativeType, &numParams);
5241
5242 if (nativeType == GL_BOOL)
5243 {
5244 getBooleanvImpl(pname, params);
5245 }
5246 else
5247 {
5248 CastStateValues(this, nativeType, pname, numParams, params);
5249 }
5250}
5251
Brandon Jones59770802018-04-02 13:18:42 -07005252void Context::getBooleanvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLboolean *params)
5253{
5254 getBooleanv(pname, params);
5255}
5256
Jamie Madillc1d770e2017-04-13 17:31:24 -04005257void Context::getFloatv(GLenum pname, GLfloat *params)
5258{
5259 GLenum nativeType;
5260 unsigned int numParams = 0;
5261 getQueryParameterInfo(pname, &nativeType, &numParams);
5262
5263 if (nativeType == GL_FLOAT)
5264 {
5265 getFloatvImpl(pname, params);
5266 }
5267 else
5268 {
5269 CastStateValues(this, nativeType, pname, numParams, params);
5270 }
5271}
5272
Brandon Jones59770802018-04-02 13:18:42 -07005273void Context::getFloatvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLfloat *params)
5274{
5275 getFloatv(pname, params);
5276}
5277
Jamie Madillc1d770e2017-04-13 17:31:24 -04005278void Context::getIntegerv(GLenum pname, GLint *params)
5279{
5280 GLenum nativeType;
5281 unsigned int numParams = 0;
5282 getQueryParameterInfo(pname, &nativeType, &numParams);
5283
5284 if (nativeType == GL_INT)
5285 {
5286 getIntegervImpl(pname, params);
5287 }
5288 else
5289 {
5290 CastStateValues(this, nativeType, pname, numParams, params);
5291 }
5292}
5293
Brandon Jones59770802018-04-02 13:18:42 -07005294void Context::getIntegervRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint *data)
5295{
5296 getIntegerv(pname, data);
5297}
5298
Jamie Madillc1d770e2017-04-13 17:31:24 -04005299void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
5300{
5301 Program *programObject = getProgram(program);
5302 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04005303 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005304}
5305
Brandon Jones59770802018-04-02 13:18:42 -07005306void Context::getProgramivRobust(GLuint program,
5307 GLenum pname,
5308 GLsizei bufSize,
5309 GLsizei *length,
5310 GLint *params)
5311{
5312 getProgramiv(program, pname, params);
5313}
5314
Jiajia Qin5451d532017-11-16 17:16:34 +08005315void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
5316{
5317 UNIMPLEMENTED();
5318}
5319
Jamie Madillbe849e42017-05-02 15:49:00 -04005320void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005321{
5322 Program *programObject = getProgram(program);
5323 ASSERT(programObject);
5324 programObject->getInfoLog(bufsize, length, infolog);
5325}
5326
Jiajia Qin5451d532017-11-16 17:16:34 +08005327void Context::getProgramPipelineInfoLog(GLuint pipeline,
5328 GLsizei bufSize,
5329 GLsizei *length,
5330 GLchar *infoLog)
5331{
5332 UNIMPLEMENTED();
5333}
5334
Jamie Madillc1d770e2017-04-13 17:31:24 -04005335void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
5336{
5337 Shader *shaderObject = getShader(shader);
5338 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04005339 QueryShaderiv(this, shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005340}
5341
Brandon Jones59770802018-04-02 13:18:42 -07005342void Context::getShaderivRobust(GLuint shader,
5343 GLenum pname,
5344 GLsizei bufSize,
5345 GLsizei *length,
5346 GLint *params)
5347{
5348 getShaderiv(shader, pname, params);
5349}
5350
Jamie Madillc1d770e2017-04-13 17:31:24 -04005351void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
5352{
5353 Shader *shaderObject = getShader(shader);
5354 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04005355 shaderObject->getInfoLog(this, bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005356}
5357
5358void Context::getShaderPrecisionFormat(GLenum shadertype,
5359 GLenum precisiontype,
5360 GLint *range,
5361 GLint *precision)
5362{
5363 // TODO(jmadill): Compute shaders.
5364
5365 switch (shadertype)
5366 {
5367 case GL_VERTEX_SHADER:
5368 switch (precisiontype)
5369 {
5370 case GL_LOW_FLOAT:
5371 mCaps.vertexLowpFloat.get(range, precision);
5372 break;
5373 case GL_MEDIUM_FLOAT:
5374 mCaps.vertexMediumpFloat.get(range, precision);
5375 break;
5376 case GL_HIGH_FLOAT:
5377 mCaps.vertexHighpFloat.get(range, precision);
5378 break;
5379
5380 case GL_LOW_INT:
5381 mCaps.vertexLowpInt.get(range, precision);
5382 break;
5383 case GL_MEDIUM_INT:
5384 mCaps.vertexMediumpInt.get(range, precision);
5385 break;
5386 case GL_HIGH_INT:
5387 mCaps.vertexHighpInt.get(range, precision);
5388 break;
5389
5390 default:
5391 UNREACHABLE();
5392 return;
5393 }
5394 break;
5395
5396 case GL_FRAGMENT_SHADER:
5397 switch (precisiontype)
5398 {
5399 case GL_LOW_FLOAT:
5400 mCaps.fragmentLowpFloat.get(range, precision);
5401 break;
5402 case GL_MEDIUM_FLOAT:
5403 mCaps.fragmentMediumpFloat.get(range, precision);
5404 break;
5405 case GL_HIGH_FLOAT:
5406 mCaps.fragmentHighpFloat.get(range, precision);
5407 break;
5408
5409 case GL_LOW_INT:
5410 mCaps.fragmentLowpInt.get(range, precision);
5411 break;
5412 case GL_MEDIUM_INT:
5413 mCaps.fragmentMediumpInt.get(range, precision);
5414 break;
5415 case GL_HIGH_INT:
5416 mCaps.fragmentHighpInt.get(range, precision);
5417 break;
5418
5419 default:
5420 UNREACHABLE();
5421 return;
5422 }
5423 break;
5424
5425 default:
5426 UNREACHABLE();
5427 return;
5428 }
5429}
5430
5431void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
5432{
5433 Shader *shaderObject = getShader(shader);
5434 ASSERT(shaderObject);
5435 shaderObject->getSource(bufsize, length, source);
5436}
5437
5438void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
5439{
5440 Program *programObject = getProgram(program);
5441 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005442 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005443}
5444
Brandon Jones59770802018-04-02 13:18:42 -07005445void Context::getUniformfvRobust(GLuint program,
5446 GLint location,
5447 GLsizei bufSize,
5448 GLsizei *length,
5449 GLfloat *params)
5450{
5451 getUniformfv(program, location, params);
5452}
5453
Jamie Madillc1d770e2017-04-13 17:31:24 -04005454void Context::getUniformiv(GLuint program, GLint location, GLint *params)
5455{
5456 Program *programObject = getProgram(program);
5457 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005458 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005459}
5460
Brandon Jones59770802018-04-02 13:18:42 -07005461void Context::getUniformivRobust(GLuint program,
5462 GLint location,
5463 GLsizei bufSize,
5464 GLsizei *length,
5465 GLint *params)
5466{
5467 getUniformiv(program, location, params);
5468}
5469
Jamie Madillc1d770e2017-04-13 17:31:24 -04005470GLint Context::getUniformLocation(GLuint program, const GLchar *name)
5471{
5472 Program *programObject = getProgram(program);
5473 ASSERT(programObject);
5474 return programObject->getUniformLocation(name);
5475}
5476
5477GLboolean Context::isBuffer(GLuint buffer)
5478{
5479 if (buffer == 0)
5480 {
5481 return GL_FALSE;
5482 }
5483
5484 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
5485}
5486
5487GLboolean Context::isEnabled(GLenum cap)
5488{
5489 return mGLState.getEnableFeature(cap);
5490}
5491
5492GLboolean Context::isFramebuffer(GLuint framebuffer)
5493{
5494 if (framebuffer == 0)
5495 {
5496 return GL_FALSE;
5497 }
5498
5499 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
5500}
5501
5502GLboolean Context::isProgram(GLuint program)
5503{
5504 if (program == 0)
5505 {
5506 return GL_FALSE;
5507 }
5508
5509 return (getProgram(program) ? GL_TRUE : GL_FALSE);
5510}
5511
5512GLboolean Context::isRenderbuffer(GLuint renderbuffer)
5513{
5514 if (renderbuffer == 0)
5515 {
5516 return GL_FALSE;
5517 }
5518
5519 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
5520}
5521
5522GLboolean Context::isShader(GLuint shader)
5523{
5524 if (shader == 0)
5525 {
5526 return GL_FALSE;
5527 }
5528
5529 return (getShader(shader) ? GL_TRUE : GL_FALSE);
5530}
5531
5532GLboolean Context::isTexture(GLuint texture)
5533{
5534 if (texture == 0)
5535 {
5536 return GL_FALSE;
5537 }
5538
5539 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
5540}
5541
5542void Context::linkProgram(GLuint program)
5543{
5544 Program *programObject = getProgram(program);
5545 ASSERT(programObject);
5546 handleError(programObject->link(this));
Martin Radev0abb7a22017-08-28 15:34:45 +03005547 mGLState.onProgramExecutableChange(programObject);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005548}
5549
5550void Context::releaseShaderCompiler()
5551{
Jamie Madill4928b7c2017-06-20 12:57:39 -04005552 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005553}
5554
5555void Context::shaderBinary(GLsizei n,
5556 const GLuint *shaders,
5557 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04005558 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005559 GLsizei length)
5560{
5561 // No binary shader formats are supported.
5562 UNIMPLEMENTED();
5563}
5564
5565void Context::shaderSource(GLuint shader,
5566 GLsizei count,
5567 const GLchar *const *string,
5568 const GLint *length)
5569{
5570 Shader *shaderObject = getShader(shader);
5571 ASSERT(shaderObject);
5572 shaderObject->setSource(count, string, length);
5573}
5574
5575void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
5576{
5577 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
5578}
5579
5580void Context::stencilMask(GLuint mask)
5581{
5582 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
5583}
5584
5585void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
5586{
5587 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
5588}
5589
5590void Context::uniform1f(GLint location, GLfloat x)
5591{
5592 Program *program = mGLState.getProgram();
5593 program->setUniform1fv(location, 1, &x);
5594}
5595
5596void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
5597{
5598 Program *program = mGLState.getProgram();
5599 program->setUniform1fv(location, count, v);
5600}
5601
5602void Context::uniform1i(GLint location, GLint x)
5603{
5604 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04005605 if (program->setUniform1iv(location, 1, &x) == Program::SetUniformResult::SamplerChanged)
5606 {
5607 mGLState.setObjectDirty(GL_PROGRAM);
5608 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005609}
5610
5611void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
5612{
5613 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04005614 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
5615 {
5616 mGLState.setObjectDirty(GL_PROGRAM);
5617 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005618}
5619
5620void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
5621{
5622 GLfloat xy[2] = {x, y};
5623 Program *program = mGLState.getProgram();
5624 program->setUniform2fv(location, 1, xy);
5625}
5626
5627void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
5628{
5629 Program *program = mGLState.getProgram();
5630 program->setUniform2fv(location, count, v);
5631}
5632
5633void Context::uniform2i(GLint location, GLint x, GLint y)
5634{
5635 GLint xy[2] = {x, y};
5636 Program *program = mGLState.getProgram();
5637 program->setUniform2iv(location, 1, xy);
5638}
5639
5640void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
5641{
5642 Program *program = mGLState.getProgram();
5643 program->setUniform2iv(location, count, v);
5644}
5645
5646void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
5647{
5648 GLfloat xyz[3] = {x, y, z};
5649 Program *program = mGLState.getProgram();
5650 program->setUniform3fv(location, 1, xyz);
5651}
5652
5653void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
5654{
5655 Program *program = mGLState.getProgram();
5656 program->setUniform3fv(location, count, v);
5657}
5658
5659void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
5660{
5661 GLint xyz[3] = {x, y, z};
5662 Program *program = mGLState.getProgram();
5663 program->setUniform3iv(location, 1, xyz);
5664}
5665
5666void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
5667{
5668 Program *program = mGLState.getProgram();
5669 program->setUniform3iv(location, count, v);
5670}
5671
5672void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
5673{
5674 GLfloat xyzw[4] = {x, y, z, w};
5675 Program *program = mGLState.getProgram();
5676 program->setUniform4fv(location, 1, xyzw);
5677}
5678
5679void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
5680{
5681 Program *program = mGLState.getProgram();
5682 program->setUniform4fv(location, count, v);
5683}
5684
5685void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
5686{
5687 GLint xyzw[4] = {x, y, z, w};
5688 Program *program = mGLState.getProgram();
5689 program->setUniform4iv(location, 1, xyzw);
5690}
5691
5692void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
5693{
5694 Program *program = mGLState.getProgram();
5695 program->setUniform4iv(location, count, v);
5696}
5697
5698void Context::uniformMatrix2fv(GLint location,
5699 GLsizei count,
5700 GLboolean transpose,
5701 const GLfloat *value)
5702{
5703 Program *program = mGLState.getProgram();
5704 program->setUniformMatrix2fv(location, count, transpose, value);
5705}
5706
5707void Context::uniformMatrix3fv(GLint location,
5708 GLsizei count,
5709 GLboolean transpose,
5710 const GLfloat *value)
5711{
5712 Program *program = mGLState.getProgram();
5713 program->setUniformMatrix3fv(location, count, transpose, value);
5714}
5715
5716void Context::uniformMatrix4fv(GLint location,
5717 GLsizei count,
5718 GLboolean transpose,
5719 const GLfloat *value)
5720{
5721 Program *program = mGLState.getProgram();
5722 program->setUniformMatrix4fv(location, count, transpose, value);
5723}
5724
5725void Context::validateProgram(GLuint program)
5726{
5727 Program *programObject = getProgram(program);
5728 ASSERT(programObject);
5729 programObject->validate(mCaps);
5730}
5731
Jiajia Qin5451d532017-11-16 17:16:34 +08005732void Context::validateProgramPipeline(GLuint pipeline)
5733{
5734 UNIMPLEMENTED();
5735}
5736
Jamie Madilld04908b2017-06-09 14:15:35 -04005737void Context::getProgramBinary(GLuint program,
5738 GLsizei bufSize,
5739 GLsizei *length,
5740 GLenum *binaryFormat,
5741 void *binary)
5742{
5743 Program *programObject = getProgram(program);
5744 ASSERT(programObject != nullptr);
5745
5746 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
5747}
5748
5749void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
5750{
5751 Program *programObject = getProgram(program);
5752 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04005753
Jamie Madilld04908b2017-06-09 14:15:35 -04005754 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
5755}
5756
Jamie Madillff325f12017-08-26 15:06:05 -04005757void Context::uniform1ui(GLint location, GLuint v0)
5758{
5759 Program *program = mGLState.getProgram();
5760 program->setUniform1uiv(location, 1, &v0);
5761}
5762
5763void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
5764{
5765 Program *program = mGLState.getProgram();
5766 const GLuint xy[] = {v0, v1};
5767 program->setUniform2uiv(location, 1, xy);
5768}
5769
5770void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
5771{
5772 Program *program = mGLState.getProgram();
5773 const GLuint xyz[] = {v0, v1, v2};
5774 program->setUniform3uiv(location, 1, xyz);
5775}
5776
5777void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
5778{
5779 Program *program = mGLState.getProgram();
5780 const GLuint xyzw[] = {v0, v1, v2, v3};
5781 program->setUniform4uiv(location, 1, xyzw);
5782}
5783
5784void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
5785{
5786 Program *program = mGLState.getProgram();
5787 program->setUniform1uiv(location, count, value);
5788}
5789void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
5790{
5791 Program *program = mGLState.getProgram();
5792 program->setUniform2uiv(location, count, value);
5793}
5794
5795void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
5796{
5797 Program *program = mGLState.getProgram();
5798 program->setUniform3uiv(location, count, value);
5799}
5800
5801void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
5802{
5803 Program *program = mGLState.getProgram();
5804 program->setUniform4uiv(location, count, value);
5805}
5806
Jamie Madillf0e04492017-08-26 15:28:42 -04005807void Context::genQueries(GLsizei n, GLuint *ids)
5808{
5809 for (GLsizei i = 0; i < n; i++)
5810 {
5811 GLuint handle = mQueryHandleAllocator.allocate();
5812 mQueryMap.assign(handle, nullptr);
5813 ids[i] = handle;
5814 }
5815}
5816
5817void Context::deleteQueries(GLsizei n, const GLuint *ids)
5818{
5819 for (int i = 0; i < n; i++)
5820 {
5821 GLuint query = ids[i];
5822
5823 Query *queryObject = nullptr;
5824 if (mQueryMap.erase(query, &queryObject))
5825 {
5826 mQueryHandleAllocator.release(query);
5827 if (queryObject)
5828 {
5829 queryObject->release(this);
5830 }
5831 }
5832 }
5833}
5834
5835GLboolean Context::isQuery(GLuint id)
5836{
Corentin Wallezad3ae902018-03-09 13:40:42 -05005837 return (getQuery(id, false, QueryType::InvalidEnum) != nullptr) ? GL_TRUE : GL_FALSE;
Jamie Madillf0e04492017-08-26 15:28:42 -04005838}
5839
Jamie Madillc8c95812017-08-26 18:40:09 -04005840void Context::uniformMatrix2x3fv(GLint location,
5841 GLsizei count,
5842 GLboolean transpose,
5843 const GLfloat *value)
5844{
5845 Program *program = mGLState.getProgram();
5846 program->setUniformMatrix2x3fv(location, count, transpose, value);
5847}
5848
5849void Context::uniformMatrix3x2fv(GLint location,
5850 GLsizei count,
5851 GLboolean transpose,
5852 const GLfloat *value)
5853{
5854 Program *program = mGLState.getProgram();
5855 program->setUniformMatrix3x2fv(location, count, transpose, value);
5856}
5857
5858void Context::uniformMatrix2x4fv(GLint location,
5859 GLsizei count,
5860 GLboolean transpose,
5861 const GLfloat *value)
5862{
5863 Program *program = mGLState.getProgram();
5864 program->setUniformMatrix2x4fv(location, count, transpose, value);
5865}
5866
5867void Context::uniformMatrix4x2fv(GLint location,
5868 GLsizei count,
5869 GLboolean transpose,
5870 const GLfloat *value)
5871{
5872 Program *program = mGLState.getProgram();
5873 program->setUniformMatrix4x2fv(location, count, transpose, value);
5874}
5875
5876void Context::uniformMatrix3x4fv(GLint location,
5877 GLsizei count,
5878 GLboolean transpose,
5879 const GLfloat *value)
5880{
5881 Program *program = mGLState.getProgram();
5882 program->setUniformMatrix3x4fv(location, count, transpose, value);
5883}
5884
5885void Context::uniformMatrix4x3fv(GLint location,
5886 GLsizei count,
5887 GLboolean transpose,
5888 const GLfloat *value)
5889{
5890 Program *program = mGLState.getProgram();
5891 program->setUniformMatrix4x3fv(location, count, transpose, value);
5892}
5893
Jamie Madilld7576732017-08-26 18:49:50 -04005894void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
5895{
5896 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5897 {
5898 GLuint vertexArray = arrays[arrayIndex];
5899
5900 if (arrays[arrayIndex] != 0)
5901 {
5902 VertexArray *vertexArrayObject = nullptr;
5903 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
5904 {
5905 if (vertexArrayObject != nullptr)
5906 {
5907 detachVertexArray(vertexArray);
5908 vertexArrayObject->onDestroy(this);
5909 }
5910
5911 mVertexArrayHandleAllocator.release(vertexArray);
5912 }
5913 }
5914 }
5915}
5916
5917void Context::genVertexArrays(GLsizei n, GLuint *arrays)
5918{
5919 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5920 {
5921 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
5922 mVertexArrayMap.assign(vertexArray, nullptr);
5923 arrays[arrayIndex] = vertexArray;
5924 }
5925}
5926
5927bool Context::isVertexArray(GLuint array)
5928{
5929 if (array == 0)
5930 {
5931 return GL_FALSE;
5932 }
5933
5934 VertexArray *vao = getVertexArray(array);
5935 return (vao != nullptr ? GL_TRUE : GL_FALSE);
5936}
5937
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04005938void Context::endTransformFeedback()
5939{
5940 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5941 transformFeedback->end(this);
5942}
5943
5944void Context::transformFeedbackVaryings(GLuint program,
5945 GLsizei count,
5946 const GLchar *const *varyings,
5947 GLenum bufferMode)
5948{
5949 Program *programObject = getProgram(program);
5950 ASSERT(programObject);
5951 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
5952}
5953
5954void Context::getTransformFeedbackVarying(GLuint program,
5955 GLuint index,
5956 GLsizei bufSize,
5957 GLsizei *length,
5958 GLsizei *size,
5959 GLenum *type,
5960 GLchar *name)
5961{
5962 Program *programObject = getProgram(program);
5963 ASSERT(programObject);
5964 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
5965}
5966
5967void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
5968{
5969 for (int i = 0; i < n; i++)
5970 {
5971 GLuint transformFeedback = ids[i];
5972 if (transformFeedback == 0)
5973 {
5974 continue;
5975 }
5976
5977 TransformFeedback *transformFeedbackObject = nullptr;
5978 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
5979 {
5980 if (transformFeedbackObject != nullptr)
5981 {
5982 detachTransformFeedback(transformFeedback);
5983 transformFeedbackObject->release(this);
5984 }
5985
5986 mTransformFeedbackHandleAllocator.release(transformFeedback);
5987 }
5988 }
5989}
5990
5991void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
5992{
5993 for (int i = 0; i < n; i++)
5994 {
5995 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
5996 mTransformFeedbackMap.assign(transformFeedback, nullptr);
5997 ids[i] = transformFeedback;
5998 }
5999}
6000
6001bool Context::isTransformFeedback(GLuint id)
6002{
6003 if (id == 0)
6004 {
6005 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
6006 // returns FALSE
6007 return GL_FALSE;
6008 }
6009
6010 const TransformFeedback *transformFeedback = getTransformFeedback(id);
6011 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
6012}
6013
6014void Context::pauseTransformFeedback()
6015{
6016 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6017 transformFeedback->pause();
6018}
6019
6020void Context::resumeTransformFeedback()
6021{
6022 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6023 transformFeedback->resume();
6024}
6025
Jamie Madill12e957f2017-08-26 21:42:26 -04006026void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
6027{
6028 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04006029 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04006030}
6031
Brandon Jones59770802018-04-02 13:18:42 -07006032void Context::getUniformuivRobust(GLuint program,
6033 GLint location,
6034 GLsizei bufSize,
6035 GLsizei *length,
6036 GLuint *params)
6037{
6038 getUniformuiv(program, location, params);
6039}
6040
Jamie Madill12e957f2017-08-26 21:42:26 -04006041GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
6042{
6043 const Program *programObject = getProgram(program);
6044 return programObject->getFragDataLocation(name);
6045}
6046
6047void Context::getUniformIndices(GLuint program,
6048 GLsizei uniformCount,
6049 const GLchar *const *uniformNames,
6050 GLuint *uniformIndices)
6051{
6052 const Program *programObject = getProgram(program);
6053 if (!programObject->isLinked())
6054 {
6055 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6056 {
6057 uniformIndices[uniformId] = GL_INVALID_INDEX;
6058 }
6059 }
6060 else
6061 {
6062 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6063 {
6064 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
6065 }
6066 }
6067}
6068
6069void Context::getActiveUniformsiv(GLuint program,
6070 GLsizei uniformCount,
6071 const GLuint *uniformIndices,
6072 GLenum pname,
6073 GLint *params)
6074{
6075 const Program *programObject = getProgram(program);
6076 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6077 {
6078 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08006079 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04006080 }
6081}
6082
6083GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
6084{
6085 const Program *programObject = getProgram(program);
6086 return programObject->getUniformBlockIndex(uniformBlockName);
6087}
6088
6089void Context::getActiveUniformBlockiv(GLuint program,
6090 GLuint uniformBlockIndex,
6091 GLenum pname,
6092 GLint *params)
6093{
6094 const Program *programObject = getProgram(program);
6095 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
6096}
6097
Brandon Jones59770802018-04-02 13:18:42 -07006098void Context::getActiveUniformBlockivRobust(GLuint program,
6099 GLuint uniformBlockIndex,
6100 GLenum pname,
6101 GLsizei bufSize,
6102 GLsizei *length,
6103 GLint *params)
6104{
6105 getActiveUniformBlockiv(program, uniformBlockIndex, pname, params);
6106}
6107
Jamie Madill12e957f2017-08-26 21:42:26 -04006108void Context::getActiveUniformBlockName(GLuint program,
6109 GLuint uniformBlockIndex,
6110 GLsizei bufSize,
6111 GLsizei *length,
6112 GLchar *uniformBlockName)
6113{
6114 const Program *programObject = getProgram(program);
6115 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
6116}
6117
6118void Context::uniformBlockBinding(GLuint program,
6119 GLuint uniformBlockIndex,
6120 GLuint uniformBlockBinding)
6121{
6122 Program *programObject = getProgram(program);
6123 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
6124}
6125
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006126GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
6127{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006128 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
6129 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006130
Jamie Madill70b5bb02017-08-28 13:32:37 -04006131 Sync *syncObject = getSync(syncHandle);
6132 Error error = syncObject->set(condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006133 if (error.isError())
6134 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04006135 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006136 handleError(error);
6137 return nullptr;
6138 }
6139
Jamie Madill70b5bb02017-08-28 13:32:37 -04006140 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006141}
6142
6143GLboolean Context::isSync(GLsync sync)
6144{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006145 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006146}
6147
6148GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6149{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006150 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006151
6152 GLenum result = GL_WAIT_FAILED;
6153 handleError(syncObject->clientWait(flags, timeout, &result));
6154 return result;
6155}
6156
6157void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6158{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006159 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006160 handleError(syncObject->serverWait(flags, timeout));
6161}
6162
6163void Context::getInteger64v(GLenum pname, GLint64 *params)
6164{
6165 GLenum nativeType = GL_NONE;
6166 unsigned int numParams = 0;
6167 getQueryParameterInfo(pname, &nativeType, &numParams);
6168
6169 if (nativeType == GL_INT_64_ANGLEX)
6170 {
6171 getInteger64vImpl(pname, params);
6172 }
6173 else
6174 {
6175 CastStateValues(this, nativeType, pname, numParams, params);
6176 }
6177}
6178
Brandon Jones59770802018-04-02 13:18:42 -07006179void Context::getInteger64vRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint64 *data)
6180{
6181 getInteger64v(pname, data);
6182}
6183
Corentin Wallez336129f2017-10-17 15:55:40 -04006184void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04006185{
6186 Buffer *buffer = mGLState.getTargetBuffer(target);
6187 QueryBufferParameteri64v(buffer, pname, params);
6188}
6189
Brandon Jones59770802018-04-02 13:18:42 -07006190void Context::getBufferParameteri64vRobust(BufferBinding target,
6191 GLenum pname,
6192 GLsizei bufSize,
6193 GLsizei *length,
6194 GLint64 *params)
6195{
6196 getBufferParameteri64v(target, pname, params);
6197}
6198
Jamie Madill3ef140a2017-08-26 23:11:21 -04006199void Context::genSamplers(GLsizei count, GLuint *samplers)
6200{
6201 for (int i = 0; i < count; i++)
6202 {
6203 samplers[i] = mState.mSamplers->createSampler();
6204 }
6205}
6206
6207void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
6208{
6209 for (int i = 0; i < count; i++)
6210 {
6211 GLuint sampler = samplers[i];
6212
6213 if (mState.mSamplers->getSampler(sampler))
6214 {
6215 detachSampler(sampler);
6216 }
6217
6218 mState.mSamplers->deleteObject(this, sampler);
6219 }
6220}
6221
6222void Context::getInternalformativ(GLenum target,
6223 GLenum internalformat,
6224 GLenum pname,
6225 GLsizei bufSize,
6226 GLint *params)
6227{
6228 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
6229 QueryInternalFormativ(formatCaps, pname, bufSize, params);
6230}
6231
Brandon Jones59770802018-04-02 13:18:42 -07006232void Context::getInternalformativRobust(GLenum target,
6233 GLenum internalformat,
6234 GLenum pname,
6235 GLsizei bufSize,
6236 GLsizei *length,
6237 GLint *params)
6238{
6239 getInternalformativ(target, internalformat, pname, bufSize, params);
6240}
6241
Jiajia Qin5451d532017-11-16 17:16:34 +08006242void Context::programUniform1i(GLuint program, GLint location, GLint v0)
6243{
6244 programUniform1iv(program, location, 1, &v0);
6245}
6246
6247void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
6248{
6249 GLint xy[2] = {v0, v1};
6250 programUniform2iv(program, location, 1, xy);
6251}
6252
6253void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
6254{
6255 GLint xyz[3] = {v0, v1, v2};
6256 programUniform3iv(program, location, 1, xyz);
6257}
6258
6259void Context::programUniform4i(GLuint program,
6260 GLint location,
6261 GLint v0,
6262 GLint v1,
6263 GLint v2,
6264 GLint v3)
6265{
6266 GLint xyzw[4] = {v0, v1, v2, v3};
6267 programUniform4iv(program, location, 1, xyzw);
6268}
6269
6270void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
6271{
6272 programUniform1uiv(program, location, 1, &v0);
6273}
6274
6275void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
6276{
6277 GLuint xy[2] = {v0, v1};
6278 programUniform2uiv(program, location, 1, xy);
6279}
6280
6281void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
6282{
6283 GLuint xyz[3] = {v0, v1, v2};
6284 programUniform3uiv(program, location, 1, xyz);
6285}
6286
6287void Context::programUniform4ui(GLuint program,
6288 GLint location,
6289 GLuint v0,
6290 GLuint v1,
6291 GLuint v2,
6292 GLuint v3)
6293{
6294 GLuint xyzw[4] = {v0, v1, v2, v3};
6295 programUniform4uiv(program, location, 1, xyzw);
6296}
6297
6298void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
6299{
6300 programUniform1fv(program, location, 1, &v0);
6301}
6302
6303void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
6304{
6305 GLfloat xy[2] = {v0, v1};
6306 programUniform2fv(program, location, 1, xy);
6307}
6308
6309void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
6310{
6311 GLfloat xyz[3] = {v0, v1, v2};
6312 programUniform3fv(program, location, 1, xyz);
6313}
6314
6315void Context::programUniform4f(GLuint program,
6316 GLint location,
6317 GLfloat v0,
6318 GLfloat v1,
6319 GLfloat v2,
6320 GLfloat v3)
6321{
6322 GLfloat xyzw[4] = {v0, v1, v2, v3};
6323 programUniform4fv(program, location, 1, xyzw);
6324}
6325
Jamie Madill81c2e252017-09-09 23:32:46 -04006326void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6327{
6328 Program *programObject = getProgram(program);
6329 ASSERT(programObject);
6330 if (programObject->setUniform1iv(location, count, value) ==
6331 Program::SetUniformResult::SamplerChanged)
6332 {
6333 mGLState.setObjectDirty(GL_PROGRAM);
6334 }
6335}
6336
Jiajia Qin5451d532017-11-16 17:16:34 +08006337void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6338{
6339 Program *programObject = getProgram(program);
6340 ASSERT(programObject);
6341 programObject->setUniform2iv(location, count, value);
6342}
6343
6344void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6345{
6346 Program *programObject = getProgram(program);
6347 ASSERT(programObject);
6348 programObject->setUniform3iv(location, count, value);
6349}
6350
6351void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6352{
6353 Program *programObject = getProgram(program);
6354 ASSERT(programObject);
6355 programObject->setUniform4iv(location, count, value);
6356}
6357
6358void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6359{
6360 Program *programObject = getProgram(program);
6361 ASSERT(programObject);
6362 programObject->setUniform1uiv(location, count, value);
6363}
6364
6365void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6366{
6367 Program *programObject = getProgram(program);
6368 ASSERT(programObject);
6369 programObject->setUniform2uiv(location, count, value);
6370}
6371
6372void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6373{
6374 Program *programObject = getProgram(program);
6375 ASSERT(programObject);
6376 programObject->setUniform3uiv(location, count, value);
6377}
6378
6379void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6380{
6381 Program *programObject = getProgram(program);
6382 ASSERT(programObject);
6383 programObject->setUniform4uiv(location, count, value);
6384}
6385
6386void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6387{
6388 Program *programObject = getProgram(program);
6389 ASSERT(programObject);
6390 programObject->setUniform1fv(location, count, value);
6391}
6392
6393void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6394{
6395 Program *programObject = getProgram(program);
6396 ASSERT(programObject);
6397 programObject->setUniform2fv(location, count, value);
6398}
6399
6400void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6401{
6402 Program *programObject = getProgram(program);
6403 ASSERT(programObject);
6404 programObject->setUniform3fv(location, count, value);
6405}
6406
6407void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6408{
6409 Program *programObject = getProgram(program);
6410 ASSERT(programObject);
6411 programObject->setUniform4fv(location, count, value);
6412}
6413
6414void Context::programUniformMatrix2fv(GLuint program,
6415 GLint location,
6416 GLsizei count,
6417 GLboolean transpose,
6418 const GLfloat *value)
6419{
6420 Program *programObject = getProgram(program);
6421 ASSERT(programObject);
6422 programObject->setUniformMatrix2fv(location, count, transpose, value);
6423}
6424
6425void Context::programUniformMatrix3fv(GLuint program,
6426 GLint location,
6427 GLsizei count,
6428 GLboolean transpose,
6429 const GLfloat *value)
6430{
6431 Program *programObject = getProgram(program);
6432 ASSERT(programObject);
6433 programObject->setUniformMatrix3fv(location, count, transpose, value);
6434}
6435
6436void Context::programUniformMatrix4fv(GLuint program,
6437 GLint location,
6438 GLsizei count,
6439 GLboolean transpose,
6440 const GLfloat *value)
6441{
6442 Program *programObject = getProgram(program);
6443 ASSERT(programObject);
6444 programObject->setUniformMatrix4fv(location, count, transpose, value);
6445}
6446
6447void Context::programUniformMatrix2x3fv(GLuint program,
6448 GLint location,
6449 GLsizei count,
6450 GLboolean transpose,
6451 const GLfloat *value)
6452{
6453 Program *programObject = getProgram(program);
6454 ASSERT(programObject);
6455 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
6456}
6457
6458void Context::programUniformMatrix3x2fv(GLuint program,
6459 GLint location,
6460 GLsizei count,
6461 GLboolean transpose,
6462 const GLfloat *value)
6463{
6464 Program *programObject = getProgram(program);
6465 ASSERT(programObject);
6466 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
6467}
6468
6469void Context::programUniformMatrix2x4fv(GLuint program,
6470 GLint location,
6471 GLsizei count,
6472 GLboolean transpose,
6473 const GLfloat *value)
6474{
6475 Program *programObject = getProgram(program);
6476 ASSERT(programObject);
6477 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
6478}
6479
6480void Context::programUniformMatrix4x2fv(GLuint program,
6481 GLint location,
6482 GLsizei count,
6483 GLboolean transpose,
6484 const GLfloat *value)
6485{
6486 Program *programObject = getProgram(program);
6487 ASSERT(programObject);
6488 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
6489}
6490
6491void Context::programUniformMatrix3x4fv(GLuint program,
6492 GLint location,
6493 GLsizei count,
6494 GLboolean transpose,
6495 const GLfloat *value)
6496{
6497 Program *programObject = getProgram(program);
6498 ASSERT(programObject);
6499 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
6500}
6501
6502void Context::programUniformMatrix4x3fv(GLuint program,
6503 GLint location,
6504 GLsizei count,
6505 GLboolean transpose,
6506 const GLfloat *value)
6507{
6508 Program *programObject = getProgram(program);
6509 ASSERT(programObject);
6510 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
6511}
6512
Jamie Madill81c2e252017-09-09 23:32:46 -04006513void Context::onTextureChange(const Texture *texture)
6514{
6515 // Conservatively assume all textures are dirty.
6516 // TODO(jmadill): More fine-grained update.
6517 mGLState.setObjectDirty(GL_TEXTURE);
6518}
6519
James Darpiniane8a93c62018-01-04 18:02:24 -08006520bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
6521{
6522 return mGLState.isCurrentTransformFeedback(tf);
6523}
6524bool Context::isCurrentVertexArray(const VertexArray *va) const
6525{
6526 return mGLState.isCurrentVertexArray(va);
6527}
6528
Yunchao Hea336b902017-08-02 16:05:21 +08006529void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
6530{
6531 for (int i = 0; i < count; i++)
6532 {
6533 pipelines[i] = createProgramPipeline();
6534 }
6535}
6536
6537void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
6538{
6539 for (int i = 0; i < count; i++)
6540 {
6541 if (pipelines[i] != 0)
6542 {
6543 deleteProgramPipeline(pipelines[i]);
6544 }
6545 }
6546}
6547
6548GLboolean Context::isProgramPipeline(GLuint pipeline)
6549{
6550 if (pipeline == 0)
6551 {
6552 return GL_FALSE;
6553 }
6554
6555 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
6556}
6557
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006558void Context::finishFenceNV(GLuint fence)
6559{
6560 FenceNV *fenceObject = getFenceNV(fence);
6561
6562 ASSERT(fenceObject && fenceObject->isSet());
6563 handleError(fenceObject->finish());
6564}
6565
6566void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
6567{
6568 FenceNV *fenceObject = getFenceNV(fence);
6569
6570 ASSERT(fenceObject && fenceObject->isSet());
6571
6572 switch (pname)
6573 {
6574 case GL_FENCE_STATUS_NV:
6575 {
6576 // GL_NV_fence spec:
6577 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
6578 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
6579 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
6580 GLboolean status = GL_TRUE;
6581 if (fenceObject->getStatus() != GL_TRUE)
6582 {
6583 ANGLE_CONTEXT_TRY(fenceObject->test(&status));
6584 }
6585 *params = status;
6586 break;
6587 }
6588
6589 case GL_FENCE_CONDITION_NV:
6590 {
6591 *params = static_cast<GLint>(fenceObject->getCondition());
6592 break;
6593 }
6594
6595 default:
6596 UNREACHABLE();
6597 }
6598}
6599
6600void Context::getTranslatedShaderSource(GLuint shader,
6601 GLsizei bufsize,
6602 GLsizei *length,
6603 GLchar *source)
6604{
6605 Shader *shaderObject = getShader(shader);
6606 ASSERT(shaderObject);
6607 shaderObject->getTranslatedSourceWithDebugInfo(this, bufsize, length, source);
6608}
6609
6610void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
6611{
6612 Program *programObject = getProgram(program);
6613 ASSERT(programObject);
6614
6615 programObject->getUniformfv(this, location, params);
6616}
6617
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006618void Context::getnUniformfvRobust(GLuint program,
6619 GLint location,
6620 GLsizei bufSize,
6621 GLsizei *length,
6622 GLfloat *params)
6623{
6624 UNIMPLEMENTED();
6625}
6626
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006627void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
6628{
6629 Program *programObject = getProgram(program);
6630 ASSERT(programObject);
6631
6632 programObject->getUniformiv(this, location, params);
6633}
6634
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006635void Context::getnUniformivRobust(GLuint program,
6636 GLint location,
6637 GLsizei bufSize,
6638 GLsizei *length,
6639 GLint *params)
6640{
6641 UNIMPLEMENTED();
6642}
6643
6644void Context::getnUniformuivRobust(GLuint program,
6645 GLint location,
6646 GLsizei bufSize,
6647 GLsizei *length,
6648 GLuint *params)
6649{
6650 UNIMPLEMENTED();
6651}
6652
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006653GLboolean Context::isFenceNV(GLuint fence)
6654{
6655 FenceNV *fenceObject = getFenceNV(fence);
6656
6657 if (fenceObject == nullptr)
6658 {
6659 return GL_FALSE;
6660 }
6661
6662 // GL_NV_fence spec:
6663 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
6664 // existing fence.
6665 return fenceObject->isSet();
6666}
6667
6668void Context::readnPixels(GLint x,
6669 GLint y,
6670 GLsizei width,
6671 GLsizei height,
6672 GLenum format,
6673 GLenum type,
6674 GLsizei bufSize,
6675 void *data)
6676{
6677 return readPixels(x, y, width, height, format, type, data);
6678}
6679
Jamie Madill007530e2017-12-28 14:27:04 -05006680void Context::setFenceNV(GLuint fence, GLenum condition)
6681{
6682 ASSERT(condition == GL_ALL_COMPLETED_NV);
6683
6684 FenceNV *fenceObject = getFenceNV(fence);
6685 ASSERT(fenceObject != nullptr);
6686 handleError(fenceObject->set(condition));
6687}
6688
6689GLboolean Context::testFenceNV(GLuint fence)
6690{
6691 FenceNV *fenceObject = getFenceNV(fence);
6692
6693 ASSERT(fenceObject != nullptr);
6694 ASSERT(fenceObject->isSet() == GL_TRUE);
6695
6696 GLboolean result = GL_TRUE;
6697 Error error = fenceObject->test(&result);
6698 if (error.isError())
6699 {
6700 handleError(error);
6701 return GL_TRUE;
6702 }
6703
6704 return result;
6705}
6706
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006707void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006708{
6709 Texture *texture = getTargetTexture(target);
Rafael Cintron05a449a2018-06-20 18:08:04 -07006710 egl::Image *imageObject = static_cast<egl::Image *>(image);
Corentin Wallez99d492c2018-02-27 15:17:10 -05006711 handleError(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05006712}
6713
Jamie Madillfa920eb2018-01-04 11:45:50 -05006714void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006715{
6716 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Rafael Cintron05a449a2018-06-20 18:08:04 -07006717 egl::Image *imageObject = static_cast<egl::Image *>(image);
Jamie Madill007530e2017-12-28 14:27:04 -05006718 handleError(renderbuffer->setStorageEGLImageTarget(this, imageObject));
6719}
6720
Jamie Madillfa920eb2018-01-04 11:45:50 -05006721void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
6722{
6723 UNIMPLEMENTED();
6724}
6725
Jamie Madill5b772312018-03-08 20:28:32 -05006726bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
6727{
6728 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
6729 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
6730 // to the fact that it is stored internally as a float, and so would require conversion
6731 // if returned from Context::getIntegerv. Since this conversion is already implemented
6732 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
6733 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
6734 // application.
6735 switch (pname)
6736 {
6737 case GL_COMPRESSED_TEXTURE_FORMATS:
6738 {
6739 *type = GL_INT;
6740 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
6741 return true;
6742 }
6743 case GL_SHADER_BINARY_FORMATS:
6744 {
6745 *type = GL_INT;
6746 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
6747 return true;
6748 }
6749
6750 case GL_MAX_VERTEX_ATTRIBS:
6751 case GL_MAX_VERTEX_UNIFORM_VECTORS:
6752 case GL_MAX_VARYING_VECTORS:
6753 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
6754 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
6755 case GL_MAX_TEXTURE_IMAGE_UNITS:
6756 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
6757 case GL_MAX_RENDERBUFFER_SIZE:
6758 case GL_NUM_SHADER_BINARY_FORMATS:
6759 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
6760 case GL_ARRAY_BUFFER_BINDING:
6761 case GL_FRAMEBUFFER_BINDING:
6762 case GL_RENDERBUFFER_BINDING:
6763 case GL_CURRENT_PROGRAM:
6764 case GL_PACK_ALIGNMENT:
6765 case GL_UNPACK_ALIGNMENT:
6766 case GL_GENERATE_MIPMAP_HINT:
6767 case GL_RED_BITS:
6768 case GL_GREEN_BITS:
6769 case GL_BLUE_BITS:
6770 case GL_ALPHA_BITS:
6771 case GL_DEPTH_BITS:
6772 case GL_STENCIL_BITS:
6773 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
6774 case GL_CULL_FACE_MODE:
6775 case GL_FRONT_FACE:
6776 case GL_ACTIVE_TEXTURE:
6777 case GL_STENCIL_FUNC:
6778 case GL_STENCIL_VALUE_MASK:
6779 case GL_STENCIL_REF:
6780 case GL_STENCIL_FAIL:
6781 case GL_STENCIL_PASS_DEPTH_FAIL:
6782 case GL_STENCIL_PASS_DEPTH_PASS:
6783 case GL_STENCIL_BACK_FUNC:
6784 case GL_STENCIL_BACK_VALUE_MASK:
6785 case GL_STENCIL_BACK_REF:
6786 case GL_STENCIL_BACK_FAIL:
6787 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
6788 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
6789 case GL_DEPTH_FUNC:
6790 case GL_BLEND_SRC_RGB:
6791 case GL_BLEND_SRC_ALPHA:
6792 case GL_BLEND_DST_RGB:
6793 case GL_BLEND_DST_ALPHA:
6794 case GL_BLEND_EQUATION_RGB:
6795 case GL_BLEND_EQUATION_ALPHA:
6796 case GL_STENCIL_WRITEMASK:
6797 case GL_STENCIL_BACK_WRITEMASK:
6798 case GL_STENCIL_CLEAR_VALUE:
6799 case GL_SUBPIXEL_BITS:
6800 case GL_MAX_TEXTURE_SIZE:
6801 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
6802 case GL_SAMPLE_BUFFERS:
6803 case GL_SAMPLES:
6804 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
6805 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
6806 case GL_TEXTURE_BINDING_2D:
6807 case GL_TEXTURE_BINDING_CUBE_MAP:
6808 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
6809 {
6810 *type = GL_INT;
6811 *numParams = 1;
6812 return true;
6813 }
6814 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6815 {
6816 if (!getExtensions().packReverseRowOrder)
6817 {
6818 return false;
6819 }
6820 *type = GL_INT;
6821 *numParams = 1;
6822 return true;
6823 }
6824 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
6825 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
6826 {
6827 if (!getExtensions().textureRectangle)
6828 {
6829 return false;
6830 }
6831 *type = GL_INT;
6832 *numParams = 1;
6833 return true;
6834 }
6835 case GL_MAX_DRAW_BUFFERS_EXT:
6836 case GL_MAX_COLOR_ATTACHMENTS_EXT:
6837 {
6838 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
6839 {
6840 return false;
6841 }
6842 *type = GL_INT;
6843 *numParams = 1;
6844 return true;
6845 }
6846 case GL_MAX_VIEWPORT_DIMS:
6847 {
6848 *type = GL_INT;
6849 *numParams = 2;
6850 return true;
6851 }
6852 case GL_VIEWPORT:
6853 case GL_SCISSOR_BOX:
6854 {
6855 *type = GL_INT;
6856 *numParams = 4;
6857 return true;
6858 }
6859 case GL_SHADER_COMPILER:
6860 case GL_SAMPLE_COVERAGE_INVERT:
6861 case GL_DEPTH_WRITEMASK:
6862 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
6863 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
6864 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
6865 // bool-natural
6866 case GL_SAMPLE_COVERAGE:
6867 case GL_SCISSOR_TEST:
6868 case GL_STENCIL_TEST:
6869 case GL_DEPTH_TEST:
6870 case GL_BLEND:
6871 case GL_DITHER:
6872 case GL_CONTEXT_ROBUST_ACCESS_EXT:
6873 {
6874 *type = GL_BOOL;
6875 *numParams = 1;
6876 return true;
6877 }
6878 case GL_COLOR_WRITEMASK:
6879 {
6880 *type = GL_BOOL;
6881 *numParams = 4;
6882 return true;
6883 }
6884 case GL_POLYGON_OFFSET_FACTOR:
6885 case GL_POLYGON_OFFSET_UNITS:
6886 case GL_SAMPLE_COVERAGE_VALUE:
6887 case GL_DEPTH_CLEAR_VALUE:
6888 case GL_LINE_WIDTH:
6889 {
6890 *type = GL_FLOAT;
6891 *numParams = 1;
6892 return true;
6893 }
6894 case GL_ALIASED_LINE_WIDTH_RANGE:
6895 case GL_ALIASED_POINT_SIZE_RANGE:
6896 case GL_DEPTH_RANGE:
6897 {
6898 *type = GL_FLOAT;
6899 *numParams = 2;
6900 return true;
6901 }
6902 case GL_COLOR_CLEAR_VALUE:
6903 case GL_BLEND_COLOR:
6904 {
6905 *type = GL_FLOAT;
6906 *numParams = 4;
6907 return true;
6908 }
6909 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
6910 if (!getExtensions().textureFilterAnisotropic)
6911 {
6912 return false;
6913 }
6914 *type = GL_FLOAT;
6915 *numParams = 1;
6916 return true;
6917 case GL_TIMESTAMP_EXT:
6918 if (!getExtensions().disjointTimerQuery)
6919 {
6920 return false;
6921 }
6922 *type = GL_INT_64_ANGLEX;
6923 *numParams = 1;
6924 return true;
6925 case GL_GPU_DISJOINT_EXT:
6926 if (!getExtensions().disjointTimerQuery)
6927 {
6928 return false;
6929 }
6930 *type = GL_INT;
6931 *numParams = 1;
6932 return true;
6933 case GL_COVERAGE_MODULATION_CHROMIUM:
6934 if (!getExtensions().framebufferMixedSamples)
6935 {
6936 return false;
6937 }
6938 *type = GL_INT;
6939 *numParams = 1;
6940 return true;
6941 case GL_TEXTURE_BINDING_EXTERNAL_OES:
6942 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
6943 {
6944 return false;
6945 }
6946 *type = GL_INT;
6947 *numParams = 1;
6948 return true;
6949 }
6950
6951 if (getExtensions().debug)
6952 {
6953 switch (pname)
6954 {
6955 case GL_DEBUG_LOGGED_MESSAGES:
6956 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
6957 case GL_DEBUG_GROUP_STACK_DEPTH:
6958 case GL_MAX_DEBUG_MESSAGE_LENGTH:
6959 case GL_MAX_DEBUG_LOGGED_MESSAGES:
6960 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
6961 case GL_MAX_LABEL_LENGTH:
6962 *type = GL_INT;
6963 *numParams = 1;
6964 return true;
6965
6966 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
6967 case GL_DEBUG_OUTPUT:
6968 *type = GL_BOOL;
6969 *numParams = 1;
6970 return true;
6971 }
6972 }
6973
6974 if (getExtensions().multisampleCompatibility)
6975 {
6976 switch (pname)
6977 {
6978 case GL_MULTISAMPLE_EXT:
6979 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
6980 *type = GL_BOOL;
6981 *numParams = 1;
6982 return true;
6983 }
6984 }
6985
6986 if (getExtensions().pathRendering)
6987 {
6988 switch (pname)
6989 {
6990 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
6991 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
6992 *type = GL_FLOAT;
6993 *numParams = 16;
6994 return true;
6995 }
6996 }
6997
6998 if (getExtensions().bindGeneratesResource)
6999 {
7000 switch (pname)
7001 {
7002 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
7003 *type = GL_BOOL;
7004 *numParams = 1;
7005 return true;
7006 }
7007 }
7008
7009 if (getExtensions().clientArrays)
7010 {
7011 switch (pname)
7012 {
7013 case GL_CLIENT_ARRAYS_ANGLE:
7014 *type = GL_BOOL;
7015 *numParams = 1;
7016 return true;
7017 }
7018 }
7019
7020 if (getExtensions().sRGBWriteControl)
7021 {
7022 switch (pname)
7023 {
7024 case GL_FRAMEBUFFER_SRGB_EXT:
7025 *type = GL_BOOL;
7026 *numParams = 1;
7027 return true;
7028 }
7029 }
7030
7031 if (getExtensions().robustResourceInitialization &&
7032 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
7033 {
7034 *type = GL_BOOL;
7035 *numParams = 1;
7036 return true;
7037 }
7038
7039 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
7040 {
7041 *type = GL_BOOL;
7042 *numParams = 1;
7043 return true;
7044 }
7045
jchen1082af6202018-06-22 10:59:52 +08007046 if (getExtensions().parallelShaderCompile && pname == GL_MAX_SHADER_COMPILER_THREADS_KHR)
7047 {
7048 *type = GL_INT;
7049 *numParams = 1;
7050 return true;
7051 }
7052
Jamie Madill5b772312018-03-08 20:28:32 -05007053 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
7054 switch (pname)
7055 {
7056 // case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE // equivalent to FRAMEBUFFER_BINDING
7057 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
7058 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
7059 {
7060 return false;
7061 }
7062 *type = GL_INT;
7063 *numParams = 1;
7064 return true;
7065
7066 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
7067 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7068 {
7069 return false;
7070 }
7071 *type = GL_INT;
7072 *numParams = 1;
7073 return true;
7074
7075 case GL_PROGRAM_BINARY_FORMATS_OES:
7076 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7077 {
7078 return false;
7079 }
7080 *type = GL_INT;
7081 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
7082 return true;
7083
7084 case GL_PACK_ROW_LENGTH:
7085 case GL_PACK_SKIP_ROWS:
7086 case GL_PACK_SKIP_PIXELS:
7087 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
7088 {
7089 return false;
7090 }
7091 *type = GL_INT;
7092 *numParams = 1;
7093 return true;
7094 case GL_UNPACK_ROW_LENGTH:
7095 case GL_UNPACK_SKIP_ROWS:
7096 case GL_UNPACK_SKIP_PIXELS:
7097 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
7098 {
7099 return false;
7100 }
7101 *type = GL_INT;
7102 *numParams = 1;
7103 return true;
7104 case GL_VERTEX_ARRAY_BINDING:
7105 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
7106 {
7107 return false;
7108 }
7109 *type = GL_INT;
7110 *numParams = 1;
7111 return true;
7112 case GL_PIXEL_PACK_BUFFER_BINDING:
7113 case GL_PIXEL_UNPACK_BUFFER_BINDING:
7114 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
7115 {
7116 return false;
7117 }
7118 *type = GL_INT;
7119 *numParams = 1;
7120 return true;
7121 case GL_MAX_SAMPLES:
7122 {
7123 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
7124 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
7125 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
7126 {
7127 return false;
7128 }
7129 *type = GL_INT;
7130 *numParams = 1;
7131 return true;
7132
7133 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
7134 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
7135 {
7136 return false;
7137 }
7138 *type = GL_INT;
7139 *numParams = 1;
7140 return true;
7141 }
7142 }
7143
7144 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
7145 {
7146 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
7147 {
7148 return false;
7149 }
7150 *type = GL_INT;
7151 *numParams = 1;
7152 return true;
7153 }
7154
7155 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
7156 {
7157 *type = GL_INT;
7158 *numParams = 1;
7159 return true;
7160 }
7161
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007162 if (getClientVersion() < Version(2, 0))
7163 {
7164 switch (pname)
7165 {
7166 case GL_ALPHA_TEST_FUNC:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007167 case GL_CLIENT_ACTIVE_TEXTURE:
7168 case GL_MATRIX_MODE:
7169 case GL_MAX_TEXTURE_UNITS:
7170 case GL_MAX_MODELVIEW_STACK_DEPTH:
7171 case GL_MAX_PROJECTION_STACK_DEPTH:
7172 case GL_MAX_TEXTURE_STACK_DEPTH:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007173 case GL_MAX_LIGHTS:
Lingfeng Yang060088a2018-05-30 20:40:57 -07007174 case GL_MAX_CLIP_PLANES:
Lingfeng Yangabb09f12018-04-16 10:43:53 -07007175 case GL_VERTEX_ARRAY_STRIDE:
7176 case GL_NORMAL_ARRAY_STRIDE:
7177 case GL_COLOR_ARRAY_STRIDE:
7178 case GL_TEXTURE_COORD_ARRAY_STRIDE:
7179 case GL_VERTEX_ARRAY_SIZE:
7180 case GL_COLOR_ARRAY_SIZE:
7181 case GL_TEXTURE_COORD_ARRAY_SIZE:
7182 case GL_VERTEX_ARRAY_TYPE:
7183 case GL_NORMAL_ARRAY_TYPE:
7184 case GL_COLOR_ARRAY_TYPE:
7185 case GL_TEXTURE_COORD_ARRAY_TYPE:
7186 case GL_VERTEX_ARRAY_BUFFER_BINDING:
7187 case GL_NORMAL_ARRAY_BUFFER_BINDING:
7188 case GL_COLOR_ARRAY_BUFFER_BINDING:
7189 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
7190 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
7191 case GL_POINT_SIZE_ARRAY_TYPE_OES:
7192 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
Lingfeng Yanga0cfa872018-05-30 21:12:17 -07007193 case GL_SHADE_MODEL:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007194 *type = GL_INT;
7195 *numParams = 1;
7196 return true;
7197 case GL_ALPHA_TEST_REF:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007198 case GL_FOG_DENSITY:
7199 case GL_FOG_START:
7200 case GL_FOG_END:
7201 case GL_FOG_MODE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007202 case GL_POINT_SIZE:
7203 case GL_POINT_SIZE_MIN:
7204 case GL_POINT_SIZE_MAX:
7205 case GL_POINT_FADE_THRESHOLD_SIZE:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007206 *type = GL_FLOAT;
7207 *numParams = 1;
7208 return true;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007209 case GL_SMOOTH_POINT_SIZE_RANGE:
7210 *type = GL_FLOAT;
7211 *numParams = 2;
7212 return true;
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007213 case GL_CURRENT_COLOR:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007214 case GL_CURRENT_TEXTURE_COORDS:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007215 case GL_LIGHT_MODEL_AMBIENT:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007216 case GL_FOG_COLOR:
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007217 *type = GL_FLOAT;
7218 *numParams = 4;
7219 return true;
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007220 case GL_CURRENT_NORMAL:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007221 case GL_POINT_DISTANCE_ATTENUATION:
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007222 *type = GL_FLOAT;
7223 *numParams = 3;
7224 return true;
Lingfeng Yang3a41af62018-04-09 07:28:56 -07007225 case GL_MODELVIEW_MATRIX:
7226 case GL_PROJECTION_MATRIX:
7227 case GL_TEXTURE_MATRIX:
7228 *type = GL_FLOAT;
7229 *numParams = 16;
7230 return true;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007231 case GL_LIGHT_MODEL_TWO_SIDE:
7232 *type = GL_BOOL;
7233 *numParams = 1;
7234 return true;
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007235 }
7236 }
7237
Jamie Madill5b772312018-03-08 20:28:32 -05007238 if (getClientVersion() < Version(3, 0))
7239 {
7240 return false;
7241 }
7242
7243 // Check for ES3.0+ parameter names
7244 switch (pname)
7245 {
7246 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
7247 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
7248 case GL_UNIFORM_BUFFER_BINDING:
7249 case GL_TRANSFORM_FEEDBACK_BINDING:
7250 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7251 case GL_COPY_READ_BUFFER_BINDING:
7252 case GL_COPY_WRITE_BUFFER_BINDING:
7253 case GL_SAMPLER_BINDING:
7254 case GL_READ_BUFFER:
7255 case GL_TEXTURE_BINDING_3D:
7256 case GL_TEXTURE_BINDING_2D_ARRAY:
7257 case GL_MAX_3D_TEXTURE_SIZE:
7258 case GL_MAX_ARRAY_TEXTURE_LAYERS:
7259 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
7260 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
7261 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
7262 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
7263 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
7264 case GL_MAX_VARYING_COMPONENTS:
7265 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
7266 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
7267 case GL_MIN_PROGRAM_TEXEL_OFFSET:
7268 case GL_MAX_PROGRAM_TEXEL_OFFSET:
7269 case GL_NUM_EXTENSIONS:
7270 case GL_MAJOR_VERSION:
7271 case GL_MINOR_VERSION:
7272 case GL_MAX_ELEMENTS_INDICES:
7273 case GL_MAX_ELEMENTS_VERTICES:
7274 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
7275 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
7276 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
7277 case GL_UNPACK_IMAGE_HEIGHT:
7278 case GL_UNPACK_SKIP_IMAGES:
7279 {
7280 *type = GL_INT;
7281 *numParams = 1;
7282 return true;
7283 }
7284
7285 case GL_MAX_ELEMENT_INDEX:
7286 case GL_MAX_UNIFORM_BLOCK_SIZE:
7287 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
7288 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
7289 case GL_MAX_SERVER_WAIT_TIMEOUT:
7290 {
7291 *type = GL_INT_64_ANGLEX;
7292 *numParams = 1;
7293 return true;
7294 }
7295
7296 case GL_TRANSFORM_FEEDBACK_ACTIVE:
7297 case GL_TRANSFORM_FEEDBACK_PAUSED:
7298 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
7299 case GL_RASTERIZER_DISCARD:
7300 {
7301 *type = GL_BOOL;
7302 *numParams = 1;
7303 return true;
7304 }
7305
7306 case GL_MAX_TEXTURE_LOD_BIAS:
7307 {
7308 *type = GL_FLOAT;
7309 *numParams = 1;
7310 return true;
7311 }
7312 }
7313
7314 if (getExtensions().requestExtension)
7315 {
7316 switch (pname)
7317 {
7318 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
7319 *type = GL_INT;
7320 *numParams = 1;
7321 return true;
7322 }
7323 }
7324
7325 if (getClientVersion() < Version(3, 1))
7326 {
7327 return false;
7328 }
7329
7330 switch (pname)
7331 {
7332 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7333 case GL_DRAW_INDIRECT_BUFFER_BINDING:
7334 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
7335 case GL_MAX_FRAMEBUFFER_WIDTH:
7336 case GL_MAX_FRAMEBUFFER_HEIGHT:
7337 case GL_MAX_FRAMEBUFFER_SAMPLES:
7338 case GL_MAX_SAMPLE_MASK_WORDS:
7339 case GL_MAX_COLOR_TEXTURE_SAMPLES:
7340 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
7341 case GL_MAX_INTEGER_SAMPLES:
7342 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
7343 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
7344 case GL_MAX_VERTEX_ATTRIB_STRIDE:
7345 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
7346 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
7347 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
7348 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
7349 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
7350 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
7351 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
7352 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
7353 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
7354 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
7355 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
7356 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
7357 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
7358 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
7359 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
7360 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
7361 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
7362 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
7363 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
7364 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
7365 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
7366 case GL_MAX_UNIFORM_LOCATIONS:
7367 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
7368 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
7369 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
7370 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
7371 case GL_MAX_IMAGE_UNITS:
7372 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
7373 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
7374 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
7375 case GL_SHADER_STORAGE_BUFFER_BINDING:
7376 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
7377 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
7378 *type = GL_INT;
7379 *numParams = 1;
7380 return true;
7381 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7382 *type = GL_INT_64_ANGLEX;
7383 *numParams = 1;
7384 return true;
7385 case GL_SAMPLE_MASK:
7386 *type = GL_BOOL;
7387 *numParams = 1;
7388 return true;
7389 }
7390
7391 if (getExtensions().geometryShader)
7392 {
7393 switch (pname)
7394 {
7395 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7396 case GL_LAYER_PROVOKING_VERTEX_EXT:
7397 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7398 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7399 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7400 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7401 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7402 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7403 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7404 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7405 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7406 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7407 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7408 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7409 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7410 *type = GL_INT;
7411 *numParams = 1;
7412 return true;
7413 }
7414 }
7415
7416 return false;
7417}
7418
7419bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7420{
7421 if (getClientVersion() < Version(3, 0))
7422 {
7423 return false;
7424 }
7425
7426 switch (target)
7427 {
7428 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7429 case GL_UNIFORM_BUFFER_BINDING:
7430 {
7431 *type = GL_INT;
7432 *numParams = 1;
7433 return true;
7434 }
7435 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7436 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7437 case GL_UNIFORM_BUFFER_START:
7438 case GL_UNIFORM_BUFFER_SIZE:
7439 {
7440 *type = GL_INT_64_ANGLEX;
7441 *numParams = 1;
7442 return true;
7443 }
7444 }
7445
7446 if (getClientVersion() < Version(3, 1))
7447 {
7448 return false;
7449 }
7450
7451 switch (target)
7452 {
7453 case GL_IMAGE_BINDING_LAYERED:
7454 {
7455 *type = GL_BOOL;
7456 *numParams = 1;
7457 return true;
7458 }
7459 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7460 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7461 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7462 case GL_SHADER_STORAGE_BUFFER_BINDING:
7463 case GL_VERTEX_BINDING_BUFFER:
7464 case GL_VERTEX_BINDING_DIVISOR:
7465 case GL_VERTEX_BINDING_OFFSET:
7466 case GL_VERTEX_BINDING_STRIDE:
7467 case GL_SAMPLE_MASK_VALUE:
7468 case GL_IMAGE_BINDING_NAME:
7469 case GL_IMAGE_BINDING_LEVEL:
7470 case GL_IMAGE_BINDING_LAYER:
7471 case GL_IMAGE_BINDING_ACCESS:
7472 case GL_IMAGE_BINDING_FORMAT:
7473 {
7474 *type = GL_INT;
7475 *numParams = 1;
7476 return true;
7477 }
7478 case GL_ATOMIC_COUNTER_BUFFER_START:
7479 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
7480 case GL_SHADER_STORAGE_BUFFER_START:
7481 case GL_SHADER_STORAGE_BUFFER_SIZE:
7482 {
7483 *type = GL_INT_64_ANGLEX;
7484 *numParams = 1;
7485 return true;
7486 }
7487 }
7488
7489 return false;
7490}
7491
7492Program *Context::getProgram(GLuint handle) const
7493{
7494 return mState.mShaderPrograms->getProgram(handle);
7495}
7496
7497Shader *Context::getShader(GLuint handle) const
7498{
7499 return mState.mShaderPrograms->getShader(handle);
7500}
7501
7502bool Context::isTextureGenerated(GLuint texture) const
7503{
7504 return mState.mTextures->isHandleGenerated(texture);
7505}
7506
7507bool Context::isBufferGenerated(GLuint buffer) const
7508{
7509 return mState.mBuffers->isHandleGenerated(buffer);
7510}
7511
7512bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
7513{
7514 return mState.mRenderbuffers->isHandleGenerated(renderbuffer);
7515}
7516
7517bool Context::isFramebufferGenerated(GLuint framebuffer) const
7518{
7519 return mState.mFramebuffers->isHandleGenerated(framebuffer);
7520}
7521
7522bool Context::isProgramPipelineGenerated(GLuint pipeline) const
7523{
7524 return mState.mPipelines->isHandleGenerated(pipeline);
7525}
7526
7527bool Context::usingDisplayTextureShareGroup() const
7528{
7529 return mDisplayTextureShareGroup;
7530}
7531
7532GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
7533{
7534 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
7535 internalformat == GL_DEPTH_STENCIL
7536 ? GL_DEPTH24_STENCIL8
7537 : internalformat;
7538}
7539
jchen1082af6202018-06-22 10:59:52 +08007540void Context::maxShaderCompilerThreads(GLuint count)
7541{
7542 mGLState.setMaxShaderCompilerThreads(count);
7543}
7544
Jamie Madillc29968b2016-01-20 11:17:23 -05007545} // namespace gl