blob: dd554a3edc7dd60fd46c3188e8e1657ecd3d2665 [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:
1596 mGLState.getIntegerv(this, pname, params);
1597 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 Madilldd43e6c2017-03-24 14:18:49 -04003342 if (framebuffer->checkStatus(this) != GL_FRAMEBUFFER_COMPLETE)
Jamie Madillc29968b2016-01-20 11:17:23 -05003343 {
Jamie Madill437fa652016-05-03 15:13:24 -04003344 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003345 }
Jamie Madill437fa652016-05-03 15:13:24 -04003346
Jamie Madill4928b7c2017-06-20 12:57:39 -04003347 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003348}
3349
3350void Context::invalidateSubFramebuffer(GLenum target,
3351 GLsizei numAttachments,
3352 const GLenum *attachments,
3353 GLint x,
3354 GLint y,
3355 GLsizei width,
3356 GLsizei height)
3357{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003358 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003359 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003360
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003361 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003362 ASSERT(framebuffer);
3363
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003364 if (framebuffer->checkStatus(this) != GL_FRAMEBUFFER_COMPLETE)
Jamie Madillc29968b2016-01-20 11:17:23 -05003365 {
Jamie Madill437fa652016-05-03 15:13:24 -04003366 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003367 }
Jamie Madill437fa652016-05-03 15:13:24 -04003368
3369 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003370 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003371}
3372
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003373void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003374 GLint level,
3375 GLint internalformat,
3376 GLsizei width,
3377 GLsizei height,
3378 GLint border,
3379 GLenum format,
3380 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003381 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003382{
Jamie Madillbc918e72018-03-08 09:47:21 -05003383 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003384
3385 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003386 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003387 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3388 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003389}
3390
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003391void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003392 GLint level,
3393 GLint internalformat,
3394 GLsizei width,
3395 GLsizei height,
3396 GLsizei depth,
3397 GLint border,
3398 GLenum format,
3399 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003400 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003401{
Jamie Madillbc918e72018-03-08 09:47:21 -05003402 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003403
3404 Extents size(width, height, depth);
3405 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003406 handleError(texture->setImage(this, mGLState.getUnpackState(),
3407 NonCubeTextureTypeToTarget(target), level, internalformat, size,
3408 format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003409}
3410
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003411void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003412 GLint level,
3413 GLint xoffset,
3414 GLint yoffset,
3415 GLsizei width,
3416 GLsizei height,
3417 GLenum format,
3418 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003419 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003420{
3421 // Zero sized uploads are valid but no-ops
3422 if (width == 0 || height == 0)
3423 {
3424 return;
3425 }
3426
Jamie Madillbc918e72018-03-08 09:47:21 -05003427 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003428
3429 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003430 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003431 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3432 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003433}
3434
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003435void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003436 GLint level,
3437 GLint xoffset,
3438 GLint yoffset,
3439 GLint zoffset,
3440 GLsizei width,
3441 GLsizei height,
3442 GLsizei depth,
3443 GLenum format,
3444 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003445 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003446{
3447 // Zero sized uploads are valid but no-ops
3448 if (width == 0 || height == 0 || depth == 0)
3449 {
3450 return;
3451 }
3452
Jamie Madillbc918e72018-03-08 09:47:21 -05003453 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003454
3455 Box area(xoffset, yoffset, zoffset, width, height, depth);
3456 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003457 handleError(texture->setSubImage(this, mGLState.getUnpackState(),
3458 NonCubeTextureTypeToTarget(target), level, area, format, type,
3459 reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003460}
3461
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003462void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003463 GLint level,
3464 GLenum internalformat,
3465 GLsizei width,
3466 GLsizei height,
3467 GLint border,
3468 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003469 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003470{
Jamie Madillbc918e72018-03-08 09:47:21 -05003471 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003472
3473 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003474 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003475 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
3476 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003477 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003478}
3479
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003480void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003481 GLint level,
3482 GLenum internalformat,
3483 GLsizei width,
3484 GLsizei height,
3485 GLsizei depth,
3486 GLint border,
3487 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003488 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003489{
Jamie Madillbc918e72018-03-08 09:47:21 -05003490 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003491
3492 Extents size(width, height, depth);
3493 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003494 handleError(texture->setCompressedImage(
3495 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
3496 size, imageSize, reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003497}
3498
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003499void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003500 GLint level,
3501 GLint xoffset,
3502 GLint yoffset,
3503 GLsizei width,
3504 GLsizei height,
3505 GLenum format,
3506 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003507 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003508{
Jamie Madillbc918e72018-03-08 09:47:21 -05003509 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003510
3511 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003512 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003513 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
3514 format, imageSize,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003515 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003516}
3517
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003518void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003519 GLint level,
3520 GLint xoffset,
3521 GLint yoffset,
3522 GLint zoffset,
3523 GLsizei width,
3524 GLsizei height,
3525 GLsizei depth,
3526 GLenum format,
3527 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003528 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003529{
3530 // Zero sized uploads are valid but no-ops
3531 if (width == 0 || height == 0)
3532 {
3533 return;
3534 }
3535
Jamie Madillbc918e72018-03-08 09:47:21 -05003536 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003537
3538 Box area(xoffset, yoffset, zoffset, width, height, depth);
3539 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003540 handleError(texture->setCompressedSubImage(
3541 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
3542 imageSize, reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003543}
3544
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003545void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003546{
3547 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003548 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003549}
3550
Jamie Madill007530e2017-12-28 14:27:04 -05003551void Context::copyTexture(GLuint sourceId,
3552 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05003553 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05003554 GLuint destId,
3555 GLint destLevel,
3556 GLint internalFormat,
3557 GLenum destType,
3558 GLboolean unpackFlipY,
3559 GLboolean unpackPremultiplyAlpha,
3560 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07003561{
Jamie Madillbc918e72018-03-08 09:47:21 -05003562 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07003563
3564 gl::Texture *sourceTexture = getTexture(sourceId);
3565 gl::Texture *destTexture = getTexture(destId);
Geoff Lang92019432017-11-20 13:09:34 -05003566 handleError(destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType,
3567 sourceLevel, ConvertToBool(unpackFlipY),
3568 ConvertToBool(unpackPremultiplyAlpha),
3569 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003570}
3571
Jamie Madill007530e2017-12-28 14:27:04 -05003572void Context::copySubTexture(GLuint sourceId,
3573 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05003574 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05003575 GLuint destId,
3576 GLint destLevel,
3577 GLint xoffset,
3578 GLint yoffset,
3579 GLint x,
3580 GLint y,
3581 GLsizei width,
3582 GLsizei height,
3583 GLboolean unpackFlipY,
3584 GLboolean unpackPremultiplyAlpha,
3585 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07003586{
3587 // Zero sized copies are valid but no-ops
3588 if (width == 0 || height == 0)
3589 {
3590 return;
3591 }
3592
Jamie Madillbc918e72018-03-08 09:47:21 -05003593 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07003594
3595 gl::Texture *sourceTexture = getTexture(sourceId);
3596 gl::Texture *destTexture = getTexture(destId);
3597 Offset offset(xoffset, yoffset, 0);
3598 Rectangle area(x, y, width, height);
Geoff Lang92019432017-11-20 13:09:34 -05003599 handleError(destTexture->copySubTexture(this, destTarget, destLevel, offset, sourceLevel, area,
3600 ConvertToBool(unpackFlipY),
3601 ConvertToBool(unpackPremultiplyAlpha),
3602 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003603}
3604
Jamie Madill007530e2017-12-28 14:27:04 -05003605void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07003606{
Jamie Madillbc918e72018-03-08 09:47:21 -05003607 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07003608
3609 gl::Texture *sourceTexture = getTexture(sourceId);
3610 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05003611 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07003612}
3613
Corentin Wallez336129f2017-10-17 15:55:40 -04003614void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03003615{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003616 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003617 ASSERT(buffer);
3618
Geoff Lang496c02d2016-10-20 11:38:11 -07003619 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03003620}
3621
Corentin Wallez336129f2017-10-17 15:55:40 -04003622void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003623{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003624 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003625 ASSERT(buffer);
3626
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003627 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003628 if (error.isError())
3629 {
Jamie Madill437fa652016-05-03 15:13:24 -04003630 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003631 return nullptr;
3632 }
3633
3634 return buffer->getMapPointer();
3635}
3636
Corentin Wallez336129f2017-10-17 15:55:40 -04003637GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03003638{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003639 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003640 ASSERT(buffer);
3641
3642 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003643 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03003644 if (error.isError())
3645 {
Jamie Madill437fa652016-05-03 15:13:24 -04003646 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003647 return GL_FALSE;
3648 }
3649
3650 return result;
3651}
3652
Corentin Wallez336129f2017-10-17 15:55:40 -04003653void *Context::mapBufferRange(BufferBinding target,
3654 GLintptr offset,
3655 GLsizeiptr length,
3656 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003657{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003658 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003659 ASSERT(buffer);
3660
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003661 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003662 if (error.isError())
3663 {
Jamie Madill437fa652016-05-03 15:13:24 -04003664 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003665 return nullptr;
3666 }
3667
3668 return buffer->getMapPointer();
3669}
3670
Corentin Wallez336129f2017-10-17 15:55:40 -04003671void Context::flushMappedBufferRange(BufferBinding /*target*/,
3672 GLintptr /*offset*/,
3673 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03003674{
3675 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
3676}
3677
Jamie Madillbc918e72018-03-08 09:47:21 -05003678Error Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05003679{
Geoff Langa8cb2872018-03-09 16:09:40 -05003680 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05003681}
3682
Jamie Madillbc918e72018-03-08 09:47:21 -05003683Error Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05003684{
Geoff Langa8cb2872018-03-09 16:09:40 -05003685 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05003686}
3687
Jamie Madillbc918e72018-03-08 09:47:21 -05003688Error Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05003689{
Geoff Langa8cb2872018-03-09 16:09:40 -05003690 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05003691}
3692
Jiajia Qin5451d532017-11-16 17:16:34 +08003693void Context::activeShaderProgram(GLuint pipeline, GLuint program)
3694{
3695 UNIMPLEMENTED();
3696}
3697
Jamie Madillc20ab272016-06-09 07:20:46 -07003698void Context::activeTexture(GLenum texture)
3699{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003700 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003701}
3702
Jamie Madill876429b2017-04-20 15:46:24 -04003703void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003704{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003705 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07003706}
3707
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003708void Context::blendEquation(GLenum mode)
3709{
3710 mGLState.setBlendEquation(mode, mode);
3711}
3712
Jamie Madillc20ab272016-06-09 07:20:46 -07003713void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
3714{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003715 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003716}
3717
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003718void Context::blendFunc(GLenum sfactor, GLenum dfactor)
3719{
3720 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
3721}
3722
Jamie Madillc20ab272016-06-09 07:20:46 -07003723void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
3724{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003725 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003726}
3727
Jamie Madill876429b2017-04-20 15:46:24 -04003728void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003729{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003730 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003731}
3732
Jamie Madill876429b2017-04-20 15:46:24 -04003733void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07003734{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003735 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07003736}
3737
3738void Context::clearStencil(GLint s)
3739{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003740 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07003741}
3742
3743void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
3744{
Geoff Lang92019432017-11-20 13:09:34 -05003745 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
3746 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07003747}
3748
Corentin Wallez2e568cf2017-09-18 17:05:22 -04003749void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07003750{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003751 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003752}
3753
3754void Context::depthFunc(GLenum func)
3755{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003756 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07003757}
3758
3759void Context::depthMask(GLboolean flag)
3760{
Geoff Lang92019432017-11-20 13:09:34 -05003761 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07003762}
3763
Jamie Madill876429b2017-04-20 15:46:24 -04003764void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07003765{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003766 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07003767}
3768
3769void Context::disable(GLenum cap)
3770{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003771 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003772}
3773
3774void Context::disableVertexAttribArray(GLuint index)
3775{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003776 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003777}
3778
3779void Context::enable(GLenum cap)
3780{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003781 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003782}
3783
3784void Context::enableVertexAttribArray(GLuint index)
3785{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003786 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003787}
3788
3789void Context::frontFace(GLenum mode)
3790{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003791 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003792}
3793
3794void Context::hint(GLenum target, GLenum mode)
3795{
3796 switch (target)
3797 {
3798 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003799 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003800 break;
3801
3802 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003803 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003804 break;
3805
3806 default:
3807 UNREACHABLE();
3808 return;
3809 }
3810}
3811
3812void Context::lineWidth(GLfloat width)
3813{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003814 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07003815}
3816
3817void Context::pixelStorei(GLenum pname, GLint param)
3818{
3819 switch (pname)
3820 {
3821 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003822 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003823 break;
3824
3825 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003826 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003827 break;
3828
3829 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003830 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003831 break;
3832
3833 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003834 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003835 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003836 break;
3837
3838 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03003839 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003840 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003841 break;
3842
3843 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03003844 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003845 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003846 break;
3847
3848 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003849 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003850 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003851 break;
3852
3853 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003854 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003855 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003856 break;
3857
3858 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003859 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003860 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003861 break;
3862
3863 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003864 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003865 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003866 break;
3867
3868 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003869 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003870 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003871 break;
3872
3873 default:
3874 UNREACHABLE();
3875 return;
3876 }
3877}
3878
3879void Context::polygonOffset(GLfloat factor, GLfloat units)
3880{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003881 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07003882}
3883
Jamie Madill876429b2017-04-20 15:46:24 -04003884void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07003885{
Geoff Lang92019432017-11-20 13:09:34 -05003886 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07003887}
3888
Jiawei Shaodb342272017-09-27 10:21:45 +08003889void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
3890{
3891 mGLState.setSampleMaskParams(maskNumber, mask);
3892}
3893
Jamie Madillc20ab272016-06-09 07:20:46 -07003894void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
3895{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003896 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07003897}
3898
3899void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
3900{
3901 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3902 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003903 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003904 }
3905
3906 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3907 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003908 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003909 }
3910}
3911
3912void Context::stencilMaskSeparate(GLenum face, GLuint mask)
3913{
3914 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3915 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003916 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003917 }
3918
3919 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3920 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003921 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003922 }
3923}
3924
3925void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
3926{
3927 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3928 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003929 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003930 }
3931
3932 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3933 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003934 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003935 }
3936}
3937
3938void Context::vertexAttrib1f(GLuint index, GLfloat x)
3939{
3940 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003941 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003942}
3943
3944void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
3945{
3946 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003947 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003948}
3949
3950void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
3951{
3952 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003953 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003954}
3955
3956void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
3957{
3958 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003959 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003960}
3961
3962void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
3963{
3964 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003965 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003966}
3967
3968void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
3969{
3970 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003971 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003972}
3973
3974void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
3975{
3976 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003977 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003978}
3979
3980void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
3981{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003982 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07003983}
3984
3985void Context::vertexAttribPointer(GLuint index,
3986 GLint size,
3987 GLenum type,
3988 GLboolean normalized,
3989 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04003990 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07003991{
Corentin Wallez336129f2017-10-17 15:55:40 -04003992 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05003993 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc20ab272016-06-09 07:20:46 -07003994}
3995
Shao80957d92017-02-20 21:25:59 +08003996void Context::vertexAttribFormat(GLuint attribIndex,
3997 GLint size,
3998 GLenum type,
3999 GLboolean normalized,
4000 GLuint relativeOffset)
4001{
Geoff Lang92019432017-11-20 13:09:34 -05004002 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08004003 relativeOffset);
4004}
4005
4006void Context::vertexAttribIFormat(GLuint attribIndex,
4007 GLint size,
4008 GLenum type,
4009 GLuint relativeOffset)
4010{
4011 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
4012}
4013
4014void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4015{
Shaodde78e82017-05-22 14:13:27 +08004016 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Shao80957d92017-02-20 21:25:59 +08004017}
4018
Jiajia Qin5451d532017-11-16 17:16:34 +08004019void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004020{
4021 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
4022}
4023
Jamie Madillc20ab272016-06-09 07:20:46 -07004024void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4025{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004026 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004027}
4028
4029void Context::vertexAttribIPointer(GLuint index,
4030 GLint size,
4031 GLenum type,
4032 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004033 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004034{
Corentin Wallez336129f2017-10-17 15:55:40 -04004035 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
4036 size, type, false, true, stride, pointer);
Jamie Madillc20ab272016-06-09 07:20:46 -07004037}
4038
4039void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4040{
4041 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004042 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004043}
4044
4045void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4046{
4047 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004048 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004049}
4050
4051void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4052{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004053 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004054}
4055
4056void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4057{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004058 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004059}
4060
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004061void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4062{
4063 const VertexAttribCurrentValueData &currentValues =
4064 getGLState().getVertexAttribCurrentValue(index);
4065 const VertexArray *vao = getGLState().getVertexArray();
4066 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4067 currentValues, pname, params);
4068}
4069
4070void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4071{
4072 const VertexAttribCurrentValueData &currentValues =
4073 getGLState().getVertexAttribCurrentValue(index);
4074 const VertexArray *vao = getGLState().getVertexArray();
4075 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4076 currentValues, pname, params);
4077}
4078
4079void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4080{
4081 const VertexAttribCurrentValueData &currentValues =
4082 getGLState().getVertexAttribCurrentValue(index);
4083 const VertexArray *vao = getGLState().getVertexArray();
4084 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4085 currentValues, pname, params);
4086}
4087
4088void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4089{
4090 const VertexAttribCurrentValueData &currentValues =
4091 getGLState().getVertexAttribCurrentValue(index);
4092 const VertexArray *vao = getGLState().getVertexArray();
4093 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4094 currentValues, pname, params);
4095}
4096
Jamie Madill876429b2017-04-20 15:46:24 -04004097void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004098{
4099 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
4100 QueryVertexAttribPointerv(attrib, pname, pointer);
4101}
4102
Jamie Madillc20ab272016-06-09 07:20:46 -07004103void Context::debugMessageControl(GLenum source,
4104 GLenum type,
4105 GLenum severity,
4106 GLsizei count,
4107 const GLuint *ids,
4108 GLboolean enabled)
4109{
4110 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004111 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05004112 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004113}
4114
4115void Context::debugMessageInsert(GLenum source,
4116 GLenum type,
4117 GLuint id,
4118 GLenum severity,
4119 GLsizei length,
4120 const GLchar *buf)
4121{
4122 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004123 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004124}
4125
4126void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4127{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004128 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004129}
4130
4131GLuint Context::getDebugMessageLog(GLuint count,
4132 GLsizei bufSize,
4133 GLenum *sources,
4134 GLenum *types,
4135 GLuint *ids,
4136 GLenum *severities,
4137 GLsizei *lengths,
4138 GLchar *messageLog)
4139{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004140 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4141 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004142}
4143
4144void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4145{
4146 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004147 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05004148 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07004149}
4150
4151void Context::popDebugGroup()
4152{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004153 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05004154 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004155}
4156
Corentin Wallez336129f2017-10-17 15:55:40 -04004157void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004158{
4159 Buffer *buffer = mGLState.getTargetBuffer(target);
4160 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004161 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004162}
4163
Corentin Wallez336129f2017-10-17 15:55:40 -04004164void Context::bufferSubData(BufferBinding target,
4165 GLintptr offset,
4166 GLsizeiptr size,
4167 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004168{
4169 if (data == nullptr)
4170 {
4171 return;
4172 }
4173
4174 Buffer *buffer = mGLState.getTargetBuffer(target);
4175 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004176 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004177}
4178
Jamie Madillef300b12016-10-07 15:12:09 -04004179void Context::attachShader(GLuint program, GLuint shader)
4180{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05004181 Program *programObject = mState.mShaderPrograms->getProgram(program);
4182 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004183 ASSERT(programObject && shaderObject);
4184 programObject->attachShader(shaderObject);
4185}
4186
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004187const Workarounds &Context::getWorkarounds() const
4188{
4189 return mWorkarounds;
4190}
4191
Corentin Wallez336129f2017-10-17 15:55:40 -04004192void Context::copyBufferSubData(BufferBinding readTarget,
4193 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04004194 GLintptr readOffset,
4195 GLintptr writeOffset,
4196 GLsizeiptr size)
4197{
4198 // if size is zero, the copy is a successful no-op
4199 if (size == 0)
4200 {
4201 return;
4202 }
4203
4204 // TODO(jmadill): cache these.
4205 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4206 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4207
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004208 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004209}
4210
Jamie Madill01a80ee2016-11-07 12:06:18 -05004211void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4212{
4213 Program *programObject = getProgram(program);
4214 // TODO(jmadill): Re-use this from the validation if possible.
4215 ASSERT(programObject);
4216 programObject->bindAttributeLocation(index, name);
4217}
4218
Corentin Wallez336129f2017-10-17 15:55:40 -04004219void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004220{
Corentin Wallez336129f2017-10-17 15:55:40 -04004221 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4222 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004223}
4224
Corentin Wallez336129f2017-10-17 15:55:40 -04004225void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08004226{
4227 bindBufferRange(target, index, buffer, 0, 0);
4228}
4229
Corentin Wallez336129f2017-10-17 15:55:40 -04004230void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08004231 GLuint index,
4232 GLuint buffer,
4233 GLintptr offset,
4234 GLsizeiptr size)
4235{
Corentin Wallez336129f2017-10-17 15:55:40 -04004236 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4237 mGLState.setIndexedBufferBinding(this, target, index, bufferObject, offset, size);
Jiajia Qin6eafb042016-12-27 17:04:07 +08004238}
4239
Jamie Madill01a80ee2016-11-07 12:06:18 -05004240void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
4241{
4242 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4243 {
4244 bindReadFramebuffer(framebuffer);
4245 }
4246
4247 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4248 {
4249 bindDrawFramebuffer(framebuffer);
4250 }
4251}
4252
4253void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4254{
4255 ASSERT(target == GL_RENDERBUFFER);
4256 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004257 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04004258 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004259}
4260
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004261void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08004262 GLsizei samples,
4263 GLenum internalformat,
4264 GLsizei width,
4265 GLsizei height,
4266 GLboolean fixedsamplelocations)
4267{
4268 Extents size(width, height, 1);
4269 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004270 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
4271 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004272}
4273
4274void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4275{
JiangYizhou5b03f472017-01-09 10:22:53 +08004276 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
4277 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillbc918e72018-03-08 09:47:21 -05004278 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
JiangYizhou5b03f472017-01-09 10:22:53 +08004279 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08004280
4281 switch (pname)
4282 {
4283 case GL_SAMPLE_POSITION:
4284 handleError(framebuffer->getSamplePosition(index, val));
4285 break;
4286 default:
4287 UNREACHABLE();
4288 }
4289}
4290
Jamie Madille8fb6402017-02-14 17:56:40 -05004291void Context::renderbufferStorage(GLenum target,
4292 GLenum internalformat,
4293 GLsizei width,
4294 GLsizei height)
4295{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004296 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4297 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
4298
Jamie Madille8fb6402017-02-14 17:56:40 -05004299 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04004300 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004301}
4302
4303void Context::renderbufferStorageMultisample(GLenum target,
4304 GLsizei samples,
4305 GLenum internalformat,
4306 GLsizei width,
4307 GLsizei height)
4308{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004309 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4310 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05004311
4312 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004313 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04004314 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004315}
4316
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004317void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
4318{
Jamie Madill70b5bb02017-08-28 13:32:37 -04004319 const Sync *syncObject = getSync(sync);
Geoff Lang82483b92017-04-11 15:33:00 -04004320 handleError(QuerySynciv(syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004321}
4322
JiangYizhoue18e6392017-02-20 10:32:23 +08004323void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
4324{
4325 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4326 QueryFramebufferParameteriv(framebuffer, pname, params);
4327}
4328
Jiajia Qin5451d532017-11-16 17:16:34 +08004329void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08004330{
4331 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4332 SetFramebufferParameteri(framebuffer, pname, param);
4333}
4334
Jamie Madillb3f26b92017-07-19 15:07:41 -04004335Error Context::getScratchBuffer(size_t requstedSizeBytes,
4336 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05004337{
Jamie Madillb3f26b92017-07-19 15:07:41 -04004338 if (!mScratchBuffer.get(requstedSizeBytes, scratchBufferOut))
4339 {
4340 return OutOfMemory() << "Failed to allocate internal buffer.";
4341 }
4342 return NoError();
4343}
4344
4345Error Context::getZeroFilledBuffer(size_t requstedSizeBytes,
4346 angle::MemoryBuffer **zeroBufferOut) const
4347{
4348 if (!mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0))
Jamie Madille14951e2017-03-09 18:55:16 -05004349 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004350 return OutOfMemory() << "Failed to allocate internal buffer.";
Jamie Madille14951e2017-03-09 18:55:16 -05004351 }
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004352 return NoError();
Jamie Madille14951e2017-03-09 18:55:16 -05004353}
4354
Xinghua Cao10a4d432017-11-28 14:46:26 +08004355Error Context::prepareForDispatch()
4356{
Geoff Langa8cb2872018-03-09 16:09:40 -05004357 ANGLE_TRY(syncState(mComputeDirtyBits, mComputeDirtyObjects));
Xinghua Cao10a4d432017-11-28 14:46:26 +08004358
4359 if (isRobustResourceInitEnabled())
4360 {
4361 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
4362 }
4363
4364 return NoError();
4365}
4366
Xinghua Cao2b396592017-03-29 15:36:04 +08004367void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
4368{
4369 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
4370 {
4371 return;
4372 }
4373
Xinghua Cao10a4d432017-11-28 14:46:26 +08004374 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill71c88b32017-09-14 22:20:29 -04004375 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08004376}
4377
Jiajia Qin5451d532017-11-16 17:16:34 +08004378void Context::dispatchComputeIndirect(GLintptr indirect)
4379{
Qin Jiajia62fcf622017-11-30 16:16:12 +08004380 ANGLE_CONTEXT_TRY(prepareForDispatch());
4381 handleError(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08004382}
4383
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004384void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08004385 GLsizei levels,
4386 GLenum internalFormat,
4387 GLsizei width,
4388 GLsizei height)
4389{
4390 Extents size(width, height, 1);
4391 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004392 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08004393}
4394
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004395void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08004396 GLsizei levels,
4397 GLenum internalFormat,
4398 GLsizei width,
4399 GLsizei height,
4400 GLsizei depth)
4401{
4402 Extents size(width, height, depth);
4403 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004404 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08004405}
4406
Jiajia Qin5451d532017-11-16 17:16:34 +08004407void Context::memoryBarrier(GLbitfield barriers)
4408{
Xinghua Cao89c422a2017-11-29 18:24:20 +08004409 handleError(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08004410}
4411
4412void Context::memoryBarrierByRegion(GLbitfield barriers)
4413{
Xinghua Cao89c422a2017-11-29 18:24:20 +08004414 handleError(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08004415}
4416
Jamie Madillc1d770e2017-04-13 17:31:24 -04004417GLenum Context::checkFramebufferStatus(GLenum target)
4418{
4419 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4420 ASSERT(framebuffer);
4421
4422 return framebuffer->checkStatus(this);
4423}
4424
4425void Context::compileShader(GLuint shader)
4426{
4427 Shader *shaderObject = GetValidShader(this, shader);
4428 if (!shaderObject)
4429 {
4430 return;
4431 }
4432 shaderObject->compile(this);
4433}
4434
4435void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
4436{
4437 for (int i = 0; i < n; i++)
4438 {
4439 deleteBuffer(buffers[i]);
4440 }
4441}
4442
4443void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
4444{
4445 for (int i = 0; i < n; i++)
4446 {
4447 if (framebuffers[i] != 0)
4448 {
4449 deleteFramebuffer(framebuffers[i]);
4450 }
4451 }
4452}
4453
4454void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
4455{
4456 for (int i = 0; i < n; i++)
4457 {
4458 deleteRenderbuffer(renderbuffers[i]);
4459 }
4460}
4461
4462void Context::deleteTextures(GLsizei n, const GLuint *textures)
4463{
4464 for (int i = 0; i < n; i++)
4465 {
4466 if (textures[i] != 0)
4467 {
4468 deleteTexture(textures[i]);
4469 }
4470 }
4471}
4472
4473void Context::detachShader(GLuint program, GLuint shader)
4474{
4475 Program *programObject = getProgram(program);
4476 ASSERT(programObject);
4477
4478 Shader *shaderObject = getShader(shader);
4479 ASSERT(shaderObject);
4480
4481 programObject->detachShader(this, shaderObject);
4482}
4483
4484void Context::genBuffers(GLsizei n, GLuint *buffers)
4485{
4486 for (int i = 0; i < n; i++)
4487 {
4488 buffers[i] = createBuffer();
4489 }
4490}
4491
4492void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
4493{
4494 for (int i = 0; i < n; i++)
4495 {
4496 framebuffers[i] = createFramebuffer();
4497 }
4498}
4499
4500void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
4501{
4502 for (int i = 0; i < n; i++)
4503 {
4504 renderbuffers[i] = createRenderbuffer();
4505 }
4506}
4507
4508void Context::genTextures(GLsizei n, GLuint *textures)
4509{
4510 for (int i = 0; i < n; i++)
4511 {
4512 textures[i] = createTexture();
4513 }
4514}
4515
4516void Context::getActiveAttrib(GLuint program,
4517 GLuint index,
4518 GLsizei bufsize,
4519 GLsizei *length,
4520 GLint *size,
4521 GLenum *type,
4522 GLchar *name)
4523{
4524 Program *programObject = getProgram(program);
4525 ASSERT(programObject);
4526 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
4527}
4528
4529void Context::getActiveUniform(GLuint program,
4530 GLuint index,
4531 GLsizei bufsize,
4532 GLsizei *length,
4533 GLint *size,
4534 GLenum *type,
4535 GLchar *name)
4536{
4537 Program *programObject = getProgram(program);
4538 ASSERT(programObject);
4539 programObject->getActiveUniform(index, bufsize, length, size, type, name);
4540}
4541
4542void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
4543{
4544 Program *programObject = getProgram(program);
4545 ASSERT(programObject);
4546 programObject->getAttachedShaders(maxcount, count, shaders);
4547}
4548
4549GLint Context::getAttribLocation(GLuint program, const GLchar *name)
4550{
4551 Program *programObject = getProgram(program);
4552 ASSERT(programObject);
4553 return programObject->getAttributeLocation(name);
4554}
4555
4556void Context::getBooleanv(GLenum pname, GLboolean *params)
4557{
4558 GLenum nativeType;
4559 unsigned int numParams = 0;
4560 getQueryParameterInfo(pname, &nativeType, &numParams);
4561
4562 if (nativeType == GL_BOOL)
4563 {
4564 getBooleanvImpl(pname, params);
4565 }
4566 else
4567 {
4568 CastStateValues(this, nativeType, pname, numParams, params);
4569 }
4570}
4571
4572void Context::getFloatv(GLenum pname, GLfloat *params)
4573{
4574 GLenum nativeType;
4575 unsigned int numParams = 0;
4576 getQueryParameterInfo(pname, &nativeType, &numParams);
4577
4578 if (nativeType == GL_FLOAT)
4579 {
4580 getFloatvImpl(pname, params);
4581 }
4582 else
4583 {
4584 CastStateValues(this, nativeType, pname, numParams, params);
4585 }
4586}
4587
4588void Context::getIntegerv(GLenum pname, GLint *params)
4589{
4590 GLenum nativeType;
4591 unsigned int numParams = 0;
4592 getQueryParameterInfo(pname, &nativeType, &numParams);
4593
4594 if (nativeType == GL_INT)
4595 {
4596 getIntegervImpl(pname, params);
4597 }
4598 else
4599 {
4600 CastStateValues(this, nativeType, pname, numParams, params);
4601 }
4602}
4603
4604void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
4605{
4606 Program *programObject = getProgram(program);
4607 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04004608 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004609}
4610
Jiajia Qin5451d532017-11-16 17:16:34 +08004611void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
4612{
4613 UNIMPLEMENTED();
4614}
4615
Jamie Madillbe849e42017-05-02 15:49:00 -04004616void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04004617{
4618 Program *programObject = getProgram(program);
4619 ASSERT(programObject);
4620 programObject->getInfoLog(bufsize, length, infolog);
4621}
4622
Jiajia Qin5451d532017-11-16 17:16:34 +08004623void Context::getProgramPipelineInfoLog(GLuint pipeline,
4624 GLsizei bufSize,
4625 GLsizei *length,
4626 GLchar *infoLog)
4627{
4628 UNIMPLEMENTED();
4629}
4630
Jamie Madillc1d770e2017-04-13 17:31:24 -04004631void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
4632{
4633 Shader *shaderObject = getShader(shader);
4634 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004635 QueryShaderiv(this, shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004636}
4637
4638void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
4639{
4640 Shader *shaderObject = getShader(shader);
4641 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004642 shaderObject->getInfoLog(this, bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004643}
4644
4645void Context::getShaderPrecisionFormat(GLenum shadertype,
4646 GLenum precisiontype,
4647 GLint *range,
4648 GLint *precision)
4649{
4650 // TODO(jmadill): Compute shaders.
4651
4652 switch (shadertype)
4653 {
4654 case GL_VERTEX_SHADER:
4655 switch (precisiontype)
4656 {
4657 case GL_LOW_FLOAT:
4658 mCaps.vertexLowpFloat.get(range, precision);
4659 break;
4660 case GL_MEDIUM_FLOAT:
4661 mCaps.vertexMediumpFloat.get(range, precision);
4662 break;
4663 case GL_HIGH_FLOAT:
4664 mCaps.vertexHighpFloat.get(range, precision);
4665 break;
4666
4667 case GL_LOW_INT:
4668 mCaps.vertexLowpInt.get(range, precision);
4669 break;
4670 case GL_MEDIUM_INT:
4671 mCaps.vertexMediumpInt.get(range, precision);
4672 break;
4673 case GL_HIGH_INT:
4674 mCaps.vertexHighpInt.get(range, precision);
4675 break;
4676
4677 default:
4678 UNREACHABLE();
4679 return;
4680 }
4681 break;
4682
4683 case GL_FRAGMENT_SHADER:
4684 switch (precisiontype)
4685 {
4686 case GL_LOW_FLOAT:
4687 mCaps.fragmentLowpFloat.get(range, precision);
4688 break;
4689 case GL_MEDIUM_FLOAT:
4690 mCaps.fragmentMediumpFloat.get(range, precision);
4691 break;
4692 case GL_HIGH_FLOAT:
4693 mCaps.fragmentHighpFloat.get(range, precision);
4694 break;
4695
4696 case GL_LOW_INT:
4697 mCaps.fragmentLowpInt.get(range, precision);
4698 break;
4699 case GL_MEDIUM_INT:
4700 mCaps.fragmentMediumpInt.get(range, precision);
4701 break;
4702 case GL_HIGH_INT:
4703 mCaps.fragmentHighpInt.get(range, precision);
4704 break;
4705
4706 default:
4707 UNREACHABLE();
4708 return;
4709 }
4710 break;
4711
4712 default:
4713 UNREACHABLE();
4714 return;
4715 }
4716}
4717
4718void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
4719{
4720 Shader *shaderObject = getShader(shader);
4721 ASSERT(shaderObject);
4722 shaderObject->getSource(bufsize, length, source);
4723}
4724
4725void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
4726{
4727 Program *programObject = getProgram(program);
4728 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04004729 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004730}
4731
4732void Context::getUniformiv(GLuint program, GLint location, GLint *params)
4733{
4734 Program *programObject = getProgram(program);
4735 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04004736 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004737}
4738
4739GLint Context::getUniformLocation(GLuint program, const GLchar *name)
4740{
4741 Program *programObject = getProgram(program);
4742 ASSERT(programObject);
4743 return programObject->getUniformLocation(name);
4744}
4745
4746GLboolean Context::isBuffer(GLuint buffer)
4747{
4748 if (buffer == 0)
4749 {
4750 return GL_FALSE;
4751 }
4752
4753 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
4754}
4755
4756GLboolean Context::isEnabled(GLenum cap)
4757{
4758 return mGLState.getEnableFeature(cap);
4759}
4760
4761GLboolean Context::isFramebuffer(GLuint framebuffer)
4762{
4763 if (framebuffer == 0)
4764 {
4765 return GL_FALSE;
4766 }
4767
4768 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
4769}
4770
4771GLboolean Context::isProgram(GLuint program)
4772{
4773 if (program == 0)
4774 {
4775 return GL_FALSE;
4776 }
4777
4778 return (getProgram(program) ? GL_TRUE : GL_FALSE);
4779}
4780
4781GLboolean Context::isRenderbuffer(GLuint renderbuffer)
4782{
4783 if (renderbuffer == 0)
4784 {
4785 return GL_FALSE;
4786 }
4787
4788 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
4789}
4790
4791GLboolean Context::isShader(GLuint shader)
4792{
4793 if (shader == 0)
4794 {
4795 return GL_FALSE;
4796 }
4797
4798 return (getShader(shader) ? GL_TRUE : GL_FALSE);
4799}
4800
4801GLboolean Context::isTexture(GLuint texture)
4802{
4803 if (texture == 0)
4804 {
4805 return GL_FALSE;
4806 }
4807
4808 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
4809}
4810
4811void Context::linkProgram(GLuint program)
4812{
4813 Program *programObject = getProgram(program);
4814 ASSERT(programObject);
4815 handleError(programObject->link(this));
Martin Radev0abb7a22017-08-28 15:34:45 +03004816 mGLState.onProgramExecutableChange(programObject);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004817}
4818
4819void Context::releaseShaderCompiler()
4820{
Jamie Madill4928b7c2017-06-20 12:57:39 -04004821 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004822}
4823
4824void Context::shaderBinary(GLsizei n,
4825 const GLuint *shaders,
4826 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04004827 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04004828 GLsizei length)
4829{
4830 // No binary shader formats are supported.
4831 UNIMPLEMENTED();
4832}
4833
4834void Context::shaderSource(GLuint shader,
4835 GLsizei count,
4836 const GLchar *const *string,
4837 const GLint *length)
4838{
4839 Shader *shaderObject = getShader(shader);
4840 ASSERT(shaderObject);
4841 shaderObject->setSource(count, string, length);
4842}
4843
4844void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
4845{
4846 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
4847}
4848
4849void Context::stencilMask(GLuint mask)
4850{
4851 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
4852}
4853
4854void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
4855{
4856 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
4857}
4858
4859void Context::uniform1f(GLint location, GLfloat x)
4860{
4861 Program *program = mGLState.getProgram();
4862 program->setUniform1fv(location, 1, &x);
4863}
4864
4865void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
4866{
4867 Program *program = mGLState.getProgram();
4868 program->setUniform1fv(location, count, v);
4869}
4870
4871void Context::uniform1i(GLint location, GLint x)
4872{
4873 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04004874 if (program->setUniform1iv(location, 1, &x) == Program::SetUniformResult::SamplerChanged)
4875 {
4876 mGLState.setObjectDirty(GL_PROGRAM);
4877 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04004878}
4879
4880void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
4881{
4882 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04004883 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
4884 {
4885 mGLState.setObjectDirty(GL_PROGRAM);
4886 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04004887}
4888
4889void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
4890{
4891 GLfloat xy[2] = {x, y};
4892 Program *program = mGLState.getProgram();
4893 program->setUniform2fv(location, 1, xy);
4894}
4895
4896void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
4897{
4898 Program *program = mGLState.getProgram();
4899 program->setUniform2fv(location, count, v);
4900}
4901
4902void Context::uniform2i(GLint location, GLint x, GLint y)
4903{
4904 GLint xy[2] = {x, y};
4905 Program *program = mGLState.getProgram();
4906 program->setUniform2iv(location, 1, xy);
4907}
4908
4909void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
4910{
4911 Program *program = mGLState.getProgram();
4912 program->setUniform2iv(location, count, v);
4913}
4914
4915void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
4916{
4917 GLfloat xyz[3] = {x, y, z};
4918 Program *program = mGLState.getProgram();
4919 program->setUniform3fv(location, 1, xyz);
4920}
4921
4922void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
4923{
4924 Program *program = mGLState.getProgram();
4925 program->setUniform3fv(location, count, v);
4926}
4927
4928void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
4929{
4930 GLint xyz[3] = {x, y, z};
4931 Program *program = mGLState.getProgram();
4932 program->setUniform3iv(location, 1, xyz);
4933}
4934
4935void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
4936{
4937 Program *program = mGLState.getProgram();
4938 program->setUniform3iv(location, count, v);
4939}
4940
4941void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4942{
4943 GLfloat xyzw[4] = {x, y, z, w};
4944 Program *program = mGLState.getProgram();
4945 program->setUniform4fv(location, 1, xyzw);
4946}
4947
4948void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
4949{
4950 Program *program = mGLState.getProgram();
4951 program->setUniform4fv(location, count, v);
4952}
4953
4954void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
4955{
4956 GLint xyzw[4] = {x, y, z, w};
4957 Program *program = mGLState.getProgram();
4958 program->setUniform4iv(location, 1, xyzw);
4959}
4960
4961void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
4962{
4963 Program *program = mGLState.getProgram();
4964 program->setUniform4iv(location, count, v);
4965}
4966
4967void Context::uniformMatrix2fv(GLint location,
4968 GLsizei count,
4969 GLboolean transpose,
4970 const GLfloat *value)
4971{
4972 Program *program = mGLState.getProgram();
4973 program->setUniformMatrix2fv(location, count, transpose, value);
4974}
4975
4976void Context::uniformMatrix3fv(GLint location,
4977 GLsizei count,
4978 GLboolean transpose,
4979 const GLfloat *value)
4980{
4981 Program *program = mGLState.getProgram();
4982 program->setUniformMatrix3fv(location, count, transpose, value);
4983}
4984
4985void Context::uniformMatrix4fv(GLint location,
4986 GLsizei count,
4987 GLboolean transpose,
4988 const GLfloat *value)
4989{
4990 Program *program = mGLState.getProgram();
4991 program->setUniformMatrix4fv(location, count, transpose, value);
4992}
4993
4994void Context::validateProgram(GLuint program)
4995{
4996 Program *programObject = getProgram(program);
4997 ASSERT(programObject);
4998 programObject->validate(mCaps);
4999}
5000
Jiajia Qin5451d532017-11-16 17:16:34 +08005001void Context::validateProgramPipeline(GLuint pipeline)
5002{
5003 UNIMPLEMENTED();
5004}
5005
Jamie Madilld04908b2017-06-09 14:15:35 -04005006void Context::getProgramBinary(GLuint program,
5007 GLsizei bufSize,
5008 GLsizei *length,
5009 GLenum *binaryFormat,
5010 void *binary)
5011{
5012 Program *programObject = getProgram(program);
5013 ASSERT(programObject != nullptr);
5014
5015 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
5016}
5017
5018void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
5019{
5020 Program *programObject = getProgram(program);
5021 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04005022
Jamie Madilld04908b2017-06-09 14:15:35 -04005023 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
5024}
5025
Jamie Madillff325f12017-08-26 15:06:05 -04005026void Context::uniform1ui(GLint location, GLuint v0)
5027{
5028 Program *program = mGLState.getProgram();
5029 program->setUniform1uiv(location, 1, &v0);
5030}
5031
5032void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
5033{
5034 Program *program = mGLState.getProgram();
5035 const GLuint xy[] = {v0, v1};
5036 program->setUniform2uiv(location, 1, xy);
5037}
5038
5039void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
5040{
5041 Program *program = mGLState.getProgram();
5042 const GLuint xyz[] = {v0, v1, v2};
5043 program->setUniform3uiv(location, 1, xyz);
5044}
5045
5046void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
5047{
5048 Program *program = mGLState.getProgram();
5049 const GLuint xyzw[] = {v0, v1, v2, v3};
5050 program->setUniform4uiv(location, 1, xyzw);
5051}
5052
5053void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
5054{
5055 Program *program = mGLState.getProgram();
5056 program->setUniform1uiv(location, count, value);
5057}
5058void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
5059{
5060 Program *program = mGLState.getProgram();
5061 program->setUniform2uiv(location, count, value);
5062}
5063
5064void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
5065{
5066 Program *program = mGLState.getProgram();
5067 program->setUniform3uiv(location, count, value);
5068}
5069
5070void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
5071{
5072 Program *program = mGLState.getProgram();
5073 program->setUniform4uiv(location, count, value);
5074}
5075
Jamie Madillf0e04492017-08-26 15:28:42 -04005076void Context::genQueries(GLsizei n, GLuint *ids)
5077{
5078 for (GLsizei i = 0; i < n; i++)
5079 {
5080 GLuint handle = mQueryHandleAllocator.allocate();
5081 mQueryMap.assign(handle, nullptr);
5082 ids[i] = handle;
5083 }
5084}
5085
5086void Context::deleteQueries(GLsizei n, const GLuint *ids)
5087{
5088 for (int i = 0; i < n; i++)
5089 {
5090 GLuint query = ids[i];
5091
5092 Query *queryObject = nullptr;
5093 if (mQueryMap.erase(query, &queryObject))
5094 {
5095 mQueryHandleAllocator.release(query);
5096 if (queryObject)
5097 {
5098 queryObject->release(this);
5099 }
5100 }
5101 }
5102}
5103
5104GLboolean Context::isQuery(GLuint id)
5105{
5106 return (getQuery(id, false, GL_NONE) != nullptr) ? GL_TRUE : GL_FALSE;
5107}
5108
Jamie Madillc8c95812017-08-26 18:40:09 -04005109void Context::uniformMatrix2x3fv(GLint location,
5110 GLsizei count,
5111 GLboolean transpose,
5112 const GLfloat *value)
5113{
5114 Program *program = mGLState.getProgram();
5115 program->setUniformMatrix2x3fv(location, count, transpose, value);
5116}
5117
5118void Context::uniformMatrix3x2fv(GLint location,
5119 GLsizei count,
5120 GLboolean transpose,
5121 const GLfloat *value)
5122{
5123 Program *program = mGLState.getProgram();
5124 program->setUniformMatrix3x2fv(location, count, transpose, value);
5125}
5126
5127void Context::uniformMatrix2x4fv(GLint location,
5128 GLsizei count,
5129 GLboolean transpose,
5130 const GLfloat *value)
5131{
5132 Program *program = mGLState.getProgram();
5133 program->setUniformMatrix2x4fv(location, count, transpose, value);
5134}
5135
5136void Context::uniformMatrix4x2fv(GLint location,
5137 GLsizei count,
5138 GLboolean transpose,
5139 const GLfloat *value)
5140{
5141 Program *program = mGLState.getProgram();
5142 program->setUniformMatrix4x2fv(location, count, transpose, value);
5143}
5144
5145void Context::uniformMatrix3x4fv(GLint location,
5146 GLsizei count,
5147 GLboolean transpose,
5148 const GLfloat *value)
5149{
5150 Program *program = mGLState.getProgram();
5151 program->setUniformMatrix3x4fv(location, count, transpose, value);
5152}
5153
5154void Context::uniformMatrix4x3fv(GLint location,
5155 GLsizei count,
5156 GLboolean transpose,
5157 const GLfloat *value)
5158{
5159 Program *program = mGLState.getProgram();
5160 program->setUniformMatrix4x3fv(location, count, transpose, value);
5161}
5162
Jamie Madilld7576732017-08-26 18:49:50 -04005163void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
5164{
5165 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5166 {
5167 GLuint vertexArray = arrays[arrayIndex];
5168
5169 if (arrays[arrayIndex] != 0)
5170 {
5171 VertexArray *vertexArrayObject = nullptr;
5172 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
5173 {
5174 if (vertexArrayObject != nullptr)
5175 {
5176 detachVertexArray(vertexArray);
5177 vertexArrayObject->onDestroy(this);
5178 }
5179
5180 mVertexArrayHandleAllocator.release(vertexArray);
5181 }
5182 }
5183 }
5184}
5185
5186void Context::genVertexArrays(GLsizei n, GLuint *arrays)
5187{
5188 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5189 {
5190 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
5191 mVertexArrayMap.assign(vertexArray, nullptr);
5192 arrays[arrayIndex] = vertexArray;
5193 }
5194}
5195
5196bool Context::isVertexArray(GLuint array)
5197{
5198 if (array == 0)
5199 {
5200 return GL_FALSE;
5201 }
5202
5203 VertexArray *vao = getVertexArray(array);
5204 return (vao != nullptr ? GL_TRUE : GL_FALSE);
5205}
5206
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04005207void Context::endTransformFeedback()
5208{
5209 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5210 transformFeedback->end(this);
5211}
5212
5213void Context::transformFeedbackVaryings(GLuint program,
5214 GLsizei count,
5215 const GLchar *const *varyings,
5216 GLenum bufferMode)
5217{
5218 Program *programObject = getProgram(program);
5219 ASSERT(programObject);
5220 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
5221}
5222
5223void Context::getTransformFeedbackVarying(GLuint program,
5224 GLuint index,
5225 GLsizei bufSize,
5226 GLsizei *length,
5227 GLsizei *size,
5228 GLenum *type,
5229 GLchar *name)
5230{
5231 Program *programObject = getProgram(program);
5232 ASSERT(programObject);
5233 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
5234}
5235
5236void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
5237{
5238 for (int i = 0; i < n; i++)
5239 {
5240 GLuint transformFeedback = ids[i];
5241 if (transformFeedback == 0)
5242 {
5243 continue;
5244 }
5245
5246 TransformFeedback *transformFeedbackObject = nullptr;
5247 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
5248 {
5249 if (transformFeedbackObject != nullptr)
5250 {
5251 detachTransformFeedback(transformFeedback);
5252 transformFeedbackObject->release(this);
5253 }
5254
5255 mTransformFeedbackHandleAllocator.release(transformFeedback);
5256 }
5257 }
5258}
5259
5260void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
5261{
5262 for (int i = 0; i < n; i++)
5263 {
5264 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
5265 mTransformFeedbackMap.assign(transformFeedback, nullptr);
5266 ids[i] = transformFeedback;
5267 }
5268}
5269
5270bool Context::isTransformFeedback(GLuint id)
5271{
5272 if (id == 0)
5273 {
5274 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
5275 // returns FALSE
5276 return GL_FALSE;
5277 }
5278
5279 const TransformFeedback *transformFeedback = getTransformFeedback(id);
5280 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
5281}
5282
5283void Context::pauseTransformFeedback()
5284{
5285 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5286 transformFeedback->pause();
5287}
5288
5289void Context::resumeTransformFeedback()
5290{
5291 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5292 transformFeedback->resume();
5293}
5294
Jamie Madill12e957f2017-08-26 21:42:26 -04005295void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
5296{
5297 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04005298 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04005299}
5300
5301GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
5302{
5303 const Program *programObject = getProgram(program);
5304 return programObject->getFragDataLocation(name);
5305}
5306
5307void Context::getUniformIndices(GLuint program,
5308 GLsizei uniformCount,
5309 const GLchar *const *uniformNames,
5310 GLuint *uniformIndices)
5311{
5312 const Program *programObject = getProgram(program);
5313 if (!programObject->isLinked())
5314 {
5315 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5316 {
5317 uniformIndices[uniformId] = GL_INVALID_INDEX;
5318 }
5319 }
5320 else
5321 {
5322 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5323 {
5324 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
5325 }
5326 }
5327}
5328
5329void Context::getActiveUniformsiv(GLuint program,
5330 GLsizei uniformCount,
5331 const GLuint *uniformIndices,
5332 GLenum pname,
5333 GLint *params)
5334{
5335 const Program *programObject = getProgram(program);
5336 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5337 {
5338 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08005339 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04005340 }
5341}
5342
5343GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
5344{
5345 const Program *programObject = getProgram(program);
5346 return programObject->getUniformBlockIndex(uniformBlockName);
5347}
5348
5349void Context::getActiveUniformBlockiv(GLuint program,
5350 GLuint uniformBlockIndex,
5351 GLenum pname,
5352 GLint *params)
5353{
5354 const Program *programObject = getProgram(program);
5355 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
5356}
5357
5358void Context::getActiveUniformBlockName(GLuint program,
5359 GLuint uniformBlockIndex,
5360 GLsizei bufSize,
5361 GLsizei *length,
5362 GLchar *uniformBlockName)
5363{
5364 const Program *programObject = getProgram(program);
5365 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
5366}
5367
5368void Context::uniformBlockBinding(GLuint program,
5369 GLuint uniformBlockIndex,
5370 GLuint uniformBlockBinding)
5371{
5372 Program *programObject = getProgram(program);
5373 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
5374}
5375
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005376GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
5377{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005378 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
5379 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005380
Jamie Madill70b5bb02017-08-28 13:32:37 -04005381 Sync *syncObject = getSync(syncHandle);
5382 Error error = syncObject->set(condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005383 if (error.isError())
5384 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04005385 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005386 handleError(error);
5387 return nullptr;
5388 }
5389
Jamie Madill70b5bb02017-08-28 13:32:37 -04005390 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005391}
5392
5393GLboolean Context::isSync(GLsync sync)
5394{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005395 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005396}
5397
5398GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
5399{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005400 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005401
5402 GLenum result = GL_WAIT_FAILED;
5403 handleError(syncObject->clientWait(flags, timeout, &result));
5404 return result;
5405}
5406
5407void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
5408{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005409 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005410 handleError(syncObject->serverWait(flags, timeout));
5411}
5412
5413void Context::getInteger64v(GLenum pname, GLint64 *params)
5414{
5415 GLenum nativeType = GL_NONE;
5416 unsigned int numParams = 0;
5417 getQueryParameterInfo(pname, &nativeType, &numParams);
5418
5419 if (nativeType == GL_INT_64_ANGLEX)
5420 {
5421 getInteger64vImpl(pname, params);
5422 }
5423 else
5424 {
5425 CastStateValues(this, nativeType, pname, numParams, params);
5426 }
5427}
5428
Corentin Wallez336129f2017-10-17 15:55:40 -04005429void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04005430{
5431 Buffer *buffer = mGLState.getTargetBuffer(target);
5432 QueryBufferParameteri64v(buffer, pname, params);
5433}
5434
5435void Context::genSamplers(GLsizei count, GLuint *samplers)
5436{
5437 for (int i = 0; i < count; i++)
5438 {
5439 samplers[i] = mState.mSamplers->createSampler();
5440 }
5441}
5442
5443void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
5444{
5445 for (int i = 0; i < count; i++)
5446 {
5447 GLuint sampler = samplers[i];
5448
5449 if (mState.mSamplers->getSampler(sampler))
5450 {
5451 detachSampler(sampler);
5452 }
5453
5454 mState.mSamplers->deleteObject(this, sampler);
5455 }
5456}
5457
5458void Context::getInternalformativ(GLenum target,
5459 GLenum internalformat,
5460 GLenum pname,
5461 GLsizei bufSize,
5462 GLint *params)
5463{
5464 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
5465 QueryInternalFormativ(formatCaps, pname, bufSize, params);
5466}
5467
Jiajia Qin5451d532017-11-16 17:16:34 +08005468void Context::programUniform1i(GLuint program, GLint location, GLint v0)
5469{
5470 programUniform1iv(program, location, 1, &v0);
5471}
5472
5473void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
5474{
5475 GLint xy[2] = {v0, v1};
5476 programUniform2iv(program, location, 1, xy);
5477}
5478
5479void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
5480{
5481 GLint xyz[3] = {v0, v1, v2};
5482 programUniform3iv(program, location, 1, xyz);
5483}
5484
5485void Context::programUniform4i(GLuint program,
5486 GLint location,
5487 GLint v0,
5488 GLint v1,
5489 GLint v2,
5490 GLint v3)
5491{
5492 GLint xyzw[4] = {v0, v1, v2, v3};
5493 programUniform4iv(program, location, 1, xyzw);
5494}
5495
5496void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
5497{
5498 programUniform1uiv(program, location, 1, &v0);
5499}
5500
5501void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
5502{
5503 GLuint xy[2] = {v0, v1};
5504 programUniform2uiv(program, location, 1, xy);
5505}
5506
5507void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
5508{
5509 GLuint xyz[3] = {v0, v1, v2};
5510 programUniform3uiv(program, location, 1, xyz);
5511}
5512
5513void Context::programUniform4ui(GLuint program,
5514 GLint location,
5515 GLuint v0,
5516 GLuint v1,
5517 GLuint v2,
5518 GLuint v3)
5519{
5520 GLuint xyzw[4] = {v0, v1, v2, v3};
5521 programUniform4uiv(program, location, 1, xyzw);
5522}
5523
5524void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
5525{
5526 programUniform1fv(program, location, 1, &v0);
5527}
5528
5529void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
5530{
5531 GLfloat xy[2] = {v0, v1};
5532 programUniform2fv(program, location, 1, xy);
5533}
5534
5535void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
5536{
5537 GLfloat xyz[3] = {v0, v1, v2};
5538 programUniform3fv(program, location, 1, xyz);
5539}
5540
5541void Context::programUniform4f(GLuint program,
5542 GLint location,
5543 GLfloat v0,
5544 GLfloat v1,
5545 GLfloat v2,
5546 GLfloat v3)
5547{
5548 GLfloat xyzw[4] = {v0, v1, v2, v3};
5549 programUniform4fv(program, location, 1, xyzw);
5550}
5551
Jamie Madill81c2e252017-09-09 23:32:46 -04005552void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5553{
5554 Program *programObject = getProgram(program);
5555 ASSERT(programObject);
5556 if (programObject->setUniform1iv(location, count, value) ==
5557 Program::SetUniformResult::SamplerChanged)
5558 {
5559 mGLState.setObjectDirty(GL_PROGRAM);
5560 }
5561}
5562
Jiajia Qin5451d532017-11-16 17:16:34 +08005563void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5564{
5565 Program *programObject = getProgram(program);
5566 ASSERT(programObject);
5567 programObject->setUniform2iv(location, count, value);
5568}
5569
5570void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5571{
5572 Program *programObject = getProgram(program);
5573 ASSERT(programObject);
5574 programObject->setUniform3iv(location, count, value);
5575}
5576
5577void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5578{
5579 Program *programObject = getProgram(program);
5580 ASSERT(programObject);
5581 programObject->setUniform4iv(location, count, value);
5582}
5583
5584void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5585{
5586 Program *programObject = getProgram(program);
5587 ASSERT(programObject);
5588 programObject->setUniform1uiv(location, count, value);
5589}
5590
5591void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5592{
5593 Program *programObject = getProgram(program);
5594 ASSERT(programObject);
5595 programObject->setUniform2uiv(location, count, value);
5596}
5597
5598void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5599{
5600 Program *programObject = getProgram(program);
5601 ASSERT(programObject);
5602 programObject->setUniform3uiv(location, count, value);
5603}
5604
5605void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5606{
5607 Program *programObject = getProgram(program);
5608 ASSERT(programObject);
5609 programObject->setUniform4uiv(location, count, value);
5610}
5611
5612void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5613{
5614 Program *programObject = getProgram(program);
5615 ASSERT(programObject);
5616 programObject->setUniform1fv(location, count, value);
5617}
5618
5619void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5620{
5621 Program *programObject = getProgram(program);
5622 ASSERT(programObject);
5623 programObject->setUniform2fv(location, count, value);
5624}
5625
5626void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5627{
5628 Program *programObject = getProgram(program);
5629 ASSERT(programObject);
5630 programObject->setUniform3fv(location, count, value);
5631}
5632
5633void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5634{
5635 Program *programObject = getProgram(program);
5636 ASSERT(programObject);
5637 programObject->setUniform4fv(location, count, value);
5638}
5639
5640void Context::programUniformMatrix2fv(GLuint program,
5641 GLint location,
5642 GLsizei count,
5643 GLboolean transpose,
5644 const GLfloat *value)
5645{
5646 Program *programObject = getProgram(program);
5647 ASSERT(programObject);
5648 programObject->setUniformMatrix2fv(location, count, transpose, value);
5649}
5650
5651void Context::programUniformMatrix3fv(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->setUniformMatrix3fv(location, count, transpose, value);
5660}
5661
5662void Context::programUniformMatrix4fv(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->setUniformMatrix4fv(location, count, transpose, value);
5671}
5672
5673void Context::programUniformMatrix2x3fv(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->setUniformMatrix2x3fv(location, count, transpose, value);
5682}
5683
5684void Context::programUniformMatrix3x2fv(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->setUniformMatrix3x2fv(location, count, transpose, value);
5693}
5694
5695void Context::programUniformMatrix2x4fv(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->setUniformMatrix2x4fv(location, count, transpose, value);
5704}
5705
5706void Context::programUniformMatrix4x2fv(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->setUniformMatrix4x2fv(location, count, transpose, value);
5715}
5716
5717void Context::programUniformMatrix3x4fv(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->setUniformMatrix3x4fv(location, count, transpose, value);
5726}
5727
5728void Context::programUniformMatrix4x3fv(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->setUniformMatrix4x3fv(location, count, transpose, value);
5737}
5738
Jamie Madill81c2e252017-09-09 23:32:46 -04005739void Context::onTextureChange(const Texture *texture)
5740{
5741 // Conservatively assume all textures are dirty.
5742 // TODO(jmadill): More fine-grained update.
5743 mGLState.setObjectDirty(GL_TEXTURE);
5744}
5745
James Darpiniane8a93c62018-01-04 18:02:24 -08005746bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
5747{
5748 return mGLState.isCurrentTransformFeedback(tf);
5749}
5750bool Context::isCurrentVertexArray(const VertexArray *va) const
5751{
5752 return mGLState.isCurrentVertexArray(va);
5753}
5754
Yunchao Hea336b902017-08-02 16:05:21 +08005755void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
5756{
5757 for (int i = 0; i < count; i++)
5758 {
5759 pipelines[i] = createProgramPipeline();
5760 }
5761}
5762
5763void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
5764{
5765 for (int i = 0; i < count; i++)
5766 {
5767 if (pipelines[i] != 0)
5768 {
5769 deleteProgramPipeline(pipelines[i]);
5770 }
5771 }
5772}
5773
5774GLboolean Context::isProgramPipeline(GLuint pipeline)
5775{
5776 if (pipeline == 0)
5777 {
5778 return GL_FALSE;
5779 }
5780
5781 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
5782}
5783
Jamie Madill2b7bbc22017-12-21 17:30:38 -05005784void Context::finishFenceNV(GLuint fence)
5785{
5786 FenceNV *fenceObject = getFenceNV(fence);
5787
5788 ASSERT(fenceObject && fenceObject->isSet());
5789 handleError(fenceObject->finish());
5790}
5791
5792void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
5793{
5794 FenceNV *fenceObject = getFenceNV(fence);
5795
5796 ASSERT(fenceObject && fenceObject->isSet());
5797
5798 switch (pname)
5799 {
5800 case GL_FENCE_STATUS_NV:
5801 {
5802 // GL_NV_fence spec:
5803 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
5804 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
5805 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
5806 GLboolean status = GL_TRUE;
5807 if (fenceObject->getStatus() != GL_TRUE)
5808 {
5809 ANGLE_CONTEXT_TRY(fenceObject->test(&status));
5810 }
5811 *params = status;
5812 break;
5813 }
5814
5815 case GL_FENCE_CONDITION_NV:
5816 {
5817 *params = static_cast<GLint>(fenceObject->getCondition());
5818 break;
5819 }
5820
5821 default:
5822 UNREACHABLE();
5823 }
5824}
5825
5826void Context::getTranslatedShaderSource(GLuint shader,
5827 GLsizei bufsize,
5828 GLsizei *length,
5829 GLchar *source)
5830{
5831 Shader *shaderObject = getShader(shader);
5832 ASSERT(shaderObject);
5833 shaderObject->getTranslatedSourceWithDebugInfo(this, bufsize, length, source);
5834}
5835
5836void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
5837{
5838 Program *programObject = getProgram(program);
5839 ASSERT(programObject);
5840
5841 programObject->getUniformfv(this, location, params);
5842}
5843
5844void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
5845{
5846 Program *programObject = getProgram(program);
5847 ASSERT(programObject);
5848
5849 programObject->getUniformiv(this, location, params);
5850}
5851
5852GLboolean Context::isFenceNV(GLuint fence)
5853{
5854 FenceNV *fenceObject = getFenceNV(fence);
5855
5856 if (fenceObject == nullptr)
5857 {
5858 return GL_FALSE;
5859 }
5860
5861 // GL_NV_fence spec:
5862 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
5863 // existing fence.
5864 return fenceObject->isSet();
5865}
5866
5867void Context::readnPixels(GLint x,
5868 GLint y,
5869 GLsizei width,
5870 GLsizei height,
5871 GLenum format,
5872 GLenum type,
5873 GLsizei bufSize,
5874 void *data)
5875{
5876 return readPixels(x, y, width, height, format, type, data);
5877}
5878
Jamie Madill007530e2017-12-28 14:27:04 -05005879void Context::setFenceNV(GLuint fence, GLenum condition)
5880{
5881 ASSERT(condition == GL_ALL_COMPLETED_NV);
5882
5883 FenceNV *fenceObject = getFenceNV(fence);
5884 ASSERT(fenceObject != nullptr);
5885 handleError(fenceObject->set(condition));
5886}
5887
5888GLboolean Context::testFenceNV(GLuint fence)
5889{
5890 FenceNV *fenceObject = getFenceNV(fence);
5891
5892 ASSERT(fenceObject != nullptr);
5893 ASSERT(fenceObject->isSet() == GL_TRUE);
5894
5895 GLboolean result = GL_TRUE;
5896 Error error = fenceObject->test(&result);
5897 if (error.isError())
5898 {
5899 handleError(error);
5900 return GL_TRUE;
5901 }
5902
5903 return result;
5904}
5905
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005906void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05005907{
5908 Texture *texture = getTargetTexture(target);
5909 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005910 handleError(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05005911}
5912
Jamie Madillfa920eb2018-01-04 11:45:50 -05005913void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05005914{
5915 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
5916 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
5917 handleError(renderbuffer->setStorageEGLImageTarget(this, imageObject));
5918}
5919
Jamie Madillfa920eb2018-01-04 11:45:50 -05005920void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
5921{
5922 UNIMPLEMENTED();
5923}
5924
Geoff Lang2aaa7b42018-01-12 17:17:27 -05005925void Context::alphaFunc(GLenum func, GLfloat ref)
5926{
5927 UNIMPLEMENTED();
5928}
5929
5930void Context::alphaFuncx(GLenum func, GLfixed ref)
5931{
5932 UNIMPLEMENTED();
5933}
5934
5935void Context::clearColorx(GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha)
5936{
5937 UNIMPLEMENTED();
5938}
5939
5940void Context::clearDepthx(GLfixed depth)
5941{
5942 UNIMPLEMENTED();
5943}
5944
5945void Context::clientActiveTexture(GLenum texture)
5946{
5947 UNIMPLEMENTED();
5948}
5949
5950void Context::clipPlanef(GLenum p, const GLfloat *eqn)
5951{
5952 UNIMPLEMENTED();
5953}
5954
5955void Context::clipPlanex(GLenum plane, const GLfixed *equation)
5956{
5957 UNIMPLEMENTED();
5958}
5959
5960void Context::color4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
5961{
5962 UNIMPLEMENTED();
5963}
5964
5965void Context::color4ub(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha)
5966{
5967 UNIMPLEMENTED();
5968}
5969
5970void Context::color4x(GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha)
5971{
5972 UNIMPLEMENTED();
5973}
5974
5975void Context::colorPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
5976{
5977 UNIMPLEMENTED();
5978}
5979
5980void Context::cullFace(GLenum mode)
5981{
5982 UNIMPLEMENTED();
5983}
5984
5985void Context::depthRangex(GLfixed n, GLfixed f)
5986{
5987 UNIMPLEMENTED();
5988}
5989
5990void Context::disableClientState(GLenum array)
5991{
5992 UNIMPLEMENTED();
5993}
5994
5995void Context::enableClientState(GLenum array)
5996{
5997 UNIMPLEMENTED();
5998}
5999
6000void Context::fogf(GLenum pname, GLfloat param)
6001{
6002 UNIMPLEMENTED();
6003}
6004
6005void Context::fogfv(GLenum pname, const GLfloat *params)
6006{
6007 UNIMPLEMENTED();
6008}
6009
6010void Context::fogx(GLenum pname, GLfixed param)
6011{
6012 UNIMPLEMENTED();
6013}
6014
6015void Context::fogxv(GLenum pname, const GLfixed *param)
6016{
6017 UNIMPLEMENTED();
6018}
6019
6020void Context::frustumf(GLfloat l, GLfloat r, GLfloat b, GLfloat t, GLfloat n, GLfloat f)
6021{
6022 UNIMPLEMENTED();
6023}
6024
6025void Context::frustumx(GLfixed l, GLfixed r, GLfixed b, GLfixed t, GLfixed n, GLfixed f)
6026{
6027 UNIMPLEMENTED();
6028}
6029
6030void Context::getBufferParameteriv(GLenum target, GLenum pname, GLint *params)
6031{
6032 UNIMPLEMENTED();
6033}
6034
6035void Context::getClipPlanef(GLenum plane, GLfloat *equation)
6036{
6037 UNIMPLEMENTED();
6038}
6039
6040void Context::getClipPlanex(GLenum plane, GLfixed *equation)
6041{
6042 UNIMPLEMENTED();
6043}
6044
6045void Context::getFixedv(GLenum pname, GLfixed *params)
6046{
6047 UNIMPLEMENTED();
6048}
6049
6050void Context::getLightfv(GLenum light, GLenum pname, GLfloat *params)
6051{
6052 UNIMPLEMENTED();
6053}
6054
6055void Context::getLightxv(GLenum light, GLenum pname, GLfixed *params)
6056{
6057 UNIMPLEMENTED();
6058}
6059
6060void Context::getMaterialfv(GLenum face, GLenum pname, GLfloat *params)
6061{
6062 UNIMPLEMENTED();
6063}
6064
6065void Context::getMaterialxv(GLenum face, GLenum pname, GLfixed *params)
6066{
6067 UNIMPLEMENTED();
6068}
6069
6070void Context::getTexEnvfv(GLenum target, GLenum pname, GLfloat *params)
6071{
6072 UNIMPLEMENTED();
6073}
6074
6075void Context::getTexEnviv(GLenum target, GLenum pname, GLint *params)
6076{
6077 UNIMPLEMENTED();
6078}
6079
6080void Context::getTexEnvxv(GLenum target, GLenum pname, GLfixed *params)
6081{
6082 UNIMPLEMENTED();
6083}
6084
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006085void Context::getTexParameterxv(TextureType target, GLenum pname, GLfixed *params)
Geoff Lang2aaa7b42018-01-12 17:17:27 -05006086{
6087 UNIMPLEMENTED();
6088}
6089
6090void Context::lightModelf(GLenum pname, GLfloat param)
6091{
6092 UNIMPLEMENTED();
6093}
6094
6095void Context::lightModelfv(GLenum pname, const GLfloat *params)
6096{
6097 UNIMPLEMENTED();
6098}
6099
6100void Context::lightModelx(GLenum pname, GLfixed param)
6101{
6102 UNIMPLEMENTED();
6103}
6104
6105void Context::lightModelxv(GLenum pname, const GLfixed *param)
6106{
6107 UNIMPLEMENTED();
6108}
6109
6110void Context::lightf(GLenum light, GLenum pname, GLfloat param)
6111{
6112 UNIMPLEMENTED();
6113}
6114
6115void Context::lightfv(GLenum light, GLenum pname, const GLfloat *params)
6116{
6117 UNIMPLEMENTED();
6118}
6119
6120void Context::lightx(GLenum light, GLenum pname, GLfixed param)
6121{
6122 UNIMPLEMENTED();
6123}
6124
6125void Context::lightxv(GLenum light, GLenum pname, const GLfixed *params)
6126{
6127 UNIMPLEMENTED();
6128}
6129
6130void Context::lineWidthx(GLfixed width)
6131{
6132 UNIMPLEMENTED();
6133}
6134
6135void Context::loadIdentity()
6136{
6137 UNIMPLEMENTED();
6138}
6139
6140void Context::loadMatrixf(const GLfloat *m)
6141{
6142 UNIMPLEMENTED();
6143}
6144
6145void Context::loadMatrixx(const GLfixed *m)
6146{
6147 UNIMPLEMENTED();
6148}
6149
6150void Context::logicOp(GLenum opcode)
6151{
6152 UNIMPLEMENTED();
6153}
6154
6155void Context::materialf(GLenum face, GLenum pname, GLfloat param)
6156{
6157 UNIMPLEMENTED();
6158}
6159
6160void Context::materialfv(GLenum face, GLenum pname, const GLfloat *params)
6161{
6162 UNIMPLEMENTED();
6163}
6164
6165void Context::materialx(GLenum face, GLenum pname, GLfixed param)
6166{
6167 UNIMPLEMENTED();
6168}
6169
6170void Context::materialxv(GLenum face, GLenum pname, const GLfixed *param)
6171{
6172 UNIMPLEMENTED();
6173}
6174
6175void Context::matrixMode(GLenum mode)
6176{
6177 UNIMPLEMENTED();
6178}
6179
6180void Context::multMatrixf(const GLfloat *m)
6181{
6182 UNIMPLEMENTED();
6183}
6184
6185void Context::multMatrixx(const GLfixed *m)
6186{
6187 UNIMPLEMENTED();
6188}
6189
6190void Context::multiTexCoord4f(GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q)
6191{
6192 UNIMPLEMENTED();
6193}
6194
6195void Context::multiTexCoord4x(GLenum texture, GLfixed s, GLfixed t, GLfixed r, GLfixed q)
6196{
6197 UNIMPLEMENTED();
6198}
6199
6200void Context::normal3f(GLfloat nx, GLfloat ny, GLfloat nz)
6201{
6202 UNIMPLEMENTED();
6203}
6204
6205void Context::normal3x(GLfixed nx, GLfixed ny, GLfixed nz)
6206{
6207 UNIMPLEMENTED();
6208}
6209
6210void Context::normalPointer(GLenum type, GLsizei stride, const void *pointer)
6211{
6212 UNIMPLEMENTED();
6213}
6214
6215void Context::orthof(GLfloat l, GLfloat r, GLfloat b, GLfloat t, GLfloat n, GLfloat f)
6216{
6217 UNIMPLEMENTED();
6218}
6219
6220void Context::orthox(GLfixed l, GLfixed r, GLfixed b, GLfixed t, GLfixed n, GLfixed f)
6221{
6222 UNIMPLEMENTED();
6223}
6224
6225void Context::pointParameterf(GLenum pname, GLfloat param)
6226{
6227 UNIMPLEMENTED();
6228}
6229
6230void Context::pointParameterfv(GLenum pname, const GLfloat *params)
6231{
6232 UNIMPLEMENTED();
6233}
6234
6235void Context::pointParameterx(GLenum pname, GLfixed param)
6236{
6237 UNIMPLEMENTED();
6238}
6239
6240void Context::pointParameterxv(GLenum pname, const GLfixed *params)
6241{
6242 UNIMPLEMENTED();
6243}
6244
6245void Context::pointSize(GLfloat size)
6246{
6247 UNIMPLEMENTED();
6248}
6249
6250void Context::pointSizex(GLfixed size)
6251{
6252 UNIMPLEMENTED();
6253}
6254
6255void Context::polygonOffsetx(GLfixed factor, GLfixed units)
6256{
6257 UNIMPLEMENTED();
6258}
6259
6260void Context::popMatrix()
6261{
6262 UNIMPLEMENTED();
6263}
6264
6265void Context::pushMatrix()
6266{
6267 UNIMPLEMENTED();
6268}
6269
6270void Context::rotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z)
6271{
6272 UNIMPLEMENTED();
6273}
6274
6275void Context::rotatex(GLfixed angle, GLfixed x, GLfixed y, GLfixed z)
6276{
6277 UNIMPLEMENTED();
6278}
6279
6280void Context::sampleCoveragex(GLclampx value, GLboolean invert)
6281{
6282 UNIMPLEMENTED();
6283}
6284
6285void Context::scalef(GLfloat x, GLfloat y, GLfloat z)
6286{
6287 UNIMPLEMENTED();
6288}
6289
6290void Context::scalex(GLfixed x, GLfixed y, GLfixed z)
6291{
6292 UNIMPLEMENTED();
6293}
6294
6295void Context::shadeModel(GLenum mode)
6296{
6297 UNIMPLEMENTED();
6298}
6299
6300void Context::texCoordPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
6301{
6302 UNIMPLEMENTED();
6303}
6304
6305void Context::texEnvf(GLenum target, GLenum pname, GLfloat param)
6306{
6307 UNIMPLEMENTED();
6308}
6309
6310void Context::texEnvfv(GLenum target, GLenum pname, const GLfloat *params)
6311{
6312 UNIMPLEMENTED();
6313}
6314
6315void Context::texEnvi(GLenum target, GLenum pname, GLint param)
6316{
6317 UNIMPLEMENTED();
6318}
6319
6320void Context::texEnviv(GLenum target, GLenum pname, const GLint *params)
6321{
6322 UNIMPLEMENTED();
6323}
6324
6325void Context::texEnvx(GLenum target, GLenum pname, GLfixed param)
6326{
6327 UNIMPLEMENTED();
6328}
6329
6330void Context::texEnvxv(GLenum target, GLenum pname, const GLfixed *params)
6331{
6332 UNIMPLEMENTED();
6333}
6334
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006335void Context::texParameterx(TextureType target, GLenum pname, GLfixed param)
Geoff Lang2aaa7b42018-01-12 17:17:27 -05006336{
6337 UNIMPLEMENTED();
6338}
6339
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006340void Context::texParameterxv(TextureType target, GLenum pname, const GLfixed *params)
Geoff Lang2aaa7b42018-01-12 17:17:27 -05006341{
6342 UNIMPLEMENTED();
6343}
6344
6345void Context::translatef(GLfloat x, GLfloat y, GLfloat z)
6346{
6347 UNIMPLEMENTED();
6348}
6349
6350void Context::translatex(GLfixed x, GLfixed y, GLfixed z)
6351{
6352 UNIMPLEMENTED();
6353}
6354
6355void Context::vertexPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
6356{
6357 UNIMPLEMENTED();
6358}
6359
6360void Context::drawTexf(GLfloat x, GLfloat y, GLfloat z, GLfloat width, GLfloat height)
6361{
6362 UNIMPLEMENTED();
6363}
6364
6365void Context::drawTexfv(const GLfloat *coords)
6366{
6367 UNIMPLEMENTED();
6368}
6369
6370void Context::drawTexi(GLint x, GLint y, GLint z, GLint width, GLint height)
6371{
6372 UNIMPLEMENTED();
6373}
6374
6375void Context::drawTexiv(const GLint *coords)
6376{
6377 UNIMPLEMENTED();
6378}
6379
6380void Context::drawTexs(GLshort x, GLshort y, GLshort z, GLshort width, GLshort height)
6381{
6382 UNIMPLEMENTED();
6383}
6384
6385void Context::drawTexsv(const GLshort *coords)
6386{
6387 UNIMPLEMENTED();
6388}
6389
6390void Context::drawTexx(GLfixed x, GLfixed y, GLfixed z, GLfixed width, GLfixed height)
6391{
6392 UNIMPLEMENTED();
6393}
6394
6395void Context::drawTexxv(const GLfixed *coords)
6396{
6397 UNIMPLEMENTED();
6398}
6399
6400void Context::currentPaletteMatrix(GLuint matrixpaletteindex)
6401{
6402 UNIMPLEMENTED();
6403}
6404
6405void Context::loadPaletteFromModelViewMatrix()
6406{
6407 UNIMPLEMENTED();
6408}
6409
6410void Context::matrixIndexPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
6411{
6412 UNIMPLEMENTED();
6413}
6414
6415void Context::weightPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
6416{
6417 UNIMPLEMENTED();
6418}
6419
6420void Context::pointSizePointer(GLenum type, GLsizei stride, const void *pointer)
6421{
6422 UNIMPLEMENTED();
6423}
6424
6425GLbitfield Context::queryMatrixx(GLfixed *mantissa, GLint *exponent)
6426{
6427 UNIMPLEMENTED();
6428 return 0;
6429}
6430
Jamie Madill5b772312018-03-08 20:28:32 -05006431bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
6432{
6433 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
6434 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
6435 // to the fact that it is stored internally as a float, and so would require conversion
6436 // if returned from Context::getIntegerv. Since this conversion is already implemented
6437 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
6438 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
6439 // application.
6440 switch (pname)
6441 {
6442 case GL_COMPRESSED_TEXTURE_FORMATS:
6443 {
6444 *type = GL_INT;
6445 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
6446 return true;
6447 }
6448 case GL_SHADER_BINARY_FORMATS:
6449 {
6450 *type = GL_INT;
6451 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
6452 return true;
6453 }
6454
6455 case GL_MAX_VERTEX_ATTRIBS:
6456 case GL_MAX_VERTEX_UNIFORM_VECTORS:
6457 case GL_MAX_VARYING_VECTORS:
6458 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
6459 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
6460 case GL_MAX_TEXTURE_IMAGE_UNITS:
6461 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
6462 case GL_MAX_RENDERBUFFER_SIZE:
6463 case GL_NUM_SHADER_BINARY_FORMATS:
6464 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
6465 case GL_ARRAY_BUFFER_BINDING:
6466 case GL_FRAMEBUFFER_BINDING:
6467 case GL_RENDERBUFFER_BINDING:
6468 case GL_CURRENT_PROGRAM:
6469 case GL_PACK_ALIGNMENT:
6470 case GL_UNPACK_ALIGNMENT:
6471 case GL_GENERATE_MIPMAP_HINT:
6472 case GL_RED_BITS:
6473 case GL_GREEN_BITS:
6474 case GL_BLUE_BITS:
6475 case GL_ALPHA_BITS:
6476 case GL_DEPTH_BITS:
6477 case GL_STENCIL_BITS:
6478 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
6479 case GL_CULL_FACE_MODE:
6480 case GL_FRONT_FACE:
6481 case GL_ACTIVE_TEXTURE:
6482 case GL_STENCIL_FUNC:
6483 case GL_STENCIL_VALUE_MASK:
6484 case GL_STENCIL_REF:
6485 case GL_STENCIL_FAIL:
6486 case GL_STENCIL_PASS_DEPTH_FAIL:
6487 case GL_STENCIL_PASS_DEPTH_PASS:
6488 case GL_STENCIL_BACK_FUNC:
6489 case GL_STENCIL_BACK_VALUE_MASK:
6490 case GL_STENCIL_BACK_REF:
6491 case GL_STENCIL_BACK_FAIL:
6492 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
6493 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
6494 case GL_DEPTH_FUNC:
6495 case GL_BLEND_SRC_RGB:
6496 case GL_BLEND_SRC_ALPHA:
6497 case GL_BLEND_DST_RGB:
6498 case GL_BLEND_DST_ALPHA:
6499 case GL_BLEND_EQUATION_RGB:
6500 case GL_BLEND_EQUATION_ALPHA:
6501 case GL_STENCIL_WRITEMASK:
6502 case GL_STENCIL_BACK_WRITEMASK:
6503 case GL_STENCIL_CLEAR_VALUE:
6504 case GL_SUBPIXEL_BITS:
6505 case GL_MAX_TEXTURE_SIZE:
6506 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
6507 case GL_SAMPLE_BUFFERS:
6508 case GL_SAMPLES:
6509 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
6510 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
6511 case GL_TEXTURE_BINDING_2D:
6512 case GL_TEXTURE_BINDING_CUBE_MAP:
6513 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
6514 {
6515 *type = GL_INT;
6516 *numParams = 1;
6517 return true;
6518 }
6519 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6520 {
6521 if (!getExtensions().packReverseRowOrder)
6522 {
6523 return false;
6524 }
6525 *type = GL_INT;
6526 *numParams = 1;
6527 return true;
6528 }
6529 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
6530 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
6531 {
6532 if (!getExtensions().textureRectangle)
6533 {
6534 return false;
6535 }
6536 *type = GL_INT;
6537 *numParams = 1;
6538 return true;
6539 }
6540 case GL_MAX_DRAW_BUFFERS_EXT:
6541 case GL_MAX_COLOR_ATTACHMENTS_EXT:
6542 {
6543 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
6544 {
6545 return false;
6546 }
6547 *type = GL_INT;
6548 *numParams = 1;
6549 return true;
6550 }
6551 case GL_MAX_VIEWPORT_DIMS:
6552 {
6553 *type = GL_INT;
6554 *numParams = 2;
6555 return true;
6556 }
6557 case GL_VIEWPORT:
6558 case GL_SCISSOR_BOX:
6559 {
6560 *type = GL_INT;
6561 *numParams = 4;
6562 return true;
6563 }
6564 case GL_SHADER_COMPILER:
6565 case GL_SAMPLE_COVERAGE_INVERT:
6566 case GL_DEPTH_WRITEMASK:
6567 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
6568 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
6569 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
6570 // bool-natural
6571 case GL_SAMPLE_COVERAGE:
6572 case GL_SCISSOR_TEST:
6573 case GL_STENCIL_TEST:
6574 case GL_DEPTH_TEST:
6575 case GL_BLEND:
6576 case GL_DITHER:
6577 case GL_CONTEXT_ROBUST_ACCESS_EXT:
6578 {
6579 *type = GL_BOOL;
6580 *numParams = 1;
6581 return true;
6582 }
6583 case GL_COLOR_WRITEMASK:
6584 {
6585 *type = GL_BOOL;
6586 *numParams = 4;
6587 return true;
6588 }
6589 case GL_POLYGON_OFFSET_FACTOR:
6590 case GL_POLYGON_OFFSET_UNITS:
6591 case GL_SAMPLE_COVERAGE_VALUE:
6592 case GL_DEPTH_CLEAR_VALUE:
6593 case GL_LINE_WIDTH:
6594 {
6595 *type = GL_FLOAT;
6596 *numParams = 1;
6597 return true;
6598 }
6599 case GL_ALIASED_LINE_WIDTH_RANGE:
6600 case GL_ALIASED_POINT_SIZE_RANGE:
6601 case GL_DEPTH_RANGE:
6602 {
6603 *type = GL_FLOAT;
6604 *numParams = 2;
6605 return true;
6606 }
6607 case GL_COLOR_CLEAR_VALUE:
6608 case GL_BLEND_COLOR:
6609 {
6610 *type = GL_FLOAT;
6611 *numParams = 4;
6612 return true;
6613 }
6614 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
6615 if (!getExtensions().textureFilterAnisotropic)
6616 {
6617 return false;
6618 }
6619 *type = GL_FLOAT;
6620 *numParams = 1;
6621 return true;
6622 case GL_TIMESTAMP_EXT:
6623 if (!getExtensions().disjointTimerQuery)
6624 {
6625 return false;
6626 }
6627 *type = GL_INT_64_ANGLEX;
6628 *numParams = 1;
6629 return true;
6630 case GL_GPU_DISJOINT_EXT:
6631 if (!getExtensions().disjointTimerQuery)
6632 {
6633 return false;
6634 }
6635 *type = GL_INT;
6636 *numParams = 1;
6637 return true;
6638 case GL_COVERAGE_MODULATION_CHROMIUM:
6639 if (!getExtensions().framebufferMixedSamples)
6640 {
6641 return false;
6642 }
6643 *type = GL_INT;
6644 *numParams = 1;
6645 return true;
6646 case GL_TEXTURE_BINDING_EXTERNAL_OES:
6647 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
6648 {
6649 return false;
6650 }
6651 *type = GL_INT;
6652 *numParams = 1;
6653 return true;
6654 }
6655
6656 if (getExtensions().debug)
6657 {
6658 switch (pname)
6659 {
6660 case GL_DEBUG_LOGGED_MESSAGES:
6661 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
6662 case GL_DEBUG_GROUP_STACK_DEPTH:
6663 case GL_MAX_DEBUG_MESSAGE_LENGTH:
6664 case GL_MAX_DEBUG_LOGGED_MESSAGES:
6665 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
6666 case GL_MAX_LABEL_LENGTH:
6667 *type = GL_INT;
6668 *numParams = 1;
6669 return true;
6670
6671 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
6672 case GL_DEBUG_OUTPUT:
6673 *type = GL_BOOL;
6674 *numParams = 1;
6675 return true;
6676 }
6677 }
6678
6679 if (getExtensions().multisampleCompatibility)
6680 {
6681 switch (pname)
6682 {
6683 case GL_MULTISAMPLE_EXT:
6684 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
6685 *type = GL_BOOL;
6686 *numParams = 1;
6687 return true;
6688 }
6689 }
6690
6691 if (getExtensions().pathRendering)
6692 {
6693 switch (pname)
6694 {
6695 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
6696 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
6697 *type = GL_FLOAT;
6698 *numParams = 16;
6699 return true;
6700 }
6701 }
6702
6703 if (getExtensions().bindGeneratesResource)
6704 {
6705 switch (pname)
6706 {
6707 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
6708 *type = GL_BOOL;
6709 *numParams = 1;
6710 return true;
6711 }
6712 }
6713
6714 if (getExtensions().clientArrays)
6715 {
6716 switch (pname)
6717 {
6718 case GL_CLIENT_ARRAYS_ANGLE:
6719 *type = GL_BOOL;
6720 *numParams = 1;
6721 return true;
6722 }
6723 }
6724
6725 if (getExtensions().sRGBWriteControl)
6726 {
6727 switch (pname)
6728 {
6729 case GL_FRAMEBUFFER_SRGB_EXT:
6730 *type = GL_BOOL;
6731 *numParams = 1;
6732 return true;
6733 }
6734 }
6735
6736 if (getExtensions().robustResourceInitialization &&
6737 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
6738 {
6739 *type = GL_BOOL;
6740 *numParams = 1;
6741 return true;
6742 }
6743
6744 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
6745 {
6746 *type = GL_BOOL;
6747 *numParams = 1;
6748 return true;
6749 }
6750
6751 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
6752 switch (pname)
6753 {
6754 // case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE // equivalent to FRAMEBUFFER_BINDING
6755 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
6756 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
6757 {
6758 return false;
6759 }
6760 *type = GL_INT;
6761 *numParams = 1;
6762 return true;
6763
6764 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
6765 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
6766 {
6767 return false;
6768 }
6769 *type = GL_INT;
6770 *numParams = 1;
6771 return true;
6772
6773 case GL_PROGRAM_BINARY_FORMATS_OES:
6774 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
6775 {
6776 return false;
6777 }
6778 *type = GL_INT;
6779 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
6780 return true;
6781
6782 case GL_PACK_ROW_LENGTH:
6783 case GL_PACK_SKIP_ROWS:
6784 case GL_PACK_SKIP_PIXELS:
6785 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
6786 {
6787 return false;
6788 }
6789 *type = GL_INT;
6790 *numParams = 1;
6791 return true;
6792 case GL_UNPACK_ROW_LENGTH:
6793 case GL_UNPACK_SKIP_ROWS:
6794 case GL_UNPACK_SKIP_PIXELS:
6795 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
6796 {
6797 return false;
6798 }
6799 *type = GL_INT;
6800 *numParams = 1;
6801 return true;
6802 case GL_VERTEX_ARRAY_BINDING:
6803 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
6804 {
6805 return false;
6806 }
6807 *type = GL_INT;
6808 *numParams = 1;
6809 return true;
6810 case GL_PIXEL_PACK_BUFFER_BINDING:
6811 case GL_PIXEL_UNPACK_BUFFER_BINDING:
6812 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
6813 {
6814 return false;
6815 }
6816 *type = GL_INT;
6817 *numParams = 1;
6818 return true;
6819 case GL_MAX_SAMPLES:
6820 {
6821 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
6822 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
6823 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
6824 {
6825 return false;
6826 }
6827 *type = GL_INT;
6828 *numParams = 1;
6829 return true;
6830
6831 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
6832 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
6833 {
6834 return false;
6835 }
6836 *type = GL_INT;
6837 *numParams = 1;
6838 return true;
6839 }
6840 }
6841
6842 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
6843 {
6844 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
6845 {
6846 return false;
6847 }
6848 *type = GL_INT;
6849 *numParams = 1;
6850 return true;
6851 }
6852
6853 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
6854 {
6855 *type = GL_INT;
6856 *numParams = 1;
6857 return true;
6858 }
6859
6860 if (getClientVersion() < Version(3, 0))
6861 {
6862 return false;
6863 }
6864
6865 // Check for ES3.0+ parameter names
6866 switch (pname)
6867 {
6868 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
6869 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
6870 case GL_UNIFORM_BUFFER_BINDING:
6871 case GL_TRANSFORM_FEEDBACK_BINDING:
6872 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
6873 case GL_COPY_READ_BUFFER_BINDING:
6874 case GL_COPY_WRITE_BUFFER_BINDING:
6875 case GL_SAMPLER_BINDING:
6876 case GL_READ_BUFFER:
6877 case GL_TEXTURE_BINDING_3D:
6878 case GL_TEXTURE_BINDING_2D_ARRAY:
6879 case GL_MAX_3D_TEXTURE_SIZE:
6880 case GL_MAX_ARRAY_TEXTURE_LAYERS:
6881 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
6882 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
6883 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
6884 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
6885 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
6886 case GL_MAX_VARYING_COMPONENTS:
6887 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
6888 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
6889 case GL_MIN_PROGRAM_TEXEL_OFFSET:
6890 case GL_MAX_PROGRAM_TEXEL_OFFSET:
6891 case GL_NUM_EXTENSIONS:
6892 case GL_MAJOR_VERSION:
6893 case GL_MINOR_VERSION:
6894 case GL_MAX_ELEMENTS_INDICES:
6895 case GL_MAX_ELEMENTS_VERTICES:
6896 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
6897 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
6898 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
6899 case GL_UNPACK_IMAGE_HEIGHT:
6900 case GL_UNPACK_SKIP_IMAGES:
6901 {
6902 *type = GL_INT;
6903 *numParams = 1;
6904 return true;
6905 }
6906
6907 case GL_MAX_ELEMENT_INDEX:
6908 case GL_MAX_UNIFORM_BLOCK_SIZE:
6909 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
6910 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
6911 case GL_MAX_SERVER_WAIT_TIMEOUT:
6912 {
6913 *type = GL_INT_64_ANGLEX;
6914 *numParams = 1;
6915 return true;
6916 }
6917
6918 case GL_TRANSFORM_FEEDBACK_ACTIVE:
6919 case GL_TRANSFORM_FEEDBACK_PAUSED:
6920 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
6921 case GL_RASTERIZER_DISCARD:
6922 {
6923 *type = GL_BOOL;
6924 *numParams = 1;
6925 return true;
6926 }
6927
6928 case GL_MAX_TEXTURE_LOD_BIAS:
6929 {
6930 *type = GL_FLOAT;
6931 *numParams = 1;
6932 return true;
6933 }
6934 }
6935
6936 if (getExtensions().requestExtension)
6937 {
6938 switch (pname)
6939 {
6940 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
6941 *type = GL_INT;
6942 *numParams = 1;
6943 return true;
6944 }
6945 }
6946
6947 if (getClientVersion() < Version(3, 1))
6948 {
6949 return false;
6950 }
6951
6952 switch (pname)
6953 {
6954 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
6955 case GL_DRAW_INDIRECT_BUFFER_BINDING:
6956 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
6957 case GL_MAX_FRAMEBUFFER_WIDTH:
6958 case GL_MAX_FRAMEBUFFER_HEIGHT:
6959 case GL_MAX_FRAMEBUFFER_SAMPLES:
6960 case GL_MAX_SAMPLE_MASK_WORDS:
6961 case GL_MAX_COLOR_TEXTURE_SAMPLES:
6962 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
6963 case GL_MAX_INTEGER_SAMPLES:
6964 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
6965 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
6966 case GL_MAX_VERTEX_ATTRIB_STRIDE:
6967 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
6968 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
6969 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
6970 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
6971 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
6972 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
6973 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
6974 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
6975 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
6976 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
6977 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
6978 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
6979 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
6980 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
6981 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
6982 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
6983 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
6984 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
6985 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
6986 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
6987 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
6988 case GL_MAX_UNIFORM_LOCATIONS:
6989 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
6990 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
6991 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
6992 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
6993 case GL_MAX_IMAGE_UNITS:
6994 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
6995 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
6996 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
6997 case GL_SHADER_STORAGE_BUFFER_BINDING:
6998 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
6999 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
7000 *type = GL_INT;
7001 *numParams = 1;
7002 return true;
7003 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7004 *type = GL_INT_64_ANGLEX;
7005 *numParams = 1;
7006 return true;
7007 case GL_SAMPLE_MASK:
7008 *type = GL_BOOL;
7009 *numParams = 1;
7010 return true;
7011 }
7012
7013 if (getExtensions().geometryShader)
7014 {
7015 switch (pname)
7016 {
7017 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7018 case GL_LAYER_PROVOKING_VERTEX_EXT:
7019 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7020 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7021 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7022 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7023 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7024 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7025 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7026 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7027 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7028 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7029 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7030 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7031 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7032 *type = GL_INT;
7033 *numParams = 1;
7034 return true;
7035 }
7036 }
7037
7038 return false;
7039}
7040
7041bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7042{
7043 if (getClientVersion() < Version(3, 0))
7044 {
7045 return false;
7046 }
7047
7048 switch (target)
7049 {
7050 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7051 case GL_UNIFORM_BUFFER_BINDING:
7052 {
7053 *type = GL_INT;
7054 *numParams = 1;
7055 return true;
7056 }
7057 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7058 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7059 case GL_UNIFORM_BUFFER_START:
7060 case GL_UNIFORM_BUFFER_SIZE:
7061 {
7062 *type = GL_INT_64_ANGLEX;
7063 *numParams = 1;
7064 return true;
7065 }
7066 }
7067
7068 if (getClientVersion() < Version(3, 1))
7069 {
7070 return false;
7071 }
7072
7073 switch (target)
7074 {
7075 case GL_IMAGE_BINDING_LAYERED:
7076 {
7077 *type = GL_BOOL;
7078 *numParams = 1;
7079 return true;
7080 }
7081 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7082 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7083 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7084 case GL_SHADER_STORAGE_BUFFER_BINDING:
7085 case GL_VERTEX_BINDING_BUFFER:
7086 case GL_VERTEX_BINDING_DIVISOR:
7087 case GL_VERTEX_BINDING_OFFSET:
7088 case GL_VERTEX_BINDING_STRIDE:
7089 case GL_SAMPLE_MASK_VALUE:
7090 case GL_IMAGE_BINDING_NAME:
7091 case GL_IMAGE_BINDING_LEVEL:
7092 case GL_IMAGE_BINDING_LAYER:
7093 case GL_IMAGE_BINDING_ACCESS:
7094 case GL_IMAGE_BINDING_FORMAT:
7095 {
7096 *type = GL_INT;
7097 *numParams = 1;
7098 return true;
7099 }
7100 case GL_ATOMIC_COUNTER_BUFFER_START:
7101 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
7102 case GL_SHADER_STORAGE_BUFFER_START:
7103 case GL_SHADER_STORAGE_BUFFER_SIZE:
7104 {
7105 *type = GL_INT_64_ANGLEX;
7106 *numParams = 1;
7107 return true;
7108 }
7109 }
7110
7111 return false;
7112}
7113
7114Program *Context::getProgram(GLuint handle) const
7115{
7116 return mState.mShaderPrograms->getProgram(handle);
7117}
7118
7119Shader *Context::getShader(GLuint handle) const
7120{
7121 return mState.mShaderPrograms->getShader(handle);
7122}
7123
7124bool Context::isTextureGenerated(GLuint texture) const
7125{
7126 return mState.mTextures->isHandleGenerated(texture);
7127}
7128
7129bool Context::isBufferGenerated(GLuint buffer) const
7130{
7131 return mState.mBuffers->isHandleGenerated(buffer);
7132}
7133
7134bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
7135{
7136 return mState.mRenderbuffers->isHandleGenerated(renderbuffer);
7137}
7138
7139bool Context::isFramebufferGenerated(GLuint framebuffer) const
7140{
7141 return mState.mFramebuffers->isHandleGenerated(framebuffer);
7142}
7143
7144bool Context::isProgramPipelineGenerated(GLuint pipeline) const
7145{
7146 return mState.mPipelines->isHandleGenerated(pipeline);
7147}
7148
7149bool Context::usingDisplayTextureShareGroup() const
7150{
7151 return mDisplayTextureShareGroup;
7152}
7153
7154GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
7155{
7156 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
7157 internalformat == GL_DEPTH_STENCIL
7158 ? GL_DEPTH24_STENCIL8
7159 : internalformat;
7160}
7161
Jamie Madillc29968b2016-01-20 11:17:23 -05007162} // namespace gl