blob: ade792eddbef4a66f0c07e6ea9bfd9ac0ed91884 [file] [log] [blame]
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001//
Geoff Langeeba6e12014-02-03 13:12:30 -05002// Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7// Context.cpp: Implements the gl::Context class, managing all GL state and performing
8// rendering operations. It is the GLES2 specific implementation of EGLContext.
9
Geoff Lang2b5420c2014-11-19 14:20:15 -050010#include "libANGLE/Context.h"
apatrick@chromium.org144f2802012-07-12 01:42:34 +000011
Jamie Madill231c7f52017-04-26 13:45:37 -040012#include <string.h>
Jamie Madillb9293972015-02-19 11:07:54 -050013#include <iterator>
14#include <sstream>
Sami Väisänend59ca052016-06-21 16:10:00 +030015#include <vector>
Jamie Madillb9293972015-02-19 11:07:54 -050016
Sami Väisänene45e53b2016-05-25 10:36:04 +030017#include "common/matrix_utils.h"
Geoff Lang0b7eef72014-06-12 14:10:47 -040018#include "common/platform.h"
Jamie Madillb9293972015-02-19 11:07:54 -050019#include "common/utilities.h"
Geoff Langc339c4e2016-11-29 10:37:36 -050020#include "common/version.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050021#include "libANGLE/Buffer.h"
Jamie Madillb9293972015-02-19 11:07:54 -050022#include "libANGLE/Compiler.h"
Jamie Madill948bbe52017-06-01 13:10:42 -040023#include "libANGLE/Display.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050024#include "libANGLE/Fence.h"
25#include "libANGLE/Framebuffer.h"
26#include "libANGLE/FramebufferAttachment.h"
Sami Väisänene45e53b2016-05-25 10:36:04 +030027#include "libANGLE/Path.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050028#include "libANGLE/Program.h"
Yunchao Hea336b902017-08-02 16:05:21 +080029#include "libANGLE/ProgramPipeline.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050030#include "libANGLE/Query.h"
Jamie Madillb9293972015-02-19 11:07:54 -050031#include "libANGLE/Renderbuffer.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050032#include "libANGLE/ResourceManager.h"
33#include "libANGLE/Sampler.h"
Jamie Madill9dd0cf02014-11-24 11:38:51 -050034#include "libANGLE/Surface.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050035#include "libANGLE/Texture.h"
36#include "libANGLE/TransformFeedback.h"
37#include "libANGLE/VertexArray.h"
Kenneth Russellf2f6f652016-10-05 19:53:23 -070038#include "libANGLE/Workarounds.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040039#include "libANGLE/formatutils.h"
Martin Radev66fb8202016-07-28 11:45:20 +030040#include "libANGLE/queryconversions.h"
Geoff Langc1984ed2016-10-07 12:41:00 -040041#include "libANGLE/queryutils.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040042#include "libANGLE/renderer/ContextImpl.h"
43#include "libANGLE/renderer/EGLImplFactory.h"
Jamie Madill7b62cf92017-11-02 15:20:49 -040044#include "libANGLE/renderer/Format.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040045#include "libANGLE/validationES.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000046
Geoff Langf6db0982015-08-25 13:04:00 -040047namespace
48{
49
Jamie Madillb6664922017-07-25 12:55:04 -040050#define ANGLE_HANDLE_ERR(X) \
51 handleError(X); \
52 return;
53#define ANGLE_CONTEXT_TRY(EXPR) ANGLE_TRY_TEMPLATE(EXPR, ANGLE_HANDLE_ERR);
54
Ian Ewell3ffd78b2016-01-22 16:09:42 -050055template <typename T>
Geoff Lang4ddf5af2016-12-01 14:30:44 -050056std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager,
Sami Väisänend59ca052016-06-21 16:10:00 +030057 GLsizei numPaths,
58 const void *paths,
59 GLuint pathBase)
60{
61 std::vector<gl::Path *> ret;
62 ret.reserve(numPaths);
63
64 const auto *nameArray = static_cast<const T *>(paths);
65
66 for (GLsizei i = 0; i < numPaths; ++i)
67 {
68 const GLuint pathName = nameArray[i] + pathBase;
69
70 ret.push_back(resourceManager.getPath(pathName));
71 }
72
73 return ret;
74}
75
Geoff Lang4ddf5af2016-12-01 14:30:44 -050076std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager,
Sami Väisänend59ca052016-06-21 16:10:00 +030077 GLsizei numPaths,
78 GLenum pathNameType,
79 const void *paths,
80 GLuint pathBase)
81{
82 switch (pathNameType)
83 {
84 case GL_UNSIGNED_BYTE:
85 return GatherPaths<GLubyte>(resourceManager, numPaths, paths, pathBase);
86
87 case GL_BYTE:
88 return GatherPaths<GLbyte>(resourceManager, numPaths, paths, pathBase);
89
90 case GL_UNSIGNED_SHORT:
91 return GatherPaths<GLushort>(resourceManager, numPaths, paths, pathBase);
92
93 case GL_SHORT:
94 return GatherPaths<GLshort>(resourceManager, numPaths, paths, pathBase);
95
96 case GL_UNSIGNED_INT:
97 return GatherPaths<GLuint>(resourceManager, numPaths, paths, pathBase);
98
99 case GL_INT:
100 return GatherPaths<GLint>(resourceManager, numPaths, paths, pathBase);
101 }
102
103 UNREACHABLE();
104 return std::vector<gl::Path *>();
105}
106
107template <typename T>
Geoff Lang2186c382016-10-14 10:54:54 -0400108gl::Error GetQueryObjectParameter(gl::Query *query, GLenum pname, T *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500109{
Geoff Lang2186c382016-10-14 10:54:54 -0400110 ASSERT(query != nullptr);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500111
112 switch (pname)
113 {
114 case GL_QUERY_RESULT_EXT:
Geoff Lang2186c382016-10-14 10:54:54 -0400115 return query->getResult(params);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500116 case GL_QUERY_RESULT_AVAILABLE_EXT:
117 {
118 bool available;
Geoff Lang2186c382016-10-14 10:54:54 -0400119 gl::Error error = query->isResultAvailable(&available);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500120 if (!error.isError())
121 {
jchen10a99ed552017-09-22 08:10:32 +0800122 *params = gl::CastFromStateValue<T>(pname, static_cast<GLuint>(available));
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500123 }
124 return error;
125 }
126 default:
127 UNREACHABLE();
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500128 return gl::InternalError() << "Unreachable Error";
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500129 }
130}
131
Geoff Langf6db0982015-08-25 13:04:00 -0400132void MarkTransformFeedbackBufferUsage(gl::TransformFeedback *transformFeedback)
133{
Geoff Lang1a683462015-09-29 15:09:59 -0400134 if (transformFeedback && transformFeedback->isActive() && !transformFeedback->isPaused())
Geoff Langf6db0982015-08-25 13:04:00 -0400135 {
136 for (size_t tfBufferIndex = 0; tfBufferIndex < transformFeedback->getIndexedBufferCount();
137 tfBufferIndex++)
138 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400139 const gl::OffsetBindingPointer<gl::Buffer> &buffer =
Geoff Langf6db0982015-08-25 13:04:00 -0400140 transformFeedback->getIndexedBuffer(tfBufferIndex);
141 if (buffer.get() != nullptr)
142 {
143 buffer->onTransformFeedback();
144 }
145 }
146 }
147}
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500148
149// Attribute map queries.
Martin Radev1be913c2016-07-11 17:59:16 +0300150EGLint GetClientMajorVersion(const egl::AttributeMap &attribs)
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500151{
Ian Ewellec2c0c52016-04-05 13:46:26 -0400152 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_CLIENT_VERSION, 1));
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500153}
154
Martin Radev1be913c2016-07-11 17:59:16 +0300155EGLint GetClientMinorVersion(const egl::AttributeMap &attribs)
156{
157 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_MINOR_VERSION, 0));
158}
159
Geoff Langeb66a6e2016-10-31 13:06:12 -0400160gl::Version GetClientVersion(const egl::AttributeMap &attribs)
161{
162 return gl::Version(GetClientMajorVersion(attribs), GetClientMinorVersion(attribs));
163}
164
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500165GLenum GetResetStrategy(const egl::AttributeMap &attribs)
166{
Ian Ewellec2c0c52016-04-05 13:46:26 -0400167 EGLAttrib attrib = attribs.get(EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT,
Jeff Gilbertc5de4d22017-10-31 15:07:53 -0700168 EGL_NO_RESET_NOTIFICATION);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500169 switch (attrib)
170 {
171 case EGL_NO_RESET_NOTIFICATION:
172 return GL_NO_RESET_NOTIFICATION_EXT;
173 case EGL_LOSE_CONTEXT_ON_RESET:
174 return GL_LOSE_CONTEXT_ON_RESET_EXT;
175 default:
176 UNREACHABLE();
177 return GL_NONE;
178 }
179}
180
181bool GetRobustAccess(const egl::AttributeMap &attribs)
182{
Geoff Lang077f20a2016-11-01 10:08:02 -0400183 return (attribs.get(EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT, EGL_FALSE) == EGL_TRUE) ||
184 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR) !=
185 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500186}
187
188bool GetDebug(const egl::AttributeMap &attribs)
189{
Geoff Lang077f20a2016-11-01 10:08:02 -0400190 return (attribs.get(EGL_CONTEXT_OPENGL_DEBUG, EGL_FALSE) == EGL_TRUE) ||
191 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR) != 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500192}
193
194bool GetNoError(const egl::AttributeMap &attribs)
195{
196 return (attribs.get(EGL_CONTEXT_OPENGL_NO_ERROR_KHR, EGL_FALSE) == EGL_TRUE);
197}
198
Geoff Langc287ea62016-09-16 14:46:51 -0400199bool GetWebGLContext(const egl::AttributeMap &attribs)
200{
201 return (attribs.get(EGL_CONTEXT_WEBGL_COMPATIBILITY_ANGLE, EGL_FALSE) == EGL_TRUE);
202}
203
Geoff Langf41a7152016-09-19 15:11:17 -0400204bool GetBindGeneratesResource(const egl::AttributeMap &attribs)
205{
206 return (attribs.get(EGL_CONTEXT_BIND_GENERATES_RESOURCE_CHROMIUM, EGL_TRUE) == EGL_TRUE);
207}
208
Geoff Langfeb8c682017-02-13 16:07:35 -0500209bool GetClientArraysEnabled(const egl::AttributeMap &attribs)
210{
211 return (attribs.get(EGL_CONTEXT_CLIENT_ARRAYS_ENABLED_ANGLE, EGL_TRUE) == EGL_TRUE);
212}
213
Geoff Langb433e872017-10-05 14:01:47 -0400214bool GetRobustResourceInit(const egl::AttributeMap &attribs)
215{
216 return (attribs.get(EGL_ROBUST_RESOURCE_INITIALIZATION_ANGLE, EGL_FALSE) == EGL_TRUE);
217}
218
Martin Radev9d901792016-07-15 15:58:58 +0300219std::string GetObjectLabelFromPointer(GLsizei length, const GLchar *label)
220{
221 std::string labelName;
222 if (label != nullptr)
223 {
224 size_t labelLength = length < 0 ? strlen(label) : length;
225 labelName = std::string(label, labelLength);
226 }
227 return labelName;
228}
229
230void GetObjectLabelBase(const std::string &objectLabel,
231 GLsizei bufSize,
232 GLsizei *length,
233 GLchar *label)
234{
235 size_t writeLength = objectLabel.length();
236 if (label != nullptr && bufSize > 0)
237 {
238 writeLength = std::min(static_cast<size_t>(bufSize) - 1, objectLabel.length());
239 std::copy(objectLabel.begin(), objectLabel.begin() + writeLength, label);
240 label[writeLength] = '\0';
241 }
242
243 if (length != nullptr)
244 {
245 *length = static_cast<GLsizei>(writeLength);
246 }
247}
248
Jamie Madill0f80ed82017-09-19 00:24:56 -0400249template <typename CapT, typename MaxT>
250void LimitCap(CapT *cap, MaxT maximum)
251{
252 *cap = std::min(*cap, static_cast<CapT>(maximum));
253}
254
Geoff Langf6db0982015-08-25 13:04:00 -0400255} // anonymous namespace
256
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000257namespace gl
258{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +0000259
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400260Context::Context(rx::EGLImplFactory *implFactory,
261 const egl::Config *config,
Corentin Wallez51706ea2015-08-07 14:39:22 -0400262 const Context *shareContext,
Geoff Langce02f082017-02-06 16:46:21 -0500263 TextureManager *shareTextures,
Jamie Madill32447362017-06-28 14:53:52 -0400264 MemoryProgramCache *memoryProgramCache,
Corentin Wallezc295e512017-01-27 17:47:50 -0500265 const egl::AttributeMap &attribs,
Geoff Langb433e872017-10-05 14:01:47 -0400266 const egl::DisplayExtensions &displayExtensions)
Martin Radev1be913c2016-07-11 17:59:16 +0300267
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500268 : ValidationContext(shareContext,
Geoff Langce02f082017-02-06 16:46:21 -0500269 shareTextures,
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500270 GetClientVersion(attribs),
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700271 &mGLState,
Jamie Madillf25855c2015-11-03 11:06:18 -0500272 mCaps,
273 mTextureCaps,
274 mExtensions,
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500275 mLimitations,
276 GetNoError(attribs)),
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700277 mImplementation(implFactory->createContext(mState)),
Jamie Madill2f348d22017-06-05 10:50:59 -0400278 mCompiler(),
Corentin Walleze3b10e82015-05-20 11:06:25 -0400279 mConfig(config),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500280 mClientType(EGL_OPENGL_ES_API),
281 mHasBeenCurrent(false),
282 mContextLost(false),
283 mResetStatus(GL_NO_ERROR),
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700284 mContextLostForced(false),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500285 mResetStrategy(GetResetStrategy(attribs)),
286 mRobustAccess(GetRobustAccess(attribs)),
Jamie Madill61e16b42017-06-19 11:13:23 -0400287 mCurrentSurface(static_cast<egl::Surface *>(EGL_NO_SURFACE)),
288 mCurrentDisplay(static_cast<egl::Display *>(EGL_NO_DISPLAY)),
Jamie Madill4e0e6f82017-02-17 11:06:03 -0500289 mSurfacelessFramebuffer(nullptr),
Jamie Madille14951e2017-03-09 18:55:16 -0500290 mWebGLContext(GetWebGLContext(attribs)),
Jamie Madill32447362017-06-28 14:53:52 -0400291 mMemoryProgramCache(memoryProgramCache),
Jamie Madillb3f26b92017-07-19 15:07:41 -0400292 mScratchBuffer(1000u),
293 mZeroFilledBuffer(1000u)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000294{
Jamie Madill14bbb3f2017-09-12 15:23:01 -0400295 mImplementation->setMemoryProgramCache(memoryProgramCache);
296
Geoff Langb433e872017-10-05 14:01:47 -0400297 bool robustResourceInit = GetRobustResourceInit(attribs);
298 initCaps(displayExtensions, robustResourceInit);
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700299 initWorkarounds();
Geoff Langc0b9ef42014-07-02 10:02:37 -0400300
Jamie Madill4928b7c2017-06-20 12:57:39 -0400301 mGLState.initialize(this, GetDebug(attribs), GetBindGeneratesResource(attribs),
Jamie Madillc43be722017-07-13 16:22:14 -0400302 GetClientArraysEnabled(attribs), robustResourceInit,
303 mMemoryProgramCache != nullptr);
Régis Fénéon83107972015-02-05 12:57:44 +0100304
Shannon Woods53a94a82014-06-24 15:20:36 -0400305 mFenceNVHandleAllocator.setBaseHandle(0);
Geoff Lang7dca1862013-07-30 16:30:46 -0400306
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000307 // [OpenGL ES 2.0.24] section 3.7 page 83:
Corentin Wallez336129f2017-10-17 15:55:40 -0400308 // In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have two-dimensional
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000309 // and cube map texture state vectors respectively associated with them.
310 // In order that access to these initial textures not be lost, they are treated as texture
311 // objects all of whose names are 0.
312
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400313 Texture *zeroTexture2D = new Texture(mImplementation.get(), 0, GL_TEXTURE_2D);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400314 mZeroTextures[GL_TEXTURE_2D].set(this, zeroTexture2D);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500315
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400316 Texture *zeroTextureCube = new Texture(mImplementation.get(), 0, GL_TEXTURE_CUBE_MAP);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400317 mZeroTextures[GL_TEXTURE_CUBE_MAP].set(this, zeroTextureCube);
Geoff Lang76b10c92014-09-05 16:28:14 -0400318
Geoff Langeb66a6e2016-10-31 13:06:12 -0400319 if (getClientVersion() >= Version(3, 0))
Geoff Lang76b10c92014-09-05 16:28:14 -0400320 {
321 // TODO: These could also be enabled via extension
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400322 Texture *zeroTexture3D = new Texture(mImplementation.get(), 0, GL_TEXTURE_3D);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400323 mZeroTextures[GL_TEXTURE_3D].set(this, zeroTexture3D);
Geoff Lang76b10c92014-09-05 16:28:14 -0400324
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400325 Texture *zeroTexture2DArray = new Texture(mImplementation.get(), 0, GL_TEXTURE_2D_ARRAY);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400326 mZeroTextures[GL_TEXTURE_2D_ARRAY].set(this, zeroTexture2DArray);
Geoff Lang76b10c92014-09-05 16:28:14 -0400327 }
Geoff Lang3b573612016-10-31 14:08:10 -0400328 if (getClientVersion() >= Version(3, 1))
329 {
330 Texture *zeroTexture2DMultisample =
331 new Texture(mImplementation.get(), 0, GL_TEXTURE_2D_MULTISAMPLE);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400332 mZeroTextures[GL_TEXTURE_2D_MULTISAMPLE].set(this, zeroTexture2DMultisample);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800333
Jiajia Qin6eafb042016-12-27 17:04:07 +0800334 for (unsigned int i = 0; i < mCaps.maxAtomicCounterBufferBindings; i++)
335 {
Corentin Wallez336129f2017-10-17 15:55:40 -0400336 bindBufferRange(BufferBinding::AtomicCounter, 0, i, 0, 0);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800337 }
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800338
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800339 for (unsigned int i = 0; i < mCaps.maxShaderStorageBufferBindings; i++)
340 {
Corentin Wallez336129f2017-10-17 15:55:40 -0400341 bindBufferRange(BufferBinding::ShaderStorage, i, 0, 0, 0);
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800342 }
Geoff Lang3b573612016-10-31 14:08:10 -0400343 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000344
Geoff Lang4751aab2017-10-30 15:14:52 -0400345 const Extensions &nativeExtensions = mImplementation->getNativeExtensions();
346 if (nativeExtensions.textureRectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400347 {
348 Texture *zeroTextureRectangle =
349 new Texture(mImplementation.get(), 0, GL_TEXTURE_RECTANGLE_ANGLE);
350 mZeroTextures[GL_TEXTURE_RECTANGLE_ANGLE].set(this, zeroTextureRectangle);
351 }
352
Geoff Lang4751aab2017-10-30 15:14:52 -0400353 if (nativeExtensions.eglImageExternal || nativeExtensions.eglStreamConsumerExternal)
Ian Ewellbda75592016-04-18 17:25:54 -0400354 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400355 Texture *zeroTextureExternal =
356 new Texture(mImplementation.get(), 0, GL_TEXTURE_EXTERNAL_OES);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400357 mZeroTextures[GL_TEXTURE_EXTERNAL_OES].set(this, zeroTextureExternal);
Ian Ewellbda75592016-04-18 17:25:54 -0400358 }
359
Jamie Madill4928b7c2017-06-20 12:57:39 -0400360 mGLState.initializeZeroTextures(this, mZeroTextures);
Jamie Madille6382c32014-11-07 15:05:26 -0500361
Jamie Madill57a89722013-07-02 11:57:03 -0400362 bindVertexArray(0);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000363
Geoff Langeb66a6e2016-10-31 13:06:12 -0400364 if (getClientVersion() >= Version(3, 0))
Geoff Lang1a683462015-09-29 15:09:59 -0400365 {
366 // [OpenGL ES 3.0.2] section 2.14.1 pg 85:
367 // In the initial state, a default transform feedback object is bound and treated as
368 // a transform feedback object with a name of zero. That object is bound any time
369 // BindTransformFeedback is called with id of zero
Jamie Madillf0dcb8b2017-08-26 19:05:13 -0400370 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Geoff Lang1a683462015-09-29 15:09:59 -0400371 }
Geoff Langc8058452014-02-03 12:04:11 -0500372
Corentin Wallez336129f2017-10-17 15:55:40 -0400373 for (auto type : angle::AllEnums<BufferBinding>())
374 {
375 bindBuffer(type, 0);
376 }
377
378 bindRenderbuffer(GL_RENDERBUFFER, 0);
379
380 for (unsigned int i = 0; i < mCaps.maxUniformBufferBindings; i++)
381 {
382 bindBufferRange(BufferBinding::Uniform, i, 0, 0, -1);
383 }
384
Jamie Madillad9f24e2016-02-12 09:27:24 -0500385 // Initialize dirty bit masks
Jamie Madillc67323a2017-11-02 23:11:41 -0400386 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500387 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500388 // No dirty objects.
389
390 // Readpixels uses the pack state and read FBO
Jamie Madillc67323a2017-11-02 23:11:41 -0400391 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500392 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500393 mReadPixelsDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
394
395 mClearDirtyBits.set(State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED);
396 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
397 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR);
398 mClearDirtyBits.set(State::DIRTY_BIT_VIEWPORT);
399 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_COLOR);
400 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_DEPTH);
401 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_STENCIL);
402 mClearDirtyBits.set(State::DIRTY_BIT_COLOR_MASK);
403 mClearDirtyBits.set(State::DIRTY_BIT_DEPTH_MASK);
404 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT);
405 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_BACK);
406 mClearDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
407
408 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
409 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR);
Geoff Lang1d2c41d2016-10-19 16:14:46 -0700410 mBlitDirtyBits.set(State::DIRTY_BIT_FRAMEBUFFER_SRGB);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500411 mBlitDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
412 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
Jamie Madill437fa652016-05-03 15:13:24 -0400413
Xinghua Cao10a4d432017-11-28 14:46:26 +0800414 // TODO(xinghua.cao@intel.com): add other dirty bits and dirty objects.
415 mComputeDirtyBits.set(State::DIRTY_BIT_SHADER_STORAGE_BUFFER_BINDING);
416 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_BINDING);
417 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_EXECUTABLE);
418 mComputeDirtyBits.set(State::DIRTY_BIT_TEXTURE_BINDINGS);
419 mComputeDirtyBits.set(State::DIRTY_BIT_SAMPLER_BINDINGS);
420
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400421 handleError(mImplementation->initialize());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000422}
423
Jamie Madill4928b7c2017-06-20 12:57:39 -0400424egl::Error Context::onDestroy(const egl::Display *display)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000425{
Corentin Wallez80b24112015-08-25 16:41:57 -0400426 for (auto fence : mFenceNVMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000427 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400428 SafeDelete(fence.second);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000429 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400430 mFenceNVMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000431
Corentin Wallez80b24112015-08-25 16:41:57 -0400432 for (auto query : mQueryMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000433 {
Geoff Langf0aa8422015-09-29 15:08:34 -0400434 if (query.second != nullptr)
435 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400436 query.second->release(this);
Geoff Langf0aa8422015-09-29 15:08:34 -0400437 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000438 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400439 mQueryMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000440
Corentin Wallez80b24112015-08-25 16:41:57 -0400441 for (auto vertexArray : mVertexArrayMap)
Jamie Madill57a89722013-07-02 11:57:03 -0400442 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400443 if (vertexArray.second)
444 {
445 vertexArray.second->onDestroy(this);
446 }
Jamie Madill57a89722013-07-02 11:57:03 -0400447 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400448 mVertexArrayMap.clear();
Jamie Madill57a89722013-07-02 11:57:03 -0400449
Corentin Wallez80b24112015-08-25 16:41:57 -0400450 for (auto transformFeedback : mTransformFeedbackMap)
Geoff Langc8058452014-02-03 12:04:11 -0500451 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500452 if (transformFeedback.second != nullptr)
453 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500454 transformFeedback.second->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500455 }
Geoff Langc8058452014-02-03 12:04:11 -0500456 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400457 mTransformFeedbackMap.clear();
Geoff Langc8058452014-02-03 12:04:11 -0500458
Jamie Madilldedd7b92014-11-05 16:30:36 -0500459 for (auto &zeroTexture : mZeroTextures)
Geoff Lang76b10c92014-09-05 16:28:14 -0400460 {
Jamie Madill71c88b32017-09-14 22:20:29 -0400461 ANGLE_TRY(zeroTexture.second->onDestroy(this));
Jamie Madill4928b7c2017-06-20 12:57:39 -0400462 zeroTexture.second.set(this, nullptr);
Geoff Lang76b10c92014-09-05 16:28:14 -0400463 }
464 mZeroTextures.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000465
Corentin Wallezccab69d2017-01-27 16:57:15 -0500466 SafeDelete(mSurfacelessFramebuffer);
467
Jamie Madill4928b7c2017-06-20 12:57:39 -0400468 ANGLE_TRY(releaseSurface(display));
Jamie Madill2f348d22017-06-05 10:50:59 -0400469 releaseShaderCompiler();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500470
Jamie Madill4928b7c2017-06-20 12:57:39 -0400471 mGLState.reset(this);
472
Jamie Madill6c1f6712017-02-14 19:08:04 -0500473 mState.mBuffers->release(this);
474 mState.mShaderPrograms->release(this);
475 mState.mTextures->release(this);
476 mState.mRenderbuffers->release(this);
477 mState.mSamplers->release(this);
Jamie Madill70b5bb02017-08-28 13:32:37 -0400478 mState.mSyncs->release(this);
Jamie Madill6c1f6712017-02-14 19:08:04 -0500479 mState.mPaths->release(this);
480 mState.mFramebuffers->release(this);
Yunchao Hea336b902017-08-02 16:05:21 +0800481 mState.mPipelines->release(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400482
Jamie Madill76e471e2017-10-21 09:56:01 -0400483 mImplementation->onDestroy(this);
484
Jamie Madill4928b7c2017-06-20 12:57:39 -0400485 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000486}
487
Jamie Madill70ee0f62017-02-06 16:04:20 -0500488Context::~Context()
489{
490}
491
Jamie Madill4928b7c2017-06-20 12:57:39 -0400492egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000493{
Jamie Madill61e16b42017-06-19 11:13:23 -0400494 mCurrentDisplay = display;
495
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000496 if (!mHasBeenCurrent)
497 {
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000498 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500499 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400500 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000501
Corentin Wallezc295e512017-01-27 17:47:50 -0500502 int width = 0;
503 int height = 0;
504 if (surface != nullptr)
505 {
506 width = surface->getWidth();
507 height = surface->getHeight();
508 }
509
510 mGLState.setViewportParams(0, 0, width, height);
511 mGLState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000512
513 mHasBeenCurrent = true;
514 }
515
Jamie Madill1b94d432015-08-07 13:23:23 -0400516 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700517 mGLState.setAllDirtyBits();
Jamie Madill81c2e252017-09-09 23:32:46 -0400518 mGLState.setAllDirtyObjects();
Jamie Madill1b94d432015-08-07 13:23:23 -0400519
Jamie Madill4928b7c2017-06-20 12:57:39 -0400520 ANGLE_TRY(releaseSurface(display));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500521
522 Framebuffer *newDefault = nullptr;
523 if (surface != nullptr)
524 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400525 ANGLE_TRY(surface->setIsCurrent(this, true));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500526 mCurrentSurface = surface;
527 newDefault = surface->getDefaultFramebuffer();
528 }
529 else
530 {
531 if (mSurfacelessFramebuffer == nullptr)
532 {
533 mSurfacelessFramebuffer = new Framebuffer(mImplementation.get());
534 }
535
536 newDefault = mSurfacelessFramebuffer;
537 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000538
Corentin Wallez37c39792015-08-20 14:19:46 -0400539 // Update default framebuffer, the binding of the previous default
540 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400541 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700542 if (mGLState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400543 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700544 mGLState.setReadFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400545 }
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700546 if (mGLState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400547 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700548 mGLState.setDrawFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400549 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500550 mState.mFramebuffers->setDefaultFramebuffer(newDefault);
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400551 }
Ian Ewell292f0052016-02-04 10:37:32 -0500552
553 // Notify the renderer of a context switch
Jamie Madill4928b7c2017-06-20 12:57:39 -0400554 mImplementation->onMakeCurrent(this);
555 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000556}
557
Jamie Madill4928b7c2017-06-20 12:57:39 -0400558egl::Error Context::releaseSurface(const egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400559{
Corentin Wallez37c39792015-08-20 14:19:46 -0400560 // Remove the default framebuffer
Corentin Wallezc295e512017-01-27 17:47:50 -0500561 Framebuffer *currentDefault = nullptr;
562 if (mCurrentSurface != nullptr)
Corentin Wallez51706ea2015-08-07 14:39:22 -0400563 {
Corentin Wallezc295e512017-01-27 17:47:50 -0500564 currentDefault = mCurrentSurface->getDefaultFramebuffer();
565 }
566 else if (mSurfacelessFramebuffer != nullptr)
567 {
568 currentDefault = mSurfacelessFramebuffer;
Corentin Wallez51706ea2015-08-07 14:39:22 -0400569 }
570
Corentin Wallezc295e512017-01-27 17:47:50 -0500571 if (mGLState.getReadFramebuffer() == currentDefault)
572 {
573 mGLState.setReadFramebufferBinding(nullptr);
574 }
575 if (mGLState.getDrawFramebuffer() == currentDefault)
576 {
577 mGLState.setDrawFramebufferBinding(nullptr);
578 }
579 mState.mFramebuffers->setDefaultFramebuffer(nullptr);
580
581 if (mCurrentSurface)
582 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400583 ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
Corentin Wallezc295e512017-01-27 17:47:50 -0500584 mCurrentSurface = nullptr;
585 }
Jamie Madill4928b7c2017-06-20 12:57:39 -0400586
587 return egl::NoError();
Jamie Madill77a72f62015-04-14 11:18:32 -0400588}
589
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000590GLuint Context::createBuffer()
591{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500592 return mState.mBuffers->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000593}
594
595GLuint Context::createProgram()
596{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500597 return mState.mShaderPrograms->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000598}
599
600GLuint Context::createShader(GLenum type)
601{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500602 return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000603}
604
605GLuint Context::createTexture()
606{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500607 return mState.mTextures->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000608}
609
610GLuint Context::createRenderbuffer()
611{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500612 return mState.mRenderbuffers->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000613}
614
Sami Väisänene45e53b2016-05-25 10:36:04 +0300615GLuint Context::createPaths(GLsizei range)
616{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500617 auto resultOrError = mState.mPaths->createPaths(mImplementation.get(), range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300618 if (resultOrError.isError())
619 {
620 handleError(resultOrError.getError());
621 return 0;
622 }
623 return resultOrError.getResult();
624}
625
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000626// Returns an unused framebuffer name
627GLuint Context::createFramebuffer()
628{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500629 return mState.mFramebuffers->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000630}
631
Jamie Madill33dc8432013-07-26 11:55:05 -0400632GLuint Context::createFenceNV()
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000633{
Jamie Madill33dc8432013-07-26 11:55:05 -0400634 GLuint handle = mFenceNVHandleAllocator.allocate();
Jamie Madill96a483b2017-06-27 16:49:21 -0400635 mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV()));
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000636 return handle;
637}
638
Yunchao Hea336b902017-08-02 16:05:21 +0800639GLuint Context::createProgramPipeline()
640{
641 return mState.mPipelines->createProgramPipeline();
642}
643
Jiajia Qin5451d532017-11-16 17:16:34 +0800644GLuint Context::createShaderProgramv(GLenum type, GLsizei count, const GLchar *const *strings)
645{
646 UNIMPLEMENTED();
647 return 0u;
648}
649
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000650void Context::deleteBuffer(GLuint buffer)
651{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500652 if (mState.mBuffers->getBuffer(buffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000653 {
654 detachBuffer(buffer);
655 }
Jamie Madill893ab082014-05-16 16:56:10 -0400656
Jamie Madill6c1f6712017-02-14 19:08:04 -0500657 mState.mBuffers->deleteObject(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000658}
659
660void Context::deleteShader(GLuint shader)
661{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500662 mState.mShaderPrograms->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000663}
664
665void Context::deleteProgram(GLuint program)
666{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500667 mState.mShaderPrograms->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000668}
669
670void Context::deleteTexture(GLuint texture)
671{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500672 if (mState.mTextures->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000673 {
674 detachTexture(texture);
675 }
676
Jamie Madill6c1f6712017-02-14 19:08:04 -0500677 mState.mTextures->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000678}
679
680void Context::deleteRenderbuffer(GLuint renderbuffer)
681{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500682 if (mState.mRenderbuffers->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000683 {
684 detachRenderbuffer(renderbuffer);
685 }
Jamie Madill893ab082014-05-16 16:56:10 -0400686
Jamie Madill6c1f6712017-02-14 19:08:04 -0500687 mState.mRenderbuffers->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000688}
689
Jamie Madill7f0c5a42017-08-26 22:43:26 -0400690void Context::deleteSync(GLsync sync)
Jamie Madillcd055f82013-07-26 11:55:15 -0400691{
692 // The spec specifies the underlying Fence object is not deleted until all current
693 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
694 // and since our API is currently designed for being called from a single thread, we can delete
695 // the fence immediately.
Jamie Madill70b5bb02017-08-28 13:32:37 -0400696 mState.mSyncs->deleteObject(this, static_cast<GLuint>(reinterpret_cast<uintptr_t>(sync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400697}
698
Yunchao Hea336b902017-08-02 16:05:21 +0800699void Context::deleteProgramPipeline(GLuint pipeline)
700{
701 if (mState.mPipelines->getProgramPipeline(pipeline))
702 {
703 detachProgramPipeline(pipeline);
704 }
705
706 mState.mPipelines->deleteObject(this, pipeline);
707}
708
Sami Väisänene45e53b2016-05-25 10:36:04 +0300709void Context::deletePaths(GLuint first, GLsizei range)
710{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500711 mState.mPaths->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300712}
713
714bool Context::hasPathData(GLuint path) const
715{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500716 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300717 if (pathObj == nullptr)
718 return false;
719
720 return pathObj->hasPathData();
721}
722
723bool Context::hasPath(GLuint path) const
724{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500725 return mState.mPaths->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300726}
727
728void Context::setPathCommands(GLuint path,
729 GLsizei numCommands,
730 const GLubyte *commands,
731 GLsizei numCoords,
732 GLenum coordType,
733 const void *coords)
734{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500735 auto *pathObject = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300736
737 handleError(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
738}
739
740void Context::setPathParameterf(GLuint path, GLenum pname, GLfloat value)
741{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500742 auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300743
744 switch (pname)
745 {
746 case GL_PATH_STROKE_WIDTH_CHROMIUM:
747 pathObj->setStrokeWidth(value);
748 break;
749 case GL_PATH_END_CAPS_CHROMIUM:
750 pathObj->setEndCaps(static_cast<GLenum>(value));
751 break;
752 case GL_PATH_JOIN_STYLE_CHROMIUM:
753 pathObj->setJoinStyle(static_cast<GLenum>(value));
754 break;
755 case GL_PATH_MITER_LIMIT_CHROMIUM:
756 pathObj->setMiterLimit(value);
757 break;
758 case GL_PATH_STROKE_BOUND_CHROMIUM:
759 pathObj->setStrokeBound(value);
760 break;
761 default:
762 UNREACHABLE();
763 break;
764 }
765}
766
767void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value) const
768{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500769 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300770
771 switch (pname)
772 {
773 case GL_PATH_STROKE_WIDTH_CHROMIUM:
774 *value = pathObj->getStrokeWidth();
775 break;
776 case GL_PATH_END_CAPS_CHROMIUM:
777 *value = static_cast<GLfloat>(pathObj->getEndCaps());
778 break;
779 case GL_PATH_JOIN_STYLE_CHROMIUM:
780 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
781 break;
782 case GL_PATH_MITER_LIMIT_CHROMIUM:
783 *value = pathObj->getMiterLimit();
784 break;
785 case GL_PATH_STROKE_BOUND_CHROMIUM:
786 *value = pathObj->getStrokeBound();
787 break;
788 default:
789 UNREACHABLE();
790 break;
791 }
792}
793
794void Context::setPathStencilFunc(GLenum func, GLint ref, GLuint mask)
795{
796 mGLState.setPathStencilFunc(func, ref, mask);
797}
798
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000799void Context::deleteFramebuffer(GLuint framebuffer)
800{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500801 if (mState.mFramebuffers->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000802 {
803 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000804 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500805
Jamie Madill6c1f6712017-02-14 19:08:04 -0500806 mState.mFramebuffers->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000807}
808
Jamie Madill33dc8432013-07-26 11:55:05 -0400809void Context::deleteFenceNV(GLuint fence)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000810{
Jamie Madill96a483b2017-06-27 16:49:21 -0400811 FenceNV *fenceObject = nullptr;
812 if (mFenceNVMap.erase(fence, &fenceObject))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000813 {
Jamie Madill96a483b2017-06-27 16:49:21 -0400814 mFenceNVHandleAllocator.release(fence);
815 delete fenceObject;
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000816 }
817}
818
Geoff Lang70d0f492015-12-10 17:45:46 -0500819Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000820{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500821 return mState.mBuffers->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000822}
823
Jamie Madill570f7c82014-07-03 10:38:54 -0400824Texture *Context::getTexture(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000825{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500826 return mState.mTextures->getTexture(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000827}
828
Geoff Lang70d0f492015-12-10 17:45:46 -0500829Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000830{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500831 return mState.mRenderbuffers->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000832}
833
Jamie Madill70b5bb02017-08-28 13:32:37 -0400834Sync *Context::getSync(GLsync handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400835{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400836 return mState.mSyncs->getSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400837}
838
Jamie Madill57a89722013-07-02 11:57:03 -0400839VertexArray *Context::getVertexArray(GLuint handle) const
840{
Jamie Madill96a483b2017-06-27 16:49:21 -0400841 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -0400842}
843
Jamie Madilldc356042013-07-19 16:36:57 -0400844Sampler *Context::getSampler(GLuint handle) const
845{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500846 return mState.mSamplers->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400847}
848
Geoff Langc8058452014-02-03 12:04:11 -0500849TransformFeedback *Context::getTransformFeedback(GLuint handle) const
850{
Jamie Madill96a483b2017-06-27 16:49:21 -0400851 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -0500852}
853
Yunchao Hea336b902017-08-02 16:05:21 +0800854ProgramPipeline *Context::getProgramPipeline(GLuint handle) const
855{
856 return mState.mPipelines->getProgramPipeline(handle);
857}
858
Geoff Lang70d0f492015-12-10 17:45:46 -0500859LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
860{
861 switch (identifier)
862 {
863 case GL_BUFFER:
864 return getBuffer(name);
865 case GL_SHADER:
866 return getShader(name);
867 case GL_PROGRAM:
868 return getProgram(name);
869 case GL_VERTEX_ARRAY:
870 return getVertexArray(name);
871 case GL_QUERY:
872 return getQuery(name);
873 case GL_TRANSFORM_FEEDBACK:
874 return getTransformFeedback(name);
875 case GL_SAMPLER:
876 return getSampler(name);
877 case GL_TEXTURE:
878 return getTexture(name);
879 case GL_RENDERBUFFER:
880 return getRenderbuffer(name);
881 case GL_FRAMEBUFFER:
882 return getFramebuffer(name);
883 default:
884 UNREACHABLE();
885 return nullptr;
886 }
887}
888
889LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
890{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400891 return getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
Geoff Lang70d0f492015-12-10 17:45:46 -0500892}
893
Martin Radev9d901792016-07-15 15:58:58 +0300894void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
895{
896 LabeledObject *object = getLabeledObject(identifier, name);
897 ASSERT(object != nullptr);
898
899 std::string labelName = GetObjectLabelFromPointer(length, label);
900 object->setLabel(labelName);
Jamie Madill8693bdb2017-09-02 15:32:14 -0400901
902 // TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the
903 // specified object is active until we do this.
904 mGLState.setObjectDirty(identifier);
Martin Radev9d901792016-07-15 15:58:58 +0300905}
906
907void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
908{
909 LabeledObject *object = getLabeledObjectFromPtr(ptr);
910 ASSERT(object != nullptr);
911
912 std::string labelName = GetObjectLabelFromPointer(length, label);
913 object->setLabel(labelName);
914}
915
916void Context::getObjectLabel(GLenum identifier,
917 GLuint name,
918 GLsizei bufSize,
919 GLsizei *length,
920 GLchar *label) const
921{
922 LabeledObject *object = getLabeledObject(identifier, name);
923 ASSERT(object != nullptr);
924
925 const std::string &objectLabel = object->getLabel();
926 GetObjectLabelBase(objectLabel, bufSize, length, label);
927}
928
929void Context::getObjectPtrLabel(const void *ptr,
930 GLsizei bufSize,
931 GLsizei *length,
932 GLchar *label) const
933{
934 LabeledObject *object = getLabeledObjectFromPtr(ptr);
935 ASSERT(object != nullptr);
936
937 const std::string &objectLabel = object->getLabel();
938 GetObjectLabelBase(objectLabel, bufSize, length, label);
939}
940
Jamie Madilldc356042013-07-19 16:36:57 -0400941bool Context::isSampler(GLuint samplerName) const
942{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500943 return mState.mSamplers->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -0400944}
945
Jamie Madilldedd7b92014-11-05 16:30:36 -0500946void Context::bindTexture(GLenum target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000947{
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500948 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000949
Jamie Madilldedd7b92014-11-05 16:30:36 -0500950 if (handle == 0)
951 {
952 texture = mZeroTextures[target].get();
953 }
954 else
955 {
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500956 texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500957 }
958
959 ASSERT(texture);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400960 mGLState.setSamplerTexture(this, target, texture);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +0000961}
962
Jamie Madill5bf9ff42016-02-01 11:13:03 -0500963void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000964{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500965 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
966 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700967 mGLState.setReadFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000968}
969
Jamie Madill5bf9ff42016-02-01 11:13:03 -0500970void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000971{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500972 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
973 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700974 mGLState.setDrawFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000975}
976
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500977void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -0400978{
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500979 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700980 mGLState.setVertexArrayBinding(vertexArray);
Jamie Madill57a89722013-07-02 11:57:03 -0400981}
982
Shao80957d92017-02-20 21:25:59 +0800983void Context::bindVertexBuffer(GLuint bindingIndex,
984 GLuint bufferHandle,
985 GLintptr offset,
986 GLsizei stride)
987{
988 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400989 mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Shao80957d92017-02-20 21:25:59 +0800990}
991
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500992void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -0400993{
Geoff Lang76b10c92014-09-05 16:28:14 -0400994 ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -0400995 Sampler *sampler =
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500996 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400997 mGLState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -0400998}
999
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001000void Context::bindImageTexture(GLuint unit,
1001 GLuint texture,
1002 GLint level,
1003 GLboolean layered,
1004 GLint layer,
1005 GLenum access,
1006 GLenum format)
1007{
1008 Texture *tex = mState.mTextures->getTexture(texture);
1009 mGLState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
1010}
1011
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001012void Context::useProgram(GLuint program)
1013{
Jamie Madill6c1f6712017-02-14 19:08:04 -05001014 mGLState.setProgram(this, getProgram(program));
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001015}
1016
Jiajia Qin5451d532017-11-16 17:16:34 +08001017void Context::useProgramStages(GLuint pipeline, GLbitfield stages, GLuint program)
1018{
1019 UNIMPLEMENTED();
1020}
1021
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001022void Context::bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001023{
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001024 ASSERT(target == GL_TRANSFORM_FEEDBACK);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001025 TransformFeedback *transformFeedback =
1026 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001027 mGLState.setTransformFeedbackBinding(this, transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -05001028}
1029
Yunchao Hea336b902017-08-02 16:05:21 +08001030void Context::bindProgramPipeline(GLuint pipelineHandle)
1031{
1032 ProgramPipeline *pipeline =
1033 mState.mPipelines->checkProgramPipelineAllocation(mImplementation.get(), pipelineHandle);
1034 mGLState.setProgramPipelineBinding(this, pipeline);
1035}
1036
Jamie Madillf0e04492017-08-26 15:28:42 -04001037void Context::beginQuery(GLenum target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001038{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001039 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001040 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001041
Geoff Lang5aad9672014-09-08 11:10:42 -04001042 // begin query
Jamie Madillf0e04492017-08-26 15:28:42 -04001043 ANGLE_CONTEXT_TRY(queryObject->begin());
Geoff Lang5aad9672014-09-08 11:10:42 -04001044
1045 // set query as active for specified target only if begin succeeded
Jamie Madill4928b7c2017-06-20 12:57:39 -04001046 mGLState.setActiveQuery(this, target, queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001047}
1048
Jamie Madillf0e04492017-08-26 15:28:42 -04001049void Context::endQuery(GLenum target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001050{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001051 Query *queryObject = mGLState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001052 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001053
Jamie Madillf0e04492017-08-26 15:28:42 -04001054 handleError(queryObject->end());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001055
Geoff Lang5aad9672014-09-08 11:10:42 -04001056 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madill4928b7c2017-06-20 12:57:39 -04001057 mGLState.setActiveQuery(this, target, nullptr);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001058}
1059
Jamie Madillf0e04492017-08-26 15:28:42 -04001060void Context::queryCounter(GLuint id, GLenum target)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001061{
1062 ASSERT(target == GL_TIMESTAMP_EXT);
1063
1064 Query *queryObject = getQuery(id, true, target);
1065 ASSERT(queryObject);
1066
Jamie Madillf0e04492017-08-26 15:28:42 -04001067 handleError(queryObject->queryCounter());
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001068}
1069
1070void Context::getQueryiv(GLenum target, GLenum pname, GLint *params)
1071{
1072 switch (pname)
1073 {
1074 case GL_CURRENT_QUERY_EXT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001075 params[0] = mGLState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001076 break;
1077 case GL_QUERY_COUNTER_BITS_EXT:
1078 switch (target)
1079 {
1080 case GL_TIME_ELAPSED_EXT:
1081 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1082 break;
1083 case GL_TIMESTAMP_EXT:
1084 params[0] = getExtensions().queryCounterBitsTimestamp;
1085 break;
1086 default:
1087 UNREACHABLE();
1088 params[0] = 0;
1089 break;
1090 }
1091 break;
1092 default:
1093 UNREACHABLE();
1094 return;
1095 }
1096}
1097
Geoff Lang2186c382016-10-14 10:54:54 -04001098void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001099{
Geoff Lang2186c382016-10-14 10:54:54 -04001100 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001101}
1102
Geoff Lang2186c382016-10-14 10:54:54 -04001103void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001104{
Geoff Lang2186c382016-10-14 10:54:54 -04001105 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001106}
1107
Geoff Lang2186c382016-10-14 10:54:54 -04001108void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001109{
Geoff Lang2186c382016-10-14 10:54:54 -04001110 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001111}
1112
Geoff Lang2186c382016-10-14 10:54:54 -04001113void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001114{
Geoff Lang2186c382016-10-14 10:54:54 -04001115 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001116}
1117
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001118Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001119{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001120 return mState.mFramebuffers->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001121}
1122
Jamie Madill2f348d22017-06-05 10:50:59 -04001123FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001124{
Jamie Madill96a483b2017-06-27 16:49:21 -04001125 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001126}
1127
Jamie Madill2f348d22017-06-05 10:50:59 -04001128Query *Context::getQuery(GLuint handle, bool create, GLenum type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001129{
Jamie Madill96a483b2017-06-27 16:49:21 -04001130 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001131 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001132 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001133 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001134
1135 Query *query = mQueryMap.query(handle);
1136 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001137 {
Jamie Madill96a483b2017-06-27 16:49:21 -04001138 query = new Query(mImplementation->createQuery(type), handle);
1139 query->addRef();
1140 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001141 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001142 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001143}
1144
Geoff Lang70d0f492015-12-10 17:45:46 -05001145Query *Context::getQuery(GLuint handle) const
1146{
Jamie Madill96a483b2017-06-27 16:49:21 -04001147 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001148}
1149
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001150Texture *Context::getTargetTexture(GLenum target) const
1151{
Ian Ewellbda75592016-04-18 17:25:54 -04001152 ASSERT(ValidTextureTarget(this, target) || ValidTextureExternalTarget(this, target));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001153 return mGLState.getTargetTexture(target);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001154}
1155
Geoff Lang76b10c92014-09-05 16:28:14 -04001156Texture *Context::getSamplerTexture(unsigned int sampler, GLenum type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001157{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001158 return mGLState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001159}
1160
Geoff Lang492a7e42014-11-05 13:27:06 -05001161Compiler *Context::getCompiler() const
1162{
Jamie Madill2f348d22017-06-05 10:50:59 -04001163 if (mCompiler.get() == nullptr)
1164 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001165 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001166 }
1167 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001168}
1169
Jamie Madillc1d770e2017-04-13 17:31:24 -04001170void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001171{
1172 switch (pname)
1173 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001174 case GL_SHADER_COMPILER:
1175 *params = GL_TRUE;
1176 break;
1177 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1178 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1179 break;
1180 default:
1181 mGLState.getBooleanv(pname, params);
1182 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001183 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001184}
1185
Jamie Madillc1d770e2017-04-13 17:31:24 -04001186void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001187{
Shannon Woods53a94a82014-06-24 15:20:36 -04001188 // Queries about context capabilities and maximums are answered by Context.
1189 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001190 switch (pname)
1191 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001192 case GL_ALIASED_LINE_WIDTH_RANGE:
1193 params[0] = mCaps.minAliasedLineWidth;
1194 params[1] = mCaps.maxAliasedLineWidth;
1195 break;
1196 case GL_ALIASED_POINT_SIZE_RANGE:
1197 params[0] = mCaps.minAliasedPointSize;
1198 params[1] = mCaps.maxAliasedPointSize;
1199 break;
1200 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1201 ASSERT(mExtensions.textureFilterAnisotropic);
1202 *params = mExtensions.maxTextureAnisotropy;
1203 break;
1204 case GL_MAX_TEXTURE_LOD_BIAS:
1205 *params = mCaps.maxLODBias;
1206 break;
1207
1208 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1209 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1210 {
1211 ASSERT(mExtensions.pathRendering);
1212 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1213 memcpy(params, m, 16 * sizeof(GLfloat));
1214 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001215 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001216
Jamie Madill231c7f52017-04-26 13:45:37 -04001217 default:
1218 mGLState.getFloatv(pname, params);
1219 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001220 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001221}
1222
Jamie Madillc1d770e2017-04-13 17:31:24 -04001223void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001224{
Shannon Woods53a94a82014-06-24 15:20:36 -04001225 // Queries about context capabilities and maximums are answered by Context.
1226 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001227
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001228 switch (pname)
1229 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001230 case GL_MAX_VERTEX_ATTRIBS:
1231 *params = mCaps.maxVertexAttributes;
1232 break;
1233 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1234 *params = mCaps.maxVertexUniformVectors;
1235 break;
1236 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
1237 *params = mCaps.maxVertexUniformComponents;
1238 break;
1239 case GL_MAX_VARYING_VECTORS:
1240 *params = mCaps.maxVaryingVectors;
1241 break;
1242 case GL_MAX_VARYING_COMPONENTS:
1243 *params = mCaps.maxVertexOutputComponents;
1244 break;
1245 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1246 *params = mCaps.maxCombinedTextureImageUnits;
1247 break;
1248 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
1249 *params = mCaps.maxVertexTextureImageUnits;
1250 break;
1251 case GL_MAX_TEXTURE_IMAGE_UNITS:
1252 *params = mCaps.maxTextureImageUnits;
1253 break;
1254 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1255 *params = mCaps.maxFragmentUniformVectors;
1256 break;
1257 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
1258 *params = mCaps.maxFragmentUniformComponents;
1259 break;
1260 case GL_MAX_RENDERBUFFER_SIZE:
1261 *params = mCaps.maxRenderbufferSize;
1262 break;
1263 case GL_MAX_COLOR_ATTACHMENTS_EXT:
1264 *params = mCaps.maxColorAttachments;
1265 break;
1266 case GL_MAX_DRAW_BUFFERS_EXT:
1267 *params = mCaps.maxDrawBuffers;
1268 break;
1269 // case GL_FRAMEBUFFER_BINDING: // now equivalent to
1270 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
1271 case GL_SUBPIXEL_BITS:
1272 *params = 4;
1273 break;
1274 case GL_MAX_TEXTURE_SIZE:
1275 *params = mCaps.max2DTextureSize;
1276 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001277 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
1278 *params = mCaps.maxRectangleTextureSize;
1279 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001280 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1281 *params = mCaps.maxCubeMapTextureSize;
1282 break;
1283 case GL_MAX_3D_TEXTURE_SIZE:
1284 *params = mCaps.max3DTextureSize;
1285 break;
1286 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1287 *params = mCaps.maxArrayTextureLayers;
1288 break;
1289 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1290 *params = mCaps.uniformBufferOffsetAlignment;
1291 break;
1292 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1293 *params = mCaps.maxUniformBufferBindings;
1294 break;
1295 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
1296 *params = mCaps.maxVertexUniformBlocks;
1297 break;
1298 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
1299 *params = mCaps.maxFragmentUniformBlocks;
1300 break;
1301 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1302 *params = mCaps.maxCombinedTextureImageUnits;
1303 break;
1304 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1305 *params = mCaps.maxVertexOutputComponents;
1306 break;
1307 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1308 *params = mCaps.maxFragmentInputComponents;
1309 break;
1310 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1311 *params = mCaps.minProgramTexelOffset;
1312 break;
1313 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1314 *params = mCaps.maxProgramTexelOffset;
1315 break;
1316 case GL_MAJOR_VERSION:
1317 *params = getClientVersion().major;
1318 break;
1319 case GL_MINOR_VERSION:
1320 *params = getClientVersion().minor;
1321 break;
1322 case GL_MAX_ELEMENTS_INDICES:
1323 *params = mCaps.maxElementsIndices;
1324 break;
1325 case GL_MAX_ELEMENTS_VERTICES:
1326 *params = mCaps.maxElementsVertices;
1327 break;
1328 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1329 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1330 break;
1331 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1332 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1333 break;
1334 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1335 *params = mCaps.maxTransformFeedbackSeparateComponents;
1336 break;
1337 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1338 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1339 break;
1340 case GL_MAX_SAMPLES_ANGLE:
1341 *params = mCaps.maxSamples;
1342 break;
1343 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001344 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001345 params[0] = mCaps.maxViewportWidth;
1346 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001347 }
1348 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001349 case GL_COMPRESSED_TEXTURE_FORMATS:
1350 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1351 params);
1352 break;
1353 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1354 *params = mResetStrategy;
1355 break;
1356 case GL_NUM_SHADER_BINARY_FORMATS:
1357 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1358 break;
1359 case GL_SHADER_BINARY_FORMATS:
1360 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1361 break;
1362 case GL_NUM_PROGRAM_BINARY_FORMATS:
1363 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1364 break;
1365 case GL_PROGRAM_BINARY_FORMATS:
1366 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1367 break;
1368 case GL_NUM_EXTENSIONS:
1369 *params = static_cast<GLint>(mExtensionStrings.size());
1370 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001371
Jamie Madill231c7f52017-04-26 13:45:37 -04001372 // GL_KHR_debug
1373 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1374 *params = mExtensions.maxDebugMessageLength;
1375 break;
1376 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1377 *params = mExtensions.maxDebugLoggedMessages;
1378 break;
1379 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1380 *params = mExtensions.maxDebugGroupStackDepth;
1381 break;
1382 case GL_MAX_LABEL_LENGTH:
1383 *params = mExtensions.maxLabelLength;
1384 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001385
Martin Radeve5285d22017-07-14 16:23:53 +03001386 // GL_ANGLE_multiview
1387 case GL_MAX_VIEWS_ANGLE:
1388 *params = mExtensions.maxViews;
1389 break;
1390
Jamie Madill231c7f52017-04-26 13:45:37 -04001391 // GL_EXT_disjoint_timer_query
1392 case GL_GPU_DISJOINT_EXT:
1393 *params = mImplementation->getGPUDisjoint();
1394 break;
1395 case GL_MAX_FRAMEBUFFER_WIDTH:
1396 *params = mCaps.maxFramebufferWidth;
1397 break;
1398 case GL_MAX_FRAMEBUFFER_HEIGHT:
1399 *params = mCaps.maxFramebufferHeight;
1400 break;
1401 case GL_MAX_FRAMEBUFFER_SAMPLES:
1402 *params = mCaps.maxFramebufferSamples;
1403 break;
1404 case GL_MAX_SAMPLE_MASK_WORDS:
1405 *params = mCaps.maxSampleMaskWords;
1406 break;
1407 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1408 *params = mCaps.maxColorTextureSamples;
1409 break;
1410 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1411 *params = mCaps.maxDepthTextureSamples;
1412 break;
1413 case GL_MAX_INTEGER_SAMPLES:
1414 *params = mCaps.maxIntegerSamples;
1415 break;
1416 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1417 *params = mCaps.maxVertexAttribRelativeOffset;
1418 break;
1419 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1420 *params = mCaps.maxVertexAttribBindings;
1421 break;
1422 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1423 *params = mCaps.maxVertexAttribStride;
1424 break;
1425 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
1426 *params = mCaps.maxVertexAtomicCounterBuffers;
1427 break;
1428 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
1429 *params = mCaps.maxVertexAtomicCounters;
1430 break;
1431 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
1432 *params = mCaps.maxVertexImageUniforms;
1433 break;
1434 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
1435 *params = mCaps.maxVertexShaderStorageBlocks;
1436 break;
1437 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
1438 *params = mCaps.maxFragmentAtomicCounterBuffers;
1439 break;
1440 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
1441 *params = mCaps.maxFragmentAtomicCounters;
1442 break;
1443 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
1444 *params = mCaps.maxFragmentImageUniforms;
1445 break;
1446 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
1447 *params = mCaps.maxFragmentShaderStorageBlocks;
1448 break;
1449 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1450 *params = mCaps.minProgramTextureGatherOffset;
1451 break;
1452 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1453 *params = mCaps.maxProgramTextureGatherOffset;
1454 break;
1455 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1456 *params = mCaps.maxComputeWorkGroupInvocations;
1457 break;
1458 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
1459 *params = mCaps.maxComputeUniformBlocks;
1460 break;
1461 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
1462 *params = mCaps.maxComputeTextureImageUnits;
1463 break;
1464 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1465 *params = mCaps.maxComputeSharedMemorySize;
1466 break;
1467 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
1468 *params = mCaps.maxComputeUniformComponents;
1469 break;
1470 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
1471 *params = mCaps.maxComputeAtomicCounterBuffers;
1472 break;
1473 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
1474 *params = mCaps.maxComputeAtomicCounters;
1475 break;
1476 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
1477 *params = mCaps.maxComputeImageUniforms;
1478 break;
1479 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
1480 *params = mCaps.maxCombinedComputeUniformComponents;
1481 break;
1482 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
1483 *params = mCaps.maxComputeShaderStorageBlocks;
1484 break;
1485 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1486 *params = mCaps.maxCombinedShaderOutputResources;
1487 break;
1488 case GL_MAX_UNIFORM_LOCATIONS:
1489 *params = mCaps.maxUniformLocations;
1490 break;
1491 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1492 *params = mCaps.maxAtomicCounterBufferBindings;
1493 break;
1494 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1495 *params = mCaps.maxAtomicCounterBufferSize;
1496 break;
1497 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1498 *params = mCaps.maxCombinedAtomicCounterBuffers;
1499 break;
1500 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1501 *params = mCaps.maxCombinedAtomicCounters;
1502 break;
1503 case GL_MAX_IMAGE_UNITS:
1504 *params = mCaps.maxImageUnits;
1505 break;
1506 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1507 *params = mCaps.maxCombinedImageUniforms;
1508 break;
1509 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1510 *params = mCaps.maxShaderStorageBufferBindings;
1511 break;
1512 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1513 *params = mCaps.maxCombinedShaderStorageBlocks;
1514 break;
1515 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1516 *params = mCaps.shaderStorageBufferOffsetAlignment;
1517 break;
Jiawei Shao361df072017-11-22 09:33:59 +08001518
1519 // GL_EXT_geometry_shader
1520 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
1521 *params = mCaps.maxFramebufferLayers;
1522 break;
1523 case GL_LAYER_PROVOKING_VERTEX_EXT:
1524 *params = mCaps.layerProvokingVertex;
1525 break;
1526 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
1527 *params = mCaps.maxGeometryUniformComponents;
1528 break;
1529 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
1530 *params = mCaps.maxGeometryUniformBlocks;
1531 break;
1532 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
1533 *params = mCaps.maxCombinedGeometryUniformComponents;
1534 break;
1535 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
1536 *params = mCaps.maxGeometryInputComponents;
1537 break;
1538 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
1539 *params = mCaps.maxGeometryOutputComponents;
1540 break;
1541 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
1542 *params = mCaps.maxGeometryOutputVertices;
1543 break;
1544 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
1545 *params = mCaps.maxGeometryTotalOutputComponents;
1546 break;
1547 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
1548 *params = mCaps.maxGeometryShaderInvocations;
1549 break;
1550 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
1551 *params = mCaps.maxGeometryTextureImageUnits;
1552 break;
1553 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
1554 *params = mCaps.maxGeometryAtomicCounterBuffers;
1555 break;
1556 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
1557 *params = mCaps.maxGeometryAtomicCounters;
1558 break;
1559 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
1560 *params = mCaps.maxGeometryImageUniforms;
1561 break;
1562 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
1563 *params = mCaps.maxGeometryShaderStorageBlocks;
1564 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001565 default:
1566 mGLState.getIntegerv(this, pname, params);
1567 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001568 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001569}
1570
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001571void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001572{
Shannon Woods53a94a82014-06-24 15:20:36 -04001573 // Queries about context capabilities and maximums are answered by Context.
1574 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001575 switch (pname)
1576 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001577 case GL_MAX_ELEMENT_INDEX:
1578 *params = mCaps.maxElementIndex;
1579 break;
1580 case GL_MAX_UNIFORM_BLOCK_SIZE:
1581 *params = mCaps.maxUniformBlockSize;
1582 break;
1583 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
1584 *params = mCaps.maxCombinedVertexUniformComponents;
1585 break;
1586 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
1587 *params = mCaps.maxCombinedFragmentUniformComponents;
1588 break;
1589 case GL_MAX_SERVER_WAIT_TIMEOUT:
1590 *params = mCaps.maxServerWaitTimeout;
1591 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001592
Jamie Madill231c7f52017-04-26 13:45:37 -04001593 // GL_EXT_disjoint_timer_query
1594 case GL_TIMESTAMP_EXT:
1595 *params = mImplementation->getTimestamp();
1596 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001597
Jamie Madill231c7f52017-04-26 13:45:37 -04001598 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1599 *params = mCaps.maxShaderStorageBlockSize;
1600 break;
1601 default:
1602 UNREACHABLE();
1603 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001604 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001605}
1606
Geoff Lang70d0f492015-12-10 17:45:46 -05001607void Context::getPointerv(GLenum pname, void **params) const
1608{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001609 mGLState.getPointerv(pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001610}
1611
Martin Radev66fb8202016-07-28 11:45:20 +03001612void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001613{
Shannon Woods53a94a82014-06-24 15:20:36 -04001614 // Queries about context capabilities and maximums are answered by Context.
1615 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001616
1617 GLenum nativeType;
1618 unsigned int numParams;
1619 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1620 ASSERT(queryStatus);
1621
1622 if (nativeType == GL_INT)
1623 {
1624 switch (target)
1625 {
1626 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1627 ASSERT(index < 3u);
1628 *data = mCaps.maxComputeWorkGroupCount[index];
1629 break;
1630 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1631 ASSERT(index < 3u);
1632 *data = mCaps.maxComputeWorkGroupSize[index];
1633 break;
1634 default:
1635 mGLState.getIntegeri_v(target, index, data);
1636 }
1637 }
1638 else
1639 {
1640 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1641 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001642}
1643
Martin Radev66fb8202016-07-28 11:45:20 +03001644void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001645{
Shannon Woods53a94a82014-06-24 15:20:36 -04001646 // Queries about context capabilities and maximums are answered by Context.
1647 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001648
1649 GLenum nativeType;
1650 unsigned int numParams;
1651 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1652 ASSERT(queryStatus);
1653
1654 if (nativeType == GL_INT_64_ANGLEX)
1655 {
1656 mGLState.getInteger64i_v(target, index, data);
1657 }
1658 else
1659 {
1660 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1661 }
1662}
1663
1664void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1665{
1666 // Queries about context capabilities and maximums are answered by Context.
1667 // Queries about current GL state values are answered by State.
1668
1669 GLenum nativeType;
1670 unsigned int numParams;
1671 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1672 ASSERT(queryStatus);
1673
1674 if (nativeType == GL_BOOL)
1675 {
1676 mGLState.getBooleani_v(target, index, data);
1677 }
1678 else
1679 {
1680 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1681 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001682}
1683
Corentin Wallez336129f2017-10-17 15:55:40 -04001684void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001685{
1686 Buffer *buffer = mGLState.getTargetBuffer(target);
1687 QueryBufferParameteriv(buffer, pname, params);
1688}
1689
1690void Context::getFramebufferAttachmentParameteriv(GLenum target,
1691 GLenum attachment,
1692 GLenum pname,
1693 GLint *params)
1694{
1695 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08001696 QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08001697}
1698
1699void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
1700{
1701 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
1702 QueryRenderbufferiv(this, renderbuffer, pname, params);
1703}
1704
1705void Context::getTexParameterfv(GLenum target, GLenum pname, GLfloat *params)
1706{
1707 Texture *texture = getTargetTexture(target);
1708 QueryTexParameterfv(texture, pname, params);
1709}
1710
1711void Context::getTexParameteriv(GLenum target, GLenum pname, GLint *params)
1712{
1713 Texture *texture = getTargetTexture(target);
1714 QueryTexParameteriv(texture, pname, params);
1715}
Jiajia Qin5451d532017-11-16 17:16:34 +08001716
1717void Context::getTexLevelParameteriv(GLenum target, GLint level, GLenum pname, GLint *params)
1718{
1719 Texture *texture =
1720 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
1721 QueryTexLevelParameteriv(texture, target, level, pname, params);
1722}
1723
1724void Context::getTexLevelParameterfv(GLenum target, GLint level, GLenum pname, GLfloat *params)
1725{
1726 Texture *texture =
1727 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
1728 QueryTexLevelParameterfv(texture, target, level, pname, params);
1729}
1730
He Yunchao010e4db2017-03-03 14:22:06 +08001731void Context::texParameterf(GLenum target, GLenum pname, GLfloat param)
1732{
1733 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001734 SetTexParameterf(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04001735 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001736}
1737
1738void Context::texParameterfv(GLenum target, GLenum pname, const GLfloat *params)
1739{
1740 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001741 SetTexParameterfv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04001742 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001743}
1744
1745void Context::texParameteri(GLenum target, GLenum pname, GLint param)
1746{
1747 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001748 SetTexParameteri(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04001749 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001750}
1751
1752void Context::texParameteriv(GLenum target, GLenum pname, const GLint *params)
1753{
1754 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001755 SetTexParameteriv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04001756 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001757}
1758
Jamie Madill675fe712016-12-19 13:07:54 -05001759void Context::drawArrays(GLenum mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001760{
Jamie Madill05b35b22017-10-03 09:01:44 -04001761 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001762 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
1763 MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001764}
1765
Jamie Madill675fe712016-12-19 13:07:54 -05001766void Context::drawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04001767{
Jamie Madill05b35b22017-10-03 09:01:44 -04001768 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001769 ANGLE_CONTEXT_TRY(
1770 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
1771 MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback());
Geoff Langf6db0982015-08-25 13:04:00 -04001772}
1773
Jamie Madill876429b2017-04-20 15:46:24 -04001774void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001775{
Jamie Madill05b35b22017-10-03 09:01:44 -04001776 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001777 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04001778}
1779
Jamie Madill675fe712016-12-19 13:07:54 -05001780void Context::drawElementsInstanced(GLenum mode,
1781 GLsizei count,
1782 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04001783 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04001784 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04001785{
Jamie Madill05b35b22017-10-03 09:01:44 -04001786 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001787 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08001788 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04001789}
1790
Jamie Madill675fe712016-12-19 13:07:54 -05001791void Context::drawRangeElements(GLenum mode,
1792 GLuint start,
1793 GLuint end,
1794 GLsizei count,
1795 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04001796 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04001797{
Jamie Madill05b35b22017-10-03 09:01:44 -04001798 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001799 ANGLE_CONTEXT_TRY(
1800 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001801}
1802
Jamie Madill876429b2017-04-20 15:46:24 -04001803void Context::drawArraysIndirect(GLenum mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08001804{
Jamie Madill05b35b22017-10-03 09:01:44 -04001805 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001806 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08001807}
1808
Jamie Madill876429b2017-04-20 15:46:24 -04001809void Context::drawElementsIndirect(GLenum mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08001810{
Jamie Madill05b35b22017-10-03 09:01:44 -04001811 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001812 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08001813}
1814
Jamie Madill675fe712016-12-19 13:07:54 -05001815void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001816{
Jamie Madillafa02a22017-11-23 12:57:38 -05001817 handleError(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05001818}
1819
Jamie Madill675fe712016-12-19 13:07:54 -05001820void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05001821{
Jamie Madillafa02a22017-11-23 12:57:38 -05001822 handleError(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001823}
1824
Austin Kinross6ee1e782015-05-29 17:05:37 -07001825void Context::insertEventMarker(GLsizei length, const char *marker)
1826{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001827 ASSERT(mImplementation);
1828 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07001829}
1830
1831void Context::pushGroupMarker(GLsizei length, const char *marker)
1832{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001833 ASSERT(mImplementation);
1834 mImplementation->pushGroupMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07001835}
1836
1837void Context::popGroupMarker()
1838{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001839 ASSERT(mImplementation);
1840 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07001841}
1842
Geoff Langd8605522016-04-13 10:19:12 -04001843void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
1844{
1845 Program *programObject = getProgram(program);
1846 ASSERT(programObject);
1847
1848 programObject->bindUniformLocation(location, name);
1849}
1850
Sami Väisänena797e062016-05-12 15:23:40 +03001851void Context::setCoverageModulation(GLenum components)
1852{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001853 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03001854}
1855
Sami Väisänene45e53b2016-05-25 10:36:04 +03001856void Context::loadPathRenderingMatrix(GLenum matrixMode, const GLfloat *matrix)
1857{
1858 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
1859}
1860
1861void Context::loadPathRenderingIdentityMatrix(GLenum matrixMode)
1862{
1863 GLfloat I[16];
1864 angle::Matrix<GLfloat>::setToIdentity(I);
1865
1866 mGLState.loadPathRenderingMatrix(matrixMode, I);
1867}
1868
1869void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
1870{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001871 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001872 if (!pathObj)
1873 return;
1874
1875 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1876 syncRendererState();
1877
1878 mImplementation->stencilFillPath(pathObj, fillMode, mask);
1879}
1880
1881void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
1882{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001883 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001884 if (!pathObj)
1885 return;
1886
1887 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1888 syncRendererState();
1889
1890 mImplementation->stencilStrokePath(pathObj, reference, mask);
1891}
1892
1893void Context::coverFillPath(GLuint path, GLenum coverMode)
1894{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001895 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001896 if (!pathObj)
1897 return;
1898
1899 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1900 syncRendererState();
1901
1902 mImplementation->coverFillPath(pathObj, coverMode);
1903}
1904
1905void Context::coverStrokePath(GLuint path, GLenum coverMode)
1906{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001907 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001908 if (!pathObj)
1909 return;
1910
1911 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1912 syncRendererState();
1913
1914 mImplementation->coverStrokePath(pathObj, coverMode);
1915}
1916
1917void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
1918{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001919 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001920 if (!pathObj)
1921 return;
1922
1923 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1924 syncRendererState();
1925
1926 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
1927}
1928
1929void Context::stencilThenCoverStrokePath(GLuint path,
1930 GLint reference,
1931 GLuint mask,
1932 GLenum coverMode)
1933{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001934 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001935 if (!pathObj)
1936 return;
1937
1938 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1939 syncRendererState();
1940
1941 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
1942}
1943
Sami Väisänend59ca052016-06-21 16:10:00 +03001944void Context::coverFillPathInstanced(GLsizei numPaths,
1945 GLenum pathNameType,
1946 const void *paths,
1947 GLuint pathBase,
1948 GLenum coverMode,
1949 GLenum transformType,
1950 const GLfloat *transformValues)
1951{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001952 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03001953
1954 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1955 syncRendererState();
1956
1957 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
1958}
Sami Väisänen46eaa942016-06-29 10:26:37 +03001959
Sami Väisänend59ca052016-06-21 16:10:00 +03001960void Context::coverStrokePathInstanced(GLsizei numPaths,
1961 GLenum pathNameType,
1962 const void *paths,
1963 GLuint pathBase,
1964 GLenum coverMode,
1965 GLenum transformType,
1966 const GLfloat *transformValues)
1967{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001968 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03001969
1970 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1971 syncRendererState();
1972
1973 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
1974 transformValues);
1975}
Sami Väisänen46eaa942016-06-29 10:26:37 +03001976
Sami Väisänend59ca052016-06-21 16:10:00 +03001977void Context::stencilFillPathInstanced(GLsizei numPaths,
1978 GLenum pathNameType,
1979 const void *paths,
1980 GLuint pathBase,
1981 GLenum fillMode,
1982 GLuint mask,
1983 GLenum transformType,
1984 const GLfloat *transformValues)
1985{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001986 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03001987
1988 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1989 syncRendererState();
1990
1991 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
1992 transformValues);
1993}
Sami Väisänen46eaa942016-06-29 10:26:37 +03001994
Sami Väisänend59ca052016-06-21 16:10:00 +03001995void Context::stencilStrokePathInstanced(GLsizei numPaths,
1996 GLenum pathNameType,
1997 const void *paths,
1998 GLuint pathBase,
1999 GLint reference,
2000 GLuint mask,
2001 GLenum transformType,
2002 const GLfloat *transformValues)
2003{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002004 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002005
2006 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2007 syncRendererState();
2008
2009 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2010 transformValues);
2011}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002012
Sami Väisänend59ca052016-06-21 16:10:00 +03002013void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2014 GLenum pathNameType,
2015 const void *paths,
2016 GLuint pathBase,
2017 GLenum fillMode,
2018 GLuint mask,
2019 GLenum coverMode,
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->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2029 transformType, transformValues);
2030}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002031
Sami Väisänend59ca052016-06-21 16:10:00 +03002032void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2033 GLenum pathNameType,
2034 const void *paths,
2035 GLuint pathBase,
2036 GLint reference,
2037 GLuint mask,
2038 GLenum coverMode,
2039 GLenum transformType,
2040 const GLfloat *transformValues)
2041{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002042 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002043
2044 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2045 syncRendererState();
2046
2047 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2048 transformType, transformValues);
2049}
2050
Sami Väisänen46eaa942016-06-29 10:26:37 +03002051void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2052{
2053 auto *programObject = getProgram(program);
2054
2055 programObject->bindFragmentInputLocation(location, name);
2056}
2057
2058void Context::programPathFragmentInputGen(GLuint program,
2059 GLint location,
2060 GLenum genMode,
2061 GLint components,
2062 const GLfloat *coeffs)
2063{
2064 auto *programObject = getProgram(program);
2065
Jamie Madillbd044ed2017-06-05 12:59:21 -04002066 programObject->pathFragmentInputGen(this, location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002067}
2068
jchen1015015f72017-03-16 13:54:21 +08002069GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2070{
jchen10fd7c3b52017-03-21 15:36:03 +08002071 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002072 return QueryProgramResourceIndex(programObject, programInterface, name);
2073}
2074
jchen10fd7c3b52017-03-21 15:36:03 +08002075void Context::getProgramResourceName(GLuint program,
2076 GLenum programInterface,
2077 GLuint index,
2078 GLsizei bufSize,
2079 GLsizei *length,
2080 GLchar *name)
2081{
2082 const auto *programObject = getProgram(program);
2083 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2084}
2085
jchen10191381f2017-04-11 13:59:04 +08002086GLint Context::getProgramResourceLocation(GLuint program,
2087 GLenum programInterface,
2088 const GLchar *name)
2089{
2090 const auto *programObject = getProgram(program);
2091 return QueryProgramResourceLocation(programObject, programInterface, name);
2092}
2093
jchen10880683b2017-04-12 16:21:55 +08002094void Context::getProgramResourceiv(GLuint program,
2095 GLenum programInterface,
2096 GLuint index,
2097 GLsizei propCount,
2098 const GLenum *props,
2099 GLsizei bufSize,
2100 GLsizei *length,
2101 GLint *params)
2102{
2103 const auto *programObject = getProgram(program);
2104 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2105 length, params);
2106}
2107
jchen10d9cd7b72017-08-30 15:04:25 +08002108void Context::getProgramInterfaceiv(GLuint program,
2109 GLenum programInterface,
2110 GLenum pname,
2111 GLint *params)
2112{
2113 const auto *programObject = getProgram(program);
2114 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2115}
2116
Jamie Madill71c88b32017-09-14 22:20:29 -04002117void Context::handleError(const Error &error)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002118{
Geoff Langda5777c2014-07-11 09:52:58 -04002119 if (error.isError())
2120 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002121 GLenum code = error.getCode();
2122 mErrors.insert(code);
2123 if (code == GL_OUT_OF_MEMORY && getWorkarounds().loseContextOnOutOfMemory)
2124 {
2125 markContextLost();
2126 }
Geoff Lang70d0f492015-12-10 17:45:46 -05002127
Geoff Langee6884e2017-11-09 16:51:11 -05002128 ASSERT(!error.getMessage().empty());
2129 mGLState.getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, error.getID(),
2130 GL_DEBUG_SEVERITY_HIGH, error.getMessage());
Geoff Langda5777c2014-07-11 09:52:58 -04002131 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002132}
2133
2134// Get one of the recorded errors and clear its flag, if any.
2135// [OpenGL ES 2.0.24] section 2.5 page 13.
2136GLenum Context::getError()
2137{
Geoff Langda5777c2014-07-11 09:52:58 -04002138 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002139 {
Geoff Langda5777c2014-07-11 09:52:58 -04002140 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002141 }
Geoff Langda5777c2014-07-11 09:52:58 -04002142 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002143 {
Geoff Langda5777c2014-07-11 09:52:58 -04002144 GLenum error = *mErrors.begin();
2145 mErrors.erase(mErrors.begin());
2146 return error;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002147 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002148}
2149
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002150// NOTE: this function should not assume that this context is current!
2151void Context::markContextLost()
2152{
2153 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002154 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002155 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002156 mContextLostForced = true;
2157 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002158 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002159}
2160
2161bool Context::isContextLost()
2162{
2163 return mContextLost;
2164}
2165
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002166GLenum Context::getResetStatus()
2167{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002168 // Even if the application doesn't want to know about resets, we want to know
2169 // as it will allow us to skip all the calls.
2170 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002171 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002172 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002173 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002174 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002175 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002176
2177 // EXT_robustness, section 2.6: If the reset notification behavior is
2178 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2179 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2180 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002181 }
2182
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002183 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2184 // status should be returned at least once, and GL_NO_ERROR should be returned
2185 // once the device has finished resetting.
2186 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002187 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002188 ASSERT(mResetStatus == GL_NO_ERROR);
2189 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002190
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002191 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002192 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002193 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002194 }
2195 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002196 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002197 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002198 // If markContextLost was used to mark the context lost then
2199 // assume that is not recoverable, and continue to report the
2200 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002201 mResetStatus = mImplementation->getResetStatus();
2202 }
Jamie Madill893ab082014-05-16 16:56:10 -04002203
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002204 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002205}
2206
2207bool Context::isResetNotificationEnabled()
2208{
2209 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2210}
2211
Corentin Walleze3b10e82015-05-20 11:06:25 -04002212const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002213{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002214 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002215}
2216
2217EGLenum Context::getClientType() const
2218{
2219 return mClientType;
2220}
2221
2222EGLenum Context::getRenderBuffer() const
2223{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002224 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2225 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002226 {
2227 return EGL_NONE;
2228 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002229
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002230 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002231 ASSERT(backAttachment != nullptr);
2232 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002233}
2234
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002235VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002236{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002237 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002238 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2239 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002240 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002241 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2242 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002243
Jamie Madill96a483b2017-06-27 16:49:21 -04002244 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002245 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002246
2247 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002248}
2249
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002250TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002251{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002252 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002253 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2254 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002255 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002256 transformFeedback =
2257 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002258 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002259 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002260 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002261
2262 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002263}
2264
2265bool Context::isVertexArrayGenerated(GLuint vertexArray)
2266{
Jamie Madill96a483b2017-06-27 16:49:21 -04002267 ASSERT(mVertexArrayMap.contains(0));
2268 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002269}
2270
2271bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2272{
Jamie Madill96a483b2017-06-27 16:49:21 -04002273 ASSERT(mTransformFeedbackMap.contains(0));
2274 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002275}
2276
Shannon Woods53a94a82014-06-24 15:20:36 -04002277void Context::detachTexture(GLuint texture)
2278{
2279 // Simple pass-through to State's detachTexture method, as textures do not require
2280 // allocation map management either here or in the resource manager at detach time.
2281 // Zero textures are held by the Context, and we don't attempt to request them from
2282 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002283 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002284}
2285
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002286void Context::detachBuffer(GLuint buffer)
2287{
Yuly Novikov5807a532015-12-03 13:01:22 -05002288 // Simple pass-through to State's detachBuffer method, since
2289 // only buffer attachments to container objects that are bound to the current context
2290 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002291
Yuly Novikov5807a532015-12-03 13:01:22 -05002292 // [OpenGL ES 3.2] section 5.1.2 page 45:
2293 // Attachments to unbound container objects, such as
2294 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2295 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002296 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002297}
2298
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002299void Context::detachFramebuffer(GLuint framebuffer)
2300{
Shannon Woods53a94a82014-06-24 15:20:36 -04002301 // Framebuffer detachment is handled by Context, because 0 is a valid
2302 // Framebuffer object, and a pointer to it must be passed from Context
2303 // to State at binding time.
2304
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002305 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002306 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2307 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2308 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002309
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002310 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002311 {
2312 bindReadFramebuffer(0);
2313 }
2314
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002315 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002316 {
2317 bindDrawFramebuffer(0);
2318 }
2319}
2320
2321void Context::detachRenderbuffer(GLuint renderbuffer)
2322{
Jamie Madilla02315b2017-02-23 14:14:47 -05002323 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002324}
2325
Jamie Madill57a89722013-07-02 11:57:03 -04002326void Context::detachVertexArray(GLuint vertexArray)
2327{
Jamie Madill77a72f62015-04-14 11:18:32 -04002328 // Vertex array detachment is handled by Context, because 0 is a valid
2329 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002330 // binding time.
2331
Jamie Madill57a89722013-07-02 11:57:03 -04002332 // [OpenGL ES 3.0.2] section 2.10 page 43:
2333 // If a vertex array object that is currently bound is deleted, the binding
2334 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002335 if (mGLState.removeVertexArrayBinding(vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002336 {
2337 bindVertexArray(0);
2338 }
2339}
2340
Geoff Langc8058452014-02-03 12:04:11 -05002341void Context::detachTransformFeedback(GLuint transformFeedback)
2342{
Corentin Walleza2257da2016-04-19 16:43:12 -04002343 // Transform feedback detachment is handled by Context, because 0 is a valid
2344 // transform feedback, and a pointer to it must be passed from Context to State at
2345 // binding time.
2346
2347 // The OpenGL specification doesn't mention what should happen when the currently bound
2348 // transform feedback object is deleted. Since it is a container object, we treat it like
2349 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002350 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002351 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002352 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002353 }
Geoff Langc8058452014-02-03 12:04:11 -05002354}
2355
Jamie Madilldc356042013-07-19 16:36:57 -04002356void Context::detachSampler(GLuint sampler)
2357{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002358 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002359}
2360
Yunchao Hea336b902017-08-02 16:05:21 +08002361void Context::detachProgramPipeline(GLuint pipeline)
2362{
2363 mGLState.detachProgramPipeline(this, pipeline);
2364}
2365
Jamie Madill3ef140a2017-08-26 23:11:21 -04002366void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002367{
Shaodde78e82017-05-22 14:13:27 +08002368 mGLState.setVertexAttribDivisor(this, index, divisor);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002369}
2370
Jamie Madille29d1672013-07-19 16:36:57 -04002371void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2372{
Geoff Langc1984ed2016-10-07 12:41:00 -04002373 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002374 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002375 SetSamplerParameteri(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002376 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002377}
Jamie Madille29d1672013-07-19 16:36:57 -04002378
Geoff Langc1984ed2016-10-07 12:41:00 -04002379void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2380{
2381 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002382 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002383 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002384 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002385}
2386
2387void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2388{
Geoff Langc1984ed2016-10-07 12:41:00 -04002389 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002390 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002391 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002392 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002393}
2394
Geoff Langc1984ed2016-10-07 12:41:00 -04002395void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002396{
Geoff Langc1984ed2016-10-07 12:41:00 -04002397 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002398 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002399 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002400 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002401}
2402
Geoff Langc1984ed2016-10-07 12:41:00 -04002403void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002404{
Geoff Langc1984ed2016-10-07 12:41:00 -04002405 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002406 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002407 QuerySamplerParameteriv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002408 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002409}
Jamie Madill9675b802013-07-19 16:36:59 -04002410
Geoff Langc1984ed2016-10-07 12:41:00 -04002411void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2412{
2413 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002414 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002415 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002416 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002417}
2418
Olli Etuahof0fee072016-03-30 15:11:58 +03002419void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2420{
2421 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002422 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002423}
2424
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002425void Context::initRendererString()
2426{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002427 std::ostringstream rendererString;
2428 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002429 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002430 rendererString << ")";
2431
Geoff Langcec35902014-04-16 10:52:36 -04002432 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002433}
2434
Geoff Langc339c4e2016-11-29 10:37:36 -05002435void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002436{
Geoff Langc339c4e2016-11-29 10:37:36 -05002437 const Version &clientVersion = getClientVersion();
2438
2439 std::ostringstream versionString;
2440 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2441 << ANGLE_VERSION_STRING << ")";
2442 mVersionString = MakeStaticString(versionString.str());
2443
2444 std::ostringstream shadingLanguageVersionString;
2445 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2446 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2447 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2448 << ")";
2449 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002450}
2451
Geoff Langcec35902014-04-16 10:52:36 -04002452void Context::initExtensionStrings()
2453{
Geoff Langc339c4e2016-11-29 10:37:36 -05002454 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2455 std::ostringstream combinedStringStream;
2456 std::copy(strings.begin(), strings.end(),
2457 std::ostream_iterator<const char *>(combinedStringStream, " "));
2458 return MakeStaticString(combinedStringStream.str());
2459 };
2460
2461 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002462 for (const auto &extensionString : mExtensions.getStrings())
2463 {
2464 mExtensionStrings.push_back(MakeStaticString(extensionString));
2465 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002466 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002467
Bryan Bernhart58806562017-01-05 13:09:31 -08002468 const gl::Extensions &nativeExtensions = mImplementation->getNativeExtensions();
2469
Geoff Langc339c4e2016-11-29 10:37:36 -05002470 mRequestableExtensionStrings.clear();
2471 for (const auto &extensionInfo : GetExtensionInfoMap())
2472 {
2473 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08002474 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
2475 nativeExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002476 {
2477 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
2478 }
2479 }
2480 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002481}
2482
Geoff Langc339c4e2016-11-29 10:37:36 -05002483const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04002484{
Geoff Langc339c4e2016-11-29 10:37:36 -05002485 switch (name)
2486 {
2487 case GL_VENDOR:
2488 return reinterpret_cast<const GLubyte *>("Google Inc.");
2489
2490 case GL_RENDERER:
2491 return reinterpret_cast<const GLubyte *>(mRendererString);
2492
2493 case GL_VERSION:
2494 return reinterpret_cast<const GLubyte *>(mVersionString);
2495
2496 case GL_SHADING_LANGUAGE_VERSION:
2497 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
2498
2499 case GL_EXTENSIONS:
2500 return reinterpret_cast<const GLubyte *>(mExtensionString);
2501
2502 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2503 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
2504
2505 default:
2506 UNREACHABLE();
2507 return nullptr;
2508 }
Geoff Langcec35902014-04-16 10:52:36 -04002509}
2510
Geoff Langc339c4e2016-11-29 10:37:36 -05002511const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04002512{
Geoff Langc339c4e2016-11-29 10:37:36 -05002513 switch (name)
2514 {
2515 case GL_EXTENSIONS:
2516 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
2517
2518 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2519 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
2520
2521 default:
2522 UNREACHABLE();
2523 return nullptr;
2524 }
Geoff Langcec35902014-04-16 10:52:36 -04002525}
2526
2527size_t Context::getExtensionStringCount() const
2528{
2529 return mExtensionStrings.size();
2530}
2531
Geoff Lang111a99e2017-10-17 10:58:41 -04002532bool Context::isExtensionRequestable(const char *name)
2533{
2534 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2535 auto extension = extensionInfos.find(name);
2536
2537 const Extensions &nativeExtensions = mImplementation->getNativeExtensions();
2538 return extension != extensionInfos.end() && extension->second.Requestable &&
2539 nativeExtensions.*(extension->second.ExtensionsMember);
2540}
2541
Geoff Langc339c4e2016-11-29 10:37:36 -05002542void Context::requestExtension(const char *name)
2543{
2544 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2545 ASSERT(extensionInfos.find(name) != extensionInfos.end());
2546 const auto &extension = extensionInfos.at(name);
2547 ASSERT(extension.Requestable);
Geoff Lang111a99e2017-10-17 10:58:41 -04002548 ASSERT(mImplementation->getNativeExtensions().*(extension.ExtensionsMember));
Geoff Langc339c4e2016-11-29 10:37:36 -05002549
2550 if (mExtensions.*(extension.ExtensionsMember))
2551 {
2552 // Extension already enabled
2553 return;
2554 }
2555
2556 mExtensions.*(extension.ExtensionsMember) = true;
2557 updateCaps();
2558 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08002559
Jamie Madill2f348d22017-06-05 10:50:59 -04002560 // Release the shader compiler so it will be re-created with the requested extensions enabled.
2561 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04002562
Jamie Madill81c2e252017-09-09 23:32:46 -04002563 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
2564 // sampleable.
2565 mState.mTextures->signalAllTexturesDirty();
Geoff Lang9aded172017-04-05 11:07:56 -04002566 for (auto &zeroTexture : mZeroTextures)
2567 {
Jamie Madill05b35b22017-10-03 09:01:44 -04002568 zeroTexture.second->signalDirty(InitState::Initialized);
Geoff Lang9aded172017-04-05 11:07:56 -04002569 }
2570
2571 mState.mFramebuffers->invalidateFramebufferComplenessCache();
Geoff Langc339c4e2016-11-29 10:37:36 -05002572}
2573
2574size_t Context::getRequestableExtensionStringCount() const
2575{
2576 return mRequestableExtensionStrings.size();
2577}
2578
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002579void Context::beginTransformFeedback(GLenum primitiveMode)
2580{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002581 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002582 ASSERT(transformFeedback != nullptr);
2583 ASSERT(!transformFeedback->isPaused());
2584
Jamie Madill6c1f6712017-02-14 19:08:04 -05002585 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002586}
2587
2588bool Context::hasActiveTransformFeedback(GLuint program) const
2589{
2590 for (auto pair : mTransformFeedbackMap)
2591 {
2592 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
2593 {
2594 return true;
2595 }
2596 }
2597 return false;
2598}
2599
Geoff Langb433e872017-10-05 14:01:47 -04002600void Context::initCaps(const egl::DisplayExtensions &displayExtensions, bool robustResourceInit)
Geoff Lang493daf52014-07-03 13:38:44 -04002601{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002602 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04002603
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002604 mExtensions = mImplementation->getNativeExtensions();
Geoff Lang493daf52014-07-03 13:38:44 -04002605
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002606 mLimitations = mImplementation->getNativeLimitations();
Austin Kinross02df7962015-07-01 10:03:42 -07002607
Geoff Langeb66a6e2016-10-31 13:06:12 -04002608 if (getClientVersion() < Version(3, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002609 {
2610 // Disable ES3+ extensions
Jamie Madill231c7f52017-04-26 13:45:37 -04002611 mExtensions.colorBufferFloat = false;
Geoff Langb66a9092016-05-16 15:59:14 -04002612 mExtensions.eglImageExternalEssl3 = false;
Vincent Lang25ab4512016-05-13 18:13:59 +02002613 mExtensions.textureNorm16 = false;
Martin Radev137032d2017-07-13 10:11:12 +03002614 mExtensions.multiview = false;
2615 mExtensions.maxViews = 1u;
Geoff Lang493daf52014-07-03 13:38:44 -04002616 }
2617
Jiawei Shao89be29a2017-11-06 14:36:45 +08002618 if (getClientVersion() < ES_3_1)
2619 {
2620 // Disable ES3.1+ extensions
2621 mExtensions.geometryShader = false;
2622 }
2623
Geoff Langeb66a6e2016-10-31 13:06:12 -04002624 if (getClientVersion() > Version(2, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002625 {
2626 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
Jamie Madill231c7f52017-04-26 13:45:37 -04002627 // mExtensions.sRGB = false;
Geoff Lang493daf52014-07-03 13:38:44 -04002628 }
2629
Jamie Madill00ed7a12016-05-19 13:13:38 -04002630 // Some extensions are always available because they are implemented in the GL layer.
Jamie Madill231c7f52017-04-26 13:45:37 -04002631 mExtensions.bindUniformLocation = true;
2632 mExtensions.vertexArrayObject = true;
Geoff Langf41a7152016-09-19 15:11:17 -04002633 mExtensions.bindGeneratesResource = true;
Geoff Langfeb8c682017-02-13 16:07:35 -05002634 mExtensions.clientArrays = true;
Geoff Langc339c4e2016-11-29 10:37:36 -05002635 mExtensions.requestExtension = true;
Jamie Madill00ed7a12016-05-19 13:13:38 -04002636
2637 // Enable the no error extension if the context was created with the flag.
2638 mExtensions.noError = mSkipValidation;
2639
Corentin Wallezccab69d2017-01-27 16:57:15 -05002640 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Corentin Wallezc295e512017-01-27 17:47:50 -05002641 mExtensions.surfacelessContext = displayExtensions.surfacelessContext;
Corentin Wallezccab69d2017-01-27 16:57:15 -05002642
Geoff Lang70d0f492015-12-10 17:45:46 -05002643 // Explicitly enable GL_KHR_debug
2644 mExtensions.debug = true;
2645 mExtensions.maxDebugMessageLength = 1024;
2646 mExtensions.maxDebugLoggedMessages = 1024;
2647 mExtensions.maxDebugGroupStackDepth = 1024;
2648 mExtensions.maxLabelLength = 1024;
2649
Geoff Langff5b2d52016-09-07 11:32:23 -04002650 // Explicitly enable GL_ANGLE_robust_client_memory
2651 mExtensions.robustClientMemory = true;
2652
Jamie Madille08a1d32017-03-07 17:24:06 -05002653 // Determine robust resource init availability from EGL.
Geoff Langb433e872017-10-05 14:01:47 -04002654 mExtensions.robustResourceInitialization = robustResourceInit;
Jamie Madille08a1d32017-03-07 17:24:06 -05002655
Jiajia Qin8a7b3a02017-08-25 16:05:48 +08002656 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
2657 // supports it.
2658 mExtensions.robustBufferAccessBehavior =
2659 mRobustAccess && mExtensions.robustBufferAccessBehavior;
2660
Jamie Madillc43be722017-07-13 16:22:14 -04002661 // Enable the cache control query unconditionally.
2662 mExtensions.programCacheControl = true;
2663
Geoff Lang301d1612014-07-09 10:34:37 -04002664 // Apply implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04002665 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002666
Jamie Madill0f80ed82017-09-19 00:24:56 -04002667 if (getClientVersion() < ES_3_1)
2668 {
2669 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
2670 }
2671 else
2672 {
2673 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
2674 }
Geoff Lang301d1612014-07-09 10:34:37 -04002675
Jamie Madill0f80ed82017-09-19 00:24:56 -04002676 LimitCap(&mCaps.maxVertexUniformBlocks, IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
2677 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
2678 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
2679
2680 // Limit textures as well, so we can use fast bitsets with texture bindings.
2681 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
2682 LimitCap(&mCaps.maxVertexTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
2683 LimitCap(&mCaps.maxTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04002684
Jiawei Shaodb342272017-09-27 10:21:45 +08002685 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
2686
Geoff Langc287ea62016-09-16 14:46:51 -04002687 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002688 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04002689 for (const auto &extensionInfo : GetExtensionInfoMap())
2690 {
2691 // If this context is for WebGL, disable all enableable extensions
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002692 if (mWebGLContext && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04002693 {
2694 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
2695 }
2696 }
2697
2698 // Generate texture caps
2699 updateCaps();
2700}
2701
2702void Context::updateCaps()
2703{
Geoff Lang900013c2014-07-07 11:32:19 -04002704 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002705 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04002706
Jamie Madill7b62cf92017-11-02 15:20:49 -04002707 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04002708 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04002709 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04002710 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04002711
Geoff Lang0d8b7242015-09-09 14:56:53 -04002712 // Update the format caps based on the client version and extensions.
2713 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
2714 // ES3.
2715 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002716 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002717 formatCaps.renderable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002718 formatCaps.renderable && formatInfo.renderSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002719 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002720 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04002721
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002722 // OpenGL ES does not support multisampling with non-rendererable formats
2723 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Olli Etuaho50c562d2017-06-06 14:43:30 +03002724 if (!formatCaps.renderable ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002725 (getClientVersion() < ES_3_1 &&
2726 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04002727 {
Geoff Langd87878e2014-09-19 15:42:59 -04002728 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04002729 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03002730 else
2731 {
2732 // We may have limited the max samples for some required renderbuffer formats due to
2733 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
2734 GLuint formatMaxSamples = formatCaps.getMaxSamples();
2735
2736 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
2737 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
2738 // exception of signed and unsigned integer formats."
2739 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
2740 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
2741 {
2742 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
2743 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
2744 }
2745
2746 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
2747 if (getClientVersion() >= ES_3_1)
2748 {
2749 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
2750 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
2751 // the exception that the signed and unsigned integer formats are required only to
2752 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
2753 // multisamples, which must be at least one."
2754 if (formatInfo.componentType == GL_INT ||
2755 formatInfo.componentType == GL_UNSIGNED_INT)
2756 {
2757 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
2758 }
2759
2760 // GLES 3.1 section 19.3.1.
2761 if (formatCaps.texturable)
2762 {
2763 if (formatInfo.depthBits > 0)
2764 {
2765 mCaps.maxDepthTextureSamples =
2766 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
2767 }
2768 else if (formatInfo.redBits > 0)
2769 {
2770 mCaps.maxColorTextureSamples =
2771 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
2772 }
2773 }
2774 }
2775 }
Geoff Langd87878e2014-09-19 15:42:59 -04002776
2777 if (formatCaps.texturable && formatInfo.compressed)
2778 {
Geoff Langca271392017-04-05 12:30:00 -04002779 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04002780 }
2781
Geoff Langca271392017-04-05 12:30:00 -04002782 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04002783 }
Jamie Madill32447362017-06-28 14:53:52 -04002784
2785 // If program binary is disabled, blank out the memory cache pointer.
2786 if (!mImplementation->getNativeExtensions().getProgramBinary)
2787 {
2788 mMemoryProgramCache = nullptr;
2789 }
Corentin Walleze4477002017-12-01 14:39:58 -05002790
2791 // Compute which buffer types are allowed
2792 mValidBufferBindings.reset();
2793 mValidBufferBindings.set(BufferBinding::ElementArray);
2794 mValidBufferBindings.set(BufferBinding::Array);
2795
2796 if (mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
2797 {
2798 mValidBufferBindings.set(BufferBinding::PixelPack);
2799 mValidBufferBindings.set(BufferBinding::PixelUnpack);
2800 }
2801
2802 if (getClientVersion() >= ES_3_0)
2803 {
2804 mValidBufferBindings.set(BufferBinding::CopyRead);
2805 mValidBufferBindings.set(BufferBinding::CopyWrite);
2806 mValidBufferBindings.set(BufferBinding::TransformFeedback);
2807 mValidBufferBindings.set(BufferBinding::Uniform);
2808 }
2809
2810 if (getClientVersion() >= ES_3_1)
2811 {
2812 mValidBufferBindings.set(BufferBinding::AtomicCounter);
2813 mValidBufferBindings.set(BufferBinding::ShaderStorage);
2814 mValidBufferBindings.set(BufferBinding::DrawIndirect);
2815 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
2816 }
Geoff Lang493daf52014-07-03 13:38:44 -04002817}
2818
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002819void Context::initWorkarounds()
2820{
Jamie Madill761b02c2017-06-23 16:27:06 -04002821 // Apply back-end workarounds.
2822 mImplementation->applyNativeWorkarounds(&mWorkarounds);
2823
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002824 // Lose the context upon out of memory error if the application is
2825 // expecting to watch for those events.
2826 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2827}
2828
Jamie Madill05b35b22017-10-03 09:01:44 -04002829Error Context::prepareForDraw()
2830{
2831 syncRendererState();
Jamie Madilla59fc192017-11-02 12:57:58 -04002832
2833 if (isRobustResourceInitEnabled())
2834 {
2835 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
2836 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
2837 }
2838
Jamie Madill05b35b22017-10-03 09:01:44 -04002839 return NoError();
2840}
2841
Jamie Madill1b94d432015-08-07 13:23:23 -04002842void Context::syncRendererState()
2843{
Jamie Madill7d1f5c62017-09-02 15:32:15 -04002844 mGLState.syncDirtyObjects(this);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002845 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
Jamie Madillfe548342017-06-19 11:13:24 -04002846 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002847 mGLState.clearDirtyBits();
Jamie Madill1b94d432015-08-07 13:23:23 -04002848}
2849
Jamie Madillad9f24e2016-02-12 09:27:24 -05002850void Context::syncRendererState(const State::DirtyBits &bitMask,
2851 const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04002852{
Jamie Madill7d1f5c62017-09-02 15:32:15 -04002853 mGLState.syncDirtyObjects(this, objectMask);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002854 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madillfe548342017-06-19 11:13:24 -04002855 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002856 mGLState.clearDirtyBits(dirtyBits);
Jamie Madill1b94d432015-08-07 13:23:23 -04002857}
Jamie Madillc29968b2016-01-20 11:17:23 -05002858
2859void Context::blitFramebuffer(GLint srcX0,
2860 GLint srcY0,
2861 GLint srcX1,
2862 GLint srcY1,
2863 GLint dstX0,
2864 GLint dstY0,
2865 GLint dstX1,
2866 GLint dstY1,
2867 GLbitfield mask,
2868 GLenum filter)
2869{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002870 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002871 ASSERT(drawFramebuffer);
2872
2873 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
2874 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
2875
Jamie Madillad9f24e2016-02-12 09:27:24 -05002876 syncStateForBlit();
Jamie Madillc29968b2016-01-20 11:17:23 -05002877
Jamie Madillc564c072017-06-01 12:45:42 -04002878 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002879}
Jamie Madillc29968b2016-01-20 11:17:23 -05002880
2881void Context::clear(GLbitfield mask)
2882{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002883 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002884 handleError(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05002885}
2886
2887void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
2888{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002889 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002890 handleError(mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002891}
2892
2893void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
2894{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002895 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002896 handleError(mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002897}
2898
2899void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
2900{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002901 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002902 handleError(mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002903}
2904
2905void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
2906{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002907 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002908 ASSERT(framebufferObject);
2909
2910 // If a buffer is not present, the clear has no effect
2911 if (framebufferObject->getDepthbuffer() == nullptr &&
2912 framebufferObject->getStencilbuffer() == nullptr)
2913 {
2914 return;
2915 }
2916
Jamie Madillad9f24e2016-02-12 09:27:24 -05002917 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002918 handleError(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05002919}
2920
2921void Context::readPixels(GLint x,
2922 GLint y,
2923 GLsizei width,
2924 GLsizei height,
2925 GLenum format,
2926 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002927 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05002928{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04002929 if (width == 0 || height == 0)
2930 {
2931 return;
2932 }
2933
Jamie Madillad9f24e2016-02-12 09:27:24 -05002934 syncStateForReadPixels();
Jamie Madillc29968b2016-01-20 11:17:23 -05002935
Jamie Madillb6664922017-07-25 12:55:04 -04002936 Framebuffer *readFBO = mGLState.getReadFramebuffer();
2937 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05002938
2939 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04002940 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05002941}
2942
2943void Context::copyTexImage2D(GLenum target,
2944 GLint level,
2945 GLenum internalformat,
2946 GLint x,
2947 GLint y,
2948 GLsizei width,
2949 GLsizei height,
2950 GLint border)
2951{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002952 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002953 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002954
Jamie Madillc29968b2016-01-20 11:17:23 -05002955 Rectangle sourceArea(x, y, width, height);
2956
Jamie Madill05b35b22017-10-03 09:01:44 -04002957 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002958 Texture *texture =
2959 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05002960 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05002961}
2962
2963void Context::copyTexSubImage2D(GLenum target,
2964 GLint level,
2965 GLint xoffset,
2966 GLint yoffset,
2967 GLint x,
2968 GLint y,
2969 GLsizei width,
2970 GLsizei height)
2971{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04002972 if (width == 0 || height == 0)
2973 {
2974 return;
2975 }
2976
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002977 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002978 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002979
Jamie Madillc29968b2016-01-20 11:17:23 -05002980 Offset destOffset(xoffset, yoffset, 0);
2981 Rectangle sourceArea(x, y, width, height);
2982
Jamie Madill05b35b22017-10-03 09:01:44 -04002983 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002984 Texture *texture =
2985 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05002986 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05002987}
2988
2989void Context::copyTexSubImage3D(GLenum target,
2990 GLint level,
2991 GLint xoffset,
2992 GLint yoffset,
2993 GLint zoffset,
2994 GLint x,
2995 GLint y,
2996 GLsizei width,
2997 GLsizei height)
2998{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04002999 if (width == 0 || height == 0)
3000 {
3001 return;
3002 }
3003
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003004 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003005 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003006
Jamie Madillc29968b2016-01-20 11:17:23 -05003007 Offset destOffset(xoffset, yoffset, zoffset);
3008 Rectangle sourceArea(x, y, width, height);
3009
Jamie Madill05b35b22017-10-03 09:01:44 -04003010 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3011 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003012 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003013}
3014
3015void Context::framebufferTexture2D(GLenum target,
3016 GLenum attachment,
3017 GLenum textarget,
3018 GLuint texture,
3019 GLint level)
3020{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003021 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003022 ASSERT(framebuffer);
3023
3024 if (texture != 0)
3025 {
3026 Texture *textureObj = getTexture(texture);
3027
3028 ImageIndex index = ImageIndex::MakeInvalid();
3029
3030 if (textarget == GL_TEXTURE_2D)
3031 {
3032 index = ImageIndex::Make2D(level);
3033 }
Corentin Wallez13c0dd42017-07-04 18:27:01 -04003034 else if (textarget == GL_TEXTURE_RECTANGLE_ANGLE)
3035 {
3036 index = ImageIndex::MakeRectangle(level);
3037 }
JiangYizhoubddc46b2016-12-09 09:50:51 +08003038 else if (textarget == GL_TEXTURE_2D_MULTISAMPLE)
3039 {
3040 ASSERT(level == 0);
3041 index = ImageIndex::Make2DMultisample();
3042 }
Jamie Madillc29968b2016-01-20 11:17:23 -05003043 else
3044 {
3045 ASSERT(IsCubeMapTextureTarget(textarget));
3046 index = ImageIndex::MakeCube(textarget, level);
3047 }
3048
Jamie Madilla02315b2017-02-23 14:14:47 -05003049 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003050 }
3051 else
3052 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003053 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003054 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003055
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003056 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003057}
3058
3059void Context::framebufferRenderbuffer(GLenum target,
3060 GLenum attachment,
3061 GLenum renderbuffertarget,
3062 GLuint renderbuffer)
3063{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003064 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003065 ASSERT(framebuffer);
3066
3067 if (renderbuffer != 0)
3068 {
3069 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003070
3071 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex::MakeInvalid(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003072 renderbufferObject);
3073 }
3074 else
3075 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003076 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003077 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003078
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003079 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003080}
3081
3082void Context::framebufferTextureLayer(GLenum target,
3083 GLenum attachment,
3084 GLuint texture,
3085 GLint level,
3086 GLint layer)
3087{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003088 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003089 ASSERT(framebuffer);
3090
3091 if (texture != 0)
3092 {
3093 Texture *textureObject = getTexture(texture);
3094
3095 ImageIndex index = ImageIndex::MakeInvalid();
3096
3097 if (textureObject->getTarget() == GL_TEXTURE_3D)
3098 {
3099 index = ImageIndex::Make3D(level, layer);
3100 }
3101 else
3102 {
3103 ASSERT(textureObject->getTarget() == GL_TEXTURE_2D_ARRAY);
3104 index = ImageIndex::Make2DArray(level, layer);
3105 }
3106
Jamie Madilla02315b2017-02-23 14:14:47 -05003107 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003108 }
3109 else
3110 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003111 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003112 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003113
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003114 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003115}
3116
Martin Radev137032d2017-07-13 10:11:12 +03003117void Context::framebufferTextureMultiviewLayeredANGLE(GLenum target,
3118 GLenum attachment,
3119 GLuint texture,
3120 GLint level,
3121 GLint baseViewIndex,
3122 GLsizei numViews)
3123{
Martin Radev82ef7742017-08-08 17:44:58 +03003124 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3125 ASSERT(framebuffer);
3126
3127 if (texture != 0)
3128 {
3129 Texture *textureObj = getTexture(texture);
3130
Martin Radev18b75ba2017-08-15 15:50:40 +03003131 ImageIndex index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
Martin Radev82ef7742017-08-08 17:44:58 +03003132 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3133 numViews, baseViewIndex);
3134 }
3135 else
3136 {
3137 framebuffer->resetAttachment(this, attachment);
3138 }
3139
3140 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003141}
3142
3143void Context::framebufferTextureMultiviewSideBySideANGLE(GLenum target,
3144 GLenum attachment,
3145 GLuint texture,
3146 GLint level,
3147 GLsizei numViews,
3148 const GLint *viewportOffsets)
3149{
Martin Radev5dae57b2017-07-14 16:15:55 +03003150 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3151 ASSERT(framebuffer);
3152
3153 if (texture != 0)
3154 {
3155 Texture *textureObj = getTexture(texture);
3156
3157 ImageIndex index = ImageIndex::Make2D(level);
3158 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3159 textureObj, numViews, viewportOffsets);
3160 }
3161 else
3162 {
3163 framebuffer->resetAttachment(this, attachment);
3164 }
3165
3166 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003167}
3168
Jamie Madillc29968b2016-01-20 11:17:23 -05003169void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3170{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003171 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003172 ASSERT(framebuffer);
3173 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003174 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003175}
3176
3177void Context::readBuffer(GLenum mode)
3178{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003179 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003180 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003181 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003182}
3183
3184void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3185{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003186 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003187 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003188
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003189 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003190 ASSERT(framebuffer);
3191
3192 // The specification isn't clear what should be done when the framebuffer isn't complete.
3193 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003194 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003195}
3196
3197void Context::invalidateFramebuffer(GLenum target,
3198 GLsizei numAttachments,
3199 const GLenum *attachments)
3200{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003201 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003202 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003203
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003204 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003205 ASSERT(framebuffer);
3206
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003207 if (framebuffer->checkStatus(this) != GL_FRAMEBUFFER_COMPLETE)
Jamie Madillc29968b2016-01-20 11:17:23 -05003208 {
Jamie Madill437fa652016-05-03 15:13:24 -04003209 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003210 }
Jamie Madill437fa652016-05-03 15:13:24 -04003211
Jamie Madill4928b7c2017-06-20 12:57:39 -04003212 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003213}
3214
3215void Context::invalidateSubFramebuffer(GLenum target,
3216 GLsizei numAttachments,
3217 const GLenum *attachments,
3218 GLint x,
3219 GLint y,
3220 GLsizei width,
3221 GLsizei height)
3222{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003223 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003224 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003225
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003226 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003227 ASSERT(framebuffer);
3228
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003229 if (framebuffer->checkStatus(this) != GL_FRAMEBUFFER_COMPLETE)
Jamie Madillc29968b2016-01-20 11:17:23 -05003230 {
Jamie Madill437fa652016-05-03 15:13:24 -04003231 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003232 }
Jamie Madill437fa652016-05-03 15:13:24 -04003233
3234 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003235 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003236}
3237
Jamie Madill73a84962016-02-12 09:27:23 -05003238void Context::texImage2D(GLenum target,
3239 GLint level,
3240 GLint internalformat,
3241 GLsizei width,
3242 GLsizei height,
3243 GLint border,
3244 GLenum format,
3245 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003246 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003247{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003248 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003249
3250 Extents size(width, height, 1);
3251 Texture *texture =
3252 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003253 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3254 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003255}
3256
3257void Context::texImage3D(GLenum target,
3258 GLint level,
3259 GLint internalformat,
3260 GLsizei width,
3261 GLsizei height,
3262 GLsizei depth,
3263 GLint border,
3264 GLenum format,
3265 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003266 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003267{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003268 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003269
3270 Extents size(width, height, depth);
3271 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003272 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3273 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003274}
3275
3276void Context::texSubImage2D(GLenum target,
3277 GLint level,
3278 GLint xoffset,
3279 GLint yoffset,
3280 GLsizei width,
3281 GLsizei height,
3282 GLenum format,
3283 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003284 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003285{
3286 // Zero sized uploads are valid but no-ops
3287 if (width == 0 || height == 0)
3288 {
3289 return;
3290 }
3291
Jamie Madillad9f24e2016-02-12 09:27:24 -05003292 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003293
3294 Box area(xoffset, yoffset, 0, width, height, 1);
3295 Texture *texture =
3296 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003297 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3298 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003299}
3300
3301void Context::texSubImage3D(GLenum target,
3302 GLint level,
3303 GLint xoffset,
3304 GLint yoffset,
3305 GLint zoffset,
3306 GLsizei width,
3307 GLsizei height,
3308 GLsizei depth,
3309 GLenum format,
3310 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003311 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003312{
3313 // Zero sized uploads are valid but no-ops
3314 if (width == 0 || height == 0 || depth == 0)
3315 {
3316 return;
3317 }
3318
Jamie Madillad9f24e2016-02-12 09:27:24 -05003319 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003320
3321 Box area(xoffset, yoffset, zoffset, width, height, depth);
3322 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003323 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3324 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003325}
3326
3327void Context::compressedTexImage2D(GLenum target,
3328 GLint level,
3329 GLenum internalformat,
3330 GLsizei width,
3331 GLsizei height,
3332 GLint border,
3333 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003334 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003335{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003336 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003337
3338 Extents size(width, height, 1);
3339 Texture *texture =
3340 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003341 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003342 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003343 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003344}
3345
3346void Context::compressedTexImage3D(GLenum target,
3347 GLint level,
3348 GLenum internalformat,
3349 GLsizei width,
3350 GLsizei height,
3351 GLsizei depth,
3352 GLint border,
3353 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003354 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003355{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003356 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003357
3358 Extents size(width, height, depth);
3359 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003360 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003361 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003362 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003363}
3364
3365void Context::compressedTexSubImage2D(GLenum target,
3366 GLint level,
3367 GLint xoffset,
3368 GLint yoffset,
3369 GLsizei width,
3370 GLsizei height,
3371 GLenum format,
3372 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003373 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003374{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003375 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003376
3377 Box area(xoffset, yoffset, 0, width, height, 1);
3378 Texture *texture =
3379 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003380 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003381 format, imageSize,
3382 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003383}
3384
3385void Context::compressedTexSubImage3D(GLenum target,
3386 GLint level,
3387 GLint xoffset,
3388 GLint yoffset,
3389 GLint zoffset,
3390 GLsizei width,
3391 GLsizei height,
3392 GLsizei depth,
3393 GLenum format,
3394 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003395 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003396{
3397 // Zero sized uploads are valid but no-ops
3398 if (width == 0 || height == 0)
3399 {
3400 return;
3401 }
3402
Jamie Madillad9f24e2016-02-12 09:27:24 -05003403 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003404
3405 Box area(xoffset, yoffset, zoffset, width, height, depth);
3406 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003407 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003408 format, imageSize,
3409 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003410}
3411
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003412void Context::generateMipmap(GLenum target)
3413{
3414 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003415 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003416}
3417
Geoff Lang97073d12016-04-20 10:42:34 -07003418void Context::copyTextureCHROMIUM(GLuint sourceId,
Geoff Langfc72a072017-03-24 14:52:39 -04003419 GLint sourceLevel,
3420 GLenum destTarget,
Geoff Lang97073d12016-04-20 10:42:34 -07003421 GLuint destId,
Geoff Langfc72a072017-03-24 14:52:39 -04003422 GLint destLevel,
Geoff Lang97073d12016-04-20 10:42:34 -07003423 GLint internalFormat,
3424 GLenum destType,
3425 GLboolean unpackFlipY,
3426 GLboolean unpackPremultiplyAlpha,
3427 GLboolean unpackUnmultiplyAlpha)
3428{
3429 syncStateForTexImage();
3430
3431 gl::Texture *sourceTexture = getTexture(sourceId);
3432 gl::Texture *destTexture = getTexture(destId);
Geoff Lang92019432017-11-20 13:09:34 -05003433 handleError(destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType,
3434 sourceLevel, ConvertToBool(unpackFlipY),
3435 ConvertToBool(unpackPremultiplyAlpha),
3436 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003437}
3438
3439void Context::copySubTextureCHROMIUM(GLuint sourceId,
Geoff Langfc72a072017-03-24 14:52:39 -04003440 GLint sourceLevel,
3441 GLenum destTarget,
Geoff Lang97073d12016-04-20 10:42:34 -07003442 GLuint destId,
Geoff Langfc72a072017-03-24 14:52:39 -04003443 GLint destLevel,
Geoff Lang97073d12016-04-20 10:42:34 -07003444 GLint xoffset,
3445 GLint yoffset,
3446 GLint x,
3447 GLint y,
3448 GLsizei width,
3449 GLsizei height,
3450 GLboolean unpackFlipY,
3451 GLboolean unpackPremultiplyAlpha,
3452 GLboolean unpackUnmultiplyAlpha)
3453{
3454 // Zero sized copies are valid but no-ops
3455 if (width == 0 || height == 0)
3456 {
3457 return;
3458 }
3459
3460 syncStateForTexImage();
3461
3462 gl::Texture *sourceTexture = getTexture(sourceId);
3463 gl::Texture *destTexture = getTexture(destId);
3464 Offset offset(xoffset, yoffset, 0);
3465 Rectangle area(x, y, width, height);
Geoff Lang92019432017-11-20 13:09:34 -05003466 handleError(destTexture->copySubTexture(this, destTarget, destLevel, offset, sourceLevel, area,
3467 ConvertToBool(unpackFlipY),
3468 ConvertToBool(unpackPremultiplyAlpha),
3469 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003470}
3471
Geoff Lang47110bf2016-04-20 11:13:22 -07003472void Context::compressedCopyTextureCHROMIUM(GLuint sourceId, GLuint destId)
3473{
3474 syncStateForTexImage();
3475
3476 gl::Texture *sourceTexture = getTexture(sourceId);
3477 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05003478 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07003479}
3480
Corentin Wallez336129f2017-10-17 15:55:40 -04003481void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03003482{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003483 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003484 ASSERT(buffer);
3485
Geoff Lang496c02d2016-10-20 11:38:11 -07003486 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03003487}
3488
Corentin Wallez336129f2017-10-17 15:55:40 -04003489void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003490{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003491 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003492 ASSERT(buffer);
3493
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003494 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003495 if (error.isError())
3496 {
Jamie Madill437fa652016-05-03 15:13:24 -04003497 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003498 return nullptr;
3499 }
3500
3501 return buffer->getMapPointer();
3502}
3503
Corentin Wallez336129f2017-10-17 15:55:40 -04003504GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03003505{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003506 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003507 ASSERT(buffer);
3508
3509 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003510 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03003511 if (error.isError())
3512 {
Jamie Madill437fa652016-05-03 15:13:24 -04003513 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003514 return GL_FALSE;
3515 }
3516
3517 return result;
3518}
3519
Corentin Wallez336129f2017-10-17 15:55:40 -04003520void *Context::mapBufferRange(BufferBinding target,
3521 GLintptr offset,
3522 GLsizeiptr length,
3523 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003524{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003525 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003526 ASSERT(buffer);
3527
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003528 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003529 if (error.isError())
3530 {
Jamie Madill437fa652016-05-03 15:13:24 -04003531 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003532 return nullptr;
3533 }
3534
3535 return buffer->getMapPointer();
3536}
3537
Corentin Wallez336129f2017-10-17 15:55:40 -04003538void Context::flushMappedBufferRange(BufferBinding /*target*/,
3539 GLintptr /*offset*/,
3540 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03003541{
3542 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
3543}
3544
Jamie Madillad9f24e2016-02-12 09:27:24 -05003545void Context::syncStateForReadPixels()
3546{
3547 syncRendererState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
3548}
3549
3550void Context::syncStateForTexImage()
3551{
3552 syncRendererState(mTexImageDirtyBits, mTexImageDirtyObjects);
3553}
3554
3555void Context::syncStateForClear()
3556{
3557 syncRendererState(mClearDirtyBits, mClearDirtyObjects);
3558}
3559
3560void Context::syncStateForBlit()
3561{
3562 syncRendererState(mBlitDirtyBits, mBlitDirtyObjects);
3563}
3564
Jiajia Qin5451d532017-11-16 17:16:34 +08003565void Context::activeShaderProgram(GLuint pipeline, GLuint program)
3566{
3567 UNIMPLEMENTED();
3568}
3569
Jamie Madillc20ab272016-06-09 07:20:46 -07003570void Context::activeTexture(GLenum texture)
3571{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003572 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003573}
3574
Jamie Madill876429b2017-04-20 15:46:24 -04003575void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003576{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003577 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07003578}
3579
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003580void Context::blendEquation(GLenum mode)
3581{
3582 mGLState.setBlendEquation(mode, mode);
3583}
3584
Jamie Madillc20ab272016-06-09 07:20:46 -07003585void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
3586{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003587 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003588}
3589
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003590void Context::blendFunc(GLenum sfactor, GLenum dfactor)
3591{
3592 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
3593}
3594
Jamie Madillc20ab272016-06-09 07:20:46 -07003595void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
3596{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003597 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003598}
3599
Jamie Madill876429b2017-04-20 15:46:24 -04003600void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003601{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003602 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003603}
3604
Jamie Madill876429b2017-04-20 15:46:24 -04003605void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07003606{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003607 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07003608}
3609
3610void Context::clearStencil(GLint s)
3611{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003612 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07003613}
3614
3615void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
3616{
Geoff Lang92019432017-11-20 13:09:34 -05003617 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
3618 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07003619}
3620
Corentin Wallez2e568cf2017-09-18 17:05:22 -04003621void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07003622{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003623 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003624}
3625
3626void Context::depthFunc(GLenum func)
3627{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003628 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07003629}
3630
3631void Context::depthMask(GLboolean flag)
3632{
Geoff Lang92019432017-11-20 13:09:34 -05003633 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07003634}
3635
Jamie Madill876429b2017-04-20 15:46:24 -04003636void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07003637{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003638 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07003639}
3640
3641void Context::disable(GLenum cap)
3642{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003643 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003644}
3645
3646void Context::disableVertexAttribArray(GLuint index)
3647{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003648 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003649}
3650
3651void Context::enable(GLenum cap)
3652{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003653 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003654}
3655
3656void Context::enableVertexAttribArray(GLuint index)
3657{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003658 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003659}
3660
3661void Context::frontFace(GLenum mode)
3662{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003663 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003664}
3665
3666void Context::hint(GLenum target, GLenum mode)
3667{
3668 switch (target)
3669 {
3670 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003671 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003672 break;
3673
3674 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003675 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003676 break;
3677
3678 default:
3679 UNREACHABLE();
3680 return;
3681 }
3682}
3683
3684void Context::lineWidth(GLfloat width)
3685{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003686 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07003687}
3688
3689void Context::pixelStorei(GLenum pname, GLint param)
3690{
3691 switch (pname)
3692 {
3693 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003694 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003695 break;
3696
3697 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003698 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003699 break;
3700
3701 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003702 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003703 break;
3704
3705 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003706 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003707 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003708 break;
3709
3710 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03003711 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003712 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003713 break;
3714
3715 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03003716 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003717 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003718 break;
3719
3720 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003721 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003722 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003723 break;
3724
3725 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003726 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003727 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003728 break;
3729
3730 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003731 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003732 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003733 break;
3734
3735 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003736 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003737 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003738 break;
3739
3740 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003741 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003742 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003743 break;
3744
3745 default:
3746 UNREACHABLE();
3747 return;
3748 }
3749}
3750
3751void Context::polygonOffset(GLfloat factor, GLfloat units)
3752{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003753 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07003754}
3755
Jamie Madill876429b2017-04-20 15:46:24 -04003756void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07003757{
Geoff Lang92019432017-11-20 13:09:34 -05003758 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07003759}
3760
Jiawei Shaodb342272017-09-27 10:21:45 +08003761void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
3762{
3763 mGLState.setSampleMaskParams(maskNumber, mask);
3764}
3765
Jamie Madillc20ab272016-06-09 07:20:46 -07003766void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
3767{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003768 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07003769}
3770
3771void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
3772{
3773 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3774 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003775 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003776 }
3777
3778 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3779 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003780 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003781 }
3782}
3783
3784void Context::stencilMaskSeparate(GLenum face, GLuint mask)
3785{
3786 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3787 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003788 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003789 }
3790
3791 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3792 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003793 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003794 }
3795}
3796
3797void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
3798{
3799 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3800 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003801 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003802 }
3803
3804 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3805 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003806 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003807 }
3808}
3809
3810void Context::vertexAttrib1f(GLuint index, GLfloat x)
3811{
3812 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003813 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003814}
3815
3816void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
3817{
3818 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003819 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003820}
3821
3822void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
3823{
3824 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003825 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003826}
3827
3828void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
3829{
3830 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003831 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003832}
3833
3834void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
3835{
3836 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003837 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003838}
3839
3840void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
3841{
3842 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003843 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003844}
3845
3846void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
3847{
3848 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003849 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003850}
3851
3852void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
3853{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003854 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07003855}
3856
3857void Context::vertexAttribPointer(GLuint index,
3858 GLint size,
3859 GLenum type,
3860 GLboolean normalized,
3861 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04003862 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07003863{
Corentin Wallez336129f2017-10-17 15:55:40 -04003864 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05003865 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc20ab272016-06-09 07:20:46 -07003866}
3867
Shao80957d92017-02-20 21:25:59 +08003868void Context::vertexAttribFormat(GLuint attribIndex,
3869 GLint size,
3870 GLenum type,
3871 GLboolean normalized,
3872 GLuint relativeOffset)
3873{
Geoff Lang92019432017-11-20 13:09:34 -05003874 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08003875 relativeOffset);
3876}
3877
3878void Context::vertexAttribIFormat(GLuint attribIndex,
3879 GLint size,
3880 GLenum type,
3881 GLuint relativeOffset)
3882{
3883 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
3884}
3885
3886void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
3887{
Shaodde78e82017-05-22 14:13:27 +08003888 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Shao80957d92017-02-20 21:25:59 +08003889}
3890
Jiajia Qin5451d532017-11-16 17:16:34 +08003891void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08003892{
3893 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
3894}
3895
Jamie Madillc20ab272016-06-09 07:20:46 -07003896void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
3897{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003898 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07003899}
3900
3901void Context::vertexAttribIPointer(GLuint index,
3902 GLint size,
3903 GLenum type,
3904 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04003905 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07003906{
Corentin Wallez336129f2017-10-17 15:55:40 -04003907 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
3908 size, type, false, true, stride, pointer);
Jamie Madillc20ab272016-06-09 07:20:46 -07003909}
3910
3911void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
3912{
3913 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003914 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003915}
3916
3917void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
3918{
3919 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003920 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003921}
3922
3923void Context::vertexAttribI4iv(GLuint index, const GLint *v)
3924{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003925 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07003926}
3927
3928void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
3929{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003930 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07003931}
3932
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003933void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
3934{
3935 const VertexAttribCurrentValueData &currentValues =
3936 getGLState().getVertexAttribCurrentValue(index);
3937 const VertexArray *vao = getGLState().getVertexArray();
3938 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3939 currentValues, pname, params);
3940}
3941
3942void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
3943{
3944 const VertexAttribCurrentValueData &currentValues =
3945 getGLState().getVertexAttribCurrentValue(index);
3946 const VertexArray *vao = getGLState().getVertexArray();
3947 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3948 currentValues, pname, params);
3949}
3950
3951void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
3952{
3953 const VertexAttribCurrentValueData &currentValues =
3954 getGLState().getVertexAttribCurrentValue(index);
3955 const VertexArray *vao = getGLState().getVertexArray();
3956 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3957 currentValues, pname, params);
3958}
3959
3960void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
3961{
3962 const VertexAttribCurrentValueData &currentValues =
3963 getGLState().getVertexAttribCurrentValue(index);
3964 const VertexArray *vao = getGLState().getVertexArray();
3965 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3966 currentValues, pname, params);
3967}
3968
Jamie Madill876429b2017-04-20 15:46:24 -04003969void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003970{
3971 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
3972 QueryVertexAttribPointerv(attrib, pname, pointer);
3973}
3974
Jamie Madillc20ab272016-06-09 07:20:46 -07003975void Context::debugMessageControl(GLenum source,
3976 GLenum type,
3977 GLenum severity,
3978 GLsizei count,
3979 const GLuint *ids,
3980 GLboolean enabled)
3981{
3982 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003983 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05003984 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07003985}
3986
3987void Context::debugMessageInsert(GLenum source,
3988 GLenum type,
3989 GLuint id,
3990 GLenum severity,
3991 GLsizei length,
3992 const GLchar *buf)
3993{
3994 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003995 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07003996}
3997
3998void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
3999{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004000 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004001}
4002
4003GLuint Context::getDebugMessageLog(GLuint count,
4004 GLsizei bufSize,
4005 GLenum *sources,
4006 GLenum *types,
4007 GLuint *ids,
4008 GLenum *severities,
4009 GLsizei *lengths,
4010 GLchar *messageLog)
4011{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004012 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4013 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004014}
4015
4016void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4017{
4018 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004019 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05004020 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07004021}
4022
4023void Context::popDebugGroup()
4024{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004025 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05004026 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004027}
4028
Corentin Wallez336129f2017-10-17 15:55:40 -04004029void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004030{
4031 Buffer *buffer = mGLState.getTargetBuffer(target);
4032 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004033 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004034}
4035
Corentin Wallez336129f2017-10-17 15:55:40 -04004036void Context::bufferSubData(BufferBinding target,
4037 GLintptr offset,
4038 GLsizeiptr size,
4039 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004040{
4041 if (data == nullptr)
4042 {
4043 return;
4044 }
4045
4046 Buffer *buffer = mGLState.getTargetBuffer(target);
4047 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004048 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004049}
4050
Jamie Madillef300b12016-10-07 15:12:09 -04004051void Context::attachShader(GLuint program, GLuint shader)
4052{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05004053 Program *programObject = mState.mShaderPrograms->getProgram(program);
4054 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004055 ASSERT(programObject && shaderObject);
4056 programObject->attachShader(shaderObject);
4057}
4058
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004059const Workarounds &Context::getWorkarounds() const
4060{
4061 return mWorkarounds;
4062}
4063
Corentin Wallez336129f2017-10-17 15:55:40 -04004064void Context::copyBufferSubData(BufferBinding readTarget,
4065 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04004066 GLintptr readOffset,
4067 GLintptr writeOffset,
4068 GLsizeiptr size)
4069{
4070 // if size is zero, the copy is a successful no-op
4071 if (size == 0)
4072 {
4073 return;
4074 }
4075
4076 // TODO(jmadill): cache these.
4077 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4078 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4079
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004080 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004081}
4082
Jamie Madill01a80ee2016-11-07 12:06:18 -05004083void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4084{
4085 Program *programObject = getProgram(program);
4086 // TODO(jmadill): Re-use this from the validation if possible.
4087 ASSERT(programObject);
4088 programObject->bindAttributeLocation(index, name);
4089}
4090
Corentin Wallez336129f2017-10-17 15:55:40 -04004091void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004092{
Corentin Wallez336129f2017-10-17 15:55:40 -04004093 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4094 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004095}
4096
Corentin Wallez336129f2017-10-17 15:55:40 -04004097void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08004098{
4099 bindBufferRange(target, index, buffer, 0, 0);
4100}
4101
Corentin Wallez336129f2017-10-17 15:55:40 -04004102void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08004103 GLuint index,
4104 GLuint buffer,
4105 GLintptr offset,
4106 GLsizeiptr size)
4107{
Corentin Wallez336129f2017-10-17 15:55:40 -04004108 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4109 mGLState.setIndexedBufferBinding(this, target, index, bufferObject, offset, size);
Jiajia Qin6eafb042016-12-27 17:04:07 +08004110}
4111
Jamie Madill01a80ee2016-11-07 12:06:18 -05004112void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
4113{
4114 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4115 {
4116 bindReadFramebuffer(framebuffer);
4117 }
4118
4119 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4120 {
4121 bindDrawFramebuffer(framebuffer);
4122 }
4123}
4124
4125void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4126{
4127 ASSERT(target == GL_RENDERBUFFER);
4128 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004129 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04004130 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004131}
4132
JiangYizhoubddc46b2016-12-09 09:50:51 +08004133void Context::texStorage2DMultisample(GLenum target,
4134 GLsizei samples,
4135 GLenum internalformat,
4136 GLsizei width,
4137 GLsizei height,
4138 GLboolean fixedsamplelocations)
4139{
4140 Extents size(width, height, 1);
4141 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05004142 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
Geoff Lang92019432017-11-20 13:09:34 -05004143 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004144}
4145
4146void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4147{
JiangYizhou5b03f472017-01-09 10:22:53 +08004148 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
4149 // the sample position should be queried by DRAW_FRAMEBUFFER.
4150 mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER);
4151 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08004152
4153 switch (pname)
4154 {
4155 case GL_SAMPLE_POSITION:
4156 handleError(framebuffer->getSamplePosition(index, val));
4157 break;
4158 default:
4159 UNREACHABLE();
4160 }
4161}
4162
Jamie Madille8fb6402017-02-14 17:56:40 -05004163void Context::renderbufferStorage(GLenum target,
4164 GLenum internalformat,
4165 GLsizei width,
4166 GLsizei height)
4167{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004168 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4169 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
4170
Jamie Madille8fb6402017-02-14 17:56:40 -05004171 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04004172 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004173}
4174
4175void Context::renderbufferStorageMultisample(GLenum target,
4176 GLsizei samples,
4177 GLenum internalformat,
4178 GLsizei width,
4179 GLsizei height)
4180{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004181 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4182 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05004183
4184 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004185 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04004186 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004187}
4188
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004189void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
4190{
Jamie Madill70b5bb02017-08-28 13:32:37 -04004191 const Sync *syncObject = getSync(sync);
Geoff Lang82483b92017-04-11 15:33:00 -04004192 handleError(QuerySynciv(syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004193}
4194
JiangYizhoue18e6392017-02-20 10:32:23 +08004195void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
4196{
4197 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4198 QueryFramebufferParameteriv(framebuffer, pname, params);
4199}
4200
Jiajia Qin5451d532017-11-16 17:16:34 +08004201void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08004202{
4203 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4204 SetFramebufferParameteri(framebuffer, pname, param);
4205}
4206
Jamie Madillb3f26b92017-07-19 15:07:41 -04004207Error Context::getScratchBuffer(size_t requstedSizeBytes,
4208 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05004209{
Jamie Madillb3f26b92017-07-19 15:07:41 -04004210 if (!mScratchBuffer.get(requstedSizeBytes, scratchBufferOut))
4211 {
4212 return OutOfMemory() << "Failed to allocate internal buffer.";
4213 }
4214 return NoError();
4215}
4216
4217Error Context::getZeroFilledBuffer(size_t requstedSizeBytes,
4218 angle::MemoryBuffer **zeroBufferOut) const
4219{
4220 if (!mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0))
Jamie Madille14951e2017-03-09 18:55:16 -05004221 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004222 return OutOfMemory() << "Failed to allocate internal buffer.";
Jamie Madille14951e2017-03-09 18:55:16 -05004223 }
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004224 return NoError();
Jamie Madille14951e2017-03-09 18:55:16 -05004225}
4226
Xinghua Cao10a4d432017-11-28 14:46:26 +08004227Error Context::prepareForDispatch()
4228{
4229 syncRendererState(mComputeDirtyBits, mComputeDirtyObjects);
4230
4231 if (isRobustResourceInitEnabled())
4232 {
4233 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
4234 }
4235
4236 return NoError();
4237}
4238
Xinghua Cao2b396592017-03-29 15:36:04 +08004239void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
4240{
4241 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
4242 {
4243 return;
4244 }
4245
Xinghua Cao10a4d432017-11-28 14:46:26 +08004246 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill71c88b32017-09-14 22:20:29 -04004247 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08004248}
4249
Jiajia Qin5451d532017-11-16 17:16:34 +08004250void Context::dispatchComputeIndirect(GLintptr indirect)
4251{
4252 UNIMPLEMENTED();
4253}
4254
JiangYizhou165361c2017-06-07 14:56:57 +08004255void Context::texStorage2D(GLenum target,
4256 GLsizei levels,
4257 GLenum internalFormat,
4258 GLsizei width,
4259 GLsizei height)
4260{
4261 Extents size(width, height, 1);
4262 Texture *texture = getTargetTexture(target);
4263 handleError(texture->setStorage(this, target, levels, internalFormat, size));
4264}
4265
4266void Context::texStorage3D(GLenum target,
4267 GLsizei levels,
4268 GLenum internalFormat,
4269 GLsizei width,
4270 GLsizei height,
4271 GLsizei depth)
4272{
4273 Extents size(width, height, depth);
4274 Texture *texture = getTargetTexture(target);
4275 handleError(texture->setStorage(this, target, levels, internalFormat, size));
4276}
4277
Jiajia Qin5451d532017-11-16 17:16:34 +08004278void Context::memoryBarrier(GLbitfield barriers)
4279{
4280 UNIMPLEMENTED();
4281}
4282
4283void Context::memoryBarrierByRegion(GLbitfield barriers)
4284{
4285 UNIMPLEMENTED();
4286}
4287
Jamie Madillc1d770e2017-04-13 17:31:24 -04004288GLenum Context::checkFramebufferStatus(GLenum target)
4289{
4290 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4291 ASSERT(framebuffer);
4292
4293 return framebuffer->checkStatus(this);
4294}
4295
4296void Context::compileShader(GLuint shader)
4297{
4298 Shader *shaderObject = GetValidShader(this, shader);
4299 if (!shaderObject)
4300 {
4301 return;
4302 }
4303 shaderObject->compile(this);
4304}
4305
4306void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
4307{
4308 for (int i = 0; i < n; i++)
4309 {
4310 deleteBuffer(buffers[i]);
4311 }
4312}
4313
4314void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
4315{
4316 for (int i = 0; i < n; i++)
4317 {
4318 if (framebuffers[i] != 0)
4319 {
4320 deleteFramebuffer(framebuffers[i]);
4321 }
4322 }
4323}
4324
4325void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
4326{
4327 for (int i = 0; i < n; i++)
4328 {
4329 deleteRenderbuffer(renderbuffers[i]);
4330 }
4331}
4332
4333void Context::deleteTextures(GLsizei n, const GLuint *textures)
4334{
4335 for (int i = 0; i < n; i++)
4336 {
4337 if (textures[i] != 0)
4338 {
4339 deleteTexture(textures[i]);
4340 }
4341 }
4342}
4343
4344void Context::detachShader(GLuint program, GLuint shader)
4345{
4346 Program *programObject = getProgram(program);
4347 ASSERT(programObject);
4348
4349 Shader *shaderObject = getShader(shader);
4350 ASSERT(shaderObject);
4351
4352 programObject->detachShader(this, shaderObject);
4353}
4354
4355void Context::genBuffers(GLsizei n, GLuint *buffers)
4356{
4357 for (int i = 0; i < n; i++)
4358 {
4359 buffers[i] = createBuffer();
4360 }
4361}
4362
4363void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
4364{
4365 for (int i = 0; i < n; i++)
4366 {
4367 framebuffers[i] = createFramebuffer();
4368 }
4369}
4370
4371void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
4372{
4373 for (int i = 0; i < n; i++)
4374 {
4375 renderbuffers[i] = createRenderbuffer();
4376 }
4377}
4378
4379void Context::genTextures(GLsizei n, GLuint *textures)
4380{
4381 for (int i = 0; i < n; i++)
4382 {
4383 textures[i] = createTexture();
4384 }
4385}
4386
4387void Context::getActiveAttrib(GLuint program,
4388 GLuint index,
4389 GLsizei bufsize,
4390 GLsizei *length,
4391 GLint *size,
4392 GLenum *type,
4393 GLchar *name)
4394{
4395 Program *programObject = getProgram(program);
4396 ASSERT(programObject);
4397 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
4398}
4399
4400void Context::getActiveUniform(GLuint program,
4401 GLuint index,
4402 GLsizei bufsize,
4403 GLsizei *length,
4404 GLint *size,
4405 GLenum *type,
4406 GLchar *name)
4407{
4408 Program *programObject = getProgram(program);
4409 ASSERT(programObject);
4410 programObject->getActiveUniform(index, bufsize, length, size, type, name);
4411}
4412
4413void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
4414{
4415 Program *programObject = getProgram(program);
4416 ASSERT(programObject);
4417 programObject->getAttachedShaders(maxcount, count, shaders);
4418}
4419
4420GLint Context::getAttribLocation(GLuint program, const GLchar *name)
4421{
4422 Program *programObject = getProgram(program);
4423 ASSERT(programObject);
4424 return programObject->getAttributeLocation(name);
4425}
4426
4427void Context::getBooleanv(GLenum pname, GLboolean *params)
4428{
4429 GLenum nativeType;
4430 unsigned int numParams = 0;
4431 getQueryParameterInfo(pname, &nativeType, &numParams);
4432
4433 if (nativeType == GL_BOOL)
4434 {
4435 getBooleanvImpl(pname, params);
4436 }
4437 else
4438 {
4439 CastStateValues(this, nativeType, pname, numParams, params);
4440 }
4441}
4442
4443void Context::getFloatv(GLenum pname, GLfloat *params)
4444{
4445 GLenum nativeType;
4446 unsigned int numParams = 0;
4447 getQueryParameterInfo(pname, &nativeType, &numParams);
4448
4449 if (nativeType == GL_FLOAT)
4450 {
4451 getFloatvImpl(pname, params);
4452 }
4453 else
4454 {
4455 CastStateValues(this, nativeType, pname, numParams, params);
4456 }
4457}
4458
4459void Context::getIntegerv(GLenum pname, GLint *params)
4460{
4461 GLenum nativeType;
4462 unsigned int numParams = 0;
4463 getQueryParameterInfo(pname, &nativeType, &numParams);
4464
4465 if (nativeType == GL_INT)
4466 {
4467 getIntegervImpl(pname, params);
4468 }
4469 else
4470 {
4471 CastStateValues(this, nativeType, pname, numParams, params);
4472 }
4473}
4474
4475void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
4476{
4477 Program *programObject = getProgram(program);
4478 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04004479 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004480}
4481
Jiajia Qin5451d532017-11-16 17:16:34 +08004482void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
4483{
4484 UNIMPLEMENTED();
4485}
4486
Jamie Madillbe849e42017-05-02 15:49:00 -04004487void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04004488{
4489 Program *programObject = getProgram(program);
4490 ASSERT(programObject);
4491 programObject->getInfoLog(bufsize, length, infolog);
4492}
4493
Jiajia Qin5451d532017-11-16 17:16:34 +08004494void Context::getProgramPipelineInfoLog(GLuint pipeline,
4495 GLsizei bufSize,
4496 GLsizei *length,
4497 GLchar *infoLog)
4498{
4499 UNIMPLEMENTED();
4500}
4501
Jamie Madillc1d770e2017-04-13 17:31:24 -04004502void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
4503{
4504 Shader *shaderObject = getShader(shader);
4505 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004506 QueryShaderiv(this, shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004507}
4508
4509void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
4510{
4511 Shader *shaderObject = getShader(shader);
4512 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004513 shaderObject->getInfoLog(this, bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004514}
4515
4516void Context::getShaderPrecisionFormat(GLenum shadertype,
4517 GLenum precisiontype,
4518 GLint *range,
4519 GLint *precision)
4520{
4521 // TODO(jmadill): Compute shaders.
4522
4523 switch (shadertype)
4524 {
4525 case GL_VERTEX_SHADER:
4526 switch (precisiontype)
4527 {
4528 case GL_LOW_FLOAT:
4529 mCaps.vertexLowpFloat.get(range, precision);
4530 break;
4531 case GL_MEDIUM_FLOAT:
4532 mCaps.vertexMediumpFloat.get(range, precision);
4533 break;
4534 case GL_HIGH_FLOAT:
4535 mCaps.vertexHighpFloat.get(range, precision);
4536 break;
4537
4538 case GL_LOW_INT:
4539 mCaps.vertexLowpInt.get(range, precision);
4540 break;
4541 case GL_MEDIUM_INT:
4542 mCaps.vertexMediumpInt.get(range, precision);
4543 break;
4544 case GL_HIGH_INT:
4545 mCaps.vertexHighpInt.get(range, precision);
4546 break;
4547
4548 default:
4549 UNREACHABLE();
4550 return;
4551 }
4552 break;
4553
4554 case GL_FRAGMENT_SHADER:
4555 switch (precisiontype)
4556 {
4557 case GL_LOW_FLOAT:
4558 mCaps.fragmentLowpFloat.get(range, precision);
4559 break;
4560 case GL_MEDIUM_FLOAT:
4561 mCaps.fragmentMediumpFloat.get(range, precision);
4562 break;
4563 case GL_HIGH_FLOAT:
4564 mCaps.fragmentHighpFloat.get(range, precision);
4565 break;
4566
4567 case GL_LOW_INT:
4568 mCaps.fragmentLowpInt.get(range, precision);
4569 break;
4570 case GL_MEDIUM_INT:
4571 mCaps.fragmentMediumpInt.get(range, precision);
4572 break;
4573 case GL_HIGH_INT:
4574 mCaps.fragmentHighpInt.get(range, precision);
4575 break;
4576
4577 default:
4578 UNREACHABLE();
4579 return;
4580 }
4581 break;
4582
4583 default:
4584 UNREACHABLE();
4585 return;
4586 }
4587}
4588
4589void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
4590{
4591 Shader *shaderObject = getShader(shader);
4592 ASSERT(shaderObject);
4593 shaderObject->getSource(bufsize, length, source);
4594}
4595
4596void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
4597{
4598 Program *programObject = getProgram(program);
4599 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04004600 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004601}
4602
4603void Context::getUniformiv(GLuint program, GLint location, GLint *params)
4604{
4605 Program *programObject = getProgram(program);
4606 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04004607 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004608}
4609
4610GLint Context::getUniformLocation(GLuint program, const GLchar *name)
4611{
4612 Program *programObject = getProgram(program);
4613 ASSERT(programObject);
4614 return programObject->getUniformLocation(name);
4615}
4616
4617GLboolean Context::isBuffer(GLuint buffer)
4618{
4619 if (buffer == 0)
4620 {
4621 return GL_FALSE;
4622 }
4623
4624 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
4625}
4626
4627GLboolean Context::isEnabled(GLenum cap)
4628{
4629 return mGLState.getEnableFeature(cap);
4630}
4631
4632GLboolean Context::isFramebuffer(GLuint framebuffer)
4633{
4634 if (framebuffer == 0)
4635 {
4636 return GL_FALSE;
4637 }
4638
4639 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
4640}
4641
4642GLboolean Context::isProgram(GLuint program)
4643{
4644 if (program == 0)
4645 {
4646 return GL_FALSE;
4647 }
4648
4649 return (getProgram(program) ? GL_TRUE : GL_FALSE);
4650}
4651
4652GLboolean Context::isRenderbuffer(GLuint renderbuffer)
4653{
4654 if (renderbuffer == 0)
4655 {
4656 return GL_FALSE;
4657 }
4658
4659 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
4660}
4661
4662GLboolean Context::isShader(GLuint shader)
4663{
4664 if (shader == 0)
4665 {
4666 return GL_FALSE;
4667 }
4668
4669 return (getShader(shader) ? GL_TRUE : GL_FALSE);
4670}
4671
4672GLboolean Context::isTexture(GLuint texture)
4673{
4674 if (texture == 0)
4675 {
4676 return GL_FALSE;
4677 }
4678
4679 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
4680}
4681
4682void Context::linkProgram(GLuint program)
4683{
4684 Program *programObject = getProgram(program);
4685 ASSERT(programObject);
4686 handleError(programObject->link(this));
Martin Radev0abb7a22017-08-28 15:34:45 +03004687 mGLState.onProgramExecutableChange(programObject);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004688}
4689
4690void Context::releaseShaderCompiler()
4691{
Jamie Madill4928b7c2017-06-20 12:57:39 -04004692 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004693}
4694
4695void Context::shaderBinary(GLsizei n,
4696 const GLuint *shaders,
4697 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04004698 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04004699 GLsizei length)
4700{
4701 // No binary shader formats are supported.
4702 UNIMPLEMENTED();
4703}
4704
4705void Context::shaderSource(GLuint shader,
4706 GLsizei count,
4707 const GLchar *const *string,
4708 const GLint *length)
4709{
4710 Shader *shaderObject = getShader(shader);
4711 ASSERT(shaderObject);
4712 shaderObject->setSource(count, string, length);
4713}
4714
4715void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
4716{
4717 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
4718}
4719
4720void Context::stencilMask(GLuint mask)
4721{
4722 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
4723}
4724
4725void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
4726{
4727 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
4728}
4729
4730void Context::uniform1f(GLint location, GLfloat x)
4731{
4732 Program *program = mGLState.getProgram();
4733 program->setUniform1fv(location, 1, &x);
4734}
4735
4736void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
4737{
4738 Program *program = mGLState.getProgram();
4739 program->setUniform1fv(location, count, v);
4740}
4741
4742void Context::uniform1i(GLint location, GLint x)
4743{
4744 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04004745 if (program->setUniform1iv(location, 1, &x) == Program::SetUniformResult::SamplerChanged)
4746 {
4747 mGLState.setObjectDirty(GL_PROGRAM);
4748 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04004749}
4750
4751void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
4752{
4753 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04004754 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
4755 {
4756 mGLState.setObjectDirty(GL_PROGRAM);
4757 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04004758}
4759
4760void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
4761{
4762 GLfloat xy[2] = {x, y};
4763 Program *program = mGLState.getProgram();
4764 program->setUniform2fv(location, 1, xy);
4765}
4766
4767void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
4768{
4769 Program *program = mGLState.getProgram();
4770 program->setUniform2fv(location, count, v);
4771}
4772
4773void Context::uniform2i(GLint location, GLint x, GLint y)
4774{
4775 GLint xy[2] = {x, y};
4776 Program *program = mGLState.getProgram();
4777 program->setUniform2iv(location, 1, xy);
4778}
4779
4780void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
4781{
4782 Program *program = mGLState.getProgram();
4783 program->setUniform2iv(location, count, v);
4784}
4785
4786void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
4787{
4788 GLfloat xyz[3] = {x, y, z};
4789 Program *program = mGLState.getProgram();
4790 program->setUniform3fv(location, 1, xyz);
4791}
4792
4793void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
4794{
4795 Program *program = mGLState.getProgram();
4796 program->setUniform3fv(location, count, v);
4797}
4798
4799void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
4800{
4801 GLint xyz[3] = {x, y, z};
4802 Program *program = mGLState.getProgram();
4803 program->setUniform3iv(location, 1, xyz);
4804}
4805
4806void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
4807{
4808 Program *program = mGLState.getProgram();
4809 program->setUniform3iv(location, count, v);
4810}
4811
4812void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4813{
4814 GLfloat xyzw[4] = {x, y, z, w};
4815 Program *program = mGLState.getProgram();
4816 program->setUniform4fv(location, 1, xyzw);
4817}
4818
4819void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
4820{
4821 Program *program = mGLState.getProgram();
4822 program->setUniform4fv(location, count, v);
4823}
4824
4825void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
4826{
4827 GLint xyzw[4] = {x, y, z, w};
4828 Program *program = mGLState.getProgram();
4829 program->setUniform4iv(location, 1, xyzw);
4830}
4831
4832void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
4833{
4834 Program *program = mGLState.getProgram();
4835 program->setUniform4iv(location, count, v);
4836}
4837
4838void Context::uniformMatrix2fv(GLint location,
4839 GLsizei count,
4840 GLboolean transpose,
4841 const GLfloat *value)
4842{
4843 Program *program = mGLState.getProgram();
4844 program->setUniformMatrix2fv(location, count, transpose, value);
4845}
4846
4847void Context::uniformMatrix3fv(GLint location,
4848 GLsizei count,
4849 GLboolean transpose,
4850 const GLfloat *value)
4851{
4852 Program *program = mGLState.getProgram();
4853 program->setUniformMatrix3fv(location, count, transpose, value);
4854}
4855
4856void Context::uniformMatrix4fv(GLint location,
4857 GLsizei count,
4858 GLboolean transpose,
4859 const GLfloat *value)
4860{
4861 Program *program = mGLState.getProgram();
4862 program->setUniformMatrix4fv(location, count, transpose, value);
4863}
4864
4865void Context::validateProgram(GLuint program)
4866{
4867 Program *programObject = getProgram(program);
4868 ASSERT(programObject);
4869 programObject->validate(mCaps);
4870}
4871
Jiajia Qin5451d532017-11-16 17:16:34 +08004872void Context::validateProgramPipeline(GLuint pipeline)
4873{
4874 UNIMPLEMENTED();
4875}
4876
Jamie Madilld04908b2017-06-09 14:15:35 -04004877void Context::getProgramBinary(GLuint program,
4878 GLsizei bufSize,
4879 GLsizei *length,
4880 GLenum *binaryFormat,
4881 void *binary)
4882{
4883 Program *programObject = getProgram(program);
4884 ASSERT(programObject != nullptr);
4885
4886 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
4887}
4888
4889void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
4890{
4891 Program *programObject = getProgram(program);
4892 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04004893
Jamie Madilld04908b2017-06-09 14:15:35 -04004894 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
4895}
4896
Jamie Madillff325f12017-08-26 15:06:05 -04004897void Context::uniform1ui(GLint location, GLuint v0)
4898{
4899 Program *program = mGLState.getProgram();
4900 program->setUniform1uiv(location, 1, &v0);
4901}
4902
4903void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
4904{
4905 Program *program = mGLState.getProgram();
4906 const GLuint xy[] = {v0, v1};
4907 program->setUniform2uiv(location, 1, xy);
4908}
4909
4910void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
4911{
4912 Program *program = mGLState.getProgram();
4913 const GLuint xyz[] = {v0, v1, v2};
4914 program->setUniform3uiv(location, 1, xyz);
4915}
4916
4917void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
4918{
4919 Program *program = mGLState.getProgram();
4920 const GLuint xyzw[] = {v0, v1, v2, v3};
4921 program->setUniform4uiv(location, 1, xyzw);
4922}
4923
4924void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
4925{
4926 Program *program = mGLState.getProgram();
4927 program->setUniform1uiv(location, count, value);
4928}
4929void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
4930{
4931 Program *program = mGLState.getProgram();
4932 program->setUniform2uiv(location, count, value);
4933}
4934
4935void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
4936{
4937 Program *program = mGLState.getProgram();
4938 program->setUniform3uiv(location, count, value);
4939}
4940
4941void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
4942{
4943 Program *program = mGLState.getProgram();
4944 program->setUniform4uiv(location, count, value);
4945}
4946
Jamie Madillf0e04492017-08-26 15:28:42 -04004947void Context::genQueries(GLsizei n, GLuint *ids)
4948{
4949 for (GLsizei i = 0; i < n; i++)
4950 {
4951 GLuint handle = mQueryHandleAllocator.allocate();
4952 mQueryMap.assign(handle, nullptr);
4953 ids[i] = handle;
4954 }
4955}
4956
4957void Context::deleteQueries(GLsizei n, const GLuint *ids)
4958{
4959 for (int i = 0; i < n; i++)
4960 {
4961 GLuint query = ids[i];
4962
4963 Query *queryObject = nullptr;
4964 if (mQueryMap.erase(query, &queryObject))
4965 {
4966 mQueryHandleAllocator.release(query);
4967 if (queryObject)
4968 {
4969 queryObject->release(this);
4970 }
4971 }
4972 }
4973}
4974
4975GLboolean Context::isQuery(GLuint id)
4976{
4977 return (getQuery(id, false, GL_NONE) != nullptr) ? GL_TRUE : GL_FALSE;
4978}
4979
Jamie Madillc8c95812017-08-26 18:40:09 -04004980void Context::uniformMatrix2x3fv(GLint location,
4981 GLsizei count,
4982 GLboolean transpose,
4983 const GLfloat *value)
4984{
4985 Program *program = mGLState.getProgram();
4986 program->setUniformMatrix2x3fv(location, count, transpose, value);
4987}
4988
4989void Context::uniformMatrix3x2fv(GLint location,
4990 GLsizei count,
4991 GLboolean transpose,
4992 const GLfloat *value)
4993{
4994 Program *program = mGLState.getProgram();
4995 program->setUniformMatrix3x2fv(location, count, transpose, value);
4996}
4997
4998void Context::uniformMatrix2x4fv(GLint location,
4999 GLsizei count,
5000 GLboolean transpose,
5001 const GLfloat *value)
5002{
5003 Program *program = mGLState.getProgram();
5004 program->setUniformMatrix2x4fv(location, count, transpose, value);
5005}
5006
5007void Context::uniformMatrix4x2fv(GLint location,
5008 GLsizei count,
5009 GLboolean transpose,
5010 const GLfloat *value)
5011{
5012 Program *program = mGLState.getProgram();
5013 program->setUniformMatrix4x2fv(location, count, transpose, value);
5014}
5015
5016void Context::uniformMatrix3x4fv(GLint location,
5017 GLsizei count,
5018 GLboolean transpose,
5019 const GLfloat *value)
5020{
5021 Program *program = mGLState.getProgram();
5022 program->setUniformMatrix3x4fv(location, count, transpose, value);
5023}
5024
5025void Context::uniformMatrix4x3fv(GLint location,
5026 GLsizei count,
5027 GLboolean transpose,
5028 const GLfloat *value)
5029{
5030 Program *program = mGLState.getProgram();
5031 program->setUniformMatrix4x3fv(location, count, transpose, value);
5032}
5033
Jamie Madilld7576732017-08-26 18:49:50 -04005034void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
5035{
5036 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5037 {
5038 GLuint vertexArray = arrays[arrayIndex];
5039
5040 if (arrays[arrayIndex] != 0)
5041 {
5042 VertexArray *vertexArrayObject = nullptr;
5043 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
5044 {
5045 if (vertexArrayObject != nullptr)
5046 {
5047 detachVertexArray(vertexArray);
5048 vertexArrayObject->onDestroy(this);
5049 }
5050
5051 mVertexArrayHandleAllocator.release(vertexArray);
5052 }
5053 }
5054 }
5055}
5056
5057void Context::genVertexArrays(GLsizei n, GLuint *arrays)
5058{
5059 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5060 {
5061 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
5062 mVertexArrayMap.assign(vertexArray, nullptr);
5063 arrays[arrayIndex] = vertexArray;
5064 }
5065}
5066
5067bool Context::isVertexArray(GLuint array)
5068{
5069 if (array == 0)
5070 {
5071 return GL_FALSE;
5072 }
5073
5074 VertexArray *vao = getVertexArray(array);
5075 return (vao != nullptr ? GL_TRUE : GL_FALSE);
5076}
5077
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04005078void Context::endTransformFeedback()
5079{
5080 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5081 transformFeedback->end(this);
5082}
5083
5084void Context::transformFeedbackVaryings(GLuint program,
5085 GLsizei count,
5086 const GLchar *const *varyings,
5087 GLenum bufferMode)
5088{
5089 Program *programObject = getProgram(program);
5090 ASSERT(programObject);
5091 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
5092}
5093
5094void Context::getTransformFeedbackVarying(GLuint program,
5095 GLuint index,
5096 GLsizei bufSize,
5097 GLsizei *length,
5098 GLsizei *size,
5099 GLenum *type,
5100 GLchar *name)
5101{
5102 Program *programObject = getProgram(program);
5103 ASSERT(programObject);
5104 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
5105}
5106
5107void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
5108{
5109 for (int i = 0; i < n; i++)
5110 {
5111 GLuint transformFeedback = ids[i];
5112 if (transformFeedback == 0)
5113 {
5114 continue;
5115 }
5116
5117 TransformFeedback *transformFeedbackObject = nullptr;
5118 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
5119 {
5120 if (transformFeedbackObject != nullptr)
5121 {
5122 detachTransformFeedback(transformFeedback);
5123 transformFeedbackObject->release(this);
5124 }
5125
5126 mTransformFeedbackHandleAllocator.release(transformFeedback);
5127 }
5128 }
5129}
5130
5131void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
5132{
5133 for (int i = 0; i < n; i++)
5134 {
5135 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
5136 mTransformFeedbackMap.assign(transformFeedback, nullptr);
5137 ids[i] = transformFeedback;
5138 }
5139}
5140
5141bool Context::isTransformFeedback(GLuint id)
5142{
5143 if (id == 0)
5144 {
5145 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
5146 // returns FALSE
5147 return GL_FALSE;
5148 }
5149
5150 const TransformFeedback *transformFeedback = getTransformFeedback(id);
5151 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
5152}
5153
5154void Context::pauseTransformFeedback()
5155{
5156 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5157 transformFeedback->pause();
5158}
5159
5160void Context::resumeTransformFeedback()
5161{
5162 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5163 transformFeedback->resume();
5164}
5165
Jamie Madill12e957f2017-08-26 21:42:26 -04005166void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
5167{
5168 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04005169 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04005170}
5171
5172GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
5173{
5174 const Program *programObject = getProgram(program);
5175 return programObject->getFragDataLocation(name);
5176}
5177
5178void Context::getUniformIndices(GLuint program,
5179 GLsizei uniformCount,
5180 const GLchar *const *uniformNames,
5181 GLuint *uniformIndices)
5182{
5183 const Program *programObject = getProgram(program);
5184 if (!programObject->isLinked())
5185 {
5186 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5187 {
5188 uniformIndices[uniformId] = GL_INVALID_INDEX;
5189 }
5190 }
5191 else
5192 {
5193 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5194 {
5195 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
5196 }
5197 }
5198}
5199
5200void Context::getActiveUniformsiv(GLuint program,
5201 GLsizei uniformCount,
5202 const GLuint *uniformIndices,
5203 GLenum pname,
5204 GLint *params)
5205{
5206 const Program *programObject = getProgram(program);
5207 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5208 {
5209 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08005210 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04005211 }
5212}
5213
5214GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
5215{
5216 const Program *programObject = getProgram(program);
5217 return programObject->getUniformBlockIndex(uniformBlockName);
5218}
5219
5220void Context::getActiveUniformBlockiv(GLuint program,
5221 GLuint uniformBlockIndex,
5222 GLenum pname,
5223 GLint *params)
5224{
5225 const Program *programObject = getProgram(program);
5226 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
5227}
5228
5229void Context::getActiveUniformBlockName(GLuint program,
5230 GLuint uniformBlockIndex,
5231 GLsizei bufSize,
5232 GLsizei *length,
5233 GLchar *uniformBlockName)
5234{
5235 const Program *programObject = getProgram(program);
5236 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
5237}
5238
5239void Context::uniformBlockBinding(GLuint program,
5240 GLuint uniformBlockIndex,
5241 GLuint uniformBlockBinding)
5242{
5243 Program *programObject = getProgram(program);
5244 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
5245}
5246
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005247GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
5248{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005249 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
5250 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005251
Jamie Madill70b5bb02017-08-28 13:32:37 -04005252 Sync *syncObject = getSync(syncHandle);
5253 Error error = syncObject->set(condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005254 if (error.isError())
5255 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04005256 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005257 handleError(error);
5258 return nullptr;
5259 }
5260
Jamie Madill70b5bb02017-08-28 13:32:37 -04005261 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005262}
5263
5264GLboolean Context::isSync(GLsync sync)
5265{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005266 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005267}
5268
5269GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
5270{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005271 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005272
5273 GLenum result = GL_WAIT_FAILED;
5274 handleError(syncObject->clientWait(flags, timeout, &result));
5275 return result;
5276}
5277
5278void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
5279{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005280 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005281 handleError(syncObject->serverWait(flags, timeout));
5282}
5283
5284void Context::getInteger64v(GLenum pname, GLint64 *params)
5285{
5286 GLenum nativeType = GL_NONE;
5287 unsigned int numParams = 0;
5288 getQueryParameterInfo(pname, &nativeType, &numParams);
5289
5290 if (nativeType == GL_INT_64_ANGLEX)
5291 {
5292 getInteger64vImpl(pname, params);
5293 }
5294 else
5295 {
5296 CastStateValues(this, nativeType, pname, numParams, params);
5297 }
5298}
5299
Corentin Wallez336129f2017-10-17 15:55:40 -04005300void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04005301{
5302 Buffer *buffer = mGLState.getTargetBuffer(target);
5303 QueryBufferParameteri64v(buffer, pname, params);
5304}
5305
5306void Context::genSamplers(GLsizei count, GLuint *samplers)
5307{
5308 for (int i = 0; i < count; i++)
5309 {
5310 samplers[i] = mState.mSamplers->createSampler();
5311 }
5312}
5313
5314void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
5315{
5316 for (int i = 0; i < count; i++)
5317 {
5318 GLuint sampler = samplers[i];
5319
5320 if (mState.mSamplers->getSampler(sampler))
5321 {
5322 detachSampler(sampler);
5323 }
5324
5325 mState.mSamplers->deleteObject(this, sampler);
5326 }
5327}
5328
5329void Context::getInternalformativ(GLenum target,
5330 GLenum internalformat,
5331 GLenum pname,
5332 GLsizei bufSize,
5333 GLint *params)
5334{
5335 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
5336 QueryInternalFormativ(formatCaps, pname, bufSize, params);
5337}
5338
Jiajia Qin5451d532017-11-16 17:16:34 +08005339void Context::programUniform1i(GLuint program, GLint location, GLint v0)
5340{
5341 programUniform1iv(program, location, 1, &v0);
5342}
5343
5344void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
5345{
5346 GLint xy[2] = {v0, v1};
5347 programUniform2iv(program, location, 1, xy);
5348}
5349
5350void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
5351{
5352 GLint xyz[3] = {v0, v1, v2};
5353 programUniform3iv(program, location, 1, xyz);
5354}
5355
5356void Context::programUniform4i(GLuint program,
5357 GLint location,
5358 GLint v0,
5359 GLint v1,
5360 GLint v2,
5361 GLint v3)
5362{
5363 GLint xyzw[4] = {v0, v1, v2, v3};
5364 programUniform4iv(program, location, 1, xyzw);
5365}
5366
5367void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
5368{
5369 programUniform1uiv(program, location, 1, &v0);
5370}
5371
5372void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
5373{
5374 GLuint xy[2] = {v0, v1};
5375 programUniform2uiv(program, location, 1, xy);
5376}
5377
5378void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
5379{
5380 GLuint xyz[3] = {v0, v1, v2};
5381 programUniform3uiv(program, location, 1, xyz);
5382}
5383
5384void Context::programUniform4ui(GLuint program,
5385 GLint location,
5386 GLuint v0,
5387 GLuint v1,
5388 GLuint v2,
5389 GLuint v3)
5390{
5391 GLuint xyzw[4] = {v0, v1, v2, v3};
5392 programUniform4uiv(program, location, 1, xyzw);
5393}
5394
5395void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
5396{
5397 programUniform1fv(program, location, 1, &v0);
5398}
5399
5400void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
5401{
5402 GLfloat xy[2] = {v0, v1};
5403 programUniform2fv(program, location, 1, xy);
5404}
5405
5406void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
5407{
5408 GLfloat xyz[3] = {v0, v1, v2};
5409 programUniform3fv(program, location, 1, xyz);
5410}
5411
5412void Context::programUniform4f(GLuint program,
5413 GLint location,
5414 GLfloat v0,
5415 GLfloat v1,
5416 GLfloat v2,
5417 GLfloat v3)
5418{
5419 GLfloat xyzw[4] = {v0, v1, v2, v3};
5420 programUniform4fv(program, location, 1, xyzw);
5421}
5422
Jamie Madill81c2e252017-09-09 23:32:46 -04005423void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5424{
5425 Program *programObject = getProgram(program);
5426 ASSERT(programObject);
5427 if (programObject->setUniform1iv(location, count, value) ==
5428 Program::SetUniformResult::SamplerChanged)
5429 {
5430 mGLState.setObjectDirty(GL_PROGRAM);
5431 }
5432}
5433
Jiajia Qin5451d532017-11-16 17:16:34 +08005434void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5435{
5436 Program *programObject = getProgram(program);
5437 ASSERT(programObject);
5438 programObject->setUniform2iv(location, count, value);
5439}
5440
5441void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5442{
5443 Program *programObject = getProgram(program);
5444 ASSERT(programObject);
5445 programObject->setUniform3iv(location, count, value);
5446}
5447
5448void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5449{
5450 Program *programObject = getProgram(program);
5451 ASSERT(programObject);
5452 programObject->setUniform4iv(location, count, value);
5453}
5454
5455void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5456{
5457 Program *programObject = getProgram(program);
5458 ASSERT(programObject);
5459 programObject->setUniform1uiv(location, count, value);
5460}
5461
5462void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5463{
5464 Program *programObject = getProgram(program);
5465 ASSERT(programObject);
5466 programObject->setUniform2uiv(location, count, value);
5467}
5468
5469void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5470{
5471 Program *programObject = getProgram(program);
5472 ASSERT(programObject);
5473 programObject->setUniform3uiv(location, count, value);
5474}
5475
5476void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5477{
5478 Program *programObject = getProgram(program);
5479 ASSERT(programObject);
5480 programObject->setUniform4uiv(location, count, value);
5481}
5482
5483void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5484{
5485 Program *programObject = getProgram(program);
5486 ASSERT(programObject);
5487 programObject->setUniform1fv(location, count, value);
5488}
5489
5490void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5491{
5492 Program *programObject = getProgram(program);
5493 ASSERT(programObject);
5494 programObject->setUniform2fv(location, count, value);
5495}
5496
5497void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5498{
5499 Program *programObject = getProgram(program);
5500 ASSERT(programObject);
5501 programObject->setUniform3fv(location, count, value);
5502}
5503
5504void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5505{
5506 Program *programObject = getProgram(program);
5507 ASSERT(programObject);
5508 programObject->setUniform4fv(location, count, value);
5509}
5510
5511void Context::programUniformMatrix2fv(GLuint program,
5512 GLint location,
5513 GLsizei count,
5514 GLboolean transpose,
5515 const GLfloat *value)
5516{
5517 Program *programObject = getProgram(program);
5518 ASSERT(programObject);
5519 programObject->setUniformMatrix2fv(location, count, transpose, value);
5520}
5521
5522void Context::programUniformMatrix3fv(GLuint program,
5523 GLint location,
5524 GLsizei count,
5525 GLboolean transpose,
5526 const GLfloat *value)
5527{
5528 Program *programObject = getProgram(program);
5529 ASSERT(programObject);
5530 programObject->setUniformMatrix3fv(location, count, transpose, value);
5531}
5532
5533void Context::programUniformMatrix4fv(GLuint program,
5534 GLint location,
5535 GLsizei count,
5536 GLboolean transpose,
5537 const GLfloat *value)
5538{
5539 Program *programObject = getProgram(program);
5540 ASSERT(programObject);
5541 programObject->setUniformMatrix4fv(location, count, transpose, value);
5542}
5543
5544void Context::programUniformMatrix2x3fv(GLuint program,
5545 GLint location,
5546 GLsizei count,
5547 GLboolean transpose,
5548 const GLfloat *value)
5549{
5550 Program *programObject = getProgram(program);
5551 ASSERT(programObject);
5552 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
5553}
5554
5555void Context::programUniformMatrix3x2fv(GLuint program,
5556 GLint location,
5557 GLsizei count,
5558 GLboolean transpose,
5559 const GLfloat *value)
5560{
5561 Program *programObject = getProgram(program);
5562 ASSERT(programObject);
5563 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
5564}
5565
5566void Context::programUniformMatrix2x4fv(GLuint program,
5567 GLint location,
5568 GLsizei count,
5569 GLboolean transpose,
5570 const GLfloat *value)
5571{
5572 Program *programObject = getProgram(program);
5573 ASSERT(programObject);
5574 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
5575}
5576
5577void Context::programUniformMatrix4x2fv(GLuint program,
5578 GLint location,
5579 GLsizei count,
5580 GLboolean transpose,
5581 const GLfloat *value)
5582{
5583 Program *programObject = getProgram(program);
5584 ASSERT(programObject);
5585 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
5586}
5587
5588void Context::programUniformMatrix3x4fv(GLuint program,
5589 GLint location,
5590 GLsizei count,
5591 GLboolean transpose,
5592 const GLfloat *value)
5593{
5594 Program *programObject = getProgram(program);
5595 ASSERT(programObject);
5596 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
5597}
5598
5599void Context::programUniformMatrix4x3fv(GLuint program,
5600 GLint location,
5601 GLsizei count,
5602 GLboolean transpose,
5603 const GLfloat *value)
5604{
5605 Program *programObject = getProgram(program);
5606 ASSERT(programObject);
5607 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
5608}
5609
Jamie Madill81c2e252017-09-09 23:32:46 -04005610void Context::onTextureChange(const Texture *texture)
5611{
5612 // Conservatively assume all textures are dirty.
5613 // TODO(jmadill): More fine-grained update.
5614 mGLState.setObjectDirty(GL_TEXTURE);
5615}
5616
Yunchao Hea336b902017-08-02 16:05:21 +08005617void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
5618{
5619 for (int i = 0; i < count; i++)
5620 {
5621 pipelines[i] = createProgramPipeline();
5622 }
5623}
5624
5625void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
5626{
5627 for (int i = 0; i < count; i++)
5628 {
5629 if (pipelines[i] != 0)
5630 {
5631 deleteProgramPipeline(pipelines[i]);
5632 }
5633 }
5634}
5635
5636GLboolean Context::isProgramPipeline(GLuint pipeline)
5637{
5638 if (pipeline == 0)
5639 {
5640 return GL_FALSE;
5641 }
5642
5643 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
5644}
5645
Jamie Madillc29968b2016-01-20 11:17:23 -05005646} // namespace gl