blob: ad3dad073379b40c313109711b6149e77ecf08c0 [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
Sami Väisänene45e53b2016-05-25 10:36:04 +030017#include "common/matrix_utils.h"
Geoff Lang0b7eef72014-06-12 14:10:47 -040018#include "common/platform.h"
Jamie Madillb9293972015-02-19 11:07:54 -050019#include "common/utilities.h"
Geoff Langc339c4e2016-11-29 10:37:36 -050020#include "common/version.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050021#include "libANGLE/Buffer.h"
Jamie Madillb9293972015-02-19 11:07:54 -050022#include "libANGLE/Compiler.h"
Jamie Madill948bbe52017-06-01 13:10:42 -040023#include "libANGLE/Display.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050024#include "libANGLE/Fence.h"
25#include "libANGLE/Framebuffer.h"
26#include "libANGLE/FramebufferAttachment.h"
Sami Väisänene45e53b2016-05-25 10:36:04 +030027#include "libANGLE/Path.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050028#include "libANGLE/Program.h"
Yunchao Hea336b902017-08-02 16:05:21 +080029#include "libANGLE/ProgramPipeline.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050030#include "libANGLE/Query.h"
Jamie Madillb9293972015-02-19 11:07:54 -050031#include "libANGLE/Renderbuffer.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050032#include "libANGLE/ResourceManager.h"
33#include "libANGLE/Sampler.h"
Jamie Madill9dd0cf02014-11-24 11:38:51 -050034#include "libANGLE/Surface.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050035#include "libANGLE/Texture.h"
36#include "libANGLE/TransformFeedback.h"
37#include "libANGLE/VertexArray.h"
Kenneth Russellf2f6f652016-10-05 19:53:23 -070038#include "libANGLE/Workarounds.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040039#include "libANGLE/formatutils.h"
Martin Radev66fb8202016-07-28 11:45:20 +030040#include "libANGLE/queryconversions.h"
Geoff Langc1984ed2016-10-07 12:41:00 -040041#include "libANGLE/queryutils.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040042#include "libANGLE/renderer/ContextImpl.h"
43#include "libANGLE/renderer/EGLImplFactory.h"
Jamie Madill7b62cf92017-11-02 15:20:49 -040044#include "libANGLE/renderer/Format.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040045#include "libANGLE/validationES.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000046
Geoff Langf6db0982015-08-25 13:04:00 -040047namespace
48{
49
Jamie Madillb6664922017-07-25 12:55:04 -040050#define ANGLE_HANDLE_ERR(X) \
51 handleError(X); \
52 return;
53#define ANGLE_CONTEXT_TRY(EXPR) ANGLE_TRY_TEMPLATE(EXPR, ANGLE_HANDLE_ERR);
54
Ian Ewell3ffd78b2016-01-22 16:09:42 -050055template <typename T>
Geoff Lang4ddf5af2016-12-01 14:30:44 -050056std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager,
Sami Väisänend59ca052016-06-21 16:10:00 +030057 GLsizei numPaths,
58 const void *paths,
59 GLuint pathBase)
60{
61 std::vector<gl::Path *> ret;
62 ret.reserve(numPaths);
63
64 const auto *nameArray = static_cast<const T *>(paths);
65
66 for (GLsizei i = 0; i < numPaths; ++i)
67 {
68 const GLuint pathName = nameArray[i] + pathBase;
69
70 ret.push_back(resourceManager.getPath(pathName));
71 }
72
73 return ret;
74}
75
Geoff Lang4ddf5af2016-12-01 14:30:44 -050076std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager,
Sami Väisänend59ca052016-06-21 16:10:00 +030077 GLsizei numPaths,
78 GLenum pathNameType,
79 const void *paths,
80 GLuint pathBase)
81{
82 switch (pathNameType)
83 {
84 case GL_UNSIGNED_BYTE:
85 return GatherPaths<GLubyte>(resourceManager, numPaths, paths, pathBase);
86
87 case GL_BYTE:
88 return GatherPaths<GLbyte>(resourceManager, numPaths, paths, pathBase);
89
90 case GL_UNSIGNED_SHORT:
91 return GatherPaths<GLushort>(resourceManager, numPaths, paths, pathBase);
92
93 case GL_SHORT:
94 return GatherPaths<GLshort>(resourceManager, numPaths, paths, pathBase);
95
96 case GL_UNSIGNED_INT:
97 return GatherPaths<GLuint>(resourceManager, numPaths, paths, pathBase);
98
99 case GL_INT:
100 return GatherPaths<GLint>(resourceManager, numPaths, paths, pathBase);
101 }
102
103 UNREACHABLE();
104 return std::vector<gl::Path *>();
105}
106
107template <typename T>
Geoff Lang2186c382016-10-14 10:54:54 -0400108gl::Error GetQueryObjectParameter(gl::Query *query, GLenum pname, T *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500109{
Geoff Lang2186c382016-10-14 10:54:54 -0400110 ASSERT(query != nullptr);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500111
112 switch (pname)
113 {
114 case GL_QUERY_RESULT_EXT:
Geoff Lang2186c382016-10-14 10:54:54 -0400115 return query->getResult(params);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500116 case GL_QUERY_RESULT_AVAILABLE_EXT:
117 {
118 bool available;
Geoff Lang2186c382016-10-14 10:54:54 -0400119 gl::Error error = query->isResultAvailable(&available);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500120 if (!error.isError())
121 {
jchen10a99ed552017-09-22 08:10:32 +0800122 *params = gl::CastFromStateValue<T>(pname, static_cast<GLuint>(available));
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500123 }
124 return error;
125 }
126 default:
127 UNREACHABLE();
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500128 return gl::InternalError() << "Unreachable Error";
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500129 }
130}
131
Geoff Langf6db0982015-08-25 13:04:00 -0400132void MarkTransformFeedbackBufferUsage(gl::TransformFeedback *transformFeedback)
133{
Geoff Lang1a683462015-09-29 15:09:59 -0400134 if (transformFeedback && transformFeedback->isActive() && !transformFeedback->isPaused())
Geoff Langf6db0982015-08-25 13:04:00 -0400135 {
136 for (size_t tfBufferIndex = 0; tfBufferIndex < transformFeedback->getIndexedBufferCount();
137 tfBufferIndex++)
138 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400139 const gl::OffsetBindingPointer<gl::Buffer> &buffer =
Geoff Langf6db0982015-08-25 13:04:00 -0400140 transformFeedback->getIndexedBuffer(tfBufferIndex);
141 if (buffer.get() != nullptr)
142 {
143 buffer->onTransformFeedback();
144 }
145 }
146 }
147}
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500148
149// Attribute map queries.
Martin Radev1be913c2016-07-11 17:59:16 +0300150EGLint GetClientMajorVersion(const egl::AttributeMap &attribs)
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500151{
Ian Ewellec2c0c52016-04-05 13:46:26 -0400152 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_CLIENT_VERSION, 1));
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500153}
154
Martin Radev1be913c2016-07-11 17:59:16 +0300155EGLint GetClientMinorVersion(const egl::AttributeMap &attribs)
156{
157 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_MINOR_VERSION, 0));
158}
159
Geoff Langeb66a6e2016-10-31 13:06:12 -0400160gl::Version GetClientVersion(const egl::AttributeMap &attribs)
161{
162 return gl::Version(GetClientMajorVersion(attribs), GetClientMinorVersion(attribs));
163}
164
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500165GLenum GetResetStrategy(const egl::AttributeMap &attribs)
166{
Lingfeng Yangb27b03a2018-02-19 13:38:48 -0800167 EGLAttrib attrib =
168 attribs.get(EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT, EGL_NO_RESET_NOTIFICATION);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500169 switch (attrib)
170 {
171 case EGL_NO_RESET_NOTIFICATION:
172 return GL_NO_RESET_NOTIFICATION_EXT;
173 case EGL_LOSE_CONTEXT_ON_RESET:
174 return GL_LOSE_CONTEXT_ON_RESET_EXT;
175 default:
176 UNREACHABLE();
177 return GL_NONE;
178 }
179}
180
181bool GetRobustAccess(const egl::AttributeMap &attribs)
182{
Geoff Lang077f20a2016-11-01 10:08:02 -0400183 return (attribs.get(EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT, EGL_FALSE) == EGL_TRUE) ||
184 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR) !=
185 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500186}
187
188bool GetDebug(const egl::AttributeMap &attribs)
189{
Geoff Lang077f20a2016-11-01 10:08:02 -0400190 return (attribs.get(EGL_CONTEXT_OPENGL_DEBUG, EGL_FALSE) == EGL_TRUE) ||
191 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR) != 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500192}
193
194bool GetNoError(const egl::AttributeMap &attribs)
195{
196 return (attribs.get(EGL_CONTEXT_OPENGL_NO_ERROR_KHR, EGL_FALSE) == EGL_TRUE);
197}
198
Geoff Langc287ea62016-09-16 14:46:51 -0400199bool GetWebGLContext(const egl::AttributeMap &attribs)
200{
201 return (attribs.get(EGL_CONTEXT_WEBGL_COMPATIBILITY_ANGLE, EGL_FALSE) == EGL_TRUE);
202}
203
Geoff Langf41a7152016-09-19 15:11:17 -0400204bool GetBindGeneratesResource(const egl::AttributeMap &attribs)
205{
206 return (attribs.get(EGL_CONTEXT_BIND_GENERATES_RESOURCE_CHROMIUM, EGL_TRUE) == EGL_TRUE);
207}
208
Geoff Langfeb8c682017-02-13 16:07:35 -0500209bool GetClientArraysEnabled(const egl::AttributeMap &attribs)
210{
211 return (attribs.get(EGL_CONTEXT_CLIENT_ARRAYS_ENABLED_ANGLE, EGL_TRUE) == EGL_TRUE);
212}
213
Geoff Langb433e872017-10-05 14:01:47 -0400214bool GetRobustResourceInit(const egl::AttributeMap &attribs)
215{
216 return (attribs.get(EGL_ROBUST_RESOURCE_INITIALIZATION_ANGLE, EGL_FALSE) == EGL_TRUE);
217}
218
Martin Radev9d901792016-07-15 15:58:58 +0300219std::string GetObjectLabelFromPointer(GLsizei length, const GLchar *label)
220{
221 std::string labelName;
222 if (label != nullptr)
223 {
224 size_t labelLength = length < 0 ? strlen(label) : length;
225 labelName = std::string(label, labelLength);
226 }
227 return labelName;
228}
229
230void GetObjectLabelBase(const std::string &objectLabel,
231 GLsizei bufSize,
232 GLsizei *length,
233 GLchar *label)
234{
235 size_t writeLength = objectLabel.length();
236 if (label != nullptr && bufSize > 0)
237 {
238 writeLength = std::min(static_cast<size_t>(bufSize) - 1, objectLabel.length());
239 std::copy(objectLabel.begin(), objectLabel.begin() + writeLength, label);
240 label[writeLength] = '\0';
241 }
242
243 if (length != nullptr)
244 {
245 *length = static_cast<GLsizei>(writeLength);
246 }
247}
248
Jamie Madill0f80ed82017-09-19 00:24:56 -0400249template <typename CapT, typename MaxT>
250void LimitCap(CapT *cap, MaxT maximum)
251{
252 *cap = std::min(*cap, static_cast<CapT>(maximum));
253}
254
Geoff Langf6db0982015-08-25 13:04:00 -0400255} // anonymous namespace
256
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000257namespace gl
258{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +0000259
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400260Context::Context(rx::EGLImplFactory *implFactory,
261 const egl::Config *config,
Corentin Wallez51706ea2015-08-07 14:39:22 -0400262 const Context *shareContext,
Geoff Langce02f082017-02-06 16:46:21 -0500263 TextureManager *shareTextures,
Jamie Madill32447362017-06-28 14:53:52 -0400264 MemoryProgramCache *memoryProgramCache,
Corentin Wallezc295e512017-01-27 17:47:50 -0500265 const egl::AttributeMap &attribs,
Geoff Langb433e872017-10-05 14:01:47 -0400266 const egl::DisplayExtensions &displayExtensions)
Jamie Madill5b772312018-03-08 20:28:32 -0500267 : mState(reinterpret_cast<ContextID>(this),
268 shareContext ? &shareContext->mState : nullptr,
269 shareTextures,
270 GetClientVersion(attribs),
271 &mGLState,
272 mCaps,
273 mTextureCaps,
274 mExtensions,
275 mLimitations),
276 mSkipValidation(GetNoError(attribs)),
277 mDisplayTextureShareGroup(shareTextures != nullptr),
278 mSavedArgsType(nullptr),
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700279 mImplementation(implFactory->createContext(mState)),
Jamie Madill2f348d22017-06-05 10:50:59 -0400280 mCompiler(),
Corentin Walleze3b10e82015-05-20 11:06:25 -0400281 mConfig(config),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500282 mClientType(EGL_OPENGL_ES_API),
283 mHasBeenCurrent(false),
284 mContextLost(false),
285 mResetStatus(GL_NO_ERROR),
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700286 mContextLostForced(false),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500287 mResetStrategy(GetResetStrategy(attribs)),
288 mRobustAccess(GetRobustAccess(attribs)),
Jamie Madill61e16b42017-06-19 11:13:23 -0400289 mCurrentSurface(static_cast<egl::Surface *>(EGL_NO_SURFACE)),
290 mCurrentDisplay(static_cast<egl::Display *>(EGL_NO_DISPLAY)),
Jamie Madill4e0e6f82017-02-17 11:06:03 -0500291 mSurfacelessFramebuffer(nullptr),
Jamie Madille14951e2017-03-09 18:55:16 -0500292 mWebGLContext(GetWebGLContext(attribs)),
Jamie Madill32447362017-06-28 14:53:52 -0400293 mMemoryProgramCache(memoryProgramCache),
Jamie Madillb3f26b92017-07-19 15:07:41 -0400294 mScratchBuffer(1000u),
295 mZeroFilledBuffer(1000u)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000296{
Jamie Madill5b772312018-03-08 20:28:32 -0500297 // Needed to solve a Clang warning of unused variables.
298 UNUSED_VARIABLE(mSavedArgsType);
299 UNUSED_VARIABLE(mParamsBuffer);
300
Jamie Madill14bbb3f2017-09-12 15:23:01 -0400301 mImplementation->setMemoryProgramCache(memoryProgramCache);
302
Geoff Langb433e872017-10-05 14:01:47 -0400303 bool robustResourceInit = GetRobustResourceInit(attribs);
304 initCaps(displayExtensions, robustResourceInit);
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700305 initWorkarounds();
Geoff Langc0b9ef42014-07-02 10:02:37 -0400306
Jamie Madill4928b7c2017-06-20 12:57:39 -0400307 mGLState.initialize(this, GetDebug(attribs), GetBindGeneratesResource(attribs),
Jamie Madillc43be722017-07-13 16:22:14 -0400308 GetClientArraysEnabled(attribs), robustResourceInit,
309 mMemoryProgramCache != nullptr);
Régis Fénéon83107972015-02-05 12:57:44 +0100310
Shannon Woods53a94a82014-06-24 15:20:36 -0400311 mFenceNVHandleAllocator.setBaseHandle(0);
Geoff Lang7dca1862013-07-30 16:30:46 -0400312
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000313 // [OpenGL ES 2.0.24] section 3.7 page 83:
Corentin Wallez336129f2017-10-17 15:55:40 -0400314 // In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have two-dimensional
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000315 // and cube map texture state vectors respectively associated with them.
316 // In order that access to these initial textures not be lost, they are treated as texture
317 // objects all of whose names are 0.
318
Corentin Wallez99d492c2018-02-27 15:17:10 -0500319 Texture *zeroTexture2D = new Texture(mImplementation.get(), 0, TextureType::_2D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800320 mZeroTextures[TextureType::_2D].set(this, zeroTexture2D);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500321
Corentin Wallez99d492c2018-02-27 15:17:10 -0500322 Texture *zeroTextureCube = new Texture(mImplementation.get(), 0, TextureType::CubeMap);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800323 mZeroTextures[TextureType::CubeMap].set(this, zeroTextureCube);
Geoff Lang76b10c92014-09-05 16:28:14 -0400324
Geoff Langeb66a6e2016-10-31 13:06:12 -0400325 if (getClientVersion() >= Version(3, 0))
Geoff Lang76b10c92014-09-05 16:28:14 -0400326 {
327 // TODO: These could also be enabled via extension
Corentin Wallez99d492c2018-02-27 15:17:10 -0500328 Texture *zeroTexture3D = new Texture(mImplementation.get(), 0, TextureType::_3D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800329 mZeroTextures[TextureType::_3D].set(this, zeroTexture3D);
Geoff Lang76b10c92014-09-05 16:28:14 -0400330
Corentin Wallez99d492c2018-02-27 15:17:10 -0500331 Texture *zeroTexture2DArray = new Texture(mImplementation.get(), 0, TextureType::_2DArray);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800332 mZeroTextures[TextureType::_2DArray].set(this, zeroTexture2DArray);
Geoff Lang76b10c92014-09-05 16:28:14 -0400333 }
Geoff Lang3b573612016-10-31 14:08:10 -0400334 if (getClientVersion() >= Version(3, 1))
335 {
336 Texture *zeroTexture2DMultisample =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500337 new Texture(mImplementation.get(), 0, TextureType::_2DMultisample);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800338 mZeroTextures[TextureType::_2DMultisample].set(this, zeroTexture2DMultisample);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800339
Jiajia Qin6eafb042016-12-27 17:04:07 +0800340 for (unsigned int i = 0; i < mCaps.maxAtomicCounterBufferBindings; i++)
341 {
Qin Jiajia339f65b2018-02-27 12:52:48 +0800342 bindBufferRange(BufferBinding::AtomicCounter, i, 0, 0, 0);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800343 }
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800344
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800345 for (unsigned int i = 0; i < mCaps.maxShaderStorageBufferBindings; i++)
346 {
Corentin Wallez336129f2017-10-17 15:55:40 -0400347 bindBufferRange(BufferBinding::ShaderStorage, i, 0, 0, 0);
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800348 }
Geoff Lang3b573612016-10-31 14:08:10 -0400349 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000350
Geoff Lang4751aab2017-10-30 15:14:52 -0400351 const Extensions &nativeExtensions = mImplementation->getNativeExtensions();
352 if (nativeExtensions.textureRectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400353 {
354 Texture *zeroTextureRectangle =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500355 new Texture(mImplementation.get(), 0, TextureType::Rectangle);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800356 mZeroTextures[TextureType::Rectangle].set(this, zeroTextureRectangle);
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400357 }
358
Geoff Lang4751aab2017-10-30 15:14:52 -0400359 if (nativeExtensions.eglImageExternal || nativeExtensions.eglStreamConsumerExternal)
Ian Ewellbda75592016-04-18 17:25:54 -0400360 {
Corentin Wallez99d492c2018-02-27 15:17:10 -0500361 Texture *zeroTextureExternal = new Texture(mImplementation.get(), 0, TextureType::External);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800362 mZeroTextures[TextureType::External].set(this, zeroTextureExternal);
Ian Ewellbda75592016-04-18 17:25:54 -0400363 }
364
Jamie Madill4928b7c2017-06-20 12:57:39 -0400365 mGLState.initializeZeroTextures(this, mZeroTextures);
Jamie Madille6382c32014-11-07 15:05:26 -0500366
Jamie Madill57a89722013-07-02 11:57:03 -0400367 bindVertexArray(0);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000368
Geoff Langeb66a6e2016-10-31 13:06:12 -0400369 if (getClientVersion() >= Version(3, 0))
Geoff Lang1a683462015-09-29 15:09:59 -0400370 {
371 // [OpenGL ES 3.0.2] section 2.14.1 pg 85:
372 // In the initial state, a default transform feedback object is bound and treated as
373 // a transform feedback object with a name of zero. That object is bound any time
374 // BindTransformFeedback is called with id of zero
Jamie Madillf0dcb8b2017-08-26 19:05:13 -0400375 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Geoff Lang1a683462015-09-29 15:09:59 -0400376 }
Geoff Langc8058452014-02-03 12:04:11 -0500377
Corentin Wallez336129f2017-10-17 15:55:40 -0400378 for (auto type : angle::AllEnums<BufferBinding>())
379 {
380 bindBuffer(type, 0);
381 }
382
383 bindRenderbuffer(GL_RENDERBUFFER, 0);
384
385 for (unsigned int i = 0; i < mCaps.maxUniformBufferBindings; i++)
386 {
387 bindBufferRange(BufferBinding::Uniform, i, 0, 0, -1);
388 }
389
Jamie Madillad9f24e2016-02-12 09:27:24 -0500390 // Initialize dirty bit masks
Jamie Madillc67323a2017-11-02 23:11:41 -0400391 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500392 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500393 // No dirty objects.
394
395 // Readpixels uses the pack state and read FBO
Jamie Madillc67323a2017-11-02 23:11:41 -0400396 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500397 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500398 mReadPixelsDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
399
400 mClearDirtyBits.set(State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED);
401 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
402 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR);
403 mClearDirtyBits.set(State::DIRTY_BIT_VIEWPORT);
404 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_COLOR);
405 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_DEPTH);
406 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_STENCIL);
407 mClearDirtyBits.set(State::DIRTY_BIT_COLOR_MASK);
408 mClearDirtyBits.set(State::DIRTY_BIT_DEPTH_MASK);
409 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT);
410 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_BACK);
411 mClearDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
412
413 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
414 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR);
Geoff Lang1d2c41d2016-10-19 16:14:46 -0700415 mBlitDirtyBits.set(State::DIRTY_BIT_FRAMEBUFFER_SRGB);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500416 mBlitDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
417 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
Jamie Madill437fa652016-05-03 15:13:24 -0400418
Xinghua Cao10a4d432017-11-28 14:46:26 +0800419 // TODO(xinghua.cao@intel.com): add other dirty bits and dirty objects.
420 mComputeDirtyBits.set(State::DIRTY_BIT_SHADER_STORAGE_BUFFER_BINDING);
421 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_BINDING);
422 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_EXECUTABLE);
423 mComputeDirtyBits.set(State::DIRTY_BIT_TEXTURE_BINDINGS);
424 mComputeDirtyBits.set(State::DIRTY_BIT_SAMPLER_BINDINGS);
Qin Jiajia62fcf622017-11-30 16:16:12 +0800425 mComputeDirtyBits.set(State::DIRTY_BIT_DISPATCH_INDIRECT_BUFFER_BINDING);
Xinghua Cao10a4d432017-11-28 14:46:26 +0800426
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400427 handleError(mImplementation->initialize());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000428}
429
Jamie Madill4928b7c2017-06-20 12:57:39 -0400430egl::Error Context::onDestroy(const egl::Display *display)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000431{
Corentin Wallez80b24112015-08-25 16:41:57 -0400432 for (auto fence : mFenceNVMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000433 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400434 SafeDelete(fence.second);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000435 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400436 mFenceNVMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000437
Corentin Wallez80b24112015-08-25 16:41:57 -0400438 for (auto query : mQueryMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000439 {
Geoff Langf0aa8422015-09-29 15:08:34 -0400440 if (query.second != nullptr)
441 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400442 query.second->release(this);
Geoff Langf0aa8422015-09-29 15:08:34 -0400443 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000444 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400445 mQueryMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000446
Corentin Wallez80b24112015-08-25 16:41:57 -0400447 for (auto vertexArray : mVertexArrayMap)
Jamie Madill57a89722013-07-02 11:57:03 -0400448 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400449 if (vertexArray.second)
450 {
451 vertexArray.second->onDestroy(this);
452 }
Jamie Madill57a89722013-07-02 11:57:03 -0400453 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400454 mVertexArrayMap.clear();
Jamie Madill57a89722013-07-02 11:57:03 -0400455
Corentin Wallez80b24112015-08-25 16:41:57 -0400456 for (auto transformFeedback : mTransformFeedbackMap)
Geoff Langc8058452014-02-03 12:04:11 -0500457 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500458 if (transformFeedback.second != nullptr)
459 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500460 transformFeedback.second->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500461 }
Geoff Langc8058452014-02-03 12:04:11 -0500462 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400463 mTransformFeedbackMap.clear();
Geoff Langc8058452014-02-03 12:04:11 -0500464
Jamie Madill5b772312018-03-08 20:28:32 -0500465 for (BindingPointer<Texture> &zeroTexture : mZeroTextures)
Geoff Lang76b10c92014-09-05 16:28:14 -0400466 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800467 if (zeroTexture.get() != nullptr)
468 {
469 ANGLE_TRY(zeroTexture->onDestroy(this));
470 zeroTexture.set(this, nullptr);
471 }
Geoff Lang76b10c92014-09-05 16:28:14 -0400472 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000473
Corentin Wallezccab69d2017-01-27 16:57:15 -0500474 SafeDelete(mSurfacelessFramebuffer);
475
Jamie Madill4928b7c2017-06-20 12:57:39 -0400476 ANGLE_TRY(releaseSurface(display));
Jamie Madill2f348d22017-06-05 10:50:59 -0400477 releaseShaderCompiler();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500478
Jamie Madill4928b7c2017-06-20 12:57:39 -0400479 mGLState.reset(this);
480
Jamie Madill6c1f6712017-02-14 19:08:04 -0500481 mState.mBuffers->release(this);
482 mState.mShaderPrograms->release(this);
483 mState.mTextures->release(this);
484 mState.mRenderbuffers->release(this);
485 mState.mSamplers->release(this);
Jamie Madill70b5bb02017-08-28 13:32:37 -0400486 mState.mSyncs->release(this);
Jamie Madill6c1f6712017-02-14 19:08:04 -0500487 mState.mPaths->release(this);
488 mState.mFramebuffers->release(this);
Yunchao Hea336b902017-08-02 16:05:21 +0800489 mState.mPipelines->release(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400490
Jamie Madill76e471e2017-10-21 09:56:01 -0400491 mImplementation->onDestroy(this);
492
Jamie Madill4928b7c2017-06-20 12:57:39 -0400493 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000494}
495
Jamie Madill70ee0f62017-02-06 16:04:20 -0500496Context::~Context()
497{
498}
499
Jamie Madill4928b7c2017-06-20 12:57:39 -0400500egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000501{
Jamie Madill61e16b42017-06-19 11:13:23 -0400502 mCurrentDisplay = display;
503
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000504 if (!mHasBeenCurrent)
505 {
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000506 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500507 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400508 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000509
Corentin Wallezc295e512017-01-27 17:47:50 -0500510 int width = 0;
511 int height = 0;
512 if (surface != nullptr)
513 {
514 width = surface->getWidth();
515 height = surface->getHeight();
516 }
517
518 mGLState.setViewportParams(0, 0, width, height);
519 mGLState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000520
521 mHasBeenCurrent = true;
522 }
523
Jamie Madill1b94d432015-08-07 13:23:23 -0400524 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700525 mGLState.setAllDirtyBits();
Jamie Madill81c2e252017-09-09 23:32:46 -0400526 mGLState.setAllDirtyObjects();
Jamie Madill1b94d432015-08-07 13:23:23 -0400527
Jamie Madill4928b7c2017-06-20 12:57:39 -0400528 ANGLE_TRY(releaseSurface(display));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500529
530 Framebuffer *newDefault = nullptr;
531 if (surface != nullptr)
532 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400533 ANGLE_TRY(surface->setIsCurrent(this, true));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500534 mCurrentSurface = surface;
535 newDefault = surface->getDefaultFramebuffer();
536 }
537 else
538 {
539 if (mSurfacelessFramebuffer == nullptr)
540 {
541 mSurfacelessFramebuffer = new Framebuffer(mImplementation.get());
542 }
543
544 newDefault = mSurfacelessFramebuffer;
545 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000546
Corentin Wallez37c39792015-08-20 14:19:46 -0400547 // Update default framebuffer, the binding of the previous default
548 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400549 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700550 if (mGLState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400551 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700552 mGLState.setReadFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400553 }
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700554 if (mGLState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400555 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700556 mGLState.setDrawFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400557 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500558 mState.mFramebuffers->setDefaultFramebuffer(newDefault);
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400559 }
Ian Ewell292f0052016-02-04 10:37:32 -0500560
561 // Notify the renderer of a context switch
Jamie Madill4928b7c2017-06-20 12:57:39 -0400562 mImplementation->onMakeCurrent(this);
563 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000564}
565
Jamie Madill4928b7c2017-06-20 12:57:39 -0400566egl::Error Context::releaseSurface(const egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400567{
Corentin Wallez37c39792015-08-20 14:19:46 -0400568 // Remove the default framebuffer
Corentin Wallezc295e512017-01-27 17:47:50 -0500569 Framebuffer *currentDefault = nullptr;
570 if (mCurrentSurface != nullptr)
Corentin Wallez51706ea2015-08-07 14:39:22 -0400571 {
Corentin Wallezc295e512017-01-27 17:47:50 -0500572 currentDefault = mCurrentSurface->getDefaultFramebuffer();
573 }
574 else if (mSurfacelessFramebuffer != nullptr)
575 {
576 currentDefault = mSurfacelessFramebuffer;
Corentin Wallez51706ea2015-08-07 14:39:22 -0400577 }
578
Corentin Wallezc295e512017-01-27 17:47:50 -0500579 if (mGLState.getReadFramebuffer() == currentDefault)
580 {
581 mGLState.setReadFramebufferBinding(nullptr);
582 }
583 if (mGLState.getDrawFramebuffer() == currentDefault)
584 {
585 mGLState.setDrawFramebufferBinding(nullptr);
586 }
587 mState.mFramebuffers->setDefaultFramebuffer(nullptr);
588
589 if (mCurrentSurface)
590 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400591 ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
Corentin Wallezc295e512017-01-27 17:47:50 -0500592 mCurrentSurface = nullptr;
593 }
Jamie Madill4928b7c2017-06-20 12:57:39 -0400594
595 return egl::NoError();
Jamie Madill77a72f62015-04-14 11:18:32 -0400596}
597
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000598GLuint Context::createBuffer()
599{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500600 return mState.mBuffers->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000601}
602
603GLuint Context::createProgram()
604{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500605 return mState.mShaderPrograms->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000606}
607
608GLuint Context::createShader(GLenum type)
609{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500610 return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000611}
612
613GLuint Context::createTexture()
614{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500615 return mState.mTextures->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000616}
617
618GLuint Context::createRenderbuffer()
619{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500620 return mState.mRenderbuffers->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000621}
622
Sami Väisänene45e53b2016-05-25 10:36:04 +0300623GLuint Context::createPaths(GLsizei range)
624{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500625 auto resultOrError = mState.mPaths->createPaths(mImplementation.get(), range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300626 if (resultOrError.isError())
627 {
628 handleError(resultOrError.getError());
629 return 0;
630 }
631 return resultOrError.getResult();
632}
633
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000634// Returns an unused framebuffer name
635GLuint Context::createFramebuffer()
636{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500637 return mState.mFramebuffers->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000638}
639
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500640void Context::genFencesNV(GLsizei n, GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000641{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500642 for (int i = 0; i < n; i++)
643 {
644 GLuint handle = mFenceNVHandleAllocator.allocate();
645 mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV()));
646 fences[i] = handle;
647 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000648}
649
Yunchao Hea336b902017-08-02 16:05:21 +0800650GLuint Context::createProgramPipeline()
651{
652 return mState.mPipelines->createProgramPipeline();
653}
654
Jiajia Qin5451d532017-11-16 17:16:34 +0800655GLuint Context::createShaderProgramv(GLenum type, GLsizei count, const GLchar *const *strings)
656{
657 UNIMPLEMENTED();
658 return 0u;
659}
660
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000661void Context::deleteBuffer(GLuint buffer)
662{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500663 if (mState.mBuffers->getBuffer(buffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000664 {
665 detachBuffer(buffer);
666 }
Jamie Madill893ab082014-05-16 16:56:10 -0400667
Jamie Madill6c1f6712017-02-14 19:08:04 -0500668 mState.mBuffers->deleteObject(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000669}
670
671void Context::deleteShader(GLuint shader)
672{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500673 mState.mShaderPrograms->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000674}
675
676void Context::deleteProgram(GLuint program)
677{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500678 mState.mShaderPrograms->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000679}
680
681void Context::deleteTexture(GLuint texture)
682{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500683 if (mState.mTextures->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000684 {
685 detachTexture(texture);
686 }
687
Jamie Madill6c1f6712017-02-14 19:08:04 -0500688 mState.mTextures->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000689}
690
691void Context::deleteRenderbuffer(GLuint renderbuffer)
692{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500693 if (mState.mRenderbuffers->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000694 {
695 detachRenderbuffer(renderbuffer);
696 }
Jamie Madill893ab082014-05-16 16:56:10 -0400697
Jamie Madill6c1f6712017-02-14 19:08:04 -0500698 mState.mRenderbuffers->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000699}
700
Jamie Madill7f0c5a42017-08-26 22:43:26 -0400701void Context::deleteSync(GLsync sync)
Jamie Madillcd055f82013-07-26 11:55:15 -0400702{
703 // The spec specifies the underlying Fence object is not deleted until all current
704 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
705 // and since our API is currently designed for being called from a single thread, we can delete
706 // the fence immediately.
Jamie Madill70b5bb02017-08-28 13:32:37 -0400707 mState.mSyncs->deleteObject(this, static_cast<GLuint>(reinterpret_cast<uintptr_t>(sync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400708}
709
Yunchao Hea336b902017-08-02 16:05:21 +0800710void Context::deleteProgramPipeline(GLuint pipeline)
711{
712 if (mState.mPipelines->getProgramPipeline(pipeline))
713 {
714 detachProgramPipeline(pipeline);
715 }
716
717 mState.mPipelines->deleteObject(this, pipeline);
718}
719
Sami Väisänene45e53b2016-05-25 10:36:04 +0300720void Context::deletePaths(GLuint first, GLsizei range)
721{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500722 mState.mPaths->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300723}
724
725bool Context::hasPathData(GLuint path) const
726{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500727 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300728 if (pathObj == nullptr)
729 return false;
730
731 return pathObj->hasPathData();
732}
733
734bool Context::hasPath(GLuint path) const
735{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500736 return mState.mPaths->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300737}
738
739void Context::setPathCommands(GLuint path,
740 GLsizei numCommands,
741 const GLubyte *commands,
742 GLsizei numCoords,
743 GLenum coordType,
744 const void *coords)
745{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500746 auto *pathObject = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300747
748 handleError(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
749}
750
Jamie Madill007530e2017-12-28 14:27:04 -0500751void Context::pathParameterf(GLuint path, GLenum pname, GLfloat value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300752{
Jamie Madill007530e2017-12-28 14:27:04 -0500753 Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300754
755 switch (pname)
756 {
757 case GL_PATH_STROKE_WIDTH_CHROMIUM:
758 pathObj->setStrokeWidth(value);
759 break;
760 case GL_PATH_END_CAPS_CHROMIUM:
761 pathObj->setEndCaps(static_cast<GLenum>(value));
762 break;
763 case GL_PATH_JOIN_STYLE_CHROMIUM:
764 pathObj->setJoinStyle(static_cast<GLenum>(value));
765 break;
766 case GL_PATH_MITER_LIMIT_CHROMIUM:
767 pathObj->setMiterLimit(value);
768 break;
769 case GL_PATH_STROKE_BOUND_CHROMIUM:
770 pathObj->setStrokeBound(value);
771 break;
772 default:
773 UNREACHABLE();
774 break;
775 }
776}
777
Jamie Madill007530e2017-12-28 14:27:04 -0500778void Context::pathParameteri(GLuint path, GLenum pname, GLint value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300779{
Jamie Madill007530e2017-12-28 14:27:04 -0500780 // TODO(jmadill): Should use proper clamping/casting.
781 pathParameterf(path, pname, static_cast<GLfloat>(value));
782}
783
784void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value)
785{
786 const Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300787
788 switch (pname)
789 {
790 case GL_PATH_STROKE_WIDTH_CHROMIUM:
791 *value = pathObj->getStrokeWidth();
792 break;
793 case GL_PATH_END_CAPS_CHROMIUM:
794 *value = static_cast<GLfloat>(pathObj->getEndCaps());
795 break;
796 case GL_PATH_JOIN_STYLE_CHROMIUM:
797 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
798 break;
799 case GL_PATH_MITER_LIMIT_CHROMIUM:
800 *value = pathObj->getMiterLimit();
801 break;
802 case GL_PATH_STROKE_BOUND_CHROMIUM:
803 *value = pathObj->getStrokeBound();
804 break;
805 default:
806 UNREACHABLE();
807 break;
808 }
809}
810
Jamie Madill007530e2017-12-28 14:27:04 -0500811void Context::getPathParameteriv(GLuint path, GLenum pname, GLint *value)
812{
813 GLfloat val = 0.0f;
814 getPathParameterfv(path, pname, value != nullptr ? &val : nullptr);
815 if (value)
816 *value = static_cast<GLint>(val);
817}
818
Sami Väisänene45e53b2016-05-25 10:36:04 +0300819void Context::setPathStencilFunc(GLenum func, GLint ref, GLuint mask)
820{
821 mGLState.setPathStencilFunc(func, ref, mask);
822}
823
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000824void Context::deleteFramebuffer(GLuint framebuffer)
825{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500826 if (mState.mFramebuffers->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000827 {
828 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000829 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500830
Jamie Madill6c1f6712017-02-14 19:08:04 -0500831 mState.mFramebuffers->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000832}
833
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500834void Context::deleteFencesNV(GLsizei n, const GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000835{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500836 for (int i = 0; i < n; i++)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000837 {
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500838 GLuint fence = fences[i];
839
840 FenceNV *fenceObject = nullptr;
841 if (mFenceNVMap.erase(fence, &fenceObject))
842 {
843 mFenceNVHandleAllocator.release(fence);
844 delete fenceObject;
845 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000846 }
847}
848
Geoff Lang70d0f492015-12-10 17:45:46 -0500849Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000850{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500851 return mState.mBuffers->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000852}
853
Jamie Madill570f7c82014-07-03 10:38:54 -0400854Texture *Context::getTexture(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000855{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500856 return mState.mTextures->getTexture(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000857}
858
Geoff Lang70d0f492015-12-10 17:45:46 -0500859Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000860{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500861 return mState.mRenderbuffers->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000862}
863
Jamie Madill70b5bb02017-08-28 13:32:37 -0400864Sync *Context::getSync(GLsync handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400865{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400866 return mState.mSyncs->getSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400867}
868
Jamie Madill57a89722013-07-02 11:57:03 -0400869VertexArray *Context::getVertexArray(GLuint handle) const
870{
Jamie Madill96a483b2017-06-27 16:49:21 -0400871 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -0400872}
873
Jamie Madilldc356042013-07-19 16:36:57 -0400874Sampler *Context::getSampler(GLuint handle) const
875{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500876 return mState.mSamplers->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400877}
878
Geoff Langc8058452014-02-03 12:04:11 -0500879TransformFeedback *Context::getTransformFeedback(GLuint handle) const
880{
Jamie Madill96a483b2017-06-27 16:49:21 -0400881 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -0500882}
883
Yunchao Hea336b902017-08-02 16:05:21 +0800884ProgramPipeline *Context::getProgramPipeline(GLuint handle) const
885{
886 return mState.mPipelines->getProgramPipeline(handle);
887}
888
Geoff Lang70d0f492015-12-10 17:45:46 -0500889LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
890{
891 switch (identifier)
892 {
893 case GL_BUFFER:
894 return getBuffer(name);
895 case GL_SHADER:
896 return getShader(name);
897 case GL_PROGRAM:
898 return getProgram(name);
899 case GL_VERTEX_ARRAY:
900 return getVertexArray(name);
901 case GL_QUERY:
902 return getQuery(name);
903 case GL_TRANSFORM_FEEDBACK:
904 return getTransformFeedback(name);
905 case GL_SAMPLER:
906 return getSampler(name);
907 case GL_TEXTURE:
908 return getTexture(name);
909 case GL_RENDERBUFFER:
910 return getRenderbuffer(name);
911 case GL_FRAMEBUFFER:
912 return getFramebuffer(name);
913 default:
914 UNREACHABLE();
915 return nullptr;
916 }
917}
918
919LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
920{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400921 return getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
Geoff Lang70d0f492015-12-10 17:45:46 -0500922}
923
Martin Radev9d901792016-07-15 15:58:58 +0300924void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
925{
926 LabeledObject *object = getLabeledObject(identifier, name);
927 ASSERT(object != nullptr);
928
929 std::string labelName = GetObjectLabelFromPointer(length, label);
930 object->setLabel(labelName);
Jamie Madill8693bdb2017-09-02 15:32:14 -0400931
932 // TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the
933 // specified object is active until we do this.
934 mGLState.setObjectDirty(identifier);
Martin Radev9d901792016-07-15 15:58:58 +0300935}
936
937void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
938{
939 LabeledObject *object = getLabeledObjectFromPtr(ptr);
940 ASSERT(object != nullptr);
941
942 std::string labelName = GetObjectLabelFromPointer(length, label);
943 object->setLabel(labelName);
944}
945
946void Context::getObjectLabel(GLenum identifier,
947 GLuint name,
948 GLsizei bufSize,
949 GLsizei *length,
950 GLchar *label) const
951{
952 LabeledObject *object = getLabeledObject(identifier, name);
953 ASSERT(object != nullptr);
954
955 const std::string &objectLabel = object->getLabel();
956 GetObjectLabelBase(objectLabel, bufSize, length, label);
957}
958
959void Context::getObjectPtrLabel(const void *ptr,
960 GLsizei bufSize,
961 GLsizei *length,
962 GLchar *label) const
963{
964 LabeledObject *object = getLabeledObjectFromPtr(ptr);
965 ASSERT(object != nullptr);
966
967 const std::string &objectLabel = object->getLabel();
968 GetObjectLabelBase(objectLabel, bufSize, length, label);
969}
970
Jamie Madilldc356042013-07-19 16:36:57 -0400971bool Context::isSampler(GLuint samplerName) const
972{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500973 return mState.mSamplers->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -0400974}
975
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800976void Context::bindTexture(TextureType target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000977{
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500978 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000979
Jamie Madilldedd7b92014-11-05 16:30:36 -0500980 if (handle == 0)
981 {
982 texture = mZeroTextures[target].get();
983 }
984 else
985 {
Corentin Wallez99d492c2018-02-27 15:17:10 -0500986 texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500987 }
988
989 ASSERT(texture);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400990 mGLState.setSamplerTexture(this, target, texture);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +0000991}
992
Jamie Madill5bf9ff42016-02-01 11:13:03 -0500993void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000994{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500995 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
996 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700997 mGLState.setReadFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000998}
999
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001000void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001001{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001002 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1003 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001004 mGLState.setDrawFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001005}
1006
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001007void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -04001008{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001009 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001010 mGLState.setVertexArrayBinding(vertexArray);
Jamie Madill57a89722013-07-02 11:57:03 -04001011}
1012
Shao80957d92017-02-20 21:25:59 +08001013void Context::bindVertexBuffer(GLuint bindingIndex,
1014 GLuint bufferHandle,
1015 GLintptr offset,
1016 GLsizei stride)
1017{
1018 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001019 mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Shao80957d92017-02-20 21:25:59 +08001020}
1021
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001022void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -04001023{
Geoff Lang76b10c92014-09-05 16:28:14 -04001024 ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -04001025 Sampler *sampler =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001026 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001027 mGLState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04001028}
1029
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001030void Context::bindImageTexture(GLuint unit,
1031 GLuint texture,
1032 GLint level,
1033 GLboolean layered,
1034 GLint layer,
1035 GLenum access,
1036 GLenum format)
1037{
1038 Texture *tex = mState.mTextures->getTexture(texture);
1039 mGLState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
1040}
1041
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001042void Context::useProgram(GLuint program)
1043{
Jamie Madill6c1f6712017-02-14 19:08:04 -05001044 mGLState.setProgram(this, getProgram(program));
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001045}
1046
Jiajia Qin5451d532017-11-16 17:16:34 +08001047void Context::useProgramStages(GLuint pipeline, GLbitfield stages, GLuint program)
1048{
1049 UNIMPLEMENTED();
1050}
1051
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001052void Context::bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001053{
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001054 ASSERT(target == GL_TRANSFORM_FEEDBACK);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001055 TransformFeedback *transformFeedback =
1056 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001057 mGLState.setTransformFeedbackBinding(this, transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -05001058}
1059
Yunchao Hea336b902017-08-02 16:05:21 +08001060void Context::bindProgramPipeline(GLuint pipelineHandle)
1061{
1062 ProgramPipeline *pipeline =
1063 mState.mPipelines->checkProgramPipelineAllocation(mImplementation.get(), pipelineHandle);
1064 mGLState.setProgramPipelineBinding(this, pipeline);
1065}
1066
Jamie Madillf0e04492017-08-26 15:28:42 -04001067void Context::beginQuery(GLenum target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001068{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001069 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001070 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001071
Geoff Lang5aad9672014-09-08 11:10:42 -04001072 // begin query
Jamie Madillf0e04492017-08-26 15:28:42 -04001073 ANGLE_CONTEXT_TRY(queryObject->begin());
Geoff Lang5aad9672014-09-08 11:10:42 -04001074
1075 // set query as active for specified target only if begin succeeded
Jamie Madill4928b7c2017-06-20 12:57:39 -04001076 mGLState.setActiveQuery(this, target, queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001077}
1078
Jamie Madillf0e04492017-08-26 15:28:42 -04001079void Context::endQuery(GLenum target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001080{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001081 Query *queryObject = mGLState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001082 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001083
Jamie Madillf0e04492017-08-26 15:28:42 -04001084 handleError(queryObject->end());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001085
Geoff Lang5aad9672014-09-08 11:10:42 -04001086 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madill4928b7c2017-06-20 12:57:39 -04001087 mGLState.setActiveQuery(this, target, nullptr);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001088}
1089
Jamie Madillf0e04492017-08-26 15:28:42 -04001090void Context::queryCounter(GLuint id, GLenum target)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001091{
1092 ASSERT(target == GL_TIMESTAMP_EXT);
1093
1094 Query *queryObject = getQuery(id, true, target);
1095 ASSERT(queryObject);
1096
Jamie Madillf0e04492017-08-26 15:28:42 -04001097 handleError(queryObject->queryCounter());
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001098}
1099
1100void Context::getQueryiv(GLenum target, GLenum pname, GLint *params)
1101{
1102 switch (pname)
1103 {
1104 case GL_CURRENT_QUERY_EXT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001105 params[0] = mGLState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001106 break;
1107 case GL_QUERY_COUNTER_BITS_EXT:
1108 switch (target)
1109 {
1110 case GL_TIME_ELAPSED_EXT:
1111 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1112 break;
1113 case GL_TIMESTAMP_EXT:
1114 params[0] = getExtensions().queryCounterBitsTimestamp;
1115 break;
1116 default:
1117 UNREACHABLE();
1118 params[0] = 0;
1119 break;
1120 }
1121 break;
1122 default:
1123 UNREACHABLE();
1124 return;
1125 }
1126}
1127
Geoff Lang2186c382016-10-14 10:54:54 -04001128void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001129{
Geoff Lang2186c382016-10-14 10:54:54 -04001130 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001131}
1132
Geoff Lang2186c382016-10-14 10:54:54 -04001133void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001134{
Geoff Lang2186c382016-10-14 10:54:54 -04001135 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001136}
1137
Geoff Lang2186c382016-10-14 10:54:54 -04001138void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001139{
Geoff Lang2186c382016-10-14 10:54:54 -04001140 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001141}
1142
Geoff Lang2186c382016-10-14 10:54:54 -04001143void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001144{
Geoff Lang2186c382016-10-14 10:54:54 -04001145 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001146}
1147
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001148Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001149{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001150 return mState.mFramebuffers->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001151}
1152
Jamie Madill2f348d22017-06-05 10:50:59 -04001153FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001154{
Jamie Madill96a483b2017-06-27 16:49:21 -04001155 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001156}
1157
Jamie Madill2f348d22017-06-05 10:50:59 -04001158Query *Context::getQuery(GLuint handle, bool create, GLenum type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001159{
Jamie Madill96a483b2017-06-27 16:49:21 -04001160 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001161 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001162 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001163 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001164
1165 Query *query = mQueryMap.query(handle);
1166 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001167 {
Jamie Madill96a483b2017-06-27 16:49:21 -04001168 query = new Query(mImplementation->createQuery(type), handle);
1169 query->addRef();
1170 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001171 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001172 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001173}
1174
Geoff Lang70d0f492015-12-10 17:45:46 -05001175Query *Context::getQuery(GLuint handle) const
1176{
Jamie Madill96a483b2017-06-27 16:49:21 -04001177 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001178}
1179
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001180Texture *Context::getTargetTexture(TextureType type) const
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001181{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001182 ASSERT(ValidTextureTarget(this, type) || ValidTextureExternalTarget(this, type));
1183 return mGLState.getTargetTexture(type);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001184}
1185
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001186Texture *Context::getSamplerTexture(unsigned int sampler, TextureType type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001187{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001188 return mGLState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001189}
1190
Geoff Lang492a7e42014-11-05 13:27:06 -05001191Compiler *Context::getCompiler() const
1192{
Jamie Madill2f348d22017-06-05 10:50:59 -04001193 if (mCompiler.get() == nullptr)
1194 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001195 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001196 }
1197 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001198}
1199
Jamie Madillc1d770e2017-04-13 17:31:24 -04001200void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001201{
1202 switch (pname)
1203 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001204 case GL_SHADER_COMPILER:
1205 *params = GL_TRUE;
1206 break;
1207 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1208 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1209 break;
1210 default:
1211 mGLState.getBooleanv(pname, params);
1212 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001213 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001214}
1215
Jamie Madillc1d770e2017-04-13 17:31:24 -04001216void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001217{
Shannon Woods53a94a82014-06-24 15:20:36 -04001218 // Queries about context capabilities and maximums are answered by Context.
1219 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001220 switch (pname)
1221 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001222 case GL_ALIASED_LINE_WIDTH_RANGE:
1223 params[0] = mCaps.minAliasedLineWidth;
1224 params[1] = mCaps.maxAliasedLineWidth;
1225 break;
1226 case GL_ALIASED_POINT_SIZE_RANGE:
1227 params[0] = mCaps.minAliasedPointSize;
1228 params[1] = mCaps.maxAliasedPointSize;
1229 break;
1230 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1231 ASSERT(mExtensions.textureFilterAnisotropic);
1232 *params = mExtensions.maxTextureAnisotropy;
1233 break;
1234 case GL_MAX_TEXTURE_LOD_BIAS:
1235 *params = mCaps.maxLODBias;
1236 break;
1237
1238 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1239 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1240 {
1241 ASSERT(mExtensions.pathRendering);
1242 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1243 memcpy(params, m, 16 * sizeof(GLfloat));
1244 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001245 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001246
Jamie Madill231c7f52017-04-26 13:45:37 -04001247 default:
1248 mGLState.getFloatv(pname, params);
1249 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001250 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001251}
1252
Jamie Madillc1d770e2017-04-13 17:31:24 -04001253void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001254{
Shannon Woods53a94a82014-06-24 15:20:36 -04001255 // Queries about context capabilities and maximums are answered by Context.
1256 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001257
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001258 switch (pname)
1259 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001260 case GL_MAX_VERTEX_ATTRIBS:
1261 *params = mCaps.maxVertexAttributes;
1262 break;
1263 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1264 *params = mCaps.maxVertexUniformVectors;
1265 break;
1266 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
1267 *params = mCaps.maxVertexUniformComponents;
1268 break;
1269 case GL_MAX_VARYING_VECTORS:
1270 *params = mCaps.maxVaryingVectors;
1271 break;
1272 case GL_MAX_VARYING_COMPONENTS:
1273 *params = mCaps.maxVertexOutputComponents;
1274 break;
1275 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1276 *params = mCaps.maxCombinedTextureImageUnits;
1277 break;
1278 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
1279 *params = mCaps.maxVertexTextureImageUnits;
1280 break;
1281 case GL_MAX_TEXTURE_IMAGE_UNITS:
1282 *params = mCaps.maxTextureImageUnits;
1283 break;
1284 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1285 *params = mCaps.maxFragmentUniformVectors;
1286 break;
1287 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
1288 *params = mCaps.maxFragmentUniformComponents;
1289 break;
1290 case GL_MAX_RENDERBUFFER_SIZE:
1291 *params = mCaps.maxRenderbufferSize;
1292 break;
1293 case GL_MAX_COLOR_ATTACHMENTS_EXT:
1294 *params = mCaps.maxColorAttachments;
1295 break;
1296 case GL_MAX_DRAW_BUFFERS_EXT:
1297 *params = mCaps.maxDrawBuffers;
1298 break;
1299 // case GL_FRAMEBUFFER_BINDING: // now equivalent to
1300 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
1301 case GL_SUBPIXEL_BITS:
1302 *params = 4;
1303 break;
1304 case GL_MAX_TEXTURE_SIZE:
1305 *params = mCaps.max2DTextureSize;
1306 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001307 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
1308 *params = mCaps.maxRectangleTextureSize;
1309 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001310 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1311 *params = mCaps.maxCubeMapTextureSize;
1312 break;
1313 case GL_MAX_3D_TEXTURE_SIZE:
1314 *params = mCaps.max3DTextureSize;
1315 break;
1316 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1317 *params = mCaps.maxArrayTextureLayers;
1318 break;
1319 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1320 *params = mCaps.uniformBufferOffsetAlignment;
1321 break;
1322 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1323 *params = mCaps.maxUniformBufferBindings;
1324 break;
1325 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
1326 *params = mCaps.maxVertexUniformBlocks;
1327 break;
1328 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
1329 *params = mCaps.maxFragmentUniformBlocks;
1330 break;
1331 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1332 *params = mCaps.maxCombinedTextureImageUnits;
1333 break;
1334 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1335 *params = mCaps.maxVertexOutputComponents;
1336 break;
1337 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1338 *params = mCaps.maxFragmentInputComponents;
1339 break;
1340 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1341 *params = mCaps.minProgramTexelOffset;
1342 break;
1343 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1344 *params = mCaps.maxProgramTexelOffset;
1345 break;
1346 case GL_MAJOR_VERSION:
1347 *params = getClientVersion().major;
1348 break;
1349 case GL_MINOR_VERSION:
1350 *params = getClientVersion().minor;
1351 break;
1352 case GL_MAX_ELEMENTS_INDICES:
1353 *params = mCaps.maxElementsIndices;
1354 break;
1355 case GL_MAX_ELEMENTS_VERTICES:
1356 *params = mCaps.maxElementsVertices;
1357 break;
1358 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1359 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1360 break;
1361 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1362 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1363 break;
1364 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1365 *params = mCaps.maxTransformFeedbackSeparateComponents;
1366 break;
1367 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1368 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1369 break;
1370 case GL_MAX_SAMPLES_ANGLE:
1371 *params = mCaps.maxSamples;
1372 break;
1373 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001374 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001375 params[0] = mCaps.maxViewportWidth;
1376 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001377 }
1378 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001379 case GL_COMPRESSED_TEXTURE_FORMATS:
1380 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1381 params);
1382 break;
1383 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1384 *params = mResetStrategy;
1385 break;
1386 case GL_NUM_SHADER_BINARY_FORMATS:
1387 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1388 break;
1389 case GL_SHADER_BINARY_FORMATS:
1390 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1391 break;
1392 case GL_NUM_PROGRAM_BINARY_FORMATS:
1393 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1394 break;
1395 case GL_PROGRAM_BINARY_FORMATS:
1396 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1397 break;
1398 case GL_NUM_EXTENSIONS:
1399 *params = static_cast<GLint>(mExtensionStrings.size());
1400 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001401
Jamie Madill231c7f52017-04-26 13:45:37 -04001402 // GL_KHR_debug
1403 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1404 *params = mExtensions.maxDebugMessageLength;
1405 break;
1406 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1407 *params = mExtensions.maxDebugLoggedMessages;
1408 break;
1409 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1410 *params = mExtensions.maxDebugGroupStackDepth;
1411 break;
1412 case GL_MAX_LABEL_LENGTH:
1413 *params = mExtensions.maxLabelLength;
1414 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001415
Martin Radeve5285d22017-07-14 16:23:53 +03001416 // GL_ANGLE_multiview
1417 case GL_MAX_VIEWS_ANGLE:
1418 *params = mExtensions.maxViews;
1419 break;
1420
Jamie Madill231c7f52017-04-26 13:45:37 -04001421 // GL_EXT_disjoint_timer_query
1422 case GL_GPU_DISJOINT_EXT:
1423 *params = mImplementation->getGPUDisjoint();
1424 break;
1425 case GL_MAX_FRAMEBUFFER_WIDTH:
1426 *params = mCaps.maxFramebufferWidth;
1427 break;
1428 case GL_MAX_FRAMEBUFFER_HEIGHT:
1429 *params = mCaps.maxFramebufferHeight;
1430 break;
1431 case GL_MAX_FRAMEBUFFER_SAMPLES:
1432 *params = mCaps.maxFramebufferSamples;
1433 break;
1434 case GL_MAX_SAMPLE_MASK_WORDS:
1435 *params = mCaps.maxSampleMaskWords;
1436 break;
1437 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1438 *params = mCaps.maxColorTextureSamples;
1439 break;
1440 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1441 *params = mCaps.maxDepthTextureSamples;
1442 break;
1443 case GL_MAX_INTEGER_SAMPLES:
1444 *params = mCaps.maxIntegerSamples;
1445 break;
1446 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1447 *params = mCaps.maxVertexAttribRelativeOffset;
1448 break;
1449 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1450 *params = mCaps.maxVertexAttribBindings;
1451 break;
1452 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1453 *params = mCaps.maxVertexAttribStride;
1454 break;
1455 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
1456 *params = mCaps.maxVertexAtomicCounterBuffers;
1457 break;
1458 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
1459 *params = mCaps.maxVertexAtomicCounters;
1460 break;
1461 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
1462 *params = mCaps.maxVertexImageUniforms;
1463 break;
1464 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
1465 *params = mCaps.maxVertexShaderStorageBlocks;
1466 break;
1467 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
1468 *params = mCaps.maxFragmentAtomicCounterBuffers;
1469 break;
1470 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
1471 *params = mCaps.maxFragmentAtomicCounters;
1472 break;
1473 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
1474 *params = mCaps.maxFragmentImageUniforms;
1475 break;
1476 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
1477 *params = mCaps.maxFragmentShaderStorageBlocks;
1478 break;
1479 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1480 *params = mCaps.minProgramTextureGatherOffset;
1481 break;
1482 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1483 *params = mCaps.maxProgramTextureGatherOffset;
1484 break;
1485 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1486 *params = mCaps.maxComputeWorkGroupInvocations;
1487 break;
1488 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
1489 *params = mCaps.maxComputeUniformBlocks;
1490 break;
1491 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
1492 *params = mCaps.maxComputeTextureImageUnits;
1493 break;
1494 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1495 *params = mCaps.maxComputeSharedMemorySize;
1496 break;
1497 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
1498 *params = mCaps.maxComputeUniformComponents;
1499 break;
1500 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
1501 *params = mCaps.maxComputeAtomicCounterBuffers;
1502 break;
1503 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
1504 *params = mCaps.maxComputeAtomicCounters;
1505 break;
1506 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
1507 *params = mCaps.maxComputeImageUniforms;
1508 break;
1509 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
1510 *params = mCaps.maxCombinedComputeUniformComponents;
1511 break;
1512 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
1513 *params = mCaps.maxComputeShaderStorageBlocks;
1514 break;
1515 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1516 *params = mCaps.maxCombinedShaderOutputResources;
1517 break;
1518 case GL_MAX_UNIFORM_LOCATIONS:
1519 *params = mCaps.maxUniformLocations;
1520 break;
1521 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1522 *params = mCaps.maxAtomicCounterBufferBindings;
1523 break;
1524 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1525 *params = mCaps.maxAtomicCounterBufferSize;
1526 break;
1527 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1528 *params = mCaps.maxCombinedAtomicCounterBuffers;
1529 break;
1530 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1531 *params = mCaps.maxCombinedAtomicCounters;
1532 break;
1533 case GL_MAX_IMAGE_UNITS:
1534 *params = mCaps.maxImageUnits;
1535 break;
1536 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1537 *params = mCaps.maxCombinedImageUniforms;
1538 break;
1539 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1540 *params = mCaps.maxShaderStorageBufferBindings;
1541 break;
1542 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1543 *params = mCaps.maxCombinedShaderStorageBlocks;
1544 break;
1545 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1546 *params = mCaps.shaderStorageBufferOffsetAlignment;
1547 break;
Jiawei Shao361df072017-11-22 09:33:59 +08001548
1549 // GL_EXT_geometry_shader
1550 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
1551 *params = mCaps.maxFramebufferLayers;
1552 break;
1553 case GL_LAYER_PROVOKING_VERTEX_EXT:
1554 *params = mCaps.layerProvokingVertex;
1555 break;
1556 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
1557 *params = mCaps.maxGeometryUniformComponents;
1558 break;
1559 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
1560 *params = mCaps.maxGeometryUniformBlocks;
1561 break;
1562 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
1563 *params = mCaps.maxCombinedGeometryUniformComponents;
1564 break;
1565 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
1566 *params = mCaps.maxGeometryInputComponents;
1567 break;
1568 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
1569 *params = mCaps.maxGeometryOutputComponents;
1570 break;
1571 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
1572 *params = mCaps.maxGeometryOutputVertices;
1573 break;
1574 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
1575 *params = mCaps.maxGeometryTotalOutputComponents;
1576 break;
1577 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
1578 *params = mCaps.maxGeometryShaderInvocations;
1579 break;
1580 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
1581 *params = mCaps.maxGeometryTextureImageUnits;
1582 break;
1583 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
1584 *params = mCaps.maxGeometryAtomicCounterBuffers;
1585 break;
1586 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
1587 *params = mCaps.maxGeometryAtomicCounters;
1588 break;
1589 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
1590 *params = mCaps.maxGeometryImageUniforms;
1591 break;
1592 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
1593 *params = mCaps.maxGeometryShaderStorageBlocks;
1594 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001595 default:
Jamie Madille98b1b52018-03-08 09:47:23 -05001596 handleError(mGLState.getIntegerv(this, pname, params));
Jamie Madill231c7f52017-04-26 13:45:37 -04001597 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001598 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001599}
1600
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001601void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001602{
Shannon Woods53a94a82014-06-24 15:20:36 -04001603 // Queries about context capabilities and maximums are answered by Context.
1604 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001605 switch (pname)
1606 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001607 case GL_MAX_ELEMENT_INDEX:
1608 *params = mCaps.maxElementIndex;
1609 break;
1610 case GL_MAX_UNIFORM_BLOCK_SIZE:
1611 *params = mCaps.maxUniformBlockSize;
1612 break;
1613 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
1614 *params = mCaps.maxCombinedVertexUniformComponents;
1615 break;
1616 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
1617 *params = mCaps.maxCombinedFragmentUniformComponents;
1618 break;
1619 case GL_MAX_SERVER_WAIT_TIMEOUT:
1620 *params = mCaps.maxServerWaitTimeout;
1621 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001622
Jamie Madill231c7f52017-04-26 13:45:37 -04001623 // GL_EXT_disjoint_timer_query
1624 case GL_TIMESTAMP_EXT:
1625 *params = mImplementation->getTimestamp();
1626 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001627
Jamie Madill231c7f52017-04-26 13:45:37 -04001628 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1629 *params = mCaps.maxShaderStorageBlockSize;
1630 break;
1631 default:
1632 UNREACHABLE();
1633 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001634 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001635}
1636
Geoff Lang70d0f492015-12-10 17:45:46 -05001637void Context::getPointerv(GLenum pname, void **params) const
1638{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001639 mGLState.getPointerv(pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001640}
1641
Martin Radev66fb8202016-07-28 11:45:20 +03001642void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001643{
Shannon Woods53a94a82014-06-24 15:20:36 -04001644 // Queries about context capabilities and maximums are answered by Context.
1645 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001646
1647 GLenum nativeType;
1648 unsigned int numParams;
1649 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1650 ASSERT(queryStatus);
1651
1652 if (nativeType == GL_INT)
1653 {
1654 switch (target)
1655 {
1656 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1657 ASSERT(index < 3u);
1658 *data = mCaps.maxComputeWorkGroupCount[index];
1659 break;
1660 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1661 ASSERT(index < 3u);
1662 *data = mCaps.maxComputeWorkGroupSize[index];
1663 break;
1664 default:
1665 mGLState.getIntegeri_v(target, index, data);
1666 }
1667 }
1668 else
1669 {
1670 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1671 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001672}
1673
Martin Radev66fb8202016-07-28 11:45:20 +03001674void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001675{
Shannon Woods53a94a82014-06-24 15:20:36 -04001676 // Queries about context capabilities and maximums are answered by Context.
1677 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001678
1679 GLenum nativeType;
1680 unsigned int numParams;
1681 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1682 ASSERT(queryStatus);
1683
1684 if (nativeType == GL_INT_64_ANGLEX)
1685 {
1686 mGLState.getInteger64i_v(target, index, data);
1687 }
1688 else
1689 {
1690 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1691 }
1692}
1693
1694void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1695{
1696 // Queries about context capabilities and maximums are answered by Context.
1697 // Queries about current GL state values are answered by State.
1698
1699 GLenum nativeType;
1700 unsigned int numParams;
1701 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1702 ASSERT(queryStatus);
1703
1704 if (nativeType == GL_BOOL)
1705 {
1706 mGLState.getBooleani_v(target, index, data);
1707 }
1708 else
1709 {
1710 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1711 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001712}
1713
Corentin Wallez336129f2017-10-17 15:55:40 -04001714void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001715{
1716 Buffer *buffer = mGLState.getTargetBuffer(target);
1717 QueryBufferParameteriv(buffer, pname, params);
1718}
1719
1720void Context::getFramebufferAttachmentParameteriv(GLenum target,
1721 GLenum attachment,
1722 GLenum pname,
1723 GLint *params)
1724{
1725 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08001726 QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08001727}
1728
1729void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
1730{
1731 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
1732 QueryRenderbufferiv(this, renderbuffer, pname, params);
1733}
1734
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001735void Context::getTexParameterfv(TextureType target, GLenum pname, GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001736{
1737 Texture *texture = getTargetTexture(target);
1738 QueryTexParameterfv(texture, pname, params);
1739}
1740
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001741void Context::getTexParameteriv(TextureType target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001742{
1743 Texture *texture = getTargetTexture(target);
1744 QueryTexParameteriv(texture, pname, params);
1745}
Jiajia Qin5451d532017-11-16 17:16:34 +08001746
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001747void Context::getTexLevelParameteriv(TextureTarget target, GLint level, GLenum pname, GLint *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08001748{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001749 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05001750 QueryTexLevelParameteriv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08001751}
1752
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001753void Context::getTexLevelParameterfv(TextureTarget target,
1754 GLint level,
1755 GLenum pname,
1756 GLfloat *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08001757{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001758 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05001759 QueryTexLevelParameterfv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08001760}
1761
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001762void Context::texParameterf(TextureType target, GLenum pname, GLfloat param)
He Yunchao010e4db2017-03-03 14:22:06 +08001763{
1764 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001765 SetTexParameterf(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04001766 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001767}
1768
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001769void Context::texParameterfv(TextureType target, GLenum pname, const GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001770{
1771 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001772 SetTexParameterfv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04001773 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001774}
1775
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001776void Context::texParameteri(TextureType target, GLenum pname, GLint param)
He Yunchao010e4db2017-03-03 14:22:06 +08001777{
1778 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001779 SetTexParameteri(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04001780 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001781}
1782
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001783void Context::texParameteriv(TextureType target, GLenum pname, const GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001784{
1785 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001786 SetTexParameteriv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04001787 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001788}
1789
Jamie Madill675fe712016-12-19 13:07:54 -05001790void Context::drawArrays(GLenum mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001791{
Jamie Madill9fdaa492018-02-16 10:52:11 -05001792 // No-op if zero count
1793 if (count == 0)
1794 {
1795 return;
1796 }
1797
Jamie Madill05b35b22017-10-03 09:01:44 -04001798 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001799 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
1800 MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001801}
1802
Jamie Madill675fe712016-12-19 13:07:54 -05001803void Context::drawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04001804{
Jamie Madill9fdaa492018-02-16 10:52:11 -05001805 // No-op if zero count
1806 if (count == 0 || instanceCount == 0)
1807 {
1808 return;
1809 }
1810
Jamie Madill05b35b22017-10-03 09:01:44 -04001811 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001812 ANGLE_CONTEXT_TRY(
1813 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
1814 MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback());
Geoff Langf6db0982015-08-25 13:04:00 -04001815}
1816
Jamie Madill876429b2017-04-20 15:46:24 -04001817void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001818{
Jamie Madill9fdaa492018-02-16 10:52:11 -05001819 // No-op if zero count
1820 if (count == 0)
1821 {
1822 return;
1823 }
1824
Jamie Madill05b35b22017-10-03 09:01:44 -04001825 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001826 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04001827}
1828
Jamie Madill675fe712016-12-19 13:07:54 -05001829void Context::drawElementsInstanced(GLenum mode,
1830 GLsizei count,
1831 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04001832 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04001833 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04001834{
Jamie Madill9fdaa492018-02-16 10:52:11 -05001835 // No-op if zero count
1836 if (count == 0 || instances == 0)
1837 {
1838 return;
1839 }
1840
Jamie Madill05b35b22017-10-03 09:01:44 -04001841 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001842 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08001843 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04001844}
1845
Jamie Madill675fe712016-12-19 13:07:54 -05001846void Context::drawRangeElements(GLenum mode,
1847 GLuint start,
1848 GLuint end,
1849 GLsizei count,
1850 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04001851 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04001852{
Jamie Madill9fdaa492018-02-16 10:52:11 -05001853 // No-op if zero count
1854 if (count == 0)
1855 {
1856 return;
1857 }
1858
Jamie Madill05b35b22017-10-03 09:01:44 -04001859 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001860 ANGLE_CONTEXT_TRY(
1861 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001862}
1863
Jamie Madill876429b2017-04-20 15:46:24 -04001864void Context::drawArraysIndirect(GLenum mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08001865{
Jamie Madill05b35b22017-10-03 09:01:44 -04001866 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001867 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08001868}
1869
Jamie Madill876429b2017-04-20 15:46:24 -04001870void Context::drawElementsIndirect(GLenum mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08001871{
Jamie Madill05b35b22017-10-03 09:01:44 -04001872 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001873 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08001874}
1875
Jamie Madill675fe712016-12-19 13:07:54 -05001876void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001877{
Jamie Madillafa02a22017-11-23 12:57:38 -05001878 handleError(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05001879}
1880
Jamie Madill675fe712016-12-19 13:07:54 -05001881void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05001882{
Jamie Madillafa02a22017-11-23 12:57:38 -05001883 handleError(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001884}
1885
Austin Kinross6ee1e782015-05-29 17:05:37 -07001886void Context::insertEventMarker(GLsizei length, const char *marker)
1887{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001888 ASSERT(mImplementation);
1889 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07001890}
1891
1892void Context::pushGroupMarker(GLsizei length, const char *marker)
1893{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001894 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05001895
1896 if (marker == nullptr)
1897 {
1898 // From the EXT_debug_marker spec,
1899 // "If <marker> is null then an empty string is pushed on the stack."
1900 mImplementation->pushGroupMarker(length, "");
1901 }
1902 else
1903 {
1904 mImplementation->pushGroupMarker(length, marker);
1905 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07001906}
1907
1908void Context::popGroupMarker()
1909{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001910 ASSERT(mImplementation);
1911 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07001912}
1913
Geoff Langd8605522016-04-13 10:19:12 -04001914void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
1915{
1916 Program *programObject = getProgram(program);
1917 ASSERT(programObject);
1918
1919 programObject->bindUniformLocation(location, name);
1920}
1921
Sami Väisänena797e062016-05-12 15:23:40 +03001922void Context::setCoverageModulation(GLenum components)
1923{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001924 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03001925}
1926
Sami Väisänene45e53b2016-05-25 10:36:04 +03001927void Context::loadPathRenderingMatrix(GLenum matrixMode, const GLfloat *matrix)
1928{
1929 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
1930}
1931
1932void Context::loadPathRenderingIdentityMatrix(GLenum matrixMode)
1933{
1934 GLfloat I[16];
1935 angle::Matrix<GLfloat>::setToIdentity(I);
1936
1937 mGLState.loadPathRenderingMatrix(matrixMode, I);
1938}
1939
1940void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
1941{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001942 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001943 if (!pathObj)
1944 return;
1945
1946 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05001947 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03001948
1949 mImplementation->stencilFillPath(pathObj, fillMode, mask);
1950}
1951
1952void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
1953{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001954 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001955 if (!pathObj)
1956 return;
1957
1958 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05001959 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03001960
1961 mImplementation->stencilStrokePath(pathObj, reference, mask);
1962}
1963
1964void Context::coverFillPath(GLuint path, GLenum coverMode)
1965{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001966 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001967 if (!pathObj)
1968 return;
1969
1970 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05001971 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03001972
1973 mImplementation->coverFillPath(pathObj, coverMode);
1974}
1975
1976void Context::coverStrokePath(GLuint path, GLenum coverMode)
1977{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001978 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001979 if (!pathObj)
1980 return;
1981
1982 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05001983 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03001984
1985 mImplementation->coverStrokePath(pathObj, coverMode);
1986}
1987
1988void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
1989{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001990 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001991 if (!pathObj)
1992 return;
1993
1994 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05001995 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03001996
1997 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
1998}
1999
2000void Context::stencilThenCoverStrokePath(GLuint path,
2001 GLint reference,
2002 GLuint mask,
2003 GLenum coverMode)
2004{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002005 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002006 if (!pathObj)
2007 return;
2008
2009 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002010 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002011
2012 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2013}
2014
Sami Väisänend59ca052016-06-21 16:10:00 +03002015void Context::coverFillPathInstanced(GLsizei numPaths,
2016 GLenum pathNameType,
2017 const void *paths,
2018 GLuint pathBase,
2019 GLenum coverMode,
2020 GLenum transformType,
2021 const GLfloat *transformValues)
2022{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002023 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002024
2025 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002026 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002027
2028 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2029}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002030
Sami Väisänend59ca052016-06-21 16:10:00 +03002031void Context::coverStrokePathInstanced(GLsizei numPaths,
2032 GLenum pathNameType,
2033 const void *paths,
2034 GLuint pathBase,
2035 GLenum coverMode,
2036 GLenum transformType,
2037 const GLfloat *transformValues)
2038{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002039 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002040
2041 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002042 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002043
2044 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2045 transformValues);
2046}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002047
Sami Väisänend59ca052016-06-21 16:10:00 +03002048void Context::stencilFillPathInstanced(GLsizei numPaths,
2049 GLenum pathNameType,
2050 const void *paths,
2051 GLuint pathBase,
2052 GLenum fillMode,
2053 GLuint mask,
2054 GLenum transformType,
2055 const GLfloat *transformValues)
2056{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002057 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002058
2059 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002060 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002061
2062 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2063 transformValues);
2064}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002065
Sami Väisänend59ca052016-06-21 16:10:00 +03002066void Context::stencilStrokePathInstanced(GLsizei numPaths,
2067 GLenum pathNameType,
2068 const void *paths,
2069 GLuint pathBase,
2070 GLint reference,
2071 GLuint mask,
2072 GLenum transformType,
2073 const GLfloat *transformValues)
2074{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002075 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002076
2077 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002078 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002079
2080 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2081 transformValues);
2082}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002083
Sami Väisänend59ca052016-06-21 16:10:00 +03002084void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2085 GLenum pathNameType,
2086 const void *paths,
2087 GLuint pathBase,
2088 GLenum fillMode,
2089 GLuint mask,
2090 GLenum coverMode,
2091 GLenum transformType,
2092 const GLfloat *transformValues)
2093{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002094 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002095
2096 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002097 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002098
2099 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2100 transformType, transformValues);
2101}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002102
Sami Väisänend59ca052016-06-21 16:10:00 +03002103void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2104 GLenum pathNameType,
2105 const void *paths,
2106 GLuint pathBase,
2107 GLint reference,
2108 GLuint mask,
2109 GLenum coverMode,
2110 GLenum transformType,
2111 const GLfloat *transformValues)
2112{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002113 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002114
2115 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002116 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002117
2118 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2119 transformType, transformValues);
2120}
2121
Sami Väisänen46eaa942016-06-29 10:26:37 +03002122void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2123{
2124 auto *programObject = getProgram(program);
2125
2126 programObject->bindFragmentInputLocation(location, name);
2127}
2128
2129void Context::programPathFragmentInputGen(GLuint program,
2130 GLint location,
2131 GLenum genMode,
2132 GLint components,
2133 const GLfloat *coeffs)
2134{
2135 auto *programObject = getProgram(program);
2136
Jamie Madillbd044ed2017-06-05 12:59:21 -04002137 programObject->pathFragmentInputGen(this, location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002138}
2139
jchen1015015f72017-03-16 13:54:21 +08002140GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2141{
jchen10fd7c3b52017-03-21 15:36:03 +08002142 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002143 return QueryProgramResourceIndex(programObject, programInterface, name);
2144}
2145
jchen10fd7c3b52017-03-21 15:36:03 +08002146void Context::getProgramResourceName(GLuint program,
2147 GLenum programInterface,
2148 GLuint index,
2149 GLsizei bufSize,
2150 GLsizei *length,
2151 GLchar *name)
2152{
2153 const auto *programObject = getProgram(program);
2154 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2155}
2156
jchen10191381f2017-04-11 13:59:04 +08002157GLint Context::getProgramResourceLocation(GLuint program,
2158 GLenum programInterface,
2159 const GLchar *name)
2160{
2161 const auto *programObject = getProgram(program);
2162 return QueryProgramResourceLocation(programObject, programInterface, name);
2163}
2164
jchen10880683b2017-04-12 16:21:55 +08002165void Context::getProgramResourceiv(GLuint program,
2166 GLenum programInterface,
2167 GLuint index,
2168 GLsizei propCount,
2169 const GLenum *props,
2170 GLsizei bufSize,
2171 GLsizei *length,
2172 GLint *params)
2173{
2174 const auto *programObject = getProgram(program);
2175 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2176 length, params);
2177}
2178
jchen10d9cd7b72017-08-30 15:04:25 +08002179void Context::getProgramInterfaceiv(GLuint program,
2180 GLenum programInterface,
2181 GLenum pname,
2182 GLint *params)
2183{
2184 const auto *programObject = getProgram(program);
2185 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2186}
2187
Jamie Madill71c88b32017-09-14 22:20:29 -04002188void Context::handleError(const Error &error)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002189{
Geoff Langda5777c2014-07-11 09:52:58 -04002190 if (error.isError())
2191 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002192 GLenum code = error.getCode();
2193 mErrors.insert(code);
2194 if (code == GL_OUT_OF_MEMORY && getWorkarounds().loseContextOnOutOfMemory)
2195 {
2196 markContextLost();
2197 }
Geoff Lang70d0f492015-12-10 17:45:46 -05002198
Geoff Langee6884e2017-11-09 16:51:11 -05002199 ASSERT(!error.getMessage().empty());
2200 mGLState.getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, error.getID(),
2201 GL_DEBUG_SEVERITY_HIGH, error.getMessage());
Geoff Langda5777c2014-07-11 09:52:58 -04002202 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002203}
2204
2205// Get one of the recorded errors and clear its flag, if any.
2206// [OpenGL ES 2.0.24] section 2.5 page 13.
2207GLenum Context::getError()
2208{
Geoff Langda5777c2014-07-11 09:52:58 -04002209 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002210 {
Geoff Langda5777c2014-07-11 09:52:58 -04002211 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002212 }
Geoff Langda5777c2014-07-11 09:52:58 -04002213 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002214 {
Geoff Langda5777c2014-07-11 09:52:58 -04002215 GLenum error = *mErrors.begin();
2216 mErrors.erase(mErrors.begin());
2217 return error;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002218 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002219}
2220
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002221// NOTE: this function should not assume that this context is current!
2222void Context::markContextLost()
2223{
2224 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002225 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002226 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002227 mContextLostForced = true;
2228 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002229 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002230}
2231
2232bool Context::isContextLost()
2233{
2234 return mContextLost;
2235}
2236
Jamie Madillfa920eb2018-01-04 11:45:50 -05002237GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002238{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002239 // Even if the application doesn't want to know about resets, we want to know
2240 // as it will allow us to skip all the calls.
2241 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002242 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002243 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002244 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002245 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002246 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002247
2248 // EXT_robustness, section 2.6: If the reset notification behavior is
2249 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2250 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2251 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002252 }
2253
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002254 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2255 // status should be returned at least once, and GL_NO_ERROR should be returned
2256 // once the device has finished resetting.
2257 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002258 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002259 ASSERT(mResetStatus == GL_NO_ERROR);
2260 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002261
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002262 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002263 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002264 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002265 }
2266 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002267 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002268 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002269 // If markContextLost was used to mark the context lost then
2270 // assume that is not recoverable, and continue to report the
2271 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002272 mResetStatus = mImplementation->getResetStatus();
2273 }
Jamie Madill893ab082014-05-16 16:56:10 -04002274
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002275 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002276}
2277
2278bool Context::isResetNotificationEnabled()
2279{
2280 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2281}
2282
Corentin Walleze3b10e82015-05-20 11:06:25 -04002283const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002284{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002285 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002286}
2287
2288EGLenum Context::getClientType() const
2289{
2290 return mClientType;
2291}
2292
2293EGLenum Context::getRenderBuffer() const
2294{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002295 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2296 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002297 {
2298 return EGL_NONE;
2299 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002300
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002301 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002302 ASSERT(backAttachment != nullptr);
2303 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002304}
2305
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002306VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002307{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002308 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002309 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2310 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002311 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002312 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2313 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002314
Jamie Madill96a483b2017-06-27 16:49:21 -04002315 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002316 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002317
2318 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002319}
2320
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002321TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002322{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002323 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002324 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2325 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002326 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002327 transformFeedback =
2328 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002329 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002330 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002331 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002332
2333 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002334}
2335
2336bool Context::isVertexArrayGenerated(GLuint vertexArray)
2337{
Jamie Madill96a483b2017-06-27 16:49:21 -04002338 ASSERT(mVertexArrayMap.contains(0));
2339 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002340}
2341
2342bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2343{
Jamie Madill96a483b2017-06-27 16:49:21 -04002344 ASSERT(mTransformFeedbackMap.contains(0));
2345 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002346}
2347
Shannon Woods53a94a82014-06-24 15:20:36 -04002348void Context::detachTexture(GLuint texture)
2349{
2350 // Simple pass-through to State's detachTexture method, as textures do not require
2351 // allocation map management either here or in the resource manager at detach time.
2352 // Zero textures are held by the Context, and we don't attempt to request them from
2353 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002354 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002355}
2356
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002357void Context::detachBuffer(GLuint buffer)
2358{
Yuly Novikov5807a532015-12-03 13:01:22 -05002359 // Simple pass-through to State's detachBuffer method, since
2360 // only buffer attachments to container objects that are bound to the current context
2361 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002362
Yuly Novikov5807a532015-12-03 13:01:22 -05002363 // [OpenGL ES 3.2] section 5.1.2 page 45:
2364 // Attachments to unbound container objects, such as
2365 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2366 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002367 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002368}
2369
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002370void Context::detachFramebuffer(GLuint framebuffer)
2371{
Shannon Woods53a94a82014-06-24 15:20:36 -04002372 // Framebuffer detachment is handled by Context, because 0 is a valid
2373 // Framebuffer object, and a pointer to it must be passed from Context
2374 // to State at binding time.
2375
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002376 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002377 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2378 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2379 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002380
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002381 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002382 {
2383 bindReadFramebuffer(0);
2384 }
2385
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002386 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002387 {
2388 bindDrawFramebuffer(0);
2389 }
2390}
2391
2392void Context::detachRenderbuffer(GLuint renderbuffer)
2393{
Jamie Madilla02315b2017-02-23 14:14:47 -05002394 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002395}
2396
Jamie Madill57a89722013-07-02 11:57:03 -04002397void Context::detachVertexArray(GLuint vertexArray)
2398{
Jamie Madill77a72f62015-04-14 11:18:32 -04002399 // Vertex array detachment is handled by Context, because 0 is a valid
2400 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002401 // binding time.
2402
Jamie Madill57a89722013-07-02 11:57:03 -04002403 // [OpenGL ES 3.0.2] section 2.10 page 43:
2404 // If a vertex array object that is currently bound is deleted, the binding
2405 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002406 if (mGLState.removeVertexArrayBinding(vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002407 {
2408 bindVertexArray(0);
2409 }
2410}
2411
Geoff Langc8058452014-02-03 12:04:11 -05002412void Context::detachTransformFeedback(GLuint transformFeedback)
2413{
Corentin Walleza2257da2016-04-19 16:43:12 -04002414 // Transform feedback detachment is handled by Context, because 0 is a valid
2415 // transform feedback, and a pointer to it must be passed from Context to State at
2416 // binding time.
2417
2418 // The OpenGL specification doesn't mention what should happen when the currently bound
2419 // transform feedback object is deleted. Since it is a container object, we treat it like
2420 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002421 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002422 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002423 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002424 }
Geoff Langc8058452014-02-03 12:04:11 -05002425}
2426
Jamie Madilldc356042013-07-19 16:36:57 -04002427void Context::detachSampler(GLuint sampler)
2428{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002429 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002430}
2431
Yunchao Hea336b902017-08-02 16:05:21 +08002432void Context::detachProgramPipeline(GLuint pipeline)
2433{
2434 mGLState.detachProgramPipeline(this, pipeline);
2435}
2436
Jamie Madill3ef140a2017-08-26 23:11:21 -04002437void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002438{
Shaodde78e82017-05-22 14:13:27 +08002439 mGLState.setVertexAttribDivisor(this, index, divisor);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002440}
2441
Jamie Madille29d1672013-07-19 16:36:57 -04002442void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2443{
Geoff Langc1984ed2016-10-07 12:41:00 -04002444 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002445 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002446 SetSamplerParameteri(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002447 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002448}
Jamie Madille29d1672013-07-19 16:36:57 -04002449
Geoff Langc1984ed2016-10-07 12:41:00 -04002450void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2451{
2452 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002453 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002454 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002455 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002456}
2457
2458void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2459{
Geoff Langc1984ed2016-10-07 12:41:00 -04002460 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002461 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002462 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002463 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002464}
2465
Geoff Langc1984ed2016-10-07 12:41:00 -04002466void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002467{
Geoff Langc1984ed2016-10-07 12:41:00 -04002468 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002469 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002470 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002471 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002472}
2473
Geoff Langc1984ed2016-10-07 12:41:00 -04002474void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002475{
Geoff Langc1984ed2016-10-07 12:41:00 -04002476 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002477 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002478 QuerySamplerParameteriv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002479 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002480}
Jamie Madill9675b802013-07-19 16:36:59 -04002481
Geoff Langc1984ed2016-10-07 12:41:00 -04002482void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2483{
2484 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002485 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002486 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002487 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002488}
2489
Olli Etuahof0fee072016-03-30 15:11:58 +03002490void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2491{
2492 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002493 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002494}
2495
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002496void Context::initRendererString()
2497{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002498 std::ostringstream rendererString;
2499 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002500 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002501 rendererString << ")";
2502
Geoff Langcec35902014-04-16 10:52:36 -04002503 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002504}
2505
Geoff Langc339c4e2016-11-29 10:37:36 -05002506void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002507{
Geoff Langc339c4e2016-11-29 10:37:36 -05002508 const Version &clientVersion = getClientVersion();
2509
2510 std::ostringstream versionString;
2511 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2512 << ANGLE_VERSION_STRING << ")";
2513 mVersionString = MakeStaticString(versionString.str());
2514
2515 std::ostringstream shadingLanguageVersionString;
2516 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2517 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2518 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2519 << ")";
2520 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002521}
2522
Geoff Langcec35902014-04-16 10:52:36 -04002523void Context::initExtensionStrings()
2524{
Geoff Langc339c4e2016-11-29 10:37:36 -05002525 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2526 std::ostringstream combinedStringStream;
2527 std::copy(strings.begin(), strings.end(),
2528 std::ostream_iterator<const char *>(combinedStringStream, " "));
2529 return MakeStaticString(combinedStringStream.str());
2530 };
2531
2532 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002533 for (const auto &extensionString : mExtensions.getStrings())
2534 {
2535 mExtensionStrings.push_back(MakeStaticString(extensionString));
2536 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002537 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002538
Bryan Bernhart58806562017-01-05 13:09:31 -08002539 const gl::Extensions &nativeExtensions = mImplementation->getNativeExtensions();
2540
Geoff Langc339c4e2016-11-29 10:37:36 -05002541 mRequestableExtensionStrings.clear();
2542 for (const auto &extensionInfo : GetExtensionInfoMap())
2543 {
2544 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08002545 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
2546 nativeExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002547 {
2548 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
2549 }
2550 }
2551 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002552}
2553
Geoff Langc339c4e2016-11-29 10:37:36 -05002554const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04002555{
Geoff Langc339c4e2016-11-29 10:37:36 -05002556 switch (name)
2557 {
2558 case GL_VENDOR:
2559 return reinterpret_cast<const GLubyte *>("Google Inc.");
2560
2561 case GL_RENDERER:
2562 return reinterpret_cast<const GLubyte *>(mRendererString);
2563
2564 case GL_VERSION:
2565 return reinterpret_cast<const GLubyte *>(mVersionString);
2566
2567 case GL_SHADING_LANGUAGE_VERSION:
2568 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
2569
2570 case GL_EXTENSIONS:
2571 return reinterpret_cast<const GLubyte *>(mExtensionString);
2572
2573 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2574 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
2575
2576 default:
2577 UNREACHABLE();
2578 return nullptr;
2579 }
Geoff Langcec35902014-04-16 10:52:36 -04002580}
2581
Geoff Langc339c4e2016-11-29 10:37:36 -05002582const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04002583{
Geoff Langc339c4e2016-11-29 10:37:36 -05002584 switch (name)
2585 {
2586 case GL_EXTENSIONS:
2587 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
2588
2589 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2590 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
2591
2592 default:
2593 UNREACHABLE();
2594 return nullptr;
2595 }
Geoff Langcec35902014-04-16 10:52:36 -04002596}
2597
2598size_t Context::getExtensionStringCount() const
2599{
2600 return mExtensionStrings.size();
2601}
2602
Geoff Lang111a99e2017-10-17 10:58:41 -04002603bool Context::isExtensionRequestable(const char *name)
2604{
2605 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2606 auto extension = extensionInfos.find(name);
2607
2608 const Extensions &nativeExtensions = mImplementation->getNativeExtensions();
2609 return extension != extensionInfos.end() && extension->second.Requestable &&
2610 nativeExtensions.*(extension->second.ExtensionsMember);
2611}
2612
Geoff Langc339c4e2016-11-29 10:37:36 -05002613void Context::requestExtension(const char *name)
2614{
2615 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2616 ASSERT(extensionInfos.find(name) != extensionInfos.end());
2617 const auto &extension = extensionInfos.at(name);
2618 ASSERT(extension.Requestable);
Geoff Lang111a99e2017-10-17 10:58:41 -04002619 ASSERT(mImplementation->getNativeExtensions().*(extension.ExtensionsMember));
Geoff Langc339c4e2016-11-29 10:37:36 -05002620
2621 if (mExtensions.*(extension.ExtensionsMember))
2622 {
2623 // Extension already enabled
2624 return;
2625 }
2626
2627 mExtensions.*(extension.ExtensionsMember) = true;
2628 updateCaps();
2629 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08002630
Jamie Madill2f348d22017-06-05 10:50:59 -04002631 // Release the shader compiler so it will be re-created with the requested extensions enabled.
2632 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04002633
Jamie Madill81c2e252017-09-09 23:32:46 -04002634 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
2635 // sampleable.
Jamie Madilld4442552018-02-27 22:03:47 -05002636 mState.mTextures->signalAllTexturesDirty(this);
Geoff Lang9aded172017-04-05 11:07:56 -04002637 for (auto &zeroTexture : mZeroTextures)
2638 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002639 if (zeroTexture.get() != nullptr)
2640 {
2641 zeroTexture->signalDirty(this, InitState::Initialized);
2642 }
Geoff Lang9aded172017-04-05 11:07:56 -04002643 }
2644
2645 mState.mFramebuffers->invalidateFramebufferComplenessCache();
Geoff Langc339c4e2016-11-29 10:37:36 -05002646}
2647
2648size_t Context::getRequestableExtensionStringCount() const
2649{
2650 return mRequestableExtensionStrings.size();
2651}
2652
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002653void Context::beginTransformFeedback(GLenum primitiveMode)
2654{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002655 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002656 ASSERT(transformFeedback != nullptr);
2657 ASSERT(!transformFeedback->isPaused());
2658
Jamie Madill6c1f6712017-02-14 19:08:04 -05002659 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002660}
2661
2662bool Context::hasActiveTransformFeedback(GLuint program) const
2663{
2664 for (auto pair : mTransformFeedbackMap)
2665 {
2666 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
2667 {
2668 return true;
2669 }
2670 }
2671 return false;
2672}
2673
Geoff Langb433e872017-10-05 14:01:47 -04002674void Context::initCaps(const egl::DisplayExtensions &displayExtensions, bool robustResourceInit)
Geoff Lang493daf52014-07-03 13:38:44 -04002675{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002676 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04002677
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08002678 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
2679 if (getClientVersion() < Version(2, 0))
2680 {
2681 mCaps.maxMultitextureUnits = 4;
2682 mCaps.maxClipPlanes = 6;
2683 mCaps.maxLights = 8;
2684 mCaps.maxModelviewMatrixStackDepth = 16;
2685 mCaps.maxProjectionMatrixStackDepth = 16;
2686 mCaps.maxTextureMatrixStackDepth = 16;
2687 }
2688
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002689 mExtensions = mImplementation->getNativeExtensions();
Geoff Lang493daf52014-07-03 13:38:44 -04002690
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002691 mLimitations = mImplementation->getNativeLimitations();
Austin Kinross02df7962015-07-01 10:03:42 -07002692
Geoff Langeb66a6e2016-10-31 13:06:12 -04002693 if (getClientVersion() < Version(3, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002694 {
2695 // Disable ES3+ extensions
Jamie Madill231c7f52017-04-26 13:45:37 -04002696 mExtensions.colorBufferFloat = false;
Geoff Langb66a9092016-05-16 15:59:14 -04002697 mExtensions.eglImageExternalEssl3 = false;
Vincent Lang25ab4512016-05-13 18:13:59 +02002698 mExtensions.textureNorm16 = false;
Martin Radev137032d2017-07-13 10:11:12 +03002699 mExtensions.multiview = false;
2700 mExtensions.maxViews = 1u;
Geoff Lang493daf52014-07-03 13:38:44 -04002701 }
2702
Jiawei Shao89be29a2017-11-06 14:36:45 +08002703 if (getClientVersion() < ES_3_1)
2704 {
2705 // Disable ES3.1+ extensions
2706 mExtensions.geometryShader = false;
2707 }
2708
Geoff Langeb66a6e2016-10-31 13:06:12 -04002709 if (getClientVersion() > Version(2, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002710 {
2711 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
Jamie Madill231c7f52017-04-26 13:45:37 -04002712 // mExtensions.sRGB = false;
Geoff Lang493daf52014-07-03 13:38:44 -04002713 }
2714
Jamie Madill00ed7a12016-05-19 13:13:38 -04002715 // Some extensions are always available because they are implemented in the GL layer.
Jamie Madill231c7f52017-04-26 13:45:37 -04002716 mExtensions.bindUniformLocation = true;
2717 mExtensions.vertexArrayObject = true;
Geoff Langf41a7152016-09-19 15:11:17 -04002718 mExtensions.bindGeneratesResource = true;
Geoff Langfeb8c682017-02-13 16:07:35 -05002719 mExtensions.clientArrays = true;
Geoff Langc339c4e2016-11-29 10:37:36 -05002720 mExtensions.requestExtension = true;
Jamie Madill00ed7a12016-05-19 13:13:38 -04002721
2722 // Enable the no error extension if the context was created with the flag.
2723 mExtensions.noError = mSkipValidation;
2724
Corentin Wallezccab69d2017-01-27 16:57:15 -05002725 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Corentin Wallezc295e512017-01-27 17:47:50 -05002726 mExtensions.surfacelessContext = displayExtensions.surfacelessContext;
Corentin Wallezccab69d2017-01-27 16:57:15 -05002727
Geoff Lang70d0f492015-12-10 17:45:46 -05002728 // Explicitly enable GL_KHR_debug
2729 mExtensions.debug = true;
2730 mExtensions.maxDebugMessageLength = 1024;
2731 mExtensions.maxDebugLoggedMessages = 1024;
2732 mExtensions.maxDebugGroupStackDepth = 1024;
2733 mExtensions.maxLabelLength = 1024;
2734
Geoff Langff5b2d52016-09-07 11:32:23 -04002735 // Explicitly enable GL_ANGLE_robust_client_memory
2736 mExtensions.robustClientMemory = true;
2737
Jamie Madille08a1d32017-03-07 17:24:06 -05002738 // Determine robust resource init availability from EGL.
Geoff Langb433e872017-10-05 14:01:47 -04002739 mExtensions.robustResourceInitialization = robustResourceInit;
Jamie Madille08a1d32017-03-07 17:24:06 -05002740
Jiajia Qin8a7b3a02017-08-25 16:05:48 +08002741 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
2742 // supports it.
2743 mExtensions.robustBufferAccessBehavior =
2744 mRobustAccess && mExtensions.robustBufferAccessBehavior;
2745
Jamie Madillc43be722017-07-13 16:22:14 -04002746 // Enable the cache control query unconditionally.
2747 mExtensions.programCacheControl = true;
2748
Geoff Lang301d1612014-07-09 10:34:37 -04002749 // Apply implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04002750 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002751
Jamie Madill0f80ed82017-09-19 00:24:56 -04002752 if (getClientVersion() < ES_3_1)
2753 {
2754 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
2755 }
2756 else
2757 {
2758 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
2759 }
Geoff Lang301d1612014-07-09 10:34:37 -04002760
Jamie Madill0f80ed82017-09-19 00:24:56 -04002761 LimitCap(&mCaps.maxVertexUniformBlocks, IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
2762 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
2763 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
2764
2765 // Limit textures as well, so we can use fast bitsets with texture bindings.
2766 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
2767 LimitCap(&mCaps.maxVertexTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
2768 LimitCap(&mCaps.maxTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04002769
Jiawei Shaodb342272017-09-27 10:21:45 +08002770 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
2771
Geoff Langc287ea62016-09-16 14:46:51 -04002772 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002773 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04002774 for (const auto &extensionInfo : GetExtensionInfoMap())
2775 {
2776 // If this context is for WebGL, disable all enableable extensions
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002777 if (mWebGLContext && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04002778 {
2779 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
2780 }
2781 }
2782
2783 // Generate texture caps
2784 updateCaps();
2785}
2786
2787void Context::updateCaps()
2788{
Geoff Lang900013c2014-07-07 11:32:19 -04002789 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002790 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04002791
Jamie Madill7b62cf92017-11-02 15:20:49 -04002792 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04002793 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04002794 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04002795 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04002796
Geoff Lang0d8b7242015-09-09 14:56:53 -04002797 // Update the format caps based on the client version and extensions.
2798 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
2799 // ES3.
2800 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002801 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002802 formatCaps.renderable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002803 formatCaps.renderable && formatInfo.renderSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002804 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002805 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04002806
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002807 // OpenGL ES does not support multisampling with non-rendererable formats
2808 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Olli Etuaho50c562d2017-06-06 14:43:30 +03002809 if (!formatCaps.renderable ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002810 (getClientVersion() < ES_3_1 &&
2811 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04002812 {
Geoff Langd87878e2014-09-19 15:42:59 -04002813 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04002814 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03002815 else
2816 {
2817 // We may have limited the max samples for some required renderbuffer formats due to
2818 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
2819 GLuint formatMaxSamples = formatCaps.getMaxSamples();
2820
2821 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
2822 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
2823 // exception of signed and unsigned integer formats."
2824 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
2825 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
2826 {
2827 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
2828 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
2829 }
2830
2831 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
2832 if (getClientVersion() >= ES_3_1)
2833 {
2834 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
2835 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
2836 // the exception that the signed and unsigned integer formats are required only to
2837 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
2838 // multisamples, which must be at least one."
2839 if (formatInfo.componentType == GL_INT ||
2840 formatInfo.componentType == GL_UNSIGNED_INT)
2841 {
2842 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
2843 }
2844
2845 // GLES 3.1 section 19.3.1.
2846 if (formatCaps.texturable)
2847 {
2848 if (formatInfo.depthBits > 0)
2849 {
2850 mCaps.maxDepthTextureSamples =
2851 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
2852 }
2853 else if (formatInfo.redBits > 0)
2854 {
2855 mCaps.maxColorTextureSamples =
2856 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
2857 }
2858 }
2859 }
2860 }
Geoff Langd87878e2014-09-19 15:42:59 -04002861
2862 if (formatCaps.texturable && formatInfo.compressed)
2863 {
Geoff Langca271392017-04-05 12:30:00 -04002864 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04002865 }
2866
Geoff Langca271392017-04-05 12:30:00 -04002867 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04002868 }
Jamie Madill32447362017-06-28 14:53:52 -04002869
2870 // If program binary is disabled, blank out the memory cache pointer.
2871 if (!mImplementation->getNativeExtensions().getProgramBinary)
2872 {
2873 mMemoryProgramCache = nullptr;
2874 }
Corentin Walleze4477002017-12-01 14:39:58 -05002875
2876 // Compute which buffer types are allowed
2877 mValidBufferBindings.reset();
2878 mValidBufferBindings.set(BufferBinding::ElementArray);
2879 mValidBufferBindings.set(BufferBinding::Array);
2880
2881 if (mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
2882 {
2883 mValidBufferBindings.set(BufferBinding::PixelPack);
2884 mValidBufferBindings.set(BufferBinding::PixelUnpack);
2885 }
2886
2887 if (getClientVersion() >= ES_3_0)
2888 {
2889 mValidBufferBindings.set(BufferBinding::CopyRead);
2890 mValidBufferBindings.set(BufferBinding::CopyWrite);
2891 mValidBufferBindings.set(BufferBinding::TransformFeedback);
2892 mValidBufferBindings.set(BufferBinding::Uniform);
2893 }
2894
2895 if (getClientVersion() >= ES_3_1)
2896 {
2897 mValidBufferBindings.set(BufferBinding::AtomicCounter);
2898 mValidBufferBindings.set(BufferBinding::ShaderStorage);
2899 mValidBufferBindings.set(BufferBinding::DrawIndirect);
2900 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
2901 }
Geoff Lang493daf52014-07-03 13:38:44 -04002902}
2903
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002904void Context::initWorkarounds()
2905{
Jamie Madill761b02c2017-06-23 16:27:06 -04002906 // Apply back-end workarounds.
2907 mImplementation->applyNativeWorkarounds(&mWorkarounds);
2908
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002909 // Lose the context upon out of memory error if the application is
2910 // expecting to watch for those events.
2911 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2912}
2913
Jamie Madill05b35b22017-10-03 09:01:44 -04002914Error Context::prepareForDraw()
2915{
Geoff Langa8cb2872018-03-09 16:09:40 -05002916 ANGLE_TRY(syncDirtyObjects());
Jamie Madilla59fc192017-11-02 12:57:58 -04002917
2918 if (isRobustResourceInitEnabled())
2919 {
2920 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
2921 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
2922 }
2923
Geoff Langa8cb2872018-03-09 16:09:40 -05002924 ANGLE_TRY(syncDirtyBits());
Geoff Langd4fff502017-09-22 11:28:28 -04002925 return NoError();
2926}
2927
2928Error Context::prepareForClear(GLbitfield mask)
2929{
Geoff Langa8cb2872018-03-09 16:09:40 -05002930 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04002931 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearAttachmentsInitialized(this, mask));
Geoff Langa8cb2872018-03-09 16:09:40 -05002932 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04002933 return NoError();
2934}
2935
2936Error Context::prepareForClearBuffer(GLenum buffer, GLint drawbuffer)
2937{
Geoff Langa8cb2872018-03-09 16:09:40 -05002938 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04002939 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearBufferAttachmentsInitialized(this, buffer,
2940 drawbuffer));
Geoff Langa8cb2872018-03-09 16:09:40 -05002941 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill05b35b22017-10-03 09:01:44 -04002942 return NoError();
2943}
2944
Geoff Langa8cb2872018-03-09 16:09:40 -05002945Error Context::syncState()
Jamie Madill1b94d432015-08-07 13:23:23 -04002946{
Geoff Langa8cb2872018-03-09 16:09:40 -05002947 ANGLE_TRY(syncDirtyObjects());
2948 ANGLE_TRY(syncDirtyBits());
Jamie Madillbc918e72018-03-08 09:47:21 -05002949 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04002950}
2951
Geoff Langa8cb2872018-03-09 16:09:40 -05002952Error Context::syncState(const State::DirtyBits &bitMask, const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04002953{
Geoff Langa8cb2872018-03-09 16:09:40 -05002954 ANGLE_TRY(syncDirtyObjects(objectMask));
2955 ANGLE_TRY(syncDirtyBits(bitMask));
Geoff Langd4fff502017-09-22 11:28:28 -04002956 return NoError();
2957}
2958
Geoff Langa8cb2872018-03-09 16:09:40 -05002959Error Context::syncDirtyBits()
Geoff Langd4fff502017-09-22 11:28:28 -04002960{
2961 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
2962 mImplementation->syncState(this, dirtyBits);
2963 mGLState.clearDirtyBits();
2964 return NoError();
2965}
2966
Geoff Langa8cb2872018-03-09 16:09:40 -05002967Error Context::syncDirtyBits(const State::DirtyBits &bitMask)
Geoff Langd4fff502017-09-22 11:28:28 -04002968{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002969 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madillfe548342017-06-19 11:13:24 -04002970 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002971 mGLState.clearDirtyBits(dirtyBits);
Jamie Madillbc918e72018-03-08 09:47:21 -05002972 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04002973}
Jamie Madillc29968b2016-01-20 11:17:23 -05002974
Geoff Langa8cb2872018-03-09 16:09:40 -05002975Error Context::syncDirtyObjects()
Geoff Langd4fff502017-09-22 11:28:28 -04002976{
2977 return mGLState.syncDirtyObjects(this);
2978}
2979
Geoff Langa8cb2872018-03-09 16:09:40 -05002980Error Context::syncDirtyObjects(const State::DirtyObjects &objectMask)
Geoff Langd4fff502017-09-22 11:28:28 -04002981{
2982 return mGLState.syncDirtyObjects(this, objectMask);
2983}
2984
Jamie Madillc29968b2016-01-20 11:17:23 -05002985void Context::blitFramebuffer(GLint srcX0,
2986 GLint srcY0,
2987 GLint srcX1,
2988 GLint srcY1,
2989 GLint dstX0,
2990 GLint dstY0,
2991 GLint dstX1,
2992 GLint dstY1,
2993 GLbitfield mask,
2994 GLenum filter)
2995{
Qin Jiajiaaef92162018-02-27 13:51:44 +08002996 if (mask == 0)
2997 {
2998 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
2999 // buffers are copied.
3000 return;
3001 }
3002
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003003 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003004 ASSERT(drawFramebuffer);
3005
3006 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
3007 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
3008
Jamie Madillbc918e72018-03-08 09:47:21 -05003009 ANGLE_CONTEXT_TRY(syncStateForBlit());
Jamie Madillc29968b2016-01-20 11:17:23 -05003010
Jamie Madillc564c072017-06-01 12:45:42 -04003011 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003012}
Jamie Madillc29968b2016-01-20 11:17:23 -05003013
3014void Context::clear(GLbitfield mask)
3015{
Geoff Langd4fff502017-09-22 11:28:28 -04003016 ANGLE_CONTEXT_TRY(prepareForClear(mask));
3017 ANGLE_CONTEXT_TRY(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05003018}
3019
3020void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
3021{
Geoff Langd4fff502017-09-22 11:28:28 -04003022 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3023 ANGLE_CONTEXT_TRY(
3024 mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003025}
3026
3027void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3028{
Geoff Langd4fff502017-09-22 11:28:28 -04003029 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3030 ANGLE_CONTEXT_TRY(
3031 mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003032}
3033
3034void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3035{
Geoff Langd4fff502017-09-22 11:28:28 -04003036 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3037 ANGLE_CONTEXT_TRY(
3038 mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003039}
3040
3041void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3042{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003043 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003044 ASSERT(framebufferObject);
3045
3046 // If a buffer is not present, the clear has no effect
3047 if (framebufferObject->getDepthbuffer() == nullptr &&
3048 framebufferObject->getStencilbuffer() == nullptr)
3049 {
3050 return;
3051 }
3052
Geoff Langd4fff502017-09-22 11:28:28 -04003053 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3054 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003055}
3056
3057void Context::readPixels(GLint x,
3058 GLint y,
3059 GLsizei width,
3060 GLsizei height,
3061 GLenum format,
3062 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003063 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003064{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003065 if (width == 0 || height == 0)
3066 {
3067 return;
3068 }
3069
Jamie Madillbc918e72018-03-08 09:47:21 -05003070 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003071
Jamie Madillb6664922017-07-25 12:55:04 -04003072 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3073 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003074
3075 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04003076 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003077}
3078
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003079void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003080 GLint level,
3081 GLenum internalformat,
3082 GLint x,
3083 GLint y,
3084 GLsizei width,
3085 GLsizei height,
3086 GLint border)
3087{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003088 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003089 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003090
Jamie Madillc29968b2016-01-20 11:17:23 -05003091 Rectangle sourceArea(x, y, width, height);
3092
Jamie Madill05b35b22017-10-03 09:01:44 -04003093 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003094 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003095 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003096}
3097
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003098void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003099 GLint level,
3100 GLint xoffset,
3101 GLint yoffset,
3102 GLint x,
3103 GLint y,
3104 GLsizei width,
3105 GLsizei height)
3106{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003107 if (width == 0 || height == 0)
3108 {
3109 return;
3110 }
3111
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003112 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003113 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003114
Jamie Madillc29968b2016-01-20 11:17:23 -05003115 Offset destOffset(xoffset, yoffset, 0);
3116 Rectangle sourceArea(x, y, width, height);
3117
Jamie Madill05b35b22017-10-03 09:01:44 -04003118 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003119 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003120 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003121}
3122
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003123void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003124 GLint level,
3125 GLint xoffset,
3126 GLint yoffset,
3127 GLint zoffset,
3128 GLint x,
3129 GLint y,
3130 GLsizei width,
3131 GLsizei height)
3132{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003133 if (width == 0 || height == 0)
3134 {
3135 return;
3136 }
3137
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003138 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003139 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003140
Jamie Madillc29968b2016-01-20 11:17:23 -05003141 Offset destOffset(xoffset, yoffset, zoffset);
3142 Rectangle sourceArea(x, y, width, height);
3143
Jamie Madill05b35b22017-10-03 09:01:44 -04003144 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3145 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003146 handleError(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level, destOffset,
3147 sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003148}
3149
3150void Context::framebufferTexture2D(GLenum target,
3151 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003152 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003153 GLuint texture,
3154 GLint level)
3155{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003156 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003157 ASSERT(framebuffer);
3158
3159 if (texture != 0)
3160 {
3161 Texture *textureObj = getTexture(texture);
3162
3163 ImageIndex index = ImageIndex::MakeInvalid();
3164
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003165 if (textarget == TextureTarget::_2D)
Jamie Madillc29968b2016-01-20 11:17:23 -05003166 {
3167 index = ImageIndex::Make2D(level);
3168 }
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003169 else if (textarget == TextureTarget::Rectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -04003170 {
3171 index = ImageIndex::MakeRectangle(level);
3172 }
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003173 else if (textarget == TextureTarget::_2DMultisample)
JiangYizhoubddc46b2016-12-09 09:50:51 +08003174 {
3175 ASSERT(level == 0);
3176 index = ImageIndex::Make2DMultisample();
3177 }
Jamie Madillc29968b2016-01-20 11:17:23 -05003178 else
3179 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003180 ASSERT(TextureTargetToType(textarget) == TextureType::CubeMap);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003181 index = ImageIndex::MakeCube(textarget, level);
Jamie Madillc29968b2016-01-20 11:17:23 -05003182 }
3183
Jamie Madilla02315b2017-02-23 14:14:47 -05003184 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003185 }
3186 else
3187 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003188 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003189 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003190
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003191 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003192}
3193
3194void Context::framebufferRenderbuffer(GLenum target,
3195 GLenum attachment,
3196 GLenum renderbuffertarget,
3197 GLuint renderbuffer)
3198{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003199 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003200 ASSERT(framebuffer);
3201
3202 if (renderbuffer != 0)
3203 {
3204 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003205
3206 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex::MakeInvalid(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003207 renderbufferObject);
3208 }
3209 else
3210 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003211 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003212 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003213
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003214 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003215}
3216
3217void Context::framebufferTextureLayer(GLenum target,
3218 GLenum attachment,
3219 GLuint texture,
3220 GLint level,
3221 GLint layer)
3222{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003223 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003224 ASSERT(framebuffer);
3225
3226 if (texture != 0)
3227 {
3228 Texture *textureObject = getTexture(texture);
3229
3230 ImageIndex index = ImageIndex::MakeInvalid();
3231
Corentin Wallez99d492c2018-02-27 15:17:10 -05003232 if (textureObject->getType() == TextureType::_3D)
Jamie Madillc29968b2016-01-20 11:17:23 -05003233 {
3234 index = ImageIndex::Make3D(level, layer);
3235 }
3236 else
3237 {
Corentin Wallez99d492c2018-02-27 15:17:10 -05003238 ASSERT(textureObject->getType() == TextureType::_2DArray);
Jamie Madillc29968b2016-01-20 11:17:23 -05003239 index = ImageIndex::Make2DArray(level, layer);
3240 }
3241
Jamie Madilla02315b2017-02-23 14:14:47 -05003242 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003243 }
3244 else
3245 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003246 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003247 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003248
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003249 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003250}
3251
Martin Radev137032d2017-07-13 10:11:12 +03003252void Context::framebufferTextureMultiviewLayeredANGLE(GLenum target,
3253 GLenum attachment,
3254 GLuint texture,
3255 GLint level,
3256 GLint baseViewIndex,
3257 GLsizei numViews)
3258{
Martin Radev82ef7742017-08-08 17:44:58 +03003259 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3260 ASSERT(framebuffer);
3261
3262 if (texture != 0)
3263 {
3264 Texture *textureObj = getTexture(texture);
3265
Martin Radev18b75ba2017-08-15 15:50:40 +03003266 ImageIndex index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
Martin Radev82ef7742017-08-08 17:44:58 +03003267 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3268 numViews, baseViewIndex);
3269 }
3270 else
3271 {
3272 framebuffer->resetAttachment(this, attachment);
3273 }
3274
3275 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003276}
3277
3278void Context::framebufferTextureMultiviewSideBySideANGLE(GLenum target,
3279 GLenum attachment,
3280 GLuint texture,
3281 GLint level,
3282 GLsizei numViews,
3283 const GLint *viewportOffsets)
3284{
Martin Radev5dae57b2017-07-14 16:15:55 +03003285 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3286 ASSERT(framebuffer);
3287
3288 if (texture != 0)
3289 {
3290 Texture *textureObj = getTexture(texture);
3291
3292 ImageIndex index = ImageIndex::Make2D(level);
3293 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3294 textureObj, numViews, viewportOffsets);
3295 }
3296 else
3297 {
3298 framebuffer->resetAttachment(this, attachment);
3299 }
3300
3301 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003302}
3303
Jamie Madillc29968b2016-01-20 11:17:23 -05003304void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3305{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003306 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003307 ASSERT(framebuffer);
3308 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003309 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003310}
3311
3312void Context::readBuffer(GLenum mode)
3313{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003314 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003315 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003316 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003317}
3318
3319void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3320{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003321 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003322 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003323
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003324 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003325 ASSERT(framebuffer);
3326
3327 // The specification isn't clear what should be done when the framebuffer isn't complete.
3328 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003329 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003330}
3331
3332void Context::invalidateFramebuffer(GLenum target,
3333 GLsizei numAttachments,
3334 const GLenum *attachments)
3335{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003336 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003337 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003338
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003339 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003340 ASSERT(framebuffer);
3341
Jamie Madille98b1b52018-03-08 09:47:23 -05003342 bool complete = false;
3343 ANGLE_CONTEXT_TRY(framebuffer->isComplete(this, &complete));
3344 if (!complete)
Jamie Madillc29968b2016-01-20 11:17:23 -05003345 {
Jamie Madill437fa652016-05-03 15:13:24 -04003346 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003347 }
Jamie Madill437fa652016-05-03 15:13:24 -04003348
Jamie Madill4928b7c2017-06-20 12:57:39 -04003349 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003350}
3351
3352void Context::invalidateSubFramebuffer(GLenum target,
3353 GLsizei numAttachments,
3354 const GLenum *attachments,
3355 GLint x,
3356 GLint y,
3357 GLsizei width,
3358 GLsizei height)
3359{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003360 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003361 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003362
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003363 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003364 ASSERT(framebuffer);
3365
Jamie Madille98b1b52018-03-08 09:47:23 -05003366 bool complete = false;
3367 ANGLE_CONTEXT_TRY(framebuffer->isComplete(this, &complete));
3368 if (!complete)
Jamie Madillc29968b2016-01-20 11:17:23 -05003369 {
Jamie Madill437fa652016-05-03 15:13:24 -04003370 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003371 }
Jamie Madill437fa652016-05-03 15:13:24 -04003372
3373 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003374 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003375}
3376
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003377void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003378 GLint level,
3379 GLint internalformat,
3380 GLsizei width,
3381 GLsizei height,
3382 GLint border,
3383 GLenum format,
3384 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003385 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003386{
Jamie Madillbc918e72018-03-08 09:47:21 -05003387 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003388
3389 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003390 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003391 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3392 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003393}
3394
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003395void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003396 GLint level,
3397 GLint internalformat,
3398 GLsizei width,
3399 GLsizei height,
3400 GLsizei depth,
3401 GLint border,
3402 GLenum format,
3403 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003404 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003405{
Jamie Madillbc918e72018-03-08 09:47:21 -05003406 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003407
3408 Extents size(width, height, depth);
3409 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003410 handleError(texture->setImage(this, mGLState.getUnpackState(),
3411 NonCubeTextureTypeToTarget(target), level, internalformat, size,
3412 format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003413}
3414
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003415void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003416 GLint level,
3417 GLint xoffset,
3418 GLint yoffset,
3419 GLsizei width,
3420 GLsizei height,
3421 GLenum format,
3422 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003423 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003424{
3425 // Zero sized uploads are valid but no-ops
3426 if (width == 0 || height == 0)
3427 {
3428 return;
3429 }
3430
Jamie Madillbc918e72018-03-08 09:47:21 -05003431 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003432
3433 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003434 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003435 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3436 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003437}
3438
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003439void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003440 GLint level,
3441 GLint xoffset,
3442 GLint yoffset,
3443 GLint zoffset,
3444 GLsizei width,
3445 GLsizei height,
3446 GLsizei depth,
3447 GLenum format,
3448 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003449 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003450{
3451 // Zero sized uploads are valid but no-ops
3452 if (width == 0 || height == 0 || depth == 0)
3453 {
3454 return;
3455 }
3456
Jamie Madillbc918e72018-03-08 09:47:21 -05003457 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003458
3459 Box area(xoffset, yoffset, zoffset, width, height, depth);
3460 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003461 handleError(texture->setSubImage(this, mGLState.getUnpackState(),
3462 NonCubeTextureTypeToTarget(target), level, area, format, type,
3463 reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003464}
3465
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003466void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003467 GLint level,
3468 GLenum internalformat,
3469 GLsizei width,
3470 GLsizei height,
3471 GLint border,
3472 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003473 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003474{
Jamie Madillbc918e72018-03-08 09:47:21 -05003475 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003476
3477 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003478 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003479 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
3480 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003481 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003482}
3483
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003484void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003485 GLint level,
3486 GLenum internalformat,
3487 GLsizei width,
3488 GLsizei height,
3489 GLsizei depth,
3490 GLint border,
3491 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003492 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003493{
Jamie Madillbc918e72018-03-08 09:47:21 -05003494 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003495
3496 Extents size(width, height, depth);
3497 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003498 handleError(texture->setCompressedImage(
3499 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
3500 size, imageSize, reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003501}
3502
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003503void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003504 GLint level,
3505 GLint xoffset,
3506 GLint yoffset,
3507 GLsizei width,
3508 GLsizei height,
3509 GLenum format,
3510 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003511 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003512{
Jamie Madillbc918e72018-03-08 09:47:21 -05003513 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003514
3515 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003516 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003517 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
3518 format, imageSize,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003519 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003520}
3521
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003522void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003523 GLint level,
3524 GLint xoffset,
3525 GLint yoffset,
3526 GLint zoffset,
3527 GLsizei width,
3528 GLsizei height,
3529 GLsizei depth,
3530 GLenum format,
3531 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003532 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003533{
3534 // Zero sized uploads are valid but no-ops
3535 if (width == 0 || height == 0)
3536 {
3537 return;
3538 }
3539
Jamie Madillbc918e72018-03-08 09:47:21 -05003540 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003541
3542 Box area(xoffset, yoffset, zoffset, width, height, depth);
3543 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003544 handleError(texture->setCompressedSubImage(
3545 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
3546 imageSize, reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003547}
3548
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003549void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003550{
3551 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003552 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003553}
3554
Jamie Madill007530e2017-12-28 14:27:04 -05003555void Context::copyTexture(GLuint sourceId,
3556 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05003557 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05003558 GLuint destId,
3559 GLint destLevel,
3560 GLint internalFormat,
3561 GLenum destType,
3562 GLboolean unpackFlipY,
3563 GLboolean unpackPremultiplyAlpha,
3564 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07003565{
Jamie Madillbc918e72018-03-08 09:47:21 -05003566 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07003567
3568 gl::Texture *sourceTexture = getTexture(sourceId);
3569 gl::Texture *destTexture = getTexture(destId);
Geoff Lang92019432017-11-20 13:09:34 -05003570 handleError(destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType,
3571 sourceLevel, ConvertToBool(unpackFlipY),
3572 ConvertToBool(unpackPremultiplyAlpha),
3573 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003574}
3575
Jamie Madill007530e2017-12-28 14:27:04 -05003576void Context::copySubTexture(GLuint sourceId,
3577 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05003578 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05003579 GLuint destId,
3580 GLint destLevel,
3581 GLint xoffset,
3582 GLint yoffset,
3583 GLint x,
3584 GLint y,
3585 GLsizei width,
3586 GLsizei height,
3587 GLboolean unpackFlipY,
3588 GLboolean unpackPremultiplyAlpha,
3589 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07003590{
3591 // Zero sized copies are valid but no-ops
3592 if (width == 0 || height == 0)
3593 {
3594 return;
3595 }
3596
Jamie Madillbc918e72018-03-08 09:47:21 -05003597 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07003598
3599 gl::Texture *sourceTexture = getTexture(sourceId);
3600 gl::Texture *destTexture = getTexture(destId);
3601 Offset offset(xoffset, yoffset, 0);
3602 Rectangle area(x, y, width, height);
Geoff Lang92019432017-11-20 13:09:34 -05003603 handleError(destTexture->copySubTexture(this, destTarget, destLevel, offset, sourceLevel, area,
3604 ConvertToBool(unpackFlipY),
3605 ConvertToBool(unpackPremultiplyAlpha),
3606 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003607}
3608
Jamie Madill007530e2017-12-28 14:27:04 -05003609void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07003610{
Jamie Madillbc918e72018-03-08 09:47:21 -05003611 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07003612
3613 gl::Texture *sourceTexture = getTexture(sourceId);
3614 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05003615 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07003616}
3617
Corentin Wallez336129f2017-10-17 15:55:40 -04003618void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03003619{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003620 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003621 ASSERT(buffer);
3622
Geoff Lang496c02d2016-10-20 11:38:11 -07003623 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03003624}
3625
Corentin Wallez336129f2017-10-17 15:55:40 -04003626void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003627{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003628 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003629 ASSERT(buffer);
3630
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003631 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003632 if (error.isError())
3633 {
Jamie Madill437fa652016-05-03 15:13:24 -04003634 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003635 return nullptr;
3636 }
3637
3638 return buffer->getMapPointer();
3639}
3640
Corentin Wallez336129f2017-10-17 15:55:40 -04003641GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03003642{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003643 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003644 ASSERT(buffer);
3645
3646 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003647 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03003648 if (error.isError())
3649 {
Jamie Madill437fa652016-05-03 15:13:24 -04003650 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003651 return GL_FALSE;
3652 }
3653
3654 return result;
3655}
3656
Corentin Wallez336129f2017-10-17 15:55:40 -04003657void *Context::mapBufferRange(BufferBinding target,
3658 GLintptr offset,
3659 GLsizeiptr length,
3660 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003661{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003662 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003663 ASSERT(buffer);
3664
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003665 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003666 if (error.isError())
3667 {
Jamie Madill437fa652016-05-03 15:13:24 -04003668 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003669 return nullptr;
3670 }
3671
3672 return buffer->getMapPointer();
3673}
3674
Corentin Wallez336129f2017-10-17 15:55:40 -04003675void Context::flushMappedBufferRange(BufferBinding /*target*/,
3676 GLintptr /*offset*/,
3677 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03003678{
3679 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
3680}
3681
Jamie Madillbc918e72018-03-08 09:47:21 -05003682Error Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05003683{
Geoff Langa8cb2872018-03-09 16:09:40 -05003684 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05003685}
3686
Jamie Madillbc918e72018-03-08 09:47:21 -05003687Error Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05003688{
Geoff Langa8cb2872018-03-09 16:09:40 -05003689 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05003690}
3691
Jamie Madillbc918e72018-03-08 09:47:21 -05003692Error Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05003693{
Geoff Langa8cb2872018-03-09 16:09:40 -05003694 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05003695}
3696
Jiajia Qin5451d532017-11-16 17:16:34 +08003697void Context::activeShaderProgram(GLuint pipeline, GLuint program)
3698{
3699 UNIMPLEMENTED();
3700}
3701
Jamie Madillc20ab272016-06-09 07:20:46 -07003702void Context::activeTexture(GLenum texture)
3703{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003704 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003705}
3706
Jamie Madill876429b2017-04-20 15:46:24 -04003707void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003708{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003709 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07003710}
3711
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003712void Context::blendEquation(GLenum mode)
3713{
3714 mGLState.setBlendEquation(mode, mode);
3715}
3716
Jamie Madillc20ab272016-06-09 07:20:46 -07003717void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
3718{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003719 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003720}
3721
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003722void Context::blendFunc(GLenum sfactor, GLenum dfactor)
3723{
3724 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
3725}
3726
Jamie Madillc20ab272016-06-09 07:20:46 -07003727void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
3728{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003729 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003730}
3731
Jamie Madill876429b2017-04-20 15:46:24 -04003732void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003733{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003734 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003735}
3736
Jamie Madill876429b2017-04-20 15:46:24 -04003737void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07003738{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003739 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07003740}
3741
3742void Context::clearStencil(GLint s)
3743{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003744 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07003745}
3746
3747void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
3748{
Geoff Lang92019432017-11-20 13:09:34 -05003749 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
3750 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07003751}
3752
Corentin Wallez2e568cf2017-09-18 17:05:22 -04003753void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07003754{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003755 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003756}
3757
3758void Context::depthFunc(GLenum func)
3759{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003760 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07003761}
3762
3763void Context::depthMask(GLboolean flag)
3764{
Geoff Lang92019432017-11-20 13:09:34 -05003765 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07003766}
3767
Jamie Madill876429b2017-04-20 15:46:24 -04003768void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07003769{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003770 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07003771}
3772
3773void Context::disable(GLenum cap)
3774{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003775 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003776}
3777
3778void Context::disableVertexAttribArray(GLuint index)
3779{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003780 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003781}
3782
3783void Context::enable(GLenum cap)
3784{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003785 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003786}
3787
3788void Context::enableVertexAttribArray(GLuint index)
3789{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003790 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003791}
3792
3793void Context::frontFace(GLenum mode)
3794{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003795 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003796}
3797
3798void Context::hint(GLenum target, GLenum mode)
3799{
3800 switch (target)
3801 {
3802 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003803 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003804 break;
3805
3806 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003807 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003808 break;
3809
3810 default:
3811 UNREACHABLE();
3812 return;
3813 }
3814}
3815
3816void Context::lineWidth(GLfloat width)
3817{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003818 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07003819}
3820
3821void Context::pixelStorei(GLenum pname, GLint param)
3822{
3823 switch (pname)
3824 {
3825 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003826 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003827 break;
3828
3829 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003830 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003831 break;
3832
3833 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003834 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003835 break;
3836
3837 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003838 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003839 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003840 break;
3841
3842 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03003843 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003844 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003845 break;
3846
3847 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03003848 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003849 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003850 break;
3851
3852 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003853 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003854 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003855 break;
3856
3857 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003858 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003859 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003860 break;
3861
3862 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003863 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003864 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003865 break;
3866
3867 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003868 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003869 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003870 break;
3871
3872 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003873 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003874 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003875 break;
3876
3877 default:
3878 UNREACHABLE();
3879 return;
3880 }
3881}
3882
3883void Context::polygonOffset(GLfloat factor, GLfloat units)
3884{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003885 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07003886}
3887
Jamie Madill876429b2017-04-20 15:46:24 -04003888void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07003889{
Geoff Lang92019432017-11-20 13:09:34 -05003890 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07003891}
3892
Jiawei Shaodb342272017-09-27 10:21:45 +08003893void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
3894{
3895 mGLState.setSampleMaskParams(maskNumber, mask);
3896}
3897
Jamie Madillc20ab272016-06-09 07:20:46 -07003898void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
3899{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003900 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07003901}
3902
3903void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
3904{
3905 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3906 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003907 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003908 }
3909
3910 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3911 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003912 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003913 }
3914}
3915
3916void Context::stencilMaskSeparate(GLenum face, GLuint mask)
3917{
3918 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3919 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003920 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003921 }
3922
3923 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3924 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003925 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003926 }
3927}
3928
3929void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
3930{
3931 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3932 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003933 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003934 }
3935
3936 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3937 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003938 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003939 }
3940}
3941
3942void Context::vertexAttrib1f(GLuint index, GLfloat x)
3943{
3944 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003945 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003946}
3947
3948void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
3949{
3950 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003951 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003952}
3953
3954void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
3955{
3956 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003957 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003958}
3959
3960void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
3961{
3962 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003963 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003964}
3965
3966void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
3967{
3968 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003969 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003970}
3971
3972void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
3973{
3974 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003975 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003976}
3977
3978void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
3979{
3980 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003981 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003982}
3983
3984void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
3985{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003986 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07003987}
3988
3989void Context::vertexAttribPointer(GLuint index,
3990 GLint size,
3991 GLenum type,
3992 GLboolean normalized,
3993 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04003994 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07003995{
Corentin Wallez336129f2017-10-17 15:55:40 -04003996 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05003997 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc20ab272016-06-09 07:20:46 -07003998}
3999
Shao80957d92017-02-20 21:25:59 +08004000void Context::vertexAttribFormat(GLuint attribIndex,
4001 GLint size,
4002 GLenum type,
4003 GLboolean normalized,
4004 GLuint relativeOffset)
4005{
Geoff Lang92019432017-11-20 13:09:34 -05004006 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08004007 relativeOffset);
4008}
4009
4010void Context::vertexAttribIFormat(GLuint attribIndex,
4011 GLint size,
4012 GLenum type,
4013 GLuint relativeOffset)
4014{
4015 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
4016}
4017
4018void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4019{
Shaodde78e82017-05-22 14:13:27 +08004020 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Shao80957d92017-02-20 21:25:59 +08004021}
4022
Jiajia Qin5451d532017-11-16 17:16:34 +08004023void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004024{
4025 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
4026}
4027
Jamie Madillc20ab272016-06-09 07:20:46 -07004028void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4029{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004030 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004031}
4032
4033void Context::vertexAttribIPointer(GLuint index,
4034 GLint size,
4035 GLenum type,
4036 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004037 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004038{
Corentin Wallez336129f2017-10-17 15:55:40 -04004039 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
4040 size, type, false, true, stride, pointer);
Jamie Madillc20ab272016-06-09 07:20:46 -07004041}
4042
4043void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4044{
4045 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004046 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004047}
4048
4049void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4050{
4051 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004052 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004053}
4054
4055void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4056{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004057 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004058}
4059
4060void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4061{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004062 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004063}
4064
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004065void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4066{
4067 const VertexAttribCurrentValueData &currentValues =
4068 getGLState().getVertexAttribCurrentValue(index);
4069 const VertexArray *vao = getGLState().getVertexArray();
4070 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4071 currentValues, pname, params);
4072}
4073
4074void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4075{
4076 const VertexAttribCurrentValueData &currentValues =
4077 getGLState().getVertexAttribCurrentValue(index);
4078 const VertexArray *vao = getGLState().getVertexArray();
4079 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4080 currentValues, pname, params);
4081}
4082
4083void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4084{
4085 const VertexAttribCurrentValueData &currentValues =
4086 getGLState().getVertexAttribCurrentValue(index);
4087 const VertexArray *vao = getGLState().getVertexArray();
4088 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4089 currentValues, pname, params);
4090}
4091
4092void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4093{
4094 const VertexAttribCurrentValueData &currentValues =
4095 getGLState().getVertexAttribCurrentValue(index);
4096 const VertexArray *vao = getGLState().getVertexArray();
4097 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4098 currentValues, pname, params);
4099}
4100
Jamie Madill876429b2017-04-20 15:46:24 -04004101void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004102{
4103 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
4104 QueryVertexAttribPointerv(attrib, pname, pointer);
4105}
4106
Jamie Madillc20ab272016-06-09 07:20:46 -07004107void Context::debugMessageControl(GLenum source,
4108 GLenum type,
4109 GLenum severity,
4110 GLsizei count,
4111 const GLuint *ids,
4112 GLboolean enabled)
4113{
4114 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004115 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05004116 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004117}
4118
4119void Context::debugMessageInsert(GLenum source,
4120 GLenum type,
4121 GLuint id,
4122 GLenum severity,
4123 GLsizei length,
4124 const GLchar *buf)
4125{
4126 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004127 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004128}
4129
4130void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4131{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004132 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004133}
4134
4135GLuint Context::getDebugMessageLog(GLuint count,
4136 GLsizei bufSize,
4137 GLenum *sources,
4138 GLenum *types,
4139 GLuint *ids,
4140 GLenum *severities,
4141 GLsizei *lengths,
4142 GLchar *messageLog)
4143{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004144 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4145 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004146}
4147
4148void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4149{
4150 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004151 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05004152 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07004153}
4154
4155void Context::popDebugGroup()
4156{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004157 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05004158 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004159}
4160
Corentin Wallez336129f2017-10-17 15:55:40 -04004161void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004162{
4163 Buffer *buffer = mGLState.getTargetBuffer(target);
4164 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004165 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004166}
4167
Corentin Wallez336129f2017-10-17 15:55:40 -04004168void Context::bufferSubData(BufferBinding target,
4169 GLintptr offset,
4170 GLsizeiptr size,
4171 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004172{
4173 if (data == nullptr)
4174 {
4175 return;
4176 }
4177
4178 Buffer *buffer = mGLState.getTargetBuffer(target);
4179 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004180 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004181}
4182
Jamie Madillef300b12016-10-07 15:12:09 -04004183void Context::attachShader(GLuint program, GLuint shader)
4184{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05004185 Program *programObject = mState.mShaderPrograms->getProgram(program);
4186 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004187 ASSERT(programObject && shaderObject);
4188 programObject->attachShader(shaderObject);
4189}
4190
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004191const Workarounds &Context::getWorkarounds() const
4192{
4193 return mWorkarounds;
4194}
4195
Corentin Wallez336129f2017-10-17 15:55:40 -04004196void Context::copyBufferSubData(BufferBinding readTarget,
4197 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04004198 GLintptr readOffset,
4199 GLintptr writeOffset,
4200 GLsizeiptr size)
4201{
4202 // if size is zero, the copy is a successful no-op
4203 if (size == 0)
4204 {
4205 return;
4206 }
4207
4208 // TODO(jmadill): cache these.
4209 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4210 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4211
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004212 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004213}
4214
Jamie Madill01a80ee2016-11-07 12:06:18 -05004215void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4216{
4217 Program *programObject = getProgram(program);
4218 // TODO(jmadill): Re-use this from the validation if possible.
4219 ASSERT(programObject);
4220 programObject->bindAttributeLocation(index, name);
4221}
4222
Corentin Wallez336129f2017-10-17 15:55:40 -04004223void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004224{
Corentin Wallez336129f2017-10-17 15:55:40 -04004225 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4226 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004227}
4228
Corentin Wallez336129f2017-10-17 15:55:40 -04004229void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08004230{
4231 bindBufferRange(target, index, buffer, 0, 0);
4232}
4233
Corentin Wallez336129f2017-10-17 15:55:40 -04004234void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08004235 GLuint index,
4236 GLuint buffer,
4237 GLintptr offset,
4238 GLsizeiptr size)
4239{
Corentin Wallez336129f2017-10-17 15:55:40 -04004240 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4241 mGLState.setIndexedBufferBinding(this, target, index, bufferObject, offset, size);
Jiajia Qin6eafb042016-12-27 17:04:07 +08004242}
4243
Jamie Madill01a80ee2016-11-07 12:06:18 -05004244void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
4245{
4246 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4247 {
4248 bindReadFramebuffer(framebuffer);
4249 }
4250
4251 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4252 {
4253 bindDrawFramebuffer(framebuffer);
4254 }
4255}
4256
4257void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4258{
4259 ASSERT(target == GL_RENDERBUFFER);
4260 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004261 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04004262 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004263}
4264
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004265void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08004266 GLsizei samples,
4267 GLenum internalformat,
4268 GLsizei width,
4269 GLsizei height,
4270 GLboolean fixedsamplelocations)
4271{
4272 Extents size(width, height, 1);
4273 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004274 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
4275 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004276}
4277
4278void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4279{
JiangYizhou5b03f472017-01-09 10:22:53 +08004280 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
4281 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillbc918e72018-03-08 09:47:21 -05004282 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
JiangYizhou5b03f472017-01-09 10:22:53 +08004283 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08004284
4285 switch (pname)
4286 {
4287 case GL_SAMPLE_POSITION:
4288 handleError(framebuffer->getSamplePosition(index, val));
4289 break;
4290 default:
4291 UNREACHABLE();
4292 }
4293}
4294
Jamie Madille8fb6402017-02-14 17:56:40 -05004295void Context::renderbufferStorage(GLenum target,
4296 GLenum internalformat,
4297 GLsizei width,
4298 GLsizei height)
4299{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004300 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4301 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
4302
Jamie Madille8fb6402017-02-14 17:56:40 -05004303 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04004304 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004305}
4306
4307void Context::renderbufferStorageMultisample(GLenum target,
4308 GLsizei samples,
4309 GLenum internalformat,
4310 GLsizei width,
4311 GLsizei height)
4312{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004313 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4314 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05004315
4316 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004317 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04004318 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004319}
4320
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004321void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
4322{
Jamie Madill70b5bb02017-08-28 13:32:37 -04004323 const Sync *syncObject = getSync(sync);
Geoff Lang82483b92017-04-11 15:33:00 -04004324 handleError(QuerySynciv(syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004325}
4326
JiangYizhoue18e6392017-02-20 10:32:23 +08004327void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
4328{
4329 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4330 QueryFramebufferParameteriv(framebuffer, pname, params);
4331}
4332
Jiajia Qin5451d532017-11-16 17:16:34 +08004333void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08004334{
4335 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4336 SetFramebufferParameteri(framebuffer, pname, param);
4337}
4338
Jamie Madillb3f26b92017-07-19 15:07:41 -04004339Error Context::getScratchBuffer(size_t requstedSizeBytes,
4340 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05004341{
Jamie Madillb3f26b92017-07-19 15:07:41 -04004342 if (!mScratchBuffer.get(requstedSizeBytes, scratchBufferOut))
4343 {
4344 return OutOfMemory() << "Failed to allocate internal buffer.";
4345 }
4346 return NoError();
4347}
4348
4349Error Context::getZeroFilledBuffer(size_t requstedSizeBytes,
4350 angle::MemoryBuffer **zeroBufferOut) const
4351{
4352 if (!mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0))
Jamie Madille14951e2017-03-09 18:55:16 -05004353 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004354 return OutOfMemory() << "Failed to allocate internal buffer.";
Jamie Madille14951e2017-03-09 18:55:16 -05004355 }
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004356 return NoError();
Jamie Madille14951e2017-03-09 18:55:16 -05004357}
4358
Xinghua Cao10a4d432017-11-28 14:46:26 +08004359Error Context::prepareForDispatch()
4360{
Geoff Langa8cb2872018-03-09 16:09:40 -05004361 ANGLE_TRY(syncState(mComputeDirtyBits, mComputeDirtyObjects));
Xinghua Cao10a4d432017-11-28 14:46:26 +08004362
4363 if (isRobustResourceInitEnabled())
4364 {
4365 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
4366 }
4367
4368 return NoError();
4369}
4370
Xinghua Cao2b396592017-03-29 15:36:04 +08004371void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
4372{
4373 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
4374 {
4375 return;
4376 }
4377
Xinghua Cao10a4d432017-11-28 14:46:26 +08004378 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill71c88b32017-09-14 22:20:29 -04004379 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08004380}
4381
Jiajia Qin5451d532017-11-16 17:16:34 +08004382void Context::dispatchComputeIndirect(GLintptr indirect)
4383{
Qin Jiajia62fcf622017-11-30 16:16:12 +08004384 ANGLE_CONTEXT_TRY(prepareForDispatch());
4385 handleError(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08004386}
4387
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004388void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08004389 GLsizei levels,
4390 GLenum internalFormat,
4391 GLsizei width,
4392 GLsizei height)
4393{
4394 Extents size(width, height, 1);
4395 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004396 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08004397}
4398
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004399void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08004400 GLsizei levels,
4401 GLenum internalFormat,
4402 GLsizei width,
4403 GLsizei height,
4404 GLsizei depth)
4405{
4406 Extents size(width, height, depth);
4407 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004408 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08004409}
4410
Jiajia Qin5451d532017-11-16 17:16:34 +08004411void Context::memoryBarrier(GLbitfield barriers)
4412{
Xinghua Cao89c422a2017-11-29 18:24:20 +08004413 handleError(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08004414}
4415
4416void Context::memoryBarrierByRegion(GLbitfield barriers)
4417{
Xinghua Cao89c422a2017-11-29 18:24:20 +08004418 handleError(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08004419}
4420
Jamie Madillc1d770e2017-04-13 17:31:24 -04004421GLenum Context::checkFramebufferStatus(GLenum target)
4422{
4423 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4424 ASSERT(framebuffer);
4425
Jamie Madille98b1b52018-03-08 09:47:23 -05004426 GLenum status = GL_NONE;
4427 Error err = framebuffer->checkStatus(this, &status);
4428 if (err.isError())
4429 {
4430 handleError(err);
4431 return 0;
4432 }
4433 return status;
Jamie Madillc1d770e2017-04-13 17:31:24 -04004434}
4435
4436void Context::compileShader(GLuint shader)
4437{
4438 Shader *shaderObject = GetValidShader(this, shader);
4439 if (!shaderObject)
4440 {
4441 return;
4442 }
4443 shaderObject->compile(this);
4444}
4445
4446void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
4447{
4448 for (int i = 0; i < n; i++)
4449 {
4450 deleteBuffer(buffers[i]);
4451 }
4452}
4453
4454void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
4455{
4456 for (int i = 0; i < n; i++)
4457 {
4458 if (framebuffers[i] != 0)
4459 {
4460 deleteFramebuffer(framebuffers[i]);
4461 }
4462 }
4463}
4464
4465void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
4466{
4467 for (int i = 0; i < n; i++)
4468 {
4469 deleteRenderbuffer(renderbuffers[i]);
4470 }
4471}
4472
4473void Context::deleteTextures(GLsizei n, const GLuint *textures)
4474{
4475 for (int i = 0; i < n; i++)
4476 {
4477 if (textures[i] != 0)
4478 {
4479 deleteTexture(textures[i]);
4480 }
4481 }
4482}
4483
4484void Context::detachShader(GLuint program, GLuint shader)
4485{
4486 Program *programObject = getProgram(program);
4487 ASSERT(programObject);
4488
4489 Shader *shaderObject = getShader(shader);
4490 ASSERT(shaderObject);
4491
4492 programObject->detachShader(this, shaderObject);
4493}
4494
4495void Context::genBuffers(GLsizei n, GLuint *buffers)
4496{
4497 for (int i = 0; i < n; i++)
4498 {
4499 buffers[i] = createBuffer();
4500 }
4501}
4502
4503void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
4504{
4505 for (int i = 0; i < n; i++)
4506 {
4507 framebuffers[i] = createFramebuffer();
4508 }
4509}
4510
4511void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
4512{
4513 for (int i = 0; i < n; i++)
4514 {
4515 renderbuffers[i] = createRenderbuffer();
4516 }
4517}
4518
4519void Context::genTextures(GLsizei n, GLuint *textures)
4520{
4521 for (int i = 0; i < n; i++)
4522 {
4523 textures[i] = createTexture();
4524 }
4525}
4526
4527void Context::getActiveAttrib(GLuint program,
4528 GLuint index,
4529 GLsizei bufsize,
4530 GLsizei *length,
4531 GLint *size,
4532 GLenum *type,
4533 GLchar *name)
4534{
4535 Program *programObject = getProgram(program);
4536 ASSERT(programObject);
4537 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
4538}
4539
4540void Context::getActiveUniform(GLuint program,
4541 GLuint index,
4542 GLsizei bufsize,
4543 GLsizei *length,
4544 GLint *size,
4545 GLenum *type,
4546 GLchar *name)
4547{
4548 Program *programObject = getProgram(program);
4549 ASSERT(programObject);
4550 programObject->getActiveUniform(index, bufsize, length, size, type, name);
4551}
4552
4553void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
4554{
4555 Program *programObject = getProgram(program);
4556 ASSERT(programObject);
4557 programObject->getAttachedShaders(maxcount, count, shaders);
4558}
4559
4560GLint Context::getAttribLocation(GLuint program, const GLchar *name)
4561{
4562 Program *programObject = getProgram(program);
4563 ASSERT(programObject);
4564 return programObject->getAttributeLocation(name);
4565}
4566
4567void Context::getBooleanv(GLenum pname, GLboolean *params)
4568{
4569 GLenum nativeType;
4570 unsigned int numParams = 0;
4571 getQueryParameterInfo(pname, &nativeType, &numParams);
4572
4573 if (nativeType == GL_BOOL)
4574 {
4575 getBooleanvImpl(pname, params);
4576 }
4577 else
4578 {
4579 CastStateValues(this, nativeType, pname, numParams, params);
4580 }
4581}
4582
4583void Context::getFloatv(GLenum pname, GLfloat *params)
4584{
4585 GLenum nativeType;
4586 unsigned int numParams = 0;
4587 getQueryParameterInfo(pname, &nativeType, &numParams);
4588
4589 if (nativeType == GL_FLOAT)
4590 {
4591 getFloatvImpl(pname, params);
4592 }
4593 else
4594 {
4595 CastStateValues(this, nativeType, pname, numParams, params);
4596 }
4597}
4598
4599void Context::getIntegerv(GLenum pname, GLint *params)
4600{
4601 GLenum nativeType;
4602 unsigned int numParams = 0;
4603 getQueryParameterInfo(pname, &nativeType, &numParams);
4604
4605 if (nativeType == GL_INT)
4606 {
4607 getIntegervImpl(pname, params);
4608 }
4609 else
4610 {
4611 CastStateValues(this, nativeType, pname, numParams, params);
4612 }
4613}
4614
4615void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
4616{
4617 Program *programObject = getProgram(program);
4618 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04004619 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004620}
4621
Jiajia Qin5451d532017-11-16 17:16:34 +08004622void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
4623{
4624 UNIMPLEMENTED();
4625}
4626
Jamie Madillbe849e42017-05-02 15:49:00 -04004627void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04004628{
4629 Program *programObject = getProgram(program);
4630 ASSERT(programObject);
4631 programObject->getInfoLog(bufsize, length, infolog);
4632}
4633
Jiajia Qin5451d532017-11-16 17:16:34 +08004634void Context::getProgramPipelineInfoLog(GLuint pipeline,
4635 GLsizei bufSize,
4636 GLsizei *length,
4637 GLchar *infoLog)
4638{
4639 UNIMPLEMENTED();
4640}
4641
Jamie Madillc1d770e2017-04-13 17:31:24 -04004642void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
4643{
4644 Shader *shaderObject = getShader(shader);
4645 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004646 QueryShaderiv(this, shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004647}
4648
4649void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
4650{
4651 Shader *shaderObject = getShader(shader);
4652 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004653 shaderObject->getInfoLog(this, bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004654}
4655
4656void Context::getShaderPrecisionFormat(GLenum shadertype,
4657 GLenum precisiontype,
4658 GLint *range,
4659 GLint *precision)
4660{
4661 // TODO(jmadill): Compute shaders.
4662
4663 switch (shadertype)
4664 {
4665 case GL_VERTEX_SHADER:
4666 switch (precisiontype)
4667 {
4668 case GL_LOW_FLOAT:
4669 mCaps.vertexLowpFloat.get(range, precision);
4670 break;
4671 case GL_MEDIUM_FLOAT:
4672 mCaps.vertexMediumpFloat.get(range, precision);
4673 break;
4674 case GL_HIGH_FLOAT:
4675 mCaps.vertexHighpFloat.get(range, precision);
4676 break;
4677
4678 case GL_LOW_INT:
4679 mCaps.vertexLowpInt.get(range, precision);
4680 break;
4681 case GL_MEDIUM_INT:
4682 mCaps.vertexMediumpInt.get(range, precision);
4683 break;
4684 case GL_HIGH_INT:
4685 mCaps.vertexHighpInt.get(range, precision);
4686 break;
4687
4688 default:
4689 UNREACHABLE();
4690 return;
4691 }
4692 break;
4693
4694 case GL_FRAGMENT_SHADER:
4695 switch (precisiontype)
4696 {
4697 case GL_LOW_FLOAT:
4698 mCaps.fragmentLowpFloat.get(range, precision);
4699 break;
4700 case GL_MEDIUM_FLOAT:
4701 mCaps.fragmentMediumpFloat.get(range, precision);
4702 break;
4703 case GL_HIGH_FLOAT:
4704 mCaps.fragmentHighpFloat.get(range, precision);
4705 break;
4706
4707 case GL_LOW_INT:
4708 mCaps.fragmentLowpInt.get(range, precision);
4709 break;
4710 case GL_MEDIUM_INT:
4711 mCaps.fragmentMediumpInt.get(range, precision);
4712 break;
4713 case GL_HIGH_INT:
4714 mCaps.fragmentHighpInt.get(range, precision);
4715 break;
4716
4717 default:
4718 UNREACHABLE();
4719 return;
4720 }
4721 break;
4722
4723 default:
4724 UNREACHABLE();
4725 return;
4726 }
4727}
4728
4729void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
4730{
4731 Shader *shaderObject = getShader(shader);
4732 ASSERT(shaderObject);
4733 shaderObject->getSource(bufsize, length, source);
4734}
4735
4736void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
4737{
4738 Program *programObject = getProgram(program);
4739 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04004740 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004741}
4742
4743void Context::getUniformiv(GLuint program, GLint location, GLint *params)
4744{
4745 Program *programObject = getProgram(program);
4746 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04004747 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004748}
4749
4750GLint Context::getUniformLocation(GLuint program, const GLchar *name)
4751{
4752 Program *programObject = getProgram(program);
4753 ASSERT(programObject);
4754 return programObject->getUniformLocation(name);
4755}
4756
4757GLboolean Context::isBuffer(GLuint buffer)
4758{
4759 if (buffer == 0)
4760 {
4761 return GL_FALSE;
4762 }
4763
4764 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
4765}
4766
4767GLboolean Context::isEnabled(GLenum cap)
4768{
4769 return mGLState.getEnableFeature(cap);
4770}
4771
4772GLboolean Context::isFramebuffer(GLuint framebuffer)
4773{
4774 if (framebuffer == 0)
4775 {
4776 return GL_FALSE;
4777 }
4778
4779 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
4780}
4781
4782GLboolean Context::isProgram(GLuint program)
4783{
4784 if (program == 0)
4785 {
4786 return GL_FALSE;
4787 }
4788
4789 return (getProgram(program) ? GL_TRUE : GL_FALSE);
4790}
4791
4792GLboolean Context::isRenderbuffer(GLuint renderbuffer)
4793{
4794 if (renderbuffer == 0)
4795 {
4796 return GL_FALSE;
4797 }
4798
4799 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
4800}
4801
4802GLboolean Context::isShader(GLuint shader)
4803{
4804 if (shader == 0)
4805 {
4806 return GL_FALSE;
4807 }
4808
4809 return (getShader(shader) ? GL_TRUE : GL_FALSE);
4810}
4811
4812GLboolean Context::isTexture(GLuint texture)
4813{
4814 if (texture == 0)
4815 {
4816 return GL_FALSE;
4817 }
4818
4819 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
4820}
4821
4822void Context::linkProgram(GLuint program)
4823{
4824 Program *programObject = getProgram(program);
4825 ASSERT(programObject);
4826 handleError(programObject->link(this));
Martin Radev0abb7a22017-08-28 15:34:45 +03004827 mGLState.onProgramExecutableChange(programObject);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004828}
4829
4830void Context::releaseShaderCompiler()
4831{
Jamie Madill4928b7c2017-06-20 12:57:39 -04004832 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004833}
4834
4835void Context::shaderBinary(GLsizei n,
4836 const GLuint *shaders,
4837 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04004838 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04004839 GLsizei length)
4840{
4841 // No binary shader formats are supported.
4842 UNIMPLEMENTED();
4843}
4844
4845void Context::shaderSource(GLuint shader,
4846 GLsizei count,
4847 const GLchar *const *string,
4848 const GLint *length)
4849{
4850 Shader *shaderObject = getShader(shader);
4851 ASSERT(shaderObject);
4852 shaderObject->setSource(count, string, length);
4853}
4854
4855void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
4856{
4857 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
4858}
4859
4860void Context::stencilMask(GLuint mask)
4861{
4862 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
4863}
4864
4865void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
4866{
4867 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
4868}
4869
4870void Context::uniform1f(GLint location, GLfloat x)
4871{
4872 Program *program = mGLState.getProgram();
4873 program->setUniform1fv(location, 1, &x);
4874}
4875
4876void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
4877{
4878 Program *program = mGLState.getProgram();
4879 program->setUniform1fv(location, count, v);
4880}
4881
4882void Context::uniform1i(GLint location, GLint x)
4883{
4884 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04004885 if (program->setUniform1iv(location, 1, &x) == Program::SetUniformResult::SamplerChanged)
4886 {
4887 mGLState.setObjectDirty(GL_PROGRAM);
4888 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04004889}
4890
4891void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
4892{
4893 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04004894 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
4895 {
4896 mGLState.setObjectDirty(GL_PROGRAM);
4897 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04004898}
4899
4900void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
4901{
4902 GLfloat xy[2] = {x, y};
4903 Program *program = mGLState.getProgram();
4904 program->setUniform2fv(location, 1, xy);
4905}
4906
4907void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
4908{
4909 Program *program = mGLState.getProgram();
4910 program->setUniform2fv(location, count, v);
4911}
4912
4913void Context::uniform2i(GLint location, GLint x, GLint y)
4914{
4915 GLint xy[2] = {x, y};
4916 Program *program = mGLState.getProgram();
4917 program->setUniform2iv(location, 1, xy);
4918}
4919
4920void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
4921{
4922 Program *program = mGLState.getProgram();
4923 program->setUniform2iv(location, count, v);
4924}
4925
4926void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
4927{
4928 GLfloat xyz[3] = {x, y, z};
4929 Program *program = mGLState.getProgram();
4930 program->setUniform3fv(location, 1, xyz);
4931}
4932
4933void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
4934{
4935 Program *program = mGLState.getProgram();
4936 program->setUniform3fv(location, count, v);
4937}
4938
4939void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
4940{
4941 GLint xyz[3] = {x, y, z};
4942 Program *program = mGLState.getProgram();
4943 program->setUniform3iv(location, 1, xyz);
4944}
4945
4946void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
4947{
4948 Program *program = mGLState.getProgram();
4949 program->setUniform3iv(location, count, v);
4950}
4951
4952void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4953{
4954 GLfloat xyzw[4] = {x, y, z, w};
4955 Program *program = mGLState.getProgram();
4956 program->setUniform4fv(location, 1, xyzw);
4957}
4958
4959void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
4960{
4961 Program *program = mGLState.getProgram();
4962 program->setUniform4fv(location, count, v);
4963}
4964
4965void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
4966{
4967 GLint xyzw[4] = {x, y, z, w};
4968 Program *program = mGLState.getProgram();
4969 program->setUniform4iv(location, 1, xyzw);
4970}
4971
4972void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
4973{
4974 Program *program = mGLState.getProgram();
4975 program->setUniform4iv(location, count, v);
4976}
4977
4978void Context::uniformMatrix2fv(GLint location,
4979 GLsizei count,
4980 GLboolean transpose,
4981 const GLfloat *value)
4982{
4983 Program *program = mGLState.getProgram();
4984 program->setUniformMatrix2fv(location, count, transpose, value);
4985}
4986
4987void Context::uniformMatrix3fv(GLint location,
4988 GLsizei count,
4989 GLboolean transpose,
4990 const GLfloat *value)
4991{
4992 Program *program = mGLState.getProgram();
4993 program->setUniformMatrix3fv(location, count, transpose, value);
4994}
4995
4996void Context::uniformMatrix4fv(GLint location,
4997 GLsizei count,
4998 GLboolean transpose,
4999 const GLfloat *value)
5000{
5001 Program *program = mGLState.getProgram();
5002 program->setUniformMatrix4fv(location, count, transpose, value);
5003}
5004
5005void Context::validateProgram(GLuint program)
5006{
5007 Program *programObject = getProgram(program);
5008 ASSERT(programObject);
5009 programObject->validate(mCaps);
5010}
5011
Jiajia Qin5451d532017-11-16 17:16:34 +08005012void Context::validateProgramPipeline(GLuint pipeline)
5013{
5014 UNIMPLEMENTED();
5015}
5016
Jamie Madilld04908b2017-06-09 14:15:35 -04005017void Context::getProgramBinary(GLuint program,
5018 GLsizei bufSize,
5019 GLsizei *length,
5020 GLenum *binaryFormat,
5021 void *binary)
5022{
5023 Program *programObject = getProgram(program);
5024 ASSERT(programObject != nullptr);
5025
5026 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
5027}
5028
5029void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
5030{
5031 Program *programObject = getProgram(program);
5032 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04005033
Jamie Madilld04908b2017-06-09 14:15:35 -04005034 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
5035}
5036
Jamie Madillff325f12017-08-26 15:06:05 -04005037void Context::uniform1ui(GLint location, GLuint v0)
5038{
5039 Program *program = mGLState.getProgram();
5040 program->setUniform1uiv(location, 1, &v0);
5041}
5042
5043void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
5044{
5045 Program *program = mGLState.getProgram();
5046 const GLuint xy[] = {v0, v1};
5047 program->setUniform2uiv(location, 1, xy);
5048}
5049
5050void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
5051{
5052 Program *program = mGLState.getProgram();
5053 const GLuint xyz[] = {v0, v1, v2};
5054 program->setUniform3uiv(location, 1, xyz);
5055}
5056
5057void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
5058{
5059 Program *program = mGLState.getProgram();
5060 const GLuint xyzw[] = {v0, v1, v2, v3};
5061 program->setUniform4uiv(location, 1, xyzw);
5062}
5063
5064void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
5065{
5066 Program *program = mGLState.getProgram();
5067 program->setUniform1uiv(location, count, value);
5068}
5069void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
5070{
5071 Program *program = mGLState.getProgram();
5072 program->setUniform2uiv(location, count, value);
5073}
5074
5075void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
5076{
5077 Program *program = mGLState.getProgram();
5078 program->setUniform3uiv(location, count, value);
5079}
5080
5081void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
5082{
5083 Program *program = mGLState.getProgram();
5084 program->setUniform4uiv(location, count, value);
5085}
5086
Jamie Madillf0e04492017-08-26 15:28:42 -04005087void Context::genQueries(GLsizei n, GLuint *ids)
5088{
5089 for (GLsizei i = 0; i < n; i++)
5090 {
5091 GLuint handle = mQueryHandleAllocator.allocate();
5092 mQueryMap.assign(handle, nullptr);
5093 ids[i] = handle;
5094 }
5095}
5096
5097void Context::deleteQueries(GLsizei n, const GLuint *ids)
5098{
5099 for (int i = 0; i < n; i++)
5100 {
5101 GLuint query = ids[i];
5102
5103 Query *queryObject = nullptr;
5104 if (mQueryMap.erase(query, &queryObject))
5105 {
5106 mQueryHandleAllocator.release(query);
5107 if (queryObject)
5108 {
5109 queryObject->release(this);
5110 }
5111 }
5112 }
5113}
5114
5115GLboolean Context::isQuery(GLuint id)
5116{
5117 return (getQuery(id, false, GL_NONE) != nullptr) ? GL_TRUE : GL_FALSE;
5118}
5119
Jamie Madillc8c95812017-08-26 18:40:09 -04005120void Context::uniformMatrix2x3fv(GLint location,
5121 GLsizei count,
5122 GLboolean transpose,
5123 const GLfloat *value)
5124{
5125 Program *program = mGLState.getProgram();
5126 program->setUniformMatrix2x3fv(location, count, transpose, value);
5127}
5128
5129void Context::uniformMatrix3x2fv(GLint location,
5130 GLsizei count,
5131 GLboolean transpose,
5132 const GLfloat *value)
5133{
5134 Program *program = mGLState.getProgram();
5135 program->setUniformMatrix3x2fv(location, count, transpose, value);
5136}
5137
5138void Context::uniformMatrix2x4fv(GLint location,
5139 GLsizei count,
5140 GLboolean transpose,
5141 const GLfloat *value)
5142{
5143 Program *program = mGLState.getProgram();
5144 program->setUniformMatrix2x4fv(location, count, transpose, value);
5145}
5146
5147void Context::uniformMatrix4x2fv(GLint location,
5148 GLsizei count,
5149 GLboolean transpose,
5150 const GLfloat *value)
5151{
5152 Program *program = mGLState.getProgram();
5153 program->setUniformMatrix4x2fv(location, count, transpose, value);
5154}
5155
5156void Context::uniformMatrix3x4fv(GLint location,
5157 GLsizei count,
5158 GLboolean transpose,
5159 const GLfloat *value)
5160{
5161 Program *program = mGLState.getProgram();
5162 program->setUniformMatrix3x4fv(location, count, transpose, value);
5163}
5164
5165void Context::uniformMatrix4x3fv(GLint location,
5166 GLsizei count,
5167 GLboolean transpose,
5168 const GLfloat *value)
5169{
5170 Program *program = mGLState.getProgram();
5171 program->setUniformMatrix4x3fv(location, count, transpose, value);
5172}
5173
Jamie Madilld7576732017-08-26 18:49:50 -04005174void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
5175{
5176 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5177 {
5178 GLuint vertexArray = arrays[arrayIndex];
5179
5180 if (arrays[arrayIndex] != 0)
5181 {
5182 VertexArray *vertexArrayObject = nullptr;
5183 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
5184 {
5185 if (vertexArrayObject != nullptr)
5186 {
5187 detachVertexArray(vertexArray);
5188 vertexArrayObject->onDestroy(this);
5189 }
5190
5191 mVertexArrayHandleAllocator.release(vertexArray);
5192 }
5193 }
5194 }
5195}
5196
5197void Context::genVertexArrays(GLsizei n, GLuint *arrays)
5198{
5199 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5200 {
5201 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
5202 mVertexArrayMap.assign(vertexArray, nullptr);
5203 arrays[arrayIndex] = vertexArray;
5204 }
5205}
5206
5207bool Context::isVertexArray(GLuint array)
5208{
5209 if (array == 0)
5210 {
5211 return GL_FALSE;
5212 }
5213
5214 VertexArray *vao = getVertexArray(array);
5215 return (vao != nullptr ? GL_TRUE : GL_FALSE);
5216}
5217
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04005218void Context::endTransformFeedback()
5219{
5220 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5221 transformFeedback->end(this);
5222}
5223
5224void Context::transformFeedbackVaryings(GLuint program,
5225 GLsizei count,
5226 const GLchar *const *varyings,
5227 GLenum bufferMode)
5228{
5229 Program *programObject = getProgram(program);
5230 ASSERT(programObject);
5231 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
5232}
5233
5234void Context::getTransformFeedbackVarying(GLuint program,
5235 GLuint index,
5236 GLsizei bufSize,
5237 GLsizei *length,
5238 GLsizei *size,
5239 GLenum *type,
5240 GLchar *name)
5241{
5242 Program *programObject = getProgram(program);
5243 ASSERT(programObject);
5244 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
5245}
5246
5247void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
5248{
5249 for (int i = 0; i < n; i++)
5250 {
5251 GLuint transformFeedback = ids[i];
5252 if (transformFeedback == 0)
5253 {
5254 continue;
5255 }
5256
5257 TransformFeedback *transformFeedbackObject = nullptr;
5258 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
5259 {
5260 if (transformFeedbackObject != nullptr)
5261 {
5262 detachTransformFeedback(transformFeedback);
5263 transformFeedbackObject->release(this);
5264 }
5265
5266 mTransformFeedbackHandleAllocator.release(transformFeedback);
5267 }
5268 }
5269}
5270
5271void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
5272{
5273 for (int i = 0; i < n; i++)
5274 {
5275 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
5276 mTransformFeedbackMap.assign(transformFeedback, nullptr);
5277 ids[i] = transformFeedback;
5278 }
5279}
5280
5281bool Context::isTransformFeedback(GLuint id)
5282{
5283 if (id == 0)
5284 {
5285 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
5286 // returns FALSE
5287 return GL_FALSE;
5288 }
5289
5290 const TransformFeedback *transformFeedback = getTransformFeedback(id);
5291 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
5292}
5293
5294void Context::pauseTransformFeedback()
5295{
5296 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5297 transformFeedback->pause();
5298}
5299
5300void Context::resumeTransformFeedback()
5301{
5302 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5303 transformFeedback->resume();
5304}
5305
Jamie Madill12e957f2017-08-26 21:42:26 -04005306void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
5307{
5308 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04005309 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04005310}
5311
5312GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
5313{
5314 const Program *programObject = getProgram(program);
5315 return programObject->getFragDataLocation(name);
5316}
5317
5318void Context::getUniformIndices(GLuint program,
5319 GLsizei uniformCount,
5320 const GLchar *const *uniformNames,
5321 GLuint *uniformIndices)
5322{
5323 const Program *programObject = getProgram(program);
5324 if (!programObject->isLinked())
5325 {
5326 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5327 {
5328 uniformIndices[uniformId] = GL_INVALID_INDEX;
5329 }
5330 }
5331 else
5332 {
5333 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5334 {
5335 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
5336 }
5337 }
5338}
5339
5340void Context::getActiveUniformsiv(GLuint program,
5341 GLsizei uniformCount,
5342 const GLuint *uniformIndices,
5343 GLenum pname,
5344 GLint *params)
5345{
5346 const Program *programObject = getProgram(program);
5347 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5348 {
5349 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08005350 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04005351 }
5352}
5353
5354GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
5355{
5356 const Program *programObject = getProgram(program);
5357 return programObject->getUniformBlockIndex(uniformBlockName);
5358}
5359
5360void Context::getActiveUniformBlockiv(GLuint program,
5361 GLuint uniformBlockIndex,
5362 GLenum pname,
5363 GLint *params)
5364{
5365 const Program *programObject = getProgram(program);
5366 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
5367}
5368
5369void Context::getActiveUniformBlockName(GLuint program,
5370 GLuint uniformBlockIndex,
5371 GLsizei bufSize,
5372 GLsizei *length,
5373 GLchar *uniformBlockName)
5374{
5375 const Program *programObject = getProgram(program);
5376 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
5377}
5378
5379void Context::uniformBlockBinding(GLuint program,
5380 GLuint uniformBlockIndex,
5381 GLuint uniformBlockBinding)
5382{
5383 Program *programObject = getProgram(program);
5384 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
5385}
5386
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005387GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
5388{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005389 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
5390 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005391
Jamie Madill70b5bb02017-08-28 13:32:37 -04005392 Sync *syncObject = getSync(syncHandle);
5393 Error error = syncObject->set(condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005394 if (error.isError())
5395 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04005396 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005397 handleError(error);
5398 return nullptr;
5399 }
5400
Jamie Madill70b5bb02017-08-28 13:32:37 -04005401 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005402}
5403
5404GLboolean Context::isSync(GLsync sync)
5405{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005406 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005407}
5408
5409GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
5410{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005411 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005412
5413 GLenum result = GL_WAIT_FAILED;
5414 handleError(syncObject->clientWait(flags, timeout, &result));
5415 return result;
5416}
5417
5418void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
5419{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005420 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005421 handleError(syncObject->serverWait(flags, timeout));
5422}
5423
5424void Context::getInteger64v(GLenum pname, GLint64 *params)
5425{
5426 GLenum nativeType = GL_NONE;
5427 unsigned int numParams = 0;
5428 getQueryParameterInfo(pname, &nativeType, &numParams);
5429
5430 if (nativeType == GL_INT_64_ANGLEX)
5431 {
5432 getInteger64vImpl(pname, params);
5433 }
5434 else
5435 {
5436 CastStateValues(this, nativeType, pname, numParams, params);
5437 }
5438}
5439
Corentin Wallez336129f2017-10-17 15:55:40 -04005440void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04005441{
5442 Buffer *buffer = mGLState.getTargetBuffer(target);
5443 QueryBufferParameteri64v(buffer, pname, params);
5444}
5445
5446void Context::genSamplers(GLsizei count, GLuint *samplers)
5447{
5448 for (int i = 0; i < count; i++)
5449 {
5450 samplers[i] = mState.mSamplers->createSampler();
5451 }
5452}
5453
5454void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
5455{
5456 for (int i = 0; i < count; i++)
5457 {
5458 GLuint sampler = samplers[i];
5459
5460 if (mState.mSamplers->getSampler(sampler))
5461 {
5462 detachSampler(sampler);
5463 }
5464
5465 mState.mSamplers->deleteObject(this, sampler);
5466 }
5467}
5468
5469void Context::getInternalformativ(GLenum target,
5470 GLenum internalformat,
5471 GLenum pname,
5472 GLsizei bufSize,
5473 GLint *params)
5474{
5475 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
5476 QueryInternalFormativ(formatCaps, pname, bufSize, params);
5477}
5478
Jiajia Qin5451d532017-11-16 17:16:34 +08005479void Context::programUniform1i(GLuint program, GLint location, GLint v0)
5480{
5481 programUniform1iv(program, location, 1, &v0);
5482}
5483
5484void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
5485{
5486 GLint xy[2] = {v0, v1};
5487 programUniform2iv(program, location, 1, xy);
5488}
5489
5490void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
5491{
5492 GLint xyz[3] = {v0, v1, v2};
5493 programUniform3iv(program, location, 1, xyz);
5494}
5495
5496void Context::programUniform4i(GLuint program,
5497 GLint location,
5498 GLint v0,
5499 GLint v1,
5500 GLint v2,
5501 GLint v3)
5502{
5503 GLint xyzw[4] = {v0, v1, v2, v3};
5504 programUniform4iv(program, location, 1, xyzw);
5505}
5506
5507void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
5508{
5509 programUniform1uiv(program, location, 1, &v0);
5510}
5511
5512void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
5513{
5514 GLuint xy[2] = {v0, v1};
5515 programUniform2uiv(program, location, 1, xy);
5516}
5517
5518void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
5519{
5520 GLuint xyz[3] = {v0, v1, v2};
5521 programUniform3uiv(program, location, 1, xyz);
5522}
5523
5524void Context::programUniform4ui(GLuint program,
5525 GLint location,
5526 GLuint v0,
5527 GLuint v1,
5528 GLuint v2,
5529 GLuint v3)
5530{
5531 GLuint xyzw[4] = {v0, v1, v2, v3};
5532 programUniform4uiv(program, location, 1, xyzw);
5533}
5534
5535void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
5536{
5537 programUniform1fv(program, location, 1, &v0);
5538}
5539
5540void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
5541{
5542 GLfloat xy[2] = {v0, v1};
5543 programUniform2fv(program, location, 1, xy);
5544}
5545
5546void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
5547{
5548 GLfloat xyz[3] = {v0, v1, v2};
5549 programUniform3fv(program, location, 1, xyz);
5550}
5551
5552void Context::programUniform4f(GLuint program,
5553 GLint location,
5554 GLfloat v0,
5555 GLfloat v1,
5556 GLfloat v2,
5557 GLfloat v3)
5558{
5559 GLfloat xyzw[4] = {v0, v1, v2, v3};
5560 programUniform4fv(program, location, 1, xyzw);
5561}
5562
Jamie Madill81c2e252017-09-09 23:32:46 -04005563void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5564{
5565 Program *programObject = getProgram(program);
5566 ASSERT(programObject);
5567 if (programObject->setUniform1iv(location, count, value) ==
5568 Program::SetUniformResult::SamplerChanged)
5569 {
5570 mGLState.setObjectDirty(GL_PROGRAM);
5571 }
5572}
5573
Jiajia Qin5451d532017-11-16 17:16:34 +08005574void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5575{
5576 Program *programObject = getProgram(program);
5577 ASSERT(programObject);
5578 programObject->setUniform2iv(location, count, value);
5579}
5580
5581void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5582{
5583 Program *programObject = getProgram(program);
5584 ASSERT(programObject);
5585 programObject->setUniform3iv(location, count, value);
5586}
5587
5588void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5589{
5590 Program *programObject = getProgram(program);
5591 ASSERT(programObject);
5592 programObject->setUniform4iv(location, count, value);
5593}
5594
5595void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5596{
5597 Program *programObject = getProgram(program);
5598 ASSERT(programObject);
5599 programObject->setUniform1uiv(location, count, value);
5600}
5601
5602void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5603{
5604 Program *programObject = getProgram(program);
5605 ASSERT(programObject);
5606 programObject->setUniform2uiv(location, count, value);
5607}
5608
5609void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5610{
5611 Program *programObject = getProgram(program);
5612 ASSERT(programObject);
5613 programObject->setUniform3uiv(location, count, value);
5614}
5615
5616void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5617{
5618 Program *programObject = getProgram(program);
5619 ASSERT(programObject);
5620 programObject->setUniform4uiv(location, count, value);
5621}
5622
5623void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5624{
5625 Program *programObject = getProgram(program);
5626 ASSERT(programObject);
5627 programObject->setUniform1fv(location, count, value);
5628}
5629
5630void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5631{
5632 Program *programObject = getProgram(program);
5633 ASSERT(programObject);
5634 programObject->setUniform2fv(location, count, value);
5635}
5636
5637void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5638{
5639 Program *programObject = getProgram(program);
5640 ASSERT(programObject);
5641 programObject->setUniform3fv(location, count, value);
5642}
5643
5644void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5645{
5646 Program *programObject = getProgram(program);
5647 ASSERT(programObject);
5648 programObject->setUniform4fv(location, count, value);
5649}
5650
5651void Context::programUniformMatrix2fv(GLuint program,
5652 GLint location,
5653 GLsizei count,
5654 GLboolean transpose,
5655 const GLfloat *value)
5656{
5657 Program *programObject = getProgram(program);
5658 ASSERT(programObject);
5659 programObject->setUniformMatrix2fv(location, count, transpose, value);
5660}
5661
5662void Context::programUniformMatrix3fv(GLuint program,
5663 GLint location,
5664 GLsizei count,
5665 GLboolean transpose,
5666 const GLfloat *value)
5667{
5668 Program *programObject = getProgram(program);
5669 ASSERT(programObject);
5670 programObject->setUniformMatrix3fv(location, count, transpose, value);
5671}
5672
5673void Context::programUniformMatrix4fv(GLuint program,
5674 GLint location,
5675 GLsizei count,
5676 GLboolean transpose,
5677 const GLfloat *value)
5678{
5679 Program *programObject = getProgram(program);
5680 ASSERT(programObject);
5681 programObject->setUniformMatrix4fv(location, count, transpose, value);
5682}
5683
5684void Context::programUniformMatrix2x3fv(GLuint program,
5685 GLint location,
5686 GLsizei count,
5687 GLboolean transpose,
5688 const GLfloat *value)
5689{
5690 Program *programObject = getProgram(program);
5691 ASSERT(programObject);
5692 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
5693}
5694
5695void Context::programUniformMatrix3x2fv(GLuint program,
5696 GLint location,
5697 GLsizei count,
5698 GLboolean transpose,
5699 const GLfloat *value)
5700{
5701 Program *programObject = getProgram(program);
5702 ASSERT(programObject);
5703 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
5704}
5705
5706void Context::programUniformMatrix2x4fv(GLuint program,
5707 GLint location,
5708 GLsizei count,
5709 GLboolean transpose,
5710 const GLfloat *value)
5711{
5712 Program *programObject = getProgram(program);
5713 ASSERT(programObject);
5714 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
5715}
5716
5717void Context::programUniformMatrix4x2fv(GLuint program,
5718 GLint location,
5719 GLsizei count,
5720 GLboolean transpose,
5721 const GLfloat *value)
5722{
5723 Program *programObject = getProgram(program);
5724 ASSERT(programObject);
5725 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
5726}
5727
5728void Context::programUniformMatrix3x4fv(GLuint program,
5729 GLint location,
5730 GLsizei count,
5731 GLboolean transpose,
5732 const GLfloat *value)
5733{
5734 Program *programObject = getProgram(program);
5735 ASSERT(programObject);
5736 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
5737}
5738
5739void Context::programUniformMatrix4x3fv(GLuint program,
5740 GLint location,
5741 GLsizei count,
5742 GLboolean transpose,
5743 const GLfloat *value)
5744{
5745 Program *programObject = getProgram(program);
5746 ASSERT(programObject);
5747 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
5748}
5749
Jamie Madill81c2e252017-09-09 23:32:46 -04005750void Context::onTextureChange(const Texture *texture)
5751{
5752 // Conservatively assume all textures are dirty.
5753 // TODO(jmadill): More fine-grained update.
5754 mGLState.setObjectDirty(GL_TEXTURE);
5755}
5756
James Darpiniane8a93c62018-01-04 18:02:24 -08005757bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
5758{
5759 return mGLState.isCurrentTransformFeedback(tf);
5760}
5761bool Context::isCurrentVertexArray(const VertexArray *va) const
5762{
5763 return mGLState.isCurrentVertexArray(va);
5764}
5765
Yunchao Hea336b902017-08-02 16:05:21 +08005766void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
5767{
5768 for (int i = 0; i < count; i++)
5769 {
5770 pipelines[i] = createProgramPipeline();
5771 }
5772}
5773
5774void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
5775{
5776 for (int i = 0; i < count; i++)
5777 {
5778 if (pipelines[i] != 0)
5779 {
5780 deleteProgramPipeline(pipelines[i]);
5781 }
5782 }
5783}
5784
5785GLboolean Context::isProgramPipeline(GLuint pipeline)
5786{
5787 if (pipeline == 0)
5788 {
5789 return GL_FALSE;
5790 }
5791
5792 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
5793}
5794
Jamie Madill2b7bbc22017-12-21 17:30:38 -05005795void Context::finishFenceNV(GLuint fence)
5796{
5797 FenceNV *fenceObject = getFenceNV(fence);
5798
5799 ASSERT(fenceObject && fenceObject->isSet());
5800 handleError(fenceObject->finish());
5801}
5802
5803void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
5804{
5805 FenceNV *fenceObject = getFenceNV(fence);
5806
5807 ASSERT(fenceObject && fenceObject->isSet());
5808
5809 switch (pname)
5810 {
5811 case GL_FENCE_STATUS_NV:
5812 {
5813 // GL_NV_fence spec:
5814 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
5815 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
5816 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
5817 GLboolean status = GL_TRUE;
5818 if (fenceObject->getStatus() != GL_TRUE)
5819 {
5820 ANGLE_CONTEXT_TRY(fenceObject->test(&status));
5821 }
5822 *params = status;
5823 break;
5824 }
5825
5826 case GL_FENCE_CONDITION_NV:
5827 {
5828 *params = static_cast<GLint>(fenceObject->getCondition());
5829 break;
5830 }
5831
5832 default:
5833 UNREACHABLE();
5834 }
5835}
5836
5837void Context::getTranslatedShaderSource(GLuint shader,
5838 GLsizei bufsize,
5839 GLsizei *length,
5840 GLchar *source)
5841{
5842 Shader *shaderObject = getShader(shader);
5843 ASSERT(shaderObject);
5844 shaderObject->getTranslatedSourceWithDebugInfo(this, bufsize, length, source);
5845}
5846
5847void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
5848{
5849 Program *programObject = getProgram(program);
5850 ASSERT(programObject);
5851
5852 programObject->getUniformfv(this, location, params);
5853}
5854
5855void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
5856{
5857 Program *programObject = getProgram(program);
5858 ASSERT(programObject);
5859
5860 programObject->getUniformiv(this, location, params);
5861}
5862
5863GLboolean Context::isFenceNV(GLuint fence)
5864{
5865 FenceNV *fenceObject = getFenceNV(fence);
5866
5867 if (fenceObject == nullptr)
5868 {
5869 return GL_FALSE;
5870 }
5871
5872 // GL_NV_fence spec:
5873 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
5874 // existing fence.
5875 return fenceObject->isSet();
5876}
5877
5878void Context::readnPixels(GLint x,
5879 GLint y,
5880 GLsizei width,
5881 GLsizei height,
5882 GLenum format,
5883 GLenum type,
5884 GLsizei bufSize,
5885 void *data)
5886{
5887 return readPixels(x, y, width, height, format, type, data);
5888}
5889
Jamie Madill007530e2017-12-28 14:27:04 -05005890void Context::setFenceNV(GLuint fence, GLenum condition)
5891{
5892 ASSERT(condition == GL_ALL_COMPLETED_NV);
5893
5894 FenceNV *fenceObject = getFenceNV(fence);
5895 ASSERT(fenceObject != nullptr);
5896 handleError(fenceObject->set(condition));
5897}
5898
5899GLboolean Context::testFenceNV(GLuint fence)
5900{
5901 FenceNV *fenceObject = getFenceNV(fence);
5902
5903 ASSERT(fenceObject != nullptr);
5904 ASSERT(fenceObject->isSet() == GL_TRUE);
5905
5906 GLboolean result = GL_TRUE;
5907 Error error = fenceObject->test(&result);
5908 if (error.isError())
5909 {
5910 handleError(error);
5911 return GL_TRUE;
5912 }
5913
5914 return result;
5915}
5916
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005917void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05005918{
5919 Texture *texture = getTargetTexture(target);
5920 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005921 handleError(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05005922}
5923
Jamie Madillfa920eb2018-01-04 11:45:50 -05005924void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05005925{
5926 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
5927 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
5928 handleError(renderbuffer->setStorageEGLImageTarget(this, imageObject));
5929}
5930
Jamie Madillfa920eb2018-01-04 11:45:50 -05005931void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
5932{
5933 UNIMPLEMENTED();
5934}
5935
Geoff Lang2aaa7b42018-01-12 17:17:27 -05005936void Context::alphaFunc(GLenum func, GLfloat ref)
5937{
5938 UNIMPLEMENTED();
5939}
5940
5941void Context::alphaFuncx(GLenum func, GLfixed ref)
5942{
5943 UNIMPLEMENTED();
5944}
5945
5946void Context::clearColorx(GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha)
5947{
5948 UNIMPLEMENTED();
5949}
5950
5951void Context::clearDepthx(GLfixed depth)
5952{
5953 UNIMPLEMENTED();
5954}
5955
5956void Context::clientActiveTexture(GLenum texture)
5957{
5958 UNIMPLEMENTED();
5959}
5960
5961void Context::clipPlanef(GLenum p, const GLfloat *eqn)
5962{
5963 UNIMPLEMENTED();
5964}
5965
5966void Context::clipPlanex(GLenum plane, const GLfixed *equation)
5967{
5968 UNIMPLEMENTED();
5969}
5970
5971void Context::color4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
5972{
5973 UNIMPLEMENTED();
5974}
5975
5976void Context::color4ub(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha)
5977{
5978 UNIMPLEMENTED();
5979}
5980
5981void Context::color4x(GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha)
5982{
5983 UNIMPLEMENTED();
5984}
5985
5986void Context::colorPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
5987{
5988 UNIMPLEMENTED();
5989}
5990
5991void Context::cullFace(GLenum mode)
5992{
5993 UNIMPLEMENTED();
5994}
5995
5996void Context::depthRangex(GLfixed n, GLfixed f)
5997{
5998 UNIMPLEMENTED();
5999}
6000
6001void Context::disableClientState(GLenum array)
6002{
6003 UNIMPLEMENTED();
6004}
6005
6006void Context::enableClientState(GLenum array)
6007{
6008 UNIMPLEMENTED();
6009}
6010
6011void Context::fogf(GLenum pname, GLfloat param)
6012{
6013 UNIMPLEMENTED();
6014}
6015
6016void Context::fogfv(GLenum pname, const GLfloat *params)
6017{
6018 UNIMPLEMENTED();
6019}
6020
6021void Context::fogx(GLenum pname, GLfixed param)
6022{
6023 UNIMPLEMENTED();
6024}
6025
6026void Context::fogxv(GLenum pname, const GLfixed *param)
6027{
6028 UNIMPLEMENTED();
6029}
6030
6031void Context::frustumf(GLfloat l, GLfloat r, GLfloat b, GLfloat t, GLfloat n, GLfloat f)
6032{
6033 UNIMPLEMENTED();
6034}
6035
6036void Context::frustumx(GLfixed l, GLfixed r, GLfixed b, GLfixed t, GLfixed n, GLfixed f)
6037{
6038 UNIMPLEMENTED();
6039}
6040
6041void Context::getBufferParameteriv(GLenum target, GLenum pname, GLint *params)
6042{
6043 UNIMPLEMENTED();
6044}
6045
6046void Context::getClipPlanef(GLenum plane, GLfloat *equation)
6047{
6048 UNIMPLEMENTED();
6049}
6050
6051void Context::getClipPlanex(GLenum plane, GLfixed *equation)
6052{
6053 UNIMPLEMENTED();
6054}
6055
6056void Context::getFixedv(GLenum pname, GLfixed *params)
6057{
6058 UNIMPLEMENTED();
6059}
6060
6061void Context::getLightfv(GLenum light, GLenum pname, GLfloat *params)
6062{
6063 UNIMPLEMENTED();
6064}
6065
6066void Context::getLightxv(GLenum light, GLenum pname, GLfixed *params)
6067{
6068 UNIMPLEMENTED();
6069}
6070
6071void Context::getMaterialfv(GLenum face, GLenum pname, GLfloat *params)
6072{
6073 UNIMPLEMENTED();
6074}
6075
6076void Context::getMaterialxv(GLenum face, GLenum pname, GLfixed *params)
6077{
6078 UNIMPLEMENTED();
6079}
6080
6081void Context::getTexEnvfv(GLenum target, GLenum pname, GLfloat *params)
6082{
6083 UNIMPLEMENTED();
6084}
6085
6086void Context::getTexEnviv(GLenum target, GLenum pname, GLint *params)
6087{
6088 UNIMPLEMENTED();
6089}
6090
6091void Context::getTexEnvxv(GLenum target, GLenum pname, GLfixed *params)
6092{
6093 UNIMPLEMENTED();
6094}
6095
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006096void Context::getTexParameterxv(TextureType target, GLenum pname, GLfixed *params)
Geoff Lang2aaa7b42018-01-12 17:17:27 -05006097{
6098 UNIMPLEMENTED();
6099}
6100
6101void Context::lightModelf(GLenum pname, GLfloat param)
6102{
6103 UNIMPLEMENTED();
6104}
6105
6106void Context::lightModelfv(GLenum pname, const GLfloat *params)
6107{
6108 UNIMPLEMENTED();
6109}
6110
6111void Context::lightModelx(GLenum pname, GLfixed param)
6112{
6113 UNIMPLEMENTED();
6114}
6115
6116void Context::lightModelxv(GLenum pname, const GLfixed *param)
6117{
6118 UNIMPLEMENTED();
6119}
6120
6121void Context::lightf(GLenum light, GLenum pname, GLfloat param)
6122{
6123 UNIMPLEMENTED();
6124}
6125
6126void Context::lightfv(GLenum light, GLenum pname, const GLfloat *params)
6127{
6128 UNIMPLEMENTED();
6129}
6130
6131void Context::lightx(GLenum light, GLenum pname, GLfixed param)
6132{
6133 UNIMPLEMENTED();
6134}
6135
6136void Context::lightxv(GLenum light, GLenum pname, const GLfixed *params)
6137{
6138 UNIMPLEMENTED();
6139}
6140
6141void Context::lineWidthx(GLfixed width)
6142{
6143 UNIMPLEMENTED();
6144}
6145
6146void Context::loadIdentity()
6147{
6148 UNIMPLEMENTED();
6149}
6150
6151void Context::loadMatrixf(const GLfloat *m)
6152{
6153 UNIMPLEMENTED();
6154}
6155
6156void Context::loadMatrixx(const GLfixed *m)
6157{
6158 UNIMPLEMENTED();
6159}
6160
6161void Context::logicOp(GLenum opcode)
6162{
6163 UNIMPLEMENTED();
6164}
6165
6166void Context::materialf(GLenum face, GLenum pname, GLfloat param)
6167{
6168 UNIMPLEMENTED();
6169}
6170
6171void Context::materialfv(GLenum face, GLenum pname, const GLfloat *params)
6172{
6173 UNIMPLEMENTED();
6174}
6175
6176void Context::materialx(GLenum face, GLenum pname, GLfixed param)
6177{
6178 UNIMPLEMENTED();
6179}
6180
6181void Context::materialxv(GLenum face, GLenum pname, const GLfixed *param)
6182{
6183 UNIMPLEMENTED();
6184}
6185
6186void Context::matrixMode(GLenum mode)
6187{
6188 UNIMPLEMENTED();
6189}
6190
6191void Context::multMatrixf(const GLfloat *m)
6192{
6193 UNIMPLEMENTED();
6194}
6195
6196void Context::multMatrixx(const GLfixed *m)
6197{
6198 UNIMPLEMENTED();
6199}
6200
6201void Context::multiTexCoord4f(GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q)
6202{
6203 UNIMPLEMENTED();
6204}
6205
6206void Context::multiTexCoord4x(GLenum texture, GLfixed s, GLfixed t, GLfixed r, GLfixed q)
6207{
6208 UNIMPLEMENTED();
6209}
6210
6211void Context::normal3f(GLfloat nx, GLfloat ny, GLfloat nz)
6212{
6213 UNIMPLEMENTED();
6214}
6215
6216void Context::normal3x(GLfixed nx, GLfixed ny, GLfixed nz)
6217{
6218 UNIMPLEMENTED();
6219}
6220
6221void Context::normalPointer(GLenum type, GLsizei stride, const void *pointer)
6222{
6223 UNIMPLEMENTED();
6224}
6225
6226void Context::orthof(GLfloat l, GLfloat r, GLfloat b, GLfloat t, GLfloat n, GLfloat f)
6227{
6228 UNIMPLEMENTED();
6229}
6230
6231void Context::orthox(GLfixed l, GLfixed r, GLfixed b, GLfixed t, GLfixed n, GLfixed f)
6232{
6233 UNIMPLEMENTED();
6234}
6235
6236void Context::pointParameterf(GLenum pname, GLfloat param)
6237{
6238 UNIMPLEMENTED();
6239}
6240
6241void Context::pointParameterfv(GLenum pname, const GLfloat *params)
6242{
6243 UNIMPLEMENTED();
6244}
6245
6246void Context::pointParameterx(GLenum pname, GLfixed param)
6247{
6248 UNIMPLEMENTED();
6249}
6250
6251void Context::pointParameterxv(GLenum pname, const GLfixed *params)
6252{
6253 UNIMPLEMENTED();
6254}
6255
6256void Context::pointSize(GLfloat size)
6257{
6258 UNIMPLEMENTED();
6259}
6260
6261void Context::pointSizex(GLfixed size)
6262{
6263 UNIMPLEMENTED();
6264}
6265
6266void Context::polygonOffsetx(GLfixed factor, GLfixed units)
6267{
6268 UNIMPLEMENTED();
6269}
6270
6271void Context::popMatrix()
6272{
6273 UNIMPLEMENTED();
6274}
6275
6276void Context::pushMatrix()
6277{
6278 UNIMPLEMENTED();
6279}
6280
6281void Context::rotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z)
6282{
6283 UNIMPLEMENTED();
6284}
6285
6286void Context::rotatex(GLfixed angle, GLfixed x, GLfixed y, GLfixed z)
6287{
6288 UNIMPLEMENTED();
6289}
6290
6291void Context::sampleCoveragex(GLclampx value, GLboolean invert)
6292{
6293 UNIMPLEMENTED();
6294}
6295
6296void Context::scalef(GLfloat x, GLfloat y, GLfloat z)
6297{
6298 UNIMPLEMENTED();
6299}
6300
6301void Context::scalex(GLfixed x, GLfixed y, GLfixed z)
6302{
6303 UNIMPLEMENTED();
6304}
6305
6306void Context::shadeModel(GLenum mode)
6307{
6308 UNIMPLEMENTED();
6309}
6310
6311void Context::texCoordPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
6312{
6313 UNIMPLEMENTED();
6314}
6315
6316void Context::texEnvf(GLenum target, GLenum pname, GLfloat param)
6317{
6318 UNIMPLEMENTED();
6319}
6320
6321void Context::texEnvfv(GLenum target, GLenum pname, const GLfloat *params)
6322{
6323 UNIMPLEMENTED();
6324}
6325
6326void Context::texEnvi(GLenum target, GLenum pname, GLint param)
6327{
6328 UNIMPLEMENTED();
6329}
6330
6331void Context::texEnviv(GLenum target, GLenum pname, const GLint *params)
6332{
6333 UNIMPLEMENTED();
6334}
6335
6336void Context::texEnvx(GLenum target, GLenum pname, GLfixed param)
6337{
6338 UNIMPLEMENTED();
6339}
6340
6341void Context::texEnvxv(GLenum target, GLenum pname, const GLfixed *params)
6342{
6343 UNIMPLEMENTED();
6344}
6345
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006346void Context::texParameterx(TextureType target, GLenum pname, GLfixed param)
Geoff Lang2aaa7b42018-01-12 17:17:27 -05006347{
6348 UNIMPLEMENTED();
6349}
6350
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006351void Context::texParameterxv(TextureType target, GLenum pname, const GLfixed *params)
Geoff Lang2aaa7b42018-01-12 17:17:27 -05006352{
6353 UNIMPLEMENTED();
6354}
6355
6356void Context::translatef(GLfloat x, GLfloat y, GLfloat z)
6357{
6358 UNIMPLEMENTED();
6359}
6360
6361void Context::translatex(GLfixed x, GLfixed y, GLfixed z)
6362{
6363 UNIMPLEMENTED();
6364}
6365
6366void Context::vertexPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
6367{
6368 UNIMPLEMENTED();
6369}
6370
6371void Context::drawTexf(GLfloat x, GLfloat y, GLfloat z, GLfloat width, GLfloat height)
6372{
6373 UNIMPLEMENTED();
6374}
6375
6376void Context::drawTexfv(const GLfloat *coords)
6377{
6378 UNIMPLEMENTED();
6379}
6380
6381void Context::drawTexi(GLint x, GLint y, GLint z, GLint width, GLint height)
6382{
6383 UNIMPLEMENTED();
6384}
6385
6386void Context::drawTexiv(const GLint *coords)
6387{
6388 UNIMPLEMENTED();
6389}
6390
6391void Context::drawTexs(GLshort x, GLshort y, GLshort z, GLshort width, GLshort height)
6392{
6393 UNIMPLEMENTED();
6394}
6395
6396void Context::drawTexsv(const GLshort *coords)
6397{
6398 UNIMPLEMENTED();
6399}
6400
6401void Context::drawTexx(GLfixed x, GLfixed y, GLfixed z, GLfixed width, GLfixed height)
6402{
6403 UNIMPLEMENTED();
6404}
6405
6406void Context::drawTexxv(const GLfixed *coords)
6407{
6408 UNIMPLEMENTED();
6409}
6410
6411void Context::currentPaletteMatrix(GLuint matrixpaletteindex)
6412{
6413 UNIMPLEMENTED();
6414}
6415
6416void Context::loadPaletteFromModelViewMatrix()
6417{
6418 UNIMPLEMENTED();
6419}
6420
6421void Context::matrixIndexPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
6422{
6423 UNIMPLEMENTED();
6424}
6425
6426void Context::weightPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
6427{
6428 UNIMPLEMENTED();
6429}
6430
6431void Context::pointSizePointer(GLenum type, GLsizei stride, const void *pointer)
6432{
6433 UNIMPLEMENTED();
6434}
6435
6436GLbitfield Context::queryMatrixx(GLfixed *mantissa, GLint *exponent)
6437{
6438 UNIMPLEMENTED();
6439 return 0;
6440}
6441
Jamie Madill5b772312018-03-08 20:28:32 -05006442bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
6443{
6444 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
6445 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
6446 // to the fact that it is stored internally as a float, and so would require conversion
6447 // if returned from Context::getIntegerv. Since this conversion is already implemented
6448 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
6449 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
6450 // application.
6451 switch (pname)
6452 {
6453 case GL_COMPRESSED_TEXTURE_FORMATS:
6454 {
6455 *type = GL_INT;
6456 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
6457 return true;
6458 }
6459 case GL_SHADER_BINARY_FORMATS:
6460 {
6461 *type = GL_INT;
6462 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
6463 return true;
6464 }
6465
6466 case GL_MAX_VERTEX_ATTRIBS:
6467 case GL_MAX_VERTEX_UNIFORM_VECTORS:
6468 case GL_MAX_VARYING_VECTORS:
6469 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
6470 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
6471 case GL_MAX_TEXTURE_IMAGE_UNITS:
6472 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
6473 case GL_MAX_RENDERBUFFER_SIZE:
6474 case GL_NUM_SHADER_BINARY_FORMATS:
6475 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
6476 case GL_ARRAY_BUFFER_BINDING:
6477 case GL_FRAMEBUFFER_BINDING:
6478 case GL_RENDERBUFFER_BINDING:
6479 case GL_CURRENT_PROGRAM:
6480 case GL_PACK_ALIGNMENT:
6481 case GL_UNPACK_ALIGNMENT:
6482 case GL_GENERATE_MIPMAP_HINT:
6483 case GL_RED_BITS:
6484 case GL_GREEN_BITS:
6485 case GL_BLUE_BITS:
6486 case GL_ALPHA_BITS:
6487 case GL_DEPTH_BITS:
6488 case GL_STENCIL_BITS:
6489 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
6490 case GL_CULL_FACE_MODE:
6491 case GL_FRONT_FACE:
6492 case GL_ACTIVE_TEXTURE:
6493 case GL_STENCIL_FUNC:
6494 case GL_STENCIL_VALUE_MASK:
6495 case GL_STENCIL_REF:
6496 case GL_STENCIL_FAIL:
6497 case GL_STENCIL_PASS_DEPTH_FAIL:
6498 case GL_STENCIL_PASS_DEPTH_PASS:
6499 case GL_STENCIL_BACK_FUNC:
6500 case GL_STENCIL_BACK_VALUE_MASK:
6501 case GL_STENCIL_BACK_REF:
6502 case GL_STENCIL_BACK_FAIL:
6503 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
6504 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
6505 case GL_DEPTH_FUNC:
6506 case GL_BLEND_SRC_RGB:
6507 case GL_BLEND_SRC_ALPHA:
6508 case GL_BLEND_DST_RGB:
6509 case GL_BLEND_DST_ALPHA:
6510 case GL_BLEND_EQUATION_RGB:
6511 case GL_BLEND_EQUATION_ALPHA:
6512 case GL_STENCIL_WRITEMASK:
6513 case GL_STENCIL_BACK_WRITEMASK:
6514 case GL_STENCIL_CLEAR_VALUE:
6515 case GL_SUBPIXEL_BITS:
6516 case GL_MAX_TEXTURE_SIZE:
6517 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
6518 case GL_SAMPLE_BUFFERS:
6519 case GL_SAMPLES:
6520 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
6521 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
6522 case GL_TEXTURE_BINDING_2D:
6523 case GL_TEXTURE_BINDING_CUBE_MAP:
6524 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
6525 {
6526 *type = GL_INT;
6527 *numParams = 1;
6528 return true;
6529 }
6530 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6531 {
6532 if (!getExtensions().packReverseRowOrder)
6533 {
6534 return false;
6535 }
6536 *type = GL_INT;
6537 *numParams = 1;
6538 return true;
6539 }
6540 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
6541 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
6542 {
6543 if (!getExtensions().textureRectangle)
6544 {
6545 return false;
6546 }
6547 *type = GL_INT;
6548 *numParams = 1;
6549 return true;
6550 }
6551 case GL_MAX_DRAW_BUFFERS_EXT:
6552 case GL_MAX_COLOR_ATTACHMENTS_EXT:
6553 {
6554 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
6555 {
6556 return false;
6557 }
6558 *type = GL_INT;
6559 *numParams = 1;
6560 return true;
6561 }
6562 case GL_MAX_VIEWPORT_DIMS:
6563 {
6564 *type = GL_INT;
6565 *numParams = 2;
6566 return true;
6567 }
6568 case GL_VIEWPORT:
6569 case GL_SCISSOR_BOX:
6570 {
6571 *type = GL_INT;
6572 *numParams = 4;
6573 return true;
6574 }
6575 case GL_SHADER_COMPILER:
6576 case GL_SAMPLE_COVERAGE_INVERT:
6577 case GL_DEPTH_WRITEMASK:
6578 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
6579 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
6580 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
6581 // bool-natural
6582 case GL_SAMPLE_COVERAGE:
6583 case GL_SCISSOR_TEST:
6584 case GL_STENCIL_TEST:
6585 case GL_DEPTH_TEST:
6586 case GL_BLEND:
6587 case GL_DITHER:
6588 case GL_CONTEXT_ROBUST_ACCESS_EXT:
6589 {
6590 *type = GL_BOOL;
6591 *numParams = 1;
6592 return true;
6593 }
6594 case GL_COLOR_WRITEMASK:
6595 {
6596 *type = GL_BOOL;
6597 *numParams = 4;
6598 return true;
6599 }
6600 case GL_POLYGON_OFFSET_FACTOR:
6601 case GL_POLYGON_OFFSET_UNITS:
6602 case GL_SAMPLE_COVERAGE_VALUE:
6603 case GL_DEPTH_CLEAR_VALUE:
6604 case GL_LINE_WIDTH:
6605 {
6606 *type = GL_FLOAT;
6607 *numParams = 1;
6608 return true;
6609 }
6610 case GL_ALIASED_LINE_WIDTH_RANGE:
6611 case GL_ALIASED_POINT_SIZE_RANGE:
6612 case GL_DEPTH_RANGE:
6613 {
6614 *type = GL_FLOAT;
6615 *numParams = 2;
6616 return true;
6617 }
6618 case GL_COLOR_CLEAR_VALUE:
6619 case GL_BLEND_COLOR:
6620 {
6621 *type = GL_FLOAT;
6622 *numParams = 4;
6623 return true;
6624 }
6625 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
6626 if (!getExtensions().textureFilterAnisotropic)
6627 {
6628 return false;
6629 }
6630 *type = GL_FLOAT;
6631 *numParams = 1;
6632 return true;
6633 case GL_TIMESTAMP_EXT:
6634 if (!getExtensions().disjointTimerQuery)
6635 {
6636 return false;
6637 }
6638 *type = GL_INT_64_ANGLEX;
6639 *numParams = 1;
6640 return true;
6641 case GL_GPU_DISJOINT_EXT:
6642 if (!getExtensions().disjointTimerQuery)
6643 {
6644 return false;
6645 }
6646 *type = GL_INT;
6647 *numParams = 1;
6648 return true;
6649 case GL_COVERAGE_MODULATION_CHROMIUM:
6650 if (!getExtensions().framebufferMixedSamples)
6651 {
6652 return false;
6653 }
6654 *type = GL_INT;
6655 *numParams = 1;
6656 return true;
6657 case GL_TEXTURE_BINDING_EXTERNAL_OES:
6658 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
6659 {
6660 return false;
6661 }
6662 *type = GL_INT;
6663 *numParams = 1;
6664 return true;
6665 }
6666
6667 if (getExtensions().debug)
6668 {
6669 switch (pname)
6670 {
6671 case GL_DEBUG_LOGGED_MESSAGES:
6672 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
6673 case GL_DEBUG_GROUP_STACK_DEPTH:
6674 case GL_MAX_DEBUG_MESSAGE_LENGTH:
6675 case GL_MAX_DEBUG_LOGGED_MESSAGES:
6676 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
6677 case GL_MAX_LABEL_LENGTH:
6678 *type = GL_INT;
6679 *numParams = 1;
6680 return true;
6681
6682 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
6683 case GL_DEBUG_OUTPUT:
6684 *type = GL_BOOL;
6685 *numParams = 1;
6686 return true;
6687 }
6688 }
6689
6690 if (getExtensions().multisampleCompatibility)
6691 {
6692 switch (pname)
6693 {
6694 case GL_MULTISAMPLE_EXT:
6695 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
6696 *type = GL_BOOL;
6697 *numParams = 1;
6698 return true;
6699 }
6700 }
6701
6702 if (getExtensions().pathRendering)
6703 {
6704 switch (pname)
6705 {
6706 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
6707 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
6708 *type = GL_FLOAT;
6709 *numParams = 16;
6710 return true;
6711 }
6712 }
6713
6714 if (getExtensions().bindGeneratesResource)
6715 {
6716 switch (pname)
6717 {
6718 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
6719 *type = GL_BOOL;
6720 *numParams = 1;
6721 return true;
6722 }
6723 }
6724
6725 if (getExtensions().clientArrays)
6726 {
6727 switch (pname)
6728 {
6729 case GL_CLIENT_ARRAYS_ANGLE:
6730 *type = GL_BOOL;
6731 *numParams = 1;
6732 return true;
6733 }
6734 }
6735
6736 if (getExtensions().sRGBWriteControl)
6737 {
6738 switch (pname)
6739 {
6740 case GL_FRAMEBUFFER_SRGB_EXT:
6741 *type = GL_BOOL;
6742 *numParams = 1;
6743 return true;
6744 }
6745 }
6746
6747 if (getExtensions().robustResourceInitialization &&
6748 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
6749 {
6750 *type = GL_BOOL;
6751 *numParams = 1;
6752 return true;
6753 }
6754
6755 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
6756 {
6757 *type = GL_BOOL;
6758 *numParams = 1;
6759 return true;
6760 }
6761
6762 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
6763 switch (pname)
6764 {
6765 // case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE // equivalent to FRAMEBUFFER_BINDING
6766 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
6767 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
6768 {
6769 return false;
6770 }
6771 *type = GL_INT;
6772 *numParams = 1;
6773 return true;
6774
6775 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
6776 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
6777 {
6778 return false;
6779 }
6780 *type = GL_INT;
6781 *numParams = 1;
6782 return true;
6783
6784 case GL_PROGRAM_BINARY_FORMATS_OES:
6785 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
6786 {
6787 return false;
6788 }
6789 *type = GL_INT;
6790 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
6791 return true;
6792
6793 case GL_PACK_ROW_LENGTH:
6794 case GL_PACK_SKIP_ROWS:
6795 case GL_PACK_SKIP_PIXELS:
6796 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
6797 {
6798 return false;
6799 }
6800 *type = GL_INT;
6801 *numParams = 1;
6802 return true;
6803 case GL_UNPACK_ROW_LENGTH:
6804 case GL_UNPACK_SKIP_ROWS:
6805 case GL_UNPACK_SKIP_PIXELS:
6806 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
6807 {
6808 return false;
6809 }
6810 *type = GL_INT;
6811 *numParams = 1;
6812 return true;
6813 case GL_VERTEX_ARRAY_BINDING:
6814 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
6815 {
6816 return false;
6817 }
6818 *type = GL_INT;
6819 *numParams = 1;
6820 return true;
6821 case GL_PIXEL_PACK_BUFFER_BINDING:
6822 case GL_PIXEL_UNPACK_BUFFER_BINDING:
6823 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
6824 {
6825 return false;
6826 }
6827 *type = GL_INT;
6828 *numParams = 1;
6829 return true;
6830 case GL_MAX_SAMPLES:
6831 {
6832 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
6833 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
6834 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
6835 {
6836 return false;
6837 }
6838 *type = GL_INT;
6839 *numParams = 1;
6840 return true;
6841
6842 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
6843 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
6844 {
6845 return false;
6846 }
6847 *type = GL_INT;
6848 *numParams = 1;
6849 return true;
6850 }
6851 }
6852
6853 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
6854 {
6855 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
6856 {
6857 return false;
6858 }
6859 *type = GL_INT;
6860 *numParams = 1;
6861 return true;
6862 }
6863
6864 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
6865 {
6866 *type = GL_INT;
6867 *numParams = 1;
6868 return true;
6869 }
6870
6871 if (getClientVersion() < Version(3, 0))
6872 {
6873 return false;
6874 }
6875
6876 // Check for ES3.0+ parameter names
6877 switch (pname)
6878 {
6879 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
6880 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
6881 case GL_UNIFORM_BUFFER_BINDING:
6882 case GL_TRANSFORM_FEEDBACK_BINDING:
6883 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
6884 case GL_COPY_READ_BUFFER_BINDING:
6885 case GL_COPY_WRITE_BUFFER_BINDING:
6886 case GL_SAMPLER_BINDING:
6887 case GL_READ_BUFFER:
6888 case GL_TEXTURE_BINDING_3D:
6889 case GL_TEXTURE_BINDING_2D_ARRAY:
6890 case GL_MAX_3D_TEXTURE_SIZE:
6891 case GL_MAX_ARRAY_TEXTURE_LAYERS:
6892 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
6893 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
6894 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
6895 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
6896 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
6897 case GL_MAX_VARYING_COMPONENTS:
6898 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
6899 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
6900 case GL_MIN_PROGRAM_TEXEL_OFFSET:
6901 case GL_MAX_PROGRAM_TEXEL_OFFSET:
6902 case GL_NUM_EXTENSIONS:
6903 case GL_MAJOR_VERSION:
6904 case GL_MINOR_VERSION:
6905 case GL_MAX_ELEMENTS_INDICES:
6906 case GL_MAX_ELEMENTS_VERTICES:
6907 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
6908 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
6909 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
6910 case GL_UNPACK_IMAGE_HEIGHT:
6911 case GL_UNPACK_SKIP_IMAGES:
6912 {
6913 *type = GL_INT;
6914 *numParams = 1;
6915 return true;
6916 }
6917
6918 case GL_MAX_ELEMENT_INDEX:
6919 case GL_MAX_UNIFORM_BLOCK_SIZE:
6920 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
6921 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
6922 case GL_MAX_SERVER_WAIT_TIMEOUT:
6923 {
6924 *type = GL_INT_64_ANGLEX;
6925 *numParams = 1;
6926 return true;
6927 }
6928
6929 case GL_TRANSFORM_FEEDBACK_ACTIVE:
6930 case GL_TRANSFORM_FEEDBACK_PAUSED:
6931 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
6932 case GL_RASTERIZER_DISCARD:
6933 {
6934 *type = GL_BOOL;
6935 *numParams = 1;
6936 return true;
6937 }
6938
6939 case GL_MAX_TEXTURE_LOD_BIAS:
6940 {
6941 *type = GL_FLOAT;
6942 *numParams = 1;
6943 return true;
6944 }
6945 }
6946
6947 if (getExtensions().requestExtension)
6948 {
6949 switch (pname)
6950 {
6951 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
6952 *type = GL_INT;
6953 *numParams = 1;
6954 return true;
6955 }
6956 }
6957
6958 if (getClientVersion() < Version(3, 1))
6959 {
6960 return false;
6961 }
6962
6963 switch (pname)
6964 {
6965 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
6966 case GL_DRAW_INDIRECT_BUFFER_BINDING:
6967 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
6968 case GL_MAX_FRAMEBUFFER_WIDTH:
6969 case GL_MAX_FRAMEBUFFER_HEIGHT:
6970 case GL_MAX_FRAMEBUFFER_SAMPLES:
6971 case GL_MAX_SAMPLE_MASK_WORDS:
6972 case GL_MAX_COLOR_TEXTURE_SAMPLES:
6973 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
6974 case GL_MAX_INTEGER_SAMPLES:
6975 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
6976 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
6977 case GL_MAX_VERTEX_ATTRIB_STRIDE:
6978 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
6979 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
6980 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
6981 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
6982 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
6983 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
6984 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
6985 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
6986 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
6987 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
6988 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
6989 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
6990 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
6991 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
6992 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
6993 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
6994 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
6995 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
6996 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
6997 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
6998 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
6999 case GL_MAX_UNIFORM_LOCATIONS:
7000 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
7001 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
7002 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
7003 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
7004 case GL_MAX_IMAGE_UNITS:
7005 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
7006 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
7007 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
7008 case GL_SHADER_STORAGE_BUFFER_BINDING:
7009 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
7010 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
7011 *type = GL_INT;
7012 *numParams = 1;
7013 return true;
7014 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7015 *type = GL_INT_64_ANGLEX;
7016 *numParams = 1;
7017 return true;
7018 case GL_SAMPLE_MASK:
7019 *type = GL_BOOL;
7020 *numParams = 1;
7021 return true;
7022 }
7023
7024 if (getExtensions().geometryShader)
7025 {
7026 switch (pname)
7027 {
7028 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7029 case GL_LAYER_PROVOKING_VERTEX_EXT:
7030 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7031 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7032 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7033 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7034 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7035 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7036 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7037 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7038 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7039 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7040 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7041 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7042 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7043 *type = GL_INT;
7044 *numParams = 1;
7045 return true;
7046 }
7047 }
7048
7049 return false;
7050}
7051
7052bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7053{
7054 if (getClientVersion() < Version(3, 0))
7055 {
7056 return false;
7057 }
7058
7059 switch (target)
7060 {
7061 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7062 case GL_UNIFORM_BUFFER_BINDING:
7063 {
7064 *type = GL_INT;
7065 *numParams = 1;
7066 return true;
7067 }
7068 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7069 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7070 case GL_UNIFORM_BUFFER_START:
7071 case GL_UNIFORM_BUFFER_SIZE:
7072 {
7073 *type = GL_INT_64_ANGLEX;
7074 *numParams = 1;
7075 return true;
7076 }
7077 }
7078
7079 if (getClientVersion() < Version(3, 1))
7080 {
7081 return false;
7082 }
7083
7084 switch (target)
7085 {
7086 case GL_IMAGE_BINDING_LAYERED:
7087 {
7088 *type = GL_BOOL;
7089 *numParams = 1;
7090 return true;
7091 }
7092 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7093 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7094 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7095 case GL_SHADER_STORAGE_BUFFER_BINDING:
7096 case GL_VERTEX_BINDING_BUFFER:
7097 case GL_VERTEX_BINDING_DIVISOR:
7098 case GL_VERTEX_BINDING_OFFSET:
7099 case GL_VERTEX_BINDING_STRIDE:
7100 case GL_SAMPLE_MASK_VALUE:
7101 case GL_IMAGE_BINDING_NAME:
7102 case GL_IMAGE_BINDING_LEVEL:
7103 case GL_IMAGE_BINDING_LAYER:
7104 case GL_IMAGE_BINDING_ACCESS:
7105 case GL_IMAGE_BINDING_FORMAT:
7106 {
7107 *type = GL_INT;
7108 *numParams = 1;
7109 return true;
7110 }
7111 case GL_ATOMIC_COUNTER_BUFFER_START:
7112 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
7113 case GL_SHADER_STORAGE_BUFFER_START:
7114 case GL_SHADER_STORAGE_BUFFER_SIZE:
7115 {
7116 *type = GL_INT_64_ANGLEX;
7117 *numParams = 1;
7118 return true;
7119 }
7120 }
7121
7122 return false;
7123}
7124
7125Program *Context::getProgram(GLuint handle) const
7126{
7127 return mState.mShaderPrograms->getProgram(handle);
7128}
7129
7130Shader *Context::getShader(GLuint handle) const
7131{
7132 return mState.mShaderPrograms->getShader(handle);
7133}
7134
7135bool Context::isTextureGenerated(GLuint texture) const
7136{
7137 return mState.mTextures->isHandleGenerated(texture);
7138}
7139
7140bool Context::isBufferGenerated(GLuint buffer) const
7141{
7142 return mState.mBuffers->isHandleGenerated(buffer);
7143}
7144
7145bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
7146{
7147 return mState.mRenderbuffers->isHandleGenerated(renderbuffer);
7148}
7149
7150bool Context::isFramebufferGenerated(GLuint framebuffer) const
7151{
7152 return mState.mFramebuffers->isHandleGenerated(framebuffer);
7153}
7154
7155bool Context::isProgramPipelineGenerated(GLuint pipeline) const
7156{
7157 return mState.mPipelines->isHandleGenerated(pipeline);
7158}
7159
7160bool Context::usingDisplayTextureShareGroup() const
7161{
7162 return mDisplayTextureShareGroup;
7163}
7164
7165GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
7166{
7167 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
7168 internalformat == GL_DEPTH_STENCIL
7169 ? GL_DEPTH24_STENCIL8
7170 : internalformat;
7171}
7172
Jamie Madillc29968b2016-01-20 11:17:23 -05007173} // namespace gl