blob: f2d09e8aa1b383cac71b25583218d2ea4afc2a4d [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
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400414 handleError(mImplementation->initialize());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000415}
416
Jamie Madill4928b7c2017-06-20 12:57:39 -0400417egl::Error Context::onDestroy(const egl::Display *display)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000418{
Corentin Wallez80b24112015-08-25 16:41:57 -0400419 for (auto fence : mFenceNVMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000420 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400421 SafeDelete(fence.second);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000422 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400423 mFenceNVMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000424
Corentin Wallez80b24112015-08-25 16:41:57 -0400425 for (auto query : mQueryMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000426 {
Geoff Langf0aa8422015-09-29 15:08:34 -0400427 if (query.second != nullptr)
428 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400429 query.second->release(this);
Geoff Langf0aa8422015-09-29 15:08:34 -0400430 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000431 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400432 mQueryMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000433
Corentin Wallez80b24112015-08-25 16:41:57 -0400434 for (auto vertexArray : mVertexArrayMap)
Jamie Madill57a89722013-07-02 11:57:03 -0400435 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400436 if (vertexArray.second)
437 {
438 vertexArray.second->onDestroy(this);
439 }
Jamie Madill57a89722013-07-02 11:57:03 -0400440 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400441 mVertexArrayMap.clear();
Jamie Madill57a89722013-07-02 11:57:03 -0400442
Corentin Wallez80b24112015-08-25 16:41:57 -0400443 for (auto transformFeedback : mTransformFeedbackMap)
Geoff Langc8058452014-02-03 12:04:11 -0500444 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500445 if (transformFeedback.second != nullptr)
446 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500447 transformFeedback.second->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500448 }
Geoff Langc8058452014-02-03 12:04:11 -0500449 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400450 mTransformFeedbackMap.clear();
Geoff Langc8058452014-02-03 12:04:11 -0500451
Jamie Madilldedd7b92014-11-05 16:30:36 -0500452 for (auto &zeroTexture : mZeroTextures)
Geoff Lang76b10c92014-09-05 16:28:14 -0400453 {
Jamie Madill71c88b32017-09-14 22:20:29 -0400454 ANGLE_TRY(zeroTexture.second->onDestroy(this));
Jamie Madill4928b7c2017-06-20 12:57:39 -0400455 zeroTexture.second.set(this, nullptr);
Geoff Lang76b10c92014-09-05 16:28:14 -0400456 }
457 mZeroTextures.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000458
Corentin Wallezccab69d2017-01-27 16:57:15 -0500459 SafeDelete(mSurfacelessFramebuffer);
460
Jamie Madill4928b7c2017-06-20 12:57:39 -0400461 ANGLE_TRY(releaseSurface(display));
Jamie Madill2f348d22017-06-05 10:50:59 -0400462 releaseShaderCompiler();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500463
Jamie Madill4928b7c2017-06-20 12:57:39 -0400464 mGLState.reset(this);
465
Jamie Madill6c1f6712017-02-14 19:08:04 -0500466 mState.mBuffers->release(this);
467 mState.mShaderPrograms->release(this);
468 mState.mTextures->release(this);
469 mState.mRenderbuffers->release(this);
470 mState.mSamplers->release(this);
Jamie Madill70b5bb02017-08-28 13:32:37 -0400471 mState.mSyncs->release(this);
Jamie Madill6c1f6712017-02-14 19:08:04 -0500472 mState.mPaths->release(this);
473 mState.mFramebuffers->release(this);
Yunchao Hea336b902017-08-02 16:05:21 +0800474 mState.mPipelines->release(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400475
Jamie Madill76e471e2017-10-21 09:56:01 -0400476 mImplementation->onDestroy(this);
477
Jamie Madill4928b7c2017-06-20 12:57:39 -0400478 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000479}
480
Jamie Madill70ee0f62017-02-06 16:04:20 -0500481Context::~Context()
482{
483}
484
Jamie Madill4928b7c2017-06-20 12:57:39 -0400485egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000486{
Jamie Madill61e16b42017-06-19 11:13:23 -0400487 mCurrentDisplay = display;
488
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000489 if (!mHasBeenCurrent)
490 {
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000491 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500492 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400493 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000494
Corentin Wallezc295e512017-01-27 17:47:50 -0500495 int width = 0;
496 int height = 0;
497 if (surface != nullptr)
498 {
499 width = surface->getWidth();
500 height = surface->getHeight();
501 }
502
503 mGLState.setViewportParams(0, 0, width, height);
504 mGLState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000505
506 mHasBeenCurrent = true;
507 }
508
Jamie Madill1b94d432015-08-07 13:23:23 -0400509 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700510 mGLState.setAllDirtyBits();
Jamie Madill81c2e252017-09-09 23:32:46 -0400511 mGLState.setAllDirtyObjects();
Jamie Madill1b94d432015-08-07 13:23:23 -0400512
Jamie Madill4928b7c2017-06-20 12:57:39 -0400513 ANGLE_TRY(releaseSurface(display));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500514
515 Framebuffer *newDefault = nullptr;
516 if (surface != nullptr)
517 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400518 ANGLE_TRY(surface->setIsCurrent(this, true));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500519 mCurrentSurface = surface;
520 newDefault = surface->getDefaultFramebuffer();
521 }
522 else
523 {
524 if (mSurfacelessFramebuffer == nullptr)
525 {
526 mSurfacelessFramebuffer = new Framebuffer(mImplementation.get());
527 }
528
529 newDefault = mSurfacelessFramebuffer;
530 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000531
Corentin Wallez37c39792015-08-20 14:19:46 -0400532 // Update default framebuffer, the binding of the previous default
533 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400534 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700535 if (mGLState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400536 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700537 mGLState.setReadFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400538 }
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700539 if (mGLState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400540 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700541 mGLState.setDrawFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400542 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500543 mState.mFramebuffers->setDefaultFramebuffer(newDefault);
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400544 }
Ian Ewell292f0052016-02-04 10:37:32 -0500545
546 // Notify the renderer of a context switch
Jamie Madill4928b7c2017-06-20 12:57:39 -0400547 mImplementation->onMakeCurrent(this);
548 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000549}
550
Jamie Madill4928b7c2017-06-20 12:57:39 -0400551egl::Error Context::releaseSurface(const egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400552{
Corentin Wallez37c39792015-08-20 14:19:46 -0400553 // Remove the default framebuffer
Corentin Wallezc295e512017-01-27 17:47:50 -0500554 Framebuffer *currentDefault = nullptr;
555 if (mCurrentSurface != nullptr)
Corentin Wallez51706ea2015-08-07 14:39:22 -0400556 {
Corentin Wallezc295e512017-01-27 17:47:50 -0500557 currentDefault = mCurrentSurface->getDefaultFramebuffer();
558 }
559 else if (mSurfacelessFramebuffer != nullptr)
560 {
561 currentDefault = mSurfacelessFramebuffer;
Corentin Wallez51706ea2015-08-07 14:39:22 -0400562 }
563
Corentin Wallezc295e512017-01-27 17:47:50 -0500564 if (mGLState.getReadFramebuffer() == currentDefault)
565 {
566 mGLState.setReadFramebufferBinding(nullptr);
567 }
568 if (mGLState.getDrawFramebuffer() == currentDefault)
569 {
570 mGLState.setDrawFramebufferBinding(nullptr);
571 }
572 mState.mFramebuffers->setDefaultFramebuffer(nullptr);
573
574 if (mCurrentSurface)
575 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400576 ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
Corentin Wallezc295e512017-01-27 17:47:50 -0500577 mCurrentSurface = nullptr;
578 }
Jamie Madill4928b7c2017-06-20 12:57:39 -0400579
580 return egl::NoError();
Jamie Madill77a72f62015-04-14 11:18:32 -0400581}
582
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000583GLuint Context::createBuffer()
584{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500585 return mState.mBuffers->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000586}
587
588GLuint Context::createProgram()
589{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500590 return mState.mShaderPrograms->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000591}
592
593GLuint Context::createShader(GLenum type)
594{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500595 return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000596}
597
598GLuint Context::createTexture()
599{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500600 return mState.mTextures->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000601}
602
603GLuint Context::createRenderbuffer()
604{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500605 return mState.mRenderbuffers->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000606}
607
Sami Väisänene45e53b2016-05-25 10:36:04 +0300608GLuint Context::createPaths(GLsizei range)
609{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500610 auto resultOrError = mState.mPaths->createPaths(mImplementation.get(), range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300611 if (resultOrError.isError())
612 {
613 handleError(resultOrError.getError());
614 return 0;
615 }
616 return resultOrError.getResult();
617}
618
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000619// Returns an unused framebuffer name
620GLuint Context::createFramebuffer()
621{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500622 return mState.mFramebuffers->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000623}
624
Jamie Madill33dc8432013-07-26 11:55:05 -0400625GLuint Context::createFenceNV()
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000626{
Jamie Madill33dc8432013-07-26 11:55:05 -0400627 GLuint handle = mFenceNVHandleAllocator.allocate();
Jamie Madill96a483b2017-06-27 16:49:21 -0400628 mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV()));
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000629 return handle;
630}
631
Yunchao Hea336b902017-08-02 16:05:21 +0800632GLuint Context::createProgramPipeline()
633{
634 return mState.mPipelines->createProgramPipeline();
635}
636
Jiajia Qin5451d532017-11-16 17:16:34 +0800637GLuint Context::createShaderProgramv(GLenum type, GLsizei count, const GLchar *const *strings)
638{
639 UNIMPLEMENTED();
640 return 0u;
641}
642
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000643void Context::deleteBuffer(GLuint buffer)
644{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500645 if (mState.mBuffers->getBuffer(buffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000646 {
647 detachBuffer(buffer);
648 }
Jamie Madill893ab082014-05-16 16:56:10 -0400649
Jamie Madill6c1f6712017-02-14 19:08:04 -0500650 mState.mBuffers->deleteObject(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000651}
652
653void Context::deleteShader(GLuint shader)
654{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500655 mState.mShaderPrograms->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000656}
657
658void Context::deleteProgram(GLuint program)
659{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500660 mState.mShaderPrograms->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000661}
662
663void Context::deleteTexture(GLuint texture)
664{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500665 if (mState.mTextures->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000666 {
667 detachTexture(texture);
668 }
669
Jamie Madill6c1f6712017-02-14 19:08:04 -0500670 mState.mTextures->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000671}
672
673void Context::deleteRenderbuffer(GLuint renderbuffer)
674{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500675 if (mState.mRenderbuffers->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000676 {
677 detachRenderbuffer(renderbuffer);
678 }
Jamie Madill893ab082014-05-16 16:56:10 -0400679
Jamie Madill6c1f6712017-02-14 19:08:04 -0500680 mState.mRenderbuffers->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000681}
682
Jamie Madill7f0c5a42017-08-26 22:43:26 -0400683void Context::deleteSync(GLsync sync)
Jamie Madillcd055f82013-07-26 11:55:15 -0400684{
685 // The spec specifies the underlying Fence object is not deleted until all current
686 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
687 // and since our API is currently designed for being called from a single thread, we can delete
688 // the fence immediately.
Jamie Madill70b5bb02017-08-28 13:32:37 -0400689 mState.mSyncs->deleteObject(this, static_cast<GLuint>(reinterpret_cast<uintptr_t>(sync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400690}
691
Yunchao Hea336b902017-08-02 16:05:21 +0800692void Context::deleteProgramPipeline(GLuint pipeline)
693{
694 if (mState.mPipelines->getProgramPipeline(pipeline))
695 {
696 detachProgramPipeline(pipeline);
697 }
698
699 mState.mPipelines->deleteObject(this, pipeline);
700}
701
Sami Väisänene45e53b2016-05-25 10:36:04 +0300702void Context::deletePaths(GLuint first, GLsizei range)
703{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500704 mState.mPaths->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300705}
706
707bool Context::hasPathData(GLuint path) const
708{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500709 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300710 if (pathObj == nullptr)
711 return false;
712
713 return pathObj->hasPathData();
714}
715
716bool Context::hasPath(GLuint path) const
717{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500718 return mState.mPaths->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300719}
720
721void Context::setPathCommands(GLuint path,
722 GLsizei numCommands,
723 const GLubyte *commands,
724 GLsizei numCoords,
725 GLenum coordType,
726 const void *coords)
727{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500728 auto *pathObject = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300729
730 handleError(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
731}
732
733void Context::setPathParameterf(GLuint path, GLenum pname, GLfloat value)
734{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500735 auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300736
737 switch (pname)
738 {
739 case GL_PATH_STROKE_WIDTH_CHROMIUM:
740 pathObj->setStrokeWidth(value);
741 break;
742 case GL_PATH_END_CAPS_CHROMIUM:
743 pathObj->setEndCaps(static_cast<GLenum>(value));
744 break;
745 case GL_PATH_JOIN_STYLE_CHROMIUM:
746 pathObj->setJoinStyle(static_cast<GLenum>(value));
747 break;
748 case GL_PATH_MITER_LIMIT_CHROMIUM:
749 pathObj->setMiterLimit(value);
750 break;
751 case GL_PATH_STROKE_BOUND_CHROMIUM:
752 pathObj->setStrokeBound(value);
753 break;
754 default:
755 UNREACHABLE();
756 break;
757 }
758}
759
760void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value) const
761{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500762 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300763
764 switch (pname)
765 {
766 case GL_PATH_STROKE_WIDTH_CHROMIUM:
767 *value = pathObj->getStrokeWidth();
768 break;
769 case GL_PATH_END_CAPS_CHROMIUM:
770 *value = static_cast<GLfloat>(pathObj->getEndCaps());
771 break;
772 case GL_PATH_JOIN_STYLE_CHROMIUM:
773 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
774 break;
775 case GL_PATH_MITER_LIMIT_CHROMIUM:
776 *value = pathObj->getMiterLimit();
777 break;
778 case GL_PATH_STROKE_BOUND_CHROMIUM:
779 *value = pathObj->getStrokeBound();
780 break;
781 default:
782 UNREACHABLE();
783 break;
784 }
785}
786
787void Context::setPathStencilFunc(GLenum func, GLint ref, GLuint mask)
788{
789 mGLState.setPathStencilFunc(func, ref, mask);
790}
791
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000792void Context::deleteFramebuffer(GLuint framebuffer)
793{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500794 if (mState.mFramebuffers->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000795 {
796 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000797 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500798
Jamie Madill6c1f6712017-02-14 19:08:04 -0500799 mState.mFramebuffers->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000800}
801
Jamie Madill33dc8432013-07-26 11:55:05 -0400802void Context::deleteFenceNV(GLuint fence)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000803{
Jamie Madill96a483b2017-06-27 16:49:21 -0400804 FenceNV *fenceObject = nullptr;
805 if (mFenceNVMap.erase(fence, &fenceObject))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000806 {
Jamie Madill96a483b2017-06-27 16:49:21 -0400807 mFenceNVHandleAllocator.release(fence);
808 delete fenceObject;
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000809 }
810}
811
Geoff Lang70d0f492015-12-10 17:45:46 -0500812Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000813{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500814 return mState.mBuffers->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000815}
816
Jamie Madill570f7c82014-07-03 10:38:54 -0400817Texture *Context::getTexture(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000818{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500819 return mState.mTextures->getTexture(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000820}
821
Geoff Lang70d0f492015-12-10 17:45:46 -0500822Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000823{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500824 return mState.mRenderbuffers->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000825}
826
Jamie Madill70b5bb02017-08-28 13:32:37 -0400827Sync *Context::getSync(GLsync handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400828{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400829 return mState.mSyncs->getSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400830}
831
Jamie Madill57a89722013-07-02 11:57:03 -0400832VertexArray *Context::getVertexArray(GLuint handle) const
833{
Jamie Madill96a483b2017-06-27 16:49:21 -0400834 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -0400835}
836
Jamie Madilldc356042013-07-19 16:36:57 -0400837Sampler *Context::getSampler(GLuint handle) const
838{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500839 return mState.mSamplers->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400840}
841
Geoff Langc8058452014-02-03 12:04:11 -0500842TransformFeedback *Context::getTransformFeedback(GLuint handle) const
843{
Jamie Madill96a483b2017-06-27 16:49:21 -0400844 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -0500845}
846
Yunchao Hea336b902017-08-02 16:05:21 +0800847ProgramPipeline *Context::getProgramPipeline(GLuint handle) const
848{
849 return mState.mPipelines->getProgramPipeline(handle);
850}
851
Geoff Lang70d0f492015-12-10 17:45:46 -0500852LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
853{
854 switch (identifier)
855 {
856 case GL_BUFFER:
857 return getBuffer(name);
858 case GL_SHADER:
859 return getShader(name);
860 case GL_PROGRAM:
861 return getProgram(name);
862 case GL_VERTEX_ARRAY:
863 return getVertexArray(name);
864 case GL_QUERY:
865 return getQuery(name);
866 case GL_TRANSFORM_FEEDBACK:
867 return getTransformFeedback(name);
868 case GL_SAMPLER:
869 return getSampler(name);
870 case GL_TEXTURE:
871 return getTexture(name);
872 case GL_RENDERBUFFER:
873 return getRenderbuffer(name);
874 case GL_FRAMEBUFFER:
875 return getFramebuffer(name);
876 default:
877 UNREACHABLE();
878 return nullptr;
879 }
880}
881
882LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
883{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400884 return getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
Geoff Lang70d0f492015-12-10 17:45:46 -0500885}
886
Martin Radev9d901792016-07-15 15:58:58 +0300887void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
888{
889 LabeledObject *object = getLabeledObject(identifier, name);
890 ASSERT(object != nullptr);
891
892 std::string labelName = GetObjectLabelFromPointer(length, label);
893 object->setLabel(labelName);
Jamie Madill8693bdb2017-09-02 15:32:14 -0400894
895 // TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the
896 // specified object is active until we do this.
897 mGLState.setObjectDirty(identifier);
Martin Radev9d901792016-07-15 15:58:58 +0300898}
899
900void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
901{
902 LabeledObject *object = getLabeledObjectFromPtr(ptr);
903 ASSERT(object != nullptr);
904
905 std::string labelName = GetObjectLabelFromPointer(length, label);
906 object->setLabel(labelName);
907}
908
909void Context::getObjectLabel(GLenum identifier,
910 GLuint name,
911 GLsizei bufSize,
912 GLsizei *length,
913 GLchar *label) const
914{
915 LabeledObject *object = getLabeledObject(identifier, name);
916 ASSERT(object != nullptr);
917
918 const std::string &objectLabel = object->getLabel();
919 GetObjectLabelBase(objectLabel, bufSize, length, label);
920}
921
922void Context::getObjectPtrLabel(const void *ptr,
923 GLsizei bufSize,
924 GLsizei *length,
925 GLchar *label) const
926{
927 LabeledObject *object = getLabeledObjectFromPtr(ptr);
928 ASSERT(object != nullptr);
929
930 const std::string &objectLabel = object->getLabel();
931 GetObjectLabelBase(objectLabel, bufSize, length, label);
932}
933
Jamie Madilldc356042013-07-19 16:36:57 -0400934bool Context::isSampler(GLuint samplerName) const
935{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500936 return mState.mSamplers->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -0400937}
938
Jamie Madilldedd7b92014-11-05 16:30:36 -0500939void Context::bindTexture(GLenum target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000940{
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500941 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000942
Jamie Madilldedd7b92014-11-05 16:30:36 -0500943 if (handle == 0)
944 {
945 texture = mZeroTextures[target].get();
946 }
947 else
948 {
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500949 texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500950 }
951
952 ASSERT(texture);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400953 mGLState.setSamplerTexture(this, target, texture);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +0000954}
955
Jamie Madill5bf9ff42016-02-01 11:13:03 -0500956void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000957{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500958 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
959 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700960 mGLState.setReadFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000961}
962
Jamie Madill5bf9ff42016-02-01 11:13:03 -0500963void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000964{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500965 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
966 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700967 mGLState.setDrawFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000968}
969
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500970void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -0400971{
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500972 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700973 mGLState.setVertexArrayBinding(vertexArray);
Jamie Madill57a89722013-07-02 11:57:03 -0400974}
975
Shao80957d92017-02-20 21:25:59 +0800976void Context::bindVertexBuffer(GLuint bindingIndex,
977 GLuint bufferHandle,
978 GLintptr offset,
979 GLsizei stride)
980{
981 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400982 mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Shao80957d92017-02-20 21:25:59 +0800983}
984
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500985void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -0400986{
Geoff Lang76b10c92014-09-05 16:28:14 -0400987 ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -0400988 Sampler *sampler =
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500989 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400990 mGLState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -0400991}
992
Xinghua Cao65ec0b22017-03-28 16:10:52 +0800993void Context::bindImageTexture(GLuint unit,
994 GLuint texture,
995 GLint level,
996 GLboolean layered,
997 GLint layer,
998 GLenum access,
999 GLenum format)
1000{
1001 Texture *tex = mState.mTextures->getTexture(texture);
1002 mGLState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
1003}
1004
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001005void Context::useProgram(GLuint program)
1006{
Jamie Madill6c1f6712017-02-14 19:08:04 -05001007 mGLState.setProgram(this, getProgram(program));
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001008}
1009
Jiajia Qin5451d532017-11-16 17:16:34 +08001010void Context::useProgramStages(GLuint pipeline, GLbitfield stages, GLuint program)
1011{
1012 UNIMPLEMENTED();
1013}
1014
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001015void Context::bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001016{
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001017 ASSERT(target == GL_TRANSFORM_FEEDBACK);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001018 TransformFeedback *transformFeedback =
1019 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001020 mGLState.setTransformFeedbackBinding(this, transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -05001021}
1022
Yunchao Hea336b902017-08-02 16:05:21 +08001023void Context::bindProgramPipeline(GLuint pipelineHandle)
1024{
1025 ProgramPipeline *pipeline =
1026 mState.mPipelines->checkProgramPipelineAllocation(mImplementation.get(), pipelineHandle);
1027 mGLState.setProgramPipelineBinding(this, pipeline);
1028}
1029
Jamie Madillf0e04492017-08-26 15:28:42 -04001030void Context::beginQuery(GLenum target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001031{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001032 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001033 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001034
Geoff Lang5aad9672014-09-08 11:10:42 -04001035 // begin query
Jamie Madillf0e04492017-08-26 15:28:42 -04001036 ANGLE_CONTEXT_TRY(queryObject->begin());
Geoff Lang5aad9672014-09-08 11:10:42 -04001037
1038 // set query as active for specified target only if begin succeeded
Jamie Madill4928b7c2017-06-20 12:57:39 -04001039 mGLState.setActiveQuery(this, target, queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001040}
1041
Jamie Madillf0e04492017-08-26 15:28:42 -04001042void Context::endQuery(GLenum target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001043{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001044 Query *queryObject = mGLState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001045 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001046
Jamie Madillf0e04492017-08-26 15:28:42 -04001047 handleError(queryObject->end());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001048
Geoff Lang5aad9672014-09-08 11:10:42 -04001049 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madill4928b7c2017-06-20 12:57:39 -04001050 mGLState.setActiveQuery(this, target, nullptr);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001051}
1052
Jamie Madillf0e04492017-08-26 15:28:42 -04001053void Context::queryCounter(GLuint id, GLenum target)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001054{
1055 ASSERT(target == GL_TIMESTAMP_EXT);
1056
1057 Query *queryObject = getQuery(id, true, target);
1058 ASSERT(queryObject);
1059
Jamie Madillf0e04492017-08-26 15:28:42 -04001060 handleError(queryObject->queryCounter());
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001061}
1062
1063void Context::getQueryiv(GLenum target, GLenum pname, GLint *params)
1064{
1065 switch (pname)
1066 {
1067 case GL_CURRENT_QUERY_EXT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001068 params[0] = mGLState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001069 break;
1070 case GL_QUERY_COUNTER_BITS_EXT:
1071 switch (target)
1072 {
1073 case GL_TIME_ELAPSED_EXT:
1074 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1075 break;
1076 case GL_TIMESTAMP_EXT:
1077 params[0] = getExtensions().queryCounterBitsTimestamp;
1078 break;
1079 default:
1080 UNREACHABLE();
1081 params[0] = 0;
1082 break;
1083 }
1084 break;
1085 default:
1086 UNREACHABLE();
1087 return;
1088 }
1089}
1090
Geoff Lang2186c382016-10-14 10:54:54 -04001091void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001092{
Geoff Lang2186c382016-10-14 10:54:54 -04001093 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001094}
1095
Geoff Lang2186c382016-10-14 10:54:54 -04001096void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001097{
Geoff Lang2186c382016-10-14 10:54:54 -04001098 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001099}
1100
Geoff Lang2186c382016-10-14 10:54:54 -04001101void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001102{
Geoff Lang2186c382016-10-14 10:54:54 -04001103 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001104}
1105
Geoff Lang2186c382016-10-14 10:54:54 -04001106void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001107{
Geoff Lang2186c382016-10-14 10:54:54 -04001108 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001109}
1110
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001111Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001112{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001113 return mState.mFramebuffers->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001114}
1115
Jamie Madill2f348d22017-06-05 10:50:59 -04001116FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001117{
Jamie Madill96a483b2017-06-27 16:49:21 -04001118 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001119}
1120
Jamie Madill2f348d22017-06-05 10:50:59 -04001121Query *Context::getQuery(GLuint handle, bool create, GLenum type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001122{
Jamie Madill96a483b2017-06-27 16:49:21 -04001123 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001124 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001125 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001126 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001127
1128 Query *query = mQueryMap.query(handle);
1129 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001130 {
Jamie Madill96a483b2017-06-27 16:49:21 -04001131 query = new Query(mImplementation->createQuery(type), handle);
1132 query->addRef();
1133 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001134 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001135 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001136}
1137
Geoff Lang70d0f492015-12-10 17:45:46 -05001138Query *Context::getQuery(GLuint handle) const
1139{
Jamie Madill96a483b2017-06-27 16:49:21 -04001140 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001141}
1142
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001143Texture *Context::getTargetTexture(GLenum target) const
1144{
Ian Ewellbda75592016-04-18 17:25:54 -04001145 ASSERT(ValidTextureTarget(this, target) || ValidTextureExternalTarget(this, target));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001146 return mGLState.getTargetTexture(target);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001147}
1148
Geoff Lang76b10c92014-09-05 16:28:14 -04001149Texture *Context::getSamplerTexture(unsigned int sampler, GLenum type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001150{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001151 return mGLState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001152}
1153
Geoff Lang492a7e42014-11-05 13:27:06 -05001154Compiler *Context::getCompiler() const
1155{
Jamie Madill2f348d22017-06-05 10:50:59 -04001156 if (mCompiler.get() == nullptr)
1157 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001158 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001159 }
1160 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001161}
1162
Jamie Madillc1d770e2017-04-13 17:31:24 -04001163void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001164{
1165 switch (pname)
1166 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001167 case GL_SHADER_COMPILER:
1168 *params = GL_TRUE;
1169 break;
1170 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1171 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1172 break;
1173 default:
1174 mGLState.getBooleanv(pname, params);
1175 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001176 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001177}
1178
Jamie Madillc1d770e2017-04-13 17:31:24 -04001179void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001180{
Shannon Woods53a94a82014-06-24 15:20:36 -04001181 // Queries about context capabilities and maximums are answered by Context.
1182 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001183 switch (pname)
1184 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001185 case GL_ALIASED_LINE_WIDTH_RANGE:
1186 params[0] = mCaps.minAliasedLineWidth;
1187 params[1] = mCaps.maxAliasedLineWidth;
1188 break;
1189 case GL_ALIASED_POINT_SIZE_RANGE:
1190 params[0] = mCaps.minAliasedPointSize;
1191 params[1] = mCaps.maxAliasedPointSize;
1192 break;
1193 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1194 ASSERT(mExtensions.textureFilterAnisotropic);
1195 *params = mExtensions.maxTextureAnisotropy;
1196 break;
1197 case GL_MAX_TEXTURE_LOD_BIAS:
1198 *params = mCaps.maxLODBias;
1199 break;
1200
1201 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1202 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1203 {
1204 ASSERT(mExtensions.pathRendering);
1205 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1206 memcpy(params, m, 16 * sizeof(GLfloat));
1207 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001208 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001209
Jamie Madill231c7f52017-04-26 13:45:37 -04001210 default:
1211 mGLState.getFloatv(pname, params);
1212 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001213 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001214}
1215
Jamie Madillc1d770e2017-04-13 17:31:24 -04001216void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001217{
Shannon Woods53a94a82014-06-24 15:20:36 -04001218 // Queries about context capabilities and maximums are answered by Context.
1219 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001220
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001221 switch (pname)
1222 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001223 case GL_MAX_VERTEX_ATTRIBS:
1224 *params = mCaps.maxVertexAttributes;
1225 break;
1226 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1227 *params = mCaps.maxVertexUniformVectors;
1228 break;
1229 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
1230 *params = mCaps.maxVertexUniformComponents;
1231 break;
1232 case GL_MAX_VARYING_VECTORS:
1233 *params = mCaps.maxVaryingVectors;
1234 break;
1235 case GL_MAX_VARYING_COMPONENTS:
1236 *params = mCaps.maxVertexOutputComponents;
1237 break;
1238 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1239 *params = mCaps.maxCombinedTextureImageUnits;
1240 break;
1241 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
1242 *params = mCaps.maxVertexTextureImageUnits;
1243 break;
1244 case GL_MAX_TEXTURE_IMAGE_UNITS:
1245 *params = mCaps.maxTextureImageUnits;
1246 break;
1247 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1248 *params = mCaps.maxFragmentUniformVectors;
1249 break;
1250 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
1251 *params = mCaps.maxFragmentUniformComponents;
1252 break;
1253 case GL_MAX_RENDERBUFFER_SIZE:
1254 *params = mCaps.maxRenderbufferSize;
1255 break;
1256 case GL_MAX_COLOR_ATTACHMENTS_EXT:
1257 *params = mCaps.maxColorAttachments;
1258 break;
1259 case GL_MAX_DRAW_BUFFERS_EXT:
1260 *params = mCaps.maxDrawBuffers;
1261 break;
1262 // case GL_FRAMEBUFFER_BINDING: // now equivalent to
1263 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
1264 case GL_SUBPIXEL_BITS:
1265 *params = 4;
1266 break;
1267 case GL_MAX_TEXTURE_SIZE:
1268 *params = mCaps.max2DTextureSize;
1269 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001270 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
1271 *params = mCaps.maxRectangleTextureSize;
1272 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001273 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1274 *params = mCaps.maxCubeMapTextureSize;
1275 break;
1276 case GL_MAX_3D_TEXTURE_SIZE:
1277 *params = mCaps.max3DTextureSize;
1278 break;
1279 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1280 *params = mCaps.maxArrayTextureLayers;
1281 break;
1282 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1283 *params = mCaps.uniformBufferOffsetAlignment;
1284 break;
1285 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1286 *params = mCaps.maxUniformBufferBindings;
1287 break;
1288 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
1289 *params = mCaps.maxVertexUniformBlocks;
1290 break;
1291 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
1292 *params = mCaps.maxFragmentUniformBlocks;
1293 break;
1294 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1295 *params = mCaps.maxCombinedTextureImageUnits;
1296 break;
1297 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1298 *params = mCaps.maxVertexOutputComponents;
1299 break;
1300 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1301 *params = mCaps.maxFragmentInputComponents;
1302 break;
1303 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1304 *params = mCaps.minProgramTexelOffset;
1305 break;
1306 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1307 *params = mCaps.maxProgramTexelOffset;
1308 break;
1309 case GL_MAJOR_VERSION:
1310 *params = getClientVersion().major;
1311 break;
1312 case GL_MINOR_VERSION:
1313 *params = getClientVersion().minor;
1314 break;
1315 case GL_MAX_ELEMENTS_INDICES:
1316 *params = mCaps.maxElementsIndices;
1317 break;
1318 case GL_MAX_ELEMENTS_VERTICES:
1319 *params = mCaps.maxElementsVertices;
1320 break;
1321 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1322 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1323 break;
1324 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1325 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1326 break;
1327 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1328 *params = mCaps.maxTransformFeedbackSeparateComponents;
1329 break;
1330 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1331 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1332 break;
1333 case GL_MAX_SAMPLES_ANGLE:
1334 *params = mCaps.maxSamples;
1335 break;
1336 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001337 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001338 params[0] = mCaps.maxViewportWidth;
1339 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001340 }
1341 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001342 case GL_COMPRESSED_TEXTURE_FORMATS:
1343 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1344 params);
1345 break;
1346 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1347 *params = mResetStrategy;
1348 break;
1349 case GL_NUM_SHADER_BINARY_FORMATS:
1350 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1351 break;
1352 case GL_SHADER_BINARY_FORMATS:
1353 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1354 break;
1355 case GL_NUM_PROGRAM_BINARY_FORMATS:
1356 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1357 break;
1358 case GL_PROGRAM_BINARY_FORMATS:
1359 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1360 break;
1361 case GL_NUM_EXTENSIONS:
1362 *params = static_cast<GLint>(mExtensionStrings.size());
1363 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001364
Jamie Madill231c7f52017-04-26 13:45:37 -04001365 // GL_KHR_debug
1366 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1367 *params = mExtensions.maxDebugMessageLength;
1368 break;
1369 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1370 *params = mExtensions.maxDebugLoggedMessages;
1371 break;
1372 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1373 *params = mExtensions.maxDebugGroupStackDepth;
1374 break;
1375 case GL_MAX_LABEL_LENGTH:
1376 *params = mExtensions.maxLabelLength;
1377 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001378
Martin Radeve5285d22017-07-14 16:23:53 +03001379 // GL_ANGLE_multiview
1380 case GL_MAX_VIEWS_ANGLE:
1381 *params = mExtensions.maxViews;
1382 break;
1383
Jamie Madill231c7f52017-04-26 13:45:37 -04001384 // GL_EXT_disjoint_timer_query
1385 case GL_GPU_DISJOINT_EXT:
1386 *params = mImplementation->getGPUDisjoint();
1387 break;
1388 case GL_MAX_FRAMEBUFFER_WIDTH:
1389 *params = mCaps.maxFramebufferWidth;
1390 break;
1391 case GL_MAX_FRAMEBUFFER_HEIGHT:
1392 *params = mCaps.maxFramebufferHeight;
1393 break;
1394 case GL_MAX_FRAMEBUFFER_SAMPLES:
1395 *params = mCaps.maxFramebufferSamples;
1396 break;
1397 case GL_MAX_SAMPLE_MASK_WORDS:
1398 *params = mCaps.maxSampleMaskWords;
1399 break;
1400 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1401 *params = mCaps.maxColorTextureSamples;
1402 break;
1403 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1404 *params = mCaps.maxDepthTextureSamples;
1405 break;
1406 case GL_MAX_INTEGER_SAMPLES:
1407 *params = mCaps.maxIntegerSamples;
1408 break;
1409 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1410 *params = mCaps.maxVertexAttribRelativeOffset;
1411 break;
1412 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1413 *params = mCaps.maxVertexAttribBindings;
1414 break;
1415 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1416 *params = mCaps.maxVertexAttribStride;
1417 break;
1418 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
1419 *params = mCaps.maxVertexAtomicCounterBuffers;
1420 break;
1421 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
1422 *params = mCaps.maxVertexAtomicCounters;
1423 break;
1424 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
1425 *params = mCaps.maxVertexImageUniforms;
1426 break;
1427 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
1428 *params = mCaps.maxVertexShaderStorageBlocks;
1429 break;
1430 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
1431 *params = mCaps.maxFragmentAtomicCounterBuffers;
1432 break;
1433 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
1434 *params = mCaps.maxFragmentAtomicCounters;
1435 break;
1436 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
1437 *params = mCaps.maxFragmentImageUniforms;
1438 break;
1439 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
1440 *params = mCaps.maxFragmentShaderStorageBlocks;
1441 break;
1442 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1443 *params = mCaps.minProgramTextureGatherOffset;
1444 break;
1445 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1446 *params = mCaps.maxProgramTextureGatherOffset;
1447 break;
1448 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1449 *params = mCaps.maxComputeWorkGroupInvocations;
1450 break;
1451 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
1452 *params = mCaps.maxComputeUniformBlocks;
1453 break;
1454 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
1455 *params = mCaps.maxComputeTextureImageUnits;
1456 break;
1457 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1458 *params = mCaps.maxComputeSharedMemorySize;
1459 break;
1460 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
1461 *params = mCaps.maxComputeUniformComponents;
1462 break;
1463 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
1464 *params = mCaps.maxComputeAtomicCounterBuffers;
1465 break;
1466 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
1467 *params = mCaps.maxComputeAtomicCounters;
1468 break;
1469 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
1470 *params = mCaps.maxComputeImageUniforms;
1471 break;
1472 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
1473 *params = mCaps.maxCombinedComputeUniformComponents;
1474 break;
1475 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
1476 *params = mCaps.maxComputeShaderStorageBlocks;
1477 break;
1478 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1479 *params = mCaps.maxCombinedShaderOutputResources;
1480 break;
1481 case GL_MAX_UNIFORM_LOCATIONS:
1482 *params = mCaps.maxUniformLocations;
1483 break;
1484 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1485 *params = mCaps.maxAtomicCounterBufferBindings;
1486 break;
1487 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1488 *params = mCaps.maxAtomicCounterBufferSize;
1489 break;
1490 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1491 *params = mCaps.maxCombinedAtomicCounterBuffers;
1492 break;
1493 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1494 *params = mCaps.maxCombinedAtomicCounters;
1495 break;
1496 case GL_MAX_IMAGE_UNITS:
1497 *params = mCaps.maxImageUnits;
1498 break;
1499 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1500 *params = mCaps.maxCombinedImageUniforms;
1501 break;
1502 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1503 *params = mCaps.maxShaderStorageBufferBindings;
1504 break;
1505 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1506 *params = mCaps.maxCombinedShaderStorageBlocks;
1507 break;
1508 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1509 *params = mCaps.shaderStorageBufferOffsetAlignment;
1510 break;
1511 default:
1512 mGLState.getIntegerv(this, pname, params);
1513 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001514 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001515}
1516
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001517void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001518{
Shannon Woods53a94a82014-06-24 15:20:36 -04001519 // Queries about context capabilities and maximums are answered by Context.
1520 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001521 switch (pname)
1522 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001523 case GL_MAX_ELEMENT_INDEX:
1524 *params = mCaps.maxElementIndex;
1525 break;
1526 case GL_MAX_UNIFORM_BLOCK_SIZE:
1527 *params = mCaps.maxUniformBlockSize;
1528 break;
1529 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
1530 *params = mCaps.maxCombinedVertexUniformComponents;
1531 break;
1532 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
1533 *params = mCaps.maxCombinedFragmentUniformComponents;
1534 break;
1535 case GL_MAX_SERVER_WAIT_TIMEOUT:
1536 *params = mCaps.maxServerWaitTimeout;
1537 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001538
Jamie Madill231c7f52017-04-26 13:45:37 -04001539 // GL_EXT_disjoint_timer_query
1540 case GL_TIMESTAMP_EXT:
1541 *params = mImplementation->getTimestamp();
1542 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001543
Jamie Madill231c7f52017-04-26 13:45:37 -04001544 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1545 *params = mCaps.maxShaderStorageBlockSize;
1546 break;
1547 default:
1548 UNREACHABLE();
1549 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001550 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001551}
1552
Geoff Lang70d0f492015-12-10 17:45:46 -05001553void Context::getPointerv(GLenum pname, void **params) const
1554{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001555 mGLState.getPointerv(pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001556}
1557
Martin Radev66fb8202016-07-28 11:45:20 +03001558void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001559{
Shannon Woods53a94a82014-06-24 15:20:36 -04001560 // Queries about context capabilities and maximums are answered by Context.
1561 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001562
1563 GLenum nativeType;
1564 unsigned int numParams;
1565 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1566 ASSERT(queryStatus);
1567
1568 if (nativeType == GL_INT)
1569 {
1570 switch (target)
1571 {
1572 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1573 ASSERT(index < 3u);
1574 *data = mCaps.maxComputeWorkGroupCount[index];
1575 break;
1576 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1577 ASSERT(index < 3u);
1578 *data = mCaps.maxComputeWorkGroupSize[index];
1579 break;
1580 default:
1581 mGLState.getIntegeri_v(target, index, data);
1582 }
1583 }
1584 else
1585 {
1586 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1587 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001588}
1589
Martin Radev66fb8202016-07-28 11:45:20 +03001590void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001591{
Shannon Woods53a94a82014-06-24 15:20:36 -04001592 // Queries about context capabilities and maximums are answered by Context.
1593 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001594
1595 GLenum nativeType;
1596 unsigned int numParams;
1597 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1598 ASSERT(queryStatus);
1599
1600 if (nativeType == GL_INT_64_ANGLEX)
1601 {
1602 mGLState.getInteger64i_v(target, index, data);
1603 }
1604 else
1605 {
1606 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1607 }
1608}
1609
1610void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1611{
1612 // Queries about context capabilities and maximums are answered by Context.
1613 // Queries about current GL state values are answered by State.
1614
1615 GLenum nativeType;
1616 unsigned int numParams;
1617 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1618 ASSERT(queryStatus);
1619
1620 if (nativeType == GL_BOOL)
1621 {
1622 mGLState.getBooleani_v(target, index, data);
1623 }
1624 else
1625 {
1626 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1627 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001628}
1629
Corentin Wallez336129f2017-10-17 15:55:40 -04001630void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001631{
1632 Buffer *buffer = mGLState.getTargetBuffer(target);
1633 QueryBufferParameteriv(buffer, pname, params);
1634}
1635
1636void Context::getFramebufferAttachmentParameteriv(GLenum target,
1637 GLenum attachment,
1638 GLenum pname,
1639 GLint *params)
1640{
1641 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
1642 QueryFramebufferAttachmentParameteriv(framebuffer, attachment, pname, params);
1643}
1644
1645void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
1646{
1647 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
1648 QueryRenderbufferiv(this, renderbuffer, pname, params);
1649}
1650
1651void Context::getTexParameterfv(GLenum target, GLenum pname, GLfloat *params)
1652{
1653 Texture *texture = getTargetTexture(target);
1654 QueryTexParameterfv(texture, pname, params);
1655}
1656
1657void Context::getTexParameteriv(GLenum target, GLenum pname, GLint *params)
1658{
1659 Texture *texture = getTargetTexture(target);
1660 QueryTexParameteriv(texture, pname, params);
1661}
Jiajia Qin5451d532017-11-16 17:16:34 +08001662
1663void Context::getTexLevelParameteriv(GLenum target, GLint level, GLenum pname, GLint *params)
1664{
1665 Texture *texture =
1666 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
1667 QueryTexLevelParameteriv(texture, target, level, pname, params);
1668}
1669
1670void Context::getTexLevelParameterfv(GLenum target, GLint level, GLenum pname, GLfloat *params)
1671{
1672 Texture *texture =
1673 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
1674 QueryTexLevelParameterfv(texture, target, level, pname, params);
1675}
1676
He Yunchao010e4db2017-03-03 14:22:06 +08001677void Context::texParameterf(GLenum target, GLenum pname, GLfloat param)
1678{
1679 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001680 SetTexParameterf(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04001681 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001682}
1683
1684void Context::texParameterfv(GLenum target, GLenum pname, const GLfloat *params)
1685{
1686 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001687 SetTexParameterfv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04001688 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001689}
1690
1691void Context::texParameteri(GLenum target, GLenum pname, GLint param)
1692{
1693 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001694 SetTexParameteri(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04001695 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001696}
1697
1698void Context::texParameteriv(GLenum target, GLenum pname, const GLint *params)
1699{
1700 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001701 SetTexParameteriv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04001702 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001703}
1704
Jamie Madill675fe712016-12-19 13:07:54 -05001705void Context::drawArrays(GLenum mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001706{
Jamie Madill05b35b22017-10-03 09:01:44 -04001707 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001708 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
1709 MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001710}
1711
Jamie Madill675fe712016-12-19 13:07:54 -05001712void Context::drawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04001713{
Jamie Madill05b35b22017-10-03 09:01:44 -04001714 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001715 ANGLE_CONTEXT_TRY(
1716 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
1717 MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback());
Geoff Langf6db0982015-08-25 13:04:00 -04001718}
1719
Jamie Madill876429b2017-04-20 15:46:24 -04001720void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001721{
Jamie Madill05b35b22017-10-03 09:01:44 -04001722 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001723 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04001724}
1725
Jamie Madill675fe712016-12-19 13:07:54 -05001726void Context::drawElementsInstanced(GLenum mode,
1727 GLsizei count,
1728 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04001729 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04001730 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04001731{
Jamie Madill05b35b22017-10-03 09:01:44 -04001732 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001733 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08001734 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04001735}
1736
Jamie Madill675fe712016-12-19 13:07:54 -05001737void Context::drawRangeElements(GLenum mode,
1738 GLuint start,
1739 GLuint end,
1740 GLsizei count,
1741 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04001742 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04001743{
Jamie Madill05b35b22017-10-03 09:01:44 -04001744 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001745 ANGLE_CONTEXT_TRY(
1746 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001747}
1748
Jamie Madill876429b2017-04-20 15:46:24 -04001749void Context::drawArraysIndirect(GLenum mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08001750{
Jamie Madill05b35b22017-10-03 09:01:44 -04001751 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001752 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08001753}
1754
Jamie Madill876429b2017-04-20 15:46:24 -04001755void Context::drawElementsIndirect(GLenum mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08001756{
Jamie Madill05b35b22017-10-03 09:01:44 -04001757 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001758 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08001759}
1760
Jamie Madill675fe712016-12-19 13:07:54 -05001761void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001762{
Jamie Madill675fe712016-12-19 13:07:54 -05001763 handleError(mImplementation->flush());
Geoff Lang129753a2015-01-09 16:52:09 -05001764}
1765
Jamie Madill675fe712016-12-19 13:07:54 -05001766void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05001767{
Jamie Madill675fe712016-12-19 13:07:54 -05001768 handleError(mImplementation->finish());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001769}
1770
Austin Kinross6ee1e782015-05-29 17:05:37 -07001771void Context::insertEventMarker(GLsizei length, const char *marker)
1772{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001773 ASSERT(mImplementation);
1774 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07001775}
1776
1777void Context::pushGroupMarker(GLsizei length, const char *marker)
1778{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001779 ASSERT(mImplementation);
1780 mImplementation->pushGroupMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07001781}
1782
1783void Context::popGroupMarker()
1784{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001785 ASSERT(mImplementation);
1786 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07001787}
1788
Geoff Langd8605522016-04-13 10:19:12 -04001789void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
1790{
1791 Program *programObject = getProgram(program);
1792 ASSERT(programObject);
1793
1794 programObject->bindUniformLocation(location, name);
1795}
1796
Sami Väisänena797e062016-05-12 15:23:40 +03001797void Context::setCoverageModulation(GLenum components)
1798{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001799 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03001800}
1801
Sami Väisänene45e53b2016-05-25 10:36:04 +03001802void Context::loadPathRenderingMatrix(GLenum matrixMode, const GLfloat *matrix)
1803{
1804 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
1805}
1806
1807void Context::loadPathRenderingIdentityMatrix(GLenum matrixMode)
1808{
1809 GLfloat I[16];
1810 angle::Matrix<GLfloat>::setToIdentity(I);
1811
1812 mGLState.loadPathRenderingMatrix(matrixMode, I);
1813}
1814
1815void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
1816{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001817 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001818 if (!pathObj)
1819 return;
1820
1821 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1822 syncRendererState();
1823
1824 mImplementation->stencilFillPath(pathObj, fillMode, mask);
1825}
1826
1827void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
1828{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001829 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001830 if (!pathObj)
1831 return;
1832
1833 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1834 syncRendererState();
1835
1836 mImplementation->stencilStrokePath(pathObj, reference, mask);
1837}
1838
1839void Context::coverFillPath(GLuint path, GLenum coverMode)
1840{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001841 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001842 if (!pathObj)
1843 return;
1844
1845 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1846 syncRendererState();
1847
1848 mImplementation->coverFillPath(pathObj, coverMode);
1849}
1850
1851void Context::coverStrokePath(GLuint path, GLenum coverMode)
1852{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001853 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001854 if (!pathObj)
1855 return;
1856
1857 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1858 syncRendererState();
1859
1860 mImplementation->coverStrokePath(pathObj, coverMode);
1861}
1862
1863void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
1864{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001865 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001866 if (!pathObj)
1867 return;
1868
1869 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1870 syncRendererState();
1871
1872 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
1873}
1874
1875void Context::stencilThenCoverStrokePath(GLuint path,
1876 GLint reference,
1877 GLuint mask,
1878 GLenum coverMode)
1879{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001880 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001881 if (!pathObj)
1882 return;
1883
1884 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1885 syncRendererState();
1886
1887 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
1888}
1889
Sami Väisänend59ca052016-06-21 16:10:00 +03001890void Context::coverFillPathInstanced(GLsizei numPaths,
1891 GLenum pathNameType,
1892 const void *paths,
1893 GLuint pathBase,
1894 GLenum coverMode,
1895 GLenum transformType,
1896 const GLfloat *transformValues)
1897{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001898 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03001899
1900 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1901 syncRendererState();
1902
1903 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
1904}
Sami Väisänen46eaa942016-06-29 10:26:37 +03001905
Sami Väisänend59ca052016-06-21 16:10:00 +03001906void Context::coverStrokePathInstanced(GLsizei numPaths,
1907 GLenum pathNameType,
1908 const void *paths,
1909 GLuint pathBase,
1910 GLenum coverMode,
1911 GLenum transformType,
1912 const GLfloat *transformValues)
1913{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001914 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03001915
1916 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1917 syncRendererState();
1918
1919 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
1920 transformValues);
1921}
Sami Väisänen46eaa942016-06-29 10:26:37 +03001922
Sami Väisänend59ca052016-06-21 16:10:00 +03001923void Context::stencilFillPathInstanced(GLsizei numPaths,
1924 GLenum pathNameType,
1925 const void *paths,
1926 GLuint pathBase,
1927 GLenum fillMode,
1928 GLuint mask,
1929 GLenum transformType,
1930 const GLfloat *transformValues)
1931{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001932 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03001933
1934 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1935 syncRendererState();
1936
1937 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
1938 transformValues);
1939}
Sami Väisänen46eaa942016-06-29 10:26:37 +03001940
Sami Väisänend59ca052016-06-21 16:10:00 +03001941void Context::stencilStrokePathInstanced(GLsizei numPaths,
1942 GLenum pathNameType,
1943 const void *paths,
1944 GLuint pathBase,
1945 GLint reference,
1946 GLuint mask,
1947 GLenum transformType,
1948 const GLfloat *transformValues)
1949{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001950 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03001951
1952 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1953 syncRendererState();
1954
1955 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
1956 transformValues);
1957}
Sami Väisänen46eaa942016-06-29 10:26:37 +03001958
Sami Väisänend59ca052016-06-21 16:10:00 +03001959void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
1960 GLenum pathNameType,
1961 const void *paths,
1962 GLuint pathBase,
1963 GLenum fillMode,
1964 GLuint mask,
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->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
1975 transformType, transformValues);
1976}
Sami Väisänen46eaa942016-06-29 10:26:37 +03001977
Sami Väisänend59ca052016-06-21 16:10:00 +03001978void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
1979 GLenum pathNameType,
1980 const void *paths,
1981 GLuint pathBase,
1982 GLint reference,
1983 GLuint mask,
1984 GLenum coverMode,
1985 GLenum transformType,
1986 const GLfloat *transformValues)
1987{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001988 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03001989
1990 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1991 syncRendererState();
1992
1993 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
1994 transformType, transformValues);
1995}
1996
Sami Väisänen46eaa942016-06-29 10:26:37 +03001997void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
1998{
1999 auto *programObject = getProgram(program);
2000
2001 programObject->bindFragmentInputLocation(location, name);
2002}
2003
2004void Context::programPathFragmentInputGen(GLuint program,
2005 GLint location,
2006 GLenum genMode,
2007 GLint components,
2008 const GLfloat *coeffs)
2009{
2010 auto *programObject = getProgram(program);
2011
Jamie Madillbd044ed2017-06-05 12:59:21 -04002012 programObject->pathFragmentInputGen(this, location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002013}
2014
jchen1015015f72017-03-16 13:54:21 +08002015GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2016{
jchen10fd7c3b52017-03-21 15:36:03 +08002017 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002018 return QueryProgramResourceIndex(programObject, programInterface, name);
2019}
2020
jchen10fd7c3b52017-03-21 15:36:03 +08002021void Context::getProgramResourceName(GLuint program,
2022 GLenum programInterface,
2023 GLuint index,
2024 GLsizei bufSize,
2025 GLsizei *length,
2026 GLchar *name)
2027{
2028 const auto *programObject = getProgram(program);
2029 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2030}
2031
jchen10191381f2017-04-11 13:59:04 +08002032GLint Context::getProgramResourceLocation(GLuint program,
2033 GLenum programInterface,
2034 const GLchar *name)
2035{
2036 const auto *programObject = getProgram(program);
2037 return QueryProgramResourceLocation(programObject, programInterface, name);
2038}
2039
jchen10880683b2017-04-12 16:21:55 +08002040void Context::getProgramResourceiv(GLuint program,
2041 GLenum programInterface,
2042 GLuint index,
2043 GLsizei propCount,
2044 const GLenum *props,
2045 GLsizei bufSize,
2046 GLsizei *length,
2047 GLint *params)
2048{
2049 const auto *programObject = getProgram(program);
2050 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2051 length, params);
2052}
2053
jchen10d9cd7b72017-08-30 15:04:25 +08002054void Context::getProgramInterfaceiv(GLuint program,
2055 GLenum programInterface,
2056 GLenum pname,
2057 GLint *params)
2058{
2059 const auto *programObject = getProgram(program);
2060 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2061}
2062
Jamie Madill71c88b32017-09-14 22:20:29 -04002063void Context::handleError(const Error &error)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002064{
Geoff Langda5777c2014-07-11 09:52:58 -04002065 if (error.isError())
2066 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002067 GLenum code = error.getCode();
2068 mErrors.insert(code);
2069 if (code == GL_OUT_OF_MEMORY && getWorkarounds().loseContextOnOutOfMemory)
2070 {
2071 markContextLost();
2072 }
Geoff Lang70d0f492015-12-10 17:45:46 -05002073
Geoff Langee6884e2017-11-09 16:51:11 -05002074 ASSERT(!error.getMessage().empty());
2075 mGLState.getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, error.getID(),
2076 GL_DEBUG_SEVERITY_HIGH, error.getMessage());
Geoff Langda5777c2014-07-11 09:52:58 -04002077 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002078}
2079
2080// Get one of the recorded errors and clear its flag, if any.
2081// [OpenGL ES 2.0.24] section 2.5 page 13.
2082GLenum Context::getError()
2083{
Geoff Langda5777c2014-07-11 09:52:58 -04002084 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002085 {
Geoff Langda5777c2014-07-11 09:52:58 -04002086 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002087 }
Geoff Langda5777c2014-07-11 09:52:58 -04002088 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002089 {
Geoff Langda5777c2014-07-11 09:52:58 -04002090 GLenum error = *mErrors.begin();
2091 mErrors.erase(mErrors.begin());
2092 return error;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002093 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002094}
2095
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002096// NOTE: this function should not assume that this context is current!
2097void Context::markContextLost()
2098{
2099 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002100 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002101 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002102 mContextLostForced = true;
2103 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002104 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002105}
2106
2107bool Context::isContextLost()
2108{
2109 return mContextLost;
2110}
2111
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002112GLenum Context::getResetStatus()
2113{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002114 // Even if the application doesn't want to know about resets, we want to know
2115 // as it will allow us to skip all the calls.
2116 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002117 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002118 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002119 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002120 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002121 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002122
2123 // EXT_robustness, section 2.6: If the reset notification behavior is
2124 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2125 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2126 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002127 }
2128
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002129 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2130 // status should be returned at least once, and GL_NO_ERROR should be returned
2131 // once the device has finished resetting.
2132 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002133 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002134 ASSERT(mResetStatus == GL_NO_ERROR);
2135 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002136
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002137 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002138 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002139 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002140 }
2141 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002142 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002143 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002144 // If markContextLost was used to mark the context lost then
2145 // assume that is not recoverable, and continue to report the
2146 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002147 mResetStatus = mImplementation->getResetStatus();
2148 }
Jamie Madill893ab082014-05-16 16:56:10 -04002149
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002150 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002151}
2152
2153bool Context::isResetNotificationEnabled()
2154{
2155 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2156}
2157
Corentin Walleze3b10e82015-05-20 11:06:25 -04002158const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002159{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002160 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002161}
2162
2163EGLenum Context::getClientType() const
2164{
2165 return mClientType;
2166}
2167
2168EGLenum Context::getRenderBuffer() const
2169{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002170 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2171 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002172 {
2173 return EGL_NONE;
2174 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002175
2176 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(GL_BACK);
2177 ASSERT(backAttachment != nullptr);
2178 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002179}
2180
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002181VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002182{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002183 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002184 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2185 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002186 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002187 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2188 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002189
Jamie Madill96a483b2017-06-27 16:49:21 -04002190 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002191 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002192
2193 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002194}
2195
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002196TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002197{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002198 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002199 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2200 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002201 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002202 transformFeedback =
2203 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002204 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002205 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002206 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002207
2208 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002209}
2210
2211bool Context::isVertexArrayGenerated(GLuint vertexArray)
2212{
Jamie Madill96a483b2017-06-27 16:49:21 -04002213 ASSERT(mVertexArrayMap.contains(0));
2214 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002215}
2216
2217bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2218{
Jamie Madill96a483b2017-06-27 16:49:21 -04002219 ASSERT(mTransformFeedbackMap.contains(0));
2220 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002221}
2222
Shannon Woods53a94a82014-06-24 15:20:36 -04002223void Context::detachTexture(GLuint texture)
2224{
2225 // Simple pass-through to State's detachTexture method, as textures do not require
2226 // allocation map management either here or in the resource manager at detach time.
2227 // Zero textures are held by the Context, and we don't attempt to request them from
2228 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002229 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002230}
2231
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002232void Context::detachBuffer(GLuint buffer)
2233{
Yuly Novikov5807a532015-12-03 13:01:22 -05002234 // Simple pass-through to State's detachBuffer method, since
2235 // only buffer attachments to container objects that are bound to the current context
2236 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002237
Yuly Novikov5807a532015-12-03 13:01:22 -05002238 // [OpenGL ES 3.2] section 5.1.2 page 45:
2239 // Attachments to unbound container objects, such as
2240 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2241 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002242 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002243}
2244
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002245void Context::detachFramebuffer(GLuint framebuffer)
2246{
Shannon Woods53a94a82014-06-24 15:20:36 -04002247 // Framebuffer detachment is handled by Context, because 0 is a valid
2248 // Framebuffer object, and a pointer to it must be passed from Context
2249 // to State at binding time.
2250
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002251 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002252 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2253 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2254 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002255
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002256 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002257 {
2258 bindReadFramebuffer(0);
2259 }
2260
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002261 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002262 {
2263 bindDrawFramebuffer(0);
2264 }
2265}
2266
2267void Context::detachRenderbuffer(GLuint renderbuffer)
2268{
Jamie Madilla02315b2017-02-23 14:14:47 -05002269 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002270}
2271
Jamie Madill57a89722013-07-02 11:57:03 -04002272void Context::detachVertexArray(GLuint vertexArray)
2273{
Jamie Madill77a72f62015-04-14 11:18:32 -04002274 // Vertex array detachment is handled by Context, because 0 is a valid
2275 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002276 // binding time.
2277
Jamie Madill57a89722013-07-02 11:57:03 -04002278 // [OpenGL ES 3.0.2] section 2.10 page 43:
2279 // If a vertex array object that is currently bound is deleted, the binding
2280 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002281 if (mGLState.removeVertexArrayBinding(vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002282 {
2283 bindVertexArray(0);
2284 }
2285}
2286
Geoff Langc8058452014-02-03 12:04:11 -05002287void Context::detachTransformFeedback(GLuint transformFeedback)
2288{
Corentin Walleza2257da2016-04-19 16:43:12 -04002289 // Transform feedback detachment is handled by Context, because 0 is a valid
2290 // transform feedback, and a pointer to it must be passed from Context to State at
2291 // binding time.
2292
2293 // The OpenGL specification doesn't mention what should happen when the currently bound
2294 // transform feedback object is deleted. Since it is a container object, we treat it like
2295 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002296 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002297 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002298 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002299 }
Geoff Langc8058452014-02-03 12:04:11 -05002300}
2301
Jamie Madilldc356042013-07-19 16:36:57 -04002302void Context::detachSampler(GLuint sampler)
2303{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002304 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002305}
2306
Yunchao Hea336b902017-08-02 16:05:21 +08002307void Context::detachProgramPipeline(GLuint pipeline)
2308{
2309 mGLState.detachProgramPipeline(this, pipeline);
2310}
2311
Jamie Madill3ef140a2017-08-26 23:11:21 -04002312void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002313{
Shaodde78e82017-05-22 14:13:27 +08002314 mGLState.setVertexAttribDivisor(this, index, divisor);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002315}
2316
Jamie Madille29d1672013-07-19 16:36:57 -04002317void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2318{
Geoff Langc1984ed2016-10-07 12:41:00 -04002319 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002320 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002321 SetSamplerParameteri(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002322 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002323}
Jamie Madille29d1672013-07-19 16:36:57 -04002324
Geoff Langc1984ed2016-10-07 12:41:00 -04002325void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2326{
2327 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002328 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002329 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002330 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002331}
2332
2333void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2334{
Geoff Langc1984ed2016-10-07 12:41:00 -04002335 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002336 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002337 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002338 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002339}
2340
Geoff Langc1984ed2016-10-07 12:41:00 -04002341void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002342{
Geoff Langc1984ed2016-10-07 12:41:00 -04002343 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002344 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002345 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002346 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002347}
2348
Geoff Langc1984ed2016-10-07 12:41:00 -04002349void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002350{
Geoff Langc1984ed2016-10-07 12:41:00 -04002351 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002352 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002353 QuerySamplerParameteriv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002354 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002355}
Jamie Madill9675b802013-07-19 16:36:59 -04002356
Geoff Langc1984ed2016-10-07 12:41:00 -04002357void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2358{
2359 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002360 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002361 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002362 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002363}
2364
Olli Etuahof0fee072016-03-30 15:11:58 +03002365void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2366{
2367 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002368 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002369}
2370
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002371void Context::initRendererString()
2372{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002373 std::ostringstream rendererString;
2374 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002375 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002376 rendererString << ")";
2377
Geoff Langcec35902014-04-16 10:52:36 -04002378 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002379}
2380
Geoff Langc339c4e2016-11-29 10:37:36 -05002381void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002382{
Geoff Langc339c4e2016-11-29 10:37:36 -05002383 const Version &clientVersion = getClientVersion();
2384
2385 std::ostringstream versionString;
2386 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2387 << ANGLE_VERSION_STRING << ")";
2388 mVersionString = MakeStaticString(versionString.str());
2389
2390 std::ostringstream shadingLanguageVersionString;
2391 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2392 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2393 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2394 << ")";
2395 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002396}
2397
Geoff Langcec35902014-04-16 10:52:36 -04002398void Context::initExtensionStrings()
2399{
Geoff Langc339c4e2016-11-29 10:37:36 -05002400 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2401 std::ostringstream combinedStringStream;
2402 std::copy(strings.begin(), strings.end(),
2403 std::ostream_iterator<const char *>(combinedStringStream, " "));
2404 return MakeStaticString(combinedStringStream.str());
2405 };
2406
2407 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002408 for (const auto &extensionString : mExtensions.getStrings())
2409 {
2410 mExtensionStrings.push_back(MakeStaticString(extensionString));
2411 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002412 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002413
Bryan Bernhart58806562017-01-05 13:09:31 -08002414 const gl::Extensions &nativeExtensions = mImplementation->getNativeExtensions();
2415
Geoff Langc339c4e2016-11-29 10:37:36 -05002416 mRequestableExtensionStrings.clear();
2417 for (const auto &extensionInfo : GetExtensionInfoMap())
2418 {
2419 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08002420 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
2421 nativeExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002422 {
2423 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
2424 }
2425 }
2426 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002427}
2428
Geoff Langc339c4e2016-11-29 10:37:36 -05002429const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04002430{
Geoff Langc339c4e2016-11-29 10:37:36 -05002431 switch (name)
2432 {
2433 case GL_VENDOR:
2434 return reinterpret_cast<const GLubyte *>("Google Inc.");
2435
2436 case GL_RENDERER:
2437 return reinterpret_cast<const GLubyte *>(mRendererString);
2438
2439 case GL_VERSION:
2440 return reinterpret_cast<const GLubyte *>(mVersionString);
2441
2442 case GL_SHADING_LANGUAGE_VERSION:
2443 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
2444
2445 case GL_EXTENSIONS:
2446 return reinterpret_cast<const GLubyte *>(mExtensionString);
2447
2448 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2449 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
2450
2451 default:
2452 UNREACHABLE();
2453 return nullptr;
2454 }
Geoff Langcec35902014-04-16 10:52:36 -04002455}
2456
Geoff Langc339c4e2016-11-29 10:37:36 -05002457const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04002458{
Geoff Langc339c4e2016-11-29 10:37:36 -05002459 switch (name)
2460 {
2461 case GL_EXTENSIONS:
2462 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
2463
2464 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2465 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
2466
2467 default:
2468 UNREACHABLE();
2469 return nullptr;
2470 }
Geoff Langcec35902014-04-16 10:52:36 -04002471}
2472
2473size_t Context::getExtensionStringCount() const
2474{
2475 return mExtensionStrings.size();
2476}
2477
Geoff Lang111a99e2017-10-17 10:58:41 -04002478bool Context::isExtensionRequestable(const char *name)
2479{
2480 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2481 auto extension = extensionInfos.find(name);
2482
2483 const Extensions &nativeExtensions = mImplementation->getNativeExtensions();
2484 return extension != extensionInfos.end() && extension->second.Requestable &&
2485 nativeExtensions.*(extension->second.ExtensionsMember);
2486}
2487
Geoff Langc339c4e2016-11-29 10:37:36 -05002488void Context::requestExtension(const char *name)
2489{
2490 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2491 ASSERT(extensionInfos.find(name) != extensionInfos.end());
2492 const auto &extension = extensionInfos.at(name);
2493 ASSERT(extension.Requestable);
Geoff Lang111a99e2017-10-17 10:58:41 -04002494 ASSERT(mImplementation->getNativeExtensions().*(extension.ExtensionsMember));
Geoff Langc339c4e2016-11-29 10:37:36 -05002495
2496 if (mExtensions.*(extension.ExtensionsMember))
2497 {
2498 // Extension already enabled
2499 return;
2500 }
2501
2502 mExtensions.*(extension.ExtensionsMember) = true;
2503 updateCaps();
2504 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08002505
Jamie Madill2f348d22017-06-05 10:50:59 -04002506 // Release the shader compiler so it will be re-created with the requested extensions enabled.
2507 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04002508
Jamie Madill81c2e252017-09-09 23:32:46 -04002509 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
2510 // sampleable.
2511 mState.mTextures->signalAllTexturesDirty();
Geoff Lang9aded172017-04-05 11:07:56 -04002512 for (auto &zeroTexture : mZeroTextures)
2513 {
Jamie Madill05b35b22017-10-03 09:01:44 -04002514 zeroTexture.second->signalDirty(InitState::Initialized);
Geoff Lang9aded172017-04-05 11:07:56 -04002515 }
2516
2517 mState.mFramebuffers->invalidateFramebufferComplenessCache();
Geoff Langc339c4e2016-11-29 10:37:36 -05002518}
2519
2520size_t Context::getRequestableExtensionStringCount() const
2521{
2522 return mRequestableExtensionStrings.size();
2523}
2524
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002525void Context::beginTransformFeedback(GLenum primitiveMode)
2526{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002527 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002528 ASSERT(transformFeedback != nullptr);
2529 ASSERT(!transformFeedback->isPaused());
2530
Jamie Madill6c1f6712017-02-14 19:08:04 -05002531 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002532}
2533
2534bool Context::hasActiveTransformFeedback(GLuint program) const
2535{
2536 for (auto pair : mTransformFeedbackMap)
2537 {
2538 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
2539 {
2540 return true;
2541 }
2542 }
2543 return false;
2544}
2545
Geoff Langb433e872017-10-05 14:01:47 -04002546void Context::initCaps(const egl::DisplayExtensions &displayExtensions, bool robustResourceInit)
Geoff Lang493daf52014-07-03 13:38:44 -04002547{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002548 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04002549
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002550 mExtensions = mImplementation->getNativeExtensions();
Geoff Lang493daf52014-07-03 13:38:44 -04002551
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002552 mLimitations = mImplementation->getNativeLimitations();
Austin Kinross02df7962015-07-01 10:03:42 -07002553
Geoff Langeb66a6e2016-10-31 13:06:12 -04002554 if (getClientVersion() < Version(3, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002555 {
2556 // Disable ES3+ extensions
Jamie Madill231c7f52017-04-26 13:45:37 -04002557 mExtensions.colorBufferFloat = false;
Geoff Langb66a9092016-05-16 15:59:14 -04002558 mExtensions.eglImageExternalEssl3 = false;
Vincent Lang25ab4512016-05-13 18:13:59 +02002559 mExtensions.textureNorm16 = false;
Martin Radev137032d2017-07-13 10:11:12 +03002560 mExtensions.multiview = false;
2561 mExtensions.maxViews = 1u;
Geoff Lang493daf52014-07-03 13:38:44 -04002562 }
2563
Jiawei Shao89be29a2017-11-06 14:36:45 +08002564 if (getClientVersion() < ES_3_1)
2565 {
2566 // Disable ES3.1+ extensions
2567 mExtensions.geometryShader = false;
2568 }
2569
Geoff Langeb66a6e2016-10-31 13:06:12 -04002570 if (getClientVersion() > Version(2, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002571 {
2572 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
Jamie Madill231c7f52017-04-26 13:45:37 -04002573 // mExtensions.sRGB = false;
Geoff Lang493daf52014-07-03 13:38:44 -04002574 }
2575
Jamie Madill00ed7a12016-05-19 13:13:38 -04002576 // Some extensions are always available because they are implemented in the GL layer.
Jamie Madill231c7f52017-04-26 13:45:37 -04002577 mExtensions.bindUniformLocation = true;
2578 mExtensions.vertexArrayObject = true;
Geoff Langf41a7152016-09-19 15:11:17 -04002579 mExtensions.bindGeneratesResource = true;
Geoff Langfeb8c682017-02-13 16:07:35 -05002580 mExtensions.clientArrays = true;
Geoff Langc339c4e2016-11-29 10:37:36 -05002581 mExtensions.requestExtension = true;
Jamie Madill00ed7a12016-05-19 13:13:38 -04002582
2583 // Enable the no error extension if the context was created with the flag.
2584 mExtensions.noError = mSkipValidation;
2585
Corentin Wallezccab69d2017-01-27 16:57:15 -05002586 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Corentin Wallezc295e512017-01-27 17:47:50 -05002587 mExtensions.surfacelessContext = displayExtensions.surfacelessContext;
Corentin Wallezccab69d2017-01-27 16:57:15 -05002588
Geoff Lang70d0f492015-12-10 17:45:46 -05002589 // Explicitly enable GL_KHR_debug
2590 mExtensions.debug = true;
2591 mExtensions.maxDebugMessageLength = 1024;
2592 mExtensions.maxDebugLoggedMessages = 1024;
2593 mExtensions.maxDebugGroupStackDepth = 1024;
2594 mExtensions.maxLabelLength = 1024;
2595
Geoff Langff5b2d52016-09-07 11:32:23 -04002596 // Explicitly enable GL_ANGLE_robust_client_memory
2597 mExtensions.robustClientMemory = true;
2598
Jamie Madille08a1d32017-03-07 17:24:06 -05002599 // Determine robust resource init availability from EGL.
Geoff Langb433e872017-10-05 14:01:47 -04002600 mExtensions.robustResourceInitialization = robustResourceInit;
Jamie Madille08a1d32017-03-07 17:24:06 -05002601
Jiajia Qin8a7b3a02017-08-25 16:05:48 +08002602 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
2603 // supports it.
2604 mExtensions.robustBufferAccessBehavior =
2605 mRobustAccess && mExtensions.robustBufferAccessBehavior;
2606
Jamie Madillc43be722017-07-13 16:22:14 -04002607 // Enable the cache control query unconditionally.
2608 mExtensions.programCacheControl = true;
2609
Geoff Lang301d1612014-07-09 10:34:37 -04002610 // Apply implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04002611 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002612
Jamie Madill0f80ed82017-09-19 00:24:56 -04002613 if (getClientVersion() < ES_3_1)
2614 {
2615 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
2616 }
2617 else
2618 {
2619 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
2620 }
Geoff Lang301d1612014-07-09 10:34:37 -04002621
Jamie Madill0f80ed82017-09-19 00:24:56 -04002622 LimitCap(&mCaps.maxVertexUniformBlocks, IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
2623 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
2624 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
2625
2626 // Limit textures as well, so we can use fast bitsets with texture bindings.
2627 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
2628 LimitCap(&mCaps.maxVertexTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
2629 LimitCap(&mCaps.maxTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04002630
Jiawei Shaodb342272017-09-27 10:21:45 +08002631 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
2632
Geoff Langc287ea62016-09-16 14:46:51 -04002633 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002634 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04002635 for (const auto &extensionInfo : GetExtensionInfoMap())
2636 {
2637 // If this context is for WebGL, disable all enableable extensions
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002638 if (mWebGLContext && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04002639 {
2640 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
2641 }
2642 }
2643
2644 // Generate texture caps
2645 updateCaps();
2646}
2647
2648void Context::updateCaps()
2649{
Geoff Lang900013c2014-07-07 11:32:19 -04002650 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002651 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04002652
Jamie Madill7b62cf92017-11-02 15:20:49 -04002653 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04002654 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04002655 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04002656 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04002657
Geoff Lang0d8b7242015-09-09 14:56:53 -04002658 // Update the format caps based on the client version and extensions.
2659 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
2660 // ES3.
2661 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002662 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002663 formatCaps.renderable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002664 formatCaps.renderable && formatInfo.renderSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002665 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002666 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04002667
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002668 // OpenGL ES does not support multisampling with non-rendererable formats
2669 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Olli Etuaho50c562d2017-06-06 14:43:30 +03002670 if (!formatCaps.renderable ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002671 (getClientVersion() < ES_3_1 &&
2672 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04002673 {
Geoff Langd87878e2014-09-19 15:42:59 -04002674 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04002675 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03002676 else
2677 {
2678 // We may have limited the max samples for some required renderbuffer formats due to
2679 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
2680 GLuint formatMaxSamples = formatCaps.getMaxSamples();
2681
2682 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
2683 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
2684 // exception of signed and unsigned integer formats."
2685 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
2686 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
2687 {
2688 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
2689 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
2690 }
2691
2692 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
2693 if (getClientVersion() >= ES_3_1)
2694 {
2695 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
2696 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
2697 // the exception that the signed and unsigned integer formats are required only to
2698 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
2699 // multisamples, which must be at least one."
2700 if (formatInfo.componentType == GL_INT ||
2701 formatInfo.componentType == GL_UNSIGNED_INT)
2702 {
2703 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
2704 }
2705
2706 // GLES 3.1 section 19.3.1.
2707 if (formatCaps.texturable)
2708 {
2709 if (formatInfo.depthBits > 0)
2710 {
2711 mCaps.maxDepthTextureSamples =
2712 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
2713 }
2714 else if (formatInfo.redBits > 0)
2715 {
2716 mCaps.maxColorTextureSamples =
2717 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
2718 }
2719 }
2720 }
2721 }
Geoff Langd87878e2014-09-19 15:42:59 -04002722
2723 if (formatCaps.texturable && formatInfo.compressed)
2724 {
Geoff Langca271392017-04-05 12:30:00 -04002725 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04002726 }
2727
Geoff Langca271392017-04-05 12:30:00 -04002728 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04002729 }
Jamie Madill32447362017-06-28 14:53:52 -04002730
2731 // If program binary is disabled, blank out the memory cache pointer.
2732 if (!mImplementation->getNativeExtensions().getProgramBinary)
2733 {
2734 mMemoryProgramCache = nullptr;
2735 }
Geoff Lang493daf52014-07-03 13:38:44 -04002736}
2737
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002738void Context::initWorkarounds()
2739{
Jamie Madill761b02c2017-06-23 16:27:06 -04002740 // Apply back-end workarounds.
2741 mImplementation->applyNativeWorkarounds(&mWorkarounds);
2742
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002743 // Lose the context upon out of memory error if the application is
2744 // expecting to watch for those events.
2745 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2746}
2747
Jamie Madill05b35b22017-10-03 09:01:44 -04002748Error Context::prepareForDraw()
2749{
2750 syncRendererState();
Jamie Madilla59fc192017-11-02 12:57:58 -04002751
2752 if (isRobustResourceInitEnabled())
2753 {
2754 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
2755 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
2756 }
2757
Jamie Madill05b35b22017-10-03 09:01:44 -04002758 return NoError();
2759}
2760
Jamie Madill1b94d432015-08-07 13:23:23 -04002761void Context::syncRendererState()
2762{
Jamie Madill7d1f5c62017-09-02 15:32:15 -04002763 mGLState.syncDirtyObjects(this);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002764 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
Jamie Madillfe548342017-06-19 11:13:24 -04002765 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002766 mGLState.clearDirtyBits();
Jamie Madill1b94d432015-08-07 13:23:23 -04002767}
2768
Jamie Madillad9f24e2016-02-12 09:27:24 -05002769void Context::syncRendererState(const State::DirtyBits &bitMask,
2770 const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04002771{
Jamie Madill7d1f5c62017-09-02 15:32:15 -04002772 mGLState.syncDirtyObjects(this, objectMask);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002773 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madillfe548342017-06-19 11:13:24 -04002774 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002775 mGLState.clearDirtyBits(dirtyBits);
Jamie Madill1b94d432015-08-07 13:23:23 -04002776}
Jamie Madillc29968b2016-01-20 11:17:23 -05002777
2778void Context::blitFramebuffer(GLint srcX0,
2779 GLint srcY0,
2780 GLint srcX1,
2781 GLint srcY1,
2782 GLint dstX0,
2783 GLint dstY0,
2784 GLint dstX1,
2785 GLint dstY1,
2786 GLbitfield mask,
2787 GLenum filter)
2788{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002789 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002790 ASSERT(drawFramebuffer);
2791
2792 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
2793 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
2794
Jamie Madillad9f24e2016-02-12 09:27:24 -05002795 syncStateForBlit();
Jamie Madillc29968b2016-01-20 11:17:23 -05002796
Jamie Madillc564c072017-06-01 12:45:42 -04002797 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002798}
Jamie Madillc29968b2016-01-20 11:17:23 -05002799
2800void Context::clear(GLbitfield mask)
2801{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002802 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002803 handleError(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05002804}
2805
2806void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
2807{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002808 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002809 handleError(mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002810}
2811
2812void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
2813{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002814 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002815 handleError(mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002816}
2817
2818void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
2819{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002820 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002821 handleError(mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002822}
2823
2824void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
2825{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002826 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002827 ASSERT(framebufferObject);
2828
2829 // If a buffer is not present, the clear has no effect
2830 if (framebufferObject->getDepthbuffer() == nullptr &&
2831 framebufferObject->getStencilbuffer() == nullptr)
2832 {
2833 return;
2834 }
2835
Jamie Madillad9f24e2016-02-12 09:27:24 -05002836 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002837 handleError(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05002838}
2839
2840void Context::readPixels(GLint x,
2841 GLint y,
2842 GLsizei width,
2843 GLsizei height,
2844 GLenum format,
2845 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002846 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05002847{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04002848 if (width == 0 || height == 0)
2849 {
2850 return;
2851 }
2852
Jamie Madillad9f24e2016-02-12 09:27:24 -05002853 syncStateForReadPixels();
Jamie Madillc29968b2016-01-20 11:17:23 -05002854
Jamie Madillb6664922017-07-25 12:55:04 -04002855 Framebuffer *readFBO = mGLState.getReadFramebuffer();
2856 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05002857
2858 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04002859 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05002860}
2861
2862void Context::copyTexImage2D(GLenum target,
2863 GLint level,
2864 GLenum internalformat,
2865 GLint x,
2866 GLint y,
2867 GLsizei width,
2868 GLsizei height,
2869 GLint border)
2870{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002871 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002872 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002873
Jamie Madillc29968b2016-01-20 11:17:23 -05002874 Rectangle sourceArea(x, y, width, height);
2875
Jamie Madill05b35b22017-10-03 09:01:44 -04002876 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002877 Texture *texture =
2878 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05002879 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05002880}
2881
2882void Context::copyTexSubImage2D(GLenum target,
2883 GLint level,
2884 GLint xoffset,
2885 GLint yoffset,
2886 GLint x,
2887 GLint y,
2888 GLsizei width,
2889 GLsizei height)
2890{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04002891 if (width == 0 || height == 0)
2892 {
2893 return;
2894 }
2895
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002896 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002897 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002898
Jamie Madillc29968b2016-01-20 11:17:23 -05002899 Offset destOffset(xoffset, yoffset, 0);
2900 Rectangle sourceArea(x, y, width, height);
2901
Jamie Madill05b35b22017-10-03 09:01:44 -04002902 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002903 Texture *texture =
2904 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05002905 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05002906}
2907
2908void Context::copyTexSubImage3D(GLenum target,
2909 GLint level,
2910 GLint xoffset,
2911 GLint yoffset,
2912 GLint zoffset,
2913 GLint x,
2914 GLint y,
2915 GLsizei width,
2916 GLsizei height)
2917{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04002918 if (width == 0 || height == 0)
2919 {
2920 return;
2921 }
2922
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002923 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002924 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002925
Jamie Madillc29968b2016-01-20 11:17:23 -05002926 Offset destOffset(xoffset, yoffset, zoffset);
2927 Rectangle sourceArea(x, y, width, height);
2928
Jamie Madill05b35b22017-10-03 09:01:44 -04002929 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
2930 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05002931 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05002932}
2933
2934void Context::framebufferTexture2D(GLenum target,
2935 GLenum attachment,
2936 GLenum textarget,
2937 GLuint texture,
2938 GLint level)
2939{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002940 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05002941 ASSERT(framebuffer);
2942
2943 if (texture != 0)
2944 {
2945 Texture *textureObj = getTexture(texture);
2946
2947 ImageIndex index = ImageIndex::MakeInvalid();
2948
2949 if (textarget == GL_TEXTURE_2D)
2950 {
2951 index = ImageIndex::Make2D(level);
2952 }
Corentin Wallez13c0dd42017-07-04 18:27:01 -04002953 else if (textarget == GL_TEXTURE_RECTANGLE_ANGLE)
2954 {
2955 index = ImageIndex::MakeRectangle(level);
2956 }
JiangYizhoubddc46b2016-12-09 09:50:51 +08002957 else if (textarget == GL_TEXTURE_2D_MULTISAMPLE)
2958 {
2959 ASSERT(level == 0);
2960 index = ImageIndex::Make2DMultisample();
2961 }
Jamie Madillc29968b2016-01-20 11:17:23 -05002962 else
2963 {
2964 ASSERT(IsCubeMapTextureTarget(textarget));
2965 index = ImageIndex::MakeCube(textarget, level);
2966 }
2967
Jamie Madilla02315b2017-02-23 14:14:47 -05002968 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05002969 }
2970 else
2971 {
Jamie Madilla02315b2017-02-23 14:14:47 -05002972 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05002973 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002974
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002975 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05002976}
2977
2978void Context::framebufferRenderbuffer(GLenum target,
2979 GLenum attachment,
2980 GLenum renderbuffertarget,
2981 GLuint renderbuffer)
2982{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002983 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05002984 ASSERT(framebuffer);
2985
2986 if (renderbuffer != 0)
2987 {
2988 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05002989
2990 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex::MakeInvalid(),
Jamie Madillc29968b2016-01-20 11:17:23 -05002991 renderbufferObject);
2992 }
2993 else
2994 {
Jamie Madilla02315b2017-02-23 14:14:47 -05002995 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05002996 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002997
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002998 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05002999}
3000
3001void Context::framebufferTextureLayer(GLenum target,
3002 GLenum attachment,
3003 GLuint texture,
3004 GLint level,
3005 GLint layer)
3006{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003007 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003008 ASSERT(framebuffer);
3009
3010 if (texture != 0)
3011 {
3012 Texture *textureObject = getTexture(texture);
3013
3014 ImageIndex index = ImageIndex::MakeInvalid();
3015
3016 if (textureObject->getTarget() == GL_TEXTURE_3D)
3017 {
3018 index = ImageIndex::Make3D(level, layer);
3019 }
3020 else
3021 {
3022 ASSERT(textureObject->getTarget() == GL_TEXTURE_2D_ARRAY);
3023 index = ImageIndex::Make2DArray(level, layer);
3024 }
3025
Jamie Madilla02315b2017-02-23 14:14:47 -05003026 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003027 }
3028 else
3029 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003030 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003031 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003032
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003033 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003034}
3035
Martin Radev137032d2017-07-13 10:11:12 +03003036void Context::framebufferTextureMultiviewLayeredANGLE(GLenum target,
3037 GLenum attachment,
3038 GLuint texture,
3039 GLint level,
3040 GLint baseViewIndex,
3041 GLsizei numViews)
3042{
Martin Radev82ef7742017-08-08 17:44:58 +03003043 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3044 ASSERT(framebuffer);
3045
3046 if (texture != 0)
3047 {
3048 Texture *textureObj = getTexture(texture);
3049
Martin Radev18b75ba2017-08-15 15:50:40 +03003050 ImageIndex index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
Martin Radev82ef7742017-08-08 17:44:58 +03003051 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3052 numViews, baseViewIndex);
3053 }
3054 else
3055 {
3056 framebuffer->resetAttachment(this, attachment);
3057 }
3058
3059 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003060}
3061
3062void Context::framebufferTextureMultiviewSideBySideANGLE(GLenum target,
3063 GLenum attachment,
3064 GLuint texture,
3065 GLint level,
3066 GLsizei numViews,
3067 const GLint *viewportOffsets)
3068{
Martin Radev5dae57b2017-07-14 16:15:55 +03003069 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3070 ASSERT(framebuffer);
3071
3072 if (texture != 0)
3073 {
3074 Texture *textureObj = getTexture(texture);
3075
3076 ImageIndex index = ImageIndex::Make2D(level);
3077 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3078 textureObj, numViews, viewportOffsets);
3079 }
3080 else
3081 {
3082 framebuffer->resetAttachment(this, attachment);
3083 }
3084
3085 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003086}
3087
Jamie Madillc29968b2016-01-20 11:17:23 -05003088void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3089{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003090 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003091 ASSERT(framebuffer);
3092 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003093 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003094}
3095
3096void Context::readBuffer(GLenum mode)
3097{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003098 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003099 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003100 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003101}
3102
3103void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3104{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003105 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003106 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003107
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003108 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003109 ASSERT(framebuffer);
3110
3111 // The specification isn't clear what should be done when the framebuffer isn't complete.
3112 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003113 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003114}
3115
3116void Context::invalidateFramebuffer(GLenum target,
3117 GLsizei numAttachments,
3118 const GLenum *attachments)
3119{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003120 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003121 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003122
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003123 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003124 ASSERT(framebuffer);
3125
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003126 if (framebuffer->checkStatus(this) != GL_FRAMEBUFFER_COMPLETE)
Jamie Madillc29968b2016-01-20 11:17:23 -05003127 {
Jamie Madill437fa652016-05-03 15:13:24 -04003128 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003129 }
Jamie Madill437fa652016-05-03 15:13:24 -04003130
Jamie Madill4928b7c2017-06-20 12:57:39 -04003131 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003132}
3133
3134void Context::invalidateSubFramebuffer(GLenum target,
3135 GLsizei numAttachments,
3136 const GLenum *attachments,
3137 GLint x,
3138 GLint y,
3139 GLsizei width,
3140 GLsizei height)
3141{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003142 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003143 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003144
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003145 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003146 ASSERT(framebuffer);
3147
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003148 if (framebuffer->checkStatus(this) != GL_FRAMEBUFFER_COMPLETE)
Jamie Madillc29968b2016-01-20 11:17:23 -05003149 {
Jamie Madill437fa652016-05-03 15:13:24 -04003150 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003151 }
Jamie Madill437fa652016-05-03 15:13:24 -04003152
3153 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003154 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003155}
3156
Jamie Madill73a84962016-02-12 09:27:23 -05003157void Context::texImage2D(GLenum target,
3158 GLint level,
3159 GLint internalformat,
3160 GLsizei width,
3161 GLsizei height,
3162 GLint border,
3163 GLenum format,
3164 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003165 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003166{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003167 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003168
3169 Extents size(width, height, 1);
3170 Texture *texture =
3171 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003172 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3173 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003174}
3175
3176void Context::texImage3D(GLenum target,
3177 GLint level,
3178 GLint internalformat,
3179 GLsizei width,
3180 GLsizei height,
3181 GLsizei depth,
3182 GLint border,
3183 GLenum format,
3184 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003185 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003186{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003187 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003188
3189 Extents size(width, height, depth);
3190 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003191 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3192 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003193}
3194
3195void Context::texSubImage2D(GLenum target,
3196 GLint level,
3197 GLint xoffset,
3198 GLint yoffset,
3199 GLsizei width,
3200 GLsizei height,
3201 GLenum format,
3202 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003203 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003204{
3205 // Zero sized uploads are valid but no-ops
3206 if (width == 0 || height == 0)
3207 {
3208 return;
3209 }
3210
Jamie Madillad9f24e2016-02-12 09:27:24 -05003211 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003212
3213 Box area(xoffset, yoffset, 0, width, height, 1);
3214 Texture *texture =
3215 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003216 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3217 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003218}
3219
3220void Context::texSubImage3D(GLenum target,
3221 GLint level,
3222 GLint xoffset,
3223 GLint yoffset,
3224 GLint zoffset,
3225 GLsizei width,
3226 GLsizei height,
3227 GLsizei depth,
3228 GLenum format,
3229 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003230 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003231{
3232 // Zero sized uploads are valid but no-ops
3233 if (width == 0 || height == 0 || depth == 0)
3234 {
3235 return;
3236 }
3237
Jamie Madillad9f24e2016-02-12 09:27:24 -05003238 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003239
3240 Box area(xoffset, yoffset, zoffset, width, height, depth);
3241 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003242 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3243 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003244}
3245
3246void Context::compressedTexImage2D(GLenum target,
3247 GLint level,
3248 GLenum internalformat,
3249 GLsizei width,
3250 GLsizei height,
3251 GLint border,
3252 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003253 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003254{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003255 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003256
3257 Extents size(width, height, 1);
3258 Texture *texture =
3259 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003260 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003261 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003262 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003263}
3264
3265void Context::compressedTexImage3D(GLenum target,
3266 GLint level,
3267 GLenum internalformat,
3268 GLsizei width,
3269 GLsizei height,
3270 GLsizei depth,
3271 GLint border,
3272 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003273 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003274{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003275 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003276
3277 Extents size(width, height, depth);
3278 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003279 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003280 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003281 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003282}
3283
3284void Context::compressedTexSubImage2D(GLenum target,
3285 GLint level,
3286 GLint xoffset,
3287 GLint yoffset,
3288 GLsizei width,
3289 GLsizei height,
3290 GLenum format,
3291 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003292 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003293{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003294 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003295
3296 Box area(xoffset, yoffset, 0, width, height, 1);
3297 Texture *texture =
3298 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003299 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003300 format, imageSize,
3301 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003302}
3303
3304void Context::compressedTexSubImage3D(GLenum target,
3305 GLint level,
3306 GLint xoffset,
3307 GLint yoffset,
3308 GLint zoffset,
3309 GLsizei width,
3310 GLsizei height,
3311 GLsizei depth,
3312 GLenum format,
3313 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003314 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003315{
3316 // Zero sized uploads are valid but no-ops
3317 if (width == 0 || height == 0)
3318 {
3319 return;
3320 }
3321
Jamie Madillad9f24e2016-02-12 09:27:24 -05003322 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003323
3324 Box area(xoffset, yoffset, zoffset, width, height, depth);
3325 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003326 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003327 format, imageSize,
3328 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003329}
3330
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003331void Context::generateMipmap(GLenum target)
3332{
3333 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003334 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003335}
3336
Geoff Lang97073d12016-04-20 10:42:34 -07003337void Context::copyTextureCHROMIUM(GLuint sourceId,
Geoff Langfc72a072017-03-24 14:52:39 -04003338 GLint sourceLevel,
3339 GLenum destTarget,
Geoff Lang97073d12016-04-20 10:42:34 -07003340 GLuint destId,
Geoff Langfc72a072017-03-24 14:52:39 -04003341 GLint destLevel,
Geoff Lang97073d12016-04-20 10:42:34 -07003342 GLint internalFormat,
3343 GLenum destType,
3344 GLboolean unpackFlipY,
3345 GLboolean unpackPremultiplyAlpha,
3346 GLboolean unpackUnmultiplyAlpha)
3347{
3348 syncStateForTexImage();
3349
3350 gl::Texture *sourceTexture = getTexture(sourceId);
3351 gl::Texture *destTexture = getTexture(destId);
Geoff Lang92019432017-11-20 13:09:34 -05003352 handleError(destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType,
3353 sourceLevel, ConvertToBool(unpackFlipY),
3354 ConvertToBool(unpackPremultiplyAlpha),
3355 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003356}
3357
3358void Context::copySubTextureCHROMIUM(GLuint sourceId,
Geoff Langfc72a072017-03-24 14:52:39 -04003359 GLint sourceLevel,
3360 GLenum destTarget,
Geoff Lang97073d12016-04-20 10:42:34 -07003361 GLuint destId,
Geoff Langfc72a072017-03-24 14:52:39 -04003362 GLint destLevel,
Geoff Lang97073d12016-04-20 10:42:34 -07003363 GLint xoffset,
3364 GLint yoffset,
3365 GLint x,
3366 GLint y,
3367 GLsizei width,
3368 GLsizei height,
3369 GLboolean unpackFlipY,
3370 GLboolean unpackPremultiplyAlpha,
3371 GLboolean unpackUnmultiplyAlpha)
3372{
3373 // Zero sized copies are valid but no-ops
3374 if (width == 0 || height == 0)
3375 {
3376 return;
3377 }
3378
3379 syncStateForTexImage();
3380
3381 gl::Texture *sourceTexture = getTexture(sourceId);
3382 gl::Texture *destTexture = getTexture(destId);
3383 Offset offset(xoffset, yoffset, 0);
3384 Rectangle area(x, y, width, height);
Geoff Lang92019432017-11-20 13:09:34 -05003385 handleError(destTexture->copySubTexture(this, destTarget, destLevel, offset, sourceLevel, area,
3386 ConvertToBool(unpackFlipY),
3387 ConvertToBool(unpackPremultiplyAlpha),
3388 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003389}
3390
Geoff Lang47110bf2016-04-20 11:13:22 -07003391void Context::compressedCopyTextureCHROMIUM(GLuint sourceId, GLuint destId)
3392{
3393 syncStateForTexImage();
3394
3395 gl::Texture *sourceTexture = getTexture(sourceId);
3396 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05003397 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07003398}
3399
Corentin Wallez336129f2017-10-17 15:55:40 -04003400void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03003401{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003402 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003403 ASSERT(buffer);
3404
Geoff Lang496c02d2016-10-20 11:38:11 -07003405 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03003406}
3407
Corentin Wallez336129f2017-10-17 15:55:40 -04003408void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003409{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003410 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003411 ASSERT(buffer);
3412
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003413 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003414 if (error.isError())
3415 {
Jamie Madill437fa652016-05-03 15:13:24 -04003416 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003417 return nullptr;
3418 }
3419
3420 return buffer->getMapPointer();
3421}
3422
Corentin Wallez336129f2017-10-17 15:55:40 -04003423GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03003424{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003425 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003426 ASSERT(buffer);
3427
3428 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003429 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03003430 if (error.isError())
3431 {
Jamie Madill437fa652016-05-03 15:13:24 -04003432 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003433 return GL_FALSE;
3434 }
3435
3436 return result;
3437}
3438
Corentin Wallez336129f2017-10-17 15:55:40 -04003439void *Context::mapBufferRange(BufferBinding target,
3440 GLintptr offset,
3441 GLsizeiptr length,
3442 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003443{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003444 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003445 ASSERT(buffer);
3446
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003447 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003448 if (error.isError())
3449 {
Jamie Madill437fa652016-05-03 15:13:24 -04003450 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003451 return nullptr;
3452 }
3453
3454 return buffer->getMapPointer();
3455}
3456
Corentin Wallez336129f2017-10-17 15:55:40 -04003457void Context::flushMappedBufferRange(BufferBinding /*target*/,
3458 GLintptr /*offset*/,
3459 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03003460{
3461 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
3462}
3463
Jamie Madillad9f24e2016-02-12 09:27:24 -05003464void Context::syncStateForReadPixels()
3465{
3466 syncRendererState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
3467}
3468
3469void Context::syncStateForTexImage()
3470{
3471 syncRendererState(mTexImageDirtyBits, mTexImageDirtyObjects);
3472}
3473
3474void Context::syncStateForClear()
3475{
3476 syncRendererState(mClearDirtyBits, mClearDirtyObjects);
3477}
3478
3479void Context::syncStateForBlit()
3480{
3481 syncRendererState(mBlitDirtyBits, mBlitDirtyObjects);
3482}
3483
Jiajia Qin5451d532017-11-16 17:16:34 +08003484void Context::activeShaderProgram(GLuint pipeline, GLuint program)
3485{
3486 UNIMPLEMENTED();
3487}
3488
Jamie Madillc20ab272016-06-09 07:20:46 -07003489void Context::activeTexture(GLenum texture)
3490{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003491 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003492}
3493
Jamie Madill876429b2017-04-20 15:46:24 -04003494void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003495{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003496 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07003497}
3498
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003499void Context::blendEquation(GLenum mode)
3500{
3501 mGLState.setBlendEquation(mode, mode);
3502}
3503
Jamie Madillc20ab272016-06-09 07:20:46 -07003504void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
3505{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003506 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003507}
3508
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003509void Context::blendFunc(GLenum sfactor, GLenum dfactor)
3510{
3511 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
3512}
3513
Jamie Madillc20ab272016-06-09 07:20:46 -07003514void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
3515{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003516 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003517}
3518
Jamie Madill876429b2017-04-20 15:46:24 -04003519void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003520{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003521 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003522}
3523
Jamie Madill876429b2017-04-20 15:46:24 -04003524void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07003525{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003526 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07003527}
3528
3529void Context::clearStencil(GLint s)
3530{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003531 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07003532}
3533
3534void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
3535{
Geoff Lang92019432017-11-20 13:09:34 -05003536 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
3537 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07003538}
3539
Corentin Wallez2e568cf2017-09-18 17:05:22 -04003540void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07003541{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003542 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003543}
3544
3545void Context::depthFunc(GLenum func)
3546{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003547 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07003548}
3549
3550void Context::depthMask(GLboolean flag)
3551{
Geoff Lang92019432017-11-20 13:09:34 -05003552 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07003553}
3554
Jamie Madill876429b2017-04-20 15:46:24 -04003555void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07003556{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003557 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07003558}
3559
3560void Context::disable(GLenum cap)
3561{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003562 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003563}
3564
3565void Context::disableVertexAttribArray(GLuint index)
3566{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003567 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003568}
3569
3570void Context::enable(GLenum cap)
3571{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003572 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003573}
3574
3575void Context::enableVertexAttribArray(GLuint index)
3576{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003577 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003578}
3579
3580void Context::frontFace(GLenum mode)
3581{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003582 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003583}
3584
3585void Context::hint(GLenum target, GLenum mode)
3586{
3587 switch (target)
3588 {
3589 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003590 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003591 break;
3592
3593 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003594 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003595 break;
3596
3597 default:
3598 UNREACHABLE();
3599 return;
3600 }
3601}
3602
3603void Context::lineWidth(GLfloat width)
3604{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003605 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07003606}
3607
3608void Context::pixelStorei(GLenum pname, GLint param)
3609{
3610 switch (pname)
3611 {
3612 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003613 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003614 break;
3615
3616 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003617 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003618 break;
3619
3620 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003621 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003622 break;
3623
3624 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003625 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003626 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003627 break;
3628
3629 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03003630 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003631 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003632 break;
3633
3634 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03003635 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003636 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003637 break;
3638
3639 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003640 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003641 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003642 break;
3643
3644 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003645 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003646 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003647 break;
3648
3649 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003650 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003651 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003652 break;
3653
3654 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003655 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003656 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003657 break;
3658
3659 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003660 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003661 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003662 break;
3663
3664 default:
3665 UNREACHABLE();
3666 return;
3667 }
3668}
3669
3670void Context::polygonOffset(GLfloat factor, GLfloat units)
3671{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003672 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07003673}
3674
Jamie Madill876429b2017-04-20 15:46:24 -04003675void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07003676{
Geoff Lang92019432017-11-20 13:09:34 -05003677 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07003678}
3679
Jiawei Shaodb342272017-09-27 10:21:45 +08003680void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
3681{
3682 mGLState.setSampleMaskParams(maskNumber, mask);
3683}
3684
Jamie Madillc20ab272016-06-09 07:20:46 -07003685void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
3686{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003687 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07003688}
3689
3690void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
3691{
3692 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3693 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003694 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003695 }
3696
3697 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3698 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003699 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003700 }
3701}
3702
3703void Context::stencilMaskSeparate(GLenum face, GLuint mask)
3704{
3705 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3706 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003707 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003708 }
3709
3710 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3711 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003712 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003713 }
3714}
3715
3716void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
3717{
3718 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3719 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003720 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003721 }
3722
3723 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3724 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003725 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003726 }
3727}
3728
3729void Context::vertexAttrib1f(GLuint index, GLfloat x)
3730{
3731 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003732 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003733}
3734
3735void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
3736{
3737 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003738 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003739}
3740
3741void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
3742{
3743 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003744 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003745}
3746
3747void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
3748{
3749 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003750 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003751}
3752
3753void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
3754{
3755 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003756 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003757}
3758
3759void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
3760{
3761 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003762 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003763}
3764
3765void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
3766{
3767 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003768 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003769}
3770
3771void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
3772{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003773 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07003774}
3775
3776void Context::vertexAttribPointer(GLuint index,
3777 GLint size,
3778 GLenum type,
3779 GLboolean normalized,
3780 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04003781 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07003782{
Corentin Wallez336129f2017-10-17 15:55:40 -04003783 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05003784 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc20ab272016-06-09 07:20:46 -07003785}
3786
Shao80957d92017-02-20 21:25:59 +08003787void Context::vertexAttribFormat(GLuint attribIndex,
3788 GLint size,
3789 GLenum type,
3790 GLboolean normalized,
3791 GLuint relativeOffset)
3792{
Geoff Lang92019432017-11-20 13:09:34 -05003793 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08003794 relativeOffset);
3795}
3796
3797void Context::vertexAttribIFormat(GLuint attribIndex,
3798 GLint size,
3799 GLenum type,
3800 GLuint relativeOffset)
3801{
3802 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
3803}
3804
3805void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
3806{
Shaodde78e82017-05-22 14:13:27 +08003807 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Shao80957d92017-02-20 21:25:59 +08003808}
3809
Jiajia Qin5451d532017-11-16 17:16:34 +08003810void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08003811{
3812 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
3813}
3814
Jamie Madillc20ab272016-06-09 07:20:46 -07003815void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
3816{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003817 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07003818}
3819
3820void Context::vertexAttribIPointer(GLuint index,
3821 GLint size,
3822 GLenum type,
3823 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04003824 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07003825{
Corentin Wallez336129f2017-10-17 15:55:40 -04003826 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
3827 size, type, false, true, stride, pointer);
Jamie Madillc20ab272016-06-09 07:20:46 -07003828}
3829
3830void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
3831{
3832 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003833 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003834}
3835
3836void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
3837{
3838 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003839 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003840}
3841
3842void Context::vertexAttribI4iv(GLuint index, const GLint *v)
3843{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003844 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07003845}
3846
3847void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
3848{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003849 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07003850}
3851
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003852void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
3853{
3854 const VertexAttribCurrentValueData &currentValues =
3855 getGLState().getVertexAttribCurrentValue(index);
3856 const VertexArray *vao = getGLState().getVertexArray();
3857 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3858 currentValues, pname, params);
3859}
3860
3861void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
3862{
3863 const VertexAttribCurrentValueData &currentValues =
3864 getGLState().getVertexAttribCurrentValue(index);
3865 const VertexArray *vao = getGLState().getVertexArray();
3866 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3867 currentValues, pname, params);
3868}
3869
3870void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
3871{
3872 const VertexAttribCurrentValueData &currentValues =
3873 getGLState().getVertexAttribCurrentValue(index);
3874 const VertexArray *vao = getGLState().getVertexArray();
3875 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3876 currentValues, pname, params);
3877}
3878
3879void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
3880{
3881 const VertexAttribCurrentValueData &currentValues =
3882 getGLState().getVertexAttribCurrentValue(index);
3883 const VertexArray *vao = getGLState().getVertexArray();
3884 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3885 currentValues, pname, params);
3886}
3887
Jamie Madill876429b2017-04-20 15:46:24 -04003888void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003889{
3890 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
3891 QueryVertexAttribPointerv(attrib, pname, pointer);
3892}
3893
Jamie Madillc20ab272016-06-09 07:20:46 -07003894void Context::debugMessageControl(GLenum source,
3895 GLenum type,
3896 GLenum severity,
3897 GLsizei count,
3898 const GLuint *ids,
3899 GLboolean enabled)
3900{
3901 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003902 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05003903 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07003904}
3905
3906void Context::debugMessageInsert(GLenum source,
3907 GLenum type,
3908 GLuint id,
3909 GLenum severity,
3910 GLsizei length,
3911 const GLchar *buf)
3912{
3913 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003914 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07003915}
3916
3917void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
3918{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003919 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07003920}
3921
3922GLuint Context::getDebugMessageLog(GLuint count,
3923 GLsizei bufSize,
3924 GLenum *sources,
3925 GLenum *types,
3926 GLuint *ids,
3927 GLenum *severities,
3928 GLsizei *lengths,
3929 GLchar *messageLog)
3930{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003931 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
3932 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07003933}
3934
3935void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
3936{
3937 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003938 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07003939}
3940
3941void Context::popDebugGroup()
3942{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003943 mGLState.getDebug().popGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07003944}
3945
Corentin Wallez336129f2017-10-17 15:55:40 -04003946void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04003947{
3948 Buffer *buffer = mGLState.getTargetBuffer(target);
3949 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08003950 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04003951}
3952
Corentin Wallez336129f2017-10-17 15:55:40 -04003953void Context::bufferSubData(BufferBinding target,
3954 GLintptr offset,
3955 GLsizeiptr size,
3956 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04003957{
3958 if (data == nullptr)
3959 {
3960 return;
3961 }
3962
3963 Buffer *buffer = mGLState.getTargetBuffer(target);
3964 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08003965 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04003966}
3967
Jamie Madillef300b12016-10-07 15:12:09 -04003968void Context::attachShader(GLuint program, GLuint shader)
3969{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05003970 Program *programObject = mState.mShaderPrograms->getProgram(program);
3971 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04003972 ASSERT(programObject && shaderObject);
3973 programObject->attachShader(shaderObject);
3974}
3975
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003976const Workarounds &Context::getWorkarounds() const
3977{
3978 return mWorkarounds;
3979}
3980
Corentin Wallez336129f2017-10-17 15:55:40 -04003981void Context::copyBufferSubData(BufferBinding readTarget,
3982 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04003983 GLintptr readOffset,
3984 GLintptr writeOffset,
3985 GLsizeiptr size)
3986{
3987 // if size is zero, the copy is a successful no-op
3988 if (size == 0)
3989 {
3990 return;
3991 }
3992
3993 // TODO(jmadill): cache these.
3994 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
3995 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
3996
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003997 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04003998}
3999
Jamie Madill01a80ee2016-11-07 12:06:18 -05004000void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4001{
4002 Program *programObject = getProgram(program);
4003 // TODO(jmadill): Re-use this from the validation if possible.
4004 ASSERT(programObject);
4005 programObject->bindAttributeLocation(index, name);
4006}
4007
Corentin Wallez336129f2017-10-17 15:55:40 -04004008void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004009{
Corentin Wallez336129f2017-10-17 15:55:40 -04004010 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4011 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004012}
4013
Corentin Wallez336129f2017-10-17 15:55:40 -04004014void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08004015{
4016 bindBufferRange(target, index, buffer, 0, 0);
4017}
4018
Corentin Wallez336129f2017-10-17 15:55:40 -04004019void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08004020 GLuint index,
4021 GLuint buffer,
4022 GLintptr offset,
4023 GLsizeiptr size)
4024{
Corentin Wallez336129f2017-10-17 15:55:40 -04004025 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4026 mGLState.setIndexedBufferBinding(this, target, index, bufferObject, offset, size);
Jiajia Qin6eafb042016-12-27 17:04:07 +08004027}
4028
Jamie Madill01a80ee2016-11-07 12:06:18 -05004029void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
4030{
4031 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4032 {
4033 bindReadFramebuffer(framebuffer);
4034 }
4035
4036 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4037 {
4038 bindDrawFramebuffer(framebuffer);
4039 }
4040}
4041
4042void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4043{
4044 ASSERT(target == GL_RENDERBUFFER);
4045 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004046 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04004047 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004048}
4049
JiangYizhoubddc46b2016-12-09 09:50:51 +08004050void Context::texStorage2DMultisample(GLenum target,
4051 GLsizei samples,
4052 GLenum internalformat,
4053 GLsizei width,
4054 GLsizei height,
4055 GLboolean fixedsamplelocations)
4056{
4057 Extents size(width, height, 1);
4058 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05004059 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
Geoff Lang92019432017-11-20 13:09:34 -05004060 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004061}
4062
4063void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4064{
JiangYizhou5b03f472017-01-09 10:22:53 +08004065 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
4066 // the sample position should be queried by DRAW_FRAMEBUFFER.
4067 mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER);
4068 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08004069
4070 switch (pname)
4071 {
4072 case GL_SAMPLE_POSITION:
4073 handleError(framebuffer->getSamplePosition(index, val));
4074 break;
4075 default:
4076 UNREACHABLE();
4077 }
4078}
4079
Jamie Madille8fb6402017-02-14 17:56:40 -05004080void Context::renderbufferStorage(GLenum target,
4081 GLenum internalformat,
4082 GLsizei width,
4083 GLsizei height)
4084{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004085 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4086 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
4087
Jamie Madille8fb6402017-02-14 17:56:40 -05004088 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04004089 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004090}
4091
4092void Context::renderbufferStorageMultisample(GLenum target,
4093 GLsizei samples,
4094 GLenum internalformat,
4095 GLsizei width,
4096 GLsizei height)
4097{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004098 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4099 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05004100
4101 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004102 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04004103 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004104}
4105
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004106void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
4107{
Jamie Madill70b5bb02017-08-28 13:32:37 -04004108 const Sync *syncObject = getSync(sync);
Geoff Lang82483b92017-04-11 15:33:00 -04004109 handleError(QuerySynciv(syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004110}
4111
JiangYizhoue18e6392017-02-20 10:32:23 +08004112void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
4113{
4114 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4115 QueryFramebufferParameteriv(framebuffer, pname, params);
4116}
4117
Jiajia Qin5451d532017-11-16 17:16:34 +08004118void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08004119{
4120 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4121 SetFramebufferParameteri(framebuffer, pname, param);
4122}
4123
Jamie Madillb3f26b92017-07-19 15:07:41 -04004124Error Context::getScratchBuffer(size_t requstedSizeBytes,
4125 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05004126{
Jamie Madillb3f26b92017-07-19 15:07:41 -04004127 if (!mScratchBuffer.get(requstedSizeBytes, scratchBufferOut))
4128 {
4129 return OutOfMemory() << "Failed to allocate internal buffer.";
4130 }
4131 return NoError();
4132}
4133
4134Error Context::getZeroFilledBuffer(size_t requstedSizeBytes,
4135 angle::MemoryBuffer **zeroBufferOut) const
4136{
4137 if (!mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0))
Jamie Madille14951e2017-03-09 18:55:16 -05004138 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004139 return OutOfMemory() << "Failed to allocate internal buffer.";
Jamie Madille14951e2017-03-09 18:55:16 -05004140 }
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004141 return NoError();
Jamie Madille14951e2017-03-09 18:55:16 -05004142}
4143
Xinghua Cao2b396592017-03-29 15:36:04 +08004144void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
4145{
4146 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
4147 {
4148 return;
4149 }
4150
Jamie Madill05b35b22017-10-03 09:01:44 -04004151 // TODO(jmadill): Dirty bits for compute.
Jamie Madilla59fc192017-11-02 12:57:58 -04004152 if (isRobustResourceInitEnabled())
4153 {
4154 ANGLE_CONTEXT_TRY(mGLState.clearUnclearedActiveTextures(this));
4155 }
Jamie Madill05b35b22017-10-03 09:01:44 -04004156
Jamie Madill71c88b32017-09-14 22:20:29 -04004157 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08004158}
4159
Jiajia Qin5451d532017-11-16 17:16:34 +08004160void Context::dispatchComputeIndirect(GLintptr indirect)
4161{
4162 UNIMPLEMENTED();
4163}
4164
JiangYizhou165361c2017-06-07 14:56:57 +08004165void Context::texStorage2D(GLenum target,
4166 GLsizei levels,
4167 GLenum internalFormat,
4168 GLsizei width,
4169 GLsizei height)
4170{
4171 Extents size(width, height, 1);
4172 Texture *texture = getTargetTexture(target);
4173 handleError(texture->setStorage(this, target, levels, internalFormat, size));
4174}
4175
4176void Context::texStorage3D(GLenum target,
4177 GLsizei levels,
4178 GLenum internalFormat,
4179 GLsizei width,
4180 GLsizei height,
4181 GLsizei depth)
4182{
4183 Extents size(width, height, depth);
4184 Texture *texture = getTargetTexture(target);
4185 handleError(texture->setStorage(this, target, levels, internalFormat, size));
4186}
4187
Jiajia Qin5451d532017-11-16 17:16:34 +08004188void Context::memoryBarrier(GLbitfield barriers)
4189{
4190 UNIMPLEMENTED();
4191}
4192
4193void Context::memoryBarrierByRegion(GLbitfield barriers)
4194{
4195 UNIMPLEMENTED();
4196}
4197
Jamie Madillc1d770e2017-04-13 17:31:24 -04004198GLenum Context::checkFramebufferStatus(GLenum target)
4199{
4200 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4201 ASSERT(framebuffer);
4202
4203 return framebuffer->checkStatus(this);
4204}
4205
4206void Context::compileShader(GLuint shader)
4207{
4208 Shader *shaderObject = GetValidShader(this, shader);
4209 if (!shaderObject)
4210 {
4211 return;
4212 }
4213 shaderObject->compile(this);
4214}
4215
4216void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
4217{
4218 for (int i = 0; i < n; i++)
4219 {
4220 deleteBuffer(buffers[i]);
4221 }
4222}
4223
4224void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
4225{
4226 for (int i = 0; i < n; i++)
4227 {
4228 if (framebuffers[i] != 0)
4229 {
4230 deleteFramebuffer(framebuffers[i]);
4231 }
4232 }
4233}
4234
4235void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
4236{
4237 for (int i = 0; i < n; i++)
4238 {
4239 deleteRenderbuffer(renderbuffers[i]);
4240 }
4241}
4242
4243void Context::deleteTextures(GLsizei n, const GLuint *textures)
4244{
4245 for (int i = 0; i < n; i++)
4246 {
4247 if (textures[i] != 0)
4248 {
4249 deleteTexture(textures[i]);
4250 }
4251 }
4252}
4253
4254void Context::detachShader(GLuint program, GLuint shader)
4255{
4256 Program *programObject = getProgram(program);
4257 ASSERT(programObject);
4258
4259 Shader *shaderObject = getShader(shader);
4260 ASSERT(shaderObject);
4261
4262 programObject->detachShader(this, shaderObject);
4263}
4264
4265void Context::genBuffers(GLsizei n, GLuint *buffers)
4266{
4267 for (int i = 0; i < n; i++)
4268 {
4269 buffers[i] = createBuffer();
4270 }
4271}
4272
4273void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
4274{
4275 for (int i = 0; i < n; i++)
4276 {
4277 framebuffers[i] = createFramebuffer();
4278 }
4279}
4280
4281void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
4282{
4283 for (int i = 0; i < n; i++)
4284 {
4285 renderbuffers[i] = createRenderbuffer();
4286 }
4287}
4288
4289void Context::genTextures(GLsizei n, GLuint *textures)
4290{
4291 for (int i = 0; i < n; i++)
4292 {
4293 textures[i] = createTexture();
4294 }
4295}
4296
4297void Context::getActiveAttrib(GLuint program,
4298 GLuint index,
4299 GLsizei bufsize,
4300 GLsizei *length,
4301 GLint *size,
4302 GLenum *type,
4303 GLchar *name)
4304{
4305 Program *programObject = getProgram(program);
4306 ASSERT(programObject);
4307 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
4308}
4309
4310void Context::getActiveUniform(GLuint program,
4311 GLuint index,
4312 GLsizei bufsize,
4313 GLsizei *length,
4314 GLint *size,
4315 GLenum *type,
4316 GLchar *name)
4317{
4318 Program *programObject = getProgram(program);
4319 ASSERT(programObject);
4320 programObject->getActiveUniform(index, bufsize, length, size, type, name);
4321}
4322
4323void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
4324{
4325 Program *programObject = getProgram(program);
4326 ASSERT(programObject);
4327 programObject->getAttachedShaders(maxcount, count, shaders);
4328}
4329
4330GLint Context::getAttribLocation(GLuint program, const GLchar *name)
4331{
4332 Program *programObject = getProgram(program);
4333 ASSERT(programObject);
4334 return programObject->getAttributeLocation(name);
4335}
4336
4337void Context::getBooleanv(GLenum pname, GLboolean *params)
4338{
4339 GLenum nativeType;
4340 unsigned int numParams = 0;
4341 getQueryParameterInfo(pname, &nativeType, &numParams);
4342
4343 if (nativeType == GL_BOOL)
4344 {
4345 getBooleanvImpl(pname, params);
4346 }
4347 else
4348 {
4349 CastStateValues(this, nativeType, pname, numParams, params);
4350 }
4351}
4352
4353void Context::getFloatv(GLenum pname, GLfloat *params)
4354{
4355 GLenum nativeType;
4356 unsigned int numParams = 0;
4357 getQueryParameterInfo(pname, &nativeType, &numParams);
4358
4359 if (nativeType == GL_FLOAT)
4360 {
4361 getFloatvImpl(pname, params);
4362 }
4363 else
4364 {
4365 CastStateValues(this, nativeType, pname, numParams, params);
4366 }
4367}
4368
4369void Context::getIntegerv(GLenum pname, GLint *params)
4370{
4371 GLenum nativeType;
4372 unsigned int numParams = 0;
4373 getQueryParameterInfo(pname, &nativeType, &numParams);
4374
4375 if (nativeType == GL_INT)
4376 {
4377 getIntegervImpl(pname, params);
4378 }
4379 else
4380 {
4381 CastStateValues(this, nativeType, pname, numParams, params);
4382 }
4383}
4384
4385void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
4386{
4387 Program *programObject = getProgram(program);
4388 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04004389 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004390}
4391
Jiajia Qin5451d532017-11-16 17:16:34 +08004392void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
4393{
4394 UNIMPLEMENTED();
4395}
4396
Jamie Madillbe849e42017-05-02 15:49:00 -04004397void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04004398{
4399 Program *programObject = getProgram(program);
4400 ASSERT(programObject);
4401 programObject->getInfoLog(bufsize, length, infolog);
4402}
4403
Jiajia Qin5451d532017-11-16 17:16:34 +08004404void Context::getProgramPipelineInfoLog(GLuint pipeline,
4405 GLsizei bufSize,
4406 GLsizei *length,
4407 GLchar *infoLog)
4408{
4409 UNIMPLEMENTED();
4410}
4411
Jamie Madillc1d770e2017-04-13 17:31:24 -04004412void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
4413{
4414 Shader *shaderObject = getShader(shader);
4415 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004416 QueryShaderiv(this, shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004417}
4418
4419void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
4420{
4421 Shader *shaderObject = getShader(shader);
4422 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004423 shaderObject->getInfoLog(this, bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004424}
4425
4426void Context::getShaderPrecisionFormat(GLenum shadertype,
4427 GLenum precisiontype,
4428 GLint *range,
4429 GLint *precision)
4430{
4431 // TODO(jmadill): Compute shaders.
4432
4433 switch (shadertype)
4434 {
4435 case GL_VERTEX_SHADER:
4436 switch (precisiontype)
4437 {
4438 case GL_LOW_FLOAT:
4439 mCaps.vertexLowpFloat.get(range, precision);
4440 break;
4441 case GL_MEDIUM_FLOAT:
4442 mCaps.vertexMediumpFloat.get(range, precision);
4443 break;
4444 case GL_HIGH_FLOAT:
4445 mCaps.vertexHighpFloat.get(range, precision);
4446 break;
4447
4448 case GL_LOW_INT:
4449 mCaps.vertexLowpInt.get(range, precision);
4450 break;
4451 case GL_MEDIUM_INT:
4452 mCaps.vertexMediumpInt.get(range, precision);
4453 break;
4454 case GL_HIGH_INT:
4455 mCaps.vertexHighpInt.get(range, precision);
4456 break;
4457
4458 default:
4459 UNREACHABLE();
4460 return;
4461 }
4462 break;
4463
4464 case GL_FRAGMENT_SHADER:
4465 switch (precisiontype)
4466 {
4467 case GL_LOW_FLOAT:
4468 mCaps.fragmentLowpFloat.get(range, precision);
4469 break;
4470 case GL_MEDIUM_FLOAT:
4471 mCaps.fragmentMediumpFloat.get(range, precision);
4472 break;
4473 case GL_HIGH_FLOAT:
4474 mCaps.fragmentHighpFloat.get(range, precision);
4475 break;
4476
4477 case GL_LOW_INT:
4478 mCaps.fragmentLowpInt.get(range, precision);
4479 break;
4480 case GL_MEDIUM_INT:
4481 mCaps.fragmentMediumpInt.get(range, precision);
4482 break;
4483 case GL_HIGH_INT:
4484 mCaps.fragmentHighpInt.get(range, precision);
4485 break;
4486
4487 default:
4488 UNREACHABLE();
4489 return;
4490 }
4491 break;
4492
4493 default:
4494 UNREACHABLE();
4495 return;
4496 }
4497}
4498
4499void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
4500{
4501 Shader *shaderObject = getShader(shader);
4502 ASSERT(shaderObject);
4503 shaderObject->getSource(bufsize, length, source);
4504}
4505
4506void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
4507{
4508 Program *programObject = getProgram(program);
4509 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04004510 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004511}
4512
4513void Context::getUniformiv(GLuint program, GLint location, GLint *params)
4514{
4515 Program *programObject = getProgram(program);
4516 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04004517 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004518}
4519
4520GLint Context::getUniformLocation(GLuint program, const GLchar *name)
4521{
4522 Program *programObject = getProgram(program);
4523 ASSERT(programObject);
4524 return programObject->getUniformLocation(name);
4525}
4526
4527GLboolean Context::isBuffer(GLuint buffer)
4528{
4529 if (buffer == 0)
4530 {
4531 return GL_FALSE;
4532 }
4533
4534 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
4535}
4536
4537GLboolean Context::isEnabled(GLenum cap)
4538{
4539 return mGLState.getEnableFeature(cap);
4540}
4541
4542GLboolean Context::isFramebuffer(GLuint framebuffer)
4543{
4544 if (framebuffer == 0)
4545 {
4546 return GL_FALSE;
4547 }
4548
4549 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
4550}
4551
4552GLboolean Context::isProgram(GLuint program)
4553{
4554 if (program == 0)
4555 {
4556 return GL_FALSE;
4557 }
4558
4559 return (getProgram(program) ? GL_TRUE : GL_FALSE);
4560}
4561
4562GLboolean Context::isRenderbuffer(GLuint renderbuffer)
4563{
4564 if (renderbuffer == 0)
4565 {
4566 return GL_FALSE;
4567 }
4568
4569 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
4570}
4571
4572GLboolean Context::isShader(GLuint shader)
4573{
4574 if (shader == 0)
4575 {
4576 return GL_FALSE;
4577 }
4578
4579 return (getShader(shader) ? GL_TRUE : GL_FALSE);
4580}
4581
4582GLboolean Context::isTexture(GLuint texture)
4583{
4584 if (texture == 0)
4585 {
4586 return GL_FALSE;
4587 }
4588
4589 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
4590}
4591
4592void Context::linkProgram(GLuint program)
4593{
4594 Program *programObject = getProgram(program);
4595 ASSERT(programObject);
4596 handleError(programObject->link(this));
Martin Radev0abb7a22017-08-28 15:34:45 +03004597 mGLState.onProgramExecutableChange(programObject);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004598}
4599
4600void Context::releaseShaderCompiler()
4601{
Jamie Madill4928b7c2017-06-20 12:57:39 -04004602 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004603}
4604
4605void Context::shaderBinary(GLsizei n,
4606 const GLuint *shaders,
4607 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04004608 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04004609 GLsizei length)
4610{
4611 // No binary shader formats are supported.
4612 UNIMPLEMENTED();
4613}
4614
4615void Context::shaderSource(GLuint shader,
4616 GLsizei count,
4617 const GLchar *const *string,
4618 const GLint *length)
4619{
4620 Shader *shaderObject = getShader(shader);
4621 ASSERT(shaderObject);
4622 shaderObject->setSource(count, string, length);
4623}
4624
4625void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
4626{
4627 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
4628}
4629
4630void Context::stencilMask(GLuint mask)
4631{
4632 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
4633}
4634
4635void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
4636{
4637 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
4638}
4639
4640void Context::uniform1f(GLint location, GLfloat x)
4641{
4642 Program *program = mGLState.getProgram();
4643 program->setUniform1fv(location, 1, &x);
4644}
4645
4646void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
4647{
4648 Program *program = mGLState.getProgram();
4649 program->setUniform1fv(location, count, v);
4650}
4651
4652void Context::uniform1i(GLint location, GLint x)
4653{
4654 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04004655 if (program->setUniform1iv(location, 1, &x) == Program::SetUniformResult::SamplerChanged)
4656 {
4657 mGLState.setObjectDirty(GL_PROGRAM);
4658 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04004659}
4660
4661void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
4662{
4663 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04004664 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
4665 {
4666 mGLState.setObjectDirty(GL_PROGRAM);
4667 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04004668}
4669
4670void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
4671{
4672 GLfloat xy[2] = {x, y};
4673 Program *program = mGLState.getProgram();
4674 program->setUniform2fv(location, 1, xy);
4675}
4676
4677void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
4678{
4679 Program *program = mGLState.getProgram();
4680 program->setUniform2fv(location, count, v);
4681}
4682
4683void Context::uniform2i(GLint location, GLint x, GLint y)
4684{
4685 GLint xy[2] = {x, y};
4686 Program *program = mGLState.getProgram();
4687 program->setUniform2iv(location, 1, xy);
4688}
4689
4690void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
4691{
4692 Program *program = mGLState.getProgram();
4693 program->setUniform2iv(location, count, v);
4694}
4695
4696void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
4697{
4698 GLfloat xyz[3] = {x, y, z};
4699 Program *program = mGLState.getProgram();
4700 program->setUniform3fv(location, 1, xyz);
4701}
4702
4703void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
4704{
4705 Program *program = mGLState.getProgram();
4706 program->setUniform3fv(location, count, v);
4707}
4708
4709void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
4710{
4711 GLint xyz[3] = {x, y, z};
4712 Program *program = mGLState.getProgram();
4713 program->setUniform3iv(location, 1, xyz);
4714}
4715
4716void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
4717{
4718 Program *program = mGLState.getProgram();
4719 program->setUniform3iv(location, count, v);
4720}
4721
4722void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4723{
4724 GLfloat xyzw[4] = {x, y, z, w};
4725 Program *program = mGLState.getProgram();
4726 program->setUniform4fv(location, 1, xyzw);
4727}
4728
4729void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
4730{
4731 Program *program = mGLState.getProgram();
4732 program->setUniform4fv(location, count, v);
4733}
4734
4735void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
4736{
4737 GLint xyzw[4] = {x, y, z, w};
4738 Program *program = mGLState.getProgram();
4739 program->setUniform4iv(location, 1, xyzw);
4740}
4741
4742void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
4743{
4744 Program *program = mGLState.getProgram();
4745 program->setUniform4iv(location, count, v);
4746}
4747
4748void Context::uniformMatrix2fv(GLint location,
4749 GLsizei count,
4750 GLboolean transpose,
4751 const GLfloat *value)
4752{
4753 Program *program = mGLState.getProgram();
4754 program->setUniformMatrix2fv(location, count, transpose, value);
4755}
4756
4757void Context::uniformMatrix3fv(GLint location,
4758 GLsizei count,
4759 GLboolean transpose,
4760 const GLfloat *value)
4761{
4762 Program *program = mGLState.getProgram();
4763 program->setUniformMatrix3fv(location, count, transpose, value);
4764}
4765
4766void Context::uniformMatrix4fv(GLint location,
4767 GLsizei count,
4768 GLboolean transpose,
4769 const GLfloat *value)
4770{
4771 Program *program = mGLState.getProgram();
4772 program->setUniformMatrix4fv(location, count, transpose, value);
4773}
4774
4775void Context::validateProgram(GLuint program)
4776{
4777 Program *programObject = getProgram(program);
4778 ASSERT(programObject);
4779 programObject->validate(mCaps);
4780}
4781
Jiajia Qin5451d532017-11-16 17:16:34 +08004782void Context::validateProgramPipeline(GLuint pipeline)
4783{
4784 UNIMPLEMENTED();
4785}
4786
Jamie Madilld04908b2017-06-09 14:15:35 -04004787void Context::getProgramBinary(GLuint program,
4788 GLsizei bufSize,
4789 GLsizei *length,
4790 GLenum *binaryFormat,
4791 void *binary)
4792{
4793 Program *programObject = getProgram(program);
4794 ASSERT(programObject != nullptr);
4795
4796 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
4797}
4798
4799void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
4800{
4801 Program *programObject = getProgram(program);
4802 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04004803
Jamie Madilld04908b2017-06-09 14:15:35 -04004804 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
4805}
4806
Jamie Madillff325f12017-08-26 15:06:05 -04004807void Context::uniform1ui(GLint location, GLuint v0)
4808{
4809 Program *program = mGLState.getProgram();
4810 program->setUniform1uiv(location, 1, &v0);
4811}
4812
4813void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
4814{
4815 Program *program = mGLState.getProgram();
4816 const GLuint xy[] = {v0, v1};
4817 program->setUniform2uiv(location, 1, xy);
4818}
4819
4820void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
4821{
4822 Program *program = mGLState.getProgram();
4823 const GLuint xyz[] = {v0, v1, v2};
4824 program->setUniform3uiv(location, 1, xyz);
4825}
4826
4827void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
4828{
4829 Program *program = mGLState.getProgram();
4830 const GLuint xyzw[] = {v0, v1, v2, v3};
4831 program->setUniform4uiv(location, 1, xyzw);
4832}
4833
4834void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
4835{
4836 Program *program = mGLState.getProgram();
4837 program->setUniform1uiv(location, count, value);
4838}
4839void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
4840{
4841 Program *program = mGLState.getProgram();
4842 program->setUniform2uiv(location, count, value);
4843}
4844
4845void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
4846{
4847 Program *program = mGLState.getProgram();
4848 program->setUniform3uiv(location, count, value);
4849}
4850
4851void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
4852{
4853 Program *program = mGLState.getProgram();
4854 program->setUniform4uiv(location, count, value);
4855}
4856
Jamie Madillf0e04492017-08-26 15:28:42 -04004857void Context::genQueries(GLsizei n, GLuint *ids)
4858{
4859 for (GLsizei i = 0; i < n; i++)
4860 {
4861 GLuint handle = mQueryHandleAllocator.allocate();
4862 mQueryMap.assign(handle, nullptr);
4863 ids[i] = handle;
4864 }
4865}
4866
4867void Context::deleteQueries(GLsizei n, const GLuint *ids)
4868{
4869 for (int i = 0; i < n; i++)
4870 {
4871 GLuint query = ids[i];
4872
4873 Query *queryObject = nullptr;
4874 if (mQueryMap.erase(query, &queryObject))
4875 {
4876 mQueryHandleAllocator.release(query);
4877 if (queryObject)
4878 {
4879 queryObject->release(this);
4880 }
4881 }
4882 }
4883}
4884
4885GLboolean Context::isQuery(GLuint id)
4886{
4887 return (getQuery(id, false, GL_NONE) != nullptr) ? GL_TRUE : GL_FALSE;
4888}
4889
Jamie Madillc8c95812017-08-26 18:40:09 -04004890void Context::uniformMatrix2x3fv(GLint location,
4891 GLsizei count,
4892 GLboolean transpose,
4893 const GLfloat *value)
4894{
4895 Program *program = mGLState.getProgram();
4896 program->setUniformMatrix2x3fv(location, count, transpose, value);
4897}
4898
4899void Context::uniformMatrix3x2fv(GLint location,
4900 GLsizei count,
4901 GLboolean transpose,
4902 const GLfloat *value)
4903{
4904 Program *program = mGLState.getProgram();
4905 program->setUniformMatrix3x2fv(location, count, transpose, value);
4906}
4907
4908void Context::uniformMatrix2x4fv(GLint location,
4909 GLsizei count,
4910 GLboolean transpose,
4911 const GLfloat *value)
4912{
4913 Program *program = mGLState.getProgram();
4914 program->setUniformMatrix2x4fv(location, count, transpose, value);
4915}
4916
4917void Context::uniformMatrix4x2fv(GLint location,
4918 GLsizei count,
4919 GLboolean transpose,
4920 const GLfloat *value)
4921{
4922 Program *program = mGLState.getProgram();
4923 program->setUniformMatrix4x2fv(location, count, transpose, value);
4924}
4925
4926void Context::uniformMatrix3x4fv(GLint location,
4927 GLsizei count,
4928 GLboolean transpose,
4929 const GLfloat *value)
4930{
4931 Program *program = mGLState.getProgram();
4932 program->setUniformMatrix3x4fv(location, count, transpose, value);
4933}
4934
4935void Context::uniformMatrix4x3fv(GLint location,
4936 GLsizei count,
4937 GLboolean transpose,
4938 const GLfloat *value)
4939{
4940 Program *program = mGLState.getProgram();
4941 program->setUniformMatrix4x3fv(location, count, transpose, value);
4942}
4943
Jamie Madilld7576732017-08-26 18:49:50 -04004944void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
4945{
4946 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
4947 {
4948 GLuint vertexArray = arrays[arrayIndex];
4949
4950 if (arrays[arrayIndex] != 0)
4951 {
4952 VertexArray *vertexArrayObject = nullptr;
4953 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
4954 {
4955 if (vertexArrayObject != nullptr)
4956 {
4957 detachVertexArray(vertexArray);
4958 vertexArrayObject->onDestroy(this);
4959 }
4960
4961 mVertexArrayHandleAllocator.release(vertexArray);
4962 }
4963 }
4964 }
4965}
4966
4967void Context::genVertexArrays(GLsizei n, GLuint *arrays)
4968{
4969 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
4970 {
4971 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
4972 mVertexArrayMap.assign(vertexArray, nullptr);
4973 arrays[arrayIndex] = vertexArray;
4974 }
4975}
4976
4977bool Context::isVertexArray(GLuint array)
4978{
4979 if (array == 0)
4980 {
4981 return GL_FALSE;
4982 }
4983
4984 VertexArray *vao = getVertexArray(array);
4985 return (vao != nullptr ? GL_TRUE : GL_FALSE);
4986}
4987
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04004988void Context::endTransformFeedback()
4989{
4990 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
4991 transformFeedback->end(this);
4992}
4993
4994void Context::transformFeedbackVaryings(GLuint program,
4995 GLsizei count,
4996 const GLchar *const *varyings,
4997 GLenum bufferMode)
4998{
4999 Program *programObject = getProgram(program);
5000 ASSERT(programObject);
5001 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
5002}
5003
5004void Context::getTransformFeedbackVarying(GLuint program,
5005 GLuint index,
5006 GLsizei bufSize,
5007 GLsizei *length,
5008 GLsizei *size,
5009 GLenum *type,
5010 GLchar *name)
5011{
5012 Program *programObject = getProgram(program);
5013 ASSERT(programObject);
5014 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
5015}
5016
5017void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
5018{
5019 for (int i = 0; i < n; i++)
5020 {
5021 GLuint transformFeedback = ids[i];
5022 if (transformFeedback == 0)
5023 {
5024 continue;
5025 }
5026
5027 TransformFeedback *transformFeedbackObject = nullptr;
5028 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
5029 {
5030 if (transformFeedbackObject != nullptr)
5031 {
5032 detachTransformFeedback(transformFeedback);
5033 transformFeedbackObject->release(this);
5034 }
5035
5036 mTransformFeedbackHandleAllocator.release(transformFeedback);
5037 }
5038 }
5039}
5040
5041void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
5042{
5043 for (int i = 0; i < n; i++)
5044 {
5045 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
5046 mTransformFeedbackMap.assign(transformFeedback, nullptr);
5047 ids[i] = transformFeedback;
5048 }
5049}
5050
5051bool Context::isTransformFeedback(GLuint id)
5052{
5053 if (id == 0)
5054 {
5055 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
5056 // returns FALSE
5057 return GL_FALSE;
5058 }
5059
5060 const TransformFeedback *transformFeedback = getTransformFeedback(id);
5061 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
5062}
5063
5064void Context::pauseTransformFeedback()
5065{
5066 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5067 transformFeedback->pause();
5068}
5069
5070void Context::resumeTransformFeedback()
5071{
5072 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5073 transformFeedback->resume();
5074}
5075
Jamie Madill12e957f2017-08-26 21:42:26 -04005076void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
5077{
5078 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04005079 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04005080}
5081
5082GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
5083{
5084 const Program *programObject = getProgram(program);
5085 return programObject->getFragDataLocation(name);
5086}
5087
5088void Context::getUniformIndices(GLuint program,
5089 GLsizei uniformCount,
5090 const GLchar *const *uniformNames,
5091 GLuint *uniformIndices)
5092{
5093 const Program *programObject = getProgram(program);
5094 if (!programObject->isLinked())
5095 {
5096 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5097 {
5098 uniformIndices[uniformId] = GL_INVALID_INDEX;
5099 }
5100 }
5101 else
5102 {
5103 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5104 {
5105 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
5106 }
5107 }
5108}
5109
5110void Context::getActiveUniformsiv(GLuint program,
5111 GLsizei uniformCount,
5112 const GLuint *uniformIndices,
5113 GLenum pname,
5114 GLint *params)
5115{
5116 const Program *programObject = getProgram(program);
5117 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5118 {
5119 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08005120 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04005121 }
5122}
5123
5124GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
5125{
5126 const Program *programObject = getProgram(program);
5127 return programObject->getUniformBlockIndex(uniformBlockName);
5128}
5129
5130void Context::getActiveUniformBlockiv(GLuint program,
5131 GLuint uniformBlockIndex,
5132 GLenum pname,
5133 GLint *params)
5134{
5135 const Program *programObject = getProgram(program);
5136 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
5137}
5138
5139void Context::getActiveUniformBlockName(GLuint program,
5140 GLuint uniformBlockIndex,
5141 GLsizei bufSize,
5142 GLsizei *length,
5143 GLchar *uniformBlockName)
5144{
5145 const Program *programObject = getProgram(program);
5146 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
5147}
5148
5149void Context::uniformBlockBinding(GLuint program,
5150 GLuint uniformBlockIndex,
5151 GLuint uniformBlockBinding)
5152{
5153 Program *programObject = getProgram(program);
5154 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
5155}
5156
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005157GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
5158{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005159 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
5160 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005161
Jamie Madill70b5bb02017-08-28 13:32:37 -04005162 Sync *syncObject = getSync(syncHandle);
5163 Error error = syncObject->set(condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005164 if (error.isError())
5165 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04005166 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005167 handleError(error);
5168 return nullptr;
5169 }
5170
Jamie Madill70b5bb02017-08-28 13:32:37 -04005171 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005172}
5173
5174GLboolean Context::isSync(GLsync sync)
5175{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005176 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005177}
5178
5179GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
5180{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005181 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005182
5183 GLenum result = GL_WAIT_FAILED;
5184 handleError(syncObject->clientWait(flags, timeout, &result));
5185 return result;
5186}
5187
5188void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
5189{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005190 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005191 handleError(syncObject->serverWait(flags, timeout));
5192}
5193
5194void Context::getInteger64v(GLenum pname, GLint64 *params)
5195{
5196 GLenum nativeType = GL_NONE;
5197 unsigned int numParams = 0;
5198 getQueryParameterInfo(pname, &nativeType, &numParams);
5199
5200 if (nativeType == GL_INT_64_ANGLEX)
5201 {
5202 getInteger64vImpl(pname, params);
5203 }
5204 else
5205 {
5206 CastStateValues(this, nativeType, pname, numParams, params);
5207 }
5208}
5209
Corentin Wallez336129f2017-10-17 15:55:40 -04005210void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04005211{
5212 Buffer *buffer = mGLState.getTargetBuffer(target);
5213 QueryBufferParameteri64v(buffer, pname, params);
5214}
5215
5216void Context::genSamplers(GLsizei count, GLuint *samplers)
5217{
5218 for (int i = 0; i < count; i++)
5219 {
5220 samplers[i] = mState.mSamplers->createSampler();
5221 }
5222}
5223
5224void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
5225{
5226 for (int i = 0; i < count; i++)
5227 {
5228 GLuint sampler = samplers[i];
5229
5230 if (mState.mSamplers->getSampler(sampler))
5231 {
5232 detachSampler(sampler);
5233 }
5234
5235 mState.mSamplers->deleteObject(this, sampler);
5236 }
5237}
5238
5239void Context::getInternalformativ(GLenum target,
5240 GLenum internalformat,
5241 GLenum pname,
5242 GLsizei bufSize,
5243 GLint *params)
5244{
5245 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
5246 QueryInternalFormativ(formatCaps, pname, bufSize, params);
5247}
5248
Jiajia Qin5451d532017-11-16 17:16:34 +08005249void Context::programUniform1i(GLuint program, GLint location, GLint v0)
5250{
5251 programUniform1iv(program, location, 1, &v0);
5252}
5253
5254void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
5255{
5256 GLint xy[2] = {v0, v1};
5257 programUniform2iv(program, location, 1, xy);
5258}
5259
5260void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
5261{
5262 GLint xyz[3] = {v0, v1, v2};
5263 programUniform3iv(program, location, 1, xyz);
5264}
5265
5266void Context::programUniform4i(GLuint program,
5267 GLint location,
5268 GLint v0,
5269 GLint v1,
5270 GLint v2,
5271 GLint v3)
5272{
5273 GLint xyzw[4] = {v0, v1, v2, v3};
5274 programUniform4iv(program, location, 1, xyzw);
5275}
5276
5277void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
5278{
5279 programUniform1uiv(program, location, 1, &v0);
5280}
5281
5282void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
5283{
5284 GLuint xy[2] = {v0, v1};
5285 programUniform2uiv(program, location, 1, xy);
5286}
5287
5288void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
5289{
5290 GLuint xyz[3] = {v0, v1, v2};
5291 programUniform3uiv(program, location, 1, xyz);
5292}
5293
5294void Context::programUniform4ui(GLuint program,
5295 GLint location,
5296 GLuint v0,
5297 GLuint v1,
5298 GLuint v2,
5299 GLuint v3)
5300{
5301 GLuint xyzw[4] = {v0, v1, v2, v3};
5302 programUniform4uiv(program, location, 1, xyzw);
5303}
5304
5305void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
5306{
5307 programUniform1fv(program, location, 1, &v0);
5308}
5309
5310void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
5311{
5312 GLfloat xy[2] = {v0, v1};
5313 programUniform2fv(program, location, 1, xy);
5314}
5315
5316void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
5317{
5318 GLfloat xyz[3] = {v0, v1, v2};
5319 programUniform3fv(program, location, 1, xyz);
5320}
5321
5322void Context::programUniform4f(GLuint program,
5323 GLint location,
5324 GLfloat v0,
5325 GLfloat v1,
5326 GLfloat v2,
5327 GLfloat v3)
5328{
5329 GLfloat xyzw[4] = {v0, v1, v2, v3};
5330 programUniform4fv(program, location, 1, xyzw);
5331}
5332
Jamie Madill81c2e252017-09-09 23:32:46 -04005333void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5334{
5335 Program *programObject = getProgram(program);
5336 ASSERT(programObject);
5337 if (programObject->setUniform1iv(location, count, value) ==
5338 Program::SetUniformResult::SamplerChanged)
5339 {
5340 mGLState.setObjectDirty(GL_PROGRAM);
5341 }
5342}
5343
Jiajia Qin5451d532017-11-16 17:16:34 +08005344void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5345{
5346 Program *programObject = getProgram(program);
5347 ASSERT(programObject);
5348 programObject->setUniform2iv(location, count, value);
5349}
5350
5351void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5352{
5353 Program *programObject = getProgram(program);
5354 ASSERT(programObject);
5355 programObject->setUniform3iv(location, count, value);
5356}
5357
5358void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5359{
5360 Program *programObject = getProgram(program);
5361 ASSERT(programObject);
5362 programObject->setUniform4iv(location, count, value);
5363}
5364
5365void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5366{
5367 Program *programObject = getProgram(program);
5368 ASSERT(programObject);
5369 programObject->setUniform1uiv(location, count, value);
5370}
5371
5372void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5373{
5374 Program *programObject = getProgram(program);
5375 ASSERT(programObject);
5376 programObject->setUniform2uiv(location, count, value);
5377}
5378
5379void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5380{
5381 Program *programObject = getProgram(program);
5382 ASSERT(programObject);
5383 programObject->setUniform3uiv(location, count, value);
5384}
5385
5386void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5387{
5388 Program *programObject = getProgram(program);
5389 ASSERT(programObject);
5390 programObject->setUniform4uiv(location, count, value);
5391}
5392
5393void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5394{
5395 Program *programObject = getProgram(program);
5396 ASSERT(programObject);
5397 programObject->setUniform1fv(location, count, value);
5398}
5399
5400void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5401{
5402 Program *programObject = getProgram(program);
5403 ASSERT(programObject);
5404 programObject->setUniform2fv(location, count, value);
5405}
5406
5407void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5408{
5409 Program *programObject = getProgram(program);
5410 ASSERT(programObject);
5411 programObject->setUniform3fv(location, count, value);
5412}
5413
5414void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5415{
5416 Program *programObject = getProgram(program);
5417 ASSERT(programObject);
5418 programObject->setUniform4fv(location, count, value);
5419}
5420
5421void Context::programUniformMatrix2fv(GLuint program,
5422 GLint location,
5423 GLsizei count,
5424 GLboolean transpose,
5425 const GLfloat *value)
5426{
5427 Program *programObject = getProgram(program);
5428 ASSERT(programObject);
5429 programObject->setUniformMatrix2fv(location, count, transpose, value);
5430}
5431
5432void Context::programUniformMatrix3fv(GLuint program,
5433 GLint location,
5434 GLsizei count,
5435 GLboolean transpose,
5436 const GLfloat *value)
5437{
5438 Program *programObject = getProgram(program);
5439 ASSERT(programObject);
5440 programObject->setUniformMatrix3fv(location, count, transpose, value);
5441}
5442
5443void Context::programUniformMatrix4fv(GLuint program,
5444 GLint location,
5445 GLsizei count,
5446 GLboolean transpose,
5447 const GLfloat *value)
5448{
5449 Program *programObject = getProgram(program);
5450 ASSERT(programObject);
5451 programObject->setUniformMatrix4fv(location, count, transpose, value);
5452}
5453
5454void Context::programUniformMatrix2x3fv(GLuint program,
5455 GLint location,
5456 GLsizei count,
5457 GLboolean transpose,
5458 const GLfloat *value)
5459{
5460 Program *programObject = getProgram(program);
5461 ASSERT(programObject);
5462 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
5463}
5464
5465void Context::programUniformMatrix3x2fv(GLuint program,
5466 GLint location,
5467 GLsizei count,
5468 GLboolean transpose,
5469 const GLfloat *value)
5470{
5471 Program *programObject = getProgram(program);
5472 ASSERT(programObject);
5473 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
5474}
5475
5476void Context::programUniformMatrix2x4fv(GLuint program,
5477 GLint location,
5478 GLsizei count,
5479 GLboolean transpose,
5480 const GLfloat *value)
5481{
5482 Program *programObject = getProgram(program);
5483 ASSERT(programObject);
5484 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
5485}
5486
5487void Context::programUniformMatrix4x2fv(GLuint program,
5488 GLint location,
5489 GLsizei count,
5490 GLboolean transpose,
5491 const GLfloat *value)
5492{
5493 Program *programObject = getProgram(program);
5494 ASSERT(programObject);
5495 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
5496}
5497
5498void Context::programUniformMatrix3x4fv(GLuint program,
5499 GLint location,
5500 GLsizei count,
5501 GLboolean transpose,
5502 const GLfloat *value)
5503{
5504 Program *programObject = getProgram(program);
5505 ASSERT(programObject);
5506 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
5507}
5508
5509void Context::programUniformMatrix4x3fv(GLuint program,
5510 GLint location,
5511 GLsizei count,
5512 GLboolean transpose,
5513 const GLfloat *value)
5514{
5515 Program *programObject = getProgram(program);
5516 ASSERT(programObject);
5517 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
5518}
5519
Jamie Madill81c2e252017-09-09 23:32:46 -04005520void Context::onTextureChange(const Texture *texture)
5521{
5522 // Conservatively assume all textures are dirty.
5523 // TODO(jmadill): More fine-grained update.
5524 mGLState.setObjectDirty(GL_TEXTURE);
5525}
5526
Yunchao Hea336b902017-08-02 16:05:21 +08005527void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
5528{
5529 for (int i = 0; i < count; i++)
5530 {
5531 pipelines[i] = createProgramPipeline();
5532 }
5533}
5534
5535void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
5536{
5537 for (int i = 0; i < count; i++)
5538 {
5539 if (pipelines[i] != 0)
5540 {
5541 deleteProgramPipeline(pipelines[i]);
5542 }
5543 }
5544}
5545
5546GLboolean Context::isProgramPipeline(GLuint pipeline)
5547{
5548 if (pipeline == 0)
5549 {
5550 return GL_FALSE;
5551 }
5552
5553 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
5554}
5555
Jamie Madillc29968b2016-01-20 11:17:23 -05005556} // namespace gl