blob: 78f5d84ea492f7d0ae9ce00f1bea8ff71533b208 [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"
Geoff Lang2b5420c2014-11-19 14:20:15 -050029#include "libANGLE/Query.h"
Jamie Madillb9293972015-02-19 11:07:54 -050030#include "libANGLE/Renderbuffer.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050031#include "libANGLE/ResourceManager.h"
32#include "libANGLE/Sampler.h"
Jamie Madill9dd0cf02014-11-24 11:38:51 -050033#include "libANGLE/Surface.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050034#include "libANGLE/Texture.h"
35#include "libANGLE/TransformFeedback.h"
36#include "libANGLE/VertexArray.h"
Kenneth Russellf2f6f652016-10-05 19:53:23 -070037#include "libANGLE/Workarounds.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040038#include "libANGLE/formatutils.h"
Martin Radev66fb8202016-07-28 11:45:20 +030039#include "libANGLE/queryconversions.h"
Geoff Langc1984ed2016-10-07 12:41:00 -040040#include "libANGLE/queryutils.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040041#include "libANGLE/renderer/ContextImpl.h"
42#include "libANGLE/renderer/EGLImplFactory.h"
43#include "libANGLE/validationES.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000044
Geoff Langf6db0982015-08-25 13:04:00 -040045namespace
46{
47
Ian Ewell3ffd78b2016-01-22 16:09:42 -050048template <typename T>
Geoff Lang4ddf5af2016-12-01 14:30:44 -050049std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager,
Sami Väisänend59ca052016-06-21 16:10:00 +030050 GLsizei numPaths,
51 const void *paths,
52 GLuint pathBase)
53{
54 std::vector<gl::Path *> ret;
55 ret.reserve(numPaths);
56
57 const auto *nameArray = static_cast<const T *>(paths);
58
59 for (GLsizei i = 0; i < numPaths; ++i)
60 {
61 const GLuint pathName = nameArray[i] + pathBase;
62
63 ret.push_back(resourceManager.getPath(pathName));
64 }
65
66 return ret;
67}
68
Geoff Lang4ddf5af2016-12-01 14:30:44 -050069std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager,
Sami Väisänend59ca052016-06-21 16:10:00 +030070 GLsizei numPaths,
71 GLenum pathNameType,
72 const void *paths,
73 GLuint pathBase)
74{
75 switch (pathNameType)
76 {
77 case GL_UNSIGNED_BYTE:
78 return GatherPaths<GLubyte>(resourceManager, numPaths, paths, pathBase);
79
80 case GL_BYTE:
81 return GatherPaths<GLbyte>(resourceManager, numPaths, paths, pathBase);
82
83 case GL_UNSIGNED_SHORT:
84 return GatherPaths<GLushort>(resourceManager, numPaths, paths, pathBase);
85
86 case GL_SHORT:
87 return GatherPaths<GLshort>(resourceManager, numPaths, paths, pathBase);
88
89 case GL_UNSIGNED_INT:
90 return GatherPaths<GLuint>(resourceManager, numPaths, paths, pathBase);
91
92 case GL_INT:
93 return GatherPaths<GLint>(resourceManager, numPaths, paths, pathBase);
94 }
95
96 UNREACHABLE();
97 return std::vector<gl::Path *>();
98}
99
100template <typename T>
Geoff Lang2186c382016-10-14 10:54:54 -0400101gl::Error GetQueryObjectParameter(gl::Query *query, GLenum pname, T *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500102{
Geoff Lang2186c382016-10-14 10:54:54 -0400103 ASSERT(query != nullptr);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500104
105 switch (pname)
106 {
107 case GL_QUERY_RESULT_EXT:
Geoff Lang2186c382016-10-14 10:54:54 -0400108 return query->getResult(params);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500109 case GL_QUERY_RESULT_AVAILABLE_EXT:
110 {
111 bool available;
Geoff Lang2186c382016-10-14 10:54:54 -0400112 gl::Error error = query->isResultAvailable(&available);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500113 if (!error.isError())
114 {
Geoff Lang2186c382016-10-14 10:54:54 -0400115 *params = gl::ConvertFromGLboolean<T>(available);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500116 }
117 return error;
118 }
119 default:
120 UNREACHABLE();
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500121 return gl::InternalError() << "Unreachable Error";
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500122 }
123}
124
Geoff Langf6db0982015-08-25 13:04:00 -0400125void MarkTransformFeedbackBufferUsage(gl::TransformFeedback *transformFeedback)
126{
Geoff Lang1a683462015-09-29 15:09:59 -0400127 if (transformFeedback && transformFeedback->isActive() && !transformFeedback->isPaused())
Geoff Langf6db0982015-08-25 13:04:00 -0400128 {
129 for (size_t tfBufferIndex = 0; tfBufferIndex < transformFeedback->getIndexedBufferCount();
130 tfBufferIndex++)
131 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400132 const gl::OffsetBindingPointer<gl::Buffer> &buffer =
Geoff Langf6db0982015-08-25 13:04:00 -0400133 transformFeedback->getIndexedBuffer(tfBufferIndex);
134 if (buffer.get() != nullptr)
135 {
136 buffer->onTransformFeedback();
137 }
138 }
139 }
140}
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500141
142// Attribute map queries.
Martin Radev1be913c2016-07-11 17:59:16 +0300143EGLint GetClientMajorVersion(const egl::AttributeMap &attribs)
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500144{
Ian Ewellec2c0c52016-04-05 13:46:26 -0400145 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_CLIENT_VERSION, 1));
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500146}
147
Martin Radev1be913c2016-07-11 17:59:16 +0300148EGLint GetClientMinorVersion(const egl::AttributeMap &attribs)
149{
150 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_MINOR_VERSION, 0));
151}
152
Geoff Langeb66a6e2016-10-31 13:06:12 -0400153gl::Version GetClientVersion(const egl::AttributeMap &attribs)
154{
155 return gl::Version(GetClientMajorVersion(attribs), GetClientMinorVersion(attribs));
156}
157
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500158GLenum GetResetStrategy(const egl::AttributeMap &attribs)
159{
Ian Ewellec2c0c52016-04-05 13:46:26 -0400160 EGLAttrib attrib = attribs.get(EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT,
161 EGL_NO_RESET_NOTIFICATION_EXT);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500162 switch (attrib)
163 {
164 case EGL_NO_RESET_NOTIFICATION:
165 return GL_NO_RESET_NOTIFICATION_EXT;
166 case EGL_LOSE_CONTEXT_ON_RESET:
167 return GL_LOSE_CONTEXT_ON_RESET_EXT;
168 default:
169 UNREACHABLE();
170 return GL_NONE;
171 }
172}
173
174bool GetRobustAccess(const egl::AttributeMap &attribs)
175{
Geoff Lang077f20a2016-11-01 10:08:02 -0400176 return (attribs.get(EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT, EGL_FALSE) == EGL_TRUE) ||
177 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR) !=
178 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500179}
180
181bool GetDebug(const egl::AttributeMap &attribs)
182{
Geoff Lang077f20a2016-11-01 10:08:02 -0400183 return (attribs.get(EGL_CONTEXT_OPENGL_DEBUG, EGL_FALSE) == EGL_TRUE) ||
184 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR) != 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500185}
186
187bool GetNoError(const egl::AttributeMap &attribs)
188{
189 return (attribs.get(EGL_CONTEXT_OPENGL_NO_ERROR_KHR, EGL_FALSE) == EGL_TRUE);
190}
191
Geoff Langc287ea62016-09-16 14:46:51 -0400192bool GetWebGLContext(const egl::AttributeMap &attribs)
193{
194 return (attribs.get(EGL_CONTEXT_WEBGL_COMPATIBILITY_ANGLE, EGL_FALSE) == EGL_TRUE);
195}
196
Geoff Langf41a7152016-09-19 15:11:17 -0400197bool GetBindGeneratesResource(const egl::AttributeMap &attribs)
198{
199 return (attribs.get(EGL_CONTEXT_BIND_GENERATES_RESOURCE_CHROMIUM, EGL_TRUE) == EGL_TRUE);
200}
201
Geoff Langfeb8c682017-02-13 16:07:35 -0500202bool GetClientArraysEnabled(const egl::AttributeMap &attribs)
203{
204 return (attribs.get(EGL_CONTEXT_CLIENT_ARRAYS_ENABLED_ANGLE, EGL_TRUE) == EGL_TRUE);
205}
206
Martin Radev9d901792016-07-15 15:58:58 +0300207std::string GetObjectLabelFromPointer(GLsizei length, const GLchar *label)
208{
209 std::string labelName;
210 if (label != nullptr)
211 {
212 size_t labelLength = length < 0 ? strlen(label) : length;
213 labelName = std::string(label, labelLength);
214 }
215 return labelName;
216}
217
218void GetObjectLabelBase(const std::string &objectLabel,
219 GLsizei bufSize,
220 GLsizei *length,
221 GLchar *label)
222{
223 size_t writeLength = objectLabel.length();
224 if (label != nullptr && bufSize > 0)
225 {
226 writeLength = std::min(static_cast<size_t>(bufSize) - 1, objectLabel.length());
227 std::copy(objectLabel.begin(), objectLabel.begin() + writeLength, label);
228 label[writeLength] = '\0';
229 }
230
231 if (length != nullptr)
232 {
233 *length = static_cast<GLsizei>(writeLength);
234 }
235}
236
Geoff Langf6db0982015-08-25 13:04:00 -0400237} // anonymous namespace
238
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000239namespace gl
240{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +0000241
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400242Context::Context(rx::EGLImplFactory *implFactory,
243 const egl::Config *config,
Corentin Wallez51706ea2015-08-07 14:39:22 -0400244 const Context *shareContext,
Geoff Langce02f082017-02-06 16:46:21 -0500245 TextureManager *shareTextures,
Jamie Madill32447362017-06-28 14:53:52 -0400246 MemoryProgramCache *memoryProgramCache,
Corentin Wallezc295e512017-01-27 17:47:50 -0500247 const egl::AttributeMap &attribs,
Jamie Madill948bbe52017-06-01 13:10:42 -0400248 const egl::DisplayExtensions &displayExtensions,
249 bool robustResourceInit)
Martin Radev1be913c2016-07-11 17:59:16 +0300250
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500251 : ValidationContext(shareContext,
Geoff Langce02f082017-02-06 16:46:21 -0500252 shareTextures,
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500253 GetClientVersion(attribs),
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700254 &mGLState,
Jamie Madillf25855c2015-11-03 11:06:18 -0500255 mCaps,
256 mTextureCaps,
257 mExtensions,
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500258 mLimitations,
259 GetNoError(attribs)),
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700260 mImplementation(implFactory->createContext(mState)),
Jamie Madill2f348d22017-06-05 10:50:59 -0400261 mCompiler(),
Corentin Walleze3b10e82015-05-20 11:06:25 -0400262 mConfig(config),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500263 mClientType(EGL_OPENGL_ES_API),
264 mHasBeenCurrent(false),
265 mContextLost(false),
266 mResetStatus(GL_NO_ERROR),
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700267 mContextLostForced(false),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500268 mResetStrategy(GetResetStrategy(attribs)),
269 mRobustAccess(GetRobustAccess(attribs)),
Jamie Madill61e16b42017-06-19 11:13:23 -0400270 mCurrentSurface(static_cast<egl::Surface *>(EGL_NO_SURFACE)),
271 mCurrentDisplay(static_cast<egl::Display *>(EGL_NO_DISPLAY)),
Jamie Madill4e0e6f82017-02-17 11:06:03 -0500272 mSurfacelessFramebuffer(nullptr),
Jamie Madille14951e2017-03-09 18:55:16 -0500273 mWebGLContext(GetWebGLContext(attribs)),
Jamie Madill32447362017-06-28 14:53:52 -0400274 mMemoryProgramCache(memoryProgramCache),
Jamie Madille14951e2017-03-09 18:55:16 -0500275 mScratchBuffer(1000u)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000276{
Geoff Lang077f20a2016-11-01 10:08:02 -0400277 if (mRobustAccess)
278 {
279 UNIMPLEMENTED();
280 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000281
Jamie Madill4e0e6f82017-02-17 11:06:03 -0500282 initCaps(displayExtensions);
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700283 initWorkarounds();
Geoff Langc0b9ef42014-07-02 10:02:37 -0400284
Jamie Madill4928b7c2017-06-20 12:57:39 -0400285 mGLState.initialize(this, GetDebug(attribs), GetBindGeneratesResource(attribs),
Jamie Madillc43be722017-07-13 16:22:14 -0400286 GetClientArraysEnabled(attribs), robustResourceInit,
287 mMemoryProgramCache != nullptr);
Régis Fénéon83107972015-02-05 12:57:44 +0100288
Shannon Woods53a94a82014-06-24 15:20:36 -0400289 mFenceNVHandleAllocator.setBaseHandle(0);
Geoff Lang7dca1862013-07-30 16:30:46 -0400290
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000291 // [OpenGL ES 2.0.24] section 3.7 page 83:
292 // In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have twodimensional
293 // and cube map texture state vectors respectively associated with them.
294 // In order that access to these initial textures not be lost, they are treated as texture
295 // objects all of whose names are 0.
296
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400297 Texture *zeroTexture2D = new Texture(mImplementation.get(), 0, GL_TEXTURE_2D);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400298 mZeroTextures[GL_TEXTURE_2D].set(this, zeroTexture2D);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500299
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400300 Texture *zeroTextureCube = new Texture(mImplementation.get(), 0, GL_TEXTURE_CUBE_MAP);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400301 mZeroTextures[GL_TEXTURE_CUBE_MAP].set(this, zeroTextureCube);
Geoff Lang76b10c92014-09-05 16:28:14 -0400302
Geoff Langeb66a6e2016-10-31 13:06:12 -0400303 if (getClientVersion() >= Version(3, 0))
Geoff Lang76b10c92014-09-05 16:28:14 -0400304 {
305 // TODO: These could also be enabled via extension
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400306 Texture *zeroTexture3D = new Texture(mImplementation.get(), 0, GL_TEXTURE_3D);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400307 mZeroTextures[GL_TEXTURE_3D].set(this, zeroTexture3D);
Geoff Lang76b10c92014-09-05 16:28:14 -0400308
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400309 Texture *zeroTexture2DArray = new Texture(mImplementation.get(), 0, GL_TEXTURE_2D_ARRAY);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400310 mZeroTextures[GL_TEXTURE_2D_ARRAY].set(this, zeroTexture2DArray);
Geoff Lang76b10c92014-09-05 16:28:14 -0400311 }
Geoff Lang3b573612016-10-31 14:08:10 -0400312 if (getClientVersion() >= Version(3, 1))
313 {
314 Texture *zeroTexture2DMultisample =
315 new Texture(mImplementation.get(), 0, GL_TEXTURE_2D_MULTISAMPLE);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400316 mZeroTextures[GL_TEXTURE_2D_MULTISAMPLE].set(this, zeroTexture2DMultisample);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800317
318 bindGenericAtomicCounterBuffer(0);
319 for (unsigned int i = 0; i < mCaps.maxAtomicCounterBufferBindings; i++)
320 {
321 bindIndexedAtomicCounterBuffer(0, i, 0, 0);
322 }
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800323
324 bindGenericShaderStorageBuffer(0);
325 for (unsigned int i = 0; i < mCaps.maxShaderStorageBufferBindings; i++)
326 {
327 bindIndexedShaderStorageBuffer(0, i, 0, 0);
328 }
Geoff Lang3b573612016-10-31 14:08:10 -0400329 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000330
Ian Ewellbda75592016-04-18 17:25:54 -0400331 if (mExtensions.eglImageExternal || mExtensions.eglStreamConsumerExternal)
332 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400333 Texture *zeroTextureExternal =
334 new Texture(mImplementation.get(), 0, GL_TEXTURE_EXTERNAL_OES);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400335 mZeroTextures[GL_TEXTURE_EXTERNAL_OES].set(this, zeroTextureExternal);
Ian Ewellbda75592016-04-18 17:25:54 -0400336 }
337
Jamie Madill4928b7c2017-06-20 12:57:39 -0400338 mGLState.initializeZeroTextures(this, mZeroTextures);
Jamie Madille6382c32014-11-07 15:05:26 -0500339
Jamie Madill57a89722013-07-02 11:57:03 -0400340 bindVertexArray(0);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000341 bindArrayBuffer(0);
Jiajia Qin9d7d0b12016-11-29 16:30:31 +0800342 bindDrawIndirectBuffer(0);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000343 bindElementArrayBuffer(0);
Geoff Lang76b10c92014-09-05 16:28:14 -0400344
Jamie Madill01a80ee2016-11-07 12:06:18 -0500345 bindRenderbuffer(GL_RENDERBUFFER, 0);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000346
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +0000347 bindGenericUniformBuffer(0);
Geoff Lang4dc3af02016-11-18 14:09:27 -0500348 for (unsigned int i = 0; i < mCaps.maxUniformBufferBindings; i++)
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +0000349 {
350 bindIndexedUniformBuffer(0, i, 0, -1);
351 }
352
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000353 bindCopyReadBuffer(0);
354 bindCopyWriteBuffer(0);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +0000355 bindPixelPackBuffer(0);
356 bindPixelUnpackBuffer(0);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000357
Geoff Langeb66a6e2016-10-31 13:06:12 -0400358 if (getClientVersion() >= Version(3, 0))
Geoff Lang1a683462015-09-29 15:09:59 -0400359 {
360 // [OpenGL ES 3.0.2] section 2.14.1 pg 85:
361 // In the initial state, a default transform feedback object is bound and treated as
362 // a transform feedback object with a name of zero. That object is bound any time
363 // BindTransformFeedback is called with id of zero
Geoff Lang1a683462015-09-29 15:09:59 -0400364 bindTransformFeedback(0);
365 }
Geoff Langc8058452014-02-03 12:04:11 -0500366
Jamie Madillad9f24e2016-02-12 09:27:24 -0500367 // Initialize dirty bit masks
368 // TODO(jmadill): additional ES3 state
369 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_ALIGNMENT);
370 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_ROW_LENGTH);
371 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_IMAGE_HEIGHT);
372 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_SKIP_IMAGES);
373 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_SKIP_ROWS);
374 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_SKIP_PIXELS);
Corentin Wallezbbd663a2016-04-20 17:49:17 -0400375 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500376 // No dirty objects.
377
378 // Readpixels uses the pack state and read FBO
379 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_ALIGNMENT);
380 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_REVERSE_ROW_ORDER);
381 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_ROW_LENGTH);
382 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_SKIP_ROWS);
383 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_SKIP_PIXELS);
Corentin Wallezbbd663a2016-04-20 17:49:17 -0400384 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500385 mReadPixelsDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
386
387 mClearDirtyBits.set(State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED);
388 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
389 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR);
390 mClearDirtyBits.set(State::DIRTY_BIT_VIEWPORT);
391 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_COLOR);
392 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_DEPTH);
393 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_STENCIL);
394 mClearDirtyBits.set(State::DIRTY_BIT_COLOR_MASK);
395 mClearDirtyBits.set(State::DIRTY_BIT_DEPTH_MASK);
396 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT);
397 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_BACK);
398 mClearDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
399
400 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
401 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR);
Geoff Lang1d2c41d2016-10-19 16:14:46 -0700402 mBlitDirtyBits.set(State::DIRTY_BIT_FRAMEBUFFER_SRGB);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500403 mBlitDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
404 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
Jamie Madill437fa652016-05-03 15:13:24 -0400405
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400406 handleError(mImplementation->initialize());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000407}
408
Jamie Madill4928b7c2017-06-20 12:57:39 -0400409egl::Error Context::onDestroy(const egl::Display *display)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000410{
Corentin Wallez80b24112015-08-25 16:41:57 -0400411 for (auto fence : mFenceNVMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000412 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400413 SafeDelete(fence.second);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000414 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400415 mFenceNVMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000416
Corentin Wallez80b24112015-08-25 16:41:57 -0400417 for (auto query : mQueryMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000418 {
Geoff Langf0aa8422015-09-29 15:08:34 -0400419 if (query.second != nullptr)
420 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400421 query.second->release(this);
Geoff Langf0aa8422015-09-29 15:08:34 -0400422 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000423 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400424 mQueryMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000425
Corentin Wallez80b24112015-08-25 16:41:57 -0400426 for (auto vertexArray : mVertexArrayMap)
Jamie Madill57a89722013-07-02 11:57:03 -0400427 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400428 if (vertexArray.second)
429 {
430 vertexArray.second->onDestroy(this);
431 }
Jamie Madill57a89722013-07-02 11:57:03 -0400432 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400433 mVertexArrayMap.clear();
Jamie Madill57a89722013-07-02 11:57:03 -0400434
Corentin Wallez80b24112015-08-25 16:41:57 -0400435 for (auto transformFeedback : mTransformFeedbackMap)
Geoff Langc8058452014-02-03 12:04:11 -0500436 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500437 if (transformFeedback.second != nullptr)
438 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500439 transformFeedback.second->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500440 }
Geoff Langc8058452014-02-03 12:04:11 -0500441 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400442 mTransformFeedbackMap.clear();
Geoff Langc8058452014-02-03 12:04:11 -0500443
Jamie Madilldedd7b92014-11-05 16:30:36 -0500444 for (auto &zeroTexture : mZeroTextures)
Geoff Lang76b10c92014-09-05 16:28:14 -0400445 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400446 zeroTexture.second->onDestroy(this);
447 zeroTexture.second.set(this, nullptr);
Geoff Lang76b10c92014-09-05 16:28:14 -0400448 }
449 mZeroTextures.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000450
Corentin Wallezccab69d2017-01-27 16:57:15 -0500451 SafeDelete(mSurfacelessFramebuffer);
452
Jamie Madill4928b7c2017-06-20 12:57:39 -0400453 ANGLE_TRY(releaseSurface(display));
Jamie Madill2f348d22017-06-05 10:50:59 -0400454 releaseShaderCompiler();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500455
Jamie Madill4928b7c2017-06-20 12:57:39 -0400456 mGLState.reset(this);
457
Jamie Madill6c1f6712017-02-14 19:08:04 -0500458 mState.mBuffers->release(this);
459 mState.mShaderPrograms->release(this);
460 mState.mTextures->release(this);
461 mState.mRenderbuffers->release(this);
462 mState.mSamplers->release(this);
463 mState.mFenceSyncs->release(this);
464 mState.mPaths->release(this);
465 mState.mFramebuffers->release(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400466
467 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000468}
469
Jamie Madill70ee0f62017-02-06 16:04:20 -0500470Context::~Context()
471{
472}
473
Jamie Madill4928b7c2017-06-20 12:57:39 -0400474egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000475{
Jamie Madill61e16b42017-06-19 11:13:23 -0400476 mCurrentDisplay = display;
477
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000478 if (!mHasBeenCurrent)
479 {
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000480 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500481 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400482 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000483
Corentin Wallezc295e512017-01-27 17:47:50 -0500484 int width = 0;
485 int height = 0;
486 if (surface != nullptr)
487 {
488 width = surface->getWidth();
489 height = surface->getHeight();
490 }
491
492 mGLState.setViewportParams(0, 0, width, height);
493 mGLState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000494
495 mHasBeenCurrent = true;
496 }
497
Jamie Madill1b94d432015-08-07 13:23:23 -0400498 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700499 mGLState.setAllDirtyBits();
Jamie Madill1b94d432015-08-07 13:23:23 -0400500
Jamie Madill4928b7c2017-06-20 12:57:39 -0400501 ANGLE_TRY(releaseSurface(display));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500502
503 Framebuffer *newDefault = nullptr;
504 if (surface != nullptr)
505 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400506 ANGLE_TRY(surface->setIsCurrent(this, true));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500507 mCurrentSurface = surface;
508 newDefault = surface->getDefaultFramebuffer();
509 }
510 else
511 {
512 if (mSurfacelessFramebuffer == nullptr)
513 {
514 mSurfacelessFramebuffer = new Framebuffer(mImplementation.get());
515 }
516
517 newDefault = mSurfacelessFramebuffer;
518 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000519
Corentin Wallez37c39792015-08-20 14:19:46 -0400520 // Update default framebuffer, the binding of the previous default
521 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400522 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700523 if (mGLState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400524 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700525 mGLState.setReadFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400526 }
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700527 if (mGLState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400528 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700529 mGLState.setDrawFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400530 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500531 mState.mFramebuffers->setDefaultFramebuffer(newDefault);
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400532 }
Ian Ewell292f0052016-02-04 10:37:32 -0500533
534 // Notify the renderer of a context switch
Jamie Madill4928b7c2017-06-20 12:57:39 -0400535 mImplementation->onMakeCurrent(this);
536 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000537}
538
Jamie Madill4928b7c2017-06-20 12:57:39 -0400539egl::Error Context::releaseSurface(const egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400540{
Corentin Wallez37c39792015-08-20 14:19:46 -0400541 // Remove the default framebuffer
Corentin Wallezc295e512017-01-27 17:47:50 -0500542 Framebuffer *currentDefault = nullptr;
543 if (mCurrentSurface != nullptr)
Corentin Wallez51706ea2015-08-07 14:39:22 -0400544 {
Corentin Wallezc295e512017-01-27 17:47:50 -0500545 currentDefault = mCurrentSurface->getDefaultFramebuffer();
546 }
547 else if (mSurfacelessFramebuffer != nullptr)
548 {
549 currentDefault = mSurfacelessFramebuffer;
Corentin Wallez51706ea2015-08-07 14:39:22 -0400550 }
551
Corentin Wallezc295e512017-01-27 17:47:50 -0500552 if (mGLState.getReadFramebuffer() == currentDefault)
553 {
554 mGLState.setReadFramebufferBinding(nullptr);
555 }
556 if (mGLState.getDrawFramebuffer() == currentDefault)
557 {
558 mGLState.setDrawFramebufferBinding(nullptr);
559 }
560 mState.mFramebuffers->setDefaultFramebuffer(nullptr);
561
562 if (mCurrentSurface)
563 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400564 ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
Corentin Wallezc295e512017-01-27 17:47:50 -0500565 mCurrentSurface = nullptr;
566 }
Jamie Madill4928b7c2017-06-20 12:57:39 -0400567
568 return egl::NoError();
Jamie Madill77a72f62015-04-14 11:18:32 -0400569}
570
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000571GLuint Context::createBuffer()
572{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500573 return mState.mBuffers->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000574}
575
576GLuint Context::createProgram()
577{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500578 return mState.mShaderPrograms->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000579}
580
581GLuint Context::createShader(GLenum type)
582{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500583 return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000584}
585
586GLuint Context::createTexture()
587{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500588 return mState.mTextures->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000589}
590
591GLuint Context::createRenderbuffer()
592{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500593 return mState.mRenderbuffers->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000594}
595
Geoff Lang882033e2014-09-30 11:26:07 -0400596GLsync Context::createFenceSync()
Jamie Madillcd055f82013-07-26 11:55:15 -0400597{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500598 GLuint handle = mState.mFenceSyncs->createFenceSync(mImplementation.get());
Jamie Madillcd055f82013-07-26 11:55:15 -0400599
Cooper Partind8e62a32015-01-29 15:21:25 -0800600 return reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madillcd055f82013-07-26 11:55:15 -0400601}
602
Sami Väisänene45e53b2016-05-25 10:36:04 +0300603GLuint Context::createPaths(GLsizei range)
604{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500605 auto resultOrError = mState.mPaths->createPaths(mImplementation.get(), range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300606 if (resultOrError.isError())
607 {
608 handleError(resultOrError.getError());
609 return 0;
610 }
611 return resultOrError.getResult();
612}
613
Jamie Madill57a89722013-07-02 11:57:03 -0400614GLuint Context::createVertexArray()
615{
Jamie Madill96a483b2017-06-27 16:49:21 -0400616 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
617 mVertexArrayMap.assign(vertexArray, nullptr);
Geoff Lang36167ab2015-12-07 10:27:14 -0500618 return vertexArray;
Jamie Madill57a89722013-07-02 11:57:03 -0400619}
620
Jamie Madilldc356042013-07-19 16:36:57 -0400621GLuint Context::createSampler()
622{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500623 return mState.mSamplers->createSampler();
Jamie Madilldc356042013-07-19 16:36:57 -0400624}
625
Geoff Langc8058452014-02-03 12:04:11 -0500626GLuint Context::createTransformFeedback()
627{
Jamie Madill96a483b2017-06-27 16:49:21 -0400628 GLuint transformFeedback = mTransformFeedbackAllocator.allocate();
629 mTransformFeedbackMap.assign(transformFeedback, nullptr);
Geoff Lang36167ab2015-12-07 10:27:14 -0500630 return transformFeedback;
Geoff Langc8058452014-02-03 12:04:11 -0500631}
632
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000633// Returns an unused framebuffer name
634GLuint Context::createFramebuffer()
635{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500636 return mState.mFramebuffers->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000637}
638
Jamie Madill33dc8432013-07-26 11:55:05 -0400639GLuint Context::createFenceNV()
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000640{
Jamie Madill33dc8432013-07-26 11:55:05 -0400641 GLuint handle = mFenceNVHandleAllocator.allocate();
Jamie Madill96a483b2017-06-27 16:49:21 -0400642 mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV()));
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000643 return handle;
644}
645
646// Returns an unused query name
647GLuint Context::createQuery()
648{
649 GLuint handle = mQueryHandleAllocator.allocate();
Jamie Madill96a483b2017-06-27 16:49:21 -0400650 mQueryMap.assign(handle, nullptr);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000651 return handle;
652}
653
654void Context::deleteBuffer(GLuint buffer)
655{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500656 if (mState.mBuffers->getBuffer(buffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000657 {
658 detachBuffer(buffer);
659 }
Jamie Madill893ab082014-05-16 16:56:10 -0400660
Jamie Madill6c1f6712017-02-14 19:08:04 -0500661 mState.mBuffers->deleteObject(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000662}
663
664void Context::deleteShader(GLuint shader)
665{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500666 mState.mShaderPrograms->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000667}
668
669void Context::deleteProgram(GLuint program)
670{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500671 mState.mShaderPrograms->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000672}
673
674void Context::deleteTexture(GLuint texture)
675{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500676 if (mState.mTextures->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000677 {
678 detachTexture(texture);
679 }
680
Jamie Madill6c1f6712017-02-14 19:08:04 -0500681 mState.mTextures->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000682}
683
684void Context::deleteRenderbuffer(GLuint renderbuffer)
685{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500686 if (mState.mRenderbuffers->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000687 {
688 detachRenderbuffer(renderbuffer);
689 }
Jamie Madill893ab082014-05-16 16:56:10 -0400690
Jamie Madill6c1f6712017-02-14 19:08:04 -0500691 mState.mRenderbuffers->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000692}
693
Jamie Madillcd055f82013-07-26 11:55:15 -0400694void Context::deleteFenceSync(GLsync fenceSync)
695{
696 // The spec specifies the underlying Fence object is not deleted until all current
697 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
698 // and since our API is currently designed for being called from a single thread, we can delete
699 // the fence immediately.
Jamie Madill6c1f6712017-02-14 19:08:04 -0500700 mState.mFenceSyncs->deleteObject(this,
701 static_cast<GLuint>(reinterpret_cast<uintptr_t>(fenceSync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400702}
703
Sami Väisänene45e53b2016-05-25 10:36:04 +0300704void Context::deletePaths(GLuint first, GLsizei range)
705{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500706 mState.mPaths->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300707}
708
709bool Context::hasPathData(GLuint path) const
710{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500711 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300712 if (pathObj == nullptr)
713 return false;
714
715 return pathObj->hasPathData();
716}
717
718bool Context::hasPath(GLuint path) const
719{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500720 return mState.mPaths->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300721}
722
723void Context::setPathCommands(GLuint path,
724 GLsizei numCommands,
725 const GLubyte *commands,
726 GLsizei numCoords,
727 GLenum coordType,
728 const void *coords)
729{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500730 auto *pathObject = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300731
732 handleError(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
733}
734
735void Context::setPathParameterf(GLuint path, GLenum pname, GLfloat value)
736{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500737 auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300738
739 switch (pname)
740 {
741 case GL_PATH_STROKE_WIDTH_CHROMIUM:
742 pathObj->setStrokeWidth(value);
743 break;
744 case GL_PATH_END_CAPS_CHROMIUM:
745 pathObj->setEndCaps(static_cast<GLenum>(value));
746 break;
747 case GL_PATH_JOIN_STYLE_CHROMIUM:
748 pathObj->setJoinStyle(static_cast<GLenum>(value));
749 break;
750 case GL_PATH_MITER_LIMIT_CHROMIUM:
751 pathObj->setMiterLimit(value);
752 break;
753 case GL_PATH_STROKE_BOUND_CHROMIUM:
754 pathObj->setStrokeBound(value);
755 break;
756 default:
757 UNREACHABLE();
758 break;
759 }
760}
761
762void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value) const
763{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500764 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300765
766 switch (pname)
767 {
768 case GL_PATH_STROKE_WIDTH_CHROMIUM:
769 *value = pathObj->getStrokeWidth();
770 break;
771 case GL_PATH_END_CAPS_CHROMIUM:
772 *value = static_cast<GLfloat>(pathObj->getEndCaps());
773 break;
774 case GL_PATH_JOIN_STYLE_CHROMIUM:
775 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
776 break;
777 case GL_PATH_MITER_LIMIT_CHROMIUM:
778 *value = pathObj->getMiterLimit();
779 break;
780 case GL_PATH_STROKE_BOUND_CHROMIUM:
781 *value = pathObj->getStrokeBound();
782 break;
783 default:
784 UNREACHABLE();
785 break;
786 }
787}
788
789void Context::setPathStencilFunc(GLenum func, GLint ref, GLuint mask)
790{
791 mGLState.setPathStencilFunc(func, ref, mask);
792}
793
Jamie Madill57a89722013-07-02 11:57:03 -0400794void Context::deleteVertexArray(GLuint vertexArray)
795{
Jamie Madill96a483b2017-06-27 16:49:21 -0400796 VertexArray *vertexArrayObject = nullptr;
797 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
Geoff Lang50b3fe82015-12-08 14:49:12 +0000798 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500799 if (vertexArrayObject != nullptr)
800 {
801 detachVertexArray(vertexArray);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400802 vertexArrayObject->onDestroy(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500803 }
Geoff Lang50b3fe82015-12-08 14:49:12 +0000804
Geoff Lang36167ab2015-12-07 10:27:14 -0500805 mVertexArrayHandleAllocator.release(vertexArray);
Jamie Madill57a89722013-07-02 11:57:03 -0400806 }
807}
808
Jamie Madilldc356042013-07-19 16:36:57 -0400809void Context::deleteSampler(GLuint sampler)
810{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500811 if (mState.mSamplers->getSampler(sampler))
Jamie Madilldc356042013-07-19 16:36:57 -0400812 {
813 detachSampler(sampler);
814 }
815
Jamie Madill6c1f6712017-02-14 19:08:04 -0500816 mState.mSamplers->deleteObject(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -0400817}
818
Geoff Langc8058452014-02-03 12:04:11 -0500819void Context::deleteTransformFeedback(GLuint transformFeedback)
820{
Geoff Lang6e60d6b2017-04-12 12:59:04 -0400821 if (transformFeedback == 0)
822 {
823 return;
824 }
825
Jamie Madill96a483b2017-06-27 16:49:21 -0400826 TransformFeedback *transformFeedbackObject = nullptr;
827 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
Geoff Langc8058452014-02-03 12:04:11 -0500828 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500829 if (transformFeedbackObject != nullptr)
830 {
831 detachTransformFeedback(transformFeedback);
Jamie Madill6c1f6712017-02-14 19:08:04 -0500832 transformFeedbackObject->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500833 }
834
Geoff Lang36167ab2015-12-07 10:27:14 -0500835 mTransformFeedbackAllocator.release(transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -0500836 }
837}
838
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000839void Context::deleteFramebuffer(GLuint framebuffer)
840{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500841 if (mState.mFramebuffers->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000842 {
843 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000844 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500845
Jamie Madill6c1f6712017-02-14 19:08:04 -0500846 mState.mFramebuffers->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000847}
848
Jamie Madill33dc8432013-07-26 11:55:05 -0400849void Context::deleteFenceNV(GLuint fence)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000850{
Jamie Madill96a483b2017-06-27 16:49:21 -0400851 FenceNV *fenceObject = nullptr;
852 if (mFenceNVMap.erase(fence, &fenceObject))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000853 {
Jamie Madill96a483b2017-06-27 16:49:21 -0400854 mFenceNVHandleAllocator.release(fence);
855 delete fenceObject;
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000856 }
857}
858
859void Context::deleteQuery(GLuint query)
860{
Jamie Madill96a483b2017-06-27 16:49:21 -0400861 Query *queryObject = nullptr;
862 if (mQueryMap.erase(query, &queryObject))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000863 {
Jamie Madill96a483b2017-06-27 16:49:21 -0400864 mQueryHandleAllocator.release(query);
865 if (queryObject)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000866 {
Jamie Madill96a483b2017-06-27 16:49:21 -0400867 queryObject->release(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000868 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000869 }
870}
871
Geoff Lang70d0f492015-12-10 17:45:46 -0500872Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000873{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500874 return mState.mBuffers->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000875}
876
Jamie Madill570f7c82014-07-03 10:38:54 -0400877Texture *Context::getTexture(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000878{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500879 return mState.mTextures->getTexture(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000880}
881
Geoff Lang70d0f492015-12-10 17:45:46 -0500882Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000883{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500884 return mState.mRenderbuffers->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000885}
886
Jamie Madillcd055f82013-07-26 11:55:15 -0400887FenceSync *Context::getFenceSync(GLsync handle) const
888{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500889 return mState.mFenceSyncs->getFenceSync(
890 static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400891}
892
Jamie Madill57a89722013-07-02 11:57:03 -0400893VertexArray *Context::getVertexArray(GLuint handle) const
894{
Jamie Madill96a483b2017-06-27 16:49:21 -0400895 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -0400896}
897
Jamie Madilldc356042013-07-19 16:36:57 -0400898Sampler *Context::getSampler(GLuint handle) const
899{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500900 return mState.mSamplers->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400901}
902
Geoff Langc8058452014-02-03 12:04:11 -0500903TransformFeedback *Context::getTransformFeedback(GLuint handle) const
904{
Jamie Madill96a483b2017-06-27 16:49:21 -0400905 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -0500906}
907
Geoff Lang70d0f492015-12-10 17:45:46 -0500908LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
909{
910 switch (identifier)
911 {
912 case GL_BUFFER:
913 return getBuffer(name);
914 case GL_SHADER:
915 return getShader(name);
916 case GL_PROGRAM:
917 return getProgram(name);
918 case GL_VERTEX_ARRAY:
919 return getVertexArray(name);
920 case GL_QUERY:
921 return getQuery(name);
922 case GL_TRANSFORM_FEEDBACK:
923 return getTransformFeedback(name);
924 case GL_SAMPLER:
925 return getSampler(name);
926 case GL_TEXTURE:
927 return getTexture(name);
928 case GL_RENDERBUFFER:
929 return getRenderbuffer(name);
930 case GL_FRAMEBUFFER:
931 return getFramebuffer(name);
932 default:
933 UNREACHABLE();
934 return nullptr;
935 }
936}
937
938LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
939{
940 return getFenceSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
941}
942
Martin Radev9d901792016-07-15 15:58:58 +0300943void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
944{
945 LabeledObject *object = getLabeledObject(identifier, name);
946 ASSERT(object != nullptr);
947
948 std::string labelName = GetObjectLabelFromPointer(length, label);
949 object->setLabel(labelName);
950}
951
952void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
953{
954 LabeledObject *object = getLabeledObjectFromPtr(ptr);
955 ASSERT(object != nullptr);
956
957 std::string labelName = GetObjectLabelFromPointer(length, label);
958 object->setLabel(labelName);
959}
960
961void Context::getObjectLabel(GLenum identifier,
962 GLuint name,
963 GLsizei bufSize,
964 GLsizei *length,
965 GLchar *label) const
966{
967 LabeledObject *object = getLabeledObject(identifier, name);
968 ASSERT(object != nullptr);
969
970 const std::string &objectLabel = object->getLabel();
971 GetObjectLabelBase(objectLabel, bufSize, length, label);
972}
973
974void Context::getObjectPtrLabel(const void *ptr,
975 GLsizei bufSize,
976 GLsizei *length,
977 GLchar *label) const
978{
979 LabeledObject *object = getLabeledObjectFromPtr(ptr);
980 ASSERT(object != nullptr);
981
982 const std::string &objectLabel = object->getLabel();
983 GetObjectLabelBase(objectLabel, bufSize, length, label);
984}
985
Jamie Madilldc356042013-07-19 16:36:57 -0400986bool Context::isSampler(GLuint samplerName) const
987{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500988 return mState.mSamplers->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -0400989}
990
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500991void Context::bindArrayBuffer(GLuint bufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000992{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500993 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400994 mGLState.setArrayBufferBinding(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000995}
996
Jiajia Qin9d7d0b12016-11-29 16:30:31 +0800997void Context::bindDrawIndirectBuffer(GLuint bufferHandle)
998{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500999 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001000 mGLState.setDrawIndirectBufferBinding(this, buffer);
Jiajia Qin9d7d0b12016-11-29 16:30:31 +08001001}
1002
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001003void Context::bindElementArrayBuffer(GLuint bufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001004{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001005 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001006 mGLState.setElementArrayBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001007}
1008
Jamie Madilldedd7b92014-11-05 16:30:36 -05001009void Context::bindTexture(GLenum target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001010{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001011 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001012
Jamie Madilldedd7b92014-11-05 16:30:36 -05001013 if (handle == 0)
1014 {
1015 texture = mZeroTextures[target].get();
1016 }
1017 else
1018 {
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001019 texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -05001020 }
1021
1022 ASSERT(texture);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001023 mGLState.setSamplerTexture(this, target, texture);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00001024}
1025
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001026void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001027{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001028 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1029 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001030 mGLState.setReadFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001031}
1032
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001033void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001034{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001035 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1036 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001037 mGLState.setDrawFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001038}
1039
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001040void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -04001041{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001042 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001043 mGLState.setVertexArrayBinding(vertexArray);
Jamie Madill57a89722013-07-02 11:57:03 -04001044}
1045
Shao80957d92017-02-20 21:25:59 +08001046void Context::bindVertexBuffer(GLuint bindingIndex,
1047 GLuint bufferHandle,
1048 GLintptr offset,
1049 GLsizei stride)
1050{
1051 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001052 mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Shao80957d92017-02-20 21:25:59 +08001053}
1054
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001055void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -04001056{
Geoff Lang76b10c92014-09-05 16:28:14 -04001057 ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -04001058 Sampler *sampler =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001059 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001060 mGLState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04001061}
1062
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001063void Context::bindImageTexture(GLuint unit,
1064 GLuint texture,
1065 GLint level,
1066 GLboolean layered,
1067 GLint layer,
1068 GLenum access,
1069 GLenum format)
1070{
1071 Texture *tex = mState.mTextures->getTexture(texture);
1072 mGLState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
1073}
1074
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001075void Context::bindGenericUniformBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001076{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001077 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001078 mGLState.setGenericUniformBufferBinding(this, buffer);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001079}
1080
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001081void Context::bindIndexedUniformBuffer(GLuint bufferHandle,
1082 GLuint index,
1083 GLintptr offset,
1084 GLsizeiptr size)
shannon.woods%transgaming.com@gtempaccount.com34089352013-04-13 03:36:57 +00001085{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001086 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001087 mGLState.setIndexedUniformBufferBinding(this, index, buffer, offset, size);
shannon.woods%transgaming.com@gtempaccount.com34089352013-04-13 03:36:57 +00001088}
1089
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001090void Context::bindGenericTransformFeedbackBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001091{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001092 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001093 mGLState.getCurrentTransformFeedback()->bindGenericBuffer(this, buffer);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001094}
1095
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001096void Context::bindIndexedTransformFeedbackBuffer(GLuint bufferHandle,
1097 GLuint index,
1098 GLintptr offset,
1099 GLsizeiptr size)
shannon.woods%transgaming.com@gtempaccount.com34089352013-04-13 03:36:57 +00001100{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001101 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001102 mGLState.getCurrentTransformFeedback()->bindIndexedBuffer(this, index, buffer, offset, size);
shannon.woods%transgaming.com@gtempaccount.com34089352013-04-13 03:36:57 +00001103}
1104
Jiajia Qin6eafb042016-12-27 17:04:07 +08001105void Context::bindGenericAtomicCounterBuffer(GLuint bufferHandle)
1106{
1107 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001108 mGLState.setGenericAtomicCounterBufferBinding(this, buffer);
Jiajia Qin6eafb042016-12-27 17:04:07 +08001109}
1110
1111void Context::bindIndexedAtomicCounterBuffer(GLuint bufferHandle,
1112 GLuint index,
1113 GLintptr offset,
1114 GLsizeiptr size)
1115{
1116 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001117 mGLState.setIndexedAtomicCounterBufferBinding(this, index, buffer, offset, size);
Jiajia Qin6eafb042016-12-27 17:04:07 +08001118}
1119
Jiajia Qinf546e7d2017-03-27 14:12:59 +08001120void Context::bindGenericShaderStorageBuffer(GLuint bufferHandle)
1121{
1122 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001123 mGLState.setGenericShaderStorageBufferBinding(this, buffer);
Jiajia Qinf546e7d2017-03-27 14:12:59 +08001124}
1125
1126void Context::bindIndexedShaderStorageBuffer(GLuint bufferHandle,
1127 GLuint index,
1128 GLintptr offset,
1129 GLsizeiptr size)
1130{
1131 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001132 mGLState.setIndexedShaderStorageBufferBinding(this, index, buffer, offset, size);
Jiajia Qinf546e7d2017-03-27 14:12:59 +08001133}
1134
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001135void Context::bindCopyReadBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001136{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001137 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001138 mGLState.setCopyReadBufferBinding(this, buffer);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001139}
1140
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001141void Context::bindCopyWriteBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001142{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001143 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001144 mGLState.setCopyWriteBufferBinding(this, buffer);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001145}
1146
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001147void Context::bindPixelPackBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001148{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001149 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001150 mGLState.setPixelPackBufferBinding(this, buffer);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001151}
1152
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001153void Context::bindPixelUnpackBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001154{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001155 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001156 mGLState.setPixelUnpackBufferBinding(this, buffer);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001157}
1158
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001159void Context::useProgram(GLuint program)
1160{
Jamie Madill6c1f6712017-02-14 19:08:04 -05001161 mGLState.setProgram(this, getProgram(program));
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001162}
1163
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001164void Context::bindTransformFeedback(GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001165{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001166 TransformFeedback *transformFeedback =
1167 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001168 mGLState.setTransformFeedbackBinding(this, transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -05001169}
1170
Geoff Lang5aad9672014-09-08 11:10:42 -04001171Error Context::beginQuery(GLenum target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001172{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001173 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001174 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001175
Geoff Lang5aad9672014-09-08 11:10:42 -04001176 // begin query
1177 Error error = queryObject->begin();
1178 if (error.isError())
1179 {
1180 return error;
1181 }
1182
1183 // set query as active for specified target only if begin succeeded
Jamie Madill4928b7c2017-06-20 12:57:39 -04001184 mGLState.setActiveQuery(this, target, queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001185
He Yunchaoacd18982017-01-04 10:46:42 +08001186 return NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001187}
1188
Geoff Lang5aad9672014-09-08 11:10:42 -04001189Error Context::endQuery(GLenum target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001190{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001191 Query *queryObject = mGLState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001192 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001193
Geoff Lang5aad9672014-09-08 11:10:42 -04001194 gl::Error error = queryObject->end();
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001195
Geoff Lang5aad9672014-09-08 11:10:42 -04001196 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madill4928b7c2017-06-20 12:57:39 -04001197 mGLState.setActiveQuery(this, target, nullptr);
Geoff Lang5aad9672014-09-08 11:10:42 -04001198
1199 return error;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001200}
1201
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001202Error Context::queryCounter(GLuint id, GLenum target)
1203{
1204 ASSERT(target == GL_TIMESTAMP_EXT);
1205
1206 Query *queryObject = getQuery(id, true, target);
1207 ASSERT(queryObject);
1208
1209 return queryObject->queryCounter();
1210}
1211
1212void Context::getQueryiv(GLenum target, GLenum pname, GLint *params)
1213{
1214 switch (pname)
1215 {
1216 case GL_CURRENT_QUERY_EXT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001217 params[0] = mGLState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001218 break;
1219 case GL_QUERY_COUNTER_BITS_EXT:
1220 switch (target)
1221 {
1222 case GL_TIME_ELAPSED_EXT:
1223 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1224 break;
1225 case GL_TIMESTAMP_EXT:
1226 params[0] = getExtensions().queryCounterBitsTimestamp;
1227 break;
1228 default:
1229 UNREACHABLE();
1230 params[0] = 0;
1231 break;
1232 }
1233 break;
1234 default:
1235 UNREACHABLE();
1236 return;
1237 }
1238}
1239
Geoff Lang2186c382016-10-14 10:54:54 -04001240void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001241{
Geoff Lang2186c382016-10-14 10:54:54 -04001242 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001243}
1244
Geoff Lang2186c382016-10-14 10:54:54 -04001245void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001246{
Geoff Lang2186c382016-10-14 10:54:54 -04001247 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001248}
1249
Geoff Lang2186c382016-10-14 10:54:54 -04001250void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001251{
Geoff Lang2186c382016-10-14 10:54:54 -04001252 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001253}
1254
Geoff Lang2186c382016-10-14 10:54:54 -04001255void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001256{
Geoff Lang2186c382016-10-14 10:54:54 -04001257 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001258}
1259
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001260Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001261{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001262 return mState.mFramebuffers->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001263}
1264
Jamie Madill2f348d22017-06-05 10:50:59 -04001265FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001266{
Jamie Madill96a483b2017-06-27 16:49:21 -04001267 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001268}
1269
Jamie Madill2f348d22017-06-05 10:50:59 -04001270Query *Context::getQuery(GLuint handle, bool create, GLenum type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001271{
Jamie Madill96a483b2017-06-27 16:49:21 -04001272 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001273 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001274 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001275 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001276
1277 Query *query = mQueryMap.query(handle);
1278 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001279 {
Jamie Madill96a483b2017-06-27 16:49:21 -04001280 query = new Query(mImplementation->createQuery(type), handle);
1281 query->addRef();
1282 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001283 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001284 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001285}
1286
Geoff Lang70d0f492015-12-10 17:45:46 -05001287Query *Context::getQuery(GLuint handle) const
1288{
Jamie Madill96a483b2017-06-27 16:49:21 -04001289 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001290}
1291
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001292Texture *Context::getTargetTexture(GLenum target) const
1293{
Ian Ewellbda75592016-04-18 17:25:54 -04001294 ASSERT(ValidTextureTarget(this, target) || ValidTextureExternalTarget(this, target));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001295 return mGLState.getTargetTexture(target);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001296}
1297
Geoff Lang76b10c92014-09-05 16:28:14 -04001298Texture *Context::getSamplerTexture(unsigned int sampler, GLenum type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001299{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001300 return mGLState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001301}
1302
Geoff Lang492a7e42014-11-05 13:27:06 -05001303Compiler *Context::getCompiler() const
1304{
Jamie Madill2f348d22017-06-05 10:50:59 -04001305 if (mCompiler.get() == nullptr)
1306 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001307 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001308 }
1309 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001310}
1311
Jamie Madillc1d770e2017-04-13 17:31:24 -04001312void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001313{
1314 switch (pname)
1315 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001316 case GL_SHADER_COMPILER:
1317 *params = GL_TRUE;
1318 break;
1319 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1320 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1321 break;
1322 default:
1323 mGLState.getBooleanv(pname, params);
1324 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001325 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001326}
1327
Jamie Madillc1d770e2017-04-13 17:31:24 -04001328void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001329{
Shannon Woods53a94a82014-06-24 15:20:36 -04001330 // Queries about context capabilities and maximums are answered by Context.
1331 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001332 switch (pname)
1333 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001334 case GL_ALIASED_LINE_WIDTH_RANGE:
1335 params[0] = mCaps.minAliasedLineWidth;
1336 params[1] = mCaps.maxAliasedLineWidth;
1337 break;
1338 case GL_ALIASED_POINT_SIZE_RANGE:
1339 params[0] = mCaps.minAliasedPointSize;
1340 params[1] = mCaps.maxAliasedPointSize;
1341 break;
1342 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1343 ASSERT(mExtensions.textureFilterAnisotropic);
1344 *params = mExtensions.maxTextureAnisotropy;
1345 break;
1346 case GL_MAX_TEXTURE_LOD_BIAS:
1347 *params = mCaps.maxLODBias;
1348 break;
1349
1350 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1351 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1352 {
1353 ASSERT(mExtensions.pathRendering);
1354 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1355 memcpy(params, m, 16 * sizeof(GLfloat));
1356 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001357 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001358
Jamie Madill231c7f52017-04-26 13:45:37 -04001359 default:
1360 mGLState.getFloatv(pname, params);
1361 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001362 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001363}
1364
Jamie Madillc1d770e2017-04-13 17:31:24 -04001365void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001366{
Shannon Woods53a94a82014-06-24 15:20:36 -04001367 // Queries about context capabilities and maximums are answered by Context.
1368 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001369
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001370 switch (pname)
1371 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001372 case GL_MAX_VERTEX_ATTRIBS:
1373 *params = mCaps.maxVertexAttributes;
1374 break;
1375 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1376 *params = mCaps.maxVertexUniformVectors;
1377 break;
1378 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
1379 *params = mCaps.maxVertexUniformComponents;
1380 break;
1381 case GL_MAX_VARYING_VECTORS:
1382 *params = mCaps.maxVaryingVectors;
1383 break;
1384 case GL_MAX_VARYING_COMPONENTS:
1385 *params = mCaps.maxVertexOutputComponents;
1386 break;
1387 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1388 *params = mCaps.maxCombinedTextureImageUnits;
1389 break;
1390 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
1391 *params = mCaps.maxVertexTextureImageUnits;
1392 break;
1393 case GL_MAX_TEXTURE_IMAGE_UNITS:
1394 *params = mCaps.maxTextureImageUnits;
1395 break;
1396 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1397 *params = mCaps.maxFragmentUniformVectors;
1398 break;
1399 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
1400 *params = mCaps.maxFragmentUniformComponents;
1401 break;
1402 case GL_MAX_RENDERBUFFER_SIZE:
1403 *params = mCaps.maxRenderbufferSize;
1404 break;
1405 case GL_MAX_COLOR_ATTACHMENTS_EXT:
1406 *params = mCaps.maxColorAttachments;
1407 break;
1408 case GL_MAX_DRAW_BUFFERS_EXT:
1409 *params = mCaps.maxDrawBuffers;
1410 break;
1411 // case GL_FRAMEBUFFER_BINDING: // now equivalent to
1412 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
1413 case GL_SUBPIXEL_BITS:
1414 *params = 4;
1415 break;
1416 case GL_MAX_TEXTURE_SIZE:
1417 *params = mCaps.max2DTextureSize;
1418 break;
1419 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1420 *params = mCaps.maxCubeMapTextureSize;
1421 break;
1422 case GL_MAX_3D_TEXTURE_SIZE:
1423 *params = mCaps.max3DTextureSize;
1424 break;
1425 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1426 *params = mCaps.maxArrayTextureLayers;
1427 break;
1428 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1429 *params = mCaps.uniformBufferOffsetAlignment;
1430 break;
1431 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1432 *params = mCaps.maxUniformBufferBindings;
1433 break;
1434 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
1435 *params = mCaps.maxVertexUniformBlocks;
1436 break;
1437 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
1438 *params = mCaps.maxFragmentUniformBlocks;
1439 break;
1440 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1441 *params = mCaps.maxCombinedTextureImageUnits;
1442 break;
1443 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1444 *params = mCaps.maxVertexOutputComponents;
1445 break;
1446 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1447 *params = mCaps.maxFragmentInputComponents;
1448 break;
1449 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1450 *params = mCaps.minProgramTexelOffset;
1451 break;
1452 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1453 *params = mCaps.maxProgramTexelOffset;
1454 break;
1455 case GL_MAJOR_VERSION:
1456 *params = getClientVersion().major;
1457 break;
1458 case GL_MINOR_VERSION:
1459 *params = getClientVersion().minor;
1460 break;
1461 case GL_MAX_ELEMENTS_INDICES:
1462 *params = mCaps.maxElementsIndices;
1463 break;
1464 case GL_MAX_ELEMENTS_VERTICES:
1465 *params = mCaps.maxElementsVertices;
1466 break;
1467 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1468 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1469 break;
1470 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1471 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1472 break;
1473 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1474 *params = mCaps.maxTransformFeedbackSeparateComponents;
1475 break;
1476 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1477 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1478 break;
1479 case GL_MAX_SAMPLES_ANGLE:
1480 *params = mCaps.maxSamples;
1481 break;
1482 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001483 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001484 params[0] = mCaps.maxViewportWidth;
1485 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001486 }
1487 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001488 case GL_COMPRESSED_TEXTURE_FORMATS:
1489 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1490 params);
1491 break;
1492 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1493 *params = mResetStrategy;
1494 break;
1495 case GL_NUM_SHADER_BINARY_FORMATS:
1496 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1497 break;
1498 case GL_SHADER_BINARY_FORMATS:
1499 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1500 break;
1501 case GL_NUM_PROGRAM_BINARY_FORMATS:
1502 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1503 break;
1504 case GL_PROGRAM_BINARY_FORMATS:
1505 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1506 break;
1507 case GL_NUM_EXTENSIONS:
1508 *params = static_cast<GLint>(mExtensionStrings.size());
1509 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001510
Jamie Madill231c7f52017-04-26 13:45:37 -04001511 // GL_KHR_debug
1512 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1513 *params = mExtensions.maxDebugMessageLength;
1514 break;
1515 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1516 *params = mExtensions.maxDebugLoggedMessages;
1517 break;
1518 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1519 *params = mExtensions.maxDebugGroupStackDepth;
1520 break;
1521 case GL_MAX_LABEL_LENGTH:
1522 *params = mExtensions.maxLabelLength;
1523 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001524
Jamie Madill231c7f52017-04-26 13:45:37 -04001525 // GL_EXT_disjoint_timer_query
1526 case GL_GPU_DISJOINT_EXT:
1527 *params = mImplementation->getGPUDisjoint();
1528 break;
1529 case GL_MAX_FRAMEBUFFER_WIDTH:
1530 *params = mCaps.maxFramebufferWidth;
1531 break;
1532 case GL_MAX_FRAMEBUFFER_HEIGHT:
1533 *params = mCaps.maxFramebufferHeight;
1534 break;
1535 case GL_MAX_FRAMEBUFFER_SAMPLES:
1536 *params = mCaps.maxFramebufferSamples;
1537 break;
1538 case GL_MAX_SAMPLE_MASK_WORDS:
1539 *params = mCaps.maxSampleMaskWords;
1540 break;
1541 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1542 *params = mCaps.maxColorTextureSamples;
1543 break;
1544 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1545 *params = mCaps.maxDepthTextureSamples;
1546 break;
1547 case GL_MAX_INTEGER_SAMPLES:
1548 *params = mCaps.maxIntegerSamples;
1549 break;
1550 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1551 *params = mCaps.maxVertexAttribRelativeOffset;
1552 break;
1553 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1554 *params = mCaps.maxVertexAttribBindings;
1555 break;
1556 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1557 *params = mCaps.maxVertexAttribStride;
1558 break;
1559 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
1560 *params = mCaps.maxVertexAtomicCounterBuffers;
1561 break;
1562 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
1563 *params = mCaps.maxVertexAtomicCounters;
1564 break;
1565 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
1566 *params = mCaps.maxVertexImageUniforms;
1567 break;
1568 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
1569 *params = mCaps.maxVertexShaderStorageBlocks;
1570 break;
1571 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
1572 *params = mCaps.maxFragmentAtomicCounterBuffers;
1573 break;
1574 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
1575 *params = mCaps.maxFragmentAtomicCounters;
1576 break;
1577 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
1578 *params = mCaps.maxFragmentImageUniforms;
1579 break;
1580 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
1581 *params = mCaps.maxFragmentShaderStorageBlocks;
1582 break;
1583 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1584 *params = mCaps.minProgramTextureGatherOffset;
1585 break;
1586 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1587 *params = mCaps.maxProgramTextureGatherOffset;
1588 break;
1589 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1590 *params = mCaps.maxComputeWorkGroupInvocations;
1591 break;
1592 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
1593 *params = mCaps.maxComputeUniformBlocks;
1594 break;
1595 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
1596 *params = mCaps.maxComputeTextureImageUnits;
1597 break;
1598 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1599 *params = mCaps.maxComputeSharedMemorySize;
1600 break;
1601 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
1602 *params = mCaps.maxComputeUniformComponents;
1603 break;
1604 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
1605 *params = mCaps.maxComputeAtomicCounterBuffers;
1606 break;
1607 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
1608 *params = mCaps.maxComputeAtomicCounters;
1609 break;
1610 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
1611 *params = mCaps.maxComputeImageUniforms;
1612 break;
1613 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
1614 *params = mCaps.maxCombinedComputeUniformComponents;
1615 break;
1616 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
1617 *params = mCaps.maxComputeShaderStorageBlocks;
1618 break;
1619 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1620 *params = mCaps.maxCombinedShaderOutputResources;
1621 break;
1622 case GL_MAX_UNIFORM_LOCATIONS:
1623 *params = mCaps.maxUniformLocations;
1624 break;
1625 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1626 *params = mCaps.maxAtomicCounterBufferBindings;
1627 break;
1628 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1629 *params = mCaps.maxAtomicCounterBufferSize;
1630 break;
1631 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1632 *params = mCaps.maxCombinedAtomicCounterBuffers;
1633 break;
1634 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1635 *params = mCaps.maxCombinedAtomicCounters;
1636 break;
1637 case GL_MAX_IMAGE_UNITS:
1638 *params = mCaps.maxImageUnits;
1639 break;
1640 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1641 *params = mCaps.maxCombinedImageUniforms;
1642 break;
1643 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1644 *params = mCaps.maxShaderStorageBufferBindings;
1645 break;
1646 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1647 *params = mCaps.maxCombinedShaderStorageBlocks;
1648 break;
1649 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1650 *params = mCaps.shaderStorageBufferOffsetAlignment;
1651 break;
1652 default:
1653 mGLState.getIntegerv(this, pname, params);
1654 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001655 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001656}
1657
Jamie Madill893ab082014-05-16 16:56:10 -04001658void Context::getInteger64v(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001659{
Shannon Woods53a94a82014-06-24 15:20:36 -04001660 // Queries about context capabilities and maximums are answered by Context.
1661 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001662 switch (pname)
1663 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001664 case GL_MAX_ELEMENT_INDEX:
1665 *params = mCaps.maxElementIndex;
1666 break;
1667 case GL_MAX_UNIFORM_BLOCK_SIZE:
1668 *params = mCaps.maxUniformBlockSize;
1669 break;
1670 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
1671 *params = mCaps.maxCombinedVertexUniformComponents;
1672 break;
1673 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
1674 *params = mCaps.maxCombinedFragmentUniformComponents;
1675 break;
1676 case GL_MAX_SERVER_WAIT_TIMEOUT:
1677 *params = mCaps.maxServerWaitTimeout;
1678 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001679
Jamie Madill231c7f52017-04-26 13:45:37 -04001680 // GL_EXT_disjoint_timer_query
1681 case GL_TIMESTAMP_EXT:
1682 *params = mImplementation->getTimestamp();
1683 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001684
Jamie Madill231c7f52017-04-26 13:45:37 -04001685 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1686 *params = mCaps.maxShaderStorageBlockSize;
1687 break;
1688 default:
1689 UNREACHABLE();
1690 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001691 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001692}
1693
Geoff Lang70d0f492015-12-10 17:45:46 -05001694void Context::getPointerv(GLenum pname, void **params) const
1695{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001696 mGLState.getPointerv(pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001697}
1698
Martin Radev66fb8202016-07-28 11:45:20 +03001699void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001700{
Shannon Woods53a94a82014-06-24 15:20:36 -04001701 // Queries about context capabilities and maximums are answered by Context.
1702 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001703
1704 GLenum nativeType;
1705 unsigned int numParams;
1706 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1707 ASSERT(queryStatus);
1708
1709 if (nativeType == GL_INT)
1710 {
1711 switch (target)
1712 {
1713 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1714 ASSERT(index < 3u);
1715 *data = mCaps.maxComputeWorkGroupCount[index];
1716 break;
1717 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1718 ASSERT(index < 3u);
1719 *data = mCaps.maxComputeWorkGroupSize[index];
1720 break;
1721 default:
1722 mGLState.getIntegeri_v(target, index, data);
1723 }
1724 }
1725 else
1726 {
1727 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1728 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001729}
1730
Martin Radev66fb8202016-07-28 11:45:20 +03001731void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001732{
Shannon Woods53a94a82014-06-24 15:20:36 -04001733 // Queries about context capabilities and maximums are answered by Context.
1734 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001735
1736 GLenum nativeType;
1737 unsigned int numParams;
1738 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1739 ASSERT(queryStatus);
1740
1741 if (nativeType == GL_INT_64_ANGLEX)
1742 {
1743 mGLState.getInteger64i_v(target, index, data);
1744 }
1745 else
1746 {
1747 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1748 }
1749}
1750
1751void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1752{
1753 // Queries about context capabilities and maximums are answered by Context.
1754 // Queries about current GL state values are answered by State.
1755
1756 GLenum nativeType;
1757 unsigned int numParams;
1758 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1759 ASSERT(queryStatus);
1760
1761 if (nativeType == GL_BOOL)
1762 {
1763 mGLState.getBooleani_v(target, index, data);
1764 }
1765 else
1766 {
1767 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1768 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001769}
1770
He Yunchao010e4db2017-03-03 14:22:06 +08001771void Context::getBufferParameteriv(GLenum target, GLenum pname, GLint *params)
1772{
1773 Buffer *buffer = mGLState.getTargetBuffer(target);
1774 QueryBufferParameteriv(buffer, pname, params);
1775}
1776
1777void Context::getFramebufferAttachmentParameteriv(GLenum target,
1778 GLenum attachment,
1779 GLenum pname,
1780 GLint *params)
1781{
1782 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
1783 QueryFramebufferAttachmentParameteriv(framebuffer, attachment, pname, params);
1784}
1785
1786void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
1787{
1788 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
1789 QueryRenderbufferiv(this, renderbuffer, pname, params);
1790}
1791
1792void Context::getTexParameterfv(GLenum target, GLenum pname, GLfloat *params)
1793{
1794 Texture *texture = getTargetTexture(target);
1795 QueryTexParameterfv(texture, pname, params);
1796}
1797
1798void Context::getTexParameteriv(GLenum target, GLenum pname, GLint *params)
1799{
1800 Texture *texture = getTargetTexture(target);
1801 QueryTexParameteriv(texture, pname, params);
1802}
1803void Context::texParameterf(GLenum target, GLenum pname, GLfloat param)
1804{
1805 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001806 SetTexParameterf(this, texture, pname, param);
He Yunchao010e4db2017-03-03 14:22:06 +08001807}
1808
1809void Context::texParameterfv(GLenum target, GLenum pname, const GLfloat *params)
1810{
1811 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001812 SetTexParameterfv(this, texture, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08001813}
1814
1815void Context::texParameteri(GLenum target, GLenum pname, GLint param)
1816{
1817 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001818 SetTexParameteri(this, texture, pname, param);
He Yunchao010e4db2017-03-03 14:22:06 +08001819}
1820
1821void Context::texParameteriv(GLenum target, GLenum pname, const GLint *params)
1822{
1823 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001824 SetTexParameteriv(this, texture, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08001825}
1826
Jamie Madill675fe712016-12-19 13:07:54 -05001827void Context::drawArrays(GLenum mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001828{
Jamie Madill1b94d432015-08-07 13:23:23 -04001829 syncRendererState();
Jamie Madillc564c072017-06-01 12:45:42 -04001830 auto error = mImplementation->drawArrays(this, mode, first, count);
Jamie Madill675fe712016-12-19 13:07:54 -05001831 handleError(error);
1832 if (!error.isError())
1833 {
1834 MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback());
1835 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001836}
1837
Jamie Madill675fe712016-12-19 13:07:54 -05001838void Context::drawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04001839{
1840 syncRendererState();
Jamie Madillc564c072017-06-01 12:45:42 -04001841 auto error = mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount);
Jamie Madill675fe712016-12-19 13:07:54 -05001842 handleError(error);
1843 if (!error.isError())
1844 {
1845 MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback());
1846 }
Geoff Langf6db0982015-08-25 13:04:00 -04001847}
1848
Jamie Madill876429b2017-04-20 15:46:24 -04001849void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001850{
Jamie Madill1b94d432015-08-07 13:23:23 -04001851 syncRendererState();
Jamie Madill9c9b40a2017-04-26 16:31:57 -04001852 const IndexRange &indexRange = getParams<HasIndexRange>().getIndexRange().value();
Jamie Madillc564c072017-06-01 12:45:42 -04001853 handleError(mImplementation->drawElements(this, mode, count, type, indices, indexRange));
Geoff Langf6db0982015-08-25 13:04:00 -04001854}
1855
Jamie Madill675fe712016-12-19 13:07:54 -05001856void Context::drawElementsInstanced(GLenum mode,
1857 GLsizei count,
1858 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04001859 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04001860 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04001861{
1862 syncRendererState();
Jamie Madill9c9b40a2017-04-26 16:31:57 -04001863 const IndexRange &indexRange = getParams<HasIndexRange>().getIndexRange().value();
Jamie Madillc564c072017-06-01 12:45:42 -04001864 handleError(mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances,
1865 indexRange));
Geoff Langf6db0982015-08-25 13:04:00 -04001866}
1867
Jamie Madill675fe712016-12-19 13:07:54 -05001868void Context::drawRangeElements(GLenum mode,
1869 GLuint start,
1870 GLuint end,
1871 GLsizei count,
1872 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04001873 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04001874{
1875 syncRendererState();
Jamie Madill9c9b40a2017-04-26 16:31:57 -04001876 const IndexRange &indexRange = getParams<HasIndexRange>().getIndexRange().value();
Jamie Madillc564c072017-06-01 12:45:42 -04001877 handleError(mImplementation->drawRangeElements(this, mode, start, end, count, type, indices,
1878 indexRange));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001879}
1880
Jamie Madill876429b2017-04-20 15:46:24 -04001881void Context::drawArraysIndirect(GLenum mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08001882{
1883 syncRendererState();
Jamie Madillc564c072017-06-01 12:45:42 -04001884 handleError(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08001885}
1886
Jamie Madill876429b2017-04-20 15:46:24 -04001887void Context::drawElementsIndirect(GLenum mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08001888{
1889 syncRendererState();
Jamie Madillc564c072017-06-01 12:45:42 -04001890 handleError(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08001891}
1892
Jamie Madill675fe712016-12-19 13:07:54 -05001893void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001894{
Jamie Madill675fe712016-12-19 13:07:54 -05001895 handleError(mImplementation->flush());
Geoff Lang129753a2015-01-09 16:52:09 -05001896}
1897
Jamie Madill675fe712016-12-19 13:07:54 -05001898void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05001899{
Jamie Madill675fe712016-12-19 13:07:54 -05001900 handleError(mImplementation->finish());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001901}
1902
Austin Kinross6ee1e782015-05-29 17:05:37 -07001903void Context::insertEventMarker(GLsizei length, const char *marker)
1904{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001905 ASSERT(mImplementation);
1906 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07001907}
1908
1909void Context::pushGroupMarker(GLsizei length, const char *marker)
1910{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001911 ASSERT(mImplementation);
1912 mImplementation->pushGroupMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07001913}
1914
1915void Context::popGroupMarker()
1916{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001917 ASSERT(mImplementation);
1918 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07001919}
1920
Geoff Langd8605522016-04-13 10:19:12 -04001921void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
1922{
1923 Program *programObject = getProgram(program);
1924 ASSERT(programObject);
1925
1926 programObject->bindUniformLocation(location, name);
1927}
1928
Sami Väisänena797e062016-05-12 15:23:40 +03001929void Context::setCoverageModulation(GLenum components)
1930{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001931 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03001932}
1933
Sami Väisänene45e53b2016-05-25 10:36:04 +03001934void Context::loadPathRenderingMatrix(GLenum matrixMode, const GLfloat *matrix)
1935{
1936 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
1937}
1938
1939void Context::loadPathRenderingIdentityMatrix(GLenum matrixMode)
1940{
1941 GLfloat I[16];
1942 angle::Matrix<GLfloat>::setToIdentity(I);
1943
1944 mGLState.loadPathRenderingMatrix(matrixMode, I);
1945}
1946
1947void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
1948{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001949 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001950 if (!pathObj)
1951 return;
1952
1953 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1954 syncRendererState();
1955
1956 mImplementation->stencilFillPath(pathObj, fillMode, mask);
1957}
1958
1959void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
1960{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001961 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001962 if (!pathObj)
1963 return;
1964
1965 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1966 syncRendererState();
1967
1968 mImplementation->stencilStrokePath(pathObj, reference, mask);
1969}
1970
1971void Context::coverFillPath(GLuint path, GLenum coverMode)
1972{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001973 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001974 if (!pathObj)
1975 return;
1976
1977 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1978 syncRendererState();
1979
1980 mImplementation->coverFillPath(pathObj, coverMode);
1981}
1982
1983void Context::coverStrokePath(GLuint path, GLenum coverMode)
1984{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001985 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001986 if (!pathObj)
1987 return;
1988
1989 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1990 syncRendererState();
1991
1992 mImplementation->coverStrokePath(pathObj, coverMode);
1993}
1994
1995void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
1996{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001997 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001998 if (!pathObj)
1999 return;
2000
2001 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2002 syncRendererState();
2003
2004 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
2005}
2006
2007void Context::stencilThenCoverStrokePath(GLuint path,
2008 GLint reference,
2009 GLuint mask,
2010 GLenum coverMode)
2011{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002012 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002013 if (!pathObj)
2014 return;
2015
2016 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2017 syncRendererState();
2018
2019 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2020}
2021
Sami Väisänend59ca052016-06-21 16:10:00 +03002022void Context::coverFillPathInstanced(GLsizei numPaths,
2023 GLenum pathNameType,
2024 const void *paths,
2025 GLuint pathBase,
2026 GLenum coverMode,
2027 GLenum transformType,
2028 const GLfloat *transformValues)
2029{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002030 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002031
2032 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2033 syncRendererState();
2034
2035 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2036}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002037
Sami Väisänend59ca052016-06-21 16:10:00 +03002038void Context::coverStrokePathInstanced(GLsizei numPaths,
2039 GLenum pathNameType,
2040 const void *paths,
2041 GLuint pathBase,
2042 GLenum coverMode,
2043 GLenum transformType,
2044 const GLfloat *transformValues)
2045{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002046 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002047
2048 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2049 syncRendererState();
2050
2051 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2052 transformValues);
2053}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002054
Sami Väisänend59ca052016-06-21 16:10:00 +03002055void Context::stencilFillPathInstanced(GLsizei numPaths,
2056 GLenum pathNameType,
2057 const void *paths,
2058 GLuint pathBase,
2059 GLenum fillMode,
2060 GLuint mask,
2061 GLenum transformType,
2062 const GLfloat *transformValues)
2063{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002064 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002065
2066 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2067 syncRendererState();
2068
2069 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2070 transformValues);
2071}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002072
Sami Väisänend59ca052016-06-21 16:10:00 +03002073void Context::stencilStrokePathInstanced(GLsizei numPaths,
2074 GLenum pathNameType,
2075 const void *paths,
2076 GLuint pathBase,
2077 GLint reference,
2078 GLuint mask,
2079 GLenum transformType,
2080 const GLfloat *transformValues)
2081{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002082 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002083
2084 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2085 syncRendererState();
2086
2087 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2088 transformValues);
2089}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002090
Sami Väisänend59ca052016-06-21 16:10:00 +03002091void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2092 GLenum pathNameType,
2093 const void *paths,
2094 GLuint pathBase,
2095 GLenum fillMode,
2096 GLuint mask,
2097 GLenum coverMode,
2098 GLenum transformType,
2099 const GLfloat *transformValues)
2100{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002101 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002102
2103 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2104 syncRendererState();
2105
2106 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2107 transformType, transformValues);
2108}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002109
Sami Väisänend59ca052016-06-21 16:10:00 +03002110void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2111 GLenum pathNameType,
2112 const void *paths,
2113 GLuint pathBase,
2114 GLint reference,
2115 GLuint mask,
2116 GLenum coverMode,
2117 GLenum transformType,
2118 const GLfloat *transformValues)
2119{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002120 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002121
2122 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2123 syncRendererState();
2124
2125 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2126 transformType, transformValues);
2127}
2128
Sami Väisänen46eaa942016-06-29 10:26:37 +03002129void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2130{
2131 auto *programObject = getProgram(program);
2132
2133 programObject->bindFragmentInputLocation(location, name);
2134}
2135
2136void Context::programPathFragmentInputGen(GLuint program,
2137 GLint location,
2138 GLenum genMode,
2139 GLint components,
2140 const GLfloat *coeffs)
2141{
2142 auto *programObject = getProgram(program);
2143
Jamie Madillbd044ed2017-06-05 12:59:21 -04002144 programObject->pathFragmentInputGen(this, location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002145}
2146
jchen1015015f72017-03-16 13:54:21 +08002147GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2148{
jchen10fd7c3b52017-03-21 15:36:03 +08002149 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002150 return QueryProgramResourceIndex(programObject, programInterface, name);
2151}
2152
jchen10fd7c3b52017-03-21 15:36:03 +08002153void Context::getProgramResourceName(GLuint program,
2154 GLenum programInterface,
2155 GLuint index,
2156 GLsizei bufSize,
2157 GLsizei *length,
2158 GLchar *name)
2159{
2160 const auto *programObject = getProgram(program);
2161 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2162}
2163
Jamie Madill437fa652016-05-03 15:13:24 -04002164void Context::handleError(const Error &error)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002165{
Geoff Langda5777c2014-07-11 09:52:58 -04002166 if (error.isError())
2167 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002168 GLenum code = error.getCode();
2169 mErrors.insert(code);
2170 if (code == GL_OUT_OF_MEMORY && getWorkarounds().loseContextOnOutOfMemory)
2171 {
2172 markContextLost();
2173 }
Geoff Lang70d0f492015-12-10 17:45:46 -05002174
2175 if (!error.getMessage().empty())
2176 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002177 auto *debug = &mGLState.getDebug();
2178 debug->insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, error.getID(),
2179 GL_DEBUG_SEVERITY_HIGH, error.getMessage());
Geoff Lang70d0f492015-12-10 17:45:46 -05002180 }
Geoff Langda5777c2014-07-11 09:52:58 -04002181 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002182}
2183
2184// Get one of the recorded errors and clear its flag, if any.
2185// [OpenGL ES 2.0.24] section 2.5 page 13.
2186GLenum Context::getError()
2187{
Geoff Langda5777c2014-07-11 09:52:58 -04002188 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002189 {
Geoff Langda5777c2014-07-11 09:52:58 -04002190 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002191 }
Geoff Langda5777c2014-07-11 09:52:58 -04002192 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002193 {
Geoff Langda5777c2014-07-11 09:52:58 -04002194 GLenum error = *mErrors.begin();
2195 mErrors.erase(mErrors.begin());
2196 return error;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002197 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002198}
2199
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002200// NOTE: this function should not assume that this context is current!
2201void Context::markContextLost()
2202{
2203 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002204 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002205 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002206 mContextLostForced = true;
2207 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002208 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002209}
2210
2211bool Context::isContextLost()
2212{
2213 return mContextLost;
2214}
2215
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002216GLenum Context::getResetStatus()
2217{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002218 // Even if the application doesn't want to know about resets, we want to know
2219 // as it will allow us to skip all the calls.
2220 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002221 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002222 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002223 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002224 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002225 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002226
2227 // EXT_robustness, section 2.6: If the reset notification behavior is
2228 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2229 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2230 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002231 }
2232
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002233 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2234 // status should be returned at least once, and GL_NO_ERROR should be returned
2235 // once the device has finished resetting.
2236 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002237 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002238 ASSERT(mResetStatus == GL_NO_ERROR);
2239 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002240
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002241 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002242 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002243 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002244 }
2245 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002246 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002247 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002248 // If markContextLost was used to mark the context lost then
2249 // assume that is not recoverable, and continue to report the
2250 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002251 mResetStatus = mImplementation->getResetStatus();
2252 }
Jamie Madill893ab082014-05-16 16:56:10 -04002253
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002254 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002255}
2256
2257bool Context::isResetNotificationEnabled()
2258{
2259 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2260}
2261
Corentin Walleze3b10e82015-05-20 11:06:25 -04002262const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002263{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002264 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002265}
2266
2267EGLenum Context::getClientType() const
2268{
2269 return mClientType;
2270}
2271
2272EGLenum Context::getRenderBuffer() const
2273{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002274 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2275 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002276 {
2277 return EGL_NONE;
2278 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002279
2280 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(GL_BACK);
2281 ASSERT(backAttachment != nullptr);
2282 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002283}
2284
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002285VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002286{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002287 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002288 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2289 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002290 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002291 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2292 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002293
Jamie Madill96a483b2017-06-27 16:49:21 -04002294 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002295 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002296
2297 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002298}
2299
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002300TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002301{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002302 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002303 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2304 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002305 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002306 transformFeedback =
2307 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002308 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002309 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002310 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002311
2312 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002313}
2314
2315bool Context::isVertexArrayGenerated(GLuint vertexArray)
2316{
Jamie Madill96a483b2017-06-27 16:49:21 -04002317 ASSERT(mVertexArrayMap.contains(0));
2318 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002319}
2320
2321bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2322{
Jamie Madill96a483b2017-06-27 16:49:21 -04002323 ASSERT(mTransformFeedbackMap.contains(0));
2324 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002325}
2326
Shannon Woods53a94a82014-06-24 15:20:36 -04002327void Context::detachTexture(GLuint texture)
2328{
2329 // Simple pass-through to State's detachTexture method, as textures do not require
2330 // allocation map management either here or in the resource manager at detach time.
2331 // Zero textures are held by the Context, and we don't attempt to request them from
2332 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002333 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002334}
2335
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002336void Context::detachBuffer(GLuint buffer)
2337{
Yuly Novikov5807a532015-12-03 13:01:22 -05002338 // Simple pass-through to State's detachBuffer method, since
2339 // only buffer attachments to container objects that are bound to the current context
2340 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002341
Yuly Novikov5807a532015-12-03 13:01:22 -05002342 // [OpenGL ES 3.2] section 5.1.2 page 45:
2343 // Attachments to unbound container objects, such as
2344 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2345 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002346 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002347}
2348
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002349void Context::detachFramebuffer(GLuint framebuffer)
2350{
Shannon Woods53a94a82014-06-24 15:20:36 -04002351 // Framebuffer detachment is handled by Context, because 0 is a valid
2352 // Framebuffer object, and a pointer to it must be passed from Context
2353 // to State at binding time.
2354
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002355 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002356 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2357 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2358 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002359
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002360 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002361 {
2362 bindReadFramebuffer(0);
2363 }
2364
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002365 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002366 {
2367 bindDrawFramebuffer(0);
2368 }
2369}
2370
2371void Context::detachRenderbuffer(GLuint renderbuffer)
2372{
Jamie Madilla02315b2017-02-23 14:14:47 -05002373 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002374}
2375
Jamie Madill57a89722013-07-02 11:57:03 -04002376void Context::detachVertexArray(GLuint vertexArray)
2377{
Jamie Madill77a72f62015-04-14 11:18:32 -04002378 // Vertex array detachment is handled by Context, because 0 is a valid
2379 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002380 // binding time.
2381
Jamie Madill57a89722013-07-02 11:57:03 -04002382 // [OpenGL ES 3.0.2] section 2.10 page 43:
2383 // If a vertex array object that is currently bound is deleted, the binding
2384 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002385 if (mGLState.removeVertexArrayBinding(vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002386 {
2387 bindVertexArray(0);
2388 }
2389}
2390
Geoff Langc8058452014-02-03 12:04:11 -05002391void Context::detachTransformFeedback(GLuint transformFeedback)
2392{
Corentin Walleza2257da2016-04-19 16:43:12 -04002393 // Transform feedback detachment is handled by Context, because 0 is a valid
2394 // transform feedback, and a pointer to it must be passed from Context to State at
2395 // binding time.
2396
2397 // The OpenGL specification doesn't mention what should happen when the currently bound
2398 // transform feedback object is deleted. Since it is a container object, we treat it like
2399 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002400 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002401 {
2402 bindTransformFeedback(0);
2403 }
Geoff Langc8058452014-02-03 12:04:11 -05002404}
2405
Jamie Madilldc356042013-07-19 16:36:57 -04002406void Context::detachSampler(GLuint sampler)
2407{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002408 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002409}
2410
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002411void Context::setVertexAttribDivisor(GLuint index, GLuint divisor)
2412{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002413 mGLState.setVertexAttribDivisor(index, divisor);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002414}
2415
Jamie Madille29d1672013-07-19 16:36:57 -04002416void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2417{
Geoff Langc1984ed2016-10-07 12:41:00 -04002418 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002419 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002420 SetSamplerParameteri(samplerObject, pname, param);
2421}
Jamie Madille29d1672013-07-19 16:36:57 -04002422
Geoff Langc1984ed2016-10-07 12:41:00 -04002423void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2424{
2425 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002426 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002427 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madille29d1672013-07-19 16:36:57 -04002428}
2429
2430void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2431{
Geoff Langc1984ed2016-10-07 12:41:00 -04002432 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002433 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002434 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madille29d1672013-07-19 16:36:57 -04002435}
2436
Geoff Langc1984ed2016-10-07 12:41:00 -04002437void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002438{
Geoff Langc1984ed2016-10-07 12:41:00 -04002439 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002440 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002441 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill9675b802013-07-19 16:36:59 -04002442}
2443
Geoff Langc1984ed2016-10-07 12:41:00 -04002444void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002445{
Geoff Langc1984ed2016-10-07 12:41:00 -04002446 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002447 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002448 QuerySamplerParameteriv(samplerObject, pname, params);
2449}
Jamie Madill9675b802013-07-19 16:36:59 -04002450
Geoff Langc1984ed2016-10-07 12:41:00 -04002451void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2452{
2453 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002454 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002455 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill9675b802013-07-19 16:36:59 -04002456}
2457
Olli Etuahof0fee072016-03-30 15:11:58 +03002458void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2459{
2460 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002461 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002462}
2463
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002464void Context::initRendererString()
2465{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002466 std::ostringstream rendererString;
2467 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002468 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002469 rendererString << ")";
2470
Geoff Langcec35902014-04-16 10:52:36 -04002471 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002472}
2473
Geoff Langc339c4e2016-11-29 10:37:36 -05002474void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002475{
Geoff Langc339c4e2016-11-29 10:37:36 -05002476 const Version &clientVersion = getClientVersion();
2477
2478 std::ostringstream versionString;
2479 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2480 << ANGLE_VERSION_STRING << ")";
2481 mVersionString = MakeStaticString(versionString.str());
2482
2483 std::ostringstream shadingLanguageVersionString;
2484 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2485 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2486 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2487 << ")";
2488 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002489}
2490
Geoff Langcec35902014-04-16 10:52:36 -04002491void Context::initExtensionStrings()
2492{
Geoff Langc339c4e2016-11-29 10:37:36 -05002493 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2494 std::ostringstream combinedStringStream;
2495 std::copy(strings.begin(), strings.end(),
2496 std::ostream_iterator<const char *>(combinedStringStream, " "));
2497 return MakeStaticString(combinedStringStream.str());
2498 };
2499
2500 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002501 for (const auto &extensionString : mExtensions.getStrings())
2502 {
2503 mExtensionStrings.push_back(MakeStaticString(extensionString));
2504 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002505 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002506
Bryan Bernhart58806562017-01-05 13:09:31 -08002507 const gl::Extensions &nativeExtensions = mImplementation->getNativeExtensions();
2508
Geoff Langc339c4e2016-11-29 10:37:36 -05002509 mRequestableExtensionStrings.clear();
2510 for (const auto &extensionInfo : GetExtensionInfoMap())
2511 {
2512 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08002513 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
2514 nativeExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002515 {
2516 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
2517 }
2518 }
2519 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002520}
2521
Geoff Langc339c4e2016-11-29 10:37:36 -05002522const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04002523{
Geoff Langc339c4e2016-11-29 10:37:36 -05002524 switch (name)
2525 {
2526 case GL_VENDOR:
2527 return reinterpret_cast<const GLubyte *>("Google Inc.");
2528
2529 case GL_RENDERER:
2530 return reinterpret_cast<const GLubyte *>(mRendererString);
2531
2532 case GL_VERSION:
2533 return reinterpret_cast<const GLubyte *>(mVersionString);
2534
2535 case GL_SHADING_LANGUAGE_VERSION:
2536 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
2537
2538 case GL_EXTENSIONS:
2539 return reinterpret_cast<const GLubyte *>(mExtensionString);
2540
2541 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2542 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
2543
2544 default:
2545 UNREACHABLE();
2546 return nullptr;
2547 }
Geoff Langcec35902014-04-16 10:52:36 -04002548}
2549
Geoff Langc339c4e2016-11-29 10:37:36 -05002550const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04002551{
Geoff Langc339c4e2016-11-29 10:37:36 -05002552 switch (name)
2553 {
2554 case GL_EXTENSIONS:
2555 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
2556
2557 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2558 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
2559
2560 default:
2561 UNREACHABLE();
2562 return nullptr;
2563 }
Geoff Langcec35902014-04-16 10:52:36 -04002564}
2565
2566size_t Context::getExtensionStringCount() const
2567{
2568 return mExtensionStrings.size();
2569}
2570
Geoff Langc339c4e2016-11-29 10:37:36 -05002571void Context::requestExtension(const char *name)
2572{
2573 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2574 ASSERT(extensionInfos.find(name) != extensionInfos.end());
2575 const auto &extension = extensionInfos.at(name);
2576 ASSERT(extension.Requestable);
2577
2578 if (mExtensions.*(extension.ExtensionsMember))
2579 {
2580 // Extension already enabled
2581 return;
2582 }
2583
2584 mExtensions.*(extension.ExtensionsMember) = true;
2585 updateCaps();
2586 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08002587
Jamie Madill2f348d22017-06-05 10:50:59 -04002588 // Release the shader compiler so it will be re-created with the requested extensions enabled.
2589 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04002590
2591 // Invalidate all cached completenesses for textures and framebuffer. Some extensions make new
2592 // formats renderable or sampleable.
2593 mState.mTextures->invalidateTextureComplenessCache();
2594 for (auto &zeroTexture : mZeroTextures)
2595 {
2596 zeroTexture.second->invalidateCompletenessCache();
2597 }
2598
2599 mState.mFramebuffers->invalidateFramebufferComplenessCache();
Geoff Langc339c4e2016-11-29 10:37:36 -05002600}
2601
2602size_t Context::getRequestableExtensionStringCount() const
2603{
2604 return mRequestableExtensionStrings.size();
2605}
2606
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002607void Context::beginTransformFeedback(GLenum primitiveMode)
2608{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002609 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002610 ASSERT(transformFeedback != nullptr);
2611 ASSERT(!transformFeedback->isPaused());
2612
Jamie Madill6c1f6712017-02-14 19:08:04 -05002613 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002614}
2615
2616bool Context::hasActiveTransformFeedback(GLuint program) const
2617{
2618 for (auto pair : mTransformFeedbackMap)
2619 {
2620 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
2621 {
2622 return true;
2623 }
2624 }
2625 return false;
2626}
2627
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002628void Context::initCaps(const egl::DisplayExtensions &displayExtensions)
Geoff Lang493daf52014-07-03 13:38:44 -04002629{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002630 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04002631
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002632 mExtensions = mImplementation->getNativeExtensions();
Geoff Lang493daf52014-07-03 13:38:44 -04002633
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002634 mLimitations = mImplementation->getNativeLimitations();
Austin Kinross02df7962015-07-01 10:03:42 -07002635
Geoff Langeb66a6e2016-10-31 13:06:12 -04002636 if (getClientVersion() < Version(3, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002637 {
2638 // Disable ES3+ extensions
Jamie Madill231c7f52017-04-26 13:45:37 -04002639 mExtensions.colorBufferFloat = false;
Geoff Langb66a9092016-05-16 15:59:14 -04002640 mExtensions.eglImageExternalEssl3 = false;
Vincent Lang25ab4512016-05-13 18:13:59 +02002641 mExtensions.textureNorm16 = false;
Geoff Lang493daf52014-07-03 13:38:44 -04002642 }
2643
Geoff Langeb66a6e2016-10-31 13:06:12 -04002644 if (getClientVersion() > Version(2, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002645 {
2646 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
Jamie Madill231c7f52017-04-26 13:45:37 -04002647 // mExtensions.sRGB = false;
Geoff Lang493daf52014-07-03 13:38:44 -04002648 }
2649
Jamie Madill00ed7a12016-05-19 13:13:38 -04002650 // Some extensions are always available because they are implemented in the GL layer.
Jamie Madill231c7f52017-04-26 13:45:37 -04002651 mExtensions.bindUniformLocation = true;
2652 mExtensions.vertexArrayObject = true;
Geoff Langf41a7152016-09-19 15:11:17 -04002653 mExtensions.bindGeneratesResource = true;
Geoff Langfeb8c682017-02-13 16:07:35 -05002654 mExtensions.clientArrays = true;
Geoff Langc339c4e2016-11-29 10:37:36 -05002655 mExtensions.requestExtension = true;
Jamie Madill00ed7a12016-05-19 13:13:38 -04002656
2657 // Enable the no error extension if the context was created with the flag.
2658 mExtensions.noError = mSkipValidation;
2659
Corentin Wallezccab69d2017-01-27 16:57:15 -05002660 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Corentin Wallezc295e512017-01-27 17:47:50 -05002661 mExtensions.surfacelessContext = displayExtensions.surfacelessContext;
Corentin Wallezccab69d2017-01-27 16:57:15 -05002662
Geoff Lang70d0f492015-12-10 17:45:46 -05002663 // Explicitly enable GL_KHR_debug
2664 mExtensions.debug = true;
2665 mExtensions.maxDebugMessageLength = 1024;
2666 mExtensions.maxDebugLoggedMessages = 1024;
2667 mExtensions.maxDebugGroupStackDepth = 1024;
2668 mExtensions.maxLabelLength = 1024;
2669
Geoff Langff5b2d52016-09-07 11:32:23 -04002670 // Explicitly enable GL_ANGLE_robust_client_memory
2671 mExtensions.robustClientMemory = true;
2672
Jamie Madille08a1d32017-03-07 17:24:06 -05002673 // Determine robust resource init availability from EGL.
2674 mExtensions.robustResourceInitialization =
Jamie Madill948bbe52017-06-01 13:10:42 -04002675 egl::Display::GetClientExtensions().displayRobustResourceInitialization;
Jamie Madille08a1d32017-03-07 17:24:06 -05002676
Jamie Madillc43be722017-07-13 16:22:14 -04002677 // Enable the cache control query unconditionally.
2678 mExtensions.programCacheControl = true;
2679
Geoff Lang301d1612014-07-09 10:34:37 -04002680 // Apply implementation limits
2681 mCaps.maxVertexAttributes = std::min<GLuint>(mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002682 mCaps.maxVertexAttribBindings =
2683 getClientVersion() < ES_3_1
2684 ? mCaps.maxVertexAttributes
2685 : std::min<GLuint>(mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
2686
Jamie Madill231c7f52017-04-26 13:45:37 -04002687 mCaps.maxVertexUniformBlocks = std::min<GLuint>(
2688 mCaps.maxVertexUniformBlocks, IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
2689 mCaps.maxVertexOutputComponents =
2690 std::min<GLuint>(mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
Geoff Lang301d1612014-07-09 10:34:37 -04002691
Jamie Madill231c7f52017-04-26 13:45:37 -04002692 mCaps.maxFragmentInputComponents =
2693 std::min<GLuint>(mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
Geoff Lang3a61c322014-07-10 13:01:54 -04002694
Geoff Langc287ea62016-09-16 14:46:51 -04002695 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002696 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04002697 for (const auto &extensionInfo : GetExtensionInfoMap())
2698 {
2699 // If this context is for WebGL, disable all enableable extensions
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002700 if (mWebGLContext && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04002701 {
2702 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
2703 }
2704 }
2705
2706 // Generate texture caps
2707 updateCaps();
2708}
2709
2710void Context::updateCaps()
2711{
Geoff Lang900013c2014-07-07 11:32:19 -04002712 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002713 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04002714
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002715 for (auto capsIt : mImplementation->getNativeTextureCaps())
Geoff Lang493daf52014-07-03 13:38:44 -04002716 {
Geoff Langca271392017-04-05 12:30:00 -04002717 GLenum sizedInternalFormat = capsIt.first;
Jamie Madill231c7f52017-04-26 13:45:37 -04002718 TextureCaps formatCaps = capsIt.second;
Geoff Lang493daf52014-07-03 13:38:44 -04002719
Geoff Langca271392017-04-05 12:30:00 -04002720 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04002721
Geoff Lang0d8b7242015-09-09 14:56:53 -04002722 // Update the format caps based on the client version and extensions.
2723 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
2724 // ES3.
2725 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002726 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002727 formatCaps.renderable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002728 formatCaps.renderable && formatInfo.renderSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002729 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002730 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04002731
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002732 // OpenGL ES does not support multisampling with non-rendererable formats
2733 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Olli Etuaho50c562d2017-06-06 14:43:30 +03002734 if (!formatCaps.renderable ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002735 (getClientVersion() < ES_3_1 &&
2736 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04002737 {
Geoff Langd87878e2014-09-19 15:42:59 -04002738 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04002739 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03002740 else
2741 {
2742 // We may have limited the max samples for some required renderbuffer formats due to
2743 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
2744 GLuint formatMaxSamples = formatCaps.getMaxSamples();
2745
2746 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
2747 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
2748 // exception of signed and unsigned integer formats."
2749 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
2750 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
2751 {
2752 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
2753 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
2754 }
2755
2756 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
2757 if (getClientVersion() >= ES_3_1)
2758 {
2759 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
2760 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
2761 // the exception that the signed and unsigned integer formats are required only to
2762 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
2763 // multisamples, which must be at least one."
2764 if (formatInfo.componentType == GL_INT ||
2765 formatInfo.componentType == GL_UNSIGNED_INT)
2766 {
2767 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
2768 }
2769
2770 // GLES 3.1 section 19.3.1.
2771 if (formatCaps.texturable)
2772 {
2773 if (formatInfo.depthBits > 0)
2774 {
2775 mCaps.maxDepthTextureSamples =
2776 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
2777 }
2778 else if (formatInfo.redBits > 0)
2779 {
2780 mCaps.maxColorTextureSamples =
2781 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
2782 }
2783 }
2784 }
2785 }
Geoff Langd87878e2014-09-19 15:42:59 -04002786
2787 if (formatCaps.texturable && formatInfo.compressed)
2788 {
Geoff Langca271392017-04-05 12:30:00 -04002789 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04002790 }
2791
Geoff Langca271392017-04-05 12:30:00 -04002792 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04002793 }
Jamie Madill32447362017-06-28 14:53:52 -04002794
2795 // If program binary is disabled, blank out the memory cache pointer.
2796 if (!mImplementation->getNativeExtensions().getProgramBinary)
2797 {
2798 mMemoryProgramCache = nullptr;
2799 }
Geoff Lang493daf52014-07-03 13:38:44 -04002800}
2801
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002802void Context::initWorkarounds()
2803{
Jamie Madill761b02c2017-06-23 16:27:06 -04002804 // Apply back-end workarounds.
2805 mImplementation->applyNativeWorkarounds(&mWorkarounds);
2806
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002807 // Lose the context upon out of memory error if the application is
2808 // expecting to watch for those events.
2809 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2810}
2811
Jamie Madill1b94d432015-08-07 13:23:23 -04002812void Context::syncRendererState()
2813{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002814 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
Jamie Madillfe548342017-06-19 11:13:24 -04002815 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002816 mGLState.clearDirtyBits();
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002817 mGLState.syncDirtyObjects(this);
Jamie Madill1b94d432015-08-07 13:23:23 -04002818}
2819
Jamie Madillad9f24e2016-02-12 09:27:24 -05002820void Context::syncRendererState(const State::DirtyBits &bitMask,
2821 const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04002822{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002823 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madillfe548342017-06-19 11:13:24 -04002824 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002825 mGLState.clearDirtyBits(dirtyBits);
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002826 mGLState.syncDirtyObjects(this, objectMask);
Jamie Madill1b94d432015-08-07 13:23:23 -04002827}
Jamie Madillc29968b2016-01-20 11:17:23 -05002828
2829void Context::blitFramebuffer(GLint srcX0,
2830 GLint srcY0,
2831 GLint srcX1,
2832 GLint srcY1,
2833 GLint dstX0,
2834 GLint dstY0,
2835 GLint dstX1,
2836 GLint dstY1,
2837 GLbitfield mask,
2838 GLenum filter)
2839{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002840 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002841 ASSERT(drawFramebuffer);
2842
2843 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
2844 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
2845
Jamie Madillad9f24e2016-02-12 09:27:24 -05002846 syncStateForBlit();
Jamie Madillc29968b2016-01-20 11:17:23 -05002847
Jamie Madillc564c072017-06-01 12:45:42 -04002848 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002849}
Jamie Madillc29968b2016-01-20 11:17:23 -05002850
2851void Context::clear(GLbitfield mask)
2852{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002853 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002854 handleError(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05002855}
2856
2857void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
2858{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002859 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002860 handleError(mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002861}
2862
2863void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
2864{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002865 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002866 handleError(mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002867}
2868
2869void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
2870{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002871 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002872 handleError(mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002873}
2874
2875void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
2876{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002877 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002878 ASSERT(framebufferObject);
2879
2880 // If a buffer is not present, the clear has no effect
2881 if (framebufferObject->getDepthbuffer() == nullptr &&
2882 framebufferObject->getStencilbuffer() == nullptr)
2883 {
2884 return;
2885 }
2886
Jamie Madillad9f24e2016-02-12 09:27:24 -05002887 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002888 handleError(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05002889}
2890
2891void Context::readPixels(GLint x,
2892 GLint y,
2893 GLsizei width,
2894 GLsizei height,
2895 GLenum format,
2896 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002897 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05002898{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04002899 if (width == 0 || height == 0)
2900 {
2901 return;
2902 }
2903
Jamie Madillad9f24e2016-02-12 09:27:24 -05002904 syncStateForReadPixels();
Jamie Madillc29968b2016-01-20 11:17:23 -05002905
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002906 Framebuffer *framebufferObject = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002907 ASSERT(framebufferObject);
2908
2909 Rectangle area(x, y, width, height);
Jamie Madillc564c072017-06-01 12:45:42 -04002910 handleError(framebufferObject->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05002911}
2912
2913void Context::copyTexImage2D(GLenum target,
2914 GLint level,
2915 GLenum internalformat,
2916 GLint x,
2917 GLint y,
2918 GLsizei width,
2919 GLsizei height,
2920 GLint border)
2921{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002922 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002923 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002924
Jamie Madillc29968b2016-01-20 11:17:23 -05002925 Rectangle sourceArea(x, y, width, height);
2926
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002927 const Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002928 Texture *texture =
2929 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05002930 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05002931}
2932
2933void Context::copyTexSubImage2D(GLenum target,
2934 GLint level,
2935 GLint xoffset,
2936 GLint yoffset,
2937 GLint x,
2938 GLint y,
2939 GLsizei width,
2940 GLsizei height)
2941{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04002942 if (width == 0 || height == 0)
2943 {
2944 return;
2945 }
2946
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002947 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002948 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002949
Jamie Madillc29968b2016-01-20 11:17:23 -05002950 Offset destOffset(xoffset, yoffset, 0);
2951 Rectangle sourceArea(x, y, width, height);
2952
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002953 const Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002954 Texture *texture =
2955 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05002956 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05002957}
2958
2959void Context::copyTexSubImage3D(GLenum target,
2960 GLint level,
2961 GLint xoffset,
2962 GLint yoffset,
2963 GLint zoffset,
2964 GLint x,
2965 GLint y,
2966 GLsizei width,
2967 GLsizei height)
2968{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04002969 if (width == 0 || height == 0)
2970 {
2971 return;
2972 }
2973
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002974 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002975 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002976
Jamie Madillc29968b2016-01-20 11:17:23 -05002977 Offset destOffset(xoffset, yoffset, zoffset);
2978 Rectangle sourceArea(x, y, width, height);
2979
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002980 const Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002981 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05002982 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05002983}
2984
2985void Context::framebufferTexture2D(GLenum target,
2986 GLenum attachment,
2987 GLenum textarget,
2988 GLuint texture,
2989 GLint level)
2990{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002991 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05002992 ASSERT(framebuffer);
2993
2994 if (texture != 0)
2995 {
2996 Texture *textureObj = getTexture(texture);
2997
2998 ImageIndex index = ImageIndex::MakeInvalid();
2999
3000 if (textarget == GL_TEXTURE_2D)
3001 {
3002 index = ImageIndex::Make2D(level);
3003 }
JiangYizhoubddc46b2016-12-09 09:50:51 +08003004 else if (textarget == GL_TEXTURE_2D_MULTISAMPLE)
3005 {
3006 ASSERT(level == 0);
3007 index = ImageIndex::Make2DMultisample();
3008 }
Jamie Madillc29968b2016-01-20 11:17:23 -05003009 else
3010 {
3011 ASSERT(IsCubeMapTextureTarget(textarget));
3012 index = ImageIndex::MakeCube(textarget, level);
3013 }
3014
Jamie Madilla02315b2017-02-23 14:14:47 -05003015 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003016 }
3017 else
3018 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003019 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003020 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003021
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003022 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003023}
3024
3025void Context::framebufferRenderbuffer(GLenum target,
3026 GLenum attachment,
3027 GLenum renderbuffertarget,
3028 GLuint renderbuffer)
3029{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003030 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003031 ASSERT(framebuffer);
3032
3033 if (renderbuffer != 0)
3034 {
3035 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003036
3037 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex::MakeInvalid(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003038 renderbufferObject);
3039 }
3040 else
3041 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003042 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003043 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003044
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003045 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003046}
3047
3048void Context::framebufferTextureLayer(GLenum target,
3049 GLenum attachment,
3050 GLuint texture,
3051 GLint level,
3052 GLint layer)
3053{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003054 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003055 ASSERT(framebuffer);
3056
3057 if (texture != 0)
3058 {
3059 Texture *textureObject = getTexture(texture);
3060
3061 ImageIndex index = ImageIndex::MakeInvalid();
3062
3063 if (textureObject->getTarget() == GL_TEXTURE_3D)
3064 {
3065 index = ImageIndex::Make3D(level, layer);
3066 }
3067 else
3068 {
3069 ASSERT(textureObject->getTarget() == GL_TEXTURE_2D_ARRAY);
3070 index = ImageIndex::Make2DArray(level, layer);
3071 }
3072
Jamie Madilla02315b2017-02-23 14:14:47 -05003073 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003074 }
3075 else
3076 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003077 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003078 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003079
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003080 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003081}
3082
3083void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3084{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003085 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003086 ASSERT(framebuffer);
3087 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003088 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003089}
3090
3091void Context::readBuffer(GLenum mode)
3092{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003093 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003094 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003095 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003096}
3097
3098void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3099{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003100 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003101 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003102
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003103 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003104 ASSERT(framebuffer);
3105
3106 // The specification isn't clear what should be done when the framebuffer isn't complete.
3107 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003108 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003109}
3110
3111void Context::invalidateFramebuffer(GLenum target,
3112 GLsizei numAttachments,
3113 const GLenum *attachments)
3114{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003115 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003116 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003117
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003118 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003119 ASSERT(framebuffer);
3120
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003121 if (framebuffer->checkStatus(this) != GL_FRAMEBUFFER_COMPLETE)
Jamie Madillc29968b2016-01-20 11:17:23 -05003122 {
Jamie Madill437fa652016-05-03 15:13:24 -04003123 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003124 }
Jamie Madill437fa652016-05-03 15:13:24 -04003125
Jamie Madill4928b7c2017-06-20 12:57:39 -04003126 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003127}
3128
3129void Context::invalidateSubFramebuffer(GLenum target,
3130 GLsizei numAttachments,
3131 const GLenum *attachments,
3132 GLint x,
3133 GLint y,
3134 GLsizei width,
3135 GLsizei height)
3136{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003137 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003138 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003139
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003140 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003141 ASSERT(framebuffer);
3142
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003143 if (framebuffer->checkStatus(this) != GL_FRAMEBUFFER_COMPLETE)
Jamie Madillc29968b2016-01-20 11:17:23 -05003144 {
Jamie Madill437fa652016-05-03 15:13:24 -04003145 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003146 }
Jamie Madill437fa652016-05-03 15:13:24 -04003147
3148 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003149 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003150}
3151
Jamie Madill73a84962016-02-12 09:27:23 -05003152void Context::texImage2D(GLenum target,
3153 GLint level,
3154 GLint internalformat,
3155 GLsizei width,
3156 GLsizei height,
3157 GLint border,
3158 GLenum format,
3159 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003160 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003161{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003162 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003163
3164 Extents size(width, height, 1);
3165 Texture *texture =
3166 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003167 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3168 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003169}
3170
3171void Context::texImage3D(GLenum target,
3172 GLint level,
3173 GLint internalformat,
3174 GLsizei width,
3175 GLsizei height,
3176 GLsizei depth,
3177 GLint border,
3178 GLenum format,
3179 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003180 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003181{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003182 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003183
3184 Extents size(width, height, depth);
3185 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003186 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3187 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003188}
3189
3190void Context::texSubImage2D(GLenum target,
3191 GLint level,
3192 GLint xoffset,
3193 GLint yoffset,
3194 GLsizei width,
3195 GLsizei height,
3196 GLenum format,
3197 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003198 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003199{
3200 // Zero sized uploads are valid but no-ops
3201 if (width == 0 || height == 0)
3202 {
3203 return;
3204 }
3205
Jamie Madillad9f24e2016-02-12 09:27:24 -05003206 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003207
3208 Box area(xoffset, yoffset, 0, width, height, 1);
3209 Texture *texture =
3210 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003211 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3212 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003213}
3214
3215void Context::texSubImage3D(GLenum target,
3216 GLint level,
3217 GLint xoffset,
3218 GLint yoffset,
3219 GLint zoffset,
3220 GLsizei width,
3221 GLsizei height,
3222 GLsizei depth,
3223 GLenum format,
3224 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003225 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003226{
3227 // Zero sized uploads are valid but no-ops
3228 if (width == 0 || height == 0 || depth == 0)
3229 {
3230 return;
3231 }
3232
Jamie Madillad9f24e2016-02-12 09:27:24 -05003233 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003234
3235 Box area(xoffset, yoffset, zoffset, width, height, depth);
3236 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003237 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3238 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003239}
3240
3241void Context::compressedTexImage2D(GLenum target,
3242 GLint level,
3243 GLenum internalformat,
3244 GLsizei width,
3245 GLsizei height,
3246 GLint border,
3247 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003248 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003249{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003250 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003251
3252 Extents size(width, height, 1);
3253 Texture *texture =
3254 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003255 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003256 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003257 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003258}
3259
3260void Context::compressedTexImage3D(GLenum target,
3261 GLint level,
3262 GLenum internalformat,
3263 GLsizei width,
3264 GLsizei height,
3265 GLsizei depth,
3266 GLint border,
3267 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003268 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003269{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003270 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003271
3272 Extents size(width, height, depth);
3273 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003274 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003275 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003276 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003277}
3278
3279void Context::compressedTexSubImage2D(GLenum target,
3280 GLint level,
3281 GLint xoffset,
3282 GLint yoffset,
3283 GLsizei width,
3284 GLsizei height,
3285 GLenum format,
3286 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003287 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003288{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003289 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003290
3291 Box area(xoffset, yoffset, 0, width, height, 1);
3292 Texture *texture =
3293 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003294 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003295 format, imageSize,
3296 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003297}
3298
3299void Context::compressedTexSubImage3D(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 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003309 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003310{
3311 // Zero sized uploads are valid but no-ops
3312 if (width == 0 || height == 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->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003322 format, imageSize,
3323 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003324}
3325
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003326void Context::generateMipmap(GLenum target)
3327{
3328 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003329 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003330}
3331
Geoff Lang97073d12016-04-20 10:42:34 -07003332void Context::copyTextureCHROMIUM(GLuint sourceId,
Geoff Langfc72a072017-03-24 14:52:39 -04003333 GLint sourceLevel,
3334 GLenum destTarget,
Geoff Lang97073d12016-04-20 10:42:34 -07003335 GLuint destId,
Geoff Langfc72a072017-03-24 14:52:39 -04003336 GLint destLevel,
Geoff Lang97073d12016-04-20 10:42:34 -07003337 GLint internalFormat,
3338 GLenum destType,
3339 GLboolean unpackFlipY,
3340 GLboolean unpackPremultiplyAlpha,
3341 GLboolean unpackUnmultiplyAlpha)
3342{
3343 syncStateForTexImage();
3344
3345 gl::Texture *sourceTexture = getTexture(sourceId);
3346 gl::Texture *destTexture = getTexture(destId);
Geoff Langfc72a072017-03-24 14:52:39 -04003347 handleError(destTexture->copyTexture(
3348 this, destTarget, destLevel, internalFormat, destType, sourceLevel, unpackFlipY == GL_TRUE,
3349 unpackPremultiplyAlpha == GL_TRUE, unpackUnmultiplyAlpha == GL_TRUE, sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003350}
3351
3352void Context::copySubTextureCHROMIUM(GLuint sourceId,
Geoff Langfc72a072017-03-24 14:52:39 -04003353 GLint sourceLevel,
3354 GLenum destTarget,
Geoff Lang97073d12016-04-20 10:42:34 -07003355 GLuint destId,
Geoff Langfc72a072017-03-24 14:52:39 -04003356 GLint destLevel,
Geoff Lang97073d12016-04-20 10:42:34 -07003357 GLint xoffset,
3358 GLint yoffset,
3359 GLint x,
3360 GLint y,
3361 GLsizei width,
3362 GLsizei height,
3363 GLboolean unpackFlipY,
3364 GLboolean unpackPremultiplyAlpha,
3365 GLboolean unpackUnmultiplyAlpha)
3366{
3367 // Zero sized copies are valid but no-ops
3368 if (width == 0 || height == 0)
3369 {
3370 return;
3371 }
3372
3373 syncStateForTexImage();
3374
3375 gl::Texture *sourceTexture = getTexture(sourceId);
3376 gl::Texture *destTexture = getTexture(destId);
3377 Offset offset(xoffset, yoffset, 0);
3378 Rectangle area(x, y, width, height);
Geoff Langfc72a072017-03-24 14:52:39 -04003379 handleError(destTexture->copySubTexture(
3380 this, destTarget, destLevel, offset, sourceLevel, area, unpackFlipY == GL_TRUE,
3381 unpackPremultiplyAlpha == GL_TRUE, unpackUnmultiplyAlpha == GL_TRUE, sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003382}
3383
Geoff Lang47110bf2016-04-20 11:13:22 -07003384void Context::compressedCopyTextureCHROMIUM(GLuint sourceId, GLuint destId)
3385{
3386 syncStateForTexImage();
3387
3388 gl::Texture *sourceTexture = getTexture(sourceId);
3389 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05003390 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07003391}
3392
Geoff Lang496c02d2016-10-20 11:38:11 -07003393void Context::getBufferPointerv(GLenum target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03003394{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003395 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003396 ASSERT(buffer);
3397
Geoff Lang496c02d2016-10-20 11:38:11 -07003398 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03003399}
3400
Jamie Madill876429b2017-04-20 15:46:24 -04003401void *Context::mapBuffer(GLenum target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003402{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003403 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003404 ASSERT(buffer);
3405
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003406 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003407 if (error.isError())
3408 {
Jamie Madill437fa652016-05-03 15:13:24 -04003409 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003410 return nullptr;
3411 }
3412
3413 return buffer->getMapPointer();
3414}
3415
3416GLboolean Context::unmapBuffer(GLenum target)
3417{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003418 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003419 ASSERT(buffer);
3420
3421 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003422 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03003423 if (error.isError())
3424 {
Jamie Madill437fa652016-05-03 15:13:24 -04003425 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003426 return GL_FALSE;
3427 }
3428
3429 return result;
3430}
3431
Jamie Madill876429b2017-04-20 15:46:24 -04003432void *Context::mapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003433{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003434 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003435 ASSERT(buffer);
3436
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003437 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003438 if (error.isError())
3439 {
Jamie Madill437fa652016-05-03 15:13:24 -04003440 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003441 return nullptr;
3442 }
3443
3444 return buffer->getMapPointer();
3445}
3446
3447void Context::flushMappedBufferRange(GLenum /*target*/, GLintptr /*offset*/, GLsizeiptr /*length*/)
3448{
3449 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
3450}
3451
Jamie Madillad9f24e2016-02-12 09:27:24 -05003452void Context::syncStateForReadPixels()
3453{
3454 syncRendererState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
3455}
3456
3457void Context::syncStateForTexImage()
3458{
3459 syncRendererState(mTexImageDirtyBits, mTexImageDirtyObjects);
3460}
3461
3462void Context::syncStateForClear()
3463{
3464 syncRendererState(mClearDirtyBits, mClearDirtyObjects);
3465}
3466
3467void Context::syncStateForBlit()
3468{
3469 syncRendererState(mBlitDirtyBits, mBlitDirtyObjects);
3470}
3471
Jamie Madillc20ab272016-06-09 07:20:46 -07003472void Context::activeTexture(GLenum texture)
3473{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003474 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003475}
3476
Jamie Madill876429b2017-04-20 15:46:24 -04003477void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003478{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003479 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07003480}
3481
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003482void Context::blendEquation(GLenum mode)
3483{
3484 mGLState.setBlendEquation(mode, mode);
3485}
3486
Jamie Madillc20ab272016-06-09 07:20:46 -07003487void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
3488{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003489 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003490}
3491
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003492void Context::blendFunc(GLenum sfactor, GLenum dfactor)
3493{
3494 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
3495}
3496
Jamie Madillc20ab272016-06-09 07:20:46 -07003497void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
3498{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003499 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003500}
3501
Jamie Madill876429b2017-04-20 15:46:24 -04003502void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003503{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003504 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003505}
3506
Jamie Madill876429b2017-04-20 15:46:24 -04003507void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07003508{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003509 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07003510}
3511
3512void Context::clearStencil(GLint s)
3513{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003514 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07003515}
3516
3517void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
3518{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003519 mGLState.setColorMask(red == GL_TRUE, green == GL_TRUE, blue == GL_TRUE, alpha == GL_TRUE);
Jamie Madillc20ab272016-06-09 07:20:46 -07003520}
3521
3522void Context::cullFace(GLenum mode)
3523{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003524 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003525}
3526
3527void Context::depthFunc(GLenum func)
3528{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003529 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07003530}
3531
3532void Context::depthMask(GLboolean flag)
3533{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003534 mGLState.setDepthMask(flag != GL_FALSE);
Jamie Madillc20ab272016-06-09 07:20:46 -07003535}
3536
Jamie Madill876429b2017-04-20 15:46:24 -04003537void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07003538{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003539 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07003540}
3541
3542void Context::disable(GLenum cap)
3543{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003544 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003545}
3546
3547void Context::disableVertexAttribArray(GLuint index)
3548{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003549 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003550}
3551
3552void Context::enable(GLenum cap)
3553{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003554 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003555}
3556
3557void Context::enableVertexAttribArray(GLuint index)
3558{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003559 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003560}
3561
3562void Context::frontFace(GLenum mode)
3563{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003564 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003565}
3566
3567void Context::hint(GLenum target, GLenum mode)
3568{
3569 switch (target)
3570 {
3571 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003572 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003573 break;
3574
3575 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003576 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003577 break;
3578
3579 default:
3580 UNREACHABLE();
3581 return;
3582 }
3583}
3584
3585void Context::lineWidth(GLfloat width)
3586{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003587 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07003588}
3589
3590void Context::pixelStorei(GLenum pname, GLint param)
3591{
3592 switch (pname)
3593 {
3594 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003595 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003596 break;
3597
3598 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003599 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003600 break;
3601
3602 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003603 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003604 break;
3605
3606 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003607 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003608 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003609 break;
3610
3611 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03003612 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003613 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003614 break;
3615
3616 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03003617 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003618 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003619 break;
3620
3621 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003622 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003623 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003624 break;
3625
3626 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003627 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003628 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003629 break;
3630
3631 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003632 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003633 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003634 break;
3635
3636 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003637 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003638 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003639 break;
3640
3641 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003642 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003643 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003644 break;
3645
3646 default:
3647 UNREACHABLE();
3648 return;
3649 }
3650}
3651
3652void Context::polygonOffset(GLfloat factor, GLfloat units)
3653{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003654 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07003655}
3656
Jamie Madill876429b2017-04-20 15:46:24 -04003657void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07003658{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003659 mGLState.setSampleCoverageParams(clamp01(value), invert == GL_TRUE);
Jamie Madillc20ab272016-06-09 07:20:46 -07003660}
3661
3662void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
3663{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003664 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07003665}
3666
3667void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
3668{
3669 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3670 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003671 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003672 }
3673
3674 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3675 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003676 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003677 }
3678}
3679
3680void Context::stencilMaskSeparate(GLenum face, GLuint mask)
3681{
3682 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3683 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003684 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003685 }
3686
3687 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3688 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003689 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003690 }
3691}
3692
3693void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
3694{
3695 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3696 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003697 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003698 }
3699
3700 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3701 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003702 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003703 }
3704}
3705
3706void Context::vertexAttrib1f(GLuint index, GLfloat x)
3707{
3708 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003709 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003710}
3711
3712void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
3713{
3714 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003715 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003716}
3717
3718void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
3719{
3720 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003721 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003722}
3723
3724void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
3725{
3726 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003727 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003728}
3729
3730void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
3731{
3732 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003733 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003734}
3735
3736void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
3737{
3738 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003739 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003740}
3741
3742void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
3743{
3744 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003745 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003746}
3747
3748void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
3749{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003750 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07003751}
3752
3753void Context::vertexAttribPointer(GLuint index,
3754 GLint size,
3755 GLenum type,
3756 GLboolean normalized,
3757 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04003758 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07003759{
Jamie Madill4928b7c2017-06-20 12:57:39 -04003760 mGLState.setVertexAttribState(this, index, mGLState.getTargetBuffer(GL_ARRAY_BUFFER), size,
3761 type, normalized == GL_TRUE, false, stride, ptr);
Jamie Madillc20ab272016-06-09 07:20:46 -07003762}
3763
Shao80957d92017-02-20 21:25:59 +08003764void Context::vertexAttribFormat(GLuint attribIndex,
3765 GLint size,
3766 GLenum type,
3767 GLboolean normalized,
3768 GLuint relativeOffset)
3769{
3770 mGLState.setVertexAttribFormat(attribIndex, size, type, normalized == GL_TRUE, false,
3771 relativeOffset);
3772}
3773
3774void Context::vertexAttribIFormat(GLuint attribIndex,
3775 GLint size,
3776 GLenum type,
3777 GLuint relativeOffset)
3778{
3779 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
3780}
3781
3782void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
3783{
3784 mGLState.setVertexAttribBinding(attribIndex, bindingIndex);
3785}
3786
3787void Context::setVertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
3788{
3789 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
3790}
3791
Jamie Madillc20ab272016-06-09 07:20:46 -07003792void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
3793{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003794 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07003795}
3796
3797void Context::vertexAttribIPointer(GLuint index,
3798 GLint size,
3799 GLenum type,
3800 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04003801 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07003802{
Jamie Madill4928b7c2017-06-20 12:57:39 -04003803 mGLState.setVertexAttribState(this, index, mGLState.getTargetBuffer(GL_ARRAY_BUFFER), size,
3804 type, false, true, stride, pointer);
Jamie Madillc20ab272016-06-09 07:20:46 -07003805}
3806
3807void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
3808{
3809 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003810 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003811}
3812
3813void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
3814{
3815 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003816 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003817}
3818
3819void Context::vertexAttribI4iv(GLuint index, const GLint *v)
3820{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003821 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07003822}
3823
3824void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
3825{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003826 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07003827}
3828
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003829void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
3830{
3831 const VertexAttribCurrentValueData &currentValues =
3832 getGLState().getVertexAttribCurrentValue(index);
3833 const VertexArray *vao = getGLState().getVertexArray();
3834 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3835 currentValues, pname, params);
3836}
3837
3838void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
3839{
3840 const VertexAttribCurrentValueData &currentValues =
3841 getGLState().getVertexAttribCurrentValue(index);
3842 const VertexArray *vao = getGLState().getVertexArray();
3843 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3844 currentValues, pname, params);
3845}
3846
3847void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
3848{
3849 const VertexAttribCurrentValueData &currentValues =
3850 getGLState().getVertexAttribCurrentValue(index);
3851 const VertexArray *vao = getGLState().getVertexArray();
3852 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3853 currentValues, pname, params);
3854}
3855
3856void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
3857{
3858 const VertexAttribCurrentValueData &currentValues =
3859 getGLState().getVertexAttribCurrentValue(index);
3860 const VertexArray *vao = getGLState().getVertexArray();
3861 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3862 currentValues, pname, params);
3863}
3864
Jamie Madill876429b2017-04-20 15:46:24 -04003865void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003866{
3867 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
3868 QueryVertexAttribPointerv(attrib, pname, pointer);
3869}
3870
Jamie Madillc20ab272016-06-09 07:20:46 -07003871void Context::debugMessageControl(GLenum source,
3872 GLenum type,
3873 GLenum severity,
3874 GLsizei count,
3875 const GLuint *ids,
3876 GLboolean enabled)
3877{
3878 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003879 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
3880 (enabled != GL_FALSE));
Jamie Madillc20ab272016-06-09 07:20:46 -07003881}
3882
3883void Context::debugMessageInsert(GLenum source,
3884 GLenum type,
3885 GLuint id,
3886 GLenum severity,
3887 GLsizei length,
3888 const GLchar *buf)
3889{
3890 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003891 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07003892}
3893
3894void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
3895{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003896 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07003897}
3898
3899GLuint Context::getDebugMessageLog(GLuint count,
3900 GLsizei bufSize,
3901 GLenum *sources,
3902 GLenum *types,
3903 GLuint *ids,
3904 GLenum *severities,
3905 GLsizei *lengths,
3906 GLchar *messageLog)
3907{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003908 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
3909 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07003910}
3911
3912void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
3913{
3914 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003915 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07003916}
3917
3918void Context::popDebugGroup()
3919{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003920 mGLState.getDebug().popGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07003921}
3922
Jamie Madill876429b2017-04-20 15:46:24 -04003923void Context::bufferData(GLenum target, GLsizeiptr size, const void *data, GLenum usage)
Jamie Madill29639852016-09-02 15:00:09 -04003924{
3925 Buffer *buffer = mGLState.getTargetBuffer(target);
3926 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08003927 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04003928}
3929
Jamie Madill876429b2017-04-20 15:46:24 -04003930void Context::bufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04003931{
3932 if (data == nullptr)
3933 {
3934 return;
3935 }
3936
3937 Buffer *buffer = mGLState.getTargetBuffer(target);
3938 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08003939 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04003940}
3941
Jamie Madillef300b12016-10-07 15:12:09 -04003942void Context::attachShader(GLuint program, GLuint shader)
3943{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05003944 auto programObject = mState.mShaderPrograms->getProgram(program);
3945 auto shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04003946 ASSERT(programObject && shaderObject);
3947 programObject->attachShader(shaderObject);
3948}
3949
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003950const Workarounds &Context::getWorkarounds() const
3951{
3952 return mWorkarounds;
3953}
3954
Jamie Madillb0817d12016-11-01 15:48:31 -04003955void Context::copyBufferSubData(GLenum readTarget,
3956 GLenum writeTarget,
3957 GLintptr readOffset,
3958 GLintptr writeOffset,
3959 GLsizeiptr size)
3960{
3961 // if size is zero, the copy is a successful no-op
3962 if (size == 0)
3963 {
3964 return;
3965 }
3966
3967 // TODO(jmadill): cache these.
3968 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
3969 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
3970
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003971 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04003972}
3973
Jamie Madill01a80ee2016-11-07 12:06:18 -05003974void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
3975{
3976 Program *programObject = getProgram(program);
3977 // TODO(jmadill): Re-use this from the validation if possible.
3978 ASSERT(programObject);
3979 programObject->bindAttributeLocation(index, name);
3980}
3981
3982void Context::bindBuffer(GLenum target, GLuint buffer)
3983{
3984 switch (target)
3985 {
3986 case GL_ARRAY_BUFFER:
3987 bindArrayBuffer(buffer);
3988 break;
3989 case GL_ELEMENT_ARRAY_BUFFER:
3990 bindElementArrayBuffer(buffer);
3991 break;
3992 case GL_COPY_READ_BUFFER:
3993 bindCopyReadBuffer(buffer);
3994 break;
3995 case GL_COPY_WRITE_BUFFER:
3996 bindCopyWriteBuffer(buffer);
3997 break;
3998 case GL_PIXEL_PACK_BUFFER:
3999 bindPixelPackBuffer(buffer);
4000 break;
4001 case GL_PIXEL_UNPACK_BUFFER:
4002 bindPixelUnpackBuffer(buffer);
4003 break;
4004 case GL_UNIFORM_BUFFER:
4005 bindGenericUniformBuffer(buffer);
4006 break;
4007 case GL_TRANSFORM_FEEDBACK_BUFFER:
4008 bindGenericTransformFeedbackBuffer(buffer);
4009 break;
Geoff Lang3b573612016-10-31 14:08:10 -04004010 case GL_ATOMIC_COUNTER_BUFFER:
Jiajia Qin6eafb042016-12-27 17:04:07 +08004011 bindGenericAtomicCounterBuffer(buffer);
Geoff Lang3b573612016-10-31 14:08:10 -04004012 break;
4013 case GL_SHADER_STORAGE_BUFFER:
Jiajia Qinf546e7d2017-03-27 14:12:59 +08004014 bindGenericShaderStorageBuffer(buffer);
Geoff Lang3b573612016-10-31 14:08:10 -04004015 break;
4016 case GL_DRAW_INDIRECT_BUFFER:
Jiajia Qin9d7d0b12016-11-29 16:30:31 +08004017 bindDrawIndirectBuffer(buffer);
Geoff Lang3b573612016-10-31 14:08:10 -04004018 break;
4019 case GL_DISPATCH_INDIRECT_BUFFER:
Geoff Lang9f090372016-12-02 10:20:43 -05004020 if (buffer != 0)
4021 {
4022 // Binding buffers to this binding point is not implemented yet.
4023 UNIMPLEMENTED();
4024 }
Geoff Lang3b573612016-10-31 14:08:10 -04004025 break;
Jamie Madill01a80ee2016-11-07 12:06:18 -05004026
4027 default:
4028 UNREACHABLE();
4029 break;
4030 }
4031}
4032
Jiajia Qin6eafb042016-12-27 17:04:07 +08004033void Context::bindBufferBase(GLenum target, GLuint index, GLuint buffer)
4034{
4035 bindBufferRange(target, index, buffer, 0, 0);
4036}
4037
4038void Context::bindBufferRange(GLenum target,
4039 GLuint index,
4040 GLuint buffer,
4041 GLintptr offset,
4042 GLsizeiptr size)
4043{
4044 switch (target)
4045 {
4046 case GL_TRANSFORM_FEEDBACK_BUFFER:
4047 bindIndexedTransformFeedbackBuffer(buffer, index, offset, size);
4048 bindGenericTransformFeedbackBuffer(buffer);
4049 break;
4050 case GL_UNIFORM_BUFFER:
4051 bindIndexedUniformBuffer(buffer, index, offset, size);
4052 bindGenericUniformBuffer(buffer);
4053 break;
4054 case GL_ATOMIC_COUNTER_BUFFER:
4055 bindIndexedAtomicCounterBuffer(buffer, index, offset, size);
4056 bindGenericAtomicCounterBuffer(buffer);
4057 break;
4058 case GL_SHADER_STORAGE_BUFFER:
Jiajia Qinf546e7d2017-03-27 14:12:59 +08004059 bindIndexedShaderStorageBuffer(buffer, index, offset, size);
4060 bindGenericShaderStorageBuffer(buffer);
Jiajia Qin6eafb042016-12-27 17:04:07 +08004061 break;
4062 default:
4063 UNREACHABLE();
4064 break;
4065 }
4066}
4067
Jamie Madill01a80ee2016-11-07 12:06:18 -05004068void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
4069{
4070 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4071 {
4072 bindReadFramebuffer(framebuffer);
4073 }
4074
4075 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4076 {
4077 bindDrawFramebuffer(framebuffer);
4078 }
4079}
4080
4081void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4082{
4083 ASSERT(target == GL_RENDERBUFFER);
4084 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004085 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04004086 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004087}
4088
JiangYizhoubddc46b2016-12-09 09:50:51 +08004089void Context::texStorage2DMultisample(GLenum target,
4090 GLsizei samples,
4091 GLenum internalformat,
4092 GLsizei width,
4093 GLsizei height,
4094 GLboolean fixedsamplelocations)
4095{
4096 Extents size(width, height, 1);
4097 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05004098 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
JiangYizhoubddc46b2016-12-09 09:50:51 +08004099 fixedsamplelocations));
4100}
4101
4102void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4103{
Jamie Madilldd43e6c2017-03-24 14:18:49 -04004104 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
JiangYizhoubddc46b2016-12-09 09:50:51 +08004105 const Framebuffer *framebuffer = mGLState.getReadFramebuffer();
4106
4107 switch (pname)
4108 {
4109 case GL_SAMPLE_POSITION:
4110 handleError(framebuffer->getSamplePosition(index, val));
4111 break;
4112 default:
4113 UNREACHABLE();
4114 }
4115}
4116
Jamie Madille8fb6402017-02-14 17:56:40 -05004117void Context::renderbufferStorage(GLenum target,
4118 GLenum internalformat,
4119 GLsizei width,
4120 GLsizei height)
4121{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004122 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4123 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
4124
Jamie Madille8fb6402017-02-14 17:56:40 -05004125 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04004126 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004127}
4128
4129void Context::renderbufferStorageMultisample(GLenum target,
4130 GLsizei samples,
4131 GLenum internalformat,
4132 GLsizei width,
4133 GLsizei height)
4134{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004135 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4136 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05004137
4138 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004139 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04004140 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004141}
4142
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004143void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
4144{
4145 const FenceSync *syncObject = getFenceSync(sync);
Geoff Lang82483b92017-04-11 15:33:00 -04004146 handleError(QuerySynciv(syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004147}
4148
JiangYizhoue18e6392017-02-20 10:32:23 +08004149void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
4150{
4151 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4152 QueryFramebufferParameteriv(framebuffer, pname, params);
4153}
4154
4155void Context::setFramebufferParameteri(GLenum target, GLenum pname, GLint param)
4156{
4157 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4158 SetFramebufferParameteri(framebuffer, pname, param);
4159}
4160
Jamie Madille14951e2017-03-09 18:55:16 -05004161Error Context::getScratchBuffer(size_t requestedSize, angle::MemoryBuffer **scratchBufferOut) const
4162{
4163 if (!mScratchBuffer.get(requestedSize, scratchBufferOut))
4164 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004165 return OutOfMemory() << "Failed to allocate internal buffer.";
Jamie Madille14951e2017-03-09 18:55:16 -05004166 }
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004167 return NoError();
Jamie Madille14951e2017-03-09 18:55:16 -05004168}
4169
Xinghua Cao2b396592017-03-29 15:36:04 +08004170void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
4171{
4172 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
4173 {
4174 return;
4175 }
4176
Jamie Madillfe548342017-06-19 11:13:24 -04004177 mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ);
Xinghua Cao2b396592017-03-29 15:36:04 +08004178}
4179
JiangYizhou165361c2017-06-07 14:56:57 +08004180void Context::texStorage2D(GLenum target,
4181 GLsizei levels,
4182 GLenum internalFormat,
4183 GLsizei width,
4184 GLsizei height)
4185{
4186 Extents size(width, height, 1);
4187 Texture *texture = getTargetTexture(target);
4188 handleError(texture->setStorage(this, target, levels, internalFormat, size));
4189}
4190
4191void Context::texStorage3D(GLenum target,
4192 GLsizei levels,
4193 GLenum internalFormat,
4194 GLsizei width,
4195 GLsizei height,
4196 GLsizei depth)
4197{
4198 Extents size(width, height, depth);
4199 Texture *texture = getTargetTexture(target);
4200 handleError(texture->setStorage(this, target, levels, internalFormat, size));
4201}
4202
Jamie Madillc1d770e2017-04-13 17:31:24 -04004203GLenum Context::checkFramebufferStatus(GLenum target)
4204{
4205 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4206 ASSERT(framebuffer);
4207
4208 return framebuffer->checkStatus(this);
4209}
4210
4211void Context::compileShader(GLuint shader)
4212{
4213 Shader *shaderObject = GetValidShader(this, shader);
4214 if (!shaderObject)
4215 {
4216 return;
4217 }
4218 shaderObject->compile(this);
4219}
4220
4221void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
4222{
4223 for (int i = 0; i < n; i++)
4224 {
4225 deleteBuffer(buffers[i]);
4226 }
4227}
4228
4229void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
4230{
4231 for (int i = 0; i < n; i++)
4232 {
4233 if (framebuffers[i] != 0)
4234 {
4235 deleteFramebuffer(framebuffers[i]);
4236 }
4237 }
4238}
4239
4240void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
4241{
4242 for (int i = 0; i < n; i++)
4243 {
4244 deleteRenderbuffer(renderbuffers[i]);
4245 }
4246}
4247
4248void Context::deleteTextures(GLsizei n, const GLuint *textures)
4249{
4250 for (int i = 0; i < n; i++)
4251 {
4252 if (textures[i] != 0)
4253 {
4254 deleteTexture(textures[i]);
4255 }
4256 }
4257}
4258
4259void Context::detachShader(GLuint program, GLuint shader)
4260{
4261 Program *programObject = getProgram(program);
4262 ASSERT(programObject);
4263
4264 Shader *shaderObject = getShader(shader);
4265 ASSERT(shaderObject);
4266
4267 programObject->detachShader(this, shaderObject);
4268}
4269
4270void Context::genBuffers(GLsizei n, GLuint *buffers)
4271{
4272 for (int i = 0; i < n; i++)
4273 {
4274 buffers[i] = createBuffer();
4275 }
4276}
4277
4278void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
4279{
4280 for (int i = 0; i < n; i++)
4281 {
4282 framebuffers[i] = createFramebuffer();
4283 }
4284}
4285
4286void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
4287{
4288 for (int i = 0; i < n; i++)
4289 {
4290 renderbuffers[i] = createRenderbuffer();
4291 }
4292}
4293
4294void Context::genTextures(GLsizei n, GLuint *textures)
4295{
4296 for (int i = 0; i < n; i++)
4297 {
4298 textures[i] = createTexture();
4299 }
4300}
4301
4302void Context::getActiveAttrib(GLuint program,
4303 GLuint index,
4304 GLsizei bufsize,
4305 GLsizei *length,
4306 GLint *size,
4307 GLenum *type,
4308 GLchar *name)
4309{
4310 Program *programObject = getProgram(program);
4311 ASSERT(programObject);
4312 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
4313}
4314
4315void Context::getActiveUniform(GLuint program,
4316 GLuint index,
4317 GLsizei bufsize,
4318 GLsizei *length,
4319 GLint *size,
4320 GLenum *type,
4321 GLchar *name)
4322{
4323 Program *programObject = getProgram(program);
4324 ASSERT(programObject);
4325 programObject->getActiveUniform(index, bufsize, length, size, type, name);
4326}
4327
4328void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
4329{
4330 Program *programObject = getProgram(program);
4331 ASSERT(programObject);
4332 programObject->getAttachedShaders(maxcount, count, shaders);
4333}
4334
4335GLint Context::getAttribLocation(GLuint program, const GLchar *name)
4336{
4337 Program *programObject = getProgram(program);
4338 ASSERT(programObject);
4339 return programObject->getAttributeLocation(name);
4340}
4341
4342void Context::getBooleanv(GLenum pname, GLboolean *params)
4343{
4344 GLenum nativeType;
4345 unsigned int numParams = 0;
4346 getQueryParameterInfo(pname, &nativeType, &numParams);
4347
4348 if (nativeType == GL_BOOL)
4349 {
4350 getBooleanvImpl(pname, params);
4351 }
4352 else
4353 {
4354 CastStateValues(this, nativeType, pname, numParams, params);
4355 }
4356}
4357
4358void Context::getFloatv(GLenum pname, GLfloat *params)
4359{
4360 GLenum nativeType;
4361 unsigned int numParams = 0;
4362 getQueryParameterInfo(pname, &nativeType, &numParams);
4363
4364 if (nativeType == GL_FLOAT)
4365 {
4366 getFloatvImpl(pname, params);
4367 }
4368 else
4369 {
4370 CastStateValues(this, nativeType, pname, numParams, params);
4371 }
4372}
4373
4374void Context::getIntegerv(GLenum pname, GLint *params)
4375{
4376 GLenum nativeType;
4377 unsigned int numParams = 0;
4378 getQueryParameterInfo(pname, &nativeType, &numParams);
4379
4380 if (nativeType == GL_INT)
4381 {
4382 getIntegervImpl(pname, params);
4383 }
4384 else
4385 {
4386 CastStateValues(this, nativeType, pname, numParams, params);
4387 }
4388}
4389
4390void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
4391{
4392 Program *programObject = getProgram(program);
4393 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04004394 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004395}
4396
Jamie Madillbe849e42017-05-02 15:49:00 -04004397void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04004398{
4399 Program *programObject = getProgram(program);
4400 ASSERT(programObject);
4401 programObject->getInfoLog(bufsize, length, infolog);
4402}
4403
4404void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
4405{
4406 Shader *shaderObject = getShader(shader);
4407 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004408 QueryShaderiv(this, shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004409}
4410
4411void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
4412{
4413 Shader *shaderObject = getShader(shader);
4414 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004415 shaderObject->getInfoLog(this, bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004416}
4417
4418void Context::getShaderPrecisionFormat(GLenum shadertype,
4419 GLenum precisiontype,
4420 GLint *range,
4421 GLint *precision)
4422{
4423 // TODO(jmadill): Compute shaders.
4424
4425 switch (shadertype)
4426 {
4427 case GL_VERTEX_SHADER:
4428 switch (precisiontype)
4429 {
4430 case GL_LOW_FLOAT:
4431 mCaps.vertexLowpFloat.get(range, precision);
4432 break;
4433 case GL_MEDIUM_FLOAT:
4434 mCaps.vertexMediumpFloat.get(range, precision);
4435 break;
4436 case GL_HIGH_FLOAT:
4437 mCaps.vertexHighpFloat.get(range, precision);
4438 break;
4439
4440 case GL_LOW_INT:
4441 mCaps.vertexLowpInt.get(range, precision);
4442 break;
4443 case GL_MEDIUM_INT:
4444 mCaps.vertexMediumpInt.get(range, precision);
4445 break;
4446 case GL_HIGH_INT:
4447 mCaps.vertexHighpInt.get(range, precision);
4448 break;
4449
4450 default:
4451 UNREACHABLE();
4452 return;
4453 }
4454 break;
4455
4456 case GL_FRAGMENT_SHADER:
4457 switch (precisiontype)
4458 {
4459 case GL_LOW_FLOAT:
4460 mCaps.fragmentLowpFloat.get(range, precision);
4461 break;
4462 case GL_MEDIUM_FLOAT:
4463 mCaps.fragmentMediumpFloat.get(range, precision);
4464 break;
4465 case GL_HIGH_FLOAT:
4466 mCaps.fragmentHighpFloat.get(range, precision);
4467 break;
4468
4469 case GL_LOW_INT:
4470 mCaps.fragmentLowpInt.get(range, precision);
4471 break;
4472 case GL_MEDIUM_INT:
4473 mCaps.fragmentMediumpInt.get(range, precision);
4474 break;
4475 case GL_HIGH_INT:
4476 mCaps.fragmentHighpInt.get(range, precision);
4477 break;
4478
4479 default:
4480 UNREACHABLE();
4481 return;
4482 }
4483 break;
4484
4485 default:
4486 UNREACHABLE();
4487 return;
4488 }
4489}
4490
4491void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
4492{
4493 Shader *shaderObject = getShader(shader);
4494 ASSERT(shaderObject);
4495 shaderObject->getSource(bufsize, length, source);
4496}
4497
4498void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
4499{
4500 Program *programObject = getProgram(program);
4501 ASSERT(programObject);
4502 programObject->getUniformfv(location, params);
4503}
4504
4505void Context::getUniformiv(GLuint program, GLint location, GLint *params)
4506{
4507 Program *programObject = getProgram(program);
4508 ASSERT(programObject);
4509 programObject->getUniformiv(location, params);
4510}
4511
4512GLint Context::getUniformLocation(GLuint program, const GLchar *name)
4513{
4514 Program *programObject = getProgram(program);
4515 ASSERT(programObject);
4516 return programObject->getUniformLocation(name);
4517}
4518
4519GLboolean Context::isBuffer(GLuint buffer)
4520{
4521 if (buffer == 0)
4522 {
4523 return GL_FALSE;
4524 }
4525
4526 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
4527}
4528
4529GLboolean Context::isEnabled(GLenum cap)
4530{
4531 return mGLState.getEnableFeature(cap);
4532}
4533
4534GLboolean Context::isFramebuffer(GLuint framebuffer)
4535{
4536 if (framebuffer == 0)
4537 {
4538 return GL_FALSE;
4539 }
4540
4541 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
4542}
4543
4544GLboolean Context::isProgram(GLuint program)
4545{
4546 if (program == 0)
4547 {
4548 return GL_FALSE;
4549 }
4550
4551 return (getProgram(program) ? GL_TRUE : GL_FALSE);
4552}
4553
4554GLboolean Context::isRenderbuffer(GLuint renderbuffer)
4555{
4556 if (renderbuffer == 0)
4557 {
4558 return GL_FALSE;
4559 }
4560
4561 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
4562}
4563
4564GLboolean Context::isShader(GLuint shader)
4565{
4566 if (shader == 0)
4567 {
4568 return GL_FALSE;
4569 }
4570
4571 return (getShader(shader) ? GL_TRUE : GL_FALSE);
4572}
4573
4574GLboolean Context::isTexture(GLuint texture)
4575{
4576 if (texture == 0)
4577 {
4578 return GL_FALSE;
4579 }
4580
4581 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
4582}
4583
4584void Context::linkProgram(GLuint program)
4585{
4586 Program *programObject = getProgram(program);
4587 ASSERT(programObject);
4588 handleError(programObject->link(this));
4589}
4590
4591void Context::releaseShaderCompiler()
4592{
Jamie Madill4928b7c2017-06-20 12:57:39 -04004593 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004594}
4595
4596void Context::shaderBinary(GLsizei n,
4597 const GLuint *shaders,
4598 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04004599 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04004600 GLsizei length)
4601{
4602 // No binary shader formats are supported.
4603 UNIMPLEMENTED();
4604}
4605
4606void Context::shaderSource(GLuint shader,
4607 GLsizei count,
4608 const GLchar *const *string,
4609 const GLint *length)
4610{
4611 Shader *shaderObject = getShader(shader);
4612 ASSERT(shaderObject);
4613 shaderObject->setSource(count, string, length);
4614}
4615
4616void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
4617{
4618 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
4619}
4620
4621void Context::stencilMask(GLuint mask)
4622{
4623 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
4624}
4625
4626void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
4627{
4628 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
4629}
4630
4631void Context::uniform1f(GLint location, GLfloat x)
4632{
4633 Program *program = mGLState.getProgram();
4634 program->setUniform1fv(location, 1, &x);
4635}
4636
4637void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
4638{
4639 Program *program = mGLState.getProgram();
4640 program->setUniform1fv(location, count, v);
4641}
4642
4643void Context::uniform1i(GLint location, GLint x)
4644{
4645 Program *program = mGLState.getProgram();
4646 program->setUniform1iv(location, 1, &x);
4647}
4648
4649void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
4650{
4651 Program *program = mGLState.getProgram();
4652 program->setUniform1iv(location, count, v);
4653}
4654
4655void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
4656{
4657 GLfloat xy[2] = {x, y};
4658 Program *program = mGLState.getProgram();
4659 program->setUniform2fv(location, 1, xy);
4660}
4661
4662void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
4663{
4664 Program *program = mGLState.getProgram();
4665 program->setUniform2fv(location, count, v);
4666}
4667
4668void Context::uniform2i(GLint location, GLint x, GLint y)
4669{
4670 GLint xy[2] = {x, y};
4671 Program *program = mGLState.getProgram();
4672 program->setUniform2iv(location, 1, xy);
4673}
4674
4675void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
4676{
4677 Program *program = mGLState.getProgram();
4678 program->setUniform2iv(location, count, v);
4679}
4680
4681void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
4682{
4683 GLfloat xyz[3] = {x, y, z};
4684 Program *program = mGLState.getProgram();
4685 program->setUniform3fv(location, 1, xyz);
4686}
4687
4688void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
4689{
4690 Program *program = mGLState.getProgram();
4691 program->setUniform3fv(location, count, v);
4692}
4693
4694void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
4695{
4696 GLint xyz[3] = {x, y, z};
4697 Program *program = mGLState.getProgram();
4698 program->setUniform3iv(location, 1, xyz);
4699}
4700
4701void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
4702{
4703 Program *program = mGLState.getProgram();
4704 program->setUniform3iv(location, count, v);
4705}
4706
4707void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4708{
4709 GLfloat xyzw[4] = {x, y, z, w};
4710 Program *program = mGLState.getProgram();
4711 program->setUniform4fv(location, 1, xyzw);
4712}
4713
4714void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
4715{
4716 Program *program = mGLState.getProgram();
4717 program->setUniform4fv(location, count, v);
4718}
4719
4720void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
4721{
4722 GLint xyzw[4] = {x, y, z, w};
4723 Program *program = mGLState.getProgram();
4724 program->setUniform4iv(location, 1, xyzw);
4725}
4726
4727void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
4728{
4729 Program *program = mGLState.getProgram();
4730 program->setUniform4iv(location, count, v);
4731}
4732
4733void Context::uniformMatrix2fv(GLint location,
4734 GLsizei count,
4735 GLboolean transpose,
4736 const GLfloat *value)
4737{
4738 Program *program = mGLState.getProgram();
4739 program->setUniformMatrix2fv(location, count, transpose, value);
4740}
4741
4742void Context::uniformMatrix3fv(GLint location,
4743 GLsizei count,
4744 GLboolean transpose,
4745 const GLfloat *value)
4746{
4747 Program *program = mGLState.getProgram();
4748 program->setUniformMatrix3fv(location, count, transpose, value);
4749}
4750
4751void Context::uniformMatrix4fv(GLint location,
4752 GLsizei count,
4753 GLboolean transpose,
4754 const GLfloat *value)
4755{
4756 Program *program = mGLState.getProgram();
4757 program->setUniformMatrix4fv(location, count, transpose, value);
4758}
4759
4760void Context::validateProgram(GLuint program)
4761{
4762 Program *programObject = getProgram(program);
4763 ASSERT(programObject);
4764 programObject->validate(mCaps);
4765}
4766
Jamie Madilld04908b2017-06-09 14:15:35 -04004767void Context::getProgramBinary(GLuint program,
4768 GLsizei bufSize,
4769 GLsizei *length,
4770 GLenum *binaryFormat,
4771 void *binary)
4772{
4773 Program *programObject = getProgram(program);
4774 ASSERT(programObject != nullptr);
4775
4776 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
4777}
4778
4779void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
4780{
4781 Program *programObject = getProgram(program);
4782 ASSERT(programObject != nullptr);
4783
4784 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
4785}
4786
Jamie Madillc29968b2016-01-20 11:17:23 -05004787} // namespace gl