blob: eb0b42441d53abab7003da9850fb07079cde525d [file] [log] [blame]
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001//
Geoff Langeeba6e12014-02-03 13:12:30 -05002// Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7// Context.cpp: Implements the gl::Context class, managing all GL state and performing
8// rendering operations. It is the GLES2 specific implementation of EGLContext.
9
Geoff Lang2b5420c2014-11-19 14:20:15 -050010#include "libANGLE/Context.h"
apatrick@chromium.org144f2802012-07-12 01:42:34 +000011
Jamie Madill231c7f52017-04-26 13:45:37 -040012#include <string.h>
Jamie Madillb9293972015-02-19 11:07:54 -050013#include <iterator>
14#include <sstream>
Sami Väisänend59ca052016-06-21 16:10:00 +030015#include <vector>
Jamie Madillb9293972015-02-19 11:07:54 -050016
Sami Väisänene45e53b2016-05-25 10:36:04 +030017#include "common/matrix_utils.h"
Geoff Lang0b7eef72014-06-12 14:10:47 -040018#include "common/platform.h"
Jamie Madillb9293972015-02-19 11:07:54 -050019#include "common/utilities.h"
Geoff Langc339c4e2016-11-29 10:37:36 -050020#include "common/version.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050021#include "libANGLE/Buffer.h"
Jamie Madillb9293972015-02-19 11:07:54 -050022#include "libANGLE/Compiler.h"
Jamie Madill948bbe52017-06-01 13:10:42 -040023#include "libANGLE/Display.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050024#include "libANGLE/Fence.h"
25#include "libANGLE/Framebuffer.h"
26#include "libANGLE/FramebufferAttachment.h"
Sami Väisänene45e53b2016-05-25 10:36:04 +030027#include "libANGLE/Path.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050028#include "libANGLE/Program.h"
Yunchao Hea336b902017-08-02 16:05:21 +080029#include "libANGLE/ProgramPipeline.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050030#include "libANGLE/Query.h"
Jamie Madillb9293972015-02-19 11:07:54 -050031#include "libANGLE/Renderbuffer.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050032#include "libANGLE/ResourceManager.h"
33#include "libANGLE/Sampler.h"
Jamie Madill9dd0cf02014-11-24 11:38:51 -050034#include "libANGLE/Surface.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050035#include "libANGLE/Texture.h"
36#include "libANGLE/TransformFeedback.h"
37#include "libANGLE/VertexArray.h"
Kenneth Russellf2f6f652016-10-05 19:53:23 -070038#include "libANGLE/Workarounds.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040039#include "libANGLE/formatutils.h"
Martin Radev66fb8202016-07-28 11:45:20 +030040#include "libANGLE/queryconversions.h"
Geoff Langc1984ed2016-10-07 12:41:00 -040041#include "libANGLE/queryutils.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040042#include "libANGLE/renderer/ContextImpl.h"
43#include "libANGLE/renderer/EGLImplFactory.h"
Jamie Madill7b62cf92017-11-02 15:20:49 -040044#include "libANGLE/renderer/Format.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040045#include "libANGLE/validationES.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000046
Geoff Langf6db0982015-08-25 13:04:00 -040047namespace
48{
49
Jamie Madillb6664922017-07-25 12:55:04 -040050#define ANGLE_HANDLE_ERR(X) \
51 handleError(X); \
52 return;
53#define ANGLE_CONTEXT_TRY(EXPR) ANGLE_TRY_TEMPLATE(EXPR, ANGLE_HANDLE_ERR);
54
Ian Ewell3ffd78b2016-01-22 16:09:42 -050055template <typename T>
Geoff Lang4ddf5af2016-12-01 14:30:44 -050056std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager,
Sami Väisänend59ca052016-06-21 16:10:00 +030057 GLsizei numPaths,
58 const void *paths,
59 GLuint pathBase)
60{
61 std::vector<gl::Path *> ret;
62 ret.reserve(numPaths);
63
64 const auto *nameArray = static_cast<const T *>(paths);
65
66 for (GLsizei i = 0; i < numPaths; ++i)
67 {
68 const GLuint pathName = nameArray[i] + pathBase;
69
70 ret.push_back(resourceManager.getPath(pathName));
71 }
72
73 return ret;
74}
75
Geoff Lang4ddf5af2016-12-01 14:30:44 -050076std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager,
Sami Väisänend59ca052016-06-21 16:10:00 +030077 GLsizei numPaths,
78 GLenum pathNameType,
79 const void *paths,
80 GLuint pathBase)
81{
82 switch (pathNameType)
83 {
84 case GL_UNSIGNED_BYTE:
85 return GatherPaths<GLubyte>(resourceManager, numPaths, paths, pathBase);
86
87 case GL_BYTE:
88 return GatherPaths<GLbyte>(resourceManager, numPaths, paths, pathBase);
89
90 case GL_UNSIGNED_SHORT:
91 return GatherPaths<GLushort>(resourceManager, numPaths, paths, pathBase);
92
93 case GL_SHORT:
94 return GatherPaths<GLshort>(resourceManager, numPaths, paths, pathBase);
95
96 case GL_UNSIGNED_INT:
97 return GatherPaths<GLuint>(resourceManager, numPaths, paths, pathBase);
98
99 case GL_INT:
100 return GatherPaths<GLint>(resourceManager, numPaths, paths, pathBase);
101 }
102
103 UNREACHABLE();
104 return std::vector<gl::Path *>();
105}
106
107template <typename T>
Geoff Lang2186c382016-10-14 10:54:54 -0400108gl::Error GetQueryObjectParameter(gl::Query *query, GLenum pname, T *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500109{
Geoff Lang2186c382016-10-14 10:54:54 -0400110 ASSERT(query != nullptr);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500111
112 switch (pname)
113 {
114 case GL_QUERY_RESULT_EXT:
Geoff Lang2186c382016-10-14 10:54:54 -0400115 return query->getResult(params);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500116 case GL_QUERY_RESULT_AVAILABLE_EXT:
117 {
118 bool available;
Geoff Lang2186c382016-10-14 10:54:54 -0400119 gl::Error error = query->isResultAvailable(&available);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500120 if (!error.isError())
121 {
jchen10a99ed552017-09-22 08:10:32 +0800122 *params = gl::CastFromStateValue<T>(pname, static_cast<GLuint>(available));
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500123 }
124 return error;
125 }
126 default:
127 UNREACHABLE();
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500128 return gl::InternalError() << "Unreachable Error";
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500129 }
130}
131
Geoff Langf6db0982015-08-25 13:04:00 -0400132void MarkTransformFeedbackBufferUsage(gl::TransformFeedback *transformFeedback)
133{
Geoff Lang1a683462015-09-29 15:09:59 -0400134 if (transformFeedback && transformFeedback->isActive() && !transformFeedback->isPaused())
Geoff Langf6db0982015-08-25 13:04:00 -0400135 {
136 for (size_t tfBufferIndex = 0; tfBufferIndex < transformFeedback->getIndexedBufferCount();
137 tfBufferIndex++)
138 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400139 const gl::OffsetBindingPointer<gl::Buffer> &buffer =
Geoff Langf6db0982015-08-25 13:04:00 -0400140 transformFeedback->getIndexedBuffer(tfBufferIndex);
141 if (buffer.get() != nullptr)
142 {
143 buffer->onTransformFeedback();
144 }
145 }
146 }
147}
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500148
149// Attribute map queries.
Martin Radev1be913c2016-07-11 17:59:16 +0300150EGLint GetClientMajorVersion(const egl::AttributeMap &attribs)
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500151{
Ian Ewellec2c0c52016-04-05 13:46:26 -0400152 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_CLIENT_VERSION, 1));
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500153}
154
Martin Radev1be913c2016-07-11 17:59:16 +0300155EGLint GetClientMinorVersion(const egl::AttributeMap &attribs)
156{
157 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_MINOR_VERSION, 0));
158}
159
Geoff Langeb66a6e2016-10-31 13:06:12 -0400160gl::Version GetClientVersion(const egl::AttributeMap &attribs)
161{
162 return gl::Version(GetClientMajorVersion(attribs), GetClientMinorVersion(attribs));
163}
164
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500165GLenum GetResetStrategy(const egl::AttributeMap &attribs)
166{
Ian Ewellec2c0c52016-04-05 13:46:26 -0400167 EGLAttrib attrib = attribs.get(EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT,
168 EGL_NO_RESET_NOTIFICATION_EXT);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500169 switch (attrib)
170 {
171 case EGL_NO_RESET_NOTIFICATION:
172 return GL_NO_RESET_NOTIFICATION_EXT;
173 case EGL_LOSE_CONTEXT_ON_RESET:
174 return GL_LOSE_CONTEXT_ON_RESET_EXT;
175 default:
176 UNREACHABLE();
177 return GL_NONE;
178 }
179}
180
181bool GetRobustAccess(const egl::AttributeMap &attribs)
182{
Geoff Lang077f20a2016-11-01 10:08:02 -0400183 return (attribs.get(EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT, EGL_FALSE) == EGL_TRUE) ||
184 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR) !=
185 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500186}
187
188bool GetDebug(const egl::AttributeMap &attribs)
189{
Geoff Lang077f20a2016-11-01 10:08:02 -0400190 return (attribs.get(EGL_CONTEXT_OPENGL_DEBUG, EGL_FALSE) == EGL_TRUE) ||
191 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR) != 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500192}
193
194bool GetNoError(const egl::AttributeMap &attribs)
195{
196 return (attribs.get(EGL_CONTEXT_OPENGL_NO_ERROR_KHR, EGL_FALSE) == EGL_TRUE);
197}
198
Geoff Langc287ea62016-09-16 14:46:51 -0400199bool GetWebGLContext(const egl::AttributeMap &attribs)
200{
201 return (attribs.get(EGL_CONTEXT_WEBGL_COMPATIBILITY_ANGLE, EGL_FALSE) == EGL_TRUE);
202}
203
Geoff Langf41a7152016-09-19 15:11:17 -0400204bool GetBindGeneratesResource(const egl::AttributeMap &attribs)
205{
206 return (attribs.get(EGL_CONTEXT_BIND_GENERATES_RESOURCE_CHROMIUM, EGL_TRUE) == EGL_TRUE);
207}
208
Geoff Langfeb8c682017-02-13 16:07:35 -0500209bool GetClientArraysEnabled(const egl::AttributeMap &attribs)
210{
211 return (attribs.get(EGL_CONTEXT_CLIENT_ARRAYS_ENABLED_ANGLE, EGL_TRUE) == EGL_TRUE);
212}
213
Geoff Langb433e872017-10-05 14:01:47 -0400214bool GetRobustResourceInit(const egl::AttributeMap &attribs)
215{
216 return (attribs.get(EGL_ROBUST_RESOURCE_INITIALIZATION_ANGLE, EGL_FALSE) == EGL_TRUE);
217}
218
Martin Radev9d901792016-07-15 15:58:58 +0300219std::string GetObjectLabelFromPointer(GLsizei length, const GLchar *label)
220{
221 std::string labelName;
222 if (label != nullptr)
223 {
224 size_t labelLength = length < 0 ? strlen(label) : length;
225 labelName = std::string(label, labelLength);
226 }
227 return labelName;
228}
229
230void GetObjectLabelBase(const std::string &objectLabel,
231 GLsizei bufSize,
232 GLsizei *length,
233 GLchar *label)
234{
235 size_t writeLength = objectLabel.length();
236 if (label != nullptr && bufSize > 0)
237 {
238 writeLength = std::min(static_cast<size_t>(bufSize) - 1, objectLabel.length());
239 std::copy(objectLabel.begin(), objectLabel.begin() + writeLength, label);
240 label[writeLength] = '\0';
241 }
242
243 if (length != nullptr)
244 {
245 *length = static_cast<GLsizei>(writeLength);
246 }
247}
248
Jamie Madill0f80ed82017-09-19 00:24:56 -0400249template <typename CapT, typename MaxT>
250void LimitCap(CapT *cap, MaxT maximum)
251{
252 *cap = std::min(*cap, static_cast<CapT>(maximum));
253}
254
Geoff Langf6db0982015-08-25 13:04:00 -0400255} // anonymous namespace
256
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000257namespace gl
258{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +0000259
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400260Context::Context(rx::EGLImplFactory *implFactory,
261 const egl::Config *config,
Corentin Wallez51706ea2015-08-07 14:39:22 -0400262 const Context *shareContext,
Geoff Langce02f082017-02-06 16:46:21 -0500263 TextureManager *shareTextures,
Jamie Madill32447362017-06-28 14:53:52 -0400264 MemoryProgramCache *memoryProgramCache,
Corentin Wallezc295e512017-01-27 17:47:50 -0500265 const egl::AttributeMap &attribs,
Geoff Langb433e872017-10-05 14:01:47 -0400266 const egl::DisplayExtensions &displayExtensions)
Martin Radev1be913c2016-07-11 17:59:16 +0300267
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500268 : ValidationContext(shareContext,
Geoff Langce02f082017-02-06 16:46:21 -0500269 shareTextures,
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500270 GetClientVersion(attribs),
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700271 &mGLState,
Jamie Madillf25855c2015-11-03 11:06:18 -0500272 mCaps,
273 mTextureCaps,
274 mExtensions,
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500275 mLimitations,
276 GetNoError(attribs)),
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700277 mImplementation(implFactory->createContext(mState)),
Jamie Madill2f348d22017-06-05 10:50:59 -0400278 mCompiler(),
Corentin Walleze3b10e82015-05-20 11:06:25 -0400279 mConfig(config),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500280 mClientType(EGL_OPENGL_ES_API),
281 mHasBeenCurrent(false),
282 mContextLost(false),
283 mResetStatus(GL_NO_ERROR),
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700284 mContextLostForced(false),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500285 mResetStrategy(GetResetStrategy(attribs)),
286 mRobustAccess(GetRobustAccess(attribs)),
Jamie Madill61e16b42017-06-19 11:13:23 -0400287 mCurrentSurface(static_cast<egl::Surface *>(EGL_NO_SURFACE)),
288 mCurrentDisplay(static_cast<egl::Display *>(EGL_NO_DISPLAY)),
Jamie Madill4e0e6f82017-02-17 11:06:03 -0500289 mSurfacelessFramebuffer(nullptr),
Jamie Madille14951e2017-03-09 18:55:16 -0500290 mWebGLContext(GetWebGLContext(attribs)),
Jamie Madill32447362017-06-28 14:53:52 -0400291 mMemoryProgramCache(memoryProgramCache),
Jamie Madillb3f26b92017-07-19 15:07:41 -0400292 mScratchBuffer(1000u),
293 mZeroFilledBuffer(1000u)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000294{
Jamie Madill14bbb3f2017-09-12 15:23:01 -0400295 mImplementation->setMemoryProgramCache(memoryProgramCache);
296
Geoff Langb433e872017-10-05 14:01:47 -0400297 bool robustResourceInit = GetRobustResourceInit(attribs);
298 initCaps(displayExtensions, robustResourceInit);
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700299 initWorkarounds();
Geoff Langc0b9ef42014-07-02 10:02:37 -0400300
Jamie Madill4928b7c2017-06-20 12:57:39 -0400301 mGLState.initialize(this, GetDebug(attribs), GetBindGeneratesResource(attribs),
Jamie Madillc43be722017-07-13 16:22:14 -0400302 GetClientArraysEnabled(attribs), robustResourceInit,
303 mMemoryProgramCache != nullptr);
Régis Fénéon83107972015-02-05 12:57:44 +0100304
Shannon Woods53a94a82014-06-24 15:20:36 -0400305 mFenceNVHandleAllocator.setBaseHandle(0);
Geoff Lang7dca1862013-07-30 16:30:46 -0400306
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000307 // [OpenGL ES 2.0.24] section 3.7 page 83:
308 // In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have twodimensional
309 // and cube map texture state vectors respectively associated with them.
310 // In order that access to these initial textures not be lost, they are treated as texture
311 // objects all of whose names are 0.
312
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400313 Texture *zeroTexture2D = new Texture(mImplementation.get(), 0, GL_TEXTURE_2D);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400314 mZeroTextures[GL_TEXTURE_2D].set(this, zeroTexture2D);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500315
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400316 Texture *zeroTextureCube = new Texture(mImplementation.get(), 0, GL_TEXTURE_CUBE_MAP);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400317 mZeroTextures[GL_TEXTURE_CUBE_MAP].set(this, zeroTextureCube);
Geoff Lang76b10c92014-09-05 16:28:14 -0400318
Geoff Langeb66a6e2016-10-31 13:06:12 -0400319 if (getClientVersion() >= Version(3, 0))
Geoff Lang76b10c92014-09-05 16:28:14 -0400320 {
321 // TODO: These could also be enabled via extension
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400322 Texture *zeroTexture3D = new Texture(mImplementation.get(), 0, GL_TEXTURE_3D);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400323 mZeroTextures[GL_TEXTURE_3D].set(this, zeroTexture3D);
Geoff Lang76b10c92014-09-05 16:28:14 -0400324
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400325 Texture *zeroTexture2DArray = new Texture(mImplementation.get(), 0, GL_TEXTURE_2D_ARRAY);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400326 mZeroTextures[GL_TEXTURE_2D_ARRAY].set(this, zeroTexture2DArray);
Geoff Lang76b10c92014-09-05 16:28:14 -0400327 }
Geoff Lang3b573612016-10-31 14:08:10 -0400328 if (getClientVersion() >= Version(3, 1))
329 {
330 Texture *zeroTexture2DMultisample =
331 new Texture(mImplementation.get(), 0, GL_TEXTURE_2D_MULTISAMPLE);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400332 mZeroTextures[GL_TEXTURE_2D_MULTISAMPLE].set(this, zeroTexture2DMultisample);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800333
334 bindGenericAtomicCounterBuffer(0);
335 for (unsigned int i = 0; i < mCaps.maxAtomicCounterBufferBindings; i++)
336 {
337 bindIndexedAtomicCounterBuffer(0, i, 0, 0);
338 }
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800339
340 bindGenericShaderStorageBuffer(0);
341 for (unsigned int i = 0; i < mCaps.maxShaderStorageBufferBindings; i++)
342 {
343 bindIndexedShaderStorageBuffer(0, i, 0, 0);
344 }
Geoff Lang3b573612016-10-31 14:08:10 -0400345 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000346
Geoff Lang4751aab2017-10-30 15:14:52 -0400347 const Extensions &nativeExtensions = mImplementation->getNativeExtensions();
348 if (nativeExtensions.textureRectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400349 {
350 Texture *zeroTextureRectangle =
351 new Texture(mImplementation.get(), 0, GL_TEXTURE_RECTANGLE_ANGLE);
352 mZeroTextures[GL_TEXTURE_RECTANGLE_ANGLE].set(this, zeroTextureRectangle);
353 }
354
Geoff Lang4751aab2017-10-30 15:14:52 -0400355 if (nativeExtensions.eglImageExternal || nativeExtensions.eglStreamConsumerExternal)
Ian Ewellbda75592016-04-18 17:25:54 -0400356 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400357 Texture *zeroTextureExternal =
358 new Texture(mImplementation.get(), 0, GL_TEXTURE_EXTERNAL_OES);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400359 mZeroTextures[GL_TEXTURE_EXTERNAL_OES].set(this, zeroTextureExternal);
Ian Ewellbda75592016-04-18 17:25:54 -0400360 }
361
Jamie Madill4928b7c2017-06-20 12:57:39 -0400362 mGLState.initializeZeroTextures(this, mZeroTextures);
Jamie Madille6382c32014-11-07 15:05:26 -0500363
Jamie Madill57a89722013-07-02 11:57:03 -0400364 bindVertexArray(0);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000365 bindArrayBuffer(0);
Jiajia Qin9d7d0b12016-11-29 16:30:31 +0800366 bindDrawIndirectBuffer(0);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000367 bindElementArrayBuffer(0);
Geoff Lang76b10c92014-09-05 16:28:14 -0400368
Jamie Madill01a80ee2016-11-07 12:06:18 -0500369 bindRenderbuffer(GL_RENDERBUFFER, 0);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000370
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +0000371 bindGenericUniformBuffer(0);
Geoff Lang4dc3af02016-11-18 14:09:27 -0500372 for (unsigned int i = 0; i < mCaps.maxUniformBufferBindings; i++)
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +0000373 {
374 bindIndexedUniformBuffer(0, i, 0, -1);
375 }
376
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000377 bindCopyReadBuffer(0);
378 bindCopyWriteBuffer(0);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +0000379 bindPixelPackBuffer(0);
380 bindPixelUnpackBuffer(0);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000381
Geoff Langeb66a6e2016-10-31 13:06:12 -0400382 if (getClientVersion() >= Version(3, 0))
Geoff Lang1a683462015-09-29 15:09:59 -0400383 {
384 // [OpenGL ES 3.0.2] section 2.14.1 pg 85:
385 // In the initial state, a default transform feedback object is bound and treated as
386 // a transform feedback object with a name of zero. That object is bound any time
387 // BindTransformFeedback is called with id of zero
Jamie Madillf0dcb8b2017-08-26 19:05:13 -0400388 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Geoff Lang1a683462015-09-29 15:09:59 -0400389 }
Geoff Langc8058452014-02-03 12:04:11 -0500390
Jamie Madillad9f24e2016-02-12 09:27:24 -0500391 // Initialize dirty bit masks
392 // TODO(jmadill): additional ES3 state
393 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_ALIGNMENT);
394 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_ROW_LENGTH);
395 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_IMAGE_HEIGHT);
396 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_SKIP_IMAGES);
397 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_SKIP_ROWS);
398 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_SKIP_PIXELS);
Corentin Wallezbbd663a2016-04-20 17:49:17 -0400399 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500400 // No dirty objects.
401
402 // Readpixels uses the pack state and read FBO
403 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_ALIGNMENT);
404 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_REVERSE_ROW_ORDER);
405 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_ROW_LENGTH);
406 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_SKIP_ROWS);
407 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_SKIP_PIXELS);
Corentin Wallezbbd663a2016-04-20 17:49:17 -0400408 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500409 mReadPixelsDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
410
411 mClearDirtyBits.set(State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED);
412 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
413 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR);
414 mClearDirtyBits.set(State::DIRTY_BIT_VIEWPORT);
415 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_COLOR);
416 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_DEPTH);
417 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_STENCIL);
418 mClearDirtyBits.set(State::DIRTY_BIT_COLOR_MASK);
419 mClearDirtyBits.set(State::DIRTY_BIT_DEPTH_MASK);
420 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT);
421 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_BACK);
422 mClearDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
423
424 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
425 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR);
Geoff Lang1d2c41d2016-10-19 16:14:46 -0700426 mBlitDirtyBits.set(State::DIRTY_BIT_FRAMEBUFFER_SRGB);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500427 mBlitDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
428 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
Jamie Madill437fa652016-05-03 15:13:24 -0400429
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400430 handleError(mImplementation->initialize());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000431}
432
Jamie Madill4928b7c2017-06-20 12:57:39 -0400433egl::Error Context::onDestroy(const egl::Display *display)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000434{
Corentin Wallez80b24112015-08-25 16:41:57 -0400435 for (auto fence : mFenceNVMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000436 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400437 SafeDelete(fence.second);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000438 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400439 mFenceNVMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000440
Corentin Wallez80b24112015-08-25 16:41:57 -0400441 for (auto query : mQueryMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000442 {
Geoff Langf0aa8422015-09-29 15:08:34 -0400443 if (query.second != nullptr)
444 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400445 query.second->release(this);
Geoff Langf0aa8422015-09-29 15:08:34 -0400446 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000447 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400448 mQueryMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000449
Corentin Wallez80b24112015-08-25 16:41:57 -0400450 for (auto vertexArray : mVertexArrayMap)
Jamie Madill57a89722013-07-02 11:57:03 -0400451 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400452 if (vertexArray.second)
453 {
454 vertexArray.second->onDestroy(this);
455 }
Jamie Madill57a89722013-07-02 11:57:03 -0400456 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400457 mVertexArrayMap.clear();
Jamie Madill57a89722013-07-02 11:57:03 -0400458
Corentin Wallez80b24112015-08-25 16:41:57 -0400459 for (auto transformFeedback : mTransformFeedbackMap)
Geoff Langc8058452014-02-03 12:04:11 -0500460 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500461 if (transformFeedback.second != nullptr)
462 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500463 transformFeedback.second->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500464 }
Geoff Langc8058452014-02-03 12:04:11 -0500465 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400466 mTransformFeedbackMap.clear();
Geoff Langc8058452014-02-03 12:04:11 -0500467
Jamie Madilldedd7b92014-11-05 16:30:36 -0500468 for (auto &zeroTexture : mZeroTextures)
Geoff Lang76b10c92014-09-05 16:28:14 -0400469 {
Jamie Madill71c88b32017-09-14 22:20:29 -0400470 ANGLE_TRY(zeroTexture.second->onDestroy(this));
Jamie Madill4928b7c2017-06-20 12:57:39 -0400471 zeroTexture.second.set(this, nullptr);
Geoff Lang76b10c92014-09-05 16:28:14 -0400472 }
473 mZeroTextures.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000474
Corentin Wallezccab69d2017-01-27 16:57:15 -0500475 SafeDelete(mSurfacelessFramebuffer);
476
Jamie Madill4928b7c2017-06-20 12:57:39 -0400477 ANGLE_TRY(releaseSurface(display));
Jamie Madill2f348d22017-06-05 10:50:59 -0400478 releaseShaderCompiler();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500479
Jamie Madill4928b7c2017-06-20 12:57:39 -0400480 mGLState.reset(this);
481
Jamie Madill6c1f6712017-02-14 19:08:04 -0500482 mState.mBuffers->release(this);
483 mState.mShaderPrograms->release(this);
484 mState.mTextures->release(this);
485 mState.mRenderbuffers->release(this);
486 mState.mSamplers->release(this);
Jamie Madill70b5bb02017-08-28 13:32:37 -0400487 mState.mSyncs->release(this);
Jamie Madill6c1f6712017-02-14 19:08:04 -0500488 mState.mPaths->release(this);
489 mState.mFramebuffers->release(this);
Yunchao Hea336b902017-08-02 16:05:21 +0800490 mState.mPipelines->release(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400491
Jamie Madill76e471e2017-10-21 09:56:01 -0400492 mImplementation->onDestroy(this);
493
Jamie Madill4928b7c2017-06-20 12:57:39 -0400494 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000495}
496
Jamie Madill70ee0f62017-02-06 16:04:20 -0500497Context::~Context()
498{
499}
500
Jamie Madill4928b7c2017-06-20 12:57:39 -0400501egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000502{
Jamie Madill61e16b42017-06-19 11:13:23 -0400503 mCurrentDisplay = display;
504
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000505 if (!mHasBeenCurrent)
506 {
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000507 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500508 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400509 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000510
Corentin Wallezc295e512017-01-27 17:47:50 -0500511 int width = 0;
512 int height = 0;
513 if (surface != nullptr)
514 {
515 width = surface->getWidth();
516 height = surface->getHeight();
517 }
518
519 mGLState.setViewportParams(0, 0, width, height);
520 mGLState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000521
522 mHasBeenCurrent = true;
523 }
524
Jamie Madill1b94d432015-08-07 13:23:23 -0400525 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700526 mGLState.setAllDirtyBits();
Jamie Madill81c2e252017-09-09 23:32:46 -0400527 mGLState.setAllDirtyObjects();
Jamie Madill1b94d432015-08-07 13:23:23 -0400528
Jamie Madill4928b7c2017-06-20 12:57:39 -0400529 ANGLE_TRY(releaseSurface(display));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500530
531 Framebuffer *newDefault = nullptr;
532 if (surface != nullptr)
533 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400534 ANGLE_TRY(surface->setIsCurrent(this, true));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500535 mCurrentSurface = surface;
536 newDefault = surface->getDefaultFramebuffer();
537 }
538 else
539 {
540 if (mSurfacelessFramebuffer == nullptr)
541 {
542 mSurfacelessFramebuffer = new Framebuffer(mImplementation.get());
543 }
544
545 newDefault = mSurfacelessFramebuffer;
546 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000547
Corentin Wallez37c39792015-08-20 14:19:46 -0400548 // Update default framebuffer, the binding of the previous default
549 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400550 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700551 if (mGLState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400552 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700553 mGLState.setReadFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400554 }
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700555 if (mGLState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400556 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700557 mGLState.setDrawFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400558 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500559 mState.mFramebuffers->setDefaultFramebuffer(newDefault);
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400560 }
Ian Ewell292f0052016-02-04 10:37:32 -0500561
562 // Notify the renderer of a context switch
Jamie Madill4928b7c2017-06-20 12:57:39 -0400563 mImplementation->onMakeCurrent(this);
564 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000565}
566
Jamie Madill4928b7c2017-06-20 12:57:39 -0400567egl::Error Context::releaseSurface(const egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400568{
Corentin Wallez37c39792015-08-20 14:19:46 -0400569 // Remove the default framebuffer
Corentin Wallezc295e512017-01-27 17:47:50 -0500570 Framebuffer *currentDefault = nullptr;
571 if (mCurrentSurface != nullptr)
Corentin Wallez51706ea2015-08-07 14:39:22 -0400572 {
Corentin Wallezc295e512017-01-27 17:47:50 -0500573 currentDefault = mCurrentSurface->getDefaultFramebuffer();
574 }
575 else if (mSurfacelessFramebuffer != nullptr)
576 {
577 currentDefault = mSurfacelessFramebuffer;
Corentin Wallez51706ea2015-08-07 14:39:22 -0400578 }
579
Corentin Wallezc295e512017-01-27 17:47:50 -0500580 if (mGLState.getReadFramebuffer() == currentDefault)
581 {
582 mGLState.setReadFramebufferBinding(nullptr);
583 }
584 if (mGLState.getDrawFramebuffer() == currentDefault)
585 {
586 mGLState.setDrawFramebufferBinding(nullptr);
587 }
588 mState.mFramebuffers->setDefaultFramebuffer(nullptr);
589
590 if (mCurrentSurface)
591 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400592 ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
Corentin Wallezc295e512017-01-27 17:47:50 -0500593 mCurrentSurface = nullptr;
594 }
Jamie Madill4928b7c2017-06-20 12:57:39 -0400595
596 return egl::NoError();
Jamie Madill77a72f62015-04-14 11:18:32 -0400597}
598
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000599GLuint Context::createBuffer()
600{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500601 return mState.mBuffers->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000602}
603
604GLuint Context::createProgram()
605{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500606 return mState.mShaderPrograms->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000607}
608
609GLuint Context::createShader(GLenum type)
610{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500611 return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000612}
613
614GLuint Context::createTexture()
615{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500616 return mState.mTextures->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000617}
618
619GLuint Context::createRenderbuffer()
620{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500621 return mState.mRenderbuffers->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000622}
623
Sami Väisänene45e53b2016-05-25 10:36:04 +0300624GLuint Context::createPaths(GLsizei range)
625{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500626 auto resultOrError = mState.mPaths->createPaths(mImplementation.get(), range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300627 if (resultOrError.isError())
628 {
629 handleError(resultOrError.getError());
630 return 0;
631 }
632 return resultOrError.getResult();
633}
634
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000635// Returns an unused framebuffer name
636GLuint Context::createFramebuffer()
637{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500638 return mState.mFramebuffers->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000639}
640
Jamie Madill33dc8432013-07-26 11:55:05 -0400641GLuint Context::createFenceNV()
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000642{
Jamie Madill33dc8432013-07-26 11:55:05 -0400643 GLuint handle = mFenceNVHandleAllocator.allocate();
Jamie Madill96a483b2017-06-27 16:49:21 -0400644 mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV()));
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000645 return handle;
646}
647
Yunchao Hea336b902017-08-02 16:05:21 +0800648GLuint Context::createProgramPipeline()
649{
650 return mState.mPipelines->createProgramPipeline();
651}
652
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000653void Context::deleteBuffer(GLuint buffer)
654{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500655 if (mState.mBuffers->getBuffer(buffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000656 {
657 detachBuffer(buffer);
658 }
Jamie Madill893ab082014-05-16 16:56:10 -0400659
Jamie Madill6c1f6712017-02-14 19:08:04 -0500660 mState.mBuffers->deleteObject(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000661}
662
663void Context::deleteShader(GLuint shader)
664{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500665 mState.mShaderPrograms->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000666}
667
668void Context::deleteProgram(GLuint program)
669{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500670 mState.mShaderPrograms->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000671}
672
673void Context::deleteTexture(GLuint texture)
674{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500675 if (mState.mTextures->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000676 {
677 detachTexture(texture);
678 }
679
Jamie Madill6c1f6712017-02-14 19:08:04 -0500680 mState.mTextures->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000681}
682
683void Context::deleteRenderbuffer(GLuint renderbuffer)
684{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500685 if (mState.mRenderbuffers->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000686 {
687 detachRenderbuffer(renderbuffer);
688 }
Jamie Madill893ab082014-05-16 16:56:10 -0400689
Jamie Madill6c1f6712017-02-14 19:08:04 -0500690 mState.mRenderbuffers->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000691}
692
Jamie Madill7f0c5a42017-08-26 22:43:26 -0400693void Context::deleteSync(GLsync sync)
Jamie Madillcd055f82013-07-26 11:55:15 -0400694{
695 // The spec specifies the underlying Fence object is not deleted until all current
696 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
697 // and since our API is currently designed for being called from a single thread, we can delete
698 // the fence immediately.
Jamie Madill70b5bb02017-08-28 13:32:37 -0400699 mState.mSyncs->deleteObject(this, static_cast<GLuint>(reinterpret_cast<uintptr_t>(sync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400700}
701
Yunchao Hea336b902017-08-02 16:05:21 +0800702void Context::deleteProgramPipeline(GLuint pipeline)
703{
704 if (mState.mPipelines->getProgramPipeline(pipeline))
705 {
706 detachProgramPipeline(pipeline);
707 }
708
709 mState.mPipelines->deleteObject(this, pipeline);
710}
711
Sami Väisänene45e53b2016-05-25 10:36:04 +0300712void Context::deletePaths(GLuint first, GLsizei range)
713{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500714 mState.mPaths->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300715}
716
717bool Context::hasPathData(GLuint path) const
718{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500719 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300720 if (pathObj == nullptr)
721 return false;
722
723 return pathObj->hasPathData();
724}
725
726bool Context::hasPath(GLuint path) const
727{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500728 return mState.mPaths->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300729}
730
731void Context::setPathCommands(GLuint path,
732 GLsizei numCommands,
733 const GLubyte *commands,
734 GLsizei numCoords,
735 GLenum coordType,
736 const void *coords)
737{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500738 auto *pathObject = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300739
740 handleError(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
741}
742
743void Context::setPathParameterf(GLuint path, GLenum pname, GLfloat value)
744{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500745 auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300746
747 switch (pname)
748 {
749 case GL_PATH_STROKE_WIDTH_CHROMIUM:
750 pathObj->setStrokeWidth(value);
751 break;
752 case GL_PATH_END_CAPS_CHROMIUM:
753 pathObj->setEndCaps(static_cast<GLenum>(value));
754 break;
755 case GL_PATH_JOIN_STYLE_CHROMIUM:
756 pathObj->setJoinStyle(static_cast<GLenum>(value));
757 break;
758 case GL_PATH_MITER_LIMIT_CHROMIUM:
759 pathObj->setMiterLimit(value);
760 break;
761 case GL_PATH_STROKE_BOUND_CHROMIUM:
762 pathObj->setStrokeBound(value);
763 break;
764 default:
765 UNREACHABLE();
766 break;
767 }
768}
769
770void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value) const
771{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500772 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300773
774 switch (pname)
775 {
776 case GL_PATH_STROKE_WIDTH_CHROMIUM:
777 *value = pathObj->getStrokeWidth();
778 break;
779 case GL_PATH_END_CAPS_CHROMIUM:
780 *value = static_cast<GLfloat>(pathObj->getEndCaps());
781 break;
782 case GL_PATH_JOIN_STYLE_CHROMIUM:
783 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
784 break;
785 case GL_PATH_MITER_LIMIT_CHROMIUM:
786 *value = pathObj->getMiterLimit();
787 break;
788 case GL_PATH_STROKE_BOUND_CHROMIUM:
789 *value = pathObj->getStrokeBound();
790 break;
791 default:
792 UNREACHABLE();
793 break;
794 }
795}
796
797void Context::setPathStencilFunc(GLenum func, GLint ref, GLuint mask)
798{
799 mGLState.setPathStencilFunc(func, ref, mask);
800}
801
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000802void Context::deleteFramebuffer(GLuint framebuffer)
803{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500804 if (mState.mFramebuffers->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000805 {
806 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000807 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500808
Jamie Madill6c1f6712017-02-14 19:08:04 -0500809 mState.mFramebuffers->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000810}
811
Jamie Madill33dc8432013-07-26 11:55:05 -0400812void Context::deleteFenceNV(GLuint fence)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000813{
Jamie Madill96a483b2017-06-27 16:49:21 -0400814 FenceNV *fenceObject = nullptr;
815 if (mFenceNVMap.erase(fence, &fenceObject))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000816 {
Jamie Madill96a483b2017-06-27 16:49:21 -0400817 mFenceNVHandleAllocator.release(fence);
818 delete fenceObject;
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000819 }
820}
821
Geoff Lang70d0f492015-12-10 17:45:46 -0500822Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000823{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500824 return mState.mBuffers->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000825}
826
Jamie Madill570f7c82014-07-03 10:38:54 -0400827Texture *Context::getTexture(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000828{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500829 return mState.mTextures->getTexture(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000830}
831
Geoff Lang70d0f492015-12-10 17:45:46 -0500832Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000833{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500834 return mState.mRenderbuffers->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000835}
836
Jamie Madill70b5bb02017-08-28 13:32:37 -0400837Sync *Context::getSync(GLsync handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400838{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400839 return mState.mSyncs->getSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400840}
841
Jamie Madill57a89722013-07-02 11:57:03 -0400842VertexArray *Context::getVertexArray(GLuint handle) const
843{
Jamie Madill96a483b2017-06-27 16:49:21 -0400844 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -0400845}
846
Jamie Madilldc356042013-07-19 16:36:57 -0400847Sampler *Context::getSampler(GLuint handle) const
848{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500849 return mState.mSamplers->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400850}
851
Geoff Langc8058452014-02-03 12:04:11 -0500852TransformFeedback *Context::getTransformFeedback(GLuint handle) const
853{
Jamie Madill96a483b2017-06-27 16:49:21 -0400854 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -0500855}
856
Yunchao Hea336b902017-08-02 16:05:21 +0800857ProgramPipeline *Context::getProgramPipeline(GLuint handle) const
858{
859 return mState.mPipelines->getProgramPipeline(handle);
860}
861
Geoff Lang70d0f492015-12-10 17:45:46 -0500862LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
863{
864 switch (identifier)
865 {
866 case GL_BUFFER:
867 return getBuffer(name);
868 case GL_SHADER:
869 return getShader(name);
870 case GL_PROGRAM:
871 return getProgram(name);
872 case GL_VERTEX_ARRAY:
873 return getVertexArray(name);
874 case GL_QUERY:
875 return getQuery(name);
876 case GL_TRANSFORM_FEEDBACK:
877 return getTransformFeedback(name);
878 case GL_SAMPLER:
879 return getSampler(name);
880 case GL_TEXTURE:
881 return getTexture(name);
882 case GL_RENDERBUFFER:
883 return getRenderbuffer(name);
884 case GL_FRAMEBUFFER:
885 return getFramebuffer(name);
886 default:
887 UNREACHABLE();
888 return nullptr;
889 }
890}
891
892LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
893{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400894 return getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
Geoff Lang70d0f492015-12-10 17:45:46 -0500895}
896
Martin Radev9d901792016-07-15 15:58:58 +0300897void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
898{
899 LabeledObject *object = getLabeledObject(identifier, name);
900 ASSERT(object != nullptr);
901
902 std::string labelName = GetObjectLabelFromPointer(length, label);
903 object->setLabel(labelName);
Jamie Madill8693bdb2017-09-02 15:32:14 -0400904
905 // TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the
906 // specified object is active until we do this.
907 mGLState.setObjectDirty(identifier);
Martin Radev9d901792016-07-15 15:58:58 +0300908}
909
910void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
911{
912 LabeledObject *object = getLabeledObjectFromPtr(ptr);
913 ASSERT(object != nullptr);
914
915 std::string labelName = GetObjectLabelFromPointer(length, label);
916 object->setLabel(labelName);
917}
918
919void Context::getObjectLabel(GLenum identifier,
920 GLuint name,
921 GLsizei bufSize,
922 GLsizei *length,
923 GLchar *label) const
924{
925 LabeledObject *object = getLabeledObject(identifier, name);
926 ASSERT(object != nullptr);
927
928 const std::string &objectLabel = object->getLabel();
929 GetObjectLabelBase(objectLabel, bufSize, length, label);
930}
931
932void Context::getObjectPtrLabel(const void *ptr,
933 GLsizei bufSize,
934 GLsizei *length,
935 GLchar *label) const
936{
937 LabeledObject *object = getLabeledObjectFromPtr(ptr);
938 ASSERT(object != nullptr);
939
940 const std::string &objectLabel = object->getLabel();
941 GetObjectLabelBase(objectLabel, bufSize, length, label);
942}
943
Jamie Madilldc356042013-07-19 16:36:57 -0400944bool Context::isSampler(GLuint samplerName) const
945{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500946 return mState.mSamplers->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -0400947}
948
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500949void Context::bindArrayBuffer(GLuint bufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000950{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500951 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400952 mGLState.setArrayBufferBinding(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000953}
954
Jiajia Qin9d7d0b12016-11-29 16:30:31 +0800955void Context::bindDrawIndirectBuffer(GLuint bufferHandle)
956{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500957 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400958 mGLState.setDrawIndirectBufferBinding(this, buffer);
Jiajia Qin9d7d0b12016-11-29 16:30:31 +0800959}
960
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500961void Context::bindElementArrayBuffer(GLuint bufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000962{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500963 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400964 mGLState.setElementArrayBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000965}
966
Jamie Madilldedd7b92014-11-05 16:30:36 -0500967void Context::bindTexture(GLenum target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000968{
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500969 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000970
Jamie Madilldedd7b92014-11-05 16:30:36 -0500971 if (handle == 0)
972 {
973 texture = mZeroTextures[target].get();
974 }
975 else
976 {
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500977 texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500978 }
979
980 ASSERT(texture);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400981 mGLState.setSamplerTexture(this, target, texture);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +0000982}
983
Jamie Madill5bf9ff42016-02-01 11:13:03 -0500984void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000985{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500986 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
987 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700988 mGLState.setReadFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000989}
990
Jamie Madill5bf9ff42016-02-01 11:13:03 -0500991void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000992{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500993 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
994 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700995 mGLState.setDrawFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000996}
997
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500998void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -0400999{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001000 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001001 mGLState.setVertexArrayBinding(vertexArray);
Jamie Madill57a89722013-07-02 11:57:03 -04001002}
1003
Shao80957d92017-02-20 21:25:59 +08001004void Context::bindVertexBuffer(GLuint bindingIndex,
1005 GLuint bufferHandle,
1006 GLintptr offset,
1007 GLsizei stride)
1008{
1009 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001010 mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Shao80957d92017-02-20 21:25:59 +08001011}
1012
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001013void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -04001014{
Geoff Lang76b10c92014-09-05 16:28:14 -04001015 ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -04001016 Sampler *sampler =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001017 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001018 mGLState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04001019}
1020
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001021void Context::bindImageTexture(GLuint unit,
1022 GLuint texture,
1023 GLint level,
1024 GLboolean layered,
1025 GLint layer,
1026 GLenum access,
1027 GLenum format)
1028{
1029 Texture *tex = mState.mTextures->getTexture(texture);
1030 mGLState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
1031}
1032
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001033void Context::bindGenericUniformBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001034{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001035 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001036 mGLState.setGenericUniformBufferBinding(this, buffer);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001037}
1038
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001039void Context::bindIndexedUniformBuffer(GLuint bufferHandle,
1040 GLuint index,
1041 GLintptr offset,
1042 GLsizeiptr size)
shannon.woods%transgaming.com@gtempaccount.com34089352013-04-13 03:36:57 +00001043{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001044 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001045 mGLState.setIndexedUniformBufferBinding(this, index, buffer, offset, size);
shannon.woods%transgaming.com@gtempaccount.com34089352013-04-13 03:36:57 +00001046}
1047
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001048void Context::bindGenericTransformFeedbackBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001049{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001050 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001051 mGLState.getCurrentTransformFeedback()->bindGenericBuffer(this, buffer);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001052}
1053
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001054void Context::bindIndexedTransformFeedbackBuffer(GLuint bufferHandle,
1055 GLuint index,
1056 GLintptr offset,
1057 GLsizeiptr size)
shannon.woods%transgaming.com@gtempaccount.com34089352013-04-13 03:36:57 +00001058{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001059 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001060 mGLState.getCurrentTransformFeedback()->bindIndexedBuffer(this, index, buffer, offset, size);
shannon.woods%transgaming.com@gtempaccount.com34089352013-04-13 03:36:57 +00001061}
1062
Jiajia Qin6eafb042016-12-27 17:04:07 +08001063void Context::bindGenericAtomicCounterBuffer(GLuint bufferHandle)
1064{
1065 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001066 mGLState.setGenericAtomicCounterBufferBinding(this, buffer);
Jiajia Qin6eafb042016-12-27 17:04:07 +08001067}
1068
1069void Context::bindIndexedAtomicCounterBuffer(GLuint bufferHandle,
1070 GLuint index,
1071 GLintptr offset,
1072 GLsizeiptr size)
1073{
1074 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001075 mGLState.setIndexedAtomicCounterBufferBinding(this, index, buffer, offset, size);
Jiajia Qin6eafb042016-12-27 17:04:07 +08001076}
1077
Jiajia Qinf546e7d2017-03-27 14:12:59 +08001078void Context::bindGenericShaderStorageBuffer(GLuint bufferHandle)
1079{
1080 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001081 mGLState.setGenericShaderStorageBufferBinding(this, buffer);
Jiajia Qinf546e7d2017-03-27 14:12:59 +08001082}
1083
1084void Context::bindIndexedShaderStorageBuffer(GLuint bufferHandle,
1085 GLuint index,
1086 GLintptr offset,
1087 GLsizeiptr size)
1088{
1089 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001090 mGLState.setIndexedShaderStorageBufferBinding(this, index, buffer, offset, size);
Jiajia Qinf546e7d2017-03-27 14:12:59 +08001091}
1092
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001093void Context::bindCopyReadBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001094{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001095 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001096 mGLState.setCopyReadBufferBinding(this, buffer);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001097}
1098
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001099void Context::bindCopyWriteBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001100{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001101 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001102 mGLState.setCopyWriteBufferBinding(this, buffer);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001103}
1104
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001105void Context::bindPixelPackBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001106{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001107 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001108 mGLState.setPixelPackBufferBinding(this, buffer);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001109}
1110
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001111void Context::bindPixelUnpackBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001112{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001113 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001114 mGLState.setPixelUnpackBufferBinding(this, buffer);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001115}
1116
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001117void Context::useProgram(GLuint program)
1118{
Jamie Madill6c1f6712017-02-14 19:08:04 -05001119 mGLState.setProgram(this, getProgram(program));
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001120}
1121
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001122void Context::bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001123{
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001124 ASSERT(target == GL_TRANSFORM_FEEDBACK);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001125 TransformFeedback *transformFeedback =
1126 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001127 mGLState.setTransformFeedbackBinding(this, transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -05001128}
1129
Yunchao Hea336b902017-08-02 16:05:21 +08001130void Context::bindProgramPipeline(GLuint pipelineHandle)
1131{
1132 ProgramPipeline *pipeline =
1133 mState.mPipelines->checkProgramPipelineAllocation(mImplementation.get(), pipelineHandle);
1134 mGLState.setProgramPipelineBinding(this, pipeline);
1135}
1136
Jamie Madillf0e04492017-08-26 15:28:42 -04001137void Context::beginQuery(GLenum target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001138{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001139 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001140 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001141
Geoff Lang5aad9672014-09-08 11:10:42 -04001142 // begin query
Jamie Madillf0e04492017-08-26 15:28:42 -04001143 ANGLE_CONTEXT_TRY(queryObject->begin());
Geoff Lang5aad9672014-09-08 11:10:42 -04001144
1145 // set query as active for specified target only if begin succeeded
Jamie Madill4928b7c2017-06-20 12:57:39 -04001146 mGLState.setActiveQuery(this, target, queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001147}
1148
Jamie Madillf0e04492017-08-26 15:28:42 -04001149void Context::endQuery(GLenum target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001150{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001151 Query *queryObject = mGLState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001152 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001153
Jamie Madillf0e04492017-08-26 15:28:42 -04001154 handleError(queryObject->end());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001155
Geoff Lang5aad9672014-09-08 11:10:42 -04001156 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madill4928b7c2017-06-20 12:57:39 -04001157 mGLState.setActiveQuery(this, target, nullptr);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001158}
1159
Jamie Madillf0e04492017-08-26 15:28:42 -04001160void Context::queryCounter(GLuint id, GLenum target)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001161{
1162 ASSERT(target == GL_TIMESTAMP_EXT);
1163
1164 Query *queryObject = getQuery(id, true, target);
1165 ASSERT(queryObject);
1166
Jamie Madillf0e04492017-08-26 15:28:42 -04001167 handleError(queryObject->queryCounter());
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001168}
1169
1170void Context::getQueryiv(GLenum target, GLenum pname, GLint *params)
1171{
1172 switch (pname)
1173 {
1174 case GL_CURRENT_QUERY_EXT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001175 params[0] = mGLState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001176 break;
1177 case GL_QUERY_COUNTER_BITS_EXT:
1178 switch (target)
1179 {
1180 case GL_TIME_ELAPSED_EXT:
1181 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1182 break;
1183 case GL_TIMESTAMP_EXT:
1184 params[0] = getExtensions().queryCounterBitsTimestamp;
1185 break;
1186 default:
1187 UNREACHABLE();
1188 params[0] = 0;
1189 break;
1190 }
1191 break;
1192 default:
1193 UNREACHABLE();
1194 return;
1195 }
1196}
1197
Geoff Lang2186c382016-10-14 10:54:54 -04001198void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001199{
Geoff Lang2186c382016-10-14 10:54:54 -04001200 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001201}
1202
Geoff Lang2186c382016-10-14 10:54:54 -04001203void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001204{
Geoff Lang2186c382016-10-14 10:54:54 -04001205 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001206}
1207
Geoff Lang2186c382016-10-14 10:54:54 -04001208void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001209{
Geoff Lang2186c382016-10-14 10:54:54 -04001210 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001211}
1212
Geoff Lang2186c382016-10-14 10:54:54 -04001213void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001214{
Geoff Lang2186c382016-10-14 10:54:54 -04001215 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001216}
1217
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001218Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001219{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001220 return mState.mFramebuffers->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001221}
1222
Jamie Madill2f348d22017-06-05 10:50:59 -04001223FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001224{
Jamie Madill96a483b2017-06-27 16:49:21 -04001225 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001226}
1227
Jamie Madill2f348d22017-06-05 10:50:59 -04001228Query *Context::getQuery(GLuint handle, bool create, GLenum type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001229{
Jamie Madill96a483b2017-06-27 16:49:21 -04001230 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001231 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001232 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001233 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001234
1235 Query *query = mQueryMap.query(handle);
1236 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001237 {
Jamie Madill96a483b2017-06-27 16:49:21 -04001238 query = new Query(mImplementation->createQuery(type), handle);
1239 query->addRef();
1240 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001241 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001242 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001243}
1244
Geoff Lang70d0f492015-12-10 17:45:46 -05001245Query *Context::getQuery(GLuint handle) const
1246{
Jamie Madill96a483b2017-06-27 16:49:21 -04001247 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001248}
1249
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001250Texture *Context::getTargetTexture(GLenum target) const
1251{
Ian Ewellbda75592016-04-18 17:25:54 -04001252 ASSERT(ValidTextureTarget(this, target) || ValidTextureExternalTarget(this, target));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001253 return mGLState.getTargetTexture(target);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001254}
1255
Geoff Lang76b10c92014-09-05 16:28:14 -04001256Texture *Context::getSamplerTexture(unsigned int sampler, GLenum type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001257{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001258 return mGLState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001259}
1260
Geoff Lang492a7e42014-11-05 13:27:06 -05001261Compiler *Context::getCompiler() const
1262{
Jamie Madill2f348d22017-06-05 10:50:59 -04001263 if (mCompiler.get() == nullptr)
1264 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001265 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001266 }
1267 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001268}
1269
Jamie Madillc1d770e2017-04-13 17:31:24 -04001270void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001271{
1272 switch (pname)
1273 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001274 case GL_SHADER_COMPILER:
1275 *params = GL_TRUE;
1276 break;
1277 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1278 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1279 break;
1280 default:
1281 mGLState.getBooleanv(pname, params);
1282 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001283 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001284}
1285
Jamie Madillc1d770e2017-04-13 17:31:24 -04001286void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001287{
Shannon Woods53a94a82014-06-24 15:20:36 -04001288 // Queries about context capabilities and maximums are answered by Context.
1289 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001290 switch (pname)
1291 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001292 case GL_ALIASED_LINE_WIDTH_RANGE:
1293 params[0] = mCaps.minAliasedLineWidth;
1294 params[1] = mCaps.maxAliasedLineWidth;
1295 break;
1296 case GL_ALIASED_POINT_SIZE_RANGE:
1297 params[0] = mCaps.minAliasedPointSize;
1298 params[1] = mCaps.maxAliasedPointSize;
1299 break;
1300 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1301 ASSERT(mExtensions.textureFilterAnisotropic);
1302 *params = mExtensions.maxTextureAnisotropy;
1303 break;
1304 case GL_MAX_TEXTURE_LOD_BIAS:
1305 *params = mCaps.maxLODBias;
1306 break;
1307
1308 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1309 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1310 {
1311 ASSERT(mExtensions.pathRendering);
1312 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1313 memcpy(params, m, 16 * sizeof(GLfloat));
1314 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001315 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001316
Jamie Madill231c7f52017-04-26 13:45:37 -04001317 default:
1318 mGLState.getFloatv(pname, params);
1319 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001320 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001321}
1322
Jamie Madillc1d770e2017-04-13 17:31:24 -04001323void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001324{
Shannon Woods53a94a82014-06-24 15:20:36 -04001325 // Queries about context capabilities and maximums are answered by Context.
1326 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001327
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001328 switch (pname)
1329 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001330 case GL_MAX_VERTEX_ATTRIBS:
1331 *params = mCaps.maxVertexAttributes;
1332 break;
1333 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1334 *params = mCaps.maxVertexUniformVectors;
1335 break;
1336 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
1337 *params = mCaps.maxVertexUniformComponents;
1338 break;
1339 case GL_MAX_VARYING_VECTORS:
1340 *params = mCaps.maxVaryingVectors;
1341 break;
1342 case GL_MAX_VARYING_COMPONENTS:
1343 *params = mCaps.maxVertexOutputComponents;
1344 break;
1345 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1346 *params = mCaps.maxCombinedTextureImageUnits;
1347 break;
1348 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
1349 *params = mCaps.maxVertexTextureImageUnits;
1350 break;
1351 case GL_MAX_TEXTURE_IMAGE_UNITS:
1352 *params = mCaps.maxTextureImageUnits;
1353 break;
1354 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1355 *params = mCaps.maxFragmentUniformVectors;
1356 break;
1357 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
1358 *params = mCaps.maxFragmentUniformComponents;
1359 break;
1360 case GL_MAX_RENDERBUFFER_SIZE:
1361 *params = mCaps.maxRenderbufferSize;
1362 break;
1363 case GL_MAX_COLOR_ATTACHMENTS_EXT:
1364 *params = mCaps.maxColorAttachments;
1365 break;
1366 case GL_MAX_DRAW_BUFFERS_EXT:
1367 *params = mCaps.maxDrawBuffers;
1368 break;
1369 // case GL_FRAMEBUFFER_BINDING: // now equivalent to
1370 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
1371 case GL_SUBPIXEL_BITS:
1372 *params = 4;
1373 break;
1374 case GL_MAX_TEXTURE_SIZE:
1375 *params = mCaps.max2DTextureSize;
1376 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001377 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
1378 *params = mCaps.maxRectangleTextureSize;
1379 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001380 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1381 *params = mCaps.maxCubeMapTextureSize;
1382 break;
1383 case GL_MAX_3D_TEXTURE_SIZE:
1384 *params = mCaps.max3DTextureSize;
1385 break;
1386 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1387 *params = mCaps.maxArrayTextureLayers;
1388 break;
1389 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1390 *params = mCaps.uniformBufferOffsetAlignment;
1391 break;
1392 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1393 *params = mCaps.maxUniformBufferBindings;
1394 break;
1395 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
1396 *params = mCaps.maxVertexUniformBlocks;
1397 break;
1398 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
1399 *params = mCaps.maxFragmentUniformBlocks;
1400 break;
1401 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1402 *params = mCaps.maxCombinedTextureImageUnits;
1403 break;
1404 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1405 *params = mCaps.maxVertexOutputComponents;
1406 break;
1407 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1408 *params = mCaps.maxFragmentInputComponents;
1409 break;
1410 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1411 *params = mCaps.minProgramTexelOffset;
1412 break;
1413 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1414 *params = mCaps.maxProgramTexelOffset;
1415 break;
1416 case GL_MAJOR_VERSION:
1417 *params = getClientVersion().major;
1418 break;
1419 case GL_MINOR_VERSION:
1420 *params = getClientVersion().minor;
1421 break;
1422 case GL_MAX_ELEMENTS_INDICES:
1423 *params = mCaps.maxElementsIndices;
1424 break;
1425 case GL_MAX_ELEMENTS_VERTICES:
1426 *params = mCaps.maxElementsVertices;
1427 break;
1428 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1429 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1430 break;
1431 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1432 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1433 break;
1434 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1435 *params = mCaps.maxTransformFeedbackSeparateComponents;
1436 break;
1437 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1438 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1439 break;
1440 case GL_MAX_SAMPLES_ANGLE:
1441 *params = mCaps.maxSamples;
1442 break;
1443 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001444 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001445 params[0] = mCaps.maxViewportWidth;
1446 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001447 }
1448 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001449 case GL_COMPRESSED_TEXTURE_FORMATS:
1450 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1451 params);
1452 break;
1453 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1454 *params = mResetStrategy;
1455 break;
1456 case GL_NUM_SHADER_BINARY_FORMATS:
1457 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1458 break;
1459 case GL_SHADER_BINARY_FORMATS:
1460 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1461 break;
1462 case GL_NUM_PROGRAM_BINARY_FORMATS:
1463 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1464 break;
1465 case GL_PROGRAM_BINARY_FORMATS:
1466 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1467 break;
1468 case GL_NUM_EXTENSIONS:
1469 *params = static_cast<GLint>(mExtensionStrings.size());
1470 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001471
Jamie Madill231c7f52017-04-26 13:45:37 -04001472 // GL_KHR_debug
1473 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1474 *params = mExtensions.maxDebugMessageLength;
1475 break;
1476 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1477 *params = mExtensions.maxDebugLoggedMessages;
1478 break;
1479 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1480 *params = mExtensions.maxDebugGroupStackDepth;
1481 break;
1482 case GL_MAX_LABEL_LENGTH:
1483 *params = mExtensions.maxLabelLength;
1484 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001485
Martin Radeve5285d22017-07-14 16:23:53 +03001486 // GL_ANGLE_multiview
1487 case GL_MAX_VIEWS_ANGLE:
1488 *params = mExtensions.maxViews;
1489 break;
1490
Jamie Madill231c7f52017-04-26 13:45:37 -04001491 // GL_EXT_disjoint_timer_query
1492 case GL_GPU_DISJOINT_EXT:
1493 *params = mImplementation->getGPUDisjoint();
1494 break;
1495 case GL_MAX_FRAMEBUFFER_WIDTH:
1496 *params = mCaps.maxFramebufferWidth;
1497 break;
1498 case GL_MAX_FRAMEBUFFER_HEIGHT:
1499 *params = mCaps.maxFramebufferHeight;
1500 break;
1501 case GL_MAX_FRAMEBUFFER_SAMPLES:
1502 *params = mCaps.maxFramebufferSamples;
1503 break;
1504 case GL_MAX_SAMPLE_MASK_WORDS:
1505 *params = mCaps.maxSampleMaskWords;
1506 break;
1507 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1508 *params = mCaps.maxColorTextureSamples;
1509 break;
1510 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1511 *params = mCaps.maxDepthTextureSamples;
1512 break;
1513 case GL_MAX_INTEGER_SAMPLES:
1514 *params = mCaps.maxIntegerSamples;
1515 break;
1516 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1517 *params = mCaps.maxVertexAttribRelativeOffset;
1518 break;
1519 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1520 *params = mCaps.maxVertexAttribBindings;
1521 break;
1522 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1523 *params = mCaps.maxVertexAttribStride;
1524 break;
1525 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
1526 *params = mCaps.maxVertexAtomicCounterBuffers;
1527 break;
1528 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
1529 *params = mCaps.maxVertexAtomicCounters;
1530 break;
1531 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
1532 *params = mCaps.maxVertexImageUniforms;
1533 break;
1534 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
1535 *params = mCaps.maxVertexShaderStorageBlocks;
1536 break;
1537 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
1538 *params = mCaps.maxFragmentAtomicCounterBuffers;
1539 break;
1540 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
1541 *params = mCaps.maxFragmentAtomicCounters;
1542 break;
1543 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
1544 *params = mCaps.maxFragmentImageUniforms;
1545 break;
1546 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
1547 *params = mCaps.maxFragmentShaderStorageBlocks;
1548 break;
1549 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1550 *params = mCaps.minProgramTextureGatherOffset;
1551 break;
1552 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1553 *params = mCaps.maxProgramTextureGatherOffset;
1554 break;
1555 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1556 *params = mCaps.maxComputeWorkGroupInvocations;
1557 break;
1558 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
1559 *params = mCaps.maxComputeUniformBlocks;
1560 break;
1561 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
1562 *params = mCaps.maxComputeTextureImageUnits;
1563 break;
1564 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1565 *params = mCaps.maxComputeSharedMemorySize;
1566 break;
1567 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
1568 *params = mCaps.maxComputeUniformComponents;
1569 break;
1570 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
1571 *params = mCaps.maxComputeAtomicCounterBuffers;
1572 break;
1573 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
1574 *params = mCaps.maxComputeAtomicCounters;
1575 break;
1576 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
1577 *params = mCaps.maxComputeImageUniforms;
1578 break;
1579 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
1580 *params = mCaps.maxCombinedComputeUniformComponents;
1581 break;
1582 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
1583 *params = mCaps.maxComputeShaderStorageBlocks;
1584 break;
1585 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1586 *params = mCaps.maxCombinedShaderOutputResources;
1587 break;
1588 case GL_MAX_UNIFORM_LOCATIONS:
1589 *params = mCaps.maxUniformLocations;
1590 break;
1591 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1592 *params = mCaps.maxAtomicCounterBufferBindings;
1593 break;
1594 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1595 *params = mCaps.maxAtomicCounterBufferSize;
1596 break;
1597 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1598 *params = mCaps.maxCombinedAtomicCounterBuffers;
1599 break;
1600 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1601 *params = mCaps.maxCombinedAtomicCounters;
1602 break;
1603 case GL_MAX_IMAGE_UNITS:
1604 *params = mCaps.maxImageUnits;
1605 break;
1606 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1607 *params = mCaps.maxCombinedImageUniforms;
1608 break;
1609 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1610 *params = mCaps.maxShaderStorageBufferBindings;
1611 break;
1612 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1613 *params = mCaps.maxCombinedShaderStorageBlocks;
1614 break;
1615 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1616 *params = mCaps.shaderStorageBufferOffsetAlignment;
1617 break;
1618 default:
1619 mGLState.getIntegerv(this, pname, params);
1620 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001621 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001622}
1623
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001624void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001625{
Shannon Woods53a94a82014-06-24 15:20:36 -04001626 // Queries about context capabilities and maximums are answered by Context.
1627 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001628 switch (pname)
1629 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001630 case GL_MAX_ELEMENT_INDEX:
1631 *params = mCaps.maxElementIndex;
1632 break;
1633 case GL_MAX_UNIFORM_BLOCK_SIZE:
1634 *params = mCaps.maxUniformBlockSize;
1635 break;
1636 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
1637 *params = mCaps.maxCombinedVertexUniformComponents;
1638 break;
1639 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
1640 *params = mCaps.maxCombinedFragmentUniformComponents;
1641 break;
1642 case GL_MAX_SERVER_WAIT_TIMEOUT:
1643 *params = mCaps.maxServerWaitTimeout;
1644 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001645
Jamie Madill231c7f52017-04-26 13:45:37 -04001646 // GL_EXT_disjoint_timer_query
1647 case GL_TIMESTAMP_EXT:
1648 *params = mImplementation->getTimestamp();
1649 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001650
Jamie Madill231c7f52017-04-26 13:45:37 -04001651 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1652 *params = mCaps.maxShaderStorageBlockSize;
1653 break;
1654 default:
1655 UNREACHABLE();
1656 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001657 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001658}
1659
Geoff Lang70d0f492015-12-10 17:45:46 -05001660void Context::getPointerv(GLenum pname, void **params) const
1661{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001662 mGLState.getPointerv(pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001663}
1664
Martin Radev66fb8202016-07-28 11:45:20 +03001665void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001666{
Shannon Woods53a94a82014-06-24 15:20:36 -04001667 // Queries about context capabilities and maximums are answered by Context.
1668 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001669
1670 GLenum nativeType;
1671 unsigned int numParams;
1672 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1673 ASSERT(queryStatus);
1674
1675 if (nativeType == GL_INT)
1676 {
1677 switch (target)
1678 {
1679 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1680 ASSERT(index < 3u);
1681 *data = mCaps.maxComputeWorkGroupCount[index];
1682 break;
1683 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1684 ASSERT(index < 3u);
1685 *data = mCaps.maxComputeWorkGroupSize[index];
1686 break;
1687 default:
1688 mGLState.getIntegeri_v(target, index, data);
1689 }
1690 }
1691 else
1692 {
1693 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1694 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001695}
1696
Martin Radev66fb8202016-07-28 11:45:20 +03001697void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001698{
Shannon Woods53a94a82014-06-24 15:20:36 -04001699 // Queries about context capabilities and maximums are answered by Context.
1700 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001701
1702 GLenum nativeType;
1703 unsigned int numParams;
1704 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1705 ASSERT(queryStatus);
1706
1707 if (nativeType == GL_INT_64_ANGLEX)
1708 {
1709 mGLState.getInteger64i_v(target, index, data);
1710 }
1711 else
1712 {
1713 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1714 }
1715}
1716
1717void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1718{
1719 // Queries about context capabilities and maximums are answered by Context.
1720 // Queries about current GL state values are answered by State.
1721
1722 GLenum nativeType;
1723 unsigned int numParams;
1724 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1725 ASSERT(queryStatus);
1726
1727 if (nativeType == GL_BOOL)
1728 {
1729 mGLState.getBooleani_v(target, index, data);
1730 }
1731 else
1732 {
1733 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1734 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001735}
1736
He Yunchao010e4db2017-03-03 14:22:06 +08001737void Context::getBufferParameteriv(GLenum target, GLenum pname, GLint *params)
1738{
1739 Buffer *buffer = mGLState.getTargetBuffer(target);
1740 QueryBufferParameteriv(buffer, pname, params);
1741}
1742
1743void Context::getFramebufferAttachmentParameteriv(GLenum target,
1744 GLenum attachment,
1745 GLenum pname,
1746 GLint *params)
1747{
1748 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
1749 QueryFramebufferAttachmentParameteriv(framebuffer, attachment, pname, params);
1750}
1751
1752void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
1753{
1754 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
1755 QueryRenderbufferiv(this, renderbuffer, pname, params);
1756}
1757
1758void Context::getTexParameterfv(GLenum target, GLenum pname, GLfloat *params)
1759{
1760 Texture *texture = getTargetTexture(target);
1761 QueryTexParameterfv(texture, pname, params);
1762}
1763
1764void Context::getTexParameteriv(GLenum target, GLenum pname, GLint *params)
1765{
1766 Texture *texture = getTargetTexture(target);
1767 QueryTexParameteriv(texture, pname, params);
1768}
1769void Context::texParameterf(GLenum target, GLenum pname, GLfloat param)
1770{
1771 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001772 SetTexParameterf(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04001773 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001774}
1775
1776void Context::texParameterfv(GLenum target, GLenum pname, const GLfloat *params)
1777{
1778 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001779 SetTexParameterfv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04001780 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001781}
1782
1783void Context::texParameteri(GLenum target, GLenum pname, GLint param)
1784{
1785 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001786 SetTexParameteri(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04001787 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001788}
1789
1790void Context::texParameteriv(GLenum target, GLenum pname, const GLint *params)
1791{
1792 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001793 SetTexParameteriv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04001794 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001795}
1796
Jamie Madill675fe712016-12-19 13:07:54 -05001797void Context::drawArrays(GLenum mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001798{
Jamie Madill05b35b22017-10-03 09:01:44 -04001799 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001800 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
1801 MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001802}
1803
Jamie Madill675fe712016-12-19 13:07:54 -05001804void Context::drawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04001805{
Jamie Madill05b35b22017-10-03 09:01:44 -04001806 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001807 ANGLE_CONTEXT_TRY(
1808 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
1809 MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback());
Geoff Langf6db0982015-08-25 13:04:00 -04001810}
1811
Jamie Madill876429b2017-04-20 15:46:24 -04001812void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001813{
Jamie Madill05b35b22017-10-03 09:01:44 -04001814 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001815 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04001816}
1817
Jamie Madill675fe712016-12-19 13:07:54 -05001818void Context::drawElementsInstanced(GLenum mode,
1819 GLsizei count,
1820 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04001821 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04001822 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04001823{
Jamie Madill05b35b22017-10-03 09:01:44 -04001824 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001825 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08001826 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04001827}
1828
Jamie Madill675fe712016-12-19 13:07:54 -05001829void Context::drawRangeElements(GLenum mode,
1830 GLuint start,
1831 GLuint end,
1832 GLsizei count,
1833 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04001834 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04001835{
Jamie Madill05b35b22017-10-03 09:01:44 -04001836 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001837 ANGLE_CONTEXT_TRY(
1838 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001839}
1840
Jamie Madill876429b2017-04-20 15:46:24 -04001841void Context::drawArraysIndirect(GLenum mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08001842{
Jamie Madill05b35b22017-10-03 09:01:44 -04001843 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001844 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08001845}
1846
Jamie Madill876429b2017-04-20 15:46:24 -04001847void Context::drawElementsIndirect(GLenum mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08001848{
Jamie Madill05b35b22017-10-03 09:01:44 -04001849 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001850 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08001851}
1852
Jamie Madill675fe712016-12-19 13:07:54 -05001853void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001854{
Jamie Madill675fe712016-12-19 13:07:54 -05001855 handleError(mImplementation->flush());
Geoff Lang129753a2015-01-09 16:52:09 -05001856}
1857
Jamie Madill675fe712016-12-19 13:07:54 -05001858void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05001859{
Jamie Madill675fe712016-12-19 13:07:54 -05001860 handleError(mImplementation->finish());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001861}
1862
Austin Kinross6ee1e782015-05-29 17:05:37 -07001863void Context::insertEventMarker(GLsizei length, const char *marker)
1864{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001865 ASSERT(mImplementation);
1866 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07001867}
1868
1869void Context::pushGroupMarker(GLsizei length, const char *marker)
1870{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001871 ASSERT(mImplementation);
1872 mImplementation->pushGroupMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07001873}
1874
1875void Context::popGroupMarker()
1876{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001877 ASSERT(mImplementation);
1878 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07001879}
1880
Geoff Langd8605522016-04-13 10:19:12 -04001881void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
1882{
1883 Program *programObject = getProgram(program);
1884 ASSERT(programObject);
1885
1886 programObject->bindUniformLocation(location, name);
1887}
1888
Sami Väisänena797e062016-05-12 15:23:40 +03001889void Context::setCoverageModulation(GLenum components)
1890{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001891 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03001892}
1893
Sami Väisänene45e53b2016-05-25 10:36:04 +03001894void Context::loadPathRenderingMatrix(GLenum matrixMode, const GLfloat *matrix)
1895{
1896 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
1897}
1898
1899void Context::loadPathRenderingIdentityMatrix(GLenum matrixMode)
1900{
1901 GLfloat I[16];
1902 angle::Matrix<GLfloat>::setToIdentity(I);
1903
1904 mGLState.loadPathRenderingMatrix(matrixMode, I);
1905}
1906
1907void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
1908{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001909 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001910 if (!pathObj)
1911 return;
1912
1913 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1914 syncRendererState();
1915
1916 mImplementation->stencilFillPath(pathObj, fillMode, mask);
1917}
1918
1919void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
1920{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001921 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001922 if (!pathObj)
1923 return;
1924
1925 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1926 syncRendererState();
1927
1928 mImplementation->stencilStrokePath(pathObj, reference, mask);
1929}
1930
1931void Context::coverFillPath(GLuint path, GLenum coverMode)
1932{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001933 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001934 if (!pathObj)
1935 return;
1936
1937 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1938 syncRendererState();
1939
1940 mImplementation->coverFillPath(pathObj, coverMode);
1941}
1942
1943void Context::coverStrokePath(GLuint path, GLenum coverMode)
1944{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001945 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001946 if (!pathObj)
1947 return;
1948
1949 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1950 syncRendererState();
1951
1952 mImplementation->coverStrokePath(pathObj, coverMode);
1953}
1954
1955void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
1956{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001957 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001958 if (!pathObj)
1959 return;
1960
1961 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1962 syncRendererState();
1963
1964 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
1965}
1966
1967void Context::stencilThenCoverStrokePath(GLuint path,
1968 GLint reference,
1969 GLuint mask,
1970 GLenum coverMode)
1971{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001972 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001973 if (!pathObj)
1974 return;
1975
1976 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1977 syncRendererState();
1978
1979 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
1980}
1981
Sami Väisänend59ca052016-06-21 16:10:00 +03001982void Context::coverFillPathInstanced(GLsizei numPaths,
1983 GLenum pathNameType,
1984 const void *paths,
1985 GLuint pathBase,
1986 GLenum coverMode,
1987 GLenum transformType,
1988 const GLfloat *transformValues)
1989{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001990 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03001991
1992 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1993 syncRendererState();
1994
1995 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
1996}
Sami Väisänen46eaa942016-06-29 10:26:37 +03001997
Sami Väisänend59ca052016-06-21 16:10:00 +03001998void Context::coverStrokePathInstanced(GLsizei numPaths,
1999 GLenum pathNameType,
2000 const void *paths,
2001 GLuint pathBase,
2002 GLenum coverMode,
2003 GLenum transformType,
2004 const GLfloat *transformValues)
2005{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002006 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002007
2008 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2009 syncRendererState();
2010
2011 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2012 transformValues);
2013}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002014
Sami Väisänend59ca052016-06-21 16:10:00 +03002015void Context::stencilFillPathInstanced(GLsizei numPaths,
2016 GLenum pathNameType,
2017 const void *paths,
2018 GLuint pathBase,
2019 GLenum fillMode,
2020 GLuint mask,
2021 GLenum transformType,
2022 const GLfloat *transformValues)
2023{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002024 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002025
2026 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2027 syncRendererState();
2028
2029 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2030 transformValues);
2031}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002032
Sami Väisänend59ca052016-06-21 16:10:00 +03002033void Context::stencilStrokePathInstanced(GLsizei numPaths,
2034 GLenum pathNameType,
2035 const void *paths,
2036 GLuint pathBase,
2037 GLint reference,
2038 GLuint mask,
2039 GLenum transformType,
2040 const GLfloat *transformValues)
2041{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002042 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002043
2044 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2045 syncRendererState();
2046
2047 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2048 transformValues);
2049}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002050
Sami Väisänend59ca052016-06-21 16:10:00 +03002051void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2052 GLenum pathNameType,
2053 const void *paths,
2054 GLuint pathBase,
2055 GLenum fillMode,
2056 GLuint mask,
2057 GLenum coverMode,
2058 GLenum transformType,
2059 const GLfloat *transformValues)
2060{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002061 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002062
2063 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2064 syncRendererState();
2065
2066 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2067 transformType, transformValues);
2068}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002069
Sami Väisänend59ca052016-06-21 16:10:00 +03002070void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2071 GLenum pathNameType,
2072 const void *paths,
2073 GLuint pathBase,
2074 GLint reference,
2075 GLuint mask,
2076 GLenum coverMode,
2077 GLenum transformType,
2078 const GLfloat *transformValues)
2079{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002080 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002081
2082 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2083 syncRendererState();
2084
2085 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2086 transformType, transformValues);
2087}
2088
Sami Väisänen46eaa942016-06-29 10:26:37 +03002089void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2090{
2091 auto *programObject = getProgram(program);
2092
2093 programObject->bindFragmentInputLocation(location, name);
2094}
2095
2096void Context::programPathFragmentInputGen(GLuint program,
2097 GLint location,
2098 GLenum genMode,
2099 GLint components,
2100 const GLfloat *coeffs)
2101{
2102 auto *programObject = getProgram(program);
2103
Jamie Madillbd044ed2017-06-05 12:59:21 -04002104 programObject->pathFragmentInputGen(this, location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002105}
2106
jchen1015015f72017-03-16 13:54:21 +08002107GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2108{
jchen10fd7c3b52017-03-21 15:36:03 +08002109 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002110 return QueryProgramResourceIndex(programObject, programInterface, name);
2111}
2112
jchen10fd7c3b52017-03-21 15:36:03 +08002113void Context::getProgramResourceName(GLuint program,
2114 GLenum programInterface,
2115 GLuint index,
2116 GLsizei bufSize,
2117 GLsizei *length,
2118 GLchar *name)
2119{
2120 const auto *programObject = getProgram(program);
2121 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2122}
2123
jchen10191381f2017-04-11 13:59:04 +08002124GLint Context::getProgramResourceLocation(GLuint program,
2125 GLenum programInterface,
2126 const GLchar *name)
2127{
2128 const auto *programObject = getProgram(program);
2129 return QueryProgramResourceLocation(programObject, programInterface, name);
2130}
2131
jchen10880683b2017-04-12 16:21:55 +08002132void Context::getProgramResourceiv(GLuint program,
2133 GLenum programInterface,
2134 GLuint index,
2135 GLsizei propCount,
2136 const GLenum *props,
2137 GLsizei bufSize,
2138 GLsizei *length,
2139 GLint *params)
2140{
2141 const auto *programObject = getProgram(program);
2142 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2143 length, params);
2144}
2145
jchen10d9cd7b72017-08-30 15:04:25 +08002146void Context::getProgramInterfaceiv(GLuint program,
2147 GLenum programInterface,
2148 GLenum pname,
2149 GLint *params)
2150{
2151 const auto *programObject = getProgram(program);
2152 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2153}
2154
Jamie Madill71c88b32017-09-14 22:20:29 -04002155void Context::handleError(const Error &error)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002156{
Geoff Langda5777c2014-07-11 09:52:58 -04002157 if (error.isError())
2158 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002159 GLenum code = error.getCode();
2160 mErrors.insert(code);
2161 if (code == GL_OUT_OF_MEMORY && getWorkarounds().loseContextOnOutOfMemory)
2162 {
2163 markContextLost();
2164 }
Geoff Lang70d0f492015-12-10 17:45:46 -05002165
2166 if (!error.getMessage().empty())
2167 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002168 auto *debug = &mGLState.getDebug();
2169 debug->insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, error.getID(),
2170 GL_DEBUG_SEVERITY_HIGH, error.getMessage());
Geoff Lang70d0f492015-12-10 17:45:46 -05002171 }
Geoff Langda5777c2014-07-11 09:52:58 -04002172 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002173}
2174
2175// Get one of the recorded errors and clear its flag, if any.
2176// [OpenGL ES 2.0.24] section 2.5 page 13.
2177GLenum Context::getError()
2178{
Geoff Langda5777c2014-07-11 09:52:58 -04002179 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002180 {
Geoff Langda5777c2014-07-11 09:52:58 -04002181 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002182 }
Geoff Langda5777c2014-07-11 09:52:58 -04002183 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002184 {
Geoff Langda5777c2014-07-11 09:52:58 -04002185 GLenum error = *mErrors.begin();
2186 mErrors.erase(mErrors.begin());
2187 return error;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002188 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002189}
2190
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002191// NOTE: this function should not assume that this context is current!
2192void Context::markContextLost()
2193{
2194 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002195 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002196 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002197 mContextLostForced = true;
2198 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002199 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002200}
2201
2202bool Context::isContextLost()
2203{
2204 return mContextLost;
2205}
2206
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002207GLenum Context::getResetStatus()
2208{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002209 // Even if the application doesn't want to know about resets, we want to know
2210 // as it will allow us to skip all the calls.
2211 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002212 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002213 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002214 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002215 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002216 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002217
2218 // EXT_robustness, section 2.6: If the reset notification behavior is
2219 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2220 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2221 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002222 }
2223
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002224 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2225 // status should be returned at least once, and GL_NO_ERROR should be returned
2226 // once the device has finished resetting.
2227 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002228 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002229 ASSERT(mResetStatus == GL_NO_ERROR);
2230 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002231
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002232 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002233 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002234 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002235 }
2236 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002237 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002238 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002239 // If markContextLost was used to mark the context lost then
2240 // assume that is not recoverable, and continue to report the
2241 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002242 mResetStatus = mImplementation->getResetStatus();
2243 }
Jamie Madill893ab082014-05-16 16:56:10 -04002244
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002245 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002246}
2247
2248bool Context::isResetNotificationEnabled()
2249{
2250 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2251}
2252
Corentin Walleze3b10e82015-05-20 11:06:25 -04002253const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002254{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002255 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002256}
2257
2258EGLenum Context::getClientType() const
2259{
2260 return mClientType;
2261}
2262
2263EGLenum Context::getRenderBuffer() const
2264{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002265 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2266 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002267 {
2268 return EGL_NONE;
2269 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002270
2271 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(GL_BACK);
2272 ASSERT(backAttachment != nullptr);
2273 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002274}
2275
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002276VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002277{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002278 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002279 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2280 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002281 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002282 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2283 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002284
Jamie Madill96a483b2017-06-27 16:49:21 -04002285 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002286 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002287
2288 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002289}
2290
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002291TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002292{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002293 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002294 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2295 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002296 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002297 transformFeedback =
2298 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002299 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002300 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002301 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002302
2303 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002304}
2305
2306bool Context::isVertexArrayGenerated(GLuint vertexArray)
2307{
Jamie Madill96a483b2017-06-27 16:49:21 -04002308 ASSERT(mVertexArrayMap.contains(0));
2309 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002310}
2311
2312bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2313{
Jamie Madill96a483b2017-06-27 16:49:21 -04002314 ASSERT(mTransformFeedbackMap.contains(0));
2315 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002316}
2317
Shannon Woods53a94a82014-06-24 15:20:36 -04002318void Context::detachTexture(GLuint texture)
2319{
2320 // Simple pass-through to State's detachTexture method, as textures do not require
2321 // allocation map management either here or in the resource manager at detach time.
2322 // Zero textures are held by the Context, and we don't attempt to request them from
2323 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002324 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002325}
2326
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002327void Context::detachBuffer(GLuint buffer)
2328{
Yuly Novikov5807a532015-12-03 13:01:22 -05002329 // Simple pass-through to State's detachBuffer method, since
2330 // only buffer attachments to container objects that are bound to the current context
2331 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002332
Yuly Novikov5807a532015-12-03 13:01:22 -05002333 // [OpenGL ES 3.2] section 5.1.2 page 45:
2334 // Attachments to unbound container objects, such as
2335 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2336 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002337 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002338}
2339
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002340void Context::detachFramebuffer(GLuint framebuffer)
2341{
Shannon Woods53a94a82014-06-24 15:20:36 -04002342 // Framebuffer detachment is handled by Context, because 0 is a valid
2343 // Framebuffer object, and a pointer to it must be passed from Context
2344 // to State at binding time.
2345
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002346 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002347 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2348 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2349 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002350
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002351 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002352 {
2353 bindReadFramebuffer(0);
2354 }
2355
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002356 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002357 {
2358 bindDrawFramebuffer(0);
2359 }
2360}
2361
2362void Context::detachRenderbuffer(GLuint renderbuffer)
2363{
Jamie Madilla02315b2017-02-23 14:14:47 -05002364 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002365}
2366
Jamie Madill57a89722013-07-02 11:57:03 -04002367void Context::detachVertexArray(GLuint vertexArray)
2368{
Jamie Madill77a72f62015-04-14 11:18:32 -04002369 // Vertex array detachment is handled by Context, because 0 is a valid
2370 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002371 // binding time.
2372
Jamie Madill57a89722013-07-02 11:57:03 -04002373 // [OpenGL ES 3.0.2] section 2.10 page 43:
2374 // If a vertex array object that is currently bound is deleted, the binding
2375 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002376 if (mGLState.removeVertexArrayBinding(vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002377 {
2378 bindVertexArray(0);
2379 }
2380}
2381
Geoff Langc8058452014-02-03 12:04:11 -05002382void Context::detachTransformFeedback(GLuint transformFeedback)
2383{
Corentin Walleza2257da2016-04-19 16:43:12 -04002384 // Transform feedback detachment is handled by Context, because 0 is a valid
2385 // transform feedback, and a pointer to it must be passed from Context to State at
2386 // binding time.
2387
2388 // The OpenGL specification doesn't mention what should happen when the currently bound
2389 // transform feedback object is deleted. Since it is a container object, we treat it like
2390 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002391 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002392 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002393 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002394 }
Geoff Langc8058452014-02-03 12:04:11 -05002395}
2396
Jamie Madilldc356042013-07-19 16:36:57 -04002397void Context::detachSampler(GLuint sampler)
2398{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002399 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002400}
2401
Yunchao Hea336b902017-08-02 16:05:21 +08002402void Context::detachProgramPipeline(GLuint pipeline)
2403{
2404 mGLState.detachProgramPipeline(this, pipeline);
2405}
2406
Jamie Madill3ef140a2017-08-26 23:11:21 -04002407void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002408{
Shaodde78e82017-05-22 14:13:27 +08002409 mGLState.setVertexAttribDivisor(this, index, divisor);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002410}
2411
Jamie Madille29d1672013-07-19 16:36:57 -04002412void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2413{
Geoff Langc1984ed2016-10-07 12:41:00 -04002414 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002415 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002416 SetSamplerParameteri(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002417 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002418}
Jamie Madille29d1672013-07-19 16:36:57 -04002419
Geoff Langc1984ed2016-10-07 12:41:00 -04002420void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2421{
2422 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002423 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002424 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002425 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002426}
2427
2428void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2429{
Geoff Langc1984ed2016-10-07 12:41:00 -04002430 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002431 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002432 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002433 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002434}
2435
Geoff Langc1984ed2016-10-07 12:41:00 -04002436void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002437{
Geoff Langc1984ed2016-10-07 12:41:00 -04002438 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002439 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002440 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002441 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002442}
2443
Geoff Langc1984ed2016-10-07 12:41:00 -04002444void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002445{
Geoff Langc1984ed2016-10-07 12:41:00 -04002446 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002447 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002448 QuerySamplerParameteriv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002449 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002450}
Jamie Madill9675b802013-07-19 16:36:59 -04002451
Geoff Langc1984ed2016-10-07 12:41:00 -04002452void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2453{
2454 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002455 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002456 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002457 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002458}
2459
Olli Etuahof0fee072016-03-30 15:11:58 +03002460void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2461{
2462 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002463 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002464}
2465
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002466void Context::initRendererString()
2467{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002468 std::ostringstream rendererString;
2469 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002470 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002471 rendererString << ")";
2472
Geoff Langcec35902014-04-16 10:52:36 -04002473 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002474}
2475
Geoff Langc339c4e2016-11-29 10:37:36 -05002476void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002477{
Geoff Langc339c4e2016-11-29 10:37:36 -05002478 const Version &clientVersion = getClientVersion();
2479
2480 std::ostringstream versionString;
2481 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2482 << ANGLE_VERSION_STRING << ")";
2483 mVersionString = MakeStaticString(versionString.str());
2484
2485 std::ostringstream shadingLanguageVersionString;
2486 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2487 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2488 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2489 << ")";
2490 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002491}
2492
Geoff Langcec35902014-04-16 10:52:36 -04002493void Context::initExtensionStrings()
2494{
Geoff Langc339c4e2016-11-29 10:37:36 -05002495 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2496 std::ostringstream combinedStringStream;
2497 std::copy(strings.begin(), strings.end(),
2498 std::ostream_iterator<const char *>(combinedStringStream, " "));
2499 return MakeStaticString(combinedStringStream.str());
2500 };
2501
2502 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002503 for (const auto &extensionString : mExtensions.getStrings())
2504 {
2505 mExtensionStrings.push_back(MakeStaticString(extensionString));
2506 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002507 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002508
Bryan Bernhart58806562017-01-05 13:09:31 -08002509 const gl::Extensions &nativeExtensions = mImplementation->getNativeExtensions();
2510
Geoff Langc339c4e2016-11-29 10:37:36 -05002511 mRequestableExtensionStrings.clear();
2512 for (const auto &extensionInfo : GetExtensionInfoMap())
2513 {
2514 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08002515 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
2516 nativeExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002517 {
2518 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
2519 }
2520 }
2521 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002522}
2523
Geoff Langc339c4e2016-11-29 10:37:36 -05002524const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04002525{
Geoff Langc339c4e2016-11-29 10:37:36 -05002526 switch (name)
2527 {
2528 case GL_VENDOR:
2529 return reinterpret_cast<const GLubyte *>("Google Inc.");
2530
2531 case GL_RENDERER:
2532 return reinterpret_cast<const GLubyte *>(mRendererString);
2533
2534 case GL_VERSION:
2535 return reinterpret_cast<const GLubyte *>(mVersionString);
2536
2537 case GL_SHADING_LANGUAGE_VERSION:
2538 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
2539
2540 case GL_EXTENSIONS:
2541 return reinterpret_cast<const GLubyte *>(mExtensionString);
2542
2543 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2544 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
2545
2546 default:
2547 UNREACHABLE();
2548 return nullptr;
2549 }
Geoff Langcec35902014-04-16 10:52:36 -04002550}
2551
Geoff Langc339c4e2016-11-29 10:37:36 -05002552const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04002553{
Geoff Langc339c4e2016-11-29 10:37:36 -05002554 switch (name)
2555 {
2556 case GL_EXTENSIONS:
2557 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
2558
2559 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2560 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
2561
2562 default:
2563 UNREACHABLE();
2564 return nullptr;
2565 }
Geoff Langcec35902014-04-16 10:52:36 -04002566}
2567
2568size_t Context::getExtensionStringCount() const
2569{
2570 return mExtensionStrings.size();
2571}
2572
Geoff Lang111a99e2017-10-17 10:58:41 -04002573bool Context::isExtensionRequestable(const char *name)
2574{
2575 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2576 auto extension = extensionInfos.find(name);
2577
2578 const Extensions &nativeExtensions = mImplementation->getNativeExtensions();
2579 return extension != extensionInfos.end() && extension->second.Requestable &&
2580 nativeExtensions.*(extension->second.ExtensionsMember);
2581}
2582
Geoff Langc339c4e2016-11-29 10:37:36 -05002583void Context::requestExtension(const char *name)
2584{
2585 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2586 ASSERT(extensionInfos.find(name) != extensionInfos.end());
2587 const auto &extension = extensionInfos.at(name);
2588 ASSERT(extension.Requestable);
Geoff Lang111a99e2017-10-17 10:58:41 -04002589 ASSERT(mImplementation->getNativeExtensions().*(extension.ExtensionsMember));
Geoff Langc339c4e2016-11-29 10:37:36 -05002590
2591 if (mExtensions.*(extension.ExtensionsMember))
2592 {
2593 // Extension already enabled
2594 return;
2595 }
2596
2597 mExtensions.*(extension.ExtensionsMember) = true;
2598 updateCaps();
2599 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08002600
Jamie Madill2f348d22017-06-05 10:50:59 -04002601 // Release the shader compiler so it will be re-created with the requested extensions enabled.
2602 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04002603
Jamie Madill81c2e252017-09-09 23:32:46 -04002604 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
2605 // sampleable.
2606 mState.mTextures->signalAllTexturesDirty();
Geoff Lang9aded172017-04-05 11:07:56 -04002607 for (auto &zeroTexture : mZeroTextures)
2608 {
Jamie Madill05b35b22017-10-03 09:01:44 -04002609 zeroTexture.second->signalDirty(InitState::Initialized);
Geoff Lang9aded172017-04-05 11:07:56 -04002610 }
2611
2612 mState.mFramebuffers->invalidateFramebufferComplenessCache();
Geoff Langc339c4e2016-11-29 10:37:36 -05002613}
2614
2615size_t Context::getRequestableExtensionStringCount() const
2616{
2617 return mRequestableExtensionStrings.size();
2618}
2619
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002620void Context::beginTransformFeedback(GLenum primitiveMode)
2621{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002622 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002623 ASSERT(transformFeedback != nullptr);
2624 ASSERT(!transformFeedback->isPaused());
2625
Jamie Madill6c1f6712017-02-14 19:08:04 -05002626 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002627}
2628
2629bool Context::hasActiveTransformFeedback(GLuint program) const
2630{
2631 for (auto pair : mTransformFeedbackMap)
2632 {
2633 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
2634 {
2635 return true;
2636 }
2637 }
2638 return false;
2639}
2640
Geoff Langb433e872017-10-05 14:01:47 -04002641void Context::initCaps(const egl::DisplayExtensions &displayExtensions, bool robustResourceInit)
Geoff Lang493daf52014-07-03 13:38:44 -04002642{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002643 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04002644
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002645 mExtensions = mImplementation->getNativeExtensions();
Geoff Lang493daf52014-07-03 13:38:44 -04002646
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002647 mLimitations = mImplementation->getNativeLimitations();
Austin Kinross02df7962015-07-01 10:03:42 -07002648
Geoff Langeb66a6e2016-10-31 13:06:12 -04002649 if (getClientVersion() < Version(3, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002650 {
2651 // Disable ES3+ extensions
Jamie Madill231c7f52017-04-26 13:45:37 -04002652 mExtensions.colorBufferFloat = false;
Geoff Langb66a9092016-05-16 15:59:14 -04002653 mExtensions.eglImageExternalEssl3 = false;
Vincent Lang25ab4512016-05-13 18:13:59 +02002654 mExtensions.textureNorm16 = false;
Martin Radev137032d2017-07-13 10:11:12 +03002655 mExtensions.multiview = false;
2656 mExtensions.maxViews = 1u;
Geoff Lang493daf52014-07-03 13:38:44 -04002657 }
2658
Geoff Langeb66a6e2016-10-31 13:06:12 -04002659 if (getClientVersion() > Version(2, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002660 {
2661 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
Jamie Madill231c7f52017-04-26 13:45:37 -04002662 // mExtensions.sRGB = false;
Geoff Lang493daf52014-07-03 13:38:44 -04002663 }
2664
Jamie Madill00ed7a12016-05-19 13:13:38 -04002665 // Some extensions are always available because they are implemented in the GL layer.
Jamie Madill231c7f52017-04-26 13:45:37 -04002666 mExtensions.bindUniformLocation = true;
2667 mExtensions.vertexArrayObject = true;
Geoff Langf41a7152016-09-19 15:11:17 -04002668 mExtensions.bindGeneratesResource = true;
Geoff Langfeb8c682017-02-13 16:07:35 -05002669 mExtensions.clientArrays = true;
Geoff Langc339c4e2016-11-29 10:37:36 -05002670 mExtensions.requestExtension = true;
Jamie Madill00ed7a12016-05-19 13:13:38 -04002671
2672 // Enable the no error extension if the context was created with the flag.
2673 mExtensions.noError = mSkipValidation;
2674
Corentin Wallezccab69d2017-01-27 16:57:15 -05002675 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Corentin Wallezc295e512017-01-27 17:47:50 -05002676 mExtensions.surfacelessContext = displayExtensions.surfacelessContext;
Corentin Wallezccab69d2017-01-27 16:57:15 -05002677
Geoff Lang70d0f492015-12-10 17:45:46 -05002678 // Explicitly enable GL_KHR_debug
2679 mExtensions.debug = true;
2680 mExtensions.maxDebugMessageLength = 1024;
2681 mExtensions.maxDebugLoggedMessages = 1024;
2682 mExtensions.maxDebugGroupStackDepth = 1024;
2683 mExtensions.maxLabelLength = 1024;
2684
Geoff Langff5b2d52016-09-07 11:32:23 -04002685 // Explicitly enable GL_ANGLE_robust_client_memory
2686 mExtensions.robustClientMemory = true;
2687
Jamie Madille08a1d32017-03-07 17:24:06 -05002688 // Determine robust resource init availability from EGL.
Geoff Langb433e872017-10-05 14:01:47 -04002689 mExtensions.robustResourceInitialization = robustResourceInit;
Jamie Madille08a1d32017-03-07 17:24:06 -05002690
Jiajia Qin8a7b3a02017-08-25 16:05:48 +08002691 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
2692 // supports it.
2693 mExtensions.robustBufferAccessBehavior =
2694 mRobustAccess && mExtensions.robustBufferAccessBehavior;
2695
Jamie Madillc43be722017-07-13 16:22:14 -04002696 // Enable the cache control query unconditionally.
2697 mExtensions.programCacheControl = true;
2698
Geoff Lang301d1612014-07-09 10:34:37 -04002699 // Apply implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04002700 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002701
Jamie Madill0f80ed82017-09-19 00:24:56 -04002702 if (getClientVersion() < ES_3_1)
2703 {
2704 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
2705 }
2706 else
2707 {
2708 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
2709 }
Geoff Lang301d1612014-07-09 10:34:37 -04002710
Jamie Madill0f80ed82017-09-19 00:24:56 -04002711 LimitCap(&mCaps.maxVertexUniformBlocks, IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
2712 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
2713 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
2714
2715 // Limit textures as well, so we can use fast bitsets with texture bindings.
2716 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
2717 LimitCap(&mCaps.maxVertexTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
2718 LimitCap(&mCaps.maxTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04002719
Jiawei Shaodb342272017-09-27 10:21:45 +08002720 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
2721
Geoff Langc287ea62016-09-16 14:46:51 -04002722 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002723 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04002724 for (const auto &extensionInfo : GetExtensionInfoMap())
2725 {
2726 // If this context is for WebGL, disable all enableable extensions
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002727 if (mWebGLContext && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04002728 {
2729 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
2730 }
2731 }
2732
2733 // Generate texture caps
2734 updateCaps();
2735}
2736
2737void Context::updateCaps()
2738{
Geoff Lang900013c2014-07-07 11:32:19 -04002739 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002740 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04002741
Jamie Madill7b62cf92017-11-02 15:20:49 -04002742 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04002743 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04002744 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04002745 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04002746
Geoff Lang0d8b7242015-09-09 14:56:53 -04002747 // Update the format caps based on the client version and extensions.
2748 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
2749 // ES3.
2750 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002751 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002752 formatCaps.renderable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002753 formatCaps.renderable && formatInfo.renderSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002754 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002755 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04002756
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002757 // OpenGL ES does not support multisampling with non-rendererable formats
2758 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Olli Etuaho50c562d2017-06-06 14:43:30 +03002759 if (!formatCaps.renderable ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002760 (getClientVersion() < ES_3_1 &&
2761 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04002762 {
Geoff Langd87878e2014-09-19 15:42:59 -04002763 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04002764 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03002765 else
2766 {
2767 // We may have limited the max samples for some required renderbuffer formats due to
2768 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
2769 GLuint formatMaxSamples = formatCaps.getMaxSamples();
2770
2771 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
2772 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
2773 // exception of signed and unsigned integer formats."
2774 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
2775 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
2776 {
2777 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
2778 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
2779 }
2780
2781 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
2782 if (getClientVersion() >= ES_3_1)
2783 {
2784 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
2785 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
2786 // the exception that the signed and unsigned integer formats are required only to
2787 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
2788 // multisamples, which must be at least one."
2789 if (formatInfo.componentType == GL_INT ||
2790 formatInfo.componentType == GL_UNSIGNED_INT)
2791 {
2792 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
2793 }
2794
2795 // GLES 3.1 section 19.3.1.
2796 if (formatCaps.texturable)
2797 {
2798 if (formatInfo.depthBits > 0)
2799 {
2800 mCaps.maxDepthTextureSamples =
2801 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
2802 }
2803 else if (formatInfo.redBits > 0)
2804 {
2805 mCaps.maxColorTextureSamples =
2806 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
2807 }
2808 }
2809 }
2810 }
Geoff Langd87878e2014-09-19 15:42:59 -04002811
2812 if (formatCaps.texturable && formatInfo.compressed)
2813 {
Geoff Langca271392017-04-05 12:30:00 -04002814 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04002815 }
2816
Geoff Langca271392017-04-05 12:30:00 -04002817 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04002818 }
Jamie Madill32447362017-06-28 14:53:52 -04002819
2820 // If program binary is disabled, blank out the memory cache pointer.
2821 if (!mImplementation->getNativeExtensions().getProgramBinary)
2822 {
2823 mMemoryProgramCache = nullptr;
2824 }
Geoff Lang493daf52014-07-03 13:38:44 -04002825}
2826
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002827void Context::initWorkarounds()
2828{
Jamie Madill761b02c2017-06-23 16:27:06 -04002829 // Apply back-end workarounds.
2830 mImplementation->applyNativeWorkarounds(&mWorkarounds);
2831
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002832 // Lose the context upon out of memory error if the application is
2833 // expecting to watch for those events.
2834 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2835}
2836
Jamie Madill05b35b22017-10-03 09:01:44 -04002837Error Context::prepareForDraw()
2838{
2839 syncRendererState();
Jamie Madilla59fc192017-11-02 12:57:58 -04002840
2841 if (isRobustResourceInitEnabled())
2842 {
2843 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
2844 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
2845 }
2846
Jamie Madill05b35b22017-10-03 09:01:44 -04002847 return NoError();
2848}
2849
Jamie Madill1b94d432015-08-07 13:23:23 -04002850void Context::syncRendererState()
2851{
Jamie Madill7d1f5c62017-09-02 15:32:15 -04002852 mGLState.syncDirtyObjects(this);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002853 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
Jamie Madillfe548342017-06-19 11:13:24 -04002854 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002855 mGLState.clearDirtyBits();
Jamie Madill1b94d432015-08-07 13:23:23 -04002856}
2857
Jamie Madillad9f24e2016-02-12 09:27:24 -05002858void Context::syncRendererState(const State::DirtyBits &bitMask,
2859 const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04002860{
Jamie Madill7d1f5c62017-09-02 15:32:15 -04002861 mGLState.syncDirtyObjects(this, objectMask);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002862 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madillfe548342017-06-19 11:13:24 -04002863 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002864 mGLState.clearDirtyBits(dirtyBits);
Jamie Madill1b94d432015-08-07 13:23:23 -04002865}
Jamie Madillc29968b2016-01-20 11:17:23 -05002866
2867void Context::blitFramebuffer(GLint srcX0,
2868 GLint srcY0,
2869 GLint srcX1,
2870 GLint srcY1,
2871 GLint dstX0,
2872 GLint dstY0,
2873 GLint dstX1,
2874 GLint dstY1,
2875 GLbitfield mask,
2876 GLenum filter)
2877{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002878 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002879 ASSERT(drawFramebuffer);
2880
2881 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
2882 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
2883
Jamie Madillad9f24e2016-02-12 09:27:24 -05002884 syncStateForBlit();
Jamie Madillc29968b2016-01-20 11:17:23 -05002885
Jamie Madillc564c072017-06-01 12:45:42 -04002886 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002887}
Jamie Madillc29968b2016-01-20 11:17:23 -05002888
2889void Context::clear(GLbitfield mask)
2890{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002891 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002892 handleError(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05002893}
2894
2895void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
2896{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002897 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002898 handleError(mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002899}
2900
2901void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
2902{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002903 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002904 handleError(mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002905}
2906
2907void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
2908{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002909 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002910 handleError(mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002911}
2912
2913void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
2914{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002915 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002916 ASSERT(framebufferObject);
2917
2918 // If a buffer is not present, the clear has no effect
2919 if (framebufferObject->getDepthbuffer() == nullptr &&
2920 framebufferObject->getStencilbuffer() == nullptr)
2921 {
2922 return;
2923 }
2924
Jamie Madillad9f24e2016-02-12 09:27:24 -05002925 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002926 handleError(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05002927}
2928
2929void Context::readPixels(GLint x,
2930 GLint y,
2931 GLsizei width,
2932 GLsizei height,
2933 GLenum format,
2934 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002935 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05002936{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04002937 if (width == 0 || height == 0)
2938 {
2939 return;
2940 }
2941
Jamie Madillad9f24e2016-02-12 09:27:24 -05002942 syncStateForReadPixels();
Jamie Madillc29968b2016-01-20 11:17:23 -05002943
Jamie Madillb6664922017-07-25 12:55:04 -04002944 Framebuffer *readFBO = mGLState.getReadFramebuffer();
2945 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05002946
2947 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04002948 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05002949}
2950
2951void Context::copyTexImage2D(GLenum target,
2952 GLint level,
2953 GLenum internalformat,
2954 GLint x,
2955 GLint y,
2956 GLsizei width,
2957 GLsizei height,
2958 GLint border)
2959{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002960 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002961 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002962
Jamie Madillc29968b2016-01-20 11:17:23 -05002963 Rectangle sourceArea(x, y, width, height);
2964
Jamie Madill05b35b22017-10-03 09:01:44 -04002965 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002966 Texture *texture =
2967 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05002968 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05002969}
2970
2971void Context::copyTexSubImage2D(GLenum target,
2972 GLint level,
2973 GLint xoffset,
2974 GLint yoffset,
2975 GLint x,
2976 GLint y,
2977 GLsizei width,
2978 GLsizei height)
2979{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04002980 if (width == 0 || height == 0)
2981 {
2982 return;
2983 }
2984
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002985 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002986 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002987
Jamie Madillc29968b2016-01-20 11:17:23 -05002988 Offset destOffset(xoffset, yoffset, 0);
2989 Rectangle sourceArea(x, y, width, height);
2990
Jamie Madill05b35b22017-10-03 09:01:44 -04002991 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002992 Texture *texture =
2993 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05002994 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05002995}
2996
2997void Context::copyTexSubImage3D(GLenum target,
2998 GLint level,
2999 GLint xoffset,
3000 GLint yoffset,
3001 GLint zoffset,
3002 GLint x,
3003 GLint y,
3004 GLsizei width,
3005 GLsizei height)
3006{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003007 if (width == 0 || height == 0)
3008 {
3009 return;
3010 }
3011
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003012 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003013 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003014
Jamie Madillc29968b2016-01-20 11:17:23 -05003015 Offset destOffset(xoffset, yoffset, zoffset);
3016 Rectangle sourceArea(x, y, width, height);
3017
Jamie Madill05b35b22017-10-03 09:01:44 -04003018 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3019 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003020 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003021}
3022
3023void Context::framebufferTexture2D(GLenum target,
3024 GLenum attachment,
3025 GLenum textarget,
3026 GLuint texture,
3027 GLint level)
3028{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003029 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003030 ASSERT(framebuffer);
3031
3032 if (texture != 0)
3033 {
3034 Texture *textureObj = getTexture(texture);
3035
3036 ImageIndex index = ImageIndex::MakeInvalid();
3037
3038 if (textarget == GL_TEXTURE_2D)
3039 {
3040 index = ImageIndex::Make2D(level);
3041 }
Corentin Wallez13c0dd42017-07-04 18:27:01 -04003042 else if (textarget == GL_TEXTURE_RECTANGLE_ANGLE)
3043 {
3044 index = ImageIndex::MakeRectangle(level);
3045 }
JiangYizhoubddc46b2016-12-09 09:50:51 +08003046 else if (textarget == GL_TEXTURE_2D_MULTISAMPLE)
3047 {
3048 ASSERT(level == 0);
3049 index = ImageIndex::Make2DMultisample();
3050 }
Jamie Madillc29968b2016-01-20 11:17:23 -05003051 else
3052 {
3053 ASSERT(IsCubeMapTextureTarget(textarget));
3054 index = ImageIndex::MakeCube(textarget, level);
3055 }
3056
Jamie Madilla02315b2017-02-23 14:14:47 -05003057 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003058 }
3059 else
3060 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003061 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003062 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003063
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003064 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003065}
3066
3067void Context::framebufferRenderbuffer(GLenum target,
3068 GLenum attachment,
3069 GLenum renderbuffertarget,
3070 GLuint renderbuffer)
3071{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003072 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003073 ASSERT(framebuffer);
3074
3075 if (renderbuffer != 0)
3076 {
3077 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003078
3079 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex::MakeInvalid(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003080 renderbufferObject);
3081 }
3082 else
3083 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003084 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003085 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003086
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003087 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003088}
3089
3090void Context::framebufferTextureLayer(GLenum target,
3091 GLenum attachment,
3092 GLuint texture,
3093 GLint level,
3094 GLint layer)
3095{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003096 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003097 ASSERT(framebuffer);
3098
3099 if (texture != 0)
3100 {
3101 Texture *textureObject = getTexture(texture);
3102
3103 ImageIndex index = ImageIndex::MakeInvalid();
3104
3105 if (textureObject->getTarget() == GL_TEXTURE_3D)
3106 {
3107 index = ImageIndex::Make3D(level, layer);
3108 }
3109 else
3110 {
3111 ASSERT(textureObject->getTarget() == GL_TEXTURE_2D_ARRAY);
3112 index = ImageIndex::Make2DArray(level, layer);
3113 }
3114
Jamie Madilla02315b2017-02-23 14:14:47 -05003115 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003116 }
3117 else
3118 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003119 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003120 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003121
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003122 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003123}
3124
Martin Radev137032d2017-07-13 10:11:12 +03003125void Context::framebufferTextureMultiviewLayeredANGLE(GLenum target,
3126 GLenum attachment,
3127 GLuint texture,
3128 GLint level,
3129 GLint baseViewIndex,
3130 GLsizei numViews)
3131{
Martin Radev82ef7742017-08-08 17:44:58 +03003132 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3133 ASSERT(framebuffer);
3134
3135 if (texture != 0)
3136 {
3137 Texture *textureObj = getTexture(texture);
3138
Martin Radev18b75ba2017-08-15 15:50:40 +03003139 ImageIndex index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
Martin Radev82ef7742017-08-08 17:44:58 +03003140 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3141 numViews, baseViewIndex);
3142 }
3143 else
3144 {
3145 framebuffer->resetAttachment(this, attachment);
3146 }
3147
3148 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003149}
3150
3151void Context::framebufferTextureMultiviewSideBySideANGLE(GLenum target,
3152 GLenum attachment,
3153 GLuint texture,
3154 GLint level,
3155 GLsizei numViews,
3156 const GLint *viewportOffsets)
3157{
Martin Radev5dae57b2017-07-14 16:15:55 +03003158 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3159 ASSERT(framebuffer);
3160
3161 if (texture != 0)
3162 {
3163 Texture *textureObj = getTexture(texture);
3164
3165 ImageIndex index = ImageIndex::Make2D(level);
3166 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3167 textureObj, numViews, viewportOffsets);
3168 }
3169 else
3170 {
3171 framebuffer->resetAttachment(this, attachment);
3172 }
3173
3174 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003175}
3176
Jamie Madillc29968b2016-01-20 11:17:23 -05003177void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3178{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003179 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003180 ASSERT(framebuffer);
3181 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003182 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003183}
3184
3185void Context::readBuffer(GLenum mode)
3186{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003187 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003188 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003189 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003190}
3191
3192void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3193{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003194 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003195 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003196
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003197 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003198 ASSERT(framebuffer);
3199
3200 // The specification isn't clear what should be done when the framebuffer isn't complete.
3201 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003202 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003203}
3204
3205void Context::invalidateFramebuffer(GLenum target,
3206 GLsizei numAttachments,
3207 const GLenum *attachments)
3208{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003209 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003210 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003211
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003212 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003213 ASSERT(framebuffer);
3214
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003215 if (framebuffer->checkStatus(this) != GL_FRAMEBUFFER_COMPLETE)
Jamie Madillc29968b2016-01-20 11:17:23 -05003216 {
Jamie Madill437fa652016-05-03 15:13:24 -04003217 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003218 }
Jamie Madill437fa652016-05-03 15:13:24 -04003219
Jamie Madill4928b7c2017-06-20 12:57:39 -04003220 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003221}
3222
3223void Context::invalidateSubFramebuffer(GLenum target,
3224 GLsizei numAttachments,
3225 const GLenum *attachments,
3226 GLint x,
3227 GLint y,
3228 GLsizei width,
3229 GLsizei height)
3230{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003231 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003232 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003233
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003234 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003235 ASSERT(framebuffer);
3236
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003237 if (framebuffer->checkStatus(this) != GL_FRAMEBUFFER_COMPLETE)
Jamie Madillc29968b2016-01-20 11:17:23 -05003238 {
Jamie Madill437fa652016-05-03 15:13:24 -04003239 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003240 }
Jamie Madill437fa652016-05-03 15:13:24 -04003241
3242 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003243 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003244}
3245
Jamie Madill73a84962016-02-12 09:27:23 -05003246void Context::texImage2D(GLenum target,
3247 GLint level,
3248 GLint internalformat,
3249 GLsizei width,
3250 GLsizei height,
3251 GLint border,
3252 GLenum format,
3253 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003254 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003255{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003256 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003257
3258 Extents size(width, height, 1);
3259 Texture *texture =
3260 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003261 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3262 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003263}
3264
3265void Context::texImage3D(GLenum target,
3266 GLint level,
3267 GLint internalformat,
3268 GLsizei width,
3269 GLsizei height,
3270 GLsizei depth,
3271 GLint border,
3272 GLenum format,
3273 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003274 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003275{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003276 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003277
3278 Extents size(width, height, depth);
3279 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003280 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3281 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003282}
3283
3284void Context::texSubImage2D(GLenum target,
3285 GLint level,
3286 GLint xoffset,
3287 GLint yoffset,
3288 GLsizei width,
3289 GLsizei height,
3290 GLenum format,
3291 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003292 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003293{
3294 // Zero sized uploads are valid but no-ops
3295 if (width == 0 || height == 0)
3296 {
3297 return;
3298 }
3299
Jamie Madillad9f24e2016-02-12 09:27:24 -05003300 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003301
3302 Box area(xoffset, yoffset, 0, width, height, 1);
3303 Texture *texture =
3304 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003305 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3306 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003307}
3308
3309void Context::texSubImage3D(GLenum target,
3310 GLint level,
3311 GLint xoffset,
3312 GLint yoffset,
3313 GLint zoffset,
3314 GLsizei width,
3315 GLsizei height,
3316 GLsizei depth,
3317 GLenum format,
3318 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003319 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003320{
3321 // Zero sized uploads are valid but no-ops
3322 if (width == 0 || height == 0 || depth == 0)
3323 {
3324 return;
3325 }
3326
Jamie Madillad9f24e2016-02-12 09:27:24 -05003327 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003328
3329 Box area(xoffset, yoffset, zoffset, width, height, depth);
3330 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003331 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3332 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003333}
3334
3335void Context::compressedTexImage2D(GLenum target,
3336 GLint level,
3337 GLenum internalformat,
3338 GLsizei width,
3339 GLsizei height,
3340 GLint border,
3341 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003342 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003343{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003344 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003345
3346 Extents size(width, height, 1);
3347 Texture *texture =
3348 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003349 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003350 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003351 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003352}
3353
3354void Context::compressedTexImage3D(GLenum target,
3355 GLint level,
3356 GLenum internalformat,
3357 GLsizei width,
3358 GLsizei height,
3359 GLsizei depth,
3360 GLint border,
3361 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003362 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003363{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003364 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003365
3366 Extents size(width, height, depth);
3367 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003368 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003369 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003370 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003371}
3372
3373void Context::compressedTexSubImage2D(GLenum target,
3374 GLint level,
3375 GLint xoffset,
3376 GLint yoffset,
3377 GLsizei width,
3378 GLsizei height,
3379 GLenum format,
3380 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003381 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003382{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003383 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003384
3385 Box area(xoffset, yoffset, 0, width, height, 1);
3386 Texture *texture =
3387 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003388 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003389 format, imageSize,
3390 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003391}
3392
3393void Context::compressedTexSubImage3D(GLenum target,
3394 GLint level,
3395 GLint xoffset,
3396 GLint yoffset,
3397 GLint zoffset,
3398 GLsizei width,
3399 GLsizei height,
3400 GLsizei depth,
3401 GLenum format,
3402 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003403 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003404{
3405 // Zero sized uploads are valid but no-ops
3406 if (width == 0 || height == 0)
3407 {
3408 return;
3409 }
3410
Jamie Madillad9f24e2016-02-12 09:27:24 -05003411 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003412
3413 Box area(xoffset, yoffset, zoffset, width, height, depth);
3414 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003415 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003416 format, imageSize,
3417 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003418}
3419
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003420void Context::generateMipmap(GLenum target)
3421{
3422 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003423 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003424}
3425
Geoff Lang97073d12016-04-20 10:42:34 -07003426void Context::copyTextureCHROMIUM(GLuint sourceId,
Geoff Langfc72a072017-03-24 14:52:39 -04003427 GLint sourceLevel,
3428 GLenum destTarget,
Geoff Lang97073d12016-04-20 10:42:34 -07003429 GLuint destId,
Geoff Langfc72a072017-03-24 14:52:39 -04003430 GLint destLevel,
Geoff Lang97073d12016-04-20 10:42:34 -07003431 GLint internalFormat,
3432 GLenum destType,
3433 GLboolean unpackFlipY,
3434 GLboolean unpackPremultiplyAlpha,
3435 GLboolean unpackUnmultiplyAlpha)
3436{
3437 syncStateForTexImage();
3438
3439 gl::Texture *sourceTexture = getTexture(sourceId);
3440 gl::Texture *destTexture = getTexture(destId);
Geoff Langfc72a072017-03-24 14:52:39 -04003441 handleError(destTexture->copyTexture(
3442 this, destTarget, destLevel, internalFormat, destType, sourceLevel, unpackFlipY == GL_TRUE,
3443 unpackPremultiplyAlpha == GL_TRUE, unpackUnmultiplyAlpha == GL_TRUE, sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003444}
3445
3446void Context::copySubTextureCHROMIUM(GLuint sourceId,
Geoff Langfc72a072017-03-24 14:52:39 -04003447 GLint sourceLevel,
3448 GLenum destTarget,
Geoff Lang97073d12016-04-20 10:42:34 -07003449 GLuint destId,
Geoff Langfc72a072017-03-24 14:52:39 -04003450 GLint destLevel,
Geoff Lang97073d12016-04-20 10:42:34 -07003451 GLint xoffset,
3452 GLint yoffset,
3453 GLint x,
3454 GLint y,
3455 GLsizei width,
3456 GLsizei height,
3457 GLboolean unpackFlipY,
3458 GLboolean unpackPremultiplyAlpha,
3459 GLboolean unpackUnmultiplyAlpha)
3460{
3461 // Zero sized copies are valid but no-ops
3462 if (width == 0 || height == 0)
3463 {
3464 return;
3465 }
3466
3467 syncStateForTexImage();
3468
3469 gl::Texture *sourceTexture = getTexture(sourceId);
3470 gl::Texture *destTexture = getTexture(destId);
3471 Offset offset(xoffset, yoffset, 0);
3472 Rectangle area(x, y, width, height);
Geoff Langfc72a072017-03-24 14:52:39 -04003473 handleError(destTexture->copySubTexture(
3474 this, destTarget, destLevel, offset, sourceLevel, area, unpackFlipY == GL_TRUE,
3475 unpackPremultiplyAlpha == GL_TRUE, unpackUnmultiplyAlpha == GL_TRUE, sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003476}
3477
Geoff Lang47110bf2016-04-20 11:13:22 -07003478void Context::compressedCopyTextureCHROMIUM(GLuint sourceId, GLuint destId)
3479{
3480 syncStateForTexImage();
3481
3482 gl::Texture *sourceTexture = getTexture(sourceId);
3483 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05003484 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07003485}
3486
Geoff Lang496c02d2016-10-20 11:38:11 -07003487void Context::getBufferPointerv(GLenum target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03003488{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003489 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003490 ASSERT(buffer);
3491
Geoff Lang496c02d2016-10-20 11:38:11 -07003492 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03003493}
3494
Jamie Madill876429b2017-04-20 15:46:24 -04003495void *Context::mapBuffer(GLenum target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003496{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003497 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003498 ASSERT(buffer);
3499
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003500 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003501 if (error.isError())
3502 {
Jamie Madill437fa652016-05-03 15:13:24 -04003503 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003504 return nullptr;
3505 }
3506
3507 return buffer->getMapPointer();
3508}
3509
3510GLboolean Context::unmapBuffer(GLenum target)
3511{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003512 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003513 ASSERT(buffer);
3514
3515 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003516 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03003517 if (error.isError())
3518 {
Jamie Madill437fa652016-05-03 15:13:24 -04003519 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003520 return GL_FALSE;
3521 }
3522
3523 return result;
3524}
3525
Jamie Madill876429b2017-04-20 15:46:24 -04003526void *Context::mapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003527{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003528 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003529 ASSERT(buffer);
3530
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003531 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003532 if (error.isError())
3533 {
Jamie Madill437fa652016-05-03 15:13:24 -04003534 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003535 return nullptr;
3536 }
3537
3538 return buffer->getMapPointer();
3539}
3540
3541void Context::flushMappedBufferRange(GLenum /*target*/, GLintptr /*offset*/, GLsizeiptr /*length*/)
3542{
3543 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
3544}
3545
Jamie Madillad9f24e2016-02-12 09:27:24 -05003546void Context::syncStateForReadPixels()
3547{
3548 syncRendererState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
3549}
3550
3551void Context::syncStateForTexImage()
3552{
3553 syncRendererState(mTexImageDirtyBits, mTexImageDirtyObjects);
3554}
3555
3556void Context::syncStateForClear()
3557{
3558 syncRendererState(mClearDirtyBits, mClearDirtyObjects);
3559}
3560
3561void Context::syncStateForBlit()
3562{
3563 syncRendererState(mBlitDirtyBits, mBlitDirtyObjects);
3564}
3565
Jamie Madillc20ab272016-06-09 07:20:46 -07003566void Context::activeTexture(GLenum texture)
3567{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003568 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003569}
3570
Jamie Madill876429b2017-04-20 15:46:24 -04003571void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003572{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003573 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07003574}
3575
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003576void Context::blendEquation(GLenum mode)
3577{
3578 mGLState.setBlendEquation(mode, mode);
3579}
3580
Jamie Madillc20ab272016-06-09 07:20:46 -07003581void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
3582{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003583 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003584}
3585
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003586void Context::blendFunc(GLenum sfactor, GLenum dfactor)
3587{
3588 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
3589}
3590
Jamie Madillc20ab272016-06-09 07:20:46 -07003591void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
3592{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003593 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003594}
3595
Jamie Madill876429b2017-04-20 15:46:24 -04003596void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003597{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003598 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003599}
3600
Jamie Madill876429b2017-04-20 15:46:24 -04003601void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07003602{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003603 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07003604}
3605
3606void Context::clearStencil(GLint s)
3607{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003608 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07003609}
3610
3611void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
3612{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003613 mGLState.setColorMask(red == GL_TRUE, green == GL_TRUE, blue == GL_TRUE, alpha == GL_TRUE);
Jamie Madillc20ab272016-06-09 07:20:46 -07003614}
3615
Corentin Wallez2e568cf2017-09-18 17:05:22 -04003616void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07003617{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003618 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003619}
3620
3621void Context::depthFunc(GLenum func)
3622{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003623 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07003624}
3625
3626void Context::depthMask(GLboolean flag)
3627{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003628 mGLState.setDepthMask(flag != GL_FALSE);
Jamie Madillc20ab272016-06-09 07:20:46 -07003629}
3630
Jamie Madill876429b2017-04-20 15:46:24 -04003631void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07003632{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003633 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07003634}
3635
3636void Context::disable(GLenum cap)
3637{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003638 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003639}
3640
3641void Context::disableVertexAttribArray(GLuint index)
3642{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003643 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003644}
3645
3646void Context::enable(GLenum cap)
3647{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003648 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003649}
3650
3651void Context::enableVertexAttribArray(GLuint index)
3652{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003653 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003654}
3655
3656void Context::frontFace(GLenum mode)
3657{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003658 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003659}
3660
3661void Context::hint(GLenum target, GLenum mode)
3662{
3663 switch (target)
3664 {
3665 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003666 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003667 break;
3668
3669 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003670 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003671 break;
3672
3673 default:
3674 UNREACHABLE();
3675 return;
3676 }
3677}
3678
3679void Context::lineWidth(GLfloat width)
3680{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003681 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07003682}
3683
3684void Context::pixelStorei(GLenum pname, GLint param)
3685{
3686 switch (pname)
3687 {
3688 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003689 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003690 break;
3691
3692 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003693 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003694 break;
3695
3696 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003697 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003698 break;
3699
3700 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003701 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003702 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003703 break;
3704
3705 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03003706 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003707 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003708 break;
3709
3710 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03003711 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003712 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003713 break;
3714
3715 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003716 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003717 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003718 break;
3719
3720 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003721 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003722 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003723 break;
3724
3725 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003726 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003727 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003728 break;
3729
3730 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003731 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003732 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003733 break;
3734
3735 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003736 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003737 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003738 break;
3739
3740 default:
3741 UNREACHABLE();
3742 return;
3743 }
3744}
3745
3746void Context::polygonOffset(GLfloat factor, GLfloat units)
3747{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003748 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07003749}
3750
Jamie Madill876429b2017-04-20 15:46:24 -04003751void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07003752{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003753 mGLState.setSampleCoverageParams(clamp01(value), invert == GL_TRUE);
Jamie Madillc20ab272016-06-09 07:20:46 -07003754}
3755
Jiawei Shaodb342272017-09-27 10:21:45 +08003756void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
3757{
3758 mGLState.setSampleMaskParams(maskNumber, mask);
3759}
3760
Jamie Madillc20ab272016-06-09 07:20:46 -07003761void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
3762{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003763 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07003764}
3765
3766void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
3767{
3768 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3769 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003770 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003771 }
3772
3773 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3774 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003775 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003776 }
3777}
3778
3779void Context::stencilMaskSeparate(GLenum face, GLuint mask)
3780{
3781 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3782 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003783 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003784 }
3785
3786 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3787 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003788 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003789 }
3790}
3791
3792void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
3793{
3794 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3795 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003796 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003797 }
3798
3799 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3800 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003801 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003802 }
3803}
3804
3805void Context::vertexAttrib1f(GLuint index, GLfloat x)
3806{
3807 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003808 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003809}
3810
3811void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
3812{
3813 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003814 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003815}
3816
3817void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
3818{
3819 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003820 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003821}
3822
3823void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
3824{
3825 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003826 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003827}
3828
3829void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
3830{
3831 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003832 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003833}
3834
3835void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
3836{
3837 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003838 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003839}
3840
3841void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
3842{
3843 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003844 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003845}
3846
3847void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
3848{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003849 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07003850}
3851
3852void Context::vertexAttribPointer(GLuint index,
3853 GLint size,
3854 GLenum type,
3855 GLboolean normalized,
3856 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04003857 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07003858{
Shaodde78e82017-05-22 14:13:27 +08003859 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(GL_ARRAY_BUFFER), size,
3860 type, normalized == GL_TRUE, false, stride, ptr);
Jamie Madillc20ab272016-06-09 07:20:46 -07003861}
3862
Shao80957d92017-02-20 21:25:59 +08003863void Context::vertexAttribFormat(GLuint attribIndex,
3864 GLint size,
3865 GLenum type,
3866 GLboolean normalized,
3867 GLuint relativeOffset)
3868{
3869 mGLState.setVertexAttribFormat(attribIndex, size, type, normalized == GL_TRUE, false,
3870 relativeOffset);
3871}
3872
3873void Context::vertexAttribIFormat(GLuint attribIndex,
3874 GLint size,
3875 GLenum type,
3876 GLuint relativeOffset)
3877{
3878 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
3879}
3880
3881void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
3882{
Shaodde78e82017-05-22 14:13:27 +08003883 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Shao80957d92017-02-20 21:25:59 +08003884}
3885
3886void Context::setVertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
3887{
3888 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
3889}
3890
Jamie Madillc20ab272016-06-09 07:20:46 -07003891void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
3892{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003893 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07003894}
3895
3896void Context::vertexAttribIPointer(GLuint index,
3897 GLint size,
3898 GLenum type,
3899 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04003900 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07003901{
Shaodde78e82017-05-22 14:13:27 +08003902 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(GL_ARRAY_BUFFER), size,
3903 type, false, true, stride, pointer);
Jamie Madillc20ab272016-06-09 07:20:46 -07003904}
3905
3906void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
3907{
3908 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003909 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003910}
3911
3912void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
3913{
3914 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003915 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003916}
3917
3918void Context::vertexAttribI4iv(GLuint index, const GLint *v)
3919{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003920 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07003921}
3922
3923void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
3924{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003925 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07003926}
3927
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003928void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
3929{
3930 const VertexAttribCurrentValueData &currentValues =
3931 getGLState().getVertexAttribCurrentValue(index);
3932 const VertexArray *vao = getGLState().getVertexArray();
3933 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3934 currentValues, pname, params);
3935}
3936
3937void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
3938{
3939 const VertexAttribCurrentValueData &currentValues =
3940 getGLState().getVertexAttribCurrentValue(index);
3941 const VertexArray *vao = getGLState().getVertexArray();
3942 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3943 currentValues, pname, params);
3944}
3945
3946void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
3947{
3948 const VertexAttribCurrentValueData &currentValues =
3949 getGLState().getVertexAttribCurrentValue(index);
3950 const VertexArray *vao = getGLState().getVertexArray();
3951 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3952 currentValues, pname, params);
3953}
3954
3955void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
3956{
3957 const VertexAttribCurrentValueData &currentValues =
3958 getGLState().getVertexAttribCurrentValue(index);
3959 const VertexArray *vao = getGLState().getVertexArray();
3960 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3961 currentValues, pname, params);
3962}
3963
Jamie Madill876429b2017-04-20 15:46:24 -04003964void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003965{
3966 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
3967 QueryVertexAttribPointerv(attrib, pname, pointer);
3968}
3969
Jamie Madillc20ab272016-06-09 07:20:46 -07003970void Context::debugMessageControl(GLenum source,
3971 GLenum type,
3972 GLenum severity,
3973 GLsizei count,
3974 const GLuint *ids,
3975 GLboolean enabled)
3976{
3977 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003978 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
3979 (enabled != GL_FALSE));
Jamie Madillc20ab272016-06-09 07:20:46 -07003980}
3981
3982void Context::debugMessageInsert(GLenum source,
3983 GLenum type,
3984 GLuint id,
3985 GLenum severity,
3986 GLsizei length,
3987 const GLchar *buf)
3988{
3989 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003990 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07003991}
3992
3993void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
3994{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003995 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07003996}
3997
3998GLuint Context::getDebugMessageLog(GLuint count,
3999 GLsizei bufSize,
4000 GLenum *sources,
4001 GLenum *types,
4002 GLuint *ids,
4003 GLenum *severities,
4004 GLsizei *lengths,
4005 GLchar *messageLog)
4006{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004007 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4008 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004009}
4010
4011void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4012{
4013 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004014 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004015}
4016
4017void Context::popDebugGroup()
4018{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004019 mGLState.getDebug().popGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004020}
4021
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004022void Context::bufferData(GLenum target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004023{
4024 Buffer *buffer = mGLState.getTargetBuffer(target);
4025 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004026 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004027}
4028
Jamie Madill876429b2017-04-20 15:46:24 -04004029void Context::bufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004030{
4031 if (data == nullptr)
4032 {
4033 return;
4034 }
4035
4036 Buffer *buffer = mGLState.getTargetBuffer(target);
4037 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004038 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004039}
4040
Jamie Madillef300b12016-10-07 15:12:09 -04004041void Context::attachShader(GLuint program, GLuint shader)
4042{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004043 auto programObject = mState.mShaderPrograms->getProgram(program);
4044 auto shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004045 ASSERT(programObject && shaderObject);
4046 programObject->attachShader(shaderObject);
4047}
4048
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004049const Workarounds &Context::getWorkarounds() const
4050{
4051 return mWorkarounds;
4052}
4053
Jamie Madillb0817d12016-11-01 15:48:31 -04004054void Context::copyBufferSubData(GLenum readTarget,
4055 GLenum writeTarget,
4056 GLintptr readOffset,
4057 GLintptr writeOffset,
4058 GLsizeiptr size)
4059{
4060 // if size is zero, the copy is a successful no-op
4061 if (size == 0)
4062 {
4063 return;
4064 }
4065
4066 // TODO(jmadill): cache these.
4067 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4068 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4069
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004070 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004071}
4072
Jamie Madill01a80ee2016-11-07 12:06:18 -05004073void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4074{
4075 Program *programObject = getProgram(program);
4076 // TODO(jmadill): Re-use this from the validation if possible.
4077 ASSERT(programObject);
4078 programObject->bindAttributeLocation(index, name);
4079}
4080
4081void Context::bindBuffer(GLenum target, GLuint buffer)
4082{
4083 switch (target)
4084 {
4085 case GL_ARRAY_BUFFER:
4086 bindArrayBuffer(buffer);
4087 break;
4088 case GL_ELEMENT_ARRAY_BUFFER:
4089 bindElementArrayBuffer(buffer);
4090 break;
4091 case GL_COPY_READ_BUFFER:
4092 bindCopyReadBuffer(buffer);
4093 break;
4094 case GL_COPY_WRITE_BUFFER:
4095 bindCopyWriteBuffer(buffer);
4096 break;
4097 case GL_PIXEL_PACK_BUFFER:
4098 bindPixelPackBuffer(buffer);
4099 break;
4100 case GL_PIXEL_UNPACK_BUFFER:
4101 bindPixelUnpackBuffer(buffer);
4102 break;
4103 case GL_UNIFORM_BUFFER:
4104 bindGenericUniformBuffer(buffer);
4105 break;
4106 case GL_TRANSFORM_FEEDBACK_BUFFER:
4107 bindGenericTransformFeedbackBuffer(buffer);
4108 break;
Geoff Lang3b573612016-10-31 14:08:10 -04004109 case GL_ATOMIC_COUNTER_BUFFER:
Jiajia Qin6eafb042016-12-27 17:04:07 +08004110 bindGenericAtomicCounterBuffer(buffer);
Geoff Lang3b573612016-10-31 14:08:10 -04004111 break;
4112 case GL_SHADER_STORAGE_BUFFER:
Jiajia Qinf546e7d2017-03-27 14:12:59 +08004113 bindGenericShaderStorageBuffer(buffer);
Geoff Lang3b573612016-10-31 14:08:10 -04004114 break;
4115 case GL_DRAW_INDIRECT_BUFFER:
Jiajia Qin9d7d0b12016-11-29 16:30:31 +08004116 bindDrawIndirectBuffer(buffer);
Geoff Lang3b573612016-10-31 14:08:10 -04004117 break;
4118 case GL_DISPATCH_INDIRECT_BUFFER:
Geoff Lang9f090372016-12-02 10:20:43 -05004119 if (buffer != 0)
4120 {
4121 // Binding buffers to this binding point is not implemented yet.
4122 UNIMPLEMENTED();
4123 }
Geoff Lang3b573612016-10-31 14:08:10 -04004124 break;
Jamie Madill01a80ee2016-11-07 12:06:18 -05004125
4126 default:
4127 UNREACHABLE();
4128 break;
4129 }
4130}
4131
Jiajia Qin6eafb042016-12-27 17:04:07 +08004132void Context::bindBufferBase(GLenum target, GLuint index, GLuint buffer)
4133{
4134 bindBufferRange(target, index, buffer, 0, 0);
4135}
4136
4137void Context::bindBufferRange(GLenum target,
4138 GLuint index,
4139 GLuint buffer,
4140 GLintptr offset,
4141 GLsizeiptr size)
4142{
4143 switch (target)
4144 {
4145 case GL_TRANSFORM_FEEDBACK_BUFFER:
4146 bindIndexedTransformFeedbackBuffer(buffer, index, offset, size);
4147 bindGenericTransformFeedbackBuffer(buffer);
4148 break;
4149 case GL_UNIFORM_BUFFER:
4150 bindIndexedUniformBuffer(buffer, index, offset, size);
4151 bindGenericUniformBuffer(buffer);
4152 break;
4153 case GL_ATOMIC_COUNTER_BUFFER:
4154 bindIndexedAtomicCounterBuffer(buffer, index, offset, size);
4155 bindGenericAtomicCounterBuffer(buffer);
4156 break;
4157 case GL_SHADER_STORAGE_BUFFER:
Jiajia Qinf546e7d2017-03-27 14:12:59 +08004158 bindIndexedShaderStorageBuffer(buffer, index, offset, size);
4159 bindGenericShaderStorageBuffer(buffer);
Jiajia Qin6eafb042016-12-27 17:04:07 +08004160 break;
4161 default:
4162 UNREACHABLE();
4163 break;
4164 }
4165}
4166
Jamie Madill01a80ee2016-11-07 12:06:18 -05004167void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
4168{
4169 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4170 {
4171 bindReadFramebuffer(framebuffer);
4172 }
4173
4174 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4175 {
4176 bindDrawFramebuffer(framebuffer);
4177 }
4178}
4179
4180void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4181{
4182 ASSERT(target == GL_RENDERBUFFER);
4183 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004184 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04004185 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004186}
4187
JiangYizhoubddc46b2016-12-09 09:50:51 +08004188void Context::texStorage2DMultisample(GLenum target,
4189 GLsizei samples,
4190 GLenum internalformat,
4191 GLsizei width,
4192 GLsizei height,
4193 GLboolean fixedsamplelocations)
4194{
4195 Extents size(width, height, 1);
4196 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05004197 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
JiangYizhoubddc46b2016-12-09 09:50:51 +08004198 fixedsamplelocations));
4199}
4200
4201void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4202{
JiangYizhou5b03f472017-01-09 10:22:53 +08004203 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
4204 // the sample position should be queried by DRAW_FRAMEBUFFER.
4205 mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER);
4206 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08004207
4208 switch (pname)
4209 {
4210 case GL_SAMPLE_POSITION:
4211 handleError(framebuffer->getSamplePosition(index, val));
4212 break;
4213 default:
4214 UNREACHABLE();
4215 }
4216}
4217
Jamie Madille8fb6402017-02-14 17:56:40 -05004218void Context::renderbufferStorage(GLenum target,
4219 GLenum internalformat,
4220 GLsizei width,
4221 GLsizei height)
4222{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004223 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4224 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
4225
Jamie Madille8fb6402017-02-14 17:56:40 -05004226 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04004227 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004228}
4229
4230void Context::renderbufferStorageMultisample(GLenum target,
4231 GLsizei samples,
4232 GLenum internalformat,
4233 GLsizei width,
4234 GLsizei height)
4235{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004236 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4237 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05004238
4239 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004240 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04004241 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004242}
4243
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004244void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
4245{
Jamie Madill70b5bb02017-08-28 13:32:37 -04004246 const Sync *syncObject = getSync(sync);
Geoff Lang82483b92017-04-11 15:33:00 -04004247 handleError(QuerySynciv(syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004248}
4249
JiangYizhoue18e6392017-02-20 10:32:23 +08004250void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
4251{
4252 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4253 QueryFramebufferParameteriv(framebuffer, pname, params);
4254}
4255
4256void Context::setFramebufferParameteri(GLenum target, GLenum pname, GLint param)
4257{
4258 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4259 SetFramebufferParameteri(framebuffer, pname, param);
4260}
4261
Jamie Madillb3f26b92017-07-19 15:07:41 -04004262Error Context::getScratchBuffer(size_t requstedSizeBytes,
4263 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05004264{
Jamie Madillb3f26b92017-07-19 15:07:41 -04004265 if (!mScratchBuffer.get(requstedSizeBytes, scratchBufferOut))
4266 {
4267 return OutOfMemory() << "Failed to allocate internal buffer.";
4268 }
4269 return NoError();
4270}
4271
4272Error Context::getZeroFilledBuffer(size_t requstedSizeBytes,
4273 angle::MemoryBuffer **zeroBufferOut) const
4274{
4275 if (!mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0))
Jamie Madille14951e2017-03-09 18:55:16 -05004276 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004277 return OutOfMemory() << "Failed to allocate internal buffer.";
Jamie Madille14951e2017-03-09 18:55:16 -05004278 }
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004279 return NoError();
Jamie Madille14951e2017-03-09 18:55:16 -05004280}
4281
Xinghua Cao2b396592017-03-29 15:36:04 +08004282void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
4283{
4284 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
4285 {
4286 return;
4287 }
4288
Jamie Madill05b35b22017-10-03 09:01:44 -04004289 // TODO(jmadill): Dirty bits for compute.
Jamie Madilla59fc192017-11-02 12:57:58 -04004290 if (isRobustResourceInitEnabled())
4291 {
4292 ANGLE_CONTEXT_TRY(mGLState.clearUnclearedActiveTextures(this));
4293 }
Jamie Madill05b35b22017-10-03 09:01:44 -04004294
Jamie Madill71c88b32017-09-14 22:20:29 -04004295 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08004296}
4297
JiangYizhou165361c2017-06-07 14:56:57 +08004298void Context::texStorage2D(GLenum target,
4299 GLsizei levels,
4300 GLenum internalFormat,
4301 GLsizei width,
4302 GLsizei height)
4303{
4304 Extents size(width, height, 1);
4305 Texture *texture = getTargetTexture(target);
4306 handleError(texture->setStorage(this, target, levels, internalFormat, size));
4307}
4308
4309void Context::texStorage3D(GLenum target,
4310 GLsizei levels,
4311 GLenum internalFormat,
4312 GLsizei width,
4313 GLsizei height,
4314 GLsizei depth)
4315{
4316 Extents size(width, height, depth);
4317 Texture *texture = getTargetTexture(target);
4318 handleError(texture->setStorage(this, target, levels, internalFormat, size));
4319}
4320
Jamie Madillc1d770e2017-04-13 17:31:24 -04004321GLenum Context::checkFramebufferStatus(GLenum target)
4322{
4323 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4324 ASSERT(framebuffer);
4325
4326 return framebuffer->checkStatus(this);
4327}
4328
4329void Context::compileShader(GLuint shader)
4330{
4331 Shader *shaderObject = GetValidShader(this, shader);
4332 if (!shaderObject)
4333 {
4334 return;
4335 }
4336 shaderObject->compile(this);
4337}
4338
4339void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
4340{
4341 for (int i = 0; i < n; i++)
4342 {
4343 deleteBuffer(buffers[i]);
4344 }
4345}
4346
4347void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
4348{
4349 for (int i = 0; i < n; i++)
4350 {
4351 if (framebuffers[i] != 0)
4352 {
4353 deleteFramebuffer(framebuffers[i]);
4354 }
4355 }
4356}
4357
4358void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
4359{
4360 for (int i = 0; i < n; i++)
4361 {
4362 deleteRenderbuffer(renderbuffers[i]);
4363 }
4364}
4365
4366void Context::deleteTextures(GLsizei n, const GLuint *textures)
4367{
4368 for (int i = 0; i < n; i++)
4369 {
4370 if (textures[i] != 0)
4371 {
4372 deleteTexture(textures[i]);
4373 }
4374 }
4375}
4376
4377void Context::detachShader(GLuint program, GLuint shader)
4378{
4379 Program *programObject = getProgram(program);
4380 ASSERT(programObject);
4381
4382 Shader *shaderObject = getShader(shader);
4383 ASSERT(shaderObject);
4384
4385 programObject->detachShader(this, shaderObject);
4386}
4387
4388void Context::genBuffers(GLsizei n, GLuint *buffers)
4389{
4390 for (int i = 0; i < n; i++)
4391 {
4392 buffers[i] = createBuffer();
4393 }
4394}
4395
4396void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
4397{
4398 for (int i = 0; i < n; i++)
4399 {
4400 framebuffers[i] = createFramebuffer();
4401 }
4402}
4403
4404void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
4405{
4406 for (int i = 0; i < n; i++)
4407 {
4408 renderbuffers[i] = createRenderbuffer();
4409 }
4410}
4411
4412void Context::genTextures(GLsizei n, GLuint *textures)
4413{
4414 for (int i = 0; i < n; i++)
4415 {
4416 textures[i] = createTexture();
4417 }
4418}
4419
4420void Context::getActiveAttrib(GLuint program,
4421 GLuint index,
4422 GLsizei bufsize,
4423 GLsizei *length,
4424 GLint *size,
4425 GLenum *type,
4426 GLchar *name)
4427{
4428 Program *programObject = getProgram(program);
4429 ASSERT(programObject);
4430 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
4431}
4432
4433void Context::getActiveUniform(GLuint program,
4434 GLuint index,
4435 GLsizei bufsize,
4436 GLsizei *length,
4437 GLint *size,
4438 GLenum *type,
4439 GLchar *name)
4440{
4441 Program *programObject = getProgram(program);
4442 ASSERT(programObject);
4443 programObject->getActiveUniform(index, bufsize, length, size, type, name);
4444}
4445
4446void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
4447{
4448 Program *programObject = getProgram(program);
4449 ASSERT(programObject);
4450 programObject->getAttachedShaders(maxcount, count, shaders);
4451}
4452
4453GLint Context::getAttribLocation(GLuint program, const GLchar *name)
4454{
4455 Program *programObject = getProgram(program);
4456 ASSERT(programObject);
4457 return programObject->getAttributeLocation(name);
4458}
4459
4460void Context::getBooleanv(GLenum pname, GLboolean *params)
4461{
4462 GLenum nativeType;
4463 unsigned int numParams = 0;
4464 getQueryParameterInfo(pname, &nativeType, &numParams);
4465
4466 if (nativeType == GL_BOOL)
4467 {
4468 getBooleanvImpl(pname, params);
4469 }
4470 else
4471 {
4472 CastStateValues(this, nativeType, pname, numParams, params);
4473 }
4474}
4475
4476void Context::getFloatv(GLenum pname, GLfloat *params)
4477{
4478 GLenum nativeType;
4479 unsigned int numParams = 0;
4480 getQueryParameterInfo(pname, &nativeType, &numParams);
4481
4482 if (nativeType == GL_FLOAT)
4483 {
4484 getFloatvImpl(pname, params);
4485 }
4486 else
4487 {
4488 CastStateValues(this, nativeType, pname, numParams, params);
4489 }
4490}
4491
4492void Context::getIntegerv(GLenum pname, GLint *params)
4493{
4494 GLenum nativeType;
4495 unsigned int numParams = 0;
4496 getQueryParameterInfo(pname, &nativeType, &numParams);
4497
4498 if (nativeType == GL_INT)
4499 {
4500 getIntegervImpl(pname, params);
4501 }
4502 else
4503 {
4504 CastStateValues(this, nativeType, pname, numParams, params);
4505 }
4506}
4507
4508void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
4509{
4510 Program *programObject = getProgram(program);
4511 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04004512 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004513}
4514
Jamie Madillbe849e42017-05-02 15:49:00 -04004515void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04004516{
4517 Program *programObject = getProgram(program);
4518 ASSERT(programObject);
4519 programObject->getInfoLog(bufsize, length, infolog);
4520}
4521
4522void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
4523{
4524 Shader *shaderObject = getShader(shader);
4525 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004526 QueryShaderiv(this, shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004527}
4528
4529void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
4530{
4531 Shader *shaderObject = getShader(shader);
4532 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004533 shaderObject->getInfoLog(this, bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004534}
4535
4536void Context::getShaderPrecisionFormat(GLenum shadertype,
4537 GLenum precisiontype,
4538 GLint *range,
4539 GLint *precision)
4540{
4541 // TODO(jmadill): Compute shaders.
4542
4543 switch (shadertype)
4544 {
4545 case GL_VERTEX_SHADER:
4546 switch (precisiontype)
4547 {
4548 case GL_LOW_FLOAT:
4549 mCaps.vertexLowpFloat.get(range, precision);
4550 break;
4551 case GL_MEDIUM_FLOAT:
4552 mCaps.vertexMediumpFloat.get(range, precision);
4553 break;
4554 case GL_HIGH_FLOAT:
4555 mCaps.vertexHighpFloat.get(range, precision);
4556 break;
4557
4558 case GL_LOW_INT:
4559 mCaps.vertexLowpInt.get(range, precision);
4560 break;
4561 case GL_MEDIUM_INT:
4562 mCaps.vertexMediumpInt.get(range, precision);
4563 break;
4564 case GL_HIGH_INT:
4565 mCaps.vertexHighpInt.get(range, precision);
4566 break;
4567
4568 default:
4569 UNREACHABLE();
4570 return;
4571 }
4572 break;
4573
4574 case GL_FRAGMENT_SHADER:
4575 switch (precisiontype)
4576 {
4577 case GL_LOW_FLOAT:
4578 mCaps.fragmentLowpFloat.get(range, precision);
4579 break;
4580 case GL_MEDIUM_FLOAT:
4581 mCaps.fragmentMediumpFloat.get(range, precision);
4582 break;
4583 case GL_HIGH_FLOAT:
4584 mCaps.fragmentHighpFloat.get(range, precision);
4585 break;
4586
4587 case GL_LOW_INT:
4588 mCaps.fragmentLowpInt.get(range, precision);
4589 break;
4590 case GL_MEDIUM_INT:
4591 mCaps.fragmentMediumpInt.get(range, precision);
4592 break;
4593 case GL_HIGH_INT:
4594 mCaps.fragmentHighpInt.get(range, precision);
4595 break;
4596
4597 default:
4598 UNREACHABLE();
4599 return;
4600 }
4601 break;
4602
4603 default:
4604 UNREACHABLE();
4605 return;
4606 }
4607}
4608
4609void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
4610{
4611 Shader *shaderObject = getShader(shader);
4612 ASSERT(shaderObject);
4613 shaderObject->getSource(bufsize, length, source);
4614}
4615
4616void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
4617{
4618 Program *programObject = getProgram(program);
4619 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04004620 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004621}
4622
4623void Context::getUniformiv(GLuint program, GLint location, GLint *params)
4624{
4625 Program *programObject = getProgram(program);
4626 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04004627 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004628}
4629
4630GLint Context::getUniformLocation(GLuint program, const GLchar *name)
4631{
4632 Program *programObject = getProgram(program);
4633 ASSERT(programObject);
4634 return programObject->getUniformLocation(name);
4635}
4636
4637GLboolean Context::isBuffer(GLuint buffer)
4638{
4639 if (buffer == 0)
4640 {
4641 return GL_FALSE;
4642 }
4643
4644 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
4645}
4646
4647GLboolean Context::isEnabled(GLenum cap)
4648{
4649 return mGLState.getEnableFeature(cap);
4650}
4651
4652GLboolean Context::isFramebuffer(GLuint framebuffer)
4653{
4654 if (framebuffer == 0)
4655 {
4656 return GL_FALSE;
4657 }
4658
4659 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
4660}
4661
4662GLboolean Context::isProgram(GLuint program)
4663{
4664 if (program == 0)
4665 {
4666 return GL_FALSE;
4667 }
4668
4669 return (getProgram(program) ? GL_TRUE : GL_FALSE);
4670}
4671
4672GLboolean Context::isRenderbuffer(GLuint renderbuffer)
4673{
4674 if (renderbuffer == 0)
4675 {
4676 return GL_FALSE;
4677 }
4678
4679 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
4680}
4681
4682GLboolean Context::isShader(GLuint shader)
4683{
4684 if (shader == 0)
4685 {
4686 return GL_FALSE;
4687 }
4688
4689 return (getShader(shader) ? GL_TRUE : GL_FALSE);
4690}
4691
4692GLboolean Context::isTexture(GLuint texture)
4693{
4694 if (texture == 0)
4695 {
4696 return GL_FALSE;
4697 }
4698
4699 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
4700}
4701
4702void Context::linkProgram(GLuint program)
4703{
4704 Program *programObject = getProgram(program);
4705 ASSERT(programObject);
4706 handleError(programObject->link(this));
Martin Radev0abb7a22017-08-28 15:34:45 +03004707 mGLState.onProgramExecutableChange(programObject);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004708}
4709
4710void Context::releaseShaderCompiler()
4711{
Jamie Madill4928b7c2017-06-20 12:57:39 -04004712 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004713}
4714
4715void Context::shaderBinary(GLsizei n,
4716 const GLuint *shaders,
4717 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04004718 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04004719 GLsizei length)
4720{
4721 // No binary shader formats are supported.
4722 UNIMPLEMENTED();
4723}
4724
4725void Context::shaderSource(GLuint shader,
4726 GLsizei count,
4727 const GLchar *const *string,
4728 const GLint *length)
4729{
4730 Shader *shaderObject = getShader(shader);
4731 ASSERT(shaderObject);
4732 shaderObject->setSource(count, string, length);
4733}
4734
4735void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
4736{
4737 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
4738}
4739
4740void Context::stencilMask(GLuint mask)
4741{
4742 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
4743}
4744
4745void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
4746{
4747 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
4748}
4749
4750void Context::uniform1f(GLint location, GLfloat x)
4751{
4752 Program *program = mGLState.getProgram();
4753 program->setUniform1fv(location, 1, &x);
4754}
4755
4756void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
4757{
4758 Program *program = mGLState.getProgram();
4759 program->setUniform1fv(location, count, v);
4760}
4761
4762void Context::uniform1i(GLint location, GLint x)
4763{
4764 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04004765 if (program->setUniform1iv(location, 1, &x) == Program::SetUniformResult::SamplerChanged)
4766 {
4767 mGLState.setObjectDirty(GL_PROGRAM);
4768 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04004769}
4770
4771void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
4772{
4773 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04004774 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
4775 {
4776 mGLState.setObjectDirty(GL_PROGRAM);
4777 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04004778}
4779
4780void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
4781{
4782 GLfloat xy[2] = {x, y};
4783 Program *program = mGLState.getProgram();
4784 program->setUniform2fv(location, 1, xy);
4785}
4786
4787void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
4788{
4789 Program *program = mGLState.getProgram();
4790 program->setUniform2fv(location, count, v);
4791}
4792
4793void Context::uniform2i(GLint location, GLint x, GLint y)
4794{
4795 GLint xy[2] = {x, y};
4796 Program *program = mGLState.getProgram();
4797 program->setUniform2iv(location, 1, xy);
4798}
4799
4800void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
4801{
4802 Program *program = mGLState.getProgram();
4803 program->setUniform2iv(location, count, v);
4804}
4805
4806void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
4807{
4808 GLfloat xyz[3] = {x, y, z};
4809 Program *program = mGLState.getProgram();
4810 program->setUniform3fv(location, 1, xyz);
4811}
4812
4813void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
4814{
4815 Program *program = mGLState.getProgram();
4816 program->setUniform3fv(location, count, v);
4817}
4818
4819void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
4820{
4821 GLint xyz[3] = {x, y, z};
4822 Program *program = mGLState.getProgram();
4823 program->setUniform3iv(location, 1, xyz);
4824}
4825
4826void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
4827{
4828 Program *program = mGLState.getProgram();
4829 program->setUniform3iv(location, count, v);
4830}
4831
4832void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4833{
4834 GLfloat xyzw[4] = {x, y, z, w};
4835 Program *program = mGLState.getProgram();
4836 program->setUniform4fv(location, 1, xyzw);
4837}
4838
4839void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
4840{
4841 Program *program = mGLState.getProgram();
4842 program->setUniform4fv(location, count, v);
4843}
4844
4845void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
4846{
4847 GLint xyzw[4] = {x, y, z, w};
4848 Program *program = mGLState.getProgram();
4849 program->setUniform4iv(location, 1, xyzw);
4850}
4851
4852void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
4853{
4854 Program *program = mGLState.getProgram();
4855 program->setUniform4iv(location, count, v);
4856}
4857
4858void Context::uniformMatrix2fv(GLint location,
4859 GLsizei count,
4860 GLboolean transpose,
4861 const GLfloat *value)
4862{
4863 Program *program = mGLState.getProgram();
4864 program->setUniformMatrix2fv(location, count, transpose, value);
4865}
4866
4867void Context::uniformMatrix3fv(GLint location,
4868 GLsizei count,
4869 GLboolean transpose,
4870 const GLfloat *value)
4871{
4872 Program *program = mGLState.getProgram();
4873 program->setUniformMatrix3fv(location, count, transpose, value);
4874}
4875
4876void Context::uniformMatrix4fv(GLint location,
4877 GLsizei count,
4878 GLboolean transpose,
4879 const GLfloat *value)
4880{
4881 Program *program = mGLState.getProgram();
4882 program->setUniformMatrix4fv(location, count, transpose, value);
4883}
4884
4885void Context::validateProgram(GLuint program)
4886{
4887 Program *programObject = getProgram(program);
4888 ASSERT(programObject);
4889 programObject->validate(mCaps);
4890}
4891
Jamie Madilld04908b2017-06-09 14:15:35 -04004892void Context::getProgramBinary(GLuint program,
4893 GLsizei bufSize,
4894 GLsizei *length,
4895 GLenum *binaryFormat,
4896 void *binary)
4897{
4898 Program *programObject = getProgram(program);
4899 ASSERT(programObject != nullptr);
4900
4901 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
4902}
4903
4904void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
4905{
4906 Program *programObject = getProgram(program);
4907 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04004908
Jamie Madilld04908b2017-06-09 14:15:35 -04004909 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
4910}
4911
Jamie Madillff325f12017-08-26 15:06:05 -04004912void Context::uniform1ui(GLint location, GLuint v0)
4913{
4914 Program *program = mGLState.getProgram();
4915 program->setUniform1uiv(location, 1, &v0);
4916}
4917
4918void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
4919{
4920 Program *program = mGLState.getProgram();
4921 const GLuint xy[] = {v0, v1};
4922 program->setUniform2uiv(location, 1, xy);
4923}
4924
4925void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
4926{
4927 Program *program = mGLState.getProgram();
4928 const GLuint xyz[] = {v0, v1, v2};
4929 program->setUniform3uiv(location, 1, xyz);
4930}
4931
4932void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
4933{
4934 Program *program = mGLState.getProgram();
4935 const GLuint xyzw[] = {v0, v1, v2, v3};
4936 program->setUniform4uiv(location, 1, xyzw);
4937}
4938
4939void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
4940{
4941 Program *program = mGLState.getProgram();
4942 program->setUniform1uiv(location, count, value);
4943}
4944void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
4945{
4946 Program *program = mGLState.getProgram();
4947 program->setUniform2uiv(location, count, value);
4948}
4949
4950void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
4951{
4952 Program *program = mGLState.getProgram();
4953 program->setUniform3uiv(location, count, value);
4954}
4955
4956void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
4957{
4958 Program *program = mGLState.getProgram();
4959 program->setUniform4uiv(location, count, value);
4960}
4961
Jamie Madillf0e04492017-08-26 15:28:42 -04004962void Context::genQueries(GLsizei n, GLuint *ids)
4963{
4964 for (GLsizei i = 0; i < n; i++)
4965 {
4966 GLuint handle = mQueryHandleAllocator.allocate();
4967 mQueryMap.assign(handle, nullptr);
4968 ids[i] = handle;
4969 }
4970}
4971
4972void Context::deleteQueries(GLsizei n, const GLuint *ids)
4973{
4974 for (int i = 0; i < n; i++)
4975 {
4976 GLuint query = ids[i];
4977
4978 Query *queryObject = nullptr;
4979 if (mQueryMap.erase(query, &queryObject))
4980 {
4981 mQueryHandleAllocator.release(query);
4982 if (queryObject)
4983 {
4984 queryObject->release(this);
4985 }
4986 }
4987 }
4988}
4989
4990GLboolean Context::isQuery(GLuint id)
4991{
4992 return (getQuery(id, false, GL_NONE) != nullptr) ? GL_TRUE : GL_FALSE;
4993}
4994
Jamie Madillc8c95812017-08-26 18:40:09 -04004995void Context::uniformMatrix2x3fv(GLint location,
4996 GLsizei count,
4997 GLboolean transpose,
4998 const GLfloat *value)
4999{
5000 Program *program = mGLState.getProgram();
5001 program->setUniformMatrix2x3fv(location, count, transpose, value);
5002}
5003
5004void Context::uniformMatrix3x2fv(GLint location,
5005 GLsizei count,
5006 GLboolean transpose,
5007 const GLfloat *value)
5008{
5009 Program *program = mGLState.getProgram();
5010 program->setUniformMatrix3x2fv(location, count, transpose, value);
5011}
5012
5013void Context::uniformMatrix2x4fv(GLint location,
5014 GLsizei count,
5015 GLboolean transpose,
5016 const GLfloat *value)
5017{
5018 Program *program = mGLState.getProgram();
5019 program->setUniformMatrix2x4fv(location, count, transpose, value);
5020}
5021
5022void Context::uniformMatrix4x2fv(GLint location,
5023 GLsizei count,
5024 GLboolean transpose,
5025 const GLfloat *value)
5026{
5027 Program *program = mGLState.getProgram();
5028 program->setUniformMatrix4x2fv(location, count, transpose, value);
5029}
5030
5031void Context::uniformMatrix3x4fv(GLint location,
5032 GLsizei count,
5033 GLboolean transpose,
5034 const GLfloat *value)
5035{
5036 Program *program = mGLState.getProgram();
5037 program->setUniformMatrix3x4fv(location, count, transpose, value);
5038}
5039
5040void Context::uniformMatrix4x3fv(GLint location,
5041 GLsizei count,
5042 GLboolean transpose,
5043 const GLfloat *value)
5044{
5045 Program *program = mGLState.getProgram();
5046 program->setUniformMatrix4x3fv(location, count, transpose, value);
5047}
5048
Jamie Madilld7576732017-08-26 18:49:50 -04005049void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
5050{
5051 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5052 {
5053 GLuint vertexArray = arrays[arrayIndex];
5054
5055 if (arrays[arrayIndex] != 0)
5056 {
5057 VertexArray *vertexArrayObject = nullptr;
5058 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
5059 {
5060 if (vertexArrayObject != nullptr)
5061 {
5062 detachVertexArray(vertexArray);
5063 vertexArrayObject->onDestroy(this);
5064 }
5065
5066 mVertexArrayHandleAllocator.release(vertexArray);
5067 }
5068 }
5069 }
5070}
5071
5072void Context::genVertexArrays(GLsizei n, GLuint *arrays)
5073{
5074 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5075 {
5076 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
5077 mVertexArrayMap.assign(vertexArray, nullptr);
5078 arrays[arrayIndex] = vertexArray;
5079 }
5080}
5081
5082bool Context::isVertexArray(GLuint array)
5083{
5084 if (array == 0)
5085 {
5086 return GL_FALSE;
5087 }
5088
5089 VertexArray *vao = getVertexArray(array);
5090 return (vao != nullptr ? GL_TRUE : GL_FALSE);
5091}
5092
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04005093void Context::endTransformFeedback()
5094{
5095 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5096 transformFeedback->end(this);
5097}
5098
5099void Context::transformFeedbackVaryings(GLuint program,
5100 GLsizei count,
5101 const GLchar *const *varyings,
5102 GLenum bufferMode)
5103{
5104 Program *programObject = getProgram(program);
5105 ASSERT(programObject);
5106 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
5107}
5108
5109void Context::getTransformFeedbackVarying(GLuint program,
5110 GLuint index,
5111 GLsizei bufSize,
5112 GLsizei *length,
5113 GLsizei *size,
5114 GLenum *type,
5115 GLchar *name)
5116{
5117 Program *programObject = getProgram(program);
5118 ASSERT(programObject);
5119 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
5120}
5121
5122void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
5123{
5124 for (int i = 0; i < n; i++)
5125 {
5126 GLuint transformFeedback = ids[i];
5127 if (transformFeedback == 0)
5128 {
5129 continue;
5130 }
5131
5132 TransformFeedback *transformFeedbackObject = nullptr;
5133 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
5134 {
5135 if (transformFeedbackObject != nullptr)
5136 {
5137 detachTransformFeedback(transformFeedback);
5138 transformFeedbackObject->release(this);
5139 }
5140
5141 mTransformFeedbackHandleAllocator.release(transformFeedback);
5142 }
5143 }
5144}
5145
5146void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
5147{
5148 for (int i = 0; i < n; i++)
5149 {
5150 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
5151 mTransformFeedbackMap.assign(transformFeedback, nullptr);
5152 ids[i] = transformFeedback;
5153 }
5154}
5155
5156bool Context::isTransformFeedback(GLuint id)
5157{
5158 if (id == 0)
5159 {
5160 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
5161 // returns FALSE
5162 return GL_FALSE;
5163 }
5164
5165 const TransformFeedback *transformFeedback = getTransformFeedback(id);
5166 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
5167}
5168
5169void Context::pauseTransformFeedback()
5170{
5171 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5172 transformFeedback->pause();
5173}
5174
5175void Context::resumeTransformFeedback()
5176{
5177 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5178 transformFeedback->resume();
5179}
5180
Jamie Madill12e957f2017-08-26 21:42:26 -04005181void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
5182{
5183 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04005184 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04005185}
5186
5187GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
5188{
5189 const Program *programObject = getProgram(program);
5190 return programObject->getFragDataLocation(name);
5191}
5192
5193void Context::getUniformIndices(GLuint program,
5194 GLsizei uniformCount,
5195 const GLchar *const *uniformNames,
5196 GLuint *uniformIndices)
5197{
5198 const Program *programObject = getProgram(program);
5199 if (!programObject->isLinked())
5200 {
5201 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5202 {
5203 uniformIndices[uniformId] = GL_INVALID_INDEX;
5204 }
5205 }
5206 else
5207 {
5208 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5209 {
5210 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
5211 }
5212 }
5213}
5214
5215void Context::getActiveUniformsiv(GLuint program,
5216 GLsizei uniformCount,
5217 const GLuint *uniformIndices,
5218 GLenum pname,
5219 GLint *params)
5220{
5221 const Program *programObject = getProgram(program);
5222 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5223 {
5224 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08005225 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04005226 }
5227}
5228
5229GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
5230{
5231 const Program *programObject = getProgram(program);
5232 return programObject->getUniformBlockIndex(uniformBlockName);
5233}
5234
5235void Context::getActiveUniformBlockiv(GLuint program,
5236 GLuint uniformBlockIndex,
5237 GLenum pname,
5238 GLint *params)
5239{
5240 const Program *programObject = getProgram(program);
5241 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
5242}
5243
5244void Context::getActiveUniformBlockName(GLuint program,
5245 GLuint uniformBlockIndex,
5246 GLsizei bufSize,
5247 GLsizei *length,
5248 GLchar *uniformBlockName)
5249{
5250 const Program *programObject = getProgram(program);
5251 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
5252}
5253
5254void Context::uniformBlockBinding(GLuint program,
5255 GLuint uniformBlockIndex,
5256 GLuint uniformBlockBinding)
5257{
5258 Program *programObject = getProgram(program);
5259 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
5260}
5261
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005262GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
5263{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005264 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
5265 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005266
Jamie Madill70b5bb02017-08-28 13:32:37 -04005267 Sync *syncObject = getSync(syncHandle);
5268 Error error = syncObject->set(condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005269 if (error.isError())
5270 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04005271 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005272 handleError(error);
5273 return nullptr;
5274 }
5275
Jamie Madill70b5bb02017-08-28 13:32:37 -04005276 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005277}
5278
5279GLboolean Context::isSync(GLsync sync)
5280{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005281 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005282}
5283
5284GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
5285{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005286 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005287
5288 GLenum result = GL_WAIT_FAILED;
5289 handleError(syncObject->clientWait(flags, timeout, &result));
5290 return result;
5291}
5292
5293void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
5294{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005295 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005296 handleError(syncObject->serverWait(flags, timeout));
5297}
5298
5299void Context::getInteger64v(GLenum pname, GLint64 *params)
5300{
5301 GLenum nativeType = GL_NONE;
5302 unsigned int numParams = 0;
5303 getQueryParameterInfo(pname, &nativeType, &numParams);
5304
5305 if (nativeType == GL_INT_64_ANGLEX)
5306 {
5307 getInteger64vImpl(pname, params);
5308 }
5309 else
5310 {
5311 CastStateValues(this, nativeType, pname, numParams, params);
5312 }
5313}
5314
Jamie Madill3ef140a2017-08-26 23:11:21 -04005315void Context::getBufferParameteri64v(GLenum target, GLenum pname, GLint64 *params)
5316{
5317 Buffer *buffer = mGLState.getTargetBuffer(target);
5318 QueryBufferParameteri64v(buffer, pname, params);
5319}
5320
5321void Context::genSamplers(GLsizei count, GLuint *samplers)
5322{
5323 for (int i = 0; i < count; i++)
5324 {
5325 samplers[i] = mState.mSamplers->createSampler();
5326 }
5327}
5328
5329void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
5330{
5331 for (int i = 0; i < count; i++)
5332 {
5333 GLuint sampler = samplers[i];
5334
5335 if (mState.mSamplers->getSampler(sampler))
5336 {
5337 detachSampler(sampler);
5338 }
5339
5340 mState.mSamplers->deleteObject(this, sampler);
5341 }
5342}
5343
5344void Context::getInternalformativ(GLenum target,
5345 GLenum internalformat,
5346 GLenum pname,
5347 GLsizei bufSize,
5348 GLint *params)
5349{
5350 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
5351 QueryInternalFormativ(formatCaps, pname, bufSize, params);
5352}
5353
Jamie Madill81c2e252017-09-09 23:32:46 -04005354void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5355{
5356 Program *programObject = getProgram(program);
5357 ASSERT(programObject);
5358 if (programObject->setUniform1iv(location, count, value) ==
5359 Program::SetUniformResult::SamplerChanged)
5360 {
5361 mGLState.setObjectDirty(GL_PROGRAM);
5362 }
5363}
5364
5365void Context::onTextureChange(const Texture *texture)
5366{
5367 // Conservatively assume all textures are dirty.
5368 // TODO(jmadill): More fine-grained update.
5369 mGLState.setObjectDirty(GL_TEXTURE);
5370}
5371
Yunchao Hea336b902017-08-02 16:05:21 +08005372void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
5373{
5374 for (int i = 0; i < count; i++)
5375 {
5376 pipelines[i] = createProgramPipeline();
5377 }
5378}
5379
5380void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
5381{
5382 for (int i = 0; i < count; i++)
5383 {
5384 if (pipelines[i] != 0)
5385 {
5386 deleteProgramPipeline(pipelines[i]);
5387 }
5388 }
5389}
5390
5391GLboolean Context::isProgramPipeline(GLuint pipeline)
5392{
5393 if (pipeline == 0)
5394 {
5395 return GL_FALSE;
5396 }
5397
5398 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
5399}
5400
Jamie Madillc29968b2016-01-20 11:17:23 -05005401} // namespace gl