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