blob: f5718f7efe6e319a31a2a970dfa8ca1341bbedf7 [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{
Lingfeng Yangb27b03a2018-02-19 13:38:48 -0800167 EGLAttrib attrib =
168 attribs.get(EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT, 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
Corentin Wallez99d492c2018-02-27 15:17:10 -0500313 Texture *zeroTexture2D = new Texture(mImplementation.get(), 0, TextureType::_2D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800314 mZeroTextures[TextureType::_2D].set(this, zeroTexture2D);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500315
Corentin Wallez99d492c2018-02-27 15:17:10 -0500316 Texture *zeroTextureCube = new Texture(mImplementation.get(), 0, TextureType::CubeMap);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800317 mZeroTextures[TextureType::CubeMap].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
Corentin Wallez99d492c2018-02-27 15:17:10 -0500322 Texture *zeroTexture3D = new Texture(mImplementation.get(), 0, TextureType::_3D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800323 mZeroTextures[TextureType::_3D].set(this, zeroTexture3D);
Geoff Lang76b10c92014-09-05 16:28:14 -0400324
Corentin Wallez99d492c2018-02-27 15:17:10 -0500325 Texture *zeroTexture2DArray = new Texture(mImplementation.get(), 0, TextureType::_2DArray);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800326 mZeroTextures[TextureType::_2DArray].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 =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500331 new Texture(mImplementation.get(), 0, TextureType::_2DMultisample);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800332 mZeroTextures[TextureType::_2DMultisample].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 {
Qin Jiajia339f65b2018-02-27 12:52:48 +0800336 bindBufferRange(BufferBinding::AtomicCounter, i, 0, 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 =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500349 new Texture(mImplementation.get(), 0, TextureType::Rectangle);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800350 mZeroTextures[TextureType::Rectangle].set(this, zeroTextureRectangle);
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400351 }
352
Geoff Lang4751aab2017-10-30 15:14:52 -0400353 if (nativeExtensions.eglImageExternal || nativeExtensions.eglStreamConsumerExternal)
Ian Ewellbda75592016-04-18 17:25:54 -0400354 {
Corentin Wallez99d492c2018-02-27 15:17:10 -0500355 Texture *zeroTextureExternal = new Texture(mImplementation.get(), 0, TextureType::External);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800356 mZeroTextures[TextureType::External].set(this, zeroTextureExternal);
Ian Ewellbda75592016-04-18 17:25:54 -0400357 }
358
Jamie Madill4928b7c2017-06-20 12:57:39 -0400359 mGLState.initializeZeroTextures(this, mZeroTextures);
Jamie Madille6382c32014-11-07 15:05:26 -0500360
Jamie Madill57a89722013-07-02 11:57:03 -0400361 bindVertexArray(0);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000362
Geoff Langeb66a6e2016-10-31 13:06:12 -0400363 if (getClientVersion() >= Version(3, 0))
Geoff Lang1a683462015-09-29 15:09:59 -0400364 {
365 // [OpenGL ES 3.0.2] section 2.14.1 pg 85:
366 // In the initial state, a default transform feedback object is bound and treated as
367 // a transform feedback object with a name of zero. That object is bound any time
368 // BindTransformFeedback is called with id of zero
Jamie Madillf0dcb8b2017-08-26 19:05:13 -0400369 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Geoff Lang1a683462015-09-29 15:09:59 -0400370 }
Geoff Langc8058452014-02-03 12:04:11 -0500371
Corentin Wallez336129f2017-10-17 15:55:40 -0400372 for (auto type : angle::AllEnums<BufferBinding>())
373 {
374 bindBuffer(type, 0);
375 }
376
377 bindRenderbuffer(GL_RENDERBUFFER, 0);
378
379 for (unsigned int i = 0; i < mCaps.maxUniformBufferBindings; i++)
380 {
381 bindBufferRange(BufferBinding::Uniform, i, 0, 0, -1);
382 }
383
Jamie Madillad9f24e2016-02-12 09:27:24 -0500384 // Initialize dirty bit masks
Jamie Madillc67323a2017-11-02 23:11:41 -0400385 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500386 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500387 // No dirty objects.
388
389 // Readpixels uses the pack state and read FBO
Jamie Madillc67323a2017-11-02 23:11:41 -0400390 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500391 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500392 mReadPixelsDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
393
394 mClearDirtyBits.set(State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED);
395 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
396 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR);
397 mClearDirtyBits.set(State::DIRTY_BIT_VIEWPORT);
398 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_COLOR);
399 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_DEPTH);
400 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_STENCIL);
401 mClearDirtyBits.set(State::DIRTY_BIT_COLOR_MASK);
402 mClearDirtyBits.set(State::DIRTY_BIT_DEPTH_MASK);
403 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT);
404 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_BACK);
405 mClearDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
406
407 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
408 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR);
Geoff Lang1d2c41d2016-10-19 16:14:46 -0700409 mBlitDirtyBits.set(State::DIRTY_BIT_FRAMEBUFFER_SRGB);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500410 mBlitDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
411 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
Jamie Madill437fa652016-05-03 15:13:24 -0400412
Xinghua Cao10a4d432017-11-28 14:46:26 +0800413 // TODO(xinghua.cao@intel.com): add other dirty bits and dirty objects.
414 mComputeDirtyBits.set(State::DIRTY_BIT_SHADER_STORAGE_BUFFER_BINDING);
415 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_BINDING);
416 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_EXECUTABLE);
417 mComputeDirtyBits.set(State::DIRTY_BIT_TEXTURE_BINDINGS);
418 mComputeDirtyBits.set(State::DIRTY_BIT_SAMPLER_BINDINGS);
Qin Jiajia62fcf622017-11-30 16:16:12 +0800419 mComputeDirtyBits.set(State::DIRTY_BIT_DISPATCH_INDIRECT_BUFFER_BINDING);
Xinghua Cao10a4d432017-11-28 14:46:26 +0800420
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400421 handleError(mImplementation->initialize());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000422}
423
Jamie Madill4928b7c2017-06-20 12:57:39 -0400424egl::Error Context::onDestroy(const egl::Display *display)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000425{
Corentin Wallez80b24112015-08-25 16:41:57 -0400426 for (auto fence : mFenceNVMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000427 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400428 SafeDelete(fence.second);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000429 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400430 mFenceNVMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000431
Corentin Wallez80b24112015-08-25 16:41:57 -0400432 for (auto query : mQueryMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000433 {
Geoff Langf0aa8422015-09-29 15:08:34 -0400434 if (query.second != nullptr)
435 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400436 query.second->release(this);
Geoff Langf0aa8422015-09-29 15:08:34 -0400437 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000438 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400439 mQueryMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000440
Corentin Wallez80b24112015-08-25 16:41:57 -0400441 for (auto vertexArray : mVertexArrayMap)
Jamie Madill57a89722013-07-02 11:57:03 -0400442 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400443 if (vertexArray.second)
444 {
445 vertexArray.second->onDestroy(this);
446 }
Jamie Madill57a89722013-07-02 11:57:03 -0400447 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400448 mVertexArrayMap.clear();
Jamie Madill57a89722013-07-02 11:57:03 -0400449
Corentin Wallez80b24112015-08-25 16:41:57 -0400450 for (auto transformFeedback : mTransformFeedbackMap)
Geoff Langc8058452014-02-03 12:04:11 -0500451 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500452 if (transformFeedback.second != nullptr)
453 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500454 transformFeedback.second->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500455 }
Geoff Langc8058452014-02-03 12:04:11 -0500456 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400457 mTransformFeedbackMap.clear();
Geoff Langc8058452014-02-03 12:04:11 -0500458
Jamie Madilldedd7b92014-11-05 16:30:36 -0500459 for (auto &zeroTexture : mZeroTextures)
Geoff Lang76b10c92014-09-05 16:28:14 -0400460 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800461 if (zeroTexture.get() != nullptr)
462 {
463 ANGLE_TRY(zeroTexture->onDestroy(this));
464 zeroTexture.set(this, nullptr);
465 }
Geoff Lang76b10c92014-09-05 16:28:14 -0400466 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000467
Corentin Wallezccab69d2017-01-27 16:57:15 -0500468 SafeDelete(mSurfacelessFramebuffer);
469
Jamie Madill4928b7c2017-06-20 12:57:39 -0400470 ANGLE_TRY(releaseSurface(display));
Jamie Madill2f348d22017-06-05 10:50:59 -0400471 releaseShaderCompiler();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500472
Jamie Madill4928b7c2017-06-20 12:57:39 -0400473 mGLState.reset(this);
474
Jamie Madill6c1f6712017-02-14 19:08:04 -0500475 mState.mBuffers->release(this);
476 mState.mShaderPrograms->release(this);
477 mState.mTextures->release(this);
478 mState.mRenderbuffers->release(this);
479 mState.mSamplers->release(this);
Jamie Madill70b5bb02017-08-28 13:32:37 -0400480 mState.mSyncs->release(this);
Jamie Madill6c1f6712017-02-14 19:08:04 -0500481 mState.mPaths->release(this);
482 mState.mFramebuffers->release(this);
Yunchao Hea336b902017-08-02 16:05:21 +0800483 mState.mPipelines->release(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400484
Jamie Madill76e471e2017-10-21 09:56:01 -0400485 mImplementation->onDestroy(this);
486
Jamie Madill4928b7c2017-06-20 12:57:39 -0400487 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000488}
489
Jamie Madill70ee0f62017-02-06 16:04:20 -0500490Context::~Context()
491{
492}
493
Jamie Madill4928b7c2017-06-20 12:57:39 -0400494egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000495{
Jamie Madill61e16b42017-06-19 11:13:23 -0400496 mCurrentDisplay = display;
497
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000498 if (!mHasBeenCurrent)
499 {
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000500 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500501 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400502 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000503
Corentin Wallezc295e512017-01-27 17:47:50 -0500504 int width = 0;
505 int height = 0;
506 if (surface != nullptr)
507 {
508 width = surface->getWidth();
509 height = surface->getHeight();
510 }
511
512 mGLState.setViewportParams(0, 0, width, height);
513 mGLState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000514
515 mHasBeenCurrent = true;
516 }
517
Jamie Madill1b94d432015-08-07 13:23:23 -0400518 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700519 mGLState.setAllDirtyBits();
Jamie Madill81c2e252017-09-09 23:32:46 -0400520 mGLState.setAllDirtyObjects();
Jamie Madill1b94d432015-08-07 13:23:23 -0400521
Jamie Madill4928b7c2017-06-20 12:57:39 -0400522 ANGLE_TRY(releaseSurface(display));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500523
524 Framebuffer *newDefault = nullptr;
525 if (surface != nullptr)
526 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400527 ANGLE_TRY(surface->setIsCurrent(this, true));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500528 mCurrentSurface = surface;
529 newDefault = surface->getDefaultFramebuffer();
530 }
531 else
532 {
533 if (mSurfacelessFramebuffer == nullptr)
534 {
535 mSurfacelessFramebuffer = new Framebuffer(mImplementation.get());
536 }
537
538 newDefault = mSurfacelessFramebuffer;
539 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000540
Corentin Wallez37c39792015-08-20 14:19:46 -0400541 // Update default framebuffer, the binding of the previous default
542 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400543 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700544 if (mGLState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400545 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700546 mGLState.setReadFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400547 }
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700548 if (mGLState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400549 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700550 mGLState.setDrawFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400551 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500552 mState.mFramebuffers->setDefaultFramebuffer(newDefault);
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400553 }
Ian Ewell292f0052016-02-04 10:37:32 -0500554
555 // Notify the renderer of a context switch
Jamie Madill4928b7c2017-06-20 12:57:39 -0400556 mImplementation->onMakeCurrent(this);
557 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000558}
559
Jamie Madill4928b7c2017-06-20 12:57:39 -0400560egl::Error Context::releaseSurface(const egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400561{
Corentin Wallez37c39792015-08-20 14:19:46 -0400562 // Remove the default framebuffer
Corentin Wallezc295e512017-01-27 17:47:50 -0500563 Framebuffer *currentDefault = nullptr;
564 if (mCurrentSurface != nullptr)
Corentin Wallez51706ea2015-08-07 14:39:22 -0400565 {
Corentin Wallezc295e512017-01-27 17:47:50 -0500566 currentDefault = mCurrentSurface->getDefaultFramebuffer();
567 }
568 else if (mSurfacelessFramebuffer != nullptr)
569 {
570 currentDefault = mSurfacelessFramebuffer;
Corentin Wallez51706ea2015-08-07 14:39:22 -0400571 }
572
Corentin Wallezc295e512017-01-27 17:47:50 -0500573 if (mGLState.getReadFramebuffer() == currentDefault)
574 {
575 mGLState.setReadFramebufferBinding(nullptr);
576 }
577 if (mGLState.getDrawFramebuffer() == currentDefault)
578 {
579 mGLState.setDrawFramebufferBinding(nullptr);
580 }
581 mState.mFramebuffers->setDefaultFramebuffer(nullptr);
582
583 if (mCurrentSurface)
584 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400585 ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
Corentin Wallezc295e512017-01-27 17:47:50 -0500586 mCurrentSurface = nullptr;
587 }
Jamie Madill4928b7c2017-06-20 12:57:39 -0400588
589 return egl::NoError();
Jamie Madill77a72f62015-04-14 11:18:32 -0400590}
591
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000592GLuint Context::createBuffer()
593{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500594 return mState.mBuffers->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000595}
596
597GLuint Context::createProgram()
598{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500599 return mState.mShaderPrograms->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000600}
601
602GLuint Context::createShader(GLenum type)
603{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500604 return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000605}
606
607GLuint Context::createTexture()
608{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500609 return mState.mTextures->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000610}
611
612GLuint Context::createRenderbuffer()
613{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500614 return mState.mRenderbuffers->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000615}
616
Sami Väisänene45e53b2016-05-25 10:36:04 +0300617GLuint Context::createPaths(GLsizei range)
618{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500619 auto resultOrError = mState.mPaths->createPaths(mImplementation.get(), range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300620 if (resultOrError.isError())
621 {
622 handleError(resultOrError.getError());
623 return 0;
624 }
625 return resultOrError.getResult();
626}
627
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000628// Returns an unused framebuffer name
629GLuint Context::createFramebuffer()
630{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500631 return mState.mFramebuffers->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000632}
633
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500634void Context::genFencesNV(GLsizei n, GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000635{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500636 for (int i = 0; i < n; i++)
637 {
638 GLuint handle = mFenceNVHandleAllocator.allocate();
639 mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV()));
640 fences[i] = handle;
641 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000642}
643
Yunchao Hea336b902017-08-02 16:05:21 +0800644GLuint Context::createProgramPipeline()
645{
646 return mState.mPipelines->createProgramPipeline();
647}
648
Jiajia Qin5451d532017-11-16 17:16:34 +0800649GLuint Context::createShaderProgramv(GLenum type, GLsizei count, const GLchar *const *strings)
650{
651 UNIMPLEMENTED();
652 return 0u;
653}
654
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000655void Context::deleteBuffer(GLuint buffer)
656{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500657 if (mState.mBuffers->getBuffer(buffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000658 {
659 detachBuffer(buffer);
660 }
Jamie Madill893ab082014-05-16 16:56:10 -0400661
Jamie Madill6c1f6712017-02-14 19:08:04 -0500662 mState.mBuffers->deleteObject(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000663}
664
665void Context::deleteShader(GLuint shader)
666{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500667 mState.mShaderPrograms->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000668}
669
670void Context::deleteProgram(GLuint program)
671{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500672 mState.mShaderPrograms->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000673}
674
675void Context::deleteTexture(GLuint texture)
676{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500677 if (mState.mTextures->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000678 {
679 detachTexture(texture);
680 }
681
Jamie Madill6c1f6712017-02-14 19:08:04 -0500682 mState.mTextures->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000683}
684
685void Context::deleteRenderbuffer(GLuint renderbuffer)
686{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500687 if (mState.mRenderbuffers->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000688 {
689 detachRenderbuffer(renderbuffer);
690 }
Jamie Madill893ab082014-05-16 16:56:10 -0400691
Jamie Madill6c1f6712017-02-14 19:08:04 -0500692 mState.mRenderbuffers->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000693}
694
Jamie Madill7f0c5a42017-08-26 22:43:26 -0400695void Context::deleteSync(GLsync sync)
Jamie Madillcd055f82013-07-26 11:55:15 -0400696{
697 // The spec specifies the underlying Fence object is not deleted until all current
698 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
699 // and since our API is currently designed for being called from a single thread, we can delete
700 // the fence immediately.
Jamie Madill70b5bb02017-08-28 13:32:37 -0400701 mState.mSyncs->deleteObject(this, static_cast<GLuint>(reinterpret_cast<uintptr_t>(sync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400702}
703
Yunchao Hea336b902017-08-02 16:05:21 +0800704void Context::deleteProgramPipeline(GLuint pipeline)
705{
706 if (mState.mPipelines->getProgramPipeline(pipeline))
707 {
708 detachProgramPipeline(pipeline);
709 }
710
711 mState.mPipelines->deleteObject(this, pipeline);
712}
713
Sami Väisänene45e53b2016-05-25 10:36:04 +0300714void Context::deletePaths(GLuint first, GLsizei range)
715{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500716 mState.mPaths->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300717}
718
719bool Context::hasPathData(GLuint path) const
720{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500721 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300722 if (pathObj == nullptr)
723 return false;
724
725 return pathObj->hasPathData();
726}
727
728bool Context::hasPath(GLuint path) const
729{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500730 return mState.mPaths->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300731}
732
733void Context::setPathCommands(GLuint path,
734 GLsizei numCommands,
735 const GLubyte *commands,
736 GLsizei numCoords,
737 GLenum coordType,
738 const void *coords)
739{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500740 auto *pathObject = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300741
742 handleError(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
743}
744
Jamie Madill007530e2017-12-28 14:27:04 -0500745void Context::pathParameterf(GLuint path, GLenum pname, GLfloat value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300746{
Jamie Madill007530e2017-12-28 14:27:04 -0500747 Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300748
749 switch (pname)
750 {
751 case GL_PATH_STROKE_WIDTH_CHROMIUM:
752 pathObj->setStrokeWidth(value);
753 break;
754 case GL_PATH_END_CAPS_CHROMIUM:
755 pathObj->setEndCaps(static_cast<GLenum>(value));
756 break;
757 case GL_PATH_JOIN_STYLE_CHROMIUM:
758 pathObj->setJoinStyle(static_cast<GLenum>(value));
759 break;
760 case GL_PATH_MITER_LIMIT_CHROMIUM:
761 pathObj->setMiterLimit(value);
762 break;
763 case GL_PATH_STROKE_BOUND_CHROMIUM:
764 pathObj->setStrokeBound(value);
765 break;
766 default:
767 UNREACHABLE();
768 break;
769 }
770}
771
Jamie Madill007530e2017-12-28 14:27:04 -0500772void Context::pathParameteri(GLuint path, GLenum pname, GLint value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300773{
Jamie Madill007530e2017-12-28 14:27:04 -0500774 // TODO(jmadill): Should use proper clamping/casting.
775 pathParameterf(path, pname, static_cast<GLfloat>(value));
776}
777
778void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value)
779{
780 const Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300781
782 switch (pname)
783 {
784 case GL_PATH_STROKE_WIDTH_CHROMIUM:
785 *value = pathObj->getStrokeWidth();
786 break;
787 case GL_PATH_END_CAPS_CHROMIUM:
788 *value = static_cast<GLfloat>(pathObj->getEndCaps());
789 break;
790 case GL_PATH_JOIN_STYLE_CHROMIUM:
791 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
792 break;
793 case GL_PATH_MITER_LIMIT_CHROMIUM:
794 *value = pathObj->getMiterLimit();
795 break;
796 case GL_PATH_STROKE_BOUND_CHROMIUM:
797 *value = pathObj->getStrokeBound();
798 break;
799 default:
800 UNREACHABLE();
801 break;
802 }
803}
804
Jamie Madill007530e2017-12-28 14:27:04 -0500805void Context::getPathParameteriv(GLuint path, GLenum pname, GLint *value)
806{
807 GLfloat val = 0.0f;
808 getPathParameterfv(path, pname, value != nullptr ? &val : nullptr);
809 if (value)
810 *value = static_cast<GLint>(val);
811}
812
Sami Väisänene45e53b2016-05-25 10:36:04 +0300813void Context::setPathStencilFunc(GLenum func, GLint ref, GLuint mask)
814{
815 mGLState.setPathStencilFunc(func, ref, mask);
816}
817
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000818void Context::deleteFramebuffer(GLuint framebuffer)
819{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500820 if (mState.mFramebuffers->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000821 {
822 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000823 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500824
Jamie Madill6c1f6712017-02-14 19:08:04 -0500825 mState.mFramebuffers->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000826}
827
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500828void Context::deleteFencesNV(GLsizei n, const GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000829{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500830 for (int i = 0; i < n; i++)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000831 {
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500832 GLuint fence = fences[i];
833
834 FenceNV *fenceObject = nullptr;
835 if (mFenceNVMap.erase(fence, &fenceObject))
836 {
837 mFenceNVHandleAllocator.release(fence);
838 delete fenceObject;
839 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000840 }
841}
842
Geoff Lang70d0f492015-12-10 17:45:46 -0500843Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000844{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500845 return mState.mBuffers->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000846}
847
Jamie Madill570f7c82014-07-03 10:38:54 -0400848Texture *Context::getTexture(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000849{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500850 return mState.mTextures->getTexture(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000851}
852
Geoff Lang70d0f492015-12-10 17:45:46 -0500853Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000854{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500855 return mState.mRenderbuffers->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000856}
857
Jamie Madill70b5bb02017-08-28 13:32:37 -0400858Sync *Context::getSync(GLsync handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400859{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400860 return mState.mSyncs->getSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400861}
862
Jamie Madill57a89722013-07-02 11:57:03 -0400863VertexArray *Context::getVertexArray(GLuint handle) const
864{
Jamie Madill96a483b2017-06-27 16:49:21 -0400865 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -0400866}
867
Jamie Madilldc356042013-07-19 16:36:57 -0400868Sampler *Context::getSampler(GLuint handle) const
869{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500870 return mState.mSamplers->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400871}
872
Geoff Langc8058452014-02-03 12:04:11 -0500873TransformFeedback *Context::getTransformFeedback(GLuint handle) const
874{
Jamie Madill96a483b2017-06-27 16:49:21 -0400875 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -0500876}
877
Yunchao Hea336b902017-08-02 16:05:21 +0800878ProgramPipeline *Context::getProgramPipeline(GLuint handle) const
879{
880 return mState.mPipelines->getProgramPipeline(handle);
881}
882
Geoff Lang70d0f492015-12-10 17:45:46 -0500883LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
884{
885 switch (identifier)
886 {
887 case GL_BUFFER:
888 return getBuffer(name);
889 case GL_SHADER:
890 return getShader(name);
891 case GL_PROGRAM:
892 return getProgram(name);
893 case GL_VERTEX_ARRAY:
894 return getVertexArray(name);
895 case GL_QUERY:
896 return getQuery(name);
897 case GL_TRANSFORM_FEEDBACK:
898 return getTransformFeedback(name);
899 case GL_SAMPLER:
900 return getSampler(name);
901 case GL_TEXTURE:
902 return getTexture(name);
903 case GL_RENDERBUFFER:
904 return getRenderbuffer(name);
905 case GL_FRAMEBUFFER:
906 return getFramebuffer(name);
907 default:
908 UNREACHABLE();
909 return nullptr;
910 }
911}
912
913LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
914{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400915 return getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
Geoff Lang70d0f492015-12-10 17:45:46 -0500916}
917
Martin Radev9d901792016-07-15 15:58:58 +0300918void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
919{
920 LabeledObject *object = getLabeledObject(identifier, name);
921 ASSERT(object != nullptr);
922
923 std::string labelName = GetObjectLabelFromPointer(length, label);
924 object->setLabel(labelName);
Jamie Madill8693bdb2017-09-02 15:32:14 -0400925
926 // TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the
927 // specified object is active until we do this.
928 mGLState.setObjectDirty(identifier);
Martin Radev9d901792016-07-15 15:58:58 +0300929}
930
931void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
932{
933 LabeledObject *object = getLabeledObjectFromPtr(ptr);
934 ASSERT(object != nullptr);
935
936 std::string labelName = GetObjectLabelFromPointer(length, label);
937 object->setLabel(labelName);
938}
939
940void Context::getObjectLabel(GLenum identifier,
941 GLuint name,
942 GLsizei bufSize,
943 GLsizei *length,
944 GLchar *label) const
945{
946 LabeledObject *object = getLabeledObject(identifier, name);
947 ASSERT(object != nullptr);
948
949 const std::string &objectLabel = object->getLabel();
950 GetObjectLabelBase(objectLabel, bufSize, length, label);
951}
952
953void Context::getObjectPtrLabel(const void *ptr,
954 GLsizei bufSize,
955 GLsizei *length,
956 GLchar *label) const
957{
958 LabeledObject *object = getLabeledObjectFromPtr(ptr);
959 ASSERT(object != nullptr);
960
961 const std::string &objectLabel = object->getLabel();
962 GetObjectLabelBase(objectLabel, bufSize, length, label);
963}
964
Jamie Madilldc356042013-07-19 16:36:57 -0400965bool Context::isSampler(GLuint samplerName) const
966{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500967 return mState.mSamplers->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -0400968}
969
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800970void Context::bindTexture(TextureType target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000971{
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500972 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000973
Jamie Madilldedd7b92014-11-05 16:30:36 -0500974 if (handle == 0)
975 {
976 texture = mZeroTextures[target].get();
977 }
978 else
979 {
Corentin Wallez99d492c2018-02-27 15:17:10 -0500980 texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500981 }
982
983 ASSERT(texture);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400984 mGLState.setSamplerTexture(this, target, texture);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +0000985}
986
Jamie Madill5bf9ff42016-02-01 11:13:03 -0500987void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000988{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500989 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
990 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700991 mGLState.setReadFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000992}
993
Jamie Madill5bf9ff42016-02-01 11:13:03 -0500994void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000995{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500996 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
997 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700998 mGLState.setDrawFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000999}
1000
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001001void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -04001002{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001003 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001004 mGLState.setVertexArrayBinding(vertexArray);
Jamie Madill57a89722013-07-02 11:57:03 -04001005}
1006
Shao80957d92017-02-20 21:25:59 +08001007void Context::bindVertexBuffer(GLuint bindingIndex,
1008 GLuint bufferHandle,
1009 GLintptr offset,
1010 GLsizei stride)
1011{
1012 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001013 mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Shao80957d92017-02-20 21:25:59 +08001014}
1015
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001016void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -04001017{
Geoff Lang76b10c92014-09-05 16:28:14 -04001018 ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -04001019 Sampler *sampler =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001020 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001021 mGLState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04001022}
1023
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001024void Context::bindImageTexture(GLuint unit,
1025 GLuint texture,
1026 GLint level,
1027 GLboolean layered,
1028 GLint layer,
1029 GLenum access,
1030 GLenum format)
1031{
1032 Texture *tex = mState.mTextures->getTexture(texture);
1033 mGLState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
1034}
1035
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001036void Context::useProgram(GLuint program)
1037{
Jamie Madill6c1f6712017-02-14 19:08:04 -05001038 mGLState.setProgram(this, getProgram(program));
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001039}
1040
Jiajia Qin5451d532017-11-16 17:16:34 +08001041void Context::useProgramStages(GLuint pipeline, GLbitfield stages, GLuint program)
1042{
1043 UNIMPLEMENTED();
1044}
1045
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001046void Context::bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001047{
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001048 ASSERT(target == GL_TRANSFORM_FEEDBACK);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001049 TransformFeedback *transformFeedback =
1050 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001051 mGLState.setTransformFeedbackBinding(this, transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -05001052}
1053
Yunchao Hea336b902017-08-02 16:05:21 +08001054void Context::bindProgramPipeline(GLuint pipelineHandle)
1055{
1056 ProgramPipeline *pipeline =
1057 mState.mPipelines->checkProgramPipelineAllocation(mImplementation.get(), pipelineHandle);
1058 mGLState.setProgramPipelineBinding(this, pipeline);
1059}
1060
Jamie Madillf0e04492017-08-26 15:28:42 -04001061void Context::beginQuery(GLenum target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001062{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001063 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001064 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001065
Geoff Lang5aad9672014-09-08 11:10:42 -04001066 // begin query
Jamie Madillf0e04492017-08-26 15:28:42 -04001067 ANGLE_CONTEXT_TRY(queryObject->begin());
Geoff Lang5aad9672014-09-08 11:10:42 -04001068
1069 // set query as active for specified target only if begin succeeded
Jamie Madill4928b7c2017-06-20 12:57:39 -04001070 mGLState.setActiveQuery(this, target, queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001071}
1072
Jamie Madillf0e04492017-08-26 15:28:42 -04001073void Context::endQuery(GLenum target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001074{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001075 Query *queryObject = mGLState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001076 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001077
Jamie Madillf0e04492017-08-26 15:28:42 -04001078 handleError(queryObject->end());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001079
Geoff Lang5aad9672014-09-08 11:10:42 -04001080 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madill4928b7c2017-06-20 12:57:39 -04001081 mGLState.setActiveQuery(this, target, nullptr);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001082}
1083
Jamie Madillf0e04492017-08-26 15:28:42 -04001084void Context::queryCounter(GLuint id, GLenum target)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001085{
1086 ASSERT(target == GL_TIMESTAMP_EXT);
1087
1088 Query *queryObject = getQuery(id, true, target);
1089 ASSERT(queryObject);
1090
Jamie Madillf0e04492017-08-26 15:28:42 -04001091 handleError(queryObject->queryCounter());
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001092}
1093
1094void Context::getQueryiv(GLenum target, GLenum pname, GLint *params)
1095{
1096 switch (pname)
1097 {
1098 case GL_CURRENT_QUERY_EXT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001099 params[0] = mGLState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001100 break;
1101 case GL_QUERY_COUNTER_BITS_EXT:
1102 switch (target)
1103 {
1104 case GL_TIME_ELAPSED_EXT:
1105 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1106 break;
1107 case GL_TIMESTAMP_EXT:
1108 params[0] = getExtensions().queryCounterBitsTimestamp;
1109 break;
1110 default:
1111 UNREACHABLE();
1112 params[0] = 0;
1113 break;
1114 }
1115 break;
1116 default:
1117 UNREACHABLE();
1118 return;
1119 }
1120}
1121
Geoff Lang2186c382016-10-14 10:54:54 -04001122void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001123{
Geoff Lang2186c382016-10-14 10:54:54 -04001124 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001125}
1126
Geoff Lang2186c382016-10-14 10:54:54 -04001127void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001128{
Geoff Lang2186c382016-10-14 10:54:54 -04001129 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001130}
1131
Geoff Lang2186c382016-10-14 10:54:54 -04001132void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001133{
Geoff Lang2186c382016-10-14 10:54:54 -04001134 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001135}
1136
Geoff Lang2186c382016-10-14 10:54:54 -04001137void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001138{
Geoff Lang2186c382016-10-14 10:54:54 -04001139 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001140}
1141
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001142Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001143{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001144 return mState.mFramebuffers->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001145}
1146
Jamie Madill2f348d22017-06-05 10:50:59 -04001147FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001148{
Jamie Madill96a483b2017-06-27 16:49:21 -04001149 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001150}
1151
Jamie Madill2f348d22017-06-05 10:50:59 -04001152Query *Context::getQuery(GLuint handle, bool create, GLenum type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001153{
Jamie Madill96a483b2017-06-27 16:49:21 -04001154 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001155 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001156 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001157 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001158
1159 Query *query = mQueryMap.query(handle);
1160 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001161 {
Jamie Madill96a483b2017-06-27 16:49:21 -04001162 query = new Query(mImplementation->createQuery(type), handle);
1163 query->addRef();
1164 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001165 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001166 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001167}
1168
Geoff Lang70d0f492015-12-10 17:45:46 -05001169Query *Context::getQuery(GLuint handle) const
1170{
Jamie Madill96a483b2017-06-27 16:49:21 -04001171 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001172}
1173
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001174Texture *Context::getTargetTexture(TextureType type) const
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001175{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001176 ASSERT(ValidTextureTarget(this, type) || ValidTextureExternalTarget(this, type));
1177 return mGLState.getTargetTexture(type);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001178}
1179
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001180Texture *Context::getSamplerTexture(unsigned int sampler, TextureType type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001181{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001182 return mGLState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001183}
1184
Geoff Lang492a7e42014-11-05 13:27:06 -05001185Compiler *Context::getCompiler() const
1186{
Jamie Madill2f348d22017-06-05 10:50:59 -04001187 if (mCompiler.get() == nullptr)
1188 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001189 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001190 }
1191 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001192}
1193
Jamie Madillc1d770e2017-04-13 17:31:24 -04001194void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001195{
1196 switch (pname)
1197 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001198 case GL_SHADER_COMPILER:
1199 *params = GL_TRUE;
1200 break;
1201 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1202 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1203 break;
1204 default:
1205 mGLState.getBooleanv(pname, params);
1206 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001207 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001208}
1209
Jamie Madillc1d770e2017-04-13 17:31:24 -04001210void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001211{
Shannon Woods53a94a82014-06-24 15:20:36 -04001212 // Queries about context capabilities and maximums are answered by Context.
1213 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001214 switch (pname)
1215 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001216 case GL_ALIASED_LINE_WIDTH_RANGE:
1217 params[0] = mCaps.minAliasedLineWidth;
1218 params[1] = mCaps.maxAliasedLineWidth;
1219 break;
1220 case GL_ALIASED_POINT_SIZE_RANGE:
1221 params[0] = mCaps.minAliasedPointSize;
1222 params[1] = mCaps.maxAliasedPointSize;
1223 break;
1224 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1225 ASSERT(mExtensions.textureFilterAnisotropic);
1226 *params = mExtensions.maxTextureAnisotropy;
1227 break;
1228 case GL_MAX_TEXTURE_LOD_BIAS:
1229 *params = mCaps.maxLODBias;
1230 break;
1231
1232 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1233 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1234 {
1235 ASSERT(mExtensions.pathRendering);
1236 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1237 memcpy(params, m, 16 * sizeof(GLfloat));
1238 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001239 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001240
Jamie Madill231c7f52017-04-26 13:45:37 -04001241 default:
1242 mGLState.getFloatv(pname, params);
1243 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001244 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001245}
1246
Jamie Madillc1d770e2017-04-13 17:31:24 -04001247void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001248{
Shannon Woods53a94a82014-06-24 15:20:36 -04001249 // Queries about context capabilities and maximums are answered by Context.
1250 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001251
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001252 switch (pname)
1253 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001254 case GL_MAX_VERTEX_ATTRIBS:
1255 *params = mCaps.maxVertexAttributes;
1256 break;
1257 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1258 *params = mCaps.maxVertexUniformVectors;
1259 break;
1260 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
1261 *params = mCaps.maxVertexUniformComponents;
1262 break;
1263 case GL_MAX_VARYING_VECTORS:
1264 *params = mCaps.maxVaryingVectors;
1265 break;
1266 case GL_MAX_VARYING_COMPONENTS:
1267 *params = mCaps.maxVertexOutputComponents;
1268 break;
1269 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1270 *params = mCaps.maxCombinedTextureImageUnits;
1271 break;
1272 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
1273 *params = mCaps.maxVertexTextureImageUnits;
1274 break;
1275 case GL_MAX_TEXTURE_IMAGE_UNITS:
1276 *params = mCaps.maxTextureImageUnits;
1277 break;
1278 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1279 *params = mCaps.maxFragmentUniformVectors;
1280 break;
1281 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
1282 *params = mCaps.maxFragmentUniformComponents;
1283 break;
1284 case GL_MAX_RENDERBUFFER_SIZE:
1285 *params = mCaps.maxRenderbufferSize;
1286 break;
1287 case GL_MAX_COLOR_ATTACHMENTS_EXT:
1288 *params = mCaps.maxColorAttachments;
1289 break;
1290 case GL_MAX_DRAW_BUFFERS_EXT:
1291 *params = mCaps.maxDrawBuffers;
1292 break;
1293 // case GL_FRAMEBUFFER_BINDING: // now equivalent to
1294 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
1295 case GL_SUBPIXEL_BITS:
1296 *params = 4;
1297 break;
1298 case GL_MAX_TEXTURE_SIZE:
1299 *params = mCaps.max2DTextureSize;
1300 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001301 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
1302 *params = mCaps.maxRectangleTextureSize;
1303 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001304 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1305 *params = mCaps.maxCubeMapTextureSize;
1306 break;
1307 case GL_MAX_3D_TEXTURE_SIZE:
1308 *params = mCaps.max3DTextureSize;
1309 break;
1310 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1311 *params = mCaps.maxArrayTextureLayers;
1312 break;
1313 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1314 *params = mCaps.uniformBufferOffsetAlignment;
1315 break;
1316 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1317 *params = mCaps.maxUniformBufferBindings;
1318 break;
1319 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
1320 *params = mCaps.maxVertexUniformBlocks;
1321 break;
1322 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
1323 *params = mCaps.maxFragmentUniformBlocks;
1324 break;
1325 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1326 *params = mCaps.maxCombinedTextureImageUnits;
1327 break;
1328 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1329 *params = mCaps.maxVertexOutputComponents;
1330 break;
1331 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1332 *params = mCaps.maxFragmentInputComponents;
1333 break;
1334 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1335 *params = mCaps.minProgramTexelOffset;
1336 break;
1337 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1338 *params = mCaps.maxProgramTexelOffset;
1339 break;
1340 case GL_MAJOR_VERSION:
1341 *params = getClientVersion().major;
1342 break;
1343 case GL_MINOR_VERSION:
1344 *params = getClientVersion().minor;
1345 break;
1346 case GL_MAX_ELEMENTS_INDICES:
1347 *params = mCaps.maxElementsIndices;
1348 break;
1349 case GL_MAX_ELEMENTS_VERTICES:
1350 *params = mCaps.maxElementsVertices;
1351 break;
1352 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1353 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1354 break;
1355 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1356 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1357 break;
1358 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1359 *params = mCaps.maxTransformFeedbackSeparateComponents;
1360 break;
1361 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1362 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1363 break;
1364 case GL_MAX_SAMPLES_ANGLE:
1365 *params = mCaps.maxSamples;
1366 break;
1367 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001368 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001369 params[0] = mCaps.maxViewportWidth;
1370 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001371 }
1372 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001373 case GL_COMPRESSED_TEXTURE_FORMATS:
1374 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1375 params);
1376 break;
1377 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1378 *params = mResetStrategy;
1379 break;
1380 case GL_NUM_SHADER_BINARY_FORMATS:
1381 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1382 break;
1383 case GL_SHADER_BINARY_FORMATS:
1384 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1385 break;
1386 case GL_NUM_PROGRAM_BINARY_FORMATS:
1387 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1388 break;
1389 case GL_PROGRAM_BINARY_FORMATS:
1390 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1391 break;
1392 case GL_NUM_EXTENSIONS:
1393 *params = static_cast<GLint>(mExtensionStrings.size());
1394 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001395
Jamie Madill231c7f52017-04-26 13:45:37 -04001396 // GL_KHR_debug
1397 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1398 *params = mExtensions.maxDebugMessageLength;
1399 break;
1400 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1401 *params = mExtensions.maxDebugLoggedMessages;
1402 break;
1403 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1404 *params = mExtensions.maxDebugGroupStackDepth;
1405 break;
1406 case GL_MAX_LABEL_LENGTH:
1407 *params = mExtensions.maxLabelLength;
1408 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001409
Martin Radeve5285d22017-07-14 16:23:53 +03001410 // GL_ANGLE_multiview
1411 case GL_MAX_VIEWS_ANGLE:
1412 *params = mExtensions.maxViews;
1413 break;
1414
Jamie Madill231c7f52017-04-26 13:45:37 -04001415 // GL_EXT_disjoint_timer_query
1416 case GL_GPU_DISJOINT_EXT:
1417 *params = mImplementation->getGPUDisjoint();
1418 break;
1419 case GL_MAX_FRAMEBUFFER_WIDTH:
1420 *params = mCaps.maxFramebufferWidth;
1421 break;
1422 case GL_MAX_FRAMEBUFFER_HEIGHT:
1423 *params = mCaps.maxFramebufferHeight;
1424 break;
1425 case GL_MAX_FRAMEBUFFER_SAMPLES:
1426 *params = mCaps.maxFramebufferSamples;
1427 break;
1428 case GL_MAX_SAMPLE_MASK_WORDS:
1429 *params = mCaps.maxSampleMaskWords;
1430 break;
1431 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1432 *params = mCaps.maxColorTextureSamples;
1433 break;
1434 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1435 *params = mCaps.maxDepthTextureSamples;
1436 break;
1437 case GL_MAX_INTEGER_SAMPLES:
1438 *params = mCaps.maxIntegerSamples;
1439 break;
1440 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1441 *params = mCaps.maxVertexAttribRelativeOffset;
1442 break;
1443 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1444 *params = mCaps.maxVertexAttribBindings;
1445 break;
1446 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1447 *params = mCaps.maxVertexAttribStride;
1448 break;
1449 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
1450 *params = mCaps.maxVertexAtomicCounterBuffers;
1451 break;
1452 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
1453 *params = mCaps.maxVertexAtomicCounters;
1454 break;
1455 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
1456 *params = mCaps.maxVertexImageUniforms;
1457 break;
1458 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
1459 *params = mCaps.maxVertexShaderStorageBlocks;
1460 break;
1461 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
1462 *params = mCaps.maxFragmentAtomicCounterBuffers;
1463 break;
1464 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
1465 *params = mCaps.maxFragmentAtomicCounters;
1466 break;
1467 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
1468 *params = mCaps.maxFragmentImageUniforms;
1469 break;
1470 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
1471 *params = mCaps.maxFragmentShaderStorageBlocks;
1472 break;
1473 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1474 *params = mCaps.minProgramTextureGatherOffset;
1475 break;
1476 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1477 *params = mCaps.maxProgramTextureGatherOffset;
1478 break;
1479 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1480 *params = mCaps.maxComputeWorkGroupInvocations;
1481 break;
1482 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
1483 *params = mCaps.maxComputeUniformBlocks;
1484 break;
1485 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
1486 *params = mCaps.maxComputeTextureImageUnits;
1487 break;
1488 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1489 *params = mCaps.maxComputeSharedMemorySize;
1490 break;
1491 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
1492 *params = mCaps.maxComputeUniformComponents;
1493 break;
1494 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
1495 *params = mCaps.maxComputeAtomicCounterBuffers;
1496 break;
1497 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
1498 *params = mCaps.maxComputeAtomicCounters;
1499 break;
1500 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
1501 *params = mCaps.maxComputeImageUniforms;
1502 break;
1503 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
1504 *params = mCaps.maxCombinedComputeUniformComponents;
1505 break;
1506 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
1507 *params = mCaps.maxComputeShaderStorageBlocks;
1508 break;
1509 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1510 *params = mCaps.maxCombinedShaderOutputResources;
1511 break;
1512 case GL_MAX_UNIFORM_LOCATIONS:
1513 *params = mCaps.maxUniformLocations;
1514 break;
1515 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1516 *params = mCaps.maxAtomicCounterBufferBindings;
1517 break;
1518 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1519 *params = mCaps.maxAtomicCounterBufferSize;
1520 break;
1521 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1522 *params = mCaps.maxCombinedAtomicCounterBuffers;
1523 break;
1524 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1525 *params = mCaps.maxCombinedAtomicCounters;
1526 break;
1527 case GL_MAX_IMAGE_UNITS:
1528 *params = mCaps.maxImageUnits;
1529 break;
1530 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1531 *params = mCaps.maxCombinedImageUniforms;
1532 break;
1533 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1534 *params = mCaps.maxShaderStorageBufferBindings;
1535 break;
1536 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1537 *params = mCaps.maxCombinedShaderStorageBlocks;
1538 break;
1539 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1540 *params = mCaps.shaderStorageBufferOffsetAlignment;
1541 break;
Jiawei Shao361df072017-11-22 09:33:59 +08001542
1543 // GL_EXT_geometry_shader
1544 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
1545 *params = mCaps.maxFramebufferLayers;
1546 break;
1547 case GL_LAYER_PROVOKING_VERTEX_EXT:
1548 *params = mCaps.layerProvokingVertex;
1549 break;
1550 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
1551 *params = mCaps.maxGeometryUniformComponents;
1552 break;
1553 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
1554 *params = mCaps.maxGeometryUniformBlocks;
1555 break;
1556 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
1557 *params = mCaps.maxCombinedGeometryUniformComponents;
1558 break;
1559 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
1560 *params = mCaps.maxGeometryInputComponents;
1561 break;
1562 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
1563 *params = mCaps.maxGeometryOutputComponents;
1564 break;
1565 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
1566 *params = mCaps.maxGeometryOutputVertices;
1567 break;
1568 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
1569 *params = mCaps.maxGeometryTotalOutputComponents;
1570 break;
1571 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
1572 *params = mCaps.maxGeometryShaderInvocations;
1573 break;
1574 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
1575 *params = mCaps.maxGeometryTextureImageUnits;
1576 break;
1577 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
1578 *params = mCaps.maxGeometryAtomicCounterBuffers;
1579 break;
1580 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
1581 *params = mCaps.maxGeometryAtomicCounters;
1582 break;
1583 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
1584 *params = mCaps.maxGeometryImageUniforms;
1585 break;
1586 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
1587 *params = mCaps.maxGeometryShaderStorageBlocks;
1588 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001589 default:
1590 mGLState.getIntegerv(this, pname, params);
1591 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001592 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001593}
1594
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001595void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001596{
Shannon Woods53a94a82014-06-24 15:20:36 -04001597 // Queries about context capabilities and maximums are answered by Context.
1598 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001599 switch (pname)
1600 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001601 case GL_MAX_ELEMENT_INDEX:
1602 *params = mCaps.maxElementIndex;
1603 break;
1604 case GL_MAX_UNIFORM_BLOCK_SIZE:
1605 *params = mCaps.maxUniformBlockSize;
1606 break;
1607 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
1608 *params = mCaps.maxCombinedVertexUniformComponents;
1609 break;
1610 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
1611 *params = mCaps.maxCombinedFragmentUniformComponents;
1612 break;
1613 case GL_MAX_SERVER_WAIT_TIMEOUT:
1614 *params = mCaps.maxServerWaitTimeout;
1615 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001616
Jamie Madill231c7f52017-04-26 13:45:37 -04001617 // GL_EXT_disjoint_timer_query
1618 case GL_TIMESTAMP_EXT:
1619 *params = mImplementation->getTimestamp();
1620 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001621
Jamie Madill231c7f52017-04-26 13:45:37 -04001622 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1623 *params = mCaps.maxShaderStorageBlockSize;
1624 break;
1625 default:
1626 UNREACHABLE();
1627 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001628 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001629}
1630
Geoff Lang70d0f492015-12-10 17:45:46 -05001631void Context::getPointerv(GLenum pname, void **params) const
1632{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001633 mGLState.getPointerv(pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001634}
1635
Martin Radev66fb8202016-07-28 11:45:20 +03001636void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001637{
Shannon Woods53a94a82014-06-24 15:20:36 -04001638 // Queries about context capabilities and maximums are answered by Context.
1639 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001640
1641 GLenum nativeType;
1642 unsigned int numParams;
1643 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1644 ASSERT(queryStatus);
1645
1646 if (nativeType == GL_INT)
1647 {
1648 switch (target)
1649 {
1650 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1651 ASSERT(index < 3u);
1652 *data = mCaps.maxComputeWorkGroupCount[index];
1653 break;
1654 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1655 ASSERT(index < 3u);
1656 *data = mCaps.maxComputeWorkGroupSize[index];
1657 break;
1658 default:
1659 mGLState.getIntegeri_v(target, index, data);
1660 }
1661 }
1662 else
1663 {
1664 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1665 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001666}
1667
Martin Radev66fb8202016-07-28 11:45:20 +03001668void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001669{
Shannon Woods53a94a82014-06-24 15:20:36 -04001670 // Queries about context capabilities and maximums are answered by Context.
1671 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001672
1673 GLenum nativeType;
1674 unsigned int numParams;
1675 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1676 ASSERT(queryStatus);
1677
1678 if (nativeType == GL_INT_64_ANGLEX)
1679 {
1680 mGLState.getInteger64i_v(target, index, data);
1681 }
1682 else
1683 {
1684 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1685 }
1686}
1687
1688void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1689{
1690 // Queries about context capabilities and maximums are answered by Context.
1691 // Queries about current GL state values are answered by State.
1692
1693 GLenum nativeType;
1694 unsigned int numParams;
1695 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1696 ASSERT(queryStatus);
1697
1698 if (nativeType == GL_BOOL)
1699 {
1700 mGLState.getBooleani_v(target, index, data);
1701 }
1702 else
1703 {
1704 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1705 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001706}
1707
Corentin Wallez336129f2017-10-17 15:55:40 -04001708void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001709{
1710 Buffer *buffer = mGLState.getTargetBuffer(target);
1711 QueryBufferParameteriv(buffer, pname, params);
1712}
1713
1714void Context::getFramebufferAttachmentParameteriv(GLenum target,
1715 GLenum attachment,
1716 GLenum pname,
1717 GLint *params)
1718{
1719 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08001720 QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08001721}
1722
1723void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
1724{
1725 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
1726 QueryRenderbufferiv(this, renderbuffer, pname, params);
1727}
1728
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001729void Context::getTexParameterfv(TextureType target, GLenum pname, GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001730{
1731 Texture *texture = getTargetTexture(target);
1732 QueryTexParameterfv(texture, pname, params);
1733}
1734
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001735void Context::getTexParameteriv(TextureType target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001736{
1737 Texture *texture = getTargetTexture(target);
1738 QueryTexParameteriv(texture, pname, params);
1739}
Jiajia Qin5451d532017-11-16 17:16:34 +08001740
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001741void Context::getTexLevelParameteriv(TextureTarget target, GLint level, GLenum pname, GLint *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08001742{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001743 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05001744 QueryTexLevelParameteriv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08001745}
1746
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001747void Context::getTexLevelParameterfv(TextureTarget target,
1748 GLint level,
1749 GLenum pname,
1750 GLfloat *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08001751{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001752 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05001753 QueryTexLevelParameterfv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08001754}
1755
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001756void Context::texParameterf(TextureType target, GLenum pname, GLfloat param)
He Yunchao010e4db2017-03-03 14:22:06 +08001757{
1758 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001759 SetTexParameterf(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04001760 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001761}
1762
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001763void Context::texParameterfv(TextureType target, GLenum pname, const GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001764{
1765 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001766 SetTexParameterfv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04001767 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001768}
1769
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001770void Context::texParameteri(TextureType target, GLenum pname, GLint param)
He Yunchao010e4db2017-03-03 14:22:06 +08001771{
1772 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001773 SetTexParameteri(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04001774 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001775}
1776
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001777void Context::texParameteriv(TextureType target, GLenum pname, const GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001778{
1779 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001780 SetTexParameteriv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04001781 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001782}
1783
Jamie Madill675fe712016-12-19 13:07:54 -05001784void Context::drawArrays(GLenum mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001785{
Jamie Madill9fdaa492018-02-16 10:52:11 -05001786 // No-op if zero count
1787 if (count == 0)
1788 {
1789 return;
1790 }
1791
Jamie Madill05b35b22017-10-03 09:01:44 -04001792 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001793 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
1794 MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001795}
1796
Jamie Madill675fe712016-12-19 13:07:54 -05001797void Context::drawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04001798{
Jamie Madill9fdaa492018-02-16 10:52:11 -05001799 // No-op if zero count
1800 if (count == 0 || instanceCount == 0)
1801 {
1802 return;
1803 }
1804
Jamie Madill05b35b22017-10-03 09:01:44 -04001805 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001806 ANGLE_CONTEXT_TRY(
1807 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
1808 MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback());
Geoff Langf6db0982015-08-25 13:04:00 -04001809}
1810
Jamie Madill876429b2017-04-20 15:46:24 -04001811void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001812{
Jamie Madill9fdaa492018-02-16 10:52:11 -05001813 // No-op if zero count
1814 if (count == 0)
1815 {
1816 return;
1817 }
1818
Jamie Madill05b35b22017-10-03 09:01:44 -04001819 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001820 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04001821}
1822
Jamie Madill675fe712016-12-19 13:07:54 -05001823void Context::drawElementsInstanced(GLenum mode,
1824 GLsizei count,
1825 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04001826 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04001827 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04001828{
Jamie Madill9fdaa492018-02-16 10:52:11 -05001829 // No-op if zero count
1830 if (count == 0 || instances == 0)
1831 {
1832 return;
1833 }
1834
Jamie Madill05b35b22017-10-03 09:01:44 -04001835 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001836 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08001837 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04001838}
1839
Jamie Madill675fe712016-12-19 13:07:54 -05001840void Context::drawRangeElements(GLenum mode,
1841 GLuint start,
1842 GLuint end,
1843 GLsizei count,
1844 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04001845 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04001846{
Jamie Madill9fdaa492018-02-16 10:52:11 -05001847 // No-op if zero count
1848 if (count == 0)
1849 {
1850 return;
1851 }
1852
Jamie Madill05b35b22017-10-03 09:01:44 -04001853 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001854 ANGLE_CONTEXT_TRY(
1855 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001856}
1857
Jamie Madill876429b2017-04-20 15:46:24 -04001858void Context::drawArraysIndirect(GLenum mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08001859{
Jamie Madill05b35b22017-10-03 09:01:44 -04001860 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001861 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08001862}
1863
Jamie Madill876429b2017-04-20 15:46:24 -04001864void Context::drawElementsIndirect(GLenum mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08001865{
Jamie Madill05b35b22017-10-03 09:01:44 -04001866 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001867 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08001868}
1869
Jamie Madill675fe712016-12-19 13:07:54 -05001870void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001871{
Jamie Madillafa02a22017-11-23 12:57:38 -05001872 handleError(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05001873}
1874
Jamie Madill675fe712016-12-19 13:07:54 -05001875void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05001876{
Jamie Madillafa02a22017-11-23 12:57:38 -05001877 handleError(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001878}
1879
Austin Kinross6ee1e782015-05-29 17:05:37 -07001880void Context::insertEventMarker(GLsizei length, const char *marker)
1881{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001882 ASSERT(mImplementation);
1883 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07001884}
1885
1886void Context::pushGroupMarker(GLsizei length, const char *marker)
1887{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001888 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05001889
1890 if (marker == nullptr)
1891 {
1892 // From the EXT_debug_marker spec,
1893 // "If <marker> is null then an empty string is pushed on the stack."
1894 mImplementation->pushGroupMarker(length, "");
1895 }
1896 else
1897 {
1898 mImplementation->pushGroupMarker(length, marker);
1899 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07001900}
1901
1902void Context::popGroupMarker()
1903{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001904 ASSERT(mImplementation);
1905 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07001906}
1907
Geoff Langd8605522016-04-13 10:19:12 -04001908void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
1909{
1910 Program *programObject = getProgram(program);
1911 ASSERT(programObject);
1912
1913 programObject->bindUniformLocation(location, name);
1914}
1915
Sami Väisänena797e062016-05-12 15:23:40 +03001916void Context::setCoverageModulation(GLenum components)
1917{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001918 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03001919}
1920
Sami Väisänene45e53b2016-05-25 10:36:04 +03001921void Context::loadPathRenderingMatrix(GLenum matrixMode, const GLfloat *matrix)
1922{
1923 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
1924}
1925
1926void Context::loadPathRenderingIdentityMatrix(GLenum matrixMode)
1927{
1928 GLfloat I[16];
1929 angle::Matrix<GLfloat>::setToIdentity(I);
1930
1931 mGLState.loadPathRenderingMatrix(matrixMode, I);
1932}
1933
1934void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
1935{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001936 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001937 if (!pathObj)
1938 return;
1939
1940 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Jamie Madillbc918e72018-03-08 09:47:21 -05001941 ANGLE_CONTEXT_TRY(syncRendererState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03001942
1943 mImplementation->stencilFillPath(pathObj, fillMode, mask);
1944}
1945
1946void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
1947{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001948 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001949 if (!pathObj)
1950 return;
1951
1952 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Jamie Madillbc918e72018-03-08 09:47:21 -05001953 ANGLE_CONTEXT_TRY(syncRendererState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03001954
1955 mImplementation->stencilStrokePath(pathObj, reference, mask);
1956}
1957
1958void Context::coverFillPath(GLuint path, GLenum coverMode)
1959{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001960 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001961 if (!pathObj)
1962 return;
1963
1964 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Jamie Madillbc918e72018-03-08 09:47:21 -05001965 ANGLE_CONTEXT_TRY(syncRendererState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03001966
1967 mImplementation->coverFillPath(pathObj, coverMode);
1968}
1969
1970void Context::coverStrokePath(GLuint path, GLenum coverMode)
1971{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001972 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001973 if (!pathObj)
1974 return;
1975
1976 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Jamie Madillbc918e72018-03-08 09:47:21 -05001977 ANGLE_CONTEXT_TRY(syncRendererState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03001978
1979 mImplementation->coverStrokePath(pathObj, coverMode);
1980}
1981
1982void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
1983{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001984 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001985 if (!pathObj)
1986 return;
1987
1988 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Jamie Madillbc918e72018-03-08 09:47:21 -05001989 ANGLE_CONTEXT_TRY(syncRendererState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03001990
1991 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
1992}
1993
1994void Context::stencilThenCoverStrokePath(GLuint path,
1995 GLint reference,
1996 GLuint mask,
1997 GLenum coverMode)
1998{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001999 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002000 if (!pathObj)
2001 return;
2002
2003 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Jamie Madillbc918e72018-03-08 09:47:21 -05002004 ANGLE_CONTEXT_TRY(syncRendererState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002005
2006 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2007}
2008
Sami Väisänend59ca052016-06-21 16:10:00 +03002009void Context::coverFillPathInstanced(GLsizei numPaths,
2010 GLenum pathNameType,
2011 const void *paths,
2012 GLuint pathBase,
2013 GLenum coverMode,
2014 GLenum transformType,
2015 const GLfloat *transformValues)
2016{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002017 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002018
2019 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Jamie Madillbc918e72018-03-08 09:47:21 -05002020 ANGLE_CONTEXT_TRY(syncRendererState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002021
2022 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2023}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002024
Sami Väisänend59ca052016-06-21 16:10:00 +03002025void Context::coverStrokePathInstanced(GLsizei numPaths,
2026 GLenum pathNameType,
2027 const void *paths,
2028 GLuint pathBase,
2029 GLenum coverMode,
2030 GLenum transformType,
2031 const GLfloat *transformValues)
2032{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002033 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002034
2035 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Jamie Madillbc918e72018-03-08 09:47:21 -05002036 ANGLE_CONTEXT_TRY(syncRendererState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002037
2038 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2039 transformValues);
2040}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002041
Sami Väisänend59ca052016-06-21 16:10:00 +03002042void Context::stencilFillPathInstanced(GLsizei numPaths,
2043 GLenum pathNameType,
2044 const void *paths,
2045 GLuint pathBase,
2046 GLenum fillMode,
2047 GLuint mask,
2048 GLenum transformType,
2049 const GLfloat *transformValues)
2050{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002051 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002052
2053 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Jamie Madillbc918e72018-03-08 09:47:21 -05002054 ANGLE_CONTEXT_TRY(syncRendererState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002055
2056 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2057 transformValues);
2058}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002059
Sami Väisänend59ca052016-06-21 16:10:00 +03002060void Context::stencilStrokePathInstanced(GLsizei numPaths,
2061 GLenum pathNameType,
2062 const void *paths,
2063 GLuint pathBase,
2064 GLint reference,
2065 GLuint mask,
2066 GLenum transformType,
2067 const GLfloat *transformValues)
2068{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002069 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002070
2071 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Jamie Madillbc918e72018-03-08 09:47:21 -05002072 ANGLE_CONTEXT_TRY(syncRendererState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002073
2074 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2075 transformValues);
2076}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002077
Sami Väisänend59ca052016-06-21 16:10:00 +03002078void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2079 GLenum pathNameType,
2080 const void *paths,
2081 GLuint pathBase,
2082 GLenum fillMode,
2083 GLuint mask,
2084 GLenum coverMode,
2085 GLenum transformType,
2086 const GLfloat *transformValues)
2087{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002088 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002089
2090 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Jamie Madillbc918e72018-03-08 09:47:21 -05002091 ANGLE_CONTEXT_TRY(syncRendererState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002092
2093 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2094 transformType, transformValues);
2095}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002096
Sami Väisänend59ca052016-06-21 16:10:00 +03002097void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2098 GLenum pathNameType,
2099 const void *paths,
2100 GLuint pathBase,
2101 GLint reference,
2102 GLuint mask,
2103 GLenum coverMode,
2104 GLenum transformType,
2105 const GLfloat *transformValues)
2106{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002107 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002108
2109 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Jamie Madillbc918e72018-03-08 09:47:21 -05002110 ANGLE_CONTEXT_TRY(syncRendererState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002111
2112 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2113 transformType, transformValues);
2114}
2115
Sami Väisänen46eaa942016-06-29 10:26:37 +03002116void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2117{
2118 auto *programObject = getProgram(program);
2119
2120 programObject->bindFragmentInputLocation(location, name);
2121}
2122
2123void Context::programPathFragmentInputGen(GLuint program,
2124 GLint location,
2125 GLenum genMode,
2126 GLint components,
2127 const GLfloat *coeffs)
2128{
2129 auto *programObject = getProgram(program);
2130
Jamie Madillbd044ed2017-06-05 12:59:21 -04002131 programObject->pathFragmentInputGen(this, location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002132}
2133
jchen1015015f72017-03-16 13:54:21 +08002134GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2135{
jchen10fd7c3b52017-03-21 15:36:03 +08002136 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002137 return QueryProgramResourceIndex(programObject, programInterface, name);
2138}
2139
jchen10fd7c3b52017-03-21 15:36:03 +08002140void Context::getProgramResourceName(GLuint program,
2141 GLenum programInterface,
2142 GLuint index,
2143 GLsizei bufSize,
2144 GLsizei *length,
2145 GLchar *name)
2146{
2147 const auto *programObject = getProgram(program);
2148 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2149}
2150
jchen10191381f2017-04-11 13:59:04 +08002151GLint Context::getProgramResourceLocation(GLuint program,
2152 GLenum programInterface,
2153 const GLchar *name)
2154{
2155 const auto *programObject = getProgram(program);
2156 return QueryProgramResourceLocation(programObject, programInterface, name);
2157}
2158
jchen10880683b2017-04-12 16:21:55 +08002159void Context::getProgramResourceiv(GLuint program,
2160 GLenum programInterface,
2161 GLuint index,
2162 GLsizei propCount,
2163 const GLenum *props,
2164 GLsizei bufSize,
2165 GLsizei *length,
2166 GLint *params)
2167{
2168 const auto *programObject = getProgram(program);
2169 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2170 length, params);
2171}
2172
jchen10d9cd7b72017-08-30 15:04:25 +08002173void Context::getProgramInterfaceiv(GLuint program,
2174 GLenum programInterface,
2175 GLenum pname,
2176 GLint *params)
2177{
2178 const auto *programObject = getProgram(program);
2179 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2180}
2181
Jamie Madill71c88b32017-09-14 22:20:29 -04002182void Context::handleError(const Error &error)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002183{
Geoff Langda5777c2014-07-11 09:52:58 -04002184 if (error.isError())
2185 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002186 GLenum code = error.getCode();
2187 mErrors.insert(code);
2188 if (code == GL_OUT_OF_MEMORY && getWorkarounds().loseContextOnOutOfMemory)
2189 {
2190 markContextLost();
2191 }
Geoff Lang70d0f492015-12-10 17:45:46 -05002192
Geoff Langee6884e2017-11-09 16:51:11 -05002193 ASSERT(!error.getMessage().empty());
2194 mGLState.getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, error.getID(),
2195 GL_DEBUG_SEVERITY_HIGH, error.getMessage());
Geoff Langda5777c2014-07-11 09:52:58 -04002196 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002197}
2198
2199// Get one of the recorded errors and clear its flag, if any.
2200// [OpenGL ES 2.0.24] section 2.5 page 13.
2201GLenum Context::getError()
2202{
Geoff Langda5777c2014-07-11 09:52:58 -04002203 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002204 {
Geoff Langda5777c2014-07-11 09:52:58 -04002205 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002206 }
Geoff Langda5777c2014-07-11 09:52:58 -04002207 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002208 {
Geoff Langda5777c2014-07-11 09:52:58 -04002209 GLenum error = *mErrors.begin();
2210 mErrors.erase(mErrors.begin());
2211 return error;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002212 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002213}
2214
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002215// NOTE: this function should not assume that this context is current!
2216void Context::markContextLost()
2217{
2218 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002219 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002220 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002221 mContextLostForced = true;
2222 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002223 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002224}
2225
2226bool Context::isContextLost()
2227{
2228 return mContextLost;
2229}
2230
Jamie Madillfa920eb2018-01-04 11:45:50 -05002231GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002232{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002233 // Even if the application doesn't want to know about resets, we want to know
2234 // as it will allow us to skip all the calls.
2235 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002236 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002237 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002238 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002239 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002240 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002241
2242 // EXT_robustness, section 2.6: If the reset notification behavior is
2243 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2244 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2245 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002246 }
2247
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002248 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2249 // status should be returned at least once, and GL_NO_ERROR should be returned
2250 // once the device has finished resetting.
2251 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002252 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002253 ASSERT(mResetStatus == GL_NO_ERROR);
2254 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002255
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002256 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002257 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002258 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002259 }
2260 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002261 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002262 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002263 // If markContextLost was used to mark the context lost then
2264 // assume that is not recoverable, and continue to report the
2265 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002266 mResetStatus = mImplementation->getResetStatus();
2267 }
Jamie Madill893ab082014-05-16 16:56:10 -04002268
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002269 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002270}
2271
2272bool Context::isResetNotificationEnabled()
2273{
2274 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2275}
2276
Corentin Walleze3b10e82015-05-20 11:06:25 -04002277const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002278{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002279 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002280}
2281
2282EGLenum Context::getClientType() const
2283{
2284 return mClientType;
2285}
2286
2287EGLenum Context::getRenderBuffer() const
2288{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002289 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2290 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002291 {
2292 return EGL_NONE;
2293 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002294
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002295 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002296 ASSERT(backAttachment != nullptr);
2297 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002298}
2299
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002300VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002301{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002302 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002303 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2304 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002305 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002306 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2307 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002308
Jamie Madill96a483b2017-06-27 16:49:21 -04002309 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002310 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002311
2312 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002313}
2314
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002315TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002316{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002317 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002318 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2319 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002320 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002321 transformFeedback =
2322 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002323 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002324 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002325 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002326
2327 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002328}
2329
2330bool Context::isVertexArrayGenerated(GLuint vertexArray)
2331{
Jamie Madill96a483b2017-06-27 16:49:21 -04002332 ASSERT(mVertexArrayMap.contains(0));
2333 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002334}
2335
2336bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2337{
Jamie Madill96a483b2017-06-27 16:49:21 -04002338 ASSERT(mTransformFeedbackMap.contains(0));
2339 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002340}
2341
Shannon Woods53a94a82014-06-24 15:20:36 -04002342void Context::detachTexture(GLuint texture)
2343{
2344 // Simple pass-through to State's detachTexture method, as textures do not require
2345 // allocation map management either here or in the resource manager at detach time.
2346 // Zero textures are held by the Context, and we don't attempt to request them from
2347 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002348 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002349}
2350
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002351void Context::detachBuffer(GLuint buffer)
2352{
Yuly Novikov5807a532015-12-03 13:01:22 -05002353 // Simple pass-through to State's detachBuffer method, since
2354 // only buffer attachments to container objects that are bound to the current context
2355 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002356
Yuly Novikov5807a532015-12-03 13:01:22 -05002357 // [OpenGL ES 3.2] section 5.1.2 page 45:
2358 // Attachments to unbound container objects, such as
2359 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2360 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002361 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002362}
2363
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002364void Context::detachFramebuffer(GLuint framebuffer)
2365{
Shannon Woods53a94a82014-06-24 15:20:36 -04002366 // Framebuffer detachment is handled by Context, because 0 is a valid
2367 // Framebuffer object, and a pointer to it must be passed from Context
2368 // to State at binding time.
2369
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002370 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002371 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2372 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2373 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002374
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002375 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002376 {
2377 bindReadFramebuffer(0);
2378 }
2379
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002380 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002381 {
2382 bindDrawFramebuffer(0);
2383 }
2384}
2385
2386void Context::detachRenderbuffer(GLuint renderbuffer)
2387{
Jamie Madilla02315b2017-02-23 14:14:47 -05002388 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002389}
2390
Jamie Madill57a89722013-07-02 11:57:03 -04002391void Context::detachVertexArray(GLuint vertexArray)
2392{
Jamie Madill77a72f62015-04-14 11:18:32 -04002393 // Vertex array detachment is handled by Context, because 0 is a valid
2394 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002395 // binding time.
2396
Jamie Madill57a89722013-07-02 11:57:03 -04002397 // [OpenGL ES 3.0.2] section 2.10 page 43:
2398 // If a vertex array object that is currently bound is deleted, the binding
2399 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002400 if (mGLState.removeVertexArrayBinding(vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002401 {
2402 bindVertexArray(0);
2403 }
2404}
2405
Geoff Langc8058452014-02-03 12:04:11 -05002406void Context::detachTransformFeedback(GLuint transformFeedback)
2407{
Corentin Walleza2257da2016-04-19 16:43:12 -04002408 // Transform feedback detachment is handled by Context, because 0 is a valid
2409 // transform feedback, and a pointer to it must be passed from Context to State at
2410 // binding time.
2411
2412 // The OpenGL specification doesn't mention what should happen when the currently bound
2413 // transform feedback object is deleted. Since it is a container object, we treat it like
2414 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002415 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002416 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002417 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002418 }
Geoff Langc8058452014-02-03 12:04:11 -05002419}
2420
Jamie Madilldc356042013-07-19 16:36:57 -04002421void Context::detachSampler(GLuint sampler)
2422{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002423 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002424}
2425
Yunchao Hea336b902017-08-02 16:05:21 +08002426void Context::detachProgramPipeline(GLuint pipeline)
2427{
2428 mGLState.detachProgramPipeline(this, pipeline);
2429}
2430
Jamie Madill3ef140a2017-08-26 23:11:21 -04002431void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002432{
Shaodde78e82017-05-22 14:13:27 +08002433 mGLState.setVertexAttribDivisor(this, index, divisor);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002434}
2435
Jamie Madille29d1672013-07-19 16:36:57 -04002436void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2437{
Geoff Langc1984ed2016-10-07 12:41:00 -04002438 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002439 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002440 SetSamplerParameteri(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002441 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002442}
Jamie Madille29d1672013-07-19 16:36:57 -04002443
Geoff Langc1984ed2016-10-07 12:41:00 -04002444void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2445{
2446 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002447 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002448 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002449 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002450}
2451
2452void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2453{
Geoff Langc1984ed2016-10-07 12:41:00 -04002454 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002455 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002456 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002457 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002458}
2459
Geoff Langc1984ed2016-10-07 12:41:00 -04002460void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002461{
Geoff Langc1984ed2016-10-07 12:41:00 -04002462 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002463 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002464 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002465 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002466}
2467
Geoff Langc1984ed2016-10-07 12:41:00 -04002468void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002469{
Geoff Langc1984ed2016-10-07 12:41:00 -04002470 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002471 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002472 QuerySamplerParameteriv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002473 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002474}
Jamie Madill9675b802013-07-19 16:36:59 -04002475
Geoff Langc1984ed2016-10-07 12:41:00 -04002476void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2477{
2478 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002479 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002480 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002481 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002482}
2483
Olli Etuahof0fee072016-03-30 15:11:58 +03002484void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2485{
2486 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002487 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002488}
2489
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002490void Context::initRendererString()
2491{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002492 std::ostringstream rendererString;
2493 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002494 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002495 rendererString << ")";
2496
Geoff Langcec35902014-04-16 10:52:36 -04002497 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002498}
2499
Geoff Langc339c4e2016-11-29 10:37:36 -05002500void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002501{
Geoff Langc339c4e2016-11-29 10:37:36 -05002502 const Version &clientVersion = getClientVersion();
2503
2504 std::ostringstream versionString;
2505 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2506 << ANGLE_VERSION_STRING << ")";
2507 mVersionString = MakeStaticString(versionString.str());
2508
2509 std::ostringstream shadingLanguageVersionString;
2510 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2511 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2512 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2513 << ")";
2514 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002515}
2516
Geoff Langcec35902014-04-16 10:52:36 -04002517void Context::initExtensionStrings()
2518{
Geoff Langc339c4e2016-11-29 10:37:36 -05002519 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2520 std::ostringstream combinedStringStream;
2521 std::copy(strings.begin(), strings.end(),
2522 std::ostream_iterator<const char *>(combinedStringStream, " "));
2523 return MakeStaticString(combinedStringStream.str());
2524 };
2525
2526 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002527 for (const auto &extensionString : mExtensions.getStrings())
2528 {
2529 mExtensionStrings.push_back(MakeStaticString(extensionString));
2530 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002531 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002532
Bryan Bernhart58806562017-01-05 13:09:31 -08002533 const gl::Extensions &nativeExtensions = mImplementation->getNativeExtensions();
2534
Geoff Langc339c4e2016-11-29 10:37:36 -05002535 mRequestableExtensionStrings.clear();
2536 for (const auto &extensionInfo : GetExtensionInfoMap())
2537 {
2538 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08002539 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
2540 nativeExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002541 {
2542 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
2543 }
2544 }
2545 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002546}
2547
Geoff Langc339c4e2016-11-29 10:37:36 -05002548const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04002549{
Geoff Langc339c4e2016-11-29 10:37:36 -05002550 switch (name)
2551 {
2552 case GL_VENDOR:
2553 return reinterpret_cast<const GLubyte *>("Google Inc.");
2554
2555 case GL_RENDERER:
2556 return reinterpret_cast<const GLubyte *>(mRendererString);
2557
2558 case GL_VERSION:
2559 return reinterpret_cast<const GLubyte *>(mVersionString);
2560
2561 case GL_SHADING_LANGUAGE_VERSION:
2562 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
2563
2564 case GL_EXTENSIONS:
2565 return reinterpret_cast<const GLubyte *>(mExtensionString);
2566
2567 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2568 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
2569
2570 default:
2571 UNREACHABLE();
2572 return nullptr;
2573 }
Geoff Langcec35902014-04-16 10:52:36 -04002574}
2575
Geoff Langc339c4e2016-11-29 10:37:36 -05002576const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04002577{
Geoff Langc339c4e2016-11-29 10:37:36 -05002578 switch (name)
2579 {
2580 case GL_EXTENSIONS:
2581 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
2582
2583 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2584 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
2585
2586 default:
2587 UNREACHABLE();
2588 return nullptr;
2589 }
Geoff Langcec35902014-04-16 10:52:36 -04002590}
2591
2592size_t Context::getExtensionStringCount() const
2593{
2594 return mExtensionStrings.size();
2595}
2596
Geoff Lang111a99e2017-10-17 10:58:41 -04002597bool Context::isExtensionRequestable(const char *name)
2598{
2599 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2600 auto extension = extensionInfos.find(name);
2601
2602 const Extensions &nativeExtensions = mImplementation->getNativeExtensions();
2603 return extension != extensionInfos.end() && extension->second.Requestable &&
2604 nativeExtensions.*(extension->second.ExtensionsMember);
2605}
2606
Geoff Langc339c4e2016-11-29 10:37:36 -05002607void Context::requestExtension(const char *name)
2608{
2609 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2610 ASSERT(extensionInfos.find(name) != extensionInfos.end());
2611 const auto &extension = extensionInfos.at(name);
2612 ASSERT(extension.Requestable);
Geoff Lang111a99e2017-10-17 10:58:41 -04002613 ASSERT(mImplementation->getNativeExtensions().*(extension.ExtensionsMember));
Geoff Langc339c4e2016-11-29 10:37:36 -05002614
2615 if (mExtensions.*(extension.ExtensionsMember))
2616 {
2617 // Extension already enabled
2618 return;
2619 }
2620
2621 mExtensions.*(extension.ExtensionsMember) = true;
2622 updateCaps();
2623 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08002624
Jamie Madill2f348d22017-06-05 10:50:59 -04002625 // Release the shader compiler so it will be re-created with the requested extensions enabled.
2626 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04002627
Jamie Madill81c2e252017-09-09 23:32:46 -04002628 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
2629 // sampleable.
Jamie Madilld4442552018-02-27 22:03:47 -05002630 mState.mTextures->signalAllTexturesDirty(this);
Geoff Lang9aded172017-04-05 11:07:56 -04002631 for (auto &zeroTexture : mZeroTextures)
2632 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002633 if (zeroTexture.get() != nullptr)
2634 {
2635 zeroTexture->signalDirty(this, InitState::Initialized);
2636 }
Geoff Lang9aded172017-04-05 11:07:56 -04002637 }
2638
2639 mState.mFramebuffers->invalidateFramebufferComplenessCache();
Geoff Langc339c4e2016-11-29 10:37:36 -05002640}
2641
2642size_t Context::getRequestableExtensionStringCount() const
2643{
2644 return mRequestableExtensionStrings.size();
2645}
2646
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002647void Context::beginTransformFeedback(GLenum primitiveMode)
2648{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002649 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002650 ASSERT(transformFeedback != nullptr);
2651 ASSERT(!transformFeedback->isPaused());
2652
Jamie Madill6c1f6712017-02-14 19:08:04 -05002653 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002654}
2655
2656bool Context::hasActiveTransformFeedback(GLuint program) const
2657{
2658 for (auto pair : mTransformFeedbackMap)
2659 {
2660 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
2661 {
2662 return true;
2663 }
2664 }
2665 return false;
2666}
2667
Geoff Langb433e872017-10-05 14:01:47 -04002668void Context::initCaps(const egl::DisplayExtensions &displayExtensions, bool robustResourceInit)
Geoff Lang493daf52014-07-03 13:38:44 -04002669{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002670 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04002671
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08002672 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
2673 if (getClientVersion() < Version(2, 0))
2674 {
2675 mCaps.maxMultitextureUnits = 4;
2676 mCaps.maxClipPlanes = 6;
2677 mCaps.maxLights = 8;
2678 mCaps.maxModelviewMatrixStackDepth = 16;
2679 mCaps.maxProjectionMatrixStackDepth = 16;
2680 mCaps.maxTextureMatrixStackDepth = 16;
2681 }
2682
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002683 mExtensions = mImplementation->getNativeExtensions();
Geoff Lang493daf52014-07-03 13:38:44 -04002684
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002685 mLimitations = mImplementation->getNativeLimitations();
Austin Kinross02df7962015-07-01 10:03:42 -07002686
Geoff Langeb66a6e2016-10-31 13:06:12 -04002687 if (getClientVersion() < Version(3, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002688 {
2689 // Disable ES3+ extensions
Jamie Madill231c7f52017-04-26 13:45:37 -04002690 mExtensions.colorBufferFloat = false;
Geoff Langb66a9092016-05-16 15:59:14 -04002691 mExtensions.eglImageExternalEssl3 = false;
Vincent Lang25ab4512016-05-13 18:13:59 +02002692 mExtensions.textureNorm16 = false;
Martin Radev137032d2017-07-13 10:11:12 +03002693 mExtensions.multiview = false;
2694 mExtensions.maxViews = 1u;
Geoff Lang493daf52014-07-03 13:38:44 -04002695 }
2696
Jiawei Shao89be29a2017-11-06 14:36:45 +08002697 if (getClientVersion() < ES_3_1)
2698 {
2699 // Disable ES3.1+ extensions
2700 mExtensions.geometryShader = false;
2701 }
2702
Geoff Langeb66a6e2016-10-31 13:06:12 -04002703 if (getClientVersion() > Version(2, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002704 {
2705 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
Jamie Madill231c7f52017-04-26 13:45:37 -04002706 // mExtensions.sRGB = false;
Geoff Lang493daf52014-07-03 13:38:44 -04002707 }
2708
Jamie Madill00ed7a12016-05-19 13:13:38 -04002709 // Some extensions are always available because they are implemented in the GL layer.
Jamie Madill231c7f52017-04-26 13:45:37 -04002710 mExtensions.bindUniformLocation = true;
2711 mExtensions.vertexArrayObject = true;
Geoff Langf41a7152016-09-19 15:11:17 -04002712 mExtensions.bindGeneratesResource = true;
Geoff Langfeb8c682017-02-13 16:07:35 -05002713 mExtensions.clientArrays = true;
Geoff Langc339c4e2016-11-29 10:37:36 -05002714 mExtensions.requestExtension = true;
Jamie Madill00ed7a12016-05-19 13:13:38 -04002715
2716 // Enable the no error extension if the context was created with the flag.
2717 mExtensions.noError = mSkipValidation;
2718
Corentin Wallezccab69d2017-01-27 16:57:15 -05002719 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Corentin Wallezc295e512017-01-27 17:47:50 -05002720 mExtensions.surfacelessContext = displayExtensions.surfacelessContext;
Corentin Wallezccab69d2017-01-27 16:57:15 -05002721
Geoff Lang70d0f492015-12-10 17:45:46 -05002722 // Explicitly enable GL_KHR_debug
2723 mExtensions.debug = true;
2724 mExtensions.maxDebugMessageLength = 1024;
2725 mExtensions.maxDebugLoggedMessages = 1024;
2726 mExtensions.maxDebugGroupStackDepth = 1024;
2727 mExtensions.maxLabelLength = 1024;
2728
Geoff Langff5b2d52016-09-07 11:32:23 -04002729 // Explicitly enable GL_ANGLE_robust_client_memory
2730 mExtensions.robustClientMemory = true;
2731
Jamie Madille08a1d32017-03-07 17:24:06 -05002732 // Determine robust resource init availability from EGL.
Geoff Langb433e872017-10-05 14:01:47 -04002733 mExtensions.robustResourceInitialization = robustResourceInit;
Jamie Madille08a1d32017-03-07 17:24:06 -05002734
Jiajia Qin8a7b3a02017-08-25 16:05:48 +08002735 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
2736 // supports it.
2737 mExtensions.robustBufferAccessBehavior =
2738 mRobustAccess && mExtensions.robustBufferAccessBehavior;
2739
Jamie Madillc43be722017-07-13 16:22:14 -04002740 // Enable the cache control query unconditionally.
2741 mExtensions.programCacheControl = true;
2742
Geoff Lang301d1612014-07-09 10:34:37 -04002743 // Apply implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04002744 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002745
Jamie Madill0f80ed82017-09-19 00:24:56 -04002746 if (getClientVersion() < ES_3_1)
2747 {
2748 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
2749 }
2750 else
2751 {
2752 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
2753 }
Geoff Lang301d1612014-07-09 10:34:37 -04002754
Jamie Madill0f80ed82017-09-19 00:24:56 -04002755 LimitCap(&mCaps.maxVertexUniformBlocks, IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
2756 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
2757 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
2758
2759 // Limit textures as well, so we can use fast bitsets with texture bindings.
2760 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
2761 LimitCap(&mCaps.maxVertexTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
2762 LimitCap(&mCaps.maxTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04002763
Jiawei Shaodb342272017-09-27 10:21:45 +08002764 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
2765
Geoff Langc287ea62016-09-16 14:46:51 -04002766 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002767 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04002768 for (const auto &extensionInfo : GetExtensionInfoMap())
2769 {
2770 // If this context is for WebGL, disable all enableable extensions
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002771 if (mWebGLContext && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04002772 {
2773 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
2774 }
2775 }
2776
2777 // Generate texture caps
2778 updateCaps();
2779}
2780
2781void Context::updateCaps()
2782{
Geoff Lang900013c2014-07-07 11:32:19 -04002783 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002784 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04002785
Jamie Madill7b62cf92017-11-02 15:20:49 -04002786 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04002787 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04002788 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04002789 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04002790
Geoff Lang0d8b7242015-09-09 14:56:53 -04002791 // Update the format caps based on the client version and extensions.
2792 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
2793 // ES3.
2794 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002795 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002796 formatCaps.renderable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002797 formatCaps.renderable && formatInfo.renderSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002798 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002799 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04002800
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002801 // OpenGL ES does not support multisampling with non-rendererable formats
2802 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Olli Etuaho50c562d2017-06-06 14:43:30 +03002803 if (!formatCaps.renderable ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002804 (getClientVersion() < ES_3_1 &&
2805 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04002806 {
Geoff Langd87878e2014-09-19 15:42:59 -04002807 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04002808 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03002809 else
2810 {
2811 // We may have limited the max samples for some required renderbuffer formats due to
2812 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
2813 GLuint formatMaxSamples = formatCaps.getMaxSamples();
2814
2815 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
2816 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
2817 // exception of signed and unsigned integer formats."
2818 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
2819 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
2820 {
2821 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
2822 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
2823 }
2824
2825 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
2826 if (getClientVersion() >= ES_3_1)
2827 {
2828 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
2829 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
2830 // the exception that the signed and unsigned integer formats are required only to
2831 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
2832 // multisamples, which must be at least one."
2833 if (formatInfo.componentType == GL_INT ||
2834 formatInfo.componentType == GL_UNSIGNED_INT)
2835 {
2836 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
2837 }
2838
2839 // GLES 3.1 section 19.3.1.
2840 if (formatCaps.texturable)
2841 {
2842 if (formatInfo.depthBits > 0)
2843 {
2844 mCaps.maxDepthTextureSamples =
2845 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
2846 }
2847 else if (formatInfo.redBits > 0)
2848 {
2849 mCaps.maxColorTextureSamples =
2850 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
2851 }
2852 }
2853 }
2854 }
Geoff Langd87878e2014-09-19 15:42:59 -04002855
2856 if (formatCaps.texturable && formatInfo.compressed)
2857 {
Geoff Langca271392017-04-05 12:30:00 -04002858 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04002859 }
2860
Geoff Langca271392017-04-05 12:30:00 -04002861 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04002862 }
Jamie Madill32447362017-06-28 14:53:52 -04002863
2864 // If program binary is disabled, blank out the memory cache pointer.
2865 if (!mImplementation->getNativeExtensions().getProgramBinary)
2866 {
2867 mMemoryProgramCache = nullptr;
2868 }
Corentin Walleze4477002017-12-01 14:39:58 -05002869
2870 // Compute which buffer types are allowed
2871 mValidBufferBindings.reset();
2872 mValidBufferBindings.set(BufferBinding::ElementArray);
2873 mValidBufferBindings.set(BufferBinding::Array);
2874
2875 if (mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
2876 {
2877 mValidBufferBindings.set(BufferBinding::PixelPack);
2878 mValidBufferBindings.set(BufferBinding::PixelUnpack);
2879 }
2880
2881 if (getClientVersion() >= ES_3_0)
2882 {
2883 mValidBufferBindings.set(BufferBinding::CopyRead);
2884 mValidBufferBindings.set(BufferBinding::CopyWrite);
2885 mValidBufferBindings.set(BufferBinding::TransformFeedback);
2886 mValidBufferBindings.set(BufferBinding::Uniform);
2887 }
2888
2889 if (getClientVersion() >= ES_3_1)
2890 {
2891 mValidBufferBindings.set(BufferBinding::AtomicCounter);
2892 mValidBufferBindings.set(BufferBinding::ShaderStorage);
2893 mValidBufferBindings.set(BufferBinding::DrawIndirect);
2894 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
2895 }
Geoff Lang493daf52014-07-03 13:38:44 -04002896}
2897
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002898void Context::initWorkarounds()
2899{
Jamie Madill761b02c2017-06-23 16:27:06 -04002900 // Apply back-end workarounds.
2901 mImplementation->applyNativeWorkarounds(&mWorkarounds);
2902
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002903 // Lose the context upon out of memory error if the application is
2904 // expecting to watch for those events.
2905 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2906}
2907
Jamie Madill05b35b22017-10-03 09:01:44 -04002908Error Context::prepareForDraw()
2909{
Jamie Madillbc918e72018-03-08 09:47:21 -05002910 ANGLE_TRY(syncRendererState());
Jamie Madilla59fc192017-11-02 12:57:58 -04002911
2912 if (isRobustResourceInitEnabled())
2913 {
2914 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
2915 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
2916 }
2917
Jamie Madill05b35b22017-10-03 09:01:44 -04002918 return NoError();
2919}
2920
Jamie Madillbc918e72018-03-08 09:47:21 -05002921Error Context::syncRendererState()
Jamie Madill1b94d432015-08-07 13:23:23 -04002922{
Jamie Madillbc918e72018-03-08 09:47:21 -05002923 ANGLE_TRY(mGLState.syncDirtyObjects(this));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002924 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
Jamie Madillfe548342017-06-19 11:13:24 -04002925 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002926 mGLState.clearDirtyBits();
Jamie Madillbc918e72018-03-08 09:47:21 -05002927 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04002928}
2929
Jamie Madillbc918e72018-03-08 09:47:21 -05002930Error Context::syncRendererState(const State::DirtyBits &bitMask,
2931 const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04002932{
Jamie Madillbc918e72018-03-08 09:47:21 -05002933 ANGLE_TRY(mGLState.syncDirtyObjects(this, objectMask));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002934 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madillfe548342017-06-19 11:13:24 -04002935 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002936 mGLState.clearDirtyBits(dirtyBits);
Jamie Madillbc918e72018-03-08 09:47:21 -05002937 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04002938}
Jamie Madillc29968b2016-01-20 11:17:23 -05002939
2940void Context::blitFramebuffer(GLint srcX0,
2941 GLint srcY0,
2942 GLint srcX1,
2943 GLint srcY1,
2944 GLint dstX0,
2945 GLint dstY0,
2946 GLint dstX1,
2947 GLint dstY1,
2948 GLbitfield mask,
2949 GLenum filter)
2950{
Qin Jiajiaaef92162018-02-27 13:51:44 +08002951 if (mask == 0)
2952 {
2953 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
2954 // buffers are copied.
2955 return;
2956 }
2957
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002958 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002959 ASSERT(drawFramebuffer);
2960
2961 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
2962 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
2963
Jamie Madillbc918e72018-03-08 09:47:21 -05002964 ANGLE_CONTEXT_TRY(syncStateForBlit());
Jamie Madillc29968b2016-01-20 11:17:23 -05002965
Jamie Madillc564c072017-06-01 12:45:42 -04002966 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002967}
Jamie Madillc29968b2016-01-20 11:17:23 -05002968
2969void Context::clear(GLbitfield mask)
2970{
Jamie Madillbc918e72018-03-08 09:47:21 -05002971 ANGLE_CONTEXT_TRY(syncStateForClear());
Jamie Madillc564c072017-06-01 12:45:42 -04002972 handleError(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05002973}
2974
2975void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
2976{
Jamie Madillbc918e72018-03-08 09:47:21 -05002977 ANGLE_CONTEXT_TRY(syncStateForClear());
Jamie Madillc564c072017-06-01 12:45:42 -04002978 handleError(mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002979}
2980
2981void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
2982{
Jamie Madillbc918e72018-03-08 09:47:21 -05002983 ANGLE_CONTEXT_TRY(syncStateForClear());
Jamie Madillc564c072017-06-01 12:45:42 -04002984 handleError(mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002985}
2986
2987void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
2988{
Jamie Madillbc918e72018-03-08 09:47:21 -05002989 ANGLE_CONTEXT_TRY(syncStateForClear());
Jamie Madillc564c072017-06-01 12:45:42 -04002990 handleError(mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002991}
2992
2993void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
2994{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002995 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002996 ASSERT(framebufferObject);
2997
2998 // If a buffer is not present, the clear has no effect
2999 if (framebufferObject->getDepthbuffer() == nullptr &&
3000 framebufferObject->getStencilbuffer() == nullptr)
3001 {
3002 return;
3003 }
3004
Jamie Madillbc918e72018-03-08 09:47:21 -05003005 ANGLE_CONTEXT_TRY(syncStateForClear());
Jamie Madillc564c072017-06-01 12:45:42 -04003006 handleError(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003007}
3008
3009void Context::readPixels(GLint x,
3010 GLint y,
3011 GLsizei width,
3012 GLsizei height,
3013 GLenum format,
3014 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003015 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003016{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003017 if (width == 0 || height == 0)
3018 {
3019 return;
3020 }
3021
Jamie Madillbc918e72018-03-08 09:47:21 -05003022 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003023
Jamie Madillb6664922017-07-25 12:55:04 -04003024 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3025 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003026
3027 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04003028 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003029}
3030
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003031void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003032 GLint level,
3033 GLenum internalformat,
3034 GLint x,
3035 GLint y,
3036 GLsizei width,
3037 GLsizei height,
3038 GLint border)
3039{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003040 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003041 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003042
Jamie Madillc29968b2016-01-20 11:17:23 -05003043 Rectangle sourceArea(x, y, width, height);
3044
Jamie Madill05b35b22017-10-03 09:01:44 -04003045 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003046 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003047 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003048}
3049
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003050void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003051 GLint level,
3052 GLint xoffset,
3053 GLint yoffset,
3054 GLint x,
3055 GLint y,
3056 GLsizei width,
3057 GLsizei height)
3058{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003059 if (width == 0 || height == 0)
3060 {
3061 return;
3062 }
3063
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003064 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003065 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003066
Jamie Madillc29968b2016-01-20 11:17:23 -05003067 Offset destOffset(xoffset, yoffset, 0);
3068 Rectangle sourceArea(x, y, width, height);
3069
Jamie Madill05b35b22017-10-03 09:01:44 -04003070 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003071 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003072 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003073}
3074
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003075void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003076 GLint level,
3077 GLint xoffset,
3078 GLint yoffset,
3079 GLint zoffset,
3080 GLint x,
3081 GLint y,
3082 GLsizei width,
3083 GLsizei height)
3084{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003085 if (width == 0 || height == 0)
3086 {
3087 return;
3088 }
3089
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003090 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003091 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003092
Jamie Madillc29968b2016-01-20 11:17:23 -05003093 Offset destOffset(xoffset, yoffset, zoffset);
3094 Rectangle sourceArea(x, y, width, height);
3095
Jamie Madill05b35b22017-10-03 09:01:44 -04003096 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3097 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003098 handleError(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level, destOffset,
3099 sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003100}
3101
3102void Context::framebufferTexture2D(GLenum target,
3103 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003104 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003105 GLuint texture,
3106 GLint level)
3107{
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 if (texture != 0)
3112 {
3113 Texture *textureObj = getTexture(texture);
3114
3115 ImageIndex index = ImageIndex::MakeInvalid();
3116
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003117 if (textarget == TextureTarget::_2D)
Jamie Madillc29968b2016-01-20 11:17:23 -05003118 {
3119 index = ImageIndex::Make2D(level);
3120 }
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003121 else if (textarget == TextureTarget::Rectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -04003122 {
3123 index = ImageIndex::MakeRectangle(level);
3124 }
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003125 else if (textarget == TextureTarget::_2DMultisample)
JiangYizhoubddc46b2016-12-09 09:50:51 +08003126 {
3127 ASSERT(level == 0);
3128 index = ImageIndex::Make2DMultisample();
3129 }
Jamie Madillc29968b2016-01-20 11:17:23 -05003130 else
3131 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003132 ASSERT(TextureTargetToType(textarget) == TextureType::CubeMap);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003133 index = ImageIndex::MakeCube(textarget, level);
Jamie Madillc29968b2016-01-20 11:17:23 -05003134 }
3135
Jamie Madilla02315b2017-02-23 14:14:47 -05003136 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003137 }
3138 else
3139 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003140 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003141 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003142
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003143 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003144}
3145
3146void Context::framebufferRenderbuffer(GLenum target,
3147 GLenum attachment,
3148 GLenum renderbuffertarget,
3149 GLuint renderbuffer)
3150{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003151 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003152 ASSERT(framebuffer);
3153
3154 if (renderbuffer != 0)
3155 {
3156 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003157
3158 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex::MakeInvalid(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003159 renderbufferObject);
3160 }
3161 else
3162 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003163 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003164 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003165
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003166 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003167}
3168
3169void Context::framebufferTextureLayer(GLenum target,
3170 GLenum attachment,
3171 GLuint texture,
3172 GLint level,
3173 GLint layer)
3174{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003175 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003176 ASSERT(framebuffer);
3177
3178 if (texture != 0)
3179 {
3180 Texture *textureObject = getTexture(texture);
3181
3182 ImageIndex index = ImageIndex::MakeInvalid();
3183
Corentin Wallez99d492c2018-02-27 15:17:10 -05003184 if (textureObject->getType() == TextureType::_3D)
Jamie Madillc29968b2016-01-20 11:17:23 -05003185 {
3186 index = ImageIndex::Make3D(level, layer);
3187 }
3188 else
3189 {
Corentin Wallez99d492c2018-02-27 15:17:10 -05003190 ASSERT(textureObject->getType() == TextureType::_2DArray);
Jamie Madillc29968b2016-01-20 11:17:23 -05003191 index = ImageIndex::Make2DArray(level, layer);
3192 }
3193
Jamie Madilla02315b2017-02-23 14:14:47 -05003194 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003195 }
3196 else
3197 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003198 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003199 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003200
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003201 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003202}
3203
Martin Radev137032d2017-07-13 10:11:12 +03003204void Context::framebufferTextureMultiviewLayeredANGLE(GLenum target,
3205 GLenum attachment,
3206 GLuint texture,
3207 GLint level,
3208 GLint baseViewIndex,
3209 GLsizei numViews)
3210{
Martin Radev82ef7742017-08-08 17:44:58 +03003211 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3212 ASSERT(framebuffer);
3213
3214 if (texture != 0)
3215 {
3216 Texture *textureObj = getTexture(texture);
3217
Martin Radev18b75ba2017-08-15 15:50:40 +03003218 ImageIndex index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
Martin Radev82ef7742017-08-08 17:44:58 +03003219 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3220 numViews, baseViewIndex);
3221 }
3222 else
3223 {
3224 framebuffer->resetAttachment(this, attachment);
3225 }
3226
3227 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003228}
3229
3230void Context::framebufferTextureMultiviewSideBySideANGLE(GLenum target,
3231 GLenum attachment,
3232 GLuint texture,
3233 GLint level,
3234 GLsizei numViews,
3235 const GLint *viewportOffsets)
3236{
Martin Radev5dae57b2017-07-14 16:15:55 +03003237 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3238 ASSERT(framebuffer);
3239
3240 if (texture != 0)
3241 {
3242 Texture *textureObj = getTexture(texture);
3243
3244 ImageIndex index = ImageIndex::Make2D(level);
3245 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3246 textureObj, numViews, viewportOffsets);
3247 }
3248 else
3249 {
3250 framebuffer->resetAttachment(this, attachment);
3251 }
3252
3253 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003254}
3255
Jamie Madillc29968b2016-01-20 11:17:23 -05003256void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3257{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003258 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003259 ASSERT(framebuffer);
3260 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003261 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003262}
3263
3264void Context::readBuffer(GLenum mode)
3265{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003266 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003267 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003268 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003269}
3270
3271void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3272{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003273 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003274 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003275
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003276 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003277 ASSERT(framebuffer);
3278
3279 // The specification isn't clear what should be done when the framebuffer isn't complete.
3280 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003281 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003282}
3283
3284void Context::invalidateFramebuffer(GLenum target,
3285 GLsizei numAttachments,
3286 const GLenum *attachments)
3287{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003288 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003289 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003290
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003291 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003292 ASSERT(framebuffer);
3293
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003294 if (framebuffer->checkStatus(this) != GL_FRAMEBUFFER_COMPLETE)
Jamie Madillc29968b2016-01-20 11:17:23 -05003295 {
Jamie Madill437fa652016-05-03 15:13:24 -04003296 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003297 }
Jamie Madill437fa652016-05-03 15:13:24 -04003298
Jamie Madill4928b7c2017-06-20 12:57:39 -04003299 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003300}
3301
3302void Context::invalidateSubFramebuffer(GLenum target,
3303 GLsizei numAttachments,
3304 const GLenum *attachments,
3305 GLint x,
3306 GLint y,
3307 GLsizei width,
3308 GLsizei height)
3309{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003310 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003311 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003312
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003313 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003314 ASSERT(framebuffer);
3315
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003316 if (framebuffer->checkStatus(this) != GL_FRAMEBUFFER_COMPLETE)
Jamie Madillc29968b2016-01-20 11:17:23 -05003317 {
Jamie Madill437fa652016-05-03 15:13:24 -04003318 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003319 }
Jamie Madill437fa652016-05-03 15:13:24 -04003320
3321 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003322 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003323}
3324
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003325void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003326 GLint level,
3327 GLint internalformat,
3328 GLsizei width,
3329 GLsizei height,
3330 GLint border,
3331 GLenum format,
3332 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003333 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003334{
Jamie Madillbc918e72018-03-08 09:47:21 -05003335 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003336
3337 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003338 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003339 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3340 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003341}
3342
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003343void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003344 GLint level,
3345 GLint internalformat,
3346 GLsizei width,
3347 GLsizei height,
3348 GLsizei depth,
3349 GLint border,
3350 GLenum format,
3351 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003352 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003353{
Jamie Madillbc918e72018-03-08 09:47:21 -05003354 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003355
3356 Extents size(width, height, depth);
3357 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003358 handleError(texture->setImage(this, mGLState.getUnpackState(),
3359 NonCubeTextureTypeToTarget(target), level, internalformat, size,
3360 format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003361}
3362
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003363void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003364 GLint level,
3365 GLint xoffset,
3366 GLint yoffset,
3367 GLsizei width,
3368 GLsizei height,
3369 GLenum format,
3370 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003371 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003372{
3373 // Zero sized uploads are valid but no-ops
3374 if (width == 0 || height == 0)
3375 {
3376 return;
3377 }
3378
Jamie Madillbc918e72018-03-08 09:47:21 -05003379 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003380
3381 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003382 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003383 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3384 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003385}
3386
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003387void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003388 GLint level,
3389 GLint xoffset,
3390 GLint yoffset,
3391 GLint zoffset,
3392 GLsizei width,
3393 GLsizei height,
3394 GLsizei depth,
3395 GLenum format,
3396 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003397 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003398{
3399 // Zero sized uploads are valid but no-ops
3400 if (width == 0 || height == 0 || depth == 0)
3401 {
3402 return;
3403 }
3404
Jamie Madillbc918e72018-03-08 09:47:21 -05003405 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003406
3407 Box area(xoffset, yoffset, zoffset, width, height, depth);
3408 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003409 handleError(texture->setSubImage(this, mGLState.getUnpackState(),
3410 NonCubeTextureTypeToTarget(target), level, area, format, type,
3411 reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003412}
3413
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003414void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003415 GLint level,
3416 GLenum internalformat,
3417 GLsizei width,
3418 GLsizei height,
3419 GLint border,
3420 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003421 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003422{
Jamie Madillbc918e72018-03-08 09:47:21 -05003423 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003424
3425 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003426 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003427 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
3428 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003429 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003430}
3431
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003432void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003433 GLint level,
3434 GLenum internalformat,
3435 GLsizei width,
3436 GLsizei height,
3437 GLsizei depth,
3438 GLint border,
3439 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003440 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003441{
Jamie Madillbc918e72018-03-08 09:47:21 -05003442 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003443
3444 Extents size(width, height, depth);
3445 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003446 handleError(texture->setCompressedImage(
3447 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
3448 size, imageSize, reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003449}
3450
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003451void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003452 GLint level,
3453 GLint xoffset,
3454 GLint yoffset,
3455 GLsizei width,
3456 GLsizei height,
3457 GLenum format,
3458 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003459 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003460{
Jamie Madillbc918e72018-03-08 09:47:21 -05003461 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003462
3463 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003464 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003465 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
3466 format, imageSize,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003467 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003468}
3469
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003470void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003471 GLint level,
3472 GLint xoffset,
3473 GLint yoffset,
3474 GLint zoffset,
3475 GLsizei width,
3476 GLsizei height,
3477 GLsizei depth,
3478 GLenum format,
3479 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003480 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003481{
3482 // Zero sized uploads are valid but no-ops
3483 if (width == 0 || height == 0)
3484 {
3485 return;
3486 }
3487
Jamie Madillbc918e72018-03-08 09:47:21 -05003488 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003489
3490 Box area(xoffset, yoffset, zoffset, width, height, depth);
3491 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003492 handleError(texture->setCompressedSubImage(
3493 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
3494 imageSize, reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003495}
3496
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003497void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003498{
3499 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003500 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003501}
3502
Jamie Madill007530e2017-12-28 14:27:04 -05003503void Context::copyTexture(GLuint sourceId,
3504 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05003505 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05003506 GLuint destId,
3507 GLint destLevel,
3508 GLint internalFormat,
3509 GLenum destType,
3510 GLboolean unpackFlipY,
3511 GLboolean unpackPremultiplyAlpha,
3512 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07003513{
Jamie Madillbc918e72018-03-08 09:47:21 -05003514 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07003515
3516 gl::Texture *sourceTexture = getTexture(sourceId);
3517 gl::Texture *destTexture = getTexture(destId);
Geoff Lang92019432017-11-20 13:09:34 -05003518 handleError(destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType,
3519 sourceLevel, ConvertToBool(unpackFlipY),
3520 ConvertToBool(unpackPremultiplyAlpha),
3521 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003522}
3523
Jamie Madill007530e2017-12-28 14:27:04 -05003524void Context::copySubTexture(GLuint sourceId,
3525 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05003526 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05003527 GLuint destId,
3528 GLint destLevel,
3529 GLint xoffset,
3530 GLint yoffset,
3531 GLint x,
3532 GLint y,
3533 GLsizei width,
3534 GLsizei height,
3535 GLboolean unpackFlipY,
3536 GLboolean unpackPremultiplyAlpha,
3537 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07003538{
3539 // Zero sized copies are valid but no-ops
3540 if (width == 0 || height == 0)
3541 {
3542 return;
3543 }
3544
Jamie Madillbc918e72018-03-08 09:47:21 -05003545 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07003546
3547 gl::Texture *sourceTexture = getTexture(sourceId);
3548 gl::Texture *destTexture = getTexture(destId);
3549 Offset offset(xoffset, yoffset, 0);
3550 Rectangle area(x, y, width, height);
Geoff Lang92019432017-11-20 13:09:34 -05003551 handleError(destTexture->copySubTexture(this, destTarget, destLevel, offset, sourceLevel, area,
3552 ConvertToBool(unpackFlipY),
3553 ConvertToBool(unpackPremultiplyAlpha),
3554 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003555}
3556
Jamie Madill007530e2017-12-28 14:27:04 -05003557void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07003558{
Jamie Madillbc918e72018-03-08 09:47:21 -05003559 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07003560
3561 gl::Texture *sourceTexture = getTexture(sourceId);
3562 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05003563 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07003564}
3565
Corentin Wallez336129f2017-10-17 15:55:40 -04003566void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03003567{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003568 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003569 ASSERT(buffer);
3570
Geoff Lang496c02d2016-10-20 11:38:11 -07003571 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03003572}
3573
Corentin Wallez336129f2017-10-17 15:55:40 -04003574void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003575{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003576 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003577 ASSERT(buffer);
3578
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003579 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003580 if (error.isError())
3581 {
Jamie Madill437fa652016-05-03 15:13:24 -04003582 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003583 return nullptr;
3584 }
3585
3586 return buffer->getMapPointer();
3587}
3588
Corentin Wallez336129f2017-10-17 15:55:40 -04003589GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03003590{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003591 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003592 ASSERT(buffer);
3593
3594 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003595 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03003596 if (error.isError())
3597 {
Jamie Madill437fa652016-05-03 15:13:24 -04003598 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003599 return GL_FALSE;
3600 }
3601
3602 return result;
3603}
3604
Corentin Wallez336129f2017-10-17 15:55:40 -04003605void *Context::mapBufferRange(BufferBinding target,
3606 GLintptr offset,
3607 GLsizeiptr length,
3608 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003609{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003610 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003611 ASSERT(buffer);
3612
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003613 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003614 if (error.isError())
3615 {
Jamie Madill437fa652016-05-03 15:13:24 -04003616 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003617 return nullptr;
3618 }
3619
3620 return buffer->getMapPointer();
3621}
3622
Corentin Wallez336129f2017-10-17 15:55:40 -04003623void Context::flushMappedBufferRange(BufferBinding /*target*/,
3624 GLintptr /*offset*/,
3625 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03003626{
3627 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
3628}
3629
Jamie Madillbc918e72018-03-08 09:47:21 -05003630Error Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05003631{
Jamie Madillbc918e72018-03-08 09:47:21 -05003632 return syncRendererState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05003633}
3634
Jamie Madillbc918e72018-03-08 09:47:21 -05003635Error Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05003636{
Jamie Madillbc918e72018-03-08 09:47:21 -05003637 return syncRendererState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05003638}
3639
Jamie Madillbc918e72018-03-08 09:47:21 -05003640Error Context::syncStateForClear()
Jamie Madillad9f24e2016-02-12 09:27:24 -05003641{
Jamie Madillbc918e72018-03-08 09:47:21 -05003642 return syncRendererState(mClearDirtyBits, mClearDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05003643}
3644
Jamie Madillbc918e72018-03-08 09:47:21 -05003645Error Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05003646{
Jamie Madillbc918e72018-03-08 09:47:21 -05003647 return syncRendererState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05003648}
3649
Jiajia Qin5451d532017-11-16 17:16:34 +08003650void Context::activeShaderProgram(GLuint pipeline, GLuint program)
3651{
3652 UNIMPLEMENTED();
3653}
3654
Jamie Madillc20ab272016-06-09 07:20:46 -07003655void Context::activeTexture(GLenum texture)
3656{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003657 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003658}
3659
Jamie Madill876429b2017-04-20 15:46:24 -04003660void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003661{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003662 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07003663}
3664
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003665void Context::blendEquation(GLenum mode)
3666{
3667 mGLState.setBlendEquation(mode, mode);
3668}
3669
Jamie Madillc20ab272016-06-09 07:20:46 -07003670void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
3671{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003672 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003673}
3674
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003675void Context::blendFunc(GLenum sfactor, GLenum dfactor)
3676{
3677 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
3678}
3679
Jamie Madillc20ab272016-06-09 07:20:46 -07003680void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
3681{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003682 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003683}
3684
Jamie Madill876429b2017-04-20 15:46:24 -04003685void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003686{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003687 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003688}
3689
Jamie Madill876429b2017-04-20 15:46:24 -04003690void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07003691{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003692 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07003693}
3694
3695void Context::clearStencil(GLint s)
3696{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003697 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07003698}
3699
3700void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
3701{
Geoff Lang92019432017-11-20 13:09:34 -05003702 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
3703 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07003704}
3705
Corentin Wallez2e568cf2017-09-18 17:05:22 -04003706void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07003707{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003708 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003709}
3710
3711void Context::depthFunc(GLenum func)
3712{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003713 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07003714}
3715
3716void Context::depthMask(GLboolean flag)
3717{
Geoff Lang92019432017-11-20 13:09:34 -05003718 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07003719}
3720
Jamie Madill876429b2017-04-20 15:46:24 -04003721void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07003722{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003723 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07003724}
3725
3726void Context::disable(GLenum cap)
3727{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003728 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003729}
3730
3731void Context::disableVertexAttribArray(GLuint index)
3732{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003733 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003734}
3735
3736void Context::enable(GLenum cap)
3737{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003738 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003739}
3740
3741void Context::enableVertexAttribArray(GLuint index)
3742{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003743 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003744}
3745
3746void Context::frontFace(GLenum mode)
3747{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003748 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003749}
3750
3751void Context::hint(GLenum target, GLenum mode)
3752{
3753 switch (target)
3754 {
3755 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003756 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003757 break;
3758
3759 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003760 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003761 break;
3762
3763 default:
3764 UNREACHABLE();
3765 return;
3766 }
3767}
3768
3769void Context::lineWidth(GLfloat width)
3770{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003771 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07003772}
3773
3774void Context::pixelStorei(GLenum pname, GLint param)
3775{
3776 switch (pname)
3777 {
3778 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003779 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003780 break;
3781
3782 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003783 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003784 break;
3785
3786 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003787 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003788 break;
3789
3790 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003791 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003792 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003793 break;
3794
3795 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03003796 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003797 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003798 break;
3799
3800 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03003801 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003802 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003803 break;
3804
3805 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003806 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003807 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003808 break;
3809
3810 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003811 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003812 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003813 break;
3814
3815 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003816 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003817 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003818 break;
3819
3820 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003821 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003822 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003823 break;
3824
3825 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003826 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003827 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003828 break;
3829
3830 default:
3831 UNREACHABLE();
3832 return;
3833 }
3834}
3835
3836void Context::polygonOffset(GLfloat factor, GLfloat units)
3837{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003838 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07003839}
3840
Jamie Madill876429b2017-04-20 15:46:24 -04003841void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07003842{
Geoff Lang92019432017-11-20 13:09:34 -05003843 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07003844}
3845
Jiawei Shaodb342272017-09-27 10:21:45 +08003846void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
3847{
3848 mGLState.setSampleMaskParams(maskNumber, mask);
3849}
3850
Jamie Madillc20ab272016-06-09 07:20:46 -07003851void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
3852{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003853 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07003854}
3855
3856void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
3857{
3858 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3859 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003860 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003861 }
3862
3863 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3864 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003865 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003866 }
3867}
3868
3869void Context::stencilMaskSeparate(GLenum face, GLuint mask)
3870{
3871 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3872 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003873 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003874 }
3875
3876 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3877 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003878 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003879 }
3880}
3881
3882void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
3883{
3884 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3885 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003886 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003887 }
3888
3889 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3890 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003891 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003892 }
3893}
3894
3895void Context::vertexAttrib1f(GLuint index, GLfloat x)
3896{
3897 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003898 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003899}
3900
3901void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
3902{
3903 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003904 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003905}
3906
3907void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
3908{
3909 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003910 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003911}
3912
3913void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
3914{
3915 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003916 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003917}
3918
3919void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
3920{
3921 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003922 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003923}
3924
3925void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
3926{
3927 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003928 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003929}
3930
3931void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
3932{
3933 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003934 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003935}
3936
3937void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
3938{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003939 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07003940}
3941
3942void Context::vertexAttribPointer(GLuint index,
3943 GLint size,
3944 GLenum type,
3945 GLboolean normalized,
3946 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04003947 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07003948{
Corentin Wallez336129f2017-10-17 15:55:40 -04003949 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05003950 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc20ab272016-06-09 07:20:46 -07003951}
3952
Shao80957d92017-02-20 21:25:59 +08003953void Context::vertexAttribFormat(GLuint attribIndex,
3954 GLint size,
3955 GLenum type,
3956 GLboolean normalized,
3957 GLuint relativeOffset)
3958{
Geoff Lang92019432017-11-20 13:09:34 -05003959 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08003960 relativeOffset);
3961}
3962
3963void Context::vertexAttribIFormat(GLuint attribIndex,
3964 GLint size,
3965 GLenum type,
3966 GLuint relativeOffset)
3967{
3968 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
3969}
3970
3971void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
3972{
Shaodde78e82017-05-22 14:13:27 +08003973 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Shao80957d92017-02-20 21:25:59 +08003974}
3975
Jiajia Qin5451d532017-11-16 17:16:34 +08003976void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08003977{
3978 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
3979}
3980
Jamie Madillc20ab272016-06-09 07:20:46 -07003981void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
3982{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003983 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07003984}
3985
3986void Context::vertexAttribIPointer(GLuint index,
3987 GLint size,
3988 GLenum type,
3989 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04003990 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07003991{
Corentin Wallez336129f2017-10-17 15:55:40 -04003992 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
3993 size, type, false, true, stride, pointer);
Jamie Madillc20ab272016-06-09 07:20:46 -07003994}
3995
3996void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
3997{
3998 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003999 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004000}
4001
4002void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4003{
4004 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004005 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004006}
4007
4008void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4009{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004010 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004011}
4012
4013void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4014{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004015 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004016}
4017
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004018void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4019{
4020 const VertexAttribCurrentValueData &currentValues =
4021 getGLState().getVertexAttribCurrentValue(index);
4022 const VertexArray *vao = getGLState().getVertexArray();
4023 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4024 currentValues, pname, params);
4025}
4026
4027void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4028{
4029 const VertexAttribCurrentValueData &currentValues =
4030 getGLState().getVertexAttribCurrentValue(index);
4031 const VertexArray *vao = getGLState().getVertexArray();
4032 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4033 currentValues, pname, params);
4034}
4035
4036void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4037{
4038 const VertexAttribCurrentValueData &currentValues =
4039 getGLState().getVertexAttribCurrentValue(index);
4040 const VertexArray *vao = getGLState().getVertexArray();
4041 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4042 currentValues, pname, params);
4043}
4044
4045void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4046{
4047 const VertexAttribCurrentValueData &currentValues =
4048 getGLState().getVertexAttribCurrentValue(index);
4049 const VertexArray *vao = getGLState().getVertexArray();
4050 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4051 currentValues, pname, params);
4052}
4053
Jamie Madill876429b2017-04-20 15:46:24 -04004054void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004055{
4056 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
4057 QueryVertexAttribPointerv(attrib, pname, pointer);
4058}
4059
Jamie Madillc20ab272016-06-09 07:20:46 -07004060void Context::debugMessageControl(GLenum source,
4061 GLenum type,
4062 GLenum severity,
4063 GLsizei count,
4064 const GLuint *ids,
4065 GLboolean enabled)
4066{
4067 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004068 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05004069 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004070}
4071
4072void Context::debugMessageInsert(GLenum source,
4073 GLenum type,
4074 GLuint id,
4075 GLenum severity,
4076 GLsizei length,
4077 const GLchar *buf)
4078{
4079 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004080 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004081}
4082
4083void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4084{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004085 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004086}
4087
4088GLuint Context::getDebugMessageLog(GLuint count,
4089 GLsizei bufSize,
4090 GLenum *sources,
4091 GLenum *types,
4092 GLuint *ids,
4093 GLenum *severities,
4094 GLsizei *lengths,
4095 GLchar *messageLog)
4096{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004097 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4098 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004099}
4100
4101void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4102{
4103 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004104 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05004105 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07004106}
4107
4108void Context::popDebugGroup()
4109{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004110 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05004111 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004112}
4113
Corentin Wallez336129f2017-10-17 15:55:40 -04004114void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004115{
4116 Buffer *buffer = mGLState.getTargetBuffer(target);
4117 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004118 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004119}
4120
Corentin Wallez336129f2017-10-17 15:55:40 -04004121void Context::bufferSubData(BufferBinding target,
4122 GLintptr offset,
4123 GLsizeiptr size,
4124 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004125{
4126 if (data == nullptr)
4127 {
4128 return;
4129 }
4130
4131 Buffer *buffer = mGLState.getTargetBuffer(target);
4132 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004133 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004134}
4135
Jamie Madillef300b12016-10-07 15:12:09 -04004136void Context::attachShader(GLuint program, GLuint shader)
4137{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05004138 Program *programObject = mState.mShaderPrograms->getProgram(program);
4139 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004140 ASSERT(programObject && shaderObject);
4141 programObject->attachShader(shaderObject);
4142}
4143
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004144const Workarounds &Context::getWorkarounds() const
4145{
4146 return mWorkarounds;
4147}
4148
Corentin Wallez336129f2017-10-17 15:55:40 -04004149void Context::copyBufferSubData(BufferBinding readTarget,
4150 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04004151 GLintptr readOffset,
4152 GLintptr writeOffset,
4153 GLsizeiptr size)
4154{
4155 // if size is zero, the copy is a successful no-op
4156 if (size == 0)
4157 {
4158 return;
4159 }
4160
4161 // TODO(jmadill): cache these.
4162 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4163 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4164
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004165 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004166}
4167
Jamie Madill01a80ee2016-11-07 12:06:18 -05004168void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4169{
4170 Program *programObject = getProgram(program);
4171 // TODO(jmadill): Re-use this from the validation if possible.
4172 ASSERT(programObject);
4173 programObject->bindAttributeLocation(index, name);
4174}
4175
Corentin Wallez336129f2017-10-17 15:55:40 -04004176void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004177{
Corentin Wallez336129f2017-10-17 15:55:40 -04004178 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4179 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004180}
4181
Corentin Wallez336129f2017-10-17 15:55:40 -04004182void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08004183{
4184 bindBufferRange(target, index, buffer, 0, 0);
4185}
4186
Corentin Wallez336129f2017-10-17 15:55:40 -04004187void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08004188 GLuint index,
4189 GLuint buffer,
4190 GLintptr offset,
4191 GLsizeiptr size)
4192{
Corentin Wallez336129f2017-10-17 15:55:40 -04004193 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4194 mGLState.setIndexedBufferBinding(this, target, index, bufferObject, offset, size);
Jiajia Qin6eafb042016-12-27 17:04:07 +08004195}
4196
Jamie Madill01a80ee2016-11-07 12:06:18 -05004197void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
4198{
4199 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4200 {
4201 bindReadFramebuffer(framebuffer);
4202 }
4203
4204 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4205 {
4206 bindDrawFramebuffer(framebuffer);
4207 }
4208}
4209
4210void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4211{
4212 ASSERT(target == GL_RENDERBUFFER);
4213 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004214 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04004215 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004216}
4217
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004218void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08004219 GLsizei samples,
4220 GLenum internalformat,
4221 GLsizei width,
4222 GLsizei height,
4223 GLboolean fixedsamplelocations)
4224{
4225 Extents size(width, height, 1);
4226 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004227 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
4228 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004229}
4230
4231void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4232{
JiangYizhou5b03f472017-01-09 10:22:53 +08004233 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
4234 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillbc918e72018-03-08 09:47:21 -05004235 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
JiangYizhou5b03f472017-01-09 10:22:53 +08004236 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08004237
4238 switch (pname)
4239 {
4240 case GL_SAMPLE_POSITION:
4241 handleError(framebuffer->getSamplePosition(index, val));
4242 break;
4243 default:
4244 UNREACHABLE();
4245 }
4246}
4247
Jamie Madille8fb6402017-02-14 17:56:40 -05004248void Context::renderbufferStorage(GLenum target,
4249 GLenum internalformat,
4250 GLsizei width,
4251 GLsizei height)
4252{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004253 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4254 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
4255
Jamie Madille8fb6402017-02-14 17:56:40 -05004256 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04004257 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004258}
4259
4260void Context::renderbufferStorageMultisample(GLenum target,
4261 GLsizei samples,
4262 GLenum internalformat,
4263 GLsizei width,
4264 GLsizei height)
4265{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004266 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4267 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05004268
4269 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004270 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04004271 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004272}
4273
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004274void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
4275{
Jamie Madill70b5bb02017-08-28 13:32:37 -04004276 const Sync *syncObject = getSync(sync);
Geoff Lang82483b92017-04-11 15:33:00 -04004277 handleError(QuerySynciv(syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004278}
4279
JiangYizhoue18e6392017-02-20 10:32:23 +08004280void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
4281{
4282 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4283 QueryFramebufferParameteriv(framebuffer, pname, params);
4284}
4285
Jiajia Qin5451d532017-11-16 17:16:34 +08004286void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08004287{
4288 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4289 SetFramebufferParameteri(framebuffer, pname, param);
4290}
4291
Jamie Madillb3f26b92017-07-19 15:07:41 -04004292Error Context::getScratchBuffer(size_t requstedSizeBytes,
4293 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05004294{
Jamie Madillb3f26b92017-07-19 15:07:41 -04004295 if (!mScratchBuffer.get(requstedSizeBytes, scratchBufferOut))
4296 {
4297 return OutOfMemory() << "Failed to allocate internal buffer.";
4298 }
4299 return NoError();
4300}
4301
4302Error Context::getZeroFilledBuffer(size_t requstedSizeBytes,
4303 angle::MemoryBuffer **zeroBufferOut) const
4304{
4305 if (!mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0))
Jamie Madille14951e2017-03-09 18:55:16 -05004306 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004307 return OutOfMemory() << "Failed to allocate internal buffer.";
Jamie Madille14951e2017-03-09 18:55:16 -05004308 }
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004309 return NoError();
Jamie Madille14951e2017-03-09 18:55:16 -05004310}
4311
Xinghua Cao10a4d432017-11-28 14:46:26 +08004312Error Context::prepareForDispatch()
4313{
Jamie Madillbc918e72018-03-08 09:47:21 -05004314 ANGLE_TRY(syncRendererState(mComputeDirtyBits, mComputeDirtyObjects));
Xinghua Cao10a4d432017-11-28 14:46:26 +08004315
4316 if (isRobustResourceInitEnabled())
4317 {
4318 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
4319 }
4320
4321 return NoError();
4322}
4323
Xinghua Cao2b396592017-03-29 15:36:04 +08004324void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
4325{
4326 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
4327 {
4328 return;
4329 }
4330
Xinghua Cao10a4d432017-11-28 14:46:26 +08004331 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill71c88b32017-09-14 22:20:29 -04004332 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08004333}
4334
Jiajia Qin5451d532017-11-16 17:16:34 +08004335void Context::dispatchComputeIndirect(GLintptr indirect)
4336{
Qin Jiajia62fcf622017-11-30 16:16:12 +08004337 ANGLE_CONTEXT_TRY(prepareForDispatch());
4338 handleError(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08004339}
4340
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004341void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08004342 GLsizei levels,
4343 GLenum internalFormat,
4344 GLsizei width,
4345 GLsizei height)
4346{
4347 Extents size(width, height, 1);
4348 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004349 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08004350}
4351
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004352void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08004353 GLsizei levels,
4354 GLenum internalFormat,
4355 GLsizei width,
4356 GLsizei height,
4357 GLsizei depth)
4358{
4359 Extents size(width, height, depth);
4360 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004361 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08004362}
4363
Jiajia Qin5451d532017-11-16 17:16:34 +08004364void Context::memoryBarrier(GLbitfield barriers)
4365{
Xinghua Cao89c422a2017-11-29 18:24:20 +08004366 handleError(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08004367}
4368
4369void Context::memoryBarrierByRegion(GLbitfield barriers)
4370{
Xinghua Cao89c422a2017-11-29 18:24:20 +08004371 handleError(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08004372}
4373
Jamie Madillc1d770e2017-04-13 17:31:24 -04004374GLenum Context::checkFramebufferStatus(GLenum target)
4375{
4376 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4377 ASSERT(framebuffer);
4378
4379 return framebuffer->checkStatus(this);
4380}
4381
4382void Context::compileShader(GLuint shader)
4383{
4384 Shader *shaderObject = GetValidShader(this, shader);
4385 if (!shaderObject)
4386 {
4387 return;
4388 }
4389 shaderObject->compile(this);
4390}
4391
4392void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
4393{
4394 for (int i = 0; i < n; i++)
4395 {
4396 deleteBuffer(buffers[i]);
4397 }
4398}
4399
4400void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
4401{
4402 for (int i = 0; i < n; i++)
4403 {
4404 if (framebuffers[i] != 0)
4405 {
4406 deleteFramebuffer(framebuffers[i]);
4407 }
4408 }
4409}
4410
4411void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
4412{
4413 for (int i = 0; i < n; i++)
4414 {
4415 deleteRenderbuffer(renderbuffers[i]);
4416 }
4417}
4418
4419void Context::deleteTextures(GLsizei n, const GLuint *textures)
4420{
4421 for (int i = 0; i < n; i++)
4422 {
4423 if (textures[i] != 0)
4424 {
4425 deleteTexture(textures[i]);
4426 }
4427 }
4428}
4429
4430void Context::detachShader(GLuint program, GLuint shader)
4431{
4432 Program *programObject = getProgram(program);
4433 ASSERT(programObject);
4434
4435 Shader *shaderObject = getShader(shader);
4436 ASSERT(shaderObject);
4437
4438 programObject->detachShader(this, shaderObject);
4439}
4440
4441void Context::genBuffers(GLsizei n, GLuint *buffers)
4442{
4443 for (int i = 0; i < n; i++)
4444 {
4445 buffers[i] = createBuffer();
4446 }
4447}
4448
4449void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
4450{
4451 for (int i = 0; i < n; i++)
4452 {
4453 framebuffers[i] = createFramebuffer();
4454 }
4455}
4456
4457void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
4458{
4459 for (int i = 0; i < n; i++)
4460 {
4461 renderbuffers[i] = createRenderbuffer();
4462 }
4463}
4464
4465void Context::genTextures(GLsizei n, GLuint *textures)
4466{
4467 for (int i = 0; i < n; i++)
4468 {
4469 textures[i] = createTexture();
4470 }
4471}
4472
4473void Context::getActiveAttrib(GLuint program,
4474 GLuint index,
4475 GLsizei bufsize,
4476 GLsizei *length,
4477 GLint *size,
4478 GLenum *type,
4479 GLchar *name)
4480{
4481 Program *programObject = getProgram(program);
4482 ASSERT(programObject);
4483 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
4484}
4485
4486void Context::getActiveUniform(GLuint program,
4487 GLuint index,
4488 GLsizei bufsize,
4489 GLsizei *length,
4490 GLint *size,
4491 GLenum *type,
4492 GLchar *name)
4493{
4494 Program *programObject = getProgram(program);
4495 ASSERT(programObject);
4496 programObject->getActiveUniform(index, bufsize, length, size, type, name);
4497}
4498
4499void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
4500{
4501 Program *programObject = getProgram(program);
4502 ASSERT(programObject);
4503 programObject->getAttachedShaders(maxcount, count, shaders);
4504}
4505
4506GLint Context::getAttribLocation(GLuint program, const GLchar *name)
4507{
4508 Program *programObject = getProgram(program);
4509 ASSERT(programObject);
4510 return programObject->getAttributeLocation(name);
4511}
4512
4513void Context::getBooleanv(GLenum pname, GLboolean *params)
4514{
4515 GLenum nativeType;
4516 unsigned int numParams = 0;
4517 getQueryParameterInfo(pname, &nativeType, &numParams);
4518
4519 if (nativeType == GL_BOOL)
4520 {
4521 getBooleanvImpl(pname, params);
4522 }
4523 else
4524 {
4525 CastStateValues(this, nativeType, pname, numParams, params);
4526 }
4527}
4528
4529void Context::getFloatv(GLenum pname, GLfloat *params)
4530{
4531 GLenum nativeType;
4532 unsigned int numParams = 0;
4533 getQueryParameterInfo(pname, &nativeType, &numParams);
4534
4535 if (nativeType == GL_FLOAT)
4536 {
4537 getFloatvImpl(pname, params);
4538 }
4539 else
4540 {
4541 CastStateValues(this, nativeType, pname, numParams, params);
4542 }
4543}
4544
4545void Context::getIntegerv(GLenum pname, GLint *params)
4546{
4547 GLenum nativeType;
4548 unsigned int numParams = 0;
4549 getQueryParameterInfo(pname, &nativeType, &numParams);
4550
4551 if (nativeType == GL_INT)
4552 {
4553 getIntegervImpl(pname, params);
4554 }
4555 else
4556 {
4557 CastStateValues(this, nativeType, pname, numParams, params);
4558 }
4559}
4560
4561void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
4562{
4563 Program *programObject = getProgram(program);
4564 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04004565 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004566}
4567
Jiajia Qin5451d532017-11-16 17:16:34 +08004568void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
4569{
4570 UNIMPLEMENTED();
4571}
4572
Jamie Madillbe849e42017-05-02 15:49:00 -04004573void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04004574{
4575 Program *programObject = getProgram(program);
4576 ASSERT(programObject);
4577 programObject->getInfoLog(bufsize, length, infolog);
4578}
4579
Jiajia Qin5451d532017-11-16 17:16:34 +08004580void Context::getProgramPipelineInfoLog(GLuint pipeline,
4581 GLsizei bufSize,
4582 GLsizei *length,
4583 GLchar *infoLog)
4584{
4585 UNIMPLEMENTED();
4586}
4587
Jamie Madillc1d770e2017-04-13 17:31:24 -04004588void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
4589{
4590 Shader *shaderObject = getShader(shader);
4591 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004592 QueryShaderiv(this, shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004593}
4594
4595void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
4596{
4597 Shader *shaderObject = getShader(shader);
4598 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004599 shaderObject->getInfoLog(this, bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004600}
4601
4602void Context::getShaderPrecisionFormat(GLenum shadertype,
4603 GLenum precisiontype,
4604 GLint *range,
4605 GLint *precision)
4606{
4607 // TODO(jmadill): Compute shaders.
4608
4609 switch (shadertype)
4610 {
4611 case GL_VERTEX_SHADER:
4612 switch (precisiontype)
4613 {
4614 case GL_LOW_FLOAT:
4615 mCaps.vertexLowpFloat.get(range, precision);
4616 break;
4617 case GL_MEDIUM_FLOAT:
4618 mCaps.vertexMediumpFloat.get(range, precision);
4619 break;
4620 case GL_HIGH_FLOAT:
4621 mCaps.vertexHighpFloat.get(range, precision);
4622 break;
4623
4624 case GL_LOW_INT:
4625 mCaps.vertexLowpInt.get(range, precision);
4626 break;
4627 case GL_MEDIUM_INT:
4628 mCaps.vertexMediumpInt.get(range, precision);
4629 break;
4630 case GL_HIGH_INT:
4631 mCaps.vertexHighpInt.get(range, precision);
4632 break;
4633
4634 default:
4635 UNREACHABLE();
4636 return;
4637 }
4638 break;
4639
4640 case GL_FRAGMENT_SHADER:
4641 switch (precisiontype)
4642 {
4643 case GL_LOW_FLOAT:
4644 mCaps.fragmentLowpFloat.get(range, precision);
4645 break;
4646 case GL_MEDIUM_FLOAT:
4647 mCaps.fragmentMediumpFloat.get(range, precision);
4648 break;
4649 case GL_HIGH_FLOAT:
4650 mCaps.fragmentHighpFloat.get(range, precision);
4651 break;
4652
4653 case GL_LOW_INT:
4654 mCaps.fragmentLowpInt.get(range, precision);
4655 break;
4656 case GL_MEDIUM_INT:
4657 mCaps.fragmentMediumpInt.get(range, precision);
4658 break;
4659 case GL_HIGH_INT:
4660 mCaps.fragmentHighpInt.get(range, precision);
4661 break;
4662
4663 default:
4664 UNREACHABLE();
4665 return;
4666 }
4667 break;
4668
4669 default:
4670 UNREACHABLE();
4671 return;
4672 }
4673}
4674
4675void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
4676{
4677 Shader *shaderObject = getShader(shader);
4678 ASSERT(shaderObject);
4679 shaderObject->getSource(bufsize, length, source);
4680}
4681
4682void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
4683{
4684 Program *programObject = getProgram(program);
4685 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04004686 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004687}
4688
4689void Context::getUniformiv(GLuint program, GLint location, GLint *params)
4690{
4691 Program *programObject = getProgram(program);
4692 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04004693 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004694}
4695
4696GLint Context::getUniformLocation(GLuint program, const GLchar *name)
4697{
4698 Program *programObject = getProgram(program);
4699 ASSERT(programObject);
4700 return programObject->getUniformLocation(name);
4701}
4702
4703GLboolean Context::isBuffer(GLuint buffer)
4704{
4705 if (buffer == 0)
4706 {
4707 return GL_FALSE;
4708 }
4709
4710 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
4711}
4712
4713GLboolean Context::isEnabled(GLenum cap)
4714{
4715 return mGLState.getEnableFeature(cap);
4716}
4717
4718GLboolean Context::isFramebuffer(GLuint framebuffer)
4719{
4720 if (framebuffer == 0)
4721 {
4722 return GL_FALSE;
4723 }
4724
4725 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
4726}
4727
4728GLboolean Context::isProgram(GLuint program)
4729{
4730 if (program == 0)
4731 {
4732 return GL_FALSE;
4733 }
4734
4735 return (getProgram(program) ? GL_TRUE : GL_FALSE);
4736}
4737
4738GLboolean Context::isRenderbuffer(GLuint renderbuffer)
4739{
4740 if (renderbuffer == 0)
4741 {
4742 return GL_FALSE;
4743 }
4744
4745 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
4746}
4747
4748GLboolean Context::isShader(GLuint shader)
4749{
4750 if (shader == 0)
4751 {
4752 return GL_FALSE;
4753 }
4754
4755 return (getShader(shader) ? GL_TRUE : GL_FALSE);
4756}
4757
4758GLboolean Context::isTexture(GLuint texture)
4759{
4760 if (texture == 0)
4761 {
4762 return GL_FALSE;
4763 }
4764
4765 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
4766}
4767
4768void Context::linkProgram(GLuint program)
4769{
4770 Program *programObject = getProgram(program);
4771 ASSERT(programObject);
4772 handleError(programObject->link(this));
Martin Radev0abb7a22017-08-28 15:34:45 +03004773 mGLState.onProgramExecutableChange(programObject);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004774}
4775
4776void Context::releaseShaderCompiler()
4777{
Jamie Madill4928b7c2017-06-20 12:57:39 -04004778 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004779}
4780
4781void Context::shaderBinary(GLsizei n,
4782 const GLuint *shaders,
4783 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04004784 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04004785 GLsizei length)
4786{
4787 // No binary shader formats are supported.
4788 UNIMPLEMENTED();
4789}
4790
4791void Context::shaderSource(GLuint shader,
4792 GLsizei count,
4793 const GLchar *const *string,
4794 const GLint *length)
4795{
4796 Shader *shaderObject = getShader(shader);
4797 ASSERT(shaderObject);
4798 shaderObject->setSource(count, string, length);
4799}
4800
4801void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
4802{
4803 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
4804}
4805
4806void Context::stencilMask(GLuint mask)
4807{
4808 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
4809}
4810
4811void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
4812{
4813 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
4814}
4815
4816void Context::uniform1f(GLint location, GLfloat x)
4817{
4818 Program *program = mGLState.getProgram();
4819 program->setUniform1fv(location, 1, &x);
4820}
4821
4822void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
4823{
4824 Program *program = mGLState.getProgram();
4825 program->setUniform1fv(location, count, v);
4826}
4827
4828void Context::uniform1i(GLint location, GLint x)
4829{
4830 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04004831 if (program->setUniform1iv(location, 1, &x) == Program::SetUniformResult::SamplerChanged)
4832 {
4833 mGLState.setObjectDirty(GL_PROGRAM);
4834 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04004835}
4836
4837void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
4838{
4839 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04004840 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
4841 {
4842 mGLState.setObjectDirty(GL_PROGRAM);
4843 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04004844}
4845
4846void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
4847{
4848 GLfloat xy[2] = {x, y};
4849 Program *program = mGLState.getProgram();
4850 program->setUniform2fv(location, 1, xy);
4851}
4852
4853void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
4854{
4855 Program *program = mGLState.getProgram();
4856 program->setUniform2fv(location, count, v);
4857}
4858
4859void Context::uniform2i(GLint location, GLint x, GLint y)
4860{
4861 GLint xy[2] = {x, y};
4862 Program *program = mGLState.getProgram();
4863 program->setUniform2iv(location, 1, xy);
4864}
4865
4866void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
4867{
4868 Program *program = mGLState.getProgram();
4869 program->setUniform2iv(location, count, v);
4870}
4871
4872void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
4873{
4874 GLfloat xyz[3] = {x, y, z};
4875 Program *program = mGLState.getProgram();
4876 program->setUniform3fv(location, 1, xyz);
4877}
4878
4879void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
4880{
4881 Program *program = mGLState.getProgram();
4882 program->setUniform3fv(location, count, v);
4883}
4884
4885void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
4886{
4887 GLint xyz[3] = {x, y, z};
4888 Program *program = mGLState.getProgram();
4889 program->setUniform3iv(location, 1, xyz);
4890}
4891
4892void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
4893{
4894 Program *program = mGLState.getProgram();
4895 program->setUniform3iv(location, count, v);
4896}
4897
4898void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4899{
4900 GLfloat xyzw[4] = {x, y, z, w};
4901 Program *program = mGLState.getProgram();
4902 program->setUniform4fv(location, 1, xyzw);
4903}
4904
4905void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
4906{
4907 Program *program = mGLState.getProgram();
4908 program->setUniform4fv(location, count, v);
4909}
4910
4911void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
4912{
4913 GLint xyzw[4] = {x, y, z, w};
4914 Program *program = mGLState.getProgram();
4915 program->setUniform4iv(location, 1, xyzw);
4916}
4917
4918void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
4919{
4920 Program *program = mGLState.getProgram();
4921 program->setUniform4iv(location, count, v);
4922}
4923
4924void Context::uniformMatrix2fv(GLint location,
4925 GLsizei count,
4926 GLboolean transpose,
4927 const GLfloat *value)
4928{
4929 Program *program = mGLState.getProgram();
4930 program->setUniformMatrix2fv(location, count, transpose, value);
4931}
4932
4933void Context::uniformMatrix3fv(GLint location,
4934 GLsizei count,
4935 GLboolean transpose,
4936 const GLfloat *value)
4937{
4938 Program *program = mGLState.getProgram();
4939 program->setUniformMatrix3fv(location, count, transpose, value);
4940}
4941
4942void Context::uniformMatrix4fv(GLint location,
4943 GLsizei count,
4944 GLboolean transpose,
4945 const GLfloat *value)
4946{
4947 Program *program = mGLState.getProgram();
4948 program->setUniformMatrix4fv(location, count, transpose, value);
4949}
4950
4951void Context::validateProgram(GLuint program)
4952{
4953 Program *programObject = getProgram(program);
4954 ASSERT(programObject);
4955 programObject->validate(mCaps);
4956}
4957
Jiajia Qin5451d532017-11-16 17:16:34 +08004958void Context::validateProgramPipeline(GLuint pipeline)
4959{
4960 UNIMPLEMENTED();
4961}
4962
Jamie Madilld04908b2017-06-09 14:15:35 -04004963void Context::getProgramBinary(GLuint program,
4964 GLsizei bufSize,
4965 GLsizei *length,
4966 GLenum *binaryFormat,
4967 void *binary)
4968{
4969 Program *programObject = getProgram(program);
4970 ASSERT(programObject != nullptr);
4971
4972 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
4973}
4974
4975void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
4976{
4977 Program *programObject = getProgram(program);
4978 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04004979
Jamie Madilld04908b2017-06-09 14:15:35 -04004980 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
4981}
4982
Jamie Madillff325f12017-08-26 15:06:05 -04004983void Context::uniform1ui(GLint location, GLuint v0)
4984{
4985 Program *program = mGLState.getProgram();
4986 program->setUniform1uiv(location, 1, &v0);
4987}
4988
4989void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
4990{
4991 Program *program = mGLState.getProgram();
4992 const GLuint xy[] = {v0, v1};
4993 program->setUniform2uiv(location, 1, xy);
4994}
4995
4996void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
4997{
4998 Program *program = mGLState.getProgram();
4999 const GLuint xyz[] = {v0, v1, v2};
5000 program->setUniform3uiv(location, 1, xyz);
5001}
5002
5003void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
5004{
5005 Program *program = mGLState.getProgram();
5006 const GLuint xyzw[] = {v0, v1, v2, v3};
5007 program->setUniform4uiv(location, 1, xyzw);
5008}
5009
5010void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
5011{
5012 Program *program = mGLState.getProgram();
5013 program->setUniform1uiv(location, count, value);
5014}
5015void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
5016{
5017 Program *program = mGLState.getProgram();
5018 program->setUniform2uiv(location, count, value);
5019}
5020
5021void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
5022{
5023 Program *program = mGLState.getProgram();
5024 program->setUniform3uiv(location, count, value);
5025}
5026
5027void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
5028{
5029 Program *program = mGLState.getProgram();
5030 program->setUniform4uiv(location, count, value);
5031}
5032
Jamie Madillf0e04492017-08-26 15:28:42 -04005033void Context::genQueries(GLsizei n, GLuint *ids)
5034{
5035 for (GLsizei i = 0; i < n; i++)
5036 {
5037 GLuint handle = mQueryHandleAllocator.allocate();
5038 mQueryMap.assign(handle, nullptr);
5039 ids[i] = handle;
5040 }
5041}
5042
5043void Context::deleteQueries(GLsizei n, const GLuint *ids)
5044{
5045 for (int i = 0; i < n; i++)
5046 {
5047 GLuint query = ids[i];
5048
5049 Query *queryObject = nullptr;
5050 if (mQueryMap.erase(query, &queryObject))
5051 {
5052 mQueryHandleAllocator.release(query);
5053 if (queryObject)
5054 {
5055 queryObject->release(this);
5056 }
5057 }
5058 }
5059}
5060
5061GLboolean Context::isQuery(GLuint id)
5062{
5063 return (getQuery(id, false, GL_NONE) != nullptr) ? GL_TRUE : GL_FALSE;
5064}
5065
Jamie Madillc8c95812017-08-26 18:40:09 -04005066void Context::uniformMatrix2x3fv(GLint location,
5067 GLsizei count,
5068 GLboolean transpose,
5069 const GLfloat *value)
5070{
5071 Program *program = mGLState.getProgram();
5072 program->setUniformMatrix2x3fv(location, count, transpose, value);
5073}
5074
5075void Context::uniformMatrix3x2fv(GLint location,
5076 GLsizei count,
5077 GLboolean transpose,
5078 const GLfloat *value)
5079{
5080 Program *program = mGLState.getProgram();
5081 program->setUniformMatrix3x2fv(location, count, transpose, value);
5082}
5083
5084void Context::uniformMatrix2x4fv(GLint location,
5085 GLsizei count,
5086 GLboolean transpose,
5087 const GLfloat *value)
5088{
5089 Program *program = mGLState.getProgram();
5090 program->setUniformMatrix2x4fv(location, count, transpose, value);
5091}
5092
5093void Context::uniformMatrix4x2fv(GLint location,
5094 GLsizei count,
5095 GLboolean transpose,
5096 const GLfloat *value)
5097{
5098 Program *program = mGLState.getProgram();
5099 program->setUniformMatrix4x2fv(location, count, transpose, value);
5100}
5101
5102void Context::uniformMatrix3x4fv(GLint location,
5103 GLsizei count,
5104 GLboolean transpose,
5105 const GLfloat *value)
5106{
5107 Program *program = mGLState.getProgram();
5108 program->setUniformMatrix3x4fv(location, count, transpose, value);
5109}
5110
5111void Context::uniformMatrix4x3fv(GLint location,
5112 GLsizei count,
5113 GLboolean transpose,
5114 const GLfloat *value)
5115{
5116 Program *program = mGLState.getProgram();
5117 program->setUniformMatrix4x3fv(location, count, transpose, value);
5118}
5119
Jamie Madilld7576732017-08-26 18:49:50 -04005120void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
5121{
5122 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5123 {
5124 GLuint vertexArray = arrays[arrayIndex];
5125
5126 if (arrays[arrayIndex] != 0)
5127 {
5128 VertexArray *vertexArrayObject = nullptr;
5129 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
5130 {
5131 if (vertexArrayObject != nullptr)
5132 {
5133 detachVertexArray(vertexArray);
5134 vertexArrayObject->onDestroy(this);
5135 }
5136
5137 mVertexArrayHandleAllocator.release(vertexArray);
5138 }
5139 }
5140 }
5141}
5142
5143void Context::genVertexArrays(GLsizei n, GLuint *arrays)
5144{
5145 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5146 {
5147 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
5148 mVertexArrayMap.assign(vertexArray, nullptr);
5149 arrays[arrayIndex] = vertexArray;
5150 }
5151}
5152
5153bool Context::isVertexArray(GLuint array)
5154{
5155 if (array == 0)
5156 {
5157 return GL_FALSE;
5158 }
5159
5160 VertexArray *vao = getVertexArray(array);
5161 return (vao != nullptr ? GL_TRUE : GL_FALSE);
5162}
5163
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04005164void Context::endTransformFeedback()
5165{
5166 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5167 transformFeedback->end(this);
5168}
5169
5170void Context::transformFeedbackVaryings(GLuint program,
5171 GLsizei count,
5172 const GLchar *const *varyings,
5173 GLenum bufferMode)
5174{
5175 Program *programObject = getProgram(program);
5176 ASSERT(programObject);
5177 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
5178}
5179
5180void Context::getTransformFeedbackVarying(GLuint program,
5181 GLuint index,
5182 GLsizei bufSize,
5183 GLsizei *length,
5184 GLsizei *size,
5185 GLenum *type,
5186 GLchar *name)
5187{
5188 Program *programObject = getProgram(program);
5189 ASSERT(programObject);
5190 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
5191}
5192
5193void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
5194{
5195 for (int i = 0; i < n; i++)
5196 {
5197 GLuint transformFeedback = ids[i];
5198 if (transformFeedback == 0)
5199 {
5200 continue;
5201 }
5202
5203 TransformFeedback *transformFeedbackObject = nullptr;
5204 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
5205 {
5206 if (transformFeedbackObject != nullptr)
5207 {
5208 detachTransformFeedback(transformFeedback);
5209 transformFeedbackObject->release(this);
5210 }
5211
5212 mTransformFeedbackHandleAllocator.release(transformFeedback);
5213 }
5214 }
5215}
5216
5217void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
5218{
5219 for (int i = 0; i < n; i++)
5220 {
5221 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
5222 mTransformFeedbackMap.assign(transformFeedback, nullptr);
5223 ids[i] = transformFeedback;
5224 }
5225}
5226
5227bool Context::isTransformFeedback(GLuint id)
5228{
5229 if (id == 0)
5230 {
5231 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
5232 // returns FALSE
5233 return GL_FALSE;
5234 }
5235
5236 const TransformFeedback *transformFeedback = getTransformFeedback(id);
5237 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
5238}
5239
5240void Context::pauseTransformFeedback()
5241{
5242 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5243 transformFeedback->pause();
5244}
5245
5246void Context::resumeTransformFeedback()
5247{
5248 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5249 transformFeedback->resume();
5250}
5251
Jamie Madill12e957f2017-08-26 21:42:26 -04005252void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
5253{
5254 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04005255 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04005256}
5257
5258GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
5259{
5260 const Program *programObject = getProgram(program);
5261 return programObject->getFragDataLocation(name);
5262}
5263
5264void Context::getUniformIndices(GLuint program,
5265 GLsizei uniformCount,
5266 const GLchar *const *uniformNames,
5267 GLuint *uniformIndices)
5268{
5269 const Program *programObject = getProgram(program);
5270 if (!programObject->isLinked())
5271 {
5272 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5273 {
5274 uniformIndices[uniformId] = GL_INVALID_INDEX;
5275 }
5276 }
5277 else
5278 {
5279 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5280 {
5281 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
5282 }
5283 }
5284}
5285
5286void Context::getActiveUniformsiv(GLuint program,
5287 GLsizei uniformCount,
5288 const GLuint *uniformIndices,
5289 GLenum pname,
5290 GLint *params)
5291{
5292 const Program *programObject = getProgram(program);
5293 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5294 {
5295 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08005296 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04005297 }
5298}
5299
5300GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
5301{
5302 const Program *programObject = getProgram(program);
5303 return programObject->getUniformBlockIndex(uniformBlockName);
5304}
5305
5306void Context::getActiveUniformBlockiv(GLuint program,
5307 GLuint uniformBlockIndex,
5308 GLenum pname,
5309 GLint *params)
5310{
5311 const Program *programObject = getProgram(program);
5312 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
5313}
5314
5315void Context::getActiveUniformBlockName(GLuint program,
5316 GLuint uniformBlockIndex,
5317 GLsizei bufSize,
5318 GLsizei *length,
5319 GLchar *uniformBlockName)
5320{
5321 const Program *programObject = getProgram(program);
5322 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
5323}
5324
5325void Context::uniformBlockBinding(GLuint program,
5326 GLuint uniformBlockIndex,
5327 GLuint uniformBlockBinding)
5328{
5329 Program *programObject = getProgram(program);
5330 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
5331}
5332
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005333GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
5334{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005335 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
5336 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005337
Jamie Madill70b5bb02017-08-28 13:32:37 -04005338 Sync *syncObject = getSync(syncHandle);
5339 Error error = syncObject->set(condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005340 if (error.isError())
5341 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04005342 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005343 handleError(error);
5344 return nullptr;
5345 }
5346
Jamie Madill70b5bb02017-08-28 13:32:37 -04005347 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005348}
5349
5350GLboolean Context::isSync(GLsync sync)
5351{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005352 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005353}
5354
5355GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
5356{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005357 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005358
5359 GLenum result = GL_WAIT_FAILED;
5360 handleError(syncObject->clientWait(flags, timeout, &result));
5361 return result;
5362}
5363
5364void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
5365{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005366 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005367 handleError(syncObject->serverWait(flags, timeout));
5368}
5369
5370void Context::getInteger64v(GLenum pname, GLint64 *params)
5371{
5372 GLenum nativeType = GL_NONE;
5373 unsigned int numParams = 0;
5374 getQueryParameterInfo(pname, &nativeType, &numParams);
5375
5376 if (nativeType == GL_INT_64_ANGLEX)
5377 {
5378 getInteger64vImpl(pname, params);
5379 }
5380 else
5381 {
5382 CastStateValues(this, nativeType, pname, numParams, params);
5383 }
5384}
5385
Corentin Wallez336129f2017-10-17 15:55:40 -04005386void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04005387{
5388 Buffer *buffer = mGLState.getTargetBuffer(target);
5389 QueryBufferParameteri64v(buffer, pname, params);
5390}
5391
5392void Context::genSamplers(GLsizei count, GLuint *samplers)
5393{
5394 for (int i = 0; i < count; i++)
5395 {
5396 samplers[i] = mState.mSamplers->createSampler();
5397 }
5398}
5399
5400void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
5401{
5402 for (int i = 0; i < count; i++)
5403 {
5404 GLuint sampler = samplers[i];
5405
5406 if (mState.mSamplers->getSampler(sampler))
5407 {
5408 detachSampler(sampler);
5409 }
5410
5411 mState.mSamplers->deleteObject(this, sampler);
5412 }
5413}
5414
5415void Context::getInternalformativ(GLenum target,
5416 GLenum internalformat,
5417 GLenum pname,
5418 GLsizei bufSize,
5419 GLint *params)
5420{
5421 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
5422 QueryInternalFormativ(formatCaps, pname, bufSize, params);
5423}
5424
Jiajia Qin5451d532017-11-16 17:16:34 +08005425void Context::programUniform1i(GLuint program, GLint location, GLint v0)
5426{
5427 programUniform1iv(program, location, 1, &v0);
5428}
5429
5430void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
5431{
5432 GLint xy[2] = {v0, v1};
5433 programUniform2iv(program, location, 1, xy);
5434}
5435
5436void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
5437{
5438 GLint xyz[3] = {v0, v1, v2};
5439 programUniform3iv(program, location, 1, xyz);
5440}
5441
5442void Context::programUniform4i(GLuint program,
5443 GLint location,
5444 GLint v0,
5445 GLint v1,
5446 GLint v2,
5447 GLint v3)
5448{
5449 GLint xyzw[4] = {v0, v1, v2, v3};
5450 programUniform4iv(program, location, 1, xyzw);
5451}
5452
5453void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
5454{
5455 programUniform1uiv(program, location, 1, &v0);
5456}
5457
5458void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
5459{
5460 GLuint xy[2] = {v0, v1};
5461 programUniform2uiv(program, location, 1, xy);
5462}
5463
5464void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
5465{
5466 GLuint xyz[3] = {v0, v1, v2};
5467 programUniform3uiv(program, location, 1, xyz);
5468}
5469
5470void Context::programUniform4ui(GLuint program,
5471 GLint location,
5472 GLuint v0,
5473 GLuint v1,
5474 GLuint v2,
5475 GLuint v3)
5476{
5477 GLuint xyzw[4] = {v0, v1, v2, v3};
5478 programUniform4uiv(program, location, 1, xyzw);
5479}
5480
5481void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
5482{
5483 programUniform1fv(program, location, 1, &v0);
5484}
5485
5486void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
5487{
5488 GLfloat xy[2] = {v0, v1};
5489 programUniform2fv(program, location, 1, xy);
5490}
5491
5492void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
5493{
5494 GLfloat xyz[3] = {v0, v1, v2};
5495 programUniform3fv(program, location, 1, xyz);
5496}
5497
5498void Context::programUniform4f(GLuint program,
5499 GLint location,
5500 GLfloat v0,
5501 GLfloat v1,
5502 GLfloat v2,
5503 GLfloat v3)
5504{
5505 GLfloat xyzw[4] = {v0, v1, v2, v3};
5506 programUniform4fv(program, location, 1, xyzw);
5507}
5508
Jamie Madill81c2e252017-09-09 23:32:46 -04005509void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5510{
5511 Program *programObject = getProgram(program);
5512 ASSERT(programObject);
5513 if (programObject->setUniform1iv(location, count, value) ==
5514 Program::SetUniformResult::SamplerChanged)
5515 {
5516 mGLState.setObjectDirty(GL_PROGRAM);
5517 }
5518}
5519
Jiajia Qin5451d532017-11-16 17:16:34 +08005520void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5521{
5522 Program *programObject = getProgram(program);
5523 ASSERT(programObject);
5524 programObject->setUniform2iv(location, count, value);
5525}
5526
5527void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5528{
5529 Program *programObject = getProgram(program);
5530 ASSERT(programObject);
5531 programObject->setUniform3iv(location, count, value);
5532}
5533
5534void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5535{
5536 Program *programObject = getProgram(program);
5537 ASSERT(programObject);
5538 programObject->setUniform4iv(location, count, value);
5539}
5540
5541void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5542{
5543 Program *programObject = getProgram(program);
5544 ASSERT(programObject);
5545 programObject->setUniform1uiv(location, count, value);
5546}
5547
5548void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5549{
5550 Program *programObject = getProgram(program);
5551 ASSERT(programObject);
5552 programObject->setUniform2uiv(location, count, value);
5553}
5554
5555void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5556{
5557 Program *programObject = getProgram(program);
5558 ASSERT(programObject);
5559 programObject->setUniform3uiv(location, count, value);
5560}
5561
5562void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5563{
5564 Program *programObject = getProgram(program);
5565 ASSERT(programObject);
5566 programObject->setUniform4uiv(location, count, value);
5567}
5568
5569void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5570{
5571 Program *programObject = getProgram(program);
5572 ASSERT(programObject);
5573 programObject->setUniform1fv(location, count, value);
5574}
5575
5576void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5577{
5578 Program *programObject = getProgram(program);
5579 ASSERT(programObject);
5580 programObject->setUniform2fv(location, count, value);
5581}
5582
5583void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5584{
5585 Program *programObject = getProgram(program);
5586 ASSERT(programObject);
5587 programObject->setUniform3fv(location, count, value);
5588}
5589
5590void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5591{
5592 Program *programObject = getProgram(program);
5593 ASSERT(programObject);
5594 programObject->setUniform4fv(location, count, value);
5595}
5596
5597void Context::programUniformMatrix2fv(GLuint program,
5598 GLint location,
5599 GLsizei count,
5600 GLboolean transpose,
5601 const GLfloat *value)
5602{
5603 Program *programObject = getProgram(program);
5604 ASSERT(programObject);
5605 programObject->setUniformMatrix2fv(location, count, transpose, value);
5606}
5607
5608void Context::programUniformMatrix3fv(GLuint program,
5609 GLint location,
5610 GLsizei count,
5611 GLboolean transpose,
5612 const GLfloat *value)
5613{
5614 Program *programObject = getProgram(program);
5615 ASSERT(programObject);
5616 programObject->setUniformMatrix3fv(location, count, transpose, value);
5617}
5618
5619void Context::programUniformMatrix4fv(GLuint program,
5620 GLint location,
5621 GLsizei count,
5622 GLboolean transpose,
5623 const GLfloat *value)
5624{
5625 Program *programObject = getProgram(program);
5626 ASSERT(programObject);
5627 programObject->setUniformMatrix4fv(location, count, transpose, value);
5628}
5629
5630void Context::programUniformMatrix2x3fv(GLuint program,
5631 GLint location,
5632 GLsizei count,
5633 GLboolean transpose,
5634 const GLfloat *value)
5635{
5636 Program *programObject = getProgram(program);
5637 ASSERT(programObject);
5638 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
5639}
5640
5641void Context::programUniformMatrix3x2fv(GLuint program,
5642 GLint location,
5643 GLsizei count,
5644 GLboolean transpose,
5645 const GLfloat *value)
5646{
5647 Program *programObject = getProgram(program);
5648 ASSERT(programObject);
5649 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
5650}
5651
5652void Context::programUniformMatrix2x4fv(GLuint program,
5653 GLint location,
5654 GLsizei count,
5655 GLboolean transpose,
5656 const GLfloat *value)
5657{
5658 Program *programObject = getProgram(program);
5659 ASSERT(programObject);
5660 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
5661}
5662
5663void Context::programUniformMatrix4x2fv(GLuint program,
5664 GLint location,
5665 GLsizei count,
5666 GLboolean transpose,
5667 const GLfloat *value)
5668{
5669 Program *programObject = getProgram(program);
5670 ASSERT(programObject);
5671 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
5672}
5673
5674void Context::programUniformMatrix3x4fv(GLuint program,
5675 GLint location,
5676 GLsizei count,
5677 GLboolean transpose,
5678 const GLfloat *value)
5679{
5680 Program *programObject = getProgram(program);
5681 ASSERT(programObject);
5682 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
5683}
5684
5685void Context::programUniformMatrix4x3fv(GLuint program,
5686 GLint location,
5687 GLsizei count,
5688 GLboolean transpose,
5689 const GLfloat *value)
5690{
5691 Program *programObject = getProgram(program);
5692 ASSERT(programObject);
5693 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
5694}
5695
Jamie Madill81c2e252017-09-09 23:32:46 -04005696void Context::onTextureChange(const Texture *texture)
5697{
5698 // Conservatively assume all textures are dirty.
5699 // TODO(jmadill): More fine-grained update.
5700 mGLState.setObjectDirty(GL_TEXTURE);
5701}
5702
James Darpiniane8a93c62018-01-04 18:02:24 -08005703bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
5704{
5705 return mGLState.isCurrentTransformFeedback(tf);
5706}
5707bool Context::isCurrentVertexArray(const VertexArray *va) const
5708{
5709 return mGLState.isCurrentVertexArray(va);
5710}
5711
Yunchao Hea336b902017-08-02 16:05:21 +08005712void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
5713{
5714 for (int i = 0; i < count; i++)
5715 {
5716 pipelines[i] = createProgramPipeline();
5717 }
5718}
5719
5720void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
5721{
5722 for (int i = 0; i < count; i++)
5723 {
5724 if (pipelines[i] != 0)
5725 {
5726 deleteProgramPipeline(pipelines[i]);
5727 }
5728 }
5729}
5730
5731GLboolean Context::isProgramPipeline(GLuint pipeline)
5732{
5733 if (pipeline == 0)
5734 {
5735 return GL_FALSE;
5736 }
5737
5738 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
5739}
5740
Jamie Madill2b7bbc22017-12-21 17:30:38 -05005741void Context::finishFenceNV(GLuint fence)
5742{
5743 FenceNV *fenceObject = getFenceNV(fence);
5744
5745 ASSERT(fenceObject && fenceObject->isSet());
5746 handleError(fenceObject->finish());
5747}
5748
5749void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
5750{
5751 FenceNV *fenceObject = getFenceNV(fence);
5752
5753 ASSERT(fenceObject && fenceObject->isSet());
5754
5755 switch (pname)
5756 {
5757 case GL_FENCE_STATUS_NV:
5758 {
5759 // GL_NV_fence spec:
5760 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
5761 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
5762 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
5763 GLboolean status = GL_TRUE;
5764 if (fenceObject->getStatus() != GL_TRUE)
5765 {
5766 ANGLE_CONTEXT_TRY(fenceObject->test(&status));
5767 }
5768 *params = status;
5769 break;
5770 }
5771
5772 case GL_FENCE_CONDITION_NV:
5773 {
5774 *params = static_cast<GLint>(fenceObject->getCondition());
5775 break;
5776 }
5777
5778 default:
5779 UNREACHABLE();
5780 }
5781}
5782
5783void Context::getTranslatedShaderSource(GLuint shader,
5784 GLsizei bufsize,
5785 GLsizei *length,
5786 GLchar *source)
5787{
5788 Shader *shaderObject = getShader(shader);
5789 ASSERT(shaderObject);
5790 shaderObject->getTranslatedSourceWithDebugInfo(this, bufsize, length, source);
5791}
5792
5793void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
5794{
5795 Program *programObject = getProgram(program);
5796 ASSERT(programObject);
5797
5798 programObject->getUniformfv(this, location, params);
5799}
5800
5801void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
5802{
5803 Program *programObject = getProgram(program);
5804 ASSERT(programObject);
5805
5806 programObject->getUniformiv(this, location, params);
5807}
5808
5809GLboolean Context::isFenceNV(GLuint fence)
5810{
5811 FenceNV *fenceObject = getFenceNV(fence);
5812
5813 if (fenceObject == nullptr)
5814 {
5815 return GL_FALSE;
5816 }
5817
5818 // GL_NV_fence spec:
5819 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
5820 // existing fence.
5821 return fenceObject->isSet();
5822}
5823
5824void Context::readnPixels(GLint x,
5825 GLint y,
5826 GLsizei width,
5827 GLsizei height,
5828 GLenum format,
5829 GLenum type,
5830 GLsizei bufSize,
5831 void *data)
5832{
5833 return readPixels(x, y, width, height, format, type, data);
5834}
5835
Jamie Madill007530e2017-12-28 14:27:04 -05005836void Context::setFenceNV(GLuint fence, GLenum condition)
5837{
5838 ASSERT(condition == GL_ALL_COMPLETED_NV);
5839
5840 FenceNV *fenceObject = getFenceNV(fence);
5841 ASSERT(fenceObject != nullptr);
5842 handleError(fenceObject->set(condition));
5843}
5844
5845GLboolean Context::testFenceNV(GLuint fence)
5846{
5847 FenceNV *fenceObject = getFenceNV(fence);
5848
5849 ASSERT(fenceObject != nullptr);
5850 ASSERT(fenceObject->isSet() == GL_TRUE);
5851
5852 GLboolean result = GL_TRUE;
5853 Error error = fenceObject->test(&result);
5854 if (error.isError())
5855 {
5856 handleError(error);
5857 return GL_TRUE;
5858 }
5859
5860 return result;
5861}
5862
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005863void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05005864{
5865 Texture *texture = getTargetTexture(target);
5866 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005867 handleError(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05005868}
5869
Jamie Madillfa920eb2018-01-04 11:45:50 -05005870void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05005871{
5872 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
5873 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
5874 handleError(renderbuffer->setStorageEGLImageTarget(this, imageObject));
5875}
5876
Jamie Madillfa920eb2018-01-04 11:45:50 -05005877void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
5878{
5879 UNIMPLEMENTED();
5880}
5881
Geoff Lang2aaa7b42018-01-12 17:17:27 -05005882void Context::alphaFunc(GLenum func, GLfloat ref)
5883{
5884 UNIMPLEMENTED();
5885}
5886
5887void Context::alphaFuncx(GLenum func, GLfixed ref)
5888{
5889 UNIMPLEMENTED();
5890}
5891
5892void Context::clearColorx(GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha)
5893{
5894 UNIMPLEMENTED();
5895}
5896
5897void Context::clearDepthx(GLfixed depth)
5898{
5899 UNIMPLEMENTED();
5900}
5901
5902void Context::clientActiveTexture(GLenum texture)
5903{
5904 UNIMPLEMENTED();
5905}
5906
5907void Context::clipPlanef(GLenum p, const GLfloat *eqn)
5908{
5909 UNIMPLEMENTED();
5910}
5911
5912void Context::clipPlanex(GLenum plane, const GLfixed *equation)
5913{
5914 UNIMPLEMENTED();
5915}
5916
5917void Context::color4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
5918{
5919 UNIMPLEMENTED();
5920}
5921
5922void Context::color4ub(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha)
5923{
5924 UNIMPLEMENTED();
5925}
5926
5927void Context::color4x(GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha)
5928{
5929 UNIMPLEMENTED();
5930}
5931
5932void Context::colorPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
5933{
5934 UNIMPLEMENTED();
5935}
5936
5937void Context::cullFace(GLenum mode)
5938{
5939 UNIMPLEMENTED();
5940}
5941
5942void Context::depthRangex(GLfixed n, GLfixed f)
5943{
5944 UNIMPLEMENTED();
5945}
5946
5947void Context::disableClientState(GLenum array)
5948{
5949 UNIMPLEMENTED();
5950}
5951
5952void Context::enableClientState(GLenum array)
5953{
5954 UNIMPLEMENTED();
5955}
5956
5957void Context::fogf(GLenum pname, GLfloat param)
5958{
5959 UNIMPLEMENTED();
5960}
5961
5962void Context::fogfv(GLenum pname, const GLfloat *params)
5963{
5964 UNIMPLEMENTED();
5965}
5966
5967void Context::fogx(GLenum pname, GLfixed param)
5968{
5969 UNIMPLEMENTED();
5970}
5971
5972void Context::fogxv(GLenum pname, const GLfixed *param)
5973{
5974 UNIMPLEMENTED();
5975}
5976
5977void Context::frustumf(GLfloat l, GLfloat r, GLfloat b, GLfloat t, GLfloat n, GLfloat f)
5978{
5979 UNIMPLEMENTED();
5980}
5981
5982void Context::frustumx(GLfixed l, GLfixed r, GLfixed b, GLfixed t, GLfixed n, GLfixed f)
5983{
5984 UNIMPLEMENTED();
5985}
5986
5987void Context::getBufferParameteriv(GLenum target, GLenum pname, GLint *params)
5988{
5989 UNIMPLEMENTED();
5990}
5991
5992void Context::getClipPlanef(GLenum plane, GLfloat *equation)
5993{
5994 UNIMPLEMENTED();
5995}
5996
5997void Context::getClipPlanex(GLenum plane, GLfixed *equation)
5998{
5999 UNIMPLEMENTED();
6000}
6001
6002void Context::getFixedv(GLenum pname, GLfixed *params)
6003{
6004 UNIMPLEMENTED();
6005}
6006
6007void Context::getLightfv(GLenum light, GLenum pname, GLfloat *params)
6008{
6009 UNIMPLEMENTED();
6010}
6011
6012void Context::getLightxv(GLenum light, GLenum pname, GLfixed *params)
6013{
6014 UNIMPLEMENTED();
6015}
6016
6017void Context::getMaterialfv(GLenum face, GLenum pname, GLfloat *params)
6018{
6019 UNIMPLEMENTED();
6020}
6021
6022void Context::getMaterialxv(GLenum face, GLenum pname, GLfixed *params)
6023{
6024 UNIMPLEMENTED();
6025}
6026
6027void Context::getTexEnvfv(GLenum target, GLenum pname, GLfloat *params)
6028{
6029 UNIMPLEMENTED();
6030}
6031
6032void Context::getTexEnviv(GLenum target, GLenum pname, GLint *params)
6033{
6034 UNIMPLEMENTED();
6035}
6036
6037void Context::getTexEnvxv(GLenum target, GLenum pname, GLfixed *params)
6038{
6039 UNIMPLEMENTED();
6040}
6041
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006042void Context::getTexParameterxv(TextureType target, GLenum pname, GLfixed *params)
Geoff Lang2aaa7b42018-01-12 17:17:27 -05006043{
6044 UNIMPLEMENTED();
6045}
6046
6047void Context::lightModelf(GLenum pname, GLfloat param)
6048{
6049 UNIMPLEMENTED();
6050}
6051
6052void Context::lightModelfv(GLenum pname, const GLfloat *params)
6053{
6054 UNIMPLEMENTED();
6055}
6056
6057void Context::lightModelx(GLenum pname, GLfixed param)
6058{
6059 UNIMPLEMENTED();
6060}
6061
6062void Context::lightModelxv(GLenum pname, const GLfixed *param)
6063{
6064 UNIMPLEMENTED();
6065}
6066
6067void Context::lightf(GLenum light, GLenum pname, GLfloat param)
6068{
6069 UNIMPLEMENTED();
6070}
6071
6072void Context::lightfv(GLenum light, GLenum pname, const GLfloat *params)
6073{
6074 UNIMPLEMENTED();
6075}
6076
6077void Context::lightx(GLenum light, GLenum pname, GLfixed param)
6078{
6079 UNIMPLEMENTED();
6080}
6081
6082void Context::lightxv(GLenum light, GLenum pname, const GLfixed *params)
6083{
6084 UNIMPLEMENTED();
6085}
6086
6087void Context::lineWidthx(GLfixed width)
6088{
6089 UNIMPLEMENTED();
6090}
6091
6092void Context::loadIdentity()
6093{
6094 UNIMPLEMENTED();
6095}
6096
6097void Context::loadMatrixf(const GLfloat *m)
6098{
6099 UNIMPLEMENTED();
6100}
6101
6102void Context::loadMatrixx(const GLfixed *m)
6103{
6104 UNIMPLEMENTED();
6105}
6106
6107void Context::logicOp(GLenum opcode)
6108{
6109 UNIMPLEMENTED();
6110}
6111
6112void Context::materialf(GLenum face, GLenum pname, GLfloat param)
6113{
6114 UNIMPLEMENTED();
6115}
6116
6117void Context::materialfv(GLenum face, GLenum pname, const GLfloat *params)
6118{
6119 UNIMPLEMENTED();
6120}
6121
6122void Context::materialx(GLenum face, GLenum pname, GLfixed param)
6123{
6124 UNIMPLEMENTED();
6125}
6126
6127void Context::materialxv(GLenum face, GLenum pname, const GLfixed *param)
6128{
6129 UNIMPLEMENTED();
6130}
6131
6132void Context::matrixMode(GLenum mode)
6133{
6134 UNIMPLEMENTED();
6135}
6136
6137void Context::multMatrixf(const GLfloat *m)
6138{
6139 UNIMPLEMENTED();
6140}
6141
6142void Context::multMatrixx(const GLfixed *m)
6143{
6144 UNIMPLEMENTED();
6145}
6146
6147void Context::multiTexCoord4f(GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q)
6148{
6149 UNIMPLEMENTED();
6150}
6151
6152void Context::multiTexCoord4x(GLenum texture, GLfixed s, GLfixed t, GLfixed r, GLfixed q)
6153{
6154 UNIMPLEMENTED();
6155}
6156
6157void Context::normal3f(GLfloat nx, GLfloat ny, GLfloat nz)
6158{
6159 UNIMPLEMENTED();
6160}
6161
6162void Context::normal3x(GLfixed nx, GLfixed ny, GLfixed nz)
6163{
6164 UNIMPLEMENTED();
6165}
6166
6167void Context::normalPointer(GLenum type, GLsizei stride, const void *pointer)
6168{
6169 UNIMPLEMENTED();
6170}
6171
6172void Context::orthof(GLfloat l, GLfloat r, GLfloat b, GLfloat t, GLfloat n, GLfloat f)
6173{
6174 UNIMPLEMENTED();
6175}
6176
6177void Context::orthox(GLfixed l, GLfixed r, GLfixed b, GLfixed t, GLfixed n, GLfixed f)
6178{
6179 UNIMPLEMENTED();
6180}
6181
6182void Context::pointParameterf(GLenum pname, GLfloat param)
6183{
6184 UNIMPLEMENTED();
6185}
6186
6187void Context::pointParameterfv(GLenum pname, const GLfloat *params)
6188{
6189 UNIMPLEMENTED();
6190}
6191
6192void Context::pointParameterx(GLenum pname, GLfixed param)
6193{
6194 UNIMPLEMENTED();
6195}
6196
6197void Context::pointParameterxv(GLenum pname, const GLfixed *params)
6198{
6199 UNIMPLEMENTED();
6200}
6201
6202void Context::pointSize(GLfloat size)
6203{
6204 UNIMPLEMENTED();
6205}
6206
6207void Context::pointSizex(GLfixed size)
6208{
6209 UNIMPLEMENTED();
6210}
6211
6212void Context::polygonOffsetx(GLfixed factor, GLfixed units)
6213{
6214 UNIMPLEMENTED();
6215}
6216
6217void Context::popMatrix()
6218{
6219 UNIMPLEMENTED();
6220}
6221
6222void Context::pushMatrix()
6223{
6224 UNIMPLEMENTED();
6225}
6226
6227void Context::rotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z)
6228{
6229 UNIMPLEMENTED();
6230}
6231
6232void Context::rotatex(GLfixed angle, GLfixed x, GLfixed y, GLfixed z)
6233{
6234 UNIMPLEMENTED();
6235}
6236
6237void Context::sampleCoveragex(GLclampx value, GLboolean invert)
6238{
6239 UNIMPLEMENTED();
6240}
6241
6242void Context::scalef(GLfloat x, GLfloat y, GLfloat z)
6243{
6244 UNIMPLEMENTED();
6245}
6246
6247void Context::scalex(GLfixed x, GLfixed y, GLfixed z)
6248{
6249 UNIMPLEMENTED();
6250}
6251
6252void Context::shadeModel(GLenum mode)
6253{
6254 UNIMPLEMENTED();
6255}
6256
6257void Context::texCoordPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
6258{
6259 UNIMPLEMENTED();
6260}
6261
6262void Context::texEnvf(GLenum target, GLenum pname, GLfloat param)
6263{
6264 UNIMPLEMENTED();
6265}
6266
6267void Context::texEnvfv(GLenum target, GLenum pname, const GLfloat *params)
6268{
6269 UNIMPLEMENTED();
6270}
6271
6272void Context::texEnvi(GLenum target, GLenum pname, GLint param)
6273{
6274 UNIMPLEMENTED();
6275}
6276
6277void Context::texEnviv(GLenum target, GLenum pname, const GLint *params)
6278{
6279 UNIMPLEMENTED();
6280}
6281
6282void Context::texEnvx(GLenum target, GLenum pname, GLfixed param)
6283{
6284 UNIMPLEMENTED();
6285}
6286
6287void Context::texEnvxv(GLenum target, GLenum pname, const GLfixed *params)
6288{
6289 UNIMPLEMENTED();
6290}
6291
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006292void Context::texParameterx(TextureType target, GLenum pname, GLfixed param)
Geoff Lang2aaa7b42018-01-12 17:17:27 -05006293{
6294 UNIMPLEMENTED();
6295}
6296
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006297void Context::texParameterxv(TextureType target, GLenum pname, const GLfixed *params)
Geoff Lang2aaa7b42018-01-12 17:17:27 -05006298{
6299 UNIMPLEMENTED();
6300}
6301
6302void Context::translatef(GLfloat x, GLfloat y, GLfloat z)
6303{
6304 UNIMPLEMENTED();
6305}
6306
6307void Context::translatex(GLfixed x, GLfixed y, GLfixed z)
6308{
6309 UNIMPLEMENTED();
6310}
6311
6312void Context::vertexPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
6313{
6314 UNIMPLEMENTED();
6315}
6316
6317void Context::drawTexf(GLfloat x, GLfloat y, GLfloat z, GLfloat width, GLfloat height)
6318{
6319 UNIMPLEMENTED();
6320}
6321
6322void Context::drawTexfv(const GLfloat *coords)
6323{
6324 UNIMPLEMENTED();
6325}
6326
6327void Context::drawTexi(GLint x, GLint y, GLint z, GLint width, GLint height)
6328{
6329 UNIMPLEMENTED();
6330}
6331
6332void Context::drawTexiv(const GLint *coords)
6333{
6334 UNIMPLEMENTED();
6335}
6336
6337void Context::drawTexs(GLshort x, GLshort y, GLshort z, GLshort width, GLshort height)
6338{
6339 UNIMPLEMENTED();
6340}
6341
6342void Context::drawTexsv(const GLshort *coords)
6343{
6344 UNIMPLEMENTED();
6345}
6346
6347void Context::drawTexx(GLfixed x, GLfixed y, GLfixed z, GLfixed width, GLfixed height)
6348{
6349 UNIMPLEMENTED();
6350}
6351
6352void Context::drawTexxv(const GLfixed *coords)
6353{
6354 UNIMPLEMENTED();
6355}
6356
6357void Context::currentPaletteMatrix(GLuint matrixpaletteindex)
6358{
6359 UNIMPLEMENTED();
6360}
6361
6362void Context::loadPaletteFromModelViewMatrix()
6363{
6364 UNIMPLEMENTED();
6365}
6366
6367void Context::matrixIndexPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
6368{
6369 UNIMPLEMENTED();
6370}
6371
6372void Context::weightPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
6373{
6374 UNIMPLEMENTED();
6375}
6376
6377void Context::pointSizePointer(GLenum type, GLsizei stride, const void *pointer)
6378{
6379 UNIMPLEMENTED();
6380}
6381
6382GLbitfield Context::queryMatrixx(GLfixed *mantissa, GLint *exponent)
6383{
6384 UNIMPLEMENTED();
6385 return 0;
6386}
6387
Jamie Madillc29968b2016-01-20 11:17:23 -05006388} // namespace gl