blob: 930f6b6f06cda105b73d26fbb8b2ecd0de8f3f09 [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{
Ian Ewellec2c0c52016-04-05 13:46:26 -0400167 EGLAttrib attrib = attribs.get(EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT,
Jeff Gilbertc5de4d22017-10-31 15:07:53 -0700168 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)
Martin Radev1be913c2016-07-11 17:59:16 +0300267
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500268 : ValidationContext(shareContext,
Geoff Langce02f082017-02-06 16:46:21 -0500269 shareTextures,
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500270 GetClientVersion(attribs),
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700271 &mGLState,
Jamie Madillf25855c2015-11-03 11:06:18 -0500272 mCaps,
273 mTextureCaps,
274 mExtensions,
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500275 mLimitations,
276 GetNoError(attribs)),
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700277 mImplementation(implFactory->createContext(mState)),
Jamie Madill2f348d22017-06-05 10:50:59 -0400278 mCompiler(),
Corentin Walleze3b10e82015-05-20 11:06:25 -0400279 mConfig(config),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500280 mClientType(EGL_OPENGL_ES_API),
281 mHasBeenCurrent(false),
282 mContextLost(false),
283 mResetStatus(GL_NO_ERROR),
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700284 mContextLostForced(false),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500285 mResetStrategy(GetResetStrategy(attribs)),
286 mRobustAccess(GetRobustAccess(attribs)),
Jamie Madill61e16b42017-06-19 11:13:23 -0400287 mCurrentSurface(static_cast<egl::Surface *>(EGL_NO_SURFACE)),
288 mCurrentDisplay(static_cast<egl::Display *>(EGL_NO_DISPLAY)),
Jamie Madill4e0e6f82017-02-17 11:06:03 -0500289 mSurfacelessFramebuffer(nullptr),
Jamie Madille14951e2017-03-09 18:55:16 -0500290 mWebGLContext(GetWebGLContext(attribs)),
Jamie Madill32447362017-06-28 14:53:52 -0400291 mMemoryProgramCache(memoryProgramCache),
Jamie Madillb3f26b92017-07-19 15:07:41 -0400292 mScratchBuffer(1000u),
293 mZeroFilledBuffer(1000u)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000294{
Jamie Madill14bbb3f2017-09-12 15:23:01 -0400295 mImplementation->setMemoryProgramCache(memoryProgramCache);
296
Geoff Langb433e872017-10-05 14:01:47 -0400297 bool robustResourceInit = GetRobustResourceInit(attribs);
298 initCaps(displayExtensions, robustResourceInit);
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700299 initWorkarounds();
Geoff Langc0b9ef42014-07-02 10:02:37 -0400300
Jamie Madill4928b7c2017-06-20 12:57:39 -0400301 mGLState.initialize(this, GetDebug(attribs), GetBindGeneratesResource(attribs),
Jamie Madillc43be722017-07-13 16:22:14 -0400302 GetClientArraysEnabled(attribs), robustResourceInit,
303 mMemoryProgramCache != nullptr);
Régis Fénéon83107972015-02-05 12:57:44 +0100304
Shannon Woods53a94a82014-06-24 15:20:36 -0400305 mFenceNVHandleAllocator.setBaseHandle(0);
Geoff Lang7dca1862013-07-30 16:30:46 -0400306
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000307 // [OpenGL ES 2.0.24] section 3.7 page 83:
Corentin Wallez336129f2017-10-17 15:55:40 -0400308 // In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have two-dimensional
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000309 // and cube map texture state vectors respectively associated with them.
310 // In order that access to these initial textures not be lost, they are treated as texture
311 // objects all of whose names are 0.
312
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400313 Texture *zeroTexture2D = new Texture(mImplementation.get(), 0, GL_TEXTURE_2D);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400314 mZeroTextures[GL_TEXTURE_2D].set(this, zeroTexture2D);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500315
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400316 Texture *zeroTextureCube = new Texture(mImplementation.get(), 0, GL_TEXTURE_CUBE_MAP);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400317 mZeroTextures[GL_TEXTURE_CUBE_MAP].set(this, zeroTextureCube);
Geoff Lang76b10c92014-09-05 16:28:14 -0400318
Geoff Langeb66a6e2016-10-31 13:06:12 -0400319 if (getClientVersion() >= Version(3, 0))
Geoff Lang76b10c92014-09-05 16:28:14 -0400320 {
321 // TODO: These could also be enabled via extension
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400322 Texture *zeroTexture3D = new Texture(mImplementation.get(), 0, GL_TEXTURE_3D);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400323 mZeroTextures[GL_TEXTURE_3D].set(this, zeroTexture3D);
Geoff Lang76b10c92014-09-05 16:28:14 -0400324
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400325 Texture *zeroTexture2DArray = new Texture(mImplementation.get(), 0, GL_TEXTURE_2D_ARRAY);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400326 mZeroTextures[GL_TEXTURE_2D_ARRAY].set(this, zeroTexture2DArray);
Geoff Lang76b10c92014-09-05 16:28:14 -0400327 }
Geoff Lang3b573612016-10-31 14:08:10 -0400328 if (getClientVersion() >= Version(3, 1))
329 {
330 Texture *zeroTexture2DMultisample =
331 new Texture(mImplementation.get(), 0, GL_TEXTURE_2D_MULTISAMPLE);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400332 mZeroTextures[GL_TEXTURE_2D_MULTISAMPLE].set(this, zeroTexture2DMultisample);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800333
Jiajia Qin6eafb042016-12-27 17:04:07 +0800334 for (unsigned int i = 0; i < mCaps.maxAtomicCounterBufferBindings; i++)
335 {
Corentin Wallez336129f2017-10-17 15:55:40 -0400336 bindBufferRange(BufferBinding::AtomicCounter, 0, i, 0, 0);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800337 }
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800338
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800339 for (unsigned int i = 0; i < mCaps.maxShaderStorageBufferBindings; i++)
340 {
Corentin Wallez336129f2017-10-17 15:55:40 -0400341 bindBufferRange(BufferBinding::ShaderStorage, i, 0, 0, 0);
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800342 }
Geoff Lang3b573612016-10-31 14:08:10 -0400343 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000344
Geoff Lang4751aab2017-10-30 15:14:52 -0400345 const Extensions &nativeExtensions = mImplementation->getNativeExtensions();
346 if (nativeExtensions.textureRectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400347 {
348 Texture *zeroTextureRectangle =
349 new Texture(mImplementation.get(), 0, GL_TEXTURE_RECTANGLE_ANGLE);
350 mZeroTextures[GL_TEXTURE_RECTANGLE_ANGLE].set(this, zeroTextureRectangle);
351 }
352
Geoff Lang4751aab2017-10-30 15:14:52 -0400353 if (nativeExtensions.eglImageExternal || nativeExtensions.eglStreamConsumerExternal)
Ian Ewellbda75592016-04-18 17:25:54 -0400354 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400355 Texture *zeroTextureExternal =
356 new Texture(mImplementation.get(), 0, GL_TEXTURE_EXTERNAL_OES);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400357 mZeroTextures[GL_TEXTURE_EXTERNAL_OES].set(this, zeroTextureExternal);
Ian Ewellbda75592016-04-18 17:25:54 -0400358 }
359
Jamie Madill4928b7c2017-06-20 12:57:39 -0400360 mGLState.initializeZeroTextures(this, mZeroTextures);
Jamie Madille6382c32014-11-07 15:05:26 -0500361
Jamie Madill57a89722013-07-02 11:57:03 -0400362 bindVertexArray(0);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000363
Geoff Langeb66a6e2016-10-31 13:06:12 -0400364 if (getClientVersion() >= Version(3, 0))
Geoff Lang1a683462015-09-29 15:09:59 -0400365 {
366 // [OpenGL ES 3.0.2] section 2.14.1 pg 85:
367 // In the initial state, a default transform feedback object is bound and treated as
368 // a transform feedback object with a name of zero. That object is bound any time
369 // BindTransformFeedback is called with id of zero
Jamie Madillf0dcb8b2017-08-26 19:05:13 -0400370 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Geoff Lang1a683462015-09-29 15:09:59 -0400371 }
Geoff Langc8058452014-02-03 12:04:11 -0500372
Corentin Wallez336129f2017-10-17 15:55:40 -0400373 for (auto type : angle::AllEnums<BufferBinding>())
374 {
375 bindBuffer(type, 0);
376 }
377
378 bindRenderbuffer(GL_RENDERBUFFER, 0);
379
380 for (unsigned int i = 0; i < mCaps.maxUniformBufferBindings; i++)
381 {
382 bindBufferRange(BufferBinding::Uniform, i, 0, 0, -1);
383 }
384
Jamie Madillad9f24e2016-02-12 09:27:24 -0500385 // Initialize dirty bit masks
Jamie Madillc67323a2017-11-02 23:11:41 -0400386 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500387 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500388 // No dirty objects.
389
390 // Readpixels uses the pack state and read FBO
Jamie Madillc67323a2017-11-02 23:11:41 -0400391 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500392 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500393 mReadPixelsDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
394
395 mClearDirtyBits.set(State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED);
396 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
397 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR);
398 mClearDirtyBits.set(State::DIRTY_BIT_VIEWPORT);
399 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_COLOR);
400 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_DEPTH);
401 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_STENCIL);
402 mClearDirtyBits.set(State::DIRTY_BIT_COLOR_MASK);
403 mClearDirtyBits.set(State::DIRTY_BIT_DEPTH_MASK);
404 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT);
405 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_BACK);
406 mClearDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
407
408 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
409 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR);
Geoff Lang1d2c41d2016-10-19 16:14:46 -0700410 mBlitDirtyBits.set(State::DIRTY_BIT_FRAMEBUFFER_SRGB);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500411 mBlitDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
412 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
Jamie Madill437fa652016-05-03 15:13:24 -0400413
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400414 handleError(mImplementation->initialize());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000415}
416
Jamie Madill4928b7c2017-06-20 12:57:39 -0400417egl::Error Context::onDestroy(const egl::Display *display)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000418{
Corentin Wallez80b24112015-08-25 16:41:57 -0400419 for (auto fence : mFenceNVMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000420 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400421 SafeDelete(fence.second);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000422 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400423 mFenceNVMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000424
Corentin Wallez80b24112015-08-25 16:41:57 -0400425 for (auto query : mQueryMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000426 {
Geoff Langf0aa8422015-09-29 15:08:34 -0400427 if (query.second != nullptr)
428 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400429 query.second->release(this);
Geoff Langf0aa8422015-09-29 15:08:34 -0400430 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000431 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400432 mQueryMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000433
Corentin Wallez80b24112015-08-25 16:41:57 -0400434 for (auto vertexArray : mVertexArrayMap)
Jamie Madill57a89722013-07-02 11:57:03 -0400435 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400436 if (vertexArray.second)
437 {
438 vertexArray.second->onDestroy(this);
439 }
Jamie Madill57a89722013-07-02 11:57:03 -0400440 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400441 mVertexArrayMap.clear();
Jamie Madill57a89722013-07-02 11:57:03 -0400442
Corentin Wallez80b24112015-08-25 16:41:57 -0400443 for (auto transformFeedback : mTransformFeedbackMap)
Geoff Langc8058452014-02-03 12:04:11 -0500444 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500445 if (transformFeedback.second != nullptr)
446 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500447 transformFeedback.second->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500448 }
Geoff Langc8058452014-02-03 12:04:11 -0500449 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400450 mTransformFeedbackMap.clear();
Geoff Langc8058452014-02-03 12:04:11 -0500451
Jamie Madilldedd7b92014-11-05 16:30:36 -0500452 for (auto &zeroTexture : mZeroTextures)
Geoff Lang76b10c92014-09-05 16:28:14 -0400453 {
Jamie Madill71c88b32017-09-14 22:20:29 -0400454 ANGLE_TRY(zeroTexture.second->onDestroy(this));
Jamie Madill4928b7c2017-06-20 12:57:39 -0400455 zeroTexture.second.set(this, nullptr);
Geoff Lang76b10c92014-09-05 16:28:14 -0400456 }
457 mZeroTextures.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000458
Corentin Wallezccab69d2017-01-27 16:57:15 -0500459 SafeDelete(mSurfacelessFramebuffer);
460
Jamie Madill4928b7c2017-06-20 12:57:39 -0400461 ANGLE_TRY(releaseSurface(display));
Jamie Madill2f348d22017-06-05 10:50:59 -0400462 releaseShaderCompiler();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500463
Jamie Madill4928b7c2017-06-20 12:57:39 -0400464 mGLState.reset(this);
465
Jamie Madill6c1f6712017-02-14 19:08:04 -0500466 mState.mBuffers->release(this);
467 mState.mShaderPrograms->release(this);
468 mState.mTextures->release(this);
469 mState.mRenderbuffers->release(this);
470 mState.mSamplers->release(this);
Jamie Madill70b5bb02017-08-28 13:32:37 -0400471 mState.mSyncs->release(this);
Jamie Madill6c1f6712017-02-14 19:08:04 -0500472 mState.mPaths->release(this);
473 mState.mFramebuffers->release(this);
Yunchao Hea336b902017-08-02 16:05:21 +0800474 mState.mPipelines->release(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400475
Jamie Madill76e471e2017-10-21 09:56:01 -0400476 mImplementation->onDestroy(this);
477
Jamie Madill4928b7c2017-06-20 12:57:39 -0400478 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000479}
480
Jamie Madill70ee0f62017-02-06 16:04:20 -0500481Context::~Context()
482{
483}
484
Jamie Madill4928b7c2017-06-20 12:57:39 -0400485egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000486{
Jamie Madill61e16b42017-06-19 11:13:23 -0400487 mCurrentDisplay = display;
488
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000489 if (!mHasBeenCurrent)
490 {
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000491 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500492 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400493 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000494
Corentin Wallezc295e512017-01-27 17:47:50 -0500495 int width = 0;
496 int height = 0;
497 if (surface != nullptr)
498 {
499 width = surface->getWidth();
500 height = surface->getHeight();
501 }
502
503 mGLState.setViewportParams(0, 0, width, height);
504 mGLState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000505
506 mHasBeenCurrent = true;
507 }
508
Jamie Madill1b94d432015-08-07 13:23:23 -0400509 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700510 mGLState.setAllDirtyBits();
Jamie Madill81c2e252017-09-09 23:32:46 -0400511 mGLState.setAllDirtyObjects();
Jamie Madill1b94d432015-08-07 13:23:23 -0400512
Jamie Madill4928b7c2017-06-20 12:57:39 -0400513 ANGLE_TRY(releaseSurface(display));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500514
515 Framebuffer *newDefault = nullptr;
516 if (surface != nullptr)
517 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400518 ANGLE_TRY(surface->setIsCurrent(this, true));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500519 mCurrentSurface = surface;
520 newDefault = surface->getDefaultFramebuffer();
521 }
522 else
523 {
524 if (mSurfacelessFramebuffer == nullptr)
525 {
526 mSurfacelessFramebuffer = new Framebuffer(mImplementation.get());
527 }
528
529 newDefault = mSurfacelessFramebuffer;
530 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000531
Corentin Wallez37c39792015-08-20 14:19:46 -0400532 // Update default framebuffer, the binding of the previous default
533 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400534 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700535 if (mGLState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400536 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700537 mGLState.setReadFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400538 }
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700539 if (mGLState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400540 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700541 mGLState.setDrawFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400542 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500543 mState.mFramebuffers->setDefaultFramebuffer(newDefault);
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400544 }
Ian Ewell292f0052016-02-04 10:37:32 -0500545
546 // Notify the renderer of a context switch
Jamie Madill4928b7c2017-06-20 12:57:39 -0400547 mImplementation->onMakeCurrent(this);
548 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000549}
550
Jamie Madill4928b7c2017-06-20 12:57:39 -0400551egl::Error Context::releaseSurface(const egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400552{
Corentin Wallez37c39792015-08-20 14:19:46 -0400553 // Remove the default framebuffer
Corentin Wallezc295e512017-01-27 17:47:50 -0500554 Framebuffer *currentDefault = nullptr;
555 if (mCurrentSurface != nullptr)
Corentin Wallez51706ea2015-08-07 14:39:22 -0400556 {
Corentin Wallezc295e512017-01-27 17:47:50 -0500557 currentDefault = mCurrentSurface->getDefaultFramebuffer();
558 }
559 else if (mSurfacelessFramebuffer != nullptr)
560 {
561 currentDefault = mSurfacelessFramebuffer;
Corentin Wallez51706ea2015-08-07 14:39:22 -0400562 }
563
Corentin Wallezc295e512017-01-27 17:47:50 -0500564 if (mGLState.getReadFramebuffer() == currentDefault)
565 {
566 mGLState.setReadFramebufferBinding(nullptr);
567 }
568 if (mGLState.getDrawFramebuffer() == currentDefault)
569 {
570 mGLState.setDrawFramebufferBinding(nullptr);
571 }
572 mState.mFramebuffers->setDefaultFramebuffer(nullptr);
573
574 if (mCurrentSurface)
575 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400576 ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
Corentin Wallezc295e512017-01-27 17:47:50 -0500577 mCurrentSurface = nullptr;
578 }
Jamie Madill4928b7c2017-06-20 12:57:39 -0400579
580 return egl::NoError();
Jamie Madill77a72f62015-04-14 11:18:32 -0400581}
582
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000583GLuint Context::createBuffer()
584{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500585 return mState.mBuffers->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000586}
587
588GLuint Context::createProgram()
589{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500590 return mState.mShaderPrograms->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000591}
592
593GLuint Context::createShader(GLenum type)
594{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500595 return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000596}
597
598GLuint Context::createTexture()
599{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500600 return mState.mTextures->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000601}
602
603GLuint Context::createRenderbuffer()
604{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500605 return mState.mRenderbuffers->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000606}
607
Sami Väisänene45e53b2016-05-25 10:36:04 +0300608GLuint Context::createPaths(GLsizei range)
609{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500610 auto resultOrError = mState.mPaths->createPaths(mImplementation.get(), range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300611 if (resultOrError.isError())
612 {
613 handleError(resultOrError.getError());
614 return 0;
615 }
616 return resultOrError.getResult();
617}
618
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000619// Returns an unused framebuffer name
620GLuint Context::createFramebuffer()
621{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500622 return mState.mFramebuffers->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000623}
624
Jamie Madill33dc8432013-07-26 11:55:05 -0400625GLuint Context::createFenceNV()
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000626{
Jamie Madill33dc8432013-07-26 11:55:05 -0400627 GLuint handle = mFenceNVHandleAllocator.allocate();
Jamie Madill96a483b2017-06-27 16:49:21 -0400628 mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV()));
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000629 return handle;
630}
631
Yunchao Hea336b902017-08-02 16:05:21 +0800632GLuint Context::createProgramPipeline()
633{
634 return mState.mPipelines->createProgramPipeline();
635}
636
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000637void Context::deleteBuffer(GLuint buffer)
638{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500639 if (mState.mBuffers->getBuffer(buffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000640 {
641 detachBuffer(buffer);
642 }
Jamie Madill893ab082014-05-16 16:56:10 -0400643
Jamie Madill6c1f6712017-02-14 19:08:04 -0500644 mState.mBuffers->deleteObject(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000645}
646
647void Context::deleteShader(GLuint shader)
648{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500649 mState.mShaderPrograms->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000650}
651
652void Context::deleteProgram(GLuint program)
653{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500654 mState.mShaderPrograms->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000655}
656
657void Context::deleteTexture(GLuint texture)
658{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500659 if (mState.mTextures->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000660 {
661 detachTexture(texture);
662 }
663
Jamie Madill6c1f6712017-02-14 19:08:04 -0500664 mState.mTextures->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000665}
666
667void Context::deleteRenderbuffer(GLuint renderbuffer)
668{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500669 if (mState.mRenderbuffers->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000670 {
671 detachRenderbuffer(renderbuffer);
672 }
Jamie Madill893ab082014-05-16 16:56:10 -0400673
Jamie Madill6c1f6712017-02-14 19:08:04 -0500674 mState.mRenderbuffers->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000675}
676
Jamie Madill7f0c5a42017-08-26 22:43:26 -0400677void Context::deleteSync(GLsync sync)
Jamie Madillcd055f82013-07-26 11:55:15 -0400678{
679 // The spec specifies the underlying Fence object is not deleted until all current
680 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
681 // and since our API is currently designed for being called from a single thread, we can delete
682 // the fence immediately.
Jamie Madill70b5bb02017-08-28 13:32:37 -0400683 mState.mSyncs->deleteObject(this, static_cast<GLuint>(reinterpret_cast<uintptr_t>(sync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400684}
685
Yunchao Hea336b902017-08-02 16:05:21 +0800686void Context::deleteProgramPipeline(GLuint pipeline)
687{
688 if (mState.mPipelines->getProgramPipeline(pipeline))
689 {
690 detachProgramPipeline(pipeline);
691 }
692
693 mState.mPipelines->deleteObject(this, pipeline);
694}
695
Sami Väisänene45e53b2016-05-25 10:36:04 +0300696void Context::deletePaths(GLuint first, GLsizei range)
697{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500698 mState.mPaths->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300699}
700
701bool Context::hasPathData(GLuint path) const
702{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500703 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300704 if (pathObj == nullptr)
705 return false;
706
707 return pathObj->hasPathData();
708}
709
710bool Context::hasPath(GLuint path) const
711{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500712 return mState.mPaths->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300713}
714
715void Context::setPathCommands(GLuint path,
716 GLsizei numCommands,
717 const GLubyte *commands,
718 GLsizei numCoords,
719 GLenum coordType,
720 const void *coords)
721{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500722 auto *pathObject = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300723
724 handleError(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
725}
726
727void Context::setPathParameterf(GLuint path, GLenum pname, GLfloat value)
728{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500729 auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300730
731 switch (pname)
732 {
733 case GL_PATH_STROKE_WIDTH_CHROMIUM:
734 pathObj->setStrokeWidth(value);
735 break;
736 case GL_PATH_END_CAPS_CHROMIUM:
737 pathObj->setEndCaps(static_cast<GLenum>(value));
738 break;
739 case GL_PATH_JOIN_STYLE_CHROMIUM:
740 pathObj->setJoinStyle(static_cast<GLenum>(value));
741 break;
742 case GL_PATH_MITER_LIMIT_CHROMIUM:
743 pathObj->setMiterLimit(value);
744 break;
745 case GL_PATH_STROKE_BOUND_CHROMIUM:
746 pathObj->setStrokeBound(value);
747 break;
748 default:
749 UNREACHABLE();
750 break;
751 }
752}
753
754void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value) const
755{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500756 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300757
758 switch (pname)
759 {
760 case GL_PATH_STROKE_WIDTH_CHROMIUM:
761 *value = pathObj->getStrokeWidth();
762 break;
763 case GL_PATH_END_CAPS_CHROMIUM:
764 *value = static_cast<GLfloat>(pathObj->getEndCaps());
765 break;
766 case GL_PATH_JOIN_STYLE_CHROMIUM:
767 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
768 break;
769 case GL_PATH_MITER_LIMIT_CHROMIUM:
770 *value = pathObj->getMiterLimit();
771 break;
772 case GL_PATH_STROKE_BOUND_CHROMIUM:
773 *value = pathObj->getStrokeBound();
774 break;
775 default:
776 UNREACHABLE();
777 break;
778 }
779}
780
781void Context::setPathStencilFunc(GLenum func, GLint ref, GLuint mask)
782{
783 mGLState.setPathStencilFunc(func, ref, mask);
784}
785
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000786void Context::deleteFramebuffer(GLuint framebuffer)
787{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500788 if (mState.mFramebuffers->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000789 {
790 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000791 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500792
Jamie Madill6c1f6712017-02-14 19:08:04 -0500793 mState.mFramebuffers->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000794}
795
Jamie Madill33dc8432013-07-26 11:55:05 -0400796void Context::deleteFenceNV(GLuint fence)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000797{
Jamie Madill96a483b2017-06-27 16:49:21 -0400798 FenceNV *fenceObject = nullptr;
799 if (mFenceNVMap.erase(fence, &fenceObject))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000800 {
Jamie Madill96a483b2017-06-27 16:49:21 -0400801 mFenceNVHandleAllocator.release(fence);
802 delete fenceObject;
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000803 }
804}
805
Geoff Lang70d0f492015-12-10 17:45:46 -0500806Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000807{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500808 return mState.mBuffers->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000809}
810
Jamie Madill570f7c82014-07-03 10:38:54 -0400811Texture *Context::getTexture(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000812{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500813 return mState.mTextures->getTexture(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000814}
815
Geoff Lang70d0f492015-12-10 17:45:46 -0500816Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000817{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500818 return mState.mRenderbuffers->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000819}
820
Jamie Madill70b5bb02017-08-28 13:32:37 -0400821Sync *Context::getSync(GLsync handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400822{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400823 return mState.mSyncs->getSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400824}
825
Jamie Madill57a89722013-07-02 11:57:03 -0400826VertexArray *Context::getVertexArray(GLuint handle) const
827{
Jamie Madill96a483b2017-06-27 16:49:21 -0400828 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -0400829}
830
Jamie Madilldc356042013-07-19 16:36:57 -0400831Sampler *Context::getSampler(GLuint handle) const
832{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500833 return mState.mSamplers->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400834}
835
Geoff Langc8058452014-02-03 12:04:11 -0500836TransformFeedback *Context::getTransformFeedback(GLuint handle) const
837{
Jamie Madill96a483b2017-06-27 16:49:21 -0400838 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -0500839}
840
Yunchao Hea336b902017-08-02 16:05:21 +0800841ProgramPipeline *Context::getProgramPipeline(GLuint handle) const
842{
843 return mState.mPipelines->getProgramPipeline(handle);
844}
845
Geoff Lang70d0f492015-12-10 17:45:46 -0500846LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
847{
848 switch (identifier)
849 {
850 case GL_BUFFER:
851 return getBuffer(name);
852 case GL_SHADER:
853 return getShader(name);
854 case GL_PROGRAM:
855 return getProgram(name);
856 case GL_VERTEX_ARRAY:
857 return getVertexArray(name);
858 case GL_QUERY:
859 return getQuery(name);
860 case GL_TRANSFORM_FEEDBACK:
861 return getTransformFeedback(name);
862 case GL_SAMPLER:
863 return getSampler(name);
864 case GL_TEXTURE:
865 return getTexture(name);
866 case GL_RENDERBUFFER:
867 return getRenderbuffer(name);
868 case GL_FRAMEBUFFER:
869 return getFramebuffer(name);
870 default:
871 UNREACHABLE();
872 return nullptr;
873 }
874}
875
876LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
877{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400878 return getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
Geoff Lang70d0f492015-12-10 17:45:46 -0500879}
880
Martin Radev9d901792016-07-15 15:58:58 +0300881void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
882{
883 LabeledObject *object = getLabeledObject(identifier, name);
884 ASSERT(object != nullptr);
885
886 std::string labelName = GetObjectLabelFromPointer(length, label);
887 object->setLabel(labelName);
Jamie Madill8693bdb2017-09-02 15:32:14 -0400888
889 // TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the
890 // specified object is active until we do this.
891 mGLState.setObjectDirty(identifier);
Martin Radev9d901792016-07-15 15:58:58 +0300892}
893
894void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
895{
896 LabeledObject *object = getLabeledObjectFromPtr(ptr);
897 ASSERT(object != nullptr);
898
899 std::string labelName = GetObjectLabelFromPointer(length, label);
900 object->setLabel(labelName);
901}
902
903void Context::getObjectLabel(GLenum identifier,
904 GLuint name,
905 GLsizei bufSize,
906 GLsizei *length,
907 GLchar *label) const
908{
909 LabeledObject *object = getLabeledObject(identifier, name);
910 ASSERT(object != nullptr);
911
912 const std::string &objectLabel = object->getLabel();
913 GetObjectLabelBase(objectLabel, bufSize, length, label);
914}
915
916void Context::getObjectPtrLabel(const void *ptr,
917 GLsizei bufSize,
918 GLsizei *length,
919 GLchar *label) const
920{
921 LabeledObject *object = getLabeledObjectFromPtr(ptr);
922 ASSERT(object != nullptr);
923
924 const std::string &objectLabel = object->getLabel();
925 GetObjectLabelBase(objectLabel, bufSize, length, label);
926}
927
Jamie Madilldc356042013-07-19 16:36:57 -0400928bool Context::isSampler(GLuint samplerName) const
929{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500930 return mState.mSamplers->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -0400931}
932
Jamie Madilldedd7b92014-11-05 16:30:36 -0500933void Context::bindTexture(GLenum target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000934{
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500935 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000936
Jamie Madilldedd7b92014-11-05 16:30:36 -0500937 if (handle == 0)
938 {
939 texture = mZeroTextures[target].get();
940 }
941 else
942 {
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500943 texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500944 }
945
946 ASSERT(texture);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400947 mGLState.setSamplerTexture(this, target, texture);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +0000948}
949
Jamie Madill5bf9ff42016-02-01 11:13:03 -0500950void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000951{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500952 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
953 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700954 mGLState.setReadFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000955}
956
Jamie Madill5bf9ff42016-02-01 11:13:03 -0500957void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000958{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500959 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
960 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700961 mGLState.setDrawFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000962}
963
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500964void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -0400965{
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500966 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700967 mGLState.setVertexArrayBinding(vertexArray);
Jamie Madill57a89722013-07-02 11:57:03 -0400968}
969
Shao80957d92017-02-20 21:25:59 +0800970void Context::bindVertexBuffer(GLuint bindingIndex,
971 GLuint bufferHandle,
972 GLintptr offset,
973 GLsizei stride)
974{
975 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400976 mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Shao80957d92017-02-20 21:25:59 +0800977}
978
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500979void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -0400980{
Geoff Lang76b10c92014-09-05 16:28:14 -0400981 ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -0400982 Sampler *sampler =
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500983 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400984 mGLState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -0400985}
986
Xinghua Cao65ec0b22017-03-28 16:10:52 +0800987void Context::bindImageTexture(GLuint unit,
988 GLuint texture,
989 GLint level,
990 GLboolean layered,
991 GLint layer,
992 GLenum access,
993 GLenum format)
994{
995 Texture *tex = mState.mTextures->getTexture(texture);
996 mGLState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
997}
998
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000999void Context::useProgram(GLuint program)
1000{
Jamie Madill6c1f6712017-02-14 19:08:04 -05001001 mGLState.setProgram(this, getProgram(program));
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001002}
1003
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001004void Context::bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001005{
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001006 ASSERT(target == GL_TRANSFORM_FEEDBACK);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001007 TransformFeedback *transformFeedback =
1008 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001009 mGLState.setTransformFeedbackBinding(this, transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -05001010}
1011
Yunchao Hea336b902017-08-02 16:05:21 +08001012void Context::bindProgramPipeline(GLuint pipelineHandle)
1013{
1014 ProgramPipeline *pipeline =
1015 mState.mPipelines->checkProgramPipelineAllocation(mImplementation.get(), pipelineHandle);
1016 mGLState.setProgramPipelineBinding(this, pipeline);
1017}
1018
Jamie Madillf0e04492017-08-26 15:28:42 -04001019void Context::beginQuery(GLenum target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001020{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001021 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001022 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001023
Geoff Lang5aad9672014-09-08 11:10:42 -04001024 // begin query
Jamie Madillf0e04492017-08-26 15:28:42 -04001025 ANGLE_CONTEXT_TRY(queryObject->begin());
Geoff Lang5aad9672014-09-08 11:10:42 -04001026
1027 // set query as active for specified target only if begin succeeded
Jamie Madill4928b7c2017-06-20 12:57:39 -04001028 mGLState.setActiveQuery(this, target, queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001029}
1030
Jamie Madillf0e04492017-08-26 15:28:42 -04001031void Context::endQuery(GLenum target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001032{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001033 Query *queryObject = mGLState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001034 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001035
Jamie Madillf0e04492017-08-26 15:28:42 -04001036 handleError(queryObject->end());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001037
Geoff Lang5aad9672014-09-08 11:10:42 -04001038 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madill4928b7c2017-06-20 12:57:39 -04001039 mGLState.setActiveQuery(this, target, nullptr);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001040}
1041
Jamie Madillf0e04492017-08-26 15:28:42 -04001042void Context::queryCounter(GLuint id, GLenum target)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001043{
1044 ASSERT(target == GL_TIMESTAMP_EXT);
1045
1046 Query *queryObject = getQuery(id, true, target);
1047 ASSERT(queryObject);
1048
Jamie Madillf0e04492017-08-26 15:28:42 -04001049 handleError(queryObject->queryCounter());
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001050}
1051
1052void Context::getQueryiv(GLenum target, GLenum pname, GLint *params)
1053{
1054 switch (pname)
1055 {
1056 case GL_CURRENT_QUERY_EXT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001057 params[0] = mGLState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001058 break;
1059 case GL_QUERY_COUNTER_BITS_EXT:
1060 switch (target)
1061 {
1062 case GL_TIME_ELAPSED_EXT:
1063 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1064 break;
1065 case GL_TIMESTAMP_EXT:
1066 params[0] = getExtensions().queryCounterBitsTimestamp;
1067 break;
1068 default:
1069 UNREACHABLE();
1070 params[0] = 0;
1071 break;
1072 }
1073 break;
1074 default:
1075 UNREACHABLE();
1076 return;
1077 }
1078}
1079
Geoff Lang2186c382016-10-14 10:54:54 -04001080void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001081{
Geoff Lang2186c382016-10-14 10:54:54 -04001082 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001083}
1084
Geoff Lang2186c382016-10-14 10:54:54 -04001085void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001086{
Geoff Lang2186c382016-10-14 10:54:54 -04001087 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001088}
1089
Geoff Lang2186c382016-10-14 10:54:54 -04001090void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001091{
Geoff Lang2186c382016-10-14 10:54:54 -04001092 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001093}
1094
Geoff Lang2186c382016-10-14 10:54:54 -04001095void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001096{
Geoff Lang2186c382016-10-14 10:54:54 -04001097 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001098}
1099
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001100Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001101{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001102 return mState.mFramebuffers->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001103}
1104
Jamie Madill2f348d22017-06-05 10:50:59 -04001105FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001106{
Jamie Madill96a483b2017-06-27 16:49:21 -04001107 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001108}
1109
Jamie Madill2f348d22017-06-05 10:50:59 -04001110Query *Context::getQuery(GLuint handle, bool create, GLenum type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001111{
Jamie Madill96a483b2017-06-27 16:49:21 -04001112 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001113 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001114 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001115 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001116
1117 Query *query = mQueryMap.query(handle);
1118 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001119 {
Jamie Madill96a483b2017-06-27 16:49:21 -04001120 query = new Query(mImplementation->createQuery(type), handle);
1121 query->addRef();
1122 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001123 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001124 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001125}
1126
Geoff Lang70d0f492015-12-10 17:45:46 -05001127Query *Context::getQuery(GLuint handle) const
1128{
Jamie Madill96a483b2017-06-27 16:49:21 -04001129 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001130}
1131
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001132Texture *Context::getTargetTexture(GLenum target) const
1133{
Ian Ewellbda75592016-04-18 17:25:54 -04001134 ASSERT(ValidTextureTarget(this, target) || ValidTextureExternalTarget(this, target));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001135 return mGLState.getTargetTexture(target);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001136}
1137
Geoff Lang76b10c92014-09-05 16:28:14 -04001138Texture *Context::getSamplerTexture(unsigned int sampler, GLenum type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001139{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001140 return mGLState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001141}
1142
Geoff Lang492a7e42014-11-05 13:27:06 -05001143Compiler *Context::getCompiler() const
1144{
Jamie Madill2f348d22017-06-05 10:50:59 -04001145 if (mCompiler.get() == nullptr)
1146 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001147 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001148 }
1149 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001150}
1151
Jamie Madillc1d770e2017-04-13 17:31:24 -04001152void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001153{
1154 switch (pname)
1155 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001156 case GL_SHADER_COMPILER:
1157 *params = GL_TRUE;
1158 break;
1159 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1160 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1161 break;
1162 default:
1163 mGLState.getBooleanv(pname, params);
1164 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001165 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001166}
1167
Jamie Madillc1d770e2017-04-13 17:31:24 -04001168void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001169{
Shannon Woods53a94a82014-06-24 15:20:36 -04001170 // Queries about context capabilities and maximums are answered by Context.
1171 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001172 switch (pname)
1173 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001174 case GL_ALIASED_LINE_WIDTH_RANGE:
1175 params[0] = mCaps.minAliasedLineWidth;
1176 params[1] = mCaps.maxAliasedLineWidth;
1177 break;
1178 case GL_ALIASED_POINT_SIZE_RANGE:
1179 params[0] = mCaps.minAliasedPointSize;
1180 params[1] = mCaps.maxAliasedPointSize;
1181 break;
1182 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1183 ASSERT(mExtensions.textureFilterAnisotropic);
1184 *params = mExtensions.maxTextureAnisotropy;
1185 break;
1186 case GL_MAX_TEXTURE_LOD_BIAS:
1187 *params = mCaps.maxLODBias;
1188 break;
1189
1190 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1191 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1192 {
1193 ASSERT(mExtensions.pathRendering);
1194 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1195 memcpy(params, m, 16 * sizeof(GLfloat));
1196 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001197 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001198
Jamie Madill231c7f52017-04-26 13:45:37 -04001199 default:
1200 mGLState.getFloatv(pname, params);
1201 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001202 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001203}
1204
Jamie Madillc1d770e2017-04-13 17:31:24 -04001205void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001206{
Shannon Woods53a94a82014-06-24 15:20:36 -04001207 // Queries about context capabilities and maximums are answered by Context.
1208 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001209
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001210 switch (pname)
1211 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001212 case GL_MAX_VERTEX_ATTRIBS:
1213 *params = mCaps.maxVertexAttributes;
1214 break;
1215 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1216 *params = mCaps.maxVertexUniformVectors;
1217 break;
1218 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
1219 *params = mCaps.maxVertexUniformComponents;
1220 break;
1221 case GL_MAX_VARYING_VECTORS:
1222 *params = mCaps.maxVaryingVectors;
1223 break;
1224 case GL_MAX_VARYING_COMPONENTS:
1225 *params = mCaps.maxVertexOutputComponents;
1226 break;
1227 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1228 *params = mCaps.maxCombinedTextureImageUnits;
1229 break;
1230 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
1231 *params = mCaps.maxVertexTextureImageUnits;
1232 break;
1233 case GL_MAX_TEXTURE_IMAGE_UNITS:
1234 *params = mCaps.maxTextureImageUnits;
1235 break;
1236 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1237 *params = mCaps.maxFragmentUniformVectors;
1238 break;
1239 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
1240 *params = mCaps.maxFragmentUniformComponents;
1241 break;
1242 case GL_MAX_RENDERBUFFER_SIZE:
1243 *params = mCaps.maxRenderbufferSize;
1244 break;
1245 case GL_MAX_COLOR_ATTACHMENTS_EXT:
1246 *params = mCaps.maxColorAttachments;
1247 break;
1248 case GL_MAX_DRAW_BUFFERS_EXT:
1249 *params = mCaps.maxDrawBuffers;
1250 break;
1251 // case GL_FRAMEBUFFER_BINDING: // now equivalent to
1252 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
1253 case GL_SUBPIXEL_BITS:
1254 *params = 4;
1255 break;
1256 case GL_MAX_TEXTURE_SIZE:
1257 *params = mCaps.max2DTextureSize;
1258 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001259 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
1260 *params = mCaps.maxRectangleTextureSize;
1261 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001262 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1263 *params = mCaps.maxCubeMapTextureSize;
1264 break;
1265 case GL_MAX_3D_TEXTURE_SIZE:
1266 *params = mCaps.max3DTextureSize;
1267 break;
1268 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1269 *params = mCaps.maxArrayTextureLayers;
1270 break;
1271 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1272 *params = mCaps.uniformBufferOffsetAlignment;
1273 break;
1274 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1275 *params = mCaps.maxUniformBufferBindings;
1276 break;
1277 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
1278 *params = mCaps.maxVertexUniformBlocks;
1279 break;
1280 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
1281 *params = mCaps.maxFragmentUniformBlocks;
1282 break;
1283 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1284 *params = mCaps.maxCombinedTextureImageUnits;
1285 break;
1286 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1287 *params = mCaps.maxVertexOutputComponents;
1288 break;
1289 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1290 *params = mCaps.maxFragmentInputComponents;
1291 break;
1292 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1293 *params = mCaps.minProgramTexelOffset;
1294 break;
1295 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1296 *params = mCaps.maxProgramTexelOffset;
1297 break;
1298 case GL_MAJOR_VERSION:
1299 *params = getClientVersion().major;
1300 break;
1301 case GL_MINOR_VERSION:
1302 *params = getClientVersion().minor;
1303 break;
1304 case GL_MAX_ELEMENTS_INDICES:
1305 *params = mCaps.maxElementsIndices;
1306 break;
1307 case GL_MAX_ELEMENTS_VERTICES:
1308 *params = mCaps.maxElementsVertices;
1309 break;
1310 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1311 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1312 break;
1313 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1314 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1315 break;
1316 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1317 *params = mCaps.maxTransformFeedbackSeparateComponents;
1318 break;
1319 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1320 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1321 break;
1322 case GL_MAX_SAMPLES_ANGLE:
1323 *params = mCaps.maxSamples;
1324 break;
1325 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001326 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001327 params[0] = mCaps.maxViewportWidth;
1328 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001329 }
1330 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001331 case GL_COMPRESSED_TEXTURE_FORMATS:
1332 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1333 params);
1334 break;
1335 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1336 *params = mResetStrategy;
1337 break;
1338 case GL_NUM_SHADER_BINARY_FORMATS:
1339 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1340 break;
1341 case GL_SHADER_BINARY_FORMATS:
1342 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1343 break;
1344 case GL_NUM_PROGRAM_BINARY_FORMATS:
1345 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1346 break;
1347 case GL_PROGRAM_BINARY_FORMATS:
1348 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1349 break;
1350 case GL_NUM_EXTENSIONS:
1351 *params = static_cast<GLint>(mExtensionStrings.size());
1352 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001353
Jamie Madill231c7f52017-04-26 13:45:37 -04001354 // GL_KHR_debug
1355 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1356 *params = mExtensions.maxDebugMessageLength;
1357 break;
1358 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1359 *params = mExtensions.maxDebugLoggedMessages;
1360 break;
1361 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1362 *params = mExtensions.maxDebugGroupStackDepth;
1363 break;
1364 case GL_MAX_LABEL_LENGTH:
1365 *params = mExtensions.maxLabelLength;
1366 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001367
Martin Radeve5285d22017-07-14 16:23:53 +03001368 // GL_ANGLE_multiview
1369 case GL_MAX_VIEWS_ANGLE:
1370 *params = mExtensions.maxViews;
1371 break;
1372
Jamie Madill231c7f52017-04-26 13:45:37 -04001373 // GL_EXT_disjoint_timer_query
1374 case GL_GPU_DISJOINT_EXT:
1375 *params = mImplementation->getGPUDisjoint();
1376 break;
1377 case GL_MAX_FRAMEBUFFER_WIDTH:
1378 *params = mCaps.maxFramebufferWidth;
1379 break;
1380 case GL_MAX_FRAMEBUFFER_HEIGHT:
1381 *params = mCaps.maxFramebufferHeight;
1382 break;
1383 case GL_MAX_FRAMEBUFFER_SAMPLES:
1384 *params = mCaps.maxFramebufferSamples;
1385 break;
1386 case GL_MAX_SAMPLE_MASK_WORDS:
1387 *params = mCaps.maxSampleMaskWords;
1388 break;
1389 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1390 *params = mCaps.maxColorTextureSamples;
1391 break;
1392 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1393 *params = mCaps.maxDepthTextureSamples;
1394 break;
1395 case GL_MAX_INTEGER_SAMPLES:
1396 *params = mCaps.maxIntegerSamples;
1397 break;
1398 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1399 *params = mCaps.maxVertexAttribRelativeOffset;
1400 break;
1401 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1402 *params = mCaps.maxVertexAttribBindings;
1403 break;
1404 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1405 *params = mCaps.maxVertexAttribStride;
1406 break;
1407 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
1408 *params = mCaps.maxVertexAtomicCounterBuffers;
1409 break;
1410 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
1411 *params = mCaps.maxVertexAtomicCounters;
1412 break;
1413 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
1414 *params = mCaps.maxVertexImageUniforms;
1415 break;
1416 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
1417 *params = mCaps.maxVertexShaderStorageBlocks;
1418 break;
1419 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
1420 *params = mCaps.maxFragmentAtomicCounterBuffers;
1421 break;
1422 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
1423 *params = mCaps.maxFragmentAtomicCounters;
1424 break;
1425 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
1426 *params = mCaps.maxFragmentImageUniforms;
1427 break;
1428 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
1429 *params = mCaps.maxFragmentShaderStorageBlocks;
1430 break;
1431 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1432 *params = mCaps.minProgramTextureGatherOffset;
1433 break;
1434 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1435 *params = mCaps.maxProgramTextureGatherOffset;
1436 break;
1437 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1438 *params = mCaps.maxComputeWorkGroupInvocations;
1439 break;
1440 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
1441 *params = mCaps.maxComputeUniformBlocks;
1442 break;
1443 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
1444 *params = mCaps.maxComputeTextureImageUnits;
1445 break;
1446 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1447 *params = mCaps.maxComputeSharedMemorySize;
1448 break;
1449 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
1450 *params = mCaps.maxComputeUniformComponents;
1451 break;
1452 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
1453 *params = mCaps.maxComputeAtomicCounterBuffers;
1454 break;
1455 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
1456 *params = mCaps.maxComputeAtomicCounters;
1457 break;
1458 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
1459 *params = mCaps.maxComputeImageUniforms;
1460 break;
1461 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
1462 *params = mCaps.maxCombinedComputeUniformComponents;
1463 break;
1464 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
1465 *params = mCaps.maxComputeShaderStorageBlocks;
1466 break;
1467 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1468 *params = mCaps.maxCombinedShaderOutputResources;
1469 break;
1470 case GL_MAX_UNIFORM_LOCATIONS:
1471 *params = mCaps.maxUniformLocations;
1472 break;
1473 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1474 *params = mCaps.maxAtomicCounterBufferBindings;
1475 break;
1476 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1477 *params = mCaps.maxAtomicCounterBufferSize;
1478 break;
1479 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1480 *params = mCaps.maxCombinedAtomicCounterBuffers;
1481 break;
1482 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1483 *params = mCaps.maxCombinedAtomicCounters;
1484 break;
1485 case GL_MAX_IMAGE_UNITS:
1486 *params = mCaps.maxImageUnits;
1487 break;
1488 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1489 *params = mCaps.maxCombinedImageUniforms;
1490 break;
1491 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1492 *params = mCaps.maxShaderStorageBufferBindings;
1493 break;
1494 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1495 *params = mCaps.maxCombinedShaderStorageBlocks;
1496 break;
1497 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1498 *params = mCaps.shaderStorageBufferOffsetAlignment;
1499 break;
1500 default:
1501 mGLState.getIntegerv(this, pname, params);
1502 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001503 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001504}
1505
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001506void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001507{
Shannon Woods53a94a82014-06-24 15:20:36 -04001508 // Queries about context capabilities and maximums are answered by Context.
1509 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001510 switch (pname)
1511 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001512 case GL_MAX_ELEMENT_INDEX:
1513 *params = mCaps.maxElementIndex;
1514 break;
1515 case GL_MAX_UNIFORM_BLOCK_SIZE:
1516 *params = mCaps.maxUniformBlockSize;
1517 break;
1518 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
1519 *params = mCaps.maxCombinedVertexUniformComponents;
1520 break;
1521 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
1522 *params = mCaps.maxCombinedFragmentUniformComponents;
1523 break;
1524 case GL_MAX_SERVER_WAIT_TIMEOUT:
1525 *params = mCaps.maxServerWaitTimeout;
1526 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001527
Jamie Madill231c7f52017-04-26 13:45:37 -04001528 // GL_EXT_disjoint_timer_query
1529 case GL_TIMESTAMP_EXT:
1530 *params = mImplementation->getTimestamp();
1531 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001532
Jamie Madill231c7f52017-04-26 13:45:37 -04001533 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1534 *params = mCaps.maxShaderStorageBlockSize;
1535 break;
1536 default:
1537 UNREACHABLE();
1538 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001539 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001540}
1541
Geoff Lang70d0f492015-12-10 17:45:46 -05001542void Context::getPointerv(GLenum pname, void **params) const
1543{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001544 mGLState.getPointerv(pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001545}
1546
Martin Radev66fb8202016-07-28 11:45:20 +03001547void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001548{
Shannon Woods53a94a82014-06-24 15:20:36 -04001549 // Queries about context capabilities and maximums are answered by Context.
1550 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001551
1552 GLenum nativeType;
1553 unsigned int numParams;
1554 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1555 ASSERT(queryStatus);
1556
1557 if (nativeType == GL_INT)
1558 {
1559 switch (target)
1560 {
1561 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1562 ASSERT(index < 3u);
1563 *data = mCaps.maxComputeWorkGroupCount[index];
1564 break;
1565 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1566 ASSERT(index < 3u);
1567 *data = mCaps.maxComputeWorkGroupSize[index];
1568 break;
1569 default:
1570 mGLState.getIntegeri_v(target, index, data);
1571 }
1572 }
1573 else
1574 {
1575 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1576 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001577}
1578
Martin Radev66fb8202016-07-28 11:45:20 +03001579void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001580{
Shannon Woods53a94a82014-06-24 15:20:36 -04001581 // Queries about context capabilities and maximums are answered by Context.
1582 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001583
1584 GLenum nativeType;
1585 unsigned int numParams;
1586 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1587 ASSERT(queryStatus);
1588
1589 if (nativeType == GL_INT_64_ANGLEX)
1590 {
1591 mGLState.getInteger64i_v(target, index, data);
1592 }
1593 else
1594 {
1595 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1596 }
1597}
1598
1599void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1600{
1601 // Queries about context capabilities and maximums are answered by Context.
1602 // Queries about current GL state values are answered by State.
1603
1604 GLenum nativeType;
1605 unsigned int numParams;
1606 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1607 ASSERT(queryStatus);
1608
1609 if (nativeType == GL_BOOL)
1610 {
1611 mGLState.getBooleani_v(target, index, data);
1612 }
1613 else
1614 {
1615 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1616 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001617}
1618
Corentin Wallez336129f2017-10-17 15:55:40 -04001619void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001620{
1621 Buffer *buffer = mGLState.getTargetBuffer(target);
1622 QueryBufferParameteriv(buffer, pname, params);
1623}
1624
1625void Context::getFramebufferAttachmentParameteriv(GLenum target,
1626 GLenum attachment,
1627 GLenum pname,
1628 GLint *params)
1629{
1630 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
1631 QueryFramebufferAttachmentParameteriv(framebuffer, attachment, pname, params);
1632}
1633
1634void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
1635{
1636 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
1637 QueryRenderbufferiv(this, renderbuffer, pname, params);
1638}
1639
1640void Context::getTexParameterfv(GLenum target, GLenum pname, GLfloat *params)
1641{
1642 Texture *texture = getTargetTexture(target);
1643 QueryTexParameterfv(texture, pname, params);
1644}
1645
1646void Context::getTexParameteriv(GLenum target, GLenum pname, GLint *params)
1647{
1648 Texture *texture = getTargetTexture(target);
1649 QueryTexParameteriv(texture, pname, params);
1650}
1651void Context::texParameterf(GLenum target, GLenum pname, GLfloat param)
1652{
1653 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001654 SetTexParameterf(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04001655 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001656}
1657
1658void Context::texParameterfv(GLenum target, GLenum pname, const GLfloat *params)
1659{
1660 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001661 SetTexParameterfv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04001662 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001663}
1664
1665void Context::texParameteri(GLenum target, GLenum pname, GLint param)
1666{
1667 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001668 SetTexParameteri(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04001669 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001670}
1671
1672void Context::texParameteriv(GLenum target, GLenum pname, const GLint *params)
1673{
1674 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001675 SetTexParameteriv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04001676 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001677}
1678
Jamie Madill675fe712016-12-19 13:07:54 -05001679void Context::drawArrays(GLenum mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001680{
Jamie Madill05b35b22017-10-03 09:01:44 -04001681 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001682 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
1683 MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001684}
1685
Jamie Madill675fe712016-12-19 13:07:54 -05001686void Context::drawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04001687{
Jamie Madill05b35b22017-10-03 09:01:44 -04001688 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001689 ANGLE_CONTEXT_TRY(
1690 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
1691 MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback());
Geoff Langf6db0982015-08-25 13:04:00 -04001692}
1693
Jamie Madill876429b2017-04-20 15:46:24 -04001694void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001695{
Jamie Madill05b35b22017-10-03 09:01:44 -04001696 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001697 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04001698}
1699
Jamie Madill675fe712016-12-19 13:07:54 -05001700void Context::drawElementsInstanced(GLenum mode,
1701 GLsizei count,
1702 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04001703 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04001704 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04001705{
Jamie Madill05b35b22017-10-03 09:01:44 -04001706 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001707 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08001708 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04001709}
1710
Jamie Madill675fe712016-12-19 13:07:54 -05001711void Context::drawRangeElements(GLenum mode,
1712 GLuint start,
1713 GLuint end,
1714 GLsizei count,
1715 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04001716 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04001717{
Jamie Madill05b35b22017-10-03 09:01:44 -04001718 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001719 ANGLE_CONTEXT_TRY(
1720 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001721}
1722
Jamie Madill876429b2017-04-20 15:46:24 -04001723void Context::drawArraysIndirect(GLenum mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08001724{
Jamie Madill05b35b22017-10-03 09:01:44 -04001725 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001726 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08001727}
1728
Jamie Madill876429b2017-04-20 15:46:24 -04001729void Context::drawElementsIndirect(GLenum mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08001730{
Jamie Madill05b35b22017-10-03 09:01:44 -04001731 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001732 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08001733}
1734
Jamie Madill675fe712016-12-19 13:07:54 -05001735void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001736{
Jamie Madill675fe712016-12-19 13:07:54 -05001737 handleError(mImplementation->flush());
Geoff Lang129753a2015-01-09 16:52:09 -05001738}
1739
Jamie Madill675fe712016-12-19 13:07:54 -05001740void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05001741{
Jamie Madill675fe712016-12-19 13:07:54 -05001742 handleError(mImplementation->finish());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001743}
1744
Austin Kinross6ee1e782015-05-29 17:05:37 -07001745void Context::insertEventMarker(GLsizei length, const char *marker)
1746{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001747 ASSERT(mImplementation);
1748 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07001749}
1750
1751void Context::pushGroupMarker(GLsizei length, const char *marker)
1752{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001753 ASSERT(mImplementation);
1754 mImplementation->pushGroupMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07001755}
1756
1757void Context::popGroupMarker()
1758{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001759 ASSERT(mImplementation);
1760 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07001761}
1762
Geoff Langd8605522016-04-13 10:19:12 -04001763void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
1764{
1765 Program *programObject = getProgram(program);
1766 ASSERT(programObject);
1767
1768 programObject->bindUniformLocation(location, name);
1769}
1770
Sami Väisänena797e062016-05-12 15:23:40 +03001771void Context::setCoverageModulation(GLenum components)
1772{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001773 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03001774}
1775
Sami Väisänene45e53b2016-05-25 10:36:04 +03001776void Context::loadPathRenderingMatrix(GLenum matrixMode, const GLfloat *matrix)
1777{
1778 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
1779}
1780
1781void Context::loadPathRenderingIdentityMatrix(GLenum matrixMode)
1782{
1783 GLfloat I[16];
1784 angle::Matrix<GLfloat>::setToIdentity(I);
1785
1786 mGLState.loadPathRenderingMatrix(matrixMode, I);
1787}
1788
1789void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
1790{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001791 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001792 if (!pathObj)
1793 return;
1794
1795 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1796 syncRendererState();
1797
1798 mImplementation->stencilFillPath(pathObj, fillMode, mask);
1799}
1800
1801void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
1802{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001803 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001804 if (!pathObj)
1805 return;
1806
1807 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1808 syncRendererState();
1809
1810 mImplementation->stencilStrokePath(pathObj, reference, mask);
1811}
1812
1813void Context::coverFillPath(GLuint path, GLenum coverMode)
1814{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001815 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001816 if (!pathObj)
1817 return;
1818
1819 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1820 syncRendererState();
1821
1822 mImplementation->coverFillPath(pathObj, coverMode);
1823}
1824
1825void Context::coverStrokePath(GLuint path, GLenum coverMode)
1826{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001827 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001828 if (!pathObj)
1829 return;
1830
1831 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1832 syncRendererState();
1833
1834 mImplementation->coverStrokePath(pathObj, coverMode);
1835}
1836
1837void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
1838{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001839 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001840 if (!pathObj)
1841 return;
1842
1843 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1844 syncRendererState();
1845
1846 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
1847}
1848
1849void Context::stencilThenCoverStrokePath(GLuint path,
1850 GLint reference,
1851 GLuint mask,
1852 GLenum coverMode)
1853{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001854 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001855 if (!pathObj)
1856 return;
1857
1858 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1859 syncRendererState();
1860
1861 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
1862}
1863
Sami Väisänend59ca052016-06-21 16:10:00 +03001864void Context::coverFillPathInstanced(GLsizei numPaths,
1865 GLenum pathNameType,
1866 const void *paths,
1867 GLuint pathBase,
1868 GLenum coverMode,
1869 GLenum transformType,
1870 const GLfloat *transformValues)
1871{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001872 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03001873
1874 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1875 syncRendererState();
1876
1877 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
1878}
Sami Väisänen46eaa942016-06-29 10:26:37 +03001879
Sami Väisänend59ca052016-06-21 16:10:00 +03001880void Context::coverStrokePathInstanced(GLsizei numPaths,
1881 GLenum pathNameType,
1882 const void *paths,
1883 GLuint pathBase,
1884 GLenum coverMode,
1885 GLenum transformType,
1886 const GLfloat *transformValues)
1887{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001888 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03001889
1890 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1891 syncRendererState();
1892
1893 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
1894 transformValues);
1895}
Sami Väisänen46eaa942016-06-29 10:26:37 +03001896
Sami Väisänend59ca052016-06-21 16:10:00 +03001897void Context::stencilFillPathInstanced(GLsizei numPaths,
1898 GLenum pathNameType,
1899 const void *paths,
1900 GLuint pathBase,
1901 GLenum fillMode,
1902 GLuint mask,
1903 GLenum transformType,
1904 const GLfloat *transformValues)
1905{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001906 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03001907
1908 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1909 syncRendererState();
1910
1911 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
1912 transformValues);
1913}
Sami Väisänen46eaa942016-06-29 10:26:37 +03001914
Sami Väisänend59ca052016-06-21 16:10:00 +03001915void Context::stencilStrokePathInstanced(GLsizei numPaths,
1916 GLenum pathNameType,
1917 const void *paths,
1918 GLuint pathBase,
1919 GLint reference,
1920 GLuint mask,
1921 GLenum transformType,
1922 const GLfloat *transformValues)
1923{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001924 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03001925
1926 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1927 syncRendererState();
1928
1929 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
1930 transformValues);
1931}
Sami Väisänen46eaa942016-06-29 10:26:37 +03001932
Sami Väisänend59ca052016-06-21 16:10:00 +03001933void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
1934 GLenum pathNameType,
1935 const void *paths,
1936 GLuint pathBase,
1937 GLenum fillMode,
1938 GLuint mask,
1939 GLenum coverMode,
1940 GLenum transformType,
1941 const GLfloat *transformValues)
1942{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001943 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03001944
1945 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1946 syncRendererState();
1947
1948 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
1949 transformType, transformValues);
1950}
Sami Väisänen46eaa942016-06-29 10:26:37 +03001951
Sami Väisänend59ca052016-06-21 16:10:00 +03001952void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
1953 GLenum pathNameType,
1954 const void *paths,
1955 GLuint pathBase,
1956 GLint reference,
1957 GLuint mask,
1958 GLenum coverMode,
1959 GLenum transformType,
1960 const GLfloat *transformValues)
1961{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001962 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03001963
1964 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1965 syncRendererState();
1966
1967 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
1968 transformType, transformValues);
1969}
1970
Sami Väisänen46eaa942016-06-29 10:26:37 +03001971void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
1972{
1973 auto *programObject = getProgram(program);
1974
1975 programObject->bindFragmentInputLocation(location, name);
1976}
1977
1978void Context::programPathFragmentInputGen(GLuint program,
1979 GLint location,
1980 GLenum genMode,
1981 GLint components,
1982 const GLfloat *coeffs)
1983{
1984 auto *programObject = getProgram(program);
1985
Jamie Madillbd044ed2017-06-05 12:59:21 -04001986 programObject->pathFragmentInputGen(this, location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03001987}
1988
jchen1015015f72017-03-16 13:54:21 +08001989GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
1990{
jchen10fd7c3b52017-03-21 15:36:03 +08001991 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08001992 return QueryProgramResourceIndex(programObject, programInterface, name);
1993}
1994
jchen10fd7c3b52017-03-21 15:36:03 +08001995void Context::getProgramResourceName(GLuint program,
1996 GLenum programInterface,
1997 GLuint index,
1998 GLsizei bufSize,
1999 GLsizei *length,
2000 GLchar *name)
2001{
2002 const auto *programObject = getProgram(program);
2003 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2004}
2005
jchen10191381f2017-04-11 13:59:04 +08002006GLint Context::getProgramResourceLocation(GLuint program,
2007 GLenum programInterface,
2008 const GLchar *name)
2009{
2010 const auto *programObject = getProgram(program);
2011 return QueryProgramResourceLocation(programObject, programInterface, name);
2012}
2013
jchen10880683b2017-04-12 16:21:55 +08002014void Context::getProgramResourceiv(GLuint program,
2015 GLenum programInterface,
2016 GLuint index,
2017 GLsizei propCount,
2018 const GLenum *props,
2019 GLsizei bufSize,
2020 GLsizei *length,
2021 GLint *params)
2022{
2023 const auto *programObject = getProgram(program);
2024 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2025 length, params);
2026}
2027
jchen10d9cd7b72017-08-30 15:04:25 +08002028void Context::getProgramInterfaceiv(GLuint program,
2029 GLenum programInterface,
2030 GLenum pname,
2031 GLint *params)
2032{
2033 const auto *programObject = getProgram(program);
2034 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2035}
2036
Jamie Madill71c88b32017-09-14 22:20:29 -04002037void Context::handleError(const Error &error)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002038{
Geoff Langda5777c2014-07-11 09:52:58 -04002039 if (error.isError())
2040 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002041 GLenum code = error.getCode();
2042 mErrors.insert(code);
2043 if (code == GL_OUT_OF_MEMORY && getWorkarounds().loseContextOnOutOfMemory)
2044 {
2045 markContextLost();
2046 }
Geoff Lang70d0f492015-12-10 17:45:46 -05002047
Geoff Langee6884e2017-11-09 16:51:11 -05002048 ASSERT(!error.getMessage().empty());
2049 mGLState.getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, error.getID(),
2050 GL_DEBUG_SEVERITY_HIGH, error.getMessage());
Geoff Langda5777c2014-07-11 09:52:58 -04002051 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002052}
2053
2054// Get one of the recorded errors and clear its flag, if any.
2055// [OpenGL ES 2.0.24] section 2.5 page 13.
2056GLenum Context::getError()
2057{
Geoff Langda5777c2014-07-11 09:52:58 -04002058 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002059 {
Geoff Langda5777c2014-07-11 09:52:58 -04002060 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002061 }
Geoff Langda5777c2014-07-11 09:52:58 -04002062 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002063 {
Geoff Langda5777c2014-07-11 09:52:58 -04002064 GLenum error = *mErrors.begin();
2065 mErrors.erase(mErrors.begin());
2066 return error;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002067 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002068}
2069
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002070// NOTE: this function should not assume that this context is current!
2071void Context::markContextLost()
2072{
2073 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002074 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002075 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002076 mContextLostForced = true;
2077 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002078 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002079}
2080
2081bool Context::isContextLost()
2082{
2083 return mContextLost;
2084}
2085
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002086GLenum Context::getResetStatus()
2087{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002088 // Even if the application doesn't want to know about resets, we want to know
2089 // as it will allow us to skip all the calls.
2090 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002091 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002092 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002093 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002094 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002095 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002096
2097 // EXT_robustness, section 2.6: If the reset notification behavior is
2098 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2099 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2100 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002101 }
2102
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002103 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2104 // status should be returned at least once, and GL_NO_ERROR should be returned
2105 // once the device has finished resetting.
2106 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002107 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002108 ASSERT(mResetStatus == GL_NO_ERROR);
2109 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002110
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002111 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002112 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002113 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002114 }
2115 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002116 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002117 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002118 // If markContextLost was used to mark the context lost then
2119 // assume that is not recoverable, and continue to report the
2120 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002121 mResetStatus = mImplementation->getResetStatus();
2122 }
Jamie Madill893ab082014-05-16 16:56:10 -04002123
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002124 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002125}
2126
2127bool Context::isResetNotificationEnabled()
2128{
2129 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2130}
2131
Corentin Walleze3b10e82015-05-20 11:06:25 -04002132const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002133{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002134 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002135}
2136
2137EGLenum Context::getClientType() const
2138{
2139 return mClientType;
2140}
2141
2142EGLenum Context::getRenderBuffer() const
2143{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002144 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2145 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002146 {
2147 return EGL_NONE;
2148 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002149
2150 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(GL_BACK);
2151 ASSERT(backAttachment != nullptr);
2152 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002153}
2154
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002155VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002156{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002157 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002158 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2159 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002160 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002161 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2162 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002163
Jamie Madill96a483b2017-06-27 16:49:21 -04002164 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002165 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002166
2167 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002168}
2169
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002170TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002171{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002172 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002173 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2174 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002175 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002176 transformFeedback =
2177 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002178 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002179 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002180 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002181
2182 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002183}
2184
2185bool Context::isVertexArrayGenerated(GLuint vertexArray)
2186{
Jamie Madill96a483b2017-06-27 16:49:21 -04002187 ASSERT(mVertexArrayMap.contains(0));
2188 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002189}
2190
2191bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2192{
Jamie Madill96a483b2017-06-27 16:49:21 -04002193 ASSERT(mTransformFeedbackMap.contains(0));
2194 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002195}
2196
Shannon Woods53a94a82014-06-24 15:20:36 -04002197void Context::detachTexture(GLuint texture)
2198{
2199 // Simple pass-through to State's detachTexture method, as textures do not require
2200 // allocation map management either here or in the resource manager at detach time.
2201 // Zero textures are held by the Context, and we don't attempt to request them from
2202 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002203 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002204}
2205
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002206void Context::detachBuffer(GLuint buffer)
2207{
Yuly Novikov5807a532015-12-03 13:01:22 -05002208 // Simple pass-through to State's detachBuffer method, since
2209 // only buffer attachments to container objects that are bound to the current context
2210 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002211
Yuly Novikov5807a532015-12-03 13:01:22 -05002212 // [OpenGL ES 3.2] section 5.1.2 page 45:
2213 // Attachments to unbound container objects, such as
2214 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2215 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002216 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002217}
2218
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002219void Context::detachFramebuffer(GLuint framebuffer)
2220{
Shannon Woods53a94a82014-06-24 15:20:36 -04002221 // Framebuffer detachment is handled by Context, because 0 is a valid
2222 // Framebuffer object, and a pointer to it must be passed from Context
2223 // to State at binding time.
2224
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002225 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002226 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2227 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2228 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002229
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002230 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002231 {
2232 bindReadFramebuffer(0);
2233 }
2234
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002235 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002236 {
2237 bindDrawFramebuffer(0);
2238 }
2239}
2240
2241void Context::detachRenderbuffer(GLuint renderbuffer)
2242{
Jamie Madilla02315b2017-02-23 14:14:47 -05002243 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002244}
2245
Jamie Madill57a89722013-07-02 11:57:03 -04002246void Context::detachVertexArray(GLuint vertexArray)
2247{
Jamie Madill77a72f62015-04-14 11:18:32 -04002248 // Vertex array detachment is handled by Context, because 0 is a valid
2249 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002250 // binding time.
2251
Jamie Madill57a89722013-07-02 11:57:03 -04002252 // [OpenGL ES 3.0.2] section 2.10 page 43:
2253 // If a vertex array object that is currently bound is deleted, the binding
2254 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002255 if (mGLState.removeVertexArrayBinding(vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002256 {
2257 bindVertexArray(0);
2258 }
2259}
2260
Geoff Langc8058452014-02-03 12:04:11 -05002261void Context::detachTransformFeedback(GLuint transformFeedback)
2262{
Corentin Walleza2257da2016-04-19 16:43:12 -04002263 // Transform feedback detachment is handled by Context, because 0 is a valid
2264 // transform feedback, and a pointer to it must be passed from Context to State at
2265 // binding time.
2266
2267 // The OpenGL specification doesn't mention what should happen when the currently bound
2268 // transform feedback object is deleted. Since it is a container object, we treat it like
2269 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002270 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002271 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002272 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002273 }
Geoff Langc8058452014-02-03 12:04:11 -05002274}
2275
Jamie Madilldc356042013-07-19 16:36:57 -04002276void Context::detachSampler(GLuint sampler)
2277{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002278 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002279}
2280
Yunchao Hea336b902017-08-02 16:05:21 +08002281void Context::detachProgramPipeline(GLuint pipeline)
2282{
2283 mGLState.detachProgramPipeline(this, pipeline);
2284}
2285
Jamie Madill3ef140a2017-08-26 23:11:21 -04002286void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002287{
Shaodde78e82017-05-22 14:13:27 +08002288 mGLState.setVertexAttribDivisor(this, index, divisor);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002289}
2290
Jamie Madille29d1672013-07-19 16:36:57 -04002291void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2292{
Geoff Langc1984ed2016-10-07 12:41:00 -04002293 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002294 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002295 SetSamplerParameteri(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002296 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002297}
Jamie Madille29d1672013-07-19 16:36:57 -04002298
Geoff Langc1984ed2016-10-07 12:41:00 -04002299void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2300{
2301 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002302 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002303 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002304 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002305}
2306
2307void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2308{
Geoff Langc1984ed2016-10-07 12:41:00 -04002309 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002310 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002311 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002312 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002313}
2314
Geoff Langc1984ed2016-10-07 12:41:00 -04002315void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002316{
Geoff Langc1984ed2016-10-07 12:41:00 -04002317 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002318 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002319 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002320 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002321}
2322
Geoff Langc1984ed2016-10-07 12:41:00 -04002323void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002324{
Geoff Langc1984ed2016-10-07 12:41:00 -04002325 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002326 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002327 QuerySamplerParameteriv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002328 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002329}
Jamie Madill9675b802013-07-19 16:36:59 -04002330
Geoff Langc1984ed2016-10-07 12:41:00 -04002331void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2332{
2333 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002334 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002335 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002336 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002337}
2338
Olli Etuahof0fee072016-03-30 15:11:58 +03002339void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2340{
2341 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002342 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002343}
2344
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002345void Context::initRendererString()
2346{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002347 std::ostringstream rendererString;
2348 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002349 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002350 rendererString << ")";
2351
Geoff Langcec35902014-04-16 10:52:36 -04002352 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002353}
2354
Geoff Langc339c4e2016-11-29 10:37:36 -05002355void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002356{
Geoff Langc339c4e2016-11-29 10:37:36 -05002357 const Version &clientVersion = getClientVersion();
2358
2359 std::ostringstream versionString;
2360 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2361 << ANGLE_VERSION_STRING << ")";
2362 mVersionString = MakeStaticString(versionString.str());
2363
2364 std::ostringstream shadingLanguageVersionString;
2365 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2366 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2367 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2368 << ")";
2369 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002370}
2371
Geoff Langcec35902014-04-16 10:52:36 -04002372void Context::initExtensionStrings()
2373{
Geoff Langc339c4e2016-11-29 10:37:36 -05002374 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2375 std::ostringstream combinedStringStream;
2376 std::copy(strings.begin(), strings.end(),
2377 std::ostream_iterator<const char *>(combinedStringStream, " "));
2378 return MakeStaticString(combinedStringStream.str());
2379 };
2380
2381 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002382 for (const auto &extensionString : mExtensions.getStrings())
2383 {
2384 mExtensionStrings.push_back(MakeStaticString(extensionString));
2385 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002386 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002387
Bryan Bernhart58806562017-01-05 13:09:31 -08002388 const gl::Extensions &nativeExtensions = mImplementation->getNativeExtensions();
2389
Geoff Langc339c4e2016-11-29 10:37:36 -05002390 mRequestableExtensionStrings.clear();
2391 for (const auto &extensionInfo : GetExtensionInfoMap())
2392 {
2393 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08002394 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
2395 nativeExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002396 {
2397 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
2398 }
2399 }
2400 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002401}
2402
Geoff Langc339c4e2016-11-29 10:37:36 -05002403const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04002404{
Geoff Langc339c4e2016-11-29 10:37:36 -05002405 switch (name)
2406 {
2407 case GL_VENDOR:
2408 return reinterpret_cast<const GLubyte *>("Google Inc.");
2409
2410 case GL_RENDERER:
2411 return reinterpret_cast<const GLubyte *>(mRendererString);
2412
2413 case GL_VERSION:
2414 return reinterpret_cast<const GLubyte *>(mVersionString);
2415
2416 case GL_SHADING_LANGUAGE_VERSION:
2417 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
2418
2419 case GL_EXTENSIONS:
2420 return reinterpret_cast<const GLubyte *>(mExtensionString);
2421
2422 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2423 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
2424
2425 default:
2426 UNREACHABLE();
2427 return nullptr;
2428 }
Geoff Langcec35902014-04-16 10:52:36 -04002429}
2430
Geoff Langc339c4e2016-11-29 10:37:36 -05002431const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04002432{
Geoff Langc339c4e2016-11-29 10:37:36 -05002433 switch (name)
2434 {
2435 case GL_EXTENSIONS:
2436 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
2437
2438 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2439 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
2440
2441 default:
2442 UNREACHABLE();
2443 return nullptr;
2444 }
Geoff Langcec35902014-04-16 10:52:36 -04002445}
2446
2447size_t Context::getExtensionStringCount() const
2448{
2449 return mExtensionStrings.size();
2450}
2451
Geoff Lang111a99e2017-10-17 10:58:41 -04002452bool Context::isExtensionRequestable(const char *name)
2453{
2454 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2455 auto extension = extensionInfos.find(name);
2456
2457 const Extensions &nativeExtensions = mImplementation->getNativeExtensions();
2458 return extension != extensionInfos.end() && extension->second.Requestable &&
2459 nativeExtensions.*(extension->second.ExtensionsMember);
2460}
2461
Geoff Langc339c4e2016-11-29 10:37:36 -05002462void Context::requestExtension(const char *name)
2463{
2464 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2465 ASSERT(extensionInfos.find(name) != extensionInfos.end());
2466 const auto &extension = extensionInfos.at(name);
2467 ASSERT(extension.Requestable);
Geoff Lang111a99e2017-10-17 10:58:41 -04002468 ASSERT(mImplementation->getNativeExtensions().*(extension.ExtensionsMember));
Geoff Langc339c4e2016-11-29 10:37:36 -05002469
2470 if (mExtensions.*(extension.ExtensionsMember))
2471 {
2472 // Extension already enabled
2473 return;
2474 }
2475
2476 mExtensions.*(extension.ExtensionsMember) = true;
2477 updateCaps();
2478 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08002479
Jamie Madill2f348d22017-06-05 10:50:59 -04002480 // Release the shader compiler so it will be re-created with the requested extensions enabled.
2481 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04002482
Jamie Madill81c2e252017-09-09 23:32:46 -04002483 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
2484 // sampleable.
2485 mState.mTextures->signalAllTexturesDirty();
Geoff Lang9aded172017-04-05 11:07:56 -04002486 for (auto &zeroTexture : mZeroTextures)
2487 {
Jamie Madill05b35b22017-10-03 09:01:44 -04002488 zeroTexture.second->signalDirty(InitState::Initialized);
Geoff Lang9aded172017-04-05 11:07:56 -04002489 }
2490
2491 mState.mFramebuffers->invalidateFramebufferComplenessCache();
Geoff Langc339c4e2016-11-29 10:37:36 -05002492}
2493
2494size_t Context::getRequestableExtensionStringCount() const
2495{
2496 return mRequestableExtensionStrings.size();
2497}
2498
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002499void Context::beginTransformFeedback(GLenum primitiveMode)
2500{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002501 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002502 ASSERT(transformFeedback != nullptr);
2503 ASSERT(!transformFeedback->isPaused());
2504
Jamie Madill6c1f6712017-02-14 19:08:04 -05002505 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002506}
2507
2508bool Context::hasActiveTransformFeedback(GLuint program) const
2509{
2510 for (auto pair : mTransformFeedbackMap)
2511 {
2512 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
2513 {
2514 return true;
2515 }
2516 }
2517 return false;
2518}
2519
Geoff Langb433e872017-10-05 14:01:47 -04002520void Context::initCaps(const egl::DisplayExtensions &displayExtensions, bool robustResourceInit)
Geoff Lang493daf52014-07-03 13:38:44 -04002521{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002522 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04002523
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002524 mExtensions = mImplementation->getNativeExtensions();
Geoff Lang493daf52014-07-03 13:38:44 -04002525
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002526 mLimitations = mImplementation->getNativeLimitations();
Austin Kinross02df7962015-07-01 10:03:42 -07002527
Geoff Langeb66a6e2016-10-31 13:06:12 -04002528 if (getClientVersion() < Version(3, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002529 {
2530 // Disable ES3+ extensions
Jamie Madill231c7f52017-04-26 13:45:37 -04002531 mExtensions.colorBufferFloat = false;
Geoff Langb66a9092016-05-16 15:59:14 -04002532 mExtensions.eglImageExternalEssl3 = false;
Vincent Lang25ab4512016-05-13 18:13:59 +02002533 mExtensions.textureNorm16 = false;
Martin Radev137032d2017-07-13 10:11:12 +03002534 mExtensions.multiview = false;
2535 mExtensions.maxViews = 1u;
Geoff Lang493daf52014-07-03 13:38:44 -04002536 }
2537
Jiawei Shao89be29a2017-11-06 14:36:45 +08002538 if (getClientVersion() < ES_3_1)
2539 {
2540 // Disable ES3.1+ extensions
2541 mExtensions.geometryShader = false;
2542 }
2543
Geoff Langeb66a6e2016-10-31 13:06:12 -04002544 if (getClientVersion() > Version(2, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002545 {
2546 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
Jamie Madill231c7f52017-04-26 13:45:37 -04002547 // mExtensions.sRGB = false;
Geoff Lang493daf52014-07-03 13:38:44 -04002548 }
2549
Jamie Madill00ed7a12016-05-19 13:13:38 -04002550 // Some extensions are always available because they are implemented in the GL layer.
Jamie Madill231c7f52017-04-26 13:45:37 -04002551 mExtensions.bindUniformLocation = true;
2552 mExtensions.vertexArrayObject = true;
Geoff Langf41a7152016-09-19 15:11:17 -04002553 mExtensions.bindGeneratesResource = true;
Geoff Langfeb8c682017-02-13 16:07:35 -05002554 mExtensions.clientArrays = true;
Geoff Langc339c4e2016-11-29 10:37:36 -05002555 mExtensions.requestExtension = true;
Jamie Madill00ed7a12016-05-19 13:13:38 -04002556
2557 // Enable the no error extension if the context was created with the flag.
2558 mExtensions.noError = mSkipValidation;
2559
Corentin Wallezccab69d2017-01-27 16:57:15 -05002560 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Corentin Wallezc295e512017-01-27 17:47:50 -05002561 mExtensions.surfacelessContext = displayExtensions.surfacelessContext;
Corentin Wallezccab69d2017-01-27 16:57:15 -05002562
Geoff Lang70d0f492015-12-10 17:45:46 -05002563 // Explicitly enable GL_KHR_debug
2564 mExtensions.debug = true;
2565 mExtensions.maxDebugMessageLength = 1024;
2566 mExtensions.maxDebugLoggedMessages = 1024;
2567 mExtensions.maxDebugGroupStackDepth = 1024;
2568 mExtensions.maxLabelLength = 1024;
2569
Geoff Langff5b2d52016-09-07 11:32:23 -04002570 // Explicitly enable GL_ANGLE_robust_client_memory
2571 mExtensions.robustClientMemory = true;
2572
Jamie Madille08a1d32017-03-07 17:24:06 -05002573 // Determine robust resource init availability from EGL.
Geoff Langb433e872017-10-05 14:01:47 -04002574 mExtensions.robustResourceInitialization = robustResourceInit;
Jamie Madille08a1d32017-03-07 17:24:06 -05002575
Jiajia Qin8a7b3a02017-08-25 16:05:48 +08002576 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
2577 // supports it.
2578 mExtensions.robustBufferAccessBehavior =
2579 mRobustAccess && mExtensions.robustBufferAccessBehavior;
2580
Jamie Madillc43be722017-07-13 16:22:14 -04002581 // Enable the cache control query unconditionally.
2582 mExtensions.programCacheControl = true;
2583
Geoff Lang301d1612014-07-09 10:34:37 -04002584 // Apply implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04002585 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002586
Jamie Madill0f80ed82017-09-19 00:24:56 -04002587 if (getClientVersion() < ES_3_1)
2588 {
2589 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
2590 }
2591 else
2592 {
2593 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
2594 }
Geoff Lang301d1612014-07-09 10:34:37 -04002595
Jamie Madill0f80ed82017-09-19 00:24:56 -04002596 LimitCap(&mCaps.maxVertexUniformBlocks, IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
2597 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
2598 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
2599
2600 // Limit textures as well, so we can use fast bitsets with texture bindings.
2601 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
2602 LimitCap(&mCaps.maxVertexTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
2603 LimitCap(&mCaps.maxTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04002604
Jiawei Shaodb342272017-09-27 10:21:45 +08002605 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
2606
Geoff Langc287ea62016-09-16 14:46:51 -04002607 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002608 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04002609 for (const auto &extensionInfo : GetExtensionInfoMap())
2610 {
2611 // If this context is for WebGL, disable all enableable extensions
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002612 if (mWebGLContext && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04002613 {
2614 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
2615 }
2616 }
2617
2618 // Generate texture caps
2619 updateCaps();
2620}
2621
2622void Context::updateCaps()
2623{
Geoff Lang900013c2014-07-07 11:32:19 -04002624 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002625 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04002626
Jamie Madill7b62cf92017-11-02 15:20:49 -04002627 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04002628 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04002629 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04002630 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04002631
Geoff Lang0d8b7242015-09-09 14:56:53 -04002632 // Update the format caps based on the client version and extensions.
2633 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
2634 // ES3.
2635 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002636 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002637 formatCaps.renderable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002638 formatCaps.renderable && formatInfo.renderSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002639 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002640 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04002641
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002642 // OpenGL ES does not support multisampling with non-rendererable formats
2643 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Olli Etuaho50c562d2017-06-06 14:43:30 +03002644 if (!formatCaps.renderable ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002645 (getClientVersion() < ES_3_1 &&
2646 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04002647 {
Geoff Langd87878e2014-09-19 15:42:59 -04002648 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04002649 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03002650 else
2651 {
2652 // We may have limited the max samples for some required renderbuffer formats due to
2653 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
2654 GLuint formatMaxSamples = formatCaps.getMaxSamples();
2655
2656 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
2657 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
2658 // exception of signed and unsigned integer formats."
2659 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
2660 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
2661 {
2662 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
2663 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
2664 }
2665
2666 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
2667 if (getClientVersion() >= ES_3_1)
2668 {
2669 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
2670 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
2671 // the exception that the signed and unsigned integer formats are required only to
2672 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
2673 // multisamples, which must be at least one."
2674 if (formatInfo.componentType == GL_INT ||
2675 formatInfo.componentType == GL_UNSIGNED_INT)
2676 {
2677 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
2678 }
2679
2680 // GLES 3.1 section 19.3.1.
2681 if (formatCaps.texturable)
2682 {
2683 if (formatInfo.depthBits > 0)
2684 {
2685 mCaps.maxDepthTextureSamples =
2686 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
2687 }
2688 else if (formatInfo.redBits > 0)
2689 {
2690 mCaps.maxColorTextureSamples =
2691 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
2692 }
2693 }
2694 }
2695 }
Geoff Langd87878e2014-09-19 15:42:59 -04002696
2697 if (formatCaps.texturable && formatInfo.compressed)
2698 {
Geoff Langca271392017-04-05 12:30:00 -04002699 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04002700 }
2701
Geoff Langca271392017-04-05 12:30:00 -04002702 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04002703 }
Jamie Madill32447362017-06-28 14:53:52 -04002704
2705 // If program binary is disabled, blank out the memory cache pointer.
2706 if (!mImplementation->getNativeExtensions().getProgramBinary)
2707 {
2708 mMemoryProgramCache = nullptr;
2709 }
Geoff Lang493daf52014-07-03 13:38:44 -04002710}
2711
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002712void Context::initWorkarounds()
2713{
Jamie Madill761b02c2017-06-23 16:27:06 -04002714 // Apply back-end workarounds.
2715 mImplementation->applyNativeWorkarounds(&mWorkarounds);
2716
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002717 // Lose the context upon out of memory error if the application is
2718 // expecting to watch for those events.
2719 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2720}
2721
Jamie Madill05b35b22017-10-03 09:01:44 -04002722Error Context::prepareForDraw()
2723{
2724 syncRendererState();
Jamie Madilla59fc192017-11-02 12:57:58 -04002725
2726 if (isRobustResourceInitEnabled())
2727 {
2728 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
2729 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
2730 }
2731
Jamie Madill05b35b22017-10-03 09:01:44 -04002732 return NoError();
2733}
2734
Jamie Madill1b94d432015-08-07 13:23:23 -04002735void Context::syncRendererState()
2736{
Jamie Madill7d1f5c62017-09-02 15:32:15 -04002737 mGLState.syncDirtyObjects(this);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002738 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
Jamie Madillfe548342017-06-19 11:13:24 -04002739 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002740 mGLState.clearDirtyBits();
Jamie Madill1b94d432015-08-07 13:23:23 -04002741}
2742
Jamie Madillad9f24e2016-02-12 09:27:24 -05002743void Context::syncRendererState(const State::DirtyBits &bitMask,
2744 const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04002745{
Jamie Madill7d1f5c62017-09-02 15:32:15 -04002746 mGLState.syncDirtyObjects(this, objectMask);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002747 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madillfe548342017-06-19 11:13:24 -04002748 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002749 mGLState.clearDirtyBits(dirtyBits);
Jamie Madill1b94d432015-08-07 13:23:23 -04002750}
Jamie Madillc29968b2016-01-20 11:17:23 -05002751
2752void Context::blitFramebuffer(GLint srcX0,
2753 GLint srcY0,
2754 GLint srcX1,
2755 GLint srcY1,
2756 GLint dstX0,
2757 GLint dstY0,
2758 GLint dstX1,
2759 GLint dstY1,
2760 GLbitfield mask,
2761 GLenum filter)
2762{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002763 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002764 ASSERT(drawFramebuffer);
2765
2766 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
2767 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
2768
Jamie Madillad9f24e2016-02-12 09:27:24 -05002769 syncStateForBlit();
Jamie Madillc29968b2016-01-20 11:17:23 -05002770
Jamie Madillc564c072017-06-01 12:45:42 -04002771 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002772}
Jamie Madillc29968b2016-01-20 11:17:23 -05002773
2774void Context::clear(GLbitfield mask)
2775{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002776 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002777 handleError(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05002778}
2779
2780void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
2781{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002782 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002783 handleError(mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002784}
2785
2786void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
2787{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002788 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002789 handleError(mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002790}
2791
2792void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
2793{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002794 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002795 handleError(mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002796}
2797
2798void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
2799{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002800 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002801 ASSERT(framebufferObject);
2802
2803 // If a buffer is not present, the clear has no effect
2804 if (framebufferObject->getDepthbuffer() == nullptr &&
2805 framebufferObject->getStencilbuffer() == nullptr)
2806 {
2807 return;
2808 }
2809
Jamie Madillad9f24e2016-02-12 09:27:24 -05002810 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002811 handleError(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05002812}
2813
2814void Context::readPixels(GLint x,
2815 GLint y,
2816 GLsizei width,
2817 GLsizei height,
2818 GLenum format,
2819 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002820 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05002821{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04002822 if (width == 0 || height == 0)
2823 {
2824 return;
2825 }
2826
Jamie Madillad9f24e2016-02-12 09:27:24 -05002827 syncStateForReadPixels();
Jamie Madillc29968b2016-01-20 11:17:23 -05002828
Jamie Madillb6664922017-07-25 12:55:04 -04002829 Framebuffer *readFBO = mGLState.getReadFramebuffer();
2830 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05002831
2832 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04002833 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05002834}
2835
2836void Context::copyTexImage2D(GLenum target,
2837 GLint level,
2838 GLenum internalformat,
2839 GLint x,
2840 GLint y,
2841 GLsizei width,
2842 GLsizei height,
2843 GLint border)
2844{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002845 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002846 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002847
Jamie Madillc29968b2016-01-20 11:17:23 -05002848 Rectangle sourceArea(x, y, width, height);
2849
Jamie Madill05b35b22017-10-03 09:01:44 -04002850 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002851 Texture *texture =
2852 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05002853 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05002854}
2855
2856void Context::copyTexSubImage2D(GLenum target,
2857 GLint level,
2858 GLint xoffset,
2859 GLint yoffset,
2860 GLint x,
2861 GLint y,
2862 GLsizei width,
2863 GLsizei height)
2864{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04002865 if (width == 0 || height == 0)
2866 {
2867 return;
2868 }
2869
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002870 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002871 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002872
Jamie Madillc29968b2016-01-20 11:17:23 -05002873 Offset destOffset(xoffset, yoffset, 0);
2874 Rectangle sourceArea(x, y, width, height);
2875
Jamie Madill05b35b22017-10-03 09:01:44 -04002876 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002877 Texture *texture =
2878 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05002879 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05002880}
2881
2882void Context::copyTexSubImage3D(GLenum target,
2883 GLint level,
2884 GLint xoffset,
2885 GLint yoffset,
2886 GLint zoffset,
2887 GLint x,
2888 GLint y,
2889 GLsizei width,
2890 GLsizei height)
2891{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04002892 if (width == 0 || height == 0)
2893 {
2894 return;
2895 }
2896
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002897 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002898 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002899
Jamie Madillc29968b2016-01-20 11:17:23 -05002900 Offset destOffset(xoffset, yoffset, zoffset);
2901 Rectangle sourceArea(x, y, width, height);
2902
Jamie Madill05b35b22017-10-03 09:01:44 -04002903 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
2904 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05002905 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05002906}
2907
2908void Context::framebufferTexture2D(GLenum target,
2909 GLenum attachment,
2910 GLenum textarget,
2911 GLuint texture,
2912 GLint level)
2913{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002914 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05002915 ASSERT(framebuffer);
2916
2917 if (texture != 0)
2918 {
2919 Texture *textureObj = getTexture(texture);
2920
2921 ImageIndex index = ImageIndex::MakeInvalid();
2922
2923 if (textarget == GL_TEXTURE_2D)
2924 {
2925 index = ImageIndex::Make2D(level);
2926 }
Corentin Wallez13c0dd42017-07-04 18:27:01 -04002927 else if (textarget == GL_TEXTURE_RECTANGLE_ANGLE)
2928 {
2929 index = ImageIndex::MakeRectangle(level);
2930 }
JiangYizhoubddc46b2016-12-09 09:50:51 +08002931 else if (textarget == GL_TEXTURE_2D_MULTISAMPLE)
2932 {
2933 ASSERT(level == 0);
2934 index = ImageIndex::Make2DMultisample();
2935 }
Jamie Madillc29968b2016-01-20 11:17:23 -05002936 else
2937 {
2938 ASSERT(IsCubeMapTextureTarget(textarget));
2939 index = ImageIndex::MakeCube(textarget, level);
2940 }
2941
Jamie Madilla02315b2017-02-23 14:14:47 -05002942 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05002943 }
2944 else
2945 {
Jamie Madilla02315b2017-02-23 14:14:47 -05002946 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05002947 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002948
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002949 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05002950}
2951
2952void Context::framebufferRenderbuffer(GLenum target,
2953 GLenum attachment,
2954 GLenum renderbuffertarget,
2955 GLuint renderbuffer)
2956{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002957 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05002958 ASSERT(framebuffer);
2959
2960 if (renderbuffer != 0)
2961 {
2962 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05002963
2964 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex::MakeInvalid(),
Jamie Madillc29968b2016-01-20 11:17:23 -05002965 renderbufferObject);
2966 }
2967 else
2968 {
Jamie Madilla02315b2017-02-23 14:14:47 -05002969 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05002970 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002971
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002972 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05002973}
2974
2975void Context::framebufferTextureLayer(GLenum target,
2976 GLenum attachment,
2977 GLuint texture,
2978 GLint level,
2979 GLint layer)
2980{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002981 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05002982 ASSERT(framebuffer);
2983
2984 if (texture != 0)
2985 {
2986 Texture *textureObject = getTexture(texture);
2987
2988 ImageIndex index = ImageIndex::MakeInvalid();
2989
2990 if (textureObject->getTarget() == GL_TEXTURE_3D)
2991 {
2992 index = ImageIndex::Make3D(level, layer);
2993 }
2994 else
2995 {
2996 ASSERT(textureObject->getTarget() == GL_TEXTURE_2D_ARRAY);
2997 index = ImageIndex::Make2DArray(level, layer);
2998 }
2999
Jamie Madilla02315b2017-02-23 14:14:47 -05003000 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003001 }
3002 else
3003 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003004 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003005 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003006
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003007 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003008}
3009
Martin Radev137032d2017-07-13 10:11:12 +03003010void Context::framebufferTextureMultiviewLayeredANGLE(GLenum target,
3011 GLenum attachment,
3012 GLuint texture,
3013 GLint level,
3014 GLint baseViewIndex,
3015 GLsizei numViews)
3016{
Martin Radev82ef7742017-08-08 17:44:58 +03003017 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3018 ASSERT(framebuffer);
3019
3020 if (texture != 0)
3021 {
3022 Texture *textureObj = getTexture(texture);
3023
Martin Radev18b75ba2017-08-15 15:50:40 +03003024 ImageIndex index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
Martin Radev82ef7742017-08-08 17:44:58 +03003025 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3026 numViews, baseViewIndex);
3027 }
3028 else
3029 {
3030 framebuffer->resetAttachment(this, attachment);
3031 }
3032
3033 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003034}
3035
3036void Context::framebufferTextureMultiviewSideBySideANGLE(GLenum target,
3037 GLenum attachment,
3038 GLuint texture,
3039 GLint level,
3040 GLsizei numViews,
3041 const GLint *viewportOffsets)
3042{
Martin Radev5dae57b2017-07-14 16:15:55 +03003043 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3044 ASSERT(framebuffer);
3045
3046 if (texture != 0)
3047 {
3048 Texture *textureObj = getTexture(texture);
3049
3050 ImageIndex index = ImageIndex::Make2D(level);
3051 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3052 textureObj, numViews, viewportOffsets);
3053 }
3054 else
3055 {
3056 framebuffer->resetAttachment(this, attachment);
3057 }
3058
3059 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003060}
3061
Jamie Madillc29968b2016-01-20 11:17:23 -05003062void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3063{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003064 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003065 ASSERT(framebuffer);
3066 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003067 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003068}
3069
3070void Context::readBuffer(GLenum mode)
3071{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003072 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003073 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003074 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003075}
3076
3077void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3078{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003079 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003080 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003081
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003082 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003083 ASSERT(framebuffer);
3084
3085 // The specification isn't clear what should be done when the framebuffer isn't complete.
3086 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003087 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003088}
3089
3090void Context::invalidateFramebuffer(GLenum target,
3091 GLsizei numAttachments,
3092 const GLenum *attachments)
3093{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003094 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003095 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003096
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003097 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003098 ASSERT(framebuffer);
3099
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003100 if (framebuffer->checkStatus(this) != GL_FRAMEBUFFER_COMPLETE)
Jamie Madillc29968b2016-01-20 11:17:23 -05003101 {
Jamie Madill437fa652016-05-03 15:13:24 -04003102 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003103 }
Jamie Madill437fa652016-05-03 15:13:24 -04003104
Jamie Madill4928b7c2017-06-20 12:57:39 -04003105 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003106}
3107
3108void Context::invalidateSubFramebuffer(GLenum target,
3109 GLsizei numAttachments,
3110 const GLenum *attachments,
3111 GLint x,
3112 GLint y,
3113 GLsizei width,
3114 GLsizei height)
3115{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003116 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003117 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003118
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003119 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003120 ASSERT(framebuffer);
3121
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003122 if (framebuffer->checkStatus(this) != GL_FRAMEBUFFER_COMPLETE)
Jamie Madillc29968b2016-01-20 11:17:23 -05003123 {
Jamie Madill437fa652016-05-03 15:13:24 -04003124 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003125 }
Jamie Madill437fa652016-05-03 15:13:24 -04003126
3127 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003128 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003129}
3130
Jamie Madill73a84962016-02-12 09:27:23 -05003131void Context::texImage2D(GLenum target,
3132 GLint level,
3133 GLint internalformat,
3134 GLsizei width,
3135 GLsizei height,
3136 GLint border,
3137 GLenum format,
3138 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003139 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003140{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003141 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003142
3143 Extents size(width, height, 1);
3144 Texture *texture =
3145 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003146 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3147 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003148}
3149
3150void Context::texImage3D(GLenum target,
3151 GLint level,
3152 GLint internalformat,
3153 GLsizei width,
3154 GLsizei height,
3155 GLsizei depth,
3156 GLint border,
3157 GLenum format,
3158 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003159 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003160{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003161 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003162
3163 Extents size(width, height, depth);
3164 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003165 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3166 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003167}
3168
3169void Context::texSubImage2D(GLenum target,
3170 GLint level,
3171 GLint xoffset,
3172 GLint yoffset,
3173 GLsizei width,
3174 GLsizei height,
3175 GLenum format,
3176 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003177 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003178{
3179 // Zero sized uploads are valid but no-ops
3180 if (width == 0 || height == 0)
3181 {
3182 return;
3183 }
3184
Jamie Madillad9f24e2016-02-12 09:27:24 -05003185 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003186
3187 Box area(xoffset, yoffset, 0, width, height, 1);
3188 Texture *texture =
3189 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003190 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3191 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003192}
3193
3194void Context::texSubImage3D(GLenum target,
3195 GLint level,
3196 GLint xoffset,
3197 GLint yoffset,
3198 GLint zoffset,
3199 GLsizei width,
3200 GLsizei height,
3201 GLsizei depth,
3202 GLenum format,
3203 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003204 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003205{
3206 // Zero sized uploads are valid but no-ops
3207 if (width == 0 || height == 0 || depth == 0)
3208 {
3209 return;
3210 }
3211
Jamie Madillad9f24e2016-02-12 09:27:24 -05003212 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003213
3214 Box area(xoffset, yoffset, zoffset, width, height, depth);
3215 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003216 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3217 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003218}
3219
3220void Context::compressedTexImage2D(GLenum target,
3221 GLint level,
3222 GLenum internalformat,
3223 GLsizei width,
3224 GLsizei height,
3225 GLint border,
3226 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003227 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003228{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003229 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003230
3231 Extents size(width, height, 1);
3232 Texture *texture =
3233 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003234 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003235 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003236 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003237}
3238
3239void Context::compressedTexImage3D(GLenum target,
3240 GLint level,
3241 GLenum internalformat,
3242 GLsizei width,
3243 GLsizei height,
3244 GLsizei depth,
3245 GLint border,
3246 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003247 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003248{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003249 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003250
3251 Extents size(width, height, depth);
3252 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003253 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003254 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003255 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003256}
3257
3258void Context::compressedTexSubImage2D(GLenum target,
3259 GLint level,
3260 GLint xoffset,
3261 GLint yoffset,
3262 GLsizei width,
3263 GLsizei height,
3264 GLenum format,
3265 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003266 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003267{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003268 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003269
3270 Box area(xoffset, yoffset, 0, width, height, 1);
3271 Texture *texture =
3272 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003273 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003274 format, imageSize,
3275 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003276}
3277
3278void Context::compressedTexSubImage3D(GLenum target,
3279 GLint level,
3280 GLint xoffset,
3281 GLint yoffset,
3282 GLint zoffset,
3283 GLsizei width,
3284 GLsizei height,
3285 GLsizei depth,
3286 GLenum format,
3287 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003288 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003289{
3290 // Zero sized uploads are valid but no-ops
3291 if (width == 0 || height == 0)
3292 {
3293 return;
3294 }
3295
Jamie Madillad9f24e2016-02-12 09:27:24 -05003296 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003297
3298 Box area(xoffset, yoffset, zoffset, width, height, depth);
3299 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003300 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003301 format, imageSize,
3302 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003303}
3304
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003305void Context::generateMipmap(GLenum target)
3306{
3307 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003308 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003309}
3310
Geoff Lang97073d12016-04-20 10:42:34 -07003311void Context::copyTextureCHROMIUM(GLuint sourceId,
Geoff Langfc72a072017-03-24 14:52:39 -04003312 GLint sourceLevel,
3313 GLenum destTarget,
Geoff Lang97073d12016-04-20 10:42:34 -07003314 GLuint destId,
Geoff Langfc72a072017-03-24 14:52:39 -04003315 GLint destLevel,
Geoff Lang97073d12016-04-20 10:42:34 -07003316 GLint internalFormat,
3317 GLenum destType,
3318 GLboolean unpackFlipY,
3319 GLboolean unpackPremultiplyAlpha,
3320 GLboolean unpackUnmultiplyAlpha)
3321{
3322 syncStateForTexImage();
3323
3324 gl::Texture *sourceTexture = getTexture(sourceId);
3325 gl::Texture *destTexture = getTexture(destId);
Geoff Lang92019432017-11-20 13:09:34 -05003326 handleError(destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType,
3327 sourceLevel, ConvertToBool(unpackFlipY),
3328 ConvertToBool(unpackPremultiplyAlpha),
3329 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003330}
3331
3332void Context::copySubTextureCHROMIUM(GLuint sourceId,
Geoff Langfc72a072017-03-24 14:52:39 -04003333 GLint sourceLevel,
3334 GLenum destTarget,
Geoff Lang97073d12016-04-20 10:42:34 -07003335 GLuint destId,
Geoff Langfc72a072017-03-24 14:52:39 -04003336 GLint destLevel,
Geoff Lang97073d12016-04-20 10:42:34 -07003337 GLint xoffset,
3338 GLint yoffset,
3339 GLint x,
3340 GLint y,
3341 GLsizei width,
3342 GLsizei height,
3343 GLboolean unpackFlipY,
3344 GLboolean unpackPremultiplyAlpha,
3345 GLboolean unpackUnmultiplyAlpha)
3346{
3347 // Zero sized copies are valid but no-ops
3348 if (width == 0 || height == 0)
3349 {
3350 return;
3351 }
3352
3353 syncStateForTexImage();
3354
3355 gl::Texture *sourceTexture = getTexture(sourceId);
3356 gl::Texture *destTexture = getTexture(destId);
3357 Offset offset(xoffset, yoffset, 0);
3358 Rectangle area(x, y, width, height);
Geoff Lang92019432017-11-20 13:09:34 -05003359 handleError(destTexture->copySubTexture(this, destTarget, destLevel, offset, sourceLevel, area,
3360 ConvertToBool(unpackFlipY),
3361 ConvertToBool(unpackPremultiplyAlpha),
3362 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003363}
3364
Geoff Lang47110bf2016-04-20 11:13:22 -07003365void Context::compressedCopyTextureCHROMIUM(GLuint sourceId, GLuint destId)
3366{
3367 syncStateForTexImage();
3368
3369 gl::Texture *sourceTexture = getTexture(sourceId);
3370 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05003371 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07003372}
3373
Corentin Wallez336129f2017-10-17 15:55:40 -04003374void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03003375{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003376 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003377 ASSERT(buffer);
3378
Geoff Lang496c02d2016-10-20 11:38:11 -07003379 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03003380}
3381
Corentin Wallez336129f2017-10-17 15:55:40 -04003382void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003383{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003384 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003385 ASSERT(buffer);
3386
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003387 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003388 if (error.isError())
3389 {
Jamie Madill437fa652016-05-03 15:13:24 -04003390 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003391 return nullptr;
3392 }
3393
3394 return buffer->getMapPointer();
3395}
3396
Corentin Wallez336129f2017-10-17 15:55:40 -04003397GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03003398{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003399 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003400 ASSERT(buffer);
3401
3402 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003403 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03003404 if (error.isError())
3405 {
Jamie Madill437fa652016-05-03 15:13:24 -04003406 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003407 return GL_FALSE;
3408 }
3409
3410 return result;
3411}
3412
Corentin Wallez336129f2017-10-17 15:55:40 -04003413void *Context::mapBufferRange(BufferBinding target,
3414 GLintptr offset,
3415 GLsizeiptr length,
3416 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003417{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003418 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003419 ASSERT(buffer);
3420
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003421 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003422 if (error.isError())
3423 {
Jamie Madill437fa652016-05-03 15:13:24 -04003424 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003425 return nullptr;
3426 }
3427
3428 return buffer->getMapPointer();
3429}
3430
Corentin Wallez336129f2017-10-17 15:55:40 -04003431void Context::flushMappedBufferRange(BufferBinding /*target*/,
3432 GLintptr /*offset*/,
3433 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03003434{
3435 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
3436}
3437
Jamie Madillad9f24e2016-02-12 09:27:24 -05003438void Context::syncStateForReadPixels()
3439{
3440 syncRendererState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
3441}
3442
3443void Context::syncStateForTexImage()
3444{
3445 syncRendererState(mTexImageDirtyBits, mTexImageDirtyObjects);
3446}
3447
3448void Context::syncStateForClear()
3449{
3450 syncRendererState(mClearDirtyBits, mClearDirtyObjects);
3451}
3452
3453void Context::syncStateForBlit()
3454{
3455 syncRendererState(mBlitDirtyBits, mBlitDirtyObjects);
3456}
3457
Jamie Madillc20ab272016-06-09 07:20:46 -07003458void Context::activeTexture(GLenum texture)
3459{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003460 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003461}
3462
Jamie Madill876429b2017-04-20 15:46:24 -04003463void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003464{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003465 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07003466}
3467
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003468void Context::blendEquation(GLenum mode)
3469{
3470 mGLState.setBlendEquation(mode, mode);
3471}
3472
Jamie Madillc20ab272016-06-09 07:20:46 -07003473void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
3474{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003475 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003476}
3477
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003478void Context::blendFunc(GLenum sfactor, GLenum dfactor)
3479{
3480 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
3481}
3482
Jamie Madillc20ab272016-06-09 07:20:46 -07003483void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
3484{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003485 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003486}
3487
Jamie Madill876429b2017-04-20 15:46:24 -04003488void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003489{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003490 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003491}
3492
Jamie Madill876429b2017-04-20 15:46:24 -04003493void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07003494{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003495 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07003496}
3497
3498void Context::clearStencil(GLint s)
3499{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003500 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07003501}
3502
3503void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
3504{
Geoff Lang92019432017-11-20 13:09:34 -05003505 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
3506 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07003507}
3508
Corentin Wallez2e568cf2017-09-18 17:05:22 -04003509void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07003510{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003511 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003512}
3513
3514void Context::depthFunc(GLenum func)
3515{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003516 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07003517}
3518
3519void Context::depthMask(GLboolean flag)
3520{
Geoff Lang92019432017-11-20 13:09:34 -05003521 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07003522}
3523
Jamie Madill876429b2017-04-20 15:46:24 -04003524void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07003525{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003526 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07003527}
3528
3529void Context::disable(GLenum cap)
3530{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003531 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003532}
3533
3534void Context::disableVertexAttribArray(GLuint index)
3535{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003536 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003537}
3538
3539void Context::enable(GLenum cap)
3540{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003541 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003542}
3543
3544void Context::enableVertexAttribArray(GLuint index)
3545{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003546 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003547}
3548
3549void Context::frontFace(GLenum mode)
3550{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003551 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003552}
3553
3554void Context::hint(GLenum target, GLenum mode)
3555{
3556 switch (target)
3557 {
3558 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003559 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003560 break;
3561
3562 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003563 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003564 break;
3565
3566 default:
3567 UNREACHABLE();
3568 return;
3569 }
3570}
3571
3572void Context::lineWidth(GLfloat width)
3573{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003574 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07003575}
3576
3577void Context::pixelStorei(GLenum pname, GLint param)
3578{
3579 switch (pname)
3580 {
3581 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003582 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003583 break;
3584
3585 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003586 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003587 break;
3588
3589 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003590 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003591 break;
3592
3593 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003594 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003595 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003596 break;
3597
3598 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03003599 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003600 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003601 break;
3602
3603 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03003604 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003605 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003606 break;
3607
3608 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003609 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003610 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003611 break;
3612
3613 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003614 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003615 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003616 break;
3617
3618 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003619 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003620 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003621 break;
3622
3623 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003624 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003625 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003626 break;
3627
3628 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003629 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003630 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003631 break;
3632
3633 default:
3634 UNREACHABLE();
3635 return;
3636 }
3637}
3638
3639void Context::polygonOffset(GLfloat factor, GLfloat units)
3640{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003641 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07003642}
3643
Jamie Madill876429b2017-04-20 15:46:24 -04003644void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07003645{
Geoff Lang92019432017-11-20 13:09:34 -05003646 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07003647}
3648
Jiawei Shaodb342272017-09-27 10:21:45 +08003649void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
3650{
3651 mGLState.setSampleMaskParams(maskNumber, mask);
3652}
3653
Jamie Madillc20ab272016-06-09 07:20:46 -07003654void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
3655{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003656 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07003657}
3658
3659void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
3660{
3661 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3662 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003663 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003664 }
3665
3666 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3667 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003668 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003669 }
3670}
3671
3672void Context::stencilMaskSeparate(GLenum face, GLuint mask)
3673{
3674 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3675 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003676 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003677 }
3678
3679 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3680 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003681 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003682 }
3683}
3684
3685void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
3686{
3687 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3688 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003689 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003690 }
3691
3692 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3693 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003694 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003695 }
3696}
3697
3698void Context::vertexAttrib1f(GLuint index, GLfloat x)
3699{
3700 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003701 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003702}
3703
3704void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
3705{
3706 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003707 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003708}
3709
3710void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
3711{
3712 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003713 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003714}
3715
3716void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
3717{
3718 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003719 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003720}
3721
3722void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
3723{
3724 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003725 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003726}
3727
3728void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
3729{
3730 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003731 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003732}
3733
3734void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
3735{
3736 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003737 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003738}
3739
3740void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
3741{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003742 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07003743}
3744
3745void Context::vertexAttribPointer(GLuint index,
3746 GLint size,
3747 GLenum type,
3748 GLboolean normalized,
3749 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04003750 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07003751{
Corentin Wallez336129f2017-10-17 15:55:40 -04003752 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05003753 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc20ab272016-06-09 07:20:46 -07003754}
3755
Shao80957d92017-02-20 21:25:59 +08003756void Context::vertexAttribFormat(GLuint attribIndex,
3757 GLint size,
3758 GLenum type,
3759 GLboolean normalized,
3760 GLuint relativeOffset)
3761{
Geoff Lang92019432017-11-20 13:09:34 -05003762 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08003763 relativeOffset);
3764}
3765
3766void Context::vertexAttribIFormat(GLuint attribIndex,
3767 GLint size,
3768 GLenum type,
3769 GLuint relativeOffset)
3770{
3771 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
3772}
3773
3774void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
3775{
Shaodde78e82017-05-22 14:13:27 +08003776 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Shao80957d92017-02-20 21:25:59 +08003777}
3778
3779void Context::setVertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
3780{
3781 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
3782}
3783
Jamie Madillc20ab272016-06-09 07:20:46 -07003784void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
3785{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003786 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07003787}
3788
3789void Context::vertexAttribIPointer(GLuint index,
3790 GLint size,
3791 GLenum type,
3792 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04003793 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07003794{
Corentin Wallez336129f2017-10-17 15:55:40 -04003795 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
3796 size, type, false, true, stride, pointer);
Jamie Madillc20ab272016-06-09 07:20:46 -07003797}
3798
3799void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
3800{
3801 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003802 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003803}
3804
3805void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
3806{
3807 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003808 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003809}
3810
3811void Context::vertexAttribI4iv(GLuint index, const GLint *v)
3812{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003813 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07003814}
3815
3816void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
3817{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003818 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07003819}
3820
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003821void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
3822{
3823 const VertexAttribCurrentValueData &currentValues =
3824 getGLState().getVertexAttribCurrentValue(index);
3825 const VertexArray *vao = getGLState().getVertexArray();
3826 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3827 currentValues, pname, params);
3828}
3829
3830void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
3831{
3832 const VertexAttribCurrentValueData &currentValues =
3833 getGLState().getVertexAttribCurrentValue(index);
3834 const VertexArray *vao = getGLState().getVertexArray();
3835 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3836 currentValues, pname, params);
3837}
3838
3839void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
3840{
3841 const VertexAttribCurrentValueData &currentValues =
3842 getGLState().getVertexAttribCurrentValue(index);
3843 const VertexArray *vao = getGLState().getVertexArray();
3844 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3845 currentValues, pname, params);
3846}
3847
3848void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
3849{
3850 const VertexAttribCurrentValueData &currentValues =
3851 getGLState().getVertexAttribCurrentValue(index);
3852 const VertexArray *vao = getGLState().getVertexArray();
3853 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3854 currentValues, pname, params);
3855}
3856
Jamie Madill876429b2017-04-20 15:46:24 -04003857void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003858{
3859 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
3860 QueryVertexAttribPointerv(attrib, pname, pointer);
3861}
3862
Jamie Madillc20ab272016-06-09 07:20:46 -07003863void Context::debugMessageControl(GLenum source,
3864 GLenum type,
3865 GLenum severity,
3866 GLsizei count,
3867 const GLuint *ids,
3868 GLboolean enabled)
3869{
3870 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003871 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05003872 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07003873}
3874
3875void Context::debugMessageInsert(GLenum source,
3876 GLenum type,
3877 GLuint id,
3878 GLenum severity,
3879 GLsizei length,
3880 const GLchar *buf)
3881{
3882 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003883 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07003884}
3885
3886void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
3887{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003888 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07003889}
3890
3891GLuint Context::getDebugMessageLog(GLuint count,
3892 GLsizei bufSize,
3893 GLenum *sources,
3894 GLenum *types,
3895 GLuint *ids,
3896 GLenum *severities,
3897 GLsizei *lengths,
3898 GLchar *messageLog)
3899{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003900 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
3901 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07003902}
3903
3904void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
3905{
3906 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003907 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07003908}
3909
3910void Context::popDebugGroup()
3911{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003912 mGLState.getDebug().popGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07003913}
3914
Corentin Wallez336129f2017-10-17 15:55:40 -04003915void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04003916{
3917 Buffer *buffer = mGLState.getTargetBuffer(target);
3918 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08003919 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04003920}
3921
Corentin Wallez336129f2017-10-17 15:55:40 -04003922void Context::bufferSubData(BufferBinding target,
3923 GLintptr offset,
3924 GLsizeiptr size,
3925 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04003926{
3927 if (data == nullptr)
3928 {
3929 return;
3930 }
3931
3932 Buffer *buffer = mGLState.getTargetBuffer(target);
3933 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08003934 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04003935}
3936
Jamie Madillef300b12016-10-07 15:12:09 -04003937void Context::attachShader(GLuint program, GLuint shader)
3938{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05003939 auto programObject = mState.mShaderPrograms->getProgram(program);
3940 auto shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04003941 ASSERT(programObject && shaderObject);
3942 programObject->attachShader(shaderObject);
3943}
3944
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003945const Workarounds &Context::getWorkarounds() const
3946{
3947 return mWorkarounds;
3948}
3949
Corentin Wallez336129f2017-10-17 15:55:40 -04003950void Context::copyBufferSubData(BufferBinding readTarget,
3951 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04003952 GLintptr readOffset,
3953 GLintptr writeOffset,
3954 GLsizeiptr size)
3955{
3956 // if size is zero, the copy is a successful no-op
3957 if (size == 0)
3958 {
3959 return;
3960 }
3961
3962 // TODO(jmadill): cache these.
3963 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
3964 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
3965
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003966 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04003967}
3968
Jamie Madill01a80ee2016-11-07 12:06:18 -05003969void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
3970{
3971 Program *programObject = getProgram(program);
3972 // TODO(jmadill): Re-use this from the validation if possible.
3973 ASSERT(programObject);
3974 programObject->bindAttributeLocation(index, name);
3975}
3976
Corentin Wallez336129f2017-10-17 15:55:40 -04003977void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05003978{
Corentin Wallez336129f2017-10-17 15:55:40 -04003979 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
3980 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madill01a80ee2016-11-07 12:06:18 -05003981}
3982
Corentin Wallez336129f2017-10-17 15:55:40 -04003983void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08003984{
3985 bindBufferRange(target, index, buffer, 0, 0);
3986}
3987
Corentin Wallez336129f2017-10-17 15:55:40 -04003988void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08003989 GLuint index,
3990 GLuint buffer,
3991 GLintptr offset,
3992 GLsizeiptr size)
3993{
Corentin Wallez336129f2017-10-17 15:55:40 -04003994 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
3995 mGLState.setIndexedBufferBinding(this, target, index, bufferObject, offset, size);
Jiajia Qin6eafb042016-12-27 17:04:07 +08003996}
3997
Jamie Madill01a80ee2016-11-07 12:06:18 -05003998void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
3999{
4000 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4001 {
4002 bindReadFramebuffer(framebuffer);
4003 }
4004
4005 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4006 {
4007 bindDrawFramebuffer(framebuffer);
4008 }
4009}
4010
4011void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4012{
4013 ASSERT(target == GL_RENDERBUFFER);
4014 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004015 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04004016 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004017}
4018
JiangYizhoubddc46b2016-12-09 09:50:51 +08004019void Context::texStorage2DMultisample(GLenum target,
4020 GLsizei samples,
4021 GLenum internalformat,
4022 GLsizei width,
4023 GLsizei height,
4024 GLboolean fixedsamplelocations)
4025{
4026 Extents size(width, height, 1);
4027 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05004028 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
Geoff Lang92019432017-11-20 13:09:34 -05004029 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004030}
4031
4032void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4033{
JiangYizhou5b03f472017-01-09 10:22:53 +08004034 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
4035 // the sample position should be queried by DRAW_FRAMEBUFFER.
4036 mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER);
4037 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08004038
4039 switch (pname)
4040 {
4041 case GL_SAMPLE_POSITION:
4042 handleError(framebuffer->getSamplePosition(index, val));
4043 break;
4044 default:
4045 UNREACHABLE();
4046 }
4047}
4048
Jamie Madille8fb6402017-02-14 17:56:40 -05004049void Context::renderbufferStorage(GLenum target,
4050 GLenum internalformat,
4051 GLsizei width,
4052 GLsizei height)
4053{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004054 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4055 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
4056
Jamie Madille8fb6402017-02-14 17:56:40 -05004057 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04004058 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004059}
4060
4061void Context::renderbufferStorageMultisample(GLenum target,
4062 GLsizei samples,
4063 GLenum internalformat,
4064 GLsizei width,
4065 GLsizei height)
4066{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004067 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4068 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05004069
4070 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004071 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04004072 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004073}
4074
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004075void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
4076{
Jamie Madill70b5bb02017-08-28 13:32:37 -04004077 const Sync *syncObject = getSync(sync);
Geoff Lang82483b92017-04-11 15:33:00 -04004078 handleError(QuerySynciv(syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004079}
4080
JiangYizhoue18e6392017-02-20 10:32:23 +08004081void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
4082{
4083 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4084 QueryFramebufferParameteriv(framebuffer, pname, params);
4085}
4086
4087void Context::setFramebufferParameteri(GLenum target, GLenum pname, GLint param)
4088{
4089 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4090 SetFramebufferParameteri(framebuffer, pname, param);
4091}
4092
Jamie Madillb3f26b92017-07-19 15:07:41 -04004093Error Context::getScratchBuffer(size_t requstedSizeBytes,
4094 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05004095{
Jamie Madillb3f26b92017-07-19 15:07:41 -04004096 if (!mScratchBuffer.get(requstedSizeBytes, scratchBufferOut))
4097 {
4098 return OutOfMemory() << "Failed to allocate internal buffer.";
4099 }
4100 return NoError();
4101}
4102
4103Error Context::getZeroFilledBuffer(size_t requstedSizeBytes,
4104 angle::MemoryBuffer **zeroBufferOut) const
4105{
4106 if (!mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0))
Jamie Madille14951e2017-03-09 18:55:16 -05004107 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004108 return OutOfMemory() << "Failed to allocate internal buffer.";
Jamie Madille14951e2017-03-09 18:55:16 -05004109 }
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004110 return NoError();
Jamie Madille14951e2017-03-09 18:55:16 -05004111}
4112
Xinghua Cao2b396592017-03-29 15:36:04 +08004113void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
4114{
4115 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
4116 {
4117 return;
4118 }
4119
Jamie Madill05b35b22017-10-03 09:01:44 -04004120 // TODO(jmadill): Dirty bits for compute.
Jamie Madilla59fc192017-11-02 12:57:58 -04004121 if (isRobustResourceInitEnabled())
4122 {
4123 ANGLE_CONTEXT_TRY(mGLState.clearUnclearedActiveTextures(this));
4124 }
Jamie Madill05b35b22017-10-03 09:01:44 -04004125
Jamie Madill71c88b32017-09-14 22:20:29 -04004126 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08004127}
4128
JiangYizhou165361c2017-06-07 14:56:57 +08004129void Context::texStorage2D(GLenum target,
4130 GLsizei levels,
4131 GLenum internalFormat,
4132 GLsizei width,
4133 GLsizei height)
4134{
4135 Extents size(width, height, 1);
4136 Texture *texture = getTargetTexture(target);
4137 handleError(texture->setStorage(this, target, levels, internalFormat, size));
4138}
4139
4140void Context::texStorage3D(GLenum target,
4141 GLsizei levels,
4142 GLenum internalFormat,
4143 GLsizei width,
4144 GLsizei height,
4145 GLsizei depth)
4146{
4147 Extents size(width, height, depth);
4148 Texture *texture = getTargetTexture(target);
4149 handleError(texture->setStorage(this, target, levels, internalFormat, size));
4150}
4151
Jamie Madillc1d770e2017-04-13 17:31:24 -04004152GLenum Context::checkFramebufferStatus(GLenum target)
4153{
4154 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4155 ASSERT(framebuffer);
4156
4157 return framebuffer->checkStatus(this);
4158}
4159
4160void Context::compileShader(GLuint shader)
4161{
4162 Shader *shaderObject = GetValidShader(this, shader);
4163 if (!shaderObject)
4164 {
4165 return;
4166 }
4167 shaderObject->compile(this);
4168}
4169
4170void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
4171{
4172 for (int i = 0; i < n; i++)
4173 {
4174 deleteBuffer(buffers[i]);
4175 }
4176}
4177
4178void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
4179{
4180 for (int i = 0; i < n; i++)
4181 {
4182 if (framebuffers[i] != 0)
4183 {
4184 deleteFramebuffer(framebuffers[i]);
4185 }
4186 }
4187}
4188
4189void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
4190{
4191 for (int i = 0; i < n; i++)
4192 {
4193 deleteRenderbuffer(renderbuffers[i]);
4194 }
4195}
4196
4197void Context::deleteTextures(GLsizei n, const GLuint *textures)
4198{
4199 for (int i = 0; i < n; i++)
4200 {
4201 if (textures[i] != 0)
4202 {
4203 deleteTexture(textures[i]);
4204 }
4205 }
4206}
4207
4208void Context::detachShader(GLuint program, GLuint shader)
4209{
4210 Program *programObject = getProgram(program);
4211 ASSERT(programObject);
4212
4213 Shader *shaderObject = getShader(shader);
4214 ASSERT(shaderObject);
4215
4216 programObject->detachShader(this, shaderObject);
4217}
4218
4219void Context::genBuffers(GLsizei n, GLuint *buffers)
4220{
4221 for (int i = 0; i < n; i++)
4222 {
4223 buffers[i] = createBuffer();
4224 }
4225}
4226
4227void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
4228{
4229 for (int i = 0; i < n; i++)
4230 {
4231 framebuffers[i] = createFramebuffer();
4232 }
4233}
4234
4235void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
4236{
4237 for (int i = 0; i < n; i++)
4238 {
4239 renderbuffers[i] = createRenderbuffer();
4240 }
4241}
4242
4243void Context::genTextures(GLsizei n, GLuint *textures)
4244{
4245 for (int i = 0; i < n; i++)
4246 {
4247 textures[i] = createTexture();
4248 }
4249}
4250
4251void Context::getActiveAttrib(GLuint program,
4252 GLuint index,
4253 GLsizei bufsize,
4254 GLsizei *length,
4255 GLint *size,
4256 GLenum *type,
4257 GLchar *name)
4258{
4259 Program *programObject = getProgram(program);
4260 ASSERT(programObject);
4261 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
4262}
4263
4264void Context::getActiveUniform(GLuint program,
4265 GLuint index,
4266 GLsizei bufsize,
4267 GLsizei *length,
4268 GLint *size,
4269 GLenum *type,
4270 GLchar *name)
4271{
4272 Program *programObject = getProgram(program);
4273 ASSERT(programObject);
4274 programObject->getActiveUniform(index, bufsize, length, size, type, name);
4275}
4276
4277void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
4278{
4279 Program *programObject = getProgram(program);
4280 ASSERT(programObject);
4281 programObject->getAttachedShaders(maxcount, count, shaders);
4282}
4283
4284GLint Context::getAttribLocation(GLuint program, const GLchar *name)
4285{
4286 Program *programObject = getProgram(program);
4287 ASSERT(programObject);
4288 return programObject->getAttributeLocation(name);
4289}
4290
4291void Context::getBooleanv(GLenum pname, GLboolean *params)
4292{
4293 GLenum nativeType;
4294 unsigned int numParams = 0;
4295 getQueryParameterInfo(pname, &nativeType, &numParams);
4296
4297 if (nativeType == GL_BOOL)
4298 {
4299 getBooleanvImpl(pname, params);
4300 }
4301 else
4302 {
4303 CastStateValues(this, nativeType, pname, numParams, params);
4304 }
4305}
4306
4307void Context::getFloatv(GLenum pname, GLfloat *params)
4308{
4309 GLenum nativeType;
4310 unsigned int numParams = 0;
4311 getQueryParameterInfo(pname, &nativeType, &numParams);
4312
4313 if (nativeType == GL_FLOAT)
4314 {
4315 getFloatvImpl(pname, params);
4316 }
4317 else
4318 {
4319 CastStateValues(this, nativeType, pname, numParams, params);
4320 }
4321}
4322
4323void Context::getIntegerv(GLenum pname, GLint *params)
4324{
4325 GLenum nativeType;
4326 unsigned int numParams = 0;
4327 getQueryParameterInfo(pname, &nativeType, &numParams);
4328
4329 if (nativeType == GL_INT)
4330 {
4331 getIntegervImpl(pname, params);
4332 }
4333 else
4334 {
4335 CastStateValues(this, nativeType, pname, numParams, params);
4336 }
4337}
4338
4339void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
4340{
4341 Program *programObject = getProgram(program);
4342 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04004343 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004344}
4345
Jamie Madillbe849e42017-05-02 15:49:00 -04004346void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04004347{
4348 Program *programObject = getProgram(program);
4349 ASSERT(programObject);
4350 programObject->getInfoLog(bufsize, length, infolog);
4351}
4352
4353void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
4354{
4355 Shader *shaderObject = getShader(shader);
4356 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004357 QueryShaderiv(this, shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004358}
4359
4360void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
4361{
4362 Shader *shaderObject = getShader(shader);
4363 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004364 shaderObject->getInfoLog(this, bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004365}
4366
4367void Context::getShaderPrecisionFormat(GLenum shadertype,
4368 GLenum precisiontype,
4369 GLint *range,
4370 GLint *precision)
4371{
4372 // TODO(jmadill): Compute shaders.
4373
4374 switch (shadertype)
4375 {
4376 case GL_VERTEX_SHADER:
4377 switch (precisiontype)
4378 {
4379 case GL_LOW_FLOAT:
4380 mCaps.vertexLowpFloat.get(range, precision);
4381 break;
4382 case GL_MEDIUM_FLOAT:
4383 mCaps.vertexMediumpFloat.get(range, precision);
4384 break;
4385 case GL_HIGH_FLOAT:
4386 mCaps.vertexHighpFloat.get(range, precision);
4387 break;
4388
4389 case GL_LOW_INT:
4390 mCaps.vertexLowpInt.get(range, precision);
4391 break;
4392 case GL_MEDIUM_INT:
4393 mCaps.vertexMediumpInt.get(range, precision);
4394 break;
4395 case GL_HIGH_INT:
4396 mCaps.vertexHighpInt.get(range, precision);
4397 break;
4398
4399 default:
4400 UNREACHABLE();
4401 return;
4402 }
4403 break;
4404
4405 case GL_FRAGMENT_SHADER:
4406 switch (precisiontype)
4407 {
4408 case GL_LOW_FLOAT:
4409 mCaps.fragmentLowpFloat.get(range, precision);
4410 break;
4411 case GL_MEDIUM_FLOAT:
4412 mCaps.fragmentMediumpFloat.get(range, precision);
4413 break;
4414 case GL_HIGH_FLOAT:
4415 mCaps.fragmentHighpFloat.get(range, precision);
4416 break;
4417
4418 case GL_LOW_INT:
4419 mCaps.fragmentLowpInt.get(range, precision);
4420 break;
4421 case GL_MEDIUM_INT:
4422 mCaps.fragmentMediumpInt.get(range, precision);
4423 break;
4424 case GL_HIGH_INT:
4425 mCaps.fragmentHighpInt.get(range, precision);
4426 break;
4427
4428 default:
4429 UNREACHABLE();
4430 return;
4431 }
4432 break;
4433
4434 default:
4435 UNREACHABLE();
4436 return;
4437 }
4438}
4439
4440void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
4441{
4442 Shader *shaderObject = getShader(shader);
4443 ASSERT(shaderObject);
4444 shaderObject->getSource(bufsize, length, source);
4445}
4446
4447void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
4448{
4449 Program *programObject = getProgram(program);
4450 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04004451 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004452}
4453
4454void Context::getUniformiv(GLuint program, GLint location, GLint *params)
4455{
4456 Program *programObject = getProgram(program);
4457 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04004458 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004459}
4460
4461GLint Context::getUniformLocation(GLuint program, const GLchar *name)
4462{
4463 Program *programObject = getProgram(program);
4464 ASSERT(programObject);
4465 return programObject->getUniformLocation(name);
4466}
4467
4468GLboolean Context::isBuffer(GLuint buffer)
4469{
4470 if (buffer == 0)
4471 {
4472 return GL_FALSE;
4473 }
4474
4475 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
4476}
4477
4478GLboolean Context::isEnabled(GLenum cap)
4479{
4480 return mGLState.getEnableFeature(cap);
4481}
4482
4483GLboolean Context::isFramebuffer(GLuint framebuffer)
4484{
4485 if (framebuffer == 0)
4486 {
4487 return GL_FALSE;
4488 }
4489
4490 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
4491}
4492
4493GLboolean Context::isProgram(GLuint program)
4494{
4495 if (program == 0)
4496 {
4497 return GL_FALSE;
4498 }
4499
4500 return (getProgram(program) ? GL_TRUE : GL_FALSE);
4501}
4502
4503GLboolean Context::isRenderbuffer(GLuint renderbuffer)
4504{
4505 if (renderbuffer == 0)
4506 {
4507 return GL_FALSE;
4508 }
4509
4510 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
4511}
4512
4513GLboolean Context::isShader(GLuint shader)
4514{
4515 if (shader == 0)
4516 {
4517 return GL_FALSE;
4518 }
4519
4520 return (getShader(shader) ? GL_TRUE : GL_FALSE);
4521}
4522
4523GLboolean Context::isTexture(GLuint texture)
4524{
4525 if (texture == 0)
4526 {
4527 return GL_FALSE;
4528 }
4529
4530 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
4531}
4532
4533void Context::linkProgram(GLuint program)
4534{
4535 Program *programObject = getProgram(program);
4536 ASSERT(programObject);
4537 handleError(programObject->link(this));
Martin Radev0abb7a22017-08-28 15:34:45 +03004538 mGLState.onProgramExecutableChange(programObject);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004539}
4540
4541void Context::releaseShaderCompiler()
4542{
Jamie Madill4928b7c2017-06-20 12:57:39 -04004543 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004544}
4545
4546void Context::shaderBinary(GLsizei n,
4547 const GLuint *shaders,
4548 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04004549 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04004550 GLsizei length)
4551{
4552 // No binary shader formats are supported.
4553 UNIMPLEMENTED();
4554}
4555
4556void Context::shaderSource(GLuint shader,
4557 GLsizei count,
4558 const GLchar *const *string,
4559 const GLint *length)
4560{
4561 Shader *shaderObject = getShader(shader);
4562 ASSERT(shaderObject);
4563 shaderObject->setSource(count, string, length);
4564}
4565
4566void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
4567{
4568 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
4569}
4570
4571void Context::stencilMask(GLuint mask)
4572{
4573 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
4574}
4575
4576void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
4577{
4578 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
4579}
4580
4581void Context::uniform1f(GLint location, GLfloat x)
4582{
4583 Program *program = mGLState.getProgram();
4584 program->setUniform1fv(location, 1, &x);
4585}
4586
4587void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
4588{
4589 Program *program = mGLState.getProgram();
4590 program->setUniform1fv(location, count, v);
4591}
4592
4593void Context::uniform1i(GLint location, GLint x)
4594{
4595 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04004596 if (program->setUniform1iv(location, 1, &x) == Program::SetUniformResult::SamplerChanged)
4597 {
4598 mGLState.setObjectDirty(GL_PROGRAM);
4599 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04004600}
4601
4602void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
4603{
4604 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04004605 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
4606 {
4607 mGLState.setObjectDirty(GL_PROGRAM);
4608 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04004609}
4610
4611void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
4612{
4613 GLfloat xy[2] = {x, y};
4614 Program *program = mGLState.getProgram();
4615 program->setUniform2fv(location, 1, xy);
4616}
4617
4618void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
4619{
4620 Program *program = mGLState.getProgram();
4621 program->setUniform2fv(location, count, v);
4622}
4623
4624void Context::uniform2i(GLint location, GLint x, GLint y)
4625{
4626 GLint xy[2] = {x, y};
4627 Program *program = mGLState.getProgram();
4628 program->setUniform2iv(location, 1, xy);
4629}
4630
4631void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
4632{
4633 Program *program = mGLState.getProgram();
4634 program->setUniform2iv(location, count, v);
4635}
4636
4637void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
4638{
4639 GLfloat xyz[3] = {x, y, z};
4640 Program *program = mGLState.getProgram();
4641 program->setUniform3fv(location, 1, xyz);
4642}
4643
4644void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
4645{
4646 Program *program = mGLState.getProgram();
4647 program->setUniform3fv(location, count, v);
4648}
4649
4650void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
4651{
4652 GLint xyz[3] = {x, y, z};
4653 Program *program = mGLState.getProgram();
4654 program->setUniform3iv(location, 1, xyz);
4655}
4656
4657void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
4658{
4659 Program *program = mGLState.getProgram();
4660 program->setUniform3iv(location, count, v);
4661}
4662
4663void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4664{
4665 GLfloat xyzw[4] = {x, y, z, w};
4666 Program *program = mGLState.getProgram();
4667 program->setUniform4fv(location, 1, xyzw);
4668}
4669
4670void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
4671{
4672 Program *program = mGLState.getProgram();
4673 program->setUniform4fv(location, count, v);
4674}
4675
4676void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
4677{
4678 GLint xyzw[4] = {x, y, z, w};
4679 Program *program = mGLState.getProgram();
4680 program->setUniform4iv(location, 1, xyzw);
4681}
4682
4683void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
4684{
4685 Program *program = mGLState.getProgram();
4686 program->setUniform4iv(location, count, v);
4687}
4688
4689void Context::uniformMatrix2fv(GLint location,
4690 GLsizei count,
4691 GLboolean transpose,
4692 const GLfloat *value)
4693{
4694 Program *program = mGLState.getProgram();
4695 program->setUniformMatrix2fv(location, count, transpose, value);
4696}
4697
4698void Context::uniformMatrix3fv(GLint location,
4699 GLsizei count,
4700 GLboolean transpose,
4701 const GLfloat *value)
4702{
4703 Program *program = mGLState.getProgram();
4704 program->setUniformMatrix3fv(location, count, transpose, value);
4705}
4706
4707void Context::uniformMatrix4fv(GLint location,
4708 GLsizei count,
4709 GLboolean transpose,
4710 const GLfloat *value)
4711{
4712 Program *program = mGLState.getProgram();
4713 program->setUniformMatrix4fv(location, count, transpose, value);
4714}
4715
4716void Context::validateProgram(GLuint program)
4717{
4718 Program *programObject = getProgram(program);
4719 ASSERT(programObject);
4720 programObject->validate(mCaps);
4721}
4722
Jamie Madilld04908b2017-06-09 14:15:35 -04004723void Context::getProgramBinary(GLuint program,
4724 GLsizei bufSize,
4725 GLsizei *length,
4726 GLenum *binaryFormat,
4727 void *binary)
4728{
4729 Program *programObject = getProgram(program);
4730 ASSERT(programObject != nullptr);
4731
4732 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
4733}
4734
4735void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
4736{
4737 Program *programObject = getProgram(program);
4738 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04004739
Jamie Madilld04908b2017-06-09 14:15:35 -04004740 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
4741}
4742
Jamie Madillff325f12017-08-26 15:06:05 -04004743void Context::uniform1ui(GLint location, GLuint v0)
4744{
4745 Program *program = mGLState.getProgram();
4746 program->setUniform1uiv(location, 1, &v0);
4747}
4748
4749void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
4750{
4751 Program *program = mGLState.getProgram();
4752 const GLuint xy[] = {v0, v1};
4753 program->setUniform2uiv(location, 1, xy);
4754}
4755
4756void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
4757{
4758 Program *program = mGLState.getProgram();
4759 const GLuint xyz[] = {v0, v1, v2};
4760 program->setUniform3uiv(location, 1, xyz);
4761}
4762
4763void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
4764{
4765 Program *program = mGLState.getProgram();
4766 const GLuint xyzw[] = {v0, v1, v2, v3};
4767 program->setUniform4uiv(location, 1, xyzw);
4768}
4769
4770void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
4771{
4772 Program *program = mGLState.getProgram();
4773 program->setUniform1uiv(location, count, value);
4774}
4775void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
4776{
4777 Program *program = mGLState.getProgram();
4778 program->setUniform2uiv(location, count, value);
4779}
4780
4781void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
4782{
4783 Program *program = mGLState.getProgram();
4784 program->setUniform3uiv(location, count, value);
4785}
4786
4787void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
4788{
4789 Program *program = mGLState.getProgram();
4790 program->setUniform4uiv(location, count, value);
4791}
4792
Jamie Madillf0e04492017-08-26 15:28:42 -04004793void Context::genQueries(GLsizei n, GLuint *ids)
4794{
4795 for (GLsizei i = 0; i < n; i++)
4796 {
4797 GLuint handle = mQueryHandleAllocator.allocate();
4798 mQueryMap.assign(handle, nullptr);
4799 ids[i] = handle;
4800 }
4801}
4802
4803void Context::deleteQueries(GLsizei n, const GLuint *ids)
4804{
4805 for (int i = 0; i < n; i++)
4806 {
4807 GLuint query = ids[i];
4808
4809 Query *queryObject = nullptr;
4810 if (mQueryMap.erase(query, &queryObject))
4811 {
4812 mQueryHandleAllocator.release(query);
4813 if (queryObject)
4814 {
4815 queryObject->release(this);
4816 }
4817 }
4818 }
4819}
4820
4821GLboolean Context::isQuery(GLuint id)
4822{
4823 return (getQuery(id, false, GL_NONE) != nullptr) ? GL_TRUE : GL_FALSE;
4824}
4825
Jamie Madillc8c95812017-08-26 18:40:09 -04004826void Context::uniformMatrix2x3fv(GLint location,
4827 GLsizei count,
4828 GLboolean transpose,
4829 const GLfloat *value)
4830{
4831 Program *program = mGLState.getProgram();
4832 program->setUniformMatrix2x3fv(location, count, transpose, value);
4833}
4834
4835void Context::uniformMatrix3x2fv(GLint location,
4836 GLsizei count,
4837 GLboolean transpose,
4838 const GLfloat *value)
4839{
4840 Program *program = mGLState.getProgram();
4841 program->setUniformMatrix3x2fv(location, count, transpose, value);
4842}
4843
4844void Context::uniformMatrix2x4fv(GLint location,
4845 GLsizei count,
4846 GLboolean transpose,
4847 const GLfloat *value)
4848{
4849 Program *program = mGLState.getProgram();
4850 program->setUniformMatrix2x4fv(location, count, transpose, value);
4851}
4852
4853void Context::uniformMatrix4x2fv(GLint location,
4854 GLsizei count,
4855 GLboolean transpose,
4856 const GLfloat *value)
4857{
4858 Program *program = mGLState.getProgram();
4859 program->setUniformMatrix4x2fv(location, count, transpose, value);
4860}
4861
4862void Context::uniformMatrix3x4fv(GLint location,
4863 GLsizei count,
4864 GLboolean transpose,
4865 const GLfloat *value)
4866{
4867 Program *program = mGLState.getProgram();
4868 program->setUniformMatrix3x4fv(location, count, transpose, value);
4869}
4870
4871void Context::uniformMatrix4x3fv(GLint location,
4872 GLsizei count,
4873 GLboolean transpose,
4874 const GLfloat *value)
4875{
4876 Program *program = mGLState.getProgram();
4877 program->setUniformMatrix4x3fv(location, count, transpose, value);
4878}
4879
Jamie Madilld7576732017-08-26 18:49:50 -04004880void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
4881{
4882 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
4883 {
4884 GLuint vertexArray = arrays[arrayIndex];
4885
4886 if (arrays[arrayIndex] != 0)
4887 {
4888 VertexArray *vertexArrayObject = nullptr;
4889 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
4890 {
4891 if (vertexArrayObject != nullptr)
4892 {
4893 detachVertexArray(vertexArray);
4894 vertexArrayObject->onDestroy(this);
4895 }
4896
4897 mVertexArrayHandleAllocator.release(vertexArray);
4898 }
4899 }
4900 }
4901}
4902
4903void Context::genVertexArrays(GLsizei n, GLuint *arrays)
4904{
4905 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
4906 {
4907 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
4908 mVertexArrayMap.assign(vertexArray, nullptr);
4909 arrays[arrayIndex] = vertexArray;
4910 }
4911}
4912
4913bool Context::isVertexArray(GLuint array)
4914{
4915 if (array == 0)
4916 {
4917 return GL_FALSE;
4918 }
4919
4920 VertexArray *vao = getVertexArray(array);
4921 return (vao != nullptr ? GL_TRUE : GL_FALSE);
4922}
4923
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04004924void Context::endTransformFeedback()
4925{
4926 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
4927 transformFeedback->end(this);
4928}
4929
4930void Context::transformFeedbackVaryings(GLuint program,
4931 GLsizei count,
4932 const GLchar *const *varyings,
4933 GLenum bufferMode)
4934{
4935 Program *programObject = getProgram(program);
4936 ASSERT(programObject);
4937 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
4938}
4939
4940void Context::getTransformFeedbackVarying(GLuint program,
4941 GLuint index,
4942 GLsizei bufSize,
4943 GLsizei *length,
4944 GLsizei *size,
4945 GLenum *type,
4946 GLchar *name)
4947{
4948 Program *programObject = getProgram(program);
4949 ASSERT(programObject);
4950 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
4951}
4952
4953void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
4954{
4955 for (int i = 0; i < n; i++)
4956 {
4957 GLuint transformFeedback = ids[i];
4958 if (transformFeedback == 0)
4959 {
4960 continue;
4961 }
4962
4963 TransformFeedback *transformFeedbackObject = nullptr;
4964 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
4965 {
4966 if (transformFeedbackObject != nullptr)
4967 {
4968 detachTransformFeedback(transformFeedback);
4969 transformFeedbackObject->release(this);
4970 }
4971
4972 mTransformFeedbackHandleAllocator.release(transformFeedback);
4973 }
4974 }
4975}
4976
4977void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
4978{
4979 for (int i = 0; i < n; i++)
4980 {
4981 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
4982 mTransformFeedbackMap.assign(transformFeedback, nullptr);
4983 ids[i] = transformFeedback;
4984 }
4985}
4986
4987bool Context::isTransformFeedback(GLuint id)
4988{
4989 if (id == 0)
4990 {
4991 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
4992 // returns FALSE
4993 return GL_FALSE;
4994 }
4995
4996 const TransformFeedback *transformFeedback = getTransformFeedback(id);
4997 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
4998}
4999
5000void Context::pauseTransformFeedback()
5001{
5002 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5003 transformFeedback->pause();
5004}
5005
5006void Context::resumeTransformFeedback()
5007{
5008 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5009 transformFeedback->resume();
5010}
5011
Jamie Madill12e957f2017-08-26 21:42:26 -04005012void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
5013{
5014 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04005015 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04005016}
5017
5018GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
5019{
5020 const Program *programObject = getProgram(program);
5021 return programObject->getFragDataLocation(name);
5022}
5023
5024void Context::getUniformIndices(GLuint program,
5025 GLsizei uniformCount,
5026 const GLchar *const *uniformNames,
5027 GLuint *uniformIndices)
5028{
5029 const Program *programObject = getProgram(program);
5030 if (!programObject->isLinked())
5031 {
5032 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5033 {
5034 uniformIndices[uniformId] = GL_INVALID_INDEX;
5035 }
5036 }
5037 else
5038 {
5039 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5040 {
5041 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
5042 }
5043 }
5044}
5045
5046void Context::getActiveUniformsiv(GLuint program,
5047 GLsizei uniformCount,
5048 const GLuint *uniformIndices,
5049 GLenum pname,
5050 GLint *params)
5051{
5052 const Program *programObject = getProgram(program);
5053 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5054 {
5055 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08005056 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04005057 }
5058}
5059
5060GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
5061{
5062 const Program *programObject = getProgram(program);
5063 return programObject->getUniformBlockIndex(uniformBlockName);
5064}
5065
5066void Context::getActiveUniformBlockiv(GLuint program,
5067 GLuint uniformBlockIndex,
5068 GLenum pname,
5069 GLint *params)
5070{
5071 const Program *programObject = getProgram(program);
5072 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
5073}
5074
5075void Context::getActiveUniformBlockName(GLuint program,
5076 GLuint uniformBlockIndex,
5077 GLsizei bufSize,
5078 GLsizei *length,
5079 GLchar *uniformBlockName)
5080{
5081 const Program *programObject = getProgram(program);
5082 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
5083}
5084
5085void Context::uniformBlockBinding(GLuint program,
5086 GLuint uniformBlockIndex,
5087 GLuint uniformBlockBinding)
5088{
5089 Program *programObject = getProgram(program);
5090 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
5091}
5092
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005093GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
5094{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005095 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
5096 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005097
Jamie Madill70b5bb02017-08-28 13:32:37 -04005098 Sync *syncObject = getSync(syncHandle);
5099 Error error = syncObject->set(condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005100 if (error.isError())
5101 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04005102 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005103 handleError(error);
5104 return nullptr;
5105 }
5106
Jamie Madill70b5bb02017-08-28 13:32:37 -04005107 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005108}
5109
5110GLboolean Context::isSync(GLsync sync)
5111{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005112 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005113}
5114
5115GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
5116{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005117 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005118
5119 GLenum result = GL_WAIT_FAILED;
5120 handleError(syncObject->clientWait(flags, timeout, &result));
5121 return result;
5122}
5123
5124void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
5125{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005126 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005127 handleError(syncObject->serverWait(flags, timeout));
5128}
5129
5130void Context::getInteger64v(GLenum pname, GLint64 *params)
5131{
5132 GLenum nativeType = GL_NONE;
5133 unsigned int numParams = 0;
5134 getQueryParameterInfo(pname, &nativeType, &numParams);
5135
5136 if (nativeType == GL_INT_64_ANGLEX)
5137 {
5138 getInteger64vImpl(pname, params);
5139 }
5140 else
5141 {
5142 CastStateValues(this, nativeType, pname, numParams, params);
5143 }
5144}
5145
Corentin Wallez336129f2017-10-17 15:55:40 -04005146void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04005147{
5148 Buffer *buffer = mGLState.getTargetBuffer(target);
5149 QueryBufferParameteri64v(buffer, pname, params);
5150}
5151
5152void Context::genSamplers(GLsizei count, GLuint *samplers)
5153{
5154 for (int i = 0; i < count; i++)
5155 {
5156 samplers[i] = mState.mSamplers->createSampler();
5157 }
5158}
5159
5160void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
5161{
5162 for (int i = 0; i < count; i++)
5163 {
5164 GLuint sampler = samplers[i];
5165
5166 if (mState.mSamplers->getSampler(sampler))
5167 {
5168 detachSampler(sampler);
5169 }
5170
5171 mState.mSamplers->deleteObject(this, sampler);
5172 }
5173}
5174
5175void Context::getInternalformativ(GLenum target,
5176 GLenum internalformat,
5177 GLenum pname,
5178 GLsizei bufSize,
5179 GLint *params)
5180{
5181 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
5182 QueryInternalFormativ(formatCaps, pname, bufSize, params);
5183}
5184
Jamie Madill81c2e252017-09-09 23:32:46 -04005185void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5186{
5187 Program *programObject = getProgram(program);
5188 ASSERT(programObject);
5189 if (programObject->setUniform1iv(location, count, value) ==
5190 Program::SetUniformResult::SamplerChanged)
5191 {
5192 mGLState.setObjectDirty(GL_PROGRAM);
5193 }
5194}
5195
5196void Context::onTextureChange(const Texture *texture)
5197{
5198 // Conservatively assume all textures are dirty.
5199 // TODO(jmadill): More fine-grained update.
5200 mGLState.setObjectDirty(GL_TEXTURE);
5201}
5202
Yunchao Hea336b902017-08-02 16:05:21 +08005203void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
5204{
5205 for (int i = 0; i < count; i++)
5206 {
5207 pipelines[i] = createProgramPipeline();
5208 }
5209}
5210
5211void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
5212{
5213 for (int i = 0; i < count; i++)
5214 {
5215 if (pipelines[i] != 0)
5216 {
5217 deleteProgramPipeline(pipelines[i]);
5218 }
5219 }
5220}
5221
5222GLboolean Context::isProgramPipeline(GLuint pipeline)
5223{
5224 if (pipeline == 0)
5225 {
5226 return GL_FALSE;
5227 }
5228
5229 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
5230}
5231
Jamie Madillc29968b2016-01-20 11:17:23 -05005232} // namespace gl