blob: 2e7ec2981ae90cf0c5fc8163fecb12d9dd57ae4e [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
Jamie Madillb6664922017-07-25 12:55:04 -040048#define ANGLE_HANDLE_ERR(X) \
49 handleError(X); \
50 return;
51#define ANGLE_CONTEXT_TRY(EXPR) ANGLE_TRY_TEMPLATE(EXPR, ANGLE_HANDLE_ERR);
52
Ian Ewell3ffd78b2016-01-22 16:09:42 -050053template <typename T>
Geoff Lang4ddf5af2016-12-01 14:30:44 -050054std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager,
Sami Väisänend59ca052016-06-21 16:10:00 +030055 GLsizei numPaths,
56 const void *paths,
57 GLuint pathBase)
58{
59 std::vector<gl::Path *> ret;
60 ret.reserve(numPaths);
61
62 const auto *nameArray = static_cast<const T *>(paths);
63
64 for (GLsizei i = 0; i < numPaths; ++i)
65 {
66 const GLuint pathName = nameArray[i] + pathBase;
67
68 ret.push_back(resourceManager.getPath(pathName));
69 }
70
71 return ret;
72}
73
Geoff Lang4ddf5af2016-12-01 14:30:44 -050074std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager,
Sami Väisänend59ca052016-06-21 16:10:00 +030075 GLsizei numPaths,
76 GLenum pathNameType,
77 const void *paths,
78 GLuint pathBase)
79{
80 switch (pathNameType)
81 {
82 case GL_UNSIGNED_BYTE:
83 return GatherPaths<GLubyte>(resourceManager, numPaths, paths, pathBase);
84
85 case GL_BYTE:
86 return GatherPaths<GLbyte>(resourceManager, numPaths, paths, pathBase);
87
88 case GL_UNSIGNED_SHORT:
89 return GatherPaths<GLushort>(resourceManager, numPaths, paths, pathBase);
90
91 case GL_SHORT:
92 return GatherPaths<GLshort>(resourceManager, numPaths, paths, pathBase);
93
94 case GL_UNSIGNED_INT:
95 return GatherPaths<GLuint>(resourceManager, numPaths, paths, pathBase);
96
97 case GL_INT:
98 return GatherPaths<GLint>(resourceManager, numPaths, paths, pathBase);
99 }
100
101 UNREACHABLE();
102 return std::vector<gl::Path *>();
103}
104
105template <typename T>
Geoff Lang2186c382016-10-14 10:54:54 -0400106gl::Error GetQueryObjectParameter(gl::Query *query, GLenum pname, T *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500107{
Geoff Lang2186c382016-10-14 10:54:54 -0400108 ASSERT(query != nullptr);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500109
110 switch (pname)
111 {
112 case GL_QUERY_RESULT_EXT:
Geoff Lang2186c382016-10-14 10:54:54 -0400113 return query->getResult(params);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500114 case GL_QUERY_RESULT_AVAILABLE_EXT:
115 {
116 bool available;
Geoff Lang2186c382016-10-14 10:54:54 -0400117 gl::Error error = query->isResultAvailable(&available);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500118 if (!error.isError())
119 {
Geoff Lang2186c382016-10-14 10:54:54 -0400120 *params = gl::ConvertFromGLboolean<T>(available);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500121 }
122 return error;
123 }
124 default:
125 UNREACHABLE();
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500126 return gl::InternalError() << "Unreachable Error";
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500127 }
128}
129
Geoff Langf6db0982015-08-25 13:04:00 -0400130void MarkTransformFeedbackBufferUsage(gl::TransformFeedback *transformFeedback)
131{
Geoff Lang1a683462015-09-29 15:09:59 -0400132 if (transformFeedback && transformFeedback->isActive() && !transformFeedback->isPaused())
Geoff Langf6db0982015-08-25 13:04:00 -0400133 {
134 for (size_t tfBufferIndex = 0; tfBufferIndex < transformFeedback->getIndexedBufferCount();
135 tfBufferIndex++)
136 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400137 const gl::OffsetBindingPointer<gl::Buffer> &buffer =
Geoff Langf6db0982015-08-25 13:04:00 -0400138 transformFeedback->getIndexedBuffer(tfBufferIndex);
139 if (buffer.get() != nullptr)
140 {
141 buffer->onTransformFeedback();
142 }
143 }
144 }
145}
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500146
147// Attribute map queries.
Martin Radev1be913c2016-07-11 17:59:16 +0300148EGLint GetClientMajorVersion(const egl::AttributeMap &attribs)
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500149{
Ian Ewellec2c0c52016-04-05 13:46:26 -0400150 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_CLIENT_VERSION, 1));
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500151}
152
Martin Radev1be913c2016-07-11 17:59:16 +0300153EGLint GetClientMinorVersion(const egl::AttributeMap &attribs)
154{
155 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_MINOR_VERSION, 0));
156}
157
Geoff Langeb66a6e2016-10-31 13:06:12 -0400158gl::Version GetClientVersion(const egl::AttributeMap &attribs)
159{
160 return gl::Version(GetClientMajorVersion(attribs), GetClientMinorVersion(attribs));
161}
162
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500163GLenum GetResetStrategy(const egl::AttributeMap &attribs)
164{
Ian Ewellec2c0c52016-04-05 13:46:26 -0400165 EGLAttrib attrib = attribs.get(EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT,
166 EGL_NO_RESET_NOTIFICATION_EXT);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500167 switch (attrib)
168 {
169 case EGL_NO_RESET_NOTIFICATION:
170 return GL_NO_RESET_NOTIFICATION_EXT;
171 case EGL_LOSE_CONTEXT_ON_RESET:
172 return GL_LOSE_CONTEXT_ON_RESET_EXT;
173 default:
174 UNREACHABLE();
175 return GL_NONE;
176 }
177}
178
179bool GetRobustAccess(const egl::AttributeMap &attribs)
180{
Geoff Lang077f20a2016-11-01 10:08:02 -0400181 return (attribs.get(EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT, EGL_FALSE) == EGL_TRUE) ||
182 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR) !=
183 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500184}
185
186bool GetDebug(const egl::AttributeMap &attribs)
187{
Geoff Lang077f20a2016-11-01 10:08:02 -0400188 return (attribs.get(EGL_CONTEXT_OPENGL_DEBUG, EGL_FALSE) == EGL_TRUE) ||
189 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR) != 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500190}
191
192bool GetNoError(const egl::AttributeMap &attribs)
193{
194 return (attribs.get(EGL_CONTEXT_OPENGL_NO_ERROR_KHR, EGL_FALSE) == EGL_TRUE);
195}
196
Geoff Langc287ea62016-09-16 14:46:51 -0400197bool GetWebGLContext(const egl::AttributeMap &attribs)
198{
199 return (attribs.get(EGL_CONTEXT_WEBGL_COMPATIBILITY_ANGLE, EGL_FALSE) == EGL_TRUE);
200}
201
Geoff Langf41a7152016-09-19 15:11:17 -0400202bool GetBindGeneratesResource(const egl::AttributeMap &attribs)
203{
204 return (attribs.get(EGL_CONTEXT_BIND_GENERATES_RESOURCE_CHROMIUM, EGL_TRUE) == EGL_TRUE);
205}
206
Geoff Langfeb8c682017-02-13 16:07:35 -0500207bool GetClientArraysEnabled(const egl::AttributeMap &attribs)
208{
209 return (attribs.get(EGL_CONTEXT_CLIENT_ARRAYS_ENABLED_ANGLE, EGL_TRUE) == EGL_TRUE);
210}
211
Martin Radev9d901792016-07-15 15:58:58 +0300212std::string GetObjectLabelFromPointer(GLsizei length, const GLchar *label)
213{
214 std::string labelName;
215 if (label != nullptr)
216 {
217 size_t labelLength = length < 0 ? strlen(label) : length;
218 labelName = std::string(label, labelLength);
219 }
220 return labelName;
221}
222
223void GetObjectLabelBase(const std::string &objectLabel,
224 GLsizei bufSize,
225 GLsizei *length,
226 GLchar *label)
227{
228 size_t writeLength = objectLabel.length();
229 if (label != nullptr && bufSize > 0)
230 {
231 writeLength = std::min(static_cast<size_t>(bufSize) - 1, objectLabel.length());
232 std::copy(objectLabel.begin(), objectLabel.begin() + writeLength, label);
233 label[writeLength] = '\0';
234 }
235
236 if (length != nullptr)
237 {
238 *length = static_cast<GLsizei>(writeLength);
239 }
240}
241
Geoff Langf6db0982015-08-25 13:04:00 -0400242} // anonymous namespace
243
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000244namespace gl
245{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +0000246
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400247Context::Context(rx::EGLImplFactory *implFactory,
248 const egl::Config *config,
Corentin Wallez51706ea2015-08-07 14:39:22 -0400249 const Context *shareContext,
Geoff Langce02f082017-02-06 16:46:21 -0500250 TextureManager *shareTextures,
Jamie Madill32447362017-06-28 14:53:52 -0400251 MemoryProgramCache *memoryProgramCache,
Corentin Wallezc295e512017-01-27 17:47:50 -0500252 const egl::AttributeMap &attribs,
Jamie Madill948bbe52017-06-01 13:10:42 -0400253 const egl::DisplayExtensions &displayExtensions,
254 bool robustResourceInit)
Martin Radev1be913c2016-07-11 17:59:16 +0300255
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500256 : ValidationContext(shareContext,
Geoff Langce02f082017-02-06 16:46:21 -0500257 shareTextures,
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500258 GetClientVersion(attribs),
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700259 &mGLState,
Jamie Madillf25855c2015-11-03 11:06:18 -0500260 mCaps,
261 mTextureCaps,
262 mExtensions,
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500263 mLimitations,
264 GetNoError(attribs)),
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700265 mImplementation(implFactory->createContext(mState)),
Jamie Madill2f348d22017-06-05 10:50:59 -0400266 mCompiler(),
Corentin Walleze3b10e82015-05-20 11:06:25 -0400267 mConfig(config),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500268 mClientType(EGL_OPENGL_ES_API),
269 mHasBeenCurrent(false),
270 mContextLost(false),
271 mResetStatus(GL_NO_ERROR),
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700272 mContextLostForced(false),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500273 mResetStrategy(GetResetStrategy(attribs)),
274 mRobustAccess(GetRobustAccess(attribs)),
Jamie Madill61e16b42017-06-19 11:13:23 -0400275 mCurrentSurface(static_cast<egl::Surface *>(EGL_NO_SURFACE)),
276 mCurrentDisplay(static_cast<egl::Display *>(EGL_NO_DISPLAY)),
Jamie Madill4e0e6f82017-02-17 11:06:03 -0500277 mSurfacelessFramebuffer(nullptr),
Jamie Madille14951e2017-03-09 18:55:16 -0500278 mWebGLContext(GetWebGLContext(attribs)),
Jamie Madill32447362017-06-28 14:53:52 -0400279 mMemoryProgramCache(memoryProgramCache),
Jamie Madillb3f26b92017-07-19 15:07:41 -0400280 mScratchBuffer(1000u),
281 mZeroFilledBuffer(1000u)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000282{
Geoff Lang077f20a2016-11-01 10:08:02 -0400283 if (mRobustAccess)
284 {
285 UNIMPLEMENTED();
286 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000287
Jamie Madill4e0e6f82017-02-17 11:06:03 -0500288 initCaps(displayExtensions);
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700289 initWorkarounds();
Geoff Langc0b9ef42014-07-02 10:02:37 -0400290
Jamie Madill4928b7c2017-06-20 12:57:39 -0400291 mGLState.initialize(this, GetDebug(attribs), GetBindGeneratesResource(attribs),
Jamie Madillc43be722017-07-13 16:22:14 -0400292 GetClientArraysEnabled(attribs), robustResourceInit,
293 mMemoryProgramCache != nullptr);
Régis Fénéon83107972015-02-05 12:57:44 +0100294
Shannon Woods53a94a82014-06-24 15:20:36 -0400295 mFenceNVHandleAllocator.setBaseHandle(0);
Geoff Lang7dca1862013-07-30 16:30:46 -0400296
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000297 // [OpenGL ES 2.0.24] section 3.7 page 83:
298 // In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have twodimensional
299 // and cube map texture state vectors respectively associated with them.
300 // In order that access to these initial textures not be lost, they are treated as texture
301 // objects all of whose names are 0.
302
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400303 Texture *zeroTexture2D = new Texture(mImplementation.get(), 0, GL_TEXTURE_2D);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400304 mZeroTextures[GL_TEXTURE_2D].set(this, zeroTexture2D);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500305
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400306 Texture *zeroTextureCube = new Texture(mImplementation.get(), 0, GL_TEXTURE_CUBE_MAP);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400307 mZeroTextures[GL_TEXTURE_CUBE_MAP].set(this, zeroTextureCube);
Geoff Lang76b10c92014-09-05 16:28:14 -0400308
Geoff Langeb66a6e2016-10-31 13:06:12 -0400309 if (getClientVersion() >= Version(3, 0))
Geoff Lang76b10c92014-09-05 16:28:14 -0400310 {
311 // TODO: These could also be enabled via extension
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400312 Texture *zeroTexture3D = new Texture(mImplementation.get(), 0, GL_TEXTURE_3D);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400313 mZeroTextures[GL_TEXTURE_3D].set(this, zeroTexture3D);
Geoff Lang76b10c92014-09-05 16:28:14 -0400314
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400315 Texture *zeroTexture2DArray = new Texture(mImplementation.get(), 0, GL_TEXTURE_2D_ARRAY);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400316 mZeroTextures[GL_TEXTURE_2D_ARRAY].set(this, zeroTexture2DArray);
Geoff Lang76b10c92014-09-05 16:28:14 -0400317 }
Geoff Lang3b573612016-10-31 14:08:10 -0400318 if (getClientVersion() >= Version(3, 1))
319 {
320 Texture *zeroTexture2DMultisample =
321 new Texture(mImplementation.get(), 0, GL_TEXTURE_2D_MULTISAMPLE);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400322 mZeroTextures[GL_TEXTURE_2D_MULTISAMPLE].set(this, zeroTexture2DMultisample);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800323
324 bindGenericAtomicCounterBuffer(0);
325 for (unsigned int i = 0; i < mCaps.maxAtomicCounterBufferBindings; i++)
326 {
327 bindIndexedAtomicCounterBuffer(0, i, 0, 0);
328 }
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800329
330 bindGenericShaderStorageBuffer(0);
331 for (unsigned int i = 0; i < mCaps.maxShaderStorageBufferBindings; i++)
332 {
333 bindIndexedShaderStorageBuffer(0, i, 0, 0);
334 }
Geoff Lang3b573612016-10-31 14:08:10 -0400335 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000336
Ian Ewellbda75592016-04-18 17:25:54 -0400337 if (mExtensions.eglImageExternal || mExtensions.eglStreamConsumerExternal)
338 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400339 Texture *zeroTextureExternal =
340 new Texture(mImplementation.get(), 0, GL_TEXTURE_EXTERNAL_OES);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400341 mZeroTextures[GL_TEXTURE_EXTERNAL_OES].set(this, zeroTextureExternal);
Ian Ewellbda75592016-04-18 17:25:54 -0400342 }
343
Jamie Madill4928b7c2017-06-20 12:57:39 -0400344 mGLState.initializeZeroTextures(this, mZeroTextures);
Jamie Madille6382c32014-11-07 15:05:26 -0500345
Jamie Madill57a89722013-07-02 11:57:03 -0400346 bindVertexArray(0);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000347 bindArrayBuffer(0);
Jiajia Qin9d7d0b12016-11-29 16:30:31 +0800348 bindDrawIndirectBuffer(0);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000349 bindElementArrayBuffer(0);
Geoff Lang76b10c92014-09-05 16:28:14 -0400350
Jamie Madill01a80ee2016-11-07 12:06:18 -0500351 bindRenderbuffer(GL_RENDERBUFFER, 0);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000352
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +0000353 bindGenericUniformBuffer(0);
Geoff Lang4dc3af02016-11-18 14:09:27 -0500354 for (unsigned int i = 0; i < mCaps.maxUniformBufferBindings; i++)
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +0000355 {
356 bindIndexedUniformBuffer(0, i, 0, -1);
357 }
358
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000359 bindCopyReadBuffer(0);
360 bindCopyWriteBuffer(0);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +0000361 bindPixelPackBuffer(0);
362 bindPixelUnpackBuffer(0);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000363
Geoff Langeb66a6e2016-10-31 13:06:12 -0400364 if (getClientVersion() >= Version(3, 0))
Geoff Lang1a683462015-09-29 15:09:59 -0400365 {
366 // [OpenGL ES 3.0.2] section 2.14.1 pg 85:
367 // In the initial state, a default transform feedback object is bound and treated as
368 // a transform feedback object with a name of zero. That object is bound any time
369 // BindTransformFeedback is called with id of zero
Geoff Lang1a683462015-09-29 15:09:59 -0400370 bindTransformFeedback(0);
371 }
Geoff Langc8058452014-02-03 12:04:11 -0500372
Jamie Madillad9f24e2016-02-12 09:27:24 -0500373 // Initialize dirty bit masks
374 // TODO(jmadill): additional ES3 state
375 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_ALIGNMENT);
376 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_ROW_LENGTH);
377 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_IMAGE_HEIGHT);
378 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_SKIP_IMAGES);
379 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_SKIP_ROWS);
380 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_SKIP_PIXELS);
Corentin Wallezbbd663a2016-04-20 17:49:17 -0400381 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500382 // No dirty objects.
383
384 // Readpixels uses the pack state and read FBO
385 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_ALIGNMENT);
386 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_REVERSE_ROW_ORDER);
387 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_ROW_LENGTH);
388 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_SKIP_ROWS);
389 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_SKIP_PIXELS);
Corentin Wallezbbd663a2016-04-20 17:49:17 -0400390 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500391 mReadPixelsDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
392
393 mClearDirtyBits.set(State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED);
394 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
395 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR);
396 mClearDirtyBits.set(State::DIRTY_BIT_VIEWPORT);
397 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_COLOR);
398 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_DEPTH);
399 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_STENCIL);
400 mClearDirtyBits.set(State::DIRTY_BIT_COLOR_MASK);
401 mClearDirtyBits.set(State::DIRTY_BIT_DEPTH_MASK);
402 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT);
403 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_BACK);
404 mClearDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
405
406 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
407 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR);
Geoff Lang1d2c41d2016-10-19 16:14:46 -0700408 mBlitDirtyBits.set(State::DIRTY_BIT_FRAMEBUFFER_SRGB);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500409 mBlitDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
410 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
Jamie Madill437fa652016-05-03 15:13:24 -0400411
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400412 handleError(mImplementation->initialize());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000413}
414
Jamie Madill4928b7c2017-06-20 12:57:39 -0400415egl::Error Context::onDestroy(const egl::Display *display)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000416{
Corentin Wallez80b24112015-08-25 16:41:57 -0400417 for (auto fence : mFenceNVMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000418 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400419 SafeDelete(fence.second);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000420 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400421 mFenceNVMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000422
Corentin Wallez80b24112015-08-25 16:41:57 -0400423 for (auto query : mQueryMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000424 {
Geoff Langf0aa8422015-09-29 15:08:34 -0400425 if (query.second != nullptr)
426 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400427 query.second->release(this);
Geoff Langf0aa8422015-09-29 15:08:34 -0400428 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000429 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400430 mQueryMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000431
Corentin Wallez80b24112015-08-25 16:41:57 -0400432 for (auto vertexArray : mVertexArrayMap)
Jamie Madill57a89722013-07-02 11:57:03 -0400433 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400434 if (vertexArray.second)
435 {
436 vertexArray.second->onDestroy(this);
437 }
Jamie Madill57a89722013-07-02 11:57:03 -0400438 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400439 mVertexArrayMap.clear();
Jamie Madill57a89722013-07-02 11:57:03 -0400440
Corentin Wallez80b24112015-08-25 16:41:57 -0400441 for (auto transformFeedback : mTransformFeedbackMap)
Geoff Langc8058452014-02-03 12:04:11 -0500442 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500443 if (transformFeedback.second != nullptr)
444 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500445 transformFeedback.second->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500446 }
Geoff Langc8058452014-02-03 12:04:11 -0500447 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400448 mTransformFeedbackMap.clear();
Geoff Langc8058452014-02-03 12:04:11 -0500449
Jamie Madilldedd7b92014-11-05 16:30:36 -0500450 for (auto &zeroTexture : mZeroTextures)
Geoff Lang76b10c92014-09-05 16:28:14 -0400451 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400452 zeroTexture.second->onDestroy(this);
453 zeroTexture.second.set(this, nullptr);
Geoff Lang76b10c92014-09-05 16:28:14 -0400454 }
455 mZeroTextures.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000456
Corentin Wallezccab69d2017-01-27 16:57:15 -0500457 SafeDelete(mSurfacelessFramebuffer);
458
Jamie Madill4928b7c2017-06-20 12:57:39 -0400459 ANGLE_TRY(releaseSurface(display));
Jamie Madill2f348d22017-06-05 10:50:59 -0400460 releaseShaderCompiler();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500461
Jamie Madill4928b7c2017-06-20 12:57:39 -0400462 mGLState.reset(this);
463
Jamie Madill6c1f6712017-02-14 19:08:04 -0500464 mState.mBuffers->release(this);
465 mState.mShaderPrograms->release(this);
466 mState.mTextures->release(this);
467 mState.mRenderbuffers->release(this);
468 mState.mSamplers->release(this);
469 mState.mFenceSyncs->release(this);
470 mState.mPaths->release(this);
471 mState.mFramebuffers->release(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400472
473 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000474}
475
Jamie Madill70ee0f62017-02-06 16:04:20 -0500476Context::~Context()
477{
478}
479
Jamie Madill4928b7c2017-06-20 12:57:39 -0400480egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000481{
Jamie Madill61e16b42017-06-19 11:13:23 -0400482 mCurrentDisplay = display;
483
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000484 if (!mHasBeenCurrent)
485 {
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000486 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500487 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400488 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000489
Corentin Wallezc295e512017-01-27 17:47:50 -0500490 int width = 0;
491 int height = 0;
492 if (surface != nullptr)
493 {
494 width = surface->getWidth();
495 height = surface->getHeight();
496 }
497
498 mGLState.setViewportParams(0, 0, width, height);
499 mGLState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000500
501 mHasBeenCurrent = true;
502 }
503
Jamie Madill1b94d432015-08-07 13:23:23 -0400504 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700505 mGLState.setAllDirtyBits();
Jamie Madill1b94d432015-08-07 13:23:23 -0400506
Jamie Madill4928b7c2017-06-20 12:57:39 -0400507 ANGLE_TRY(releaseSurface(display));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500508
509 Framebuffer *newDefault = nullptr;
510 if (surface != nullptr)
511 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400512 ANGLE_TRY(surface->setIsCurrent(this, true));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500513 mCurrentSurface = surface;
514 newDefault = surface->getDefaultFramebuffer();
515 }
516 else
517 {
518 if (mSurfacelessFramebuffer == nullptr)
519 {
520 mSurfacelessFramebuffer = new Framebuffer(mImplementation.get());
521 }
522
523 newDefault = mSurfacelessFramebuffer;
524 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000525
Corentin Wallez37c39792015-08-20 14:19:46 -0400526 // Update default framebuffer, the binding of the previous default
527 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400528 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700529 if (mGLState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400530 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700531 mGLState.setReadFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400532 }
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700533 if (mGLState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400534 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700535 mGLState.setDrawFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400536 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500537 mState.mFramebuffers->setDefaultFramebuffer(newDefault);
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400538 }
Ian Ewell292f0052016-02-04 10:37:32 -0500539
540 // Notify the renderer of a context switch
Jamie Madill4928b7c2017-06-20 12:57:39 -0400541 mImplementation->onMakeCurrent(this);
542 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000543}
544
Jamie Madill4928b7c2017-06-20 12:57:39 -0400545egl::Error Context::releaseSurface(const egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400546{
Corentin Wallez37c39792015-08-20 14:19:46 -0400547 // Remove the default framebuffer
Corentin Wallezc295e512017-01-27 17:47:50 -0500548 Framebuffer *currentDefault = nullptr;
549 if (mCurrentSurface != nullptr)
Corentin Wallez51706ea2015-08-07 14:39:22 -0400550 {
Corentin Wallezc295e512017-01-27 17:47:50 -0500551 currentDefault = mCurrentSurface->getDefaultFramebuffer();
552 }
553 else if (mSurfacelessFramebuffer != nullptr)
554 {
555 currentDefault = mSurfacelessFramebuffer;
Corentin Wallez51706ea2015-08-07 14:39:22 -0400556 }
557
Corentin Wallezc295e512017-01-27 17:47:50 -0500558 if (mGLState.getReadFramebuffer() == currentDefault)
559 {
560 mGLState.setReadFramebufferBinding(nullptr);
561 }
562 if (mGLState.getDrawFramebuffer() == currentDefault)
563 {
564 mGLState.setDrawFramebufferBinding(nullptr);
565 }
566 mState.mFramebuffers->setDefaultFramebuffer(nullptr);
567
568 if (mCurrentSurface)
569 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400570 ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
Corentin Wallezc295e512017-01-27 17:47:50 -0500571 mCurrentSurface = nullptr;
572 }
Jamie Madill4928b7c2017-06-20 12:57:39 -0400573
574 return egl::NoError();
Jamie Madill77a72f62015-04-14 11:18:32 -0400575}
576
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000577GLuint Context::createBuffer()
578{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500579 return mState.mBuffers->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000580}
581
582GLuint Context::createProgram()
583{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500584 return mState.mShaderPrograms->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000585}
586
587GLuint Context::createShader(GLenum type)
588{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500589 return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000590}
591
592GLuint Context::createTexture()
593{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500594 return mState.mTextures->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000595}
596
597GLuint Context::createRenderbuffer()
598{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500599 return mState.mRenderbuffers->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000600}
601
Geoff Lang882033e2014-09-30 11:26:07 -0400602GLsync Context::createFenceSync()
Jamie Madillcd055f82013-07-26 11:55:15 -0400603{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500604 GLuint handle = mState.mFenceSyncs->createFenceSync(mImplementation.get());
Jamie Madillcd055f82013-07-26 11:55:15 -0400605
Cooper Partind8e62a32015-01-29 15:21:25 -0800606 return reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madillcd055f82013-07-26 11:55:15 -0400607}
608
Sami Väisänene45e53b2016-05-25 10:36:04 +0300609GLuint Context::createPaths(GLsizei range)
610{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500611 auto resultOrError = mState.mPaths->createPaths(mImplementation.get(), range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300612 if (resultOrError.isError())
613 {
614 handleError(resultOrError.getError());
615 return 0;
616 }
617 return resultOrError.getResult();
618}
619
Jamie Madill57a89722013-07-02 11:57:03 -0400620GLuint Context::createVertexArray()
621{
Jamie Madill96a483b2017-06-27 16:49:21 -0400622 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
623 mVertexArrayMap.assign(vertexArray, nullptr);
Geoff Lang36167ab2015-12-07 10:27:14 -0500624 return vertexArray;
Jamie Madill57a89722013-07-02 11:57:03 -0400625}
626
Jamie Madilldc356042013-07-19 16:36:57 -0400627GLuint Context::createSampler()
628{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500629 return mState.mSamplers->createSampler();
Jamie Madilldc356042013-07-19 16:36:57 -0400630}
631
Geoff Langc8058452014-02-03 12:04:11 -0500632GLuint Context::createTransformFeedback()
633{
Jamie Madill96a483b2017-06-27 16:49:21 -0400634 GLuint transformFeedback = mTransformFeedbackAllocator.allocate();
635 mTransformFeedbackMap.assign(transformFeedback, nullptr);
Geoff Lang36167ab2015-12-07 10:27:14 -0500636 return transformFeedback;
Geoff Langc8058452014-02-03 12:04:11 -0500637}
638
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000639// Returns an unused framebuffer name
640GLuint Context::createFramebuffer()
641{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500642 return mState.mFramebuffers->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000643}
644
Jamie Madill33dc8432013-07-26 11:55:05 -0400645GLuint Context::createFenceNV()
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000646{
Jamie Madill33dc8432013-07-26 11:55:05 -0400647 GLuint handle = mFenceNVHandleAllocator.allocate();
Jamie Madill96a483b2017-06-27 16:49:21 -0400648 mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV()));
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000649 return handle;
650}
651
652// Returns an unused query name
653GLuint Context::createQuery()
654{
655 GLuint handle = mQueryHandleAllocator.allocate();
Jamie Madill96a483b2017-06-27 16:49:21 -0400656 mQueryMap.assign(handle, nullptr);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000657 return handle;
658}
659
660void Context::deleteBuffer(GLuint buffer)
661{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500662 if (mState.mBuffers->getBuffer(buffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000663 {
664 detachBuffer(buffer);
665 }
Jamie Madill893ab082014-05-16 16:56:10 -0400666
Jamie Madill6c1f6712017-02-14 19:08:04 -0500667 mState.mBuffers->deleteObject(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000668}
669
670void Context::deleteShader(GLuint shader)
671{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500672 mState.mShaderPrograms->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000673}
674
675void Context::deleteProgram(GLuint program)
676{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500677 mState.mShaderPrograms->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000678}
679
680void Context::deleteTexture(GLuint texture)
681{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500682 if (mState.mTextures->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000683 {
684 detachTexture(texture);
685 }
686
Jamie Madill6c1f6712017-02-14 19:08:04 -0500687 mState.mTextures->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000688}
689
690void Context::deleteRenderbuffer(GLuint renderbuffer)
691{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500692 if (mState.mRenderbuffers->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000693 {
694 detachRenderbuffer(renderbuffer);
695 }
Jamie Madill893ab082014-05-16 16:56:10 -0400696
Jamie Madill6c1f6712017-02-14 19:08:04 -0500697 mState.mRenderbuffers->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000698}
699
Jamie Madillcd055f82013-07-26 11:55:15 -0400700void Context::deleteFenceSync(GLsync fenceSync)
701{
702 // The spec specifies the underlying Fence object is not deleted until all current
703 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
704 // and since our API is currently designed for being called from a single thread, we can delete
705 // the fence immediately.
Jamie Madill6c1f6712017-02-14 19:08:04 -0500706 mState.mFenceSyncs->deleteObject(this,
707 static_cast<GLuint>(reinterpret_cast<uintptr_t>(fenceSync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400708}
709
Sami Väisänene45e53b2016-05-25 10:36:04 +0300710void Context::deletePaths(GLuint first, GLsizei range)
711{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500712 mState.mPaths->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300713}
714
715bool Context::hasPathData(GLuint path) const
716{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500717 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300718 if (pathObj == nullptr)
719 return false;
720
721 return pathObj->hasPathData();
722}
723
724bool Context::hasPath(GLuint path) const
725{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500726 return mState.mPaths->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300727}
728
729void Context::setPathCommands(GLuint path,
730 GLsizei numCommands,
731 const GLubyte *commands,
732 GLsizei numCoords,
733 GLenum coordType,
734 const void *coords)
735{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500736 auto *pathObject = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300737
738 handleError(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
739}
740
741void Context::setPathParameterf(GLuint path, GLenum pname, GLfloat value)
742{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500743 auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300744
745 switch (pname)
746 {
747 case GL_PATH_STROKE_WIDTH_CHROMIUM:
748 pathObj->setStrokeWidth(value);
749 break;
750 case GL_PATH_END_CAPS_CHROMIUM:
751 pathObj->setEndCaps(static_cast<GLenum>(value));
752 break;
753 case GL_PATH_JOIN_STYLE_CHROMIUM:
754 pathObj->setJoinStyle(static_cast<GLenum>(value));
755 break;
756 case GL_PATH_MITER_LIMIT_CHROMIUM:
757 pathObj->setMiterLimit(value);
758 break;
759 case GL_PATH_STROKE_BOUND_CHROMIUM:
760 pathObj->setStrokeBound(value);
761 break;
762 default:
763 UNREACHABLE();
764 break;
765 }
766}
767
768void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value) const
769{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500770 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300771
772 switch (pname)
773 {
774 case GL_PATH_STROKE_WIDTH_CHROMIUM:
775 *value = pathObj->getStrokeWidth();
776 break;
777 case GL_PATH_END_CAPS_CHROMIUM:
778 *value = static_cast<GLfloat>(pathObj->getEndCaps());
779 break;
780 case GL_PATH_JOIN_STYLE_CHROMIUM:
781 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
782 break;
783 case GL_PATH_MITER_LIMIT_CHROMIUM:
784 *value = pathObj->getMiterLimit();
785 break;
786 case GL_PATH_STROKE_BOUND_CHROMIUM:
787 *value = pathObj->getStrokeBound();
788 break;
789 default:
790 UNREACHABLE();
791 break;
792 }
793}
794
795void Context::setPathStencilFunc(GLenum func, GLint ref, GLuint mask)
796{
797 mGLState.setPathStencilFunc(func, ref, mask);
798}
799
Jamie Madill57a89722013-07-02 11:57:03 -0400800void Context::deleteVertexArray(GLuint vertexArray)
801{
Jamie Madill96a483b2017-06-27 16:49:21 -0400802 VertexArray *vertexArrayObject = nullptr;
803 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
Geoff Lang50b3fe82015-12-08 14:49:12 +0000804 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500805 if (vertexArrayObject != nullptr)
806 {
807 detachVertexArray(vertexArray);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400808 vertexArrayObject->onDestroy(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500809 }
Geoff Lang50b3fe82015-12-08 14:49:12 +0000810
Geoff Lang36167ab2015-12-07 10:27:14 -0500811 mVertexArrayHandleAllocator.release(vertexArray);
Jamie Madill57a89722013-07-02 11:57:03 -0400812 }
813}
814
Jamie Madilldc356042013-07-19 16:36:57 -0400815void Context::deleteSampler(GLuint sampler)
816{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500817 if (mState.mSamplers->getSampler(sampler))
Jamie Madilldc356042013-07-19 16:36:57 -0400818 {
819 detachSampler(sampler);
820 }
821
Jamie Madill6c1f6712017-02-14 19:08:04 -0500822 mState.mSamplers->deleteObject(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -0400823}
824
Geoff Langc8058452014-02-03 12:04:11 -0500825void Context::deleteTransformFeedback(GLuint transformFeedback)
826{
Geoff Lang6e60d6b2017-04-12 12:59:04 -0400827 if (transformFeedback == 0)
828 {
829 return;
830 }
831
Jamie Madill96a483b2017-06-27 16:49:21 -0400832 TransformFeedback *transformFeedbackObject = nullptr;
833 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
Geoff Langc8058452014-02-03 12:04:11 -0500834 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500835 if (transformFeedbackObject != nullptr)
836 {
837 detachTransformFeedback(transformFeedback);
Jamie Madill6c1f6712017-02-14 19:08:04 -0500838 transformFeedbackObject->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500839 }
840
Geoff Lang36167ab2015-12-07 10:27:14 -0500841 mTransformFeedbackAllocator.release(transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -0500842 }
843}
844
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000845void Context::deleteFramebuffer(GLuint framebuffer)
846{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500847 if (mState.mFramebuffers->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000848 {
849 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000850 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500851
Jamie Madill6c1f6712017-02-14 19:08:04 -0500852 mState.mFramebuffers->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000853}
854
Jamie Madill33dc8432013-07-26 11:55:05 -0400855void Context::deleteFenceNV(GLuint fence)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000856{
Jamie Madill96a483b2017-06-27 16:49:21 -0400857 FenceNV *fenceObject = nullptr;
858 if (mFenceNVMap.erase(fence, &fenceObject))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000859 {
Jamie Madill96a483b2017-06-27 16:49:21 -0400860 mFenceNVHandleAllocator.release(fence);
861 delete fenceObject;
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000862 }
863}
864
865void Context::deleteQuery(GLuint query)
866{
Jamie Madill96a483b2017-06-27 16:49:21 -0400867 Query *queryObject = nullptr;
868 if (mQueryMap.erase(query, &queryObject))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000869 {
Jamie Madill96a483b2017-06-27 16:49:21 -0400870 mQueryHandleAllocator.release(query);
871 if (queryObject)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000872 {
Jamie Madill96a483b2017-06-27 16:49:21 -0400873 queryObject->release(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000874 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000875 }
876}
877
Geoff Lang70d0f492015-12-10 17:45:46 -0500878Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000879{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500880 return mState.mBuffers->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000881}
882
Jamie Madill570f7c82014-07-03 10:38:54 -0400883Texture *Context::getTexture(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000884{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500885 return mState.mTextures->getTexture(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000886}
887
Geoff Lang70d0f492015-12-10 17:45:46 -0500888Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000889{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500890 return mState.mRenderbuffers->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000891}
892
Jamie Madillcd055f82013-07-26 11:55:15 -0400893FenceSync *Context::getFenceSync(GLsync handle) const
894{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500895 return mState.mFenceSyncs->getFenceSync(
896 static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400897}
898
Jamie Madill57a89722013-07-02 11:57:03 -0400899VertexArray *Context::getVertexArray(GLuint handle) const
900{
Jamie Madill96a483b2017-06-27 16:49:21 -0400901 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -0400902}
903
Jamie Madilldc356042013-07-19 16:36:57 -0400904Sampler *Context::getSampler(GLuint handle) const
905{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500906 return mState.mSamplers->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400907}
908
Geoff Langc8058452014-02-03 12:04:11 -0500909TransformFeedback *Context::getTransformFeedback(GLuint handle) const
910{
Jamie Madill96a483b2017-06-27 16:49:21 -0400911 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -0500912}
913
Geoff Lang70d0f492015-12-10 17:45:46 -0500914LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
915{
916 switch (identifier)
917 {
918 case GL_BUFFER:
919 return getBuffer(name);
920 case GL_SHADER:
921 return getShader(name);
922 case GL_PROGRAM:
923 return getProgram(name);
924 case GL_VERTEX_ARRAY:
925 return getVertexArray(name);
926 case GL_QUERY:
927 return getQuery(name);
928 case GL_TRANSFORM_FEEDBACK:
929 return getTransformFeedback(name);
930 case GL_SAMPLER:
931 return getSampler(name);
932 case GL_TEXTURE:
933 return getTexture(name);
934 case GL_RENDERBUFFER:
935 return getRenderbuffer(name);
936 case GL_FRAMEBUFFER:
937 return getFramebuffer(name);
938 default:
939 UNREACHABLE();
940 return nullptr;
941 }
942}
943
944LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
945{
946 return getFenceSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
947}
948
Martin Radev9d901792016-07-15 15:58:58 +0300949void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
950{
951 LabeledObject *object = getLabeledObject(identifier, name);
952 ASSERT(object != nullptr);
953
954 std::string labelName = GetObjectLabelFromPointer(length, label);
955 object->setLabel(labelName);
956}
957
958void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
959{
960 LabeledObject *object = getLabeledObjectFromPtr(ptr);
961 ASSERT(object != nullptr);
962
963 std::string labelName = GetObjectLabelFromPointer(length, label);
964 object->setLabel(labelName);
965}
966
967void Context::getObjectLabel(GLenum identifier,
968 GLuint name,
969 GLsizei bufSize,
970 GLsizei *length,
971 GLchar *label) const
972{
973 LabeledObject *object = getLabeledObject(identifier, name);
974 ASSERT(object != nullptr);
975
976 const std::string &objectLabel = object->getLabel();
977 GetObjectLabelBase(objectLabel, bufSize, length, label);
978}
979
980void Context::getObjectPtrLabel(const void *ptr,
981 GLsizei bufSize,
982 GLsizei *length,
983 GLchar *label) const
984{
985 LabeledObject *object = getLabeledObjectFromPtr(ptr);
986 ASSERT(object != nullptr);
987
988 const std::string &objectLabel = object->getLabel();
989 GetObjectLabelBase(objectLabel, bufSize, length, label);
990}
991
Jamie Madilldc356042013-07-19 16:36:57 -0400992bool Context::isSampler(GLuint samplerName) const
993{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500994 return mState.mSamplers->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -0400995}
996
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500997void Context::bindArrayBuffer(GLuint bufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000998{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500999 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001000 mGLState.setArrayBufferBinding(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001001}
1002
Jiajia Qin9d7d0b12016-11-29 16:30:31 +08001003void Context::bindDrawIndirectBuffer(GLuint bufferHandle)
1004{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001005 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001006 mGLState.setDrawIndirectBufferBinding(this, buffer);
Jiajia Qin9d7d0b12016-11-29 16:30:31 +08001007}
1008
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001009void Context::bindElementArrayBuffer(GLuint bufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001010{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001011 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001012 mGLState.setElementArrayBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001013}
1014
Jamie Madilldedd7b92014-11-05 16:30:36 -05001015void Context::bindTexture(GLenum target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001016{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001017 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001018
Jamie Madilldedd7b92014-11-05 16:30:36 -05001019 if (handle == 0)
1020 {
1021 texture = mZeroTextures[target].get();
1022 }
1023 else
1024 {
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001025 texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -05001026 }
1027
1028 ASSERT(texture);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001029 mGLState.setSamplerTexture(this, target, texture);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00001030}
1031
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001032void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001033{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001034 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1035 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001036 mGLState.setReadFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001037}
1038
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001039void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001040{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001041 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1042 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001043 mGLState.setDrawFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001044}
1045
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001046void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -04001047{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001048 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001049 mGLState.setVertexArrayBinding(vertexArray);
Jamie Madill57a89722013-07-02 11:57:03 -04001050}
1051
Shao80957d92017-02-20 21:25:59 +08001052void Context::bindVertexBuffer(GLuint bindingIndex,
1053 GLuint bufferHandle,
1054 GLintptr offset,
1055 GLsizei stride)
1056{
1057 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001058 mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Shao80957d92017-02-20 21:25:59 +08001059}
1060
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001061void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -04001062{
Geoff Lang76b10c92014-09-05 16:28:14 -04001063 ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -04001064 Sampler *sampler =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001065 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001066 mGLState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04001067}
1068
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001069void Context::bindImageTexture(GLuint unit,
1070 GLuint texture,
1071 GLint level,
1072 GLboolean layered,
1073 GLint layer,
1074 GLenum access,
1075 GLenum format)
1076{
1077 Texture *tex = mState.mTextures->getTexture(texture);
1078 mGLState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
1079}
1080
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001081void Context::bindGenericUniformBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001082{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001083 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001084 mGLState.setGenericUniformBufferBinding(this, buffer);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001085}
1086
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001087void Context::bindIndexedUniformBuffer(GLuint bufferHandle,
1088 GLuint index,
1089 GLintptr offset,
1090 GLsizeiptr size)
shannon.woods%transgaming.com@gtempaccount.com34089352013-04-13 03:36:57 +00001091{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001092 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001093 mGLState.setIndexedUniformBufferBinding(this, index, buffer, offset, size);
shannon.woods%transgaming.com@gtempaccount.com34089352013-04-13 03:36:57 +00001094}
1095
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001096void Context::bindGenericTransformFeedbackBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001097{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001098 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001099 mGLState.getCurrentTransformFeedback()->bindGenericBuffer(this, buffer);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001100}
1101
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001102void Context::bindIndexedTransformFeedbackBuffer(GLuint bufferHandle,
1103 GLuint index,
1104 GLintptr offset,
1105 GLsizeiptr size)
shannon.woods%transgaming.com@gtempaccount.com34089352013-04-13 03:36:57 +00001106{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001107 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001108 mGLState.getCurrentTransformFeedback()->bindIndexedBuffer(this, index, buffer, offset, size);
shannon.woods%transgaming.com@gtempaccount.com34089352013-04-13 03:36:57 +00001109}
1110
Jiajia Qin6eafb042016-12-27 17:04:07 +08001111void Context::bindGenericAtomicCounterBuffer(GLuint bufferHandle)
1112{
1113 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001114 mGLState.setGenericAtomicCounterBufferBinding(this, buffer);
Jiajia Qin6eafb042016-12-27 17:04:07 +08001115}
1116
1117void Context::bindIndexedAtomicCounterBuffer(GLuint bufferHandle,
1118 GLuint index,
1119 GLintptr offset,
1120 GLsizeiptr size)
1121{
1122 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001123 mGLState.setIndexedAtomicCounterBufferBinding(this, index, buffer, offset, size);
Jiajia Qin6eafb042016-12-27 17:04:07 +08001124}
1125
Jiajia Qinf546e7d2017-03-27 14:12:59 +08001126void Context::bindGenericShaderStorageBuffer(GLuint bufferHandle)
1127{
1128 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001129 mGLState.setGenericShaderStorageBufferBinding(this, buffer);
Jiajia Qinf546e7d2017-03-27 14:12:59 +08001130}
1131
1132void Context::bindIndexedShaderStorageBuffer(GLuint bufferHandle,
1133 GLuint index,
1134 GLintptr offset,
1135 GLsizeiptr size)
1136{
1137 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001138 mGLState.setIndexedShaderStorageBufferBinding(this, index, buffer, offset, size);
Jiajia Qinf546e7d2017-03-27 14:12:59 +08001139}
1140
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001141void Context::bindCopyReadBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001142{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001143 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001144 mGLState.setCopyReadBufferBinding(this, buffer);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001145}
1146
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001147void Context::bindCopyWriteBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001148{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001149 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001150 mGLState.setCopyWriteBufferBinding(this, buffer);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001151}
1152
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001153void Context::bindPixelPackBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001154{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001155 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001156 mGLState.setPixelPackBufferBinding(this, buffer);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001157}
1158
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001159void Context::bindPixelUnpackBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001160{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001161 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001162 mGLState.setPixelUnpackBufferBinding(this, buffer);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001163}
1164
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001165void Context::useProgram(GLuint program)
1166{
Jamie Madill6c1f6712017-02-14 19:08:04 -05001167 mGLState.setProgram(this, getProgram(program));
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001168}
1169
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001170void Context::bindTransformFeedback(GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001171{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001172 TransformFeedback *transformFeedback =
1173 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001174 mGLState.setTransformFeedbackBinding(this, transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -05001175}
1176
Geoff Lang5aad9672014-09-08 11:10:42 -04001177Error Context::beginQuery(GLenum target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001178{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001179 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001180 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001181
Geoff Lang5aad9672014-09-08 11:10:42 -04001182 // begin query
1183 Error error = queryObject->begin();
1184 if (error.isError())
1185 {
1186 return error;
1187 }
1188
1189 // set query as active for specified target only if begin succeeded
Jamie Madill4928b7c2017-06-20 12:57:39 -04001190 mGLState.setActiveQuery(this, target, queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001191
He Yunchaoacd18982017-01-04 10:46:42 +08001192 return NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001193}
1194
Geoff Lang5aad9672014-09-08 11:10:42 -04001195Error Context::endQuery(GLenum target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001196{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001197 Query *queryObject = mGLState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001198 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001199
Geoff Lang5aad9672014-09-08 11:10:42 -04001200 gl::Error error = queryObject->end();
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001201
Geoff Lang5aad9672014-09-08 11:10:42 -04001202 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madill4928b7c2017-06-20 12:57:39 -04001203 mGLState.setActiveQuery(this, target, nullptr);
Geoff Lang5aad9672014-09-08 11:10:42 -04001204
1205 return error;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001206}
1207
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001208Error Context::queryCounter(GLuint id, GLenum target)
1209{
1210 ASSERT(target == GL_TIMESTAMP_EXT);
1211
1212 Query *queryObject = getQuery(id, true, target);
1213 ASSERT(queryObject);
1214
1215 return queryObject->queryCounter();
1216}
1217
1218void Context::getQueryiv(GLenum target, GLenum pname, GLint *params)
1219{
1220 switch (pname)
1221 {
1222 case GL_CURRENT_QUERY_EXT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001223 params[0] = mGLState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001224 break;
1225 case GL_QUERY_COUNTER_BITS_EXT:
1226 switch (target)
1227 {
1228 case GL_TIME_ELAPSED_EXT:
1229 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1230 break;
1231 case GL_TIMESTAMP_EXT:
1232 params[0] = getExtensions().queryCounterBitsTimestamp;
1233 break;
1234 default:
1235 UNREACHABLE();
1236 params[0] = 0;
1237 break;
1238 }
1239 break;
1240 default:
1241 UNREACHABLE();
1242 return;
1243 }
1244}
1245
Geoff Lang2186c382016-10-14 10:54:54 -04001246void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001247{
Geoff Lang2186c382016-10-14 10:54:54 -04001248 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001249}
1250
Geoff Lang2186c382016-10-14 10:54:54 -04001251void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001252{
Geoff Lang2186c382016-10-14 10:54:54 -04001253 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001254}
1255
Geoff Lang2186c382016-10-14 10:54:54 -04001256void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001257{
Geoff Lang2186c382016-10-14 10:54:54 -04001258 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001259}
1260
Geoff Lang2186c382016-10-14 10:54:54 -04001261void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001262{
Geoff Lang2186c382016-10-14 10:54:54 -04001263 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001264}
1265
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001266Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001267{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001268 return mState.mFramebuffers->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001269}
1270
Jamie Madill2f348d22017-06-05 10:50:59 -04001271FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001272{
Jamie Madill96a483b2017-06-27 16:49:21 -04001273 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001274}
1275
Jamie Madill2f348d22017-06-05 10:50:59 -04001276Query *Context::getQuery(GLuint handle, bool create, GLenum type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001277{
Jamie Madill96a483b2017-06-27 16:49:21 -04001278 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001279 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001280 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001281 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001282
1283 Query *query = mQueryMap.query(handle);
1284 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001285 {
Jamie Madill96a483b2017-06-27 16:49:21 -04001286 query = new Query(mImplementation->createQuery(type), handle);
1287 query->addRef();
1288 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001289 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001290 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001291}
1292
Geoff Lang70d0f492015-12-10 17:45:46 -05001293Query *Context::getQuery(GLuint handle) const
1294{
Jamie Madill96a483b2017-06-27 16:49:21 -04001295 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001296}
1297
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001298Texture *Context::getTargetTexture(GLenum target) const
1299{
Ian Ewellbda75592016-04-18 17:25:54 -04001300 ASSERT(ValidTextureTarget(this, target) || ValidTextureExternalTarget(this, target));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001301 return mGLState.getTargetTexture(target);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001302}
1303
Geoff Lang76b10c92014-09-05 16:28:14 -04001304Texture *Context::getSamplerTexture(unsigned int sampler, GLenum type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001305{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001306 return mGLState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001307}
1308
Geoff Lang492a7e42014-11-05 13:27:06 -05001309Compiler *Context::getCompiler() const
1310{
Jamie Madill2f348d22017-06-05 10:50:59 -04001311 if (mCompiler.get() == nullptr)
1312 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001313 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001314 }
1315 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001316}
1317
Jamie Madillc1d770e2017-04-13 17:31:24 -04001318void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001319{
1320 switch (pname)
1321 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001322 case GL_SHADER_COMPILER:
1323 *params = GL_TRUE;
1324 break;
1325 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1326 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1327 break;
1328 default:
1329 mGLState.getBooleanv(pname, params);
1330 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001331 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001332}
1333
Jamie Madillc1d770e2017-04-13 17:31:24 -04001334void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001335{
Shannon Woods53a94a82014-06-24 15:20:36 -04001336 // Queries about context capabilities and maximums are answered by Context.
1337 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001338 switch (pname)
1339 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001340 case GL_ALIASED_LINE_WIDTH_RANGE:
1341 params[0] = mCaps.minAliasedLineWidth;
1342 params[1] = mCaps.maxAliasedLineWidth;
1343 break;
1344 case GL_ALIASED_POINT_SIZE_RANGE:
1345 params[0] = mCaps.minAliasedPointSize;
1346 params[1] = mCaps.maxAliasedPointSize;
1347 break;
1348 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1349 ASSERT(mExtensions.textureFilterAnisotropic);
1350 *params = mExtensions.maxTextureAnisotropy;
1351 break;
1352 case GL_MAX_TEXTURE_LOD_BIAS:
1353 *params = mCaps.maxLODBias;
1354 break;
1355
1356 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1357 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1358 {
1359 ASSERT(mExtensions.pathRendering);
1360 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1361 memcpy(params, m, 16 * sizeof(GLfloat));
1362 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001363 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001364
Jamie Madill231c7f52017-04-26 13:45:37 -04001365 default:
1366 mGLState.getFloatv(pname, params);
1367 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001368 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001369}
1370
Jamie Madillc1d770e2017-04-13 17:31:24 -04001371void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001372{
Shannon Woods53a94a82014-06-24 15:20:36 -04001373 // Queries about context capabilities and maximums are answered by Context.
1374 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001375
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001376 switch (pname)
1377 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001378 case GL_MAX_VERTEX_ATTRIBS:
1379 *params = mCaps.maxVertexAttributes;
1380 break;
1381 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1382 *params = mCaps.maxVertexUniformVectors;
1383 break;
1384 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
1385 *params = mCaps.maxVertexUniformComponents;
1386 break;
1387 case GL_MAX_VARYING_VECTORS:
1388 *params = mCaps.maxVaryingVectors;
1389 break;
1390 case GL_MAX_VARYING_COMPONENTS:
1391 *params = mCaps.maxVertexOutputComponents;
1392 break;
1393 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1394 *params = mCaps.maxCombinedTextureImageUnits;
1395 break;
1396 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
1397 *params = mCaps.maxVertexTextureImageUnits;
1398 break;
1399 case GL_MAX_TEXTURE_IMAGE_UNITS:
1400 *params = mCaps.maxTextureImageUnits;
1401 break;
1402 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1403 *params = mCaps.maxFragmentUniformVectors;
1404 break;
1405 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
1406 *params = mCaps.maxFragmentUniformComponents;
1407 break;
1408 case GL_MAX_RENDERBUFFER_SIZE:
1409 *params = mCaps.maxRenderbufferSize;
1410 break;
1411 case GL_MAX_COLOR_ATTACHMENTS_EXT:
1412 *params = mCaps.maxColorAttachments;
1413 break;
1414 case GL_MAX_DRAW_BUFFERS_EXT:
1415 *params = mCaps.maxDrawBuffers;
1416 break;
1417 // case GL_FRAMEBUFFER_BINDING: // now equivalent to
1418 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
1419 case GL_SUBPIXEL_BITS:
1420 *params = 4;
1421 break;
1422 case GL_MAX_TEXTURE_SIZE:
1423 *params = mCaps.max2DTextureSize;
1424 break;
1425 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1426 *params = mCaps.maxCubeMapTextureSize;
1427 break;
1428 case GL_MAX_3D_TEXTURE_SIZE:
1429 *params = mCaps.max3DTextureSize;
1430 break;
1431 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1432 *params = mCaps.maxArrayTextureLayers;
1433 break;
1434 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1435 *params = mCaps.uniformBufferOffsetAlignment;
1436 break;
1437 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1438 *params = mCaps.maxUniformBufferBindings;
1439 break;
1440 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
1441 *params = mCaps.maxVertexUniformBlocks;
1442 break;
1443 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
1444 *params = mCaps.maxFragmentUniformBlocks;
1445 break;
1446 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1447 *params = mCaps.maxCombinedTextureImageUnits;
1448 break;
1449 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1450 *params = mCaps.maxVertexOutputComponents;
1451 break;
1452 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1453 *params = mCaps.maxFragmentInputComponents;
1454 break;
1455 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1456 *params = mCaps.minProgramTexelOffset;
1457 break;
1458 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1459 *params = mCaps.maxProgramTexelOffset;
1460 break;
1461 case GL_MAJOR_VERSION:
1462 *params = getClientVersion().major;
1463 break;
1464 case GL_MINOR_VERSION:
1465 *params = getClientVersion().minor;
1466 break;
1467 case GL_MAX_ELEMENTS_INDICES:
1468 *params = mCaps.maxElementsIndices;
1469 break;
1470 case GL_MAX_ELEMENTS_VERTICES:
1471 *params = mCaps.maxElementsVertices;
1472 break;
1473 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1474 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1475 break;
1476 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1477 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1478 break;
1479 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1480 *params = mCaps.maxTransformFeedbackSeparateComponents;
1481 break;
1482 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1483 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1484 break;
1485 case GL_MAX_SAMPLES_ANGLE:
1486 *params = mCaps.maxSamples;
1487 break;
1488 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001489 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001490 params[0] = mCaps.maxViewportWidth;
1491 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001492 }
1493 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001494 case GL_COMPRESSED_TEXTURE_FORMATS:
1495 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1496 params);
1497 break;
1498 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1499 *params = mResetStrategy;
1500 break;
1501 case GL_NUM_SHADER_BINARY_FORMATS:
1502 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1503 break;
1504 case GL_SHADER_BINARY_FORMATS:
1505 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1506 break;
1507 case GL_NUM_PROGRAM_BINARY_FORMATS:
1508 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1509 break;
1510 case GL_PROGRAM_BINARY_FORMATS:
1511 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1512 break;
1513 case GL_NUM_EXTENSIONS:
1514 *params = static_cast<GLint>(mExtensionStrings.size());
1515 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001516
Jamie Madill231c7f52017-04-26 13:45:37 -04001517 // GL_KHR_debug
1518 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1519 *params = mExtensions.maxDebugMessageLength;
1520 break;
1521 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1522 *params = mExtensions.maxDebugLoggedMessages;
1523 break;
1524 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1525 *params = mExtensions.maxDebugGroupStackDepth;
1526 break;
1527 case GL_MAX_LABEL_LENGTH:
1528 *params = mExtensions.maxLabelLength;
1529 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001530
Martin Radeve5285d22017-07-14 16:23:53 +03001531 // GL_ANGLE_multiview
1532 case GL_MAX_VIEWS_ANGLE:
1533 *params = mExtensions.maxViews;
1534 break;
1535
Jamie Madill231c7f52017-04-26 13:45:37 -04001536 // GL_EXT_disjoint_timer_query
1537 case GL_GPU_DISJOINT_EXT:
1538 *params = mImplementation->getGPUDisjoint();
1539 break;
1540 case GL_MAX_FRAMEBUFFER_WIDTH:
1541 *params = mCaps.maxFramebufferWidth;
1542 break;
1543 case GL_MAX_FRAMEBUFFER_HEIGHT:
1544 *params = mCaps.maxFramebufferHeight;
1545 break;
1546 case GL_MAX_FRAMEBUFFER_SAMPLES:
1547 *params = mCaps.maxFramebufferSamples;
1548 break;
1549 case GL_MAX_SAMPLE_MASK_WORDS:
1550 *params = mCaps.maxSampleMaskWords;
1551 break;
1552 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1553 *params = mCaps.maxColorTextureSamples;
1554 break;
1555 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1556 *params = mCaps.maxDepthTextureSamples;
1557 break;
1558 case GL_MAX_INTEGER_SAMPLES:
1559 *params = mCaps.maxIntegerSamples;
1560 break;
1561 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1562 *params = mCaps.maxVertexAttribRelativeOffset;
1563 break;
1564 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1565 *params = mCaps.maxVertexAttribBindings;
1566 break;
1567 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1568 *params = mCaps.maxVertexAttribStride;
1569 break;
1570 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
1571 *params = mCaps.maxVertexAtomicCounterBuffers;
1572 break;
1573 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
1574 *params = mCaps.maxVertexAtomicCounters;
1575 break;
1576 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
1577 *params = mCaps.maxVertexImageUniforms;
1578 break;
1579 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
1580 *params = mCaps.maxVertexShaderStorageBlocks;
1581 break;
1582 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
1583 *params = mCaps.maxFragmentAtomicCounterBuffers;
1584 break;
1585 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
1586 *params = mCaps.maxFragmentAtomicCounters;
1587 break;
1588 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
1589 *params = mCaps.maxFragmentImageUniforms;
1590 break;
1591 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
1592 *params = mCaps.maxFragmentShaderStorageBlocks;
1593 break;
1594 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1595 *params = mCaps.minProgramTextureGatherOffset;
1596 break;
1597 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1598 *params = mCaps.maxProgramTextureGatherOffset;
1599 break;
1600 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1601 *params = mCaps.maxComputeWorkGroupInvocations;
1602 break;
1603 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
1604 *params = mCaps.maxComputeUniformBlocks;
1605 break;
1606 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
1607 *params = mCaps.maxComputeTextureImageUnits;
1608 break;
1609 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1610 *params = mCaps.maxComputeSharedMemorySize;
1611 break;
1612 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
1613 *params = mCaps.maxComputeUniformComponents;
1614 break;
1615 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
1616 *params = mCaps.maxComputeAtomicCounterBuffers;
1617 break;
1618 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
1619 *params = mCaps.maxComputeAtomicCounters;
1620 break;
1621 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
1622 *params = mCaps.maxComputeImageUniforms;
1623 break;
1624 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
1625 *params = mCaps.maxCombinedComputeUniformComponents;
1626 break;
1627 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
1628 *params = mCaps.maxComputeShaderStorageBlocks;
1629 break;
1630 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1631 *params = mCaps.maxCombinedShaderOutputResources;
1632 break;
1633 case GL_MAX_UNIFORM_LOCATIONS:
1634 *params = mCaps.maxUniformLocations;
1635 break;
1636 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1637 *params = mCaps.maxAtomicCounterBufferBindings;
1638 break;
1639 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1640 *params = mCaps.maxAtomicCounterBufferSize;
1641 break;
1642 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1643 *params = mCaps.maxCombinedAtomicCounterBuffers;
1644 break;
1645 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1646 *params = mCaps.maxCombinedAtomicCounters;
1647 break;
1648 case GL_MAX_IMAGE_UNITS:
1649 *params = mCaps.maxImageUnits;
1650 break;
1651 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1652 *params = mCaps.maxCombinedImageUniforms;
1653 break;
1654 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1655 *params = mCaps.maxShaderStorageBufferBindings;
1656 break;
1657 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1658 *params = mCaps.maxCombinedShaderStorageBlocks;
1659 break;
1660 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1661 *params = mCaps.shaderStorageBufferOffsetAlignment;
1662 break;
1663 default:
1664 mGLState.getIntegerv(this, pname, params);
1665 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001666 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001667}
1668
Jamie Madill893ab082014-05-16 16:56:10 -04001669void Context::getInteger64v(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001670{
Shannon Woods53a94a82014-06-24 15:20:36 -04001671 // Queries about context capabilities and maximums are answered by Context.
1672 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001673 switch (pname)
1674 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001675 case GL_MAX_ELEMENT_INDEX:
1676 *params = mCaps.maxElementIndex;
1677 break;
1678 case GL_MAX_UNIFORM_BLOCK_SIZE:
1679 *params = mCaps.maxUniformBlockSize;
1680 break;
1681 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
1682 *params = mCaps.maxCombinedVertexUniformComponents;
1683 break;
1684 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
1685 *params = mCaps.maxCombinedFragmentUniformComponents;
1686 break;
1687 case GL_MAX_SERVER_WAIT_TIMEOUT:
1688 *params = mCaps.maxServerWaitTimeout;
1689 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001690
Jamie Madill231c7f52017-04-26 13:45:37 -04001691 // GL_EXT_disjoint_timer_query
1692 case GL_TIMESTAMP_EXT:
1693 *params = mImplementation->getTimestamp();
1694 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001695
Jamie Madill231c7f52017-04-26 13:45:37 -04001696 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1697 *params = mCaps.maxShaderStorageBlockSize;
1698 break;
1699 default:
1700 UNREACHABLE();
1701 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001702 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001703}
1704
Geoff Lang70d0f492015-12-10 17:45:46 -05001705void Context::getPointerv(GLenum pname, void **params) const
1706{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001707 mGLState.getPointerv(pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001708}
1709
Martin Radev66fb8202016-07-28 11:45:20 +03001710void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001711{
Shannon Woods53a94a82014-06-24 15:20:36 -04001712 // Queries about context capabilities and maximums are answered by Context.
1713 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001714
1715 GLenum nativeType;
1716 unsigned int numParams;
1717 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1718 ASSERT(queryStatus);
1719
1720 if (nativeType == GL_INT)
1721 {
1722 switch (target)
1723 {
1724 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1725 ASSERT(index < 3u);
1726 *data = mCaps.maxComputeWorkGroupCount[index];
1727 break;
1728 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1729 ASSERT(index < 3u);
1730 *data = mCaps.maxComputeWorkGroupSize[index];
1731 break;
1732 default:
1733 mGLState.getIntegeri_v(target, index, data);
1734 }
1735 }
1736 else
1737 {
1738 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1739 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001740}
1741
Martin Radev66fb8202016-07-28 11:45:20 +03001742void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001743{
Shannon Woods53a94a82014-06-24 15:20:36 -04001744 // Queries about context capabilities and maximums are answered by Context.
1745 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001746
1747 GLenum nativeType;
1748 unsigned int numParams;
1749 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1750 ASSERT(queryStatus);
1751
1752 if (nativeType == GL_INT_64_ANGLEX)
1753 {
1754 mGLState.getInteger64i_v(target, index, data);
1755 }
1756 else
1757 {
1758 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1759 }
1760}
1761
1762void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1763{
1764 // Queries about context capabilities and maximums are answered by Context.
1765 // Queries about current GL state values are answered by State.
1766
1767 GLenum nativeType;
1768 unsigned int numParams;
1769 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1770 ASSERT(queryStatus);
1771
1772 if (nativeType == GL_BOOL)
1773 {
1774 mGLState.getBooleani_v(target, index, data);
1775 }
1776 else
1777 {
1778 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1779 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001780}
1781
He Yunchao010e4db2017-03-03 14:22:06 +08001782void Context::getBufferParameteriv(GLenum target, GLenum pname, GLint *params)
1783{
1784 Buffer *buffer = mGLState.getTargetBuffer(target);
1785 QueryBufferParameteriv(buffer, pname, params);
1786}
1787
1788void Context::getFramebufferAttachmentParameteriv(GLenum target,
1789 GLenum attachment,
1790 GLenum pname,
1791 GLint *params)
1792{
1793 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
1794 QueryFramebufferAttachmentParameteriv(framebuffer, attachment, pname, params);
1795}
1796
1797void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
1798{
1799 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
1800 QueryRenderbufferiv(this, renderbuffer, pname, params);
1801}
1802
1803void Context::getTexParameterfv(GLenum target, GLenum pname, GLfloat *params)
1804{
1805 Texture *texture = getTargetTexture(target);
1806 QueryTexParameterfv(texture, pname, params);
1807}
1808
1809void Context::getTexParameteriv(GLenum target, GLenum pname, GLint *params)
1810{
1811 Texture *texture = getTargetTexture(target);
1812 QueryTexParameteriv(texture, pname, params);
1813}
1814void Context::texParameterf(GLenum target, GLenum pname, GLfloat param)
1815{
1816 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001817 SetTexParameterf(this, texture, pname, param);
He Yunchao010e4db2017-03-03 14:22:06 +08001818}
1819
1820void Context::texParameterfv(GLenum target, GLenum pname, const GLfloat *params)
1821{
1822 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001823 SetTexParameterfv(this, texture, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08001824}
1825
1826void Context::texParameteri(GLenum target, GLenum pname, GLint param)
1827{
1828 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001829 SetTexParameteri(this, texture, pname, param);
He Yunchao010e4db2017-03-03 14:22:06 +08001830}
1831
1832void Context::texParameteriv(GLenum target, GLenum pname, const GLint *params)
1833{
1834 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001835 SetTexParameteriv(this, texture, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08001836}
1837
Jamie Madill675fe712016-12-19 13:07:54 -05001838void Context::drawArrays(GLenum mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001839{
Jamie Madill4c19a8a2017-07-24 11:46:06 -04001840 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04001841 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
1842 MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001843}
1844
Jamie Madill675fe712016-12-19 13:07:54 -05001845void Context::drawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04001846{
Jamie Madill4c19a8a2017-07-24 11:46:06 -04001847 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04001848 ANGLE_CONTEXT_TRY(
1849 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
1850 MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback());
Geoff Langf6db0982015-08-25 13:04:00 -04001851}
1852
Jamie Madill876429b2017-04-20 15:46:24 -04001853void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001854{
Jamie Madill4c19a8a2017-07-24 11:46:06 -04001855 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04001856 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04001857}
1858
Jamie Madill675fe712016-12-19 13:07:54 -05001859void Context::drawElementsInstanced(GLenum mode,
1860 GLsizei count,
1861 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04001862 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04001863 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04001864{
Jamie Madill4c19a8a2017-07-24 11:46:06 -04001865 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04001866 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08001867 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04001868}
1869
Jamie Madill675fe712016-12-19 13:07:54 -05001870void Context::drawRangeElements(GLenum mode,
1871 GLuint start,
1872 GLuint end,
1873 GLsizei count,
1874 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04001875 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04001876{
Jamie Madill4c19a8a2017-07-24 11:46:06 -04001877 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04001878 ANGLE_CONTEXT_TRY(
1879 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001880}
1881
Jamie Madill876429b2017-04-20 15:46:24 -04001882void Context::drawArraysIndirect(GLenum mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08001883{
Jamie Madill4c19a8a2017-07-24 11:46:06 -04001884 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04001885 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08001886}
1887
Jamie Madill876429b2017-04-20 15:46:24 -04001888void Context::drawElementsIndirect(GLenum mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08001889{
Jamie Madill4c19a8a2017-07-24 11:46:06 -04001890 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04001891 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08001892}
1893
Jamie Madill675fe712016-12-19 13:07:54 -05001894void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001895{
Jamie Madill675fe712016-12-19 13:07:54 -05001896 handleError(mImplementation->flush());
Geoff Lang129753a2015-01-09 16:52:09 -05001897}
1898
Jamie Madill675fe712016-12-19 13:07:54 -05001899void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05001900{
Jamie Madill675fe712016-12-19 13:07:54 -05001901 handleError(mImplementation->finish());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001902}
1903
Austin Kinross6ee1e782015-05-29 17:05:37 -07001904void Context::insertEventMarker(GLsizei length, const char *marker)
1905{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001906 ASSERT(mImplementation);
1907 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07001908}
1909
1910void Context::pushGroupMarker(GLsizei length, const char *marker)
1911{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001912 ASSERT(mImplementation);
1913 mImplementation->pushGroupMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07001914}
1915
1916void Context::popGroupMarker()
1917{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001918 ASSERT(mImplementation);
1919 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07001920}
1921
Geoff Langd8605522016-04-13 10:19:12 -04001922void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
1923{
1924 Program *programObject = getProgram(program);
1925 ASSERT(programObject);
1926
1927 programObject->bindUniformLocation(location, name);
1928}
1929
Sami Väisänena797e062016-05-12 15:23:40 +03001930void Context::setCoverageModulation(GLenum components)
1931{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001932 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03001933}
1934
Sami Väisänene45e53b2016-05-25 10:36:04 +03001935void Context::loadPathRenderingMatrix(GLenum matrixMode, const GLfloat *matrix)
1936{
1937 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
1938}
1939
1940void Context::loadPathRenderingIdentityMatrix(GLenum matrixMode)
1941{
1942 GLfloat I[16];
1943 angle::Matrix<GLfloat>::setToIdentity(I);
1944
1945 mGLState.loadPathRenderingMatrix(matrixMode, I);
1946}
1947
1948void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
1949{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001950 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001951 if (!pathObj)
1952 return;
1953
1954 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1955 syncRendererState();
1956
1957 mImplementation->stencilFillPath(pathObj, fillMode, mask);
1958}
1959
1960void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
1961{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001962 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001963 if (!pathObj)
1964 return;
1965
1966 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1967 syncRendererState();
1968
1969 mImplementation->stencilStrokePath(pathObj, reference, mask);
1970}
1971
1972void Context::coverFillPath(GLuint path, GLenum coverMode)
1973{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001974 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001975 if (!pathObj)
1976 return;
1977
1978 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1979 syncRendererState();
1980
1981 mImplementation->coverFillPath(pathObj, coverMode);
1982}
1983
1984void Context::coverStrokePath(GLuint path, GLenum coverMode)
1985{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001986 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001987 if (!pathObj)
1988 return;
1989
1990 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1991 syncRendererState();
1992
1993 mImplementation->coverStrokePath(pathObj, coverMode);
1994}
1995
1996void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
1997{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001998 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001999 if (!pathObj)
2000 return;
2001
2002 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2003 syncRendererState();
2004
2005 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
2006}
2007
2008void Context::stencilThenCoverStrokePath(GLuint path,
2009 GLint reference,
2010 GLuint mask,
2011 GLenum coverMode)
2012{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002013 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002014 if (!pathObj)
2015 return;
2016
2017 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2018 syncRendererState();
2019
2020 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2021}
2022
Sami Väisänend59ca052016-06-21 16:10:00 +03002023void Context::coverFillPathInstanced(GLsizei numPaths,
2024 GLenum pathNameType,
2025 const void *paths,
2026 GLuint pathBase,
2027 GLenum coverMode,
2028 GLenum transformType,
2029 const GLfloat *transformValues)
2030{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002031 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002032
2033 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2034 syncRendererState();
2035
2036 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2037}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002038
Sami Väisänend59ca052016-06-21 16:10:00 +03002039void Context::coverStrokePathInstanced(GLsizei numPaths,
2040 GLenum pathNameType,
2041 const void *paths,
2042 GLuint pathBase,
2043 GLenum coverMode,
2044 GLenum transformType,
2045 const GLfloat *transformValues)
2046{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002047 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002048
2049 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2050 syncRendererState();
2051
2052 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2053 transformValues);
2054}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002055
Sami Väisänend59ca052016-06-21 16:10:00 +03002056void Context::stencilFillPathInstanced(GLsizei numPaths,
2057 GLenum pathNameType,
2058 const void *paths,
2059 GLuint pathBase,
2060 GLenum fillMode,
2061 GLuint mask,
2062 GLenum transformType,
2063 const GLfloat *transformValues)
2064{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002065 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002066
2067 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2068 syncRendererState();
2069
2070 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2071 transformValues);
2072}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002073
Sami Väisänend59ca052016-06-21 16:10:00 +03002074void Context::stencilStrokePathInstanced(GLsizei numPaths,
2075 GLenum pathNameType,
2076 const void *paths,
2077 GLuint pathBase,
2078 GLint reference,
2079 GLuint mask,
2080 GLenum transformType,
2081 const GLfloat *transformValues)
2082{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002083 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002084
2085 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2086 syncRendererState();
2087
2088 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2089 transformValues);
2090}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002091
Sami Väisänend59ca052016-06-21 16:10:00 +03002092void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2093 GLenum pathNameType,
2094 const void *paths,
2095 GLuint pathBase,
2096 GLenum fillMode,
2097 GLuint mask,
2098 GLenum coverMode,
2099 GLenum transformType,
2100 const GLfloat *transformValues)
2101{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002102 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002103
2104 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2105 syncRendererState();
2106
2107 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2108 transformType, transformValues);
2109}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002110
Sami Väisänend59ca052016-06-21 16:10:00 +03002111void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2112 GLenum pathNameType,
2113 const void *paths,
2114 GLuint pathBase,
2115 GLint reference,
2116 GLuint mask,
2117 GLenum coverMode,
2118 GLenum transformType,
2119 const GLfloat *transformValues)
2120{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002121 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002122
2123 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2124 syncRendererState();
2125
2126 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2127 transformType, transformValues);
2128}
2129
Sami Väisänen46eaa942016-06-29 10:26:37 +03002130void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2131{
2132 auto *programObject = getProgram(program);
2133
2134 programObject->bindFragmentInputLocation(location, name);
2135}
2136
2137void Context::programPathFragmentInputGen(GLuint program,
2138 GLint location,
2139 GLenum genMode,
2140 GLint components,
2141 const GLfloat *coeffs)
2142{
2143 auto *programObject = getProgram(program);
2144
Jamie Madillbd044ed2017-06-05 12:59:21 -04002145 programObject->pathFragmentInputGen(this, location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002146}
2147
jchen1015015f72017-03-16 13:54:21 +08002148GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2149{
jchen10fd7c3b52017-03-21 15:36:03 +08002150 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002151 return QueryProgramResourceIndex(programObject, programInterface, name);
2152}
2153
jchen10fd7c3b52017-03-21 15:36:03 +08002154void Context::getProgramResourceName(GLuint program,
2155 GLenum programInterface,
2156 GLuint index,
2157 GLsizei bufSize,
2158 GLsizei *length,
2159 GLchar *name)
2160{
2161 const auto *programObject = getProgram(program);
2162 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2163}
2164
jchen10191381f2017-04-11 13:59:04 +08002165GLint Context::getProgramResourceLocation(GLuint program,
2166 GLenum programInterface,
2167 const GLchar *name)
2168{
2169 const auto *programObject = getProgram(program);
2170 return QueryProgramResourceLocation(programObject, programInterface, name);
2171}
2172
Jamie Madill4c19a8a2017-07-24 11:46:06 -04002173Error Context::handleError(const Error &error)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002174{
Geoff Langda5777c2014-07-11 09:52:58 -04002175 if (error.isError())
2176 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002177 GLenum code = error.getCode();
2178 mErrors.insert(code);
2179 if (code == GL_OUT_OF_MEMORY && getWorkarounds().loseContextOnOutOfMemory)
2180 {
2181 markContextLost();
2182 }
Geoff Lang70d0f492015-12-10 17:45:46 -05002183
2184 if (!error.getMessage().empty())
2185 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002186 auto *debug = &mGLState.getDebug();
2187 debug->insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, error.getID(),
2188 GL_DEBUG_SEVERITY_HIGH, error.getMessage());
Geoff Lang70d0f492015-12-10 17:45:46 -05002189 }
Geoff Langda5777c2014-07-11 09:52:58 -04002190 }
Jamie Madill4c19a8a2017-07-24 11:46:06 -04002191
2192 return error;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002193}
2194
2195// Get one of the recorded errors and clear its flag, if any.
2196// [OpenGL ES 2.0.24] section 2.5 page 13.
2197GLenum Context::getError()
2198{
Geoff Langda5777c2014-07-11 09:52:58 -04002199 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002200 {
Geoff Langda5777c2014-07-11 09:52:58 -04002201 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002202 }
Geoff Langda5777c2014-07-11 09:52:58 -04002203 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002204 {
Geoff Langda5777c2014-07-11 09:52:58 -04002205 GLenum error = *mErrors.begin();
2206 mErrors.erase(mErrors.begin());
2207 return error;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002208 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002209}
2210
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002211// NOTE: this function should not assume that this context is current!
2212void Context::markContextLost()
2213{
2214 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002215 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002216 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002217 mContextLostForced = true;
2218 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002219 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002220}
2221
2222bool Context::isContextLost()
2223{
2224 return mContextLost;
2225}
2226
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002227GLenum Context::getResetStatus()
2228{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002229 // Even if the application doesn't want to know about resets, we want to know
2230 // as it will allow us to skip all the calls.
2231 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002232 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002233 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002234 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002235 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002236 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002237
2238 // EXT_robustness, section 2.6: If the reset notification behavior is
2239 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2240 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2241 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002242 }
2243
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002244 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2245 // status should be returned at least once, and GL_NO_ERROR should be returned
2246 // once the device has finished resetting.
2247 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002248 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002249 ASSERT(mResetStatus == GL_NO_ERROR);
2250 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002251
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002252 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002253 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002254 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002255 }
2256 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002257 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002258 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002259 // If markContextLost was used to mark the context lost then
2260 // assume that is not recoverable, and continue to report the
2261 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002262 mResetStatus = mImplementation->getResetStatus();
2263 }
Jamie Madill893ab082014-05-16 16:56:10 -04002264
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002265 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002266}
2267
2268bool Context::isResetNotificationEnabled()
2269{
2270 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2271}
2272
Corentin Walleze3b10e82015-05-20 11:06:25 -04002273const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002274{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002275 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002276}
2277
2278EGLenum Context::getClientType() const
2279{
2280 return mClientType;
2281}
2282
2283EGLenum Context::getRenderBuffer() const
2284{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002285 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2286 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002287 {
2288 return EGL_NONE;
2289 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002290
2291 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(GL_BACK);
2292 ASSERT(backAttachment != nullptr);
2293 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002294}
2295
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002296VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002297{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002298 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002299 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2300 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002301 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002302 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2303 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002304
Jamie Madill96a483b2017-06-27 16:49:21 -04002305 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002306 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002307
2308 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002309}
2310
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002311TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002312{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002313 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002314 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2315 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002316 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002317 transformFeedback =
2318 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002319 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002320 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002321 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002322
2323 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002324}
2325
2326bool Context::isVertexArrayGenerated(GLuint vertexArray)
2327{
Jamie Madill96a483b2017-06-27 16:49:21 -04002328 ASSERT(mVertexArrayMap.contains(0));
2329 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002330}
2331
2332bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2333{
Jamie Madill96a483b2017-06-27 16:49:21 -04002334 ASSERT(mTransformFeedbackMap.contains(0));
2335 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002336}
2337
Shannon Woods53a94a82014-06-24 15:20:36 -04002338void Context::detachTexture(GLuint texture)
2339{
2340 // Simple pass-through to State's detachTexture method, as textures do not require
2341 // allocation map management either here or in the resource manager at detach time.
2342 // Zero textures are held by the Context, and we don't attempt to request them from
2343 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002344 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002345}
2346
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002347void Context::detachBuffer(GLuint buffer)
2348{
Yuly Novikov5807a532015-12-03 13:01:22 -05002349 // Simple pass-through to State's detachBuffer method, since
2350 // only buffer attachments to container objects that are bound to the current context
2351 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002352
Yuly Novikov5807a532015-12-03 13:01:22 -05002353 // [OpenGL ES 3.2] section 5.1.2 page 45:
2354 // Attachments to unbound container objects, such as
2355 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2356 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002357 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002358}
2359
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002360void Context::detachFramebuffer(GLuint framebuffer)
2361{
Shannon Woods53a94a82014-06-24 15:20:36 -04002362 // Framebuffer detachment is handled by Context, because 0 is a valid
2363 // Framebuffer object, and a pointer to it must be passed from Context
2364 // to State at binding time.
2365
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002366 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002367 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2368 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2369 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002370
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002371 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002372 {
2373 bindReadFramebuffer(0);
2374 }
2375
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002376 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002377 {
2378 bindDrawFramebuffer(0);
2379 }
2380}
2381
2382void Context::detachRenderbuffer(GLuint renderbuffer)
2383{
Jamie Madilla02315b2017-02-23 14:14:47 -05002384 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002385}
2386
Jamie Madill57a89722013-07-02 11:57:03 -04002387void Context::detachVertexArray(GLuint vertexArray)
2388{
Jamie Madill77a72f62015-04-14 11:18:32 -04002389 // Vertex array detachment is handled by Context, because 0 is a valid
2390 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002391 // binding time.
2392
Jamie Madill57a89722013-07-02 11:57:03 -04002393 // [OpenGL ES 3.0.2] section 2.10 page 43:
2394 // If a vertex array object that is currently bound is deleted, the binding
2395 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002396 if (mGLState.removeVertexArrayBinding(vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002397 {
2398 bindVertexArray(0);
2399 }
2400}
2401
Geoff Langc8058452014-02-03 12:04:11 -05002402void Context::detachTransformFeedback(GLuint transformFeedback)
2403{
Corentin Walleza2257da2016-04-19 16:43:12 -04002404 // Transform feedback detachment is handled by Context, because 0 is a valid
2405 // transform feedback, and a pointer to it must be passed from Context to State at
2406 // binding time.
2407
2408 // The OpenGL specification doesn't mention what should happen when the currently bound
2409 // transform feedback object is deleted. Since it is a container object, we treat it like
2410 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002411 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002412 {
2413 bindTransformFeedback(0);
2414 }
Geoff Langc8058452014-02-03 12:04:11 -05002415}
2416
Jamie Madilldc356042013-07-19 16:36:57 -04002417void Context::detachSampler(GLuint sampler)
2418{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002419 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002420}
2421
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002422void Context::setVertexAttribDivisor(GLuint index, GLuint divisor)
2423{
Shaodde78e82017-05-22 14:13:27 +08002424 mGLState.setVertexAttribDivisor(this, index, divisor);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002425}
2426
Jamie Madille29d1672013-07-19 16:36:57 -04002427void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2428{
Geoff Langc1984ed2016-10-07 12:41:00 -04002429 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002430 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002431 SetSamplerParameteri(samplerObject, pname, param);
2432}
Jamie Madille29d1672013-07-19 16:36:57 -04002433
Geoff Langc1984ed2016-10-07 12:41:00 -04002434void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2435{
2436 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002437 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002438 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madille29d1672013-07-19 16:36:57 -04002439}
2440
2441void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2442{
Geoff Langc1984ed2016-10-07 12:41:00 -04002443 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002444 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002445 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madille29d1672013-07-19 16:36:57 -04002446}
2447
Geoff Langc1984ed2016-10-07 12:41:00 -04002448void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002449{
Geoff Langc1984ed2016-10-07 12:41:00 -04002450 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002451 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002452 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill9675b802013-07-19 16:36:59 -04002453}
2454
Geoff Langc1984ed2016-10-07 12:41:00 -04002455void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002456{
Geoff Langc1984ed2016-10-07 12:41:00 -04002457 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002458 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002459 QuerySamplerParameteriv(samplerObject, pname, params);
2460}
Jamie Madill9675b802013-07-19 16:36:59 -04002461
Geoff Langc1984ed2016-10-07 12:41:00 -04002462void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2463{
2464 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002465 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002466 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill9675b802013-07-19 16:36:59 -04002467}
2468
Olli Etuahof0fee072016-03-30 15:11:58 +03002469void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2470{
2471 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002472 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002473}
2474
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002475void Context::initRendererString()
2476{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002477 std::ostringstream rendererString;
2478 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002479 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002480 rendererString << ")";
2481
Geoff Langcec35902014-04-16 10:52:36 -04002482 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002483}
2484
Geoff Langc339c4e2016-11-29 10:37:36 -05002485void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002486{
Geoff Langc339c4e2016-11-29 10:37:36 -05002487 const Version &clientVersion = getClientVersion();
2488
2489 std::ostringstream versionString;
2490 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2491 << ANGLE_VERSION_STRING << ")";
2492 mVersionString = MakeStaticString(versionString.str());
2493
2494 std::ostringstream shadingLanguageVersionString;
2495 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2496 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2497 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2498 << ")";
2499 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002500}
2501
Geoff Langcec35902014-04-16 10:52:36 -04002502void Context::initExtensionStrings()
2503{
Geoff Langc339c4e2016-11-29 10:37:36 -05002504 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2505 std::ostringstream combinedStringStream;
2506 std::copy(strings.begin(), strings.end(),
2507 std::ostream_iterator<const char *>(combinedStringStream, " "));
2508 return MakeStaticString(combinedStringStream.str());
2509 };
2510
2511 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002512 for (const auto &extensionString : mExtensions.getStrings())
2513 {
2514 mExtensionStrings.push_back(MakeStaticString(extensionString));
2515 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002516 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002517
Bryan Bernhart58806562017-01-05 13:09:31 -08002518 const gl::Extensions &nativeExtensions = mImplementation->getNativeExtensions();
2519
Geoff Langc339c4e2016-11-29 10:37:36 -05002520 mRequestableExtensionStrings.clear();
2521 for (const auto &extensionInfo : GetExtensionInfoMap())
2522 {
2523 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08002524 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
2525 nativeExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002526 {
2527 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
2528 }
2529 }
2530 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002531}
2532
Geoff Langc339c4e2016-11-29 10:37:36 -05002533const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04002534{
Geoff Langc339c4e2016-11-29 10:37:36 -05002535 switch (name)
2536 {
2537 case GL_VENDOR:
2538 return reinterpret_cast<const GLubyte *>("Google Inc.");
2539
2540 case GL_RENDERER:
2541 return reinterpret_cast<const GLubyte *>(mRendererString);
2542
2543 case GL_VERSION:
2544 return reinterpret_cast<const GLubyte *>(mVersionString);
2545
2546 case GL_SHADING_LANGUAGE_VERSION:
2547 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
2548
2549 case GL_EXTENSIONS:
2550 return reinterpret_cast<const GLubyte *>(mExtensionString);
2551
2552 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2553 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
2554
2555 default:
2556 UNREACHABLE();
2557 return nullptr;
2558 }
Geoff Langcec35902014-04-16 10:52:36 -04002559}
2560
Geoff Langc339c4e2016-11-29 10:37:36 -05002561const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04002562{
Geoff Langc339c4e2016-11-29 10:37:36 -05002563 switch (name)
2564 {
2565 case GL_EXTENSIONS:
2566 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
2567
2568 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2569 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
2570
2571 default:
2572 UNREACHABLE();
2573 return nullptr;
2574 }
Geoff Langcec35902014-04-16 10:52:36 -04002575}
2576
2577size_t Context::getExtensionStringCount() const
2578{
2579 return mExtensionStrings.size();
2580}
2581
Geoff Langc339c4e2016-11-29 10:37:36 -05002582void Context::requestExtension(const char *name)
2583{
2584 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2585 ASSERT(extensionInfos.find(name) != extensionInfos.end());
2586 const auto &extension = extensionInfos.at(name);
2587 ASSERT(extension.Requestable);
2588
2589 if (mExtensions.*(extension.ExtensionsMember))
2590 {
2591 // Extension already enabled
2592 return;
2593 }
2594
2595 mExtensions.*(extension.ExtensionsMember) = true;
2596 updateCaps();
2597 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08002598
Jamie Madill2f348d22017-06-05 10:50:59 -04002599 // Release the shader compiler so it will be re-created with the requested extensions enabled.
2600 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04002601
2602 // Invalidate all cached completenesses for textures and framebuffer. Some extensions make new
2603 // formats renderable or sampleable.
2604 mState.mTextures->invalidateTextureComplenessCache();
2605 for (auto &zeroTexture : mZeroTextures)
2606 {
2607 zeroTexture.second->invalidateCompletenessCache();
2608 }
2609
2610 mState.mFramebuffers->invalidateFramebufferComplenessCache();
Geoff Langc339c4e2016-11-29 10:37:36 -05002611}
2612
2613size_t Context::getRequestableExtensionStringCount() const
2614{
2615 return mRequestableExtensionStrings.size();
2616}
2617
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002618void Context::beginTransformFeedback(GLenum primitiveMode)
2619{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002620 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002621 ASSERT(transformFeedback != nullptr);
2622 ASSERT(!transformFeedback->isPaused());
2623
Jamie Madill6c1f6712017-02-14 19:08:04 -05002624 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002625}
2626
2627bool Context::hasActiveTransformFeedback(GLuint program) const
2628{
2629 for (auto pair : mTransformFeedbackMap)
2630 {
2631 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
2632 {
2633 return true;
2634 }
2635 }
2636 return false;
2637}
2638
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002639void Context::initCaps(const egl::DisplayExtensions &displayExtensions)
Geoff Lang493daf52014-07-03 13:38:44 -04002640{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002641 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04002642
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002643 mExtensions = mImplementation->getNativeExtensions();
Geoff Lang493daf52014-07-03 13:38:44 -04002644
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002645 mLimitations = mImplementation->getNativeLimitations();
Austin Kinross02df7962015-07-01 10:03:42 -07002646
Geoff Langeb66a6e2016-10-31 13:06:12 -04002647 if (getClientVersion() < Version(3, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002648 {
2649 // Disable ES3+ extensions
Jamie Madill231c7f52017-04-26 13:45:37 -04002650 mExtensions.colorBufferFloat = false;
Geoff Langb66a9092016-05-16 15:59:14 -04002651 mExtensions.eglImageExternalEssl3 = false;
Vincent Lang25ab4512016-05-13 18:13:59 +02002652 mExtensions.textureNorm16 = false;
Martin Radev137032d2017-07-13 10:11:12 +03002653 mExtensions.multiview = false;
2654 mExtensions.maxViews = 1u;
Geoff Lang493daf52014-07-03 13:38:44 -04002655 }
2656
Geoff Langeb66a6e2016-10-31 13:06:12 -04002657 if (getClientVersion() > Version(2, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002658 {
2659 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
Jamie Madill231c7f52017-04-26 13:45:37 -04002660 // mExtensions.sRGB = false;
Geoff Lang493daf52014-07-03 13:38:44 -04002661 }
2662
Jamie Madill00ed7a12016-05-19 13:13:38 -04002663 // Some extensions are always available because they are implemented in the GL layer.
Jamie Madill231c7f52017-04-26 13:45:37 -04002664 mExtensions.bindUniformLocation = true;
2665 mExtensions.vertexArrayObject = true;
Geoff Langf41a7152016-09-19 15:11:17 -04002666 mExtensions.bindGeneratesResource = true;
Geoff Langfeb8c682017-02-13 16:07:35 -05002667 mExtensions.clientArrays = true;
Geoff Langc339c4e2016-11-29 10:37:36 -05002668 mExtensions.requestExtension = true;
Jamie Madill00ed7a12016-05-19 13:13:38 -04002669
2670 // Enable the no error extension if the context was created with the flag.
2671 mExtensions.noError = mSkipValidation;
2672
Corentin Wallezccab69d2017-01-27 16:57:15 -05002673 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Corentin Wallezc295e512017-01-27 17:47:50 -05002674 mExtensions.surfacelessContext = displayExtensions.surfacelessContext;
Corentin Wallezccab69d2017-01-27 16:57:15 -05002675
Geoff Lang70d0f492015-12-10 17:45:46 -05002676 // Explicitly enable GL_KHR_debug
2677 mExtensions.debug = true;
2678 mExtensions.maxDebugMessageLength = 1024;
2679 mExtensions.maxDebugLoggedMessages = 1024;
2680 mExtensions.maxDebugGroupStackDepth = 1024;
2681 mExtensions.maxLabelLength = 1024;
2682
Geoff Langff5b2d52016-09-07 11:32:23 -04002683 // Explicitly enable GL_ANGLE_robust_client_memory
2684 mExtensions.robustClientMemory = true;
2685
Jamie Madille08a1d32017-03-07 17:24:06 -05002686 // Determine robust resource init availability from EGL.
2687 mExtensions.robustResourceInitialization =
Jamie Madill948bbe52017-06-01 13:10:42 -04002688 egl::Display::GetClientExtensions().displayRobustResourceInitialization;
Jamie Madille08a1d32017-03-07 17:24:06 -05002689
Jamie Madillc43be722017-07-13 16:22:14 -04002690 // Enable the cache control query unconditionally.
2691 mExtensions.programCacheControl = true;
2692
Geoff Lang301d1612014-07-09 10:34:37 -04002693 // Apply implementation limits
2694 mCaps.maxVertexAttributes = std::min<GLuint>(mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002695 mCaps.maxVertexAttribBindings =
2696 getClientVersion() < ES_3_1
2697 ? mCaps.maxVertexAttributes
2698 : std::min<GLuint>(mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
2699
Jamie Madill231c7f52017-04-26 13:45:37 -04002700 mCaps.maxVertexUniformBlocks = std::min<GLuint>(
2701 mCaps.maxVertexUniformBlocks, IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
2702 mCaps.maxVertexOutputComponents =
2703 std::min<GLuint>(mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
Geoff Lang301d1612014-07-09 10:34:37 -04002704
Jamie Madill231c7f52017-04-26 13:45:37 -04002705 mCaps.maxFragmentInputComponents =
2706 std::min<GLuint>(mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
Geoff Lang3a61c322014-07-10 13:01:54 -04002707
Geoff Langc287ea62016-09-16 14:46:51 -04002708 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002709 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04002710 for (const auto &extensionInfo : GetExtensionInfoMap())
2711 {
2712 // If this context is for WebGL, disable all enableable extensions
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002713 if (mWebGLContext && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04002714 {
2715 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
2716 }
2717 }
2718
2719 // Generate texture caps
2720 updateCaps();
2721}
2722
2723void Context::updateCaps()
2724{
Geoff Lang900013c2014-07-07 11:32:19 -04002725 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002726 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04002727
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002728 for (auto capsIt : mImplementation->getNativeTextureCaps())
Geoff Lang493daf52014-07-03 13:38:44 -04002729 {
Geoff Langca271392017-04-05 12:30:00 -04002730 GLenum sizedInternalFormat = capsIt.first;
Jamie Madill231c7f52017-04-26 13:45:37 -04002731 TextureCaps formatCaps = capsIt.second;
Geoff Lang493daf52014-07-03 13:38:44 -04002732
Geoff Langca271392017-04-05 12:30:00 -04002733 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04002734
Geoff Lang0d8b7242015-09-09 14:56:53 -04002735 // Update the format caps based on the client version and extensions.
2736 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
2737 // ES3.
2738 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002739 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002740 formatCaps.renderable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002741 formatCaps.renderable && formatInfo.renderSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002742 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002743 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04002744
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002745 // OpenGL ES does not support multisampling with non-rendererable formats
2746 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Olli Etuaho50c562d2017-06-06 14:43:30 +03002747 if (!formatCaps.renderable ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002748 (getClientVersion() < ES_3_1 &&
2749 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04002750 {
Geoff Langd87878e2014-09-19 15:42:59 -04002751 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04002752 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03002753 else
2754 {
2755 // We may have limited the max samples for some required renderbuffer formats due to
2756 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
2757 GLuint formatMaxSamples = formatCaps.getMaxSamples();
2758
2759 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
2760 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
2761 // exception of signed and unsigned integer formats."
2762 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
2763 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
2764 {
2765 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
2766 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
2767 }
2768
2769 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
2770 if (getClientVersion() >= ES_3_1)
2771 {
2772 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
2773 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
2774 // the exception that the signed and unsigned integer formats are required only to
2775 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
2776 // multisamples, which must be at least one."
2777 if (formatInfo.componentType == GL_INT ||
2778 formatInfo.componentType == GL_UNSIGNED_INT)
2779 {
2780 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
2781 }
2782
2783 // GLES 3.1 section 19.3.1.
2784 if (formatCaps.texturable)
2785 {
2786 if (formatInfo.depthBits > 0)
2787 {
2788 mCaps.maxDepthTextureSamples =
2789 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
2790 }
2791 else if (formatInfo.redBits > 0)
2792 {
2793 mCaps.maxColorTextureSamples =
2794 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
2795 }
2796 }
2797 }
2798 }
Geoff Langd87878e2014-09-19 15:42:59 -04002799
2800 if (formatCaps.texturable && formatInfo.compressed)
2801 {
Geoff Langca271392017-04-05 12:30:00 -04002802 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04002803 }
2804
Geoff Langca271392017-04-05 12:30:00 -04002805 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04002806 }
Jamie Madill32447362017-06-28 14:53:52 -04002807
2808 // If program binary is disabled, blank out the memory cache pointer.
2809 if (!mImplementation->getNativeExtensions().getProgramBinary)
2810 {
2811 mMemoryProgramCache = nullptr;
2812 }
Geoff Lang493daf52014-07-03 13:38:44 -04002813}
2814
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002815void Context::initWorkarounds()
2816{
Jamie Madill761b02c2017-06-23 16:27:06 -04002817 // Apply back-end workarounds.
2818 mImplementation->applyNativeWorkarounds(&mWorkarounds);
2819
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002820 // Lose the context upon out of memory error if the application is
2821 // expecting to watch for those events.
2822 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2823}
2824
Jamie Madill4c19a8a2017-07-24 11:46:06 -04002825Error Context::prepareForDraw(GLenum drawMode)
Jamie Madillb6664922017-07-25 12:55:04 -04002826{
2827 syncRendererState();
Jamie Madill4c19a8a2017-07-24 11:46:06 -04002828
2829 InfoLog infoLog;
2830 Error err = mImplementation->triggerDrawCallProgramRecompilation(this, &infoLog,
2831 mMemoryProgramCache, drawMode);
2832 if (err.isError())
2833 {
2834 WARN() << "Dynamic recompilation error log: " << infoLog.str();
2835 }
2836 return err;
Jamie Madillb6664922017-07-25 12:55:04 -04002837}
2838
Jamie Madill1b94d432015-08-07 13:23:23 -04002839void Context::syncRendererState()
2840{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002841 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
Jamie Madillfe548342017-06-19 11:13:24 -04002842 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002843 mGLState.clearDirtyBits();
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002844 mGLState.syncDirtyObjects(this);
Jamie Madill1b94d432015-08-07 13:23:23 -04002845}
2846
Jamie Madillad9f24e2016-02-12 09:27:24 -05002847void Context::syncRendererState(const State::DirtyBits &bitMask,
2848 const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04002849{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002850 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madillfe548342017-06-19 11:13:24 -04002851 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002852 mGLState.clearDirtyBits(dirtyBits);
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002853 mGLState.syncDirtyObjects(this, objectMask);
Jamie Madill1b94d432015-08-07 13:23:23 -04002854}
Jamie Madillc29968b2016-01-20 11:17:23 -05002855
2856void Context::blitFramebuffer(GLint srcX0,
2857 GLint srcY0,
2858 GLint srcX1,
2859 GLint srcY1,
2860 GLint dstX0,
2861 GLint dstY0,
2862 GLint dstX1,
2863 GLint dstY1,
2864 GLbitfield mask,
2865 GLenum filter)
2866{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002867 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002868 ASSERT(drawFramebuffer);
2869
2870 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
2871 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
2872
Jamie Madillad9f24e2016-02-12 09:27:24 -05002873 syncStateForBlit();
Jamie Madillc29968b2016-01-20 11:17:23 -05002874
Jamie Madillc564c072017-06-01 12:45:42 -04002875 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002876}
Jamie Madillc29968b2016-01-20 11:17:23 -05002877
2878void Context::clear(GLbitfield mask)
2879{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002880 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002881 handleError(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05002882}
2883
2884void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
2885{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002886 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002887 handleError(mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002888}
2889
2890void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
2891{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002892 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002893 handleError(mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002894}
2895
2896void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
2897{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002898 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002899 handleError(mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002900}
2901
2902void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
2903{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002904 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002905 ASSERT(framebufferObject);
2906
2907 // If a buffer is not present, the clear has no effect
2908 if (framebufferObject->getDepthbuffer() == nullptr &&
2909 framebufferObject->getStencilbuffer() == nullptr)
2910 {
2911 return;
2912 }
2913
Jamie Madillad9f24e2016-02-12 09:27:24 -05002914 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002915 handleError(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05002916}
2917
2918void Context::readPixels(GLint x,
2919 GLint y,
2920 GLsizei width,
2921 GLsizei height,
2922 GLenum format,
2923 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002924 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05002925{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04002926 if (width == 0 || height == 0)
2927 {
2928 return;
2929 }
2930
Jamie Madillad9f24e2016-02-12 09:27:24 -05002931 syncStateForReadPixels();
Jamie Madillc29968b2016-01-20 11:17:23 -05002932
Jamie Madillb6664922017-07-25 12:55:04 -04002933 Framebuffer *readFBO = mGLState.getReadFramebuffer();
2934 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05002935
2936 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04002937 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05002938}
2939
2940void Context::copyTexImage2D(GLenum target,
2941 GLint level,
2942 GLenum internalformat,
2943 GLint x,
2944 GLint y,
2945 GLsizei width,
2946 GLsizei height,
2947 GLint border)
2948{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002949 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002950 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002951
Jamie Madillc29968b2016-01-20 11:17:23 -05002952 Rectangle sourceArea(x, y, width, height);
2953
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002954 const Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002955 Texture *texture =
2956 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05002957 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05002958}
2959
2960void Context::copyTexSubImage2D(GLenum target,
2961 GLint level,
2962 GLint xoffset,
2963 GLint yoffset,
2964 GLint x,
2965 GLint y,
2966 GLsizei width,
2967 GLsizei height)
2968{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04002969 if (width == 0 || height == 0)
2970 {
2971 return;
2972 }
2973
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002974 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002975 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002976
Jamie Madillc29968b2016-01-20 11:17:23 -05002977 Offset destOffset(xoffset, yoffset, 0);
2978 Rectangle sourceArea(x, y, width, height);
2979
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002980 const Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002981 Texture *texture =
2982 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05002983 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05002984}
2985
2986void Context::copyTexSubImage3D(GLenum target,
2987 GLint level,
2988 GLint xoffset,
2989 GLint yoffset,
2990 GLint zoffset,
2991 GLint x,
2992 GLint y,
2993 GLsizei width,
2994 GLsizei height)
2995{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04002996 if (width == 0 || height == 0)
2997 {
2998 return;
2999 }
3000
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003001 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003002 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003003
Jamie Madillc29968b2016-01-20 11:17:23 -05003004 Offset destOffset(xoffset, yoffset, zoffset);
3005 Rectangle sourceArea(x, y, width, height);
3006
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003007 const Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003008 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003009 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003010}
3011
3012void Context::framebufferTexture2D(GLenum target,
3013 GLenum attachment,
3014 GLenum textarget,
3015 GLuint texture,
3016 GLint level)
3017{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003018 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003019 ASSERT(framebuffer);
3020
3021 if (texture != 0)
3022 {
3023 Texture *textureObj = getTexture(texture);
3024
3025 ImageIndex index = ImageIndex::MakeInvalid();
3026
3027 if (textarget == GL_TEXTURE_2D)
3028 {
3029 index = ImageIndex::Make2D(level);
3030 }
JiangYizhoubddc46b2016-12-09 09:50:51 +08003031 else if (textarget == GL_TEXTURE_2D_MULTISAMPLE)
3032 {
3033 ASSERT(level == 0);
3034 index = ImageIndex::Make2DMultisample();
3035 }
Jamie Madillc29968b2016-01-20 11:17:23 -05003036 else
3037 {
3038 ASSERT(IsCubeMapTextureTarget(textarget));
3039 index = ImageIndex::MakeCube(textarget, level);
3040 }
3041
Jamie Madilla02315b2017-02-23 14:14:47 -05003042 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003043 }
3044 else
3045 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003046 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003047 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003048
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003049 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003050}
3051
3052void Context::framebufferRenderbuffer(GLenum target,
3053 GLenum attachment,
3054 GLenum renderbuffertarget,
3055 GLuint renderbuffer)
3056{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003057 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003058 ASSERT(framebuffer);
3059
3060 if (renderbuffer != 0)
3061 {
3062 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003063
3064 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex::MakeInvalid(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003065 renderbufferObject);
3066 }
3067 else
3068 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003069 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003070 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003071
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003072 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003073}
3074
3075void Context::framebufferTextureLayer(GLenum target,
3076 GLenum attachment,
3077 GLuint texture,
3078 GLint level,
3079 GLint layer)
3080{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003081 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003082 ASSERT(framebuffer);
3083
3084 if (texture != 0)
3085 {
3086 Texture *textureObject = getTexture(texture);
3087
3088 ImageIndex index = ImageIndex::MakeInvalid();
3089
3090 if (textureObject->getTarget() == GL_TEXTURE_3D)
3091 {
3092 index = ImageIndex::Make3D(level, layer);
3093 }
3094 else
3095 {
3096 ASSERT(textureObject->getTarget() == GL_TEXTURE_2D_ARRAY);
3097 index = ImageIndex::Make2DArray(level, layer);
3098 }
3099
Jamie Madilla02315b2017-02-23 14:14:47 -05003100 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003101 }
3102 else
3103 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003104 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003105 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003106
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003107 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003108}
3109
Martin Radev137032d2017-07-13 10:11:12 +03003110void Context::framebufferTextureMultiviewLayeredANGLE(GLenum target,
3111 GLenum attachment,
3112 GLuint texture,
3113 GLint level,
3114 GLint baseViewIndex,
3115 GLsizei numViews)
3116{
3117 UNIMPLEMENTED();
3118}
3119
3120void Context::framebufferTextureMultiviewSideBySideANGLE(GLenum target,
3121 GLenum attachment,
3122 GLuint texture,
3123 GLint level,
3124 GLsizei numViews,
3125 const GLint *viewportOffsets)
3126{
Martin Radev5dae57b2017-07-14 16:15:55 +03003127 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3128 ASSERT(framebuffer);
3129
3130 if (texture != 0)
3131 {
3132 Texture *textureObj = getTexture(texture);
3133
3134 ImageIndex index = ImageIndex::Make2D(level);
3135 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3136 textureObj, numViews, viewportOffsets);
3137 }
3138 else
3139 {
3140 framebuffer->resetAttachment(this, attachment);
3141 }
3142
3143 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003144}
3145
Jamie Madillc29968b2016-01-20 11:17:23 -05003146void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3147{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003148 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003149 ASSERT(framebuffer);
3150 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003151 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003152}
3153
3154void Context::readBuffer(GLenum mode)
3155{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003156 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003157 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003158 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003159}
3160
3161void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3162{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003163 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003164 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003165
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003166 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003167 ASSERT(framebuffer);
3168
3169 // The specification isn't clear what should be done when the framebuffer isn't complete.
3170 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003171 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003172}
3173
3174void Context::invalidateFramebuffer(GLenum target,
3175 GLsizei numAttachments,
3176 const GLenum *attachments)
3177{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003178 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003179 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003180
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003181 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003182 ASSERT(framebuffer);
3183
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003184 if (framebuffer->checkStatus(this) != GL_FRAMEBUFFER_COMPLETE)
Jamie Madillc29968b2016-01-20 11:17:23 -05003185 {
Jamie Madill437fa652016-05-03 15:13:24 -04003186 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003187 }
Jamie Madill437fa652016-05-03 15:13:24 -04003188
Jamie Madill4928b7c2017-06-20 12:57:39 -04003189 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003190}
3191
3192void Context::invalidateSubFramebuffer(GLenum target,
3193 GLsizei numAttachments,
3194 const GLenum *attachments,
3195 GLint x,
3196 GLint y,
3197 GLsizei width,
3198 GLsizei height)
3199{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003200 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003201 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003202
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003203 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003204 ASSERT(framebuffer);
3205
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003206 if (framebuffer->checkStatus(this) != GL_FRAMEBUFFER_COMPLETE)
Jamie Madillc29968b2016-01-20 11:17:23 -05003207 {
Jamie Madill437fa652016-05-03 15:13:24 -04003208 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003209 }
Jamie Madill437fa652016-05-03 15:13:24 -04003210
3211 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003212 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003213}
3214
Jamie Madill73a84962016-02-12 09:27:23 -05003215void Context::texImage2D(GLenum target,
3216 GLint level,
3217 GLint internalformat,
3218 GLsizei width,
3219 GLsizei height,
3220 GLint border,
3221 GLenum format,
3222 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003223 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003224{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003225 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003226
3227 Extents size(width, height, 1);
3228 Texture *texture =
3229 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003230 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3231 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003232}
3233
3234void Context::texImage3D(GLenum target,
3235 GLint level,
3236 GLint internalformat,
3237 GLsizei width,
3238 GLsizei height,
3239 GLsizei depth,
3240 GLint border,
3241 GLenum format,
3242 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003243 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003244{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003245 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003246
3247 Extents size(width, height, depth);
3248 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003249 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3250 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003251}
3252
3253void Context::texSubImage2D(GLenum target,
3254 GLint level,
3255 GLint xoffset,
3256 GLint yoffset,
3257 GLsizei width,
3258 GLsizei height,
3259 GLenum format,
3260 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003261 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003262{
3263 // Zero sized uploads are valid but no-ops
3264 if (width == 0 || height == 0)
3265 {
3266 return;
3267 }
3268
Jamie Madillad9f24e2016-02-12 09:27:24 -05003269 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003270
3271 Box area(xoffset, yoffset, 0, width, height, 1);
3272 Texture *texture =
3273 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003274 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3275 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003276}
3277
3278void Context::texSubImage3D(GLenum target,
3279 GLint level,
3280 GLint xoffset,
3281 GLint yoffset,
3282 GLint zoffset,
3283 GLsizei width,
3284 GLsizei height,
3285 GLsizei depth,
3286 GLenum format,
3287 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003288 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003289{
3290 // Zero sized uploads are valid but no-ops
3291 if (width == 0 || height == 0 || depth == 0)
3292 {
3293 return;
3294 }
3295
Jamie Madillad9f24e2016-02-12 09:27:24 -05003296 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003297
3298 Box area(xoffset, yoffset, zoffset, width, height, depth);
3299 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003300 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3301 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003302}
3303
3304void Context::compressedTexImage2D(GLenum target,
3305 GLint level,
3306 GLenum internalformat,
3307 GLsizei width,
3308 GLsizei height,
3309 GLint border,
3310 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003311 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003312{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003313 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003314
3315 Extents size(width, height, 1);
3316 Texture *texture =
3317 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003318 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003319 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003320 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003321}
3322
3323void Context::compressedTexImage3D(GLenum target,
3324 GLint level,
3325 GLenum internalformat,
3326 GLsizei width,
3327 GLsizei height,
3328 GLsizei depth,
3329 GLint border,
3330 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003331 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003332{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003333 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003334
3335 Extents size(width, height, depth);
3336 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003337 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003338 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003339 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003340}
3341
3342void Context::compressedTexSubImage2D(GLenum target,
3343 GLint level,
3344 GLint xoffset,
3345 GLint yoffset,
3346 GLsizei width,
3347 GLsizei height,
3348 GLenum format,
3349 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003350 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003351{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003352 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003353
3354 Box area(xoffset, yoffset, 0, width, height, 1);
3355 Texture *texture =
3356 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003357 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003358 format, imageSize,
3359 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003360}
3361
3362void Context::compressedTexSubImage3D(GLenum target,
3363 GLint level,
3364 GLint xoffset,
3365 GLint yoffset,
3366 GLint zoffset,
3367 GLsizei width,
3368 GLsizei height,
3369 GLsizei depth,
3370 GLenum format,
3371 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003372 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003373{
3374 // Zero sized uploads are valid but no-ops
3375 if (width == 0 || height == 0)
3376 {
3377 return;
3378 }
3379
Jamie Madillad9f24e2016-02-12 09:27:24 -05003380 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003381
3382 Box area(xoffset, yoffset, zoffset, width, height, depth);
3383 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003384 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003385 format, imageSize,
3386 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003387}
3388
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003389void Context::generateMipmap(GLenum target)
3390{
3391 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003392 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003393}
3394
Geoff Lang97073d12016-04-20 10:42:34 -07003395void Context::copyTextureCHROMIUM(GLuint sourceId,
Geoff Langfc72a072017-03-24 14:52:39 -04003396 GLint sourceLevel,
3397 GLenum destTarget,
Geoff Lang97073d12016-04-20 10:42:34 -07003398 GLuint destId,
Geoff Langfc72a072017-03-24 14:52:39 -04003399 GLint destLevel,
Geoff Lang97073d12016-04-20 10:42:34 -07003400 GLint internalFormat,
3401 GLenum destType,
3402 GLboolean unpackFlipY,
3403 GLboolean unpackPremultiplyAlpha,
3404 GLboolean unpackUnmultiplyAlpha)
3405{
3406 syncStateForTexImage();
3407
3408 gl::Texture *sourceTexture = getTexture(sourceId);
3409 gl::Texture *destTexture = getTexture(destId);
Geoff Langfc72a072017-03-24 14:52:39 -04003410 handleError(destTexture->copyTexture(
3411 this, destTarget, destLevel, internalFormat, destType, sourceLevel, unpackFlipY == GL_TRUE,
3412 unpackPremultiplyAlpha == GL_TRUE, unpackUnmultiplyAlpha == GL_TRUE, sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003413}
3414
3415void Context::copySubTextureCHROMIUM(GLuint sourceId,
Geoff Langfc72a072017-03-24 14:52:39 -04003416 GLint sourceLevel,
3417 GLenum destTarget,
Geoff Lang97073d12016-04-20 10:42:34 -07003418 GLuint destId,
Geoff Langfc72a072017-03-24 14:52:39 -04003419 GLint destLevel,
Geoff Lang97073d12016-04-20 10:42:34 -07003420 GLint xoffset,
3421 GLint yoffset,
3422 GLint x,
3423 GLint y,
3424 GLsizei width,
3425 GLsizei height,
3426 GLboolean unpackFlipY,
3427 GLboolean unpackPremultiplyAlpha,
3428 GLboolean unpackUnmultiplyAlpha)
3429{
3430 // Zero sized copies are valid but no-ops
3431 if (width == 0 || height == 0)
3432 {
3433 return;
3434 }
3435
3436 syncStateForTexImage();
3437
3438 gl::Texture *sourceTexture = getTexture(sourceId);
3439 gl::Texture *destTexture = getTexture(destId);
3440 Offset offset(xoffset, yoffset, 0);
3441 Rectangle area(x, y, width, height);
Geoff Langfc72a072017-03-24 14:52:39 -04003442 handleError(destTexture->copySubTexture(
3443 this, destTarget, destLevel, offset, sourceLevel, area, unpackFlipY == GL_TRUE,
3444 unpackPremultiplyAlpha == GL_TRUE, unpackUnmultiplyAlpha == GL_TRUE, sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003445}
3446
Geoff Lang47110bf2016-04-20 11:13:22 -07003447void Context::compressedCopyTextureCHROMIUM(GLuint sourceId, GLuint destId)
3448{
3449 syncStateForTexImage();
3450
3451 gl::Texture *sourceTexture = getTexture(sourceId);
3452 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05003453 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07003454}
3455
Geoff Lang496c02d2016-10-20 11:38:11 -07003456void Context::getBufferPointerv(GLenum target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03003457{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003458 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003459 ASSERT(buffer);
3460
Geoff Lang496c02d2016-10-20 11:38:11 -07003461 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03003462}
3463
Jamie Madill876429b2017-04-20 15:46:24 -04003464void *Context::mapBuffer(GLenum target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003465{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003466 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003467 ASSERT(buffer);
3468
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003469 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003470 if (error.isError())
3471 {
Jamie Madill437fa652016-05-03 15:13:24 -04003472 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003473 return nullptr;
3474 }
3475
3476 return buffer->getMapPointer();
3477}
3478
3479GLboolean Context::unmapBuffer(GLenum target)
3480{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003481 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003482 ASSERT(buffer);
3483
3484 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003485 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03003486 if (error.isError())
3487 {
Jamie Madill437fa652016-05-03 15:13:24 -04003488 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003489 return GL_FALSE;
3490 }
3491
3492 return result;
3493}
3494
Jamie Madill876429b2017-04-20 15:46:24 -04003495void *Context::mapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003496{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003497 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003498 ASSERT(buffer);
3499
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003500 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003501 if (error.isError())
3502 {
Jamie Madill437fa652016-05-03 15:13:24 -04003503 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003504 return nullptr;
3505 }
3506
3507 return buffer->getMapPointer();
3508}
3509
3510void Context::flushMappedBufferRange(GLenum /*target*/, GLintptr /*offset*/, GLsizeiptr /*length*/)
3511{
3512 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
3513}
3514
Jamie Madillad9f24e2016-02-12 09:27:24 -05003515void Context::syncStateForReadPixels()
3516{
3517 syncRendererState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
3518}
3519
3520void Context::syncStateForTexImage()
3521{
3522 syncRendererState(mTexImageDirtyBits, mTexImageDirtyObjects);
3523}
3524
3525void Context::syncStateForClear()
3526{
3527 syncRendererState(mClearDirtyBits, mClearDirtyObjects);
3528}
3529
3530void Context::syncStateForBlit()
3531{
3532 syncRendererState(mBlitDirtyBits, mBlitDirtyObjects);
3533}
3534
Jamie Madillc20ab272016-06-09 07:20:46 -07003535void Context::activeTexture(GLenum texture)
3536{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003537 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003538}
3539
Jamie Madill876429b2017-04-20 15:46:24 -04003540void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003541{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003542 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07003543}
3544
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003545void Context::blendEquation(GLenum mode)
3546{
3547 mGLState.setBlendEquation(mode, mode);
3548}
3549
Jamie Madillc20ab272016-06-09 07:20:46 -07003550void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
3551{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003552 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003553}
3554
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003555void Context::blendFunc(GLenum sfactor, GLenum dfactor)
3556{
3557 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
3558}
3559
Jamie Madillc20ab272016-06-09 07:20:46 -07003560void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
3561{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003562 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003563}
3564
Jamie Madill876429b2017-04-20 15:46:24 -04003565void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003566{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003567 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003568}
3569
Jamie Madill876429b2017-04-20 15:46:24 -04003570void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07003571{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003572 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07003573}
3574
3575void Context::clearStencil(GLint s)
3576{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003577 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07003578}
3579
3580void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
3581{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003582 mGLState.setColorMask(red == GL_TRUE, green == GL_TRUE, blue == GL_TRUE, alpha == GL_TRUE);
Jamie Madillc20ab272016-06-09 07:20:46 -07003583}
3584
3585void Context::cullFace(GLenum mode)
3586{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003587 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003588}
3589
3590void Context::depthFunc(GLenum func)
3591{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003592 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07003593}
3594
3595void Context::depthMask(GLboolean flag)
3596{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003597 mGLState.setDepthMask(flag != GL_FALSE);
Jamie Madillc20ab272016-06-09 07:20:46 -07003598}
3599
Jamie Madill876429b2017-04-20 15:46:24 -04003600void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07003601{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003602 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07003603}
3604
3605void Context::disable(GLenum cap)
3606{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003607 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003608}
3609
3610void Context::disableVertexAttribArray(GLuint index)
3611{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003612 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003613}
3614
3615void Context::enable(GLenum cap)
3616{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003617 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003618}
3619
3620void Context::enableVertexAttribArray(GLuint index)
3621{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003622 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003623}
3624
3625void Context::frontFace(GLenum mode)
3626{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003627 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003628}
3629
3630void Context::hint(GLenum target, GLenum mode)
3631{
3632 switch (target)
3633 {
3634 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003635 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003636 break;
3637
3638 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003639 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003640 break;
3641
3642 default:
3643 UNREACHABLE();
3644 return;
3645 }
3646}
3647
3648void Context::lineWidth(GLfloat width)
3649{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003650 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07003651}
3652
3653void Context::pixelStorei(GLenum pname, GLint param)
3654{
3655 switch (pname)
3656 {
3657 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003658 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003659 break;
3660
3661 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003662 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003663 break;
3664
3665 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003666 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003667 break;
3668
3669 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003670 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003671 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003672 break;
3673
3674 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03003675 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003676 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003677 break;
3678
3679 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03003680 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003681 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003682 break;
3683
3684 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003685 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003686 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003687 break;
3688
3689 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003690 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003691 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003692 break;
3693
3694 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003695 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003696 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003697 break;
3698
3699 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003700 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003701 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003702 break;
3703
3704 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003705 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003706 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003707 break;
3708
3709 default:
3710 UNREACHABLE();
3711 return;
3712 }
3713}
3714
3715void Context::polygonOffset(GLfloat factor, GLfloat units)
3716{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003717 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07003718}
3719
Jamie Madill876429b2017-04-20 15:46:24 -04003720void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07003721{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003722 mGLState.setSampleCoverageParams(clamp01(value), invert == GL_TRUE);
Jamie Madillc20ab272016-06-09 07:20:46 -07003723}
3724
3725void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
3726{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003727 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07003728}
3729
3730void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
3731{
3732 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3733 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003734 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003735 }
3736
3737 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3738 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003739 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003740 }
3741}
3742
3743void Context::stencilMaskSeparate(GLenum face, GLuint mask)
3744{
3745 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3746 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003747 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003748 }
3749
3750 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3751 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003752 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003753 }
3754}
3755
3756void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
3757{
3758 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3759 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003760 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003761 }
3762
3763 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3764 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003765 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003766 }
3767}
3768
3769void Context::vertexAttrib1f(GLuint index, GLfloat x)
3770{
3771 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003772 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003773}
3774
3775void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
3776{
3777 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003778 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003779}
3780
3781void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
3782{
3783 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003784 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003785}
3786
3787void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
3788{
3789 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003790 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003791}
3792
3793void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
3794{
3795 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003796 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003797}
3798
3799void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
3800{
3801 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003802 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003803}
3804
3805void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
3806{
3807 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003808 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003809}
3810
3811void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
3812{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003813 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07003814}
3815
3816void Context::vertexAttribPointer(GLuint index,
3817 GLint size,
3818 GLenum type,
3819 GLboolean normalized,
3820 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04003821 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07003822{
Shaodde78e82017-05-22 14:13:27 +08003823 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(GL_ARRAY_BUFFER), size,
3824 type, normalized == GL_TRUE, false, stride, ptr);
Jamie Madillc20ab272016-06-09 07:20:46 -07003825}
3826
Shao80957d92017-02-20 21:25:59 +08003827void Context::vertexAttribFormat(GLuint attribIndex,
3828 GLint size,
3829 GLenum type,
3830 GLboolean normalized,
3831 GLuint relativeOffset)
3832{
3833 mGLState.setVertexAttribFormat(attribIndex, size, type, normalized == GL_TRUE, false,
3834 relativeOffset);
3835}
3836
3837void Context::vertexAttribIFormat(GLuint attribIndex,
3838 GLint size,
3839 GLenum type,
3840 GLuint relativeOffset)
3841{
3842 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
3843}
3844
3845void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
3846{
Shaodde78e82017-05-22 14:13:27 +08003847 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Shao80957d92017-02-20 21:25:59 +08003848}
3849
3850void Context::setVertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
3851{
3852 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
3853}
3854
Jamie Madillc20ab272016-06-09 07:20:46 -07003855void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
3856{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003857 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07003858}
3859
3860void Context::vertexAttribIPointer(GLuint index,
3861 GLint size,
3862 GLenum type,
3863 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04003864 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07003865{
Shaodde78e82017-05-22 14:13:27 +08003866 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(GL_ARRAY_BUFFER), size,
3867 type, false, true, stride, pointer);
Jamie Madillc20ab272016-06-09 07:20:46 -07003868}
3869
3870void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
3871{
3872 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003873 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003874}
3875
3876void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
3877{
3878 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003879 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003880}
3881
3882void Context::vertexAttribI4iv(GLuint index, const GLint *v)
3883{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003884 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07003885}
3886
3887void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
3888{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003889 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07003890}
3891
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003892void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
3893{
3894 const VertexAttribCurrentValueData &currentValues =
3895 getGLState().getVertexAttribCurrentValue(index);
3896 const VertexArray *vao = getGLState().getVertexArray();
3897 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3898 currentValues, pname, params);
3899}
3900
3901void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
3902{
3903 const VertexAttribCurrentValueData &currentValues =
3904 getGLState().getVertexAttribCurrentValue(index);
3905 const VertexArray *vao = getGLState().getVertexArray();
3906 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3907 currentValues, pname, params);
3908}
3909
3910void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
3911{
3912 const VertexAttribCurrentValueData &currentValues =
3913 getGLState().getVertexAttribCurrentValue(index);
3914 const VertexArray *vao = getGLState().getVertexArray();
3915 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3916 currentValues, pname, params);
3917}
3918
3919void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
3920{
3921 const VertexAttribCurrentValueData &currentValues =
3922 getGLState().getVertexAttribCurrentValue(index);
3923 const VertexArray *vao = getGLState().getVertexArray();
3924 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3925 currentValues, pname, params);
3926}
3927
Jamie Madill876429b2017-04-20 15:46:24 -04003928void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003929{
3930 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
3931 QueryVertexAttribPointerv(attrib, pname, pointer);
3932}
3933
Jamie Madillc20ab272016-06-09 07:20:46 -07003934void Context::debugMessageControl(GLenum source,
3935 GLenum type,
3936 GLenum severity,
3937 GLsizei count,
3938 const GLuint *ids,
3939 GLboolean enabled)
3940{
3941 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003942 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
3943 (enabled != GL_FALSE));
Jamie Madillc20ab272016-06-09 07:20:46 -07003944}
3945
3946void Context::debugMessageInsert(GLenum source,
3947 GLenum type,
3948 GLuint id,
3949 GLenum severity,
3950 GLsizei length,
3951 const GLchar *buf)
3952{
3953 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003954 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07003955}
3956
3957void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
3958{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003959 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07003960}
3961
3962GLuint Context::getDebugMessageLog(GLuint count,
3963 GLsizei bufSize,
3964 GLenum *sources,
3965 GLenum *types,
3966 GLuint *ids,
3967 GLenum *severities,
3968 GLsizei *lengths,
3969 GLchar *messageLog)
3970{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003971 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
3972 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07003973}
3974
3975void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
3976{
3977 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003978 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07003979}
3980
3981void Context::popDebugGroup()
3982{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003983 mGLState.getDebug().popGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07003984}
3985
Jamie Madill876429b2017-04-20 15:46:24 -04003986void Context::bufferData(GLenum target, GLsizeiptr size, const void *data, GLenum usage)
Jamie Madill29639852016-09-02 15:00:09 -04003987{
3988 Buffer *buffer = mGLState.getTargetBuffer(target);
3989 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08003990 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04003991}
3992
Jamie Madill876429b2017-04-20 15:46:24 -04003993void Context::bufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04003994{
3995 if (data == nullptr)
3996 {
3997 return;
3998 }
3999
4000 Buffer *buffer = mGLState.getTargetBuffer(target);
4001 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004002 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004003}
4004
Jamie Madillef300b12016-10-07 15:12:09 -04004005void Context::attachShader(GLuint program, GLuint shader)
4006{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004007 auto programObject = mState.mShaderPrograms->getProgram(program);
4008 auto shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004009 ASSERT(programObject && shaderObject);
4010 programObject->attachShader(shaderObject);
4011}
4012
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004013const Workarounds &Context::getWorkarounds() const
4014{
4015 return mWorkarounds;
4016}
4017
Jamie Madillb0817d12016-11-01 15:48:31 -04004018void Context::copyBufferSubData(GLenum readTarget,
4019 GLenum writeTarget,
4020 GLintptr readOffset,
4021 GLintptr writeOffset,
4022 GLsizeiptr size)
4023{
4024 // if size is zero, the copy is a successful no-op
4025 if (size == 0)
4026 {
4027 return;
4028 }
4029
4030 // TODO(jmadill): cache these.
4031 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4032 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4033
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004034 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004035}
4036
Jamie Madill01a80ee2016-11-07 12:06:18 -05004037void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4038{
4039 Program *programObject = getProgram(program);
4040 // TODO(jmadill): Re-use this from the validation if possible.
4041 ASSERT(programObject);
4042 programObject->bindAttributeLocation(index, name);
4043}
4044
4045void Context::bindBuffer(GLenum target, GLuint buffer)
4046{
4047 switch (target)
4048 {
4049 case GL_ARRAY_BUFFER:
4050 bindArrayBuffer(buffer);
4051 break;
4052 case GL_ELEMENT_ARRAY_BUFFER:
4053 bindElementArrayBuffer(buffer);
4054 break;
4055 case GL_COPY_READ_BUFFER:
4056 bindCopyReadBuffer(buffer);
4057 break;
4058 case GL_COPY_WRITE_BUFFER:
4059 bindCopyWriteBuffer(buffer);
4060 break;
4061 case GL_PIXEL_PACK_BUFFER:
4062 bindPixelPackBuffer(buffer);
4063 break;
4064 case GL_PIXEL_UNPACK_BUFFER:
4065 bindPixelUnpackBuffer(buffer);
4066 break;
4067 case GL_UNIFORM_BUFFER:
4068 bindGenericUniformBuffer(buffer);
4069 break;
4070 case GL_TRANSFORM_FEEDBACK_BUFFER:
4071 bindGenericTransformFeedbackBuffer(buffer);
4072 break;
Geoff Lang3b573612016-10-31 14:08:10 -04004073 case GL_ATOMIC_COUNTER_BUFFER:
Jiajia Qin6eafb042016-12-27 17:04:07 +08004074 bindGenericAtomicCounterBuffer(buffer);
Geoff Lang3b573612016-10-31 14:08:10 -04004075 break;
4076 case GL_SHADER_STORAGE_BUFFER:
Jiajia Qinf546e7d2017-03-27 14:12:59 +08004077 bindGenericShaderStorageBuffer(buffer);
Geoff Lang3b573612016-10-31 14:08:10 -04004078 break;
4079 case GL_DRAW_INDIRECT_BUFFER:
Jiajia Qin9d7d0b12016-11-29 16:30:31 +08004080 bindDrawIndirectBuffer(buffer);
Geoff Lang3b573612016-10-31 14:08:10 -04004081 break;
4082 case GL_DISPATCH_INDIRECT_BUFFER:
Geoff Lang9f090372016-12-02 10:20:43 -05004083 if (buffer != 0)
4084 {
4085 // Binding buffers to this binding point is not implemented yet.
4086 UNIMPLEMENTED();
4087 }
Geoff Lang3b573612016-10-31 14:08:10 -04004088 break;
Jamie Madill01a80ee2016-11-07 12:06:18 -05004089
4090 default:
4091 UNREACHABLE();
4092 break;
4093 }
4094}
4095
Jiajia Qin6eafb042016-12-27 17:04:07 +08004096void Context::bindBufferBase(GLenum target, GLuint index, GLuint buffer)
4097{
4098 bindBufferRange(target, index, buffer, 0, 0);
4099}
4100
4101void Context::bindBufferRange(GLenum target,
4102 GLuint index,
4103 GLuint buffer,
4104 GLintptr offset,
4105 GLsizeiptr size)
4106{
4107 switch (target)
4108 {
4109 case GL_TRANSFORM_FEEDBACK_BUFFER:
4110 bindIndexedTransformFeedbackBuffer(buffer, index, offset, size);
4111 bindGenericTransformFeedbackBuffer(buffer);
4112 break;
4113 case GL_UNIFORM_BUFFER:
4114 bindIndexedUniformBuffer(buffer, index, offset, size);
4115 bindGenericUniformBuffer(buffer);
4116 break;
4117 case GL_ATOMIC_COUNTER_BUFFER:
4118 bindIndexedAtomicCounterBuffer(buffer, index, offset, size);
4119 bindGenericAtomicCounterBuffer(buffer);
4120 break;
4121 case GL_SHADER_STORAGE_BUFFER:
Jiajia Qinf546e7d2017-03-27 14:12:59 +08004122 bindIndexedShaderStorageBuffer(buffer, index, offset, size);
4123 bindGenericShaderStorageBuffer(buffer);
Jiajia Qin6eafb042016-12-27 17:04:07 +08004124 break;
4125 default:
4126 UNREACHABLE();
4127 break;
4128 }
4129}
4130
Jamie Madill01a80ee2016-11-07 12:06:18 -05004131void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
4132{
4133 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4134 {
4135 bindReadFramebuffer(framebuffer);
4136 }
4137
4138 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4139 {
4140 bindDrawFramebuffer(framebuffer);
4141 }
4142}
4143
4144void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4145{
4146 ASSERT(target == GL_RENDERBUFFER);
4147 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004148 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04004149 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004150}
4151
JiangYizhoubddc46b2016-12-09 09:50:51 +08004152void Context::texStorage2DMultisample(GLenum target,
4153 GLsizei samples,
4154 GLenum internalformat,
4155 GLsizei width,
4156 GLsizei height,
4157 GLboolean fixedsamplelocations)
4158{
4159 Extents size(width, height, 1);
4160 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05004161 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
JiangYizhoubddc46b2016-12-09 09:50:51 +08004162 fixedsamplelocations));
4163}
4164
4165void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4166{
Jamie Madilldd43e6c2017-03-24 14:18:49 -04004167 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
JiangYizhoubddc46b2016-12-09 09:50:51 +08004168 const Framebuffer *framebuffer = mGLState.getReadFramebuffer();
4169
4170 switch (pname)
4171 {
4172 case GL_SAMPLE_POSITION:
4173 handleError(framebuffer->getSamplePosition(index, val));
4174 break;
4175 default:
4176 UNREACHABLE();
4177 }
4178}
4179
Jamie Madille8fb6402017-02-14 17:56:40 -05004180void Context::renderbufferStorage(GLenum target,
4181 GLenum internalformat,
4182 GLsizei width,
4183 GLsizei height)
4184{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004185 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4186 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
4187
Jamie Madille8fb6402017-02-14 17:56:40 -05004188 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04004189 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004190}
4191
4192void Context::renderbufferStorageMultisample(GLenum target,
4193 GLsizei samples,
4194 GLenum internalformat,
4195 GLsizei width,
4196 GLsizei height)
4197{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004198 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4199 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05004200
4201 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004202 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04004203 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004204}
4205
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004206void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
4207{
4208 const FenceSync *syncObject = getFenceSync(sync);
Geoff Lang82483b92017-04-11 15:33:00 -04004209 handleError(QuerySynciv(syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004210}
4211
JiangYizhoue18e6392017-02-20 10:32:23 +08004212void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
4213{
4214 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4215 QueryFramebufferParameteriv(framebuffer, pname, params);
4216}
4217
4218void Context::setFramebufferParameteri(GLenum target, GLenum pname, GLint param)
4219{
4220 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4221 SetFramebufferParameteri(framebuffer, pname, param);
4222}
4223
Jamie Madillb3f26b92017-07-19 15:07:41 -04004224Error Context::getScratchBuffer(size_t requstedSizeBytes,
4225 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05004226{
Jamie Madillb3f26b92017-07-19 15:07:41 -04004227 if (!mScratchBuffer.get(requstedSizeBytes, scratchBufferOut))
4228 {
4229 return OutOfMemory() << "Failed to allocate internal buffer.";
4230 }
4231 return NoError();
4232}
4233
4234Error Context::getZeroFilledBuffer(size_t requstedSizeBytes,
4235 angle::MemoryBuffer **zeroBufferOut) const
4236{
4237 if (!mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0))
Jamie Madille14951e2017-03-09 18:55:16 -05004238 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004239 return OutOfMemory() << "Failed to allocate internal buffer.";
Jamie Madille14951e2017-03-09 18:55:16 -05004240 }
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004241 return NoError();
Jamie Madille14951e2017-03-09 18:55:16 -05004242}
4243
Xinghua Cao2b396592017-03-29 15:36:04 +08004244void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
4245{
4246 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
4247 {
4248 return;
4249 }
4250
Jamie Madillfe548342017-06-19 11:13:24 -04004251 mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ);
Xinghua Cao2b396592017-03-29 15:36:04 +08004252}
4253
JiangYizhou165361c2017-06-07 14:56:57 +08004254void Context::texStorage2D(GLenum target,
4255 GLsizei levels,
4256 GLenum internalFormat,
4257 GLsizei width,
4258 GLsizei height)
4259{
4260 Extents size(width, height, 1);
4261 Texture *texture = getTargetTexture(target);
4262 handleError(texture->setStorage(this, target, levels, internalFormat, size));
4263}
4264
4265void Context::texStorage3D(GLenum target,
4266 GLsizei levels,
4267 GLenum internalFormat,
4268 GLsizei width,
4269 GLsizei height,
4270 GLsizei depth)
4271{
4272 Extents size(width, height, depth);
4273 Texture *texture = getTargetTexture(target);
4274 handleError(texture->setStorage(this, target, levels, internalFormat, size));
4275}
4276
Jamie Madillc1d770e2017-04-13 17:31:24 -04004277GLenum Context::checkFramebufferStatus(GLenum target)
4278{
4279 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4280 ASSERT(framebuffer);
4281
4282 return framebuffer->checkStatus(this);
4283}
4284
4285void Context::compileShader(GLuint shader)
4286{
4287 Shader *shaderObject = GetValidShader(this, shader);
4288 if (!shaderObject)
4289 {
4290 return;
4291 }
4292 shaderObject->compile(this);
4293}
4294
4295void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
4296{
4297 for (int i = 0; i < n; i++)
4298 {
4299 deleteBuffer(buffers[i]);
4300 }
4301}
4302
4303void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
4304{
4305 for (int i = 0; i < n; i++)
4306 {
4307 if (framebuffers[i] != 0)
4308 {
4309 deleteFramebuffer(framebuffers[i]);
4310 }
4311 }
4312}
4313
4314void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
4315{
4316 for (int i = 0; i < n; i++)
4317 {
4318 deleteRenderbuffer(renderbuffers[i]);
4319 }
4320}
4321
4322void Context::deleteTextures(GLsizei n, const GLuint *textures)
4323{
4324 for (int i = 0; i < n; i++)
4325 {
4326 if (textures[i] != 0)
4327 {
4328 deleteTexture(textures[i]);
4329 }
4330 }
4331}
4332
4333void Context::detachShader(GLuint program, GLuint shader)
4334{
4335 Program *programObject = getProgram(program);
4336 ASSERT(programObject);
4337
4338 Shader *shaderObject = getShader(shader);
4339 ASSERT(shaderObject);
4340
4341 programObject->detachShader(this, shaderObject);
4342}
4343
4344void Context::genBuffers(GLsizei n, GLuint *buffers)
4345{
4346 for (int i = 0; i < n; i++)
4347 {
4348 buffers[i] = createBuffer();
4349 }
4350}
4351
4352void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
4353{
4354 for (int i = 0; i < n; i++)
4355 {
4356 framebuffers[i] = createFramebuffer();
4357 }
4358}
4359
4360void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
4361{
4362 for (int i = 0; i < n; i++)
4363 {
4364 renderbuffers[i] = createRenderbuffer();
4365 }
4366}
4367
4368void Context::genTextures(GLsizei n, GLuint *textures)
4369{
4370 for (int i = 0; i < n; i++)
4371 {
4372 textures[i] = createTexture();
4373 }
4374}
4375
4376void Context::getActiveAttrib(GLuint program,
4377 GLuint index,
4378 GLsizei bufsize,
4379 GLsizei *length,
4380 GLint *size,
4381 GLenum *type,
4382 GLchar *name)
4383{
4384 Program *programObject = getProgram(program);
4385 ASSERT(programObject);
4386 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
4387}
4388
4389void Context::getActiveUniform(GLuint program,
4390 GLuint index,
4391 GLsizei bufsize,
4392 GLsizei *length,
4393 GLint *size,
4394 GLenum *type,
4395 GLchar *name)
4396{
4397 Program *programObject = getProgram(program);
4398 ASSERT(programObject);
4399 programObject->getActiveUniform(index, bufsize, length, size, type, name);
4400}
4401
4402void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
4403{
4404 Program *programObject = getProgram(program);
4405 ASSERT(programObject);
4406 programObject->getAttachedShaders(maxcount, count, shaders);
4407}
4408
4409GLint Context::getAttribLocation(GLuint program, const GLchar *name)
4410{
4411 Program *programObject = getProgram(program);
4412 ASSERT(programObject);
4413 return programObject->getAttributeLocation(name);
4414}
4415
4416void Context::getBooleanv(GLenum pname, GLboolean *params)
4417{
4418 GLenum nativeType;
4419 unsigned int numParams = 0;
4420 getQueryParameterInfo(pname, &nativeType, &numParams);
4421
4422 if (nativeType == GL_BOOL)
4423 {
4424 getBooleanvImpl(pname, params);
4425 }
4426 else
4427 {
4428 CastStateValues(this, nativeType, pname, numParams, params);
4429 }
4430}
4431
4432void Context::getFloatv(GLenum pname, GLfloat *params)
4433{
4434 GLenum nativeType;
4435 unsigned int numParams = 0;
4436 getQueryParameterInfo(pname, &nativeType, &numParams);
4437
4438 if (nativeType == GL_FLOAT)
4439 {
4440 getFloatvImpl(pname, params);
4441 }
4442 else
4443 {
4444 CastStateValues(this, nativeType, pname, numParams, params);
4445 }
4446}
4447
4448void Context::getIntegerv(GLenum pname, GLint *params)
4449{
4450 GLenum nativeType;
4451 unsigned int numParams = 0;
4452 getQueryParameterInfo(pname, &nativeType, &numParams);
4453
4454 if (nativeType == GL_INT)
4455 {
4456 getIntegervImpl(pname, params);
4457 }
4458 else
4459 {
4460 CastStateValues(this, nativeType, pname, numParams, params);
4461 }
4462}
4463
4464void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
4465{
4466 Program *programObject = getProgram(program);
4467 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04004468 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004469}
4470
Jamie Madillbe849e42017-05-02 15:49:00 -04004471void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04004472{
4473 Program *programObject = getProgram(program);
4474 ASSERT(programObject);
4475 programObject->getInfoLog(bufsize, length, infolog);
4476}
4477
4478void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
4479{
4480 Shader *shaderObject = getShader(shader);
4481 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004482 QueryShaderiv(this, shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004483}
4484
4485void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
4486{
4487 Shader *shaderObject = getShader(shader);
4488 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004489 shaderObject->getInfoLog(this, bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004490}
4491
4492void Context::getShaderPrecisionFormat(GLenum shadertype,
4493 GLenum precisiontype,
4494 GLint *range,
4495 GLint *precision)
4496{
4497 // TODO(jmadill): Compute shaders.
4498
4499 switch (shadertype)
4500 {
4501 case GL_VERTEX_SHADER:
4502 switch (precisiontype)
4503 {
4504 case GL_LOW_FLOAT:
4505 mCaps.vertexLowpFloat.get(range, precision);
4506 break;
4507 case GL_MEDIUM_FLOAT:
4508 mCaps.vertexMediumpFloat.get(range, precision);
4509 break;
4510 case GL_HIGH_FLOAT:
4511 mCaps.vertexHighpFloat.get(range, precision);
4512 break;
4513
4514 case GL_LOW_INT:
4515 mCaps.vertexLowpInt.get(range, precision);
4516 break;
4517 case GL_MEDIUM_INT:
4518 mCaps.vertexMediumpInt.get(range, precision);
4519 break;
4520 case GL_HIGH_INT:
4521 mCaps.vertexHighpInt.get(range, precision);
4522 break;
4523
4524 default:
4525 UNREACHABLE();
4526 return;
4527 }
4528 break;
4529
4530 case GL_FRAGMENT_SHADER:
4531 switch (precisiontype)
4532 {
4533 case GL_LOW_FLOAT:
4534 mCaps.fragmentLowpFloat.get(range, precision);
4535 break;
4536 case GL_MEDIUM_FLOAT:
4537 mCaps.fragmentMediumpFloat.get(range, precision);
4538 break;
4539 case GL_HIGH_FLOAT:
4540 mCaps.fragmentHighpFloat.get(range, precision);
4541 break;
4542
4543 case GL_LOW_INT:
4544 mCaps.fragmentLowpInt.get(range, precision);
4545 break;
4546 case GL_MEDIUM_INT:
4547 mCaps.fragmentMediumpInt.get(range, precision);
4548 break;
4549 case GL_HIGH_INT:
4550 mCaps.fragmentHighpInt.get(range, precision);
4551 break;
4552
4553 default:
4554 UNREACHABLE();
4555 return;
4556 }
4557 break;
4558
4559 default:
4560 UNREACHABLE();
4561 return;
4562 }
4563}
4564
4565void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
4566{
4567 Shader *shaderObject = getShader(shader);
4568 ASSERT(shaderObject);
4569 shaderObject->getSource(bufsize, length, source);
4570}
4571
4572void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
4573{
4574 Program *programObject = getProgram(program);
4575 ASSERT(programObject);
4576 programObject->getUniformfv(location, params);
4577}
4578
4579void Context::getUniformiv(GLuint program, GLint location, GLint *params)
4580{
4581 Program *programObject = getProgram(program);
4582 ASSERT(programObject);
4583 programObject->getUniformiv(location, params);
4584}
4585
4586GLint Context::getUniformLocation(GLuint program, const GLchar *name)
4587{
4588 Program *programObject = getProgram(program);
4589 ASSERT(programObject);
4590 return programObject->getUniformLocation(name);
4591}
4592
4593GLboolean Context::isBuffer(GLuint buffer)
4594{
4595 if (buffer == 0)
4596 {
4597 return GL_FALSE;
4598 }
4599
4600 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
4601}
4602
4603GLboolean Context::isEnabled(GLenum cap)
4604{
4605 return mGLState.getEnableFeature(cap);
4606}
4607
4608GLboolean Context::isFramebuffer(GLuint framebuffer)
4609{
4610 if (framebuffer == 0)
4611 {
4612 return GL_FALSE;
4613 }
4614
4615 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
4616}
4617
4618GLboolean Context::isProgram(GLuint program)
4619{
4620 if (program == 0)
4621 {
4622 return GL_FALSE;
4623 }
4624
4625 return (getProgram(program) ? GL_TRUE : GL_FALSE);
4626}
4627
4628GLboolean Context::isRenderbuffer(GLuint renderbuffer)
4629{
4630 if (renderbuffer == 0)
4631 {
4632 return GL_FALSE;
4633 }
4634
4635 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
4636}
4637
4638GLboolean Context::isShader(GLuint shader)
4639{
4640 if (shader == 0)
4641 {
4642 return GL_FALSE;
4643 }
4644
4645 return (getShader(shader) ? GL_TRUE : GL_FALSE);
4646}
4647
4648GLboolean Context::isTexture(GLuint texture)
4649{
4650 if (texture == 0)
4651 {
4652 return GL_FALSE;
4653 }
4654
4655 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
4656}
4657
4658void Context::linkProgram(GLuint program)
4659{
4660 Program *programObject = getProgram(program);
4661 ASSERT(programObject);
4662 handleError(programObject->link(this));
4663}
4664
4665void Context::releaseShaderCompiler()
4666{
Jamie Madill4928b7c2017-06-20 12:57:39 -04004667 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004668}
4669
4670void Context::shaderBinary(GLsizei n,
4671 const GLuint *shaders,
4672 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04004673 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04004674 GLsizei length)
4675{
4676 // No binary shader formats are supported.
4677 UNIMPLEMENTED();
4678}
4679
4680void Context::shaderSource(GLuint shader,
4681 GLsizei count,
4682 const GLchar *const *string,
4683 const GLint *length)
4684{
4685 Shader *shaderObject = getShader(shader);
4686 ASSERT(shaderObject);
4687 shaderObject->setSource(count, string, length);
4688}
4689
4690void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
4691{
4692 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
4693}
4694
4695void Context::stencilMask(GLuint mask)
4696{
4697 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
4698}
4699
4700void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
4701{
4702 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
4703}
4704
4705void Context::uniform1f(GLint location, GLfloat x)
4706{
4707 Program *program = mGLState.getProgram();
4708 program->setUniform1fv(location, 1, &x);
4709}
4710
4711void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
4712{
4713 Program *program = mGLState.getProgram();
4714 program->setUniform1fv(location, count, v);
4715}
4716
4717void Context::uniform1i(GLint location, GLint x)
4718{
4719 Program *program = mGLState.getProgram();
4720 program->setUniform1iv(location, 1, &x);
4721}
4722
4723void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
4724{
4725 Program *program = mGLState.getProgram();
4726 program->setUniform1iv(location, count, v);
4727}
4728
4729void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
4730{
4731 GLfloat xy[2] = {x, y};
4732 Program *program = mGLState.getProgram();
4733 program->setUniform2fv(location, 1, xy);
4734}
4735
4736void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
4737{
4738 Program *program = mGLState.getProgram();
4739 program->setUniform2fv(location, count, v);
4740}
4741
4742void Context::uniform2i(GLint location, GLint x, GLint y)
4743{
4744 GLint xy[2] = {x, y};
4745 Program *program = mGLState.getProgram();
4746 program->setUniform2iv(location, 1, xy);
4747}
4748
4749void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
4750{
4751 Program *program = mGLState.getProgram();
4752 program->setUniform2iv(location, count, v);
4753}
4754
4755void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
4756{
4757 GLfloat xyz[3] = {x, y, z};
4758 Program *program = mGLState.getProgram();
4759 program->setUniform3fv(location, 1, xyz);
4760}
4761
4762void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
4763{
4764 Program *program = mGLState.getProgram();
4765 program->setUniform3fv(location, count, v);
4766}
4767
4768void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
4769{
4770 GLint xyz[3] = {x, y, z};
4771 Program *program = mGLState.getProgram();
4772 program->setUniform3iv(location, 1, xyz);
4773}
4774
4775void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
4776{
4777 Program *program = mGLState.getProgram();
4778 program->setUniform3iv(location, count, v);
4779}
4780
4781void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4782{
4783 GLfloat xyzw[4] = {x, y, z, w};
4784 Program *program = mGLState.getProgram();
4785 program->setUniform4fv(location, 1, xyzw);
4786}
4787
4788void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
4789{
4790 Program *program = mGLState.getProgram();
4791 program->setUniform4fv(location, count, v);
4792}
4793
4794void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
4795{
4796 GLint xyzw[4] = {x, y, z, w};
4797 Program *program = mGLState.getProgram();
4798 program->setUniform4iv(location, 1, xyzw);
4799}
4800
4801void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
4802{
4803 Program *program = mGLState.getProgram();
4804 program->setUniform4iv(location, count, v);
4805}
4806
4807void Context::uniformMatrix2fv(GLint location,
4808 GLsizei count,
4809 GLboolean transpose,
4810 const GLfloat *value)
4811{
4812 Program *program = mGLState.getProgram();
4813 program->setUniformMatrix2fv(location, count, transpose, value);
4814}
4815
4816void Context::uniformMatrix3fv(GLint location,
4817 GLsizei count,
4818 GLboolean transpose,
4819 const GLfloat *value)
4820{
4821 Program *program = mGLState.getProgram();
4822 program->setUniformMatrix3fv(location, count, transpose, value);
4823}
4824
4825void Context::uniformMatrix4fv(GLint location,
4826 GLsizei count,
4827 GLboolean transpose,
4828 const GLfloat *value)
4829{
4830 Program *program = mGLState.getProgram();
4831 program->setUniformMatrix4fv(location, count, transpose, value);
4832}
4833
4834void Context::validateProgram(GLuint program)
4835{
4836 Program *programObject = getProgram(program);
4837 ASSERT(programObject);
4838 programObject->validate(mCaps);
4839}
4840
Jamie Madilld04908b2017-06-09 14:15:35 -04004841void Context::getProgramBinary(GLuint program,
4842 GLsizei bufSize,
4843 GLsizei *length,
4844 GLenum *binaryFormat,
4845 void *binary)
4846{
4847 Program *programObject = getProgram(program);
4848 ASSERT(programObject != nullptr);
4849
4850 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
4851}
4852
4853void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
4854{
4855 Program *programObject = getProgram(program);
4856 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04004857
Jamie Madilld04908b2017-06-09 14:15:35 -04004858 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
4859}
4860
Jamie Madillc29968b2016-01-20 11:17:23 -05004861} // namespace gl