blob: 64b9d4f36916ffe14c283b1e9d203fd88a4a424c [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 Lang111a99e2017-10-17 10:58:41 -04002569bool Context::isExtensionRequestable(const char *name)
2570{
2571 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2572 auto extension = extensionInfos.find(name);
2573
2574 const Extensions &nativeExtensions = mImplementation->getNativeExtensions();
2575 return extension != extensionInfos.end() && extension->second.Requestable &&
2576 nativeExtensions.*(extension->second.ExtensionsMember);
2577}
2578
Geoff Langc339c4e2016-11-29 10:37:36 -05002579void Context::requestExtension(const char *name)
2580{
2581 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2582 ASSERT(extensionInfos.find(name) != extensionInfos.end());
2583 const auto &extension = extensionInfos.at(name);
2584 ASSERT(extension.Requestable);
Geoff Lang111a99e2017-10-17 10:58:41 -04002585 ASSERT(mImplementation->getNativeExtensions().*(extension.ExtensionsMember));
Geoff Langc339c4e2016-11-29 10:37:36 -05002586
2587 if (mExtensions.*(extension.ExtensionsMember))
2588 {
2589 // Extension already enabled
2590 return;
2591 }
2592
2593 mExtensions.*(extension.ExtensionsMember) = true;
2594 updateCaps();
2595 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08002596
Jamie Madill2f348d22017-06-05 10:50:59 -04002597 // Release the shader compiler so it will be re-created with the requested extensions enabled.
2598 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04002599
Jamie Madill81c2e252017-09-09 23:32:46 -04002600 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
2601 // sampleable.
2602 mState.mTextures->signalAllTexturesDirty();
Geoff Lang9aded172017-04-05 11:07:56 -04002603 for (auto &zeroTexture : mZeroTextures)
2604 {
Jamie Madill05b35b22017-10-03 09:01:44 -04002605 zeroTexture.second->signalDirty(InitState::Initialized);
Geoff Lang9aded172017-04-05 11:07:56 -04002606 }
2607
2608 mState.mFramebuffers->invalidateFramebufferComplenessCache();
Geoff Langc339c4e2016-11-29 10:37:36 -05002609}
2610
2611size_t Context::getRequestableExtensionStringCount() const
2612{
2613 return mRequestableExtensionStrings.size();
2614}
2615
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002616void Context::beginTransformFeedback(GLenum primitiveMode)
2617{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002618 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002619 ASSERT(transformFeedback != nullptr);
2620 ASSERT(!transformFeedback->isPaused());
2621
Jamie Madill6c1f6712017-02-14 19:08:04 -05002622 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002623}
2624
2625bool Context::hasActiveTransformFeedback(GLuint program) const
2626{
2627 for (auto pair : mTransformFeedbackMap)
2628 {
2629 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
2630 {
2631 return true;
2632 }
2633 }
2634 return false;
2635}
2636
Geoff Langb433e872017-10-05 14:01:47 -04002637void Context::initCaps(const egl::DisplayExtensions &displayExtensions, bool robustResourceInit)
Geoff Lang493daf52014-07-03 13:38:44 -04002638{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002639 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04002640
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002641 mExtensions = mImplementation->getNativeExtensions();
Geoff Lang493daf52014-07-03 13:38:44 -04002642
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002643 mLimitations = mImplementation->getNativeLimitations();
Austin Kinross02df7962015-07-01 10:03:42 -07002644
Geoff Langeb66a6e2016-10-31 13:06:12 -04002645 if (getClientVersion() < Version(3, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002646 {
2647 // Disable ES3+ extensions
Jamie Madill231c7f52017-04-26 13:45:37 -04002648 mExtensions.colorBufferFloat = false;
Geoff Langb66a9092016-05-16 15:59:14 -04002649 mExtensions.eglImageExternalEssl3 = false;
Vincent Lang25ab4512016-05-13 18:13:59 +02002650 mExtensions.textureNorm16 = false;
Martin Radev137032d2017-07-13 10:11:12 +03002651 mExtensions.multiview = false;
2652 mExtensions.maxViews = 1u;
Geoff Lang493daf52014-07-03 13:38:44 -04002653 }
2654
Geoff Langeb66a6e2016-10-31 13:06:12 -04002655 if (getClientVersion() > Version(2, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002656 {
2657 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
Jamie Madill231c7f52017-04-26 13:45:37 -04002658 // mExtensions.sRGB = false;
Geoff Lang493daf52014-07-03 13:38:44 -04002659 }
2660
Jamie Madill00ed7a12016-05-19 13:13:38 -04002661 // Some extensions are always available because they are implemented in the GL layer.
Jamie Madill231c7f52017-04-26 13:45:37 -04002662 mExtensions.bindUniformLocation = true;
2663 mExtensions.vertexArrayObject = true;
Geoff Langf41a7152016-09-19 15:11:17 -04002664 mExtensions.bindGeneratesResource = true;
Geoff Langfeb8c682017-02-13 16:07:35 -05002665 mExtensions.clientArrays = true;
Geoff Langc339c4e2016-11-29 10:37:36 -05002666 mExtensions.requestExtension = true;
Jamie Madill00ed7a12016-05-19 13:13:38 -04002667
2668 // Enable the no error extension if the context was created with the flag.
2669 mExtensions.noError = mSkipValidation;
2670
Corentin Wallezccab69d2017-01-27 16:57:15 -05002671 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Corentin Wallezc295e512017-01-27 17:47:50 -05002672 mExtensions.surfacelessContext = displayExtensions.surfacelessContext;
Corentin Wallezccab69d2017-01-27 16:57:15 -05002673
Geoff Lang70d0f492015-12-10 17:45:46 -05002674 // Explicitly enable GL_KHR_debug
2675 mExtensions.debug = true;
2676 mExtensions.maxDebugMessageLength = 1024;
2677 mExtensions.maxDebugLoggedMessages = 1024;
2678 mExtensions.maxDebugGroupStackDepth = 1024;
2679 mExtensions.maxLabelLength = 1024;
2680
Geoff Langff5b2d52016-09-07 11:32:23 -04002681 // Explicitly enable GL_ANGLE_robust_client_memory
2682 mExtensions.robustClientMemory = true;
2683
Jamie Madille08a1d32017-03-07 17:24:06 -05002684 // Determine robust resource init availability from EGL.
Geoff Langb433e872017-10-05 14:01:47 -04002685 mExtensions.robustResourceInitialization = robustResourceInit;
Jamie Madille08a1d32017-03-07 17:24:06 -05002686
Jiajia Qin8a7b3a02017-08-25 16:05:48 +08002687 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
2688 // supports it.
2689 mExtensions.robustBufferAccessBehavior =
2690 mRobustAccess && mExtensions.robustBufferAccessBehavior;
2691
Jamie Madillc43be722017-07-13 16:22:14 -04002692 // Enable the cache control query unconditionally.
2693 mExtensions.programCacheControl = true;
2694
Geoff Lang301d1612014-07-09 10:34:37 -04002695 // Apply implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04002696 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002697
Jamie Madill0f80ed82017-09-19 00:24:56 -04002698 if (getClientVersion() < ES_3_1)
2699 {
2700 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
2701 }
2702 else
2703 {
2704 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
2705 }
Geoff Lang301d1612014-07-09 10:34:37 -04002706
Jamie Madill0f80ed82017-09-19 00:24:56 -04002707 LimitCap(&mCaps.maxVertexUniformBlocks, IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
2708 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
2709 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
2710
2711 // Limit textures as well, so we can use fast bitsets with texture bindings.
2712 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
2713 LimitCap(&mCaps.maxVertexTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
2714 LimitCap(&mCaps.maxTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04002715
Jiawei Shaodb342272017-09-27 10:21:45 +08002716 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
2717
Geoff Langc287ea62016-09-16 14:46:51 -04002718 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002719 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04002720 for (const auto &extensionInfo : GetExtensionInfoMap())
2721 {
2722 // If this context is for WebGL, disable all enableable extensions
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002723 if (mWebGLContext && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04002724 {
2725 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
2726 }
2727 }
2728
2729 // Generate texture caps
2730 updateCaps();
2731}
2732
2733void Context::updateCaps()
2734{
Geoff Lang900013c2014-07-07 11:32:19 -04002735 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002736 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04002737
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002738 for (auto capsIt : mImplementation->getNativeTextureCaps())
Geoff Lang493daf52014-07-03 13:38:44 -04002739 {
Geoff Langca271392017-04-05 12:30:00 -04002740 GLenum sizedInternalFormat = capsIt.first;
Jamie Madill231c7f52017-04-26 13:45:37 -04002741 TextureCaps formatCaps = capsIt.second;
Geoff Lang493daf52014-07-03 13:38:44 -04002742
Geoff Langca271392017-04-05 12:30:00 -04002743 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04002744
Geoff Lang0d8b7242015-09-09 14:56:53 -04002745 // Update the format caps based on the client version and extensions.
2746 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
2747 // ES3.
2748 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002749 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002750 formatCaps.renderable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002751 formatCaps.renderable && formatInfo.renderSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002752 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002753 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04002754
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002755 // OpenGL ES does not support multisampling with non-rendererable formats
2756 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Olli Etuaho50c562d2017-06-06 14:43:30 +03002757 if (!formatCaps.renderable ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002758 (getClientVersion() < ES_3_1 &&
2759 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04002760 {
Geoff Langd87878e2014-09-19 15:42:59 -04002761 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04002762 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03002763 else
2764 {
2765 // We may have limited the max samples for some required renderbuffer formats due to
2766 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
2767 GLuint formatMaxSamples = formatCaps.getMaxSamples();
2768
2769 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
2770 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
2771 // exception of signed and unsigned integer formats."
2772 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
2773 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
2774 {
2775 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
2776 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
2777 }
2778
2779 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
2780 if (getClientVersion() >= ES_3_1)
2781 {
2782 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
2783 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
2784 // the exception that the signed and unsigned integer formats are required only to
2785 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
2786 // multisamples, which must be at least one."
2787 if (formatInfo.componentType == GL_INT ||
2788 formatInfo.componentType == GL_UNSIGNED_INT)
2789 {
2790 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
2791 }
2792
2793 // GLES 3.1 section 19.3.1.
2794 if (formatCaps.texturable)
2795 {
2796 if (formatInfo.depthBits > 0)
2797 {
2798 mCaps.maxDepthTextureSamples =
2799 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
2800 }
2801 else if (formatInfo.redBits > 0)
2802 {
2803 mCaps.maxColorTextureSamples =
2804 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
2805 }
2806 }
2807 }
2808 }
Geoff Langd87878e2014-09-19 15:42:59 -04002809
2810 if (formatCaps.texturable && formatInfo.compressed)
2811 {
Geoff Langca271392017-04-05 12:30:00 -04002812 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04002813 }
2814
Geoff Langca271392017-04-05 12:30:00 -04002815 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04002816 }
Jamie Madill32447362017-06-28 14:53:52 -04002817
2818 // If program binary is disabled, blank out the memory cache pointer.
2819 if (!mImplementation->getNativeExtensions().getProgramBinary)
2820 {
2821 mMemoryProgramCache = nullptr;
2822 }
Geoff Lang493daf52014-07-03 13:38:44 -04002823}
2824
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002825void Context::initWorkarounds()
2826{
Jamie Madill761b02c2017-06-23 16:27:06 -04002827 // Apply back-end workarounds.
2828 mImplementation->applyNativeWorkarounds(&mWorkarounds);
2829
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002830 // Lose the context upon out of memory error if the application is
2831 // expecting to watch for those events.
2832 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2833}
2834
Jamie Madill05b35b22017-10-03 09:01:44 -04002835Error Context::prepareForDraw()
2836{
2837 syncRendererState();
2838 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
2839 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
2840 return NoError();
2841}
2842
Jamie Madill1b94d432015-08-07 13:23:23 -04002843void Context::syncRendererState()
2844{
Jamie Madill7d1f5c62017-09-02 15:32:15 -04002845 mGLState.syncDirtyObjects(this);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002846 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
Jamie Madillfe548342017-06-19 11:13:24 -04002847 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002848 mGLState.clearDirtyBits();
Jamie Madill1b94d432015-08-07 13:23:23 -04002849}
2850
Jamie Madillad9f24e2016-02-12 09:27:24 -05002851void Context::syncRendererState(const State::DirtyBits &bitMask,
2852 const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04002853{
Jamie Madill7d1f5c62017-09-02 15:32:15 -04002854 mGLState.syncDirtyObjects(this, objectMask);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002855 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madillfe548342017-06-19 11:13:24 -04002856 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002857 mGLState.clearDirtyBits(dirtyBits);
Jamie Madill1b94d432015-08-07 13:23:23 -04002858}
Jamie Madillc29968b2016-01-20 11:17:23 -05002859
2860void Context::blitFramebuffer(GLint srcX0,
2861 GLint srcY0,
2862 GLint srcX1,
2863 GLint srcY1,
2864 GLint dstX0,
2865 GLint dstY0,
2866 GLint dstX1,
2867 GLint dstY1,
2868 GLbitfield mask,
2869 GLenum filter)
2870{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002871 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002872 ASSERT(drawFramebuffer);
2873
2874 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
2875 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
2876
Jamie Madillad9f24e2016-02-12 09:27:24 -05002877 syncStateForBlit();
Jamie Madillc29968b2016-01-20 11:17:23 -05002878
Jamie Madillc564c072017-06-01 12:45:42 -04002879 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002880}
Jamie Madillc29968b2016-01-20 11:17:23 -05002881
2882void Context::clear(GLbitfield mask)
2883{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002884 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002885 handleError(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05002886}
2887
2888void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
2889{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002890 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002891 handleError(mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002892}
2893
2894void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
2895{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002896 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002897 handleError(mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002898}
2899
2900void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
2901{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002902 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002903 handleError(mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002904}
2905
2906void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
2907{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002908 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002909 ASSERT(framebufferObject);
2910
2911 // If a buffer is not present, the clear has no effect
2912 if (framebufferObject->getDepthbuffer() == nullptr &&
2913 framebufferObject->getStencilbuffer() == nullptr)
2914 {
2915 return;
2916 }
2917
Jamie Madillad9f24e2016-02-12 09:27:24 -05002918 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002919 handleError(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05002920}
2921
2922void Context::readPixels(GLint x,
2923 GLint y,
2924 GLsizei width,
2925 GLsizei height,
2926 GLenum format,
2927 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002928 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05002929{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04002930 if (width == 0 || height == 0)
2931 {
2932 return;
2933 }
2934
Jamie Madillad9f24e2016-02-12 09:27:24 -05002935 syncStateForReadPixels();
Jamie Madillc29968b2016-01-20 11:17:23 -05002936
Jamie Madillb6664922017-07-25 12:55:04 -04002937 Framebuffer *readFBO = mGLState.getReadFramebuffer();
2938 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05002939
2940 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04002941 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05002942}
2943
2944void Context::copyTexImage2D(GLenum target,
2945 GLint level,
2946 GLenum internalformat,
2947 GLint x,
2948 GLint y,
2949 GLsizei width,
2950 GLsizei height,
2951 GLint border)
2952{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002953 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002954 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002955
Jamie Madillc29968b2016-01-20 11:17:23 -05002956 Rectangle sourceArea(x, y, width, height);
2957
Jamie Madill05b35b22017-10-03 09:01:44 -04002958 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002959 Texture *texture =
2960 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05002961 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05002962}
2963
2964void Context::copyTexSubImage2D(GLenum target,
2965 GLint level,
2966 GLint xoffset,
2967 GLint yoffset,
2968 GLint x,
2969 GLint y,
2970 GLsizei width,
2971 GLsizei height)
2972{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04002973 if (width == 0 || height == 0)
2974 {
2975 return;
2976 }
2977
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002978 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002979 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002980
Jamie Madillc29968b2016-01-20 11:17:23 -05002981 Offset destOffset(xoffset, yoffset, 0);
2982 Rectangle sourceArea(x, y, width, height);
2983
Jamie Madill05b35b22017-10-03 09:01:44 -04002984 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002985 Texture *texture =
2986 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05002987 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05002988}
2989
2990void Context::copyTexSubImage3D(GLenum target,
2991 GLint level,
2992 GLint xoffset,
2993 GLint yoffset,
2994 GLint zoffset,
2995 GLint x,
2996 GLint y,
2997 GLsizei width,
2998 GLsizei height)
2999{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003000 if (width == 0 || height == 0)
3001 {
3002 return;
3003 }
3004
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003005 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003006 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003007
Jamie Madillc29968b2016-01-20 11:17:23 -05003008 Offset destOffset(xoffset, yoffset, zoffset);
3009 Rectangle sourceArea(x, y, width, height);
3010
Jamie Madill05b35b22017-10-03 09:01:44 -04003011 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3012 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003013 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003014}
3015
3016void Context::framebufferTexture2D(GLenum target,
3017 GLenum attachment,
3018 GLenum textarget,
3019 GLuint texture,
3020 GLint level)
3021{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003022 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003023 ASSERT(framebuffer);
3024
3025 if (texture != 0)
3026 {
3027 Texture *textureObj = getTexture(texture);
3028
3029 ImageIndex index = ImageIndex::MakeInvalid();
3030
3031 if (textarget == GL_TEXTURE_2D)
3032 {
3033 index = ImageIndex::Make2D(level);
3034 }
Corentin Wallez13c0dd42017-07-04 18:27:01 -04003035 else if (textarget == GL_TEXTURE_RECTANGLE_ANGLE)
3036 {
3037 index = ImageIndex::MakeRectangle(level);
3038 }
JiangYizhoubddc46b2016-12-09 09:50:51 +08003039 else if (textarget == GL_TEXTURE_2D_MULTISAMPLE)
3040 {
3041 ASSERT(level == 0);
3042 index = ImageIndex::Make2DMultisample();
3043 }
Jamie Madillc29968b2016-01-20 11:17:23 -05003044 else
3045 {
3046 ASSERT(IsCubeMapTextureTarget(textarget));
3047 index = ImageIndex::MakeCube(textarget, level);
3048 }
3049
Jamie Madilla02315b2017-02-23 14:14:47 -05003050 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003051 }
3052 else
3053 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003054 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003055 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003056
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003057 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003058}
3059
3060void Context::framebufferRenderbuffer(GLenum target,
3061 GLenum attachment,
3062 GLenum renderbuffertarget,
3063 GLuint renderbuffer)
3064{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003065 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003066 ASSERT(framebuffer);
3067
3068 if (renderbuffer != 0)
3069 {
3070 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003071
3072 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex::MakeInvalid(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003073 renderbufferObject);
3074 }
3075 else
3076 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003077 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003078 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003079
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003080 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003081}
3082
3083void Context::framebufferTextureLayer(GLenum target,
3084 GLenum attachment,
3085 GLuint texture,
3086 GLint level,
3087 GLint layer)
3088{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003089 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003090 ASSERT(framebuffer);
3091
3092 if (texture != 0)
3093 {
3094 Texture *textureObject = getTexture(texture);
3095
3096 ImageIndex index = ImageIndex::MakeInvalid();
3097
3098 if (textureObject->getTarget() == GL_TEXTURE_3D)
3099 {
3100 index = ImageIndex::Make3D(level, layer);
3101 }
3102 else
3103 {
3104 ASSERT(textureObject->getTarget() == GL_TEXTURE_2D_ARRAY);
3105 index = ImageIndex::Make2DArray(level, layer);
3106 }
3107
Jamie Madilla02315b2017-02-23 14:14:47 -05003108 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003109 }
3110 else
3111 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003112 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003113 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003114
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003115 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003116}
3117
Martin Radev137032d2017-07-13 10:11:12 +03003118void Context::framebufferTextureMultiviewLayeredANGLE(GLenum target,
3119 GLenum attachment,
3120 GLuint texture,
3121 GLint level,
3122 GLint baseViewIndex,
3123 GLsizei numViews)
3124{
Martin Radev82ef7742017-08-08 17:44:58 +03003125 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3126 ASSERT(framebuffer);
3127
3128 if (texture != 0)
3129 {
3130 Texture *textureObj = getTexture(texture);
3131
Martin Radev18b75ba2017-08-15 15:50:40 +03003132 ImageIndex index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
Martin Radev82ef7742017-08-08 17:44:58 +03003133 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3134 numViews, baseViewIndex);
3135 }
3136 else
3137 {
3138 framebuffer->resetAttachment(this, attachment);
3139 }
3140
3141 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003142}
3143
3144void Context::framebufferTextureMultiviewSideBySideANGLE(GLenum target,
3145 GLenum attachment,
3146 GLuint texture,
3147 GLint level,
3148 GLsizei numViews,
3149 const GLint *viewportOffsets)
3150{
Martin Radev5dae57b2017-07-14 16:15:55 +03003151 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3152 ASSERT(framebuffer);
3153
3154 if (texture != 0)
3155 {
3156 Texture *textureObj = getTexture(texture);
3157
3158 ImageIndex index = ImageIndex::Make2D(level);
3159 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3160 textureObj, numViews, viewportOffsets);
3161 }
3162 else
3163 {
3164 framebuffer->resetAttachment(this, attachment);
3165 }
3166
3167 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003168}
3169
Jamie Madillc29968b2016-01-20 11:17:23 -05003170void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3171{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003172 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003173 ASSERT(framebuffer);
3174 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003175 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003176}
3177
3178void Context::readBuffer(GLenum mode)
3179{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003180 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003181 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003182 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003183}
3184
3185void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3186{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003187 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003188 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003189
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003190 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003191 ASSERT(framebuffer);
3192
3193 // The specification isn't clear what should be done when the framebuffer isn't complete.
3194 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003195 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003196}
3197
3198void Context::invalidateFramebuffer(GLenum target,
3199 GLsizei numAttachments,
3200 const GLenum *attachments)
3201{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003202 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003203 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003204
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003205 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003206 ASSERT(framebuffer);
3207
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003208 if (framebuffer->checkStatus(this) != GL_FRAMEBUFFER_COMPLETE)
Jamie Madillc29968b2016-01-20 11:17:23 -05003209 {
Jamie Madill437fa652016-05-03 15:13:24 -04003210 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003211 }
Jamie Madill437fa652016-05-03 15:13:24 -04003212
Jamie Madill4928b7c2017-06-20 12:57:39 -04003213 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003214}
3215
3216void Context::invalidateSubFramebuffer(GLenum target,
3217 GLsizei numAttachments,
3218 const GLenum *attachments,
3219 GLint x,
3220 GLint y,
3221 GLsizei width,
3222 GLsizei height)
3223{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003224 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003225 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003226
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003227 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003228 ASSERT(framebuffer);
3229
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003230 if (framebuffer->checkStatus(this) != GL_FRAMEBUFFER_COMPLETE)
Jamie Madillc29968b2016-01-20 11:17:23 -05003231 {
Jamie Madill437fa652016-05-03 15:13:24 -04003232 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003233 }
Jamie Madill437fa652016-05-03 15:13:24 -04003234
3235 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003236 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003237}
3238
Jamie Madill73a84962016-02-12 09:27:23 -05003239void Context::texImage2D(GLenum target,
3240 GLint level,
3241 GLint internalformat,
3242 GLsizei width,
3243 GLsizei height,
3244 GLint border,
3245 GLenum format,
3246 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003247 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003248{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003249 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003250
3251 Extents size(width, height, 1);
3252 Texture *texture =
3253 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003254 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3255 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003256}
3257
3258void Context::texImage3D(GLenum target,
3259 GLint level,
3260 GLint internalformat,
3261 GLsizei width,
3262 GLsizei height,
3263 GLsizei depth,
3264 GLint border,
3265 GLenum format,
3266 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003267 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003268{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003269 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003270
3271 Extents size(width, height, depth);
3272 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003273 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3274 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003275}
3276
3277void Context::texSubImage2D(GLenum target,
3278 GLint level,
3279 GLint xoffset,
3280 GLint yoffset,
3281 GLsizei width,
3282 GLsizei height,
3283 GLenum format,
3284 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003285 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003286{
3287 // Zero sized uploads are valid but no-ops
3288 if (width == 0 || height == 0)
3289 {
3290 return;
3291 }
3292
Jamie Madillad9f24e2016-02-12 09:27:24 -05003293 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003294
3295 Box area(xoffset, yoffset, 0, width, height, 1);
3296 Texture *texture =
3297 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003298 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3299 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003300}
3301
3302void Context::texSubImage3D(GLenum target,
3303 GLint level,
3304 GLint xoffset,
3305 GLint yoffset,
3306 GLint zoffset,
3307 GLsizei width,
3308 GLsizei height,
3309 GLsizei depth,
3310 GLenum format,
3311 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003312 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003313{
3314 // Zero sized uploads are valid but no-ops
3315 if (width == 0 || height == 0 || depth == 0)
3316 {
3317 return;
3318 }
3319
Jamie Madillad9f24e2016-02-12 09:27:24 -05003320 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003321
3322 Box area(xoffset, yoffset, zoffset, width, height, depth);
3323 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003324 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3325 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003326}
3327
3328void Context::compressedTexImage2D(GLenum target,
3329 GLint level,
3330 GLenum internalformat,
3331 GLsizei width,
3332 GLsizei height,
3333 GLint border,
3334 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003335 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003336{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003337 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003338
3339 Extents size(width, height, 1);
3340 Texture *texture =
3341 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003342 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003343 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003344 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003345}
3346
3347void Context::compressedTexImage3D(GLenum target,
3348 GLint level,
3349 GLenum internalformat,
3350 GLsizei width,
3351 GLsizei height,
3352 GLsizei depth,
3353 GLint border,
3354 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003355 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003356{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003357 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003358
3359 Extents size(width, height, depth);
3360 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003361 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003362 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003363 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003364}
3365
3366void Context::compressedTexSubImage2D(GLenum target,
3367 GLint level,
3368 GLint xoffset,
3369 GLint yoffset,
3370 GLsizei width,
3371 GLsizei height,
3372 GLenum format,
3373 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003374 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003375{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003376 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003377
3378 Box area(xoffset, yoffset, 0, width, height, 1);
3379 Texture *texture =
3380 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003381 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003382 format, imageSize,
3383 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003384}
3385
3386void Context::compressedTexSubImage3D(GLenum target,
3387 GLint level,
3388 GLint xoffset,
3389 GLint yoffset,
3390 GLint zoffset,
3391 GLsizei width,
3392 GLsizei height,
3393 GLsizei depth,
3394 GLenum format,
3395 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003396 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003397{
3398 // Zero sized uploads are valid but no-ops
3399 if (width == 0 || height == 0)
3400 {
3401 return;
3402 }
3403
Jamie Madillad9f24e2016-02-12 09:27:24 -05003404 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003405
3406 Box area(xoffset, yoffset, zoffset, width, height, depth);
3407 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003408 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003409 format, imageSize,
3410 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003411}
3412
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003413void Context::generateMipmap(GLenum target)
3414{
3415 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003416 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003417}
3418
Geoff Lang97073d12016-04-20 10:42:34 -07003419void Context::copyTextureCHROMIUM(GLuint sourceId,
Geoff Langfc72a072017-03-24 14:52:39 -04003420 GLint sourceLevel,
3421 GLenum destTarget,
Geoff Lang97073d12016-04-20 10:42:34 -07003422 GLuint destId,
Geoff Langfc72a072017-03-24 14:52:39 -04003423 GLint destLevel,
Geoff Lang97073d12016-04-20 10:42:34 -07003424 GLint internalFormat,
3425 GLenum destType,
3426 GLboolean unpackFlipY,
3427 GLboolean unpackPremultiplyAlpha,
3428 GLboolean unpackUnmultiplyAlpha)
3429{
3430 syncStateForTexImage();
3431
3432 gl::Texture *sourceTexture = getTexture(sourceId);
3433 gl::Texture *destTexture = getTexture(destId);
Geoff Langfc72a072017-03-24 14:52:39 -04003434 handleError(destTexture->copyTexture(
3435 this, destTarget, destLevel, internalFormat, destType, sourceLevel, unpackFlipY == GL_TRUE,
3436 unpackPremultiplyAlpha == GL_TRUE, unpackUnmultiplyAlpha == GL_TRUE, sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003437}
3438
3439void Context::copySubTextureCHROMIUM(GLuint sourceId,
Geoff Langfc72a072017-03-24 14:52:39 -04003440 GLint sourceLevel,
3441 GLenum destTarget,
Geoff Lang97073d12016-04-20 10:42:34 -07003442 GLuint destId,
Geoff Langfc72a072017-03-24 14:52:39 -04003443 GLint destLevel,
Geoff Lang97073d12016-04-20 10:42:34 -07003444 GLint xoffset,
3445 GLint yoffset,
3446 GLint x,
3447 GLint y,
3448 GLsizei width,
3449 GLsizei height,
3450 GLboolean unpackFlipY,
3451 GLboolean unpackPremultiplyAlpha,
3452 GLboolean unpackUnmultiplyAlpha)
3453{
3454 // Zero sized copies are valid but no-ops
3455 if (width == 0 || height == 0)
3456 {
3457 return;
3458 }
3459
3460 syncStateForTexImage();
3461
3462 gl::Texture *sourceTexture = getTexture(sourceId);
3463 gl::Texture *destTexture = getTexture(destId);
3464 Offset offset(xoffset, yoffset, 0);
3465 Rectangle area(x, y, width, height);
Geoff Langfc72a072017-03-24 14:52:39 -04003466 handleError(destTexture->copySubTexture(
3467 this, destTarget, destLevel, offset, sourceLevel, area, unpackFlipY == GL_TRUE,
3468 unpackPremultiplyAlpha == GL_TRUE, unpackUnmultiplyAlpha == GL_TRUE, sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003469}
3470
Geoff Lang47110bf2016-04-20 11:13:22 -07003471void Context::compressedCopyTextureCHROMIUM(GLuint sourceId, GLuint destId)
3472{
3473 syncStateForTexImage();
3474
3475 gl::Texture *sourceTexture = getTexture(sourceId);
3476 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05003477 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07003478}
3479
Geoff Lang496c02d2016-10-20 11:38:11 -07003480void Context::getBufferPointerv(GLenum target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03003481{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003482 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003483 ASSERT(buffer);
3484
Geoff Lang496c02d2016-10-20 11:38:11 -07003485 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03003486}
3487
Jamie Madill876429b2017-04-20 15:46:24 -04003488void *Context::mapBuffer(GLenum target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003489{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003490 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003491 ASSERT(buffer);
3492
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003493 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003494 if (error.isError())
3495 {
Jamie Madill437fa652016-05-03 15:13:24 -04003496 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003497 return nullptr;
3498 }
3499
3500 return buffer->getMapPointer();
3501}
3502
3503GLboolean Context::unmapBuffer(GLenum target)
3504{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003505 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003506 ASSERT(buffer);
3507
3508 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003509 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03003510 if (error.isError())
3511 {
Jamie Madill437fa652016-05-03 15:13:24 -04003512 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003513 return GL_FALSE;
3514 }
3515
3516 return result;
3517}
3518
Jamie Madill876429b2017-04-20 15:46:24 -04003519void *Context::mapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003520{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003521 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003522 ASSERT(buffer);
3523
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003524 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003525 if (error.isError())
3526 {
Jamie Madill437fa652016-05-03 15:13:24 -04003527 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003528 return nullptr;
3529 }
3530
3531 return buffer->getMapPointer();
3532}
3533
3534void Context::flushMappedBufferRange(GLenum /*target*/, GLintptr /*offset*/, GLsizeiptr /*length*/)
3535{
3536 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
3537}
3538
Jamie Madillad9f24e2016-02-12 09:27:24 -05003539void Context::syncStateForReadPixels()
3540{
3541 syncRendererState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
3542}
3543
3544void Context::syncStateForTexImage()
3545{
3546 syncRendererState(mTexImageDirtyBits, mTexImageDirtyObjects);
3547}
3548
3549void Context::syncStateForClear()
3550{
3551 syncRendererState(mClearDirtyBits, mClearDirtyObjects);
3552}
3553
3554void Context::syncStateForBlit()
3555{
3556 syncRendererState(mBlitDirtyBits, mBlitDirtyObjects);
3557}
3558
Jamie Madillc20ab272016-06-09 07:20:46 -07003559void Context::activeTexture(GLenum texture)
3560{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003561 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003562}
3563
Jamie Madill876429b2017-04-20 15:46:24 -04003564void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003565{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003566 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07003567}
3568
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003569void Context::blendEquation(GLenum mode)
3570{
3571 mGLState.setBlendEquation(mode, mode);
3572}
3573
Jamie Madillc20ab272016-06-09 07:20:46 -07003574void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
3575{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003576 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003577}
3578
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003579void Context::blendFunc(GLenum sfactor, GLenum dfactor)
3580{
3581 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
3582}
3583
Jamie Madillc20ab272016-06-09 07:20:46 -07003584void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
3585{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003586 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003587}
3588
Jamie Madill876429b2017-04-20 15:46:24 -04003589void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003590{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003591 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003592}
3593
Jamie Madill876429b2017-04-20 15:46:24 -04003594void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07003595{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003596 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07003597}
3598
3599void Context::clearStencil(GLint s)
3600{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003601 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07003602}
3603
3604void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
3605{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003606 mGLState.setColorMask(red == GL_TRUE, green == GL_TRUE, blue == GL_TRUE, alpha == GL_TRUE);
Jamie Madillc20ab272016-06-09 07:20:46 -07003607}
3608
Corentin Wallez2e568cf2017-09-18 17:05:22 -04003609void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07003610{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003611 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003612}
3613
3614void Context::depthFunc(GLenum func)
3615{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003616 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07003617}
3618
3619void Context::depthMask(GLboolean flag)
3620{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003621 mGLState.setDepthMask(flag != GL_FALSE);
Jamie Madillc20ab272016-06-09 07:20:46 -07003622}
3623
Jamie Madill876429b2017-04-20 15:46:24 -04003624void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07003625{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003626 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07003627}
3628
3629void Context::disable(GLenum cap)
3630{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003631 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003632}
3633
3634void Context::disableVertexAttribArray(GLuint index)
3635{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003636 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003637}
3638
3639void Context::enable(GLenum cap)
3640{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003641 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003642}
3643
3644void Context::enableVertexAttribArray(GLuint index)
3645{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003646 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003647}
3648
3649void Context::frontFace(GLenum mode)
3650{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003651 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003652}
3653
3654void Context::hint(GLenum target, GLenum mode)
3655{
3656 switch (target)
3657 {
3658 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003659 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003660 break;
3661
3662 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003663 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003664 break;
3665
3666 default:
3667 UNREACHABLE();
3668 return;
3669 }
3670}
3671
3672void Context::lineWidth(GLfloat width)
3673{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003674 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07003675}
3676
3677void Context::pixelStorei(GLenum pname, GLint param)
3678{
3679 switch (pname)
3680 {
3681 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003682 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003683 break;
3684
3685 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003686 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003687 break;
3688
3689 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003690 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003691 break;
3692
3693 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003694 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003695 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003696 break;
3697
3698 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03003699 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003700 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003701 break;
3702
3703 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03003704 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003705 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003706 break;
3707
3708 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003709 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003710 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003711 break;
3712
3713 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003714 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003715 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003716 break;
3717
3718 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003719 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003720 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003721 break;
3722
3723 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003724 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003725 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003726 break;
3727
3728 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003729 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003730 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003731 break;
3732
3733 default:
3734 UNREACHABLE();
3735 return;
3736 }
3737}
3738
3739void Context::polygonOffset(GLfloat factor, GLfloat units)
3740{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003741 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07003742}
3743
Jamie Madill876429b2017-04-20 15:46:24 -04003744void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07003745{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003746 mGLState.setSampleCoverageParams(clamp01(value), invert == GL_TRUE);
Jamie Madillc20ab272016-06-09 07:20:46 -07003747}
3748
Jiawei Shaodb342272017-09-27 10:21:45 +08003749void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
3750{
3751 mGLState.setSampleMaskParams(maskNumber, mask);
3752}
3753
Jamie Madillc20ab272016-06-09 07:20:46 -07003754void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
3755{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003756 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07003757}
3758
3759void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
3760{
3761 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3762 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003763 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003764 }
3765
3766 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3767 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003768 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003769 }
3770}
3771
3772void Context::stencilMaskSeparate(GLenum face, GLuint mask)
3773{
3774 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3775 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003776 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003777 }
3778
3779 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3780 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003781 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003782 }
3783}
3784
3785void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
3786{
3787 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3788 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003789 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003790 }
3791
3792 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3793 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003794 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003795 }
3796}
3797
3798void Context::vertexAttrib1f(GLuint index, GLfloat x)
3799{
3800 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003801 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003802}
3803
3804void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
3805{
3806 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003807 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003808}
3809
3810void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
3811{
3812 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003813 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003814}
3815
3816void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
3817{
3818 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003819 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003820}
3821
3822void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
3823{
3824 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003825 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003826}
3827
3828void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
3829{
3830 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003831 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003832}
3833
3834void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
3835{
3836 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003837 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003838}
3839
3840void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
3841{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003842 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07003843}
3844
3845void Context::vertexAttribPointer(GLuint index,
3846 GLint size,
3847 GLenum type,
3848 GLboolean normalized,
3849 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04003850 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07003851{
Shaodde78e82017-05-22 14:13:27 +08003852 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(GL_ARRAY_BUFFER), size,
3853 type, normalized == GL_TRUE, false, stride, ptr);
Jamie Madillc20ab272016-06-09 07:20:46 -07003854}
3855
Shao80957d92017-02-20 21:25:59 +08003856void Context::vertexAttribFormat(GLuint attribIndex,
3857 GLint size,
3858 GLenum type,
3859 GLboolean normalized,
3860 GLuint relativeOffset)
3861{
3862 mGLState.setVertexAttribFormat(attribIndex, size, type, normalized == GL_TRUE, false,
3863 relativeOffset);
3864}
3865
3866void Context::vertexAttribIFormat(GLuint attribIndex,
3867 GLint size,
3868 GLenum type,
3869 GLuint relativeOffset)
3870{
3871 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
3872}
3873
3874void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
3875{
Shaodde78e82017-05-22 14:13:27 +08003876 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Shao80957d92017-02-20 21:25:59 +08003877}
3878
3879void Context::setVertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
3880{
3881 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
3882}
3883
Jamie Madillc20ab272016-06-09 07:20:46 -07003884void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
3885{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003886 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07003887}
3888
3889void Context::vertexAttribIPointer(GLuint index,
3890 GLint size,
3891 GLenum type,
3892 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04003893 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07003894{
Shaodde78e82017-05-22 14:13:27 +08003895 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(GL_ARRAY_BUFFER), size,
3896 type, false, true, stride, pointer);
Jamie Madillc20ab272016-06-09 07:20:46 -07003897}
3898
3899void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
3900{
3901 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003902 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003903}
3904
3905void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
3906{
3907 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003908 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003909}
3910
3911void Context::vertexAttribI4iv(GLuint index, const GLint *v)
3912{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003913 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07003914}
3915
3916void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
3917{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003918 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07003919}
3920
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003921void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
3922{
3923 const VertexAttribCurrentValueData &currentValues =
3924 getGLState().getVertexAttribCurrentValue(index);
3925 const VertexArray *vao = getGLState().getVertexArray();
3926 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3927 currentValues, pname, params);
3928}
3929
3930void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
3931{
3932 const VertexAttribCurrentValueData &currentValues =
3933 getGLState().getVertexAttribCurrentValue(index);
3934 const VertexArray *vao = getGLState().getVertexArray();
3935 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3936 currentValues, pname, params);
3937}
3938
3939void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
3940{
3941 const VertexAttribCurrentValueData &currentValues =
3942 getGLState().getVertexAttribCurrentValue(index);
3943 const VertexArray *vao = getGLState().getVertexArray();
3944 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3945 currentValues, pname, params);
3946}
3947
3948void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
3949{
3950 const VertexAttribCurrentValueData &currentValues =
3951 getGLState().getVertexAttribCurrentValue(index);
3952 const VertexArray *vao = getGLState().getVertexArray();
3953 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3954 currentValues, pname, params);
3955}
3956
Jamie Madill876429b2017-04-20 15:46:24 -04003957void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003958{
3959 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
3960 QueryVertexAttribPointerv(attrib, pname, pointer);
3961}
3962
Jamie Madillc20ab272016-06-09 07:20:46 -07003963void Context::debugMessageControl(GLenum source,
3964 GLenum type,
3965 GLenum severity,
3966 GLsizei count,
3967 const GLuint *ids,
3968 GLboolean enabled)
3969{
3970 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003971 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
3972 (enabled != GL_FALSE));
Jamie Madillc20ab272016-06-09 07:20:46 -07003973}
3974
3975void Context::debugMessageInsert(GLenum source,
3976 GLenum type,
3977 GLuint id,
3978 GLenum severity,
3979 GLsizei length,
3980 const GLchar *buf)
3981{
3982 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003983 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07003984}
3985
3986void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
3987{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003988 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07003989}
3990
3991GLuint Context::getDebugMessageLog(GLuint count,
3992 GLsizei bufSize,
3993 GLenum *sources,
3994 GLenum *types,
3995 GLuint *ids,
3996 GLenum *severities,
3997 GLsizei *lengths,
3998 GLchar *messageLog)
3999{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004000 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4001 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004002}
4003
4004void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4005{
4006 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004007 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004008}
4009
4010void Context::popDebugGroup()
4011{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004012 mGLState.getDebug().popGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004013}
4014
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004015void Context::bufferData(GLenum target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004016{
4017 Buffer *buffer = mGLState.getTargetBuffer(target);
4018 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004019 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004020}
4021
Jamie Madill876429b2017-04-20 15:46:24 -04004022void Context::bufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004023{
4024 if (data == nullptr)
4025 {
4026 return;
4027 }
4028
4029 Buffer *buffer = mGLState.getTargetBuffer(target);
4030 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004031 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004032}
4033
Jamie Madillef300b12016-10-07 15:12:09 -04004034void Context::attachShader(GLuint program, GLuint shader)
4035{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004036 auto programObject = mState.mShaderPrograms->getProgram(program);
4037 auto shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004038 ASSERT(programObject && shaderObject);
4039 programObject->attachShader(shaderObject);
4040}
4041
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004042const Workarounds &Context::getWorkarounds() const
4043{
4044 return mWorkarounds;
4045}
4046
Jamie Madillb0817d12016-11-01 15:48:31 -04004047void Context::copyBufferSubData(GLenum readTarget,
4048 GLenum writeTarget,
4049 GLintptr readOffset,
4050 GLintptr writeOffset,
4051 GLsizeiptr size)
4052{
4053 // if size is zero, the copy is a successful no-op
4054 if (size == 0)
4055 {
4056 return;
4057 }
4058
4059 // TODO(jmadill): cache these.
4060 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4061 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4062
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004063 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004064}
4065
Jamie Madill01a80ee2016-11-07 12:06:18 -05004066void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4067{
4068 Program *programObject = getProgram(program);
4069 // TODO(jmadill): Re-use this from the validation if possible.
4070 ASSERT(programObject);
4071 programObject->bindAttributeLocation(index, name);
4072}
4073
4074void Context::bindBuffer(GLenum target, GLuint buffer)
4075{
4076 switch (target)
4077 {
4078 case GL_ARRAY_BUFFER:
4079 bindArrayBuffer(buffer);
4080 break;
4081 case GL_ELEMENT_ARRAY_BUFFER:
4082 bindElementArrayBuffer(buffer);
4083 break;
4084 case GL_COPY_READ_BUFFER:
4085 bindCopyReadBuffer(buffer);
4086 break;
4087 case GL_COPY_WRITE_BUFFER:
4088 bindCopyWriteBuffer(buffer);
4089 break;
4090 case GL_PIXEL_PACK_BUFFER:
4091 bindPixelPackBuffer(buffer);
4092 break;
4093 case GL_PIXEL_UNPACK_BUFFER:
4094 bindPixelUnpackBuffer(buffer);
4095 break;
4096 case GL_UNIFORM_BUFFER:
4097 bindGenericUniformBuffer(buffer);
4098 break;
4099 case GL_TRANSFORM_FEEDBACK_BUFFER:
4100 bindGenericTransformFeedbackBuffer(buffer);
4101 break;
Geoff Lang3b573612016-10-31 14:08:10 -04004102 case GL_ATOMIC_COUNTER_BUFFER:
Jiajia Qin6eafb042016-12-27 17:04:07 +08004103 bindGenericAtomicCounterBuffer(buffer);
Geoff Lang3b573612016-10-31 14:08:10 -04004104 break;
4105 case GL_SHADER_STORAGE_BUFFER:
Jiajia Qinf546e7d2017-03-27 14:12:59 +08004106 bindGenericShaderStorageBuffer(buffer);
Geoff Lang3b573612016-10-31 14:08:10 -04004107 break;
4108 case GL_DRAW_INDIRECT_BUFFER:
Jiajia Qin9d7d0b12016-11-29 16:30:31 +08004109 bindDrawIndirectBuffer(buffer);
Geoff Lang3b573612016-10-31 14:08:10 -04004110 break;
4111 case GL_DISPATCH_INDIRECT_BUFFER:
Geoff Lang9f090372016-12-02 10:20:43 -05004112 if (buffer != 0)
4113 {
4114 // Binding buffers to this binding point is not implemented yet.
4115 UNIMPLEMENTED();
4116 }
Geoff Lang3b573612016-10-31 14:08:10 -04004117 break;
Jamie Madill01a80ee2016-11-07 12:06:18 -05004118
4119 default:
4120 UNREACHABLE();
4121 break;
4122 }
4123}
4124
Jiajia Qin6eafb042016-12-27 17:04:07 +08004125void Context::bindBufferBase(GLenum target, GLuint index, GLuint buffer)
4126{
4127 bindBufferRange(target, index, buffer, 0, 0);
4128}
4129
4130void Context::bindBufferRange(GLenum target,
4131 GLuint index,
4132 GLuint buffer,
4133 GLintptr offset,
4134 GLsizeiptr size)
4135{
4136 switch (target)
4137 {
4138 case GL_TRANSFORM_FEEDBACK_BUFFER:
4139 bindIndexedTransformFeedbackBuffer(buffer, index, offset, size);
4140 bindGenericTransformFeedbackBuffer(buffer);
4141 break;
4142 case GL_UNIFORM_BUFFER:
4143 bindIndexedUniformBuffer(buffer, index, offset, size);
4144 bindGenericUniformBuffer(buffer);
4145 break;
4146 case GL_ATOMIC_COUNTER_BUFFER:
4147 bindIndexedAtomicCounterBuffer(buffer, index, offset, size);
4148 bindGenericAtomicCounterBuffer(buffer);
4149 break;
4150 case GL_SHADER_STORAGE_BUFFER:
Jiajia Qinf546e7d2017-03-27 14:12:59 +08004151 bindIndexedShaderStorageBuffer(buffer, index, offset, size);
4152 bindGenericShaderStorageBuffer(buffer);
Jiajia Qin6eafb042016-12-27 17:04:07 +08004153 break;
4154 default:
4155 UNREACHABLE();
4156 break;
4157 }
4158}
4159
Jamie Madill01a80ee2016-11-07 12:06:18 -05004160void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
4161{
4162 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4163 {
4164 bindReadFramebuffer(framebuffer);
4165 }
4166
4167 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4168 {
4169 bindDrawFramebuffer(framebuffer);
4170 }
4171}
4172
4173void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4174{
4175 ASSERT(target == GL_RENDERBUFFER);
4176 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004177 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04004178 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004179}
4180
JiangYizhoubddc46b2016-12-09 09:50:51 +08004181void Context::texStorage2DMultisample(GLenum target,
4182 GLsizei samples,
4183 GLenum internalformat,
4184 GLsizei width,
4185 GLsizei height,
4186 GLboolean fixedsamplelocations)
4187{
4188 Extents size(width, height, 1);
4189 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05004190 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
JiangYizhoubddc46b2016-12-09 09:50:51 +08004191 fixedsamplelocations));
4192}
4193
4194void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4195{
JiangYizhou5b03f472017-01-09 10:22:53 +08004196 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
4197 // the sample position should be queried by DRAW_FRAMEBUFFER.
4198 mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER);
4199 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08004200
4201 switch (pname)
4202 {
4203 case GL_SAMPLE_POSITION:
4204 handleError(framebuffer->getSamplePosition(index, val));
4205 break;
4206 default:
4207 UNREACHABLE();
4208 }
4209}
4210
Jamie Madille8fb6402017-02-14 17:56:40 -05004211void Context::renderbufferStorage(GLenum target,
4212 GLenum internalformat,
4213 GLsizei width,
4214 GLsizei height)
4215{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004216 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4217 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
4218
Jamie Madille8fb6402017-02-14 17:56:40 -05004219 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04004220 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004221}
4222
4223void Context::renderbufferStorageMultisample(GLenum target,
4224 GLsizei samples,
4225 GLenum internalformat,
4226 GLsizei width,
4227 GLsizei height)
4228{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004229 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4230 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05004231
4232 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004233 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04004234 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004235}
4236
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004237void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
4238{
Jamie Madill70b5bb02017-08-28 13:32:37 -04004239 const Sync *syncObject = getSync(sync);
Geoff Lang82483b92017-04-11 15:33:00 -04004240 handleError(QuerySynciv(syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004241}
4242
JiangYizhoue18e6392017-02-20 10:32:23 +08004243void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
4244{
4245 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4246 QueryFramebufferParameteriv(framebuffer, pname, params);
4247}
4248
4249void Context::setFramebufferParameteri(GLenum target, GLenum pname, GLint param)
4250{
4251 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4252 SetFramebufferParameteri(framebuffer, pname, param);
4253}
4254
Jamie Madillb3f26b92017-07-19 15:07:41 -04004255Error Context::getScratchBuffer(size_t requstedSizeBytes,
4256 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05004257{
Jamie Madillb3f26b92017-07-19 15:07:41 -04004258 if (!mScratchBuffer.get(requstedSizeBytes, scratchBufferOut))
4259 {
4260 return OutOfMemory() << "Failed to allocate internal buffer.";
4261 }
4262 return NoError();
4263}
4264
4265Error Context::getZeroFilledBuffer(size_t requstedSizeBytes,
4266 angle::MemoryBuffer **zeroBufferOut) const
4267{
4268 if (!mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0))
Jamie Madille14951e2017-03-09 18:55:16 -05004269 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004270 return OutOfMemory() << "Failed to allocate internal buffer.";
Jamie Madille14951e2017-03-09 18:55:16 -05004271 }
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004272 return NoError();
Jamie Madille14951e2017-03-09 18:55:16 -05004273}
4274
Xinghua Cao2b396592017-03-29 15:36:04 +08004275void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
4276{
4277 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
4278 {
4279 return;
4280 }
4281
Jamie Madill05b35b22017-10-03 09:01:44 -04004282 // TODO(jmadill): Dirty bits for compute.
4283 ANGLE_CONTEXT_TRY(mGLState.clearUnclearedActiveTextures(this));
4284
Jamie Madill71c88b32017-09-14 22:20:29 -04004285 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08004286}
4287
JiangYizhou165361c2017-06-07 14:56:57 +08004288void Context::texStorage2D(GLenum target,
4289 GLsizei levels,
4290 GLenum internalFormat,
4291 GLsizei width,
4292 GLsizei height)
4293{
4294 Extents size(width, height, 1);
4295 Texture *texture = getTargetTexture(target);
4296 handleError(texture->setStorage(this, target, levels, internalFormat, size));
4297}
4298
4299void Context::texStorage3D(GLenum target,
4300 GLsizei levels,
4301 GLenum internalFormat,
4302 GLsizei width,
4303 GLsizei height,
4304 GLsizei depth)
4305{
4306 Extents size(width, height, depth);
4307 Texture *texture = getTargetTexture(target);
4308 handleError(texture->setStorage(this, target, levels, internalFormat, size));
4309}
4310
Jamie Madillc1d770e2017-04-13 17:31:24 -04004311GLenum Context::checkFramebufferStatus(GLenum target)
4312{
4313 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4314 ASSERT(framebuffer);
4315
4316 return framebuffer->checkStatus(this);
4317}
4318
4319void Context::compileShader(GLuint shader)
4320{
4321 Shader *shaderObject = GetValidShader(this, shader);
4322 if (!shaderObject)
4323 {
4324 return;
4325 }
4326 shaderObject->compile(this);
4327}
4328
4329void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
4330{
4331 for (int i = 0; i < n; i++)
4332 {
4333 deleteBuffer(buffers[i]);
4334 }
4335}
4336
4337void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
4338{
4339 for (int i = 0; i < n; i++)
4340 {
4341 if (framebuffers[i] != 0)
4342 {
4343 deleteFramebuffer(framebuffers[i]);
4344 }
4345 }
4346}
4347
4348void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
4349{
4350 for (int i = 0; i < n; i++)
4351 {
4352 deleteRenderbuffer(renderbuffers[i]);
4353 }
4354}
4355
4356void Context::deleteTextures(GLsizei n, const GLuint *textures)
4357{
4358 for (int i = 0; i < n; i++)
4359 {
4360 if (textures[i] != 0)
4361 {
4362 deleteTexture(textures[i]);
4363 }
4364 }
4365}
4366
4367void Context::detachShader(GLuint program, GLuint shader)
4368{
4369 Program *programObject = getProgram(program);
4370 ASSERT(programObject);
4371
4372 Shader *shaderObject = getShader(shader);
4373 ASSERT(shaderObject);
4374
4375 programObject->detachShader(this, shaderObject);
4376}
4377
4378void Context::genBuffers(GLsizei n, GLuint *buffers)
4379{
4380 for (int i = 0; i < n; i++)
4381 {
4382 buffers[i] = createBuffer();
4383 }
4384}
4385
4386void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
4387{
4388 for (int i = 0; i < n; i++)
4389 {
4390 framebuffers[i] = createFramebuffer();
4391 }
4392}
4393
4394void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
4395{
4396 for (int i = 0; i < n; i++)
4397 {
4398 renderbuffers[i] = createRenderbuffer();
4399 }
4400}
4401
4402void Context::genTextures(GLsizei n, GLuint *textures)
4403{
4404 for (int i = 0; i < n; i++)
4405 {
4406 textures[i] = createTexture();
4407 }
4408}
4409
4410void Context::getActiveAttrib(GLuint program,
4411 GLuint index,
4412 GLsizei bufsize,
4413 GLsizei *length,
4414 GLint *size,
4415 GLenum *type,
4416 GLchar *name)
4417{
4418 Program *programObject = getProgram(program);
4419 ASSERT(programObject);
4420 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
4421}
4422
4423void Context::getActiveUniform(GLuint program,
4424 GLuint index,
4425 GLsizei bufsize,
4426 GLsizei *length,
4427 GLint *size,
4428 GLenum *type,
4429 GLchar *name)
4430{
4431 Program *programObject = getProgram(program);
4432 ASSERT(programObject);
4433 programObject->getActiveUniform(index, bufsize, length, size, type, name);
4434}
4435
4436void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
4437{
4438 Program *programObject = getProgram(program);
4439 ASSERT(programObject);
4440 programObject->getAttachedShaders(maxcount, count, shaders);
4441}
4442
4443GLint Context::getAttribLocation(GLuint program, const GLchar *name)
4444{
4445 Program *programObject = getProgram(program);
4446 ASSERT(programObject);
4447 return programObject->getAttributeLocation(name);
4448}
4449
4450void Context::getBooleanv(GLenum pname, GLboolean *params)
4451{
4452 GLenum nativeType;
4453 unsigned int numParams = 0;
4454 getQueryParameterInfo(pname, &nativeType, &numParams);
4455
4456 if (nativeType == GL_BOOL)
4457 {
4458 getBooleanvImpl(pname, params);
4459 }
4460 else
4461 {
4462 CastStateValues(this, nativeType, pname, numParams, params);
4463 }
4464}
4465
4466void Context::getFloatv(GLenum pname, GLfloat *params)
4467{
4468 GLenum nativeType;
4469 unsigned int numParams = 0;
4470 getQueryParameterInfo(pname, &nativeType, &numParams);
4471
4472 if (nativeType == GL_FLOAT)
4473 {
4474 getFloatvImpl(pname, params);
4475 }
4476 else
4477 {
4478 CastStateValues(this, nativeType, pname, numParams, params);
4479 }
4480}
4481
4482void Context::getIntegerv(GLenum pname, GLint *params)
4483{
4484 GLenum nativeType;
4485 unsigned int numParams = 0;
4486 getQueryParameterInfo(pname, &nativeType, &numParams);
4487
4488 if (nativeType == GL_INT)
4489 {
4490 getIntegervImpl(pname, params);
4491 }
4492 else
4493 {
4494 CastStateValues(this, nativeType, pname, numParams, params);
4495 }
4496}
4497
4498void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
4499{
4500 Program *programObject = getProgram(program);
4501 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04004502 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004503}
4504
Jamie Madillbe849e42017-05-02 15:49:00 -04004505void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04004506{
4507 Program *programObject = getProgram(program);
4508 ASSERT(programObject);
4509 programObject->getInfoLog(bufsize, length, infolog);
4510}
4511
4512void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
4513{
4514 Shader *shaderObject = getShader(shader);
4515 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004516 QueryShaderiv(this, shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004517}
4518
4519void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
4520{
4521 Shader *shaderObject = getShader(shader);
4522 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004523 shaderObject->getInfoLog(this, bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004524}
4525
4526void Context::getShaderPrecisionFormat(GLenum shadertype,
4527 GLenum precisiontype,
4528 GLint *range,
4529 GLint *precision)
4530{
4531 // TODO(jmadill): Compute shaders.
4532
4533 switch (shadertype)
4534 {
4535 case GL_VERTEX_SHADER:
4536 switch (precisiontype)
4537 {
4538 case GL_LOW_FLOAT:
4539 mCaps.vertexLowpFloat.get(range, precision);
4540 break;
4541 case GL_MEDIUM_FLOAT:
4542 mCaps.vertexMediumpFloat.get(range, precision);
4543 break;
4544 case GL_HIGH_FLOAT:
4545 mCaps.vertexHighpFloat.get(range, precision);
4546 break;
4547
4548 case GL_LOW_INT:
4549 mCaps.vertexLowpInt.get(range, precision);
4550 break;
4551 case GL_MEDIUM_INT:
4552 mCaps.vertexMediumpInt.get(range, precision);
4553 break;
4554 case GL_HIGH_INT:
4555 mCaps.vertexHighpInt.get(range, precision);
4556 break;
4557
4558 default:
4559 UNREACHABLE();
4560 return;
4561 }
4562 break;
4563
4564 case GL_FRAGMENT_SHADER:
4565 switch (precisiontype)
4566 {
4567 case GL_LOW_FLOAT:
4568 mCaps.fragmentLowpFloat.get(range, precision);
4569 break;
4570 case GL_MEDIUM_FLOAT:
4571 mCaps.fragmentMediumpFloat.get(range, precision);
4572 break;
4573 case GL_HIGH_FLOAT:
4574 mCaps.fragmentHighpFloat.get(range, precision);
4575 break;
4576
4577 case GL_LOW_INT:
4578 mCaps.fragmentLowpInt.get(range, precision);
4579 break;
4580 case GL_MEDIUM_INT:
4581 mCaps.fragmentMediumpInt.get(range, precision);
4582 break;
4583 case GL_HIGH_INT:
4584 mCaps.fragmentHighpInt.get(range, precision);
4585 break;
4586
4587 default:
4588 UNREACHABLE();
4589 return;
4590 }
4591 break;
4592
4593 default:
4594 UNREACHABLE();
4595 return;
4596 }
4597}
4598
4599void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
4600{
4601 Shader *shaderObject = getShader(shader);
4602 ASSERT(shaderObject);
4603 shaderObject->getSource(bufsize, length, source);
4604}
4605
4606void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
4607{
4608 Program *programObject = getProgram(program);
4609 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04004610 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004611}
4612
4613void Context::getUniformiv(GLuint program, GLint location, GLint *params)
4614{
4615 Program *programObject = getProgram(program);
4616 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04004617 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004618}
4619
4620GLint Context::getUniformLocation(GLuint program, const GLchar *name)
4621{
4622 Program *programObject = getProgram(program);
4623 ASSERT(programObject);
4624 return programObject->getUniformLocation(name);
4625}
4626
4627GLboolean Context::isBuffer(GLuint buffer)
4628{
4629 if (buffer == 0)
4630 {
4631 return GL_FALSE;
4632 }
4633
4634 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
4635}
4636
4637GLboolean Context::isEnabled(GLenum cap)
4638{
4639 return mGLState.getEnableFeature(cap);
4640}
4641
4642GLboolean Context::isFramebuffer(GLuint framebuffer)
4643{
4644 if (framebuffer == 0)
4645 {
4646 return GL_FALSE;
4647 }
4648
4649 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
4650}
4651
4652GLboolean Context::isProgram(GLuint program)
4653{
4654 if (program == 0)
4655 {
4656 return GL_FALSE;
4657 }
4658
4659 return (getProgram(program) ? GL_TRUE : GL_FALSE);
4660}
4661
4662GLboolean Context::isRenderbuffer(GLuint renderbuffer)
4663{
4664 if (renderbuffer == 0)
4665 {
4666 return GL_FALSE;
4667 }
4668
4669 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
4670}
4671
4672GLboolean Context::isShader(GLuint shader)
4673{
4674 if (shader == 0)
4675 {
4676 return GL_FALSE;
4677 }
4678
4679 return (getShader(shader) ? GL_TRUE : GL_FALSE);
4680}
4681
4682GLboolean Context::isTexture(GLuint texture)
4683{
4684 if (texture == 0)
4685 {
4686 return GL_FALSE;
4687 }
4688
4689 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
4690}
4691
4692void Context::linkProgram(GLuint program)
4693{
4694 Program *programObject = getProgram(program);
4695 ASSERT(programObject);
4696 handleError(programObject->link(this));
Martin Radev0abb7a22017-08-28 15:34:45 +03004697 mGLState.onProgramExecutableChange(programObject);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004698}
4699
4700void Context::releaseShaderCompiler()
4701{
Jamie Madill4928b7c2017-06-20 12:57:39 -04004702 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004703}
4704
4705void Context::shaderBinary(GLsizei n,
4706 const GLuint *shaders,
4707 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04004708 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04004709 GLsizei length)
4710{
4711 // No binary shader formats are supported.
4712 UNIMPLEMENTED();
4713}
4714
4715void Context::shaderSource(GLuint shader,
4716 GLsizei count,
4717 const GLchar *const *string,
4718 const GLint *length)
4719{
4720 Shader *shaderObject = getShader(shader);
4721 ASSERT(shaderObject);
4722 shaderObject->setSource(count, string, length);
4723}
4724
4725void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
4726{
4727 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
4728}
4729
4730void Context::stencilMask(GLuint mask)
4731{
4732 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
4733}
4734
4735void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
4736{
4737 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
4738}
4739
4740void Context::uniform1f(GLint location, GLfloat x)
4741{
4742 Program *program = mGLState.getProgram();
4743 program->setUniform1fv(location, 1, &x);
4744}
4745
4746void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
4747{
4748 Program *program = mGLState.getProgram();
4749 program->setUniform1fv(location, count, v);
4750}
4751
4752void Context::uniform1i(GLint location, GLint x)
4753{
4754 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04004755 if (program->setUniform1iv(location, 1, &x) == Program::SetUniformResult::SamplerChanged)
4756 {
4757 mGLState.setObjectDirty(GL_PROGRAM);
4758 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04004759}
4760
4761void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
4762{
4763 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04004764 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
4765 {
4766 mGLState.setObjectDirty(GL_PROGRAM);
4767 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04004768}
4769
4770void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
4771{
4772 GLfloat xy[2] = {x, y};
4773 Program *program = mGLState.getProgram();
4774 program->setUniform2fv(location, 1, xy);
4775}
4776
4777void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
4778{
4779 Program *program = mGLState.getProgram();
4780 program->setUniform2fv(location, count, v);
4781}
4782
4783void Context::uniform2i(GLint location, GLint x, GLint y)
4784{
4785 GLint xy[2] = {x, y};
4786 Program *program = mGLState.getProgram();
4787 program->setUniform2iv(location, 1, xy);
4788}
4789
4790void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
4791{
4792 Program *program = mGLState.getProgram();
4793 program->setUniform2iv(location, count, v);
4794}
4795
4796void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
4797{
4798 GLfloat xyz[3] = {x, y, z};
4799 Program *program = mGLState.getProgram();
4800 program->setUniform3fv(location, 1, xyz);
4801}
4802
4803void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
4804{
4805 Program *program = mGLState.getProgram();
4806 program->setUniform3fv(location, count, v);
4807}
4808
4809void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
4810{
4811 GLint xyz[3] = {x, y, z};
4812 Program *program = mGLState.getProgram();
4813 program->setUniform3iv(location, 1, xyz);
4814}
4815
4816void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
4817{
4818 Program *program = mGLState.getProgram();
4819 program->setUniform3iv(location, count, v);
4820}
4821
4822void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4823{
4824 GLfloat xyzw[4] = {x, y, z, w};
4825 Program *program = mGLState.getProgram();
4826 program->setUniform4fv(location, 1, xyzw);
4827}
4828
4829void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
4830{
4831 Program *program = mGLState.getProgram();
4832 program->setUniform4fv(location, count, v);
4833}
4834
4835void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
4836{
4837 GLint xyzw[4] = {x, y, z, w};
4838 Program *program = mGLState.getProgram();
4839 program->setUniform4iv(location, 1, xyzw);
4840}
4841
4842void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
4843{
4844 Program *program = mGLState.getProgram();
4845 program->setUniform4iv(location, count, v);
4846}
4847
4848void Context::uniformMatrix2fv(GLint location,
4849 GLsizei count,
4850 GLboolean transpose,
4851 const GLfloat *value)
4852{
4853 Program *program = mGLState.getProgram();
4854 program->setUniformMatrix2fv(location, count, transpose, value);
4855}
4856
4857void Context::uniformMatrix3fv(GLint location,
4858 GLsizei count,
4859 GLboolean transpose,
4860 const GLfloat *value)
4861{
4862 Program *program = mGLState.getProgram();
4863 program->setUniformMatrix3fv(location, count, transpose, value);
4864}
4865
4866void Context::uniformMatrix4fv(GLint location,
4867 GLsizei count,
4868 GLboolean transpose,
4869 const GLfloat *value)
4870{
4871 Program *program = mGLState.getProgram();
4872 program->setUniformMatrix4fv(location, count, transpose, value);
4873}
4874
4875void Context::validateProgram(GLuint program)
4876{
4877 Program *programObject = getProgram(program);
4878 ASSERT(programObject);
4879 programObject->validate(mCaps);
4880}
4881
Jamie Madilld04908b2017-06-09 14:15:35 -04004882void Context::getProgramBinary(GLuint program,
4883 GLsizei bufSize,
4884 GLsizei *length,
4885 GLenum *binaryFormat,
4886 void *binary)
4887{
4888 Program *programObject = getProgram(program);
4889 ASSERT(programObject != nullptr);
4890
4891 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
4892}
4893
4894void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
4895{
4896 Program *programObject = getProgram(program);
4897 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04004898
Jamie Madilld04908b2017-06-09 14:15:35 -04004899 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
4900}
4901
Jamie Madillff325f12017-08-26 15:06:05 -04004902void Context::uniform1ui(GLint location, GLuint v0)
4903{
4904 Program *program = mGLState.getProgram();
4905 program->setUniform1uiv(location, 1, &v0);
4906}
4907
4908void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
4909{
4910 Program *program = mGLState.getProgram();
4911 const GLuint xy[] = {v0, v1};
4912 program->setUniform2uiv(location, 1, xy);
4913}
4914
4915void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
4916{
4917 Program *program = mGLState.getProgram();
4918 const GLuint xyz[] = {v0, v1, v2};
4919 program->setUniform3uiv(location, 1, xyz);
4920}
4921
4922void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
4923{
4924 Program *program = mGLState.getProgram();
4925 const GLuint xyzw[] = {v0, v1, v2, v3};
4926 program->setUniform4uiv(location, 1, xyzw);
4927}
4928
4929void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
4930{
4931 Program *program = mGLState.getProgram();
4932 program->setUniform1uiv(location, count, value);
4933}
4934void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
4935{
4936 Program *program = mGLState.getProgram();
4937 program->setUniform2uiv(location, count, value);
4938}
4939
4940void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
4941{
4942 Program *program = mGLState.getProgram();
4943 program->setUniform3uiv(location, count, value);
4944}
4945
4946void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
4947{
4948 Program *program = mGLState.getProgram();
4949 program->setUniform4uiv(location, count, value);
4950}
4951
Jamie Madillf0e04492017-08-26 15:28:42 -04004952void Context::genQueries(GLsizei n, GLuint *ids)
4953{
4954 for (GLsizei i = 0; i < n; i++)
4955 {
4956 GLuint handle = mQueryHandleAllocator.allocate();
4957 mQueryMap.assign(handle, nullptr);
4958 ids[i] = handle;
4959 }
4960}
4961
4962void Context::deleteQueries(GLsizei n, const GLuint *ids)
4963{
4964 for (int i = 0; i < n; i++)
4965 {
4966 GLuint query = ids[i];
4967
4968 Query *queryObject = nullptr;
4969 if (mQueryMap.erase(query, &queryObject))
4970 {
4971 mQueryHandleAllocator.release(query);
4972 if (queryObject)
4973 {
4974 queryObject->release(this);
4975 }
4976 }
4977 }
4978}
4979
4980GLboolean Context::isQuery(GLuint id)
4981{
4982 return (getQuery(id, false, GL_NONE) != nullptr) ? GL_TRUE : GL_FALSE;
4983}
4984
Jamie Madillc8c95812017-08-26 18:40:09 -04004985void Context::uniformMatrix2x3fv(GLint location,
4986 GLsizei count,
4987 GLboolean transpose,
4988 const GLfloat *value)
4989{
4990 Program *program = mGLState.getProgram();
4991 program->setUniformMatrix2x3fv(location, count, transpose, value);
4992}
4993
4994void Context::uniformMatrix3x2fv(GLint location,
4995 GLsizei count,
4996 GLboolean transpose,
4997 const GLfloat *value)
4998{
4999 Program *program = mGLState.getProgram();
5000 program->setUniformMatrix3x2fv(location, count, transpose, value);
5001}
5002
5003void Context::uniformMatrix2x4fv(GLint location,
5004 GLsizei count,
5005 GLboolean transpose,
5006 const GLfloat *value)
5007{
5008 Program *program = mGLState.getProgram();
5009 program->setUniformMatrix2x4fv(location, count, transpose, value);
5010}
5011
5012void Context::uniformMatrix4x2fv(GLint location,
5013 GLsizei count,
5014 GLboolean transpose,
5015 const GLfloat *value)
5016{
5017 Program *program = mGLState.getProgram();
5018 program->setUniformMatrix4x2fv(location, count, transpose, value);
5019}
5020
5021void Context::uniformMatrix3x4fv(GLint location,
5022 GLsizei count,
5023 GLboolean transpose,
5024 const GLfloat *value)
5025{
5026 Program *program = mGLState.getProgram();
5027 program->setUniformMatrix3x4fv(location, count, transpose, value);
5028}
5029
5030void Context::uniformMatrix4x3fv(GLint location,
5031 GLsizei count,
5032 GLboolean transpose,
5033 const GLfloat *value)
5034{
5035 Program *program = mGLState.getProgram();
5036 program->setUniformMatrix4x3fv(location, count, transpose, value);
5037}
5038
Jamie Madilld7576732017-08-26 18:49:50 -04005039void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
5040{
5041 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5042 {
5043 GLuint vertexArray = arrays[arrayIndex];
5044
5045 if (arrays[arrayIndex] != 0)
5046 {
5047 VertexArray *vertexArrayObject = nullptr;
5048 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
5049 {
5050 if (vertexArrayObject != nullptr)
5051 {
5052 detachVertexArray(vertexArray);
5053 vertexArrayObject->onDestroy(this);
5054 }
5055
5056 mVertexArrayHandleAllocator.release(vertexArray);
5057 }
5058 }
5059 }
5060}
5061
5062void Context::genVertexArrays(GLsizei n, GLuint *arrays)
5063{
5064 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5065 {
5066 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
5067 mVertexArrayMap.assign(vertexArray, nullptr);
5068 arrays[arrayIndex] = vertexArray;
5069 }
5070}
5071
5072bool Context::isVertexArray(GLuint array)
5073{
5074 if (array == 0)
5075 {
5076 return GL_FALSE;
5077 }
5078
5079 VertexArray *vao = getVertexArray(array);
5080 return (vao != nullptr ? GL_TRUE : GL_FALSE);
5081}
5082
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04005083void Context::endTransformFeedback()
5084{
5085 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5086 transformFeedback->end(this);
5087}
5088
5089void Context::transformFeedbackVaryings(GLuint program,
5090 GLsizei count,
5091 const GLchar *const *varyings,
5092 GLenum bufferMode)
5093{
5094 Program *programObject = getProgram(program);
5095 ASSERT(programObject);
5096 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
5097}
5098
5099void Context::getTransformFeedbackVarying(GLuint program,
5100 GLuint index,
5101 GLsizei bufSize,
5102 GLsizei *length,
5103 GLsizei *size,
5104 GLenum *type,
5105 GLchar *name)
5106{
5107 Program *programObject = getProgram(program);
5108 ASSERT(programObject);
5109 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
5110}
5111
5112void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
5113{
5114 for (int i = 0; i < n; i++)
5115 {
5116 GLuint transformFeedback = ids[i];
5117 if (transformFeedback == 0)
5118 {
5119 continue;
5120 }
5121
5122 TransformFeedback *transformFeedbackObject = nullptr;
5123 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
5124 {
5125 if (transformFeedbackObject != nullptr)
5126 {
5127 detachTransformFeedback(transformFeedback);
5128 transformFeedbackObject->release(this);
5129 }
5130
5131 mTransformFeedbackHandleAllocator.release(transformFeedback);
5132 }
5133 }
5134}
5135
5136void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
5137{
5138 for (int i = 0; i < n; i++)
5139 {
5140 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
5141 mTransformFeedbackMap.assign(transformFeedback, nullptr);
5142 ids[i] = transformFeedback;
5143 }
5144}
5145
5146bool Context::isTransformFeedback(GLuint id)
5147{
5148 if (id == 0)
5149 {
5150 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
5151 // returns FALSE
5152 return GL_FALSE;
5153 }
5154
5155 const TransformFeedback *transformFeedback = getTransformFeedback(id);
5156 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
5157}
5158
5159void Context::pauseTransformFeedback()
5160{
5161 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5162 transformFeedback->pause();
5163}
5164
5165void Context::resumeTransformFeedback()
5166{
5167 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5168 transformFeedback->resume();
5169}
5170
Jamie Madill12e957f2017-08-26 21:42:26 -04005171void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
5172{
5173 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04005174 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04005175}
5176
5177GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
5178{
5179 const Program *programObject = getProgram(program);
5180 return programObject->getFragDataLocation(name);
5181}
5182
5183void Context::getUniformIndices(GLuint program,
5184 GLsizei uniformCount,
5185 const GLchar *const *uniformNames,
5186 GLuint *uniformIndices)
5187{
5188 const Program *programObject = getProgram(program);
5189 if (!programObject->isLinked())
5190 {
5191 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5192 {
5193 uniformIndices[uniformId] = GL_INVALID_INDEX;
5194 }
5195 }
5196 else
5197 {
5198 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5199 {
5200 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
5201 }
5202 }
5203}
5204
5205void Context::getActiveUniformsiv(GLuint program,
5206 GLsizei uniformCount,
5207 const GLuint *uniformIndices,
5208 GLenum pname,
5209 GLint *params)
5210{
5211 const Program *programObject = getProgram(program);
5212 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5213 {
5214 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08005215 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04005216 }
5217}
5218
5219GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
5220{
5221 const Program *programObject = getProgram(program);
5222 return programObject->getUniformBlockIndex(uniformBlockName);
5223}
5224
5225void Context::getActiveUniformBlockiv(GLuint program,
5226 GLuint uniformBlockIndex,
5227 GLenum pname,
5228 GLint *params)
5229{
5230 const Program *programObject = getProgram(program);
5231 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
5232}
5233
5234void Context::getActiveUniformBlockName(GLuint program,
5235 GLuint uniformBlockIndex,
5236 GLsizei bufSize,
5237 GLsizei *length,
5238 GLchar *uniformBlockName)
5239{
5240 const Program *programObject = getProgram(program);
5241 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
5242}
5243
5244void Context::uniformBlockBinding(GLuint program,
5245 GLuint uniformBlockIndex,
5246 GLuint uniformBlockBinding)
5247{
5248 Program *programObject = getProgram(program);
5249 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
5250}
5251
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005252GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
5253{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005254 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
5255 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005256
Jamie Madill70b5bb02017-08-28 13:32:37 -04005257 Sync *syncObject = getSync(syncHandle);
5258 Error error = syncObject->set(condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005259 if (error.isError())
5260 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04005261 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005262 handleError(error);
5263 return nullptr;
5264 }
5265
Jamie Madill70b5bb02017-08-28 13:32:37 -04005266 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005267}
5268
5269GLboolean Context::isSync(GLsync sync)
5270{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005271 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005272}
5273
5274GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
5275{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005276 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005277
5278 GLenum result = GL_WAIT_FAILED;
5279 handleError(syncObject->clientWait(flags, timeout, &result));
5280 return result;
5281}
5282
5283void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
5284{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005285 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005286 handleError(syncObject->serverWait(flags, timeout));
5287}
5288
5289void Context::getInteger64v(GLenum pname, GLint64 *params)
5290{
5291 GLenum nativeType = GL_NONE;
5292 unsigned int numParams = 0;
5293 getQueryParameterInfo(pname, &nativeType, &numParams);
5294
5295 if (nativeType == GL_INT_64_ANGLEX)
5296 {
5297 getInteger64vImpl(pname, params);
5298 }
5299 else
5300 {
5301 CastStateValues(this, nativeType, pname, numParams, params);
5302 }
5303}
5304
Jamie Madill3ef140a2017-08-26 23:11:21 -04005305void Context::getBufferParameteri64v(GLenum target, GLenum pname, GLint64 *params)
5306{
5307 Buffer *buffer = mGLState.getTargetBuffer(target);
5308 QueryBufferParameteri64v(buffer, pname, params);
5309}
5310
5311void Context::genSamplers(GLsizei count, GLuint *samplers)
5312{
5313 for (int i = 0; i < count; i++)
5314 {
5315 samplers[i] = mState.mSamplers->createSampler();
5316 }
5317}
5318
5319void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
5320{
5321 for (int i = 0; i < count; i++)
5322 {
5323 GLuint sampler = samplers[i];
5324
5325 if (mState.mSamplers->getSampler(sampler))
5326 {
5327 detachSampler(sampler);
5328 }
5329
5330 mState.mSamplers->deleteObject(this, sampler);
5331 }
5332}
5333
5334void Context::getInternalformativ(GLenum target,
5335 GLenum internalformat,
5336 GLenum pname,
5337 GLsizei bufSize,
5338 GLint *params)
5339{
5340 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
5341 QueryInternalFormativ(formatCaps, pname, bufSize, params);
5342}
5343
Jamie Madill81c2e252017-09-09 23:32:46 -04005344void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5345{
5346 Program *programObject = getProgram(program);
5347 ASSERT(programObject);
5348 if (programObject->setUniform1iv(location, count, value) ==
5349 Program::SetUniformResult::SamplerChanged)
5350 {
5351 mGLState.setObjectDirty(GL_PROGRAM);
5352 }
5353}
5354
5355void Context::onTextureChange(const Texture *texture)
5356{
5357 // Conservatively assume all textures are dirty.
5358 // TODO(jmadill): More fine-grained update.
5359 mGLState.setObjectDirty(GL_TEXTURE);
5360}
5361
Yunchao Hea336b902017-08-02 16:05:21 +08005362void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
5363{
5364 for (int i = 0; i < count; i++)
5365 {
5366 pipelines[i] = createProgramPipeline();
5367 }
5368}
5369
5370void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
5371{
5372 for (int i = 0; i < count; i++)
5373 {
5374 if (pipelines[i] != 0)
5375 {
5376 deleteProgramPipeline(pipelines[i]);
5377 }
5378 }
5379}
5380
5381GLboolean Context::isProgramPipeline(GLuint pipeline)
5382{
5383 if (pipeline == 0)
5384 {
5385 return GL_FALSE;
5386 }
5387
5388 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
5389}
5390
Jamie Madillc29968b2016-01-20 11:17:23 -05005391} // namespace gl