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