blob: fab655302c029787244be92a81f4868b03b95cee [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();
Qin Jiajia1da00652017-06-20 17:16:25 +08001858 handleError(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04001859}
1860
Jamie Madill675fe712016-12-19 13:07:54 -05001861void Context::drawElementsInstanced(GLenum mode,
1862 GLsizei count,
1863 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04001864 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04001865 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04001866{
1867 syncRendererState();
Qin Jiajia1da00652017-06-20 17:16:25 +08001868 handleError(
1869 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04001870}
1871
Jamie Madill675fe712016-12-19 13:07:54 -05001872void Context::drawRangeElements(GLenum mode,
1873 GLuint start,
1874 GLuint end,
1875 GLsizei count,
1876 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04001877 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04001878{
1879 syncRendererState();
Qin Jiajia1da00652017-06-20 17:16:25 +08001880 handleError(mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001881}
1882
Jamie Madill876429b2017-04-20 15:46:24 -04001883void Context::drawArraysIndirect(GLenum mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08001884{
1885 syncRendererState();
Jamie Madillc564c072017-06-01 12:45:42 -04001886 handleError(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08001887}
1888
Jamie Madill876429b2017-04-20 15:46:24 -04001889void Context::drawElementsIndirect(GLenum mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08001890{
1891 syncRendererState();
Jamie Madillc564c072017-06-01 12:45:42 -04001892 handleError(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08001893}
1894
Jamie Madill675fe712016-12-19 13:07:54 -05001895void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001896{
Jamie Madill675fe712016-12-19 13:07:54 -05001897 handleError(mImplementation->flush());
Geoff Lang129753a2015-01-09 16:52:09 -05001898}
1899
Jamie Madill675fe712016-12-19 13:07:54 -05001900void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05001901{
Jamie Madill675fe712016-12-19 13:07:54 -05001902 handleError(mImplementation->finish());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001903}
1904
Austin Kinross6ee1e782015-05-29 17:05:37 -07001905void Context::insertEventMarker(GLsizei length, const char *marker)
1906{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001907 ASSERT(mImplementation);
1908 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07001909}
1910
1911void Context::pushGroupMarker(GLsizei length, const char *marker)
1912{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001913 ASSERT(mImplementation);
1914 mImplementation->pushGroupMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07001915}
1916
1917void Context::popGroupMarker()
1918{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001919 ASSERT(mImplementation);
1920 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07001921}
1922
Geoff Langd8605522016-04-13 10:19:12 -04001923void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
1924{
1925 Program *programObject = getProgram(program);
1926 ASSERT(programObject);
1927
1928 programObject->bindUniformLocation(location, name);
1929}
1930
Sami Väisänena797e062016-05-12 15:23:40 +03001931void Context::setCoverageModulation(GLenum components)
1932{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001933 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03001934}
1935
Sami Väisänene45e53b2016-05-25 10:36:04 +03001936void Context::loadPathRenderingMatrix(GLenum matrixMode, const GLfloat *matrix)
1937{
1938 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
1939}
1940
1941void Context::loadPathRenderingIdentityMatrix(GLenum matrixMode)
1942{
1943 GLfloat I[16];
1944 angle::Matrix<GLfloat>::setToIdentity(I);
1945
1946 mGLState.loadPathRenderingMatrix(matrixMode, I);
1947}
1948
1949void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
1950{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001951 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001952 if (!pathObj)
1953 return;
1954
1955 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1956 syncRendererState();
1957
1958 mImplementation->stencilFillPath(pathObj, fillMode, mask);
1959}
1960
1961void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
1962{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001963 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001964 if (!pathObj)
1965 return;
1966
1967 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1968 syncRendererState();
1969
1970 mImplementation->stencilStrokePath(pathObj, reference, mask);
1971}
1972
1973void Context::coverFillPath(GLuint path, GLenum coverMode)
1974{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001975 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001976 if (!pathObj)
1977 return;
1978
1979 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1980 syncRendererState();
1981
1982 mImplementation->coverFillPath(pathObj, coverMode);
1983}
1984
1985void Context::coverStrokePath(GLuint path, GLenum coverMode)
1986{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001987 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001988 if (!pathObj)
1989 return;
1990
1991 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1992 syncRendererState();
1993
1994 mImplementation->coverStrokePath(pathObj, coverMode);
1995}
1996
1997void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
1998{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001999 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002000 if (!pathObj)
2001 return;
2002
2003 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2004 syncRendererState();
2005
2006 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
2007}
2008
2009void Context::stencilThenCoverStrokePath(GLuint path,
2010 GLint reference,
2011 GLuint mask,
2012 GLenum coverMode)
2013{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002014 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002015 if (!pathObj)
2016 return;
2017
2018 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2019 syncRendererState();
2020
2021 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2022}
2023
Sami Väisänend59ca052016-06-21 16:10:00 +03002024void Context::coverFillPathInstanced(GLsizei numPaths,
2025 GLenum pathNameType,
2026 const void *paths,
2027 GLuint pathBase,
2028 GLenum coverMode,
2029 GLenum transformType,
2030 const GLfloat *transformValues)
2031{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002032 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002033
2034 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2035 syncRendererState();
2036
2037 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2038}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002039
Sami Väisänend59ca052016-06-21 16:10:00 +03002040void Context::coverStrokePathInstanced(GLsizei numPaths,
2041 GLenum pathNameType,
2042 const void *paths,
2043 GLuint pathBase,
2044 GLenum coverMode,
2045 GLenum transformType,
2046 const GLfloat *transformValues)
2047{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002048 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002049
2050 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2051 syncRendererState();
2052
2053 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2054 transformValues);
2055}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002056
Sami Väisänend59ca052016-06-21 16:10:00 +03002057void Context::stencilFillPathInstanced(GLsizei numPaths,
2058 GLenum pathNameType,
2059 const void *paths,
2060 GLuint pathBase,
2061 GLenum fillMode,
2062 GLuint mask,
2063 GLenum transformType,
2064 const GLfloat *transformValues)
2065{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002066 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002067
2068 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2069 syncRendererState();
2070
2071 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2072 transformValues);
2073}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002074
Sami Väisänend59ca052016-06-21 16:10:00 +03002075void Context::stencilStrokePathInstanced(GLsizei numPaths,
2076 GLenum pathNameType,
2077 const void *paths,
2078 GLuint pathBase,
2079 GLint reference,
2080 GLuint mask,
2081 GLenum transformType,
2082 const GLfloat *transformValues)
2083{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002084 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002085
2086 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2087 syncRendererState();
2088
2089 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2090 transformValues);
2091}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002092
Sami Väisänend59ca052016-06-21 16:10:00 +03002093void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2094 GLenum pathNameType,
2095 const void *paths,
2096 GLuint pathBase,
2097 GLenum fillMode,
2098 GLuint mask,
2099 GLenum coverMode,
2100 GLenum transformType,
2101 const GLfloat *transformValues)
2102{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002103 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002104
2105 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2106 syncRendererState();
2107
2108 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2109 transformType, transformValues);
2110}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002111
Sami Väisänend59ca052016-06-21 16:10:00 +03002112void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2113 GLenum pathNameType,
2114 const void *paths,
2115 GLuint pathBase,
2116 GLint reference,
2117 GLuint mask,
2118 GLenum coverMode,
2119 GLenum transformType,
2120 const GLfloat *transformValues)
2121{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002122 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002123
2124 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2125 syncRendererState();
2126
2127 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2128 transformType, transformValues);
2129}
2130
Sami Väisänen46eaa942016-06-29 10:26:37 +03002131void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2132{
2133 auto *programObject = getProgram(program);
2134
2135 programObject->bindFragmentInputLocation(location, name);
2136}
2137
2138void Context::programPathFragmentInputGen(GLuint program,
2139 GLint location,
2140 GLenum genMode,
2141 GLint components,
2142 const GLfloat *coeffs)
2143{
2144 auto *programObject = getProgram(program);
2145
Jamie Madillbd044ed2017-06-05 12:59:21 -04002146 programObject->pathFragmentInputGen(this, location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002147}
2148
jchen1015015f72017-03-16 13:54:21 +08002149GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2150{
jchen10fd7c3b52017-03-21 15:36:03 +08002151 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002152 return QueryProgramResourceIndex(programObject, programInterface, name);
2153}
2154
jchen10fd7c3b52017-03-21 15:36:03 +08002155void Context::getProgramResourceName(GLuint program,
2156 GLenum programInterface,
2157 GLuint index,
2158 GLsizei bufSize,
2159 GLsizei *length,
2160 GLchar *name)
2161{
2162 const auto *programObject = getProgram(program);
2163 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2164}
2165
jchen10191381f2017-04-11 13:59:04 +08002166GLint Context::getProgramResourceLocation(GLuint program,
2167 GLenum programInterface,
2168 const GLchar *name)
2169{
2170 const auto *programObject = getProgram(program);
2171 return QueryProgramResourceLocation(programObject, programInterface, name);
2172}
2173
Jamie Madill437fa652016-05-03 15:13:24 -04002174void Context::handleError(const Error &error)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002175{
Geoff Langda5777c2014-07-11 09:52:58 -04002176 if (error.isError())
2177 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002178 GLenum code = error.getCode();
2179 mErrors.insert(code);
2180 if (code == GL_OUT_OF_MEMORY && getWorkarounds().loseContextOnOutOfMemory)
2181 {
2182 markContextLost();
2183 }
Geoff Lang70d0f492015-12-10 17:45:46 -05002184
2185 if (!error.getMessage().empty())
2186 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002187 auto *debug = &mGLState.getDebug();
2188 debug->insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, error.getID(),
2189 GL_DEBUG_SEVERITY_HIGH, error.getMessage());
Geoff Lang70d0f492015-12-10 17:45:46 -05002190 }
Geoff Langda5777c2014-07-11 09:52:58 -04002191 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002192}
2193
2194// Get one of the recorded errors and clear its flag, if any.
2195// [OpenGL ES 2.0.24] section 2.5 page 13.
2196GLenum Context::getError()
2197{
Geoff Langda5777c2014-07-11 09:52:58 -04002198 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002199 {
Geoff Langda5777c2014-07-11 09:52:58 -04002200 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002201 }
Geoff Langda5777c2014-07-11 09:52:58 -04002202 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002203 {
Geoff Langda5777c2014-07-11 09:52:58 -04002204 GLenum error = *mErrors.begin();
2205 mErrors.erase(mErrors.begin());
2206 return error;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002207 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002208}
2209
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002210// NOTE: this function should not assume that this context is current!
2211void Context::markContextLost()
2212{
2213 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002214 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002215 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002216 mContextLostForced = true;
2217 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002218 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002219}
2220
2221bool Context::isContextLost()
2222{
2223 return mContextLost;
2224}
2225
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002226GLenum Context::getResetStatus()
2227{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002228 // Even if the application doesn't want to know about resets, we want to know
2229 // as it will allow us to skip all the calls.
2230 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002231 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002232 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002233 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002234 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002235 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002236
2237 // EXT_robustness, section 2.6: If the reset notification behavior is
2238 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2239 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2240 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002241 }
2242
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002243 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2244 // status should be returned at least once, and GL_NO_ERROR should be returned
2245 // once the device has finished resetting.
2246 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002247 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002248 ASSERT(mResetStatus == GL_NO_ERROR);
2249 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002250
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002251 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002252 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002253 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002254 }
2255 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002256 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002257 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002258 // If markContextLost was used to mark the context lost then
2259 // assume that is not recoverable, and continue to report the
2260 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002261 mResetStatus = mImplementation->getResetStatus();
2262 }
Jamie Madill893ab082014-05-16 16:56:10 -04002263
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002264 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002265}
2266
2267bool Context::isResetNotificationEnabled()
2268{
2269 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2270}
2271
Corentin Walleze3b10e82015-05-20 11:06:25 -04002272const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002273{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002274 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002275}
2276
2277EGLenum Context::getClientType() const
2278{
2279 return mClientType;
2280}
2281
2282EGLenum Context::getRenderBuffer() const
2283{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002284 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2285 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002286 {
2287 return EGL_NONE;
2288 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002289
2290 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(GL_BACK);
2291 ASSERT(backAttachment != nullptr);
2292 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002293}
2294
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002295VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002296{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002297 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002298 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2299 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002300 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002301 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2302 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002303
Jamie Madill96a483b2017-06-27 16:49:21 -04002304 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002305 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002306
2307 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002308}
2309
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002310TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002311{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002312 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002313 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2314 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002315 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002316 transformFeedback =
2317 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002318 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002319 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002320 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002321
2322 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002323}
2324
2325bool Context::isVertexArrayGenerated(GLuint vertexArray)
2326{
Jamie Madill96a483b2017-06-27 16:49:21 -04002327 ASSERT(mVertexArrayMap.contains(0));
2328 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002329}
2330
2331bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2332{
Jamie Madill96a483b2017-06-27 16:49:21 -04002333 ASSERT(mTransformFeedbackMap.contains(0));
2334 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002335}
2336
Shannon Woods53a94a82014-06-24 15:20:36 -04002337void Context::detachTexture(GLuint texture)
2338{
2339 // Simple pass-through to State's detachTexture method, as textures do not require
2340 // allocation map management either here or in the resource manager at detach time.
2341 // Zero textures are held by the Context, and we don't attempt to request them from
2342 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002343 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002344}
2345
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002346void Context::detachBuffer(GLuint buffer)
2347{
Yuly Novikov5807a532015-12-03 13:01:22 -05002348 // Simple pass-through to State's detachBuffer method, since
2349 // only buffer attachments to container objects that are bound to the current context
2350 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002351
Yuly Novikov5807a532015-12-03 13:01:22 -05002352 // [OpenGL ES 3.2] section 5.1.2 page 45:
2353 // Attachments to unbound container objects, such as
2354 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2355 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002356 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002357}
2358
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002359void Context::detachFramebuffer(GLuint framebuffer)
2360{
Shannon Woods53a94a82014-06-24 15:20:36 -04002361 // Framebuffer detachment is handled by Context, because 0 is a valid
2362 // Framebuffer object, and a pointer to it must be passed from Context
2363 // to State at binding time.
2364
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002365 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002366 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2367 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2368 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002369
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002370 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002371 {
2372 bindReadFramebuffer(0);
2373 }
2374
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002375 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002376 {
2377 bindDrawFramebuffer(0);
2378 }
2379}
2380
2381void Context::detachRenderbuffer(GLuint renderbuffer)
2382{
Jamie Madilla02315b2017-02-23 14:14:47 -05002383 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002384}
2385
Jamie Madill57a89722013-07-02 11:57:03 -04002386void Context::detachVertexArray(GLuint vertexArray)
2387{
Jamie Madill77a72f62015-04-14 11:18:32 -04002388 // Vertex array detachment is handled by Context, because 0 is a valid
2389 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002390 // binding time.
2391
Jamie Madill57a89722013-07-02 11:57:03 -04002392 // [OpenGL ES 3.0.2] section 2.10 page 43:
2393 // If a vertex array object that is currently bound is deleted, the binding
2394 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002395 if (mGLState.removeVertexArrayBinding(vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002396 {
2397 bindVertexArray(0);
2398 }
2399}
2400
Geoff Langc8058452014-02-03 12:04:11 -05002401void Context::detachTransformFeedback(GLuint transformFeedback)
2402{
Corentin Walleza2257da2016-04-19 16:43:12 -04002403 // Transform feedback detachment is handled by Context, because 0 is a valid
2404 // transform feedback, and a pointer to it must be passed from Context to State at
2405 // binding time.
2406
2407 // The OpenGL specification doesn't mention what should happen when the currently bound
2408 // transform feedback object is deleted. Since it is a container object, we treat it like
2409 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002410 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002411 {
2412 bindTransformFeedback(0);
2413 }
Geoff Langc8058452014-02-03 12:04:11 -05002414}
2415
Jamie Madilldc356042013-07-19 16:36:57 -04002416void Context::detachSampler(GLuint sampler)
2417{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002418 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002419}
2420
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002421void Context::setVertexAttribDivisor(GLuint index, GLuint divisor)
2422{
Shaodde78e82017-05-22 14:13:27 +08002423 mGLState.setVertexAttribDivisor(this, index, divisor);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002424}
2425
Jamie Madille29d1672013-07-19 16:36:57 -04002426void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2427{
Geoff Langc1984ed2016-10-07 12:41:00 -04002428 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002429 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002430 SetSamplerParameteri(samplerObject, pname, param);
2431}
Jamie Madille29d1672013-07-19 16:36:57 -04002432
Geoff Langc1984ed2016-10-07 12:41:00 -04002433void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2434{
2435 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002436 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002437 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madille29d1672013-07-19 16:36:57 -04002438}
2439
2440void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2441{
Geoff Langc1984ed2016-10-07 12:41:00 -04002442 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002443 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002444 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madille29d1672013-07-19 16:36:57 -04002445}
2446
Geoff Langc1984ed2016-10-07 12:41:00 -04002447void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002448{
Geoff Langc1984ed2016-10-07 12:41:00 -04002449 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002450 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002451 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill9675b802013-07-19 16:36:59 -04002452}
2453
Geoff Langc1984ed2016-10-07 12:41:00 -04002454void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002455{
Geoff Langc1984ed2016-10-07 12:41:00 -04002456 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002457 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002458 QuerySamplerParameteriv(samplerObject, pname, params);
2459}
Jamie Madill9675b802013-07-19 16:36:59 -04002460
Geoff Langc1984ed2016-10-07 12:41:00 -04002461void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2462{
2463 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002464 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002465 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill9675b802013-07-19 16:36:59 -04002466}
2467
Olli Etuahof0fee072016-03-30 15:11:58 +03002468void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2469{
2470 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002471 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002472}
2473
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002474void Context::initRendererString()
2475{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002476 std::ostringstream rendererString;
2477 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002478 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002479 rendererString << ")";
2480
Geoff Langcec35902014-04-16 10:52:36 -04002481 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002482}
2483
Geoff Langc339c4e2016-11-29 10:37:36 -05002484void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002485{
Geoff Langc339c4e2016-11-29 10:37:36 -05002486 const Version &clientVersion = getClientVersion();
2487
2488 std::ostringstream versionString;
2489 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2490 << ANGLE_VERSION_STRING << ")";
2491 mVersionString = MakeStaticString(versionString.str());
2492
2493 std::ostringstream shadingLanguageVersionString;
2494 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2495 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2496 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2497 << ")";
2498 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002499}
2500
Geoff Langcec35902014-04-16 10:52:36 -04002501void Context::initExtensionStrings()
2502{
Geoff Langc339c4e2016-11-29 10:37:36 -05002503 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2504 std::ostringstream combinedStringStream;
2505 std::copy(strings.begin(), strings.end(),
2506 std::ostream_iterator<const char *>(combinedStringStream, " "));
2507 return MakeStaticString(combinedStringStream.str());
2508 };
2509
2510 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002511 for (const auto &extensionString : mExtensions.getStrings())
2512 {
2513 mExtensionStrings.push_back(MakeStaticString(extensionString));
2514 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002515 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002516
Bryan Bernhart58806562017-01-05 13:09:31 -08002517 const gl::Extensions &nativeExtensions = mImplementation->getNativeExtensions();
2518
Geoff Langc339c4e2016-11-29 10:37:36 -05002519 mRequestableExtensionStrings.clear();
2520 for (const auto &extensionInfo : GetExtensionInfoMap())
2521 {
2522 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08002523 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
2524 nativeExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002525 {
2526 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
2527 }
2528 }
2529 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002530}
2531
Geoff Langc339c4e2016-11-29 10:37:36 -05002532const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04002533{
Geoff Langc339c4e2016-11-29 10:37:36 -05002534 switch (name)
2535 {
2536 case GL_VENDOR:
2537 return reinterpret_cast<const GLubyte *>("Google Inc.");
2538
2539 case GL_RENDERER:
2540 return reinterpret_cast<const GLubyte *>(mRendererString);
2541
2542 case GL_VERSION:
2543 return reinterpret_cast<const GLubyte *>(mVersionString);
2544
2545 case GL_SHADING_LANGUAGE_VERSION:
2546 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
2547
2548 case GL_EXTENSIONS:
2549 return reinterpret_cast<const GLubyte *>(mExtensionString);
2550
2551 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2552 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
2553
2554 default:
2555 UNREACHABLE();
2556 return nullptr;
2557 }
Geoff Langcec35902014-04-16 10:52:36 -04002558}
2559
Geoff Langc339c4e2016-11-29 10:37:36 -05002560const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04002561{
Geoff Langc339c4e2016-11-29 10:37:36 -05002562 switch (name)
2563 {
2564 case GL_EXTENSIONS:
2565 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
2566
2567 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2568 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
2569
2570 default:
2571 UNREACHABLE();
2572 return nullptr;
2573 }
Geoff Langcec35902014-04-16 10:52:36 -04002574}
2575
2576size_t Context::getExtensionStringCount() const
2577{
2578 return mExtensionStrings.size();
2579}
2580
Geoff Langc339c4e2016-11-29 10:37:36 -05002581void Context::requestExtension(const char *name)
2582{
2583 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2584 ASSERT(extensionInfos.find(name) != extensionInfos.end());
2585 const auto &extension = extensionInfos.at(name);
2586 ASSERT(extension.Requestable);
2587
2588 if (mExtensions.*(extension.ExtensionsMember))
2589 {
2590 // Extension already enabled
2591 return;
2592 }
2593
2594 mExtensions.*(extension.ExtensionsMember) = true;
2595 updateCaps();
2596 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08002597
Jamie Madill2f348d22017-06-05 10:50:59 -04002598 // Release the shader compiler so it will be re-created with the requested extensions enabled.
2599 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04002600
2601 // Invalidate all cached completenesses for textures and framebuffer. Some extensions make new
2602 // formats renderable or sampleable.
2603 mState.mTextures->invalidateTextureComplenessCache();
2604 for (auto &zeroTexture : mZeroTextures)
2605 {
2606 zeroTexture.second->invalidateCompletenessCache();
2607 }
2608
2609 mState.mFramebuffers->invalidateFramebufferComplenessCache();
Geoff Langc339c4e2016-11-29 10:37:36 -05002610}
2611
2612size_t Context::getRequestableExtensionStringCount() const
2613{
2614 return mRequestableExtensionStrings.size();
2615}
2616
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002617void Context::beginTransformFeedback(GLenum primitiveMode)
2618{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002619 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002620 ASSERT(transformFeedback != nullptr);
2621 ASSERT(!transformFeedback->isPaused());
2622
Jamie Madill6c1f6712017-02-14 19:08:04 -05002623 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002624}
2625
2626bool Context::hasActiveTransformFeedback(GLuint program) const
2627{
2628 for (auto pair : mTransformFeedbackMap)
2629 {
2630 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
2631 {
2632 return true;
2633 }
2634 }
2635 return false;
2636}
2637
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002638void Context::initCaps(const egl::DisplayExtensions &displayExtensions)
Geoff Lang493daf52014-07-03 13:38:44 -04002639{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002640 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04002641
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002642 mExtensions = mImplementation->getNativeExtensions();
Geoff Lang493daf52014-07-03 13:38:44 -04002643
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002644 mLimitations = mImplementation->getNativeLimitations();
Austin Kinross02df7962015-07-01 10:03:42 -07002645
Geoff Langeb66a6e2016-10-31 13:06:12 -04002646 if (getClientVersion() < Version(3, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002647 {
2648 // Disable ES3+ extensions
Jamie Madill231c7f52017-04-26 13:45:37 -04002649 mExtensions.colorBufferFloat = false;
Geoff Langb66a9092016-05-16 15:59:14 -04002650 mExtensions.eglImageExternalEssl3 = false;
Vincent Lang25ab4512016-05-13 18:13:59 +02002651 mExtensions.textureNorm16 = false;
Martin Radev137032d2017-07-13 10:11:12 +03002652 mExtensions.multiview = false;
2653 mExtensions.maxViews = 1u;
Geoff Lang493daf52014-07-03 13:38:44 -04002654 }
2655
Geoff Langeb66a6e2016-10-31 13:06:12 -04002656 if (getClientVersion() > Version(2, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002657 {
2658 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
Jamie Madill231c7f52017-04-26 13:45:37 -04002659 // mExtensions.sRGB = false;
Geoff Lang493daf52014-07-03 13:38:44 -04002660 }
2661
Jamie Madill00ed7a12016-05-19 13:13:38 -04002662 // Some extensions are always available because they are implemented in the GL layer.
Jamie Madill231c7f52017-04-26 13:45:37 -04002663 mExtensions.bindUniformLocation = true;
2664 mExtensions.vertexArrayObject = true;
Geoff Langf41a7152016-09-19 15:11:17 -04002665 mExtensions.bindGeneratesResource = true;
Geoff Langfeb8c682017-02-13 16:07:35 -05002666 mExtensions.clientArrays = true;
Geoff Langc339c4e2016-11-29 10:37:36 -05002667 mExtensions.requestExtension = true;
Jamie Madill00ed7a12016-05-19 13:13:38 -04002668
2669 // Enable the no error extension if the context was created with the flag.
2670 mExtensions.noError = mSkipValidation;
2671
Corentin Wallezccab69d2017-01-27 16:57:15 -05002672 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Corentin Wallezc295e512017-01-27 17:47:50 -05002673 mExtensions.surfacelessContext = displayExtensions.surfacelessContext;
Corentin Wallezccab69d2017-01-27 16:57:15 -05002674
Geoff Lang70d0f492015-12-10 17:45:46 -05002675 // Explicitly enable GL_KHR_debug
2676 mExtensions.debug = true;
2677 mExtensions.maxDebugMessageLength = 1024;
2678 mExtensions.maxDebugLoggedMessages = 1024;
2679 mExtensions.maxDebugGroupStackDepth = 1024;
2680 mExtensions.maxLabelLength = 1024;
2681
Geoff Langff5b2d52016-09-07 11:32:23 -04002682 // Explicitly enable GL_ANGLE_robust_client_memory
2683 mExtensions.robustClientMemory = true;
2684
Jamie Madille08a1d32017-03-07 17:24:06 -05002685 // Determine robust resource init availability from EGL.
2686 mExtensions.robustResourceInitialization =
Jamie Madill948bbe52017-06-01 13:10:42 -04002687 egl::Display::GetClientExtensions().displayRobustResourceInitialization;
Jamie Madille08a1d32017-03-07 17:24:06 -05002688
Jamie Madillc43be722017-07-13 16:22:14 -04002689 // Enable the cache control query unconditionally.
2690 mExtensions.programCacheControl = true;
2691
Geoff Lang301d1612014-07-09 10:34:37 -04002692 // Apply implementation limits
2693 mCaps.maxVertexAttributes = std::min<GLuint>(mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002694 mCaps.maxVertexAttribBindings =
2695 getClientVersion() < ES_3_1
2696 ? mCaps.maxVertexAttributes
2697 : std::min<GLuint>(mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
2698
Jamie Madill231c7f52017-04-26 13:45:37 -04002699 mCaps.maxVertexUniformBlocks = std::min<GLuint>(
2700 mCaps.maxVertexUniformBlocks, IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
2701 mCaps.maxVertexOutputComponents =
2702 std::min<GLuint>(mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
Geoff Lang301d1612014-07-09 10:34:37 -04002703
Jamie Madill231c7f52017-04-26 13:45:37 -04002704 mCaps.maxFragmentInputComponents =
2705 std::min<GLuint>(mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
Geoff Lang3a61c322014-07-10 13:01:54 -04002706
Geoff Langc287ea62016-09-16 14:46:51 -04002707 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002708 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04002709 for (const auto &extensionInfo : GetExtensionInfoMap())
2710 {
2711 // If this context is for WebGL, disable all enableable extensions
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002712 if (mWebGLContext && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04002713 {
2714 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
2715 }
2716 }
2717
2718 // Generate texture caps
2719 updateCaps();
2720}
2721
2722void Context::updateCaps()
2723{
Geoff Lang900013c2014-07-07 11:32:19 -04002724 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002725 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04002726
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002727 for (auto capsIt : mImplementation->getNativeTextureCaps())
Geoff Lang493daf52014-07-03 13:38:44 -04002728 {
Geoff Langca271392017-04-05 12:30:00 -04002729 GLenum sizedInternalFormat = capsIt.first;
Jamie Madill231c7f52017-04-26 13:45:37 -04002730 TextureCaps formatCaps = capsIt.second;
Geoff Lang493daf52014-07-03 13:38:44 -04002731
Geoff Langca271392017-04-05 12:30:00 -04002732 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04002733
Geoff Lang0d8b7242015-09-09 14:56:53 -04002734 // Update the format caps based on the client version and extensions.
2735 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
2736 // ES3.
2737 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002738 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002739 formatCaps.renderable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002740 formatCaps.renderable && formatInfo.renderSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002741 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002742 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04002743
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002744 // OpenGL ES does not support multisampling with non-rendererable formats
2745 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Olli Etuaho50c562d2017-06-06 14:43:30 +03002746 if (!formatCaps.renderable ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002747 (getClientVersion() < ES_3_1 &&
2748 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04002749 {
Geoff Langd87878e2014-09-19 15:42:59 -04002750 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04002751 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03002752 else
2753 {
2754 // We may have limited the max samples for some required renderbuffer formats due to
2755 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
2756 GLuint formatMaxSamples = formatCaps.getMaxSamples();
2757
2758 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
2759 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
2760 // exception of signed and unsigned integer formats."
2761 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
2762 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
2763 {
2764 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
2765 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
2766 }
2767
2768 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
2769 if (getClientVersion() >= ES_3_1)
2770 {
2771 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
2772 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
2773 // the exception that the signed and unsigned integer formats are required only to
2774 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
2775 // multisamples, which must be at least one."
2776 if (formatInfo.componentType == GL_INT ||
2777 formatInfo.componentType == GL_UNSIGNED_INT)
2778 {
2779 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
2780 }
2781
2782 // GLES 3.1 section 19.3.1.
2783 if (formatCaps.texturable)
2784 {
2785 if (formatInfo.depthBits > 0)
2786 {
2787 mCaps.maxDepthTextureSamples =
2788 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
2789 }
2790 else if (formatInfo.redBits > 0)
2791 {
2792 mCaps.maxColorTextureSamples =
2793 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
2794 }
2795 }
2796 }
2797 }
Geoff Langd87878e2014-09-19 15:42:59 -04002798
2799 if (formatCaps.texturable && formatInfo.compressed)
2800 {
Geoff Langca271392017-04-05 12:30:00 -04002801 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04002802 }
2803
Geoff Langca271392017-04-05 12:30:00 -04002804 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04002805 }
Jamie Madill32447362017-06-28 14:53:52 -04002806
2807 // If program binary is disabled, blank out the memory cache pointer.
2808 if (!mImplementation->getNativeExtensions().getProgramBinary)
2809 {
2810 mMemoryProgramCache = nullptr;
2811 }
Geoff Lang493daf52014-07-03 13:38:44 -04002812}
2813
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002814void Context::initWorkarounds()
2815{
Jamie Madill761b02c2017-06-23 16:27:06 -04002816 // Apply back-end workarounds.
2817 mImplementation->applyNativeWorkarounds(&mWorkarounds);
2818
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002819 // Lose the context upon out of memory error if the application is
2820 // expecting to watch for those events.
2821 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2822}
2823
Jamie Madill1b94d432015-08-07 13:23:23 -04002824void Context::syncRendererState()
2825{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002826 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
Jamie Madillfe548342017-06-19 11:13:24 -04002827 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002828 mGLState.clearDirtyBits();
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002829 mGLState.syncDirtyObjects(this);
Jamie Madill1b94d432015-08-07 13:23:23 -04002830}
2831
Jamie Madillad9f24e2016-02-12 09:27:24 -05002832void Context::syncRendererState(const State::DirtyBits &bitMask,
2833 const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04002834{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002835 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madillfe548342017-06-19 11:13:24 -04002836 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002837 mGLState.clearDirtyBits(dirtyBits);
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002838 mGLState.syncDirtyObjects(this, objectMask);
Jamie Madill1b94d432015-08-07 13:23:23 -04002839}
Jamie Madillc29968b2016-01-20 11:17:23 -05002840
2841void Context::blitFramebuffer(GLint srcX0,
2842 GLint srcY0,
2843 GLint srcX1,
2844 GLint srcY1,
2845 GLint dstX0,
2846 GLint dstY0,
2847 GLint dstX1,
2848 GLint dstY1,
2849 GLbitfield mask,
2850 GLenum filter)
2851{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002852 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002853 ASSERT(drawFramebuffer);
2854
2855 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
2856 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
2857
Jamie Madillad9f24e2016-02-12 09:27:24 -05002858 syncStateForBlit();
Jamie Madillc29968b2016-01-20 11:17:23 -05002859
Jamie Madillc564c072017-06-01 12:45:42 -04002860 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002861}
Jamie Madillc29968b2016-01-20 11:17:23 -05002862
2863void Context::clear(GLbitfield mask)
2864{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002865 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002866 handleError(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05002867}
2868
2869void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
2870{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002871 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002872 handleError(mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002873}
2874
2875void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
2876{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002877 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002878 handleError(mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002879}
2880
2881void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
2882{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002883 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002884 handleError(mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002885}
2886
2887void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
2888{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002889 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002890 ASSERT(framebufferObject);
2891
2892 // If a buffer is not present, the clear has no effect
2893 if (framebufferObject->getDepthbuffer() == nullptr &&
2894 framebufferObject->getStencilbuffer() == nullptr)
2895 {
2896 return;
2897 }
2898
Jamie Madillad9f24e2016-02-12 09:27:24 -05002899 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002900 handleError(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05002901}
2902
2903void Context::readPixels(GLint x,
2904 GLint y,
2905 GLsizei width,
2906 GLsizei height,
2907 GLenum format,
2908 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002909 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05002910{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04002911 if (width == 0 || height == 0)
2912 {
2913 return;
2914 }
2915
Jamie Madillad9f24e2016-02-12 09:27:24 -05002916 syncStateForReadPixels();
Jamie Madillc29968b2016-01-20 11:17:23 -05002917
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002918 Framebuffer *framebufferObject = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002919 ASSERT(framebufferObject);
2920
2921 Rectangle area(x, y, width, height);
Jamie Madillc564c072017-06-01 12:45:42 -04002922 handleError(framebufferObject->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05002923}
2924
2925void Context::copyTexImage2D(GLenum target,
2926 GLint level,
2927 GLenum internalformat,
2928 GLint x,
2929 GLint y,
2930 GLsizei width,
2931 GLsizei height,
2932 GLint border)
2933{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002934 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002935 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002936
Jamie Madillc29968b2016-01-20 11:17:23 -05002937 Rectangle sourceArea(x, y, width, height);
2938
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002939 const Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002940 Texture *texture =
2941 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05002942 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05002943}
2944
2945void Context::copyTexSubImage2D(GLenum target,
2946 GLint level,
2947 GLint xoffset,
2948 GLint yoffset,
2949 GLint x,
2950 GLint y,
2951 GLsizei width,
2952 GLsizei height)
2953{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04002954 if (width == 0 || height == 0)
2955 {
2956 return;
2957 }
2958
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002959 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002960 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002961
Jamie Madillc29968b2016-01-20 11:17:23 -05002962 Offset destOffset(xoffset, yoffset, 0);
2963 Rectangle sourceArea(x, y, width, height);
2964
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002965 const Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002966 Texture *texture =
2967 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05002968 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05002969}
2970
2971void Context::copyTexSubImage3D(GLenum target,
2972 GLint level,
2973 GLint xoffset,
2974 GLint yoffset,
2975 GLint zoffset,
2976 GLint x,
2977 GLint y,
2978 GLsizei width,
2979 GLsizei height)
2980{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04002981 if (width == 0 || height == 0)
2982 {
2983 return;
2984 }
2985
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002986 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002987 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002988
Jamie Madillc29968b2016-01-20 11:17:23 -05002989 Offset destOffset(xoffset, yoffset, zoffset);
2990 Rectangle sourceArea(x, y, width, height);
2991
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002992 const Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002993 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05002994 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05002995}
2996
2997void Context::framebufferTexture2D(GLenum target,
2998 GLenum attachment,
2999 GLenum textarget,
3000 GLuint texture,
3001 GLint level)
3002{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003003 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003004 ASSERT(framebuffer);
3005
3006 if (texture != 0)
3007 {
3008 Texture *textureObj = getTexture(texture);
3009
3010 ImageIndex index = ImageIndex::MakeInvalid();
3011
3012 if (textarget == GL_TEXTURE_2D)
3013 {
3014 index = ImageIndex::Make2D(level);
3015 }
JiangYizhoubddc46b2016-12-09 09:50:51 +08003016 else if (textarget == GL_TEXTURE_2D_MULTISAMPLE)
3017 {
3018 ASSERT(level == 0);
3019 index = ImageIndex::Make2DMultisample();
3020 }
Jamie Madillc29968b2016-01-20 11:17:23 -05003021 else
3022 {
3023 ASSERT(IsCubeMapTextureTarget(textarget));
3024 index = ImageIndex::MakeCube(textarget, level);
3025 }
3026
Jamie Madilla02315b2017-02-23 14:14:47 -05003027 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003028 }
3029 else
3030 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003031 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003032 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003033
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003034 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003035}
3036
3037void Context::framebufferRenderbuffer(GLenum target,
3038 GLenum attachment,
3039 GLenum renderbuffertarget,
3040 GLuint renderbuffer)
3041{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003042 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003043 ASSERT(framebuffer);
3044
3045 if (renderbuffer != 0)
3046 {
3047 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003048
3049 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex::MakeInvalid(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003050 renderbufferObject);
3051 }
3052 else
3053 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003054 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003055 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003056
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003057 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003058}
3059
3060void Context::framebufferTextureLayer(GLenum target,
3061 GLenum attachment,
3062 GLuint texture,
3063 GLint level,
3064 GLint layer)
3065{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003066 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003067 ASSERT(framebuffer);
3068
3069 if (texture != 0)
3070 {
3071 Texture *textureObject = getTexture(texture);
3072
3073 ImageIndex index = ImageIndex::MakeInvalid();
3074
3075 if (textureObject->getTarget() == GL_TEXTURE_3D)
3076 {
3077 index = ImageIndex::Make3D(level, layer);
3078 }
3079 else
3080 {
3081 ASSERT(textureObject->getTarget() == GL_TEXTURE_2D_ARRAY);
3082 index = ImageIndex::Make2DArray(level, layer);
3083 }
3084
Jamie Madilla02315b2017-02-23 14:14:47 -05003085 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003086 }
3087 else
3088 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003089 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003090 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003091
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003092 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003093}
3094
Martin Radev137032d2017-07-13 10:11:12 +03003095void Context::framebufferTextureMultiviewLayeredANGLE(GLenum target,
3096 GLenum attachment,
3097 GLuint texture,
3098 GLint level,
3099 GLint baseViewIndex,
3100 GLsizei numViews)
3101{
3102 UNIMPLEMENTED();
3103}
3104
3105void Context::framebufferTextureMultiviewSideBySideANGLE(GLenum target,
3106 GLenum attachment,
3107 GLuint texture,
3108 GLint level,
3109 GLsizei numViews,
3110 const GLint *viewportOffsets)
3111{
Martin Radev5dae57b2017-07-14 16:15:55 +03003112 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3113 ASSERT(framebuffer);
3114
3115 if (texture != 0)
3116 {
3117 Texture *textureObj = getTexture(texture);
3118
3119 ImageIndex index = ImageIndex::Make2D(level);
3120 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3121 textureObj, numViews, viewportOffsets);
3122 }
3123 else
3124 {
3125 framebuffer->resetAttachment(this, attachment);
3126 }
3127
3128 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003129}
3130
Jamie Madillc29968b2016-01-20 11:17:23 -05003131void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3132{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003133 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003134 ASSERT(framebuffer);
3135 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003136 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003137}
3138
3139void Context::readBuffer(GLenum mode)
3140{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003141 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003142 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003143 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003144}
3145
3146void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3147{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003148 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003149 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003150
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003151 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003152 ASSERT(framebuffer);
3153
3154 // The specification isn't clear what should be done when the framebuffer isn't complete.
3155 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003156 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003157}
3158
3159void Context::invalidateFramebuffer(GLenum target,
3160 GLsizei numAttachments,
3161 const GLenum *attachments)
3162{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003163 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003164 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003165
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003166 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003167 ASSERT(framebuffer);
3168
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003169 if (framebuffer->checkStatus(this) != GL_FRAMEBUFFER_COMPLETE)
Jamie Madillc29968b2016-01-20 11:17:23 -05003170 {
Jamie Madill437fa652016-05-03 15:13:24 -04003171 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003172 }
Jamie Madill437fa652016-05-03 15:13:24 -04003173
Jamie Madill4928b7c2017-06-20 12:57:39 -04003174 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003175}
3176
3177void Context::invalidateSubFramebuffer(GLenum target,
3178 GLsizei numAttachments,
3179 const GLenum *attachments,
3180 GLint x,
3181 GLint y,
3182 GLsizei width,
3183 GLsizei height)
3184{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003185 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003186 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003187
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003188 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003189 ASSERT(framebuffer);
3190
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003191 if (framebuffer->checkStatus(this) != GL_FRAMEBUFFER_COMPLETE)
Jamie Madillc29968b2016-01-20 11:17:23 -05003192 {
Jamie Madill437fa652016-05-03 15:13:24 -04003193 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003194 }
Jamie Madill437fa652016-05-03 15:13:24 -04003195
3196 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003197 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003198}
3199
Jamie Madill73a84962016-02-12 09:27:23 -05003200void Context::texImage2D(GLenum target,
3201 GLint level,
3202 GLint internalformat,
3203 GLsizei width,
3204 GLsizei height,
3205 GLint border,
3206 GLenum format,
3207 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003208 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003209{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003210 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003211
3212 Extents size(width, height, 1);
3213 Texture *texture =
3214 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003215 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3216 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003217}
3218
3219void Context::texImage3D(GLenum target,
3220 GLint level,
3221 GLint internalformat,
3222 GLsizei width,
3223 GLsizei height,
3224 GLsizei depth,
3225 GLint border,
3226 GLenum format,
3227 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003228 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003229{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003230 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003231
3232 Extents size(width, height, depth);
3233 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003234 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3235 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003236}
3237
3238void Context::texSubImage2D(GLenum target,
3239 GLint level,
3240 GLint xoffset,
3241 GLint yoffset,
3242 GLsizei width,
3243 GLsizei height,
3244 GLenum format,
3245 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003246 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003247{
3248 // Zero sized uploads are valid but no-ops
3249 if (width == 0 || height == 0)
3250 {
3251 return;
3252 }
3253
Jamie Madillad9f24e2016-02-12 09:27:24 -05003254 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003255
3256 Box area(xoffset, yoffset, 0, width, height, 1);
3257 Texture *texture =
3258 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003259 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3260 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003261}
3262
3263void Context::texSubImage3D(GLenum target,
3264 GLint level,
3265 GLint xoffset,
3266 GLint yoffset,
3267 GLint zoffset,
3268 GLsizei width,
3269 GLsizei height,
3270 GLsizei depth,
3271 GLenum format,
3272 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003273 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003274{
3275 // Zero sized uploads are valid but no-ops
3276 if (width == 0 || height == 0 || depth == 0)
3277 {
3278 return;
3279 }
3280
Jamie Madillad9f24e2016-02-12 09:27:24 -05003281 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003282
3283 Box area(xoffset, yoffset, zoffset, width, height, depth);
3284 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003285 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3286 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003287}
3288
3289void Context::compressedTexImage2D(GLenum target,
3290 GLint level,
3291 GLenum internalformat,
3292 GLsizei width,
3293 GLsizei height,
3294 GLint border,
3295 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003296 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003297{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003298 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003299
3300 Extents size(width, height, 1);
3301 Texture *texture =
3302 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003303 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003304 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003305 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003306}
3307
3308void Context::compressedTexImage3D(GLenum target,
3309 GLint level,
3310 GLenum internalformat,
3311 GLsizei width,
3312 GLsizei height,
3313 GLsizei depth,
3314 GLint border,
3315 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003316 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003317{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003318 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003319
3320 Extents size(width, height, depth);
3321 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003322 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003323 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003324 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003325}
3326
3327void Context::compressedTexSubImage2D(GLenum target,
3328 GLint level,
3329 GLint xoffset,
3330 GLint yoffset,
3331 GLsizei width,
3332 GLsizei height,
3333 GLenum format,
3334 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003335 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003336{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003337 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003338
3339 Box area(xoffset, yoffset, 0, width, height, 1);
3340 Texture *texture =
3341 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003342 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003343 format, imageSize,
3344 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003345}
3346
3347void Context::compressedTexSubImage3D(GLenum target,
3348 GLint level,
3349 GLint xoffset,
3350 GLint yoffset,
3351 GLint zoffset,
3352 GLsizei width,
3353 GLsizei height,
3354 GLsizei depth,
3355 GLenum format,
3356 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003357 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003358{
3359 // Zero sized uploads are valid but no-ops
3360 if (width == 0 || height == 0)
3361 {
3362 return;
3363 }
3364
Jamie Madillad9f24e2016-02-12 09:27:24 -05003365 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003366
3367 Box area(xoffset, yoffset, zoffset, width, height, depth);
3368 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003369 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003370 format, imageSize,
3371 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003372}
3373
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003374void Context::generateMipmap(GLenum target)
3375{
3376 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003377 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003378}
3379
Geoff Lang97073d12016-04-20 10:42:34 -07003380void Context::copyTextureCHROMIUM(GLuint sourceId,
Geoff Langfc72a072017-03-24 14:52:39 -04003381 GLint sourceLevel,
3382 GLenum destTarget,
Geoff Lang97073d12016-04-20 10:42:34 -07003383 GLuint destId,
Geoff Langfc72a072017-03-24 14:52:39 -04003384 GLint destLevel,
Geoff Lang97073d12016-04-20 10:42:34 -07003385 GLint internalFormat,
3386 GLenum destType,
3387 GLboolean unpackFlipY,
3388 GLboolean unpackPremultiplyAlpha,
3389 GLboolean unpackUnmultiplyAlpha)
3390{
3391 syncStateForTexImage();
3392
3393 gl::Texture *sourceTexture = getTexture(sourceId);
3394 gl::Texture *destTexture = getTexture(destId);
Geoff Langfc72a072017-03-24 14:52:39 -04003395 handleError(destTexture->copyTexture(
3396 this, destTarget, destLevel, internalFormat, destType, sourceLevel, unpackFlipY == GL_TRUE,
3397 unpackPremultiplyAlpha == GL_TRUE, unpackUnmultiplyAlpha == GL_TRUE, sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003398}
3399
3400void Context::copySubTextureCHROMIUM(GLuint sourceId,
Geoff Langfc72a072017-03-24 14:52:39 -04003401 GLint sourceLevel,
3402 GLenum destTarget,
Geoff Lang97073d12016-04-20 10:42:34 -07003403 GLuint destId,
Geoff Langfc72a072017-03-24 14:52:39 -04003404 GLint destLevel,
Geoff Lang97073d12016-04-20 10:42:34 -07003405 GLint xoffset,
3406 GLint yoffset,
3407 GLint x,
3408 GLint y,
3409 GLsizei width,
3410 GLsizei height,
3411 GLboolean unpackFlipY,
3412 GLboolean unpackPremultiplyAlpha,
3413 GLboolean unpackUnmultiplyAlpha)
3414{
3415 // Zero sized copies are valid but no-ops
3416 if (width == 0 || height == 0)
3417 {
3418 return;
3419 }
3420
3421 syncStateForTexImage();
3422
3423 gl::Texture *sourceTexture = getTexture(sourceId);
3424 gl::Texture *destTexture = getTexture(destId);
3425 Offset offset(xoffset, yoffset, 0);
3426 Rectangle area(x, y, width, height);
Geoff Langfc72a072017-03-24 14:52:39 -04003427 handleError(destTexture->copySubTexture(
3428 this, destTarget, destLevel, offset, sourceLevel, area, unpackFlipY == GL_TRUE,
3429 unpackPremultiplyAlpha == GL_TRUE, unpackUnmultiplyAlpha == GL_TRUE, sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003430}
3431
Geoff Lang47110bf2016-04-20 11:13:22 -07003432void Context::compressedCopyTextureCHROMIUM(GLuint sourceId, GLuint destId)
3433{
3434 syncStateForTexImage();
3435
3436 gl::Texture *sourceTexture = getTexture(sourceId);
3437 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05003438 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07003439}
3440
Geoff Lang496c02d2016-10-20 11:38:11 -07003441void Context::getBufferPointerv(GLenum target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03003442{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003443 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003444 ASSERT(buffer);
3445
Geoff Lang496c02d2016-10-20 11:38:11 -07003446 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03003447}
3448
Jamie Madill876429b2017-04-20 15:46:24 -04003449void *Context::mapBuffer(GLenum target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003450{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003451 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003452 ASSERT(buffer);
3453
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003454 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003455 if (error.isError())
3456 {
Jamie Madill437fa652016-05-03 15:13:24 -04003457 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003458 return nullptr;
3459 }
3460
3461 return buffer->getMapPointer();
3462}
3463
3464GLboolean Context::unmapBuffer(GLenum target)
3465{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003466 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003467 ASSERT(buffer);
3468
3469 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003470 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03003471 if (error.isError())
3472 {
Jamie Madill437fa652016-05-03 15:13:24 -04003473 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003474 return GL_FALSE;
3475 }
3476
3477 return result;
3478}
3479
Jamie Madill876429b2017-04-20 15:46:24 -04003480void *Context::mapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003481{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003482 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003483 ASSERT(buffer);
3484
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003485 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003486 if (error.isError())
3487 {
Jamie Madill437fa652016-05-03 15:13:24 -04003488 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003489 return nullptr;
3490 }
3491
3492 return buffer->getMapPointer();
3493}
3494
3495void Context::flushMappedBufferRange(GLenum /*target*/, GLintptr /*offset*/, GLsizeiptr /*length*/)
3496{
3497 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
3498}
3499
Jamie Madillad9f24e2016-02-12 09:27:24 -05003500void Context::syncStateForReadPixels()
3501{
3502 syncRendererState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
3503}
3504
3505void Context::syncStateForTexImage()
3506{
3507 syncRendererState(mTexImageDirtyBits, mTexImageDirtyObjects);
3508}
3509
3510void Context::syncStateForClear()
3511{
3512 syncRendererState(mClearDirtyBits, mClearDirtyObjects);
3513}
3514
3515void Context::syncStateForBlit()
3516{
3517 syncRendererState(mBlitDirtyBits, mBlitDirtyObjects);
3518}
3519
Jamie Madillc20ab272016-06-09 07:20:46 -07003520void Context::activeTexture(GLenum texture)
3521{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003522 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003523}
3524
Jamie Madill876429b2017-04-20 15:46:24 -04003525void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003526{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003527 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07003528}
3529
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003530void Context::blendEquation(GLenum mode)
3531{
3532 mGLState.setBlendEquation(mode, mode);
3533}
3534
Jamie Madillc20ab272016-06-09 07:20:46 -07003535void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
3536{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003537 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003538}
3539
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003540void Context::blendFunc(GLenum sfactor, GLenum dfactor)
3541{
3542 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
3543}
3544
Jamie Madillc20ab272016-06-09 07:20:46 -07003545void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
3546{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003547 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003548}
3549
Jamie Madill876429b2017-04-20 15:46:24 -04003550void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003551{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003552 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003553}
3554
Jamie Madill876429b2017-04-20 15:46:24 -04003555void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07003556{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003557 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07003558}
3559
3560void Context::clearStencil(GLint s)
3561{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003562 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07003563}
3564
3565void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
3566{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003567 mGLState.setColorMask(red == GL_TRUE, green == GL_TRUE, blue == GL_TRUE, alpha == GL_TRUE);
Jamie Madillc20ab272016-06-09 07:20:46 -07003568}
3569
3570void Context::cullFace(GLenum mode)
3571{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003572 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003573}
3574
3575void Context::depthFunc(GLenum func)
3576{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003577 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07003578}
3579
3580void Context::depthMask(GLboolean flag)
3581{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003582 mGLState.setDepthMask(flag != GL_FALSE);
Jamie Madillc20ab272016-06-09 07:20:46 -07003583}
3584
Jamie Madill876429b2017-04-20 15:46:24 -04003585void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07003586{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003587 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07003588}
3589
3590void Context::disable(GLenum cap)
3591{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003592 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003593}
3594
3595void Context::disableVertexAttribArray(GLuint index)
3596{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003597 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003598}
3599
3600void Context::enable(GLenum cap)
3601{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003602 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003603}
3604
3605void Context::enableVertexAttribArray(GLuint index)
3606{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003607 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003608}
3609
3610void Context::frontFace(GLenum mode)
3611{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003612 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003613}
3614
3615void Context::hint(GLenum target, GLenum mode)
3616{
3617 switch (target)
3618 {
3619 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003620 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003621 break;
3622
3623 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003624 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003625 break;
3626
3627 default:
3628 UNREACHABLE();
3629 return;
3630 }
3631}
3632
3633void Context::lineWidth(GLfloat width)
3634{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003635 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07003636}
3637
3638void Context::pixelStorei(GLenum pname, GLint param)
3639{
3640 switch (pname)
3641 {
3642 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003643 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003644 break;
3645
3646 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003647 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003648 break;
3649
3650 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003651 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003652 break;
3653
3654 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003655 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003656 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003657 break;
3658
3659 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03003660 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003661 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003662 break;
3663
3664 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03003665 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003666 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003667 break;
3668
3669 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003670 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003671 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003672 break;
3673
3674 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003675 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003676 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003677 break;
3678
3679 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003680 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003681 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003682 break;
3683
3684 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003685 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003686 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003687 break;
3688
3689 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003690 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003691 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003692 break;
3693
3694 default:
3695 UNREACHABLE();
3696 return;
3697 }
3698}
3699
3700void Context::polygonOffset(GLfloat factor, GLfloat units)
3701{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003702 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07003703}
3704
Jamie Madill876429b2017-04-20 15:46:24 -04003705void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07003706{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003707 mGLState.setSampleCoverageParams(clamp01(value), invert == GL_TRUE);
Jamie Madillc20ab272016-06-09 07:20:46 -07003708}
3709
3710void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
3711{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003712 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07003713}
3714
3715void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
3716{
3717 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3718 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003719 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003720 }
3721
3722 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3723 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003724 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003725 }
3726}
3727
3728void Context::stencilMaskSeparate(GLenum face, GLuint mask)
3729{
3730 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3731 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003732 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003733 }
3734
3735 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3736 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003737 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003738 }
3739}
3740
3741void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
3742{
3743 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3744 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003745 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003746 }
3747
3748 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3749 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003750 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003751 }
3752}
3753
3754void Context::vertexAttrib1f(GLuint index, GLfloat x)
3755{
3756 GLfloat vals[4] = {x, 0, 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::vertexAttrib1fv(GLuint index, const GLfloat *values)
3761{
3762 GLfloat vals[4] = {values[0], 0, 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::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
3767{
3768 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003769 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003770}
3771
3772void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
3773{
3774 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003775 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003776}
3777
3778void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
3779{
3780 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003781 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003782}
3783
3784void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
3785{
3786 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003787 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003788}
3789
3790void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
3791{
3792 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003793 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003794}
3795
3796void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
3797{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003798 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07003799}
3800
3801void Context::vertexAttribPointer(GLuint index,
3802 GLint size,
3803 GLenum type,
3804 GLboolean normalized,
3805 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04003806 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07003807{
Shaodde78e82017-05-22 14:13:27 +08003808 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(GL_ARRAY_BUFFER), size,
3809 type, normalized == GL_TRUE, false, stride, ptr);
Jamie Madillc20ab272016-06-09 07:20:46 -07003810}
3811
Shao80957d92017-02-20 21:25:59 +08003812void Context::vertexAttribFormat(GLuint attribIndex,
3813 GLint size,
3814 GLenum type,
3815 GLboolean normalized,
3816 GLuint relativeOffset)
3817{
3818 mGLState.setVertexAttribFormat(attribIndex, size, type, normalized == GL_TRUE, false,
3819 relativeOffset);
3820}
3821
3822void Context::vertexAttribIFormat(GLuint attribIndex,
3823 GLint size,
3824 GLenum type,
3825 GLuint relativeOffset)
3826{
3827 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
3828}
3829
3830void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
3831{
Shaodde78e82017-05-22 14:13:27 +08003832 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Shao80957d92017-02-20 21:25:59 +08003833}
3834
3835void Context::setVertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
3836{
3837 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
3838}
3839
Jamie Madillc20ab272016-06-09 07:20:46 -07003840void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
3841{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003842 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07003843}
3844
3845void Context::vertexAttribIPointer(GLuint index,
3846 GLint size,
3847 GLenum type,
3848 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04003849 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07003850{
Shaodde78e82017-05-22 14:13:27 +08003851 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(GL_ARRAY_BUFFER), size,
3852 type, false, true, stride, pointer);
Jamie Madillc20ab272016-06-09 07:20:46 -07003853}
3854
3855void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
3856{
3857 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003858 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003859}
3860
3861void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
3862{
3863 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003864 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003865}
3866
3867void Context::vertexAttribI4iv(GLuint index, const GLint *v)
3868{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003869 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07003870}
3871
3872void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
3873{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003874 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07003875}
3876
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003877void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
3878{
3879 const VertexAttribCurrentValueData &currentValues =
3880 getGLState().getVertexAttribCurrentValue(index);
3881 const VertexArray *vao = getGLState().getVertexArray();
3882 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3883 currentValues, pname, params);
3884}
3885
3886void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
3887{
3888 const VertexAttribCurrentValueData &currentValues =
3889 getGLState().getVertexAttribCurrentValue(index);
3890 const VertexArray *vao = getGLState().getVertexArray();
3891 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3892 currentValues, pname, params);
3893}
3894
3895void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
3896{
3897 const VertexAttribCurrentValueData &currentValues =
3898 getGLState().getVertexAttribCurrentValue(index);
3899 const VertexArray *vao = getGLState().getVertexArray();
3900 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3901 currentValues, pname, params);
3902}
3903
3904void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
3905{
3906 const VertexAttribCurrentValueData &currentValues =
3907 getGLState().getVertexAttribCurrentValue(index);
3908 const VertexArray *vao = getGLState().getVertexArray();
3909 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3910 currentValues, pname, params);
3911}
3912
Jamie Madill876429b2017-04-20 15:46:24 -04003913void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003914{
3915 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
3916 QueryVertexAttribPointerv(attrib, pname, pointer);
3917}
3918
Jamie Madillc20ab272016-06-09 07:20:46 -07003919void Context::debugMessageControl(GLenum source,
3920 GLenum type,
3921 GLenum severity,
3922 GLsizei count,
3923 const GLuint *ids,
3924 GLboolean enabled)
3925{
3926 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003927 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
3928 (enabled != GL_FALSE));
Jamie Madillc20ab272016-06-09 07:20:46 -07003929}
3930
3931void Context::debugMessageInsert(GLenum source,
3932 GLenum type,
3933 GLuint id,
3934 GLenum severity,
3935 GLsizei length,
3936 const GLchar *buf)
3937{
3938 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003939 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07003940}
3941
3942void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
3943{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003944 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07003945}
3946
3947GLuint Context::getDebugMessageLog(GLuint count,
3948 GLsizei bufSize,
3949 GLenum *sources,
3950 GLenum *types,
3951 GLuint *ids,
3952 GLenum *severities,
3953 GLsizei *lengths,
3954 GLchar *messageLog)
3955{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003956 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
3957 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07003958}
3959
3960void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
3961{
3962 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003963 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07003964}
3965
3966void Context::popDebugGroup()
3967{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003968 mGLState.getDebug().popGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07003969}
3970
Jamie Madill876429b2017-04-20 15:46:24 -04003971void Context::bufferData(GLenum target, GLsizeiptr size, const void *data, GLenum usage)
Jamie Madill29639852016-09-02 15:00:09 -04003972{
3973 Buffer *buffer = mGLState.getTargetBuffer(target);
3974 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08003975 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04003976}
3977
Jamie Madill876429b2017-04-20 15:46:24 -04003978void Context::bufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04003979{
3980 if (data == nullptr)
3981 {
3982 return;
3983 }
3984
3985 Buffer *buffer = mGLState.getTargetBuffer(target);
3986 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08003987 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04003988}
3989
Jamie Madillef300b12016-10-07 15:12:09 -04003990void Context::attachShader(GLuint program, GLuint shader)
3991{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05003992 auto programObject = mState.mShaderPrograms->getProgram(program);
3993 auto shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04003994 ASSERT(programObject && shaderObject);
3995 programObject->attachShader(shaderObject);
3996}
3997
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003998const Workarounds &Context::getWorkarounds() const
3999{
4000 return mWorkarounds;
4001}
4002
Jamie Madillb0817d12016-11-01 15:48:31 -04004003void Context::copyBufferSubData(GLenum readTarget,
4004 GLenum writeTarget,
4005 GLintptr readOffset,
4006 GLintptr writeOffset,
4007 GLsizeiptr size)
4008{
4009 // if size is zero, the copy is a successful no-op
4010 if (size == 0)
4011 {
4012 return;
4013 }
4014
4015 // TODO(jmadill): cache these.
4016 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4017 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4018
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004019 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004020}
4021
Jamie Madill01a80ee2016-11-07 12:06:18 -05004022void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4023{
4024 Program *programObject = getProgram(program);
4025 // TODO(jmadill): Re-use this from the validation if possible.
4026 ASSERT(programObject);
4027 programObject->bindAttributeLocation(index, name);
4028}
4029
4030void Context::bindBuffer(GLenum target, GLuint buffer)
4031{
4032 switch (target)
4033 {
4034 case GL_ARRAY_BUFFER:
4035 bindArrayBuffer(buffer);
4036 break;
4037 case GL_ELEMENT_ARRAY_BUFFER:
4038 bindElementArrayBuffer(buffer);
4039 break;
4040 case GL_COPY_READ_BUFFER:
4041 bindCopyReadBuffer(buffer);
4042 break;
4043 case GL_COPY_WRITE_BUFFER:
4044 bindCopyWriteBuffer(buffer);
4045 break;
4046 case GL_PIXEL_PACK_BUFFER:
4047 bindPixelPackBuffer(buffer);
4048 break;
4049 case GL_PIXEL_UNPACK_BUFFER:
4050 bindPixelUnpackBuffer(buffer);
4051 break;
4052 case GL_UNIFORM_BUFFER:
4053 bindGenericUniformBuffer(buffer);
4054 break;
4055 case GL_TRANSFORM_FEEDBACK_BUFFER:
4056 bindGenericTransformFeedbackBuffer(buffer);
4057 break;
Geoff Lang3b573612016-10-31 14:08:10 -04004058 case GL_ATOMIC_COUNTER_BUFFER:
Jiajia Qin6eafb042016-12-27 17:04:07 +08004059 bindGenericAtomicCounterBuffer(buffer);
Geoff Lang3b573612016-10-31 14:08:10 -04004060 break;
4061 case GL_SHADER_STORAGE_BUFFER:
Jiajia Qinf546e7d2017-03-27 14:12:59 +08004062 bindGenericShaderStorageBuffer(buffer);
Geoff Lang3b573612016-10-31 14:08:10 -04004063 break;
4064 case GL_DRAW_INDIRECT_BUFFER:
Jiajia Qin9d7d0b12016-11-29 16:30:31 +08004065 bindDrawIndirectBuffer(buffer);
Geoff Lang3b573612016-10-31 14:08:10 -04004066 break;
4067 case GL_DISPATCH_INDIRECT_BUFFER:
Geoff Lang9f090372016-12-02 10:20:43 -05004068 if (buffer != 0)
4069 {
4070 // Binding buffers to this binding point is not implemented yet.
4071 UNIMPLEMENTED();
4072 }
Geoff Lang3b573612016-10-31 14:08:10 -04004073 break;
Jamie Madill01a80ee2016-11-07 12:06:18 -05004074
4075 default:
4076 UNREACHABLE();
4077 break;
4078 }
4079}
4080
Jiajia Qin6eafb042016-12-27 17:04:07 +08004081void Context::bindBufferBase(GLenum target, GLuint index, GLuint buffer)
4082{
4083 bindBufferRange(target, index, buffer, 0, 0);
4084}
4085
4086void Context::bindBufferRange(GLenum target,
4087 GLuint index,
4088 GLuint buffer,
4089 GLintptr offset,
4090 GLsizeiptr size)
4091{
4092 switch (target)
4093 {
4094 case GL_TRANSFORM_FEEDBACK_BUFFER:
4095 bindIndexedTransformFeedbackBuffer(buffer, index, offset, size);
4096 bindGenericTransformFeedbackBuffer(buffer);
4097 break;
4098 case GL_UNIFORM_BUFFER:
4099 bindIndexedUniformBuffer(buffer, index, offset, size);
4100 bindGenericUniformBuffer(buffer);
4101 break;
4102 case GL_ATOMIC_COUNTER_BUFFER:
4103 bindIndexedAtomicCounterBuffer(buffer, index, offset, size);
4104 bindGenericAtomicCounterBuffer(buffer);
4105 break;
4106 case GL_SHADER_STORAGE_BUFFER:
Jiajia Qinf546e7d2017-03-27 14:12:59 +08004107 bindIndexedShaderStorageBuffer(buffer, index, offset, size);
4108 bindGenericShaderStorageBuffer(buffer);
Jiajia Qin6eafb042016-12-27 17:04:07 +08004109 break;
4110 default:
4111 UNREACHABLE();
4112 break;
4113 }
4114}
4115
Jamie Madill01a80ee2016-11-07 12:06:18 -05004116void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
4117{
4118 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4119 {
4120 bindReadFramebuffer(framebuffer);
4121 }
4122
4123 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4124 {
4125 bindDrawFramebuffer(framebuffer);
4126 }
4127}
4128
4129void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4130{
4131 ASSERT(target == GL_RENDERBUFFER);
4132 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004133 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04004134 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004135}
4136
JiangYizhoubddc46b2016-12-09 09:50:51 +08004137void Context::texStorage2DMultisample(GLenum target,
4138 GLsizei samples,
4139 GLenum internalformat,
4140 GLsizei width,
4141 GLsizei height,
4142 GLboolean fixedsamplelocations)
4143{
4144 Extents size(width, height, 1);
4145 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05004146 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
JiangYizhoubddc46b2016-12-09 09:50:51 +08004147 fixedsamplelocations));
4148}
4149
4150void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4151{
Jamie Madilldd43e6c2017-03-24 14:18:49 -04004152 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
JiangYizhoubddc46b2016-12-09 09:50:51 +08004153 const Framebuffer *framebuffer = mGLState.getReadFramebuffer();
4154
4155 switch (pname)
4156 {
4157 case GL_SAMPLE_POSITION:
4158 handleError(framebuffer->getSamplePosition(index, val));
4159 break;
4160 default:
4161 UNREACHABLE();
4162 }
4163}
4164
Jamie Madille8fb6402017-02-14 17:56:40 -05004165void Context::renderbufferStorage(GLenum target,
4166 GLenum internalformat,
4167 GLsizei width,
4168 GLsizei height)
4169{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004170 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4171 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
4172
Jamie Madille8fb6402017-02-14 17:56:40 -05004173 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04004174 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004175}
4176
4177void Context::renderbufferStorageMultisample(GLenum target,
4178 GLsizei samples,
4179 GLenum internalformat,
4180 GLsizei width,
4181 GLsizei height)
4182{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004183 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4184 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05004185
4186 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004187 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04004188 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004189}
4190
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004191void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
4192{
4193 const FenceSync *syncObject = getFenceSync(sync);
Geoff Lang82483b92017-04-11 15:33:00 -04004194 handleError(QuerySynciv(syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004195}
4196
JiangYizhoue18e6392017-02-20 10:32:23 +08004197void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
4198{
4199 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4200 QueryFramebufferParameteriv(framebuffer, pname, params);
4201}
4202
4203void Context::setFramebufferParameteri(GLenum target, GLenum pname, GLint param)
4204{
4205 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4206 SetFramebufferParameteri(framebuffer, pname, param);
4207}
4208
Jamie Madillb3f26b92017-07-19 15:07:41 -04004209Error Context::getScratchBuffer(size_t requstedSizeBytes,
4210 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05004211{
Jamie Madillb3f26b92017-07-19 15:07:41 -04004212 if (!mScratchBuffer.get(requstedSizeBytes, scratchBufferOut))
4213 {
4214 return OutOfMemory() << "Failed to allocate internal buffer.";
4215 }
4216 return NoError();
4217}
4218
4219Error Context::getZeroFilledBuffer(size_t requstedSizeBytes,
4220 angle::MemoryBuffer **zeroBufferOut) const
4221{
4222 if (!mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0))
Jamie Madille14951e2017-03-09 18:55:16 -05004223 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004224 return OutOfMemory() << "Failed to allocate internal buffer.";
Jamie Madille14951e2017-03-09 18:55:16 -05004225 }
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004226 return NoError();
Jamie Madille14951e2017-03-09 18:55:16 -05004227}
4228
Xinghua Cao2b396592017-03-29 15:36:04 +08004229void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
4230{
4231 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
4232 {
4233 return;
4234 }
4235
Jamie Madillfe548342017-06-19 11:13:24 -04004236 mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ);
Xinghua Cao2b396592017-03-29 15:36:04 +08004237}
4238
JiangYizhou165361c2017-06-07 14:56:57 +08004239void Context::texStorage2D(GLenum target,
4240 GLsizei levels,
4241 GLenum internalFormat,
4242 GLsizei width,
4243 GLsizei height)
4244{
4245 Extents size(width, height, 1);
4246 Texture *texture = getTargetTexture(target);
4247 handleError(texture->setStorage(this, target, levels, internalFormat, size));
4248}
4249
4250void Context::texStorage3D(GLenum target,
4251 GLsizei levels,
4252 GLenum internalFormat,
4253 GLsizei width,
4254 GLsizei height,
4255 GLsizei depth)
4256{
4257 Extents size(width, height, depth);
4258 Texture *texture = getTargetTexture(target);
4259 handleError(texture->setStorage(this, target, levels, internalFormat, size));
4260}
4261
Jamie Madillc1d770e2017-04-13 17:31:24 -04004262GLenum Context::checkFramebufferStatus(GLenum target)
4263{
4264 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4265 ASSERT(framebuffer);
4266
4267 return framebuffer->checkStatus(this);
4268}
4269
4270void Context::compileShader(GLuint shader)
4271{
4272 Shader *shaderObject = GetValidShader(this, shader);
4273 if (!shaderObject)
4274 {
4275 return;
4276 }
4277 shaderObject->compile(this);
4278}
4279
4280void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
4281{
4282 for (int i = 0; i < n; i++)
4283 {
4284 deleteBuffer(buffers[i]);
4285 }
4286}
4287
4288void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
4289{
4290 for (int i = 0; i < n; i++)
4291 {
4292 if (framebuffers[i] != 0)
4293 {
4294 deleteFramebuffer(framebuffers[i]);
4295 }
4296 }
4297}
4298
4299void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
4300{
4301 for (int i = 0; i < n; i++)
4302 {
4303 deleteRenderbuffer(renderbuffers[i]);
4304 }
4305}
4306
4307void Context::deleteTextures(GLsizei n, const GLuint *textures)
4308{
4309 for (int i = 0; i < n; i++)
4310 {
4311 if (textures[i] != 0)
4312 {
4313 deleteTexture(textures[i]);
4314 }
4315 }
4316}
4317
4318void Context::detachShader(GLuint program, GLuint shader)
4319{
4320 Program *programObject = getProgram(program);
4321 ASSERT(programObject);
4322
4323 Shader *shaderObject = getShader(shader);
4324 ASSERT(shaderObject);
4325
4326 programObject->detachShader(this, shaderObject);
4327}
4328
4329void Context::genBuffers(GLsizei n, GLuint *buffers)
4330{
4331 for (int i = 0; i < n; i++)
4332 {
4333 buffers[i] = createBuffer();
4334 }
4335}
4336
4337void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
4338{
4339 for (int i = 0; i < n; i++)
4340 {
4341 framebuffers[i] = createFramebuffer();
4342 }
4343}
4344
4345void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
4346{
4347 for (int i = 0; i < n; i++)
4348 {
4349 renderbuffers[i] = createRenderbuffer();
4350 }
4351}
4352
4353void Context::genTextures(GLsizei n, GLuint *textures)
4354{
4355 for (int i = 0; i < n; i++)
4356 {
4357 textures[i] = createTexture();
4358 }
4359}
4360
4361void Context::getActiveAttrib(GLuint program,
4362 GLuint index,
4363 GLsizei bufsize,
4364 GLsizei *length,
4365 GLint *size,
4366 GLenum *type,
4367 GLchar *name)
4368{
4369 Program *programObject = getProgram(program);
4370 ASSERT(programObject);
4371 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
4372}
4373
4374void Context::getActiveUniform(GLuint program,
4375 GLuint index,
4376 GLsizei bufsize,
4377 GLsizei *length,
4378 GLint *size,
4379 GLenum *type,
4380 GLchar *name)
4381{
4382 Program *programObject = getProgram(program);
4383 ASSERT(programObject);
4384 programObject->getActiveUniform(index, bufsize, length, size, type, name);
4385}
4386
4387void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
4388{
4389 Program *programObject = getProgram(program);
4390 ASSERT(programObject);
4391 programObject->getAttachedShaders(maxcount, count, shaders);
4392}
4393
4394GLint Context::getAttribLocation(GLuint program, const GLchar *name)
4395{
4396 Program *programObject = getProgram(program);
4397 ASSERT(programObject);
4398 return programObject->getAttributeLocation(name);
4399}
4400
4401void Context::getBooleanv(GLenum pname, GLboolean *params)
4402{
4403 GLenum nativeType;
4404 unsigned int numParams = 0;
4405 getQueryParameterInfo(pname, &nativeType, &numParams);
4406
4407 if (nativeType == GL_BOOL)
4408 {
4409 getBooleanvImpl(pname, params);
4410 }
4411 else
4412 {
4413 CastStateValues(this, nativeType, pname, numParams, params);
4414 }
4415}
4416
4417void Context::getFloatv(GLenum pname, GLfloat *params)
4418{
4419 GLenum nativeType;
4420 unsigned int numParams = 0;
4421 getQueryParameterInfo(pname, &nativeType, &numParams);
4422
4423 if (nativeType == GL_FLOAT)
4424 {
4425 getFloatvImpl(pname, params);
4426 }
4427 else
4428 {
4429 CastStateValues(this, nativeType, pname, numParams, params);
4430 }
4431}
4432
4433void Context::getIntegerv(GLenum pname, GLint *params)
4434{
4435 GLenum nativeType;
4436 unsigned int numParams = 0;
4437 getQueryParameterInfo(pname, &nativeType, &numParams);
4438
4439 if (nativeType == GL_INT)
4440 {
4441 getIntegervImpl(pname, params);
4442 }
4443 else
4444 {
4445 CastStateValues(this, nativeType, pname, numParams, params);
4446 }
4447}
4448
4449void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
4450{
4451 Program *programObject = getProgram(program);
4452 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04004453 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004454}
4455
Jamie Madillbe849e42017-05-02 15:49:00 -04004456void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04004457{
4458 Program *programObject = getProgram(program);
4459 ASSERT(programObject);
4460 programObject->getInfoLog(bufsize, length, infolog);
4461}
4462
4463void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
4464{
4465 Shader *shaderObject = getShader(shader);
4466 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004467 QueryShaderiv(this, shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004468}
4469
4470void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
4471{
4472 Shader *shaderObject = getShader(shader);
4473 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004474 shaderObject->getInfoLog(this, bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004475}
4476
4477void Context::getShaderPrecisionFormat(GLenum shadertype,
4478 GLenum precisiontype,
4479 GLint *range,
4480 GLint *precision)
4481{
4482 // TODO(jmadill): Compute shaders.
4483
4484 switch (shadertype)
4485 {
4486 case GL_VERTEX_SHADER:
4487 switch (precisiontype)
4488 {
4489 case GL_LOW_FLOAT:
4490 mCaps.vertexLowpFloat.get(range, precision);
4491 break;
4492 case GL_MEDIUM_FLOAT:
4493 mCaps.vertexMediumpFloat.get(range, precision);
4494 break;
4495 case GL_HIGH_FLOAT:
4496 mCaps.vertexHighpFloat.get(range, precision);
4497 break;
4498
4499 case GL_LOW_INT:
4500 mCaps.vertexLowpInt.get(range, precision);
4501 break;
4502 case GL_MEDIUM_INT:
4503 mCaps.vertexMediumpInt.get(range, precision);
4504 break;
4505 case GL_HIGH_INT:
4506 mCaps.vertexHighpInt.get(range, precision);
4507 break;
4508
4509 default:
4510 UNREACHABLE();
4511 return;
4512 }
4513 break;
4514
4515 case GL_FRAGMENT_SHADER:
4516 switch (precisiontype)
4517 {
4518 case GL_LOW_FLOAT:
4519 mCaps.fragmentLowpFloat.get(range, precision);
4520 break;
4521 case GL_MEDIUM_FLOAT:
4522 mCaps.fragmentMediumpFloat.get(range, precision);
4523 break;
4524 case GL_HIGH_FLOAT:
4525 mCaps.fragmentHighpFloat.get(range, precision);
4526 break;
4527
4528 case GL_LOW_INT:
4529 mCaps.fragmentLowpInt.get(range, precision);
4530 break;
4531 case GL_MEDIUM_INT:
4532 mCaps.fragmentMediumpInt.get(range, precision);
4533 break;
4534 case GL_HIGH_INT:
4535 mCaps.fragmentHighpInt.get(range, precision);
4536 break;
4537
4538 default:
4539 UNREACHABLE();
4540 return;
4541 }
4542 break;
4543
4544 default:
4545 UNREACHABLE();
4546 return;
4547 }
4548}
4549
4550void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
4551{
4552 Shader *shaderObject = getShader(shader);
4553 ASSERT(shaderObject);
4554 shaderObject->getSource(bufsize, length, source);
4555}
4556
4557void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
4558{
4559 Program *programObject = getProgram(program);
4560 ASSERT(programObject);
4561 programObject->getUniformfv(location, params);
4562}
4563
4564void Context::getUniformiv(GLuint program, GLint location, GLint *params)
4565{
4566 Program *programObject = getProgram(program);
4567 ASSERT(programObject);
4568 programObject->getUniformiv(location, params);
4569}
4570
4571GLint Context::getUniformLocation(GLuint program, const GLchar *name)
4572{
4573 Program *programObject = getProgram(program);
4574 ASSERT(programObject);
4575 return programObject->getUniformLocation(name);
4576}
4577
4578GLboolean Context::isBuffer(GLuint buffer)
4579{
4580 if (buffer == 0)
4581 {
4582 return GL_FALSE;
4583 }
4584
4585 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
4586}
4587
4588GLboolean Context::isEnabled(GLenum cap)
4589{
4590 return mGLState.getEnableFeature(cap);
4591}
4592
4593GLboolean Context::isFramebuffer(GLuint framebuffer)
4594{
4595 if (framebuffer == 0)
4596 {
4597 return GL_FALSE;
4598 }
4599
4600 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
4601}
4602
4603GLboolean Context::isProgram(GLuint program)
4604{
4605 if (program == 0)
4606 {
4607 return GL_FALSE;
4608 }
4609
4610 return (getProgram(program) ? GL_TRUE : GL_FALSE);
4611}
4612
4613GLboolean Context::isRenderbuffer(GLuint renderbuffer)
4614{
4615 if (renderbuffer == 0)
4616 {
4617 return GL_FALSE;
4618 }
4619
4620 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
4621}
4622
4623GLboolean Context::isShader(GLuint shader)
4624{
4625 if (shader == 0)
4626 {
4627 return GL_FALSE;
4628 }
4629
4630 return (getShader(shader) ? GL_TRUE : GL_FALSE);
4631}
4632
4633GLboolean Context::isTexture(GLuint texture)
4634{
4635 if (texture == 0)
4636 {
4637 return GL_FALSE;
4638 }
4639
4640 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
4641}
4642
4643void Context::linkProgram(GLuint program)
4644{
4645 Program *programObject = getProgram(program);
4646 ASSERT(programObject);
4647 handleError(programObject->link(this));
Jamie Madilla779b612017-07-24 11:46:05 -04004648 mGLState.onProgramExecutableChange(programObject);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004649}
4650
4651void Context::releaseShaderCompiler()
4652{
Jamie Madill4928b7c2017-06-20 12:57:39 -04004653 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004654}
4655
4656void Context::shaderBinary(GLsizei n,
4657 const GLuint *shaders,
4658 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04004659 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04004660 GLsizei length)
4661{
4662 // No binary shader formats are supported.
4663 UNIMPLEMENTED();
4664}
4665
4666void Context::shaderSource(GLuint shader,
4667 GLsizei count,
4668 const GLchar *const *string,
4669 const GLint *length)
4670{
4671 Shader *shaderObject = getShader(shader);
4672 ASSERT(shaderObject);
4673 shaderObject->setSource(count, string, length);
4674}
4675
4676void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
4677{
4678 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
4679}
4680
4681void Context::stencilMask(GLuint mask)
4682{
4683 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
4684}
4685
4686void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
4687{
4688 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
4689}
4690
4691void Context::uniform1f(GLint location, GLfloat x)
4692{
4693 Program *program = mGLState.getProgram();
4694 program->setUniform1fv(location, 1, &x);
4695}
4696
4697void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
4698{
4699 Program *program = mGLState.getProgram();
4700 program->setUniform1fv(location, count, v);
4701}
4702
4703void Context::uniform1i(GLint location, GLint x)
4704{
4705 Program *program = mGLState.getProgram();
4706 program->setUniform1iv(location, 1, &x);
4707}
4708
4709void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
4710{
4711 Program *program = mGLState.getProgram();
4712 program->setUniform1iv(location, count, v);
4713}
4714
4715void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
4716{
4717 GLfloat xy[2] = {x, y};
4718 Program *program = mGLState.getProgram();
4719 program->setUniform2fv(location, 1, xy);
4720}
4721
4722void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
4723{
4724 Program *program = mGLState.getProgram();
4725 program->setUniform2fv(location, count, v);
4726}
4727
4728void Context::uniform2i(GLint location, GLint x, GLint y)
4729{
4730 GLint xy[2] = {x, y};
4731 Program *program = mGLState.getProgram();
4732 program->setUniform2iv(location, 1, xy);
4733}
4734
4735void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
4736{
4737 Program *program = mGLState.getProgram();
4738 program->setUniform2iv(location, count, v);
4739}
4740
4741void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
4742{
4743 GLfloat xyz[3] = {x, y, z};
4744 Program *program = mGLState.getProgram();
4745 program->setUniform3fv(location, 1, xyz);
4746}
4747
4748void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
4749{
4750 Program *program = mGLState.getProgram();
4751 program->setUniform3fv(location, count, v);
4752}
4753
4754void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
4755{
4756 GLint xyz[3] = {x, y, z};
4757 Program *program = mGLState.getProgram();
4758 program->setUniform3iv(location, 1, xyz);
4759}
4760
4761void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
4762{
4763 Program *program = mGLState.getProgram();
4764 program->setUniform3iv(location, count, v);
4765}
4766
4767void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4768{
4769 GLfloat xyzw[4] = {x, y, z, w};
4770 Program *program = mGLState.getProgram();
4771 program->setUniform4fv(location, 1, xyzw);
4772}
4773
4774void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
4775{
4776 Program *program = mGLState.getProgram();
4777 program->setUniform4fv(location, count, v);
4778}
4779
4780void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
4781{
4782 GLint xyzw[4] = {x, y, z, w};
4783 Program *program = mGLState.getProgram();
4784 program->setUniform4iv(location, 1, xyzw);
4785}
4786
4787void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
4788{
4789 Program *program = mGLState.getProgram();
4790 program->setUniform4iv(location, count, v);
4791}
4792
4793void Context::uniformMatrix2fv(GLint location,
4794 GLsizei count,
4795 GLboolean transpose,
4796 const GLfloat *value)
4797{
4798 Program *program = mGLState.getProgram();
4799 program->setUniformMatrix2fv(location, count, transpose, value);
4800}
4801
4802void Context::uniformMatrix3fv(GLint location,
4803 GLsizei count,
4804 GLboolean transpose,
4805 const GLfloat *value)
4806{
4807 Program *program = mGLState.getProgram();
4808 program->setUniformMatrix3fv(location, count, transpose, value);
4809}
4810
4811void Context::uniformMatrix4fv(GLint location,
4812 GLsizei count,
4813 GLboolean transpose,
4814 const GLfloat *value)
4815{
4816 Program *program = mGLState.getProgram();
4817 program->setUniformMatrix4fv(location, count, transpose, value);
4818}
4819
4820void Context::validateProgram(GLuint program)
4821{
4822 Program *programObject = getProgram(program);
4823 ASSERT(programObject);
4824 programObject->validate(mCaps);
4825}
4826
Jamie Madilld04908b2017-06-09 14:15:35 -04004827void Context::getProgramBinary(GLuint program,
4828 GLsizei bufSize,
4829 GLsizei *length,
4830 GLenum *binaryFormat,
4831 void *binary)
4832{
4833 Program *programObject = getProgram(program);
4834 ASSERT(programObject != nullptr);
4835
4836 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
4837}
4838
4839void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
4840{
4841 Program *programObject = getProgram(program);
4842 ASSERT(programObject != nullptr);
Jamie Madilld04908b2017-06-09 14:15:35 -04004843 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
Jamie Madilla779b612017-07-24 11:46:05 -04004844 mGLState.onProgramExecutableChange(programObject);
Jamie Madilld04908b2017-06-09 14:15:35 -04004845}
4846
Jamie Madillc29968b2016-01-20 11:17:23 -05004847} // namespace gl