blob: 337cb9d70c1d2e148c14d97b06f8002b91a7a32d [file] [log] [blame]
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001//
Geoff Langeeba6e12014-02-03 13:12:30 -05002// Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7// Context.cpp: Implements the gl::Context class, managing all GL state and performing
8// rendering operations. It is the GLES2 specific implementation of EGLContext.
9
Geoff Lang2b5420c2014-11-19 14:20:15 -050010#include "libANGLE/Context.h"
apatrick@chromium.org144f2802012-07-12 01:42:34 +000011
Jamie Madill231c7f52017-04-26 13:45:37 -040012#include <string.h>
Jamie Madillb9293972015-02-19 11:07:54 -050013#include <iterator>
14#include <sstream>
Sami Väisänend59ca052016-06-21 16:10:00 +030015#include <vector>
Jamie Madillb9293972015-02-19 11:07:54 -050016
Sami Väisänene45e53b2016-05-25 10:36:04 +030017#include "common/matrix_utils.h"
Geoff Lang0b7eef72014-06-12 14:10:47 -040018#include "common/platform.h"
Jamie Madillb9293972015-02-19 11:07:54 -050019#include "common/utilities.h"
Geoff Langc339c4e2016-11-29 10:37:36 -050020#include "common/version.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050021#include "libANGLE/Buffer.h"
Jamie Madillb9293972015-02-19 11:07:54 -050022#include "libANGLE/Compiler.h"
Jamie Madill948bbe52017-06-01 13:10:42 -040023#include "libANGLE/Display.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050024#include "libANGLE/Fence.h"
25#include "libANGLE/Framebuffer.h"
26#include "libANGLE/FramebufferAttachment.h"
Sami Väisänene45e53b2016-05-25 10:36:04 +030027#include "libANGLE/Path.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050028#include "libANGLE/Program.h"
Yunchao Hea336b902017-08-02 16:05:21 +080029#include "libANGLE/ProgramPipeline.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050030#include "libANGLE/Query.h"
Jamie Madillb9293972015-02-19 11:07:54 -050031#include "libANGLE/Renderbuffer.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050032#include "libANGLE/ResourceManager.h"
33#include "libANGLE/Sampler.h"
Jamie Madill9dd0cf02014-11-24 11:38:51 -050034#include "libANGLE/Surface.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050035#include "libANGLE/Texture.h"
36#include "libANGLE/TransformFeedback.h"
37#include "libANGLE/VertexArray.h"
Kenneth Russellf2f6f652016-10-05 19:53:23 -070038#include "libANGLE/Workarounds.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040039#include "libANGLE/formatutils.h"
Martin Radev66fb8202016-07-28 11:45:20 +030040#include "libANGLE/queryconversions.h"
Geoff Langc1984ed2016-10-07 12:41:00 -040041#include "libANGLE/queryutils.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040042#include "libANGLE/renderer/ContextImpl.h"
43#include "libANGLE/renderer/EGLImplFactory.h"
Jamie Madill7b62cf92017-11-02 15:20:49 -040044#include "libANGLE/renderer/Format.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040045#include "libANGLE/validationES.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000046
Geoff Langf6db0982015-08-25 13:04:00 -040047namespace
48{
49
Jamie Madillb6664922017-07-25 12:55:04 -040050#define ANGLE_HANDLE_ERR(X) \
51 handleError(X); \
52 return;
53#define ANGLE_CONTEXT_TRY(EXPR) ANGLE_TRY_TEMPLATE(EXPR, ANGLE_HANDLE_ERR);
54
Ian Ewell3ffd78b2016-01-22 16:09:42 -050055template <typename T>
Geoff Lang4ddf5af2016-12-01 14:30:44 -050056std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager,
Sami Väisänend59ca052016-06-21 16:10:00 +030057 GLsizei numPaths,
58 const void *paths,
59 GLuint pathBase)
60{
61 std::vector<gl::Path *> ret;
62 ret.reserve(numPaths);
63
64 const auto *nameArray = static_cast<const T *>(paths);
65
66 for (GLsizei i = 0; i < numPaths; ++i)
67 {
68 const GLuint pathName = nameArray[i] + pathBase;
69
70 ret.push_back(resourceManager.getPath(pathName));
71 }
72
73 return ret;
74}
75
Geoff Lang4ddf5af2016-12-01 14:30:44 -050076std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager,
Sami Väisänend59ca052016-06-21 16:10:00 +030077 GLsizei numPaths,
78 GLenum pathNameType,
79 const void *paths,
80 GLuint pathBase)
81{
82 switch (pathNameType)
83 {
84 case GL_UNSIGNED_BYTE:
85 return GatherPaths<GLubyte>(resourceManager, numPaths, paths, pathBase);
86
87 case GL_BYTE:
88 return GatherPaths<GLbyte>(resourceManager, numPaths, paths, pathBase);
89
90 case GL_UNSIGNED_SHORT:
91 return GatherPaths<GLushort>(resourceManager, numPaths, paths, pathBase);
92
93 case GL_SHORT:
94 return GatherPaths<GLshort>(resourceManager, numPaths, paths, pathBase);
95
96 case GL_UNSIGNED_INT:
97 return GatherPaths<GLuint>(resourceManager, numPaths, paths, pathBase);
98
99 case GL_INT:
100 return GatherPaths<GLint>(resourceManager, numPaths, paths, pathBase);
101 }
102
103 UNREACHABLE();
104 return std::vector<gl::Path *>();
105}
106
107template <typename T>
Geoff Lang2186c382016-10-14 10:54:54 -0400108gl::Error GetQueryObjectParameter(gl::Query *query, GLenum pname, T *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500109{
Geoff Lang2186c382016-10-14 10:54:54 -0400110 ASSERT(query != nullptr);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500111
112 switch (pname)
113 {
114 case GL_QUERY_RESULT_EXT:
Geoff Lang2186c382016-10-14 10:54:54 -0400115 return query->getResult(params);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500116 case GL_QUERY_RESULT_AVAILABLE_EXT:
117 {
118 bool available;
Geoff Lang2186c382016-10-14 10:54:54 -0400119 gl::Error error = query->isResultAvailable(&available);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500120 if (!error.isError())
121 {
jchen10a99ed552017-09-22 08:10:32 +0800122 *params = gl::CastFromStateValue<T>(pname, static_cast<GLuint>(available));
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500123 }
124 return error;
125 }
126 default:
127 UNREACHABLE();
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500128 return gl::InternalError() << "Unreachable Error";
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500129 }
130}
131
Geoff Langf6db0982015-08-25 13:04:00 -0400132void MarkTransformFeedbackBufferUsage(gl::TransformFeedback *transformFeedback)
133{
Geoff Lang1a683462015-09-29 15:09:59 -0400134 if (transformFeedback && transformFeedback->isActive() && !transformFeedback->isPaused())
Geoff Langf6db0982015-08-25 13:04:00 -0400135 {
136 for (size_t tfBufferIndex = 0; tfBufferIndex < transformFeedback->getIndexedBufferCount();
137 tfBufferIndex++)
138 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400139 const gl::OffsetBindingPointer<gl::Buffer> &buffer =
Geoff Langf6db0982015-08-25 13:04:00 -0400140 transformFeedback->getIndexedBuffer(tfBufferIndex);
141 if (buffer.get() != nullptr)
142 {
143 buffer->onTransformFeedback();
144 }
145 }
146 }
147}
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500148
149// Attribute map queries.
Martin Radev1be913c2016-07-11 17:59:16 +0300150EGLint GetClientMajorVersion(const egl::AttributeMap &attribs)
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500151{
Ian Ewellec2c0c52016-04-05 13:46:26 -0400152 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_CLIENT_VERSION, 1));
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500153}
154
Martin Radev1be913c2016-07-11 17:59:16 +0300155EGLint GetClientMinorVersion(const egl::AttributeMap &attribs)
156{
157 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_MINOR_VERSION, 0));
158}
159
Geoff Langeb66a6e2016-10-31 13:06:12 -0400160gl::Version GetClientVersion(const egl::AttributeMap &attribs)
161{
162 return gl::Version(GetClientMajorVersion(attribs), GetClientMinorVersion(attribs));
163}
164
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500165GLenum GetResetStrategy(const egl::AttributeMap &attribs)
166{
Ian Ewellec2c0c52016-04-05 13:46:26 -0400167 EGLAttrib attrib = attribs.get(EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT,
Jeff Gilbertc5de4d22017-10-31 15:07:53 -0700168 EGL_NO_RESET_NOTIFICATION);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500169 switch (attrib)
170 {
171 case EGL_NO_RESET_NOTIFICATION:
172 return GL_NO_RESET_NOTIFICATION_EXT;
173 case EGL_LOSE_CONTEXT_ON_RESET:
174 return GL_LOSE_CONTEXT_ON_RESET_EXT;
175 default:
176 UNREACHABLE();
177 return GL_NONE;
178 }
179}
180
181bool GetRobustAccess(const egl::AttributeMap &attribs)
182{
Geoff Lang077f20a2016-11-01 10:08:02 -0400183 return (attribs.get(EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT, EGL_FALSE) == EGL_TRUE) ||
184 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR) !=
185 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500186}
187
188bool GetDebug(const egl::AttributeMap &attribs)
189{
Geoff Lang077f20a2016-11-01 10:08:02 -0400190 return (attribs.get(EGL_CONTEXT_OPENGL_DEBUG, EGL_FALSE) == EGL_TRUE) ||
191 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR) != 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500192}
193
194bool GetNoError(const egl::AttributeMap &attribs)
195{
196 return (attribs.get(EGL_CONTEXT_OPENGL_NO_ERROR_KHR, EGL_FALSE) == EGL_TRUE);
197}
198
Geoff Langc287ea62016-09-16 14:46:51 -0400199bool GetWebGLContext(const egl::AttributeMap &attribs)
200{
201 return (attribs.get(EGL_CONTEXT_WEBGL_COMPATIBILITY_ANGLE, EGL_FALSE) == EGL_TRUE);
202}
203
Geoff Langf41a7152016-09-19 15:11:17 -0400204bool GetBindGeneratesResource(const egl::AttributeMap &attribs)
205{
206 return (attribs.get(EGL_CONTEXT_BIND_GENERATES_RESOURCE_CHROMIUM, EGL_TRUE) == EGL_TRUE);
207}
208
Geoff Langfeb8c682017-02-13 16:07:35 -0500209bool GetClientArraysEnabled(const egl::AttributeMap &attribs)
210{
211 return (attribs.get(EGL_CONTEXT_CLIENT_ARRAYS_ENABLED_ANGLE, EGL_TRUE) == EGL_TRUE);
212}
213
Geoff Langb433e872017-10-05 14:01:47 -0400214bool GetRobustResourceInit(const egl::AttributeMap &attribs)
215{
216 return (attribs.get(EGL_ROBUST_RESOURCE_INITIALIZATION_ANGLE, EGL_FALSE) == EGL_TRUE);
217}
218
Martin Radev9d901792016-07-15 15:58:58 +0300219std::string GetObjectLabelFromPointer(GLsizei length, const GLchar *label)
220{
221 std::string labelName;
222 if (label != nullptr)
223 {
224 size_t labelLength = length < 0 ? strlen(label) : length;
225 labelName = std::string(label, labelLength);
226 }
227 return labelName;
228}
229
230void GetObjectLabelBase(const std::string &objectLabel,
231 GLsizei bufSize,
232 GLsizei *length,
233 GLchar *label)
234{
235 size_t writeLength = objectLabel.length();
236 if (label != nullptr && bufSize > 0)
237 {
238 writeLength = std::min(static_cast<size_t>(bufSize) - 1, objectLabel.length());
239 std::copy(objectLabel.begin(), objectLabel.begin() + writeLength, label);
240 label[writeLength] = '\0';
241 }
242
243 if (length != nullptr)
244 {
245 *length = static_cast<GLsizei>(writeLength);
246 }
247}
248
Jamie Madill0f80ed82017-09-19 00:24:56 -0400249template <typename CapT, typename MaxT>
250void LimitCap(CapT *cap, MaxT maximum)
251{
252 *cap = std::min(*cap, static_cast<CapT>(maximum));
253}
254
Geoff Langf6db0982015-08-25 13:04:00 -0400255} // anonymous namespace
256
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000257namespace gl
258{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +0000259
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400260Context::Context(rx::EGLImplFactory *implFactory,
261 const egl::Config *config,
Corentin Wallez51706ea2015-08-07 14:39:22 -0400262 const Context *shareContext,
Geoff Langce02f082017-02-06 16:46:21 -0500263 TextureManager *shareTextures,
Jamie Madill32447362017-06-28 14:53:52 -0400264 MemoryProgramCache *memoryProgramCache,
Corentin Wallezc295e512017-01-27 17:47:50 -0500265 const egl::AttributeMap &attribs,
Geoff Langb433e872017-10-05 14:01:47 -0400266 const egl::DisplayExtensions &displayExtensions)
Martin Radev1be913c2016-07-11 17:59:16 +0300267
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500268 : ValidationContext(shareContext,
Geoff Langce02f082017-02-06 16:46:21 -0500269 shareTextures,
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500270 GetClientVersion(attribs),
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700271 &mGLState,
Jamie Madillf25855c2015-11-03 11:06:18 -0500272 mCaps,
273 mTextureCaps,
274 mExtensions,
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500275 mLimitations,
276 GetNoError(attribs)),
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700277 mImplementation(implFactory->createContext(mState)),
Jamie Madill2f348d22017-06-05 10:50:59 -0400278 mCompiler(),
Corentin Walleze3b10e82015-05-20 11:06:25 -0400279 mConfig(config),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500280 mClientType(EGL_OPENGL_ES_API),
281 mHasBeenCurrent(false),
282 mContextLost(false),
283 mResetStatus(GL_NO_ERROR),
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700284 mContextLostForced(false),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500285 mResetStrategy(GetResetStrategy(attribs)),
286 mRobustAccess(GetRobustAccess(attribs)),
Jamie Madill61e16b42017-06-19 11:13:23 -0400287 mCurrentSurface(static_cast<egl::Surface *>(EGL_NO_SURFACE)),
288 mCurrentDisplay(static_cast<egl::Display *>(EGL_NO_DISPLAY)),
Jamie Madill4e0e6f82017-02-17 11:06:03 -0500289 mSurfacelessFramebuffer(nullptr),
Jamie Madille14951e2017-03-09 18:55:16 -0500290 mWebGLContext(GetWebGLContext(attribs)),
Jamie Madill32447362017-06-28 14:53:52 -0400291 mMemoryProgramCache(memoryProgramCache),
Jamie Madillb3f26b92017-07-19 15:07:41 -0400292 mScratchBuffer(1000u),
293 mZeroFilledBuffer(1000u)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000294{
Jamie Madill14bbb3f2017-09-12 15:23:01 -0400295 mImplementation->setMemoryProgramCache(memoryProgramCache);
296
Geoff Langb433e872017-10-05 14:01:47 -0400297 bool robustResourceInit = GetRobustResourceInit(attribs);
298 initCaps(displayExtensions, robustResourceInit);
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700299 initWorkarounds();
Geoff Langc0b9ef42014-07-02 10:02:37 -0400300
Jamie Madill4928b7c2017-06-20 12:57:39 -0400301 mGLState.initialize(this, GetDebug(attribs), GetBindGeneratesResource(attribs),
Jamie Madillc43be722017-07-13 16:22:14 -0400302 GetClientArraysEnabled(attribs), robustResourceInit,
303 mMemoryProgramCache != nullptr);
Régis Fénéon83107972015-02-05 12:57:44 +0100304
Shannon Woods53a94a82014-06-24 15:20:36 -0400305 mFenceNVHandleAllocator.setBaseHandle(0);
Geoff Lang7dca1862013-07-30 16:30:46 -0400306
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000307 // [OpenGL ES 2.0.24] section 3.7 page 83:
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);
Corentin Wallez29a20992017-11-06 18:23:16 -0500393 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500394 // No dirty objects.
395
396 // Readpixels uses the pack state and read FBO
Jamie Madillc67323a2017-11-02 23:11:41 -0400397 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500398 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500399 mReadPixelsDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
400
401 mClearDirtyBits.set(State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED);
402 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
403 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR);
404 mClearDirtyBits.set(State::DIRTY_BIT_VIEWPORT);
405 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_COLOR);
406 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_DEPTH);
407 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_STENCIL);
408 mClearDirtyBits.set(State::DIRTY_BIT_COLOR_MASK);
409 mClearDirtyBits.set(State::DIRTY_BIT_DEPTH_MASK);
410 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT);
411 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_BACK);
412 mClearDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
413
414 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
415 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR);
Geoff Lang1d2c41d2016-10-19 16:14:46 -0700416 mBlitDirtyBits.set(State::DIRTY_BIT_FRAMEBUFFER_SRGB);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500417 mBlitDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
418 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
Jamie Madill437fa652016-05-03 15:13:24 -0400419
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400420 handleError(mImplementation->initialize());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000421}
422
Jamie Madill4928b7c2017-06-20 12:57:39 -0400423egl::Error Context::onDestroy(const egl::Display *display)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000424{
Corentin Wallez80b24112015-08-25 16:41:57 -0400425 for (auto fence : mFenceNVMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000426 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400427 SafeDelete(fence.second);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000428 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400429 mFenceNVMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000430
Corentin Wallez80b24112015-08-25 16:41:57 -0400431 for (auto query : mQueryMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000432 {
Geoff Langf0aa8422015-09-29 15:08:34 -0400433 if (query.second != nullptr)
434 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400435 query.second->release(this);
Geoff Langf0aa8422015-09-29 15:08:34 -0400436 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000437 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400438 mQueryMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000439
Corentin Wallez80b24112015-08-25 16:41:57 -0400440 for (auto vertexArray : mVertexArrayMap)
Jamie Madill57a89722013-07-02 11:57:03 -0400441 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400442 if (vertexArray.second)
443 {
444 vertexArray.second->onDestroy(this);
445 }
Jamie Madill57a89722013-07-02 11:57:03 -0400446 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400447 mVertexArrayMap.clear();
Jamie Madill57a89722013-07-02 11:57:03 -0400448
Corentin Wallez80b24112015-08-25 16:41:57 -0400449 for (auto transformFeedback : mTransformFeedbackMap)
Geoff Langc8058452014-02-03 12:04:11 -0500450 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500451 if (transformFeedback.second != nullptr)
452 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500453 transformFeedback.second->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500454 }
Geoff Langc8058452014-02-03 12:04:11 -0500455 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400456 mTransformFeedbackMap.clear();
Geoff Langc8058452014-02-03 12:04:11 -0500457
Jamie Madilldedd7b92014-11-05 16:30:36 -0500458 for (auto &zeroTexture : mZeroTextures)
Geoff Lang76b10c92014-09-05 16:28:14 -0400459 {
Jamie Madill71c88b32017-09-14 22:20:29 -0400460 ANGLE_TRY(zeroTexture.second->onDestroy(this));
Jamie Madill4928b7c2017-06-20 12:57:39 -0400461 zeroTexture.second.set(this, nullptr);
Geoff Lang76b10c92014-09-05 16:28:14 -0400462 }
463 mZeroTextures.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000464
Corentin Wallezccab69d2017-01-27 16:57:15 -0500465 SafeDelete(mSurfacelessFramebuffer);
466
Jamie Madill4928b7c2017-06-20 12:57:39 -0400467 ANGLE_TRY(releaseSurface(display));
Jamie Madill2f348d22017-06-05 10:50:59 -0400468 releaseShaderCompiler();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500469
Jamie Madill4928b7c2017-06-20 12:57:39 -0400470 mGLState.reset(this);
471
Jamie Madill6c1f6712017-02-14 19:08:04 -0500472 mState.mBuffers->release(this);
473 mState.mShaderPrograms->release(this);
474 mState.mTextures->release(this);
475 mState.mRenderbuffers->release(this);
476 mState.mSamplers->release(this);
Jamie Madill70b5bb02017-08-28 13:32:37 -0400477 mState.mSyncs->release(this);
Jamie Madill6c1f6712017-02-14 19:08:04 -0500478 mState.mPaths->release(this);
479 mState.mFramebuffers->release(this);
Yunchao Hea336b902017-08-02 16:05:21 +0800480 mState.mPipelines->release(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400481
Jamie Madill76e471e2017-10-21 09:56:01 -0400482 mImplementation->onDestroy(this);
483
Jamie Madill4928b7c2017-06-20 12:57:39 -0400484 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000485}
486
Jamie Madill70ee0f62017-02-06 16:04:20 -0500487Context::~Context()
488{
489}
490
Jamie Madill4928b7c2017-06-20 12:57:39 -0400491egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000492{
Jamie Madill61e16b42017-06-19 11:13:23 -0400493 mCurrentDisplay = display;
494
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000495 if (!mHasBeenCurrent)
496 {
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000497 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500498 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400499 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000500
Corentin Wallezc295e512017-01-27 17:47:50 -0500501 int width = 0;
502 int height = 0;
503 if (surface != nullptr)
504 {
505 width = surface->getWidth();
506 height = surface->getHeight();
507 }
508
509 mGLState.setViewportParams(0, 0, width, height);
510 mGLState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000511
512 mHasBeenCurrent = true;
513 }
514
Jamie Madill1b94d432015-08-07 13:23:23 -0400515 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700516 mGLState.setAllDirtyBits();
Jamie Madill81c2e252017-09-09 23:32:46 -0400517 mGLState.setAllDirtyObjects();
Jamie Madill1b94d432015-08-07 13:23:23 -0400518
Jamie Madill4928b7c2017-06-20 12:57:39 -0400519 ANGLE_TRY(releaseSurface(display));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500520
521 Framebuffer *newDefault = nullptr;
522 if (surface != nullptr)
523 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400524 ANGLE_TRY(surface->setIsCurrent(this, true));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500525 mCurrentSurface = surface;
526 newDefault = surface->getDefaultFramebuffer();
527 }
528 else
529 {
530 if (mSurfacelessFramebuffer == nullptr)
531 {
532 mSurfacelessFramebuffer = new Framebuffer(mImplementation.get());
533 }
534
535 newDefault = mSurfacelessFramebuffer;
536 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000537
Corentin Wallez37c39792015-08-20 14:19:46 -0400538 // Update default framebuffer, the binding of the previous default
539 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400540 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700541 if (mGLState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400542 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700543 mGLState.setReadFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400544 }
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700545 if (mGLState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400546 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700547 mGLState.setDrawFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400548 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500549 mState.mFramebuffers->setDefaultFramebuffer(newDefault);
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400550 }
Ian Ewell292f0052016-02-04 10:37:32 -0500551
552 // Notify the renderer of a context switch
Jamie Madill4928b7c2017-06-20 12:57:39 -0400553 mImplementation->onMakeCurrent(this);
554 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000555}
556
Jamie Madill4928b7c2017-06-20 12:57:39 -0400557egl::Error Context::releaseSurface(const egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400558{
Corentin Wallez37c39792015-08-20 14:19:46 -0400559 // Remove the default framebuffer
Corentin Wallezc295e512017-01-27 17:47:50 -0500560 Framebuffer *currentDefault = nullptr;
561 if (mCurrentSurface != nullptr)
Corentin Wallez51706ea2015-08-07 14:39:22 -0400562 {
Corentin Wallezc295e512017-01-27 17:47:50 -0500563 currentDefault = mCurrentSurface->getDefaultFramebuffer();
564 }
565 else if (mSurfacelessFramebuffer != nullptr)
566 {
567 currentDefault = mSurfacelessFramebuffer;
Corentin Wallez51706ea2015-08-07 14:39:22 -0400568 }
569
Corentin Wallezc295e512017-01-27 17:47:50 -0500570 if (mGLState.getReadFramebuffer() == currentDefault)
571 {
572 mGLState.setReadFramebufferBinding(nullptr);
573 }
574 if (mGLState.getDrawFramebuffer() == currentDefault)
575 {
576 mGLState.setDrawFramebufferBinding(nullptr);
577 }
578 mState.mFramebuffers->setDefaultFramebuffer(nullptr);
579
580 if (mCurrentSurface)
581 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400582 ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
Corentin Wallezc295e512017-01-27 17:47:50 -0500583 mCurrentSurface = nullptr;
584 }
Jamie Madill4928b7c2017-06-20 12:57:39 -0400585
586 return egl::NoError();
Jamie Madill77a72f62015-04-14 11:18:32 -0400587}
588
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000589GLuint Context::createBuffer()
590{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500591 return mState.mBuffers->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000592}
593
594GLuint Context::createProgram()
595{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500596 return mState.mShaderPrograms->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000597}
598
599GLuint Context::createShader(GLenum type)
600{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500601 return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000602}
603
604GLuint Context::createTexture()
605{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500606 return mState.mTextures->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000607}
608
609GLuint Context::createRenderbuffer()
610{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500611 return mState.mRenderbuffers->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000612}
613
Sami Väisänene45e53b2016-05-25 10:36:04 +0300614GLuint Context::createPaths(GLsizei range)
615{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500616 auto resultOrError = mState.mPaths->createPaths(mImplementation.get(), range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300617 if (resultOrError.isError())
618 {
619 handleError(resultOrError.getError());
620 return 0;
621 }
622 return resultOrError.getResult();
623}
624
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000625// Returns an unused framebuffer name
626GLuint Context::createFramebuffer()
627{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500628 return mState.mFramebuffers->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000629}
630
Jamie Madill33dc8432013-07-26 11:55:05 -0400631GLuint Context::createFenceNV()
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000632{
Jamie Madill33dc8432013-07-26 11:55:05 -0400633 GLuint handle = mFenceNVHandleAllocator.allocate();
Jamie Madill96a483b2017-06-27 16:49:21 -0400634 mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV()));
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000635 return handle;
636}
637
Yunchao Hea336b902017-08-02 16:05:21 +0800638GLuint Context::createProgramPipeline()
639{
640 return mState.mPipelines->createProgramPipeline();
641}
642
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000643void Context::deleteBuffer(GLuint buffer)
644{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500645 if (mState.mBuffers->getBuffer(buffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000646 {
647 detachBuffer(buffer);
648 }
Jamie Madill893ab082014-05-16 16:56:10 -0400649
Jamie Madill6c1f6712017-02-14 19:08:04 -0500650 mState.mBuffers->deleteObject(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000651}
652
653void Context::deleteShader(GLuint shader)
654{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500655 mState.mShaderPrograms->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000656}
657
658void Context::deleteProgram(GLuint program)
659{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500660 mState.mShaderPrograms->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000661}
662
663void Context::deleteTexture(GLuint texture)
664{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500665 if (mState.mTextures->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000666 {
667 detachTexture(texture);
668 }
669
Jamie Madill6c1f6712017-02-14 19:08:04 -0500670 mState.mTextures->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000671}
672
673void Context::deleteRenderbuffer(GLuint renderbuffer)
674{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500675 if (mState.mRenderbuffers->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000676 {
677 detachRenderbuffer(renderbuffer);
678 }
Jamie Madill893ab082014-05-16 16:56:10 -0400679
Jamie Madill6c1f6712017-02-14 19:08:04 -0500680 mState.mRenderbuffers->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000681}
682
Jamie Madill7f0c5a42017-08-26 22:43:26 -0400683void Context::deleteSync(GLsync sync)
Jamie Madillcd055f82013-07-26 11:55:15 -0400684{
685 // The spec specifies the underlying Fence object is not deleted until all current
686 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
687 // and since our API is currently designed for being called from a single thread, we can delete
688 // the fence immediately.
Jamie Madill70b5bb02017-08-28 13:32:37 -0400689 mState.mSyncs->deleteObject(this, static_cast<GLuint>(reinterpret_cast<uintptr_t>(sync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400690}
691
Yunchao Hea336b902017-08-02 16:05:21 +0800692void Context::deleteProgramPipeline(GLuint pipeline)
693{
694 if (mState.mPipelines->getProgramPipeline(pipeline))
695 {
696 detachProgramPipeline(pipeline);
697 }
698
699 mState.mPipelines->deleteObject(this, pipeline);
700}
701
Sami Väisänene45e53b2016-05-25 10:36:04 +0300702void Context::deletePaths(GLuint first, GLsizei range)
703{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500704 mState.mPaths->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300705}
706
707bool Context::hasPathData(GLuint path) const
708{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500709 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300710 if (pathObj == nullptr)
711 return false;
712
713 return pathObj->hasPathData();
714}
715
716bool Context::hasPath(GLuint path) const
717{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500718 return mState.mPaths->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300719}
720
721void Context::setPathCommands(GLuint path,
722 GLsizei numCommands,
723 const GLubyte *commands,
724 GLsizei numCoords,
725 GLenum coordType,
726 const void *coords)
727{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500728 auto *pathObject = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300729
730 handleError(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
731}
732
733void Context::setPathParameterf(GLuint path, GLenum pname, GLfloat value)
734{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500735 auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300736
737 switch (pname)
738 {
739 case GL_PATH_STROKE_WIDTH_CHROMIUM:
740 pathObj->setStrokeWidth(value);
741 break;
742 case GL_PATH_END_CAPS_CHROMIUM:
743 pathObj->setEndCaps(static_cast<GLenum>(value));
744 break;
745 case GL_PATH_JOIN_STYLE_CHROMIUM:
746 pathObj->setJoinStyle(static_cast<GLenum>(value));
747 break;
748 case GL_PATH_MITER_LIMIT_CHROMIUM:
749 pathObj->setMiterLimit(value);
750 break;
751 case GL_PATH_STROKE_BOUND_CHROMIUM:
752 pathObj->setStrokeBound(value);
753 break;
754 default:
755 UNREACHABLE();
756 break;
757 }
758}
759
760void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value) const
761{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500762 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300763
764 switch (pname)
765 {
766 case GL_PATH_STROKE_WIDTH_CHROMIUM:
767 *value = pathObj->getStrokeWidth();
768 break;
769 case GL_PATH_END_CAPS_CHROMIUM:
770 *value = static_cast<GLfloat>(pathObj->getEndCaps());
771 break;
772 case GL_PATH_JOIN_STYLE_CHROMIUM:
773 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
774 break;
775 case GL_PATH_MITER_LIMIT_CHROMIUM:
776 *value = pathObj->getMiterLimit();
777 break;
778 case GL_PATH_STROKE_BOUND_CHROMIUM:
779 *value = pathObj->getStrokeBound();
780 break;
781 default:
782 UNREACHABLE();
783 break;
784 }
785}
786
787void Context::setPathStencilFunc(GLenum func, GLint ref, GLuint mask)
788{
789 mGLState.setPathStencilFunc(func, ref, mask);
790}
791
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000792void Context::deleteFramebuffer(GLuint framebuffer)
793{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500794 if (mState.mFramebuffers->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000795 {
796 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000797 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500798
Jamie Madill6c1f6712017-02-14 19:08:04 -0500799 mState.mFramebuffers->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000800}
801
Jamie Madill33dc8432013-07-26 11:55:05 -0400802void Context::deleteFenceNV(GLuint fence)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000803{
Jamie Madill96a483b2017-06-27 16:49:21 -0400804 FenceNV *fenceObject = nullptr;
805 if (mFenceNVMap.erase(fence, &fenceObject))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000806 {
Jamie Madill96a483b2017-06-27 16:49:21 -0400807 mFenceNVHandleAllocator.release(fence);
808 delete fenceObject;
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000809 }
810}
811
Geoff Lang70d0f492015-12-10 17:45:46 -0500812Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000813{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500814 return mState.mBuffers->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000815}
816
Jamie Madill570f7c82014-07-03 10:38:54 -0400817Texture *Context::getTexture(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000818{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500819 return mState.mTextures->getTexture(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000820}
821
Geoff Lang70d0f492015-12-10 17:45:46 -0500822Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000823{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500824 return mState.mRenderbuffers->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000825}
826
Jamie Madill70b5bb02017-08-28 13:32:37 -0400827Sync *Context::getSync(GLsync handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400828{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400829 return mState.mSyncs->getSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400830}
831
Jamie Madill57a89722013-07-02 11:57:03 -0400832VertexArray *Context::getVertexArray(GLuint handle) const
833{
Jamie Madill96a483b2017-06-27 16:49:21 -0400834 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -0400835}
836
Jamie Madilldc356042013-07-19 16:36:57 -0400837Sampler *Context::getSampler(GLuint handle) const
838{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500839 return mState.mSamplers->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400840}
841
Geoff Langc8058452014-02-03 12:04:11 -0500842TransformFeedback *Context::getTransformFeedback(GLuint handle) const
843{
Jamie Madill96a483b2017-06-27 16:49:21 -0400844 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -0500845}
846
Yunchao Hea336b902017-08-02 16:05:21 +0800847ProgramPipeline *Context::getProgramPipeline(GLuint handle) const
848{
849 return mState.mPipelines->getProgramPipeline(handle);
850}
851
Geoff Lang70d0f492015-12-10 17:45:46 -0500852LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
853{
854 switch (identifier)
855 {
856 case GL_BUFFER:
857 return getBuffer(name);
858 case GL_SHADER:
859 return getShader(name);
860 case GL_PROGRAM:
861 return getProgram(name);
862 case GL_VERTEX_ARRAY:
863 return getVertexArray(name);
864 case GL_QUERY:
865 return getQuery(name);
866 case GL_TRANSFORM_FEEDBACK:
867 return getTransformFeedback(name);
868 case GL_SAMPLER:
869 return getSampler(name);
870 case GL_TEXTURE:
871 return getTexture(name);
872 case GL_RENDERBUFFER:
873 return getRenderbuffer(name);
874 case GL_FRAMEBUFFER:
875 return getFramebuffer(name);
876 default:
877 UNREACHABLE();
878 return nullptr;
879 }
880}
881
882LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
883{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400884 return getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
Geoff Lang70d0f492015-12-10 17:45:46 -0500885}
886
Martin Radev9d901792016-07-15 15:58:58 +0300887void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
888{
889 LabeledObject *object = getLabeledObject(identifier, name);
890 ASSERT(object != nullptr);
891
892 std::string labelName = GetObjectLabelFromPointer(length, label);
893 object->setLabel(labelName);
Jamie Madill8693bdb2017-09-02 15:32:14 -0400894
895 // TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the
896 // specified object is active until we do this.
897 mGLState.setObjectDirty(identifier);
Martin Radev9d901792016-07-15 15:58:58 +0300898}
899
900void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
901{
902 LabeledObject *object = getLabeledObjectFromPtr(ptr);
903 ASSERT(object != nullptr);
904
905 std::string labelName = GetObjectLabelFromPointer(length, label);
906 object->setLabel(labelName);
907}
908
909void Context::getObjectLabel(GLenum identifier,
910 GLuint name,
911 GLsizei bufSize,
912 GLsizei *length,
913 GLchar *label) const
914{
915 LabeledObject *object = getLabeledObject(identifier, name);
916 ASSERT(object != nullptr);
917
918 const std::string &objectLabel = object->getLabel();
919 GetObjectLabelBase(objectLabel, bufSize, length, label);
920}
921
922void Context::getObjectPtrLabel(const void *ptr,
923 GLsizei bufSize,
924 GLsizei *length,
925 GLchar *label) const
926{
927 LabeledObject *object = getLabeledObjectFromPtr(ptr);
928 ASSERT(object != nullptr);
929
930 const std::string &objectLabel = object->getLabel();
931 GetObjectLabelBase(objectLabel, bufSize, length, label);
932}
933
Jamie Madilldc356042013-07-19 16:36:57 -0400934bool Context::isSampler(GLuint samplerName) const
935{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500936 return mState.mSamplers->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -0400937}
938
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500939void Context::bindArrayBuffer(GLuint bufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000940{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500941 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400942 mGLState.setArrayBufferBinding(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000943}
944
Jiajia Qin9d7d0b12016-11-29 16:30:31 +0800945void Context::bindDrawIndirectBuffer(GLuint bufferHandle)
946{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500947 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400948 mGLState.setDrawIndirectBufferBinding(this, buffer);
Jiajia Qin9d7d0b12016-11-29 16:30:31 +0800949}
950
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500951void Context::bindElementArrayBuffer(GLuint bufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000952{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500953 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400954 mGLState.setElementArrayBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000955}
956
Jamie Madilldedd7b92014-11-05 16:30:36 -0500957void Context::bindTexture(GLenum target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000958{
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500959 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000960
Jamie Madilldedd7b92014-11-05 16:30:36 -0500961 if (handle == 0)
962 {
963 texture = mZeroTextures[target].get();
964 }
965 else
966 {
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500967 texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500968 }
969
970 ASSERT(texture);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400971 mGLState.setSamplerTexture(this, target, texture);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +0000972}
973
Jamie Madill5bf9ff42016-02-01 11:13:03 -0500974void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000975{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500976 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
977 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700978 mGLState.setReadFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000979}
980
Jamie Madill5bf9ff42016-02-01 11:13:03 -0500981void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000982{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500983 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
984 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700985 mGLState.setDrawFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000986}
987
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500988void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -0400989{
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500990 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700991 mGLState.setVertexArrayBinding(vertexArray);
Jamie Madill57a89722013-07-02 11:57:03 -0400992}
993
Shao80957d92017-02-20 21:25:59 +0800994void Context::bindVertexBuffer(GLuint bindingIndex,
995 GLuint bufferHandle,
996 GLintptr offset,
997 GLsizei stride)
998{
999 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001000 mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Shao80957d92017-02-20 21:25:59 +08001001}
1002
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001003void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -04001004{
Geoff Lang76b10c92014-09-05 16:28:14 -04001005 ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -04001006 Sampler *sampler =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001007 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001008 mGLState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04001009}
1010
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001011void Context::bindImageTexture(GLuint unit,
1012 GLuint texture,
1013 GLint level,
1014 GLboolean layered,
1015 GLint layer,
1016 GLenum access,
1017 GLenum format)
1018{
1019 Texture *tex = mState.mTextures->getTexture(texture);
1020 mGLState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
1021}
1022
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001023void Context::bindGenericUniformBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001024{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001025 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001026 mGLState.setGenericUniformBufferBinding(this, buffer);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001027}
1028
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001029void Context::bindIndexedUniformBuffer(GLuint bufferHandle,
1030 GLuint index,
1031 GLintptr offset,
1032 GLsizeiptr size)
shannon.woods%transgaming.com@gtempaccount.com34089352013-04-13 03:36:57 +00001033{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001034 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001035 mGLState.setIndexedUniformBufferBinding(this, index, buffer, offset, size);
shannon.woods%transgaming.com@gtempaccount.com34089352013-04-13 03:36:57 +00001036}
1037
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001038void Context::bindGenericTransformFeedbackBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001039{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001040 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001041 mGLState.getCurrentTransformFeedback()->bindGenericBuffer(this, buffer);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001042}
1043
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001044void Context::bindIndexedTransformFeedbackBuffer(GLuint bufferHandle,
1045 GLuint index,
1046 GLintptr offset,
1047 GLsizeiptr size)
shannon.woods%transgaming.com@gtempaccount.com34089352013-04-13 03:36:57 +00001048{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001049 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001050 mGLState.getCurrentTransformFeedback()->bindIndexedBuffer(this, index, buffer, offset, size);
shannon.woods%transgaming.com@gtempaccount.com34089352013-04-13 03:36:57 +00001051}
1052
Jiajia Qin6eafb042016-12-27 17:04:07 +08001053void Context::bindGenericAtomicCounterBuffer(GLuint bufferHandle)
1054{
1055 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001056 mGLState.setGenericAtomicCounterBufferBinding(this, buffer);
Jiajia Qin6eafb042016-12-27 17:04:07 +08001057}
1058
1059void Context::bindIndexedAtomicCounterBuffer(GLuint bufferHandle,
1060 GLuint index,
1061 GLintptr offset,
1062 GLsizeiptr size)
1063{
1064 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001065 mGLState.setIndexedAtomicCounterBufferBinding(this, index, buffer, offset, size);
Jiajia Qin6eafb042016-12-27 17:04:07 +08001066}
1067
Jiajia Qinf546e7d2017-03-27 14:12:59 +08001068void Context::bindGenericShaderStorageBuffer(GLuint bufferHandle)
1069{
1070 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001071 mGLState.setGenericShaderStorageBufferBinding(this, buffer);
Jiajia Qinf546e7d2017-03-27 14:12:59 +08001072}
1073
1074void Context::bindIndexedShaderStorageBuffer(GLuint bufferHandle,
1075 GLuint index,
1076 GLintptr offset,
1077 GLsizeiptr size)
1078{
1079 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001080 mGLState.setIndexedShaderStorageBufferBinding(this, index, buffer, offset, size);
Jiajia Qinf546e7d2017-03-27 14:12:59 +08001081}
1082
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001083void Context::bindCopyReadBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001084{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001085 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001086 mGLState.setCopyReadBufferBinding(this, buffer);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001087}
1088
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001089void Context::bindCopyWriteBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001090{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001091 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001092 mGLState.setCopyWriteBufferBinding(this, buffer);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001093}
1094
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001095void Context::bindPixelPackBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001096{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001097 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001098 mGLState.setPixelPackBufferBinding(this, buffer);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001099}
1100
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001101void Context::bindPixelUnpackBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001102{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001103 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001104 mGLState.setPixelUnpackBufferBinding(this, buffer);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001105}
1106
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001107void Context::useProgram(GLuint program)
1108{
Jamie Madill6c1f6712017-02-14 19:08:04 -05001109 mGLState.setProgram(this, getProgram(program));
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001110}
1111
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001112void Context::bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001113{
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001114 ASSERT(target == GL_TRANSFORM_FEEDBACK);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001115 TransformFeedback *transformFeedback =
1116 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001117 mGLState.setTransformFeedbackBinding(this, transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -05001118}
1119
Yunchao Hea336b902017-08-02 16:05:21 +08001120void Context::bindProgramPipeline(GLuint pipelineHandle)
1121{
1122 ProgramPipeline *pipeline =
1123 mState.mPipelines->checkProgramPipelineAllocation(mImplementation.get(), pipelineHandle);
1124 mGLState.setProgramPipelineBinding(this, pipeline);
1125}
1126
Jamie Madillf0e04492017-08-26 15:28:42 -04001127void Context::beginQuery(GLenum target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001128{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001129 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001130 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001131
Geoff Lang5aad9672014-09-08 11:10:42 -04001132 // begin query
Jamie Madillf0e04492017-08-26 15:28:42 -04001133 ANGLE_CONTEXT_TRY(queryObject->begin());
Geoff Lang5aad9672014-09-08 11:10:42 -04001134
1135 // set query as active for specified target only if begin succeeded
Jamie Madill4928b7c2017-06-20 12:57:39 -04001136 mGLState.setActiveQuery(this, target, queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001137}
1138
Jamie Madillf0e04492017-08-26 15:28:42 -04001139void Context::endQuery(GLenum target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001140{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001141 Query *queryObject = mGLState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001142 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001143
Jamie Madillf0e04492017-08-26 15:28:42 -04001144 handleError(queryObject->end());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001145
Geoff Lang5aad9672014-09-08 11:10:42 -04001146 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madill4928b7c2017-06-20 12:57:39 -04001147 mGLState.setActiveQuery(this, target, nullptr);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001148}
1149
Jamie Madillf0e04492017-08-26 15:28:42 -04001150void Context::queryCounter(GLuint id, GLenum target)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001151{
1152 ASSERT(target == GL_TIMESTAMP_EXT);
1153
1154 Query *queryObject = getQuery(id, true, target);
1155 ASSERT(queryObject);
1156
Jamie Madillf0e04492017-08-26 15:28:42 -04001157 handleError(queryObject->queryCounter());
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001158}
1159
1160void Context::getQueryiv(GLenum target, GLenum pname, GLint *params)
1161{
1162 switch (pname)
1163 {
1164 case GL_CURRENT_QUERY_EXT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001165 params[0] = mGLState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001166 break;
1167 case GL_QUERY_COUNTER_BITS_EXT:
1168 switch (target)
1169 {
1170 case GL_TIME_ELAPSED_EXT:
1171 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1172 break;
1173 case GL_TIMESTAMP_EXT:
1174 params[0] = getExtensions().queryCounterBitsTimestamp;
1175 break;
1176 default:
1177 UNREACHABLE();
1178 params[0] = 0;
1179 break;
1180 }
1181 break;
1182 default:
1183 UNREACHABLE();
1184 return;
1185 }
1186}
1187
Geoff Lang2186c382016-10-14 10:54:54 -04001188void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001189{
Geoff Lang2186c382016-10-14 10:54:54 -04001190 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001191}
1192
Geoff Lang2186c382016-10-14 10:54:54 -04001193void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001194{
Geoff Lang2186c382016-10-14 10:54:54 -04001195 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001196}
1197
Geoff Lang2186c382016-10-14 10:54:54 -04001198void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001199{
Geoff Lang2186c382016-10-14 10:54:54 -04001200 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001201}
1202
Geoff Lang2186c382016-10-14 10:54:54 -04001203void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001204{
Geoff Lang2186c382016-10-14 10:54:54 -04001205 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001206}
1207
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001208Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001209{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001210 return mState.mFramebuffers->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001211}
1212
Jamie Madill2f348d22017-06-05 10:50:59 -04001213FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001214{
Jamie Madill96a483b2017-06-27 16:49:21 -04001215 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001216}
1217
Jamie Madill2f348d22017-06-05 10:50:59 -04001218Query *Context::getQuery(GLuint handle, bool create, GLenum type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001219{
Jamie Madill96a483b2017-06-27 16:49:21 -04001220 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001221 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001222 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001223 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001224
1225 Query *query = mQueryMap.query(handle);
1226 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001227 {
Jamie Madill96a483b2017-06-27 16:49:21 -04001228 query = new Query(mImplementation->createQuery(type), handle);
1229 query->addRef();
1230 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001231 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001232 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001233}
1234
Geoff Lang70d0f492015-12-10 17:45:46 -05001235Query *Context::getQuery(GLuint handle) const
1236{
Jamie Madill96a483b2017-06-27 16:49:21 -04001237 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001238}
1239
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001240Texture *Context::getTargetTexture(GLenum target) const
1241{
Ian Ewellbda75592016-04-18 17:25:54 -04001242 ASSERT(ValidTextureTarget(this, target) || ValidTextureExternalTarget(this, target));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001243 return mGLState.getTargetTexture(target);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001244}
1245
Geoff Lang76b10c92014-09-05 16:28:14 -04001246Texture *Context::getSamplerTexture(unsigned int sampler, GLenum type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001247{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001248 return mGLState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001249}
1250
Geoff Lang492a7e42014-11-05 13:27:06 -05001251Compiler *Context::getCompiler() const
1252{
Jamie Madill2f348d22017-06-05 10:50:59 -04001253 if (mCompiler.get() == nullptr)
1254 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001255 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001256 }
1257 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001258}
1259
Jamie Madillc1d770e2017-04-13 17:31:24 -04001260void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001261{
1262 switch (pname)
1263 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001264 case GL_SHADER_COMPILER:
1265 *params = GL_TRUE;
1266 break;
1267 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1268 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1269 break;
1270 default:
1271 mGLState.getBooleanv(pname, params);
1272 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001273 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001274}
1275
Jamie Madillc1d770e2017-04-13 17:31:24 -04001276void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001277{
Shannon Woods53a94a82014-06-24 15:20:36 -04001278 // Queries about context capabilities and maximums are answered by Context.
1279 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001280 switch (pname)
1281 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001282 case GL_ALIASED_LINE_WIDTH_RANGE:
1283 params[0] = mCaps.minAliasedLineWidth;
1284 params[1] = mCaps.maxAliasedLineWidth;
1285 break;
1286 case GL_ALIASED_POINT_SIZE_RANGE:
1287 params[0] = mCaps.minAliasedPointSize;
1288 params[1] = mCaps.maxAliasedPointSize;
1289 break;
1290 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1291 ASSERT(mExtensions.textureFilterAnisotropic);
1292 *params = mExtensions.maxTextureAnisotropy;
1293 break;
1294 case GL_MAX_TEXTURE_LOD_BIAS:
1295 *params = mCaps.maxLODBias;
1296 break;
1297
1298 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1299 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1300 {
1301 ASSERT(mExtensions.pathRendering);
1302 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1303 memcpy(params, m, 16 * sizeof(GLfloat));
1304 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001305 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001306
Jamie Madill231c7f52017-04-26 13:45:37 -04001307 default:
1308 mGLState.getFloatv(pname, params);
1309 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001310 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001311}
1312
Jamie Madillc1d770e2017-04-13 17:31:24 -04001313void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001314{
Shannon Woods53a94a82014-06-24 15:20:36 -04001315 // Queries about context capabilities and maximums are answered by Context.
1316 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001317
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001318 switch (pname)
1319 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001320 case GL_MAX_VERTEX_ATTRIBS:
1321 *params = mCaps.maxVertexAttributes;
1322 break;
1323 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1324 *params = mCaps.maxVertexUniformVectors;
1325 break;
1326 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
1327 *params = mCaps.maxVertexUniformComponents;
1328 break;
1329 case GL_MAX_VARYING_VECTORS:
1330 *params = mCaps.maxVaryingVectors;
1331 break;
1332 case GL_MAX_VARYING_COMPONENTS:
1333 *params = mCaps.maxVertexOutputComponents;
1334 break;
1335 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1336 *params = mCaps.maxCombinedTextureImageUnits;
1337 break;
1338 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
1339 *params = mCaps.maxVertexTextureImageUnits;
1340 break;
1341 case GL_MAX_TEXTURE_IMAGE_UNITS:
1342 *params = mCaps.maxTextureImageUnits;
1343 break;
1344 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1345 *params = mCaps.maxFragmentUniformVectors;
1346 break;
1347 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
1348 *params = mCaps.maxFragmentUniformComponents;
1349 break;
1350 case GL_MAX_RENDERBUFFER_SIZE:
1351 *params = mCaps.maxRenderbufferSize;
1352 break;
1353 case GL_MAX_COLOR_ATTACHMENTS_EXT:
1354 *params = mCaps.maxColorAttachments;
1355 break;
1356 case GL_MAX_DRAW_BUFFERS_EXT:
1357 *params = mCaps.maxDrawBuffers;
1358 break;
1359 // case GL_FRAMEBUFFER_BINDING: // now equivalent to
1360 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
1361 case GL_SUBPIXEL_BITS:
1362 *params = 4;
1363 break;
1364 case GL_MAX_TEXTURE_SIZE:
1365 *params = mCaps.max2DTextureSize;
1366 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001367 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
1368 *params = mCaps.maxRectangleTextureSize;
1369 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001370 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1371 *params = mCaps.maxCubeMapTextureSize;
1372 break;
1373 case GL_MAX_3D_TEXTURE_SIZE:
1374 *params = mCaps.max3DTextureSize;
1375 break;
1376 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1377 *params = mCaps.maxArrayTextureLayers;
1378 break;
1379 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1380 *params = mCaps.uniformBufferOffsetAlignment;
1381 break;
1382 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1383 *params = mCaps.maxUniformBufferBindings;
1384 break;
1385 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
1386 *params = mCaps.maxVertexUniformBlocks;
1387 break;
1388 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
1389 *params = mCaps.maxFragmentUniformBlocks;
1390 break;
1391 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1392 *params = mCaps.maxCombinedTextureImageUnits;
1393 break;
1394 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1395 *params = mCaps.maxVertexOutputComponents;
1396 break;
1397 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1398 *params = mCaps.maxFragmentInputComponents;
1399 break;
1400 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1401 *params = mCaps.minProgramTexelOffset;
1402 break;
1403 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1404 *params = mCaps.maxProgramTexelOffset;
1405 break;
1406 case GL_MAJOR_VERSION:
1407 *params = getClientVersion().major;
1408 break;
1409 case GL_MINOR_VERSION:
1410 *params = getClientVersion().minor;
1411 break;
1412 case GL_MAX_ELEMENTS_INDICES:
1413 *params = mCaps.maxElementsIndices;
1414 break;
1415 case GL_MAX_ELEMENTS_VERTICES:
1416 *params = mCaps.maxElementsVertices;
1417 break;
1418 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1419 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1420 break;
1421 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1422 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1423 break;
1424 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1425 *params = mCaps.maxTransformFeedbackSeparateComponents;
1426 break;
1427 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1428 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1429 break;
1430 case GL_MAX_SAMPLES_ANGLE:
1431 *params = mCaps.maxSamples;
1432 break;
1433 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001434 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001435 params[0] = mCaps.maxViewportWidth;
1436 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001437 }
1438 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001439 case GL_COMPRESSED_TEXTURE_FORMATS:
1440 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1441 params);
1442 break;
1443 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1444 *params = mResetStrategy;
1445 break;
1446 case GL_NUM_SHADER_BINARY_FORMATS:
1447 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1448 break;
1449 case GL_SHADER_BINARY_FORMATS:
1450 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1451 break;
1452 case GL_NUM_PROGRAM_BINARY_FORMATS:
1453 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1454 break;
1455 case GL_PROGRAM_BINARY_FORMATS:
1456 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1457 break;
1458 case GL_NUM_EXTENSIONS:
1459 *params = static_cast<GLint>(mExtensionStrings.size());
1460 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001461
Jamie Madill231c7f52017-04-26 13:45:37 -04001462 // GL_KHR_debug
1463 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1464 *params = mExtensions.maxDebugMessageLength;
1465 break;
1466 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1467 *params = mExtensions.maxDebugLoggedMessages;
1468 break;
1469 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1470 *params = mExtensions.maxDebugGroupStackDepth;
1471 break;
1472 case GL_MAX_LABEL_LENGTH:
1473 *params = mExtensions.maxLabelLength;
1474 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001475
Martin Radeve5285d22017-07-14 16:23:53 +03001476 // GL_ANGLE_multiview
1477 case GL_MAX_VIEWS_ANGLE:
1478 *params = mExtensions.maxViews;
1479 break;
1480
Jamie Madill231c7f52017-04-26 13:45:37 -04001481 // GL_EXT_disjoint_timer_query
1482 case GL_GPU_DISJOINT_EXT:
1483 *params = mImplementation->getGPUDisjoint();
1484 break;
1485 case GL_MAX_FRAMEBUFFER_WIDTH:
1486 *params = mCaps.maxFramebufferWidth;
1487 break;
1488 case GL_MAX_FRAMEBUFFER_HEIGHT:
1489 *params = mCaps.maxFramebufferHeight;
1490 break;
1491 case GL_MAX_FRAMEBUFFER_SAMPLES:
1492 *params = mCaps.maxFramebufferSamples;
1493 break;
1494 case GL_MAX_SAMPLE_MASK_WORDS:
1495 *params = mCaps.maxSampleMaskWords;
1496 break;
1497 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1498 *params = mCaps.maxColorTextureSamples;
1499 break;
1500 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1501 *params = mCaps.maxDepthTextureSamples;
1502 break;
1503 case GL_MAX_INTEGER_SAMPLES:
1504 *params = mCaps.maxIntegerSamples;
1505 break;
1506 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1507 *params = mCaps.maxVertexAttribRelativeOffset;
1508 break;
1509 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1510 *params = mCaps.maxVertexAttribBindings;
1511 break;
1512 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1513 *params = mCaps.maxVertexAttribStride;
1514 break;
1515 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
1516 *params = mCaps.maxVertexAtomicCounterBuffers;
1517 break;
1518 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
1519 *params = mCaps.maxVertexAtomicCounters;
1520 break;
1521 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
1522 *params = mCaps.maxVertexImageUniforms;
1523 break;
1524 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
1525 *params = mCaps.maxVertexShaderStorageBlocks;
1526 break;
1527 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
1528 *params = mCaps.maxFragmentAtomicCounterBuffers;
1529 break;
1530 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
1531 *params = mCaps.maxFragmentAtomicCounters;
1532 break;
1533 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
1534 *params = mCaps.maxFragmentImageUniforms;
1535 break;
1536 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
1537 *params = mCaps.maxFragmentShaderStorageBlocks;
1538 break;
1539 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1540 *params = mCaps.minProgramTextureGatherOffset;
1541 break;
1542 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1543 *params = mCaps.maxProgramTextureGatherOffset;
1544 break;
1545 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1546 *params = mCaps.maxComputeWorkGroupInvocations;
1547 break;
1548 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
1549 *params = mCaps.maxComputeUniformBlocks;
1550 break;
1551 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
1552 *params = mCaps.maxComputeTextureImageUnits;
1553 break;
1554 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1555 *params = mCaps.maxComputeSharedMemorySize;
1556 break;
1557 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
1558 *params = mCaps.maxComputeUniformComponents;
1559 break;
1560 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
1561 *params = mCaps.maxComputeAtomicCounterBuffers;
1562 break;
1563 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
1564 *params = mCaps.maxComputeAtomicCounters;
1565 break;
1566 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
1567 *params = mCaps.maxComputeImageUniforms;
1568 break;
1569 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
1570 *params = mCaps.maxCombinedComputeUniformComponents;
1571 break;
1572 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
1573 *params = mCaps.maxComputeShaderStorageBlocks;
1574 break;
1575 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1576 *params = mCaps.maxCombinedShaderOutputResources;
1577 break;
1578 case GL_MAX_UNIFORM_LOCATIONS:
1579 *params = mCaps.maxUniformLocations;
1580 break;
1581 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1582 *params = mCaps.maxAtomicCounterBufferBindings;
1583 break;
1584 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1585 *params = mCaps.maxAtomicCounterBufferSize;
1586 break;
1587 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1588 *params = mCaps.maxCombinedAtomicCounterBuffers;
1589 break;
1590 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1591 *params = mCaps.maxCombinedAtomicCounters;
1592 break;
1593 case GL_MAX_IMAGE_UNITS:
1594 *params = mCaps.maxImageUnits;
1595 break;
1596 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1597 *params = mCaps.maxCombinedImageUniforms;
1598 break;
1599 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1600 *params = mCaps.maxShaderStorageBufferBindings;
1601 break;
1602 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1603 *params = mCaps.maxCombinedShaderStorageBlocks;
1604 break;
1605 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1606 *params = mCaps.shaderStorageBufferOffsetAlignment;
1607 break;
1608 default:
1609 mGLState.getIntegerv(this, pname, params);
1610 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001611 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001612}
1613
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001614void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001615{
Shannon Woods53a94a82014-06-24 15:20:36 -04001616 // Queries about context capabilities and maximums are answered by Context.
1617 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001618 switch (pname)
1619 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001620 case GL_MAX_ELEMENT_INDEX:
1621 *params = mCaps.maxElementIndex;
1622 break;
1623 case GL_MAX_UNIFORM_BLOCK_SIZE:
1624 *params = mCaps.maxUniformBlockSize;
1625 break;
1626 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
1627 *params = mCaps.maxCombinedVertexUniformComponents;
1628 break;
1629 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
1630 *params = mCaps.maxCombinedFragmentUniformComponents;
1631 break;
1632 case GL_MAX_SERVER_WAIT_TIMEOUT:
1633 *params = mCaps.maxServerWaitTimeout;
1634 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001635
Jamie Madill231c7f52017-04-26 13:45:37 -04001636 // GL_EXT_disjoint_timer_query
1637 case GL_TIMESTAMP_EXT:
1638 *params = mImplementation->getTimestamp();
1639 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001640
Jamie Madill231c7f52017-04-26 13:45:37 -04001641 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1642 *params = mCaps.maxShaderStorageBlockSize;
1643 break;
1644 default:
1645 UNREACHABLE();
1646 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001647 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001648}
1649
Geoff Lang70d0f492015-12-10 17:45:46 -05001650void Context::getPointerv(GLenum pname, void **params) const
1651{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001652 mGLState.getPointerv(pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001653}
1654
Martin Radev66fb8202016-07-28 11:45:20 +03001655void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001656{
Shannon Woods53a94a82014-06-24 15:20:36 -04001657 // Queries about context capabilities and maximums are answered by Context.
1658 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001659
1660 GLenum nativeType;
1661 unsigned int numParams;
1662 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1663 ASSERT(queryStatus);
1664
1665 if (nativeType == GL_INT)
1666 {
1667 switch (target)
1668 {
1669 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1670 ASSERT(index < 3u);
1671 *data = mCaps.maxComputeWorkGroupCount[index];
1672 break;
1673 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1674 ASSERT(index < 3u);
1675 *data = mCaps.maxComputeWorkGroupSize[index];
1676 break;
1677 default:
1678 mGLState.getIntegeri_v(target, index, data);
1679 }
1680 }
1681 else
1682 {
1683 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1684 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001685}
1686
Martin Radev66fb8202016-07-28 11:45:20 +03001687void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001688{
Shannon Woods53a94a82014-06-24 15:20:36 -04001689 // Queries about context capabilities and maximums are answered by Context.
1690 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001691
1692 GLenum nativeType;
1693 unsigned int numParams;
1694 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1695 ASSERT(queryStatus);
1696
1697 if (nativeType == GL_INT_64_ANGLEX)
1698 {
1699 mGLState.getInteger64i_v(target, index, data);
1700 }
1701 else
1702 {
1703 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1704 }
1705}
1706
1707void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1708{
1709 // Queries about context capabilities and maximums are answered by Context.
1710 // Queries about current GL state values are answered by State.
1711
1712 GLenum nativeType;
1713 unsigned int numParams;
1714 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1715 ASSERT(queryStatus);
1716
1717 if (nativeType == GL_BOOL)
1718 {
1719 mGLState.getBooleani_v(target, index, data);
1720 }
1721 else
1722 {
1723 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1724 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001725}
1726
He Yunchao010e4db2017-03-03 14:22:06 +08001727void Context::getBufferParameteriv(GLenum target, GLenum pname, GLint *params)
1728{
1729 Buffer *buffer = mGLState.getTargetBuffer(target);
1730 QueryBufferParameteriv(buffer, pname, params);
1731}
1732
1733void Context::getFramebufferAttachmentParameteriv(GLenum target,
1734 GLenum attachment,
1735 GLenum pname,
1736 GLint *params)
1737{
1738 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
1739 QueryFramebufferAttachmentParameteriv(framebuffer, attachment, pname, params);
1740}
1741
1742void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
1743{
1744 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
1745 QueryRenderbufferiv(this, renderbuffer, pname, params);
1746}
1747
1748void Context::getTexParameterfv(GLenum target, GLenum pname, GLfloat *params)
1749{
1750 Texture *texture = getTargetTexture(target);
1751 QueryTexParameterfv(texture, pname, params);
1752}
1753
1754void Context::getTexParameteriv(GLenum target, GLenum pname, GLint *params)
1755{
1756 Texture *texture = getTargetTexture(target);
1757 QueryTexParameteriv(texture, pname, params);
1758}
1759void Context::texParameterf(GLenum target, GLenum pname, GLfloat param)
1760{
1761 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001762 SetTexParameterf(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04001763 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001764}
1765
1766void Context::texParameterfv(GLenum target, GLenum pname, const GLfloat *params)
1767{
1768 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001769 SetTexParameterfv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04001770 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001771}
1772
1773void Context::texParameteri(GLenum target, GLenum pname, GLint param)
1774{
1775 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001776 SetTexParameteri(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04001777 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001778}
1779
1780void Context::texParameteriv(GLenum target, GLenum pname, const GLint *params)
1781{
1782 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001783 SetTexParameteriv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04001784 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001785}
1786
Jamie Madill675fe712016-12-19 13:07:54 -05001787void Context::drawArrays(GLenum mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001788{
Jamie Madill05b35b22017-10-03 09:01:44 -04001789 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001790 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
1791 MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001792}
1793
Jamie Madill675fe712016-12-19 13:07:54 -05001794void Context::drawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04001795{
Jamie Madill05b35b22017-10-03 09:01:44 -04001796 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001797 ANGLE_CONTEXT_TRY(
1798 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
1799 MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback());
Geoff Langf6db0982015-08-25 13:04:00 -04001800}
1801
Jamie Madill876429b2017-04-20 15:46:24 -04001802void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001803{
Jamie Madill05b35b22017-10-03 09:01:44 -04001804 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001805 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04001806}
1807
Jamie Madill675fe712016-12-19 13:07:54 -05001808void Context::drawElementsInstanced(GLenum mode,
1809 GLsizei count,
1810 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04001811 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04001812 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04001813{
Jamie Madill05b35b22017-10-03 09:01:44 -04001814 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001815 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08001816 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04001817}
1818
Jamie Madill675fe712016-12-19 13:07:54 -05001819void Context::drawRangeElements(GLenum mode,
1820 GLuint start,
1821 GLuint end,
1822 GLsizei count,
1823 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04001824 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04001825{
Jamie Madill05b35b22017-10-03 09:01:44 -04001826 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001827 ANGLE_CONTEXT_TRY(
1828 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001829}
1830
Jamie Madill876429b2017-04-20 15:46:24 -04001831void Context::drawArraysIndirect(GLenum mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08001832{
Jamie Madill05b35b22017-10-03 09:01:44 -04001833 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001834 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08001835}
1836
Jamie Madill876429b2017-04-20 15:46:24 -04001837void Context::drawElementsIndirect(GLenum mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08001838{
Jamie Madill05b35b22017-10-03 09:01:44 -04001839 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001840 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08001841}
1842
Jamie Madill675fe712016-12-19 13:07:54 -05001843void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001844{
Jamie Madill675fe712016-12-19 13:07:54 -05001845 handleError(mImplementation->flush());
Geoff Lang129753a2015-01-09 16:52:09 -05001846}
1847
Jamie Madill675fe712016-12-19 13:07:54 -05001848void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05001849{
Jamie Madill675fe712016-12-19 13:07:54 -05001850 handleError(mImplementation->finish());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001851}
1852
Austin Kinross6ee1e782015-05-29 17:05:37 -07001853void Context::insertEventMarker(GLsizei length, const char *marker)
1854{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001855 ASSERT(mImplementation);
1856 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07001857}
1858
1859void Context::pushGroupMarker(GLsizei length, const char *marker)
1860{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001861 ASSERT(mImplementation);
1862 mImplementation->pushGroupMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07001863}
1864
1865void Context::popGroupMarker()
1866{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001867 ASSERT(mImplementation);
1868 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07001869}
1870
Geoff Langd8605522016-04-13 10:19:12 -04001871void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
1872{
1873 Program *programObject = getProgram(program);
1874 ASSERT(programObject);
1875
1876 programObject->bindUniformLocation(location, name);
1877}
1878
Sami Väisänena797e062016-05-12 15:23:40 +03001879void Context::setCoverageModulation(GLenum components)
1880{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001881 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03001882}
1883
Sami Väisänene45e53b2016-05-25 10:36:04 +03001884void Context::loadPathRenderingMatrix(GLenum matrixMode, const GLfloat *matrix)
1885{
1886 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
1887}
1888
1889void Context::loadPathRenderingIdentityMatrix(GLenum matrixMode)
1890{
1891 GLfloat I[16];
1892 angle::Matrix<GLfloat>::setToIdentity(I);
1893
1894 mGLState.loadPathRenderingMatrix(matrixMode, I);
1895}
1896
1897void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
1898{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001899 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001900 if (!pathObj)
1901 return;
1902
1903 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1904 syncRendererState();
1905
1906 mImplementation->stencilFillPath(pathObj, fillMode, mask);
1907}
1908
1909void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
1910{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001911 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001912 if (!pathObj)
1913 return;
1914
1915 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1916 syncRendererState();
1917
1918 mImplementation->stencilStrokePath(pathObj, reference, mask);
1919}
1920
1921void Context::coverFillPath(GLuint path, GLenum coverMode)
1922{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001923 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001924 if (!pathObj)
1925 return;
1926
1927 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1928 syncRendererState();
1929
1930 mImplementation->coverFillPath(pathObj, coverMode);
1931}
1932
1933void Context::coverStrokePath(GLuint path, GLenum coverMode)
1934{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001935 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001936 if (!pathObj)
1937 return;
1938
1939 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1940 syncRendererState();
1941
1942 mImplementation->coverStrokePath(pathObj, coverMode);
1943}
1944
1945void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
1946{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001947 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001948 if (!pathObj)
1949 return;
1950
1951 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1952 syncRendererState();
1953
1954 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
1955}
1956
1957void Context::stencilThenCoverStrokePath(GLuint path,
1958 GLint reference,
1959 GLuint mask,
1960 GLenum coverMode)
1961{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001962 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001963 if (!pathObj)
1964 return;
1965
1966 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1967 syncRendererState();
1968
1969 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
1970}
1971
Sami Väisänend59ca052016-06-21 16:10:00 +03001972void Context::coverFillPathInstanced(GLsizei numPaths,
1973 GLenum pathNameType,
1974 const void *paths,
1975 GLuint pathBase,
1976 GLenum coverMode,
1977 GLenum transformType,
1978 const GLfloat *transformValues)
1979{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001980 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03001981
1982 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1983 syncRendererState();
1984
1985 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
1986}
Sami Väisänen46eaa942016-06-29 10:26:37 +03001987
Sami Väisänend59ca052016-06-21 16:10:00 +03001988void Context::coverStrokePathInstanced(GLsizei numPaths,
1989 GLenum pathNameType,
1990 const void *paths,
1991 GLuint pathBase,
1992 GLenum coverMode,
1993 GLenum transformType,
1994 const GLfloat *transformValues)
1995{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001996 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03001997
1998 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1999 syncRendererState();
2000
2001 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2002 transformValues);
2003}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002004
Sami Väisänend59ca052016-06-21 16:10:00 +03002005void Context::stencilFillPathInstanced(GLsizei numPaths,
2006 GLenum pathNameType,
2007 const void *paths,
2008 GLuint pathBase,
2009 GLenum fillMode,
2010 GLuint mask,
2011 GLenum transformType,
2012 const GLfloat *transformValues)
2013{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002014 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002015
2016 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2017 syncRendererState();
2018
2019 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2020 transformValues);
2021}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002022
Sami Väisänend59ca052016-06-21 16:10:00 +03002023void Context::stencilStrokePathInstanced(GLsizei numPaths,
2024 GLenum pathNameType,
2025 const void *paths,
2026 GLuint pathBase,
2027 GLint reference,
2028 GLuint mask,
2029 GLenum transformType,
2030 const GLfloat *transformValues)
2031{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002032 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002033
2034 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2035 syncRendererState();
2036
2037 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2038 transformValues);
2039}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002040
Sami Väisänend59ca052016-06-21 16:10:00 +03002041void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2042 GLenum pathNameType,
2043 const void *paths,
2044 GLuint pathBase,
2045 GLenum fillMode,
2046 GLuint mask,
2047 GLenum coverMode,
2048 GLenum transformType,
2049 const GLfloat *transformValues)
2050{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002051 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002052
2053 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2054 syncRendererState();
2055
2056 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2057 transformType, transformValues);
2058}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002059
Sami Väisänend59ca052016-06-21 16:10:00 +03002060void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2061 GLenum pathNameType,
2062 const void *paths,
2063 GLuint pathBase,
2064 GLint reference,
2065 GLuint mask,
2066 GLenum coverMode,
2067 GLenum transformType,
2068 const GLfloat *transformValues)
2069{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002070 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002071
2072 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2073 syncRendererState();
2074
2075 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2076 transformType, transformValues);
2077}
2078
Sami Väisänen46eaa942016-06-29 10:26:37 +03002079void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2080{
2081 auto *programObject = getProgram(program);
2082
2083 programObject->bindFragmentInputLocation(location, name);
2084}
2085
2086void Context::programPathFragmentInputGen(GLuint program,
2087 GLint location,
2088 GLenum genMode,
2089 GLint components,
2090 const GLfloat *coeffs)
2091{
2092 auto *programObject = getProgram(program);
2093
Jamie Madillbd044ed2017-06-05 12:59:21 -04002094 programObject->pathFragmentInputGen(this, location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002095}
2096
jchen1015015f72017-03-16 13:54:21 +08002097GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2098{
jchen10fd7c3b52017-03-21 15:36:03 +08002099 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002100 return QueryProgramResourceIndex(programObject, programInterface, name);
2101}
2102
jchen10fd7c3b52017-03-21 15:36:03 +08002103void Context::getProgramResourceName(GLuint program,
2104 GLenum programInterface,
2105 GLuint index,
2106 GLsizei bufSize,
2107 GLsizei *length,
2108 GLchar *name)
2109{
2110 const auto *programObject = getProgram(program);
2111 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2112}
2113
jchen10191381f2017-04-11 13:59:04 +08002114GLint Context::getProgramResourceLocation(GLuint program,
2115 GLenum programInterface,
2116 const GLchar *name)
2117{
2118 const auto *programObject = getProgram(program);
2119 return QueryProgramResourceLocation(programObject, programInterface, name);
2120}
2121
jchen10880683b2017-04-12 16:21:55 +08002122void Context::getProgramResourceiv(GLuint program,
2123 GLenum programInterface,
2124 GLuint index,
2125 GLsizei propCount,
2126 const GLenum *props,
2127 GLsizei bufSize,
2128 GLsizei *length,
2129 GLint *params)
2130{
2131 const auto *programObject = getProgram(program);
2132 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2133 length, params);
2134}
2135
jchen10d9cd7b72017-08-30 15:04:25 +08002136void Context::getProgramInterfaceiv(GLuint program,
2137 GLenum programInterface,
2138 GLenum pname,
2139 GLint *params)
2140{
2141 const auto *programObject = getProgram(program);
2142 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2143}
2144
Jamie Madill71c88b32017-09-14 22:20:29 -04002145void Context::handleError(const Error &error)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002146{
Geoff Langda5777c2014-07-11 09:52:58 -04002147 if (error.isError())
2148 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002149 GLenum code = error.getCode();
2150 mErrors.insert(code);
2151 if (code == GL_OUT_OF_MEMORY && getWorkarounds().loseContextOnOutOfMemory)
2152 {
2153 markContextLost();
2154 }
Geoff Lang70d0f492015-12-10 17:45:46 -05002155
Geoff Langee6884e2017-11-09 16:51:11 -05002156 ASSERT(!error.getMessage().empty());
2157 mGLState.getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, error.getID(),
2158 GL_DEBUG_SEVERITY_HIGH, error.getMessage());
Geoff Langda5777c2014-07-11 09:52:58 -04002159 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002160}
2161
2162// Get one of the recorded errors and clear its flag, if any.
2163// [OpenGL ES 2.0.24] section 2.5 page 13.
2164GLenum Context::getError()
2165{
Geoff Langda5777c2014-07-11 09:52:58 -04002166 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002167 {
Geoff Langda5777c2014-07-11 09:52:58 -04002168 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002169 }
Geoff Langda5777c2014-07-11 09:52:58 -04002170 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002171 {
Geoff Langda5777c2014-07-11 09:52:58 -04002172 GLenum error = *mErrors.begin();
2173 mErrors.erase(mErrors.begin());
2174 return error;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002175 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002176}
2177
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002178// NOTE: this function should not assume that this context is current!
2179void Context::markContextLost()
2180{
2181 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002182 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002183 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002184 mContextLostForced = true;
2185 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002186 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002187}
2188
2189bool Context::isContextLost()
2190{
2191 return mContextLost;
2192}
2193
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002194GLenum Context::getResetStatus()
2195{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002196 // Even if the application doesn't want to know about resets, we want to know
2197 // as it will allow us to skip all the calls.
2198 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002199 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002200 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002201 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002202 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002203 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002204
2205 // EXT_robustness, section 2.6: If the reset notification behavior is
2206 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2207 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2208 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002209 }
2210
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002211 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2212 // status should be returned at least once, and GL_NO_ERROR should be returned
2213 // once the device has finished resetting.
2214 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002215 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002216 ASSERT(mResetStatus == GL_NO_ERROR);
2217 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002218
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002219 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002220 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002221 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002222 }
2223 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002224 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002225 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002226 // If markContextLost was used to mark the context lost then
2227 // assume that is not recoverable, and continue to report the
2228 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002229 mResetStatus = mImplementation->getResetStatus();
2230 }
Jamie Madill893ab082014-05-16 16:56:10 -04002231
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002232 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002233}
2234
2235bool Context::isResetNotificationEnabled()
2236{
2237 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2238}
2239
Corentin Walleze3b10e82015-05-20 11:06:25 -04002240const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002241{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002242 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002243}
2244
2245EGLenum Context::getClientType() const
2246{
2247 return mClientType;
2248}
2249
2250EGLenum Context::getRenderBuffer() const
2251{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002252 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2253 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002254 {
2255 return EGL_NONE;
2256 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002257
2258 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(GL_BACK);
2259 ASSERT(backAttachment != nullptr);
2260 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002261}
2262
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002263VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002264{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002265 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002266 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2267 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002268 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002269 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2270 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002271
Jamie Madill96a483b2017-06-27 16:49:21 -04002272 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002273 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002274
2275 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002276}
2277
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002278TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002279{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002280 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002281 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2282 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002283 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002284 transformFeedback =
2285 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002286 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002287 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002288 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002289
2290 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002291}
2292
2293bool Context::isVertexArrayGenerated(GLuint vertexArray)
2294{
Jamie Madill96a483b2017-06-27 16:49:21 -04002295 ASSERT(mVertexArrayMap.contains(0));
2296 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002297}
2298
2299bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2300{
Jamie Madill96a483b2017-06-27 16:49:21 -04002301 ASSERT(mTransformFeedbackMap.contains(0));
2302 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002303}
2304
Shannon Woods53a94a82014-06-24 15:20:36 -04002305void Context::detachTexture(GLuint texture)
2306{
2307 // Simple pass-through to State's detachTexture method, as textures do not require
2308 // allocation map management either here or in the resource manager at detach time.
2309 // Zero textures are held by the Context, and we don't attempt to request them from
2310 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002311 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002312}
2313
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002314void Context::detachBuffer(GLuint buffer)
2315{
Yuly Novikov5807a532015-12-03 13:01:22 -05002316 // Simple pass-through to State's detachBuffer method, since
2317 // only buffer attachments to container objects that are bound to the current context
2318 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002319
Yuly Novikov5807a532015-12-03 13:01:22 -05002320 // [OpenGL ES 3.2] section 5.1.2 page 45:
2321 // Attachments to unbound container objects, such as
2322 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2323 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002324 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002325}
2326
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002327void Context::detachFramebuffer(GLuint framebuffer)
2328{
Shannon Woods53a94a82014-06-24 15:20:36 -04002329 // Framebuffer detachment is handled by Context, because 0 is a valid
2330 // Framebuffer object, and a pointer to it must be passed from Context
2331 // to State at binding time.
2332
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002333 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002334 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2335 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2336 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002337
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002338 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002339 {
2340 bindReadFramebuffer(0);
2341 }
2342
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002343 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002344 {
2345 bindDrawFramebuffer(0);
2346 }
2347}
2348
2349void Context::detachRenderbuffer(GLuint renderbuffer)
2350{
Jamie Madilla02315b2017-02-23 14:14:47 -05002351 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002352}
2353
Jamie Madill57a89722013-07-02 11:57:03 -04002354void Context::detachVertexArray(GLuint vertexArray)
2355{
Jamie Madill77a72f62015-04-14 11:18:32 -04002356 // Vertex array detachment is handled by Context, because 0 is a valid
2357 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002358 // binding time.
2359
Jamie Madill57a89722013-07-02 11:57:03 -04002360 // [OpenGL ES 3.0.2] section 2.10 page 43:
2361 // If a vertex array object that is currently bound is deleted, the binding
2362 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002363 if (mGLState.removeVertexArrayBinding(vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002364 {
2365 bindVertexArray(0);
2366 }
2367}
2368
Geoff Langc8058452014-02-03 12:04:11 -05002369void Context::detachTransformFeedback(GLuint transformFeedback)
2370{
Corentin Walleza2257da2016-04-19 16:43:12 -04002371 // Transform feedback detachment is handled by Context, because 0 is a valid
2372 // transform feedback, and a pointer to it must be passed from Context to State at
2373 // binding time.
2374
2375 // The OpenGL specification doesn't mention what should happen when the currently bound
2376 // transform feedback object is deleted. Since it is a container object, we treat it like
2377 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002378 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002379 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002380 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002381 }
Geoff Langc8058452014-02-03 12:04:11 -05002382}
2383
Jamie Madilldc356042013-07-19 16:36:57 -04002384void Context::detachSampler(GLuint sampler)
2385{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002386 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002387}
2388
Yunchao Hea336b902017-08-02 16:05:21 +08002389void Context::detachProgramPipeline(GLuint pipeline)
2390{
2391 mGLState.detachProgramPipeline(this, pipeline);
2392}
2393
Jamie Madill3ef140a2017-08-26 23:11:21 -04002394void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002395{
Shaodde78e82017-05-22 14:13:27 +08002396 mGLState.setVertexAttribDivisor(this, index, divisor);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002397}
2398
Jamie Madille29d1672013-07-19 16:36:57 -04002399void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2400{
Geoff Langc1984ed2016-10-07 12:41:00 -04002401 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002402 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002403 SetSamplerParameteri(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002404 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002405}
Jamie Madille29d1672013-07-19 16:36:57 -04002406
Geoff Langc1984ed2016-10-07 12:41:00 -04002407void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2408{
2409 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002410 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002411 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002412 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002413}
2414
2415void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2416{
Geoff Langc1984ed2016-10-07 12:41:00 -04002417 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002418 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002419 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002420 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002421}
2422
Geoff Langc1984ed2016-10-07 12:41:00 -04002423void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002424{
Geoff Langc1984ed2016-10-07 12:41:00 -04002425 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002426 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002427 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002428 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002429}
2430
Geoff Langc1984ed2016-10-07 12:41:00 -04002431void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002432{
Geoff Langc1984ed2016-10-07 12:41:00 -04002433 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002434 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002435 QuerySamplerParameteriv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002436 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002437}
Jamie Madill9675b802013-07-19 16:36:59 -04002438
Geoff Langc1984ed2016-10-07 12:41:00 -04002439void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2440{
2441 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002442 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002443 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002444 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002445}
2446
Olli Etuahof0fee072016-03-30 15:11:58 +03002447void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2448{
2449 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002450 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002451}
2452
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002453void Context::initRendererString()
2454{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002455 std::ostringstream rendererString;
2456 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002457 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002458 rendererString << ")";
2459
Geoff Langcec35902014-04-16 10:52:36 -04002460 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002461}
2462
Geoff Langc339c4e2016-11-29 10:37:36 -05002463void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002464{
Geoff Langc339c4e2016-11-29 10:37:36 -05002465 const Version &clientVersion = getClientVersion();
2466
2467 std::ostringstream versionString;
2468 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2469 << ANGLE_VERSION_STRING << ")";
2470 mVersionString = MakeStaticString(versionString.str());
2471
2472 std::ostringstream shadingLanguageVersionString;
2473 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2474 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2475 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2476 << ")";
2477 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002478}
2479
Geoff Langcec35902014-04-16 10:52:36 -04002480void Context::initExtensionStrings()
2481{
Geoff Langc339c4e2016-11-29 10:37:36 -05002482 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2483 std::ostringstream combinedStringStream;
2484 std::copy(strings.begin(), strings.end(),
2485 std::ostream_iterator<const char *>(combinedStringStream, " "));
2486 return MakeStaticString(combinedStringStream.str());
2487 };
2488
2489 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002490 for (const auto &extensionString : mExtensions.getStrings())
2491 {
2492 mExtensionStrings.push_back(MakeStaticString(extensionString));
2493 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002494 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002495
Bryan Bernhart58806562017-01-05 13:09:31 -08002496 const gl::Extensions &nativeExtensions = mImplementation->getNativeExtensions();
2497
Geoff Langc339c4e2016-11-29 10:37:36 -05002498 mRequestableExtensionStrings.clear();
2499 for (const auto &extensionInfo : GetExtensionInfoMap())
2500 {
2501 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08002502 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
2503 nativeExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002504 {
2505 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
2506 }
2507 }
2508 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002509}
2510
Geoff Langc339c4e2016-11-29 10:37:36 -05002511const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04002512{
Geoff Langc339c4e2016-11-29 10:37:36 -05002513 switch (name)
2514 {
2515 case GL_VENDOR:
2516 return reinterpret_cast<const GLubyte *>("Google Inc.");
2517
2518 case GL_RENDERER:
2519 return reinterpret_cast<const GLubyte *>(mRendererString);
2520
2521 case GL_VERSION:
2522 return reinterpret_cast<const GLubyte *>(mVersionString);
2523
2524 case GL_SHADING_LANGUAGE_VERSION:
2525 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
2526
2527 case GL_EXTENSIONS:
2528 return reinterpret_cast<const GLubyte *>(mExtensionString);
2529
2530 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2531 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
2532
2533 default:
2534 UNREACHABLE();
2535 return nullptr;
2536 }
Geoff Langcec35902014-04-16 10:52:36 -04002537}
2538
Geoff Langc339c4e2016-11-29 10:37:36 -05002539const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04002540{
Geoff Langc339c4e2016-11-29 10:37:36 -05002541 switch (name)
2542 {
2543 case GL_EXTENSIONS:
2544 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
2545
2546 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2547 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
2548
2549 default:
2550 UNREACHABLE();
2551 return nullptr;
2552 }
Geoff Langcec35902014-04-16 10:52:36 -04002553}
2554
2555size_t Context::getExtensionStringCount() const
2556{
2557 return mExtensionStrings.size();
2558}
2559
Geoff Lang111a99e2017-10-17 10:58:41 -04002560bool Context::isExtensionRequestable(const char *name)
2561{
2562 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2563 auto extension = extensionInfos.find(name);
2564
2565 const Extensions &nativeExtensions = mImplementation->getNativeExtensions();
2566 return extension != extensionInfos.end() && extension->second.Requestable &&
2567 nativeExtensions.*(extension->second.ExtensionsMember);
2568}
2569
Geoff Langc339c4e2016-11-29 10:37:36 -05002570void Context::requestExtension(const char *name)
2571{
2572 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2573 ASSERT(extensionInfos.find(name) != extensionInfos.end());
2574 const auto &extension = extensionInfos.at(name);
2575 ASSERT(extension.Requestable);
Geoff Lang111a99e2017-10-17 10:58:41 -04002576 ASSERT(mImplementation->getNativeExtensions().*(extension.ExtensionsMember));
Geoff Langc339c4e2016-11-29 10:37:36 -05002577
2578 if (mExtensions.*(extension.ExtensionsMember))
2579 {
2580 // Extension already enabled
2581 return;
2582 }
2583
2584 mExtensions.*(extension.ExtensionsMember) = true;
2585 updateCaps();
2586 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08002587
Jamie Madill2f348d22017-06-05 10:50:59 -04002588 // Release the shader compiler so it will be re-created with the requested extensions enabled.
2589 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04002590
Jamie Madill81c2e252017-09-09 23:32:46 -04002591 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
2592 // sampleable.
2593 mState.mTextures->signalAllTexturesDirty();
Geoff Lang9aded172017-04-05 11:07:56 -04002594 for (auto &zeroTexture : mZeroTextures)
2595 {
Jamie Madill05b35b22017-10-03 09:01:44 -04002596 zeroTexture.second->signalDirty(InitState::Initialized);
Geoff Lang9aded172017-04-05 11:07:56 -04002597 }
2598
2599 mState.mFramebuffers->invalidateFramebufferComplenessCache();
Geoff Langc339c4e2016-11-29 10:37:36 -05002600}
2601
2602size_t Context::getRequestableExtensionStringCount() const
2603{
2604 return mRequestableExtensionStrings.size();
2605}
2606
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002607void Context::beginTransformFeedback(GLenum primitiveMode)
2608{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002609 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002610 ASSERT(transformFeedback != nullptr);
2611 ASSERT(!transformFeedback->isPaused());
2612
Jamie Madill6c1f6712017-02-14 19:08:04 -05002613 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002614}
2615
2616bool Context::hasActiveTransformFeedback(GLuint program) const
2617{
2618 for (auto pair : mTransformFeedbackMap)
2619 {
2620 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
2621 {
2622 return true;
2623 }
2624 }
2625 return false;
2626}
2627
Geoff Langb433e872017-10-05 14:01:47 -04002628void Context::initCaps(const egl::DisplayExtensions &displayExtensions, bool robustResourceInit)
Geoff Lang493daf52014-07-03 13:38:44 -04002629{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002630 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04002631
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002632 mExtensions = mImplementation->getNativeExtensions();
Geoff Lang493daf52014-07-03 13:38:44 -04002633
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002634 mLimitations = mImplementation->getNativeLimitations();
Austin Kinross02df7962015-07-01 10:03:42 -07002635
Geoff Langeb66a6e2016-10-31 13:06:12 -04002636 if (getClientVersion() < Version(3, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002637 {
2638 // Disable ES3+ extensions
Jamie Madill231c7f52017-04-26 13:45:37 -04002639 mExtensions.colorBufferFloat = false;
Geoff Langb66a9092016-05-16 15:59:14 -04002640 mExtensions.eglImageExternalEssl3 = false;
Vincent Lang25ab4512016-05-13 18:13:59 +02002641 mExtensions.textureNorm16 = false;
Martin Radev137032d2017-07-13 10:11:12 +03002642 mExtensions.multiview = false;
2643 mExtensions.maxViews = 1u;
Geoff Lang493daf52014-07-03 13:38:44 -04002644 }
2645
Geoff Langeb66a6e2016-10-31 13:06:12 -04002646 if (getClientVersion() > Version(2, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002647 {
2648 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
Jamie Madill231c7f52017-04-26 13:45:37 -04002649 // mExtensions.sRGB = false;
Geoff Lang493daf52014-07-03 13:38:44 -04002650 }
2651
Jamie Madill00ed7a12016-05-19 13:13:38 -04002652 // Some extensions are always available because they are implemented in the GL layer.
Jamie Madill231c7f52017-04-26 13:45:37 -04002653 mExtensions.bindUniformLocation = true;
2654 mExtensions.vertexArrayObject = true;
Geoff Langf41a7152016-09-19 15:11:17 -04002655 mExtensions.bindGeneratesResource = true;
Geoff Langfeb8c682017-02-13 16:07:35 -05002656 mExtensions.clientArrays = true;
Geoff Langc339c4e2016-11-29 10:37:36 -05002657 mExtensions.requestExtension = true;
Jamie Madill00ed7a12016-05-19 13:13:38 -04002658
2659 // Enable the no error extension if the context was created with the flag.
2660 mExtensions.noError = mSkipValidation;
2661
Corentin Wallezccab69d2017-01-27 16:57:15 -05002662 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Corentin Wallezc295e512017-01-27 17:47:50 -05002663 mExtensions.surfacelessContext = displayExtensions.surfacelessContext;
Corentin Wallezccab69d2017-01-27 16:57:15 -05002664
Geoff Lang70d0f492015-12-10 17:45:46 -05002665 // Explicitly enable GL_KHR_debug
2666 mExtensions.debug = true;
2667 mExtensions.maxDebugMessageLength = 1024;
2668 mExtensions.maxDebugLoggedMessages = 1024;
2669 mExtensions.maxDebugGroupStackDepth = 1024;
2670 mExtensions.maxLabelLength = 1024;
2671
Geoff Langff5b2d52016-09-07 11:32:23 -04002672 // Explicitly enable GL_ANGLE_robust_client_memory
2673 mExtensions.robustClientMemory = true;
2674
Jamie Madille08a1d32017-03-07 17:24:06 -05002675 // Determine robust resource init availability from EGL.
Geoff Langb433e872017-10-05 14:01:47 -04002676 mExtensions.robustResourceInitialization = robustResourceInit;
Jamie Madille08a1d32017-03-07 17:24:06 -05002677
Jiajia Qin8a7b3a02017-08-25 16:05:48 +08002678 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
2679 // supports it.
2680 mExtensions.robustBufferAccessBehavior =
2681 mRobustAccess && mExtensions.robustBufferAccessBehavior;
2682
Jamie Madillc43be722017-07-13 16:22:14 -04002683 // Enable the cache control query unconditionally.
2684 mExtensions.programCacheControl = true;
2685
Geoff Lang301d1612014-07-09 10:34:37 -04002686 // Apply implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04002687 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002688
Jamie Madill0f80ed82017-09-19 00:24:56 -04002689 if (getClientVersion() < ES_3_1)
2690 {
2691 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
2692 }
2693 else
2694 {
2695 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
2696 }
Geoff Lang301d1612014-07-09 10:34:37 -04002697
Jamie Madill0f80ed82017-09-19 00:24:56 -04002698 LimitCap(&mCaps.maxVertexUniformBlocks, IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
2699 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
2700 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
2701
2702 // Limit textures as well, so we can use fast bitsets with texture bindings.
2703 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
2704 LimitCap(&mCaps.maxVertexTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
2705 LimitCap(&mCaps.maxTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04002706
Jiawei Shaodb342272017-09-27 10:21:45 +08002707 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
2708
Geoff Langc287ea62016-09-16 14:46:51 -04002709 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002710 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04002711 for (const auto &extensionInfo : GetExtensionInfoMap())
2712 {
2713 // If this context is for WebGL, disable all enableable extensions
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002714 if (mWebGLContext && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04002715 {
2716 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
2717 }
2718 }
2719
2720 // Generate texture caps
2721 updateCaps();
2722}
2723
2724void Context::updateCaps()
2725{
Geoff Lang900013c2014-07-07 11:32:19 -04002726 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002727 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04002728
Jamie Madill7b62cf92017-11-02 15:20:49 -04002729 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04002730 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04002731 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04002732 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04002733
Geoff Lang0d8b7242015-09-09 14:56:53 -04002734 // Update the format caps based on the client version and extensions.
2735 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
2736 // ES3.
2737 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002738 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002739 formatCaps.renderable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002740 formatCaps.renderable && formatInfo.renderSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002741 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002742 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04002743
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002744 // OpenGL ES does not support multisampling with non-rendererable formats
2745 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Olli Etuaho50c562d2017-06-06 14:43:30 +03002746 if (!formatCaps.renderable ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002747 (getClientVersion() < ES_3_1 &&
2748 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04002749 {
Geoff Langd87878e2014-09-19 15:42:59 -04002750 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04002751 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03002752 else
2753 {
2754 // We may have limited the max samples for some required renderbuffer formats due to
2755 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
2756 GLuint formatMaxSamples = formatCaps.getMaxSamples();
2757
2758 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
2759 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
2760 // exception of signed and unsigned integer formats."
2761 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
2762 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
2763 {
2764 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
2765 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
2766 }
2767
2768 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
2769 if (getClientVersion() >= ES_3_1)
2770 {
2771 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
2772 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
2773 // the exception that the signed and unsigned integer formats are required only to
2774 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
2775 // multisamples, which must be at least one."
2776 if (formatInfo.componentType == GL_INT ||
2777 formatInfo.componentType == GL_UNSIGNED_INT)
2778 {
2779 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
2780 }
2781
2782 // GLES 3.1 section 19.3.1.
2783 if (formatCaps.texturable)
2784 {
2785 if (formatInfo.depthBits > 0)
2786 {
2787 mCaps.maxDepthTextureSamples =
2788 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
2789 }
2790 else if (formatInfo.redBits > 0)
2791 {
2792 mCaps.maxColorTextureSamples =
2793 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
2794 }
2795 }
2796 }
2797 }
Geoff Langd87878e2014-09-19 15:42:59 -04002798
2799 if (formatCaps.texturable && formatInfo.compressed)
2800 {
Geoff Langca271392017-04-05 12:30:00 -04002801 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04002802 }
2803
Geoff Langca271392017-04-05 12:30:00 -04002804 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04002805 }
Jamie Madill32447362017-06-28 14:53:52 -04002806
2807 // If program binary is disabled, blank out the memory cache pointer.
2808 if (!mImplementation->getNativeExtensions().getProgramBinary)
2809 {
2810 mMemoryProgramCache = nullptr;
2811 }
Geoff Lang493daf52014-07-03 13:38:44 -04002812}
2813
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002814void Context::initWorkarounds()
2815{
Jamie Madill761b02c2017-06-23 16:27:06 -04002816 // Apply back-end workarounds.
2817 mImplementation->applyNativeWorkarounds(&mWorkarounds);
2818
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002819 // Lose the context upon out of memory error if the application is
2820 // expecting to watch for those events.
2821 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2822}
2823
Jamie Madill05b35b22017-10-03 09:01:44 -04002824Error Context::prepareForDraw()
2825{
2826 syncRendererState();
Jamie Madilla59fc192017-11-02 12:57:58 -04002827
2828 if (isRobustResourceInitEnabled())
2829 {
2830 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
2831 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
2832 }
2833
Jamie Madill05b35b22017-10-03 09:01:44 -04002834 return NoError();
2835}
2836
Jamie Madill1b94d432015-08-07 13:23:23 -04002837void Context::syncRendererState()
2838{
Jamie Madill7d1f5c62017-09-02 15:32:15 -04002839 mGLState.syncDirtyObjects(this);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002840 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
Jamie Madillfe548342017-06-19 11:13:24 -04002841 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002842 mGLState.clearDirtyBits();
Jamie Madill1b94d432015-08-07 13:23:23 -04002843}
2844
Jamie Madillad9f24e2016-02-12 09:27:24 -05002845void Context::syncRendererState(const State::DirtyBits &bitMask,
2846 const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04002847{
Jamie Madill7d1f5c62017-09-02 15:32:15 -04002848 mGLState.syncDirtyObjects(this, objectMask);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002849 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madillfe548342017-06-19 11:13:24 -04002850 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002851 mGLState.clearDirtyBits(dirtyBits);
Jamie Madill1b94d432015-08-07 13:23:23 -04002852}
Jamie Madillc29968b2016-01-20 11:17:23 -05002853
2854void Context::blitFramebuffer(GLint srcX0,
2855 GLint srcY0,
2856 GLint srcX1,
2857 GLint srcY1,
2858 GLint dstX0,
2859 GLint dstY0,
2860 GLint dstX1,
2861 GLint dstY1,
2862 GLbitfield mask,
2863 GLenum filter)
2864{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002865 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002866 ASSERT(drawFramebuffer);
2867
2868 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
2869 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
2870
Jamie Madillad9f24e2016-02-12 09:27:24 -05002871 syncStateForBlit();
Jamie Madillc29968b2016-01-20 11:17:23 -05002872
Jamie Madillc564c072017-06-01 12:45:42 -04002873 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002874}
Jamie Madillc29968b2016-01-20 11:17:23 -05002875
2876void Context::clear(GLbitfield mask)
2877{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002878 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002879 handleError(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05002880}
2881
2882void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
2883{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002884 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002885 handleError(mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002886}
2887
2888void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
2889{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002890 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002891 handleError(mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002892}
2893
2894void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
2895{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002896 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002897 handleError(mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002898}
2899
2900void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
2901{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002902 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002903 ASSERT(framebufferObject);
2904
2905 // If a buffer is not present, the clear has no effect
2906 if (framebufferObject->getDepthbuffer() == nullptr &&
2907 framebufferObject->getStencilbuffer() == nullptr)
2908 {
2909 return;
2910 }
2911
Jamie Madillad9f24e2016-02-12 09:27:24 -05002912 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002913 handleError(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05002914}
2915
2916void Context::readPixels(GLint x,
2917 GLint y,
2918 GLsizei width,
2919 GLsizei height,
2920 GLenum format,
2921 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002922 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05002923{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04002924 if (width == 0 || height == 0)
2925 {
2926 return;
2927 }
2928
Jamie Madillad9f24e2016-02-12 09:27:24 -05002929 syncStateForReadPixels();
Jamie Madillc29968b2016-01-20 11:17:23 -05002930
Jamie Madillb6664922017-07-25 12:55:04 -04002931 Framebuffer *readFBO = mGLState.getReadFramebuffer();
2932 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05002933
2934 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04002935 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05002936}
2937
2938void Context::copyTexImage2D(GLenum target,
2939 GLint level,
2940 GLenum internalformat,
2941 GLint x,
2942 GLint y,
2943 GLsizei width,
2944 GLsizei height,
2945 GLint border)
2946{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002947 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002948 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002949
Jamie Madillc29968b2016-01-20 11:17:23 -05002950 Rectangle sourceArea(x, y, width, height);
2951
Jamie Madill05b35b22017-10-03 09:01:44 -04002952 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002953 Texture *texture =
2954 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05002955 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05002956}
2957
2958void Context::copyTexSubImage2D(GLenum target,
2959 GLint level,
2960 GLint xoffset,
2961 GLint yoffset,
2962 GLint x,
2963 GLint y,
2964 GLsizei width,
2965 GLsizei height)
2966{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04002967 if (width == 0 || height == 0)
2968 {
2969 return;
2970 }
2971
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002972 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002973 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002974
Jamie Madillc29968b2016-01-20 11:17:23 -05002975 Offset destOffset(xoffset, yoffset, 0);
2976 Rectangle sourceArea(x, y, width, height);
2977
Jamie Madill05b35b22017-10-03 09:01:44 -04002978 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002979 Texture *texture =
2980 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05002981 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05002982}
2983
2984void Context::copyTexSubImage3D(GLenum target,
2985 GLint level,
2986 GLint xoffset,
2987 GLint yoffset,
2988 GLint zoffset,
2989 GLint x,
2990 GLint y,
2991 GLsizei width,
2992 GLsizei height)
2993{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04002994 if (width == 0 || height == 0)
2995 {
2996 return;
2997 }
2998
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002999 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003000 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003001
Jamie Madillc29968b2016-01-20 11:17:23 -05003002 Offset destOffset(xoffset, yoffset, zoffset);
3003 Rectangle sourceArea(x, y, width, height);
3004
Jamie Madill05b35b22017-10-03 09:01:44 -04003005 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3006 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003007 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003008}
3009
3010void Context::framebufferTexture2D(GLenum target,
3011 GLenum attachment,
3012 GLenum textarget,
3013 GLuint texture,
3014 GLint level)
3015{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003016 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003017 ASSERT(framebuffer);
3018
3019 if (texture != 0)
3020 {
3021 Texture *textureObj = getTexture(texture);
3022
3023 ImageIndex index = ImageIndex::MakeInvalid();
3024
3025 if (textarget == GL_TEXTURE_2D)
3026 {
3027 index = ImageIndex::Make2D(level);
3028 }
Corentin Wallez13c0dd42017-07-04 18:27:01 -04003029 else if (textarget == GL_TEXTURE_RECTANGLE_ANGLE)
3030 {
3031 index = ImageIndex::MakeRectangle(level);
3032 }
JiangYizhoubddc46b2016-12-09 09:50:51 +08003033 else if (textarget == GL_TEXTURE_2D_MULTISAMPLE)
3034 {
3035 ASSERT(level == 0);
3036 index = ImageIndex::Make2DMultisample();
3037 }
Jamie Madillc29968b2016-01-20 11:17:23 -05003038 else
3039 {
3040 ASSERT(IsCubeMapTextureTarget(textarget));
3041 index = ImageIndex::MakeCube(textarget, level);
3042 }
3043
Jamie Madilla02315b2017-02-23 14:14:47 -05003044 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003045 }
3046 else
3047 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003048 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003049 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003050
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003051 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003052}
3053
3054void Context::framebufferRenderbuffer(GLenum target,
3055 GLenum attachment,
3056 GLenum renderbuffertarget,
3057 GLuint renderbuffer)
3058{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003059 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003060 ASSERT(framebuffer);
3061
3062 if (renderbuffer != 0)
3063 {
3064 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003065
3066 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex::MakeInvalid(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003067 renderbufferObject);
3068 }
3069 else
3070 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003071 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003072 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003073
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003074 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003075}
3076
3077void Context::framebufferTextureLayer(GLenum target,
3078 GLenum attachment,
3079 GLuint texture,
3080 GLint level,
3081 GLint layer)
3082{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003083 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003084 ASSERT(framebuffer);
3085
3086 if (texture != 0)
3087 {
3088 Texture *textureObject = getTexture(texture);
3089
3090 ImageIndex index = ImageIndex::MakeInvalid();
3091
3092 if (textureObject->getTarget() == GL_TEXTURE_3D)
3093 {
3094 index = ImageIndex::Make3D(level, layer);
3095 }
3096 else
3097 {
3098 ASSERT(textureObject->getTarget() == GL_TEXTURE_2D_ARRAY);
3099 index = ImageIndex::Make2DArray(level, layer);
3100 }
3101
Jamie Madilla02315b2017-02-23 14:14:47 -05003102 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003103 }
3104 else
3105 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003106 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003107 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003108
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003109 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003110}
3111
Martin Radev137032d2017-07-13 10:11:12 +03003112void Context::framebufferTextureMultiviewLayeredANGLE(GLenum target,
3113 GLenum attachment,
3114 GLuint texture,
3115 GLint level,
3116 GLint baseViewIndex,
3117 GLsizei numViews)
3118{
Martin Radev82ef7742017-08-08 17:44:58 +03003119 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3120 ASSERT(framebuffer);
3121
3122 if (texture != 0)
3123 {
3124 Texture *textureObj = getTexture(texture);
3125
Martin Radev18b75ba2017-08-15 15:50:40 +03003126 ImageIndex index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
Martin Radev82ef7742017-08-08 17:44:58 +03003127 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3128 numViews, baseViewIndex);
3129 }
3130 else
3131 {
3132 framebuffer->resetAttachment(this, attachment);
3133 }
3134
3135 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003136}
3137
3138void Context::framebufferTextureMultiviewSideBySideANGLE(GLenum target,
3139 GLenum attachment,
3140 GLuint texture,
3141 GLint level,
3142 GLsizei numViews,
3143 const GLint *viewportOffsets)
3144{
Martin Radev5dae57b2017-07-14 16:15:55 +03003145 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3146 ASSERT(framebuffer);
3147
3148 if (texture != 0)
3149 {
3150 Texture *textureObj = getTexture(texture);
3151
3152 ImageIndex index = ImageIndex::Make2D(level);
3153 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3154 textureObj, numViews, viewportOffsets);
3155 }
3156 else
3157 {
3158 framebuffer->resetAttachment(this, attachment);
3159 }
3160
3161 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003162}
3163
Jamie Madillc29968b2016-01-20 11:17:23 -05003164void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3165{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003166 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003167 ASSERT(framebuffer);
3168 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003169 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003170}
3171
3172void Context::readBuffer(GLenum mode)
3173{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003174 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003175 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003176 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003177}
3178
3179void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3180{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003181 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003182 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003183
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003184 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003185 ASSERT(framebuffer);
3186
3187 // The specification isn't clear what should be done when the framebuffer isn't complete.
3188 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003189 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003190}
3191
3192void Context::invalidateFramebuffer(GLenum target,
3193 GLsizei numAttachments,
3194 const GLenum *attachments)
3195{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003196 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003197 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003198
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003199 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003200 ASSERT(framebuffer);
3201
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003202 if (framebuffer->checkStatus(this) != GL_FRAMEBUFFER_COMPLETE)
Jamie Madillc29968b2016-01-20 11:17:23 -05003203 {
Jamie Madill437fa652016-05-03 15:13:24 -04003204 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003205 }
Jamie Madill437fa652016-05-03 15:13:24 -04003206
Jamie Madill4928b7c2017-06-20 12:57:39 -04003207 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003208}
3209
3210void Context::invalidateSubFramebuffer(GLenum target,
3211 GLsizei numAttachments,
3212 const GLenum *attachments,
3213 GLint x,
3214 GLint y,
3215 GLsizei width,
3216 GLsizei height)
3217{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003218 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003219 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003220
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003221 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003222 ASSERT(framebuffer);
3223
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003224 if (framebuffer->checkStatus(this) != GL_FRAMEBUFFER_COMPLETE)
Jamie Madillc29968b2016-01-20 11:17:23 -05003225 {
Jamie Madill437fa652016-05-03 15:13:24 -04003226 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003227 }
Jamie Madill437fa652016-05-03 15:13:24 -04003228
3229 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003230 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003231}
3232
Jamie Madill73a84962016-02-12 09:27:23 -05003233void Context::texImage2D(GLenum target,
3234 GLint level,
3235 GLint internalformat,
3236 GLsizei width,
3237 GLsizei height,
3238 GLint border,
3239 GLenum format,
3240 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003241 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003242{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003243 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003244
3245 Extents size(width, height, 1);
3246 Texture *texture =
3247 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003248 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3249 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003250}
3251
3252void Context::texImage3D(GLenum target,
3253 GLint level,
3254 GLint internalformat,
3255 GLsizei width,
3256 GLsizei height,
3257 GLsizei depth,
3258 GLint border,
3259 GLenum format,
3260 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003261 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003262{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003263 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003264
3265 Extents size(width, height, depth);
3266 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003267 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3268 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003269}
3270
3271void Context::texSubImage2D(GLenum target,
3272 GLint level,
3273 GLint xoffset,
3274 GLint yoffset,
3275 GLsizei width,
3276 GLsizei height,
3277 GLenum format,
3278 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003279 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003280{
3281 // Zero sized uploads are valid but no-ops
3282 if (width == 0 || height == 0)
3283 {
3284 return;
3285 }
3286
Jamie Madillad9f24e2016-02-12 09:27:24 -05003287 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003288
3289 Box area(xoffset, yoffset, 0, width, height, 1);
3290 Texture *texture =
3291 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003292 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3293 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003294}
3295
3296void Context::texSubImage3D(GLenum target,
3297 GLint level,
3298 GLint xoffset,
3299 GLint yoffset,
3300 GLint zoffset,
3301 GLsizei width,
3302 GLsizei height,
3303 GLsizei depth,
3304 GLenum format,
3305 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003306 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003307{
3308 // Zero sized uploads are valid but no-ops
3309 if (width == 0 || height == 0 || depth == 0)
3310 {
3311 return;
3312 }
3313
Jamie Madillad9f24e2016-02-12 09:27:24 -05003314 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003315
3316 Box area(xoffset, yoffset, zoffset, width, height, depth);
3317 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003318 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3319 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003320}
3321
3322void Context::compressedTexImage2D(GLenum target,
3323 GLint level,
3324 GLenum internalformat,
3325 GLsizei width,
3326 GLsizei height,
3327 GLint border,
3328 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003329 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003330{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003331 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003332
3333 Extents size(width, height, 1);
3334 Texture *texture =
3335 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003336 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003337 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003338 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003339}
3340
3341void Context::compressedTexImage3D(GLenum target,
3342 GLint level,
3343 GLenum internalformat,
3344 GLsizei width,
3345 GLsizei height,
3346 GLsizei depth,
3347 GLint border,
3348 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003349 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003350{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003351 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003352
3353 Extents size(width, height, depth);
3354 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003355 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003356 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003357 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003358}
3359
3360void Context::compressedTexSubImage2D(GLenum target,
3361 GLint level,
3362 GLint xoffset,
3363 GLint yoffset,
3364 GLsizei width,
3365 GLsizei height,
3366 GLenum format,
3367 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003368 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003369{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003370 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003371
3372 Box area(xoffset, yoffset, 0, width, height, 1);
3373 Texture *texture =
3374 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003375 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003376 format, imageSize,
3377 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003378}
3379
3380void Context::compressedTexSubImage3D(GLenum target,
3381 GLint level,
3382 GLint xoffset,
3383 GLint yoffset,
3384 GLint zoffset,
3385 GLsizei width,
3386 GLsizei height,
3387 GLsizei depth,
3388 GLenum format,
3389 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003390 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003391{
3392 // Zero sized uploads are valid but no-ops
3393 if (width == 0 || height == 0)
3394 {
3395 return;
3396 }
3397
Jamie Madillad9f24e2016-02-12 09:27:24 -05003398 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003399
3400 Box area(xoffset, yoffset, zoffset, width, height, depth);
3401 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003402 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003403 format, imageSize,
3404 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003405}
3406
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003407void Context::generateMipmap(GLenum target)
3408{
3409 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003410 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003411}
3412
Geoff Lang97073d12016-04-20 10:42:34 -07003413void Context::copyTextureCHROMIUM(GLuint sourceId,
Geoff Langfc72a072017-03-24 14:52:39 -04003414 GLint sourceLevel,
3415 GLenum destTarget,
Geoff Lang97073d12016-04-20 10:42:34 -07003416 GLuint destId,
Geoff Langfc72a072017-03-24 14:52:39 -04003417 GLint destLevel,
Geoff Lang97073d12016-04-20 10:42:34 -07003418 GLint internalFormat,
3419 GLenum destType,
3420 GLboolean unpackFlipY,
3421 GLboolean unpackPremultiplyAlpha,
3422 GLboolean unpackUnmultiplyAlpha)
3423{
3424 syncStateForTexImage();
3425
3426 gl::Texture *sourceTexture = getTexture(sourceId);
3427 gl::Texture *destTexture = getTexture(destId);
Geoff Langfc72a072017-03-24 14:52:39 -04003428 handleError(destTexture->copyTexture(
3429 this, destTarget, destLevel, internalFormat, destType, sourceLevel, unpackFlipY == GL_TRUE,
3430 unpackPremultiplyAlpha == GL_TRUE, unpackUnmultiplyAlpha == GL_TRUE, sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003431}
3432
3433void Context::copySubTextureCHROMIUM(GLuint sourceId,
Geoff Langfc72a072017-03-24 14:52:39 -04003434 GLint sourceLevel,
3435 GLenum destTarget,
Geoff Lang97073d12016-04-20 10:42:34 -07003436 GLuint destId,
Geoff Langfc72a072017-03-24 14:52:39 -04003437 GLint destLevel,
Geoff Lang97073d12016-04-20 10:42:34 -07003438 GLint xoffset,
3439 GLint yoffset,
3440 GLint x,
3441 GLint y,
3442 GLsizei width,
3443 GLsizei height,
3444 GLboolean unpackFlipY,
3445 GLboolean unpackPremultiplyAlpha,
3446 GLboolean unpackUnmultiplyAlpha)
3447{
3448 // Zero sized copies are valid but no-ops
3449 if (width == 0 || height == 0)
3450 {
3451 return;
3452 }
3453
3454 syncStateForTexImage();
3455
3456 gl::Texture *sourceTexture = getTexture(sourceId);
3457 gl::Texture *destTexture = getTexture(destId);
3458 Offset offset(xoffset, yoffset, 0);
3459 Rectangle area(x, y, width, height);
Geoff Langfc72a072017-03-24 14:52:39 -04003460 handleError(destTexture->copySubTexture(
3461 this, destTarget, destLevel, offset, sourceLevel, area, unpackFlipY == GL_TRUE,
3462 unpackPremultiplyAlpha == GL_TRUE, unpackUnmultiplyAlpha == GL_TRUE, sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003463}
3464
Geoff Lang47110bf2016-04-20 11:13:22 -07003465void Context::compressedCopyTextureCHROMIUM(GLuint sourceId, GLuint destId)
3466{
3467 syncStateForTexImage();
3468
3469 gl::Texture *sourceTexture = getTexture(sourceId);
3470 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05003471 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07003472}
3473
Geoff Lang496c02d2016-10-20 11:38:11 -07003474void Context::getBufferPointerv(GLenum target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03003475{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003476 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003477 ASSERT(buffer);
3478
Geoff Lang496c02d2016-10-20 11:38:11 -07003479 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03003480}
3481
Jamie Madill876429b2017-04-20 15:46:24 -04003482void *Context::mapBuffer(GLenum target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003483{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003484 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003485 ASSERT(buffer);
3486
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003487 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003488 if (error.isError())
3489 {
Jamie Madill437fa652016-05-03 15:13:24 -04003490 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003491 return nullptr;
3492 }
3493
3494 return buffer->getMapPointer();
3495}
3496
3497GLboolean Context::unmapBuffer(GLenum target)
3498{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003499 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003500 ASSERT(buffer);
3501
3502 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003503 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03003504 if (error.isError())
3505 {
Jamie Madill437fa652016-05-03 15:13:24 -04003506 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003507 return GL_FALSE;
3508 }
3509
3510 return result;
3511}
3512
Jamie Madill876429b2017-04-20 15:46:24 -04003513void *Context::mapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003514{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003515 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003516 ASSERT(buffer);
3517
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003518 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003519 if (error.isError())
3520 {
Jamie Madill437fa652016-05-03 15:13:24 -04003521 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003522 return nullptr;
3523 }
3524
3525 return buffer->getMapPointer();
3526}
3527
3528void Context::flushMappedBufferRange(GLenum /*target*/, GLintptr /*offset*/, GLsizeiptr /*length*/)
3529{
3530 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
3531}
3532
Jamie Madillad9f24e2016-02-12 09:27:24 -05003533void Context::syncStateForReadPixels()
3534{
3535 syncRendererState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
3536}
3537
3538void Context::syncStateForTexImage()
3539{
3540 syncRendererState(mTexImageDirtyBits, mTexImageDirtyObjects);
3541}
3542
3543void Context::syncStateForClear()
3544{
3545 syncRendererState(mClearDirtyBits, mClearDirtyObjects);
3546}
3547
3548void Context::syncStateForBlit()
3549{
3550 syncRendererState(mBlitDirtyBits, mBlitDirtyObjects);
3551}
3552
Jamie Madillc20ab272016-06-09 07:20:46 -07003553void Context::activeTexture(GLenum texture)
3554{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003555 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003556}
3557
Jamie Madill876429b2017-04-20 15:46:24 -04003558void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003559{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003560 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07003561}
3562
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003563void Context::blendEquation(GLenum mode)
3564{
3565 mGLState.setBlendEquation(mode, mode);
3566}
3567
Jamie Madillc20ab272016-06-09 07:20:46 -07003568void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
3569{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003570 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003571}
3572
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003573void Context::blendFunc(GLenum sfactor, GLenum dfactor)
3574{
3575 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
3576}
3577
Jamie Madillc20ab272016-06-09 07:20:46 -07003578void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
3579{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003580 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003581}
3582
Jamie Madill876429b2017-04-20 15:46:24 -04003583void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003584{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003585 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003586}
3587
Jamie Madill876429b2017-04-20 15:46:24 -04003588void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07003589{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003590 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07003591}
3592
3593void Context::clearStencil(GLint s)
3594{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003595 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07003596}
3597
3598void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
3599{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003600 mGLState.setColorMask(red == GL_TRUE, green == GL_TRUE, blue == GL_TRUE, alpha == GL_TRUE);
Jamie Madillc20ab272016-06-09 07:20:46 -07003601}
3602
Corentin Wallez2e568cf2017-09-18 17:05:22 -04003603void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07003604{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003605 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003606}
3607
3608void Context::depthFunc(GLenum func)
3609{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003610 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07003611}
3612
3613void Context::depthMask(GLboolean flag)
3614{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003615 mGLState.setDepthMask(flag != GL_FALSE);
Jamie Madillc20ab272016-06-09 07:20:46 -07003616}
3617
Jamie Madill876429b2017-04-20 15:46:24 -04003618void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07003619{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003620 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07003621}
3622
3623void Context::disable(GLenum cap)
3624{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003625 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003626}
3627
3628void Context::disableVertexAttribArray(GLuint index)
3629{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003630 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003631}
3632
3633void Context::enable(GLenum cap)
3634{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003635 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003636}
3637
3638void Context::enableVertexAttribArray(GLuint index)
3639{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003640 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003641}
3642
3643void Context::frontFace(GLenum mode)
3644{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003645 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003646}
3647
3648void Context::hint(GLenum target, GLenum mode)
3649{
3650 switch (target)
3651 {
3652 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003653 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003654 break;
3655
3656 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003657 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003658 break;
3659
3660 default:
3661 UNREACHABLE();
3662 return;
3663 }
3664}
3665
3666void Context::lineWidth(GLfloat width)
3667{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003668 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07003669}
3670
3671void Context::pixelStorei(GLenum pname, GLint param)
3672{
3673 switch (pname)
3674 {
3675 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003676 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003677 break;
3678
3679 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003680 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003681 break;
3682
3683 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003684 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003685 break;
3686
3687 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003688 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003689 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003690 break;
3691
3692 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03003693 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003694 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003695 break;
3696
3697 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03003698 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003699 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003700 break;
3701
3702 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003703 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003704 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003705 break;
3706
3707 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003708 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003709 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003710 break;
3711
3712 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003713 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003714 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003715 break;
3716
3717 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003718 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003719 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003720 break;
3721
3722 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003723 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003724 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003725 break;
3726
3727 default:
3728 UNREACHABLE();
3729 return;
3730 }
3731}
3732
3733void Context::polygonOffset(GLfloat factor, GLfloat units)
3734{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003735 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07003736}
3737
Jamie Madill876429b2017-04-20 15:46:24 -04003738void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07003739{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003740 mGLState.setSampleCoverageParams(clamp01(value), invert == GL_TRUE);
Jamie Madillc20ab272016-06-09 07:20:46 -07003741}
3742
Jiawei Shaodb342272017-09-27 10:21:45 +08003743void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
3744{
3745 mGLState.setSampleMaskParams(maskNumber, mask);
3746}
3747
Jamie Madillc20ab272016-06-09 07:20:46 -07003748void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
3749{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003750 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07003751}
3752
3753void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
3754{
3755 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3756 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003757 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003758 }
3759
3760 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3761 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003762 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003763 }
3764}
3765
3766void Context::stencilMaskSeparate(GLenum face, GLuint mask)
3767{
3768 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3769 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003770 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003771 }
3772
3773 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3774 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003775 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003776 }
3777}
3778
3779void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
3780{
3781 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3782 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003783 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003784 }
3785
3786 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3787 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003788 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003789 }
3790}
3791
3792void Context::vertexAttrib1f(GLuint index, GLfloat x)
3793{
3794 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003795 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003796}
3797
3798void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
3799{
3800 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003801 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003802}
3803
3804void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
3805{
3806 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003807 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003808}
3809
3810void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
3811{
3812 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003813 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003814}
3815
3816void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
3817{
3818 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003819 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003820}
3821
3822void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
3823{
3824 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003825 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003826}
3827
3828void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
3829{
3830 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003831 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003832}
3833
3834void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
3835{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003836 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07003837}
3838
3839void Context::vertexAttribPointer(GLuint index,
3840 GLint size,
3841 GLenum type,
3842 GLboolean normalized,
3843 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04003844 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07003845{
Shaodde78e82017-05-22 14:13:27 +08003846 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(GL_ARRAY_BUFFER), size,
3847 type, normalized == GL_TRUE, false, stride, ptr);
Jamie Madillc20ab272016-06-09 07:20:46 -07003848}
3849
Shao80957d92017-02-20 21:25:59 +08003850void Context::vertexAttribFormat(GLuint attribIndex,
3851 GLint size,
3852 GLenum type,
3853 GLboolean normalized,
3854 GLuint relativeOffset)
3855{
3856 mGLState.setVertexAttribFormat(attribIndex, size, type, normalized == GL_TRUE, false,
3857 relativeOffset);
3858}
3859
3860void Context::vertexAttribIFormat(GLuint attribIndex,
3861 GLint size,
3862 GLenum type,
3863 GLuint relativeOffset)
3864{
3865 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
3866}
3867
3868void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
3869{
Shaodde78e82017-05-22 14:13:27 +08003870 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Shao80957d92017-02-20 21:25:59 +08003871}
3872
3873void Context::setVertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
3874{
3875 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
3876}
3877
Jamie Madillc20ab272016-06-09 07:20:46 -07003878void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
3879{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003880 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07003881}
3882
3883void Context::vertexAttribIPointer(GLuint index,
3884 GLint size,
3885 GLenum type,
3886 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04003887 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07003888{
Shaodde78e82017-05-22 14:13:27 +08003889 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(GL_ARRAY_BUFFER), size,
3890 type, false, true, stride, pointer);
Jamie Madillc20ab272016-06-09 07:20:46 -07003891}
3892
3893void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
3894{
3895 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003896 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003897}
3898
3899void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
3900{
3901 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003902 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003903}
3904
3905void Context::vertexAttribI4iv(GLuint index, const GLint *v)
3906{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003907 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07003908}
3909
3910void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
3911{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003912 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07003913}
3914
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003915void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
3916{
3917 const VertexAttribCurrentValueData &currentValues =
3918 getGLState().getVertexAttribCurrentValue(index);
3919 const VertexArray *vao = getGLState().getVertexArray();
3920 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3921 currentValues, pname, params);
3922}
3923
3924void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
3925{
3926 const VertexAttribCurrentValueData &currentValues =
3927 getGLState().getVertexAttribCurrentValue(index);
3928 const VertexArray *vao = getGLState().getVertexArray();
3929 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3930 currentValues, pname, params);
3931}
3932
3933void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
3934{
3935 const VertexAttribCurrentValueData &currentValues =
3936 getGLState().getVertexAttribCurrentValue(index);
3937 const VertexArray *vao = getGLState().getVertexArray();
3938 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3939 currentValues, pname, params);
3940}
3941
3942void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
3943{
3944 const VertexAttribCurrentValueData &currentValues =
3945 getGLState().getVertexAttribCurrentValue(index);
3946 const VertexArray *vao = getGLState().getVertexArray();
3947 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3948 currentValues, pname, params);
3949}
3950
Jamie Madill876429b2017-04-20 15:46:24 -04003951void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003952{
3953 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
3954 QueryVertexAttribPointerv(attrib, pname, pointer);
3955}
3956
Jamie Madillc20ab272016-06-09 07:20:46 -07003957void Context::debugMessageControl(GLenum source,
3958 GLenum type,
3959 GLenum severity,
3960 GLsizei count,
3961 const GLuint *ids,
3962 GLboolean enabled)
3963{
3964 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003965 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
3966 (enabled != GL_FALSE));
Jamie Madillc20ab272016-06-09 07:20:46 -07003967}
3968
3969void Context::debugMessageInsert(GLenum source,
3970 GLenum type,
3971 GLuint id,
3972 GLenum severity,
3973 GLsizei length,
3974 const GLchar *buf)
3975{
3976 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003977 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07003978}
3979
3980void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
3981{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003982 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07003983}
3984
3985GLuint Context::getDebugMessageLog(GLuint count,
3986 GLsizei bufSize,
3987 GLenum *sources,
3988 GLenum *types,
3989 GLuint *ids,
3990 GLenum *severities,
3991 GLsizei *lengths,
3992 GLchar *messageLog)
3993{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003994 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
3995 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07003996}
3997
3998void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
3999{
4000 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004001 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004002}
4003
4004void Context::popDebugGroup()
4005{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004006 mGLState.getDebug().popGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004007}
4008
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004009void Context::bufferData(GLenum target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004010{
4011 Buffer *buffer = mGLState.getTargetBuffer(target);
4012 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004013 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004014}
4015
Jamie Madill876429b2017-04-20 15:46:24 -04004016void Context::bufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004017{
4018 if (data == nullptr)
4019 {
4020 return;
4021 }
4022
4023 Buffer *buffer = mGLState.getTargetBuffer(target);
4024 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004025 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004026}
4027
Jamie Madillef300b12016-10-07 15:12:09 -04004028void Context::attachShader(GLuint program, GLuint shader)
4029{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004030 auto programObject = mState.mShaderPrograms->getProgram(program);
4031 auto shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004032 ASSERT(programObject && shaderObject);
4033 programObject->attachShader(shaderObject);
4034}
4035
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004036const Workarounds &Context::getWorkarounds() const
4037{
4038 return mWorkarounds;
4039}
4040
Jamie Madillb0817d12016-11-01 15:48:31 -04004041void Context::copyBufferSubData(GLenum readTarget,
4042 GLenum writeTarget,
4043 GLintptr readOffset,
4044 GLintptr writeOffset,
4045 GLsizeiptr size)
4046{
4047 // if size is zero, the copy is a successful no-op
4048 if (size == 0)
4049 {
4050 return;
4051 }
4052
4053 // TODO(jmadill): cache these.
4054 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4055 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4056
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004057 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004058}
4059
Jamie Madill01a80ee2016-11-07 12:06:18 -05004060void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4061{
4062 Program *programObject = getProgram(program);
4063 // TODO(jmadill): Re-use this from the validation if possible.
4064 ASSERT(programObject);
4065 programObject->bindAttributeLocation(index, name);
4066}
4067
4068void Context::bindBuffer(GLenum target, GLuint buffer)
4069{
4070 switch (target)
4071 {
4072 case GL_ARRAY_BUFFER:
4073 bindArrayBuffer(buffer);
4074 break;
4075 case GL_ELEMENT_ARRAY_BUFFER:
4076 bindElementArrayBuffer(buffer);
4077 break;
4078 case GL_COPY_READ_BUFFER:
4079 bindCopyReadBuffer(buffer);
4080 break;
4081 case GL_COPY_WRITE_BUFFER:
4082 bindCopyWriteBuffer(buffer);
4083 break;
4084 case GL_PIXEL_PACK_BUFFER:
4085 bindPixelPackBuffer(buffer);
4086 break;
4087 case GL_PIXEL_UNPACK_BUFFER:
4088 bindPixelUnpackBuffer(buffer);
4089 break;
4090 case GL_UNIFORM_BUFFER:
4091 bindGenericUniformBuffer(buffer);
4092 break;
4093 case GL_TRANSFORM_FEEDBACK_BUFFER:
4094 bindGenericTransformFeedbackBuffer(buffer);
4095 break;
Geoff Lang3b573612016-10-31 14:08:10 -04004096 case GL_ATOMIC_COUNTER_BUFFER:
Jiajia Qin6eafb042016-12-27 17:04:07 +08004097 bindGenericAtomicCounterBuffer(buffer);
Geoff Lang3b573612016-10-31 14:08:10 -04004098 break;
4099 case GL_SHADER_STORAGE_BUFFER:
Jiajia Qinf546e7d2017-03-27 14:12:59 +08004100 bindGenericShaderStorageBuffer(buffer);
Geoff Lang3b573612016-10-31 14:08:10 -04004101 break;
4102 case GL_DRAW_INDIRECT_BUFFER:
Jiajia Qin9d7d0b12016-11-29 16:30:31 +08004103 bindDrawIndirectBuffer(buffer);
Geoff Lang3b573612016-10-31 14:08:10 -04004104 break;
4105 case GL_DISPATCH_INDIRECT_BUFFER:
Geoff Lang9f090372016-12-02 10:20:43 -05004106 if (buffer != 0)
4107 {
4108 // Binding buffers to this binding point is not implemented yet.
4109 UNIMPLEMENTED();
4110 }
Geoff Lang3b573612016-10-31 14:08:10 -04004111 break;
Jamie Madill01a80ee2016-11-07 12:06:18 -05004112
4113 default:
4114 UNREACHABLE();
4115 break;
4116 }
4117}
4118
Jiajia Qin6eafb042016-12-27 17:04:07 +08004119void Context::bindBufferBase(GLenum target, GLuint index, GLuint buffer)
4120{
4121 bindBufferRange(target, index, buffer, 0, 0);
4122}
4123
4124void Context::bindBufferRange(GLenum target,
4125 GLuint index,
4126 GLuint buffer,
4127 GLintptr offset,
4128 GLsizeiptr size)
4129{
4130 switch (target)
4131 {
4132 case GL_TRANSFORM_FEEDBACK_BUFFER:
4133 bindIndexedTransformFeedbackBuffer(buffer, index, offset, size);
4134 bindGenericTransformFeedbackBuffer(buffer);
4135 break;
4136 case GL_UNIFORM_BUFFER:
4137 bindIndexedUniformBuffer(buffer, index, offset, size);
4138 bindGenericUniformBuffer(buffer);
4139 break;
4140 case GL_ATOMIC_COUNTER_BUFFER:
4141 bindIndexedAtomicCounterBuffer(buffer, index, offset, size);
4142 bindGenericAtomicCounterBuffer(buffer);
4143 break;
4144 case GL_SHADER_STORAGE_BUFFER:
Jiajia Qinf546e7d2017-03-27 14:12:59 +08004145 bindIndexedShaderStorageBuffer(buffer, index, offset, size);
4146 bindGenericShaderStorageBuffer(buffer);
Jiajia Qin6eafb042016-12-27 17:04:07 +08004147 break;
4148 default:
4149 UNREACHABLE();
4150 break;
4151 }
4152}
4153
Jamie Madill01a80ee2016-11-07 12:06:18 -05004154void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
4155{
4156 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4157 {
4158 bindReadFramebuffer(framebuffer);
4159 }
4160
4161 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4162 {
4163 bindDrawFramebuffer(framebuffer);
4164 }
4165}
4166
4167void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4168{
4169 ASSERT(target == GL_RENDERBUFFER);
4170 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004171 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04004172 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004173}
4174
JiangYizhoubddc46b2016-12-09 09:50:51 +08004175void Context::texStorage2DMultisample(GLenum target,
4176 GLsizei samples,
4177 GLenum internalformat,
4178 GLsizei width,
4179 GLsizei height,
4180 GLboolean fixedsamplelocations)
4181{
4182 Extents size(width, height, 1);
4183 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05004184 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
JiangYizhoubddc46b2016-12-09 09:50:51 +08004185 fixedsamplelocations));
4186}
4187
4188void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4189{
JiangYizhou5b03f472017-01-09 10:22:53 +08004190 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
4191 // the sample position should be queried by DRAW_FRAMEBUFFER.
4192 mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER);
4193 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08004194
4195 switch (pname)
4196 {
4197 case GL_SAMPLE_POSITION:
4198 handleError(framebuffer->getSamplePosition(index, val));
4199 break;
4200 default:
4201 UNREACHABLE();
4202 }
4203}
4204
Jamie Madille8fb6402017-02-14 17:56:40 -05004205void Context::renderbufferStorage(GLenum target,
4206 GLenum internalformat,
4207 GLsizei width,
4208 GLsizei height)
4209{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004210 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4211 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
4212
Jamie Madille8fb6402017-02-14 17:56:40 -05004213 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04004214 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004215}
4216
4217void Context::renderbufferStorageMultisample(GLenum target,
4218 GLsizei samples,
4219 GLenum internalformat,
4220 GLsizei width,
4221 GLsizei height)
4222{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004223 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4224 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05004225
4226 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004227 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04004228 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004229}
4230
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004231void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
4232{
Jamie Madill70b5bb02017-08-28 13:32:37 -04004233 const Sync *syncObject = getSync(sync);
Geoff Lang82483b92017-04-11 15:33:00 -04004234 handleError(QuerySynciv(syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004235}
4236
JiangYizhoue18e6392017-02-20 10:32:23 +08004237void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
4238{
4239 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4240 QueryFramebufferParameteriv(framebuffer, pname, params);
4241}
4242
4243void Context::setFramebufferParameteri(GLenum target, GLenum pname, GLint param)
4244{
4245 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4246 SetFramebufferParameteri(framebuffer, pname, param);
4247}
4248
Jamie Madillb3f26b92017-07-19 15:07:41 -04004249Error Context::getScratchBuffer(size_t requstedSizeBytes,
4250 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05004251{
Jamie Madillb3f26b92017-07-19 15:07:41 -04004252 if (!mScratchBuffer.get(requstedSizeBytes, scratchBufferOut))
4253 {
4254 return OutOfMemory() << "Failed to allocate internal buffer.";
4255 }
4256 return NoError();
4257}
4258
4259Error Context::getZeroFilledBuffer(size_t requstedSizeBytes,
4260 angle::MemoryBuffer **zeroBufferOut) const
4261{
4262 if (!mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0))
Jamie Madille14951e2017-03-09 18:55:16 -05004263 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004264 return OutOfMemory() << "Failed to allocate internal buffer.";
Jamie Madille14951e2017-03-09 18:55:16 -05004265 }
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004266 return NoError();
Jamie Madille14951e2017-03-09 18:55:16 -05004267}
4268
Xinghua Cao2b396592017-03-29 15:36:04 +08004269void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
4270{
4271 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
4272 {
4273 return;
4274 }
4275
Jamie Madill05b35b22017-10-03 09:01:44 -04004276 // TODO(jmadill): Dirty bits for compute.
Jamie Madilla59fc192017-11-02 12:57:58 -04004277 if (isRobustResourceInitEnabled())
4278 {
4279 ANGLE_CONTEXT_TRY(mGLState.clearUnclearedActiveTextures(this));
4280 }
Jamie Madill05b35b22017-10-03 09:01:44 -04004281
Jamie Madill71c88b32017-09-14 22:20:29 -04004282 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08004283}
4284
JiangYizhou165361c2017-06-07 14:56:57 +08004285void Context::texStorage2D(GLenum target,
4286 GLsizei levels,
4287 GLenum internalFormat,
4288 GLsizei width,
4289 GLsizei height)
4290{
4291 Extents size(width, height, 1);
4292 Texture *texture = getTargetTexture(target);
4293 handleError(texture->setStorage(this, target, levels, internalFormat, size));
4294}
4295
4296void Context::texStorage3D(GLenum target,
4297 GLsizei levels,
4298 GLenum internalFormat,
4299 GLsizei width,
4300 GLsizei height,
4301 GLsizei depth)
4302{
4303 Extents size(width, height, depth);
4304 Texture *texture = getTargetTexture(target);
4305 handleError(texture->setStorage(this, target, levels, internalFormat, size));
4306}
4307
Jamie Madillc1d770e2017-04-13 17:31:24 -04004308GLenum Context::checkFramebufferStatus(GLenum target)
4309{
4310 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4311 ASSERT(framebuffer);
4312
4313 return framebuffer->checkStatus(this);
4314}
4315
4316void Context::compileShader(GLuint shader)
4317{
4318 Shader *shaderObject = GetValidShader(this, shader);
4319 if (!shaderObject)
4320 {
4321 return;
4322 }
4323 shaderObject->compile(this);
4324}
4325
4326void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
4327{
4328 for (int i = 0; i < n; i++)
4329 {
4330 deleteBuffer(buffers[i]);
4331 }
4332}
4333
4334void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
4335{
4336 for (int i = 0; i < n; i++)
4337 {
4338 if (framebuffers[i] != 0)
4339 {
4340 deleteFramebuffer(framebuffers[i]);
4341 }
4342 }
4343}
4344
4345void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
4346{
4347 for (int i = 0; i < n; i++)
4348 {
4349 deleteRenderbuffer(renderbuffers[i]);
4350 }
4351}
4352
4353void Context::deleteTextures(GLsizei n, const GLuint *textures)
4354{
4355 for (int i = 0; i < n; i++)
4356 {
4357 if (textures[i] != 0)
4358 {
4359 deleteTexture(textures[i]);
4360 }
4361 }
4362}
4363
4364void Context::detachShader(GLuint program, GLuint shader)
4365{
4366 Program *programObject = getProgram(program);
4367 ASSERT(programObject);
4368
4369 Shader *shaderObject = getShader(shader);
4370 ASSERT(shaderObject);
4371
4372 programObject->detachShader(this, shaderObject);
4373}
4374
4375void Context::genBuffers(GLsizei n, GLuint *buffers)
4376{
4377 for (int i = 0; i < n; i++)
4378 {
4379 buffers[i] = createBuffer();
4380 }
4381}
4382
4383void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
4384{
4385 for (int i = 0; i < n; i++)
4386 {
4387 framebuffers[i] = createFramebuffer();
4388 }
4389}
4390
4391void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
4392{
4393 for (int i = 0; i < n; i++)
4394 {
4395 renderbuffers[i] = createRenderbuffer();
4396 }
4397}
4398
4399void Context::genTextures(GLsizei n, GLuint *textures)
4400{
4401 for (int i = 0; i < n; i++)
4402 {
4403 textures[i] = createTexture();
4404 }
4405}
4406
4407void Context::getActiveAttrib(GLuint program,
4408 GLuint index,
4409 GLsizei bufsize,
4410 GLsizei *length,
4411 GLint *size,
4412 GLenum *type,
4413 GLchar *name)
4414{
4415 Program *programObject = getProgram(program);
4416 ASSERT(programObject);
4417 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
4418}
4419
4420void Context::getActiveUniform(GLuint program,
4421 GLuint index,
4422 GLsizei bufsize,
4423 GLsizei *length,
4424 GLint *size,
4425 GLenum *type,
4426 GLchar *name)
4427{
4428 Program *programObject = getProgram(program);
4429 ASSERT(programObject);
4430 programObject->getActiveUniform(index, bufsize, length, size, type, name);
4431}
4432
4433void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
4434{
4435 Program *programObject = getProgram(program);
4436 ASSERT(programObject);
4437 programObject->getAttachedShaders(maxcount, count, shaders);
4438}
4439
4440GLint Context::getAttribLocation(GLuint program, const GLchar *name)
4441{
4442 Program *programObject = getProgram(program);
4443 ASSERT(programObject);
4444 return programObject->getAttributeLocation(name);
4445}
4446
4447void Context::getBooleanv(GLenum pname, GLboolean *params)
4448{
4449 GLenum nativeType;
4450 unsigned int numParams = 0;
4451 getQueryParameterInfo(pname, &nativeType, &numParams);
4452
4453 if (nativeType == GL_BOOL)
4454 {
4455 getBooleanvImpl(pname, params);
4456 }
4457 else
4458 {
4459 CastStateValues(this, nativeType, pname, numParams, params);
4460 }
4461}
4462
4463void Context::getFloatv(GLenum pname, GLfloat *params)
4464{
4465 GLenum nativeType;
4466 unsigned int numParams = 0;
4467 getQueryParameterInfo(pname, &nativeType, &numParams);
4468
4469 if (nativeType == GL_FLOAT)
4470 {
4471 getFloatvImpl(pname, params);
4472 }
4473 else
4474 {
4475 CastStateValues(this, nativeType, pname, numParams, params);
4476 }
4477}
4478
4479void Context::getIntegerv(GLenum pname, GLint *params)
4480{
4481 GLenum nativeType;
4482 unsigned int numParams = 0;
4483 getQueryParameterInfo(pname, &nativeType, &numParams);
4484
4485 if (nativeType == GL_INT)
4486 {
4487 getIntegervImpl(pname, params);
4488 }
4489 else
4490 {
4491 CastStateValues(this, nativeType, pname, numParams, params);
4492 }
4493}
4494
4495void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
4496{
4497 Program *programObject = getProgram(program);
4498 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04004499 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004500}
4501
Jamie Madillbe849e42017-05-02 15:49:00 -04004502void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04004503{
4504 Program *programObject = getProgram(program);
4505 ASSERT(programObject);
4506 programObject->getInfoLog(bufsize, length, infolog);
4507}
4508
4509void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
4510{
4511 Shader *shaderObject = getShader(shader);
4512 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004513 QueryShaderiv(this, shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004514}
4515
4516void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
4517{
4518 Shader *shaderObject = getShader(shader);
4519 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004520 shaderObject->getInfoLog(this, bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004521}
4522
4523void Context::getShaderPrecisionFormat(GLenum shadertype,
4524 GLenum precisiontype,
4525 GLint *range,
4526 GLint *precision)
4527{
4528 // TODO(jmadill): Compute shaders.
4529
4530 switch (shadertype)
4531 {
4532 case GL_VERTEX_SHADER:
4533 switch (precisiontype)
4534 {
4535 case GL_LOW_FLOAT:
4536 mCaps.vertexLowpFloat.get(range, precision);
4537 break;
4538 case GL_MEDIUM_FLOAT:
4539 mCaps.vertexMediumpFloat.get(range, precision);
4540 break;
4541 case GL_HIGH_FLOAT:
4542 mCaps.vertexHighpFloat.get(range, precision);
4543 break;
4544
4545 case GL_LOW_INT:
4546 mCaps.vertexLowpInt.get(range, precision);
4547 break;
4548 case GL_MEDIUM_INT:
4549 mCaps.vertexMediumpInt.get(range, precision);
4550 break;
4551 case GL_HIGH_INT:
4552 mCaps.vertexHighpInt.get(range, precision);
4553 break;
4554
4555 default:
4556 UNREACHABLE();
4557 return;
4558 }
4559 break;
4560
4561 case GL_FRAGMENT_SHADER:
4562 switch (precisiontype)
4563 {
4564 case GL_LOW_FLOAT:
4565 mCaps.fragmentLowpFloat.get(range, precision);
4566 break;
4567 case GL_MEDIUM_FLOAT:
4568 mCaps.fragmentMediumpFloat.get(range, precision);
4569 break;
4570 case GL_HIGH_FLOAT:
4571 mCaps.fragmentHighpFloat.get(range, precision);
4572 break;
4573
4574 case GL_LOW_INT:
4575 mCaps.fragmentLowpInt.get(range, precision);
4576 break;
4577 case GL_MEDIUM_INT:
4578 mCaps.fragmentMediumpInt.get(range, precision);
4579 break;
4580 case GL_HIGH_INT:
4581 mCaps.fragmentHighpInt.get(range, precision);
4582 break;
4583
4584 default:
4585 UNREACHABLE();
4586 return;
4587 }
4588 break;
4589
4590 default:
4591 UNREACHABLE();
4592 return;
4593 }
4594}
4595
4596void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
4597{
4598 Shader *shaderObject = getShader(shader);
4599 ASSERT(shaderObject);
4600 shaderObject->getSource(bufsize, length, source);
4601}
4602
4603void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
4604{
4605 Program *programObject = getProgram(program);
4606 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04004607 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004608}
4609
4610void Context::getUniformiv(GLuint program, GLint location, GLint *params)
4611{
4612 Program *programObject = getProgram(program);
4613 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04004614 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004615}
4616
4617GLint Context::getUniformLocation(GLuint program, const GLchar *name)
4618{
4619 Program *programObject = getProgram(program);
4620 ASSERT(programObject);
4621 return programObject->getUniformLocation(name);
4622}
4623
4624GLboolean Context::isBuffer(GLuint buffer)
4625{
4626 if (buffer == 0)
4627 {
4628 return GL_FALSE;
4629 }
4630
4631 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
4632}
4633
4634GLboolean Context::isEnabled(GLenum cap)
4635{
4636 return mGLState.getEnableFeature(cap);
4637}
4638
4639GLboolean Context::isFramebuffer(GLuint framebuffer)
4640{
4641 if (framebuffer == 0)
4642 {
4643 return GL_FALSE;
4644 }
4645
4646 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
4647}
4648
4649GLboolean Context::isProgram(GLuint program)
4650{
4651 if (program == 0)
4652 {
4653 return GL_FALSE;
4654 }
4655
4656 return (getProgram(program) ? GL_TRUE : GL_FALSE);
4657}
4658
4659GLboolean Context::isRenderbuffer(GLuint renderbuffer)
4660{
4661 if (renderbuffer == 0)
4662 {
4663 return GL_FALSE;
4664 }
4665
4666 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
4667}
4668
4669GLboolean Context::isShader(GLuint shader)
4670{
4671 if (shader == 0)
4672 {
4673 return GL_FALSE;
4674 }
4675
4676 return (getShader(shader) ? GL_TRUE : GL_FALSE);
4677}
4678
4679GLboolean Context::isTexture(GLuint texture)
4680{
4681 if (texture == 0)
4682 {
4683 return GL_FALSE;
4684 }
4685
4686 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
4687}
4688
4689void Context::linkProgram(GLuint program)
4690{
4691 Program *programObject = getProgram(program);
4692 ASSERT(programObject);
4693 handleError(programObject->link(this));
Martin Radev0abb7a22017-08-28 15:34:45 +03004694 mGLState.onProgramExecutableChange(programObject);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004695}
4696
4697void Context::releaseShaderCompiler()
4698{
Jamie Madill4928b7c2017-06-20 12:57:39 -04004699 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004700}
4701
4702void Context::shaderBinary(GLsizei n,
4703 const GLuint *shaders,
4704 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04004705 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04004706 GLsizei length)
4707{
4708 // No binary shader formats are supported.
4709 UNIMPLEMENTED();
4710}
4711
4712void Context::shaderSource(GLuint shader,
4713 GLsizei count,
4714 const GLchar *const *string,
4715 const GLint *length)
4716{
4717 Shader *shaderObject = getShader(shader);
4718 ASSERT(shaderObject);
4719 shaderObject->setSource(count, string, length);
4720}
4721
4722void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
4723{
4724 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
4725}
4726
4727void Context::stencilMask(GLuint mask)
4728{
4729 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
4730}
4731
4732void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
4733{
4734 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
4735}
4736
4737void Context::uniform1f(GLint location, GLfloat x)
4738{
4739 Program *program = mGLState.getProgram();
4740 program->setUniform1fv(location, 1, &x);
4741}
4742
4743void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
4744{
4745 Program *program = mGLState.getProgram();
4746 program->setUniform1fv(location, count, v);
4747}
4748
4749void Context::uniform1i(GLint location, GLint x)
4750{
4751 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04004752 if (program->setUniform1iv(location, 1, &x) == Program::SetUniformResult::SamplerChanged)
4753 {
4754 mGLState.setObjectDirty(GL_PROGRAM);
4755 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04004756}
4757
4758void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
4759{
4760 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04004761 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
4762 {
4763 mGLState.setObjectDirty(GL_PROGRAM);
4764 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04004765}
4766
4767void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
4768{
4769 GLfloat xy[2] = {x, y};
4770 Program *program = mGLState.getProgram();
4771 program->setUniform2fv(location, 1, xy);
4772}
4773
4774void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
4775{
4776 Program *program = mGLState.getProgram();
4777 program->setUniform2fv(location, count, v);
4778}
4779
4780void Context::uniform2i(GLint location, GLint x, GLint y)
4781{
4782 GLint xy[2] = {x, y};
4783 Program *program = mGLState.getProgram();
4784 program->setUniform2iv(location, 1, xy);
4785}
4786
4787void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
4788{
4789 Program *program = mGLState.getProgram();
4790 program->setUniform2iv(location, count, v);
4791}
4792
4793void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
4794{
4795 GLfloat xyz[3] = {x, y, z};
4796 Program *program = mGLState.getProgram();
4797 program->setUniform3fv(location, 1, xyz);
4798}
4799
4800void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
4801{
4802 Program *program = mGLState.getProgram();
4803 program->setUniform3fv(location, count, v);
4804}
4805
4806void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
4807{
4808 GLint xyz[3] = {x, y, z};
4809 Program *program = mGLState.getProgram();
4810 program->setUniform3iv(location, 1, xyz);
4811}
4812
4813void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
4814{
4815 Program *program = mGLState.getProgram();
4816 program->setUniform3iv(location, count, v);
4817}
4818
4819void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4820{
4821 GLfloat xyzw[4] = {x, y, z, w};
4822 Program *program = mGLState.getProgram();
4823 program->setUniform4fv(location, 1, xyzw);
4824}
4825
4826void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
4827{
4828 Program *program = mGLState.getProgram();
4829 program->setUniform4fv(location, count, v);
4830}
4831
4832void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
4833{
4834 GLint xyzw[4] = {x, y, z, w};
4835 Program *program = mGLState.getProgram();
4836 program->setUniform4iv(location, 1, xyzw);
4837}
4838
4839void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
4840{
4841 Program *program = mGLState.getProgram();
4842 program->setUniform4iv(location, count, v);
4843}
4844
4845void Context::uniformMatrix2fv(GLint location,
4846 GLsizei count,
4847 GLboolean transpose,
4848 const GLfloat *value)
4849{
4850 Program *program = mGLState.getProgram();
4851 program->setUniformMatrix2fv(location, count, transpose, value);
4852}
4853
4854void Context::uniformMatrix3fv(GLint location,
4855 GLsizei count,
4856 GLboolean transpose,
4857 const GLfloat *value)
4858{
4859 Program *program = mGLState.getProgram();
4860 program->setUniformMatrix3fv(location, count, transpose, value);
4861}
4862
4863void Context::uniformMatrix4fv(GLint location,
4864 GLsizei count,
4865 GLboolean transpose,
4866 const GLfloat *value)
4867{
4868 Program *program = mGLState.getProgram();
4869 program->setUniformMatrix4fv(location, count, transpose, value);
4870}
4871
4872void Context::validateProgram(GLuint program)
4873{
4874 Program *programObject = getProgram(program);
4875 ASSERT(programObject);
4876 programObject->validate(mCaps);
4877}
4878
Jamie Madilld04908b2017-06-09 14:15:35 -04004879void Context::getProgramBinary(GLuint program,
4880 GLsizei bufSize,
4881 GLsizei *length,
4882 GLenum *binaryFormat,
4883 void *binary)
4884{
4885 Program *programObject = getProgram(program);
4886 ASSERT(programObject != nullptr);
4887
4888 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
4889}
4890
4891void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
4892{
4893 Program *programObject = getProgram(program);
4894 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04004895
Jamie Madilld04908b2017-06-09 14:15:35 -04004896 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
4897}
4898
Jamie Madillff325f12017-08-26 15:06:05 -04004899void Context::uniform1ui(GLint location, GLuint v0)
4900{
4901 Program *program = mGLState.getProgram();
4902 program->setUniform1uiv(location, 1, &v0);
4903}
4904
4905void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
4906{
4907 Program *program = mGLState.getProgram();
4908 const GLuint xy[] = {v0, v1};
4909 program->setUniform2uiv(location, 1, xy);
4910}
4911
4912void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
4913{
4914 Program *program = mGLState.getProgram();
4915 const GLuint xyz[] = {v0, v1, v2};
4916 program->setUniform3uiv(location, 1, xyz);
4917}
4918
4919void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
4920{
4921 Program *program = mGLState.getProgram();
4922 const GLuint xyzw[] = {v0, v1, v2, v3};
4923 program->setUniform4uiv(location, 1, xyzw);
4924}
4925
4926void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
4927{
4928 Program *program = mGLState.getProgram();
4929 program->setUniform1uiv(location, count, value);
4930}
4931void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
4932{
4933 Program *program = mGLState.getProgram();
4934 program->setUniform2uiv(location, count, value);
4935}
4936
4937void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
4938{
4939 Program *program = mGLState.getProgram();
4940 program->setUniform3uiv(location, count, value);
4941}
4942
4943void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
4944{
4945 Program *program = mGLState.getProgram();
4946 program->setUniform4uiv(location, count, value);
4947}
4948
Jamie Madillf0e04492017-08-26 15:28:42 -04004949void Context::genQueries(GLsizei n, GLuint *ids)
4950{
4951 for (GLsizei i = 0; i < n; i++)
4952 {
4953 GLuint handle = mQueryHandleAllocator.allocate();
4954 mQueryMap.assign(handle, nullptr);
4955 ids[i] = handle;
4956 }
4957}
4958
4959void Context::deleteQueries(GLsizei n, const GLuint *ids)
4960{
4961 for (int i = 0; i < n; i++)
4962 {
4963 GLuint query = ids[i];
4964
4965 Query *queryObject = nullptr;
4966 if (mQueryMap.erase(query, &queryObject))
4967 {
4968 mQueryHandleAllocator.release(query);
4969 if (queryObject)
4970 {
4971 queryObject->release(this);
4972 }
4973 }
4974 }
4975}
4976
4977GLboolean Context::isQuery(GLuint id)
4978{
4979 return (getQuery(id, false, GL_NONE) != nullptr) ? GL_TRUE : GL_FALSE;
4980}
4981
Jamie Madillc8c95812017-08-26 18:40:09 -04004982void Context::uniformMatrix2x3fv(GLint location,
4983 GLsizei count,
4984 GLboolean transpose,
4985 const GLfloat *value)
4986{
4987 Program *program = mGLState.getProgram();
4988 program->setUniformMatrix2x3fv(location, count, transpose, value);
4989}
4990
4991void Context::uniformMatrix3x2fv(GLint location,
4992 GLsizei count,
4993 GLboolean transpose,
4994 const GLfloat *value)
4995{
4996 Program *program = mGLState.getProgram();
4997 program->setUniformMatrix3x2fv(location, count, transpose, value);
4998}
4999
5000void Context::uniformMatrix2x4fv(GLint location,
5001 GLsizei count,
5002 GLboolean transpose,
5003 const GLfloat *value)
5004{
5005 Program *program = mGLState.getProgram();
5006 program->setUniformMatrix2x4fv(location, count, transpose, value);
5007}
5008
5009void Context::uniformMatrix4x2fv(GLint location,
5010 GLsizei count,
5011 GLboolean transpose,
5012 const GLfloat *value)
5013{
5014 Program *program = mGLState.getProgram();
5015 program->setUniformMatrix4x2fv(location, count, transpose, value);
5016}
5017
5018void Context::uniformMatrix3x4fv(GLint location,
5019 GLsizei count,
5020 GLboolean transpose,
5021 const GLfloat *value)
5022{
5023 Program *program = mGLState.getProgram();
5024 program->setUniformMatrix3x4fv(location, count, transpose, value);
5025}
5026
5027void Context::uniformMatrix4x3fv(GLint location,
5028 GLsizei count,
5029 GLboolean transpose,
5030 const GLfloat *value)
5031{
5032 Program *program = mGLState.getProgram();
5033 program->setUniformMatrix4x3fv(location, count, transpose, value);
5034}
5035
Jamie Madilld7576732017-08-26 18:49:50 -04005036void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
5037{
5038 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5039 {
5040 GLuint vertexArray = arrays[arrayIndex];
5041
5042 if (arrays[arrayIndex] != 0)
5043 {
5044 VertexArray *vertexArrayObject = nullptr;
5045 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
5046 {
5047 if (vertexArrayObject != nullptr)
5048 {
5049 detachVertexArray(vertexArray);
5050 vertexArrayObject->onDestroy(this);
5051 }
5052
5053 mVertexArrayHandleAllocator.release(vertexArray);
5054 }
5055 }
5056 }
5057}
5058
5059void Context::genVertexArrays(GLsizei n, GLuint *arrays)
5060{
5061 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5062 {
5063 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
5064 mVertexArrayMap.assign(vertexArray, nullptr);
5065 arrays[arrayIndex] = vertexArray;
5066 }
5067}
5068
5069bool Context::isVertexArray(GLuint array)
5070{
5071 if (array == 0)
5072 {
5073 return GL_FALSE;
5074 }
5075
5076 VertexArray *vao = getVertexArray(array);
5077 return (vao != nullptr ? GL_TRUE : GL_FALSE);
5078}
5079
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04005080void Context::endTransformFeedback()
5081{
5082 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5083 transformFeedback->end(this);
5084}
5085
5086void Context::transformFeedbackVaryings(GLuint program,
5087 GLsizei count,
5088 const GLchar *const *varyings,
5089 GLenum bufferMode)
5090{
5091 Program *programObject = getProgram(program);
5092 ASSERT(programObject);
5093 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
5094}
5095
5096void Context::getTransformFeedbackVarying(GLuint program,
5097 GLuint index,
5098 GLsizei bufSize,
5099 GLsizei *length,
5100 GLsizei *size,
5101 GLenum *type,
5102 GLchar *name)
5103{
5104 Program *programObject = getProgram(program);
5105 ASSERT(programObject);
5106 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
5107}
5108
5109void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
5110{
5111 for (int i = 0; i < n; i++)
5112 {
5113 GLuint transformFeedback = ids[i];
5114 if (transformFeedback == 0)
5115 {
5116 continue;
5117 }
5118
5119 TransformFeedback *transformFeedbackObject = nullptr;
5120 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
5121 {
5122 if (transformFeedbackObject != nullptr)
5123 {
5124 detachTransformFeedback(transformFeedback);
5125 transformFeedbackObject->release(this);
5126 }
5127
5128 mTransformFeedbackHandleAllocator.release(transformFeedback);
5129 }
5130 }
5131}
5132
5133void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
5134{
5135 for (int i = 0; i < n; i++)
5136 {
5137 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
5138 mTransformFeedbackMap.assign(transformFeedback, nullptr);
5139 ids[i] = transformFeedback;
5140 }
5141}
5142
5143bool Context::isTransformFeedback(GLuint id)
5144{
5145 if (id == 0)
5146 {
5147 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
5148 // returns FALSE
5149 return GL_FALSE;
5150 }
5151
5152 const TransformFeedback *transformFeedback = getTransformFeedback(id);
5153 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
5154}
5155
5156void Context::pauseTransformFeedback()
5157{
5158 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5159 transformFeedback->pause();
5160}
5161
5162void Context::resumeTransformFeedback()
5163{
5164 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5165 transformFeedback->resume();
5166}
5167
Jamie Madill12e957f2017-08-26 21:42:26 -04005168void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
5169{
5170 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04005171 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04005172}
5173
5174GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
5175{
5176 const Program *programObject = getProgram(program);
5177 return programObject->getFragDataLocation(name);
5178}
5179
5180void Context::getUniformIndices(GLuint program,
5181 GLsizei uniformCount,
5182 const GLchar *const *uniformNames,
5183 GLuint *uniformIndices)
5184{
5185 const Program *programObject = getProgram(program);
5186 if (!programObject->isLinked())
5187 {
5188 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5189 {
5190 uniformIndices[uniformId] = GL_INVALID_INDEX;
5191 }
5192 }
5193 else
5194 {
5195 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5196 {
5197 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
5198 }
5199 }
5200}
5201
5202void Context::getActiveUniformsiv(GLuint program,
5203 GLsizei uniformCount,
5204 const GLuint *uniformIndices,
5205 GLenum pname,
5206 GLint *params)
5207{
5208 const Program *programObject = getProgram(program);
5209 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5210 {
5211 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08005212 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04005213 }
5214}
5215
5216GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
5217{
5218 const Program *programObject = getProgram(program);
5219 return programObject->getUniformBlockIndex(uniformBlockName);
5220}
5221
5222void Context::getActiveUniformBlockiv(GLuint program,
5223 GLuint uniformBlockIndex,
5224 GLenum pname,
5225 GLint *params)
5226{
5227 const Program *programObject = getProgram(program);
5228 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
5229}
5230
5231void Context::getActiveUniformBlockName(GLuint program,
5232 GLuint uniformBlockIndex,
5233 GLsizei bufSize,
5234 GLsizei *length,
5235 GLchar *uniformBlockName)
5236{
5237 const Program *programObject = getProgram(program);
5238 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
5239}
5240
5241void Context::uniformBlockBinding(GLuint program,
5242 GLuint uniformBlockIndex,
5243 GLuint uniformBlockBinding)
5244{
5245 Program *programObject = getProgram(program);
5246 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
5247}
5248
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005249GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
5250{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005251 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
5252 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005253
Jamie Madill70b5bb02017-08-28 13:32:37 -04005254 Sync *syncObject = getSync(syncHandle);
5255 Error error = syncObject->set(condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005256 if (error.isError())
5257 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04005258 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005259 handleError(error);
5260 return nullptr;
5261 }
5262
Jamie Madill70b5bb02017-08-28 13:32:37 -04005263 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005264}
5265
5266GLboolean Context::isSync(GLsync sync)
5267{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005268 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005269}
5270
5271GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
5272{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005273 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005274
5275 GLenum result = GL_WAIT_FAILED;
5276 handleError(syncObject->clientWait(flags, timeout, &result));
5277 return result;
5278}
5279
5280void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
5281{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005282 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005283 handleError(syncObject->serverWait(flags, timeout));
5284}
5285
5286void Context::getInteger64v(GLenum pname, GLint64 *params)
5287{
5288 GLenum nativeType = GL_NONE;
5289 unsigned int numParams = 0;
5290 getQueryParameterInfo(pname, &nativeType, &numParams);
5291
5292 if (nativeType == GL_INT_64_ANGLEX)
5293 {
5294 getInteger64vImpl(pname, params);
5295 }
5296 else
5297 {
5298 CastStateValues(this, nativeType, pname, numParams, params);
5299 }
5300}
5301
Jamie Madill3ef140a2017-08-26 23:11:21 -04005302void Context::getBufferParameteri64v(GLenum target, GLenum pname, GLint64 *params)
5303{
5304 Buffer *buffer = mGLState.getTargetBuffer(target);
5305 QueryBufferParameteri64v(buffer, pname, params);
5306}
5307
5308void Context::genSamplers(GLsizei count, GLuint *samplers)
5309{
5310 for (int i = 0; i < count; i++)
5311 {
5312 samplers[i] = mState.mSamplers->createSampler();
5313 }
5314}
5315
5316void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
5317{
5318 for (int i = 0; i < count; i++)
5319 {
5320 GLuint sampler = samplers[i];
5321
5322 if (mState.mSamplers->getSampler(sampler))
5323 {
5324 detachSampler(sampler);
5325 }
5326
5327 mState.mSamplers->deleteObject(this, sampler);
5328 }
5329}
5330
5331void Context::getInternalformativ(GLenum target,
5332 GLenum internalformat,
5333 GLenum pname,
5334 GLsizei bufSize,
5335 GLint *params)
5336{
5337 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
5338 QueryInternalFormativ(formatCaps, pname, bufSize, params);
5339}
5340
Jamie Madill81c2e252017-09-09 23:32:46 -04005341void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5342{
5343 Program *programObject = getProgram(program);
5344 ASSERT(programObject);
5345 if (programObject->setUniform1iv(location, count, value) ==
5346 Program::SetUniformResult::SamplerChanged)
5347 {
5348 mGLState.setObjectDirty(GL_PROGRAM);
5349 }
5350}
5351
5352void Context::onTextureChange(const Texture *texture)
5353{
5354 // Conservatively assume all textures are dirty.
5355 // TODO(jmadill): More fine-grained update.
5356 mGLState.setObjectDirty(GL_TEXTURE);
5357}
5358
Yunchao Hea336b902017-08-02 16:05:21 +08005359void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
5360{
5361 for (int i = 0; i < count; i++)
5362 {
5363 pipelines[i] = createProgramPipeline();
5364 }
5365}
5366
5367void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
5368{
5369 for (int i = 0; i < count; i++)
5370 {
5371 if (pipelines[i] != 0)
5372 {
5373 deleteProgramPipeline(pipelines[i]);
5374 }
5375 }
5376}
5377
5378GLboolean Context::isProgramPipeline(GLuint pipeline)
5379{
5380 if (pipeline == 0)
5381 {
5382 return GL_FALSE;
5383 }
5384
5385 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
5386}
5387
Jamie Madillc29968b2016-01-20 11:17:23 -05005388} // namespace gl