blob: 7489e443175cc10681180c3b67fe666d5d12e7da [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 Madillb3f26b92017-07-19 15:07:41 -0400275 mScratchBuffer(1000u),
276 mZeroFilledBuffer(1000u)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000277{
Geoff Lang077f20a2016-11-01 10:08:02 -0400278 if (mRobustAccess)
279 {
280 UNIMPLEMENTED();
281 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000282
Jamie Madill4e0e6f82017-02-17 11:06:03 -0500283 initCaps(displayExtensions);
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700284 initWorkarounds();
Geoff Langc0b9ef42014-07-02 10:02:37 -0400285
Jamie Madill4928b7c2017-06-20 12:57:39 -0400286 mGLState.initialize(this, GetDebug(attribs), GetBindGeneratesResource(attribs),
Jamie Madillc43be722017-07-13 16:22:14 -0400287 GetClientArraysEnabled(attribs), robustResourceInit,
288 mMemoryProgramCache != nullptr);
Régis Fénéon83107972015-02-05 12:57:44 +0100289
Shannon Woods53a94a82014-06-24 15:20:36 -0400290 mFenceNVHandleAllocator.setBaseHandle(0);
Geoff Lang7dca1862013-07-30 16:30:46 -0400291
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000292 // [OpenGL ES 2.0.24] section 3.7 page 83:
293 // In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have twodimensional
294 // and cube map texture state vectors respectively associated with them.
295 // In order that access to these initial textures not be lost, they are treated as texture
296 // objects all of whose names are 0.
297
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400298 Texture *zeroTexture2D = new Texture(mImplementation.get(), 0, GL_TEXTURE_2D);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400299 mZeroTextures[GL_TEXTURE_2D].set(this, zeroTexture2D);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500300
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400301 Texture *zeroTextureCube = new Texture(mImplementation.get(), 0, GL_TEXTURE_CUBE_MAP);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400302 mZeroTextures[GL_TEXTURE_CUBE_MAP].set(this, zeroTextureCube);
Geoff Lang76b10c92014-09-05 16:28:14 -0400303
Geoff Langeb66a6e2016-10-31 13:06:12 -0400304 if (getClientVersion() >= Version(3, 0))
Geoff Lang76b10c92014-09-05 16:28:14 -0400305 {
306 // TODO: These could also be enabled via extension
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400307 Texture *zeroTexture3D = new Texture(mImplementation.get(), 0, GL_TEXTURE_3D);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400308 mZeroTextures[GL_TEXTURE_3D].set(this, zeroTexture3D);
Geoff Lang76b10c92014-09-05 16:28:14 -0400309
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400310 Texture *zeroTexture2DArray = new Texture(mImplementation.get(), 0, GL_TEXTURE_2D_ARRAY);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400311 mZeroTextures[GL_TEXTURE_2D_ARRAY].set(this, zeroTexture2DArray);
Geoff Lang76b10c92014-09-05 16:28:14 -0400312 }
Geoff Lang3b573612016-10-31 14:08:10 -0400313 if (getClientVersion() >= Version(3, 1))
314 {
315 Texture *zeroTexture2DMultisample =
316 new Texture(mImplementation.get(), 0, GL_TEXTURE_2D_MULTISAMPLE);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400317 mZeroTextures[GL_TEXTURE_2D_MULTISAMPLE].set(this, zeroTexture2DMultisample);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800318
319 bindGenericAtomicCounterBuffer(0);
320 for (unsigned int i = 0; i < mCaps.maxAtomicCounterBufferBindings; i++)
321 {
322 bindIndexedAtomicCounterBuffer(0, i, 0, 0);
323 }
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800324
325 bindGenericShaderStorageBuffer(0);
326 for (unsigned int i = 0; i < mCaps.maxShaderStorageBufferBindings; i++)
327 {
328 bindIndexedShaderStorageBuffer(0, i, 0, 0);
329 }
Geoff Lang3b573612016-10-31 14:08:10 -0400330 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000331
Ian Ewellbda75592016-04-18 17:25:54 -0400332 if (mExtensions.eglImageExternal || mExtensions.eglStreamConsumerExternal)
333 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400334 Texture *zeroTextureExternal =
335 new Texture(mImplementation.get(), 0, GL_TEXTURE_EXTERNAL_OES);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400336 mZeroTextures[GL_TEXTURE_EXTERNAL_OES].set(this, zeroTextureExternal);
Ian Ewellbda75592016-04-18 17:25:54 -0400337 }
338
Jamie Madill4928b7c2017-06-20 12:57:39 -0400339 mGLState.initializeZeroTextures(this, mZeroTextures);
Jamie Madille6382c32014-11-07 15:05:26 -0500340
Jamie Madill57a89722013-07-02 11:57:03 -0400341 bindVertexArray(0);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000342 bindArrayBuffer(0);
Jiajia Qin9d7d0b12016-11-29 16:30:31 +0800343 bindDrawIndirectBuffer(0);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000344 bindElementArrayBuffer(0);
Geoff Lang76b10c92014-09-05 16:28:14 -0400345
Jamie Madill01a80ee2016-11-07 12:06:18 -0500346 bindRenderbuffer(GL_RENDERBUFFER, 0);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000347
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +0000348 bindGenericUniformBuffer(0);
Geoff Lang4dc3af02016-11-18 14:09:27 -0500349 for (unsigned int i = 0; i < mCaps.maxUniformBufferBindings; i++)
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +0000350 {
351 bindIndexedUniformBuffer(0, i, 0, -1);
352 }
353
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000354 bindCopyReadBuffer(0);
355 bindCopyWriteBuffer(0);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +0000356 bindPixelPackBuffer(0);
357 bindPixelUnpackBuffer(0);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000358
Geoff Langeb66a6e2016-10-31 13:06:12 -0400359 if (getClientVersion() >= Version(3, 0))
Geoff Lang1a683462015-09-29 15:09:59 -0400360 {
361 // [OpenGL ES 3.0.2] section 2.14.1 pg 85:
362 // In the initial state, a default transform feedback object is bound and treated as
363 // a transform feedback object with a name of zero. That object is bound any time
364 // BindTransformFeedback is called with id of zero
Geoff Lang1a683462015-09-29 15:09:59 -0400365 bindTransformFeedback(0);
366 }
Geoff Langc8058452014-02-03 12:04:11 -0500367
Jamie Madillad9f24e2016-02-12 09:27:24 -0500368 // Initialize dirty bit masks
369 // TODO(jmadill): additional ES3 state
370 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_ALIGNMENT);
371 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_ROW_LENGTH);
372 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_IMAGE_HEIGHT);
373 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_SKIP_IMAGES);
374 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_SKIP_ROWS);
375 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_SKIP_PIXELS);
Corentin Wallezbbd663a2016-04-20 17:49:17 -0400376 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500377 // No dirty objects.
378
379 // Readpixels uses the pack state and read FBO
380 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_ALIGNMENT);
381 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_REVERSE_ROW_ORDER);
382 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_ROW_LENGTH);
383 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_SKIP_ROWS);
384 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_SKIP_PIXELS);
Corentin Wallezbbd663a2016-04-20 17:49:17 -0400385 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500386 mReadPixelsDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
387
388 mClearDirtyBits.set(State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED);
389 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
390 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR);
391 mClearDirtyBits.set(State::DIRTY_BIT_VIEWPORT);
392 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_COLOR);
393 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_DEPTH);
394 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_STENCIL);
395 mClearDirtyBits.set(State::DIRTY_BIT_COLOR_MASK);
396 mClearDirtyBits.set(State::DIRTY_BIT_DEPTH_MASK);
397 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT);
398 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_BACK);
399 mClearDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
400
401 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
402 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR);
Geoff Lang1d2c41d2016-10-19 16:14:46 -0700403 mBlitDirtyBits.set(State::DIRTY_BIT_FRAMEBUFFER_SRGB);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500404 mBlitDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
405 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
Jamie Madill437fa652016-05-03 15:13:24 -0400406
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400407 handleError(mImplementation->initialize());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000408}
409
Jamie Madill4928b7c2017-06-20 12:57:39 -0400410egl::Error Context::onDestroy(const egl::Display *display)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000411{
Corentin Wallez80b24112015-08-25 16:41:57 -0400412 for (auto fence : mFenceNVMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000413 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400414 SafeDelete(fence.second);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000415 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400416 mFenceNVMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000417
Corentin Wallez80b24112015-08-25 16:41:57 -0400418 for (auto query : mQueryMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000419 {
Geoff Langf0aa8422015-09-29 15:08:34 -0400420 if (query.second != nullptr)
421 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400422 query.second->release(this);
Geoff Langf0aa8422015-09-29 15:08:34 -0400423 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000424 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400425 mQueryMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000426
Corentin Wallez80b24112015-08-25 16:41:57 -0400427 for (auto vertexArray : mVertexArrayMap)
Jamie Madill57a89722013-07-02 11:57:03 -0400428 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400429 if (vertexArray.second)
430 {
431 vertexArray.second->onDestroy(this);
432 }
Jamie Madill57a89722013-07-02 11:57:03 -0400433 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400434 mVertexArrayMap.clear();
Jamie Madill57a89722013-07-02 11:57:03 -0400435
Corentin Wallez80b24112015-08-25 16:41:57 -0400436 for (auto transformFeedback : mTransformFeedbackMap)
Geoff Langc8058452014-02-03 12:04:11 -0500437 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500438 if (transformFeedback.second != nullptr)
439 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500440 transformFeedback.second->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500441 }
Geoff Langc8058452014-02-03 12:04:11 -0500442 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400443 mTransformFeedbackMap.clear();
Geoff Langc8058452014-02-03 12:04:11 -0500444
Jamie Madilldedd7b92014-11-05 16:30:36 -0500445 for (auto &zeroTexture : mZeroTextures)
Geoff Lang76b10c92014-09-05 16:28:14 -0400446 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400447 zeroTexture.second->onDestroy(this);
448 zeroTexture.second.set(this, nullptr);
Geoff Lang76b10c92014-09-05 16:28:14 -0400449 }
450 mZeroTextures.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000451
Corentin Wallezccab69d2017-01-27 16:57:15 -0500452 SafeDelete(mSurfacelessFramebuffer);
453
Jamie Madill4928b7c2017-06-20 12:57:39 -0400454 ANGLE_TRY(releaseSurface(display));
Jamie Madill2f348d22017-06-05 10:50:59 -0400455 releaseShaderCompiler();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500456
Jamie Madill4928b7c2017-06-20 12:57:39 -0400457 mGLState.reset(this);
458
Jamie Madill6c1f6712017-02-14 19:08:04 -0500459 mState.mBuffers->release(this);
460 mState.mShaderPrograms->release(this);
461 mState.mTextures->release(this);
462 mState.mRenderbuffers->release(this);
463 mState.mSamplers->release(this);
464 mState.mFenceSyncs->release(this);
465 mState.mPaths->release(this);
466 mState.mFramebuffers->release(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400467
468 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000469}
470
Jamie Madill70ee0f62017-02-06 16:04:20 -0500471Context::~Context()
472{
473}
474
Jamie Madill4928b7c2017-06-20 12:57:39 -0400475egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000476{
Jamie Madill61e16b42017-06-19 11:13:23 -0400477 mCurrentDisplay = display;
478
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000479 if (!mHasBeenCurrent)
480 {
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000481 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500482 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400483 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000484
Corentin Wallezc295e512017-01-27 17:47:50 -0500485 int width = 0;
486 int height = 0;
487 if (surface != nullptr)
488 {
489 width = surface->getWidth();
490 height = surface->getHeight();
491 }
492
493 mGLState.setViewportParams(0, 0, width, height);
494 mGLState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000495
496 mHasBeenCurrent = true;
497 }
498
Jamie Madill1b94d432015-08-07 13:23:23 -0400499 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700500 mGLState.setAllDirtyBits();
Jamie Madill1b94d432015-08-07 13:23:23 -0400501
Jamie Madill4928b7c2017-06-20 12:57:39 -0400502 ANGLE_TRY(releaseSurface(display));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500503
504 Framebuffer *newDefault = nullptr;
505 if (surface != nullptr)
506 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400507 ANGLE_TRY(surface->setIsCurrent(this, true));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500508 mCurrentSurface = surface;
509 newDefault = surface->getDefaultFramebuffer();
510 }
511 else
512 {
513 if (mSurfacelessFramebuffer == nullptr)
514 {
515 mSurfacelessFramebuffer = new Framebuffer(mImplementation.get());
516 }
517
518 newDefault = mSurfacelessFramebuffer;
519 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000520
Corentin Wallez37c39792015-08-20 14:19:46 -0400521 // Update default framebuffer, the binding of the previous default
522 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400523 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700524 if (mGLState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400525 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700526 mGLState.setReadFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400527 }
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700528 if (mGLState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400529 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700530 mGLState.setDrawFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400531 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500532 mState.mFramebuffers->setDefaultFramebuffer(newDefault);
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400533 }
Ian Ewell292f0052016-02-04 10:37:32 -0500534
535 // Notify the renderer of a context switch
Jamie Madill4928b7c2017-06-20 12:57:39 -0400536 mImplementation->onMakeCurrent(this);
537 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000538}
539
Jamie Madill4928b7c2017-06-20 12:57:39 -0400540egl::Error Context::releaseSurface(const egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400541{
Corentin Wallez37c39792015-08-20 14:19:46 -0400542 // Remove the default framebuffer
Corentin Wallezc295e512017-01-27 17:47:50 -0500543 Framebuffer *currentDefault = nullptr;
544 if (mCurrentSurface != nullptr)
Corentin Wallez51706ea2015-08-07 14:39:22 -0400545 {
Corentin Wallezc295e512017-01-27 17:47:50 -0500546 currentDefault = mCurrentSurface->getDefaultFramebuffer();
547 }
548 else if (mSurfacelessFramebuffer != nullptr)
549 {
550 currentDefault = mSurfacelessFramebuffer;
Corentin Wallez51706ea2015-08-07 14:39:22 -0400551 }
552
Corentin Wallezc295e512017-01-27 17:47:50 -0500553 if (mGLState.getReadFramebuffer() == currentDefault)
554 {
555 mGLState.setReadFramebufferBinding(nullptr);
556 }
557 if (mGLState.getDrawFramebuffer() == currentDefault)
558 {
559 mGLState.setDrawFramebufferBinding(nullptr);
560 }
561 mState.mFramebuffers->setDefaultFramebuffer(nullptr);
562
563 if (mCurrentSurface)
564 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400565 ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
Corentin Wallezc295e512017-01-27 17:47:50 -0500566 mCurrentSurface = nullptr;
567 }
Jamie Madill4928b7c2017-06-20 12:57:39 -0400568
569 return egl::NoError();
Jamie Madill77a72f62015-04-14 11:18:32 -0400570}
571
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000572GLuint Context::createBuffer()
573{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500574 return mState.mBuffers->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000575}
576
577GLuint Context::createProgram()
578{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500579 return mState.mShaderPrograms->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000580}
581
582GLuint Context::createShader(GLenum type)
583{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500584 return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000585}
586
587GLuint Context::createTexture()
588{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500589 return mState.mTextures->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000590}
591
592GLuint Context::createRenderbuffer()
593{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500594 return mState.mRenderbuffers->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000595}
596
Geoff Lang882033e2014-09-30 11:26:07 -0400597GLsync Context::createFenceSync()
Jamie Madillcd055f82013-07-26 11:55:15 -0400598{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500599 GLuint handle = mState.mFenceSyncs->createFenceSync(mImplementation.get());
Jamie Madillcd055f82013-07-26 11:55:15 -0400600
Cooper Partind8e62a32015-01-29 15:21:25 -0800601 return reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madillcd055f82013-07-26 11:55:15 -0400602}
603
Sami Väisänene45e53b2016-05-25 10:36:04 +0300604GLuint Context::createPaths(GLsizei range)
605{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500606 auto resultOrError = mState.mPaths->createPaths(mImplementation.get(), range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300607 if (resultOrError.isError())
608 {
609 handleError(resultOrError.getError());
610 return 0;
611 }
612 return resultOrError.getResult();
613}
614
Jamie Madill57a89722013-07-02 11:57:03 -0400615GLuint Context::createVertexArray()
616{
Jamie Madill96a483b2017-06-27 16:49:21 -0400617 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
618 mVertexArrayMap.assign(vertexArray, nullptr);
Geoff Lang36167ab2015-12-07 10:27:14 -0500619 return vertexArray;
Jamie Madill57a89722013-07-02 11:57:03 -0400620}
621
Jamie Madilldc356042013-07-19 16:36:57 -0400622GLuint Context::createSampler()
623{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500624 return mState.mSamplers->createSampler();
Jamie Madilldc356042013-07-19 16:36:57 -0400625}
626
Geoff Langc8058452014-02-03 12:04:11 -0500627GLuint Context::createTransformFeedback()
628{
Jamie Madill96a483b2017-06-27 16:49:21 -0400629 GLuint transformFeedback = mTransformFeedbackAllocator.allocate();
630 mTransformFeedbackMap.assign(transformFeedback, nullptr);
Geoff Lang36167ab2015-12-07 10:27:14 -0500631 return transformFeedback;
Geoff Langc8058452014-02-03 12:04:11 -0500632}
633
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000634// Returns an unused framebuffer name
635GLuint Context::createFramebuffer()
636{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500637 return mState.mFramebuffers->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000638}
639
Jamie Madill33dc8432013-07-26 11:55:05 -0400640GLuint Context::createFenceNV()
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000641{
Jamie Madill33dc8432013-07-26 11:55:05 -0400642 GLuint handle = mFenceNVHandleAllocator.allocate();
Jamie Madill96a483b2017-06-27 16:49:21 -0400643 mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV()));
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000644 return handle;
645}
646
647// Returns an unused query name
648GLuint Context::createQuery()
649{
650 GLuint handle = mQueryHandleAllocator.allocate();
Jamie Madill96a483b2017-06-27 16:49:21 -0400651 mQueryMap.assign(handle, nullptr);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000652 return handle;
653}
654
655void Context::deleteBuffer(GLuint buffer)
656{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500657 if (mState.mBuffers->getBuffer(buffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000658 {
659 detachBuffer(buffer);
660 }
Jamie Madill893ab082014-05-16 16:56:10 -0400661
Jamie Madill6c1f6712017-02-14 19:08:04 -0500662 mState.mBuffers->deleteObject(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000663}
664
665void Context::deleteShader(GLuint shader)
666{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500667 mState.mShaderPrograms->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000668}
669
670void Context::deleteProgram(GLuint program)
671{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500672 mState.mShaderPrograms->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000673}
674
675void Context::deleteTexture(GLuint texture)
676{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500677 if (mState.mTextures->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000678 {
679 detachTexture(texture);
680 }
681
Jamie Madill6c1f6712017-02-14 19:08:04 -0500682 mState.mTextures->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000683}
684
685void Context::deleteRenderbuffer(GLuint renderbuffer)
686{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500687 if (mState.mRenderbuffers->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000688 {
689 detachRenderbuffer(renderbuffer);
690 }
Jamie Madill893ab082014-05-16 16:56:10 -0400691
Jamie Madill6c1f6712017-02-14 19:08:04 -0500692 mState.mRenderbuffers->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000693}
694
Jamie Madillcd055f82013-07-26 11:55:15 -0400695void Context::deleteFenceSync(GLsync fenceSync)
696{
697 // The spec specifies the underlying Fence object is not deleted until all current
698 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
699 // and since our API is currently designed for being called from a single thread, we can delete
700 // the fence immediately.
Jamie Madill6c1f6712017-02-14 19:08:04 -0500701 mState.mFenceSyncs->deleteObject(this,
702 static_cast<GLuint>(reinterpret_cast<uintptr_t>(fenceSync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400703}
704
Sami Väisänene45e53b2016-05-25 10:36:04 +0300705void Context::deletePaths(GLuint first, GLsizei range)
706{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500707 mState.mPaths->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300708}
709
710bool Context::hasPathData(GLuint path) const
711{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500712 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300713 if (pathObj == nullptr)
714 return false;
715
716 return pathObj->hasPathData();
717}
718
719bool Context::hasPath(GLuint path) const
720{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500721 return mState.mPaths->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300722}
723
724void Context::setPathCommands(GLuint path,
725 GLsizei numCommands,
726 const GLubyte *commands,
727 GLsizei numCoords,
728 GLenum coordType,
729 const void *coords)
730{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500731 auto *pathObject = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300732
733 handleError(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
734}
735
736void Context::setPathParameterf(GLuint path, GLenum pname, GLfloat value)
737{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500738 auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300739
740 switch (pname)
741 {
742 case GL_PATH_STROKE_WIDTH_CHROMIUM:
743 pathObj->setStrokeWidth(value);
744 break;
745 case GL_PATH_END_CAPS_CHROMIUM:
746 pathObj->setEndCaps(static_cast<GLenum>(value));
747 break;
748 case GL_PATH_JOIN_STYLE_CHROMIUM:
749 pathObj->setJoinStyle(static_cast<GLenum>(value));
750 break;
751 case GL_PATH_MITER_LIMIT_CHROMIUM:
752 pathObj->setMiterLimit(value);
753 break;
754 case GL_PATH_STROKE_BOUND_CHROMIUM:
755 pathObj->setStrokeBound(value);
756 break;
757 default:
758 UNREACHABLE();
759 break;
760 }
761}
762
763void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value) const
764{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500765 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300766
767 switch (pname)
768 {
769 case GL_PATH_STROKE_WIDTH_CHROMIUM:
770 *value = pathObj->getStrokeWidth();
771 break;
772 case GL_PATH_END_CAPS_CHROMIUM:
773 *value = static_cast<GLfloat>(pathObj->getEndCaps());
774 break;
775 case GL_PATH_JOIN_STYLE_CHROMIUM:
776 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
777 break;
778 case GL_PATH_MITER_LIMIT_CHROMIUM:
779 *value = pathObj->getMiterLimit();
780 break;
781 case GL_PATH_STROKE_BOUND_CHROMIUM:
782 *value = pathObj->getStrokeBound();
783 break;
784 default:
785 UNREACHABLE();
786 break;
787 }
788}
789
790void Context::setPathStencilFunc(GLenum func, GLint ref, GLuint mask)
791{
792 mGLState.setPathStencilFunc(func, ref, mask);
793}
794
Jamie Madill57a89722013-07-02 11:57:03 -0400795void Context::deleteVertexArray(GLuint vertexArray)
796{
Jamie Madill96a483b2017-06-27 16:49:21 -0400797 VertexArray *vertexArrayObject = nullptr;
798 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
Geoff Lang50b3fe82015-12-08 14:49:12 +0000799 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500800 if (vertexArrayObject != nullptr)
801 {
802 detachVertexArray(vertexArray);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400803 vertexArrayObject->onDestroy(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500804 }
Geoff Lang50b3fe82015-12-08 14:49:12 +0000805
Geoff Lang36167ab2015-12-07 10:27:14 -0500806 mVertexArrayHandleAllocator.release(vertexArray);
Jamie Madill57a89722013-07-02 11:57:03 -0400807 }
808}
809
Jamie Madilldc356042013-07-19 16:36:57 -0400810void Context::deleteSampler(GLuint sampler)
811{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500812 if (mState.mSamplers->getSampler(sampler))
Jamie Madilldc356042013-07-19 16:36:57 -0400813 {
814 detachSampler(sampler);
815 }
816
Jamie Madill6c1f6712017-02-14 19:08:04 -0500817 mState.mSamplers->deleteObject(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -0400818}
819
Geoff Langc8058452014-02-03 12:04:11 -0500820void Context::deleteTransformFeedback(GLuint transformFeedback)
821{
Geoff Lang6e60d6b2017-04-12 12:59:04 -0400822 if (transformFeedback == 0)
823 {
824 return;
825 }
826
Jamie Madill96a483b2017-06-27 16:49:21 -0400827 TransformFeedback *transformFeedbackObject = nullptr;
828 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
Geoff Langc8058452014-02-03 12:04:11 -0500829 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500830 if (transformFeedbackObject != nullptr)
831 {
832 detachTransformFeedback(transformFeedback);
Jamie Madill6c1f6712017-02-14 19:08:04 -0500833 transformFeedbackObject->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500834 }
835
Geoff Lang36167ab2015-12-07 10:27:14 -0500836 mTransformFeedbackAllocator.release(transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -0500837 }
838}
839
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000840void Context::deleteFramebuffer(GLuint framebuffer)
841{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500842 if (mState.mFramebuffers->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000843 {
844 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000845 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500846
Jamie Madill6c1f6712017-02-14 19:08:04 -0500847 mState.mFramebuffers->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000848}
849
Jamie Madill33dc8432013-07-26 11:55:05 -0400850void Context::deleteFenceNV(GLuint fence)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000851{
Jamie Madill96a483b2017-06-27 16:49:21 -0400852 FenceNV *fenceObject = nullptr;
853 if (mFenceNVMap.erase(fence, &fenceObject))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000854 {
Jamie Madill96a483b2017-06-27 16:49:21 -0400855 mFenceNVHandleAllocator.release(fence);
856 delete fenceObject;
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000857 }
858}
859
860void Context::deleteQuery(GLuint query)
861{
Jamie Madill96a483b2017-06-27 16:49:21 -0400862 Query *queryObject = nullptr;
863 if (mQueryMap.erase(query, &queryObject))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000864 {
Jamie Madill96a483b2017-06-27 16:49:21 -0400865 mQueryHandleAllocator.release(query);
866 if (queryObject)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000867 {
Jamie Madill96a483b2017-06-27 16:49:21 -0400868 queryObject->release(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000869 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000870 }
871}
872
Geoff Lang70d0f492015-12-10 17:45:46 -0500873Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000874{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500875 return mState.mBuffers->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000876}
877
Jamie Madill570f7c82014-07-03 10:38:54 -0400878Texture *Context::getTexture(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000879{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500880 return mState.mTextures->getTexture(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000881}
882
Geoff Lang70d0f492015-12-10 17:45:46 -0500883Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000884{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500885 return mState.mRenderbuffers->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000886}
887
Jamie Madillcd055f82013-07-26 11:55:15 -0400888FenceSync *Context::getFenceSync(GLsync handle) const
889{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500890 return mState.mFenceSyncs->getFenceSync(
891 static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400892}
893
Jamie Madill57a89722013-07-02 11:57:03 -0400894VertexArray *Context::getVertexArray(GLuint handle) const
895{
Jamie Madill96a483b2017-06-27 16:49:21 -0400896 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -0400897}
898
Jamie Madilldc356042013-07-19 16:36:57 -0400899Sampler *Context::getSampler(GLuint handle) const
900{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500901 return mState.mSamplers->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400902}
903
Geoff Langc8058452014-02-03 12:04:11 -0500904TransformFeedback *Context::getTransformFeedback(GLuint handle) const
905{
Jamie Madill96a483b2017-06-27 16:49:21 -0400906 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -0500907}
908
Geoff Lang70d0f492015-12-10 17:45:46 -0500909LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
910{
911 switch (identifier)
912 {
913 case GL_BUFFER:
914 return getBuffer(name);
915 case GL_SHADER:
916 return getShader(name);
917 case GL_PROGRAM:
918 return getProgram(name);
919 case GL_VERTEX_ARRAY:
920 return getVertexArray(name);
921 case GL_QUERY:
922 return getQuery(name);
923 case GL_TRANSFORM_FEEDBACK:
924 return getTransformFeedback(name);
925 case GL_SAMPLER:
926 return getSampler(name);
927 case GL_TEXTURE:
928 return getTexture(name);
929 case GL_RENDERBUFFER:
930 return getRenderbuffer(name);
931 case GL_FRAMEBUFFER:
932 return getFramebuffer(name);
933 default:
934 UNREACHABLE();
935 return nullptr;
936 }
937}
938
939LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
940{
941 return getFenceSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
942}
943
Martin Radev9d901792016-07-15 15:58:58 +0300944void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
945{
946 LabeledObject *object = getLabeledObject(identifier, name);
947 ASSERT(object != nullptr);
948
949 std::string labelName = GetObjectLabelFromPointer(length, label);
950 object->setLabel(labelName);
951}
952
953void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
954{
955 LabeledObject *object = getLabeledObjectFromPtr(ptr);
956 ASSERT(object != nullptr);
957
958 std::string labelName = GetObjectLabelFromPointer(length, label);
959 object->setLabel(labelName);
960}
961
962void Context::getObjectLabel(GLenum identifier,
963 GLuint name,
964 GLsizei bufSize,
965 GLsizei *length,
966 GLchar *label) const
967{
968 LabeledObject *object = getLabeledObject(identifier, name);
969 ASSERT(object != nullptr);
970
971 const std::string &objectLabel = object->getLabel();
972 GetObjectLabelBase(objectLabel, bufSize, length, label);
973}
974
975void Context::getObjectPtrLabel(const void *ptr,
976 GLsizei bufSize,
977 GLsizei *length,
978 GLchar *label) const
979{
980 LabeledObject *object = getLabeledObjectFromPtr(ptr);
981 ASSERT(object != nullptr);
982
983 const std::string &objectLabel = object->getLabel();
984 GetObjectLabelBase(objectLabel, bufSize, length, label);
985}
986
Jamie Madilldc356042013-07-19 16:36:57 -0400987bool Context::isSampler(GLuint samplerName) const
988{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500989 return mState.mSamplers->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -0400990}
991
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500992void Context::bindArrayBuffer(GLuint bufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000993{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500994 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400995 mGLState.setArrayBufferBinding(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000996}
997
Jiajia Qin9d7d0b12016-11-29 16:30:31 +0800998void Context::bindDrawIndirectBuffer(GLuint bufferHandle)
999{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001000 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001001 mGLState.setDrawIndirectBufferBinding(this, buffer);
Jiajia Qin9d7d0b12016-11-29 16:30:31 +08001002}
1003
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001004void Context::bindElementArrayBuffer(GLuint bufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001005{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001006 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001007 mGLState.setElementArrayBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001008}
1009
Jamie Madilldedd7b92014-11-05 16:30:36 -05001010void Context::bindTexture(GLenum target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001011{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001012 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001013
Jamie Madilldedd7b92014-11-05 16:30:36 -05001014 if (handle == 0)
1015 {
1016 texture = mZeroTextures[target].get();
1017 }
1018 else
1019 {
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001020 texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -05001021 }
1022
1023 ASSERT(texture);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001024 mGLState.setSamplerTexture(this, target, texture);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00001025}
1026
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001027void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001028{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001029 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1030 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001031 mGLState.setReadFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001032}
1033
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001034void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001035{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001036 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1037 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001038 mGLState.setDrawFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001039}
1040
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001041void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -04001042{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001043 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001044 mGLState.setVertexArrayBinding(vertexArray);
Jamie Madill57a89722013-07-02 11:57:03 -04001045}
1046
Shao80957d92017-02-20 21:25:59 +08001047void Context::bindVertexBuffer(GLuint bindingIndex,
1048 GLuint bufferHandle,
1049 GLintptr offset,
1050 GLsizei stride)
1051{
1052 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001053 mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Shao80957d92017-02-20 21:25:59 +08001054}
1055
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001056void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -04001057{
Geoff Lang76b10c92014-09-05 16:28:14 -04001058 ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -04001059 Sampler *sampler =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001060 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001061 mGLState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04001062}
1063
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001064void Context::bindImageTexture(GLuint unit,
1065 GLuint texture,
1066 GLint level,
1067 GLboolean layered,
1068 GLint layer,
1069 GLenum access,
1070 GLenum format)
1071{
1072 Texture *tex = mState.mTextures->getTexture(texture);
1073 mGLState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
1074}
1075
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001076void Context::bindGenericUniformBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001077{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001078 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001079 mGLState.setGenericUniformBufferBinding(this, buffer);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001080}
1081
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001082void Context::bindIndexedUniformBuffer(GLuint bufferHandle,
1083 GLuint index,
1084 GLintptr offset,
1085 GLsizeiptr size)
shannon.woods%transgaming.com@gtempaccount.com34089352013-04-13 03:36:57 +00001086{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001087 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001088 mGLState.setIndexedUniformBufferBinding(this, index, buffer, offset, size);
shannon.woods%transgaming.com@gtempaccount.com34089352013-04-13 03:36:57 +00001089}
1090
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001091void Context::bindGenericTransformFeedbackBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001092{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001093 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001094 mGLState.getCurrentTransformFeedback()->bindGenericBuffer(this, buffer);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001095}
1096
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001097void Context::bindIndexedTransformFeedbackBuffer(GLuint bufferHandle,
1098 GLuint index,
1099 GLintptr offset,
1100 GLsizeiptr size)
shannon.woods%transgaming.com@gtempaccount.com34089352013-04-13 03:36:57 +00001101{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001102 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001103 mGLState.getCurrentTransformFeedback()->bindIndexedBuffer(this, index, buffer, offset, size);
shannon.woods%transgaming.com@gtempaccount.com34089352013-04-13 03:36:57 +00001104}
1105
Jiajia Qin6eafb042016-12-27 17:04:07 +08001106void Context::bindGenericAtomicCounterBuffer(GLuint bufferHandle)
1107{
1108 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001109 mGLState.setGenericAtomicCounterBufferBinding(this, buffer);
Jiajia Qin6eafb042016-12-27 17:04:07 +08001110}
1111
1112void Context::bindIndexedAtomicCounterBuffer(GLuint bufferHandle,
1113 GLuint index,
1114 GLintptr offset,
1115 GLsizeiptr size)
1116{
1117 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001118 mGLState.setIndexedAtomicCounterBufferBinding(this, index, buffer, offset, size);
Jiajia Qin6eafb042016-12-27 17:04:07 +08001119}
1120
Jiajia Qinf546e7d2017-03-27 14:12:59 +08001121void Context::bindGenericShaderStorageBuffer(GLuint bufferHandle)
1122{
1123 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001124 mGLState.setGenericShaderStorageBufferBinding(this, buffer);
Jiajia Qinf546e7d2017-03-27 14:12:59 +08001125}
1126
1127void Context::bindIndexedShaderStorageBuffer(GLuint bufferHandle,
1128 GLuint index,
1129 GLintptr offset,
1130 GLsizeiptr size)
1131{
1132 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001133 mGLState.setIndexedShaderStorageBufferBinding(this, index, buffer, offset, size);
Jiajia Qinf546e7d2017-03-27 14:12:59 +08001134}
1135
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001136void Context::bindCopyReadBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001137{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001138 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001139 mGLState.setCopyReadBufferBinding(this, buffer);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001140}
1141
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001142void Context::bindCopyWriteBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001143{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001144 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001145 mGLState.setCopyWriteBufferBinding(this, buffer);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001146}
1147
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001148void Context::bindPixelPackBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001149{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001150 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001151 mGLState.setPixelPackBufferBinding(this, buffer);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001152}
1153
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001154void Context::bindPixelUnpackBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001155{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001156 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001157 mGLState.setPixelUnpackBufferBinding(this, buffer);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001158}
1159
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001160void Context::useProgram(GLuint program)
1161{
Jamie Madill6c1f6712017-02-14 19:08:04 -05001162 mGLState.setProgram(this, getProgram(program));
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001163}
1164
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001165void Context::bindTransformFeedback(GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001166{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001167 TransformFeedback *transformFeedback =
1168 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001169 mGLState.setTransformFeedbackBinding(this, transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -05001170}
1171
Geoff Lang5aad9672014-09-08 11:10:42 -04001172Error Context::beginQuery(GLenum target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001173{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001174 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001175 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001176
Geoff Lang5aad9672014-09-08 11:10:42 -04001177 // begin query
1178 Error error = queryObject->begin();
1179 if (error.isError())
1180 {
1181 return error;
1182 }
1183
1184 // set query as active for specified target only if begin succeeded
Jamie Madill4928b7c2017-06-20 12:57:39 -04001185 mGLState.setActiveQuery(this, target, queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001186
He Yunchaoacd18982017-01-04 10:46:42 +08001187 return NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001188}
1189
Geoff Lang5aad9672014-09-08 11:10:42 -04001190Error Context::endQuery(GLenum target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001191{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001192 Query *queryObject = mGLState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001193 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001194
Geoff Lang5aad9672014-09-08 11:10:42 -04001195 gl::Error error = queryObject->end();
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001196
Geoff Lang5aad9672014-09-08 11:10:42 -04001197 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madill4928b7c2017-06-20 12:57:39 -04001198 mGLState.setActiveQuery(this, target, nullptr);
Geoff Lang5aad9672014-09-08 11:10:42 -04001199
1200 return error;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001201}
1202
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001203Error Context::queryCounter(GLuint id, GLenum target)
1204{
1205 ASSERT(target == GL_TIMESTAMP_EXT);
1206
1207 Query *queryObject = getQuery(id, true, target);
1208 ASSERT(queryObject);
1209
1210 return queryObject->queryCounter();
1211}
1212
1213void Context::getQueryiv(GLenum target, GLenum pname, GLint *params)
1214{
1215 switch (pname)
1216 {
1217 case GL_CURRENT_QUERY_EXT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001218 params[0] = mGLState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001219 break;
1220 case GL_QUERY_COUNTER_BITS_EXT:
1221 switch (target)
1222 {
1223 case GL_TIME_ELAPSED_EXT:
1224 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1225 break;
1226 case GL_TIMESTAMP_EXT:
1227 params[0] = getExtensions().queryCounterBitsTimestamp;
1228 break;
1229 default:
1230 UNREACHABLE();
1231 params[0] = 0;
1232 break;
1233 }
1234 break;
1235 default:
1236 UNREACHABLE();
1237 return;
1238 }
1239}
1240
Geoff Lang2186c382016-10-14 10:54:54 -04001241void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001242{
Geoff Lang2186c382016-10-14 10:54:54 -04001243 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001244}
1245
Geoff Lang2186c382016-10-14 10:54:54 -04001246void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001247{
Geoff Lang2186c382016-10-14 10:54:54 -04001248 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001249}
1250
Geoff Lang2186c382016-10-14 10:54:54 -04001251void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001252{
Geoff Lang2186c382016-10-14 10:54:54 -04001253 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001254}
1255
Geoff Lang2186c382016-10-14 10:54:54 -04001256void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001257{
Geoff Lang2186c382016-10-14 10:54:54 -04001258 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001259}
1260
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001261Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001262{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001263 return mState.mFramebuffers->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001264}
1265
Jamie Madill2f348d22017-06-05 10:50:59 -04001266FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001267{
Jamie Madill96a483b2017-06-27 16:49:21 -04001268 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001269}
1270
Jamie Madill2f348d22017-06-05 10:50:59 -04001271Query *Context::getQuery(GLuint handle, bool create, GLenum type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001272{
Jamie Madill96a483b2017-06-27 16:49:21 -04001273 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001274 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001275 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001276 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001277
1278 Query *query = mQueryMap.query(handle);
1279 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001280 {
Jamie Madill96a483b2017-06-27 16:49:21 -04001281 query = new Query(mImplementation->createQuery(type), handle);
1282 query->addRef();
1283 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001284 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001285 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001286}
1287
Geoff Lang70d0f492015-12-10 17:45:46 -05001288Query *Context::getQuery(GLuint handle) const
1289{
Jamie Madill96a483b2017-06-27 16:49:21 -04001290 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001291}
1292
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001293Texture *Context::getTargetTexture(GLenum target) const
1294{
Ian Ewellbda75592016-04-18 17:25:54 -04001295 ASSERT(ValidTextureTarget(this, target) || ValidTextureExternalTarget(this, target));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001296 return mGLState.getTargetTexture(target);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001297}
1298
Geoff Lang76b10c92014-09-05 16:28:14 -04001299Texture *Context::getSamplerTexture(unsigned int sampler, GLenum type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001300{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001301 return mGLState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001302}
1303
Geoff Lang492a7e42014-11-05 13:27:06 -05001304Compiler *Context::getCompiler() const
1305{
Jamie Madill2f348d22017-06-05 10:50:59 -04001306 if (mCompiler.get() == nullptr)
1307 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001308 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001309 }
1310 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001311}
1312
Jamie Madillc1d770e2017-04-13 17:31:24 -04001313void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001314{
1315 switch (pname)
1316 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001317 case GL_SHADER_COMPILER:
1318 *params = GL_TRUE;
1319 break;
1320 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1321 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1322 break;
1323 default:
1324 mGLState.getBooleanv(pname, params);
1325 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001326 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001327}
1328
Jamie Madillc1d770e2017-04-13 17:31:24 -04001329void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001330{
Shannon Woods53a94a82014-06-24 15:20:36 -04001331 // Queries about context capabilities and maximums are answered by Context.
1332 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001333 switch (pname)
1334 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001335 case GL_ALIASED_LINE_WIDTH_RANGE:
1336 params[0] = mCaps.minAliasedLineWidth;
1337 params[1] = mCaps.maxAliasedLineWidth;
1338 break;
1339 case GL_ALIASED_POINT_SIZE_RANGE:
1340 params[0] = mCaps.minAliasedPointSize;
1341 params[1] = mCaps.maxAliasedPointSize;
1342 break;
1343 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1344 ASSERT(mExtensions.textureFilterAnisotropic);
1345 *params = mExtensions.maxTextureAnisotropy;
1346 break;
1347 case GL_MAX_TEXTURE_LOD_BIAS:
1348 *params = mCaps.maxLODBias;
1349 break;
1350
1351 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1352 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1353 {
1354 ASSERT(mExtensions.pathRendering);
1355 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1356 memcpy(params, m, 16 * sizeof(GLfloat));
1357 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001358 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001359
Jamie Madill231c7f52017-04-26 13:45:37 -04001360 default:
1361 mGLState.getFloatv(pname, params);
1362 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001363 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001364}
1365
Jamie Madillc1d770e2017-04-13 17:31:24 -04001366void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001367{
Shannon Woods53a94a82014-06-24 15:20:36 -04001368 // Queries about context capabilities and maximums are answered by Context.
1369 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001370
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001371 switch (pname)
1372 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001373 case GL_MAX_VERTEX_ATTRIBS:
1374 *params = mCaps.maxVertexAttributes;
1375 break;
1376 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1377 *params = mCaps.maxVertexUniformVectors;
1378 break;
1379 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
1380 *params = mCaps.maxVertexUniformComponents;
1381 break;
1382 case GL_MAX_VARYING_VECTORS:
1383 *params = mCaps.maxVaryingVectors;
1384 break;
1385 case GL_MAX_VARYING_COMPONENTS:
1386 *params = mCaps.maxVertexOutputComponents;
1387 break;
1388 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1389 *params = mCaps.maxCombinedTextureImageUnits;
1390 break;
1391 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
1392 *params = mCaps.maxVertexTextureImageUnits;
1393 break;
1394 case GL_MAX_TEXTURE_IMAGE_UNITS:
1395 *params = mCaps.maxTextureImageUnits;
1396 break;
1397 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1398 *params = mCaps.maxFragmentUniformVectors;
1399 break;
1400 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
1401 *params = mCaps.maxFragmentUniformComponents;
1402 break;
1403 case GL_MAX_RENDERBUFFER_SIZE:
1404 *params = mCaps.maxRenderbufferSize;
1405 break;
1406 case GL_MAX_COLOR_ATTACHMENTS_EXT:
1407 *params = mCaps.maxColorAttachments;
1408 break;
1409 case GL_MAX_DRAW_BUFFERS_EXT:
1410 *params = mCaps.maxDrawBuffers;
1411 break;
1412 // case GL_FRAMEBUFFER_BINDING: // now equivalent to
1413 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
1414 case GL_SUBPIXEL_BITS:
1415 *params = 4;
1416 break;
1417 case GL_MAX_TEXTURE_SIZE:
1418 *params = mCaps.max2DTextureSize;
1419 break;
1420 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1421 *params = mCaps.maxCubeMapTextureSize;
1422 break;
1423 case GL_MAX_3D_TEXTURE_SIZE:
1424 *params = mCaps.max3DTextureSize;
1425 break;
1426 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1427 *params = mCaps.maxArrayTextureLayers;
1428 break;
1429 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1430 *params = mCaps.uniformBufferOffsetAlignment;
1431 break;
1432 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1433 *params = mCaps.maxUniformBufferBindings;
1434 break;
1435 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
1436 *params = mCaps.maxVertexUniformBlocks;
1437 break;
1438 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
1439 *params = mCaps.maxFragmentUniformBlocks;
1440 break;
1441 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1442 *params = mCaps.maxCombinedTextureImageUnits;
1443 break;
1444 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1445 *params = mCaps.maxVertexOutputComponents;
1446 break;
1447 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1448 *params = mCaps.maxFragmentInputComponents;
1449 break;
1450 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1451 *params = mCaps.minProgramTexelOffset;
1452 break;
1453 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1454 *params = mCaps.maxProgramTexelOffset;
1455 break;
1456 case GL_MAJOR_VERSION:
1457 *params = getClientVersion().major;
1458 break;
1459 case GL_MINOR_VERSION:
1460 *params = getClientVersion().minor;
1461 break;
1462 case GL_MAX_ELEMENTS_INDICES:
1463 *params = mCaps.maxElementsIndices;
1464 break;
1465 case GL_MAX_ELEMENTS_VERTICES:
1466 *params = mCaps.maxElementsVertices;
1467 break;
1468 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1469 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1470 break;
1471 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1472 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1473 break;
1474 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1475 *params = mCaps.maxTransformFeedbackSeparateComponents;
1476 break;
1477 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1478 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1479 break;
1480 case GL_MAX_SAMPLES_ANGLE:
1481 *params = mCaps.maxSamples;
1482 break;
1483 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001484 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001485 params[0] = mCaps.maxViewportWidth;
1486 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001487 }
1488 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001489 case GL_COMPRESSED_TEXTURE_FORMATS:
1490 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1491 params);
1492 break;
1493 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1494 *params = mResetStrategy;
1495 break;
1496 case GL_NUM_SHADER_BINARY_FORMATS:
1497 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1498 break;
1499 case GL_SHADER_BINARY_FORMATS:
1500 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1501 break;
1502 case GL_NUM_PROGRAM_BINARY_FORMATS:
1503 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1504 break;
1505 case GL_PROGRAM_BINARY_FORMATS:
1506 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1507 break;
1508 case GL_NUM_EXTENSIONS:
1509 *params = static_cast<GLint>(mExtensionStrings.size());
1510 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001511
Jamie Madill231c7f52017-04-26 13:45:37 -04001512 // GL_KHR_debug
1513 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1514 *params = mExtensions.maxDebugMessageLength;
1515 break;
1516 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1517 *params = mExtensions.maxDebugLoggedMessages;
1518 break;
1519 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1520 *params = mExtensions.maxDebugGroupStackDepth;
1521 break;
1522 case GL_MAX_LABEL_LENGTH:
1523 *params = mExtensions.maxLabelLength;
1524 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001525
Martin Radeve5285d22017-07-14 16:23:53 +03001526 // GL_ANGLE_multiview
1527 case GL_MAX_VIEWS_ANGLE:
1528 *params = mExtensions.maxViews;
1529 break;
1530
Jamie Madill231c7f52017-04-26 13:45:37 -04001531 // GL_EXT_disjoint_timer_query
1532 case GL_GPU_DISJOINT_EXT:
1533 *params = mImplementation->getGPUDisjoint();
1534 break;
1535 case GL_MAX_FRAMEBUFFER_WIDTH:
1536 *params = mCaps.maxFramebufferWidth;
1537 break;
1538 case GL_MAX_FRAMEBUFFER_HEIGHT:
1539 *params = mCaps.maxFramebufferHeight;
1540 break;
1541 case GL_MAX_FRAMEBUFFER_SAMPLES:
1542 *params = mCaps.maxFramebufferSamples;
1543 break;
1544 case GL_MAX_SAMPLE_MASK_WORDS:
1545 *params = mCaps.maxSampleMaskWords;
1546 break;
1547 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1548 *params = mCaps.maxColorTextureSamples;
1549 break;
1550 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1551 *params = mCaps.maxDepthTextureSamples;
1552 break;
1553 case GL_MAX_INTEGER_SAMPLES:
1554 *params = mCaps.maxIntegerSamples;
1555 break;
1556 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1557 *params = mCaps.maxVertexAttribRelativeOffset;
1558 break;
1559 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1560 *params = mCaps.maxVertexAttribBindings;
1561 break;
1562 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1563 *params = mCaps.maxVertexAttribStride;
1564 break;
1565 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
1566 *params = mCaps.maxVertexAtomicCounterBuffers;
1567 break;
1568 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
1569 *params = mCaps.maxVertexAtomicCounters;
1570 break;
1571 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
1572 *params = mCaps.maxVertexImageUniforms;
1573 break;
1574 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
1575 *params = mCaps.maxVertexShaderStorageBlocks;
1576 break;
1577 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
1578 *params = mCaps.maxFragmentAtomicCounterBuffers;
1579 break;
1580 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
1581 *params = mCaps.maxFragmentAtomicCounters;
1582 break;
1583 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
1584 *params = mCaps.maxFragmentImageUniforms;
1585 break;
1586 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
1587 *params = mCaps.maxFragmentShaderStorageBlocks;
1588 break;
1589 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1590 *params = mCaps.minProgramTextureGatherOffset;
1591 break;
1592 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1593 *params = mCaps.maxProgramTextureGatherOffset;
1594 break;
1595 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1596 *params = mCaps.maxComputeWorkGroupInvocations;
1597 break;
1598 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
1599 *params = mCaps.maxComputeUniformBlocks;
1600 break;
1601 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
1602 *params = mCaps.maxComputeTextureImageUnits;
1603 break;
1604 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1605 *params = mCaps.maxComputeSharedMemorySize;
1606 break;
1607 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
1608 *params = mCaps.maxComputeUniformComponents;
1609 break;
1610 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
1611 *params = mCaps.maxComputeAtomicCounterBuffers;
1612 break;
1613 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
1614 *params = mCaps.maxComputeAtomicCounters;
1615 break;
1616 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
1617 *params = mCaps.maxComputeImageUniforms;
1618 break;
1619 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
1620 *params = mCaps.maxCombinedComputeUniformComponents;
1621 break;
1622 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
1623 *params = mCaps.maxComputeShaderStorageBlocks;
1624 break;
1625 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1626 *params = mCaps.maxCombinedShaderOutputResources;
1627 break;
1628 case GL_MAX_UNIFORM_LOCATIONS:
1629 *params = mCaps.maxUniformLocations;
1630 break;
1631 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1632 *params = mCaps.maxAtomicCounterBufferBindings;
1633 break;
1634 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1635 *params = mCaps.maxAtomicCounterBufferSize;
1636 break;
1637 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1638 *params = mCaps.maxCombinedAtomicCounterBuffers;
1639 break;
1640 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1641 *params = mCaps.maxCombinedAtomicCounters;
1642 break;
1643 case GL_MAX_IMAGE_UNITS:
1644 *params = mCaps.maxImageUnits;
1645 break;
1646 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1647 *params = mCaps.maxCombinedImageUniforms;
1648 break;
1649 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1650 *params = mCaps.maxShaderStorageBufferBindings;
1651 break;
1652 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1653 *params = mCaps.maxCombinedShaderStorageBlocks;
1654 break;
1655 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1656 *params = mCaps.shaderStorageBufferOffsetAlignment;
1657 break;
1658 default:
1659 mGLState.getIntegerv(this, pname, params);
1660 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001661 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001662}
1663
Jamie Madill893ab082014-05-16 16:56:10 -04001664void Context::getInteger64v(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001665{
Shannon Woods53a94a82014-06-24 15:20:36 -04001666 // Queries about context capabilities and maximums are answered by Context.
1667 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001668 switch (pname)
1669 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001670 case GL_MAX_ELEMENT_INDEX:
1671 *params = mCaps.maxElementIndex;
1672 break;
1673 case GL_MAX_UNIFORM_BLOCK_SIZE:
1674 *params = mCaps.maxUniformBlockSize;
1675 break;
1676 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
1677 *params = mCaps.maxCombinedVertexUniformComponents;
1678 break;
1679 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
1680 *params = mCaps.maxCombinedFragmentUniformComponents;
1681 break;
1682 case GL_MAX_SERVER_WAIT_TIMEOUT:
1683 *params = mCaps.maxServerWaitTimeout;
1684 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001685
Jamie Madill231c7f52017-04-26 13:45:37 -04001686 // GL_EXT_disjoint_timer_query
1687 case GL_TIMESTAMP_EXT:
1688 *params = mImplementation->getTimestamp();
1689 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001690
Jamie Madill231c7f52017-04-26 13:45:37 -04001691 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1692 *params = mCaps.maxShaderStorageBlockSize;
1693 break;
1694 default:
1695 UNREACHABLE();
1696 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001697 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001698}
1699
Geoff Lang70d0f492015-12-10 17:45:46 -05001700void Context::getPointerv(GLenum pname, void **params) const
1701{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001702 mGLState.getPointerv(pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001703}
1704
Martin Radev66fb8202016-07-28 11:45:20 +03001705void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001706{
Shannon Woods53a94a82014-06-24 15:20:36 -04001707 // Queries about context capabilities and maximums are answered by Context.
1708 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001709
1710 GLenum nativeType;
1711 unsigned int numParams;
1712 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1713 ASSERT(queryStatus);
1714
1715 if (nativeType == GL_INT)
1716 {
1717 switch (target)
1718 {
1719 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1720 ASSERT(index < 3u);
1721 *data = mCaps.maxComputeWorkGroupCount[index];
1722 break;
1723 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1724 ASSERT(index < 3u);
1725 *data = mCaps.maxComputeWorkGroupSize[index];
1726 break;
1727 default:
1728 mGLState.getIntegeri_v(target, index, data);
1729 }
1730 }
1731 else
1732 {
1733 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1734 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001735}
1736
Martin Radev66fb8202016-07-28 11:45:20 +03001737void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001738{
Shannon Woods53a94a82014-06-24 15:20:36 -04001739 // Queries about context capabilities and maximums are answered by Context.
1740 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001741
1742 GLenum nativeType;
1743 unsigned int numParams;
1744 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1745 ASSERT(queryStatus);
1746
1747 if (nativeType == GL_INT_64_ANGLEX)
1748 {
1749 mGLState.getInteger64i_v(target, index, data);
1750 }
1751 else
1752 {
1753 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1754 }
1755}
1756
1757void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1758{
1759 // Queries about context capabilities and maximums are answered by Context.
1760 // Queries about current GL state values are answered by State.
1761
1762 GLenum nativeType;
1763 unsigned int numParams;
1764 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1765 ASSERT(queryStatus);
1766
1767 if (nativeType == GL_BOOL)
1768 {
1769 mGLState.getBooleani_v(target, index, data);
1770 }
1771 else
1772 {
1773 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1774 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001775}
1776
He Yunchao010e4db2017-03-03 14:22:06 +08001777void Context::getBufferParameteriv(GLenum target, GLenum pname, GLint *params)
1778{
1779 Buffer *buffer = mGLState.getTargetBuffer(target);
1780 QueryBufferParameteriv(buffer, pname, params);
1781}
1782
1783void Context::getFramebufferAttachmentParameteriv(GLenum target,
1784 GLenum attachment,
1785 GLenum pname,
1786 GLint *params)
1787{
1788 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
1789 QueryFramebufferAttachmentParameteriv(framebuffer, attachment, pname, params);
1790}
1791
1792void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
1793{
1794 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
1795 QueryRenderbufferiv(this, renderbuffer, pname, params);
1796}
1797
1798void Context::getTexParameterfv(GLenum target, GLenum pname, GLfloat *params)
1799{
1800 Texture *texture = getTargetTexture(target);
1801 QueryTexParameterfv(texture, pname, params);
1802}
1803
1804void Context::getTexParameteriv(GLenum target, GLenum pname, GLint *params)
1805{
1806 Texture *texture = getTargetTexture(target);
1807 QueryTexParameteriv(texture, pname, params);
1808}
1809void Context::texParameterf(GLenum target, GLenum pname, GLfloat param)
1810{
1811 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001812 SetTexParameterf(this, texture, pname, param);
He Yunchao010e4db2017-03-03 14:22:06 +08001813}
1814
1815void Context::texParameterfv(GLenum target, GLenum pname, const GLfloat *params)
1816{
1817 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001818 SetTexParameterfv(this, texture, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08001819}
1820
1821void Context::texParameteri(GLenum target, GLenum pname, GLint param)
1822{
1823 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001824 SetTexParameteri(this, texture, pname, param);
He Yunchao010e4db2017-03-03 14:22:06 +08001825}
1826
1827void Context::texParameteriv(GLenum target, GLenum pname, const GLint *params)
1828{
1829 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001830 SetTexParameteriv(this, texture, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08001831}
1832
Jamie Madill675fe712016-12-19 13:07:54 -05001833void Context::drawArrays(GLenum mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001834{
Jamie Madill1b94d432015-08-07 13:23:23 -04001835 syncRendererState();
Jamie Madillc564c072017-06-01 12:45:42 -04001836 auto error = mImplementation->drawArrays(this, mode, first, count);
Jamie Madill675fe712016-12-19 13:07:54 -05001837 handleError(error);
1838 if (!error.isError())
1839 {
1840 MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback());
1841 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001842}
1843
Jamie Madill675fe712016-12-19 13:07:54 -05001844void Context::drawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04001845{
1846 syncRendererState();
Jamie Madillc564c072017-06-01 12:45:42 -04001847 auto error = mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount);
Jamie Madill675fe712016-12-19 13:07:54 -05001848 handleError(error);
1849 if (!error.isError())
1850 {
1851 MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback());
1852 }
Geoff Langf6db0982015-08-25 13:04:00 -04001853}
1854
Jamie Madill876429b2017-04-20 15:46:24 -04001855void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001856{
Jamie Madill1b94d432015-08-07 13:23:23 -04001857 syncRendererState();
Jamie Madill9c9b40a2017-04-26 16:31:57 -04001858 const IndexRange &indexRange = getParams<HasIndexRange>().getIndexRange().value();
Jamie Madillc564c072017-06-01 12:45:42 -04001859 handleError(mImplementation->drawElements(this, mode, count, type, indices, indexRange));
Geoff Langf6db0982015-08-25 13:04:00 -04001860}
1861
Jamie Madill675fe712016-12-19 13:07:54 -05001862void Context::drawElementsInstanced(GLenum mode,
1863 GLsizei count,
1864 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04001865 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04001866 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04001867{
1868 syncRendererState();
Jamie Madill9c9b40a2017-04-26 16:31:57 -04001869 const IndexRange &indexRange = getParams<HasIndexRange>().getIndexRange().value();
Jamie Madillc564c072017-06-01 12:45:42 -04001870 handleError(mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances,
1871 indexRange));
Geoff Langf6db0982015-08-25 13:04:00 -04001872}
1873
Jamie Madill675fe712016-12-19 13:07:54 -05001874void Context::drawRangeElements(GLenum mode,
1875 GLuint start,
1876 GLuint end,
1877 GLsizei count,
1878 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04001879 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04001880{
1881 syncRendererState();
Jamie Madill9c9b40a2017-04-26 16:31:57 -04001882 const IndexRange &indexRange = getParams<HasIndexRange>().getIndexRange().value();
Jamie Madillc564c072017-06-01 12:45:42 -04001883 handleError(mImplementation->drawRangeElements(this, mode, start, end, count, type, indices,
1884 indexRange));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001885}
1886
Jamie Madill876429b2017-04-20 15:46:24 -04001887void Context::drawArraysIndirect(GLenum mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08001888{
1889 syncRendererState();
Jamie Madillc564c072017-06-01 12:45:42 -04001890 handleError(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08001891}
1892
Jamie Madill876429b2017-04-20 15:46:24 -04001893void Context::drawElementsIndirect(GLenum mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08001894{
1895 syncRendererState();
Jamie Madillc564c072017-06-01 12:45:42 -04001896 handleError(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08001897}
1898
Jamie Madill675fe712016-12-19 13:07:54 -05001899void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001900{
Jamie Madill675fe712016-12-19 13:07:54 -05001901 handleError(mImplementation->flush());
Geoff Lang129753a2015-01-09 16:52:09 -05001902}
1903
Jamie Madill675fe712016-12-19 13:07:54 -05001904void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05001905{
Jamie Madill675fe712016-12-19 13:07:54 -05001906 handleError(mImplementation->finish());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001907}
1908
Austin Kinross6ee1e782015-05-29 17:05:37 -07001909void Context::insertEventMarker(GLsizei length, const char *marker)
1910{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001911 ASSERT(mImplementation);
1912 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07001913}
1914
1915void Context::pushGroupMarker(GLsizei length, const char *marker)
1916{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001917 ASSERT(mImplementation);
1918 mImplementation->pushGroupMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07001919}
1920
1921void Context::popGroupMarker()
1922{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001923 ASSERT(mImplementation);
1924 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07001925}
1926
Geoff Langd8605522016-04-13 10:19:12 -04001927void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
1928{
1929 Program *programObject = getProgram(program);
1930 ASSERT(programObject);
1931
1932 programObject->bindUniformLocation(location, name);
1933}
1934
Sami Väisänena797e062016-05-12 15:23:40 +03001935void Context::setCoverageModulation(GLenum components)
1936{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001937 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03001938}
1939
Sami Väisänene45e53b2016-05-25 10:36:04 +03001940void Context::loadPathRenderingMatrix(GLenum matrixMode, const GLfloat *matrix)
1941{
1942 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
1943}
1944
1945void Context::loadPathRenderingIdentityMatrix(GLenum matrixMode)
1946{
1947 GLfloat I[16];
1948 angle::Matrix<GLfloat>::setToIdentity(I);
1949
1950 mGLState.loadPathRenderingMatrix(matrixMode, I);
1951}
1952
1953void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
1954{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001955 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001956 if (!pathObj)
1957 return;
1958
1959 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1960 syncRendererState();
1961
1962 mImplementation->stencilFillPath(pathObj, fillMode, mask);
1963}
1964
1965void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
1966{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001967 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001968 if (!pathObj)
1969 return;
1970
1971 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1972 syncRendererState();
1973
1974 mImplementation->stencilStrokePath(pathObj, reference, mask);
1975}
1976
1977void Context::coverFillPath(GLuint path, GLenum coverMode)
1978{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001979 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001980 if (!pathObj)
1981 return;
1982
1983 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1984 syncRendererState();
1985
1986 mImplementation->coverFillPath(pathObj, coverMode);
1987}
1988
1989void Context::coverStrokePath(GLuint path, GLenum coverMode)
1990{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001991 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001992 if (!pathObj)
1993 return;
1994
1995 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1996 syncRendererState();
1997
1998 mImplementation->coverStrokePath(pathObj, coverMode);
1999}
2000
2001void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
2002{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002003 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002004 if (!pathObj)
2005 return;
2006
2007 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2008 syncRendererState();
2009
2010 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
2011}
2012
2013void Context::stencilThenCoverStrokePath(GLuint path,
2014 GLint reference,
2015 GLuint mask,
2016 GLenum coverMode)
2017{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002018 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002019 if (!pathObj)
2020 return;
2021
2022 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2023 syncRendererState();
2024
2025 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2026}
2027
Sami Väisänend59ca052016-06-21 16:10:00 +03002028void Context::coverFillPathInstanced(GLsizei numPaths,
2029 GLenum pathNameType,
2030 const void *paths,
2031 GLuint pathBase,
2032 GLenum coverMode,
2033 GLenum transformType,
2034 const GLfloat *transformValues)
2035{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002036 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002037
2038 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2039 syncRendererState();
2040
2041 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2042}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002043
Sami Väisänend59ca052016-06-21 16:10:00 +03002044void Context::coverStrokePathInstanced(GLsizei numPaths,
2045 GLenum pathNameType,
2046 const void *paths,
2047 GLuint pathBase,
2048 GLenum coverMode,
2049 GLenum transformType,
2050 const GLfloat *transformValues)
2051{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002052 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002053
2054 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2055 syncRendererState();
2056
2057 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2058 transformValues);
2059}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002060
Sami Väisänend59ca052016-06-21 16:10:00 +03002061void Context::stencilFillPathInstanced(GLsizei numPaths,
2062 GLenum pathNameType,
2063 const void *paths,
2064 GLuint pathBase,
2065 GLenum fillMode,
2066 GLuint mask,
2067 GLenum transformType,
2068 const GLfloat *transformValues)
2069{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002070 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002071
2072 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2073 syncRendererState();
2074
2075 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2076 transformValues);
2077}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002078
Sami Väisänend59ca052016-06-21 16:10:00 +03002079void Context::stencilStrokePathInstanced(GLsizei numPaths,
2080 GLenum pathNameType,
2081 const void *paths,
2082 GLuint pathBase,
2083 GLint reference,
2084 GLuint mask,
2085 GLenum transformType,
2086 const GLfloat *transformValues)
2087{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002088 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002089
2090 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2091 syncRendererState();
2092
2093 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2094 transformValues);
2095}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002096
Sami Väisänend59ca052016-06-21 16:10:00 +03002097void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2098 GLenum pathNameType,
2099 const void *paths,
2100 GLuint pathBase,
2101 GLenum fillMode,
2102 GLuint mask,
2103 GLenum coverMode,
2104 GLenum transformType,
2105 const GLfloat *transformValues)
2106{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002107 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002108
2109 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2110 syncRendererState();
2111
2112 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2113 transformType, transformValues);
2114}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002115
Sami Väisänend59ca052016-06-21 16:10:00 +03002116void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2117 GLenum pathNameType,
2118 const void *paths,
2119 GLuint pathBase,
2120 GLint reference,
2121 GLuint mask,
2122 GLenum coverMode,
2123 GLenum transformType,
2124 const GLfloat *transformValues)
2125{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002126 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002127
2128 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2129 syncRendererState();
2130
2131 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2132 transformType, transformValues);
2133}
2134
Sami Väisänen46eaa942016-06-29 10:26:37 +03002135void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2136{
2137 auto *programObject = getProgram(program);
2138
2139 programObject->bindFragmentInputLocation(location, name);
2140}
2141
2142void Context::programPathFragmentInputGen(GLuint program,
2143 GLint location,
2144 GLenum genMode,
2145 GLint components,
2146 const GLfloat *coeffs)
2147{
2148 auto *programObject = getProgram(program);
2149
Jamie Madillbd044ed2017-06-05 12:59:21 -04002150 programObject->pathFragmentInputGen(this, location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002151}
2152
jchen1015015f72017-03-16 13:54:21 +08002153GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2154{
jchen10fd7c3b52017-03-21 15:36:03 +08002155 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002156 return QueryProgramResourceIndex(programObject, programInterface, name);
2157}
2158
jchen10fd7c3b52017-03-21 15:36:03 +08002159void Context::getProgramResourceName(GLuint program,
2160 GLenum programInterface,
2161 GLuint index,
2162 GLsizei bufSize,
2163 GLsizei *length,
2164 GLchar *name)
2165{
2166 const auto *programObject = getProgram(program);
2167 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2168}
2169
jchen10191381f2017-04-11 13:59:04 +08002170GLint Context::getProgramResourceLocation(GLuint program,
2171 GLenum programInterface,
2172 const GLchar *name)
2173{
2174 const auto *programObject = getProgram(program);
2175 return QueryProgramResourceLocation(programObject, programInterface, name);
2176}
2177
Jamie Madill437fa652016-05-03 15:13:24 -04002178void Context::handleError(const Error &error)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002179{
Geoff Langda5777c2014-07-11 09:52:58 -04002180 if (error.isError())
2181 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002182 GLenum code = error.getCode();
2183 mErrors.insert(code);
2184 if (code == GL_OUT_OF_MEMORY && getWorkarounds().loseContextOnOutOfMemory)
2185 {
2186 markContextLost();
2187 }
Geoff Lang70d0f492015-12-10 17:45:46 -05002188
2189 if (!error.getMessage().empty())
2190 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002191 auto *debug = &mGLState.getDebug();
2192 debug->insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, error.getID(),
2193 GL_DEBUG_SEVERITY_HIGH, error.getMessage());
Geoff Lang70d0f492015-12-10 17:45:46 -05002194 }
Geoff Langda5777c2014-07-11 09:52:58 -04002195 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002196}
2197
2198// Get one of the recorded errors and clear its flag, if any.
2199// [OpenGL ES 2.0.24] section 2.5 page 13.
2200GLenum Context::getError()
2201{
Geoff Langda5777c2014-07-11 09:52:58 -04002202 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002203 {
Geoff Langda5777c2014-07-11 09:52:58 -04002204 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002205 }
Geoff Langda5777c2014-07-11 09:52:58 -04002206 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002207 {
Geoff Langda5777c2014-07-11 09:52:58 -04002208 GLenum error = *mErrors.begin();
2209 mErrors.erase(mErrors.begin());
2210 return error;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002211 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002212}
2213
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002214// NOTE: this function should not assume that this context is current!
2215void Context::markContextLost()
2216{
2217 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002218 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002219 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002220 mContextLostForced = true;
2221 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002222 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002223}
2224
2225bool Context::isContextLost()
2226{
2227 return mContextLost;
2228}
2229
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002230GLenum Context::getResetStatus()
2231{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002232 // Even if the application doesn't want to know about resets, we want to know
2233 // as it will allow us to skip all the calls.
2234 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002235 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002236 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002237 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002238 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002239 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002240
2241 // EXT_robustness, section 2.6: If the reset notification behavior is
2242 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2243 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2244 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002245 }
2246
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002247 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2248 // status should be returned at least once, and GL_NO_ERROR should be returned
2249 // once the device has finished resetting.
2250 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002251 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002252 ASSERT(mResetStatus == GL_NO_ERROR);
2253 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002254
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002255 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002256 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002257 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002258 }
2259 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002260 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002261 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002262 // If markContextLost was used to mark the context lost then
2263 // assume that is not recoverable, and continue to report the
2264 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002265 mResetStatus = mImplementation->getResetStatus();
2266 }
Jamie Madill893ab082014-05-16 16:56:10 -04002267
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002268 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002269}
2270
2271bool Context::isResetNotificationEnabled()
2272{
2273 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2274}
2275
Corentin Walleze3b10e82015-05-20 11:06:25 -04002276const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002277{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002278 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002279}
2280
2281EGLenum Context::getClientType() const
2282{
2283 return mClientType;
2284}
2285
2286EGLenum Context::getRenderBuffer() const
2287{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002288 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2289 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002290 {
2291 return EGL_NONE;
2292 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002293
2294 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(GL_BACK);
2295 ASSERT(backAttachment != nullptr);
2296 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002297}
2298
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002299VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002300{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002301 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002302 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2303 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002304 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002305 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2306 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002307
Jamie Madill96a483b2017-06-27 16:49:21 -04002308 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002309 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002310
2311 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002312}
2313
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002314TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002315{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002316 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002317 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2318 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002319 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002320 transformFeedback =
2321 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002322 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002323 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002324 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002325
2326 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002327}
2328
2329bool Context::isVertexArrayGenerated(GLuint vertexArray)
2330{
Jamie Madill96a483b2017-06-27 16:49:21 -04002331 ASSERT(mVertexArrayMap.contains(0));
2332 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002333}
2334
2335bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2336{
Jamie Madill96a483b2017-06-27 16:49:21 -04002337 ASSERT(mTransformFeedbackMap.contains(0));
2338 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002339}
2340
Shannon Woods53a94a82014-06-24 15:20:36 -04002341void Context::detachTexture(GLuint texture)
2342{
2343 // Simple pass-through to State's detachTexture method, as textures do not require
2344 // allocation map management either here or in the resource manager at detach time.
2345 // Zero textures are held by the Context, and we don't attempt to request them from
2346 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002347 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002348}
2349
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002350void Context::detachBuffer(GLuint buffer)
2351{
Yuly Novikov5807a532015-12-03 13:01:22 -05002352 // Simple pass-through to State's detachBuffer method, since
2353 // only buffer attachments to container objects that are bound to the current context
2354 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002355
Yuly Novikov5807a532015-12-03 13:01:22 -05002356 // [OpenGL ES 3.2] section 5.1.2 page 45:
2357 // Attachments to unbound container objects, such as
2358 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2359 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002360 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002361}
2362
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002363void Context::detachFramebuffer(GLuint framebuffer)
2364{
Shannon Woods53a94a82014-06-24 15:20:36 -04002365 // Framebuffer detachment is handled by Context, because 0 is a valid
2366 // Framebuffer object, and a pointer to it must be passed from Context
2367 // to State at binding time.
2368
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002369 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002370 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2371 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2372 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002373
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002374 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002375 {
2376 bindReadFramebuffer(0);
2377 }
2378
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002379 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002380 {
2381 bindDrawFramebuffer(0);
2382 }
2383}
2384
2385void Context::detachRenderbuffer(GLuint renderbuffer)
2386{
Jamie Madilla02315b2017-02-23 14:14:47 -05002387 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002388}
2389
Jamie Madill57a89722013-07-02 11:57:03 -04002390void Context::detachVertexArray(GLuint vertexArray)
2391{
Jamie Madill77a72f62015-04-14 11:18:32 -04002392 // Vertex array detachment is handled by Context, because 0 is a valid
2393 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002394 // binding time.
2395
Jamie Madill57a89722013-07-02 11:57:03 -04002396 // [OpenGL ES 3.0.2] section 2.10 page 43:
2397 // If a vertex array object that is currently bound is deleted, the binding
2398 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002399 if (mGLState.removeVertexArrayBinding(vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002400 {
2401 bindVertexArray(0);
2402 }
2403}
2404
Geoff Langc8058452014-02-03 12:04:11 -05002405void Context::detachTransformFeedback(GLuint transformFeedback)
2406{
Corentin Walleza2257da2016-04-19 16:43:12 -04002407 // Transform feedback detachment is handled by Context, because 0 is a valid
2408 // transform feedback, and a pointer to it must be passed from Context to State at
2409 // binding time.
2410
2411 // The OpenGL specification doesn't mention what should happen when the currently bound
2412 // transform feedback object is deleted. Since it is a container object, we treat it like
2413 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002414 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002415 {
2416 bindTransformFeedback(0);
2417 }
Geoff Langc8058452014-02-03 12:04:11 -05002418}
2419
Jamie Madilldc356042013-07-19 16:36:57 -04002420void Context::detachSampler(GLuint sampler)
2421{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002422 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002423}
2424
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002425void Context::setVertexAttribDivisor(GLuint index, GLuint divisor)
2426{
Shaodde78e82017-05-22 14:13:27 +08002427 mGLState.setVertexAttribDivisor(this, index, divisor);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002428}
2429
Jamie Madille29d1672013-07-19 16:36:57 -04002430void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint 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 SetSamplerParameteri(samplerObject, pname, param);
2435}
Jamie Madille29d1672013-07-19 16:36:57 -04002436
Geoff Langc1984ed2016-10-07 12:41:00 -04002437void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2438{
2439 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002440 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002441 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madille29d1672013-07-19 16:36:57 -04002442}
2443
2444void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2445{
Geoff Langc1984ed2016-10-07 12:41:00 -04002446 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002447 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002448 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madille29d1672013-07-19 16:36:57 -04002449}
2450
Geoff Langc1984ed2016-10-07 12:41:00 -04002451void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002452{
Geoff Langc1984ed2016-10-07 12:41:00 -04002453 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002454 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002455 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill9675b802013-07-19 16:36:59 -04002456}
2457
Geoff Langc1984ed2016-10-07 12:41:00 -04002458void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002459{
Geoff Langc1984ed2016-10-07 12:41:00 -04002460 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002461 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002462 QuerySamplerParameteriv(samplerObject, pname, params);
2463}
Jamie Madill9675b802013-07-19 16:36:59 -04002464
Geoff Langc1984ed2016-10-07 12:41:00 -04002465void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2466{
2467 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002468 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002469 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill9675b802013-07-19 16:36:59 -04002470}
2471
Olli Etuahof0fee072016-03-30 15:11:58 +03002472void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2473{
2474 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002475 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002476}
2477
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002478void Context::initRendererString()
2479{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002480 std::ostringstream rendererString;
2481 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002482 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002483 rendererString << ")";
2484
Geoff Langcec35902014-04-16 10:52:36 -04002485 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002486}
2487
Geoff Langc339c4e2016-11-29 10:37:36 -05002488void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002489{
Geoff Langc339c4e2016-11-29 10:37:36 -05002490 const Version &clientVersion = getClientVersion();
2491
2492 std::ostringstream versionString;
2493 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2494 << ANGLE_VERSION_STRING << ")";
2495 mVersionString = MakeStaticString(versionString.str());
2496
2497 std::ostringstream shadingLanguageVersionString;
2498 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2499 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2500 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2501 << ")";
2502 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002503}
2504
Geoff Langcec35902014-04-16 10:52:36 -04002505void Context::initExtensionStrings()
2506{
Geoff Langc339c4e2016-11-29 10:37:36 -05002507 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2508 std::ostringstream combinedStringStream;
2509 std::copy(strings.begin(), strings.end(),
2510 std::ostream_iterator<const char *>(combinedStringStream, " "));
2511 return MakeStaticString(combinedStringStream.str());
2512 };
2513
2514 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002515 for (const auto &extensionString : mExtensions.getStrings())
2516 {
2517 mExtensionStrings.push_back(MakeStaticString(extensionString));
2518 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002519 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002520
Bryan Bernhart58806562017-01-05 13:09:31 -08002521 const gl::Extensions &nativeExtensions = mImplementation->getNativeExtensions();
2522
Geoff Langc339c4e2016-11-29 10:37:36 -05002523 mRequestableExtensionStrings.clear();
2524 for (const auto &extensionInfo : GetExtensionInfoMap())
2525 {
2526 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08002527 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
2528 nativeExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002529 {
2530 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
2531 }
2532 }
2533 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002534}
2535
Geoff Langc339c4e2016-11-29 10:37:36 -05002536const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04002537{
Geoff Langc339c4e2016-11-29 10:37:36 -05002538 switch (name)
2539 {
2540 case GL_VENDOR:
2541 return reinterpret_cast<const GLubyte *>("Google Inc.");
2542
2543 case GL_RENDERER:
2544 return reinterpret_cast<const GLubyte *>(mRendererString);
2545
2546 case GL_VERSION:
2547 return reinterpret_cast<const GLubyte *>(mVersionString);
2548
2549 case GL_SHADING_LANGUAGE_VERSION:
2550 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
2551
2552 case GL_EXTENSIONS:
2553 return reinterpret_cast<const GLubyte *>(mExtensionString);
2554
2555 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2556 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
2557
2558 default:
2559 UNREACHABLE();
2560 return nullptr;
2561 }
Geoff Langcec35902014-04-16 10:52:36 -04002562}
2563
Geoff Langc339c4e2016-11-29 10:37:36 -05002564const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04002565{
Geoff Langc339c4e2016-11-29 10:37:36 -05002566 switch (name)
2567 {
2568 case GL_EXTENSIONS:
2569 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
2570
2571 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2572 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
2573
2574 default:
2575 UNREACHABLE();
2576 return nullptr;
2577 }
Geoff Langcec35902014-04-16 10:52:36 -04002578}
2579
2580size_t Context::getExtensionStringCount() const
2581{
2582 return mExtensionStrings.size();
2583}
2584
Geoff Langc339c4e2016-11-29 10:37:36 -05002585void Context::requestExtension(const char *name)
2586{
2587 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2588 ASSERT(extensionInfos.find(name) != extensionInfos.end());
2589 const auto &extension = extensionInfos.at(name);
2590 ASSERT(extension.Requestable);
2591
2592 if (mExtensions.*(extension.ExtensionsMember))
2593 {
2594 // Extension already enabled
2595 return;
2596 }
2597
2598 mExtensions.*(extension.ExtensionsMember) = true;
2599 updateCaps();
2600 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08002601
Jamie Madill2f348d22017-06-05 10:50:59 -04002602 // Release the shader compiler so it will be re-created with the requested extensions enabled.
2603 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04002604
2605 // Invalidate all cached completenesses for textures and framebuffer. Some extensions make new
2606 // formats renderable or sampleable.
2607 mState.mTextures->invalidateTextureComplenessCache();
2608 for (auto &zeroTexture : mZeroTextures)
2609 {
2610 zeroTexture.second->invalidateCompletenessCache();
2611 }
2612
2613 mState.mFramebuffers->invalidateFramebufferComplenessCache();
Geoff Langc339c4e2016-11-29 10:37:36 -05002614}
2615
2616size_t Context::getRequestableExtensionStringCount() const
2617{
2618 return mRequestableExtensionStrings.size();
2619}
2620
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002621void Context::beginTransformFeedback(GLenum primitiveMode)
2622{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002623 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002624 ASSERT(transformFeedback != nullptr);
2625 ASSERT(!transformFeedback->isPaused());
2626
Jamie Madill6c1f6712017-02-14 19:08:04 -05002627 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002628}
2629
2630bool Context::hasActiveTransformFeedback(GLuint program) const
2631{
2632 for (auto pair : mTransformFeedbackMap)
2633 {
2634 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
2635 {
2636 return true;
2637 }
2638 }
2639 return false;
2640}
2641
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002642void Context::initCaps(const egl::DisplayExtensions &displayExtensions)
Geoff Lang493daf52014-07-03 13:38:44 -04002643{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002644 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04002645
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002646 mExtensions = mImplementation->getNativeExtensions();
Geoff Lang493daf52014-07-03 13:38:44 -04002647
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002648 mLimitations = mImplementation->getNativeLimitations();
Austin Kinross02df7962015-07-01 10:03:42 -07002649
Geoff Langeb66a6e2016-10-31 13:06:12 -04002650 if (getClientVersion() < Version(3, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002651 {
2652 // Disable ES3+ extensions
Jamie Madill231c7f52017-04-26 13:45:37 -04002653 mExtensions.colorBufferFloat = false;
Geoff Langb66a9092016-05-16 15:59:14 -04002654 mExtensions.eglImageExternalEssl3 = false;
Vincent Lang25ab4512016-05-13 18:13:59 +02002655 mExtensions.textureNorm16 = false;
Martin Radev137032d2017-07-13 10:11:12 +03002656 mExtensions.multiview = false;
2657 mExtensions.maxViews = 1u;
Geoff Lang493daf52014-07-03 13:38:44 -04002658 }
2659
Geoff Langeb66a6e2016-10-31 13:06:12 -04002660 if (getClientVersion() > Version(2, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002661 {
2662 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
Jamie Madill231c7f52017-04-26 13:45:37 -04002663 // mExtensions.sRGB = false;
Geoff Lang493daf52014-07-03 13:38:44 -04002664 }
2665
Jamie Madill00ed7a12016-05-19 13:13:38 -04002666 // Some extensions are always available because they are implemented in the GL layer.
Jamie Madill231c7f52017-04-26 13:45:37 -04002667 mExtensions.bindUniformLocation = true;
2668 mExtensions.vertexArrayObject = true;
Geoff Langf41a7152016-09-19 15:11:17 -04002669 mExtensions.bindGeneratesResource = true;
Geoff Langfeb8c682017-02-13 16:07:35 -05002670 mExtensions.clientArrays = true;
Geoff Langc339c4e2016-11-29 10:37:36 -05002671 mExtensions.requestExtension = true;
Jamie Madill00ed7a12016-05-19 13:13:38 -04002672
2673 // Enable the no error extension if the context was created with the flag.
2674 mExtensions.noError = mSkipValidation;
2675
Corentin Wallezccab69d2017-01-27 16:57:15 -05002676 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Corentin Wallezc295e512017-01-27 17:47:50 -05002677 mExtensions.surfacelessContext = displayExtensions.surfacelessContext;
Corentin Wallezccab69d2017-01-27 16:57:15 -05002678
Geoff Lang70d0f492015-12-10 17:45:46 -05002679 // Explicitly enable GL_KHR_debug
2680 mExtensions.debug = true;
2681 mExtensions.maxDebugMessageLength = 1024;
2682 mExtensions.maxDebugLoggedMessages = 1024;
2683 mExtensions.maxDebugGroupStackDepth = 1024;
2684 mExtensions.maxLabelLength = 1024;
2685
Geoff Langff5b2d52016-09-07 11:32:23 -04002686 // Explicitly enable GL_ANGLE_robust_client_memory
2687 mExtensions.robustClientMemory = true;
2688
Jamie Madille08a1d32017-03-07 17:24:06 -05002689 // Determine robust resource init availability from EGL.
2690 mExtensions.robustResourceInitialization =
Jamie Madill948bbe52017-06-01 13:10:42 -04002691 egl::Display::GetClientExtensions().displayRobustResourceInitialization;
Jamie Madille08a1d32017-03-07 17:24:06 -05002692
Jamie Madillc43be722017-07-13 16:22:14 -04002693 // Enable the cache control query unconditionally.
2694 mExtensions.programCacheControl = true;
2695
Geoff Lang301d1612014-07-09 10:34:37 -04002696 // Apply implementation limits
2697 mCaps.maxVertexAttributes = std::min<GLuint>(mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002698 mCaps.maxVertexAttribBindings =
2699 getClientVersion() < ES_3_1
2700 ? mCaps.maxVertexAttributes
2701 : std::min<GLuint>(mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
2702
Jamie Madill231c7f52017-04-26 13:45:37 -04002703 mCaps.maxVertexUniformBlocks = std::min<GLuint>(
2704 mCaps.maxVertexUniformBlocks, IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
2705 mCaps.maxVertexOutputComponents =
2706 std::min<GLuint>(mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
Geoff Lang301d1612014-07-09 10:34:37 -04002707
Jamie Madill231c7f52017-04-26 13:45:37 -04002708 mCaps.maxFragmentInputComponents =
2709 std::min<GLuint>(mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
Geoff Lang3a61c322014-07-10 13:01:54 -04002710
Geoff Langc287ea62016-09-16 14:46:51 -04002711 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002712 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04002713 for (const auto &extensionInfo : GetExtensionInfoMap())
2714 {
2715 // If this context is for WebGL, disable all enableable extensions
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002716 if (mWebGLContext && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04002717 {
2718 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
2719 }
2720 }
2721
2722 // Generate texture caps
2723 updateCaps();
2724}
2725
2726void Context::updateCaps()
2727{
Geoff Lang900013c2014-07-07 11:32:19 -04002728 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002729 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04002730
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002731 for (auto capsIt : mImplementation->getNativeTextureCaps())
Geoff Lang493daf52014-07-03 13:38:44 -04002732 {
Geoff Langca271392017-04-05 12:30:00 -04002733 GLenum sizedInternalFormat = capsIt.first;
Jamie Madill231c7f52017-04-26 13:45:37 -04002734 TextureCaps formatCaps = capsIt.second;
Geoff Lang493daf52014-07-03 13:38:44 -04002735
Geoff Langca271392017-04-05 12:30:00 -04002736 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04002737
Geoff Lang0d8b7242015-09-09 14:56:53 -04002738 // Update the format caps based on the client version and extensions.
2739 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
2740 // ES3.
2741 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002742 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002743 formatCaps.renderable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002744 formatCaps.renderable && formatInfo.renderSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002745 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002746 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04002747
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002748 // OpenGL ES does not support multisampling with non-rendererable formats
2749 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Olli Etuaho50c562d2017-06-06 14:43:30 +03002750 if (!formatCaps.renderable ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002751 (getClientVersion() < ES_3_1 &&
2752 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04002753 {
Geoff Langd87878e2014-09-19 15:42:59 -04002754 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04002755 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03002756 else
2757 {
2758 // We may have limited the max samples for some required renderbuffer formats due to
2759 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
2760 GLuint formatMaxSamples = formatCaps.getMaxSamples();
2761
2762 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
2763 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
2764 // exception of signed and unsigned integer formats."
2765 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
2766 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
2767 {
2768 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
2769 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
2770 }
2771
2772 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
2773 if (getClientVersion() >= ES_3_1)
2774 {
2775 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
2776 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
2777 // the exception that the signed and unsigned integer formats are required only to
2778 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
2779 // multisamples, which must be at least one."
2780 if (formatInfo.componentType == GL_INT ||
2781 formatInfo.componentType == GL_UNSIGNED_INT)
2782 {
2783 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
2784 }
2785
2786 // GLES 3.1 section 19.3.1.
2787 if (formatCaps.texturable)
2788 {
2789 if (formatInfo.depthBits > 0)
2790 {
2791 mCaps.maxDepthTextureSamples =
2792 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
2793 }
2794 else if (formatInfo.redBits > 0)
2795 {
2796 mCaps.maxColorTextureSamples =
2797 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
2798 }
2799 }
2800 }
2801 }
Geoff Langd87878e2014-09-19 15:42:59 -04002802
2803 if (formatCaps.texturable && formatInfo.compressed)
2804 {
Geoff Langca271392017-04-05 12:30:00 -04002805 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04002806 }
2807
Geoff Langca271392017-04-05 12:30:00 -04002808 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04002809 }
Jamie Madill32447362017-06-28 14:53:52 -04002810
2811 // If program binary is disabled, blank out the memory cache pointer.
2812 if (!mImplementation->getNativeExtensions().getProgramBinary)
2813 {
2814 mMemoryProgramCache = nullptr;
2815 }
Geoff Lang493daf52014-07-03 13:38:44 -04002816}
2817
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002818void Context::initWorkarounds()
2819{
Jamie Madill761b02c2017-06-23 16:27:06 -04002820 // Apply back-end workarounds.
2821 mImplementation->applyNativeWorkarounds(&mWorkarounds);
2822
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002823 // Lose the context upon out of memory error if the application is
2824 // expecting to watch for those events.
2825 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2826}
2827
Jamie Madill1b94d432015-08-07 13:23:23 -04002828void Context::syncRendererState()
2829{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002830 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
Jamie Madillfe548342017-06-19 11:13:24 -04002831 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002832 mGLState.clearDirtyBits();
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002833 mGLState.syncDirtyObjects(this);
Jamie Madill1b94d432015-08-07 13:23:23 -04002834}
2835
Jamie Madillad9f24e2016-02-12 09:27:24 -05002836void Context::syncRendererState(const State::DirtyBits &bitMask,
2837 const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04002838{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002839 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madillfe548342017-06-19 11:13:24 -04002840 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002841 mGLState.clearDirtyBits(dirtyBits);
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002842 mGLState.syncDirtyObjects(this, objectMask);
Jamie Madill1b94d432015-08-07 13:23:23 -04002843}
Jamie Madillc29968b2016-01-20 11:17:23 -05002844
2845void Context::blitFramebuffer(GLint srcX0,
2846 GLint srcY0,
2847 GLint srcX1,
2848 GLint srcY1,
2849 GLint dstX0,
2850 GLint dstY0,
2851 GLint dstX1,
2852 GLint dstY1,
2853 GLbitfield mask,
2854 GLenum filter)
2855{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002856 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002857 ASSERT(drawFramebuffer);
2858
2859 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
2860 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
2861
Jamie Madillad9f24e2016-02-12 09:27:24 -05002862 syncStateForBlit();
Jamie Madillc29968b2016-01-20 11:17:23 -05002863
Jamie Madillc564c072017-06-01 12:45:42 -04002864 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002865}
Jamie Madillc29968b2016-01-20 11:17:23 -05002866
2867void Context::clear(GLbitfield mask)
2868{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002869 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002870 handleError(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05002871}
2872
2873void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
2874{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002875 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002876 handleError(mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002877}
2878
2879void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
2880{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002881 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002882 handleError(mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002883}
2884
2885void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
2886{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002887 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002888 handleError(mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002889}
2890
2891void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
2892{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002893 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002894 ASSERT(framebufferObject);
2895
2896 // If a buffer is not present, the clear has no effect
2897 if (framebufferObject->getDepthbuffer() == nullptr &&
2898 framebufferObject->getStencilbuffer() == nullptr)
2899 {
2900 return;
2901 }
2902
Jamie Madillad9f24e2016-02-12 09:27:24 -05002903 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002904 handleError(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05002905}
2906
2907void Context::readPixels(GLint x,
2908 GLint y,
2909 GLsizei width,
2910 GLsizei height,
2911 GLenum format,
2912 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002913 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05002914{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04002915 if (width == 0 || height == 0)
2916 {
2917 return;
2918 }
2919
Jamie Madillad9f24e2016-02-12 09:27:24 -05002920 syncStateForReadPixels();
Jamie Madillc29968b2016-01-20 11:17:23 -05002921
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002922 Framebuffer *framebufferObject = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002923 ASSERT(framebufferObject);
2924
2925 Rectangle area(x, y, width, height);
Jamie Madillc564c072017-06-01 12:45:42 -04002926 handleError(framebufferObject->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05002927}
2928
2929void Context::copyTexImage2D(GLenum target,
2930 GLint level,
2931 GLenum internalformat,
2932 GLint x,
2933 GLint y,
2934 GLsizei width,
2935 GLsizei height,
2936 GLint border)
2937{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002938 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002939 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002940
Jamie Madillc29968b2016-01-20 11:17:23 -05002941 Rectangle sourceArea(x, y, width, height);
2942
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002943 const Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002944 Texture *texture =
2945 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05002946 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05002947}
2948
2949void Context::copyTexSubImage2D(GLenum target,
2950 GLint level,
2951 GLint xoffset,
2952 GLint yoffset,
2953 GLint x,
2954 GLint y,
2955 GLsizei width,
2956 GLsizei height)
2957{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04002958 if (width == 0 || height == 0)
2959 {
2960 return;
2961 }
2962
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002963 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002964 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002965
Jamie Madillc29968b2016-01-20 11:17:23 -05002966 Offset destOffset(xoffset, yoffset, 0);
2967 Rectangle sourceArea(x, y, width, height);
2968
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002969 const Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002970 Texture *texture =
2971 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05002972 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05002973}
2974
2975void Context::copyTexSubImage3D(GLenum target,
2976 GLint level,
2977 GLint xoffset,
2978 GLint yoffset,
2979 GLint zoffset,
2980 GLint x,
2981 GLint y,
2982 GLsizei width,
2983 GLsizei height)
2984{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04002985 if (width == 0 || height == 0)
2986 {
2987 return;
2988 }
2989
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002990 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002991 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002992
Jamie Madillc29968b2016-01-20 11:17:23 -05002993 Offset destOffset(xoffset, yoffset, zoffset);
2994 Rectangle sourceArea(x, y, width, height);
2995
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002996 const Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002997 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05002998 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05002999}
3000
3001void Context::framebufferTexture2D(GLenum target,
3002 GLenum attachment,
3003 GLenum textarget,
3004 GLuint texture,
3005 GLint level)
3006{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003007 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003008 ASSERT(framebuffer);
3009
3010 if (texture != 0)
3011 {
3012 Texture *textureObj = getTexture(texture);
3013
3014 ImageIndex index = ImageIndex::MakeInvalid();
3015
3016 if (textarget == GL_TEXTURE_2D)
3017 {
3018 index = ImageIndex::Make2D(level);
3019 }
JiangYizhoubddc46b2016-12-09 09:50:51 +08003020 else if (textarget == GL_TEXTURE_2D_MULTISAMPLE)
3021 {
3022 ASSERT(level == 0);
3023 index = ImageIndex::Make2DMultisample();
3024 }
Jamie Madillc29968b2016-01-20 11:17:23 -05003025 else
3026 {
3027 ASSERT(IsCubeMapTextureTarget(textarget));
3028 index = ImageIndex::MakeCube(textarget, level);
3029 }
3030
Jamie Madilla02315b2017-02-23 14:14:47 -05003031 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003032 }
3033 else
3034 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003035 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003036 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003037
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003038 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003039}
3040
3041void Context::framebufferRenderbuffer(GLenum target,
3042 GLenum attachment,
3043 GLenum renderbuffertarget,
3044 GLuint renderbuffer)
3045{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003046 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003047 ASSERT(framebuffer);
3048
3049 if (renderbuffer != 0)
3050 {
3051 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003052
3053 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex::MakeInvalid(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003054 renderbufferObject);
3055 }
3056 else
3057 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003058 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003059 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003060
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003061 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003062}
3063
3064void Context::framebufferTextureLayer(GLenum target,
3065 GLenum attachment,
3066 GLuint texture,
3067 GLint level,
3068 GLint layer)
3069{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003070 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003071 ASSERT(framebuffer);
3072
3073 if (texture != 0)
3074 {
3075 Texture *textureObject = getTexture(texture);
3076
3077 ImageIndex index = ImageIndex::MakeInvalid();
3078
3079 if (textureObject->getTarget() == GL_TEXTURE_3D)
3080 {
3081 index = ImageIndex::Make3D(level, layer);
3082 }
3083 else
3084 {
3085 ASSERT(textureObject->getTarget() == GL_TEXTURE_2D_ARRAY);
3086 index = ImageIndex::Make2DArray(level, layer);
3087 }
3088
Jamie Madilla02315b2017-02-23 14:14:47 -05003089 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003090 }
3091 else
3092 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003093 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003094 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003095
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003096 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003097}
3098
Martin Radev137032d2017-07-13 10:11:12 +03003099void Context::framebufferTextureMultiviewLayeredANGLE(GLenum target,
3100 GLenum attachment,
3101 GLuint texture,
3102 GLint level,
3103 GLint baseViewIndex,
3104 GLsizei numViews)
3105{
3106 UNIMPLEMENTED();
3107}
3108
3109void Context::framebufferTextureMultiviewSideBySideANGLE(GLenum target,
3110 GLenum attachment,
3111 GLuint texture,
3112 GLint level,
3113 GLsizei numViews,
3114 const GLint *viewportOffsets)
3115{
3116 UNIMPLEMENTED();
3117}
3118
Jamie Madillc29968b2016-01-20 11:17:23 -05003119void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3120{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003121 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003122 ASSERT(framebuffer);
3123 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003124 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003125}
3126
3127void Context::readBuffer(GLenum mode)
3128{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003129 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003130 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003131 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003132}
3133
3134void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3135{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003136 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003137 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003138
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003139 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003140 ASSERT(framebuffer);
3141
3142 // The specification isn't clear what should be done when the framebuffer isn't complete.
3143 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003144 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003145}
3146
3147void Context::invalidateFramebuffer(GLenum target,
3148 GLsizei numAttachments,
3149 const GLenum *attachments)
3150{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003151 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003152 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003153
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003154 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003155 ASSERT(framebuffer);
3156
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003157 if (framebuffer->checkStatus(this) != GL_FRAMEBUFFER_COMPLETE)
Jamie Madillc29968b2016-01-20 11:17:23 -05003158 {
Jamie Madill437fa652016-05-03 15:13:24 -04003159 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003160 }
Jamie Madill437fa652016-05-03 15:13:24 -04003161
Jamie Madill4928b7c2017-06-20 12:57:39 -04003162 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003163}
3164
3165void Context::invalidateSubFramebuffer(GLenum target,
3166 GLsizei numAttachments,
3167 const GLenum *attachments,
3168 GLint x,
3169 GLint y,
3170 GLsizei width,
3171 GLsizei height)
3172{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003173 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003174 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003175
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003176 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003177 ASSERT(framebuffer);
3178
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003179 if (framebuffer->checkStatus(this) != GL_FRAMEBUFFER_COMPLETE)
Jamie Madillc29968b2016-01-20 11:17:23 -05003180 {
Jamie Madill437fa652016-05-03 15:13:24 -04003181 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003182 }
Jamie Madill437fa652016-05-03 15:13:24 -04003183
3184 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003185 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003186}
3187
Jamie Madill73a84962016-02-12 09:27:23 -05003188void Context::texImage2D(GLenum target,
3189 GLint level,
3190 GLint internalformat,
3191 GLsizei width,
3192 GLsizei height,
3193 GLint border,
3194 GLenum format,
3195 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003196 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003197{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003198 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003199
3200 Extents size(width, height, 1);
3201 Texture *texture =
3202 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003203 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3204 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003205}
3206
3207void Context::texImage3D(GLenum target,
3208 GLint level,
3209 GLint internalformat,
3210 GLsizei width,
3211 GLsizei height,
3212 GLsizei depth,
3213 GLint border,
3214 GLenum format,
3215 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003216 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003217{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003218 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003219
3220 Extents size(width, height, depth);
3221 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003222 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3223 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003224}
3225
3226void Context::texSubImage2D(GLenum target,
3227 GLint level,
3228 GLint xoffset,
3229 GLint yoffset,
3230 GLsizei width,
3231 GLsizei height,
3232 GLenum format,
3233 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003234 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003235{
3236 // Zero sized uploads are valid but no-ops
3237 if (width == 0 || height == 0)
3238 {
3239 return;
3240 }
3241
Jamie Madillad9f24e2016-02-12 09:27:24 -05003242 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003243
3244 Box area(xoffset, yoffset, 0, width, height, 1);
3245 Texture *texture =
3246 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003247 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3248 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003249}
3250
3251void Context::texSubImage3D(GLenum target,
3252 GLint level,
3253 GLint xoffset,
3254 GLint yoffset,
3255 GLint zoffset,
3256 GLsizei width,
3257 GLsizei height,
3258 GLsizei depth,
3259 GLenum format,
3260 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003261 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003262{
3263 // Zero sized uploads are valid but no-ops
3264 if (width == 0 || height == 0 || depth == 0)
3265 {
3266 return;
3267 }
3268
Jamie Madillad9f24e2016-02-12 09:27:24 -05003269 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003270
3271 Box area(xoffset, yoffset, zoffset, width, height, depth);
3272 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003273 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3274 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003275}
3276
3277void Context::compressedTexImage2D(GLenum target,
3278 GLint level,
3279 GLenum internalformat,
3280 GLsizei width,
3281 GLsizei height,
3282 GLint border,
3283 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003284 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003285{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003286 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003287
3288 Extents size(width, height, 1);
3289 Texture *texture =
3290 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003291 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003292 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003293 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003294}
3295
3296void Context::compressedTexImage3D(GLenum target,
3297 GLint level,
3298 GLenum internalformat,
3299 GLsizei width,
3300 GLsizei height,
3301 GLsizei depth,
3302 GLint border,
3303 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003304 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003305{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003306 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003307
3308 Extents size(width, height, depth);
3309 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003310 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003311 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003312 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003313}
3314
3315void Context::compressedTexSubImage2D(GLenum target,
3316 GLint level,
3317 GLint xoffset,
3318 GLint yoffset,
3319 GLsizei width,
3320 GLsizei height,
3321 GLenum format,
3322 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003323 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003324{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003325 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003326
3327 Box area(xoffset, yoffset, 0, width, height, 1);
3328 Texture *texture =
3329 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003330 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003331 format, imageSize,
3332 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003333}
3334
3335void Context::compressedTexSubImage3D(GLenum target,
3336 GLint level,
3337 GLint xoffset,
3338 GLint yoffset,
3339 GLint zoffset,
3340 GLsizei width,
3341 GLsizei height,
3342 GLsizei depth,
3343 GLenum format,
3344 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003345 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003346{
3347 // Zero sized uploads are valid but no-ops
3348 if (width == 0 || height == 0)
3349 {
3350 return;
3351 }
3352
Jamie Madillad9f24e2016-02-12 09:27:24 -05003353 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003354
3355 Box area(xoffset, yoffset, zoffset, width, height, depth);
3356 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003357 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003358 format, imageSize,
3359 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003360}
3361
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003362void Context::generateMipmap(GLenum target)
3363{
3364 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003365 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003366}
3367
Geoff Lang97073d12016-04-20 10:42:34 -07003368void Context::copyTextureCHROMIUM(GLuint sourceId,
Geoff Langfc72a072017-03-24 14:52:39 -04003369 GLint sourceLevel,
3370 GLenum destTarget,
Geoff Lang97073d12016-04-20 10:42:34 -07003371 GLuint destId,
Geoff Langfc72a072017-03-24 14:52:39 -04003372 GLint destLevel,
Geoff Lang97073d12016-04-20 10:42:34 -07003373 GLint internalFormat,
3374 GLenum destType,
3375 GLboolean unpackFlipY,
3376 GLboolean unpackPremultiplyAlpha,
3377 GLboolean unpackUnmultiplyAlpha)
3378{
3379 syncStateForTexImage();
3380
3381 gl::Texture *sourceTexture = getTexture(sourceId);
3382 gl::Texture *destTexture = getTexture(destId);
Geoff Langfc72a072017-03-24 14:52:39 -04003383 handleError(destTexture->copyTexture(
3384 this, destTarget, destLevel, internalFormat, destType, sourceLevel, unpackFlipY == GL_TRUE,
3385 unpackPremultiplyAlpha == GL_TRUE, unpackUnmultiplyAlpha == GL_TRUE, sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003386}
3387
3388void Context::copySubTextureCHROMIUM(GLuint sourceId,
Geoff Langfc72a072017-03-24 14:52:39 -04003389 GLint sourceLevel,
3390 GLenum destTarget,
Geoff Lang97073d12016-04-20 10:42:34 -07003391 GLuint destId,
Geoff Langfc72a072017-03-24 14:52:39 -04003392 GLint destLevel,
Geoff Lang97073d12016-04-20 10:42:34 -07003393 GLint xoffset,
3394 GLint yoffset,
3395 GLint x,
3396 GLint y,
3397 GLsizei width,
3398 GLsizei height,
3399 GLboolean unpackFlipY,
3400 GLboolean unpackPremultiplyAlpha,
3401 GLboolean unpackUnmultiplyAlpha)
3402{
3403 // Zero sized copies are valid but no-ops
3404 if (width == 0 || height == 0)
3405 {
3406 return;
3407 }
3408
3409 syncStateForTexImage();
3410
3411 gl::Texture *sourceTexture = getTexture(sourceId);
3412 gl::Texture *destTexture = getTexture(destId);
3413 Offset offset(xoffset, yoffset, 0);
3414 Rectangle area(x, y, width, height);
Geoff Langfc72a072017-03-24 14:52:39 -04003415 handleError(destTexture->copySubTexture(
3416 this, destTarget, destLevel, offset, sourceLevel, area, unpackFlipY == GL_TRUE,
3417 unpackPremultiplyAlpha == GL_TRUE, unpackUnmultiplyAlpha == GL_TRUE, sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003418}
3419
Geoff Lang47110bf2016-04-20 11:13:22 -07003420void Context::compressedCopyTextureCHROMIUM(GLuint sourceId, GLuint destId)
3421{
3422 syncStateForTexImage();
3423
3424 gl::Texture *sourceTexture = getTexture(sourceId);
3425 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05003426 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07003427}
3428
Geoff Lang496c02d2016-10-20 11:38:11 -07003429void Context::getBufferPointerv(GLenum target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03003430{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003431 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003432 ASSERT(buffer);
3433
Geoff Lang496c02d2016-10-20 11:38:11 -07003434 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03003435}
3436
Jamie Madill876429b2017-04-20 15:46:24 -04003437void *Context::mapBuffer(GLenum target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003438{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003439 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003440 ASSERT(buffer);
3441
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003442 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003443 if (error.isError())
3444 {
Jamie Madill437fa652016-05-03 15:13:24 -04003445 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003446 return nullptr;
3447 }
3448
3449 return buffer->getMapPointer();
3450}
3451
3452GLboolean Context::unmapBuffer(GLenum target)
3453{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003454 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003455 ASSERT(buffer);
3456
3457 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003458 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03003459 if (error.isError())
3460 {
Jamie Madill437fa652016-05-03 15:13:24 -04003461 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003462 return GL_FALSE;
3463 }
3464
3465 return result;
3466}
3467
Jamie Madill876429b2017-04-20 15:46:24 -04003468void *Context::mapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003469{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003470 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003471 ASSERT(buffer);
3472
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003473 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003474 if (error.isError())
3475 {
Jamie Madill437fa652016-05-03 15:13:24 -04003476 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003477 return nullptr;
3478 }
3479
3480 return buffer->getMapPointer();
3481}
3482
3483void Context::flushMappedBufferRange(GLenum /*target*/, GLintptr /*offset*/, GLsizeiptr /*length*/)
3484{
3485 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
3486}
3487
Jamie Madillad9f24e2016-02-12 09:27:24 -05003488void Context::syncStateForReadPixels()
3489{
3490 syncRendererState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
3491}
3492
3493void Context::syncStateForTexImage()
3494{
3495 syncRendererState(mTexImageDirtyBits, mTexImageDirtyObjects);
3496}
3497
3498void Context::syncStateForClear()
3499{
3500 syncRendererState(mClearDirtyBits, mClearDirtyObjects);
3501}
3502
3503void Context::syncStateForBlit()
3504{
3505 syncRendererState(mBlitDirtyBits, mBlitDirtyObjects);
3506}
3507
Jamie Madillc20ab272016-06-09 07:20:46 -07003508void Context::activeTexture(GLenum texture)
3509{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003510 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003511}
3512
Jamie Madill876429b2017-04-20 15:46:24 -04003513void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003514{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003515 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07003516}
3517
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003518void Context::blendEquation(GLenum mode)
3519{
3520 mGLState.setBlendEquation(mode, mode);
3521}
3522
Jamie Madillc20ab272016-06-09 07:20:46 -07003523void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
3524{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003525 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003526}
3527
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003528void Context::blendFunc(GLenum sfactor, GLenum dfactor)
3529{
3530 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
3531}
3532
Jamie Madillc20ab272016-06-09 07:20:46 -07003533void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
3534{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003535 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003536}
3537
Jamie Madill876429b2017-04-20 15:46:24 -04003538void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003539{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003540 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003541}
3542
Jamie Madill876429b2017-04-20 15:46:24 -04003543void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07003544{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003545 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07003546}
3547
3548void Context::clearStencil(GLint s)
3549{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003550 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07003551}
3552
3553void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
3554{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003555 mGLState.setColorMask(red == GL_TRUE, green == GL_TRUE, blue == GL_TRUE, alpha == GL_TRUE);
Jamie Madillc20ab272016-06-09 07:20:46 -07003556}
3557
3558void Context::cullFace(GLenum mode)
3559{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003560 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003561}
3562
3563void Context::depthFunc(GLenum func)
3564{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003565 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07003566}
3567
3568void Context::depthMask(GLboolean flag)
3569{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003570 mGLState.setDepthMask(flag != GL_FALSE);
Jamie Madillc20ab272016-06-09 07:20:46 -07003571}
3572
Jamie Madill876429b2017-04-20 15:46:24 -04003573void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07003574{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003575 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07003576}
3577
3578void Context::disable(GLenum cap)
3579{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003580 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003581}
3582
3583void Context::disableVertexAttribArray(GLuint index)
3584{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003585 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003586}
3587
3588void Context::enable(GLenum cap)
3589{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003590 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003591}
3592
3593void Context::enableVertexAttribArray(GLuint index)
3594{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003595 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003596}
3597
3598void Context::frontFace(GLenum mode)
3599{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003600 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003601}
3602
3603void Context::hint(GLenum target, GLenum mode)
3604{
3605 switch (target)
3606 {
3607 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003608 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003609 break;
3610
3611 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003612 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003613 break;
3614
3615 default:
3616 UNREACHABLE();
3617 return;
3618 }
3619}
3620
3621void Context::lineWidth(GLfloat width)
3622{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003623 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07003624}
3625
3626void Context::pixelStorei(GLenum pname, GLint param)
3627{
3628 switch (pname)
3629 {
3630 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003631 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003632 break;
3633
3634 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003635 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003636 break;
3637
3638 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003639 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003640 break;
3641
3642 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003643 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003644 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003645 break;
3646
3647 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03003648 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003649 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003650 break;
3651
3652 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03003653 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003654 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003655 break;
3656
3657 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003658 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003659 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003660 break;
3661
3662 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003663 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003664 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003665 break;
3666
3667 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003668 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003669 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003670 break;
3671
3672 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003673 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003674 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003675 break;
3676
3677 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003678 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003679 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003680 break;
3681
3682 default:
3683 UNREACHABLE();
3684 return;
3685 }
3686}
3687
3688void Context::polygonOffset(GLfloat factor, GLfloat units)
3689{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003690 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07003691}
3692
Jamie Madill876429b2017-04-20 15:46:24 -04003693void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07003694{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003695 mGLState.setSampleCoverageParams(clamp01(value), invert == GL_TRUE);
Jamie Madillc20ab272016-06-09 07:20:46 -07003696}
3697
3698void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
3699{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003700 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07003701}
3702
3703void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
3704{
3705 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3706 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003707 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003708 }
3709
3710 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3711 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003712 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003713 }
3714}
3715
3716void Context::stencilMaskSeparate(GLenum face, GLuint mask)
3717{
3718 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3719 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003720 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003721 }
3722
3723 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3724 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003725 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003726 }
3727}
3728
3729void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
3730{
3731 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3732 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003733 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003734 }
3735
3736 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3737 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003738 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003739 }
3740}
3741
3742void Context::vertexAttrib1f(GLuint index, GLfloat x)
3743{
3744 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003745 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003746}
3747
3748void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
3749{
3750 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003751 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003752}
3753
3754void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
3755{
3756 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003757 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003758}
3759
3760void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
3761{
3762 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003763 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003764}
3765
3766void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
3767{
3768 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003769 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003770}
3771
3772void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
3773{
3774 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003775 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003776}
3777
3778void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
3779{
3780 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003781 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003782}
3783
3784void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
3785{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003786 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07003787}
3788
3789void Context::vertexAttribPointer(GLuint index,
3790 GLint size,
3791 GLenum type,
3792 GLboolean normalized,
3793 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04003794 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07003795{
Shaodde78e82017-05-22 14:13:27 +08003796 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(GL_ARRAY_BUFFER), size,
3797 type, normalized == GL_TRUE, false, stride, ptr);
Jamie Madillc20ab272016-06-09 07:20:46 -07003798}
3799
Shao80957d92017-02-20 21:25:59 +08003800void Context::vertexAttribFormat(GLuint attribIndex,
3801 GLint size,
3802 GLenum type,
3803 GLboolean normalized,
3804 GLuint relativeOffset)
3805{
3806 mGLState.setVertexAttribFormat(attribIndex, size, type, normalized == GL_TRUE, false,
3807 relativeOffset);
3808}
3809
3810void Context::vertexAttribIFormat(GLuint attribIndex,
3811 GLint size,
3812 GLenum type,
3813 GLuint relativeOffset)
3814{
3815 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
3816}
3817
3818void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
3819{
Shaodde78e82017-05-22 14:13:27 +08003820 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Shao80957d92017-02-20 21:25:59 +08003821}
3822
3823void Context::setVertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
3824{
3825 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
3826}
3827
Jamie Madillc20ab272016-06-09 07:20:46 -07003828void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
3829{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003830 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07003831}
3832
3833void Context::vertexAttribIPointer(GLuint index,
3834 GLint size,
3835 GLenum type,
3836 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04003837 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07003838{
Shaodde78e82017-05-22 14:13:27 +08003839 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(GL_ARRAY_BUFFER), size,
3840 type, false, true, stride, pointer);
Jamie Madillc20ab272016-06-09 07:20:46 -07003841}
3842
3843void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
3844{
3845 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003846 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003847}
3848
3849void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
3850{
3851 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003852 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003853}
3854
3855void Context::vertexAttribI4iv(GLuint index, const GLint *v)
3856{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003857 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07003858}
3859
3860void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
3861{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003862 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07003863}
3864
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003865void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
3866{
3867 const VertexAttribCurrentValueData &currentValues =
3868 getGLState().getVertexAttribCurrentValue(index);
3869 const VertexArray *vao = getGLState().getVertexArray();
3870 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3871 currentValues, pname, params);
3872}
3873
3874void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
3875{
3876 const VertexAttribCurrentValueData &currentValues =
3877 getGLState().getVertexAttribCurrentValue(index);
3878 const VertexArray *vao = getGLState().getVertexArray();
3879 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3880 currentValues, pname, params);
3881}
3882
3883void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
3884{
3885 const VertexAttribCurrentValueData &currentValues =
3886 getGLState().getVertexAttribCurrentValue(index);
3887 const VertexArray *vao = getGLState().getVertexArray();
3888 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3889 currentValues, pname, params);
3890}
3891
3892void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
3893{
3894 const VertexAttribCurrentValueData &currentValues =
3895 getGLState().getVertexAttribCurrentValue(index);
3896 const VertexArray *vao = getGLState().getVertexArray();
3897 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3898 currentValues, pname, params);
3899}
3900
Jamie Madill876429b2017-04-20 15:46:24 -04003901void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003902{
3903 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
3904 QueryVertexAttribPointerv(attrib, pname, pointer);
3905}
3906
Jamie Madillc20ab272016-06-09 07:20:46 -07003907void Context::debugMessageControl(GLenum source,
3908 GLenum type,
3909 GLenum severity,
3910 GLsizei count,
3911 const GLuint *ids,
3912 GLboolean enabled)
3913{
3914 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003915 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
3916 (enabled != GL_FALSE));
Jamie Madillc20ab272016-06-09 07:20:46 -07003917}
3918
3919void Context::debugMessageInsert(GLenum source,
3920 GLenum type,
3921 GLuint id,
3922 GLenum severity,
3923 GLsizei length,
3924 const GLchar *buf)
3925{
3926 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003927 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07003928}
3929
3930void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
3931{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003932 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07003933}
3934
3935GLuint Context::getDebugMessageLog(GLuint count,
3936 GLsizei bufSize,
3937 GLenum *sources,
3938 GLenum *types,
3939 GLuint *ids,
3940 GLenum *severities,
3941 GLsizei *lengths,
3942 GLchar *messageLog)
3943{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003944 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
3945 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07003946}
3947
3948void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
3949{
3950 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003951 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07003952}
3953
3954void Context::popDebugGroup()
3955{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003956 mGLState.getDebug().popGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07003957}
3958
Jamie Madill876429b2017-04-20 15:46:24 -04003959void Context::bufferData(GLenum target, GLsizeiptr size, const void *data, GLenum usage)
Jamie Madill29639852016-09-02 15:00:09 -04003960{
3961 Buffer *buffer = mGLState.getTargetBuffer(target);
3962 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08003963 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04003964}
3965
Jamie Madill876429b2017-04-20 15:46:24 -04003966void Context::bufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04003967{
3968 if (data == nullptr)
3969 {
3970 return;
3971 }
3972
3973 Buffer *buffer = mGLState.getTargetBuffer(target);
3974 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08003975 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04003976}
3977
Jamie Madillef300b12016-10-07 15:12:09 -04003978void Context::attachShader(GLuint program, GLuint shader)
3979{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05003980 auto programObject = mState.mShaderPrograms->getProgram(program);
3981 auto shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04003982 ASSERT(programObject && shaderObject);
3983 programObject->attachShader(shaderObject);
3984}
3985
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003986const Workarounds &Context::getWorkarounds() const
3987{
3988 return mWorkarounds;
3989}
3990
Jamie Madillb0817d12016-11-01 15:48:31 -04003991void Context::copyBufferSubData(GLenum readTarget,
3992 GLenum writeTarget,
3993 GLintptr readOffset,
3994 GLintptr writeOffset,
3995 GLsizeiptr size)
3996{
3997 // if size is zero, the copy is a successful no-op
3998 if (size == 0)
3999 {
4000 return;
4001 }
4002
4003 // TODO(jmadill): cache these.
4004 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4005 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4006
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004007 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004008}
4009
Jamie Madill01a80ee2016-11-07 12:06:18 -05004010void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4011{
4012 Program *programObject = getProgram(program);
4013 // TODO(jmadill): Re-use this from the validation if possible.
4014 ASSERT(programObject);
4015 programObject->bindAttributeLocation(index, name);
4016}
4017
4018void Context::bindBuffer(GLenum target, GLuint buffer)
4019{
4020 switch (target)
4021 {
4022 case GL_ARRAY_BUFFER:
4023 bindArrayBuffer(buffer);
4024 break;
4025 case GL_ELEMENT_ARRAY_BUFFER:
4026 bindElementArrayBuffer(buffer);
4027 break;
4028 case GL_COPY_READ_BUFFER:
4029 bindCopyReadBuffer(buffer);
4030 break;
4031 case GL_COPY_WRITE_BUFFER:
4032 bindCopyWriteBuffer(buffer);
4033 break;
4034 case GL_PIXEL_PACK_BUFFER:
4035 bindPixelPackBuffer(buffer);
4036 break;
4037 case GL_PIXEL_UNPACK_BUFFER:
4038 bindPixelUnpackBuffer(buffer);
4039 break;
4040 case GL_UNIFORM_BUFFER:
4041 bindGenericUniformBuffer(buffer);
4042 break;
4043 case GL_TRANSFORM_FEEDBACK_BUFFER:
4044 bindGenericTransformFeedbackBuffer(buffer);
4045 break;
Geoff Lang3b573612016-10-31 14:08:10 -04004046 case GL_ATOMIC_COUNTER_BUFFER:
Jiajia Qin6eafb042016-12-27 17:04:07 +08004047 bindGenericAtomicCounterBuffer(buffer);
Geoff Lang3b573612016-10-31 14:08:10 -04004048 break;
4049 case GL_SHADER_STORAGE_BUFFER:
Jiajia Qinf546e7d2017-03-27 14:12:59 +08004050 bindGenericShaderStorageBuffer(buffer);
Geoff Lang3b573612016-10-31 14:08:10 -04004051 break;
4052 case GL_DRAW_INDIRECT_BUFFER:
Jiajia Qin9d7d0b12016-11-29 16:30:31 +08004053 bindDrawIndirectBuffer(buffer);
Geoff Lang3b573612016-10-31 14:08:10 -04004054 break;
4055 case GL_DISPATCH_INDIRECT_BUFFER:
Geoff Lang9f090372016-12-02 10:20:43 -05004056 if (buffer != 0)
4057 {
4058 // Binding buffers to this binding point is not implemented yet.
4059 UNIMPLEMENTED();
4060 }
Geoff Lang3b573612016-10-31 14:08:10 -04004061 break;
Jamie Madill01a80ee2016-11-07 12:06:18 -05004062
4063 default:
4064 UNREACHABLE();
4065 break;
4066 }
4067}
4068
Jiajia Qin6eafb042016-12-27 17:04:07 +08004069void Context::bindBufferBase(GLenum target, GLuint index, GLuint buffer)
4070{
4071 bindBufferRange(target, index, buffer, 0, 0);
4072}
4073
4074void Context::bindBufferRange(GLenum target,
4075 GLuint index,
4076 GLuint buffer,
4077 GLintptr offset,
4078 GLsizeiptr size)
4079{
4080 switch (target)
4081 {
4082 case GL_TRANSFORM_FEEDBACK_BUFFER:
4083 bindIndexedTransformFeedbackBuffer(buffer, index, offset, size);
4084 bindGenericTransformFeedbackBuffer(buffer);
4085 break;
4086 case GL_UNIFORM_BUFFER:
4087 bindIndexedUniformBuffer(buffer, index, offset, size);
4088 bindGenericUniformBuffer(buffer);
4089 break;
4090 case GL_ATOMIC_COUNTER_BUFFER:
4091 bindIndexedAtomicCounterBuffer(buffer, index, offset, size);
4092 bindGenericAtomicCounterBuffer(buffer);
4093 break;
4094 case GL_SHADER_STORAGE_BUFFER:
Jiajia Qinf546e7d2017-03-27 14:12:59 +08004095 bindIndexedShaderStorageBuffer(buffer, index, offset, size);
4096 bindGenericShaderStorageBuffer(buffer);
Jiajia Qin6eafb042016-12-27 17:04:07 +08004097 break;
4098 default:
4099 UNREACHABLE();
4100 break;
4101 }
4102}
4103
Jamie Madill01a80ee2016-11-07 12:06:18 -05004104void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
4105{
4106 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4107 {
4108 bindReadFramebuffer(framebuffer);
4109 }
4110
4111 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4112 {
4113 bindDrawFramebuffer(framebuffer);
4114 }
4115}
4116
4117void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4118{
4119 ASSERT(target == GL_RENDERBUFFER);
4120 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004121 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04004122 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004123}
4124
JiangYizhoubddc46b2016-12-09 09:50:51 +08004125void Context::texStorage2DMultisample(GLenum target,
4126 GLsizei samples,
4127 GLenum internalformat,
4128 GLsizei width,
4129 GLsizei height,
4130 GLboolean fixedsamplelocations)
4131{
4132 Extents size(width, height, 1);
4133 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05004134 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
JiangYizhoubddc46b2016-12-09 09:50:51 +08004135 fixedsamplelocations));
4136}
4137
4138void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4139{
Jamie Madilldd43e6c2017-03-24 14:18:49 -04004140 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
JiangYizhoubddc46b2016-12-09 09:50:51 +08004141 const Framebuffer *framebuffer = mGLState.getReadFramebuffer();
4142
4143 switch (pname)
4144 {
4145 case GL_SAMPLE_POSITION:
4146 handleError(framebuffer->getSamplePosition(index, val));
4147 break;
4148 default:
4149 UNREACHABLE();
4150 }
4151}
4152
Jamie Madille8fb6402017-02-14 17:56:40 -05004153void Context::renderbufferStorage(GLenum target,
4154 GLenum internalformat,
4155 GLsizei width,
4156 GLsizei height)
4157{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004158 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4159 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
4160
Jamie Madille8fb6402017-02-14 17:56:40 -05004161 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04004162 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004163}
4164
4165void Context::renderbufferStorageMultisample(GLenum target,
4166 GLsizei samples,
4167 GLenum internalformat,
4168 GLsizei width,
4169 GLsizei height)
4170{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004171 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4172 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05004173
4174 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004175 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04004176 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004177}
4178
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004179void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
4180{
4181 const FenceSync *syncObject = getFenceSync(sync);
Geoff Lang82483b92017-04-11 15:33:00 -04004182 handleError(QuerySynciv(syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004183}
4184
JiangYizhoue18e6392017-02-20 10:32:23 +08004185void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
4186{
4187 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4188 QueryFramebufferParameteriv(framebuffer, pname, params);
4189}
4190
4191void Context::setFramebufferParameteri(GLenum target, GLenum pname, GLint param)
4192{
4193 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4194 SetFramebufferParameteri(framebuffer, pname, param);
4195}
4196
Jamie Madillb3f26b92017-07-19 15:07:41 -04004197Error Context::getScratchBuffer(size_t requstedSizeBytes,
4198 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05004199{
Jamie Madillb3f26b92017-07-19 15:07:41 -04004200 if (!mScratchBuffer.get(requstedSizeBytes, scratchBufferOut))
4201 {
4202 return OutOfMemory() << "Failed to allocate internal buffer.";
4203 }
4204 return NoError();
4205}
4206
4207Error Context::getZeroFilledBuffer(size_t requstedSizeBytes,
4208 angle::MemoryBuffer **zeroBufferOut) const
4209{
4210 if (!mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0))
Jamie Madille14951e2017-03-09 18:55:16 -05004211 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004212 return OutOfMemory() << "Failed to allocate internal buffer.";
Jamie Madille14951e2017-03-09 18:55:16 -05004213 }
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004214 return NoError();
Jamie Madille14951e2017-03-09 18:55:16 -05004215}
4216
Xinghua Cao2b396592017-03-29 15:36:04 +08004217void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
4218{
4219 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
4220 {
4221 return;
4222 }
4223
Jamie Madillfe548342017-06-19 11:13:24 -04004224 mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ);
Xinghua Cao2b396592017-03-29 15:36:04 +08004225}
4226
JiangYizhou165361c2017-06-07 14:56:57 +08004227void Context::texStorage2D(GLenum target,
4228 GLsizei levels,
4229 GLenum internalFormat,
4230 GLsizei width,
4231 GLsizei height)
4232{
4233 Extents size(width, height, 1);
4234 Texture *texture = getTargetTexture(target);
4235 handleError(texture->setStorage(this, target, levels, internalFormat, size));
4236}
4237
4238void Context::texStorage3D(GLenum target,
4239 GLsizei levels,
4240 GLenum internalFormat,
4241 GLsizei width,
4242 GLsizei height,
4243 GLsizei depth)
4244{
4245 Extents size(width, height, depth);
4246 Texture *texture = getTargetTexture(target);
4247 handleError(texture->setStorage(this, target, levels, internalFormat, size));
4248}
4249
Jamie Madillc1d770e2017-04-13 17:31:24 -04004250GLenum Context::checkFramebufferStatus(GLenum target)
4251{
4252 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4253 ASSERT(framebuffer);
4254
4255 return framebuffer->checkStatus(this);
4256}
4257
4258void Context::compileShader(GLuint shader)
4259{
4260 Shader *shaderObject = GetValidShader(this, shader);
4261 if (!shaderObject)
4262 {
4263 return;
4264 }
4265 shaderObject->compile(this);
4266}
4267
4268void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
4269{
4270 for (int i = 0; i < n; i++)
4271 {
4272 deleteBuffer(buffers[i]);
4273 }
4274}
4275
4276void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
4277{
4278 for (int i = 0; i < n; i++)
4279 {
4280 if (framebuffers[i] != 0)
4281 {
4282 deleteFramebuffer(framebuffers[i]);
4283 }
4284 }
4285}
4286
4287void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
4288{
4289 for (int i = 0; i < n; i++)
4290 {
4291 deleteRenderbuffer(renderbuffers[i]);
4292 }
4293}
4294
4295void Context::deleteTextures(GLsizei n, const GLuint *textures)
4296{
4297 for (int i = 0; i < n; i++)
4298 {
4299 if (textures[i] != 0)
4300 {
4301 deleteTexture(textures[i]);
4302 }
4303 }
4304}
4305
4306void Context::detachShader(GLuint program, GLuint shader)
4307{
4308 Program *programObject = getProgram(program);
4309 ASSERT(programObject);
4310
4311 Shader *shaderObject = getShader(shader);
4312 ASSERT(shaderObject);
4313
4314 programObject->detachShader(this, shaderObject);
4315}
4316
4317void Context::genBuffers(GLsizei n, GLuint *buffers)
4318{
4319 for (int i = 0; i < n; i++)
4320 {
4321 buffers[i] = createBuffer();
4322 }
4323}
4324
4325void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
4326{
4327 for (int i = 0; i < n; i++)
4328 {
4329 framebuffers[i] = createFramebuffer();
4330 }
4331}
4332
4333void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
4334{
4335 for (int i = 0; i < n; i++)
4336 {
4337 renderbuffers[i] = createRenderbuffer();
4338 }
4339}
4340
4341void Context::genTextures(GLsizei n, GLuint *textures)
4342{
4343 for (int i = 0; i < n; i++)
4344 {
4345 textures[i] = createTexture();
4346 }
4347}
4348
4349void Context::getActiveAttrib(GLuint program,
4350 GLuint index,
4351 GLsizei bufsize,
4352 GLsizei *length,
4353 GLint *size,
4354 GLenum *type,
4355 GLchar *name)
4356{
4357 Program *programObject = getProgram(program);
4358 ASSERT(programObject);
4359 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
4360}
4361
4362void Context::getActiveUniform(GLuint program,
4363 GLuint index,
4364 GLsizei bufsize,
4365 GLsizei *length,
4366 GLint *size,
4367 GLenum *type,
4368 GLchar *name)
4369{
4370 Program *programObject = getProgram(program);
4371 ASSERT(programObject);
4372 programObject->getActiveUniform(index, bufsize, length, size, type, name);
4373}
4374
4375void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
4376{
4377 Program *programObject = getProgram(program);
4378 ASSERT(programObject);
4379 programObject->getAttachedShaders(maxcount, count, shaders);
4380}
4381
4382GLint Context::getAttribLocation(GLuint program, const GLchar *name)
4383{
4384 Program *programObject = getProgram(program);
4385 ASSERT(programObject);
4386 return programObject->getAttributeLocation(name);
4387}
4388
4389void Context::getBooleanv(GLenum pname, GLboolean *params)
4390{
4391 GLenum nativeType;
4392 unsigned int numParams = 0;
4393 getQueryParameterInfo(pname, &nativeType, &numParams);
4394
4395 if (nativeType == GL_BOOL)
4396 {
4397 getBooleanvImpl(pname, params);
4398 }
4399 else
4400 {
4401 CastStateValues(this, nativeType, pname, numParams, params);
4402 }
4403}
4404
4405void Context::getFloatv(GLenum pname, GLfloat *params)
4406{
4407 GLenum nativeType;
4408 unsigned int numParams = 0;
4409 getQueryParameterInfo(pname, &nativeType, &numParams);
4410
4411 if (nativeType == GL_FLOAT)
4412 {
4413 getFloatvImpl(pname, params);
4414 }
4415 else
4416 {
4417 CastStateValues(this, nativeType, pname, numParams, params);
4418 }
4419}
4420
4421void Context::getIntegerv(GLenum pname, GLint *params)
4422{
4423 GLenum nativeType;
4424 unsigned int numParams = 0;
4425 getQueryParameterInfo(pname, &nativeType, &numParams);
4426
4427 if (nativeType == GL_INT)
4428 {
4429 getIntegervImpl(pname, params);
4430 }
4431 else
4432 {
4433 CastStateValues(this, nativeType, pname, numParams, params);
4434 }
4435}
4436
4437void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
4438{
4439 Program *programObject = getProgram(program);
4440 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04004441 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004442}
4443
Jamie Madillbe849e42017-05-02 15:49:00 -04004444void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04004445{
4446 Program *programObject = getProgram(program);
4447 ASSERT(programObject);
4448 programObject->getInfoLog(bufsize, length, infolog);
4449}
4450
4451void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
4452{
4453 Shader *shaderObject = getShader(shader);
4454 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004455 QueryShaderiv(this, shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004456}
4457
4458void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
4459{
4460 Shader *shaderObject = getShader(shader);
4461 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004462 shaderObject->getInfoLog(this, bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004463}
4464
4465void Context::getShaderPrecisionFormat(GLenum shadertype,
4466 GLenum precisiontype,
4467 GLint *range,
4468 GLint *precision)
4469{
4470 // TODO(jmadill): Compute shaders.
4471
4472 switch (shadertype)
4473 {
4474 case GL_VERTEX_SHADER:
4475 switch (precisiontype)
4476 {
4477 case GL_LOW_FLOAT:
4478 mCaps.vertexLowpFloat.get(range, precision);
4479 break;
4480 case GL_MEDIUM_FLOAT:
4481 mCaps.vertexMediumpFloat.get(range, precision);
4482 break;
4483 case GL_HIGH_FLOAT:
4484 mCaps.vertexHighpFloat.get(range, precision);
4485 break;
4486
4487 case GL_LOW_INT:
4488 mCaps.vertexLowpInt.get(range, precision);
4489 break;
4490 case GL_MEDIUM_INT:
4491 mCaps.vertexMediumpInt.get(range, precision);
4492 break;
4493 case GL_HIGH_INT:
4494 mCaps.vertexHighpInt.get(range, precision);
4495 break;
4496
4497 default:
4498 UNREACHABLE();
4499 return;
4500 }
4501 break;
4502
4503 case GL_FRAGMENT_SHADER:
4504 switch (precisiontype)
4505 {
4506 case GL_LOW_FLOAT:
4507 mCaps.fragmentLowpFloat.get(range, precision);
4508 break;
4509 case GL_MEDIUM_FLOAT:
4510 mCaps.fragmentMediumpFloat.get(range, precision);
4511 break;
4512 case GL_HIGH_FLOAT:
4513 mCaps.fragmentHighpFloat.get(range, precision);
4514 break;
4515
4516 case GL_LOW_INT:
4517 mCaps.fragmentLowpInt.get(range, precision);
4518 break;
4519 case GL_MEDIUM_INT:
4520 mCaps.fragmentMediumpInt.get(range, precision);
4521 break;
4522 case GL_HIGH_INT:
4523 mCaps.fragmentHighpInt.get(range, precision);
4524 break;
4525
4526 default:
4527 UNREACHABLE();
4528 return;
4529 }
4530 break;
4531
4532 default:
4533 UNREACHABLE();
4534 return;
4535 }
4536}
4537
4538void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
4539{
4540 Shader *shaderObject = getShader(shader);
4541 ASSERT(shaderObject);
4542 shaderObject->getSource(bufsize, length, source);
4543}
4544
4545void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
4546{
4547 Program *programObject = getProgram(program);
4548 ASSERT(programObject);
4549 programObject->getUniformfv(location, params);
4550}
4551
4552void Context::getUniformiv(GLuint program, GLint location, GLint *params)
4553{
4554 Program *programObject = getProgram(program);
4555 ASSERT(programObject);
4556 programObject->getUniformiv(location, params);
4557}
4558
4559GLint Context::getUniformLocation(GLuint program, const GLchar *name)
4560{
4561 Program *programObject = getProgram(program);
4562 ASSERT(programObject);
4563 return programObject->getUniformLocation(name);
4564}
4565
4566GLboolean Context::isBuffer(GLuint buffer)
4567{
4568 if (buffer == 0)
4569 {
4570 return GL_FALSE;
4571 }
4572
4573 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
4574}
4575
4576GLboolean Context::isEnabled(GLenum cap)
4577{
4578 return mGLState.getEnableFeature(cap);
4579}
4580
4581GLboolean Context::isFramebuffer(GLuint framebuffer)
4582{
4583 if (framebuffer == 0)
4584 {
4585 return GL_FALSE;
4586 }
4587
4588 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
4589}
4590
4591GLboolean Context::isProgram(GLuint program)
4592{
4593 if (program == 0)
4594 {
4595 return GL_FALSE;
4596 }
4597
4598 return (getProgram(program) ? GL_TRUE : GL_FALSE);
4599}
4600
4601GLboolean Context::isRenderbuffer(GLuint renderbuffer)
4602{
4603 if (renderbuffer == 0)
4604 {
4605 return GL_FALSE;
4606 }
4607
4608 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
4609}
4610
4611GLboolean Context::isShader(GLuint shader)
4612{
4613 if (shader == 0)
4614 {
4615 return GL_FALSE;
4616 }
4617
4618 return (getShader(shader) ? GL_TRUE : GL_FALSE);
4619}
4620
4621GLboolean Context::isTexture(GLuint texture)
4622{
4623 if (texture == 0)
4624 {
4625 return GL_FALSE;
4626 }
4627
4628 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
4629}
4630
4631void Context::linkProgram(GLuint program)
4632{
4633 Program *programObject = getProgram(program);
4634 ASSERT(programObject);
4635 handleError(programObject->link(this));
4636}
4637
4638void Context::releaseShaderCompiler()
4639{
Jamie Madill4928b7c2017-06-20 12:57:39 -04004640 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004641}
4642
4643void Context::shaderBinary(GLsizei n,
4644 const GLuint *shaders,
4645 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04004646 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04004647 GLsizei length)
4648{
4649 // No binary shader formats are supported.
4650 UNIMPLEMENTED();
4651}
4652
4653void Context::shaderSource(GLuint shader,
4654 GLsizei count,
4655 const GLchar *const *string,
4656 const GLint *length)
4657{
4658 Shader *shaderObject = getShader(shader);
4659 ASSERT(shaderObject);
4660 shaderObject->setSource(count, string, length);
4661}
4662
4663void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
4664{
4665 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
4666}
4667
4668void Context::stencilMask(GLuint mask)
4669{
4670 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
4671}
4672
4673void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
4674{
4675 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
4676}
4677
4678void Context::uniform1f(GLint location, GLfloat x)
4679{
4680 Program *program = mGLState.getProgram();
4681 program->setUniform1fv(location, 1, &x);
4682}
4683
4684void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
4685{
4686 Program *program = mGLState.getProgram();
4687 program->setUniform1fv(location, count, v);
4688}
4689
4690void Context::uniform1i(GLint location, GLint x)
4691{
4692 Program *program = mGLState.getProgram();
4693 program->setUniform1iv(location, 1, &x);
4694}
4695
4696void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
4697{
4698 Program *program = mGLState.getProgram();
4699 program->setUniform1iv(location, count, v);
4700}
4701
4702void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
4703{
4704 GLfloat xy[2] = {x, y};
4705 Program *program = mGLState.getProgram();
4706 program->setUniform2fv(location, 1, xy);
4707}
4708
4709void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
4710{
4711 Program *program = mGLState.getProgram();
4712 program->setUniform2fv(location, count, v);
4713}
4714
4715void Context::uniform2i(GLint location, GLint x, GLint y)
4716{
4717 GLint xy[2] = {x, y};
4718 Program *program = mGLState.getProgram();
4719 program->setUniform2iv(location, 1, xy);
4720}
4721
4722void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
4723{
4724 Program *program = mGLState.getProgram();
4725 program->setUniform2iv(location, count, v);
4726}
4727
4728void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
4729{
4730 GLfloat xyz[3] = {x, y, z};
4731 Program *program = mGLState.getProgram();
4732 program->setUniform3fv(location, 1, xyz);
4733}
4734
4735void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
4736{
4737 Program *program = mGLState.getProgram();
4738 program->setUniform3fv(location, count, v);
4739}
4740
4741void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
4742{
4743 GLint xyz[3] = {x, y, z};
4744 Program *program = mGLState.getProgram();
4745 program->setUniform3iv(location, 1, xyz);
4746}
4747
4748void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
4749{
4750 Program *program = mGLState.getProgram();
4751 program->setUniform3iv(location, count, v);
4752}
4753
4754void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4755{
4756 GLfloat xyzw[4] = {x, y, z, w};
4757 Program *program = mGLState.getProgram();
4758 program->setUniform4fv(location, 1, xyzw);
4759}
4760
4761void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
4762{
4763 Program *program = mGLState.getProgram();
4764 program->setUniform4fv(location, count, v);
4765}
4766
4767void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
4768{
4769 GLint xyzw[4] = {x, y, z, w};
4770 Program *program = mGLState.getProgram();
4771 program->setUniform4iv(location, 1, xyzw);
4772}
4773
4774void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
4775{
4776 Program *program = mGLState.getProgram();
4777 program->setUniform4iv(location, count, v);
4778}
4779
4780void Context::uniformMatrix2fv(GLint location,
4781 GLsizei count,
4782 GLboolean transpose,
4783 const GLfloat *value)
4784{
4785 Program *program = mGLState.getProgram();
4786 program->setUniformMatrix2fv(location, count, transpose, value);
4787}
4788
4789void Context::uniformMatrix3fv(GLint location,
4790 GLsizei count,
4791 GLboolean transpose,
4792 const GLfloat *value)
4793{
4794 Program *program = mGLState.getProgram();
4795 program->setUniformMatrix3fv(location, count, transpose, value);
4796}
4797
4798void Context::uniformMatrix4fv(GLint location,
4799 GLsizei count,
4800 GLboolean transpose,
4801 const GLfloat *value)
4802{
4803 Program *program = mGLState.getProgram();
4804 program->setUniformMatrix4fv(location, count, transpose, value);
4805}
4806
4807void Context::validateProgram(GLuint program)
4808{
4809 Program *programObject = getProgram(program);
4810 ASSERT(programObject);
4811 programObject->validate(mCaps);
4812}
4813
Jamie Madilld04908b2017-06-09 14:15:35 -04004814void Context::getProgramBinary(GLuint program,
4815 GLsizei bufSize,
4816 GLsizei *length,
4817 GLenum *binaryFormat,
4818 void *binary)
4819{
4820 Program *programObject = getProgram(program);
4821 ASSERT(programObject != nullptr);
4822
4823 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
4824}
4825
4826void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
4827{
4828 Program *programObject = getProgram(program);
4829 ASSERT(programObject != nullptr);
4830
4831 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
4832}
4833
Jamie Madillc29968b2016-01-20 11:17:23 -05004834} // namespace gl