blob: 98efef941e8ca698792117589fffc0f30e6acaf0 [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 Madillb6664922017-07-25 12:55:04 -04001840 ANGLE_CONTEXT_TRY(prepareForDraw());
1841 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 Madillb6664922017-07-25 12:55:04 -04001847 ANGLE_CONTEXT_TRY(prepareForDraw());
1848 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 Madillb6664922017-07-25 12:55:04 -04001855 ANGLE_CONTEXT_TRY(prepareForDraw());
1856 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 Madillb6664922017-07-25 12:55:04 -04001865 ANGLE_CONTEXT_TRY(prepareForDraw());
1866 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 Madillb6664922017-07-25 12:55:04 -04001877 ANGLE_CONTEXT_TRY(prepareForDraw());
1878 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 Madillb6664922017-07-25 12:55:04 -04001884 ANGLE_CONTEXT_TRY(prepareForDraw());
1885 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 Madillb6664922017-07-25 12:55:04 -04001890 ANGLE_CONTEXT_TRY(prepareForDraw());
1891 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 Madill437fa652016-05-03 15:13:24 -04002173void 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 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002191}
2192
2193// Get one of the recorded errors and clear its flag, if any.
2194// [OpenGL ES 2.0.24] section 2.5 page 13.
2195GLenum Context::getError()
2196{
Geoff Langda5777c2014-07-11 09:52:58 -04002197 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002198 {
Geoff Langda5777c2014-07-11 09:52:58 -04002199 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002200 }
Geoff Langda5777c2014-07-11 09:52:58 -04002201 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002202 {
Geoff Langda5777c2014-07-11 09:52:58 -04002203 GLenum error = *mErrors.begin();
2204 mErrors.erase(mErrors.begin());
2205 return error;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002206 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002207}
2208
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002209// NOTE: this function should not assume that this context is current!
2210void Context::markContextLost()
2211{
2212 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002213 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002214 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002215 mContextLostForced = true;
2216 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002217 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002218}
2219
2220bool Context::isContextLost()
2221{
2222 return mContextLost;
2223}
2224
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002225GLenum Context::getResetStatus()
2226{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002227 // Even if the application doesn't want to know about resets, we want to know
2228 // as it will allow us to skip all the calls.
2229 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002230 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002231 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002232 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002233 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002234 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002235
2236 // EXT_robustness, section 2.6: If the reset notification behavior is
2237 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2238 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2239 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002240 }
2241
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002242 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2243 // status should be returned at least once, and GL_NO_ERROR should be returned
2244 // once the device has finished resetting.
2245 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002246 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002247 ASSERT(mResetStatus == GL_NO_ERROR);
2248 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002249
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002250 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002251 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002252 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002253 }
2254 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002255 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002256 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002257 // If markContextLost was used to mark the context lost then
2258 // assume that is not recoverable, and continue to report the
2259 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002260 mResetStatus = mImplementation->getResetStatus();
2261 }
Jamie Madill893ab082014-05-16 16:56:10 -04002262
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002263 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002264}
2265
2266bool Context::isResetNotificationEnabled()
2267{
2268 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2269}
2270
Corentin Walleze3b10e82015-05-20 11:06:25 -04002271const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002272{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002273 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002274}
2275
2276EGLenum Context::getClientType() const
2277{
2278 return mClientType;
2279}
2280
2281EGLenum Context::getRenderBuffer() const
2282{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002283 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2284 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002285 {
2286 return EGL_NONE;
2287 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002288
2289 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(GL_BACK);
2290 ASSERT(backAttachment != nullptr);
2291 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002292}
2293
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002294VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002295{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002296 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002297 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2298 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002299 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002300 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2301 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002302
Jamie Madill96a483b2017-06-27 16:49:21 -04002303 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002304 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002305
2306 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002307}
2308
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002309TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002310{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002311 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002312 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2313 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002314 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002315 transformFeedback =
2316 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002317 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002318 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002319 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002320
2321 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002322}
2323
2324bool Context::isVertexArrayGenerated(GLuint vertexArray)
2325{
Jamie Madill96a483b2017-06-27 16:49:21 -04002326 ASSERT(mVertexArrayMap.contains(0));
2327 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002328}
2329
2330bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2331{
Jamie Madill96a483b2017-06-27 16:49:21 -04002332 ASSERT(mTransformFeedbackMap.contains(0));
2333 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002334}
2335
Shannon Woods53a94a82014-06-24 15:20:36 -04002336void Context::detachTexture(GLuint texture)
2337{
2338 // Simple pass-through to State's detachTexture method, as textures do not require
2339 // allocation map management either here or in the resource manager at detach time.
2340 // Zero textures are held by the Context, and we don't attempt to request them from
2341 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002342 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002343}
2344
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002345void Context::detachBuffer(GLuint buffer)
2346{
Yuly Novikov5807a532015-12-03 13:01:22 -05002347 // Simple pass-through to State's detachBuffer method, since
2348 // only buffer attachments to container objects that are bound to the current context
2349 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002350
Yuly Novikov5807a532015-12-03 13:01:22 -05002351 // [OpenGL ES 3.2] section 5.1.2 page 45:
2352 // Attachments to unbound container objects, such as
2353 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2354 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002355 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002356}
2357
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002358void Context::detachFramebuffer(GLuint framebuffer)
2359{
Shannon Woods53a94a82014-06-24 15:20:36 -04002360 // Framebuffer detachment is handled by Context, because 0 is a valid
2361 // Framebuffer object, and a pointer to it must be passed from Context
2362 // to State at binding time.
2363
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002364 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002365 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2366 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2367 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002368
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002369 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002370 {
2371 bindReadFramebuffer(0);
2372 }
2373
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002374 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002375 {
2376 bindDrawFramebuffer(0);
2377 }
2378}
2379
2380void Context::detachRenderbuffer(GLuint renderbuffer)
2381{
Jamie Madilla02315b2017-02-23 14:14:47 -05002382 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002383}
2384
Jamie Madill57a89722013-07-02 11:57:03 -04002385void Context::detachVertexArray(GLuint vertexArray)
2386{
Jamie Madill77a72f62015-04-14 11:18:32 -04002387 // Vertex array detachment is handled by Context, because 0 is a valid
2388 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002389 // binding time.
2390
Jamie Madill57a89722013-07-02 11:57:03 -04002391 // [OpenGL ES 3.0.2] section 2.10 page 43:
2392 // If a vertex array object that is currently bound is deleted, the binding
2393 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002394 if (mGLState.removeVertexArrayBinding(vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002395 {
2396 bindVertexArray(0);
2397 }
2398}
2399
Geoff Langc8058452014-02-03 12:04:11 -05002400void Context::detachTransformFeedback(GLuint transformFeedback)
2401{
Corentin Walleza2257da2016-04-19 16:43:12 -04002402 // Transform feedback detachment is handled by Context, because 0 is a valid
2403 // transform feedback, and a pointer to it must be passed from Context to State at
2404 // binding time.
2405
2406 // The OpenGL specification doesn't mention what should happen when the currently bound
2407 // transform feedback object is deleted. Since it is a container object, we treat it like
2408 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002409 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002410 {
2411 bindTransformFeedback(0);
2412 }
Geoff Langc8058452014-02-03 12:04:11 -05002413}
2414
Jamie Madilldc356042013-07-19 16:36:57 -04002415void Context::detachSampler(GLuint sampler)
2416{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002417 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002418}
2419
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002420void Context::setVertexAttribDivisor(GLuint index, GLuint divisor)
2421{
Shaodde78e82017-05-22 14:13:27 +08002422 mGLState.setVertexAttribDivisor(this, index, divisor);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002423}
2424
Jamie Madille29d1672013-07-19 16:36:57 -04002425void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2426{
Geoff Langc1984ed2016-10-07 12:41:00 -04002427 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002428 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002429 SetSamplerParameteri(samplerObject, pname, param);
2430}
Jamie Madille29d1672013-07-19 16:36:57 -04002431
Geoff Langc1984ed2016-10-07 12:41:00 -04002432void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2433{
2434 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002435 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002436 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madille29d1672013-07-19 16:36:57 -04002437}
2438
2439void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2440{
Geoff Langc1984ed2016-10-07 12:41:00 -04002441 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002442 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002443 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madille29d1672013-07-19 16:36:57 -04002444}
2445
Geoff Langc1984ed2016-10-07 12:41:00 -04002446void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002447{
Geoff Langc1984ed2016-10-07 12:41:00 -04002448 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002449 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002450 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill9675b802013-07-19 16:36:59 -04002451}
2452
Geoff Langc1984ed2016-10-07 12:41:00 -04002453void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002454{
Geoff Langc1984ed2016-10-07 12:41:00 -04002455 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002456 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002457 QuerySamplerParameteriv(samplerObject, pname, params);
2458}
Jamie Madill9675b802013-07-19 16:36:59 -04002459
Geoff Langc1984ed2016-10-07 12:41:00 -04002460void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2461{
2462 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002463 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002464 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill9675b802013-07-19 16:36:59 -04002465}
2466
Olli Etuahof0fee072016-03-30 15:11:58 +03002467void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2468{
2469 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002470 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002471}
2472
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002473void Context::initRendererString()
2474{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002475 std::ostringstream rendererString;
2476 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002477 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002478 rendererString << ")";
2479
Geoff Langcec35902014-04-16 10:52:36 -04002480 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002481}
2482
Geoff Langc339c4e2016-11-29 10:37:36 -05002483void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002484{
Geoff Langc339c4e2016-11-29 10:37:36 -05002485 const Version &clientVersion = getClientVersion();
2486
2487 std::ostringstream versionString;
2488 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2489 << ANGLE_VERSION_STRING << ")";
2490 mVersionString = MakeStaticString(versionString.str());
2491
2492 std::ostringstream shadingLanguageVersionString;
2493 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2494 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2495 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2496 << ")";
2497 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002498}
2499
Geoff Langcec35902014-04-16 10:52:36 -04002500void Context::initExtensionStrings()
2501{
Geoff Langc339c4e2016-11-29 10:37:36 -05002502 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2503 std::ostringstream combinedStringStream;
2504 std::copy(strings.begin(), strings.end(),
2505 std::ostream_iterator<const char *>(combinedStringStream, " "));
2506 return MakeStaticString(combinedStringStream.str());
2507 };
2508
2509 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002510 for (const auto &extensionString : mExtensions.getStrings())
2511 {
2512 mExtensionStrings.push_back(MakeStaticString(extensionString));
2513 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002514 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002515
Bryan Bernhart58806562017-01-05 13:09:31 -08002516 const gl::Extensions &nativeExtensions = mImplementation->getNativeExtensions();
2517
Geoff Langc339c4e2016-11-29 10:37:36 -05002518 mRequestableExtensionStrings.clear();
2519 for (const auto &extensionInfo : GetExtensionInfoMap())
2520 {
2521 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08002522 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
2523 nativeExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002524 {
2525 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
2526 }
2527 }
2528 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002529}
2530
Geoff Langc339c4e2016-11-29 10:37:36 -05002531const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04002532{
Geoff Langc339c4e2016-11-29 10:37:36 -05002533 switch (name)
2534 {
2535 case GL_VENDOR:
2536 return reinterpret_cast<const GLubyte *>("Google Inc.");
2537
2538 case GL_RENDERER:
2539 return reinterpret_cast<const GLubyte *>(mRendererString);
2540
2541 case GL_VERSION:
2542 return reinterpret_cast<const GLubyte *>(mVersionString);
2543
2544 case GL_SHADING_LANGUAGE_VERSION:
2545 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
2546
2547 case GL_EXTENSIONS:
2548 return reinterpret_cast<const GLubyte *>(mExtensionString);
2549
2550 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2551 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
2552
2553 default:
2554 UNREACHABLE();
2555 return nullptr;
2556 }
Geoff Langcec35902014-04-16 10:52:36 -04002557}
2558
Geoff Langc339c4e2016-11-29 10:37:36 -05002559const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04002560{
Geoff Langc339c4e2016-11-29 10:37:36 -05002561 switch (name)
2562 {
2563 case GL_EXTENSIONS:
2564 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
2565
2566 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2567 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
2568
2569 default:
2570 UNREACHABLE();
2571 return nullptr;
2572 }
Geoff Langcec35902014-04-16 10:52:36 -04002573}
2574
2575size_t Context::getExtensionStringCount() const
2576{
2577 return mExtensionStrings.size();
2578}
2579
Geoff Langc339c4e2016-11-29 10:37:36 -05002580void Context::requestExtension(const char *name)
2581{
2582 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2583 ASSERT(extensionInfos.find(name) != extensionInfos.end());
2584 const auto &extension = extensionInfos.at(name);
2585 ASSERT(extension.Requestable);
2586
2587 if (mExtensions.*(extension.ExtensionsMember))
2588 {
2589 // Extension already enabled
2590 return;
2591 }
2592
2593 mExtensions.*(extension.ExtensionsMember) = true;
2594 updateCaps();
2595 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08002596
Jamie Madill2f348d22017-06-05 10:50:59 -04002597 // Release the shader compiler so it will be re-created with the requested extensions enabled.
2598 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04002599
2600 // Invalidate all cached completenesses for textures and framebuffer. Some extensions make new
2601 // formats renderable or sampleable.
2602 mState.mTextures->invalidateTextureComplenessCache();
2603 for (auto &zeroTexture : mZeroTextures)
2604 {
2605 zeroTexture.second->invalidateCompletenessCache();
2606 }
2607
2608 mState.mFramebuffers->invalidateFramebufferComplenessCache();
Geoff Langc339c4e2016-11-29 10:37:36 -05002609}
2610
2611size_t Context::getRequestableExtensionStringCount() const
2612{
2613 return mRequestableExtensionStrings.size();
2614}
2615
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002616void Context::beginTransformFeedback(GLenum primitiveMode)
2617{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002618 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002619 ASSERT(transformFeedback != nullptr);
2620 ASSERT(!transformFeedback->isPaused());
2621
Jamie Madill6c1f6712017-02-14 19:08:04 -05002622 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002623}
2624
2625bool Context::hasActiveTransformFeedback(GLuint program) const
2626{
2627 for (auto pair : mTransformFeedbackMap)
2628 {
2629 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
2630 {
2631 return true;
2632 }
2633 }
2634 return false;
2635}
2636
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002637void Context::initCaps(const egl::DisplayExtensions &displayExtensions)
Geoff Lang493daf52014-07-03 13:38:44 -04002638{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002639 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04002640
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002641 mExtensions = mImplementation->getNativeExtensions();
Geoff Lang493daf52014-07-03 13:38:44 -04002642
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002643 mLimitations = mImplementation->getNativeLimitations();
Austin Kinross02df7962015-07-01 10:03:42 -07002644
Geoff Langeb66a6e2016-10-31 13:06:12 -04002645 if (getClientVersion() < Version(3, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002646 {
2647 // Disable ES3+ extensions
Jamie Madill231c7f52017-04-26 13:45:37 -04002648 mExtensions.colorBufferFloat = false;
Geoff Langb66a9092016-05-16 15:59:14 -04002649 mExtensions.eglImageExternalEssl3 = false;
Vincent Lang25ab4512016-05-13 18:13:59 +02002650 mExtensions.textureNorm16 = false;
Martin Radev137032d2017-07-13 10:11:12 +03002651 mExtensions.multiview = false;
2652 mExtensions.maxViews = 1u;
Geoff Lang493daf52014-07-03 13:38:44 -04002653 }
2654
Geoff Langeb66a6e2016-10-31 13:06:12 -04002655 if (getClientVersion() > Version(2, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002656 {
2657 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
Jamie Madill231c7f52017-04-26 13:45:37 -04002658 // mExtensions.sRGB = false;
Geoff Lang493daf52014-07-03 13:38:44 -04002659 }
2660
Jamie Madill00ed7a12016-05-19 13:13:38 -04002661 // Some extensions are always available because they are implemented in the GL layer.
Jamie Madill231c7f52017-04-26 13:45:37 -04002662 mExtensions.bindUniformLocation = true;
2663 mExtensions.vertexArrayObject = true;
Geoff Langf41a7152016-09-19 15:11:17 -04002664 mExtensions.bindGeneratesResource = true;
Geoff Langfeb8c682017-02-13 16:07:35 -05002665 mExtensions.clientArrays = true;
Geoff Langc339c4e2016-11-29 10:37:36 -05002666 mExtensions.requestExtension = true;
Jamie Madill00ed7a12016-05-19 13:13:38 -04002667
2668 // Enable the no error extension if the context was created with the flag.
2669 mExtensions.noError = mSkipValidation;
2670
Corentin Wallezccab69d2017-01-27 16:57:15 -05002671 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Corentin Wallezc295e512017-01-27 17:47:50 -05002672 mExtensions.surfacelessContext = displayExtensions.surfacelessContext;
Corentin Wallezccab69d2017-01-27 16:57:15 -05002673
Geoff Lang70d0f492015-12-10 17:45:46 -05002674 // Explicitly enable GL_KHR_debug
2675 mExtensions.debug = true;
2676 mExtensions.maxDebugMessageLength = 1024;
2677 mExtensions.maxDebugLoggedMessages = 1024;
2678 mExtensions.maxDebugGroupStackDepth = 1024;
2679 mExtensions.maxLabelLength = 1024;
2680
Geoff Langff5b2d52016-09-07 11:32:23 -04002681 // Explicitly enable GL_ANGLE_robust_client_memory
2682 mExtensions.robustClientMemory = true;
2683
Jamie Madille08a1d32017-03-07 17:24:06 -05002684 // Determine robust resource init availability from EGL.
2685 mExtensions.robustResourceInitialization =
Jamie Madill948bbe52017-06-01 13:10:42 -04002686 egl::Display::GetClientExtensions().displayRobustResourceInitialization;
Jamie Madille08a1d32017-03-07 17:24:06 -05002687
Jamie Madillc43be722017-07-13 16:22:14 -04002688 // Enable the cache control query unconditionally.
2689 mExtensions.programCacheControl = true;
2690
Geoff Lang301d1612014-07-09 10:34:37 -04002691 // Apply implementation limits
2692 mCaps.maxVertexAttributes = std::min<GLuint>(mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002693 mCaps.maxVertexAttribBindings =
2694 getClientVersion() < ES_3_1
2695 ? mCaps.maxVertexAttributes
2696 : std::min<GLuint>(mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
2697
Jamie Madill231c7f52017-04-26 13:45:37 -04002698 mCaps.maxVertexUniformBlocks = std::min<GLuint>(
2699 mCaps.maxVertexUniformBlocks, IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
2700 mCaps.maxVertexOutputComponents =
2701 std::min<GLuint>(mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
Geoff Lang301d1612014-07-09 10:34:37 -04002702
Jamie Madill231c7f52017-04-26 13:45:37 -04002703 mCaps.maxFragmentInputComponents =
2704 std::min<GLuint>(mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
Geoff Lang3a61c322014-07-10 13:01:54 -04002705
Geoff Langc287ea62016-09-16 14:46:51 -04002706 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002707 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04002708 for (const auto &extensionInfo : GetExtensionInfoMap())
2709 {
2710 // If this context is for WebGL, disable all enableable extensions
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002711 if (mWebGLContext && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04002712 {
2713 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
2714 }
2715 }
2716
2717 // Generate texture caps
2718 updateCaps();
2719}
2720
2721void Context::updateCaps()
2722{
Geoff Lang900013c2014-07-07 11:32:19 -04002723 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002724 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04002725
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002726 for (auto capsIt : mImplementation->getNativeTextureCaps())
Geoff Lang493daf52014-07-03 13:38:44 -04002727 {
Geoff Langca271392017-04-05 12:30:00 -04002728 GLenum sizedInternalFormat = capsIt.first;
Jamie Madill231c7f52017-04-26 13:45:37 -04002729 TextureCaps formatCaps = capsIt.second;
Geoff Lang493daf52014-07-03 13:38:44 -04002730
Geoff Langca271392017-04-05 12:30:00 -04002731 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04002732
Geoff Lang0d8b7242015-09-09 14:56:53 -04002733 // Update the format caps based on the client version and extensions.
2734 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
2735 // ES3.
2736 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002737 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002738 formatCaps.renderable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002739 formatCaps.renderable && formatInfo.renderSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002740 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002741 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04002742
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002743 // OpenGL ES does not support multisampling with non-rendererable formats
2744 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Olli Etuaho50c562d2017-06-06 14:43:30 +03002745 if (!formatCaps.renderable ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002746 (getClientVersion() < ES_3_1 &&
2747 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04002748 {
Geoff Langd87878e2014-09-19 15:42:59 -04002749 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04002750 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03002751 else
2752 {
2753 // We may have limited the max samples for some required renderbuffer formats due to
2754 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
2755 GLuint formatMaxSamples = formatCaps.getMaxSamples();
2756
2757 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
2758 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
2759 // exception of signed and unsigned integer formats."
2760 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
2761 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
2762 {
2763 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
2764 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
2765 }
2766
2767 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
2768 if (getClientVersion() >= ES_3_1)
2769 {
2770 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
2771 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
2772 // the exception that the signed and unsigned integer formats are required only to
2773 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
2774 // multisamples, which must be at least one."
2775 if (formatInfo.componentType == GL_INT ||
2776 formatInfo.componentType == GL_UNSIGNED_INT)
2777 {
2778 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
2779 }
2780
2781 // GLES 3.1 section 19.3.1.
2782 if (formatCaps.texturable)
2783 {
2784 if (formatInfo.depthBits > 0)
2785 {
2786 mCaps.maxDepthTextureSamples =
2787 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
2788 }
2789 else if (formatInfo.redBits > 0)
2790 {
2791 mCaps.maxColorTextureSamples =
2792 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
2793 }
2794 }
2795 }
2796 }
Geoff Langd87878e2014-09-19 15:42:59 -04002797
2798 if (formatCaps.texturable && formatInfo.compressed)
2799 {
Geoff Langca271392017-04-05 12:30:00 -04002800 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04002801 }
2802
Geoff Langca271392017-04-05 12:30:00 -04002803 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04002804 }
Jamie Madill32447362017-06-28 14:53:52 -04002805
2806 // If program binary is disabled, blank out the memory cache pointer.
2807 if (!mImplementation->getNativeExtensions().getProgramBinary)
2808 {
2809 mMemoryProgramCache = nullptr;
2810 }
Geoff Lang493daf52014-07-03 13:38:44 -04002811}
2812
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002813void Context::initWorkarounds()
2814{
Jamie Madill761b02c2017-06-23 16:27:06 -04002815 // Apply back-end workarounds.
2816 mImplementation->applyNativeWorkarounds(&mWorkarounds);
2817
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002818 // Lose the context upon out of memory error if the application is
2819 // expecting to watch for those events.
2820 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2821}
2822
Jamie Madillb6664922017-07-25 12:55:04 -04002823Error Context::prepareForDraw()
2824{
2825 syncRendererState();
2826 return NoError();
2827}
2828
Jamie Madill1b94d432015-08-07 13:23:23 -04002829void Context::syncRendererState()
2830{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002831 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
Jamie Madillfe548342017-06-19 11:13:24 -04002832 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002833 mGLState.clearDirtyBits();
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002834 mGLState.syncDirtyObjects(this);
Jamie Madill1b94d432015-08-07 13:23:23 -04002835}
2836
Jamie Madillad9f24e2016-02-12 09:27:24 -05002837void Context::syncRendererState(const State::DirtyBits &bitMask,
2838 const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04002839{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002840 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madillfe548342017-06-19 11:13:24 -04002841 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002842 mGLState.clearDirtyBits(dirtyBits);
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002843 mGLState.syncDirtyObjects(this, objectMask);
Jamie Madill1b94d432015-08-07 13:23:23 -04002844}
Jamie Madillc29968b2016-01-20 11:17:23 -05002845
2846void Context::blitFramebuffer(GLint srcX0,
2847 GLint srcY0,
2848 GLint srcX1,
2849 GLint srcY1,
2850 GLint dstX0,
2851 GLint dstY0,
2852 GLint dstX1,
2853 GLint dstY1,
2854 GLbitfield mask,
2855 GLenum filter)
2856{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002857 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002858 ASSERT(drawFramebuffer);
2859
2860 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
2861 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
2862
Jamie Madillad9f24e2016-02-12 09:27:24 -05002863 syncStateForBlit();
Jamie Madillc29968b2016-01-20 11:17:23 -05002864
Jamie Madillc564c072017-06-01 12:45:42 -04002865 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002866}
Jamie Madillc29968b2016-01-20 11:17:23 -05002867
2868void Context::clear(GLbitfield mask)
2869{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002870 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002871 handleError(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05002872}
2873
2874void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
2875{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002876 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002877 handleError(mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002878}
2879
2880void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
2881{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002882 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002883 handleError(mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002884}
2885
2886void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
2887{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002888 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002889 handleError(mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002890}
2891
2892void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
2893{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002894 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002895 ASSERT(framebufferObject);
2896
2897 // If a buffer is not present, the clear has no effect
2898 if (framebufferObject->getDepthbuffer() == nullptr &&
2899 framebufferObject->getStencilbuffer() == nullptr)
2900 {
2901 return;
2902 }
2903
Jamie Madillad9f24e2016-02-12 09:27:24 -05002904 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002905 handleError(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05002906}
2907
2908void Context::readPixels(GLint x,
2909 GLint y,
2910 GLsizei width,
2911 GLsizei height,
2912 GLenum format,
2913 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002914 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05002915{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04002916 if (width == 0 || height == 0)
2917 {
2918 return;
2919 }
2920
Jamie Madillad9f24e2016-02-12 09:27:24 -05002921 syncStateForReadPixels();
Jamie Madillc29968b2016-01-20 11:17:23 -05002922
Jamie Madillb6664922017-07-25 12:55:04 -04002923 Framebuffer *readFBO = mGLState.getReadFramebuffer();
2924 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05002925
2926 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04002927 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05002928}
2929
2930void Context::copyTexImage2D(GLenum target,
2931 GLint level,
2932 GLenum internalformat,
2933 GLint x,
2934 GLint y,
2935 GLsizei width,
2936 GLsizei height,
2937 GLint border)
2938{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002939 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002940 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002941
Jamie Madillc29968b2016-01-20 11:17:23 -05002942 Rectangle sourceArea(x, y, width, height);
2943
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002944 const Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002945 Texture *texture =
2946 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05002947 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05002948}
2949
2950void Context::copyTexSubImage2D(GLenum target,
2951 GLint level,
2952 GLint xoffset,
2953 GLint yoffset,
2954 GLint x,
2955 GLint y,
2956 GLsizei width,
2957 GLsizei height)
2958{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04002959 if (width == 0 || height == 0)
2960 {
2961 return;
2962 }
2963
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002964 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002965 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002966
Jamie Madillc29968b2016-01-20 11:17:23 -05002967 Offset destOffset(xoffset, yoffset, 0);
2968 Rectangle sourceArea(x, y, width, height);
2969
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002970 const Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002971 Texture *texture =
2972 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05002973 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05002974}
2975
2976void Context::copyTexSubImage3D(GLenum target,
2977 GLint level,
2978 GLint xoffset,
2979 GLint yoffset,
2980 GLint zoffset,
2981 GLint x,
2982 GLint y,
2983 GLsizei width,
2984 GLsizei height)
2985{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04002986 if (width == 0 || height == 0)
2987 {
2988 return;
2989 }
2990
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002991 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002992 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002993
Jamie Madillc29968b2016-01-20 11:17:23 -05002994 Offset destOffset(xoffset, yoffset, zoffset);
2995 Rectangle sourceArea(x, y, width, height);
2996
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002997 const Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002998 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05002999 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003000}
3001
3002void Context::framebufferTexture2D(GLenum target,
3003 GLenum attachment,
3004 GLenum textarget,
3005 GLuint texture,
3006 GLint level)
3007{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003008 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003009 ASSERT(framebuffer);
3010
3011 if (texture != 0)
3012 {
3013 Texture *textureObj = getTexture(texture);
3014
3015 ImageIndex index = ImageIndex::MakeInvalid();
3016
3017 if (textarget == GL_TEXTURE_2D)
3018 {
3019 index = ImageIndex::Make2D(level);
3020 }
JiangYizhoubddc46b2016-12-09 09:50:51 +08003021 else if (textarget == GL_TEXTURE_2D_MULTISAMPLE)
3022 {
3023 ASSERT(level == 0);
3024 index = ImageIndex::Make2DMultisample();
3025 }
Jamie Madillc29968b2016-01-20 11:17:23 -05003026 else
3027 {
3028 ASSERT(IsCubeMapTextureTarget(textarget));
3029 index = ImageIndex::MakeCube(textarget, level);
3030 }
3031
Jamie Madilla02315b2017-02-23 14:14:47 -05003032 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003033 }
3034 else
3035 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003036 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003037 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003038
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003039 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003040}
3041
3042void Context::framebufferRenderbuffer(GLenum target,
3043 GLenum attachment,
3044 GLenum renderbuffertarget,
3045 GLuint renderbuffer)
3046{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003047 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003048 ASSERT(framebuffer);
3049
3050 if (renderbuffer != 0)
3051 {
3052 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003053
3054 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex::MakeInvalid(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003055 renderbufferObject);
3056 }
3057 else
3058 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003059 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003060 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003061
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003062 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003063}
3064
3065void Context::framebufferTextureLayer(GLenum target,
3066 GLenum attachment,
3067 GLuint texture,
3068 GLint level,
3069 GLint layer)
3070{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003071 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003072 ASSERT(framebuffer);
3073
3074 if (texture != 0)
3075 {
3076 Texture *textureObject = getTexture(texture);
3077
3078 ImageIndex index = ImageIndex::MakeInvalid();
3079
3080 if (textureObject->getTarget() == GL_TEXTURE_3D)
3081 {
3082 index = ImageIndex::Make3D(level, layer);
3083 }
3084 else
3085 {
3086 ASSERT(textureObject->getTarget() == GL_TEXTURE_2D_ARRAY);
3087 index = ImageIndex::Make2DArray(level, layer);
3088 }
3089
Jamie Madilla02315b2017-02-23 14:14:47 -05003090 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003091 }
3092 else
3093 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003094 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003095 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003096
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003097 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003098}
3099
Martin Radev137032d2017-07-13 10:11:12 +03003100void Context::framebufferTextureMultiviewLayeredANGLE(GLenum target,
3101 GLenum attachment,
3102 GLuint texture,
3103 GLint level,
3104 GLint baseViewIndex,
3105 GLsizei numViews)
3106{
3107 UNIMPLEMENTED();
3108}
3109
3110void Context::framebufferTextureMultiviewSideBySideANGLE(GLenum target,
3111 GLenum attachment,
3112 GLuint texture,
3113 GLint level,
3114 GLsizei numViews,
3115 const GLint *viewportOffsets)
3116{
Martin Radev5dae57b2017-07-14 16:15:55 +03003117 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3118 ASSERT(framebuffer);
3119
3120 if (texture != 0)
3121 {
3122 Texture *textureObj = getTexture(texture);
3123
3124 ImageIndex index = ImageIndex::Make2D(level);
3125 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3126 textureObj, numViews, viewportOffsets);
3127 }
3128 else
3129 {
3130 framebuffer->resetAttachment(this, attachment);
3131 }
3132
3133 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003134}
3135
Jamie Madillc29968b2016-01-20 11:17:23 -05003136void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3137{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003138 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003139 ASSERT(framebuffer);
3140 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003141 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003142}
3143
3144void Context::readBuffer(GLenum mode)
3145{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003146 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003147 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003148 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003149}
3150
3151void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3152{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003153 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003154 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003155
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003156 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003157 ASSERT(framebuffer);
3158
3159 // The specification isn't clear what should be done when the framebuffer isn't complete.
3160 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003161 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003162}
3163
3164void Context::invalidateFramebuffer(GLenum target,
3165 GLsizei numAttachments,
3166 const GLenum *attachments)
3167{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003168 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003169 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003170
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003171 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003172 ASSERT(framebuffer);
3173
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003174 if (framebuffer->checkStatus(this) != GL_FRAMEBUFFER_COMPLETE)
Jamie Madillc29968b2016-01-20 11:17:23 -05003175 {
Jamie Madill437fa652016-05-03 15:13:24 -04003176 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003177 }
Jamie Madill437fa652016-05-03 15:13:24 -04003178
Jamie Madill4928b7c2017-06-20 12:57:39 -04003179 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003180}
3181
3182void Context::invalidateSubFramebuffer(GLenum target,
3183 GLsizei numAttachments,
3184 const GLenum *attachments,
3185 GLint x,
3186 GLint y,
3187 GLsizei width,
3188 GLsizei height)
3189{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003190 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003191 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003192
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003193 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003194 ASSERT(framebuffer);
3195
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003196 if (framebuffer->checkStatus(this) != GL_FRAMEBUFFER_COMPLETE)
Jamie Madillc29968b2016-01-20 11:17:23 -05003197 {
Jamie Madill437fa652016-05-03 15:13:24 -04003198 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003199 }
Jamie Madill437fa652016-05-03 15:13:24 -04003200
3201 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003202 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003203}
3204
Jamie Madill73a84962016-02-12 09:27:23 -05003205void Context::texImage2D(GLenum target,
3206 GLint level,
3207 GLint internalformat,
3208 GLsizei width,
3209 GLsizei height,
3210 GLint border,
3211 GLenum format,
3212 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003213 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003214{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003215 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003216
3217 Extents size(width, height, 1);
3218 Texture *texture =
3219 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003220 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3221 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003222}
3223
3224void Context::texImage3D(GLenum target,
3225 GLint level,
3226 GLint internalformat,
3227 GLsizei width,
3228 GLsizei height,
3229 GLsizei depth,
3230 GLint border,
3231 GLenum format,
3232 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003233 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003234{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003235 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003236
3237 Extents size(width, height, depth);
3238 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003239 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3240 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003241}
3242
3243void Context::texSubImage2D(GLenum target,
3244 GLint level,
3245 GLint xoffset,
3246 GLint yoffset,
3247 GLsizei width,
3248 GLsizei height,
3249 GLenum format,
3250 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003251 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003252{
3253 // Zero sized uploads are valid but no-ops
3254 if (width == 0 || height == 0)
3255 {
3256 return;
3257 }
3258
Jamie Madillad9f24e2016-02-12 09:27:24 -05003259 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003260
3261 Box area(xoffset, yoffset, 0, width, height, 1);
3262 Texture *texture =
3263 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003264 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3265 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003266}
3267
3268void Context::texSubImage3D(GLenum target,
3269 GLint level,
3270 GLint xoffset,
3271 GLint yoffset,
3272 GLint zoffset,
3273 GLsizei width,
3274 GLsizei height,
3275 GLsizei depth,
3276 GLenum format,
3277 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003278 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003279{
3280 // Zero sized uploads are valid but no-ops
3281 if (width == 0 || height == 0 || depth == 0)
3282 {
3283 return;
3284 }
3285
Jamie Madillad9f24e2016-02-12 09:27:24 -05003286 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003287
3288 Box area(xoffset, yoffset, zoffset, width, height, depth);
3289 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003290 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3291 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003292}
3293
3294void Context::compressedTexImage2D(GLenum target,
3295 GLint level,
3296 GLenum internalformat,
3297 GLsizei width,
3298 GLsizei height,
3299 GLint border,
3300 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003301 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003302{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003303 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003304
3305 Extents size(width, height, 1);
3306 Texture *texture =
3307 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003308 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003309 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003310 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003311}
3312
3313void Context::compressedTexImage3D(GLenum target,
3314 GLint level,
3315 GLenum internalformat,
3316 GLsizei width,
3317 GLsizei height,
3318 GLsizei depth,
3319 GLint border,
3320 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003321 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003322{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003323 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003324
3325 Extents size(width, height, depth);
3326 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003327 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003328 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003329 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003330}
3331
3332void Context::compressedTexSubImage2D(GLenum target,
3333 GLint level,
3334 GLint xoffset,
3335 GLint yoffset,
3336 GLsizei width,
3337 GLsizei height,
3338 GLenum format,
3339 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003340 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003341{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003342 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003343
3344 Box area(xoffset, yoffset, 0, width, height, 1);
3345 Texture *texture =
3346 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003347 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003348 format, imageSize,
3349 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003350}
3351
3352void Context::compressedTexSubImage3D(GLenum target,
3353 GLint level,
3354 GLint xoffset,
3355 GLint yoffset,
3356 GLint zoffset,
3357 GLsizei width,
3358 GLsizei height,
3359 GLsizei depth,
3360 GLenum format,
3361 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003362 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003363{
3364 // Zero sized uploads are valid but no-ops
3365 if (width == 0 || height == 0)
3366 {
3367 return;
3368 }
3369
Jamie Madillad9f24e2016-02-12 09:27:24 -05003370 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003371
3372 Box area(xoffset, yoffset, zoffset, width, height, depth);
3373 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003374 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003375 format, imageSize,
3376 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003377}
3378
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003379void Context::generateMipmap(GLenum target)
3380{
3381 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003382 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003383}
3384
Geoff Lang97073d12016-04-20 10:42:34 -07003385void Context::copyTextureCHROMIUM(GLuint sourceId,
Geoff Langfc72a072017-03-24 14:52:39 -04003386 GLint sourceLevel,
3387 GLenum destTarget,
Geoff Lang97073d12016-04-20 10:42:34 -07003388 GLuint destId,
Geoff Langfc72a072017-03-24 14:52:39 -04003389 GLint destLevel,
Geoff Lang97073d12016-04-20 10:42:34 -07003390 GLint internalFormat,
3391 GLenum destType,
3392 GLboolean unpackFlipY,
3393 GLboolean unpackPremultiplyAlpha,
3394 GLboolean unpackUnmultiplyAlpha)
3395{
3396 syncStateForTexImage();
3397
3398 gl::Texture *sourceTexture = getTexture(sourceId);
3399 gl::Texture *destTexture = getTexture(destId);
Geoff Langfc72a072017-03-24 14:52:39 -04003400 handleError(destTexture->copyTexture(
3401 this, destTarget, destLevel, internalFormat, destType, sourceLevel, unpackFlipY == GL_TRUE,
3402 unpackPremultiplyAlpha == GL_TRUE, unpackUnmultiplyAlpha == GL_TRUE, sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003403}
3404
3405void Context::copySubTextureCHROMIUM(GLuint sourceId,
Geoff Langfc72a072017-03-24 14:52:39 -04003406 GLint sourceLevel,
3407 GLenum destTarget,
Geoff Lang97073d12016-04-20 10:42:34 -07003408 GLuint destId,
Geoff Langfc72a072017-03-24 14:52:39 -04003409 GLint destLevel,
Geoff Lang97073d12016-04-20 10:42:34 -07003410 GLint xoffset,
3411 GLint yoffset,
3412 GLint x,
3413 GLint y,
3414 GLsizei width,
3415 GLsizei height,
3416 GLboolean unpackFlipY,
3417 GLboolean unpackPremultiplyAlpha,
3418 GLboolean unpackUnmultiplyAlpha)
3419{
3420 // Zero sized copies are valid but no-ops
3421 if (width == 0 || height == 0)
3422 {
3423 return;
3424 }
3425
3426 syncStateForTexImage();
3427
3428 gl::Texture *sourceTexture = getTexture(sourceId);
3429 gl::Texture *destTexture = getTexture(destId);
3430 Offset offset(xoffset, yoffset, 0);
3431 Rectangle area(x, y, width, height);
Geoff Langfc72a072017-03-24 14:52:39 -04003432 handleError(destTexture->copySubTexture(
3433 this, destTarget, destLevel, offset, sourceLevel, area, unpackFlipY == GL_TRUE,
3434 unpackPremultiplyAlpha == GL_TRUE, unpackUnmultiplyAlpha == GL_TRUE, sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003435}
3436
Geoff Lang47110bf2016-04-20 11:13:22 -07003437void Context::compressedCopyTextureCHROMIUM(GLuint sourceId, GLuint destId)
3438{
3439 syncStateForTexImage();
3440
3441 gl::Texture *sourceTexture = getTexture(sourceId);
3442 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05003443 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07003444}
3445
Geoff Lang496c02d2016-10-20 11:38:11 -07003446void Context::getBufferPointerv(GLenum target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03003447{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003448 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003449 ASSERT(buffer);
3450
Geoff Lang496c02d2016-10-20 11:38:11 -07003451 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03003452}
3453
Jamie Madill876429b2017-04-20 15:46:24 -04003454void *Context::mapBuffer(GLenum target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003455{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003456 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003457 ASSERT(buffer);
3458
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003459 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003460 if (error.isError())
3461 {
Jamie Madill437fa652016-05-03 15:13:24 -04003462 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003463 return nullptr;
3464 }
3465
3466 return buffer->getMapPointer();
3467}
3468
3469GLboolean Context::unmapBuffer(GLenum target)
3470{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003471 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003472 ASSERT(buffer);
3473
3474 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003475 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03003476 if (error.isError())
3477 {
Jamie Madill437fa652016-05-03 15:13:24 -04003478 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003479 return GL_FALSE;
3480 }
3481
3482 return result;
3483}
3484
Jamie Madill876429b2017-04-20 15:46:24 -04003485void *Context::mapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003486{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003487 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003488 ASSERT(buffer);
3489
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003490 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003491 if (error.isError())
3492 {
Jamie Madill437fa652016-05-03 15:13:24 -04003493 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003494 return nullptr;
3495 }
3496
3497 return buffer->getMapPointer();
3498}
3499
3500void Context::flushMappedBufferRange(GLenum /*target*/, GLintptr /*offset*/, GLsizeiptr /*length*/)
3501{
3502 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
3503}
3504
Jamie Madillad9f24e2016-02-12 09:27:24 -05003505void Context::syncStateForReadPixels()
3506{
3507 syncRendererState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
3508}
3509
3510void Context::syncStateForTexImage()
3511{
3512 syncRendererState(mTexImageDirtyBits, mTexImageDirtyObjects);
3513}
3514
3515void Context::syncStateForClear()
3516{
3517 syncRendererState(mClearDirtyBits, mClearDirtyObjects);
3518}
3519
3520void Context::syncStateForBlit()
3521{
3522 syncRendererState(mBlitDirtyBits, mBlitDirtyObjects);
3523}
3524
Jamie Madillc20ab272016-06-09 07:20:46 -07003525void Context::activeTexture(GLenum texture)
3526{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003527 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003528}
3529
Jamie Madill876429b2017-04-20 15:46:24 -04003530void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003531{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003532 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07003533}
3534
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003535void Context::blendEquation(GLenum mode)
3536{
3537 mGLState.setBlendEquation(mode, mode);
3538}
3539
Jamie Madillc20ab272016-06-09 07:20:46 -07003540void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
3541{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003542 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003543}
3544
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003545void Context::blendFunc(GLenum sfactor, GLenum dfactor)
3546{
3547 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
3548}
3549
Jamie Madillc20ab272016-06-09 07:20:46 -07003550void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
3551{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003552 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003553}
3554
Jamie Madill876429b2017-04-20 15:46:24 -04003555void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003556{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003557 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003558}
3559
Jamie Madill876429b2017-04-20 15:46:24 -04003560void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07003561{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003562 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07003563}
3564
3565void Context::clearStencil(GLint s)
3566{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003567 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07003568}
3569
3570void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
3571{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003572 mGLState.setColorMask(red == GL_TRUE, green == GL_TRUE, blue == GL_TRUE, alpha == GL_TRUE);
Jamie Madillc20ab272016-06-09 07:20:46 -07003573}
3574
3575void Context::cullFace(GLenum mode)
3576{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003577 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003578}
3579
3580void Context::depthFunc(GLenum func)
3581{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003582 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07003583}
3584
3585void Context::depthMask(GLboolean flag)
3586{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003587 mGLState.setDepthMask(flag != GL_FALSE);
Jamie Madillc20ab272016-06-09 07:20:46 -07003588}
3589
Jamie Madill876429b2017-04-20 15:46:24 -04003590void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07003591{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003592 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07003593}
3594
3595void Context::disable(GLenum cap)
3596{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003597 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003598}
3599
3600void Context::disableVertexAttribArray(GLuint index)
3601{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003602 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003603}
3604
3605void Context::enable(GLenum cap)
3606{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003607 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003608}
3609
3610void Context::enableVertexAttribArray(GLuint index)
3611{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003612 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003613}
3614
3615void Context::frontFace(GLenum mode)
3616{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003617 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003618}
3619
3620void Context::hint(GLenum target, GLenum mode)
3621{
3622 switch (target)
3623 {
3624 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003625 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003626 break;
3627
3628 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003629 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003630 break;
3631
3632 default:
3633 UNREACHABLE();
3634 return;
3635 }
3636}
3637
3638void Context::lineWidth(GLfloat width)
3639{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003640 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07003641}
3642
3643void Context::pixelStorei(GLenum pname, GLint param)
3644{
3645 switch (pname)
3646 {
3647 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003648 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003649 break;
3650
3651 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003652 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003653 break;
3654
3655 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003656 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003657 break;
3658
3659 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003660 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003661 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003662 break;
3663
3664 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03003665 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003666 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003667 break;
3668
3669 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03003670 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003671 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003672 break;
3673
3674 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003675 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003676 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003677 break;
3678
3679 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003680 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003681 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003682 break;
3683
3684 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003685 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003686 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003687 break;
3688
3689 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003690 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003691 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003692 break;
3693
3694 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003695 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003696 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003697 break;
3698
3699 default:
3700 UNREACHABLE();
3701 return;
3702 }
3703}
3704
3705void Context::polygonOffset(GLfloat factor, GLfloat units)
3706{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003707 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07003708}
3709
Jamie Madill876429b2017-04-20 15:46:24 -04003710void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07003711{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003712 mGLState.setSampleCoverageParams(clamp01(value), invert == GL_TRUE);
Jamie Madillc20ab272016-06-09 07:20:46 -07003713}
3714
3715void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
3716{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003717 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07003718}
3719
3720void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
3721{
3722 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3723 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003724 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003725 }
3726
3727 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3728 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003729 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003730 }
3731}
3732
3733void Context::stencilMaskSeparate(GLenum face, GLuint mask)
3734{
3735 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3736 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003737 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003738 }
3739
3740 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3741 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003742 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003743 }
3744}
3745
3746void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
3747{
3748 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3749 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003750 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003751 }
3752
3753 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3754 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003755 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003756 }
3757}
3758
3759void Context::vertexAttrib1f(GLuint index, GLfloat x)
3760{
3761 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003762 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003763}
3764
3765void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
3766{
3767 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003768 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003769}
3770
3771void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
3772{
3773 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003774 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003775}
3776
3777void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
3778{
3779 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003780 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003781}
3782
3783void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
3784{
3785 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003786 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003787}
3788
3789void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
3790{
3791 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003792 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003793}
3794
3795void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
3796{
3797 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003798 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003799}
3800
3801void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
3802{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003803 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07003804}
3805
3806void Context::vertexAttribPointer(GLuint index,
3807 GLint size,
3808 GLenum type,
3809 GLboolean normalized,
3810 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04003811 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07003812{
Shaodde78e82017-05-22 14:13:27 +08003813 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(GL_ARRAY_BUFFER), size,
3814 type, normalized == GL_TRUE, false, stride, ptr);
Jamie Madillc20ab272016-06-09 07:20:46 -07003815}
3816
Shao80957d92017-02-20 21:25:59 +08003817void Context::vertexAttribFormat(GLuint attribIndex,
3818 GLint size,
3819 GLenum type,
3820 GLboolean normalized,
3821 GLuint relativeOffset)
3822{
3823 mGLState.setVertexAttribFormat(attribIndex, size, type, normalized == GL_TRUE, false,
3824 relativeOffset);
3825}
3826
3827void Context::vertexAttribIFormat(GLuint attribIndex,
3828 GLint size,
3829 GLenum type,
3830 GLuint relativeOffset)
3831{
3832 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
3833}
3834
3835void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
3836{
Shaodde78e82017-05-22 14:13:27 +08003837 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Shao80957d92017-02-20 21:25:59 +08003838}
3839
3840void Context::setVertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
3841{
3842 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
3843}
3844
Jamie Madillc20ab272016-06-09 07:20:46 -07003845void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
3846{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003847 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07003848}
3849
3850void Context::vertexAttribIPointer(GLuint index,
3851 GLint size,
3852 GLenum type,
3853 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04003854 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07003855{
Shaodde78e82017-05-22 14:13:27 +08003856 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(GL_ARRAY_BUFFER), size,
3857 type, false, true, stride, pointer);
Jamie Madillc20ab272016-06-09 07:20:46 -07003858}
3859
3860void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
3861{
3862 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003863 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003864}
3865
3866void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
3867{
3868 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003869 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003870}
3871
3872void Context::vertexAttribI4iv(GLuint index, const GLint *v)
3873{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003874 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07003875}
3876
3877void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
3878{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003879 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07003880}
3881
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003882void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
3883{
3884 const VertexAttribCurrentValueData &currentValues =
3885 getGLState().getVertexAttribCurrentValue(index);
3886 const VertexArray *vao = getGLState().getVertexArray();
3887 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3888 currentValues, pname, params);
3889}
3890
3891void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
3892{
3893 const VertexAttribCurrentValueData &currentValues =
3894 getGLState().getVertexAttribCurrentValue(index);
3895 const VertexArray *vao = getGLState().getVertexArray();
3896 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3897 currentValues, pname, params);
3898}
3899
3900void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
3901{
3902 const VertexAttribCurrentValueData &currentValues =
3903 getGLState().getVertexAttribCurrentValue(index);
3904 const VertexArray *vao = getGLState().getVertexArray();
3905 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3906 currentValues, pname, params);
3907}
3908
3909void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
3910{
3911 const VertexAttribCurrentValueData &currentValues =
3912 getGLState().getVertexAttribCurrentValue(index);
3913 const VertexArray *vao = getGLState().getVertexArray();
3914 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3915 currentValues, pname, params);
3916}
3917
Jamie Madill876429b2017-04-20 15:46:24 -04003918void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003919{
3920 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
3921 QueryVertexAttribPointerv(attrib, pname, pointer);
3922}
3923
Jamie Madillc20ab272016-06-09 07:20:46 -07003924void Context::debugMessageControl(GLenum source,
3925 GLenum type,
3926 GLenum severity,
3927 GLsizei count,
3928 const GLuint *ids,
3929 GLboolean enabled)
3930{
3931 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003932 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
3933 (enabled != GL_FALSE));
Jamie Madillc20ab272016-06-09 07:20:46 -07003934}
3935
3936void Context::debugMessageInsert(GLenum source,
3937 GLenum type,
3938 GLuint id,
3939 GLenum severity,
3940 GLsizei length,
3941 const GLchar *buf)
3942{
3943 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003944 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07003945}
3946
3947void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
3948{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003949 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07003950}
3951
3952GLuint Context::getDebugMessageLog(GLuint count,
3953 GLsizei bufSize,
3954 GLenum *sources,
3955 GLenum *types,
3956 GLuint *ids,
3957 GLenum *severities,
3958 GLsizei *lengths,
3959 GLchar *messageLog)
3960{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003961 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
3962 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07003963}
3964
3965void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
3966{
3967 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003968 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07003969}
3970
3971void Context::popDebugGroup()
3972{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003973 mGLState.getDebug().popGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07003974}
3975
Jamie Madill876429b2017-04-20 15:46:24 -04003976void Context::bufferData(GLenum target, GLsizeiptr size, const void *data, GLenum usage)
Jamie Madill29639852016-09-02 15:00:09 -04003977{
3978 Buffer *buffer = mGLState.getTargetBuffer(target);
3979 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08003980 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04003981}
3982
Jamie Madill876429b2017-04-20 15:46:24 -04003983void Context::bufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04003984{
3985 if (data == nullptr)
3986 {
3987 return;
3988 }
3989
3990 Buffer *buffer = mGLState.getTargetBuffer(target);
3991 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08003992 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04003993}
3994
Jamie Madillef300b12016-10-07 15:12:09 -04003995void Context::attachShader(GLuint program, GLuint shader)
3996{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05003997 auto programObject = mState.mShaderPrograms->getProgram(program);
3998 auto shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04003999 ASSERT(programObject && shaderObject);
4000 programObject->attachShader(shaderObject);
4001}
4002
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004003const Workarounds &Context::getWorkarounds() const
4004{
4005 return mWorkarounds;
4006}
4007
Jamie Madillb0817d12016-11-01 15:48:31 -04004008void Context::copyBufferSubData(GLenum readTarget,
4009 GLenum writeTarget,
4010 GLintptr readOffset,
4011 GLintptr writeOffset,
4012 GLsizeiptr size)
4013{
4014 // if size is zero, the copy is a successful no-op
4015 if (size == 0)
4016 {
4017 return;
4018 }
4019
4020 // TODO(jmadill): cache these.
4021 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4022 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4023
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004024 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004025}
4026
Jamie Madill01a80ee2016-11-07 12:06:18 -05004027void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4028{
4029 Program *programObject = getProgram(program);
4030 // TODO(jmadill): Re-use this from the validation if possible.
4031 ASSERT(programObject);
4032 programObject->bindAttributeLocation(index, name);
4033}
4034
4035void Context::bindBuffer(GLenum target, GLuint buffer)
4036{
4037 switch (target)
4038 {
4039 case GL_ARRAY_BUFFER:
4040 bindArrayBuffer(buffer);
4041 break;
4042 case GL_ELEMENT_ARRAY_BUFFER:
4043 bindElementArrayBuffer(buffer);
4044 break;
4045 case GL_COPY_READ_BUFFER:
4046 bindCopyReadBuffer(buffer);
4047 break;
4048 case GL_COPY_WRITE_BUFFER:
4049 bindCopyWriteBuffer(buffer);
4050 break;
4051 case GL_PIXEL_PACK_BUFFER:
4052 bindPixelPackBuffer(buffer);
4053 break;
4054 case GL_PIXEL_UNPACK_BUFFER:
4055 bindPixelUnpackBuffer(buffer);
4056 break;
4057 case GL_UNIFORM_BUFFER:
4058 bindGenericUniformBuffer(buffer);
4059 break;
4060 case GL_TRANSFORM_FEEDBACK_BUFFER:
4061 bindGenericTransformFeedbackBuffer(buffer);
4062 break;
Geoff Lang3b573612016-10-31 14:08:10 -04004063 case GL_ATOMIC_COUNTER_BUFFER:
Jiajia Qin6eafb042016-12-27 17:04:07 +08004064 bindGenericAtomicCounterBuffer(buffer);
Geoff Lang3b573612016-10-31 14:08:10 -04004065 break;
4066 case GL_SHADER_STORAGE_BUFFER:
Jiajia Qinf546e7d2017-03-27 14:12:59 +08004067 bindGenericShaderStorageBuffer(buffer);
Geoff Lang3b573612016-10-31 14:08:10 -04004068 break;
4069 case GL_DRAW_INDIRECT_BUFFER:
Jiajia Qin9d7d0b12016-11-29 16:30:31 +08004070 bindDrawIndirectBuffer(buffer);
Geoff Lang3b573612016-10-31 14:08:10 -04004071 break;
4072 case GL_DISPATCH_INDIRECT_BUFFER:
Geoff Lang9f090372016-12-02 10:20:43 -05004073 if (buffer != 0)
4074 {
4075 // Binding buffers to this binding point is not implemented yet.
4076 UNIMPLEMENTED();
4077 }
Geoff Lang3b573612016-10-31 14:08:10 -04004078 break;
Jamie Madill01a80ee2016-11-07 12:06:18 -05004079
4080 default:
4081 UNREACHABLE();
4082 break;
4083 }
4084}
4085
Jiajia Qin6eafb042016-12-27 17:04:07 +08004086void Context::bindBufferBase(GLenum target, GLuint index, GLuint buffer)
4087{
4088 bindBufferRange(target, index, buffer, 0, 0);
4089}
4090
4091void Context::bindBufferRange(GLenum target,
4092 GLuint index,
4093 GLuint buffer,
4094 GLintptr offset,
4095 GLsizeiptr size)
4096{
4097 switch (target)
4098 {
4099 case GL_TRANSFORM_FEEDBACK_BUFFER:
4100 bindIndexedTransformFeedbackBuffer(buffer, index, offset, size);
4101 bindGenericTransformFeedbackBuffer(buffer);
4102 break;
4103 case GL_UNIFORM_BUFFER:
4104 bindIndexedUniformBuffer(buffer, index, offset, size);
4105 bindGenericUniformBuffer(buffer);
4106 break;
4107 case GL_ATOMIC_COUNTER_BUFFER:
4108 bindIndexedAtomicCounterBuffer(buffer, index, offset, size);
4109 bindGenericAtomicCounterBuffer(buffer);
4110 break;
4111 case GL_SHADER_STORAGE_BUFFER:
Jiajia Qinf546e7d2017-03-27 14:12:59 +08004112 bindIndexedShaderStorageBuffer(buffer, index, offset, size);
4113 bindGenericShaderStorageBuffer(buffer);
Jiajia Qin6eafb042016-12-27 17:04:07 +08004114 break;
4115 default:
4116 UNREACHABLE();
4117 break;
4118 }
4119}
4120
Jamie Madill01a80ee2016-11-07 12:06:18 -05004121void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
4122{
4123 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4124 {
4125 bindReadFramebuffer(framebuffer);
4126 }
4127
4128 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4129 {
4130 bindDrawFramebuffer(framebuffer);
4131 }
4132}
4133
4134void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4135{
4136 ASSERT(target == GL_RENDERBUFFER);
4137 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004138 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04004139 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004140}
4141
JiangYizhoubddc46b2016-12-09 09:50:51 +08004142void Context::texStorage2DMultisample(GLenum target,
4143 GLsizei samples,
4144 GLenum internalformat,
4145 GLsizei width,
4146 GLsizei height,
4147 GLboolean fixedsamplelocations)
4148{
4149 Extents size(width, height, 1);
4150 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05004151 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
JiangYizhoubddc46b2016-12-09 09:50:51 +08004152 fixedsamplelocations));
4153}
4154
4155void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4156{
Jamie Madilldd43e6c2017-03-24 14:18:49 -04004157 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
JiangYizhoubddc46b2016-12-09 09:50:51 +08004158 const Framebuffer *framebuffer = mGLState.getReadFramebuffer();
4159
4160 switch (pname)
4161 {
4162 case GL_SAMPLE_POSITION:
4163 handleError(framebuffer->getSamplePosition(index, val));
4164 break;
4165 default:
4166 UNREACHABLE();
4167 }
4168}
4169
Jamie Madille8fb6402017-02-14 17:56:40 -05004170void Context::renderbufferStorage(GLenum target,
4171 GLenum internalformat,
4172 GLsizei width,
4173 GLsizei height)
4174{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004175 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4176 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
4177
Jamie Madille8fb6402017-02-14 17:56:40 -05004178 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04004179 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004180}
4181
4182void Context::renderbufferStorageMultisample(GLenum target,
4183 GLsizei samples,
4184 GLenum internalformat,
4185 GLsizei width,
4186 GLsizei height)
4187{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004188 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4189 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05004190
4191 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004192 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04004193 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004194}
4195
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004196void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
4197{
4198 const FenceSync *syncObject = getFenceSync(sync);
Geoff Lang82483b92017-04-11 15:33:00 -04004199 handleError(QuerySynciv(syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004200}
4201
JiangYizhoue18e6392017-02-20 10:32:23 +08004202void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
4203{
4204 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4205 QueryFramebufferParameteriv(framebuffer, pname, params);
4206}
4207
4208void Context::setFramebufferParameteri(GLenum target, GLenum pname, GLint param)
4209{
4210 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4211 SetFramebufferParameteri(framebuffer, pname, param);
4212}
4213
Jamie Madillb3f26b92017-07-19 15:07:41 -04004214Error Context::getScratchBuffer(size_t requstedSizeBytes,
4215 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05004216{
Jamie Madillb3f26b92017-07-19 15:07:41 -04004217 if (!mScratchBuffer.get(requstedSizeBytes, scratchBufferOut))
4218 {
4219 return OutOfMemory() << "Failed to allocate internal buffer.";
4220 }
4221 return NoError();
4222}
4223
4224Error Context::getZeroFilledBuffer(size_t requstedSizeBytes,
4225 angle::MemoryBuffer **zeroBufferOut) const
4226{
4227 if (!mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0))
Jamie Madille14951e2017-03-09 18:55:16 -05004228 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004229 return OutOfMemory() << "Failed to allocate internal buffer.";
Jamie Madille14951e2017-03-09 18:55:16 -05004230 }
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004231 return NoError();
Jamie Madille14951e2017-03-09 18:55:16 -05004232}
4233
Xinghua Cao2b396592017-03-29 15:36:04 +08004234void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
4235{
4236 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
4237 {
4238 return;
4239 }
4240
Jamie Madillfe548342017-06-19 11:13:24 -04004241 mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ);
Xinghua Cao2b396592017-03-29 15:36:04 +08004242}
4243
JiangYizhou165361c2017-06-07 14:56:57 +08004244void Context::texStorage2D(GLenum target,
4245 GLsizei levels,
4246 GLenum internalFormat,
4247 GLsizei width,
4248 GLsizei height)
4249{
4250 Extents size(width, height, 1);
4251 Texture *texture = getTargetTexture(target);
4252 handleError(texture->setStorage(this, target, levels, internalFormat, size));
4253}
4254
4255void Context::texStorage3D(GLenum target,
4256 GLsizei levels,
4257 GLenum internalFormat,
4258 GLsizei width,
4259 GLsizei height,
4260 GLsizei depth)
4261{
4262 Extents size(width, height, depth);
4263 Texture *texture = getTargetTexture(target);
4264 handleError(texture->setStorage(this, target, levels, internalFormat, size));
4265}
4266
Jamie Madillc1d770e2017-04-13 17:31:24 -04004267GLenum Context::checkFramebufferStatus(GLenum target)
4268{
4269 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4270 ASSERT(framebuffer);
4271
4272 return framebuffer->checkStatus(this);
4273}
4274
4275void Context::compileShader(GLuint shader)
4276{
4277 Shader *shaderObject = GetValidShader(this, shader);
4278 if (!shaderObject)
4279 {
4280 return;
4281 }
4282 shaderObject->compile(this);
4283}
4284
4285void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
4286{
4287 for (int i = 0; i < n; i++)
4288 {
4289 deleteBuffer(buffers[i]);
4290 }
4291}
4292
4293void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
4294{
4295 for (int i = 0; i < n; i++)
4296 {
4297 if (framebuffers[i] != 0)
4298 {
4299 deleteFramebuffer(framebuffers[i]);
4300 }
4301 }
4302}
4303
4304void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
4305{
4306 for (int i = 0; i < n; i++)
4307 {
4308 deleteRenderbuffer(renderbuffers[i]);
4309 }
4310}
4311
4312void Context::deleteTextures(GLsizei n, const GLuint *textures)
4313{
4314 for (int i = 0; i < n; i++)
4315 {
4316 if (textures[i] != 0)
4317 {
4318 deleteTexture(textures[i]);
4319 }
4320 }
4321}
4322
4323void Context::detachShader(GLuint program, GLuint shader)
4324{
4325 Program *programObject = getProgram(program);
4326 ASSERT(programObject);
4327
4328 Shader *shaderObject = getShader(shader);
4329 ASSERT(shaderObject);
4330
4331 programObject->detachShader(this, shaderObject);
4332}
4333
4334void Context::genBuffers(GLsizei n, GLuint *buffers)
4335{
4336 for (int i = 0; i < n; i++)
4337 {
4338 buffers[i] = createBuffer();
4339 }
4340}
4341
4342void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
4343{
4344 for (int i = 0; i < n; i++)
4345 {
4346 framebuffers[i] = createFramebuffer();
4347 }
4348}
4349
4350void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
4351{
4352 for (int i = 0; i < n; i++)
4353 {
4354 renderbuffers[i] = createRenderbuffer();
4355 }
4356}
4357
4358void Context::genTextures(GLsizei n, GLuint *textures)
4359{
4360 for (int i = 0; i < n; i++)
4361 {
4362 textures[i] = createTexture();
4363 }
4364}
4365
4366void Context::getActiveAttrib(GLuint program,
4367 GLuint index,
4368 GLsizei bufsize,
4369 GLsizei *length,
4370 GLint *size,
4371 GLenum *type,
4372 GLchar *name)
4373{
4374 Program *programObject = getProgram(program);
4375 ASSERT(programObject);
4376 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
4377}
4378
4379void Context::getActiveUniform(GLuint program,
4380 GLuint index,
4381 GLsizei bufsize,
4382 GLsizei *length,
4383 GLint *size,
4384 GLenum *type,
4385 GLchar *name)
4386{
4387 Program *programObject = getProgram(program);
4388 ASSERT(programObject);
4389 programObject->getActiveUniform(index, bufsize, length, size, type, name);
4390}
4391
4392void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
4393{
4394 Program *programObject = getProgram(program);
4395 ASSERT(programObject);
4396 programObject->getAttachedShaders(maxcount, count, shaders);
4397}
4398
4399GLint Context::getAttribLocation(GLuint program, const GLchar *name)
4400{
4401 Program *programObject = getProgram(program);
4402 ASSERT(programObject);
4403 return programObject->getAttributeLocation(name);
4404}
4405
4406void Context::getBooleanv(GLenum pname, GLboolean *params)
4407{
4408 GLenum nativeType;
4409 unsigned int numParams = 0;
4410 getQueryParameterInfo(pname, &nativeType, &numParams);
4411
4412 if (nativeType == GL_BOOL)
4413 {
4414 getBooleanvImpl(pname, params);
4415 }
4416 else
4417 {
4418 CastStateValues(this, nativeType, pname, numParams, params);
4419 }
4420}
4421
4422void Context::getFloatv(GLenum pname, GLfloat *params)
4423{
4424 GLenum nativeType;
4425 unsigned int numParams = 0;
4426 getQueryParameterInfo(pname, &nativeType, &numParams);
4427
4428 if (nativeType == GL_FLOAT)
4429 {
4430 getFloatvImpl(pname, params);
4431 }
4432 else
4433 {
4434 CastStateValues(this, nativeType, pname, numParams, params);
4435 }
4436}
4437
4438void Context::getIntegerv(GLenum pname, GLint *params)
4439{
4440 GLenum nativeType;
4441 unsigned int numParams = 0;
4442 getQueryParameterInfo(pname, &nativeType, &numParams);
4443
4444 if (nativeType == GL_INT)
4445 {
4446 getIntegervImpl(pname, params);
4447 }
4448 else
4449 {
4450 CastStateValues(this, nativeType, pname, numParams, params);
4451 }
4452}
4453
4454void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
4455{
4456 Program *programObject = getProgram(program);
4457 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04004458 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004459}
4460
Jamie Madillbe849e42017-05-02 15:49:00 -04004461void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04004462{
4463 Program *programObject = getProgram(program);
4464 ASSERT(programObject);
4465 programObject->getInfoLog(bufsize, length, infolog);
4466}
4467
4468void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
4469{
4470 Shader *shaderObject = getShader(shader);
4471 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004472 QueryShaderiv(this, shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004473}
4474
4475void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
4476{
4477 Shader *shaderObject = getShader(shader);
4478 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004479 shaderObject->getInfoLog(this, bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004480}
4481
4482void Context::getShaderPrecisionFormat(GLenum shadertype,
4483 GLenum precisiontype,
4484 GLint *range,
4485 GLint *precision)
4486{
4487 // TODO(jmadill): Compute shaders.
4488
4489 switch (shadertype)
4490 {
4491 case GL_VERTEX_SHADER:
4492 switch (precisiontype)
4493 {
4494 case GL_LOW_FLOAT:
4495 mCaps.vertexLowpFloat.get(range, precision);
4496 break;
4497 case GL_MEDIUM_FLOAT:
4498 mCaps.vertexMediumpFloat.get(range, precision);
4499 break;
4500 case GL_HIGH_FLOAT:
4501 mCaps.vertexHighpFloat.get(range, precision);
4502 break;
4503
4504 case GL_LOW_INT:
4505 mCaps.vertexLowpInt.get(range, precision);
4506 break;
4507 case GL_MEDIUM_INT:
4508 mCaps.vertexMediumpInt.get(range, precision);
4509 break;
4510 case GL_HIGH_INT:
4511 mCaps.vertexHighpInt.get(range, precision);
4512 break;
4513
4514 default:
4515 UNREACHABLE();
4516 return;
4517 }
4518 break;
4519
4520 case GL_FRAGMENT_SHADER:
4521 switch (precisiontype)
4522 {
4523 case GL_LOW_FLOAT:
4524 mCaps.fragmentLowpFloat.get(range, precision);
4525 break;
4526 case GL_MEDIUM_FLOAT:
4527 mCaps.fragmentMediumpFloat.get(range, precision);
4528 break;
4529 case GL_HIGH_FLOAT:
4530 mCaps.fragmentHighpFloat.get(range, precision);
4531 break;
4532
4533 case GL_LOW_INT:
4534 mCaps.fragmentLowpInt.get(range, precision);
4535 break;
4536 case GL_MEDIUM_INT:
4537 mCaps.fragmentMediumpInt.get(range, precision);
4538 break;
4539 case GL_HIGH_INT:
4540 mCaps.fragmentHighpInt.get(range, precision);
4541 break;
4542
4543 default:
4544 UNREACHABLE();
4545 return;
4546 }
4547 break;
4548
4549 default:
4550 UNREACHABLE();
4551 return;
4552 }
4553}
4554
4555void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
4556{
4557 Shader *shaderObject = getShader(shader);
4558 ASSERT(shaderObject);
4559 shaderObject->getSource(bufsize, length, source);
4560}
4561
4562void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
4563{
4564 Program *programObject = getProgram(program);
4565 ASSERT(programObject);
4566 programObject->getUniformfv(location, params);
4567}
4568
4569void Context::getUniformiv(GLuint program, GLint location, GLint *params)
4570{
4571 Program *programObject = getProgram(program);
4572 ASSERT(programObject);
4573 programObject->getUniformiv(location, params);
4574}
4575
4576GLint Context::getUniformLocation(GLuint program, const GLchar *name)
4577{
4578 Program *programObject = getProgram(program);
4579 ASSERT(programObject);
4580 return programObject->getUniformLocation(name);
4581}
4582
4583GLboolean Context::isBuffer(GLuint buffer)
4584{
4585 if (buffer == 0)
4586 {
4587 return GL_FALSE;
4588 }
4589
4590 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
4591}
4592
4593GLboolean Context::isEnabled(GLenum cap)
4594{
4595 return mGLState.getEnableFeature(cap);
4596}
4597
4598GLboolean Context::isFramebuffer(GLuint framebuffer)
4599{
4600 if (framebuffer == 0)
4601 {
4602 return GL_FALSE;
4603 }
4604
4605 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
4606}
4607
4608GLboolean Context::isProgram(GLuint program)
4609{
4610 if (program == 0)
4611 {
4612 return GL_FALSE;
4613 }
4614
4615 return (getProgram(program) ? GL_TRUE : GL_FALSE);
4616}
4617
4618GLboolean Context::isRenderbuffer(GLuint renderbuffer)
4619{
4620 if (renderbuffer == 0)
4621 {
4622 return GL_FALSE;
4623 }
4624
4625 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
4626}
4627
4628GLboolean Context::isShader(GLuint shader)
4629{
4630 if (shader == 0)
4631 {
4632 return GL_FALSE;
4633 }
4634
4635 return (getShader(shader) ? GL_TRUE : GL_FALSE);
4636}
4637
4638GLboolean Context::isTexture(GLuint texture)
4639{
4640 if (texture == 0)
4641 {
4642 return GL_FALSE;
4643 }
4644
4645 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
4646}
4647
4648void Context::linkProgram(GLuint program)
4649{
4650 Program *programObject = getProgram(program);
4651 ASSERT(programObject);
4652 handleError(programObject->link(this));
4653}
4654
4655void Context::releaseShaderCompiler()
4656{
Jamie Madill4928b7c2017-06-20 12:57:39 -04004657 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004658}
4659
4660void Context::shaderBinary(GLsizei n,
4661 const GLuint *shaders,
4662 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04004663 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04004664 GLsizei length)
4665{
4666 // No binary shader formats are supported.
4667 UNIMPLEMENTED();
4668}
4669
4670void Context::shaderSource(GLuint shader,
4671 GLsizei count,
4672 const GLchar *const *string,
4673 const GLint *length)
4674{
4675 Shader *shaderObject = getShader(shader);
4676 ASSERT(shaderObject);
4677 shaderObject->setSource(count, string, length);
4678}
4679
4680void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
4681{
4682 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
4683}
4684
4685void Context::stencilMask(GLuint mask)
4686{
4687 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
4688}
4689
4690void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
4691{
4692 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
4693}
4694
4695void Context::uniform1f(GLint location, GLfloat x)
4696{
4697 Program *program = mGLState.getProgram();
4698 program->setUniform1fv(location, 1, &x);
4699}
4700
4701void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
4702{
4703 Program *program = mGLState.getProgram();
4704 program->setUniform1fv(location, count, v);
4705}
4706
4707void Context::uniform1i(GLint location, GLint x)
4708{
4709 Program *program = mGLState.getProgram();
4710 program->setUniform1iv(location, 1, &x);
4711}
4712
4713void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
4714{
4715 Program *program = mGLState.getProgram();
4716 program->setUniform1iv(location, count, v);
4717}
4718
4719void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
4720{
4721 GLfloat xy[2] = {x, y};
4722 Program *program = mGLState.getProgram();
4723 program->setUniform2fv(location, 1, xy);
4724}
4725
4726void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
4727{
4728 Program *program = mGLState.getProgram();
4729 program->setUniform2fv(location, count, v);
4730}
4731
4732void Context::uniform2i(GLint location, GLint x, GLint y)
4733{
4734 GLint xy[2] = {x, y};
4735 Program *program = mGLState.getProgram();
4736 program->setUniform2iv(location, 1, xy);
4737}
4738
4739void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
4740{
4741 Program *program = mGLState.getProgram();
4742 program->setUniform2iv(location, count, v);
4743}
4744
4745void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
4746{
4747 GLfloat xyz[3] = {x, y, z};
4748 Program *program = mGLState.getProgram();
4749 program->setUniform3fv(location, 1, xyz);
4750}
4751
4752void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
4753{
4754 Program *program = mGLState.getProgram();
4755 program->setUniform3fv(location, count, v);
4756}
4757
4758void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
4759{
4760 GLint xyz[3] = {x, y, z};
4761 Program *program = mGLState.getProgram();
4762 program->setUniform3iv(location, 1, xyz);
4763}
4764
4765void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
4766{
4767 Program *program = mGLState.getProgram();
4768 program->setUniform3iv(location, count, v);
4769}
4770
4771void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4772{
4773 GLfloat xyzw[4] = {x, y, z, w};
4774 Program *program = mGLState.getProgram();
4775 program->setUniform4fv(location, 1, xyzw);
4776}
4777
4778void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
4779{
4780 Program *program = mGLState.getProgram();
4781 program->setUniform4fv(location, count, v);
4782}
4783
4784void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
4785{
4786 GLint xyzw[4] = {x, y, z, w};
4787 Program *program = mGLState.getProgram();
4788 program->setUniform4iv(location, 1, xyzw);
4789}
4790
4791void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
4792{
4793 Program *program = mGLState.getProgram();
4794 program->setUniform4iv(location, count, v);
4795}
4796
4797void Context::uniformMatrix2fv(GLint location,
4798 GLsizei count,
4799 GLboolean transpose,
4800 const GLfloat *value)
4801{
4802 Program *program = mGLState.getProgram();
4803 program->setUniformMatrix2fv(location, count, transpose, value);
4804}
4805
4806void Context::uniformMatrix3fv(GLint location,
4807 GLsizei count,
4808 GLboolean transpose,
4809 const GLfloat *value)
4810{
4811 Program *program = mGLState.getProgram();
4812 program->setUniformMatrix3fv(location, count, transpose, value);
4813}
4814
4815void Context::uniformMatrix4fv(GLint location,
4816 GLsizei count,
4817 GLboolean transpose,
4818 const GLfloat *value)
4819{
4820 Program *program = mGLState.getProgram();
4821 program->setUniformMatrix4fv(location, count, transpose, value);
4822}
4823
4824void Context::validateProgram(GLuint program)
4825{
4826 Program *programObject = getProgram(program);
4827 ASSERT(programObject);
4828 programObject->validate(mCaps);
4829}
4830
Jamie Madilld04908b2017-06-09 14:15:35 -04004831void Context::getProgramBinary(GLuint program,
4832 GLsizei bufSize,
4833 GLsizei *length,
4834 GLenum *binaryFormat,
4835 void *binary)
4836{
4837 Program *programObject = getProgram(program);
4838 ASSERT(programObject != nullptr);
4839
4840 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
4841}
4842
4843void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
4844{
4845 Program *programObject = getProgram(program);
4846 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04004847
Jamie Madilld04908b2017-06-09 14:15:35 -04004848 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
4849}
4850
Jamie Madillc29968b2016-01-20 11:17:23 -05004851} // namespace gl