blob: eef856447af661391b59bd3ca621e690a86fc280 [file] [log] [blame]
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001//
Geoff Langeeba6e12014-02-03 13:12:30 -05002// Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7// Context.cpp: Implements the gl::Context class, managing all GL state and performing
8// rendering operations. It is the GLES2 specific implementation of EGLContext.
9
Geoff Lang2b5420c2014-11-19 14:20:15 -050010#include "libANGLE/Context.h"
apatrick@chromium.org144f2802012-07-12 01:42:34 +000011
Jamie Madill231c7f52017-04-26 13:45:37 -040012#include <string.h>
Jamie Madillb9293972015-02-19 11:07:54 -050013#include <iterator>
14#include <sstream>
Sami Väisänend59ca052016-06-21 16:10:00 +030015#include <vector>
Jamie Madillb9293972015-02-19 11:07:54 -050016
Sami Väisänene45e53b2016-05-25 10:36:04 +030017#include "common/matrix_utils.h"
Geoff Lang0b7eef72014-06-12 14:10:47 -040018#include "common/platform.h"
Jamie Madillb9293972015-02-19 11:07:54 -050019#include "common/utilities.h"
Geoff Langc339c4e2016-11-29 10:37:36 -050020#include "common/version.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050021#include "libANGLE/Buffer.h"
Jamie Madillb9293972015-02-19 11:07:54 -050022#include "libANGLE/Compiler.h"
Jamie Madill948bbe52017-06-01 13:10:42 -040023#include "libANGLE/Display.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050024#include "libANGLE/Fence.h"
25#include "libANGLE/Framebuffer.h"
26#include "libANGLE/FramebufferAttachment.h"
Sami Väisänene45e53b2016-05-25 10:36:04 +030027#include "libANGLE/Path.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050028#include "libANGLE/Program.h"
Yunchao Hea336b902017-08-02 16:05:21 +080029#include "libANGLE/ProgramPipeline.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050030#include "libANGLE/Query.h"
Jamie Madillb9293972015-02-19 11:07:54 -050031#include "libANGLE/Renderbuffer.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050032#include "libANGLE/ResourceManager.h"
33#include "libANGLE/Sampler.h"
Jamie Madill9dd0cf02014-11-24 11:38:51 -050034#include "libANGLE/Surface.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050035#include "libANGLE/Texture.h"
36#include "libANGLE/TransformFeedback.h"
37#include "libANGLE/VertexArray.h"
Kenneth Russellf2f6f652016-10-05 19:53:23 -070038#include "libANGLE/Workarounds.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040039#include "libANGLE/formatutils.h"
Martin Radev66fb8202016-07-28 11:45:20 +030040#include "libANGLE/queryconversions.h"
Geoff Langc1984ed2016-10-07 12:41:00 -040041#include "libANGLE/queryutils.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040042#include "libANGLE/renderer/ContextImpl.h"
43#include "libANGLE/renderer/EGLImplFactory.h"
Jamie Madill7b62cf92017-11-02 15:20:49 -040044#include "libANGLE/renderer/Format.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040045#include "libANGLE/validationES.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000046
Geoff Langf6db0982015-08-25 13:04:00 -040047namespace
48{
49
Jamie Madillb6664922017-07-25 12:55:04 -040050#define ANGLE_HANDLE_ERR(X) \
51 handleError(X); \
52 return;
53#define ANGLE_CONTEXT_TRY(EXPR) ANGLE_TRY_TEMPLATE(EXPR, ANGLE_HANDLE_ERR);
54
Ian Ewell3ffd78b2016-01-22 16:09:42 -050055template <typename T>
Geoff Lang4ddf5af2016-12-01 14:30:44 -050056std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager,
Sami Väisänend59ca052016-06-21 16:10:00 +030057 GLsizei numPaths,
58 const void *paths,
59 GLuint pathBase)
60{
61 std::vector<gl::Path *> ret;
62 ret.reserve(numPaths);
63
64 const auto *nameArray = static_cast<const T *>(paths);
65
66 for (GLsizei i = 0; i < numPaths; ++i)
67 {
68 const GLuint pathName = nameArray[i] + pathBase;
69
70 ret.push_back(resourceManager.getPath(pathName));
71 }
72
73 return ret;
74}
75
Geoff Lang4ddf5af2016-12-01 14:30:44 -050076std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager,
Sami Väisänend59ca052016-06-21 16:10:00 +030077 GLsizei numPaths,
78 GLenum pathNameType,
79 const void *paths,
80 GLuint pathBase)
81{
82 switch (pathNameType)
83 {
84 case GL_UNSIGNED_BYTE:
85 return GatherPaths<GLubyte>(resourceManager, numPaths, paths, pathBase);
86
87 case GL_BYTE:
88 return GatherPaths<GLbyte>(resourceManager, numPaths, paths, pathBase);
89
90 case GL_UNSIGNED_SHORT:
91 return GatherPaths<GLushort>(resourceManager, numPaths, paths, pathBase);
92
93 case GL_SHORT:
94 return GatherPaths<GLshort>(resourceManager, numPaths, paths, pathBase);
95
96 case GL_UNSIGNED_INT:
97 return GatherPaths<GLuint>(resourceManager, numPaths, paths, pathBase);
98
99 case GL_INT:
100 return GatherPaths<GLint>(resourceManager, numPaths, paths, pathBase);
101 }
102
103 UNREACHABLE();
104 return std::vector<gl::Path *>();
105}
106
107template <typename T>
Geoff Lang2186c382016-10-14 10:54:54 -0400108gl::Error GetQueryObjectParameter(gl::Query *query, GLenum pname, T *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500109{
Geoff Lang2186c382016-10-14 10:54:54 -0400110 ASSERT(query != nullptr);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500111
112 switch (pname)
113 {
114 case GL_QUERY_RESULT_EXT:
Geoff Lang2186c382016-10-14 10:54:54 -0400115 return query->getResult(params);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500116 case GL_QUERY_RESULT_AVAILABLE_EXT:
117 {
118 bool available;
Geoff Lang2186c382016-10-14 10:54:54 -0400119 gl::Error error = query->isResultAvailable(&available);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500120 if (!error.isError())
121 {
jchen10a99ed552017-09-22 08:10:32 +0800122 *params = gl::CastFromStateValue<T>(pname, static_cast<GLuint>(available));
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500123 }
124 return error;
125 }
126 default:
127 UNREACHABLE();
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500128 return gl::InternalError() << "Unreachable Error";
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500129 }
130}
131
Geoff Langf6db0982015-08-25 13:04:00 -0400132void MarkTransformFeedbackBufferUsage(gl::TransformFeedback *transformFeedback)
133{
Geoff Lang1a683462015-09-29 15:09:59 -0400134 if (transformFeedback && transformFeedback->isActive() && !transformFeedback->isPaused())
Geoff Langf6db0982015-08-25 13:04:00 -0400135 {
136 for (size_t tfBufferIndex = 0; tfBufferIndex < transformFeedback->getIndexedBufferCount();
137 tfBufferIndex++)
138 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400139 const gl::OffsetBindingPointer<gl::Buffer> &buffer =
Geoff Langf6db0982015-08-25 13:04:00 -0400140 transformFeedback->getIndexedBuffer(tfBufferIndex);
141 if (buffer.get() != nullptr)
142 {
143 buffer->onTransformFeedback();
144 }
145 }
146 }
147}
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500148
149// Attribute map queries.
Martin Radev1be913c2016-07-11 17:59:16 +0300150EGLint GetClientMajorVersion(const egl::AttributeMap &attribs)
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500151{
Ian Ewellec2c0c52016-04-05 13:46:26 -0400152 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_CLIENT_VERSION, 1));
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500153}
154
Martin Radev1be913c2016-07-11 17:59:16 +0300155EGLint GetClientMinorVersion(const egl::AttributeMap &attribs)
156{
157 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_MINOR_VERSION, 0));
158}
159
Geoff Langeb66a6e2016-10-31 13:06:12 -0400160gl::Version GetClientVersion(const egl::AttributeMap &attribs)
161{
162 return gl::Version(GetClientMajorVersion(attribs), GetClientMinorVersion(attribs));
163}
164
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500165GLenum GetResetStrategy(const egl::AttributeMap &attribs)
166{
Ian Ewellec2c0c52016-04-05 13:46:26 -0400167 EGLAttrib attrib = attribs.get(EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT,
168 EGL_NO_RESET_NOTIFICATION_EXT);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500169 switch (attrib)
170 {
171 case EGL_NO_RESET_NOTIFICATION:
172 return GL_NO_RESET_NOTIFICATION_EXT;
173 case EGL_LOSE_CONTEXT_ON_RESET:
174 return GL_LOSE_CONTEXT_ON_RESET_EXT;
175 default:
176 UNREACHABLE();
177 return GL_NONE;
178 }
179}
180
181bool GetRobustAccess(const egl::AttributeMap &attribs)
182{
Geoff Lang077f20a2016-11-01 10:08:02 -0400183 return (attribs.get(EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT, EGL_FALSE) == EGL_TRUE) ||
184 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR) !=
185 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500186}
187
188bool GetDebug(const egl::AttributeMap &attribs)
189{
Geoff Lang077f20a2016-11-01 10:08:02 -0400190 return (attribs.get(EGL_CONTEXT_OPENGL_DEBUG, EGL_FALSE) == EGL_TRUE) ||
191 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR) != 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500192}
193
194bool GetNoError(const egl::AttributeMap &attribs)
195{
196 return (attribs.get(EGL_CONTEXT_OPENGL_NO_ERROR_KHR, EGL_FALSE) == EGL_TRUE);
197}
198
Geoff Langc287ea62016-09-16 14:46:51 -0400199bool GetWebGLContext(const egl::AttributeMap &attribs)
200{
201 return (attribs.get(EGL_CONTEXT_WEBGL_COMPATIBILITY_ANGLE, EGL_FALSE) == EGL_TRUE);
202}
203
Geoff Langf41a7152016-09-19 15:11:17 -0400204bool GetBindGeneratesResource(const egl::AttributeMap &attribs)
205{
206 return (attribs.get(EGL_CONTEXT_BIND_GENERATES_RESOURCE_CHROMIUM, EGL_TRUE) == EGL_TRUE);
207}
208
Geoff Langfeb8c682017-02-13 16:07:35 -0500209bool GetClientArraysEnabled(const egl::AttributeMap &attribs)
210{
211 return (attribs.get(EGL_CONTEXT_CLIENT_ARRAYS_ENABLED_ANGLE, EGL_TRUE) == EGL_TRUE);
212}
213
Geoff Langb433e872017-10-05 14:01:47 -0400214bool GetRobustResourceInit(const egl::AttributeMap &attribs)
215{
216 return (attribs.get(EGL_ROBUST_RESOURCE_INITIALIZATION_ANGLE, EGL_FALSE) == EGL_TRUE);
217}
218
Martin Radev9d901792016-07-15 15:58:58 +0300219std::string GetObjectLabelFromPointer(GLsizei length, const GLchar *label)
220{
221 std::string labelName;
222 if (label != nullptr)
223 {
224 size_t labelLength = length < 0 ? strlen(label) : length;
225 labelName = std::string(label, labelLength);
226 }
227 return labelName;
228}
229
230void GetObjectLabelBase(const std::string &objectLabel,
231 GLsizei bufSize,
232 GLsizei *length,
233 GLchar *label)
234{
235 size_t writeLength = objectLabel.length();
236 if (label != nullptr && bufSize > 0)
237 {
238 writeLength = std::min(static_cast<size_t>(bufSize) - 1, objectLabel.length());
239 std::copy(objectLabel.begin(), objectLabel.begin() + writeLength, label);
240 label[writeLength] = '\0';
241 }
242
243 if (length != nullptr)
244 {
245 *length = static_cast<GLsizei>(writeLength);
246 }
247}
248
Jamie Madill0f80ed82017-09-19 00:24:56 -0400249template <typename CapT, typename MaxT>
250void LimitCap(CapT *cap, MaxT maximum)
251{
252 *cap = std::min(*cap, static_cast<CapT>(maximum));
253}
254
Geoff Langf6db0982015-08-25 13:04:00 -0400255} // anonymous namespace
256
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000257namespace gl
258{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +0000259
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400260Context::Context(rx::EGLImplFactory *implFactory,
261 const egl::Config *config,
Corentin Wallez51706ea2015-08-07 14:39:22 -0400262 const Context *shareContext,
Geoff Langce02f082017-02-06 16:46:21 -0500263 TextureManager *shareTextures,
Jamie Madill32447362017-06-28 14:53:52 -0400264 MemoryProgramCache *memoryProgramCache,
Corentin Wallezc295e512017-01-27 17:47:50 -0500265 const egl::AttributeMap &attribs,
Geoff Langb433e872017-10-05 14:01:47 -0400266 const egl::DisplayExtensions &displayExtensions)
Martin Radev1be913c2016-07-11 17:59:16 +0300267
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500268 : ValidationContext(shareContext,
Geoff Langce02f082017-02-06 16:46:21 -0500269 shareTextures,
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500270 GetClientVersion(attribs),
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700271 &mGLState,
Jamie Madillf25855c2015-11-03 11:06:18 -0500272 mCaps,
273 mTextureCaps,
274 mExtensions,
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500275 mLimitations,
276 GetNoError(attribs)),
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700277 mImplementation(implFactory->createContext(mState)),
Jamie Madill2f348d22017-06-05 10:50:59 -0400278 mCompiler(),
Corentin Walleze3b10e82015-05-20 11:06:25 -0400279 mConfig(config),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500280 mClientType(EGL_OPENGL_ES_API),
281 mHasBeenCurrent(false),
282 mContextLost(false),
283 mResetStatus(GL_NO_ERROR),
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700284 mContextLostForced(false),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500285 mResetStrategy(GetResetStrategy(attribs)),
286 mRobustAccess(GetRobustAccess(attribs)),
Jamie Madill61e16b42017-06-19 11:13:23 -0400287 mCurrentSurface(static_cast<egl::Surface *>(EGL_NO_SURFACE)),
288 mCurrentDisplay(static_cast<egl::Display *>(EGL_NO_DISPLAY)),
Jamie Madill4e0e6f82017-02-17 11:06:03 -0500289 mSurfacelessFramebuffer(nullptr),
Jamie Madille14951e2017-03-09 18:55:16 -0500290 mWebGLContext(GetWebGLContext(attribs)),
Jamie Madill32447362017-06-28 14:53:52 -0400291 mMemoryProgramCache(memoryProgramCache),
Jamie Madillb3f26b92017-07-19 15:07:41 -0400292 mScratchBuffer(1000u),
293 mZeroFilledBuffer(1000u)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000294{
Jamie Madill14bbb3f2017-09-12 15:23:01 -0400295 mImplementation->setMemoryProgramCache(memoryProgramCache);
296
Geoff Langb433e872017-10-05 14:01:47 -0400297 bool robustResourceInit = GetRobustResourceInit(attribs);
298 initCaps(displayExtensions, robustResourceInit);
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700299 initWorkarounds();
Geoff Langc0b9ef42014-07-02 10:02:37 -0400300
Jamie Madill4928b7c2017-06-20 12:57:39 -0400301 mGLState.initialize(this, GetDebug(attribs), GetBindGeneratesResource(attribs),
Jamie Madillc43be722017-07-13 16:22:14 -0400302 GetClientArraysEnabled(attribs), robustResourceInit,
303 mMemoryProgramCache != nullptr);
Régis Fénéon83107972015-02-05 12:57:44 +0100304
Shannon Woods53a94a82014-06-24 15:20:36 -0400305 mFenceNVHandleAllocator.setBaseHandle(0);
Geoff Lang7dca1862013-07-30 16:30:46 -0400306
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000307 // [OpenGL ES 2.0.24] section 3.7 page 83:
308 // In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have twodimensional
309 // and cube map texture state vectors respectively associated with them.
310 // In order that access to these initial textures not be lost, they are treated as texture
311 // objects all of whose names are 0.
312
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400313 Texture *zeroTexture2D = new Texture(mImplementation.get(), 0, GL_TEXTURE_2D);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400314 mZeroTextures[GL_TEXTURE_2D].set(this, zeroTexture2D);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500315
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400316 Texture *zeroTextureCube = new Texture(mImplementation.get(), 0, GL_TEXTURE_CUBE_MAP);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400317 mZeroTextures[GL_TEXTURE_CUBE_MAP].set(this, zeroTextureCube);
Geoff Lang76b10c92014-09-05 16:28:14 -0400318
Geoff Langeb66a6e2016-10-31 13:06:12 -0400319 if (getClientVersion() >= Version(3, 0))
Geoff Lang76b10c92014-09-05 16:28:14 -0400320 {
321 // TODO: These could also be enabled via extension
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400322 Texture *zeroTexture3D = new Texture(mImplementation.get(), 0, GL_TEXTURE_3D);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400323 mZeroTextures[GL_TEXTURE_3D].set(this, zeroTexture3D);
Geoff Lang76b10c92014-09-05 16:28:14 -0400324
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400325 Texture *zeroTexture2DArray = new Texture(mImplementation.get(), 0, GL_TEXTURE_2D_ARRAY);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400326 mZeroTextures[GL_TEXTURE_2D_ARRAY].set(this, zeroTexture2DArray);
Geoff Lang76b10c92014-09-05 16:28:14 -0400327 }
Geoff Lang3b573612016-10-31 14:08:10 -0400328 if (getClientVersion() >= Version(3, 1))
329 {
330 Texture *zeroTexture2DMultisample =
331 new Texture(mImplementation.get(), 0, GL_TEXTURE_2D_MULTISAMPLE);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400332 mZeroTextures[GL_TEXTURE_2D_MULTISAMPLE].set(this, zeroTexture2DMultisample);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800333
334 bindGenericAtomicCounterBuffer(0);
335 for (unsigned int i = 0; i < mCaps.maxAtomicCounterBufferBindings; i++)
336 {
337 bindIndexedAtomicCounterBuffer(0, i, 0, 0);
338 }
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800339
340 bindGenericShaderStorageBuffer(0);
341 for (unsigned int i = 0; i < mCaps.maxShaderStorageBufferBindings; i++)
342 {
343 bindIndexedShaderStorageBuffer(0, i, 0, 0);
344 }
Geoff Lang3b573612016-10-31 14:08:10 -0400345 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000346
Geoff Lang4751aab2017-10-30 15:14:52 -0400347 const Extensions &nativeExtensions = mImplementation->getNativeExtensions();
348 if (nativeExtensions.textureRectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400349 {
350 Texture *zeroTextureRectangle =
351 new Texture(mImplementation.get(), 0, GL_TEXTURE_RECTANGLE_ANGLE);
352 mZeroTextures[GL_TEXTURE_RECTANGLE_ANGLE].set(this, zeroTextureRectangle);
353 }
354
Geoff Lang4751aab2017-10-30 15:14:52 -0400355 if (nativeExtensions.eglImageExternal || nativeExtensions.eglStreamConsumerExternal)
Ian Ewellbda75592016-04-18 17:25:54 -0400356 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400357 Texture *zeroTextureExternal =
358 new Texture(mImplementation.get(), 0, GL_TEXTURE_EXTERNAL_OES);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400359 mZeroTextures[GL_TEXTURE_EXTERNAL_OES].set(this, zeroTextureExternal);
Ian Ewellbda75592016-04-18 17:25:54 -0400360 }
361
Jamie Madill4928b7c2017-06-20 12:57:39 -0400362 mGLState.initializeZeroTextures(this, mZeroTextures);
Jamie Madille6382c32014-11-07 15:05:26 -0500363
Jamie Madill57a89722013-07-02 11:57:03 -0400364 bindVertexArray(0);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000365 bindArrayBuffer(0);
Jiajia Qin9d7d0b12016-11-29 16:30:31 +0800366 bindDrawIndirectBuffer(0);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000367 bindElementArrayBuffer(0);
Geoff Lang76b10c92014-09-05 16:28:14 -0400368
Jamie Madill01a80ee2016-11-07 12:06:18 -0500369 bindRenderbuffer(GL_RENDERBUFFER, 0);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000370
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +0000371 bindGenericUniformBuffer(0);
Geoff Lang4dc3af02016-11-18 14:09:27 -0500372 for (unsigned int i = 0; i < mCaps.maxUniformBufferBindings; i++)
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +0000373 {
374 bindIndexedUniformBuffer(0, i, 0, -1);
375 }
376
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000377 bindCopyReadBuffer(0);
378 bindCopyWriteBuffer(0);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +0000379 bindPixelPackBuffer(0);
380 bindPixelUnpackBuffer(0);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000381
Geoff Langeb66a6e2016-10-31 13:06:12 -0400382 if (getClientVersion() >= Version(3, 0))
Geoff Lang1a683462015-09-29 15:09:59 -0400383 {
384 // [OpenGL ES 3.0.2] section 2.14.1 pg 85:
385 // In the initial state, a default transform feedback object is bound and treated as
386 // a transform feedback object with a name of zero. That object is bound any time
387 // BindTransformFeedback is called with id of zero
Jamie Madillf0dcb8b2017-08-26 19:05:13 -0400388 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Geoff Lang1a683462015-09-29 15:09:59 -0400389 }
Geoff Langc8058452014-02-03 12:04:11 -0500390
Jamie Madillad9f24e2016-02-12 09:27:24 -0500391 // Initialize dirty bit masks
Jamie Madillc67323a2017-11-02 23:11:41 -0400392 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_STATE);
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
2156 if (!error.getMessage().empty())
2157 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002158 auto *debug = &mGLState.getDebug();
2159 debug->insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, error.getID(),
2160 GL_DEBUG_SEVERITY_HIGH, error.getMessage());
Geoff Lang70d0f492015-12-10 17:45:46 -05002161 }
Geoff Langda5777c2014-07-11 09:52:58 -04002162 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002163}
2164
2165// Get one of the recorded errors and clear its flag, if any.
2166// [OpenGL ES 2.0.24] section 2.5 page 13.
2167GLenum Context::getError()
2168{
Geoff Langda5777c2014-07-11 09:52:58 -04002169 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002170 {
Geoff Langda5777c2014-07-11 09:52:58 -04002171 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002172 }
Geoff Langda5777c2014-07-11 09:52:58 -04002173 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002174 {
Geoff Langda5777c2014-07-11 09:52:58 -04002175 GLenum error = *mErrors.begin();
2176 mErrors.erase(mErrors.begin());
2177 return error;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002178 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002179}
2180
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002181// NOTE: this function should not assume that this context is current!
2182void Context::markContextLost()
2183{
2184 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002185 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002186 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002187 mContextLostForced = true;
2188 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002189 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002190}
2191
2192bool Context::isContextLost()
2193{
2194 return mContextLost;
2195}
2196
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002197GLenum Context::getResetStatus()
2198{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002199 // Even if the application doesn't want to know about resets, we want to know
2200 // as it will allow us to skip all the calls.
2201 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002202 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002203 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002204 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002205 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002206 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002207
2208 // EXT_robustness, section 2.6: If the reset notification behavior is
2209 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2210 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2211 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002212 }
2213
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002214 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2215 // status should be returned at least once, and GL_NO_ERROR should be returned
2216 // once the device has finished resetting.
2217 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002218 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002219 ASSERT(mResetStatus == GL_NO_ERROR);
2220 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002221
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002222 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002223 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002224 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002225 }
2226 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002227 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002228 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002229 // If markContextLost was used to mark the context lost then
2230 // assume that is not recoverable, and continue to report the
2231 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002232 mResetStatus = mImplementation->getResetStatus();
2233 }
Jamie Madill893ab082014-05-16 16:56:10 -04002234
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002235 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002236}
2237
2238bool Context::isResetNotificationEnabled()
2239{
2240 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2241}
2242
Corentin Walleze3b10e82015-05-20 11:06:25 -04002243const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002244{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002245 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002246}
2247
2248EGLenum Context::getClientType() const
2249{
2250 return mClientType;
2251}
2252
2253EGLenum Context::getRenderBuffer() const
2254{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002255 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2256 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002257 {
2258 return EGL_NONE;
2259 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002260
2261 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(GL_BACK);
2262 ASSERT(backAttachment != nullptr);
2263 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002264}
2265
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002266VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002267{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002268 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002269 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2270 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002271 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002272 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2273 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002274
Jamie Madill96a483b2017-06-27 16:49:21 -04002275 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002276 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002277
2278 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002279}
2280
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002281TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002282{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002283 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002284 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2285 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002286 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002287 transformFeedback =
2288 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002289 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002290 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002291 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002292
2293 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002294}
2295
2296bool Context::isVertexArrayGenerated(GLuint vertexArray)
2297{
Jamie Madill96a483b2017-06-27 16:49:21 -04002298 ASSERT(mVertexArrayMap.contains(0));
2299 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002300}
2301
2302bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2303{
Jamie Madill96a483b2017-06-27 16:49:21 -04002304 ASSERT(mTransformFeedbackMap.contains(0));
2305 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002306}
2307
Shannon Woods53a94a82014-06-24 15:20:36 -04002308void Context::detachTexture(GLuint texture)
2309{
2310 // Simple pass-through to State's detachTexture method, as textures do not require
2311 // allocation map management either here or in the resource manager at detach time.
2312 // Zero textures are held by the Context, and we don't attempt to request them from
2313 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002314 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002315}
2316
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002317void Context::detachBuffer(GLuint buffer)
2318{
Yuly Novikov5807a532015-12-03 13:01:22 -05002319 // Simple pass-through to State's detachBuffer method, since
2320 // only buffer attachments to container objects that are bound to the current context
2321 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002322
Yuly Novikov5807a532015-12-03 13:01:22 -05002323 // [OpenGL ES 3.2] section 5.1.2 page 45:
2324 // Attachments to unbound container objects, such as
2325 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2326 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002327 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002328}
2329
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002330void Context::detachFramebuffer(GLuint framebuffer)
2331{
Shannon Woods53a94a82014-06-24 15:20:36 -04002332 // Framebuffer detachment is handled by Context, because 0 is a valid
2333 // Framebuffer object, and a pointer to it must be passed from Context
2334 // to State at binding time.
2335
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002336 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002337 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2338 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2339 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002340
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002341 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002342 {
2343 bindReadFramebuffer(0);
2344 }
2345
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002346 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002347 {
2348 bindDrawFramebuffer(0);
2349 }
2350}
2351
2352void Context::detachRenderbuffer(GLuint renderbuffer)
2353{
Jamie Madilla02315b2017-02-23 14:14:47 -05002354 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002355}
2356
Jamie Madill57a89722013-07-02 11:57:03 -04002357void Context::detachVertexArray(GLuint vertexArray)
2358{
Jamie Madill77a72f62015-04-14 11:18:32 -04002359 // Vertex array detachment is handled by Context, because 0 is a valid
2360 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002361 // binding time.
2362
Jamie Madill57a89722013-07-02 11:57:03 -04002363 // [OpenGL ES 3.0.2] section 2.10 page 43:
2364 // If a vertex array object that is currently bound is deleted, the binding
2365 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002366 if (mGLState.removeVertexArrayBinding(vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002367 {
2368 bindVertexArray(0);
2369 }
2370}
2371
Geoff Langc8058452014-02-03 12:04:11 -05002372void Context::detachTransformFeedback(GLuint transformFeedback)
2373{
Corentin Walleza2257da2016-04-19 16:43:12 -04002374 // Transform feedback detachment is handled by Context, because 0 is a valid
2375 // transform feedback, and a pointer to it must be passed from Context to State at
2376 // binding time.
2377
2378 // The OpenGL specification doesn't mention what should happen when the currently bound
2379 // transform feedback object is deleted. Since it is a container object, we treat it like
2380 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002381 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002382 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002383 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002384 }
Geoff Langc8058452014-02-03 12:04:11 -05002385}
2386
Jamie Madilldc356042013-07-19 16:36:57 -04002387void Context::detachSampler(GLuint sampler)
2388{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002389 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002390}
2391
Yunchao Hea336b902017-08-02 16:05:21 +08002392void Context::detachProgramPipeline(GLuint pipeline)
2393{
2394 mGLState.detachProgramPipeline(this, pipeline);
2395}
2396
Jamie Madill3ef140a2017-08-26 23:11:21 -04002397void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002398{
Shaodde78e82017-05-22 14:13:27 +08002399 mGLState.setVertexAttribDivisor(this, index, divisor);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002400}
2401
Jamie Madille29d1672013-07-19 16:36:57 -04002402void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2403{
Geoff Langc1984ed2016-10-07 12:41:00 -04002404 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002405 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002406 SetSamplerParameteri(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002407 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002408}
Jamie Madille29d1672013-07-19 16:36:57 -04002409
Geoff Langc1984ed2016-10-07 12:41:00 -04002410void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2411{
2412 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002413 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002414 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002415 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002416}
2417
2418void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2419{
Geoff Langc1984ed2016-10-07 12:41:00 -04002420 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002421 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002422 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002423 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002424}
2425
Geoff Langc1984ed2016-10-07 12:41:00 -04002426void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002427{
Geoff Langc1984ed2016-10-07 12:41:00 -04002428 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002429 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002430 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002431 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002432}
2433
Geoff Langc1984ed2016-10-07 12:41:00 -04002434void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002435{
Geoff Langc1984ed2016-10-07 12:41:00 -04002436 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002437 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002438 QuerySamplerParameteriv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002439 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002440}
Jamie Madill9675b802013-07-19 16:36:59 -04002441
Geoff Langc1984ed2016-10-07 12:41:00 -04002442void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2443{
2444 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002445 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002446 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002447 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002448}
2449
Olli Etuahof0fee072016-03-30 15:11:58 +03002450void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2451{
2452 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002453 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002454}
2455
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002456void Context::initRendererString()
2457{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002458 std::ostringstream rendererString;
2459 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002460 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002461 rendererString << ")";
2462
Geoff Langcec35902014-04-16 10:52:36 -04002463 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002464}
2465
Geoff Langc339c4e2016-11-29 10:37:36 -05002466void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002467{
Geoff Langc339c4e2016-11-29 10:37:36 -05002468 const Version &clientVersion = getClientVersion();
2469
2470 std::ostringstream versionString;
2471 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2472 << ANGLE_VERSION_STRING << ")";
2473 mVersionString = MakeStaticString(versionString.str());
2474
2475 std::ostringstream shadingLanguageVersionString;
2476 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2477 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2478 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2479 << ")";
2480 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002481}
2482
Geoff Langcec35902014-04-16 10:52:36 -04002483void Context::initExtensionStrings()
2484{
Geoff Langc339c4e2016-11-29 10:37:36 -05002485 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2486 std::ostringstream combinedStringStream;
2487 std::copy(strings.begin(), strings.end(),
2488 std::ostream_iterator<const char *>(combinedStringStream, " "));
2489 return MakeStaticString(combinedStringStream.str());
2490 };
2491
2492 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002493 for (const auto &extensionString : mExtensions.getStrings())
2494 {
2495 mExtensionStrings.push_back(MakeStaticString(extensionString));
2496 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002497 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002498
Bryan Bernhart58806562017-01-05 13:09:31 -08002499 const gl::Extensions &nativeExtensions = mImplementation->getNativeExtensions();
2500
Geoff Langc339c4e2016-11-29 10:37:36 -05002501 mRequestableExtensionStrings.clear();
2502 for (const auto &extensionInfo : GetExtensionInfoMap())
2503 {
2504 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08002505 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
2506 nativeExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002507 {
2508 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
2509 }
2510 }
2511 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002512}
2513
Geoff Langc339c4e2016-11-29 10:37:36 -05002514const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04002515{
Geoff Langc339c4e2016-11-29 10:37:36 -05002516 switch (name)
2517 {
2518 case GL_VENDOR:
2519 return reinterpret_cast<const GLubyte *>("Google Inc.");
2520
2521 case GL_RENDERER:
2522 return reinterpret_cast<const GLubyte *>(mRendererString);
2523
2524 case GL_VERSION:
2525 return reinterpret_cast<const GLubyte *>(mVersionString);
2526
2527 case GL_SHADING_LANGUAGE_VERSION:
2528 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
2529
2530 case GL_EXTENSIONS:
2531 return reinterpret_cast<const GLubyte *>(mExtensionString);
2532
2533 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2534 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
2535
2536 default:
2537 UNREACHABLE();
2538 return nullptr;
2539 }
Geoff Langcec35902014-04-16 10:52:36 -04002540}
2541
Geoff Langc339c4e2016-11-29 10:37:36 -05002542const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04002543{
Geoff Langc339c4e2016-11-29 10:37:36 -05002544 switch (name)
2545 {
2546 case GL_EXTENSIONS:
2547 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
2548
2549 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2550 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
2551
2552 default:
2553 UNREACHABLE();
2554 return nullptr;
2555 }
Geoff Langcec35902014-04-16 10:52:36 -04002556}
2557
2558size_t Context::getExtensionStringCount() const
2559{
2560 return mExtensionStrings.size();
2561}
2562
Geoff Lang111a99e2017-10-17 10:58:41 -04002563bool Context::isExtensionRequestable(const char *name)
2564{
2565 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2566 auto extension = extensionInfos.find(name);
2567
2568 const Extensions &nativeExtensions = mImplementation->getNativeExtensions();
2569 return extension != extensionInfos.end() && extension->second.Requestable &&
2570 nativeExtensions.*(extension->second.ExtensionsMember);
2571}
2572
Geoff Langc339c4e2016-11-29 10:37:36 -05002573void Context::requestExtension(const char *name)
2574{
2575 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2576 ASSERT(extensionInfos.find(name) != extensionInfos.end());
2577 const auto &extension = extensionInfos.at(name);
2578 ASSERT(extension.Requestable);
Geoff Lang111a99e2017-10-17 10:58:41 -04002579 ASSERT(mImplementation->getNativeExtensions().*(extension.ExtensionsMember));
Geoff Langc339c4e2016-11-29 10:37:36 -05002580
2581 if (mExtensions.*(extension.ExtensionsMember))
2582 {
2583 // Extension already enabled
2584 return;
2585 }
2586
2587 mExtensions.*(extension.ExtensionsMember) = true;
2588 updateCaps();
2589 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08002590
Jamie Madill2f348d22017-06-05 10:50:59 -04002591 // Release the shader compiler so it will be re-created with the requested extensions enabled.
2592 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04002593
Jamie Madill81c2e252017-09-09 23:32:46 -04002594 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
2595 // sampleable.
2596 mState.mTextures->signalAllTexturesDirty();
Geoff Lang9aded172017-04-05 11:07:56 -04002597 for (auto &zeroTexture : mZeroTextures)
2598 {
Jamie Madill05b35b22017-10-03 09:01:44 -04002599 zeroTexture.second->signalDirty(InitState::Initialized);
Geoff Lang9aded172017-04-05 11:07:56 -04002600 }
2601
2602 mState.mFramebuffers->invalidateFramebufferComplenessCache();
Geoff Langc339c4e2016-11-29 10:37:36 -05002603}
2604
2605size_t Context::getRequestableExtensionStringCount() const
2606{
2607 return mRequestableExtensionStrings.size();
2608}
2609
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002610void Context::beginTransformFeedback(GLenum primitiveMode)
2611{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002612 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002613 ASSERT(transformFeedback != nullptr);
2614 ASSERT(!transformFeedback->isPaused());
2615
Jamie Madill6c1f6712017-02-14 19:08:04 -05002616 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002617}
2618
2619bool Context::hasActiveTransformFeedback(GLuint program) const
2620{
2621 for (auto pair : mTransformFeedbackMap)
2622 {
2623 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
2624 {
2625 return true;
2626 }
2627 }
2628 return false;
2629}
2630
Geoff Langb433e872017-10-05 14:01:47 -04002631void Context::initCaps(const egl::DisplayExtensions &displayExtensions, bool robustResourceInit)
Geoff Lang493daf52014-07-03 13:38:44 -04002632{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002633 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04002634
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002635 mExtensions = mImplementation->getNativeExtensions();
Geoff Lang493daf52014-07-03 13:38:44 -04002636
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002637 mLimitations = mImplementation->getNativeLimitations();
Austin Kinross02df7962015-07-01 10:03:42 -07002638
Geoff Langeb66a6e2016-10-31 13:06:12 -04002639 if (getClientVersion() < Version(3, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002640 {
2641 // Disable ES3+ extensions
Jamie Madill231c7f52017-04-26 13:45:37 -04002642 mExtensions.colorBufferFloat = false;
Geoff Langb66a9092016-05-16 15:59:14 -04002643 mExtensions.eglImageExternalEssl3 = false;
Vincent Lang25ab4512016-05-13 18:13:59 +02002644 mExtensions.textureNorm16 = false;
Martin Radev137032d2017-07-13 10:11:12 +03002645 mExtensions.multiview = false;
2646 mExtensions.maxViews = 1u;
Geoff Lang493daf52014-07-03 13:38:44 -04002647 }
2648
Geoff Langeb66a6e2016-10-31 13:06:12 -04002649 if (getClientVersion() > Version(2, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002650 {
2651 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
Jamie Madill231c7f52017-04-26 13:45:37 -04002652 // mExtensions.sRGB = false;
Geoff Lang493daf52014-07-03 13:38:44 -04002653 }
2654
Jamie Madill00ed7a12016-05-19 13:13:38 -04002655 // Some extensions are always available because they are implemented in the GL layer.
Jamie Madill231c7f52017-04-26 13:45:37 -04002656 mExtensions.bindUniformLocation = true;
2657 mExtensions.vertexArrayObject = true;
Geoff Langf41a7152016-09-19 15:11:17 -04002658 mExtensions.bindGeneratesResource = true;
Geoff Langfeb8c682017-02-13 16:07:35 -05002659 mExtensions.clientArrays = true;
Geoff Langc339c4e2016-11-29 10:37:36 -05002660 mExtensions.requestExtension = true;
Jamie Madill00ed7a12016-05-19 13:13:38 -04002661
2662 // Enable the no error extension if the context was created with the flag.
2663 mExtensions.noError = mSkipValidation;
2664
Corentin Wallezccab69d2017-01-27 16:57:15 -05002665 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Corentin Wallezc295e512017-01-27 17:47:50 -05002666 mExtensions.surfacelessContext = displayExtensions.surfacelessContext;
Corentin Wallezccab69d2017-01-27 16:57:15 -05002667
Geoff Lang70d0f492015-12-10 17:45:46 -05002668 // Explicitly enable GL_KHR_debug
2669 mExtensions.debug = true;
2670 mExtensions.maxDebugMessageLength = 1024;
2671 mExtensions.maxDebugLoggedMessages = 1024;
2672 mExtensions.maxDebugGroupStackDepth = 1024;
2673 mExtensions.maxLabelLength = 1024;
2674
Geoff Langff5b2d52016-09-07 11:32:23 -04002675 // Explicitly enable GL_ANGLE_robust_client_memory
2676 mExtensions.robustClientMemory = true;
2677
Jamie Madille08a1d32017-03-07 17:24:06 -05002678 // Determine robust resource init availability from EGL.
Geoff Langb433e872017-10-05 14:01:47 -04002679 mExtensions.robustResourceInitialization = robustResourceInit;
Jamie Madille08a1d32017-03-07 17:24:06 -05002680
Jiajia Qin8a7b3a02017-08-25 16:05:48 +08002681 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
2682 // supports it.
2683 mExtensions.robustBufferAccessBehavior =
2684 mRobustAccess && mExtensions.robustBufferAccessBehavior;
2685
Jamie Madillc43be722017-07-13 16:22:14 -04002686 // Enable the cache control query unconditionally.
2687 mExtensions.programCacheControl = true;
2688
Geoff Lang301d1612014-07-09 10:34:37 -04002689 // Apply implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04002690 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002691
Jamie Madill0f80ed82017-09-19 00:24:56 -04002692 if (getClientVersion() < ES_3_1)
2693 {
2694 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
2695 }
2696 else
2697 {
2698 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
2699 }
Geoff Lang301d1612014-07-09 10:34:37 -04002700
Jamie Madill0f80ed82017-09-19 00:24:56 -04002701 LimitCap(&mCaps.maxVertexUniformBlocks, IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
2702 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
2703 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
2704
2705 // Limit textures as well, so we can use fast bitsets with texture bindings.
2706 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
2707 LimitCap(&mCaps.maxVertexTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
2708 LimitCap(&mCaps.maxTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04002709
Jiawei Shaodb342272017-09-27 10:21:45 +08002710 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
2711
Geoff Langc287ea62016-09-16 14:46:51 -04002712 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002713 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04002714 for (const auto &extensionInfo : GetExtensionInfoMap())
2715 {
2716 // If this context is for WebGL, disable all enableable extensions
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002717 if (mWebGLContext && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04002718 {
2719 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
2720 }
2721 }
2722
2723 // Generate texture caps
2724 updateCaps();
2725}
2726
2727void Context::updateCaps()
2728{
Geoff Lang900013c2014-07-07 11:32:19 -04002729 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002730 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04002731
Jamie Madill7b62cf92017-11-02 15:20:49 -04002732 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04002733 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04002734 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04002735 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04002736
Geoff Lang0d8b7242015-09-09 14:56:53 -04002737 // Update the format caps based on the client version and extensions.
2738 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
2739 // ES3.
2740 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002741 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002742 formatCaps.renderable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002743 formatCaps.renderable && formatInfo.renderSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002744 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002745 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04002746
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002747 // OpenGL ES does not support multisampling with non-rendererable formats
2748 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Olli Etuaho50c562d2017-06-06 14:43:30 +03002749 if (!formatCaps.renderable ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002750 (getClientVersion() < ES_3_1 &&
2751 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04002752 {
Geoff Langd87878e2014-09-19 15:42:59 -04002753 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04002754 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03002755 else
2756 {
2757 // We may have limited the max samples for some required renderbuffer formats due to
2758 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
2759 GLuint formatMaxSamples = formatCaps.getMaxSamples();
2760
2761 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
2762 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
2763 // exception of signed and unsigned integer formats."
2764 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
2765 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
2766 {
2767 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
2768 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
2769 }
2770
2771 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
2772 if (getClientVersion() >= ES_3_1)
2773 {
2774 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
2775 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
2776 // the exception that the signed and unsigned integer formats are required only to
2777 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
2778 // multisamples, which must be at least one."
2779 if (formatInfo.componentType == GL_INT ||
2780 formatInfo.componentType == GL_UNSIGNED_INT)
2781 {
2782 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
2783 }
2784
2785 // GLES 3.1 section 19.3.1.
2786 if (formatCaps.texturable)
2787 {
2788 if (formatInfo.depthBits > 0)
2789 {
2790 mCaps.maxDepthTextureSamples =
2791 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
2792 }
2793 else if (formatInfo.redBits > 0)
2794 {
2795 mCaps.maxColorTextureSamples =
2796 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
2797 }
2798 }
2799 }
2800 }
Geoff Langd87878e2014-09-19 15:42:59 -04002801
2802 if (formatCaps.texturable && formatInfo.compressed)
2803 {
Geoff Langca271392017-04-05 12:30:00 -04002804 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04002805 }
2806
Geoff Langca271392017-04-05 12:30:00 -04002807 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04002808 }
Jamie Madill32447362017-06-28 14:53:52 -04002809
2810 // If program binary is disabled, blank out the memory cache pointer.
2811 if (!mImplementation->getNativeExtensions().getProgramBinary)
2812 {
2813 mMemoryProgramCache = nullptr;
2814 }
Geoff Lang493daf52014-07-03 13:38:44 -04002815}
2816
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002817void Context::initWorkarounds()
2818{
Jamie Madill761b02c2017-06-23 16:27:06 -04002819 // Apply back-end workarounds.
2820 mImplementation->applyNativeWorkarounds(&mWorkarounds);
2821
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002822 // Lose the context upon out of memory error if the application is
2823 // expecting to watch for those events.
2824 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2825}
2826
Jamie Madill05b35b22017-10-03 09:01:44 -04002827Error Context::prepareForDraw()
2828{
2829 syncRendererState();
Jamie Madilla59fc192017-11-02 12:57:58 -04002830
2831 if (isRobustResourceInitEnabled())
2832 {
2833 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
2834 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
2835 }
2836
Jamie Madill05b35b22017-10-03 09:01:44 -04002837 return NoError();
2838}
2839
Jamie Madill1b94d432015-08-07 13:23:23 -04002840void Context::syncRendererState()
2841{
Jamie Madill7d1f5c62017-09-02 15:32:15 -04002842 mGLState.syncDirtyObjects(this);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002843 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
Jamie Madillfe548342017-06-19 11:13:24 -04002844 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002845 mGLState.clearDirtyBits();
Jamie Madill1b94d432015-08-07 13:23:23 -04002846}
2847
Jamie Madillad9f24e2016-02-12 09:27:24 -05002848void Context::syncRendererState(const State::DirtyBits &bitMask,
2849 const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04002850{
Jamie Madill7d1f5c62017-09-02 15:32:15 -04002851 mGLState.syncDirtyObjects(this, objectMask);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002852 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madillfe548342017-06-19 11:13:24 -04002853 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002854 mGLState.clearDirtyBits(dirtyBits);
Jamie Madill1b94d432015-08-07 13:23:23 -04002855}
Jamie Madillc29968b2016-01-20 11:17:23 -05002856
2857void Context::blitFramebuffer(GLint srcX0,
2858 GLint srcY0,
2859 GLint srcX1,
2860 GLint srcY1,
2861 GLint dstX0,
2862 GLint dstY0,
2863 GLint dstX1,
2864 GLint dstY1,
2865 GLbitfield mask,
2866 GLenum filter)
2867{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002868 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002869 ASSERT(drawFramebuffer);
2870
2871 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
2872 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
2873
Jamie Madillad9f24e2016-02-12 09:27:24 -05002874 syncStateForBlit();
Jamie Madillc29968b2016-01-20 11:17:23 -05002875
Jamie Madillc564c072017-06-01 12:45:42 -04002876 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002877}
Jamie Madillc29968b2016-01-20 11:17:23 -05002878
2879void Context::clear(GLbitfield mask)
2880{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002881 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002882 handleError(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05002883}
2884
2885void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
2886{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002887 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002888 handleError(mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002889}
2890
2891void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
2892{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002893 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002894 handleError(mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002895}
2896
2897void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
2898{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002899 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002900 handleError(mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002901}
2902
2903void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
2904{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002905 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002906 ASSERT(framebufferObject);
2907
2908 // If a buffer is not present, the clear has no effect
2909 if (framebufferObject->getDepthbuffer() == nullptr &&
2910 framebufferObject->getStencilbuffer() == nullptr)
2911 {
2912 return;
2913 }
2914
Jamie Madillad9f24e2016-02-12 09:27:24 -05002915 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002916 handleError(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05002917}
2918
2919void Context::readPixels(GLint x,
2920 GLint y,
2921 GLsizei width,
2922 GLsizei height,
2923 GLenum format,
2924 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002925 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05002926{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04002927 if (width == 0 || height == 0)
2928 {
2929 return;
2930 }
2931
Jamie Madillad9f24e2016-02-12 09:27:24 -05002932 syncStateForReadPixels();
Jamie Madillc29968b2016-01-20 11:17:23 -05002933
Jamie Madillb6664922017-07-25 12:55:04 -04002934 Framebuffer *readFBO = mGLState.getReadFramebuffer();
2935 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05002936
2937 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04002938 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05002939}
2940
2941void Context::copyTexImage2D(GLenum target,
2942 GLint level,
2943 GLenum internalformat,
2944 GLint x,
2945 GLint y,
2946 GLsizei width,
2947 GLsizei height,
2948 GLint border)
2949{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002950 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002951 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002952
Jamie Madillc29968b2016-01-20 11:17:23 -05002953 Rectangle sourceArea(x, y, width, height);
2954
Jamie Madill05b35b22017-10-03 09:01:44 -04002955 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002956 Texture *texture =
2957 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05002958 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05002959}
2960
2961void Context::copyTexSubImage2D(GLenum target,
2962 GLint level,
2963 GLint xoffset,
2964 GLint yoffset,
2965 GLint x,
2966 GLint y,
2967 GLsizei width,
2968 GLsizei height)
2969{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04002970 if (width == 0 || height == 0)
2971 {
2972 return;
2973 }
2974
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002975 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002976 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002977
Jamie Madillc29968b2016-01-20 11:17:23 -05002978 Offset destOffset(xoffset, yoffset, 0);
2979 Rectangle sourceArea(x, y, width, height);
2980
Jamie Madill05b35b22017-10-03 09:01:44 -04002981 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002982 Texture *texture =
2983 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05002984 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05002985}
2986
2987void Context::copyTexSubImage3D(GLenum target,
2988 GLint level,
2989 GLint xoffset,
2990 GLint yoffset,
2991 GLint zoffset,
2992 GLint x,
2993 GLint y,
2994 GLsizei width,
2995 GLsizei height)
2996{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04002997 if (width == 0 || height == 0)
2998 {
2999 return;
3000 }
3001
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003002 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003003 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003004
Jamie Madillc29968b2016-01-20 11:17:23 -05003005 Offset destOffset(xoffset, yoffset, zoffset);
3006 Rectangle sourceArea(x, y, width, height);
3007
Jamie Madill05b35b22017-10-03 09:01:44 -04003008 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3009 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003010 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003011}
3012
3013void Context::framebufferTexture2D(GLenum target,
3014 GLenum attachment,
3015 GLenum textarget,
3016 GLuint texture,
3017 GLint level)
3018{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003019 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003020 ASSERT(framebuffer);
3021
3022 if (texture != 0)
3023 {
3024 Texture *textureObj = getTexture(texture);
3025
3026 ImageIndex index = ImageIndex::MakeInvalid();
3027
3028 if (textarget == GL_TEXTURE_2D)
3029 {
3030 index = ImageIndex::Make2D(level);
3031 }
Corentin Wallez13c0dd42017-07-04 18:27:01 -04003032 else if (textarget == GL_TEXTURE_RECTANGLE_ANGLE)
3033 {
3034 index = ImageIndex::MakeRectangle(level);
3035 }
JiangYizhoubddc46b2016-12-09 09:50:51 +08003036 else if (textarget == GL_TEXTURE_2D_MULTISAMPLE)
3037 {
3038 ASSERT(level == 0);
3039 index = ImageIndex::Make2DMultisample();
3040 }
Jamie Madillc29968b2016-01-20 11:17:23 -05003041 else
3042 {
3043 ASSERT(IsCubeMapTextureTarget(textarget));
3044 index = ImageIndex::MakeCube(textarget, level);
3045 }
3046
Jamie Madilla02315b2017-02-23 14:14:47 -05003047 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003048 }
3049 else
3050 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003051 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003052 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003053
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003054 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003055}
3056
3057void Context::framebufferRenderbuffer(GLenum target,
3058 GLenum attachment,
3059 GLenum renderbuffertarget,
3060 GLuint renderbuffer)
3061{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003062 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003063 ASSERT(framebuffer);
3064
3065 if (renderbuffer != 0)
3066 {
3067 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003068
3069 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex::MakeInvalid(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003070 renderbufferObject);
3071 }
3072 else
3073 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003074 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003075 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003076
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003077 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003078}
3079
3080void Context::framebufferTextureLayer(GLenum target,
3081 GLenum attachment,
3082 GLuint texture,
3083 GLint level,
3084 GLint layer)
3085{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003086 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003087 ASSERT(framebuffer);
3088
3089 if (texture != 0)
3090 {
3091 Texture *textureObject = getTexture(texture);
3092
3093 ImageIndex index = ImageIndex::MakeInvalid();
3094
3095 if (textureObject->getTarget() == GL_TEXTURE_3D)
3096 {
3097 index = ImageIndex::Make3D(level, layer);
3098 }
3099 else
3100 {
3101 ASSERT(textureObject->getTarget() == GL_TEXTURE_2D_ARRAY);
3102 index = ImageIndex::Make2DArray(level, layer);
3103 }
3104
Jamie Madilla02315b2017-02-23 14:14:47 -05003105 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003106 }
3107 else
3108 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003109 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003110 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003111
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003112 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003113}
3114
Martin Radev137032d2017-07-13 10:11:12 +03003115void Context::framebufferTextureMultiviewLayeredANGLE(GLenum target,
3116 GLenum attachment,
3117 GLuint texture,
3118 GLint level,
3119 GLint baseViewIndex,
3120 GLsizei numViews)
3121{
Martin Radev82ef7742017-08-08 17:44:58 +03003122 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3123 ASSERT(framebuffer);
3124
3125 if (texture != 0)
3126 {
3127 Texture *textureObj = getTexture(texture);
3128
Martin Radev18b75ba2017-08-15 15:50:40 +03003129 ImageIndex index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
Martin Radev82ef7742017-08-08 17:44:58 +03003130 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3131 numViews, baseViewIndex);
3132 }
3133 else
3134 {
3135 framebuffer->resetAttachment(this, attachment);
3136 }
3137
3138 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003139}
3140
3141void Context::framebufferTextureMultiviewSideBySideANGLE(GLenum target,
3142 GLenum attachment,
3143 GLuint texture,
3144 GLint level,
3145 GLsizei numViews,
3146 const GLint *viewportOffsets)
3147{
Martin Radev5dae57b2017-07-14 16:15:55 +03003148 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3149 ASSERT(framebuffer);
3150
3151 if (texture != 0)
3152 {
3153 Texture *textureObj = getTexture(texture);
3154
3155 ImageIndex index = ImageIndex::Make2D(level);
3156 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3157 textureObj, numViews, viewportOffsets);
3158 }
3159 else
3160 {
3161 framebuffer->resetAttachment(this, attachment);
3162 }
3163
3164 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003165}
3166
Jamie Madillc29968b2016-01-20 11:17:23 -05003167void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3168{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003169 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003170 ASSERT(framebuffer);
3171 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003172 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003173}
3174
3175void Context::readBuffer(GLenum mode)
3176{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003177 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003178 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003179 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003180}
3181
3182void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3183{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003184 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003185 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003186
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003187 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003188 ASSERT(framebuffer);
3189
3190 // The specification isn't clear what should be done when the framebuffer isn't complete.
3191 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003192 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003193}
3194
3195void Context::invalidateFramebuffer(GLenum target,
3196 GLsizei numAttachments,
3197 const GLenum *attachments)
3198{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003199 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003200 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003201
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003202 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003203 ASSERT(framebuffer);
3204
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003205 if (framebuffer->checkStatus(this) != GL_FRAMEBUFFER_COMPLETE)
Jamie Madillc29968b2016-01-20 11:17:23 -05003206 {
Jamie Madill437fa652016-05-03 15:13:24 -04003207 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003208 }
Jamie Madill437fa652016-05-03 15:13:24 -04003209
Jamie Madill4928b7c2017-06-20 12:57:39 -04003210 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003211}
3212
3213void Context::invalidateSubFramebuffer(GLenum target,
3214 GLsizei numAttachments,
3215 const GLenum *attachments,
3216 GLint x,
3217 GLint y,
3218 GLsizei width,
3219 GLsizei height)
3220{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003221 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003222 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003223
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003224 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003225 ASSERT(framebuffer);
3226
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003227 if (framebuffer->checkStatus(this) != GL_FRAMEBUFFER_COMPLETE)
Jamie Madillc29968b2016-01-20 11:17:23 -05003228 {
Jamie Madill437fa652016-05-03 15:13:24 -04003229 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003230 }
Jamie Madill437fa652016-05-03 15:13:24 -04003231
3232 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003233 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003234}
3235
Jamie Madill73a84962016-02-12 09:27:23 -05003236void Context::texImage2D(GLenum target,
3237 GLint level,
3238 GLint internalformat,
3239 GLsizei width,
3240 GLsizei height,
3241 GLint border,
3242 GLenum format,
3243 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003244 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003245{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003246 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003247
3248 Extents size(width, height, 1);
3249 Texture *texture =
3250 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003251 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3252 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003253}
3254
3255void Context::texImage3D(GLenum target,
3256 GLint level,
3257 GLint internalformat,
3258 GLsizei width,
3259 GLsizei height,
3260 GLsizei depth,
3261 GLint border,
3262 GLenum format,
3263 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003264 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003265{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003266 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003267
3268 Extents size(width, height, depth);
3269 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003270 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3271 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003272}
3273
3274void Context::texSubImage2D(GLenum target,
3275 GLint level,
3276 GLint xoffset,
3277 GLint yoffset,
3278 GLsizei width,
3279 GLsizei height,
3280 GLenum format,
3281 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003282 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003283{
3284 // Zero sized uploads are valid but no-ops
3285 if (width == 0 || height == 0)
3286 {
3287 return;
3288 }
3289
Jamie Madillad9f24e2016-02-12 09:27:24 -05003290 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003291
3292 Box area(xoffset, yoffset, 0, width, height, 1);
3293 Texture *texture =
3294 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003295 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3296 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003297}
3298
3299void Context::texSubImage3D(GLenum target,
3300 GLint level,
3301 GLint xoffset,
3302 GLint yoffset,
3303 GLint zoffset,
3304 GLsizei width,
3305 GLsizei height,
3306 GLsizei depth,
3307 GLenum format,
3308 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003309 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003310{
3311 // Zero sized uploads are valid but no-ops
3312 if (width == 0 || height == 0 || depth == 0)
3313 {
3314 return;
3315 }
3316
Jamie Madillad9f24e2016-02-12 09:27:24 -05003317 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003318
3319 Box area(xoffset, yoffset, zoffset, width, height, depth);
3320 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003321 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3322 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003323}
3324
3325void Context::compressedTexImage2D(GLenum target,
3326 GLint level,
3327 GLenum internalformat,
3328 GLsizei width,
3329 GLsizei height,
3330 GLint border,
3331 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003332 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003333{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003334 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003335
3336 Extents size(width, height, 1);
3337 Texture *texture =
3338 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003339 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003340 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003341 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003342}
3343
3344void Context::compressedTexImage3D(GLenum target,
3345 GLint level,
3346 GLenum internalformat,
3347 GLsizei width,
3348 GLsizei height,
3349 GLsizei depth,
3350 GLint border,
3351 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003352 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003353{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003354 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003355
3356 Extents size(width, height, depth);
3357 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003358 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003359 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003360 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003361}
3362
3363void Context::compressedTexSubImage2D(GLenum target,
3364 GLint level,
3365 GLint xoffset,
3366 GLint yoffset,
3367 GLsizei width,
3368 GLsizei height,
3369 GLenum format,
3370 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003371 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003372{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003373 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003374
3375 Box area(xoffset, yoffset, 0, width, height, 1);
3376 Texture *texture =
3377 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003378 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003379 format, imageSize,
3380 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003381}
3382
3383void Context::compressedTexSubImage3D(GLenum target,
3384 GLint level,
3385 GLint xoffset,
3386 GLint yoffset,
3387 GLint zoffset,
3388 GLsizei width,
3389 GLsizei height,
3390 GLsizei depth,
3391 GLenum format,
3392 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003393 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003394{
3395 // Zero sized uploads are valid but no-ops
3396 if (width == 0 || height == 0)
3397 {
3398 return;
3399 }
3400
Jamie Madillad9f24e2016-02-12 09:27:24 -05003401 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003402
3403 Box area(xoffset, yoffset, zoffset, width, height, depth);
3404 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003405 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003406 format, imageSize,
3407 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003408}
3409
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003410void Context::generateMipmap(GLenum target)
3411{
3412 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003413 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003414}
3415
Geoff Lang97073d12016-04-20 10:42:34 -07003416void Context::copyTextureCHROMIUM(GLuint sourceId,
Geoff Langfc72a072017-03-24 14:52:39 -04003417 GLint sourceLevel,
3418 GLenum destTarget,
Geoff Lang97073d12016-04-20 10:42:34 -07003419 GLuint destId,
Geoff Langfc72a072017-03-24 14:52:39 -04003420 GLint destLevel,
Geoff Lang97073d12016-04-20 10:42:34 -07003421 GLint internalFormat,
3422 GLenum destType,
3423 GLboolean unpackFlipY,
3424 GLboolean unpackPremultiplyAlpha,
3425 GLboolean unpackUnmultiplyAlpha)
3426{
3427 syncStateForTexImage();
3428
3429 gl::Texture *sourceTexture = getTexture(sourceId);
3430 gl::Texture *destTexture = getTexture(destId);
Geoff Langfc72a072017-03-24 14:52:39 -04003431 handleError(destTexture->copyTexture(
3432 this, destTarget, destLevel, internalFormat, destType, sourceLevel, unpackFlipY == GL_TRUE,
3433 unpackPremultiplyAlpha == GL_TRUE, unpackUnmultiplyAlpha == GL_TRUE, sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003434}
3435
3436void Context::copySubTextureCHROMIUM(GLuint sourceId,
Geoff Langfc72a072017-03-24 14:52:39 -04003437 GLint sourceLevel,
3438 GLenum destTarget,
Geoff Lang97073d12016-04-20 10:42:34 -07003439 GLuint destId,
Geoff Langfc72a072017-03-24 14:52:39 -04003440 GLint destLevel,
Geoff Lang97073d12016-04-20 10:42:34 -07003441 GLint xoffset,
3442 GLint yoffset,
3443 GLint x,
3444 GLint y,
3445 GLsizei width,
3446 GLsizei height,
3447 GLboolean unpackFlipY,
3448 GLboolean unpackPremultiplyAlpha,
3449 GLboolean unpackUnmultiplyAlpha)
3450{
3451 // Zero sized copies are valid but no-ops
3452 if (width == 0 || height == 0)
3453 {
3454 return;
3455 }
3456
3457 syncStateForTexImage();
3458
3459 gl::Texture *sourceTexture = getTexture(sourceId);
3460 gl::Texture *destTexture = getTexture(destId);
3461 Offset offset(xoffset, yoffset, 0);
3462 Rectangle area(x, y, width, height);
Geoff Langfc72a072017-03-24 14:52:39 -04003463 handleError(destTexture->copySubTexture(
3464 this, destTarget, destLevel, offset, sourceLevel, area, unpackFlipY == GL_TRUE,
3465 unpackPremultiplyAlpha == GL_TRUE, unpackUnmultiplyAlpha == GL_TRUE, sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003466}
3467
Geoff Lang47110bf2016-04-20 11:13:22 -07003468void Context::compressedCopyTextureCHROMIUM(GLuint sourceId, GLuint destId)
3469{
3470 syncStateForTexImage();
3471
3472 gl::Texture *sourceTexture = getTexture(sourceId);
3473 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05003474 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07003475}
3476
Geoff Lang496c02d2016-10-20 11:38:11 -07003477void Context::getBufferPointerv(GLenum target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03003478{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003479 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003480 ASSERT(buffer);
3481
Geoff Lang496c02d2016-10-20 11:38:11 -07003482 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03003483}
3484
Jamie Madill876429b2017-04-20 15:46:24 -04003485void *Context::mapBuffer(GLenum target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003486{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003487 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003488 ASSERT(buffer);
3489
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003490 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003491 if (error.isError())
3492 {
Jamie Madill437fa652016-05-03 15:13:24 -04003493 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003494 return nullptr;
3495 }
3496
3497 return buffer->getMapPointer();
3498}
3499
3500GLboolean Context::unmapBuffer(GLenum target)
3501{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003502 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003503 ASSERT(buffer);
3504
3505 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003506 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03003507 if (error.isError())
3508 {
Jamie Madill437fa652016-05-03 15:13:24 -04003509 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003510 return GL_FALSE;
3511 }
3512
3513 return result;
3514}
3515
Jamie Madill876429b2017-04-20 15:46:24 -04003516void *Context::mapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003517{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003518 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003519 ASSERT(buffer);
3520
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003521 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003522 if (error.isError())
3523 {
Jamie Madill437fa652016-05-03 15:13:24 -04003524 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003525 return nullptr;
3526 }
3527
3528 return buffer->getMapPointer();
3529}
3530
3531void Context::flushMappedBufferRange(GLenum /*target*/, GLintptr /*offset*/, GLsizeiptr /*length*/)
3532{
3533 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
3534}
3535
Jamie Madillad9f24e2016-02-12 09:27:24 -05003536void Context::syncStateForReadPixels()
3537{
3538 syncRendererState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
3539}
3540
3541void Context::syncStateForTexImage()
3542{
3543 syncRendererState(mTexImageDirtyBits, mTexImageDirtyObjects);
3544}
3545
3546void Context::syncStateForClear()
3547{
3548 syncRendererState(mClearDirtyBits, mClearDirtyObjects);
3549}
3550
3551void Context::syncStateForBlit()
3552{
3553 syncRendererState(mBlitDirtyBits, mBlitDirtyObjects);
3554}
3555
Jamie Madillc20ab272016-06-09 07:20:46 -07003556void Context::activeTexture(GLenum texture)
3557{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003558 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003559}
3560
Jamie Madill876429b2017-04-20 15:46:24 -04003561void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003562{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003563 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07003564}
3565
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003566void Context::blendEquation(GLenum mode)
3567{
3568 mGLState.setBlendEquation(mode, mode);
3569}
3570
Jamie Madillc20ab272016-06-09 07:20:46 -07003571void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
3572{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003573 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003574}
3575
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003576void Context::blendFunc(GLenum sfactor, GLenum dfactor)
3577{
3578 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
3579}
3580
Jamie Madillc20ab272016-06-09 07:20:46 -07003581void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
3582{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003583 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003584}
3585
Jamie Madill876429b2017-04-20 15:46:24 -04003586void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003587{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003588 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003589}
3590
Jamie Madill876429b2017-04-20 15:46:24 -04003591void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07003592{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003593 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07003594}
3595
3596void Context::clearStencil(GLint s)
3597{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003598 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07003599}
3600
3601void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
3602{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003603 mGLState.setColorMask(red == GL_TRUE, green == GL_TRUE, blue == GL_TRUE, alpha == GL_TRUE);
Jamie Madillc20ab272016-06-09 07:20:46 -07003604}
3605
Corentin Wallez2e568cf2017-09-18 17:05:22 -04003606void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07003607{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003608 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003609}
3610
3611void Context::depthFunc(GLenum func)
3612{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003613 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07003614}
3615
3616void Context::depthMask(GLboolean flag)
3617{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003618 mGLState.setDepthMask(flag != GL_FALSE);
Jamie Madillc20ab272016-06-09 07:20:46 -07003619}
3620
Jamie Madill876429b2017-04-20 15:46:24 -04003621void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07003622{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003623 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07003624}
3625
3626void Context::disable(GLenum cap)
3627{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003628 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003629}
3630
3631void Context::disableVertexAttribArray(GLuint index)
3632{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003633 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003634}
3635
3636void Context::enable(GLenum cap)
3637{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003638 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003639}
3640
3641void Context::enableVertexAttribArray(GLuint index)
3642{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003643 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003644}
3645
3646void Context::frontFace(GLenum mode)
3647{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003648 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003649}
3650
3651void Context::hint(GLenum target, GLenum mode)
3652{
3653 switch (target)
3654 {
3655 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003656 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003657 break;
3658
3659 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003660 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003661 break;
3662
3663 default:
3664 UNREACHABLE();
3665 return;
3666 }
3667}
3668
3669void Context::lineWidth(GLfloat width)
3670{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003671 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07003672}
3673
3674void Context::pixelStorei(GLenum pname, GLint param)
3675{
3676 switch (pname)
3677 {
3678 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003679 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003680 break;
3681
3682 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003683 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003684 break;
3685
3686 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003687 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003688 break;
3689
3690 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003691 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003692 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003693 break;
3694
3695 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03003696 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003697 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003698 break;
3699
3700 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03003701 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003702 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003703 break;
3704
3705 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003706 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003707 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003708 break;
3709
3710 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003711 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003712 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003713 break;
3714
3715 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003716 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003717 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003718 break;
3719
3720 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003721 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003722 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003723 break;
3724
3725 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003726 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003727 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003728 break;
3729
3730 default:
3731 UNREACHABLE();
3732 return;
3733 }
3734}
3735
3736void Context::polygonOffset(GLfloat factor, GLfloat units)
3737{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003738 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07003739}
3740
Jamie Madill876429b2017-04-20 15:46:24 -04003741void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07003742{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003743 mGLState.setSampleCoverageParams(clamp01(value), invert == GL_TRUE);
Jamie Madillc20ab272016-06-09 07:20:46 -07003744}
3745
Jiawei Shaodb342272017-09-27 10:21:45 +08003746void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
3747{
3748 mGLState.setSampleMaskParams(maskNumber, mask);
3749}
3750
Jamie Madillc20ab272016-06-09 07:20:46 -07003751void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
3752{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003753 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07003754}
3755
3756void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
3757{
3758 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3759 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003760 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003761 }
3762
3763 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3764 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003765 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003766 }
3767}
3768
3769void Context::stencilMaskSeparate(GLenum face, GLuint mask)
3770{
3771 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3772 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003773 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003774 }
3775
3776 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3777 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003778 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003779 }
3780}
3781
3782void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
3783{
3784 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3785 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003786 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003787 }
3788
3789 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3790 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003791 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003792 }
3793}
3794
3795void Context::vertexAttrib1f(GLuint index, GLfloat x)
3796{
3797 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003798 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003799}
3800
3801void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
3802{
3803 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003804 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003805}
3806
3807void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
3808{
3809 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003810 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003811}
3812
3813void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
3814{
3815 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003816 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003817}
3818
3819void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
3820{
3821 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003822 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003823}
3824
3825void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
3826{
3827 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003828 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003829}
3830
3831void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
3832{
3833 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003834 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003835}
3836
3837void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
3838{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003839 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07003840}
3841
3842void Context::vertexAttribPointer(GLuint index,
3843 GLint size,
3844 GLenum type,
3845 GLboolean normalized,
3846 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04003847 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07003848{
Shaodde78e82017-05-22 14:13:27 +08003849 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(GL_ARRAY_BUFFER), size,
3850 type, normalized == GL_TRUE, false, stride, ptr);
Jamie Madillc20ab272016-06-09 07:20:46 -07003851}
3852
Shao80957d92017-02-20 21:25:59 +08003853void Context::vertexAttribFormat(GLuint attribIndex,
3854 GLint size,
3855 GLenum type,
3856 GLboolean normalized,
3857 GLuint relativeOffset)
3858{
3859 mGLState.setVertexAttribFormat(attribIndex, size, type, normalized == GL_TRUE, false,
3860 relativeOffset);
3861}
3862
3863void Context::vertexAttribIFormat(GLuint attribIndex,
3864 GLint size,
3865 GLenum type,
3866 GLuint relativeOffset)
3867{
3868 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
3869}
3870
3871void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
3872{
Shaodde78e82017-05-22 14:13:27 +08003873 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Shao80957d92017-02-20 21:25:59 +08003874}
3875
3876void Context::setVertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
3877{
3878 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
3879}
3880
Jamie Madillc20ab272016-06-09 07:20:46 -07003881void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
3882{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003883 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07003884}
3885
3886void Context::vertexAttribIPointer(GLuint index,
3887 GLint size,
3888 GLenum type,
3889 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04003890 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07003891{
Shaodde78e82017-05-22 14:13:27 +08003892 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(GL_ARRAY_BUFFER), size,
3893 type, false, true, stride, pointer);
Jamie Madillc20ab272016-06-09 07:20:46 -07003894}
3895
3896void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
3897{
3898 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003899 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003900}
3901
3902void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
3903{
3904 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003905 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003906}
3907
3908void Context::vertexAttribI4iv(GLuint index, const GLint *v)
3909{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003910 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07003911}
3912
3913void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
3914{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003915 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07003916}
3917
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003918void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
3919{
3920 const VertexAttribCurrentValueData &currentValues =
3921 getGLState().getVertexAttribCurrentValue(index);
3922 const VertexArray *vao = getGLState().getVertexArray();
3923 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3924 currentValues, pname, params);
3925}
3926
3927void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
3928{
3929 const VertexAttribCurrentValueData &currentValues =
3930 getGLState().getVertexAttribCurrentValue(index);
3931 const VertexArray *vao = getGLState().getVertexArray();
3932 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3933 currentValues, pname, params);
3934}
3935
3936void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
3937{
3938 const VertexAttribCurrentValueData &currentValues =
3939 getGLState().getVertexAttribCurrentValue(index);
3940 const VertexArray *vao = getGLState().getVertexArray();
3941 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3942 currentValues, pname, params);
3943}
3944
3945void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
3946{
3947 const VertexAttribCurrentValueData &currentValues =
3948 getGLState().getVertexAttribCurrentValue(index);
3949 const VertexArray *vao = getGLState().getVertexArray();
3950 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3951 currentValues, pname, params);
3952}
3953
Jamie Madill876429b2017-04-20 15:46:24 -04003954void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003955{
3956 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
3957 QueryVertexAttribPointerv(attrib, pname, pointer);
3958}
3959
Jamie Madillc20ab272016-06-09 07:20:46 -07003960void Context::debugMessageControl(GLenum source,
3961 GLenum type,
3962 GLenum severity,
3963 GLsizei count,
3964 const GLuint *ids,
3965 GLboolean enabled)
3966{
3967 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003968 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
3969 (enabled != GL_FALSE));
Jamie Madillc20ab272016-06-09 07:20:46 -07003970}
3971
3972void Context::debugMessageInsert(GLenum source,
3973 GLenum type,
3974 GLuint id,
3975 GLenum severity,
3976 GLsizei length,
3977 const GLchar *buf)
3978{
3979 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003980 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07003981}
3982
3983void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
3984{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003985 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07003986}
3987
3988GLuint Context::getDebugMessageLog(GLuint count,
3989 GLsizei bufSize,
3990 GLenum *sources,
3991 GLenum *types,
3992 GLuint *ids,
3993 GLenum *severities,
3994 GLsizei *lengths,
3995 GLchar *messageLog)
3996{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003997 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
3998 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07003999}
4000
4001void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4002{
4003 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004004 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004005}
4006
4007void Context::popDebugGroup()
4008{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004009 mGLState.getDebug().popGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004010}
4011
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004012void Context::bufferData(GLenum target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004013{
4014 Buffer *buffer = mGLState.getTargetBuffer(target);
4015 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004016 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004017}
4018
Jamie Madill876429b2017-04-20 15:46:24 -04004019void Context::bufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004020{
4021 if (data == nullptr)
4022 {
4023 return;
4024 }
4025
4026 Buffer *buffer = mGLState.getTargetBuffer(target);
4027 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004028 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004029}
4030
Jamie Madillef300b12016-10-07 15:12:09 -04004031void Context::attachShader(GLuint program, GLuint shader)
4032{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004033 auto programObject = mState.mShaderPrograms->getProgram(program);
4034 auto shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004035 ASSERT(programObject && shaderObject);
4036 programObject->attachShader(shaderObject);
4037}
4038
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004039const Workarounds &Context::getWorkarounds() const
4040{
4041 return mWorkarounds;
4042}
4043
Jamie Madillb0817d12016-11-01 15:48:31 -04004044void Context::copyBufferSubData(GLenum readTarget,
4045 GLenum writeTarget,
4046 GLintptr readOffset,
4047 GLintptr writeOffset,
4048 GLsizeiptr size)
4049{
4050 // if size is zero, the copy is a successful no-op
4051 if (size == 0)
4052 {
4053 return;
4054 }
4055
4056 // TODO(jmadill): cache these.
4057 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4058 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4059
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004060 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004061}
4062
Jamie Madill01a80ee2016-11-07 12:06:18 -05004063void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4064{
4065 Program *programObject = getProgram(program);
4066 // TODO(jmadill): Re-use this from the validation if possible.
4067 ASSERT(programObject);
4068 programObject->bindAttributeLocation(index, name);
4069}
4070
4071void Context::bindBuffer(GLenum target, GLuint buffer)
4072{
4073 switch (target)
4074 {
4075 case GL_ARRAY_BUFFER:
4076 bindArrayBuffer(buffer);
4077 break;
4078 case GL_ELEMENT_ARRAY_BUFFER:
4079 bindElementArrayBuffer(buffer);
4080 break;
4081 case GL_COPY_READ_BUFFER:
4082 bindCopyReadBuffer(buffer);
4083 break;
4084 case GL_COPY_WRITE_BUFFER:
4085 bindCopyWriteBuffer(buffer);
4086 break;
4087 case GL_PIXEL_PACK_BUFFER:
4088 bindPixelPackBuffer(buffer);
4089 break;
4090 case GL_PIXEL_UNPACK_BUFFER:
4091 bindPixelUnpackBuffer(buffer);
4092 break;
4093 case GL_UNIFORM_BUFFER:
4094 bindGenericUniformBuffer(buffer);
4095 break;
4096 case GL_TRANSFORM_FEEDBACK_BUFFER:
4097 bindGenericTransformFeedbackBuffer(buffer);
4098 break;
Geoff Lang3b573612016-10-31 14:08:10 -04004099 case GL_ATOMIC_COUNTER_BUFFER:
Jiajia Qin6eafb042016-12-27 17:04:07 +08004100 bindGenericAtomicCounterBuffer(buffer);
Geoff Lang3b573612016-10-31 14:08:10 -04004101 break;
4102 case GL_SHADER_STORAGE_BUFFER:
Jiajia Qinf546e7d2017-03-27 14:12:59 +08004103 bindGenericShaderStorageBuffer(buffer);
Geoff Lang3b573612016-10-31 14:08:10 -04004104 break;
4105 case GL_DRAW_INDIRECT_BUFFER:
Jiajia Qin9d7d0b12016-11-29 16:30:31 +08004106 bindDrawIndirectBuffer(buffer);
Geoff Lang3b573612016-10-31 14:08:10 -04004107 break;
4108 case GL_DISPATCH_INDIRECT_BUFFER:
Geoff Lang9f090372016-12-02 10:20:43 -05004109 if (buffer != 0)
4110 {
4111 // Binding buffers to this binding point is not implemented yet.
4112 UNIMPLEMENTED();
4113 }
Geoff Lang3b573612016-10-31 14:08:10 -04004114 break;
Jamie Madill01a80ee2016-11-07 12:06:18 -05004115
4116 default:
4117 UNREACHABLE();
4118 break;
4119 }
4120}
4121
Jiajia Qin6eafb042016-12-27 17:04:07 +08004122void Context::bindBufferBase(GLenum target, GLuint index, GLuint buffer)
4123{
4124 bindBufferRange(target, index, buffer, 0, 0);
4125}
4126
4127void Context::bindBufferRange(GLenum target,
4128 GLuint index,
4129 GLuint buffer,
4130 GLintptr offset,
4131 GLsizeiptr size)
4132{
4133 switch (target)
4134 {
4135 case GL_TRANSFORM_FEEDBACK_BUFFER:
4136 bindIndexedTransformFeedbackBuffer(buffer, index, offset, size);
4137 bindGenericTransformFeedbackBuffer(buffer);
4138 break;
4139 case GL_UNIFORM_BUFFER:
4140 bindIndexedUniformBuffer(buffer, index, offset, size);
4141 bindGenericUniformBuffer(buffer);
4142 break;
4143 case GL_ATOMIC_COUNTER_BUFFER:
4144 bindIndexedAtomicCounterBuffer(buffer, index, offset, size);
4145 bindGenericAtomicCounterBuffer(buffer);
4146 break;
4147 case GL_SHADER_STORAGE_BUFFER:
Jiajia Qinf546e7d2017-03-27 14:12:59 +08004148 bindIndexedShaderStorageBuffer(buffer, index, offset, size);
4149 bindGenericShaderStorageBuffer(buffer);
Jiajia Qin6eafb042016-12-27 17:04:07 +08004150 break;
4151 default:
4152 UNREACHABLE();
4153 break;
4154 }
4155}
4156
Jamie Madill01a80ee2016-11-07 12:06:18 -05004157void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
4158{
4159 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4160 {
4161 bindReadFramebuffer(framebuffer);
4162 }
4163
4164 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4165 {
4166 bindDrawFramebuffer(framebuffer);
4167 }
4168}
4169
4170void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4171{
4172 ASSERT(target == GL_RENDERBUFFER);
4173 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004174 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04004175 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004176}
4177
JiangYizhoubddc46b2016-12-09 09:50:51 +08004178void Context::texStorage2DMultisample(GLenum target,
4179 GLsizei samples,
4180 GLenum internalformat,
4181 GLsizei width,
4182 GLsizei height,
4183 GLboolean fixedsamplelocations)
4184{
4185 Extents size(width, height, 1);
4186 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05004187 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
JiangYizhoubddc46b2016-12-09 09:50:51 +08004188 fixedsamplelocations));
4189}
4190
4191void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4192{
JiangYizhou5b03f472017-01-09 10:22:53 +08004193 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
4194 // the sample position should be queried by DRAW_FRAMEBUFFER.
4195 mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER);
4196 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08004197
4198 switch (pname)
4199 {
4200 case GL_SAMPLE_POSITION:
4201 handleError(framebuffer->getSamplePosition(index, val));
4202 break;
4203 default:
4204 UNREACHABLE();
4205 }
4206}
4207
Jamie Madille8fb6402017-02-14 17:56:40 -05004208void Context::renderbufferStorage(GLenum target,
4209 GLenum internalformat,
4210 GLsizei width,
4211 GLsizei height)
4212{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004213 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4214 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
4215
Jamie Madille8fb6402017-02-14 17:56:40 -05004216 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04004217 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004218}
4219
4220void Context::renderbufferStorageMultisample(GLenum target,
4221 GLsizei samples,
4222 GLenum internalformat,
4223 GLsizei width,
4224 GLsizei height)
4225{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004226 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4227 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05004228
4229 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004230 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04004231 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004232}
4233
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004234void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
4235{
Jamie Madill70b5bb02017-08-28 13:32:37 -04004236 const Sync *syncObject = getSync(sync);
Geoff Lang82483b92017-04-11 15:33:00 -04004237 handleError(QuerySynciv(syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004238}
4239
JiangYizhoue18e6392017-02-20 10:32:23 +08004240void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
4241{
4242 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4243 QueryFramebufferParameteriv(framebuffer, pname, params);
4244}
4245
4246void Context::setFramebufferParameteri(GLenum target, GLenum pname, GLint param)
4247{
4248 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4249 SetFramebufferParameteri(framebuffer, pname, param);
4250}
4251
Jamie Madillb3f26b92017-07-19 15:07:41 -04004252Error Context::getScratchBuffer(size_t requstedSizeBytes,
4253 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05004254{
Jamie Madillb3f26b92017-07-19 15:07:41 -04004255 if (!mScratchBuffer.get(requstedSizeBytes, scratchBufferOut))
4256 {
4257 return OutOfMemory() << "Failed to allocate internal buffer.";
4258 }
4259 return NoError();
4260}
4261
4262Error Context::getZeroFilledBuffer(size_t requstedSizeBytes,
4263 angle::MemoryBuffer **zeroBufferOut) const
4264{
4265 if (!mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0))
Jamie Madille14951e2017-03-09 18:55:16 -05004266 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004267 return OutOfMemory() << "Failed to allocate internal buffer.";
Jamie Madille14951e2017-03-09 18:55:16 -05004268 }
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004269 return NoError();
Jamie Madille14951e2017-03-09 18:55:16 -05004270}
4271
Xinghua Cao2b396592017-03-29 15:36:04 +08004272void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
4273{
4274 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
4275 {
4276 return;
4277 }
4278
Jamie Madill05b35b22017-10-03 09:01:44 -04004279 // TODO(jmadill): Dirty bits for compute.
Jamie Madilla59fc192017-11-02 12:57:58 -04004280 if (isRobustResourceInitEnabled())
4281 {
4282 ANGLE_CONTEXT_TRY(mGLState.clearUnclearedActiveTextures(this));
4283 }
Jamie Madill05b35b22017-10-03 09:01:44 -04004284
Jamie Madill71c88b32017-09-14 22:20:29 -04004285 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08004286}
4287
JiangYizhou165361c2017-06-07 14:56:57 +08004288void Context::texStorage2D(GLenum target,
4289 GLsizei levels,
4290 GLenum internalFormat,
4291 GLsizei width,
4292 GLsizei height)
4293{
4294 Extents size(width, height, 1);
4295 Texture *texture = getTargetTexture(target);
4296 handleError(texture->setStorage(this, target, levels, internalFormat, size));
4297}
4298
4299void Context::texStorage3D(GLenum target,
4300 GLsizei levels,
4301 GLenum internalFormat,
4302 GLsizei width,
4303 GLsizei height,
4304 GLsizei depth)
4305{
4306 Extents size(width, height, depth);
4307 Texture *texture = getTargetTexture(target);
4308 handleError(texture->setStorage(this, target, levels, internalFormat, size));
4309}
4310
Jamie Madillc1d770e2017-04-13 17:31:24 -04004311GLenum Context::checkFramebufferStatus(GLenum target)
4312{
4313 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4314 ASSERT(framebuffer);
4315
4316 return framebuffer->checkStatus(this);
4317}
4318
4319void Context::compileShader(GLuint shader)
4320{
4321 Shader *shaderObject = GetValidShader(this, shader);
4322 if (!shaderObject)
4323 {
4324 return;
4325 }
4326 shaderObject->compile(this);
4327}
4328
4329void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
4330{
4331 for (int i = 0; i < n; i++)
4332 {
4333 deleteBuffer(buffers[i]);
4334 }
4335}
4336
4337void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
4338{
4339 for (int i = 0; i < n; i++)
4340 {
4341 if (framebuffers[i] != 0)
4342 {
4343 deleteFramebuffer(framebuffers[i]);
4344 }
4345 }
4346}
4347
4348void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
4349{
4350 for (int i = 0; i < n; i++)
4351 {
4352 deleteRenderbuffer(renderbuffers[i]);
4353 }
4354}
4355
4356void Context::deleteTextures(GLsizei n, const GLuint *textures)
4357{
4358 for (int i = 0; i < n; i++)
4359 {
4360 if (textures[i] != 0)
4361 {
4362 deleteTexture(textures[i]);
4363 }
4364 }
4365}
4366
4367void Context::detachShader(GLuint program, GLuint shader)
4368{
4369 Program *programObject = getProgram(program);
4370 ASSERT(programObject);
4371
4372 Shader *shaderObject = getShader(shader);
4373 ASSERT(shaderObject);
4374
4375 programObject->detachShader(this, shaderObject);
4376}
4377
4378void Context::genBuffers(GLsizei n, GLuint *buffers)
4379{
4380 for (int i = 0; i < n; i++)
4381 {
4382 buffers[i] = createBuffer();
4383 }
4384}
4385
4386void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
4387{
4388 for (int i = 0; i < n; i++)
4389 {
4390 framebuffers[i] = createFramebuffer();
4391 }
4392}
4393
4394void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
4395{
4396 for (int i = 0; i < n; i++)
4397 {
4398 renderbuffers[i] = createRenderbuffer();
4399 }
4400}
4401
4402void Context::genTextures(GLsizei n, GLuint *textures)
4403{
4404 for (int i = 0; i < n; i++)
4405 {
4406 textures[i] = createTexture();
4407 }
4408}
4409
4410void Context::getActiveAttrib(GLuint program,
4411 GLuint index,
4412 GLsizei bufsize,
4413 GLsizei *length,
4414 GLint *size,
4415 GLenum *type,
4416 GLchar *name)
4417{
4418 Program *programObject = getProgram(program);
4419 ASSERT(programObject);
4420 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
4421}
4422
4423void Context::getActiveUniform(GLuint program,
4424 GLuint index,
4425 GLsizei bufsize,
4426 GLsizei *length,
4427 GLint *size,
4428 GLenum *type,
4429 GLchar *name)
4430{
4431 Program *programObject = getProgram(program);
4432 ASSERT(programObject);
4433 programObject->getActiveUniform(index, bufsize, length, size, type, name);
4434}
4435
4436void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
4437{
4438 Program *programObject = getProgram(program);
4439 ASSERT(programObject);
4440 programObject->getAttachedShaders(maxcount, count, shaders);
4441}
4442
4443GLint Context::getAttribLocation(GLuint program, const GLchar *name)
4444{
4445 Program *programObject = getProgram(program);
4446 ASSERT(programObject);
4447 return programObject->getAttributeLocation(name);
4448}
4449
4450void Context::getBooleanv(GLenum pname, GLboolean *params)
4451{
4452 GLenum nativeType;
4453 unsigned int numParams = 0;
4454 getQueryParameterInfo(pname, &nativeType, &numParams);
4455
4456 if (nativeType == GL_BOOL)
4457 {
4458 getBooleanvImpl(pname, params);
4459 }
4460 else
4461 {
4462 CastStateValues(this, nativeType, pname, numParams, params);
4463 }
4464}
4465
4466void Context::getFloatv(GLenum pname, GLfloat *params)
4467{
4468 GLenum nativeType;
4469 unsigned int numParams = 0;
4470 getQueryParameterInfo(pname, &nativeType, &numParams);
4471
4472 if (nativeType == GL_FLOAT)
4473 {
4474 getFloatvImpl(pname, params);
4475 }
4476 else
4477 {
4478 CastStateValues(this, nativeType, pname, numParams, params);
4479 }
4480}
4481
4482void Context::getIntegerv(GLenum pname, GLint *params)
4483{
4484 GLenum nativeType;
4485 unsigned int numParams = 0;
4486 getQueryParameterInfo(pname, &nativeType, &numParams);
4487
4488 if (nativeType == GL_INT)
4489 {
4490 getIntegervImpl(pname, params);
4491 }
4492 else
4493 {
4494 CastStateValues(this, nativeType, pname, numParams, params);
4495 }
4496}
4497
4498void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
4499{
4500 Program *programObject = getProgram(program);
4501 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04004502 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004503}
4504
Jamie Madillbe849e42017-05-02 15:49:00 -04004505void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04004506{
4507 Program *programObject = getProgram(program);
4508 ASSERT(programObject);
4509 programObject->getInfoLog(bufsize, length, infolog);
4510}
4511
4512void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
4513{
4514 Shader *shaderObject = getShader(shader);
4515 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004516 QueryShaderiv(this, shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004517}
4518
4519void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
4520{
4521 Shader *shaderObject = getShader(shader);
4522 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004523 shaderObject->getInfoLog(this, bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004524}
4525
4526void Context::getShaderPrecisionFormat(GLenum shadertype,
4527 GLenum precisiontype,
4528 GLint *range,
4529 GLint *precision)
4530{
4531 // TODO(jmadill): Compute shaders.
4532
4533 switch (shadertype)
4534 {
4535 case GL_VERTEX_SHADER:
4536 switch (precisiontype)
4537 {
4538 case GL_LOW_FLOAT:
4539 mCaps.vertexLowpFloat.get(range, precision);
4540 break;
4541 case GL_MEDIUM_FLOAT:
4542 mCaps.vertexMediumpFloat.get(range, precision);
4543 break;
4544 case GL_HIGH_FLOAT:
4545 mCaps.vertexHighpFloat.get(range, precision);
4546 break;
4547
4548 case GL_LOW_INT:
4549 mCaps.vertexLowpInt.get(range, precision);
4550 break;
4551 case GL_MEDIUM_INT:
4552 mCaps.vertexMediumpInt.get(range, precision);
4553 break;
4554 case GL_HIGH_INT:
4555 mCaps.vertexHighpInt.get(range, precision);
4556 break;
4557
4558 default:
4559 UNREACHABLE();
4560 return;
4561 }
4562 break;
4563
4564 case GL_FRAGMENT_SHADER:
4565 switch (precisiontype)
4566 {
4567 case GL_LOW_FLOAT:
4568 mCaps.fragmentLowpFloat.get(range, precision);
4569 break;
4570 case GL_MEDIUM_FLOAT:
4571 mCaps.fragmentMediumpFloat.get(range, precision);
4572 break;
4573 case GL_HIGH_FLOAT:
4574 mCaps.fragmentHighpFloat.get(range, precision);
4575 break;
4576
4577 case GL_LOW_INT:
4578 mCaps.fragmentLowpInt.get(range, precision);
4579 break;
4580 case GL_MEDIUM_INT:
4581 mCaps.fragmentMediumpInt.get(range, precision);
4582 break;
4583 case GL_HIGH_INT:
4584 mCaps.fragmentHighpInt.get(range, precision);
4585 break;
4586
4587 default:
4588 UNREACHABLE();
4589 return;
4590 }
4591 break;
4592
4593 default:
4594 UNREACHABLE();
4595 return;
4596 }
4597}
4598
4599void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
4600{
4601 Shader *shaderObject = getShader(shader);
4602 ASSERT(shaderObject);
4603 shaderObject->getSource(bufsize, length, source);
4604}
4605
4606void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
4607{
4608 Program *programObject = getProgram(program);
4609 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04004610 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004611}
4612
4613void Context::getUniformiv(GLuint program, GLint location, GLint *params)
4614{
4615 Program *programObject = getProgram(program);
4616 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04004617 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004618}
4619
4620GLint Context::getUniformLocation(GLuint program, const GLchar *name)
4621{
4622 Program *programObject = getProgram(program);
4623 ASSERT(programObject);
4624 return programObject->getUniformLocation(name);
4625}
4626
4627GLboolean Context::isBuffer(GLuint buffer)
4628{
4629 if (buffer == 0)
4630 {
4631 return GL_FALSE;
4632 }
4633
4634 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
4635}
4636
4637GLboolean Context::isEnabled(GLenum cap)
4638{
4639 return mGLState.getEnableFeature(cap);
4640}
4641
4642GLboolean Context::isFramebuffer(GLuint framebuffer)
4643{
4644 if (framebuffer == 0)
4645 {
4646 return GL_FALSE;
4647 }
4648
4649 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
4650}
4651
4652GLboolean Context::isProgram(GLuint program)
4653{
4654 if (program == 0)
4655 {
4656 return GL_FALSE;
4657 }
4658
4659 return (getProgram(program) ? GL_TRUE : GL_FALSE);
4660}
4661
4662GLboolean Context::isRenderbuffer(GLuint renderbuffer)
4663{
4664 if (renderbuffer == 0)
4665 {
4666 return GL_FALSE;
4667 }
4668
4669 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
4670}
4671
4672GLboolean Context::isShader(GLuint shader)
4673{
4674 if (shader == 0)
4675 {
4676 return GL_FALSE;
4677 }
4678
4679 return (getShader(shader) ? GL_TRUE : GL_FALSE);
4680}
4681
4682GLboolean Context::isTexture(GLuint texture)
4683{
4684 if (texture == 0)
4685 {
4686 return GL_FALSE;
4687 }
4688
4689 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
4690}
4691
4692void Context::linkProgram(GLuint program)
4693{
4694 Program *programObject = getProgram(program);
4695 ASSERT(programObject);
4696 handleError(programObject->link(this));
Martin Radev0abb7a22017-08-28 15:34:45 +03004697 mGLState.onProgramExecutableChange(programObject);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004698}
4699
4700void Context::releaseShaderCompiler()
4701{
Jamie Madill4928b7c2017-06-20 12:57:39 -04004702 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004703}
4704
4705void Context::shaderBinary(GLsizei n,
4706 const GLuint *shaders,
4707 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04004708 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04004709 GLsizei length)
4710{
4711 // No binary shader formats are supported.
4712 UNIMPLEMENTED();
4713}
4714
4715void Context::shaderSource(GLuint shader,
4716 GLsizei count,
4717 const GLchar *const *string,
4718 const GLint *length)
4719{
4720 Shader *shaderObject = getShader(shader);
4721 ASSERT(shaderObject);
4722 shaderObject->setSource(count, string, length);
4723}
4724
4725void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
4726{
4727 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
4728}
4729
4730void Context::stencilMask(GLuint mask)
4731{
4732 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
4733}
4734
4735void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
4736{
4737 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
4738}
4739
4740void Context::uniform1f(GLint location, GLfloat x)
4741{
4742 Program *program = mGLState.getProgram();
4743 program->setUniform1fv(location, 1, &x);
4744}
4745
4746void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
4747{
4748 Program *program = mGLState.getProgram();
4749 program->setUniform1fv(location, count, v);
4750}
4751
4752void Context::uniform1i(GLint location, GLint x)
4753{
4754 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04004755 if (program->setUniform1iv(location, 1, &x) == Program::SetUniformResult::SamplerChanged)
4756 {
4757 mGLState.setObjectDirty(GL_PROGRAM);
4758 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04004759}
4760
4761void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
4762{
4763 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04004764 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
4765 {
4766 mGLState.setObjectDirty(GL_PROGRAM);
4767 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04004768}
4769
4770void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
4771{
4772 GLfloat xy[2] = {x, y};
4773 Program *program = mGLState.getProgram();
4774 program->setUniform2fv(location, 1, xy);
4775}
4776
4777void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
4778{
4779 Program *program = mGLState.getProgram();
4780 program->setUniform2fv(location, count, v);
4781}
4782
4783void Context::uniform2i(GLint location, GLint x, GLint y)
4784{
4785 GLint xy[2] = {x, y};
4786 Program *program = mGLState.getProgram();
4787 program->setUniform2iv(location, 1, xy);
4788}
4789
4790void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
4791{
4792 Program *program = mGLState.getProgram();
4793 program->setUniform2iv(location, count, v);
4794}
4795
4796void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
4797{
4798 GLfloat xyz[3] = {x, y, z};
4799 Program *program = mGLState.getProgram();
4800 program->setUniform3fv(location, 1, xyz);
4801}
4802
4803void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
4804{
4805 Program *program = mGLState.getProgram();
4806 program->setUniform3fv(location, count, v);
4807}
4808
4809void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
4810{
4811 GLint xyz[3] = {x, y, z};
4812 Program *program = mGLState.getProgram();
4813 program->setUniform3iv(location, 1, xyz);
4814}
4815
4816void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
4817{
4818 Program *program = mGLState.getProgram();
4819 program->setUniform3iv(location, count, v);
4820}
4821
4822void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4823{
4824 GLfloat xyzw[4] = {x, y, z, w};
4825 Program *program = mGLState.getProgram();
4826 program->setUniform4fv(location, 1, xyzw);
4827}
4828
4829void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
4830{
4831 Program *program = mGLState.getProgram();
4832 program->setUniform4fv(location, count, v);
4833}
4834
4835void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
4836{
4837 GLint xyzw[4] = {x, y, z, w};
4838 Program *program = mGLState.getProgram();
4839 program->setUniform4iv(location, 1, xyzw);
4840}
4841
4842void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
4843{
4844 Program *program = mGLState.getProgram();
4845 program->setUniform4iv(location, count, v);
4846}
4847
4848void Context::uniformMatrix2fv(GLint location,
4849 GLsizei count,
4850 GLboolean transpose,
4851 const GLfloat *value)
4852{
4853 Program *program = mGLState.getProgram();
4854 program->setUniformMatrix2fv(location, count, transpose, value);
4855}
4856
4857void Context::uniformMatrix3fv(GLint location,
4858 GLsizei count,
4859 GLboolean transpose,
4860 const GLfloat *value)
4861{
4862 Program *program = mGLState.getProgram();
4863 program->setUniformMatrix3fv(location, count, transpose, value);
4864}
4865
4866void Context::uniformMatrix4fv(GLint location,
4867 GLsizei count,
4868 GLboolean transpose,
4869 const GLfloat *value)
4870{
4871 Program *program = mGLState.getProgram();
4872 program->setUniformMatrix4fv(location, count, transpose, value);
4873}
4874
4875void Context::validateProgram(GLuint program)
4876{
4877 Program *programObject = getProgram(program);
4878 ASSERT(programObject);
4879 programObject->validate(mCaps);
4880}
4881
Jamie Madilld04908b2017-06-09 14:15:35 -04004882void Context::getProgramBinary(GLuint program,
4883 GLsizei bufSize,
4884 GLsizei *length,
4885 GLenum *binaryFormat,
4886 void *binary)
4887{
4888 Program *programObject = getProgram(program);
4889 ASSERT(programObject != nullptr);
4890
4891 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
4892}
4893
4894void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
4895{
4896 Program *programObject = getProgram(program);
4897 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04004898
Jamie Madilld04908b2017-06-09 14:15:35 -04004899 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
4900}
4901
Jamie Madillff325f12017-08-26 15:06:05 -04004902void Context::uniform1ui(GLint location, GLuint v0)
4903{
4904 Program *program = mGLState.getProgram();
4905 program->setUniform1uiv(location, 1, &v0);
4906}
4907
4908void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
4909{
4910 Program *program = mGLState.getProgram();
4911 const GLuint xy[] = {v0, v1};
4912 program->setUniform2uiv(location, 1, xy);
4913}
4914
4915void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
4916{
4917 Program *program = mGLState.getProgram();
4918 const GLuint xyz[] = {v0, v1, v2};
4919 program->setUniform3uiv(location, 1, xyz);
4920}
4921
4922void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
4923{
4924 Program *program = mGLState.getProgram();
4925 const GLuint xyzw[] = {v0, v1, v2, v3};
4926 program->setUniform4uiv(location, 1, xyzw);
4927}
4928
4929void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
4930{
4931 Program *program = mGLState.getProgram();
4932 program->setUniform1uiv(location, count, value);
4933}
4934void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
4935{
4936 Program *program = mGLState.getProgram();
4937 program->setUniform2uiv(location, count, value);
4938}
4939
4940void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
4941{
4942 Program *program = mGLState.getProgram();
4943 program->setUniform3uiv(location, count, value);
4944}
4945
4946void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
4947{
4948 Program *program = mGLState.getProgram();
4949 program->setUniform4uiv(location, count, value);
4950}
4951
Jamie Madillf0e04492017-08-26 15:28:42 -04004952void Context::genQueries(GLsizei n, GLuint *ids)
4953{
4954 for (GLsizei i = 0; i < n; i++)
4955 {
4956 GLuint handle = mQueryHandleAllocator.allocate();
4957 mQueryMap.assign(handle, nullptr);
4958 ids[i] = handle;
4959 }
4960}
4961
4962void Context::deleteQueries(GLsizei n, const GLuint *ids)
4963{
4964 for (int i = 0; i < n; i++)
4965 {
4966 GLuint query = ids[i];
4967
4968 Query *queryObject = nullptr;
4969 if (mQueryMap.erase(query, &queryObject))
4970 {
4971 mQueryHandleAllocator.release(query);
4972 if (queryObject)
4973 {
4974 queryObject->release(this);
4975 }
4976 }
4977 }
4978}
4979
4980GLboolean Context::isQuery(GLuint id)
4981{
4982 return (getQuery(id, false, GL_NONE) != nullptr) ? GL_TRUE : GL_FALSE;
4983}
4984
Jamie Madillc8c95812017-08-26 18:40:09 -04004985void Context::uniformMatrix2x3fv(GLint location,
4986 GLsizei count,
4987 GLboolean transpose,
4988 const GLfloat *value)
4989{
4990 Program *program = mGLState.getProgram();
4991 program->setUniformMatrix2x3fv(location, count, transpose, value);
4992}
4993
4994void Context::uniformMatrix3x2fv(GLint location,
4995 GLsizei count,
4996 GLboolean transpose,
4997 const GLfloat *value)
4998{
4999 Program *program = mGLState.getProgram();
5000 program->setUniformMatrix3x2fv(location, count, transpose, value);
5001}
5002
5003void Context::uniformMatrix2x4fv(GLint location,
5004 GLsizei count,
5005 GLboolean transpose,
5006 const GLfloat *value)
5007{
5008 Program *program = mGLState.getProgram();
5009 program->setUniformMatrix2x4fv(location, count, transpose, value);
5010}
5011
5012void Context::uniformMatrix4x2fv(GLint location,
5013 GLsizei count,
5014 GLboolean transpose,
5015 const GLfloat *value)
5016{
5017 Program *program = mGLState.getProgram();
5018 program->setUniformMatrix4x2fv(location, count, transpose, value);
5019}
5020
5021void Context::uniformMatrix3x4fv(GLint location,
5022 GLsizei count,
5023 GLboolean transpose,
5024 const GLfloat *value)
5025{
5026 Program *program = mGLState.getProgram();
5027 program->setUniformMatrix3x4fv(location, count, transpose, value);
5028}
5029
5030void Context::uniformMatrix4x3fv(GLint location,
5031 GLsizei count,
5032 GLboolean transpose,
5033 const GLfloat *value)
5034{
5035 Program *program = mGLState.getProgram();
5036 program->setUniformMatrix4x3fv(location, count, transpose, value);
5037}
5038
Jamie Madilld7576732017-08-26 18:49:50 -04005039void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
5040{
5041 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5042 {
5043 GLuint vertexArray = arrays[arrayIndex];
5044
5045 if (arrays[arrayIndex] != 0)
5046 {
5047 VertexArray *vertexArrayObject = nullptr;
5048 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
5049 {
5050 if (vertexArrayObject != nullptr)
5051 {
5052 detachVertexArray(vertexArray);
5053 vertexArrayObject->onDestroy(this);
5054 }
5055
5056 mVertexArrayHandleAllocator.release(vertexArray);
5057 }
5058 }
5059 }
5060}
5061
5062void Context::genVertexArrays(GLsizei n, GLuint *arrays)
5063{
5064 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5065 {
5066 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
5067 mVertexArrayMap.assign(vertexArray, nullptr);
5068 arrays[arrayIndex] = vertexArray;
5069 }
5070}
5071
5072bool Context::isVertexArray(GLuint array)
5073{
5074 if (array == 0)
5075 {
5076 return GL_FALSE;
5077 }
5078
5079 VertexArray *vao = getVertexArray(array);
5080 return (vao != nullptr ? GL_TRUE : GL_FALSE);
5081}
5082
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04005083void Context::endTransformFeedback()
5084{
5085 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5086 transformFeedback->end(this);
5087}
5088
5089void Context::transformFeedbackVaryings(GLuint program,
5090 GLsizei count,
5091 const GLchar *const *varyings,
5092 GLenum bufferMode)
5093{
5094 Program *programObject = getProgram(program);
5095 ASSERT(programObject);
5096 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
5097}
5098
5099void Context::getTransformFeedbackVarying(GLuint program,
5100 GLuint index,
5101 GLsizei bufSize,
5102 GLsizei *length,
5103 GLsizei *size,
5104 GLenum *type,
5105 GLchar *name)
5106{
5107 Program *programObject = getProgram(program);
5108 ASSERT(programObject);
5109 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
5110}
5111
5112void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
5113{
5114 for (int i = 0; i < n; i++)
5115 {
5116 GLuint transformFeedback = ids[i];
5117 if (transformFeedback == 0)
5118 {
5119 continue;
5120 }
5121
5122 TransformFeedback *transformFeedbackObject = nullptr;
5123 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
5124 {
5125 if (transformFeedbackObject != nullptr)
5126 {
5127 detachTransformFeedback(transformFeedback);
5128 transformFeedbackObject->release(this);
5129 }
5130
5131 mTransformFeedbackHandleAllocator.release(transformFeedback);
5132 }
5133 }
5134}
5135
5136void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
5137{
5138 for (int i = 0; i < n; i++)
5139 {
5140 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
5141 mTransformFeedbackMap.assign(transformFeedback, nullptr);
5142 ids[i] = transformFeedback;
5143 }
5144}
5145
5146bool Context::isTransformFeedback(GLuint id)
5147{
5148 if (id == 0)
5149 {
5150 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
5151 // returns FALSE
5152 return GL_FALSE;
5153 }
5154
5155 const TransformFeedback *transformFeedback = getTransformFeedback(id);
5156 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
5157}
5158
5159void Context::pauseTransformFeedback()
5160{
5161 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5162 transformFeedback->pause();
5163}
5164
5165void Context::resumeTransformFeedback()
5166{
5167 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5168 transformFeedback->resume();
5169}
5170
Jamie Madill12e957f2017-08-26 21:42:26 -04005171void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
5172{
5173 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04005174 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04005175}
5176
5177GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
5178{
5179 const Program *programObject = getProgram(program);
5180 return programObject->getFragDataLocation(name);
5181}
5182
5183void Context::getUniformIndices(GLuint program,
5184 GLsizei uniformCount,
5185 const GLchar *const *uniformNames,
5186 GLuint *uniformIndices)
5187{
5188 const Program *programObject = getProgram(program);
5189 if (!programObject->isLinked())
5190 {
5191 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5192 {
5193 uniformIndices[uniformId] = GL_INVALID_INDEX;
5194 }
5195 }
5196 else
5197 {
5198 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5199 {
5200 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
5201 }
5202 }
5203}
5204
5205void Context::getActiveUniformsiv(GLuint program,
5206 GLsizei uniformCount,
5207 const GLuint *uniformIndices,
5208 GLenum pname,
5209 GLint *params)
5210{
5211 const Program *programObject = getProgram(program);
5212 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5213 {
5214 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08005215 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04005216 }
5217}
5218
5219GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
5220{
5221 const Program *programObject = getProgram(program);
5222 return programObject->getUniformBlockIndex(uniformBlockName);
5223}
5224
5225void Context::getActiveUniformBlockiv(GLuint program,
5226 GLuint uniformBlockIndex,
5227 GLenum pname,
5228 GLint *params)
5229{
5230 const Program *programObject = getProgram(program);
5231 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
5232}
5233
5234void Context::getActiveUniformBlockName(GLuint program,
5235 GLuint uniformBlockIndex,
5236 GLsizei bufSize,
5237 GLsizei *length,
5238 GLchar *uniformBlockName)
5239{
5240 const Program *programObject = getProgram(program);
5241 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
5242}
5243
5244void Context::uniformBlockBinding(GLuint program,
5245 GLuint uniformBlockIndex,
5246 GLuint uniformBlockBinding)
5247{
5248 Program *programObject = getProgram(program);
5249 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
5250}
5251
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005252GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
5253{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005254 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
5255 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005256
Jamie Madill70b5bb02017-08-28 13:32:37 -04005257 Sync *syncObject = getSync(syncHandle);
5258 Error error = syncObject->set(condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005259 if (error.isError())
5260 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04005261 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005262 handleError(error);
5263 return nullptr;
5264 }
5265
Jamie Madill70b5bb02017-08-28 13:32:37 -04005266 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005267}
5268
5269GLboolean Context::isSync(GLsync sync)
5270{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005271 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005272}
5273
5274GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
5275{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005276 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005277
5278 GLenum result = GL_WAIT_FAILED;
5279 handleError(syncObject->clientWait(flags, timeout, &result));
5280 return result;
5281}
5282
5283void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
5284{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005285 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005286 handleError(syncObject->serverWait(flags, timeout));
5287}
5288
5289void Context::getInteger64v(GLenum pname, GLint64 *params)
5290{
5291 GLenum nativeType = GL_NONE;
5292 unsigned int numParams = 0;
5293 getQueryParameterInfo(pname, &nativeType, &numParams);
5294
5295 if (nativeType == GL_INT_64_ANGLEX)
5296 {
5297 getInteger64vImpl(pname, params);
5298 }
5299 else
5300 {
5301 CastStateValues(this, nativeType, pname, numParams, params);
5302 }
5303}
5304
Jamie Madill3ef140a2017-08-26 23:11:21 -04005305void Context::getBufferParameteri64v(GLenum target, GLenum pname, GLint64 *params)
5306{
5307 Buffer *buffer = mGLState.getTargetBuffer(target);
5308 QueryBufferParameteri64v(buffer, pname, params);
5309}
5310
5311void Context::genSamplers(GLsizei count, GLuint *samplers)
5312{
5313 for (int i = 0; i < count; i++)
5314 {
5315 samplers[i] = mState.mSamplers->createSampler();
5316 }
5317}
5318
5319void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
5320{
5321 for (int i = 0; i < count; i++)
5322 {
5323 GLuint sampler = samplers[i];
5324
5325 if (mState.mSamplers->getSampler(sampler))
5326 {
5327 detachSampler(sampler);
5328 }
5329
5330 mState.mSamplers->deleteObject(this, sampler);
5331 }
5332}
5333
5334void Context::getInternalformativ(GLenum target,
5335 GLenum internalformat,
5336 GLenum pname,
5337 GLsizei bufSize,
5338 GLint *params)
5339{
5340 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
5341 QueryInternalFormativ(formatCaps, pname, bufSize, params);
5342}
5343
Jamie Madill81c2e252017-09-09 23:32:46 -04005344void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5345{
5346 Program *programObject = getProgram(program);
5347 ASSERT(programObject);
5348 if (programObject->setUniform1iv(location, count, value) ==
5349 Program::SetUniformResult::SamplerChanged)
5350 {
5351 mGLState.setObjectDirty(GL_PROGRAM);
5352 }
5353}
5354
5355void Context::onTextureChange(const Texture *texture)
5356{
5357 // Conservatively assume all textures are dirty.
5358 // TODO(jmadill): More fine-grained update.
5359 mGLState.setObjectDirty(GL_TEXTURE);
5360}
5361
Yunchao Hea336b902017-08-02 16:05:21 +08005362void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
5363{
5364 for (int i = 0; i < count; i++)
5365 {
5366 pipelines[i] = createProgramPipeline();
5367 }
5368}
5369
5370void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
5371{
5372 for (int i = 0; i < count; i++)
5373 {
5374 if (pipelines[i] != 0)
5375 {
5376 deleteProgramPipeline(pipelines[i]);
5377 }
5378 }
5379}
5380
5381GLboolean Context::isProgramPipeline(GLuint pipeline)
5382{
5383 if (pipeline == 0)
5384 {
5385 return GL_FALSE;
5386 }
5387
5388 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
5389}
5390
Jamie Madillc29968b2016-01-20 11:17:23 -05005391} // namespace gl