blob: b102bb54344587d752b626dde9d2ae5a6c2e602f [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);
Qin Jiajia62fcf622017-11-30 16:16:12 +0800420 mComputeDirtyBits.set(State::DIRTY_BIT_DISPATCH_INDIRECT_BUFFER_BINDING);
Xinghua Cao10a4d432017-11-28 14:46:26 +0800421
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400422 handleError(mImplementation->initialize());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000423}
424
Jamie Madill4928b7c2017-06-20 12:57:39 -0400425egl::Error Context::onDestroy(const egl::Display *display)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000426{
Corentin Wallez80b24112015-08-25 16:41:57 -0400427 for (auto fence : mFenceNVMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000428 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400429 SafeDelete(fence.second);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000430 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400431 mFenceNVMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000432
Corentin Wallez80b24112015-08-25 16:41:57 -0400433 for (auto query : mQueryMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000434 {
Geoff Langf0aa8422015-09-29 15:08:34 -0400435 if (query.second != nullptr)
436 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400437 query.second->release(this);
Geoff Langf0aa8422015-09-29 15:08:34 -0400438 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000439 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400440 mQueryMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000441
Corentin Wallez80b24112015-08-25 16:41:57 -0400442 for (auto vertexArray : mVertexArrayMap)
Jamie Madill57a89722013-07-02 11:57:03 -0400443 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400444 if (vertexArray.second)
445 {
446 vertexArray.second->onDestroy(this);
447 }
Jamie Madill57a89722013-07-02 11:57:03 -0400448 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400449 mVertexArrayMap.clear();
Jamie Madill57a89722013-07-02 11:57:03 -0400450
Corentin Wallez80b24112015-08-25 16:41:57 -0400451 for (auto transformFeedback : mTransformFeedbackMap)
Geoff Langc8058452014-02-03 12:04:11 -0500452 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500453 if (transformFeedback.second != nullptr)
454 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500455 transformFeedback.second->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500456 }
Geoff Langc8058452014-02-03 12:04:11 -0500457 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400458 mTransformFeedbackMap.clear();
Geoff Langc8058452014-02-03 12:04:11 -0500459
Jamie Madilldedd7b92014-11-05 16:30:36 -0500460 for (auto &zeroTexture : mZeroTextures)
Geoff Lang76b10c92014-09-05 16:28:14 -0400461 {
Jamie Madill71c88b32017-09-14 22:20:29 -0400462 ANGLE_TRY(zeroTexture.second->onDestroy(this));
Jamie Madill4928b7c2017-06-20 12:57:39 -0400463 zeroTexture.second.set(this, nullptr);
Geoff Lang76b10c92014-09-05 16:28:14 -0400464 }
465 mZeroTextures.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000466
Corentin Wallezccab69d2017-01-27 16:57:15 -0500467 SafeDelete(mSurfacelessFramebuffer);
468
Jamie Madill4928b7c2017-06-20 12:57:39 -0400469 ANGLE_TRY(releaseSurface(display));
Jamie Madill2f348d22017-06-05 10:50:59 -0400470 releaseShaderCompiler();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500471
Jamie Madill4928b7c2017-06-20 12:57:39 -0400472 mGLState.reset(this);
473
Jamie Madill6c1f6712017-02-14 19:08:04 -0500474 mState.mBuffers->release(this);
475 mState.mShaderPrograms->release(this);
476 mState.mTextures->release(this);
477 mState.mRenderbuffers->release(this);
478 mState.mSamplers->release(this);
Jamie Madill70b5bb02017-08-28 13:32:37 -0400479 mState.mSyncs->release(this);
Jamie Madill6c1f6712017-02-14 19:08:04 -0500480 mState.mPaths->release(this);
481 mState.mFramebuffers->release(this);
Yunchao Hea336b902017-08-02 16:05:21 +0800482 mState.mPipelines->release(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400483
Jamie Madill76e471e2017-10-21 09:56:01 -0400484 mImplementation->onDestroy(this);
485
Jamie Madill4928b7c2017-06-20 12:57:39 -0400486 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000487}
488
Jamie Madill70ee0f62017-02-06 16:04:20 -0500489Context::~Context()
490{
491}
492
Jamie Madill4928b7c2017-06-20 12:57:39 -0400493egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000494{
Jamie Madill61e16b42017-06-19 11:13:23 -0400495 mCurrentDisplay = display;
496
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000497 if (!mHasBeenCurrent)
498 {
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000499 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500500 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400501 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000502
Corentin Wallezc295e512017-01-27 17:47:50 -0500503 int width = 0;
504 int height = 0;
505 if (surface != nullptr)
506 {
507 width = surface->getWidth();
508 height = surface->getHeight();
509 }
510
511 mGLState.setViewportParams(0, 0, width, height);
512 mGLState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000513
514 mHasBeenCurrent = true;
515 }
516
Jamie Madill1b94d432015-08-07 13:23:23 -0400517 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700518 mGLState.setAllDirtyBits();
Jamie Madill81c2e252017-09-09 23:32:46 -0400519 mGLState.setAllDirtyObjects();
Jamie Madill1b94d432015-08-07 13:23:23 -0400520
Jamie Madill4928b7c2017-06-20 12:57:39 -0400521 ANGLE_TRY(releaseSurface(display));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500522
523 Framebuffer *newDefault = nullptr;
524 if (surface != nullptr)
525 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400526 ANGLE_TRY(surface->setIsCurrent(this, true));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500527 mCurrentSurface = surface;
528 newDefault = surface->getDefaultFramebuffer();
529 }
530 else
531 {
532 if (mSurfacelessFramebuffer == nullptr)
533 {
534 mSurfacelessFramebuffer = new Framebuffer(mImplementation.get());
535 }
536
537 newDefault = mSurfacelessFramebuffer;
538 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000539
Corentin Wallez37c39792015-08-20 14:19:46 -0400540 // Update default framebuffer, the binding of the previous default
541 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400542 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700543 if (mGLState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400544 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700545 mGLState.setReadFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400546 }
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700547 if (mGLState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400548 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700549 mGLState.setDrawFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400550 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500551 mState.mFramebuffers->setDefaultFramebuffer(newDefault);
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400552 }
Ian Ewell292f0052016-02-04 10:37:32 -0500553
554 // Notify the renderer of a context switch
Jamie Madill4928b7c2017-06-20 12:57:39 -0400555 mImplementation->onMakeCurrent(this);
556 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000557}
558
Jamie Madill4928b7c2017-06-20 12:57:39 -0400559egl::Error Context::releaseSurface(const egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400560{
Corentin Wallez37c39792015-08-20 14:19:46 -0400561 // Remove the default framebuffer
Corentin Wallezc295e512017-01-27 17:47:50 -0500562 Framebuffer *currentDefault = nullptr;
563 if (mCurrentSurface != nullptr)
Corentin Wallez51706ea2015-08-07 14:39:22 -0400564 {
Corentin Wallezc295e512017-01-27 17:47:50 -0500565 currentDefault = mCurrentSurface->getDefaultFramebuffer();
566 }
567 else if (mSurfacelessFramebuffer != nullptr)
568 {
569 currentDefault = mSurfacelessFramebuffer;
Corentin Wallez51706ea2015-08-07 14:39:22 -0400570 }
571
Corentin Wallezc295e512017-01-27 17:47:50 -0500572 if (mGLState.getReadFramebuffer() == currentDefault)
573 {
574 mGLState.setReadFramebufferBinding(nullptr);
575 }
576 if (mGLState.getDrawFramebuffer() == currentDefault)
577 {
578 mGLState.setDrawFramebufferBinding(nullptr);
579 }
580 mState.mFramebuffers->setDefaultFramebuffer(nullptr);
581
582 if (mCurrentSurface)
583 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400584 ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
Corentin Wallezc295e512017-01-27 17:47:50 -0500585 mCurrentSurface = nullptr;
586 }
Jamie Madill4928b7c2017-06-20 12:57:39 -0400587
588 return egl::NoError();
Jamie Madill77a72f62015-04-14 11:18:32 -0400589}
590
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000591GLuint Context::createBuffer()
592{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500593 return mState.mBuffers->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000594}
595
596GLuint Context::createProgram()
597{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500598 return mState.mShaderPrograms->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000599}
600
601GLuint Context::createShader(GLenum type)
602{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500603 return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000604}
605
606GLuint Context::createTexture()
607{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500608 return mState.mTextures->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000609}
610
611GLuint Context::createRenderbuffer()
612{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500613 return mState.mRenderbuffers->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000614}
615
Sami Väisänene45e53b2016-05-25 10:36:04 +0300616GLuint Context::createPaths(GLsizei range)
617{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500618 auto resultOrError = mState.mPaths->createPaths(mImplementation.get(), range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300619 if (resultOrError.isError())
620 {
621 handleError(resultOrError.getError());
622 return 0;
623 }
624 return resultOrError.getResult();
625}
626
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000627// Returns an unused framebuffer name
628GLuint Context::createFramebuffer()
629{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500630 return mState.mFramebuffers->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000631}
632
Jamie Madill33dc8432013-07-26 11:55:05 -0400633GLuint Context::createFenceNV()
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000634{
Jamie Madill33dc8432013-07-26 11:55:05 -0400635 GLuint handle = mFenceNVHandleAllocator.allocate();
Jamie Madill96a483b2017-06-27 16:49:21 -0400636 mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV()));
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000637 return handle;
638}
639
Yunchao Hea336b902017-08-02 16:05:21 +0800640GLuint Context::createProgramPipeline()
641{
642 return mState.mPipelines->createProgramPipeline();
643}
644
Jiajia Qin5451d532017-11-16 17:16:34 +0800645GLuint Context::createShaderProgramv(GLenum type, GLsizei count, const GLchar *const *strings)
646{
647 UNIMPLEMENTED();
648 return 0u;
649}
650
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000651void Context::deleteBuffer(GLuint buffer)
652{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500653 if (mState.mBuffers->getBuffer(buffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000654 {
655 detachBuffer(buffer);
656 }
Jamie Madill893ab082014-05-16 16:56:10 -0400657
Jamie Madill6c1f6712017-02-14 19:08:04 -0500658 mState.mBuffers->deleteObject(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000659}
660
661void Context::deleteShader(GLuint shader)
662{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500663 mState.mShaderPrograms->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000664}
665
666void Context::deleteProgram(GLuint program)
667{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500668 mState.mShaderPrograms->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000669}
670
671void Context::deleteTexture(GLuint texture)
672{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500673 if (mState.mTextures->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000674 {
675 detachTexture(texture);
676 }
677
Jamie Madill6c1f6712017-02-14 19:08:04 -0500678 mState.mTextures->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000679}
680
681void Context::deleteRenderbuffer(GLuint renderbuffer)
682{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500683 if (mState.mRenderbuffers->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000684 {
685 detachRenderbuffer(renderbuffer);
686 }
Jamie Madill893ab082014-05-16 16:56:10 -0400687
Jamie Madill6c1f6712017-02-14 19:08:04 -0500688 mState.mRenderbuffers->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000689}
690
Jamie Madill7f0c5a42017-08-26 22:43:26 -0400691void Context::deleteSync(GLsync sync)
Jamie Madillcd055f82013-07-26 11:55:15 -0400692{
693 // The spec specifies the underlying Fence object is not deleted until all current
694 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
695 // and since our API is currently designed for being called from a single thread, we can delete
696 // the fence immediately.
Jamie Madill70b5bb02017-08-28 13:32:37 -0400697 mState.mSyncs->deleteObject(this, static_cast<GLuint>(reinterpret_cast<uintptr_t>(sync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400698}
699
Yunchao Hea336b902017-08-02 16:05:21 +0800700void Context::deleteProgramPipeline(GLuint pipeline)
701{
702 if (mState.mPipelines->getProgramPipeline(pipeline))
703 {
704 detachProgramPipeline(pipeline);
705 }
706
707 mState.mPipelines->deleteObject(this, pipeline);
708}
709
Sami Väisänene45e53b2016-05-25 10:36:04 +0300710void Context::deletePaths(GLuint first, GLsizei range)
711{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500712 mState.mPaths->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300713}
714
715bool Context::hasPathData(GLuint path) const
716{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500717 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300718 if (pathObj == nullptr)
719 return false;
720
721 return pathObj->hasPathData();
722}
723
724bool Context::hasPath(GLuint path) const
725{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500726 return mState.mPaths->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300727}
728
729void Context::setPathCommands(GLuint path,
730 GLsizei numCommands,
731 const GLubyte *commands,
732 GLsizei numCoords,
733 GLenum coordType,
734 const void *coords)
735{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500736 auto *pathObject = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300737
738 handleError(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
739}
740
741void Context::setPathParameterf(GLuint path, GLenum pname, GLfloat value)
742{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500743 auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300744
745 switch (pname)
746 {
747 case GL_PATH_STROKE_WIDTH_CHROMIUM:
748 pathObj->setStrokeWidth(value);
749 break;
750 case GL_PATH_END_CAPS_CHROMIUM:
751 pathObj->setEndCaps(static_cast<GLenum>(value));
752 break;
753 case GL_PATH_JOIN_STYLE_CHROMIUM:
754 pathObj->setJoinStyle(static_cast<GLenum>(value));
755 break;
756 case GL_PATH_MITER_LIMIT_CHROMIUM:
757 pathObj->setMiterLimit(value);
758 break;
759 case GL_PATH_STROKE_BOUND_CHROMIUM:
760 pathObj->setStrokeBound(value);
761 break;
762 default:
763 UNREACHABLE();
764 break;
765 }
766}
767
768void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value) const
769{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500770 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300771
772 switch (pname)
773 {
774 case GL_PATH_STROKE_WIDTH_CHROMIUM:
775 *value = pathObj->getStrokeWidth();
776 break;
777 case GL_PATH_END_CAPS_CHROMIUM:
778 *value = static_cast<GLfloat>(pathObj->getEndCaps());
779 break;
780 case GL_PATH_JOIN_STYLE_CHROMIUM:
781 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
782 break;
783 case GL_PATH_MITER_LIMIT_CHROMIUM:
784 *value = pathObj->getMiterLimit();
785 break;
786 case GL_PATH_STROKE_BOUND_CHROMIUM:
787 *value = pathObj->getStrokeBound();
788 break;
789 default:
790 UNREACHABLE();
791 break;
792 }
793}
794
795void Context::setPathStencilFunc(GLenum func, GLint ref, GLuint mask)
796{
797 mGLState.setPathStencilFunc(func, ref, mask);
798}
799
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000800void Context::deleteFramebuffer(GLuint framebuffer)
801{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500802 if (mState.mFramebuffers->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000803 {
804 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000805 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500806
Jamie Madill6c1f6712017-02-14 19:08:04 -0500807 mState.mFramebuffers->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000808}
809
Jamie Madill33dc8432013-07-26 11:55:05 -0400810void Context::deleteFenceNV(GLuint fence)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000811{
Jamie Madill96a483b2017-06-27 16:49:21 -0400812 FenceNV *fenceObject = nullptr;
813 if (mFenceNVMap.erase(fence, &fenceObject))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000814 {
Jamie Madill96a483b2017-06-27 16:49:21 -0400815 mFenceNVHandleAllocator.release(fence);
816 delete fenceObject;
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000817 }
818}
819
Geoff Lang70d0f492015-12-10 17:45:46 -0500820Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000821{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500822 return mState.mBuffers->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000823}
824
Jamie Madill570f7c82014-07-03 10:38:54 -0400825Texture *Context::getTexture(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000826{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500827 return mState.mTextures->getTexture(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000828}
829
Geoff Lang70d0f492015-12-10 17:45:46 -0500830Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000831{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500832 return mState.mRenderbuffers->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000833}
834
Jamie Madill70b5bb02017-08-28 13:32:37 -0400835Sync *Context::getSync(GLsync handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400836{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400837 return mState.mSyncs->getSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400838}
839
Jamie Madill57a89722013-07-02 11:57:03 -0400840VertexArray *Context::getVertexArray(GLuint handle) const
841{
Jamie Madill96a483b2017-06-27 16:49:21 -0400842 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -0400843}
844
Jamie Madilldc356042013-07-19 16:36:57 -0400845Sampler *Context::getSampler(GLuint handle) const
846{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500847 return mState.mSamplers->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400848}
849
Geoff Langc8058452014-02-03 12:04:11 -0500850TransformFeedback *Context::getTransformFeedback(GLuint handle) const
851{
Jamie Madill96a483b2017-06-27 16:49:21 -0400852 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -0500853}
854
Yunchao Hea336b902017-08-02 16:05:21 +0800855ProgramPipeline *Context::getProgramPipeline(GLuint handle) const
856{
857 return mState.mPipelines->getProgramPipeline(handle);
858}
859
Geoff Lang70d0f492015-12-10 17:45:46 -0500860LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
861{
862 switch (identifier)
863 {
864 case GL_BUFFER:
865 return getBuffer(name);
866 case GL_SHADER:
867 return getShader(name);
868 case GL_PROGRAM:
869 return getProgram(name);
870 case GL_VERTEX_ARRAY:
871 return getVertexArray(name);
872 case GL_QUERY:
873 return getQuery(name);
874 case GL_TRANSFORM_FEEDBACK:
875 return getTransformFeedback(name);
876 case GL_SAMPLER:
877 return getSampler(name);
878 case GL_TEXTURE:
879 return getTexture(name);
880 case GL_RENDERBUFFER:
881 return getRenderbuffer(name);
882 case GL_FRAMEBUFFER:
883 return getFramebuffer(name);
884 default:
885 UNREACHABLE();
886 return nullptr;
887 }
888}
889
890LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
891{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400892 return getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
Geoff Lang70d0f492015-12-10 17:45:46 -0500893}
894
Martin Radev9d901792016-07-15 15:58:58 +0300895void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
896{
897 LabeledObject *object = getLabeledObject(identifier, name);
898 ASSERT(object != nullptr);
899
900 std::string labelName = GetObjectLabelFromPointer(length, label);
901 object->setLabel(labelName);
Jamie Madill8693bdb2017-09-02 15:32:14 -0400902
903 // TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the
904 // specified object is active until we do this.
905 mGLState.setObjectDirty(identifier);
Martin Radev9d901792016-07-15 15:58:58 +0300906}
907
908void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
909{
910 LabeledObject *object = getLabeledObjectFromPtr(ptr);
911 ASSERT(object != nullptr);
912
913 std::string labelName = GetObjectLabelFromPointer(length, label);
914 object->setLabel(labelName);
915}
916
917void Context::getObjectLabel(GLenum identifier,
918 GLuint name,
919 GLsizei bufSize,
920 GLsizei *length,
921 GLchar *label) const
922{
923 LabeledObject *object = getLabeledObject(identifier, name);
924 ASSERT(object != nullptr);
925
926 const std::string &objectLabel = object->getLabel();
927 GetObjectLabelBase(objectLabel, bufSize, length, label);
928}
929
930void Context::getObjectPtrLabel(const void *ptr,
931 GLsizei bufSize,
932 GLsizei *length,
933 GLchar *label) const
934{
935 LabeledObject *object = getLabeledObjectFromPtr(ptr);
936 ASSERT(object != nullptr);
937
938 const std::string &objectLabel = object->getLabel();
939 GetObjectLabelBase(objectLabel, bufSize, length, label);
940}
941
Jamie Madilldc356042013-07-19 16:36:57 -0400942bool Context::isSampler(GLuint samplerName) const
943{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500944 return mState.mSamplers->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -0400945}
946
Jamie Madilldedd7b92014-11-05 16:30:36 -0500947void Context::bindTexture(GLenum target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000948{
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500949 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000950
Jamie Madilldedd7b92014-11-05 16:30:36 -0500951 if (handle == 0)
952 {
953 texture = mZeroTextures[target].get();
954 }
955 else
956 {
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500957 texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500958 }
959
960 ASSERT(texture);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400961 mGLState.setSamplerTexture(this, target, texture);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +0000962}
963
Jamie Madill5bf9ff42016-02-01 11:13:03 -0500964void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000965{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500966 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
967 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700968 mGLState.setReadFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000969}
970
Jamie Madill5bf9ff42016-02-01 11:13:03 -0500971void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000972{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500973 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
974 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700975 mGLState.setDrawFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000976}
977
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500978void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -0400979{
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500980 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700981 mGLState.setVertexArrayBinding(vertexArray);
Jamie Madill57a89722013-07-02 11:57:03 -0400982}
983
Shao80957d92017-02-20 21:25:59 +0800984void Context::bindVertexBuffer(GLuint bindingIndex,
985 GLuint bufferHandle,
986 GLintptr offset,
987 GLsizei stride)
988{
989 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400990 mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Shao80957d92017-02-20 21:25:59 +0800991}
992
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500993void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -0400994{
Geoff Lang76b10c92014-09-05 16:28:14 -0400995 ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -0400996 Sampler *sampler =
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500997 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400998 mGLState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -0400999}
1000
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001001void Context::bindImageTexture(GLuint unit,
1002 GLuint texture,
1003 GLint level,
1004 GLboolean layered,
1005 GLint layer,
1006 GLenum access,
1007 GLenum format)
1008{
1009 Texture *tex = mState.mTextures->getTexture(texture);
1010 mGLState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
1011}
1012
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001013void Context::useProgram(GLuint program)
1014{
Jamie Madill6c1f6712017-02-14 19:08:04 -05001015 mGLState.setProgram(this, getProgram(program));
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001016}
1017
Jiajia Qin5451d532017-11-16 17:16:34 +08001018void Context::useProgramStages(GLuint pipeline, GLbitfield stages, GLuint program)
1019{
1020 UNIMPLEMENTED();
1021}
1022
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001023void Context::bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001024{
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001025 ASSERT(target == GL_TRANSFORM_FEEDBACK);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001026 TransformFeedback *transformFeedback =
1027 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001028 mGLState.setTransformFeedbackBinding(this, transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -05001029}
1030
Yunchao Hea336b902017-08-02 16:05:21 +08001031void Context::bindProgramPipeline(GLuint pipelineHandle)
1032{
1033 ProgramPipeline *pipeline =
1034 mState.mPipelines->checkProgramPipelineAllocation(mImplementation.get(), pipelineHandle);
1035 mGLState.setProgramPipelineBinding(this, pipeline);
1036}
1037
Jamie Madillf0e04492017-08-26 15:28:42 -04001038void Context::beginQuery(GLenum target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001039{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001040 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001041 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001042
Geoff Lang5aad9672014-09-08 11:10:42 -04001043 // begin query
Jamie Madillf0e04492017-08-26 15:28:42 -04001044 ANGLE_CONTEXT_TRY(queryObject->begin());
Geoff Lang5aad9672014-09-08 11:10:42 -04001045
1046 // set query as active for specified target only if begin succeeded
Jamie Madill4928b7c2017-06-20 12:57:39 -04001047 mGLState.setActiveQuery(this, target, queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001048}
1049
Jamie Madillf0e04492017-08-26 15:28:42 -04001050void Context::endQuery(GLenum target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001051{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001052 Query *queryObject = mGLState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001053 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001054
Jamie Madillf0e04492017-08-26 15:28:42 -04001055 handleError(queryObject->end());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001056
Geoff Lang5aad9672014-09-08 11:10:42 -04001057 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madill4928b7c2017-06-20 12:57:39 -04001058 mGLState.setActiveQuery(this, target, nullptr);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001059}
1060
Jamie Madillf0e04492017-08-26 15:28:42 -04001061void Context::queryCounter(GLuint id, GLenum target)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001062{
1063 ASSERT(target == GL_TIMESTAMP_EXT);
1064
1065 Query *queryObject = getQuery(id, true, target);
1066 ASSERT(queryObject);
1067
Jamie Madillf0e04492017-08-26 15:28:42 -04001068 handleError(queryObject->queryCounter());
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001069}
1070
1071void Context::getQueryiv(GLenum target, GLenum pname, GLint *params)
1072{
1073 switch (pname)
1074 {
1075 case GL_CURRENT_QUERY_EXT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001076 params[0] = mGLState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001077 break;
1078 case GL_QUERY_COUNTER_BITS_EXT:
1079 switch (target)
1080 {
1081 case GL_TIME_ELAPSED_EXT:
1082 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1083 break;
1084 case GL_TIMESTAMP_EXT:
1085 params[0] = getExtensions().queryCounterBitsTimestamp;
1086 break;
1087 default:
1088 UNREACHABLE();
1089 params[0] = 0;
1090 break;
1091 }
1092 break;
1093 default:
1094 UNREACHABLE();
1095 return;
1096 }
1097}
1098
Geoff Lang2186c382016-10-14 10:54:54 -04001099void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001100{
Geoff Lang2186c382016-10-14 10:54:54 -04001101 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001102}
1103
Geoff Lang2186c382016-10-14 10:54:54 -04001104void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001105{
Geoff Lang2186c382016-10-14 10:54:54 -04001106 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001107}
1108
Geoff Lang2186c382016-10-14 10:54:54 -04001109void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001110{
Geoff Lang2186c382016-10-14 10:54:54 -04001111 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001112}
1113
Geoff Lang2186c382016-10-14 10:54:54 -04001114void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001115{
Geoff Lang2186c382016-10-14 10:54:54 -04001116 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001117}
1118
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001119Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001120{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001121 return mState.mFramebuffers->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001122}
1123
Jamie Madill2f348d22017-06-05 10:50:59 -04001124FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001125{
Jamie Madill96a483b2017-06-27 16:49:21 -04001126 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001127}
1128
Jamie Madill2f348d22017-06-05 10:50:59 -04001129Query *Context::getQuery(GLuint handle, bool create, GLenum type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001130{
Jamie Madill96a483b2017-06-27 16:49:21 -04001131 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001132 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001133 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001134 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001135
1136 Query *query = mQueryMap.query(handle);
1137 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001138 {
Jamie Madill96a483b2017-06-27 16:49:21 -04001139 query = new Query(mImplementation->createQuery(type), handle);
1140 query->addRef();
1141 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001142 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001143 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001144}
1145
Geoff Lang70d0f492015-12-10 17:45:46 -05001146Query *Context::getQuery(GLuint handle) const
1147{
Jamie Madill96a483b2017-06-27 16:49:21 -04001148 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001149}
1150
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001151Texture *Context::getTargetTexture(GLenum target) const
1152{
Ian Ewellbda75592016-04-18 17:25:54 -04001153 ASSERT(ValidTextureTarget(this, target) || ValidTextureExternalTarget(this, target));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001154 return mGLState.getTargetTexture(target);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001155}
1156
Geoff Lang76b10c92014-09-05 16:28:14 -04001157Texture *Context::getSamplerTexture(unsigned int sampler, GLenum type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001158{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001159 return mGLState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001160}
1161
Geoff Lang492a7e42014-11-05 13:27:06 -05001162Compiler *Context::getCompiler() const
1163{
Jamie Madill2f348d22017-06-05 10:50:59 -04001164 if (mCompiler.get() == nullptr)
1165 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001166 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001167 }
1168 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001169}
1170
Jamie Madillc1d770e2017-04-13 17:31:24 -04001171void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001172{
1173 switch (pname)
1174 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001175 case GL_SHADER_COMPILER:
1176 *params = GL_TRUE;
1177 break;
1178 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1179 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1180 break;
1181 default:
1182 mGLState.getBooleanv(pname, params);
1183 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001184 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001185}
1186
Jamie Madillc1d770e2017-04-13 17:31:24 -04001187void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001188{
Shannon Woods53a94a82014-06-24 15:20:36 -04001189 // Queries about context capabilities and maximums are answered by Context.
1190 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001191 switch (pname)
1192 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001193 case GL_ALIASED_LINE_WIDTH_RANGE:
1194 params[0] = mCaps.minAliasedLineWidth;
1195 params[1] = mCaps.maxAliasedLineWidth;
1196 break;
1197 case GL_ALIASED_POINT_SIZE_RANGE:
1198 params[0] = mCaps.minAliasedPointSize;
1199 params[1] = mCaps.maxAliasedPointSize;
1200 break;
1201 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1202 ASSERT(mExtensions.textureFilterAnisotropic);
1203 *params = mExtensions.maxTextureAnisotropy;
1204 break;
1205 case GL_MAX_TEXTURE_LOD_BIAS:
1206 *params = mCaps.maxLODBias;
1207 break;
1208
1209 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1210 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1211 {
1212 ASSERT(mExtensions.pathRendering);
1213 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1214 memcpy(params, m, 16 * sizeof(GLfloat));
1215 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001216 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001217
Jamie Madill231c7f52017-04-26 13:45:37 -04001218 default:
1219 mGLState.getFloatv(pname, params);
1220 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001221 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001222}
1223
Jamie Madillc1d770e2017-04-13 17:31:24 -04001224void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001225{
Shannon Woods53a94a82014-06-24 15:20:36 -04001226 // Queries about context capabilities and maximums are answered by Context.
1227 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001228
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001229 switch (pname)
1230 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001231 case GL_MAX_VERTEX_ATTRIBS:
1232 *params = mCaps.maxVertexAttributes;
1233 break;
1234 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1235 *params = mCaps.maxVertexUniformVectors;
1236 break;
1237 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
1238 *params = mCaps.maxVertexUniformComponents;
1239 break;
1240 case GL_MAX_VARYING_VECTORS:
1241 *params = mCaps.maxVaryingVectors;
1242 break;
1243 case GL_MAX_VARYING_COMPONENTS:
1244 *params = mCaps.maxVertexOutputComponents;
1245 break;
1246 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1247 *params = mCaps.maxCombinedTextureImageUnits;
1248 break;
1249 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
1250 *params = mCaps.maxVertexTextureImageUnits;
1251 break;
1252 case GL_MAX_TEXTURE_IMAGE_UNITS:
1253 *params = mCaps.maxTextureImageUnits;
1254 break;
1255 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1256 *params = mCaps.maxFragmentUniformVectors;
1257 break;
1258 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
1259 *params = mCaps.maxFragmentUniformComponents;
1260 break;
1261 case GL_MAX_RENDERBUFFER_SIZE:
1262 *params = mCaps.maxRenderbufferSize;
1263 break;
1264 case GL_MAX_COLOR_ATTACHMENTS_EXT:
1265 *params = mCaps.maxColorAttachments;
1266 break;
1267 case GL_MAX_DRAW_BUFFERS_EXT:
1268 *params = mCaps.maxDrawBuffers;
1269 break;
1270 // case GL_FRAMEBUFFER_BINDING: // now equivalent to
1271 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
1272 case GL_SUBPIXEL_BITS:
1273 *params = 4;
1274 break;
1275 case GL_MAX_TEXTURE_SIZE:
1276 *params = mCaps.max2DTextureSize;
1277 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001278 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
1279 *params = mCaps.maxRectangleTextureSize;
1280 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001281 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1282 *params = mCaps.maxCubeMapTextureSize;
1283 break;
1284 case GL_MAX_3D_TEXTURE_SIZE:
1285 *params = mCaps.max3DTextureSize;
1286 break;
1287 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1288 *params = mCaps.maxArrayTextureLayers;
1289 break;
1290 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1291 *params = mCaps.uniformBufferOffsetAlignment;
1292 break;
1293 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1294 *params = mCaps.maxUniformBufferBindings;
1295 break;
1296 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
1297 *params = mCaps.maxVertexUniformBlocks;
1298 break;
1299 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
1300 *params = mCaps.maxFragmentUniformBlocks;
1301 break;
1302 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1303 *params = mCaps.maxCombinedTextureImageUnits;
1304 break;
1305 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1306 *params = mCaps.maxVertexOutputComponents;
1307 break;
1308 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1309 *params = mCaps.maxFragmentInputComponents;
1310 break;
1311 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1312 *params = mCaps.minProgramTexelOffset;
1313 break;
1314 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1315 *params = mCaps.maxProgramTexelOffset;
1316 break;
1317 case GL_MAJOR_VERSION:
1318 *params = getClientVersion().major;
1319 break;
1320 case GL_MINOR_VERSION:
1321 *params = getClientVersion().minor;
1322 break;
1323 case GL_MAX_ELEMENTS_INDICES:
1324 *params = mCaps.maxElementsIndices;
1325 break;
1326 case GL_MAX_ELEMENTS_VERTICES:
1327 *params = mCaps.maxElementsVertices;
1328 break;
1329 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1330 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1331 break;
1332 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1333 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1334 break;
1335 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1336 *params = mCaps.maxTransformFeedbackSeparateComponents;
1337 break;
1338 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1339 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1340 break;
1341 case GL_MAX_SAMPLES_ANGLE:
1342 *params = mCaps.maxSamples;
1343 break;
1344 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001345 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001346 params[0] = mCaps.maxViewportWidth;
1347 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001348 }
1349 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001350 case GL_COMPRESSED_TEXTURE_FORMATS:
1351 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1352 params);
1353 break;
1354 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1355 *params = mResetStrategy;
1356 break;
1357 case GL_NUM_SHADER_BINARY_FORMATS:
1358 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1359 break;
1360 case GL_SHADER_BINARY_FORMATS:
1361 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1362 break;
1363 case GL_NUM_PROGRAM_BINARY_FORMATS:
1364 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1365 break;
1366 case GL_PROGRAM_BINARY_FORMATS:
1367 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1368 break;
1369 case GL_NUM_EXTENSIONS:
1370 *params = static_cast<GLint>(mExtensionStrings.size());
1371 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001372
Jamie Madill231c7f52017-04-26 13:45:37 -04001373 // GL_KHR_debug
1374 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1375 *params = mExtensions.maxDebugMessageLength;
1376 break;
1377 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1378 *params = mExtensions.maxDebugLoggedMessages;
1379 break;
1380 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1381 *params = mExtensions.maxDebugGroupStackDepth;
1382 break;
1383 case GL_MAX_LABEL_LENGTH:
1384 *params = mExtensions.maxLabelLength;
1385 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001386
Martin Radeve5285d22017-07-14 16:23:53 +03001387 // GL_ANGLE_multiview
1388 case GL_MAX_VIEWS_ANGLE:
1389 *params = mExtensions.maxViews;
1390 break;
1391
Jamie Madill231c7f52017-04-26 13:45:37 -04001392 // GL_EXT_disjoint_timer_query
1393 case GL_GPU_DISJOINT_EXT:
1394 *params = mImplementation->getGPUDisjoint();
1395 break;
1396 case GL_MAX_FRAMEBUFFER_WIDTH:
1397 *params = mCaps.maxFramebufferWidth;
1398 break;
1399 case GL_MAX_FRAMEBUFFER_HEIGHT:
1400 *params = mCaps.maxFramebufferHeight;
1401 break;
1402 case GL_MAX_FRAMEBUFFER_SAMPLES:
1403 *params = mCaps.maxFramebufferSamples;
1404 break;
1405 case GL_MAX_SAMPLE_MASK_WORDS:
1406 *params = mCaps.maxSampleMaskWords;
1407 break;
1408 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1409 *params = mCaps.maxColorTextureSamples;
1410 break;
1411 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1412 *params = mCaps.maxDepthTextureSamples;
1413 break;
1414 case GL_MAX_INTEGER_SAMPLES:
1415 *params = mCaps.maxIntegerSamples;
1416 break;
1417 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1418 *params = mCaps.maxVertexAttribRelativeOffset;
1419 break;
1420 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1421 *params = mCaps.maxVertexAttribBindings;
1422 break;
1423 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1424 *params = mCaps.maxVertexAttribStride;
1425 break;
1426 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
1427 *params = mCaps.maxVertexAtomicCounterBuffers;
1428 break;
1429 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
1430 *params = mCaps.maxVertexAtomicCounters;
1431 break;
1432 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
1433 *params = mCaps.maxVertexImageUniforms;
1434 break;
1435 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
1436 *params = mCaps.maxVertexShaderStorageBlocks;
1437 break;
1438 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
1439 *params = mCaps.maxFragmentAtomicCounterBuffers;
1440 break;
1441 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
1442 *params = mCaps.maxFragmentAtomicCounters;
1443 break;
1444 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
1445 *params = mCaps.maxFragmentImageUniforms;
1446 break;
1447 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
1448 *params = mCaps.maxFragmentShaderStorageBlocks;
1449 break;
1450 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1451 *params = mCaps.minProgramTextureGatherOffset;
1452 break;
1453 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1454 *params = mCaps.maxProgramTextureGatherOffset;
1455 break;
1456 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1457 *params = mCaps.maxComputeWorkGroupInvocations;
1458 break;
1459 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
1460 *params = mCaps.maxComputeUniformBlocks;
1461 break;
1462 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
1463 *params = mCaps.maxComputeTextureImageUnits;
1464 break;
1465 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1466 *params = mCaps.maxComputeSharedMemorySize;
1467 break;
1468 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
1469 *params = mCaps.maxComputeUniformComponents;
1470 break;
1471 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
1472 *params = mCaps.maxComputeAtomicCounterBuffers;
1473 break;
1474 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
1475 *params = mCaps.maxComputeAtomicCounters;
1476 break;
1477 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
1478 *params = mCaps.maxComputeImageUniforms;
1479 break;
1480 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
1481 *params = mCaps.maxCombinedComputeUniformComponents;
1482 break;
1483 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
1484 *params = mCaps.maxComputeShaderStorageBlocks;
1485 break;
1486 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1487 *params = mCaps.maxCombinedShaderOutputResources;
1488 break;
1489 case GL_MAX_UNIFORM_LOCATIONS:
1490 *params = mCaps.maxUniformLocations;
1491 break;
1492 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1493 *params = mCaps.maxAtomicCounterBufferBindings;
1494 break;
1495 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1496 *params = mCaps.maxAtomicCounterBufferSize;
1497 break;
1498 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1499 *params = mCaps.maxCombinedAtomicCounterBuffers;
1500 break;
1501 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1502 *params = mCaps.maxCombinedAtomicCounters;
1503 break;
1504 case GL_MAX_IMAGE_UNITS:
1505 *params = mCaps.maxImageUnits;
1506 break;
1507 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1508 *params = mCaps.maxCombinedImageUniforms;
1509 break;
1510 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1511 *params = mCaps.maxShaderStorageBufferBindings;
1512 break;
1513 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1514 *params = mCaps.maxCombinedShaderStorageBlocks;
1515 break;
1516 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1517 *params = mCaps.shaderStorageBufferOffsetAlignment;
1518 break;
Jiawei Shao361df072017-11-22 09:33:59 +08001519
1520 // GL_EXT_geometry_shader
1521 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
1522 *params = mCaps.maxFramebufferLayers;
1523 break;
1524 case GL_LAYER_PROVOKING_VERTEX_EXT:
1525 *params = mCaps.layerProvokingVertex;
1526 break;
1527 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
1528 *params = mCaps.maxGeometryUniformComponents;
1529 break;
1530 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
1531 *params = mCaps.maxGeometryUniformBlocks;
1532 break;
1533 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
1534 *params = mCaps.maxCombinedGeometryUniformComponents;
1535 break;
1536 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
1537 *params = mCaps.maxGeometryInputComponents;
1538 break;
1539 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
1540 *params = mCaps.maxGeometryOutputComponents;
1541 break;
1542 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
1543 *params = mCaps.maxGeometryOutputVertices;
1544 break;
1545 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
1546 *params = mCaps.maxGeometryTotalOutputComponents;
1547 break;
1548 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
1549 *params = mCaps.maxGeometryShaderInvocations;
1550 break;
1551 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
1552 *params = mCaps.maxGeometryTextureImageUnits;
1553 break;
1554 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
1555 *params = mCaps.maxGeometryAtomicCounterBuffers;
1556 break;
1557 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
1558 *params = mCaps.maxGeometryAtomicCounters;
1559 break;
1560 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
1561 *params = mCaps.maxGeometryImageUniforms;
1562 break;
1563 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
1564 *params = mCaps.maxGeometryShaderStorageBlocks;
1565 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001566 default:
1567 mGLState.getIntegerv(this, pname, params);
1568 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001569 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001570}
1571
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001572void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001573{
Shannon Woods53a94a82014-06-24 15:20:36 -04001574 // Queries about context capabilities and maximums are answered by Context.
1575 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001576 switch (pname)
1577 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001578 case GL_MAX_ELEMENT_INDEX:
1579 *params = mCaps.maxElementIndex;
1580 break;
1581 case GL_MAX_UNIFORM_BLOCK_SIZE:
1582 *params = mCaps.maxUniformBlockSize;
1583 break;
1584 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
1585 *params = mCaps.maxCombinedVertexUniformComponents;
1586 break;
1587 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
1588 *params = mCaps.maxCombinedFragmentUniformComponents;
1589 break;
1590 case GL_MAX_SERVER_WAIT_TIMEOUT:
1591 *params = mCaps.maxServerWaitTimeout;
1592 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001593
Jamie Madill231c7f52017-04-26 13:45:37 -04001594 // GL_EXT_disjoint_timer_query
1595 case GL_TIMESTAMP_EXT:
1596 *params = mImplementation->getTimestamp();
1597 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001598
Jamie Madill231c7f52017-04-26 13:45:37 -04001599 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1600 *params = mCaps.maxShaderStorageBlockSize;
1601 break;
1602 default:
1603 UNREACHABLE();
1604 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001605 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001606}
1607
Geoff Lang70d0f492015-12-10 17:45:46 -05001608void Context::getPointerv(GLenum pname, void **params) const
1609{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001610 mGLState.getPointerv(pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001611}
1612
Martin Radev66fb8202016-07-28 11:45:20 +03001613void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001614{
Shannon Woods53a94a82014-06-24 15:20:36 -04001615 // Queries about context capabilities and maximums are answered by Context.
1616 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001617
1618 GLenum nativeType;
1619 unsigned int numParams;
1620 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1621 ASSERT(queryStatus);
1622
1623 if (nativeType == GL_INT)
1624 {
1625 switch (target)
1626 {
1627 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1628 ASSERT(index < 3u);
1629 *data = mCaps.maxComputeWorkGroupCount[index];
1630 break;
1631 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1632 ASSERT(index < 3u);
1633 *data = mCaps.maxComputeWorkGroupSize[index];
1634 break;
1635 default:
1636 mGLState.getIntegeri_v(target, index, data);
1637 }
1638 }
1639 else
1640 {
1641 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1642 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001643}
1644
Martin Radev66fb8202016-07-28 11:45:20 +03001645void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001646{
Shannon Woods53a94a82014-06-24 15:20:36 -04001647 // Queries about context capabilities and maximums are answered by Context.
1648 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001649
1650 GLenum nativeType;
1651 unsigned int numParams;
1652 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1653 ASSERT(queryStatus);
1654
1655 if (nativeType == GL_INT_64_ANGLEX)
1656 {
1657 mGLState.getInteger64i_v(target, index, data);
1658 }
1659 else
1660 {
1661 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1662 }
1663}
1664
1665void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1666{
1667 // Queries about context capabilities and maximums are answered by Context.
1668 // Queries about current GL state values are answered by State.
1669
1670 GLenum nativeType;
1671 unsigned int numParams;
1672 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1673 ASSERT(queryStatus);
1674
1675 if (nativeType == GL_BOOL)
1676 {
1677 mGLState.getBooleani_v(target, index, data);
1678 }
1679 else
1680 {
1681 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1682 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001683}
1684
Corentin Wallez336129f2017-10-17 15:55:40 -04001685void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001686{
1687 Buffer *buffer = mGLState.getTargetBuffer(target);
1688 QueryBufferParameteriv(buffer, pname, params);
1689}
1690
1691void Context::getFramebufferAttachmentParameteriv(GLenum target,
1692 GLenum attachment,
1693 GLenum pname,
1694 GLint *params)
1695{
1696 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08001697 QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08001698}
1699
1700void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
1701{
1702 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
1703 QueryRenderbufferiv(this, renderbuffer, pname, params);
1704}
1705
1706void Context::getTexParameterfv(GLenum target, GLenum pname, GLfloat *params)
1707{
1708 Texture *texture = getTargetTexture(target);
1709 QueryTexParameterfv(texture, pname, params);
1710}
1711
1712void Context::getTexParameteriv(GLenum target, GLenum pname, GLint *params)
1713{
1714 Texture *texture = getTargetTexture(target);
1715 QueryTexParameteriv(texture, pname, params);
1716}
Jiajia Qin5451d532017-11-16 17:16:34 +08001717
1718void Context::getTexLevelParameteriv(GLenum target, GLint level, GLenum pname, GLint *params)
1719{
1720 Texture *texture =
1721 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
1722 QueryTexLevelParameteriv(texture, target, level, pname, params);
1723}
1724
1725void Context::getTexLevelParameterfv(GLenum target, GLint level, GLenum pname, GLfloat *params)
1726{
1727 Texture *texture =
1728 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
1729 QueryTexLevelParameterfv(texture, target, level, pname, params);
1730}
1731
He Yunchao010e4db2017-03-03 14:22:06 +08001732void Context::texParameterf(GLenum target, GLenum pname, GLfloat param)
1733{
1734 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001735 SetTexParameterf(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04001736 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001737}
1738
1739void Context::texParameterfv(GLenum target, GLenum pname, const GLfloat *params)
1740{
1741 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001742 SetTexParameterfv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04001743 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001744}
1745
1746void Context::texParameteri(GLenum target, GLenum pname, GLint param)
1747{
1748 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001749 SetTexParameteri(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04001750 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001751}
1752
1753void Context::texParameteriv(GLenum target, GLenum pname, const GLint *params)
1754{
1755 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001756 SetTexParameteriv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04001757 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001758}
1759
Jamie Madill675fe712016-12-19 13:07:54 -05001760void Context::drawArrays(GLenum mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001761{
Jamie Madill05b35b22017-10-03 09:01:44 -04001762 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001763 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
1764 MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001765}
1766
Jamie Madill675fe712016-12-19 13:07:54 -05001767void Context::drawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04001768{
Jamie Madill05b35b22017-10-03 09:01:44 -04001769 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001770 ANGLE_CONTEXT_TRY(
1771 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
1772 MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback());
Geoff Langf6db0982015-08-25 13:04:00 -04001773}
1774
Jamie Madill876429b2017-04-20 15:46:24 -04001775void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001776{
Jamie Madill05b35b22017-10-03 09:01:44 -04001777 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001778 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04001779}
1780
Jamie Madill675fe712016-12-19 13:07:54 -05001781void Context::drawElementsInstanced(GLenum mode,
1782 GLsizei count,
1783 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04001784 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04001785 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04001786{
Jamie Madill05b35b22017-10-03 09:01:44 -04001787 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001788 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08001789 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04001790}
1791
Jamie Madill675fe712016-12-19 13:07:54 -05001792void Context::drawRangeElements(GLenum mode,
1793 GLuint start,
1794 GLuint end,
1795 GLsizei count,
1796 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04001797 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04001798{
Jamie Madill05b35b22017-10-03 09:01:44 -04001799 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001800 ANGLE_CONTEXT_TRY(
1801 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001802}
1803
Jamie Madill876429b2017-04-20 15:46:24 -04001804void Context::drawArraysIndirect(GLenum mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08001805{
Jamie Madill05b35b22017-10-03 09:01:44 -04001806 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001807 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08001808}
1809
Jamie Madill876429b2017-04-20 15:46:24 -04001810void Context::drawElementsIndirect(GLenum mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08001811{
Jamie Madill05b35b22017-10-03 09:01:44 -04001812 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001813 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08001814}
1815
Jamie Madill675fe712016-12-19 13:07:54 -05001816void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001817{
Jamie Madillafa02a22017-11-23 12:57:38 -05001818 handleError(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05001819}
1820
Jamie Madill675fe712016-12-19 13:07:54 -05001821void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05001822{
Jamie Madillafa02a22017-11-23 12:57:38 -05001823 handleError(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001824}
1825
Austin Kinross6ee1e782015-05-29 17:05:37 -07001826void Context::insertEventMarker(GLsizei length, const char *marker)
1827{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001828 ASSERT(mImplementation);
1829 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07001830}
1831
1832void Context::pushGroupMarker(GLsizei length, const char *marker)
1833{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001834 ASSERT(mImplementation);
1835 mImplementation->pushGroupMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07001836}
1837
1838void Context::popGroupMarker()
1839{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001840 ASSERT(mImplementation);
1841 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07001842}
1843
Geoff Langd8605522016-04-13 10:19:12 -04001844void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
1845{
1846 Program *programObject = getProgram(program);
1847 ASSERT(programObject);
1848
1849 programObject->bindUniformLocation(location, name);
1850}
1851
Sami Väisänena797e062016-05-12 15:23:40 +03001852void Context::setCoverageModulation(GLenum components)
1853{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001854 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03001855}
1856
Sami Väisänene45e53b2016-05-25 10:36:04 +03001857void Context::loadPathRenderingMatrix(GLenum matrixMode, const GLfloat *matrix)
1858{
1859 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
1860}
1861
1862void Context::loadPathRenderingIdentityMatrix(GLenum matrixMode)
1863{
1864 GLfloat I[16];
1865 angle::Matrix<GLfloat>::setToIdentity(I);
1866
1867 mGLState.loadPathRenderingMatrix(matrixMode, I);
1868}
1869
1870void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
1871{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001872 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001873 if (!pathObj)
1874 return;
1875
1876 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1877 syncRendererState();
1878
1879 mImplementation->stencilFillPath(pathObj, fillMode, mask);
1880}
1881
1882void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
1883{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001884 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001885 if (!pathObj)
1886 return;
1887
1888 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1889 syncRendererState();
1890
1891 mImplementation->stencilStrokePath(pathObj, reference, mask);
1892}
1893
1894void Context::coverFillPath(GLuint path, GLenum coverMode)
1895{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001896 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001897 if (!pathObj)
1898 return;
1899
1900 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1901 syncRendererState();
1902
1903 mImplementation->coverFillPath(pathObj, coverMode);
1904}
1905
1906void Context::coverStrokePath(GLuint path, GLenum coverMode)
1907{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001908 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001909 if (!pathObj)
1910 return;
1911
1912 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1913 syncRendererState();
1914
1915 mImplementation->coverStrokePath(pathObj, coverMode);
1916}
1917
1918void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
1919{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001920 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001921 if (!pathObj)
1922 return;
1923
1924 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1925 syncRendererState();
1926
1927 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
1928}
1929
1930void Context::stencilThenCoverStrokePath(GLuint path,
1931 GLint reference,
1932 GLuint mask,
1933 GLenum coverMode)
1934{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001935 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001936 if (!pathObj)
1937 return;
1938
1939 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1940 syncRendererState();
1941
1942 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
1943}
1944
Sami Väisänend59ca052016-06-21 16:10:00 +03001945void Context::coverFillPathInstanced(GLsizei numPaths,
1946 GLenum pathNameType,
1947 const void *paths,
1948 GLuint pathBase,
1949 GLenum coverMode,
1950 GLenum transformType,
1951 const GLfloat *transformValues)
1952{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001953 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03001954
1955 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1956 syncRendererState();
1957
1958 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
1959}
Sami Väisänen46eaa942016-06-29 10:26:37 +03001960
Sami Väisänend59ca052016-06-21 16:10:00 +03001961void Context::coverStrokePathInstanced(GLsizei numPaths,
1962 GLenum pathNameType,
1963 const void *paths,
1964 GLuint pathBase,
1965 GLenum coverMode,
1966 GLenum transformType,
1967 const GLfloat *transformValues)
1968{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001969 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03001970
1971 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1972 syncRendererState();
1973
1974 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
1975 transformValues);
1976}
Sami Väisänen46eaa942016-06-29 10:26:37 +03001977
Sami Väisänend59ca052016-06-21 16:10:00 +03001978void Context::stencilFillPathInstanced(GLsizei numPaths,
1979 GLenum pathNameType,
1980 const void *paths,
1981 GLuint pathBase,
1982 GLenum fillMode,
1983 GLuint mask,
1984 GLenum transformType,
1985 const GLfloat *transformValues)
1986{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001987 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03001988
1989 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1990 syncRendererState();
1991
1992 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
1993 transformValues);
1994}
Sami Väisänen46eaa942016-06-29 10:26:37 +03001995
Sami Väisänend59ca052016-06-21 16:10:00 +03001996void Context::stencilStrokePathInstanced(GLsizei numPaths,
1997 GLenum pathNameType,
1998 const void *paths,
1999 GLuint pathBase,
2000 GLint reference,
2001 GLuint mask,
2002 GLenum transformType,
2003 const GLfloat *transformValues)
2004{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002005 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002006
2007 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2008 syncRendererState();
2009
2010 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2011 transformValues);
2012}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002013
Sami Väisänend59ca052016-06-21 16:10:00 +03002014void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2015 GLenum pathNameType,
2016 const void *paths,
2017 GLuint pathBase,
2018 GLenum fillMode,
2019 GLuint mask,
2020 GLenum coverMode,
2021 GLenum transformType,
2022 const GLfloat *transformValues)
2023{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002024 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002025
2026 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2027 syncRendererState();
2028
2029 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2030 transformType, transformValues);
2031}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002032
Sami Väisänend59ca052016-06-21 16:10:00 +03002033void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2034 GLenum pathNameType,
2035 const void *paths,
2036 GLuint pathBase,
2037 GLint reference,
2038 GLuint mask,
2039 GLenum coverMode,
2040 GLenum transformType,
2041 const GLfloat *transformValues)
2042{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002043 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002044
2045 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2046 syncRendererState();
2047
2048 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2049 transformType, transformValues);
2050}
2051
Sami Väisänen46eaa942016-06-29 10:26:37 +03002052void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2053{
2054 auto *programObject = getProgram(program);
2055
2056 programObject->bindFragmentInputLocation(location, name);
2057}
2058
2059void Context::programPathFragmentInputGen(GLuint program,
2060 GLint location,
2061 GLenum genMode,
2062 GLint components,
2063 const GLfloat *coeffs)
2064{
2065 auto *programObject = getProgram(program);
2066
Jamie Madillbd044ed2017-06-05 12:59:21 -04002067 programObject->pathFragmentInputGen(this, location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002068}
2069
jchen1015015f72017-03-16 13:54:21 +08002070GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2071{
jchen10fd7c3b52017-03-21 15:36:03 +08002072 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002073 return QueryProgramResourceIndex(programObject, programInterface, name);
2074}
2075
jchen10fd7c3b52017-03-21 15:36:03 +08002076void Context::getProgramResourceName(GLuint program,
2077 GLenum programInterface,
2078 GLuint index,
2079 GLsizei bufSize,
2080 GLsizei *length,
2081 GLchar *name)
2082{
2083 const auto *programObject = getProgram(program);
2084 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2085}
2086
jchen10191381f2017-04-11 13:59:04 +08002087GLint Context::getProgramResourceLocation(GLuint program,
2088 GLenum programInterface,
2089 const GLchar *name)
2090{
2091 const auto *programObject = getProgram(program);
2092 return QueryProgramResourceLocation(programObject, programInterface, name);
2093}
2094
jchen10880683b2017-04-12 16:21:55 +08002095void Context::getProgramResourceiv(GLuint program,
2096 GLenum programInterface,
2097 GLuint index,
2098 GLsizei propCount,
2099 const GLenum *props,
2100 GLsizei bufSize,
2101 GLsizei *length,
2102 GLint *params)
2103{
2104 const auto *programObject = getProgram(program);
2105 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2106 length, params);
2107}
2108
jchen10d9cd7b72017-08-30 15:04:25 +08002109void Context::getProgramInterfaceiv(GLuint program,
2110 GLenum programInterface,
2111 GLenum pname,
2112 GLint *params)
2113{
2114 const auto *programObject = getProgram(program);
2115 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2116}
2117
Jamie Madill71c88b32017-09-14 22:20:29 -04002118void Context::handleError(const Error &error)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002119{
Geoff Langda5777c2014-07-11 09:52:58 -04002120 if (error.isError())
2121 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002122 GLenum code = error.getCode();
2123 mErrors.insert(code);
2124 if (code == GL_OUT_OF_MEMORY && getWorkarounds().loseContextOnOutOfMemory)
2125 {
2126 markContextLost();
2127 }
Geoff Lang70d0f492015-12-10 17:45:46 -05002128
Geoff Langee6884e2017-11-09 16:51:11 -05002129 ASSERT(!error.getMessage().empty());
2130 mGLState.getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, error.getID(),
2131 GL_DEBUG_SEVERITY_HIGH, error.getMessage());
Geoff Langda5777c2014-07-11 09:52:58 -04002132 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002133}
2134
2135// Get one of the recorded errors and clear its flag, if any.
2136// [OpenGL ES 2.0.24] section 2.5 page 13.
2137GLenum Context::getError()
2138{
Geoff Langda5777c2014-07-11 09:52:58 -04002139 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002140 {
Geoff Langda5777c2014-07-11 09:52:58 -04002141 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002142 }
Geoff Langda5777c2014-07-11 09:52:58 -04002143 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002144 {
Geoff Langda5777c2014-07-11 09:52:58 -04002145 GLenum error = *mErrors.begin();
2146 mErrors.erase(mErrors.begin());
2147 return error;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002148 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002149}
2150
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002151// NOTE: this function should not assume that this context is current!
2152void Context::markContextLost()
2153{
2154 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002155 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002156 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002157 mContextLostForced = true;
2158 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002159 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002160}
2161
2162bool Context::isContextLost()
2163{
2164 return mContextLost;
2165}
2166
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002167GLenum Context::getResetStatus()
2168{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002169 // Even if the application doesn't want to know about resets, we want to know
2170 // as it will allow us to skip all the calls.
2171 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002172 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002173 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002174 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002175 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002176 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002177
2178 // EXT_robustness, section 2.6: If the reset notification behavior is
2179 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2180 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2181 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002182 }
2183
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002184 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2185 // status should be returned at least once, and GL_NO_ERROR should be returned
2186 // once the device has finished resetting.
2187 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002188 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002189 ASSERT(mResetStatus == GL_NO_ERROR);
2190 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002191
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002192 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002193 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002194 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002195 }
2196 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002197 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002198 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002199 // If markContextLost was used to mark the context lost then
2200 // assume that is not recoverable, and continue to report the
2201 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002202 mResetStatus = mImplementation->getResetStatus();
2203 }
Jamie Madill893ab082014-05-16 16:56:10 -04002204
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002205 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002206}
2207
2208bool Context::isResetNotificationEnabled()
2209{
2210 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2211}
2212
Corentin Walleze3b10e82015-05-20 11:06:25 -04002213const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002214{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002215 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002216}
2217
2218EGLenum Context::getClientType() const
2219{
2220 return mClientType;
2221}
2222
2223EGLenum Context::getRenderBuffer() const
2224{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002225 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2226 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002227 {
2228 return EGL_NONE;
2229 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002230
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002231 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002232 ASSERT(backAttachment != nullptr);
2233 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002234}
2235
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002236VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002237{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002238 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002239 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2240 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002241 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002242 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2243 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002244
Jamie Madill96a483b2017-06-27 16:49:21 -04002245 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002246 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002247
2248 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002249}
2250
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002251TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002252{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002253 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002254 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2255 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002256 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002257 transformFeedback =
2258 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002259 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002260 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002261 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002262
2263 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002264}
2265
2266bool Context::isVertexArrayGenerated(GLuint vertexArray)
2267{
Jamie Madill96a483b2017-06-27 16:49:21 -04002268 ASSERT(mVertexArrayMap.contains(0));
2269 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002270}
2271
2272bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2273{
Jamie Madill96a483b2017-06-27 16:49:21 -04002274 ASSERT(mTransformFeedbackMap.contains(0));
2275 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002276}
2277
Shannon Woods53a94a82014-06-24 15:20:36 -04002278void Context::detachTexture(GLuint texture)
2279{
2280 // Simple pass-through to State's detachTexture method, as textures do not require
2281 // allocation map management either here or in the resource manager at detach time.
2282 // Zero textures are held by the Context, and we don't attempt to request them from
2283 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002284 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002285}
2286
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002287void Context::detachBuffer(GLuint buffer)
2288{
Yuly Novikov5807a532015-12-03 13:01:22 -05002289 // Simple pass-through to State's detachBuffer method, since
2290 // only buffer attachments to container objects that are bound to the current context
2291 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002292
Yuly Novikov5807a532015-12-03 13:01:22 -05002293 // [OpenGL ES 3.2] section 5.1.2 page 45:
2294 // Attachments to unbound container objects, such as
2295 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2296 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002297 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002298}
2299
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002300void Context::detachFramebuffer(GLuint framebuffer)
2301{
Shannon Woods53a94a82014-06-24 15:20:36 -04002302 // Framebuffer detachment is handled by Context, because 0 is a valid
2303 // Framebuffer object, and a pointer to it must be passed from Context
2304 // to State at binding time.
2305
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002306 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002307 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2308 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2309 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002310
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002311 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002312 {
2313 bindReadFramebuffer(0);
2314 }
2315
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002316 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002317 {
2318 bindDrawFramebuffer(0);
2319 }
2320}
2321
2322void Context::detachRenderbuffer(GLuint renderbuffer)
2323{
Jamie Madilla02315b2017-02-23 14:14:47 -05002324 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002325}
2326
Jamie Madill57a89722013-07-02 11:57:03 -04002327void Context::detachVertexArray(GLuint vertexArray)
2328{
Jamie Madill77a72f62015-04-14 11:18:32 -04002329 // Vertex array detachment is handled by Context, because 0 is a valid
2330 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002331 // binding time.
2332
Jamie Madill57a89722013-07-02 11:57:03 -04002333 // [OpenGL ES 3.0.2] section 2.10 page 43:
2334 // If a vertex array object that is currently bound is deleted, the binding
2335 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002336 if (mGLState.removeVertexArrayBinding(vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002337 {
2338 bindVertexArray(0);
2339 }
2340}
2341
Geoff Langc8058452014-02-03 12:04:11 -05002342void Context::detachTransformFeedback(GLuint transformFeedback)
2343{
Corentin Walleza2257da2016-04-19 16:43:12 -04002344 // Transform feedback detachment is handled by Context, because 0 is a valid
2345 // transform feedback, and a pointer to it must be passed from Context to State at
2346 // binding time.
2347
2348 // The OpenGL specification doesn't mention what should happen when the currently bound
2349 // transform feedback object is deleted. Since it is a container object, we treat it like
2350 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002351 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002352 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002353 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002354 }
Geoff Langc8058452014-02-03 12:04:11 -05002355}
2356
Jamie Madilldc356042013-07-19 16:36:57 -04002357void Context::detachSampler(GLuint sampler)
2358{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002359 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002360}
2361
Yunchao Hea336b902017-08-02 16:05:21 +08002362void Context::detachProgramPipeline(GLuint pipeline)
2363{
2364 mGLState.detachProgramPipeline(this, pipeline);
2365}
2366
Jamie Madill3ef140a2017-08-26 23:11:21 -04002367void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002368{
Shaodde78e82017-05-22 14:13:27 +08002369 mGLState.setVertexAttribDivisor(this, index, divisor);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002370}
2371
Jamie Madille29d1672013-07-19 16:36:57 -04002372void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2373{
Geoff Langc1984ed2016-10-07 12:41:00 -04002374 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002375 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002376 SetSamplerParameteri(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002377 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002378}
Jamie Madille29d1672013-07-19 16:36:57 -04002379
Geoff Langc1984ed2016-10-07 12:41:00 -04002380void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2381{
2382 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002383 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002384 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002385 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002386}
2387
2388void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2389{
Geoff Langc1984ed2016-10-07 12:41:00 -04002390 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002391 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002392 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002393 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002394}
2395
Geoff Langc1984ed2016-10-07 12:41:00 -04002396void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002397{
Geoff Langc1984ed2016-10-07 12:41:00 -04002398 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002399 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002400 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002401 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002402}
2403
Geoff Langc1984ed2016-10-07 12:41:00 -04002404void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002405{
Geoff Langc1984ed2016-10-07 12:41:00 -04002406 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002407 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002408 QuerySamplerParameteriv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002409 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002410}
Jamie Madill9675b802013-07-19 16:36:59 -04002411
Geoff Langc1984ed2016-10-07 12:41:00 -04002412void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2413{
2414 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002415 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002416 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002417 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002418}
2419
Olli Etuahof0fee072016-03-30 15:11:58 +03002420void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2421{
2422 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002423 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002424}
2425
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002426void Context::initRendererString()
2427{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002428 std::ostringstream rendererString;
2429 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002430 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002431 rendererString << ")";
2432
Geoff Langcec35902014-04-16 10:52:36 -04002433 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002434}
2435
Geoff Langc339c4e2016-11-29 10:37:36 -05002436void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002437{
Geoff Langc339c4e2016-11-29 10:37:36 -05002438 const Version &clientVersion = getClientVersion();
2439
2440 std::ostringstream versionString;
2441 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2442 << ANGLE_VERSION_STRING << ")";
2443 mVersionString = MakeStaticString(versionString.str());
2444
2445 std::ostringstream shadingLanguageVersionString;
2446 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2447 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2448 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2449 << ")";
2450 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002451}
2452
Geoff Langcec35902014-04-16 10:52:36 -04002453void Context::initExtensionStrings()
2454{
Geoff Langc339c4e2016-11-29 10:37:36 -05002455 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2456 std::ostringstream combinedStringStream;
2457 std::copy(strings.begin(), strings.end(),
2458 std::ostream_iterator<const char *>(combinedStringStream, " "));
2459 return MakeStaticString(combinedStringStream.str());
2460 };
2461
2462 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002463 for (const auto &extensionString : mExtensions.getStrings())
2464 {
2465 mExtensionStrings.push_back(MakeStaticString(extensionString));
2466 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002467 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002468
Bryan Bernhart58806562017-01-05 13:09:31 -08002469 const gl::Extensions &nativeExtensions = mImplementation->getNativeExtensions();
2470
Geoff Langc339c4e2016-11-29 10:37:36 -05002471 mRequestableExtensionStrings.clear();
2472 for (const auto &extensionInfo : GetExtensionInfoMap())
2473 {
2474 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08002475 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
2476 nativeExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002477 {
2478 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
2479 }
2480 }
2481 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002482}
2483
Geoff Langc339c4e2016-11-29 10:37:36 -05002484const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04002485{
Geoff Langc339c4e2016-11-29 10:37:36 -05002486 switch (name)
2487 {
2488 case GL_VENDOR:
2489 return reinterpret_cast<const GLubyte *>("Google Inc.");
2490
2491 case GL_RENDERER:
2492 return reinterpret_cast<const GLubyte *>(mRendererString);
2493
2494 case GL_VERSION:
2495 return reinterpret_cast<const GLubyte *>(mVersionString);
2496
2497 case GL_SHADING_LANGUAGE_VERSION:
2498 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
2499
2500 case GL_EXTENSIONS:
2501 return reinterpret_cast<const GLubyte *>(mExtensionString);
2502
2503 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2504 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
2505
2506 default:
2507 UNREACHABLE();
2508 return nullptr;
2509 }
Geoff Langcec35902014-04-16 10:52:36 -04002510}
2511
Geoff Langc339c4e2016-11-29 10:37:36 -05002512const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04002513{
Geoff Langc339c4e2016-11-29 10:37:36 -05002514 switch (name)
2515 {
2516 case GL_EXTENSIONS:
2517 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
2518
2519 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2520 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
2521
2522 default:
2523 UNREACHABLE();
2524 return nullptr;
2525 }
Geoff Langcec35902014-04-16 10:52:36 -04002526}
2527
2528size_t Context::getExtensionStringCount() const
2529{
2530 return mExtensionStrings.size();
2531}
2532
Geoff Lang111a99e2017-10-17 10:58:41 -04002533bool Context::isExtensionRequestable(const char *name)
2534{
2535 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2536 auto extension = extensionInfos.find(name);
2537
2538 const Extensions &nativeExtensions = mImplementation->getNativeExtensions();
2539 return extension != extensionInfos.end() && extension->second.Requestable &&
2540 nativeExtensions.*(extension->second.ExtensionsMember);
2541}
2542
Geoff Langc339c4e2016-11-29 10:37:36 -05002543void Context::requestExtension(const char *name)
2544{
2545 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2546 ASSERT(extensionInfos.find(name) != extensionInfos.end());
2547 const auto &extension = extensionInfos.at(name);
2548 ASSERT(extension.Requestable);
Geoff Lang111a99e2017-10-17 10:58:41 -04002549 ASSERT(mImplementation->getNativeExtensions().*(extension.ExtensionsMember));
Geoff Langc339c4e2016-11-29 10:37:36 -05002550
2551 if (mExtensions.*(extension.ExtensionsMember))
2552 {
2553 // Extension already enabled
2554 return;
2555 }
2556
2557 mExtensions.*(extension.ExtensionsMember) = true;
2558 updateCaps();
2559 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08002560
Jamie Madill2f348d22017-06-05 10:50:59 -04002561 // Release the shader compiler so it will be re-created with the requested extensions enabled.
2562 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04002563
Jamie Madill81c2e252017-09-09 23:32:46 -04002564 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
2565 // sampleable.
2566 mState.mTextures->signalAllTexturesDirty();
Geoff Lang9aded172017-04-05 11:07:56 -04002567 for (auto &zeroTexture : mZeroTextures)
2568 {
Jamie Madill05b35b22017-10-03 09:01:44 -04002569 zeroTexture.second->signalDirty(InitState::Initialized);
Geoff Lang9aded172017-04-05 11:07:56 -04002570 }
2571
2572 mState.mFramebuffers->invalidateFramebufferComplenessCache();
Geoff Langc339c4e2016-11-29 10:37:36 -05002573}
2574
2575size_t Context::getRequestableExtensionStringCount() const
2576{
2577 return mRequestableExtensionStrings.size();
2578}
2579
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002580void Context::beginTransformFeedback(GLenum primitiveMode)
2581{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002582 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002583 ASSERT(transformFeedback != nullptr);
2584 ASSERT(!transformFeedback->isPaused());
2585
Jamie Madill6c1f6712017-02-14 19:08:04 -05002586 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002587}
2588
2589bool Context::hasActiveTransformFeedback(GLuint program) const
2590{
2591 for (auto pair : mTransformFeedbackMap)
2592 {
2593 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
2594 {
2595 return true;
2596 }
2597 }
2598 return false;
2599}
2600
Geoff Langb433e872017-10-05 14:01:47 -04002601void Context::initCaps(const egl::DisplayExtensions &displayExtensions, bool robustResourceInit)
Geoff Lang493daf52014-07-03 13:38:44 -04002602{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002603 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04002604
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002605 mExtensions = mImplementation->getNativeExtensions();
Geoff Lang493daf52014-07-03 13:38:44 -04002606
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002607 mLimitations = mImplementation->getNativeLimitations();
Austin Kinross02df7962015-07-01 10:03:42 -07002608
Geoff Langeb66a6e2016-10-31 13:06:12 -04002609 if (getClientVersion() < Version(3, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002610 {
2611 // Disable ES3+ extensions
Jamie Madill231c7f52017-04-26 13:45:37 -04002612 mExtensions.colorBufferFloat = false;
Geoff Langb66a9092016-05-16 15:59:14 -04002613 mExtensions.eglImageExternalEssl3 = false;
Vincent Lang25ab4512016-05-13 18:13:59 +02002614 mExtensions.textureNorm16 = false;
Martin Radev137032d2017-07-13 10:11:12 +03002615 mExtensions.multiview = false;
2616 mExtensions.maxViews = 1u;
Geoff Lang493daf52014-07-03 13:38:44 -04002617 }
2618
Jiawei Shao89be29a2017-11-06 14:36:45 +08002619 if (getClientVersion() < ES_3_1)
2620 {
2621 // Disable ES3.1+ extensions
2622 mExtensions.geometryShader = false;
2623 }
2624
Geoff Langeb66a6e2016-10-31 13:06:12 -04002625 if (getClientVersion() > Version(2, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002626 {
2627 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
Jamie Madill231c7f52017-04-26 13:45:37 -04002628 // mExtensions.sRGB = false;
Geoff Lang493daf52014-07-03 13:38:44 -04002629 }
2630
Jamie Madill00ed7a12016-05-19 13:13:38 -04002631 // Some extensions are always available because they are implemented in the GL layer.
Jamie Madill231c7f52017-04-26 13:45:37 -04002632 mExtensions.bindUniformLocation = true;
2633 mExtensions.vertexArrayObject = true;
Geoff Langf41a7152016-09-19 15:11:17 -04002634 mExtensions.bindGeneratesResource = true;
Geoff Langfeb8c682017-02-13 16:07:35 -05002635 mExtensions.clientArrays = true;
Geoff Langc339c4e2016-11-29 10:37:36 -05002636 mExtensions.requestExtension = true;
Jamie Madill00ed7a12016-05-19 13:13:38 -04002637
2638 // Enable the no error extension if the context was created with the flag.
2639 mExtensions.noError = mSkipValidation;
2640
Corentin Wallezccab69d2017-01-27 16:57:15 -05002641 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Corentin Wallezc295e512017-01-27 17:47:50 -05002642 mExtensions.surfacelessContext = displayExtensions.surfacelessContext;
Corentin Wallezccab69d2017-01-27 16:57:15 -05002643
Geoff Lang70d0f492015-12-10 17:45:46 -05002644 // Explicitly enable GL_KHR_debug
2645 mExtensions.debug = true;
2646 mExtensions.maxDebugMessageLength = 1024;
2647 mExtensions.maxDebugLoggedMessages = 1024;
2648 mExtensions.maxDebugGroupStackDepth = 1024;
2649 mExtensions.maxLabelLength = 1024;
2650
Geoff Langff5b2d52016-09-07 11:32:23 -04002651 // Explicitly enable GL_ANGLE_robust_client_memory
2652 mExtensions.robustClientMemory = true;
2653
Jamie Madille08a1d32017-03-07 17:24:06 -05002654 // Determine robust resource init availability from EGL.
Geoff Langb433e872017-10-05 14:01:47 -04002655 mExtensions.robustResourceInitialization = robustResourceInit;
Jamie Madille08a1d32017-03-07 17:24:06 -05002656
Jiajia Qin8a7b3a02017-08-25 16:05:48 +08002657 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
2658 // supports it.
2659 mExtensions.robustBufferAccessBehavior =
2660 mRobustAccess && mExtensions.robustBufferAccessBehavior;
2661
Jamie Madillc43be722017-07-13 16:22:14 -04002662 // Enable the cache control query unconditionally.
2663 mExtensions.programCacheControl = true;
2664
Geoff Lang301d1612014-07-09 10:34:37 -04002665 // Apply implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04002666 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002667
Jamie Madill0f80ed82017-09-19 00:24:56 -04002668 if (getClientVersion() < ES_3_1)
2669 {
2670 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
2671 }
2672 else
2673 {
2674 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
2675 }
Geoff Lang301d1612014-07-09 10:34:37 -04002676
Jamie Madill0f80ed82017-09-19 00:24:56 -04002677 LimitCap(&mCaps.maxVertexUniformBlocks, IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
2678 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
2679 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
2680
2681 // Limit textures as well, so we can use fast bitsets with texture bindings.
2682 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
2683 LimitCap(&mCaps.maxVertexTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
2684 LimitCap(&mCaps.maxTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04002685
Jiawei Shaodb342272017-09-27 10:21:45 +08002686 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
2687
Geoff Langc287ea62016-09-16 14:46:51 -04002688 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002689 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04002690 for (const auto &extensionInfo : GetExtensionInfoMap())
2691 {
2692 // If this context is for WebGL, disable all enableable extensions
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002693 if (mWebGLContext && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04002694 {
2695 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
2696 }
2697 }
2698
2699 // Generate texture caps
2700 updateCaps();
2701}
2702
2703void Context::updateCaps()
2704{
Geoff Lang900013c2014-07-07 11:32:19 -04002705 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002706 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04002707
Jamie Madill7b62cf92017-11-02 15:20:49 -04002708 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04002709 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04002710 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04002711 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04002712
Geoff Lang0d8b7242015-09-09 14:56:53 -04002713 // Update the format caps based on the client version and extensions.
2714 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
2715 // ES3.
2716 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002717 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002718 formatCaps.renderable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002719 formatCaps.renderable && formatInfo.renderSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002720 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002721 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04002722
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002723 // OpenGL ES does not support multisampling with non-rendererable formats
2724 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Olli Etuaho50c562d2017-06-06 14:43:30 +03002725 if (!formatCaps.renderable ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002726 (getClientVersion() < ES_3_1 &&
2727 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04002728 {
Geoff Langd87878e2014-09-19 15:42:59 -04002729 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04002730 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03002731 else
2732 {
2733 // We may have limited the max samples for some required renderbuffer formats due to
2734 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
2735 GLuint formatMaxSamples = formatCaps.getMaxSamples();
2736
2737 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
2738 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
2739 // exception of signed and unsigned integer formats."
2740 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
2741 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
2742 {
2743 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
2744 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
2745 }
2746
2747 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
2748 if (getClientVersion() >= ES_3_1)
2749 {
2750 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
2751 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
2752 // the exception that the signed and unsigned integer formats are required only to
2753 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
2754 // multisamples, which must be at least one."
2755 if (formatInfo.componentType == GL_INT ||
2756 formatInfo.componentType == GL_UNSIGNED_INT)
2757 {
2758 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
2759 }
2760
2761 // GLES 3.1 section 19.3.1.
2762 if (formatCaps.texturable)
2763 {
2764 if (formatInfo.depthBits > 0)
2765 {
2766 mCaps.maxDepthTextureSamples =
2767 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
2768 }
2769 else if (formatInfo.redBits > 0)
2770 {
2771 mCaps.maxColorTextureSamples =
2772 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
2773 }
2774 }
2775 }
2776 }
Geoff Langd87878e2014-09-19 15:42:59 -04002777
2778 if (formatCaps.texturable && formatInfo.compressed)
2779 {
Geoff Langca271392017-04-05 12:30:00 -04002780 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04002781 }
2782
Geoff Langca271392017-04-05 12:30:00 -04002783 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04002784 }
Jamie Madill32447362017-06-28 14:53:52 -04002785
2786 // If program binary is disabled, blank out the memory cache pointer.
2787 if (!mImplementation->getNativeExtensions().getProgramBinary)
2788 {
2789 mMemoryProgramCache = nullptr;
2790 }
Corentin Walleze4477002017-12-01 14:39:58 -05002791
2792 // Compute which buffer types are allowed
2793 mValidBufferBindings.reset();
2794 mValidBufferBindings.set(BufferBinding::ElementArray);
2795 mValidBufferBindings.set(BufferBinding::Array);
2796
2797 if (mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
2798 {
2799 mValidBufferBindings.set(BufferBinding::PixelPack);
2800 mValidBufferBindings.set(BufferBinding::PixelUnpack);
2801 }
2802
2803 if (getClientVersion() >= ES_3_0)
2804 {
2805 mValidBufferBindings.set(BufferBinding::CopyRead);
2806 mValidBufferBindings.set(BufferBinding::CopyWrite);
2807 mValidBufferBindings.set(BufferBinding::TransformFeedback);
2808 mValidBufferBindings.set(BufferBinding::Uniform);
2809 }
2810
2811 if (getClientVersion() >= ES_3_1)
2812 {
2813 mValidBufferBindings.set(BufferBinding::AtomicCounter);
2814 mValidBufferBindings.set(BufferBinding::ShaderStorage);
2815 mValidBufferBindings.set(BufferBinding::DrawIndirect);
2816 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
2817 }
Geoff Lang493daf52014-07-03 13:38:44 -04002818}
2819
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002820void Context::initWorkarounds()
2821{
Jamie Madill761b02c2017-06-23 16:27:06 -04002822 // Apply back-end workarounds.
2823 mImplementation->applyNativeWorkarounds(&mWorkarounds);
2824
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002825 // Lose the context upon out of memory error if the application is
2826 // expecting to watch for those events.
2827 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2828}
2829
Jamie Madill05b35b22017-10-03 09:01:44 -04002830Error Context::prepareForDraw()
2831{
2832 syncRendererState();
Jamie Madilla59fc192017-11-02 12:57:58 -04002833
2834 if (isRobustResourceInitEnabled())
2835 {
2836 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
2837 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
2838 }
2839
Jamie Madill05b35b22017-10-03 09:01:44 -04002840 return NoError();
2841}
2842
Jamie Madill1b94d432015-08-07 13:23:23 -04002843void Context::syncRendererState()
2844{
Jamie Madill7d1f5c62017-09-02 15:32:15 -04002845 mGLState.syncDirtyObjects(this);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002846 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
Jamie Madillfe548342017-06-19 11:13:24 -04002847 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002848 mGLState.clearDirtyBits();
Jamie Madill1b94d432015-08-07 13:23:23 -04002849}
2850
Jamie Madillad9f24e2016-02-12 09:27:24 -05002851void Context::syncRendererState(const State::DirtyBits &bitMask,
2852 const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04002853{
Jamie Madill7d1f5c62017-09-02 15:32:15 -04002854 mGLState.syncDirtyObjects(this, objectMask);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002855 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madillfe548342017-06-19 11:13:24 -04002856 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002857 mGLState.clearDirtyBits(dirtyBits);
Jamie Madill1b94d432015-08-07 13:23:23 -04002858}
Jamie Madillc29968b2016-01-20 11:17:23 -05002859
2860void Context::blitFramebuffer(GLint srcX0,
2861 GLint srcY0,
2862 GLint srcX1,
2863 GLint srcY1,
2864 GLint dstX0,
2865 GLint dstY0,
2866 GLint dstX1,
2867 GLint dstY1,
2868 GLbitfield mask,
2869 GLenum filter)
2870{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002871 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002872 ASSERT(drawFramebuffer);
2873
2874 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
2875 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
2876
Jamie Madillad9f24e2016-02-12 09:27:24 -05002877 syncStateForBlit();
Jamie Madillc29968b2016-01-20 11:17:23 -05002878
Jamie Madillc564c072017-06-01 12:45:42 -04002879 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002880}
Jamie Madillc29968b2016-01-20 11:17:23 -05002881
2882void Context::clear(GLbitfield mask)
2883{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002884 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002885 handleError(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05002886}
2887
2888void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
2889{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002890 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002891 handleError(mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002892}
2893
2894void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
2895{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002896 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002897 handleError(mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002898}
2899
2900void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
2901{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002902 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002903 handleError(mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002904}
2905
2906void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
2907{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002908 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002909 ASSERT(framebufferObject);
2910
2911 // If a buffer is not present, the clear has no effect
2912 if (framebufferObject->getDepthbuffer() == nullptr &&
2913 framebufferObject->getStencilbuffer() == nullptr)
2914 {
2915 return;
2916 }
2917
Jamie Madillad9f24e2016-02-12 09:27:24 -05002918 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002919 handleError(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05002920}
2921
2922void Context::readPixels(GLint x,
2923 GLint y,
2924 GLsizei width,
2925 GLsizei height,
2926 GLenum format,
2927 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002928 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05002929{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04002930 if (width == 0 || height == 0)
2931 {
2932 return;
2933 }
2934
Jamie Madillad9f24e2016-02-12 09:27:24 -05002935 syncStateForReadPixels();
Jamie Madillc29968b2016-01-20 11:17:23 -05002936
Jamie Madillb6664922017-07-25 12:55:04 -04002937 Framebuffer *readFBO = mGLState.getReadFramebuffer();
2938 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05002939
2940 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04002941 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05002942}
2943
2944void Context::copyTexImage2D(GLenum target,
2945 GLint level,
2946 GLenum internalformat,
2947 GLint x,
2948 GLint y,
2949 GLsizei width,
2950 GLsizei height,
2951 GLint border)
2952{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002953 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002954 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002955
Jamie Madillc29968b2016-01-20 11:17:23 -05002956 Rectangle sourceArea(x, y, width, height);
2957
Jamie Madill05b35b22017-10-03 09:01:44 -04002958 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002959 Texture *texture =
2960 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05002961 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05002962}
2963
2964void Context::copyTexSubImage2D(GLenum target,
2965 GLint level,
2966 GLint xoffset,
2967 GLint yoffset,
2968 GLint x,
2969 GLint y,
2970 GLsizei width,
2971 GLsizei height)
2972{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04002973 if (width == 0 || height == 0)
2974 {
2975 return;
2976 }
2977
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002978 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002979 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002980
Jamie Madillc29968b2016-01-20 11:17:23 -05002981 Offset destOffset(xoffset, yoffset, 0);
2982 Rectangle sourceArea(x, y, width, height);
2983
Jamie Madill05b35b22017-10-03 09:01:44 -04002984 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002985 Texture *texture =
2986 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05002987 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05002988}
2989
2990void Context::copyTexSubImage3D(GLenum target,
2991 GLint level,
2992 GLint xoffset,
2993 GLint yoffset,
2994 GLint zoffset,
2995 GLint x,
2996 GLint y,
2997 GLsizei width,
2998 GLsizei height)
2999{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003000 if (width == 0 || height == 0)
3001 {
3002 return;
3003 }
3004
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003005 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003006 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003007
Jamie Madillc29968b2016-01-20 11:17:23 -05003008 Offset destOffset(xoffset, yoffset, zoffset);
3009 Rectangle sourceArea(x, y, width, height);
3010
Jamie Madill05b35b22017-10-03 09:01:44 -04003011 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3012 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003013 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003014}
3015
3016void Context::framebufferTexture2D(GLenum target,
3017 GLenum attachment,
3018 GLenum textarget,
3019 GLuint texture,
3020 GLint level)
3021{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003022 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003023 ASSERT(framebuffer);
3024
3025 if (texture != 0)
3026 {
3027 Texture *textureObj = getTexture(texture);
3028
3029 ImageIndex index = ImageIndex::MakeInvalid();
3030
3031 if (textarget == GL_TEXTURE_2D)
3032 {
3033 index = ImageIndex::Make2D(level);
3034 }
Corentin Wallez13c0dd42017-07-04 18:27:01 -04003035 else if (textarget == GL_TEXTURE_RECTANGLE_ANGLE)
3036 {
3037 index = ImageIndex::MakeRectangle(level);
3038 }
JiangYizhoubddc46b2016-12-09 09:50:51 +08003039 else if (textarget == GL_TEXTURE_2D_MULTISAMPLE)
3040 {
3041 ASSERT(level == 0);
3042 index = ImageIndex::Make2DMultisample();
3043 }
Jamie Madillc29968b2016-01-20 11:17:23 -05003044 else
3045 {
3046 ASSERT(IsCubeMapTextureTarget(textarget));
3047 index = ImageIndex::MakeCube(textarget, level);
3048 }
3049
Jamie Madilla02315b2017-02-23 14:14:47 -05003050 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003051 }
3052 else
3053 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003054 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003055 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003056
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003057 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003058}
3059
3060void Context::framebufferRenderbuffer(GLenum target,
3061 GLenum attachment,
3062 GLenum renderbuffertarget,
3063 GLuint renderbuffer)
3064{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003065 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003066 ASSERT(framebuffer);
3067
3068 if (renderbuffer != 0)
3069 {
3070 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003071
3072 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex::MakeInvalid(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003073 renderbufferObject);
3074 }
3075 else
3076 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003077 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003078 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003079
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003080 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003081}
3082
3083void Context::framebufferTextureLayer(GLenum target,
3084 GLenum attachment,
3085 GLuint texture,
3086 GLint level,
3087 GLint layer)
3088{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003089 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003090 ASSERT(framebuffer);
3091
3092 if (texture != 0)
3093 {
3094 Texture *textureObject = getTexture(texture);
3095
3096 ImageIndex index = ImageIndex::MakeInvalid();
3097
3098 if (textureObject->getTarget() == GL_TEXTURE_3D)
3099 {
3100 index = ImageIndex::Make3D(level, layer);
3101 }
3102 else
3103 {
3104 ASSERT(textureObject->getTarget() == GL_TEXTURE_2D_ARRAY);
3105 index = ImageIndex::Make2DArray(level, layer);
3106 }
3107
Jamie Madilla02315b2017-02-23 14:14:47 -05003108 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003109 }
3110 else
3111 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003112 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003113 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003114
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003115 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003116}
3117
Martin Radev137032d2017-07-13 10:11:12 +03003118void Context::framebufferTextureMultiviewLayeredANGLE(GLenum target,
3119 GLenum attachment,
3120 GLuint texture,
3121 GLint level,
3122 GLint baseViewIndex,
3123 GLsizei numViews)
3124{
Martin Radev82ef7742017-08-08 17:44:58 +03003125 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3126 ASSERT(framebuffer);
3127
3128 if (texture != 0)
3129 {
3130 Texture *textureObj = getTexture(texture);
3131
Martin Radev18b75ba2017-08-15 15:50:40 +03003132 ImageIndex index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
Martin Radev82ef7742017-08-08 17:44:58 +03003133 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3134 numViews, baseViewIndex);
3135 }
3136 else
3137 {
3138 framebuffer->resetAttachment(this, attachment);
3139 }
3140
3141 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003142}
3143
3144void Context::framebufferTextureMultiviewSideBySideANGLE(GLenum target,
3145 GLenum attachment,
3146 GLuint texture,
3147 GLint level,
3148 GLsizei numViews,
3149 const GLint *viewportOffsets)
3150{
Martin Radev5dae57b2017-07-14 16:15:55 +03003151 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3152 ASSERT(framebuffer);
3153
3154 if (texture != 0)
3155 {
3156 Texture *textureObj = getTexture(texture);
3157
3158 ImageIndex index = ImageIndex::Make2D(level);
3159 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3160 textureObj, numViews, viewportOffsets);
3161 }
3162 else
3163 {
3164 framebuffer->resetAttachment(this, attachment);
3165 }
3166
3167 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003168}
3169
Jamie Madillc29968b2016-01-20 11:17:23 -05003170void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3171{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003172 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003173 ASSERT(framebuffer);
3174 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003175 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003176}
3177
3178void Context::readBuffer(GLenum mode)
3179{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003180 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003181 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003182 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003183}
3184
3185void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3186{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003187 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003188 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003189
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003190 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003191 ASSERT(framebuffer);
3192
3193 // The specification isn't clear what should be done when the framebuffer isn't complete.
3194 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003195 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003196}
3197
3198void Context::invalidateFramebuffer(GLenum target,
3199 GLsizei numAttachments,
3200 const GLenum *attachments)
3201{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003202 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003203 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003204
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003205 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003206 ASSERT(framebuffer);
3207
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003208 if (framebuffer->checkStatus(this) != GL_FRAMEBUFFER_COMPLETE)
Jamie Madillc29968b2016-01-20 11:17:23 -05003209 {
Jamie Madill437fa652016-05-03 15:13:24 -04003210 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003211 }
Jamie Madill437fa652016-05-03 15:13:24 -04003212
Jamie Madill4928b7c2017-06-20 12:57:39 -04003213 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003214}
3215
3216void Context::invalidateSubFramebuffer(GLenum target,
3217 GLsizei numAttachments,
3218 const GLenum *attachments,
3219 GLint x,
3220 GLint y,
3221 GLsizei width,
3222 GLsizei height)
3223{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003224 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003225 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003226
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003227 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003228 ASSERT(framebuffer);
3229
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003230 if (framebuffer->checkStatus(this) != GL_FRAMEBUFFER_COMPLETE)
Jamie Madillc29968b2016-01-20 11:17:23 -05003231 {
Jamie Madill437fa652016-05-03 15:13:24 -04003232 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003233 }
Jamie Madill437fa652016-05-03 15:13:24 -04003234
3235 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003236 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003237}
3238
Jamie Madill73a84962016-02-12 09:27:23 -05003239void Context::texImage2D(GLenum target,
3240 GLint level,
3241 GLint internalformat,
3242 GLsizei width,
3243 GLsizei height,
3244 GLint border,
3245 GLenum format,
3246 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003247 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003248{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003249 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003250
3251 Extents size(width, height, 1);
3252 Texture *texture =
3253 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003254 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3255 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003256}
3257
3258void Context::texImage3D(GLenum target,
3259 GLint level,
3260 GLint internalformat,
3261 GLsizei width,
3262 GLsizei height,
3263 GLsizei depth,
3264 GLint border,
3265 GLenum format,
3266 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003267 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003268{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003269 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003270
3271 Extents size(width, height, depth);
3272 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003273 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3274 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003275}
3276
3277void Context::texSubImage2D(GLenum target,
3278 GLint level,
3279 GLint xoffset,
3280 GLint yoffset,
3281 GLsizei width,
3282 GLsizei height,
3283 GLenum format,
3284 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003285 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003286{
3287 // Zero sized uploads are valid but no-ops
3288 if (width == 0 || height == 0)
3289 {
3290 return;
3291 }
3292
Jamie Madillad9f24e2016-02-12 09:27:24 -05003293 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003294
3295 Box area(xoffset, yoffset, 0, width, height, 1);
3296 Texture *texture =
3297 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003298 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3299 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003300}
3301
3302void Context::texSubImage3D(GLenum target,
3303 GLint level,
3304 GLint xoffset,
3305 GLint yoffset,
3306 GLint zoffset,
3307 GLsizei width,
3308 GLsizei height,
3309 GLsizei depth,
3310 GLenum format,
3311 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003312 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003313{
3314 // Zero sized uploads are valid but no-ops
3315 if (width == 0 || height == 0 || depth == 0)
3316 {
3317 return;
3318 }
3319
Jamie Madillad9f24e2016-02-12 09:27:24 -05003320 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003321
3322 Box area(xoffset, yoffset, zoffset, width, height, depth);
3323 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003324 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3325 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003326}
3327
3328void Context::compressedTexImage2D(GLenum target,
3329 GLint level,
3330 GLenum internalformat,
3331 GLsizei width,
3332 GLsizei height,
3333 GLint border,
3334 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003335 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003336{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003337 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003338
3339 Extents size(width, height, 1);
3340 Texture *texture =
3341 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003342 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003343 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003344 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003345}
3346
3347void Context::compressedTexImage3D(GLenum target,
3348 GLint level,
3349 GLenum internalformat,
3350 GLsizei width,
3351 GLsizei height,
3352 GLsizei depth,
3353 GLint border,
3354 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003355 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003356{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003357 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003358
3359 Extents size(width, height, depth);
3360 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003361 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003362 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003363 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003364}
3365
3366void Context::compressedTexSubImage2D(GLenum target,
3367 GLint level,
3368 GLint xoffset,
3369 GLint yoffset,
3370 GLsizei width,
3371 GLsizei height,
3372 GLenum format,
3373 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003374 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003375{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003376 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003377
3378 Box area(xoffset, yoffset, 0, width, height, 1);
3379 Texture *texture =
3380 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003381 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003382 format, imageSize,
3383 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003384}
3385
3386void Context::compressedTexSubImage3D(GLenum target,
3387 GLint level,
3388 GLint xoffset,
3389 GLint yoffset,
3390 GLint zoffset,
3391 GLsizei width,
3392 GLsizei height,
3393 GLsizei depth,
3394 GLenum format,
3395 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003396 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003397{
3398 // Zero sized uploads are valid but no-ops
3399 if (width == 0 || height == 0)
3400 {
3401 return;
3402 }
3403
Jamie Madillad9f24e2016-02-12 09:27:24 -05003404 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003405
3406 Box area(xoffset, yoffset, zoffset, width, height, depth);
3407 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003408 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003409 format, imageSize,
3410 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003411}
3412
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003413void Context::generateMipmap(GLenum target)
3414{
3415 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003416 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003417}
3418
Geoff Lang97073d12016-04-20 10:42:34 -07003419void Context::copyTextureCHROMIUM(GLuint sourceId,
Geoff Langfc72a072017-03-24 14:52:39 -04003420 GLint sourceLevel,
3421 GLenum destTarget,
Geoff Lang97073d12016-04-20 10:42:34 -07003422 GLuint destId,
Geoff Langfc72a072017-03-24 14:52:39 -04003423 GLint destLevel,
Geoff Lang97073d12016-04-20 10:42:34 -07003424 GLint internalFormat,
3425 GLenum destType,
3426 GLboolean unpackFlipY,
3427 GLboolean unpackPremultiplyAlpha,
3428 GLboolean unpackUnmultiplyAlpha)
3429{
3430 syncStateForTexImage();
3431
3432 gl::Texture *sourceTexture = getTexture(sourceId);
3433 gl::Texture *destTexture = getTexture(destId);
Geoff Lang92019432017-11-20 13:09:34 -05003434 handleError(destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType,
3435 sourceLevel, ConvertToBool(unpackFlipY),
3436 ConvertToBool(unpackPremultiplyAlpha),
3437 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003438}
3439
3440void Context::copySubTextureCHROMIUM(GLuint sourceId,
Geoff Langfc72a072017-03-24 14:52:39 -04003441 GLint sourceLevel,
3442 GLenum destTarget,
Geoff Lang97073d12016-04-20 10:42:34 -07003443 GLuint destId,
Geoff Langfc72a072017-03-24 14:52:39 -04003444 GLint destLevel,
Geoff Lang97073d12016-04-20 10:42:34 -07003445 GLint xoffset,
3446 GLint yoffset,
3447 GLint x,
3448 GLint y,
3449 GLsizei width,
3450 GLsizei height,
3451 GLboolean unpackFlipY,
3452 GLboolean unpackPremultiplyAlpha,
3453 GLboolean unpackUnmultiplyAlpha)
3454{
3455 // Zero sized copies are valid but no-ops
3456 if (width == 0 || height == 0)
3457 {
3458 return;
3459 }
3460
3461 syncStateForTexImage();
3462
3463 gl::Texture *sourceTexture = getTexture(sourceId);
3464 gl::Texture *destTexture = getTexture(destId);
3465 Offset offset(xoffset, yoffset, 0);
3466 Rectangle area(x, y, width, height);
Geoff Lang92019432017-11-20 13:09:34 -05003467 handleError(destTexture->copySubTexture(this, destTarget, destLevel, offset, sourceLevel, area,
3468 ConvertToBool(unpackFlipY),
3469 ConvertToBool(unpackPremultiplyAlpha),
3470 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003471}
3472
Geoff Lang47110bf2016-04-20 11:13:22 -07003473void Context::compressedCopyTextureCHROMIUM(GLuint sourceId, GLuint destId)
3474{
3475 syncStateForTexImage();
3476
3477 gl::Texture *sourceTexture = getTexture(sourceId);
3478 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05003479 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07003480}
3481
Corentin Wallez336129f2017-10-17 15:55:40 -04003482void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03003483{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003484 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003485 ASSERT(buffer);
3486
Geoff Lang496c02d2016-10-20 11:38:11 -07003487 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03003488}
3489
Corentin Wallez336129f2017-10-17 15:55:40 -04003490void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003491{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003492 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003493 ASSERT(buffer);
3494
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003495 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003496 if (error.isError())
3497 {
Jamie Madill437fa652016-05-03 15:13:24 -04003498 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003499 return nullptr;
3500 }
3501
3502 return buffer->getMapPointer();
3503}
3504
Corentin Wallez336129f2017-10-17 15:55:40 -04003505GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03003506{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003507 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003508 ASSERT(buffer);
3509
3510 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003511 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03003512 if (error.isError())
3513 {
Jamie Madill437fa652016-05-03 15:13:24 -04003514 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003515 return GL_FALSE;
3516 }
3517
3518 return result;
3519}
3520
Corentin Wallez336129f2017-10-17 15:55:40 -04003521void *Context::mapBufferRange(BufferBinding target,
3522 GLintptr offset,
3523 GLsizeiptr length,
3524 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003525{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003526 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003527 ASSERT(buffer);
3528
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003529 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003530 if (error.isError())
3531 {
Jamie Madill437fa652016-05-03 15:13:24 -04003532 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003533 return nullptr;
3534 }
3535
3536 return buffer->getMapPointer();
3537}
3538
Corentin Wallez336129f2017-10-17 15:55:40 -04003539void Context::flushMappedBufferRange(BufferBinding /*target*/,
3540 GLintptr /*offset*/,
3541 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03003542{
3543 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
3544}
3545
Jamie Madillad9f24e2016-02-12 09:27:24 -05003546void Context::syncStateForReadPixels()
3547{
3548 syncRendererState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
3549}
3550
3551void Context::syncStateForTexImage()
3552{
3553 syncRendererState(mTexImageDirtyBits, mTexImageDirtyObjects);
3554}
3555
3556void Context::syncStateForClear()
3557{
3558 syncRendererState(mClearDirtyBits, mClearDirtyObjects);
3559}
3560
3561void Context::syncStateForBlit()
3562{
3563 syncRendererState(mBlitDirtyBits, mBlitDirtyObjects);
3564}
3565
Jiajia Qin5451d532017-11-16 17:16:34 +08003566void Context::activeShaderProgram(GLuint pipeline, GLuint program)
3567{
3568 UNIMPLEMENTED();
3569}
3570
Jamie Madillc20ab272016-06-09 07:20:46 -07003571void Context::activeTexture(GLenum texture)
3572{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003573 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003574}
3575
Jamie Madill876429b2017-04-20 15:46:24 -04003576void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003577{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003578 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07003579}
3580
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003581void Context::blendEquation(GLenum mode)
3582{
3583 mGLState.setBlendEquation(mode, mode);
3584}
3585
Jamie Madillc20ab272016-06-09 07:20:46 -07003586void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
3587{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003588 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003589}
3590
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003591void Context::blendFunc(GLenum sfactor, GLenum dfactor)
3592{
3593 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
3594}
3595
Jamie Madillc20ab272016-06-09 07:20:46 -07003596void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
3597{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003598 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003599}
3600
Jamie Madill876429b2017-04-20 15:46:24 -04003601void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003602{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003603 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003604}
3605
Jamie Madill876429b2017-04-20 15:46:24 -04003606void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07003607{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003608 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07003609}
3610
3611void Context::clearStencil(GLint s)
3612{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003613 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07003614}
3615
3616void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
3617{
Geoff Lang92019432017-11-20 13:09:34 -05003618 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
3619 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07003620}
3621
Corentin Wallez2e568cf2017-09-18 17:05:22 -04003622void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07003623{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003624 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003625}
3626
3627void Context::depthFunc(GLenum func)
3628{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003629 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07003630}
3631
3632void Context::depthMask(GLboolean flag)
3633{
Geoff Lang92019432017-11-20 13:09:34 -05003634 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07003635}
3636
Jamie Madill876429b2017-04-20 15:46:24 -04003637void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07003638{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003639 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07003640}
3641
3642void Context::disable(GLenum cap)
3643{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003644 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003645}
3646
3647void Context::disableVertexAttribArray(GLuint index)
3648{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003649 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003650}
3651
3652void Context::enable(GLenum cap)
3653{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003654 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003655}
3656
3657void Context::enableVertexAttribArray(GLuint index)
3658{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003659 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003660}
3661
3662void Context::frontFace(GLenum mode)
3663{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003664 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003665}
3666
3667void Context::hint(GLenum target, GLenum mode)
3668{
3669 switch (target)
3670 {
3671 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003672 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003673 break;
3674
3675 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003676 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003677 break;
3678
3679 default:
3680 UNREACHABLE();
3681 return;
3682 }
3683}
3684
3685void Context::lineWidth(GLfloat width)
3686{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003687 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07003688}
3689
3690void Context::pixelStorei(GLenum pname, GLint param)
3691{
3692 switch (pname)
3693 {
3694 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003695 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003696 break;
3697
3698 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003699 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003700 break;
3701
3702 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003703 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003704 break;
3705
3706 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003707 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003708 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003709 break;
3710
3711 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03003712 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003713 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003714 break;
3715
3716 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03003717 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003718 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003719 break;
3720
3721 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003722 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003723 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003724 break;
3725
3726 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003727 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003728 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003729 break;
3730
3731 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003732 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003733 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003734 break;
3735
3736 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003737 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003738 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003739 break;
3740
3741 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003742 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003743 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003744 break;
3745
3746 default:
3747 UNREACHABLE();
3748 return;
3749 }
3750}
3751
3752void Context::polygonOffset(GLfloat factor, GLfloat units)
3753{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003754 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07003755}
3756
Jamie Madill876429b2017-04-20 15:46:24 -04003757void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07003758{
Geoff Lang92019432017-11-20 13:09:34 -05003759 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07003760}
3761
Jiawei Shaodb342272017-09-27 10:21:45 +08003762void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
3763{
3764 mGLState.setSampleMaskParams(maskNumber, mask);
3765}
3766
Jamie Madillc20ab272016-06-09 07:20:46 -07003767void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
3768{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003769 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07003770}
3771
3772void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
3773{
3774 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3775 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003776 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003777 }
3778
3779 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3780 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003781 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003782 }
3783}
3784
3785void Context::stencilMaskSeparate(GLenum face, GLuint mask)
3786{
3787 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3788 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003789 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003790 }
3791
3792 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3793 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003794 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003795 }
3796}
3797
3798void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
3799{
3800 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3801 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003802 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003803 }
3804
3805 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3806 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003807 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003808 }
3809}
3810
3811void Context::vertexAttrib1f(GLuint index, GLfloat x)
3812{
3813 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003814 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003815}
3816
3817void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
3818{
3819 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003820 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003821}
3822
3823void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
3824{
3825 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003826 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003827}
3828
3829void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
3830{
3831 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003832 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003833}
3834
3835void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
3836{
3837 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003838 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003839}
3840
3841void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
3842{
3843 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003844 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003845}
3846
3847void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
3848{
3849 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003850 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003851}
3852
3853void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
3854{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003855 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07003856}
3857
3858void Context::vertexAttribPointer(GLuint index,
3859 GLint size,
3860 GLenum type,
3861 GLboolean normalized,
3862 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04003863 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07003864{
Corentin Wallez336129f2017-10-17 15:55:40 -04003865 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05003866 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc20ab272016-06-09 07:20:46 -07003867}
3868
Shao80957d92017-02-20 21:25:59 +08003869void Context::vertexAttribFormat(GLuint attribIndex,
3870 GLint size,
3871 GLenum type,
3872 GLboolean normalized,
3873 GLuint relativeOffset)
3874{
Geoff Lang92019432017-11-20 13:09:34 -05003875 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08003876 relativeOffset);
3877}
3878
3879void Context::vertexAttribIFormat(GLuint attribIndex,
3880 GLint size,
3881 GLenum type,
3882 GLuint relativeOffset)
3883{
3884 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
3885}
3886
3887void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
3888{
Shaodde78e82017-05-22 14:13:27 +08003889 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Shao80957d92017-02-20 21:25:59 +08003890}
3891
Jiajia Qin5451d532017-11-16 17:16:34 +08003892void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08003893{
3894 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
3895}
3896
Jamie Madillc20ab272016-06-09 07:20:46 -07003897void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
3898{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003899 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07003900}
3901
3902void Context::vertexAttribIPointer(GLuint index,
3903 GLint size,
3904 GLenum type,
3905 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04003906 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07003907{
Corentin Wallez336129f2017-10-17 15:55:40 -04003908 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
3909 size, type, false, true, stride, pointer);
Jamie Madillc20ab272016-06-09 07:20:46 -07003910}
3911
3912void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
3913{
3914 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003915 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003916}
3917
3918void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
3919{
3920 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003921 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003922}
3923
3924void Context::vertexAttribI4iv(GLuint index, const GLint *v)
3925{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003926 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07003927}
3928
3929void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
3930{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003931 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07003932}
3933
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003934void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
3935{
3936 const VertexAttribCurrentValueData &currentValues =
3937 getGLState().getVertexAttribCurrentValue(index);
3938 const VertexArray *vao = getGLState().getVertexArray();
3939 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3940 currentValues, pname, params);
3941}
3942
3943void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
3944{
3945 const VertexAttribCurrentValueData &currentValues =
3946 getGLState().getVertexAttribCurrentValue(index);
3947 const VertexArray *vao = getGLState().getVertexArray();
3948 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3949 currentValues, pname, params);
3950}
3951
3952void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
3953{
3954 const VertexAttribCurrentValueData &currentValues =
3955 getGLState().getVertexAttribCurrentValue(index);
3956 const VertexArray *vao = getGLState().getVertexArray();
3957 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3958 currentValues, pname, params);
3959}
3960
3961void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
3962{
3963 const VertexAttribCurrentValueData &currentValues =
3964 getGLState().getVertexAttribCurrentValue(index);
3965 const VertexArray *vao = getGLState().getVertexArray();
3966 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3967 currentValues, pname, params);
3968}
3969
Jamie Madill876429b2017-04-20 15:46:24 -04003970void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003971{
3972 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
3973 QueryVertexAttribPointerv(attrib, pname, pointer);
3974}
3975
Jamie Madillc20ab272016-06-09 07:20:46 -07003976void Context::debugMessageControl(GLenum source,
3977 GLenum type,
3978 GLenum severity,
3979 GLsizei count,
3980 const GLuint *ids,
3981 GLboolean enabled)
3982{
3983 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003984 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05003985 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07003986}
3987
3988void Context::debugMessageInsert(GLenum source,
3989 GLenum type,
3990 GLuint id,
3991 GLenum severity,
3992 GLsizei length,
3993 const GLchar *buf)
3994{
3995 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003996 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07003997}
3998
3999void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4000{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004001 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004002}
4003
4004GLuint Context::getDebugMessageLog(GLuint count,
4005 GLsizei bufSize,
4006 GLenum *sources,
4007 GLenum *types,
4008 GLuint *ids,
4009 GLenum *severities,
4010 GLsizei *lengths,
4011 GLchar *messageLog)
4012{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004013 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4014 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004015}
4016
4017void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4018{
4019 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004020 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05004021 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07004022}
4023
4024void Context::popDebugGroup()
4025{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004026 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05004027 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004028}
4029
Corentin Wallez336129f2017-10-17 15:55:40 -04004030void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004031{
4032 Buffer *buffer = mGLState.getTargetBuffer(target);
4033 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004034 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004035}
4036
Corentin Wallez336129f2017-10-17 15:55:40 -04004037void Context::bufferSubData(BufferBinding target,
4038 GLintptr offset,
4039 GLsizeiptr size,
4040 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004041{
4042 if (data == nullptr)
4043 {
4044 return;
4045 }
4046
4047 Buffer *buffer = mGLState.getTargetBuffer(target);
4048 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004049 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004050}
4051
Jamie Madillef300b12016-10-07 15:12:09 -04004052void Context::attachShader(GLuint program, GLuint shader)
4053{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05004054 Program *programObject = mState.mShaderPrograms->getProgram(program);
4055 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004056 ASSERT(programObject && shaderObject);
4057 programObject->attachShader(shaderObject);
4058}
4059
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004060const Workarounds &Context::getWorkarounds() const
4061{
4062 return mWorkarounds;
4063}
4064
Corentin Wallez336129f2017-10-17 15:55:40 -04004065void Context::copyBufferSubData(BufferBinding readTarget,
4066 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04004067 GLintptr readOffset,
4068 GLintptr writeOffset,
4069 GLsizeiptr size)
4070{
4071 // if size is zero, the copy is a successful no-op
4072 if (size == 0)
4073 {
4074 return;
4075 }
4076
4077 // TODO(jmadill): cache these.
4078 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4079 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4080
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004081 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004082}
4083
Jamie Madill01a80ee2016-11-07 12:06:18 -05004084void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4085{
4086 Program *programObject = getProgram(program);
4087 // TODO(jmadill): Re-use this from the validation if possible.
4088 ASSERT(programObject);
4089 programObject->bindAttributeLocation(index, name);
4090}
4091
Corentin Wallez336129f2017-10-17 15:55:40 -04004092void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004093{
Corentin Wallez336129f2017-10-17 15:55:40 -04004094 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4095 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004096}
4097
Corentin Wallez336129f2017-10-17 15:55:40 -04004098void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08004099{
4100 bindBufferRange(target, index, buffer, 0, 0);
4101}
4102
Corentin Wallez336129f2017-10-17 15:55:40 -04004103void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08004104 GLuint index,
4105 GLuint buffer,
4106 GLintptr offset,
4107 GLsizeiptr size)
4108{
Corentin Wallez336129f2017-10-17 15:55:40 -04004109 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4110 mGLState.setIndexedBufferBinding(this, target, index, bufferObject, offset, size);
Jiajia Qin6eafb042016-12-27 17:04:07 +08004111}
4112
Jamie Madill01a80ee2016-11-07 12:06:18 -05004113void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
4114{
4115 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4116 {
4117 bindReadFramebuffer(framebuffer);
4118 }
4119
4120 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4121 {
4122 bindDrawFramebuffer(framebuffer);
4123 }
4124}
4125
4126void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4127{
4128 ASSERT(target == GL_RENDERBUFFER);
4129 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004130 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04004131 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004132}
4133
JiangYizhoubddc46b2016-12-09 09:50:51 +08004134void Context::texStorage2DMultisample(GLenum target,
4135 GLsizei samples,
4136 GLenum internalformat,
4137 GLsizei width,
4138 GLsizei height,
4139 GLboolean fixedsamplelocations)
4140{
4141 Extents size(width, height, 1);
4142 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05004143 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
Geoff Lang92019432017-11-20 13:09:34 -05004144 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004145}
4146
4147void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4148{
JiangYizhou5b03f472017-01-09 10:22:53 +08004149 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
4150 // the sample position should be queried by DRAW_FRAMEBUFFER.
4151 mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER);
4152 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08004153
4154 switch (pname)
4155 {
4156 case GL_SAMPLE_POSITION:
4157 handleError(framebuffer->getSamplePosition(index, val));
4158 break;
4159 default:
4160 UNREACHABLE();
4161 }
4162}
4163
Jamie Madille8fb6402017-02-14 17:56:40 -05004164void Context::renderbufferStorage(GLenum target,
4165 GLenum internalformat,
4166 GLsizei width,
4167 GLsizei height)
4168{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004169 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4170 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
4171
Jamie Madille8fb6402017-02-14 17:56:40 -05004172 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04004173 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004174}
4175
4176void Context::renderbufferStorageMultisample(GLenum target,
4177 GLsizei samples,
4178 GLenum internalformat,
4179 GLsizei width,
4180 GLsizei height)
4181{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004182 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4183 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05004184
4185 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004186 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04004187 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004188}
4189
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004190void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
4191{
Jamie Madill70b5bb02017-08-28 13:32:37 -04004192 const Sync *syncObject = getSync(sync);
Geoff Lang82483b92017-04-11 15:33:00 -04004193 handleError(QuerySynciv(syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004194}
4195
JiangYizhoue18e6392017-02-20 10:32:23 +08004196void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
4197{
4198 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4199 QueryFramebufferParameteriv(framebuffer, pname, params);
4200}
4201
Jiajia Qin5451d532017-11-16 17:16:34 +08004202void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08004203{
4204 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4205 SetFramebufferParameteri(framebuffer, pname, param);
4206}
4207
Jamie Madillb3f26b92017-07-19 15:07:41 -04004208Error Context::getScratchBuffer(size_t requstedSizeBytes,
4209 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05004210{
Jamie Madillb3f26b92017-07-19 15:07:41 -04004211 if (!mScratchBuffer.get(requstedSizeBytes, scratchBufferOut))
4212 {
4213 return OutOfMemory() << "Failed to allocate internal buffer.";
4214 }
4215 return NoError();
4216}
4217
4218Error Context::getZeroFilledBuffer(size_t requstedSizeBytes,
4219 angle::MemoryBuffer **zeroBufferOut) const
4220{
4221 if (!mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0))
Jamie Madille14951e2017-03-09 18:55:16 -05004222 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004223 return OutOfMemory() << "Failed to allocate internal buffer.";
Jamie Madille14951e2017-03-09 18:55:16 -05004224 }
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004225 return NoError();
Jamie Madille14951e2017-03-09 18:55:16 -05004226}
4227
Xinghua Cao10a4d432017-11-28 14:46:26 +08004228Error Context::prepareForDispatch()
4229{
4230 syncRendererState(mComputeDirtyBits, mComputeDirtyObjects);
4231
4232 if (isRobustResourceInitEnabled())
4233 {
4234 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
4235 }
4236
4237 return NoError();
4238}
4239
Xinghua Cao2b396592017-03-29 15:36:04 +08004240void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
4241{
4242 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
4243 {
4244 return;
4245 }
4246
Xinghua Cao10a4d432017-11-28 14:46:26 +08004247 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill71c88b32017-09-14 22:20:29 -04004248 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08004249}
4250
Jiajia Qin5451d532017-11-16 17:16:34 +08004251void Context::dispatchComputeIndirect(GLintptr indirect)
4252{
Qin Jiajia62fcf622017-11-30 16:16:12 +08004253 ANGLE_CONTEXT_TRY(prepareForDispatch());
4254 handleError(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08004255}
4256
JiangYizhou165361c2017-06-07 14:56:57 +08004257void Context::texStorage2D(GLenum target,
4258 GLsizei levels,
4259 GLenum internalFormat,
4260 GLsizei width,
4261 GLsizei height)
4262{
4263 Extents size(width, height, 1);
4264 Texture *texture = getTargetTexture(target);
4265 handleError(texture->setStorage(this, target, levels, internalFormat, size));
4266}
4267
4268void Context::texStorage3D(GLenum target,
4269 GLsizei levels,
4270 GLenum internalFormat,
4271 GLsizei width,
4272 GLsizei height,
4273 GLsizei depth)
4274{
4275 Extents size(width, height, depth);
4276 Texture *texture = getTargetTexture(target);
4277 handleError(texture->setStorage(this, target, levels, internalFormat, size));
4278}
4279
Jiajia Qin5451d532017-11-16 17:16:34 +08004280void Context::memoryBarrier(GLbitfield barriers)
4281{
Xinghua Cao89c422a2017-11-29 18:24:20 +08004282 handleError(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08004283}
4284
4285void Context::memoryBarrierByRegion(GLbitfield barriers)
4286{
Xinghua Cao89c422a2017-11-29 18:24:20 +08004287 handleError(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08004288}
4289
Jamie Madillc1d770e2017-04-13 17:31:24 -04004290GLenum Context::checkFramebufferStatus(GLenum target)
4291{
4292 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4293 ASSERT(framebuffer);
4294
4295 return framebuffer->checkStatus(this);
4296}
4297
4298void Context::compileShader(GLuint shader)
4299{
4300 Shader *shaderObject = GetValidShader(this, shader);
4301 if (!shaderObject)
4302 {
4303 return;
4304 }
4305 shaderObject->compile(this);
4306}
4307
4308void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
4309{
4310 for (int i = 0; i < n; i++)
4311 {
4312 deleteBuffer(buffers[i]);
4313 }
4314}
4315
4316void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
4317{
4318 for (int i = 0; i < n; i++)
4319 {
4320 if (framebuffers[i] != 0)
4321 {
4322 deleteFramebuffer(framebuffers[i]);
4323 }
4324 }
4325}
4326
4327void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
4328{
4329 for (int i = 0; i < n; i++)
4330 {
4331 deleteRenderbuffer(renderbuffers[i]);
4332 }
4333}
4334
4335void Context::deleteTextures(GLsizei n, const GLuint *textures)
4336{
4337 for (int i = 0; i < n; i++)
4338 {
4339 if (textures[i] != 0)
4340 {
4341 deleteTexture(textures[i]);
4342 }
4343 }
4344}
4345
4346void Context::detachShader(GLuint program, GLuint shader)
4347{
4348 Program *programObject = getProgram(program);
4349 ASSERT(programObject);
4350
4351 Shader *shaderObject = getShader(shader);
4352 ASSERT(shaderObject);
4353
4354 programObject->detachShader(this, shaderObject);
4355}
4356
4357void Context::genBuffers(GLsizei n, GLuint *buffers)
4358{
4359 for (int i = 0; i < n; i++)
4360 {
4361 buffers[i] = createBuffer();
4362 }
4363}
4364
4365void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
4366{
4367 for (int i = 0; i < n; i++)
4368 {
4369 framebuffers[i] = createFramebuffer();
4370 }
4371}
4372
4373void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
4374{
4375 for (int i = 0; i < n; i++)
4376 {
4377 renderbuffers[i] = createRenderbuffer();
4378 }
4379}
4380
4381void Context::genTextures(GLsizei n, GLuint *textures)
4382{
4383 for (int i = 0; i < n; i++)
4384 {
4385 textures[i] = createTexture();
4386 }
4387}
4388
4389void Context::getActiveAttrib(GLuint program,
4390 GLuint index,
4391 GLsizei bufsize,
4392 GLsizei *length,
4393 GLint *size,
4394 GLenum *type,
4395 GLchar *name)
4396{
4397 Program *programObject = getProgram(program);
4398 ASSERT(programObject);
4399 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
4400}
4401
4402void Context::getActiveUniform(GLuint program,
4403 GLuint index,
4404 GLsizei bufsize,
4405 GLsizei *length,
4406 GLint *size,
4407 GLenum *type,
4408 GLchar *name)
4409{
4410 Program *programObject = getProgram(program);
4411 ASSERT(programObject);
4412 programObject->getActiveUniform(index, bufsize, length, size, type, name);
4413}
4414
4415void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
4416{
4417 Program *programObject = getProgram(program);
4418 ASSERT(programObject);
4419 programObject->getAttachedShaders(maxcount, count, shaders);
4420}
4421
4422GLint Context::getAttribLocation(GLuint program, const GLchar *name)
4423{
4424 Program *programObject = getProgram(program);
4425 ASSERT(programObject);
4426 return programObject->getAttributeLocation(name);
4427}
4428
4429void Context::getBooleanv(GLenum pname, GLboolean *params)
4430{
4431 GLenum nativeType;
4432 unsigned int numParams = 0;
4433 getQueryParameterInfo(pname, &nativeType, &numParams);
4434
4435 if (nativeType == GL_BOOL)
4436 {
4437 getBooleanvImpl(pname, params);
4438 }
4439 else
4440 {
4441 CastStateValues(this, nativeType, pname, numParams, params);
4442 }
4443}
4444
4445void Context::getFloatv(GLenum pname, GLfloat *params)
4446{
4447 GLenum nativeType;
4448 unsigned int numParams = 0;
4449 getQueryParameterInfo(pname, &nativeType, &numParams);
4450
4451 if (nativeType == GL_FLOAT)
4452 {
4453 getFloatvImpl(pname, params);
4454 }
4455 else
4456 {
4457 CastStateValues(this, nativeType, pname, numParams, params);
4458 }
4459}
4460
4461void Context::getIntegerv(GLenum pname, GLint *params)
4462{
4463 GLenum nativeType;
4464 unsigned int numParams = 0;
4465 getQueryParameterInfo(pname, &nativeType, &numParams);
4466
4467 if (nativeType == GL_INT)
4468 {
4469 getIntegervImpl(pname, params);
4470 }
4471 else
4472 {
4473 CastStateValues(this, nativeType, pname, numParams, params);
4474 }
4475}
4476
4477void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
4478{
4479 Program *programObject = getProgram(program);
4480 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04004481 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004482}
4483
Jiajia Qin5451d532017-11-16 17:16:34 +08004484void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
4485{
4486 UNIMPLEMENTED();
4487}
4488
Jamie Madillbe849e42017-05-02 15:49:00 -04004489void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04004490{
4491 Program *programObject = getProgram(program);
4492 ASSERT(programObject);
4493 programObject->getInfoLog(bufsize, length, infolog);
4494}
4495
Jiajia Qin5451d532017-11-16 17:16:34 +08004496void Context::getProgramPipelineInfoLog(GLuint pipeline,
4497 GLsizei bufSize,
4498 GLsizei *length,
4499 GLchar *infoLog)
4500{
4501 UNIMPLEMENTED();
4502}
4503
Jamie Madillc1d770e2017-04-13 17:31:24 -04004504void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
4505{
4506 Shader *shaderObject = getShader(shader);
4507 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004508 QueryShaderiv(this, shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004509}
4510
4511void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
4512{
4513 Shader *shaderObject = getShader(shader);
4514 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004515 shaderObject->getInfoLog(this, bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004516}
4517
4518void Context::getShaderPrecisionFormat(GLenum shadertype,
4519 GLenum precisiontype,
4520 GLint *range,
4521 GLint *precision)
4522{
4523 // TODO(jmadill): Compute shaders.
4524
4525 switch (shadertype)
4526 {
4527 case GL_VERTEX_SHADER:
4528 switch (precisiontype)
4529 {
4530 case GL_LOW_FLOAT:
4531 mCaps.vertexLowpFloat.get(range, precision);
4532 break;
4533 case GL_MEDIUM_FLOAT:
4534 mCaps.vertexMediumpFloat.get(range, precision);
4535 break;
4536 case GL_HIGH_FLOAT:
4537 mCaps.vertexHighpFloat.get(range, precision);
4538 break;
4539
4540 case GL_LOW_INT:
4541 mCaps.vertexLowpInt.get(range, precision);
4542 break;
4543 case GL_MEDIUM_INT:
4544 mCaps.vertexMediumpInt.get(range, precision);
4545 break;
4546 case GL_HIGH_INT:
4547 mCaps.vertexHighpInt.get(range, precision);
4548 break;
4549
4550 default:
4551 UNREACHABLE();
4552 return;
4553 }
4554 break;
4555
4556 case GL_FRAGMENT_SHADER:
4557 switch (precisiontype)
4558 {
4559 case GL_LOW_FLOAT:
4560 mCaps.fragmentLowpFloat.get(range, precision);
4561 break;
4562 case GL_MEDIUM_FLOAT:
4563 mCaps.fragmentMediumpFloat.get(range, precision);
4564 break;
4565 case GL_HIGH_FLOAT:
4566 mCaps.fragmentHighpFloat.get(range, precision);
4567 break;
4568
4569 case GL_LOW_INT:
4570 mCaps.fragmentLowpInt.get(range, precision);
4571 break;
4572 case GL_MEDIUM_INT:
4573 mCaps.fragmentMediumpInt.get(range, precision);
4574 break;
4575 case GL_HIGH_INT:
4576 mCaps.fragmentHighpInt.get(range, precision);
4577 break;
4578
4579 default:
4580 UNREACHABLE();
4581 return;
4582 }
4583 break;
4584
4585 default:
4586 UNREACHABLE();
4587 return;
4588 }
4589}
4590
4591void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
4592{
4593 Shader *shaderObject = getShader(shader);
4594 ASSERT(shaderObject);
4595 shaderObject->getSource(bufsize, length, source);
4596}
4597
4598void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
4599{
4600 Program *programObject = getProgram(program);
4601 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04004602 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004603}
4604
4605void Context::getUniformiv(GLuint program, GLint location, GLint *params)
4606{
4607 Program *programObject = getProgram(program);
4608 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04004609 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004610}
4611
4612GLint Context::getUniformLocation(GLuint program, const GLchar *name)
4613{
4614 Program *programObject = getProgram(program);
4615 ASSERT(programObject);
4616 return programObject->getUniformLocation(name);
4617}
4618
4619GLboolean Context::isBuffer(GLuint buffer)
4620{
4621 if (buffer == 0)
4622 {
4623 return GL_FALSE;
4624 }
4625
4626 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
4627}
4628
4629GLboolean Context::isEnabled(GLenum cap)
4630{
4631 return mGLState.getEnableFeature(cap);
4632}
4633
4634GLboolean Context::isFramebuffer(GLuint framebuffer)
4635{
4636 if (framebuffer == 0)
4637 {
4638 return GL_FALSE;
4639 }
4640
4641 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
4642}
4643
4644GLboolean Context::isProgram(GLuint program)
4645{
4646 if (program == 0)
4647 {
4648 return GL_FALSE;
4649 }
4650
4651 return (getProgram(program) ? GL_TRUE : GL_FALSE);
4652}
4653
4654GLboolean Context::isRenderbuffer(GLuint renderbuffer)
4655{
4656 if (renderbuffer == 0)
4657 {
4658 return GL_FALSE;
4659 }
4660
4661 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
4662}
4663
4664GLboolean Context::isShader(GLuint shader)
4665{
4666 if (shader == 0)
4667 {
4668 return GL_FALSE;
4669 }
4670
4671 return (getShader(shader) ? GL_TRUE : GL_FALSE);
4672}
4673
4674GLboolean Context::isTexture(GLuint texture)
4675{
4676 if (texture == 0)
4677 {
4678 return GL_FALSE;
4679 }
4680
4681 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
4682}
4683
4684void Context::linkProgram(GLuint program)
4685{
4686 Program *programObject = getProgram(program);
4687 ASSERT(programObject);
4688 handleError(programObject->link(this));
Martin Radev0abb7a22017-08-28 15:34:45 +03004689 mGLState.onProgramExecutableChange(programObject);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004690}
4691
4692void Context::releaseShaderCompiler()
4693{
Jamie Madill4928b7c2017-06-20 12:57:39 -04004694 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004695}
4696
4697void Context::shaderBinary(GLsizei n,
4698 const GLuint *shaders,
4699 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04004700 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04004701 GLsizei length)
4702{
4703 // No binary shader formats are supported.
4704 UNIMPLEMENTED();
4705}
4706
4707void Context::shaderSource(GLuint shader,
4708 GLsizei count,
4709 const GLchar *const *string,
4710 const GLint *length)
4711{
4712 Shader *shaderObject = getShader(shader);
4713 ASSERT(shaderObject);
4714 shaderObject->setSource(count, string, length);
4715}
4716
4717void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
4718{
4719 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
4720}
4721
4722void Context::stencilMask(GLuint mask)
4723{
4724 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
4725}
4726
4727void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
4728{
4729 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
4730}
4731
4732void Context::uniform1f(GLint location, GLfloat x)
4733{
4734 Program *program = mGLState.getProgram();
4735 program->setUniform1fv(location, 1, &x);
4736}
4737
4738void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
4739{
4740 Program *program = mGLState.getProgram();
4741 program->setUniform1fv(location, count, v);
4742}
4743
4744void Context::uniform1i(GLint location, GLint x)
4745{
4746 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04004747 if (program->setUniform1iv(location, 1, &x) == Program::SetUniformResult::SamplerChanged)
4748 {
4749 mGLState.setObjectDirty(GL_PROGRAM);
4750 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04004751}
4752
4753void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
4754{
4755 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04004756 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
4757 {
4758 mGLState.setObjectDirty(GL_PROGRAM);
4759 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04004760}
4761
4762void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
4763{
4764 GLfloat xy[2] = {x, y};
4765 Program *program = mGLState.getProgram();
4766 program->setUniform2fv(location, 1, xy);
4767}
4768
4769void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
4770{
4771 Program *program = mGLState.getProgram();
4772 program->setUniform2fv(location, count, v);
4773}
4774
4775void Context::uniform2i(GLint location, GLint x, GLint y)
4776{
4777 GLint xy[2] = {x, y};
4778 Program *program = mGLState.getProgram();
4779 program->setUniform2iv(location, 1, xy);
4780}
4781
4782void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
4783{
4784 Program *program = mGLState.getProgram();
4785 program->setUniform2iv(location, count, v);
4786}
4787
4788void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
4789{
4790 GLfloat xyz[3] = {x, y, z};
4791 Program *program = mGLState.getProgram();
4792 program->setUniform3fv(location, 1, xyz);
4793}
4794
4795void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
4796{
4797 Program *program = mGLState.getProgram();
4798 program->setUniform3fv(location, count, v);
4799}
4800
4801void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
4802{
4803 GLint xyz[3] = {x, y, z};
4804 Program *program = mGLState.getProgram();
4805 program->setUniform3iv(location, 1, xyz);
4806}
4807
4808void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
4809{
4810 Program *program = mGLState.getProgram();
4811 program->setUniform3iv(location, count, v);
4812}
4813
4814void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4815{
4816 GLfloat xyzw[4] = {x, y, z, w};
4817 Program *program = mGLState.getProgram();
4818 program->setUniform4fv(location, 1, xyzw);
4819}
4820
4821void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
4822{
4823 Program *program = mGLState.getProgram();
4824 program->setUniform4fv(location, count, v);
4825}
4826
4827void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
4828{
4829 GLint xyzw[4] = {x, y, z, w};
4830 Program *program = mGLState.getProgram();
4831 program->setUniform4iv(location, 1, xyzw);
4832}
4833
4834void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
4835{
4836 Program *program = mGLState.getProgram();
4837 program->setUniform4iv(location, count, v);
4838}
4839
4840void Context::uniformMatrix2fv(GLint location,
4841 GLsizei count,
4842 GLboolean transpose,
4843 const GLfloat *value)
4844{
4845 Program *program = mGLState.getProgram();
4846 program->setUniformMatrix2fv(location, count, transpose, value);
4847}
4848
4849void Context::uniformMatrix3fv(GLint location,
4850 GLsizei count,
4851 GLboolean transpose,
4852 const GLfloat *value)
4853{
4854 Program *program = mGLState.getProgram();
4855 program->setUniformMatrix3fv(location, count, transpose, value);
4856}
4857
4858void Context::uniformMatrix4fv(GLint location,
4859 GLsizei count,
4860 GLboolean transpose,
4861 const GLfloat *value)
4862{
4863 Program *program = mGLState.getProgram();
4864 program->setUniformMatrix4fv(location, count, transpose, value);
4865}
4866
4867void Context::validateProgram(GLuint program)
4868{
4869 Program *programObject = getProgram(program);
4870 ASSERT(programObject);
4871 programObject->validate(mCaps);
4872}
4873
Jiajia Qin5451d532017-11-16 17:16:34 +08004874void Context::validateProgramPipeline(GLuint pipeline)
4875{
4876 UNIMPLEMENTED();
4877}
4878
Jamie Madilld04908b2017-06-09 14:15:35 -04004879void Context::getProgramBinary(GLuint program,
4880 GLsizei bufSize,
4881 GLsizei *length,
4882 GLenum *binaryFormat,
4883 void *binary)
4884{
4885 Program *programObject = getProgram(program);
4886 ASSERT(programObject != nullptr);
4887
4888 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
4889}
4890
4891void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
4892{
4893 Program *programObject = getProgram(program);
4894 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04004895
Jamie Madilld04908b2017-06-09 14:15:35 -04004896 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
4897}
4898
Jamie Madillff325f12017-08-26 15:06:05 -04004899void Context::uniform1ui(GLint location, GLuint v0)
4900{
4901 Program *program = mGLState.getProgram();
4902 program->setUniform1uiv(location, 1, &v0);
4903}
4904
4905void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
4906{
4907 Program *program = mGLState.getProgram();
4908 const GLuint xy[] = {v0, v1};
4909 program->setUniform2uiv(location, 1, xy);
4910}
4911
4912void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
4913{
4914 Program *program = mGLState.getProgram();
4915 const GLuint xyz[] = {v0, v1, v2};
4916 program->setUniform3uiv(location, 1, xyz);
4917}
4918
4919void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
4920{
4921 Program *program = mGLState.getProgram();
4922 const GLuint xyzw[] = {v0, v1, v2, v3};
4923 program->setUniform4uiv(location, 1, xyzw);
4924}
4925
4926void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
4927{
4928 Program *program = mGLState.getProgram();
4929 program->setUniform1uiv(location, count, value);
4930}
4931void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
4932{
4933 Program *program = mGLState.getProgram();
4934 program->setUniform2uiv(location, count, value);
4935}
4936
4937void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
4938{
4939 Program *program = mGLState.getProgram();
4940 program->setUniform3uiv(location, count, value);
4941}
4942
4943void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
4944{
4945 Program *program = mGLState.getProgram();
4946 program->setUniform4uiv(location, count, value);
4947}
4948
Jamie Madillf0e04492017-08-26 15:28:42 -04004949void Context::genQueries(GLsizei n, GLuint *ids)
4950{
4951 for (GLsizei i = 0; i < n; i++)
4952 {
4953 GLuint handle = mQueryHandleAllocator.allocate();
4954 mQueryMap.assign(handle, nullptr);
4955 ids[i] = handle;
4956 }
4957}
4958
4959void Context::deleteQueries(GLsizei n, const GLuint *ids)
4960{
4961 for (int i = 0; i < n; i++)
4962 {
4963 GLuint query = ids[i];
4964
4965 Query *queryObject = nullptr;
4966 if (mQueryMap.erase(query, &queryObject))
4967 {
4968 mQueryHandleAllocator.release(query);
4969 if (queryObject)
4970 {
4971 queryObject->release(this);
4972 }
4973 }
4974 }
4975}
4976
4977GLboolean Context::isQuery(GLuint id)
4978{
4979 return (getQuery(id, false, GL_NONE) != nullptr) ? GL_TRUE : GL_FALSE;
4980}
4981
Jamie Madillc8c95812017-08-26 18:40:09 -04004982void Context::uniformMatrix2x3fv(GLint location,
4983 GLsizei count,
4984 GLboolean transpose,
4985 const GLfloat *value)
4986{
4987 Program *program = mGLState.getProgram();
4988 program->setUniformMatrix2x3fv(location, count, transpose, value);
4989}
4990
4991void Context::uniformMatrix3x2fv(GLint location,
4992 GLsizei count,
4993 GLboolean transpose,
4994 const GLfloat *value)
4995{
4996 Program *program = mGLState.getProgram();
4997 program->setUniformMatrix3x2fv(location, count, transpose, value);
4998}
4999
5000void Context::uniformMatrix2x4fv(GLint location,
5001 GLsizei count,
5002 GLboolean transpose,
5003 const GLfloat *value)
5004{
5005 Program *program = mGLState.getProgram();
5006 program->setUniformMatrix2x4fv(location, count, transpose, value);
5007}
5008
5009void Context::uniformMatrix4x2fv(GLint location,
5010 GLsizei count,
5011 GLboolean transpose,
5012 const GLfloat *value)
5013{
5014 Program *program = mGLState.getProgram();
5015 program->setUniformMatrix4x2fv(location, count, transpose, value);
5016}
5017
5018void Context::uniformMatrix3x4fv(GLint location,
5019 GLsizei count,
5020 GLboolean transpose,
5021 const GLfloat *value)
5022{
5023 Program *program = mGLState.getProgram();
5024 program->setUniformMatrix3x4fv(location, count, transpose, value);
5025}
5026
5027void Context::uniformMatrix4x3fv(GLint location,
5028 GLsizei count,
5029 GLboolean transpose,
5030 const GLfloat *value)
5031{
5032 Program *program = mGLState.getProgram();
5033 program->setUniformMatrix4x3fv(location, count, transpose, value);
5034}
5035
Jamie Madilld7576732017-08-26 18:49:50 -04005036void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
5037{
5038 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5039 {
5040 GLuint vertexArray = arrays[arrayIndex];
5041
5042 if (arrays[arrayIndex] != 0)
5043 {
5044 VertexArray *vertexArrayObject = nullptr;
5045 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
5046 {
5047 if (vertexArrayObject != nullptr)
5048 {
5049 detachVertexArray(vertexArray);
5050 vertexArrayObject->onDestroy(this);
5051 }
5052
5053 mVertexArrayHandleAllocator.release(vertexArray);
5054 }
5055 }
5056 }
5057}
5058
5059void Context::genVertexArrays(GLsizei n, GLuint *arrays)
5060{
5061 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5062 {
5063 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
5064 mVertexArrayMap.assign(vertexArray, nullptr);
5065 arrays[arrayIndex] = vertexArray;
5066 }
5067}
5068
5069bool Context::isVertexArray(GLuint array)
5070{
5071 if (array == 0)
5072 {
5073 return GL_FALSE;
5074 }
5075
5076 VertexArray *vao = getVertexArray(array);
5077 return (vao != nullptr ? GL_TRUE : GL_FALSE);
5078}
5079
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04005080void Context::endTransformFeedback()
5081{
5082 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5083 transformFeedback->end(this);
5084}
5085
5086void Context::transformFeedbackVaryings(GLuint program,
5087 GLsizei count,
5088 const GLchar *const *varyings,
5089 GLenum bufferMode)
5090{
5091 Program *programObject = getProgram(program);
5092 ASSERT(programObject);
5093 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
5094}
5095
5096void Context::getTransformFeedbackVarying(GLuint program,
5097 GLuint index,
5098 GLsizei bufSize,
5099 GLsizei *length,
5100 GLsizei *size,
5101 GLenum *type,
5102 GLchar *name)
5103{
5104 Program *programObject = getProgram(program);
5105 ASSERT(programObject);
5106 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
5107}
5108
5109void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
5110{
5111 for (int i = 0; i < n; i++)
5112 {
5113 GLuint transformFeedback = ids[i];
5114 if (transformFeedback == 0)
5115 {
5116 continue;
5117 }
5118
5119 TransformFeedback *transformFeedbackObject = nullptr;
5120 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
5121 {
5122 if (transformFeedbackObject != nullptr)
5123 {
5124 detachTransformFeedback(transformFeedback);
5125 transformFeedbackObject->release(this);
5126 }
5127
5128 mTransformFeedbackHandleAllocator.release(transformFeedback);
5129 }
5130 }
5131}
5132
5133void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
5134{
5135 for (int i = 0; i < n; i++)
5136 {
5137 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
5138 mTransformFeedbackMap.assign(transformFeedback, nullptr);
5139 ids[i] = transformFeedback;
5140 }
5141}
5142
5143bool Context::isTransformFeedback(GLuint id)
5144{
5145 if (id == 0)
5146 {
5147 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
5148 // returns FALSE
5149 return GL_FALSE;
5150 }
5151
5152 const TransformFeedback *transformFeedback = getTransformFeedback(id);
5153 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
5154}
5155
5156void Context::pauseTransformFeedback()
5157{
5158 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5159 transformFeedback->pause();
5160}
5161
5162void Context::resumeTransformFeedback()
5163{
5164 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5165 transformFeedback->resume();
5166}
5167
Jamie Madill12e957f2017-08-26 21:42:26 -04005168void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
5169{
5170 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04005171 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04005172}
5173
5174GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
5175{
5176 const Program *programObject = getProgram(program);
5177 return programObject->getFragDataLocation(name);
5178}
5179
5180void Context::getUniformIndices(GLuint program,
5181 GLsizei uniformCount,
5182 const GLchar *const *uniformNames,
5183 GLuint *uniformIndices)
5184{
5185 const Program *programObject = getProgram(program);
5186 if (!programObject->isLinked())
5187 {
5188 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5189 {
5190 uniformIndices[uniformId] = GL_INVALID_INDEX;
5191 }
5192 }
5193 else
5194 {
5195 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5196 {
5197 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
5198 }
5199 }
5200}
5201
5202void Context::getActiveUniformsiv(GLuint program,
5203 GLsizei uniformCount,
5204 const GLuint *uniformIndices,
5205 GLenum pname,
5206 GLint *params)
5207{
5208 const Program *programObject = getProgram(program);
5209 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5210 {
5211 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08005212 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04005213 }
5214}
5215
5216GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
5217{
5218 const Program *programObject = getProgram(program);
5219 return programObject->getUniformBlockIndex(uniformBlockName);
5220}
5221
5222void Context::getActiveUniformBlockiv(GLuint program,
5223 GLuint uniformBlockIndex,
5224 GLenum pname,
5225 GLint *params)
5226{
5227 const Program *programObject = getProgram(program);
5228 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
5229}
5230
5231void Context::getActiveUniformBlockName(GLuint program,
5232 GLuint uniformBlockIndex,
5233 GLsizei bufSize,
5234 GLsizei *length,
5235 GLchar *uniformBlockName)
5236{
5237 const Program *programObject = getProgram(program);
5238 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
5239}
5240
5241void Context::uniformBlockBinding(GLuint program,
5242 GLuint uniformBlockIndex,
5243 GLuint uniformBlockBinding)
5244{
5245 Program *programObject = getProgram(program);
5246 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
5247}
5248
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005249GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
5250{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005251 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
5252 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005253
Jamie Madill70b5bb02017-08-28 13:32:37 -04005254 Sync *syncObject = getSync(syncHandle);
5255 Error error = syncObject->set(condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005256 if (error.isError())
5257 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04005258 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005259 handleError(error);
5260 return nullptr;
5261 }
5262
Jamie Madill70b5bb02017-08-28 13:32:37 -04005263 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005264}
5265
5266GLboolean Context::isSync(GLsync sync)
5267{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005268 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005269}
5270
5271GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
5272{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005273 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005274
5275 GLenum result = GL_WAIT_FAILED;
5276 handleError(syncObject->clientWait(flags, timeout, &result));
5277 return result;
5278}
5279
5280void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
5281{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005282 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005283 handleError(syncObject->serverWait(flags, timeout));
5284}
5285
5286void Context::getInteger64v(GLenum pname, GLint64 *params)
5287{
5288 GLenum nativeType = GL_NONE;
5289 unsigned int numParams = 0;
5290 getQueryParameterInfo(pname, &nativeType, &numParams);
5291
5292 if (nativeType == GL_INT_64_ANGLEX)
5293 {
5294 getInteger64vImpl(pname, params);
5295 }
5296 else
5297 {
5298 CastStateValues(this, nativeType, pname, numParams, params);
5299 }
5300}
5301
Corentin Wallez336129f2017-10-17 15:55:40 -04005302void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04005303{
5304 Buffer *buffer = mGLState.getTargetBuffer(target);
5305 QueryBufferParameteri64v(buffer, pname, params);
5306}
5307
5308void Context::genSamplers(GLsizei count, GLuint *samplers)
5309{
5310 for (int i = 0; i < count; i++)
5311 {
5312 samplers[i] = mState.mSamplers->createSampler();
5313 }
5314}
5315
5316void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
5317{
5318 for (int i = 0; i < count; i++)
5319 {
5320 GLuint sampler = samplers[i];
5321
5322 if (mState.mSamplers->getSampler(sampler))
5323 {
5324 detachSampler(sampler);
5325 }
5326
5327 mState.mSamplers->deleteObject(this, sampler);
5328 }
5329}
5330
5331void Context::getInternalformativ(GLenum target,
5332 GLenum internalformat,
5333 GLenum pname,
5334 GLsizei bufSize,
5335 GLint *params)
5336{
5337 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
5338 QueryInternalFormativ(formatCaps, pname, bufSize, params);
5339}
5340
Jiajia Qin5451d532017-11-16 17:16:34 +08005341void Context::programUniform1i(GLuint program, GLint location, GLint v0)
5342{
5343 programUniform1iv(program, location, 1, &v0);
5344}
5345
5346void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
5347{
5348 GLint xy[2] = {v0, v1};
5349 programUniform2iv(program, location, 1, xy);
5350}
5351
5352void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
5353{
5354 GLint xyz[3] = {v0, v1, v2};
5355 programUniform3iv(program, location, 1, xyz);
5356}
5357
5358void Context::programUniform4i(GLuint program,
5359 GLint location,
5360 GLint v0,
5361 GLint v1,
5362 GLint v2,
5363 GLint v3)
5364{
5365 GLint xyzw[4] = {v0, v1, v2, v3};
5366 programUniform4iv(program, location, 1, xyzw);
5367}
5368
5369void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
5370{
5371 programUniform1uiv(program, location, 1, &v0);
5372}
5373
5374void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
5375{
5376 GLuint xy[2] = {v0, v1};
5377 programUniform2uiv(program, location, 1, xy);
5378}
5379
5380void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
5381{
5382 GLuint xyz[3] = {v0, v1, v2};
5383 programUniform3uiv(program, location, 1, xyz);
5384}
5385
5386void Context::programUniform4ui(GLuint program,
5387 GLint location,
5388 GLuint v0,
5389 GLuint v1,
5390 GLuint v2,
5391 GLuint v3)
5392{
5393 GLuint xyzw[4] = {v0, v1, v2, v3};
5394 programUniform4uiv(program, location, 1, xyzw);
5395}
5396
5397void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
5398{
5399 programUniform1fv(program, location, 1, &v0);
5400}
5401
5402void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
5403{
5404 GLfloat xy[2] = {v0, v1};
5405 programUniform2fv(program, location, 1, xy);
5406}
5407
5408void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
5409{
5410 GLfloat xyz[3] = {v0, v1, v2};
5411 programUniform3fv(program, location, 1, xyz);
5412}
5413
5414void Context::programUniform4f(GLuint program,
5415 GLint location,
5416 GLfloat v0,
5417 GLfloat v1,
5418 GLfloat v2,
5419 GLfloat v3)
5420{
5421 GLfloat xyzw[4] = {v0, v1, v2, v3};
5422 programUniform4fv(program, location, 1, xyzw);
5423}
5424
Jamie Madill81c2e252017-09-09 23:32:46 -04005425void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5426{
5427 Program *programObject = getProgram(program);
5428 ASSERT(programObject);
5429 if (programObject->setUniform1iv(location, count, value) ==
5430 Program::SetUniformResult::SamplerChanged)
5431 {
5432 mGLState.setObjectDirty(GL_PROGRAM);
5433 }
5434}
5435
Jiajia Qin5451d532017-11-16 17:16:34 +08005436void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5437{
5438 Program *programObject = getProgram(program);
5439 ASSERT(programObject);
5440 programObject->setUniform2iv(location, count, value);
5441}
5442
5443void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5444{
5445 Program *programObject = getProgram(program);
5446 ASSERT(programObject);
5447 programObject->setUniform3iv(location, count, value);
5448}
5449
5450void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5451{
5452 Program *programObject = getProgram(program);
5453 ASSERT(programObject);
5454 programObject->setUniform4iv(location, count, value);
5455}
5456
5457void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5458{
5459 Program *programObject = getProgram(program);
5460 ASSERT(programObject);
5461 programObject->setUniform1uiv(location, count, value);
5462}
5463
5464void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5465{
5466 Program *programObject = getProgram(program);
5467 ASSERT(programObject);
5468 programObject->setUniform2uiv(location, count, value);
5469}
5470
5471void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5472{
5473 Program *programObject = getProgram(program);
5474 ASSERT(programObject);
5475 programObject->setUniform3uiv(location, count, value);
5476}
5477
5478void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5479{
5480 Program *programObject = getProgram(program);
5481 ASSERT(programObject);
5482 programObject->setUniform4uiv(location, count, value);
5483}
5484
5485void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5486{
5487 Program *programObject = getProgram(program);
5488 ASSERT(programObject);
5489 programObject->setUniform1fv(location, count, value);
5490}
5491
5492void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5493{
5494 Program *programObject = getProgram(program);
5495 ASSERT(programObject);
5496 programObject->setUniform2fv(location, count, value);
5497}
5498
5499void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5500{
5501 Program *programObject = getProgram(program);
5502 ASSERT(programObject);
5503 programObject->setUniform3fv(location, count, value);
5504}
5505
5506void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5507{
5508 Program *programObject = getProgram(program);
5509 ASSERT(programObject);
5510 programObject->setUniform4fv(location, count, value);
5511}
5512
5513void Context::programUniformMatrix2fv(GLuint program,
5514 GLint location,
5515 GLsizei count,
5516 GLboolean transpose,
5517 const GLfloat *value)
5518{
5519 Program *programObject = getProgram(program);
5520 ASSERT(programObject);
5521 programObject->setUniformMatrix2fv(location, count, transpose, value);
5522}
5523
5524void Context::programUniformMatrix3fv(GLuint program,
5525 GLint location,
5526 GLsizei count,
5527 GLboolean transpose,
5528 const GLfloat *value)
5529{
5530 Program *programObject = getProgram(program);
5531 ASSERT(programObject);
5532 programObject->setUniformMatrix3fv(location, count, transpose, value);
5533}
5534
5535void Context::programUniformMatrix4fv(GLuint program,
5536 GLint location,
5537 GLsizei count,
5538 GLboolean transpose,
5539 const GLfloat *value)
5540{
5541 Program *programObject = getProgram(program);
5542 ASSERT(programObject);
5543 programObject->setUniformMatrix4fv(location, count, transpose, value);
5544}
5545
5546void Context::programUniformMatrix2x3fv(GLuint program,
5547 GLint location,
5548 GLsizei count,
5549 GLboolean transpose,
5550 const GLfloat *value)
5551{
5552 Program *programObject = getProgram(program);
5553 ASSERT(programObject);
5554 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
5555}
5556
5557void Context::programUniformMatrix3x2fv(GLuint program,
5558 GLint location,
5559 GLsizei count,
5560 GLboolean transpose,
5561 const GLfloat *value)
5562{
5563 Program *programObject = getProgram(program);
5564 ASSERT(programObject);
5565 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
5566}
5567
5568void Context::programUniformMatrix2x4fv(GLuint program,
5569 GLint location,
5570 GLsizei count,
5571 GLboolean transpose,
5572 const GLfloat *value)
5573{
5574 Program *programObject = getProgram(program);
5575 ASSERT(programObject);
5576 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
5577}
5578
5579void Context::programUniformMatrix4x2fv(GLuint program,
5580 GLint location,
5581 GLsizei count,
5582 GLboolean transpose,
5583 const GLfloat *value)
5584{
5585 Program *programObject = getProgram(program);
5586 ASSERT(programObject);
5587 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
5588}
5589
5590void Context::programUniformMatrix3x4fv(GLuint program,
5591 GLint location,
5592 GLsizei count,
5593 GLboolean transpose,
5594 const GLfloat *value)
5595{
5596 Program *programObject = getProgram(program);
5597 ASSERT(programObject);
5598 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
5599}
5600
5601void Context::programUniformMatrix4x3fv(GLuint program,
5602 GLint location,
5603 GLsizei count,
5604 GLboolean transpose,
5605 const GLfloat *value)
5606{
5607 Program *programObject = getProgram(program);
5608 ASSERT(programObject);
5609 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
5610}
5611
Jamie Madill81c2e252017-09-09 23:32:46 -04005612void Context::onTextureChange(const Texture *texture)
5613{
5614 // Conservatively assume all textures are dirty.
5615 // TODO(jmadill): More fine-grained update.
5616 mGLState.setObjectDirty(GL_TEXTURE);
5617}
5618
Yunchao Hea336b902017-08-02 16:05:21 +08005619void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
5620{
5621 for (int i = 0; i < count; i++)
5622 {
5623 pipelines[i] = createProgramPipeline();
5624 }
5625}
5626
5627void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
5628{
5629 for (int i = 0; i < count; i++)
5630 {
5631 if (pipelines[i] != 0)
5632 {
5633 deleteProgramPipeline(pipelines[i]);
5634 }
5635 }
5636}
5637
5638GLboolean Context::isProgramPipeline(GLuint pipeline)
5639{
5640 if (pipeline == 0)
5641 {
5642 return GL_FALSE;
5643 }
5644
5645 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
5646}
5647
Jamie Madillc29968b2016-01-20 11:17:23 -05005648} // namespace gl