blob: c51cf33028033ac2626fba3fb88cf93e13476fd5 [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"
Geoff Lang2b5420c2014-11-19 14:20:15 -050029#include "libANGLE/Query.h"
Jamie Madillb9293972015-02-19 11:07:54 -050030#include "libANGLE/Renderbuffer.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050031#include "libANGLE/ResourceManager.h"
32#include "libANGLE/Sampler.h"
Jamie Madill9dd0cf02014-11-24 11:38:51 -050033#include "libANGLE/Surface.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050034#include "libANGLE/Texture.h"
35#include "libANGLE/TransformFeedback.h"
36#include "libANGLE/VertexArray.h"
Kenneth Russellf2f6f652016-10-05 19:53:23 -070037#include "libANGLE/Workarounds.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040038#include "libANGLE/formatutils.h"
Martin Radev66fb8202016-07-28 11:45:20 +030039#include "libANGLE/queryconversions.h"
Geoff Langc1984ed2016-10-07 12:41:00 -040040#include "libANGLE/queryutils.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040041#include "libANGLE/renderer/ContextImpl.h"
42#include "libANGLE/renderer/EGLImplFactory.h"
43#include "libANGLE/validationES.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000044
Geoff Langf6db0982015-08-25 13:04:00 -040045namespace
46{
47
Ian Ewell3ffd78b2016-01-22 16:09:42 -050048template <typename T>
Geoff Lang4ddf5af2016-12-01 14:30:44 -050049std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager,
Sami Väisänend59ca052016-06-21 16:10:00 +030050 GLsizei numPaths,
51 const void *paths,
52 GLuint pathBase)
53{
54 std::vector<gl::Path *> ret;
55 ret.reserve(numPaths);
56
57 const auto *nameArray = static_cast<const T *>(paths);
58
59 for (GLsizei i = 0; i < numPaths; ++i)
60 {
61 const GLuint pathName = nameArray[i] + pathBase;
62
63 ret.push_back(resourceManager.getPath(pathName));
64 }
65
66 return ret;
67}
68
Geoff Lang4ddf5af2016-12-01 14:30:44 -050069std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager,
Sami Väisänend59ca052016-06-21 16:10:00 +030070 GLsizei numPaths,
71 GLenum pathNameType,
72 const void *paths,
73 GLuint pathBase)
74{
75 switch (pathNameType)
76 {
77 case GL_UNSIGNED_BYTE:
78 return GatherPaths<GLubyte>(resourceManager, numPaths, paths, pathBase);
79
80 case GL_BYTE:
81 return GatherPaths<GLbyte>(resourceManager, numPaths, paths, pathBase);
82
83 case GL_UNSIGNED_SHORT:
84 return GatherPaths<GLushort>(resourceManager, numPaths, paths, pathBase);
85
86 case GL_SHORT:
87 return GatherPaths<GLshort>(resourceManager, numPaths, paths, pathBase);
88
89 case GL_UNSIGNED_INT:
90 return GatherPaths<GLuint>(resourceManager, numPaths, paths, pathBase);
91
92 case GL_INT:
93 return GatherPaths<GLint>(resourceManager, numPaths, paths, pathBase);
94 }
95
96 UNREACHABLE();
97 return std::vector<gl::Path *>();
98}
99
100template <typename T>
Geoff Lang2186c382016-10-14 10:54:54 -0400101gl::Error GetQueryObjectParameter(gl::Query *query, GLenum pname, T *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500102{
Geoff Lang2186c382016-10-14 10:54:54 -0400103 ASSERT(query != nullptr);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500104
105 switch (pname)
106 {
107 case GL_QUERY_RESULT_EXT:
Geoff Lang2186c382016-10-14 10:54:54 -0400108 return query->getResult(params);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500109 case GL_QUERY_RESULT_AVAILABLE_EXT:
110 {
111 bool available;
Geoff Lang2186c382016-10-14 10:54:54 -0400112 gl::Error error = query->isResultAvailable(&available);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500113 if (!error.isError())
114 {
Geoff Lang2186c382016-10-14 10:54:54 -0400115 *params = gl::ConvertFromGLboolean<T>(available);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500116 }
117 return error;
118 }
119 default:
120 UNREACHABLE();
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500121 return gl::InternalError() << "Unreachable Error";
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500122 }
123}
124
Geoff Langf6db0982015-08-25 13:04:00 -0400125void MarkTransformFeedbackBufferUsage(gl::TransformFeedback *transformFeedback)
126{
Geoff Lang1a683462015-09-29 15:09:59 -0400127 if (transformFeedback && transformFeedback->isActive() && !transformFeedback->isPaused())
Geoff Langf6db0982015-08-25 13:04:00 -0400128 {
129 for (size_t tfBufferIndex = 0; tfBufferIndex < transformFeedback->getIndexedBufferCount();
130 tfBufferIndex++)
131 {
132 const OffsetBindingPointer<gl::Buffer> &buffer =
133 transformFeedback->getIndexedBuffer(tfBufferIndex);
134 if (buffer.get() != nullptr)
135 {
136 buffer->onTransformFeedback();
137 }
138 }
139 }
140}
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500141
142// Attribute map queries.
Martin Radev1be913c2016-07-11 17:59:16 +0300143EGLint GetClientMajorVersion(const egl::AttributeMap &attribs)
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500144{
Ian Ewellec2c0c52016-04-05 13:46:26 -0400145 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_CLIENT_VERSION, 1));
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500146}
147
Martin Radev1be913c2016-07-11 17:59:16 +0300148EGLint GetClientMinorVersion(const egl::AttributeMap &attribs)
149{
150 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_MINOR_VERSION, 0));
151}
152
Geoff Langeb66a6e2016-10-31 13:06:12 -0400153gl::Version GetClientVersion(const egl::AttributeMap &attribs)
154{
155 return gl::Version(GetClientMajorVersion(attribs), GetClientMinorVersion(attribs));
156}
157
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500158GLenum GetResetStrategy(const egl::AttributeMap &attribs)
159{
Ian Ewellec2c0c52016-04-05 13:46:26 -0400160 EGLAttrib attrib = attribs.get(EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT,
161 EGL_NO_RESET_NOTIFICATION_EXT);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500162 switch (attrib)
163 {
164 case EGL_NO_RESET_NOTIFICATION:
165 return GL_NO_RESET_NOTIFICATION_EXT;
166 case EGL_LOSE_CONTEXT_ON_RESET:
167 return GL_LOSE_CONTEXT_ON_RESET_EXT;
168 default:
169 UNREACHABLE();
170 return GL_NONE;
171 }
172}
173
174bool GetRobustAccess(const egl::AttributeMap &attribs)
175{
Geoff Lang077f20a2016-11-01 10:08:02 -0400176 return (attribs.get(EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT, EGL_FALSE) == EGL_TRUE) ||
177 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR) !=
178 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500179}
180
181bool GetDebug(const egl::AttributeMap &attribs)
182{
Geoff Lang077f20a2016-11-01 10:08:02 -0400183 return (attribs.get(EGL_CONTEXT_OPENGL_DEBUG, EGL_FALSE) == EGL_TRUE) ||
184 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR) != 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500185}
186
187bool GetNoError(const egl::AttributeMap &attribs)
188{
189 return (attribs.get(EGL_CONTEXT_OPENGL_NO_ERROR_KHR, EGL_FALSE) == EGL_TRUE);
190}
191
Geoff Langc287ea62016-09-16 14:46:51 -0400192bool GetWebGLContext(const egl::AttributeMap &attribs)
193{
194 return (attribs.get(EGL_CONTEXT_WEBGL_COMPATIBILITY_ANGLE, EGL_FALSE) == EGL_TRUE);
195}
196
Geoff Langf41a7152016-09-19 15:11:17 -0400197bool GetBindGeneratesResource(const egl::AttributeMap &attribs)
198{
199 return (attribs.get(EGL_CONTEXT_BIND_GENERATES_RESOURCE_CHROMIUM, EGL_TRUE) == EGL_TRUE);
200}
201
Geoff Langfeb8c682017-02-13 16:07:35 -0500202bool GetClientArraysEnabled(const egl::AttributeMap &attribs)
203{
204 return (attribs.get(EGL_CONTEXT_CLIENT_ARRAYS_ENABLED_ANGLE, EGL_TRUE) == EGL_TRUE);
205}
206
Martin Radev9d901792016-07-15 15:58:58 +0300207std::string GetObjectLabelFromPointer(GLsizei length, const GLchar *label)
208{
209 std::string labelName;
210 if (label != nullptr)
211 {
212 size_t labelLength = length < 0 ? strlen(label) : length;
213 labelName = std::string(label, labelLength);
214 }
215 return labelName;
216}
217
218void GetObjectLabelBase(const std::string &objectLabel,
219 GLsizei bufSize,
220 GLsizei *length,
221 GLchar *label)
222{
223 size_t writeLength = objectLabel.length();
224 if (label != nullptr && bufSize > 0)
225 {
226 writeLength = std::min(static_cast<size_t>(bufSize) - 1, objectLabel.length());
227 std::copy(objectLabel.begin(), objectLabel.begin() + writeLength, label);
228 label[writeLength] = '\0';
229 }
230
231 if (length != nullptr)
232 {
233 *length = static_cast<GLsizei>(writeLength);
234 }
235}
236
Geoff Langf6db0982015-08-25 13:04:00 -0400237} // anonymous namespace
238
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000239namespace gl
240{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +0000241
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400242Context::Context(rx::EGLImplFactory *implFactory,
243 const egl::Config *config,
Corentin Wallez51706ea2015-08-07 14:39:22 -0400244 const Context *shareContext,
Geoff Langce02f082017-02-06 16:46:21 -0500245 TextureManager *shareTextures,
Corentin Wallezc295e512017-01-27 17:47:50 -0500246 const egl::AttributeMap &attribs,
Jamie Madill948bbe52017-06-01 13:10:42 -0400247 const egl::DisplayExtensions &displayExtensions,
248 bool robustResourceInit)
Martin Radev1be913c2016-07-11 17:59:16 +0300249
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500250 : ValidationContext(shareContext,
Geoff Langce02f082017-02-06 16:46:21 -0500251 shareTextures,
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500252 GetClientVersion(attribs),
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700253 &mGLState,
Jamie Madillf25855c2015-11-03 11:06:18 -0500254 mCaps,
255 mTextureCaps,
256 mExtensions,
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500257 mLimitations,
258 GetNoError(attribs)),
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700259 mImplementation(implFactory->createContext(mState)),
Jamie Madill2f348d22017-06-05 10:50:59 -0400260 mCompiler(),
Corentin Walleze3b10e82015-05-20 11:06:25 -0400261 mConfig(config),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500262 mClientType(EGL_OPENGL_ES_API),
263 mHasBeenCurrent(false),
264 mContextLost(false),
265 mResetStatus(GL_NO_ERROR),
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700266 mContextLostForced(false),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500267 mResetStrategy(GetResetStrategy(attribs)),
268 mRobustAccess(GetRobustAccess(attribs)),
Corentin Wallezccab69d2017-01-27 16:57:15 -0500269 mCurrentSurface(nullptr),
Jamie Madill4e0e6f82017-02-17 11:06:03 -0500270 mSurfacelessFramebuffer(nullptr),
Jamie Madille14951e2017-03-09 18:55:16 -0500271 mWebGLContext(GetWebGLContext(attribs)),
272 mScratchBuffer(1000u)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000273{
Geoff Lang077f20a2016-11-01 10:08:02 -0400274 if (mRobustAccess)
275 {
276 UNIMPLEMENTED();
277 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000278
Jamie Madill4e0e6f82017-02-17 11:06:03 -0500279 initCaps(displayExtensions);
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700280 initWorkarounds();
Geoff Langc0b9ef42014-07-02 10:02:37 -0400281
Geoff Langeb66a6e2016-10-31 13:06:12 -0400282 mGLState.initialize(mCaps, mExtensions, getClientVersion(), GetDebug(attribs),
Jamie Madille08a1d32017-03-07 17:24:06 -0500283 GetBindGeneratesResource(attribs), GetClientArraysEnabled(attribs),
Jamie Madill948bbe52017-06-01 13:10:42 -0400284 robustResourceInit);
Régis Fénéon83107972015-02-05 12:57:44 +0100285
Shannon Woods53a94a82014-06-24 15:20:36 -0400286 mFenceNVHandleAllocator.setBaseHandle(0);
Geoff Lang7dca1862013-07-30 16:30:46 -0400287
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000288 // [OpenGL ES 2.0.24] section 3.7 page 83:
289 // In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have twodimensional
290 // and cube map texture state vectors respectively associated with them.
291 // In order that access to these initial textures not be lost, they are treated as texture
292 // objects all of whose names are 0.
293
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400294 Texture *zeroTexture2D = new Texture(mImplementation.get(), 0, GL_TEXTURE_2D);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500295 mZeroTextures[GL_TEXTURE_2D].set(zeroTexture2D);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500296
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400297 Texture *zeroTextureCube = new Texture(mImplementation.get(), 0, GL_TEXTURE_CUBE_MAP);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500298 mZeroTextures[GL_TEXTURE_CUBE_MAP].set(zeroTextureCube);
Geoff Lang76b10c92014-09-05 16:28:14 -0400299
Geoff Langeb66a6e2016-10-31 13:06:12 -0400300 if (getClientVersion() >= Version(3, 0))
Geoff Lang76b10c92014-09-05 16:28:14 -0400301 {
302 // TODO: These could also be enabled via extension
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400303 Texture *zeroTexture3D = new Texture(mImplementation.get(), 0, GL_TEXTURE_3D);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500304 mZeroTextures[GL_TEXTURE_3D].set(zeroTexture3D);
Geoff Lang76b10c92014-09-05 16:28:14 -0400305
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400306 Texture *zeroTexture2DArray = new Texture(mImplementation.get(), 0, GL_TEXTURE_2D_ARRAY);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500307 mZeroTextures[GL_TEXTURE_2D_ARRAY].set(zeroTexture2DArray);
Geoff Lang76b10c92014-09-05 16:28:14 -0400308 }
Geoff Lang3b573612016-10-31 14:08:10 -0400309 if (getClientVersion() >= Version(3, 1))
310 {
311 Texture *zeroTexture2DMultisample =
312 new Texture(mImplementation.get(), 0, GL_TEXTURE_2D_MULTISAMPLE);
313 mZeroTextures[GL_TEXTURE_2D_MULTISAMPLE].set(zeroTexture2DMultisample);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800314
315 bindGenericAtomicCounterBuffer(0);
316 for (unsigned int i = 0; i < mCaps.maxAtomicCounterBufferBindings; i++)
317 {
318 bindIndexedAtomicCounterBuffer(0, i, 0, 0);
319 }
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800320
321 bindGenericShaderStorageBuffer(0);
322 for (unsigned int i = 0; i < mCaps.maxShaderStorageBufferBindings; i++)
323 {
324 bindIndexedShaderStorageBuffer(0, i, 0, 0);
325 }
Geoff Lang3b573612016-10-31 14:08:10 -0400326 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000327
Ian Ewellbda75592016-04-18 17:25:54 -0400328 if (mExtensions.eglImageExternal || mExtensions.eglStreamConsumerExternal)
329 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400330 Texture *zeroTextureExternal =
331 new Texture(mImplementation.get(), 0, GL_TEXTURE_EXTERNAL_OES);
Ian Ewellbda75592016-04-18 17:25:54 -0400332 mZeroTextures[GL_TEXTURE_EXTERNAL_OES].set(zeroTextureExternal);
333 }
334
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700335 mGLState.initializeZeroTextures(mZeroTextures);
Jamie Madille6382c32014-11-07 15:05:26 -0500336
Jamie Madill57a89722013-07-02 11:57:03 -0400337 bindVertexArray(0);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000338 bindArrayBuffer(0);
Jiajia Qin9d7d0b12016-11-29 16:30:31 +0800339 bindDrawIndirectBuffer(0);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000340 bindElementArrayBuffer(0);
Geoff Lang76b10c92014-09-05 16:28:14 -0400341
Jamie Madill01a80ee2016-11-07 12:06:18 -0500342 bindRenderbuffer(GL_RENDERBUFFER, 0);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000343
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +0000344 bindGenericUniformBuffer(0);
Geoff Lang4dc3af02016-11-18 14:09:27 -0500345 for (unsigned int i = 0; i < mCaps.maxUniformBufferBindings; i++)
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +0000346 {
347 bindIndexedUniformBuffer(0, i, 0, -1);
348 }
349
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000350 bindCopyReadBuffer(0);
351 bindCopyWriteBuffer(0);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +0000352 bindPixelPackBuffer(0);
353 bindPixelUnpackBuffer(0);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000354
Geoff Langeb66a6e2016-10-31 13:06:12 -0400355 if (getClientVersion() >= Version(3, 0))
Geoff Lang1a683462015-09-29 15:09:59 -0400356 {
357 // [OpenGL ES 3.0.2] section 2.14.1 pg 85:
358 // In the initial state, a default transform feedback object is bound and treated as
359 // a transform feedback object with a name of zero. That object is bound any time
360 // BindTransformFeedback is called with id of zero
Geoff Lang1a683462015-09-29 15:09:59 -0400361 bindTransformFeedback(0);
362 }
Geoff Langc8058452014-02-03 12:04:11 -0500363
Jamie Madillad9f24e2016-02-12 09:27:24 -0500364 // Initialize dirty bit masks
365 // TODO(jmadill): additional ES3 state
366 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_ALIGNMENT);
367 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_ROW_LENGTH);
368 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_IMAGE_HEIGHT);
369 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_SKIP_IMAGES);
370 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_SKIP_ROWS);
371 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_SKIP_PIXELS);
Corentin Wallezbbd663a2016-04-20 17:49:17 -0400372 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500373 // No dirty objects.
374
375 // Readpixels uses the pack state and read FBO
376 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_ALIGNMENT);
377 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_REVERSE_ROW_ORDER);
378 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_ROW_LENGTH);
379 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_SKIP_ROWS);
380 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_SKIP_PIXELS);
Corentin Wallezbbd663a2016-04-20 17:49:17 -0400381 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500382 mReadPixelsDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
383
384 mClearDirtyBits.set(State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED);
385 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
386 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR);
387 mClearDirtyBits.set(State::DIRTY_BIT_VIEWPORT);
388 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_COLOR);
389 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_DEPTH);
390 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_STENCIL);
391 mClearDirtyBits.set(State::DIRTY_BIT_COLOR_MASK);
392 mClearDirtyBits.set(State::DIRTY_BIT_DEPTH_MASK);
393 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT);
394 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_BACK);
395 mClearDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
396
397 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
398 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR);
Geoff Lang1d2c41d2016-10-19 16:14:46 -0700399 mBlitDirtyBits.set(State::DIRTY_BIT_FRAMEBUFFER_SRGB);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500400 mBlitDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
401 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
Jamie Madill437fa652016-05-03 15:13:24 -0400402
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400403 handleError(mImplementation->initialize());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000404}
405
Jamie Madill70ee0f62017-02-06 16:04:20 -0500406void Context::destroy(egl::Display *display)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000407{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500408 mGLState.reset(this);
Geoff Lang21329412014-12-02 20:50:30 +0000409
Corentin Wallez80b24112015-08-25 16:41:57 -0400410 for (auto fence : mFenceNVMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000411 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400412 SafeDelete(fence.second);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000413 }
414
Corentin Wallez80b24112015-08-25 16:41:57 -0400415 for (auto query : mQueryMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000416 {
Geoff Langf0aa8422015-09-29 15:08:34 -0400417 if (query.second != nullptr)
418 {
419 query.second->release();
420 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000421 }
422
Corentin Wallez80b24112015-08-25 16:41:57 -0400423 for (auto vertexArray : mVertexArrayMap)
Jamie Madill57a89722013-07-02 11:57:03 -0400424 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400425 SafeDelete(vertexArray.second);
Jamie Madill57a89722013-07-02 11:57:03 -0400426 }
427
Corentin Wallez80b24112015-08-25 16:41:57 -0400428 for (auto transformFeedback : mTransformFeedbackMap)
Geoff Langc8058452014-02-03 12:04:11 -0500429 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500430 if (transformFeedback.second != nullptr)
431 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500432 transformFeedback.second->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500433 }
Geoff Langc8058452014-02-03 12:04:11 -0500434 }
435
Jamie Madilldedd7b92014-11-05 16:30:36 -0500436 for (auto &zeroTexture : mZeroTextures)
Geoff Lang76b10c92014-09-05 16:28:14 -0400437 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +0800438 zeroTexture.second.set(nullptr);
Geoff Lang76b10c92014-09-05 16:28:14 -0400439 }
440 mZeroTextures.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000441
Corentin Wallezccab69d2017-01-27 16:57:15 -0500442 SafeDelete(mSurfacelessFramebuffer);
443
Jamie Madill70ee0f62017-02-06 16:04:20 -0500444 releaseSurface(display);
Jamie Madill2f348d22017-06-05 10:50:59 -0400445 releaseShaderCompiler();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500446
447 mState.mBuffers->release(this);
448 mState.mShaderPrograms->release(this);
449 mState.mTextures->release(this);
450 mState.mRenderbuffers->release(this);
451 mState.mSamplers->release(this);
452 mState.mFenceSyncs->release(this);
453 mState.mPaths->release(this);
454 mState.mFramebuffers->release(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000455}
456
Jamie Madill70ee0f62017-02-06 16:04:20 -0500457Context::~Context()
458{
459}
460
461void Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000462{
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000463 if (!mHasBeenCurrent)
464 {
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000465 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500466 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400467 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000468
Corentin Wallezc295e512017-01-27 17:47:50 -0500469 int width = 0;
470 int height = 0;
471 if (surface != nullptr)
472 {
473 width = surface->getWidth();
474 height = surface->getHeight();
475 }
476
477 mGLState.setViewportParams(0, 0, width, height);
478 mGLState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000479
480 mHasBeenCurrent = true;
481 }
482
Jamie Madill1b94d432015-08-07 13:23:23 -0400483 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700484 mGLState.setAllDirtyBits();
Jamie Madill1b94d432015-08-07 13:23:23 -0400485
Jamie Madill70ee0f62017-02-06 16:04:20 -0500486 releaseSurface(display);
Corentin Wallezccab69d2017-01-27 16:57:15 -0500487
488 Framebuffer *newDefault = nullptr;
489 if (surface != nullptr)
490 {
Jamie Madill70ee0f62017-02-06 16:04:20 -0500491 surface->setIsCurrent(display, true);
Corentin Wallezccab69d2017-01-27 16:57:15 -0500492 mCurrentSurface = surface;
493 newDefault = surface->getDefaultFramebuffer();
494 }
495 else
496 {
497 if (mSurfacelessFramebuffer == nullptr)
498 {
499 mSurfacelessFramebuffer = new Framebuffer(mImplementation.get());
500 }
501
502 newDefault = mSurfacelessFramebuffer;
503 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000504
Corentin Wallez37c39792015-08-20 14:19:46 -0400505 // Update default framebuffer, the binding of the previous default
506 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400507 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700508 if (mGLState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400509 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700510 mGLState.setReadFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400511 }
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700512 if (mGLState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400513 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700514 mGLState.setDrawFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400515 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500516 mState.mFramebuffers->setDefaultFramebuffer(newDefault);
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400517 }
Ian Ewell292f0052016-02-04 10:37:32 -0500518
519 // Notify the renderer of a context switch
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700520 mImplementation->onMakeCurrent(mState);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000521}
522
Jamie Madill70ee0f62017-02-06 16:04:20 -0500523void Context::releaseSurface(egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400524{
Corentin Wallez37c39792015-08-20 14:19:46 -0400525 // Remove the default framebuffer
Corentin Wallezc295e512017-01-27 17:47:50 -0500526 Framebuffer *currentDefault = nullptr;
527 if (mCurrentSurface != nullptr)
Corentin Wallez51706ea2015-08-07 14:39:22 -0400528 {
Corentin Wallezc295e512017-01-27 17:47:50 -0500529 currentDefault = mCurrentSurface->getDefaultFramebuffer();
530 }
531 else if (mSurfacelessFramebuffer != nullptr)
532 {
533 currentDefault = mSurfacelessFramebuffer;
Corentin Wallez51706ea2015-08-07 14:39:22 -0400534 }
535
Corentin Wallezc295e512017-01-27 17:47:50 -0500536 if (mGLState.getReadFramebuffer() == currentDefault)
537 {
538 mGLState.setReadFramebufferBinding(nullptr);
539 }
540 if (mGLState.getDrawFramebuffer() == currentDefault)
541 {
542 mGLState.setDrawFramebufferBinding(nullptr);
543 }
544 mState.mFramebuffers->setDefaultFramebuffer(nullptr);
545
546 if (mCurrentSurface)
547 {
Jamie Madill70ee0f62017-02-06 16:04:20 -0500548 mCurrentSurface->setIsCurrent(display, false);
Corentin Wallezc295e512017-01-27 17:47:50 -0500549 mCurrentSurface = nullptr;
550 }
Jamie Madill77a72f62015-04-14 11:18:32 -0400551}
552
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000553GLuint Context::createBuffer()
554{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500555 return mState.mBuffers->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000556}
557
558GLuint Context::createProgram()
559{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500560 return mState.mShaderPrograms->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000561}
562
563GLuint Context::createShader(GLenum type)
564{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500565 return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000566}
567
568GLuint Context::createTexture()
569{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500570 return mState.mTextures->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000571}
572
573GLuint Context::createRenderbuffer()
574{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500575 return mState.mRenderbuffers->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000576}
577
Geoff Lang882033e2014-09-30 11:26:07 -0400578GLsync Context::createFenceSync()
Jamie Madillcd055f82013-07-26 11:55:15 -0400579{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500580 GLuint handle = mState.mFenceSyncs->createFenceSync(mImplementation.get());
Jamie Madillcd055f82013-07-26 11:55:15 -0400581
Cooper Partind8e62a32015-01-29 15:21:25 -0800582 return reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madillcd055f82013-07-26 11:55:15 -0400583}
584
Sami Väisänene45e53b2016-05-25 10:36:04 +0300585GLuint Context::createPaths(GLsizei range)
586{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500587 auto resultOrError = mState.mPaths->createPaths(mImplementation.get(), range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300588 if (resultOrError.isError())
589 {
590 handleError(resultOrError.getError());
591 return 0;
592 }
593 return resultOrError.getResult();
594}
595
Jamie Madill57a89722013-07-02 11:57:03 -0400596GLuint Context::createVertexArray()
597{
Geoff Lang36167ab2015-12-07 10:27:14 -0500598 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
599 mVertexArrayMap[vertexArray] = nullptr;
600 return vertexArray;
Jamie Madill57a89722013-07-02 11:57:03 -0400601}
602
Jamie Madilldc356042013-07-19 16:36:57 -0400603GLuint Context::createSampler()
604{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500605 return mState.mSamplers->createSampler();
Jamie Madilldc356042013-07-19 16:36:57 -0400606}
607
Geoff Langc8058452014-02-03 12:04:11 -0500608GLuint Context::createTransformFeedback()
609{
Geoff Lang36167ab2015-12-07 10:27:14 -0500610 GLuint transformFeedback = mTransformFeedbackAllocator.allocate();
611 mTransformFeedbackMap[transformFeedback] = nullptr;
612 return transformFeedback;
Geoff Langc8058452014-02-03 12:04:11 -0500613}
614
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000615// Returns an unused framebuffer name
616GLuint Context::createFramebuffer()
617{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500618 return mState.mFramebuffers->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000619}
620
Jamie Madill33dc8432013-07-26 11:55:05 -0400621GLuint Context::createFenceNV()
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000622{
Jamie Madill33dc8432013-07-26 11:55:05 -0400623 GLuint handle = mFenceNVHandleAllocator.allocate();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000624
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400625 mFenceNVMap[handle] = new FenceNV(mImplementation->createFenceNV());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000626
627 return handle;
628}
629
630// Returns an unused query name
631GLuint Context::createQuery()
632{
633 GLuint handle = mQueryHandleAllocator.allocate();
634
Yunchao Hed7297bf2017-04-19 15:27:10 +0800635 mQueryMap[handle] = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000636
637 return handle;
638}
639
640void Context::deleteBuffer(GLuint buffer)
641{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500642 if (mState.mBuffers->getBuffer(buffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000643 {
644 detachBuffer(buffer);
645 }
Jamie Madill893ab082014-05-16 16:56:10 -0400646
Jamie Madill6c1f6712017-02-14 19:08:04 -0500647 mState.mBuffers->deleteObject(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000648}
649
650void Context::deleteShader(GLuint shader)
651{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500652 mState.mShaderPrograms->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000653}
654
655void Context::deleteProgram(GLuint program)
656{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500657 mState.mShaderPrograms->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000658}
659
660void Context::deleteTexture(GLuint texture)
661{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500662 if (mState.mTextures->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000663 {
664 detachTexture(texture);
665 }
666
Jamie Madill6c1f6712017-02-14 19:08:04 -0500667 mState.mTextures->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000668}
669
670void Context::deleteRenderbuffer(GLuint renderbuffer)
671{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500672 if (mState.mRenderbuffers->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000673 {
674 detachRenderbuffer(renderbuffer);
675 }
Jamie Madill893ab082014-05-16 16:56:10 -0400676
Jamie Madill6c1f6712017-02-14 19:08:04 -0500677 mState.mRenderbuffers->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000678}
679
Jamie Madillcd055f82013-07-26 11:55:15 -0400680void Context::deleteFenceSync(GLsync fenceSync)
681{
682 // The spec specifies the underlying Fence object is not deleted until all current
683 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
684 // and since our API is currently designed for being called from a single thread, we can delete
685 // the fence immediately.
Jamie Madill6c1f6712017-02-14 19:08:04 -0500686 mState.mFenceSyncs->deleteObject(this,
687 static_cast<GLuint>(reinterpret_cast<uintptr_t>(fenceSync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400688}
689
Sami Väisänene45e53b2016-05-25 10:36:04 +0300690void Context::deletePaths(GLuint first, GLsizei range)
691{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500692 mState.mPaths->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300693}
694
695bool Context::hasPathData(GLuint path) const
696{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500697 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300698 if (pathObj == nullptr)
699 return false;
700
701 return pathObj->hasPathData();
702}
703
704bool Context::hasPath(GLuint path) const
705{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500706 return mState.mPaths->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300707}
708
709void Context::setPathCommands(GLuint path,
710 GLsizei numCommands,
711 const GLubyte *commands,
712 GLsizei numCoords,
713 GLenum coordType,
714 const void *coords)
715{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500716 auto *pathObject = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300717
718 handleError(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
719}
720
721void Context::setPathParameterf(GLuint path, GLenum pname, GLfloat value)
722{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500723 auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300724
725 switch (pname)
726 {
727 case GL_PATH_STROKE_WIDTH_CHROMIUM:
728 pathObj->setStrokeWidth(value);
729 break;
730 case GL_PATH_END_CAPS_CHROMIUM:
731 pathObj->setEndCaps(static_cast<GLenum>(value));
732 break;
733 case GL_PATH_JOIN_STYLE_CHROMIUM:
734 pathObj->setJoinStyle(static_cast<GLenum>(value));
735 break;
736 case GL_PATH_MITER_LIMIT_CHROMIUM:
737 pathObj->setMiterLimit(value);
738 break;
739 case GL_PATH_STROKE_BOUND_CHROMIUM:
740 pathObj->setStrokeBound(value);
741 break;
742 default:
743 UNREACHABLE();
744 break;
745 }
746}
747
748void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value) const
749{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500750 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300751
752 switch (pname)
753 {
754 case GL_PATH_STROKE_WIDTH_CHROMIUM:
755 *value = pathObj->getStrokeWidth();
756 break;
757 case GL_PATH_END_CAPS_CHROMIUM:
758 *value = static_cast<GLfloat>(pathObj->getEndCaps());
759 break;
760 case GL_PATH_JOIN_STYLE_CHROMIUM:
761 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
762 break;
763 case GL_PATH_MITER_LIMIT_CHROMIUM:
764 *value = pathObj->getMiterLimit();
765 break;
766 case GL_PATH_STROKE_BOUND_CHROMIUM:
767 *value = pathObj->getStrokeBound();
768 break;
769 default:
770 UNREACHABLE();
771 break;
772 }
773}
774
775void Context::setPathStencilFunc(GLenum func, GLint ref, GLuint mask)
776{
777 mGLState.setPathStencilFunc(func, ref, mask);
778}
779
Jamie Madill57a89722013-07-02 11:57:03 -0400780void Context::deleteVertexArray(GLuint vertexArray)
781{
Geoff Lang36167ab2015-12-07 10:27:14 -0500782 auto iter = mVertexArrayMap.find(vertexArray);
783 if (iter != mVertexArrayMap.end())
Geoff Lang50b3fe82015-12-08 14:49:12 +0000784 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500785 VertexArray *vertexArrayObject = iter->second;
786 if (vertexArrayObject != nullptr)
787 {
788 detachVertexArray(vertexArray);
789 delete vertexArrayObject;
790 }
Geoff Lang50b3fe82015-12-08 14:49:12 +0000791
Geoff Lang36167ab2015-12-07 10:27:14 -0500792 mVertexArrayMap.erase(iter);
793 mVertexArrayHandleAllocator.release(vertexArray);
Jamie Madill57a89722013-07-02 11:57:03 -0400794 }
795}
796
Jamie Madilldc356042013-07-19 16:36:57 -0400797void Context::deleteSampler(GLuint sampler)
798{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500799 if (mState.mSamplers->getSampler(sampler))
Jamie Madilldc356042013-07-19 16:36:57 -0400800 {
801 detachSampler(sampler);
802 }
803
Jamie Madill6c1f6712017-02-14 19:08:04 -0500804 mState.mSamplers->deleteObject(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -0400805}
806
Geoff Langc8058452014-02-03 12:04:11 -0500807void Context::deleteTransformFeedback(GLuint transformFeedback)
808{
Geoff Lang6e60d6b2017-04-12 12:59:04 -0400809 if (transformFeedback == 0)
810 {
811 return;
812 }
813
Jamie Madill5fd0b2d2015-01-05 13:38:44 -0500814 auto iter = mTransformFeedbackMap.find(transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -0500815 if (iter != mTransformFeedbackMap.end())
816 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500817 TransformFeedback *transformFeedbackObject = iter->second;
818 if (transformFeedbackObject != nullptr)
819 {
820 detachTransformFeedback(transformFeedback);
Jamie Madill6c1f6712017-02-14 19:08:04 -0500821 transformFeedbackObject->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500822 }
823
Geoff Lang50b3fe82015-12-08 14:49:12 +0000824 mTransformFeedbackMap.erase(iter);
Geoff Lang36167ab2015-12-07 10:27:14 -0500825 mTransformFeedbackAllocator.release(transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -0500826 }
827}
828
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000829void Context::deleteFramebuffer(GLuint framebuffer)
830{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500831 if (mState.mFramebuffers->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000832 {
833 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000834 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500835
Jamie Madill6c1f6712017-02-14 19:08:04 -0500836 mState.mFramebuffers->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000837}
838
Jamie Madill33dc8432013-07-26 11:55:05 -0400839void Context::deleteFenceNV(GLuint fence)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000840{
Jamie Madill4e25a0d2016-03-08 13:53:03 -0500841 auto fenceObject = mFenceNVMap.find(fence);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000842
Jamie Madill33dc8432013-07-26 11:55:05 -0400843 if (fenceObject != mFenceNVMap.end())
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000844 {
Jamie Madill33dc8432013-07-26 11:55:05 -0400845 mFenceNVHandleAllocator.release(fenceObject->first);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000846 delete fenceObject->second;
Jamie Madill33dc8432013-07-26 11:55:05 -0400847 mFenceNVMap.erase(fenceObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000848 }
849}
850
851void Context::deleteQuery(GLuint query)
852{
Jamie Madill4e25a0d2016-03-08 13:53:03 -0500853 auto queryObject = mQueryMap.find(query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000854 if (queryObject != mQueryMap.end())
855 {
856 mQueryHandleAllocator.release(queryObject->first);
857 if (queryObject->second)
858 {
859 queryObject->second->release();
860 }
861 mQueryMap.erase(queryObject);
862 }
863}
864
Geoff Lang70d0f492015-12-10 17:45:46 -0500865Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000866{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500867 return mState.mBuffers->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000868}
869
Jamie Madill570f7c82014-07-03 10:38:54 -0400870Texture *Context::getTexture(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000871{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500872 return mState.mTextures->getTexture(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000873}
874
Geoff Lang70d0f492015-12-10 17:45:46 -0500875Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000876{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500877 return mState.mRenderbuffers->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000878}
879
Jamie Madillcd055f82013-07-26 11:55:15 -0400880FenceSync *Context::getFenceSync(GLsync handle) const
881{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500882 return mState.mFenceSyncs->getFenceSync(
883 static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400884}
885
Jamie Madill57a89722013-07-02 11:57:03 -0400886VertexArray *Context::getVertexArray(GLuint handle) const
887{
888 auto vertexArray = mVertexArrayMap.find(handle);
Geoff Lang36167ab2015-12-07 10:27:14 -0500889 return (vertexArray != mVertexArrayMap.end()) ? vertexArray->second : nullptr;
Jamie Madill57a89722013-07-02 11:57:03 -0400890}
891
Jamie Madilldc356042013-07-19 16:36:57 -0400892Sampler *Context::getSampler(GLuint handle) const
893{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500894 return mState.mSamplers->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400895}
896
Geoff Langc8058452014-02-03 12:04:11 -0500897TransformFeedback *Context::getTransformFeedback(GLuint handle) const
898{
Geoff Lang36167ab2015-12-07 10:27:14 -0500899 auto iter = mTransformFeedbackMap.find(handle);
900 return (iter != mTransformFeedbackMap.end()) ? iter->second : nullptr;
Geoff Langc8058452014-02-03 12:04:11 -0500901}
902
Geoff Lang70d0f492015-12-10 17:45:46 -0500903LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
904{
905 switch (identifier)
906 {
907 case GL_BUFFER:
908 return getBuffer(name);
909 case GL_SHADER:
910 return getShader(name);
911 case GL_PROGRAM:
912 return getProgram(name);
913 case GL_VERTEX_ARRAY:
914 return getVertexArray(name);
915 case GL_QUERY:
916 return getQuery(name);
917 case GL_TRANSFORM_FEEDBACK:
918 return getTransformFeedback(name);
919 case GL_SAMPLER:
920 return getSampler(name);
921 case GL_TEXTURE:
922 return getTexture(name);
923 case GL_RENDERBUFFER:
924 return getRenderbuffer(name);
925 case GL_FRAMEBUFFER:
926 return getFramebuffer(name);
927 default:
928 UNREACHABLE();
929 return nullptr;
930 }
931}
932
933LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
934{
935 return getFenceSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
936}
937
Martin Radev9d901792016-07-15 15:58:58 +0300938void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
939{
940 LabeledObject *object = getLabeledObject(identifier, name);
941 ASSERT(object != nullptr);
942
943 std::string labelName = GetObjectLabelFromPointer(length, label);
944 object->setLabel(labelName);
945}
946
947void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
948{
949 LabeledObject *object = getLabeledObjectFromPtr(ptr);
950 ASSERT(object != nullptr);
951
952 std::string labelName = GetObjectLabelFromPointer(length, label);
953 object->setLabel(labelName);
954}
955
956void Context::getObjectLabel(GLenum identifier,
957 GLuint name,
958 GLsizei bufSize,
959 GLsizei *length,
960 GLchar *label) const
961{
962 LabeledObject *object = getLabeledObject(identifier, name);
963 ASSERT(object != nullptr);
964
965 const std::string &objectLabel = object->getLabel();
966 GetObjectLabelBase(objectLabel, bufSize, length, label);
967}
968
969void Context::getObjectPtrLabel(const void *ptr,
970 GLsizei bufSize,
971 GLsizei *length,
972 GLchar *label) const
973{
974 LabeledObject *object = getLabeledObjectFromPtr(ptr);
975 ASSERT(object != nullptr);
976
977 const std::string &objectLabel = object->getLabel();
978 GetObjectLabelBase(objectLabel, bufSize, length, label);
979}
980
Jamie Madilldc356042013-07-19 16:36:57 -0400981bool Context::isSampler(GLuint samplerName) const
982{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500983 return mState.mSamplers->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -0400984}
985
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500986void Context::bindArrayBuffer(GLuint bufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000987{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500988 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700989 mGLState.setArrayBufferBinding(buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000990}
991
Jiajia Qin9d7d0b12016-11-29 16:30:31 +0800992void Context::bindDrawIndirectBuffer(GLuint bufferHandle)
993{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500994 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jiajia Qin9d7d0b12016-11-29 16:30:31 +0800995 mGLState.setDrawIndirectBufferBinding(buffer);
996}
997
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500998void Context::bindElementArrayBuffer(GLuint bufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000999{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001000 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Shao80957d92017-02-20 21:25:59 +08001001 mGLState.setElementArrayBuffer(buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001002}
1003
Jamie Madilldedd7b92014-11-05 16:30:36 -05001004void Context::bindTexture(GLenum target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001005{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001006 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001007
Jamie Madilldedd7b92014-11-05 16:30:36 -05001008 if (handle == 0)
1009 {
1010 texture = mZeroTextures[target].get();
1011 }
1012 else
1013 {
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001014 texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -05001015 }
1016
1017 ASSERT(texture);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001018 mGLState.setSamplerTexture(target, texture);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00001019}
1020
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001021void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001022{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001023 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1024 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001025 mGLState.setReadFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001026}
1027
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001028void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001029{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001030 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1031 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001032 mGLState.setDrawFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001033}
1034
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001035void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -04001036{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001037 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001038 mGLState.setVertexArrayBinding(vertexArray);
Jamie Madill57a89722013-07-02 11:57:03 -04001039}
1040
Shao80957d92017-02-20 21:25:59 +08001041void Context::bindVertexBuffer(GLuint bindingIndex,
1042 GLuint bufferHandle,
1043 GLintptr offset,
1044 GLsizei stride)
1045{
1046 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
1047 mGLState.bindVertexBuffer(bindingIndex, buffer, offset, stride);
1048}
1049
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001050void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -04001051{
Geoff Lang76b10c92014-09-05 16:28:14 -04001052 ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -04001053 Sampler *sampler =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001054 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001055 mGLState.setSamplerBinding(textureUnit, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04001056}
1057
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001058void Context::bindGenericUniformBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001059{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001060 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001061 mGLState.setGenericUniformBufferBinding(buffer);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001062}
1063
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001064void Context::bindIndexedUniformBuffer(GLuint bufferHandle,
1065 GLuint index,
1066 GLintptr offset,
1067 GLsizeiptr size)
shannon.woods%transgaming.com@gtempaccount.com34089352013-04-13 03:36:57 +00001068{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001069 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001070 mGLState.setIndexedUniformBufferBinding(index, buffer, offset, size);
shannon.woods%transgaming.com@gtempaccount.com34089352013-04-13 03:36:57 +00001071}
1072
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001073void Context::bindGenericTransformFeedbackBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001074{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001075 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001076 mGLState.getCurrentTransformFeedback()->bindGenericBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001077}
1078
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001079void Context::bindIndexedTransformFeedbackBuffer(GLuint bufferHandle,
1080 GLuint index,
1081 GLintptr offset,
1082 GLsizeiptr size)
shannon.woods%transgaming.com@gtempaccount.com34089352013-04-13 03:36:57 +00001083{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001084 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001085 mGLState.getCurrentTransformFeedback()->bindIndexedBuffer(index, buffer, offset, size);
shannon.woods%transgaming.com@gtempaccount.com34089352013-04-13 03:36:57 +00001086}
1087
Jiajia Qin6eafb042016-12-27 17:04:07 +08001088void Context::bindGenericAtomicCounterBuffer(GLuint bufferHandle)
1089{
1090 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
1091 mGLState.setGenericAtomicCounterBufferBinding(buffer);
1092}
1093
1094void Context::bindIndexedAtomicCounterBuffer(GLuint bufferHandle,
1095 GLuint index,
1096 GLintptr offset,
1097 GLsizeiptr size)
1098{
1099 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
1100 mGLState.setIndexedAtomicCounterBufferBinding(index, buffer, offset, size);
1101}
1102
Jiajia Qinf546e7d2017-03-27 14:12:59 +08001103void Context::bindGenericShaderStorageBuffer(GLuint bufferHandle)
1104{
1105 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
1106 mGLState.setGenericShaderStorageBufferBinding(buffer);
1107}
1108
1109void Context::bindIndexedShaderStorageBuffer(GLuint bufferHandle,
1110 GLuint index,
1111 GLintptr offset,
1112 GLsizeiptr size)
1113{
1114 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
1115 mGLState.setIndexedShaderStorageBufferBinding(index, buffer, offset, size);
1116}
1117
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001118void Context::bindCopyReadBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001119{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001120 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001121 mGLState.setCopyReadBufferBinding(buffer);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001122}
1123
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001124void Context::bindCopyWriteBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001125{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001126 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001127 mGLState.setCopyWriteBufferBinding(buffer);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001128}
1129
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001130void Context::bindPixelPackBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001131{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001132 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001133 mGLState.setPixelPackBufferBinding(buffer);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001134}
1135
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001136void Context::bindPixelUnpackBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001137{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001138 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001139 mGLState.setPixelUnpackBufferBinding(buffer);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001140}
1141
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001142void Context::useProgram(GLuint program)
1143{
Jamie Madill6c1f6712017-02-14 19:08:04 -05001144 mGLState.setProgram(this, getProgram(program));
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001145}
1146
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001147void Context::bindTransformFeedback(GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001148{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001149 TransformFeedback *transformFeedback =
1150 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001151 mGLState.setTransformFeedbackBinding(transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -05001152}
1153
Geoff Lang5aad9672014-09-08 11:10:42 -04001154Error Context::beginQuery(GLenum target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001155{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001156 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001157 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001158
Geoff Lang5aad9672014-09-08 11:10:42 -04001159 // begin query
1160 Error error = queryObject->begin();
1161 if (error.isError())
1162 {
1163 return error;
1164 }
1165
1166 // set query as active for specified target only if begin succeeded
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001167 mGLState.setActiveQuery(target, queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001168
He Yunchaoacd18982017-01-04 10:46:42 +08001169 return NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001170}
1171
Geoff Lang5aad9672014-09-08 11:10:42 -04001172Error Context::endQuery(GLenum target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001173{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001174 Query *queryObject = mGLState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001175 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001176
Geoff Lang5aad9672014-09-08 11:10:42 -04001177 gl::Error error = queryObject->end();
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001178
Geoff Lang5aad9672014-09-08 11:10:42 -04001179 // Always unbind the query, even if there was an error. This may delete the query object.
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001180 mGLState.setActiveQuery(target, nullptr);
Geoff Lang5aad9672014-09-08 11:10:42 -04001181
1182 return error;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001183}
1184
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001185Error Context::queryCounter(GLuint id, GLenum target)
1186{
1187 ASSERT(target == GL_TIMESTAMP_EXT);
1188
1189 Query *queryObject = getQuery(id, true, target);
1190 ASSERT(queryObject);
1191
1192 return queryObject->queryCounter();
1193}
1194
1195void Context::getQueryiv(GLenum target, GLenum pname, GLint *params)
1196{
1197 switch (pname)
1198 {
1199 case GL_CURRENT_QUERY_EXT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001200 params[0] = mGLState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001201 break;
1202 case GL_QUERY_COUNTER_BITS_EXT:
1203 switch (target)
1204 {
1205 case GL_TIME_ELAPSED_EXT:
1206 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1207 break;
1208 case GL_TIMESTAMP_EXT:
1209 params[0] = getExtensions().queryCounterBitsTimestamp;
1210 break;
1211 default:
1212 UNREACHABLE();
1213 params[0] = 0;
1214 break;
1215 }
1216 break;
1217 default:
1218 UNREACHABLE();
1219 return;
1220 }
1221}
1222
Geoff Lang2186c382016-10-14 10:54:54 -04001223void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001224{
Geoff Lang2186c382016-10-14 10:54:54 -04001225 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001226}
1227
Geoff Lang2186c382016-10-14 10:54:54 -04001228void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001229{
Geoff Lang2186c382016-10-14 10:54:54 -04001230 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001231}
1232
Geoff Lang2186c382016-10-14 10:54:54 -04001233void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001234{
Geoff Lang2186c382016-10-14 10:54:54 -04001235 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001236}
1237
Geoff Lang2186c382016-10-14 10:54:54 -04001238void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001239{
Geoff Lang2186c382016-10-14 10:54:54 -04001240 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001241}
1242
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001243Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001244{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001245 return mState.mFramebuffers->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001246}
1247
Jamie Madill2f348d22017-06-05 10:50:59 -04001248FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001249{
Jamie Madill4e25a0d2016-03-08 13:53:03 -05001250 auto fence = mFenceNVMap.find(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001251
Jamie Madill33dc8432013-07-26 11:55:05 -04001252 if (fence == mFenceNVMap.end())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001253 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001254 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001255 }
1256 else
1257 {
1258 return fence->second;
1259 }
1260}
1261
Jamie Madill2f348d22017-06-05 10:50:59 -04001262Query *Context::getQuery(GLuint handle, bool create, GLenum type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001263{
Jamie Madill4e25a0d2016-03-08 13:53:03 -05001264 auto query = mQueryMap.find(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001265
1266 if (query == mQueryMap.end())
1267 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001268 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001269 }
1270 else
1271 {
1272 if (!query->second && create)
1273 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001274 query->second = new Query(mImplementation->createQuery(type), handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001275 query->second->addRef();
1276 }
1277 return query->second;
1278 }
1279}
1280
Geoff Lang70d0f492015-12-10 17:45:46 -05001281Query *Context::getQuery(GLuint handle) const
1282{
1283 auto iter = mQueryMap.find(handle);
1284 return (iter != mQueryMap.end()) ? iter->second : nullptr;
1285}
1286
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001287Texture *Context::getTargetTexture(GLenum target) const
1288{
Ian Ewellbda75592016-04-18 17:25:54 -04001289 ASSERT(ValidTextureTarget(this, target) || ValidTextureExternalTarget(this, target));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001290 return mGLState.getTargetTexture(target);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001291}
1292
Geoff Lang76b10c92014-09-05 16:28:14 -04001293Texture *Context::getSamplerTexture(unsigned int sampler, GLenum type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001294{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001295 return mGLState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001296}
1297
Geoff Lang492a7e42014-11-05 13:27:06 -05001298Compiler *Context::getCompiler() const
1299{
Jamie Madill2f348d22017-06-05 10:50:59 -04001300 if (mCompiler.get() == nullptr)
1301 {
1302 mCompiler.set(new Compiler(mImplementation.get(), mState));
1303 }
1304 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001305}
1306
Jamie Madillc1d770e2017-04-13 17:31:24 -04001307void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001308{
1309 switch (pname)
1310 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001311 case GL_SHADER_COMPILER:
1312 *params = GL_TRUE;
1313 break;
1314 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1315 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1316 break;
1317 default:
1318 mGLState.getBooleanv(pname, params);
1319 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001320 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001321}
1322
Jamie Madillc1d770e2017-04-13 17:31:24 -04001323void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001324{
Shannon Woods53a94a82014-06-24 15:20:36 -04001325 // Queries about context capabilities and maximums are answered by Context.
1326 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001327 switch (pname)
1328 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001329 case GL_ALIASED_LINE_WIDTH_RANGE:
1330 params[0] = mCaps.minAliasedLineWidth;
1331 params[1] = mCaps.maxAliasedLineWidth;
1332 break;
1333 case GL_ALIASED_POINT_SIZE_RANGE:
1334 params[0] = mCaps.minAliasedPointSize;
1335 params[1] = mCaps.maxAliasedPointSize;
1336 break;
1337 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1338 ASSERT(mExtensions.textureFilterAnisotropic);
1339 *params = mExtensions.maxTextureAnisotropy;
1340 break;
1341 case GL_MAX_TEXTURE_LOD_BIAS:
1342 *params = mCaps.maxLODBias;
1343 break;
1344
1345 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1346 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1347 {
1348 ASSERT(mExtensions.pathRendering);
1349 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1350 memcpy(params, m, 16 * sizeof(GLfloat));
1351 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001352 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001353
Jamie Madill231c7f52017-04-26 13:45:37 -04001354 default:
1355 mGLState.getFloatv(pname, params);
1356 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001357 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001358}
1359
Jamie Madillc1d770e2017-04-13 17:31:24 -04001360void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001361{
Shannon Woods53a94a82014-06-24 15:20:36 -04001362 // Queries about context capabilities and maximums are answered by Context.
1363 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001364
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001365 switch (pname)
1366 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001367 case GL_MAX_VERTEX_ATTRIBS:
1368 *params = mCaps.maxVertexAttributes;
1369 break;
1370 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1371 *params = mCaps.maxVertexUniformVectors;
1372 break;
1373 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
1374 *params = mCaps.maxVertexUniformComponents;
1375 break;
1376 case GL_MAX_VARYING_VECTORS:
1377 *params = mCaps.maxVaryingVectors;
1378 break;
1379 case GL_MAX_VARYING_COMPONENTS:
1380 *params = mCaps.maxVertexOutputComponents;
1381 break;
1382 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1383 *params = mCaps.maxCombinedTextureImageUnits;
1384 break;
1385 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
1386 *params = mCaps.maxVertexTextureImageUnits;
1387 break;
1388 case GL_MAX_TEXTURE_IMAGE_UNITS:
1389 *params = mCaps.maxTextureImageUnits;
1390 break;
1391 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1392 *params = mCaps.maxFragmentUniformVectors;
1393 break;
1394 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
1395 *params = mCaps.maxFragmentUniformComponents;
1396 break;
1397 case GL_MAX_RENDERBUFFER_SIZE:
1398 *params = mCaps.maxRenderbufferSize;
1399 break;
1400 case GL_MAX_COLOR_ATTACHMENTS_EXT:
1401 *params = mCaps.maxColorAttachments;
1402 break;
1403 case GL_MAX_DRAW_BUFFERS_EXT:
1404 *params = mCaps.maxDrawBuffers;
1405 break;
1406 // case GL_FRAMEBUFFER_BINDING: // now equivalent to
1407 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
1408 case GL_SUBPIXEL_BITS:
1409 *params = 4;
1410 break;
1411 case GL_MAX_TEXTURE_SIZE:
1412 *params = mCaps.max2DTextureSize;
1413 break;
1414 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1415 *params = mCaps.maxCubeMapTextureSize;
1416 break;
1417 case GL_MAX_3D_TEXTURE_SIZE:
1418 *params = mCaps.max3DTextureSize;
1419 break;
1420 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1421 *params = mCaps.maxArrayTextureLayers;
1422 break;
1423 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1424 *params = mCaps.uniformBufferOffsetAlignment;
1425 break;
1426 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1427 *params = mCaps.maxUniformBufferBindings;
1428 break;
1429 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
1430 *params = mCaps.maxVertexUniformBlocks;
1431 break;
1432 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
1433 *params = mCaps.maxFragmentUniformBlocks;
1434 break;
1435 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1436 *params = mCaps.maxCombinedTextureImageUnits;
1437 break;
1438 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1439 *params = mCaps.maxVertexOutputComponents;
1440 break;
1441 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1442 *params = mCaps.maxFragmentInputComponents;
1443 break;
1444 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1445 *params = mCaps.minProgramTexelOffset;
1446 break;
1447 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1448 *params = mCaps.maxProgramTexelOffset;
1449 break;
1450 case GL_MAJOR_VERSION:
1451 *params = getClientVersion().major;
1452 break;
1453 case GL_MINOR_VERSION:
1454 *params = getClientVersion().minor;
1455 break;
1456 case GL_MAX_ELEMENTS_INDICES:
1457 *params = mCaps.maxElementsIndices;
1458 break;
1459 case GL_MAX_ELEMENTS_VERTICES:
1460 *params = mCaps.maxElementsVertices;
1461 break;
1462 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1463 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1464 break;
1465 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1466 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1467 break;
1468 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1469 *params = mCaps.maxTransformFeedbackSeparateComponents;
1470 break;
1471 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1472 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1473 break;
1474 case GL_MAX_SAMPLES_ANGLE:
1475 *params = mCaps.maxSamples;
1476 break;
1477 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001478 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001479 params[0] = mCaps.maxViewportWidth;
1480 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001481 }
1482 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001483 case GL_COMPRESSED_TEXTURE_FORMATS:
1484 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1485 params);
1486 break;
1487 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1488 *params = mResetStrategy;
1489 break;
1490 case GL_NUM_SHADER_BINARY_FORMATS:
1491 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1492 break;
1493 case GL_SHADER_BINARY_FORMATS:
1494 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1495 break;
1496 case GL_NUM_PROGRAM_BINARY_FORMATS:
1497 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1498 break;
1499 case GL_PROGRAM_BINARY_FORMATS:
1500 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1501 break;
1502 case GL_NUM_EXTENSIONS:
1503 *params = static_cast<GLint>(mExtensionStrings.size());
1504 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001505
Jamie Madill231c7f52017-04-26 13:45:37 -04001506 // GL_KHR_debug
1507 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1508 *params = mExtensions.maxDebugMessageLength;
1509 break;
1510 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1511 *params = mExtensions.maxDebugLoggedMessages;
1512 break;
1513 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1514 *params = mExtensions.maxDebugGroupStackDepth;
1515 break;
1516 case GL_MAX_LABEL_LENGTH:
1517 *params = mExtensions.maxLabelLength;
1518 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001519
Jamie Madill231c7f52017-04-26 13:45:37 -04001520 // GL_EXT_disjoint_timer_query
1521 case GL_GPU_DISJOINT_EXT:
1522 *params = mImplementation->getGPUDisjoint();
1523 break;
1524 case GL_MAX_FRAMEBUFFER_WIDTH:
1525 *params = mCaps.maxFramebufferWidth;
1526 break;
1527 case GL_MAX_FRAMEBUFFER_HEIGHT:
1528 *params = mCaps.maxFramebufferHeight;
1529 break;
1530 case GL_MAX_FRAMEBUFFER_SAMPLES:
1531 *params = mCaps.maxFramebufferSamples;
1532 break;
1533 case GL_MAX_SAMPLE_MASK_WORDS:
1534 *params = mCaps.maxSampleMaskWords;
1535 break;
1536 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1537 *params = mCaps.maxColorTextureSamples;
1538 break;
1539 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1540 *params = mCaps.maxDepthTextureSamples;
1541 break;
1542 case GL_MAX_INTEGER_SAMPLES:
1543 *params = mCaps.maxIntegerSamples;
1544 break;
1545 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1546 *params = mCaps.maxVertexAttribRelativeOffset;
1547 break;
1548 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1549 *params = mCaps.maxVertexAttribBindings;
1550 break;
1551 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1552 *params = mCaps.maxVertexAttribStride;
1553 break;
1554 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
1555 *params = mCaps.maxVertexAtomicCounterBuffers;
1556 break;
1557 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
1558 *params = mCaps.maxVertexAtomicCounters;
1559 break;
1560 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
1561 *params = mCaps.maxVertexImageUniforms;
1562 break;
1563 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
1564 *params = mCaps.maxVertexShaderStorageBlocks;
1565 break;
1566 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
1567 *params = mCaps.maxFragmentAtomicCounterBuffers;
1568 break;
1569 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
1570 *params = mCaps.maxFragmentAtomicCounters;
1571 break;
1572 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
1573 *params = mCaps.maxFragmentImageUniforms;
1574 break;
1575 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
1576 *params = mCaps.maxFragmentShaderStorageBlocks;
1577 break;
1578 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1579 *params = mCaps.minProgramTextureGatherOffset;
1580 break;
1581 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1582 *params = mCaps.maxProgramTextureGatherOffset;
1583 break;
1584 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1585 *params = mCaps.maxComputeWorkGroupInvocations;
1586 break;
1587 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
1588 *params = mCaps.maxComputeUniformBlocks;
1589 break;
1590 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
1591 *params = mCaps.maxComputeTextureImageUnits;
1592 break;
1593 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1594 *params = mCaps.maxComputeSharedMemorySize;
1595 break;
1596 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
1597 *params = mCaps.maxComputeUniformComponents;
1598 break;
1599 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
1600 *params = mCaps.maxComputeAtomicCounterBuffers;
1601 break;
1602 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
1603 *params = mCaps.maxComputeAtomicCounters;
1604 break;
1605 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
1606 *params = mCaps.maxComputeImageUniforms;
1607 break;
1608 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
1609 *params = mCaps.maxCombinedComputeUniformComponents;
1610 break;
1611 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
1612 *params = mCaps.maxComputeShaderStorageBlocks;
1613 break;
1614 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1615 *params = mCaps.maxCombinedShaderOutputResources;
1616 break;
1617 case GL_MAX_UNIFORM_LOCATIONS:
1618 *params = mCaps.maxUniformLocations;
1619 break;
1620 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1621 *params = mCaps.maxAtomicCounterBufferBindings;
1622 break;
1623 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1624 *params = mCaps.maxAtomicCounterBufferSize;
1625 break;
1626 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1627 *params = mCaps.maxCombinedAtomicCounterBuffers;
1628 break;
1629 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1630 *params = mCaps.maxCombinedAtomicCounters;
1631 break;
1632 case GL_MAX_IMAGE_UNITS:
1633 *params = mCaps.maxImageUnits;
1634 break;
1635 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1636 *params = mCaps.maxCombinedImageUniforms;
1637 break;
1638 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1639 *params = mCaps.maxShaderStorageBufferBindings;
1640 break;
1641 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1642 *params = mCaps.maxCombinedShaderStorageBlocks;
1643 break;
1644 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1645 *params = mCaps.shaderStorageBufferOffsetAlignment;
1646 break;
1647 default:
1648 mGLState.getIntegerv(this, pname, params);
1649 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001650 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001651}
1652
Jamie Madill893ab082014-05-16 16:56:10 -04001653void Context::getInteger64v(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001654{
Shannon Woods53a94a82014-06-24 15:20:36 -04001655 // Queries about context capabilities and maximums are answered by Context.
1656 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001657 switch (pname)
1658 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001659 case GL_MAX_ELEMENT_INDEX:
1660 *params = mCaps.maxElementIndex;
1661 break;
1662 case GL_MAX_UNIFORM_BLOCK_SIZE:
1663 *params = mCaps.maxUniformBlockSize;
1664 break;
1665 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
1666 *params = mCaps.maxCombinedVertexUniformComponents;
1667 break;
1668 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
1669 *params = mCaps.maxCombinedFragmentUniformComponents;
1670 break;
1671 case GL_MAX_SERVER_WAIT_TIMEOUT:
1672 *params = mCaps.maxServerWaitTimeout;
1673 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001674
Jamie Madill231c7f52017-04-26 13:45:37 -04001675 // GL_EXT_disjoint_timer_query
1676 case GL_TIMESTAMP_EXT:
1677 *params = mImplementation->getTimestamp();
1678 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001679
Jamie Madill231c7f52017-04-26 13:45:37 -04001680 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1681 *params = mCaps.maxShaderStorageBlockSize;
1682 break;
1683 default:
1684 UNREACHABLE();
1685 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001686 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001687}
1688
Geoff Lang70d0f492015-12-10 17:45:46 -05001689void Context::getPointerv(GLenum pname, void **params) const
1690{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001691 mGLState.getPointerv(pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001692}
1693
Martin Radev66fb8202016-07-28 11:45:20 +03001694void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001695{
Shannon Woods53a94a82014-06-24 15:20:36 -04001696 // Queries about context capabilities and maximums are answered by Context.
1697 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001698
1699 GLenum nativeType;
1700 unsigned int numParams;
1701 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1702 ASSERT(queryStatus);
1703
1704 if (nativeType == GL_INT)
1705 {
1706 switch (target)
1707 {
1708 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1709 ASSERT(index < 3u);
1710 *data = mCaps.maxComputeWorkGroupCount[index];
1711 break;
1712 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1713 ASSERT(index < 3u);
1714 *data = mCaps.maxComputeWorkGroupSize[index];
1715 break;
1716 default:
1717 mGLState.getIntegeri_v(target, index, data);
1718 }
1719 }
1720 else
1721 {
1722 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1723 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001724}
1725
Martin Radev66fb8202016-07-28 11:45:20 +03001726void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001727{
Shannon Woods53a94a82014-06-24 15:20:36 -04001728 // Queries about context capabilities and maximums are answered by Context.
1729 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001730
1731 GLenum nativeType;
1732 unsigned int numParams;
1733 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1734 ASSERT(queryStatus);
1735
1736 if (nativeType == GL_INT_64_ANGLEX)
1737 {
1738 mGLState.getInteger64i_v(target, index, data);
1739 }
1740 else
1741 {
1742 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1743 }
1744}
1745
1746void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1747{
1748 // Queries about context capabilities and maximums are answered by Context.
1749 // Queries about current GL state values are answered by State.
1750
1751 GLenum nativeType;
1752 unsigned int numParams;
1753 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1754 ASSERT(queryStatus);
1755
1756 if (nativeType == GL_BOOL)
1757 {
1758 mGLState.getBooleani_v(target, index, data);
1759 }
1760 else
1761 {
1762 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1763 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001764}
1765
He Yunchao010e4db2017-03-03 14:22:06 +08001766void Context::getBufferParameteriv(GLenum target, GLenum pname, GLint *params)
1767{
1768 Buffer *buffer = mGLState.getTargetBuffer(target);
1769 QueryBufferParameteriv(buffer, pname, params);
1770}
1771
1772void Context::getFramebufferAttachmentParameteriv(GLenum target,
1773 GLenum attachment,
1774 GLenum pname,
1775 GLint *params)
1776{
1777 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
1778 QueryFramebufferAttachmentParameteriv(framebuffer, attachment, pname, params);
1779}
1780
1781void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
1782{
1783 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
1784 QueryRenderbufferiv(this, renderbuffer, pname, params);
1785}
1786
1787void Context::getTexParameterfv(GLenum target, GLenum pname, GLfloat *params)
1788{
1789 Texture *texture = getTargetTexture(target);
1790 QueryTexParameterfv(texture, pname, params);
1791}
1792
1793void Context::getTexParameteriv(GLenum target, GLenum pname, GLint *params)
1794{
1795 Texture *texture = getTargetTexture(target);
1796 QueryTexParameteriv(texture, pname, params);
1797}
1798void Context::texParameterf(GLenum target, GLenum pname, GLfloat param)
1799{
1800 Texture *texture = getTargetTexture(target);
1801 SetTexParameterf(texture, pname, param);
1802}
1803
1804void Context::texParameterfv(GLenum target, GLenum pname, const GLfloat *params)
1805{
1806 Texture *texture = getTargetTexture(target);
1807 SetTexParameterfv(texture, pname, params);
1808}
1809
1810void Context::texParameteri(GLenum target, GLenum pname, GLint param)
1811{
1812 Texture *texture = getTargetTexture(target);
1813 SetTexParameteri(texture, pname, param);
1814}
1815
1816void Context::texParameteriv(GLenum target, GLenum pname, const GLint *params)
1817{
1818 Texture *texture = getTargetTexture(target);
1819 SetTexParameteriv(texture, pname, params);
1820}
1821
Jamie Madill675fe712016-12-19 13:07:54 -05001822void Context::drawArrays(GLenum mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001823{
Jamie Madill1b94d432015-08-07 13:23:23 -04001824 syncRendererState();
Jamie Madillc564c072017-06-01 12:45:42 -04001825 auto error = mImplementation->drawArrays(this, mode, first, count);
Jamie Madill675fe712016-12-19 13:07:54 -05001826 handleError(error);
1827 if (!error.isError())
1828 {
1829 MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback());
1830 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001831}
1832
Jamie Madill675fe712016-12-19 13:07:54 -05001833void Context::drawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04001834{
1835 syncRendererState();
Jamie Madillc564c072017-06-01 12:45:42 -04001836 auto error = mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount);
Jamie Madill675fe712016-12-19 13:07:54 -05001837 handleError(error);
1838 if (!error.isError())
1839 {
1840 MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback());
1841 }
Geoff Langf6db0982015-08-25 13:04:00 -04001842}
1843
Jamie Madill876429b2017-04-20 15:46:24 -04001844void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001845{
Jamie Madill1b94d432015-08-07 13:23:23 -04001846 syncRendererState();
Jamie Madill9c9b40a2017-04-26 16:31:57 -04001847 const IndexRange &indexRange = getParams<HasIndexRange>().getIndexRange().value();
Jamie Madillc564c072017-06-01 12:45:42 -04001848 handleError(mImplementation->drawElements(this, mode, count, type, indices, indexRange));
Geoff Langf6db0982015-08-25 13:04:00 -04001849}
1850
Jamie Madill675fe712016-12-19 13:07:54 -05001851void Context::drawElementsInstanced(GLenum mode,
1852 GLsizei count,
1853 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04001854 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04001855 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04001856{
1857 syncRendererState();
Jamie Madill9c9b40a2017-04-26 16:31:57 -04001858 const IndexRange &indexRange = getParams<HasIndexRange>().getIndexRange().value();
Jamie Madillc564c072017-06-01 12:45:42 -04001859 handleError(mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances,
1860 indexRange));
Geoff Langf6db0982015-08-25 13:04:00 -04001861}
1862
Jamie Madill675fe712016-12-19 13:07:54 -05001863void Context::drawRangeElements(GLenum mode,
1864 GLuint start,
1865 GLuint end,
1866 GLsizei count,
1867 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04001868 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04001869{
1870 syncRendererState();
Jamie Madill9c9b40a2017-04-26 16:31:57 -04001871 const IndexRange &indexRange = getParams<HasIndexRange>().getIndexRange().value();
Jamie Madillc564c072017-06-01 12:45:42 -04001872 handleError(mImplementation->drawRangeElements(this, mode, start, end, count, type, indices,
1873 indexRange));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001874}
1875
Jamie Madill876429b2017-04-20 15:46:24 -04001876void Context::drawArraysIndirect(GLenum mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08001877{
1878 syncRendererState();
Jamie Madillc564c072017-06-01 12:45:42 -04001879 handleError(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08001880}
1881
Jamie Madill876429b2017-04-20 15:46:24 -04001882void Context::drawElementsIndirect(GLenum mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08001883{
1884 syncRendererState();
Jamie Madillc564c072017-06-01 12:45:42 -04001885 handleError(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08001886}
1887
Jamie Madill675fe712016-12-19 13:07:54 -05001888void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001889{
Jamie Madill675fe712016-12-19 13:07:54 -05001890 handleError(mImplementation->flush());
Geoff Lang129753a2015-01-09 16:52:09 -05001891}
1892
Jamie Madill675fe712016-12-19 13:07:54 -05001893void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05001894{
Jamie Madill675fe712016-12-19 13:07:54 -05001895 handleError(mImplementation->finish());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001896}
1897
Austin Kinross6ee1e782015-05-29 17:05:37 -07001898void Context::insertEventMarker(GLsizei length, const char *marker)
1899{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001900 ASSERT(mImplementation);
1901 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07001902}
1903
1904void Context::pushGroupMarker(GLsizei length, const char *marker)
1905{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001906 ASSERT(mImplementation);
1907 mImplementation->pushGroupMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07001908}
1909
1910void Context::popGroupMarker()
1911{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001912 ASSERT(mImplementation);
1913 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07001914}
1915
Geoff Langd8605522016-04-13 10:19:12 -04001916void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
1917{
1918 Program *programObject = getProgram(program);
1919 ASSERT(programObject);
1920
1921 programObject->bindUniformLocation(location, name);
1922}
1923
Sami Väisänena797e062016-05-12 15:23:40 +03001924void Context::setCoverageModulation(GLenum components)
1925{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001926 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03001927}
1928
Sami Väisänene45e53b2016-05-25 10:36:04 +03001929void Context::loadPathRenderingMatrix(GLenum matrixMode, const GLfloat *matrix)
1930{
1931 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
1932}
1933
1934void Context::loadPathRenderingIdentityMatrix(GLenum matrixMode)
1935{
1936 GLfloat I[16];
1937 angle::Matrix<GLfloat>::setToIdentity(I);
1938
1939 mGLState.loadPathRenderingMatrix(matrixMode, I);
1940}
1941
1942void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
1943{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001944 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001945 if (!pathObj)
1946 return;
1947
1948 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1949 syncRendererState();
1950
1951 mImplementation->stencilFillPath(pathObj, fillMode, mask);
1952}
1953
1954void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
1955{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001956 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001957 if (!pathObj)
1958 return;
1959
1960 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1961 syncRendererState();
1962
1963 mImplementation->stencilStrokePath(pathObj, reference, mask);
1964}
1965
1966void Context::coverFillPath(GLuint path, GLenum coverMode)
1967{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001968 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001969 if (!pathObj)
1970 return;
1971
1972 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1973 syncRendererState();
1974
1975 mImplementation->coverFillPath(pathObj, coverMode);
1976}
1977
1978void Context::coverStrokePath(GLuint path, GLenum coverMode)
1979{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001980 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001981 if (!pathObj)
1982 return;
1983
1984 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1985 syncRendererState();
1986
1987 mImplementation->coverStrokePath(pathObj, coverMode);
1988}
1989
1990void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
1991{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001992 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001993 if (!pathObj)
1994 return;
1995
1996 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1997 syncRendererState();
1998
1999 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
2000}
2001
2002void Context::stencilThenCoverStrokePath(GLuint path,
2003 GLint reference,
2004 GLuint mask,
2005 GLenum coverMode)
2006{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002007 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002008 if (!pathObj)
2009 return;
2010
2011 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2012 syncRendererState();
2013
2014 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2015}
2016
Sami Väisänend59ca052016-06-21 16:10:00 +03002017void Context::coverFillPathInstanced(GLsizei numPaths,
2018 GLenum pathNameType,
2019 const void *paths,
2020 GLuint pathBase,
2021 GLenum coverMode,
2022 GLenum transformType,
2023 const GLfloat *transformValues)
2024{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002025 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002026
2027 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2028 syncRendererState();
2029
2030 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2031}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002032
Sami Väisänend59ca052016-06-21 16:10:00 +03002033void Context::coverStrokePathInstanced(GLsizei numPaths,
2034 GLenum pathNameType,
2035 const void *paths,
2036 GLuint pathBase,
2037 GLenum coverMode,
2038 GLenum transformType,
2039 const GLfloat *transformValues)
2040{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002041 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002042
2043 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2044 syncRendererState();
2045
2046 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2047 transformValues);
2048}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002049
Sami Väisänend59ca052016-06-21 16:10:00 +03002050void Context::stencilFillPathInstanced(GLsizei numPaths,
2051 GLenum pathNameType,
2052 const void *paths,
2053 GLuint pathBase,
2054 GLenum fillMode,
2055 GLuint mask,
2056 GLenum transformType,
2057 const GLfloat *transformValues)
2058{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002059 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002060
2061 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2062 syncRendererState();
2063
2064 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2065 transformValues);
2066}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002067
Sami Väisänend59ca052016-06-21 16:10:00 +03002068void Context::stencilStrokePathInstanced(GLsizei numPaths,
2069 GLenum pathNameType,
2070 const void *paths,
2071 GLuint pathBase,
2072 GLint reference,
2073 GLuint mask,
2074 GLenum transformType,
2075 const GLfloat *transformValues)
2076{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002077 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002078
2079 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2080 syncRendererState();
2081
2082 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2083 transformValues);
2084}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002085
Sami Väisänend59ca052016-06-21 16:10:00 +03002086void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2087 GLenum pathNameType,
2088 const void *paths,
2089 GLuint pathBase,
2090 GLenum fillMode,
2091 GLuint mask,
2092 GLenum coverMode,
2093 GLenum transformType,
2094 const GLfloat *transformValues)
2095{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002096 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002097
2098 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2099 syncRendererState();
2100
2101 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2102 transformType, transformValues);
2103}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002104
Sami Väisänend59ca052016-06-21 16:10:00 +03002105void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2106 GLenum pathNameType,
2107 const void *paths,
2108 GLuint pathBase,
2109 GLint reference,
2110 GLuint mask,
2111 GLenum coverMode,
2112 GLenum transformType,
2113 const GLfloat *transformValues)
2114{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002115 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002116
2117 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2118 syncRendererState();
2119
2120 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2121 transformType, transformValues);
2122}
2123
Sami Väisänen46eaa942016-06-29 10:26:37 +03002124void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2125{
2126 auto *programObject = getProgram(program);
2127
2128 programObject->bindFragmentInputLocation(location, name);
2129}
2130
2131void Context::programPathFragmentInputGen(GLuint program,
2132 GLint location,
2133 GLenum genMode,
2134 GLint components,
2135 const GLfloat *coeffs)
2136{
2137 auto *programObject = getProgram(program);
2138
Jamie Madillbd044ed2017-06-05 12:59:21 -04002139 programObject->pathFragmentInputGen(this, location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002140}
2141
jchen1015015f72017-03-16 13:54:21 +08002142GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2143{
jchen10fd7c3b52017-03-21 15:36:03 +08002144 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002145 return QueryProgramResourceIndex(programObject, programInterface, name);
2146}
2147
jchen10fd7c3b52017-03-21 15:36:03 +08002148void Context::getProgramResourceName(GLuint program,
2149 GLenum programInterface,
2150 GLuint index,
2151 GLsizei bufSize,
2152 GLsizei *length,
2153 GLchar *name)
2154{
2155 const auto *programObject = getProgram(program);
2156 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2157}
2158
Jamie Madill437fa652016-05-03 15:13:24 -04002159void Context::handleError(const Error &error)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002160{
Geoff Langda5777c2014-07-11 09:52:58 -04002161 if (error.isError())
2162 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002163 GLenum code = error.getCode();
2164 mErrors.insert(code);
2165 if (code == GL_OUT_OF_MEMORY && getWorkarounds().loseContextOnOutOfMemory)
2166 {
2167 markContextLost();
2168 }
Geoff Lang70d0f492015-12-10 17:45:46 -05002169
2170 if (!error.getMessage().empty())
2171 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002172 auto *debug = &mGLState.getDebug();
2173 debug->insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, error.getID(),
2174 GL_DEBUG_SEVERITY_HIGH, error.getMessage());
Geoff Lang70d0f492015-12-10 17:45:46 -05002175 }
Geoff Langda5777c2014-07-11 09:52:58 -04002176 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002177}
2178
2179// Get one of the recorded errors and clear its flag, if any.
2180// [OpenGL ES 2.0.24] section 2.5 page 13.
2181GLenum Context::getError()
2182{
Geoff Langda5777c2014-07-11 09:52:58 -04002183 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002184 {
Geoff Langda5777c2014-07-11 09:52:58 -04002185 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002186 }
Geoff Langda5777c2014-07-11 09:52:58 -04002187 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002188 {
Geoff Langda5777c2014-07-11 09:52:58 -04002189 GLenum error = *mErrors.begin();
2190 mErrors.erase(mErrors.begin());
2191 return error;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002192 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002193}
2194
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002195// NOTE: this function should not assume that this context is current!
2196void Context::markContextLost()
2197{
2198 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002199 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002200 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002201 mContextLostForced = true;
2202 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002203 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002204}
2205
2206bool Context::isContextLost()
2207{
2208 return mContextLost;
2209}
2210
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002211GLenum Context::getResetStatus()
2212{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002213 // Even if the application doesn't want to know about resets, we want to know
2214 // as it will allow us to skip all the calls.
2215 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002216 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002217 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002218 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002219 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002220 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002221
2222 // EXT_robustness, section 2.6: If the reset notification behavior is
2223 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2224 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2225 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002226 }
2227
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002228 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2229 // status should be returned at least once, and GL_NO_ERROR should be returned
2230 // once the device has finished resetting.
2231 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002232 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002233 ASSERT(mResetStatus == GL_NO_ERROR);
2234 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002235
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002236 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002237 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002238 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002239 }
2240 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002241 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002242 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002243 // If markContextLost was used to mark the context lost then
2244 // assume that is not recoverable, and continue to report the
2245 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002246 mResetStatus = mImplementation->getResetStatus();
2247 }
Jamie Madill893ab082014-05-16 16:56:10 -04002248
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002249 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002250}
2251
2252bool Context::isResetNotificationEnabled()
2253{
2254 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2255}
2256
Corentin Walleze3b10e82015-05-20 11:06:25 -04002257const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002258{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002259 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002260}
2261
2262EGLenum Context::getClientType() const
2263{
2264 return mClientType;
2265}
2266
2267EGLenum Context::getRenderBuffer() const
2268{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002269 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2270 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002271 {
2272 return EGL_NONE;
2273 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002274
2275 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(GL_BACK);
2276 ASSERT(backAttachment != nullptr);
2277 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002278}
2279
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002280VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002281{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002282 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002283 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2284 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002285 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002286 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2287 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002288
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002289 mVertexArrayMap[vertexArrayHandle] = vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002290 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002291
2292 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002293}
2294
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002295TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002296{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002297 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002298 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2299 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002300 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002301 transformFeedback =
2302 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002303 transformFeedback->addRef();
2304 mTransformFeedbackMap[transformFeedbackHandle] = transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002305 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002306
2307 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002308}
2309
2310bool Context::isVertexArrayGenerated(GLuint vertexArray)
2311{
Geoff Langf41a7152016-09-19 15:11:17 -04002312 ASSERT(mVertexArrayMap.find(0) != mVertexArrayMap.end());
Geoff Lang36167ab2015-12-07 10:27:14 -05002313 return mVertexArrayMap.find(vertexArray) != mVertexArrayMap.end();
2314}
2315
2316bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2317{
Geoff Langf41a7152016-09-19 15:11:17 -04002318 ASSERT(mTransformFeedbackMap.find(0) != mTransformFeedbackMap.end());
Geoff Lang36167ab2015-12-07 10:27:14 -05002319 return mTransformFeedbackMap.find(transformFeedback) != mTransformFeedbackMap.end();
2320}
2321
Shannon Woods53a94a82014-06-24 15:20:36 -04002322void Context::detachTexture(GLuint texture)
2323{
2324 // Simple pass-through to State's detachTexture method, as textures do not require
2325 // allocation map management either here or in the resource manager at detach time.
2326 // Zero textures are held by the Context, and we don't attempt to request them from
2327 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002328 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002329}
2330
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002331void Context::detachBuffer(GLuint buffer)
2332{
Yuly Novikov5807a532015-12-03 13:01:22 -05002333 // Simple pass-through to State's detachBuffer method, since
2334 // only buffer attachments to container objects that are bound to the current context
2335 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002336
Yuly Novikov5807a532015-12-03 13:01:22 -05002337 // [OpenGL ES 3.2] section 5.1.2 page 45:
2338 // Attachments to unbound container objects, such as
2339 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2340 // are not affected and continue to act as references on the deleted object
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002341 mGLState.detachBuffer(buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002342}
2343
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002344void Context::detachFramebuffer(GLuint framebuffer)
2345{
Shannon Woods53a94a82014-06-24 15:20:36 -04002346 // Framebuffer detachment is handled by Context, because 0 is a valid
2347 // Framebuffer object, and a pointer to it must be passed from Context
2348 // to State at binding time.
2349
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002350 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002351 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2352 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2353 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002354
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002355 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002356 {
2357 bindReadFramebuffer(0);
2358 }
2359
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002360 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002361 {
2362 bindDrawFramebuffer(0);
2363 }
2364}
2365
2366void Context::detachRenderbuffer(GLuint renderbuffer)
2367{
Jamie Madilla02315b2017-02-23 14:14:47 -05002368 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002369}
2370
Jamie Madill57a89722013-07-02 11:57:03 -04002371void Context::detachVertexArray(GLuint vertexArray)
2372{
Jamie Madill77a72f62015-04-14 11:18:32 -04002373 // Vertex array detachment is handled by Context, because 0 is a valid
2374 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002375 // binding time.
2376
Jamie Madill57a89722013-07-02 11:57:03 -04002377 // [OpenGL ES 3.0.2] section 2.10 page 43:
2378 // If a vertex array object that is currently bound is deleted, the binding
2379 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002380 if (mGLState.removeVertexArrayBinding(vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002381 {
2382 bindVertexArray(0);
2383 }
2384}
2385
Geoff Langc8058452014-02-03 12:04:11 -05002386void Context::detachTransformFeedback(GLuint transformFeedback)
2387{
Corentin Walleza2257da2016-04-19 16:43:12 -04002388 // Transform feedback detachment is handled by Context, because 0 is a valid
2389 // transform feedback, and a pointer to it must be passed from Context to State at
2390 // binding time.
2391
2392 // The OpenGL specification doesn't mention what should happen when the currently bound
2393 // transform feedback object is deleted. Since it is a container object, we treat it like
2394 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002395 if (mGLState.removeTransformFeedbackBinding(transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002396 {
2397 bindTransformFeedback(0);
2398 }
Geoff Langc8058452014-02-03 12:04:11 -05002399}
2400
Jamie Madilldc356042013-07-19 16:36:57 -04002401void Context::detachSampler(GLuint sampler)
2402{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002403 mGLState.detachSampler(sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002404}
2405
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002406void Context::setVertexAttribDivisor(GLuint index, GLuint divisor)
2407{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002408 mGLState.setVertexAttribDivisor(index, divisor);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002409}
2410
Jamie Madille29d1672013-07-19 16:36:57 -04002411void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2412{
Geoff Langc1984ed2016-10-07 12:41:00 -04002413 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002414 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002415 SetSamplerParameteri(samplerObject, pname, param);
2416}
Jamie Madille29d1672013-07-19 16:36:57 -04002417
Geoff Langc1984ed2016-10-07 12:41:00 -04002418void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2419{
2420 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002421 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002422 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madille29d1672013-07-19 16:36:57 -04002423}
2424
2425void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2426{
Geoff Langc1984ed2016-10-07 12:41:00 -04002427 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002428 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002429 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madille29d1672013-07-19 16:36:57 -04002430}
2431
Geoff Langc1984ed2016-10-07 12:41:00 -04002432void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002433{
Geoff Langc1984ed2016-10-07 12:41:00 -04002434 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002435 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002436 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill9675b802013-07-19 16:36:59 -04002437}
2438
Geoff Langc1984ed2016-10-07 12:41:00 -04002439void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002440{
Geoff Langc1984ed2016-10-07 12:41:00 -04002441 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002442 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002443 QuerySamplerParameteriv(samplerObject, pname, params);
2444}
Jamie Madill9675b802013-07-19 16:36:59 -04002445
Geoff Langc1984ed2016-10-07 12:41:00 -04002446void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2447{
2448 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002449 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002450 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill9675b802013-07-19 16:36:59 -04002451}
2452
Olli Etuahof0fee072016-03-30 15:11:58 +03002453void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2454{
2455 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002456 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002457}
2458
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002459void Context::initRendererString()
2460{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002461 std::ostringstream rendererString;
2462 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002463 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002464 rendererString << ")";
2465
Geoff Langcec35902014-04-16 10:52:36 -04002466 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002467}
2468
Geoff Langc339c4e2016-11-29 10:37:36 -05002469void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002470{
Geoff Langc339c4e2016-11-29 10:37:36 -05002471 const Version &clientVersion = getClientVersion();
2472
2473 std::ostringstream versionString;
2474 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2475 << ANGLE_VERSION_STRING << ")";
2476 mVersionString = MakeStaticString(versionString.str());
2477
2478 std::ostringstream shadingLanguageVersionString;
2479 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2480 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2481 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2482 << ")";
2483 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002484}
2485
Geoff Langcec35902014-04-16 10:52:36 -04002486void Context::initExtensionStrings()
2487{
Geoff Langc339c4e2016-11-29 10:37:36 -05002488 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2489 std::ostringstream combinedStringStream;
2490 std::copy(strings.begin(), strings.end(),
2491 std::ostream_iterator<const char *>(combinedStringStream, " "));
2492 return MakeStaticString(combinedStringStream.str());
2493 };
2494
2495 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002496 for (const auto &extensionString : mExtensions.getStrings())
2497 {
2498 mExtensionStrings.push_back(MakeStaticString(extensionString));
2499 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002500 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002501
Bryan Bernhart58806562017-01-05 13:09:31 -08002502 const gl::Extensions &nativeExtensions = mImplementation->getNativeExtensions();
2503
Geoff Langc339c4e2016-11-29 10:37:36 -05002504 mRequestableExtensionStrings.clear();
2505 for (const auto &extensionInfo : GetExtensionInfoMap())
2506 {
2507 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08002508 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
2509 nativeExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002510 {
2511 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
2512 }
2513 }
2514 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002515}
2516
Geoff Langc339c4e2016-11-29 10:37:36 -05002517const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04002518{
Geoff Langc339c4e2016-11-29 10:37:36 -05002519 switch (name)
2520 {
2521 case GL_VENDOR:
2522 return reinterpret_cast<const GLubyte *>("Google Inc.");
2523
2524 case GL_RENDERER:
2525 return reinterpret_cast<const GLubyte *>(mRendererString);
2526
2527 case GL_VERSION:
2528 return reinterpret_cast<const GLubyte *>(mVersionString);
2529
2530 case GL_SHADING_LANGUAGE_VERSION:
2531 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
2532
2533 case GL_EXTENSIONS:
2534 return reinterpret_cast<const GLubyte *>(mExtensionString);
2535
2536 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2537 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
2538
2539 default:
2540 UNREACHABLE();
2541 return nullptr;
2542 }
Geoff Langcec35902014-04-16 10:52:36 -04002543}
2544
Geoff Langc339c4e2016-11-29 10:37:36 -05002545const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04002546{
Geoff Langc339c4e2016-11-29 10:37:36 -05002547 switch (name)
2548 {
2549 case GL_EXTENSIONS:
2550 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
2551
2552 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2553 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
2554
2555 default:
2556 UNREACHABLE();
2557 return nullptr;
2558 }
Geoff Langcec35902014-04-16 10:52:36 -04002559}
2560
2561size_t Context::getExtensionStringCount() const
2562{
2563 return mExtensionStrings.size();
2564}
2565
Geoff Langc339c4e2016-11-29 10:37:36 -05002566void Context::requestExtension(const char *name)
2567{
2568 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2569 ASSERT(extensionInfos.find(name) != extensionInfos.end());
2570 const auto &extension = extensionInfos.at(name);
2571 ASSERT(extension.Requestable);
2572
2573 if (mExtensions.*(extension.ExtensionsMember))
2574 {
2575 // Extension already enabled
2576 return;
2577 }
2578
2579 mExtensions.*(extension.ExtensionsMember) = true;
2580 updateCaps();
2581 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08002582
Jamie Madill2f348d22017-06-05 10:50:59 -04002583 // Release the shader compiler so it will be re-created with the requested extensions enabled.
2584 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04002585
2586 // Invalidate all cached completenesses for textures and framebuffer. Some extensions make new
2587 // formats renderable or sampleable.
2588 mState.mTextures->invalidateTextureComplenessCache();
2589 for (auto &zeroTexture : mZeroTextures)
2590 {
2591 zeroTexture.second->invalidateCompletenessCache();
2592 }
2593
2594 mState.mFramebuffers->invalidateFramebufferComplenessCache();
Geoff Langc339c4e2016-11-29 10:37:36 -05002595}
2596
2597size_t Context::getRequestableExtensionStringCount() const
2598{
2599 return mRequestableExtensionStrings.size();
2600}
2601
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002602void Context::beginTransformFeedback(GLenum primitiveMode)
2603{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002604 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002605 ASSERT(transformFeedback != nullptr);
2606 ASSERT(!transformFeedback->isPaused());
2607
Jamie Madill6c1f6712017-02-14 19:08:04 -05002608 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002609}
2610
2611bool Context::hasActiveTransformFeedback(GLuint program) const
2612{
2613 for (auto pair : mTransformFeedbackMap)
2614 {
2615 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
2616 {
2617 return true;
2618 }
2619 }
2620 return false;
2621}
2622
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002623void Context::initCaps(const egl::DisplayExtensions &displayExtensions)
Geoff Lang493daf52014-07-03 13:38:44 -04002624{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002625 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04002626
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002627 mExtensions = mImplementation->getNativeExtensions();
Geoff Lang493daf52014-07-03 13:38:44 -04002628
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002629 mLimitations = mImplementation->getNativeLimitations();
Austin Kinross02df7962015-07-01 10:03:42 -07002630
Geoff Langeb66a6e2016-10-31 13:06:12 -04002631 if (getClientVersion() < Version(3, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002632 {
2633 // Disable ES3+ extensions
Jamie Madill231c7f52017-04-26 13:45:37 -04002634 mExtensions.colorBufferFloat = false;
Geoff Langb66a9092016-05-16 15:59:14 -04002635 mExtensions.eglImageExternalEssl3 = false;
Vincent Lang25ab4512016-05-13 18:13:59 +02002636 mExtensions.textureNorm16 = false;
Geoff Lang493daf52014-07-03 13:38:44 -04002637 }
2638
Geoff Langeb66a6e2016-10-31 13:06:12 -04002639 if (getClientVersion() > Version(2, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002640 {
2641 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
Jamie Madill231c7f52017-04-26 13:45:37 -04002642 // mExtensions.sRGB = false;
Geoff Lang493daf52014-07-03 13:38:44 -04002643 }
2644
Jamie Madill00ed7a12016-05-19 13:13:38 -04002645 // Some extensions are always available because they are implemented in the GL layer.
Jamie Madill231c7f52017-04-26 13:45:37 -04002646 mExtensions.bindUniformLocation = true;
2647 mExtensions.vertexArrayObject = true;
Geoff Langf41a7152016-09-19 15:11:17 -04002648 mExtensions.bindGeneratesResource = true;
Geoff Langfeb8c682017-02-13 16:07:35 -05002649 mExtensions.clientArrays = true;
Geoff Langc339c4e2016-11-29 10:37:36 -05002650 mExtensions.requestExtension = true;
Jamie Madill00ed7a12016-05-19 13:13:38 -04002651
2652 // Enable the no error extension if the context was created with the flag.
2653 mExtensions.noError = mSkipValidation;
2654
Corentin Wallezccab69d2017-01-27 16:57:15 -05002655 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Corentin Wallezc295e512017-01-27 17:47:50 -05002656 mExtensions.surfacelessContext = displayExtensions.surfacelessContext;
Corentin Wallezccab69d2017-01-27 16:57:15 -05002657
Geoff Lang70d0f492015-12-10 17:45:46 -05002658 // Explicitly enable GL_KHR_debug
2659 mExtensions.debug = true;
2660 mExtensions.maxDebugMessageLength = 1024;
2661 mExtensions.maxDebugLoggedMessages = 1024;
2662 mExtensions.maxDebugGroupStackDepth = 1024;
2663 mExtensions.maxLabelLength = 1024;
2664
Geoff Langff5b2d52016-09-07 11:32:23 -04002665 // Explicitly enable GL_ANGLE_robust_client_memory
2666 mExtensions.robustClientMemory = true;
2667
Jamie Madille08a1d32017-03-07 17:24:06 -05002668 // Determine robust resource init availability from EGL.
2669 mExtensions.robustResourceInitialization =
Jamie Madill948bbe52017-06-01 13:10:42 -04002670 egl::Display::GetClientExtensions().displayRobustResourceInitialization;
Jamie Madille08a1d32017-03-07 17:24:06 -05002671
Geoff Lang301d1612014-07-09 10:34:37 -04002672 // Apply implementation limits
2673 mCaps.maxVertexAttributes = std::min<GLuint>(mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002674 mCaps.maxVertexAttribBindings =
2675 getClientVersion() < ES_3_1
2676 ? mCaps.maxVertexAttributes
2677 : std::min<GLuint>(mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
2678
Jamie Madill231c7f52017-04-26 13:45:37 -04002679 mCaps.maxVertexUniformBlocks = std::min<GLuint>(
2680 mCaps.maxVertexUniformBlocks, IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
2681 mCaps.maxVertexOutputComponents =
2682 std::min<GLuint>(mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
Geoff Lang301d1612014-07-09 10:34:37 -04002683
Jamie Madill231c7f52017-04-26 13:45:37 -04002684 mCaps.maxFragmentInputComponents =
2685 std::min<GLuint>(mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
Geoff Lang3a61c322014-07-10 13:01:54 -04002686
Geoff Langc287ea62016-09-16 14:46:51 -04002687 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002688 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04002689 for (const auto &extensionInfo : GetExtensionInfoMap())
2690 {
2691 // If this context is for WebGL, disable all enableable extensions
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002692 if (mWebGLContext && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04002693 {
2694 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
2695 }
2696 }
2697
2698 // Generate texture caps
2699 updateCaps();
2700}
2701
2702void Context::updateCaps()
2703{
Geoff Lang900013c2014-07-07 11:32:19 -04002704 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002705 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04002706
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002707 for (auto capsIt : mImplementation->getNativeTextureCaps())
Geoff Lang493daf52014-07-03 13:38:44 -04002708 {
Geoff Langca271392017-04-05 12:30:00 -04002709 GLenum sizedInternalFormat = capsIt.first;
Jamie Madill231c7f52017-04-26 13:45:37 -04002710 TextureCaps formatCaps = capsIt.second;
Geoff Lang493daf52014-07-03 13:38:44 -04002711
Geoff Langca271392017-04-05 12:30:00 -04002712 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04002713
Geoff Lang0d8b7242015-09-09 14:56:53 -04002714 // Update the format caps based on the client version and extensions.
2715 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
2716 // ES3.
2717 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002718 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002719 formatCaps.renderable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002720 formatCaps.renderable && formatInfo.renderSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002721 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002722 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04002723
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002724 // OpenGL ES does not support multisampling with non-rendererable formats
2725 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
2726 if (!formatInfo.renderSupport ||
2727 (getClientVersion() < ES_3_1 &&
2728 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04002729 {
Geoff Langd87878e2014-09-19 15:42:59 -04002730 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04002731 }
Geoff Langd87878e2014-09-19 15:42:59 -04002732
2733 if (formatCaps.texturable && formatInfo.compressed)
2734 {
Geoff Langca271392017-04-05 12:30:00 -04002735 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04002736 }
2737
Geoff Langca271392017-04-05 12:30:00 -04002738 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04002739 }
2740}
2741
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002742void Context::initWorkarounds()
2743{
2744 // Lose the context upon out of memory error if the application is
2745 // expecting to watch for those events.
2746 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2747}
2748
Jamie Madill1b94d432015-08-07 13:23:23 -04002749void Context::syncRendererState()
2750{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002751 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
Frank Henigman5a53d542017-02-16 21:24:10 -05002752 mImplementation->syncState(dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002753 mGLState.clearDirtyBits();
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002754 mGLState.syncDirtyObjects(this);
Jamie Madill1b94d432015-08-07 13:23:23 -04002755}
2756
Jamie Madillad9f24e2016-02-12 09:27:24 -05002757void Context::syncRendererState(const State::DirtyBits &bitMask,
2758 const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04002759{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002760 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Frank Henigman5a53d542017-02-16 21:24:10 -05002761 mImplementation->syncState(dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002762 mGLState.clearDirtyBits(dirtyBits);
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002763 mGLState.syncDirtyObjects(this, objectMask);
Jamie Madill1b94d432015-08-07 13:23:23 -04002764}
Jamie Madillc29968b2016-01-20 11:17:23 -05002765
2766void Context::blitFramebuffer(GLint srcX0,
2767 GLint srcY0,
2768 GLint srcX1,
2769 GLint srcY1,
2770 GLint dstX0,
2771 GLint dstY0,
2772 GLint dstX1,
2773 GLint dstY1,
2774 GLbitfield mask,
2775 GLenum filter)
2776{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002777 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002778 ASSERT(drawFramebuffer);
2779
2780 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
2781 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
2782
Jamie Madillad9f24e2016-02-12 09:27:24 -05002783 syncStateForBlit();
Jamie Madillc29968b2016-01-20 11:17:23 -05002784
Jamie Madillc564c072017-06-01 12:45:42 -04002785 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002786}
Jamie Madillc29968b2016-01-20 11:17:23 -05002787
2788void Context::clear(GLbitfield mask)
2789{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002790 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002791 handleError(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05002792}
2793
2794void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
2795{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002796 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002797 handleError(mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002798}
2799
2800void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
2801{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002802 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002803 handleError(mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002804}
2805
2806void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
2807{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002808 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002809 handleError(mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002810}
2811
2812void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
2813{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002814 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002815 ASSERT(framebufferObject);
2816
2817 // If a buffer is not present, the clear has no effect
2818 if (framebufferObject->getDepthbuffer() == nullptr &&
2819 framebufferObject->getStencilbuffer() == nullptr)
2820 {
2821 return;
2822 }
2823
Jamie Madillad9f24e2016-02-12 09:27:24 -05002824 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002825 handleError(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05002826}
2827
2828void Context::readPixels(GLint x,
2829 GLint y,
2830 GLsizei width,
2831 GLsizei height,
2832 GLenum format,
2833 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002834 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05002835{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04002836 if (width == 0 || height == 0)
2837 {
2838 return;
2839 }
2840
Jamie Madillad9f24e2016-02-12 09:27:24 -05002841 syncStateForReadPixels();
Jamie Madillc29968b2016-01-20 11:17:23 -05002842
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002843 Framebuffer *framebufferObject = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002844 ASSERT(framebufferObject);
2845
2846 Rectangle area(x, y, width, height);
Jamie Madillc564c072017-06-01 12:45:42 -04002847 handleError(framebufferObject->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05002848}
2849
2850void Context::copyTexImage2D(GLenum target,
2851 GLint level,
2852 GLenum internalformat,
2853 GLint x,
2854 GLint y,
2855 GLsizei width,
2856 GLsizei height,
2857 GLint border)
2858{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002859 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002860 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002861
Jamie Madillc29968b2016-01-20 11:17:23 -05002862 Rectangle sourceArea(x, y, width, height);
2863
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002864 const Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002865 Texture *texture =
2866 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05002867 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05002868}
2869
2870void Context::copyTexSubImage2D(GLenum target,
2871 GLint level,
2872 GLint xoffset,
2873 GLint yoffset,
2874 GLint x,
2875 GLint y,
2876 GLsizei width,
2877 GLsizei height)
2878{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04002879 if (width == 0 || height == 0)
2880 {
2881 return;
2882 }
2883
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002884 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002885 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002886
Jamie Madillc29968b2016-01-20 11:17:23 -05002887 Offset destOffset(xoffset, yoffset, 0);
2888 Rectangle sourceArea(x, y, width, height);
2889
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002890 const Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002891 Texture *texture =
2892 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05002893 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05002894}
2895
2896void Context::copyTexSubImage3D(GLenum target,
2897 GLint level,
2898 GLint xoffset,
2899 GLint yoffset,
2900 GLint zoffset,
2901 GLint x,
2902 GLint y,
2903 GLsizei width,
2904 GLsizei height)
2905{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04002906 if (width == 0 || height == 0)
2907 {
2908 return;
2909 }
2910
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002911 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002912 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002913
Jamie Madillc29968b2016-01-20 11:17:23 -05002914 Offset destOffset(xoffset, yoffset, zoffset);
2915 Rectangle sourceArea(x, y, width, height);
2916
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002917 const Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002918 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05002919 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05002920}
2921
2922void Context::framebufferTexture2D(GLenum target,
2923 GLenum attachment,
2924 GLenum textarget,
2925 GLuint texture,
2926 GLint level)
2927{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002928 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05002929 ASSERT(framebuffer);
2930
2931 if (texture != 0)
2932 {
2933 Texture *textureObj = getTexture(texture);
2934
2935 ImageIndex index = ImageIndex::MakeInvalid();
2936
2937 if (textarget == GL_TEXTURE_2D)
2938 {
2939 index = ImageIndex::Make2D(level);
2940 }
JiangYizhoubddc46b2016-12-09 09:50:51 +08002941 else if (textarget == GL_TEXTURE_2D_MULTISAMPLE)
2942 {
2943 ASSERT(level == 0);
2944 index = ImageIndex::Make2DMultisample();
2945 }
Jamie Madillc29968b2016-01-20 11:17:23 -05002946 else
2947 {
2948 ASSERT(IsCubeMapTextureTarget(textarget));
2949 index = ImageIndex::MakeCube(textarget, level);
2950 }
2951
Jamie Madilla02315b2017-02-23 14:14:47 -05002952 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05002953 }
2954 else
2955 {
Jamie Madilla02315b2017-02-23 14:14:47 -05002956 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05002957 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002958
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002959 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05002960}
2961
2962void Context::framebufferRenderbuffer(GLenum target,
2963 GLenum attachment,
2964 GLenum renderbuffertarget,
2965 GLuint renderbuffer)
2966{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002967 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05002968 ASSERT(framebuffer);
2969
2970 if (renderbuffer != 0)
2971 {
2972 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05002973
2974 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex::MakeInvalid(),
Jamie Madillc29968b2016-01-20 11:17:23 -05002975 renderbufferObject);
2976 }
2977 else
2978 {
Jamie Madilla02315b2017-02-23 14:14:47 -05002979 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05002980 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002981
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002982 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05002983}
2984
2985void Context::framebufferTextureLayer(GLenum target,
2986 GLenum attachment,
2987 GLuint texture,
2988 GLint level,
2989 GLint layer)
2990{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002991 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05002992 ASSERT(framebuffer);
2993
2994 if (texture != 0)
2995 {
2996 Texture *textureObject = getTexture(texture);
2997
2998 ImageIndex index = ImageIndex::MakeInvalid();
2999
3000 if (textureObject->getTarget() == GL_TEXTURE_3D)
3001 {
3002 index = ImageIndex::Make3D(level, layer);
3003 }
3004 else
3005 {
3006 ASSERT(textureObject->getTarget() == GL_TEXTURE_2D_ARRAY);
3007 index = ImageIndex::Make2DArray(level, layer);
3008 }
3009
Jamie Madilla02315b2017-02-23 14:14:47 -05003010 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003011 }
3012 else
3013 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003014 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003015 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003016
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003017 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003018}
3019
3020void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3021{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003022 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003023 ASSERT(framebuffer);
3024 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003025 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003026}
3027
3028void Context::readBuffer(GLenum mode)
3029{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003030 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003031 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003032 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003033}
3034
3035void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3036{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003037 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003038 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003039
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003040 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003041 ASSERT(framebuffer);
3042
3043 // The specification isn't clear what should be done when the framebuffer isn't complete.
3044 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill437fa652016-05-03 15:13:24 -04003045 handleError(framebuffer->discard(numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003046}
3047
3048void Context::invalidateFramebuffer(GLenum target,
3049 GLsizei numAttachments,
3050 const GLenum *attachments)
3051{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003052 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003053 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003054
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003055 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003056 ASSERT(framebuffer);
3057
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003058 if (framebuffer->checkStatus(this) != GL_FRAMEBUFFER_COMPLETE)
Jamie Madillc29968b2016-01-20 11:17:23 -05003059 {
Jamie Madill437fa652016-05-03 15:13:24 -04003060 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003061 }
Jamie Madill437fa652016-05-03 15:13:24 -04003062
3063 handleError(framebuffer->invalidate(numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003064}
3065
3066void Context::invalidateSubFramebuffer(GLenum target,
3067 GLsizei numAttachments,
3068 const GLenum *attachments,
3069 GLint x,
3070 GLint y,
3071 GLsizei width,
3072 GLsizei height)
3073{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003074 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003075 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003076
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003077 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003078 ASSERT(framebuffer);
3079
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003080 if (framebuffer->checkStatus(this) != GL_FRAMEBUFFER_COMPLETE)
Jamie Madillc29968b2016-01-20 11:17:23 -05003081 {
Jamie Madill437fa652016-05-03 15:13:24 -04003082 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003083 }
Jamie Madill437fa652016-05-03 15:13:24 -04003084
3085 Rectangle area(x, y, width, height);
3086 handleError(framebuffer->invalidateSub(numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003087}
3088
Jamie Madill73a84962016-02-12 09:27:23 -05003089void Context::texImage2D(GLenum target,
3090 GLint level,
3091 GLint internalformat,
3092 GLsizei width,
3093 GLsizei height,
3094 GLint border,
3095 GLenum format,
3096 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003097 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003098{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003099 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003100
3101 Extents size(width, height, 1);
3102 Texture *texture =
3103 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003104 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3105 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003106}
3107
3108void Context::texImage3D(GLenum target,
3109 GLint level,
3110 GLint internalformat,
3111 GLsizei width,
3112 GLsizei height,
3113 GLsizei depth,
3114 GLint border,
3115 GLenum format,
3116 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003117 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003118{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003119 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003120
3121 Extents size(width, height, depth);
3122 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003123 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3124 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003125}
3126
3127void Context::texSubImage2D(GLenum target,
3128 GLint level,
3129 GLint xoffset,
3130 GLint yoffset,
3131 GLsizei width,
3132 GLsizei height,
3133 GLenum format,
3134 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003135 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003136{
3137 // Zero sized uploads are valid but no-ops
3138 if (width == 0 || height == 0)
3139 {
3140 return;
3141 }
3142
Jamie Madillad9f24e2016-02-12 09:27:24 -05003143 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003144
3145 Box area(xoffset, yoffset, 0, width, height, 1);
3146 Texture *texture =
3147 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003148 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3149 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003150}
3151
3152void Context::texSubImage3D(GLenum target,
3153 GLint level,
3154 GLint xoffset,
3155 GLint yoffset,
3156 GLint zoffset,
3157 GLsizei width,
3158 GLsizei height,
3159 GLsizei depth,
3160 GLenum format,
3161 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003162 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003163{
3164 // Zero sized uploads are valid but no-ops
3165 if (width == 0 || height == 0 || depth == 0)
3166 {
3167 return;
3168 }
3169
Jamie Madillad9f24e2016-02-12 09:27:24 -05003170 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003171
3172 Box area(xoffset, yoffset, zoffset, width, height, depth);
3173 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003174 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3175 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003176}
3177
3178void Context::compressedTexImage2D(GLenum target,
3179 GLint level,
3180 GLenum internalformat,
3181 GLsizei width,
3182 GLsizei height,
3183 GLint border,
3184 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003185 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003186{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003187 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003188
3189 Extents size(width, height, 1);
3190 Texture *texture =
3191 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003192 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003193 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003194 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003195}
3196
3197void Context::compressedTexImage3D(GLenum target,
3198 GLint level,
3199 GLenum internalformat,
3200 GLsizei width,
3201 GLsizei height,
3202 GLsizei depth,
3203 GLint border,
3204 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003205 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003206{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003207 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003208
3209 Extents size(width, height, depth);
3210 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003211 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003212 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003213 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003214}
3215
3216void Context::compressedTexSubImage2D(GLenum target,
3217 GLint level,
3218 GLint xoffset,
3219 GLint yoffset,
3220 GLsizei width,
3221 GLsizei height,
3222 GLenum format,
3223 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003224 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003225{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003226 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003227
3228 Box area(xoffset, yoffset, 0, width, height, 1);
3229 Texture *texture =
3230 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003231 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003232 format, imageSize,
3233 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003234}
3235
3236void Context::compressedTexSubImage3D(GLenum target,
3237 GLint level,
3238 GLint xoffset,
3239 GLint yoffset,
3240 GLint zoffset,
3241 GLsizei width,
3242 GLsizei height,
3243 GLsizei depth,
3244 GLenum format,
3245 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003246 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003247{
3248 // Zero sized uploads are valid but no-ops
3249 if (width == 0 || height == 0)
3250 {
3251 return;
3252 }
3253
Jamie Madillad9f24e2016-02-12 09:27:24 -05003254 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003255
3256 Box area(xoffset, yoffset, zoffset, width, height, depth);
3257 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003258 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003259 format, imageSize,
3260 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003261}
3262
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003263void Context::generateMipmap(GLenum target)
3264{
3265 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003266 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003267}
3268
Geoff Lang97073d12016-04-20 10:42:34 -07003269void Context::copyTextureCHROMIUM(GLuint sourceId,
Geoff Langfc72a072017-03-24 14:52:39 -04003270 GLint sourceLevel,
3271 GLenum destTarget,
Geoff Lang97073d12016-04-20 10:42:34 -07003272 GLuint destId,
Geoff Langfc72a072017-03-24 14:52:39 -04003273 GLint destLevel,
Geoff Lang97073d12016-04-20 10:42:34 -07003274 GLint internalFormat,
3275 GLenum destType,
3276 GLboolean unpackFlipY,
3277 GLboolean unpackPremultiplyAlpha,
3278 GLboolean unpackUnmultiplyAlpha)
3279{
3280 syncStateForTexImage();
3281
3282 gl::Texture *sourceTexture = getTexture(sourceId);
3283 gl::Texture *destTexture = getTexture(destId);
Geoff Langfc72a072017-03-24 14:52:39 -04003284 handleError(destTexture->copyTexture(
3285 this, destTarget, destLevel, internalFormat, destType, sourceLevel, unpackFlipY == GL_TRUE,
3286 unpackPremultiplyAlpha == GL_TRUE, unpackUnmultiplyAlpha == GL_TRUE, sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003287}
3288
3289void Context::copySubTextureCHROMIUM(GLuint sourceId,
Geoff Langfc72a072017-03-24 14:52:39 -04003290 GLint sourceLevel,
3291 GLenum destTarget,
Geoff Lang97073d12016-04-20 10:42:34 -07003292 GLuint destId,
Geoff Langfc72a072017-03-24 14:52:39 -04003293 GLint destLevel,
Geoff Lang97073d12016-04-20 10:42:34 -07003294 GLint xoffset,
3295 GLint yoffset,
3296 GLint x,
3297 GLint y,
3298 GLsizei width,
3299 GLsizei height,
3300 GLboolean unpackFlipY,
3301 GLboolean unpackPremultiplyAlpha,
3302 GLboolean unpackUnmultiplyAlpha)
3303{
3304 // Zero sized copies are valid but no-ops
3305 if (width == 0 || height == 0)
3306 {
3307 return;
3308 }
3309
3310 syncStateForTexImage();
3311
3312 gl::Texture *sourceTexture = getTexture(sourceId);
3313 gl::Texture *destTexture = getTexture(destId);
3314 Offset offset(xoffset, yoffset, 0);
3315 Rectangle area(x, y, width, height);
Geoff Langfc72a072017-03-24 14:52:39 -04003316 handleError(destTexture->copySubTexture(
3317 this, destTarget, destLevel, offset, sourceLevel, area, unpackFlipY == GL_TRUE,
3318 unpackPremultiplyAlpha == GL_TRUE, unpackUnmultiplyAlpha == GL_TRUE, sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003319}
3320
Geoff Lang47110bf2016-04-20 11:13:22 -07003321void Context::compressedCopyTextureCHROMIUM(GLuint sourceId, GLuint destId)
3322{
3323 syncStateForTexImage();
3324
3325 gl::Texture *sourceTexture = getTexture(sourceId);
3326 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05003327 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07003328}
3329
Geoff Lang496c02d2016-10-20 11:38:11 -07003330void Context::getBufferPointerv(GLenum target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03003331{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003332 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003333 ASSERT(buffer);
3334
Geoff Lang496c02d2016-10-20 11:38:11 -07003335 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03003336}
3337
Jamie Madill876429b2017-04-20 15:46:24 -04003338void *Context::mapBuffer(GLenum target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003339{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003340 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003341 ASSERT(buffer);
3342
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003343 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003344 if (error.isError())
3345 {
Jamie Madill437fa652016-05-03 15:13:24 -04003346 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003347 return nullptr;
3348 }
3349
3350 return buffer->getMapPointer();
3351}
3352
3353GLboolean Context::unmapBuffer(GLenum target)
3354{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003355 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003356 ASSERT(buffer);
3357
3358 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003359 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03003360 if (error.isError())
3361 {
Jamie Madill437fa652016-05-03 15:13:24 -04003362 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003363 return GL_FALSE;
3364 }
3365
3366 return result;
3367}
3368
Jamie Madill876429b2017-04-20 15:46:24 -04003369void *Context::mapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003370{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003371 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003372 ASSERT(buffer);
3373
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003374 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003375 if (error.isError())
3376 {
Jamie Madill437fa652016-05-03 15:13:24 -04003377 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003378 return nullptr;
3379 }
3380
3381 return buffer->getMapPointer();
3382}
3383
3384void Context::flushMappedBufferRange(GLenum /*target*/, GLintptr /*offset*/, GLsizeiptr /*length*/)
3385{
3386 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
3387}
3388
Jamie Madillad9f24e2016-02-12 09:27:24 -05003389void Context::syncStateForReadPixels()
3390{
3391 syncRendererState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
3392}
3393
3394void Context::syncStateForTexImage()
3395{
3396 syncRendererState(mTexImageDirtyBits, mTexImageDirtyObjects);
3397}
3398
3399void Context::syncStateForClear()
3400{
3401 syncRendererState(mClearDirtyBits, mClearDirtyObjects);
3402}
3403
3404void Context::syncStateForBlit()
3405{
3406 syncRendererState(mBlitDirtyBits, mBlitDirtyObjects);
3407}
3408
Jamie Madillc20ab272016-06-09 07:20:46 -07003409void Context::activeTexture(GLenum texture)
3410{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003411 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003412}
3413
Jamie Madill876429b2017-04-20 15:46:24 -04003414void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003415{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003416 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07003417}
3418
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003419void Context::blendEquation(GLenum mode)
3420{
3421 mGLState.setBlendEquation(mode, mode);
3422}
3423
Jamie Madillc20ab272016-06-09 07:20:46 -07003424void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
3425{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003426 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003427}
3428
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003429void Context::blendFunc(GLenum sfactor, GLenum dfactor)
3430{
3431 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
3432}
3433
Jamie Madillc20ab272016-06-09 07:20:46 -07003434void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
3435{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003436 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003437}
3438
Jamie Madill876429b2017-04-20 15:46:24 -04003439void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003440{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003441 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003442}
3443
Jamie Madill876429b2017-04-20 15:46:24 -04003444void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07003445{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003446 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07003447}
3448
3449void Context::clearStencil(GLint s)
3450{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003451 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07003452}
3453
3454void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
3455{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003456 mGLState.setColorMask(red == GL_TRUE, green == GL_TRUE, blue == GL_TRUE, alpha == GL_TRUE);
Jamie Madillc20ab272016-06-09 07:20:46 -07003457}
3458
3459void Context::cullFace(GLenum mode)
3460{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003461 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003462}
3463
3464void Context::depthFunc(GLenum func)
3465{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003466 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07003467}
3468
3469void Context::depthMask(GLboolean flag)
3470{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003471 mGLState.setDepthMask(flag != GL_FALSE);
Jamie Madillc20ab272016-06-09 07:20:46 -07003472}
3473
Jamie Madill876429b2017-04-20 15:46:24 -04003474void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07003475{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003476 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07003477}
3478
3479void Context::disable(GLenum cap)
3480{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003481 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003482}
3483
3484void Context::disableVertexAttribArray(GLuint index)
3485{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003486 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003487}
3488
3489void Context::enable(GLenum cap)
3490{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003491 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003492}
3493
3494void Context::enableVertexAttribArray(GLuint index)
3495{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003496 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003497}
3498
3499void Context::frontFace(GLenum mode)
3500{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003501 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003502}
3503
3504void Context::hint(GLenum target, GLenum mode)
3505{
3506 switch (target)
3507 {
3508 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003509 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003510 break;
3511
3512 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003513 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003514 break;
3515
3516 default:
3517 UNREACHABLE();
3518 return;
3519 }
3520}
3521
3522void Context::lineWidth(GLfloat width)
3523{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003524 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07003525}
3526
3527void Context::pixelStorei(GLenum pname, GLint param)
3528{
3529 switch (pname)
3530 {
3531 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003532 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003533 break;
3534
3535 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003536 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003537 break;
3538
3539 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003540 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003541 break;
3542
3543 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003544 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003545 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003546 break;
3547
3548 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03003549 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003550 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003551 break;
3552
3553 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03003554 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003555 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003556 break;
3557
3558 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003559 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003560 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003561 break;
3562
3563 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003564 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003565 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003566 break;
3567
3568 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003569 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003570 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003571 break;
3572
3573 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003574 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003575 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003576 break;
3577
3578 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003579 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003580 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003581 break;
3582
3583 default:
3584 UNREACHABLE();
3585 return;
3586 }
3587}
3588
3589void Context::polygonOffset(GLfloat factor, GLfloat units)
3590{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003591 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07003592}
3593
Jamie Madill876429b2017-04-20 15:46:24 -04003594void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07003595{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003596 mGLState.setSampleCoverageParams(clamp01(value), invert == GL_TRUE);
Jamie Madillc20ab272016-06-09 07:20:46 -07003597}
3598
3599void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
3600{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003601 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07003602}
3603
3604void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
3605{
3606 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3607 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003608 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003609 }
3610
3611 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3612 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003613 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003614 }
3615}
3616
3617void Context::stencilMaskSeparate(GLenum face, GLuint mask)
3618{
3619 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3620 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003621 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003622 }
3623
3624 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3625 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003626 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003627 }
3628}
3629
3630void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
3631{
3632 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3633 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003634 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003635 }
3636
3637 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3638 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003639 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003640 }
3641}
3642
3643void Context::vertexAttrib1f(GLuint index, GLfloat x)
3644{
3645 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003646 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003647}
3648
3649void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
3650{
3651 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003652 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003653}
3654
3655void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
3656{
3657 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003658 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003659}
3660
3661void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
3662{
3663 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003664 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003665}
3666
3667void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
3668{
3669 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003670 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003671}
3672
3673void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
3674{
3675 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003676 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003677}
3678
3679void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
3680{
3681 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003682 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003683}
3684
3685void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
3686{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003687 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07003688}
3689
3690void Context::vertexAttribPointer(GLuint index,
3691 GLint size,
3692 GLenum type,
3693 GLboolean normalized,
3694 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04003695 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07003696{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003697 mGLState.setVertexAttribState(index, mGLState.getTargetBuffer(GL_ARRAY_BUFFER), size, type,
3698 normalized == GL_TRUE, false, stride, ptr);
Jamie Madillc20ab272016-06-09 07:20:46 -07003699}
3700
Shao80957d92017-02-20 21:25:59 +08003701void Context::vertexAttribFormat(GLuint attribIndex,
3702 GLint size,
3703 GLenum type,
3704 GLboolean normalized,
3705 GLuint relativeOffset)
3706{
3707 mGLState.setVertexAttribFormat(attribIndex, size, type, normalized == GL_TRUE, false,
3708 relativeOffset);
3709}
3710
3711void Context::vertexAttribIFormat(GLuint attribIndex,
3712 GLint size,
3713 GLenum type,
3714 GLuint relativeOffset)
3715{
3716 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
3717}
3718
3719void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
3720{
3721 mGLState.setVertexAttribBinding(attribIndex, bindingIndex);
3722}
3723
3724void Context::setVertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
3725{
3726 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
3727}
3728
Jamie Madillc20ab272016-06-09 07:20:46 -07003729void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
3730{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003731 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07003732}
3733
3734void Context::vertexAttribIPointer(GLuint index,
3735 GLint size,
3736 GLenum type,
3737 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04003738 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07003739{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003740 mGLState.setVertexAttribState(index, mGLState.getTargetBuffer(GL_ARRAY_BUFFER), size, type,
3741 false, true, stride, pointer);
Jamie Madillc20ab272016-06-09 07:20:46 -07003742}
3743
3744void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
3745{
3746 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003747 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003748}
3749
3750void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
3751{
3752 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003753 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003754}
3755
3756void Context::vertexAttribI4iv(GLuint index, const GLint *v)
3757{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003758 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07003759}
3760
3761void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
3762{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003763 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07003764}
3765
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003766void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
3767{
3768 const VertexAttribCurrentValueData &currentValues =
3769 getGLState().getVertexAttribCurrentValue(index);
3770 const VertexArray *vao = getGLState().getVertexArray();
3771 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3772 currentValues, pname, params);
3773}
3774
3775void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
3776{
3777 const VertexAttribCurrentValueData &currentValues =
3778 getGLState().getVertexAttribCurrentValue(index);
3779 const VertexArray *vao = getGLState().getVertexArray();
3780 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3781 currentValues, pname, params);
3782}
3783
3784void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
3785{
3786 const VertexAttribCurrentValueData &currentValues =
3787 getGLState().getVertexAttribCurrentValue(index);
3788 const VertexArray *vao = getGLState().getVertexArray();
3789 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3790 currentValues, pname, params);
3791}
3792
3793void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
3794{
3795 const VertexAttribCurrentValueData &currentValues =
3796 getGLState().getVertexAttribCurrentValue(index);
3797 const VertexArray *vao = getGLState().getVertexArray();
3798 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3799 currentValues, pname, params);
3800}
3801
Jamie Madill876429b2017-04-20 15:46:24 -04003802void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003803{
3804 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
3805 QueryVertexAttribPointerv(attrib, pname, pointer);
3806}
3807
Jamie Madillc20ab272016-06-09 07:20:46 -07003808void Context::debugMessageControl(GLenum source,
3809 GLenum type,
3810 GLenum severity,
3811 GLsizei count,
3812 const GLuint *ids,
3813 GLboolean enabled)
3814{
3815 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003816 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
3817 (enabled != GL_FALSE));
Jamie Madillc20ab272016-06-09 07:20:46 -07003818}
3819
3820void Context::debugMessageInsert(GLenum source,
3821 GLenum type,
3822 GLuint id,
3823 GLenum severity,
3824 GLsizei length,
3825 const GLchar *buf)
3826{
3827 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003828 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07003829}
3830
3831void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
3832{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003833 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07003834}
3835
3836GLuint Context::getDebugMessageLog(GLuint count,
3837 GLsizei bufSize,
3838 GLenum *sources,
3839 GLenum *types,
3840 GLuint *ids,
3841 GLenum *severities,
3842 GLsizei *lengths,
3843 GLchar *messageLog)
3844{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003845 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
3846 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07003847}
3848
3849void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
3850{
3851 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003852 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07003853}
3854
3855void Context::popDebugGroup()
3856{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003857 mGLState.getDebug().popGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07003858}
3859
Jamie Madill876429b2017-04-20 15:46:24 -04003860void Context::bufferData(GLenum target, GLsizeiptr size, const void *data, GLenum usage)
Jamie Madill29639852016-09-02 15:00:09 -04003861{
3862 Buffer *buffer = mGLState.getTargetBuffer(target);
3863 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08003864 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04003865}
3866
Jamie Madill876429b2017-04-20 15:46:24 -04003867void Context::bufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04003868{
3869 if (data == nullptr)
3870 {
3871 return;
3872 }
3873
3874 Buffer *buffer = mGLState.getTargetBuffer(target);
3875 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08003876 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04003877}
3878
Jamie Madillef300b12016-10-07 15:12:09 -04003879void Context::attachShader(GLuint program, GLuint shader)
3880{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05003881 auto programObject = mState.mShaderPrograms->getProgram(program);
3882 auto shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04003883 ASSERT(programObject && shaderObject);
3884 programObject->attachShader(shaderObject);
3885}
3886
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003887const Workarounds &Context::getWorkarounds() const
3888{
3889 return mWorkarounds;
3890}
3891
Jamie Madillb0817d12016-11-01 15:48:31 -04003892void Context::copyBufferSubData(GLenum readTarget,
3893 GLenum writeTarget,
3894 GLintptr readOffset,
3895 GLintptr writeOffset,
3896 GLsizeiptr size)
3897{
3898 // if size is zero, the copy is a successful no-op
3899 if (size == 0)
3900 {
3901 return;
3902 }
3903
3904 // TODO(jmadill): cache these.
3905 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
3906 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
3907
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003908 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04003909}
3910
Jamie Madill01a80ee2016-11-07 12:06:18 -05003911void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
3912{
3913 Program *programObject = getProgram(program);
3914 // TODO(jmadill): Re-use this from the validation if possible.
3915 ASSERT(programObject);
3916 programObject->bindAttributeLocation(index, name);
3917}
3918
3919void Context::bindBuffer(GLenum target, GLuint buffer)
3920{
3921 switch (target)
3922 {
3923 case GL_ARRAY_BUFFER:
3924 bindArrayBuffer(buffer);
3925 break;
3926 case GL_ELEMENT_ARRAY_BUFFER:
3927 bindElementArrayBuffer(buffer);
3928 break;
3929 case GL_COPY_READ_BUFFER:
3930 bindCopyReadBuffer(buffer);
3931 break;
3932 case GL_COPY_WRITE_BUFFER:
3933 bindCopyWriteBuffer(buffer);
3934 break;
3935 case GL_PIXEL_PACK_BUFFER:
3936 bindPixelPackBuffer(buffer);
3937 break;
3938 case GL_PIXEL_UNPACK_BUFFER:
3939 bindPixelUnpackBuffer(buffer);
3940 break;
3941 case GL_UNIFORM_BUFFER:
3942 bindGenericUniformBuffer(buffer);
3943 break;
3944 case GL_TRANSFORM_FEEDBACK_BUFFER:
3945 bindGenericTransformFeedbackBuffer(buffer);
3946 break;
Geoff Lang3b573612016-10-31 14:08:10 -04003947 case GL_ATOMIC_COUNTER_BUFFER:
Jiajia Qin6eafb042016-12-27 17:04:07 +08003948 bindGenericAtomicCounterBuffer(buffer);
Geoff Lang3b573612016-10-31 14:08:10 -04003949 break;
3950 case GL_SHADER_STORAGE_BUFFER:
Jiajia Qinf546e7d2017-03-27 14:12:59 +08003951 bindGenericShaderStorageBuffer(buffer);
Geoff Lang3b573612016-10-31 14:08:10 -04003952 break;
3953 case GL_DRAW_INDIRECT_BUFFER:
Jiajia Qin9d7d0b12016-11-29 16:30:31 +08003954 bindDrawIndirectBuffer(buffer);
Geoff Lang3b573612016-10-31 14:08:10 -04003955 break;
3956 case GL_DISPATCH_INDIRECT_BUFFER:
Geoff Lang9f090372016-12-02 10:20:43 -05003957 if (buffer != 0)
3958 {
3959 // Binding buffers to this binding point is not implemented yet.
3960 UNIMPLEMENTED();
3961 }
Geoff Lang3b573612016-10-31 14:08:10 -04003962 break;
Jamie Madill01a80ee2016-11-07 12:06:18 -05003963
3964 default:
3965 UNREACHABLE();
3966 break;
3967 }
3968}
3969
Jiajia Qin6eafb042016-12-27 17:04:07 +08003970void Context::bindBufferBase(GLenum target, GLuint index, GLuint buffer)
3971{
3972 bindBufferRange(target, index, buffer, 0, 0);
3973}
3974
3975void Context::bindBufferRange(GLenum target,
3976 GLuint index,
3977 GLuint buffer,
3978 GLintptr offset,
3979 GLsizeiptr size)
3980{
3981 switch (target)
3982 {
3983 case GL_TRANSFORM_FEEDBACK_BUFFER:
3984 bindIndexedTransformFeedbackBuffer(buffer, index, offset, size);
3985 bindGenericTransformFeedbackBuffer(buffer);
3986 break;
3987 case GL_UNIFORM_BUFFER:
3988 bindIndexedUniformBuffer(buffer, index, offset, size);
3989 bindGenericUniformBuffer(buffer);
3990 break;
3991 case GL_ATOMIC_COUNTER_BUFFER:
3992 bindIndexedAtomicCounterBuffer(buffer, index, offset, size);
3993 bindGenericAtomicCounterBuffer(buffer);
3994 break;
3995 case GL_SHADER_STORAGE_BUFFER:
Jiajia Qinf546e7d2017-03-27 14:12:59 +08003996 bindIndexedShaderStorageBuffer(buffer, index, offset, size);
3997 bindGenericShaderStorageBuffer(buffer);
Jiajia Qin6eafb042016-12-27 17:04:07 +08003998 break;
3999 default:
4000 UNREACHABLE();
4001 break;
4002 }
4003}
4004
Jamie Madill01a80ee2016-11-07 12:06:18 -05004005void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
4006{
4007 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4008 {
4009 bindReadFramebuffer(framebuffer);
4010 }
4011
4012 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4013 {
4014 bindDrawFramebuffer(framebuffer);
4015 }
4016}
4017
4018void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4019{
4020 ASSERT(target == GL_RENDERBUFFER);
4021 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004022 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004023 mGLState.setRenderbufferBinding(object);
4024}
4025
JiangYizhoubddc46b2016-12-09 09:50:51 +08004026void Context::texStorage2DMultisample(GLenum target,
4027 GLsizei samples,
4028 GLenum internalformat,
4029 GLsizei width,
4030 GLsizei height,
4031 GLboolean fixedsamplelocations)
4032{
4033 Extents size(width, height, 1);
4034 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05004035 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
JiangYizhoubddc46b2016-12-09 09:50:51 +08004036 fixedsamplelocations));
4037}
4038
4039void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4040{
Jamie Madilldd43e6c2017-03-24 14:18:49 -04004041 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
JiangYizhoubddc46b2016-12-09 09:50:51 +08004042 const Framebuffer *framebuffer = mGLState.getReadFramebuffer();
4043
4044 switch (pname)
4045 {
4046 case GL_SAMPLE_POSITION:
4047 handleError(framebuffer->getSamplePosition(index, val));
4048 break;
4049 default:
4050 UNREACHABLE();
4051 }
4052}
4053
Jamie Madille8fb6402017-02-14 17:56:40 -05004054void Context::renderbufferStorage(GLenum target,
4055 GLenum internalformat,
4056 GLsizei width,
4057 GLsizei height)
4058{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004059 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4060 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
4061
Jamie Madille8fb6402017-02-14 17:56:40 -05004062 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004063 handleError(renderbuffer->setStorage(convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004064}
4065
4066void Context::renderbufferStorageMultisample(GLenum target,
4067 GLsizei samples,
4068 GLenum internalformat,
4069 GLsizei width,
4070 GLsizei height)
4071{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004072 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4073 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05004074
4075 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004076 handleError(
4077 renderbuffer->setStorageMultisample(samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004078}
4079
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004080void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
4081{
4082 const FenceSync *syncObject = getFenceSync(sync);
Geoff Lang82483b92017-04-11 15:33:00 -04004083 handleError(QuerySynciv(syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004084}
4085
JiangYizhoue18e6392017-02-20 10:32:23 +08004086void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
4087{
4088 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4089 QueryFramebufferParameteriv(framebuffer, pname, params);
4090}
4091
4092void Context::setFramebufferParameteri(GLenum target, GLenum pname, GLint param)
4093{
4094 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4095 SetFramebufferParameteri(framebuffer, pname, param);
4096}
4097
Jamie Madille14951e2017-03-09 18:55:16 -05004098Error Context::getScratchBuffer(size_t requestedSize, angle::MemoryBuffer **scratchBufferOut) const
4099{
4100 if (!mScratchBuffer.get(requestedSize, scratchBufferOut))
4101 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004102 return OutOfMemory() << "Failed to allocate internal buffer.";
Jamie Madille14951e2017-03-09 18:55:16 -05004103 }
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004104 return NoError();
Jamie Madille14951e2017-03-09 18:55:16 -05004105}
4106
Xinghua Cao2b396592017-03-29 15:36:04 +08004107void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
4108{
4109 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
4110 {
4111 return;
4112 }
4113
4114 mImplementation->dispatchCompute(numGroupsX, numGroupsY, numGroupsZ);
4115}
4116
JiangYizhou165361c2017-06-07 14:56:57 +08004117void Context::texStorage2D(GLenum target,
4118 GLsizei levels,
4119 GLenum internalFormat,
4120 GLsizei width,
4121 GLsizei height)
4122{
4123 Extents size(width, height, 1);
4124 Texture *texture = getTargetTexture(target);
4125 handleError(texture->setStorage(this, target, levels, internalFormat, size));
4126}
4127
4128void Context::texStorage3D(GLenum target,
4129 GLsizei levels,
4130 GLenum internalFormat,
4131 GLsizei width,
4132 GLsizei height,
4133 GLsizei depth)
4134{
4135 Extents size(width, height, depth);
4136 Texture *texture = getTargetTexture(target);
4137 handleError(texture->setStorage(this, target, levels, internalFormat, size));
4138}
4139
Jamie Madillc1d770e2017-04-13 17:31:24 -04004140GLenum Context::checkFramebufferStatus(GLenum target)
4141{
4142 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4143 ASSERT(framebuffer);
4144
4145 return framebuffer->checkStatus(this);
4146}
4147
4148void Context::compileShader(GLuint shader)
4149{
4150 Shader *shaderObject = GetValidShader(this, shader);
4151 if (!shaderObject)
4152 {
4153 return;
4154 }
4155 shaderObject->compile(this);
4156}
4157
4158void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
4159{
4160 for (int i = 0; i < n; i++)
4161 {
4162 deleteBuffer(buffers[i]);
4163 }
4164}
4165
4166void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
4167{
4168 for (int i = 0; i < n; i++)
4169 {
4170 if (framebuffers[i] != 0)
4171 {
4172 deleteFramebuffer(framebuffers[i]);
4173 }
4174 }
4175}
4176
4177void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
4178{
4179 for (int i = 0; i < n; i++)
4180 {
4181 deleteRenderbuffer(renderbuffers[i]);
4182 }
4183}
4184
4185void Context::deleteTextures(GLsizei n, const GLuint *textures)
4186{
4187 for (int i = 0; i < n; i++)
4188 {
4189 if (textures[i] != 0)
4190 {
4191 deleteTexture(textures[i]);
4192 }
4193 }
4194}
4195
4196void Context::detachShader(GLuint program, GLuint shader)
4197{
4198 Program *programObject = getProgram(program);
4199 ASSERT(programObject);
4200
4201 Shader *shaderObject = getShader(shader);
4202 ASSERT(shaderObject);
4203
4204 programObject->detachShader(this, shaderObject);
4205}
4206
4207void Context::genBuffers(GLsizei n, GLuint *buffers)
4208{
4209 for (int i = 0; i < n; i++)
4210 {
4211 buffers[i] = createBuffer();
4212 }
4213}
4214
4215void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
4216{
4217 for (int i = 0; i < n; i++)
4218 {
4219 framebuffers[i] = createFramebuffer();
4220 }
4221}
4222
4223void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
4224{
4225 for (int i = 0; i < n; i++)
4226 {
4227 renderbuffers[i] = createRenderbuffer();
4228 }
4229}
4230
4231void Context::genTextures(GLsizei n, GLuint *textures)
4232{
4233 for (int i = 0; i < n; i++)
4234 {
4235 textures[i] = createTexture();
4236 }
4237}
4238
4239void Context::getActiveAttrib(GLuint program,
4240 GLuint index,
4241 GLsizei bufsize,
4242 GLsizei *length,
4243 GLint *size,
4244 GLenum *type,
4245 GLchar *name)
4246{
4247 Program *programObject = getProgram(program);
4248 ASSERT(programObject);
4249 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
4250}
4251
4252void Context::getActiveUniform(GLuint program,
4253 GLuint index,
4254 GLsizei bufsize,
4255 GLsizei *length,
4256 GLint *size,
4257 GLenum *type,
4258 GLchar *name)
4259{
4260 Program *programObject = getProgram(program);
4261 ASSERT(programObject);
4262 programObject->getActiveUniform(index, bufsize, length, size, type, name);
4263}
4264
4265void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
4266{
4267 Program *programObject = getProgram(program);
4268 ASSERT(programObject);
4269 programObject->getAttachedShaders(maxcount, count, shaders);
4270}
4271
4272GLint Context::getAttribLocation(GLuint program, const GLchar *name)
4273{
4274 Program *programObject = getProgram(program);
4275 ASSERT(programObject);
4276 return programObject->getAttributeLocation(name);
4277}
4278
4279void Context::getBooleanv(GLenum pname, GLboolean *params)
4280{
4281 GLenum nativeType;
4282 unsigned int numParams = 0;
4283 getQueryParameterInfo(pname, &nativeType, &numParams);
4284
4285 if (nativeType == GL_BOOL)
4286 {
4287 getBooleanvImpl(pname, params);
4288 }
4289 else
4290 {
4291 CastStateValues(this, nativeType, pname, numParams, params);
4292 }
4293}
4294
4295void Context::getFloatv(GLenum pname, GLfloat *params)
4296{
4297 GLenum nativeType;
4298 unsigned int numParams = 0;
4299 getQueryParameterInfo(pname, &nativeType, &numParams);
4300
4301 if (nativeType == GL_FLOAT)
4302 {
4303 getFloatvImpl(pname, params);
4304 }
4305 else
4306 {
4307 CastStateValues(this, nativeType, pname, numParams, params);
4308 }
4309}
4310
4311void Context::getIntegerv(GLenum pname, GLint *params)
4312{
4313 GLenum nativeType;
4314 unsigned int numParams = 0;
4315 getQueryParameterInfo(pname, &nativeType, &numParams);
4316
4317 if (nativeType == GL_INT)
4318 {
4319 getIntegervImpl(pname, params);
4320 }
4321 else
4322 {
4323 CastStateValues(this, nativeType, pname, numParams, params);
4324 }
4325}
4326
4327void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
4328{
4329 Program *programObject = getProgram(program);
4330 ASSERT(programObject);
4331 QueryProgramiv(programObject, pname, params);
4332}
4333
Jamie Madillbe849e42017-05-02 15:49:00 -04004334void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04004335{
4336 Program *programObject = getProgram(program);
4337 ASSERT(programObject);
4338 programObject->getInfoLog(bufsize, length, infolog);
4339}
4340
4341void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
4342{
4343 Shader *shaderObject = getShader(shader);
4344 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004345 QueryShaderiv(this, shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004346}
4347
4348void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
4349{
4350 Shader *shaderObject = getShader(shader);
4351 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004352 shaderObject->getInfoLog(this, bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004353}
4354
4355void Context::getShaderPrecisionFormat(GLenum shadertype,
4356 GLenum precisiontype,
4357 GLint *range,
4358 GLint *precision)
4359{
4360 // TODO(jmadill): Compute shaders.
4361
4362 switch (shadertype)
4363 {
4364 case GL_VERTEX_SHADER:
4365 switch (precisiontype)
4366 {
4367 case GL_LOW_FLOAT:
4368 mCaps.vertexLowpFloat.get(range, precision);
4369 break;
4370 case GL_MEDIUM_FLOAT:
4371 mCaps.vertexMediumpFloat.get(range, precision);
4372 break;
4373 case GL_HIGH_FLOAT:
4374 mCaps.vertexHighpFloat.get(range, precision);
4375 break;
4376
4377 case GL_LOW_INT:
4378 mCaps.vertexLowpInt.get(range, precision);
4379 break;
4380 case GL_MEDIUM_INT:
4381 mCaps.vertexMediumpInt.get(range, precision);
4382 break;
4383 case GL_HIGH_INT:
4384 mCaps.vertexHighpInt.get(range, precision);
4385 break;
4386
4387 default:
4388 UNREACHABLE();
4389 return;
4390 }
4391 break;
4392
4393 case GL_FRAGMENT_SHADER:
4394 switch (precisiontype)
4395 {
4396 case GL_LOW_FLOAT:
4397 mCaps.fragmentLowpFloat.get(range, precision);
4398 break;
4399 case GL_MEDIUM_FLOAT:
4400 mCaps.fragmentMediumpFloat.get(range, precision);
4401 break;
4402 case GL_HIGH_FLOAT:
4403 mCaps.fragmentHighpFloat.get(range, precision);
4404 break;
4405
4406 case GL_LOW_INT:
4407 mCaps.fragmentLowpInt.get(range, precision);
4408 break;
4409 case GL_MEDIUM_INT:
4410 mCaps.fragmentMediumpInt.get(range, precision);
4411 break;
4412 case GL_HIGH_INT:
4413 mCaps.fragmentHighpInt.get(range, precision);
4414 break;
4415
4416 default:
4417 UNREACHABLE();
4418 return;
4419 }
4420 break;
4421
4422 default:
4423 UNREACHABLE();
4424 return;
4425 }
4426}
4427
4428void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
4429{
4430 Shader *shaderObject = getShader(shader);
4431 ASSERT(shaderObject);
4432 shaderObject->getSource(bufsize, length, source);
4433}
4434
4435void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
4436{
4437 Program *programObject = getProgram(program);
4438 ASSERT(programObject);
4439 programObject->getUniformfv(location, params);
4440}
4441
4442void Context::getUniformiv(GLuint program, GLint location, GLint *params)
4443{
4444 Program *programObject = getProgram(program);
4445 ASSERT(programObject);
4446 programObject->getUniformiv(location, params);
4447}
4448
4449GLint Context::getUniformLocation(GLuint program, const GLchar *name)
4450{
4451 Program *programObject = getProgram(program);
4452 ASSERT(programObject);
4453 return programObject->getUniformLocation(name);
4454}
4455
4456GLboolean Context::isBuffer(GLuint buffer)
4457{
4458 if (buffer == 0)
4459 {
4460 return GL_FALSE;
4461 }
4462
4463 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
4464}
4465
4466GLboolean Context::isEnabled(GLenum cap)
4467{
4468 return mGLState.getEnableFeature(cap);
4469}
4470
4471GLboolean Context::isFramebuffer(GLuint framebuffer)
4472{
4473 if (framebuffer == 0)
4474 {
4475 return GL_FALSE;
4476 }
4477
4478 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
4479}
4480
4481GLboolean Context::isProgram(GLuint program)
4482{
4483 if (program == 0)
4484 {
4485 return GL_FALSE;
4486 }
4487
4488 return (getProgram(program) ? GL_TRUE : GL_FALSE);
4489}
4490
4491GLboolean Context::isRenderbuffer(GLuint renderbuffer)
4492{
4493 if (renderbuffer == 0)
4494 {
4495 return GL_FALSE;
4496 }
4497
4498 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
4499}
4500
4501GLboolean Context::isShader(GLuint shader)
4502{
4503 if (shader == 0)
4504 {
4505 return GL_FALSE;
4506 }
4507
4508 return (getShader(shader) ? GL_TRUE : GL_FALSE);
4509}
4510
4511GLboolean Context::isTexture(GLuint texture)
4512{
4513 if (texture == 0)
4514 {
4515 return GL_FALSE;
4516 }
4517
4518 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
4519}
4520
4521void Context::linkProgram(GLuint program)
4522{
4523 Program *programObject = getProgram(program);
4524 ASSERT(programObject);
4525 handleError(programObject->link(this));
4526}
4527
4528void Context::releaseShaderCompiler()
4529{
Jamie Madill2f348d22017-06-05 10:50:59 -04004530 mCompiler.set(nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004531}
4532
4533void Context::shaderBinary(GLsizei n,
4534 const GLuint *shaders,
4535 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04004536 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04004537 GLsizei length)
4538{
4539 // No binary shader formats are supported.
4540 UNIMPLEMENTED();
4541}
4542
4543void Context::shaderSource(GLuint shader,
4544 GLsizei count,
4545 const GLchar *const *string,
4546 const GLint *length)
4547{
4548 Shader *shaderObject = getShader(shader);
4549 ASSERT(shaderObject);
4550 shaderObject->setSource(count, string, length);
4551}
4552
4553void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
4554{
4555 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
4556}
4557
4558void Context::stencilMask(GLuint mask)
4559{
4560 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
4561}
4562
4563void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
4564{
4565 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
4566}
4567
4568void Context::uniform1f(GLint location, GLfloat x)
4569{
4570 Program *program = mGLState.getProgram();
4571 program->setUniform1fv(location, 1, &x);
4572}
4573
4574void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
4575{
4576 Program *program = mGLState.getProgram();
4577 program->setUniform1fv(location, count, v);
4578}
4579
4580void Context::uniform1i(GLint location, GLint x)
4581{
4582 Program *program = mGLState.getProgram();
4583 program->setUniform1iv(location, 1, &x);
4584}
4585
4586void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
4587{
4588 Program *program = mGLState.getProgram();
4589 program->setUniform1iv(location, count, v);
4590}
4591
4592void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
4593{
4594 GLfloat xy[2] = {x, y};
4595 Program *program = mGLState.getProgram();
4596 program->setUniform2fv(location, 1, xy);
4597}
4598
4599void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
4600{
4601 Program *program = mGLState.getProgram();
4602 program->setUniform2fv(location, count, v);
4603}
4604
4605void Context::uniform2i(GLint location, GLint x, GLint y)
4606{
4607 GLint xy[2] = {x, y};
4608 Program *program = mGLState.getProgram();
4609 program->setUniform2iv(location, 1, xy);
4610}
4611
4612void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
4613{
4614 Program *program = mGLState.getProgram();
4615 program->setUniform2iv(location, count, v);
4616}
4617
4618void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
4619{
4620 GLfloat xyz[3] = {x, y, z};
4621 Program *program = mGLState.getProgram();
4622 program->setUniform3fv(location, 1, xyz);
4623}
4624
4625void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
4626{
4627 Program *program = mGLState.getProgram();
4628 program->setUniform3fv(location, count, v);
4629}
4630
4631void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
4632{
4633 GLint xyz[3] = {x, y, z};
4634 Program *program = mGLState.getProgram();
4635 program->setUniform3iv(location, 1, xyz);
4636}
4637
4638void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
4639{
4640 Program *program = mGLState.getProgram();
4641 program->setUniform3iv(location, count, v);
4642}
4643
4644void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4645{
4646 GLfloat xyzw[4] = {x, y, z, w};
4647 Program *program = mGLState.getProgram();
4648 program->setUniform4fv(location, 1, xyzw);
4649}
4650
4651void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
4652{
4653 Program *program = mGLState.getProgram();
4654 program->setUniform4fv(location, count, v);
4655}
4656
4657void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
4658{
4659 GLint xyzw[4] = {x, y, z, w};
4660 Program *program = mGLState.getProgram();
4661 program->setUniform4iv(location, 1, xyzw);
4662}
4663
4664void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
4665{
4666 Program *program = mGLState.getProgram();
4667 program->setUniform4iv(location, count, v);
4668}
4669
4670void Context::uniformMatrix2fv(GLint location,
4671 GLsizei count,
4672 GLboolean transpose,
4673 const GLfloat *value)
4674{
4675 Program *program = mGLState.getProgram();
4676 program->setUniformMatrix2fv(location, count, transpose, value);
4677}
4678
4679void Context::uniformMatrix3fv(GLint location,
4680 GLsizei count,
4681 GLboolean transpose,
4682 const GLfloat *value)
4683{
4684 Program *program = mGLState.getProgram();
4685 program->setUniformMatrix3fv(location, count, transpose, value);
4686}
4687
4688void Context::uniformMatrix4fv(GLint location,
4689 GLsizei count,
4690 GLboolean transpose,
4691 const GLfloat *value)
4692{
4693 Program *program = mGLState.getProgram();
4694 program->setUniformMatrix4fv(location, count, transpose, value);
4695}
4696
4697void Context::validateProgram(GLuint program)
4698{
4699 Program *programObject = getProgram(program);
4700 ASSERT(programObject);
4701 programObject->validate(mCaps);
4702}
4703
Jamie Madilld04908b2017-06-09 14:15:35 -04004704void Context::getProgramBinary(GLuint program,
4705 GLsizei bufSize,
4706 GLsizei *length,
4707 GLenum *binaryFormat,
4708 void *binary)
4709{
4710 Program *programObject = getProgram(program);
4711 ASSERT(programObject != nullptr);
4712
4713 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
4714}
4715
4716void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
4717{
4718 Program *programObject = getProgram(program);
4719 ASSERT(programObject != nullptr);
4720
4721 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
4722}
4723
Jamie Madillc29968b2016-01-20 11:17:23 -05004724} // namespace gl