blob: 449fad2d9dfbd99d13811c3e3b324af56f64cccd [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{
Geoff Langd4fff502017-09-22 11:28:28 -04002910 ANGLE_TRY(syncRendererDirtyObjects());
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
Geoff Langd4fff502017-09-22 11:28:28 -04002918 ANGLE_TRY(syncRendererDirtyBits());
2919 return NoError();
2920}
2921
2922Error Context::prepareForClear(GLbitfield mask)
2923{
2924 ANGLE_TRY(syncRendererDirtyObjects(mClearDirtyObjects));
2925 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearAttachmentsInitialized(this, mask));
2926 ANGLE_TRY(syncRendererDirtyBits(mClearDirtyBits));
2927 return NoError();
2928}
2929
2930Error Context::prepareForClearBuffer(GLenum buffer, GLint drawbuffer)
2931{
2932 ANGLE_TRY(syncRendererDirtyObjects(mClearDirtyObjects));
2933 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearBufferAttachmentsInitialized(this, buffer,
2934 drawbuffer));
2935 ANGLE_TRY(syncRendererDirtyBits(mClearDirtyBits));
Jamie Madill05b35b22017-10-03 09:01:44 -04002936 return NoError();
2937}
2938
Jamie Madillbc918e72018-03-08 09:47:21 -05002939Error Context::syncRendererState()
Jamie Madill1b94d432015-08-07 13:23:23 -04002940{
Geoff Langd4fff502017-09-22 11:28:28 -04002941 ANGLE_TRY(syncRendererDirtyObjects());
2942 ANGLE_TRY(syncRendererDirtyBits());
Jamie Madillbc918e72018-03-08 09:47:21 -05002943 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04002944}
2945
Jamie Madillbc918e72018-03-08 09:47:21 -05002946Error Context::syncRendererState(const State::DirtyBits &bitMask,
2947 const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04002948{
Geoff Langd4fff502017-09-22 11:28:28 -04002949 ANGLE_TRY(syncRendererDirtyObjects(objectMask));
2950 ANGLE_TRY(syncRendererDirtyBits(bitMask));
2951 return NoError();
2952}
2953
2954Error Context::syncRendererDirtyBits()
2955{
2956 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
2957 mImplementation->syncState(this, dirtyBits);
2958 mGLState.clearDirtyBits();
2959 return NoError();
2960}
2961
2962Error Context::syncRendererDirtyBits(const State::DirtyBits &bitMask)
2963{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002964 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madillfe548342017-06-19 11:13:24 -04002965 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002966 mGLState.clearDirtyBits(dirtyBits);
Jamie Madillbc918e72018-03-08 09:47:21 -05002967 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04002968}
Jamie Madillc29968b2016-01-20 11:17:23 -05002969
Geoff Langd4fff502017-09-22 11:28:28 -04002970Error Context::syncRendererDirtyObjects()
2971{
2972 return mGLState.syncDirtyObjects(this);
2973}
2974
2975Error Context::syncRendererDirtyObjects(const State::DirtyObjects &objectMask)
2976{
2977 return mGLState.syncDirtyObjects(this, objectMask);
2978}
2979
Jamie Madillc29968b2016-01-20 11:17:23 -05002980void Context::blitFramebuffer(GLint srcX0,
2981 GLint srcY0,
2982 GLint srcX1,
2983 GLint srcY1,
2984 GLint dstX0,
2985 GLint dstY0,
2986 GLint dstX1,
2987 GLint dstY1,
2988 GLbitfield mask,
2989 GLenum filter)
2990{
Qin Jiajiaaef92162018-02-27 13:51:44 +08002991 if (mask == 0)
2992 {
2993 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
2994 // buffers are copied.
2995 return;
2996 }
2997
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002998 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002999 ASSERT(drawFramebuffer);
3000
3001 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
3002 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
3003
Jamie Madillbc918e72018-03-08 09:47:21 -05003004 ANGLE_CONTEXT_TRY(syncStateForBlit());
Jamie Madillc29968b2016-01-20 11:17:23 -05003005
Jamie Madillc564c072017-06-01 12:45:42 -04003006 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003007}
Jamie Madillc29968b2016-01-20 11:17:23 -05003008
3009void Context::clear(GLbitfield mask)
3010{
Geoff Langd4fff502017-09-22 11:28:28 -04003011 ANGLE_CONTEXT_TRY(prepareForClear(mask));
3012 ANGLE_CONTEXT_TRY(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05003013}
3014
3015void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
3016{
Geoff Langd4fff502017-09-22 11:28:28 -04003017 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3018 ANGLE_CONTEXT_TRY(
3019 mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003020}
3021
3022void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3023{
Geoff Langd4fff502017-09-22 11:28:28 -04003024 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3025 ANGLE_CONTEXT_TRY(
3026 mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003027}
3028
3029void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3030{
Geoff Langd4fff502017-09-22 11:28:28 -04003031 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3032 ANGLE_CONTEXT_TRY(
3033 mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003034}
3035
3036void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3037{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003038 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003039 ASSERT(framebufferObject);
3040
3041 // If a buffer is not present, the clear has no effect
3042 if (framebufferObject->getDepthbuffer() == nullptr &&
3043 framebufferObject->getStencilbuffer() == nullptr)
3044 {
3045 return;
3046 }
3047
Geoff Langd4fff502017-09-22 11:28:28 -04003048 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3049 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003050}
3051
3052void Context::readPixels(GLint x,
3053 GLint y,
3054 GLsizei width,
3055 GLsizei height,
3056 GLenum format,
3057 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003058 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003059{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003060 if (width == 0 || height == 0)
3061 {
3062 return;
3063 }
3064
Jamie Madillbc918e72018-03-08 09:47:21 -05003065 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003066
Jamie Madillb6664922017-07-25 12:55:04 -04003067 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3068 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003069
3070 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04003071 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003072}
3073
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003074void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003075 GLint level,
3076 GLenum internalformat,
3077 GLint x,
3078 GLint y,
3079 GLsizei width,
3080 GLsizei height,
3081 GLint border)
3082{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003083 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003084 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003085
Jamie Madillc29968b2016-01-20 11:17:23 -05003086 Rectangle sourceArea(x, y, width, height);
3087
Jamie Madill05b35b22017-10-03 09:01:44 -04003088 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003089 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003090 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003091}
3092
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003093void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003094 GLint level,
3095 GLint xoffset,
3096 GLint yoffset,
3097 GLint x,
3098 GLint y,
3099 GLsizei width,
3100 GLsizei height)
3101{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003102 if (width == 0 || height == 0)
3103 {
3104 return;
3105 }
3106
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003107 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003108 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003109
Jamie Madillc29968b2016-01-20 11:17:23 -05003110 Offset destOffset(xoffset, yoffset, 0);
3111 Rectangle sourceArea(x, y, width, height);
3112
Jamie Madill05b35b22017-10-03 09:01:44 -04003113 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003114 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003115 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003116}
3117
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003118void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003119 GLint level,
3120 GLint xoffset,
3121 GLint yoffset,
3122 GLint zoffset,
3123 GLint x,
3124 GLint y,
3125 GLsizei width,
3126 GLsizei height)
3127{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003128 if (width == 0 || height == 0)
3129 {
3130 return;
3131 }
3132
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003133 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003134 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003135
Jamie Madillc29968b2016-01-20 11:17:23 -05003136 Offset destOffset(xoffset, yoffset, zoffset);
3137 Rectangle sourceArea(x, y, width, height);
3138
Jamie Madill05b35b22017-10-03 09:01:44 -04003139 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3140 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003141 handleError(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level, destOffset,
3142 sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003143}
3144
3145void Context::framebufferTexture2D(GLenum target,
3146 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003147 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003148 GLuint texture,
3149 GLint level)
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 (texture != 0)
3155 {
3156 Texture *textureObj = getTexture(texture);
3157
3158 ImageIndex index = ImageIndex::MakeInvalid();
3159
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003160 if (textarget == TextureTarget::_2D)
Jamie Madillc29968b2016-01-20 11:17:23 -05003161 {
3162 index = ImageIndex::Make2D(level);
3163 }
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003164 else if (textarget == TextureTarget::Rectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -04003165 {
3166 index = ImageIndex::MakeRectangle(level);
3167 }
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003168 else if (textarget == TextureTarget::_2DMultisample)
JiangYizhoubddc46b2016-12-09 09:50:51 +08003169 {
3170 ASSERT(level == 0);
3171 index = ImageIndex::Make2DMultisample();
3172 }
Jamie Madillc29968b2016-01-20 11:17:23 -05003173 else
3174 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003175 ASSERT(TextureTargetToType(textarget) == TextureType::CubeMap);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003176 index = ImageIndex::MakeCube(textarget, level);
Jamie Madillc29968b2016-01-20 11:17:23 -05003177 }
3178
Jamie Madilla02315b2017-02-23 14:14:47 -05003179 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003180 }
3181 else
3182 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003183 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003184 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003185
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003186 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003187}
3188
3189void Context::framebufferRenderbuffer(GLenum target,
3190 GLenum attachment,
3191 GLenum renderbuffertarget,
3192 GLuint renderbuffer)
3193{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003194 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003195 ASSERT(framebuffer);
3196
3197 if (renderbuffer != 0)
3198 {
3199 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003200
3201 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex::MakeInvalid(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003202 renderbufferObject);
3203 }
3204 else
3205 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003206 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003207 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003208
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003209 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003210}
3211
3212void Context::framebufferTextureLayer(GLenum target,
3213 GLenum attachment,
3214 GLuint texture,
3215 GLint level,
3216 GLint layer)
3217{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003218 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003219 ASSERT(framebuffer);
3220
3221 if (texture != 0)
3222 {
3223 Texture *textureObject = getTexture(texture);
3224
3225 ImageIndex index = ImageIndex::MakeInvalid();
3226
Corentin Wallez99d492c2018-02-27 15:17:10 -05003227 if (textureObject->getType() == TextureType::_3D)
Jamie Madillc29968b2016-01-20 11:17:23 -05003228 {
3229 index = ImageIndex::Make3D(level, layer);
3230 }
3231 else
3232 {
Corentin Wallez99d492c2018-02-27 15:17:10 -05003233 ASSERT(textureObject->getType() == TextureType::_2DArray);
Jamie Madillc29968b2016-01-20 11:17:23 -05003234 index = ImageIndex::Make2DArray(level, layer);
3235 }
3236
Jamie Madilla02315b2017-02-23 14:14:47 -05003237 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003238 }
3239 else
3240 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003241 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003242 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003243
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003244 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003245}
3246
Martin Radev137032d2017-07-13 10:11:12 +03003247void Context::framebufferTextureMultiviewLayeredANGLE(GLenum target,
3248 GLenum attachment,
3249 GLuint texture,
3250 GLint level,
3251 GLint baseViewIndex,
3252 GLsizei numViews)
3253{
Martin Radev82ef7742017-08-08 17:44:58 +03003254 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3255 ASSERT(framebuffer);
3256
3257 if (texture != 0)
3258 {
3259 Texture *textureObj = getTexture(texture);
3260
Martin Radev18b75ba2017-08-15 15:50:40 +03003261 ImageIndex index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
Martin Radev82ef7742017-08-08 17:44:58 +03003262 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3263 numViews, baseViewIndex);
3264 }
3265 else
3266 {
3267 framebuffer->resetAttachment(this, attachment);
3268 }
3269
3270 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003271}
3272
3273void Context::framebufferTextureMultiviewSideBySideANGLE(GLenum target,
3274 GLenum attachment,
3275 GLuint texture,
3276 GLint level,
3277 GLsizei numViews,
3278 const GLint *viewportOffsets)
3279{
Martin Radev5dae57b2017-07-14 16:15:55 +03003280 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3281 ASSERT(framebuffer);
3282
3283 if (texture != 0)
3284 {
3285 Texture *textureObj = getTexture(texture);
3286
3287 ImageIndex index = ImageIndex::Make2D(level);
3288 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3289 textureObj, numViews, viewportOffsets);
3290 }
3291 else
3292 {
3293 framebuffer->resetAttachment(this, attachment);
3294 }
3295
3296 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003297}
3298
Jamie Madillc29968b2016-01-20 11:17:23 -05003299void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3300{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003301 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003302 ASSERT(framebuffer);
3303 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003304 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003305}
3306
3307void Context::readBuffer(GLenum mode)
3308{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003309 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003310 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003311 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003312}
3313
3314void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3315{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003316 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003317 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003318
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003319 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003320 ASSERT(framebuffer);
3321
3322 // The specification isn't clear what should be done when the framebuffer isn't complete.
3323 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003324 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003325}
3326
3327void Context::invalidateFramebuffer(GLenum target,
3328 GLsizei numAttachments,
3329 const GLenum *attachments)
3330{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003331 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003332 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003333
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003334 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003335 ASSERT(framebuffer);
3336
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003337 if (framebuffer->checkStatus(this) != GL_FRAMEBUFFER_COMPLETE)
Jamie Madillc29968b2016-01-20 11:17:23 -05003338 {
Jamie Madill437fa652016-05-03 15:13:24 -04003339 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003340 }
Jamie Madill437fa652016-05-03 15:13:24 -04003341
Jamie Madill4928b7c2017-06-20 12:57:39 -04003342 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003343}
3344
3345void Context::invalidateSubFramebuffer(GLenum target,
3346 GLsizei numAttachments,
3347 const GLenum *attachments,
3348 GLint x,
3349 GLint y,
3350 GLsizei width,
3351 GLsizei height)
3352{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003353 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003354 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003355
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003356 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003357 ASSERT(framebuffer);
3358
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003359 if (framebuffer->checkStatus(this) != GL_FRAMEBUFFER_COMPLETE)
Jamie Madillc29968b2016-01-20 11:17:23 -05003360 {
Jamie Madill437fa652016-05-03 15:13:24 -04003361 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003362 }
Jamie Madill437fa652016-05-03 15:13:24 -04003363
3364 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003365 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003366}
3367
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003368void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003369 GLint level,
3370 GLint internalformat,
3371 GLsizei width,
3372 GLsizei height,
3373 GLint border,
3374 GLenum format,
3375 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003376 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003377{
Jamie Madillbc918e72018-03-08 09:47:21 -05003378 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003379
3380 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003381 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003382 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3383 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003384}
3385
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003386void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003387 GLint level,
3388 GLint internalformat,
3389 GLsizei width,
3390 GLsizei height,
3391 GLsizei depth,
3392 GLint border,
3393 GLenum format,
3394 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003395 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003396{
Jamie Madillbc918e72018-03-08 09:47:21 -05003397 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003398
3399 Extents size(width, height, depth);
3400 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003401 handleError(texture->setImage(this, mGLState.getUnpackState(),
3402 NonCubeTextureTypeToTarget(target), level, internalformat, size,
3403 format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003404}
3405
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003406void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003407 GLint level,
3408 GLint xoffset,
3409 GLint yoffset,
3410 GLsizei width,
3411 GLsizei height,
3412 GLenum format,
3413 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003414 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003415{
3416 // Zero sized uploads are valid but no-ops
3417 if (width == 0 || height == 0)
3418 {
3419 return;
3420 }
3421
Jamie Madillbc918e72018-03-08 09:47:21 -05003422 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003423
3424 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003425 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003426 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3427 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003428}
3429
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003430void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003431 GLint level,
3432 GLint xoffset,
3433 GLint yoffset,
3434 GLint zoffset,
3435 GLsizei width,
3436 GLsizei height,
3437 GLsizei depth,
3438 GLenum format,
3439 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003440 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003441{
3442 // Zero sized uploads are valid but no-ops
3443 if (width == 0 || height == 0 || depth == 0)
3444 {
3445 return;
3446 }
3447
Jamie Madillbc918e72018-03-08 09:47:21 -05003448 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003449
3450 Box area(xoffset, yoffset, zoffset, width, height, depth);
3451 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003452 handleError(texture->setSubImage(this, mGLState.getUnpackState(),
3453 NonCubeTextureTypeToTarget(target), level, area, format, type,
3454 reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003455}
3456
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003457void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003458 GLint level,
3459 GLenum internalformat,
3460 GLsizei width,
3461 GLsizei height,
3462 GLint border,
3463 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003464 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003465{
Jamie Madillbc918e72018-03-08 09:47:21 -05003466 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003467
3468 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003469 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003470 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
3471 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003472 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003473}
3474
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003475void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003476 GLint level,
3477 GLenum internalformat,
3478 GLsizei width,
3479 GLsizei height,
3480 GLsizei depth,
3481 GLint border,
3482 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003483 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003484{
Jamie Madillbc918e72018-03-08 09:47:21 -05003485 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003486
3487 Extents size(width, height, depth);
3488 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003489 handleError(texture->setCompressedImage(
3490 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
3491 size, imageSize, reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003492}
3493
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003494void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003495 GLint level,
3496 GLint xoffset,
3497 GLint yoffset,
3498 GLsizei width,
3499 GLsizei height,
3500 GLenum format,
3501 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003502 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003503{
Jamie Madillbc918e72018-03-08 09:47:21 -05003504 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003505
3506 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003507 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003508 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
3509 format, imageSize,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003510 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003511}
3512
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003513void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003514 GLint level,
3515 GLint xoffset,
3516 GLint yoffset,
3517 GLint zoffset,
3518 GLsizei width,
3519 GLsizei height,
3520 GLsizei depth,
3521 GLenum format,
3522 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003523 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003524{
3525 // Zero sized uploads are valid but no-ops
3526 if (width == 0 || height == 0)
3527 {
3528 return;
3529 }
3530
Jamie Madillbc918e72018-03-08 09:47:21 -05003531 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003532
3533 Box area(xoffset, yoffset, zoffset, width, height, depth);
3534 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003535 handleError(texture->setCompressedSubImage(
3536 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
3537 imageSize, reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003538}
3539
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003540void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003541{
3542 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003543 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003544}
3545
Jamie Madill007530e2017-12-28 14:27:04 -05003546void Context::copyTexture(GLuint sourceId,
3547 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05003548 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05003549 GLuint destId,
3550 GLint destLevel,
3551 GLint internalFormat,
3552 GLenum destType,
3553 GLboolean unpackFlipY,
3554 GLboolean unpackPremultiplyAlpha,
3555 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07003556{
Jamie Madillbc918e72018-03-08 09:47:21 -05003557 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07003558
3559 gl::Texture *sourceTexture = getTexture(sourceId);
3560 gl::Texture *destTexture = getTexture(destId);
Geoff Lang92019432017-11-20 13:09:34 -05003561 handleError(destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType,
3562 sourceLevel, ConvertToBool(unpackFlipY),
3563 ConvertToBool(unpackPremultiplyAlpha),
3564 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003565}
3566
Jamie Madill007530e2017-12-28 14:27:04 -05003567void Context::copySubTexture(GLuint sourceId,
3568 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05003569 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05003570 GLuint destId,
3571 GLint destLevel,
3572 GLint xoffset,
3573 GLint yoffset,
3574 GLint x,
3575 GLint y,
3576 GLsizei width,
3577 GLsizei height,
3578 GLboolean unpackFlipY,
3579 GLboolean unpackPremultiplyAlpha,
3580 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07003581{
3582 // Zero sized copies are valid but no-ops
3583 if (width == 0 || height == 0)
3584 {
3585 return;
3586 }
3587
Jamie Madillbc918e72018-03-08 09:47:21 -05003588 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07003589
3590 gl::Texture *sourceTexture = getTexture(sourceId);
3591 gl::Texture *destTexture = getTexture(destId);
3592 Offset offset(xoffset, yoffset, 0);
3593 Rectangle area(x, y, width, height);
Geoff Lang92019432017-11-20 13:09:34 -05003594 handleError(destTexture->copySubTexture(this, destTarget, destLevel, offset, sourceLevel, area,
3595 ConvertToBool(unpackFlipY),
3596 ConvertToBool(unpackPremultiplyAlpha),
3597 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003598}
3599
Jamie Madill007530e2017-12-28 14:27:04 -05003600void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07003601{
Jamie Madillbc918e72018-03-08 09:47:21 -05003602 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07003603
3604 gl::Texture *sourceTexture = getTexture(sourceId);
3605 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05003606 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07003607}
3608
Corentin Wallez336129f2017-10-17 15:55:40 -04003609void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03003610{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003611 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003612 ASSERT(buffer);
3613
Geoff Lang496c02d2016-10-20 11:38:11 -07003614 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03003615}
3616
Corentin Wallez336129f2017-10-17 15:55:40 -04003617void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003618{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003619 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003620 ASSERT(buffer);
3621
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003622 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003623 if (error.isError())
3624 {
Jamie Madill437fa652016-05-03 15:13:24 -04003625 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003626 return nullptr;
3627 }
3628
3629 return buffer->getMapPointer();
3630}
3631
Corentin Wallez336129f2017-10-17 15:55:40 -04003632GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03003633{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003634 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003635 ASSERT(buffer);
3636
3637 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003638 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03003639 if (error.isError())
3640 {
Jamie Madill437fa652016-05-03 15:13:24 -04003641 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003642 return GL_FALSE;
3643 }
3644
3645 return result;
3646}
3647
Corentin Wallez336129f2017-10-17 15:55:40 -04003648void *Context::mapBufferRange(BufferBinding target,
3649 GLintptr offset,
3650 GLsizeiptr length,
3651 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003652{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003653 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003654 ASSERT(buffer);
3655
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003656 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003657 if (error.isError())
3658 {
Jamie Madill437fa652016-05-03 15:13:24 -04003659 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003660 return nullptr;
3661 }
3662
3663 return buffer->getMapPointer();
3664}
3665
Corentin Wallez336129f2017-10-17 15:55:40 -04003666void Context::flushMappedBufferRange(BufferBinding /*target*/,
3667 GLintptr /*offset*/,
3668 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03003669{
3670 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
3671}
3672
Jamie Madillbc918e72018-03-08 09:47:21 -05003673Error Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05003674{
Jamie Madillbc918e72018-03-08 09:47:21 -05003675 return syncRendererState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05003676}
3677
Jamie Madillbc918e72018-03-08 09:47:21 -05003678Error Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05003679{
Jamie Madillbc918e72018-03-08 09:47:21 -05003680 return syncRendererState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05003681}
3682
Jamie Madillbc918e72018-03-08 09:47:21 -05003683Error Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05003684{
Jamie Madillbc918e72018-03-08 09:47:21 -05003685 return syncRendererState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05003686}
3687
Jiajia Qin5451d532017-11-16 17:16:34 +08003688void Context::activeShaderProgram(GLuint pipeline, GLuint program)
3689{
3690 UNIMPLEMENTED();
3691}
3692
Jamie Madillc20ab272016-06-09 07:20:46 -07003693void Context::activeTexture(GLenum texture)
3694{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003695 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003696}
3697
Jamie Madill876429b2017-04-20 15:46:24 -04003698void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003699{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003700 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07003701}
3702
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003703void Context::blendEquation(GLenum mode)
3704{
3705 mGLState.setBlendEquation(mode, mode);
3706}
3707
Jamie Madillc20ab272016-06-09 07:20:46 -07003708void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
3709{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003710 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003711}
3712
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003713void Context::blendFunc(GLenum sfactor, GLenum dfactor)
3714{
3715 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
3716}
3717
Jamie Madillc20ab272016-06-09 07:20:46 -07003718void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
3719{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003720 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003721}
3722
Jamie Madill876429b2017-04-20 15:46:24 -04003723void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003724{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003725 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003726}
3727
Jamie Madill876429b2017-04-20 15:46:24 -04003728void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07003729{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003730 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07003731}
3732
3733void Context::clearStencil(GLint s)
3734{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003735 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07003736}
3737
3738void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
3739{
Geoff Lang92019432017-11-20 13:09:34 -05003740 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
3741 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07003742}
3743
Corentin Wallez2e568cf2017-09-18 17:05:22 -04003744void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07003745{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003746 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003747}
3748
3749void Context::depthFunc(GLenum func)
3750{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003751 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07003752}
3753
3754void Context::depthMask(GLboolean flag)
3755{
Geoff Lang92019432017-11-20 13:09:34 -05003756 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07003757}
3758
Jamie Madill876429b2017-04-20 15:46:24 -04003759void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07003760{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003761 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07003762}
3763
3764void Context::disable(GLenum cap)
3765{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003766 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003767}
3768
3769void Context::disableVertexAttribArray(GLuint index)
3770{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003771 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003772}
3773
3774void Context::enable(GLenum cap)
3775{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003776 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003777}
3778
3779void Context::enableVertexAttribArray(GLuint index)
3780{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003781 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003782}
3783
3784void Context::frontFace(GLenum mode)
3785{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003786 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003787}
3788
3789void Context::hint(GLenum target, GLenum mode)
3790{
3791 switch (target)
3792 {
3793 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003794 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003795 break;
3796
3797 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003798 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003799 break;
3800
3801 default:
3802 UNREACHABLE();
3803 return;
3804 }
3805}
3806
3807void Context::lineWidth(GLfloat width)
3808{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003809 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07003810}
3811
3812void Context::pixelStorei(GLenum pname, GLint param)
3813{
3814 switch (pname)
3815 {
3816 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003817 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003818 break;
3819
3820 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003821 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003822 break;
3823
3824 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003825 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003826 break;
3827
3828 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003829 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003830 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003831 break;
3832
3833 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03003834 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003835 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003836 break;
3837
3838 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03003839 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003840 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003841 break;
3842
3843 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003844 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003845 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003846 break;
3847
3848 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003849 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003850 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003851 break;
3852
3853 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003854 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003855 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003856 break;
3857
3858 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003859 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003860 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003861 break;
3862
3863 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003864 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003865 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003866 break;
3867
3868 default:
3869 UNREACHABLE();
3870 return;
3871 }
3872}
3873
3874void Context::polygonOffset(GLfloat factor, GLfloat units)
3875{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003876 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07003877}
3878
Jamie Madill876429b2017-04-20 15:46:24 -04003879void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07003880{
Geoff Lang92019432017-11-20 13:09:34 -05003881 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07003882}
3883
Jiawei Shaodb342272017-09-27 10:21:45 +08003884void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
3885{
3886 mGLState.setSampleMaskParams(maskNumber, mask);
3887}
3888
Jamie Madillc20ab272016-06-09 07:20:46 -07003889void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
3890{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003891 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07003892}
3893
3894void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
3895{
3896 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3897 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003898 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003899 }
3900
3901 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3902 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003903 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003904 }
3905}
3906
3907void Context::stencilMaskSeparate(GLenum face, GLuint mask)
3908{
3909 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3910 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003911 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003912 }
3913
3914 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3915 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003916 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003917 }
3918}
3919
3920void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
3921{
3922 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3923 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003924 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003925 }
3926
3927 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3928 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003929 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003930 }
3931}
3932
3933void Context::vertexAttrib1f(GLuint index, GLfloat x)
3934{
3935 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003936 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003937}
3938
3939void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
3940{
3941 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003942 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003943}
3944
3945void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
3946{
3947 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003948 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003949}
3950
3951void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
3952{
3953 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003954 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003955}
3956
3957void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
3958{
3959 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003960 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003961}
3962
3963void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
3964{
3965 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003966 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003967}
3968
3969void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
3970{
3971 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003972 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003973}
3974
3975void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
3976{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003977 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07003978}
3979
3980void Context::vertexAttribPointer(GLuint index,
3981 GLint size,
3982 GLenum type,
3983 GLboolean normalized,
3984 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04003985 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07003986{
Corentin Wallez336129f2017-10-17 15:55:40 -04003987 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05003988 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc20ab272016-06-09 07:20:46 -07003989}
3990
Shao80957d92017-02-20 21:25:59 +08003991void Context::vertexAttribFormat(GLuint attribIndex,
3992 GLint size,
3993 GLenum type,
3994 GLboolean normalized,
3995 GLuint relativeOffset)
3996{
Geoff Lang92019432017-11-20 13:09:34 -05003997 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08003998 relativeOffset);
3999}
4000
4001void Context::vertexAttribIFormat(GLuint attribIndex,
4002 GLint size,
4003 GLenum type,
4004 GLuint relativeOffset)
4005{
4006 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
4007}
4008
4009void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4010{
Shaodde78e82017-05-22 14:13:27 +08004011 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Shao80957d92017-02-20 21:25:59 +08004012}
4013
Jiajia Qin5451d532017-11-16 17:16:34 +08004014void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004015{
4016 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
4017}
4018
Jamie Madillc20ab272016-06-09 07:20:46 -07004019void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4020{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004021 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004022}
4023
4024void Context::vertexAttribIPointer(GLuint index,
4025 GLint size,
4026 GLenum type,
4027 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004028 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004029{
Corentin Wallez336129f2017-10-17 15:55:40 -04004030 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
4031 size, type, false, true, stride, pointer);
Jamie Madillc20ab272016-06-09 07:20:46 -07004032}
4033
4034void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4035{
4036 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004037 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004038}
4039
4040void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4041{
4042 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004043 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004044}
4045
4046void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4047{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004048 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004049}
4050
4051void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4052{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004053 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004054}
4055
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004056void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4057{
4058 const VertexAttribCurrentValueData &currentValues =
4059 getGLState().getVertexAttribCurrentValue(index);
4060 const VertexArray *vao = getGLState().getVertexArray();
4061 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4062 currentValues, pname, params);
4063}
4064
4065void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4066{
4067 const VertexAttribCurrentValueData &currentValues =
4068 getGLState().getVertexAttribCurrentValue(index);
4069 const VertexArray *vao = getGLState().getVertexArray();
4070 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4071 currentValues, pname, params);
4072}
4073
4074void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4075{
4076 const VertexAttribCurrentValueData &currentValues =
4077 getGLState().getVertexAttribCurrentValue(index);
4078 const VertexArray *vao = getGLState().getVertexArray();
4079 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4080 currentValues, pname, params);
4081}
4082
4083void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4084{
4085 const VertexAttribCurrentValueData &currentValues =
4086 getGLState().getVertexAttribCurrentValue(index);
4087 const VertexArray *vao = getGLState().getVertexArray();
4088 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4089 currentValues, pname, params);
4090}
4091
Jamie Madill876429b2017-04-20 15:46:24 -04004092void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004093{
4094 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
4095 QueryVertexAttribPointerv(attrib, pname, pointer);
4096}
4097
Jamie Madillc20ab272016-06-09 07:20:46 -07004098void Context::debugMessageControl(GLenum source,
4099 GLenum type,
4100 GLenum severity,
4101 GLsizei count,
4102 const GLuint *ids,
4103 GLboolean enabled)
4104{
4105 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004106 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05004107 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004108}
4109
4110void Context::debugMessageInsert(GLenum source,
4111 GLenum type,
4112 GLuint id,
4113 GLenum severity,
4114 GLsizei length,
4115 const GLchar *buf)
4116{
4117 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004118 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004119}
4120
4121void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4122{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004123 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004124}
4125
4126GLuint Context::getDebugMessageLog(GLuint count,
4127 GLsizei bufSize,
4128 GLenum *sources,
4129 GLenum *types,
4130 GLuint *ids,
4131 GLenum *severities,
4132 GLsizei *lengths,
4133 GLchar *messageLog)
4134{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004135 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4136 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004137}
4138
4139void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4140{
4141 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004142 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05004143 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07004144}
4145
4146void Context::popDebugGroup()
4147{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004148 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05004149 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004150}
4151
Corentin Wallez336129f2017-10-17 15:55:40 -04004152void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004153{
4154 Buffer *buffer = mGLState.getTargetBuffer(target);
4155 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004156 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004157}
4158
Corentin Wallez336129f2017-10-17 15:55:40 -04004159void Context::bufferSubData(BufferBinding target,
4160 GLintptr offset,
4161 GLsizeiptr size,
4162 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004163{
4164 if (data == nullptr)
4165 {
4166 return;
4167 }
4168
4169 Buffer *buffer = mGLState.getTargetBuffer(target);
4170 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004171 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004172}
4173
Jamie Madillef300b12016-10-07 15:12:09 -04004174void Context::attachShader(GLuint program, GLuint shader)
4175{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05004176 Program *programObject = mState.mShaderPrograms->getProgram(program);
4177 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004178 ASSERT(programObject && shaderObject);
4179 programObject->attachShader(shaderObject);
4180}
4181
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004182const Workarounds &Context::getWorkarounds() const
4183{
4184 return mWorkarounds;
4185}
4186
Corentin Wallez336129f2017-10-17 15:55:40 -04004187void Context::copyBufferSubData(BufferBinding readTarget,
4188 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04004189 GLintptr readOffset,
4190 GLintptr writeOffset,
4191 GLsizeiptr size)
4192{
4193 // if size is zero, the copy is a successful no-op
4194 if (size == 0)
4195 {
4196 return;
4197 }
4198
4199 // TODO(jmadill): cache these.
4200 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4201 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4202
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004203 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004204}
4205
Jamie Madill01a80ee2016-11-07 12:06:18 -05004206void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4207{
4208 Program *programObject = getProgram(program);
4209 // TODO(jmadill): Re-use this from the validation if possible.
4210 ASSERT(programObject);
4211 programObject->bindAttributeLocation(index, name);
4212}
4213
Corentin Wallez336129f2017-10-17 15:55:40 -04004214void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004215{
Corentin Wallez336129f2017-10-17 15:55:40 -04004216 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4217 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004218}
4219
Corentin Wallez336129f2017-10-17 15:55:40 -04004220void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08004221{
4222 bindBufferRange(target, index, buffer, 0, 0);
4223}
4224
Corentin Wallez336129f2017-10-17 15:55:40 -04004225void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08004226 GLuint index,
4227 GLuint buffer,
4228 GLintptr offset,
4229 GLsizeiptr size)
4230{
Corentin Wallez336129f2017-10-17 15:55:40 -04004231 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4232 mGLState.setIndexedBufferBinding(this, target, index, bufferObject, offset, size);
Jiajia Qin6eafb042016-12-27 17:04:07 +08004233}
4234
Jamie Madill01a80ee2016-11-07 12:06:18 -05004235void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
4236{
4237 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4238 {
4239 bindReadFramebuffer(framebuffer);
4240 }
4241
4242 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4243 {
4244 bindDrawFramebuffer(framebuffer);
4245 }
4246}
4247
4248void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4249{
4250 ASSERT(target == GL_RENDERBUFFER);
4251 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004252 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04004253 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004254}
4255
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004256void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08004257 GLsizei samples,
4258 GLenum internalformat,
4259 GLsizei width,
4260 GLsizei height,
4261 GLboolean fixedsamplelocations)
4262{
4263 Extents size(width, height, 1);
4264 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004265 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
4266 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004267}
4268
4269void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4270{
JiangYizhou5b03f472017-01-09 10:22:53 +08004271 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
4272 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillbc918e72018-03-08 09:47:21 -05004273 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
JiangYizhou5b03f472017-01-09 10:22:53 +08004274 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08004275
4276 switch (pname)
4277 {
4278 case GL_SAMPLE_POSITION:
4279 handleError(framebuffer->getSamplePosition(index, val));
4280 break;
4281 default:
4282 UNREACHABLE();
4283 }
4284}
4285
Jamie Madille8fb6402017-02-14 17:56:40 -05004286void Context::renderbufferStorage(GLenum target,
4287 GLenum internalformat,
4288 GLsizei width,
4289 GLsizei height)
4290{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004291 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4292 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
4293
Jamie Madille8fb6402017-02-14 17:56:40 -05004294 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04004295 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004296}
4297
4298void Context::renderbufferStorageMultisample(GLenum target,
4299 GLsizei samples,
4300 GLenum internalformat,
4301 GLsizei width,
4302 GLsizei height)
4303{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004304 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4305 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05004306
4307 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004308 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04004309 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004310}
4311
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004312void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
4313{
Jamie Madill70b5bb02017-08-28 13:32:37 -04004314 const Sync *syncObject = getSync(sync);
Geoff Lang82483b92017-04-11 15:33:00 -04004315 handleError(QuerySynciv(syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004316}
4317
JiangYizhoue18e6392017-02-20 10:32:23 +08004318void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
4319{
4320 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4321 QueryFramebufferParameteriv(framebuffer, pname, params);
4322}
4323
Jiajia Qin5451d532017-11-16 17:16:34 +08004324void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08004325{
4326 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4327 SetFramebufferParameteri(framebuffer, pname, param);
4328}
4329
Jamie Madillb3f26b92017-07-19 15:07:41 -04004330Error Context::getScratchBuffer(size_t requstedSizeBytes,
4331 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05004332{
Jamie Madillb3f26b92017-07-19 15:07:41 -04004333 if (!mScratchBuffer.get(requstedSizeBytes, scratchBufferOut))
4334 {
4335 return OutOfMemory() << "Failed to allocate internal buffer.";
4336 }
4337 return NoError();
4338}
4339
4340Error Context::getZeroFilledBuffer(size_t requstedSizeBytes,
4341 angle::MemoryBuffer **zeroBufferOut) const
4342{
4343 if (!mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0))
Jamie Madille14951e2017-03-09 18:55:16 -05004344 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004345 return OutOfMemory() << "Failed to allocate internal buffer.";
Jamie Madille14951e2017-03-09 18:55:16 -05004346 }
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004347 return NoError();
Jamie Madille14951e2017-03-09 18:55:16 -05004348}
4349
Xinghua Cao10a4d432017-11-28 14:46:26 +08004350Error Context::prepareForDispatch()
4351{
Jamie Madillbc918e72018-03-08 09:47:21 -05004352 ANGLE_TRY(syncRendererState(mComputeDirtyBits, mComputeDirtyObjects));
Xinghua Cao10a4d432017-11-28 14:46:26 +08004353
4354 if (isRobustResourceInitEnabled())
4355 {
4356 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
4357 }
4358
4359 return NoError();
4360}
4361
Xinghua Cao2b396592017-03-29 15:36:04 +08004362void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
4363{
4364 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
4365 {
4366 return;
4367 }
4368
Xinghua Cao10a4d432017-11-28 14:46:26 +08004369 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill71c88b32017-09-14 22:20:29 -04004370 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08004371}
4372
Jiajia Qin5451d532017-11-16 17:16:34 +08004373void Context::dispatchComputeIndirect(GLintptr indirect)
4374{
Qin Jiajia62fcf622017-11-30 16:16:12 +08004375 ANGLE_CONTEXT_TRY(prepareForDispatch());
4376 handleError(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08004377}
4378
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004379void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08004380 GLsizei levels,
4381 GLenum internalFormat,
4382 GLsizei width,
4383 GLsizei height)
4384{
4385 Extents size(width, height, 1);
4386 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004387 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08004388}
4389
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004390void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08004391 GLsizei levels,
4392 GLenum internalFormat,
4393 GLsizei width,
4394 GLsizei height,
4395 GLsizei depth)
4396{
4397 Extents size(width, height, depth);
4398 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004399 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08004400}
4401
Jiajia Qin5451d532017-11-16 17:16:34 +08004402void Context::memoryBarrier(GLbitfield barriers)
4403{
Xinghua Cao89c422a2017-11-29 18:24:20 +08004404 handleError(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08004405}
4406
4407void Context::memoryBarrierByRegion(GLbitfield barriers)
4408{
Xinghua Cao89c422a2017-11-29 18:24:20 +08004409 handleError(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08004410}
4411
Jamie Madillc1d770e2017-04-13 17:31:24 -04004412GLenum Context::checkFramebufferStatus(GLenum target)
4413{
4414 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4415 ASSERT(framebuffer);
4416
4417 return framebuffer->checkStatus(this);
4418}
4419
4420void Context::compileShader(GLuint shader)
4421{
4422 Shader *shaderObject = GetValidShader(this, shader);
4423 if (!shaderObject)
4424 {
4425 return;
4426 }
4427 shaderObject->compile(this);
4428}
4429
4430void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
4431{
4432 for (int i = 0; i < n; i++)
4433 {
4434 deleteBuffer(buffers[i]);
4435 }
4436}
4437
4438void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
4439{
4440 for (int i = 0; i < n; i++)
4441 {
4442 if (framebuffers[i] != 0)
4443 {
4444 deleteFramebuffer(framebuffers[i]);
4445 }
4446 }
4447}
4448
4449void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
4450{
4451 for (int i = 0; i < n; i++)
4452 {
4453 deleteRenderbuffer(renderbuffers[i]);
4454 }
4455}
4456
4457void Context::deleteTextures(GLsizei n, const GLuint *textures)
4458{
4459 for (int i = 0; i < n; i++)
4460 {
4461 if (textures[i] != 0)
4462 {
4463 deleteTexture(textures[i]);
4464 }
4465 }
4466}
4467
4468void Context::detachShader(GLuint program, GLuint shader)
4469{
4470 Program *programObject = getProgram(program);
4471 ASSERT(programObject);
4472
4473 Shader *shaderObject = getShader(shader);
4474 ASSERT(shaderObject);
4475
4476 programObject->detachShader(this, shaderObject);
4477}
4478
4479void Context::genBuffers(GLsizei n, GLuint *buffers)
4480{
4481 for (int i = 0; i < n; i++)
4482 {
4483 buffers[i] = createBuffer();
4484 }
4485}
4486
4487void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
4488{
4489 for (int i = 0; i < n; i++)
4490 {
4491 framebuffers[i] = createFramebuffer();
4492 }
4493}
4494
4495void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
4496{
4497 for (int i = 0; i < n; i++)
4498 {
4499 renderbuffers[i] = createRenderbuffer();
4500 }
4501}
4502
4503void Context::genTextures(GLsizei n, GLuint *textures)
4504{
4505 for (int i = 0; i < n; i++)
4506 {
4507 textures[i] = createTexture();
4508 }
4509}
4510
4511void Context::getActiveAttrib(GLuint program,
4512 GLuint index,
4513 GLsizei bufsize,
4514 GLsizei *length,
4515 GLint *size,
4516 GLenum *type,
4517 GLchar *name)
4518{
4519 Program *programObject = getProgram(program);
4520 ASSERT(programObject);
4521 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
4522}
4523
4524void Context::getActiveUniform(GLuint program,
4525 GLuint index,
4526 GLsizei bufsize,
4527 GLsizei *length,
4528 GLint *size,
4529 GLenum *type,
4530 GLchar *name)
4531{
4532 Program *programObject = getProgram(program);
4533 ASSERT(programObject);
4534 programObject->getActiveUniform(index, bufsize, length, size, type, name);
4535}
4536
4537void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
4538{
4539 Program *programObject = getProgram(program);
4540 ASSERT(programObject);
4541 programObject->getAttachedShaders(maxcount, count, shaders);
4542}
4543
4544GLint Context::getAttribLocation(GLuint program, const GLchar *name)
4545{
4546 Program *programObject = getProgram(program);
4547 ASSERT(programObject);
4548 return programObject->getAttributeLocation(name);
4549}
4550
4551void Context::getBooleanv(GLenum pname, GLboolean *params)
4552{
4553 GLenum nativeType;
4554 unsigned int numParams = 0;
4555 getQueryParameterInfo(pname, &nativeType, &numParams);
4556
4557 if (nativeType == GL_BOOL)
4558 {
4559 getBooleanvImpl(pname, params);
4560 }
4561 else
4562 {
4563 CastStateValues(this, nativeType, pname, numParams, params);
4564 }
4565}
4566
4567void Context::getFloatv(GLenum pname, GLfloat *params)
4568{
4569 GLenum nativeType;
4570 unsigned int numParams = 0;
4571 getQueryParameterInfo(pname, &nativeType, &numParams);
4572
4573 if (nativeType == GL_FLOAT)
4574 {
4575 getFloatvImpl(pname, params);
4576 }
4577 else
4578 {
4579 CastStateValues(this, nativeType, pname, numParams, params);
4580 }
4581}
4582
4583void Context::getIntegerv(GLenum pname, GLint *params)
4584{
4585 GLenum nativeType;
4586 unsigned int numParams = 0;
4587 getQueryParameterInfo(pname, &nativeType, &numParams);
4588
4589 if (nativeType == GL_INT)
4590 {
4591 getIntegervImpl(pname, params);
4592 }
4593 else
4594 {
4595 CastStateValues(this, nativeType, pname, numParams, params);
4596 }
4597}
4598
4599void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
4600{
4601 Program *programObject = getProgram(program);
4602 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04004603 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004604}
4605
Jiajia Qin5451d532017-11-16 17:16:34 +08004606void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
4607{
4608 UNIMPLEMENTED();
4609}
4610
Jamie Madillbe849e42017-05-02 15:49:00 -04004611void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04004612{
4613 Program *programObject = getProgram(program);
4614 ASSERT(programObject);
4615 programObject->getInfoLog(bufsize, length, infolog);
4616}
4617
Jiajia Qin5451d532017-11-16 17:16:34 +08004618void Context::getProgramPipelineInfoLog(GLuint pipeline,
4619 GLsizei bufSize,
4620 GLsizei *length,
4621 GLchar *infoLog)
4622{
4623 UNIMPLEMENTED();
4624}
4625
Jamie Madillc1d770e2017-04-13 17:31:24 -04004626void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
4627{
4628 Shader *shaderObject = getShader(shader);
4629 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004630 QueryShaderiv(this, shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004631}
4632
4633void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
4634{
4635 Shader *shaderObject = getShader(shader);
4636 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004637 shaderObject->getInfoLog(this, bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004638}
4639
4640void Context::getShaderPrecisionFormat(GLenum shadertype,
4641 GLenum precisiontype,
4642 GLint *range,
4643 GLint *precision)
4644{
4645 // TODO(jmadill): Compute shaders.
4646
4647 switch (shadertype)
4648 {
4649 case GL_VERTEX_SHADER:
4650 switch (precisiontype)
4651 {
4652 case GL_LOW_FLOAT:
4653 mCaps.vertexLowpFloat.get(range, precision);
4654 break;
4655 case GL_MEDIUM_FLOAT:
4656 mCaps.vertexMediumpFloat.get(range, precision);
4657 break;
4658 case GL_HIGH_FLOAT:
4659 mCaps.vertexHighpFloat.get(range, precision);
4660 break;
4661
4662 case GL_LOW_INT:
4663 mCaps.vertexLowpInt.get(range, precision);
4664 break;
4665 case GL_MEDIUM_INT:
4666 mCaps.vertexMediumpInt.get(range, precision);
4667 break;
4668 case GL_HIGH_INT:
4669 mCaps.vertexHighpInt.get(range, precision);
4670 break;
4671
4672 default:
4673 UNREACHABLE();
4674 return;
4675 }
4676 break;
4677
4678 case GL_FRAGMENT_SHADER:
4679 switch (precisiontype)
4680 {
4681 case GL_LOW_FLOAT:
4682 mCaps.fragmentLowpFloat.get(range, precision);
4683 break;
4684 case GL_MEDIUM_FLOAT:
4685 mCaps.fragmentMediumpFloat.get(range, precision);
4686 break;
4687 case GL_HIGH_FLOAT:
4688 mCaps.fragmentHighpFloat.get(range, precision);
4689 break;
4690
4691 case GL_LOW_INT:
4692 mCaps.fragmentLowpInt.get(range, precision);
4693 break;
4694 case GL_MEDIUM_INT:
4695 mCaps.fragmentMediumpInt.get(range, precision);
4696 break;
4697 case GL_HIGH_INT:
4698 mCaps.fragmentHighpInt.get(range, precision);
4699 break;
4700
4701 default:
4702 UNREACHABLE();
4703 return;
4704 }
4705 break;
4706
4707 default:
4708 UNREACHABLE();
4709 return;
4710 }
4711}
4712
4713void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
4714{
4715 Shader *shaderObject = getShader(shader);
4716 ASSERT(shaderObject);
4717 shaderObject->getSource(bufsize, length, source);
4718}
4719
4720void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
4721{
4722 Program *programObject = getProgram(program);
4723 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04004724 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004725}
4726
4727void Context::getUniformiv(GLuint program, GLint location, GLint *params)
4728{
4729 Program *programObject = getProgram(program);
4730 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04004731 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004732}
4733
4734GLint Context::getUniformLocation(GLuint program, const GLchar *name)
4735{
4736 Program *programObject = getProgram(program);
4737 ASSERT(programObject);
4738 return programObject->getUniformLocation(name);
4739}
4740
4741GLboolean Context::isBuffer(GLuint buffer)
4742{
4743 if (buffer == 0)
4744 {
4745 return GL_FALSE;
4746 }
4747
4748 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
4749}
4750
4751GLboolean Context::isEnabled(GLenum cap)
4752{
4753 return mGLState.getEnableFeature(cap);
4754}
4755
4756GLboolean Context::isFramebuffer(GLuint framebuffer)
4757{
4758 if (framebuffer == 0)
4759 {
4760 return GL_FALSE;
4761 }
4762
4763 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
4764}
4765
4766GLboolean Context::isProgram(GLuint program)
4767{
4768 if (program == 0)
4769 {
4770 return GL_FALSE;
4771 }
4772
4773 return (getProgram(program) ? GL_TRUE : GL_FALSE);
4774}
4775
4776GLboolean Context::isRenderbuffer(GLuint renderbuffer)
4777{
4778 if (renderbuffer == 0)
4779 {
4780 return GL_FALSE;
4781 }
4782
4783 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
4784}
4785
4786GLboolean Context::isShader(GLuint shader)
4787{
4788 if (shader == 0)
4789 {
4790 return GL_FALSE;
4791 }
4792
4793 return (getShader(shader) ? GL_TRUE : GL_FALSE);
4794}
4795
4796GLboolean Context::isTexture(GLuint texture)
4797{
4798 if (texture == 0)
4799 {
4800 return GL_FALSE;
4801 }
4802
4803 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
4804}
4805
4806void Context::linkProgram(GLuint program)
4807{
4808 Program *programObject = getProgram(program);
4809 ASSERT(programObject);
4810 handleError(programObject->link(this));
Martin Radev0abb7a22017-08-28 15:34:45 +03004811 mGLState.onProgramExecutableChange(programObject);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004812}
4813
4814void Context::releaseShaderCompiler()
4815{
Jamie Madill4928b7c2017-06-20 12:57:39 -04004816 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004817}
4818
4819void Context::shaderBinary(GLsizei n,
4820 const GLuint *shaders,
4821 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04004822 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04004823 GLsizei length)
4824{
4825 // No binary shader formats are supported.
4826 UNIMPLEMENTED();
4827}
4828
4829void Context::shaderSource(GLuint shader,
4830 GLsizei count,
4831 const GLchar *const *string,
4832 const GLint *length)
4833{
4834 Shader *shaderObject = getShader(shader);
4835 ASSERT(shaderObject);
4836 shaderObject->setSource(count, string, length);
4837}
4838
4839void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
4840{
4841 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
4842}
4843
4844void Context::stencilMask(GLuint mask)
4845{
4846 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
4847}
4848
4849void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
4850{
4851 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
4852}
4853
4854void Context::uniform1f(GLint location, GLfloat x)
4855{
4856 Program *program = mGLState.getProgram();
4857 program->setUniform1fv(location, 1, &x);
4858}
4859
4860void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
4861{
4862 Program *program = mGLState.getProgram();
4863 program->setUniform1fv(location, count, v);
4864}
4865
4866void Context::uniform1i(GLint location, GLint x)
4867{
4868 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04004869 if (program->setUniform1iv(location, 1, &x) == Program::SetUniformResult::SamplerChanged)
4870 {
4871 mGLState.setObjectDirty(GL_PROGRAM);
4872 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04004873}
4874
4875void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
4876{
4877 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04004878 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
4879 {
4880 mGLState.setObjectDirty(GL_PROGRAM);
4881 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04004882}
4883
4884void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
4885{
4886 GLfloat xy[2] = {x, y};
4887 Program *program = mGLState.getProgram();
4888 program->setUniform2fv(location, 1, xy);
4889}
4890
4891void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
4892{
4893 Program *program = mGLState.getProgram();
4894 program->setUniform2fv(location, count, v);
4895}
4896
4897void Context::uniform2i(GLint location, GLint x, GLint y)
4898{
4899 GLint xy[2] = {x, y};
4900 Program *program = mGLState.getProgram();
4901 program->setUniform2iv(location, 1, xy);
4902}
4903
4904void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
4905{
4906 Program *program = mGLState.getProgram();
4907 program->setUniform2iv(location, count, v);
4908}
4909
4910void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
4911{
4912 GLfloat xyz[3] = {x, y, z};
4913 Program *program = mGLState.getProgram();
4914 program->setUniform3fv(location, 1, xyz);
4915}
4916
4917void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
4918{
4919 Program *program = mGLState.getProgram();
4920 program->setUniform3fv(location, count, v);
4921}
4922
4923void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
4924{
4925 GLint xyz[3] = {x, y, z};
4926 Program *program = mGLState.getProgram();
4927 program->setUniform3iv(location, 1, xyz);
4928}
4929
4930void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
4931{
4932 Program *program = mGLState.getProgram();
4933 program->setUniform3iv(location, count, v);
4934}
4935
4936void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4937{
4938 GLfloat xyzw[4] = {x, y, z, w};
4939 Program *program = mGLState.getProgram();
4940 program->setUniform4fv(location, 1, xyzw);
4941}
4942
4943void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
4944{
4945 Program *program = mGLState.getProgram();
4946 program->setUniform4fv(location, count, v);
4947}
4948
4949void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
4950{
4951 GLint xyzw[4] = {x, y, z, w};
4952 Program *program = mGLState.getProgram();
4953 program->setUniform4iv(location, 1, xyzw);
4954}
4955
4956void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
4957{
4958 Program *program = mGLState.getProgram();
4959 program->setUniform4iv(location, count, v);
4960}
4961
4962void Context::uniformMatrix2fv(GLint location,
4963 GLsizei count,
4964 GLboolean transpose,
4965 const GLfloat *value)
4966{
4967 Program *program = mGLState.getProgram();
4968 program->setUniformMatrix2fv(location, count, transpose, value);
4969}
4970
4971void Context::uniformMatrix3fv(GLint location,
4972 GLsizei count,
4973 GLboolean transpose,
4974 const GLfloat *value)
4975{
4976 Program *program = mGLState.getProgram();
4977 program->setUniformMatrix3fv(location, count, transpose, value);
4978}
4979
4980void Context::uniformMatrix4fv(GLint location,
4981 GLsizei count,
4982 GLboolean transpose,
4983 const GLfloat *value)
4984{
4985 Program *program = mGLState.getProgram();
4986 program->setUniformMatrix4fv(location, count, transpose, value);
4987}
4988
4989void Context::validateProgram(GLuint program)
4990{
4991 Program *programObject = getProgram(program);
4992 ASSERT(programObject);
4993 programObject->validate(mCaps);
4994}
4995
Jiajia Qin5451d532017-11-16 17:16:34 +08004996void Context::validateProgramPipeline(GLuint pipeline)
4997{
4998 UNIMPLEMENTED();
4999}
5000
Jamie Madilld04908b2017-06-09 14:15:35 -04005001void Context::getProgramBinary(GLuint program,
5002 GLsizei bufSize,
5003 GLsizei *length,
5004 GLenum *binaryFormat,
5005 void *binary)
5006{
5007 Program *programObject = getProgram(program);
5008 ASSERT(programObject != nullptr);
5009
5010 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
5011}
5012
5013void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
5014{
5015 Program *programObject = getProgram(program);
5016 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04005017
Jamie Madilld04908b2017-06-09 14:15:35 -04005018 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
5019}
5020
Jamie Madillff325f12017-08-26 15:06:05 -04005021void Context::uniform1ui(GLint location, GLuint v0)
5022{
5023 Program *program = mGLState.getProgram();
5024 program->setUniform1uiv(location, 1, &v0);
5025}
5026
5027void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
5028{
5029 Program *program = mGLState.getProgram();
5030 const GLuint xy[] = {v0, v1};
5031 program->setUniform2uiv(location, 1, xy);
5032}
5033
5034void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
5035{
5036 Program *program = mGLState.getProgram();
5037 const GLuint xyz[] = {v0, v1, v2};
5038 program->setUniform3uiv(location, 1, xyz);
5039}
5040
5041void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
5042{
5043 Program *program = mGLState.getProgram();
5044 const GLuint xyzw[] = {v0, v1, v2, v3};
5045 program->setUniform4uiv(location, 1, xyzw);
5046}
5047
5048void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
5049{
5050 Program *program = mGLState.getProgram();
5051 program->setUniform1uiv(location, count, value);
5052}
5053void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
5054{
5055 Program *program = mGLState.getProgram();
5056 program->setUniform2uiv(location, count, value);
5057}
5058
5059void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
5060{
5061 Program *program = mGLState.getProgram();
5062 program->setUniform3uiv(location, count, value);
5063}
5064
5065void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
5066{
5067 Program *program = mGLState.getProgram();
5068 program->setUniform4uiv(location, count, value);
5069}
5070
Jamie Madillf0e04492017-08-26 15:28:42 -04005071void Context::genQueries(GLsizei n, GLuint *ids)
5072{
5073 for (GLsizei i = 0; i < n; i++)
5074 {
5075 GLuint handle = mQueryHandleAllocator.allocate();
5076 mQueryMap.assign(handle, nullptr);
5077 ids[i] = handle;
5078 }
5079}
5080
5081void Context::deleteQueries(GLsizei n, const GLuint *ids)
5082{
5083 for (int i = 0; i < n; i++)
5084 {
5085 GLuint query = ids[i];
5086
5087 Query *queryObject = nullptr;
5088 if (mQueryMap.erase(query, &queryObject))
5089 {
5090 mQueryHandleAllocator.release(query);
5091 if (queryObject)
5092 {
5093 queryObject->release(this);
5094 }
5095 }
5096 }
5097}
5098
5099GLboolean Context::isQuery(GLuint id)
5100{
5101 return (getQuery(id, false, GL_NONE) != nullptr) ? GL_TRUE : GL_FALSE;
5102}
5103
Jamie Madillc8c95812017-08-26 18:40:09 -04005104void Context::uniformMatrix2x3fv(GLint location,
5105 GLsizei count,
5106 GLboolean transpose,
5107 const GLfloat *value)
5108{
5109 Program *program = mGLState.getProgram();
5110 program->setUniformMatrix2x3fv(location, count, transpose, value);
5111}
5112
5113void Context::uniformMatrix3x2fv(GLint location,
5114 GLsizei count,
5115 GLboolean transpose,
5116 const GLfloat *value)
5117{
5118 Program *program = mGLState.getProgram();
5119 program->setUniformMatrix3x2fv(location, count, transpose, value);
5120}
5121
5122void Context::uniformMatrix2x4fv(GLint location,
5123 GLsizei count,
5124 GLboolean transpose,
5125 const GLfloat *value)
5126{
5127 Program *program = mGLState.getProgram();
5128 program->setUniformMatrix2x4fv(location, count, transpose, value);
5129}
5130
5131void Context::uniformMatrix4x2fv(GLint location,
5132 GLsizei count,
5133 GLboolean transpose,
5134 const GLfloat *value)
5135{
5136 Program *program = mGLState.getProgram();
5137 program->setUniformMatrix4x2fv(location, count, transpose, value);
5138}
5139
5140void Context::uniformMatrix3x4fv(GLint location,
5141 GLsizei count,
5142 GLboolean transpose,
5143 const GLfloat *value)
5144{
5145 Program *program = mGLState.getProgram();
5146 program->setUniformMatrix3x4fv(location, count, transpose, value);
5147}
5148
5149void Context::uniformMatrix4x3fv(GLint location,
5150 GLsizei count,
5151 GLboolean transpose,
5152 const GLfloat *value)
5153{
5154 Program *program = mGLState.getProgram();
5155 program->setUniformMatrix4x3fv(location, count, transpose, value);
5156}
5157
Jamie Madilld7576732017-08-26 18:49:50 -04005158void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
5159{
5160 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5161 {
5162 GLuint vertexArray = arrays[arrayIndex];
5163
5164 if (arrays[arrayIndex] != 0)
5165 {
5166 VertexArray *vertexArrayObject = nullptr;
5167 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
5168 {
5169 if (vertexArrayObject != nullptr)
5170 {
5171 detachVertexArray(vertexArray);
5172 vertexArrayObject->onDestroy(this);
5173 }
5174
5175 mVertexArrayHandleAllocator.release(vertexArray);
5176 }
5177 }
5178 }
5179}
5180
5181void Context::genVertexArrays(GLsizei n, GLuint *arrays)
5182{
5183 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5184 {
5185 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
5186 mVertexArrayMap.assign(vertexArray, nullptr);
5187 arrays[arrayIndex] = vertexArray;
5188 }
5189}
5190
5191bool Context::isVertexArray(GLuint array)
5192{
5193 if (array == 0)
5194 {
5195 return GL_FALSE;
5196 }
5197
5198 VertexArray *vao = getVertexArray(array);
5199 return (vao != nullptr ? GL_TRUE : GL_FALSE);
5200}
5201
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04005202void Context::endTransformFeedback()
5203{
5204 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5205 transformFeedback->end(this);
5206}
5207
5208void Context::transformFeedbackVaryings(GLuint program,
5209 GLsizei count,
5210 const GLchar *const *varyings,
5211 GLenum bufferMode)
5212{
5213 Program *programObject = getProgram(program);
5214 ASSERT(programObject);
5215 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
5216}
5217
5218void Context::getTransformFeedbackVarying(GLuint program,
5219 GLuint index,
5220 GLsizei bufSize,
5221 GLsizei *length,
5222 GLsizei *size,
5223 GLenum *type,
5224 GLchar *name)
5225{
5226 Program *programObject = getProgram(program);
5227 ASSERT(programObject);
5228 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
5229}
5230
5231void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
5232{
5233 for (int i = 0; i < n; i++)
5234 {
5235 GLuint transformFeedback = ids[i];
5236 if (transformFeedback == 0)
5237 {
5238 continue;
5239 }
5240
5241 TransformFeedback *transformFeedbackObject = nullptr;
5242 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
5243 {
5244 if (transformFeedbackObject != nullptr)
5245 {
5246 detachTransformFeedback(transformFeedback);
5247 transformFeedbackObject->release(this);
5248 }
5249
5250 mTransformFeedbackHandleAllocator.release(transformFeedback);
5251 }
5252 }
5253}
5254
5255void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
5256{
5257 for (int i = 0; i < n; i++)
5258 {
5259 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
5260 mTransformFeedbackMap.assign(transformFeedback, nullptr);
5261 ids[i] = transformFeedback;
5262 }
5263}
5264
5265bool Context::isTransformFeedback(GLuint id)
5266{
5267 if (id == 0)
5268 {
5269 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
5270 // returns FALSE
5271 return GL_FALSE;
5272 }
5273
5274 const TransformFeedback *transformFeedback = getTransformFeedback(id);
5275 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
5276}
5277
5278void Context::pauseTransformFeedback()
5279{
5280 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5281 transformFeedback->pause();
5282}
5283
5284void Context::resumeTransformFeedback()
5285{
5286 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5287 transformFeedback->resume();
5288}
5289
Jamie Madill12e957f2017-08-26 21:42:26 -04005290void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
5291{
5292 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04005293 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04005294}
5295
5296GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
5297{
5298 const Program *programObject = getProgram(program);
5299 return programObject->getFragDataLocation(name);
5300}
5301
5302void Context::getUniformIndices(GLuint program,
5303 GLsizei uniformCount,
5304 const GLchar *const *uniformNames,
5305 GLuint *uniformIndices)
5306{
5307 const Program *programObject = getProgram(program);
5308 if (!programObject->isLinked())
5309 {
5310 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5311 {
5312 uniformIndices[uniformId] = GL_INVALID_INDEX;
5313 }
5314 }
5315 else
5316 {
5317 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5318 {
5319 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
5320 }
5321 }
5322}
5323
5324void Context::getActiveUniformsiv(GLuint program,
5325 GLsizei uniformCount,
5326 const GLuint *uniformIndices,
5327 GLenum pname,
5328 GLint *params)
5329{
5330 const Program *programObject = getProgram(program);
5331 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5332 {
5333 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08005334 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04005335 }
5336}
5337
5338GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
5339{
5340 const Program *programObject = getProgram(program);
5341 return programObject->getUniformBlockIndex(uniformBlockName);
5342}
5343
5344void Context::getActiveUniformBlockiv(GLuint program,
5345 GLuint uniformBlockIndex,
5346 GLenum pname,
5347 GLint *params)
5348{
5349 const Program *programObject = getProgram(program);
5350 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
5351}
5352
5353void Context::getActiveUniformBlockName(GLuint program,
5354 GLuint uniformBlockIndex,
5355 GLsizei bufSize,
5356 GLsizei *length,
5357 GLchar *uniformBlockName)
5358{
5359 const Program *programObject = getProgram(program);
5360 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
5361}
5362
5363void Context::uniformBlockBinding(GLuint program,
5364 GLuint uniformBlockIndex,
5365 GLuint uniformBlockBinding)
5366{
5367 Program *programObject = getProgram(program);
5368 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
5369}
5370
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005371GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
5372{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005373 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
5374 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005375
Jamie Madill70b5bb02017-08-28 13:32:37 -04005376 Sync *syncObject = getSync(syncHandle);
5377 Error error = syncObject->set(condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005378 if (error.isError())
5379 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04005380 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005381 handleError(error);
5382 return nullptr;
5383 }
5384
Jamie Madill70b5bb02017-08-28 13:32:37 -04005385 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005386}
5387
5388GLboolean Context::isSync(GLsync sync)
5389{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005390 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005391}
5392
5393GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
5394{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005395 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005396
5397 GLenum result = GL_WAIT_FAILED;
5398 handleError(syncObject->clientWait(flags, timeout, &result));
5399 return result;
5400}
5401
5402void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
5403{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005404 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005405 handleError(syncObject->serverWait(flags, timeout));
5406}
5407
5408void Context::getInteger64v(GLenum pname, GLint64 *params)
5409{
5410 GLenum nativeType = GL_NONE;
5411 unsigned int numParams = 0;
5412 getQueryParameterInfo(pname, &nativeType, &numParams);
5413
5414 if (nativeType == GL_INT_64_ANGLEX)
5415 {
5416 getInteger64vImpl(pname, params);
5417 }
5418 else
5419 {
5420 CastStateValues(this, nativeType, pname, numParams, params);
5421 }
5422}
5423
Corentin Wallez336129f2017-10-17 15:55:40 -04005424void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04005425{
5426 Buffer *buffer = mGLState.getTargetBuffer(target);
5427 QueryBufferParameteri64v(buffer, pname, params);
5428}
5429
5430void Context::genSamplers(GLsizei count, GLuint *samplers)
5431{
5432 for (int i = 0; i < count; i++)
5433 {
5434 samplers[i] = mState.mSamplers->createSampler();
5435 }
5436}
5437
5438void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
5439{
5440 for (int i = 0; i < count; i++)
5441 {
5442 GLuint sampler = samplers[i];
5443
5444 if (mState.mSamplers->getSampler(sampler))
5445 {
5446 detachSampler(sampler);
5447 }
5448
5449 mState.mSamplers->deleteObject(this, sampler);
5450 }
5451}
5452
5453void Context::getInternalformativ(GLenum target,
5454 GLenum internalformat,
5455 GLenum pname,
5456 GLsizei bufSize,
5457 GLint *params)
5458{
5459 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
5460 QueryInternalFormativ(formatCaps, pname, bufSize, params);
5461}
5462
Jiajia Qin5451d532017-11-16 17:16:34 +08005463void Context::programUniform1i(GLuint program, GLint location, GLint v0)
5464{
5465 programUniform1iv(program, location, 1, &v0);
5466}
5467
5468void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
5469{
5470 GLint xy[2] = {v0, v1};
5471 programUniform2iv(program, location, 1, xy);
5472}
5473
5474void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
5475{
5476 GLint xyz[3] = {v0, v1, v2};
5477 programUniform3iv(program, location, 1, xyz);
5478}
5479
5480void Context::programUniform4i(GLuint program,
5481 GLint location,
5482 GLint v0,
5483 GLint v1,
5484 GLint v2,
5485 GLint v3)
5486{
5487 GLint xyzw[4] = {v0, v1, v2, v3};
5488 programUniform4iv(program, location, 1, xyzw);
5489}
5490
5491void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
5492{
5493 programUniform1uiv(program, location, 1, &v0);
5494}
5495
5496void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
5497{
5498 GLuint xy[2] = {v0, v1};
5499 programUniform2uiv(program, location, 1, xy);
5500}
5501
5502void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
5503{
5504 GLuint xyz[3] = {v0, v1, v2};
5505 programUniform3uiv(program, location, 1, xyz);
5506}
5507
5508void Context::programUniform4ui(GLuint program,
5509 GLint location,
5510 GLuint v0,
5511 GLuint v1,
5512 GLuint v2,
5513 GLuint v3)
5514{
5515 GLuint xyzw[4] = {v0, v1, v2, v3};
5516 programUniform4uiv(program, location, 1, xyzw);
5517}
5518
5519void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
5520{
5521 programUniform1fv(program, location, 1, &v0);
5522}
5523
5524void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
5525{
5526 GLfloat xy[2] = {v0, v1};
5527 programUniform2fv(program, location, 1, xy);
5528}
5529
5530void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
5531{
5532 GLfloat xyz[3] = {v0, v1, v2};
5533 programUniform3fv(program, location, 1, xyz);
5534}
5535
5536void Context::programUniform4f(GLuint program,
5537 GLint location,
5538 GLfloat v0,
5539 GLfloat v1,
5540 GLfloat v2,
5541 GLfloat v3)
5542{
5543 GLfloat xyzw[4] = {v0, v1, v2, v3};
5544 programUniform4fv(program, location, 1, xyzw);
5545}
5546
Jamie Madill81c2e252017-09-09 23:32:46 -04005547void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5548{
5549 Program *programObject = getProgram(program);
5550 ASSERT(programObject);
5551 if (programObject->setUniform1iv(location, count, value) ==
5552 Program::SetUniformResult::SamplerChanged)
5553 {
5554 mGLState.setObjectDirty(GL_PROGRAM);
5555 }
5556}
5557
Jiajia Qin5451d532017-11-16 17:16:34 +08005558void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5559{
5560 Program *programObject = getProgram(program);
5561 ASSERT(programObject);
5562 programObject->setUniform2iv(location, count, value);
5563}
5564
5565void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5566{
5567 Program *programObject = getProgram(program);
5568 ASSERT(programObject);
5569 programObject->setUniform3iv(location, count, value);
5570}
5571
5572void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5573{
5574 Program *programObject = getProgram(program);
5575 ASSERT(programObject);
5576 programObject->setUniform4iv(location, count, value);
5577}
5578
5579void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5580{
5581 Program *programObject = getProgram(program);
5582 ASSERT(programObject);
5583 programObject->setUniform1uiv(location, count, value);
5584}
5585
5586void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5587{
5588 Program *programObject = getProgram(program);
5589 ASSERT(programObject);
5590 programObject->setUniform2uiv(location, count, value);
5591}
5592
5593void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5594{
5595 Program *programObject = getProgram(program);
5596 ASSERT(programObject);
5597 programObject->setUniform3uiv(location, count, value);
5598}
5599
5600void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5601{
5602 Program *programObject = getProgram(program);
5603 ASSERT(programObject);
5604 programObject->setUniform4uiv(location, count, value);
5605}
5606
5607void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5608{
5609 Program *programObject = getProgram(program);
5610 ASSERT(programObject);
5611 programObject->setUniform1fv(location, count, value);
5612}
5613
5614void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5615{
5616 Program *programObject = getProgram(program);
5617 ASSERT(programObject);
5618 programObject->setUniform2fv(location, count, value);
5619}
5620
5621void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5622{
5623 Program *programObject = getProgram(program);
5624 ASSERT(programObject);
5625 programObject->setUniform3fv(location, count, value);
5626}
5627
5628void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5629{
5630 Program *programObject = getProgram(program);
5631 ASSERT(programObject);
5632 programObject->setUniform4fv(location, count, value);
5633}
5634
5635void Context::programUniformMatrix2fv(GLuint program,
5636 GLint location,
5637 GLsizei count,
5638 GLboolean transpose,
5639 const GLfloat *value)
5640{
5641 Program *programObject = getProgram(program);
5642 ASSERT(programObject);
5643 programObject->setUniformMatrix2fv(location, count, transpose, value);
5644}
5645
5646void Context::programUniformMatrix3fv(GLuint program,
5647 GLint location,
5648 GLsizei count,
5649 GLboolean transpose,
5650 const GLfloat *value)
5651{
5652 Program *programObject = getProgram(program);
5653 ASSERT(programObject);
5654 programObject->setUniformMatrix3fv(location, count, transpose, value);
5655}
5656
5657void Context::programUniformMatrix4fv(GLuint program,
5658 GLint location,
5659 GLsizei count,
5660 GLboolean transpose,
5661 const GLfloat *value)
5662{
5663 Program *programObject = getProgram(program);
5664 ASSERT(programObject);
5665 programObject->setUniformMatrix4fv(location, count, transpose, value);
5666}
5667
5668void Context::programUniformMatrix2x3fv(GLuint program,
5669 GLint location,
5670 GLsizei count,
5671 GLboolean transpose,
5672 const GLfloat *value)
5673{
5674 Program *programObject = getProgram(program);
5675 ASSERT(programObject);
5676 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
5677}
5678
5679void Context::programUniformMatrix3x2fv(GLuint program,
5680 GLint location,
5681 GLsizei count,
5682 GLboolean transpose,
5683 const GLfloat *value)
5684{
5685 Program *programObject = getProgram(program);
5686 ASSERT(programObject);
5687 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
5688}
5689
5690void Context::programUniformMatrix2x4fv(GLuint program,
5691 GLint location,
5692 GLsizei count,
5693 GLboolean transpose,
5694 const GLfloat *value)
5695{
5696 Program *programObject = getProgram(program);
5697 ASSERT(programObject);
5698 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
5699}
5700
5701void Context::programUniformMatrix4x2fv(GLuint program,
5702 GLint location,
5703 GLsizei count,
5704 GLboolean transpose,
5705 const GLfloat *value)
5706{
5707 Program *programObject = getProgram(program);
5708 ASSERT(programObject);
5709 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
5710}
5711
5712void Context::programUniformMatrix3x4fv(GLuint program,
5713 GLint location,
5714 GLsizei count,
5715 GLboolean transpose,
5716 const GLfloat *value)
5717{
5718 Program *programObject = getProgram(program);
5719 ASSERT(programObject);
5720 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
5721}
5722
5723void Context::programUniformMatrix4x3fv(GLuint program,
5724 GLint location,
5725 GLsizei count,
5726 GLboolean transpose,
5727 const GLfloat *value)
5728{
5729 Program *programObject = getProgram(program);
5730 ASSERT(programObject);
5731 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
5732}
5733
Jamie Madill81c2e252017-09-09 23:32:46 -04005734void Context::onTextureChange(const Texture *texture)
5735{
5736 // Conservatively assume all textures are dirty.
5737 // TODO(jmadill): More fine-grained update.
5738 mGLState.setObjectDirty(GL_TEXTURE);
5739}
5740
James Darpiniane8a93c62018-01-04 18:02:24 -08005741bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
5742{
5743 return mGLState.isCurrentTransformFeedback(tf);
5744}
5745bool Context::isCurrentVertexArray(const VertexArray *va) const
5746{
5747 return mGLState.isCurrentVertexArray(va);
5748}
5749
Yunchao Hea336b902017-08-02 16:05:21 +08005750void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
5751{
5752 for (int i = 0; i < count; i++)
5753 {
5754 pipelines[i] = createProgramPipeline();
5755 }
5756}
5757
5758void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
5759{
5760 for (int i = 0; i < count; i++)
5761 {
5762 if (pipelines[i] != 0)
5763 {
5764 deleteProgramPipeline(pipelines[i]);
5765 }
5766 }
5767}
5768
5769GLboolean Context::isProgramPipeline(GLuint pipeline)
5770{
5771 if (pipeline == 0)
5772 {
5773 return GL_FALSE;
5774 }
5775
5776 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
5777}
5778
Jamie Madill2b7bbc22017-12-21 17:30:38 -05005779void Context::finishFenceNV(GLuint fence)
5780{
5781 FenceNV *fenceObject = getFenceNV(fence);
5782
5783 ASSERT(fenceObject && fenceObject->isSet());
5784 handleError(fenceObject->finish());
5785}
5786
5787void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
5788{
5789 FenceNV *fenceObject = getFenceNV(fence);
5790
5791 ASSERT(fenceObject && fenceObject->isSet());
5792
5793 switch (pname)
5794 {
5795 case GL_FENCE_STATUS_NV:
5796 {
5797 // GL_NV_fence spec:
5798 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
5799 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
5800 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
5801 GLboolean status = GL_TRUE;
5802 if (fenceObject->getStatus() != GL_TRUE)
5803 {
5804 ANGLE_CONTEXT_TRY(fenceObject->test(&status));
5805 }
5806 *params = status;
5807 break;
5808 }
5809
5810 case GL_FENCE_CONDITION_NV:
5811 {
5812 *params = static_cast<GLint>(fenceObject->getCondition());
5813 break;
5814 }
5815
5816 default:
5817 UNREACHABLE();
5818 }
5819}
5820
5821void Context::getTranslatedShaderSource(GLuint shader,
5822 GLsizei bufsize,
5823 GLsizei *length,
5824 GLchar *source)
5825{
5826 Shader *shaderObject = getShader(shader);
5827 ASSERT(shaderObject);
5828 shaderObject->getTranslatedSourceWithDebugInfo(this, bufsize, length, source);
5829}
5830
5831void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
5832{
5833 Program *programObject = getProgram(program);
5834 ASSERT(programObject);
5835
5836 programObject->getUniformfv(this, location, params);
5837}
5838
5839void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
5840{
5841 Program *programObject = getProgram(program);
5842 ASSERT(programObject);
5843
5844 programObject->getUniformiv(this, location, params);
5845}
5846
5847GLboolean Context::isFenceNV(GLuint fence)
5848{
5849 FenceNV *fenceObject = getFenceNV(fence);
5850
5851 if (fenceObject == nullptr)
5852 {
5853 return GL_FALSE;
5854 }
5855
5856 // GL_NV_fence spec:
5857 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
5858 // existing fence.
5859 return fenceObject->isSet();
5860}
5861
5862void Context::readnPixels(GLint x,
5863 GLint y,
5864 GLsizei width,
5865 GLsizei height,
5866 GLenum format,
5867 GLenum type,
5868 GLsizei bufSize,
5869 void *data)
5870{
5871 return readPixels(x, y, width, height, format, type, data);
5872}
5873
Jamie Madill007530e2017-12-28 14:27:04 -05005874void Context::setFenceNV(GLuint fence, GLenum condition)
5875{
5876 ASSERT(condition == GL_ALL_COMPLETED_NV);
5877
5878 FenceNV *fenceObject = getFenceNV(fence);
5879 ASSERT(fenceObject != nullptr);
5880 handleError(fenceObject->set(condition));
5881}
5882
5883GLboolean Context::testFenceNV(GLuint fence)
5884{
5885 FenceNV *fenceObject = getFenceNV(fence);
5886
5887 ASSERT(fenceObject != nullptr);
5888 ASSERT(fenceObject->isSet() == GL_TRUE);
5889
5890 GLboolean result = GL_TRUE;
5891 Error error = fenceObject->test(&result);
5892 if (error.isError())
5893 {
5894 handleError(error);
5895 return GL_TRUE;
5896 }
5897
5898 return result;
5899}
5900
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005901void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05005902{
5903 Texture *texture = getTargetTexture(target);
5904 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005905 handleError(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05005906}
5907
Jamie Madillfa920eb2018-01-04 11:45:50 -05005908void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05005909{
5910 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
5911 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
5912 handleError(renderbuffer->setStorageEGLImageTarget(this, imageObject));
5913}
5914
Jamie Madillfa920eb2018-01-04 11:45:50 -05005915void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
5916{
5917 UNIMPLEMENTED();
5918}
5919
Geoff Lang2aaa7b42018-01-12 17:17:27 -05005920void Context::alphaFunc(GLenum func, GLfloat ref)
5921{
5922 UNIMPLEMENTED();
5923}
5924
5925void Context::alphaFuncx(GLenum func, GLfixed ref)
5926{
5927 UNIMPLEMENTED();
5928}
5929
5930void Context::clearColorx(GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha)
5931{
5932 UNIMPLEMENTED();
5933}
5934
5935void Context::clearDepthx(GLfixed depth)
5936{
5937 UNIMPLEMENTED();
5938}
5939
5940void Context::clientActiveTexture(GLenum texture)
5941{
5942 UNIMPLEMENTED();
5943}
5944
5945void Context::clipPlanef(GLenum p, const GLfloat *eqn)
5946{
5947 UNIMPLEMENTED();
5948}
5949
5950void Context::clipPlanex(GLenum plane, const GLfixed *equation)
5951{
5952 UNIMPLEMENTED();
5953}
5954
5955void Context::color4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
5956{
5957 UNIMPLEMENTED();
5958}
5959
5960void Context::color4ub(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha)
5961{
5962 UNIMPLEMENTED();
5963}
5964
5965void Context::color4x(GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha)
5966{
5967 UNIMPLEMENTED();
5968}
5969
5970void Context::colorPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
5971{
5972 UNIMPLEMENTED();
5973}
5974
5975void Context::cullFace(GLenum mode)
5976{
5977 UNIMPLEMENTED();
5978}
5979
5980void Context::depthRangex(GLfixed n, GLfixed f)
5981{
5982 UNIMPLEMENTED();
5983}
5984
5985void Context::disableClientState(GLenum array)
5986{
5987 UNIMPLEMENTED();
5988}
5989
5990void Context::enableClientState(GLenum array)
5991{
5992 UNIMPLEMENTED();
5993}
5994
5995void Context::fogf(GLenum pname, GLfloat param)
5996{
5997 UNIMPLEMENTED();
5998}
5999
6000void Context::fogfv(GLenum pname, const GLfloat *params)
6001{
6002 UNIMPLEMENTED();
6003}
6004
6005void Context::fogx(GLenum pname, GLfixed param)
6006{
6007 UNIMPLEMENTED();
6008}
6009
6010void Context::fogxv(GLenum pname, const GLfixed *param)
6011{
6012 UNIMPLEMENTED();
6013}
6014
6015void Context::frustumf(GLfloat l, GLfloat r, GLfloat b, GLfloat t, GLfloat n, GLfloat f)
6016{
6017 UNIMPLEMENTED();
6018}
6019
6020void Context::frustumx(GLfixed l, GLfixed r, GLfixed b, GLfixed t, GLfixed n, GLfixed f)
6021{
6022 UNIMPLEMENTED();
6023}
6024
6025void Context::getBufferParameteriv(GLenum target, GLenum pname, GLint *params)
6026{
6027 UNIMPLEMENTED();
6028}
6029
6030void Context::getClipPlanef(GLenum plane, GLfloat *equation)
6031{
6032 UNIMPLEMENTED();
6033}
6034
6035void Context::getClipPlanex(GLenum plane, GLfixed *equation)
6036{
6037 UNIMPLEMENTED();
6038}
6039
6040void Context::getFixedv(GLenum pname, GLfixed *params)
6041{
6042 UNIMPLEMENTED();
6043}
6044
6045void Context::getLightfv(GLenum light, GLenum pname, GLfloat *params)
6046{
6047 UNIMPLEMENTED();
6048}
6049
6050void Context::getLightxv(GLenum light, GLenum pname, GLfixed *params)
6051{
6052 UNIMPLEMENTED();
6053}
6054
6055void Context::getMaterialfv(GLenum face, GLenum pname, GLfloat *params)
6056{
6057 UNIMPLEMENTED();
6058}
6059
6060void Context::getMaterialxv(GLenum face, GLenum pname, GLfixed *params)
6061{
6062 UNIMPLEMENTED();
6063}
6064
6065void Context::getTexEnvfv(GLenum target, GLenum pname, GLfloat *params)
6066{
6067 UNIMPLEMENTED();
6068}
6069
6070void Context::getTexEnviv(GLenum target, GLenum pname, GLint *params)
6071{
6072 UNIMPLEMENTED();
6073}
6074
6075void Context::getTexEnvxv(GLenum target, GLenum pname, GLfixed *params)
6076{
6077 UNIMPLEMENTED();
6078}
6079
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006080void Context::getTexParameterxv(TextureType target, GLenum pname, GLfixed *params)
Geoff Lang2aaa7b42018-01-12 17:17:27 -05006081{
6082 UNIMPLEMENTED();
6083}
6084
6085void Context::lightModelf(GLenum pname, GLfloat param)
6086{
6087 UNIMPLEMENTED();
6088}
6089
6090void Context::lightModelfv(GLenum pname, const GLfloat *params)
6091{
6092 UNIMPLEMENTED();
6093}
6094
6095void Context::lightModelx(GLenum pname, GLfixed param)
6096{
6097 UNIMPLEMENTED();
6098}
6099
6100void Context::lightModelxv(GLenum pname, const GLfixed *param)
6101{
6102 UNIMPLEMENTED();
6103}
6104
6105void Context::lightf(GLenum light, GLenum pname, GLfloat param)
6106{
6107 UNIMPLEMENTED();
6108}
6109
6110void Context::lightfv(GLenum light, GLenum pname, const GLfloat *params)
6111{
6112 UNIMPLEMENTED();
6113}
6114
6115void Context::lightx(GLenum light, GLenum pname, GLfixed param)
6116{
6117 UNIMPLEMENTED();
6118}
6119
6120void Context::lightxv(GLenum light, GLenum pname, const GLfixed *params)
6121{
6122 UNIMPLEMENTED();
6123}
6124
6125void Context::lineWidthx(GLfixed width)
6126{
6127 UNIMPLEMENTED();
6128}
6129
6130void Context::loadIdentity()
6131{
6132 UNIMPLEMENTED();
6133}
6134
6135void Context::loadMatrixf(const GLfloat *m)
6136{
6137 UNIMPLEMENTED();
6138}
6139
6140void Context::loadMatrixx(const GLfixed *m)
6141{
6142 UNIMPLEMENTED();
6143}
6144
6145void Context::logicOp(GLenum opcode)
6146{
6147 UNIMPLEMENTED();
6148}
6149
6150void Context::materialf(GLenum face, GLenum pname, GLfloat param)
6151{
6152 UNIMPLEMENTED();
6153}
6154
6155void Context::materialfv(GLenum face, GLenum pname, const GLfloat *params)
6156{
6157 UNIMPLEMENTED();
6158}
6159
6160void Context::materialx(GLenum face, GLenum pname, GLfixed param)
6161{
6162 UNIMPLEMENTED();
6163}
6164
6165void Context::materialxv(GLenum face, GLenum pname, const GLfixed *param)
6166{
6167 UNIMPLEMENTED();
6168}
6169
6170void Context::matrixMode(GLenum mode)
6171{
6172 UNIMPLEMENTED();
6173}
6174
6175void Context::multMatrixf(const GLfloat *m)
6176{
6177 UNIMPLEMENTED();
6178}
6179
6180void Context::multMatrixx(const GLfixed *m)
6181{
6182 UNIMPLEMENTED();
6183}
6184
6185void Context::multiTexCoord4f(GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q)
6186{
6187 UNIMPLEMENTED();
6188}
6189
6190void Context::multiTexCoord4x(GLenum texture, GLfixed s, GLfixed t, GLfixed r, GLfixed q)
6191{
6192 UNIMPLEMENTED();
6193}
6194
6195void Context::normal3f(GLfloat nx, GLfloat ny, GLfloat nz)
6196{
6197 UNIMPLEMENTED();
6198}
6199
6200void Context::normal3x(GLfixed nx, GLfixed ny, GLfixed nz)
6201{
6202 UNIMPLEMENTED();
6203}
6204
6205void Context::normalPointer(GLenum type, GLsizei stride, const void *pointer)
6206{
6207 UNIMPLEMENTED();
6208}
6209
6210void Context::orthof(GLfloat l, GLfloat r, GLfloat b, GLfloat t, GLfloat n, GLfloat f)
6211{
6212 UNIMPLEMENTED();
6213}
6214
6215void Context::orthox(GLfixed l, GLfixed r, GLfixed b, GLfixed t, GLfixed n, GLfixed f)
6216{
6217 UNIMPLEMENTED();
6218}
6219
6220void Context::pointParameterf(GLenum pname, GLfloat param)
6221{
6222 UNIMPLEMENTED();
6223}
6224
6225void Context::pointParameterfv(GLenum pname, const GLfloat *params)
6226{
6227 UNIMPLEMENTED();
6228}
6229
6230void Context::pointParameterx(GLenum pname, GLfixed param)
6231{
6232 UNIMPLEMENTED();
6233}
6234
6235void Context::pointParameterxv(GLenum pname, const GLfixed *params)
6236{
6237 UNIMPLEMENTED();
6238}
6239
6240void Context::pointSize(GLfloat size)
6241{
6242 UNIMPLEMENTED();
6243}
6244
6245void Context::pointSizex(GLfixed size)
6246{
6247 UNIMPLEMENTED();
6248}
6249
6250void Context::polygonOffsetx(GLfixed factor, GLfixed units)
6251{
6252 UNIMPLEMENTED();
6253}
6254
6255void Context::popMatrix()
6256{
6257 UNIMPLEMENTED();
6258}
6259
6260void Context::pushMatrix()
6261{
6262 UNIMPLEMENTED();
6263}
6264
6265void Context::rotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z)
6266{
6267 UNIMPLEMENTED();
6268}
6269
6270void Context::rotatex(GLfixed angle, GLfixed x, GLfixed y, GLfixed z)
6271{
6272 UNIMPLEMENTED();
6273}
6274
6275void Context::sampleCoveragex(GLclampx value, GLboolean invert)
6276{
6277 UNIMPLEMENTED();
6278}
6279
6280void Context::scalef(GLfloat x, GLfloat y, GLfloat z)
6281{
6282 UNIMPLEMENTED();
6283}
6284
6285void Context::scalex(GLfixed x, GLfixed y, GLfixed z)
6286{
6287 UNIMPLEMENTED();
6288}
6289
6290void Context::shadeModel(GLenum mode)
6291{
6292 UNIMPLEMENTED();
6293}
6294
6295void Context::texCoordPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
6296{
6297 UNIMPLEMENTED();
6298}
6299
6300void Context::texEnvf(GLenum target, GLenum pname, GLfloat param)
6301{
6302 UNIMPLEMENTED();
6303}
6304
6305void Context::texEnvfv(GLenum target, GLenum pname, const GLfloat *params)
6306{
6307 UNIMPLEMENTED();
6308}
6309
6310void Context::texEnvi(GLenum target, GLenum pname, GLint param)
6311{
6312 UNIMPLEMENTED();
6313}
6314
6315void Context::texEnviv(GLenum target, GLenum pname, const GLint *params)
6316{
6317 UNIMPLEMENTED();
6318}
6319
6320void Context::texEnvx(GLenum target, GLenum pname, GLfixed param)
6321{
6322 UNIMPLEMENTED();
6323}
6324
6325void Context::texEnvxv(GLenum target, GLenum pname, const GLfixed *params)
6326{
6327 UNIMPLEMENTED();
6328}
6329
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006330void Context::texParameterx(TextureType target, GLenum pname, GLfixed param)
Geoff Lang2aaa7b42018-01-12 17:17:27 -05006331{
6332 UNIMPLEMENTED();
6333}
6334
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006335void Context::texParameterxv(TextureType target, GLenum pname, const GLfixed *params)
Geoff Lang2aaa7b42018-01-12 17:17:27 -05006336{
6337 UNIMPLEMENTED();
6338}
6339
6340void Context::translatef(GLfloat x, GLfloat y, GLfloat z)
6341{
6342 UNIMPLEMENTED();
6343}
6344
6345void Context::translatex(GLfixed x, GLfixed y, GLfixed z)
6346{
6347 UNIMPLEMENTED();
6348}
6349
6350void Context::vertexPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
6351{
6352 UNIMPLEMENTED();
6353}
6354
6355void Context::drawTexf(GLfloat x, GLfloat y, GLfloat z, GLfloat width, GLfloat height)
6356{
6357 UNIMPLEMENTED();
6358}
6359
6360void Context::drawTexfv(const GLfloat *coords)
6361{
6362 UNIMPLEMENTED();
6363}
6364
6365void Context::drawTexi(GLint x, GLint y, GLint z, GLint width, GLint height)
6366{
6367 UNIMPLEMENTED();
6368}
6369
6370void Context::drawTexiv(const GLint *coords)
6371{
6372 UNIMPLEMENTED();
6373}
6374
6375void Context::drawTexs(GLshort x, GLshort y, GLshort z, GLshort width, GLshort height)
6376{
6377 UNIMPLEMENTED();
6378}
6379
6380void Context::drawTexsv(const GLshort *coords)
6381{
6382 UNIMPLEMENTED();
6383}
6384
6385void Context::drawTexx(GLfixed x, GLfixed y, GLfixed z, GLfixed width, GLfixed height)
6386{
6387 UNIMPLEMENTED();
6388}
6389
6390void Context::drawTexxv(const GLfixed *coords)
6391{
6392 UNIMPLEMENTED();
6393}
6394
6395void Context::currentPaletteMatrix(GLuint matrixpaletteindex)
6396{
6397 UNIMPLEMENTED();
6398}
6399
6400void Context::loadPaletteFromModelViewMatrix()
6401{
6402 UNIMPLEMENTED();
6403}
6404
6405void Context::matrixIndexPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
6406{
6407 UNIMPLEMENTED();
6408}
6409
6410void Context::weightPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
6411{
6412 UNIMPLEMENTED();
6413}
6414
6415void Context::pointSizePointer(GLenum type, GLsizei stride, const void *pointer)
6416{
6417 UNIMPLEMENTED();
6418}
6419
6420GLbitfield Context::queryMatrixx(GLfixed *mantissa, GLint *exponent)
6421{
6422 UNIMPLEMENTED();
6423 return 0;
6424}
6425
Jamie Madillc29968b2016-01-20 11:17:23 -05006426} // namespace gl