blob: c4a132b70a997aed0bd0e202ae22d5ddf7f05b26 [file] [log] [blame]
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001//
Geoff Langeeba6e12014-02-03 13:12:30 -05002// Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7// Context.cpp: Implements the gl::Context class, managing all GL state and performing
8// rendering operations. It is the GLES2 specific implementation of EGLContext.
9
Geoff Lang2b5420c2014-11-19 14:20:15 -050010#include "libANGLE/Context.h"
apatrick@chromium.org144f2802012-07-12 01:42:34 +000011
Jamie Madill231c7f52017-04-26 13:45:37 -040012#include <string.h>
Jamie Madillb9293972015-02-19 11:07:54 -050013#include <iterator>
14#include <sstream>
Sami Väisänend59ca052016-06-21 16:10:00 +030015#include <vector>
Jamie Madillb9293972015-02-19 11:07:54 -050016
Sami Väisänene45e53b2016-05-25 10:36:04 +030017#include "common/matrix_utils.h"
Geoff Lang0b7eef72014-06-12 14:10:47 -040018#include "common/platform.h"
Jamie Madillb9293972015-02-19 11:07:54 -050019#include "common/utilities.h"
Geoff Langc339c4e2016-11-29 10:37:36 -050020#include "common/version.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050021#include "libANGLE/Buffer.h"
Jamie Madillb9293972015-02-19 11:07:54 -050022#include "libANGLE/Compiler.h"
Jamie Madill948bbe52017-06-01 13:10:42 -040023#include "libANGLE/Display.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050024#include "libANGLE/Fence.h"
25#include "libANGLE/Framebuffer.h"
26#include "libANGLE/FramebufferAttachment.h"
Sami Väisänene45e53b2016-05-25 10:36:04 +030027#include "libANGLE/Path.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050028#include "libANGLE/Program.h"
Yunchao Hea336b902017-08-02 16:05:21 +080029#include "libANGLE/ProgramPipeline.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050030#include "libANGLE/Query.h"
Jamie Madillb9293972015-02-19 11:07:54 -050031#include "libANGLE/Renderbuffer.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050032#include "libANGLE/ResourceManager.h"
33#include "libANGLE/Sampler.h"
Jamie Madill9dd0cf02014-11-24 11:38:51 -050034#include "libANGLE/Surface.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050035#include "libANGLE/Texture.h"
36#include "libANGLE/TransformFeedback.h"
37#include "libANGLE/VertexArray.h"
Kenneth Russellf2f6f652016-10-05 19:53:23 -070038#include "libANGLE/Workarounds.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040039#include "libANGLE/formatutils.h"
Martin Radev66fb8202016-07-28 11:45:20 +030040#include "libANGLE/queryconversions.h"
Geoff Langc1984ed2016-10-07 12:41:00 -040041#include "libANGLE/queryutils.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040042#include "libANGLE/renderer/ContextImpl.h"
43#include "libANGLE/renderer/EGLImplFactory.h"
44#include "libANGLE/validationES.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000045
Geoff Langf6db0982015-08-25 13:04:00 -040046namespace
47{
48
Jamie Madillb6664922017-07-25 12:55:04 -040049#define ANGLE_HANDLE_ERR(X) \
50 handleError(X); \
51 return;
52#define ANGLE_CONTEXT_TRY(EXPR) ANGLE_TRY_TEMPLATE(EXPR, ANGLE_HANDLE_ERR);
53
Ian Ewell3ffd78b2016-01-22 16:09:42 -050054template <typename T>
Geoff Lang4ddf5af2016-12-01 14:30:44 -050055std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager,
Sami Väisänend59ca052016-06-21 16:10:00 +030056 GLsizei numPaths,
57 const void *paths,
58 GLuint pathBase)
59{
60 std::vector<gl::Path *> ret;
61 ret.reserve(numPaths);
62
63 const auto *nameArray = static_cast<const T *>(paths);
64
65 for (GLsizei i = 0; i < numPaths; ++i)
66 {
67 const GLuint pathName = nameArray[i] + pathBase;
68
69 ret.push_back(resourceManager.getPath(pathName));
70 }
71
72 return ret;
73}
74
Geoff Lang4ddf5af2016-12-01 14:30:44 -050075std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager,
Sami Väisänend59ca052016-06-21 16:10:00 +030076 GLsizei numPaths,
77 GLenum pathNameType,
78 const void *paths,
79 GLuint pathBase)
80{
81 switch (pathNameType)
82 {
83 case GL_UNSIGNED_BYTE:
84 return GatherPaths<GLubyte>(resourceManager, numPaths, paths, pathBase);
85
86 case GL_BYTE:
87 return GatherPaths<GLbyte>(resourceManager, numPaths, paths, pathBase);
88
89 case GL_UNSIGNED_SHORT:
90 return GatherPaths<GLushort>(resourceManager, numPaths, paths, pathBase);
91
92 case GL_SHORT:
93 return GatherPaths<GLshort>(resourceManager, numPaths, paths, pathBase);
94
95 case GL_UNSIGNED_INT:
96 return GatherPaths<GLuint>(resourceManager, numPaths, paths, pathBase);
97
98 case GL_INT:
99 return GatherPaths<GLint>(resourceManager, numPaths, paths, pathBase);
100 }
101
102 UNREACHABLE();
103 return std::vector<gl::Path *>();
104}
105
106template <typename T>
Geoff Lang2186c382016-10-14 10:54:54 -0400107gl::Error GetQueryObjectParameter(gl::Query *query, GLenum pname, T *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500108{
Geoff Lang2186c382016-10-14 10:54:54 -0400109 ASSERT(query != nullptr);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500110
111 switch (pname)
112 {
113 case GL_QUERY_RESULT_EXT:
Geoff Lang2186c382016-10-14 10:54:54 -0400114 return query->getResult(params);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500115 case GL_QUERY_RESULT_AVAILABLE_EXT:
116 {
117 bool available;
Geoff Lang2186c382016-10-14 10:54:54 -0400118 gl::Error error = query->isResultAvailable(&available);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500119 if (!error.isError())
120 {
jchen10a99ed552017-09-22 08:10:32 +0800121 *params = gl::CastFromStateValue<T>(pname, static_cast<GLuint>(available));
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500122 }
123 return error;
124 }
125 default:
126 UNREACHABLE();
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500127 return gl::InternalError() << "Unreachable Error";
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500128 }
129}
130
Geoff Langf6db0982015-08-25 13:04:00 -0400131void MarkTransformFeedbackBufferUsage(gl::TransformFeedback *transformFeedback)
132{
Geoff Lang1a683462015-09-29 15:09:59 -0400133 if (transformFeedback && transformFeedback->isActive() && !transformFeedback->isPaused())
Geoff Langf6db0982015-08-25 13:04:00 -0400134 {
135 for (size_t tfBufferIndex = 0; tfBufferIndex < transformFeedback->getIndexedBufferCount();
136 tfBufferIndex++)
137 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400138 const gl::OffsetBindingPointer<gl::Buffer> &buffer =
Geoff Langf6db0982015-08-25 13:04:00 -0400139 transformFeedback->getIndexedBuffer(tfBufferIndex);
140 if (buffer.get() != nullptr)
141 {
142 buffer->onTransformFeedback();
143 }
144 }
145 }
146}
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500147
148// Attribute map queries.
Martin Radev1be913c2016-07-11 17:59:16 +0300149EGLint GetClientMajorVersion(const egl::AttributeMap &attribs)
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500150{
Ian Ewellec2c0c52016-04-05 13:46:26 -0400151 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_CLIENT_VERSION, 1));
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500152}
153
Martin Radev1be913c2016-07-11 17:59:16 +0300154EGLint GetClientMinorVersion(const egl::AttributeMap &attribs)
155{
156 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_MINOR_VERSION, 0));
157}
158
Geoff Langeb66a6e2016-10-31 13:06:12 -0400159gl::Version GetClientVersion(const egl::AttributeMap &attribs)
160{
161 return gl::Version(GetClientMajorVersion(attribs), GetClientMinorVersion(attribs));
162}
163
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500164GLenum GetResetStrategy(const egl::AttributeMap &attribs)
165{
Ian Ewellec2c0c52016-04-05 13:46:26 -0400166 EGLAttrib attrib = attribs.get(EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT,
167 EGL_NO_RESET_NOTIFICATION_EXT);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500168 switch (attrib)
169 {
170 case EGL_NO_RESET_NOTIFICATION:
171 return GL_NO_RESET_NOTIFICATION_EXT;
172 case EGL_LOSE_CONTEXT_ON_RESET:
173 return GL_LOSE_CONTEXT_ON_RESET_EXT;
174 default:
175 UNREACHABLE();
176 return GL_NONE;
177 }
178}
179
180bool GetRobustAccess(const egl::AttributeMap &attribs)
181{
Geoff Lang077f20a2016-11-01 10:08:02 -0400182 return (attribs.get(EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT, EGL_FALSE) == EGL_TRUE) ||
183 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR) !=
184 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500185}
186
187bool GetDebug(const egl::AttributeMap &attribs)
188{
Geoff Lang077f20a2016-11-01 10:08:02 -0400189 return (attribs.get(EGL_CONTEXT_OPENGL_DEBUG, EGL_FALSE) == EGL_TRUE) ||
190 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR) != 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500191}
192
193bool GetNoError(const egl::AttributeMap &attribs)
194{
195 return (attribs.get(EGL_CONTEXT_OPENGL_NO_ERROR_KHR, EGL_FALSE) == EGL_TRUE);
196}
197
Geoff Langc287ea62016-09-16 14:46:51 -0400198bool GetWebGLContext(const egl::AttributeMap &attribs)
199{
200 return (attribs.get(EGL_CONTEXT_WEBGL_COMPATIBILITY_ANGLE, EGL_FALSE) == EGL_TRUE);
201}
202
Geoff Langf41a7152016-09-19 15:11:17 -0400203bool GetBindGeneratesResource(const egl::AttributeMap &attribs)
204{
205 return (attribs.get(EGL_CONTEXT_BIND_GENERATES_RESOURCE_CHROMIUM, EGL_TRUE) == EGL_TRUE);
206}
207
Geoff Langfeb8c682017-02-13 16:07:35 -0500208bool GetClientArraysEnabled(const egl::AttributeMap &attribs)
209{
210 return (attribs.get(EGL_CONTEXT_CLIENT_ARRAYS_ENABLED_ANGLE, EGL_TRUE) == EGL_TRUE);
211}
212
Geoff Langb433e872017-10-05 14:01:47 -0400213bool GetRobustResourceInit(const egl::AttributeMap &attribs)
214{
215 return (attribs.get(EGL_ROBUST_RESOURCE_INITIALIZATION_ANGLE, EGL_FALSE) == EGL_TRUE);
216}
217
Martin Radev9d901792016-07-15 15:58:58 +0300218std::string GetObjectLabelFromPointer(GLsizei length, const GLchar *label)
219{
220 std::string labelName;
221 if (label != nullptr)
222 {
223 size_t labelLength = length < 0 ? strlen(label) : length;
224 labelName = std::string(label, labelLength);
225 }
226 return labelName;
227}
228
229void GetObjectLabelBase(const std::string &objectLabel,
230 GLsizei bufSize,
231 GLsizei *length,
232 GLchar *label)
233{
234 size_t writeLength = objectLabel.length();
235 if (label != nullptr && bufSize > 0)
236 {
237 writeLength = std::min(static_cast<size_t>(bufSize) - 1, objectLabel.length());
238 std::copy(objectLabel.begin(), objectLabel.begin() + writeLength, label);
239 label[writeLength] = '\0';
240 }
241
242 if (length != nullptr)
243 {
244 *length = static_cast<GLsizei>(writeLength);
245 }
246}
247
Jamie Madill0f80ed82017-09-19 00:24:56 -0400248template <typename CapT, typename MaxT>
249void LimitCap(CapT *cap, MaxT maximum)
250{
251 *cap = std::min(*cap, static_cast<CapT>(maximum));
252}
253
Geoff Langf6db0982015-08-25 13:04:00 -0400254} // anonymous namespace
255
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000256namespace gl
257{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +0000258
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400259Context::Context(rx::EGLImplFactory *implFactory,
260 const egl::Config *config,
Corentin Wallez51706ea2015-08-07 14:39:22 -0400261 const Context *shareContext,
Geoff Langce02f082017-02-06 16:46:21 -0500262 TextureManager *shareTextures,
Jamie Madill32447362017-06-28 14:53:52 -0400263 MemoryProgramCache *memoryProgramCache,
Corentin Wallezc295e512017-01-27 17:47:50 -0500264 const egl::AttributeMap &attribs,
Geoff Langb433e872017-10-05 14:01:47 -0400265 const egl::DisplayExtensions &displayExtensions)
Martin Radev1be913c2016-07-11 17:59:16 +0300266
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500267 : ValidationContext(shareContext,
Geoff Langce02f082017-02-06 16:46:21 -0500268 shareTextures,
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500269 GetClientVersion(attribs),
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700270 &mGLState,
Jamie Madillf25855c2015-11-03 11:06:18 -0500271 mCaps,
272 mTextureCaps,
273 mExtensions,
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500274 mLimitations,
275 GetNoError(attribs)),
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700276 mImplementation(implFactory->createContext(mState)),
Jamie Madill2f348d22017-06-05 10:50:59 -0400277 mCompiler(),
Corentin Walleze3b10e82015-05-20 11:06:25 -0400278 mConfig(config),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500279 mClientType(EGL_OPENGL_ES_API),
280 mHasBeenCurrent(false),
281 mContextLost(false),
282 mResetStatus(GL_NO_ERROR),
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700283 mContextLostForced(false),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500284 mResetStrategy(GetResetStrategy(attribs)),
285 mRobustAccess(GetRobustAccess(attribs)),
Jamie Madill61e16b42017-06-19 11:13:23 -0400286 mCurrentSurface(static_cast<egl::Surface *>(EGL_NO_SURFACE)),
287 mCurrentDisplay(static_cast<egl::Display *>(EGL_NO_DISPLAY)),
Jamie Madill4e0e6f82017-02-17 11:06:03 -0500288 mSurfacelessFramebuffer(nullptr),
Jamie Madille14951e2017-03-09 18:55:16 -0500289 mWebGLContext(GetWebGLContext(attribs)),
Jamie Madill32447362017-06-28 14:53:52 -0400290 mMemoryProgramCache(memoryProgramCache),
Jamie Madillb3f26b92017-07-19 15:07:41 -0400291 mScratchBuffer(1000u),
292 mZeroFilledBuffer(1000u)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000293{
Jamie Madill14bbb3f2017-09-12 15:23:01 -0400294 mImplementation->setMemoryProgramCache(memoryProgramCache);
295
Geoff Langb433e872017-10-05 14:01:47 -0400296 bool robustResourceInit = GetRobustResourceInit(attribs);
297 initCaps(displayExtensions, robustResourceInit);
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700298 initWorkarounds();
Geoff Langc0b9ef42014-07-02 10:02:37 -0400299
Jamie Madill4928b7c2017-06-20 12:57:39 -0400300 mGLState.initialize(this, GetDebug(attribs), GetBindGeneratesResource(attribs),
Jamie Madillc43be722017-07-13 16:22:14 -0400301 GetClientArraysEnabled(attribs), robustResourceInit,
302 mMemoryProgramCache != nullptr);
Régis Fénéon83107972015-02-05 12:57:44 +0100303
Shannon Woods53a94a82014-06-24 15:20:36 -0400304 mFenceNVHandleAllocator.setBaseHandle(0);
Geoff Lang7dca1862013-07-30 16:30:46 -0400305
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000306 // [OpenGL ES 2.0.24] section 3.7 page 83:
307 // In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have twodimensional
308 // and cube map texture state vectors respectively associated with them.
309 // In order that access to these initial textures not be lost, they are treated as texture
310 // objects all of whose names are 0.
311
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400312 Texture *zeroTexture2D = new Texture(mImplementation.get(), 0, GL_TEXTURE_2D);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400313 mZeroTextures[GL_TEXTURE_2D].set(this, zeroTexture2D);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500314
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400315 Texture *zeroTextureCube = new Texture(mImplementation.get(), 0, GL_TEXTURE_CUBE_MAP);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400316 mZeroTextures[GL_TEXTURE_CUBE_MAP].set(this, zeroTextureCube);
Geoff Lang76b10c92014-09-05 16:28:14 -0400317
Geoff Langeb66a6e2016-10-31 13:06:12 -0400318 if (getClientVersion() >= Version(3, 0))
Geoff Lang76b10c92014-09-05 16:28:14 -0400319 {
320 // TODO: These could also be enabled via extension
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400321 Texture *zeroTexture3D = new Texture(mImplementation.get(), 0, GL_TEXTURE_3D);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400322 mZeroTextures[GL_TEXTURE_3D].set(this, zeroTexture3D);
Geoff Lang76b10c92014-09-05 16:28:14 -0400323
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400324 Texture *zeroTexture2DArray = new Texture(mImplementation.get(), 0, GL_TEXTURE_2D_ARRAY);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400325 mZeroTextures[GL_TEXTURE_2D_ARRAY].set(this, zeroTexture2DArray);
Geoff Lang76b10c92014-09-05 16:28:14 -0400326 }
Geoff Lang3b573612016-10-31 14:08:10 -0400327 if (getClientVersion() >= Version(3, 1))
328 {
329 Texture *zeroTexture2DMultisample =
330 new Texture(mImplementation.get(), 0, GL_TEXTURE_2D_MULTISAMPLE);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400331 mZeroTextures[GL_TEXTURE_2D_MULTISAMPLE].set(this, zeroTexture2DMultisample);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800332
333 bindGenericAtomicCounterBuffer(0);
334 for (unsigned int i = 0; i < mCaps.maxAtomicCounterBufferBindings; i++)
335 {
336 bindIndexedAtomicCounterBuffer(0, i, 0, 0);
337 }
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800338
339 bindGenericShaderStorageBuffer(0);
340 for (unsigned int i = 0; i < mCaps.maxShaderStorageBufferBindings; i++)
341 {
342 bindIndexedShaderStorageBuffer(0, i, 0, 0);
343 }
Geoff Lang3b573612016-10-31 14:08:10 -0400344 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000345
Geoff Lang4751aab2017-10-30 15:14:52 -0400346 const Extensions &nativeExtensions = mImplementation->getNativeExtensions();
347 if (nativeExtensions.textureRectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400348 {
349 Texture *zeroTextureRectangle =
350 new Texture(mImplementation.get(), 0, GL_TEXTURE_RECTANGLE_ANGLE);
351 mZeroTextures[GL_TEXTURE_RECTANGLE_ANGLE].set(this, zeroTextureRectangle);
352 }
353
Geoff Lang4751aab2017-10-30 15:14:52 -0400354 if (nativeExtensions.eglImageExternal || nativeExtensions.eglStreamConsumerExternal)
Ian Ewellbda75592016-04-18 17:25:54 -0400355 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400356 Texture *zeroTextureExternal =
357 new Texture(mImplementation.get(), 0, GL_TEXTURE_EXTERNAL_OES);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400358 mZeroTextures[GL_TEXTURE_EXTERNAL_OES].set(this, zeroTextureExternal);
Ian Ewellbda75592016-04-18 17:25:54 -0400359 }
360
Jamie Madill4928b7c2017-06-20 12:57:39 -0400361 mGLState.initializeZeroTextures(this, mZeroTextures);
Jamie Madille6382c32014-11-07 15:05:26 -0500362
Jamie Madill57a89722013-07-02 11:57:03 -0400363 bindVertexArray(0);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000364 bindArrayBuffer(0);
Jiajia Qin9d7d0b12016-11-29 16:30:31 +0800365 bindDrawIndirectBuffer(0);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000366 bindElementArrayBuffer(0);
Geoff Lang76b10c92014-09-05 16:28:14 -0400367
Jamie Madill01a80ee2016-11-07 12:06:18 -0500368 bindRenderbuffer(GL_RENDERBUFFER, 0);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000369
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +0000370 bindGenericUniformBuffer(0);
Geoff Lang4dc3af02016-11-18 14:09:27 -0500371 for (unsigned int i = 0; i < mCaps.maxUniformBufferBindings; i++)
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +0000372 {
373 bindIndexedUniformBuffer(0, i, 0, -1);
374 }
375
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000376 bindCopyReadBuffer(0);
377 bindCopyWriteBuffer(0);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +0000378 bindPixelPackBuffer(0);
379 bindPixelUnpackBuffer(0);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000380
Geoff Langeb66a6e2016-10-31 13:06:12 -0400381 if (getClientVersion() >= Version(3, 0))
Geoff Lang1a683462015-09-29 15:09:59 -0400382 {
383 // [OpenGL ES 3.0.2] section 2.14.1 pg 85:
384 // In the initial state, a default transform feedback object is bound and treated as
385 // a transform feedback object with a name of zero. That object is bound any time
386 // BindTransformFeedback is called with id of zero
Jamie Madillf0dcb8b2017-08-26 19:05:13 -0400387 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Geoff Lang1a683462015-09-29 15:09:59 -0400388 }
Geoff Langc8058452014-02-03 12:04:11 -0500389
Jamie Madillad9f24e2016-02-12 09:27:24 -0500390 // Initialize dirty bit masks
391 // TODO(jmadill): additional ES3 state
392 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_ALIGNMENT);
393 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_ROW_LENGTH);
394 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_IMAGE_HEIGHT);
395 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_SKIP_IMAGES);
396 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_SKIP_ROWS);
397 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_SKIP_PIXELS);
Corentin Wallezbbd663a2016-04-20 17:49:17 -0400398 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500399 // No dirty objects.
400
401 // Readpixels uses the pack state and read FBO
402 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_ALIGNMENT);
403 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_REVERSE_ROW_ORDER);
404 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_ROW_LENGTH);
405 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_SKIP_ROWS);
406 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_SKIP_PIXELS);
Corentin Wallezbbd663a2016-04-20 17:49:17 -0400407 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500408 mReadPixelsDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
409
410 mClearDirtyBits.set(State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED);
411 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
412 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR);
413 mClearDirtyBits.set(State::DIRTY_BIT_VIEWPORT);
414 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_COLOR);
415 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_DEPTH);
416 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_STENCIL);
417 mClearDirtyBits.set(State::DIRTY_BIT_COLOR_MASK);
418 mClearDirtyBits.set(State::DIRTY_BIT_DEPTH_MASK);
419 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT);
420 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_BACK);
421 mClearDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
422
423 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
424 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR);
Geoff Lang1d2c41d2016-10-19 16:14:46 -0700425 mBlitDirtyBits.set(State::DIRTY_BIT_FRAMEBUFFER_SRGB);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500426 mBlitDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
427 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
Jamie Madill437fa652016-05-03 15:13:24 -0400428
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400429 handleError(mImplementation->initialize());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000430}
431
Jamie Madill4928b7c2017-06-20 12:57:39 -0400432egl::Error Context::onDestroy(const egl::Display *display)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000433{
Corentin Wallez80b24112015-08-25 16:41:57 -0400434 for (auto fence : mFenceNVMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000435 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400436 SafeDelete(fence.second);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000437 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400438 mFenceNVMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000439
Corentin Wallez80b24112015-08-25 16:41:57 -0400440 for (auto query : mQueryMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000441 {
Geoff Langf0aa8422015-09-29 15:08:34 -0400442 if (query.second != nullptr)
443 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400444 query.second->release(this);
Geoff Langf0aa8422015-09-29 15:08:34 -0400445 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000446 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400447 mQueryMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000448
Corentin Wallez80b24112015-08-25 16:41:57 -0400449 for (auto vertexArray : mVertexArrayMap)
Jamie Madill57a89722013-07-02 11:57:03 -0400450 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400451 if (vertexArray.second)
452 {
453 vertexArray.second->onDestroy(this);
454 }
Jamie Madill57a89722013-07-02 11:57:03 -0400455 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400456 mVertexArrayMap.clear();
Jamie Madill57a89722013-07-02 11:57:03 -0400457
Corentin Wallez80b24112015-08-25 16:41:57 -0400458 for (auto transformFeedback : mTransformFeedbackMap)
Geoff Langc8058452014-02-03 12:04:11 -0500459 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500460 if (transformFeedback.second != nullptr)
461 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500462 transformFeedback.second->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500463 }
Geoff Langc8058452014-02-03 12:04:11 -0500464 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400465 mTransformFeedbackMap.clear();
Geoff Langc8058452014-02-03 12:04:11 -0500466
Jamie Madilldedd7b92014-11-05 16:30:36 -0500467 for (auto &zeroTexture : mZeroTextures)
Geoff Lang76b10c92014-09-05 16:28:14 -0400468 {
Jamie Madill71c88b32017-09-14 22:20:29 -0400469 ANGLE_TRY(zeroTexture.second->onDestroy(this));
Jamie Madill4928b7c2017-06-20 12:57:39 -0400470 zeroTexture.second.set(this, nullptr);
Geoff Lang76b10c92014-09-05 16:28:14 -0400471 }
472 mZeroTextures.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000473
Corentin Wallezccab69d2017-01-27 16:57:15 -0500474 SafeDelete(mSurfacelessFramebuffer);
475
Jamie Madill4928b7c2017-06-20 12:57:39 -0400476 ANGLE_TRY(releaseSurface(display));
Jamie Madill2f348d22017-06-05 10:50:59 -0400477 releaseShaderCompiler();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500478
Jamie Madill4928b7c2017-06-20 12:57:39 -0400479 mGLState.reset(this);
480
Jamie Madill6c1f6712017-02-14 19:08:04 -0500481 mState.mBuffers->release(this);
482 mState.mShaderPrograms->release(this);
483 mState.mTextures->release(this);
484 mState.mRenderbuffers->release(this);
485 mState.mSamplers->release(this);
Jamie Madill70b5bb02017-08-28 13:32:37 -0400486 mState.mSyncs->release(this);
Jamie Madill6c1f6712017-02-14 19:08:04 -0500487 mState.mPaths->release(this);
488 mState.mFramebuffers->release(this);
Yunchao Hea336b902017-08-02 16:05:21 +0800489 mState.mPipelines->release(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400490
Jamie Madill76e471e2017-10-21 09:56:01 -0400491 mImplementation->onDestroy(this);
492
Jamie Madill4928b7c2017-06-20 12:57:39 -0400493 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000494}
495
Jamie Madill70ee0f62017-02-06 16:04:20 -0500496Context::~Context()
497{
498}
499
Jamie Madill4928b7c2017-06-20 12:57:39 -0400500egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000501{
Jamie Madill61e16b42017-06-19 11:13:23 -0400502 mCurrentDisplay = display;
503
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000504 if (!mHasBeenCurrent)
505 {
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000506 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500507 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400508 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000509
Corentin Wallezc295e512017-01-27 17:47:50 -0500510 int width = 0;
511 int height = 0;
512 if (surface != nullptr)
513 {
514 width = surface->getWidth();
515 height = surface->getHeight();
516 }
517
518 mGLState.setViewportParams(0, 0, width, height);
519 mGLState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000520
521 mHasBeenCurrent = true;
522 }
523
Jamie Madill1b94d432015-08-07 13:23:23 -0400524 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700525 mGLState.setAllDirtyBits();
Jamie Madill81c2e252017-09-09 23:32:46 -0400526 mGLState.setAllDirtyObjects();
Jamie Madill1b94d432015-08-07 13:23:23 -0400527
Jamie Madill4928b7c2017-06-20 12:57:39 -0400528 ANGLE_TRY(releaseSurface(display));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500529
530 Framebuffer *newDefault = nullptr;
531 if (surface != nullptr)
532 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400533 ANGLE_TRY(surface->setIsCurrent(this, true));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500534 mCurrentSurface = surface;
535 newDefault = surface->getDefaultFramebuffer();
536 }
537 else
538 {
539 if (mSurfacelessFramebuffer == nullptr)
540 {
541 mSurfacelessFramebuffer = new Framebuffer(mImplementation.get());
542 }
543
544 newDefault = mSurfacelessFramebuffer;
545 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000546
Corentin Wallez37c39792015-08-20 14:19:46 -0400547 // Update default framebuffer, the binding of the previous default
548 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400549 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700550 if (mGLState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400551 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700552 mGLState.setReadFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400553 }
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700554 if (mGLState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400555 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700556 mGLState.setDrawFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400557 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500558 mState.mFramebuffers->setDefaultFramebuffer(newDefault);
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400559 }
Ian Ewell292f0052016-02-04 10:37:32 -0500560
561 // Notify the renderer of a context switch
Jamie Madill4928b7c2017-06-20 12:57:39 -0400562 mImplementation->onMakeCurrent(this);
563 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000564}
565
Jamie Madill4928b7c2017-06-20 12:57:39 -0400566egl::Error Context::releaseSurface(const egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400567{
Corentin Wallez37c39792015-08-20 14:19:46 -0400568 // Remove the default framebuffer
Corentin Wallezc295e512017-01-27 17:47:50 -0500569 Framebuffer *currentDefault = nullptr;
570 if (mCurrentSurface != nullptr)
Corentin Wallez51706ea2015-08-07 14:39:22 -0400571 {
Corentin Wallezc295e512017-01-27 17:47:50 -0500572 currentDefault = mCurrentSurface->getDefaultFramebuffer();
573 }
574 else if (mSurfacelessFramebuffer != nullptr)
575 {
576 currentDefault = mSurfacelessFramebuffer;
Corentin Wallez51706ea2015-08-07 14:39:22 -0400577 }
578
Corentin Wallezc295e512017-01-27 17:47:50 -0500579 if (mGLState.getReadFramebuffer() == currentDefault)
580 {
581 mGLState.setReadFramebufferBinding(nullptr);
582 }
583 if (mGLState.getDrawFramebuffer() == currentDefault)
584 {
585 mGLState.setDrawFramebufferBinding(nullptr);
586 }
587 mState.mFramebuffers->setDefaultFramebuffer(nullptr);
588
589 if (mCurrentSurface)
590 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400591 ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
Corentin Wallezc295e512017-01-27 17:47:50 -0500592 mCurrentSurface = nullptr;
593 }
Jamie Madill4928b7c2017-06-20 12:57:39 -0400594
595 return egl::NoError();
Jamie Madill77a72f62015-04-14 11:18:32 -0400596}
597
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000598GLuint Context::createBuffer()
599{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500600 return mState.mBuffers->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000601}
602
603GLuint Context::createProgram()
604{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500605 return mState.mShaderPrograms->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000606}
607
608GLuint Context::createShader(GLenum type)
609{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500610 return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000611}
612
613GLuint Context::createTexture()
614{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500615 return mState.mTextures->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000616}
617
618GLuint Context::createRenderbuffer()
619{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500620 return mState.mRenderbuffers->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000621}
622
Sami Väisänene45e53b2016-05-25 10:36:04 +0300623GLuint Context::createPaths(GLsizei range)
624{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500625 auto resultOrError = mState.mPaths->createPaths(mImplementation.get(), range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300626 if (resultOrError.isError())
627 {
628 handleError(resultOrError.getError());
629 return 0;
630 }
631 return resultOrError.getResult();
632}
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
Yunchao Hea336b902017-08-02 16:05:21 +0800647GLuint Context::createProgramPipeline()
648{
649 return mState.mPipelines->createProgramPipeline();
650}
651
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000652void Context::deleteBuffer(GLuint buffer)
653{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500654 if (mState.mBuffers->getBuffer(buffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000655 {
656 detachBuffer(buffer);
657 }
Jamie Madill893ab082014-05-16 16:56:10 -0400658
Jamie Madill6c1f6712017-02-14 19:08:04 -0500659 mState.mBuffers->deleteObject(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000660}
661
662void Context::deleteShader(GLuint shader)
663{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500664 mState.mShaderPrograms->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000665}
666
667void Context::deleteProgram(GLuint program)
668{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500669 mState.mShaderPrograms->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000670}
671
672void Context::deleteTexture(GLuint texture)
673{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500674 if (mState.mTextures->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000675 {
676 detachTexture(texture);
677 }
678
Jamie Madill6c1f6712017-02-14 19:08:04 -0500679 mState.mTextures->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000680}
681
682void Context::deleteRenderbuffer(GLuint renderbuffer)
683{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500684 if (mState.mRenderbuffers->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000685 {
686 detachRenderbuffer(renderbuffer);
687 }
Jamie Madill893ab082014-05-16 16:56:10 -0400688
Jamie Madill6c1f6712017-02-14 19:08:04 -0500689 mState.mRenderbuffers->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000690}
691
Jamie Madill7f0c5a42017-08-26 22:43:26 -0400692void Context::deleteSync(GLsync sync)
Jamie Madillcd055f82013-07-26 11:55:15 -0400693{
694 // The spec specifies the underlying Fence object is not deleted until all current
695 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
696 // and since our API is currently designed for being called from a single thread, we can delete
697 // the fence immediately.
Jamie Madill70b5bb02017-08-28 13:32:37 -0400698 mState.mSyncs->deleteObject(this, static_cast<GLuint>(reinterpret_cast<uintptr_t>(sync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400699}
700
Yunchao Hea336b902017-08-02 16:05:21 +0800701void Context::deleteProgramPipeline(GLuint pipeline)
702{
703 if (mState.mPipelines->getProgramPipeline(pipeline))
704 {
705 detachProgramPipeline(pipeline);
706 }
707
708 mState.mPipelines->deleteObject(this, pipeline);
709}
710
Sami Väisänene45e53b2016-05-25 10:36:04 +0300711void Context::deletePaths(GLuint first, GLsizei range)
712{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500713 mState.mPaths->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300714}
715
716bool Context::hasPathData(GLuint path) const
717{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500718 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300719 if (pathObj == nullptr)
720 return false;
721
722 return pathObj->hasPathData();
723}
724
725bool Context::hasPath(GLuint path) const
726{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500727 return mState.mPaths->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300728}
729
730void Context::setPathCommands(GLuint path,
731 GLsizei numCommands,
732 const GLubyte *commands,
733 GLsizei numCoords,
734 GLenum coordType,
735 const void *coords)
736{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500737 auto *pathObject = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300738
739 handleError(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
740}
741
742void Context::setPathParameterf(GLuint path, GLenum pname, GLfloat value)
743{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500744 auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300745
746 switch (pname)
747 {
748 case GL_PATH_STROKE_WIDTH_CHROMIUM:
749 pathObj->setStrokeWidth(value);
750 break;
751 case GL_PATH_END_CAPS_CHROMIUM:
752 pathObj->setEndCaps(static_cast<GLenum>(value));
753 break;
754 case GL_PATH_JOIN_STYLE_CHROMIUM:
755 pathObj->setJoinStyle(static_cast<GLenum>(value));
756 break;
757 case GL_PATH_MITER_LIMIT_CHROMIUM:
758 pathObj->setMiterLimit(value);
759 break;
760 case GL_PATH_STROKE_BOUND_CHROMIUM:
761 pathObj->setStrokeBound(value);
762 break;
763 default:
764 UNREACHABLE();
765 break;
766 }
767}
768
769void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value) const
770{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500771 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300772
773 switch (pname)
774 {
775 case GL_PATH_STROKE_WIDTH_CHROMIUM:
776 *value = pathObj->getStrokeWidth();
777 break;
778 case GL_PATH_END_CAPS_CHROMIUM:
779 *value = static_cast<GLfloat>(pathObj->getEndCaps());
780 break;
781 case GL_PATH_JOIN_STYLE_CHROMIUM:
782 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
783 break;
784 case GL_PATH_MITER_LIMIT_CHROMIUM:
785 *value = pathObj->getMiterLimit();
786 break;
787 case GL_PATH_STROKE_BOUND_CHROMIUM:
788 *value = pathObj->getStrokeBound();
789 break;
790 default:
791 UNREACHABLE();
792 break;
793 }
794}
795
796void Context::setPathStencilFunc(GLenum func, GLint ref, GLuint mask)
797{
798 mGLState.setPathStencilFunc(func, ref, mask);
799}
800
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000801void Context::deleteFramebuffer(GLuint framebuffer)
802{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500803 if (mState.mFramebuffers->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000804 {
805 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000806 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500807
Jamie Madill6c1f6712017-02-14 19:08:04 -0500808 mState.mFramebuffers->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000809}
810
Jamie Madill33dc8432013-07-26 11:55:05 -0400811void Context::deleteFenceNV(GLuint fence)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000812{
Jamie Madill96a483b2017-06-27 16:49:21 -0400813 FenceNV *fenceObject = nullptr;
814 if (mFenceNVMap.erase(fence, &fenceObject))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000815 {
Jamie Madill96a483b2017-06-27 16:49:21 -0400816 mFenceNVHandleAllocator.release(fence);
817 delete fenceObject;
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000818 }
819}
820
Geoff Lang70d0f492015-12-10 17:45:46 -0500821Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000822{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500823 return mState.mBuffers->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000824}
825
Jamie Madill570f7c82014-07-03 10:38:54 -0400826Texture *Context::getTexture(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000827{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500828 return mState.mTextures->getTexture(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000829}
830
Geoff Lang70d0f492015-12-10 17:45:46 -0500831Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000832{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500833 return mState.mRenderbuffers->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000834}
835
Jamie Madill70b5bb02017-08-28 13:32:37 -0400836Sync *Context::getSync(GLsync handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400837{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400838 return mState.mSyncs->getSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400839}
840
Jamie Madill57a89722013-07-02 11:57:03 -0400841VertexArray *Context::getVertexArray(GLuint handle) const
842{
Jamie Madill96a483b2017-06-27 16:49:21 -0400843 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -0400844}
845
Jamie Madilldc356042013-07-19 16:36:57 -0400846Sampler *Context::getSampler(GLuint handle) const
847{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500848 return mState.mSamplers->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400849}
850
Geoff Langc8058452014-02-03 12:04:11 -0500851TransformFeedback *Context::getTransformFeedback(GLuint handle) const
852{
Jamie Madill96a483b2017-06-27 16:49:21 -0400853 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -0500854}
855
Yunchao Hea336b902017-08-02 16:05:21 +0800856ProgramPipeline *Context::getProgramPipeline(GLuint handle) const
857{
858 return mState.mPipelines->getProgramPipeline(handle);
859}
860
Geoff Lang70d0f492015-12-10 17:45:46 -0500861LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
862{
863 switch (identifier)
864 {
865 case GL_BUFFER:
866 return getBuffer(name);
867 case GL_SHADER:
868 return getShader(name);
869 case GL_PROGRAM:
870 return getProgram(name);
871 case GL_VERTEX_ARRAY:
872 return getVertexArray(name);
873 case GL_QUERY:
874 return getQuery(name);
875 case GL_TRANSFORM_FEEDBACK:
876 return getTransformFeedback(name);
877 case GL_SAMPLER:
878 return getSampler(name);
879 case GL_TEXTURE:
880 return getTexture(name);
881 case GL_RENDERBUFFER:
882 return getRenderbuffer(name);
883 case GL_FRAMEBUFFER:
884 return getFramebuffer(name);
885 default:
886 UNREACHABLE();
887 return nullptr;
888 }
889}
890
891LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
892{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400893 return getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
Geoff Lang70d0f492015-12-10 17:45:46 -0500894}
895
Martin Radev9d901792016-07-15 15:58:58 +0300896void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
897{
898 LabeledObject *object = getLabeledObject(identifier, name);
899 ASSERT(object != nullptr);
900
901 std::string labelName = GetObjectLabelFromPointer(length, label);
902 object->setLabel(labelName);
Jamie Madill8693bdb2017-09-02 15:32:14 -0400903
904 // TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the
905 // specified object is active until we do this.
906 mGLState.setObjectDirty(identifier);
Martin Radev9d901792016-07-15 15:58:58 +0300907}
908
909void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
910{
911 LabeledObject *object = getLabeledObjectFromPtr(ptr);
912 ASSERT(object != nullptr);
913
914 std::string labelName = GetObjectLabelFromPointer(length, label);
915 object->setLabel(labelName);
916}
917
918void Context::getObjectLabel(GLenum identifier,
919 GLuint name,
920 GLsizei bufSize,
921 GLsizei *length,
922 GLchar *label) const
923{
924 LabeledObject *object = getLabeledObject(identifier, name);
925 ASSERT(object != nullptr);
926
927 const std::string &objectLabel = object->getLabel();
928 GetObjectLabelBase(objectLabel, bufSize, length, label);
929}
930
931void Context::getObjectPtrLabel(const void *ptr,
932 GLsizei bufSize,
933 GLsizei *length,
934 GLchar *label) const
935{
936 LabeledObject *object = getLabeledObjectFromPtr(ptr);
937 ASSERT(object != nullptr);
938
939 const std::string &objectLabel = object->getLabel();
940 GetObjectLabelBase(objectLabel, bufSize, length, label);
941}
942
Jamie Madilldc356042013-07-19 16:36:57 -0400943bool Context::isSampler(GLuint samplerName) const
944{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500945 return mState.mSamplers->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -0400946}
947
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500948void Context::bindArrayBuffer(GLuint bufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000949{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500950 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400951 mGLState.setArrayBufferBinding(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000952}
953
Jiajia Qin9d7d0b12016-11-29 16:30:31 +0800954void Context::bindDrawIndirectBuffer(GLuint bufferHandle)
955{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500956 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400957 mGLState.setDrawIndirectBufferBinding(this, buffer);
Jiajia Qin9d7d0b12016-11-29 16:30:31 +0800958}
959
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500960void Context::bindElementArrayBuffer(GLuint bufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000961{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500962 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400963 mGLState.setElementArrayBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000964}
965
Jamie Madilldedd7b92014-11-05 16:30:36 -0500966void Context::bindTexture(GLenum target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000967{
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500968 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000969
Jamie Madilldedd7b92014-11-05 16:30:36 -0500970 if (handle == 0)
971 {
972 texture = mZeroTextures[target].get();
973 }
974 else
975 {
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500976 texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500977 }
978
979 ASSERT(texture);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400980 mGLState.setSamplerTexture(this, target, texture);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +0000981}
982
Jamie Madill5bf9ff42016-02-01 11:13:03 -0500983void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000984{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500985 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
986 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700987 mGLState.setReadFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000988}
989
Jamie Madill5bf9ff42016-02-01 11:13:03 -0500990void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000991{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500992 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
993 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700994 mGLState.setDrawFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000995}
996
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500997void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -0400998{
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500999 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001000 mGLState.setVertexArrayBinding(vertexArray);
Jamie Madill57a89722013-07-02 11:57:03 -04001001}
1002
Shao80957d92017-02-20 21:25:59 +08001003void Context::bindVertexBuffer(GLuint bindingIndex,
1004 GLuint bufferHandle,
1005 GLintptr offset,
1006 GLsizei stride)
1007{
1008 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001009 mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Shao80957d92017-02-20 21:25:59 +08001010}
1011
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001012void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -04001013{
Geoff Lang76b10c92014-09-05 16:28:14 -04001014 ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -04001015 Sampler *sampler =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001016 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001017 mGLState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04001018}
1019
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001020void Context::bindImageTexture(GLuint unit,
1021 GLuint texture,
1022 GLint level,
1023 GLboolean layered,
1024 GLint layer,
1025 GLenum access,
1026 GLenum format)
1027{
1028 Texture *tex = mState.mTextures->getTexture(texture);
1029 mGLState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
1030}
1031
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001032void Context::bindGenericUniformBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001033{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001034 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001035 mGLState.setGenericUniformBufferBinding(this, buffer);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001036}
1037
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001038void Context::bindIndexedUniformBuffer(GLuint bufferHandle,
1039 GLuint index,
1040 GLintptr offset,
1041 GLsizeiptr size)
shannon.woods%transgaming.com@gtempaccount.com34089352013-04-13 03:36:57 +00001042{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001043 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001044 mGLState.setIndexedUniformBufferBinding(this, index, buffer, offset, size);
shannon.woods%transgaming.com@gtempaccount.com34089352013-04-13 03:36:57 +00001045}
1046
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001047void Context::bindGenericTransformFeedbackBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001048{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001049 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001050 mGLState.getCurrentTransformFeedback()->bindGenericBuffer(this, buffer);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001051}
1052
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001053void Context::bindIndexedTransformFeedbackBuffer(GLuint bufferHandle,
1054 GLuint index,
1055 GLintptr offset,
1056 GLsizeiptr size)
shannon.woods%transgaming.com@gtempaccount.com34089352013-04-13 03:36:57 +00001057{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001058 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001059 mGLState.getCurrentTransformFeedback()->bindIndexedBuffer(this, index, buffer, offset, size);
shannon.woods%transgaming.com@gtempaccount.com34089352013-04-13 03:36:57 +00001060}
1061
Jiajia Qin6eafb042016-12-27 17:04:07 +08001062void Context::bindGenericAtomicCounterBuffer(GLuint bufferHandle)
1063{
1064 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001065 mGLState.setGenericAtomicCounterBufferBinding(this, buffer);
Jiajia Qin6eafb042016-12-27 17:04:07 +08001066}
1067
1068void Context::bindIndexedAtomicCounterBuffer(GLuint bufferHandle,
1069 GLuint index,
1070 GLintptr offset,
1071 GLsizeiptr size)
1072{
1073 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001074 mGLState.setIndexedAtomicCounterBufferBinding(this, index, buffer, offset, size);
Jiajia Qin6eafb042016-12-27 17:04:07 +08001075}
1076
Jiajia Qinf546e7d2017-03-27 14:12:59 +08001077void Context::bindGenericShaderStorageBuffer(GLuint bufferHandle)
1078{
1079 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001080 mGLState.setGenericShaderStorageBufferBinding(this, buffer);
Jiajia Qinf546e7d2017-03-27 14:12:59 +08001081}
1082
1083void Context::bindIndexedShaderStorageBuffer(GLuint bufferHandle,
1084 GLuint index,
1085 GLintptr offset,
1086 GLsizeiptr size)
1087{
1088 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001089 mGLState.setIndexedShaderStorageBufferBinding(this, index, buffer, offset, size);
Jiajia Qinf546e7d2017-03-27 14:12:59 +08001090}
1091
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001092void Context::bindCopyReadBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001093{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001094 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001095 mGLState.setCopyReadBufferBinding(this, buffer);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001096}
1097
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001098void Context::bindCopyWriteBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001099{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001100 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001101 mGLState.setCopyWriteBufferBinding(this, buffer);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001102}
1103
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001104void Context::bindPixelPackBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001105{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001106 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001107 mGLState.setPixelPackBufferBinding(this, buffer);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001108}
1109
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001110void Context::bindPixelUnpackBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001111{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001112 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001113 mGLState.setPixelUnpackBufferBinding(this, buffer);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001114}
1115
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001116void Context::useProgram(GLuint program)
1117{
Jamie Madill6c1f6712017-02-14 19:08:04 -05001118 mGLState.setProgram(this, getProgram(program));
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001119}
1120
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001121void Context::bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001122{
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001123 ASSERT(target == GL_TRANSFORM_FEEDBACK);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001124 TransformFeedback *transformFeedback =
1125 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001126 mGLState.setTransformFeedbackBinding(this, transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -05001127}
1128
Yunchao Hea336b902017-08-02 16:05:21 +08001129void Context::bindProgramPipeline(GLuint pipelineHandle)
1130{
1131 ProgramPipeline *pipeline =
1132 mState.mPipelines->checkProgramPipelineAllocation(mImplementation.get(), pipelineHandle);
1133 mGLState.setProgramPipelineBinding(this, pipeline);
1134}
1135
Jamie Madillf0e04492017-08-26 15:28:42 -04001136void Context::beginQuery(GLenum target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001137{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001138 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001139 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001140
Geoff Lang5aad9672014-09-08 11:10:42 -04001141 // begin query
Jamie Madillf0e04492017-08-26 15:28:42 -04001142 ANGLE_CONTEXT_TRY(queryObject->begin());
Geoff Lang5aad9672014-09-08 11:10:42 -04001143
1144 // set query as active for specified target only if begin succeeded
Jamie Madill4928b7c2017-06-20 12:57:39 -04001145 mGLState.setActiveQuery(this, target, queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001146}
1147
Jamie Madillf0e04492017-08-26 15:28:42 -04001148void Context::endQuery(GLenum target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001149{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001150 Query *queryObject = mGLState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001151 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001152
Jamie Madillf0e04492017-08-26 15:28:42 -04001153 handleError(queryObject->end());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001154
Geoff Lang5aad9672014-09-08 11:10:42 -04001155 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madill4928b7c2017-06-20 12:57:39 -04001156 mGLState.setActiveQuery(this, target, nullptr);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001157}
1158
Jamie Madillf0e04492017-08-26 15:28:42 -04001159void Context::queryCounter(GLuint id, GLenum target)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001160{
1161 ASSERT(target == GL_TIMESTAMP_EXT);
1162
1163 Query *queryObject = getQuery(id, true, target);
1164 ASSERT(queryObject);
1165
Jamie Madillf0e04492017-08-26 15:28:42 -04001166 handleError(queryObject->queryCounter());
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001167}
1168
1169void Context::getQueryiv(GLenum target, GLenum pname, GLint *params)
1170{
1171 switch (pname)
1172 {
1173 case GL_CURRENT_QUERY_EXT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001174 params[0] = mGLState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001175 break;
1176 case GL_QUERY_COUNTER_BITS_EXT:
1177 switch (target)
1178 {
1179 case GL_TIME_ELAPSED_EXT:
1180 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1181 break;
1182 case GL_TIMESTAMP_EXT:
1183 params[0] = getExtensions().queryCounterBitsTimestamp;
1184 break;
1185 default:
1186 UNREACHABLE();
1187 params[0] = 0;
1188 break;
1189 }
1190 break;
1191 default:
1192 UNREACHABLE();
1193 return;
1194 }
1195}
1196
Geoff Lang2186c382016-10-14 10:54:54 -04001197void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001198{
Geoff Lang2186c382016-10-14 10:54:54 -04001199 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001200}
1201
Geoff Lang2186c382016-10-14 10:54:54 -04001202void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001203{
Geoff Lang2186c382016-10-14 10:54:54 -04001204 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001205}
1206
Geoff Lang2186c382016-10-14 10:54:54 -04001207void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001208{
Geoff Lang2186c382016-10-14 10:54:54 -04001209 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001210}
1211
Geoff Lang2186c382016-10-14 10:54:54 -04001212void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001213{
Geoff Lang2186c382016-10-14 10:54:54 -04001214 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001215}
1216
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001217Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001218{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001219 return mState.mFramebuffers->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001220}
1221
Jamie Madill2f348d22017-06-05 10:50:59 -04001222FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001223{
Jamie Madill96a483b2017-06-27 16:49:21 -04001224 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001225}
1226
Jamie Madill2f348d22017-06-05 10:50:59 -04001227Query *Context::getQuery(GLuint handle, bool create, GLenum type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001228{
Jamie Madill96a483b2017-06-27 16:49:21 -04001229 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001230 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001231 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001232 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001233
1234 Query *query = mQueryMap.query(handle);
1235 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001236 {
Jamie Madill96a483b2017-06-27 16:49:21 -04001237 query = new Query(mImplementation->createQuery(type), handle);
1238 query->addRef();
1239 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001240 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001241 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001242}
1243
Geoff Lang70d0f492015-12-10 17:45:46 -05001244Query *Context::getQuery(GLuint handle) const
1245{
Jamie Madill96a483b2017-06-27 16:49:21 -04001246 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001247}
1248
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001249Texture *Context::getTargetTexture(GLenum target) const
1250{
Ian Ewellbda75592016-04-18 17:25:54 -04001251 ASSERT(ValidTextureTarget(this, target) || ValidTextureExternalTarget(this, target));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001252 return mGLState.getTargetTexture(target);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001253}
1254
Geoff Lang76b10c92014-09-05 16:28:14 -04001255Texture *Context::getSamplerTexture(unsigned int sampler, GLenum type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001256{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001257 return mGLState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001258}
1259
Geoff Lang492a7e42014-11-05 13:27:06 -05001260Compiler *Context::getCompiler() const
1261{
Jamie Madill2f348d22017-06-05 10:50:59 -04001262 if (mCompiler.get() == nullptr)
1263 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001264 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001265 }
1266 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001267}
1268
Jamie Madillc1d770e2017-04-13 17:31:24 -04001269void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001270{
1271 switch (pname)
1272 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001273 case GL_SHADER_COMPILER:
1274 *params = GL_TRUE;
1275 break;
1276 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1277 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1278 break;
1279 default:
1280 mGLState.getBooleanv(pname, params);
1281 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001282 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001283}
1284
Jamie Madillc1d770e2017-04-13 17:31:24 -04001285void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001286{
Shannon Woods53a94a82014-06-24 15:20:36 -04001287 // Queries about context capabilities and maximums are answered by Context.
1288 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001289 switch (pname)
1290 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001291 case GL_ALIASED_LINE_WIDTH_RANGE:
1292 params[0] = mCaps.minAliasedLineWidth;
1293 params[1] = mCaps.maxAliasedLineWidth;
1294 break;
1295 case GL_ALIASED_POINT_SIZE_RANGE:
1296 params[0] = mCaps.minAliasedPointSize;
1297 params[1] = mCaps.maxAliasedPointSize;
1298 break;
1299 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1300 ASSERT(mExtensions.textureFilterAnisotropic);
1301 *params = mExtensions.maxTextureAnisotropy;
1302 break;
1303 case GL_MAX_TEXTURE_LOD_BIAS:
1304 *params = mCaps.maxLODBias;
1305 break;
1306
1307 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1308 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1309 {
1310 ASSERT(mExtensions.pathRendering);
1311 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1312 memcpy(params, m, 16 * sizeof(GLfloat));
1313 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001314 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001315
Jamie Madill231c7f52017-04-26 13:45:37 -04001316 default:
1317 mGLState.getFloatv(pname, params);
1318 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001319 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001320}
1321
Jamie Madillc1d770e2017-04-13 17:31:24 -04001322void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001323{
Shannon Woods53a94a82014-06-24 15:20:36 -04001324 // Queries about context capabilities and maximums are answered by Context.
1325 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001326
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001327 switch (pname)
1328 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001329 case GL_MAX_VERTEX_ATTRIBS:
1330 *params = mCaps.maxVertexAttributes;
1331 break;
1332 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1333 *params = mCaps.maxVertexUniformVectors;
1334 break;
1335 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
1336 *params = mCaps.maxVertexUniformComponents;
1337 break;
1338 case GL_MAX_VARYING_VECTORS:
1339 *params = mCaps.maxVaryingVectors;
1340 break;
1341 case GL_MAX_VARYING_COMPONENTS:
1342 *params = mCaps.maxVertexOutputComponents;
1343 break;
1344 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1345 *params = mCaps.maxCombinedTextureImageUnits;
1346 break;
1347 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
1348 *params = mCaps.maxVertexTextureImageUnits;
1349 break;
1350 case GL_MAX_TEXTURE_IMAGE_UNITS:
1351 *params = mCaps.maxTextureImageUnits;
1352 break;
1353 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1354 *params = mCaps.maxFragmentUniformVectors;
1355 break;
1356 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
1357 *params = mCaps.maxFragmentUniformComponents;
1358 break;
1359 case GL_MAX_RENDERBUFFER_SIZE:
1360 *params = mCaps.maxRenderbufferSize;
1361 break;
1362 case GL_MAX_COLOR_ATTACHMENTS_EXT:
1363 *params = mCaps.maxColorAttachments;
1364 break;
1365 case GL_MAX_DRAW_BUFFERS_EXT:
1366 *params = mCaps.maxDrawBuffers;
1367 break;
1368 // case GL_FRAMEBUFFER_BINDING: // now equivalent to
1369 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
1370 case GL_SUBPIXEL_BITS:
1371 *params = 4;
1372 break;
1373 case GL_MAX_TEXTURE_SIZE:
1374 *params = mCaps.max2DTextureSize;
1375 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001376 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
1377 *params = mCaps.maxRectangleTextureSize;
1378 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001379 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1380 *params = mCaps.maxCubeMapTextureSize;
1381 break;
1382 case GL_MAX_3D_TEXTURE_SIZE:
1383 *params = mCaps.max3DTextureSize;
1384 break;
1385 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1386 *params = mCaps.maxArrayTextureLayers;
1387 break;
1388 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1389 *params = mCaps.uniformBufferOffsetAlignment;
1390 break;
1391 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1392 *params = mCaps.maxUniformBufferBindings;
1393 break;
1394 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
1395 *params = mCaps.maxVertexUniformBlocks;
1396 break;
1397 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
1398 *params = mCaps.maxFragmentUniformBlocks;
1399 break;
1400 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1401 *params = mCaps.maxCombinedTextureImageUnits;
1402 break;
1403 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1404 *params = mCaps.maxVertexOutputComponents;
1405 break;
1406 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1407 *params = mCaps.maxFragmentInputComponents;
1408 break;
1409 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1410 *params = mCaps.minProgramTexelOffset;
1411 break;
1412 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1413 *params = mCaps.maxProgramTexelOffset;
1414 break;
1415 case GL_MAJOR_VERSION:
1416 *params = getClientVersion().major;
1417 break;
1418 case GL_MINOR_VERSION:
1419 *params = getClientVersion().minor;
1420 break;
1421 case GL_MAX_ELEMENTS_INDICES:
1422 *params = mCaps.maxElementsIndices;
1423 break;
1424 case GL_MAX_ELEMENTS_VERTICES:
1425 *params = mCaps.maxElementsVertices;
1426 break;
1427 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1428 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1429 break;
1430 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1431 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1432 break;
1433 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1434 *params = mCaps.maxTransformFeedbackSeparateComponents;
1435 break;
1436 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1437 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1438 break;
1439 case GL_MAX_SAMPLES_ANGLE:
1440 *params = mCaps.maxSamples;
1441 break;
1442 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001443 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001444 params[0] = mCaps.maxViewportWidth;
1445 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001446 }
1447 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001448 case GL_COMPRESSED_TEXTURE_FORMATS:
1449 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1450 params);
1451 break;
1452 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1453 *params = mResetStrategy;
1454 break;
1455 case GL_NUM_SHADER_BINARY_FORMATS:
1456 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1457 break;
1458 case GL_SHADER_BINARY_FORMATS:
1459 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1460 break;
1461 case GL_NUM_PROGRAM_BINARY_FORMATS:
1462 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1463 break;
1464 case GL_PROGRAM_BINARY_FORMATS:
1465 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1466 break;
1467 case GL_NUM_EXTENSIONS:
1468 *params = static_cast<GLint>(mExtensionStrings.size());
1469 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001470
Jamie Madill231c7f52017-04-26 13:45:37 -04001471 // GL_KHR_debug
1472 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1473 *params = mExtensions.maxDebugMessageLength;
1474 break;
1475 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1476 *params = mExtensions.maxDebugLoggedMessages;
1477 break;
1478 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1479 *params = mExtensions.maxDebugGroupStackDepth;
1480 break;
1481 case GL_MAX_LABEL_LENGTH:
1482 *params = mExtensions.maxLabelLength;
1483 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001484
Martin Radeve5285d22017-07-14 16:23:53 +03001485 // GL_ANGLE_multiview
1486 case GL_MAX_VIEWS_ANGLE:
1487 *params = mExtensions.maxViews;
1488 break;
1489
Jamie Madill231c7f52017-04-26 13:45:37 -04001490 // GL_EXT_disjoint_timer_query
1491 case GL_GPU_DISJOINT_EXT:
1492 *params = mImplementation->getGPUDisjoint();
1493 break;
1494 case GL_MAX_FRAMEBUFFER_WIDTH:
1495 *params = mCaps.maxFramebufferWidth;
1496 break;
1497 case GL_MAX_FRAMEBUFFER_HEIGHT:
1498 *params = mCaps.maxFramebufferHeight;
1499 break;
1500 case GL_MAX_FRAMEBUFFER_SAMPLES:
1501 *params = mCaps.maxFramebufferSamples;
1502 break;
1503 case GL_MAX_SAMPLE_MASK_WORDS:
1504 *params = mCaps.maxSampleMaskWords;
1505 break;
1506 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1507 *params = mCaps.maxColorTextureSamples;
1508 break;
1509 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1510 *params = mCaps.maxDepthTextureSamples;
1511 break;
1512 case GL_MAX_INTEGER_SAMPLES:
1513 *params = mCaps.maxIntegerSamples;
1514 break;
1515 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1516 *params = mCaps.maxVertexAttribRelativeOffset;
1517 break;
1518 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1519 *params = mCaps.maxVertexAttribBindings;
1520 break;
1521 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1522 *params = mCaps.maxVertexAttribStride;
1523 break;
1524 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
1525 *params = mCaps.maxVertexAtomicCounterBuffers;
1526 break;
1527 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
1528 *params = mCaps.maxVertexAtomicCounters;
1529 break;
1530 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
1531 *params = mCaps.maxVertexImageUniforms;
1532 break;
1533 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
1534 *params = mCaps.maxVertexShaderStorageBlocks;
1535 break;
1536 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
1537 *params = mCaps.maxFragmentAtomicCounterBuffers;
1538 break;
1539 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
1540 *params = mCaps.maxFragmentAtomicCounters;
1541 break;
1542 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
1543 *params = mCaps.maxFragmentImageUniforms;
1544 break;
1545 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
1546 *params = mCaps.maxFragmentShaderStorageBlocks;
1547 break;
1548 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1549 *params = mCaps.minProgramTextureGatherOffset;
1550 break;
1551 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1552 *params = mCaps.maxProgramTextureGatherOffset;
1553 break;
1554 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1555 *params = mCaps.maxComputeWorkGroupInvocations;
1556 break;
1557 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
1558 *params = mCaps.maxComputeUniformBlocks;
1559 break;
1560 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
1561 *params = mCaps.maxComputeTextureImageUnits;
1562 break;
1563 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1564 *params = mCaps.maxComputeSharedMemorySize;
1565 break;
1566 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
1567 *params = mCaps.maxComputeUniformComponents;
1568 break;
1569 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
1570 *params = mCaps.maxComputeAtomicCounterBuffers;
1571 break;
1572 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
1573 *params = mCaps.maxComputeAtomicCounters;
1574 break;
1575 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
1576 *params = mCaps.maxComputeImageUniforms;
1577 break;
1578 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
1579 *params = mCaps.maxCombinedComputeUniformComponents;
1580 break;
1581 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
1582 *params = mCaps.maxComputeShaderStorageBlocks;
1583 break;
1584 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1585 *params = mCaps.maxCombinedShaderOutputResources;
1586 break;
1587 case GL_MAX_UNIFORM_LOCATIONS:
1588 *params = mCaps.maxUniformLocations;
1589 break;
1590 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1591 *params = mCaps.maxAtomicCounterBufferBindings;
1592 break;
1593 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1594 *params = mCaps.maxAtomicCounterBufferSize;
1595 break;
1596 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1597 *params = mCaps.maxCombinedAtomicCounterBuffers;
1598 break;
1599 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1600 *params = mCaps.maxCombinedAtomicCounters;
1601 break;
1602 case GL_MAX_IMAGE_UNITS:
1603 *params = mCaps.maxImageUnits;
1604 break;
1605 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1606 *params = mCaps.maxCombinedImageUniforms;
1607 break;
1608 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1609 *params = mCaps.maxShaderStorageBufferBindings;
1610 break;
1611 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1612 *params = mCaps.maxCombinedShaderStorageBlocks;
1613 break;
1614 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1615 *params = mCaps.shaderStorageBufferOffsetAlignment;
1616 break;
1617 default:
1618 mGLState.getIntegerv(this, pname, params);
1619 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001620 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001621}
1622
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001623void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001624{
Shannon Woods53a94a82014-06-24 15:20:36 -04001625 // Queries about context capabilities and maximums are answered by Context.
1626 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001627 switch (pname)
1628 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001629 case GL_MAX_ELEMENT_INDEX:
1630 *params = mCaps.maxElementIndex;
1631 break;
1632 case GL_MAX_UNIFORM_BLOCK_SIZE:
1633 *params = mCaps.maxUniformBlockSize;
1634 break;
1635 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
1636 *params = mCaps.maxCombinedVertexUniformComponents;
1637 break;
1638 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
1639 *params = mCaps.maxCombinedFragmentUniformComponents;
1640 break;
1641 case GL_MAX_SERVER_WAIT_TIMEOUT:
1642 *params = mCaps.maxServerWaitTimeout;
1643 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001644
Jamie Madill231c7f52017-04-26 13:45:37 -04001645 // GL_EXT_disjoint_timer_query
1646 case GL_TIMESTAMP_EXT:
1647 *params = mImplementation->getTimestamp();
1648 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001649
Jamie Madill231c7f52017-04-26 13:45:37 -04001650 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1651 *params = mCaps.maxShaderStorageBlockSize;
1652 break;
1653 default:
1654 UNREACHABLE();
1655 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001656 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001657}
1658
Geoff Lang70d0f492015-12-10 17:45:46 -05001659void Context::getPointerv(GLenum pname, void **params) const
1660{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001661 mGLState.getPointerv(pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001662}
1663
Martin Radev66fb8202016-07-28 11:45:20 +03001664void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -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.
Martin Radev66fb8202016-07-28 11:45:20 +03001668
1669 GLenum nativeType;
1670 unsigned int numParams;
1671 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1672 ASSERT(queryStatus);
1673
1674 if (nativeType == GL_INT)
1675 {
1676 switch (target)
1677 {
1678 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1679 ASSERT(index < 3u);
1680 *data = mCaps.maxComputeWorkGroupCount[index];
1681 break;
1682 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1683 ASSERT(index < 3u);
1684 *data = mCaps.maxComputeWorkGroupSize[index];
1685 break;
1686 default:
1687 mGLState.getIntegeri_v(target, index, data);
1688 }
1689 }
1690 else
1691 {
1692 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1693 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001694}
1695
Martin Radev66fb8202016-07-28 11:45:20 +03001696void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001697{
Shannon Woods53a94a82014-06-24 15:20:36 -04001698 // Queries about context capabilities and maximums are answered by Context.
1699 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001700
1701 GLenum nativeType;
1702 unsigned int numParams;
1703 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1704 ASSERT(queryStatus);
1705
1706 if (nativeType == GL_INT_64_ANGLEX)
1707 {
1708 mGLState.getInteger64i_v(target, index, data);
1709 }
1710 else
1711 {
1712 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1713 }
1714}
1715
1716void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1717{
1718 // Queries about context capabilities and maximums are answered by Context.
1719 // Queries about current GL state values are answered by State.
1720
1721 GLenum nativeType;
1722 unsigned int numParams;
1723 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1724 ASSERT(queryStatus);
1725
1726 if (nativeType == GL_BOOL)
1727 {
1728 mGLState.getBooleani_v(target, index, data);
1729 }
1730 else
1731 {
1732 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1733 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001734}
1735
He Yunchao010e4db2017-03-03 14:22:06 +08001736void Context::getBufferParameteriv(GLenum target, GLenum pname, GLint *params)
1737{
1738 Buffer *buffer = mGLState.getTargetBuffer(target);
1739 QueryBufferParameteriv(buffer, pname, params);
1740}
1741
1742void Context::getFramebufferAttachmentParameteriv(GLenum target,
1743 GLenum attachment,
1744 GLenum pname,
1745 GLint *params)
1746{
1747 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
1748 QueryFramebufferAttachmentParameteriv(framebuffer, attachment, pname, params);
1749}
1750
1751void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
1752{
1753 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
1754 QueryRenderbufferiv(this, renderbuffer, pname, params);
1755}
1756
1757void Context::getTexParameterfv(GLenum target, GLenum pname, GLfloat *params)
1758{
1759 Texture *texture = getTargetTexture(target);
1760 QueryTexParameterfv(texture, pname, params);
1761}
1762
1763void Context::getTexParameteriv(GLenum target, GLenum pname, GLint *params)
1764{
1765 Texture *texture = getTargetTexture(target);
1766 QueryTexParameteriv(texture, pname, params);
1767}
1768void Context::texParameterf(GLenum target, GLenum pname, GLfloat param)
1769{
1770 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001771 SetTexParameterf(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04001772 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001773}
1774
1775void Context::texParameterfv(GLenum target, GLenum pname, const GLfloat *params)
1776{
1777 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001778 SetTexParameterfv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04001779 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001780}
1781
1782void Context::texParameteri(GLenum target, GLenum pname, GLint param)
1783{
1784 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001785 SetTexParameteri(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04001786 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001787}
1788
1789void Context::texParameteriv(GLenum target, GLenum pname, const GLint *params)
1790{
1791 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001792 SetTexParameteriv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04001793 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001794}
1795
Jamie Madill675fe712016-12-19 13:07:54 -05001796void Context::drawArrays(GLenum mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001797{
Jamie Madill05b35b22017-10-03 09:01:44 -04001798 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001799 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
1800 MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001801}
1802
Jamie Madill675fe712016-12-19 13:07:54 -05001803void Context::drawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04001804{
Jamie Madill05b35b22017-10-03 09:01:44 -04001805 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001806 ANGLE_CONTEXT_TRY(
1807 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
1808 MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback());
Geoff Langf6db0982015-08-25 13:04:00 -04001809}
1810
Jamie Madill876429b2017-04-20 15:46:24 -04001811void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001812{
Jamie Madill05b35b22017-10-03 09:01:44 -04001813 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001814 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04001815}
1816
Jamie Madill675fe712016-12-19 13:07:54 -05001817void Context::drawElementsInstanced(GLenum mode,
1818 GLsizei count,
1819 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04001820 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04001821 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04001822{
Jamie Madill05b35b22017-10-03 09:01:44 -04001823 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001824 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08001825 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04001826}
1827
Jamie Madill675fe712016-12-19 13:07:54 -05001828void Context::drawRangeElements(GLenum mode,
1829 GLuint start,
1830 GLuint end,
1831 GLsizei count,
1832 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04001833 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04001834{
Jamie Madill05b35b22017-10-03 09:01:44 -04001835 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001836 ANGLE_CONTEXT_TRY(
1837 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001838}
1839
Jamie Madill876429b2017-04-20 15:46:24 -04001840void Context::drawArraysIndirect(GLenum mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08001841{
Jamie Madill05b35b22017-10-03 09:01:44 -04001842 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001843 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08001844}
1845
Jamie Madill876429b2017-04-20 15:46:24 -04001846void Context::drawElementsIndirect(GLenum mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08001847{
Jamie Madill05b35b22017-10-03 09:01:44 -04001848 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001849 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08001850}
1851
Jamie Madill675fe712016-12-19 13:07:54 -05001852void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001853{
Jamie Madill675fe712016-12-19 13:07:54 -05001854 handleError(mImplementation->flush());
Geoff Lang129753a2015-01-09 16:52:09 -05001855}
1856
Jamie Madill675fe712016-12-19 13:07:54 -05001857void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05001858{
Jamie Madill675fe712016-12-19 13:07:54 -05001859 handleError(mImplementation->finish());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001860}
1861
Austin Kinross6ee1e782015-05-29 17:05:37 -07001862void Context::insertEventMarker(GLsizei length, const char *marker)
1863{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001864 ASSERT(mImplementation);
1865 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07001866}
1867
1868void Context::pushGroupMarker(GLsizei length, const char *marker)
1869{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001870 ASSERT(mImplementation);
1871 mImplementation->pushGroupMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07001872}
1873
1874void Context::popGroupMarker()
1875{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001876 ASSERT(mImplementation);
1877 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07001878}
1879
Geoff Langd8605522016-04-13 10:19:12 -04001880void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
1881{
1882 Program *programObject = getProgram(program);
1883 ASSERT(programObject);
1884
1885 programObject->bindUniformLocation(location, name);
1886}
1887
Sami Väisänena797e062016-05-12 15:23:40 +03001888void Context::setCoverageModulation(GLenum components)
1889{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001890 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03001891}
1892
Sami Väisänene45e53b2016-05-25 10:36:04 +03001893void Context::loadPathRenderingMatrix(GLenum matrixMode, const GLfloat *matrix)
1894{
1895 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
1896}
1897
1898void Context::loadPathRenderingIdentityMatrix(GLenum matrixMode)
1899{
1900 GLfloat I[16];
1901 angle::Matrix<GLfloat>::setToIdentity(I);
1902
1903 mGLState.loadPathRenderingMatrix(matrixMode, I);
1904}
1905
1906void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
1907{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001908 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001909 if (!pathObj)
1910 return;
1911
1912 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1913 syncRendererState();
1914
1915 mImplementation->stencilFillPath(pathObj, fillMode, mask);
1916}
1917
1918void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
1919{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001920 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001921 if (!pathObj)
1922 return;
1923
1924 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1925 syncRendererState();
1926
1927 mImplementation->stencilStrokePath(pathObj, reference, mask);
1928}
1929
1930void Context::coverFillPath(GLuint path, GLenum coverMode)
1931{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001932 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001933 if (!pathObj)
1934 return;
1935
1936 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1937 syncRendererState();
1938
1939 mImplementation->coverFillPath(pathObj, coverMode);
1940}
1941
1942void Context::coverStrokePath(GLuint path, GLenum coverMode)
1943{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001944 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001945 if (!pathObj)
1946 return;
1947
1948 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1949 syncRendererState();
1950
1951 mImplementation->coverStrokePath(pathObj, coverMode);
1952}
1953
1954void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
1955{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001956 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001957 if (!pathObj)
1958 return;
1959
1960 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1961 syncRendererState();
1962
1963 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
1964}
1965
1966void Context::stencilThenCoverStrokePath(GLuint path,
1967 GLint reference,
1968 GLuint mask,
1969 GLenum coverMode)
1970{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001971 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001972 if (!pathObj)
1973 return;
1974
1975 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1976 syncRendererState();
1977
1978 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
1979}
1980
Sami Väisänend59ca052016-06-21 16:10:00 +03001981void Context::coverFillPathInstanced(GLsizei numPaths,
1982 GLenum pathNameType,
1983 const void *paths,
1984 GLuint pathBase,
1985 GLenum coverMode,
1986 GLenum transformType,
1987 const GLfloat *transformValues)
1988{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001989 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03001990
1991 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1992 syncRendererState();
1993
1994 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
1995}
Sami Väisänen46eaa942016-06-29 10:26:37 +03001996
Sami Väisänend59ca052016-06-21 16:10:00 +03001997void Context::coverStrokePathInstanced(GLsizei numPaths,
1998 GLenum pathNameType,
1999 const void *paths,
2000 GLuint pathBase,
2001 GLenum coverMode,
2002 GLenum transformType,
2003 const GLfloat *transformValues)
2004{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002005 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002006
2007 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2008 syncRendererState();
2009
2010 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2011 transformValues);
2012}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002013
Sami Väisänend59ca052016-06-21 16:10:00 +03002014void Context::stencilFillPathInstanced(GLsizei numPaths,
2015 GLenum pathNameType,
2016 const void *paths,
2017 GLuint pathBase,
2018 GLenum fillMode,
2019 GLuint mask,
2020 GLenum transformType,
2021 const GLfloat *transformValues)
2022{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002023 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002024
2025 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2026 syncRendererState();
2027
2028 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2029 transformValues);
2030}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002031
Sami Väisänend59ca052016-06-21 16:10:00 +03002032void Context::stencilStrokePathInstanced(GLsizei numPaths,
2033 GLenum pathNameType,
2034 const void *paths,
2035 GLuint pathBase,
2036 GLint reference,
2037 GLuint mask,
2038 GLenum transformType,
2039 const GLfloat *transformValues)
2040{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002041 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002042
2043 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2044 syncRendererState();
2045
2046 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2047 transformValues);
2048}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002049
Sami Väisänend59ca052016-06-21 16:10:00 +03002050void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2051 GLenum pathNameType,
2052 const void *paths,
2053 GLuint pathBase,
2054 GLenum fillMode,
2055 GLuint mask,
2056 GLenum coverMode,
2057 GLenum transformType,
2058 const GLfloat *transformValues)
2059{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002060 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002061
2062 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2063 syncRendererState();
2064
2065 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2066 transformType, transformValues);
2067}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002068
Sami Väisänend59ca052016-06-21 16:10:00 +03002069void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2070 GLenum pathNameType,
2071 const void *paths,
2072 GLuint pathBase,
2073 GLint reference,
2074 GLuint mask,
2075 GLenum coverMode,
2076 GLenum transformType,
2077 const GLfloat *transformValues)
2078{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002079 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002080
2081 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2082 syncRendererState();
2083
2084 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2085 transformType, transformValues);
2086}
2087
Sami Väisänen46eaa942016-06-29 10:26:37 +03002088void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2089{
2090 auto *programObject = getProgram(program);
2091
2092 programObject->bindFragmentInputLocation(location, name);
2093}
2094
2095void Context::programPathFragmentInputGen(GLuint program,
2096 GLint location,
2097 GLenum genMode,
2098 GLint components,
2099 const GLfloat *coeffs)
2100{
2101 auto *programObject = getProgram(program);
2102
Jamie Madillbd044ed2017-06-05 12:59:21 -04002103 programObject->pathFragmentInputGen(this, location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002104}
2105
jchen1015015f72017-03-16 13:54:21 +08002106GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2107{
jchen10fd7c3b52017-03-21 15:36:03 +08002108 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002109 return QueryProgramResourceIndex(programObject, programInterface, name);
2110}
2111
jchen10fd7c3b52017-03-21 15:36:03 +08002112void Context::getProgramResourceName(GLuint program,
2113 GLenum programInterface,
2114 GLuint index,
2115 GLsizei bufSize,
2116 GLsizei *length,
2117 GLchar *name)
2118{
2119 const auto *programObject = getProgram(program);
2120 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2121}
2122
jchen10191381f2017-04-11 13:59:04 +08002123GLint Context::getProgramResourceLocation(GLuint program,
2124 GLenum programInterface,
2125 const GLchar *name)
2126{
2127 const auto *programObject = getProgram(program);
2128 return QueryProgramResourceLocation(programObject, programInterface, name);
2129}
2130
jchen10880683b2017-04-12 16:21:55 +08002131void Context::getProgramResourceiv(GLuint program,
2132 GLenum programInterface,
2133 GLuint index,
2134 GLsizei propCount,
2135 const GLenum *props,
2136 GLsizei bufSize,
2137 GLsizei *length,
2138 GLint *params)
2139{
2140 const auto *programObject = getProgram(program);
2141 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2142 length, params);
2143}
2144
jchen10d9cd7b72017-08-30 15:04:25 +08002145void Context::getProgramInterfaceiv(GLuint program,
2146 GLenum programInterface,
2147 GLenum pname,
2148 GLint *params)
2149{
2150 const auto *programObject = getProgram(program);
2151 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2152}
2153
Jamie Madill71c88b32017-09-14 22:20:29 -04002154void Context::handleError(const Error &error)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002155{
Geoff Langda5777c2014-07-11 09:52:58 -04002156 if (error.isError())
2157 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002158 GLenum code = error.getCode();
2159 mErrors.insert(code);
2160 if (code == GL_OUT_OF_MEMORY && getWorkarounds().loseContextOnOutOfMemory)
2161 {
2162 markContextLost();
2163 }
Geoff Lang70d0f492015-12-10 17:45:46 -05002164
2165 if (!error.getMessage().empty())
2166 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002167 auto *debug = &mGLState.getDebug();
2168 debug->insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, error.getID(),
2169 GL_DEBUG_SEVERITY_HIGH, error.getMessage());
Geoff Lang70d0f492015-12-10 17:45:46 -05002170 }
Geoff Langda5777c2014-07-11 09:52:58 -04002171 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002172}
2173
2174// Get one of the recorded errors and clear its flag, if any.
2175// [OpenGL ES 2.0.24] section 2.5 page 13.
2176GLenum Context::getError()
2177{
Geoff Langda5777c2014-07-11 09:52:58 -04002178 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002179 {
Geoff Langda5777c2014-07-11 09:52:58 -04002180 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002181 }
Geoff Langda5777c2014-07-11 09:52:58 -04002182 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002183 {
Geoff Langda5777c2014-07-11 09:52:58 -04002184 GLenum error = *mErrors.begin();
2185 mErrors.erase(mErrors.begin());
2186 return error;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002187 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002188}
2189
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002190// NOTE: this function should not assume that this context is current!
2191void Context::markContextLost()
2192{
2193 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002194 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002195 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002196 mContextLostForced = true;
2197 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002198 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002199}
2200
2201bool Context::isContextLost()
2202{
2203 return mContextLost;
2204}
2205
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002206GLenum Context::getResetStatus()
2207{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002208 // Even if the application doesn't want to know about resets, we want to know
2209 // as it will allow us to skip all the calls.
2210 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002211 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002212 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002213 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002214 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002215 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002216
2217 // EXT_robustness, section 2.6: If the reset notification behavior is
2218 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2219 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2220 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002221 }
2222
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002223 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2224 // status should be returned at least once, and GL_NO_ERROR should be returned
2225 // once the device has finished resetting.
2226 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002227 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002228 ASSERT(mResetStatus == GL_NO_ERROR);
2229 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002230
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002231 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002232 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002233 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002234 }
2235 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002236 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002237 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002238 // If markContextLost was used to mark the context lost then
2239 // assume that is not recoverable, and continue to report the
2240 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002241 mResetStatus = mImplementation->getResetStatus();
2242 }
Jamie Madill893ab082014-05-16 16:56:10 -04002243
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002244 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002245}
2246
2247bool Context::isResetNotificationEnabled()
2248{
2249 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2250}
2251
Corentin Walleze3b10e82015-05-20 11:06:25 -04002252const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002253{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002254 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002255}
2256
2257EGLenum Context::getClientType() const
2258{
2259 return mClientType;
2260}
2261
2262EGLenum Context::getRenderBuffer() const
2263{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002264 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2265 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002266 {
2267 return EGL_NONE;
2268 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002269
2270 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(GL_BACK);
2271 ASSERT(backAttachment != nullptr);
2272 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002273}
2274
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002275VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002276{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002277 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002278 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2279 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002280 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002281 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2282 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002283
Jamie Madill96a483b2017-06-27 16:49:21 -04002284 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002285 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002286
2287 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002288}
2289
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002290TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002291{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002292 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002293 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2294 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002295 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002296 transformFeedback =
2297 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002298 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002299 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002300 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002301
2302 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002303}
2304
2305bool Context::isVertexArrayGenerated(GLuint vertexArray)
2306{
Jamie Madill96a483b2017-06-27 16:49:21 -04002307 ASSERT(mVertexArrayMap.contains(0));
2308 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002309}
2310
2311bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2312{
Jamie Madill96a483b2017-06-27 16:49:21 -04002313 ASSERT(mTransformFeedbackMap.contains(0));
2314 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002315}
2316
Shannon Woods53a94a82014-06-24 15:20:36 -04002317void Context::detachTexture(GLuint texture)
2318{
2319 // Simple pass-through to State's detachTexture method, as textures do not require
2320 // allocation map management either here or in the resource manager at detach time.
2321 // Zero textures are held by the Context, and we don't attempt to request them from
2322 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002323 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002324}
2325
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002326void Context::detachBuffer(GLuint buffer)
2327{
Yuly Novikov5807a532015-12-03 13:01:22 -05002328 // Simple pass-through to State's detachBuffer method, since
2329 // only buffer attachments to container objects that are bound to the current context
2330 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002331
Yuly Novikov5807a532015-12-03 13:01:22 -05002332 // [OpenGL ES 3.2] section 5.1.2 page 45:
2333 // Attachments to unbound container objects, such as
2334 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2335 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002336 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002337}
2338
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002339void Context::detachFramebuffer(GLuint framebuffer)
2340{
Shannon Woods53a94a82014-06-24 15:20:36 -04002341 // Framebuffer detachment is handled by Context, because 0 is a valid
2342 // Framebuffer object, and a pointer to it must be passed from Context
2343 // to State at binding time.
2344
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002345 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002346 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2347 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2348 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002349
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002350 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002351 {
2352 bindReadFramebuffer(0);
2353 }
2354
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002355 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002356 {
2357 bindDrawFramebuffer(0);
2358 }
2359}
2360
2361void Context::detachRenderbuffer(GLuint renderbuffer)
2362{
Jamie Madilla02315b2017-02-23 14:14:47 -05002363 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002364}
2365
Jamie Madill57a89722013-07-02 11:57:03 -04002366void Context::detachVertexArray(GLuint vertexArray)
2367{
Jamie Madill77a72f62015-04-14 11:18:32 -04002368 // Vertex array detachment is handled by Context, because 0 is a valid
2369 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002370 // binding time.
2371
Jamie Madill57a89722013-07-02 11:57:03 -04002372 // [OpenGL ES 3.0.2] section 2.10 page 43:
2373 // If a vertex array object that is currently bound is deleted, the binding
2374 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002375 if (mGLState.removeVertexArrayBinding(vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002376 {
2377 bindVertexArray(0);
2378 }
2379}
2380
Geoff Langc8058452014-02-03 12:04:11 -05002381void Context::detachTransformFeedback(GLuint transformFeedback)
2382{
Corentin Walleza2257da2016-04-19 16:43:12 -04002383 // Transform feedback detachment is handled by Context, because 0 is a valid
2384 // transform feedback, and a pointer to it must be passed from Context to State at
2385 // binding time.
2386
2387 // The OpenGL specification doesn't mention what should happen when the currently bound
2388 // transform feedback object is deleted. Since it is a container object, we treat it like
2389 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002390 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002391 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002392 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002393 }
Geoff Langc8058452014-02-03 12:04:11 -05002394}
2395
Jamie Madilldc356042013-07-19 16:36:57 -04002396void Context::detachSampler(GLuint sampler)
2397{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002398 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002399}
2400
Yunchao Hea336b902017-08-02 16:05:21 +08002401void Context::detachProgramPipeline(GLuint pipeline)
2402{
2403 mGLState.detachProgramPipeline(this, pipeline);
2404}
2405
Jamie Madill3ef140a2017-08-26 23:11:21 -04002406void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002407{
Shaodde78e82017-05-22 14:13:27 +08002408 mGLState.setVertexAttribDivisor(this, index, divisor);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002409}
2410
Jamie Madille29d1672013-07-19 16:36:57 -04002411void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2412{
Geoff Langc1984ed2016-10-07 12:41:00 -04002413 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002414 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002415 SetSamplerParameteri(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002416 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002417}
Jamie Madille29d1672013-07-19 16:36:57 -04002418
Geoff Langc1984ed2016-10-07 12:41:00 -04002419void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2420{
2421 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002422 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002423 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002424 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002425}
2426
2427void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2428{
Geoff Langc1984ed2016-10-07 12:41:00 -04002429 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002430 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002431 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002432 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002433}
2434
Geoff Langc1984ed2016-10-07 12:41:00 -04002435void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002436{
Geoff Langc1984ed2016-10-07 12:41:00 -04002437 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002438 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002439 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002440 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002441}
2442
Geoff Langc1984ed2016-10-07 12:41:00 -04002443void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002444{
Geoff Langc1984ed2016-10-07 12:41:00 -04002445 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002446 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002447 QuerySamplerParameteriv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002448 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002449}
Jamie Madill9675b802013-07-19 16:36:59 -04002450
Geoff Langc1984ed2016-10-07 12:41:00 -04002451void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2452{
2453 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002454 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002455 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002456 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002457}
2458
Olli Etuahof0fee072016-03-30 15:11:58 +03002459void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2460{
2461 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002462 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002463}
2464
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002465void Context::initRendererString()
2466{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002467 std::ostringstream rendererString;
2468 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002469 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002470 rendererString << ")";
2471
Geoff Langcec35902014-04-16 10:52:36 -04002472 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002473}
2474
Geoff Langc339c4e2016-11-29 10:37:36 -05002475void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002476{
Geoff Langc339c4e2016-11-29 10:37:36 -05002477 const Version &clientVersion = getClientVersion();
2478
2479 std::ostringstream versionString;
2480 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2481 << ANGLE_VERSION_STRING << ")";
2482 mVersionString = MakeStaticString(versionString.str());
2483
2484 std::ostringstream shadingLanguageVersionString;
2485 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2486 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2487 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2488 << ")";
2489 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002490}
2491
Geoff Langcec35902014-04-16 10:52:36 -04002492void Context::initExtensionStrings()
2493{
Geoff Langc339c4e2016-11-29 10:37:36 -05002494 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2495 std::ostringstream combinedStringStream;
2496 std::copy(strings.begin(), strings.end(),
2497 std::ostream_iterator<const char *>(combinedStringStream, " "));
2498 return MakeStaticString(combinedStringStream.str());
2499 };
2500
2501 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002502 for (const auto &extensionString : mExtensions.getStrings())
2503 {
2504 mExtensionStrings.push_back(MakeStaticString(extensionString));
2505 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002506 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002507
Bryan Bernhart58806562017-01-05 13:09:31 -08002508 const gl::Extensions &nativeExtensions = mImplementation->getNativeExtensions();
2509
Geoff Langc339c4e2016-11-29 10:37:36 -05002510 mRequestableExtensionStrings.clear();
2511 for (const auto &extensionInfo : GetExtensionInfoMap())
2512 {
2513 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08002514 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
2515 nativeExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002516 {
2517 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
2518 }
2519 }
2520 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002521}
2522
Geoff Langc339c4e2016-11-29 10:37:36 -05002523const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04002524{
Geoff Langc339c4e2016-11-29 10:37:36 -05002525 switch (name)
2526 {
2527 case GL_VENDOR:
2528 return reinterpret_cast<const GLubyte *>("Google Inc.");
2529
2530 case GL_RENDERER:
2531 return reinterpret_cast<const GLubyte *>(mRendererString);
2532
2533 case GL_VERSION:
2534 return reinterpret_cast<const GLubyte *>(mVersionString);
2535
2536 case GL_SHADING_LANGUAGE_VERSION:
2537 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
2538
2539 case GL_EXTENSIONS:
2540 return reinterpret_cast<const GLubyte *>(mExtensionString);
2541
2542 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2543 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
2544
2545 default:
2546 UNREACHABLE();
2547 return nullptr;
2548 }
Geoff Langcec35902014-04-16 10:52:36 -04002549}
2550
Geoff Langc339c4e2016-11-29 10:37:36 -05002551const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04002552{
Geoff Langc339c4e2016-11-29 10:37:36 -05002553 switch (name)
2554 {
2555 case GL_EXTENSIONS:
2556 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
2557
2558 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2559 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
2560
2561 default:
2562 UNREACHABLE();
2563 return nullptr;
2564 }
Geoff Langcec35902014-04-16 10:52:36 -04002565}
2566
2567size_t Context::getExtensionStringCount() const
2568{
2569 return mExtensionStrings.size();
2570}
2571
Geoff Lang111a99e2017-10-17 10:58:41 -04002572bool Context::isExtensionRequestable(const char *name)
2573{
2574 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2575 auto extension = extensionInfos.find(name);
2576
2577 const Extensions &nativeExtensions = mImplementation->getNativeExtensions();
2578 return extension != extensionInfos.end() && extension->second.Requestable &&
2579 nativeExtensions.*(extension->second.ExtensionsMember);
2580}
2581
Geoff Langc339c4e2016-11-29 10:37:36 -05002582void Context::requestExtension(const char *name)
2583{
2584 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2585 ASSERT(extensionInfos.find(name) != extensionInfos.end());
2586 const auto &extension = extensionInfos.at(name);
2587 ASSERT(extension.Requestable);
Geoff Lang111a99e2017-10-17 10:58:41 -04002588 ASSERT(mImplementation->getNativeExtensions().*(extension.ExtensionsMember));
Geoff Langc339c4e2016-11-29 10:37:36 -05002589
2590 if (mExtensions.*(extension.ExtensionsMember))
2591 {
2592 // Extension already enabled
2593 return;
2594 }
2595
2596 mExtensions.*(extension.ExtensionsMember) = true;
2597 updateCaps();
2598 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08002599
Jamie Madill2f348d22017-06-05 10:50:59 -04002600 // Release the shader compiler so it will be re-created with the requested extensions enabled.
2601 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04002602
Jamie Madill81c2e252017-09-09 23:32:46 -04002603 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
2604 // sampleable.
2605 mState.mTextures->signalAllTexturesDirty();
Geoff Lang9aded172017-04-05 11:07:56 -04002606 for (auto &zeroTexture : mZeroTextures)
2607 {
Jamie Madill05b35b22017-10-03 09:01:44 -04002608 zeroTexture.second->signalDirty(InitState::Initialized);
Geoff Lang9aded172017-04-05 11:07:56 -04002609 }
2610
2611 mState.mFramebuffers->invalidateFramebufferComplenessCache();
Geoff Langc339c4e2016-11-29 10:37:36 -05002612}
2613
2614size_t Context::getRequestableExtensionStringCount() const
2615{
2616 return mRequestableExtensionStrings.size();
2617}
2618
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002619void Context::beginTransformFeedback(GLenum primitiveMode)
2620{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002621 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002622 ASSERT(transformFeedback != nullptr);
2623 ASSERT(!transformFeedback->isPaused());
2624
Jamie Madill6c1f6712017-02-14 19:08:04 -05002625 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002626}
2627
2628bool Context::hasActiveTransformFeedback(GLuint program) const
2629{
2630 for (auto pair : mTransformFeedbackMap)
2631 {
2632 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
2633 {
2634 return true;
2635 }
2636 }
2637 return false;
2638}
2639
Geoff Langb433e872017-10-05 14:01:47 -04002640void Context::initCaps(const egl::DisplayExtensions &displayExtensions, bool robustResourceInit)
Geoff Lang493daf52014-07-03 13:38:44 -04002641{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002642 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04002643
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002644 mExtensions = mImplementation->getNativeExtensions();
Geoff Lang493daf52014-07-03 13:38:44 -04002645
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002646 mLimitations = mImplementation->getNativeLimitations();
Austin Kinross02df7962015-07-01 10:03:42 -07002647
Geoff Langeb66a6e2016-10-31 13:06:12 -04002648 if (getClientVersion() < Version(3, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002649 {
2650 // Disable ES3+ extensions
Jamie Madill231c7f52017-04-26 13:45:37 -04002651 mExtensions.colorBufferFloat = false;
Geoff Langb66a9092016-05-16 15:59:14 -04002652 mExtensions.eglImageExternalEssl3 = false;
Vincent Lang25ab4512016-05-13 18:13:59 +02002653 mExtensions.textureNorm16 = false;
Martin Radev137032d2017-07-13 10:11:12 +03002654 mExtensions.multiview = false;
2655 mExtensions.maxViews = 1u;
Geoff Lang493daf52014-07-03 13:38:44 -04002656 }
2657
Geoff Langeb66a6e2016-10-31 13:06:12 -04002658 if (getClientVersion() > Version(2, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002659 {
2660 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
Jamie Madill231c7f52017-04-26 13:45:37 -04002661 // mExtensions.sRGB = false;
Geoff Lang493daf52014-07-03 13:38:44 -04002662 }
2663
Jamie Madill00ed7a12016-05-19 13:13:38 -04002664 // Some extensions are always available because they are implemented in the GL layer.
Jamie Madill231c7f52017-04-26 13:45:37 -04002665 mExtensions.bindUniformLocation = true;
2666 mExtensions.vertexArrayObject = true;
Geoff Langf41a7152016-09-19 15:11:17 -04002667 mExtensions.bindGeneratesResource = true;
Geoff Langfeb8c682017-02-13 16:07:35 -05002668 mExtensions.clientArrays = true;
Geoff Langc339c4e2016-11-29 10:37:36 -05002669 mExtensions.requestExtension = true;
Jamie Madill00ed7a12016-05-19 13:13:38 -04002670
2671 // Enable the no error extension if the context was created with the flag.
2672 mExtensions.noError = mSkipValidation;
2673
Corentin Wallezccab69d2017-01-27 16:57:15 -05002674 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Corentin Wallezc295e512017-01-27 17:47:50 -05002675 mExtensions.surfacelessContext = displayExtensions.surfacelessContext;
Corentin Wallezccab69d2017-01-27 16:57:15 -05002676
Geoff Lang70d0f492015-12-10 17:45:46 -05002677 // Explicitly enable GL_KHR_debug
2678 mExtensions.debug = true;
2679 mExtensions.maxDebugMessageLength = 1024;
2680 mExtensions.maxDebugLoggedMessages = 1024;
2681 mExtensions.maxDebugGroupStackDepth = 1024;
2682 mExtensions.maxLabelLength = 1024;
2683
Geoff Langff5b2d52016-09-07 11:32:23 -04002684 // Explicitly enable GL_ANGLE_robust_client_memory
2685 mExtensions.robustClientMemory = true;
2686
Jamie Madille08a1d32017-03-07 17:24:06 -05002687 // Determine robust resource init availability from EGL.
Geoff Langb433e872017-10-05 14:01:47 -04002688 mExtensions.robustResourceInitialization = robustResourceInit;
Jamie Madille08a1d32017-03-07 17:24:06 -05002689
Jiajia Qin8a7b3a02017-08-25 16:05:48 +08002690 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
2691 // supports it.
2692 mExtensions.robustBufferAccessBehavior =
2693 mRobustAccess && mExtensions.robustBufferAccessBehavior;
2694
Jamie Madillc43be722017-07-13 16:22:14 -04002695 // Enable the cache control query unconditionally.
2696 mExtensions.programCacheControl = true;
2697
Geoff Lang301d1612014-07-09 10:34:37 -04002698 // Apply implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04002699 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002700
Jamie Madill0f80ed82017-09-19 00:24:56 -04002701 if (getClientVersion() < ES_3_1)
2702 {
2703 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
2704 }
2705 else
2706 {
2707 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
2708 }
Geoff Lang301d1612014-07-09 10:34:37 -04002709
Jamie Madill0f80ed82017-09-19 00:24:56 -04002710 LimitCap(&mCaps.maxVertexUniformBlocks, IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
2711 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
2712 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
2713
2714 // Limit textures as well, so we can use fast bitsets with texture bindings.
2715 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
2716 LimitCap(&mCaps.maxVertexTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
2717 LimitCap(&mCaps.maxTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04002718
Jiawei Shaodb342272017-09-27 10:21:45 +08002719 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
2720
Geoff Langc287ea62016-09-16 14:46:51 -04002721 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002722 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04002723 for (const auto &extensionInfo : GetExtensionInfoMap())
2724 {
2725 // If this context is for WebGL, disable all enableable extensions
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002726 if (mWebGLContext && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04002727 {
2728 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
2729 }
2730 }
2731
2732 // Generate texture caps
2733 updateCaps();
2734}
2735
2736void Context::updateCaps()
2737{
Geoff Lang900013c2014-07-07 11:32:19 -04002738 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002739 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04002740
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002741 for (auto capsIt : mImplementation->getNativeTextureCaps())
Geoff Lang493daf52014-07-03 13:38:44 -04002742 {
Geoff Langca271392017-04-05 12:30:00 -04002743 GLenum sizedInternalFormat = capsIt.first;
Jamie Madill231c7f52017-04-26 13:45:37 -04002744 TextureCaps formatCaps = capsIt.second;
Geoff Lang493daf52014-07-03 13:38:44 -04002745
Geoff Langca271392017-04-05 12:30:00 -04002746 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04002747
Geoff Lang0d8b7242015-09-09 14:56:53 -04002748 // Update the format caps based on the client version and extensions.
2749 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
2750 // ES3.
2751 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002752 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002753 formatCaps.renderable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002754 formatCaps.renderable && formatInfo.renderSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002755 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002756 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04002757
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002758 // OpenGL ES does not support multisampling with non-rendererable formats
2759 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Olli Etuaho50c562d2017-06-06 14:43:30 +03002760 if (!formatCaps.renderable ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002761 (getClientVersion() < ES_3_1 &&
2762 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04002763 {
Geoff Langd87878e2014-09-19 15:42:59 -04002764 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04002765 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03002766 else
2767 {
2768 // We may have limited the max samples for some required renderbuffer formats due to
2769 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
2770 GLuint formatMaxSamples = formatCaps.getMaxSamples();
2771
2772 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
2773 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
2774 // exception of signed and unsigned integer formats."
2775 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
2776 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
2777 {
2778 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
2779 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
2780 }
2781
2782 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
2783 if (getClientVersion() >= ES_3_1)
2784 {
2785 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
2786 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
2787 // the exception that the signed and unsigned integer formats are required only to
2788 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
2789 // multisamples, which must be at least one."
2790 if (formatInfo.componentType == GL_INT ||
2791 formatInfo.componentType == GL_UNSIGNED_INT)
2792 {
2793 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
2794 }
2795
2796 // GLES 3.1 section 19.3.1.
2797 if (formatCaps.texturable)
2798 {
2799 if (formatInfo.depthBits > 0)
2800 {
2801 mCaps.maxDepthTextureSamples =
2802 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
2803 }
2804 else if (formatInfo.redBits > 0)
2805 {
2806 mCaps.maxColorTextureSamples =
2807 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
2808 }
2809 }
2810 }
2811 }
Geoff Langd87878e2014-09-19 15:42:59 -04002812
2813 if (formatCaps.texturable && formatInfo.compressed)
2814 {
Geoff Langca271392017-04-05 12:30:00 -04002815 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04002816 }
2817
Geoff Langca271392017-04-05 12:30:00 -04002818 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04002819 }
Jamie Madill32447362017-06-28 14:53:52 -04002820
2821 // If program binary is disabled, blank out the memory cache pointer.
2822 if (!mImplementation->getNativeExtensions().getProgramBinary)
2823 {
2824 mMemoryProgramCache = nullptr;
2825 }
Geoff Lang493daf52014-07-03 13:38:44 -04002826}
2827
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002828void Context::initWorkarounds()
2829{
Jamie Madill761b02c2017-06-23 16:27:06 -04002830 // Apply back-end workarounds.
2831 mImplementation->applyNativeWorkarounds(&mWorkarounds);
2832
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002833 // Lose the context upon out of memory error if the application is
2834 // expecting to watch for those events.
2835 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2836}
2837
Jamie Madill05b35b22017-10-03 09:01:44 -04002838Error Context::prepareForDraw()
2839{
2840 syncRendererState();
Jamie Madilla59fc192017-11-02 12:57:58 -04002841
2842 if (isRobustResourceInitEnabled())
2843 {
2844 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
2845 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
2846 }
2847
Jamie Madill05b35b22017-10-03 09:01:44 -04002848 return NoError();
2849}
2850
Jamie Madill1b94d432015-08-07 13:23:23 -04002851void Context::syncRendererState()
2852{
Jamie Madill7d1f5c62017-09-02 15:32:15 -04002853 mGLState.syncDirtyObjects(this);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002854 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
Jamie Madillfe548342017-06-19 11:13:24 -04002855 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002856 mGLState.clearDirtyBits();
Jamie Madill1b94d432015-08-07 13:23:23 -04002857}
2858
Jamie Madillad9f24e2016-02-12 09:27:24 -05002859void Context::syncRendererState(const State::DirtyBits &bitMask,
2860 const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04002861{
Jamie Madill7d1f5c62017-09-02 15:32:15 -04002862 mGLState.syncDirtyObjects(this, objectMask);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002863 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madillfe548342017-06-19 11:13:24 -04002864 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002865 mGLState.clearDirtyBits(dirtyBits);
Jamie Madill1b94d432015-08-07 13:23:23 -04002866}
Jamie Madillc29968b2016-01-20 11:17:23 -05002867
2868void Context::blitFramebuffer(GLint srcX0,
2869 GLint srcY0,
2870 GLint srcX1,
2871 GLint srcY1,
2872 GLint dstX0,
2873 GLint dstY0,
2874 GLint dstX1,
2875 GLint dstY1,
2876 GLbitfield mask,
2877 GLenum filter)
2878{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002879 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002880 ASSERT(drawFramebuffer);
2881
2882 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
2883 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
2884
Jamie Madillad9f24e2016-02-12 09:27:24 -05002885 syncStateForBlit();
Jamie Madillc29968b2016-01-20 11:17:23 -05002886
Jamie Madillc564c072017-06-01 12:45:42 -04002887 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002888}
Jamie Madillc29968b2016-01-20 11:17:23 -05002889
2890void Context::clear(GLbitfield mask)
2891{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002892 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002893 handleError(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05002894}
2895
2896void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
2897{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002898 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002899 handleError(mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002900}
2901
2902void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
2903{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002904 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002905 handleError(mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002906}
2907
2908void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
2909{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002910 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002911 handleError(mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002912}
2913
2914void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
2915{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002916 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002917 ASSERT(framebufferObject);
2918
2919 // If a buffer is not present, the clear has no effect
2920 if (framebufferObject->getDepthbuffer() == nullptr &&
2921 framebufferObject->getStencilbuffer() == nullptr)
2922 {
2923 return;
2924 }
2925
Jamie Madillad9f24e2016-02-12 09:27:24 -05002926 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002927 handleError(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05002928}
2929
2930void Context::readPixels(GLint x,
2931 GLint y,
2932 GLsizei width,
2933 GLsizei height,
2934 GLenum format,
2935 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002936 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05002937{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04002938 if (width == 0 || height == 0)
2939 {
2940 return;
2941 }
2942
Jamie Madillad9f24e2016-02-12 09:27:24 -05002943 syncStateForReadPixels();
Jamie Madillc29968b2016-01-20 11:17:23 -05002944
Jamie Madillb6664922017-07-25 12:55:04 -04002945 Framebuffer *readFBO = mGLState.getReadFramebuffer();
2946 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05002947
2948 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04002949 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05002950}
2951
2952void Context::copyTexImage2D(GLenum target,
2953 GLint level,
2954 GLenum internalformat,
2955 GLint x,
2956 GLint y,
2957 GLsizei width,
2958 GLsizei height,
2959 GLint border)
2960{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002961 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002962 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002963
Jamie Madillc29968b2016-01-20 11:17:23 -05002964 Rectangle sourceArea(x, y, width, height);
2965
Jamie Madill05b35b22017-10-03 09:01:44 -04002966 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002967 Texture *texture =
2968 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05002969 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05002970}
2971
2972void Context::copyTexSubImage2D(GLenum target,
2973 GLint level,
2974 GLint xoffset,
2975 GLint yoffset,
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, 0);
2990 Rectangle sourceArea(x, y, width, height);
2991
Jamie Madill05b35b22017-10-03 09:01:44 -04002992 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002993 Texture *texture =
2994 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05002995 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05002996}
2997
2998void Context::copyTexSubImage3D(GLenum target,
2999 GLint level,
3000 GLint xoffset,
3001 GLint yoffset,
3002 GLint zoffset,
3003 GLint x,
3004 GLint y,
3005 GLsizei width,
3006 GLsizei height)
3007{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003008 if (width == 0 || height == 0)
3009 {
3010 return;
3011 }
3012
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003013 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003014 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003015
Jamie Madillc29968b2016-01-20 11:17:23 -05003016 Offset destOffset(xoffset, yoffset, zoffset);
3017 Rectangle sourceArea(x, y, width, height);
3018
Jamie Madill05b35b22017-10-03 09:01:44 -04003019 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3020 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003021 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003022}
3023
3024void Context::framebufferTexture2D(GLenum target,
3025 GLenum attachment,
3026 GLenum textarget,
3027 GLuint texture,
3028 GLint level)
3029{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003030 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003031 ASSERT(framebuffer);
3032
3033 if (texture != 0)
3034 {
3035 Texture *textureObj = getTexture(texture);
3036
3037 ImageIndex index = ImageIndex::MakeInvalid();
3038
3039 if (textarget == GL_TEXTURE_2D)
3040 {
3041 index = ImageIndex::Make2D(level);
3042 }
Corentin Wallez13c0dd42017-07-04 18:27:01 -04003043 else if (textarget == GL_TEXTURE_RECTANGLE_ANGLE)
3044 {
3045 index = ImageIndex::MakeRectangle(level);
3046 }
JiangYizhoubddc46b2016-12-09 09:50:51 +08003047 else if (textarget == GL_TEXTURE_2D_MULTISAMPLE)
3048 {
3049 ASSERT(level == 0);
3050 index = ImageIndex::Make2DMultisample();
3051 }
Jamie Madillc29968b2016-01-20 11:17:23 -05003052 else
3053 {
3054 ASSERT(IsCubeMapTextureTarget(textarget));
3055 index = ImageIndex::MakeCube(textarget, level);
3056 }
3057
Jamie Madilla02315b2017-02-23 14:14:47 -05003058 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003059 }
3060 else
3061 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003062 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003063 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003064
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003065 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003066}
3067
3068void Context::framebufferRenderbuffer(GLenum target,
3069 GLenum attachment,
3070 GLenum renderbuffertarget,
3071 GLuint renderbuffer)
3072{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003073 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003074 ASSERT(framebuffer);
3075
3076 if (renderbuffer != 0)
3077 {
3078 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003079
3080 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex::MakeInvalid(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003081 renderbufferObject);
3082 }
3083 else
3084 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003085 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003086 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003087
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003088 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003089}
3090
3091void Context::framebufferTextureLayer(GLenum target,
3092 GLenum attachment,
3093 GLuint texture,
3094 GLint level,
3095 GLint layer)
3096{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003097 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003098 ASSERT(framebuffer);
3099
3100 if (texture != 0)
3101 {
3102 Texture *textureObject = getTexture(texture);
3103
3104 ImageIndex index = ImageIndex::MakeInvalid();
3105
3106 if (textureObject->getTarget() == GL_TEXTURE_3D)
3107 {
3108 index = ImageIndex::Make3D(level, layer);
3109 }
3110 else
3111 {
3112 ASSERT(textureObject->getTarget() == GL_TEXTURE_2D_ARRAY);
3113 index = ImageIndex::Make2DArray(level, layer);
3114 }
3115
Jamie Madilla02315b2017-02-23 14:14:47 -05003116 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003117 }
3118 else
3119 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003120 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003121 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003122
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003123 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003124}
3125
Martin Radev137032d2017-07-13 10:11:12 +03003126void Context::framebufferTextureMultiviewLayeredANGLE(GLenum target,
3127 GLenum attachment,
3128 GLuint texture,
3129 GLint level,
3130 GLint baseViewIndex,
3131 GLsizei numViews)
3132{
Martin Radev82ef7742017-08-08 17:44:58 +03003133 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3134 ASSERT(framebuffer);
3135
3136 if (texture != 0)
3137 {
3138 Texture *textureObj = getTexture(texture);
3139
Martin Radev18b75ba2017-08-15 15:50:40 +03003140 ImageIndex index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
Martin Radev82ef7742017-08-08 17:44:58 +03003141 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3142 numViews, baseViewIndex);
3143 }
3144 else
3145 {
3146 framebuffer->resetAttachment(this, attachment);
3147 }
3148
3149 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003150}
3151
3152void Context::framebufferTextureMultiviewSideBySideANGLE(GLenum target,
3153 GLenum attachment,
3154 GLuint texture,
3155 GLint level,
3156 GLsizei numViews,
3157 const GLint *viewportOffsets)
3158{
Martin Radev5dae57b2017-07-14 16:15:55 +03003159 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3160 ASSERT(framebuffer);
3161
3162 if (texture != 0)
3163 {
3164 Texture *textureObj = getTexture(texture);
3165
3166 ImageIndex index = ImageIndex::Make2D(level);
3167 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3168 textureObj, numViews, viewportOffsets);
3169 }
3170 else
3171 {
3172 framebuffer->resetAttachment(this, attachment);
3173 }
3174
3175 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003176}
3177
Jamie Madillc29968b2016-01-20 11:17:23 -05003178void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3179{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003180 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003181 ASSERT(framebuffer);
3182 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003183 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003184}
3185
3186void Context::readBuffer(GLenum mode)
3187{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003188 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003189 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003190 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003191}
3192
3193void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3194{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003195 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003196 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003197
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003198 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003199 ASSERT(framebuffer);
3200
3201 // The specification isn't clear what should be done when the framebuffer isn't complete.
3202 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003203 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003204}
3205
3206void Context::invalidateFramebuffer(GLenum target,
3207 GLsizei numAttachments,
3208 const GLenum *attachments)
3209{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003210 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003211 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003212
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003213 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003214 ASSERT(framebuffer);
3215
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003216 if (framebuffer->checkStatus(this) != GL_FRAMEBUFFER_COMPLETE)
Jamie Madillc29968b2016-01-20 11:17:23 -05003217 {
Jamie Madill437fa652016-05-03 15:13:24 -04003218 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003219 }
Jamie Madill437fa652016-05-03 15:13:24 -04003220
Jamie Madill4928b7c2017-06-20 12:57:39 -04003221 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003222}
3223
3224void Context::invalidateSubFramebuffer(GLenum target,
3225 GLsizei numAttachments,
3226 const GLenum *attachments,
3227 GLint x,
3228 GLint y,
3229 GLsizei width,
3230 GLsizei height)
3231{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003232 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003233 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003234
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003235 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003236 ASSERT(framebuffer);
3237
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003238 if (framebuffer->checkStatus(this) != GL_FRAMEBUFFER_COMPLETE)
Jamie Madillc29968b2016-01-20 11:17:23 -05003239 {
Jamie Madill437fa652016-05-03 15:13:24 -04003240 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003241 }
Jamie Madill437fa652016-05-03 15:13:24 -04003242
3243 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003244 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003245}
3246
Jamie Madill73a84962016-02-12 09:27:23 -05003247void Context::texImage2D(GLenum target,
3248 GLint level,
3249 GLint internalformat,
3250 GLsizei width,
3251 GLsizei height,
3252 GLint border,
3253 GLenum format,
3254 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003255 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003256{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003257 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003258
3259 Extents size(width, height, 1);
3260 Texture *texture =
3261 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003262 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3263 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003264}
3265
3266void Context::texImage3D(GLenum target,
3267 GLint level,
3268 GLint internalformat,
3269 GLsizei width,
3270 GLsizei height,
3271 GLsizei depth,
3272 GLint border,
3273 GLenum format,
3274 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003275 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003276{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003277 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003278
3279 Extents size(width, height, depth);
3280 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003281 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3282 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003283}
3284
3285void Context::texSubImage2D(GLenum target,
3286 GLint level,
3287 GLint xoffset,
3288 GLint yoffset,
3289 GLsizei width,
3290 GLsizei height,
3291 GLenum format,
3292 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003293 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003294{
3295 // Zero sized uploads are valid but no-ops
3296 if (width == 0 || height == 0)
3297 {
3298 return;
3299 }
3300
Jamie Madillad9f24e2016-02-12 09:27:24 -05003301 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003302
3303 Box area(xoffset, yoffset, 0, width, height, 1);
3304 Texture *texture =
3305 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003306 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3307 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003308}
3309
3310void Context::texSubImage3D(GLenum target,
3311 GLint level,
3312 GLint xoffset,
3313 GLint yoffset,
3314 GLint zoffset,
3315 GLsizei width,
3316 GLsizei height,
3317 GLsizei depth,
3318 GLenum format,
3319 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003320 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003321{
3322 // Zero sized uploads are valid but no-ops
3323 if (width == 0 || height == 0 || depth == 0)
3324 {
3325 return;
3326 }
3327
Jamie Madillad9f24e2016-02-12 09:27:24 -05003328 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003329
3330 Box area(xoffset, yoffset, zoffset, width, height, depth);
3331 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003332 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3333 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003334}
3335
3336void Context::compressedTexImage2D(GLenum target,
3337 GLint level,
3338 GLenum internalformat,
3339 GLsizei width,
3340 GLsizei height,
3341 GLint border,
3342 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003343 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003344{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003345 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003346
3347 Extents size(width, height, 1);
3348 Texture *texture =
3349 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003350 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003351 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003352 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003353}
3354
3355void Context::compressedTexImage3D(GLenum target,
3356 GLint level,
3357 GLenum internalformat,
3358 GLsizei width,
3359 GLsizei height,
3360 GLsizei depth,
3361 GLint border,
3362 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003363 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003364{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003365 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003366
3367 Extents size(width, height, depth);
3368 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003369 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003370 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003371 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003372}
3373
3374void Context::compressedTexSubImage2D(GLenum target,
3375 GLint level,
3376 GLint xoffset,
3377 GLint yoffset,
3378 GLsizei width,
3379 GLsizei height,
3380 GLenum format,
3381 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003382 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003383{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003384 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003385
3386 Box area(xoffset, yoffset, 0, width, height, 1);
3387 Texture *texture =
3388 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003389 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003390 format, imageSize,
3391 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003392}
3393
3394void Context::compressedTexSubImage3D(GLenum target,
3395 GLint level,
3396 GLint xoffset,
3397 GLint yoffset,
3398 GLint zoffset,
3399 GLsizei width,
3400 GLsizei height,
3401 GLsizei depth,
3402 GLenum format,
3403 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003404 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003405{
3406 // Zero sized uploads are valid but no-ops
3407 if (width == 0 || height == 0)
3408 {
3409 return;
3410 }
3411
Jamie Madillad9f24e2016-02-12 09:27:24 -05003412 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003413
3414 Box area(xoffset, yoffset, zoffset, width, height, depth);
3415 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003416 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003417 format, imageSize,
3418 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003419}
3420
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003421void Context::generateMipmap(GLenum target)
3422{
3423 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003424 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003425}
3426
Geoff Lang97073d12016-04-20 10:42:34 -07003427void Context::copyTextureCHROMIUM(GLuint sourceId,
Geoff Langfc72a072017-03-24 14:52:39 -04003428 GLint sourceLevel,
3429 GLenum destTarget,
Geoff Lang97073d12016-04-20 10:42:34 -07003430 GLuint destId,
Geoff Langfc72a072017-03-24 14:52:39 -04003431 GLint destLevel,
Geoff Lang97073d12016-04-20 10:42:34 -07003432 GLint internalFormat,
3433 GLenum destType,
3434 GLboolean unpackFlipY,
3435 GLboolean unpackPremultiplyAlpha,
3436 GLboolean unpackUnmultiplyAlpha)
3437{
3438 syncStateForTexImage();
3439
3440 gl::Texture *sourceTexture = getTexture(sourceId);
3441 gl::Texture *destTexture = getTexture(destId);
Geoff Langfc72a072017-03-24 14:52:39 -04003442 handleError(destTexture->copyTexture(
3443 this, destTarget, destLevel, internalFormat, destType, sourceLevel, unpackFlipY == GL_TRUE,
3444 unpackPremultiplyAlpha == GL_TRUE, unpackUnmultiplyAlpha == GL_TRUE, sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003445}
3446
3447void Context::copySubTextureCHROMIUM(GLuint sourceId,
Geoff Langfc72a072017-03-24 14:52:39 -04003448 GLint sourceLevel,
3449 GLenum destTarget,
Geoff Lang97073d12016-04-20 10:42:34 -07003450 GLuint destId,
Geoff Langfc72a072017-03-24 14:52:39 -04003451 GLint destLevel,
Geoff Lang97073d12016-04-20 10:42:34 -07003452 GLint xoffset,
3453 GLint yoffset,
3454 GLint x,
3455 GLint y,
3456 GLsizei width,
3457 GLsizei height,
3458 GLboolean unpackFlipY,
3459 GLboolean unpackPremultiplyAlpha,
3460 GLboolean unpackUnmultiplyAlpha)
3461{
3462 // Zero sized copies are valid but no-ops
3463 if (width == 0 || height == 0)
3464 {
3465 return;
3466 }
3467
3468 syncStateForTexImage();
3469
3470 gl::Texture *sourceTexture = getTexture(sourceId);
3471 gl::Texture *destTexture = getTexture(destId);
3472 Offset offset(xoffset, yoffset, 0);
3473 Rectangle area(x, y, width, height);
Geoff Langfc72a072017-03-24 14:52:39 -04003474 handleError(destTexture->copySubTexture(
3475 this, destTarget, destLevel, offset, sourceLevel, area, unpackFlipY == GL_TRUE,
3476 unpackPremultiplyAlpha == GL_TRUE, unpackUnmultiplyAlpha == GL_TRUE, sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003477}
3478
Geoff Lang47110bf2016-04-20 11:13:22 -07003479void Context::compressedCopyTextureCHROMIUM(GLuint sourceId, GLuint destId)
3480{
3481 syncStateForTexImage();
3482
3483 gl::Texture *sourceTexture = getTexture(sourceId);
3484 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05003485 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07003486}
3487
Geoff Lang496c02d2016-10-20 11:38:11 -07003488void Context::getBufferPointerv(GLenum target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03003489{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003490 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003491 ASSERT(buffer);
3492
Geoff Lang496c02d2016-10-20 11:38:11 -07003493 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03003494}
3495
Jamie Madill876429b2017-04-20 15:46:24 -04003496void *Context::mapBuffer(GLenum target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003497{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003498 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003499 ASSERT(buffer);
3500
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003501 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003502 if (error.isError())
3503 {
Jamie Madill437fa652016-05-03 15:13:24 -04003504 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003505 return nullptr;
3506 }
3507
3508 return buffer->getMapPointer();
3509}
3510
3511GLboolean Context::unmapBuffer(GLenum target)
3512{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003513 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003514 ASSERT(buffer);
3515
3516 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003517 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03003518 if (error.isError())
3519 {
Jamie Madill437fa652016-05-03 15:13:24 -04003520 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003521 return GL_FALSE;
3522 }
3523
3524 return result;
3525}
3526
Jamie Madill876429b2017-04-20 15:46:24 -04003527void *Context::mapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003528{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003529 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003530 ASSERT(buffer);
3531
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003532 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003533 if (error.isError())
3534 {
Jamie Madill437fa652016-05-03 15:13:24 -04003535 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003536 return nullptr;
3537 }
3538
3539 return buffer->getMapPointer();
3540}
3541
3542void Context::flushMappedBufferRange(GLenum /*target*/, GLintptr /*offset*/, GLsizeiptr /*length*/)
3543{
3544 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
3545}
3546
Jamie Madillad9f24e2016-02-12 09:27:24 -05003547void Context::syncStateForReadPixels()
3548{
3549 syncRendererState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
3550}
3551
3552void Context::syncStateForTexImage()
3553{
3554 syncRendererState(mTexImageDirtyBits, mTexImageDirtyObjects);
3555}
3556
3557void Context::syncStateForClear()
3558{
3559 syncRendererState(mClearDirtyBits, mClearDirtyObjects);
3560}
3561
3562void Context::syncStateForBlit()
3563{
3564 syncRendererState(mBlitDirtyBits, mBlitDirtyObjects);
3565}
3566
Jamie Madillc20ab272016-06-09 07:20:46 -07003567void Context::activeTexture(GLenum texture)
3568{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003569 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003570}
3571
Jamie Madill876429b2017-04-20 15:46:24 -04003572void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003573{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003574 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07003575}
3576
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003577void Context::blendEquation(GLenum mode)
3578{
3579 mGLState.setBlendEquation(mode, mode);
3580}
3581
Jamie Madillc20ab272016-06-09 07:20:46 -07003582void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
3583{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003584 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003585}
3586
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003587void Context::blendFunc(GLenum sfactor, GLenum dfactor)
3588{
3589 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
3590}
3591
Jamie Madillc20ab272016-06-09 07:20:46 -07003592void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
3593{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003594 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003595}
3596
Jamie Madill876429b2017-04-20 15:46:24 -04003597void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003598{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003599 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003600}
3601
Jamie Madill876429b2017-04-20 15:46:24 -04003602void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07003603{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003604 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07003605}
3606
3607void Context::clearStencil(GLint s)
3608{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003609 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07003610}
3611
3612void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
3613{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003614 mGLState.setColorMask(red == GL_TRUE, green == GL_TRUE, blue == GL_TRUE, alpha == GL_TRUE);
Jamie Madillc20ab272016-06-09 07:20:46 -07003615}
3616
Corentin Wallez2e568cf2017-09-18 17:05:22 -04003617void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07003618{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003619 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003620}
3621
3622void Context::depthFunc(GLenum func)
3623{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003624 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07003625}
3626
3627void Context::depthMask(GLboolean flag)
3628{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003629 mGLState.setDepthMask(flag != GL_FALSE);
Jamie Madillc20ab272016-06-09 07:20:46 -07003630}
3631
Jamie Madill876429b2017-04-20 15:46:24 -04003632void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07003633{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003634 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07003635}
3636
3637void Context::disable(GLenum cap)
3638{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003639 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003640}
3641
3642void Context::disableVertexAttribArray(GLuint index)
3643{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003644 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003645}
3646
3647void Context::enable(GLenum cap)
3648{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003649 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003650}
3651
3652void Context::enableVertexAttribArray(GLuint index)
3653{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003654 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003655}
3656
3657void Context::frontFace(GLenum mode)
3658{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003659 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003660}
3661
3662void Context::hint(GLenum target, GLenum mode)
3663{
3664 switch (target)
3665 {
3666 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003667 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003668 break;
3669
3670 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003671 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003672 break;
3673
3674 default:
3675 UNREACHABLE();
3676 return;
3677 }
3678}
3679
3680void Context::lineWidth(GLfloat width)
3681{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003682 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07003683}
3684
3685void Context::pixelStorei(GLenum pname, GLint param)
3686{
3687 switch (pname)
3688 {
3689 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003690 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003691 break;
3692
3693 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003694 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003695 break;
3696
3697 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003698 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003699 break;
3700
3701 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003702 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003703 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003704 break;
3705
3706 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03003707 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003708 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003709 break;
3710
3711 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03003712 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003713 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003714 break;
3715
3716 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003717 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003718 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003719 break;
3720
3721 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003722 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003723 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003724 break;
3725
3726 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003727 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003728 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003729 break;
3730
3731 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003732 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003733 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003734 break;
3735
3736 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003737 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003738 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003739 break;
3740
3741 default:
3742 UNREACHABLE();
3743 return;
3744 }
3745}
3746
3747void Context::polygonOffset(GLfloat factor, GLfloat units)
3748{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003749 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07003750}
3751
Jamie Madill876429b2017-04-20 15:46:24 -04003752void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07003753{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003754 mGLState.setSampleCoverageParams(clamp01(value), invert == GL_TRUE);
Jamie Madillc20ab272016-06-09 07:20:46 -07003755}
3756
Jiawei Shaodb342272017-09-27 10:21:45 +08003757void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
3758{
3759 mGLState.setSampleMaskParams(maskNumber, mask);
3760}
3761
Jamie Madillc20ab272016-06-09 07:20:46 -07003762void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
3763{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003764 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07003765}
3766
3767void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
3768{
3769 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3770 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003771 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003772 }
3773
3774 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3775 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003776 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003777 }
3778}
3779
3780void Context::stencilMaskSeparate(GLenum face, GLuint mask)
3781{
3782 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3783 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003784 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003785 }
3786
3787 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3788 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003789 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003790 }
3791}
3792
3793void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
3794{
3795 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3796 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003797 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003798 }
3799
3800 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3801 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003802 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003803 }
3804}
3805
3806void Context::vertexAttrib1f(GLuint index, GLfloat x)
3807{
3808 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003809 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003810}
3811
3812void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
3813{
3814 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003815 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003816}
3817
3818void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
3819{
3820 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003821 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003822}
3823
3824void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
3825{
3826 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003827 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003828}
3829
3830void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
3831{
3832 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003833 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003834}
3835
3836void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
3837{
3838 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003839 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003840}
3841
3842void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
3843{
3844 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003845 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003846}
3847
3848void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
3849{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003850 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07003851}
3852
3853void Context::vertexAttribPointer(GLuint index,
3854 GLint size,
3855 GLenum type,
3856 GLboolean normalized,
3857 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04003858 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07003859{
Shaodde78e82017-05-22 14:13:27 +08003860 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(GL_ARRAY_BUFFER), size,
3861 type, normalized == GL_TRUE, false, stride, ptr);
Jamie Madillc20ab272016-06-09 07:20:46 -07003862}
3863
Shao80957d92017-02-20 21:25:59 +08003864void Context::vertexAttribFormat(GLuint attribIndex,
3865 GLint size,
3866 GLenum type,
3867 GLboolean normalized,
3868 GLuint relativeOffset)
3869{
3870 mGLState.setVertexAttribFormat(attribIndex, size, type, normalized == GL_TRUE, false,
3871 relativeOffset);
3872}
3873
3874void Context::vertexAttribIFormat(GLuint attribIndex,
3875 GLint size,
3876 GLenum type,
3877 GLuint relativeOffset)
3878{
3879 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
3880}
3881
3882void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
3883{
Shaodde78e82017-05-22 14:13:27 +08003884 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Shao80957d92017-02-20 21:25:59 +08003885}
3886
3887void Context::setVertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
3888{
3889 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
3890}
3891
Jamie Madillc20ab272016-06-09 07:20:46 -07003892void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
3893{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003894 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07003895}
3896
3897void Context::vertexAttribIPointer(GLuint index,
3898 GLint size,
3899 GLenum type,
3900 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04003901 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07003902{
Shaodde78e82017-05-22 14:13:27 +08003903 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(GL_ARRAY_BUFFER), size,
3904 type, false, true, stride, pointer);
Jamie Madillc20ab272016-06-09 07:20:46 -07003905}
3906
3907void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
3908{
3909 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003910 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003911}
3912
3913void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
3914{
3915 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003916 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003917}
3918
3919void Context::vertexAttribI4iv(GLuint index, const GLint *v)
3920{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003921 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07003922}
3923
3924void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
3925{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003926 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07003927}
3928
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003929void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
3930{
3931 const VertexAttribCurrentValueData &currentValues =
3932 getGLState().getVertexAttribCurrentValue(index);
3933 const VertexArray *vao = getGLState().getVertexArray();
3934 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3935 currentValues, pname, params);
3936}
3937
3938void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
3939{
3940 const VertexAttribCurrentValueData &currentValues =
3941 getGLState().getVertexAttribCurrentValue(index);
3942 const VertexArray *vao = getGLState().getVertexArray();
3943 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3944 currentValues, pname, params);
3945}
3946
3947void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
3948{
3949 const VertexAttribCurrentValueData &currentValues =
3950 getGLState().getVertexAttribCurrentValue(index);
3951 const VertexArray *vao = getGLState().getVertexArray();
3952 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3953 currentValues, pname, params);
3954}
3955
3956void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
3957{
3958 const VertexAttribCurrentValueData &currentValues =
3959 getGLState().getVertexAttribCurrentValue(index);
3960 const VertexArray *vao = getGLState().getVertexArray();
3961 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3962 currentValues, pname, params);
3963}
3964
Jamie Madill876429b2017-04-20 15:46:24 -04003965void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003966{
3967 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
3968 QueryVertexAttribPointerv(attrib, pname, pointer);
3969}
3970
Jamie Madillc20ab272016-06-09 07:20:46 -07003971void Context::debugMessageControl(GLenum source,
3972 GLenum type,
3973 GLenum severity,
3974 GLsizei count,
3975 const GLuint *ids,
3976 GLboolean enabled)
3977{
3978 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003979 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
3980 (enabled != GL_FALSE));
Jamie Madillc20ab272016-06-09 07:20:46 -07003981}
3982
3983void Context::debugMessageInsert(GLenum source,
3984 GLenum type,
3985 GLuint id,
3986 GLenum severity,
3987 GLsizei length,
3988 const GLchar *buf)
3989{
3990 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003991 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07003992}
3993
3994void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
3995{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003996 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07003997}
3998
3999GLuint Context::getDebugMessageLog(GLuint count,
4000 GLsizei bufSize,
4001 GLenum *sources,
4002 GLenum *types,
4003 GLuint *ids,
4004 GLenum *severities,
4005 GLsizei *lengths,
4006 GLchar *messageLog)
4007{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004008 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4009 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004010}
4011
4012void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4013{
4014 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004015 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004016}
4017
4018void Context::popDebugGroup()
4019{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004020 mGLState.getDebug().popGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004021}
4022
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004023void Context::bufferData(GLenum target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004024{
4025 Buffer *buffer = mGLState.getTargetBuffer(target);
4026 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004027 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004028}
4029
Jamie Madill876429b2017-04-20 15:46:24 -04004030void Context::bufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004031{
4032 if (data == nullptr)
4033 {
4034 return;
4035 }
4036
4037 Buffer *buffer = mGLState.getTargetBuffer(target);
4038 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004039 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004040}
4041
Jamie Madillef300b12016-10-07 15:12:09 -04004042void Context::attachShader(GLuint program, GLuint shader)
4043{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004044 auto programObject = mState.mShaderPrograms->getProgram(program);
4045 auto shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004046 ASSERT(programObject && shaderObject);
4047 programObject->attachShader(shaderObject);
4048}
4049
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004050const Workarounds &Context::getWorkarounds() const
4051{
4052 return mWorkarounds;
4053}
4054
Jamie Madillb0817d12016-11-01 15:48:31 -04004055void Context::copyBufferSubData(GLenum readTarget,
4056 GLenum writeTarget,
4057 GLintptr readOffset,
4058 GLintptr writeOffset,
4059 GLsizeiptr size)
4060{
4061 // if size is zero, the copy is a successful no-op
4062 if (size == 0)
4063 {
4064 return;
4065 }
4066
4067 // TODO(jmadill): cache these.
4068 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4069 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4070
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004071 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004072}
4073
Jamie Madill01a80ee2016-11-07 12:06:18 -05004074void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4075{
4076 Program *programObject = getProgram(program);
4077 // TODO(jmadill): Re-use this from the validation if possible.
4078 ASSERT(programObject);
4079 programObject->bindAttributeLocation(index, name);
4080}
4081
4082void Context::bindBuffer(GLenum target, GLuint buffer)
4083{
4084 switch (target)
4085 {
4086 case GL_ARRAY_BUFFER:
4087 bindArrayBuffer(buffer);
4088 break;
4089 case GL_ELEMENT_ARRAY_BUFFER:
4090 bindElementArrayBuffer(buffer);
4091 break;
4092 case GL_COPY_READ_BUFFER:
4093 bindCopyReadBuffer(buffer);
4094 break;
4095 case GL_COPY_WRITE_BUFFER:
4096 bindCopyWriteBuffer(buffer);
4097 break;
4098 case GL_PIXEL_PACK_BUFFER:
4099 bindPixelPackBuffer(buffer);
4100 break;
4101 case GL_PIXEL_UNPACK_BUFFER:
4102 bindPixelUnpackBuffer(buffer);
4103 break;
4104 case GL_UNIFORM_BUFFER:
4105 bindGenericUniformBuffer(buffer);
4106 break;
4107 case GL_TRANSFORM_FEEDBACK_BUFFER:
4108 bindGenericTransformFeedbackBuffer(buffer);
4109 break;
Geoff Lang3b573612016-10-31 14:08:10 -04004110 case GL_ATOMIC_COUNTER_BUFFER:
Jiajia Qin6eafb042016-12-27 17:04:07 +08004111 bindGenericAtomicCounterBuffer(buffer);
Geoff Lang3b573612016-10-31 14:08:10 -04004112 break;
4113 case GL_SHADER_STORAGE_BUFFER:
Jiajia Qinf546e7d2017-03-27 14:12:59 +08004114 bindGenericShaderStorageBuffer(buffer);
Geoff Lang3b573612016-10-31 14:08:10 -04004115 break;
4116 case GL_DRAW_INDIRECT_BUFFER:
Jiajia Qin9d7d0b12016-11-29 16:30:31 +08004117 bindDrawIndirectBuffer(buffer);
Geoff Lang3b573612016-10-31 14:08:10 -04004118 break;
4119 case GL_DISPATCH_INDIRECT_BUFFER:
Geoff Lang9f090372016-12-02 10:20:43 -05004120 if (buffer != 0)
4121 {
4122 // Binding buffers to this binding point is not implemented yet.
4123 UNIMPLEMENTED();
4124 }
Geoff Lang3b573612016-10-31 14:08:10 -04004125 break;
Jamie Madill01a80ee2016-11-07 12:06:18 -05004126
4127 default:
4128 UNREACHABLE();
4129 break;
4130 }
4131}
4132
Jiajia Qin6eafb042016-12-27 17:04:07 +08004133void Context::bindBufferBase(GLenum target, GLuint index, GLuint buffer)
4134{
4135 bindBufferRange(target, index, buffer, 0, 0);
4136}
4137
4138void Context::bindBufferRange(GLenum target,
4139 GLuint index,
4140 GLuint buffer,
4141 GLintptr offset,
4142 GLsizeiptr size)
4143{
4144 switch (target)
4145 {
4146 case GL_TRANSFORM_FEEDBACK_BUFFER:
4147 bindIndexedTransformFeedbackBuffer(buffer, index, offset, size);
4148 bindGenericTransformFeedbackBuffer(buffer);
4149 break;
4150 case GL_UNIFORM_BUFFER:
4151 bindIndexedUniformBuffer(buffer, index, offset, size);
4152 bindGenericUniformBuffer(buffer);
4153 break;
4154 case GL_ATOMIC_COUNTER_BUFFER:
4155 bindIndexedAtomicCounterBuffer(buffer, index, offset, size);
4156 bindGenericAtomicCounterBuffer(buffer);
4157 break;
4158 case GL_SHADER_STORAGE_BUFFER:
Jiajia Qinf546e7d2017-03-27 14:12:59 +08004159 bindIndexedShaderStorageBuffer(buffer, index, offset, size);
4160 bindGenericShaderStorageBuffer(buffer);
Jiajia Qin6eafb042016-12-27 17:04:07 +08004161 break;
4162 default:
4163 UNREACHABLE();
4164 break;
4165 }
4166}
4167
Jamie Madill01a80ee2016-11-07 12:06:18 -05004168void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
4169{
4170 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4171 {
4172 bindReadFramebuffer(framebuffer);
4173 }
4174
4175 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4176 {
4177 bindDrawFramebuffer(framebuffer);
4178 }
4179}
4180
4181void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4182{
4183 ASSERT(target == GL_RENDERBUFFER);
4184 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004185 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04004186 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004187}
4188
JiangYizhoubddc46b2016-12-09 09:50:51 +08004189void Context::texStorage2DMultisample(GLenum target,
4190 GLsizei samples,
4191 GLenum internalformat,
4192 GLsizei width,
4193 GLsizei height,
4194 GLboolean fixedsamplelocations)
4195{
4196 Extents size(width, height, 1);
4197 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05004198 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
JiangYizhoubddc46b2016-12-09 09:50:51 +08004199 fixedsamplelocations));
4200}
4201
4202void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4203{
JiangYizhou5b03f472017-01-09 10:22:53 +08004204 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
4205 // the sample position should be queried by DRAW_FRAMEBUFFER.
4206 mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER);
4207 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08004208
4209 switch (pname)
4210 {
4211 case GL_SAMPLE_POSITION:
4212 handleError(framebuffer->getSamplePosition(index, val));
4213 break;
4214 default:
4215 UNREACHABLE();
4216 }
4217}
4218
Jamie Madille8fb6402017-02-14 17:56:40 -05004219void Context::renderbufferStorage(GLenum target,
4220 GLenum internalformat,
4221 GLsizei width,
4222 GLsizei height)
4223{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004224 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4225 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
4226
Jamie Madille8fb6402017-02-14 17:56:40 -05004227 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04004228 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004229}
4230
4231void Context::renderbufferStorageMultisample(GLenum target,
4232 GLsizei samples,
4233 GLenum internalformat,
4234 GLsizei width,
4235 GLsizei height)
4236{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004237 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4238 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05004239
4240 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004241 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04004242 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004243}
4244
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004245void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
4246{
Jamie Madill70b5bb02017-08-28 13:32:37 -04004247 const Sync *syncObject = getSync(sync);
Geoff Lang82483b92017-04-11 15:33:00 -04004248 handleError(QuerySynciv(syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004249}
4250
JiangYizhoue18e6392017-02-20 10:32:23 +08004251void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
4252{
4253 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4254 QueryFramebufferParameteriv(framebuffer, pname, params);
4255}
4256
4257void Context::setFramebufferParameteri(GLenum target, GLenum pname, GLint param)
4258{
4259 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4260 SetFramebufferParameteri(framebuffer, pname, param);
4261}
4262
Jamie Madillb3f26b92017-07-19 15:07:41 -04004263Error Context::getScratchBuffer(size_t requstedSizeBytes,
4264 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05004265{
Jamie Madillb3f26b92017-07-19 15:07:41 -04004266 if (!mScratchBuffer.get(requstedSizeBytes, scratchBufferOut))
4267 {
4268 return OutOfMemory() << "Failed to allocate internal buffer.";
4269 }
4270 return NoError();
4271}
4272
4273Error Context::getZeroFilledBuffer(size_t requstedSizeBytes,
4274 angle::MemoryBuffer **zeroBufferOut) const
4275{
4276 if (!mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0))
Jamie Madille14951e2017-03-09 18:55:16 -05004277 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004278 return OutOfMemory() << "Failed to allocate internal buffer.";
Jamie Madille14951e2017-03-09 18:55:16 -05004279 }
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004280 return NoError();
Jamie Madille14951e2017-03-09 18:55:16 -05004281}
4282
Xinghua Cao2b396592017-03-29 15:36:04 +08004283void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
4284{
4285 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
4286 {
4287 return;
4288 }
4289
Jamie Madill05b35b22017-10-03 09:01:44 -04004290 // TODO(jmadill): Dirty bits for compute.
Jamie Madilla59fc192017-11-02 12:57:58 -04004291 if (isRobustResourceInitEnabled())
4292 {
4293 ANGLE_CONTEXT_TRY(mGLState.clearUnclearedActiveTextures(this));
4294 }
Jamie Madill05b35b22017-10-03 09:01:44 -04004295
Jamie Madill71c88b32017-09-14 22:20:29 -04004296 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08004297}
4298
JiangYizhou165361c2017-06-07 14:56:57 +08004299void Context::texStorage2D(GLenum target,
4300 GLsizei levels,
4301 GLenum internalFormat,
4302 GLsizei width,
4303 GLsizei height)
4304{
4305 Extents size(width, height, 1);
4306 Texture *texture = getTargetTexture(target);
4307 handleError(texture->setStorage(this, target, levels, internalFormat, size));
4308}
4309
4310void Context::texStorage3D(GLenum target,
4311 GLsizei levels,
4312 GLenum internalFormat,
4313 GLsizei width,
4314 GLsizei height,
4315 GLsizei depth)
4316{
4317 Extents size(width, height, depth);
4318 Texture *texture = getTargetTexture(target);
4319 handleError(texture->setStorage(this, target, levels, internalFormat, size));
4320}
4321
Jamie Madillc1d770e2017-04-13 17:31:24 -04004322GLenum Context::checkFramebufferStatus(GLenum target)
4323{
4324 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4325 ASSERT(framebuffer);
4326
4327 return framebuffer->checkStatus(this);
4328}
4329
4330void Context::compileShader(GLuint shader)
4331{
4332 Shader *shaderObject = GetValidShader(this, shader);
4333 if (!shaderObject)
4334 {
4335 return;
4336 }
4337 shaderObject->compile(this);
4338}
4339
4340void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
4341{
4342 for (int i = 0; i < n; i++)
4343 {
4344 deleteBuffer(buffers[i]);
4345 }
4346}
4347
4348void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
4349{
4350 for (int i = 0; i < n; i++)
4351 {
4352 if (framebuffers[i] != 0)
4353 {
4354 deleteFramebuffer(framebuffers[i]);
4355 }
4356 }
4357}
4358
4359void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
4360{
4361 for (int i = 0; i < n; i++)
4362 {
4363 deleteRenderbuffer(renderbuffers[i]);
4364 }
4365}
4366
4367void Context::deleteTextures(GLsizei n, const GLuint *textures)
4368{
4369 for (int i = 0; i < n; i++)
4370 {
4371 if (textures[i] != 0)
4372 {
4373 deleteTexture(textures[i]);
4374 }
4375 }
4376}
4377
4378void Context::detachShader(GLuint program, GLuint shader)
4379{
4380 Program *programObject = getProgram(program);
4381 ASSERT(programObject);
4382
4383 Shader *shaderObject = getShader(shader);
4384 ASSERT(shaderObject);
4385
4386 programObject->detachShader(this, shaderObject);
4387}
4388
4389void Context::genBuffers(GLsizei n, GLuint *buffers)
4390{
4391 for (int i = 0; i < n; i++)
4392 {
4393 buffers[i] = createBuffer();
4394 }
4395}
4396
4397void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
4398{
4399 for (int i = 0; i < n; i++)
4400 {
4401 framebuffers[i] = createFramebuffer();
4402 }
4403}
4404
4405void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
4406{
4407 for (int i = 0; i < n; i++)
4408 {
4409 renderbuffers[i] = createRenderbuffer();
4410 }
4411}
4412
4413void Context::genTextures(GLsizei n, GLuint *textures)
4414{
4415 for (int i = 0; i < n; i++)
4416 {
4417 textures[i] = createTexture();
4418 }
4419}
4420
4421void Context::getActiveAttrib(GLuint program,
4422 GLuint index,
4423 GLsizei bufsize,
4424 GLsizei *length,
4425 GLint *size,
4426 GLenum *type,
4427 GLchar *name)
4428{
4429 Program *programObject = getProgram(program);
4430 ASSERT(programObject);
4431 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
4432}
4433
4434void Context::getActiveUniform(GLuint program,
4435 GLuint index,
4436 GLsizei bufsize,
4437 GLsizei *length,
4438 GLint *size,
4439 GLenum *type,
4440 GLchar *name)
4441{
4442 Program *programObject = getProgram(program);
4443 ASSERT(programObject);
4444 programObject->getActiveUniform(index, bufsize, length, size, type, name);
4445}
4446
4447void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
4448{
4449 Program *programObject = getProgram(program);
4450 ASSERT(programObject);
4451 programObject->getAttachedShaders(maxcount, count, shaders);
4452}
4453
4454GLint Context::getAttribLocation(GLuint program, const GLchar *name)
4455{
4456 Program *programObject = getProgram(program);
4457 ASSERT(programObject);
4458 return programObject->getAttributeLocation(name);
4459}
4460
4461void Context::getBooleanv(GLenum pname, GLboolean *params)
4462{
4463 GLenum nativeType;
4464 unsigned int numParams = 0;
4465 getQueryParameterInfo(pname, &nativeType, &numParams);
4466
4467 if (nativeType == GL_BOOL)
4468 {
4469 getBooleanvImpl(pname, params);
4470 }
4471 else
4472 {
4473 CastStateValues(this, nativeType, pname, numParams, params);
4474 }
4475}
4476
4477void Context::getFloatv(GLenum pname, GLfloat *params)
4478{
4479 GLenum nativeType;
4480 unsigned int numParams = 0;
4481 getQueryParameterInfo(pname, &nativeType, &numParams);
4482
4483 if (nativeType == GL_FLOAT)
4484 {
4485 getFloatvImpl(pname, params);
4486 }
4487 else
4488 {
4489 CastStateValues(this, nativeType, pname, numParams, params);
4490 }
4491}
4492
4493void Context::getIntegerv(GLenum pname, GLint *params)
4494{
4495 GLenum nativeType;
4496 unsigned int numParams = 0;
4497 getQueryParameterInfo(pname, &nativeType, &numParams);
4498
4499 if (nativeType == GL_INT)
4500 {
4501 getIntegervImpl(pname, params);
4502 }
4503 else
4504 {
4505 CastStateValues(this, nativeType, pname, numParams, params);
4506 }
4507}
4508
4509void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
4510{
4511 Program *programObject = getProgram(program);
4512 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04004513 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004514}
4515
Jamie Madillbe849e42017-05-02 15:49:00 -04004516void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04004517{
4518 Program *programObject = getProgram(program);
4519 ASSERT(programObject);
4520 programObject->getInfoLog(bufsize, length, infolog);
4521}
4522
4523void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
4524{
4525 Shader *shaderObject = getShader(shader);
4526 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004527 QueryShaderiv(this, shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004528}
4529
4530void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
4531{
4532 Shader *shaderObject = getShader(shader);
4533 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004534 shaderObject->getInfoLog(this, bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004535}
4536
4537void Context::getShaderPrecisionFormat(GLenum shadertype,
4538 GLenum precisiontype,
4539 GLint *range,
4540 GLint *precision)
4541{
4542 // TODO(jmadill): Compute shaders.
4543
4544 switch (shadertype)
4545 {
4546 case GL_VERTEX_SHADER:
4547 switch (precisiontype)
4548 {
4549 case GL_LOW_FLOAT:
4550 mCaps.vertexLowpFloat.get(range, precision);
4551 break;
4552 case GL_MEDIUM_FLOAT:
4553 mCaps.vertexMediumpFloat.get(range, precision);
4554 break;
4555 case GL_HIGH_FLOAT:
4556 mCaps.vertexHighpFloat.get(range, precision);
4557 break;
4558
4559 case GL_LOW_INT:
4560 mCaps.vertexLowpInt.get(range, precision);
4561 break;
4562 case GL_MEDIUM_INT:
4563 mCaps.vertexMediumpInt.get(range, precision);
4564 break;
4565 case GL_HIGH_INT:
4566 mCaps.vertexHighpInt.get(range, precision);
4567 break;
4568
4569 default:
4570 UNREACHABLE();
4571 return;
4572 }
4573 break;
4574
4575 case GL_FRAGMENT_SHADER:
4576 switch (precisiontype)
4577 {
4578 case GL_LOW_FLOAT:
4579 mCaps.fragmentLowpFloat.get(range, precision);
4580 break;
4581 case GL_MEDIUM_FLOAT:
4582 mCaps.fragmentMediumpFloat.get(range, precision);
4583 break;
4584 case GL_HIGH_FLOAT:
4585 mCaps.fragmentHighpFloat.get(range, precision);
4586 break;
4587
4588 case GL_LOW_INT:
4589 mCaps.fragmentLowpInt.get(range, precision);
4590 break;
4591 case GL_MEDIUM_INT:
4592 mCaps.fragmentMediumpInt.get(range, precision);
4593 break;
4594 case GL_HIGH_INT:
4595 mCaps.fragmentHighpInt.get(range, precision);
4596 break;
4597
4598 default:
4599 UNREACHABLE();
4600 return;
4601 }
4602 break;
4603
4604 default:
4605 UNREACHABLE();
4606 return;
4607 }
4608}
4609
4610void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
4611{
4612 Shader *shaderObject = getShader(shader);
4613 ASSERT(shaderObject);
4614 shaderObject->getSource(bufsize, length, source);
4615}
4616
4617void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
4618{
4619 Program *programObject = getProgram(program);
4620 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04004621 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004622}
4623
4624void Context::getUniformiv(GLuint program, GLint location, GLint *params)
4625{
4626 Program *programObject = getProgram(program);
4627 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04004628 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004629}
4630
4631GLint Context::getUniformLocation(GLuint program, const GLchar *name)
4632{
4633 Program *programObject = getProgram(program);
4634 ASSERT(programObject);
4635 return programObject->getUniformLocation(name);
4636}
4637
4638GLboolean Context::isBuffer(GLuint buffer)
4639{
4640 if (buffer == 0)
4641 {
4642 return GL_FALSE;
4643 }
4644
4645 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
4646}
4647
4648GLboolean Context::isEnabled(GLenum cap)
4649{
4650 return mGLState.getEnableFeature(cap);
4651}
4652
4653GLboolean Context::isFramebuffer(GLuint framebuffer)
4654{
4655 if (framebuffer == 0)
4656 {
4657 return GL_FALSE;
4658 }
4659
4660 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
4661}
4662
4663GLboolean Context::isProgram(GLuint program)
4664{
4665 if (program == 0)
4666 {
4667 return GL_FALSE;
4668 }
4669
4670 return (getProgram(program) ? GL_TRUE : GL_FALSE);
4671}
4672
4673GLboolean Context::isRenderbuffer(GLuint renderbuffer)
4674{
4675 if (renderbuffer == 0)
4676 {
4677 return GL_FALSE;
4678 }
4679
4680 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
4681}
4682
4683GLboolean Context::isShader(GLuint shader)
4684{
4685 if (shader == 0)
4686 {
4687 return GL_FALSE;
4688 }
4689
4690 return (getShader(shader) ? GL_TRUE : GL_FALSE);
4691}
4692
4693GLboolean Context::isTexture(GLuint texture)
4694{
4695 if (texture == 0)
4696 {
4697 return GL_FALSE;
4698 }
4699
4700 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
4701}
4702
4703void Context::linkProgram(GLuint program)
4704{
4705 Program *programObject = getProgram(program);
4706 ASSERT(programObject);
4707 handleError(programObject->link(this));
Martin Radev0abb7a22017-08-28 15:34:45 +03004708 mGLState.onProgramExecutableChange(programObject);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004709}
4710
4711void Context::releaseShaderCompiler()
4712{
Jamie Madill4928b7c2017-06-20 12:57:39 -04004713 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004714}
4715
4716void Context::shaderBinary(GLsizei n,
4717 const GLuint *shaders,
4718 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04004719 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04004720 GLsizei length)
4721{
4722 // No binary shader formats are supported.
4723 UNIMPLEMENTED();
4724}
4725
4726void Context::shaderSource(GLuint shader,
4727 GLsizei count,
4728 const GLchar *const *string,
4729 const GLint *length)
4730{
4731 Shader *shaderObject = getShader(shader);
4732 ASSERT(shaderObject);
4733 shaderObject->setSource(count, string, length);
4734}
4735
4736void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
4737{
4738 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
4739}
4740
4741void Context::stencilMask(GLuint mask)
4742{
4743 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
4744}
4745
4746void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
4747{
4748 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
4749}
4750
4751void Context::uniform1f(GLint location, GLfloat x)
4752{
4753 Program *program = mGLState.getProgram();
4754 program->setUniform1fv(location, 1, &x);
4755}
4756
4757void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
4758{
4759 Program *program = mGLState.getProgram();
4760 program->setUniform1fv(location, count, v);
4761}
4762
4763void Context::uniform1i(GLint location, GLint x)
4764{
4765 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04004766 if (program->setUniform1iv(location, 1, &x) == Program::SetUniformResult::SamplerChanged)
4767 {
4768 mGLState.setObjectDirty(GL_PROGRAM);
4769 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04004770}
4771
4772void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
4773{
4774 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04004775 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
4776 {
4777 mGLState.setObjectDirty(GL_PROGRAM);
4778 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04004779}
4780
4781void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
4782{
4783 GLfloat xy[2] = {x, y};
4784 Program *program = mGLState.getProgram();
4785 program->setUniform2fv(location, 1, xy);
4786}
4787
4788void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
4789{
4790 Program *program = mGLState.getProgram();
4791 program->setUniform2fv(location, count, v);
4792}
4793
4794void Context::uniform2i(GLint location, GLint x, GLint y)
4795{
4796 GLint xy[2] = {x, y};
4797 Program *program = mGLState.getProgram();
4798 program->setUniform2iv(location, 1, xy);
4799}
4800
4801void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
4802{
4803 Program *program = mGLState.getProgram();
4804 program->setUniform2iv(location, count, v);
4805}
4806
4807void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
4808{
4809 GLfloat xyz[3] = {x, y, z};
4810 Program *program = mGLState.getProgram();
4811 program->setUniform3fv(location, 1, xyz);
4812}
4813
4814void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
4815{
4816 Program *program = mGLState.getProgram();
4817 program->setUniform3fv(location, count, v);
4818}
4819
4820void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
4821{
4822 GLint xyz[3] = {x, y, z};
4823 Program *program = mGLState.getProgram();
4824 program->setUniform3iv(location, 1, xyz);
4825}
4826
4827void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
4828{
4829 Program *program = mGLState.getProgram();
4830 program->setUniform3iv(location, count, v);
4831}
4832
4833void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4834{
4835 GLfloat xyzw[4] = {x, y, z, w};
4836 Program *program = mGLState.getProgram();
4837 program->setUniform4fv(location, 1, xyzw);
4838}
4839
4840void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
4841{
4842 Program *program = mGLState.getProgram();
4843 program->setUniform4fv(location, count, v);
4844}
4845
4846void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
4847{
4848 GLint xyzw[4] = {x, y, z, w};
4849 Program *program = mGLState.getProgram();
4850 program->setUniform4iv(location, 1, xyzw);
4851}
4852
4853void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
4854{
4855 Program *program = mGLState.getProgram();
4856 program->setUniform4iv(location, count, v);
4857}
4858
4859void Context::uniformMatrix2fv(GLint location,
4860 GLsizei count,
4861 GLboolean transpose,
4862 const GLfloat *value)
4863{
4864 Program *program = mGLState.getProgram();
4865 program->setUniformMatrix2fv(location, count, transpose, value);
4866}
4867
4868void Context::uniformMatrix3fv(GLint location,
4869 GLsizei count,
4870 GLboolean transpose,
4871 const GLfloat *value)
4872{
4873 Program *program = mGLState.getProgram();
4874 program->setUniformMatrix3fv(location, count, transpose, value);
4875}
4876
4877void Context::uniformMatrix4fv(GLint location,
4878 GLsizei count,
4879 GLboolean transpose,
4880 const GLfloat *value)
4881{
4882 Program *program = mGLState.getProgram();
4883 program->setUniformMatrix4fv(location, count, transpose, value);
4884}
4885
4886void Context::validateProgram(GLuint program)
4887{
4888 Program *programObject = getProgram(program);
4889 ASSERT(programObject);
4890 programObject->validate(mCaps);
4891}
4892
Jamie Madilld04908b2017-06-09 14:15:35 -04004893void Context::getProgramBinary(GLuint program,
4894 GLsizei bufSize,
4895 GLsizei *length,
4896 GLenum *binaryFormat,
4897 void *binary)
4898{
4899 Program *programObject = getProgram(program);
4900 ASSERT(programObject != nullptr);
4901
4902 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
4903}
4904
4905void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
4906{
4907 Program *programObject = getProgram(program);
4908 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04004909
Jamie Madilld04908b2017-06-09 14:15:35 -04004910 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
4911}
4912
Jamie Madillff325f12017-08-26 15:06:05 -04004913void Context::uniform1ui(GLint location, GLuint v0)
4914{
4915 Program *program = mGLState.getProgram();
4916 program->setUniform1uiv(location, 1, &v0);
4917}
4918
4919void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
4920{
4921 Program *program = mGLState.getProgram();
4922 const GLuint xy[] = {v0, v1};
4923 program->setUniform2uiv(location, 1, xy);
4924}
4925
4926void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
4927{
4928 Program *program = mGLState.getProgram();
4929 const GLuint xyz[] = {v0, v1, v2};
4930 program->setUniform3uiv(location, 1, xyz);
4931}
4932
4933void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
4934{
4935 Program *program = mGLState.getProgram();
4936 const GLuint xyzw[] = {v0, v1, v2, v3};
4937 program->setUniform4uiv(location, 1, xyzw);
4938}
4939
4940void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
4941{
4942 Program *program = mGLState.getProgram();
4943 program->setUniform1uiv(location, count, value);
4944}
4945void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
4946{
4947 Program *program = mGLState.getProgram();
4948 program->setUniform2uiv(location, count, value);
4949}
4950
4951void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
4952{
4953 Program *program = mGLState.getProgram();
4954 program->setUniform3uiv(location, count, value);
4955}
4956
4957void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
4958{
4959 Program *program = mGLState.getProgram();
4960 program->setUniform4uiv(location, count, value);
4961}
4962
Jamie Madillf0e04492017-08-26 15:28:42 -04004963void Context::genQueries(GLsizei n, GLuint *ids)
4964{
4965 for (GLsizei i = 0; i < n; i++)
4966 {
4967 GLuint handle = mQueryHandleAllocator.allocate();
4968 mQueryMap.assign(handle, nullptr);
4969 ids[i] = handle;
4970 }
4971}
4972
4973void Context::deleteQueries(GLsizei n, const GLuint *ids)
4974{
4975 for (int i = 0; i < n; i++)
4976 {
4977 GLuint query = ids[i];
4978
4979 Query *queryObject = nullptr;
4980 if (mQueryMap.erase(query, &queryObject))
4981 {
4982 mQueryHandleAllocator.release(query);
4983 if (queryObject)
4984 {
4985 queryObject->release(this);
4986 }
4987 }
4988 }
4989}
4990
4991GLboolean Context::isQuery(GLuint id)
4992{
4993 return (getQuery(id, false, GL_NONE) != nullptr) ? GL_TRUE : GL_FALSE;
4994}
4995
Jamie Madillc8c95812017-08-26 18:40:09 -04004996void Context::uniformMatrix2x3fv(GLint location,
4997 GLsizei count,
4998 GLboolean transpose,
4999 const GLfloat *value)
5000{
5001 Program *program = mGLState.getProgram();
5002 program->setUniformMatrix2x3fv(location, count, transpose, value);
5003}
5004
5005void Context::uniformMatrix3x2fv(GLint location,
5006 GLsizei count,
5007 GLboolean transpose,
5008 const GLfloat *value)
5009{
5010 Program *program = mGLState.getProgram();
5011 program->setUniformMatrix3x2fv(location, count, transpose, value);
5012}
5013
5014void Context::uniformMatrix2x4fv(GLint location,
5015 GLsizei count,
5016 GLboolean transpose,
5017 const GLfloat *value)
5018{
5019 Program *program = mGLState.getProgram();
5020 program->setUniformMatrix2x4fv(location, count, transpose, value);
5021}
5022
5023void Context::uniformMatrix4x2fv(GLint location,
5024 GLsizei count,
5025 GLboolean transpose,
5026 const GLfloat *value)
5027{
5028 Program *program = mGLState.getProgram();
5029 program->setUniformMatrix4x2fv(location, count, transpose, value);
5030}
5031
5032void Context::uniformMatrix3x4fv(GLint location,
5033 GLsizei count,
5034 GLboolean transpose,
5035 const GLfloat *value)
5036{
5037 Program *program = mGLState.getProgram();
5038 program->setUniformMatrix3x4fv(location, count, transpose, value);
5039}
5040
5041void Context::uniformMatrix4x3fv(GLint location,
5042 GLsizei count,
5043 GLboolean transpose,
5044 const GLfloat *value)
5045{
5046 Program *program = mGLState.getProgram();
5047 program->setUniformMatrix4x3fv(location, count, transpose, value);
5048}
5049
Jamie Madilld7576732017-08-26 18:49:50 -04005050void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
5051{
5052 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5053 {
5054 GLuint vertexArray = arrays[arrayIndex];
5055
5056 if (arrays[arrayIndex] != 0)
5057 {
5058 VertexArray *vertexArrayObject = nullptr;
5059 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
5060 {
5061 if (vertexArrayObject != nullptr)
5062 {
5063 detachVertexArray(vertexArray);
5064 vertexArrayObject->onDestroy(this);
5065 }
5066
5067 mVertexArrayHandleAllocator.release(vertexArray);
5068 }
5069 }
5070 }
5071}
5072
5073void Context::genVertexArrays(GLsizei n, GLuint *arrays)
5074{
5075 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5076 {
5077 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
5078 mVertexArrayMap.assign(vertexArray, nullptr);
5079 arrays[arrayIndex] = vertexArray;
5080 }
5081}
5082
5083bool Context::isVertexArray(GLuint array)
5084{
5085 if (array == 0)
5086 {
5087 return GL_FALSE;
5088 }
5089
5090 VertexArray *vao = getVertexArray(array);
5091 return (vao != nullptr ? GL_TRUE : GL_FALSE);
5092}
5093
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04005094void Context::endTransformFeedback()
5095{
5096 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5097 transformFeedback->end(this);
5098}
5099
5100void Context::transformFeedbackVaryings(GLuint program,
5101 GLsizei count,
5102 const GLchar *const *varyings,
5103 GLenum bufferMode)
5104{
5105 Program *programObject = getProgram(program);
5106 ASSERT(programObject);
5107 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
5108}
5109
5110void Context::getTransformFeedbackVarying(GLuint program,
5111 GLuint index,
5112 GLsizei bufSize,
5113 GLsizei *length,
5114 GLsizei *size,
5115 GLenum *type,
5116 GLchar *name)
5117{
5118 Program *programObject = getProgram(program);
5119 ASSERT(programObject);
5120 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
5121}
5122
5123void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
5124{
5125 for (int i = 0; i < n; i++)
5126 {
5127 GLuint transformFeedback = ids[i];
5128 if (transformFeedback == 0)
5129 {
5130 continue;
5131 }
5132
5133 TransformFeedback *transformFeedbackObject = nullptr;
5134 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
5135 {
5136 if (transformFeedbackObject != nullptr)
5137 {
5138 detachTransformFeedback(transformFeedback);
5139 transformFeedbackObject->release(this);
5140 }
5141
5142 mTransformFeedbackHandleAllocator.release(transformFeedback);
5143 }
5144 }
5145}
5146
5147void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
5148{
5149 for (int i = 0; i < n; i++)
5150 {
5151 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
5152 mTransformFeedbackMap.assign(transformFeedback, nullptr);
5153 ids[i] = transformFeedback;
5154 }
5155}
5156
5157bool Context::isTransformFeedback(GLuint id)
5158{
5159 if (id == 0)
5160 {
5161 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
5162 // returns FALSE
5163 return GL_FALSE;
5164 }
5165
5166 const TransformFeedback *transformFeedback = getTransformFeedback(id);
5167 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
5168}
5169
5170void Context::pauseTransformFeedback()
5171{
5172 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5173 transformFeedback->pause();
5174}
5175
5176void Context::resumeTransformFeedback()
5177{
5178 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5179 transformFeedback->resume();
5180}
5181
Jamie Madill12e957f2017-08-26 21:42:26 -04005182void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
5183{
5184 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04005185 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04005186}
5187
5188GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
5189{
5190 const Program *programObject = getProgram(program);
5191 return programObject->getFragDataLocation(name);
5192}
5193
5194void Context::getUniformIndices(GLuint program,
5195 GLsizei uniformCount,
5196 const GLchar *const *uniformNames,
5197 GLuint *uniformIndices)
5198{
5199 const Program *programObject = getProgram(program);
5200 if (!programObject->isLinked())
5201 {
5202 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5203 {
5204 uniformIndices[uniformId] = GL_INVALID_INDEX;
5205 }
5206 }
5207 else
5208 {
5209 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5210 {
5211 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
5212 }
5213 }
5214}
5215
5216void Context::getActiveUniformsiv(GLuint program,
5217 GLsizei uniformCount,
5218 const GLuint *uniformIndices,
5219 GLenum pname,
5220 GLint *params)
5221{
5222 const Program *programObject = getProgram(program);
5223 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5224 {
5225 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08005226 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04005227 }
5228}
5229
5230GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
5231{
5232 const Program *programObject = getProgram(program);
5233 return programObject->getUniformBlockIndex(uniformBlockName);
5234}
5235
5236void Context::getActiveUniformBlockiv(GLuint program,
5237 GLuint uniformBlockIndex,
5238 GLenum pname,
5239 GLint *params)
5240{
5241 const Program *programObject = getProgram(program);
5242 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
5243}
5244
5245void Context::getActiveUniformBlockName(GLuint program,
5246 GLuint uniformBlockIndex,
5247 GLsizei bufSize,
5248 GLsizei *length,
5249 GLchar *uniformBlockName)
5250{
5251 const Program *programObject = getProgram(program);
5252 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
5253}
5254
5255void Context::uniformBlockBinding(GLuint program,
5256 GLuint uniformBlockIndex,
5257 GLuint uniformBlockBinding)
5258{
5259 Program *programObject = getProgram(program);
5260 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
5261}
5262
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005263GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
5264{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005265 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
5266 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005267
Jamie Madill70b5bb02017-08-28 13:32:37 -04005268 Sync *syncObject = getSync(syncHandle);
5269 Error error = syncObject->set(condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005270 if (error.isError())
5271 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04005272 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005273 handleError(error);
5274 return nullptr;
5275 }
5276
Jamie Madill70b5bb02017-08-28 13:32:37 -04005277 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005278}
5279
5280GLboolean Context::isSync(GLsync sync)
5281{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005282 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005283}
5284
5285GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
5286{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005287 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005288
5289 GLenum result = GL_WAIT_FAILED;
5290 handleError(syncObject->clientWait(flags, timeout, &result));
5291 return result;
5292}
5293
5294void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
5295{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005296 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005297 handleError(syncObject->serverWait(flags, timeout));
5298}
5299
5300void Context::getInteger64v(GLenum pname, GLint64 *params)
5301{
5302 GLenum nativeType = GL_NONE;
5303 unsigned int numParams = 0;
5304 getQueryParameterInfo(pname, &nativeType, &numParams);
5305
5306 if (nativeType == GL_INT_64_ANGLEX)
5307 {
5308 getInteger64vImpl(pname, params);
5309 }
5310 else
5311 {
5312 CastStateValues(this, nativeType, pname, numParams, params);
5313 }
5314}
5315
Jamie Madill3ef140a2017-08-26 23:11:21 -04005316void Context::getBufferParameteri64v(GLenum target, GLenum pname, GLint64 *params)
5317{
5318 Buffer *buffer = mGLState.getTargetBuffer(target);
5319 QueryBufferParameteri64v(buffer, pname, params);
5320}
5321
5322void Context::genSamplers(GLsizei count, GLuint *samplers)
5323{
5324 for (int i = 0; i < count; i++)
5325 {
5326 samplers[i] = mState.mSamplers->createSampler();
5327 }
5328}
5329
5330void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
5331{
5332 for (int i = 0; i < count; i++)
5333 {
5334 GLuint sampler = samplers[i];
5335
5336 if (mState.mSamplers->getSampler(sampler))
5337 {
5338 detachSampler(sampler);
5339 }
5340
5341 mState.mSamplers->deleteObject(this, sampler);
5342 }
5343}
5344
5345void Context::getInternalformativ(GLenum target,
5346 GLenum internalformat,
5347 GLenum pname,
5348 GLsizei bufSize,
5349 GLint *params)
5350{
5351 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
5352 QueryInternalFormativ(formatCaps, pname, bufSize, params);
5353}
5354
Jamie Madill81c2e252017-09-09 23:32:46 -04005355void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5356{
5357 Program *programObject = getProgram(program);
5358 ASSERT(programObject);
5359 if (programObject->setUniform1iv(location, count, value) ==
5360 Program::SetUniformResult::SamplerChanged)
5361 {
5362 mGLState.setObjectDirty(GL_PROGRAM);
5363 }
5364}
5365
5366void Context::onTextureChange(const Texture *texture)
5367{
5368 // Conservatively assume all textures are dirty.
5369 // TODO(jmadill): More fine-grained update.
5370 mGLState.setObjectDirty(GL_TEXTURE);
5371}
5372
Yunchao Hea336b902017-08-02 16:05:21 +08005373void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
5374{
5375 for (int i = 0; i < count; i++)
5376 {
5377 pipelines[i] = createProgramPipeline();
5378 }
5379}
5380
5381void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
5382{
5383 for (int i = 0; i < count; i++)
5384 {
5385 if (pipelines[i] != 0)
5386 {
5387 deleteProgramPipeline(pipelines[i]);
5388 }
5389 }
5390}
5391
5392GLboolean Context::isProgramPipeline(GLuint pipeline)
5393{
5394 if (pipeline == 0)
5395 {
5396 return GL_FALSE;
5397 }
5398
5399 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
5400}
5401
Jamie Madillc29968b2016-01-20 11:17:23 -05005402} // namespace gl