blob: 168d8a0f92a5c9938f4bad001982399ab5d98995 [file] [log] [blame]
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001//
Geoff Langeeba6e12014-02-03 13:12:30 -05002// Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7// Context.cpp: Implements the gl::Context class, managing all GL state and performing
8// rendering operations. It is the GLES2 specific implementation of EGLContext.
9
Geoff Lang2b5420c2014-11-19 14:20:15 -050010#include "libANGLE/Context.h"
apatrick@chromium.org144f2802012-07-12 01:42:34 +000011
Jamie Madill231c7f52017-04-26 13:45:37 -040012#include <string.h>
Jamie Madillb9293972015-02-19 11:07:54 -050013#include <iterator>
14#include <sstream>
Sami Väisänend59ca052016-06-21 16:10:00 +030015#include <vector>
Jamie Madillb9293972015-02-19 11:07:54 -050016
Sami Väisänene45e53b2016-05-25 10:36:04 +030017#include "common/matrix_utils.h"
Geoff Lang0b7eef72014-06-12 14:10:47 -040018#include "common/platform.h"
Jamie Madillb9293972015-02-19 11:07:54 -050019#include "common/utilities.h"
Geoff Langc339c4e2016-11-29 10:37:36 -050020#include "common/version.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050021#include "libANGLE/Buffer.h"
Jamie Madillb9293972015-02-19 11:07:54 -050022#include "libANGLE/Compiler.h"
Jamie Madill948bbe52017-06-01 13:10:42 -040023#include "libANGLE/Display.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050024#include "libANGLE/Fence.h"
25#include "libANGLE/Framebuffer.h"
26#include "libANGLE/FramebufferAttachment.h"
Sami Väisänene45e53b2016-05-25 10:36:04 +030027#include "libANGLE/Path.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050028#include "libANGLE/Program.h"
Yunchao Hea336b902017-08-02 16:05:21 +080029#include "libANGLE/ProgramPipeline.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050030#include "libANGLE/Query.h"
Jamie Madillb9293972015-02-19 11:07:54 -050031#include "libANGLE/Renderbuffer.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050032#include "libANGLE/ResourceManager.h"
33#include "libANGLE/Sampler.h"
Jamie Madill9dd0cf02014-11-24 11:38:51 -050034#include "libANGLE/Surface.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050035#include "libANGLE/Texture.h"
36#include "libANGLE/TransformFeedback.h"
37#include "libANGLE/VertexArray.h"
Kenneth Russellf2f6f652016-10-05 19:53:23 -070038#include "libANGLE/Workarounds.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040039#include "libANGLE/formatutils.h"
Martin Radev66fb8202016-07-28 11:45:20 +030040#include "libANGLE/queryconversions.h"
Geoff Langc1984ed2016-10-07 12:41:00 -040041#include "libANGLE/queryutils.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040042#include "libANGLE/renderer/ContextImpl.h"
43#include "libANGLE/renderer/EGLImplFactory.h"
44#include "libANGLE/validationES.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000045
Geoff Langf6db0982015-08-25 13:04:00 -040046namespace
47{
48
Jamie Madillb6664922017-07-25 12:55:04 -040049#define ANGLE_HANDLE_ERR(X) \
50 handleError(X); \
51 return;
52#define ANGLE_CONTEXT_TRY(EXPR) ANGLE_TRY_TEMPLATE(EXPR, ANGLE_HANDLE_ERR);
53
Ian Ewell3ffd78b2016-01-22 16:09:42 -050054template <typename T>
Geoff Lang4ddf5af2016-12-01 14:30:44 -050055std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager,
Sami Väisänend59ca052016-06-21 16:10:00 +030056 GLsizei numPaths,
57 const void *paths,
58 GLuint pathBase)
59{
60 std::vector<gl::Path *> ret;
61 ret.reserve(numPaths);
62
63 const auto *nameArray = static_cast<const T *>(paths);
64
65 for (GLsizei i = 0; i < numPaths; ++i)
66 {
67 const GLuint pathName = nameArray[i] + pathBase;
68
69 ret.push_back(resourceManager.getPath(pathName));
70 }
71
72 return ret;
73}
74
Geoff Lang4ddf5af2016-12-01 14:30:44 -050075std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager,
Sami Väisänend59ca052016-06-21 16:10:00 +030076 GLsizei numPaths,
77 GLenum pathNameType,
78 const void *paths,
79 GLuint pathBase)
80{
81 switch (pathNameType)
82 {
83 case GL_UNSIGNED_BYTE:
84 return GatherPaths<GLubyte>(resourceManager, numPaths, paths, pathBase);
85
86 case GL_BYTE:
87 return GatherPaths<GLbyte>(resourceManager, numPaths, paths, pathBase);
88
89 case GL_UNSIGNED_SHORT:
90 return GatherPaths<GLushort>(resourceManager, numPaths, paths, pathBase);
91
92 case GL_SHORT:
93 return GatherPaths<GLshort>(resourceManager, numPaths, paths, pathBase);
94
95 case GL_UNSIGNED_INT:
96 return GatherPaths<GLuint>(resourceManager, numPaths, paths, pathBase);
97
98 case GL_INT:
99 return GatherPaths<GLint>(resourceManager, numPaths, paths, pathBase);
100 }
101
102 UNREACHABLE();
103 return std::vector<gl::Path *>();
104}
105
106template <typename T>
Geoff Lang2186c382016-10-14 10:54:54 -0400107gl::Error GetQueryObjectParameter(gl::Query *query, GLenum pname, T *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500108{
Geoff Lang2186c382016-10-14 10:54:54 -0400109 ASSERT(query != nullptr);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500110
111 switch (pname)
112 {
113 case GL_QUERY_RESULT_EXT:
Geoff Lang2186c382016-10-14 10:54:54 -0400114 return query->getResult(params);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500115 case GL_QUERY_RESULT_AVAILABLE_EXT:
116 {
117 bool available;
Geoff Lang2186c382016-10-14 10:54:54 -0400118 gl::Error error = query->isResultAvailable(&available);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500119 if (!error.isError())
120 {
jchen10a99ed552017-09-22 08:10:32 +0800121 *params = gl::CastFromStateValue<T>(pname, static_cast<GLuint>(available));
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500122 }
123 return error;
124 }
125 default:
126 UNREACHABLE();
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500127 return gl::InternalError() << "Unreachable Error";
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500128 }
129}
130
Geoff Langf6db0982015-08-25 13:04:00 -0400131void MarkTransformFeedbackBufferUsage(gl::TransformFeedback *transformFeedback)
132{
Geoff Lang1a683462015-09-29 15:09:59 -0400133 if (transformFeedback && transformFeedback->isActive() && !transformFeedback->isPaused())
Geoff Langf6db0982015-08-25 13:04:00 -0400134 {
135 for (size_t tfBufferIndex = 0; tfBufferIndex < transformFeedback->getIndexedBufferCount();
136 tfBufferIndex++)
137 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400138 const gl::OffsetBindingPointer<gl::Buffer> &buffer =
Geoff Langf6db0982015-08-25 13:04:00 -0400139 transformFeedback->getIndexedBuffer(tfBufferIndex);
140 if (buffer.get() != nullptr)
141 {
142 buffer->onTransformFeedback();
143 }
144 }
145 }
146}
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500147
148// Attribute map queries.
Martin Radev1be913c2016-07-11 17:59:16 +0300149EGLint GetClientMajorVersion(const egl::AttributeMap &attribs)
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500150{
Ian Ewellec2c0c52016-04-05 13:46:26 -0400151 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_CLIENT_VERSION, 1));
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500152}
153
Martin Radev1be913c2016-07-11 17:59:16 +0300154EGLint GetClientMinorVersion(const egl::AttributeMap &attribs)
155{
156 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_MINOR_VERSION, 0));
157}
158
Geoff Langeb66a6e2016-10-31 13:06:12 -0400159gl::Version GetClientVersion(const egl::AttributeMap &attribs)
160{
161 return gl::Version(GetClientMajorVersion(attribs), GetClientMinorVersion(attribs));
162}
163
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500164GLenum GetResetStrategy(const egl::AttributeMap &attribs)
165{
Ian Ewellec2c0c52016-04-05 13:46:26 -0400166 EGLAttrib attrib = attribs.get(EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT,
167 EGL_NO_RESET_NOTIFICATION_EXT);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500168 switch (attrib)
169 {
170 case EGL_NO_RESET_NOTIFICATION:
171 return GL_NO_RESET_NOTIFICATION_EXT;
172 case EGL_LOSE_CONTEXT_ON_RESET:
173 return GL_LOSE_CONTEXT_ON_RESET_EXT;
174 default:
175 UNREACHABLE();
176 return GL_NONE;
177 }
178}
179
180bool GetRobustAccess(const egl::AttributeMap &attribs)
181{
Geoff Lang077f20a2016-11-01 10:08:02 -0400182 return (attribs.get(EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT, EGL_FALSE) == EGL_TRUE) ||
183 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR) !=
184 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500185}
186
187bool GetDebug(const egl::AttributeMap &attribs)
188{
Geoff Lang077f20a2016-11-01 10:08:02 -0400189 return (attribs.get(EGL_CONTEXT_OPENGL_DEBUG, EGL_FALSE) == EGL_TRUE) ||
190 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR) != 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500191}
192
193bool GetNoError(const egl::AttributeMap &attribs)
194{
195 return (attribs.get(EGL_CONTEXT_OPENGL_NO_ERROR_KHR, EGL_FALSE) == EGL_TRUE);
196}
197
Geoff Langc287ea62016-09-16 14:46:51 -0400198bool GetWebGLContext(const egl::AttributeMap &attribs)
199{
200 return (attribs.get(EGL_CONTEXT_WEBGL_COMPATIBILITY_ANGLE, EGL_FALSE) == EGL_TRUE);
201}
202
Geoff Langf41a7152016-09-19 15:11:17 -0400203bool GetBindGeneratesResource(const egl::AttributeMap &attribs)
204{
205 return (attribs.get(EGL_CONTEXT_BIND_GENERATES_RESOURCE_CHROMIUM, EGL_TRUE) == EGL_TRUE);
206}
207
Geoff Langfeb8c682017-02-13 16:07:35 -0500208bool GetClientArraysEnabled(const egl::AttributeMap &attribs)
209{
210 return (attribs.get(EGL_CONTEXT_CLIENT_ARRAYS_ENABLED_ANGLE, EGL_TRUE) == EGL_TRUE);
211}
212
Geoff Langb433e872017-10-05 14:01:47 -0400213bool GetRobustResourceInit(const egl::AttributeMap &attribs)
214{
215 return (attribs.get(EGL_ROBUST_RESOURCE_INITIALIZATION_ANGLE, EGL_FALSE) == EGL_TRUE);
216}
217
Martin Radev9d901792016-07-15 15:58:58 +0300218std::string GetObjectLabelFromPointer(GLsizei length, const GLchar *label)
219{
220 std::string labelName;
221 if (label != nullptr)
222 {
223 size_t labelLength = length < 0 ? strlen(label) : length;
224 labelName = std::string(label, labelLength);
225 }
226 return labelName;
227}
228
229void GetObjectLabelBase(const std::string &objectLabel,
230 GLsizei bufSize,
231 GLsizei *length,
232 GLchar *label)
233{
234 size_t writeLength = objectLabel.length();
235 if (label != nullptr && bufSize > 0)
236 {
237 writeLength = std::min(static_cast<size_t>(bufSize) - 1, objectLabel.length());
238 std::copy(objectLabel.begin(), objectLabel.begin() + writeLength, label);
239 label[writeLength] = '\0';
240 }
241
242 if (length != nullptr)
243 {
244 *length = static_cast<GLsizei>(writeLength);
245 }
246}
247
Jamie Madill0f80ed82017-09-19 00:24:56 -0400248template <typename CapT, typename MaxT>
249void LimitCap(CapT *cap, MaxT maximum)
250{
251 *cap = std::min(*cap, static_cast<CapT>(maximum));
252}
253
Geoff Langf6db0982015-08-25 13:04:00 -0400254} // anonymous namespace
255
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000256namespace gl
257{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +0000258
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400259Context::Context(rx::EGLImplFactory *implFactory,
260 const egl::Config *config,
Corentin Wallez51706ea2015-08-07 14:39:22 -0400261 const Context *shareContext,
Geoff Langce02f082017-02-06 16:46:21 -0500262 TextureManager *shareTextures,
Jamie Madill32447362017-06-28 14:53:52 -0400263 MemoryProgramCache *memoryProgramCache,
Corentin Wallezc295e512017-01-27 17:47:50 -0500264 const egl::AttributeMap &attribs,
Geoff Langb433e872017-10-05 14:01:47 -0400265 const egl::DisplayExtensions &displayExtensions)
Martin Radev1be913c2016-07-11 17:59:16 +0300266
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500267 : ValidationContext(shareContext,
Geoff Langce02f082017-02-06 16:46:21 -0500268 shareTextures,
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500269 GetClientVersion(attribs),
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700270 &mGLState,
Jamie Madillf25855c2015-11-03 11:06:18 -0500271 mCaps,
272 mTextureCaps,
273 mExtensions,
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500274 mLimitations,
275 GetNoError(attribs)),
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700276 mImplementation(implFactory->createContext(mState)),
Jamie Madill2f348d22017-06-05 10:50:59 -0400277 mCompiler(),
Corentin Walleze3b10e82015-05-20 11:06:25 -0400278 mConfig(config),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500279 mClientType(EGL_OPENGL_ES_API),
280 mHasBeenCurrent(false),
281 mContextLost(false),
282 mResetStatus(GL_NO_ERROR),
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700283 mContextLostForced(false),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500284 mResetStrategy(GetResetStrategy(attribs)),
285 mRobustAccess(GetRobustAccess(attribs)),
Jamie Madill61e16b42017-06-19 11:13:23 -0400286 mCurrentSurface(static_cast<egl::Surface *>(EGL_NO_SURFACE)),
287 mCurrentDisplay(static_cast<egl::Display *>(EGL_NO_DISPLAY)),
Jamie Madill4e0e6f82017-02-17 11:06:03 -0500288 mSurfacelessFramebuffer(nullptr),
Jamie Madille14951e2017-03-09 18:55:16 -0500289 mWebGLContext(GetWebGLContext(attribs)),
Jamie Madill32447362017-06-28 14:53:52 -0400290 mMemoryProgramCache(memoryProgramCache),
Jamie Madillb3f26b92017-07-19 15:07:41 -0400291 mScratchBuffer(1000u),
292 mZeroFilledBuffer(1000u)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000293{
Jamie Madill14bbb3f2017-09-12 15:23:01 -0400294 mImplementation->setMemoryProgramCache(memoryProgramCache);
295
Geoff Langb433e872017-10-05 14:01:47 -0400296 bool robustResourceInit = GetRobustResourceInit(attribs);
297 initCaps(displayExtensions, robustResourceInit);
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700298 initWorkarounds();
Geoff Langc0b9ef42014-07-02 10:02:37 -0400299
Jamie Madill4928b7c2017-06-20 12:57:39 -0400300 mGLState.initialize(this, GetDebug(attribs), GetBindGeneratesResource(attribs),
Jamie Madillc43be722017-07-13 16:22:14 -0400301 GetClientArraysEnabled(attribs), robustResourceInit,
302 mMemoryProgramCache != nullptr);
Régis Fénéon83107972015-02-05 12:57:44 +0100303
Shannon Woods53a94a82014-06-24 15:20:36 -0400304 mFenceNVHandleAllocator.setBaseHandle(0);
Geoff Lang7dca1862013-07-30 16:30:46 -0400305
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000306 // [OpenGL ES 2.0.24] section 3.7 page 83:
307 // In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have twodimensional
308 // and cube map texture state vectors respectively associated with them.
309 // In order that access to these initial textures not be lost, they are treated as texture
310 // objects all of whose names are 0.
311
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400312 Texture *zeroTexture2D = new Texture(mImplementation.get(), 0, GL_TEXTURE_2D);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400313 mZeroTextures[GL_TEXTURE_2D].set(this, zeroTexture2D);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500314
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400315 Texture *zeroTextureCube = new Texture(mImplementation.get(), 0, GL_TEXTURE_CUBE_MAP);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400316 mZeroTextures[GL_TEXTURE_CUBE_MAP].set(this, zeroTextureCube);
Geoff Lang76b10c92014-09-05 16:28:14 -0400317
Geoff Langeb66a6e2016-10-31 13:06:12 -0400318 if (getClientVersion() >= Version(3, 0))
Geoff Lang76b10c92014-09-05 16:28:14 -0400319 {
320 // TODO: These could also be enabled via extension
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400321 Texture *zeroTexture3D = new Texture(mImplementation.get(), 0, GL_TEXTURE_3D);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400322 mZeroTextures[GL_TEXTURE_3D].set(this, zeroTexture3D);
Geoff Lang76b10c92014-09-05 16:28:14 -0400323
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400324 Texture *zeroTexture2DArray = new Texture(mImplementation.get(), 0, GL_TEXTURE_2D_ARRAY);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400325 mZeroTextures[GL_TEXTURE_2D_ARRAY].set(this, zeroTexture2DArray);
Geoff Lang76b10c92014-09-05 16:28:14 -0400326 }
Geoff Lang3b573612016-10-31 14:08:10 -0400327 if (getClientVersion() >= Version(3, 1))
328 {
329 Texture *zeroTexture2DMultisample =
330 new Texture(mImplementation.get(), 0, GL_TEXTURE_2D_MULTISAMPLE);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400331 mZeroTextures[GL_TEXTURE_2D_MULTISAMPLE].set(this, zeroTexture2DMultisample);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800332
333 bindGenericAtomicCounterBuffer(0);
334 for (unsigned int i = 0; i < mCaps.maxAtomicCounterBufferBindings; i++)
335 {
336 bindIndexedAtomicCounterBuffer(0, i, 0, 0);
337 }
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800338
339 bindGenericShaderStorageBuffer(0);
340 for (unsigned int i = 0; i < mCaps.maxShaderStorageBufferBindings; i++)
341 {
342 bindIndexedShaderStorageBuffer(0, i, 0, 0);
343 }
Geoff Lang3b573612016-10-31 14:08:10 -0400344 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000345
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400346 if (mExtensions.textureRectangle)
347 {
348 Texture *zeroTextureRectangle =
349 new Texture(mImplementation.get(), 0, GL_TEXTURE_RECTANGLE_ANGLE);
350 mZeroTextures[GL_TEXTURE_RECTANGLE_ANGLE].set(this, zeroTextureRectangle);
351 }
352
Ian Ewellbda75592016-04-18 17:25:54 -0400353 if (mExtensions.eglImageExternal || mExtensions.eglStreamConsumerExternal)
354 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400355 Texture *zeroTextureExternal =
356 new Texture(mImplementation.get(), 0, GL_TEXTURE_EXTERNAL_OES);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400357 mZeroTextures[GL_TEXTURE_EXTERNAL_OES].set(this, zeroTextureExternal);
Ian Ewellbda75592016-04-18 17:25:54 -0400358 }
359
Jamie Madill4928b7c2017-06-20 12:57:39 -0400360 mGLState.initializeZeroTextures(this, mZeroTextures);
Jamie Madille6382c32014-11-07 15:05:26 -0500361
Jamie Madill57a89722013-07-02 11:57:03 -0400362 bindVertexArray(0);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000363 bindArrayBuffer(0);
Jiajia Qin9d7d0b12016-11-29 16:30:31 +0800364 bindDrawIndirectBuffer(0);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000365 bindElementArrayBuffer(0);
Geoff Lang76b10c92014-09-05 16:28:14 -0400366
Jamie Madill01a80ee2016-11-07 12:06:18 -0500367 bindRenderbuffer(GL_RENDERBUFFER, 0);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000368
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +0000369 bindGenericUniformBuffer(0);
Geoff Lang4dc3af02016-11-18 14:09:27 -0500370 for (unsigned int i = 0; i < mCaps.maxUniformBufferBindings; i++)
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +0000371 {
372 bindIndexedUniformBuffer(0, i, 0, -1);
373 }
374
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000375 bindCopyReadBuffer(0);
376 bindCopyWriteBuffer(0);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +0000377 bindPixelPackBuffer(0);
378 bindPixelUnpackBuffer(0);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000379
Geoff Langeb66a6e2016-10-31 13:06:12 -0400380 if (getClientVersion() >= Version(3, 0))
Geoff Lang1a683462015-09-29 15:09:59 -0400381 {
382 // [OpenGL ES 3.0.2] section 2.14.1 pg 85:
383 // In the initial state, a default transform feedback object is bound and treated as
384 // a transform feedback object with a name of zero. That object is bound any time
385 // BindTransformFeedback is called with id of zero
Jamie Madillf0dcb8b2017-08-26 19:05:13 -0400386 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Geoff Lang1a683462015-09-29 15:09:59 -0400387 }
Geoff Langc8058452014-02-03 12:04:11 -0500388
Jamie Madillad9f24e2016-02-12 09:27:24 -0500389 // Initialize dirty bit masks
390 // TODO(jmadill): additional ES3 state
391 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_ALIGNMENT);
392 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_ROW_LENGTH);
393 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_IMAGE_HEIGHT);
394 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_SKIP_IMAGES);
395 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_SKIP_ROWS);
396 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_SKIP_PIXELS);
Corentin Wallezbbd663a2016-04-20 17:49:17 -0400397 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500398 // No dirty objects.
399
400 // Readpixels uses the pack state and read FBO
401 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_ALIGNMENT);
402 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_REVERSE_ROW_ORDER);
403 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_ROW_LENGTH);
404 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_SKIP_ROWS);
405 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_SKIP_PIXELS);
Corentin Wallezbbd663a2016-04-20 17:49:17 -0400406 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500407 mReadPixelsDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
408
409 mClearDirtyBits.set(State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED);
410 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
411 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR);
412 mClearDirtyBits.set(State::DIRTY_BIT_VIEWPORT);
413 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_COLOR);
414 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_DEPTH);
415 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_STENCIL);
416 mClearDirtyBits.set(State::DIRTY_BIT_COLOR_MASK);
417 mClearDirtyBits.set(State::DIRTY_BIT_DEPTH_MASK);
418 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT);
419 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_BACK);
420 mClearDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
421
422 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
423 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR);
Geoff Lang1d2c41d2016-10-19 16:14:46 -0700424 mBlitDirtyBits.set(State::DIRTY_BIT_FRAMEBUFFER_SRGB);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500425 mBlitDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
426 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
Jamie Madill437fa652016-05-03 15:13:24 -0400427
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400428 handleError(mImplementation->initialize());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000429}
430
Jamie Madill4928b7c2017-06-20 12:57:39 -0400431egl::Error Context::onDestroy(const egl::Display *display)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000432{
Corentin Wallez80b24112015-08-25 16:41:57 -0400433 for (auto fence : mFenceNVMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000434 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400435 SafeDelete(fence.second);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000436 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400437 mFenceNVMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000438
Corentin Wallez80b24112015-08-25 16:41:57 -0400439 for (auto query : mQueryMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000440 {
Geoff Langf0aa8422015-09-29 15:08:34 -0400441 if (query.second != nullptr)
442 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400443 query.second->release(this);
Geoff Langf0aa8422015-09-29 15:08:34 -0400444 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000445 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400446 mQueryMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000447
Corentin Wallez80b24112015-08-25 16:41:57 -0400448 for (auto vertexArray : mVertexArrayMap)
Jamie Madill57a89722013-07-02 11:57:03 -0400449 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400450 if (vertexArray.second)
451 {
452 vertexArray.second->onDestroy(this);
453 }
Jamie Madill57a89722013-07-02 11:57:03 -0400454 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400455 mVertexArrayMap.clear();
Jamie Madill57a89722013-07-02 11:57:03 -0400456
Corentin Wallez80b24112015-08-25 16:41:57 -0400457 for (auto transformFeedback : mTransformFeedbackMap)
Geoff Langc8058452014-02-03 12:04:11 -0500458 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500459 if (transformFeedback.second != nullptr)
460 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500461 transformFeedback.second->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500462 }
Geoff Langc8058452014-02-03 12:04:11 -0500463 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400464 mTransformFeedbackMap.clear();
Geoff Langc8058452014-02-03 12:04:11 -0500465
Jamie Madilldedd7b92014-11-05 16:30:36 -0500466 for (auto &zeroTexture : mZeroTextures)
Geoff Lang76b10c92014-09-05 16:28:14 -0400467 {
Jamie Madill71c88b32017-09-14 22:20:29 -0400468 ANGLE_TRY(zeroTexture.second->onDestroy(this));
Jamie Madill4928b7c2017-06-20 12:57:39 -0400469 zeroTexture.second.set(this, nullptr);
Geoff Lang76b10c92014-09-05 16:28:14 -0400470 }
471 mZeroTextures.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000472
Corentin Wallezccab69d2017-01-27 16:57:15 -0500473 SafeDelete(mSurfacelessFramebuffer);
474
Jamie Madill4928b7c2017-06-20 12:57:39 -0400475 ANGLE_TRY(releaseSurface(display));
Jamie Madill2f348d22017-06-05 10:50:59 -0400476 releaseShaderCompiler();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500477
Jamie Madill4928b7c2017-06-20 12:57:39 -0400478 mGLState.reset(this);
479
Jamie Madill6c1f6712017-02-14 19:08:04 -0500480 mState.mBuffers->release(this);
481 mState.mShaderPrograms->release(this);
482 mState.mTextures->release(this);
483 mState.mRenderbuffers->release(this);
484 mState.mSamplers->release(this);
Jamie Madill70b5bb02017-08-28 13:32:37 -0400485 mState.mSyncs->release(this);
Jamie Madill6c1f6712017-02-14 19:08:04 -0500486 mState.mPaths->release(this);
487 mState.mFramebuffers->release(this);
Yunchao Hea336b902017-08-02 16:05:21 +0800488 mState.mPipelines->release(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400489
490 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000491}
492
Jamie Madill70ee0f62017-02-06 16:04:20 -0500493Context::~Context()
494{
495}
496
Jamie Madill4928b7c2017-06-20 12:57:39 -0400497egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000498{
Jamie Madill61e16b42017-06-19 11:13:23 -0400499 mCurrentDisplay = display;
500
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000501 if (!mHasBeenCurrent)
502 {
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000503 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500504 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400505 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000506
Corentin Wallezc295e512017-01-27 17:47:50 -0500507 int width = 0;
508 int height = 0;
509 if (surface != nullptr)
510 {
511 width = surface->getWidth();
512 height = surface->getHeight();
513 }
514
515 mGLState.setViewportParams(0, 0, width, height);
516 mGLState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000517
518 mHasBeenCurrent = true;
519 }
520
Jamie Madill1b94d432015-08-07 13:23:23 -0400521 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700522 mGLState.setAllDirtyBits();
Jamie Madill81c2e252017-09-09 23:32:46 -0400523 mGLState.setAllDirtyObjects();
Jamie Madill1b94d432015-08-07 13:23:23 -0400524
Jamie Madill4928b7c2017-06-20 12:57:39 -0400525 ANGLE_TRY(releaseSurface(display));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500526
527 Framebuffer *newDefault = nullptr;
528 if (surface != nullptr)
529 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400530 ANGLE_TRY(surface->setIsCurrent(this, true));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500531 mCurrentSurface = surface;
532 newDefault = surface->getDefaultFramebuffer();
533 }
534 else
535 {
536 if (mSurfacelessFramebuffer == nullptr)
537 {
538 mSurfacelessFramebuffer = new Framebuffer(mImplementation.get());
539 }
540
541 newDefault = mSurfacelessFramebuffer;
542 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000543
Corentin Wallez37c39792015-08-20 14:19:46 -0400544 // Update default framebuffer, the binding of the previous default
545 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400546 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700547 if (mGLState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400548 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700549 mGLState.setReadFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400550 }
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700551 if (mGLState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400552 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700553 mGLState.setDrawFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400554 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500555 mState.mFramebuffers->setDefaultFramebuffer(newDefault);
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400556 }
Ian Ewell292f0052016-02-04 10:37:32 -0500557
558 // Notify the renderer of a context switch
Jamie Madill4928b7c2017-06-20 12:57:39 -0400559 mImplementation->onMakeCurrent(this);
560 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000561}
562
Jamie Madill4928b7c2017-06-20 12:57:39 -0400563egl::Error Context::releaseSurface(const egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400564{
Corentin Wallez37c39792015-08-20 14:19:46 -0400565 // Remove the default framebuffer
Corentin Wallezc295e512017-01-27 17:47:50 -0500566 Framebuffer *currentDefault = nullptr;
567 if (mCurrentSurface != nullptr)
Corentin Wallez51706ea2015-08-07 14:39:22 -0400568 {
Corentin Wallezc295e512017-01-27 17:47:50 -0500569 currentDefault = mCurrentSurface->getDefaultFramebuffer();
570 }
571 else if (mSurfacelessFramebuffer != nullptr)
572 {
573 currentDefault = mSurfacelessFramebuffer;
Corentin Wallez51706ea2015-08-07 14:39:22 -0400574 }
575
Corentin Wallezc295e512017-01-27 17:47:50 -0500576 if (mGLState.getReadFramebuffer() == currentDefault)
577 {
578 mGLState.setReadFramebufferBinding(nullptr);
579 }
580 if (mGLState.getDrawFramebuffer() == currentDefault)
581 {
582 mGLState.setDrawFramebufferBinding(nullptr);
583 }
584 mState.mFramebuffers->setDefaultFramebuffer(nullptr);
585
586 if (mCurrentSurface)
587 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400588 ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
Corentin Wallezc295e512017-01-27 17:47:50 -0500589 mCurrentSurface = nullptr;
590 }
Jamie Madill4928b7c2017-06-20 12:57:39 -0400591
592 return egl::NoError();
Jamie Madill77a72f62015-04-14 11:18:32 -0400593}
594
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000595GLuint Context::createBuffer()
596{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500597 return mState.mBuffers->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000598}
599
600GLuint Context::createProgram()
601{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500602 return mState.mShaderPrograms->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000603}
604
605GLuint Context::createShader(GLenum type)
606{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500607 return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000608}
609
610GLuint Context::createTexture()
611{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500612 return mState.mTextures->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000613}
614
615GLuint Context::createRenderbuffer()
616{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500617 return mState.mRenderbuffers->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000618}
619
Sami Väisänene45e53b2016-05-25 10:36:04 +0300620GLuint Context::createPaths(GLsizei range)
621{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500622 auto resultOrError = mState.mPaths->createPaths(mImplementation.get(), range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300623 if (resultOrError.isError())
624 {
625 handleError(resultOrError.getError());
626 return 0;
627 }
628 return resultOrError.getResult();
629}
630
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000631// Returns an unused framebuffer name
632GLuint Context::createFramebuffer()
633{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500634 return mState.mFramebuffers->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000635}
636
Jamie Madill33dc8432013-07-26 11:55:05 -0400637GLuint Context::createFenceNV()
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000638{
Jamie Madill33dc8432013-07-26 11:55:05 -0400639 GLuint handle = mFenceNVHandleAllocator.allocate();
Jamie Madill96a483b2017-06-27 16:49:21 -0400640 mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV()));
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000641 return handle;
642}
643
Yunchao Hea336b902017-08-02 16:05:21 +0800644GLuint Context::createProgramPipeline()
645{
646 return mState.mPipelines->createProgramPipeline();
647}
648
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000649void Context::deleteBuffer(GLuint buffer)
650{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500651 if (mState.mBuffers->getBuffer(buffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000652 {
653 detachBuffer(buffer);
654 }
Jamie Madill893ab082014-05-16 16:56:10 -0400655
Jamie Madill6c1f6712017-02-14 19:08:04 -0500656 mState.mBuffers->deleteObject(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000657}
658
659void Context::deleteShader(GLuint shader)
660{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500661 mState.mShaderPrograms->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000662}
663
664void Context::deleteProgram(GLuint program)
665{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500666 mState.mShaderPrograms->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000667}
668
669void Context::deleteTexture(GLuint texture)
670{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500671 if (mState.mTextures->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000672 {
673 detachTexture(texture);
674 }
675
Jamie Madill6c1f6712017-02-14 19:08:04 -0500676 mState.mTextures->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000677}
678
679void Context::deleteRenderbuffer(GLuint renderbuffer)
680{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500681 if (mState.mRenderbuffers->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000682 {
683 detachRenderbuffer(renderbuffer);
684 }
Jamie Madill893ab082014-05-16 16:56:10 -0400685
Jamie Madill6c1f6712017-02-14 19:08:04 -0500686 mState.mRenderbuffers->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000687}
688
Jamie Madill7f0c5a42017-08-26 22:43:26 -0400689void Context::deleteSync(GLsync sync)
Jamie Madillcd055f82013-07-26 11:55:15 -0400690{
691 // The spec specifies the underlying Fence object is not deleted until all current
692 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
693 // and since our API is currently designed for being called from a single thread, we can delete
694 // the fence immediately.
Jamie Madill70b5bb02017-08-28 13:32:37 -0400695 mState.mSyncs->deleteObject(this, static_cast<GLuint>(reinterpret_cast<uintptr_t>(sync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400696}
697
Yunchao Hea336b902017-08-02 16:05:21 +0800698void Context::deleteProgramPipeline(GLuint pipeline)
699{
700 if (mState.mPipelines->getProgramPipeline(pipeline))
701 {
702 detachProgramPipeline(pipeline);
703 }
704
705 mState.mPipelines->deleteObject(this, pipeline);
706}
707
Sami Väisänene45e53b2016-05-25 10:36:04 +0300708void Context::deletePaths(GLuint first, GLsizei range)
709{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500710 mState.mPaths->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300711}
712
713bool Context::hasPathData(GLuint path) const
714{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500715 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300716 if (pathObj == nullptr)
717 return false;
718
719 return pathObj->hasPathData();
720}
721
722bool Context::hasPath(GLuint path) const
723{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500724 return mState.mPaths->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300725}
726
727void Context::setPathCommands(GLuint path,
728 GLsizei numCommands,
729 const GLubyte *commands,
730 GLsizei numCoords,
731 GLenum coordType,
732 const void *coords)
733{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500734 auto *pathObject = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300735
736 handleError(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
737}
738
739void Context::setPathParameterf(GLuint path, GLenum pname, GLfloat value)
740{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500741 auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300742
743 switch (pname)
744 {
745 case GL_PATH_STROKE_WIDTH_CHROMIUM:
746 pathObj->setStrokeWidth(value);
747 break;
748 case GL_PATH_END_CAPS_CHROMIUM:
749 pathObj->setEndCaps(static_cast<GLenum>(value));
750 break;
751 case GL_PATH_JOIN_STYLE_CHROMIUM:
752 pathObj->setJoinStyle(static_cast<GLenum>(value));
753 break;
754 case GL_PATH_MITER_LIMIT_CHROMIUM:
755 pathObj->setMiterLimit(value);
756 break;
757 case GL_PATH_STROKE_BOUND_CHROMIUM:
758 pathObj->setStrokeBound(value);
759 break;
760 default:
761 UNREACHABLE();
762 break;
763 }
764}
765
766void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value) const
767{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500768 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300769
770 switch (pname)
771 {
772 case GL_PATH_STROKE_WIDTH_CHROMIUM:
773 *value = pathObj->getStrokeWidth();
774 break;
775 case GL_PATH_END_CAPS_CHROMIUM:
776 *value = static_cast<GLfloat>(pathObj->getEndCaps());
777 break;
778 case GL_PATH_JOIN_STYLE_CHROMIUM:
779 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
780 break;
781 case GL_PATH_MITER_LIMIT_CHROMIUM:
782 *value = pathObj->getMiterLimit();
783 break;
784 case GL_PATH_STROKE_BOUND_CHROMIUM:
785 *value = pathObj->getStrokeBound();
786 break;
787 default:
788 UNREACHABLE();
789 break;
790 }
791}
792
793void Context::setPathStencilFunc(GLenum func, GLint ref, GLuint mask)
794{
795 mGLState.setPathStencilFunc(func, ref, mask);
796}
797
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000798void Context::deleteFramebuffer(GLuint framebuffer)
799{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500800 if (mState.mFramebuffers->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000801 {
802 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000803 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500804
Jamie Madill6c1f6712017-02-14 19:08:04 -0500805 mState.mFramebuffers->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000806}
807
Jamie Madill33dc8432013-07-26 11:55:05 -0400808void Context::deleteFenceNV(GLuint fence)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000809{
Jamie Madill96a483b2017-06-27 16:49:21 -0400810 FenceNV *fenceObject = nullptr;
811 if (mFenceNVMap.erase(fence, &fenceObject))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000812 {
Jamie Madill96a483b2017-06-27 16:49:21 -0400813 mFenceNVHandleAllocator.release(fence);
814 delete fenceObject;
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000815 }
816}
817
Geoff Lang70d0f492015-12-10 17:45:46 -0500818Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000819{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500820 return mState.mBuffers->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000821}
822
Jamie Madill570f7c82014-07-03 10:38:54 -0400823Texture *Context::getTexture(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000824{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500825 return mState.mTextures->getTexture(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000826}
827
Geoff Lang70d0f492015-12-10 17:45:46 -0500828Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000829{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500830 return mState.mRenderbuffers->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000831}
832
Jamie Madill70b5bb02017-08-28 13:32:37 -0400833Sync *Context::getSync(GLsync handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400834{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400835 return mState.mSyncs->getSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400836}
837
Jamie Madill57a89722013-07-02 11:57:03 -0400838VertexArray *Context::getVertexArray(GLuint handle) const
839{
Jamie Madill96a483b2017-06-27 16:49:21 -0400840 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -0400841}
842
Jamie Madilldc356042013-07-19 16:36:57 -0400843Sampler *Context::getSampler(GLuint handle) const
844{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500845 return mState.mSamplers->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400846}
847
Geoff Langc8058452014-02-03 12:04:11 -0500848TransformFeedback *Context::getTransformFeedback(GLuint handle) const
849{
Jamie Madill96a483b2017-06-27 16:49:21 -0400850 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -0500851}
852
Yunchao Hea336b902017-08-02 16:05:21 +0800853ProgramPipeline *Context::getProgramPipeline(GLuint handle) const
854{
855 return mState.mPipelines->getProgramPipeline(handle);
856}
857
Geoff Lang70d0f492015-12-10 17:45:46 -0500858LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
859{
860 switch (identifier)
861 {
862 case GL_BUFFER:
863 return getBuffer(name);
864 case GL_SHADER:
865 return getShader(name);
866 case GL_PROGRAM:
867 return getProgram(name);
868 case GL_VERTEX_ARRAY:
869 return getVertexArray(name);
870 case GL_QUERY:
871 return getQuery(name);
872 case GL_TRANSFORM_FEEDBACK:
873 return getTransformFeedback(name);
874 case GL_SAMPLER:
875 return getSampler(name);
876 case GL_TEXTURE:
877 return getTexture(name);
878 case GL_RENDERBUFFER:
879 return getRenderbuffer(name);
880 case GL_FRAMEBUFFER:
881 return getFramebuffer(name);
882 default:
883 UNREACHABLE();
884 return nullptr;
885 }
886}
887
888LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
889{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400890 return getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
Geoff Lang70d0f492015-12-10 17:45:46 -0500891}
892
Martin Radev9d901792016-07-15 15:58:58 +0300893void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
894{
895 LabeledObject *object = getLabeledObject(identifier, name);
896 ASSERT(object != nullptr);
897
898 std::string labelName = GetObjectLabelFromPointer(length, label);
899 object->setLabel(labelName);
Jamie Madill8693bdb2017-09-02 15:32:14 -0400900
901 // TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the
902 // specified object is active until we do this.
903 mGLState.setObjectDirty(identifier);
Martin Radev9d901792016-07-15 15:58:58 +0300904}
905
906void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
907{
908 LabeledObject *object = getLabeledObjectFromPtr(ptr);
909 ASSERT(object != nullptr);
910
911 std::string labelName = GetObjectLabelFromPointer(length, label);
912 object->setLabel(labelName);
913}
914
915void Context::getObjectLabel(GLenum identifier,
916 GLuint name,
917 GLsizei bufSize,
918 GLsizei *length,
919 GLchar *label) const
920{
921 LabeledObject *object = getLabeledObject(identifier, name);
922 ASSERT(object != nullptr);
923
924 const std::string &objectLabel = object->getLabel();
925 GetObjectLabelBase(objectLabel, bufSize, length, label);
926}
927
928void Context::getObjectPtrLabel(const void *ptr,
929 GLsizei bufSize,
930 GLsizei *length,
931 GLchar *label) const
932{
933 LabeledObject *object = getLabeledObjectFromPtr(ptr);
934 ASSERT(object != nullptr);
935
936 const std::string &objectLabel = object->getLabel();
937 GetObjectLabelBase(objectLabel, bufSize, length, label);
938}
939
Jamie Madilldc356042013-07-19 16:36:57 -0400940bool Context::isSampler(GLuint samplerName) const
941{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500942 return mState.mSamplers->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -0400943}
944
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500945void Context::bindArrayBuffer(GLuint bufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000946{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500947 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400948 mGLState.setArrayBufferBinding(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000949}
950
Jiajia Qin9d7d0b12016-11-29 16:30:31 +0800951void Context::bindDrawIndirectBuffer(GLuint bufferHandle)
952{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500953 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400954 mGLState.setDrawIndirectBufferBinding(this, buffer);
Jiajia Qin9d7d0b12016-11-29 16:30:31 +0800955}
956
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500957void Context::bindElementArrayBuffer(GLuint bufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000958{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500959 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400960 mGLState.setElementArrayBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000961}
962
Jamie Madilldedd7b92014-11-05 16:30:36 -0500963void Context::bindTexture(GLenum target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000964{
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500965 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000966
Jamie Madilldedd7b92014-11-05 16:30:36 -0500967 if (handle == 0)
968 {
969 texture = mZeroTextures[target].get();
970 }
971 else
972 {
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500973 texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500974 }
975
976 ASSERT(texture);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400977 mGLState.setSamplerTexture(this, target, texture);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +0000978}
979
Jamie Madill5bf9ff42016-02-01 11:13:03 -0500980void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000981{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500982 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
983 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700984 mGLState.setReadFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000985}
986
Jamie Madill5bf9ff42016-02-01 11:13:03 -0500987void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000988{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500989 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
990 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700991 mGLState.setDrawFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000992}
993
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500994void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -0400995{
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500996 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700997 mGLState.setVertexArrayBinding(vertexArray);
Jamie Madill57a89722013-07-02 11:57:03 -0400998}
999
Shao80957d92017-02-20 21:25:59 +08001000void Context::bindVertexBuffer(GLuint bindingIndex,
1001 GLuint bufferHandle,
1002 GLintptr offset,
1003 GLsizei stride)
1004{
1005 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001006 mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Shao80957d92017-02-20 21:25:59 +08001007}
1008
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001009void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -04001010{
Geoff Lang76b10c92014-09-05 16:28:14 -04001011 ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -04001012 Sampler *sampler =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001013 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001014 mGLState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04001015}
1016
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001017void Context::bindImageTexture(GLuint unit,
1018 GLuint texture,
1019 GLint level,
1020 GLboolean layered,
1021 GLint layer,
1022 GLenum access,
1023 GLenum format)
1024{
1025 Texture *tex = mState.mTextures->getTexture(texture);
1026 mGLState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
1027}
1028
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001029void Context::bindGenericUniformBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001030{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001031 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001032 mGLState.setGenericUniformBufferBinding(this, buffer);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001033}
1034
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001035void Context::bindIndexedUniformBuffer(GLuint bufferHandle,
1036 GLuint index,
1037 GLintptr offset,
1038 GLsizeiptr size)
shannon.woods%transgaming.com@gtempaccount.com34089352013-04-13 03:36:57 +00001039{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001040 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001041 mGLState.setIndexedUniformBufferBinding(this, index, buffer, offset, size);
shannon.woods%transgaming.com@gtempaccount.com34089352013-04-13 03:36:57 +00001042}
1043
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001044void Context::bindGenericTransformFeedbackBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001045{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001046 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001047 mGLState.getCurrentTransformFeedback()->bindGenericBuffer(this, buffer);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001048}
1049
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001050void Context::bindIndexedTransformFeedbackBuffer(GLuint bufferHandle,
1051 GLuint index,
1052 GLintptr offset,
1053 GLsizeiptr size)
shannon.woods%transgaming.com@gtempaccount.com34089352013-04-13 03:36:57 +00001054{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001055 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001056 mGLState.getCurrentTransformFeedback()->bindIndexedBuffer(this, index, buffer, offset, size);
shannon.woods%transgaming.com@gtempaccount.com34089352013-04-13 03:36:57 +00001057}
1058
Jiajia Qin6eafb042016-12-27 17:04:07 +08001059void Context::bindGenericAtomicCounterBuffer(GLuint bufferHandle)
1060{
1061 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001062 mGLState.setGenericAtomicCounterBufferBinding(this, buffer);
Jiajia Qin6eafb042016-12-27 17:04:07 +08001063}
1064
1065void Context::bindIndexedAtomicCounterBuffer(GLuint bufferHandle,
1066 GLuint index,
1067 GLintptr offset,
1068 GLsizeiptr size)
1069{
1070 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001071 mGLState.setIndexedAtomicCounterBufferBinding(this, index, buffer, offset, size);
Jiajia Qin6eafb042016-12-27 17:04:07 +08001072}
1073
Jiajia Qinf546e7d2017-03-27 14:12:59 +08001074void Context::bindGenericShaderStorageBuffer(GLuint bufferHandle)
1075{
1076 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001077 mGLState.setGenericShaderStorageBufferBinding(this, buffer);
Jiajia Qinf546e7d2017-03-27 14:12:59 +08001078}
1079
1080void Context::bindIndexedShaderStorageBuffer(GLuint bufferHandle,
1081 GLuint index,
1082 GLintptr offset,
1083 GLsizeiptr size)
1084{
1085 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001086 mGLState.setIndexedShaderStorageBufferBinding(this, index, buffer, offset, size);
Jiajia Qinf546e7d2017-03-27 14:12:59 +08001087}
1088
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001089void Context::bindCopyReadBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001090{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001091 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001092 mGLState.setCopyReadBufferBinding(this, buffer);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001093}
1094
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001095void Context::bindCopyWriteBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001096{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001097 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001098 mGLState.setCopyWriteBufferBinding(this, buffer);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001099}
1100
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001101void Context::bindPixelPackBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001102{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001103 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001104 mGLState.setPixelPackBufferBinding(this, buffer);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001105}
1106
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001107void Context::bindPixelUnpackBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001108{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001109 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001110 mGLState.setPixelUnpackBufferBinding(this, buffer);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001111}
1112
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001113void Context::useProgram(GLuint program)
1114{
Jamie Madill6c1f6712017-02-14 19:08:04 -05001115 mGLState.setProgram(this, getProgram(program));
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001116}
1117
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001118void Context::bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001119{
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001120 ASSERT(target == GL_TRANSFORM_FEEDBACK);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001121 TransformFeedback *transformFeedback =
1122 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001123 mGLState.setTransformFeedbackBinding(this, transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -05001124}
1125
Yunchao Hea336b902017-08-02 16:05:21 +08001126void Context::bindProgramPipeline(GLuint pipelineHandle)
1127{
1128 ProgramPipeline *pipeline =
1129 mState.mPipelines->checkProgramPipelineAllocation(mImplementation.get(), pipelineHandle);
1130 mGLState.setProgramPipelineBinding(this, pipeline);
1131}
1132
Jamie Madillf0e04492017-08-26 15:28:42 -04001133void Context::beginQuery(GLenum target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001134{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001135 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001136 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001137
Geoff Lang5aad9672014-09-08 11:10:42 -04001138 // begin query
Jamie Madillf0e04492017-08-26 15:28:42 -04001139 ANGLE_CONTEXT_TRY(queryObject->begin());
Geoff Lang5aad9672014-09-08 11:10:42 -04001140
1141 // set query as active for specified target only if begin succeeded
Jamie Madill4928b7c2017-06-20 12:57:39 -04001142 mGLState.setActiveQuery(this, target, queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001143}
1144
Jamie Madillf0e04492017-08-26 15:28:42 -04001145void Context::endQuery(GLenum target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001146{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001147 Query *queryObject = mGLState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001148 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001149
Jamie Madillf0e04492017-08-26 15:28:42 -04001150 handleError(queryObject->end());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001151
Geoff Lang5aad9672014-09-08 11:10:42 -04001152 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madill4928b7c2017-06-20 12:57:39 -04001153 mGLState.setActiveQuery(this, target, nullptr);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001154}
1155
Jamie Madillf0e04492017-08-26 15:28:42 -04001156void Context::queryCounter(GLuint id, GLenum target)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001157{
1158 ASSERT(target == GL_TIMESTAMP_EXT);
1159
1160 Query *queryObject = getQuery(id, true, target);
1161 ASSERT(queryObject);
1162
Jamie Madillf0e04492017-08-26 15:28:42 -04001163 handleError(queryObject->queryCounter());
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001164}
1165
1166void Context::getQueryiv(GLenum target, GLenum pname, GLint *params)
1167{
1168 switch (pname)
1169 {
1170 case GL_CURRENT_QUERY_EXT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001171 params[0] = mGLState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001172 break;
1173 case GL_QUERY_COUNTER_BITS_EXT:
1174 switch (target)
1175 {
1176 case GL_TIME_ELAPSED_EXT:
1177 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1178 break;
1179 case GL_TIMESTAMP_EXT:
1180 params[0] = getExtensions().queryCounterBitsTimestamp;
1181 break;
1182 default:
1183 UNREACHABLE();
1184 params[0] = 0;
1185 break;
1186 }
1187 break;
1188 default:
1189 UNREACHABLE();
1190 return;
1191 }
1192}
1193
Geoff Lang2186c382016-10-14 10:54:54 -04001194void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001195{
Geoff Lang2186c382016-10-14 10:54:54 -04001196 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001197}
1198
Geoff Lang2186c382016-10-14 10:54:54 -04001199void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001200{
Geoff Lang2186c382016-10-14 10:54:54 -04001201 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001202}
1203
Geoff Lang2186c382016-10-14 10:54:54 -04001204void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001205{
Geoff Lang2186c382016-10-14 10:54:54 -04001206 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001207}
1208
Geoff Lang2186c382016-10-14 10:54:54 -04001209void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001210{
Geoff Lang2186c382016-10-14 10:54:54 -04001211 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001212}
1213
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001214Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001215{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001216 return mState.mFramebuffers->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001217}
1218
Jamie Madill2f348d22017-06-05 10:50:59 -04001219FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001220{
Jamie Madill96a483b2017-06-27 16:49:21 -04001221 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001222}
1223
Jamie Madill2f348d22017-06-05 10:50:59 -04001224Query *Context::getQuery(GLuint handle, bool create, GLenum type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001225{
Jamie Madill96a483b2017-06-27 16:49:21 -04001226 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001227 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001228 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001229 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001230
1231 Query *query = mQueryMap.query(handle);
1232 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001233 {
Jamie Madill96a483b2017-06-27 16:49:21 -04001234 query = new Query(mImplementation->createQuery(type), handle);
1235 query->addRef();
1236 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001237 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001238 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001239}
1240
Geoff Lang70d0f492015-12-10 17:45:46 -05001241Query *Context::getQuery(GLuint handle) const
1242{
Jamie Madill96a483b2017-06-27 16:49:21 -04001243 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001244}
1245
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001246Texture *Context::getTargetTexture(GLenum target) const
1247{
Ian Ewellbda75592016-04-18 17:25:54 -04001248 ASSERT(ValidTextureTarget(this, target) || ValidTextureExternalTarget(this, target));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001249 return mGLState.getTargetTexture(target);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001250}
1251
Geoff Lang76b10c92014-09-05 16:28:14 -04001252Texture *Context::getSamplerTexture(unsigned int sampler, GLenum type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001253{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001254 return mGLState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001255}
1256
Geoff Lang492a7e42014-11-05 13:27:06 -05001257Compiler *Context::getCompiler() const
1258{
Jamie Madill2f348d22017-06-05 10:50:59 -04001259 if (mCompiler.get() == nullptr)
1260 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001261 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001262 }
1263 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001264}
1265
Jamie Madillc1d770e2017-04-13 17:31:24 -04001266void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001267{
1268 switch (pname)
1269 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001270 case GL_SHADER_COMPILER:
1271 *params = GL_TRUE;
1272 break;
1273 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1274 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1275 break;
1276 default:
1277 mGLState.getBooleanv(pname, params);
1278 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001279 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001280}
1281
Jamie Madillc1d770e2017-04-13 17:31:24 -04001282void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001283{
Shannon Woods53a94a82014-06-24 15:20:36 -04001284 // Queries about context capabilities and maximums are answered by Context.
1285 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001286 switch (pname)
1287 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001288 case GL_ALIASED_LINE_WIDTH_RANGE:
1289 params[0] = mCaps.minAliasedLineWidth;
1290 params[1] = mCaps.maxAliasedLineWidth;
1291 break;
1292 case GL_ALIASED_POINT_SIZE_RANGE:
1293 params[0] = mCaps.minAliasedPointSize;
1294 params[1] = mCaps.maxAliasedPointSize;
1295 break;
1296 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1297 ASSERT(mExtensions.textureFilterAnisotropic);
1298 *params = mExtensions.maxTextureAnisotropy;
1299 break;
1300 case GL_MAX_TEXTURE_LOD_BIAS:
1301 *params = mCaps.maxLODBias;
1302 break;
1303
1304 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1305 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1306 {
1307 ASSERT(mExtensions.pathRendering);
1308 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1309 memcpy(params, m, 16 * sizeof(GLfloat));
1310 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001311 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001312
Jamie Madill231c7f52017-04-26 13:45:37 -04001313 default:
1314 mGLState.getFloatv(pname, params);
1315 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001316 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001317}
1318
Jamie Madillc1d770e2017-04-13 17:31:24 -04001319void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001320{
Shannon Woods53a94a82014-06-24 15:20:36 -04001321 // Queries about context capabilities and maximums are answered by Context.
1322 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001323
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001324 switch (pname)
1325 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001326 case GL_MAX_VERTEX_ATTRIBS:
1327 *params = mCaps.maxVertexAttributes;
1328 break;
1329 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1330 *params = mCaps.maxVertexUniformVectors;
1331 break;
1332 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
1333 *params = mCaps.maxVertexUniformComponents;
1334 break;
1335 case GL_MAX_VARYING_VECTORS:
1336 *params = mCaps.maxVaryingVectors;
1337 break;
1338 case GL_MAX_VARYING_COMPONENTS:
1339 *params = mCaps.maxVertexOutputComponents;
1340 break;
1341 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1342 *params = mCaps.maxCombinedTextureImageUnits;
1343 break;
1344 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
1345 *params = mCaps.maxVertexTextureImageUnits;
1346 break;
1347 case GL_MAX_TEXTURE_IMAGE_UNITS:
1348 *params = mCaps.maxTextureImageUnits;
1349 break;
1350 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1351 *params = mCaps.maxFragmentUniformVectors;
1352 break;
1353 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
1354 *params = mCaps.maxFragmentUniformComponents;
1355 break;
1356 case GL_MAX_RENDERBUFFER_SIZE:
1357 *params = mCaps.maxRenderbufferSize;
1358 break;
1359 case GL_MAX_COLOR_ATTACHMENTS_EXT:
1360 *params = mCaps.maxColorAttachments;
1361 break;
1362 case GL_MAX_DRAW_BUFFERS_EXT:
1363 *params = mCaps.maxDrawBuffers;
1364 break;
1365 // case GL_FRAMEBUFFER_BINDING: // now equivalent to
1366 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
1367 case GL_SUBPIXEL_BITS:
1368 *params = 4;
1369 break;
1370 case GL_MAX_TEXTURE_SIZE:
1371 *params = mCaps.max2DTextureSize;
1372 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001373 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
1374 *params = mCaps.maxRectangleTextureSize;
1375 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001376 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1377 *params = mCaps.maxCubeMapTextureSize;
1378 break;
1379 case GL_MAX_3D_TEXTURE_SIZE:
1380 *params = mCaps.max3DTextureSize;
1381 break;
1382 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1383 *params = mCaps.maxArrayTextureLayers;
1384 break;
1385 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1386 *params = mCaps.uniformBufferOffsetAlignment;
1387 break;
1388 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1389 *params = mCaps.maxUniformBufferBindings;
1390 break;
1391 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
1392 *params = mCaps.maxVertexUniformBlocks;
1393 break;
1394 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
1395 *params = mCaps.maxFragmentUniformBlocks;
1396 break;
1397 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1398 *params = mCaps.maxCombinedTextureImageUnits;
1399 break;
1400 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1401 *params = mCaps.maxVertexOutputComponents;
1402 break;
1403 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1404 *params = mCaps.maxFragmentInputComponents;
1405 break;
1406 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1407 *params = mCaps.minProgramTexelOffset;
1408 break;
1409 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1410 *params = mCaps.maxProgramTexelOffset;
1411 break;
1412 case GL_MAJOR_VERSION:
1413 *params = getClientVersion().major;
1414 break;
1415 case GL_MINOR_VERSION:
1416 *params = getClientVersion().minor;
1417 break;
1418 case GL_MAX_ELEMENTS_INDICES:
1419 *params = mCaps.maxElementsIndices;
1420 break;
1421 case GL_MAX_ELEMENTS_VERTICES:
1422 *params = mCaps.maxElementsVertices;
1423 break;
1424 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1425 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1426 break;
1427 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1428 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1429 break;
1430 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1431 *params = mCaps.maxTransformFeedbackSeparateComponents;
1432 break;
1433 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1434 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1435 break;
1436 case GL_MAX_SAMPLES_ANGLE:
1437 *params = mCaps.maxSamples;
1438 break;
1439 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001440 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001441 params[0] = mCaps.maxViewportWidth;
1442 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001443 }
1444 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001445 case GL_COMPRESSED_TEXTURE_FORMATS:
1446 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1447 params);
1448 break;
1449 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1450 *params = mResetStrategy;
1451 break;
1452 case GL_NUM_SHADER_BINARY_FORMATS:
1453 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1454 break;
1455 case GL_SHADER_BINARY_FORMATS:
1456 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1457 break;
1458 case GL_NUM_PROGRAM_BINARY_FORMATS:
1459 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1460 break;
1461 case GL_PROGRAM_BINARY_FORMATS:
1462 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1463 break;
1464 case GL_NUM_EXTENSIONS:
1465 *params = static_cast<GLint>(mExtensionStrings.size());
1466 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001467
Jamie Madill231c7f52017-04-26 13:45:37 -04001468 // GL_KHR_debug
1469 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1470 *params = mExtensions.maxDebugMessageLength;
1471 break;
1472 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1473 *params = mExtensions.maxDebugLoggedMessages;
1474 break;
1475 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1476 *params = mExtensions.maxDebugGroupStackDepth;
1477 break;
1478 case GL_MAX_LABEL_LENGTH:
1479 *params = mExtensions.maxLabelLength;
1480 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001481
Martin Radeve5285d22017-07-14 16:23:53 +03001482 // GL_ANGLE_multiview
1483 case GL_MAX_VIEWS_ANGLE:
1484 *params = mExtensions.maxViews;
1485 break;
1486
Jamie Madill231c7f52017-04-26 13:45:37 -04001487 // GL_EXT_disjoint_timer_query
1488 case GL_GPU_DISJOINT_EXT:
1489 *params = mImplementation->getGPUDisjoint();
1490 break;
1491 case GL_MAX_FRAMEBUFFER_WIDTH:
1492 *params = mCaps.maxFramebufferWidth;
1493 break;
1494 case GL_MAX_FRAMEBUFFER_HEIGHT:
1495 *params = mCaps.maxFramebufferHeight;
1496 break;
1497 case GL_MAX_FRAMEBUFFER_SAMPLES:
1498 *params = mCaps.maxFramebufferSamples;
1499 break;
1500 case GL_MAX_SAMPLE_MASK_WORDS:
1501 *params = mCaps.maxSampleMaskWords;
1502 break;
1503 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1504 *params = mCaps.maxColorTextureSamples;
1505 break;
1506 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1507 *params = mCaps.maxDepthTextureSamples;
1508 break;
1509 case GL_MAX_INTEGER_SAMPLES:
1510 *params = mCaps.maxIntegerSamples;
1511 break;
1512 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1513 *params = mCaps.maxVertexAttribRelativeOffset;
1514 break;
1515 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1516 *params = mCaps.maxVertexAttribBindings;
1517 break;
1518 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1519 *params = mCaps.maxVertexAttribStride;
1520 break;
1521 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
1522 *params = mCaps.maxVertexAtomicCounterBuffers;
1523 break;
1524 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
1525 *params = mCaps.maxVertexAtomicCounters;
1526 break;
1527 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
1528 *params = mCaps.maxVertexImageUniforms;
1529 break;
1530 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
1531 *params = mCaps.maxVertexShaderStorageBlocks;
1532 break;
1533 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
1534 *params = mCaps.maxFragmentAtomicCounterBuffers;
1535 break;
1536 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
1537 *params = mCaps.maxFragmentAtomicCounters;
1538 break;
1539 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
1540 *params = mCaps.maxFragmentImageUniforms;
1541 break;
1542 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
1543 *params = mCaps.maxFragmentShaderStorageBlocks;
1544 break;
1545 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1546 *params = mCaps.minProgramTextureGatherOffset;
1547 break;
1548 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1549 *params = mCaps.maxProgramTextureGatherOffset;
1550 break;
1551 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1552 *params = mCaps.maxComputeWorkGroupInvocations;
1553 break;
1554 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
1555 *params = mCaps.maxComputeUniformBlocks;
1556 break;
1557 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
1558 *params = mCaps.maxComputeTextureImageUnits;
1559 break;
1560 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1561 *params = mCaps.maxComputeSharedMemorySize;
1562 break;
1563 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
1564 *params = mCaps.maxComputeUniformComponents;
1565 break;
1566 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
1567 *params = mCaps.maxComputeAtomicCounterBuffers;
1568 break;
1569 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
1570 *params = mCaps.maxComputeAtomicCounters;
1571 break;
1572 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
1573 *params = mCaps.maxComputeImageUniforms;
1574 break;
1575 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
1576 *params = mCaps.maxCombinedComputeUniformComponents;
1577 break;
1578 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
1579 *params = mCaps.maxComputeShaderStorageBlocks;
1580 break;
1581 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1582 *params = mCaps.maxCombinedShaderOutputResources;
1583 break;
1584 case GL_MAX_UNIFORM_LOCATIONS:
1585 *params = mCaps.maxUniformLocations;
1586 break;
1587 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1588 *params = mCaps.maxAtomicCounterBufferBindings;
1589 break;
1590 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1591 *params = mCaps.maxAtomicCounterBufferSize;
1592 break;
1593 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1594 *params = mCaps.maxCombinedAtomicCounterBuffers;
1595 break;
1596 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1597 *params = mCaps.maxCombinedAtomicCounters;
1598 break;
1599 case GL_MAX_IMAGE_UNITS:
1600 *params = mCaps.maxImageUnits;
1601 break;
1602 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1603 *params = mCaps.maxCombinedImageUniforms;
1604 break;
1605 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1606 *params = mCaps.maxShaderStorageBufferBindings;
1607 break;
1608 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1609 *params = mCaps.maxCombinedShaderStorageBlocks;
1610 break;
1611 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1612 *params = mCaps.shaderStorageBufferOffsetAlignment;
1613 break;
1614 default:
1615 mGLState.getIntegerv(this, pname, params);
1616 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001617 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001618}
1619
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001620void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001621{
Shannon Woods53a94a82014-06-24 15:20:36 -04001622 // Queries about context capabilities and maximums are answered by Context.
1623 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001624 switch (pname)
1625 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001626 case GL_MAX_ELEMENT_INDEX:
1627 *params = mCaps.maxElementIndex;
1628 break;
1629 case GL_MAX_UNIFORM_BLOCK_SIZE:
1630 *params = mCaps.maxUniformBlockSize;
1631 break;
1632 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
1633 *params = mCaps.maxCombinedVertexUniformComponents;
1634 break;
1635 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
1636 *params = mCaps.maxCombinedFragmentUniformComponents;
1637 break;
1638 case GL_MAX_SERVER_WAIT_TIMEOUT:
1639 *params = mCaps.maxServerWaitTimeout;
1640 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001641
Jamie Madill231c7f52017-04-26 13:45:37 -04001642 // GL_EXT_disjoint_timer_query
1643 case GL_TIMESTAMP_EXT:
1644 *params = mImplementation->getTimestamp();
1645 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001646
Jamie Madill231c7f52017-04-26 13:45:37 -04001647 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1648 *params = mCaps.maxShaderStorageBlockSize;
1649 break;
1650 default:
1651 UNREACHABLE();
1652 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001653 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001654}
1655
Geoff Lang70d0f492015-12-10 17:45:46 -05001656void Context::getPointerv(GLenum pname, void **params) const
1657{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001658 mGLState.getPointerv(pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001659}
1660
Martin Radev66fb8202016-07-28 11:45:20 +03001661void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001662{
Shannon Woods53a94a82014-06-24 15:20:36 -04001663 // Queries about context capabilities and maximums are answered by Context.
1664 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001665
1666 GLenum nativeType;
1667 unsigned int numParams;
1668 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1669 ASSERT(queryStatus);
1670
1671 if (nativeType == GL_INT)
1672 {
1673 switch (target)
1674 {
1675 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1676 ASSERT(index < 3u);
1677 *data = mCaps.maxComputeWorkGroupCount[index];
1678 break;
1679 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1680 ASSERT(index < 3u);
1681 *data = mCaps.maxComputeWorkGroupSize[index];
1682 break;
1683 default:
1684 mGLState.getIntegeri_v(target, index, data);
1685 }
1686 }
1687 else
1688 {
1689 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1690 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001691}
1692
Martin Radev66fb8202016-07-28 11:45:20 +03001693void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001694{
Shannon Woods53a94a82014-06-24 15:20:36 -04001695 // Queries about context capabilities and maximums are answered by Context.
1696 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001697
1698 GLenum nativeType;
1699 unsigned int numParams;
1700 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1701 ASSERT(queryStatus);
1702
1703 if (nativeType == GL_INT_64_ANGLEX)
1704 {
1705 mGLState.getInteger64i_v(target, index, data);
1706 }
1707 else
1708 {
1709 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1710 }
1711}
1712
1713void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1714{
1715 // Queries about context capabilities and maximums are answered by Context.
1716 // Queries about current GL state values are answered by State.
1717
1718 GLenum nativeType;
1719 unsigned int numParams;
1720 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1721 ASSERT(queryStatus);
1722
1723 if (nativeType == GL_BOOL)
1724 {
1725 mGLState.getBooleani_v(target, index, data);
1726 }
1727 else
1728 {
1729 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1730 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001731}
1732
He Yunchao010e4db2017-03-03 14:22:06 +08001733void Context::getBufferParameteriv(GLenum target, GLenum pname, GLint *params)
1734{
1735 Buffer *buffer = mGLState.getTargetBuffer(target);
1736 QueryBufferParameteriv(buffer, pname, params);
1737}
1738
1739void Context::getFramebufferAttachmentParameteriv(GLenum target,
1740 GLenum attachment,
1741 GLenum pname,
1742 GLint *params)
1743{
1744 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
1745 QueryFramebufferAttachmentParameteriv(framebuffer, attachment, pname, params);
1746}
1747
1748void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
1749{
1750 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
1751 QueryRenderbufferiv(this, renderbuffer, pname, params);
1752}
1753
1754void Context::getTexParameterfv(GLenum target, GLenum pname, GLfloat *params)
1755{
1756 Texture *texture = getTargetTexture(target);
1757 QueryTexParameterfv(texture, pname, params);
1758}
1759
1760void Context::getTexParameteriv(GLenum target, GLenum pname, GLint *params)
1761{
1762 Texture *texture = getTargetTexture(target);
1763 QueryTexParameteriv(texture, pname, params);
1764}
1765void Context::texParameterf(GLenum target, GLenum pname, GLfloat param)
1766{
1767 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001768 SetTexParameterf(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04001769 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001770}
1771
1772void Context::texParameterfv(GLenum target, GLenum pname, const GLfloat *params)
1773{
1774 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001775 SetTexParameterfv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04001776 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001777}
1778
1779void Context::texParameteri(GLenum target, GLenum pname, GLint param)
1780{
1781 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001782 SetTexParameteri(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04001783 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001784}
1785
1786void Context::texParameteriv(GLenum target, GLenum pname, const GLint *params)
1787{
1788 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001789 SetTexParameteriv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04001790 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001791}
1792
Jamie Madill675fe712016-12-19 13:07:54 -05001793void Context::drawArrays(GLenum mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001794{
Jamie Madill05b35b22017-10-03 09:01:44 -04001795 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001796 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
1797 MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001798}
1799
Jamie Madill675fe712016-12-19 13:07:54 -05001800void Context::drawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04001801{
Jamie Madill05b35b22017-10-03 09:01:44 -04001802 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001803 ANGLE_CONTEXT_TRY(
1804 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
1805 MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback());
Geoff Langf6db0982015-08-25 13:04:00 -04001806}
1807
Jamie Madill876429b2017-04-20 15:46:24 -04001808void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001809{
Jamie Madill05b35b22017-10-03 09:01:44 -04001810 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001811 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04001812}
1813
Jamie Madill675fe712016-12-19 13:07:54 -05001814void Context::drawElementsInstanced(GLenum mode,
1815 GLsizei count,
1816 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04001817 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04001818 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04001819{
Jamie Madill05b35b22017-10-03 09:01:44 -04001820 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001821 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08001822 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04001823}
1824
Jamie Madill675fe712016-12-19 13:07:54 -05001825void Context::drawRangeElements(GLenum mode,
1826 GLuint start,
1827 GLuint end,
1828 GLsizei count,
1829 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04001830 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04001831{
Jamie Madill05b35b22017-10-03 09:01:44 -04001832 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001833 ANGLE_CONTEXT_TRY(
1834 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001835}
1836
Jamie Madill876429b2017-04-20 15:46:24 -04001837void Context::drawArraysIndirect(GLenum mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08001838{
Jamie Madill05b35b22017-10-03 09:01:44 -04001839 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001840 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08001841}
1842
Jamie Madill876429b2017-04-20 15:46:24 -04001843void Context::drawElementsIndirect(GLenum mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08001844{
Jamie Madill05b35b22017-10-03 09:01:44 -04001845 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001846 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08001847}
1848
Jamie Madill675fe712016-12-19 13:07:54 -05001849void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001850{
Jamie Madill675fe712016-12-19 13:07:54 -05001851 handleError(mImplementation->flush());
Geoff Lang129753a2015-01-09 16:52:09 -05001852}
1853
Jamie Madill675fe712016-12-19 13:07:54 -05001854void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05001855{
Jamie Madill675fe712016-12-19 13:07:54 -05001856 handleError(mImplementation->finish());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001857}
1858
Austin Kinross6ee1e782015-05-29 17:05:37 -07001859void Context::insertEventMarker(GLsizei length, const char *marker)
1860{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001861 ASSERT(mImplementation);
1862 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07001863}
1864
1865void Context::pushGroupMarker(GLsizei length, const char *marker)
1866{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001867 ASSERT(mImplementation);
1868 mImplementation->pushGroupMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07001869}
1870
1871void Context::popGroupMarker()
1872{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001873 ASSERT(mImplementation);
1874 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07001875}
1876
Geoff Langd8605522016-04-13 10:19:12 -04001877void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
1878{
1879 Program *programObject = getProgram(program);
1880 ASSERT(programObject);
1881
1882 programObject->bindUniformLocation(location, name);
1883}
1884
Sami Väisänena797e062016-05-12 15:23:40 +03001885void Context::setCoverageModulation(GLenum components)
1886{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001887 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03001888}
1889
Sami Väisänene45e53b2016-05-25 10:36:04 +03001890void Context::loadPathRenderingMatrix(GLenum matrixMode, const GLfloat *matrix)
1891{
1892 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
1893}
1894
1895void Context::loadPathRenderingIdentityMatrix(GLenum matrixMode)
1896{
1897 GLfloat I[16];
1898 angle::Matrix<GLfloat>::setToIdentity(I);
1899
1900 mGLState.loadPathRenderingMatrix(matrixMode, I);
1901}
1902
1903void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
1904{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001905 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001906 if (!pathObj)
1907 return;
1908
1909 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1910 syncRendererState();
1911
1912 mImplementation->stencilFillPath(pathObj, fillMode, mask);
1913}
1914
1915void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
1916{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001917 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001918 if (!pathObj)
1919 return;
1920
1921 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1922 syncRendererState();
1923
1924 mImplementation->stencilStrokePath(pathObj, reference, mask);
1925}
1926
1927void Context::coverFillPath(GLuint path, GLenum coverMode)
1928{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001929 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001930 if (!pathObj)
1931 return;
1932
1933 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1934 syncRendererState();
1935
1936 mImplementation->coverFillPath(pathObj, coverMode);
1937}
1938
1939void Context::coverStrokePath(GLuint path, GLenum coverMode)
1940{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001941 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001942 if (!pathObj)
1943 return;
1944
1945 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1946 syncRendererState();
1947
1948 mImplementation->coverStrokePath(pathObj, coverMode);
1949}
1950
1951void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
1952{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001953 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001954 if (!pathObj)
1955 return;
1956
1957 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1958 syncRendererState();
1959
1960 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
1961}
1962
1963void Context::stencilThenCoverStrokePath(GLuint path,
1964 GLint reference,
1965 GLuint mask,
1966 GLenum coverMode)
1967{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001968 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001969 if (!pathObj)
1970 return;
1971
1972 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1973 syncRendererState();
1974
1975 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
1976}
1977
Sami Väisänend59ca052016-06-21 16:10:00 +03001978void Context::coverFillPathInstanced(GLsizei numPaths,
1979 GLenum pathNameType,
1980 const void *paths,
1981 GLuint pathBase,
1982 GLenum coverMode,
1983 GLenum transformType,
1984 const GLfloat *transformValues)
1985{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001986 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03001987
1988 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1989 syncRendererState();
1990
1991 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
1992}
Sami Väisänen46eaa942016-06-29 10:26:37 +03001993
Sami Väisänend59ca052016-06-21 16:10:00 +03001994void Context::coverStrokePathInstanced(GLsizei numPaths,
1995 GLenum pathNameType,
1996 const void *paths,
1997 GLuint pathBase,
1998 GLenum coverMode,
1999 GLenum transformType,
2000 const GLfloat *transformValues)
2001{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002002 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002003
2004 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2005 syncRendererState();
2006
2007 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2008 transformValues);
2009}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002010
Sami Väisänend59ca052016-06-21 16:10:00 +03002011void Context::stencilFillPathInstanced(GLsizei numPaths,
2012 GLenum pathNameType,
2013 const void *paths,
2014 GLuint pathBase,
2015 GLenum fillMode,
2016 GLuint mask,
2017 GLenum transformType,
2018 const GLfloat *transformValues)
2019{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002020 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002021
2022 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2023 syncRendererState();
2024
2025 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2026 transformValues);
2027}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002028
Sami Väisänend59ca052016-06-21 16:10:00 +03002029void Context::stencilStrokePathInstanced(GLsizei numPaths,
2030 GLenum pathNameType,
2031 const void *paths,
2032 GLuint pathBase,
2033 GLint reference,
2034 GLuint mask,
2035 GLenum transformType,
2036 const GLfloat *transformValues)
2037{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002038 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002039
2040 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2041 syncRendererState();
2042
2043 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2044 transformValues);
2045}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002046
Sami Väisänend59ca052016-06-21 16:10:00 +03002047void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2048 GLenum pathNameType,
2049 const void *paths,
2050 GLuint pathBase,
2051 GLenum fillMode,
2052 GLuint mask,
2053 GLenum coverMode,
2054 GLenum transformType,
2055 const GLfloat *transformValues)
2056{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002057 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002058
2059 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2060 syncRendererState();
2061
2062 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2063 transformType, transformValues);
2064}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002065
Sami Väisänend59ca052016-06-21 16:10:00 +03002066void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2067 GLenum pathNameType,
2068 const void *paths,
2069 GLuint pathBase,
2070 GLint reference,
2071 GLuint mask,
2072 GLenum coverMode,
2073 GLenum transformType,
2074 const GLfloat *transformValues)
2075{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002076 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002077
2078 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2079 syncRendererState();
2080
2081 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2082 transformType, transformValues);
2083}
2084
Sami Väisänen46eaa942016-06-29 10:26:37 +03002085void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2086{
2087 auto *programObject = getProgram(program);
2088
2089 programObject->bindFragmentInputLocation(location, name);
2090}
2091
2092void Context::programPathFragmentInputGen(GLuint program,
2093 GLint location,
2094 GLenum genMode,
2095 GLint components,
2096 const GLfloat *coeffs)
2097{
2098 auto *programObject = getProgram(program);
2099
Jamie Madillbd044ed2017-06-05 12:59:21 -04002100 programObject->pathFragmentInputGen(this, location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002101}
2102
jchen1015015f72017-03-16 13:54:21 +08002103GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2104{
jchen10fd7c3b52017-03-21 15:36:03 +08002105 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002106 return QueryProgramResourceIndex(programObject, programInterface, name);
2107}
2108
jchen10fd7c3b52017-03-21 15:36:03 +08002109void Context::getProgramResourceName(GLuint program,
2110 GLenum programInterface,
2111 GLuint index,
2112 GLsizei bufSize,
2113 GLsizei *length,
2114 GLchar *name)
2115{
2116 const auto *programObject = getProgram(program);
2117 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2118}
2119
jchen10191381f2017-04-11 13:59:04 +08002120GLint Context::getProgramResourceLocation(GLuint program,
2121 GLenum programInterface,
2122 const GLchar *name)
2123{
2124 const auto *programObject = getProgram(program);
2125 return QueryProgramResourceLocation(programObject, programInterface, name);
2126}
2127
jchen10880683b2017-04-12 16:21:55 +08002128void Context::getProgramResourceiv(GLuint program,
2129 GLenum programInterface,
2130 GLuint index,
2131 GLsizei propCount,
2132 const GLenum *props,
2133 GLsizei bufSize,
2134 GLsizei *length,
2135 GLint *params)
2136{
2137 const auto *programObject = getProgram(program);
2138 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2139 length, params);
2140}
2141
jchen10d9cd7b72017-08-30 15:04:25 +08002142void Context::getProgramInterfaceiv(GLuint program,
2143 GLenum programInterface,
2144 GLenum pname,
2145 GLint *params)
2146{
2147 const auto *programObject = getProgram(program);
2148 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2149}
2150
Jamie Madill71c88b32017-09-14 22:20:29 -04002151void Context::handleError(const Error &error)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002152{
Geoff Langda5777c2014-07-11 09:52:58 -04002153 if (error.isError())
2154 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002155 GLenum code = error.getCode();
2156 mErrors.insert(code);
2157 if (code == GL_OUT_OF_MEMORY && getWorkarounds().loseContextOnOutOfMemory)
2158 {
2159 markContextLost();
2160 }
Geoff Lang70d0f492015-12-10 17:45:46 -05002161
2162 if (!error.getMessage().empty())
2163 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002164 auto *debug = &mGLState.getDebug();
2165 debug->insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, error.getID(),
2166 GL_DEBUG_SEVERITY_HIGH, error.getMessage());
Geoff Lang70d0f492015-12-10 17:45:46 -05002167 }
Geoff Langda5777c2014-07-11 09:52:58 -04002168 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002169}
2170
2171// Get one of the recorded errors and clear its flag, if any.
2172// [OpenGL ES 2.0.24] section 2.5 page 13.
2173GLenum Context::getError()
2174{
Geoff Langda5777c2014-07-11 09:52:58 -04002175 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002176 {
Geoff Langda5777c2014-07-11 09:52:58 -04002177 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002178 }
Geoff Langda5777c2014-07-11 09:52:58 -04002179 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002180 {
Geoff Langda5777c2014-07-11 09:52:58 -04002181 GLenum error = *mErrors.begin();
2182 mErrors.erase(mErrors.begin());
2183 return error;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002184 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002185}
2186
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002187// NOTE: this function should not assume that this context is current!
2188void Context::markContextLost()
2189{
2190 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002191 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002192 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002193 mContextLostForced = true;
2194 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002195 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002196}
2197
2198bool Context::isContextLost()
2199{
2200 return mContextLost;
2201}
2202
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002203GLenum Context::getResetStatus()
2204{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002205 // Even if the application doesn't want to know about resets, we want to know
2206 // as it will allow us to skip all the calls.
2207 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002208 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002209 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002210 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002211 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002212 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002213
2214 // EXT_robustness, section 2.6: If the reset notification behavior is
2215 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2216 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2217 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002218 }
2219
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002220 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2221 // status should be returned at least once, and GL_NO_ERROR should be returned
2222 // once the device has finished resetting.
2223 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002224 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002225 ASSERT(mResetStatus == GL_NO_ERROR);
2226 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002227
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002228 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002229 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002230 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002231 }
2232 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002233 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002234 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002235 // If markContextLost was used to mark the context lost then
2236 // assume that is not recoverable, and continue to report the
2237 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002238 mResetStatus = mImplementation->getResetStatus();
2239 }
Jamie Madill893ab082014-05-16 16:56:10 -04002240
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002241 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002242}
2243
2244bool Context::isResetNotificationEnabled()
2245{
2246 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2247}
2248
Corentin Walleze3b10e82015-05-20 11:06:25 -04002249const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002250{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002251 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002252}
2253
2254EGLenum Context::getClientType() const
2255{
2256 return mClientType;
2257}
2258
2259EGLenum Context::getRenderBuffer() const
2260{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002261 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2262 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002263 {
2264 return EGL_NONE;
2265 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002266
2267 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(GL_BACK);
2268 ASSERT(backAttachment != nullptr);
2269 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002270}
2271
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002272VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002273{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002274 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002275 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2276 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002277 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002278 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2279 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002280
Jamie Madill96a483b2017-06-27 16:49:21 -04002281 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002282 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002283
2284 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002285}
2286
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002287TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002288{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002289 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002290 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2291 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002292 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002293 transformFeedback =
2294 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002295 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002296 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002297 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002298
2299 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002300}
2301
2302bool Context::isVertexArrayGenerated(GLuint vertexArray)
2303{
Jamie Madill96a483b2017-06-27 16:49:21 -04002304 ASSERT(mVertexArrayMap.contains(0));
2305 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002306}
2307
2308bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2309{
Jamie Madill96a483b2017-06-27 16:49:21 -04002310 ASSERT(mTransformFeedbackMap.contains(0));
2311 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002312}
2313
Shannon Woods53a94a82014-06-24 15:20:36 -04002314void Context::detachTexture(GLuint texture)
2315{
2316 // Simple pass-through to State's detachTexture method, as textures do not require
2317 // allocation map management either here or in the resource manager at detach time.
2318 // Zero textures are held by the Context, and we don't attempt to request them from
2319 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002320 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002321}
2322
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002323void Context::detachBuffer(GLuint buffer)
2324{
Yuly Novikov5807a532015-12-03 13:01:22 -05002325 // Simple pass-through to State's detachBuffer method, since
2326 // only buffer attachments to container objects that are bound to the current context
2327 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002328
Yuly Novikov5807a532015-12-03 13:01:22 -05002329 // [OpenGL ES 3.2] section 5.1.2 page 45:
2330 // Attachments to unbound container objects, such as
2331 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2332 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002333 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002334}
2335
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002336void Context::detachFramebuffer(GLuint framebuffer)
2337{
Shannon Woods53a94a82014-06-24 15:20:36 -04002338 // Framebuffer detachment is handled by Context, because 0 is a valid
2339 // Framebuffer object, and a pointer to it must be passed from Context
2340 // to State at binding time.
2341
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002342 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002343 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2344 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2345 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002346
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002347 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002348 {
2349 bindReadFramebuffer(0);
2350 }
2351
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002352 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002353 {
2354 bindDrawFramebuffer(0);
2355 }
2356}
2357
2358void Context::detachRenderbuffer(GLuint renderbuffer)
2359{
Jamie Madilla02315b2017-02-23 14:14:47 -05002360 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002361}
2362
Jamie Madill57a89722013-07-02 11:57:03 -04002363void Context::detachVertexArray(GLuint vertexArray)
2364{
Jamie Madill77a72f62015-04-14 11:18:32 -04002365 // Vertex array detachment is handled by Context, because 0 is a valid
2366 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002367 // binding time.
2368
Jamie Madill57a89722013-07-02 11:57:03 -04002369 // [OpenGL ES 3.0.2] section 2.10 page 43:
2370 // If a vertex array object that is currently bound is deleted, the binding
2371 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002372 if (mGLState.removeVertexArrayBinding(vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002373 {
2374 bindVertexArray(0);
2375 }
2376}
2377
Geoff Langc8058452014-02-03 12:04:11 -05002378void Context::detachTransformFeedback(GLuint transformFeedback)
2379{
Corentin Walleza2257da2016-04-19 16:43:12 -04002380 // Transform feedback detachment is handled by Context, because 0 is a valid
2381 // transform feedback, and a pointer to it must be passed from Context to State at
2382 // binding time.
2383
2384 // The OpenGL specification doesn't mention what should happen when the currently bound
2385 // transform feedback object is deleted. Since it is a container object, we treat it like
2386 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002387 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002388 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002389 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002390 }
Geoff Langc8058452014-02-03 12:04:11 -05002391}
2392
Jamie Madilldc356042013-07-19 16:36:57 -04002393void Context::detachSampler(GLuint sampler)
2394{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002395 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002396}
2397
Yunchao Hea336b902017-08-02 16:05:21 +08002398void Context::detachProgramPipeline(GLuint pipeline)
2399{
2400 mGLState.detachProgramPipeline(this, pipeline);
2401}
2402
Jamie Madill3ef140a2017-08-26 23:11:21 -04002403void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002404{
Shaodde78e82017-05-22 14:13:27 +08002405 mGLState.setVertexAttribDivisor(this, index, divisor);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002406}
2407
Jamie Madille29d1672013-07-19 16:36:57 -04002408void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2409{
Geoff Langc1984ed2016-10-07 12:41:00 -04002410 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002411 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002412 SetSamplerParameteri(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002413 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002414}
Jamie Madille29d1672013-07-19 16:36:57 -04002415
Geoff Langc1984ed2016-10-07 12:41:00 -04002416void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2417{
2418 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002419 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002420 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002421 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002422}
2423
2424void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2425{
Geoff Langc1984ed2016-10-07 12:41:00 -04002426 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002427 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002428 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002429 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002430}
2431
Geoff Langc1984ed2016-10-07 12:41:00 -04002432void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002433{
Geoff Langc1984ed2016-10-07 12:41:00 -04002434 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002435 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002436 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002437 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002438}
2439
Geoff Langc1984ed2016-10-07 12:41:00 -04002440void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002441{
Geoff Langc1984ed2016-10-07 12:41:00 -04002442 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002443 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002444 QuerySamplerParameteriv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002445 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002446}
Jamie Madill9675b802013-07-19 16:36:59 -04002447
Geoff Langc1984ed2016-10-07 12:41:00 -04002448void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2449{
2450 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002451 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002452 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002453 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002454}
2455
Olli Etuahof0fee072016-03-30 15:11:58 +03002456void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2457{
2458 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002459 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002460}
2461
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002462void Context::initRendererString()
2463{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002464 std::ostringstream rendererString;
2465 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002466 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002467 rendererString << ")";
2468
Geoff Langcec35902014-04-16 10:52:36 -04002469 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002470}
2471
Geoff Langc339c4e2016-11-29 10:37:36 -05002472void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002473{
Geoff Langc339c4e2016-11-29 10:37:36 -05002474 const Version &clientVersion = getClientVersion();
2475
2476 std::ostringstream versionString;
2477 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2478 << ANGLE_VERSION_STRING << ")";
2479 mVersionString = MakeStaticString(versionString.str());
2480
2481 std::ostringstream shadingLanguageVersionString;
2482 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2483 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2484 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2485 << ")";
2486 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002487}
2488
Geoff Langcec35902014-04-16 10:52:36 -04002489void Context::initExtensionStrings()
2490{
Geoff Langc339c4e2016-11-29 10:37:36 -05002491 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2492 std::ostringstream combinedStringStream;
2493 std::copy(strings.begin(), strings.end(),
2494 std::ostream_iterator<const char *>(combinedStringStream, " "));
2495 return MakeStaticString(combinedStringStream.str());
2496 };
2497
2498 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002499 for (const auto &extensionString : mExtensions.getStrings())
2500 {
2501 mExtensionStrings.push_back(MakeStaticString(extensionString));
2502 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002503 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002504
Bryan Bernhart58806562017-01-05 13:09:31 -08002505 const gl::Extensions &nativeExtensions = mImplementation->getNativeExtensions();
2506
Geoff Langc339c4e2016-11-29 10:37:36 -05002507 mRequestableExtensionStrings.clear();
2508 for (const auto &extensionInfo : GetExtensionInfoMap())
2509 {
2510 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08002511 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
2512 nativeExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002513 {
2514 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
2515 }
2516 }
2517 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002518}
2519
Geoff Langc339c4e2016-11-29 10:37:36 -05002520const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04002521{
Geoff Langc339c4e2016-11-29 10:37:36 -05002522 switch (name)
2523 {
2524 case GL_VENDOR:
2525 return reinterpret_cast<const GLubyte *>("Google Inc.");
2526
2527 case GL_RENDERER:
2528 return reinterpret_cast<const GLubyte *>(mRendererString);
2529
2530 case GL_VERSION:
2531 return reinterpret_cast<const GLubyte *>(mVersionString);
2532
2533 case GL_SHADING_LANGUAGE_VERSION:
2534 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
2535
2536 case GL_EXTENSIONS:
2537 return reinterpret_cast<const GLubyte *>(mExtensionString);
2538
2539 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2540 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
2541
2542 default:
2543 UNREACHABLE();
2544 return nullptr;
2545 }
Geoff Langcec35902014-04-16 10:52:36 -04002546}
2547
Geoff Langc339c4e2016-11-29 10:37:36 -05002548const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04002549{
Geoff Langc339c4e2016-11-29 10:37:36 -05002550 switch (name)
2551 {
2552 case GL_EXTENSIONS:
2553 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
2554
2555 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2556 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
2557
2558 default:
2559 UNREACHABLE();
2560 return nullptr;
2561 }
Geoff Langcec35902014-04-16 10:52:36 -04002562}
2563
2564size_t Context::getExtensionStringCount() const
2565{
2566 return mExtensionStrings.size();
2567}
2568
Geoff Langc339c4e2016-11-29 10:37:36 -05002569void Context::requestExtension(const char *name)
2570{
2571 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2572 ASSERT(extensionInfos.find(name) != extensionInfos.end());
2573 const auto &extension = extensionInfos.at(name);
2574 ASSERT(extension.Requestable);
2575
2576 if (mExtensions.*(extension.ExtensionsMember))
2577 {
2578 // Extension already enabled
2579 return;
2580 }
2581
2582 mExtensions.*(extension.ExtensionsMember) = true;
2583 updateCaps();
2584 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08002585
Jamie Madill2f348d22017-06-05 10:50:59 -04002586 // Release the shader compiler so it will be re-created with the requested extensions enabled.
2587 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04002588
Jamie Madill81c2e252017-09-09 23:32:46 -04002589 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
2590 // sampleable.
2591 mState.mTextures->signalAllTexturesDirty();
Geoff Lang9aded172017-04-05 11:07:56 -04002592 for (auto &zeroTexture : mZeroTextures)
2593 {
Jamie Madill05b35b22017-10-03 09:01:44 -04002594 zeroTexture.second->signalDirty(InitState::Initialized);
Geoff Lang9aded172017-04-05 11:07:56 -04002595 }
2596
2597 mState.mFramebuffers->invalidateFramebufferComplenessCache();
Geoff Langc339c4e2016-11-29 10:37:36 -05002598}
2599
2600size_t Context::getRequestableExtensionStringCount() const
2601{
2602 return mRequestableExtensionStrings.size();
2603}
2604
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002605void Context::beginTransformFeedback(GLenum primitiveMode)
2606{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002607 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002608 ASSERT(transformFeedback != nullptr);
2609 ASSERT(!transformFeedback->isPaused());
2610
Jamie Madill6c1f6712017-02-14 19:08:04 -05002611 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002612}
2613
2614bool Context::hasActiveTransformFeedback(GLuint program) const
2615{
2616 for (auto pair : mTransformFeedbackMap)
2617 {
2618 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
2619 {
2620 return true;
2621 }
2622 }
2623 return false;
2624}
2625
Geoff Langb433e872017-10-05 14:01:47 -04002626void Context::initCaps(const egl::DisplayExtensions &displayExtensions, bool robustResourceInit)
Geoff Lang493daf52014-07-03 13:38:44 -04002627{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002628 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04002629
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002630 mExtensions = mImplementation->getNativeExtensions();
Geoff Lang493daf52014-07-03 13:38:44 -04002631
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002632 mLimitations = mImplementation->getNativeLimitations();
Austin Kinross02df7962015-07-01 10:03:42 -07002633
Geoff Langeb66a6e2016-10-31 13:06:12 -04002634 if (getClientVersion() < Version(3, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002635 {
2636 // Disable ES3+ extensions
Jamie Madill231c7f52017-04-26 13:45:37 -04002637 mExtensions.colorBufferFloat = false;
Geoff Langb66a9092016-05-16 15:59:14 -04002638 mExtensions.eglImageExternalEssl3 = false;
Vincent Lang25ab4512016-05-13 18:13:59 +02002639 mExtensions.textureNorm16 = false;
Martin Radev137032d2017-07-13 10:11:12 +03002640 mExtensions.multiview = false;
2641 mExtensions.maxViews = 1u;
Geoff Lang493daf52014-07-03 13:38:44 -04002642 }
2643
Geoff Langeb66a6e2016-10-31 13:06:12 -04002644 if (getClientVersion() > Version(2, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002645 {
2646 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
Jamie Madill231c7f52017-04-26 13:45:37 -04002647 // mExtensions.sRGB = false;
Geoff Lang493daf52014-07-03 13:38:44 -04002648 }
2649
Jamie Madill00ed7a12016-05-19 13:13:38 -04002650 // Some extensions are always available because they are implemented in the GL layer.
Jamie Madill231c7f52017-04-26 13:45:37 -04002651 mExtensions.bindUniformLocation = true;
2652 mExtensions.vertexArrayObject = true;
Geoff Langf41a7152016-09-19 15:11:17 -04002653 mExtensions.bindGeneratesResource = true;
Geoff Langfeb8c682017-02-13 16:07:35 -05002654 mExtensions.clientArrays = true;
Geoff Langc339c4e2016-11-29 10:37:36 -05002655 mExtensions.requestExtension = true;
Jamie Madill00ed7a12016-05-19 13:13:38 -04002656
2657 // Enable the no error extension if the context was created with the flag.
2658 mExtensions.noError = mSkipValidation;
2659
Corentin Wallezccab69d2017-01-27 16:57:15 -05002660 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Corentin Wallezc295e512017-01-27 17:47:50 -05002661 mExtensions.surfacelessContext = displayExtensions.surfacelessContext;
Corentin Wallezccab69d2017-01-27 16:57:15 -05002662
Geoff Lang70d0f492015-12-10 17:45:46 -05002663 // Explicitly enable GL_KHR_debug
2664 mExtensions.debug = true;
2665 mExtensions.maxDebugMessageLength = 1024;
2666 mExtensions.maxDebugLoggedMessages = 1024;
2667 mExtensions.maxDebugGroupStackDepth = 1024;
2668 mExtensions.maxLabelLength = 1024;
2669
Geoff Langff5b2d52016-09-07 11:32:23 -04002670 // Explicitly enable GL_ANGLE_robust_client_memory
2671 mExtensions.robustClientMemory = true;
2672
Jamie Madille08a1d32017-03-07 17:24:06 -05002673 // Determine robust resource init availability from EGL.
Geoff Langb433e872017-10-05 14:01:47 -04002674 mExtensions.robustResourceInitialization = robustResourceInit;
Jamie Madille08a1d32017-03-07 17:24:06 -05002675
Jiajia Qin8a7b3a02017-08-25 16:05:48 +08002676 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
2677 // supports it.
2678 mExtensions.robustBufferAccessBehavior =
2679 mRobustAccess && mExtensions.robustBufferAccessBehavior;
2680
Jamie Madillc43be722017-07-13 16:22:14 -04002681 // Enable the cache control query unconditionally.
2682 mExtensions.programCacheControl = true;
2683
Geoff Lang301d1612014-07-09 10:34:37 -04002684 // Apply implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04002685 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002686
Jamie Madill0f80ed82017-09-19 00:24:56 -04002687 if (getClientVersion() < ES_3_1)
2688 {
2689 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
2690 }
2691 else
2692 {
2693 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
2694 }
Geoff Lang301d1612014-07-09 10:34:37 -04002695
Jamie Madill0f80ed82017-09-19 00:24:56 -04002696 LimitCap(&mCaps.maxVertexUniformBlocks, IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
2697 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
2698 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
2699
2700 // Limit textures as well, so we can use fast bitsets with texture bindings.
2701 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
2702 LimitCap(&mCaps.maxVertexTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
2703 LimitCap(&mCaps.maxTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04002704
Jiawei Shaodb342272017-09-27 10:21:45 +08002705 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
2706
Geoff Langc287ea62016-09-16 14:46:51 -04002707 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002708 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04002709 for (const auto &extensionInfo : GetExtensionInfoMap())
2710 {
2711 // If this context is for WebGL, disable all enableable extensions
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002712 if (mWebGLContext && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04002713 {
2714 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
2715 }
2716 }
2717
2718 // Generate texture caps
2719 updateCaps();
2720}
2721
2722void Context::updateCaps()
2723{
Geoff Lang900013c2014-07-07 11:32:19 -04002724 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002725 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04002726
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002727 for (auto capsIt : mImplementation->getNativeTextureCaps())
Geoff Lang493daf52014-07-03 13:38:44 -04002728 {
Geoff Langca271392017-04-05 12:30:00 -04002729 GLenum sizedInternalFormat = capsIt.first;
Jamie Madill231c7f52017-04-26 13:45:37 -04002730 TextureCaps formatCaps = capsIt.second;
Geoff Lang493daf52014-07-03 13:38:44 -04002731
Geoff Langca271392017-04-05 12:30:00 -04002732 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04002733
Geoff Lang0d8b7242015-09-09 14:56:53 -04002734 // Update the format caps based on the client version and extensions.
2735 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
2736 // ES3.
2737 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002738 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002739 formatCaps.renderable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002740 formatCaps.renderable && formatInfo.renderSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002741 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002742 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04002743
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002744 // OpenGL ES does not support multisampling with non-rendererable formats
2745 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Olli Etuaho50c562d2017-06-06 14:43:30 +03002746 if (!formatCaps.renderable ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002747 (getClientVersion() < ES_3_1 &&
2748 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04002749 {
Geoff Langd87878e2014-09-19 15:42:59 -04002750 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04002751 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03002752 else
2753 {
2754 // We may have limited the max samples for some required renderbuffer formats due to
2755 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
2756 GLuint formatMaxSamples = formatCaps.getMaxSamples();
2757
2758 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
2759 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
2760 // exception of signed and unsigned integer formats."
2761 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
2762 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
2763 {
2764 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
2765 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
2766 }
2767
2768 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
2769 if (getClientVersion() >= ES_3_1)
2770 {
2771 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
2772 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
2773 // the exception that the signed and unsigned integer formats are required only to
2774 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
2775 // multisamples, which must be at least one."
2776 if (formatInfo.componentType == GL_INT ||
2777 formatInfo.componentType == GL_UNSIGNED_INT)
2778 {
2779 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
2780 }
2781
2782 // GLES 3.1 section 19.3.1.
2783 if (formatCaps.texturable)
2784 {
2785 if (formatInfo.depthBits > 0)
2786 {
2787 mCaps.maxDepthTextureSamples =
2788 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
2789 }
2790 else if (formatInfo.redBits > 0)
2791 {
2792 mCaps.maxColorTextureSamples =
2793 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
2794 }
2795 }
2796 }
2797 }
Geoff Langd87878e2014-09-19 15:42:59 -04002798
2799 if (formatCaps.texturable && formatInfo.compressed)
2800 {
Geoff Langca271392017-04-05 12:30:00 -04002801 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04002802 }
2803
Geoff Langca271392017-04-05 12:30:00 -04002804 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04002805 }
Jamie Madill32447362017-06-28 14:53:52 -04002806
2807 // If program binary is disabled, blank out the memory cache pointer.
2808 if (!mImplementation->getNativeExtensions().getProgramBinary)
2809 {
2810 mMemoryProgramCache = nullptr;
2811 }
Geoff Lang493daf52014-07-03 13:38:44 -04002812}
2813
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002814void Context::initWorkarounds()
2815{
Jamie Madill761b02c2017-06-23 16:27:06 -04002816 // Apply back-end workarounds.
2817 mImplementation->applyNativeWorkarounds(&mWorkarounds);
2818
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002819 // Lose the context upon out of memory error if the application is
2820 // expecting to watch for those events.
2821 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2822}
2823
Jamie Madill05b35b22017-10-03 09:01:44 -04002824Error Context::prepareForDraw()
2825{
2826 syncRendererState();
2827 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
2828 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
2829 return NoError();
2830}
2831
Jamie Madill1b94d432015-08-07 13:23:23 -04002832void Context::syncRendererState()
2833{
Jamie Madill7d1f5c62017-09-02 15:32:15 -04002834 mGLState.syncDirtyObjects(this);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002835 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
Jamie Madillfe548342017-06-19 11:13:24 -04002836 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002837 mGLState.clearDirtyBits();
Jamie Madill1b94d432015-08-07 13:23:23 -04002838}
2839
Jamie Madillad9f24e2016-02-12 09:27:24 -05002840void Context::syncRendererState(const State::DirtyBits &bitMask,
2841 const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04002842{
Jamie Madill7d1f5c62017-09-02 15:32:15 -04002843 mGLState.syncDirtyObjects(this, objectMask);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002844 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madillfe548342017-06-19 11:13:24 -04002845 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002846 mGLState.clearDirtyBits(dirtyBits);
Jamie Madill1b94d432015-08-07 13:23:23 -04002847}
Jamie Madillc29968b2016-01-20 11:17:23 -05002848
2849void Context::blitFramebuffer(GLint srcX0,
2850 GLint srcY0,
2851 GLint srcX1,
2852 GLint srcY1,
2853 GLint dstX0,
2854 GLint dstY0,
2855 GLint dstX1,
2856 GLint dstY1,
2857 GLbitfield mask,
2858 GLenum filter)
2859{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002860 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002861 ASSERT(drawFramebuffer);
2862
2863 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
2864 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
2865
Jamie Madillad9f24e2016-02-12 09:27:24 -05002866 syncStateForBlit();
Jamie Madillc29968b2016-01-20 11:17:23 -05002867
Jamie Madillc564c072017-06-01 12:45:42 -04002868 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002869}
Jamie Madillc29968b2016-01-20 11:17:23 -05002870
2871void Context::clear(GLbitfield mask)
2872{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002873 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002874 handleError(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05002875}
2876
2877void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
2878{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002879 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002880 handleError(mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002881}
2882
2883void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
2884{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002885 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002886 handleError(mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002887}
2888
2889void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
2890{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002891 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002892 handleError(mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002893}
2894
2895void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
2896{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002897 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002898 ASSERT(framebufferObject);
2899
2900 // If a buffer is not present, the clear has no effect
2901 if (framebufferObject->getDepthbuffer() == nullptr &&
2902 framebufferObject->getStencilbuffer() == nullptr)
2903 {
2904 return;
2905 }
2906
Jamie Madillad9f24e2016-02-12 09:27:24 -05002907 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002908 handleError(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05002909}
2910
2911void Context::readPixels(GLint x,
2912 GLint y,
2913 GLsizei width,
2914 GLsizei height,
2915 GLenum format,
2916 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002917 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05002918{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04002919 if (width == 0 || height == 0)
2920 {
2921 return;
2922 }
2923
Jamie Madillad9f24e2016-02-12 09:27:24 -05002924 syncStateForReadPixels();
Jamie Madillc29968b2016-01-20 11:17:23 -05002925
Jamie Madillb6664922017-07-25 12:55:04 -04002926 Framebuffer *readFBO = mGLState.getReadFramebuffer();
2927 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05002928
2929 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04002930 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05002931}
2932
2933void Context::copyTexImage2D(GLenum target,
2934 GLint level,
2935 GLenum internalformat,
2936 GLint x,
2937 GLint y,
2938 GLsizei width,
2939 GLsizei height,
2940 GLint border)
2941{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002942 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002943 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002944
Jamie Madillc29968b2016-01-20 11:17:23 -05002945 Rectangle sourceArea(x, y, width, height);
2946
Jamie Madill05b35b22017-10-03 09:01:44 -04002947 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002948 Texture *texture =
2949 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05002950 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05002951}
2952
2953void Context::copyTexSubImage2D(GLenum target,
2954 GLint level,
2955 GLint xoffset,
2956 GLint yoffset,
2957 GLint x,
2958 GLint y,
2959 GLsizei width,
2960 GLsizei height)
2961{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04002962 if (width == 0 || height == 0)
2963 {
2964 return;
2965 }
2966
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002967 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002968 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002969
Jamie Madillc29968b2016-01-20 11:17:23 -05002970 Offset destOffset(xoffset, yoffset, 0);
2971 Rectangle sourceArea(x, y, width, height);
2972
Jamie Madill05b35b22017-10-03 09:01:44 -04002973 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002974 Texture *texture =
2975 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05002976 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05002977}
2978
2979void Context::copyTexSubImage3D(GLenum target,
2980 GLint level,
2981 GLint xoffset,
2982 GLint yoffset,
2983 GLint zoffset,
2984 GLint x,
2985 GLint y,
2986 GLsizei width,
2987 GLsizei height)
2988{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04002989 if (width == 0 || height == 0)
2990 {
2991 return;
2992 }
2993
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002994 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002995 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002996
Jamie Madillc29968b2016-01-20 11:17:23 -05002997 Offset destOffset(xoffset, yoffset, zoffset);
2998 Rectangle sourceArea(x, y, width, height);
2999
Jamie Madill05b35b22017-10-03 09:01:44 -04003000 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3001 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003002 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003003}
3004
3005void Context::framebufferTexture2D(GLenum target,
3006 GLenum attachment,
3007 GLenum textarget,
3008 GLuint texture,
3009 GLint level)
3010{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003011 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003012 ASSERT(framebuffer);
3013
3014 if (texture != 0)
3015 {
3016 Texture *textureObj = getTexture(texture);
3017
3018 ImageIndex index = ImageIndex::MakeInvalid();
3019
3020 if (textarget == GL_TEXTURE_2D)
3021 {
3022 index = ImageIndex::Make2D(level);
3023 }
Corentin Wallez13c0dd42017-07-04 18:27:01 -04003024 else if (textarget == GL_TEXTURE_RECTANGLE_ANGLE)
3025 {
3026 index = ImageIndex::MakeRectangle(level);
3027 }
JiangYizhoubddc46b2016-12-09 09:50:51 +08003028 else if (textarget == GL_TEXTURE_2D_MULTISAMPLE)
3029 {
3030 ASSERT(level == 0);
3031 index = ImageIndex::Make2DMultisample();
3032 }
Jamie Madillc29968b2016-01-20 11:17:23 -05003033 else
3034 {
3035 ASSERT(IsCubeMapTextureTarget(textarget));
3036 index = ImageIndex::MakeCube(textarget, level);
3037 }
3038
Jamie Madilla02315b2017-02-23 14:14:47 -05003039 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003040 }
3041 else
3042 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003043 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003044 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003045
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003046 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003047}
3048
3049void Context::framebufferRenderbuffer(GLenum target,
3050 GLenum attachment,
3051 GLenum renderbuffertarget,
3052 GLuint renderbuffer)
3053{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003054 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003055 ASSERT(framebuffer);
3056
3057 if (renderbuffer != 0)
3058 {
3059 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003060
3061 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex::MakeInvalid(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003062 renderbufferObject);
3063 }
3064 else
3065 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003066 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003067 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003068
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003069 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003070}
3071
3072void Context::framebufferTextureLayer(GLenum target,
3073 GLenum attachment,
3074 GLuint texture,
3075 GLint level,
3076 GLint layer)
3077{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003078 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003079 ASSERT(framebuffer);
3080
3081 if (texture != 0)
3082 {
3083 Texture *textureObject = getTexture(texture);
3084
3085 ImageIndex index = ImageIndex::MakeInvalid();
3086
3087 if (textureObject->getTarget() == GL_TEXTURE_3D)
3088 {
3089 index = ImageIndex::Make3D(level, layer);
3090 }
3091 else
3092 {
3093 ASSERT(textureObject->getTarget() == GL_TEXTURE_2D_ARRAY);
3094 index = ImageIndex::Make2DArray(level, layer);
3095 }
3096
Jamie Madilla02315b2017-02-23 14:14:47 -05003097 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003098 }
3099 else
3100 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003101 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003102 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003103
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003104 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003105}
3106
Martin Radev137032d2017-07-13 10:11:12 +03003107void Context::framebufferTextureMultiviewLayeredANGLE(GLenum target,
3108 GLenum attachment,
3109 GLuint texture,
3110 GLint level,
3111 GLint baseViewIndex,
3112 GLsizei numViews)
3113{
Martin Radev82ef7742017-08-08 17:44:58 +03003114 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3115 ASSERT(framebuffer);
3116
3117 if (texture != 0)
3118 {
3119 Texture *textureObj = getTexture(texture);
3120
Martin Radev18b75ba2017-08-15 15:50:40 +03003121 ImageIndex index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
Martin Radev82ef7742017-08-08 17:44:58 +03003122 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3123 numViews, baseViewIndex);
3124 }
3125 else
3126 {
3127 framebuffer->resetAttachment(this, attachment);
3128 }
3129
3130 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003131}
3132
3133void Context::framebufferTextureMultiviewSideBySideANGLE(GLenum target,
3134 GLenum attachment,
3135 GLuint texture,
3136 GLint level,
3137 GLsizei numViews,
3138 const GLint *viewportOffsets)
3139{
Martin Radev5dae57b2017-07-14 16:15:55 +03003140 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3141 ASSERT(framebuffer);
3142
3143 if (texture != 0)
3144 {
3145 Texture *textureObj = getTexture(texture);
3146
3147 ImageIndex index = ImageIndex::Make2D(level);
3148 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3149 textureObj, numViews, viewportOffsets);
3150 }
3151 else
3152 {
3153 framebuffer->resetAttachment(this, attachment);
3154 }
3155
3156 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003157}
3158
Jamie Madillc29968b2016-01-20 11:17:23 -05003159void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3160{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003161 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003162 ASSERT(framebuffer);
3163 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003164 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003165}
3166
3167void Context::readBuffer(GLenum mode)
3168{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003169 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003170 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003171 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003172}
3173
3174void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3175{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003176 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003177 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003178
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003179 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003180 ASSERT(framebuffer);
3181
3182 // The specification isn't clear what should be done when the framebuffer isn't complete.
3183 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003184 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003185}
3186
3187void Context::invalidateFramebuffer(GLenum target,
3188 GLsizei numAttachments,
3189 const GLenum *attachments)
3190{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003191 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003192 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003193
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003194 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003195 ASSERT(framebuffer);
3196
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003197 if (framebuffer->checkStatus(this) != GL_FRAMEBUFFER_COMPLETE)
Jamie Madillc29968b2016-01-20 11:17:23 -05003198 {
Jamie Madill437fa652016-05-03 15:13:24 -04003199 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003200 }
Jamie Madill437fa652016-05-03 15:13:24 -04003201
Jamie Madill4928b7c2017-06-20 12:57:39 -04003202 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003203}
3204
3205void Context::invalidateSubFramebuffer(GLenum target,
3206 GLsizei numAttachments,
3207 const GLenum *attachments,
3208 GLint x,
3209 GLint y,
3210 GLsizei width,
3211 GLsizei height)
3212{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003213 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003214 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003215
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003216 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003217 ASSERT(framebuffer);
3218
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003219 if (framebuffer->checkStatus(this) != GL_FRAMEBUFFER_COMPLETE)
Jamie Madillc29968b2016-01-20 11:17:23 -05003220 {
Jamie Madill437fa652016-05-03 15:13:24 -04003221 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003222 }
Jamie Madill437fa652016-05-03 15:13:24 -04003223
3224 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003225 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003226}
3227
Jamie Madill73a84962016-02-12 09:27:23 -05003228void Context::texImage2D(GLenum target,
3229 GLint level,
3230 GLint internalformat,
3231 GLsizei width,
3232 GLsizei height,
3233 GLint border,
3234 GLenum format,
3235 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003236 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003237{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003238 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003239
3240 Extents size(width, height, 1);
3241 Texture *texture =
3242 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003243 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3244 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003245}
3246
3247void Context::texImage3D(GLenum target,
3248 GLint level,
3249 GLint internalformat,
3250 GLsizei width,
3251 GLsizei height,
3252 GLsizei depth,
3253 GLint border,
3254 GLenum format,
3255 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003256 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003257{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003258 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003259
3260 Extents size(width, height, depth);
3261 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003262 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3263 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003264}
3265
3266void Context::texSubImage2D(GLenum target,
3267 GLint level,
3268 GLint xoffset,
3269 GLint yoffset,
3270 GLsizei width,
3271 GLsizei height,
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{
3276 // Zero sized uploads are valid but no-ops
3277 if (width == 0 || height == 0)
3278 {
3279 return;
3280 }
3281
Jamie Madillad9f24e2016-02-12 09:27:24 -05003282 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003283
3284 Box area(xoffset, yoffset, 0, width, height, 1);
3285 Texture *texture =
3286 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003287 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3288 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003289}
3290
3291void Context::texSubImage3D(GLenum target,
3292 GLint level,
3293 GLint xoffset,
3294 GLint yoffset,
3295 GLint zoffset,
3296 GLsizei width,
3297 GLsizei height,
3298 GLsizei depth,
3299 GLenum format,
3300 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003301 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003302{
3303 // Zero sized uploads are valid but no-ops
3304 if (width == 0 || height == 0 || depth == 0)
3305 {
3306 return;
3307 }
3308
Jamie Madillad9f24e2016-02-12 09:27:24 -05003309 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003310
3311 Box area(xoffset, yoffset, zoffset, width, height, depth);
3312 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003313 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3314 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003315}
3316
3317void Context::compressedTexImage2D(GLenum target,
3318 GLint level,
3319 GLenum internalformat,
3320 GLsizei width,
3321 GLsizei height,
3322 GLint border,
3323 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003324 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003325{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003326 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003327
3328 Extents size(width, height, 1);
3329 Texture *texture =
3330 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003331 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003332 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003333 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003334}
3335
3336void Context::compressedTexImage3D(GLenum target,
3337 GLint level,
3338 GLenum internalformat,
3339 GLsizei width,
3340 GLsizei height,
3341 GLsizei depth,
3342 GLint border,
3343 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003344 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003345{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003346 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003347
3348 Extents size(width, height, depth);
3349 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003350 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003351 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003352 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003353}
3354
3355void Context::compressedTexSubImage2D(GLenum target,
3356 GLint level,
3357 GLint xoffset,
3358 GLint yoffset,
3359 GLsizei width,
3360 GLsizei height,
3361 GLenum format,
3362 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003363 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003364{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003365 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003366
3367 Box area(xoffset, yoffset, 0, width, height, 1);
3368 Texture *texture =
3369 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003370 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003371 format, imageSize,
3372 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003373}
3374
3375void Context::compressedTexSubImage3D(GLenum target,
3376 GLint level,
3377 GLint xoffset,
3378 GLint yoffset,
3379 GLint zoffset,
3380 GLsizei width,
3381 GLsizei height,
3382 GLsizei depth,
3383 GLenum format,
3384 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003385 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003386{
3387 // Zero sized uploads are valid but no-ops
3388 if (width == 0 || height == 0)
3389 {
3390 return;
3391 }
3392
Jamie Madillad9f24e2016-02-12 09:27:24 -05003393 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003394
3395 Box area(xoffset, yoffset, zoffset, width, height, depth);
3396 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003397 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003398 format, imageSize,
3399 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003400}
3401
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003402void Context::generateMipmap(GLenum target)
3403{
3404 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003405 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003406}
3407
Geoff Lang97073d12016-04-20 10:42:34 -07003408void Context::copyTextureCHROMIUM(GLuint sourceId,
Geoff Langfc72a072017-03-24 14:52:39 -04003409 GLint sourceLevel,
3410 GLenum destTarget,
Geoff Lang97073d12016-04-20 10:42:34 -07003411 GLuint destId,
Geoff Langfc72a072017-03-24 14:52:39 -04003412 GLint destLevel,
Geoff Lang97073d12016-04-20 10:42:34 -07003413 GLint internalFormat,
3414 GLenum destType,
3415 GLboolean unpackFlipY,
3416 GLboolean unpackPremultiplyAlpha,
3417 GLboolean unpackUnmultiplyAlpha)
3418{
3419 syncStateForTexImage();
3420
3421 gl::Texture *sourceTexture = getTexture(sourceId);
3422 gl::Texture *destTexture = getTexture(destId);
Geoff Langfc72a072017-03-24 14:52:39 -04003423 handleError(destTexture->copyTexture(
3424 this, destTarget, destLevel, internalFormat, destType, sourceLevel, unpackFlipY == GL_TRUE,
3425 unpackPremultiplyAlpha == GL_TRUE, unpackUnmultiplyAlpha == GL_TRUE, sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003426}
3427
3428void Context::copySubTextureCHROMIUM(GLuint sourceId,
Geoff Langfc72a072017-03-24 14:52:39 -04003429 GLint sourceLevel,
3430 GLenum destTarget,
Geoff Lang97073d12016-04-20 10:42:34 -07003431 GLuint destId,
Geoff Langfc72a072017-03-24 14:52:39 -04003432 GLint destLevel,
Geoff Lang97073d12016-04-20 10:42:34 -07003433 GLint xoffset,
3434 GLint yoffset,
3435 GLint x,
3436 GLint y,
3437 GLsizei width,
3438 GLsizei height,
3439 GLboolean unpackFlipY,
3440 GLboolean unpackPremultiplyAlpha,
3441 GLboolean unpackUnmultiplyAlpha)
3442{
3443 // Zero sized copies are valid but no-ops
3444 if (width == 0 || height == 0)
3445 {
3446 return;
3447 }
3448
3449 syncStateForTexImage();
3450
3451 gl::Texture *sourceTexture = getTexture(sourceId);
3452 gl::Texture *destTexture = getTexture(destId);
3453 Offset offset(xoffset, yoffset, 0);
3454 Rectangle area(x, y, width, height);
Geoff Langfc72a072017-03-24 14:52:39 -04003455 handleError(destTexture->copySubTexture(
3456 this, destTarget, destLevel, offset, sourceLevel, area, unpackFlipY == GL_TRUE,
3457 unpackPremultiplyAlpha == GL_TRUE, unpackUnmultiplyAlpha == GL_TRUE, sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003458}
3459
Geoff Lang47110bf2016-04-20 11:13:22 -07003460void Context::compressedCopyTextureCHROMIUM(GLuint sourceId, GLuint destId)
3461{
3462 syncStateForTexImage();
3463
3464 gl::Texture *sourceTexture = getTexture(sourceId);
3465 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05003466 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07003467}
3468
Geoff Lang496c02d2016-10-20 11:38:11 -07003469void Context::getBufferPointerv(GLenum target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03003470{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003471 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003472 ASSERT(buffer);
3473
Geoff Lang496c02d2016-10-20 11:38:11 -07003474 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03003475}
3476
Jamie Madill876429b2017-04-20 15:46:24 -04003477void *Context::mapBuffer(GLenum target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003478{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003479 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003480 ASSERT(buffer);
3481
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003482 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003483 if (error.isError())
3484 {
Jamie Madill437fa652016-05-03 15:13:24 -04003485 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003486 return nullptr;
3487 }
3488
3489 return buffer->getMapPointer();
3490}
3491
3492GLboolean Context::unmapBuffer(GLenum target)
3493{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003494 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003495 ASSERT(buffer);
3496
3497 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003498 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03003499 if (error.isError())
3500 {
Jamie Madill437fa652016-05-03 15:13:24 -04003501 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003502 return GL_FALSE;
3503 }
3504
3505 return result;
3506}
3507
Jamie Madill876429b2017-04-20 15:46:24 -04003508void *Context::mapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003509{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003510 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003511 ASSERT(buffer);
3512
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003513 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003514 if (error.isError())
3515 {
Jamie Madill437fa652016-05-03 15:13:24 -04003516 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003517 return nullptr;
3518 }
3519
3520 return buffer->getMapPointer();
3521}
3522
3523void Context::flushMappedBufferRange(GLenum /*target*/, GLintptr /*offset*/, GLsizeiptr /*length*/)
3524{
3525 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
3526}
3527
Jamie Madillad9f24e2016-02-12 09:27:24 -05003528void Context::syncStateForReadPixels()
3529{
3530 syncRendererState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
3531}
3532
3533void Context::syncStateForTexImage()
3534{
3535 syncRendererState(mTexImageDirtyBits, mTexImageDirtyObjects);
3536}
3537
3538void Context::syncStateForClear()
3539{
3540 syncRendererState(mClearDirtyBits, mClearDirtyObjects);
3541}
3542
3543void Context::syncStateForBlit()
3544{
3545 syncRendererState(mBlitDirtyBits, mBlitDirtyObjects);
3546}
3547
Jamie Madillc20ab272016-06-09 07:20:46 -07003548void Context::activeTexture(GLenum texture)
3549{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003550 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003551}
3552
Jamie Madill876429b2017-04-20 15:46:24 -04003553void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003554{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003555 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07003556}
3557
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003558void Context::blendEquation(GLenum mode)
3559{
3560 mGLState.setBlendEquation(mode, mode);
3561}
3562
Jamie Madillc20ab272016-06-09 07:20:46 -07003563void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
3564{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003565 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003566}
3567
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003568void Context::blendFunc(GLenum sfactor, GLenum dfactor)
3569{
3570 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
3571}
3572
Jamie Madillc20ab272016-06-09 07:20:46 -07003573void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
3574{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003575 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003576}
3577
Jamie Madill876429b2017-04-20 15:46:24 -04003578void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003579{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003580 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003581}
3582
Jamie Madill876429b2017-04-20 15:46:24 -04003583void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07003584{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003585 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07003586}
3587
3588void Context::clearStencil(GLint s)
3589{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003590 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07003591}
3592
3593void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
3594{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003595 mGLState.setColorMask(red == GL_TRUE, green == GL_TRUE, blue == GL_TRUE, alpha == GL_TRUE);
Jamie Madillc20ab272016-06-09 07:20:46 -07003596}
3597
3598void Context::cullFace(GLenum mode)
3599{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003600 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003601}
3602
3603void Context::depthFunc(GLenum func)
3604{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003605 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07003606}
3607
3608void Context::depthMask(GLboolean flag)
3609{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003610 mGLState.setDepthMask(flag != GL_FALSE);
Jamie Madillc20ab272016-06-09 07:20:46 -07003611}
3612
Jamie Madill876429b2017-04-20 15:46:24 -04003613void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07003614{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003615 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07003616}
3617
3618void Context::disable(GLenum cap)
3619{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003620 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003621}
3622
3623void Context::disableVertexAttribArray(GLuint index)
3624{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003625 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003626}
3627
3628void Context::enable(GLenum cap)
3629{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003630 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003631}
3632
3633void Context::enableVertexAttribArray(GLuint index)
3634{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003635 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003636}
3637
3638void Context::frontFace(GLenum mode)
3639{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003640 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003641}
3642
3643void Context::hint(GLenum target, GLenum mode)
3644{
3645 switch (target)
3646 {
3647 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003648 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003649 break;
3650
3651 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003652 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003653 break;
3654
3655 default:
3656 UNREACHABLE();
3657 return;
3658 }
3659}
3660
3661void Context::lineWidth(GLfloat width)
3662{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003663 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07003664}
3665
3666void Context::pixelStorei(GLenum pname, GLint param)
3667{
3668 switch (pname)
3669 {
3670 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003671 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003672 break;
3673
3674 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003675 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003676 break;
3677
3678 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003679 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003680 break;
3681
3682 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003683 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003684 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003685 break;
3686
3687 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03003688 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003689 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003690 break;
3691
3692 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03003693 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003694 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003695 break;
3696
3697 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003698 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003699 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003700 break;
3701
3702 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003703 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003704 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003705 break;
3706
3707 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003708 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003709 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003710 break;
3711
3712 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003713 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003714 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003715 break;
3716
3717 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003718 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003719 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003720 break;
3721
3722 default:
3723 UNREACHABLE();
3724 return;
3725 }
3726}
3727
3728void Context::polygonOffset(GLfloat factor, GLfloat units)
3729{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003730 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07003731}
3732
Jamie Madill876429b2017-04-20 15:46:24 -04003733void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07003734{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003735 mGLState.setSampleCoverageParams(clamp01(value), invert == GL_TRUE);
Jamie Madillc20ab272016-06-09 07:20:46 -07003736}
3737
Jiawei Shaodb342272017-09-27 10:21:45 +08003738void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
3739{
3740 mGLState.setSampleMaskParams(maskNumber, mask);
3741}
3742
Jamie Madillc20ab272016-06-09 07:20:46 -07003743void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
3744{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003745 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07003746}
3747
3748void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
3749{
3750 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3751 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003752 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003753 }
3754
3755 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3756 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003757 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003758 }
3759}
3760
3761void Context::stencilMaskSeparate(GLenum face, GLuint mask)
3762{
3763 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3764 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003765 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003766 }
3767
3768 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3769 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003770 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003771 }
3772}
3773
3774void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
3775{
3776 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3777 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003778 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003779 }
3780
3781 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3782 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003783 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003784 }
3785}
3786
3787void Context::vertexAttrib1f(GLuint index, GLfloat x)
3788{
3789 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003790 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003791}
3792
3793void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
3794{
3795 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003796 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003797}
3798
3799void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
3800{
3801 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003802 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003803}
3804
3805void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
3806{
3807 GLfloat vals[4] = {values[0], values[1], 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::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
3812{
3813 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003814 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003815}
3816
3817void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
3818{
3819 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003820 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003821}
3822
3823void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
3824{
3825 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003826 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003827}
3828
3829void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
3830{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003831 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07003832}
3833
3834void Context::vertexAttribPointer(GLuint index,
3835 GLint size,
3836 GLenum type,
3837 GLboolean normalized,
3838 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04003839 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07003840{
Shaodde78e82017-05-22 14:13:27 +08003841 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(GL_ARRAY_BUFFER), size,
3842 type, normalized == GL_TRUE, false, stride, ptr);
Jamie Madillc20ab272016-06-09 07:20:46 -07003843}
3844
Shao80957d92017-02-20 21:25:59 +08003845void Context::vertexAttribFormat(GLuint attribIndex,
3846 GLint size,
3847 GLenum type,
3848 GLboolean normalized,
3849 GLuint relativeOffset)
3850{
3851 mGLState.setVertexAttribFormat(attribIndex, size, type, normalized == GL_TRUE, false,
3852 relativeOffset);
3853}
3854
3855void Context::vertexAttribIFormat(GLuint attribIndex,
3856 GLint size,
3857 GLenum type,
3858 GLuint relativeOffset)
3859{
3860 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
3861}
3862
3863void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
3864{
Shaodde78e82017-05-22 14:13:27 +08003865 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Shao80957d92017-02-20 21:25:59 +08003866}
3867
3868void Context::setVertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
3869{
3870 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
3871}
3872
Jamie Madillc20ab272016-06-09 07:20:46 -07003873void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
3874{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003875 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07003876}
3877
3878void Context::vertexAttribIPointer(GLuint index,
3879 GLint size,
3880 GLenum type,
3881 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04003882 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07003883{
Shaodde78e82017-05-22 14:13:27 +08003884 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(GL_ARRAY_BUFFER), size,
3885 type, false, true, stride, pointer);
Jamie Madillc20ab272016-06-09 07:20:46 -07003886}
3887
3888void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
3889{
3890 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003891 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003892}
3893
3894void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
3895{
3896 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003897 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003898}
3899
3900void Context::vertexAttribI4iv(GLuint index, const GLint *v)
3901{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003902 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07003903}
3904
3905void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
3906{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003907 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07003908}
3909
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003910void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
3911{
3912 const VertexAttribCurrentValueData &currentValues =
3913 getGLState().getVertexAttribCurrentValue(index);
3914 const VertexArray *vao = getGLState().getVertexArray();
3915 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3916 currentValues, pname, params);
3917}
3918
3919void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
3920{
3921 const VertexAttribCurrentValueData &currentValues =
3922 getGLState().getVertexAttribCurrentValue(index);
3923 const VertexArray *vao = getGLState().getVertexArray();
3924 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3925 currentValues, pname, params);
3926}
3927
3928void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
3929{
3930 const VertexAttribCurrentValueData &currentValues =
3931 getGLState().getVertexAttribCurrentValue(index);
3932 const VertexArray *vao = getGLState().getVertexArray();
3933 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3934 currentValues, pname, params);
3935}
3936
3937void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
3938{
3939 const VertexAttribCurrentValueData &currentValues =
3940 getGLState().getVertexAttribCurrentValue(index);
3941 const VertexArray *vao = getGLState().getVertexArray();
3942 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3943 currentValues, pname, params);
3944}
3945
Jamie Madill876429b2017-04-20 15:46:24 -04003946void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003947{
3948 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
3949 QueryVertexAttribPointerv(attrib, pname, pointer);
3950}
3951
Jamie Madillc20ab272016-06-09 07:20:46 -07003952void Context::debugMessageControl(GLenum source,
3953 GLenum type,
3954 GLenum severity,
3955 GLsizei count,
3956 const GLuint *ids,
3957 GLboolean enabled)
3958{
3959 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003960 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
3961 (enabled != GL_FALSE));
Jamie Madillc20ab272016-06-09 07:20:46 -07003962}
3963
3964void Context::debugMessageInsert(GLenum source,
3965 GLenum type,
3966 GLuint id,
3967 GLenum severity,
3968 GLsizei length,
3969 const GLchar *buf)
3970{
3971 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003972 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07003973}
3974
3975void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
3976{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003977 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07003978}
3979
3980GLuint Context::getDebugMessageLog(GLuint count,
3981 GLsizei bufSize,
3982 GLenum *sources,
3983 GLenum *types,
3984 GLuint *ids,
3985 GLenum *severities,
3986 GLsizei *lengths,
3987 GLchar *messageLog)
3988{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003989 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
3990 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07003991}
3992
3993void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
3994{
3995 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003996 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07003997}
3998
3999void Context::popDebugGroup()
4000{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004001 mGLState.getDebug().popGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004002}
4003
Jamie Madill876429b2017-04-20 15:46:24 -04004004void Context::bufferData(GLenum target, GLsizeiptr size, const void *data, GLenum usage)
Jamie Madill29639852016-09-02 15:00:09 -04004005{
4006 Buffer *buffer = mGLState.getTargetBuffer(target);
4007 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004008 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004009}
4010
Jamie Madill876429b2017-04-20 15:46:24 -04004011void Context::bufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004012{
4013 if (data == nullptr)
4014 {
4015 return;
4016 }
4017
4018 Buffer *buffer = mGLState.getTargetBuffer(target);
4019 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004020 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004021}
4022
Jamie Madillef300b12016-10-07 15:12:09 -04004023void Context::attachShader(GLuint program, GLuint shader)
4024{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004025 auto programObject = mState.mShaderPrograms->getProgram(program);
4026 auto shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004027 ASSERT(programObject && shaderObject);
4028 programObject->attachShader(shaderObject);
4029}
4030
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004031const Workarounds &Context::getWorkarounds() const
4032{
4033 return mWorkarounds;
4034}
4035
Jamie Madillb0817d12016-11-01 15:48:31 -04004036void Context::copyBufferSubData(GLenum readTarget,
4037 GLenum writeTarget,
4038 GLintptr readOffset,
4039 GLintptr writeOffset,
4040 GLsizeiptr size)
4041{
4042 // if size is zero, the copy is a successful no-op
4043 if (size == 0)
4044 {
4045 return;
4046 }
4047
4048 // TODO(jmadill): cache these.
4049 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4050 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4051
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004052 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004053}
4054
Jamie Madill01a80ee2016-11-07 12:06:18 -05004055void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4056{
4057 Program *programObject = getProgram(program);
4058 // TODO(jmadill): Re-use this from the validation if possible.
4059 ASSERT(programObject);
4060 programObject->bindAttributeLocation(index, name);
4061}
4062
4063void Context::bindBuffer(GLenum target, GLuint buffer)
4064{
4065 switch (target)
4066 {
4067 case GL_ARRAY_BUFFER:
4068 bindArrayBuffer(buffer);
4069 break;
4070 case GL_ELEMENT_ARRAY_BUFFER:
4071 bindElementArrayBuffer(buffer);
4072 break;
4073 case GL_COPY_READ_BUFFER:
4074 bindCopyReadBuffer(buffer);
4075 break;
4076 case GL_COPY_WRITE_BUFFER:
4077 bindCopyWriteBuffer(buffer);
4078 break;
4079 case GL_PIXEL_PACK_BUFFER:
4080 bindPixelPackBuffer(buffer);
4081 break;
4082 case GL_PIXEL_UNPACK_BUFFER:
4083 bindPixelUnpackBuffer(buffer);
4084 break;
4085 case GL_UNIFORM_BUFFER:
4086 bindGenericUniformBuffer(buffer);
4087 break;
4088 case GL_TRANSFORM_FEEDBACK_BUFFER:
4089 bindGenericTransformFeedbackBuffer(buffer);
4090 break;
Geoff Lang3b573612016-10-31 14:08:10 -04004091 case GL_ATOMIC_COUNTER_BUFFER:
Jiajia Qin6eafb042016-12-27 17:04:07 +08004092 bindGenericAtomicCounterBuffer(buffer);
Geoff Lang3b573612016-10-31 14:08:10 -04004093 break;
4094 case GL_SHADER_STORAGE_BUFFER:
Jiajia Qinf546e7d2017-03-27 14:12:59 +08004095 bindGenericShaderStorageBuffer(buffer);
Geoff Lang3b573612016-10-31 14:08:10 -04004096 break;
4097 case GL_DRAW_INDIRECT_BUFFER:
Jiajia Qin9d7d0b12016-11-29 16:30:31 +08004098 bindDrawIndirectBuffer(buffer);
Geoff Lang3b573612016-10-31 14:08:10 -04004099 break;
4100 case GL_DISPATCH_INDIRECT_BUFFER:
Geoff Lang9f090372016-12-02 10:20:43 -05004101 if (buffer != 0)
4102 {
4103 // Binding buffers to this binding point is not implemented yet.
4104 UNIMPLEMENTED();
4105 }
Geoff Lang3b573612016-10-31 14:08:10 -04004106 break;
Jamie Madill01a80ee2016-11-07 12:06:18 -05004107
4108 default:
4109 UNREACHABLE();
4110 break;
4111 }
4112}
4113
Jiajia Qin6eafb042016-12-27 17:04:07 +08004114void Context::bindBufferBase(GLenum target, GLuint index, GLuint buffer)
4115{
4116 bindBufferRange(target, index, buffer, 0, 0);
4117}
4118
4119void Context::bindBufferRange(GLenum target,
4120 GLuint index,
4121 GLuint buffer,
4122 GLintptr offset,
4123 GLsizeiptr size)
4124{
4125 switch (target)
4126 {
4127 case GL_TRANSFORM_FEEDBACK_BUFFER:
4128 bindIndexedTransformFeedbackBuffer(buffer, index, offset, size);
4129 bindGenericTransformFeedbackBuffer(buffer);
4130 break;
4131 case GL_UNIFORM_BUFFER:
4132 bindIndexedUniformBuffer(buffer, index, offset, size);
4133 bindGenericUniformBuffer(buffer);
4134 break;
4135 case GL_ATOMIC_COUNTER_BUFFER:
4136 bindIndexedAtomicCounterBuffer(buffer, index, offset, size);
4137 bindGenericAtomicCounterBuffer(buffer);
4138 break;
4139 case GL_SHADER_STORAGE_BUFFER:
Jiajia Qinf546e7d2017-03-27 14:12:59 +08004140 bindIndexedShaderStorageBuffer(buffer, index, offset, size);
4141 bindGenericShaderStorageBuffer(buffer);
Jiajia Qin6eafb042016-12-27 17:04:07 +08004142 break;
4143 default:
4144 UNREACHABLE();
4145 break;
4146 }
4147}
4148
Jamie Madill01a80ee2016-11-07 12:06:18 -05004149void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
4150{
4151 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4152 {
4153 bindReadFramebuffer(framebuffer);
4154 }
4155
4156 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4157 {
4158 bindDrawFramebuffer(framebuffer);
4159 }
4160}
4161
4162void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4163{
4164 ASSERT(target == GL_RENDERBUFFER);
4165 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004166 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04004167 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004168}
4169
JiangYizhoubddc46b2016-12-09 09:50:51 +08004170void Context::texStorage2DMultisample(GLenum target,
4171 GLsizei samples,
4172 GLenum internalformat,
4173 GLsizei width,
4174 GLsizei height,
4175 GLboolean fixedsamplelocations)
4176{
4177 Extents size(width, height, 1);
4178 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05004179 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
JiangYizhoubddc46b2016-12-09 09:50:51 +08004180 fixedsamplelocations));
4181}
4182
4183void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4184{
JiangYizhou5b03f472017-01-09 10:22:53 +08004185 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
4186 // the sample position should be queried by DRAW_FRAMEBUFFER.
4187 mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER);
4188 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08004189
4190 switch (pname)
4191 {
4192 case GL_SAMPLE_POSITION:
4193 handleError(framebuffer->getSamplePosition(index, val));
4194 break;
4195 default:
4196 UNREACHABLE();
4197 }
4198}
4199
Jamie Madille8fb6402017-02-14 17:56:40 -05004200void Context::renderbufferStorage(GLenum target,
4201 GLenum internalformat,
4202 GLsizei width,
4203 GLsizei height)
4204{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004205 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4206 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
4207
Jamie Madille8fb6402017-02-14 17:56:40 -05004208 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04004209 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004210}
4211
4212void Context::renderbufferStorageMultisample(GLenum target,
4213 GLsizei samples,
4214 GLenum internalformat,
4215 GLsizei width,
4216 GLsizei height)
4217{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004218 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4219 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05004220
4221 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004222 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04004223 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004224}
4225
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004226void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
4227{
Jamie Madill70b5bb02017-08-28 13:32:37 -04004228 const Sync *syncObject = getSync(sync);
Geoff Lang82483b92017-04-11 15:33:00 -04004229 handleError(QuerySynciv(syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004230}
4231
JiangYizhoue18e6392017-02-20 10:32:23 +08004232void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
4233{
4234 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4235 QueryFramebufferParameteriv(framebuffer, pname, params);
4236}
4237
4238void Context::setFramebufferParameteri(GLenum target, GLenum pname, GLint param)
4239{
4240 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4241 SetFramebufferParameteri(framebuffer, pname, param);
4242}
4243
Jamie Madillb3f26b92017-07-19 15:07:41 -04004244Error Context::getScratchBuffer(size_t requstedSizeBytes,
4245 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05004246{
Jamie Madillb3f26b92017-07-19 15:07:41 -04004247 if (!mScratchBuffer.get(requstedSizeBytes, scratchBufferOut))
4248 {
4249 return OutOfMemory() << "Failed to allocate internal buffer.";
4250 }
4251 return NoError();
4252}
4253
4254Error Context::getZeroFilledBuffer(size_t requstedSizeBytes,
4255 angle::MemoryBuffer **zeroBufferOut) const
4256{
4257 if (!mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0))
Jamie Madille14951e2017-03-09 18:55:16 -05004258 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004259 return OutOfMemory() << "Failed to allocate internal buffer.";
Jamie Madille14951e2017-03-09 18:55:16 -05004260 }
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004261 return NoError();
Jamie Madille14951e2017-03-09 18:55:16 -05004262}
4263
Xinghua Cao2b396592017-03-29 15:36:04 +08004264void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
4265{
4266 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
4267 {
4268 return;
4269 }
4270
Jamie Madill05b35b22017-10-03 09:01:44 -04004271 // TODO(jmadill): Dirty bits for compute.
4272 ANGLE_CONTEXT_TRY(mGLState.clearUnclearedActiveTextures(this));
4273
Jamie Madill71c88b32017-09-14 22:20:29 -04004274 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08004275}
4276
JiangYizhou165361c2017-06-07 14:56:57 +08004277void Context::texStorage2D(GLenum target,
4278 GLsizei levels,
4279 GLenum internalFormat,
4280 GLsizei width,
4281 GLsizei height)
4282{
4283 Extents size(width, height, 1);
4284 Texture *texture = getTargetTexture(target);
4285 handleError(texture->setStorage(this, target, levels, internalFormat, size));
4286}
4287
4288void Context::texStorage3D(GLenum target,
4289 GLsizei levels,
4290 GLenum internalFormat,
4291 GLsizei width,
4292 GLsizei height,
4293 GLsizei depth)
4294{
4295 Extents size(width, height, depth);
4296 Texture *texture = getTargetTexture(target);
4297 handleError(texture->setStorage(this, target, levels, internalFormat, size));
4298}
4299
Jamie Madillc1d770e2017-04-13 17:31:24 -04004300GLenum Context::checkFramebufferStatus(GLenum target)
4301{
4302 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4303 ASSERT(framebuffer);
4304
4305 return framebuffer->checkStatus(this);
4306}
4307
4308void Context::compileShader(GLuint shader)
4309{
4310 Shader *shaderObject = GetValidShader(this, shader);
4311 if (!shaderObject)
4312 {
4313 return;
4314 }
4315 shaderObject->compile(this);
4316}
4317
4318void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
4319{
4320 for (int i = 0; i < n; i++)
4321 {
4322 deleteBuffer(buffers[i]);
4323 }
4324}
4325
4326void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
4327{
4328 for (int i = 0; i < n; i++)
4329 {
4330 if (framebuffers[i] != 0)
4331 {
4332 deleteFramebuffer(framebuffers[i]);
4333 }
4334 }
4335}
4336
4337void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
4338{
4339 for (int i = 0; i < n; i++)
4340 {
4341 deleteRenderbuffer(renderbuffers[i]);
4342 }
4343}
4344
4345void Context::deleteTextures(GLsizei n, const GLuint *textures)
4346{
4347 for (int i = 0; i < n; i++)
4348 {
4349 if (textures[i] != 0)
4350 {
4351 deleteTexture(textures[i]);
4352 }
4353 }
4354}
4355
4356void Context::detachShader(GLuint program, GLuint shader)
4357{
4358 Program *programObject = getProgram(program);
4359 ASSERT(programObject);
4360
4361 Shader *shaderObject = getShader(shader);
4362 ASSERT(shaderObject);
4363
4364 programObject->detachShader(this, shaderObject);
4365}
4366
4367void Context::genBuffers(GLsizei n, GLuint *buffers)
4368{
4369 for (int i = 0; i < n; i++)
4370 {
4371 buffers[i] = createBuffer();
4372 }
4373}
4374
4375void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
4376{
4377 for (int i = 0; i < n; i++)
4378 {
4379 framebuffers[i] = createFramebuffer();
4380 }
4381}
4382
4383void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
4384{
4385 for (int i = 0; i < n; i++)
4386 {
4387 renderbuffers[i] = createRenderbuffer();
4388 }
4389}
4390
4391void Context::genTextures(GLsizei n, GLuint *textures)
4392{
4393 for (int i = 0; i < n; i++)
4394 {
4395 textures[i] = createTexture();
4396 }
4397}
4398
4399void Context::getActiveAttrib(GLuint program,
4400 GLuint index,
4401 GLsizei bufsize,
4402 GLsizei *length,
4403 GLint *size,
4404 GLenum *type,
4405 GLchar *name)
4406{
4407 Program *programObject = getProgram(program);
4408 ASSERT(programObject);
4409 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
4410}
4411
4412void Context::getActiveUniform(GLuint program,
4413 GLuint index,
4414 GLsizei bufsize,
4415 GLsizei *length,
4416 GLint *size,
4417 GLenum *type,
4418 GLchar *name)
4419{
4420 Program *programObject = getProgram(program);
4421 ASSERT(programObject);
4422 programObject->getActiveUniform(index, bufsize, length, size, type, name);
4423}
4424
4425void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
4426{
4427 Program *programObject = getProgram(program);
4428 ASSERT(programObject);
4429 programObject->getAttachedShaders(maxcount, count, shaders);
4430}
4431
4432GLint Context::getAttribLocation(GLuint program, const GLchar *name)
4433{
4434 Program *programObject = getProgram(program);
4435 ASSERT(programObject);
4436 return programObject->getAttributeLocation(name);
4437}
4438
4439void Context::getBooleanv(GLenum pname, GLboolean *params)
4440{
4441 GLenum nativeType;
4442 unsigned int numParams = 0;
4443 getQueryParameterInfo(pname, &nativeType, &numParams);
4444
4445 if (nativeType == GL_BOOL)
4446 {
4447 getBooleanvImpl(pname, params);
4448 }
4449 else
4450 {
4451 CastStateValues(this, nativeType, pname, numParams, params);
4452 }
4453}
4454
4455void Context::getFloatv(GLenum pname, GLfloat *params)
4456{
4457 GLenum nativeType;
4458 unsigned int numParams = 0;
4459 getQueryParameterInfo(pname, &nativeType, &numParams);
4460
4461 if (nativeType == GL_FLOAT)
4462 {
4463 getFloatvImpl(pname, params);
4464 }
4465 else
4466 {
4467 CastStateValues(this, nativeType, pname, numParams, params);
4468 }
4469}
4470
4471void Context::getIntegerv(GLenum pname, GLint *params)
4472{
4473 GLenum nativeType;
4474 unsigned int numParams = 0;
4475 getQueryParameterInfo(pname, &nativeType, &numParams);
4476
4477 if (nativeType == GL_INT)
4478 {
4479 getIntegervImpl(pname, params);
4480 }
4481 else
4482 {
4483 CastStateValues(this, nativeType, pname, numParams, params);
4484 }
4485}
4486
4487void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
4488{
4489 Program *programObject = getProgram(program);
4490 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04004491 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004492}
4493
Jamie Madillbe849e42017-05-02 15:49:00 -04004494void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04004495{
4496 Program *programObject = getProgram(program);
4497 ASSERT(programObject);
4498 programObject->getInfoLog(bufsize, length, infolog);
4499}
4500
4501void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
4502{
4503 Shader *shaderObject = getShader(shader);
4504 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004505 QueryShaderiv(this, shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004506}
4507
4508void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
4509{
4510 Shader *shaderObject = getShader(shader);
4511 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004512 shaderObject->getInfoLog(this, bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004513}
4514
4515void Context::getShaderPrecisionFormat(GLenum shadertype,
4516 GLenum precisiontype,
4517 GLint *range,
4518 GLint *precision)
4519{
4520 // TODO(jmadill): Compute shaders.
4521
4522 switch (shadertype)
4523 {
4524 case GL_VERTEX_SHADER:
4525 switch (precisiontype)
4526 {
4527 case GL_LOW_FLOAT:
4528 mCaps.vertexLowpFloat.get(range, precision);
4529 break;
4530 case GL_MEDIUM_FLOAT:
4531 mCaps.vertexMediumpFloat.get(range, precision);
4532 break;
4533 case GL_HIGH_FLOAT:
4534 mCaps.vertexHighpFloat.get(range, precision);
4535 break;
4536
4537 case GL_LOW_INT:
4538 mCaps.vertexLowpInt.get(range, precision);
4539 break;
4540 case GL_MEDIUM_INT:
4541 mCaps.vertexMediumpInt.get(range, precision);
4542 break;
4543 case GL_HIGH_INT:
4544 mCaps.vertexHighpInt.get(range, precision);
4545 break;
4546
4547 default:
4548 UNREACHABLE();
4549 return;
4550 }
4551 break;
4552
4553 case GL_FRAGMENT_SHADER:
4554 switch (precisiontype)
4555 {
4556 case GL_LOW_FLOAT:
4557 mCaps.fragmentLowpFloat.get(range, precision);
4558 break;
4559 case GL_MEDIUM_FLOAT:
4560 mCaps.fragmentMediumpFloat.get(range, precision);
4561 break;
4562 case GL_HIGH_FLOAT:
4563 mCaps.fragmentHighpFloat.get(range, precision);
4564 break;
4565
4566 case GL_LOW_INT:
4567 mCaps.fragmentLowpInt.get(range, precision);
4568 break;
4569 case GL_MEDIUM_INT:
4570 mCaps.fragmentMediumpInt.get(range, precision);
4571 break;
4572 case GL_HIGH_INT:
4573 mCaps.fragmentHighpInt.get(range, precision);
4574 break;
4575
4576 default:
4577 UNREACHABLE();
4578 return;
4579 }
4580 break;
4581
4582 default:
4583 UNREACHABLE();
4584 return;
4585 }
4586}
4587
4588void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
4589{
4590 Shader *shaderObject = getShader(shader);
4591 ASSERT(shaderObject);
4592 shaderObject->getSource(bufsize, length, source);
4593}
4594
4595void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
4596{
4597 Program *programObject = getProgram(program);
4598 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04004599 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004600}
4601
4602void Context::getUniformiv(GLuint program, GLint location, GLint *params)
4603{
4604 Program *programObject = getProgram(program);
4605 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04004606 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004607}
4608
4609GLint Context::getUniformLocation(GLuint program, const GLchar *name)
4610{
4611 Program *programObject = getProgram(program);
4612 ASSERT(programObject);
4613 return programObject->getUniformLocation(name);
4614}
4615
4616GLboolean Context::isBuffer(GLuint buffer)
4617{
4618 if (buffer == 0)
4619 {
4620 return GL_FALSE;
4621 }
4622
4623 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
4624}
4625
4626GLboolean Context::isEnabled(GLenum cap)
4627{
4628 return mGLState.getEnableFeature(cap);
4629}
4630
4631GLboolean Context::isFramebuffer(GLuint framebuffer)
4632{
4633 if (framebuffer == 0)
4634 {
4635 return GL_FALSE;
4636 }
4637
4638 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
4639}
4640
4641GLboolean Context::isProgram(GLuint program)
4642{
4643 if (program == 0)
4644 {
4645 return GL_FALSE;
4646 }
4647
4648 return (getProgram(program) ? GL_TRUE : GL_FALSE);
4649}
4650
4651GLboolean Context::isRenderbuffer(GLuint renderbuffer)
4652{
4653 if (renderbuffer == 0)
4654 {
4655 return GL_FALSE;
4656 }
4657
4658 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
4659}
4660
4661GLboolean Context::isShader(GLuint shader)
4662{
4663 if (shader == 0)
4664 {
4665 return GL_FALSE;
4666 }
4667
4668 return (getShader(shader) ? GL_TRUE : GL_FALSE);
4669}
4670
4671GLboolean Context::isTexture(GLuint texture)
4672{
4673 if (texture == 0)
4674 {
4675 return GL_FALSE;
4676 }
4677
4678 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
4679}
4680
4681void Context::linkProgram(GLuint program)
4682{
4683 Program *programObject = getProgram(program);
4684 ASSERT(programObject);
4685 handleError(programObject->link(this));
Martin Radev0abb7a22017-08-28 15:34:45 +03004686 mGLState.onProgramExecutableChange(programObject);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004687}
4688
4689void Context::releaseShaderCompiler()
4690{
Jamie Madill4928b7c2017-06-20 12:57:39 -04004691 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004692}
4693
4694void Context::shaderBinary(GLsizei n,
4695 const GLuint *shaders,
4696 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04004697 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04004698 GLsizei length)
4699{
4700 // No binary shader formats are supported.
4701 UNIMPLEMENTED();
4702}
4703
4704void Context::shaderSource(GLuint shader,
4705 GLsizei count,
4706 const GLchar *const *string,
4707 const GLint *length)
4708{
4709 Shader *shaderObject = getShader(shader);
4710 ASSERT(shaderObject);
4711 shaderObject->setSource(count, string, length);
4712}
4713
4714void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
4715{
4716 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
4717}
4718
4719void Context::stencilMask(GLuint mask)
4720{
4721 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
4722}
4723
4724void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
4725{
4726 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
4727}
4728
4729void Context::uniform1f(GLint location, GLfloat x)
4730{
4731 Program *program = mGLState.getProgram();
4732 program->setUniform1fv(location, 1, &x);
4733}
4734
4735void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
4736{
4737 Program *program = mGLState.getProgram();
4738 program->setUniform1fv(location, count, v);
4739}
4740
4741void Context::uniform1i(GLint location, GLint x)
4742{
4743 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04004744 if (program->setUniform1iv(location, 1, &x) == Program::SetUniformResult::SamplerChanged)
4745 {
4746 mGLState.setObjectDirty(GL_PROGRAM);
4747 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04004748}
4749
4750void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
4751{
4752 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04004753 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
4754 {
4755 mGLState.setObjectDirty(GL_PROGRAM);
4756 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04004757}
4758
4759void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
4760{
4761 GLfloat xy[2] = {x, y};
4762 Program *program = mGLState.getProgram();
4763 program->setUniform2fv(location, 1, xy);
4764}
4765
4766void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
4767{
4768 Program *program = mGLState.getProgram();
4769 program->setUniform2fv(location, count, v);
4770}
4771
4772void Context::uniform2i(GLint location, GLint x, GLint y)
4773{
4774 GLint xy[2] = {x, y};
4775 Program *program = mGLState.getProgram();
4776 program->setUniform2iv(location, 1, xy);
4777}
4778
4779void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
4780{
4781 Program *program = mGLState.getProgram();
4782 program->setUniform2iv(location, count, v);
4783}
4784
4785void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
4786{
4787 GLfloat xyz[3] = {x, y, z};
4788 Program *program = mGLState.getProgram();
4789 program->setUniform3fv(location, 1, xyz);
4790}
4791
4792void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
4793{
4794 Program *program = mGLState.getProgram();
4795 program->setUniform3fv(location, count, v);
4796}
4797
4798void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
4799{
4800 GLint xyz[3] = {x, y, z};
4801 Program *program = mGLState.getProgram();
4802 program->setUniform3iv(location, 1, xyz);
4803}
4804
4805void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
4806{
4807 Program *program = mGLState.getProgram();
4808 program->setUniform3iv(location, count, v);
4809}
4810
4811void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4812{
4813 GLfloat xyzw[4] = {x, y, z, w};
4814 Program *program = mGLState.getProgram();
4815 program->setUniform4fv(location, 1, xyzw);
4816}
4817
4818void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
4819{
4820 Program *program = mGLState.getProgram();
4821 program->setUniform4fv(location, count, v);
4822}
4823
4824void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
4825{
4826 GLint xyzw[4] = {x, y, z, w};
4827 Program *program = mGLState.getProgram();
4828 program->setUniform4iv(location, 1, xyzw);
4829}
4830
4831void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
4832{
4833 Program *program = mGLState.getProgram();
4834 program->setUniform4iv(location, count, v);
4835}
4836
4837void Context::uniformMatrix2fv(GLint location,
4838 GLsizei count,
4839 GLboolean transpose,
4840 const GLfloat *value)
4841{
4842 Program *program = mGLState.getProgram();
4843 program->setUniformMatrix2fv(location, count, transpose, value);
4844}
4845
4846void Context::uniformMatrix3fv(GLint location,
4847 GLsizei count,
4848 GLboolean transpose,
4849 const GLfloat *value)
4850{
4851 Program *program = mGLState.getProgram();
4852 program->setUniformMatrix3fv(location, count, transpose, value);
4853}
4854
4855void Context::uniformMatrix4fv(GLint location,
4856 GLsizei count,
4857 GLboolean transpose,
4858 const GLfloat *value)
4859{
4860 Program *program = mGLState.getProgram();
4861 program->setUniformMatrix4fv(location, count, transpose, value);
4862}
4863
4864void Context::validateProgram(GLuint program)
4865{
4866 Program *programObject = getProgram(program);
4867 ASSERT(programObject);
4868 programObject->validate(mCaps);
4869}
4870
Jamie Madilld04908b2017-06-09 14:15:35 -04004871void Context::getProgramBinary(GLuint program,
4872 GLsizei bufSize,
4873 GLsizei *length,
4874 GLenum *binaryFormat,
4875 void *binary)
4876{
4877 Program *programObject = getProgram(program);
4878 ASSERT(programObject != nullptr);
4879
4880 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
4881}
4882
4883void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
4884{
4885 Program *programObject = getProgram(program);
4886 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04004887
Jamie Madilld04908b2017-06-09 14:15:35 -04004888 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
4889}
4890
Jamie Madillff325f12017-08-26 15:06:05 -04004891void Context::uniform1ui(GLint location, GLuint v0)
4892{
4893 Program *program = mGLState.getProgram();
4894 program->setUniform1uiv(location, 1, &v0);
4895}
4896
4897void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
4898{
4899 Program *program = mGLState.getProgram();
4900 const GLuint xy[] = {v0, v1};
4901 program->setUniform2uiv(location, 1, xy);
4902}
4903
4904void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
4905{
4906 Program *program = mGLState.getProgram();
4907 const GLuint xyz[] = {v0, v1, v2};
4908 program->setUniform3uiv(location, 1, xyz);
4909}
4910
4911void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
4912{
4913 Program *program = mGLState.getProgram();
4914 const GLuint xyzw[] = {v0, v1, v2, v3};
4915 program->setUniform4uiv(location, 1, xyzw);
4916}
4917
4918void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
4919{
4920 Program *program = mGLState.getProgram();
4921 program->setUniform1uiv(location, count, value);
4922}
4923void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
4924{
4925 Program *program = mGLState.getProgram();
4926 program->setUniform2uiv(location, count, value);
4927}
4928
4929void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
4930{
4931 Program *program = mGLState.getProgram();
4932 program->setUniform3uiv(location, count, value);
4933}
4934
4935void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
4936{
4937 Program *program = mGLState.getProgram();
4938 program->setUniform4uiv(location, count, value);
4939}
4940
Jamie Madillf0e04492017-08-26 15:28:42 -04004941void Context::genQueries(GLsizei n, GLuint *ids)
4942{
4943 for (GLsizei i = 0; i < n; i++)
4944 {
4945 GLuint handle = mQueryHandleAllocator.allocate();
4946 mQueryMap.assign(handle, nullptr);
4947 ids[i] = handle;
4948 }
4949}
4950
4951void Context::deleteQueries(GLsizei n, const GLuint *ids)
4952{
4953 for (int i = 0; i < n; i++)
4954 {
4955 GLuint query = ids[i];
4956
4957 Query *queryObject = nullptr;
4958 if (mQueryMap.erase(query, &queryObject))
4959 {
4960 mQueryHandleAllocator.release(query);
4961 if (queryObject)
4962 {
4963 queryObject->release(this);
4964 }
4965 }
4966 }
4967}
4968
4969GLboolean Context::isQuery(GLuint id)
4970{
4971 return (getQuery(id, false, GL_NONE) != nullptr) ? GL_TRUE : GL_FALSE;
4972}
4973
Jamie Madillc8c95812017-08-26 18:40:09 -04004974void Context::uniformMatrix2x3fv(GLint location,
4975 GLsizei count,
4976 GLboolean transpose,
4977 const GLfloat *value)
4978{
4979 Program *program = mGLState.getProgram();
4980 program->setUniformMatrix2x3fv(location, count, transpose, value);
4981}
4982
4983void Context::uniformMatrix3x2fv(GLint location,
4984 GLsizei count,
4985 GLboolean transpose,
4986 const GLfloat *value)
4987{
4988 Program *program = mGLState.getProgram();
4989 program->setUniformMatrix3x2fv(location, count, transpose, value);
4990}
4991
4992void Context::uniformMatrix2x4fv(GLint location,
4993 GLsizei count,
4994 GLboolean transpose,
4995 const GLfloat *value)
4996{
4997 Program *program = mGLState.getProgram();
4998 program->setUniformMatrix2x4fv(location, count, transpose, value);
4999}
5000
5001void Context::uniformMatrix4x2fv(GLint location,
5002 GLsizei count,
5003 GLboolean transpose,
5004 const GLfloat *value)
5005{
5006 Program *program = mGLState.getProgram();
5007 program->setUniformMatrix4x2fv(location, count, transpose, value);
5008}
5009
5010void Context::uniformMatrix3x4fv(GLint location,
5011 GLsizei count,
5012 GLboolean transpose,
5013 const GLfloat *value)
5014{
5015 Program *program = mGLState.getProgram();
5016 program->setUniformMatrix3x4fv(location, count, transpose, value);
5017}
5018
5019void Context::uniformMatrix4x3fv(GLint location,
5020 GLsizei count,
5021 GLboolean transpose,
5022 const GLfloat *value)
5023{
5024 Program *program = mGLState.getProgram();
5025 program->setUniformMatrix4x3fv(location, count, transpose, value);
5026}
5027
Jamie Madilld7576732017-08-26 18:49:50 -04005028void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
5029{
5030 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5031 {
5032 GLuint vertexArray = arrays[arrayIndex];
5033
5034 if (arrays[arrayIndex] != 0)
5035 {
5036 VertexArray *vertexArrayObject = nullptr;
5037 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
5038 {
5039 if (vertexArrayObject != nullptr)
5040 {
5041 detachVertexArray(vertexArray);
5042 vertexArrayObject->onDestroy(this);
5043 }
5044
5045 mVertexArrayHandleAllocator.release(vertexArray);
5046 }
5047 }
5048 }
5049}
5050
5051void Context::genVertexArrays(GLsizei n, GLuint *arrays)
5052{
5053 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5054 {
5055 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
5056 mVertexArrayMap.assign(vertexArray, nullptr);
5057 arrays[arrayIndex] = vertexArray;
5058 }
5059}
5060
5061bool Context::isVertexArray(GLuint array)
5062{
5063 if (array == 0)
5064 {
5065 return GL_FALSE;
5066 }
5067
5068 VertexArray *vao = getVertexArray(array);
5069 return (vao != nullptr ? GL_TRUE : GL_FALSE);
5070}
5071
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04005072void Context::endTransformFeedback()
5073{
5074 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5075 transformFeedback->end(this);
5076}
5077
5078void Context::transformFeedbackVaryings(GLuint program,
5079 GLsizei count,
5080 const GLchar *const *varyings,
5081 GLenum bufferMode)
5082{
5083 Program *programObject = getProgram(program);
5084 ASSERT(programObject);
5085 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
5086}
5087
5088void Context::getTransformFeedbackVarying(GLuint program,
5089 GLuint index,
5090 GLsizei bufSize,
5091 GLsizei *length,
5092 GLsizei *size,
5093 GLenum *type,
5094 GLchar *name)
5095{
5096 Program *programObject = getProgram(program);
5097 ASSERT(programObject);
5098 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
5099}
5100
5101void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
5102{
5103 for (int i = 0; i < n; i++)
5104 {
5105 GLuint transformFeedback = ids[i];
5106 if (transformFeedback == 0)
5107 {
5108 continue;
5109 }
5110
5111 TransformFeedback *transformFeedbackObject = nullptr;
5112 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
5113 {
5114 if (transformFeedbackObject != nullptr)
5115 {
5116 detachTransformFeedback(transformFeedback);
5117 transformFeedbackObject->release(this);
5118 }
5119
5120 mTransformFeedbackHandleAllocator.release(transformFeedback);
5121 }
5122 }
5123}
5124
5125void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
5126{
5127 for (int i = 0; i < n; i++)
5128 {
5129 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
5130 mTransformFeedbackMap.assign(transformFeedback, nullptr);
5131 ids[i] = transformFeedback;
5132 }
5133}
5134
5135bool Context::isTransformFeedback(GLuint id)
5136{
5137 if (id == 0)
5138 {
5139 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
5140 // returns FALSE
5141 return GL_FALSE;
5142 }
5143
5144 const TransformFeedback *transformFeedback = getTransformFeedback(id);
5145 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
5146}
5147
5148void Context::pauseTransformFeedback()
5149{
5150 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5151 transformFeedback->pause();
5152}
5153
5154void Context::resumeTransformFeedback()
5155{
5156 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5157 transformFeedback->resume();
5158}
5159
Jamie Madill12e957f2017-08-26 21:42:26 -04005160void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
5161{
5162 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04005163 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04005164}
5165
5166GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
5167{
5168 const Program *programObject = getProgram(program);
5169 return programObject->getFragDataLocation(name);
5170}
5171
5172void Context::getUniformIndices(GLuint program,
5173 GLsizei uniformCount,
5174 const GLchar *const *uniformNames,
5175 GLuint *uniformIndices)
5176{
5177 const Program *programObject = getProgram(program);
5178 if (!programObject->isLinked())
5179 {
5180 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5181 {
5182 uniformIndices[uniformId] = GL_INVALID_INDEX;
5183 }
5184 }
5185 else
5186 {
5187 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5188 {
5189 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
5190 }
5191 }
5192}
5193
5194void Context::getActiveUniformsiv(GLuint program,
5195 GLsizei uniformCount,
5196 const GLuint *uniformIndices,
5197 GLenum pname,
5198 GLint *params)
5199{
5200 const Program *programObject = getProgram(program);
5201 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5202 {
5203 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08005204 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04005205 }
5206}
5207
5208GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
5209{
5210 const Program *programObject = getProgram(program);
5211 return programObject->getUniformBlockIndex(uniformBlockName);
5212}
5213
5214void Context::getActiveUniformBlockiv(GLuint program,
5215 GLuint uniformBlockIndex,
5216 GLenum pname,
5217 GLint *params)
5218{
5219 const Program *programObject = getProgram(program);
5220 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
5221}
5222
5223void Context::getActiveUniformBlockName(GLuint program,
5224 GLuint uniformBlockIndex,
5225 GLsizei bufSize,
5226 GLsizei *length,
5227 GLchar *uniformBlockName)
5228{
5229 const Program *programObject = getProgram(program);
5230 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
5231}
5232
5233void Context::uniformBlockBinding(GLuint program,
5234 GLuint uniformBlockIndex,
5235 GLuint uniformBlockBinding)
5236{
5237 Program *programObject = getProgram(program);
5238 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
5239}
5240
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005241GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
5242{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005243 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
5244 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005245
Jamie Madill70b5bb02017-08-28 13:32:37 -04005246 Sync *syncObject = getSync(syncHandle);
5247 Error error = syncObject->set(condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005248 if (error.isError())
5249 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04005250 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005251 handleError(error);
5252 return nullptr;
5253 }
5254
Jamie Madill70b5bb02017-08-28 13:32:37 -04005255 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005256}
5257
5258GLboolean Context::isSync(GLsync sync)
5259{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005260 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005261}
5262
5263GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
5264{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005265 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005266
5267 GLenum result = GL_WAIT_FAILED;
5268 handleError(syncObject->clientWait(flags, timeout, &result));
5269 return result;
5270}
5271
5272void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
5273{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005274 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005275 handleError(syncObject->serverWait(flags, timeout));
5276}
5277
5278void Context::getInteger64v(GLenum pname, GLint64 *params)
5279{
5280 GLenum nativeType = GL_NONE;
5281 unsigned int numParams = 0;
5282 getQueryParameterInfo(pname, &nativeType, &numParams);
5283
5284 if (nativeType == GL_INT_64_ANGLEX)
5285 {
5286 getInteger64vImpl(pname, params);
5287 }
5288 else
5289 {
5290 CastStateValues(this, nativeType, pname, numParams, params);
5291 }
5292}
5293
Jamie Madill3ef140a2017-08-26 23:11:21 -04005294void Context::getBufferParameteri64v(GLenum target, GLenum pname, GLint64 *params)
5295{
5296 Buffer *buffer = mGLState.getTargetBuffer(target);
5297 QueryBufferParameteri64v(buffer, pname, params);
5298}
5299
5300void Context::genSamplers(GLsizei count, GLuint *samplers)
5301{
5302 for (int i = 0; i < count; i++)
5303 {
5304 samplers[i] = mState.mSamplers->createSampler();
5305 }
5306}
5307
5308void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
5309{
5310 for (int i = 0; i < count; i++)
5311 {
5312 GLuint sampler = samplers[i];
5313
5314 if (mState.mSamplers->getSampler(sampler))
5315 {
5316 detachSampler(sampler);
5317 }
5318
5319 mState.mSamplers->deleteObject(this, sampler);
5320 }
5321}
5322
5323void Context::getInternalformativ(GLenum target,
5324 GLenum internalformat,
5325 GLenum pname,
5326 GLsizei bufSize,
5327 GLint *params)
5328{
5329 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
5330 QueryInternalFormativ(formatCaps, pname, bufSize, params);
5331}
5332
Jamie Madill81c2e252017-09-09 23:32:46 -04005333void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5334{
5335 Program *programObject = getProgram(program);
5336 ASSERT(programObject);
5337 if (programObject->setUniform1iv(location, count, value) ==
5338 Program::SetUniformResult::SamplerChanged)
5339 {
5340 mGLState.setObjectDirty(GL_PROGRAM);
5341 }
5342}
5343
5344void Context::onTextureChange(const Texture *texture)
5345{
5346 // Conservatively assume all textures are dirty.
5347 // TODO(jmadill): More fine-grained update.
5348 mGLState.setObjectDirty(GL_TEXTURE);
5349}
5350
Yunchao Hea336b902017-08-02 16:05:21 +08005351void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
5352{
5353 for (int i = 0; i < count; i++)
5354 {
5355 pipelines[i] = createProgramPipeline();
5356 }
5357}
5358
5359void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
5360{
5361 for (int i = 0; i < count; i++)
5362 {
5363 if (pipelines[i] != 0)
5364 {
5365 deleteProgramPipeline(pipelines[i]);
5366 }
5367 }
5368}
5369
5370GLboolean Context::isProgramPipeline(GLuint pipeline)
5371{
5372 if (pipeline == 0)
5373 {
5374 return GL_FALSE;
5375 }
5376
5377 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
5378}
5379
Jamie Madillc29968b2016-01-20 11:17:23 -05005380} // namespace gl