blob: 80a90d76975974ae833647b27d381df105604e67 [file] [log] [blame]
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001//
Geoff Langeeba6e12014-02-03 13:12:30 -05002// Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7// Context.cpp: Implements the gl::Context class, managing all GL state and performing
8// rendering operations. It is the GLES2 specific implementation of EGLContext.
9
Geoff Lang2b5420c2014-11-19 14:20:15 -050010#include "libANGLE/Context.h"
apatrick@chromium.org144f2802012-07-12 01:42:34 +000011
Jamie Madill231c7f52017-04-26 13:45:37 -040012#include <string.h>
Jamie Madillb9293972015-02-19 11:07:54 -050013#include <iterator>
14#include <sstream>
Sami Väisänend59ca052016-06-21 16:10:00 +030015#include <vector>
Jamie Madillb9293972015-02-19 11:07:54 -050016
Tobin Ehlisd7890bc2018-06-29 11:57:22 -060017#include "common/PackedEnums.h"
Sami Väisänene45e53b2016-05-25 10:36:04 +030018#include "common/matrix_utils.h"
Geoff Lang0b7eef72014-06-12 14:10:47 -040019#include "common/platform.h"
Jamie Madillb9293972015-02-19 11:07:54 -050020#include "common/utilities.h"
Geoff Langc339c4e2016-11-29 10:37:36 -050021#include "common/version.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050022#include "libANGLE/Buffer.h"
Jamie Madillb9293972015-02-19 11:07:54 -050023#include "libANGLE/Compiler.h"
Jamie Madill948bbe52017-06-01 13:10:42 -040024#include "libANGLE/Display.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050025#include "libANGLE/Fence.h"
26#include "libANGLE/Framebuffer.h"
27#include "libANGLE/FramebufferAttachment.h"
Lingfeng Yang461b09a2018-04-23 09:02:09 -070028#include "libANGLE/GLES1Renderer.h"
Sami Väisänene45e53b2016-05-25 10:36:04 +030029#include "libANGLE/Path.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050030#include "libANGLE/Program.h"
Yunchao Hea336b902017-08-02 16:05:21 +080031#include "libANGLE/ProgramPipeline.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050032#include "libANGLE/Query.h"
Jamie Madillb9293972015-02-19 11:07:54 -050033#include "libANGLE/Renderbuffer.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050034#include "libANGLE/ResourceManager.h"
35#include "libANGLE/Sampler.h"
Jamie Madill9dd0cf02014-11-24 11:38:51 -050036#include "libANGLE/Surface.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050037#include "libANGLE/Texture.h"
38#include "libANGLE/TransformFeedback.h"
39#include "libANGLE/VertexArray.h"
Kenneth Russellf2f6f652016-10-05 19:53:23 -070040#include "libANGLE/Workarounds.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040041#include "libANGLE/formatutils.h"
Martin Radev66fb8202016-07-28 11:45:20 +030042#include "libANGLE/queryconversions.h"
Geoff Langc1984ed2016-10-07 12:41:00 -040043#include "libANGLE/queryutils.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040044#include "libANGLE/renderer/ContextImpl.h"
45#include "libANGLE/renderer/EGLImplFactory.h"
Jamie Madill7b62cf92017-11-02 15:20:49 -040046#include "libANGLE/renderer/Format.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040047#include "libANGLE/validationES.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000048
Geoff Langf6db0982015-08-25 13:04:00 -040049namespace
50{
51
Jamie Madillb6664922017-07-25 12:55:04 -040052#define ANGLE_HANDLE_ERR(X) \
53 handleError(X); \
54 return;
55#define ANGLE_CONTEXT_TRY(EXPR) ANGLE_TRY_TEMPLATE(EXPR, ANGLE_HANDLE_ERR);
56
Ian Ewell3ffd78b2016-01-22 16:09:42 -050057template <typename T>
Geoff Lang4ddf5af2016-12-01 14:30:44 -050058std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager,
Sami Väisänend59ca052016-06-21 16:10:00 +030059 GLsizei numPaths,
60 const void *paths,
61 GLuint pathBase)
62{
63 std::vector<gl::Path *> ret;
64 ret.reserve(numPaths);
65
66 const auto *nameArray = static_cast<const T *>(paths);
67
68 for (GLsizei i = 0; i < numPaths; ++i)
69 {
70 const GLuint pathName = nameArray[i] + pathBase;
71
72 ret.push_back(resourceManager.getPath(pathName));
73 }
74
75 return ret;
76}
77
Geoff Lang4ddf5af2016-12-01 14:30:44 -050078std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager,
Sami Väisänend59ca052016-06-21 16:10:00 +030079 GLsizei numPaths,
80 GLenum pathNameType,
81 const void *paths,
82 GLuint pathBase)
83{
84 switch (pathNameType)
85 {
86 case GL_UNSIGNED_BYTE:
87 return GatherPaths<GLubyte>(resourceManager, numPaths, paths, pathBase);
88
89 case GL_BYTE:
90 return GatherPaths<GLbyte>(resourceManager, numPaths, paths, pathBase);
91
92 case GL_UNSIGNED_SHORT:
93 return GatherPaths<GLushort>(resourceManager, numPaths, paths, pathBase);
94
95 case GL_SHORT:
96 return GatherPaths<GLshort>(resourceManager, numPaths, paths, pathBase);
97
98 case GL_UNSIGNED_INT:
99 return GatherPaths<GLuint>(resourceManager, numPaths, paths, pathBase);
100
101 case GL_INT:
102 return GatherPaths<GLint>(resourceManager, numPaths, paths, pathBase);
103 }
104
105 UNREACHABLE();
106 return std::vector<gl::Path *>();
107}
108
109template <typename T>
Geoff Lang2186c382016-10-14 10:54:54 -0400110gl::Error GetQueryObjectParameter(gl::Query *query, GLenum pname, T *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500111{
Geoff Lang2186c382016-10-14 10:54:54 -0400112 ASSERT(query != nullptr);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500113
114 switch (pname)
115 {
116 case GL_QUERY_RESULT_EXT:
Geoff Lang2186c382016-10-14 10:54:54 -0400117 return query->getResult(params);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500118 case GL_QUERY_RESULT_AVAILABLE_EXT:
119 {
120 bool available;
Geoff Lang2186c382016-10-14 10:54:54 -0400121 gl::Error error = query->isResultAvailable(&available);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500122 if (!error.isError())
123 {
jchen10a99ed552017-09-22 08:10:32 +0800124 *params = gl::CastFromStateValue<T>(pname, static_cast<GLuint>(available));
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500125 }
126 return error;
127 }
128 default:
129 UNREACHABLE();
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500130 return gl::InternalError() << "Unreachable Error";
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500131 }
132}
133
Jamie Madill09463932018-04-04 05:26:59 -0400134void MarkTransformFeedbackBufferUsage(const gl::Context *context,
135 gl::TransformFeedback *transformFeedback,
James Darpinian30b604d2018-03-12 17:26:57 -0700136 GLsizei count,
137 GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -0400138{
Geoff Lang1a683462015-09-29 15:09:59 -0400139 if (transformFeedback && transformFeedback->isActive() && !transformFeedback->isPaused())
Geoff Langf6db0982015-08-25 13:04:00 -0400140 {
Jamie Madill09463932018-04-04 05:26:59 -0400141 transformFeedback->onVerticesDrawn(context, count, instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -0400142 }
143}
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500144
145// Attribute map queries.
Martin Radev1be913c2016-07-11 17:59:16 +0300146EGLint GetClientMajorVersion(const egl::AttributeMap &attribs)
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500147{
Ian Ewellec2c0c52016-04-05 13:46:26 -0400148 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_CLIENT_VERSION, 1));
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500149}
150
Martin Radev1be913c2016-07-11 17:59:16 +0300151EGLint GetClientMinorVersion(const egl::AttributeMap &attribs)
152{
153 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_MINOR_VERSION, 0));
154}
155
Geoff Langeb66a6e2016-10-31 13:06:12 -0400156gl::Version GetClientVersion(const egl::AttributeMap &attribs)
157{
158 return gl::Version(GetClientMajorVersion(attribs), GetClientMinorVersion(attribs));
159}
160
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500161GLenum GetResetStrategy(const egl::AttributeMap &attribs)
162{
Lingfeng Yangb27b03a2018-02-19 13:38:48 -0800163 EGLAttrib attrib =
164 attribs.get(EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT, EGL_NO_RESET_NOTIFICATION);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500165 switch (attrib)
166 {
167 case EGL_NO_RESET_NOTIFICATION:
168 return GL_NO_RESET_NOTIFICATION_EXT;
169 case EGL_LOSE_CONTEXT_ON_RESET:
170 return GL_LOSE_CONTEXT_ON_RESET_EXT;
171 default:
172 UNREACHABLE();
173 return GL_NONE;
174 }
175}
176
177bool GetRobustAccess(const egl::AttributeMap &attribs)
178{
Geoff Lang077f20a2016-11-01 10:08:02 -0400179 return (attribs.get(EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT, EGL_FALSE) == EGL_TRUE) ||
180 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR) !=
181 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500182}
183
184bool GetDebug(const egl::AttributeMap &attribs)
185{
Geoff Lang077f20a2016-11-01 10:08:02 -0400186 return (attribs.get(EGL_CONTEXT_OPENGL_DEBUG, EGL_FALSE) == EGL_TRUE) ||
187 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR) != 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500188}
189
190bool GetNoError(const egl::AttributeMap &attribs)
191{
192 return (attribs.get(EGL_CONTEXT_OPENGL_NO_ERROR_KHR, EGL_FALSE) == EGL_TRUE);
193}
194
Geoff Langc287ea62016-09-16 14:46:51 -0400195bool GetWebGLContext(const egl::AttributeMap &attribs)
196{
197 return (attribs.get(EGL_CONTEXT_WEBGL_COMPATIBILITY_ANGLE, EGL_FALSE) == EGL_TRUE);
198}
199
Geoff Lang0ab41fa2018-03-14 11:03:30 -0400200bool GetExtensionsEnabled(const egl::AttributeMap &attribs, bool webGLContext)
201{
202 // If the context is WebGL, extensions are disabled by default
203 EGLAttrib defaultValue = webGLContext ? EGL_FALSE : EGL_TRUE;
204 return (attribs.get(EGL_EXTENSIONS_ENABLED_ANGLE, defaultValue) == EGL_TRUE);
205}
206
Geoff Langf41a7152016-09-19 15:11:17 -0400207bool GetBindGeneratesResource(const egl::AttributeMap &attribs)
208{
209 return (attribs.get(EGL_CONTEXT_BIND_GENERATES_RESOURCE_CHROMIUM, EGL_TRUE) == EGL_TRUE);
210}
211
Geoff Langfeb8c682017-02-13 16:07:35 -0500212bool GetClientArraysEnabled(const egl::AttributeMap &attribs)
213{
214 return (attribs.get(EGL_CONTEXT_CLIENT_ARRAYS_ENABLED_ANGLE, EGL_TRUE) == EGL_TRUE);
215}
216
Geoff Langb433e872017-10-05 14:01:47 -0400217bool GetRobustResourceInit(const egl::AttributeMap &attribs)
218{
219 return (attribs.get(EGL_ROBUST_RESOURCE_INITIALIZATION_ANGLE, EGL_FALSE) == EGL_TRUE);
220}
221
Martin Radev9d901792016-07-15 15:58:58 +0300222std::string GetObjectLabelFromPointer(GLsizei length, const GLchar *label)
223{
224 std::string labelName;
225 if (label != nullptr)
226 {
227 size_t labelLength = length < 0 ? strlen(label) : length;
228 labelName = std::string(label, labelLength);
229 }
230 return labelName;
231}
232
233void GetObjectLabelBase(const std::string &objectLabel,
234 GLsizei bufSize,
235 GLsizei *length,
236 GLchar *label)
237{
238 size_t writeLength = objectLabel.length();
239 if (label != nullptr && bufSize > 0)
240 {
241 writeLength = std::min(static_cast<size_t>(bufSize) - 1, objectLabel.length());
242 std::copy(objectLabel.begin(), objectLabel.begin() + writeLength, label);
243 label[writeLength] = '\0';
244 }
245
246 if (length != nullptr)
247 {
248 *length = static_cast<GLsizei>(writeLength);
249 }
250}
251
Jamie Madill0f80ed82017-09-19 00:24:56 -0400252template <typename CapT, typename MaxT>
253void LimitCap(CapT *cap, MaxT maximum)
254{
255 *cap = std::min(*cap, static_cast<CapT>(maximum));
256}
257
Tobin Ehlisd7890bc2018-06-29 11:57:22 -0600258constexpr angle::PackedEnumMap<gl::PrimitiveMode, GLsizei> kMinimumPrimitiveCounts = {{
259 /* Points */ 1,
260 /* Lines */ 2,
261 /* LineLoop */ 2,
262 /* LineStrip */ 2,
263 /* Triangles */ 3,
264 /* TriangleStrip */ 3,
265 /* TriangleFan */ 3,
266 /* LinesAdjacency */ 2,
267 /* LineStripAdjacency */ 2,
268 /* TrianglesAdjacency */ 3,
269 /* TriangleStripAdjacency */ 3,
270}};
271// Indices above are code-gen'd so make sure they don't change
272// if any of these static asserts are hit, must update kMinimumPrimitiveCounts abouve
273static_assert(static_cast<gl::PrimitiveMode>(0) == gl::PrimitiveMode::Points,
274 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
275static_assert(static_cast<gl::PrimitiveMode>(1) == gl::PrimitiveMode::Lines,
276 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
277static_assert(static_cast<gl::PrimitiveMode>(2) == gl::PrimitiveMode::LineLoop,
278 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
279static_assert(static_cast<gl::PrimitiveMode>(3) == gl::PrimitiveMode::LineStrip,
280 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
281static_assert(static_cast<gl::PrimitiveMode>(4) == gl::PrimitiveMode::Triangles,
282 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
283static_assert(static_cast<gl::PrimitiveMode>(5) == gl::PrimitiveMode::TriangleStrip,
284 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
285static_assert(static_cast<gl::PrimitiveMode>(6) == gl::PrimitiveMode::TriangleFan,
286 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
287static_assert(static_cast<gl::PrimitiveMode>(7) == gl::PrimitiveMode::LinesAdjacency,
288 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
289static_assert(static_cast<gl::PrimitiveMode>(8) == gl::PrimitiveMode::LineStripAdjacency,
290 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
291static_assert(static_cast<gl::PrimitiveMode>(9) == gl::PrimitiveMode::TrianglesAdjacency,
292 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
293static_assert(static_cast<gl::PrimitiveMode>(10) == gl::PrimitiveMode::TriangleStripAdjacency,
294 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
295static_assert(static_cast<gl::PrimitiveMode>(11) == gl::PrimitiveMode::EnumCount,
296 "gl::PrimitiveMode enum values have changed, update kMinimumPrimitiveCounts.");
297
Geoff Langf6db0982015-08-25 13:04:00 -0400298} // anonymous namespace
299
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000300namespace gl
301{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +0000302
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400303Context::Context(rx::EGLImplFactory *implFactory,
304 const egl::Config *config,
Corentin Wallez51706ea2015-08-07 14:39:22 -0400305 const Context *shareContext,
Geoff Langce02f082017-02-06 16:46:21 -0500306 TextureManager *shareTextures,
Jamie Madill32447362017-06-28 14:53:52 -0400307 MemoryProgramCache *memoryProgramCache,
Corentin Wallezc295e512017-01-27 17:47:50 -0500308 const egl::AttributeMap &attribs,
Brandon Jones2b0cdcc2018-05-02 08:02:50 -0700309 const egl::DisplayExtensions &displayExtensions,
310 const egl::ClientExtensions &clientExtensions)
Jamie Madill5b772312018-03-08 20:28:32 -0500311 : mState(reinterpret_cast<ContextID>(this),
312 shareContext ? &shareContext->mState : nullptr,
313 shareTextures,
314 GetClientVersion(attribs),
315 &mGLState,
316 mCaps,
317 mTextureCaps,
318 mExtensions,
319 mLimitations),
320 mSkipValidation(GetNoError(attribs)),
321 mDisplayTextureShareGroup(shareTextures != nullptr),
322 mSavedArgsType(nullptr),
Geoff Lang3cacf692018-06-20 16:49:57 -0400323 mImplementation(implFactory->createContext(mState, config, shareContext, attribs)),
Geoff Lang75359662018-04-11 01:42:27 -0400324 mLabel(nullptr),
Jamie Madill2f348d22017-06-05 10:50:59 -0400325 mCompiler(),
Geoff Lang4fb8a8b2018-06-01 16:47:57 -0400326 mGLState(GetDebug(attribs),
327 GetBindGeneratesResource(attribs),
328 GetClientArraysEnabled(attribs),
329 GetRobustResourceInit(attribs),
330 memoryProgramCache != nullptr),
Corentin Walleze3b10e82015-05-20 11:06:25 -0400331 mConfig(config),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500332 mClientType(EGL_OPENGL_ES_API),
Jamie Madill6b873dd2018-07-12 23:56:30 -0400333 mErrors(this),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500334 mHasBeenCurrent(false),
335 mContextLost(false),
336 mResetStatus(GL_NO_ERROR),
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700337 mContextLostForced(false),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500338 mResetStrategy(GetResetStrategy(attribs)),
339 mRobustAccess(GetRobustAccess(attribs)),
Geoff Lang33f11fb2018-05-07 13:42:47 -0400340 mSurfacelessSupported(displayExtensions.surfacelessContext),
341 mExplicitContextAvailable(clientExtensions.explicitContext),
Jamie Madill61e16b42017-06-19 11:13:23 -0400342 mCurrentSurface(static_cast<egl::Surface *>(EGL_NO_SURFACE)),
343 mCurrentDisplay(static_cast<egl::Display *>(EGL_NO_DISPLAY)),
Jamie Madille14951e2017-03-09 18:55:16 -0500344 mWebGLContext(GetWebGLContext(attribs)),
Geoff Lang0ab41fa2018-03-14 11:03:30 -0400345 mExtensionsEnabled(GetExtensionsEnabled(attribs, mWebGLContext)),
Jamie Madill32447362017-06-28 14:53:52 -0400346 mMemoryProgramCache(memoryProgramCache),
Jamie Madillb3f26b92017-07-19 15:07:41 -0400347 mScratchBuffer(1000u),
348 mZeroFilledBuffer(1000u)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000349{
Jamie Madill5b772312018-03-08 20:28:32 -0500350 // Needed to solve a Clang warning of unused variables.
Jamie Madillc6dbc252018-04-30 19:07:56 -0400351 ANGLE_UNUSED_VARIABLE(mSavedArgsType);
352 ANGLE_UNUSED_VARIABLE(mParamsBuffer);
Geoff Lang33f11fb2018-05-07 13:42:47 -0400353}
Jamie Madill5b772312018-03-08 20:28:32 -0500354
Geoff Lang33f11fb2018-05-07 13:42:47 -0400355void Context::initialize()
356{
357 mImplementation->setMemoryProgramCache(mMemoryProgramCache);
Jamie Madill14bbb3f2017-09-12 15:23:01 -0400358
Geoff Lang33f11fb2018-05-07 13:42:47 -0400359 initCaps();
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700360 initWorkarounds();
Geoff Langc0b9ef42014-07-02 10:02:37 -0400361
Geoff Lang4fb8a8b2018-06-01 16:47:57 -0400362 mGLState.initialize(this);
Régis Fénéon83107972015-02-05 12:57:44 +0100363
Shannon Woods53a94a82014-06-24 15:20:36 -0400364 mFenceNVHandleAllocator.setBaseHandle(0);
Geoff Lang7dca1862013-07-30 16:30:46 -0400365
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000366 // [OpenGL ES 2.0.24] section 3.7 page 83:
Corentin Wallez336129f2017-10-17 15:55:40 -0400367 // In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have two-dimensional
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000368 // and cube map texture state vectors respectively associated with them.
369 // In order that access to these initial textures not be lost, they are treated as texture
370 // objects all of whose names are 0.
371
Corentin Wallez99d492c2018-02-27 15:17:10 -0500372 Texture *zeroTexture2D = new Texture(mImplementation.get(), 0, TextureType::_2D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800373 mZeroTextures[TextureType::_2D].set(this, zeroTexture2D);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500374
Corentin Wallez99d492c2018-02-27 15:17:10 -0500375 Texture *zeroTextureCube = new Texture(mImplementation.get(), 0, TextureType::CubeMap);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800376 mZeroTextures[TextureType::CubeMap].set(this, zeroTextureCube);
Geoff Lang76b10c92014-09-05 16:28:14 -0400377
Geoff Langeb66a6e2016-10-31 13:06:12 -0400378 if (getClientVersion() >= Version(3, 0))
Geoff Lang76b10c92014-09-05 16:28:14 -0400379 {
380 // TODO: These could also be enabled via extension
Corentin Wallez99d492c2018-02-27 15:17:10 -0500381 Texture *zeroTexture3D = new Texture(mImplementation.get(), 0, TextureType::_3D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800382 mZeroTextures[TextureType::_3D].set(this, zeroTexture3D);
Geoff Lang76b10c92014-09-05 16:28:14 -0400383
Corentin Wallez99d492c2018-02-27 15:17:10 -0500384 Texture *zeroTexture2DArray = new Texture(mImplementation.get(), 0, TextureType::_2DArray);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800385 mZeroTextures[TextureType::_2DArray].set(this, zeroTexture2DArray);
Geoff Lang76b10c92014-09-05 16:28:14 -0400386 }
Geoff Lang3b573612016-10-31 14:08:10 -0400387 if (getClientVersion() >= Version(3, 1))
388 {
389 Texture *zeroTexture2DMultisample =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500390 new Texture(mImplementation.get(), 0, TextureType::_2DMultisample);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800391 mZeroTextures[TextureType::_2DMultisample].set(this, zeroTexture2DMultisample);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800392
Jiajia Qin6eafb042016-12-27 17:04:07 +0800393 for (unsigned int i = 0; i < mCaps.maxAtomicCounterBufferBindings; i++)
394 {
Qin Jiajia339f65b2018-02-27 12:52:48 +0800395 bindBufferRange(BufferBinding::AtomicCounter, i, 0, 0, 0);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800396 }
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800397
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800398 for (unsigned int i = 0; i < mCaps.maxShaderStorageBufferBindings; i++)
399 {
Corentin Wallez336129f2017-10-17 15:55:40 -0400400 bindBufferRange(BufferBinding::ShaderStorage, i, 0, 0, 0);
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800401 }
Geoff Lang3b573612016-10-31 14:08:10 -0400402 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000403
Geoff Langb0f917f2017-12-05 13:41:54 -0500404 if (mSupportedExtensions.textureRectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400405 {
406 Texture *zeroTextureRectangle =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500407 new Texture(mImplementation.get(), 0, TextureType::Rectangle);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800408 mZeroTextures[TextureType::Rectangle].set(this, zeroTextureRectangle);
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400409 }
410
Geoff Langb0f917f2017-12-05 13:41:54 -0500411 if (mSupportedExtensions.eglImageExternal || mSupportedExtensions.eglStreamConsumerExternal)
Ian Ewellbda75592016-04-18 17:25:54 -0400412 {
Corentin Wallez99d492c2018-02-27 15:17:10 -0500413 Texture *zeroTextureExternal = new Texture(mImplementation.get(), 0, TextureType::External);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800414 mZeroTextures[TextureType::External].set(this, zeroTextureExternal);
Ian Ewellbda75592016-04-18 17:25:54 -0400415 }
416
Jamie Madill4928b7c2017-06-20 12:57:39 -0400417 mGLState.initializeZeroTextures(this, mZeroTextures);
Jamie Madille6382c32014-11-07 15:05:26 -0500418
Jamie Madill57a89722013-07-02 11:57:03 -0400419 bindVertexArray(0);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000420
Geoff Langeb66a6e2016-10-31 13:06:12 -0400421 if (getClientVersion() >= Version(3, 0))
Geoff Lang1a683462015-09-29 15:09:59 -0400422 {
423 // [OpenGL ES 3.0.2] section 2.14.1 pg 85:
424 // In the initial state, a default transform feedback object is bound and treated as
425 // a transform feedback object with a name of zero. That object is bound any time
426 // BindTransformFeedback is called with id of zero
Jamie Madillf0dcb8b2017-08-26 19:05:13 -0400427 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Geoff Lang1a683462015-09-29 15:09:59 -0400428 }
Geoff Langc8058452014-02-03 12:04:11 -0500429
Corentin Wallez336129f2017-10-17 15:55:40 -0400430 for (auto type : angle::AllEnums<BufferBinding>())
431 {
432 bindBuffer(type, 0);
433 }
434
435 bindRenderbuffer(GL_RENDERBUFFER, 0);
436
437 for (unsigned int i = 0; i < mCaps.maxUniformBufferBindings; i++)
438 {
439 bindBufferRange(BufferBinding::Uniform, i, 0, 0, -1);
440 }
441
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700442 // Initialize GLES1 renderer if appropriate.
443 if (getClientVersion() < Version(2, 0))
444 {
445 mGLES1Renderer.reset(new GLES1Renderer());
446 }
447
Jamie Madillad9f24e2016-02-12 09:27:24 -0500448 // Initialize dirty bit masks
Jamie Madillc67323a2017-11-02 23:11:41 -0400449 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500450 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500451 // No dirty objects.
452
453 // Readpixels uses the pack state and read FBO
Jamie Madillc67323a2017-11-02 23:11:41 -0400454 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500455 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_BUFFER_BINDING);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400456 mReadPixelsDirtyBits.set(State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500457 mReadPixelsDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
458
459 mClearDirtyBits.set(State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED);
460 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
461 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR);
462 mClearDirtyBits.set(State::DIRTY_BIT_VIEWPORT);
463 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_COLOR);
464 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_DEPTH);
465 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_STENCIL);
466 mClearDirtyBits.set(State::DIRTY_BIT_COLOR_MASK);
467 mClearDirtyBits.set(State::DIRTY_BIT_DEPTH_MASK);
468 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT);
469 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_BACK);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400470 mClearDirtyBits.set(State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500471 mClearDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
472
473 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
474 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR);
Geoff Lang1d2c41d2016-10-19 16:14:46 -0700475 mBlitDirtyBits.set(State::DIRTY_BIT_FRAMEBUFFER_SRGB);
Luc Ferronaf7dc012018-06-26 07:56:49 -0400476 mBlitDirtyBits.set(State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING);
477 mBlitDirtyBits.set(State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500478 mBlitDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
479 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
Jamie Madill437fa652016-05-03 15:13:24 -0400480
Xinghua Cao10a4d432017-11-28 14:46:26 +0800481 // TODO(xinghua.cao@intel.com): add other dirty bits and dirty objects.
482 mComputeDirtyBits.set(State::DIRTY_BIT_SHADER_STORAGE_BUFFER_BINDING);
483 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_BINDING);
484 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_EXECUTABLE);
485 mComputeDirtyBits.set(State::DIRTY_BIT_TEXTURE_BINDINGS);
486 mComputeDirtyBits.set(State::DIRTY_BIT_SAMPLER_BINDINGS);
Qin Jiajia62fcf622017-11-30 16:16:12 +0800487 mComputeDirtyBits.set(State::DIRTY_BIT_DISPATCH_INDIRECT_BUFFER_BINDING);
Jiajia Qin5ae6ee42018-03-06 17:39:42 +0800488 mComputeDirtyObjects.set(State::DIRTY_OBJECT_PROGRAM_TEXTURES);
Xinghua Cao10a4d432017-11-28 14:46:26 +0800489
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400490 handleError(mImplementation->initialize());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000491}
492
Jamie Madill4928b7c2017-06-20 12:57:39 -0400493egl::Error Context::onDestroy(const egl::Display *display)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000494{
Lingfeng Yang461b09a2018-04-23 09:02:09 -0700495 if (mGLES1Renderer)
496 {
497 mGLES1Renderer->onDestroy(this, &mGLState);
498 }
499
Jamie Madille7b3fe22018-04-05 09:42:46 -0400500 // Delete the Surface first to trigger a finish() in Vulkan.
Jamie Madille7b3fe22018-04-05 09:42:46 -0400501 ANGLE_TRY(releaseSurface(display));
502
Corentin Wallez80b24112015-08-25 16:41:57 -0400503 for (auto fence : mFenceNVMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000504 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400505 SafeDelete(fence.second);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000506 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400507 mFenceNVMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000508
Corentin Wallez80b24112015-08-25 16:41:57 -0400509 for (auto query : mQueryMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000510 {
Geoff Langf0aa8422015-09-29 15:08:34 -0400511 if (query.second != nullptr)
512 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400513 query.second->release(this);
Geoff Langf0aa8422015-09-29 15:08:34 -0400514 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000515 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400516 mQueryMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000517
Corentin Wallez80b24112015-08-25 16:41:57 -0400518 for (auto vertexArray : mVertexArrayMap)
Jamie Madill57a89722013-07-02 11:57:03 -0400519 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400520 if (vertexArray.second)
521 {
522 vertexArray.second->onDestroy(this);
523 }
Jamie Madill57a89722013-07-02 11:57:03 -0400524 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400525 mVertexArrayMap.clear();
Jamie Madill57a89722013-07-02 11:57:03 -0400526
Corentin Wallez80b24112015-08-25 16:41:57 -0400527 for (auto transformFeedback : mTransformFeedbackMap)
Geoff Langc8058452014-02-03 12:04:11 -0500528 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500529 if (transformFeedback.second != nullptr)
530 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500531 transformFeedback.second->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500532 }
Geoff Langc8058452014-02-03 12:04:11 -0500533 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400534 mTransformFeedbackMap.clear();
Geoff Langc8058452014-02-03 12:04:11 -0500535
Jamie Madill5b772312018-03-08 20:28:32 -0500536 for (BindingPointer<Texture> &zeroTexture : mZeroTextures)
Geoff Lang76b10c92014-09-05 16:28:14 -0400537 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800538 if (zeroTexture.get() != nullptr)
539 {
540 ANGLE_TRY(zeroTexture->onDestroy(this));
541 zeroTexture.set(this, nullptr);
542 }
Geoff Lang76b10c92014-09-05 16:28:14 -0400543 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000544
Jamie Madill2f348d22017-06-05 10:50:59 -0400545 releaseShaderCompiler();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500546
Jamie Madill4928b7c2017-06-20 12:57:39 -0400547 mGLState.reset(this);
548
Jamie Madill6c1f6712017-02-14 19:08:04 -0500549 mState.mBuffers->release(this);
550 mState.mShaderPrograms->release(this);
551 mState.mTextures->release(this);
552 mState.mRenderbuffers->release(this);
553 mState.mSamplers->release(this);
Jamie Madill70b5bb02017-08-28 13:32:37 -0400554 mState.mSyncs->release(this);
Jamie Madill6c1f6712017-02-14 19:08:04 -0500555 mState.mPaths->release(this);
556 mState.mFramebuffers->release(this);
Yunchao Hea336b902017-08-02 16:05:21 +0800557 mState.mPipelines->release(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400558
Jamie Madill76e471e2017-10-21 09:56:01 -0400559 mImplementation->onDestroy(this);
560
Jamie Madill4928b7c2017-06-20 12:57:39 -0400561 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000562}
563
Jamie Madill70ee0f62017-02-06 16:04:20 -0500564Context::~Context()
565{
566}
567
Geoff Lang75359662018-04-11 01:42:27 -0400568void Context::setLabel(EGLLabelKHR label)
569{
570 mLabel = label;
571}
572
573EGLLabelKHR Context::getLabel() const
574{
575 return mLabel;
576}
577
Jamie Madill4928b7c2017-06-20 12:57:39 -0400578egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000579{
Jamie Madill61e16b42017-06-19 11:13:23 -0400580 mCurrentDisplay = display;
581
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000582 if (!mHasBeenCurrent)
583 {
Geoff Lang33f11fb2018-05-07 13:42:47 -0400584 initialize();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000585 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500586 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400587 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000588
Corentin Wallezc295e512017-01-27 17:47:50 -0500589 int width = 0;
590 int height = 0;
591 if (surface != nullptr)
592 {
593 width = surface->getWidth();
594 height = surface->getHeight();
595 }
596
597 mGLState.setViewportParams(0, 0, width, height);
598 mGLState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000599
600 mHasBeenCurrent = true;
601 }
602
Jamie Madill1b94d432015-08-07 13:23:23 -0400603 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700604 mGLState.setAllDirtyBits();
Jamie Madill81c2e252017-09-09 23:32:46 -0400605 mGLState.setAllDirtyObjects();
Jamie Madill1b94d432015-08-07 13:23:23 -0400606
Jamie Madill4928b7c2017-06-20 12:57:39 -0400607 ANGLE_TRY(releaseSurface(display));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500608
609 Framebuffer *newDefault = nullptr;
610 if (surface != nullptr)
611 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400612 ANGLE_TRY(surface->setIsCurrent(this, true));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500613 mCurrentSurface = surface;
Geoff Langbf7b95d2018-05-01 16:48:21 -0400614 newDefault = surface->createDefaultFramebuffer(this);
Corentin Wallezccab69d2017-01-27 16:57:15 -0500615 }
616 else
617 {
Geoff Langbf7b95d2018-05-01 16:48:21 -0400618 newDefault = new Framebuffer(mImplementation.get());
Corentin Wallezccab69d2017-01-27 16:57:15 -0500619 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000620
Corentin Wallez37c39792015-08-20 14:19:46 -0400621 // Update default framebuffer, the binding of the previous default
622 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400623 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700624 if (mGLState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400625 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700626 mGLState.setReadFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400627 }
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700628 if (mGLState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400629 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700630 mGLState.setDrawFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400631 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500632 mState.mFramebuffers->setDefaultFramebuffer(newDefault);
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400633 }
Ian Ewell292f0052016-02-04 10:37:32 -0500634
635 // Notify the renderer of a context switch
Luc Ferron5396f2a2018-07-12 08:24:23 -0400636 ANGLE_TRY(mImplementation->onMakeCurrent(this));
Jamie Madill4928b7c2017-06-20 12:57:39 -0400637 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000638}
639
Jamie Madill4928b7c2017-06-20 12:57:39 -0400640egl::Error Context::releaseSurface(const egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400641{
Geoff Langbf7b95d2018-05-01 16:48:21 -0400642 gl::Framebuffer *defaultFramebuffer = mState.mFramebuffers->getFramebuffer(0);
Corentin Wallez51706ea2015-08-07 14:39:22 -0400643
Geoff Langbf7b95d2018-05-01 16:48:21 -0400644 // Remove the default framebuffer
645 if (mGLState.getReadFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500646 {
647 mGLState.setReadFramebufferBinding(nullptr);
648 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400649
650 if (mGLState.getDrawFramebuffer() == defaultFramebuffer)
Corentin Wallezc295e512017-01-27 17:47:50 -0500651 {
652 mGLState.setDrawFramebufferBinding(nullptr);
653 }
Geoff Langbf7b95d2018-05-01 16:48:21 -0400654
655 if (defaultFramebuffer)
656 {
657 defaultFramebuffer->onDestroy(this);
658 delete defaultFramebuffer;
659 }
660
Corentin Wallezc295e512017-01-27 17:47:50 -0500661 mState.mFramebuffers->setDefaultFramebuffer(nullptr);
662
663 if (mCurrentSurface)
664 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400665 ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
Corentin Wallezc295e512017-01-27 17:47:50 -0500666 mCurrentSurface = nullptr;
667 }
Jamie Madill4928b7c2017-06-20 12:57:39 -0400668
669 return egl::NoError();
Jamie Madill77a72f62015-04-14 11:18:32 -0400670}
671
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000672GLuint Context::createBuffer()
673{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500674 return mState.mBuffers->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000675}
676
677GLuint Context::createProgram()
678{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500679 return mState.mShaderPrograms->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000680}
681
Jiawei Shao385b3e02018-03-21 09:43:28 +0800682GLuint Context::createShader(ShaderType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000683{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500684 return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000685}
686
687GLuint Context::createTexture()
688{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500689 return mState.mTextures->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000690}
691
692GLuint Context::createRenderbuffer()
693{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500694 return mState.mRenderbuffers->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000695}
696
Brandon Jones59770802018-04-02 13:18:42 -0700697GLuint Context::genPaths(GLsizei range)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300698{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500699 auto resultOrError = mState.mPaths->createPaths(mImplementation.get(), range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300700 if (resultOrError.isError())
701 {
702 handleError(resultOrError.getError());
703 return 0;
704 }
705 return resultOrError.getResult();
706}
707
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000708// Returns an unused framebuffer name
709GLuint Context::createFramebuffer()
710{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500711 return mState.mFramebuffers->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000712}
713
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500714void Context::genFencesNV(GLsizei n, GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000715{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500716 for (int i = 0; i < n; i++)
717 {
718 GLuint handle = mFenceNVHandleAllocator.allocate();
719 mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV()));
720 fences[i] = handle;
721 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000722}
723
Yunchao Hea336b902017-08-02 16:05:21 +0800724GLuint Context::createProgramPipeline()
725{
726 return mState.mPipelines->createProgramPipeline();
727}
728
Jiawei Shao385b3e02018-03-21 09:43:28 +0800729GLuint Context::createShaderProgramv(ShaderType type, GLsizei count, const GLchar *const *strings)
Jiajia Qin5451d532017-11-16 17:16:34 +0800730{
731 UNIMPLEMENTED();
732 return 0u;
733}
734
James Darpinian4d9d4832018-03-13 12:43:28 -0700735void Context::deleteBuffer(GLuint bufferName)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000736{
James Darpinian4d9d4832018-03-13 12:43:28 -0700737 Buffer *buffer = mState.mBuffers->getBuffer(bufferName);
738 if (buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000739 {
740 detachBuffer(buffer);
741 }
Jamie Madill893ab082014-05-16 16:56:10 -0400742
James Darpinian4d9d4832018-03-13 12:43:28 -0700743 mState.mBuffers->deleteObject(this, bufferName);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000744}
745
746void Context::deleteShader(GLuint shader)
747{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500748 mState.mShaderPrograms->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000749}
750
751void Context::deleteProgram(GLuint program)
752{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500753 mState.mShaderPrograms->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000754}
755
756void Context::deleteTexture(GLuint texture)
757{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500758 if (mState.mTextures->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000759 {
760 detachTexture(texture);
761 }
762
Jamie Madill6c1f6712017-02-14 19:08:04 -0500763 mState.mTextures->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000764}
765
766void Context::deleteRenderbuffer(GLuint renderbuffer)
767{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500768 if (mState.mRenderbuffers->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000769 {
770 detachRenderbuffer(renderbuffer);
771 }
Jamie Madill893ab082014-05-16 16:56:10 -0400772
Jamie Madill6c1f6712017-02-14 19:08:04 -0500773 mState.mRenderbuffers->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000774}
775
Jamie Madill7f0c5a42017-08-26 22:43:26 -0400776void Context::deleteSync(GLsync sync)
Jamie Madillcd055f82013-07-26 11:55:15 -0400777{
778 // The spec specifies the underlying Fence object is not deleted until all current
779 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
780 // and since our API is currently designed for being called from a single thread, we can delete
781 // the fence immediately.
Jamie Madill70b5bb02017-08-28 13:32:37 -0400782 mState.mSyncs->deleteObject(this, static_cast<GLuint>(reinterpret_cast<uintptr_t>(sync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400783}
784
Yunchao Hea336b902017-08-02 16:05:21 +0800785void Context::deleteProgramPipeline(GLuint pipeline)
786{
787 if (mState.mPipelines->getProgramPipeline(pipeline))
788 {
789 detachProgramPipeline(pipeline);
790 }
791
792 mState.mPipelines->deleteObject(this, pipeline);
793}
794
Sami Väisänene45e53b2016-05-25 10:36:04 +0300795void Context::deletePaths(GLuint first, GLsizei range)
796{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500797 mState.mPaths->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300798}
799
Brandon Jones59770802018-04-02 13:18:42 -0700800bool Context::isPath(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300801{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500802 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300803 if (pathObj == nullptr)
804 return false;
805
806 return pathObj->hasPathData();
807}
808
Brandon Jones59770802018-04-02 13:18:42 -0700809bool Context::isPathGenerated(GLuint path) const
Sami Väisänene45e53b2016-05-25 10:36:04 +0300810{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500811 return mState.mPaths->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300812}
813
Brandon Jones59770802018-04-02 13:18:42 -0700814void Context::pathCommands(GLuint path,
815 GLsizei numCommands,
816 const GLubyte *commands,
817 GLsizei numCoords,
818 GLenum coordType,
819 const void *coords)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300820{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500821 auto *pathObject = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300822
823 handleError(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
824}
825
Jamie Madill007530e2017-12-28 14:27:04 -0500826void Context::pathParameterf(GLuint path, GLenum pname, GLfloat value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300827{
Jamie Madill007530e2017-12-28 14:27:04 -0500828 Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300829
830 switch (pname)
831 {
832 case GL_PATH_STROKE_WIDTH_CHROMIUM:
833 pathObj->setStrokeWidth(value);
834 break;
835 case GL_PATH_END_CAPS_CHROMIUM:
836 pathObj->setEndCaps(static_cast<GLenum>(value));
837 break;
838 case GL_PATH_JOIN_STYLE_CHROMIUM:
839 pathObj->setJoinStyle(static_cast<GLenum>(value));
840 break;
841 case GL_PATH_MITER_LIMIT_CHROMIUM:
842 pathObj->setMiterLimit(value);
843 break;
844 case GL_PATH_STROKE_BOUND_CHROMIUM:
845 pathObj->setStrokeBound(value);
846 break;
847 default:
848 UNREACHABLE();
849 break;
850 }
851}
852
Jamie Madill007530e2017-12-28 14:27:04 -0500853void Context::pathParameteri(GLuint path, GLenum pname, GLint value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300854{
Jamie Madill007530e2017-12-28 14:27:04 -0500855 // TODO(jmadill): Should use proper clamping/casting.
856 pathParameterf(path, pname, static_cast<GLfloat>(value));
857}
858
859void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value)
860{
861 const Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300862
863 switch (pname)
864 {
865 case GL_PATH_STROKE_WIDTH_CHROMIUM:
866 *value = pathObj->getStrokeWidth();
867 break;
868 case GL_PATH_END_CAPS_CHROMIUM:
869 *value = static_cast<GLfloat>(pathObj->getEndCaps());
870 break;
871 case GL_PATH_JOIN_STYLE_CHROMIUM:
872 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
873 break;
874 case GL_PATH_MITER_LIMIT_CHROMIUM:
875 *value = pathObj->getMiterLimit();
876 break;
877 case GL_PATH_STROKE_BOUND_CHROMIUM:
878 *value = pathObj->getStrokeBound();
879 break;
880 default:
881 UNREACHABLE();
882 break;
883 }
884}
885
Jamie Madill007530e2017-12-28 14:27:04 -0500886void Context::getPathParameteriv(GLuint path, GLenum pname, GLint *value)
887{
888 GLfloat val = 0.0f;
889 getPathParameterfv(path, pname, value != nullptr ? &val : nullptr);
890 if (value)
891 *value = static_cast<GLint>(val);
892}
893
Brandon Jones59770802018-04-02 13:18:42 -0700894void Context::pathStencilFunc(GLenum func, GLint ref, GLuint mask)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300895{
896 mGLState.setPathStencilFunc(func, ref, mask);
897}
898
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000899void Context::deleteFramebuffer(GLuint framebuffer)
900{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500901 if (mState.mFramebuffers->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000902 {
903 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000904 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500905
Jamie Madill6c1f6712017-02-14 19:08:04 -0500906 mState.mFramebuffers->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000907}
908
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500909void Context::deleteFencesNV(GLsizei n, const GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000910{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500911 for (int i = 0; i < n; i++)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000912 {
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500913 GLuint fence = fences[i];
914
915 FenceNV *fenceObject = nullptr;
916 if (mFenceNVMap.erase(fence, &fenceObject))
917 {
918 mFenceNVHandleAllocator.release(fence);
919 delete fenceObject;
920 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000921 }
922}
923
Geoff Lang70d0f492015-12-10 17:45:46 -0500924Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000925{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500926 return mState.mBuffers->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000927}
928
Jamie Madill570f7c82014-07-03 10:38:54 -0400929Texture *Context::getTexture(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000930{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500931 return mState.mTextures->getTexture(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000932}
933
Geoff Lang70d0f492015-12-10 17:45:46 -0500934Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000935{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500936 return mState.mRenderbuffers->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000937}
938
Jamie Madill70b5bb02017-08-28 13:32:37 -0400939Sync *Context::getSync(GLsync handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400940{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400941 return mState.mSyncs->getSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400942}
943
Jamie Madill57a89722013-07-02 11:57:03 -0400944VertexArray *Context::getVertexArray(GLuint handle) const
945{
Jamie Madill96a483b2017-06-27 16:49:21 -0400946 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -0400947}
948
Jamie Madilldc356042013-07-19 16:36:57 -0400949Sampler *Context::getSampler(GLuint handle) const
950{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500951 return mState.mSamplers->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400952}
953
Geoff Langc8058452014-02-03 12:04:11 -0500954TransformFeedback *Context::getTransformFeedback(GLuint handle) const
955{
Jamie Madill96a483b2017-06-27 16:49:21 -0400956 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -0500957}
958
Yunchao Hea336b902017-08-02 16:05:21 +0800959ProgramPipeline *Context::getProgramPipeline(GLuint handle) const
960{
961 return mState.mPipelines->getProgramPipeline(handle);
962}
963
Geoff Lang75359662018-04-11 01:42:27 -0400964gl::LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
Geoff Lang70d0f492015-12-10 17:45:46 -0500965{
966 switch (identifier)
967 {
968 case GL_BUFFER:
969 return getBuffer(name);
970 case GL_SHADER:
971 return getShader(name);
972 case GL_PROGRAM:
973 return getProgram(name);
974 case GL_VERTEX_ARRAY:
975 return getVertexArray(name);
976 case GL_QUERY:
977 return getQuery(name);
978 case GL_TRANSFORM_FEEDBACK:
979 return getTransformFeedback(name);
980 case GL_SAMPLER:
981 return getSampler(name);
982 case GL_TEXTURE:
983 return getTexture(name);
984 case GL_RENDERBUFFER:
985 return getRenderbuffer(name);
986 case GL_FRAMEBUFFER:
987 return getFramebuffer(name);
988 default:
989 UNREACHABLE();
990 return nullptr;
991 }
992}
993
Geoff Lang75359662018-04-11 01:42:27 -0400994gl::LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
Geoff Lang70d0f492015-12-10 17:45:46 -0500995{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400996 return getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
Geoff Lang70d0f492015-12-10 17:45:46 -0500997}
998
Martin Radev9d901792016-07-15 15:58:58 +0300999void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
1000{
Geoff Lang75359662018-04-11 01:42:27 -04001001 gl::LabeledObject *object = getLabeledObject(identifier, name);
Martin Radev9d901792016-07-15 15:58:58 +03001002 ASSERT(object != nullptr);
1003
1004 std::string labelName = GetObjectLabelFromPointer(length, label);
1005 object->setLabel(labelName);
Jamie Madill8693bdb2017-09-02 15:32:14 -04001006
1007 // TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the
1008 // specified object is active until we do this.
1009 mGLState.setObjectDirty(identifier);
Martin Radev9d901792016-07-15 15:58:58 +03001010}
1011
1012void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
1013{
Geoff Lang75359662018-04-11 01:42:27 -04001014 gl::LabeledObject *object = getLabeledObjectFromPtr(ptr);
Martin Radev9d901792016-07-15 15:58:58 +03001015 ASSERT(object != nullptr);
1016
1017 std::string labelName = GetObjectLabelFromPointer(length, label);
1018 object->setLabel(labelName);
1019}
1020
1021void Context::getObjectLabel(GLenum identifier,
1022 GLuint name,
1023 GLsizei bufSize,
1024 GLsizei *length,
1025 GLchar *label) const
1026{
Geoff Lang75359662018-04-11 01:42:27 -04001027 gl::LabeledObject *object = getLabeledObject(identifier, name);
Martin Radev9d901792016-07-15 15:58:58 +03001028 ASSERT(object != nullptr);
1029
1030 const std::string &objectLabel = object->getLabel();
1031 GetObjectLabelBase(objectLabel, bufSize, length, label);
1032}
1033
1034void Context::getObjectPtrLabel(const void *ptr,
1035 GLsizei bufSize,
1036 GLsizei *length,
1037 GLchar *label) const
1038{
Geoff Lang75359662018-04-11 01:42:27 -04001039 gl::LabeledObject *object = getLabeledObjectFromPtr(ptr);
Martin Radev9d901792016-07-15 15:58:58 +03001040 ASSERT(object != nullptr);
1041
1042 const std::string &objectLabel = object->getLabel();
1043 GetObjectLabelBase(objectLabel, bufSize, length, label);
1044}
1045
Jamie Madilldc356042013-07-19 16:36:57 -04001046bool Context::isSampler(GLuint samplerName) const
1047{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001048 return mState.mSamplers->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -04001049}
1050
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001051void Context::bindTexture(TextureType target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001052{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001053 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001054
Jamie Madilldedd7b92014-11-05 16:30:36 -05001055 if (handle == 0)
1056 {
1057 texture = mZeroTextures[target].get();
1058 }
1059 else
1060 {
Corentin Wallez99d492c2018-02-27 15:17:10 -05001061 texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -05001062 }
1063
1064 ASSERT(texture);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001065 mGLState.setSamplerTexture(this, target, texture);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00001066}
1067
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001068void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001069{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001070 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1071 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001072 mGLState.setReadFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001073}
1074
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001075void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001076{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001077 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1078 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001079 mGLState.setDrawFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001080}
1081
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001082void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -04001083{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001084 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madill7267aa62018-04-17 15:28:21 -04001085 mGLState.setVertexArrayBinding(this, vertexArray);
Jamie Madill57a89722013-07-02 11:57:03 -04001086}
1087
Shao80957d92017-02-20 21:25:59 +08001088void Context::bindVertexBuffer(GLuint bindingIndex,
1089 GLuint bufferHandle,
1090 GLintptr offset,
1091 GLsizei stride)
1092{
1093 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001094 mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Shao80957d92017-02-20 21:25:59 +08001095}
1096
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001097void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -04001098{
Geoff Lang76b10c92014-09-05 16:28:14 -04001099 ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -04001100 Sampler *sampler =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001101 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001102 mGLState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04001103}
1104
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001105void Context::bindImageTexture(GLuint unit,
1106 GLuint texture,
1107 GLint level,
1108 GLboolean layered,
1109 GLint layer,
1110 GLenum access,
1111 GLenum format)
1112{
1113 Texture *tex = mState.mTextures->getTexture(texture);
1114 mGLState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
1115}
1116
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001117void Context::useProgram(GLuint program)
1118{
Jamie Madill6c1f6712017-02-14 19:08:04 -05001119 mGLState.setProgram(this, getProgram(program));
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001120}
1121
Jiajia Qin5451d532017-11-16 17:16:34 +08001122void Context::useProgramStages(GLuint pipeline, GLbitfield stages, GLuint program)
1123{
1124 UNIMPLEMENTED();
1125}
1126
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001127void Context::bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001128{
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001129 ASSERT(target == GL_TRANSFORM_FEEDBACK);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001130 TransformFeedback *transformFeedback =
1131 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001132 mGLState.setTransformFeedbackBinding(this, transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -05001133}
1134
Yunchao Hea336b902017-08-02 16:05:21 +08001135void Context::bindProgramPipeline(GLuint pipelineHandle)
1136{
1137 ProgramPipeline *pipeline =
1138 mState.mPipelines->checkProgramPipelineAllocation(mImplementation.get(), pipelineHandle);
1139 mGLState.setProgramPipelineBinding(this, pipeline);
1140}
1141
Corentin Wallezad3ae902018-03-09 13:40:42 -05001142void Context::beginQuery(QueryType target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001143{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001144 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001145 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001146
Geoff Lang5aad9672014-09-08 11:10:42 -04001147 // begin query
Jamie Madillf0e04492017-08-26 15:28:42 -04001148 ANGLE_CONTEXT_TRY(queryObject->begin());
Geoff Lang5aad9672014-09-08 11:10:42 -04001149
1150 // set query as active for specified target only if begin succeeded
Jamie Madill4928b7c2017-06-20 12:57:39 -04001151 mGLState.setActiveQuery(this, target, queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001152}
1153
Corentin Wallezad3ae902018-03-09 13:40:42 -05001154void Context::endQuery(QueryType target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001155{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001156 Query *queryObject = mGLState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001157 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001158
Jamie Madillf0e04492017-08-26 15:28:42 -04001159 handleError(queryObject->end());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001160
Geoff Lang5aad9672014-09-08 11:10:42 -04001161 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madill4928b7c2017-06-20 12:57:39 -04001162 mGLState.setActiveQuery(this, target, nullptr);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001163}
1164
Corentin Wallezad3ae902018-03-09 13:40:42 -05001165void Context::queryCounter(GLuint id, QueryType target)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001166{
Corentin Wallezad3ae902018-03-09 13:40:42 -05001167 ASSERT(target == QueryType::Timestamp);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001168
1169 Query *queryObject = getQuery(id, true, target);
1170 ASSERT(queryObject);
1171
Jamie Madillf0e04492017-08-26 15:28:42 -04001172 handleError(queryObject->queryCounter());
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001173}
1174
Corentin Wallezad3ae902018-03-09 13:40:42 -05001175void Context::getQueryiv(QueryType target, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001176{
1177 switch (pname)
1178 {
1179 case GL_CURRENT_QUERY_EXT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001180 params[0] = mGLState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001181 break;
1182 case GL_QUERY_COUNTER_BITS_EXT:
1183 switch (target)
1184 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001185 case QueryType::TimeElapsed:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001186 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1187 break;
Corentin Wallezad3ae902018-03-09 13:40:42 -05001188 case QueryType::Timestamp:
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001189 params[0] = getExtensions().queryCounterBitsTimestamp;
1190 break;
1191 default:
1192 UNREACHABLE();
1193 params[0] = 0;
1194 break;
1195 }
1196 break;
1197 default:
1198 UNREACHABLE();
1199 return;
1200 }
1201}
1202
Corentin Wallezad3ae902018-03-09 13:40:42 -05001203void Context::getQueryivRobust(QueryType target,
Brandon Jones59770802018-04-02 13:18:42 -07001204 GLenum pname,
1205 GLsizei bufSize,
1206 GLsizei *length,
1207 GLint *params)
1208{
1209 getQueryiv(target, pname, params);
1210}
1211
Geoff Lang2186c382016-10-14 10:54:54 -04001212void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001213{
Geoff Lang2186c382016-10-14 10:54:54 -04001214 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001215}
1216
Brandon Jones59770802018-04-02 13:18:42 -07001217void Context::getQueryObjectivRobust(GLuint id,
1218 GLenum pname,
1219 GLsizei bufSize,
1220 GLsizei *length,
1221 GLint *params)
1222{
1223 getQueryObjectiv(id, pname, params);
1224}
1225
Geoff Lang2186c382016-10-14 10:54:54 -04001226void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001227{
Geoff Lang2186c382016-10-14 10:54:54 -04001228 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001229}
1230
Brandon Jones59770802018-04-02 13:18:42 -07001231void Context::getQueryObjectuivRobust(GLuint id,
1232 GLenum pname,
1233 GLsizei bufSize,
1234 GLsizei *length,
1235 GLuint *params)
1236{
1237 getQueryObjectuiv(id, pname, params);
1238}
1239
Geoff Lang2186c382016-10-14 10:54:54 -04001240void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001241{
Geoff Lang2186c382016-10-14 10:54:54 -04001242 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001243}
1244
Brandon Jones59770802018-04-02 13:18:42 -07001245void Context::getQueryObjecti64vRobust(GLuint id,
1246 GLenum pname,
1247 GLsizei bufSize,
1248 GLsizei *length,
1249 GLint64 *params)
1250{
1251 getQueryObjecti64v(id, pname, params);
1252}
1253
Geoff Lang2186c382016-10-14 10:54:54 -04001254void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001255{
Geoff Lang2186c382016-10-14 10:54:54 -04001256 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001257}
1258
Brandon Jones59770802018-04-02 13:18:42 -07001259void Context::getQueryObjectui64vRobust(GLuint id,
1260 GLenum pname,
1261 GLsizei bufSize,
1262 GLsizei *length,
1263 GLuint64 *params)
1264{
1265 getQueryObjectui64v(id, pname, params);
1266}
1267
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001268Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001269{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001270 return mState.mFramebuffers->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001271}
1272
Jamie Madill2f348d22017-06-05 10:50:59 -04001273FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001274{
Jamie Madill96a483b2017-06-27 16:49:21 -04001275 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001276}
1277
Corentin Wallezad3ae902018-03-09 13:40:42 -05001278Query *Context::getQuery(GLuint handle, bool create, QueryType type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001279{
Jamie Madill96a483b2017-06-27 16:49:21 -04001280 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001281 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001282 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001283 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001284
1285 Query *query = mQueryMap.query(handle);
1286 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001287 {
Corentin Wallezad3ae902018-03-09 13:40:42 -05001288 ASSERT(type != QueryType::InvalidEnum);
Jamie Madill96a483b2017-06-27 16:49:21 -04001289 query = new Query(mImplementation->createQuery(type), handle);
1290 query->addRef();
1291 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001292 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001293 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001294}
1295
Geoff Lang70d0f492015-12-10 17:45:46 -05001296Query *Context::getQuery(GLuint handle) const
1297{
Jamie Madill96a483b2017-06-27 16:49:21 -04001298 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001299}
1300
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001301Texture *Context::getTargetTexture(TextureType type) const
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001302{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001303 ASSERT(ValidTextureTarget(this, type) || ValidTextureExternalTarget(this, type));
1304 return mGLState.getTargetTexture(type);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001305}
1306
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001307Texture *Context::getSamplerTexture(unsigned int sampler, TextureType type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001308{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001309 return mGLState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001310}
1311
Geoff Lang492a7e42014-11-05 13:27:06 -05001312Compiler *Context::getCompiler() const
1313{
Jamie Madill2f348d22017-06-05 10:50:59 -04001314 if (mCompiler.get() == nullptr)
1315 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001316 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001317 }
1318 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001319}
1320
Jamie Madillc1d770e2017-04-13 17:31:24 -04001321void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001322{
1323 switch (pname)
1324 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001325 case GL_SHADER_COMPILER:
1326 *params = GL_TRUE;
1327 break;
1328 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1329 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1330 break;
1331 default:
1332 mGLState.getBooleanv(pname, params);
1333 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001334 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001335}
1336
Jamie Madillc1d770e2017-04-13 17:31:24 -04001337void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001338{
Shannon Woods53a94a82014-06-24 15:20:36 -04001339 // Queries about context capabilities and maximums are answered by Context.
1340 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001341 switch (pname)
1342 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001343 case GL_ALIASED_LINE_WIDTH_RANGE:
1344 params[0] = mCaps.minAliasedLineWidth;
1345 params[1] = mCaps.maxAliasedLineWidth;
1346 break;
1347 case GL_ALIASED_POINT_SIZE_RANGE:
1348 params[0] = mCaps.minAliasedPointSize;
1349 params[1] = mCaps.maxAliasedPointSize;
1350 break;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07001351 case GL_SMOOTH_POINT_SIZE_RANGE:
1352 params[0] = mCaps.minSmoothPointSize;
1353 params[1] = mCaps.maxSmoothPointSize;
1354 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001355 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1356 ASSERT(mExtensions.textureFilterAnisotropic);
1357 *params = mExtensions.maxTextureAnisotropy;
1358 break;
1359 case GL_MAX_TEXTURE_LOD_BIAS:
1360 *params = mCaps.maxLODBias;
1361 break;
1362
1363 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1364 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1365 {
Lingfeng Yang3a41af62018-04-09 07:28:56 -07001366 // GLES1 emulation: // GL_PATH_(MODELVIEW|PROJECTION)_MATRIX_CHROMIUM collides with the
1367 // GLES1 constants for modelview/projection matrix.
1368 if (getClientVersion() < Version(2, 0))
1369 {
1370 mGLState.getFloatv(pname, params);
1371 }
1372 else
1373 {
1374 ASSERT(mExtensions.pathRendering);
1375 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1376 memcpy(params, m, 16 * sizeof(GLfloat));
1377 }
Jamie Madill231c7f52017-04-26 13:45:37 -04001378 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001379 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001380
Jamie Madill231c7f52017-04-26 13:45:37 -04001381 default:
1382 mGLState.getFloatv(pname, params);
1383 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001384 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001385}
1386
Jamie Madillc1d770e2017-04-13 17:31:24 -04001387void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001388{
Shannon Woods53a94a82014-06-24 15:20:36 -04001389 // Queries about context capabilities and maximums are answered by Context.
1390 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001391
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001392 switch (pname)
1393 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001394 case GL_MAX_VERTEX_ATTRIBS:
1395 *params = mCaps.maxVertexAttributes;
1396 break;
1397 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1398 *params = mCaps.maxVertexUniformVectors;
1399 break;
1400 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001401 *params = mCaps.maxShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001402 break;
1403 case GL_MAX_VARYING_VECTORS:
1404 *params = mCaps.maxVaryingVectors;
1405 break;
1406 case GL_MAX_VARYING_COMPONENTS:
1407 *params = mCaps.maxVertexOutputComponents;
1408 break;
1409 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1410 *params = mCaps.maxCombinedTextureImageUnits;
1411 break;
1412 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001413 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001414 break;
1415 case GL_MAX_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001416 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001417 break;
1418 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1419 *params = mCaps.maxFragmentUniformVectors;
1420 break;
1421 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001422 *params = mCaps.maxShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001423 break;
1424 case GL_MAX_RENDERBUFFER_SIZE:
1425 *params = mCaps.maxRenderbufferSize;
1426 break;
1427 case GL_MAX_COLOR_ATTACHMENTS_EXT:
1428 *params = mCaps.maxColorAttachments;
1429 break;
1430 case GL_MAX_DRAW_BUFFERS_EXT:
1431 *params = mCaps.maxDrawBuffers;
1432 break;
1433 // case GL_FRAMEBUFFER_BINDING: // now equivalent to
1434 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
1435 case GL_SUBPIXEL_BITS:
1436 *params = 4;
1437 break;
1438 case GL_MAX_TEXTURE_SIZE:
1439 *params = mCaps.max2DTextureSize;
1440 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001441 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
1442 *params = mCaps.maxRectangleTextureSize;
1443 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001444 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1445 *params = mCaps.maxCubeMapTextureSize;
1446 break;
1447 case GL_MAX_3D_TEXTURE_SIZE:
1448 *params = mCaps.max3DTextureSize;
1449 break;
1450 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1451 *params = mCaps.maxArrayTextureLayers;
1452 break;
1453 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1454 *params = mCaps.uniformBufferOffsetAlignment;
1455 break;
1456 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1457 *params = mCaps.maxUniformBufferBindings;
1458 break;
1459 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001460 *params = mCaps.maxShaderUniformBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001461 break;
1462 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001463 *params = mCaps.maxShaderUniformBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001464 break;
1465 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1466 *params = mCaps.maxCombinedTextureImageUnits;
1467 break;
1468 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1469 *params = mCaps.maxVertexOutputComponents;
1470 break;
1471 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1472 *params = mCaps.maxFragmentInputComponents;
1473 break;
1474 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1475 *params = mCaps.minProgramTexelOffset;
1476 break;
1477 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1478 *params = mCaps.maxProgramTexelOffset;
1479 break;
1480 case GL_MAJOR_VERSION:
1481 *params = getClientVersion().major;
1482 break;
1483 case GL_MINOR_VERSION:
1484 *params = getClientVersion().minor;
1485 break;
1486 case GL_MAX_ELEMENTS_INDICES:
1487 *params = mCaps.maxElementsIndices;
1488 break;
1489 case GL_MAX_ELEMENTS_VERTICES:
1490 *params = mCaps.maxElementsVertices;
1491 break;
1492 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1493 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1494 break;
1495 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1496 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1497 break;
1498 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1499 *params = mCaps.maxTransformFeedbackSeparateComponents;
1500 break;
1501 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1502 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1503 break;
1504 case GL_MAX_SAMPLES_ANGLE:
1505 *params = mCaps.maxSamples;
1506 break;
1507 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001508 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001509 params[0] = mCaps.maxViewportWidth;
1510 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001511 }
1512 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001513 case GL_COMPRESSED_TEXTURE_FORMATS:
1514 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1515 params);
1516 break;
1517 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1518 *params = mResetStrategy;
1519 break;
1520 case GL_NUM_SHADER_BINARY_FORMATS:
1521 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1522 break;
1523 case GL_SHADER_BINARY_FORMATS:
1524 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1525 break;
1526 case GL_NUM_PROGRAM_BINARY_FORMATS:
1527 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1528 break;
1529 case GL_PROGRAM_BINARY_FORMATS:
1530 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1531 break;
1532 case GL_NUM_EXTENSIONS:
1533 *params = static_cast<GLint>(mExtensionStrings.size());
1534 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001535
Jamie Madill231c7f52017-04-26 13:45:37 -04001536 // GL_KHR_debug
1537 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1538 *params = mExtensions.maxDebugMessageLength;
1539 break;
1540 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1541 *params = mExtensions.maxDebugLoggedMessages;
1542 break;
1543 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1544 *params = mExtensions.maxDebugGroupStackDepth;
1545 break;
1546 case GL_MAX_LABEL_LENGTH:
1547 *params = mExtensions.maxLabelLength;
1548 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001549
Martin Radeve5285d22017-07-14 16:23:53 +03001550 // GL_ANGLE_multiview
1551 case GL_MAX_VIEWS_ANGLE:
1552 *params = mExtensions.maxViews;
1553 break;
1554
Jamie Madill231c7f52017-04-26 13:45:37 -04001555 // GL_EXT_disjoint_timer_query
1556 case GL_GPU_DISJOINT_EXT:
1557 *params = mImplementation->getGPUDisjoint();
1558 break;
1559 case GL_MAX_FRAMEBUFFER_WIDTH:
1560 *params = mCaps.maxFramebufferWidth;
1561 break;
1562 case GL_MAX_FRAMEBUFFER_HEIGHT:
1563 *params = mCaps.maxFramebufferHeight;
1564 break;
1565 case GL_MAX_FRAMEBUFFER_SAMPLES:
1566 *params = mCaps.maxFramebufferSamples;
1567 break;
1568 case GL_MAX_SAMPLE_MASK_WORDS:
1569 *params = mCaps.maxSampleMaskWords;
1570 break;
1571 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1572 *params = mCaps.maxColorTextureSamples;
1573 break;
1574 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1575 *params = mCaps.maxDepthTextureSamples;
1576 break;
1577 case GL_MAX_INTEGER_SAMPLES:
1578 *params = mCaps.maxIntegerSamples;
1579 break;
1580 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1581 *params = mCaps.maxVertexAttribRelativeOffset;
1582 break;
1583 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1584 *params = mCaps.maxVertexAttribBindings;
1585 break;
1586 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1587 *params = mCaps.maxVertexAttribStride;
1588 break;
1589 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001590 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001591 break;
1592 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001593 *params = mCaps.maxShaderAtomicCounters[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001594 break;
1595 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001596 *params = mCaps.maxShaderImageUniforms[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001597 break;
1598 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001599 *params = mCaps.maxShaderStorageBlocks[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001600 break;
1601 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001602 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001603 break;
1604 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001605 *params = mCaps.maxShaderAtomicCounters[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001606 break;
1607 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001608 *params = mCaps.maxShaderImageUniforms[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001609 break;
1610 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001611 *params = mCaps.maxShaderStorageBlocks[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001612 break;
1613 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1614 *params = mCaps.minProgramTextureGatherOffset;
1615 break;
1616 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1617 *params = mCaps.maxProgramTextureGatherOffset;
1618 break;
1619 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1620 *params = mCaps.maxComputeWorkGroupInvocations;
1621 break;
1622 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001623 *params = mCaps.maxShaderUniformBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001624 break;
1625 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001626 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001627 break;
1628 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1629 *params = mCaps.maxComputeSharedMemorySize;
1630 break;
1631 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001632 *params = mCaps.maxShaderUniformComponents[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001633 break;
1634 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001635 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001636 break;
1637 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001638 *params = mCaps.maxShaderAtomicCounters[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001639 break;
1640 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001641 *params = mCaps.maxShaderImageUniforms[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001642 break;
1643 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001644 *params =
1645 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Compute]);
Jamie Madill231c7f52017-04-26 13:45:37 -04001646 break;
1647 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001648 *params = mCaps.maxShaderStorageBlocks[ShaderType::Compute];
Jamie Madill231c7f52017-04-26 13:45:37 -04001649 break;
1650 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1651 *params = mCaps.maxCombinedShaderOutputResources;
1652 break;
1653 case GL_MAX_UNIFORM_LOCATIONS:
1654 *params = mCaps.maxUniformLocations;
1655 break;
1656 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1657 *params = mCaps.maxAtomicCounterBufferBindings;
1658 break;
1659 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1660 *params = mCaps.maxAtomicCounterBufferSize;
1661 break;
1662 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1663 *params = mCaps.maxCombinedAtomicCounterBuffers;
1664 break;
1665 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1666 *params = mCaps.maxCombinedAtomicCounters;
1667 break;
1668 case GL_MAX_IMAGE_UNITS:
1669 *params = mCaps.maxImageUnits;
1670 break;
1671 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1672 *params = mCaps.maxCombinedImageUniforms;
1673 break;
1674 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1675 *params = mCaps.maxShaderStorageBufferBindings;
1676 break;
1677 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1678 *params = mCaps.maxCombinedShaderStorageBlocks;
1679 break;
1680 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1681 *params = mCaps.shaderStorageBufferOffsetAlignment;
1682 break;
Jiawei Shao361df072017-11-22 09:33:59 +08001683
1684 // GL_EXT_geometry_shader
1685 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
1686 *params = mCaps.maxFramebufferLayers;
1687 break;
1688 case GL_LAYER_PROVOKING_VERTEX_EXT:
1689 *params = mCaps.layerProvokingVertex;
1690 break;
1691 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001692 *params = mCaps.maxShaderUniformComponents[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001693 break;
1694 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001695 *params = mCaps.maxShaderUniformBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001696 break;
1697 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001698 *params =
1699 static_cast<GLint>(mCaps.maxCombinedShaderUniformComponents[ShaderType::Geometry]);
Jiawei Shao361df072017-11-22 09:33:59 +08001700 break;
1701 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
1702 *params = mCaps.maxGeometryInputComponents;
1703 break;
1704 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
1705 *params = mCaps.maxGeometryOutputComponents;
1706 break;
1707 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
1708 *params = mCaps.maxGeometryOutputVertices;
1709 break;
1710 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
1711 *params = mCaps.maxGeometryTotalOutputComponents;
1712 break;
1713 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
1714 *params = mCaps.maxGeometryShaderInvocations;
1715 break;
1716 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001717 *params = mCaps.maxShaderTextureImageUnits[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001718 break;
1719 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001720 *params = mCaps.maxShaderAtomicCounterBuffers[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001721 break;
1722 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001723 *params = mCaps.maxShaderAtomicCounters[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001724 break;
1725 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001726 *params = mCaps.maxShaderImageUniforms[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001727 break;
1728 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
Jiawei Shao54aafe52018-04-27 14:54:57 +08001729 *params = mCaps.maxShaderStorageBlocks[ShaderType::Geometry];
Jiawei Shao361df072017-11-22 09:33:59 +08001730 break;
Lingfeng Yang96310cd2018-03-28 11:56:28 -07001731 // GLES1 emulation: Caps queries
1732 case GL_MAX_TEXTURE_UNITS:
1733 *params = mCaps.maxMultitextureUnits;
1734 break;
Lingfeng Yange547aac2018-04-05 09:39:20 -07001735 case GL_MAX_MODELVIEW_STACK_DEPTH:
1736 *params = mCaps.maxModelviewMatrixStackDepth;
1737 break;
1738 case GL_MAX_PROJECTION_STACK_DEPTH:
1739 *params = mCaps.maxProjectionMatrixStackDepth;
1740 break;
1741 case GL_MAX_TEXTURE_STACK_DEPTH:
1742 *params = mCaps.maxTextureMatrixStackDepth;
1743 break;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07001744 case GL_MAX_LIGHTS:
1745 *params = mCaps.maxLights;
1746 break;
Lingfeng Yang060088a2018-05-30 20:40:57 -07001747 case GL_MAX_CLIP_PLANES:
1748 *params = mCaps.maxClipPlanes;
1749 break;
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001750 // GLES1 emulation: Vertex attribute queries
1751 case GL_VERTEX_ARRAY_BUFFER_BINDING:
1752 case GL_NORMAL_ARRAY_BUFFER_BINDING:
1753 case GL_COLOR_ARRAY_BUFFER_BINDING:
1754 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
1755 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
1756 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1757 GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, params);
1758 break;
1759 case GL_VERTEX_ARRAY_STRIDE:
1760 case GL_NORMAL_ARRAY_STRIDE:
1761 case GL_COLOR_ARRAY_STRIDE:
1762 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
1763 case GL_TEXTURE_COORD_ARRAY_STRIDE:
1764 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1765 GL_VERTEX_ATTRIB_ARRAY_STRIDE, params);
1766 break;
1767 case GL_VERTEX_ARRAY_SIZE:
1768 case GL_COLOR_ARRAY_SIZE:
1769 case GL_TEXTURE_COORD_ARRAY_SIZE:
1770 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1771 GL_VERTEX_ATTRIB_ARRAY_SIZE, params);
1772 break;
1773 case GL_VERTEX_ARRAY_TYPE:
1774 case GL_COLOR_ARRAY_TYPE:
1775 case GL_NORMAL_ARRAY_TYPE:
1776 case GL_POINT_SIZE_ARRAY_TYPE_OES:
1777 case GL_TEXTURE_COORD_ARRAY_TYPE:
1778 getVertexAttribiv(static_cast<GLuint>(vertexArrayIndex(ParamToVertexArrayType(pname))),
1779 GL_VERTEX_ATTRIB_ARRAY_TYPE, params);
1780 break;
1781
jchen1082af6202018-06-22 10:59:52 +08001782 // GL_KHR_parallel_shader_compile
1783 case GL_MAX_SHADER_COMPILER_THREADS_KHR:
1784 *params = mGLState.getMaxShaderCompilerThreads();
1785 break;
1786
Jamie Madill231c7f52017-04-26 13:45:37 -04001787 default:
Jamie Madille98b1b52018-03-08 09:47:23 -05001788 handleError(mGLState.getIntegerv(this, pname, params));
Jamie Madill231c7f52017-04-26 13:45:37 -04001789 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001790 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001791}
1792
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001793void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001794{
Shannon Woods53a94a82014-06-24 15:20:36 -04001795 // Queries about context capabilities and maximums are answered by Context.
1796 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001797 switch (pname)
1798 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001799 case GL_MAX_ELEMENT_INDEX:
1800 *params = mCaps.maxElementIndex;
1801 break;
1802 case GL_MAX_UNIFORM_BLOCK_SIZE:
1803 *params = mCaps.maxUniformBlockSize;
1804 break;
1805 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001806 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Vertex];
Jamie Madill231c7f52017-04-26 13:45:37 -04001807 break;
1808 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
Jiawei Shao0c4e08e2018-05-08 11:00:36 +08001809 *params = mCaps.maxCombinedShaderUniformComponents[ShaderType::Fragment];
Jamie Madill231c7f52017-04-26 13:45:37 -04001810 break;
1811 case GL_MAX_SERVER_WAIT_TIMEOUT:
1812 *params = mCaps.maxServerWaitTimeout;
1813 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001814
Jamie Madill231c7f52017-04-26 13:45:37 -04001815 // GL_EXT_disjoint_timer_query
1816 case GL_TIMESTAMP_EXT:
1817 *params = mImplementation->getTimestamp();
1818 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001819
Jamie Madill231c7f52017-04-26 13:45:37 -04001820 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1821 *params = mCaps.maxShaderStorageBlockSize;
1822 break;
1823 default:
1824 UNREACHABLE();
1825 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001826 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001827}
1828
Geoff Lang70d0f492015-12-10 17:45:46 -05001829void Context::getPointerv(GLenum pname, void **params) const
1830{
Lingfeng Yangabb09f12018-04-16 10:43:53 -07001831 mGLState.getPointerv(this, pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001832}
1833
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07001834void Context::getPointervRobustANGLERobust(GLenum pname,
1835 GLsizei bufSize,
1836 GLsizei *length,
1837 void **params)
1838{
1839 UNIMPLEMENTED();
1840}
1841
Martin Radev66fb8202016-07-28 11:45:20 +03001842void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001843{
Shannon Woods53a94a82014-06-24 15:20:36 -04001844 // Queries about context capabilities and maximums are answered by Context.
1845 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001846
1847 GLenum nativeType;
1848 unsigned int numParams;
1849 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1850 ASSERT(queryStatus);
1851
1852 if (nativeType == GL_INT)
1853 {
1854 switch (target)
1855 {
1856 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1857 ASSERT(index < 3u);
1858 *data = mCaps.maxComputeWorkGroupCount[index];
1859 break;
1860 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1861 ASSERT(index < 3u);
1862 *data = mCaps.maxComputeWorkGroupSize[index];
1863 break;
1864 default:
1865 mGLState.getIntegeri_v(target, index, data);
1866 }
1867 }
1868 else
1869 {
1870 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1871 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001872}
1873
Brandon Jones59770802018-04-02 13:18:42 -07001874void Context::getIntegeri_vRobust(GLenum target,
1875 GLuint index,
1876 GLsizei bufSize,
1877 GLsizei *length,
1878 GLint *data)
1879{
1880 getIntegeri_v(target, index, data);
1881}
1882
Martin Radev66fb8202016-07-28 11:45:20 +03001883void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001884{
Shannon Woods53a94a82014-06-24 15:20:36 -04001885 // Queries about context capabilities and maximums are answered by Context.
1886 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001887
1888 GLenum nativeType;
1889 unsigned int numParams;
1890 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1891 ASSERT(queryStatus);
1892
1893 if (nativeType == GL_INT_64_ANGLEX)
1894 {
1895 mGLState.getInteger64i_v(target, index, data);
1896 }
1897 else
1898 {
1899 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1900 }
1901}
1902
Brandon Jones59770802018-04-02 13:18:42 -07001903void Context::getInteger64i_vRobust(GLenum target,
1904 GLuint index,
1905 GLsizei bufSize,
1906 GLsizei *length,
1907 GLint64 *data)
1908{
1909 getInteger64i_v(target, index, data);
1910}
1911
Martin Radev66fb8202016-07-28 11:45:20 +03001912void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1913{
1914 // Queries about context capabilities and maximums are answered by Context.
1915 // Queries about current GL state values are answered by State.
1916
1917 GLenum nativeType;
1918 unsigned int numParams;
1919 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1920 ASSERT(queryStatus);
1921
1922 if (nativeType == GL_BOOL)
1923 {
1924 mGLState.getBooleani_v(target, index, data);
1925 }
1926 else
1927 {
1928 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1929 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001930}
1931
Brandon Jones59770802018-04-02 13:18:42 -07001932void Context::getBooleani_vRobust(GLenum target,
1933 GLuint index,
1934 GLsizei bufSize,
1935 GLsizei *length,
1936 GLboolean *data)
1937{
1938 getBooleani_v(target, index, data);
1939}
1940
Corentin Wallez336129f2017-10-17 15:55:40 -04001941void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001942{
1943 Buffer *buffer = mGLState.getTargetBuffer(target);
1944 QueryBufferParameteriv(buffer, pname, params);
1945}
1946
Brandon Jones59770802018-04-02 13:18:42 -07001947void Context::getBufferParameterivRobust(BufferBinding target,
1948 GLenum pname,
1949 GLsizei bufSize,
1950 GLsizei *length,
1951 GLint *params)
1952{
1953 getBufferParameteriv(target, pname, params);
1954}
1955
He Yunchao010e4db2017-03-03 14:22:06 +08001956void Context::getFramebufferAttachmentParameteriv(GLenum target,
1957 GLenum attachment,
1958 GLenum pname,
1959 GLint *params)
1960{
1961 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08001962 QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08001963}
1964
Brandon Jones59770802018-04-02 13:18:42 -07001965void Context::getFramebufferAttachmentParameterivRobust(GLenum target,
1966 GLenum attachment,
1967 GLenum pname,
1968 GLsizei bufSize,
1969 GLsizei *length,
1970 GLint *params)
1971{
1972 getFramebufferAttachmentParameteriv(target, attachment, pname, params);
1973}
1974
He Yunchao010e4db2017-03-03 14:22:06 +08001975void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
1976{
1977 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
1978 QueryRenderbufferiv(this, renderbuffer, pname, params);
1979}
1980
Brandon Jones59770802018-04-02 13:18:42 -07001981void Context::getRenderbufferParameterivRobust(GLenum target,
1982 GLenum pname,
1983 GLsizei bufSize,
1984 GLsizei *length,
1985 GLint *params)
1986{
1987 getRenderbufferParameteriv(target, pname, params);
1988}
1989
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001990void Context::getTexParameterfv(TextureType target, GLenum pname, GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001991{
1992 Texture *texture = getTargetTexture(target);
1993 QueryTexParameterfv(texture, pname, params);
1994}
1995
Brandon Jones59770802018-04-02 13:18:42 -07001996void Context::getTexParameterfvRobust(TextureType target,
1997 GLenum pname,
1998 GLsizei bufSize,
1999 GLsizei *length,
2000 GLfloat *params)
2001{
2002 getTexParameterfv(target, pname, params);
2003}
2004
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002005void Context::getTexParameteriv(TextureType target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002006{
2007 Texture *texture = getTargetTexture(target);
2008 QueryTexParameteriv(texture, pname, params);
2009}
Jiajia Qin5451d532017-11-16 17:16:34 +08002010
Brandon Jones59770802018-04-02 13:18:42 -07002011void Context::getTexParameterivRobust(TextureType target,
2012 GLenum pname,
2013 GLsizei bufSize,
2014 GLsizei *length,
2015 GLint *params)
2016{
2017 getTexParameteriv(target, pname, params);
2018}
2019
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002020void Context::getTexParameterIivRobust(TextureType target,
2021 GLenum pname,
2022 GLsizei bufSize,
2023 GLsizei *length,
2024 GLint *params)
2025{
2026 UNIMPLEMENTED();
2027}
2028
2029void Context::getTexParameterIuivRobust(TextureType target,
2030 GLenum pname,
2031 GLsizei bufSize,
2032 GLsizei *length,
2033 GLuint *params)
2034{
2035 UNIMPLEMENTED();
2036}
2037
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002038void Context::getTexLevelParameteriv(TextureTarget target, GLint level, GLenum pname, GLint *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002039{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002040 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002041 QueryTexLevelParameteriv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002042}
2043
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002044void Context::getTexLevelParameterivRobust(TextureTarget target,
2045 GLint level,
2046 GLenum pname,
2047 GLsizei bufSize,
2048 GLsizei *length,
2049 GLint *params)
2050{
2051 UNIMPLEMENTED();
2052}
2053
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002054void Context::getTexLevelParameterfv(TextureTarget target,
2055 GLint level,
2056 GLenum pname,
2057 GLfloat *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08002058{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002059 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05002060 QueryTexLevelParameterfv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08002061}
2062
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002063void Context::getTexLevelParameterfvRobust(TextureTarget target,
2064 GLint level,
2065 GLenum pname,
2066 GLsizei bufSize,
2067 GLsizei *length,
2068 GLfloat *params)
2069{
2070 UNIMPLEMENTED();
2071}
2072
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002073void Context::texParameterf(TextureType target, GLenum pname, GLfloat param)
He Yunchao010e4db2017-03-03 14:22:06 +08002074{
2075 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002076 SetTexParameterf(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002077 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002078}
2079
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002080void Context::texParameterfv(TextureType target, GLenum pname, const GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002081{
2082 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002083 SetTexParameterfv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002084 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002085}
2086
Brandon Jones59770802018-04-02 13:18:42 -07002087void Context::texParameterfvRobust(TextureType target,
2088 GLenum pname,
2089 GLsizei bufSize,
2090 const GLfloat *params)
2091{
2092 texParameterfv(target, pname, params);
2093}
2094
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002095void Context::texParameteri(TextureType target, GLenum pname, GLint param)
He Yunchao010e4db2017-03-03 14:22:06 +08002096{
2097 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002098 SetTexParameteri(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04002099 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002100}
2101
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002102void Context::texParameteriv(TextureType target, GLenum pname, const GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08002103{
2104 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04002105 SetTexParameteriv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04002106 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08002107}
2108
Brandon Jones59770802018-04-02 13:18:42 -07002109void Context::texParameterivRobust(TextureType target,
2110 GLenum pname,
2111 GLsizei bufSize,
2112 const GLint *params)
2113{
2114 texParameteriv(target, pname, params);
2115}
2116
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002117void Context::texParameterIivRobust(TextureType target,
2118 GLenum pname,
2119 GLsizei bufSize,
2120 const GLint *params)
2121{
2122 UNIMPLEMENTED();
2123}
2124
2125void Context::texParameterIuivRobust(TextureType target,
2126 GLenum pname,
2127 GLsizei bufSize,
2128 const GLuint *params)
2129{
2130 UNIMPLEMENTED();
2131}
2132
Jamie Madill493f9572018-05-24 19:52:15 -04002133void Context::drawArrays(PrimitiveMode mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002134{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002135 // No-op if count draws no primitives for given mode
2136 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002137 {
2138 return;
2139 }
2140
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002141 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002142 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
Jamie Madill09463932018-04-04 05:26:59 -04002143 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count, 1);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002144}
2145
Jamie Madill493f9572018-05-24 19:52:15 -04002146void Context::drawArraysInstanced(PrimitiveMode mode,
2147 GLint first,
2148 GLsizei count,
2149 GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04002150{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002151 // No-op if count draws no primitives for given mode
2152 if (noopDrawInstanced(mode, count, instanceCount))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002153 {
2154 return;
2155 }
2156
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002157 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002158 ANGLE_CONTEXT_TRY(
2159 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
Jamie Madill09463932018-04-04 05:26:59 -04002160 MarkTransformFeedbackBufferUsage(this, mGLState.getCurrentTransformFeedback(), count,
2161 instanceCount);
Geoff Langf6db0982015-08-25 13:04:00 -04002162}
2163
Jamie Madill493f9572018-05-24 19:52:15 -04002164void Context::drawElements(PrimitiveMode mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002165{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002166 // No-op if count draws no primitives for given mode
2167 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002168 {
2169 return;
2170 }
2171
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002172 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002173 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04002174}
2175
Jamie Madill493f9572018-05-24 19:52:15 -04002176void Context::drawElementsInstanced(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002177 GLsizei count,
2178 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002179 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04002180 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04002181{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002182 // No-op if count draws no primitives for given mode
2183 if (noopDrawInstanced(mode, count, instances))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002184 {
2185 return;
2186 }
2187
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002188 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002189 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08002190 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04002191}
2192
Jamie Madill493f9572018-05-24 19:52:15 -04002193void Context::drawRangeElements(PrimitiveMode mode,
Jamie Madill675fe712016-12-19 13:07:54 -05002194 GLuint start,
2195 GLuint end,
2196 GLsizei count,
2197 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002198 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04002199{
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06002200 // No-op if count draws no primitives for given mode
2201 if (noopDraw(mode, count))
Jamie Madill9fdaa492018-02-16 10:52:11 -05002202 {
2203 return;
2204 }
2205
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002206 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002207 ANGLE_CONTEXT_TRY(
2208 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002209}
2210
Jamie Madill493f9572018-05-24 19:52:15 -04002211void Context::drawArraysIndirect(PrimitiveMode mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002212{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002213 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002214 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002215}
2216
Jamie Madill493f9572018-05-24 19:52:15 -04002217void Context::drawElementsIndirect(PrimitiveMode mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08002218{
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07002219 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04002220 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08002221}
2222
Jamie Madill675fe712016-12-19 13:07:54 -05002223void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002224{
Jamie Madillafa02a22017-11-23 12:57:38 -05002225 handleError(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05002226}
2227
Jamie Madill675fe712016-12-19 13:07:54 -05002228void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05002229{
Jamie Madillafa02a22017-11-23 12:57:38 -05002230 handleError(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002231}
2232
Austin Kinross6ee1e782015-05-29 17:05:37 -07002233void Context::insertEventMarker(GLsizei length, const char *marker)
2234{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002235 ASSERT(mImplementation);
2236 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07002237}
2238
2239void Context::pushGroupMarker(GLsizei length, const char *marker)
2240{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002241 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05002242
2243 if (marker == nullptr)
2244 {
2245 // From the EXT_debug_marker spec,
2246 // "If <marker> is null then an empty string is pushed on the stack."
2247 mImplementation->pushGroupMarker(length, "");
2248 }
2249 else
2250 {
2251 mImplementation->pushGroupMarker(length, marker);
2252 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07002253}
2254
2255void Context::popGroupMarker()
2256{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002257 ASSERT(mImplementation);
2258 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07002259}
2260
Geoff Langd8605522016-04-13 10:19:12 -04002261void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
2262{
2263 Program *programObject = getProgram(program);
2264 ASSERT(programObject);
2265
2266 programObject->bindUniformLocation(location, name);
2267}
2268
Brandon Jones59770802018-04-02 13:18:42 -07002269void Context::coverageModulation(GLenum components)
Sami Väisänena797e062016-05-12 15:23:40 +03002270{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002271 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03002272}
2273
Brandon Jones59770802018-04-02 13:18:42 -07002274void Context::matrixLoadf(GLenum matrixMode, const GLfloat *matrix)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002275{
2276 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
2277}
2278
Brandon Jones59770802018-04-02 13:18:42 -07002279void Context::matrixLoadIdentity(GLenum matrixMode)
Sami Väisänene45e53b2016-05-25 10:36:04 +03002280{
2281 GLfloat I[16];
2282 angle::Matrix<GLfloat>::setToIdentity(I);
2283
2284 mGLState.loadPathRenderingMatrix(matrixMode, I);
2285}
2286
2287void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
2288{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002289 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002290 if (!pathObj)
2291 return;
2292
2293 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002294 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002295
2296 mImplementation->stencilFillPath(pathObj, fillMode, mask);
2297}
2298
2299void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
2300{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002301 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002302 if (!pathObj)
2303 return;
2304
2305 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002306 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002307
2308 mImplementation->stencilStrokePath(pathObj, reference, mask);
2309}
2310
2311void Context::coverFillPath(GLuint path, GLenum coverMode)
2312{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002313 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002314 if (!pathObj)
2315 return;
2316
2317 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002318 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002319
2320 mImplementation->coverFillPath(pathObj, coverMode);
2321}
2322
2323void Context::coverStrokePath(GLuint path, GLenum coverMode)
2324{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002325 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002326 if (!pathObj)
2327 return;
2328
2329 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002330 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002331
2332 mImplementation->coverStrokePath(pathObj, coverMode);
2333}
2334
2335void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
2336{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002337 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002338 if (!pathObj)
2339 return;
2340
2341 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002342 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002343
2344 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
2345}
2346
2347void Context::stencilThenCoverStrokePath(GLuint path,
2348 GLint reference,
2349 GLuint mask,
2350 GLenum coverMode)
2351{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002352 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002353 if (!pathObj)
2354 return;
2355
2356 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002357 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002358
2359 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2360}
2361
Sami Väisänend59ca052016-06-21 16:10:00 +03002362void Context::coverFillPathInstanced(GLsizei numPaths,
2363 GLenum pathNameType,
2364 const void *paths,
2365 GLuint pathBase,
2366 GLenum coverMode,
2367 GLenum transformType,
2368 const GLfloat *transformValues)
2369{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002370 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002371
2372 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002373 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002374
2375 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2376}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002377
Sami Väisänend59ca052016-06-21 16:10:00 +03002378void Context::coverStrokePathInstanced(GLsizei numPaths,
2379 GLenum pathNameType,
2380 const void *paths,
2381 GLuint pathBase,
2382 GLenum coverMode,
2383 GLenum transformType,
2384 const GLfloat *transformValues)
2385{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002386 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002387
2388 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002389 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002390
2391 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2392 transformValues);
2393}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002394
Sami Väisänend59ca052016-06-21 16:10:00 +03002395void Context::stencilFillPathInstanced(GLsizei numPaths,
2396 GLenum pathNameType,
2397 const void *paths,
2398 GLuint pathBase,
2399 GLenum fillMode,
2400 GLuint mask,
2401 GLenum transformType,
2402 const GLfloat *transformValues)
2403{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002404 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002405
2406 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002407 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002408
2409 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2410 transformValues);
2411}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002412
Sami Väisänend59ca052016-06-21 16:10:00 +03002413void Context::stencilStrokePathInstanced(GLsizei numPaths,
2414 GLenum pathNameType,
2415 const void *paths,
2416 GLuint pathBase,
2417 GLint reference,
2418 GLuint mask,
2419 GLenum transformType,
2420 const GLfloat *transformValues)
2421{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002422 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002423
2424 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002425 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002426
2427 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2428 transformValues);
2429}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002430
Sami Väisänend59ca052016-06-21 16:10:00 +03002431void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2432 GLenum pathNameType,
2433 const void *paths,
2434 GLuint pathBase,
2435 GLenum fillMode,
2436 GLuint mask,
2437 GLenum coverMode,
2438 GLenum transformType,
2439 const GLfloat *transformValues)
2440{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002441 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002442
2443 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002444 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002445
2446 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2447 transformType, transformValues);
2448}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002449
Sami Väisänend59ca052016-06-21 16:10:00 +03002450void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2451 GLenum pathNameType,
2452 const void *paths,
2453 GLuint pathBase,
2454 GLint reference,
2455 GLuint mask,
2456 GLenum coverMode,
2457 GLenum transformType,
2458 const GLfloat *transformValues)
2459{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002460 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002461
2462 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002463 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002464
2465 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2466 transformType, transformValues);
2467}
2468
Sami Väisänen46eaa942016-06-29 10:26:37 +03002469void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2470{
2471 auto *programObject = getProgram(program);
2472
2473 programObject->bindFragmentInputLocation(location, name);
2474}
2475
2476void Context::programPathFragmentInputGen(GLuint program,
2477 GLint location,
2478 GLenum genMode,
2479 GLint components,
2480 const GLfloat *coeffs)
2481{
2482 auto *programObject = getProgram(program);
2483
Jamie Madillbd044ed2017-06-05 12:59:21 -04002484 programObject->pathFragmentInputGen(this, location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002485}
2486
jchen1015015f72017-03-16 13:54:21 +08002487GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2488{
jchen10fd7c3b52017-03-21 15:36:03 +08002489 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002490 return QueryProgramResourceIndex(programObject, programInterface, name);
2491}
2492
jchen10fd7c3b52017-03-21 15:36:03 +08002493void Context::getProgramResourceName(GLuint program,
2494 GLenum programInterface,
2495 GLuint index,
2496 GLsizei bufSize,
2497 GLsizei *length,
2498 GLchar *name)
2499{
2500 const auto *programObject = getProgram(program);
2501 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2502}
2503
jchen10191381f2017-04-11 13:59:04 +08002504GLint Context::getProgramResourceLocation(GLuint program,
2505 GLenum programInterface,
2506 const GLchar *name)
2507{
2508 const auto *programObject = getProgram(program);
2509 return QueryProgramResourceLocation(programObject, programInterface, name);
2510}
2511
jchen10880683b2017-04-12 16:21:55 +08002512void Context::getProgramResourceiv(GLuint program,
2513 GLenum programInterface,
2514 GLuint index,
2515 GLsizei propCount,
2516 const GLenum *props,
2517 GLsizei bufSize,
2518 GLsizei *length,
2519 GLint *params)
2520{
2521 const auto *programObject = getProgram(program);
2522 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2523 length, params);
2524}
2525
jchen10d9cd7b72017-08-30 15:04:25 +08002526void Context::getProgramInterfaceiv(GLuint program,
2527 GLenum programInterface,
2528 GLenum pname,
2529 GLint *params)
2530{
2531 const auto *programObject = getProgram(program);
2532 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2533}
2534
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002535void Context::getProgramInterfaceivRobust(GLuint program,
2536 GLenum programInterface,
2537 GLenum pname,
2538 GLsizei bufSize,
2539 GLsizei *length,
2540 GLint *params)
2541{
2542 UNIMPLEMENTED();
2543}
2544
Jamie Madill6b873dd2018-07-12 23:56:30 -04002545void Context::handleError(const Error &error)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002546{
Jamie Madill6b873dd2018-07-12 23:56:30 -04002547 mErrors.handleError(error);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002548}
2549
2550// Get one of the recorded errors and clear its flag, if any.
2551// [OpenGL ES 2.0.24] section 2.5 page 13.
2552GLenum Context::getError()
2553{
Geoff Langda5777c2014-07-11 09:52:58 -04002554 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002555 {
Geoff Langda5777c2014-07-11 09:52:58 -04002556 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002557 }
Geoff Langda5777c2014-07-11 09:52:58 -04002558 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002559 {
Jamie Madill6b873dd2018-07-12 23:56:30 -04002560 return mErrors.popError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002561 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002562}
2563
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002564// NOTE: this function should not assume that this context is current!
Jamie Madill6b873dd2018-07-12 23:56:30 -04002565void Context::markContextLost()
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002566{
2567 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002568 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002569 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002570 mContextLostForced = true;
2571 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002572 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002573}
2574
Jamie Madill427064d2018-04-13 16:20:34 -04002575bool Context::isContextLost() const
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002576{
2577 return mContextLost;
2578}
2579
Jamie Madillfa920eb2018-01-04 11:45:50 -05002580GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002581{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002582 // Even if the application doesn't want to know about resets, we want to know
2583 // as it will allow us to skip all the calls.
2584 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002585 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002586 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002587 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002588 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002589 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002590
2591 // EXT_robustness, section 2.6: If the reset notification behavior is
2592 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2593 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2594 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002595 }
2596
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002597 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2598 // status should be returned at least once, and GL_NO_ERROR should be returned
2599 // once the device has finished resetting.
2600 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002601 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002602 ASSERT(mResetStatus == GL_NO_ERROR);
2603 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002604
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002605 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002606 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002607 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002608 }
2609 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002610 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002611 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002612 // If markContextLost was used to mark the context lost then
2613 // assume that is not recoverable, and continue to report the
2614 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002615 mResetStatus = mImplementation->getResetStatus();
2616 }
Jamie Madill893ab082014-05-16 16:56:10 -04002617
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002618 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002619}
2620
2621bool Context::isResetNotificationEnabled()
2622{
2623 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2624}
2625
Corentin Walleze3b10e82015-05-20 11:06:25 -04002626const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002627{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002628 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002629}
2630
2631EGLenum Context::getClientType() const
2632{
2633 return mClientType;
2634}
2635
2636EGLenum Context::getRenderBuffer() const
2637{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002638 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2639 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002640 {
2641 return EGL_NONE;
2642 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002643
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002644 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002645 ASSERT(backAttachment != nullptr);
2646 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002647}
2648
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002649VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002650{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002651 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002652 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2653 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002654 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002655 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2656 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002657
Jamie Madill96a483b2017-06-27 16:49:21 -04002658 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002659 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002660
2661 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002662}
2663
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002664TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002665{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002666 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002667 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2668 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002669 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002670 transformFeedback =
2671 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002672 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002673 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002674 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002675
2676 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002677}
2678
2679bool Context::isVertexArrayGenerated(GLuint vertexArray)
2680{
Jamie Madill96a483b2017-06-27 16:49:21 -04002681 ASSERT(mVertexArrayMap.contains(0));
2682 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002683}
2684
2685bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2686{
Jamie Madill96a483b2017-06-27 16:49:21 -04002687 ASSERT(mTransformFeedbackMap.contains(0));
2688 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002689}
2690
Shannon Woods53a94a82014-06-24 15:20:36 -04002691void Context::detachTexture(GLuint texture)
2692{
2693 // Simple pass-through to State's detachTexture method, as textures do not require
2694 // allocation map management either here or in the resource manager at detach time.
2695 // Zero textures are held by the Context, and we don't attempt to request them from
2696 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002697 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002698}
2699
James Darpinian4d9d4832018-03-13 12:43:28 -07002700void Context::detachBuffer(Buffer *buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002701{
Yuly Novikov5807a532015-12-03 13:01:22 -05002702 // Simple pass-through to State's detachBuffer method, since
2703 // only buffer attachments to container objects that are bound to the current context
2704 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002705
Yuly Novikov5807a532015-12-03 13:01:22 -05002706 // [OpenGL ES 3.2] section 5.1.2 page 45:
2707 // Attachments to unbound container objects, such as
2708 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2709 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002710 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002711}
2712
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002713void Context::detachFramebuffer(GLuint framebuffer)
2714{
Shannon Woods53a94a82014-06-24 15:20:36 -04002715 // Framebuffer detachment is handled by Context, because 0 is a valid
2716 // Framebuffer object, and a pointer to it must be passed from Context
2717 // to State at binding time.
2718
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002719 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002720 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2721 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2722 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002723
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002724 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002725 {
2726 bindReadFramebuffer(0);
2727 }
2728
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002729 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002730 {
2731 bindDrawFramebuffer(0);
2732 }
2733}
2734
2735void Context::detachRenderbuffer(GLuint renderbuffer)
2736{
Jamie Madilla02315b2017-02-23 14:14:47 -05002737 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002738}
2739
Jamie Madill57a89722013-07-02 11:57:03 -04002740void Context::detachVertexArray(GLuint vertexArray)
2741{
Jamie Madill77a72f62015-04-14 11:18:32 -04002742 // Vertex array detachment is handled by Context, because 0 is a valid
2743 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002744 // binding time.
2745
Jamie Madill57a89722013-07-02 11:57:03 -04002746 // [OpenGL ES 3.0.2] section 2.10 page 43:
2747 // If a vertex array object that is currently bound is deleted, the binding
2748 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madill7267aa62018-04-17 15:28:21 -04002749 if (mGLState.removeVertexArrayBinding(this, vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002750 {
2751 bindVertexArray(0);
2752 }
2753}
2754
Geoff Langc8058452014-02-03 12:04:11 -05002755void Context::detachTransformFeedback(GLuint transformFeedback)
2756{
Corentin Walleza2257da2016-04-19 16:43:12 -04002757 // Transform feedback detachment is handled by Context, because 0 is a valid
2758 // transform feedback, and a pointer to it must be passed from Context to State at
2759 // binding time.
2760
2761 // The OpenGL specification doesn't mention what should happen when the currently bound
2762 // transform feedback object is deleted. Since it is a container object, we treat it like
2763 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002764 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002765 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002766 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002767 }
Geoff Langc8058452014-02-03 12:04:11 -05002768}
2769
Jamie Madilldc356042013-07-19 16:36:57 -04002770void Context::detachSampler(GLuint sampler)
2771{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002772 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002773}
2774
Yunchao Hea336b902017-08-02 16:05:21 +08002775void Context::detachProgramPipeline(GLuint pipeline)
2776{
2777 mGLState.detachProgramPipeline(this, pipeline);
2778}
2779
Jamie Madill3ef140a2017-08-26 23:11:21 -04002780void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002781{
Shaodde78e82017-05-22 14:13:27 +08002782 mGLState.setVertexAttribDivisor(this, index, divisor);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002783}
2784
Jamie Madille29d1672013-07-19 16:36:57 -04002785void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2786{
Geoff Langc1984ed2016-10-07 12:41:00 -04002787 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002788 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002789 SetSamplerParameteri(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002790 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002791}
Jamie Madille29d1672013-07-19 16:36:57 -04002792
Geoff Langc1984ed2016-10-07 12:41:00 -04002793void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2794{
2795 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002796 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002797 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002798 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002799}
2800
Brandon Jones59770802018-04-02 13:18:42 -07002801void Context::samplerParameterivRobust(GLuint sampler,
2802 GLenum pname,
2803 GLsizei bufSize,
2804 const GLint *param)
2805{
2806 samplerParameteriv(sampler, pname, param);
2807}
2808
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002809void Context::samplerParameterIivRobust(GLuint sampler,
2810 GLenum pname,
2811 GLsizei bufSize,
2812 const GLint *param)
2813{
2814 UNIMPLEMENTED();
2815}
2816
2817void Context::samplerParameterIuivRobust(GLuint sampler,
2818 GLenum pname,
2819 GLsizei bufSize,
2820 const GLuint *param)
2821{
2822 UNIMPLEMENTED();
2823}
2824
Jamie Madille29d1672013-07-19 16:36:57 -04002825void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2826{
Geoff Langc1984ed2016-10-07 12:41:00 -04002827 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002828 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002829 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002830 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002831}
2832
Geoff Langc1984ed2016-10-07 12:41:00 -04002833void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002834{
Geoff Langc1984ed2016-10-07 12:41:00 -04002835 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002836 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002837 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002838 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002839}
2840
Brandon Jones59770802018-04-02 13:18:42 -07002841void Context::samplerParameterfvRobust(GLuint sampler,
2842 GLenum pname,
2843 GLsizei bufSize,
2844 const GLfloat *param)
2845{
2846 samplerParameterfv(sampler, pname, param);
2847}
2848
Geoff Langc1984ed2016-10-07 12:41:00 -04002849void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002850{
Geoff Langc1984ed2016-10-07 12:41:00 -04002851 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002852 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002853 QuerySamplerParameteriv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002854 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002855}
Jamie Madill9675b802013-07-19 16:36:59 -04002856
Brandon Jones59770802018-04-02 13:18:42 -07002857void Context::getSamplerParameterivRobust(GLuint sampler,
2858 GLenum pname,
2859 GLsizei bufSize,
2860 GLsizei *length,
2861 GLint *params)
2862{
2863 getSamplerParameteriv(sampler, pname, params);
2864}
2865
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07002866void Context::getSamplerParameterIivRobust(GLuint sampler,
2867 GLenum pname,
2868 GLsizei bufSize,
2869 GLsizei *length,
2870 GLint *params)
2871{
2872 UNIMPLEMENTED();
2873}
2874
2875void Context::getSamplerParameterIuivRobust(GLuint sampler,
2876 GLenum pname,
2877 GLsizei bufSize,
2878 GLsizei *length,
2879 GLuint *params)
2880{
2881 UNIMPLEMENTED();
2882}
2883
Geoff Langc1984ed2016-10-07 12:41:00 -04002884void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2885{
2886 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002887 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002888 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002889 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002890}
2891
Brandon Jones59770802018-04-02 13:18:42 -07002892void Context::getSamplerParameterfvRobust(GLuint sampler,
2893 GLenum pname,
2894 GLsizei bufSize,
2895 GLsizei *length,
2896 GLfloat *params)
2897{
2898 getSamplerParameterfv(sampler, pname, params);
2899}
2900
Olli Etuahof0fee072016-03-30 15:11:58 +03002901void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2902{
2903 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002904 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002905}
2906
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002907void Context::initRendererString()
2908{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002909 std::ostringstream rendererString;
2910 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002911 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002912 rendererString << ")";
2913
Geoff Langcec35902014-04-16 10:52:36 -04002914 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002915}
2916
Geoff Langc339c4e2016-11-29 10:37:36 -05002917void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002918{
Geoff Langc339c4e2016-11-29 10:37:36 -05002919 const Version &clientVersion = getClientVersion();
2920
2921 std::ostringstream versionString;
2922 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2923 << ANGLE_VERSION_STRING << ")";
2924 mVersionString = MakeStaticString(versionString.str());
2925
2926 std::ostringstream shadingLanguageVersionString;
2927 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2928 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2929 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2930 << ")";
2931 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002932}
2933
Geoff Langcec35902014-04-16 10:52:36 -04002934void Context::initExtensionStrings()
2935{
Geoff Langc339c4e2016-11-29 10:37:36 -05002936 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2937 std::ostringstream combinedStringStream;
2938 std::copy(strings.begin(), strings.end(),
2939 std::ostream_iterator<const char *>(combinedStringStream, " "));
2940 return MakeStaticString(combinedStringStream.str());
2941 };
2942
2943 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002944 for (const auto &extensionString : mExtensions.getStrings())
2945 {
2946 mExtensionStrings.push_back(MakeStaticString(extensionString));
2947 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002948 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002949
Geoff Langc339c4e2016-11-29 10:37:36 -05002950 mRequestableExtensionStrings.clear();
2951 for (const auto &extensionInfo : GetExtensionInfoMap())
2952 {
2953 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08002954 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
Geoff Langb0f917f2017-12-05 13:41:54 -05002955 mSupportedExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002956 {
2957 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
2958 }
2959 }
2960 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002961}
2962
Geoff Langc339c4e2016-11-29 10:37:36 -05002963const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04002964{
Geoff Langc339c4e2016-11-29 10:37:36 -05002965 switch (name)
2966 {
2967 case GL_VENDOR:
2968 return reinterpret_cast<const GLubyte *>("Google Inc.");
2969
2970 case GL_RENDERER:
2971 return reinterpret_cast<const GLubyte *>(mRendererString);
2972
2973 case GL_VERSION:
2974 return reinterpret_cast<const GLubyte *>(mVersionString);
2975
2976 case GL_SHADING_LANGUAGE_VERSION:
2977 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
2978
2979 case GL_EXTENSIONS:
2980 return reinterpret_cast<const GLubyte *>(mExtensionString);
2981
2982 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2983 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
2984
2985 default:
2986 UNREACHABLE();
2987 return nullptr;
2988 }
Geoff Langcec35902014-04-16 10:52:36 -04002989}
2990
Geoff Langc339c4e2016-11-29 10:37:36 -05002991const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04002992{
Geoff Langc339c4e2016-11-29 10:37:36 -05002993 switch (name)
2994 {
2995 case GL_EXTENSIONS:
2996 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
2997
2998 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2999 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
3000
3001 default:
3002 UNREACHABLE();
3003 return nullptr;
3004 }
Geoff Langcec35902014-04-16 10:52:36 -04003005}
3006
3007size_t Context::getExtensionStringCount() const
3008{
3009 return mExtensionStrings.size();
3010}
3011
Geoff Lang111a99e2017-10-17 10:58:41 -04003012bool Context::isExtensionRequestable(const char *name)
3013{
3014 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3015 auto extension = extensionInfos.find(name);
3016
Geoff Lang111a99e2017-10-17 10:58:41 -04003017 return extension != extensionInfos.end() && extension->second.Requestable &&
Geoff Langb0f917f2017-12-05 13:41:54 -05003018 mSupportedExtensions.*(extension->second.ExtensionsMember);
Geoff Lang111a99e2017-10-17 10:58:41 -04003019}
3020
Geoff Langc339c4e2016-11-29 10:37:36 -05003021void Context::requestExtension(const char *name)
3022{
3023 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
3024 ASSERT(extensionInfos.find(name) != extensionInfos.end());
3025 const auto &extension = extensionInfos.at(name);
3026 ASSERT(extension.Requestable);
Geoff Langb0f917f2017-12-05 13:41:54 -05003027 ASSERT(isExtensionRequestable(name));
Geoff Langc339c4e2016-11-29 10:37:36 -05003028
3029 if (mExtensions.*(extension.ExtensionsMember))
3030 {
3031 // Extension already enabled
3032 return;
3033 }
3034
3035 mExtensions.*(extension.ExtensionsMember) = true;
3036 updateCaps();
3037 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08003038
Jamie Madill2f348d22017-06-05 10:50:59 -04003039 // Release the shader compiler so it will be re-created with the requested extensions enabled.
3040 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04003041
Jamie Madill81c2e252017-09-09 23:32:46 -04003042 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
3043 // sampleable.
Jamie Madilld4442552018-02-27 22:03:47 -05003044 mState.mTextures->signalAllTexturesDirty(this);
Geoff Lang9aded172017-04-05 11:07:56 -04003045 for (auto &zeroTexture : mZeroTextures)
3046 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003047 if (zeroTexture.get() != nullptr)
3048 {
3049 zeroTexture->signalDirty(this, InitState::Initialized);
3050 }
Geoff Lang9aded172017-04-05 11:07:56 -04003051 }
3052
3053 mState.mFramebuffers->invalidateFramebufferComplenessCache();
Geoff Langc339c4e2016-11-29 10:37:36 -05003054}
3055
3056size_t Context::getRequestableExtensionStringCount() const
3057{
3058 return mRequestableExtensionStrings.size();
3059}
3060
Jamie Madill493f9572018-05-24 19:52:15 -04003061void Context::beginTransformFeedback(PrimitiveMode primitiveMode)
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003062{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003063 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003064 ASSERT(transformFeedback != nullptr);
3065 ASSERT(!transformFeedback->isPaused());
3066
Jamie Madill6c1f6712017-02-14 19:08:04 -05003067 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Olli Etuahoc3e55a42016-03-09 16:29:18 +02003068}
3069
3070bool Context::hasActiveTransformFeedback(GLuint program) const
3071{
3072 for (auto pair : mTransformFeedbackMap)
3073 {
3074 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
3075 {
3076 return true;
3077 }
3078 }
3079 return false;
3080}
3081
Geoff Lang33f11fb2018-05-07 13:42:47 -04003082Extensions Context::generateSupportedExtensions() const
Geoff Langb0f917f2017-12-05 13:41:54 -05003083{
3084 Extensions supportedExtensions = mImplementation->getNativeExtensions();
3085
jchen1082af6202018-06-22 10:59:52 +08003086 // Explicitly enable GL_KHR_parallel_shader_compile
3087 supportedExtensions.parallelShaderCompile = true;
3088
Geoff Langb0f917f2017-12-05 13:41:54 -05003089 if (getClientVersion() < ES_2_0)
3090 {
3091 // Default extensions for GLES1
3092 supportedExtensions.pointSizeArray = true;
Lingfeng Yang23dc90b2018-04-23 09:01:49 -07003093 supportedExtensions.textureCubeMap = true;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003094 supportedExtensions.pointSprite = true;
jchen1082af6202018-06-22 10:59:52 +08003095 supportedExtensions.parallelShaderCompile = false;
Geoff Langb0f917f2017-12-05 13:41:54 -05003096 }
3097
3098 if (getClientVersion() < ES_3_0)
3099 {
3100 // Disable ES3+ extensions
3101 supportedExtensions.colorBufferFloat = false;
3102 supportedExtensions.eglImageExternalEssl3 = false;
3103 supportedExtensions.textureNorm16 = false;
3104 supportedExtensions.multiview = false;
3105 supportedExtensions.maxViews = 1u;
3106 }
3107
3108 if (getClientVersion() < ES_3_1)
3109 {
3110 // Disable ES3.1+ extensions
3111 supportedExtensions.geometryShader = false;
3112 }
3113
3114 if (getClientVersion() > ES_2_0)
3115 {
3116 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
3117 // supportedExtensions.sRGB = false;
3118 }
3119
3120 // Some extensions are always available because they are implemented in the GL layer.
3121 supportedExtensions.bindUniformLocation = true;
3122 supportedExtensions.vertexArrayObject = true;
3123 supportedExtensions.bindGeneratesResource = true;
3124 supportedExtensions.clientArrays = true;
3125 supportedExtensions.requestExtension = true;
3126
3127 // Enable the no error extension if the context was created with the flag.
3128 supportedExtensions.noError = mSkipValidation;
3129
3130 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Geoff Lang33f11fb2018-05-07 13:42:47 -04003131 supportedExtensions.surfacelessContext = mSurfacelessSupported;
Geoff Langb0f917f2017-12-05 13:41:54 -05003132
3133 // Explicitly enable GL_KHR_debug
3134 supportedExtensions.debug = true;
3135 supportedExtensions.maxDebugMessageLength = 1024;
3136 supportedExtensions.maxDebugLoggedMessages = 1024;
3137 supportedExtensions.maxDebugGroupStackDepth = 1024;
3138 supportedExtensions.maxLabelLength = 1024;
3139
3140 // Explicitly enable GL_ANGLE_robust_client_memory
3141 supportedExtensions.robustClientMemory = true;
3142
3143 // Determine robust resource init availability from EGL.
Geoff Lang33f11fb2018-05-07 13:42:47 -04003144 supportedExtensions.robustResourceInitialization = mGLState.isRobustResourceInitEnabled();
Geoff Langb0f917f2017-12-05 13:41:54 -05003145
3146 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
3147 // supports it.
3148 supportedExtensions.robustBufferAccessBehavior =
3149 mRobustAccess && supportedExtensions.robustBufferAccessBehavior;
3150
3151 // Enable the cache control query unconditionally.
3152 supportedExtensions.programCacheControl = true;
3153
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003154 // Enable EGL_ANGLE_explicit_context subextensions
Geoff Lang33f11fb2018-05-07 13:42:47 -04003155 if (mExplicitContextAvailable)
Brandon Jones2b0cdcc2018-05-02 08:02:50 -07003156 {
3157 // GL_ANGLE_explicit_context_gles1
3158 supportedExtensions.explicitContextGles1 = true;
3159 // GL_ANGLE_explicit_context
3160 supportedExtensions.explicitContext = true;
3161 }
3162
Geoff Langb0f917f2017-12-05 13:41:54 -05003163 return supportedExtensions;
3164}
3165
Geoff Lang33f11fb2018-05-07 13:42:47 -04003166void Context::initCaps()
Geoff Lang493daf52014-07-03 13:38:44 -04003167{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04003168 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04003169
Geoff Lang33f11fb2018-05-07 13:42:47 -04003170 mSupportedExtensions = generateSupportedExtensions();
3171 mExtensions = mSupportedExtensions;
Lingfeng Yang01074432018-04-16 10:19:51 -07003172
3173 mLimitations = mImplementation->getNativeLimitations();
3174
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003175 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
3176 if (getClientVersion() < Version(2, 0))
3177 {
3178 mCaps.maxMultitextureUnits = 4;
3179 mCaps.maxClipPlanes = 6;
3180 mCaps.maxLights = 8;
Lingfeng Yange547aac2018-04-05 09:39:20 -07003181 mCaps.maxModelviewMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3182 mCaps.maxProjectionMatrixStackDepth = Caps::GlobalMatrixStackDepth;
3183 mCaps.maxTextureMatrixStackDepth = Caps::GlobalMatrixStackDepth;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003184 mCaps.minSmoothPointSize = 1.0f;
3185 mCaps.maxSmoothPointSize = 1.0f;
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08003186 }
3187
Luc Ferronad2ae932018-06-11 15:31:17 -04003188 // Apply/Verify implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04003189 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003190
Luc Ferronad2ae932018-06-11 15:31:17 -04003191 ASSERT(mCaps.minAliasedPointSize >= 1.0f);
3192
Jamie Madill0f80ed82017-09-19 00:24:56 -04003193 if (getClientVersion() < ES_3_1)
3194 {
3195 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
3196 }
3197 else
3198 {
3199 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
3200 }
Geoff Lang301d1612014-07-09 10:34:37 -04003201
Jiawei Shao54aafe52018-04-27 14:54:57 +08003202 LimitCap(&mCaps.maxShaderUniformBlocks[ShaderType::Vertex],
3203 IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
Jamie Madill0f80ed82017-09-19 00:24:56 -04003204 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3205 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
3206
3207 // Limit textures as well, so we can use fast bitsets with texture bindings.
3208 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
Jiawei Shao54aafe52018-04-27 14:54:57 +08003209 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Vertex],
3210 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
3211 LimitCap(&mCaps.maxShaderTextureImageUnits[ShaderType::Fragment],
3212 IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04003213
Jiawei Shaodb342272017-09-27 10:21:45 +08003214 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
3215
Geoff Langc287ea62016-09-16 14:46:51 -04003216 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05003217 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04003218 for (const auto &extensionInfo : GetExtensionInfoMap())
3219 {
Geoff Lang0ab41fa2018-03-14 11:03:30 -04003220 // If the user has requested that extensions start disabled and they are requestable,
3221 // disable them.
3222 if (!mExtensionsEnabled && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04003223 {
3224 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
3225 }
3226 }
3227
3228 // Generate texture caps
3229 updateCaps();
3230}
3231
3232void Context::updateCaps()
3233{
Geoff Lang900013c2014-07-07 11:32:19 -04003234 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04003235 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04003236
Jamie Madill7b62cf92017-11-02 15:20:49 -04003237 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04003238 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04003239 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04003240 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003241
Geoff Lang0d8b7242015-09-09 14:56:53 -04003242 // Update the format caps based on the client version and extensions.
3243 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
3244 // ES3.
3245 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003246 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04003247 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04003248 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Yuly Novikovf15f8862018-06-04 18:59:41 -04003249 formatCaps.textureAttachment =
3250 formatCaps.textureAttachment &&
3251 formatInfo.textureAttachmentSupport(getClientVersion(), mExtensions);
3252 formatCaps.renderbuffer = formatCaps.renderbuffer &&
3253 formatInfo.renderbufferSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04003254
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003255 // OpenGL ES does not support multisampling with non-rendererable formats
3256 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Yuly Novikovf15f8862018-06-04 18:59:41 -04003257 if (!formatCaps.renderbuffer ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08003258 (getClientVersion() < ES_3_1 &&
3259 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04003260 {
Geoff Langd87878e2014-09-19 15:42:59 -04003261 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04003262 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03003263 else
3264 {
3265 // We may have limited the max samples for some required renderbuffer formats due to
3266 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
3267 GLuint formatMaxSamples = formatCaps.getMaxSamples();
3268
3269 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
3270 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
3271 // exception of signed and unsigned integer formats."
3272 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
3273 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
3274 {
3275 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
3276 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
3277 }
3278
3279 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
3280 if (getClientVersion() >= ES_3_1)
3281 {
3282 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
3283 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
3284 // the exception that the signed and unsigned integer formats are required only to
3285 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
3286 // multisamples, which must be at least one."
3287 if (formatInfo.componentType == GL_INT ||
3288 formatInfo.componentType == GL_UNSIGNED_INT)
3289 {
3290 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
3291 }
3292
3293 // GLES 3.1 section 19.3.1.
3294 if (formatCaps.texturable)
3295 {
3296 if (formatInfo.depthBits > 0)
3297 {
3298 mCaps.maxDepthTextureSamples =
3299 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
3300 }
3301 else if (formatInfo.redBits > 0)
3302 {
3303 mCaps.maxColorTextureSamples =
3304 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
3305 }
3306 }
3307 }
3308 }
Geoff Langd87878e2014-09-19 15:42:59 -04003309
3310 if (formatCaps.texturable && formatInfo.compressed)
3311 {
Geoff Langca271392017-04-05 12:30:00 -04003312 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04003313 }
3314
Geoff Langca271392017-04-05 12:30:00 -04003315 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04003316 }
Jamie Madill32447362017-06-28 14:53:52 -04003317
3318 // If program binary is disabled, blank out the memory cache pointer.
Geoff Langb0f917f2017-12-05 13:41:54 -05003319 if (!mSupportedExtensions.getProgramBinary)
Jamie Madill32447362017-06-28 14:53:52 -04003320 {
3321 mMemoryProgramCache = nullptr;
3322 }
Corentin Walleze4477002017-12-01 14:39:58 -05003323
3324 // Compute which buffer types are allowed
3325 mValidBufferBindings.reset();
3326 mValidBufferBindings.set(BufferBinding::ElementArray);
3327 mValidBufferBindings.set(BufferBinding::Array);
3328
3329 if (mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
3330 {
3331 mValidBufferBindings.set(BufferBinding::PixelPack);
3332 mValidBufferBindings.set(BufferBinding::PixelUnpack);
3333 }
3334
3335 if (getClientVersion() >= ES_3_0)
3336 {
3337 mValidBufferBindings.set(BufferBinding::CopyRead);
3338 mValidBufferBindings.set(BufferBinding::CopyWrite);
3339 mValidBufferBindings.set(BufferBinding::TransformFeedback);
3340 mValidBufferBindings.set(BufferBinding::Uniform);
3341 }
3342
3343 if (getClientVersion() >= ES_3_1)
3344 {
3345 mValidBufferBindings.set(BufferBinding::AtomicCounter);
3346 mValidBufferBindings.set(BufferBinding::ShaderStorage);
3347 mValidBufferBindings.set(BufferBinding::DrawIndirect);
3348 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
3349 }
Geoff Lang493daf52014-07-03 13:38:44 -04003350}
3351
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003352void Context::initWorkarounds()
3353{
Jamie Madill761b02c2017-06-23 16:27:06 -04003354 // Apply back-end workarounds.
3355 mImplementation->applyNativeWorkarounds(&mWorkarounds);
3356
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003357 // Lose the context upon out of memory error if the application is
3358 // expecting to watch for those events.
3359 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
3360}
3361
Tobin Ehlisd7890bc2018-06-29 11:57:22 -06003362// Return true if the draw is a no-op, else return false.
3363// A no-op draw occurs if the count of vertices is less than the minimum required to
3364// have a valid primitive for this mode (0 for points, 0-1 for lines, 0-2 for tris).
3365bool Context::noopDraw(PrimitiveMode mode, GLsizei count)
3366{
3367 return count < kMinimumPrimitiveCounts[mode];
3368}
3369
3370bool Context::noopDrawInstanced(PrimitiveMode mode, GLsizei count, GLsizei instanceCount)
3371{
3372 return (instanceCount == 0) || noopDraw(mode, count);
3373}
3374
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003375Error Context::prepareForDraw(PrimitiveMode mode)
Jamie Madill05b35b22017-10-03 09:01:44 -04003376{
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003377 if (mGLES1Renderer)
3378 {
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07003379 ANGLE_TRY(mGLES1Renderer->prepareForDraw(mode, this, &mGLState));
Lingfeng Yang461b09a2018-04-23 09:02:09 -07003380 }
3381
Geoff Langa8cb2872018-03-09 16:09:40 -05003382 ANGLE_TRY(syncDirtyObjects());
Jamie Madilla59fc192017-11-02 12:57:58 -04003383
3384 if (isRobustResourceInitEnabled())
3385 {
3386 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
3387 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
3388 }
3389
Geoff Langa8cb2872018-03-09 16:09:40 -05003390 ANGLE_TRY(syncDirtyBits());
Geoff Langd4fff502017-09-22 11:28:28 -04003391 return NoError();
3392}
3393
3394Error Context::prepareForClear(GLbitfield mask)
3395{
Geoff Langa8cb2872018-03-09 16:09:40 -05003396 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003397 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearAttachmentsInitialized(this, mask));
Geoff Langa8cb2872018-03-09 16:09:40 -05003398 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04003399 return NoError();
3400}
3401
3402Error Context::prepareForClearBuffer(GLenum buffer, GLint drawbuffer)
3403{
Geoff Langa8cb2872018-03-09 16:09:40 -05003404 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04003405 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearBufferAttachmentsInitialized(this, buffer,
3406 drawbuffer));
Geoff Langa8cb2872018-03-09 16:09:40 -05003407 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill05b35b22017-10-03 09:01:44 -04003408 return NoError();
3409}
3410
Geoff Langa8cb2872018-03-09 16:09:40 -05003411Error Context::syncState()
Jamie Madill1b94d432015-08-07 13:23:23 -04003412{
Geoff Langa8cb2872018-03-09 16:09:40 -05003413 ANGLE_TRY(syncDirtyObjects());
3414 ANGLE_TRY(syncDirtyBits());
Jamie Madillbc918e72018-03-08 09:47:21 -05003415 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003416}
3417
Geoff Langa8cb2872018-03-09 16:09:40 -05003418Error Context::syncState(const State::DirtyBits &bitMask, const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04003419{
Geoff Langa8cb2872018-03-09 16:09:40 -05003420 ANGLE_TRY(syncDirtyObjects(objectMask));
3421 ANGLE_TRY(syncDirtyBits(bitMask));
Geoff Langd4fff502017-09-22 11:28:28 -04003422 return NoError();
3423}
3424
Geoff Langa8cb2872018-03-09 16:09:40 -05003425Error Context::syncDirtyBits()
Geoff Langd4fff502017-09-22 11:28:28 -04003426{
3427 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
Jamie Madill189ad872018-07-09 13:32:37 -04003428 ANGLE_TRY(mImplementation->syncState(this, dirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04003429 mGLState.clearDirtyBits();
3430 return NoError();
3431}
3432
Geoff Langa8cb2872018-03-09 16:09:40 -05003433Error Context::syncDirtyBits(const State::DirtyBits &bitMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003434{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003435 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madill189ad872018-07-09 13:32:37 -04003436 ANGLE_TRY(mImplementation->syncState(this, dirtyBits));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003437 mGLState.clearDirtyBits(dirtyBits);
Jamie Madillbc918e72018-03-08 09:47:21 -05003438 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04003439}
Jamie Madillc29968b2016-01-20 11:17:23 -05003440
Geoff Langa8cb2872018-03-09 16:09:40 -05003441Error Context::syncDirtyObjects()
Geoff Langd4fff502017-09-22 11:28:28 -04003442{
3443 return mGLState.syncDirtyObjects(this);
3444}
3445
Geoff Langa8cb2872018-03-09 16:09:40 -05003446Error Context::syncDirtyObjects(const State::DirtyObjects &objectMask)
Geoff Langd4fff502017-09-22 11:28:28 -04003447{
3448 return mGLState.syncDirtyObjects(this, objectMask);
3449}
3450
Jamie Madillc29968b2016-01-20 11:17:23 -05003451void Context::blitFramebuffer(GLint srcX0,
3452 GLint srcY0,
3453 GLint srcX1,
3454 GLint srcY1,
3455 GLint dstX0,
3456 GLint dstY0,
3457 GLint dstX1,
3458 GLint dstY1,
3459 GLbitfield mask,
3460 GLenum filter)
3461{
Qin Jiajiaaef92162018-02-27 13:51:44 +08003462 if (mask == 0)
3463 {
3464 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
3465 // buffers are copied.
3466 return;
3467 }
3468
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003469 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003470 ASSERT(drawFramebuffer);
3471
3472 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
3473 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
3474
Jamie Madillbc918e72018-03-08 09:47:21 -05003475 ANGLE_CONTEXT_TRY(syncStateForBlit());
Jamie Madillc29968b2016-01-20 11:17:23 -05003476
Jamie Madillc564c072017-06-01 12:45:42 -04003477 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003478}
Jamie Madillc29968b2016-01-20 11:17:23 -05003479
3480void Context::clear(GLbitfield mask)
3481{
Geoff Langd4fff502017-09-22 11:28:28 -04003482 ANGLE_CONTEXT_TRY(prepareForClear(mask));
3483 ANGLE_CONTEXT_TRY(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05003484}
3485
3486void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
3487{
Geoff Langd4fff502017-09-22 11:28:28 -04003488 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3489 ANGLE_CONTEXT_TRY(
3490 mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003491}
3492
3493void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3494{
Geoff Langd4fff502017-09-22 11:28:28 -04003495 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3496 ANGLE_CONTEXT_TRY(
3497 mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003498}
3499
3500void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3501{
Geoff Langd4fff502017-09-22 11:28:28 -04003502 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3503 ANGLE_CONTEXT_TRY(
3504 mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003505}
3506
3507void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3508{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003509 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003510 ASSERT(framebufferObject);
3511
3512 // If a buffer is not present, the clear has no effect
3513 if (framebufferObject->getDepthbuffer() == nullptr &&
3514 framebufferObject->getStencilbuffer() == nullptr)
3515 {
3516 return;
3517 }
3518
Geoff Langd4fff502017-09-22 11:28:28 -04003519 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3520 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003521}
3522
3523void Context::readPixels(GLint x,
3524 GLint y,
3525 GLsizei width,
3526 GLsizei height,
3527 GLenum format,
3528 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003529 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003530{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003531 if (width == 0 || height == 0)
3532 {
3533 return;
3534 }
3535
Jamie Madillbc918e72018-03-08 09:47:21 -05003536 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003537
Jamie Madillb6664922017-07-25 12:55:04 -04003538 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3539 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003540
3541 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04003542 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003543}
3544
Brandon Jones59770802018-04-02 13:18:42 -07003545void Context::readPixelsRobust(GLint x,
3546 GLint y,
3547 GLsizei width,
3548 GLsizei height,
3549 GLenum format,
3550 GLenum type,
3551 GLsizei bufSize,
3552 GLsizei *length,
3553 GLsizei *columns,
3554 GLsizei *rows,
3555 void *pixels)
3556{
3557 readPixels(x, y, width, height, format, type, pixels);
3558}
3559
3560void Context::readnPixelsRobust(GLint x,
3561 GLint y,
3562 GLsizei width,
3563 GLsizei height,
3564 GLenum format,
3565 GLenum type,
3566 GLsizei bufSize,
3567 GLsizei *length,
3568 GLsizei *columns,
3569 GLsizei *rows,
3570 void *data)
3571{
3572 readPixels(x, y, width, height, format, type, data);
3573}
3574
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003575void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003576 GLint level,
3577 GLenum internalformat,
3578 GLint x,
3579 GLint y,
3580 GLsizei width,
3581 GLsizei height,
3582 GLint border)
3583{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003584 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003585 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003586
Jamie Madillc29968b2016-01-20 11:17:23 -05003587 Rectangle sourceArea(x, y, width, height);
3588
Jamie Madill05b35b22017-10-03 09:01:44 -04003589 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003590 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003591 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003592}
3593
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003594void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003595 GLint level,
3596 GLint xoffset,
3597 GLint yoffset,
3598 GLint x,
3599 GLint y,
3600 GLsizei width,
3601 GLsizei height)
3602{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003603 if (width == 0 || height == 0)
3604 {
3605 return;
3606 }
3607
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003608 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003609 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003610
Jamie Madillc29968b2016-01-20 11:17:23 -05003611 Offset destOffset(xoffset, yoffset, 0);
3612 Rectangle sourceArea(x, y, width, height);
3613
Jamie Madill05b35b22017-10-03 09:01:44 -04003614 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003615 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003616 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003617}
3618
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003619void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003620 GLint level,
3621 GLint xoffset,
3622 GLint yoffset,
3623 GLint zoffset,
3624 GLint x,
3625 GLint y,
3626 GLsizei width,
3627 GLsizei height)
3628{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003629 if (width == 0 || height == 0)
3630 {
3631 return;
3632 }
3633
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003634 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003635 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003636
Jamie Madillc29968b2016-01-20 11:17:23 -05003637 Offset destOffset(xoffset, yoffset, zoffset);
3638 Rectangle sourceArea(x, y, width, height);
3639
Jamie Madill05b35b22017-10-03 09:01:44 -04003640 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3641 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003642 handleError(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level, destOffset,
3643 sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003644}
3645
3646void Context::framebufferTexture2D(GLenum target,
3647 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003648 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003649 GLuint texture,
3650 GLint level)
3651{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003652 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003653 ASSERT(framebuffer);
3654
3655 if (texture != 0)
3656 {
3657 Texture *textureObj = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003658 ImageIndex index = ImageIndex::MakeFromTarget(textarget, level);
Jamie Madilla02315b2017-02-23 14:14:47 -05003659 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003660 }
3661 else
3662 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003663 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003664 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003665
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003666 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003667}
3668
3669void Context::framebufferRenderbuffer(GLenum target,
3670 GLenum attachment,
3671 GLenum renderbuffertarget,
3672 GLuint renderbuffer)
3673{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003674 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003675 ASSERT(framebuffer);
3676
3677 if (renderbuffer != 0)
3678 {
3679 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003680
Jamie Madillcc129372018-04-12 09:13:18 -04003681 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003682 renderbufferObject);
3683 }
3684 else
3685 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003686 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003687 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003688
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003689 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003690}
3691
3692void Context::framebufferTextureLayer(GLenum target,
3693 GLenum attachment,
3694 GLuint texture,
3695 GLint level,
3696 GLint layer)
3697{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003698 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003699 ASSERT(framebuffer);
3700
3701 if (texture != 0)
3702 {
3703 Texture *textureObject = getTexture(texture);
Jamie Madillcc129372018-04-12 09:13:18 -04003704 ImageIndex index = ImageIndex::MakeFromType(textureObject->getType(), level, layer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003705 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003706 }
3707 else
3708 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003709 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003710 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003711
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003712 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003713}
3714
Brandon Jones59770802018-04-02 13:18:42 -07003715void Context::framebufferTextureMultiviewLayered(GLenum target,
3716 GLenum attachment,
3717 GLuint texture,
3718 GLint level,
3719 GLint baseViewIndex,
3720 GLsizei numViews)
Martin Radev137032d2017-07-13 10:11:12 +03003721{
Martin Radev82ef7742017-08-08 17:44:58 +03003722 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3723 ASSERT(framebuffer);
3724
3725 if (texture != 0)
3726 {
3727 Texture *textureObj = getTexture(texture);
3728
Martin Radev18b75ba2017-08-15 15:50:40 +03003729 ImageIndex index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
Martin Radev82ef7742017-08-08 17:44:58 +03003730 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3731 numViews, baseViewIndex);
3732 }
3733 else
3734 {
3735 framebuffer->resetAttachment(this, attachment);
3736 }
3737
3738 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003739}
3740
Brandon Jones59770802018-04-02 13:18:42 -07003741void Context::framebufferTextureMultiviewSideBySide(GLenum target,
3742 GLenum attachment,
3743 GLuint texture,
3744 GLint level,
3745 GLsizei numViews,
3746 const GLint *viewportOffsets)
Martin Radev137032d2017-07-13 10:11:12 +03003747{
Martin Radev5dae57b2017-07-14 16:15:55 +03003748 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3749 ASSERT(framebuffer);
3750
3751 if (texture != 0)
3752 {
3753 Texture *textureObj = getTexture(texture);
3754
3755 ImageIndex index = ImageIndex::Make2D(level);
3756 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3757 textureObj, numViews, viewportOffsets);
3758 }
3759 else
3760 {
3761 framebuffer->resetAttachment(this, attachment);
3762 }
3763
3764 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003765}
3766
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003767void Context::framebufferTexture(GLenum target, GLenum attachment, GLuint texture, GLint level)
3768{
Jiawei Shaoa8802472018-05-28 11:17:47 +08003769 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3770 ASSERT(framebuffer);
3771
3772 if (texture != 0)
3773 {
3774 Texture *textureObj = getTexture(texture);
3775
3776 ImageIndex index = ImageIndex::MakeFromType(
3777 textureObj->getType(), level, ImageIndex::kEntireLevel, ImageIndex::kEntireLevel);
3778 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
3779 }
3780 else
3781 {
3782 framebuffer->resetAttachment(this, attachment);
3783 }
3784
3785 mGLState.setObjectDirty(target);
Jiawei Shao5f9482f2018-05-18 09:00:09 +08003786}
3787
Jamie Madillc29968b2016-01-20 11:17:23 -05003788void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3789{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003790 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003791 ASSERT(framebuffer);
3792 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003793 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003794}
3795
3796void Context::readBuffer(GLenum mode)
3797{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003798 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003799 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003800 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003801}
3802
3803void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3804{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003805 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003806 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003807
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003808 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003809 ASSERT(framebuffer);
3810
3811 // The specification isn't clear what should be done when the framebuffer isn't complete.
3812 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003813 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003814}
3815
3816void Context::invalidateFramebuffer(GLenum target,
3817 GLsizei numAttachments,
3818 const GLenum *attachments)
3819{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003820 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003821 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003822
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003823 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003824 ASSERT(framebuffer);
3825
Jamie Madill427064d2018-04-13 16:20:34 -04003826 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003827 {
Jamie Madill437fa652016-05-03 15:13:24 -04003828 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003829 }
Jamie Madill437fa652016-05-03 15:13:24 -04003830
Jamie Madill4928b7c2017-06-20 12:57:39 -04003831 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003832}
3833
3834void Context::invalidateSubFramebuffer(GLenum target,
3835 GLsizei numAttachments,
3836 const GLenum *attachments,
3837 GLint x,
3838 GLint y,
3839 GLsizei width,
3840 GLsizei height)
3841{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003842 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003843 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003844
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003845 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003846 ASSERT(framebuffer);
3847
Jamie Madill427064d2018-04-13 16:20:34 -04003848 if (!framebuffer->isComplete(this))
Jamie Madillc29968b2016-01-20 11:17:23 -05003849 {
Jamie Madill437fa652016-05-03 15:13:24 -04003850 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003851 }
Jamie Madill437fa652016-05-03 15:13:24 -04003852
3853 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003854 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003855}
3856
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003857void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003858 GLint level,
3859 GLint internalformat,
3860 GLsizei width,
3861 GLsizei height,
3862 GLint border,
3863 GLenum format,
3864 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003865 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003866{
Jamie Madillbc918e72018-03-08 09:47:21 -05003867 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003868
3869 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003870 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003871 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003872 size, format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003873}
3874
Brandon Jones59770802018-04-02 13:18:42 -07003875void Context::texImage2DRobust(TextureTarget target,
3876 GLint level,
3877 GLint internalformat,
3878 GLsizei width,
3879 GLsizei height,
3880 GLint border,
3881 GLenum format,
3882 GLenum type,
3883 GLsizei bufSize,
3884 const void *pixels)
3885{
3886 texImage2D(target, level, internalformat, width, height, border, format, type, pixels);
3887}
3888
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003889void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003890 GLint level,
3891 GLint internalformat,
3892 GLsizei width,
3893 GLsizei height,
3894 GLsizei depth,
3895 GLint border,
3896 GLenum format,
3897 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003898 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003899{
Jamie Madillbc918e72018-03-08 09:47:21 -05003900 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003901
3902 Extents size(width, height, depth);
3903 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003904 handleError(texture->setImage(this, mGLState.getUnpackState(),
3905 NonCubeTextureTypeToTarget(target), level, internalformat, size,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003906 format, type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003907}
3908
Brandon Jones59770802018-04-02 13:18:42 -07003909void Context::texImage3DRobust(TextureType target,
3910 GLint level,
3911 GLint internalformat,
3912 GLsizei width,
3913 GLsizei height,
3914 GLsizei depth,
3915 GLint border,
3916 GLenum format,
3917 GLenum type,
3918 GLsizei bufSize,
3919 const void *pixels)
3920{
3921 texImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels);
3922}
3923
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003924void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003925 GLint level,
3926 GLint xoffset,
3927 GLint yoffset,
3928 GLsizei width,
3929 GLsizei height,
3930 GLenum format,
3931 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003932 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003933{
3934 // Zero sized uploads are valid but no-ops
3935 if (width == 0 || height == 0)
3936 {
3937 return;
3938 }
3939
Jamie Madillbc918e72018-03-08 09:47:21 -05003940 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003941
3942 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003943 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003944 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003945 type, static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003946}
3947
Brandon Jones59770802018-04-02 13:18:42 -07003948void Context::texSubImage2DRobust(TextureTarget target,
3949 GLint level,
3950 GLint xoffset,
3951 GLint yoffset,
3952 GLsizei width,
3953 GLsizei height,
3954 GLenum format,
3955 GLenum type,
3956 GLsizei bufSize,
3957 const void *pixels)
3958{
3959 texSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
3960}
3961
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003962void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003963 GLint level,
3964 GLint xoffset,
3965 GLint yoffset,
3966 GLint zoffset,
3967 GLsizei width,
3968 GLsizei height,
3969 GLsizei depth,
3970 GLenum format,
3971 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003972 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003973{
3974 // Zero sized uploads are valid but no-ops
3975 if (width == 0 || height == 0 || depth == 0)
3976 {
3977 return;
3978 }
3979
Jamie Madillbc918e72018-03-08 09:47:21 -05003980 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003981
3982 Box area(xoffset, yoffset, zoffset, width, height, depth);
3983 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003984 handleError(texture->setSubImage(this, mGLState.getUnpackState(),
3985 NonCubeTextureTypeToTarget(target), level, area, format, type,
Rafael Cintron05a449a2018-06-20 18:08:04 -07003986 static_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003987}
3988
Brandon Jones59770802018-04-02 13:18:42 -07003989void Context::texSubImage3DRobust(TextureType target,
3990 GLint level,
3991 GLint xoffset,
3992 GLint yoffset,
3993 GLint zoffset,
3994 GLsizei width,
3995 GLsizei height,
3996 GLsizei depth,
3997 GLenum format,
3998 GLenum type,
3999 GLsizei bufSize,
4000 const void *pixels)
4001{
4002 texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type,
4003 pixels);
4004}
4005
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004006void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004007 GLint level,
4008 GLenum internalformat,
4009 GLsizei width,
4010 GLsizei height,
4011 GLint border,
4012 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004013 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004014{
Jamie Madillbc918e72018-03-08 09:47:21 -05004015 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004016
4017 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004018 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05004019 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
4020 internalformat, size, imageSize,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004021 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004022}
4023
Brandon Jones59770802018-04-02 13:18:42 -07004024void Context::compressedTexImage2DRobust(TextureTarget target,
4025 GLint level,
4026 GLenum internalformat,
4027 GLsizei width,
4028 GLsizei height,
4029 GLint border,
4030 GLsizei imageSize,
4031 GLsizei dataSize,
4032 const GLvoid *data)
4033{
4034 compressedTexImage2D(target, level, internalformat, width, height, border, imageSize, data);
4035}
4036
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004037void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004038 GLint level,
4039 GLenum internalformat,
4040 GLsizei width,
4041 GLsizei height,
4042 GLsizei depth,
4043 GLint border,
4044 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004045 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004046{
Jamie Madillbc918e72018-03-08 09:47:21 -05004047 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004048
4049 Extents size(width, height, depth);
4050 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004051 handleError(texture->setCompressedImage(
4052 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004053 size, imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004054}
4055
Brandon Jones59770802018-04-02 13:18:42 -07004056void Context::compressedTexImage3DRobust(TextureType target,
4057 GLint level,
4058 GLenum internalformat,
4059 GLsizei width,
4060 GLsizei height,
4061 GLsizei depth,
4062 GLint border,
4063 GLsizei imageSize,
4064 GLsizei dataSize,
4065 const GLvoid *data)
4066{
4067 compressedTexImage3D(target, level, internalformat, width, height, depth, border, imageSize,
4068 data);
4069}
4070
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004071void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05004072 GLint level,
4073 GLint xoffset,
4074 GLint yoffset,
4075 GLsizei width,
4076 GLsizei height,
4077 GLenum format,
4078 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004079 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004080{
Jamie Madillbc918e72018-03-08 09:47:21 -05004081 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004082
4083 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004084 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05004085 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
4086 format, imageSize,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004087 static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004088}
4089
Brandon Jones59770802018-04-02 13:18:42 -07004090void Context::compressedTexSubImage2DRobust(TextureTarget target,
4091 GLint level,
4092 GLint xoffset,
4093 GLint yoffset,
4094 GLsizei width,
4095 GLsizei height,
4096 GLenum format,
4097 GLsizei imageSize,
4098 GLsizei dataSize,
4099 const GLvoid *data)
4100{
4101 compressedTexSubImage2D(target, level, xoffset, yoffset, width, height, format, imageSize,
4102 data);
4103}
4104
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004105void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05004106 GLint level,
4107 GLint xoffset,
4108 GLint yoffset,
4109 GLint zoffset,
4110 GLsizei width,
4111 GLsizei height,
4112 GLsizei depth,
4113 GLenum format,
4114 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04004115 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05004116{
4117 // Zero sized uploads are valid but no-ops
4118 if (width == 0 || height == 0)
4119 {
4120 return;
4121 }
4122
Jamie Madillbc918e72018-03-08 09:47:21 -05004123 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05004124
4125 Box area(xoffset, yoffset, zoffset, width, height, depth);
4126 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004127 handleError(texture->setCompressedSubImage(
4128 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
Rafael Cintron05a449a2018-06-20 18:08:04 -07004129 imageSize, static_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05004130}
4131
Brandon Jones59770802018-04-02 13:18:42 -07004132void Context::compressedTexSubImage3DRobust(TextureType target,
4133 GLint level,
4134 GLint xoffset,
4135 GLint yoffset,
4136 GLint zoffset,
4137 GLsizei width,
4138 GLsizei height,
4139 GLsizei depth,
4140 GLenum format,
4141 GLsizei imageSize,
4142 GLsizei dataSize,
4143 const GLvoid *data)
4144{
4145 compressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format,
4146 imageSize, data);
4147}
4148
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004149void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004150{
4151 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05004152 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03004153}
4154
Jamie Madill007530e2017-12-28 14:27:04 -05004155void Context::copyTexture(GLuint sourceId,
4156 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004157 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004158 GLuint destId,
4159 GLint destLevel,
4160 GLint internalFormat,
4161 GLenum destType,
4162 GLboolean unpackFlipY,
4163 GLboolean unpackPremultiplyAlpha,
4164 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004165{
Jamie Madillbc918e72018-03-08 09:47:21 -05004166 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004167
4168 gl::Texture *sourceTexture = getTexture(sourceId);
4169 gl::Texture *destTexture = getTexture(destId);
Geoff Lang92019432017-11-20 13:09:34 -05004170 handleError(destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType,
4171 sourceLevel, ConvertToBool(unpackFlipY),
4172 ConvertToBool(unpackPremultiplyAlpha),
4173 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004174}
4175
Jamie Madill007530e2017-12-28 14:27:04 -05004176void Context::copySubTexture(GLuint sourceId,
4177 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05004178 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05004179 GLuint destId,
4180 GLint destLevel,
4181 GLint xoffset,
4182 GLint yoffset,
4183 GLint x,
4184 GLint y,
4185 GLsizei width,
4186 GLsizei height,
4187 GLboolean unpackFlipY,
4188 GLboolean unpackPremultiplyAlpha,
4189 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07004190{
4191 // Zero sized copies are valid but no-ops
4192 if (width == 0 || height == 0)
4193 {
4194 return;
4195 }
4196
Jamie Madillbc918e72018-03-08 09:47:21 -05004197 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07004198
4199 gl::Texture *sourceTexture = getTexture(sourceId);
4200 gl::Texture *destTexture = getTexture(destId);
4201 Offset offset(xoffset, yoffset, 0);
4202 Rectangle area(x, y, width, height);
Geoff Lang92019432017-11-20 13:09:34 -05004203 handleError(destTexture->copySubTexture(this, destTarget, destLevel, offset, sourceLevel, area,
4204 ConvertToBool(unpackFlipY),
4205 ConvertToBool(unpackPremultiplyAlpha),
4206 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07004207}
4208
Jamie Madill007530e2017-12-28 14:27:04 -05004209void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07004210{
Jamie Madillbc918e72018-03-08 09:47:21 -05004211 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07004212
4213 gl::Texture *sourceTexture = getTexture(sourceId);
4214 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05004215 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07004216}
4217
Corentin Wallez336129f2017-10-17 15:55:40 -04004218void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03004219{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004220 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004221 ASSERT(buffer);
4222
Geoff Lang496c02d2016-10-20 11:38:11 -07004223 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03004224}
4225
Brandon Jones59770802018-04-02 13:18:42 -07004226void Context::getBufferPointervRobust(BufferBinding target,
4227 GLenum pname,
4228 GLsizei bufSize,
4229 GLsizei *length,
4230 void **params)
4231{
4232 getBufferPointerv(target, pname, params);
4233}
4234
Corentin Wallez336129f2017-10-17 15:55:40 -04004235void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004236{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004237 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004238 ASSERT(buffer);
4239
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004240 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004241 if (error.isError())
4242 {
Jamie Madill437fa652016-05-03 15:13:24 -04004243 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004244 return nullptr;
4245 }
4246
4247 return buffer->getMapPointer();
4248}
4249
Corentin Wallez336129f2017-10-17 15:55:40 -04004250GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03004251{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004252 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004253 ASSERT(buffer);
4254
4255 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004256 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03004257 if (error.isError())
4258 {
Jamie Madill437fa652016-05-03 15:13:24 -04004259 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004260 return GL_FALSE;
4261 }
4262
4263 return result;
4264}
4265
Corentin Wallez336129f2017-10-17 15:55:40 -04004266void *Context::mapBufferRange(BufferBinding target,
4267 GLintptr offset,
4268 GLsizeiptr length,
4269 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03004270{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004271 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03004272 ASSERT(buffer);
4273
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004274 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03004275 if (error.isError())
4276 {
Jamie Madill437fa652016-05-03 15:13:24 -04004277 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03004278 return nullptr;
4279 }
4280
4281 return buffer->getMapPointer();
4282}
4283
Corentin Wallez336129f2017-10-17 15:55:40 -04004284void Context::flushMappedBufferRange(BufferBinding /*target*/,
4285 GLintptr /*offset*/,
4286 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03004287{
4288 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
4289}
4290
Jamie Madillbc918e72018-03-08 09:47:21 -05004291Error Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004292{
Geoff Langa8cb2872018-03-09 16:09:40 -05004293 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004294}
4295
Jamie Madillbc918e72018-03-08 09:47:21 -05004296Error Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004297{
Geoff Langa8cb2872018-03-09 16:09:40 -05004298 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004299}
4300
Jamie Madillbc918e72018-03-08 09:47:21 -05004301Error Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05004302{
Geoff Langa8cb2872018-03-09 16:09:40 -05004303 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05004304}
4305
Jiajia Qin5451d532017-11-16 17:16:34 +08004306void Context::activeShaderProgram(GLuint pipeline, GLuint program)
4307{
4308 UNIMPLEMENTED();
4309}
4310
Jamie Madillc20ab272016-06-09 07:20:46 -07004311void Context::activeTexture(GLenum texture)
4312{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004313 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004314}
4315
Jamie Madill876429b2017-04-20 15:46:24 -04004316void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004317{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004318 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004319}
4320
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004321void Context::blendEquation(GLenum mode)
4322{
4323 mGLState.setBlendEquation(mode, mode);
4324}
4325
Jamie Madillc20ab272016-06-09 07:20:46 -07004326void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
4327{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004328 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004329}
4330
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05004331void Context::blendFunc(GLenum sfactor, GLenum dfactor)
4332{
4333 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
4334}
4335
Jamie Madillc20ab272016-06-09 07:20:46 -07004336void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
4337{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004338 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004339}
4340
Jamie Madill876429b2017-04-20 15:46:24 -04004341void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07004342{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004343 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07004344}
4345
Jamie Madill876429b2017-04-20 15:46:24 -04004346void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07004347{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004348 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07004349}
4350
4351void Context::clearStencil(GLint s)
4352{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004353 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07004354}
4355
4356void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
4357{
Geoff Lang92019432017-11-20 13:09:34 -05004358 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
4359 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07004360}
4361
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004362void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07004363{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004364 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004365}
4366
4367void Context::depthFunc(GLenum func)
4368{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004369 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07004370}
4371
4372void Context::depthMask(GLboolean flag)
4373{
Geoff Lang92019432017-11-20 13:09:34 -05004374 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07004375}
4376
Jamie Madill876429b2017-04-20 15:46:24 -04004377void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07004378{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004379 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07004380}
4381
4382void Context::disable(GLenum cap)
4383{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004384 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07004385}
4386
4387void Context::disableVertexAttribArray(GLuint index)
4388{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004389 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07004390}
4391
4392void Context::enable(GLenum cap)
4393{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004394 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07004395}
4396
4397void Context::enableVertexAttribArray(GLuint index)
4398{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004399 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07004400}
4401
4402void Context::frontFace(GLenum mode)
4403{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004404 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004405}
4406
4407void Context::hint(GLenum target, GLenum mode)
4408{
4409 switch (target)
4410 {
4411 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004412 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004413 break;
4414
4415 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004416 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07004417 break;
4418
4419 default:
4420 UNREACHABLE();
4421 return;
4422 }
4423}
4424
4425void Context::lineWidth(GLfloat width)
4426{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004427 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07004428}
4429
4430void Context::pixelStorei(GLenum pname, GLint param)
4431{
4432 switch (pname)
4433 {
4434 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004435 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004436 break;
4437
4438 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004439 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004440 break;
4441
4442 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004443 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07004444 break;
4445
4446 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004447 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004448 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004449 break;
4450
4451 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03004452 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004453 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004454 break;
4455
4456 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03004457 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004458 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004459 break;
4460
4461 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004462 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004463 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004464 break;
4465
4466 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004467 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004468 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004469 break;
4470
4471 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03004472 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004473 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004474 break;
4475
4476 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03004477 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004478 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004479 break;
4480
4481 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03004482 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004483 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07004484 break;
4485
4486 default:
4487 UNREACHABLE();
4488 return;
4489 }
4490}
4491
4492void Context::polygonOffset(GLfloat factor, GLfloat units)
4493{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004494 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07004495}
4496
Jamie Madill876429b2017-04-20 15:46:24 -04004497void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07004498{
Geoff Lang92019432017-11-20 13:09:34 -05004499 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07004500}
4501
Jiawei Shaodb342272017-09-27 10:21:45 +08004502void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
4503{
4504 mGLState.setSampleMaskParams(maskNumber, mask);
4505}
4506
Jamie Madillc20ab272016-06-09 07:20:46 -07004507void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
4508{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004509 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004510}
4511
4512void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
4513{
4514 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4515 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004516 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004517 }
4518
4519 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
4520 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004521 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004522 }
4523}
4524
4525void Context::stencilMaskSeparate(GLenum face, GLuint mask)
4526{
4527 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4528 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004529 mGLState.setStencilWritemask(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.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07004535 }
4536}
4537
4538void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
4539{
4540 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
4541 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004542 mGLState.setStencilOperations(fail, zfail, zpass);
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.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07004548 }
4549}
4550
4551void Context::vertexAttrib1f(GLuint index, GLfloat x)
4552{
4553 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004554 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004555}
4556
4557void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
4558{
4559 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004560 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004561}
4562
4563void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
4564{
4565 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004566 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004567}
4568
4569void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
4570{
4571 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004572 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004573}
4574
4575void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
4576{
4577 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004578 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004579}
4580
4581void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
4582{
4583 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004584 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004585}
4586
4587void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4588{
4589 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004590 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004591}
4592
4593void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
4594{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004595 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07004596}
4597
4598void Context::vertexAttribPointer(GLuint index,
4599 GLint size,
4600 GLenum type,
4601 GLboolean normalized,
4602 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004603 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07004604{
Corentin Wallez336129f2017-10-17 15:55:40 -04004605 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05004606 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc20ab272016-06-09 07:20:46 -07004607}
4608
Shao80957d92017-02-20 21:25:59 +08004609void Context::vertexAttribFormat(GLuint attribIndex,
4610 GLint size,
4611 GLenum type,
4612 GLboolean normalized,
4613 GLuint relativeOffset)
4614{
Geoff Lang92019432017-11-20 13:09:34 -05004615 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08004616 relativeOffset);
4617}
4618
4619void Context::vertexAttribIFormat(GLuint attribIndex,
4620 GLint size,
4621 GLenum type,
4622 GLuint relativeOffset)
4623{
4624 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
4625}
4626
4627void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4628{
Shaodde78e82017-05-22 14:13:27 +08004629 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Shao80957d92017-02-20 21:25:59 +08004630}
4631
Jiajia Qin5451d532017-11-16 17:16:34 +08004632void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004633{
4634 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
4635}
4636
Jamie Madillc20ab272016-06-09 07:20:46 -07004637void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4638{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004639 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004640}
4641
4642void Context::vertexAttribIPointer(GLuint index,
4643 GLint size,
4644 GLenum type,
4645 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004646 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004647{
Corentin Wallez336129f2017-10-17 15:55:40 -04004648 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
4649 size, type, false, true, stride, pointer);
Jamie Madillc20ab272016-06-09 07:20:46 -07004650}
4651
4652void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4653{
4654 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004655 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004656}
4657
4658void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4659{
4660 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004661 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004662}
4663
4664void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4665{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004666 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004667}
4668
4669void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4670{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004671 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004672}
4673
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004674void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4675{
4676 const VertexAttribCurrentValueData &currentValues =
4677 getGLState().getVertexAttribCurrentValue(index);
4678 const VertexArray *vao = getGLState().getVertexArray();
4679 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4680 currentValues, pname, params);
4681}
4682
Brandon Jones59770802018-04-02 13:18:42 -07004683void Context::getVertexAttribivRobust(GLuint index,
4684 GLenum pname,
4685 GLsizei bufSize,
4686 GLsizei *length,
4687 GLint *params)
4688{
4689 getVertexAttribiv(index, pname, params);
4690}
4691
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004692void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4693{
4694 const VertexAttribCurrentValueData &currentValues =
4695 getGLState().getVertexAttribCurrentValue(index);
4696 const VertexArray *vao = getGLState().getVertexArray();
4697 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4698 currentValues, pname, params);
4699}
4700
Brandon Jones59770802018-04-02 13:18:42 -07004701void Context::getVertexAttribfvRobust(GLuint index,
4702 GLenum pname,
4703 GLsizei bufSize,
4704 GLsizei *length,
4705 GLfloat *params)
4706{
4707 getVertexAttribfv(index, pname, params);
4708}
4709
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004710void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4711{
4712 const VertexAttribCurrentValueData &currentValues =
4713 getGLState().getVertexAttribCurrentValue(index);
4714 const VertexArray *vao = getGLState().getVertexArray();
4715 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4716 currentValues, pname, params);
4717}
4718
Brandon Jones59770802018-04-02 13:18:42 -07004719void Context::getVertexAttribIivRobust(GLuint index,
4720 GLenum pname,
4721 GLsizei bufSize,
4722 GLsizei *length,
4723 GLint *params)
4724{
4725 getVertexAttribIiv(index, pname, params);
4726}
4727
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004728void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4729{
4730 const VertexAttribCurrentValueData &currentValues =
4731 getGLState().getVertexAttribCurrentValue(index);
4732 const VertexArray *vao = getGLState().getVertexArray();
4733 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4734 currentValues, pname, params);
4735}
4736
Brandon Jones59770802018-04-02 13:18:42 -07004737void Context::getVertexAttribIuivRobust(GLuint index,
4738 GLenum pname,
4739 GLsizei bufSize,
4740 GLsizei *length,
4741 GLuint *params)
4742{
4743 getVertexAttribIuiv(index, pname, params);
4744}
4745
Jamie Madill876429b2017-04-20 15:46:24 -04004746void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004747{
4748 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
4749 QueryVertexAttribPointerv(attrib, pname, pointer);
4750}
4751
Brandon Jones59770802018-04-02 13:18:42 -07004752void Context::getVertexAttribPointervRobust(GLuint index,
4753 GLenum pname,
4754 GLsizei bufSize,
4755 GLsizei *length,
4756 void **pointer)
4757{
4758 getVertexAttribPointerv(index, pname, pointer);
4759}
4760
Jamie Madillc20ab272016-06-09 07:20:46 -07004761void Context::debugMessageControl(GLenum source,
4762 GLenum type,
4763 GLenum severity,
4764 GLsizei count,
4765 const GLuint *ids,
4766 GLboolean enabled)
4767{
4768 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004769 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05004770 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004771}
4772
4773void Context::debugMessageInsert(GLenum source,
4774 GLenum type,
4775 GLuint id,
4776 GLenum severity,
4777 GLsizei length,
4778 const GLchar *buf)
4779{
4780 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004781 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004782}
4783
4784void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4785{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004786 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004787}
4788
4789GLuint Context::getDebugMessageLog(GLuint count,
4790 GLsizei bufSize,
4791 GLenum *sources,
4792 GLenum *types,
4793 GLuint *ids,
4794 GLenum *severities,
4795 GLsizei *lengths,
4796 GLchar *messageLog)
4797{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004798 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4799 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004800}
4801
4802void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4803{
4804 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004805 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05004806 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07004807}
4808
4809void Context::popDebugGroup()
4810{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004811 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05004812 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004813}
4814
Corentin Wallez336129f2017-10-17 15:55:40 -04004815void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004816{
4817 Buffer *buffer = mGLState.getTargetBuffer(target);
4818 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004819 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004820}
4821
Corentin Wallez336129f2017-10-17 15:55:40 -04004822void Context::bufferSubData(BufferBinding target,
4823 GLintptr offset,
4824 GLsizeiptr size,
4825 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004826{
4827 if (data == nullptr)
4828 {
4829 return;
4830 }
4831
4832 Buffer *buffer = mGLState.getTargetBuffer(target);
4833 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004834 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004835}
4836
Jamie Madillef300b12016-10-07 15:12:09 -04004837void Context::attachShader(GLuint program, GLuint shader)
4838{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05004839 Program *programObject = mState.mShaderPrograms->getProgram(program);
4840 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004841 ASSERT(programObject && shaderObject);
4842 programObject->attachShader(shaderObject);
4843}
4844
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004845const Workarounds &Context::getWorkarounds() const
4846{
4847 return mWorkarounds;
4848}
4849
Corentin Wallez336129f2017-10-17 15:55:40 -04004850void Context::copyBufferSubData(BufferBinding readTarget,
4851 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04004852 GLintptr readOffset,
4853 GLintptr writeOffset,
4854 GLsizeiptr size)
4855{
4856 // if size is zero, the copy is a successful no-op
4857 if (size == 0)
4858 {
4859 return;
4860 }
4861
4862 // TODO(jmadill): cache these.
4863 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4864 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4865
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004866 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004867}
4868
Jamie Madill01a80ee2016-11-07 12:06:18 -05004869void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4870{
4871 Program *programObject = getProgram(program);
4872 // TODO(jmadill): Re-use this from the validation if possible.
4873 ASSERT(programObject);
4874 programObject->bindAttributeLocation(index, name);
4875}
4876
Corentin Wallez336129f2017-10-17 15:55:40 -04004877void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004878{
Corentin Wallez336129f2017-10-17 15:55:40 -04004879 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4880 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004881}
4882
Corentin Wallez336129f2017-10-17 15:55:40 -04004883void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08004884{
4885 bindBufferRange(target, index, buffer, 0, 0);
4886}
4887
Corentin Wallez336129f2017-10-17 15:55:40 -04004888void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08004889 GLuint index,
4890 GLuint buffer,
4891 GLintptr offset,
4892 GLsizeiptr size)
4893{
Corentin Wallez336129f2017-10-17 15:55:40 -04004894 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4895 mGLState.setIndexedBufferBinding(this, target, index, bufferObject, offset, size);
Jiajia Qin6eafb042016-12-27 17:04:07 +08004896}
4897
Jamie Madill01a80ee2016-11-07 12:06:18 -05004898void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
4899{
4900 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4901 {
4902 bindReadFramebuffer(framebuffer);
4903 }
4904
4905 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4906 {
4907 bindDrawFramebuffer(framebuffer);
4908 }
4909}
4910
4911void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4912{
4913 ASSERT(target == GL_RENDERBUFFER);
4914 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004915 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04004916 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004917}
4918
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004919void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08004920 GLsizei samples,
4921 GLenum internalformat,
4922 GLsizei width,
4923 GLsizei height,
4924 GLboolean fixedsamplelocations)
4925{
4926 Extents size(width, height, 1);
4927 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004928 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
4929 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004930}
4931
4932void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4933{
JiangYizhou5b03f472017-01-09 10:22:53 +08004934 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
4935 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillbc918e72018-03-08 09:47:21 -05004936 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
JiangYizhou5b03f472017-01-09 10:22:53 +08004937 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08004938
4939 switch (pname)
4940 {
4941 case GL_SAMPLE_POSITION:
Geoff Lang13455072018-05-09 11:24:43 -04004942 handleError(framebuffer->getSamplePosition(this, index, val));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004943 break;
4944 default:
4945 UNREACHABLE();
4946 }
4947}
4948
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07004949void Context::getMultisamplefvRobust(GLenum pname,
4950 GLuint index,
4951 GLsizei bufSize,
4952 GLsizei *length,
4953 GLfloat *val)
4954{
4955 UNIMPLEMENTED();
4956}
4957
Jamie Madille8fb6402017-02-14 17:56:40 -05004958void Context::renderbufferStorage(GLenum target,
4959 GLenum internalformat,
4960 GLsizei width,
4961 GLsizei height)
4962{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004963 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4964 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
4965
Jamie Madille8fb6402017-02-14 17:56:40 -05004966 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04004967 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004968}
4969
4970void Context::renderbufferStorageMultisample(GLenum target,
4971 GLsizei samples,
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);
Jamie Madille8fb6402017-02-14 17:56:40 -05004978
4979 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004980 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04004981 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004982}
4983
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004984void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
4985{
Jamie Madill70b5bb02017-08-28 13:32:37 -04004986 const Sync *syncObject = getSync(sync);
Geoff Lang82483b92017-04-11 15:33:00 -04004987 handleError(QuerySynciv(syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004988}
4989
JiangYizhoue18e6392017-02-20 10:32:23 +08004990void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
4991{
4992 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4993 QueryFramebufferParameteriv(framebuffer, pname, params);
4994}
4995
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07004996void Context::getFramebufferParameterivRobust(GLenum target,
4997 GLenum pname,
4998 GLsizei bufSize,
4999 GLsizei *length,
5000 GLint *params)
5001{
5002 UNIMPLEMENTED();
5003}
5004
Jiajia Qin5451d532017-11-16 17:16:34 +08005005void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08005006{
5007 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5008 SetFramebufferParameteri(framebuffer, pname, param);
5009}
5010
Jamie Madilldec86232018-07-11 09:01:18 -04005011bool Context::getScratchBuffer(size_t requstedSizeBytes,
5012 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05005013{
Jamie Madilldec86232018-07-11 09:01:18 -04005014 return mScratchBuffer.get(requstedSizeBytes, scratchBufferOut);
Jamie Madillb3f26b92017-07-19 15:07:41 -04005015}
5016
Jamie Madilldec86232018-07-11 09:01:18 -04005017bool Context::getZeroFilledBuffer(size_t requstedSizeBytes,
5018 angle::MemoryBuffer **zeroBufferOut) const
Jamie Madillb3f26b92017-07-19 15:07:41 -04005019{
Jamie Madilldec86232018-07-11 09:01:18 -04005020 return mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0);
Jamie Madille14951e2017-03-09 18:55:16 -05005021}
5022
Xinghua Cao10a4d432017-11-28 14:46:26 +08005023Error Context::prepareForDispatch()
5024{
Geoff Langa8cb2872018-03-09 16:09:40 -05005025 ANGLE_TRY(syncState(mComputeDirtyBits, mComputeDirtyObjects));
Xinghua Cao10a4d432017-11-28 14:46:26 +08005026
5027 if (isRobustResourceInitEnabled())
5028 {
5029 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
5030 }
5031
5032 return NoError();
5033}
5034
Xinghua Cao2b396592017-03-29 15:36:04 +08005035void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
5036{
5037 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
5038 {
5039 return;
5040 }
5041
Xinghua Cao10a4d432017-11-28 14:46:26 +08005042 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill71c88b32017-09-14 22:20:29 -04005043 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08005044}
5045
Jiajia Qin5451d532017-11-16 17:16:34 +08005046void Context::dispatchComputeIndirect(GLintptr indirect)
5047{
Qin Jiajia62fcf622017-11-30 16:16:12 +08005048 ANGLE_CONTEXT_TRY(prepareForDispatch());
5049 handleError(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08005050}
5051
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005052void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005053 GLsizei levels,
5054 GLenum internalFormat,
5055 GLsizei width,
5056 GLsizei height)
5057{
5058 Extents size(width, height, 1);
5059 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005060 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005061}
5062
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005063void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08005064 GLsizei levels,
5065 GLenum internalFormat,
5066 GLsizei width,
5067 GLsizei height,
5068 GLsizei depth)
5069{
5070 Extents size(width, height, depth);
5071 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005072 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08005073}
5074
Jiajia Qin5451d532017-11-16 17:16:34 +08005075void Context::memoryBarrier(GLbitfield barriers)
5076{
Xinghua Cao89c422a2017-11-29 18:24:20 +08005077 handleError(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005078}
5079
5080void Context::memoryBarrierByRegion(GLbitfield barriers)
5081{
Xinghua Cao89c422a2017-11-29 18:24:20 +08005082 handleError(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08005083}
5084
Jamie Madillc1d770e2017-04-13 17:31:24 -04005085GLenum Context::checkFramebufferStatus(GLenum target)
5086{
5087 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
5088 ASSERT(framebuffer);
Jamie Madill427064d2018-04-13 16:20:34 -04005089 return framebuffer->checkStatus(this);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005090}
5091
5092void Context::compileShader(GLuint shader)
5093{
5094 Shader *shaderObject = GetValidShader(this, shader);
5095 if (!shaderObject)
5096 {
5097 return;
5098 }
5099 shaderObject->compile(this);
5100}
5101
5102void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
5103{
5104 for (int i = 0; i < n; i++)
5105 {
5106 deleteBuffer(buffers[i]);
5107 }
5108}
5109
5110void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
5111{
5112 for (int i = 0; i < n; i++)
5113 {
5114 if (framebuffers[i] != 0)
5115 {
5116 deleteFramebuffer(framebuffers[i]);
5117 }
5118 }
5119}
5120
5121void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
5122{
5123 for (int i = 0; i < n; i++)
5124 {
5125 deleteRenderbuffer(renderbuffers[i]);
5126 }
5127}
5128
5129void Context::deleteTextures(GLsizei n, const GLuint *textures)
5130{
5131 for (int i = 0; i < n; i++)
5132 {
5133 if (textures[i] != 0)
5134 {
5135 deleteTexture(textures[i]);
5136 }
5137 }
5138}
5139
5140void Context::detachShader(GLuint program, GLuint shader)
5141{
5142 Program *programObject = getProgram(program);
5143 ASSERT(programObject);
5144
5145 Shader *shaderObject = getShader(shader);
5146 ASSERT(shaderObject);
5147
5148 programObject->detachShader(this, shaderObject);
5149}
5150
5151void Context::genBuffers(GLsizei n, GLuint *buffers)
5152{
5153 for (int i = 0; i < n; i++)
5154 {
5155 buffers[i] = createBuffer();
5156 }
5157}
5158
5159void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
5160{
5161 for (int i = 0; i < n; i++)
5162 {
5163 framebuffers[i] = createFramebuffer();
5164 }
5165}
5166
5167void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
5168{
5169 for (int i = 0; i < n; i++)
5170 {
5171 renderbuffers[i] = createRenderbuffer();
5172 }
5173}
5174
5175void Context::genTextures(GLsizei n, GLuint *textures)
5176{
5177 for (int i = 0; i < n; i++)
5178 {
5179 textures[i] = createTexture();
5180 }
5181}
5182
5183void Context::getActiveAttrib(GLuint program,
5184 GLuint index,
5185 GLsizei bufsize,
5186 GLsizei *length,
5187 GLint *size,
5188 GLenum *type,
5189 GLchar *name)
5190{
5191 Program *programObject = getProgram(program);
5192 ASSERT(programObject);
5193 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
5194}
5195
5196void Context::getActiveUniform(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->getActiveUniform(index, bufsize, length, size, type, name);
5207}
5208
5209void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
5210{
5211 Program *programObject = getProgram(program);
5212 ASSERT(programObject);
5213 programObject->getAttachedShaders(maxcount, count, shaders);
5214}
5215
5216GLint Context::getAttribLocation(GLuint program, const GLchar *name)
5217{
5218 Program *programObject = getProgram(program);
5219 ASSERT(programObject);
5220 return programObject->getAttributeLocation(name);
5221}
5222
5223void Context::getBooleanv(GLenum pname, GLboolean *params)
5224{
5225 GLenum nativeType;
5226 unsigned int numParams = 0;
5227 getQueryParameterInfo(pname, &nativeType, &numParams);
5228
5229 if (nativeType == GL_BOOL)
5230 {
5231 getBooleanvImpl(pname, params);
5232 }
5233 else
5234 {
5235 CastStateValues(this, nativeType, pname, numParams, params);
5236 }
5237}
5238
Brandon Jones59770802018-04-02 13:18:42 -07005239void Context::getBooleanvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLboolean *params)
5240{
5241 getBooleanv(pname, params);
5242}
5243
Jamie Madillc1d770e2017-04-13 17:31:24 -04005244void Context::getFloatv(GLenum pname, GLfloat *params)
5245{
5246 GLenum nativeType;
5247 unsigned int numParams = 0;
5248 getQueryParameterInfo(pname, &nativeType, &numParams);
5249
5250 if (nativeType == GL_FLOAT)
5251 {
5252 getFloatvImpl(pname, params);
5253 }
5254 else
5255 {
5256 CastStateValues(this, nativeType, pname, numParams, params);
5257 }
5258}
5259
Brandon Jones59770802018-04-02 13:18:42 -07005260void Context::getFloatvRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLfloat *params)
5261{
5262 getFloatv(pname, params);
5263}
5264
Jamie Madillc1d770e2017-04-13 17:31:24 -04005265void Context::getIntegerv(GLenum pname, GLint *params)
5266{
5267 GLenum nativeType;
5268 unsigned int numParams = 0;
5269 getQueryParameterInfo(pname, &nativeType, &numParams);
5270
5271 if (nativeType == GL_INT)
5272 {
5273 getIntegervImpl(pname, params);
5274 }
5275 else
5276 {
5277 CastStateValues(this, nativeType, pname, numParams, params);
5278 }
5279}
5280
Brandon Jones59770802018-04-02 13:18:42 -07005281void Context::getIntegervRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint *data)
5282{
5283 getIntegerv(pname, data);
5284}
5285
Jamie Madillc1d770e2017-04-13 17:31:24 -04005286void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
5287{
5288 Program *programObject = getProgram(program);
5289 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04005290 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005291}
5292
Brandon Jones59770802018-04-02 13:18:42 -07005293void Context::getProgramivRobust(GLuint program,
5294 GLenum pname,
5295 GLsizei bufSize,
5296 GLsizei *length,
5297 GLint *params)
5298{
5299 getProgramiv(program, pname, params);
5300}
5301
Jiajia Qin5451d532017-11-16 17:16:34 +08005302void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
5303{
5304 UNIMPLEMENTED();
5305}
5306
Jamie Madillbe849e42017-05-02 15:49:00 -04005307void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04005308{
5309 Program *programObject = getProgram(program);
5310 ASSERT(programObject);
5311 programObject->getInfoLog(bufsize, length, infolog);
5312}
5313
Jiajia Qin5451d532017-11-16 17:16:34 +08005314void Context::getProgramPipelineInfoLog(GLuint pipeline,
5315 GLsizei bufSize,
5316 GLsizei *length,
5317 GLchar *infoLog)
5318{
5319 UNIMPLEMENTED();
5320}
5321
Jamie Madillc1d770e2017-04-13 17:31:24 -04005322void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
5323{
5324 Shader *shaderObject = getShader(shader);
5325 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04005326 QueryShaderiv(this, shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005327}
5328
Brandon Jones59770802018-04-02 13:18:42 -07005329void Context::getShaderivRobust(GLuint shader,
5330 GLenum pname,
5331 GLsizei bufSize,
5332 GLsizei *length,
5333 GLint *params)
5334{
5335 getShaderiv(shader, pname, params);
5336}
5337
Jamie Madillc1d770e2017-04-13 17:31:24 -04005338void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
5339{
5340 Shader *shaderObject = getShader(shader);
5341 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04005342 shaderObject->getInfoLog(this, bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005343}
5344
5345void Context::getShaderPrecisionFormat(GLenum shadertype,
5346 GLenum precisiontype,
5347 GLint *range,
5348 GLint *precision)
5349{
5350 // TODO(jmadill): Compute shaders.
5351
5352 switch (shadertype)
5353 {
5354 case GL_VERTEX_SHADER:
5355 switch (precisiontype)
5356 {
5357 case GL_LOW_FLOAT:
5358 mCaps.vertexLowpFloat.get(range, precision);
5359 break;
5360 case GL_MEDIUM_FLOAT:
5361 mCaps.vertexMediumpFloat.get(range, precision);
5362 break;
5363 case GL_HIGH_FLOAT:
5364 mCaps.vertexHighpFloat.get(range, precision);
5365 break;
5366
5367 case GL_LOW_INT:
5368 mCaps.vertexLowpInt.get(range, precision);
5369 break;
5370 case GL_MEDIUM_INT:
5371 mCaps.vertexMediumpInt.get(range, precision);
5372 break;
5373 case GL_HIGH_INT:
5374 mCaps.vertexHighpInt.get(range, precision);
5375 break;
5376
5377 default:
5378 UNREACHABLE();
5379 return;
5380 }
5381 break;
5382
5383 case GL_FRAGMENT_SHADER:
5384 switch (precisiontype)
5385 {
5386 case GL_LOW_FLOAT:
5387 mCaps.fragmentLowpFloat.get(range, precision);
5388 break;
5389 case GL_MEDIUM_FLOAT:
5390 mCaps.fragmentMediumpFloat.get(range, precision);
5391 break;
5392 case GL_HIGH_FLOAT:
5393 mCaps.fragmentHighpFloat.get(range, precision);
5394 break;
5395
5396 case GL_LOW_INT:
5397 mCaps.fragmentLowpInt.get(range, precision);
5398 break;
5399 case GL_MEDIUM_INT:
5400 mCaps.fragmentMediumpInt.get(range, precision);
5401 break;
5402 case GL_HIGH_INT:
5403 mCaps.fragmentHighpInt.get(range, precision);
5404 break;
5405
5406 default:
5407 UNREACHABLE();
5408 return;
5409 }
5410 break;
5411
5412 default:
5413 UNREACHABLE();
5414 return;
5415 }
5416}
5417
5418void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
5419{
5420 Shader *shaderObject = getShader(shader);
5421 ASSERT(shaderObject);
5422 shaderObject->getSource(bufsize, length, source);
5423}
5424
5425void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
5426{
5427 Program *programObject = getProgram(program);
5428 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005429 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005430}
5431
Brandon Jones59770802018-04-02 13:18:42 -07005432void Context::getUniformfvRobust(GLuint program,
5433 GLint location,
5434 GLsizei bufSize,
5435 GLsizei *length,
5436 GLfloat *params)
5437{
5438 getUniformfv(program, location, params);
5439}
5440
Jamie Madillc1d770e2017-04-13 17:31:24 -04005441void Context::getUniformiv(GLuint program, GLint location, GLint *params)
5442{
5443 Program *programObject = getProgram(program);
5444 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04005445 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005446}
5447
Brandon Jones59770802018-04-02 13:18:42 -07005448void Context::getUniformivRobust(GLuint program,
5449 GLint location,
5450 GLsizei bufSize,
5451 GLsizei *length,
5452 GLint *params)
5453{
5454 getUniformiv(program, location, params);
5455}
5456
Jamie Madillc1d770e2017-04-13 17:31:24 -04005457GLint Context::getUniformLocation(GLuint program, const GLchar *name)
5458{
5459 Program *programObject = getProgram(program);
5460 ASSERT(programObject);
5461 return programObject->getUniformLocation(name);
5462}
5463
5464GLboolean Context::isBuffer(GLuint buffer)
5465{
5466 if (buffer == 0)
5467 {
5468 return GL_FALSE;
5469 }
5470
5471 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
5472}
5473
5474GLboolean Context::isEnabled(GLenum cap)
5475{
5476 return mGLState.getEnableFeature(cap);
5477}
5478
5479GLboolean Context::isFramebuffer(GLuint framebuffer)
5480{
5481 if (framebuffer == 0)
5482 {
5483 return GL_FALSE;
5484 }
5485
5486 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
5487}
5488
5489GLboolean Context::isProgram(GLuint program)
5490{
5491 if (program == 0)
5492 {
5493 return GL_FALSE;
5494 }
5495
5496 return (getProgram(program) ? GL_TRUE : GL_FALSE);
5497}
5498
5499GLboolean Context::isRenderbuffer(GLuint renderbuffer)
5500{
5501 if (renderbuffer == 0)
5502 {
5503 return GL_FALSE;
5504 }
5505
5506 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
5507}
5508
5509GLboolean Context::isShader(GLuint shader)
5510{
5511 if (shader == 0)
5512 {
5513 return GL_FALSE;
5514 }
5515
5516 return (getShader(shader) ? GL_TRUE : GL_FALSE);
5517}
5518
5519GLboolean Context::isTexture(GLuint texture)
5520{
5521 if (texture == 0)
5522 {
5523 return GL_FALSE;
5524 }
5525
5526 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
5527}
5528
5529void Context::linkProgram(GLuint program)
5530{
5531 Program *programObject = getProgram(program);
5532 ASSERT(programObject);
5533 handleError(programObject->link(this));
Martin Radev0abb7a22017-08-28 15:34:45 +03005534 mGLState.onProgramExecutableChange(programObject);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005535}
5536
5537void Context::releaseShaderCompiler()
5538{
Jamie Madill4928b7c2017-06-20 12:57:39 -04005539 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04005540}
5541
5542void Context::shaderBinary(GLsizei n,
5543 const GLuint *shaders,
5544 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04005545 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04005546 GLsizei length)
5547{
5548 // No binary shader formats are supported.
5549 UNIMPLEMENTED();
5550}
5551
5552void Context::shaderSource(GLuint shader,
5553 GLsizei count,
5554 const GLchar *const *string,
5555 const GLint *length)
5556{
5557 Shader *shaderObject = getShader(shader);
5558 ASSERT(shaderObject);
5559 shaderObject->setSource(count, string, length);
5560}
5561
5562void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
5563{
5564 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
5565}
5566
5567void Context::stencilMask(GLuint mask)
5568{
5569 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
5570}
5571
5572void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
5573{
5574 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
5575}
5576
5577void Context::uniform1f(GLint location, GLfloat x)
5578{
5579 Program *program = mGLState.getProgram();
5580 program->setUniform1fv(location, 1, &x);
5581}
5582
5583void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
5584{
5585 Program *program = mGLState.getProgram();
5586 program->setUniform1fv(location, count, v);
5587}
5588
5589void Context::uniform1i(GLint location, GLint x)
5590{
5591 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04005592 if (program->setUniform1iv(location, 1, &x) == Program::SetUniformResult::SamplerChanged)
5593 {
5594 mGLState.setObjectDirty(GL_PROGRAM);
5595 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005596}
5597
5598void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
5599{
5600 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04005601 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
5602 {
5603 mGLState.setObjectDirty(GL_PROGRAM);
5604 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04005605}
5606
5607void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
5608{
5609 GLfloat xy[2] = {x, y};
5610 Program *program = mGLState.getProgram();
5611 program->setUniform2fv(location, 1, xy);
5612}
5613
5614void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
5615{
5616 Program *program = mGLState.getProgram();
5617 program->setUniform2fv(location, count, v);
5618}
5619
5620void Context::uniform2i(GLint location, GLint x, GLint y)
5621{
5622 GLint xy[2] = {x, y};
5623 Program *program = mGLState.getProgram();
5624 program->setUniform2iv(location, 1, xy);
5625}
5626
5627void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
5628{
5629 Program *program = mGLState.getProgram();
5630 program->setUniform2iv(location, count, v);
5631}
5632
5633void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
5634{
5635 GLfloat xyz[3] = {x, y, z};
5636 Program *program = mGLState.getProgram();
5637 program->setUniform3fv(location, 1, xyz);
5638}
5639
5640void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
5641{
5642 Program *program = mGLState.getProgram();
5643 program->setUniform3fv(location, count, v);
5644}
5645
5646void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
5647{
5648 GLint xyz[3] = {x, y, z};
5649 Program *program = mGLState.getProgram();
5650 program->setUniform3iv(location, 1, xyz);
5651}
5652
5653void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
5654{
5655 Program *program = mGLState.getProgram();
5656 program->setUniform3iv(location, count, v);
5657}
5658
5659void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
5660{
5661 GLfloat xyzw[4] = {x, y, z, w};
5662 Program *program = mGLState.getProgram();
5663 program->setUniform4fv(location, 1, xyzw);
5664}
5665
5666void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
5667{
5668 Program *program = mGLState.getProgram();
5669 program->setUniform4fv(location, count, v);
5670}
5671
5672void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
5673{
5674 GLint xyzw[4] = {x, y, z, w};
5675 Program *program = mGLState.getProgram();
5676 program->setUniform4iv(location, 1, xyzw);
5677}
5678
5679void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
5680{
5681 Program *program = mGLState.getProgram();
5682 program->setUniform4iv(location, count, v);
5683}
5684
5685void Context::uniformMatrix2fv(GLint location,
5686 GLsizei count,
5687 GLboolean transpose,
5688 const GLfloat *value)
5689{
5690 Program *program = mGLState.getProgram();
5691 program->setUniformMatrix2fv(location, count, transpose, value);
5692}
5693
5694void Context::uniformMatrix3fv(GLint location,
5695 GLsizei count,
5696 GLboolean transpose,
5697 const GLfloat *value)
5698{
5699 Program *program = mGLState.getProgram();
5700 program->setUniformMatrix3fv(location, count, transpose, value);
5701}
5702
5703void Context::uniformMatrix4fv(GLint location,
5704 GLsizei count,
5705 GLboolean transpose,
5706 const GLfloat *value)
5707{
5708 Program *program = mGLState.getProgram();
5709 program->setUniformMatrix4fv(location, count, transpose, value);
5710}
5711
5712void Context::validateProgram(GLuint program)
5713{
5714 Program *programObject = getProgram(program);
5715 ASSERT(programObject);
5716 programObject->validate(mCaps);
5717}
5718
Jiajia Qin5451d532017-11-16 17:16:34 +08005719void Context::validateProgramPipeline(GLuint pipeline)
5720{
5721 UNIMPLEMENTED();
5722}
5723
Jamie Madilld04908b2017-06-09 14:15:35 -04005724void Context::getProgramBinary(GLuint program,
5725 GLsizei bufSize,
5726 GLsizei *length,
5727 GLenum *binaryFormat,
5728 void *binary)
5729{
5730 Program *programObject = getProgram(program);
5731 ASSERT(programObject != nullptr);
5732
5733 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
5734}
5735
5736void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
5737{
5738 Program *programObject = getProgram(program);
5739 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04005740
Jamie Madilld04908b2017-06-09 14:15:35 -04005741 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
5742}
5743
Jamie Madillff325f12017-08-26 15:06:05 -04005744void Context::uniform1ui(GLint location, GLuint v0)
5745{
5746 Program *program = mGLState.getProgram();
5747 program->setUniform1uiv(location, 1, &v0);
5748}
5749
5750void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
5751{
5752 Program *program = mGLState.getProgram();
5753 const GLuint xy[] = {v0, v1};
5754 program->setUniform2uiv(location, 1, xy);
5755}
5756
5757void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
5758{
5759 Program *program = mGLState.getProgram();
5760 const GLuint xyz[] = {v0, v1, v2};
5761 program->setUniform3uiv(location, 1, xyz);
5762}
5763
5764void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
5765{
5766 Program *program = mGLState.getProgram();
5767 const GLuint xyzw[] = {v0, v1, v2, v3};
5768 program->setUniform4uiv(location, 1, xyzw);
5769}
5770
5771void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
5772{
5773 Program *program = mGLState.getProgram();
5774 program->setUniform1uiv(location, count, value);
5775}
5776void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
5777{
5778 Program *program = mGLState.getProgram();
5779 program->setUniform2uiv(location, count, value);
5780}
5781
5782void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
5783{
5784 Program *program = mGLState.getProgram();
5785 program->setUniform3uiv(location, count, value);
5786}
5787
5788void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
5789{
5790 Program *program = mGLState.getProgram();
5791 program->setUniform4uiv(location, count, value);
5792}
5793
Jamie Madillf0e04492017-08-26 15:28:42 -04005794void Context::genQueries(GLsizei n, GLuint *ids)
5795{
5796 for (GLsizei i = 0; i < n; i++)
5797 {
5798 GLuint handle = mQueryHandleAllocator.allocate();
5799 mQueryMap.assign(handle, nullptr);
5800 ids[i] = handle;
5801 }
5802}
5803
5804void Context::deleteQueries(GLsizei n, const GLuint *ids)
5805{
5806 for (int i = 0; i < n; i++)
5807 {
5808 GLuint query = ids[i];
5809
5810 Query *queryObject = nullptr;
5811 if (mQueryMap.erase(query, &queryObject))
5812 {
5813 mQueryHandleAllocator.release(query);
5814 if (queryObject)
5815 {
5816 queryObject->release(this);
5817 }
5818 }
5819 }
5820}
5821
5822GLboolean Context::isQuery(GLuint id)
5823{
Corentin Wallezad3ae902018-03-09 13:40:42 -05005824 return (getQuery(id, false, QueryType::InvalidEnum) != nullptr) ? GL_TRUE : GL_FALSE;
Jamie Madillf0e04492017-08-26 15:28:42 -04005825}
5826
Jamie Madillc8c95812017-08-26 18:40:09 -04005827void Context::uniformMatrix2x3fv(GLint location,
5828 GLsizei count,
5829 GLboolean transpose,
5830 const GLfloat *value)
5831{
5832 Program *program = mGLState.getProgram();
5833 program->setUniformMatrix2x3fv(location, count, transpose, value);
5834}
5835
5836void Context::uniformMatrix3x2fv(GLint location,
5837 GLsizei count,
5838 GLboolean transpose,
5839 const GLfloat *value)
5840{
5841 Program *program = mGLState.getProgram();
5842 program->setUniformMatrix3x2fv(location, count, transpose, value);
5843}
5844
5845void Context::uniformMatrix2x4fv(GLint location,
5846 GLsizei count,
5847 GLboolean transpose,
5848 const GLfloat *value)
5849{
5850 Program *program = mGLState.getProgram();
5851 program->setUniformMatrix2x4fv(location, count, transpose, value);
5852}
5853
5854void Context::uniformMatrix4x2fv(GLint location,
5855 GLsizei count,
5856 GLboolean transpose,
5857 const GLfloat *value)
5858{
5859 Program *program = mGLState.getProgram();
5860 program->setUniformMatrix4x2fv(location, count, transpose, value);
5861}
5862
5863void Context::uniformMatrix3x4fv(GLint location,
5864 GLsizei count,
5865 GLboolean transpose,
5866 const GLfloat *value)
5867{
5868 Program *program = mGLState.getProgram();
5869 program->setUniformMatrix3x4fv(location, count, transpose, value);
5870}
5871
5872void Context::uniformMatrix4x3fv(GLint location,
5873 GLsizei count,
5874 GLboolean transpose,
5875 const GLfloat *value)
5876{
5877 Program *program = mGLState.getProgram();
5878 program->setUniformMatrix4x3fv(location, count, transpose, value);
5879}
5880
Jamie Madilld7576732017-08-26 18:49:50 -04005881void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
5882{
5883 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5884 {
5885 GLuint vertexArray = arrays[arrayIndex];
5886
5887 if (arrays[arrayIndex] != 0)
5888 {
5889 VertexArray *vertexArrayObject = nullptr;
5890 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
5891 {
5892 if (vertexArrayObject != nullptr)
5893 {
5894 detachVertexArray(vertexArray);
5895 vertexArrayObject->onDestroy(this);
5896 }
5897
5898 mVertexArrayHandleAllocator.release(vertexArray);
5899 }
5900 }
5901 }
5902}
5903
5904void Context::genVertexArrays(GLsizei n, GLuint *arrays)
5905{
5906 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5907 {
5908 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
5909 mVertexArrayMap.assign(vertexArray, nullptr);
5910 arrays[arrayIndex] = vertexArray;
5911 }
5912}
5913
5914bool Context::isVertexArray(GLuint array)
5915{
5916 if (array == 0)
5917 {
5918 return GL_FALSE;
5919 }
5920
5921 VertexArray *vao = getVertexArray(array);
5922 return (vao != nullptr ? GL_TRUE : GL_FALSE);
5923}
5924
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04005925void Context::endTransformFeedback()
5926{
5927 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5928 transformFeedback->end(this);
5929}
5930
5931void Context::transformFeedbackVaryings(GLuint program,
5932 GLsizei count,
5933 const GLchar *const *varyings,
5934 GLenum bufferMode)
5935{
5936 Program *programObject = getProgram(program);
5937 ASSERT(programObject);
5938 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
5939}
5940
5941void Context::getTransformFeedbackVarying(GLuint program,
5942 GLuint index,
5943 GLsizei bufSize,
5944 GLsizei *length,
5945 GLsizei *size,
5946 GLenum *type,
5947 GLchar *name)
5948{
5949 Program *programObject = getProgram(program);
5950 ASSERT(programObject);
5951 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
5952}
5953
5954void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
5955{
5956 for (int i = 0; i < n; i++)
5957 {
5958 GLuint transformFeedback = ids[i];
5959 if (transformFeedback == 0)
5960 {
5961 continue;
5962 }
5963
5964 TransformFeedback *transformFeedbackObject = nullptr;
5965 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
5966 {
5967 if (transformFeedbackObject != nullptr)
5968 {
5969 detachTransformFeedback(transformFeedback);
5970 transformFeedbackObject->release(this);
5971 }
5972
5973 mTransformFeedbackHandleAllocator.release(transformFeedback);
5974 }
5975 }
5976}
5977
5978void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
5979{
5980 for (int i = 0; i < n; i++)
5981 {
5982 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
5983 mTransformFeedbackMap.assign(transformFeedback, nullptr);
5984 ids[i] = transformFeedback;
5985 }
5986}
5987
5988bool Context::isTransformFeedback(GLuint id)
5989{
5990 if (id == 0)
5991 {
5992 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
5993 // returns FALSE
5994 return GL_FALSE;
5995 }
5996
5997 const TransformFeedback *transformFeedback = getTransformFeedback(id);
5998 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
5999}
6000
6001void Context::pauseTransformFeedback()
6002{
6003 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6004 transformFeedback->pause();
6005}
6006
6007void Context::resumeTransformFeedback()
6008{
6009 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
6010 transformFeedback->resume();
6011}
6012
Jamie Madill12e957f2017-08-26 21:42:26 -04006013void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
6014{
6015 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04006016 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04006017}
6018
Brandon Jones59770802018-04-02 13:18:42 -07006019void Context::getUniformuivRobust(GLuint program,
6020 GLint location,
6021 GLsizei bufSize,
6022 GLsizei *length,
6023 GLuint *params)
6024{
6025 getUniformuiv(program, location, params);
6026}
6027
Jamie Madill12e957f2017-08-26 21:42:26 -04006028GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
6029{
6030 const Program *programObject = getProgram(program);
6031 return programObject->getFragDataLocation(name);
6032}
6033
6034void Context::getUniformIndices(GLuint program,
6035 GLsizei uniformCount,
6036 const GLchar *const *uniformNames,
6037 GLuint *uniformIndices)
6038{
6039 const Program *programObject = getProgram(program);
6040 if (!programObject->isLinked())
6041 {
6042 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6043 {
6044 uniformIndices[uniformId] = GL_INVALID_INDEX;
6045 }
6046 }
6047 else
6048 {
6049 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6050 {
6051 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
6052 }
6053 }
6054}
6055
6056void Context::getActiveUniformsiv(GLuint program,
6057 GLsizei uniformCount,
6058 const GLuint *uniformIndices,
6059 GLenum pname,
6060 GLint *params)
6061{
6062 const Program *programObject = getProgram(program);
6063 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
6064 {
6065 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08006066 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04006067 }
6068}
6069
6070GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
6071{
6072 const Program *programObject = getProgram(program);
6073 return programObject->getUniformBlockIndex(uniformBlockName);
6074}
6075
6076void Context::getActiveUniformBlockiv(GLuint program,
6077 GLuint uniformBlockIndex,
6078 GLenum pname,
6079 GLint *params)
6080{
6081 const Program *programObject = getProgram(program);
6082 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
6083}
6084
Brandon Jones59770802018-04-02 13:18:42 -07006085void Context::getActiveUniformBlockivRobust(GLuint program,
6086 GLuint uniformBlockIndex,
6087 GLenum pname,
6088 GLsizei bufSize,
6089 GLsizei *length,
6090 GLint *params)
6091{
6092 getActiveUniformBlockiv(program, uniformBlockIndex, pname, params);
6093}
6094
Jamie Madill12e957f2017-08-26 21:42:26 -04006095void Context::getActiveUniformBlockName(GLuint program,
6096 GLuint uniformBlockIndex,
6097 GLsizei bufSize,
6098 GLsizei *length,
6099 GLchar *uniformBlockName)
6100{
6101 const Program *programObject = getProgram(program);
6102 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
6103}
6104
6105void Context::uniformBlockBinding(GLuint program,
6106 GLuint uniformBlockIndex,
6107 GLuint uniformBlockBinding)
6108{
6109 Program *programObject = getProgram(program);
6110 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
6111}
6112
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006113GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
6114{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006115 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
6116 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006117
Jamie Madill70b5bb02017-08-28 13:32:37 -04006118 Sync *syncObject = getSync(syncHandle);
6119 Error error = syncObject->set(condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006120 if (error.isError())
6121 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04006122 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006123 handleError(error);
6124 return nullptr;
6125 }
6126
Jamie Madill70b5bb02017-08-28 13:32:37 -04006127 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006128}
6129
6130GLboolean Context::isSync(GLsync sync)
6131{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006132 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006133}
6134
6135GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6136{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006137 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006138
6139 GLenum result = GL_WAIT_FAILED;
6140 handleError(syncObject->clientWait(flags, timeout, &result));
6141 return result;
6142}
6143
6144void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
6145{
Jamie Madill70b5bb02017-08-28 13:32:37 -04006146 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04006147 handleError(syncObject->serverWait(flags, timeout));
6148}
6149
6150void Context::getInteger64v(GLenum pname, GLint64 *params)
6151{
6152 GLenum nativeType = GL_NONE;
6153 unsigned int numParams = 0;
6154 getQueryParameterInfo(pname, &nativeType, &numParams);
6155
6156 if (nativeType == GL_INT_64_ANGLEX)
6157 {
6158 getInteger64vImpl(pname, params);
6159 }
6160 else
6161 {
6162 CastStateValues(this, nativeType, pname, numParams, params);
6163 }
6164}
6165
Brandon Jones59770802018-04-02 13:18:42 -07006166void Context::getInteger64vRobust(GLenum pname, GLsizei bufSize, GLsizei *length, GLint64 *data)
6167{
6168 getInteger64v(pname, data);
6169}
6170
Corentin Wallez336129f2017-10-17 15:55:40 -04006171void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04006172{
6173 Buffer *buffer = mGLState.getTargetBuffer(target);
6174 QueryBufferParameteri64v(buffer, pname, params);
6175}
6176
Brandon Jones59770802018-04-02 13:18:42 -07006177void Context::getBufferParameteri64vRobust(BufferBinding target,
6178 GLenum pname,
6179 GLsizei bufSize,
6180 GLsizei *length,
6181 GLint64 *params)
6182{
6183 getBufferParameteri64v(target, pname, params);
6184}
6185
Jamie Madill3ef140a2017-08-26 23:11:21 -04006186void Context::genSamplers(GLsizei count, GLuint *samplers)
6187{
6188 for (int i = 0; i < count; i++)
6189 {
6190 samplers[i] = mState.mSamplers->createSampler();
6191 }
6192}
6193
6194void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
6195{
6196 for (int i = 0; i < count; i++)
6197 {
6198 GLuint sampler = samplers[i];
6199
6200 if (mState.mSamplers->getSampler(sampler))
6201 {
6202 detachSampler(sampler);
6203 }
6204
6205 mState.mSamplers->deleteObject(this, sampler);
6206 }
6207}
6208
6209void Context::getInternalformativ(GLenum target,
6210 GLenum internalformat,
6211 GLenum pname,
6212 GLsizei bufSize,
6213 GLint *params)
6214{
6215 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
6216 QueryInternalFormativ(formatCaps, pname, bufSize, params);
6217}
6218
Brandon Jones59770802018-04-02 13:18:42 -07006219void Context::getInternalformativRobust(GLenum target,
6220 GLenum internalformat,
6221 GLenum pname,
6222 GLsizei bufSize,
6223 GLsizei *length,
6224 GLint *params)
6225{
6226 getInternalformativ(target, internalformat, pname, bufSize, params);
6227}
6228
Jiajia Qin5451d532017-11-16 17:16:34 +08006229void Context::programUniform1i(GLuint program, GLint location, GLint v0)
6230{
6231 programUniform1iv(program, location, 1, &v0);
6232}
6233
6234void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
6235{
6236 GLint xy[2] = {v0, v1};
6237 programUniform2iv(program, location, 1, xy);
6238}
6239
6240void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
6241{
6242 GLint xyz[3] = {v0, v1, v2};
6243 programUniform3iv(program, location, 1, xyz);
6244}
6245
6246void Context::programUniform4i(GLuint program,
6247 GLint location,
6248 GLint v0,
6249 GLint v1,
6250 GLint v2,
6251 GLint v3)
6252{
6253 GLint xyzw[4] = {v0, v1, v2, v3};
6254 programUniform4iv(program, location, 1, xyzw);
6255}
6256
6257void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
6258{
6259 programUniform1uiv(program, location, 1, &v0);
6260}
6261
6262void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
6263{
6264 GLuint xy[2] = {v0, v1};
6265 programUniform2uiv(program, location, 1, xy);
6266}
6267
6268void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
6269{
6270 GLuint xyz[3] = {v0, v1, v2};
6271 programUniform3uiv(program, location, 1, xyz);
6272}
6273
6274void Context::programUniform4ui(GLuint program,
6275 GLint location,
6276 GLuint v0,
6277 GLuint v1,
6278 GLuint v2,
6279 GLuint v3)
6280{
6281 GLuint xyzw[4] = {v0, v1, v2, v3};
6282 programUniform4uiv(program, location, 1, xyzw);
6283}
6284
6285void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
6286{
6287 programUniform1fv(program, location, 1, &v0);
6288}
6289
6290void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
6291{
6292 GLfloat xy[2] = {v0, v1};
6293 programUniform2fv(program, location, 1, xy);
6294}
6295
6296void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
6297{
6298 GLfloat xyz[3] = {v0, v1, v2};
6299 programUniform3fv(program, location, 1, xyz);
6300}
6301
6302void Context::programUniform4f(GLuint program,
6303 GLint location,
6304 GLfloat v0,
6305 GLfloat v1,
6306 GLfloat v2,
6307 GLfloat v3)
6308{
6309 GLfloat xyzw[4] = {v0, v1, v2, v3};
6310 programUniform4fv(program, location, 1, xyzw);
6311}
6312
Jamie Madill81c2e252017-09-09 23:32:46 -04006313void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6314{
6315 Program *programObject = getProgram(program);
6316 ASSERT(programObject);
6317 if (programObject->setUniform1iv(location, count, value) ==
6318 Program::SetUniformResult::SamplerChanged)
6319 {
6320 mGLState.setObjectDirty(GL_PROGRAM);
6321 }
6322}
6323
Jiajia Qin5451d532017-11-16 17:16:34 +08006324void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6325{
6326 Program *programObject = getProgram(program);
6327 ASSERT(programObject);
6328 programObject->setUniform2iv(location, count, value);
6329}
6330
6331void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6332{
6333 Program *programObject = getProgram(program);
6334 ASSERT(programObject);
6335 programObject->setUniform3iv(location, count, value);
6336}
6337
6338void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
6339{
6340 Program *programObject = getProgram(program);
6341 ASSERT(programObject);
6342 programObject->setUniform4iv(location, count, value);
6343}
6344
6345void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6346{
6347 Program *programObject = getProgram(program);
6348 ASSERT(programObject);
6349 programObject->setUniform1uiv(location, count, value);
6350}
6351
6352void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6353{
6354 Program *programObject = getProgram(program);
6355 ASSERT(programObject);
6356 programObject->setUniform2uiv(location, count, value);
6357}
6358
6359void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6360{
6361 Program *programObject = getProgram(program);
6362 ASSERT(programObject);
6363 programObject->setUniform3uiv(location, count, value);
6364}
6365
6366void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
6367{
6368 Program *programObject = getProgram(program);
6369 ASSERT(programObject);
6370 programObject->setUniform4uiv(location, count, value);
6371}
6372
6373void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6374{
6375 Program *programObject = getProgram(program);
6376 ASSERT(programObject);
6377 programObject->setUniform1fv(location, count, value);
6378}
6379
6380void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6381{
6382 Program *programObject = getProgram(program);
6383 ASSERT(programObject);
6384 programObject->setUniform2fv(location, count, value);
6385}
6386
6387void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6388{
6389 Program *programObject = getProgram(program);
6390 ASSERT(programObject);
6391 programObject->setUniform3fv(location, count, value);
6392}
6393
6394void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
6395{
6396 Program *programObject = getProgram(program);
6397 ASSERT(programObject);
6398 programObject->setUniform4fv(location, count, value);
6399}
6400
6401void Context::programUniformMatrix2fv(GLuint program,
6402 GLint location,
6403 GLsizei count,
6404 GLboolean transpose,
6405 const GLfloat *value)
6406{
6407 Program *programObject = getProgram(program);
6408 ASSERT(programObject);
6409 programObject->setUniformMatrix2fv(location, count, transpose, value);
6410}
6411
6412void Context::programUniformMatrix3fv(GLuint program,
6413 GLint location,
6414 GLsizei count,
6415 GLboolean transpose,
6416 const GLfloat *value)
6417{
6418 Program *programObject = getProgram(program);
6419 ASSERT(programObject);
6420 programObject->setUniformMatrix3fv(location, count, transpose, value);
6421}
6422
6423void Context::programUniformMatrix4fv(GLuint program,
6424 GLint location,
6425 GLsizei count,
6426 GLboolean transpose,
6427 const GLfloat *value)
6428{
6429 Program *programObject = getProgram(program);
6430 ASSERT(programObject);
6431 programObject->setUniformMatrix4fv(location, count, transpose, value);
6432}
6433
6434void Context::programUniformMatrix2x3fv(GLuint program,
6435 GLint location,
6436 GLsizei count,
6437 GLboolean transpose,
6438 const GLfloat *value)
6439{
6440 Program *programObject = getProgram(program);
6441 ASSERT(programObject);
6442 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
6443}
6444
6445void Context::programUniformMatrix3x2fv(GLuint program,
6446 GLint location,
6447 GLsizei count,
6448 GLboolean transpose,
6449 const GLfloat *value)
6450{
6451 Program *programObject = getProgram(program);
6452 ASSERT(programObject);
6453 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
6454}
6455
6456void Context::programUniformMatrix2x4fv(GLuint program,
6457 GLint location,
6458 GLsizei count,
6459 GLboolean transpose,
6460 const GLfloat *value)
6461{
6462 Program *programObject = getProgram(program);
6463 ASSERT(programObject);
6464 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
6465}
6466
6467void Context::programUniformMatrix4x2fv(GLuint program,
6468 GLint location,
6469 GLsizei count,
6470 GLboolean transpose,
6471 const GLfloat *value)
6472{
6473 Program *programObject = getProgram(program);
6474 ASSERT(programObject);
6475 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
6476}
6477
6478void Context::programUniformMatrix3x4fv(GLuint program,
6479 GLint location,
6480 GLsizei count,
6481 GLboolean transpose,
6482 const GLfloat *value)
6483{
6484 Program *programObject = getProgram(program);
6485 ASSERT(programObject);
6486 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
6487}
6488
6489void Context::programUniformMatrix4x3fv(GLuint program,
6490 GLint location,
6491 GLsizei count,
6492 GLboolean transpose,
6493 const GLfloat *value)
6494{
6495 Program *programObject = getProgram(program);
6496 ASSERT(programObject);
6497 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
6498}
6499
Jamie Madill81c2e252017-09-09 23:32:46 -04006500void Context::onTextureChange(const Texture *texture)
6501{
6502 // Conservatively assume all textures are dirty.
6503 // TODO(jmadill): More fine-grained update.
6504 mGLState.setObjectDirty(GL_TEXTURE);
6505}
6506
James Darpiniane8a93c62018-01-04 18:02:24 -08006507bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
6508{
6509 return mGLState.isCurrentTransformFeedback(tf);
6510}
6511bool Context::isCurrentVertexArray(const VertexArray *va) const
6512{
6513 return mGLState.isCurrentVertexArray(va);
6514}
6515
Yunchao Hea336b902017-08-02 16:05:21 +08006516void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
6517{
6518 for (int i = 0; i < count; i++)
6519 {
6520 pipelines[i] = createProgramPipeline();
6521 }
6522}
6523
6524void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
6525{
6526 for (int i = 0; i < count; i++)
6527 {
6528 if (pipelines[i] != 0)
6529 {
6530 deleteProgramPipeline(pipelines[i]);
6531 }
6532 }
6533}
6534
6535GLboolean Context::isProgramPipeline(GLuint pipeline)
6536{
6537 if (pipeline == 0)
6538 {
6539 return GL_FALSE;
6540 }
6541
6542 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
6543}
6544
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006545void Context::finishFenceNV(GLuint fence)
6546{
6547 FenceNV *fenceObject = getFenceNV(fence);
6548
6549 ASSERT(fenceObject && fenceObject->isSet());
6550 handleError(fenceObject->finish());
6551}
6552
6553void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
6554{
6555 FenceNV *fenceObject = getFenceNV(fence);
6556
6557 ASSERT(fenceObject && fenceObject->isSet());
6558
6559 switch (pname)
6560 {
6561 case GL_FENCE_STATUS_NV:
6562 {
6563 // GL_NV_fence spec:
6564 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
6565 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
6566 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
6567 GLboolean status = GL_TRUE;
6568 if (fenceObject->getStatus() != GL_TRUE)
6569 {
6570 ANGLE_CONTEXT_TRY(fenceObject->test(&status));
6571 }
6572 *params = status;
6573 break;
6574 }
6575
6576 case GL_FENCE_CONDITION_NV:
6577 {
6578 *params = static_cast<GLint>(fenceObject->getCondition());
6579 break;
6580 }
6581
6582 default:
6583 UNREACHABLE();
6584 }
6585}
6586
6587void Context::getTranslatedShaderSource(GLuint shader,
6588 GLsizei bufsize,
6589 GLsizei *length,
6590 GLchar *source)
6591{
6592 Shader *shaderObject = getShader(shader);
6593 ASSERT(shaderObject);
6594 shaderObject->getTranslatedSourceWithDebugInfo(this, bufsize, length, source);
6595}
6596
6597void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
6598{
6599 Program *programObject = getProgram(program);
6600 ASSERT(programObject);
6601
6602 programObject->getUniformfv(this, location, params);
6603}
6604
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006605void Context::getnUniformfvRobust(GLuint program,
6606 GLint location,
6607 GLsizei bufSize,
6608 GLsizei *length,
6609 GLfloat *params)
6610{
6611 UNIMPLEMENTED();
6612}
6613
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006614void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
6615{
6616 Program *programObject = getProgram(program);
6617 ASSERT(programObject);
6618
6619 programObject->getUniformiv(this, location, params);
6620}
6621
Brandon Jonesfe4bbe62018-04-06 13:50:14 -07006622void Context::getnUniformivRobust(GLuint program,
6623 GLint location,
6624 GLsizei bufSize,
6625 GLsizei *length,
6626 GLint *params)
6627{
6628 UNIMPLEMENTED();
6629}
6630
6631void Context::getnUniformuivRobust(GLuint program,
6632 GLint location,
6633 GLsizei bufSize,
6634 GLsizei *length,
6635 GLuint *params)
6636{
6637 UNIMPLEMENTED();
6638}
6639
Jamie Madill2b7bbc22017-12-21 17:30:38 -05006640GLboolean Context::isFenceNV(GLuint fence)
6641{
6642 FenceNV *fenceObject = getFenceNV(fence);
6643
6644 if (fenceObject == nullptr)
6645 {
6646 return GL_FALSE;
6647 }
6648
6649 // GL_NV_fence spec:
6650 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
6651 // existing fence.
6652 return fenceObject->isSet();
6653}
6654
6655void Context::readnPixels(GLint x,
6656 GLint y,
6657 GLsizei width,
6658 GLsizei height,
6659 GLenum format,
6660 GLenum type,
6661 GLsizei bufSize,
6662 void *data)
6663{
6664 return readPixels(x, y, width, height, format, type, data);
6665}
6666
Jamie Madill007530e2017-12-28 14:27:04 -05006667void Context::setFenceNV(GLuint fence, GLenum condition)
6668{
6669 ASSERT(condition == GL_ALL_COMPLETED_NV);
6670
6671 FenceNV *fenceObject = getFenceNV(fence);
6672 ASSERT(fenceObject != nullptr);
6673 handleError(fenceObject->set(condition));
6674}
6675
6676GLboolean Context::testFenceNV(GLuint fence)
6677{
6678 FenceNV *fenceObject = getFenceNV(fence);
6679
6680 ASSERT(fenceObject != nullptr);
6681 ASSERT(fenceObject->isSet() == GL_TRUE);
6682
6683 GLboolean result = GL_TRUE;
6684 Error error = fenceObject->test(&result);
6685 if (error.isError())
6686 {
6687 handleError(error);
6688 return GL_TRUE;
6689 }
6690
6691 return result;
6692}
6693
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006694void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006695{
6696 Texture *texture = getTargetTexture(target);
Rafael Cintron05a449a2018-06-20 18:08:04 -07006697 egl::Image *imageObject = static_cast<egl::Image *>(image);
Corentin Wallez99d492c2018-02-27 15:17:10 -05006698 handleError(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05006699}
6700
Jamie Madillfa920eb2018-01-04 11:45:50 -05006701void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05006702{
6703 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Rafael Cintron05a449a2018-06-20 18:08:04 -07006704 egl::Image *imageObject = static_cast<egl::Image *>(image);
Jamie Madill007530e2017-12-28 14:27:04 -05006705 handleError(renderbuffer->setStorageEGLImageTarget(this, imageObject));
6706}
6707
Jamie Madillfa920eb2018-01-04 11:45:50 -05006708void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
6709{
6710 UNIMPLEMENTED();
6711}
6712
Jamie Madill5b772312018-03-08 20:28:32 -05006713bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
6714{
6715 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
6716 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
6717 // to the fact that it is stored internally as a float, and so would require conversion
6718 // if returned from Context::getIntegerv. Since this conversion is already implemented
6719 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
6720 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
6721 // application.
6722 switch (pname)
6723 {
6724 case GL_COMPRESSED_TEXTURE_FORMATS:
6725 {
6726 *type = GL_INT;
6727 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
6728 return true;
6729 }
6730 case GL_SHADER_BINARY_FORMATS:
6731 {
6732 *type = GL_INT;
6733 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
6734 return true;
6735 }
6736
6737 case GL_MAX_VERTEX_ATTRIBS:
6738 case GL_MAX_VERTEX_UNIFORM_VECTORS:
6739 case GL_MAX_VARYING_VECTORS:
6740 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
6741 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
6742 case GL_MAX_TEXTURE_IMAGE_UNITS:
6743 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
6744 case GL_MAX_RENDERBUFFER_SIZE:
6745 case GL_NUM_SHADER_BINARY_FORMATS:
6746 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
6747 case GL_ARRAY_BUFFER_BINDING:
6748 case GL_FRAMEBUFFER_BINDING:
6749 case GL_RENDERBUFFER_BINDING:
6750 case GL_CURRENT_PROGRAM:
6751 case GL_PACK_ALIGNMENT:
6752 case GL_UNPACK_ALIGNMENT:
6753 case GL_GENERATE_MIPMAP_HINT:
6754 case GL_RED_BITS:
6755 case GL_GREEN_BITS:
6756 case GL_BLUE_BITS:
6757 case GL_ALPHA_BITS:
6758 case GL_DEPTH_BITS:
6759 case GL_STENCIL_BITS:
6760 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
6761 case GL_CULL_FACE_MODE:
6762 case GL_FRONT_FACE:
6763 case GL_ACTIVE_TEXTURE:
6764 case GL_STENCIL_FUNC:
6765 case GL_STENCIL_VALUE_MASK:
6766 case GL_STENCIL_REF:
6767 case GL_STENCIL_FAIL:
6768 case GL_STENCIL_PASS_DEPTH_FAIL:
6769 case GL_STENCIL_PASS_DEPTH_PASS:
6770 case GL_STENCIL_BACK_FUNC:
6771 case GL_STENCIL_BACK_VALUE_MASK:
6772 case GL_STENCIL_BACK_REF:
6773 case GL_STENCIL_BACK_FAIL:
6774 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
6775 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
6776 case GL_DEPTH_FUNC:
6777 case GL_BLEND_SRC_RGB:
6778 case GL_BLEND_SRC_ALPHA:
6779 case GL_BLEND_DST_RGB:
6780 case GL_BLEND_DST_ALPHA:
6781 case GL_BLEND_EQUATION_RGB:
6782 case GL_BLEND_EQUATION_ALPHA:
6783 case GL_STENCIL_WRITEMASK:
6784 case GL_STENCIL_BACK_WRITEMASK:
6785 case GL_STENCIL_CLEAR_VALUE:
6786 case GL_SUBPIXEL_BITS:
6787 case GL_MAX_TEXTURE_SIZE:
6788 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
6789 case GL_SAMPLE_BUFFERS:
6790 case GL_SAMPLES:
6791 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
6792 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
6793 case GL_TEXTURE_BINDING_2D:
6794 case GL_TEXTURE_BINDING_CUBE_MAP:
6795 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
6796 {
6797 *type = GL_INT;
6798 *numParams = 1;
6799 return true;
6800 }
6801 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6802 {
6803 if (!getExtensions().packReverseRowOrder)
6804 {
6805 return false;
6806 }
6807 *type = GL_INT;
6808 *numParams = 1;
6809 return true;
6810 }
6811 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
6812 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
6813 {
6814 if (!getExtensions().textureRectangle)
6815 {
6816 return false;
6817 }
6818 *type = GL_INT;
6819 *numParams = 1;
6820 return true;
6821 }
6822 case GL_MAX_DRAW_BUFFERS_EXT:
6823 case GL_MAX_COLOR_ATTACHMENTS_EXT:
6824 {
6825 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
6826 {
6827 return false;
6828 }
6829 *type = GL_INT;
6830 *numParams = 1;
6831 return true;
6832 }
6833 case GL_MAX_VIEWPORT_DIMS:
6834 {
6835 *type = GL_INT;
6836 *numParams = 2;
6837 return true;
6838 }
6839 case GL_VIEWPORT:
6840 case GL_SCISSOR_BOX:
6841 {
6842 *type = GL_INT;
6843 *numParams = 4;
6844 return true;
6845 }
6846 case GL_SHADER_COMPILER:
6847 case GL_SAMPLE_COVERAGE_INVERT:
6848 case GL_DEPTH_WRITEMASK:
6849 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
6850 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
6851 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
6852 // bool-natural
6853 case GL_SAMPLE_COVERAGE:
6854 case GL_SCISSOR_TEST:
6855 case GL_STENCIL_TEST:
6856 case GL_DEPTH_TEST:
6857 case GL_BLEND:
6858 case GL_DITHER:
6859 case GL_CONTEXT_ROBUST_ACCESS_EXT:
6860 {
6861 *type = GL_BOOL;
6862 *numParams = 1;
6863 return true;
6864 }
6865 case GL_COLOR_WRITEMASK:
6866 {
6867 *type = GL_BOOL;
6868 *numParams = 4;
6869 return true;
6870 }
6871 case GL_POLYGON_OFFSET_FACTOR:
6872 case GL_POLYGON_OFFSET_UNITS:
6873 case GL_SAMPLE_COVERAGE_VALUE:
6874 case GL_DEPTH_CLEAR_VALUE:
6875 case GL_LINE_WIDTH:
6876 {
6877 *type = GL_FLOAT;
6878 *numParams = 1;
6879 return true;
6880 }
6881 case GL_ALIASED_LINE_WIDTH_RANGE:
6882 case GL_ALIASED_POINT_SIZE_RANGE:
6883 case GL_DEPTH_RANGE:
6884 {
6885 *type = GL_FLOAT;
6886 *numParams = 2;
6887 return true;
6888 }
6889 case GL_COLOR_CLEAR_VALUE:
6890 case GL_BLEND_COLOR:
6891 {
6892 *type = GL_FLOAT;
6893 *numParams = 4;
6894 return true;
6895 }
6896 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
6897 if (!getExtensions().textureFilterAnisotropic)
6898 {
6899 return false;
6900 }
6901 *type = GL_FLOAT;
6902 *numParams = 1;
6903 return true;
6904 case GL_TIMESTAMP_EXT:
6905 if (!getExtensions().disjointTimerQuery)
6906 {
6907 return false;
6908 }
6909 *type = GL_INT_64_ANGLEX;
6910 *numParams = 1;
6911 return true;
6912 case GL_GPU_DISJOINT_EXT:
6913 if (!getExtensions().disjointTimerQuery)
6914 {
6915 return false;
6916 }
6917 *type = GL_INT;
6918 *numParams = 1;
6919 return true;
6920 case GL_COVERAGE_MODULATION_CHROMIUM:
6921 if (!getExtensions().framebufferMixedSamples)
6922 {
6923 return false;
6924 }
6925 *type = GL_INT;
6926 *numParams = 1;
6927 return true;
6928 case GL_TEXTURE_BINDING_EXTERNAL_OES:
6929 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
6930 {
6931 return false;
6932 }
6933 *type = GL_INT;
6934 *numParams = 1;
6935 return true;
6936 }
6937
6938 if (getExtensions().debug)
6939 {
6940 switch (pname)
6941 {
6942 case GL_DEBUG_LOGGED_MESSAGES:
6943 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
6944 case GL_DEBUG_GROUP_STACK_DEPTH:
6945 case GL_MAX_DEBUG_MESSAGE_LENGTH:
6946 case GL_MAX_DEBUG_LOGGED_MESSAGES:
6947 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
6948 case GL_MAX_LABEL_LENGTH:
6949 *type = GL_INT;
6950 *numParams = 1;
6951 return true;
6952
6953 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
6954 case GL_DEBUG_OUTPUT:
6955 *type = GL_BOOL;
6956 *numParams = 1;
6957 return true;
6958 }
6959 }
6960
6961 if (getExtensions().multisampleCompatibility)
6962 {
6963 switch (pname)
6964 {
6965 case GL_MULTISAMPLE_EXT:
6966 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
6967 *type = GL_BOOL;
6968 *numParams = 1;
6969 return true;
6970 }
6971 }
6972
6973 if (getExtensions().pathRendering)
6974 {
6975 switch (pname)
6976 {
6977 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
6978 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
6979 *type = GL_FLOAT;
6980 *numParams = 16;
6981 return true;
6982 }
6983 }
6984
6985 if (getExtensions().bindGeneratesResource)
6986 {
6987 switch (pname)
6988 {
6989 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
6990 *type = GL_BOOL;
6991 *numParams = 1;
6992 return true;
6993 }
6994 }
6995
6996 if (getExtensions().clientArrays)
6997 {
6998 switch (pname)
6999 {
7000 case GL_CLIENT_ARRAYS_ANGLE:
7001 *type = GL_BOOL;
7002 *numParams = 1;
7003 return true;
7004 }
7005 }
7006
7007 if (getExtensions().sRGBWriteControl)
7008 {
7009 switch (pname)
7010 {
7011 case GL_FRAMEBUFFER_SRGB_EXT:
7012 *type = GL_BOOL;
7013 *numParams = 1;
7014 return true;
7015 }
7016 }
7017
7018 if (getExtensions().robustResourceInitialization &&
7019 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
7020 {
7021 *type = GL_BOOL;
7022 *numParams = 1;
7023 return true;
7024 }
7025
7026 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
7027 {
7028 *type = GL_BOOL;
7029 *numParams = 1;
7030 return true;
7031 }
7032
jchen1082af6202018-06-22 10:59:52 +08007033 if (getExtensions().parallelShaderCompile && pname == GL_MAX_SHADER_COMPILER_THREADS_KHR)
7034 {
7035 *type = GL_INT;
7036 *numParams = 1;
7037 return true;
7038 }
7039
Jamie Madill5b772312018-03-08 20:28:32 -05007040 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
7041 switch (pname)
7042 {
7043 // case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE // equivalent to FRAMEBUFFER_BINDING
7044 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
7045 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
7046 {
7047 return false;
7048 }
7049 *type = GL_INT;
7050 *numParams = 1;
7051 return true;
7052
7053 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
7054 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7055 {
7056 return false;
7057 }
7058 *type = GL_INT;
7059 *numParams = 1;
7060 return true;
7061
7062 case GL_PROGRAM_BINARY_FORMATS_OES:
7063 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
7064 {
7065 return false;
7066 }
7067 *type = GL_INT;
7068 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
7069 return true;
7070
7071 case GL_PACK_ROW_LENGTH:
7072 case GL_PACK_SKIP_ROWS:
7073 case GL_PACK_SKIP_PIXELS:
7074 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
7075 {
7076 return false;
7077 }
7078 *type = GL_INT;
7079 *numParams = 1;
7080 return true;
7081 case GL_UNPACK_ROW_LENGTH:
7082 case GL_UNPACK_SKIP_ROWS:
7083 case GL_UNPACK_SKIP_PIXELS:
7084 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
7085 {
7086 return false;
7087 }
7088 *type = GL_INT;
7089 *numParams = 1;
7090 return true;
7091 case GL_VERTEX_ARRAY_BINDING:
7092 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
7093 {
7094 return false;
7095 }
7096 *type = GL_INT;
7097 *numParams = 1;
7098 return true;
7099 case GL_PIXEL_PACK_BUFFER_BINDING:
7100 case GL_PIXEL_UNPACK_BUFFER_BINDING:
7101 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
7102 {
7103 return false;
7104 }
7105 *type = GL_INT;
7106 *numParams = 1;
7107 return true;
7108 case GL_MAX_SAMPLES:
7109 {
7110 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
7111 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
7112 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
7113 {
7114 return false;
7115 }
7116 *type = GL_INT;
7117 *numParams = 1;
7118 return true;
7119
7120 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
7121 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
7122 {
7123 return false;
7124 }
7125 *type = GL_INT;
7126 *numParams = 1;
7127 return true;
7128 }
7129 }
7130
7131 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
7132 {
7133 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
7134 {
7135 return false;
7136 }
7137 *type = GL_INT;
7138 *numParams = 1;
7139 return true;
7140 }
7141
7142 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
7143 {
7144 *type = GL_INT;
7145 *numParams = 1;
7146 return true;
7147 }
7148
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007149 if (getClientVersion() < Version(2, 0))
7150 {
7151 switch (pname)
7152 {
7153 case GL_ALPHA_TEST_FUNC:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007154 case GL_CLIENT_ACTIVE_TEXTURE:
7155 case GL_MATRIX_MODE:
7156 case GL_MAX_TEXTURE_UNITS:
7157 case GL_MAX_MODELVIEW_STACK_DEPTH:
7158 case GL_MAX_PROJECTION_STACK_DEPTH:
7159 case GL_MAX_TEXTURE_STACK_DEPTH:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007160 case GL_MAX_LIGHTS:
Lingfeng Yang060088a2018-05-30 20:40:57 -07007161 case GL_MAX_CLIP_PLANES:
Lingfeng Yangabb09f12018-04-16 10:43:53 -07007162 case GL_VERTEX_ARRAY_STRIDE:
7163 case GL_NORMAL_ARRAY_STRIDE:
7164 case GL_COLOR_ARRAY_STRIDE:
7165 case GL_TEXTURE_COORD_ARRAY_STRIDE:
7166 case GL_VERTEX_ARRAY_SIZE:
7167 case GL_COLOR_ARRAY_SIZE:
7168 case GL_TEXTURE_COORD_ARRAY_SIZE:
7169 case GL_VERTEX_ARRAY_TYPE:
7170 case GL_NORMAL_ARRAY_TYPE:
7171 case GL_COLOR_ARRAY_TYPE:
7172 case GL_TEXTURE_COORD_ARRAY_TYPE:
7173 case GL_VERTEX_ARRAY_BUFFER_BINDING:
7174 case GL_NORMAL_ARRAY_BUFFER_BINDING:
7175 case GL_COLOR_ARRAY_BUFFER_BINDING:
7176 case GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING:
7177 case GL_POINT_SIZE_ARRAY_STRIDE_OES:
7178 case GL_POINT_SIZE_ARRAY_TYPE_OES:
7179 case GL_POINT_SIZE_ARRAY_BUFFER_BINDING_OES:
Lingfeng Yanga0cfa872018-05-30 21:12:17 -07007180 case GL_SHADE_MODEL:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007181 *type = GL_INT;
7182 *numParams = 1;
7183 return true;
7184 case GL_ALPHA_TEST_REF:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007185 case GL_FOG_DENSITY:
7186 case GL_FOG_START:
7187 case GL_FOG_END:
7188 case GL_FOG_MODE:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007189 case GL_POINT_SIZE:
7190 case GL_POINT_SIZE_MIN:
7191 case GL_POINT_SIZE_MAX:
7192 case GL_POINT_FADE_THRESHOLD_SIZE:
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007193 *type = GL_FLOAT;
7194 *numParams = 1;
7195 return true;
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007196 case GL_SMOOTH_POINT_SIZE_RANGE:
7197 *type = GL_FLOAT;
7198 *numParams = 2;
7199 return true;
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007200 case GL_CURRENT_COLOR:
Lingfeng Yange547aac2018-04-05 09:39:20 -07007201 case GL_CURRENT_TEXTURE_COORDS:
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007202 case GL_LIGHT_MODEL_AMBIENT:
Lingfeng Yang7ba3f422018-06-01 09:43:04 -07007203 case GL_FOG_COLOR:
Lingfeng Yanga43994c2018-03-29 07:21:41 -07007204 *type = GL_FLOAT;
7205 *numParams = 4;
7206 return true;
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007207 case GL_CURRENT_NORMAL:
Lingfeng Yang9c4c0922018-06-13 09:29:00 -07007208 case GL_POINT_DISTANCE_ATTENUATION:
Lingfeng Yang5a7e61b2018-03-29 16:50:32 -07007209 *type = GL_FLOAT;
7210 *numParams = 3;
7211 return true;
Lingfeng Yang3a41af62018-04-09 07:28:56 -07007212 case GL_MODELVIEW_MATRIX:
7213 case GL_PROJECTION_MATRIX:
7214 case GL_TEXTURE_MATRIX:
7215 *type = GL_FLOAT;
7216 *numParams = 16;
7217 return true;
Lingfeng Yangd0febe72018-05-17 22:36:52 -07007218 case GL_LIGHT_MODEL_TWO_SIDE:
7219 *type = GL_BOOL;
7220 *numParams = 1;
7221 return true;
Lingfeng Yang13b708f2018-03-21 12:14:10 -07007222 }
7223 }
7224
Jamie Madill5b772312018-03-08 20:28:32 -05007225 if (getClientVersion() < Version(3, 0))
7226 {
7227 return false;
7228 }
7229
7230 // Check for ES3.0+ parameter names
7231 switch (pname)
7232 {
7233 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
7234 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
7235 case GL_UNIFORM_BUFFER_BINDING:
7236 case GL_TRANSFORM_FEEDBACK_BINDING:
7237 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7238 case GL_COPY_READ_BUFFER_BINDING:
7239 case GL_COPY_WRITE_BUFFER_BINDING:
7240 case GL_SAMPLER_BINDING:
7241 case GL_READ_BUFFER:
7242 case GL_TEXTURE_BINDING_3D:
7243 case GL_TEXTURE_BINDING_2D_ARRAY:
7244 case GL_MAX_3D_TEXTURE_SIZE:
7245 case GL_MAX_ARRAY_TEXTURE_LAYERS:
7246 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
7247 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
7248 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
7249 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
7250 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
7251 case GL_MAX_VARYING_COMPONENTS:
7252 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
7253 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
7254 case GL_MIN_PROGRAM_TEXEL_OFFSET:
7255 case GL_MAX_PROGRAM_TEXEL_OFFSET:
7256 case GL_NUM_EXTENSIONS:
7257 case GL_MAJOR_VERSION:
7258 case GL_MINOR_VERSION:
7259 case GL_MAX_ELEMENTS_INDICES:
7260 case GL_MAX_ELEMENTS_VERTICES:
7261 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
7262 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
7263 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
7264 case GL_UNPACK_IMAGE_HEIGHT:
7265 case GL_UNPACK_SKIP_IMAGES:
7266 {
7267 *type = GL_INT;
7268 *numParams = 1;
7269 return true;
7270 }
7271
7272 case GL_MAX_ELEMENT_INDEX:
7273 case GL_MAX_UNIFORM_BLOCK_SIZE:
7274 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
7275 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
7276 case GL_MAX_SERVER_WAIT_TIMEOUT:
7277 {
7278 *type = GL_INT_64_ANGLEX;
7279 *numParams = 1;
7280 return true;
7281 }
7282
7283 case GL_TRANSFORM_FEEDBACK_ACTIVE:
7284 case GL_TRANSFORM_FEEDBACK_PAUSED:
7285 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
7286 case GL_RASTERIZER_DISCARD:
7287 {
7288 *type = GL_BOOL;
7289 *numParams = 1;
7290 return true;
7291 }
7292
7293 case GL_MAX_TEXTURE_LOD_BIAS:
7294 {
7295 *type = GL_FLOAT;
7296 *numParams = 1;
7297 return true;
7298 }
7299 }
7300
7301 if (getExtensions().requestExtension)
7302 {
7303 switch (pname)
7304 {
7305 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
7306 *type = GL_INT;
7307 *numParams = 1;
7308 return true;
7309 }
7310 }
7311
7312 if (getClientVersion() < Version(3, 1))
7313 {
7314 return false;
7315 }
7316
7317 switch (pname)
7318 {
7319 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7320 case GL_DRAW_INDIRECT_BUFFER_BINDING:
7321 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
7322 case GL_MAX_FRAMEBUFFER_WIDTH:
7323 case GL_MAX_FRAMEBUFFER_HEIGHT:
7324 case GL_MAX_FRAMEBUFFER_SAMPLES:
7325 case GL_MAX_SAMPLE_MASK_WORDS:
7326 case GL_MAX_COLOR_TEXTURE_SAMPLES:
7327 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
7328 case GL_MAX_INTEGER_SAMPLES:
7329 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
7330 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
7331 case GL_MAX_VERTEX_ATTRIB_STRIDE:
7332 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
7333 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
7334 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
7335 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
7336 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
7337 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
7338 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
7339 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
7340 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
7341 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
7342 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
7343 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
7344 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
7345 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
7346 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
7347 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
7348 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
7349 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
7350 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
7351 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
7352 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
7353 case GL_MAX_UNIFORM_LOCATIONS:
7354 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
7355 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
7356 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
7357 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
7358 case GL_MAX_IMAGE_UNITS:
7359 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
7360 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
7361 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
7362 case GL_SHADER_STORAGE_BUFFER_BINDING:
7363 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
7364 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
7365 *type = GL_INT;
7366 *numParams = 1;
7367 return true;
7368 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7369 *type = GL_INT_64_ANGLEX;
7370 *numParams = 1;
7371 return true;
7372 case GL_SAMPLE_MASK:
7373 *type = GL_BOOL;
7374 *numParams = 1;
7375 return true;
7376 }
7377
7378 if (getExtensions().geometryShader)
7379 {
7380 switch (pname)
7381 {
7382 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7383 case GL_LAYER_PROVOKING_VERTEX_EXT:
7384 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7385 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7386 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7387 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7388 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7389 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7390 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7391 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7392 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7393 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7394 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7395 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7396 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7397 *type = GL_INT;
7398 *numParams = 1;
7399 return true;
7400 }
7401 }
7402
7403 return false;
7404}
7405
7406bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7407{
7408 if (getClientVersion() < Version(3, 0))
7409 {
7410 return false;
7411 }
7412
7413 switch (target)
7414 {
7415 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7416 case GL_UNIFORM_BUFFER_BINDING:
7417 {
7418 *type = GL_INT;
7419 *numParams = 1;
7420 return true;
7421 }
7422 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7423 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7424 case GL_UNIFORM_BUFFER_START:
7425 case GL_UNIFORM_BUFFER_SIZE:
7426 {
7427 *type = GL_INT_64_ANGLEX;
7428 *numParams = 1;
7429 return true;
7430 }
7431 }
7432
7433 if (getClientVersion() < Version(3, 1))
7434 {
7435 return false;
7436 }
7437
7438 switch (target)
7439 {
7440 case GL_IMAGE_BINDING_LAYERED:
7441 {
7442 *type = GL_BOOL;
7443 *numParams = 1;
7444 return true;
7445 }
7446 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7447 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7448 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7449 case GL_SHADER_STORAGE_BUFFER_BINDING:
7450 case GL_VERTEX_BINDING_BUFFER:
7451 case GL_VERTEX_BINDING_DIVISOR:
7452 case GL_VERTEX_BINDING_OFFSET:
7453 case GL_VERTEX_BINDING_STRIDE:
7454 case GL_SAMPLE_MASK_VALUE:
7455 case GL_IMAGE_BINDING_NAME:
7456 case GL_IMAGE_BINDING_LEVEL:
7457 case GL_IMAGE_BINDING_LAYER:
7458 case GL_IMAGE_BINDING_ACCESS:
7459 case GL_IMAGE_BINDING_FORMAT:
7460 {
7461 *type = GL_INT;
7462 *numParams = 1;
7463 return true;
7464 }
7465 case GL_ATOMIC_COUNTER_BUFFER_START:
7466 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
7467 case GL_SHADER_STORAGE_BUFFER_START:
7468 case GL_SHADER_STORAGE_BUFFER_SIZE:
7469 {
7470 *type = GL_INT_64_ANGLEX;
7471 *numParams = 1;
7472 return true;
7473 }
7474 }
7475
7476 return false;
7477}
7478
7479Program *Context::getProgram(GLuint handle) const
7480{
7481 return mState.mShaderPrograms->getProgram(handle);
7482}
7483
7484Shader *Context::getShader(GLuint handle) const
7485{
7486 return mState.mShaderPrograms->getShader(handle);
7487}
7488
7489bool Context::isTextureGenerated(GLuint texture) const
7490{
7491 return mState.mTextures->isHandleGenerated(texture);
7492}
7493
7494bool Context::isBufferGenerated(GLuint buffer) const
7495{
7496 return mState.mBuffers->isHandleGenerated(buffer);
7497}
7498
7499bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
7500{
7501 return mState.mRenderbuffers->isHandleGenerated(renderbuffer);
7502}
7503
7504bool Context::isFramebufferGenerated(GLuint framebuffer) const
7505{
7506 return mState.mFramebuffers->isHandleGenerated(framebuffer);
7507}
7508
7509bool Context::isProgramPipelineGenerated(GLuint pipeline) const
7510{
7511 return mState.mPipelines->isHandleGenerated(pipeline);
7512}
7513
7514bool Context::usingDisplayTextureShareGroup() const
7515{
7516 return mDisplayTextureShareGroup;
7517}
7518
7519GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
7520{
7521 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
7522 internalformat == GL_DEPTH_STENCIL
7523 ? GL_DEPTH24_STENCIL8
7524 : internalformat;
7525}
7526
jchen1082af6202018-06-22 10:59:52 +08007527void Context::maxShaderCompilerThreads(GLuint count)
7528{
7529 mGLState.setMaxShaderCompilerThreads(count);
7530}
7531
Jamie Madill6b873dd2018-07-12 23:56:30 -04007532// ErrorSet implementation.
7533ErrorSet::ErrorSet(Context *context) : mContext(context)
7534{
7535}
7536
7537ErrorSet::~ErrorSet() = default;
7538
7539void ErrorSet::handleError(const Error &error)
7540{
7541 // This internal enum is used to filter internal errors that are already handled.
7542 // TODO(jmadill): Remove this when refactor is done. http://anglebug.com/2491
7543 if (error.getCode() == GL_INTERNAL_ERROR_ANGLEX)
7544 {
7545 return;
7546 }
7547
7548 if (ANGLE_UNLIKELY(error.isError()))
7549 {
7550 GLenum code = error.getCode();
7551 mErrors.insert(code);
7552 if (code == GL_OUT_OF_MEMORY && mContext->getWorkarounds().loseContextOnOutOfMemory)
7553 {
7554 mContext->markContextLost();
7555 }
7556
7557 ASSERT(!error.getMessage().empty());
7558 mContext->getGLState().getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR,
7559 error.getID(), GL_DEBUG_SEVERITY_HIGH,
7560 error.getMessage());
7561 }
7562}
7563
7564bool ErrorSet::empty() const
7565{
7566 return mErrors.empty();
7567}
7568
7569GLenum ErrorSet::popError()
7570{
7571 ASSERT(!empty());
7572 GLenum error = *mErrors.begin();
7573 mErrors.erase(mErrors.begin());
7574 return error;
7575}
Jamie Madillc29968b2016-01-20 11:17:23 -05007576} // namespace gl