blob: 476a13926d87db98e3ed00fad8d9fe096d9df8cb [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,
168 EGL_NO_RESET_NOTIFICATION_EXT);
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:
308 // In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have twodimensional
309 // 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
334 bindGenericAtomicCounterBuffer(0);
335 for (unsigned int i = 0; i < mCaps.maxAtomicCounterBufferBindings; i++)
336 {
337 bindIndexedAtomicCounterBuffer(0, i, 0, 0);
338 }
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800339
340 bindGenericShaderStorageBuffer(0);
341 for (unsigned int i = 0; i < mCaps.maxShaderStorageBufferBindings; i++)
342 {
343 bindIndexedShaderStorageBuffer(0, i, 0, 0);
344 }
Geoff Lang3b573612016-10-31 14:08:10 -0400345 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000346
Geoff Lang4751aab2017-10-30 15:14:52 -0400347 const Extensions &nativeExtensions = mImplementation->getNativeExtensions();
348 if (nativeExtensions.textureRectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400349 {
350 Texture *zeroTextureRectangle =
351 new Texture(mImplementation.get(), 0, GL_TEXTURE_RECTANGLE_ANGLE);
352 mZeroTextures[GL_TEXTURE_RECTANGLE_ANGLE].set(this, zeroTextureRectangle);
353 }
354
Geoff Lang4751aab2017-10-30 15:14:52 -0400355 if (nativeExtensions.eglImageExternal || nativeExtensions.eglStreamConsumerExternal)
Ian Ewellbda75592016-04-18 17:25:54 -0400356 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400357 Texture *zeroTextureExternal =
358 new Texture(mImplementation.get(), 0, GL_TEXTURE_EXTERNAL_OES);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400359 mZeroTextures[GL_TEXTURE_EXTERNAL_OES].set(this, zeroTextureExternal);
Ian Ewellbda75592016-04-18 17:25:54 -0400360 }
361
Jamie Madill4928b7c2017-06-20 12:57:39 -0400362 mGLState.initializeZeroTextures(this, mZeroTextures);
Jamie Madille6382c32014-11-07 15:05:26 -0500363
Jamie Madill57a89722013-07-02 11:57:03 -0400364 bindVertexArray(0);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000365 bindArrayBuffer(0);
Jiajia Qin9d7d0b12016-11-29 16:30:31 +0800366 bindDrawIndirectBuffer(0);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000367 bindElementArrayBuffer(0);
Geoff Lang76b10c92014-09-05 16:28:14 -0400368
Jamie Madill01a80ee2016-11-07 12:06:18 -0500369 bindRenderbuffer(GL_RENDERBUFFER, 0);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000370
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +0000371 bindGenericUniformBuffer(0);
Geoff Lang4dc3af02016-11-18 14:09:27 -0500372 for (unsigned int i = 0; i < mCaps.maxUniformBufferBindings; i++)
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +0000373 {
374 bindIndexedUniformBuffer(0, i, 0, -1);
375 }
376
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000377 bindCopyReadBuffer(0);
378 bindCopyWriteBuffer(0);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +0000379 bindPixelPackBuffer(0);
380 bindPixelUnpackBuffer(0);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000381
Geoff Langeb66a6e2016-10-31 13:06:12 -0400382 if (getClientVersion() >= Version(3, 0))
Geoff Lang1a683462015-09-29 15:09:59 -0400383 {
384 // [OpenGL ES 3.0.2] section 2.14.1 pg 85:
385 // In the initial state, a default transform feedback object is bound and treated as
386 // a transform feedback object with a name of zero. That object is bound any time
387 // BindTransformFeedback is called with id of zero
Jamie Madillf0dcb8b2017-08-26 19:05:13 -0400388 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Geoff Lang1a683462015-09-29 15:09:59 -0400389 }
Geoff Langc8058452014-02-03 12:04:11 -0500390
Jamie Madillad9f24e2016-02-12 09:27:24 -0500391 // Initialize dirty bit masks
Jamie Madillc67323a2017-11-02 23:11:41 -0400392 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_STATE);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500393 // No dirty objects.
394
395 // Readpixels uses the pack state and read FBO
Jamie Madillc67323a2017-11-02 23:11:41 -0400396 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_STATE);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500397 mReadPixelsDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
398
399 mClearDirtyBits.set(State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED);
400 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
401 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR);
402 mClearDirtyBits.set(State::DIRTY_BIT_VIEWPORT);
403 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_COLOR);
404 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_DEPTH);
405 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_STENCIL);
406 mClearDirtyBits.set(State::DIRTY_BIT_COLOR_MASK);
407 mClearDirtyBits.set(State::DIRTY_BIT_DEPTH_MASK);
408 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT);
409 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_BACK);
410 mClearDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
411
412 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
413 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR);
Geoff Lang1d2c41d2016-10-19 16:14:46 -0700414 mBlitDirtyBits.set(State::DIRTY_BIT_FRAMEBUFFER_SRGB);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500415 mBlitDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
416 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
Jamie Madill437fa652016-05-03 15:13:24 -0400417
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400418 handleError(mImplementation->initialize());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000419}
420
Jamie Madill4928b7c2017-06-20 12:57:39 -0400421egl::Error Context::onDestroy(const egl::Display *display)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000422{
Corentin Wallez80b24112015-08-25 16:41:57 -0400423 for (auto fence : mFenceNVMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000424 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400425 SafeDelete(fence.second);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000426 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400427 mFenceNVMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000428
Corentin Wallez80b24112015-08-25 16:41:57 -0400429 for (auto query : mQueryMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000430 {
Geoff Langf0aa8422015-09-29 15:08:34 -0400431 if (query.second != nullptr)
432 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400433 query.second->release(this);
Geoff Langf0aa8422015-09-29 15:08:34 -0400434 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000435 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400436 mQueryMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000437
Corentin Wallez80b24112015-08-25 16:41:57 -0400438 for (auto vertexArray : mVertexArrayMap)
Jamie Madill57a89722013-07-02 11:57:03 -0400439 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400440 if (vertexArray.second)
441 {
442 vertexArray.second->onDestroy(this);
443 }
Jamie Madill57a89722013-07-02 11:57:03 -0400444 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400445 mVertexArrayMap.clear();
Jamie Madill57a89722013-07-02 11:57:03 -0400446
Corentin Wallez80b24112015-08-25 16:41:57 -0400447 for (auto transformFeedback : mTransformFeedbackMap)
Geoff Langc8058452014-02-03 12:04:11 -0500448 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500449 if (transformFeedback.second != nullptr)
450 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500451 transformFeedback.second->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500452 }
Geoff Langc8058452014-02-03 12:04:11 -0500453 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400454 mTransformFeedbackMap.clear();
Geoff Langc8058452014-02-03 12:04:11 -0500455
Jamie Madilldedd7b92014-11-05 16:30:36 -0500456 for (auto &zeroTexture : mZeroTextures)
Geoff Lang76b10c92014-09-05 16:28:14 -0400457 {
Jamie Madill71c88b32017-09-14 22:20:29 -0400458 ANGLE_TRY(zeroTexture.second->onDestroy(this));
Jamie Madill4928b7c2017-06-20 12:57:39 -0400459 zeroTexture.second.set(this, nullptr);
Geoff Lang76b10c92014-09-05 16:28:14 -0400460 }
461 mZeroTextures.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000462
Corentin Wallezccab69d2017-01-27 16:57:15 -0500463 SafeDelete(mSurfacelessFramebuffer);
464
Jamie Madill4928b7c2017-06-20 12:57:39 -0400465 ANGLE_TRY(releaseSurface(display));
Jamie Madill2f348d22017-06-05 10:50:59 -0400466 releaseShaderCompiler();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500467
Jamie Madill4928b7c2017-06-20 12:57:39 -0400468 mGLState.reset(this);
469
Jamie Madill6c1f6712017-02-14 19:08:04 -0500470 mState.mBuffers->release(this);
471 mState.mShaderPrograms->release(this);
472 mState.mTextures->release(this);
473 mState.mRenderbuffers->release(this);
474 mState.mSamplers->release(this);
Jamie Madill70b5bb02017-08-28 13:32:37 -0400475 mState.mSyncs->release(this);
Jamie Madill6c1f6712017-02-14 19:08:04 -0500476 mState.mPaths->release(this);
477 mState.mFramebuffers->release(this);
Yunchao Hea336b902017-08-02 16:05:21 +0800478 mState.mPipelines->release(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400479
Jamie Madill76e471e2017-10-21 09:56:01 -0400480 mImplementation->onDestroy(this);
481
Jamie Madill4928b7c2017-06-20 12:57:39 -0400482 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000483}
484
Jamie Madill70ee0f62017-02-06 16:04:20 -0500485Context::~Context()
486{
487}
488
Jamie Madill4928b7c2017-06-20 12:57:39 -0400489egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000490{
Jamie Madill61e16b42017-06-19 11:13:23 -0400491 mCurrentDisplay = display;
492
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000493 if (!mHasBeenCurrent)
494 {
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000495 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500496 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400497 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000498
Corentin Wallezc295e512017-01-27 17:47:50 -0500499 int width = 0;
500 int height = 0;
501 if (surface != nullptr)
502 {
503 width = surface->getWidth();
504 height = surface->getHeight();
505 }
506
507 mGLState.setViewportParams(0, 0, width, height);
508 mGLState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000509
510 mHasBeenCurrent = true;
511 }
512
Jamie Madill1b94d432015-08-07 13:23:23 -0400513 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700514 mGLState.setAllDirtyBits();
Jamie Madill81c2e252017-09-09 23:32:46 -0400515 mGLState.setAllDirtyObjects();
Jamie Madill1b94d432015-08-07 13:23:23 -0400516
Jamie Madill4928b7c2017-06-20 12:57:39 -0400517 ANGLE_TRY(releaseSurface(display));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500518
519 Framebuffer *newDefault = nullptr;
520 if (surface != nullptr)
521 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400522 ANGLE_TRY(surface->setIsCurrent(this, true));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500523 mCurrentSurface = surface;
524 newDefault = surface->getDefaultFramebuffer();
525 }
526 else
527 {
528 if (mSurfacelessFramebuffer == nullptr)
529 {
530 mSurfacelessFramebuffer = new Framebuffer(mImplementation.get());
531 }
532
533 newDefault = mSurfacelessFramebuffer;
534 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000535
Corentin Wallez37c39792015-08-20 14:19:46 -0400536 // Update default framebuffer, the binding of the previous default
537 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400538 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700539 if (mGLState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400540 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700541 mGLState.setReadFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400542 }
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700543 if (mGLState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400544 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700545 mGLState.setDrawFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400546 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500547 mState.mFramebuffers->setDefaultFramebuffer(newDefault);
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400548 }
Ian Ewell292f0052016-02-04 10:37:32 -0500549
550 // Notify the renderer of a context switch
Jamie Madill4928b7c2017-06-20 12:57:39 -0400551 mImplementation->onMakeCurrent(this);
552 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000553}
554
Jamie Madill4928b7c2017-06-20 12:57:39 -0400555egl::Error Context::releaseSurface(const egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400556{
Corentin Wallez37c39792015-08-20 14:19:46 -0400557 // Remove the default framebuffer
Corentin Wallezc295e512017-01-27 17:47:50 -0500558 Framebuffer *currentDefault = nullptr;
559 if (mCurrentSurface != nullptr)
Corentin Wallez51706ea2015-08-07 14:39:22 -0400560 {
Corentin Wallezc295e512017-01-27 17:47:50 -0500561 currentDefault = mCurrentSurface->getDefaultFramebuffer();
562 }
563 else if (mSurfacelessFramebuffer != nullptr)
564 {
565 currentDefault = mSurfacelessFramebuffer;
Corentin Wallez51706ea2015-08-07 14:39:22 -0400566 }
567
Corentin Wallezc295e512017-01-27 17:47:50 -0500568 if (mGLState.getReadFramebuffer() == currentDefault)
569 {
570 mGLState.setReadFramebufferBinding(nullptr);
571 }
572 if (mGLState.getDrawFramebuffer() == currentDefault)
573 {
574 mGLState.setDrawFramebufferBinding(nullptr);
575 }
576 mState.mFramebuffers->setDefaultFramebuffer(nullptr);
577
578 if (mCurrentSurface)
579 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400580 ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
Corentin Wallezc295e512017-01-27 17:47:50 -0500581 mCurrentSurface = nullptr;
582 }
Jamie Madill4928b7c2017-06-20 12:57:39 -0400583
584 return egl::NoError();
Jamie Madill77a72f62015-04-14 11:18:32 -0400585}
586
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000587GLuint Context::createBuffer()
588{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500589 return mState.mBuffers->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000590}
591
592GLuint Context::createProgram()
593{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500594 return mState.mShaderPrograms->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000595}
596
597GLuint Context::createShader(GLenum type)
598{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500599 return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000600}
601
602GLuint Context::createTexture()
603{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500604 return mState.mTextures->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000605}
606
607GLuint Context::createRenderbuffer()
608{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500609 return mState.mRenderbuffers->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000610}
611
Sami Väisänene45e53b2016-05-25 10:36:04 +0300612GLuint Context::createPaths(GLsizei range)
613{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500614 auto resultOrError = mState.mPaths->createPaths(mImplementation.get(), range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300615 if (resultOrError.isError())
616 {
617 handleError(resultOrError.getError());
618 return 0;
619 }
620 return resultOrError.getResult();
621}
622
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000623// Returns an unused framebuffer name
624GLuint Context::createFramebuffer()
625{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500626 return mState.mFramebuffers->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000627}
628
Jamie Madill33dc8432013-07-26 11:55:05 -0400629GLuint Context::createFenceNV()
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000630{
Jamie Madill33dc8432013-07-26 11:55:05 -0400631 GLuint handle = mFenceNVHandleAllocator.allocate();
Jamie Madill96a483b2017-06-27 16:49:21 -0400632 mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV()));
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000633 return handle;
634}
635
Yunchao Hea336b902017-08-02 16:05:21 +0800636GLuint Context::createProgramPipeline()
637{
638 return mState.mPipelines->createProgramPipeline();
639}
640
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000641void Context::deleteBuffer(GLuint buffer)
642{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500643 if (mState.mBuffers->getBuffer(buffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000644 {
645 detachBuffer(buffer);
646 }
Jamie Madill893ab082014-05-16 16:56:10 -0400647
Jamie Madill6c1f6712017-02-14 19:08:04 -0500648 mState.mBuffers->deleteObject(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000649}
650
651void Context::deleteShader(GLuint shader)
652{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500653 mState.mShaderPrograms->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000654}
655
656void Context::deleteProgram(GLuint program)
657{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500658 mState.mShaderPrograms->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000659}
660
661void Context::deleteTexture(GLuint texture)
662{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500663 if (mState.mTextures->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000664 {
665 detachTexture(texture);
666 }
667
Jamie Madill6c1f6712017-02-14 19:08:04 -0500668 mState.mTextures->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000669}
670
671void Context::deleteRenderbuffer(GLuint renderbuffer)
672{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500673 if (mState.mRenderbuffers->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000674 {
675 detachRenderbuffer(renderbuffer);
676 }
Jamie Madill893ab082014-05-16 16:56:10 -0400677
Jamie Madill6c1f6712017-02-14 19:08:04 -0500678 mState.mRenderbuffers->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000679}
680
Jamie Madill7f0c5a42017-08-26 22:43:26 -0400681void Context::deleteSync(GLsync sync)
Jamie Madillcd055f82013-07-26 11:55:15 -0400682{
683 // The spec specifies the underlying Fence object is not deleted until all current
684 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
685 // and since our API is currently designed for being called from a single thread, we can delete
686 // the fence immediately.
Jamie Madill70b5bb02017-08-28 13:32:37 -0400687 mState.mSyncs->deleteObject(this, static_cast<GLuint>(reinterpret_cast<uintptr_t>(sync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400688}
689
Yunchao Hea336b902017-08-02 16:05:21 +0800690void Context::deleteProgramPipeline(GLuint pipeline)
691{
692 if (mState.mPipelines->getProgramPipeline(pipeline))
693 {
694 detachProgramPipeline(pipeline);
695 }
696
697 mState.mPipelines->deleteObject(this, pipeline);
698}
699
Sami Väisänene45e53b2016-05-25 10:36:04 +0300700void Context::deletePaths(GLuint first, GLsizei range)
701{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500702 mState.mPaths->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300703}
704
705bool Context::hasPathData(GLuint path) const
706{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500707 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300708 if (pathObj == nullptr)
709 return false;
710
711 return pathObj->hasPathData();
712}
713
714bool Context::hasPath(GLuint path) const
715{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500716 return mState.mPaths->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300717}
718
719void Context::setPathCommands(GLuint path,
720 GLsizei numCommands,
721 const GLubyte *commands,
722 GLsizei numCoords,
723 GLenum coordType,
724 const void *coords)
725{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500726 auto *pathObject = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300727
728 handleError(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
729}
730
731void Context::setPathParameterf(GLuint path, GLenum pname, GLfloat value)
732{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500733 auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300734
735 switch (pname)
736 {
737 case GL_PATH_STROKE_WIDTH_CHROMIUM:
738 pathObj->setStrokeWidth(value);
739 break;
740 case GL_PATH_END_CAPS_CHROMIUM:
741 pathObj->setEndCaps(static_cast<GLenum>(value));
742 break;
743 case GL_PATH_JOIN_STYLE_CHROMIUM:
744 pathObj->setJoinStyle(static_cast<GLenum>(value));
745 break;
746 case GL_PATH_MITER_LIMIT_CHROMIUM:
747 pathObj->setMiterLimit(value);
748 break;
749 case GL_PATH_STROKE_BOUND_CHROMIUM:
750 pathObj->setStrokeBound(value);
751 break;
752 default:
753 UNREACHABLE();
754 break;
755 }
756}
757
758void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value) const
759{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500760 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300761
762 switch (pname)
763 {
764 case GL_PATH_STROKE_WIDTH_CHROMIUM:
765 *value = pathObj->getStrokeWidth();
766 break;
767 case GL_PATH_END_CAPS_CHROMIUM:
768 *value = static_cast<GLfloat>(pathObj->getEndCaps());
769 break;
770 case GL_PATH_JOIN_STYLE_CHROMIUM:
771 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
772 break;
773 case GL_PATH_MITER_LIMIT_CHROMIUM:
774 *value = pathObj->getMiterLimit();
775 break;
776 case GL_PATH_STROKE_BOUND_CHROMIUM:
777 *value = pathObj->getStrokeBound();
778 break;
779 default:
780 UNREACHABLE();
781 break;
782 }
783}
784
785void Context::setPathStencilFunc(GLenum func, GLint ref, GLuint mask)
786{
787 mGLState.setPathStencilFunc(func, ref, mask);
788}
789
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000790void Context::deleteFramebuffer(GLuint framebuffer)
791{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500792 if (mState.mFramebuffers->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000793 {
794 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000795 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500796
Jamie Madill6c1f6712017-02-14 19:08:04 -0500797 mState.mFramebuffers->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000798}
799
Jamie Madill33dc8432013-07-26 11:55:05 -0400800void Context::deleteFenceNV(GLuint fence)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000801{
Jamie Madill96a483b2017-06-27 16:49:21 -0400802 FenceNV *fenceObject = nullptr;
803 if (mFenceNVMap.erase(fence, &fenceObject))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000804 {
Jamie Madill96a483b2017-06-27 16:49:21 -0400805 mFenceNVHandleAllocator.release(fence);
806 delete fenceObject;
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000807 }
808}
809
Geoff Lang70d0f492015-12-10 17:45:46 -0500810Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000811{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500812 return mState.mBuffers->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000813}
814
Jamie Madill570f7c82014-07-03 10:38:54 -0400815Texture *Context::getTexture(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000816{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500817 return mState.mTextures->getTexture(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000818}
819
Geoff Lang70d0f492015-12-10 17:45:46 -0500820Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000821{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500822 return mState.mRenderbuffers->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000823}
824
Jamie Madill70b5bb02017-08-28 13:32:37 -0400825Sync *Context::getSync(GLsync handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400826{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400827 return mState.mSyncs->getSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400828}
829
Jamie Madill57a89722013-07-02 11:57:03 -0400830VertexArray *Context::getVertexArray(GLuint handle) const
831{
Jamie Madill96a483b2017-06-27 16:49:21 -0400832 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -0400833}
834
Jamie Madilldc356042013-07-19 16:36:57 -0400835Sampler *Context::getSampler(GLuint handle) const
836{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500837 return mState.mSamplers->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400838}
839
Geoff Langc8058452014-02-03 12:04:11 -0500840TransformFeedback *Context::getTransformFeedback(GLuint handle) const
841{
Jamie Madill96a483b2017-06-27 16:49:21 -0400842 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -0500843}
844
Yunchao Hea336b902017-08-02 16:05:21 +0800845ProgramPipeline *Context::getProgramPipeline(GLuint handle) const
846{
847 return mState.mPipelines->getProgramPipeline(handle);
848}
849
Geoff Lang70d0f492015-12-10 17:45:46 -0500850LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
851{
852 switch (identifier)
853 {
854 case GL_BUFFER:
855 return getBuffer(name);
856 case GL_SHADER:
857 return getShader(name);
858 case GL_PROGRAM:
859 return getProgram(name);
860 case GL_VERTEX_ARRAY:
861 return getVertexArray(name);
862 case GL_QUERY:
863 return getQuery(name);
864 case GL_TRANSFORM_FEEDBACK:
865 return getTransformFeedback(name);
866 case GL_SAMPLER:
867 return getSampler(name);
868 case GL_TEXTURE:
869 return getTexture(name);
870 case GL_RENDERBUFFER:
871 return getRenderbuffer(name);
872 case GL_FRAMEBUFFER:
873 return getFramebuffer(name);
874 default:
875 UNREACHABLE();
876 return nullptr;
877 }
878}
879
880LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
881{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400882 return getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
Geoff Lang70d0f492015-12-10 17:45:46 -0500883}
884
Martin Radev9d901792016-07-15 15:58:58 +0300885void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
886{
887 LabeledObject *object = getLabeledObject(identifier, name);
888 ASSERT(object != nullptr);
889
890 std::string labelName = GetObjectLabelFromPointer(length, label);
891 object->setLabel(labelName);
Jamie Madill8693bdb2017-09-02 15:32:14 -0400892
893 // TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the
894 // specified object is active until we do this.
895 mGLState.setObjectDirty(identifier);
Martin Radev9d901792016-07-15 15:58:58 +0300896}
897
898void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
899{
900 LabeledObject *object = getLabeledObjectFromPtr(ptr);
901 ASSERT(object != nullptr);
902
903 std::string labelName = GetObjectLabelFromPointer(length, label);
904 object->setLabel(labelName);
905}
906
907void Context::getObjectLabel(GLenum identifier,
908 GLuint name,
909 GLsizei bufSize,
910 GLsizei *length,
911 GLchar *label) const
912{
913 LabeledObject *object = getLabeledObject(identifier, name);
914 ASSERT(object != nullptr);
915
916 const std::string &objectLabel = object->getLabel();
917 GetObjectLabelBase(objectLabel, bufSize, length, label);
918}
919
920void Context::getObjectPtrLabel(const void *ptr,
921 GLsizei bufSize,
922 GLsizei *length,
923 GLchar *label) const
924{
925 LabeledObject *object = getLabeledObjectFromPtr(ptr);
926 ASSERT(object != nullptr);
927
928 const std::string &objectLabel = object->getLabel();
929 GetObjectLabelBase(objectLabel, bufSize, length, label);
930}
931
Jamie Madilldc356042013-07-19 16:36:57 -0400932bool Context::isSampler(GLuint samplerName) const
933{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500934 return mState.mSamplers->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -0400935}
936
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500937void Context::bindArrayBuffer(GLuint bufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000938{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500939 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400940 mGLState.setArrayBufferBinding(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000941}
942
Jiajia Qin9d7d0b12016-11-29 16:30:31 +0800943void Context::bindDrawIndirectBuffer(GLuint bufferHandle)
944{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500945 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400946 mGLState.setDrawIndirectBufferBinding(this, buffer);
Jiajia Qin9d7d0b12016-11-29 16:30:31 +0800947}
948
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500949void Context::bindElementArrayBuffer(GLuint bufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000950{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500951 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400952 mGLState.setElementArrayBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000953}
954
Jamie Madilldedd7b92014-11-05 16:30:36 -0500955void Context::bindTexture(GLenum target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000956{
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500957 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000958
Jamie Madilldedd7b92014-11-05 16:30:36 -0500959 if (handle == 0)
960 {
961 texture = mZeroTextures[target].get();
962 }
963 else
964 {
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500965 texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500966 }
967
968 ASSERT(texture);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400969 mGLState.setSamplerTexture(this, target, texture);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +0000970}
971
Jamie Madill5bf9ff42016-02-01 11:13:03 -0500972void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000973{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500974 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
975 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700976 mGLState.setReadFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000977}
978
Jamie Madill5bf9ff42016-02-01 11:13:03 -0500979void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000980{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500981 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
982 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700983 mGLState.setDrawFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000984}
985
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500986void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -0400987{
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500988 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700989 mGLState.setVertexArrayBinding(vertexArray);
Jamie Madill57a89722013-07-02 11:57:03 -0400990}
991
Shao80957d92017-02-20 21:25:59 +0800992void Context::bindVertexBuffer(GLuint bindingIndex,
993 GLuint bufferHandle,
994 GLintptr offset,
995 GLsizei stride)
996{
997 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400998 mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Shao80957d92017-02-20 21:25:59 +0800999}
1000
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001001void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -04001002{
Geoff Lang76b10c92014-09-05 16:28:14 -04001003 ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -04001004 Sampler *sampler =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001005 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001006 mGLState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04001007}
1008
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001009void Context::bindImageTexture(GLuint unit,
1010 GLuint texture,
1011 GLint level,
1012 GLboolean layered,
1013 GLint layer,
1014 GLenum access,
1015 GLenum format)
1016{
1017 Texture *tex = mState.mTextures->getTexture(texture);
1018 mGLState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
1019}
1020
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001021void Context::bindGenericUniformBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001022{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001023 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001024 mGLState.setGenericUniformBufferBinding(this, buffer);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001025}
1026
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001027void Context::bindIndexedUniformBuffer(GLuint bufferHandle,
1028 GLuint index,
1029 GLintptr offset,
1030 GLsizeiptr size)
shannon.woods%transgaming.com@gtempaccount.com34089352013-04-13 03:36:57 +00001031{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001032 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001033 mGLState.setIndexedUniformBufferBinding(this, index, buffer, offset, size);
shannon.woods%transgaming.com@gtempaccount.com34089352013-04-13 03:36:57 +00001034}
1035
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001036void Context::bindGenericTransformFeedbackBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001037{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001038 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001039 mGLState.getCurrentTransformFeedback()->bindGenericBuffer(this, buffer);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001040}
1041
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001042void Context::bindIndexedTransformFeedbackBuffer(GLuint bufferHandle,
1043 GLuint index,
1044 GLintptr offset,
1045 GLsizeiptr size)
shannon.woods%transgaming.com@gtempaccount.com34089352013-04-13 03:36:57 +00001046{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001047 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001048 mGLState.getCurrentTransformFeedback()->bindIndexedBuffer(this, index, buffer, offset, size);
shannon.woods%transgaming.com@gtempaccount.com34089352013-04-13 03:36:57 +00001049}
1050
Jiajia Qin6eafb042016-12-27 17:04:07 +08001051void Context::bindGenericAtomicCounterBuffer(GLuint bufferHandle)
1052{
1053 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001054 mGLState.setGenericAtomicCounterBufferBinding(this, buffer);
Jiajia Qin6eafb042016-12-27 17:04:07 +08001055}
1056
1057void Context::bindIndexedAtomicCounterBuffer(GLuint bufferHandle,
1058 GLuint index,
1059 GLintptr offset,
1060 GLsizeiptr size)
1061{
1062 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001063 mGLState.setIndexedAtomicCounterBufferBinding(this, index, buffer, offset, size);
Jiajia Qin6eafb042016-12-27 17:04:07 +08001064}
1065
Jiajia Qinf546e7d2017-03-27 14:12:59 +08001066void Context::bindGenericShaderStorageBuffer(GLuint bufferHandle)
1067{
1068 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001069 mGLState.setGenericShaderStorageBufferBinding(this, buffer);
Jiajia Qinf546e7d2017-03-27 14:12:59 +08001070}
1071
1072void Context::bindIndexedShaderStorageBuffer(GLuint bufferHandle,
1073 GLuint index,
1074 GLintptr offset,
1075 GLsizeiptr size)
1076{
1077 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001078 mGLState.setIndexedShaderStorageBufferBinding(this, index, buffer, offset, size);
Jiajia Qinf546e7d2017-03-27 14:12:59 +08001079}
1080
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001081void Context::bindCopyReadBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001082{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001083 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001084 mGLState.setCopyReadBufferBinding(this, buffer);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001085}
1086
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001087void Context::bindCopyWriteBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001088{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001089 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001090 mGLState.setCopyWriteBufferBinding(this, buffer);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001091}
1092
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001093void Context::bindPixelPackBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001094{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001095 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001096 mGLState.setPixelPackBufferBinding(this, buffer);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001097}
1098
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001099void Context::bindPixelUnpackBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001100{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001101 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001102 mGLState.setPixelUnpackBufferBinding(this, buffer);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001103}
1104
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001105void Context::useProgram(GLuint program)
1106{
Jamie Madill6c1f6712017-02-14 19:08:04 -05001107 mGLState.setProgram(this, getProgram(program));
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001108}
1109
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001110void Context::bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001111{
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001112 ASSERT(target == GL_TRANSFORM_FEEDBACK);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001113 TransformFeedback *transformFeedback =
1114 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001115 mGLState.setTransformFeedbackBinding(this, transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -05001116}
1117
Yunchao Hea336b902017-08-02 16:05:21 +08001118void Context::bindProgramPipeline(GLuint pipelineHandle)
1119{
1120 ProgramPipeline *pipeline =
1121 mState.mPipelines->checkProgramPipelineAllocation(mImplementation.get(), pipelineHandle);
1122 mGLState.setProgramPipelineBinding(this, pipeline);
1123}
1124
Jamie Madillf0e04492017-08-26 15:28:42 -04001125void Context::beginQuery(GLenum target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001126{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001127 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001128 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001129
Geoff Lang5aad9672014-09-08 11:10:42 -04001130 // begin query
Jamie Madillf0e04492017-08-26 15:28:42 -04001131 ANGLE_CONTEXT_TRY(queryObject->begin());
Geoff Lang5aad9672014-09-08 11:10:42 -04001132
1133 // set query as active for specified target only if begin succeeded
Jamie Madill4928b7c2017-06-20 12:57:39 -04001134 mGLState.setActiveQuery(this, target, queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001135}
1136
Jamie Madillf0e04492017-08-26 15:28:42 -04001137void Context::endQuery(GLenum target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001138{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001139 Query *queryObject = mGLState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001140 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001141
Jamie Madillf0e04492017-08-26 15:28:42 -04001142 handleError(queryObject->end());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001143
Geoff Lang5aad9672014-09-08 11:10:42 -04001144 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madill4928b7c2017-06-20 12:57:39 -04001145 mGLState.setActiveQuery(this, target, nullptr);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001146}
1147
Jamie Madillf0e04492017-08-26 15:28:42 -04001148void Context::queryCounter(GLuint id, GLenum target)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001149{
1150 ASSERT(target == GL_TIMESTAMP_EXT);
1151
1152 Query *queryObject = getQuery(id, true, target);
1153 ASSERT(queryObject);
1154
Jamie Madillf0e04492017-08-26 15:28:42 -04001155 handleError(queryObject->queryCounter());
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001156}
1157
1158void Context::getQueryiv(GLenum target, GLenum pname, GLint *params)
1159{
1160 switch (pname)
1161 {
1162 case GL_CURRENT_QUERY_EXT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001163 params[0] = mGLState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001164 break;
1165 case GL_QUERY_COUNTER_BITS_EXT:
1166 switch (target)
1167 {
1168 case GL_TIME_ELAPSED_EXT:
1169 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1170 break;
1171 case GL_TIMESTAMP_EXT:
1172 params[0] = getExtensions().queryCounterBitsTimestamp;
1173 break;
1174 default:
1175 UNREACHABLE();
1176 params[0] = 0;
1177 break;
1178 }
1179 break;
1180 default:
1181 UNREACHABLE();
1182 return;
1183 }
1184}
1185
Geoff Lang2186c382016-10-14 10:54:54 -04001186void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001187{
Geoff Lang2186c382016-10-14 10:54:54 -04001188 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001189}
1190
Geoff Lang2186c382016-10-14 10:54:54 -04001191void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001192{
Geoff Lang2186c382016-10-14 10:54:54 -04001193 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001194}
1195
Geoff Lang2186c382016-10-14 10:54:54 -04001196void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001197{
Geoff Lang2186c382016-10-14 10:54:54 -04001198 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001199}
1200
Geoff Lang2186c382016-10-14 10:54:54 -04001201void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001202{
Geoff Lang2186c382016-10-14 10:54:54 -04001203 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001204}
1205
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001206Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001207{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001208 return mState.mFramebuffers->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001209}
1210
Jamie Madill2f348d22017-06-05 10:50:59 -04001211FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001212{
Jamie Madill96a483b2017-06-27 16:49:21 -04001213 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001214}
1215
Jamie Madill2f348d22017-06-05 10:50:59 -04001216Query *Context::getQuery(GLuint handle, bool create, GLenum type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001217{
Jamie Madill96a483b2017-06-27 16:49:21 -04001218 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001219 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001220 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001221 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001222
1223 Query *query = mQueryMap.query(handle);
1224 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001225 {
Jamie Madill96a483b2017-06-27 16:49:21 -04001226 query = new Query(mImplementation->createQuery(type), handle);
1227 query->addRef();
1228 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001229 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001230 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001231}
1232
Geoff Lang70d0f492015-12-10 17:45:46 -05001233Query *Context::getQuery(GLuint handle) const
1234{
Jamie Madill96a483b2017-06-27 16:49:21 -04001235 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001236}
1237
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001238Texture *Context::getTargetTexture(GLenum target) const
1239{
Ian Ewellbda75592016-04-18 17:25:54 -04001240 ASSERT(ValidTextureTarget(this, target) || ValidTextureExternalTarget(this, target));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001241 return mGLState.getTargetTexture(target);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001242}
1243
Geoff Lang76b10c92014-09-05 16:28:14 -04001244Texture *Context::getSamplerTexture(unsigned int sampler, GLenum type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001245{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001246 return mGLState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001247}
1248
Geoff Lang492a7e42014-11-05 13:27:06 -05001249Compiler *Context::getCompiler() const
1250{
Jamie Madill2f348d22017-06-05 10:50:59 -04001251 if (mCompiler.get() == nullptr)
1252 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001253 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001254 }
1255 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001256}
1257
Jamie Madillc1d770e2017-04-13 17:31:24 -04001258void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001259{
1260 switch (pname)
1261 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001262 case GL_SHADER_COMPILER:
1263 *params = GL_TRUE;
1264 break;
1265 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1266 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1267 break;
1268 default:
1269 mGLState.getBooleanv(pname, params);
1270 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001271 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001272}
1273
Jamie Madillc1d770e2017-04-13 17:31:24 -04001274void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001275{
Shannon Woods53a94a82014-06-24 15:20:36 -04001276 // Queries about context capabilities and maximums are answered by Context.
1277 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001278 switch (pname)
1279 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001280 case GL_ALIASED_LINE_WIDTH_RANGE:
1281 params[0] = mCaps.minAliasedLineWidth;
1282 params[1] = mCaps.maxAliasedLineWidth;
1283 break;
1284 case GL_ALIASED_POINT_SIZE_RANGE:
1285 params[0] = mCaps.minAliasedPointSize;
1286 params[1] = mCaps.maxAliasedPointSize;
1287 break;
1288 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1289 ASSERT(mExtensions.textureFilterAnisotropic);
1290 *params = mExtensions.maxTextureAnisotropy;
1291 break;
1292 case GL_MAX_TEXTURE_LOD_BIAS:
1293 *params = mCaps.maxLODBias;
1294 break;
1295
1296 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1297 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1298 {
1299 ASSERT(mExtensions.pathRendering);
1300 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1301 memcpy(params, m, 16 * sizeof(GLfloat));
1302 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001303 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001304
Jamie Madill231c7f52017-04-26 13:45:37 -04001305 default:
1306 mGLState.getFloatv(pname, params);
1307 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001308 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001309}
1310
Jamie Madillc1d770e2017-04-13 17:31:24 -04001311void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001312{
Shannon Woods53a94a82014-06-24 15:20:36 -04001313 // Queries about context capabilities and maximums are answered by Context.
1314 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001315
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001316 switch (pname)
1317 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001318 case GL_MAX_VERTEX_ATTRIBS:
1319 *params = mCaps.maxVertexAttributes;
1320 break;
1321 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1322 *params = mCaps.maxVertexUniformVectors;
1323 break;
1324 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
1325 *params = mCaps.maxVertexUniformComponents;
1326 break;
1327 case GL_MAX_VARYING_VECTORS:
1328 *params = mCaps.maxVaryingVectors;
1329 break;
1330 case GL_MAX_VARYING_COMPONENTS:
1331 *params = mCaps.maxVertexOutputComponents;
1332 break;
1333 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1334 *params = mCaps.maxCombinedTextureImageUnits;
1335 break;
1336 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
1337 *params = mCaps.maxVertexTextureImageUnits;
1338 break;
1339 case GL_MAX_TEXTURE_IMAGE_UNITS:
1340 *params = mCaps.maxTextureImageUnits;
1341 break;
1342 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1343 *params = mCaps.maxFragmentUniformVectors;
1344 break;
1345 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
1346 *params = mCaps.maxFragmentUniformComponents;
1347 break;
1348 case GL_MAX_RENDERBUFFER_SIZE:
1349 *params = mCaps.maxRenderbufferSize;
1350 break;
1351 case GL_MAX_COLOR_ATTACHMENTS_EXT:
1352 *params = mCaps.maxColorAttachments;
1353 break;
1354 case GL_MAX_DRAW_BUFFERS_EXT:
1355 *params = mCaps.maxDrawBuffers;
1356 break;
1357 // case GL_FRAMEBUFFER_BINDING: // now equivalent to
1358 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
1359 case GL_SUBPIXEL_BITS:
1360 *params = 4;
1361 break;
1362 case GL_MAX_TEXTURE_SIZE:
1363 *params = mCaps.max2DTextureSize;
1364 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001365 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
1366 *params = mCaps.maxRectangleTextureSize;
1367 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001368 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1369 *params = mCaps.maxCubeMapTextureSize;
1370 break;
1371 case GL_MAX_3D_TEXTURE_SIZE:
1372 *params = mCaps.max3DTextureSize;
1373 break;
1374 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1375 *params = mCaps.maxArrayTextureLayers;
1376 break;
1377 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1378 *params = mCaps.uniformBufferOffsetAlignment;
1379 break;
1380 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1381 *params = mCaps.maxUniformBufferBindings;
1382 break;
1383 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
1384 *params = mCaps.maxVertexUniformBlocks;
1385 break;
1386 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
1387 *params = mCaps.maxFragmentUniformBlocks;
1388 break;
1389 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1390 *params = mCaps.maxCombinedTextureImageUnits;
1391 break;
1392 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1393 *params = mCaps.maxVertexOutputComponents;
1394 break;
1395 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1396 *params = mCaps.maxFragmentInputComponents;
1397 break;
1398 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1399 *params = mCaps.minProgramTexelOffset;
1400 break;
1401 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1402 *params = mCaps.maxProgramTexelOffset;
1403 break;
1404 case GL_MAJOR_VERSION:
1405 *params = getClientVersion().major;
1406 break;
1407 case GL_MINOR_VERSION:
1408 *params = getClientVersion().minor;
1409 break;
1410 case GL_MAX_ELEMENTS_INDICES:
1411 *params = mCaps.maxElementsIndices;
1412 break;
1413 case GL_MAX_ELEMENTS_VERTICES:
1414 *params = mCaps.maxElementsVertices;
1415 break;
1416 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1417 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1418 break;
1419 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1420 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1421 break;
1422 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1423 *params = mCaps.maxTransformFeedbackSeparateComponents;
1424 break;
1425 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1426 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1427 break;
1428 case GL_MAX_SAMPLES_ANGLE:
1429 *params = mCaps.maxSamples;
1430 break;
1431 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001432 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001433 params[0] = mCaps.maxViewportWidth;
1434 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001435 }
1436 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001437 case GL_COMPRESSED_TEXTURE_FORMATS:
1438 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1439 params);
1440 break;
1441 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1442 *params = mResetStrategy;
1443 break;
1444 case GL_NUM_SHADER_BINARY_FORMATS:
1445 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1446 break;
1447 case GL_SHADER_BINARY_FORMATS:
1448 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1449 break;
1450 case GL_NUM_PROGRAM_BINARY_FORMATS:
1451 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1452 break;
1453 case GL_PROGRAM_BINARY_FORMATS:
1454 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1455 break;
1456 case GL_NUM_EXTENSIONS:
1457 *params = static_cast<GLint>(mExtensionStrings.size());
1458 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001459
Jamie Madill231c7f52017-04-26 13:45:37 -04001460 // GL_KHR_debug
1461 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1462 *params = mExtensions.maxDebugMessageLength;
1463 break;
1464 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1465 *params = mExtensions.maxDebugLoggedMessages;
1466 break;
1467 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1468 *params = mExtensions.maxDebugGroupStackDepth;
1469 break;
1470 case GL_MAX_LABEL_LENGTH:
1471 *params = mExtensions.maxLabelLength;
1472 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001473
Martin Radeve5285d22017-07-14 16:23:53 +03001474 // GL_ANGLE_multiview
1475 case GL_MAX_VIEWS_ANGLE:
1476 *params = mExtensions.maxViews;
1477 break;
1478
Jamie Madill231c7f52017-04-26 13:45:37 -04001479 // GL_EXT_disjoint_timer_query
1480 case GL_GPU_DISJOINT_EXT:
1481 *params = mImplementation->getGPUDisjoint();
1482 break;
1483 case GL_MAX_FRAMEBUFFER_WIDTH:
1484 *params = mCaps.maxFramebufferWidth;
1485 break;
1486 case GL_MAX_FRAMEBUFFER_HEIGHT:
1487 *params = mCaps.maxFramebufferHeight;
1488 break;
1489 case GL_MAX_FRAMEBUFFER_SAMPLES:
1490 *params = mCaps.maxFramebufferSamples;
1491 break;
1492 case GL_MAX_SAMPLE_MASK_WORDS:
1493 *params = mCaps.maxSampleMaskWords;
1494 break;
1495 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1496 *params = mCaps.maxColorTextureSamples;
1497 break;
1498 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1499 *params = mCaps.maxDepthTextureSamples;
1500 break;
1501 case GL_MAX_INTEGER_SAMPLES:
1502 *params = mCaps.maxIntegerSamples;
1503 break;
1504 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1505 *params = mCaps.maxVertexAttribRelativeOffset;
1506 break;
1507 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1508 *params = mCaps.maxVertexAttribBindings;
1509 break;
1510 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1511 *params = mCaps.maxVertexAttribStride;
1512 break;
1513 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
1514 *params = mCaps.maxVertexAtomicCounterBuffers;
1515 break;
1516 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
1517 *params = mCaps.maxVertexAtomicCounters;
1518 break;
1519 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
1520 *params = mCaps.maxVertexImageUniforms;
1521 break;
1522 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
1523 *params = mCaps.maxVertexShaderStorageBlocks;
1524 break;
1525 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
1526 *params = mCaps.maxFragmentAtomicCounterBuffers;
1527 break;
1528 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
1529 *params = mCaps.maxFragmentAtomicCounters;
1530 break;
1531 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
1532 *params = mCaps.maxFragmentImageUniforms;
1533 break;
1534 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
1535 *params = mCaps.maxFragmentShaderStorageBlocks;
1536 break;
1537 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1538 *params = mCaps.minProgramTextureGatherOffset;
1539 break;
1540 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1541 *params = mCaps.maxProgramTextureGatherOffset;
1542 break;
1543 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1544 *params = mCaps.maxComputeWorkGroupInvocations;
1545 break;
1546 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
1547 *params = mCaps.maxComputeUniformBlocks;
1548 break;
1549 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
1550 *params = mCaps.maxComputeTextureImageUnits;
1551 break;
1552 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1553 *params = mCaps.maxComputeSharedMemorySize;
1554 break;
1555 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
1556 *params = mCaps.maxComputeUniformComponents;
1557 break;
1558 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
1559 *params = mCaps.maxComputeAtomicCounterBuffers;
1560 break;
1561 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
1562 *params = mCaps.maxComputeAtomicCounters;
1563 break;
1564 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
1565 *params = mCaps.maxComputeImageUniforms;
1566 break;
1567 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
1568 *params = mCaps.maxCombinedComputeUniformComponents;
1569 break;
1570 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
1571 *params = mCaps.maxComputeShaderStorageBlocks;
1572 break;
1573 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1574 *params = mCaps.maxCombinedShaderOutputResources;
1575 break;
1576 case GL_MAX_UNIFORM_LOCATIONS:
1577 *params = mCaps.maxUniformLocations;
1578 break;
1579 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1580 *params = mCaps.maxAtomicCounterBufferBindings;
1581 break;
1582 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1583 *params = mCaps.maxAtomicCounterBufferSize;
1584 break;
1585 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1586 *params = mCaps.maxCombinedAtomicCounterBuffers;
1587 break;
1588 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1589 *params = mCaps.maxCombinedAtomicCounters;
1590 break;
1591 case GL_MAX_IMAGE_UNITS:
1592 *params = mCaps.maxImageUnits;
1593 break;
1594 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1595 *params = mCaps.maxCombinedImageUniforms;
1596 break;
1597 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1598 *params = mCaps.maxShaderStorageBufferBindings;
1599 break;
1600 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1601 *params = mCaps.maxCombinedShaderStorageBlocks;
1602 break;
1603 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1604 *params = mCaps.shaderStorageBufferOffsetAlignment;
1605 break;
1606 default:
1607 mGLState.getIntegerv(this, pname, params);
1608 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001609 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001610}
1611
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001612void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001613{
Shannon Woods53a94a82014-06-24 15:20:36 -04001614 // Queries about context capabilities and maximums are answered by Context.
1615 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001616 switch (pname)
1617 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001618 case GL_MAX_ELEMENT_INDEX:
1619 *params = mCaps.maxElementIndex;
1620 break;
1621 case GL_MAX_UNIFORM_BLOCK_SIZE:
1622 *params = mCaps.maxUniformBlockSize;
1623 break;
1624 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
1625 *params = mCaps.maxCombinedVertexUniformComponents;
1626 break;
1627 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
1628 *params = mCaps.maxCombinedFragmentUniformComponents;
1629 break;
1630 case GL_MAX_SERVER_WAIT_TIMEOUT:
1631 *params = mCaps.maxServerWaitTimeout;
1632 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001633
Jamie Madill231c7f52017-04-26 13:45:37 -04001634 // GL_EXT_disjoint_timer_query
1635 case GL_TIMESTAMP_EXT:
1636 *params = mImplementation->getTimestamp();
1637 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001638
Jamie Madill231c7f52017-04-26 13:45:37 -04001639 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1640 *params = mCaps.maxShaderStorageBlockSize;
1641 break;
1642 default:
1643 UNREACHABLE();
1644 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001645 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001646}
1647
Geoff Lang70d0f492015-12-10 17:45:46 -05001648void Context::getPointerv(GLenum pname, void **params) const
1649{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001650 mGLState.getPointerv(pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001651}
1652
Martin Radev66fb8202016-07-28 11:45:20 +03001653void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001654{
Shannon Woods53a94a82014-06-24 15:20:36 -04001655 // Queries about context capabilities and maximums are answered by Context.
1656 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001657
1658 GLenum nativeType;
1659 unsigned int numParams;
1660 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1661 ASSERT(queryStatus);
1662
1663 if (nativeType == GL_INT)
1664 {
1665 switch (target)
1666 {
1667 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1668 ASSERT(index < 3u);
1669 *data = mCaps.maxComputeWorkGroupCount[index];
1670 break;
1671 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1672 ASSERT(index < 3u);
1673 *data = mCaps.maxComputeWorkGroupSize[index];
1674 break;
1675 default:
1676 mGLState.getIntegeri_v(target, index, data);
1677 }
1678 }
1679 else
1680 {
1681 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1682 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001683}
1684
Martin Radev66fb8202016-07-28 11:45:20 +03001685void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001686{
Shannon Woods53a94a82014-06-24 15:20:36 -04001687 // Queries about context capabilities and maximums are answered by Context.
1688 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001689
1690 GLenum nativeType;
1691 unsigned int numParams;
1692 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1693 ASSERT(queryStatus);
1694
1695 if (nativeType == GL_INT_64_ANGLEX)
1696 {
1697 mGLState.getInteger64i_v(target, index, data);
1698 }
1699 else
1700 {
1701 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1702 }
1703}
1704
1705void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1706{
1707 // Queries about context capabilities and maximums are answered by Context.
1708 // Queries about current GL state values are answered by State.
1709
1710 GLenum nativeType;
1711 unsigned int numParams;
1712 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1713 ASSERT(queryStatus);
1714
1715 if (nativeType == GL_BOOL)
1716 {
1717 mGLState.getBooleani_v(target, index, data);
1718 }
1719 else
1720 {
1721 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1722 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001723}
1724
He Yunchao010e4db2017-03-03 14:22:06 +08001725void Context::getBufferParameteriv(GLenum target, GLenum pname, GLint *params)
1726{
1727 Buffer *buffer = mGLState.getTargetBuffer(target);
1728 QueryBufferParameteriv(buffer, pname, params);
1729}
1730
1731void Context::getFramebufferAttachmentParameteriv(GLenum target,
1732 GLenum attachment,
1733 GLenum pname,
1734 GLint *params)
1735{
1736 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
1737 QueryFramebufferAttachmentParameteriv(framebuffer, attachment, pname, params);
1738}
1739
1740void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
1741{
1742 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
1743 QueryRenderbufferiv(this, renderbuffer, pname, params);
1744}
1745
1746void Context::getTexParameterfv(GLenum target, GLenum pname, GLfloat *params)
1747{
1748 Texture *texture = getTargetTexture(target);
1749 QueryTexParameterfv(texture, pname, params);
1750}
1751
1752void Context::getTexParameteriv(GLenum target, GLenum pname, GLint *params)
1753{
1754 Texture *texture = getTargetTexture(target);
1755 QueryTexParameteriv(texture, pname, params);
1756}
1757void Context::texParameterf(GLenum target, GLenum pname, GLfloat param)
1758{
1759 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001760 SetTexParameterf(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04001761 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001762}
1763
1764void Context::texParameterfv(GLenum target, GLenum pname, const GLfloat *params)
1765{
1766 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001767 SetTexParameterfv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04001768 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001769}
1770
1771void Context::texParameteri(GLenum target, GLenum pname, GLint param)
1772{
1773 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001774 SetTexParameteri(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04001775 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001776}
1777
1778void Context::texParameteriv(GLenum target, GLenum pname, const GLint *params)
1779{
1780 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001781 SetTexParameteriv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04001782 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001783}
1784
Jamie Madill675fe712016-12-19 13:07:54 -05001785void Context::drawArrays(GLenum mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001786{
Jamie Madill05b35b22017-10-03 09:01:44 -04001787 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001788 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
1789 MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001790}
1791
Jamie Madill675fe712016-12-19 13:07:54 -05001792void Context::drawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04001793{
Jamie Madill05b35b22017-10-03 09:01:44 -04001794 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001795 ANGLE_CONTEXT_TRY(
1796 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
1797 MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback());
Geoff Langf6db0982015-08-25 13:04:00 -04001798}
1799
Jamie Madill876429b2017-04-20 15:46:24 -04001800void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001801{
Jamie Madill05b35b22017-10-03 09:01:44 -04001802 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001803 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04001804}
1805
Jamie Madill675fe712016-12-19 13:07:54 -05001806void Context::drawElementsInstanced(GLenum mode,
1807 GLsizei count,
1808 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04001809 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04001810 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04001811{
Jamie Madill05b35b22017-10-03 09:01:44 -04001812 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001813 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08001814 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04001815}
1816
Jamie Madill675fe712016-12-19 13:07:54 -05001817void Context::drawRangeElements(GLenum mode,
1818 GLuint start,
1819 GLuint end,
1820 GLsizei count,
1821 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04001822 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04001823{
Jamie Madill05b35b22017-10-03 09:01:44 -04001824 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001825 ANGLE_CONTEXT_TRY(
1826 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001827}
1828
Jamie Madill876429b2017-04-20 15:46:24 -04001829void Context::drawArraysIndirect(GLenum mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08001830{
Jamie Madill05b35b22017-10-03 09:01:44 -04001831 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001832 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08001833}
1834
Jamie Madill876429b2017-04-20 15:46:24 -04001835void Context::drawElementsIndirect(GLenum mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08001836{
Jamie Madill05b35b22017-10-03 09:01:44 -04001837 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001838 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08001839}
1840
Jamie Madill675fe712016-12-19 13:07:54 -05001841void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001842{
Jamie Madill675fe712016-12-19 13:07:54 -05001843 handleError(mImplementation->flush());
Geoff Lang129753a2015-01-09 16:52:09 -05001844}
1845
Jamie Madill675fe712016-12-19 13:07:54 -05001846void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05001847{
Jamie Madill675fe712016-12-19 13:07:54 -05001848 handleError(mImplementation->finish());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001849}
1850
Austin Kinross6ee1e782015-05-29 17:05:37 -07001851void Context::insertEventMarker(GLsizei length, const char *marker)
1852{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001853 ASSERT(mImplementation);
1854 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07001855}
1856
1857void Context::pushGroupMarker(GLsizei length, const char *marker)
1858{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001859 ASSERT(mImplementation);
1860 mImplementation->pushGroupMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07001861}
1862
1863void Context::popGroupMarker()
1864{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001865 ASSERT(mImplementation);
1866 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07001867}
1868
Geoff Langd8605522016-04-13 10:19:12 -04001869void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
1870{
1871 Program *programObject = getProgram(program);
1872 ASSERT(programObject);
1873
1874 programObject->bindUniformLocation(location, name);
1875}
1876
Sami Väisänena797e062016-05-12 15:23:40 +03001877void Context::setCoverageModulation(GLenum components)
1878{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001879 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03001880}
1881
Sami Väisänene45e53b2016-05-25 10:36:04 +03001882void Context::loadPathRenderingMatrix(GLenum matrixMode, const GLfloat *matrix)
1883{
1884 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
1885}
1886
1887void Context::loadPathRenderingIdentityMatrix(GLenum matrixMode)
1888{
1889 GLfloat I[16];
1890 angle::Matrix<GLfloat>::setToIdentity(I);
1891
1892 mGLState.loadPathRenderingMatrix(matrixMode, I);
1893}
1894
1895void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
1896{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001897 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001898 if (!pathObj)
1899 return;
1900
1901 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1902 syncRendererState();
1903
1904 mImplementation->stencilFillPath(pathObj, fillMode, mask);
1905}
1906
1907void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
1908{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001909 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001910 if (!pathObj)
1911 return;
1912
1913 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1914 syncRendererState();
1915
1916 mImplementation->stencilStrokePath(pathObj, reference, mask);
1917}
1918
1919void Context::coverFillPath(GLuint path, GLenum coverMode)
1920{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001921 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001922 if (!pathObj)
1923 return;
1924
1925 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1926 syncRendererState();
1927
1928 mImplementation->coverFillPath(pathObj, coverMode);
1929}
1930
1931void Context::coverStrokePath(GLuint path, GLenum coverMode)
1932{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001933 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001934 if (!pathObj)
1935 return;
1936
1937 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1938 syncRendererState();
1939
1940 mImplementation->coverStrokePath(pathObj, coverMode);
1941}
1942
1943void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
1944{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001945 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001946 if (!pathObj)
1947 return;
1948
1949 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1950 syncRendererState();
1951
1952 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
1953}
1954
1955void Context::stencilThenCoverStrokePath(GLuint path,
1956 GLint reference,
1957 GLuint mask,
1958 GLenum coverMode)
1959{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001960 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001961 if (!pathObj)
1962 return;
1963
1964 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1965 syncRendererState();
1966
1967 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
1968}
1969
Sami Väisänend59ca052016-06-21 16:10:00 +03001970void Context::coverFillPathInstanced(GLsizei numPaths,
1971 GLenum pathNameType,
1972 const void *paths,
1973 GLuint pathBase,
1974 GLenum coverMode,
1975 GLenum transformType,
1976 const GLfloat *transformValues)
1977{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001978 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03001979
1980 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1981 syncRendererState();
1982
1983 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
1984}
Sami Väisänen46eaa942016-06-29 10:26:37 +03001985
Sami Väisänend59ca052016-06-21 16:10:00 +03001986void Context::coverStrokePathInstanced(GLsizei numPaths,
1987 GLenum pathNameType,
1988 const void *paths,
1989 GLuint pathBase,
1990 GLenum coverMode,
1991 GLenum transformType,
1992 const GLfloat *transformValues)
1993{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001994 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03001995
1996 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1997 syncRendererState();
1998
1999 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2000 transformValues);
2001}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002002
Sami Väisänend59ca052016-06-21 16:10:00 +03002003void Context::stencilFillPathInstanced(GLsizei numPaths,
2004 GLenum pathNameType,
2005 const void *paths,
2006 GLuint pathBase,
2007 GLenum fillMode,
2008 GLuint mask,
2009 GLenum transformType,
2010 const GLfloat *transformValues)
2011{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002012 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002013
2014 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2015 syncRendererState();
2016
2017 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2018 transformValues);
2019}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002020
Sami Väisänend59ca052016-06-21 16:10:00 +03002021void Context::stencilStrokePathInstanced(GLsizei numPaths,
2022 GLenum pathNameType,
2023 const void *paths,
2024 GLuint pathBase,
2025 GLint reference,
2026 GLuint mask,
2027 GLenum transformType,
2028 const GLfloat *transformValues)
2029{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002030 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002031
2032 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2033 syncRendererState();
2034
2035 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2036 transformValues);
2037}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002038
Sami Väisänend59ca052016-06-21 16:10:00 +03002039void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2040 GLenum pathNameType,
2041 const void *paths,
2042 GLuint pathBase,
2043 GLenum fillMode,
2044 GLuint mask,
2045 GLenum coverMode,
2046 GLenum transformType,
2047 const GLfloat *transformValues)
2048{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002049 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002050
2051 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2052 syncRendererState();
2053
2054 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2055 transformType, transformValues);
2056}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002057
Sami Väisänend59ca052016-06-21 16:10:00 +03002058void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2059 GLenum pathNameType,
2060 const void *paths,
2061 GLuint pathBase,
2062 GLint reference,
2063 GLuint mask,
2064 GLenum coverMode,
2065 GLenum transformType,
2066 const GLfloat *transformValues)
2067{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002068 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002069
2070 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2071 syncRendererState();
2072
2073 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2074 transformType, transformValues);
2075}
2076
Sami Väisänen46eaa942016-06-29 10:26:37 +03002077void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2078{
2079 auto *programObject = getProgram(program);
2080
2081 programObject->bindFragmentInputLocation(location, name);
2082}
2083
2084void Context::programPathFragmentInputGen(GLuint program,
2085 GLint location,
2086 GLenum genMode,
2087 GLint components,
2088 const GLfloat *coeffs)
2089{
2090 auto *programObject = getProgram(program);
2091
Jamie Madillbd044ed2017-06-05 12:59:21 -04002092 programObject->pathFragmentInputGen(this, location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002093}
2094
jchen1015015f72017-03-16 13:54:21 +08002095GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2096{
jchen10fd7c3b52017-03-21 15:36:03 +08002097 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002098 return QueryProgramResourceIndex(programObject, programInterface, name);
2099}
2100
jchen10fd7c3b52017-03-21 15:36:03 +08002101void Context::getProgramResourceName(GLuint program,
2102 GLenum programInterface,
2103 GLuint index,
2104 GLsizei bufSize,
2105 GLsizei *length,
2106 GLchar *name)
2107{
2108 const auto *programObject = getProgram(program);
2109 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2110}
2111
jchen10191381f2017-04-11 13:59:04 +08002112GLint Context::getProgramResourceLocation(GLuint program,
2113 GLenum programInterface,
2114 const GLchar *name)
2115{
2116 const auto *programObject = getProgram(program);
2117 return QueryProgramResourceLocation(programObject, programInterface, name);
2118}
2119
jchen10880683b2017-04-12 16:21:55 +08002120void Context::getProgramResourceiv(GLuint program,
2121 GLenum programInterface,
2122 GLuint index,
2123 GLsizei propCount,
2124 const GLenum *props,
2125 GLsizei bufSize,
2126 GLsizei *length,
2127 GLint *params)
2128{
2129 const auto *programObject = getProgram(program);
2130 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2131 length, params);
2132}
2133
jchen10d9cd7b72017-08-30 15:04:25 +08002134void Context::getProgramInterfaceiv(GLuint program,
2135 GLenum programInterface,
2136 GLenum pname,
2137 GLint *params)
2138{
2139 const auto *programObject = getProgram(program);
2140 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2141}
2142
Jamie Madill71c88b32017-09-14 22:20:29 -04002143void Context::handleError(const Error &error)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002144{
Geoff Langda5777c2014-07-11 09:52:58 -04002145 if (error.isError())
2146 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002147 GLenum code = error.getCode();
2148 mErrors.insert(code);
2149 if (code == GL_OUT_OF_MEMORY && getWorkarounds().loseContextOnOutOfMemory)
2150 {
2151 markContextLost();
2152 }
Geoff Lang70d0f492015-12-10 17:45:46 -05002153
2154 if (!error.getMessage().empty())
2155 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002156 auto *debug = &mGLState.getDebug();
2157 debug->insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, error.getID(),
2158 GL_DEBUG_SEVERITY_HIGH, error.getMessage());
Geoff Lang70d0f492015-12-10 17:45:46 -05002159 }
Geoff Langda5777c2014-07-11 09:52:58 -04002160 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002161}
2162
2163// Get one of the recorded errors and clear its flag, if any.
2164// [OpenGL ES 2.0.24] section 2.5 page 13.
2165GLenum Context::getError()
2166{
Geoff Langda5777c2014-07-11 09:52:58 -04002167 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002168 {
Geoff Langda5777c2014-07-11 09:52:58 -04002169 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002170 }
Geoff Langda5777c2014-07-11 09:52:58 -04002171 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002172 {
Geoff Langda5777c2014-07-11 09:52:58 -04002173 GLenum error = *mErrors.begin();
2174 mErrors.erase(mErrors.begin());
2175 return error;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002176 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002177}
2178
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002179// NOTE: this function should not assume that this context is current!
2180void Context::markContextLost()
2181{
2182 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002183 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002184 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002185 mContextLostForced = true;
2186 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002187 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002188}
2189
2190bool Context::isContextLost()
2191{
2192 return mContextLost;
2193}
2194
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002195GLenum Context::getResetStatus()
2196{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002197 // Even if the application doesn't want to know about resets, we want to know
2198 // as it will allow us to skip all the calls.
2199 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002200 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002201 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002202 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002203 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002204 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002205
2206 // EXT_robustness, section 2.6: If the reset notification behavior is
2207 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2208 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2209 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002210 }
2211
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002212 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2213 // status should be returned at least once, and GL_NO_ERROR should be returned
2214 // once the device has finished resetting.
2215 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002216 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002217 ASSERT(mResetStatus == GL_NO_ERROR);
2218 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002219
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002220 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002221 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002222 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002223 }
2224 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002225 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002226 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002227 // If markContextLost was used to mark the context lost then
2228 // assume that is not recoverable, and continue to report the
2229 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002230 mResetStatus = mImplementation->getResetStatus();
2231 }
Jamie Madill893ab082014-05-16 16:56:10 -04002232
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002233 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002234}
2235
2236bool Context::isResetNotificationEnabled()
2237{
2238 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2239}
2240
Corentin Walleze3b10e82015-05-20 11:06:25 -04002241const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002242{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002243 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002244}
2245
2246EGLenum Context::getClientType() const
2247{
2248 return mClientType;
2249}
2250
2251EGLenum Context::getRenderBuffer() const
2252{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002253 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2254 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002255 {
2256 return EGL_NONE;
2257 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002258
2259 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(GL_BACK);
2260 ASSERT(backAttachment != nullptr);
2261 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002262}
2263
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002264VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002265{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002266 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002267 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2268 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002269 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002270 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2271 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002272
Jamie Madill96a483b2017-06-27 16:49:21 -04002273 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002274 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002275
2276 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002277}
2278
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002279TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002280{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002281 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002282 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2283 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002284 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002285 transformFeedback =
2286 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002287 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002288 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002289 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002290
2291 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002292}
2293
2294bool Context::isVertexArrayGenerated(GLuint vertexArray)
2295{
Jamie Madill96a483b2017-06-27 16:49:21 -04002296 ASSERT(mVertexArrayMap.contains(0));
2297 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002298}
2299
2300bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2301{
Jamie Madill96a483b2017-06-27 16:49:21 -04002302 ASSERT(mTransformFeedbackMap.contains(0));
2303 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002304}
2305
Shannon Woods53a94a82014-06-24 15:20:36 -04002306void Context::detachTexture(GLuint texture)
2307{
2308 // Simple pass-through to State's detachTexture method, as textures do not require
2309 // allocation map management either here or in the resource manager at detach time.
2310 // Zero textures are held by the Context, and we don't attempt to request them from
2311 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002312 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002313}
2314
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002315void Context::detachBuffer(GLuint buffer)
2316{
Yuly Novikov5807a532015-12-03 13:01:22 -05002317 // Simple pass-through to State's detachBuffer method, since
2318 // only buffer attachments to container objects that are bound to the current context
2319 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002320
Yuly Novikov5807a532015-12-03 13:01:22 -05002321 // [OpenGL ES 3.2] section 5.1.2 page 45:
2322 // Attachments to unbound container objects, such as
2323 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2324 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002325 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002326}
2327
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002328void Context::detachFramebuffer(GLuint framebuffer)
2329{
Shannon Woods53a94a82014-06-24 15:20:36 -04002330 // Framebuffer detachment is handled by Context, because 0 is a valid
2331 // Framebuffer object, and a pointer to it must be passed from Context
2332 // to State at binding time.
2333
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002334 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002335 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2336 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2337 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002338
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002339 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002340 {
2341 bindReadFramebuffer(0);
2342 }
2343
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002344 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002345 {
2346 bindDrawFramebuffer(0);
2347 }
2348}
2349
2350void Context::detachRenderbuffer(GLuint renderbuffer)
2351{
Jamie Madilla02315b2017-02-23 14:14:47 -05002352 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002353}
2354
Jamie Madill57a89722013-07-02 11:57:03 -04002355void Context::detachVertexArray(GLuint vertexArray)
2356{
Jamie Madill77a72f62015-04-14 11:18:32 -04002357 // Vertex array detachment is handled by Context, because 0 is a valid
2358 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002359 // binding time.
2360
Jamie Madill57a89722013-07-02 11:57:03 -04002361 // [OpenGL ES 3.0.2] section 2.10 page 43:
2362 // If a vertex array object that is currently bound is deleted, the binding
2363 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002364 if (mGLState.removeVertexArrayBinding(vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002365 {
2366 bindVertexArray(0);
2367 }
2368}
2369
Geoff Langc8058452014-02-03 12:04:11 -05002370void Context::detachTransformFeedback(GLuint transformFeedback)
2371{
Corentin Walleza2257da2016-04-19 16:43:12 -04002372 // Transform feedback detachment is handled by Context, because 0 is a valid
2373 // transform feedback, and a pointer to it must be passed from Context to State at
2374 // binding time.
2375
2376 // The OpenGL specification doesn't mention what should happen when the currently bound
2377 // transform feedback object is deleted. Since it is a container object, we treat it like
2378 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002379 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002380 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002381 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002382 }
Geoff Langc8058452014-02-03 12:04:11 -05002383}
2384
Jamie Madilldc356042013-07-19 16:36:57 -04002385void Context::detachSampler(GLuint sampler)
2386{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002387 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002388}
2389
Yunchao Hea336b902017-08-02 16:05:21 +08002390void Context::detachProgramPipeline(GLuint pipeline)
2391{
2392 mGLState.detachProgramPipeline(this, pipeline);
2393}
2394
Jamie Madill3ef140a2017-08-26 23:11:21 -04002395void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002396{
Shaodde78e82017-05-22 14:13:27 +08002397 mGLState.setVertexAttribDivisor(this, index, divisor);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002398}
2399
Jamie Madille29d1672013-07-19 16:36:57 -04002400void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2401{
Geoff Langc1984ed2016-10-07 12:41:00 -04002402 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002403 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002404 SetSamplerParameteri(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002405 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002406}
Jamie Madille29d1672013-07-19 16:36:57 -04002407
Geoff Langc1984ed2016-10-07 12:41:00 -04002408void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2409{
2410 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002411 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002412 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002413 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002414}
2415
2416void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2417{
Geoff Langc1984ed2016-10-07 12:41:00 -04002418 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002419 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002420 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002421 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002422}
2423
Geoff Langc1984ed2016-10-07 12:41:00 -04002424void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002425{
Geoff Langc1984ed2016-10-07 12:41:00 -04002426 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002427 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002428 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002429 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002430}
2431
Geoff Langc1984ed2016-10-07 12:41:00 -04002432void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002433{
Geoff Langc1984ed2016-10-07 12:41:00 -04002434 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002435 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002436 QuerySamplerParameteriv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002437 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002438}
Jamie Madill9675b802013-07-19 16:36:59 -04002439
Geoff Langc1984ed2016-10-07 12:41:00 -04002440void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2441{
2442 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002443 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002444 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002445 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002446}
2447
Olli Etuahof0fee072016-03-30 15:11:58 +03002448void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2449{
2450 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002451 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002452}
2453
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002454void Context::initRendererString()
2455{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002456 std::ostringstream rendererString;
2457 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002458 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002459 rendererString << ")";
2460
Geoff Langcec35902014-04-16 10:52:36 -04002461 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002462}
2463
Geoff Langc339c4e2016-11-29 10:37:36 -05002464void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002465{
Geoff Langc339c4e2016-11-29 10:37:36 -05002466 const Version &clientVersion = getClientVersion();
2467
2468 std::ostringstream versionString;
2469 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2470 << ANGLE_VERSION_STRING << ")";
2471 mVersionString = MakeStaticString(versionString.str());
2472
2473 std::ostringstream shadingLanguageVersionString;
2474 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2475 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2476 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2477 << ")";
2478 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002479}
2480
Geoff Langcec35902014-04-16 10:52:36 -04002481void Context::initExtensionStrings()
2482{
Geoff Langc339c4e2016-11-29 10:37:36 -05002483 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2484 std::ostringstream combinedStringStream;
2485 std::copy(strings.begin(), strings.end(),
2486 std::ostream_iterator<const char *>(combinedStringStream, " "));
2487 return MakeStaticString(combinedStringStream.str());
2488 };
2489
2490 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002491 for (const auto &extensionString : mExtensions.getStrings())
2492 {
2493 mExtensionStrings.push_back(MakeStaticString(extensionString));
2494 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002495 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002496
Bryan Bernhart58806562017-01-05 13:09:31 -08002497 const gl::Extensions &nativeExtensions = mImplementation->getNativeExtensions();
2498
Geoff Langc339c4e2016-11-29 10:37:36 -05002499 mRequestableExtensionStrings.clear();
2500 for (const auto &extensionInfo : GetExtensionInfoMap())
2501 {
2502 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08002503 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
2504 nativeExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002505 {
2506 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
2507 }
2508 }
2509 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002510}
2511
Geoff Langc339c4e2016-11-29 10:37:36 -05002512const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04002513{
Geoff Langc339c4e2016-11-29 10:37:36 -05002514 switch (name)
2515 {
2516 case GL_VENDOR:
2517 return reinterpret_cast<const GLubyte *>("Google Inc.");
2518
2519 case GL_RENDERER:
2520 return reinterpret_cast<const GLubyte *>(mRendererString);
2521
2522 case GL_VERSION:
2523 return reinterpret_cast<const GLubyte *>(mVersionString);
2524
2525 case GL_SHADING_LANGUAGE_VERSION:
2526 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
2527
2528 case GL_EXTENSIONS:
2529 return reinterpret_cast<const GLubyte *>(mExtensionString);
2530
2531 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2532 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
2533
2534 default:
2535 UNREACHABLE();
2536 return nullptr;
2537 }
Geoff Langcec35902014-04-16 10:52:36 -04002538}
2539
Geoff Langc339c4e2016-11-29 10:37:36 -05002540const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04002541{
Geoff Langc339c4e2016-11-29 10:37:36 -05002542 switch (name)
2543 {
2544 case GL_EXTENSIONS:
2545 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
2546
2547 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2548 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
2549
2550 default:
2551 UNREACHABLE();
2552 return nullptr;
2553 }
Geoff Langcec35902014-04-16 10:52:36 -04002554}
2555
2556size_t Context::getExtensionStringCount() const
2557{
2558 return mExtensionStrings.size();
2559}
2560
Geoff Lang111a99e2017-10-17 10:58:41 -04002561bool Context::isExtensionRequestable(const char *name)
2562{
2563 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2564 auto extension = extensionInfos.find(name);
2565
2566 const Extensions &nativeExtensions = mImplementation->getNativeExtensions();
2567 return extension != extensionInfos.end() && extension->second.Requestable &&
2568 nativeExtensions.*(extension->second.ExtensionsMember);
2569}
2570
Geoff Langc339c4e2016-11-29 10:37:36 -05002571void Context::requestExtension(const char *name)
2572{
2573 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2574 ASSERT(extensionInfos.find(name) != extensionInfos.end());
2575 const auto &extension = extensionInfos.at(name);
2576 ASSERT(extension.Requestable);
Geoff Lang111a99e2017-10-17 10:58:41 -04002577 ASSERT(mImplementation->getNativeExtensions().*(extension.ExtensionsMember));
Geoff Langc339c4e2016-11-29 10:37:36 -05002578
2579 if (mExtensions.*(extension.ExtensionsMember))
2580 {
2581 // Extension already enabled
2582 return;
2583 }
2584
2585 mExtensions.*(extension.ExtensionsMember) = true;
2586 updateCaps();
2587 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08002588
Jamie Madill2f348d22017-06-05 10:50:59 -04002589 // Release the shader compiler so it will be re-created with the requested extensions enabled.
2590 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04002591
Jamie Madill81c2e252017-09-09 23:32:46 -04002592 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
2593 // sampleable.
2594 mState.mTextures->signalAllTexturesDirty();
Geoff Lang9aded172017-04-05 11:07:56 -04002595 for (auto &zeroTexture : mZeroTextures)
2596 {
Jamie Madill05b35b22017-10-03 09:01:44 -04002597 zeroTexture.second->signalDirty(InitState::Initialized);
Geoff Lang9aded172017-04-05 11:07:56 -04002598 }
2599
2600 mState.mFramebuffers->invalidateFramebufferComplenessCache();
Geoff Langc339c4e2016-11-29 10:37:36 -05002601}
2602
2603size_t Context::getRequestableExtensionStringCount() const
2604{
2605 return mRequestableExtensionStrings.size();
2606}
2607
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002608void Context::beginTransformFeedback(GLenum primitiveMode)
2609{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002610 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002611 ASSERT(transformFeedback != nullptr);
2612 ASSERT(!transformFeedback->isPaused());
2613
Jamie Madill6c1f6712017-02-14 19:08:04 -05002614 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002615}
2616
2617bool Context::hasActiveTransformFeedback(GLuint program) const
2618{
2619 for (auto pair : mTransformFeedbackMap)
2620 {
2621 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
2622 {
2623 return true;
2624 }
2625 }
2626 return false;
2627}
2628
Geoff Langb433e872017-10-05 14:01:47 -04002629void Context::initCaps(const egl::DisplayExtensions &displayExtensions, bool robustResourceInit)
Geoff Lang493daf52014-07-03 13:38:44 -04002630{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002631 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04002632
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002633 mExtensions = mImplementation->getNativeExtensions();
Geoff Lang493daf52014-07-03 13:38:44 -04002634
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002635 mLimitations = mImplementation->getNativeLimitations();
Austin Kinross02df7962015-07-01 10:03:42 -07002636
Geoff Langeb66a6e2016-10-31 13:06:12 -04002637 if (getClientVersion() < Version(3, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002638 {
2639 // Disable ES3+ extensions
Jamie Madill231c7f52017-04-26 13:45:37 -04002640 mExtensions.colorBufferFloat = false;
Geoff Langb66a9092016-05-16 15:59:14 -04002641 mExtensions.eglImageExternalEssl3 = false;
Vincent Lang25ab4512016-05-13 18:13:59 +02002642 mExtensions.textureNorm16 = false;
Martin Radev137032d2017-07-13 10:11:12 +03002643 mExtensions.multiview = false;
2644 mExtensions.maxViews = 1u;
Geoff Lang493daf52014-07-03 13:38:44 -04002645 }
2646
Geoff Langeb66a6e2016-10-31 13:06:12 -04002647 if (getClientVersion() > Version(2, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002648 {
2649 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
Jamie Madill231c7f52017-04-26 13:45:37 -04002650 // mExtensions.sRGB = false;
Geoff Lang493daf52014-07-03 13:38:44 -04002651 }
2652
Jamie Madill00ed7a12016-05-19 13:13:38 -04002653 // Some extensions are always available because they are implemented in the GL layer.
Jamie Madill231c7f52017-04-26 13:45:37 -04002654 mExtensions.bindUniformLocation = true;
2655 mExtensions.vertexArrayObject = true;
Geoff Langf41a7152016-09-19 15:11:17 -04002656 mExtensions.bindGeneratesResource = true;
Geoff Langfeb8c682017-02-13 16:07:35 -05002657 mExtensions.clientArrays = true;
Geoff Langc339c4e2016-11-29 10:37:36 -05002658 mExtensions.requestExtension = true;
Jamie Madill00ed7a12016-05-19 13:13:38 -04002659
2660 // Enable the no error extension if the context was created with the flag.
2661 mExtensions.noError = mSkipValidation;
2662
Corentin Wallezccab69d2017-01-27 16:57:15 -05002663 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Corentin Wallezc295e512017-01-27 17:47:50 -05002664 mExtensions.surfacelessContext = displayExtensions.surfacelessContext;
Corentin Wallezccab69d2017-01-27 16:57:15 -05002665
Geoff Lang70d0f492015-12-10 17:45:46 -05002666 // Explicitly enable GL_KHR_debug
2667 mExtensions.debug = true;
2668 mExtensions.maxDebugMessageLength = 1024;
2669 mExtensions.maxDebugLoggedMessages = 1024;
2670 mExtensions.maxDebugGroupStackDepth = 1024;
2671 mExtensions.maxLabelLength = 1024;
2672
Geoff Langff5b2d52016-09-07 11:32:23 -04002673 // Explicitly enable GL_ANGLE_robust_client_memory
2674 mExtensions.robustClientMemory = true;
2675
Jamie Madille08a1d32017-03-07 17:24:06 -05002676 // Determine robust resource init availability from EGL.
Geoff Langb433e872017-10-05 14:01:47 -04002677 mExtensions.robustResourceInitialization = robustResourceInit;
Jamie Madille08a1d32017-03-07 17:24:06 -05002678
Jiajia Qin8a7b3a02017-08-25 16:05:48 +08002679 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
2680 // supports it.
2681 mExtensions.robustBufferAccessBehavior =
2682 mRobustAccess && mExtensions.robustBufferAccessBehavior;
2683
Jamie Madillc43be722017-07-13 16:22:14 -04002684 // Enable the cache control query unconditionally.
2685 mExtensions.programCacheControl = true;
2686
Geoff Lang301d1612014-07-09 10:34:37 -04002687 // Apply implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04002688 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002689
Jamie Madill0f80ed82017-09-19 00:24:56 -04002690 if (getClientVersion() < ES_3_1)
2691 {
2692 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
2693 }
2694 else
2695 {
2696 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
2697 }
Geoff Lang301d1612014-07-09 10:34:37 -04002698
Jamie Madill0f80ed82017-09-19 00:24:56 -04002699 LimitCap(&mCaps.maxVertexUniformBlocks, IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
2700 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
2701 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
2702
2703 // Limit textures as well, so we can use fast bitsets with texture bindings.
2704 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
2705 LimitCap(&mCaps.maxVertexTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
2706 LimitCap(&mCaps.maxTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04002707
Jiawei Shaodb342272017-09-27 10:21:45 +08002708 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
2709
Geoff Langc287ea62016-09-16 14:46:51 -04002710 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002711 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04002712 for (const auto &extensionInfo : GetExtensionInfoMap())
2713 {
2714 // If this context is for WebGL, disable all enableable extensions
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002715 if (mWebGLContext && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04002716 {
2717 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
2718 }
2719 }
2720
2721 // Generate texture caps
2722 updateCaps();
2723}
2724
2725void Context::updateCaps()
2726{
Geoff Lang900013c2014-07-07 11:32:19 -04002727 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002728 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04002729
Jamie Madill7b62cf92017-11-02 15:20:49 -04002730 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04002731 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04002732 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04002733 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04002734
Geoff Lang0d8b7242015-09-09 14:56:53 -04002735 // Update the format caps based on the client version and extensions.
2736 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
2737 // ES3.
2738 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002739 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002740 formatCaps.renderable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002741 formatCaps.renderable && formatInfo.renderSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002742 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002743 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04002744
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002745 // OpenGL ES does not support multisampling with non-rendererable formats
2746 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Olli Etuaho50c562d2017-06-06 14:43:30 +03002747 if (!formatCaps.renderable ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002748 (getClientVersion() < ES_3_1 &&
2749 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04002750 {
Geoff Langd87878e2014-09-19 15:42:59 -04002751 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04002752 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03002753 else
2754 {
2755 // We may have limited the max samples for some required renderbuffer formats due to
2756 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
2757 GLuint formatMaxSamples = formatCaps.getMaxSamples();
2758
2759 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
2760 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
2761 // exception of signed and unsigned integer formats."
2762 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
2763 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
2764 {
2765 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
2766 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
2767 }
2768
2769 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
2770 if (getClientVersion() >= ES_3_1)
2771 {
2772 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
2773 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
2774 // the exception that the signed and unsigned integer formats are required only to
2775 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
2776 // multisamples, which must be at least one."
2777 if (formatInfo.componentType == GL_INT ||
2778 formatInfo.componentType == GL_UNSIGNED_INT)
2779 {
2780 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
2781 }
2782
2783 // GLES 3.1 section 19.3.1.
2784 if (formatCaps.texturable)
2785 {
2786 if (formatInfo.depthBits > 0)
2787 {
2788 mCaps.maxDepthTextureSamples =
2789 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
2790 }
2791 else if (formatInfo.redBits > 0)
2792 {
2793 mCaps.maxColorTextureSamples =
2794 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
2795 }
2796 }
2797 }
2798 }
Geoff Langd87878e2014-09-19 15:42:59 -04002799
2800 if (formatCaps.texturable && formatInfo.compressed)
2801 {
Geoff Langca271392017-04-05 12:30:00 -04002802 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04002803 }
2804
Geoff Langca271392017-04-05 12:30:00 -04002805 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04002806 }
Jamie Madill32447362017-06-28 14:53:52 -04002807
2808 // If program binary is disabled, blank out the memory cache pointer.
2809 if (!mImplementation->getNativeExtensions().getProgramBinary)
2810 {
2811 mMemoryProgramCache = nullptr;
2812 }
Geoff Lang493daf52014-07-03 13:38:44 -04002813}
2814
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002815void Context::initWorkarounds()
2816{
Jamie Madill761b02c2017-06-23 16:27:06 -04002817 // Apply back-end workarounds.
2818 mImplementation->applyNativeWorkarounds(&mWorkarounds);
2819
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002820 // Lose the context upon out of memory error if the application is
2821 // expecting to watch for those events.
2822 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2823}
2824
Jamie Madill05b35b22017-10-03 09:01:44 -04002825Error Context::prepareForDraw()
2826{
2827 syncRendererState();
Jamie Madilla59fc192017-11-02 12:57:58 -04002828
2829 if (isRobustResourceInitEnabled())
2830 {
2831 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
2832 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
2833 }
2834
Jamie Madill05b35b22017-10-03 09:01:44 -04002835 return NoError();
2836}
2837
Jamie Madill1b94d432015-08-07 13:23:23 -04002838void Context::syncRendererState()
2839{
Jamie Madill7d1f5c62017-09-02 15:32:15 -04002840 mGLState.syncDirtyObjects(this);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002841 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
Jamie Madillfe548342017-06-19 11:13:24 -04002842 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002843 mGLState.clearDirtyBits();
Jamie Madill1b94d432015-08-07 13:23:23 -04002844}
2845
Jamie Madillad9f24e2016-02-12 09:27:24 -05002846void Context::syncRendererState(const State::DirtyBits &bitMask,
2847 const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04002848{
Jamie Madill7d1f5c62017-09-02 15:32:15 -04002849 mGLState.syncDirtyObjects(this, objectMask);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002850 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madillfe548342017-06-19 11:13:24 -04002851 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002852 mGLState.clearDirtyBits(dirtyBits);
Jamie Madill1b94d432015-08-07 13:23:23 -04002853}
Jamie Madillc29968b2016-01-20 11:17:23 -05002854
2855void Context::blitFramebuffer(GLint srcX0,
2856 GLint srcY0,
2857 GLint srcX1,
2858 GLint srcY1,
2859 GLint dstX0,
2860 GLint dstY0,
2861 GLint dstX1,
2862 GLint dstY1,
2863 GLbitfield mask,
2864 GLenum filter)
2865{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002866 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002867 ASSERT(drawFramebuffer);
2868
2869 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
2870 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
2871
Jamie Madillad9f24e2016-02-12 09:27:24 -05002872 syncStateForBlit();
Jamie Madillc29968b2016-01-20 11:17:23 -05002873
Jamie Madillc564c072017-06-01 12:45:42 -04002874 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002875}
Jamie Madillc29968b2016-01-20 11:17:23 -05002876
2877void Context::clear(GLbitfield mask)
2878{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002879 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002880 handleError(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05002881}
2882
2883void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
2884{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002885 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002886 handleError(mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002887}
2888
2889void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
2890{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002891 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002892 handleError(mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002893}
2894
2895void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
2896{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002897 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002898 handleError(mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002899}
2900
2901void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
2902{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002903 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002904 ASSERT(framebufferObject);
2905
2906 // If a buffer is not present, the clear has no effect
2907 if (framebufferObject->getDepthbuffer() == nullptr &&
2908 framebufferObject->getStencilbuffer() == nullptr)
2909 {
2910 return;
2911 }
2912
Jamie Madillad9f24e2016-02-12 09:27:24 -05002913 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002914 handleError(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05002915}
2916
2917void Context::readPixels(GLint x,
2918 GLint y,
2919 GLsizei width,
2920 GLsizei height,
2921 GLenum format,
2922 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002923 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05002924{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04002925 if (width == 0 || height == 0)
2926 {
2927 return;
2928 }
2929
Jamie Madillad9f24e2016-02-12 09:27:24 -05002930 syncStateForReadPixels();
Jamie Madillc29968b2016-01-20 11:17:23 -05002931
Jamie Madillb6664922017-07-25 12:55:04 -04002932 Framebuffer *readFBO = mGLState.getReadFramebuffer();
2933 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05002934
2935 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04002936 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05002937}
2938
2939void Context::copyTexImage2D(GLenum target,
2940 GLint level,
2941 GLenum internalformat,
2942 GLint x,
2943 GLint y,
2944 GLsizei width,
2945 GLsizei height,
2946 GLint border)
2947{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002948 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002949 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002950
Jamie Madillc29968b2016-01-20 11:17:23 -05002951 Rectangle sourceArea(x, y, width, height);
2952
Jamie Madill05b35b22017-10-03 09:01:44 -04002953 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002954 Texture *texture =
2955 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05002956 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05002957}
2958
2959void Context::copyTexSubImage2D(GLenum target,
2960 GLint level,
2961 GLint xoffset,
2962 GLint yoffset,
2963 GLint x,
2964 GLint y,
2965 GLsizei width,
2966 GLsizei height)
2967{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04002968 if (width == 0 || height == 0)
2969 {
2970 return;
2971 }
2972
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002973 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002974 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002975
Jamie Madillc29968b2016-01-20 11:17:23 -05002976 Offset destOffset(xoffset, yoffset, 0);
2977 Rectangle sourceArea(x, y, width, height);
2978
Jamie Madill05b35b22017-10-03 09:01:44 -04002979 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002980 Texture *texture =
2981 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05002982 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05002983}
2984
2985void Context::copyTexSubImage3D(GLenum target,
2986 GLint level,
2987 GLint xoffset,
2988 GLint yoffset,
2989 GLint zoffset,
2990 GLint x,
2991 GLint y,
2992 GLsizei width,
2993 GLsizei height)
2994{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04002995 if (width == 0 || height == 0)
2996 {
2997 return;
2998 }
2999
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003000 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003001 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003002
Jamie Madillc29968b2016-01-20 11:17:23 -05003003 Offset destOffset(xoffset, yoffset, zoffset);
3004 Rectangle sourceArea(x, y, width, height);
3005
Jamie Madill05b35b22017-10-03 09:01:44 -04003006 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3007 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003008 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003009}
3010
3011void Context::framebufferTexture2D(GLenum target,
3012 GLenum attachment,
3013 GLenum textarget,
3014 GLuint texture,
3015 GLint level)
3016{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003017 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003018 ASSERT(framebuffer);
3019
3020 if (texture != 0)
3021 {
3022 Texture *textureObj = getTexture(texture);
3023
3024 ImageIndex index = ImageIndex::MakeInvalid();
3025
3026 if (textarget == GL_TEXTURE_2D)
3027 {
3028 index = ImageIndex::Make2D(level);
3029 }
Corentin Wallez13c0dd42017-07-04 18:27:01 -04003030 else if (textarget == GL_TEXTURE_RECTANGLE_ANGLE)
3031 {
3032 index = ImageIndex::MakeRectangle(level);
3033 }
JiangYizhoubddc46b2016-12-09 09:50:51 +08003034 else if (textarget == GL_TEXTURE_2D_MULTISAMPLE)
3035 {
3036 ASSERT(level == 0);
3037 index = ImageIndex::Make2DMultisample();
3038 }
Jamie Madillc29968b2016-01-20 11:17:23 -05003039 else
3040 {
3041 ASSERT(IsCubeMapTextureTarget(textarget));
3042 index = ImageIndex::MakeCube(textarget, level);
3043 }
3044
Jamie Madilla02315b2017-02-23 14:14:47 -05003045 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003046 }
3047 else
3048 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003049 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003050 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003051
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003052 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003053}
3054
3055void Context::framebufferRenderbuffer(GLenum target,
3056 GLenum attachment,
3057 GLenum renderbuffertarget,
3058 GLuint renderbuffer)
3059{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003060 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003061 ASSERT(framebuffer);
3062
3063 if (renderbuffer != 0)
3064 {
3065 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003066
3067 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex::MakeInvalid(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003068 renderbufferObject);
3069 }
3070 else
3071 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003072 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003073 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003074
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003075 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003076}
3077
3078void Context::framebufferTextureLayer(GLenum target,
3079 GLenum attachment,
3080 GLuint texture,
3081 GLint level,
3082 GLint layer)
3083{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003084 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003085 ASSERT(framebuffer);
3086
3087 if (texture != 0)
3088 {
3089 Texture *textureObject = getTexture(texture);
3090
3091 ImageIndex index = ImageIndex::MakeInvalid();
3092
3093 if (textureObject->getTarget() == GL_TEXTURE_3D)
3094 {
3095 index = ImageIndex::Make3D(level, layer);
3096 }
3097 else
3098 {
3099 ASSERT(textureObject->getTarget() == GL_TEXTURE_2D_ARRAY);
3100 index = ImageIndex::Make2DArray(level, layer);
3101 }
3102
Jamie Madilla02315b2017-02-23 14:14:47 -05003103 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003104 }
3105 else
3106 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003107 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003108 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003109
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003110 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003111}
3112
Martin Radev137032d2017-07-13 10:11:12 +03003113void Context::framebufferTextureMultiviewLayeredANGLE(GLenum target,
3114 GLenum attachment,
3115 GLuint texture,
3116 GLint level,
3117 GLint baseViewIndex,
3118 GLsizei numViews)
3119{
Martin Radev82ef7742017-08-08 17:44:58 +03003120 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3121 ASSERT(framebuffer);
3122
3123 if (texture != 0)
3124 {
3125 Texture *textureObj = getTexture(texture);
3126
Martin Radev18b75ba2017-08-15 15:50:40 +03003127 ImageIndex index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
Martin Radev82ef7742017-08-08 17:44:58 +03003128 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3129 numViews, baseViewIndex);
3130 }
3131 else
3132 {
3133 framebuffer->resetAttachment(this, attachment);
3134 }
3135
3136 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003137}
3138
3139void Context::framebufferTextureMultiviewSideBySideANGLE(GLenum target,
3140 GLenum attachment,
3141 GLuint texture,
3142 GLint level,
3143 GLsizei numViews,
3144 const GLint *viewportOffsets)
3145{
Martin Radev5dae57b2017-07-14 16:15:55 +03003146 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3147 ASSERT(framebuffer);
3148
3149 if (texture != 0)
3150 {
3151 Texture *textureObj = getTexture(texture);
3152
3153 ImageIndex index = ImageIndex::Make2D(level);
3154 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3155 textureObj, numViews, viewportOffsets);
3156 }
3157 else
3158 {
3159 framebuffer->resetAttachment(this, attachment);
3160 }
3161
3162 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003163}
3164
Jamie Madillc29968b2016-01-20 11:17:23 -05003165void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3166{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003167 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003168 ASSERT(framebuffer);
3169 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003170 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003171}
3172
3173void Context::readBuffer(GLenum mode)
3174{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003175 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003176 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003177 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003178}
3179
3180void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3181{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003182 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003183 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003184
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003185 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003186 ASSERT(framebuffer);
3187
3188 // The specification isn't clear what should be done when the framebuffer isn't complete.
3189 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003190 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003191}
3192
3193void Context::invalidateFramebuffer(GLenum target,
3194 GLsizei numAttachments,
3195 const GLenum *attachments)
3196{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003197 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003198 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003199
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003200 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003201 ASSERT(framebuffer);
3202
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003203 if (framebuffer->checkStatus(this) != GL_FRAMEBUFFER_COMPLETE)
Jamie Madillc29968b2016-01-20 11:17:23 -05003204 {
Jamie Madill437fa652016-05-03 15:13:24 -04003205 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003206 }
Jamie Madill437fa652016-05-03 15:13:24 -04003207
Jamie Madill4928b7c2017-06-20 12:57:39 -04003208 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003209}
3210
3211void Context::invalidateSubFramebuffer(GLenum target,
3212 GLsizei numAttachments,
3213 const GLenum *attachments,
3214 GLint x,
3215 GLint y,
3216 GLsizei width,
3217 GLsizei height)
3218{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003219 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003220 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003221
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003222 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003223 ASSERT(framebuffer);
3224
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003225 if (framebuffer->checkStatus(this) != GL_FRAMEBUFFER_COMPLETE)
Jamie Madillc29968b2016-01-20 11:17:23 -05003226 {
Jamie Madill437fa652016-05-03 15:13:24 -04003227 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003228 }
Jamie Madill437fa652016-05-03 15:13:24 -04003229
3230 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003231 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003232}
3233
Jamie Madill73a84962016-02-12 09:27:23 -05003234void Context::texImage2D(GLenum target,
3235 GLint level,
3236 GLint internalformat,
3237 GLsizei width,
3238 GLsizei height,
3239 GLint border,
3240 GLenum format,
3241 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003242 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003243{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003244 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003245
3246 Extents size(width, height, 1);
3247 Texture *texture =
3248 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003249 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3250 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003251}
3252
3253void Context::texImage3D(GLenum target,
3254 GLint level,
3255 GLint internalformat,
3256 GLsizei width,
3257 GLsizei height,
3258 GLsizei depth,
3259 GLint border,
3260 GLenum format,
3261 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003262 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003263{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003264 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003265
3266 Extents size(width, height, depth);
3267 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003268 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3269 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003270}
3271
3272void Context::texSubImage2D(GLenum target,
3273 GLint level,
3274 GLint xoffset,
3275 GLint yoffset,
3276 GLsizei width,
3277 GLsizei height,
3278 GLenum format,
3279 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003280 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003281{
3282 // Zero sized uploads are valid but no-ops
3283 if (width == 0 || height == 0)
3284 {
3285 return;
3286 }
3287
Jamie Madillad9f24e2016-02-12 09:27:24 -05003288 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003289
3290 Box area(xoffset, yoffset, 0, width, height, 1);
3291 Texture *texture =
3292 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003293 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3294 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003295}
3296
3297void Context::texSubImage3D(GLenum target,
3298 GLint level,
3299 GLint xoffset,
3300 GLint yoffset,
3301 GLint zoffset,
3302 GLsizei width,
3303 GLsizei height,
3304 GLsizei depth,
3305 GLenum format,
3306 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003307 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003308{
3309 // Zero sized uploads are valid but no-ops
3310 if (width == 0 || height == 0 || depth == 0)
3311 {
3312 return;
3313 }
3314
Jamie Madillad9f24e2016-02-12 09:27:24 -05003315 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003316
3317 Box area(xoffset, yoffset, zoffset, width, height, depth);
3318 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003319 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3320 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003321}
3322
3323void Context::compressedTexImage2D(GLenum target,
3324 GLint level,
3325 GLenum internalformat,
3326 GLsizei width,
3327 GLsizei height,
3328 GLint border,
3329 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003330 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003331{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003332 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003333
3334 Extents size(width, height, 1);
3335 Texture *texture =
3336 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003337 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003338 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003339 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003340}
3341
3342void Context::compressedTexImage3D(GLenum target,
3343 GLint level,
3344 GLenum internalformat,
3345 GLsizei width,
3346 GLsizei height,
3347 GLsizei depth,
3348 GLint border,
3349 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003350 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003351{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003352 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003353
3354 Extents size(width, height, depth);
3355 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003356 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003357 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003358 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003359}
3360
3361void Context::compressedTexSubImage2D(GLenum target,
3362 GLint level,
3363 GLint xoffset,
3364 GLint yoffset,
3365 GLsizei width,
3366 GLsizei height,
3367 GLenum format,
3368 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003369 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003370{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003371 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003372
3373 Box area(xoffset, yoffset, 0, width, height, 1);
3374 Texture *texture =
3375 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003376 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003377 format, imageSize,
3378 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003379}
3380
3381void Context::compressedTexSubImage3D(GLenum target,
3382 GLint level,
3383 GLint xoffset,
3384 GLint yoffset,
3385 GLint zoffset,
3386 GLsizei width,
3387 GLsizei height,
3388 GLsizei depth,
3389 GLenum format,
3390 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003391 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003392{
3393 // Zero sized uploads are valid but no-ops
3394 if (width == 0 || height == 0)
3395 {
3396 return;
3397 }
3398
Jamie Madillad9f24e2016-02-12 09:27:24 -05003399 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003400
3401 Box area(xoffset, yoffset, zoffset, width, height, depth);
3402 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003403 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003404 format, imageSize,
3405 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003406}
3407
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003408void Context::generateMipmap(GLenum target)
3409{
3410 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003411 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003412}
3413
Geoff Lang97073d12016-04-20 10:42:34 -07003414void Context::copyTextureCHROMIUM(GLuint sourceId,
Geoff Langfc72a072017-03-24 14:52:39 -04003415 GLint sourceLevel,
3416 GLenum destTarget,
Geoff Lang97073d12016-04-20 10:42:34 -07003417 GLuint destId,
Geoff Langfc72a072017-03-24 14:52:39 -04003418 GLint destLevel,
Geoff Lang97073d12016-04-20 10:42:34 -07003419 GLint internalFormat,
3420 GLenum destType,
3421 GLboolean unpackFlipY,
3422 GLboolean unpackPremultiplyAlpha,
3423 GLboolean unpackUnmultiplyAlpha)
3424{
3425 syncStateForTexImage();
3426
3427 gl::Texture *sourceTexture = getTexture(sourceId);
3428 gl::Texture *destTexture = getTexture(destId);
Geoff Langfc72a072017-03-24 14:52:39 -04003429 handleError(destTexture->copyTexture(
3430 this, destTarget, destLevel, internalFormat, destType, sourceLevel, unpackFlipY == GL_TRUE,
3431 unpackPremultiplyAlpha == GL_TRUE, unpackUnmultiplyAlpha == GL_TRUE, sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003432}
3433
3434void Context::copySubTextureCHROMIUM(GLuint sourceId,
Geoff Langfc72a072017-03-24 14:52:39 -04003435 GLint sourceLevel,
3436 GLenum destTarget,
Geoff Lang97073d12016-04-20 10:42:34 -07003437 GLuint destId,
Geoff Langfc72a072017-03-24 14:52:39 -04003438 GLint destLevel,
Geoff Lang97073d12016-04-20 10:42:34 -07003439 GLint xoffset,
3440 GLint yoffset,
3441 GLint x,
3442 GLint y,
3443 GLsizei width,
3444 GLsizei height,
3445 GLboolean unpackFlipY,
3446 GLboolean unpackPremultiplyAlpha,
3447 GLboolean unpackUnmultiplyAlpha)
3448{
3449 // Zero sized copies are valid but no-ops
3450 if (width == 0 || height == 0)
3451 {
3452 return;
3453 }
3454
3455 syncStateForTexImage();
3456
3457 gl::Texture *sourceTexture = getTexture(sourceId);
3458 gl::Texture *destTexture = getTexture(destId);
3459 Offset offset(xoffset, yoffset, 0);
3460 Rectangle area(x, y, width, height);
Geoff Langfc72a072017-03-24 14:52:39 -04003461 handleError(destTexture->copySubTexture(
3462 this, destTarget, destLevel, offset, sourceLevel, area, unpackFlipY == GL_TRUE,
3463 unpackPremultiplyAlpha == GL_TRUE, unpackUnmultiplyAlpha == GL_TRUE, sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003464}
3465
Geoff Lang47110bf2016-04-20 11:13:22 -07003466void Context::compressedCopyTextureCHROMIUM(GLuint sourceId, GLuint destId)
3467{
3468 syncStateForTexImage();
3469
3470 gl::Texture *sourceTexture = getTexture(sourceId);
3471 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05003472 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07003473}
3474
Geoff Lang496c02d2016-10-20 11:38:11 -07003475void Context::getBufferPointerv(GLenum target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03003476{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003477 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003478 ASSERT(buffer);
3479
Geoff Lang496c02d2016-10-20 11:38:11 -07003480 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03003481}
3482
Jamie Madill876429b2017-04-20 15:46:24 -04003483void *Context::mapBuffer(GLenum target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003484{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003485 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003486 ASSERT(buffer);
3487
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003488 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003489 if (error.isError())
3490 {
Jamie Madill437fa652016-05-03 15:13:24 -04003491 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003492 return nullptr;
3493 }
3494
3495 return buffer->getMapPointer();
3496}
3497
3498GLboolean Context::unmapBuffer(GLenum target)
3499{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003500 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003501 ASSERT(buffer);
3502
3503 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003504 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03003505 if (error.isError())
3506 {
Jamie Madill437fa652016-05-03 15:13:24 -04003507 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003508 return GL_FALSE;
3509 }
3510
3511 return result;
3512}
3513
Jamie Madill876429b2017-04-20 15:46:24 -04003514void *Context::mapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003515{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003516 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003517 ASSERT(buffer);
3518
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003519 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003520 if (error.isError())
3521 {
Jamie Madill437fa652016-05-03 15:13:24 -04003522 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003523 return nullptr;
3524 }
3525
3526 return buffer->getMapPointer();
3527}
3528
3529void Context::flushMappedBufferRange(GLenum /*target*/, GLintptr /*offset*/, GLsizeiptr /*length*/)
3530{
3531 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
3532}
3533
Jamie Madillad9f24e2016-02-12 09:27:24 -05003534void Context::syncStateForReadPixels()
3535{
3536 syncRendererState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
3537}
3538
3539void Context::syncStateForTexImage()
3540{
3541 syncRendererState(mTexImageDirtyBits, mTexImageDirtyObjects);
3542}
3543
3544void Context::syncStateForClear()
3545{
3546 syncRendererState(mClearDirtyBits, mClearDirtyObjects);
3547}
3548
3549void Context::syncStateForBlit()
3550{
3551 syncRendererState(mBlitDirtyBits, mBlitDirtyObjects);
3552}
3553
Jamie Madillc20ab272016-06-09 07:20:46 -07003554void Context::activeTexture(GLenum texture)
3555{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003556 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003557}
3558
Jamie Madill876429b2017-04-20 15:46:24 -04003559void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003560{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003561 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07003562}
3563
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003564void Context::blendEquation(GLenum mode)
3565{
3566 mGLState.setBlendEquation(mode, mode);
3567}
3568
Jamie Madillc20ab272016-06-09 07:20:46 -07003569void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
3570{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003571 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003572}
3573
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003574void Context::blendFunc(GLenum sfactor, GLenum dfactor)
3575{
3576 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
3577}
3578
Jamie Madillc20ab272016-06-09 07:20:46 -07003579void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
3580{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003581 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003582}
3583
Jamie Madill876429b2017-04-20 15:46:24 -04003584void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003585{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003586 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003587}
3588
Jamie Madill876429b2017-04-20 15:46:24 -04003589void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07003590{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003591 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07003592}
3593
3594void Context::clearStencil(GLint s)
3595{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003596 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07003597}
3598
3599void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
3600{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003601 mGLState.setColorMask(red == GL_TRUE, green == GL_TRUE, blue == GL_TRUE, alpha == GL_TRUE);
Jamie Madillc20ab272016-06-09 07:20:46 -07003602}
3603
Corentin Wallez2e568cf2017-09-18 17:05:22 -04003604void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07003605{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003606 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003607}
3608
3609void Context::depthFunc(GLenum func)
3610{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003611 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07003612}
3613
3614void Context::depthMask(GLboolean flag)
3615{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003616 mGLState.setDepthMask(flag != GL_FALSE);
Jamie Madillc20ab272016-06-09 07:20:46 -07003617}
3618
Jamie Madill876429b2017-04-20 15:46:24 -04003619void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07003620{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003621 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07003622}
3623
3624void Context::disable(GLenum cap)
3625{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003626 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003627}
3628
3629void Context::disableVertexAttribArray(GLuint index)
3630{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003631 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003632}
3633
3634void Context::enable(GLenum cap)
3635{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003636 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003637}
3638
3639void Context::enableVertexAttribArray(GLuint index)
3640{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003641 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003642}
3643
3644void Context::frontFace(GLenum mode)
3645{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003646 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003647}
3648
3649void Context::hint(GLenum target, GLenum mode)
3650{
3651 switch (target)
3652 {
3653 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003654 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003655 break;
3656
3657 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003658 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003659 break;
3660
3661 default:
3662 UNREACHABLE();
3663 return;
3664 }
3665}
3666
3667void Context::lineWidth(GLfloat width)
3668{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003669 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07003670}
3671
3672void Context::pixelStorei(GLenum pname, GLint param)
3673{
3674 switch (pname)
3675 {
3676 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003677 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003678 break;
3679
3680 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003681 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003682 break;
3683
3684 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003685 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003686 break;
3687
3688 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003689 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003690 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003691 break;
3692
3693 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03003694 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003695 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003696 break;
3697
3698 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03003699 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003700 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003701 break;
3702
3703 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003704 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003705 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003706 break;
3707
3708 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003709 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003710 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003711 break;
3712
3713 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003714 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003715 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003716 break;
3717
3718 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003719 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003720 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003721 break;
3722
3723 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003724 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003725 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003726 break;
3727
3728 default:
3729 UNREACHABLE();
3730 return;
3731 }
3732}
3733
3734void Context::polygonOffset(GLfloat factor, GLfloat units)
3735{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003736 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07003737}
3738
Jamie Madill876429b2017-04-20 15:46:24 -04003739void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07003740{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003741 mGLState.setSampleCoverageParams(clamp01(value), invert == GL_TRUE);
Jamie Madillc20ab272016-06-09 07:20:46 -07003742}
3743
Jiawei Shaodb342272017-09-27 10:21:45 +08003744void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
3745{
3746 mGLState.setSampleMaskParams(maskNumber, mask);
3747}
3748
Jamie Madillc20ab272016-06-09 07:20:46 -07003749void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
3750{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003751 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07003752}
3753
3754void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
3755{
3756 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3757 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003758 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003759 }
3760
3761 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3762 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003763 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003764 }
3765}
3766
3767void Context::stencilMaskSeparate(GLenum face, GLuint mask)
3768{
3769 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3770 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003771 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003772 }
3773
3774 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3775 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003776 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003777 }
3778}
3779
3780void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
3781{
3782 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3783 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003784 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003785 }
3786
3787 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3788 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003789 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003790 }
3791}
3792
3793void Context::vertexAttrib1f(GLuint index, GLfloat x)
3794{
3795 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003796 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003797}
3798
3799void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
3800{
3801 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003802 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003803}
3804
3805void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
3806{
3807 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003808 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003809}
3810
3811void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
3812{
3813 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003814 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003815}
3816
3817void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
3818{
3819 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003820 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003821}
3822
3823void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
3824{
3825 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003826 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003827}
3828
3829void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
3830{
3831 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003832 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003833}
3834
3835void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
3836{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003837 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07003838}
3839
3840void Context::vertexAttribPointer(GLuint index,
3841 GLint size,
3842 GLenum type,
3843 GLboolean normalized,
3844 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04003845 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07003846{
Shaodde78e82017-05-22 14:13:27 +08003847 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(GL_ARRAY_BUFFER), size,
3848 type, normalized == GL_TRUE, false, stride, ptr);
Jamie Madillc20ab272016-06-09 07:20:46 -07003849}
3850
Shao80957d92017-02-20 21:25:59 +08003851void Context::vertexAttribFormat(GLuint attribIndex,
3852 GLint size,
3853 GLenum type,
3854 GLboolean normalized,
3855 GLuint relativeOffset)
3856{
3857 mGLState.setVertexAttribFormat(attribIndex, size, type, normalized == GL_TRUE, false,
3858 relativeOffset);
3859}
3860
3861void Context::vertexAttribIFormat(GLuint attribIndex,
3862 GLint size,
3863 GLenum type,
3864 GLuint relativeOffset)
3865{
3866 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
3867}
3868
3869void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
3870{
Shaodde78e82017-05-22 14:13:27 +08003871 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Shao80957d92017-02-20 21:25:59 +08003872}
3873
3874void Context::setVertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
3875{
3876 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
3877}
3878
Jamie Madillc20ab272016-06-09 07:20:46 -07003879void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
3880{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003881 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07003882}
3883
3884void Context::vertexAttribIPointer(GLuint index,
3885 GLint size,
3886 GLenum type,
3887 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04003888 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07003889{
Shaodde78e82017-05-22 14:13:27 +08003890 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(GL_ARRAY_BUFFER), size,
3891 type, false, true, stride, pointer);
Jamie Madillc20ab272016-06-09 07:20:46 -07003892}
3893
3894void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
3895{
3896 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003897 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003898}
3899
3900void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
3901{
3902 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003903 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003904}
3905
3906void Context::vertexAttribI4iv(GLuint index, const GLint *v)
3907{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003908 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07003909}
3910
3911void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
3912{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003913 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07003914}
3915
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003916void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
3917{
3918 const VertexAttribCurrentValueData &currentValues =
3919 getGLState().getVertexAttribCurrentValue(index);
3920 const VertexArray *vao = getGLState().getVertexArray();
3921 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3922 currentValues, pname, params);
3923}
3924
3925void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
3926{
3927 const VertexAttribCurrentValueData &currentValues =
3928 getGLState().getVertexAttribCurrentValue(index);
3929 const VertexArray *vao = getGLState().getVertexArray();
3930 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3931 currentValues, pname, params);
3932}
3933
3934void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
3935{
3936 const VertexAttribCurrentValueData &currentValues =
3937 getGLState().getVertexAttribCurrentValue(index);
3938 const VertexArray *vao = getGLState().getVertexArray();
3939 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3940 currentValues, pname, params);
3941}
3942
3943void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
3944{
3945 const VertexAttribCurrentValueData &currentValues =
3946 getGLState().getVertexAttribCurrentValue(index);
3947 const VertexArray *vao = getGLState().getVertexArray();
3948 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3949 currentValues, pname, params);
3950}
3951
Jamie Madill876429b2017-04-20 15:46:24 -04003952void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003953{
3954 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
3955 QueryVertexAttribPointerv(attrib, pname, pointer);
3956}
3957
Jamie Madillc20ab272016-06-09 07:20:46 -07003958void Context::debugMessageControl(GLenum source,
3959 GLenum type,
3960 GLenum severity,
3961 GLsizei count,
3962 const GLuint *ids,
3963 GLboolean enabled)
3964{
3965 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003966 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
3967 (enabled != GL_FALSE));
Jamie Madillc20ab272016-06-09 07:20:46 -07003968}
3969
3970void Context::debugMessageInsert(GLenum source,
3971 GLenum type,
3972 GLuint id,
3973 GLenum severity,
3974 GLsizei length,
3975 const GLchar *buf)
3976{
3977 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003978 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07003979}
3980
3981void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
3982{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003983 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07003984}
3985
3986GLuint Context::getDebugMessageLog(GLuint count,
3987 GLsizei bufSize,
3988 GLenum *sources,
3989 GLenum *types,
3990 GLuint *ids,
3991 GLenum *severities,
3992 GLsizei *lengths,
3993 GLchar *messageLog)
3994{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003995 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
3996 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07003997}
3998
3999void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4000{
4001 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004002 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004003}
4004
4005void Context::popDebugGroup()
4006{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004007 mGLState.getDebug().popGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004008}
4009
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004010void Context::bufferData(GLenum target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004011{
4012 Buffer *buffer = mGLState.getTargetBuffer(target);
4013 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004014 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004015}
4016
Jamie Madill876429b2017-04-20 15:46:24 -04004017void Context::bufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004018{
4019 if (data == nullptr)
4020 {
4021 return;
4022 }
4023
4024 Buffer *buffer = mGLState.getTargetBuffer(target);
4025 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004026 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004027}
4028
Jamie Madillef300b12016-10-07 15:12:09 -04004029void Context::attachShader(GLuint program, GLuint shader)
4030{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004031 auto programObject = mState.mShaderPrograms->getProgram(program);
4032 auto shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004033 ASSERT(programObject && shaderObject);
4034 programObject->attachShader(shaderObject);
4035}
4036
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004037const Workarounds &Context::getWorkarounds() const
4038{
4039 return mWorkarounds;
4040}
4041
Jamie Madillb0817d12016-11-01 15:48:31 -04004042void Context::copyBufferSubData(GLenum readTarget,
4043 GLenum writeTarget,
4044 GLintptr readOffset,
4045 GLintptr writeOffset,
4046 GLsizeiptr size)
4047{
4048 // if size is zero, the copy is a successful no-op
4049 if (size == 0)
4050 {
4051 return;
4052 }
4053
4054 // TODO(jmadill): cache these.
4055 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4056 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4057
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004058 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004059}
4060
Jamie Madill01a80ee2016-11-07 12:06:18 -05004061void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4062{
4063 Program *programObject = getProgram(program);
4064 // TODO(jmadill): Re-use this from the validation if possible.
4065 ASSERT(programObject);
4066 programObject->bindAttributeLocation(index, name);
4067}
4068
4069void Context::bindBuffer(GLenum target, GLuint buffer)
4070{
4071 switch (target)
4072 {
4073 case GL_ARRAY_BUFFER:
4074 bindArrayBuffer(buffer);
4075 break;
4076 case GL_ELEMENT_ARRAY_BUFFER:
4077 bindElementArrayBuffer(buffer);
4078 break;
4079 case GL_COPY_READ_BUFFER:
4080 bindCopyReadBuffer(buffer);
4081 break;
4082 case GL_COPY_WRITE_BUFFER:
4083 bindCopyWriteBuffer(buffer);
4084 break;
4085 case GL_PIXEL_PACK_BUFFER:
4086 bindPixelPackBuffer(buffer);
4087 break;
4088 case GL_PIXEL_UNPACK_BUFFER:
4089 bindPixelUnpackBuffer(buffer);
4090 break;
4091 case GL_UNIFORM_BUFFER:
4092 bindGenericUniformBuffer(buffer);
4093 break;
4094 case GL_TRANSFORM_FEEDBACK_BUFFER:
4095 bindGenericTransformFeedbackBuffer(buffer);
4096 break;
Geoff Lang3b573612016-10-31 14:08:10 -04004097 case GL_ATOMIC_COUNTER_BUFFER:
Jiajia Qin6eafb042016-12-27 17:04:07 +08004098 bindGenericAtomicCounterBuffer(buffer);
Geoff Lang3b573612016-10-31 14:08:10 -04004099 break;
4100 case GL_SHADER_STORAGE_BUFFER:
Jiajia Qinf546e7d2017-03-27 14:12:59 +08004101 bindGenericShaderStorageBuffer(buffer);
Geoff Lang3b573612016-10-31 14:08:10 -04004102 break;
4103 case GL_DRAW_INDIRECT_BUFFER:
Jiajia Qin9d7d0b12016-11-29 16:30:31 +08004104 bindDrawIndirectBuffer(buffer);
Geoff Lang3b573612016-10-31 14:08:10 -04004105 break;
4106 case GL_DISPATCH_INDIRECT_BUFFER:
Geoff Lang9f090372016-12-02 10:20:43 -05004107 if (buffer != 0)
4108 {
4109 // Binding buffers to this binding point is not implemented yet.
4110 UNIMPLEMENTED();
4111 }
Geoff Lang3b573612016-10-31 14:08:10 -04004112 break;
Jamie Madill01a80ee2016-11-07 12:06:18 -05004113
4114 default:
4115 UNREACHABLE();
4116 break;
4117 }
4118}
4119
Jiajia Qin6eafb042016-12-27 17:04:07 +08004120void Context::bindBufferBase(GLenum target, GLuint index, GLuint buffer)
4121{
4122 bindBufferRange(target, index, buffer, 0, 0);
4123}
4124
4125void Context::bindBufferRange(GLenum target,
4126 GLuint index,
4127 GLuint buffer,
4128 GLintptr offset,
4129 GLsizeiptr size)
4130{
4131 switch (target)
4132 {
4133 case GL_TRANSFORM_FEEDBACK_BUFFER:
4134 bindIndexedTransformFeedbackBuffer(buffer, index, offset, size);
4135 bindGenericTransformFeedbackBuffer(buffer);
4136 break;
4137 case GL_UNIFORM_BUFFER:
4138 bindIndexedUniformBuffer(buffer, index, offset, size);
4139 bindGenericUniformBuffer(buffer);
4140 break;
4141 case GL_ATOMIC_COUNTER_BUFFER:
4142 bindIndexedAtomicCounterBuffer(buffer, index, offset, size);
4143 bindGenericAtomicCounterBuffer(buffer);
4144 break;
4145 case GL_SHADER_STORAGE_BUFFER:
Jiajia Qinf546e7d2017-03-27 14:12:59 +08004146 bindIndexedShaderStorageBuffer(buffer, index, offset, size);
4147 bindGenericShaderStorageBuffer(buffer);
Jiajia Qin6eafb042016-12-27 17:04:07 +08004148 break;
4149 default:
4150 UNREACHABLE();
4151 break;
4152 }
4153}
4154
Jamie Madill01a80ee2016-11-07 12:06:18 -05004155void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
4156{
4157 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4158 {
4159 bindReadFramebuffer(framebuffer);
4160 }
4161
4162 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4163 {
4164 bindDrawFramebuffer(framebuffer);
4165 }
4166}
4167
4168void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4169{
4170 ASSERT(target == GL_RENDERBUFFER);
4171 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004172 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04004173 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004174}
4175
JiangYizhoubddc46b2016-12-09 09:50:51 +08004176void Context::texStorage2DMultisample(GLenum target,
4177 GLsizei samples,
4178 GLenum internalformat,
4179 GLsizei width,
4180 GLsizei height,
4181 GLboolean fixedsamplelocations)
4182{
4183 Extents size(width, height, 1);
4184 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05004185 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
JiangYizhoubddc46b2016-12-09 09:50:51 +08004186 fixedsamplelocations));
4187}
4188
4189void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4190{
JiangYizhou5b03f472017-01-09 10:22:53 +08004191 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
4192 // the sample position should be queried by DRAW_FRAMEBUFFER.
4193 mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER);
4194 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08004195
4196 switch (pname)
4197 {
4198 case GL_SAMPLE_POSITION:
4199 handleError(framebuffer->getSamplePosition(index, val));
4200 break;
4201 default:
4202 UNREACHABLE();
4203 }
4204}
4205
Jamie Madille8fb6402017-02-14 17:56:40 -05004206void Context::renderbufferStorage(GLenum target,
4207 GLenum internalformat,
4208 GLsizei width,
4209 GLsizei height)
4210{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004211 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4212 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
4213
Jamie Madille8fb6402017-02-14 17:56:40 -05004214 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04004215 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004216}
4217
4218void Context::renderbufferStorageMultisample(GLenum target,
4219 GLsizei samples,
4220 GLenum internalformat,
4221 GLsizei width,
4222 GLsizei height)
4223{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004224 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4225 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05004226
4227 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004228 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04004229 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004230}
4231
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004232void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
4233{
Jamie Madill70b5bb02017-08-28 13:32:37 -04004234 const Sync *syncObject = getSync(sync);
Geoff Lang82483b92017-04-11 15:33:00 -04004235 handleError(QuerySynciv(syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004236}
4237
JiangYizhoue18e6392017-02-20 10:32:23 +08004238void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
4239{
4240 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4241 QueryFramebufferParameteriv(framebuffer, pname, params);
4242}
4243
4244void Context::setFramebufferParameteri(GLenum target, GLenum pname, GLint param)
4245{
4246 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4247 SetFramebufferParameteri(framebuffer, pname, param);
4248}
4249
Jamie Madillb3f26b92017-07-19 15:07:41 -04004250Error Context::getScratchBuffer(size_t requstedSizeBytes,
4251 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05004252{
Jamie Madillb3f26b92017-07-19 15:07:41 -04004253 if (!mScratchBuffer.get(requstedSizeBytes, scratchBufferOut))
4254 {
4255 return OutOfMemory() << "Failed to allocate internal buffer.";
4256 }
4257 return NoError();
4258}
4259
4260Error Context::getZeroFilledBuffer(size_t requstedSizeBytes,
4261 angle::MemoryBuffer **zeroBufferOut) const
4262{
4263 if (!mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0))
Jamie Madille14951e2017-03-09 18:55:16 -05004264 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004265 return OutOfMemory() << "Failed to allocate internal buffer.";
Jamie Madille14951e2017-03-09 18:55:16 -05004266 }
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004267 return NoError();
Jamie Madille14951e2017-03-09 18:55:16 -05004268}
4269
Xinghua Cao2b396592017-03-29 15:36:04 +08004270void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
4271{
4272 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
4273 {
4274 return;
4275 }
4276
Jamie Madill05b35b22017-10-03 09:01:44 -04004277 // TODO(jmadill): Dirty bits for compute.
Jamie Madilla59fc192017-11-02 12:57:58 -04004278 if (isRobustResourceInitEnabled())
4279 {
4280 ANGLE_CONTEXT_TRY(mGLState.clearUnclearedActiveTextures(this));
4281 }
Jamie Madill05b35b22017-10-03 09:01:44 -04004282
Jamie Madill71c88b32017-09-14 22:20:29 -04004283 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08004284}
4285
JiangYizhou165361c2017-06-07 14:56:57 +08004286void Context::texStorage2D(GLenum target,
4287 GLsizei levels,
4288 GLenum internalFormat,
4289 GLsizei width,
4290 GLsizei height)
4291{
4292 Extents size(width, height, 1);
4293 Texture *texture = getTargetTexture(target);
4294 handleError(texture->setStorage(this, target, levels, internalFormat, size));
4295}
4296
4297void Context::texStorage3D(GLenum target,
4298 GLsizei levels,
4299 GLenum internalFormat,
4300 GLsizei width,
4301 GLsizei height,
4302 GLsizei depth)
4303{
4304 Extents size(width, height, depth);
4305 Texture *texture = getTargetTexture(target);
4306 handleError(texture->setStorage(this, target, levels, internalFormat, size));
4307}
4308
Jamie Madillc1d770e2017-04-13 17:31:24 -04004309GLenum Context::checkFramebufferStatus(GLenum target)
4310{
4311 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4312 ASSERT(framebuffer);
4313
4314 return framebuffer->checkStatus(this);
4315}
4316
4317void Context::compileShader(GLuint shader)
4318{
4319 Shader *shaderObject = GetValidShader(this, shader);
4320 if (!shaderObject)
4321 {
4322 return;
4323 }
4324 shaderObject->compile(this);
4325}
4326
4327void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
4328{
4329 for (int i = 0; i < n; i++)
4330 {
4331 deleteBuffer(buffers[i]);
4332 }
4333}
4334
4335void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
4336{
4337 for (int i = 0; i < n; i++)
4338 {
4339 if (framebuffers[i] != 0)
4340 {
4341 deleteFramebuffer(framebuffers[i]);
4342 }
4343 }
4344}
4345
4346void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
4347{
4348 for (int i = 0; i < n; i++)
4349 {
4350 deleteRenderbuffer(renderbuffers[i]);
4351 }
4352}
4353
4354void Context::deleteTextures(GLsizei n, const GLuint *textures)
4355{
4356 for (int i = 0; i < n; i++)
4357 {
4358 if (textures[i] != 0)
4359 {
4360 deleteTexture(textures[i]);
4361 }
4362 }
4363}
4364
4365void Context::detachShader(GLuint program, GLuint shader)
4366{
4367 Program *programObject = getProgram(program);
4368 ASSERT(programObject);
4369
4370 Shader *shaderObject = getShader(shader);
4371 ASSERT(shaderObject);
4372
4373 programObject->detachShader(this, shaderObject);
4374}
4375
4376void Context::genBuffers(GLsizei n, GLuint *buffers)
4377{
4378 for (int i = 0; i < n; i++)
4379 {
4380 buffers[i] = createBuffer();
4381 }
4382}
4383
4384void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
4385{
4386 for (int i = 0; i < n; i++)
4387 {
4388 framebuffers[i] = createFramebuffer();
4389 }
4390}
4391
4392void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
4393{
4394 for (int i = 0; i < n; i++)
4395 {
4396 renderbuffers[i] = createRenderbuffer();
4397 }
4398}
4399
4400void Context::genTextures(GLsizei n, GLuint *textures)
4401{
4402 for (int i = 0; i < n; i++)
4403 {
4404 textures[i] = createTexture();
4405 }
4406}
4407
4408void Context::getActiveAttrib(GLuint program,
4409 GLuint index,
4410 GLsizei bufsize,
4411 GLsizei *length,
4412 GLint *size,
4413 GLenum *type,
4414 GLchar *name)
4415{
4416 Program *programObject = getProgram(program);
4417 ASSERT(programObject);
4418 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
4419}
4420
4421void Context::getActiveUniform(GLuint program,
4422 GLuint index,
4423 GLsizei bufsize,
4424 GLsizei *length,
4425 GLint *size,
4426 GLenum *type,
4427 GLchar *name)
4428{
4429 Program *programObject = getProgram(program);
4430 ASSERT(programObject);
4431 programObject->getActiveUniform(index, bufsize, length, size, type, name);
4432}
4433
4434void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
4435{
4436 Program *programObject = getProgram(program);
4437 ASSERT(programObject);
4438 programObject->getAttachedShaders(maxcount, count, shaders);
4439}
4440
4441GLint Context::getAttribLocation(GLuint program, const GLchar *name)
4442{
4443 Program *programObject = getProgram(program);
4444 ASSERT(programObject);
4445 return programObject->getAttributeLocation(name);
4446}
4447
4448void Context::getBooleanv(GLenum pname, GLboolean *params)
4449{
4450 GLenum nativeType;
4451 unsigned int numParams = 0;
4452 getQueryParameterInfo(pname, &nativeType, &numParams);
4453
4454 if (nativeType == GL_BOOL)
4455 {
4456 getBooleanvImpl(pname, params);
4457 }
4458 else
4459 {
4460 CastStateValues(this, nativeType, pname, numParams, params);
4461 }
4462}
4463
4464void Context::getFloatv(GLenum pname, GLfloat *params)
4465{
4466 GLenum nativeType;
4467 unsigned int numParams = 0;
4468 getQueryParameterInfo(pname, &nativeType, &numParams);
4469
4470 if (nativeType == GL_FLOAT)
4471 {
4472 getFloatvImpl(pname, params);
4473 }
4474 else
4475 {
4476 CastStateValues(this, nativeType, pname, numParams, params);
4477 }
4478}
4479
4480void Context::getIntegerv(GLenum pname, GLint *params)
4481{
4482 GLenum nativeType;
4483 unsigned int numParams = 0;
4484 getQueryParameterInfo(pname, &nativeType, &numParams);
4485
4486 if (nativeType == GL_INT)
4487 {
4488 getIntegervImpl(pname, params);
4489 }
4490 else
4491 {
4492 CastStateValues(this, nativeType, pname, numParams, params);
4493 }
4494}
4495
4496void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
4497{
4498 Program *programObject = getProgram(program);
4499 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04004500 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004501}
4502
Jamie Madillbe849e42017-05-02 15:49:00 -04004503void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04004504{
4505 Program *programObject = getProgram(program);
4506 ASSERT(programObject);
4507 programObject->getInfoLog(bufsize, length, infolog);
4508}
4509
4510void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
4511{
4512 Shader *shaderObject = getShader(shader);
4513 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004514 QueryShaderiv(this, shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004515}
4516
4517void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
4518{
4519 Shader *shaderObject = getShader(shader);
4520 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004521 shaderObject->getInfoLog(this, bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004522}
4523
4524void Context::getShaderPrecisionFormat(GLenum shadertype,
4525 GLenum precisiontype,
4526 GLint *range,
4527 GLint *precision)
4528{
4529 // TODO(jmadill): Compute shaders.
4530
4531 switch (shadertype)
4532 {
4533 case GL_VERTEX_SHADER:
4534 switch (precisiontype)
4535 {
4536 case GL_LOW_FLOAT:
4537 mCaps.vertexLowpFloat.get(range, precision);
4538 break;
4539 case GL_MEDIUM_FLOAT:
4540 mCaps.vertexMediumpFloat.get(range, precision);
4541 break;
4542 case GL_HIGH_FLOAT:
4543 mCaps.vertexHighpFloat.get(range, precision);
4544 break;
4545
4546 case GL_LOW_INT:
4547 mCaps.vertexLowpInt.get(range, precision);
4548 break;
4549 case GL_MEDIUM_INT:
4550 mCaps.vertexMediumpInt.get(range, precision);
4551 break;
4552 case GL_HIGH_INT:
4553 mCaps.vertexHighpInt.get(range, precision);
4554 break;
4555
4556 default:
4557 UNREACHABLE();
4558 return;
4559 }
4560 break;
4561
4562 case GL_FRAGMENT_SHADER:
4563 switch (precisiontype)
4564 {
4565 case GL_LOW_FLOAT:
4566 mCaps.fragmentLowpFloat.get(range, precision);
4567 break;
4568 case GL_MEDIUM_FLOAT:
4569 mCaps.fragmentMediumpFloat.get(range, precision);
4570 break;
4571 case GL_HIGH_FLOAT:
4572 mCaps.fragmentHighpFloat.get(range, precision);
4573 break;
4574
4575 case GL_LOW_INT:
4576 mCaps.fragmentLowpInt.get(range, precision);
4577 break;
4578 case GL_MEDIUM_INT:
4579 mCaps.fragmentMediumpInt.get(range, precision);
4580 break;
4581 case GL_HIGH_INT:
4582 mCaps.fragmentHighpInt.get(range, precision);
4583 break;
4584
4585 default:
4586 UNREACHABLE();
4587 return;
4588 }
4589 break;
4590
4591 default:
4592 UNREACHABLE();
4593 return;
4594 }
4595}
4596
4597void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
4598{
4599 Shader *shaderObject = getShader(shader);
4600 ASSERT(shaderObject);
4601 shaderObject->getSource(bufsize, length, source);
4602}
4603
4604void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
4605{
4606 Program *programObject = getProgram(program);
4607 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04004608 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004609}
4610
4611void Context::getUniformiv(GLuint program, GLint location, GLint *params)
4612{
4613 Program *programObject = getProgram(program);
4614 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04004615 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004616}
4617
4618GLint Context::getUniformLocation(GLuint program, const GLchar *name)
4619{
4620 Program *programObject = getProgram(program);
4621 ASSERT(programObject);
4622 return programObject->getUniformLocation(name);
4623}
4624
4625GLboolean Context::isBuffer(GLuint buffer)
4626{
4627 if (buffer == 0)
4628 {
4629 return GL_FALSE;
4630 }
4631
4632 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
4633}
4634
4635GLboolean Context::isEnabled(GLenum cap)
4636{
4637 return mGLState.getEnableFeature(cap);
4638}
4639
4640GLboolean Context::isFramebuffer(GLuint framebuffer)
4641{
4642 if (framebuffer == 0)
4643 {
4644 return GL_FALSE;
4645 }
4646
4647 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
4648}
4649
4650GLboolean Context::isProgram(GLuint program)
4651{
4652 if (program == 0)
4653 {
4654 return GL_FALSE;
4655 }
4656
4657 return (getProgram(program) ? GL_TRUE : GL_FALSE);
4658}
4659
4660GLboolean Context::isRenderbuffer(GLuint renderbuffer)
4661{
4662 if (renderbuffer == 0)
4663 {
4664 return GL_FALSE;
4665 }
4666
4667 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
4668}
4669
4670GLboolean Context::isShader(GLuint shader)
4671{
4672 if (shader == 0)
4673 {
4674 return GL_FALSE;
4675 }
4676
4677 return (getShader(shader) ? GL_TRUE : GL_FALSE);
4678}
4679
4680GLboolean Context::isTexture(GLuint texture)
4681{
4682 if (texture == 0)
4683 {
4684 return GL_FALSE;
4685 }
4686
4687 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
4688}
4689
4690void Context::linkProgram(GLuint program)
4691{
4692 Program *programObject = getProgram(program);
4693 ASSERT(programObject);
4694 handleError(programObject->link(this));
Martin Radev0abb7a22017-08-28 15:34:45 +03004695 mGLState.onProgramExecutableChange(programObject);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004696}
4697
4698void Context::releaseShaderCompiler()
4699{
Jamie Madill4928b7c2017-06-20 12:57:39 -04004700 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004701}
4702
4703void Context::shaderBinary(GLsizei n,
4704 const GLuint *shaders,
4705 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04004706 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04004707 GLsizei length)
4708{
4709 // No binary shader formats are supported.
4710 UNIMPLEMENTED();
4711}
4712
4713void Context::shaderSource(GLuint shader,
4714 GLsizei count,
4715 const GLchar *const *string,
4716 const GLint *length)
4717{
4718 Shader *shaderObject = getShader(shader);
4719 ASSERT(shaderObject);
4720 shaderObject->setSource(count, string, length);
4721}
4722
4723void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
4724{
4725 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
4726}
4727
4728void Context::stencilMask(GLuint mask)
4729{
4730 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
4731}
4732
4733void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
4734{
4735 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
4736}
4737
4738void Context::uniform1f(GLint location, GLfloat x)
4739{
4740 Program *program = mGLState.getProgram();
4741 program->setUniform1fv(location, 1, &x);
4742}
4743
4744void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
4745{
4746 Program *program = mGLState.getProgram();
4747 program->setUniform1fv(location, count, v);
4748}
4749
4750void Context::uniform1i(GLint location, GLint x)
4751{
4752 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04004753 if (program->setUniform1iv(location, 1, &x) == Program::SetUniformResult::SamplerChanged)
4754 {
4755 mGLState.setObjectDirty(GL_PROGRAM);
4756 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04004757}
4758
4759void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
4760{
4761 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04004762 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
4763 {
4764 mGLState.setObjectDirty(GL_PROGRAM);
4765 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04004766}
4767
4768void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
4769{
4770 GLfloat xy[2] = {x, y};
4771 Program *program = mGLState.getProgram();
4772 program->setUniform2fv(location, 1, xy);
4773}
4774
4775void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
4776{
4777 Program *program = mGLState.getProgram();
4778 program->setUniform2fv(location, count, v);
4779}
4780
4781void Context::uniform2i(GLint location, GLint x, GLint y)
4782{
4783 GLint xy[2] = {x, y};
4784 Program *program = mGLState.getProgram();
4785 program->setUniform2iv(location, 1, xy);
4786}
4787
4788void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
4789{
4790 Program *program = mGLState.getProgram();
4791 program->setUniform2iv(location, count, v);
4792}
4793
4794void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
4795{
4796 GLfloat xyz[3] = {x, y, z};
4797 Program *program = mGLState.getProgram();
4798 program->setUniform3fv(location, 1, xyz);
4799}
4800
4801void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
4802{
4803 Program *program = mGLState.getProgram();
4804 program->setUniform3fv(location, count, v);
4805}
4806
4807void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
4808{
4809 GLint xyz[3] = {x, y, z};
4810 Program *program = mGLState.getProgram();
4811 program->setUniform3iv(location, 1, xyz);
4812}
4813
4814void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
4815{
4816 Program *program = mGLState.getProgram();
4817 program->setUniform3iv(location, count, v);
4818}
4819
4820void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4821{
4822 GLfloat xyzw[4] = {x, y, z, w};
4823 Program *program = mGLState.getProgram();
4824 program->setUniform4fv(location, 1, xyzw);
4825}
4826
4827void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
4828{
4829 Program *program = mGLState.getProgram();
4830 program->setUniform4fv(location, count, v);
4831}
4832
4833void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
4834{
4835 GLint xyzw[4] = {x, y, z, w};
4836 Program *program = mGLState.getProgram();
4837 program->setUniform4iv(location, 1, xyzw);
4838}
4839
4840void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
4841{
4842 Program *program = mGLState.getProgram();
4843 program->setUniform4iv(location, count, v);
4844}
4845
4846void Context::uniformMatrix2fv(GLint location,
4847 GLsizei count,
4848 GLboolean transpose,
4849 const GLfloat *value)
4850{
4851 Program *program = mGLState.getProgram();
4852 program->setUniformMatrix2fv(location, count, transpose, value);
4853}
4854
4855void Context::uniformMatrix3fv(GLint location,
4856 GLsizei count,
4857 GLboolean transpose,
4858 const GLfloat *value)
4859{
4860 Program *program = mGLState.getProgram();
4861 program->setUniformMatrix3fv(location, count, transpose, value);
4862}
4863
4864void Context::uniformMatrix4fv(GLint location,
4865 GLsizei count,
4866 GLboolean transpose,
4867 const GLfloat *value)
4868{
4869 Program *program = mGLState.getProgram();
4870 program->setUniformMatrix4fv(location, count, transpose, value);
4871}
4872
4873void Context::validateProgram(GLuint program)
4874{
4875 Program *programObject = getProgram(program);
4876 ASSERT(programObject);
4877 programObject->validate(mCaps);
4878}
4879
Jamie Madilld04908b2017-06-09 14:15:35 -04004880void Context::getProgramBinary(GLuint program,
4881 GLsizei bufSize,
4882 GLsizei *length,
4883 GLenum *binaryFormat,
4884 void *binary)
4885{
4886 Program *programObject = getProgram(program);
4887 ASSERT(programObject != nullptr);
4888
4889 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
4890}
4891
4892void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
4893{
4894 Program *programObject = getProgram(program);
4895 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04004896
Jamie Madilld04908b2017-06-09 14:15:35 -04004897 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
4898}
4899
Jamie Madillff325f12017-08-26 15:06:05 -04004900void Context::uniform1ui(GLint location, GLuint v0)
4901{
4902 Program *program = mGLState.getProgram();
4903 program->setUniform1uiv(location, 1, &v0);
4904}
4905
4906void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
4907{
4908 Program *program = mGLState.getProgram();
4909 const GLuint xy[] = {v0, v1};
4910 program->setUniform2uiv(location, 1, xy);
4911}
4912
4913void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
4914{
4915 Program *program = mGLState.getProgram();
4916 const GLuint xyz[] = {v0, v1, v2};
4917 program->setUniform3uiv(location, 1, xyz);
4918}
4919
4920void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
4921{
4922 Program *program = mGLState.getProgram();
4923 const GLuint xyzw[] = {v0, v1, v2, v3};
4924 program->setUniform4uiv(location, 1, xyzw);
4925}
4926
4927void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
4928{
4929 Program *program = mGLState.getProgram();
4930 program->setUniform1uiv(location, count, value);
4931}
4932void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
4933{
4934 Program *program = mGLState.getProgram();
4935 program->setUniform2uiv(location, count, value);
4936}
4937
4938void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
4939{
4940 Program *program = mGLState.getProgram();
4941 program->setUniform3uiv(location, count, value);
4942}
4943
4944void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
4945{
4946 Program *program = mGLState.getProgram();
4947 program->setUniform4uiv(location, count, value);
4948}
4949
Jamie Madillf0e04492017-08-26 15:28:42 -04004950void Context::genQueries(GLsizei n, GLuint *ids)
4951{
4952 for (GLsizei i = 0; i < n; i++)
4953 {
4954 GLuint handle = mQueryHandleAllocator.allocate();
4955 mQueryMap.assign(handle, nullptr);
4956 ids[i] = handle;
4957 }
4958}
4959
4960void Context::deleteQueries(GLsizei n, const GLuint *ids)
4961{
4962 for (int i = 0; i < n; i++)
4963 {
4964 GLuint query = ids[i];
4965
4966 Query *queryObject = nullptr;
4967 if (mQueryMap.erase(query, &queryObject))
4968 {
4969 mQueryHandleAllocator.release(query);
4970 if (queryObject)
4971 {
4972 queryObject->release(this);
4973 }
4974 }
4975 }
4976}
4977
4978GLboolean Context::isQuery(GLuint id)
4979{
4980 return (getQuery(id, false, GL_NONE) != nullptr) ? GL_TRUE : GL_FALSE;
4981}
4982
Jamie Madillc8c95812017-08-26 18:40:09 -04004983void Context::uniformMatrix2x3fv(GLint location,
4984 GLsizei count,
4985 GLboolean transpose,
4986 const GLfloat *value)
4987{
4988 Program *program = mGLState.getProgram();
4989 program->setUniformMatrix2x3fv(location, count, transpose, value);
4990}
4991
4992void Context::uniformMatrix3x2fv(GLint location,
4993 GLsizei count,
4994 GLboolean transpose,
4995 const GLfloat *value)
4996{
4997 Program *program = mGLState.getProgram();
4998 program->setUniformMatrix3x2fv(location, count, transpose, value);
4999}
5000
5001void Context::uniformMatrix2x4fv(GLint location,
5002 GLsizei count,
5003 GLboolean transpose,
5004 const GLfloat *value)
5005{
5006 Program *program = mGLState.getProgram();
5007 program->setUniformMatrix2x4fv(location, count, transpose, value);
5008}
5009
5010void Context::uniformMatrix4x2fv(GLint location,
5011 GLsizei count,
5012 GLboolean transpose,
5013 const GLfloat *value)
5014{
5015 Program *program = mGLState.getProgram();
5016 program->setUniformMatrix4x2fv(location, count, transpose, value);
5017}
5018
5019void Context::uniformMatrix3x4fv(GLint location,
5020 GLsizei count,
5021 GLboolean transpose,
5022 const GLfloat *value)
5023{
5024 Program *program = mGLState.getProgram();
5025 program->setUniformMatrix3x4fv(location, count, transpose, value);
5026}
5027
5028void Context::uniformMatrix4x3fv(GLint location,
5029 GLsizei count,
5030 GLboolean transpose,
5031 const GLfloat *value)
5032{
5033 Program *program = mGLState.getProgram();
5034 program->setUniformMatrix4x3fv(location, count, transpose, value);
5035}
5036
Jamie Madilld7576732017-08-26 18:49:50 -04005037void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
5038{
5039 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5040 {
5041 GLuint vertexArray = arrays[arrayIndex];
5042
5043 if (arrays[arrayIndex] != 0)
5044 {
5045 VertexArray *vertexArrayObject = nullptr;
5046 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
5047 {
5048 if (vertexArrayObject != nullptr)
5049 {
5050 detachVertexArray(vertexArray);
5051 vertexArrayObject->onDestroy(this);
5052 }
5053
5054 mVertexArrayHandleAllocator.release(vertexArray);
5055 }
5056 }
5057 }
5058}
5059
5060void Context::genVertexArrays(GLsizei n, GLuint *arrays)
5061{
5062 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5063 {
5064 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
5065 mVertexArrayMap.assign(vertexArray, nullptr);
5066 arrays[arrayIndex] = vertexArray;
5067 }
5068}
5069
5070bool Context::isVertexArray(GLuint array)
5071{
5072 if (array == 0)
5073 {
5074 return GL_FALSE;
5075 }
5076
5077 VertexArray *vao = getVertexArray(array);
5078 return (vao != nullptr ? GL_TRUE : GL_FALSE);
5079}
5080
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04005081void Context::endTransformFeedback()
5082{
5083 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5084 transformFeedback->end(this);
5085}
5086
5087void Context::transformFeedbackVaryings(GLuint program,
5088 GLsizei count,
5089 const GLchar *const *varyings,
5090 GLenum bufferMode)
5091{
5092 Program *programObject = getProgram(program);
5093 ASSERT(programObject);
5094 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
5095}
5096
5097void Context::getTransformFeedbackVarying(GLuint program,
5098 GLuint index,
5099 GLsizei bufSize,
5100 GLsizei *length,
5101 GLsizei *size,
5102 GLenum *type,
5103 GLchar *name)
5104{
5105 Program *programObject = getProgram(program);
5106 ASSERT(programObject);
5107 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
5108}
5109
5110void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
5111{
5112 for (int i = 0; i < n; i++)
5113 {
5114 GLuint transformFeedback = ids[i];
5115 if (transformFeedback == 0)
5116 {
5117 continue;
5118 }
5119
5120 TransformFeedback *transformFeedbackObject = nullptr;
5121 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
5122 {
5123 if (transformFeedbackObject != nullptr)
5124 {
5125 detachTransformFeedback(transformFeedback);
5126 transformFeedbackObject->release(this);
5127 }
5128
5129 mTransformFeedbackHandleAllocator.release(transformFeedback);
5130 }
5131 }
5132}
5133
5134void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
5135{
5136 for (int i = 0; i < n; i++)
5137 {
5138 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
5139 mTransformFeedbackMap.assign(transformFeedback, nullptr);
5140 ids[i] = transformFeedback;
5141 }
5142}
5143
5144bool Context::isTransformFeedback(GLuint id)
5145{
5146 if (id == 0)
5147 {
5148 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
5149 // returns FALSE
5150 return GL_FALSE;
5151 }
5152
5153 const TransformFeedback *transformFeedback = getTransformFeedback(id);
5154 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
5155}
5156
5157void Context::pauseTransformFeedback()
5158{
5159 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5160 transformFeedback->pause();
5161}
5162
5163void Context::resumeTransformFeedback()
5164{
5165 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5166 transformFeedback->resume();
5167}
5168
Jamie Madill12e957f2017-08-26 21:42:26 -04005169void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
5170{
5171 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04005172 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04005173}
5174
5175GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
5176{
5177 const Program *programObject = getProgram(program);
5178 return programObject->getFragDataLocation(name);
5179}
5180
5181void Context::getUniformIndices(GLuint program,
5182 GLsizei uniformCount,
5183 const GLchar *const *uniformNames,
5184 GLuint *uniformIndices)
5185{
5186 const Program *programObject = getProgram(program);
5187 if (!programObject->isLinked())
5188 {
5189 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5190 {
5191 uniformIndices[uniformId] = GL_INVALID_INDEX;
5192 }
5193 }
5194 else
5195 {
5196 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5197 {
5198 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
5199 }
5200 }
5201}
5202
5203void Context::getActiveUniformsiv(GLuint program,
5204 GLsizei uniformCount,
5205 const GLuint *uniformIndices,
5206 GLenum pname,
5207 GLint *params)
5208{
5209 const Program *programObject = getProgram(program);
5210 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5211 {
5212 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08005213 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04005214 }
5215}
5216
5217GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
5218{
5219 const Program *programObject = getProgram(program);
5220 return programObject->getUniformBlockIndex(uniformBlockName);
5221}
5222
5223void Context::getActiveUniformBlockiv(GLuint program,
5224 GLuint uniformBlockIndex,
5225 GLenum pname,
5226 GLint *params)
5227{
5228 const Program *programObject = getProgram(program);
5229 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
5230}
5231
5232void Context::getActiveUniformBlockName(GLuint program,
5233 GLuint uniformBlockIndex,
5234 GLsizei bufSize,
5235 GLsizei *length,
5236 GLchar *uniformBlockName)
5237{
5238 const Program *programObject = getProgram(program);
5239 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
5240}
5241
5242void Context::uniformBlockBinding(GLuint program,
5243 GLuint uniformBlockIndex,
5244 GLuint uniformBlockBinding)
5245{
5246 Program *programObject = getProgram(program);
5247 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
5248}
5249
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005250GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
5251{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005252 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
5253 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005254
Jamie Madill70b5bb02017-08-28 13:32:37 -04005255 Sync *syncObject = getSync(syncHandle);
5256 Error error = syncObject->set(condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005257 if (error.isError())
5258 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04005259 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005260 handleError(error);
5261 return nullptr;
5262 }
5263
Jamie Madill70b5bb02017-08-28 13:32:37 -04005264 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005265}
5266
5267GLboolean Context::isSync(GLsync sync)
5268{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005269 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005270}
5271
5272GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
5273{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005274 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005275
5276 GLenum result = GL_WAIT_FAILED;
5277 handleError(syncObject->clientWait(flags, timeout, &result));
5278 return result;
5279}
5280
5281void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
5282{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005283 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005284 handleError(syncObject->serverWait(flags, timeout));
5285}
5286
5287void Context::getInteger64v(GLenum pname, GLint64 *params)
5288{
5289 GLenum nativeType = GL_NONE;
5290 unsigned int numParams = 0;
5291 getQueryParameterInfo(pname, &nativeType, &numParams);
5292
5293 if (nativeType == GL_INT_64_ANGLEX)
5294 {
5295 getInteger64vImpl(pname, params);
5296 }
5297 else
5298 {
5299 CastStateValues(this, nativeType, pname, numParams, params);
5300 }
5301}
5302
Jamie Madill3ef140a2017-08-26 23:11:21 -04005303void Context::getBufferParameteri64v(GLenum target, GLenum pname, GLint64 *params)
5304{
5305 Buffer *buffer = mGLState.getTargetBuffer(target);
5306 QueryBufferParameteri64v(buffer, pname, params);
5307}
5308
5309void Context::genSamplers(GLsizei count, GLuint *samplers)
5310{
5311 for (int i = 0; i < count; i++)
5312 {
5313 samplers[i] = mState.mSamplers->createSampler();
5314 }
5315}
5316
5317void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
5318{
5319 for (int i = 0; i < count; i++)
5320 {
5321 GLuint sampler = samplers[i];
5322
5323 if (mState.mSamplers->getSampler(sampler))
5324 {
5325 detachSampler(sampler);
5326 }
5327
5328 mState.mSamplers->deleteObject(this, sampler);
5329 }
5330}
5331
5332void Context::getInternalformativ(GLenum target,
5333 GLenum internalformat,
5334 GLenum pname,
5335 GLsizei bufSize,
5336 GLint *params)
5337{
5338 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
5339 QueryInternalFormativ(formatCaps, pname, bufSize, params);
5340}
5341
Jamie Madill81c2e252017-09-09 23:32:46 -04005342void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5343{
5344 Program *programObject = getProgram(program);
5345 ASSERT(programObject);
5346 if (programObject->setUniform1iv(location, count, value) ==
5347 Program::SetUniformResult::SamplerChanged)
5348 {
5349 mGLState.setObjectDirty(GL_PROGRAM);
5350 }
5351}
5352
5353void Context::onTextureChange(const Texture *texture)
5354{
5355 // Conservatively assume all textures are dirty.
5356 // TODO(jmadill): More fine-grained update.
5357 mGLState.setObjectDirty(GL_TEXTURE);
5358}
5359
Yunchao Hea336b902017-08-02 16:05:21 +08005360void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
5361{
5362 for (int i = 0; i < count; i++)
5363 {
5364 pipelines[i] = createProgramPipeline();
5365 }
5366}
5367
5368void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
5369{
5370 for (int i = 0; i < count; i++)
5371 {
5372 if (pipelines[i] != 0)
5373 {
5374 deleteProgramPipeline(pipelines[i]);
5375 }
5376 }
5377}
5378
5379GLboolean Context::isProgramPipeline(GLuint pipeline)
5380{
5381 if (pipeline == 0)
5382 {
5383 return GL_FALSE;
5384 }
5385
5386 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
5387}
5388
Jamie Madillc29968b2016-01-20 11:17:23 -05005389} // namespace gl