blob: 022bf66e5bb173cd8e1ede247623338c3be8e43a [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
Jamie Madill76e471e2017-10-21 09:56:01 -0400490 mImplementation->onDestroy(this);
491
Jamie Madill4928b7c2017-06-20 12:57:39 -0400492 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000493}
494
Jamie Madill70ee0f62017-02-06 16:04:20 -0500495Context::~Context()
496{
497}
498
Jamie Madill4928b7c2017-06-20 12:57:39 -0400499egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000500{
Jamie Madill61e16b42017-06-19 11:13:23 -0400501 mCurrentDisplay = display;
502
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000503 if (!mHasBeenCurrent)
504 {
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000505 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500506 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400507 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000508
Corentin Wallezc295e512017-01-27 17:47:50 -0500509 int width = 0;
510 int height = 0;
511 if (surface != nullptr)
512 {
513 width = surface->getWidth();
514 height = surface->getHeight();
515 }
516
517 mGLState.setViewportParams(0, 0, width, height);
518 mGLState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000519
520 mHasBeenCurrent = true;
521 }
522
Jamie Madill1b94d432015-08-07 13:23:23 -0400523 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700524 mGLState.setAllDirtyBits();
Jamie Madill81c2e252017-09-09 23:32:46 -0400525 mGLState.setAllDirtyObjects();
Jamie Madill1b94d432015-08-07 13:23:23 -0400526
Jamie Madill4928b7c2017-06-20 12:57:39 -0400527 ANGLE_TRY(releaseSurface(display));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500528
529 Framebuffer *newDefault = nullptr;
530 if (surface != nullptr)
531 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400532 ANGLE_TRY(surface->setIsCurrent(this, true));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500533 mCurrentSurface = surface;
534 newDefault = surface->getDefaultFramebuffer();
535 }
536 else
537 {
538 if (mSurfacelessFramebuffer == nullptr)
539 {
540 mSurfacelessFramebuffer = new Framebuffer(mImplementation.get());
541 }
542
543 newDefault = mSurfacelessFramebuffer;
544 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000545
Corentin Wallez37c39792015-08-20 14:19:46 -0400546 // Update default framebuffer, the binding of the previous default
547 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400548 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700549 if (mGLState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400550 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700551 mGLState.setReadFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400552 }
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700553 if (mGLState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400554 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700555 mGLState.setDrawFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400556 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500557 mState.mFramebuffers->setDefaultFramebuffer(newDefault);
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400558 }
Ian Ewell292f0052016-02-04 10:37:32 -0500559
560 // Notify the renderer of a context switch
Jamie Madill4928b7c2017-06-20 12:57:39 -0400561 mImplementation->onMakeCurrent(this);
562 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000563}
564
Jamie Madill4928b7c2017-06-20 12:57:39 -0400565egl::Error Context::releaseSurface(const egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400566{
Corentin Wallez37c39792015-08-20 14:19:46 -0400567 // Remove the default framebuffer
Corentin Wallezc295e512017-01-27 17:47:50 -0500568 Framebuffer *currentDefault = nullptr;
569 if (mCurrentSurface != nullptr)
Corentin Wallez51706ea2015-08-07 14:39:22 -0400570 {
Corentin Wallezc295e512017-01-27 17:47:50 -0500571 currentDefault = mCurrentSurface->getDefaultFramebuffer();
572 }
573 else if (mSurfacelessFramebuffer != nullptr)
574 {
575 currentDefault = mSurfacelessFramebuffer;
Corentin Wallez51706ea2015-08-07 14:39:22 -0400576 }
577
Corentin Wallezc295e512017-01-27 17:47:50 -0500578 if (mGLState.getReadFramebuffer() == currentDefault)
579 {
580 mGLState.setReadFramebufferBinding(nullptr);
581 }
582 if (mGLState.getDrawFramebuffer() == currentDefault)
583 {
584 mGLState.setDrawFramebufferBinding(nullptr);
585 }
586 mState.mFramebuffers->setDefaultFramebuffer(nullptr);
587
588 if (mCurrentSurface)
589 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400590 ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
Corentin Wallezc295e512017-01-27 17:47:50 -0500591 mCurrentSurface = nullptr;
592 }
Jamie Madill4928b7c2017-06-20 12:57:39 -0400593
594 return egl::NoError();
Jamie Madill77a72f62015-04-14 11:18:32 -0400595}
596
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000597GLuint Context::createBuffer()
598{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500599 return mState.mBuffers->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000600}
601
602GLuint Context::createProgram()
603{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500604 return mState.mShaderPrograms->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000605}
606
607GLuint Context::createShader(GLenum type)
608{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500609 return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000610}
611
612GLuint Context::createTexture()
613{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500614 return mState.mTextures->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000615}
616
617GLuint Context::createRenderbuffer()
618{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500619 return mState.mRenderbuffers->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000620}
621
Sami Väisänene45e53b2016-05-25 10:36:04 +0300622GLuint Context::createPaths(GLsizei range)
623{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500624 auto resultOrError = mState.mPaths->createPaths(mImplementation.get(), range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300625 if (resultOrError.isError())
626 {
627 handleError(resultOrError.getError());
628 return 0;
629 }
630 return resultOrError.getResult();
631}
632
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000633// Returns an unused framebuffer name
634GLuint Context::createFramebuffer()
635{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500636 return mState.mFramebuffers->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000637}
638
Jamie Madill33dc8432013-07-26 11:55:05 -0400639GLuint Context::createFenceNV()
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000640{
Jamie Madill33dc8432013-07-26 11:55:05 -0400641 GLuint handle = mFenceNVHandleAllocator.allocate();
Jamie Madill96a483b2017-06-27 16:49:21 -0400642 mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV()));
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000643 return handle;
644}
645
Yunchao Hea336b902017-08-02 16:05:21 +0800646GLuint Context::createProgramPipeline()
647{
648 return mState.mPipelines->createProgramPipeline();
649}
650
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000651void Context::deleteBuffer(GLuint buffer)
652{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500653 if (mState.mBuffers->getBuffer(buffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000654 {
655 detachBuffer(buffer);
656 }
Jamie Madill893ab082014-05-16 16:56:10 -0400657
Jamie Madill6c1f6712017-02-14 19:08:04 -0500658 mState.mBuffers->deleteObject(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000659}
660
661void Context::deleteShader(GLuint shader)
662{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500663 mState.mShaderPrograms->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000664}
665
666void Context::deleteProgram(GLuint program)
667{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500668 mState.mShaderPrograms->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000669}
670
671void Context::deleteTexture(GLuint texture)
672{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500673 if (mState.mTextures->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000674 {
675 detachTexture(texture);
676 }
677
Jamie Madill6c1f6712017-02-14 19:08:04 -0500678 mState.mTextures->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000679}
680
681void Context::deleteRenderbuffer(GLuint renderbuffer)
682{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500683 if (mState.mRenderbuffers->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000684 {
685 detachRenderbuffer(renderbuffer);
686 }
Jamie Madill893ab082014-05-16 16:56:10 -0400687
Jamie Madill6c1f6712017-02-14 19:08:04 -0500688 mState.mRenderbuffers->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000689}
690
Jamie Madill7f0c5a42017-08-26 22:43:26 -0400691void Context::deleteSync(GLsync sync)
Jamie Madillcd055f82013-07-26 11:55:15 -0400692{
693 // The spec specifies the underlying Fence object is not deleted until all current
694 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
695 // and since our API is currently designed for being called from a single thread, we can delete
696 // the fence immediately.
Jamie Madill70b5bb02017-08-28 13:32:37 -0400697 mState.mSyncs->deleteObject(this, static_cast<GLuint>(reinterpret_cast<uintptr_t>(sync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400698}
699
Yunchao Hea336b902017-08-02 16:05:21 +0800700void Context::deleteProgramPipeline(GLuint pipeline)
701{
702 if (mState.mPipelines->getProgramPipeline(pipeline))
703 {
704 detachProgramPipeline(pipeline);
705 }
706
707 mState.mPipelines->deleteObject(this, pipeline);
708}
709
Sami Väisänene45e53b2016-05-25 10:36:04 +0300710void Context::deletePaths(GLuint first, GLsizei range)
711{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500712 mState.mPaths->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300713}
714
715bool Context::hasPathData(GLuint path) const
716{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500717 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300718 if (pathObj == nullptr)
719 return false;
720
721 return pathObj->hasPathData();
722}
723
724bool Context::hasPath(GLuint path) const
725{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500726 return mState.mPaths->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300727}
728
729void Context::setPathCommands(GLuint path,
730 GLsizei numCommands,
731 const GLubyte *commands,
732 GLsizei numCoords,
733 GLenum coordType,
734 const void *coords)
735{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500736 auto *pathObject = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300737
738 handleError(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
739}
740
741void Context::setPathParameterf(GLuint path, GLenum pname, GLfloat value)
742{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500743 auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300744
745 switch (pname)
746 {
747 case GL_PATH_STROKE_WIDTH_CHROMIUM:
748 pathObj->setStrokeWidth(value);
749 break;
750 case GL_PATH_END_CAPS_CHROMIUM:
751 pathObj->setEndCaps(static_cast<GLenum>(value));
752 break;
753 case GL_PATH_JOIN_STYLE_CHROMIUM:
754 pathObj->setJoinStyle(static_cast<GLenum>(value));
755 break;
756 case GL_PATH_MITER_LIMIT_CHROMIUM:
757 pathObj->setMiterLimit(value);
758 break;
759 case GL_PATH_STROKE_BOUND_CHROMIUM:
760 pathObj->setStrokeBound(value);
761 break;
762 default:
763 UNREACHABLE();
764 break;
765 }
766}
767
768void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value) const
769{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500770 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300771
772 switch (pname)
773 {
774 case GL_PATH_STROKE_WIDTH_CHROMIUM:
775 *value = pathObj->getStrokeWidth();
776 break;
777 case GL_PATH_END_CAPS_CHROMIUM:
778 *value = static_cast<GLfloat>(pathObj->getEndCaps());
779 break;
780 case GL_PATH_JOIN_STYLE_CHROMIUM:
781 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
782 break;
783 case GL_PATH_MITER_LIMIT_CHROMIUM:
784 *value = pathObj->getMiterLimit();
785 break;
786 case GL_PATH_STROKE_BOUND_CHROMIUM:
787 *value = pathObj->getStrokeBound();
788 break;
789 default:
790 UNREACHABLE();
791 break;
792 }
793}
794
795void Context::setPathStencilFunc(GLenum func, GLint ref, GLuint mask)
796{
797 mGLState.setPathStencilFunc(func, ref, mask);
798}
799
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000800void Context::deleteFramebuffer(GLuint framebuffer)
801{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500802 if (mState.mFramebuffers->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000803 {
804 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000805 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500806
Jamie Madill6c1f6712017-02-14 19:08:04 -0500807 mState.mFramebuffers->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000808}
809
Jamie Madill33dc8432013-07-26 11:55:05 -0400810void Context::deleteFenceNV(GLuint fence)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000811{
Jamie Madill96a483b2017-06-27 16:49:21 -0400812 FenceNV *fenceObject = nullptr;
813 if (mFenceNVMap.erase(fence, &fenceObject))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000814 {
Jamie Madill96a483b2017-06-27 16:49:21 -0400815 mFenceNVHandleAllocator.release(fence);
816 delete fenceObject;
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000817 }
818}
819
Geoff Lang70d0f492015-12-10 17:45:46 -0500820Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000821{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500822 return mState.mBuffers->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000823}
824
Jamie Madill570f7c82014-07-03 10:38:54 -0400825Texture *Context::getTexture(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000826{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500827 return mState.mTextures->getTexture(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000828}
829
Geoff Lang70d0f492015-12-10 17:45:46 -0500830Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000831{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500832 return mState.mRenderbuffers->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000833}
834
Jamie Madill70b5bb02017-08-28 13:32:37 -0400835Sync *Context::getSync(GLsync handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400836{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400837 return mState.mSyncs->getSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400838}
839
Jamie Madill57a89722013-07-02 11:57:03 -0400840VertexArray *Context::getVertexArray(GLuint handle) const
841{
Jamie Madill96a483b2017-06-27 16:49:21 -0400842 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -0400843}
844
Jamie Madilldc356042013-07-19 16:36:57 -0400845Sampler *Context::getSampler(GLuint handle) const
846{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500847 return mState.mSamplers->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400848}
849
Geoff Langc8058452014-02-03 12:04:11 -0500850TransformFeedback *Context::getTransformFeedback(GLuint handle) const
851{
Jamie Madill96a483b2017-06-27 16:49:21 -0400852 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -0500853}
854
Yunchao Hea336b902017-08-02 16:05:21 +0800855ProgramPipeline *Context::getProgramPipeline(GLuint handle) const
856{
857 return mState.mPipelines->getProgramPipeline(handle);
858}
859
Geoff Lang70d0f492015-12-10 17:45:46 -0500860LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
861{
862 switch (identifier)
863 {
864 case GL_BUFFER:
865 return getBuffer(name);
866 case GL_SHADER:
867 return getShader(name);
868 case GL_PROGRAM:
869 return getProgram(name);
870 case GL_VERTEX_ARRAY:
871 return getVertexArray(name);
872 case GL_QUERY:
873 return getQuery(name);
874 case GL_TRANSFORM_FEEDBACK:
875 return getTransformFeedback(name);
876 case GL_SAMPLER:
877 return getSampler(name);
878 case GL_TEXTURE:
879 return getTexture(name);
880 case GL_RENDERBUFFER:
881 return getRenderbuffer(name);
882 case GL_FRAMEBUFFER:
883 return getFramebuffer(name);
884 default:
885 UNREACHABLE();
886 return nullptr;
887 }
888}
889
890LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
891{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400892 return getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
Geoff Lang70d0f492015-12-10 17:45:46 -0500893}
894
Martin Radev9d901792016-07-15 15:58:58 +0300895void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
896{
897 LabeledObject *object = getLabeledObject(identifier, name);
898 ASSERT(object != nullptr);
899
900 std::string labelName = GetObjectLabelFromPointer(length, label);
901 object->setLabel(labelName);
Jamie Madill8693bdb2017-09-02 15:32:14 -0400902
903 // TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the
904 // specified object is active until we do this.
905 mGLState.setObjectDirty(identifier);
Martin Radev9d901792016-07-15 15:58:58 +0300906}
907
908void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
909{
910 LabeledObject *object = getLabeledObjectFromPtr(ptr);
911 ASSERT(object != nullptr);
912
913 std::string labelName = GetObjectLabelFromPointer(length, label);
914 object->setLabel(labelName);
915}
916
917void Context::getObjectLabel(GLenum identifier,
918 GLuint name,
919 GLsizei bufSize,
920 GLsizei *length,
921 GLchar *label) const
922{
923 LabeledObject *object = getLabeledObject(identifier, name);
924 ASSERT(object != nullptr);
925
926 const std::string &objectLabel = object->getLabel();
927 GetObjectLabelBase(objectLabel, bufSize, length, label);
928}
929
930void Context::getObjectPtrLabel(const void *ptr,
931 GLsizei bufSize,
932 GLsizei *length,
933 GLchar *label) const
934{
935 LabeledObject *object = getLabeledObjectFromPtr(ptr);
936 ASSERT(object != nullptr);
937
938 const std::string &objectLabel = object->getLabel();
939 GetObjectLabelBase(objectLabel, bufSize, length, label);
940}
941
Jamie Madilldc356042013-07-19 16:36:57 -0400942bool Context::isSampler(GLuint samplerName) const
943{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500944 return mState.mSamplers->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -0400945}
946
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500947void Context::bindArrayBuffer(GLuint bufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000948{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500949 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400950 mGLState.setArrayBufferBinding(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000951}
952
Jiajia Qin9d7d0b12016-11-29 16:30:31 +0800953void Context::bindDrawIndirectBuffer(GLuint bufferHandle)
954{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500955 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400956 mGLState.setDrawIndirectBufferBinding(this, buffer);
Jiajia Qin9d7d0b12016-11-29 16:30:31 +0800957}
958
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500959void Context::bindElementArrayBuffer(GLuint bufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000960{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500961 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400962 mGLState.setElementArrayBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000963}
964
Jamie Madilldedd7b92014-11-05 16:30:36 -0500965void Context::bindTexture(GLenum target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000966{
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500967 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000968
Jamie Madilldedd7b92014-11-05 16:30:36 -0500969 if (handle == 0)
970 {
971 texture = mZeroTextures[target].get();
972 }
973 else
974 {
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500975 texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500976 }
977
978 ASSERT(texture);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400979 mGLState.setSamplerTexture(this, target, texture);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +0000980}
981
Jamie Madill5bf9ff42016-02-01 11:13:03 -0500982void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000983{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500984 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
985 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700986 mGLState.setReadFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000987}
988
Jamie Madill5bf9ff42016-02-01 11:13:03 -0500989void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000990{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500991 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
992 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700993 mGLState.setDrawFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000994}
995
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500996void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -0400997{
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500998 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700999 mGLState.setVertexArrayBinding(vertexArray);
Jamie Madill57a89722013-07-02 11:57:03 -04001000}
1001
Shao80957d92017-02-20 21:25:59 +08001002void Context::bindVertexBuffer(GLuint bindingIndex,
1003 GLuint bufferHandle,
1004 GLintptr offset,
1005 GLsizei stride)
1006{
1007 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001008 mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Shao80957d92017-02-20 21:25:59 +08001009}
1010
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001011void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -04001012{
Geoff Lang76b10c92014-09-05 16:28:14 -04001013 ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -04001014 Sampler *sampler =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001015 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001016 mGLState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04001017}
1018
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001019void Context::bindImageTexture(GLuint unit,
1020 GLuint texture,
1021 GLint level,
1022 GLboolean layered,
1023 GLint layer,
1024 GLenum access,
1025 GLenum format)
1026{
1027 Texture *tex = mState.mTextures->getTexture(texture);
1028 mGLState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
1029}
1030
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001031void Context::bindGenericUniformBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001032{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001033 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001034 mGLState.setGenericUniformBufferBinding(this, buffer);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001035}
1036
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001037void Context::bindIndexedUniformBuffer(GLuint bufferHandle,
1038 GLuint index,
1039 GLintptr offset,
1040 GLsizeiptr size)
shannon.woods%transgaming.com@gtempaccount.com34089352013-04-13 03:36:57 +00001041{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001042 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001043 mGLState.setIndexedUniformBufferBinding(this, index, buffer, offset, size);
shannon.woods%transgaming.com@gtempaccount.com34089352013-04-13 03:36:57 +00001044}
1045
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001046void Context::bindGenericTransformFeedbackBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001047{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001048 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001049 mGLState.getCurrentTransformFeedback()->bindGenericBuffer(this, buffer);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001050}
1051
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001052void Context::bindIndexedTransformFeedbackBuffer(GLuint bufferHandle,
1053 GLuint index,
1054 GLintptr offset,
1055 GLsizeiptr size)
shannon.woods%transgaming.com@gtempaccount.com34089352013-04-13 03:36:57 +00001056{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001057 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001058 mGLState.getCurrentTransformFeedback()->bindIndexedBuffer(this, index, buffer, offset, size);
shannon.woods%transgaming.com@gtempaccount.com34089352013-04-13 03:36:57 +00001059}
1060
Jiajia Qin6eafb042016-12-27 17:04:07 +08001061void Context::bindGenericAtomicCounterBuffer(GLuint bufferHandle)
1062{
1063 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001064 mGLState.setGenericAtomicCounterBufferBinding(this, buffer);
Jiajia Qin6eafb042016-12-27 17:04:07 +08001065}
1066
1067void Context::bindIndexedAtomicCounterBuffer(GLuint bufferHandle,
1068 GLuint index,
1069 GLintptr offset,
1070 GLsizeiptr size)
1071{
1072 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001073 mGLState.setIndexedAtomicCounterBufferBinding(this, index, buffer, offset, size);
Jiajia Qin6eafb042016-12-27 17:04:07 +08001074}
1075
Jiajia Qinf546e7d2017-03-27 14:12:59 +08001076void Context::bindGenericShaderStorageBuffer(GLuint bufferHandle)
1077{
1078 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001079 mGLState.setGenericShaderStorageBufferBinding(this, buffer);
Jiajia Qinf546e7d2017-03-27 14:12:59 +08001080}
1081
1082void Context::bindIndexedShaderStorageBuffer(GLuint bufferHandle,
1083 GLuint index,
1084 GLintptr offset,
1085 GLsizeiptr size)
1086{
1087 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001088 mGLState.setIndexedShaderStorageBufferBinding(this, index, buffer, offset, size);
Jiajia Qinf546e7d2017-03-27 14:12:59 +08001089}
1090
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001091void Context::bindCopyReadBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001092{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001093 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001094 mGLState.setCopyReadBufferBinding(this, buffer);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001095}
1096
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001097void Context::bindCopyWriteBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001098{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001099 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001100 mGLState.setCopyWriteBufferBinding(this, buffer);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001101}
1102
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001103void Context::bindPixelPackBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001104{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001105 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001106 mGLState.setPixelPackBufferBinding(this, buffer);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001107}
1108
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001109void Context::bindPixelUnpackBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001110{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001111 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001112 mGLState.setPixelUnpackBufferBinding(this, buffer);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001113}
1114
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001115void Context::useProgram(GLuint program)
1116{
Jamie Madill6c1f6712017-02-14 19:08:04 -05001117 mGLState.setProgram(this, getProgram(program));
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001118}
1119
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001120void Context::bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001121{
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001122 ASSERT(target == GL_TRANSFORM_FEEDBACK);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001123 TransformFeedback *transformFeedback =
1124 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001125 mGLState.setTransformFeedbackBinding(this, transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -05001126}
1127
Yunchao Hea336b902017-08-02 16:05:21 +08001128void Context::bindProgramPipeline(GLuint pipelineHandle)
1129{
1130 ProgramPipeline *pipeline =
1131 mState.mPipelines->checkProgramPipelineAllocation(mImplementation.get(), pipelineHandle);
1132 mGLState.setProgramPipelineBinding(this, pipeline);
1133}
1134
Jamie Madillf0e04492017-08-26 15:28:42 -04001135void Context::beginQuery(GLenum target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001136{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001137 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001138 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001139
Geoff Lang5aad9672014-09-08 11:10:42 -04001140 // begin query
Jamie Madillf0e04492017-08-26 15:28:42 -04001141 ANGLE_CONTEXT_TRY(queryObject->begin());
Geoff Lang5aad9672014-09-08 11:10:42 -04001142
1143 // set query as active for specified target only if begin succeeded
Jamie Madill4928b7c2017-06-20 12:57:39 -04001144 mGLState.setActiveQuery(this, target, queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001145}
1146
Jamie Madillf0e04492017-08-26 15:28:42 -04001147void Context::endQuery(GLenum target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001148{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001149 Query *queryObject = mGLState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001150 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001151
Jamie Madillf0e04492017-08-26 15:28:42 -04001152 handleError(queryObject->end());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001153
Geoff Lang5aad9672014-09-08 11:10:42 -04001154 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madill4928b7c2017-06-20 12:57:39 -04001155 mGLState.setActiveQuery(this, target, nullptr);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001156}
1157
Jamie Madillf0e04492017-08-26 15:28:42 -04001158void Context::queryCounter(GLuint id, GLenum target)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001159{
1160 ASSERT(target == GL_TIMESTAMP_EXT);
1161
1162 Query *queryObject = getQuery(id, true, target);
1163 ASSERT(queryObject);
1164
Jamie Madillf0e04492017-08-26 15:28:42 -04001165 handleError(queryObject->queryCounter());
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001166}
1167
1168void Context::getQueryiv(GLenum target, GLenum pname, GLint *params)
1169{
1170 switch (pname)
1171 {
1172 case GL_CURRENT_QUERY_EXT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001173 params[0] = mGLState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001174 break;
1175 case GL_QUERY_COUNTER_BITS_EXT:
1176 switch (target)
1177 {
1178 case GL_TIME_ELAPSED_EXT:
1179 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1180 break;
1181 case GL_TIMESTAMP_EXT:
1182 params[0] = getExtensions().queryCounterBitsTimestamp;
1183 break;
1184 default:
1185 UNREACHABLE();
1186 params[0] = 0;
1187 break;
1188 }
1189 break;
1190 default:
1191 UNREACHABLE();
1192 return;
1193 }
1194}
1195
Geoff Lang2186c382016-10-14 10:54:54 -04001196void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001197{
Geoff Lang2186c382016-10-14 10:54:54 -04001198 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001199}
1200
Geoff Lang2186c382016-10-14 10:54:54 -04001201void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001202{
Geoff Lang2186c382016-10-14 10:54:54 -04001203 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001204}
1205
Geoff Lang2186c382016-10-14 10:54:54 -04001206void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001207{
Geoff Lang2186c382016-10-14 10:54:54 -04001208 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001209}
1210
Geoff Lang2186c382016-10-14 10:54:54 -04001211void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001212{
Geoff Lang2186c382016-10-14 10:54:54 -04001213 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001214}
1215
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001216Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001217{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001218 return mState.mFramebuffers->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001219}
1220
Jamie Madill2f348d22017-06-05 10:50:59 -04001221FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001222{
Jamie Madill96a483b2017-06-27 16:49:21 -04001223 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001224}
1225
Jamie Madill2f348d22017-06-05 10:50:59 -04001226Query *Context::getQuery(GLuint handle, bool create, GLenum type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001227{
Jamie Madill96a483b2017-06-27 16:49:21 -04001228 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001229 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001230 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001231 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001232
1233 Query *query = mQueryMap.query(handle);
1234 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001235 {
Jamie Madill96a483b2017-06-27 16:49:21 -04001236 query = new Query(mImplementation->createQuery(type), handle);
1237 query->addRef();
1238 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001239 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001240 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001241}
1242
Geoff Lang70d0f492015-12-10 17:45:46 -05001243Query *Context::getQuery(GLuint handle) const
1244{
Jamie Madill96a483b2017-06-27 16:49:21 -04001245 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001246}
1247
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001248Texture *Context::getTargetTexture(GLenum target) const
1249{
Ian Ewellbda75592016-04-18 17:25:54 -04001250 ASSERT(ValidTextureTarget(this, target) || ValidTextureExternalTarget(this, target));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001251 return mGLState.getTargetTexture(target);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001252}
1253
Geoff Lang76b10c92014-09-05 16:28:14 -04001254Texture *Context::getSamplerTexture(unsigned int sampler, GLenum type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001255{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001256 return mGLState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001257}
1258
Geoff Lang492a7e42014-11-05 13:27:06 -05001259Compiler *Context::getCompiler() const
1260{
Jamie Madill2f348d22017-06-05 10:50:59 -04001261 if (mCompiler.get() == nullptr)
1262 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001263 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001264 }
1265 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001266}
1267
Jamie Madillc1d770e2017-04-13 17:31:24 -04001268void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001269{
1270 switch (pname)
1271 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001272 case GL_SHADER_COMPILER:
1273 *params = GL_TRUE;
1274 break;
1275 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1276 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1277 break;
1278 default:
1279 mGLState.getBooleanv(pname, params);
1280 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001281 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001282}
1283
Jamie Madillc1d770e2017-04-13 17:31:24 -04001284void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001285{
Shannon Woods53a94a82014-06-24 15:20:36 -04001286 // Queries about context capabilities and maximums are answered by Context.
1287 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001288 switch (pname)
1289 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001290 case GL_ALIASED_LINE_WIDTH_RANGE:
1291 params[0] = mCaps.minAliasedLineWidth;
1292 params[1] = mCaps.maxAliasedLineWidth;
1293 break;
1294 case GL_ALIASED_POINT_SIZE_RANGE:
1295 params[0] = mCaps.minAliasedPointSize;
1296 params[1] = mCaps.maxAliasedPointSize;
1297 break;
1298 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1299 ASSERT(mExtensions.textureFilterAnisotropic);
1300 *params = mExtensions.maxTextureAnisotropy;
1301 break;
1302 case GL_MAX_TEXTURE_LOD_BIAS:
1303 *params = mCaps.maxLODBias;
1304 break;
1305
1306 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1307 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1308 {
1309 ASSERT(mExtensions.pathRendering);
1310 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1311 memcpy(params, m, 16 * sizeof(GLfloat));
1312 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001313 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001314
Jamie Madill231c7f52017-04-26 13:45:37 -04001315 default:
1316 mGLState.getFloatv(pname, params);
1317 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001318 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001319}
1320
Jamie Madillc1d770e2017-04-13 17:31:24 -04001321void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001322{
Shannon Woods53a94a82014-06-24 15:20:36 -04001323 // Queries about context capabilities and maximums are answered by Context.
1324 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001325
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001326 switch (pname)
1327 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001328 case GL_MAX_VERTEX_ATTRIBS:
1329 *params = mCaps.maxVertexAttributes;
1330 break;
1331 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1332 *params = mCaps.maxVertexUniformVectors;
1333 break;
1334 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
1335 *params = mCaps.maxVertexUniformComponents;
1336 break;
1337 case GL_MAX_VARYING_VECTORS:
1338 *params = mCaps.maxVaryingVectors;
1339 break;
1340 case GL_MAX_VARYING_COMPONENTS:
1341 *params = mCaps.maxVertexOutputComponents;
1342 break;
1343 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1344 *params = mCaps.maxCombinedTextureImageUnits;
1345 break;
1346 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
1347 *params = mCaps.maxVertexTextureImageUnits;
1348 break;
1349 case GL_MAX_TEXTURE_IMAGE_UNITS:
1350 *params = mCaps.maxTextureImageUnits;
1351 break;
1352 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1353 *params = mCaps.maxFragmentUniformVectors;
1354 break;
1355 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
1356 *params = mCaps.maxFragmentUniformComponents;
1357 break;
1358 case GL_MAX_RENDERBUFFER_SIZE:
1359 *params = mCaps.maxRenderbufferSize;
1360 break;
1361 case GL_MAX_COLOR_ATTACHMENTS_EXT:
1362 *params = mCaps.maxColorAttachments;
1363 break;
1364 case GL_MAX_DRAW_BUFFERS_EXT:
1365 *params = mCaps.maxDrawBuffers;
1366 break;
1367 // case GL_FRAMEBUFFER_BINDING: // now equivalent to
1368 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
1369 case GL_SUBPIXEL_BITS:
1370 *params = 4;
1371 break;
1372 case GL_MAX_TEXTURE_SIZE:
1373 *params = mCaps.max2DTextureSize;
1374 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001375 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
1376 *params = mCaps.maxRectangleTextureSize;
1377 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001378 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1379 *params = mCaps.maxCubeMapTextureSize;
1380 break;
1381 case GL_MAX_3D_TEXTURE_SIZE:
1382 *params = mCaps.max3DTextureSize;
1383 break;
1384 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1385 *params = mCaps.maxArrayTextureLayers;
1386 break;
1387 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1388 *params = mCaps.uniformBufferOffsetAlignment;
1389 break;
1390 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1391 *params = mCaps.maxUniformBufferBindings;
1392 break;
1393 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
1394 *params = mCaps.maxVertexUniformBlocks;
1395 break;
1396 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
1397 *params = mCaps.maxFragmentUniformBlocks;
1398 break;
1399 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1400 *params = mCaps.maxCombinedTextureImageUnits;
1401 break;
1402 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1403 *params = mCaps.maxVertexOutputComponents;
1404 break;
1405 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1406 *params = mCaps.maxFragmentInputComponents;
1407 break;
1408 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1409 *params = mCaps.minProgramTexelOffset;
1410 break;
1411 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1412 *params = mCaps.maxProgramTexelOffset;
1413 break;
1414 case GL_MAJOR_VERSION:
1415 *params = getClientVersion().major;
1416 break;
1417 case GL_MINOR_VERSION:
1418 *params = getClientVersion().minor;
1419 break;
1420 case GL_MAX_ELEMENTS_INDICES:
1421 *params = mCaps.maxElementsIndices;
1422 break;
1423 case GL_MAX_ELEMENTS_VERTICES:
1424 *params = mCaps.maxElementsVertices;
1425 break;
1426 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1427 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1428 break;
1429 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1430 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1431 break;
1432 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1433 *params = mCaps.maxTransformFeedbackSeparateComponents;
1434 break;
1435 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1436 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1437 break;
1438 case GL_MAX_SAMPLES_ANGLE:
1439 *params = mCaps.maxSamples;
1440 break;
1441 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001442 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001443 params[0] = mCaps.maxViewportWidth;
1444 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001445 }
1446 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001447 case GL_COMPRESSED_TEXTURE_FORMATS:
1448 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1449 params);
1450 break;
1451 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1452 *params = mResetStrategy;
1453 break;
1454 case GL_NUM_SHADER_BINARY_FORMATS:
1455 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1456 break;
1457 case GL_SHADER_BINARY_FORMATS:
1458 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1459 break;
1460 case GL_NUM_PROGRAM_BINARY_FORMATS:
1461 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1462 break;
1463 case GL_PROGRAM_BINARY_FORMATS:
1464 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1465 break;
1466 case GL_NUM_EXTENSIONS:
1467 *params = static_cast<GLint>(mExtensionStrings.size());
1468 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001469
Jamie Madill231c7f52017-04-26 13:45:37 -04001470 // GL_KHR_debug
1471 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1472 *params = mExtensions.maxDebugMessageLength;
1473 break;
1474 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1475 *params = mExtensions.maxDebugLoggedMessages;
1476 break;
1477 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1478 *params = mExtensions.maxDebugGroupStackDepth;
1479 break;
1480 case GL_MAX_LABEL_LENGTH:
1481 *params = mExtensions.maxLabelLength;
1482 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001483
Martin Radeve5285d22017-07-14 16:23:53 +03001484 // GL_ANGLE_multiview
1485 case GL_MAX_VIEWS_ANGLE:
1486 *params = mExtensions.maxViews;
1487 break;
1488
Jamie Madill231c7f52017-04-26 13:45:37 -04001489 // GL_EXT_disjoint_timer_query
1490 case GL_GPU_DISJOINT_EXT:
1491 *params = mImplementation->getGPUDisjoint();
1492 break;
1493 case GL_MAX_FRAMEBUFFER_WIDTH:
1494 *params = mCaps.maxFramebufferWidth;
1495 break;
1496 case GL_MAX_FRAMEBUFFER_HEIGHT:
1497 *params = mCaps.maxFramebufferHeight;
1498 break;
1499 case GL_MAX_FRAMEBUFFER_SAMPLES:
1500 *params = mCaps.maxFramebufferSamples;
1501 break;
1502 case GL_MAX_SAMPLE_MASK_WORDS:
1503 *params = mCaps.maxSampleMaskWords;
1504 break;
1505 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1506 *params = mCaps.maxColorTextureSamples;
1507 break;
1508 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1509 *params = mCaps.maxDepthTextureSamples;
1510 break;
1511 case GL_MAX_INTEGER_SAMPLES:
1512 *params = mCaps.maxIntegerSamples;
1513 break;
1514 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1515 *params = mCaps.maxVertexAttribRelativeOffset;
1516 break;
1517 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1518 *params = mCaps.maxVertexAttribBindings;
1519 break;
1520 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1521 *params = mCaps.maxVertexAttribStride;
1522 break;
1523 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
1524 *params = mCaps.maxVertexAtomicCounterBuffers;
1525 break;
1526 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
1527 *params = mCaps.maxVertexAtomicCounters;
1528 break;
1529 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
1530 *params = mCaps.maxVertexImageUniforms;
1531 break;
1532 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
1533 *params = mCaps.maxVertexShaderStorageBlocks;
1534 break;
1535 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
1536 *params = mCaps.maxFragmentAtomicCounterBuffers;
1537 break;
1538 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
1539 *params = mCaps.maxFragmentAtomicCounters;
1540 break;
1541 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
1542 *params = mCaps.maxFragmentImageUniforms;
1543 break;
1544 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
1545 *params = mCaps.maxFragmentShaderStorageBlocks;
1546 break;
1547 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1548 *params = mCaps.minProgramTextureGatherOffset;
1549 break;
1550 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1551 *params = mCaps.maxProgramTextureGatherOffset;
1552 break;
1553 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1554 *params = mCaps.maxComputeWorkGroupInvocations;
1555 break;
1556 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
1557 *params = mCaps.maxComputeUniformBlocks;
1558 break;
1559 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
1560 *params = mCaps.maxComputeTextureImageUnits;
1561 break;
1562 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1563 *params = mCaps.maxComputeSharedMemorySize;
1564 break;
1565 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
1566 *params = mCaps.maxComputeUniformComponents;
1567 break;
1568 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
1569 *params = mCaps.maxComputeAtomicCounterBuffers;
1570 break;
1571 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
1572 *params = mCaps.maxComputeAtomicCounters;
1573 break;
1574 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
1575 *params = mCaps.maxComputeImageUniforms;
1576 break;
1577 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
1578 *params = mCaps.maxCombinedComputeUniformComponents;
1579 break;
1580 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
1581 *params = mCaps.maxComputeShaderStorageBlocks;
1582 break;
1583 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1584 *params = mCaps.maxCombinedShaderOutputResources;
1585 break;
1586 case GL_MAX_UNIFORM_LOCATIONS:
1587 *params = mCaps.maxUniformLocations;
1588 break;
1589 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1590 *params = mCaps.maxAtomicCounterBufferBindings;
1591 break;
1592 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1593 *params = mCaps.maxAtomicCounterBufferSize;
1594 break;
1595 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1596 *params = mCaps.maxCombinedAtomicCounterBuffers;
1597 break;
1598 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1599 *params = mCaps.maxCombinedAtomicCounters;
1600 break;
1601 case GL_MAX_IMAGE_UNITS:
1602 *params = mCaps.maxImageUnits;
1603 break;
1604 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1605 *params = mCaps.maxCombinedImageUniforms;
1606 break;
1607 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1608 *params = mCaps.maxShaderStorageBufferBindings;
1609 break;
1610 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1611 *params = mCaps.maxCombinedShaderStorageBlocks;
1612 break;
1613 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1614 *params = mCaps.shaderStorageBufferOffsetAlignment;
1615 break;
1616 default:
1617 mGLState.getIntegerv(this, pname, params);
1618 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001619 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001620}
1621
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001622void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001623{
Shannon Woods53a94a82014-06-24 15:20:36 -04001624 // Queries about context capabilities and maximums are answered by Context.
1625 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001626 switch (pname)
1627 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001628 case GL_MAX_ELEMENT_INDEX:
1629 *params = mCaps.maxElementIndex;
1630 break;
1631 case GL_MAX_UNIFORM_BLOCK_SIZE:
1632 *params = mCaps.maxUniformBlockSize;
1633 break;
1634 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
1635 *params = mCaps.maxCombinedVertexUniformComponents;
1636 break;
1637 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
1638 *params = mCaps.maxCombinedFragmentUniformComponents;
1639 break;
1640 case GL_MAX_SERVER_WAIT_TIMEOUT:
1641 *params = mCaps.maxServerWaitTimeout;
1642 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001643
Jamie Madill231c7f52017-04-26 13:45:37 -04001644 // GL_EXT_disjoint_timer_query
1645 case GL_TIMESTAMP_EXT:
1646 *params = mImplementation->getTimestamp();
1647 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001648
Jamie Madill231c7f52017-04-26 13:45:37 -04001649 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1650 *params = mCaps.maxShaderStorageBlockSize;
1651 break;
1652 default:
1653 UNREACHABLE();
1654 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001655 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001656}
1657
Geoff Lang70d0f492015-12-10 17:45:46 -05001658void Context::getPointerv(GLenum pname, void **params) const
1659{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001660 mGLState.getPointerv(pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001661}
1662
Martin Radev66fb8202016-07-28 11:45:20 +03001663void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001664{
Shannon Woods53a94a82014-06-24 15:20:36 -04001665 // Queries about context capabilities and maximums are answered by Context.
1666 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001667
1668 GLenum nativeType;
1669 unsigned int numParams;
1670 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1671 ASSERT(queryStatus);
1672
1673 if (nativeType == GL_INT)
1674 {
1675 switch (target)
1676 {
1677 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1678 ASSERT(index < 3u);
1679 *data = mCaps.maxComputeWorkGroupCount[index];
1680 break;
1681 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1682 ASSERT(index < 3u);
1683 *data = mCaps.maxComputeWorkGroupSize[index];
1684 break;
1685 default:
1686 mGLState.getIntegeri_v(target, index, data);
1687 }
1688 }
1689 else
1690 {
1691 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1692 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001693}
1694
Martin Radev66fb8202016-07-28 11:45:20 +03001695void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001696{
Shannon Woods53a94a82014-06-24 15:20:36 -04001697 // Queries about context capabilities and maximums are answered by Context.
1698 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001699
1700 GLenum nativeType;
1701 unsigned int numParams;
1702 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1703 ASSERT(queryStatus);
1704
1705 if (nativeType == GL_INT_64_ANGLEX)
1706 {
1707 mGLState.getInteger64i_v(target, index, data);
1708 }
1709 else
1710 {
1711 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1712 }
1713}
1714
1715void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1716{
1717 // Queries about context capabilities and maximums are answered by Context.
1718 // Queries about current GL state values are answered by State.
1719
1720 GLenum nativeType;
1721 unsigned int numParams;
1722 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1723 ASSERT(queryStatus);
1724
1725 if (nativeType == GL_BOOL)
1726 {
1727 mGLState.getBooleani_v(target, index, data);
1728 }
1729 else
1730 {
1731 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1732 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001733}
1734
He Yunchao010e4db2017-03-03 14:22:06 +08001735void Context::getBufferParameteriv(GLenum target, GLenum pname, GLint *params)
1736{
1737 Buffer *buffer = mGLState.getTargetBuffer(target);
1738 QueryBufferParameteriv(buffer, pname, params);
1739}
1740
1741void Context::getFramebufferAttachmentParameteriv(GLenum target,
1742 GLenum attachment,
1743 GLenum pname,
1744 GLint *params)
1745{
1746 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
1747 QueryFramebufferAttachmentParameteriv(framebuffer, attachment, pname, params);
1748}
1749
1750void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
1751{
1752 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
1753 QueryRenderbufferiv(this, renderbuffer, pname, params);
1754}
1755
1756void Context::getTexParameterfv(GLenum target, GLenum pname, GLfloat *params)
1757{
1758 Texture *texture = getTargetTexture(target);
1759 QueryTexParameterfv(texture, pname, params);
1760}
1761
1762void Context::getTexParameteriv(GLenum target, GLenum pname, GLint *params)
1763{
1764 Texture *texture = getTargetTexture(target);
1765 QueryTexParameteriv(texture, pname, params);
1766}
1767void Context::texParameterf(GLenum target, GLenum pname, GLfloat param)
1768{
1769 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001770 SetTexParameterf(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04001771 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001772}
1773
1774void Context::texParameterfv(GLenum target, GLenum pname, const GLfloat *params)
1775{
1776 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001777 SetTexParameterfv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04001778 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001779}
1780
1781void Context::texParameteri(GLenum target, GLenum pname, GLint param)
1782{
1783 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001784 SetTexParameteri(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04001785 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001786}
1787
1788void Context::texParameteriv(GLenum target, GLenum pname, const GLint *params)
1789{
1790 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001791 SetTexParameteriv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04001792 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001793}
1794
Jamie Madill675fe712016-12-19 13:07:54 -05001795void Context::drawArrays(GLenum mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001796{
Jamie Madill05b35b22017-10-03 09:01:44 -04001797 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001798 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
1799 MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001800}
1801
Jamie Madill675fe712016-12-19 13:07:54 -05001802void Context::drawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04001803{
Jamie Madill05b35b22017-10-03 09:01:44 -04001804 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001805 ANGLE_CONTEXT_TRY(
1806 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
1807 MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback());
Geoff Langf6db0982015-08-25 13:04:00 -04001808}
1809
Jamie Madill876429b2017-04-20 15:46:24 -04001810void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001811{
Jamie Madill05b35b22017-10-03 09:01:44 -04001812 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001813 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04001814}
1815
Jamie Madill675fe712016-12-19 13:07:54 -05001816void Context::drawElementsInstanced(GLenum mode,
1817 GLsizei count,
1818 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04001819 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04001820 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04001821{
Jamie Madill05b35b22017-10-03 09:01:44 -04001822 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001823 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08001824 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04001825}
1826
Jamie Madill675fe712016-12-19 13:07:54 -05001827void Context::drawRangeElements(GLenum mode,
1828 GLuint start,
1829 GLuint end,
1830 GLsizei count,
1831 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04001832 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04001833{
Jamie Madill05b35b22017-10-03 09:01:44 -04001834 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001835 ANGLE_CONTEXT_TRY(
1836 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001837}
1838
Jamie Madill876429b2017-04-20 15:46:24 -04001839void Context::drawArraysIndirect(GLenum mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08001840{
Jamie Madill05b35b22017-10-03 09:01:44 -04001841 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001842 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08001843}
1844
Jamie Madill876429b2017-04-20 15:46:24 -04001845void Context::drawElementsIndirect(GLenum mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08001846{
Jamie Madill05b35b22017-10-03 09:01:44 -04001847 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001848 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08001849}
1850
Jamie Madill675fe712016-12-19 13:07:54 -05001851void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001852{
Jamie Madill675fe712016-12-19 13:07:54 -05001853 handleError(mImplementation->flush());
Geoff Lang129753a2015-01-09 16:52:09 -05001854}
1855
Jamie Madill675fe712016-12-19 13:07:54 -05001856void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05001857{
Jamie Madill675fe712016-12-19 13:07:54 -05001858 handleError(mImplementation->finish());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001859}
1860
Austin Kinross6ee1e782015-05-29 17:05:37 -07001861void Context::insertEventMarker(GLsizei length, const char *marker)
1862{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001863 ASSERT(mImplementation);
1864 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07001865}
1866
1867void Context::pushGroupMarker(GLsizei length, const char *marker)
1868{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001869 ASSERT(mImplementation);
1870 mImplementation->pushGroupMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07001871}
1872
1873void Context::popGroupMarker()
1874{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001875 ASSERT(mImplementation);
1876 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07001877}
1878
Geoff Langd8605522016-04-13 10:19:12 -04001879void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
1880{
1881 Program *programObject = getProgram(program);
1882 ASSERT(programObject);
1883
1884 programObject->bindUniformLocation(location, name);
1885}
1886
Sami Väisänena797e062016-05-12 15:23:40 +03001887void Context::setCoverageModulation(GLenum components)
1888{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001889 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03001890}
1891
Sami Väisänene45e53b2016-05-25 10:36:04 +03001892void Context::loadPathRenderingMatrix(GLenum matrixMode, const GLfloat *matrix)
1893{
1894 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
1895}
1896
1897void Context::loadPathRenderingIdentityMatrix(GLenum matrixMode)
1898{
1899 GLfloat I[16];
1900 angle::Matrix<GLfloat>::setToIdentity(I);
1901
1902 mGLState.loadPathRenderingMatrix(matrixMode, I);
1903}
1904
1905void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
1906{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001907 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001908 if (!pathObj)
1909 return;
1910
1911 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1912 syncRendererState();
1913
1914 mImplementation->stencilFillPath(pathObj, fillMode, mask);
1915}
1916
1917void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
1918{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001919 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001920 if (!pathObj)
1921 return;
1922
1923 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1924 syncRendererState();
1925
1926 mImplementation->stencilStrokePath(pathObj, reference, mask);
1927}
1928
1929void Context::coverFillPath(GLuint path, GLenum coverMode)
1930{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001931 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001932 if (!pathObj)
1933 return;
1934
1935 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1936 syncRendererState();
1937
1938 mImplementation->coverFillPath(pathObj, coverMode);
1939}
1940
1941void Context::coverStrokePath(GLuint path, GLenum coverMode)
1942{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001943 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001944 if (!pathObj)
1945 return;
1946
1947 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1948 syncRendererState();
1949
1950 mImplementation->coverStrokePath(pathObj, coverMode);
1951}
1952
1953void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
1954{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001955 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001956 if (!pathObj)
1957 return;
1958
1959 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1960 syncRendererState();
1961
1962 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
1963}
1964
1965void Context::stencilThenCoverStrokePath(GLuint path,
1966 GLint reference,
1967 GLuint mask,
1968 GLenum coverMode)
1969{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001970 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001971 if (!pathObj)
1972 return;
1973
1974 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1975 syncRendererState();
1976
1977 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
1978}
1979
Sami Väisänend59ca052016-06-21 16:10:00 +03001980void Context::coverFillPathInstanced(GLsizei numPaths,
1981 GLenum pathNameType,
1982 const void *paths,
1983 GLuint pathBase,
1984 GLenum coverMode,
1985 GLenum transformType,
1986 const GLfloat *transformValues)
1987{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001988 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03001989
1990 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1991 syncRendererState();
1992
1993 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
1994}
Sami Väisänen46eaa942016-06-29 10:26:37 +03001995
Sami Väisänend59ca052016-06-21 16:10:00 +03001996void Context::coverStrokePathInstanced(GLsizei numPaths,
1997 GLenum pathNameType,
1998 const void *paths,
1999 GLuint pathBase,
2000 GLenum coverMode,
2001 GLenum transformType,
2002 const GLfloat *transformValues)
2003{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002004 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002005
2006 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2007 syncRendererState();
2008
2009 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2010 transformValues);
2011}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002012
Sami Väisänend59ca052016-06-21 16:10:00 +03002013void Context::stencilFillPathInstanced(GLsizei numPaths,
2014 GLenum pathNameType,
2015 const void *paths,
2016 GLuint pathBase,
2017 GLenum fillMode,
2018 GLuint mask,
2019 GLenum transformType,
2020 const GLfloat *transformValues)
2021{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002022 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002023
2024 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2025 syncRendererState();
2026
2027 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2028 transformValues);
2029}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002030
Sami Väisänend59ca052016-06-21 16:10:00 +03002031void Context::stencilStrokePathInstanced(GLsizei numPaths,
2032 GLenum pathNameType,
2033 const void *paths,
2034 GLuint pathBase,
2035 GLint reference,
2036 GLuint mask,
2037 GLenum transformType,
2038 const GLfloat *transformValues)
2039{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002040 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002041
2042 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2043 syncRendererState();
2044
2045 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2046 transformValues);
2047}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002048
Sami Väisänend59ca052016-06-21 16:10:00 +03002049void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2050 GLenum pathNameType,
2051 const void *paths,
2052 GLuint pathBase,
2053 GLenum fillMode,
2054 GLuint mask,
2055 GLenum coverMode,
2056 GLenum transformType,
2057 const GLfloat *transformValues)
2058{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002059 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002060
2061 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2062 syncRendererState();
2063
2064 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2065 transformType, transformValues);
2066}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002067
Sami Väisänend59ca052016-06-21 16:10:00 +03002068void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2069 GLenum pathNameType,
2070 const void *paths,
2071 GLuint pathBase,
2072 GLint reference,
2073 GLuint mask,
2074 GLenum coverMode,
2075 GLenum transformType,
2076 const GLfloat *transformValues)
2077{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002078 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002079
2080 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2081 syncRendererState();
2082
2083 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2084 transformType, transformValues);
2085}
2086
Sami Väisänen46eaa942016-06-29 10:26:37 +03002087void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2088{
2089 auto *programObject = getProgram(program);
2090
2091 programObject->bindFragmentInputLocation(location, name);
2092}
2093
2094void Context::programPathFragmentInputGen(GLuint program,
2095 GLint location,
2096 GLenum genMode,
2097 GLint components,
2098 const GLfloat *coeffs)
2099{
2100 auto *programObject = getProgram(program);
2101
Jamie Madillbd044ed2017-06-05 12:59:21 -04002102 programObject->pathFragmentInputGen(this, location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002103}
2104
jchen1015015f72017-03-16 13:54:21 +08002105GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2106{
jchen10fd7c3b52017-03-21 15:36:03 +08002107 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002108 return QueryProgramResourceIndex(programObject, programInterface, name);
2109}
2110
jchen10fd7c3b52017-03-21 15:36:03 +08002111void Context::getProgramResourceName(GLuint program,
2112 GLenum programInterface,
2113 GLuint index,
2114 GLsizei bufSize,
2115 GLsizei *length,
2116 GLchar *name)
2117{
2118 const auto *programObject = getProgram(program);
2119 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2120}
2121
jchen10191381f2017-04-11 13:59:04 +08002122GLint Context::getProgramResourceLocation(GLuint program,
2123 GLenum programInterface,
2124 const GLchar *name)
2125{
2126 const auto *programObject = getProgram(program);
2127 return QueryProgramResourceLocation(programObject, programInterface, name);
2128}
2129
jchen10880683b2017-04-12 16:21:55 +08002130void Context::getProgramResourceiv(GLuint program,
2131 GLenum programInterface,
2132 GLuint index,
2133 GLsizei propCount,
2134 const GLenum *props,
2135 GLsizei bufSize,
2136 GLsizei *length,
2137 GLint *params)
2138{
2139 const auto *programObject = getProgram(program);
2140 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2141 length, params);
2142}
2143
jchen10d9cd7b72017-08-30 15:04:25 +08002144void Context::getProgramInterfaceiv(GLuint program,
2145 GLenum programInterface,
2146 GLenum pname,
2147 GLint *params)
2148{
2149 const auto *programObject = getProgram(program);
2150 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2151}
2152
Jamie Madill71c88b32017-09-14 22:20:29 -04002153void Context::handleError(const Error &error)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002154{
Geoff Langda5777c2014-07-11 09:52:58 -04002155 if (error.isError())
2156 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002157 GLenum code = error.getCode();
2158 mErrors.insert(code);
2159 if (code == GL_OUT_OF_MEMORY && getWorkarounds().loseContextOnOutOfMemory)
2160 {
2161 markContextLost();
2162 }
Geoff Lang70d0f492015-12-10 17:45:46 -05002163
2164 if (!error.getMessage().empty())
2165 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002166 auto *debug = &mGLState.getDebug();
2167 debug->insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, error.getID(),
2168 GL_DEBUG_SEVERITY_HIGH, error.getMessage());
Geoff Lang70d0f492015-12-10 17:45:46 -05002169 }
Geoff Langda5777c2014-07-11 09:52:58 -04002170 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002171}
2172
2173// Get one of the recorded errors and clear its flag, if any.
2174// [OpenGL ES 2.0.24] section 2.5 page 13.
2175GLenum Context::getError()
2176{
Geoff Langda5777c2014-07-11 09:52:58 -04002177 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002178 {
Geoff Langda5777c2014-07-11 09:52:58 -04002179 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002180 }
Geoff Langda5777c2014-07-11 09:52:58 -04002181 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002182 {
Geoff Langda5777c2014-07-11 09:52:58 -04002183 GLenum error = *mErrors.begin();
2184 mErrors.erase(mErrors.begin());
2185 return error;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002186 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002187}
2188
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002189// NOTE: this function should not assume that this context is current!
2190void Context::markContextLost()
2191{
2192 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002193 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002194 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002195 mContextLostForced = true;
2196 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002197 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002198}
2199
2200bool Context::isContextLost()
2201{
2202 return mContextLost;
2203}
2204
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002205GLenum Context::getResetStatus()
2206{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002207 // Even if the application doesn't want to know about resets, we want to know
2208 // as it will allow us to skip all the calls.
2209 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002210 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002211 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002212 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002213 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002214 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002215
2216 // EXT_robustness, section 2.6: If the reset notification behavior is
2217 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2218 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2219 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002220 }
2221
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002222 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2223 // status should be returned at least once, and GL_NO_ERROR should be returned
2224 // once the device has finished resetting.
2225 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002226 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002227 ASSERT(mResetStatus == GL_NO_ERROR);
2228 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002229
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002230 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002231 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002232 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002233 }
2234 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002235 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002236 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002237 // If markContextLost was used to mark the context lost then
2238 // assume that is not recoverable, and continue to report the
2239 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002240 mResetStatus = mImplementation->getResetStatus();
2241 }
Jamie Madill893ab082014-05-16 16:56:10 -04002242
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002243 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002244}
2245
2246bool Context::isResetNotificationEnabled()
2247{
2248 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2249}
2250
Corentin Walleze3b10e82015-05-20 11:06:25 -04002251const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002252{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002253 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002254}
2255
2256EGLenum Context::getClientType() const
2257{
2258 return mClientType;
2259}
2260
2261EGLenum Context::getRenderBuffer() const
2262{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002263 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2264 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002265 {
2266 return EGL_NONE;
2267 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002268
2269 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(GL_BACK);
2270 ASSERT(backAttachment != nullptr);
2271 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002272}
2273
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002274VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002275{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002276 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002277 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2278 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002279 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002280 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2281 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002282
Jamie Madill96a483b2017-06-27 16:49:21 -04002283 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002284 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002285
2286 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002287}
2288
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002289TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002290{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002291 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002292 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2293 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002294 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002295 transformFeedback =
2296 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002297 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002298 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002299 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002300
2301 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002302}
2303
2304bool Context::isVertexArrayGenerated(GLuint vertexArray)
2305{
Jamie Madill96a483b2017-06-27 16:49:21 -04002306 ASSERT(mVertexArrayMap.contains(0));
2307 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002308}
2309
2310bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2311{
Jamie Madill96a483b2017-06-27 16:49:21 -04002312 ASSERT(mTransformFeedbackMap.contains(0));
2313 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002314}
2315
Shannon Woods53a94a82014-06-24 15:20:36 -04002316void Context::detachTexture(GLuint texture)
2317{
2318 // Simple pass-through to State's detachTexture method, as textures do not require
2319 // allocation map management either here or in the resource manager at detach time.
2320 // Zero textures are held by the Context, and we don't attempt to request them from
2321 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002322 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002323}
2324
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002325void Context::detachBuffer(GLuint buffer)
2326{
Yuly Novikov5807a532015-12-03 13:01:22 -05002327 // Simple pass-through to State's detachBuffer method, since
2328 // only buffer attachments to container objects that are bound to the current context
2329 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002330
Yuly Novikov5807a532015-12-03 13:01:22 -05002331 // [OpenGL ES 3.2] section 5.1.2 page 45:
2332 // Attachments to unbound container objects, such as
2333 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2334 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002335 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002336}
2337
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002338void Context::detachFramebuffer(GLuint framebuffer)
2339{
Shannon Woods53a94a82014-06-24 15:20:36 -04002340 // Framebuffer detachment is handled by Context, because 0 is a valid
2341 // Framebuffer object, and a pointer to it must be passed from Context
2342 // to State at binding time.
2343
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002344 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002345 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2346 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2347 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002348
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002349 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002350 {
2351 bindReadFramebuffer(0);
2352 }
2353
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002354 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002355 {
2356 bindDrawFramebuffer(0);
2357 }
2358}
2359
2360void Context::detachRenderbuffer(GLuint renderbuffer)
2361{
Jamie Madilla02315b2017-02-23 14:14:47 -05002362 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002363}
2364
Jamie Madill57a89722013-07-02 11:57:03 -04002365void Context::detachVertexArray(GLuint vertexArray)
2366{
Jamie Madill77a72f62015-04-14 11:18:32 -04002367 // Vertex array detachment is handled by Context, because 0 is a valid
2368 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002369 // binding time.
2370
Jamie Madill57a89722013-07-02 11:57:03 -04002371 // [OpenGL ES 3.0.2] section 2.10 page 43:
2372 // If a vertex array object that is currently bound is deleted, the binding
2373 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002374 if (mGLState.removeVertexArrayBinding(vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002375 {
2376 bindVertexArray(0);
2377 }
2378}
2379
Geoff Langc8058452014-02-03 12:04:11 -05002380void Context::detachTransformFeedback(GLuint transformFeedback)
2381{
Corentin Walleza2257da2016-04-19 16:43:12 -04002382 // Transform feedback detachment is handled by Context, because 0 is a valid
2383 // transform feedback, and a pointer to it must be passed from Context to State at
2384 // binding time.
2385
2386 // The OpenGL specification doesn't mention what should happen when the currently bound
2387 // transform feedback object is deleted. Since it is a container object, we treat it like
2388 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002389 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002390 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002391 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002392 }
Geoff Langc8058452014-02-03 12:04:11 -05002393}
2394
Jamie Madilldc356042013-07-19 16:36:57 -04002395void Context::detachSampler(GLuint sampler)
2396{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002397 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002398}
2399
Yunchao Hea336b902017-08-02 16:05:21 +08002400void Context::detachProgramPipeline(GLuint pipeline)
2401{
2402 mGLState.detachProgramPipeline(this, pipeline);
2403}
2404
Jamie Madill3ef140a2017-08-26 23:11:21 -04002405void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002406{
Shaodde78e82017-05-22 14:13:27 +08002407 mGLState.setVertexAttribDivisor(this, index, divisor);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002408}
2409
Jamie Madille29d1672013-07-19 16:36:57 -04002410void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2411{
Geoff Langc1984ed2016-10-07 12:41:00 -04002412 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002413 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002414 SetSamplerParameteri(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002415 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002416}
Jamie Madille29d1672013-07-19 16:36:57 -04002417
Geoff Langc1984ed2016-10-07 12:41:00 -04002418void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2419{
2420 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002421 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002422 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002423 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002424}
2425
2426void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2427{
Geoff Langc1984ed2016-10-07 12:41:00 -04002428 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002429 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002430 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002431 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002432}
2433
Geoff Langc1984ed2016-10-07 12:41:00 -04002434void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002435{
Geoff Langc1984ed2016-10-07 12:41:00 -04002436 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002437 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002438 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002439 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002440}
2441
Geoff Langc1984ed2016-10-07 12:41:00 -04002442void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002443{
Geoff Langc1984ed2016-10-07 12:41:00 -04002444 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002445 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002446 QuerySamplerParameteriv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002447 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002448}
Jamie Madill9675b802013-07-19 16:36:59 -04002449
Geoff Langc1984ed2016-10-07 12:41:00 -04002450void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2451{
2452 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002453 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002454 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002455 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002456}
2457
Olli Etuahof0fee072016-03-30 15:11:58 +03002458void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2459{
2460 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002461 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002462}
2463
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002464void Context::initRendererString()
2465{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002466 std::ostringstream rendererString;
2467 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002468 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002469 rendererString << ")";
2470
Geoff Langcec35902014-04-16 10:52:36 -04002471 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002472}
2473
Geoff Langc339c4e2016-11-29 10:37:36 -05002474void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002475{
Geoff Langc339c4e2016-11-29 10:37:36 -05002476 const Version &clientVersion = getClientVersion();
2477
2478 std::ostringstream versionString;
2479 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2480 << ANGLE_VERSION_STRING << ")";
2481 mVersionString = MakeStaticString(versionString.str());
2482
2483 std::ostringstream shadingLanguageVersionString;
2484 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2485 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2486 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2487 << ")";
2488 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002489}
2490
Geoff Langcec35902014-04-16 10:52:36 -04002491void Context::initExtensionStrings()
2492{
Geoff Langc339c4e2016-11-29 10:37:36 -05002493 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2494 std::ostringstream combinedStringStream;
2495 std::copy(strings.begin(), strings.end(),
2496 std::ostream_iterator<const char *>(combinedStringStream, " "));
2497 return MakeStaticString(combinedStringStream.str());
2498 };
2499
2500 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002501 for (const auto &extensionString : mExtensions.getStrings())
2502 {
2503 mExtensionStrings.push_back(MakeStaticString(extensionString));
2504 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002505 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002506
Bryan Bernhart58806562017-01-05 13:09:31 -08002507 const gl::Extensions &nativeExtensions = mImplementation->getNativeExtensions();
2508
Geoff Langc339c4e2016-11-29 10:37:36 -05002509 mRequestableExtensionStrings.clear();
2510 for (const auto &extensionInfo : GetExtensionInfoMap())
2511 {
2512 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08002513 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
2514 nativeExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002515 {
2516 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
2517 }
2518 }
2519 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002520}
2521
Geoff Langc339c4e2016-11-29 10:37:36 -05002522const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04002523{
Geoff Langc339c4e2016-11-29 10:37:36 -05002524 switch (name)
2525 {
2526 case GL_VENDOR:
2527 return reinterpret_cast<const GLubyte *>("Google Inc.");
2528
2529 case GL_RENDERER:
2530 return reinterpret_cast<const GLubyte *>(mRendererString);
2531
2532 case GL_VERSION:
2533 return reinterpret_cast<const GLubyte *>(mVersionString);
2534
2535 case GL_SHADING_LANGUAGE_VERSION:
2536 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
2537
2538 case GL_EXTENSIONS:
2539 return reinterpret_cast<const GLubyte *>(mExtensionString);
2540
2541 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2542 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
2543
2544 default:
2545 UNREACHABLE();
2546 return nullptr;
2547 }
Geoff Langcec35902014-04-16 10:52:36 -04002548}
2549
Geoff Langc339c4e2016-11-29 10:37:36 -05002550const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04002551{
Geoff Langc339c4e2016-11-29 10:37:36 -05002552 switch (name)
2553 {
2554 case GL_EXTENSIONS:
2555 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
2556
2557 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2558 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
2559
2560 default:
2561 UNREACHABLE();
2562 return nullptr;
2563 }
Geoff Langcec35902014-04-16 10:52:36 -04002564}
2565
2566size_t Context::getExtensionStringCount() const
2567{
2568 return mExtensionStrings.size();
2569}
2570
Geoff Lang111a99e2017-10-17 10:58:41 -04002571bool Context::isExtensionRequestable(const char *name)
2572{
2573 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2574 auto extension = extensionInfos.find(name);
2575
2576 const Extensions &nativeExtensions = mImplementation->getNativeExtensions();
2577 return extension != extensionInfos.end() && extension->second.Requestable &&
2578 nativeExtensions.*(extension->second.ExtensionsMember);
2579}
2580
Geoff Langc339c4e2016-11-29 10:37:36 -05002581void Context::requestExtension(const char *name)
2582{
2583 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2584 ASSERT(extensionInfos.find(name) != extensionInfos.end());
2585 const auto &extension = extensionInfos.at(name);
2586 ASSERT(extension.Requestable);
Geoff Lang111a99e2017-10-17 10:58:41 -04002587 ASSERT(mImplementation->getNativeExtensions().*(extension.ExtensionsMember));
Geoff Langc339c4e2016-11-29 10:37:36 -05002588
2589 if (mExtensions.*(extension.ExtensionsMember))
2590 {
2591 // Extension already enabled
2592 return;
2593 }
2594
2595 mExtensions.*(extension.ExtensionsMember) = true;
2596 updateCaps();
2597 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08002598
Jamie Madill2f348d22017-06-05 10:50:59 -04002599 // Release the shader compiler so it will be re-created with the requested extensions enabled.
2600 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04002601
Jamie Madill81c2e252017-09-09 23:32:46 -04002602 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
2603 // sampleable.
2604 mState.mTextures->signalAllTexturesDirty();
Geoff Lang9aded172017-04-05 11:07:56 -04002605 for (auto &zeroTexture : mZeroTextures)
2606 {
Jamie Madill05b35b22017-10-03 09:01:44 -04002607 zeroTexture.second->signalDirty(InitState::Initialized);
Geoff Lang9aded172017-04-05 11:07:56 -04002608 }
2609
2610 mState.mFramebuffers->invalidateFramebufferComplenessCache();
Geoff Langc339c4e2016-11-29 10:37:36 -05002611}
2612
2613size_t Context::getRequestableExtensionStringCount() const
2614{
2615 return mRequestableExtensionStrings.size();
2616}
2617
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002618void Context::beginTransformFeedback(GLenum primitiveMode)
2619{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002620 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002621 ASSERT(transformFeedback != nullptr);
2622 ASSERT(!transformFeedback->isPaused());
2623
Jamie Madill6c1f6712017-02-14 19:08:04 -05002624 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002625}
2626
2627bool Context::hasActiveTransformFeedback(GLuint program) const
2628{
2629 for (auto pair : mTransformFeedbackMap)
2630 {
2631 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
2632 {
2633 return true;
2634 }
2635 }
2636 return false;
2637}
2638
Geoff Langb433e872017-10-05 14:01:47 -04002639void Context::initCaps(const egl::DisplayExtensions &displayExtensions, bool robustResourceInit)
Geoff Lang493daf52014-07-03 13:38:44 -04002640{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002641 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04002642
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002643 mExtensions = mImplementation->getNativeExtensions();
Geoff Lang493daf52014-07-03 13:38:44 -04002644
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002645 mLimitations = mImplementation->getNativeLimitations();
Austin Kinross02df7962015-07-01 10:03:42 -07002646
Geoff Langeb66a6e2016-10-31 13:06:12 -04002647 if (getClientVersion() < Version(3, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002648 {
2649 // Disable ES3+ extensions
Jamie Madill231c7f52017-04-26 13:45:37 -04002650 mExtensions.colorBufferFloat = false;
Geoff Langb66a9092016-05-16 15:59:14 -04002651 mExtensions.eglImageExternalEssl3 = false;
Vincent Lang25ab4512016-05-13 18:13:59 +02002652 mExtensions.textureNorm16 = false;
Martin Radev137032d2017-07-13 10:11:12 +03002653 mExtensions.multiview = false;
2654 mExtensions.maxViews = 1u;
Geoff Lang493daf52014-07-03 13:38:44 -04002655 }
2656
Geoff Langeb66a6e2016-10-31 13:06:12 -04002657 if (getClientVersion() > Version(2, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002658 {
2659 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
Jamie Madill231c7f52017-04-26 13:45:37 -04002660 // mExtensions.sRGB = false;
Geoff Lang493daf52014-07-03 13:38:44 -04002661 }
2662
Jamie Madill00ed7a12016-05-19 13:13:38 -04002663 // Some extensions are always available because they are implemented in the GL layer.
Jamie Madill231c7f52017-04-26 13:45:37 -04002664 mExtensions.bindUniformLocation = true;
2665 mExtensions.vertexArrayObject = true;
Geoff Langf41a7152016-09-19 15:11:17 -04002666 mExtensions.bindGeneratesResource = true;
Geoff Langfeb8c682017-02-13 16:07:35 -05002667 mExtensions.clientArrays = true;
Geoff Langc339c4e2016-11-29 10:37:36 -05002668 mExtensions.requestExtension = true;
Jamie Madill00ed7a12016-05-19 13:13:38 -04002669
2670 // Enable the no error extension if the context was created with the flag.
2671 mExtensions.noError = mSkipValidation;
2672
Corentin Wallezccab69d2017-01-27 16:57:15 -05002673 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Corentin Wallezc295e512017-01-27 17:47:50 -05002674 mExtensions.surfacelessContext = displayExtensions.surfacelessContext;
Corentin Wallezccab69d2017-01-27 16:57:15 -05002675
Geoff Lang70d0f492015-12-10 17:45:46 -05002676 // Explicitly enable GL_KHR_debug
2677 mExtensions.debug = true;
2678 mExtensions.maxDebugMessageLength = 1024;
2679 mExtensions.maxDebugLoggedMessages = 1024;
2680 mExtensions.maxDebugGroupStackDepth = 1024;
2681 mExtensions.maxLabelLength = 1024;
2682
Geoff Langff5b2d52016-09-07 11:32:23 -04002683 // Explicitly enable GL_ANGLE_robust_client_memory
2684 mExtensions.robustClientMemory = true;
2685
Jamie Madille08a1d32017-03-07 17:24:06 -05002686 // Determine robust resource init availability from EGL.
Geoff Langb433e872017-10-05 14:01:47 -04002687 mExtensions.robustResourceInitialization = robustResourceInit;
Jamie Madille08a1d32017-03-07 17:24:06 -05002688
Jiajia Qin8a7b3a02017-08-25 16:05:48 +08002689 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
2690 // supports it.
2691 mExtensions.robustBufferAccessBehavior =
2692 mRobustAccess && mExtensions.robustBufferAccessBehavior;
2693
Jamie Madillc43be722017-07-13 16:22:14 -04002694 // Enable the cache control query unconditionally.
2695 mExtensions.programCacheControl = true;
2696
Geoff Lang301d1612014-07-09 10:34:37 -04002697 // Apply implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04002698 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002699
Jamie Madill0f80ed82017-09-19 00:24:56 -04002700 if (getClientVersion() < ES_3_1)
2701 {
2702 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
2703 }
2704 else
2705 {
2706 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
2707 }
Geoff Lang301d1612014-07-09 10:34:37 -04002708
Jamie Madill0f80ed82017-09-19 00:24:56 -04002709 LimitCap(&mCaps.maxVertexUniformBlocks, IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
2710 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
2711 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
2712
2713 // Limit textures as well, so we can use fast bitsets with texture bindings.
2714 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
2715 LimitCap(&mCaps.maxVertexTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
2716 LimitCap(&mCaps.maxTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04002717
Jiawei Shaodb342272017-09-27 10:21:45 +08002718 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
2719
Geoff Langc287ea62016-09-16 14:46:51 -04002720 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002721 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04002722 for (const auto &extensionInfo : GetExtensionInfoMap())
2723 {
2724 // If this context is for WebGL, disable all enableable extensions
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002725 if (mWebGLContext && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04002726 {
2727 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
2728 }
2729 }
2730
2731 // Generate texture caps
2732 updateCaps();
2733}
2734
2735void Context::updateCaps()
2736{
Geoff Lang900013c2014-07-07 11:32:19 -04002737 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002738 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04002739
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002740 for (auto capsIt : mImplementation->getNativeTextureCaps())
Geoff Lang493daf52014-07-03 13:38:44 -04002741 {
Geoff Langca271392017-04-05 12:30:00 -04002742 GLenum sizedInternalFormat = capsIt.first;
Jamie Madill231c7f52017-04-26 13:45:37 -04002743 TextureCaps formatCaps = capsIt.second;
Geoff Lang493daf52014-07-03 13:38:44 -04002744
Geoff Langca271392017-04-05 12:30:00 -04002745 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04002746
Geoff Lang0d8b7242015-09-09 14:56:53 -04002747 // Update the format caps based on the client version and extensions.
2748 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
2749 // ES3.
2750 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002751 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002752 formatCaps.renderable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002753 formatCaps.renderable && formatInfo.renderSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002754 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002755 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04002756
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002757 // OpenGL ES does not support multisampling with non-rendererable formats
2758 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Olli Etuaho50c562d2017-06-06 14:43:30 +03002759 if (!formatCaps.renderable ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002760 (getClientVersion() < ES_3_1 &&
2761 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04002762 {
Geoff Langd87878e2014-09-19 15:42:59 -04002763 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04002764 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03002765 else
2766 {
2767 // We may have limited the max samples for some required renderbuffer formats due to
2768 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
2769 GLuint formatMaxSamples = formatCaps.getMaxSamples();
2770
2771 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
2772 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
2773 // exception of signed and unsigned integer formats."
2774 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
2775 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
2776 {
2777 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
2778 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
2779 }
2780
2781 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
2782 if (getClientVersion() >= ES_3_1)
2783 {
2784 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
2785 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
2786 // the exception that the signed and unsigned integer formats are required only to
2787 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
2788 // multisamples, which must be at least one."
2789 if (formatInfo.componentType == GL_INT ||
2790 formatInfo.componentType == GL_UNSIGNED_INT)
2791 {
2792 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
2793 }
2794
2795 // GLES 3.1 section 19.3.1.
2796 if (formatCaps.texturable)
2797 {
2798 if (formatInfo.depthBits > 0)
2799 {
2800 mCaps.maxDepthTextureSamples =
2801 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
2802 }
2803 else if (formatInfo.redBits > 0)
2804 {
2805 mCaps.maxColorTextureSamples =
2806 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
2807 }
2808 }
2809 }
2810 }
Geoff Langd87878e2014-09-19 15:42:59 -04002811
2812 if (formatCaps.texturable && formatInfo.compressed)
2813 {
Geoff Langca271392017-04-05 12:30:00 -04002814 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04002815 }
2816
Geoff Langca271392017-04-05 12:30:00 -04002817 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04002818 }
Jamie Madill32447362017-06-28 14:53:52 -04002819
2820 // If program binary is disabled, blank out the memory cache pointer.
2821 if (!mImplementation->getNativeExtensions().getProgramBinary)
2822 {
2823 mMemoryProgramCache = nullptr;
2824 }
Geoff Lang493daf52014-07-03 13:38:44 -04002825}
2826
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002827void Context::initWorkarounds()
2828{
Jamie Madill761b02c2017-06-23 16:27:06 -04002829 // Apply back-end workarounds.
2830 mImplementation->applyNativeWorkarounds(&mWorkarounds);
2831
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002832 // Lose the context upon out of memory error if the application is
2833 // expecting to watch for those events.
2834 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2835}
2836
Jamie Madill05b35b22017-10-03 09:01:44 -04002837Error Context::prepareForDraw()
2838{
2839 syncRendererState();
2840 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
2841 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
2842 return NoError();
2843}
2844
Jamie Madill1b94d432015-08-07 13:23:23 -04002845void Context::syncRendererState()
2846{
Jamie Madill7d1f5c62017-09-02 15:32:15 -04002847 mGLState.syncDirtyObjects(this);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002848 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
Jamie Madillfe548342017-06-19 11:13:24 -04002849 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002850 mGLState.clearDirtyBits();
Jamie Madill1b94d432015-08-07 13:23:23 -04002851}
2852
Jamie Madillad9f24e2016-02-12 09:27:24 -05002853void Context::syncRendererState(const State::DirtyBits &bitMask,
2854 const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04002855{
Jamie Madill7d1f5c62017-09-02 15:32:15 -04002856 mGLState.syncDirtyObjects(this, objectMask);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002857 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madillfe548342017-06-19 11:13:24 -04002858 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002859 mGLState.clearDirtyBits(dirtyBits);
Jamie Madill1b94d432015-08-07 13:23:23 -04002860}
Jamie Madillc29968b2016-01-20 11:17:23 -05002861
2862void Context::blitFramebuffer(GLint srcX0,
2863 GLint srcY0,
2864 GLint srcX1,
2865 GLint srcY1,
2866 GLint dstX0,
2867 GLint dstY0,
2868 GLint dstX1,
2869 GLint dstY1,
2870 GLbitfield mask,
2871 GLenum filter)
2872{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002873 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002874 ASSERT(drawFramebuffer);
2875
2876 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
2877 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
2878
Jamie Madillad9f24e2016-02-12 09:27:24 -05002879 syncStateForBlit();
Jamie Madillc29968b2016-01-20 11:17:23 -05002880
Jamie Madillc564c072017-06-01 12:45:42 -04002881 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002882}
Jamie Madillc29968b2016-01-20 11:17:23 -05002883
2884void Context::clear(GLbitfield mask)
2885{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002886 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002887 handleError(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05002888}
2889
2890void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
2891{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002892 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002893 handleError(mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002894}
2895
2896void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
2897{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002898 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002899 handleError(mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002900}
2901
2902void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
2903{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002904 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002905 handleError(mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002906}
2907
2908void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
2909{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002910 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002911 ASSERT(framebufferObject);
2912
2913 // If a buffer is not present, the clear has no effect
2914 if (framebufferObject->getDepthbuffer() == nullptr &&
2915 framebufferObject->getStencilbuffer() == nullptr)
2916 {
2917 return;
2918 }
2919
Jamie Madillad9f24e2016-02-12 09:27:24 -05002920 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002921 handleError(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05002922}
2923
2924void Context::readPixels(GLint x,
2925 GLint y,
2926 GLsizei width,
2927 GLsizei height,
2928 GLenum format,
2929 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002930 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05002931{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04002932 if (width == 0 || height == 0)
2933 {
2934 return;
2935 }
2936
Jamie Madillad9f24e2016-02-12 09:27:24 -05002937 syncStateForReadPixels();
Jamie Madillc29968b2016-01-20 11:17:23 -05002938
Jamie Madillb6664922017-07-25 12:55:04 -04002939 Framebuffer *readFBO = mGLState.getReadFramebuffer();
2940 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05002941
2942 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04002943 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05002944}
2945
2946void Context::copyTexImage2D(GLenum target,
2947 GLint level,
2948 GLenum internalformat,
2949 GLint x,
2950 GLint y,
2951 GLsizei width,
2952 GLsizei height,
2953 GLint border)
2954{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002955 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002956 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002957
Jamie Madillc29968b2016-01-20 11:17:23 -05002958 Rectangle sourceArea(x, y, width, height);
2959
Jamie Madill05b35b22017-10-03 09:01:44 -04002960 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002961 Texture *texture =
2962 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05002963 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05002964}
2965
2966void Context::copyTexSubImage2D(GLenum target,
2967 GLint level,
2968 GLint xoffset,
2969 GLint yoffset,
2970 GLint x,
2971 GLint y,
2972 GLsizei width,
2973 GLsizei height)
2974{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04002975 if (width == 0 || height == 0)
2976 {
2977 return;
2978 }
2979
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002980 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002981 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002982
Jamie Madillc29968b2016-01-20 11:17:23 -05002983 Offset destOffset(xoffset, yoffset, 0);
2984 Rectangle sourceArea(x, y, width, height);
2985
Jamie Madill05b35b22017-10-03 09:01:44 -04002986 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002987 Texture *texture =
2988 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05002989 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05002990}
2991
2992void Context::copyTexSubImage3D(GLenum target,
2993 GLint level,
2994 GLint xoffset,
2995 GLint yoffset,
2996 GLint zoffset,
2997 GLint x,
2998 GLint y,
2999 GLsizei width,
3000 GLsizei height)
3001{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003002 if (width == 0 || height == 0)
3003 {
3004 return;
3005 }
3006
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003007 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003008 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003009
Jamie Madillc29968b2016-01-20 11:17:23 -05003010 Offset destOffset(xoffset, yoffset, zoffset);
3011 Rectangle sourceArea(x, y, width, height);
3012
Jamie Madill05b35b22017-10-03 09:01:44 -04003013 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3014 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003015 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003016}
3017
3018void Context::framebufferTexture2D(GLenum target,
3019 GLenum attachment,
3020 GLenum textarget,
3021 GLuint texture,
3022 GLint level)
3023{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003024 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003025 ASSERT(framebuffer);
3026
3027 if (texture != 0)
3028 {
3029 Texture *textureObj = getTexture(texture);
3030
3031 ImageIndex index = ImageIndex::MakeInvalid();
3032
3033 if (textarget == GL_TEXTURE_2D)
3034 {
3035 index = ImageIndex::Make2D(level);
3036 }
Corentin Wallez13c0dd42017-07-04 18:27:01 -04003037 else if (textarget == GL_TEXTURE_RECTANGLE_ANGLE)
3038 {
3039 index = ImageIndex::MakeRectangle(level);
3040 }
JiangYizhoubddc46b2016-12-09 09:50:51 +08003041 else if (textarget == GL_TEXTURE_2D_MULTISAMPLE)
3042 {
3043 ASSERT(level == 0);
3044 index = ImageIndex::Make2DMultisample();
3045 }
Jamie Madillc29968b2016-01-20 11:17:23 -05003046 else
3047 {
3048 ASSERT(IsCubeMapTextureTarget(textarget));
3049 index = ImageIndex::MakeCube(textarget, level);
3050 }
3051
Jamie Madilla02315b2017-02-23 14:14:47 -05003052 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003053 }
3054 else
3055 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003056 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003057 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003058
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003059 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003060}
3061
3062void Context::framebufferRenderbuffer(GLenum target,
3063 GLenum attachment,
3064 GLenum renderbuffertarget,
3065 GLuint renderbuffer)
3066{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003067 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003068 ASSERT(framebuffer);
3069
3070 if (renderbuffer != 0)
3071 {
3072 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003073
3074 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex::MakeInvalid(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003075 renderbufferObject);
3076 }
3077 else
3078 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003079 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003080 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003081
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003082 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003083}
3084
3085void Context::framebufferTextureLayer(GLenum target,
3086 GLenum attachment,
3087 GLuint texture,
3088 GLint level,
3089 GLint layer)
3090{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003091 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003092 ASSERT(framebuffer);
3093
3094 if (texture != 0)
3095 {
3096 Texture *textureObject = getTexture(texture);
3097
3098 ImageIndex index = ImageIndex::MakeInvalid();
3099
3100 if (textureObject->getTarget() == GL_TEXTURE_3D)
3101 {
3102 index = ImageIndex::Make3D(level, layer);
3103 }
3104 else
3105 {
3106 ASSERT(textureObject->getTarget() == GL_TEXTURE_2D_ARRAY);
3107 index = ImageIndex::Make2DArray(level, layer);
3108 }
3109
Jamie Madilla02315b2017-02-23 14:14:47 -05003110 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003111 }
3112 else
3113 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003114 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003115 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003116
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003117 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003118}
3119
Martin Radev137032d2017-07-13 10:11:12 +03003120void Context::framebufferTextureMultiviewLayeredANGLE(GLenum target,
3121 GLenum attachment,
3122 GLuint texture,
3123 GLint level,
3124 GLint baseViewIndex,
3125 GLsizei numViews)
3126{
Martin Radev82ef7742017-08-08 17:44:58 +03003127 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3128 ASSERT(framebuffer);
3129
3130 if (texture != 0)
3131 {
3132 Texture *textureObj = getTexture(texture);
3133
Martin Radev18b75ba2017-08-15 15:50:40 +03003134 ImageIndex index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
Martin Radev82ef7742017-08-08 17:44:58 +03003135 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3136 numViews, baseViewIndex);
3137 }
3138 else
3139 {
3140 framebuffer->resetAttachment(this, attachment);
3141 }
3142
3143 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003144}
3145
3146void Context::framebufferTextureMultiviewSideBySideANGLE(GLenum target,
3147 GLenum attachment,
3148 GLuint texture,
3149 GLint level,
3150 GLsizei numViews,
3151 const GLint *viewportOffsets)
3152{
Martin Radev5dae57b2017-07-14 16:15:55 +03003153 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3154 ASSERT(framebuffer);
3155
3156 if (texture != 0)
3157 {
3158 Texture *textureObj = getTexture(texture);
3159
3160 ImageIndex index = ImageIndex::Make2D(level);
3161 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3162 textureObj, numViews, viewportOffsets);
3163 }
3164 else
3165 {
3166 framebuffer->resetAttachment(this, attachment);
3167 }
3168
3169 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003170}
3171
Jamie Madillc29968b2016-01-20 11:17:23 -05003172void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3173{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003174 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003175 ASSERT(framebuffer);
3176 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003177 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003178}
3179
3180void Context::readBuffer(GLenum mode)
3181{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003182 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003183 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003184 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003185}
3186
3187void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3188{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003189 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003190 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003191
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003192 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003193 ASSERT(framebuffer);
3194
3195 // The specification isn't clear what should be done when the framebuffer isn't complete.
3196 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003197 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003198}
3199
3200void Context::invalidateFramebuffer(GLenum target,
3201 GLsizei numAttachments,
3202 const GLenum *attachments)
3203{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003204 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003205 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003206
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003207 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003208 ASSERT(framebuffer);
3209
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003210 if (framebuffer->checkStatus(this) != GL_FRAMEBUFFER_COMPLETE)
Jamie Madillc29968b2016-01-20 11:17:23 -05003211 {
Jamie Madill437fa652016-05-03 15:13:24 -04003212 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003213 }
Jamie Madill437fa652016-05-03 15:13:24 -04003214
Jamie Madill4928b7c2017-06-20 12:57:39 -04003215 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003216}
3217
3218void Context::invalidateSubFramebuffer(GLenum target,
3219 GLsizei numAttachments,
3220 const GLenum *attachments,
3221 GLint x,
3222 GLint y,
3223 GLsizei width,
3224 GLsizei height)
3225{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003226 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003227 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003228
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003229 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003230 ASSERT(framebuffer);
3231
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003232 if (framebuffer->checkStatus(this) != GL_FRAMEBUFFER_COMPLETE)
Jamie Madillc29968b2016-01-20 11:17:23 -05003233 {
Jamie Madill437fa652016-05-03 15:13:24 -04003234 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003235 }
Jamie Madill437fa652016-05-03 15:13:24 -04003236
3237 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003238 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003239}
3240
Jamie Madill73a84962016-02-12 09:27:23 -05003241void Context::texImage2D(GLenum target,
3242 GLint level,
3243 GLint internalformat,
3244 GLsizei width,
3245 GLsizei height,
3246 GLint border,
3247 GLenum format,
3248 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003249 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003250{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003251 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003252
3253 Extents size(width, height, 1);
3254 Texture *texture =
3255 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003256 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3257 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003258}
3259
3260void Context::texImage3D(GLenum target,
3261 GLint level,
3262 GLint internalformat,
3263 GLsizei width,
3264 GLsizei height,
3265 GLsizei depth,
3266 GLint border,
3267 GLenum format,
3268 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003269 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003270{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003271 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003272
3273 Extents size(width, height, depth);
3274 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003275 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3276 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003277}
3278
3279void Context::texSubImage2D(GLenum target,
3280 GLint level,
3281 GLint xoffset,
3282 GLint yoffset,
3283 GLsizei width,
3284 GLsizei height,
3285 GLenum format,
3286 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003287 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003288{
3289 // Zero sized uploads are valid but no-ops
3290 if (width == 0 || height == 0)
3291 {
3292 return;
3293 }
3294
Jamie Madillad9f24e2016-02-12 09:27:24 -05003295 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003296
3297 Box area(xoffset, yoffset, 0, width, height, 1);
3298 Texture *texture =
3299 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003300 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3301 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003302}
3303
3304void Context::texSubImage3D(GLenum target,
3305 GLint level,
3306 GLint xoffset,
3307 GLint yoffset,
3308 GLint zoffset,
3309 GLsizei width,
3310 GLsizei height,
3311 GLsizei depth,
3312 GLenum format,
3313 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003314 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003315{
3316 // Zero sized uploads are valid but no-ops
3317 if (width == 0 || height == 0 || depth == 0)
3318 {
3319 return;
3320 }
3321
Jamie Madillad9f24e2016-02-12 09:27:24 -05003322 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003323
3324 Box area(xoffset, yoffset, zoffset, width, height, depth);
3325 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003326 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3327 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003328}
3329
3330void Context::compressedTexImage2D(GLenum target,
3331 GLint level,
3332 GLenum internalformat,
3333 GLsizei width,
3334 GLsizei height,
3335 GLint border,
3336 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003337 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003338{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003339 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003340
3341 Extents size(width, height, 1);
3342 Texture *texture =
3343 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003344 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003345 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003346 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003347}
3348
3349void Context::compressedTexImage3D(GLenum target,
3350 GLint level,
3351 GLenum internalformat,
3352 GLsizei width,
3353 GLsizei height,
3354 GLsizei depth,
3355 GLint border,
3356 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003357 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003358{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003359 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003360
3361 Extents size(width, height, depth);
3362 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003363 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003364 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003365 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003366}
3367
3368void Context::compressedTexSubImage2D(GLenum target,
3369 GLint level,
3370 GLint xoffset,
3371 GLint yoffset,
3372 GLsizei width,
3373 GLsizei height,
3374 GLenum format,
3375 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003376 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003377{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003378 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003379
3380 Box area(xoffset, yoffset, 0, width, height, 1);
3381 Texture *texture =
3382 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003383 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003384 format, imageSize,
3385 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003386}
3387
3388void Context::compressedTexSubImage3D(GLenum target,
3389 GLint level,
3390 GLint xoffset,
3391 GLint yoffset,
3392 GLint zoffset,
3393 GLsizei width,
3394 GLsizei height,
3395 GLsizei depth,
3396 GLenum format,
3397 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003398 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003399{
3400 // Zero sized uploads are valid but no-ops
3401 if (width == 0 || height == 0)
3402 {
3403 return;
3404 }
3405
Jamie Madillad9f24e2016-02-12 09:27:24 -05003406 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003407
3408 Box area(xoffset, yoffset, zoffset, width, height, depth);
3409 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003410 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003411 format, imageSize,
3412 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003413}
3414
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003415void Context::generateMipmap(GLenum target)
3416{
3417 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003418 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003419}
3420
Geoff Lang97073d12016-04-20 10:42:34 -07003421void Context::copyTextureCHROMIUM(GLuint sourceId,
Geoff Langfc72a072017-03-24 14:52:39 -04003422 GLint sourceLevel,
3423 GLenum destTarget,
Geoff Lang97073d12016-04-20 10:42:34 -07003424 GLuint destId,
Geoff Langfc72a072017-03-24 14:52:39 -04003425 GLint destLevel,
Geoff Lang97073d12016-04-20 10:42:34 -07003426 GLint internalFormat,
3427 GLenum destType,
3428 GLboolean unpackFlipY,
3429 GLboolean unpackPremultiplyAlpha,
3430 GLboolean unpackUnmultiplyAlpha)
3431{
3432 syncStateForTexImage();
3433
3434 gl::Texture *sourceTexture = getTexture(sourceId);
3435 gl::Texture *destTexture = getTexture(destId);
Geoff Langfc72a072017-03-24 14:52:39 -04003436 handleError(destTexture->copyTexture(
3437 this, destTarget, destLevel, internalFormat, destType, sourceLevel, unpackFlipY == GL_TRUE,
3438 unpackPremultiplyAlpha == GL_TRUE, unpackUnmultiplyAlpha == GL_TRUE, sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003439}
3440
3441void Context::copySubTextureCHROMIUM(GLuint sourceId,
Geoff Langfc72a072017-03-24 14:52:39 -04003442 GLint sourceLevel,
3443 GLenum destTarget,
Geoff Lang97073d12016-04-20 10:42:34 -07003444 GLuint destId,
Geoff Langfc72a072017-03-24 14:52:39 -04003445 GLint destLevel,
Geoff Lang97073d12016-04-20 10:42:34 -07003446 GLint xoffset,
3447 GLint yoffset,
3448 GLint x,
3449 GLint y,
3450 GLsizei width,
3451 GLsizei height,
3452 GLboolean unpackFlipY,
3453 GLboolean unpackPremultiplyAlpha,
3454 GLboolean unpackUnmultiplyAlpha)
3455{
3456 // Zero sized copies are valid but no-ops
3457 if (width == 0 || height == 0)
3458 {
3459 return;
3460 }
3461
3462 syncStateForTexImage();
3463
3464 gl::Texture *sourceTexture = getTexture(sourceId);
3465 gl::Texture *destTexture = getTexture(destId);
3466 Offset offset(xoffset, yoffset, 0);
3467 Rectangle area(x, y, width, height);
Geoff Langfc72a072017-03-24 14:52:39 -04003468 handleError(destTexture->copySubTexture(
3469 this, destTarget, destLevel, offset, sourceLevel, area, unpackFlipY == GL_TRUE,
3470 unpackPremultiplyAlpha == GL_TRUE, unpackUnmultiplyAlpha == GL_TRUE, sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003471}
3472
Geoff Lang47110bf2016-04-20 11:13:22 -07003473void Context::compressedCopyTextureCHROMIUM(GLuint sourceId, GLuint destId)
3474{
3475 syncStateForTexImage();
3476
3477 gl::Texture *sourceTexture = getTexture(sourceId);
3478 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05003479 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07003480}
3481
Geoff Lang496c02d2016-10-20 11:38:11 -07003482void Context::getBufferPointerv(GLenum target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03003483{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003484 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003485 ASSERT(buffer);
3486
Geoff Lang496c02d2016-10-20 11:38:11 -07003487 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03003488}
3489
Jamie Madill876429b2017-04-20 15:46:24 -04003490void *Context::mapBuffer(GLenum target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003491{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003492 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003493 ASSERT(buffer);
3494
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003495 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003496 if (error.isError())
3497 {
Jamie Madill437fa652016-05-03 15:13:24 -04003498 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003499 return nullptr;
3500 }
3501
3502 return buffer->getMapPointer();
3503}
3504
3505GLboolean Context::unmapBuffer(GLenum target)
3506{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003507 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003508 ASSERT(buffer);
3509
3510 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003511 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03003512 if (error.isError())
3513 {
Jamie Madill437fa652016-05-03 15:13:24 -04003514 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003515 return GL_FALSE;
3516 }
3517
3518 return result;
3519}
3520
Jamie Madill876429b2017-04-20 15:46:24 -04003521void *Context::mapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003522{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003523 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003524 ASSERT(buffer);
3525
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003526 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003527 if (error.isError())
3528 {
Jamie Madill437fa652016-05-03 15:13:24 -04003529 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003530 return nullptr;
3531 }
3532
3533 return buffer->getMapPointer();
3534}
3535
3536void Context::flushMappedBufferRange(GLenum /*target*/, GLintptr /*offset*/, GLsizeiptr /*length*/)
3537{
3538 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
3539}
3540
Jamie Madillad9f24e2016-02-12 09:27:24 -05003541void Context::syncStateForReadPixels()
3542{
3543 syncRendererState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
3544}
3545
3546void Context::syncStateForTexImage()
3547{
3548 syncRendererState(mTexImageDirtyBits, mTexImageDirtyObjects);
3549}
3550
3551void Context::syncStateForClear()
3552{
3553 syncRendererState(mClearDirtyBits, mClearDirtyObjects);
3554}
3555
3556void Context::syncStateForBlit()
3557{
3558 syncRendererState(mBlitDirtyBits, mBlitDirtyObjects);
3559}
3560
Jamie Madillc20ab272016-06-09 07:20:46 -07003561void Context::activeTexture(GLenum texture)
3562{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003563 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003564}
3565
Jamie Madill876429b2017-04-20 15:46:24 -04003566void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003567{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003568 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07003569}
3570
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003571void Context::blendEquation(GLenum mode)
3572{
3573 mGLState.setBlendEquation(mode, mode);
3574}
3575
Jamie Madillc20ab272016-06-09 07:20:46 -07003576void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
3577{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003578 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003579}
3580
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003581void Context::blendFunc(GLenum sfactor, GLenum dfactor)
3582{
3583 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
3584}
3585
Jamie Madillc20ab272016-06-09 07:20:46 -07003586void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
3587{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003588 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003589}
3590
Jamie Madill876429b2017-04-20 15:46:24 -04003591void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003592{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003593 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003594}
3595
Jamie Madill876429b2017-04-20 15:46:24 -04003596void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07003597{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003598 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07003599}
3600
3601void Context::clearStencil(GLint s)
3602{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003603 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07003604}
3605
3606void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
3607{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003608 mGLState.setColorMask(red == GL_TRUE, green == GL_TRUE, blue == GL_TRUE, alpha == GL_TRUE);
Jamie Madillc20ab272016-06-09 07:20:46 -07003609}
3610
Corentin Wallez2e568cf2017-09-18 17:05:22 -04003611void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07003612{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003613 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003614}
3615
3616void Context::depthFunc(GLenum func)
3617{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003618 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07003619}
3620
3621void Context::depthMask(GLboolean flag)
3622{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003623 mGLState.setDepthMask(flag != GL_FALSE);
Jamie Madillc20ab272016-06-09 07:20:46 -07003624}
3625
Jamie Madill876429b2017-04-20 15:46:24 -04003626void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07003627{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003628 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07003629}
3630
3631void Context::disable(GLenum cap)
3632{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003633 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003634}
3635
3636void Context::disableVertexAttribArray(GLuint index)
3637{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003638 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003639}
3640
3641void Context::enable(GLenum cap)
3642{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003643 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003644}
3645
3646void Context::enableVertexAttribArray(GLuint index)
3647{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003648 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003649}
3650
3651void Context::frontFace(GLenum mode)
3652{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003653 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003654}
3655
3656void Context::hint(GLenum target, GLenum mode)
3657{
3658 switch (target)
3659 {
3660 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003661 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003662 break;
3663
3664 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003665 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003666 break;
3667
3668 default:
3669 UNREACHABLE();
3670 return;
3671 }
3672}
3673
3674void Context::lineWidth(GLfloat width)
3675{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003676 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07003677}
3678
3679void Context::pixelStorei(GLenum pname, GLint param)
3680{
3681 switch (pname)
3682 {
3683 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003684 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003685 break;
3686
3687 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003688 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003689 break;
3690
3691 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003692 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003693 break;
3694
3695 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003696 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003697 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003698 break;
3699
3700 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03003701 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003702 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003703 break;
3704
3705 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03003706 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003707 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003708 break;
3709
3710 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003711 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003712 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003713 break;
3714
3715 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003716 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003717 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003718 break;
3719
3720 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003721 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003722 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003723 break;
3724
3725 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003726 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003727 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003728 break;
3729
3730 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003731 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003732 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003733 break;
3734
3735 default:
3736 UNREACHABLE();
3737 return;
3738 }
3739}
3740
3741void Context::polygonOffset(GLfloat factor, GLfloat units)
3742{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003743 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07003744}
3745
Jamie Madill876429b2017-04-20 15:46:24 -04003746void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07003747{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003748 mGLState.setSampleCoverageParams(clamp01(value), invert == GL_TRUE);
Jamie Madillc20ab272016-06-09 07:20:46 -07003749}
3750
Jiawei Shaodb342272017-09-27 10:21:45 +08003751void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
3752{
3753 mGLState.setSampleMaskParams(maskNumber, mask);
3754}
3755
Jamie Madillc20ab272016-06-09 07:20:46 -07003756void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
3757{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003758 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07003759}
3760
3761void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
3762{
3763 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3764 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003765 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003766 }
3767
3768 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3769 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003770 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003771 }
3772}
3773
3774void Context::stencilMaskSeparate(GLenum face, GLuint mask)
3775{
3776 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3777 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003778 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003779 }
3780
3781 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3782 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003783 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003784 }
3785}
3786
3787void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
3788{
3789 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3790 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003791 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003792 }
3793
3794 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3795 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003796 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003797 }
3798}
3799
3800void Context::vertexAttrib1f(GLuint index, GLfloat x)
3801{
3802 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003803 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003804}
3805
3806void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
3807{
3808 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003809 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003810}
3811
3812void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
3813{
3814 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003815 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003816}
3817
3818void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
3819{
3820 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003821 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003822}
3823
3824void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
3825{
3826 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003827 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003828}
3829
3830void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
3831{
3832 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003833 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003834}
3835
3836void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
3837{
3838 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003839 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003840}
3841
3842void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
3843{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003844 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07003845}
3846
3847void Context::vertexAttribPointer(GLuint index,
3848 GLint size,
3849 GLenum type,
3850 GLboolean normalized,
3851 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04003852 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07003853{
Shaodde78e82017-05-22 14:13:27 +08003854 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(GL_ARRAY_BUFFER), size,
3855 type, normalized == GL_TRUE, false, stride, ptr);
Jamie Madillc20ab272016-06-09 07:20:46 -07003856}
3857
Shao80957d92017-02-20 21:25:59 +08003858void Context::vertexAttribFormat(GLuint attribIndex,
3859 GLint size,
3860 GLenum type,
3861 GLboolean normalized,
3862 GLuint relativeOffset)
3863{
3864 mGLState.setVertexAttribFormat(attribIndex, size, type, normalized == GL_TRUE, false,
3865 relativeOffset);
3866}
3867
3868void Context::vertexAttribIFormat(GLuint attribIndex,
3869 GLint size,
3870 GLenum type,
3871 GLuint relativeOffset)
3872{
3873 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
3874}
3875
3876void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
3877{
Shaodde78e82017-05-22 14:13:27 +08003878 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Shao80957d92017-02-20 21:25:59 +08003879}
3880
3881void Context::setVertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
3882{
3883 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
3884}
3885
Jamie Madillc20ab272016-06-09 07:20:46 -07003886void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
3887{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003888 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07003889}
3890
3891void Context::vertexAttribIPointer(GLuint index,
3892 GLint size,
3893 GLenum type,
3894 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04003895 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07003896{
Shaodde78e82017-05-22 14:13:27 +08003897 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(GL_ARRAY_BUFFER), size,
3898 type, false, true, stride, pointer);
Jamie Madillc20ab272016-06-09 07:20:46 -07003899}
3900
3901void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
3902{
3903 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003904 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003905}
3906
3907void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
3908{
3909 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003910 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003911}
3912
3913void Context::vertexAttribI4iv(GLuint index, const GLint *v)
3914{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003915 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07003916}
3917
3918void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
3919{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003920 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07003921}
3922
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003923void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
3924{
3925 const VertexAttribCurrentValueData &currentValues =
3926 getGLState().getVertexAttribCurrentValue(index);
3927 const VertexArray *vao = getGLState().getVertexArray();
3928 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3929 currentValues, pname, params);
3930}
3931
3932void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
3933{
3934 const VertexAttribCurrentValueData &currentValues =
3935 getGLState().getVertexAttribCurrentValue(index);
3936 const VertexArray *vao = getGLState().getVertexArray();
3937 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3938 currentValues, pname, params);
3939}
3940
3941void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
3942{
3943 const VertexAttribCurrentValueData &currentValues =
3944 getGLState().getVertexAttribCurrentValue(index);
3945 const VertexArray *vao = getGLState().getVertexArray();
3946 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3947 currentValues, pname, params);
3948}
3949
3950void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
3951{
3952 const VertexAttribCurrentValueData &currentValues =
3953 getGLState().getVertexAttribCurrentValue(index);
3954 const VertexArray *vao = getGLState().getVertexArray();
3955 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3956 currentValues, pname, params);
3957}
3958
Jamie Madill876429b2017-04-20 15:46:24 -04003959void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003960{
3961 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
3962 QueryVertexAttribPointerv(attrib, pname, pointer);
3963}
3964
Jamie Madillc20ab272016-06-09 07:20:46 -07003965void Context::debugMessageControl(GLenum source,
3966 GLenum type,
3967 GLenum severity,
3968 GLsizei count,
3969 const GLuint *ids,
3970 GLboolean enabled)
3971{
3972 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003973 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
3974 (enabled != GL_FALSE));
Jamie Madillc20ab272016-06-09 07:20:46 -07003975}
3976
3977void Context::debugMessageInsert(GLenum source,
3978 GLenum type,
3979 GLuint id,
3980 GLenum severity,
3981 GLsizei length,
3982 const GLchar *buf)
3983{
3984 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003985 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07003986}
3987
3988void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
3989{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003990 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07003991}
3992
3993GLuint Context::getDebugMessageLog(GLuint count,
3994 GLsizei bufSize,
3995 GLenum *sources,
3996 GLenum *types,
3997 GLuint *ids,
3998 GLenum *severities,
3999 GLsizei *lengths,
4000 GLchar *messageLog)
4001{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004002 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4003 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004004}
4005
4006void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4007{
4008 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004009 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004010}
4011
4012void Context::popDebugGroup()
4013{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004014 mGLState.getDebug().popGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004015}
4016
Corentin Wallez2e568cf2017-09-18 17:05:22 -04004017void Context::bufferData(GLenum target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004018{
4019 Buffer *buffer = mGLState.getTargetBuffer(target);
4020 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004021 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004022}
4023
Jamie Madill876429b2017-04-20 15:46:24 -04004024void Context::bufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004025{
4026 if (data == nullptr)
4027 {
4028 return;
4029 }
4030
4031 Buffer *buffer = mGLState.getTargetBuffer(target);
4032 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004033 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004034}
4035
Jamie Madillef300b12016-10-07 15:12:09 -04004036void Context::attachShader(GLuint program, GLuint shader)
4037{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004038 auto programObject = mState.mShaderPrograms->getProgram(program);
4039 auto shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004040 ASSERT(programObject && shaderObject);
4041 programObject->attachShader(shaderObject);
4042}
4043
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004044const Workarounds &Context::getWorkarounds() const
4045{
4046 return mWorkarounds;
4047}
4048
Jamie Madillb0817d12016-11-01 15:48:31 -04004049void Context::copyBufferSubData(GLenum readTarget,
4050 GLenum writeTarget,
4051 GLintptr readOffset,
4052 GLintptr writeOffset,
4053 GLsizeiptr size)
4054{
4055 // if size is zero, the copy is a successful no-op
4056 if (size == 0)
4057 {
4058 return;
4059 }
4060
4061 // TODO(jmadill): cache these.
4062 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4063 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4064
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004065 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004066}
4067
Jamie Madill01a80ee2016-11-07 12:06:18 -05004068void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4069{
4070 Program *programObject = getProgram(program);
4071 // TODO(jmadill): Re-use this from the validation if possible.
4072 ASSERT(programObject);
4073 programObject->bindAttributeLocation(index, name);
4074}
4075
4076void Context::bindBuffer(GLenum target, GLuint buffer)
4077{
4078 switch (target)
4079 {
4080 case GL_ARRAY_BUFFER:
4081 bindArrayBuffer(buffer);
4082 break;
4083 case GL_ELEMENT_ARRAY_BUFFER:
4084 bindElementArrayBuffer(buffer);
4085 break;
4086 case GL_COPY_READ_BUFFER:
4087 bindCopyReadBuffer(buffer);
4088 break;
4089 case GL_COPY_WRITE_BUFFER:
4090 bindCopyWriteBuffer(buffer);
4091 break;
4092 case GL_PIXEL_PACK_BUFFER:
4093 bindPixelPackBuffer(buffer);
4094 break;
4095 case GL_PIXEL_UNPACK_BUFFER:
4096 bindPixelUnpackBuffer(buffer);
4097 break;
4098 case GL_UNIFORM_BUFFER:
4099 bindGenericUniformBuffer(buffer);
4100 break;
4101 case GL_TRANSFORM_FEEDBACK_BUFFER:
4102 bindGenericTransformFeedbackBuffer(buffer);
4103 break;
Geoff Lang3b573612016-10-31 14:08:10 -04004104 case GL_ATOMIC_COUNTER_BUFFER:
Jiajia Qin6eafb042016-12-27 17:04:07 +08004105 bindGenericAtomicCounterBuffer(buffer);
Geoff Lang3b573612016-10-31 14:08:10 -04004106 break;
4107 case GL_SHADER_STORAGE_BUFFER:
Jiajia Qinf546e7d2017-03-27 14:12:59 +08004108 bindGenericShaderStorageBuffer(buffer);
Geoff Lang3b573612016-10-31 14:08:10 -04004109 break;
4110 case GL_DRAW_INDIRECT_BUFFER:
Jiajia Qin9d7d0b12016-11-29 16:30:31 +08004111 bindDrawIndirectBuffer(buffer);
Geoff Lang3b573612016-10-31 14:08:10 -04004112 break;
4113 case GL_DISPATCH_INDIRECT_BUFFER:
Geoff Lang9f090372016-12-02 10:20:43 -05004114 if (buffer != 0)
4115 {
4116 // Binding buffers to this binding point is not implemented yet.
4117 UNIMPLEMENTED();
4118 }
Geoff Lang3b573612016-10-31 14:08:10 -04004119 break;
Jamie Madill01a80ee2016-11-07 12:06:18 -05004120
4121 default:
4122 UNREACHABLE();
4123 break;
4124 }
4125}
4126
Jiajia Qin6eafb042016-12-27 17:04:07 +08004127void Context::bindBufferBase(GLenum target, GLuint index, GLuint buffer)
4128{
4129 bindBufferRange(target, index, buffer, 0, 0);
4130}
4131
4132void Context::bindBufferRange(GLenum target,
4133 GLuint index,
4134 GLuint buffer,
4135 GLintptr offset,
4136 GLsizeiptr size)
4137{
4138 switch (target)
4139 {
4140 case GL_TRANSFORM_FEEDBACK_BUFFER:
4141 bindIndexedTransformFeedbackBuffer(buffer, index, offset, size);
4142 bindGenericTransformFeedbackBuffer(buffer);
4143 break;
4144 case GL_UNIFORM_BUFFER:
4145 bindIndexedUniformBuffer(buffer, index, offset, size);
4146 bindGenericUniformBuffer(buffer);
4147 break;
4148 case GL_ATOMIC_COUNTER_BUFFER:
4149 bindIndexedAtomicCounterBuffer(buffer, index, offset, size);
4150 bindGenericAtomicCounterBuffer(buffer);
4151 break;
4152 case GL_SHADER_STORAGE_BUFFER:
Jiajia Qinf546e7d2017-03-27 14:12:59 +08004153 bindIndexedShaderStorageBuffer(buffer, index, offset, size);
4154 bindGenericShaderStorageBuffer(buffer);
Jiajia Qin6eafb042016-12-27 17:04:07 +08004155 break;
4156 default:
4157 UNREACHABLE();
4158 break;
4159 }
4160}
4161
Jamie Madill01a80ee2016-11-07 12:06:18 -05004162void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
4163{
4164 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4165 {
4166 bindReadFramebuffer(framebuffer);
4167 }
4168
4169 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4170 {
4171 bindDrawFramebuffer(framebuffer);
4172 }
4173}
4174
4175void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4176{
4177 ASSERT(target == GL_RENDERBUFFER);
4178 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004179 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04004180 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004181}
4182
JiangYizhoubddc46b2016-12-09 09:50:51 +08004183void Context::texStorage2DMultisample(GLenum target,
4184 GLsizei samples,
4185 GLenum internalformat,
4186 GLsizei width,
4187 GLsizei height,
4188 GLboolean fixedsamplelocations)
4189{
4190 Extents size(width, height, 1);
4191 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05004192 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
JiangYizhoubddc46b2016-12-09 09:50:51 +08004193 fixedsamplelocations));
4194}
4195
4196void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4197{
JiangYizhou5b03f472017-01-09 10:22:53 +08004198 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
4199 // the sample position should be queried by DRAW_FRAMEBUFFER.
4200 mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER);
4201 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08004202
4203 switch (pname)
4204 {
4205 case GL_SAMPLE_POSITION:
4206 handleError(framebuffer->getSamplePosition(index, val));
4207 break;
4208 default:
4209 UNREACHABLE();
4210 }
4211}
4212
Jamie Madille8fb6402017-02-14 17:56:40 -05004213void Context::renderbufferStorage(GLenum target,
4214 GLenum internalformat,
4215 GLsizei width,
4216 GLsizei height)
4217{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004218 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4219 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
4220
Jamie Madille8fb6402017-02-14 17:56:40 -05004221 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04004222 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004223}
4224
4225void Context::renderbufferStorageMultisample(GLenum target,
4226 GLsizei samples,
4227 GLenum internalformat,
4228 GLsizei width,
4229 GLsizei height)
4230{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004231 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4232 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05004233
4234 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004235 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04004236 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004237}
4238
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004239void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
4240{
Jamie Madill70b5bb02017-08-28 13:32:37 -04004241 const Sync *syncObject = getSync(sync);
Geoff Lang82483b92017-04-11 15:33:00 -04004242 handleError(QuerySynciv(syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004243}
4244
JiangYizhoue18e6392017-02-20 10:32:23 +08004245void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
4246{
4247 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4248 QueryFramebufferParameteriv(framebuffer, pname, params);
4249}
4250
4251void Context::setFramebufferParameteri(GLenum target, GLenum pname, GLint param)
4252{
4253 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4254 SetFramebufferParameteri(framebuffer, pname, param);
4255}
4256
Jamie Madillb3f26b92017-07-19 15:07:41 -04004257Error Context::getScratchBuffer(size_t requstedSizeBytes,
4258 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05004259{
Jamie Madillb3f26b92017-07-19 15:07:41 -04004260 if (!mScratchBuffer.get(requstedSizeBytes, scratchBufferOut))
4261 {
4262 return OutOfMemory() << "Failed to allocate internal buffer.";
4263 }
4264 return NoError();
4265}
4266
4267Error Context::getZeroFilledBuffer(size_t requstedSizeBytes,
4268 angle::MemoryBuffer **zeroBufferOut) const
4269{
4270 if (!mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0))
Jamie Madille14951e2017-03-09 18:55:16 -05004271 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004272 return OutOfMemory() << "Failed to allocate internal buffer.";
Jamie Madille14951e2017-03-09 18:55:16 -05004273 }
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004274 return NoError();
Jamie Madille14951e2017-03-09 18:55:16 -05004275}
4276
Xinghua Cao2b396592017-03-29 15:36:04 +08004277void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
4278{
4279 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
4280 {
4281 return;
4282 }
4283
Jamie Madill05b35b22017-10-03 09:01:44 -04004284 // TODO(jmadill): Dirty bits for compute.
4285 ANGLE_CONTEXT_TRY(mGLState.clearUnclearedActiveTextures(this));
4286
Jamie Madill71c88b32017-09-14 22:20:29 -04004287 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08004288}
4289
JiangYizhou165361c2017-06-07 14:56:57 +08004290void Context::texStorage2D(GLenum target,
4291 GLsizei levels,
4292 GLenum internalFormat,
4293 GLsizei width,
4294 GLsizei height)
4295{
4296 Extents size(width, height, 1);
4297 Texture *texture = getTargetTexture(target);
4298 handleError(texture->setStorage(this, target, levels, internalFormat, size));
4299}
4300
4301void Context::texStorage3D(GLenum target,
4302 GLsizei levels,
4303 GLenum internalFormat,
4304 GLsizei width,
4305 GLsizei height,
4306 GLsizei depth)
4307{
4308 Extents size(width, height, depth);
4309 Texture *texture = getTargetTexture(target);
4310 handleError(texture->setStorage(this, target, levels, internalFormat, size));
4311}
4312
Jamie Madillc1d770e2017-04-13 17:31:24 -04004313GLenum Context::checkFramebufferStatus(GLenum target)
4314{
4315 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4316 ASSERT(framebuffer);
4317
4318 return framebuffer->checkStatus(this);
4319}
4320
4321void Context::compileShader(GLuint shader)
4322{
4323 Shader *shaderObject = GetValidShader(this, shader);
4324 if (!shaderObject)
4325 {
4326 return;
4327 }
4328 shaderObject->compile(this);
4329}
4330
4331void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
4332{
4333 for (int i = 0; i < n; i++)
4334 {
4335 deleteBuffer(buffers[i]);
4336 }
4337}
4338
4339void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
4340{
4341 for (int i = 0; i < n; i++)
4342 {
4343 if (framebuffers[i] != 0)
4344 {
4345 deleteFramebuffer(framebuffers[i]);
4346 }
4347 }
4348}
4349
4350void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
4351{
4352 for (int i = 0; i < n; i++)
4353 {
4354 deleteRenderbuffer(renderbuffers[i]);
4355 }
4356}
4357
4358void Context::deleteTextures(GLsizei n, const GLuint *textures)
4359{
4360 for (int i = 0; i < n; i++)
4361 {
4362 if (textures[i] != 0)
4363 {
4364 deleteTexture(textures[i]);
4365 }
4366 }
4367}
4368
4369void Context::detachShader(GLuint program, GLuint shader)
4370{
4371 Program *programObject = getProgram(program);
4372 ASSERT(programObject);
4373
4374 Shader *shaderObject = getShader(shader);
4375 ASSERT(shaderObject);
4376
4377 programObject->detachShader(this, shaderObject);
4378}
4379
4380void Context::genBuffers(GLsizei n, GLuint *buffers)
4381{
4382 for (int i = 0; i < n; i++)
4383 {
4384 buffers[i] = createBuffer();
4385 }
4386}
4387
4388void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
4389{
4390 for (int i = 0; i < n; i++)
4391 {
4392 framebuffers[i] = createFramebuffer();
4393 }
4394}
4395
4396void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
4397{
4398 for (int i = 0; i < n; i++)
4399 {
4400 renderbuffers[i] = createRenderbuffer();
4401 }
4402}
4403
4404void Context::genTextures(GLsizei n, GLuint *textures)
4405{
4406 for (int i = 0; i < n; i++)
4407 {
4408 textures[i] = createTexture();
4409 }
4410}
4411
4412void Context::getActiveAttrib(GLuint program,
4413 GLuint index,
4414 GLsizei bufsize,
4415 GLsizei *length,
4416 GLint *size,
4417 GLenum *type,
4418 GLchar *name)
4419{
4420 Program *programObject = getProgram(program);
4421 ASSERT(programObject);
4422 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
4423}
4424
4425void Context::getActiveUniform(GLuint program,
4426 GLuint index,
4427 GLsizei bufsize,
4428 GLsizei *length,
4429 GLint *size,
4430 GLenum *type,
4431 GLchar *name)
4432{
4433 Program *programObject = getProgram(program);
4434 ASSERT(programObject);
4435 programObject->getActiveUniform(index, bufsize, length, size, type, name);
4436}
4437
4438void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
4439{
4440 Program *programObject = getProgram(program);
4441 ASSERT(programObject);
4442 programObject->getAttachedShaders(maxcount, count, shaders);
4443}
4444
4445GLint Context::getAttribLocation(GLuint program, const GLchar *name)
4446{
4447 Program *programObject = getProgram(program);
4448 ASSERT(programObject);
4449 return programObject->getAttributeLocation(name);
4450}
4451
4452void Context::getBooleanv(GLenum pname, GLboolean *params)
4453{
4454 GLenum nativeType;
4455 unsigned int numParams = 0;
4456 getQueryParameterInfo(pname, &nativeType, &numParams);
4457
4458 if (nativeType == GL_BOOL)
4459 {
4460 getBooleanvImpl(pname, params);
4461 }
4462 else
4463 {
4464 CastStateValues(this, nativeType, pname, numParams, params);
4465 }
4466}
4467
4468void Context::getFloatv(GLenum pname, GLfloat *params)
4469{
4470 GLenum nativeType;
4471 unsigned int numParams = 0;
4472 getQueryParameterInfo(pname, &nativeType, &numParams);
4473
4474 if (nativeType == GL_FLOAT)
4475 {
4476 getFloatvImpl(pname, params);
4477 }
4478 else
4479 {
4480 CastStateValues(this, nativeType, pname, numParams, params);
4481 }
4482}
4483
4484void Context::getIntegerv(GLenum pname, GLint *params)
4485{
4486 GLenum nativeType;
4487 unsigned int numParams = 0;
4488 getQueryParameterInfo(pname, &nativeType, &numParams);
4489
4490 if (nativeType == GL_INT)
4491 {
4492 getIntegervImpl(pname, params);
4493 }
4494 else
4495 {
4496 CastStateValues(this, nativeType, pname, numParams, params);
4497 }
4498}
4499
4500void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
4501{
4502 Program *programObject = getProgram(program);
4503 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04004504 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004505}
4506
Jamie Madillbe849e42017-05-02 15:49:00 -04004507void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04004508{
4509 Program *programObject = getProgram(program);
4510 ASSERT(programObject);
4511 programObject->getInfoLog(bufsize, length, infolog);
4512}
4513
4514void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
4515{
4516 Shader *shaderObject = getShader(shader);
4517 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004518 QueryShaderiv(this, shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004519}
4520
4521void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
4522{
4523 Shader *shaderObject = getShader(shader);
4524 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004525 shaderObject->getInfoLog(this, bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004526}
4527
4528void Context::getShaderPrecisionFormat(GLenum shadertype,
4529 GLenum precisiontype,
4530 GLint *range,
4531 GLint *precision)
4532{
4533 // TODO(jmadill): Compute shaders.
4534
4535 switch (shadertype)
4536 {
4537 case GL_VERTEX_SHADER:
4538 switch (precisiontype)
4539 {
4540 case GL_LOW_FLOAT:
4541 mCaps.vertexLowpFloat.get(range, precision);
4542 break;
4543 case GL_MEDIUM_FLOAT:
4544 mCaps.vertexMediumpFloat.get(range, precision);
4545 break;
4546 case GL_HIGH_FLOAT:
4547 mCaps.vertexHighpFloat.get(range, precision);
4548 break;
4549
4550 case GL_LOW_INT:
4551 mCaps.vertexLowpInt.get(range, precision);
4552 break;
4553 case GL_MEDIUM_INT:
4554 mCaps.vertexMediumpInt.get(range, precision);
4555 break;
4556 case GL_HIGH_INT:
4557 mCaps.vertexHighpInt.get(range, precision);
4558 break;
4559
4560 default:
4561 UNREACHABLE();
4562 return;
4563 }
4564 break;
4565
4566 case GL_FRAGMENT_SHADER:
4567 switch (precisiontype)
4568 {
4569 case GL_LOW_FLOAT:
4570 mCaps.fragmentLowpFloat.get(range, precision);
4571 break;
4572 case GL_MEDIUM_FLOAT:
4573 mCaps.fragmentMediumpFloat.get(range, precision);
4574 break;
4575 case GL_HIGH_FLOAT:
4576 mCaps.fragmentHighpFloat.get(range, precision);
4577 break;
4578
4579 case GL_LOW_INT:
4580 mCaps.fragmentLowpInt.get(range, precision);
4581 break;
4582 case GL_MEDIUM_INT:
4583 mCaps.fragmentMediumpInt.get(range, precision);
4584 break;
4585 case GL_HIGH_INT:
4586 mCaps.fragmentHighpInt.get(range, precision);
4587 break;
4588
4589 default:
4590 UNREACHABLE();
4591 return;
4592 }
4593 break;
4594
4595 default:
4596 UNREACHABLE();
4597 return;
4598 }
4599}
4600
4601void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
4602{
4603 Shader *shaderObject = getShader(shader);
4604 ASSERT(shaderObject);
4605 shaderObject->getSource(bufsize, length, source);
4606}
4607
4608void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
4609{
4610 Program *programObject = getProgram(program);
4611 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04004612 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004613}
4614
4615void Context::getUniformiv(GLuint program, GLint location, GLint *params)
4616{
4617 Program *programObject = getProgram(program);
4618 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04004619 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004620}
4621
4622GLint Context::getUniformLocation(GLuint program, const GLchar *name)
4623{
4624 Program *programObject = getProgram(program);
4625 ASSERT(programObject);
4626 return programObject->getUniformLocation(name);
4627}
4628
4629GLboolean Context::isBuffer(GLuint buffer)
4630{
4631 if (buffer == 0)
4632 {
4633 return GL_FALSE;
4634 }
4635
4636 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
4637}
4638
4639GLboolean Context::isEnabled(GLenum cap)
4640{
4641 return mGLState.getEnableFeature(cap);
4642}
4643
4644GLboolean Context::isFramebuffer(GLuint framebuffer)
4645{
4646 if (framebuffer == 0)
4647 {
4648 return GL_FALSE;
4649 }
4650
4651 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
4652}
4653
4654GLboolean Context::isProgram(GLuint program)
4655{
4656 if (program == 0)
4657 {
4658 return GL_FALSE;
4659 }
4660
4661 return (getProgram(program) ? GL_TRUE : GL_FALSE);
4662}
4663
4664GLboolean Context::isRenderbuffer(GLuint renderbuffer)
4665{
4666 if (renderbuffer == 0)
4667 {
4668 return GL_FALSE;
4669 }
4670
4671 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
4672}
4673
4674GLboolean Context::isShader(GLuint shader)
4675{
4676 if (shader == 0)
4677 {
4678 return GL_FALSE;
4679 }
4680
4681 return (getShader(shader) ? GL_TRUE : GL_FALSE);
4682}
4683
4684GLboolean Context::isTexture(GLuint texture)
4685{
4686 if (texture == 0)
4687 {
4688 return GL_FALSE;
4689 }
4690
4691 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
4692}
4693
4694void Context::linkProgram(GLuint program)
4695{
4696 Program *programObject = getProgram(program);
4697 ASSERT(programObject);
4698 handleError(programObject->link(this));
Martin Radev0abb7a22017-08-28 15:34:45 +03004699 mGLState.onProgramExecutableChange(programObject);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004700}
4701
4702void Context::releaseShaderCompiler()
4703{
Jamie Madill4928b7c2017-06-20 12:57:39 -04004704 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004705}
4706
4707void Context::shaderBinary(GLsizei n,
4708 const GLuint *shaders,
4709 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04004710 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04004711 GLsizei length)
4712{
4713 // No binary shader formats are supported.
4714 UNIMPLEMENTED();
4715}
4716
4717void Context::shaderSource(GLuint shader,
4718 GLsizei count,
4719 const GLchar *const *string,
4720 const GLint *length)
4721{
4722 Shader *shaderObject = getShader(shader);
4723 ASSERT(shaderObject);
4724 shaderObject->setSource(count, string, length);
4725}
4726
4727void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
4728{
4729 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
4730}
4731
4732void Context::stencilMask(GLuint mask)
4733{
4734 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
4735}
4736
4737void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
4738{
4739 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
4740}
4741
4742void Context::uniform1f(GLint location, GLfloat x)
4743{
4744 Program *program = mGLState.getProgram();
4745 program->setUniform1fv(location, 1, &x);
4746}
4747
4748void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
4749{
4750 Program *program = mGLState.getProgram();
4751 program->setUniform1fv(location, count, v);
4752}
4753
4754void Context::uniform1i(GLint location, GLint x)
4755{
4756 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04004757 if (program->setUniform1iv(location, 1, &x) == Program::SetUniformResult::SamplerChanged)
4758 {
4759 mGLState.setObjectDirty(GL_PROGRAM);
4760 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04004761}
4762
4763void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
4764{
4765 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04004766 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
4767 {
4768 mGLState.setObjectDirty(GL_PROGRAM);
4769 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04004770}
4771
4772void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
4773{
4774 GLfloat xy[2] = {x, y};
4775 Program *program = mGLState.getProgram();
4776 program->setUniform2fv(location, 1, xy);
4777}
4778
4779void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
4780{
4781 Program *program = mGLState.getProgram();
4782 program->setUniform2fv(location, count, v);
4783}
4784
4785void Context::uniform2i(GLint location, GLint x, GLint y)
4786{
4787 GLint xy[2] = {x, y};
4788 Program *program = mGLState.getProgram();
4789 program->setUniform2iv(location, 1, xy);
4790}
4791
4792void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
4793{
4794 Program *program = mGLState.getProgram();
4795 program->setUniform2iv(location, count, v);
4796}
4797
4798void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
4799{
4800 GLfloat xyz[3] = {x, y, z};
4801 Program *program = mGLState.getProgram();
4802 program->setUniform3fv(location, 1, xyz);
4803}
4804
4805void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
4806{
4807 Program *program = mGLState.getProgram();
4808 program->setUniform3fv(location, count, v);
4809}
4810
4811void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
4812{
4813 GLint xyz[3] = {x, y, z};
4814 Program *program = mGLState.getProgram();
4815 program->setUniform3iv(location, 1, xyz);
4816}
4817
4818void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
4819{
4820 Program *program = mGLState.getProgram();
4821 program->setUniform3iv(location, count, v);
4822}
4823
4824void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4825{
4826 GLfloat xyzw[4] = {x, y, z, w};
4827 Program *program = mGLState.getProgram();
4828 program->setUniform4fv(location, 1, xyzw);
4829}
4830
4831void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
4832{
4833 Program *program = mGLState.getProgram();
4834 program->setUniform4fv(location, count, v);
4835}
4836
4837void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
4838{
4839 GLint xyzw[4] = {x, y, z, w};
4840 Program *program = mGLState.getProgram();
4841 program->setUniform4iv(location, 1, xyzw);
4842}
4843
4844void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
4845{
4846 Program *program = mGLState.getProgram();
4847 program->setUniform4iv(location, count, v);
4848}
4849
4850void Context::uniformMatrix2fv(GLint location,
4851 GLsizei count,
4852 GLboolean transpose,
4853 const GLfloat *value)
4854{
4855 Program *program = mGLState.getProgram();
4856 program->setUniformMatrix2fv(location, count, transpose, value);
4857}
4858
4859void Context::uniformMatrix3fv(GLint location,
4860 GLsizei count,
4861 GLboolean transpose,
4862 const GLfloat *value)
4863{
4864 Program *program = mGLState.getProgram();
4865 program->setUniformMatrix3fv(location, count, transpose, value);
4866}
4867
4868void Context::uniformMatrix4fv(GLint location,
4869 GLsizei count,
4870 GLboolean transpose,
4871 const GLfloat *value)
4872{
4873 Program *program = mGLState.getProgram();
4874 program->setUniformMatrix4fv(location, count, transpose, value);
4875}
4876
4877void Context::validateProgram(GLuint program)
4878{
4879 Program *programObject = getProgram(program);
4880 ASSERT(programObject);
4881 programObject->validate(mCaps);
4882}
4883
Jamie Madilld04908b2017-06-09 14:15:35 -04004884void Context::getProgramBinary(GLuint program,
4885 GLsizei bufSize,
4886 GLsizei *length,
4887 GLenum *binaryFormat,
4888 void *binary)
4889{
4890 Program *programObject = getProgram(program);
4891 ASSERT(programObject != nullptr);
4892
4893 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
4894}
4895
4896void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
4897{
4898 Program *programObject = getProgram(program);
4899 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04004900
Jamie Madilld04908b2017-06-09 14:15:35 -04004901 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
4902}
4903
Jamie Madillff325f12017-08-26 15:06:05 -04004904void Context::uniform1ui(GLint location, GLuint v0)
4905{
4906 Program *program = mGLState.getProgram();
4907 program->setUniform1uiv(location, 1, &v0);
4908}
4909
4910void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
4911{
4912 Program *program = mGLState.getProgram();
4913 const GLuint xy[] = {v0, v1};
4914 program->setUniform2uiv(location, 1, xy);
4915}
4916
4917void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
4918{
4919 Program *program = mGLState.getProgram();
4920 const GLuint xyz[] = {v0, v1, v2};
4921 program->setUniform3uiv(location, 1, xyz);
4922}
4923
4924void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
4925{
4926 Program *program = mGLState.getProgram();
4927 const GLuint xyzw[] = {v0, v1, v2, v3};
4928 program->setUniform4uiv(location, 1, xyzw);
4929}
4930
4931void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
4932{
4933 Program *program = mGLState.getProgram();
4934 program->setUniform1uiv(location, count, value);
4935}
4936void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
4937{
4938 Program *program = mGLState.getProgram();
4939 program->setUniform2uiv(location, count, value);
4940}
4941
4942void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
4943{
4944 Program *program = mGLState.getProgram();
4945 program->setUniform3uiv(location, count, value);
4946}
4947
4948void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
4949{
4950 Program *program = mGLState.getProgram();
4951 program->setUniform4uiv(location, count, value);
4952}
4953
Jamie Madillf0e04492017-08-26 15:28:42 -04004954void Context::genQueries(GLsizei n, GLuint *ids)
4955{
4956 for (GLsizei i = 0; i < n; i++)
4957 {
4958 GLuint handle = mQueryHandleAllocator.allocate();
4959 mQueryMap.assign(handle, nullptr);
4960 ids[i] = handle;
4961 }
4962}
4963
4964void Context::deleteQueries(GLsizei n, const GLuint *ids)
4965{
4966 for (int i = 0; i < n; i++)
4967 {
4968 GLuint query = ids[i];
4969
4970 Query *queryObject = nullptr;
4971 if (mQueryMap.erase(query, &queryObject))
4972 {
4973 mQueryHandleAllocator.release(query);
4974 if (queryObject)
4975 {
4976 queryObject->release(this);
4977 }
4978 }
4979 }
4980}
4981
4982GLboolean Context::isQuery(GLuint id)
4983{
4984 return (getQuery(id, false, GL_NONE) != nullptr) ? GL_TRUE : GL_FALSE;
4985}
4986
Jamie Madillc8c95812017-08-26 18:40:09 -04004987void Context::uniformMatrix2x3fv(GLint location,
4988 GLsizei count,
4989 GLboolean transpose,
4990 const GLfloat *value)
4991{
4992 Program *program = mGLState.getProgram();
4993 program->setUniformMatrix2x3fv(location, count, transpose, value);
4994}
4995
4996void Context::uniformMatrix3x2fv(GLint location,
4997 GLsizei count,
4998 GLboolean transpose,
4999 const GLfloat *value)
5000{
5001 Program *program = mGLState.getProgram();
5002 program->setUniformMatrix3x2fv(location, count, transpose, value);
5003}
5004
5005void Context::uniformMatrix2x4fv(GLint location,
5006 GLsizei count,
5007 GLboolean transpose,
5008 const GLfloat *value)
5009{
5010 Program *program = mGLState.getProgram();
5011 program->setUniformMatrix2x4fv(location, count, transpose, value);
5012}
5013
5014void Context::uniformMatrix4x2fv(GLint location,
5015 GLsizei count,
5016 GLboolean transpose,
5017 const GLfloat *value)
5018{
5019 Program *program = mGLState.getProgram();
5020 program->setUniformMatrix4x2fv(location, count, transpose, value);
5021}
5022
5023void Context::uniformMatrix3x4fv(GLint location,
5024 GLsizei count,
5025 GLboolean transpose,
5026 const GLfloat *value)
5027{
5028 Program *program = mGLState.getProgram();
5029 program->setUniformMatrix3x4fv(location, count, transpose, value);
5030}
5031
5032void Context::uniformMatrix4x3fv(GLint location,
5033 GLsizei count,
5034 GLboolean transpose,
5035 const GLfloat *value)
5036{
5037 Program *program = mGLState.getProgram();
5038 program->setUniformMatrix4x3fv(location, count, transpose, value);
5039}
5040
Jamie Madilld7576732017-08-26 18:49:50 -04005041void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
5042{
5043 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5044 {
5045 GLuint vertexArray = arrays[arrayIndex];
5046
5047 if (arrays[arrayIndex] != 0)
5048 {
5049 VertexArray *vertexArrayObject = nullptr;
5050 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
5051 {
5052 if (vertexArrayObject != nullptr)
5053 {
5054 detachVertexArray(vertexArray);
5055 vertexArrayObject->onDestroy(this);
5056 }
5057
5058 mVertexArrayHandleAllocator.release(vertexArray);
5059 }
5060 }
5061 }
5062}
5063
5064void Context::genVertexArrays(GLsizei n, GLuint *arrays)
5065{
5066 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5067 {
5068 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
5069 mVertexArrayMap.assign(vertexArray, nullptr);
5070 arrays[arrayIndex] = vertexArray;
5071 }
5072}
5073
5074bool Context::isVertexArray(GLuint array)
5075{
5076 if (array == 0)
5077 {
5078 return GL_FALSE;
5079 }
5080
5081 VertexArray *vao = getVertexArray(array);
5082 return (vao != nullptr ? GL_TRUE : GL_FALSE);
5083}
5084
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04005085void Context::endTransformFeedback()
5086{
5087 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5088 transformFeedback->end(this);
5089}
5090
5091void Context::transformFeedbackVaryings(GLuint program,
5092 GLsizei count,
5093 const GLchar *const *varyings,
5094 GLenum bufferMode)
5095{
5096 Program *programObject = getProgram(program);
5097 ASSERT(programObject);
5098 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
5099}
5100
5101void Context::getTransformFeedbackVarying(GLuint program,
5102 GLuint index,
5103 GLsizei bufSize,
5104 GLsizei *length,
5105 GLsizei *size,
5106 GLenum *type,
5107 GLchar *name)
5108{
5109 Program *programObject = getProgram(program);
5110 ASSERT(programObject);
5111 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
5112}
5113
5114void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
5115{
5116 for (int i = 0; i < n; i++)
5117 {
5118 GLuint transformFeedback = ids[i];
5119 if (transformFeedback == 0)
5120 {
5121 continue;
5122 }
5123
5124 TransformFeedback *transformFeedbackObject = nullptr;
5125 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
5126 {
5127 if (transformFeedbackObject != nullptr)
5128 {
5129 detachTransformFeedback(transformFeedback);
5130 transformFeedbackObject->release(this);
5131 }
5132
5133 mTransformFeedbackHandleAllocator.release(transformFeedback);
5134 }
5135 }
5136}
5137
5138void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
5139{
5140 for (int i = 0; i < n; i++)
5141 {
5142 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
5143 mTransformFeedbackMap.assign(transformFeedback, nullptr);
5144 ids[i] = transformFeedback;
5145 }
5146}
5147
5148bool Context::isTransformFeedback(GLuint id)
5149{
5150 if (id == 0)
5151 {
5152 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
5153 // returns FALSE
5154 return GL_FALSE;
5155 }
5156
5157 const TransformFeedback *transformFeedback = getTransformFeedback(id);
5158 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
5159}
5160
5161void Context::pauseTransformFeedback()
5162{
5163 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5164 transformFeedback->pause();
5165}
5166
5167void Context::resumeTransformFeedback()
5168{
5169 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5170 transformFeedback->resume();
5171}
5172
Jamie Madill12e957f2017-08-26 21:42:26 -04005173void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
5174{
5175 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04005176 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04005177}
5178
5179GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
5180{
5181 const Program *programObject = getProgram(program);
5182 return programObject->getFragDataLocation(name);
5183}
5184
5185void Context::getUniformIndices(GLuint program,
5186 GLsizei uniformCount,
5187 const GLchar *const *uniformNames,
5188 GLuint *uniformIndices)
5189{
5190 const Program *programObject = getProgram(program);
5191 if (!programObject->isLinked())
5192 {
5193 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5194 {
5195 uniformIndices[uniformId] = GL_INVALID_INDEX;
5196 }
5197 }
5198 else
5199 {
5200 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5201 {
5202 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
5203 }
5204 }
5205}
5206
5207void Context::getActiveUniformsiv(GLuint program,
5208 GLsizei uniformCount,
5209 const GLuint *uniformIndices,
5210 GLenum pname,
5211 GLint *params)
5212{
5213 const Program *programObject = getProgram(program);
5214 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5215 {
5216 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08005217 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04005218 }
5219}
5220
5221GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
5222{
5223 const Program *programObject = getProgram(program);
5224 return programObject->getUniformBlockIndex(uniformBlockName);
5225}
5226
5227void Context::getActiveUniformBlockiv(GLuint program,
5228 GLuint uniformBlockIndex,
5229 GLenum pname,
5230 GLint *params)
5231{
5232 const Program *programObject = getProgram(program);
5233 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
5234}
5235
5236void Context::getActiveUniformBlockName(GLuint program,
5237 GLuint uniformBlockIndex,
5238 GLsizei bufSize,
5239 GLsizei *length,
5240 GLchar *uniformBlockName)
5241{
5242 const Program *programObject = getProgram(program);
5243 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
5244}
5245
5246void Context::uniformBlockBinding(GLuint program,
5247 GLuint uniformBlockIndex,
5248 GLuint uniformBlockBinding)
5249{
5250 Program *programObject = getProgram(program);
5251 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
5252}
5253
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005254GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
5255{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005256 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
5257 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005258
Jamie Madill70b5bb02017-08-28 13:32:37 -04005259 Sync *syncObject = getSync(syncHandle);
5260 Error error = syncObject->set(condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005261 if (error.isError())
5262 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04005263 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005264 handleError(error);
5265 return nullptr;
5266 }
5267
Jamie Madill70b5bb02017-08-28 13:32:37 -04005268 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005269}
5270
5271GLboolean Context::isSync(GLsync sync)
5272{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005273 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005274}
5275
5276GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
5277{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005278 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005279
5280 GLenum result = GL_WAIT_FAILED;
5281 handleError(syncObject->clientWait(flags, timeout, &result));
5282 return result;
5283}
5284
5285void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
5286{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005287 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005288 handleError(syncObject->serverWait(flags, timeout));
5289}
5290
5291void Context::getInteger64v(GLenum pname, GLint64 *params)
5292{
5293 GLenum nativeType = GL_NONE;
5294 unsigned int numParams = 0;
5295 getQueryParameterInfo(pname, &nativeType, &numParams);
5296
5297 if (nativeType == GL_INT_64_ANGLEX)
5298 {
5299 getInteger64vImpl(pname, params);
5300 }
5301 else
5302 {
5303 CastStateValues(this, nativeType, pname, numParams, params);
5304 }
5305}
5306
Jamie Madill3ef140a2017-08-26 23:11:21 -04005307void Context::getBufferParameteri64v(GLenum target, GLenum pname, GLint64 *params)
5308{
5309 Buffer *buffer = mGLState.getTargetBuffer(target);
5310 QueryBufferParameteri64v(buffer, pname, params);
5311}
5312
5313void Context::genSamplers(GLsizei count, GLuint *samplers)
5314{
5315 for (int i = 0; i < count; i++)
5316 {
5317 samplers[i] = mState.mSamplers->createSampler();
5318 }
5319}
5320
5321void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
5322{
5323 for (int i = 0; i < count; i++)
5324 {
5325 GLuint sampler = samplers[i];
5326
5327 if (mState.mSamplers->getSampler(sampler))
5328 {
5329 detachSampler(sampler);
5330 }
5331
5332 mState.mSamplers->deleteObject(this, sampler);
5333 }
5334}
5335
5336void Context::getInternalformativ(GLenum target,
5337 GLenum internalformat,
5338 GLenum pname,
5339 GLsizei bufSize,
5340 GLint *params)
5341{
5342 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
5343 QueryInternalFormativ(formatCaps, pname, bufSize, params);
5344}
5345
Jamie Madill81c2e252017-09-09 23:32:46 -04005346void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5347{
5348 Program *programObject = getProgram(program);
5349 ASSERT(programObject);
5350 if (programObject->setUniform1iv(location, count, value) ==
5351 Program::SetUniformResult::SamplerChanged)
5352 {
5353 mGLState.setObjectDirty(GL_PROGRAM);
5354 }
5355}
5356
5357void Context::onTextureChange(const Texture *texture)
5358{
5359 // Conservatively assume all textures are dirty.
5360 // TODO(jmadill): More fine-grained update.
5361 mGLState.setObjectDirty(GL_TEXTURE);
5362}
5363
Yunchao Hea336b902017-08-02 16:05:21 +08005364void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
5365{
5366 for (int i = 0; i < count; i++)
5367 {
5368 pipelines[i] = createProgramPipeline();
5369 }
5370}
5371
5372void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
5373{
5374 for (int i = 0; i < count; i++)
5375 {
5376 if (pipelines[i] != 0)
5377 {
5378 deleteProgramPipeline(pipelines[i]);
5379 }
5380 }
5381}
5382
5383GLboolean Context::isProgramPipeline(GLuint pipeline)
5384{
5385 if (pipeline == 0)
5386 {
5387 return GL_FALSE;
5388 }
5389
5390 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
5391}
5392
Jamie Madillc29968b2016-01-20 11:17:23 -05005393} // namespace gl