blob: 3e434b4160b5fb260a4eee50daf25bbc8381ffa8 [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();
121 return gl::Error(GL_INVALID_OPERATION, "Unreachable Error");
122 }
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 Madill46e6c7a2016-01-18 14:42:30 -0500260 mCompiler(nullptr),
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 Madilldfde6ab2016-06-09 07:07:18 -0700364 mCompiler = new Compiler(mImplementation.get(), mState);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500365
366 // Initialize dirty bit masks
367 // TODO(jmadill): additional ES3 state
368 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_ALIGNMENT);
369 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_ROW_LENGTH);
370 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_IMAGE_HEIGHT);
371 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_SKIP_IMAGES);
372 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_SKIP_ROWS);
373 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_SKIP_PIXELS);
Corentin Wallezbbd663a2016-04-20 17:49:17 -0400374 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500375 // No dirty objects.
376
377 // Readpixels uses the pack state and read FBO
378 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_ALIGNMENT);
379 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_REVERSE_ROW_ORDER);
380 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_ROW_LENGTH);
381 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_SKIP_ROWS);
382 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_SKIP_PIXELS);
Corentin Wallezbbd663a2016-04-20 17:49:17 -0400383 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500384 mReadPixelsDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
385
386 mClearDirtyBits.set(State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED);
387 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
388 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR);
389 mClearDirtyBits.set(State::DIRTY_BIT_VIEWPORT);
390 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_COLOR);
391 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_DEPTH);
392 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_STENCIL);
393 mClearDirtyBits.set(State::DIRTY_BIT_COLOR_MASK);
394 mClearDirtyBits.set(State::DIRTY_BIT_DEPTH_MASK);
395 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT);
396 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_BACK);
397 mClearDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
398
399 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
400 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR);
Geoff Lang1d2c41d2016-10-19 16:14:46 -0700401 mBlitDirtyBits.set(State::DIRTY_BIT_FRAMEBUFFER_SRGB);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500402 mBlitDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
403 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
Jamie Madill437fa652016-05-03 15:13:24 -0400404
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400405 handleError(mImplementation->initialize());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000406}
407
Jamie Madill70ee0f62017-02-06 16:04:20 -0500408void Context::destroy(egl::Display *display)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000409{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500410 mGLState.reset(this);
Geoff Lang21329412014-12-02 20:50:30 +0000411
Corentin Wallez80b24112015-08-25 16:41:57 -0400412 for (auto fence : mFenceNVMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000413 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400414 SafeDelete(fence.second);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000415 }
416
Corentin Wallez80b24112015-08-25 16:41:57 -0400417 for (auto query : mQueryMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000418 {
Geoff Langf0aa8422015-09-29 15:08:34 -0400419 if (query.second != nullptr)
420 {
421 query.second->release();
422 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000423 }
424
Corentin Wallez80b24112015-08-25 16:41:57 -0400425 for (auto vertexArray : mVertexArrayMap)
Jamie Madill57a89722013-07-02 11:57:03 -0400426 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400427 SafeDelete(vertexArray.second);
Jamie Madill57a89722013-07-02 11:57:03 -0400428 }
429
Corentin Wallez80b24112015-08-25 16:41:57 -0400430 for (auto transformFeedback : mTransformFeedbackMap)
Geoff Langc8058452014-02-03 12:04:11 -0500431 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500432 if (transformFeedback.second != nullptr)
433 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500434 transformFeedback.second->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500435 }
Geoff Langc8058452014-02-03 12:04:11 -0500436 }
437
Jamie Madilldedd7b92014-11-05 16:30:36 -0500438 for (auto &zeroTexture : mZeroTextures)
Geoff Lang76b10c92014-09-05 16:28:14 -0400439 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +0800440 zeroTexture.second.set(nullptr);
Geoff Lang76b10c92014-09-05 16:28:14 -0400441 }
442 mZeroTextures.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000443
Corentin Wallezccab69d2017-01-27 16:57:15 -0500444 SafeDelete(mSurfacelessFramebuffer);
445
Jamie Madill70ee0f62017-02-06 16:04:20 -0500446 releaseSurface(display);
Corentin Wallez51706ea2015-08-07 14:39:22 -0400447
Geoff Lang492a7e42014-11-05 13:27:06 -0500448 SafeDelete(mCompiler);
Jamie Madill6c1f6712017-02-14 19:08:04 -0500449
450 mState.mBuffers->release(this);
451 mState.mShaderPrograms->release(this);
452 mState.mTextures->release(this);
453 mState.mRenderbuffers->release(this);
454 mState.mSamplers->release(this);
455 mState.mFenceSyncs->release(this);
456 mState.mPaths->release(this);
457 mState.mFramebuffers->release(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000458}
459
Jamie Madill70ee0f62017-02-06 16:04:20 -0500460Context::~Context()
461{
462}
463
464void Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000465{
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000466 if (!mHasBeenCurrent)
467 {
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000468 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500469 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400470 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000471
Corentin Wallezc295e512017-01-27 17:47:50 -0500472 int width = 0;
473 int height = 0;
474 if (surface != nullptr)
475 {
476 width = surface->getWidth();
477 height = surface->getHeight();
478 }
479
480 mGLState.setViewportParams(0, 0, width, height);
481 mGLState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000482
483 mHasBeenCurrent = true;
484 }
485
Jamie Madill1b94d432015-08-07 13:23:23 -0400486 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700487 mGLState.setAllDirtyBits();
Jamie Madill1b94d432015-08-07 13:23:23 -0400488
Jamie Madill70ee0f62017-02-06 16:04:20 -0500489 releaseSurface(display);
Corentin Wallezccab69d2017-01-27 16:57:15 -0500490
491 Framebuffer *newDefault = nullptr;
492 if (surface != nullptr)
493 {
Jamie Madill70ee0f62017-02-06 16:04:20 -0500494 surface->setIsCurrent(display, true);
Corentin Wallezccab69d2017-01-27 16:57:15 -0500495 mCurrentSurface = surface;
496 newDefault = surface->getDefaultFramebuffer();
497 }
498 else
499 {
500 if (mSurfacelessFramebuffer == nullptr)
501 {
502 mSurfacelessFramebuffer = new Framebuffer(mImplementation.get());
503 }
504
505 newDefault = mSurfacelessFramebuffer;
506 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000507
Corentin Wallez37c39792015-08-20 14:19:46 -0400508 // Update default framebuffer, the binding of the previous default
509 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400510 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700511 if (mGLState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400512 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700513 mGLState.setReadFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400514 }
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700515 if (mGLState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400516 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700517 mGLState.setDrawFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400518 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500519 mState.mFramebuffers->setDefaultFramebuffer(newDefault);
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400520 }
Ian Ewell292f0052016-02-04 10:37:32 -0500521
522 // Notify the renderer of a context switch
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700523 mImplementation->onMakeCurrent(mState);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000524}
525
Jamie Madill70ee0f62017-02-06 16:04:20 -0500526void Context::releaseSurface(egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400527{
Corentin Wallez37c39792015-08-20 14:19:46 -0400528 // Remove the default framebuffer
Corentin Wallezc295e512017-01-27 17:47:50 -0500529 Framebuffer *currentDefault = nullptr;
530 if (mCurrentSurface != nullptr)
Corentin Wallez51706ea2015-08-07 14:39:22 -0400531 {
Corentin Wallezc295e512017-01-27 17:47:50 -0500532 currentDefault = mCurrentSurface->getDefaultFramebuffer();
533 }
534 else if (mSurfacelessFramebuffer != nullptr)
535 {
536 currentDefault = mSurfacelessFramebuffer;
Corentin Wallez51706ea2015-08-07 14:39:22 -0400537 }
538
Corentin Wallezc295e512017-01-27 17:47:50 -0500539 if (mGLState.getReadFramebuffer() == currentDefault)
540 {
541 mGLState.setReadFramebufferBinding(nullptr);
542 }
543 if (mGLState.getDrawFramebuffer() == currentDefault)
544 {
545 mGLState.setDrawFramebufferBinding(nullptr);
546 }
547 mState.mFramebuffers->setDefaultFramebuffer(nullptr);
548
549 if (mCurrentSurface)
550 {
Jamie Madill70ee0f62017-02-06 16:04:20 -0500551 mCurrentSurface->setIsCurrent(display, false);
Corentin Wallezc295e512017-01-27 17:47:50 -0500552 mCurrentSurface = nullptr;
553 }
Jamie Madill77a72f62015-04-14 11:18:32 -0400554}
555
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000556GLuint Context::createBuffer()
557{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500558 return mState.mBuffers->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000559}
560
561GLuint Context::createProgram()
562{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500563 return mState.mShaderPrograms->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000564}
565
566GLuint Context::createShader(GLenum type)
567{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500568 return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000569}
570
571GLuint Context::createTexture()
572{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500573 return mState.mTextures->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000574}
575
576GLuint Context::createRenderbuffer()
577{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500578 return mState.mRenderbuffers->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000579}
580
Geoff Lang882033e2014-09-30 11:26:07 -0400581GLsync Context::createFenceSync()
Jamie Madillcd055f82013-07-26 11:55:15 -0400582{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500583 GLuint handle = mState.mFenceSyncs->createFenceSync(mImplementation.get());
Jamie Madillcd055f82013-07-26 11:55:15 -0400584
Cooper Partind8e62a32015-01-29 15:21:25 -0800585 return reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madillcd055f82013-07-26 11:55:15 -0400586}
587
Sami Väisänene45e53b2016-05-25 10:36:04 +0300588GLuint Context::createPaths(GLsizei range)
589{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500590 auto resultOrError = mState.mPaths->createPaths(mImplementation.get(), range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300591 if (resultOrError.isError())
592 {
593 handleError(resultOrError.getError());
594 return 0;
595 }
596 return resultOrError.getResult();
597}
598
Jamie Madill57a89722013-07-02 11:57:03 -0400599GLuint Context::createVertexArray()
600{
Geoff Lang36167ab2015-12-07 10:27:14 -0500601 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
602 mVertexArrayMap[vertexArray] = nullptr;
603 return vertexArray;
Jamie Madill57a89722013-07-02 11:57:03 -0400604}
605
Jamie Madilldc356042013-07-19 16:36:57 -0400606GLuint Context::createSampler()
607{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500608 return mState.mSamplers->createSampler();
Jamie Madilldc356042013-07-19 16:36:57 -0400609}
610
Geoff Langc8058452014-02-03 12:04:11 -0500611GLuint Context::createTransformFeedback()
612{
Geoff Lang36167ab2015-12-07 10:27:14 -0500613 GLuint transformFeedback = mTransformFeedbackAllocator.allocate();
614 mTransformFeedbackMap[transformFeedback] = nullptr;
615 return transformFeedback;
Geoff Langc8058452014-02-03 12:04:11 -0500616}
617
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000618// Returns an unused framebuffer name
619GLuint Context::createFramebuffer()
620{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500621 return mState.mFramebuffers->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000622}
623
Jamie Madill33dc8432013-07-26 11:55:05 -0400624GLuint Context::createFenceNV()
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000625{
Jamie Madill33dc8432013-07-26 11:55:05 -0400626 GLuint handle = mFenceNVHandleAllocator.allocate();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000627
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400628 mFenceNVMap[handle] = new FenceNV(mImplementation->createFenceNV());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000629
630 return handle;
631}
632
633// Returns an unused query name
634GLuint Context::createQuery()
635{
636 GLuint handle = mQueryHandleAllocator.allocate();
637
Yunchao Hed7297bf2017-04-19 15:27:10 +0800638 mQueryMap[handle] = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000639
640 return handle;
641}
642
643void Context::deleteBuffer(GLuint buffer)
644{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500645 if (mState.mBuffers->getBuffer(buffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000646 {
647 detachBuffer(buffer);
648 }
Jamie Madill893ab082014-05-16 16:56:10 -0400649
Jamie Madill6c1f6712017-02-14 19:08:04 -0500650 mState.mBuffers->deleteObject(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000651}
652
653void Context::deleteShader(GLuint shader)
654{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500655 mState.mShaderPrograms->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000656}
657
658void Context::deleteProgram(GLuint program)
659{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500660 mState.mShaderPrograms->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000661}
662
663void Context::deleteTexture(GLuint texture)
664{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500665 if (mState.mTextures->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000666 {
667 detachTexture(texture);
668 }
669
Jamie Madill6c1f6712017-02-14 19:08:04 -0500670 mState.mTextures->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000671}
672
673void Context::deleteRenderbuffer(GLuint renderbuffer)
674{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500675 if (mState.mRenderbuffers->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000676 {
677 detachRenderbuffer(renderbuffer);
678 }
Jamie Madill893ab082014-05-16 16:56:10 -0400679
Jamie Madill6c1f6712017-02-14 19:08:04 -0500680 mState.mRenderbuffers->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000681}
682
Jamie Madillcd055f82013-07-26 11:55:15 -0400683void Context::deleteFenceSync(GLsync fenceSync)
684{
685 // The spec specifies the underlying Fence object is not deleted until all current
686 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
687 // and since our API is currently designed for being called from a single thread, we can delete
688 // the fence immediately.
Jamie Madill6c1f6712017-02-14 19:08:04 -0500689 mState.mFenceSyncs->deleteObject(this,
690 static_cast<GLuint>(reinterpret_cast<uintptr_t>(fenceSync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400691}
692
Sami Väisänene45e53b2016-05-25 10:36:04 +0300693void Context::deletePaths(GLuint first, GLsizei range)
694{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500695 mState.mPaths->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300696}
697
698bool Context::hasPathData(GLuint path) const
699{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500700 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300701 if (pathObj == nullptr)
702 return false;
703
704 return pathObj->hasPathData();
705}
706
707bool Context::hasPath(GLuint path) const
708{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500709 return mState.mPaths->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300710}
711
712void Context::setPathCommands(GLuint path,
713 GLsizei numCommands,
714 const GLubyte *commands,
715 GLsizei numCoords,
716 GLenum coordType,
717 const void *coords)
718{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500719 auto *pathObject = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300720
721 handleError(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
722}
723
724void Context::setPathParameterf(GLuint path, GLenum pname, GLfloat value)
725{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500726 auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300727
728 switch (pname)
729 {
730 case GL_PATH_STROKE_WIDTH_CHROMIUM:
731 pathObj->setStrokeWidth(value);
732 break;
733 case GL_PATH_END_CAPS_CHROMIUM:
734 pathObj->setEndCaps(static_cast<GLenum>(value));
735 break;
736 case GL_PATH_JOIN_STYLE_CHROMIUM:
737 pathObj->setJoinStyle(static_cast<GLenum>(value));
738 break;
739 case GL_PATH_MITER_LIMIT_CHROMIUM:
740 pathObj->setMiterLimit(value);
741 break;
742 case GL_PATH_STROKE_BOUND_CHROMIUM:
743 pathObj->setStrokeBound(value);
744 break;
745 default:
746 UNREACHABLE();
747 break;
748 }
749}
750
751void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value) const
752{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500753 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300754
755 switch (pname)
756 {
757 case GL_PATH_STROKE_WIDTH_CHROMIUM:
758 *value = pathObj->getStrokeWidth();
759 break;
760 case GL_PATH_END_CAPS_CHROMIUM:
761 *value = static_cast<GLfloat>(pathObj->getEndCaps());
762 break;
763 case GL_PATH_JOIN_STYLE_CHROMIUM:
764 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
765 break;
766 case GL_PATH_MITER_LIMIT_CHROMIUM:
767 *value = pathObj->getMiterLimit();
768 break;
769 case GL_PATH_STROKE_BOUND_CHROMIUM:
770 *value = pathObj->getStrokeBound();
771 break;
772 default:
773 UNREACHABLE();
774 break;
775 }
776}
777
778void Context::setPathStencilFunc(GLenum func, GLint ref, GLuint mask)
779{
780 mGLState.setPathStencilFunc(func, ref, mask);
781}
782
Jamie Madill57a89722013-07-02 11:57:03 -0400783void Context::deleteVertexArray(GLuint vertexArray)
784{
Geoff Lang36167ab2015-12-07 10:27:14 -0500785 auto iter = mVertexArrayMap.find(vertexArray);
786 if (iter != mVertexArrayMap.end())
Geoff Lang50b3fe82015-12-08 14:49:12 +0000787 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500788 VertexArray *vertexArrayObject = iter->second;
789 if (vertexArrayObject != nullptr)
790 {
791 detachVertexArray(vertexArray);
792 delete vertexArrayObject;
793 }
Geoff Lang50b3fe82015-12-08 14:49:12 +0000794
Geoff Lang36167ab2015-12-07 10:27:14 -0500795 mVertexArrayMap.erase(iter);
796 mVertexArrayHandleAllocator.release(vertexArray);
Jamie Madill57a89722013-07-02 11:57:03 -0400797 }
798}
799
Jamie Madilldc356042013-07-19 16:36:57 -0400800void Context::deleteSampler(GLuint sampler)
801{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500802 if (mState.mSamplers->getSampler(sampler))
Jamie Madilldc356042013-07-19 16:36:57 -0400803 {
804 detachSampler(sampler);
805 }
806
Jamie Madill6c1f6712017-02-14 19:08:04 -0500807 mState.mSamplers->deleteObject(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -0400808}
809
Geoff Langc8058452014-02-03 12:04:11 -0500810void Context::deleteTransformFeedback(GLuint transformFeedback)
811{
Geoff Lang6e60d6b2017-04-12 12:59:04 -0400812 if (transformFeedback == 0)
813 {
814 return;
815 }
816
Jamie Madill5fd0b2d2015-01-05 13:38:44 -0500817 auto iter = mTransformFeedbackMap.find(transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -0500818 if (iter != mTransformFeedbackMap.end())
819 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500820 TransformFeedback *transformFeedbackObject = iter->second;
821 if (transformFeedbackObject != nullptr)
822 {
823 detachTransformFeedback(transformFeedback);
Jamie Madill6c1f6712017-02-14 19:08:04 -0500824 transformFeedbackObject->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500825 }
826
Geoff Lang50b3fe82015-12-08 14:49:12 +0000827 mTransformFeedbackMap.erase(iter);
Geoff Lang36167ab2015-12-07 10:27:14 -0500828 mTransformFeedbackAllocator.release(transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -0500829 }
830}
831
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000832void Context::deleteFramebuffer(GLuint framebuffer)
833{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500834 if (mState.mFramebuffers->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000835 {
836 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000837 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500838
Jamie Madill6c1f6712017-02-14 19:08:04 -0500839 mState.mFramebuffers->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000840}
841
Jamie Madill33dc8432013-07-26 11:55:05 -0400842void Context::deleteFenceNV(GLuint fence)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000843{
Jamie Madill4e25a0d2016-03-08 13:53:03 -0500844 auto fenceObject = mFenceNVMap.find(fence);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000845
Jamie Madill33dc8432013-07-26 11:55:05 -0400846 if (fenceObject != mFenceNVMap.end())
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000847 {
Jamie Madill33dc8432013-07-26 11:55:05 -0400848 mFenceNVHandleAllocator.release(fenceObject->first);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000849 delete fenceObject->second;
Jamie Madill33dc8432013-07-26 11:55:05 -0400850 mFenceNVMap.erase(fenceObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000851 }
852}
853
854void Context::deleteQuery(GLuint query)
855{
Jamie Madill4e25a0d2016-03-08 13:53:03 -0500856 auto queryObject = mQueryMap.find(query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000857 if (queryObject != mQueryMap.end())
858 {
859 mQueryHandleAllocator.release(queryObject->first);
860 if (queryObject->second)
861 {
862 queryObject->second->release();
863 }
864 mQueryMap.erase(queryObject);
865 }
866}
867
Geoff Lang70d0f492015-12-10 17:45:46 -0500868Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000869{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500870 return mState.mBuffers->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000871}
872
Jamie Madill570f7c82014-07-03 10:38:54 -0400873Texture *Context::getTexture(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000874{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500875 return mState.mTextures->getTexture(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000876}
877
Geoff Lang70d0f492015-12-10 17:45:46 -0500878Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000879{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500880 return mState.mRenderbuffers->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000881}
882
Jamie Madillcd055f82013-07-26 11:55:15 -0400883FenceSync *Context::getFenceSync(GLsync handle) const
884{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500885 return mState.mFenceSyncs->getFenceSync(
886 static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400887}
888
Jamie Madill57a89722013-07-02 11:57:03 -0400889VertexArray *Context::getVertexArray(GLuint handle) const
890{
891 auto vertexArray = mVertexArrayMap.find(handle);
Geoff Lang36167ab2015-12-07 10:27:14 -0500892 return (vertexArray != mVertexArrayMap.end()) ? vertexArray->second : nullptr;
Jamie Madill57a89722013-07-02 11:57:03 -0400893}
894
Jamie Madilldc356042013-07-19 16:36:57 -0400895Sampler *Context::getSampler(GLuint handle) const
896{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500897 return mState.mSamplers->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400898}
899
Geoff Langc8058452014-02-03 12:04:11 -0500900TransformFeedback *Context::getTransformFeedback(GLuint handle) const
901{
Geoff Lang36167ab2015-12-07 10:27:14 -0500902 auto iter = mTransformFeedbackMap.find(handle);
903 return (iter != mTransformFeedbackMap.end()) ? iter->second : nullptr;
Geoff Langc8058452014-02-03 12:04:11 -0500904}
905
Geoff Lang70d0f492015-12-10 17:45:46 -0500906LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
907{
908 switch (identifier)
909 {
910 case GL_BUFFER:
911 return getBuffer(name);
912 case GL_SHADER:
913 return getShader(name);
914 case GL_PROGRAM:
915 return getProgram(name);
916 case GL_VERTEX_ARRAY:
917 return getVertexArray(name);
918 case GL_QUERY:
919 return getQuery(name);
920 case GL_TRANSFORM_FEEDBACK:
921 return getTransformFeedback(name);
922 case GL_SAMPLER:
923 return getSampler(name);
924 case GL_TEXTURE:
925 return getTexture(name);
926 case GL_RENDERBUFFER:
927 return getRenderbuffer(name);
928 case GL_FRAMEBUFFER:
929 return getFramebuffer(name);
930 default:
931 UNREACHABLE();
932 return nullptr;
933 }
934}
935
936LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
937{
938 return getFenceSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
939}
940
Martin Radev9d901792016-07-15 15:58:58 +0300941void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
942{
943 LabeledObject *object = getLabeledObject(identifier, name);
944 ASSERT(object != nullptr);
945
946 std::string labelName = GetObjectLabelFromPointer(length, label);
947 object->setLabel(labelName);
948}
949
950void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
951{
952 LabeledObject *object = getLabeledObjectFromPtr(ptr);
953 ASSERT(object != nullptr);
954
955 std::string labelName = GetObjectLabelFromPointer(length, label);
956 object->setLabel(labelName);
957}
958
959void Context::getObjectLabel(GLenum identifier,
960 GLuint name,
961 GLsizei bufSize,
962 GLsizei *length,
963 GLchar *label) const
964{
965 LabeledObject *object = getLabeledObject(identifier, name);
966 ASSERT(object != nullptr);
967
968 const std::string &objectLabel = object->getLabel();
969 GetObjectLabelBase(objectLabel, bufSize, length, label);
970}
971
972void Context::getObjectPtrLabel(const void *ptr,
973 GLsizei bufSize,
974 GLsizei *length,
975 GLchar *label) const
976{
977 LabeledObject *object = getLabeledObjectFromPtr(ptr);
978 ASSERT(object != nullptr);
979
980 const std::string &objectLabel = object->getLabel();
981 GetObjectLabelBase(objectLabel, bufSize, length, label);
982}
983
Jamie Madilldc356042013-07-19 16:36:57 -0400984bool Context::isSampler(GLuint samplerName) const
985{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500986 return mState.mSamplers->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -0400987}
988
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500989void Context::bindArrayBuffer(GLuint bufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000990{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500991 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700992 mGLState.setArrayBufferBinding(buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000993}
994
Jiajia Qin9d7d0b12016-11-29 16:30:31 +0800995void Context::bindDrawIndirectBuffer(GLuint bufferHandle)
996{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500997 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jiajia Qin9d7d0b12016-11-29 16:30:31 +0800998 mGLState.setDrawIndirectBufferBinding(buffer);
999}
1000
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001001void Context::bindElementArrayBuffer(GLuint bufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001002{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001003 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Shao80957d92017-02-20 21:25:59 +08001004 mGLState.setElementArrayBuffer(buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001005}
1006
Jamie Madilldedd7b92014-11-05 16:30:36 -05001007void Context::bindTexture(GLenum target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001008{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001009 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001010
Jamie Madilldedd7b92014-11-05 16:30:36 -05001011 if (handle == 0)
1012 {
1013 texture = mZeroTextures[target].get();
1014 }
1015 else
1016 {
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001017 texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -05001018 }
1019
1020 ASSERT(texture);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001021 mGLState.setSamplerTexture(target, texture);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00001022}
1023
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001024void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001025{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001026 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1027 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001028 mGLState.setReadFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001029}
1030
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001031void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001032{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001033 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1034 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001035 mGLState.setDrawFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001036}
1037
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001038void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -04001039{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001040 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001041 mGLState.setVertexArrayBinding(vertexArray);
Jamie Madill57a89722013-07-02 11:57:03 -04001042}
1043
Shao80957d92017-02-20 21:25:59 +08001044void Context::bindVertexBuffer(GLuint bindingIndex,
1045 GLuint bufferHandle,
1046 GLintptr offset,
1047 GLsizei stride)
1048{
1049 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
1050 mGLState.bindVertexBuffer(bindingIndex, buffer, offset, stride);
1051}
1052
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001053void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -04001054{
Geoff Lang76b10c92014-09-05 16:28:14 -04001055 ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -04001056 Sampler *sampler =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001057 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001058 mGLState.setSamplerBinding(textureUnit, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04001059}
1060
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001061void Context::bindGenericUniformBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001062{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001063 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001064 mGLState.setGenericUniformBufferBinding(buffer);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001065}
1066
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001067void Context::bindIndexedUniformBuffer(GLuint bufferHandle,
1068 GLuint index,
1069 GLintptr offset,
1070 GLsizeiptr size)
shannon.woods%transgaming.com@gtempaccount.com34089352013-04-13 03:36:57 +00001071{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001072 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001073 mGLState.setIndexedUniformBufferBinding(index, buffer, offset, size);
shannon.woods%transgaming.com@gtempaccount.com34089352013-04-13 03:36:57 +00001074}
1075
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001076void Context::bindGenericTransformFeedbackBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001077{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001078 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001079 mGLState.getCurrentTransformFeedback()->bindGenericBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001080}
1081
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001082void Context::bindIndexedTransformFeedbackBuffer(GLuint bufferHandle,
1083 GLuint index,
1084 GLintptr offset,
1085 GLsizeiptr size)
shannon.woods%transgaming.com@gtempaccount.com34089352013-04-13 03:36:57 +00001086{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001087 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001088 mGLState.getCurrentTransformFeedback()->bindIndexedBuffer(index, buffer, offset, size);
shannon.woods%transgaming.com@gtempaccount.com34089352013-04-13 03:36:57 +00001089}
1090
Jiajia Qin6eafb042016-12-27 17:04:07 +08001091void Context::bindGenericAtomicCounterBuffer(GLuint bufferHandle)
1092{
1093 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
1094 mGLState.setGenericAtomicCounterBufferBinding(buffer);
1095}
1096
1097void Context::bindIndexedAtomicCounterBuffer(GLuint bufferHandle,
1098 GLuint index,
1099 GLintptr offset,
1100 GLsizeiptr size)
1101{
1102 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
1103 mGLState.setIndexedAtomicCounterBufferBinding(index, buffer, offset, size);
1104}
1105
Jiajia Qinf546e7d2017-03-27 14:12:59 +08001106void Context::bindGenericShaderStorageBuffer(GLuint bufferHandle)
1107{
1108 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
1109 mGLState.setGenericShaderStorageBufferBinding(buffer);
1110}
1111
1112void Context::bindIndexedShaderStorageBuffer(GLuint bufferHandle,
1113 GLuint index,
1114 GLintptr offset,
1115 GLsizeiptr size)
1116{
1117 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
1118 mGLState.setIndexedShaderStorageBufferBinding(index, buffer, offset, size);
1119}
1120
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001121void Context::bindCopyReadBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001122{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001123 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001124 mGLState.setCopyReadBufferBinding(buffer);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001125}
1126
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001127void Context::bindCopyWriteBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001128{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001129 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001130 mGLState.setCopyWriteBufferBinding(buffer);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001131}
1132
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001133void Context::bindPixelPackBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001134{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001135 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001136 mGLState.setPixelPackBufferBinding(buffer);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001137}
1138
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001139void Context::bindPixelUnpackBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001140{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001141 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001142 mGLState.setPixelUnpackBufferBinding(buffer);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001143}
1144
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001145void Context::useProgram(GLuint program)
1146{
Jamie Madill6c1f6712017-02-14 19:08:04 -05001147 mGLState.setProgram(this, getProgram(program));
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001148}
1149
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001150void Context::bindTransformFeedback(GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001151{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001152 TransformFeedback *transformFeedback =
1153 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001154 mGLState.setTransformFeedbackBinding(transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -05001155}
1156
Geoff Lang5aad9672014-09-08 11:10:42 -04001157Error Context::beginQuery(GLenum target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001158{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001159 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001160 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001161
Geoff Lang5aad9672014-09-08 11:10:42 -04001162 // begin query
1163 Error error = queryObject->begin();
1164 if (error.isError())
1165 {
1166 return error;
1167 }
1168
1169 // set query as active for specified target only if begin succeeded
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001170 mGLState.setActiveQuery(target, queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001171
He Yunchaoacd18982017-01-04 10:46:42 +08001172 return NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001173}
1174
Geoff Lang5aad9672014-09-08 11:10:42 -04001175Error Context::endQuery(GLenum target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001176{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001177 Query *queryObject = mGLState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001178 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001179
Geoff Lang5aad9672014-09-08 11:10:42 -04001180 gl::Error error = queryObject->end();
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001181
Geoff Lang5aad9672014-09-08 11:10:42 -04001182 // Always unbind the query, even if there was an error. This may delete the query object.
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001183 mGLState.setActiveQuery(target, nullptr);
Geoff Lang5aad9672014-09-08 11:10:42 -04001184
1185 return error;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001186}
1187
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001188Error Context::queryCounter(GLuint id, GLenum target)
1189{
1190 ASSERT(target == GL_TIMESTAMP_EXT);
1191
1192 Query *queryObject = getQuery(id, true, target);
1193 ASSERT(queryObject);
1194
1195 return queryObject->queryCounter();
1196}
1197
1198void Context::getQueryiv(GLenum target, GLenum pname, GLint *params)
1199{
1200 switch (pname)
1201 {
1202 case GL_CURRENT_QUERY_EXT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001203 params[0] = mGLState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001204 break;
1205 case GL_QUERY_COUNTER_BITS_EXT:
1206 switch (target)
1207 {
1208 case GL_TIME_ELAPSED_EXT:
1209 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1210 break;
1211 case GL_TIMESTAMP_EXT:
1212 params[0] = getExtensions().queryCounterBitsTimestamp;
1213 break;
1214 default:
1215 UNREACHABLE();
1216 params[0] = 0;
1217 break;
1218 }
1219 break;
1220 default:
1221 UNREACHABLE();
1222 return;
1223 }
1224}
1225
Geoff Lang2186c382016-10-14 10:54:54 -04001226void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001227{
Geoff Lang2186c382016-10-14 10:54:54 -04001228 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001229}
1230
Geoff Lang2186c382016-10-14 10:54:54 -04001231void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001232{
Geoff Lang2186c382016-10-14 10:54:54 -04001233 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001234}
1235
Geoff Lang2186c382016-10-14 10:54:54 -04001236void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001237{
Geoff Lang2186c382016-10-14 10:54:54 -04001238 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001239}
1240
Geoff Lang2186c382016-10-14 10:54:54 -04001241void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001242{
Geoff Lang2186c382016-10-14 10:54:54 -04001243 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001244}
1245
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001246Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001247{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001248 return mState.mFramebuffers->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001249}
1250
Jamie Madill33dc8432013-07-26 11:55:05 -04001251FenceNV *Context::getFenceNV(unsigned int handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001252{
Jamie Madill4e25a0d2016-03-08 13:53:03 -05001253 auto fence = mFenceNVMap.find(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001254
Jamie Madill33dc8432013-07-26 11:55:05 -04001255 if (fence == mFenceNVMap.end())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001256 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001257 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001258 }
1259 else
1260 {
1261 return fence->second;
1262 }
1263}
1264
1265Query *Context::getQuery(unsigned int handle, bool create, GLenum type)
1266{
Jamie Madill4e25a0d2016-03-08 13:53:03 -05001267 auto query = mQueryMap.find(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001268
1269 if (query == mQueryMap.end())
1270 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001271 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001272 }
1273 else
1274 {
1275 if (!query->second && create)
1276 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001277 query->second = new Query(mImplementation->createQuery(type), handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001278 query->second->addRef();
1279 }
1280 return query->second;
1281 }
1282}
1283
Geoff Lang70d0f492015-12-10 17:45:46 -05001284Query *Context::getQuery(GLuint handle) const
1285{
1286 auto iter = mQueryMap.find(handle);
1287 return (iter != mQueryMap.end()) ? iter->second : nullptr;
1288}
1289
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001290Texture *Context::getTargetTexture(GLenum target) const
1291{
Ian Ewellbda75592016-04-18 17:25:54 -04001292 ASSERT(ValidTextureTarget(this, target) || ValidTextureExternalTarget(this, target));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001293 return mGLState.getTargetTexture(target);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001294}
1295
Geoff Lang76b10c92014-09-05 16:28:14 -04001296Texture *Context::getSamplerTexture(unsigned int sampler, GLenum type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001297{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001298 return mGLState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001299}
1300
Geoff Lang492a7e42014-11-05 13:27:06 -05001301Compiler *Context::getCompiler() const
1302{
1303 return mCompiler;
1304}
1305
Jamie Madillc1d770e2017-04-13 17:31:24 -04001306void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001307{
1308 switch (pname)
1309 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001310 case GL_SHADER_COMPILER:
1311 *params = GL_TRUE;
1312 break;
1313 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1314 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1315 break;
1316 default:
1317 mGLState.getBooleanv(pname, params);
1318 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001319 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001320}
1321
Jamie Madillc1d770e2017-04-13 17:31:24 -04001322void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001323{
Shannon Woods53a94a82014-06-24 15:20:36 -04001324 // Queries about context capabilities and maximums are answered by Context.
1325 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001326 switch (pname)
1327 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001328 case GL_ALIASED_LINE_WIDTH_RANGE:
1329 params[0] = mCaps.minAliasedLineWidth;
1330 params[1] = mCaps.maxAliasedLineWidth;
1331 break;
1332 case GL_ALIASED_POINT_SIZE_RANGE:
1333 params[0] = mCaps.minAliasedPointSize;
1334 params[1] = mCaps.maxAliasedPointSize;
1335 break;
1336 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1337 ASSERT(mExtensions.textureFilterAnisotropic);
1338 *params = mExtensions.maxTextureAnisotropy;
1339 break;
1340 case GL_MAX_TEXTURE_LOD_BIAS:
1341 *params = mCaps.maxLODBias;
1342 break;
1343
1344 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1345 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1346 {
1347 ASSERT(mExtensions.pathRendering);
1348 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1349 memcpy(params, m, 16 * sizeof(GLfloat));
1350 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001351 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001352
Jamie Madill231c7f52017-04-26 13:45:37 -04001353 default:
1354 mGLState.getFloatv(pname, params);
1355 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001356 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001357}
1358
Jamie Madillc1d770e2017-04-13 17:31:24 -04001359void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001360{
Shannon Woods53a94a82014-06-24 15:20:36 -04001361 // Queries about context capabilities and maximums are answered by Context.
1362 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001363
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001364 switch (pname)
1365 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001366 case GL_MAX_VERTEX_ATTRIBS:
1367 *params = mCaps.maxVertexAttributes;
1368 break;
1369 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1370 *params = mCaps.maxVertexUniformVectors;
1371 break;
1372 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
1373 *params = mCaps.maxVertexUniformComponents;
1374 break;
1375 case GL_MAX_VARYING_VECTORS:
1376 *params = mCaps.maxVaryingVectors;
1377 break;
1378 case GL_MAX_VARYING_COMPONENTS:
1379 *params = mCaps.maxVertexOutputComponents;
1380 break;
1381 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1382 *params = mCaps.maxCombinedTextureImageUnits;
1383 break;
1384 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
1385 *params = mCaps.maxVertexTextureImageUnits;
1386 break;
1387 case GL_MAX_TEXTURE_IMAGE_UNITS:
1388 *params = mCaps.maxTextureImageUnits;
1389 break;
1390 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1391 *params = mCaps.maxFragmentUniformVectors;
1392 break;
1393 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
1394 *params = mCaps.maxFragmentUniformComponents;
1395 break;
1396 case GL_MAX_RENDERBUFFER_SIZE:
1397 *params = mCaps.maxRenderbufferSize;
1398 break;
1399 case GL_MAX_COLOR_ATTACHMENTS_EXT:
1400 *params = mCaps.maxColorAttachments;
1401 break;
1402 case GL_MAX_DRAW_BUFFERS_EXT:
1403 *params = mCaps.maxDrawBuffers;
1404 break;
1405 // case GL_FRAMEBUFFER_BINDING: // now equivalent to
1406 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
1407 case GL_SUBPIXEL_BITS:
1408 *params = 4;
1409 break;
1410 case GL_MAX_TEXTURE_SIZE:
1411 *params = mCaps.max2DTextureSize;
1412 break;
1413 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1414 *params = mCaps.maxCubeMapTextureSize;
1415 break;
1416 case GL_MAX_3D_TEXTURE_SIZE:
1417 *params = mCaps.max3DTextureSize;
1418 break;
1419 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1420 *params = mCaps.maxArrayTextureLayers;
1421 break;
1422 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1423 *params = mCaps.uniformBufferOffsetAlignment;
1424 break;
1425 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1426 *params = mCaps.maxUniformBufferBindings;
1427 break;
1428 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
1429 *params = mCaps.maxVertexUniformBlocks;
1430 break;
1431 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
1432 *params = mCaps.maxFragmentUniformBlocks;
1433 break;
1434 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1435 *params = mCaps.maxCombinedTextureImageUnits;
1436 break;
1437 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1438 *params = mCaps.maxVertexOutputComponents;
1439 break;
1440 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1441 *params = mCaps.maxFragmentInputComponents;
1442 break;
1443 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1444 *params = mCaps.minProgramTexelOffset;
1445 break;
1446 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1447 *params = mCaps.maxProgramTexelOffset;
1448 break;
1449 case GL_MAJOR_VERSION:
1450 *params = getClientVersion().major;
1451 break;
1452 case GL_MINOR_VERSION:
1453 *params = getClientVersion().minor;
1454 break;
1455 case GL_MAX_ELEMENTS_INDICES:
1456 *params = mCaps.maxElementsIndices;
1457 break;
1458 case GL_MAX_ELEMENTS_VERTICES:
1459 *params = mCaps.maxElementsVertices;
1460 break;
1461 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1462 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1463 break;
1464 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1465 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1466 break;
1467 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1468 *params = mCaps.maxTransformFeedbackSeparateComponents;
1469 break;
1470 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1471 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1472 break;
1473 case GL_MAX_SAMPLES_ANGLE:
1474 *params = mCaps.maxSamples;
1475 break;
1476 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001477 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001478 params[0] = mCaps.maxViewportWidth;
1479 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001480 }
1481 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001482 case GL_COMPRESSED_TEXTURE_FORMATS:
1483 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1484 params);
1485 break;
1486 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1487 *params = mResetStrategy;
1488 break;
1489 case GL_NUM_SHADER_BINARY_FORMATS:
1490 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1491 break;
1492 case GL_SHADER_BINARY_FORMATS:
1493 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1494 break;
1495 case GL_NUM_PROGRAM_BINARY_FORMATS:
1496 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1497 break;
1498 case GL_PROGRAM_BINARY_FORMATS:
1499 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1500 break;
1501 case GL_NUM_EXTENSIONS:
1502 *params = static_cast<GLint>(mExtensionStrings.size());
1503 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001504
Jamie Madill231c7f52017-04-26 13:45:37 -04001505 // GL_KHR_debug
1506 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1507 *params = mExtensions.maxDebugMessageLength;
1508 break;
1509 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1510 *params = mExtensions.maxDebugLoggedMessages;
1511 break;
1512 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1513 *params = mExtensions.maxDebugGroupStackDepth;
1514 break;
1515 case GL_MAX_LABEL_LENGTH:
1516 *params = mExtensions.maxLabelLength;
1517 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001518
Jamie Madill231c7f52017-04-26 13:45:37 -04001519 // GL_EXT_disjoint_timer_query
1520 case GL_GPU_DISJOINT_EXT:
1521 *params = mImplementation->getGPUDisjoint();
1522 break;
1523 case GL_MAX_FRAMEBUFFER_WIDTH:
1524 *params = mCaps.maxFramebufferWidth;
1525 break;
1526 case GL_MAX_FRAMEBUFFER_HEIGHT:
1527 *params = mCaps.maxFramebufferHeight;
1528 break;
1529 case GL_MAX_FRAMEBUFFER_SAMPLES:
1530 *params = mCaps.maxFramebufferSamples;
1531 break;
1532 case GL_MAX_SAMPLE_MASK_WORDS:
1533 *params = mCaps.maxSampleMaskWords;
1534 break;
1535 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1536 *params = mCaps.maxColorTextureSamples;
1537 break;
1538 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1539 *params = mCaps.maxDepthTextureSamples;
1540 break;
1541 case GL_MAX_INTEGER_SAMPLES:
1542 *params = mCaps.maxIntegerSamples;
1543 break;
1544 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1545 *params = mCaps.maxVertexAttribRelativeOffset;
1546 break;
1547 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1548 *params = mCaps.maxVertexAttribBindings;
1549 break;
1550 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1551 *params = mCaps.maxVertexAttribStride;
1552 break;
1553 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
1554 *params = mCaps.maxVertexAtomicCounterBuffers;
1555 break;
1556 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
1557 *params = mCaps.maxVertexAtomicCounters;
1558 break;
1559 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
1560 *params = mCaps.maxVertexImageUniforms;
1561 break;
1562 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
1563 *params = mCaps.maxVertexShaderStorageBlocks;
1564 break;
1565 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
1566 *params = mCaps.maxFragmentAtomicCounterBuffers;
1567 break;
1568 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
1569 *params = mCaps.maxFragmentAtomicCounters;
1570 break;
1571 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
1572 *params = mCaps.maxFragmentImageUniforms;
1573 break;
1574 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
1575 *params = mCaps.maxFragmentShaderStorageBlocks;
1576 break;
1577 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1578 *params = mCaps.minProgramTextureGatherOffset;
1579 break;
1580 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1581 *params = mCaps.maxProgramTextureGatherOffset;
1582 break;
1583 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1584 *params = mCaps.maxComputeWorkGroupInvocations;
1585 break;
1586 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
1587 *params = mCaps.maxComputeUniformBlocks;
1588 break;
1589 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
1590 *params = mCaps.maxComputeTextureImageUnits;
1591 break;
1592 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1593 *params = mCaps.maxComputeSharedMemorySize;
1594 break;
1595 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
1596 *params = mCaps.maxComputeUniformComponents;
1597 break;
1598 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
1599 *params = mCaps.maxComputeAtomicCounterBuffers;
1600 break;
1601 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
1602 *params = mCaps.maxComputeAtomicCounters;
1603 break;
1604 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
1605 *params = mCaps.maxComputeImageUniforms;
1606 break;
1607 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
1608 *params = mCaps.maxCombinedComputeUniformComponents;
1609 break;
1610 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
1611 *params = mCaps.maxComputeShaderStorageBlocks;
1612 break;
1613 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1614 *params = mCaps.maxCombinedShaderOutputResources;
1615 break;
1616 case GL_MAX_UNIFORM_LOCATIONS:
1617 *params = mCaps.maxUniformLocations;
1618 break;
1619 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1620 *params = mCaps.maxAtomicCounterBufferBindings;
1621 break;
1622 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1623 *params = mCaps.maxAtomicCounterBufferSize;
1624 break;
1625 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1626 *params = mCaps.maxCombinedAtomicCounterBuffers;
1627 break;
1628 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1629 *params = mCaps.maxCombinedAtomicCounters;
1630 break;
1631 case GL_MAX_IMAGE_UNITS:
1632 *params = mCaps.maxImageUnits;
1633 break;
1634 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1635 *params = mCaps.maxCombinedImageUniforms;
1636 break;
1637 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1638 *params = mCaps.maxShaderStorageBufferBindings;
1639 break;
1640 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1641 *params = mCaps.maxCombinedShaderStorageBlocks;
1642 break;
1643 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1644 *params = mCaps.shaderStorageBufferOffsetAlignment;
1645 break;
1646 default:
1647 mGLState.getIntegerv(this, pname, params);
1648 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001649 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001650}
1651
Jamie Madill893ab082014-05-16 16:56:10 -04001652void Context::getInteger64v(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001653{
Shannon Woods53a94a82014-06-24 15:20:36 -04001654 // Queries about context capabilities and maximums are answered by Context.
1655 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001656 switch (pname)
1657 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001658 case GL_MAX_ELEMENT_INDEX:
1659 *params = mCaps.maxElementIndex;
1660 break;
1661 case GL_MAX_UNIFORM_BLOCK_SIZE:
1662 *params = mCaps.maxUniformBlockSize;
1663 break;
1664 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
1665 *params = mCaps.maxCombinedVertexUniformComponents;
1666 break;
1667 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
1668 *params = mCaps.maxCombinedFragmentUniformComponents;
1669 break;
1670 case GL_MAX_SERVER_WAIT_TIMEOUT:
1671 *params = mCaps.maxServerWaitTimeout;
1672 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001673
Jamie Madill231c7f52017-04-26 13:45:37 -04001674 // GL_EXT_disjoint_timer_query
1675 case GL_TIMESTAMP_EXT:
1676 *params = mImplementation->getTimestamp();
1677 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001678
Jamie Madill231c7f52017-04-26 13:45:37 -04001679 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1680 *params = mCaps.maxShaderStorageBlockSize;
1681 break;
1682 default:
1683 UNREACHABLE();
1684 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001685 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001686}
1687
Geoff Lang70d0f492015-12-10 17:45:46 -05001688void Context::getPointerv(GLenum pname, void **params) const
1689{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001690 mGLState.getPointerv(pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001691}
1692
Martin Radev66fb8202016-07-28 11:45:20 +03001693void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001694{
Shannon Woods53a94a82014-06-24 15:20:36 -04001695 // Queries about context capabilities and maximums are answered by Context.
1696 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001697
1698 GLenum nativeType;
1699 unsigned int numParams;
1700 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1701 ASSERT(queryStatus);
1702
1703 if (nativeType == GL_INT)
1704 {
1705 switch (target)
1706 {
1707 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1708 ASSERT(index < 3u);
1709 *data = mCaps.maxComputeWorkGroupCount[index];
1710 break;
1711 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1712 ASSERT(index < 3u);
1713 *data = mCaps.maxComputeWorkGroupSize[index];
1714 break;
1715 default:
1716 mGLState.getIntegeri_v(target, index, data);
1717 }
1718 }
1719 else
1720 {
1721 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1722 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001723}
1724
Martin Radev66fb8202016-07-28 11:45:20 +03001725void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001726{
Shannon Woods53a94a82014-06-24 15:20:36 -04001727 // Queries about context capabilities and maximums are answered by Context.
1728 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001729
1730 GLenum nativeType;
1731 unsigned int numParams;
1732 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1733 ASSERT(queryStatus);
1734
1735 if (nativeType == GL_INT_64_ANGLEX)
1736 {
1737 mGLState.getInteger64i_v(target, index, data);
1738 }
1739 else
1740 {
1741 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1742 }
1743}
1744
1745void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1746{
1747 // Queries about context capabilities and maximums are answered by Context.
1748 // Queries about current GL state values are answered by State.
1749
1750 GLenum nativeType;
1751 unsigned int numParams;
1752 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1753 ASSERT(queryStatus);
1754
1755 if (nativeType == GL_BOOL)
1756 {
1757 mGLState.getBooleani_v(target, index, data);
1758 }
1759 else
1760 {
1761 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1762 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001763}
1764
He Yunchao010e4db2017-03-03 14:22:06 +08001765void Context::getBufferParameteriv(GLenum target, GLenum pname, GLint *params)
1766{
1767 Buffer *buffer = mGLState.getTargetBuffer(target);
1768 QueryBufferParameteriv(buffer, pname, params);
1769}
1770
1771void Context::getFramebufferAttachmentParameteriv(GLenum target,
1772 GLenum attachment,
1773 GLenum pname,
1774 GLint *params)
1775{
1776 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
1777 QueryFramebufferAttachmentParameteriv(framebuffer, attachment, pname, params);
1778}
1779
1780void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
1781{
1782 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
1783 QueryRenderbufferiv(this, renderbuffer, pname, params);
1784}
1785
1786void Context::getTexParameterfv(GLenum target, GLenum pname, GLfloat *params)
1787{
1788 Texture *texture = getTargetTexture(target);
1789 QueryTexParameterfv(texture, pname, params);
1790}
1791
1792void Context::getTexParameteriv(GLenum target, GLenum pname, GLint *params)
1793{
1794 Texture *texture = getTargetTexture(target);
1795 QueryTexParameteriv(texture, pname, params);
1796}
1797void Context::texParameterf(GLenum target, GLenum pname, GLfloat param)
1798{
1799 Texture *texture = getTargetTexture(target);
1800 SetTexParameterf(texture, pname, param);
1801}
1802
1803void Context::texParameterfv(GLenum target, GLenum pname, const GLfloat *params)
1804{
1805 Texture *texture = getTargetTexture(target);
1806 SetTexParameterfv(texture, pname, params);
1807}
1808
1809void Context::texParameteri(GLenum target, GLenum pname, GLint param)
1810{
1811 Texture *texture = getTargetTexture(target);
1812 SetTexParameteri(texture, pname, param);
1813}
1814
1815void Context::texParameteriv(GLenum target, GLenum pname, const GLint *params)
1816{
1817 Texture *texture = getTargetTexture(target);
1818 SetTexParameteriv(texture, pname, params);
1819}
1820
Jamie Madill675fe712016-12-19 13:07:54 -05001821void Context::drawArrays(GLenum mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001822{
Jamie Madill1b94d432015-08-07 13:23:23 -04001823 syncRendererState();
Jamie Madillc564c072017-06-01 12:45:42 -04001824 auto error = mImplementation->drawArrays(this, mode, first, count);
Jamie Madill675fe712016-12-19 13:07:54 -05001825 handleError(error);
1826 if (!error.isError())
1827 {
1828 MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback());
1829 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001830}
1831
Jamie Madill675fe712016-12-19 13:07:54 -05001832void Context::drawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04001833{
1834 syncRendererState();
Jamie Madillc564c072017-06-01 12:45:42 -04001835 auto error = mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount);
Jamie Madill675fe712016-12-19 13:07:54 -05001836 handleError(error);
1837 if (!error.isError())
1838 {
1839 MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback());
1840 }
Geoff Langf6db0982015-08-25 13:04:00 -04001841}
1842
Jamie Madill876429b2017-04-20 15:46:24 -04001843void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001844{
Jamie Madill1b94d432015-08-07 13:23:23 -04001845 syncRendererState();
Jamie Madill9c9b40a2017-04-26 16:31:57 -04001846 const IndexRange &indexRange = getParams<HasIndexRange>().getIndexRange().value();
Jamie Madillc564c072017-06-01 12:45:42 -04001847 handleError(mImplementation->drawElements(this, mode, count, type, indices, indexRange));
Geoff Langf6db0982015-08-25 13:04:00 -04001848}
1849
Jamie Madill675fe712016-12-19 13:07:54 -05001850void Context::drawElementsInstanced(GLenum mode,
1851 GLsizei count,
1852 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04001853 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04001854 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04001855{
1856 syncRendererState();
Jamie Madill9c9b40a2017-04-26 16:31:57 -04001857 const IndexRange &indexRange = getParams<HasIndexRange>().getIndexRange().value();
Jamie Madillc564c072017-06-01 12:45:42 -04001858 handleError(mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances,
1859 indexRange));
Geoff Langf6db0982015-08-25 13:04:00 -04001860}
1861
Jamie Madill675fe712016-12-19 13:07:54 -05001862void Context::drawRangeElements(GLenum mode,
1863 GLuint start,
1864 GLuint end,
1865 GLsizei count,
1866 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04001867 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04001868{
1869 syncRendererState();
Jamie Madill9c9b40a2017-04-26 16:31:57 -04001870 const IndexRange &indexRange = getParams<HasIndexRange>().getIndexRange().value();
Jamie Madillc564c072017-06-01 12:45:42 -04001871 handleError(mImplementation->drawRangeElements(this, mode, start, end, count, type, indices,
1872 indexRange));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001873}
1874
Jamie Madill876429b2017-04-20 15:46:24 -04001875void Context::drawArraysIndirect(GLenum mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08001876{
1877 syncRendererState();
Jamie Madillc564c072017-06-01 12:45:42 -04001878 handleError(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08001879}
1880
Jamie Madill876429b2017-04-20 15:46:24 -04001881void Context::drawElementsIndirect(GLenum mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08001882{
1883 syncRendererState();
Jamie Madillc564c072017-06-01 12:45:42 -04001884 handleError(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08001885}
1886
Jamie Madill675fe712016-12-19 13:07:54 -05001887void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001888{
Jamie Madill675fe712016-12-19 13:07:54 -05001889 handleError(mImplementation->flush());
Geoff Lang129753a2015-01-09 16:52:09 -05001890}
1891
Jamie Madill675fe712016-12-19 13:07:54 -05001892void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05001893{
Jamie Madill675fe712016-12-19 13:07:54 -05001894 handleError(mImplementation->finish());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001895}
1896
Austin Kinross6ee1e782015-05-29 17:05:37 -07001897void Context::insertEventMarker(GLsizei length, const char *marker)
1898{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001899 ASSERT(mImplementation);
1900 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07001901}
1902
1903void Context::pushGroupMarker(GLsizei length, const char *marker)
1904{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001905 ASSERT(mImplementation);
1906 mImplementation->pushGroupMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07001907}
1908
1909void Context::popGroupMarker()
1910{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001911 ASSERT(mImplementation);
1912 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07001913}
1914
Geoff Langd8605522016-04-13 10:19:12 -04001915void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
1916{
1917 Program *programObject = getProgram(program);
1918 ASSERT(programObject);
1919
1920 programObject->bindUniformLocation(location, name);
1921}
1922
Sami Väisänena797e062016-05-12 15:23:40 +03001923void Context::setCoverageModulation(GLenum components)
1924{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001925 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03001926}
1927
Sami Väisänene45e53b2016-05-25 10:36:04 +03001928void Context::loadPathRenderingMatrix(GLenum matrixMode, const GLfloat *matrix)
1929{
1930 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
1931}
1932
1933void Context::loadPathRenderingIdentityMatrix(GLenum matrixMode)
1934{
1935 GLfloat I[16];
1936 angle::Matrix<GLfloat>::setToIdentity(I);
1937
1938 mGLState.loadPathRenderingMatrix(matrixMode, I);
1939}
1940
1941void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
1942{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001943 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001944 if (!pathObj)
1945 return;
1946
1947 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1948 syncRendererState();
1949
1950 mImplementation->stencilFillPath(pathObj, fillMode, mask);
1951}
1952
1953void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
1954{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001955 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001956 if (!pathObj)
1957 return;
1958
1959 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1960 syncRendererState();
1961
1962 mImplementation->stencilStrokePath(pathObj, reference, mask);
1963}
1964
1965void Context::coverFillPath(GLuint path, GLenum coverMode)
1966{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001967 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001968 if (!pathObj)
1969 return;
1970
1971 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1972 syncRendererState();
1973
1974 mImplementation->coverFillPath(pathObj, coverMode);
1975}
1976
1977void Context::coverStrokePath(GLuint path, GLenum coverMode)
1978{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001979 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001980 if (!pathObj)
1981 return;
1982
1983 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1984 syncRendererState();
1985
1986 mImplementation->coverStrokePath(pathObj, coverMode);
1987}
1988
1989void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
1990{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001991 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001992 if (!pathObj)
1993 return;
1994
1995 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1996 syncRendererState();
1997
1998 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
1999}
2000
2001void Context::stencilThenCoverStrokePath(GLuint path,
2002 GLint reference,
2003 GLuint mask,
2004 GLenum coverMode)
2005{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002006 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002007 if (!pathObj)
2008 return;
2009
2010 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2011 syncRendererState();
2012
2013 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2014}
2015
Sami Väisänend59ca052016-06-21 16:10:00 +03002016void Context::coverFillPathInstanced(GLsizei numPaths,
2017 GLenum pathNameType,
2018 const void *paths,
2019 GLuint pathBase,
2020 GLenum coverMode,
2021 GLenum transformType,
2022 const GLfloat *transformValues)
2023{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002024 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002025
2026 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2027 syncRendererState();
2028
2029 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2030}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002031
Sami Väisänend59ca052016-06-21 16:10:00 +03002032void Context::coverStrokePathInstanced(GLsizei numPaths,
2033 GLenum pathNameType,
2034 const void *paths,
2035 GLuint pathBase,
2036 GLenum coverMode,
2037 GLenum transformType,
2038 const GLfloat *transformValues)
2039{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002040 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002041
2042 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2043 syncRendererState();
2044
2045 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2046 transformValues);
2047}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002048
Sami Väisänend59ca052016-06-21 16:10:00 +03002049void Context::stencilFillPathInstanced(GLsizei numPaths,
2050 GLenum pathNameType,
2051 const void *paths,
2052 GLuint pathBase,
2053 GLenum fillMode,
2054 GLuint mask,
2055 GLenum transformType,
2056 const GLfloat *transformValues)
2057{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002058 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002059
2060 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2061 syncRendererState();
2062
2063 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2064 transformValues);
2065}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002066
Sami Väisänend59ca052016-06-21 16:10:00 +03002067void Context::stencilStrokePathInstanced(GLsizei numPaths,
2068 GLenum pathNameType,
2069 const void *paths,
2070 GLuint pathBase,
2071 GLint reference,
2072 GLuint mask,
2073 GLenum transformType,
2074 const GLfloat *transformValues)
2075{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002076 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002077
2078 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2079 syncRendererState();
2080
2081 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2082 transformValues);
2083}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002084
Sami Väisänend59ca052016-06-21 16:10:00 +03002085void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2086 GLenum pathNameType,
2087 const void *paths,
2088 GLuint pathBase,
2089 GLenum fillMode,
2090 GLuint mask,
2091 GLenum coverMode,
2092 GLenum transformType,
2093 const GLfloat *transformValues)
2094{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002095 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002096
2097 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2098 syncRendererState();
2099
2100 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2101 transformType, transformValues);
2102}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002103
Sami Väisänend59ca052016-06-21 16:10:00 +03002104void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2105 GLenum pathNameType,
2106 const void *paths,
2107 GLuint pathBase,
2108 GLint reference,
2109 GLuint mask,
2110 GLenum coverMode,
2111 GLenum transformType,
2112 const GLfloat *transformValues)
2113{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002114 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002115
2116 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2117 syncRendererState();
2118
2119 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2120 transformType, transformValues);
2121}
2122
Sami Väisänen46eaa942016-06-29 10:26:37 +03002123void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2124{
2125 auto *programObject = getProgram(program);
2126
2127 programObject->bindFragmentInputLocation(location, name);
2128}
2129
2130void Context::programPathFragmentInputGen(GLuint program,
2131 GLint location,
2132 GLenum genMode,
2133 GLint components,
2134 const GLfloat *coeffs)
2135{
2136 auto *programObject = getProgram(program);
2137
2138 programObject->pathFragmentInputGen(location, genMode, components, coeffs);
2139}
2140
jchen1015015f72017-03-16 13:54:21 +08002141GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2142{
jchen10fd7c3b52017-03-21 15:36:03 +08002143 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002144 return QueryProgramResourceIndex(programObject, programInterface, name);
2145}
2146
jchen10fd7c3b52017-03-21 15:36:03 +08002147void Context::getProgramResourceName(GLuint program,
2148 GLenum programInterface,
2149 GLuint index,
2150 GLsizei bufSize,
2151 GLsizei *length,
2152 GLchar *name)
2153{
2154 const auto *programObject = getProgram(program);
2155 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2156}
2157
Jamie Madill437fa652016-05-03 15:13:24 -04002158void Context::handleError(const Error &error)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002159{
Geoff Langda5777c2014-07-11 09:52:58 -04002160 if (error.isError())
2161 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002162 GLenum code = error.getCode();
2163 mErrors.insert(code);
2164 if (code == GL_OUT_OF_MEMORY && getWorkarounds().loseContextOnOutOfMemory)
2165 {
2166 markContextLost();
2167 }
Geoff Lang70d0f492015-12-10 17:45:46 -05002168
2169 if (!error.getMessage().empty())
2170 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002171 auto *debug = &mGLState.getDebug();
2172 debug->insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, error.getID(),
2173 GL_DEBUG_SEVERITY_HIGH, error.getMessage());
Geoff Lang70d0f492015-12-10 17:45:46 -05002174 }
Geoff Langda5777c2014-07-11 09:52:58 -04002175 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002176}
2177
2178// Get one of the recorded errors and clear its flag, if any.
2179// [OpenGL ES 2.0.24] section 2.5 page 13.
2180GLenum Context::getError()
2181{
Geoff Langda5777c2014-07-11 09:52:58 -04002182 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002183 {
Geoff Langda5777c2014-07-11 09:52:58 -04002184 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002185 }
Geoff Langda5777c2014-07-11 09:52:58 -04002186 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002187 {
Geoff Langda5777c2014-07-11 09:52:58 -04002188 GLenum error = *mErrors.begin();
2189 mErrors.erase(mErrors.begin());
2190 return error;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002191 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002192}
2193
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002194// NOTE: this function should not assume that this context is current!
2195void Context::markContextLost()
2196{
2197 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002198 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002199 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002200 mContextLostForced = true;
2201 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002202 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002203}
2204
2205bool Context::isContextLost()
2206{
2207 return mContextLost;
2208}
2209
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002210GLenum Context::getResetStatus()
2211{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002212 // Even if the application doesn't want to know about resets, we want to know
2213 // as it will allow us to skip all the calls.
2214 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002215 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002216 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002217 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002218 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002219 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002220
2221 // EXT_robustness, section 2.6: If the reset notification behavior is
2222 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2223 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2224 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002225 }
2226
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002227 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2228 // status should be returned at least once, and GL_NO_ERROR should be returned
2229 // once the device has finished resetting.
2230 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002231 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002232 ASSERT(mResetStatus == GL_NO_ERROR);
2233 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002234
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002235 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002236 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002237 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002238 }
2239 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002240 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002241 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002242 // If markContextLost was used to mark the context lost then
2243 // assume that is not recoverable, and continue to report the
2244 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002245 mResetStatus = mImplementation->getResetStatus();
2246 }
Jamie Madill893ab082014-05-16 16:56:10 -04002247
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002248 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002249}
2250
2251bool Context::isResetNotificationEnabled()
2252{
2253 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2254}
2255
Corentin Walleze3b10e82015-05-20 11:06:25 -04002256const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002257{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002258 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002259}
2260
2261EGLenum Context::getClientType() const
2262{
2263 return mClientType;
2264}
2265
2266EGLenum Context::getRenderBuffer() const
2267{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002268 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2269 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002270 {
2271 return EGL_NONE;
2272 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002273
2274 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(GL_BACK);
2275 ASSERT(backAttachment != nullptr);
2276 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002277}
2278
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002279VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002280{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002281 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002282 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2283 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002284 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002285 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2286 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002287
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002288 mVertexArrayMap[vertexArrayHandle] = vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002289 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002290
2291 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002292}
2293
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002294TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002295{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002296 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002297 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2298 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002299 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002300 transformFeedback =
2301 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002302 transformFeedback->addRef();
2303 mTransformFeedbackMap[transformFeedbackHandle] = transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002304 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002305
2306 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002307}
2308
2309bool Context::isVertexArrayGenerated(GLuint vertexArray)
2310{
Geoff Langf41a7152016-09-19 15:11:17 -04002311 ASSERT(mVertexArrayMap.find(0) != mVertexArrayMap.end());
Geoff Lang36167ab2015-12-07 10:27:14 -05002312 return mVertexArrayMap.find(vertexArray) != mVertexArrayMap.end();
2313}
2314
2315bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2316{
Geoff Langf41a7152016-09-19 15:11:17 -04002317 ASSERT(mTransformFeedbackMap.find(0) != mTransformFeedbackMap.end());
Geoff Lang36167ab2015-12-07 10:27:14 -05002318 return mTransformFeedbackMap.find(transformFeedback) != mTransformFeedbackMap.end();
2319}
2320
Shannon Woods53a94a82014-06-24 15:20:36 -04002321void Context::detachTexture(GLuint texture)
2322{
2323 // Simple pass-through to State's detachTexture method, as textures do not require
2324 // allocation map management either here or in the resource manager at detach time.
2325 // Zero textures are held by the Context, and we don't attempt to request them from
2326 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002327 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002328}
2329
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002330void Context::detachBuffer(GLuint buffer)
2331{
Yuly Novikov5807a532015-12-03 13:01:22 -05002332 // Simple pass-through to State's detachBuffer method, since
2333 // only buffer attachments to container objects that are bound to the current context
2334 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002335
Yuly Novikov5807a532015-12-03 13:01:22 -05002336 // [OpenGL ES 3.2] section 5.1.2 page 45:
2337 // Attachments to unbound container objects, such as
2338 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2339 // are not affected and continue to act as references on the deleted object
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002340 mGLState.detachBuffer(buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002341}
2342
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002343void Context::detachFramebuffer(GLuint framebuffer)
2344{
Shannon Woods53a94a82014-06-24 15:20:36 -04002345 // Framebuffer detachment is handled by Context, because 0 is a valid
2346 // Framebuffer object, and a pointer to it must be passed from Context
2347 // to State at binding time.
2348
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002349 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002350 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2351 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2352 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002353
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002354 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002355 {
2356 bindReadFramebuffer(0);
2357 }
2358
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002359 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002360 {
2361 bindDrawFramebuffer(0);
2362 }
2363}
2364
2365void Context::detachRenderbuffer(GLuint renderbuffer)
2366{
Jamie Madilla02315b2017-02-23 14:14:47 -05002367 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002368}
2369
Jamie Madill57a89722013-07-02 11:57:03 -04002370void Context::detachVertexArray(GLuint vertexArray)
2371{
Jamie Madill77a72f62015-04-14 11:18:32 -04002372 // Vertex array detachment is handled by Context, because 0 is a valid
2373 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002374 // binding time.
2375
Jamie Madill57a89722013-07-02 11:57:03 -04002376 // [OpenGL ES 3.0.2] section 2.10 page 43:
2377 // If a vertex array object that is currently bound is deleted, the binding
2378 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002379 if (mGLState.removeVertexArrayBinding(vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002380 {
2381 bindVertexArray(0);
2382 }
2383}
2384
Geoff Langc8058452014-02-03 12:04:11 -05002385void Context::detachTransformFeedback(GLuint transformFeedback)
2386{
Corentin Walleza2257da2016-04-19 16:43:12 -04002387 // Transform feedback detachment is handled by Context, because 0 is a valid
2388 // transform feedback, and a pointer to it must be passed from Context to State at
2389 // binding time.
2390
2391 // The OpenGL specification doesn't mention what should happen when the currently bound
2392 // transform feedback object is deleted. Since it is a container object, we treat it like
2393 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002394 if (mGLState.removeTransformFeedbackBinding(transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002395 {
2396 bindTransformFeedback(0);
2397 }
Geoff Langc8058452014-02-03 12:04:11 -05002398}
2399
Jamie Madilldc356042013-07-19 16:36:57 -04002400void Context::detachSampler(GLuint sampler)
2401{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002402 mGLState.detachSampler(sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002403}
2404
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002405void Context::setVertexAttribDivisor(GLuint index, GLuint divisor)
2406{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002407 mGLState.setVertexAttribDivisor(index, divisor);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002408}
2409
Jamie Madille29d1672013-07-19 16:36:57 -04002410void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2411{
Geoff Langc1984ed2016-10-07 12:41:00 -04002412 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002413 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002414 SetSamplerParameteri(samplerObject, pname, param);
2415}
Jamie Madille29d1672013-07-19 16:36:57 -04002416
Geoff Langc1984ed2016-10-07 12:41:00 -04002417void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2418{
2419 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002420 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002421 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madille29d1672013-07-19 16:36:57 -04002422}
2423
2424void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2425{
Geoff Langc1984ed2016-10-07 12:41:00 -04002426 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002427 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002428 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madille29d1672013-07-19 16:36:57 -04002429}
2430
Geoff Langc1984ed2016-10-07 12:41:00 -04002431void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002432{
Geoff Langc1984ed2016-10-07 12:41:00 -04002433 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002434 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002435 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill9675b802013-07-19 16:36:59 -04002436}
2437
Geoff Langc1984ed2016-10-07 12:41:00 -04002438void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002439{
Geoff Langc1984ed2016-10-07 12:41:00 -04002440 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002441 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002442 QuerySamplerParameteriv(samplerObject, pname, params);
2443}
Jamie Madill9675b802013-07-19 16:36:59 -04002444
Geoff Langc1984ed2016-10-07 12:41:00 -04002445void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2446{
2447 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002448 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002449 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill9675b802013-07-19 16:36:59 -04002450}
2451
Olli Etuahof0fee072016-03-30 15:11:58 +03002452void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2453{
2454 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002455 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002456}
2457
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002458void Context::initRendererString()
2459{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002460 std::ostringstream rendererString;
2461 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002462 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002463 rendererString << ")";
2464
Geoff Langcec35902014-04-16 10:52:36 -04002465 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002466}
2467
Geoff Langc339c4e2016-11-29 10:37:36 -05002468void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002469{
Geoff Langc339c4e2016-11-29 10:37:36 -05002470 const Version &clientVersion = getClientVersion();
2471
2472 std::ostringstream versionString;
2473 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2474 << ANGLE_VERSION_STRING << ")";
2475 mVersionString = MakeStaticString(versionString.str());
2476
2477 std::ostringstream shadingLanguageVersionString;
2478 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2479 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2480 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2481 << ")";
2482 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002483}
2484
Geoff Langcec35902014-04-16 10:52:36 -04002485void Context::initExtensionStrings()
2486{
Geoff Langc339c4e2016-11-29 10:37:36 -05002487 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2488 std::ostringstream combinedStringStream;
2489 std::copy(strings.begin(), strings.end(),
2490 std::ostream_iterator<const char *>(combinedStringStream, " "));
2491 return MakeStaticString(combinedStringStream.str());
2492 };
2493
2494 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002495 for (const auto &extensionString : mExtensions.getStrings())
2496 {
2497 mExtensionStrings.push_back(MakeStaticString(extensionString));
2498 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002499 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002500
Bryan Bernhart58806562017-01-05 13:09:31 -08002501 const gl::Extensions &nativeExtensions = mImplementation->getNativeExtensions();
2502
Geoff Langc339c4e2016-11-29 10:37:36 -05002503 mRequestableExtensionStrings.clear();
2504 for (const auto &extensionInfo : GetExtensionInfoMap())
2505 {
2506 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08002507 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
2508 nativeExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002509 {
2510 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
2511 }
2512 }
2513 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002514}
2515
Geoff Langc339c4e2016-11-29 10:37:36 -05002516const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04002517{
Geoff Langc339c4e2016-11-29 10:37:36 -05002518 switch (name)
2519 {
2520 case GL_VENDOR:
2521 return reinterpret_cast<const GLubyte *>("Google Inc.");
2522
2523 case GL_RENDERER:
2524 return reinterpret_cast<const GLubyte *>(mRendererString);
2525
2526 case GL_VERSION:
2527 return reinterpret_cast<const GLubyte *>(mVersionString);
2528
2529 case GL_SHADING_LANGUAGE_VERSION:
2530 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
2531
2532 case GL_EXTENSIONS:
2533 return reinterpret_cast<const GLubyte *>(mExtensionString);
2534
2535 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2536 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
2537
2538 default:
2539 UNREACHABLE();
2540 return nullptr;
2541 }
Geoff Langcec35902014-04-16 10:52:36 -04002542}
2543
Geoff Langc339c4e2016-11-29 10:37:36 -05002544const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04002545{
Geoff Langc339c4e2016-11-29 10:37:36 -05002546 switch (name)
2547 {
2548 case GL_EXTENSIONS:
2549 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
2550
2551 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2552 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
2553
2554 default:
2555 UNREACHABLE();
2556 return nullptr;
2557 }
Geoff Langcec35902014-04-16 10:52:36 -04002558}
2559
2560size_t Context::getExtensionStringCount() const
2561{
2562 return mExtensionStrings.size();
2563}
2564
Geoff Langc339c4e2016-11-29 10:37:36 -05002565void Context::requestExtension(const char *name)
2566{
2567 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2568 ASSERT(extensionInfos.find(name) != extensionInfos.end());
2569 const auto &extension = extensionInfos.at(name);
2570 ASSERT(extension.Requestable);
2571
2572 if (mExtensions.*(extension.ExtensionsMember))
2573 {
2574 // Extension already enabled
2575 return;
2576 }
2577
2578 mExtensions.*(extension.ExtensionsMember) = true;
2579 updateCaps();
2580 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08002581
2582 // Re-create the compiler with the requested extensions enabled.
2583 SafeDelete(mCompiler);
2584 mCompiler = new Compiler(mImplementation.get(), mState);
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 {
4102 return gl::OutOfMemory() << "Failed to allocate internal buffer.";
4103 }
4104 return gl::NoError();
4105}
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
Jamie Madillc1d770e2017-04-13 17:31:24 -04004117GLenum Context::checkFramebufferStatus(GLenum target)
4118{
4119 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4120 ASSERT(framebuffer);
4121
4122 return framebuffer->checkStatus(this);
4123}
4124
4125void Context::compileShader(GLuint shader)
4126{
4127 Shader *shaderObject = GetValidShader(this, shader);
4128 if (!shaderObject)
4129 {
4130 return;
4131 }
4132 shaderObject->compile(this);
4133}
4134
4135void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
4136{
4137 for (int i = 0; i < n; i++)
4138 {
4139 deleteBuffer(buffers[i]);
4140 }
4141}
4142
4143void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
4144{
4145 for (int i = 0; i < n; i++)
4146 {
4147 if (framebuffers[i] != 0)
4148 {
4149 deleteFramebuffer(framebuffers[i]);
4150 }
4151 }
4152}
4153
4154void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
4155{
4156 for (int i = 0; i < n; i++)
4157 {
4158 deleteRenderbuffer(renderbuffers[i]);
4159 }
4160}
4161
4162void Context::deleteTextures(GLsizei n, const GLuint *textures)
4163{
4164 for (int i = 0; i < n; i++)
4165 {
4166 if (textures[i] != 0)
4167 {
4168 deleteTexture(textures[i]);
4169 }
4170 }
4171}
4172
4173void Context::detachShader(GLuint program, GLuint shader)
4174{
4175 Program *programObject = getProgram(program);
4176 ASSERT(programObject);
4177
4178 Shader *shaderObject = getShader(shader);
4179 ASSERT(shaderObject);
4180
4181 programObject->detachShader(this, shaderObject);
4182}
4183
4184void Context::genBuffers(GLsizei n, GLuint *buffers)
4185{
4186 for (int i = 0; i < n; i++)
4187 {
4188 buffers[i] = createBuffer();
4189 }
4190}
4191
4192void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
4193{
4194 for (int i = 0; i < n; i++)
4195 {
4196 framebuffers[i] = createFramebuffer();
4197 }
4198}
4199
4200void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
4201{
4202 for (int i = 0; i < n; i++)
4203 {
4204 renderbuffers[i] = createRenderbuffer();
4205 }
4206}
4207
4208void Context::genTextures(GLsizei n, GLuint *textures)
4209{
4210 for (int i = 0; i < n; i++)
4211 {
4212 textures[i] = createTexture();
4213 }
4214}
4215
4216void Context::getActiveAttrib(GLuint program,
4217 GLuint index,
4218 GLsizei bufsize,
4219 GLsizei *length,
4220 GLint *size,
4221 GLenum *type,
4222 GLchar *name)
4223{
4224 Program *programObject = getProgram(program);
4225 ASSERT(programObject);
4226 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
4227}
4228
4229void Context::getActiveUniform(GLuint program,
4230 GLuint index,
4231 GLsizei bufsize,
4232 GLsizei *length,
4233 GLint *size,
4234 GLenum *type,
4235 GLchar *name)
4236{
4237 Program *programObject = getProgram(program);
4238 ASSERT(programObject);
4239 programObject->getActiveUniform(index, bufsize, length, size, type, name);
4240}
4241
4242void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
4243{
4244 Program *programObject = getProgram(program);
4245 ASSERT(programObject);
4246 programObject->getAttachedShaders(maxcount, count, shaders);
4247}
4248
4249GLint Context::getAttribLocation(GLuint program, const GLchar *name)
4250{
4251 Program *programObject = getProgram(program);
4252 ASSERT(programObject);
4253 return programObject->getAttributeLocation(name);
4254}
4255
4256void Context::getBooleanv(GLenum pname, GLboolean *params)
4257{
4258 GLenum nativeType;
4259 unsigned int numParams = 0;
4260 getQueryParameterInfo(pname, &nativeType, &numParams);
4261
4262 if (nativeType == GL_BOOL)
4263 {
4264 getBooleanvImpl(pname, params);
4265 }
4266 else
4267 {
4268 CastStateValues(this, nativeType, pname, numParams, params);
4269 }
4270}
4271
4272void Context::getFloatv(GLenum pname, GLfloat *params)
4273{
4274 GLenum nativeType;
4275 unsigned int numParams = 0;
4276 getQueryParameterInfo(pname, &nativeType, &numParams);
4277
4278 if (nativeType == GL_FLOAT)
4279 {
4280 getFloatvImpl(pname, params);
4281 }
4282 else
4283 {
4284 CastStateValues(this, nativeType, pname, numParams, params);
4285 }
4286}
4287
4288void Context::getIntegerv(GLenum pname, GLint *params)
4289{
4290 GLenum nativeType;
4291 unsigned int numParams = 0;
4292 getQueryParameterInfo(pname, &nativeType, &numParams);
4293
4294 if (nativeType == GL_INT)
4295 {
4296 getIntegervImpl(pname, params);
4297 }
4298 else
4299 {
4300 CastStateValues(this, nativeType, pname, numParams, params);
4301 }
4302}
4303
4304void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
4305{
4306 Program *programObject = getProgram(program);
4307 ASSERT(programObject);
4308 QueryProgramiv(programObject, pname, params);
4309}
4310
Jamie Madillbe849e42017-05-02 15:49:00 -04004311void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04004312{
4313 Program *programObject = getProgram(program);
4314 ASSERT(programObject);
4315 programObject->getInfoLog(bufsize, length, infolog);
4316}
4317
4318void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
4319{
4320 Shader *shaderObject = getShader(shader);
4321 ASSERT(shaderObject);
4322 QueryShaderiv(shaderObject, pname, params);
4323}
4324
4325void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
4326{
4327 Shader *shaderObject = getShader(shader);
4328 ASSERT(shaderObject);
4329 shaderObject->getInfoLog(bufsize, length, infolog);
4330}
4331
4332void Context::getShaderPrecisionFormat(GLenum shadertype,
4333 GLenum precisiontype,
4334 GLint *range,
4335 GLint *precision)
4336{
4337 // TODO(jmadill): Compute shaders.
4338
4339 switch (shadertype)
4340 {
4341 case GL_VERTEX_SHADER:
4342 switch (precisiontype)
4343 {
4344 case GL_LOW_FLOAT:
4345 mCaps.vertexLowpFloat.get(range, precision);
4346 break;
4347 case GL_MEDIUM_FLOAT:
4348 mCaps.vertexMediumpFloat.get(range, precision);
4349 break;
4350 case GL_HIGH_FLOAT:
4351 mCaps.vertexHighpFloat.get(range, precision);
4352 break;
4353
4354 case GL_LOW_INT:
4355 mCaps.vertexLowpInt.get(range, precision);
4356 break;
4357 case GL_MEDIUM_INT:
4358 mCaps.vertexMediumpInt.get(range, precision);
4359 break;
4360 case GL_HIGH_INT:
4361 mCaps.vertexHighpInt.get(range, precision);
4362 break;
4363
4364 default:
4365 UNREACHABLE();
4366 return;
4367 }
4368 break;
4369
4370 case GL_FRAGMENT_SHADER:
4371 switch (precisiontype)
4372 {
4373 case GL_LOW_FLOAT:
4374 mCaps.fragmentLowpFloat.get(range, precision);
4375 break;
4376 case GL_MEDIUM_FLOAT:
4377 mCaps.fragmentMediumpFloat.get(range, precision);
4378 break;
4379 case GL_HIGH_FLOAT:
4380 mCaps.fragmentHighpFloat.get(range, precision);
4381 break;
4382
4383 case GL_LOW_INT:
4384 mCaps.fragmentLowpInt.get(range, precision);
4385 break;
4386 case GL_MEDIUM_INT:
4387 mCaps.fragmentMediumpInt.get(range, precision);
4388 break;
4389 case GL_HIGH_INT:
4390 mCaps.fragmentHighpInt.get(range, precision);
4391 break;
4392
4393 default:
4394 UNREACHABLE();
4395 return;
4396 }
4397 break;
4398
4399 default:
4400 UNREACHABLE();
4401 return;
4402 }
4403}
4404
4405void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
4406{
4407 Shader *shaderObject = getShader(shader);
4408 ASSERT(shaderObject);
4409 shaderObject->getSource(bufsize, length, source);
4410}
4411
4412void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
4413{
4414 Program *programObject = getProgram(program);
4415 ASSERT(programObject);
4416 programObject->getUniformfv(location, params);
4417}
4418
4419void Context::getUniformiv(GLuint program, GLint location, GLint *params)
4420{
4421 Program *programObject = getProgram(program);
4422 ASSERT(programObject);
4423 programObject->getUniformiv(location, params);
4424}
4425
4426GLint Context::getUniformLocation(GLuint program, const GLchar *name)
4427{
4428 Program *programObject = getProgram(program);
4429 ASSERT(programObject);
4430 return programObject->getUniformLocation(name);
4431}
4432
4433GLboolean Context::isBuffer(GLuint buffer)
4434{
4435 if (buffer == 0)
4436 {
4437 return GL_FALSE;
4438 }
4439
4440 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
4441}
4442
4443GLboolean Context::isEnabled(GLenum cap)
4444{
4445 return mGLState.getEnableFeature(cap);
4446}
4447
4448GLboolean Context::isFramebuffer(GLuint framebuffer)
4449{
4450 if (framebuffer == 0)
4451 {
4452 return GL_FALSE;
4453 }
4454
4455 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
4456}
4457
4458GLboolean Context::isProgram(GLuint program)
4459{
4460 if (program == 0)
4461 {
4462 return GL_FALSE;
4463 }
4464
4465 return (getProgram(program) ? GL_TRUE : GL_FALSE);
4466}
4467
4468GLboolean Context::isRenderbuffer(GLuint renderbuffer)
4469{
4470 if (renderbuffer == 0)
4471 {
4472 return GL_FALSE;
4473 }
4474
4475 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
4476}
4477
4478GLboolean Context::isShader(GLuint shader)
4479{
4480 if (shader == 0)
4481 {
4482 return GL_FALSE;
4483 }
4484
4485 return (getShader(shader) ? GL_TRUE : GL_FALSE);
4486}
4487
4488GLboolean Context::isTexture(GLuint texture)
4489{
4490 if (texture == 0)
4491 {
4492 return GL_FALSE;
4493 }
4494
4495 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
4496}
4497
4498void Context::linkProgram(GLuint program)
4499{
4500 Program *programObject = getProgram(program);
4501 ASSERT(programObject);
4502 handleError(programObject->link(this));
4503}
4504
4505void Context::releaseShaderCompiler()
4506{
4507 handleError(mCompiler->release());
4508}
4509
4510void Context::shaderBinary(GLsizei n,
4511 const GLuint *shaders,
4512 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04004513 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04004514 GLsizei length)
4515{
4516 // No binary shader formats are supported.
4517 UNIMPLEMENTED();
4518}
4519
4520void Context::shaderSource(GLuint shader,
4521 GLsizei count,
4522 const GLchar *const *string,
4523 const GLint *length)
4524{
4525 Shader *shaderObject = getShader(shader);
4526 ASSERT(shaderObject);
4527 shaderObject->setSource(count, string, length);
4528}
4529
4530void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
4531{
4532 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
4533}
4534
4535void Context::stencilMask(GLuint mask)
4536{
4537 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
4538}
4539
4540void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
4541{
4542 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
4543}
4544
4545void Context::uniform1f(GLint location, GLfloat x)
4546{
4547 Program *program = mGLState.getProgram();
4548 program->setUniform1fv(location, 1, &x);
4549}
4550
4551void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
4552{
4553 Program *program = mGLState.getProgram();
4554 program->setUniform1fv(location, count, v);
4555}
4556
4557void Context::uniform1i(GLint location, GLint x)
4558{
4559 Program *program = mGLState.getProgram();
4560 program->setUniform1iv(location, 1, &x);
4561}
4562
4563void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
4564{
4565 Program *program = mGLState.getProgram();
4566 program->setUniform1iv(location, count, v);
4567}
4568
4569void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
4570{
4571 GLfloat xy[2] = {x, y};
4572 Program *program = mGLState.getProgram();
4573 program->setUniform2fv(location, 1, xy);
4574}
4575
4576void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
4577{
4578 Program *program = mGLState.getProgram();
4579 program->setUniform2fv(location, count, v);
4580}
4581
4582void Context::uniform2i(GLint location, GLint x, GLint y)
4583{
4584 GLint xy[2] = {x, y};
4585 Program *program = mGLState.getProgram();
4586 program->setUniform2iv(location, 1, xy);
4587}
4588
4589void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
4590{
4591 Program *program = mGLState.getProgram();
4592 program->setUniform2iv(location, count, v);
4593}
4594
4595void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
4596{
4597 GLfloat xyz[3] = {x, y, z};
4598 Program *program = mGLState.getProgram();
4599 program->setUniform3fv(location, 1, xyz);
4600}
4601
4602void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
4603{
4604 Program *program = mGLState.getProgram();
4605 program->setUniform3fv(location, count, v);
4606}
4607
4608void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
4609{
4610 GLint xyz[3] = {x, y, z};
4611 Program *program = mGLState.getProgram();
4612 program->setUniform3iv(location, 1, xyz);
4613}
4614
4615void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
4616{
4617 Program *program = mGLState.getProgram();
4618 program->setUniform3iv(location, count, v);
4619}
4620
4621void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4622{
4623 GLfloat xyzw[4] = {x, y, z, w};
4624 Program *program = mGLState.getProgram();
4625 program->setUniform4fv(location, 1, xyzw);
4626}
4627
4628void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
4629{
4630 Program *program = mGLState.getProgram();
4631 program->setUniform4fv(location, count, v);
4632}
4633
4634void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
4635{
4636 GLint xyzw[4] = {x, y, z, w};
4637 Program *program = mGLState.getProgram();
4638 program->setUniform4iv(location, 1, xyzw);
4639}
4640
4641void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
4642{
4643 Program *program = mGLState.getProgram();
4644 program->setUniform4iv(location, count, v);
4645}
4646
4647void Context::uniformMatrix2fv(GLint location,
4648 GLsizei count,
4649 GLboolean transpose,
4650 const GLfloat *value)
4651{
4652 Program *program = mGLState.getProgram();
4653 program->setUniformMatrix2fv(location, count, transpose, value);
4654}
4655
4656void Context::uniformMatrix3fv(GLint location,
4657 GLsizei count,
4658 GLboolean transpose,
4659 const GLfloat *value)
4660{
4661 Program *program = mGLState.getProgram();
4662 program->setUniformMatrix3fv(location, count, transpose, value);
4663}
4664
4665void Context::uniformMatrix4fv(GLint location,
4666 GLsizei count,
4667 GLboolean transpose,
4668 const GLfloat *value)
4669{
4670 Program *program = mGLState.getProgram();
4671 program->setUniformMatrix4fv(location, count, transpose, value);
4672}
4673
4674void Context::validateProgram(GLuint program)
4675{
4676 Program *programObject = getProgram(program);
4677 ASSERT(programObject);
4678 programObject->validate(mCaps);
4679}
4680
Jamie Madillc29968b2016-01-20 11:17:23 -05004681} // namespace gl