blob: 1c5c6a1b946e2144a82da610c5fc7b6912d076d0 [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
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400337 if (mExtensions.textureRectangle)
338 {
339 Texture *zeroTextureRectangle =
340 new Texture(mImplementation.get(), 0, GL_TEXTURE_RECTANGLE_ANGLE);
341 mZeroTextures[GL_TEXTURE_RECTANGLE_ANGLE].set(this, zeroTextureRectangle);
342 }
343
Ian Ewellbda75592016-04-18 17:25:54 -0400344 if (mExtensions.eglImageExternal || mExtensions.eglStreamConsumerExternal)
345 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400346 Texture *zeroTextureExternal =
347 new Texture(mImplementation.get(), 0, GL_TEXTURE_EXTERNAL_OES);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400348 mZeroTextures[GL_TEXTURE_EXTERNAL_OES].set(this, zeroTextureExternal);
Ian Ewellbda75592016-04-18 17:25:54 -0400349 }
350
Jamie Madill4928b7c2017-06-20 12:57:39 -0400351 mGLState.initializeZeroTextures(this, mZeroTextures);
Jamie Madille6382c32014-11-07 15:05:26 -0500352
Jamie Madill57a89722013-07-02 11:57:03 -0400353 bindVertexArray(0);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000354 bindArrayBuffer(0);
Jiajia Qin9d7d0b12016-11-29 16:30:31 +0800355 bindDrawIndirectBuffer(0);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000356 bindElementArrayBuffer(0);
Geoff Lang76b10c92014-09-05 16:28:14 -0400357
Jamie Madill01a80ee2016-11-07 12:06:18 -0500358 bindRenderbuffer(GL_RENDERBUFFER, 0);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000359
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +0000360 bindGenericUniformBuffer(0);
Geoff Lang4dc3af02016-11-18 14:09:27 -0500361 for (unsigned int i = 0; i < mCaps.maxUniformBufferBindings; i++)
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +0000362 {
363 bindIndexedUniformBuffer(0, i, 0, -1);
364 }
365
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000366 bindCopyReadBuffer(0);
367 bindCopyWriteBuffer(0);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +0000368 bindPixelPackBuffer(0);
369 bindPixelUnpackBuffer(0);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000370
Geoff Langeb66a6e2016-10-31 13:06:12 -0400371 if (getClientVersion() >= Version(3, 0))
Geoff Lang1a683462015-09-29 15:09:59 -0400372 {
373 // [OpenGL ES 3.0.2] section 2.14.1 pg 85:
374 // In the initial state, a default transform feedback object is bound and treated as
375 // a transform feedback object with a name of zero. That object is bound any time
376 // BindTransformFeedback is called with id of zero
Geoff Lang1a683462015-09-29 15:09:59 -0400377 bindTransformFeedback(0);
378 }
Geoff Langc8058452014-02-03 12:04:11 -0500379
Jamie Madillad9f24e2016-02-12 09:27:24 -0500380 // Initialize dirty bit masks
381 // TODO(jmadill): additional ES3 state
382 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_ALIGNMENT);
383 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_ROW_LENGTH);
384 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_IMAGE_HEIGHT);
385 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_SKIP_IMAGES);
386 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_SKIP_ROWS);
387 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_SKIP_PIXELS);
Corentin Wallezbbd663a2016-04-20 17:49:17 -0400388 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500389 // No dirty objects.
390
391 // Readpixels uses the pack state and read FBO
392 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_ALIGNMENT);
393 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_REVERSE_ROW_ORDER);
394 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_ROW_LENGTH);
395 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_SKIP_ROWS);
396 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_SKIP_PIXELS);
Corentin Wallezbbd663a2016-04-20 17:49:17 -0400397 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500398 mReadPixelsDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
399
400 mClearDirtyBits.set(State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED);
401 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
402 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR);
403 mClearDirtyBits.set(State::DIRTY_BIT_VIEWPORT);
404 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_COLOR);
405 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_DEPTH);
406 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_STENCIL);
407 mClearDirtyBits.set(State::DIRTY_BIT_COLOR_MASK);
408 mClearDirtyBits.set(State::DIRTY_BIT_DEPTH_MASK);
409 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT);
410 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_BACK);
411 mClearDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
412
413 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
414 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR);
Geoff Lang1d2c41d2016-10-19 16:14:46 -0700415 mBlitDirtyBits.set(State::DIRTY_BIT_FRAMEBUFFER_SRGB);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500416 mBlitDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
417 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
Jamie Madill437fa652016-05-03 15:13:24 -0400418
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400419 handleError(mImplementation->initialize());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000420}
421
Jamie Madill4928b7c2017-06-20 12:57:39 -0400422egl::Error Context::onDestroy(const egl::Display *display)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000423{
Corentin Wallez80b24112015-08-25 16:41:57 -0400424 for (auto fence : mFenceNVMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000425 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400426 SafeDelete(fence.second);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000427 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400428 mFenceNVMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000429
Corentin Wallez80b24112015-08-25 16:41:57 -0400430 for (auto query : mQueryMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000431 {
Geoff Langf0aa8422015-09-29 15:08:34 -0400432 if (query.second != nullptr)
433 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400434 query.second->release(this);
Geoff Langf0aa8422015-09-29 15:08:34 -0400435 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000436 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400437 mQueryMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000438
Corentin Wallez80b24112015-08-25 16:41:57 -0400439 for (auto vertexArray : mVertexArrayMap)
Jamie Madill57a89722013-07-02 11:57:03 -0400440 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400441 if (vertexArray.second)
442 {
443 vertexArray.second->onDestroy(this);
444 }
Jamie Madill57a89722013-07-02 11:57:03 -0400445 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400446 mVertexArrayMap.clear();
Jamie Madill57a89722013-07-02 11:57:03 -0400447
Corentin Wallez80b24112015-08-25 16:41:57 -0400448 for (auto transformFeedback : mTransformFeedbackMap)
Geoff Langc8058452014-02-03 12:04:11 -0500449 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500450 if (transformFeedback.second != nullptr)
451 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500452 transformFeedback.second->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500453 }
Geoff Langc8058452014-02-03 12:04:11 -0500454 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400455 mTransformFeedbackMap.clear();
Geoff Langc8058452014-02-03 12:04:11 -0500456
Jamie Madilldedd7b92014-11-05 16:30:36 -0500457 for (auto &zeroTexture : mZeroTextures)
Geoff Lang76b10c92014-09-05 16:28:14 -0400458 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400459 zeroTexture.second->onDestroy(this);
460 zeroTexture.second.set(this, nullptr);
Geoff Lang76b10c92014-09-05 16:28:14 -0400461 }
462 mZeroTextures.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000463
Corentin Wallezccab69d2017-01-27 16:57:15 -0500464 SafeDelete(mSurfacelessFramebuffer);
465
Jamie Madill4928b7c2017-06-20 12:57:39 -0400466 ANGLE_TRY(releaseSurface(display));
Jamie Madill2f348d22017-06-05 10:50:59 -0400467 releaseShaderCompiler();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500468
Jamie Madill4928b7c2017-06-20 12:57:39 -0400469 mGLState.reset(this);
470
Jamie Madill6c1f6712017-02-14 19:08:04 -0500471 mState.mBuffers->release(this);
472 mState.mShaderPrograms->release(this);
473 mState.mTextures->release(this);
474 mState.mRenderbuffers->release(this);
475 mState.mSamplers->release(this);
476 mState.mFenceSyncs->release(this);
477 mState.mPaths->release(this);
478 mState.mFramebuffers->release(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400479
480 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000481}
482
Jamie Madill70ee0f62017-02-06 16:04:20 -0500483Context::~Context()
484{
485}
486
Jamie Madill4928b7c2017-06-20 12:57:39 -0400487egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000488{
Jamie Madill61e16b42017-06-19 11:13:23 -0400489 mCurrentDisplay = display;
490
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000491 if (!mHasBeenCurrent)
492 {
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000493 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500494 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400495 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000496
Corentin Wallezc295e512017-01-27 17:47:50 -0500497 int width = 0;
498 int height = 0;
499 if (surface != nullptr)
500 {
501 width = surface->getWidth();
502 height = surface->getHeight();
503 }
504
505 mGLState.setViewportParams(0, 0, width, height);
506 mGLState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000507
508 mHasBeenCurrent = true;
509 }
510
Jamie Madill1b94d432015-08-07 13:23:23 -0400511 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700512 mGLState.setAllDirtyBits();
Jamie Madill1b94d432015-08-07 13:23:23 -0400513
Jamie Madill4928b7c2017-06-20 12:57:39 -0400514 ANGLE_TRY(releaseSurface(display));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500515
516 Framebuffer *newDefault = nullptr;
517 if (surface != nullptr)
518 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400519 ANGLE_TRY(surface->setIsCurrent(this, true));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500520 mCurrentSurface = surface;
521 newDefault = surface->getDefaultFramebuffer();
522 }
523 else
524 {
525 if (mSurfacelessFramebuffer == nullptr)
526 {
527 mSurfacelessFramebuffer = new Framebuffer(mImplementation.get());
528 }
529
530 newDefault = mSurfacelessFramebuffer;
531 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000532
Corentin Wallez37c39792015-08-20 14:19:46 -0400533 // Update default framebuffer, the binding of the previous default
534 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400535 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700536 if (mGLState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400537 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700538 mGLState.setReadFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400539 }
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700540 if (mGLState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400541 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700542 mGLState.setDrawFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400543 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500544 mState.mFramebuffers->setDefaultFramebuffer(newDefault);
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400545 }
Ian Ewell292f0052016-02-04 10:37:32 -0500546
547 // Notify the renderer of a context switch
Jamie Madill4928b7c2017-06-20 12:57:39 -0400548 mImplementation->onMakeCurrent(this);
549 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000550}
551
Jamie Madill4928b7c2017-06-20 12:57:39 -0400552egl::Error Context::releaseSurface(const egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400553{
Corentin Wallez37c39792015-08-20 14:19:46 -0400554 // Remove the default framebuffer
Corentin Wallezc295e512017-01-27 17:47:50 -0500555 Framebuffer *currentDefault = nullptr;
556 if (mCurrentSurface != nullptr)
Corentin Wallez51706ea2015-08-07 14:39:22 -0400557 {
Corentin Wallezc295e512017-01-27 17:47:50 -0500558 currentDefault = mCurrentSurface->getDefaultFramebuffer();
559 }
560 else if (mSurfacelessFramebuffer != nullptr)
561 {
562 currentDefault = mSurfacelessFramebuffer;
Corentin Wallez51706ea2015-08-07 14:39:22 -0400563 }
564
Corentin Wallezc295e512017-01-27 17:47:50 -0500565 if (mGLState.getReadFramebuffer() == currentDefault)
566 {
567 mGLState.setReadFramebufferBinding(nullptr);
568 }
569 if (mGLState.getDrawFramebuffer() == currentDefault)
570 {
571 mGLState.setDrawFramebufferBinding(nullptr);
572 }
573 mState.mFramebuffers->setDefaultFramebuffer(nullptr);
574
575 if (mCurrentSurface)
576 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400577 ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
Corentin Wallezc295e512017-01-27 17:47:50 -0500578 mCurrentSurface = nullptr;
579 }
Jamie Madill4928b7c2017-06-20 12:57:39 -0400580
581 return egl::NoError();
Jamie Madill77a72f62015-04-14 11:18:32 -0400582}
583
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000584GLuint Context::createBuffer()
585{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500586 return mState.mBuffers->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000587}
588
589GLuint Context::createProgram()
590{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500591 return mState.mShaderPrograms->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000592}
593
594GLuint Context::createShader(GLenum type)
595{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500596 return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000597}
598
599GLuint Context::createTexture()
600{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500601 return mState.mTextures->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000602}
603
604GLuint Context::createRenderbuffer()
605{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500606 return mState.mRenderbuffers->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000607}
608
Geoff Lang882033e2014-09-30 11:26:07 -0400609GLsync Context::createFenceSync()
Jamie Madillcd055f82013-07-26 11:55:15 -0400610{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500611 GLuint handle = mState.mFenceSyncs->createFenceSync(mImplementation.get());
Jamie Madillcd055f82013-07-26 11:55:15 -0400612
Cooper Partind8e62a32015-01-29 15:21:25 -0800613 return reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madillcd055f82013-07-26 11:55:15 -0400614}
615
Sami Väisänene45e53b2016-05-25 10:36:04 +0300616GLuint Context::createPaths(GLsizei range)
617{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500618 auto resultOrError = mState.mPaths->createPaths(mImplementation.get(), range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300619 if (resultOrError.isError())
620 {
621 handleError(resultOrError.getError());
622 return 0;
623 }
624 return resultOrError.getResult();
625}
626
Jamie Madill57a89722013-07-02 11:57:03 -0400627GLuint Context::createVertexArray()
628{
Jamie Madill96a483b2017-06-27 16:49:21 -0400629 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
630 mVertexArrayMap.assign(vertexArray, nullptr);
Geoff Lang36167ab2015-12-07 10:27:14 -0500631 return vertexArray;
Jamie Madill57a89722013-07-02 11:57:03 -0400632}
633
Jamie Madilldc356042013-07-19 16:36:57 -0400634GLuint Context::createSampler()
635{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500636 return mState.mSamplers->createSampler();
Jamie Madilldc356042013-07-19 16:36:57 -0400637}
638
Geoff Langc8058452014-02-03 12:04:11 -0500639GLuint Context::createTransformFeedback()
640{
Jamie Madill96a483b2017-06-27 16:49:21 -0400641 GLuint transformFeedback = mTransformFeedbackAllocator.allocate();
642 mTransformFeedbackMap.assign(transformFeedback, nullptr);
Geoff Lang36167ab2015-12-07 10:27:14 -0500643 return transformFeedback;
Geoff Langc8058452014-02-03 12:04:11 -0500644}
645
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000646// Returns an unused framebuffer name
647GLuint Context::createFramebuffer()
648{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500649 return mState.mFramebuffers->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000650}
651
Jamie Madill33dc8432013-07-26 11:55:05 -0400652GLuint Context::createFenceNV()
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000653{
Jamie Madill33dc8432013-07-26 11:55:05 -0400654 GLuint handle = mFenceNVHandleAllocator.allocate();
Jamie Madill96a483b2017-06-27 16:49:21 -0400655 mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV()));
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000656 return handle;
657}
658
659// Returns an unused query name
660GLuint Context::createQuery()
661{
662 GLuint handle = mQueryHandleAllocator.allocate();
Jamie Madill96a483b2017-06-27 16:49:21 -0400663 mQueryMap.assign(handle, nullptr);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000664 return handle;
665}
666
667void Context::deleteBuffer(GLuint buffer)
668{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500669 if (mState.mBuffers->getBuffer(buffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000670 {
671 detachBuffer(buffer);
672 }
Jamie Madill893ab082014-05-16 16:56:10 -0400673
Jamie Madill6c1f6712017-02-14 19:08:04 -0500674 mState.mBuffers->deleteObject(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000675}
676
677void Context::deleteShader(GLuint shader)
678{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500679 mState.mShaderPrograms->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000680}
681
682void Context::deleteProgram(GLuint program)
683{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500684 mState.mShaderPrograms->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000685}
686
687void Context::deleteTexture(GLuint texture)
688{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500689 if (mState.mTextures->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000690 {
691 detachTexture(texture);
692 }
693
Jamie Madill6c1f6712017-02-14 19:08:04 -0500694 mState.mTextures->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000695}
696
697void Context::deleteRenderbuffer(GLuint renderbuffer)
698{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500699 if (mState.mRenderbuffers->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000700 {
701 detachRenderbuffer(renderbuffer);
702 }
Jamie Madill893ab082014-05-16 16:56:10 -0400703
Jamie Madill6c1f6712017-02-14 19:08:04 -0500704 mState.mRenderbuffers->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000705}
706
Jamie Madillcd055f82013-07-26 11:55:15 -0400707void Context::deleteFenceSync(GLsync fenceSync)
708{
709 // The spec specifies the underlying Fence object is not deleted until all current
710 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
711 // and since our API is currently designed for being called from a single thread, we can delete
712 // the fence immediately.
Jamie Madill6c1f6712017-02-14 19:08:04 -0500713 mState.mFenceSyncs->deleteObject(this,
714 static_cast<GLuint>(reinterpret_cast<uintptr_t>(fenceSync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400715}
716
Sami Väisänene45e53b2016-05-25 10:36:04 +0300717void Context::deletePaths(GLuint first, GLsizei range)
718{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500719 mState.mPaths->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300720}
721
722bool Context::hasPathData(GLuint path) const
723{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500724 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300725 if (pathObj == nullptr)
726 return false;
727
728 return pathObj->hasPathData();
729}
730
731bool Context::hasPath(GLuint path) const
732{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500733 return mState.mPaths->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300734}
735
736void Context::setPathCommands(GLuint path,
737 GLsizei numCommands,
738 const GLubyte *commands,
739 GLsizei numCoords,
740 GLenum coordType,
741 const void *coords)
742{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500743 auto *pathObject = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300744
745 handleError(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
746}
747
748void Context::setPathParameterf(GLuint path, GLenum pname, GLfloat value)
749{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500750 auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300751
752 switch (pname)
753 {
754 case GL_PATH_STROKE_WIDTH_CHROMIUM:
755 pathObj->setStrokeWidth(value);
756 break;
757 case GL_PATH_END_CAPS_CHROMIUM:
758 pathObj->setEndCaps(static_cast<GLenum>(value));
759 break;
760 case GL_PATH_JOIN_STYLE_CHROMIUM:
761 pathObj->setJoinStyle(static_cast<GLenum>(value));
762 break;
763 case GL_PATH_MITER_LIMIT_CHROMIUM:
764 pathObj->setMiterLimit(value);
765 break;
766 case GL_PATH_STROKE_BOUND_CHROMIUM:
767 pathObj->setStrokeBound(value);
768 break;
769 default:
770 UNREACHABLE();
771 break;
772 }
773}
774
775void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value) const
776{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500777 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300778
779 switch (pname)
780 {
781 case GL_PATH_STROKE_WIDTH_CHROMIUM:
782 *value = pathObj->getStrokeWidth();
783 break;
784 case GL_PATH_END_CAPS_CHROMIUM:
785 *value = static_cast<GLfloat>(pathObj->getEndCaps());
786 break;
787 case GL_PATH_JOIN_STYLE_CHROMIUM:
788 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
789 break;
790 case GL_PATH_MITER_LIMIT_CHROMIUM:
791 *value = pathObj->getMiterLimit();
792 break;
793 case GL_PATH_STROKE_BOUND_CHROMIUM:
794 *value = pathObj->getStrokeBound();
795 break;
796 default:
797 UNREACHABLE();
798 break;
799 }
800}
801
802void Context::setPathStencilFunc(GLenum func, GLint ref, GLuint mask)
803{
804 mGLState.setPathStencilFunc(func, ref, mask);
805}
806
Jamie Madill57a89722013-07-02 11:57:03 -0400807void Context::deleteVertexArray(GLuint vertexArray)
808{
Jamie Madill96a483b2017-06-27 16:49:21 -0400809 VertexArray *vertexArrayObject = nullptr;
810 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
Geoff Lang50b3fe82015-12-08 14:49:12 +0000811 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500812 if (vertexArrayObject != nullptr)
813 {
814 detachVertexArray(vertexArray);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400815 vertexArrayObject->onDestroy(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500816 }
Geoff Lang50b3fe82015-12-08 14:49:12 +0000817
Geoff Lang36167ab2015-12-07 10:27:14 -0500818 mVertexArrayHandleAllocator.release(vertexArray);
Jamie Madill57a89722013-07-02 11:57:03 -0400819 }
820}
821
Jamie Madilldc356042013-07-19 16:36:57 -0400822void Context::deleteSampler(GLuint sampler)
823{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500824 if (mState.mSamplers->getSampler(sampler))
Jamie Madilldc356042013-07-19 16:36:57 -0400825 {
826 detachSampler(sampler);
827 }
828
Jamie Madill6c1f6712017-02-14 19:08:04 -0500829 mState.mSamplers->deleteObject(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -0400830}
831
Geoff Langc8058452014-02-03 12:04:11 -0500832void Context::deleteTransformFeedback(GLuint transformFeedback)
833{
Geoff Lang6e60d6b2017-04-12 12:59:04 -0400834 if (transformFeedback == 0)
835 {
836 return;
837 }
838
Jamie Madill96a483b2017-06-27 16:49:21 -0400839 TransformFeedback *transformFeedbackObject = nullptr;
840 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
Geoff Langc8058452014-02-03 12:04:11 -0500841 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500842 if (transformFeedbackObject != nullptr)
843 {
844 detachTransformFeedback(transformFeedback);
Jamie Madill6c1f6712017-02-14 19:08:04 -0500845 transformFeedbackObject->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500846 }
847
Geoff Lang36167ab2015-12-07 10:27:14 -0500848 mTransformFeedbackAllocator.release(transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -0500849 }
850}
851
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000852void Context::deleteFramebuffer(GLuint framebuffer)
853{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500854 if (mState.mFramebuffers->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000855 {
856 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000857 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500858
Jamie Madill6c1f6712017-02-14 19:08:04 -0500859 mState.mFramebuffers->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000860}
861
Jamie Madill33dc8432013-07-26 11:55:05 -0400862void Context::deleteFenceNV(GLuint fence)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000863{
Jamie Madill96a483b2017-06-27 16:49:21 -0400864 FenceNV *fenceObject = nullptr;
865 if (mFenceNVMap.erase(fence, &fenceObject))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000866 {
Jamie Madill96a483b2017-06-27 16:49:21 -0400867 mFenceNVHandleAllocator.release(fence);
868 delete fenceObject;
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000869 }
870}
871
872void Context::deleteQuery(GLuint query)
873{
Jamie Madill96a483b2017-06-27 16:49:21 -0400874 Query *queryObject = nullptr;
875 if (mQueryMap.erase(query, &queryObject))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000876 {
Jamie Madill96a483b2017-06-27 16:49:21 -0400877 mQueryHandleAllocator.release(query);
878 if (queryObject)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000879 {
Jamie Madill96a483b2017-06-27 16:49:21 -0400880 queryObject->release(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000881 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000882 }
883}
884
Geoff Lang70d0f492015-12-10 17:45:46 -0500885Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000886{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500887 return mState.mBuffers->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000888}
889
Jamie Madill570f7c82014-07-03 10:38:54 -0400890Texture *Context::getTexture(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000891{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500892 return mState.mTextures->getTexture(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000893}
894
Geoff Lang70d0f492015-12-10 17:45:46 -0500895Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000896{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500897 return mState.mRenderbuffers->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000898}
899
Jamie Madillcd055f82013-07-26 11:55:15 -0400900FenceSync *Context::getFenceSync(GLsync handle) const
901{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500902 return mState.mFenceSyncs->getFenceSync(
903 static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400904}
905
Jamie Madill57a89722013-07-02 11:57:03 -0400906VertexArray *Context::getVertexArray(GLuint handle) const
907{
Jamie Madill96a483b2017-06-27 16:49:21 -0400908 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -0400909}
910
Jamie Madilldc356042013-07-19 16:36:57 -0400911Sampler *Context::getSampler(GLuint handle) const
912{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500913 return mState.mSamplers->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400914}
915
Geoff Langc8058452014-02-03 12:04:11 -0500916TransformFeedback *Context::getTransformFeedback(GLuint handle) const
917{
Jamie Madill96a483b2017-06-27 16:49:21 -0400918 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -0500919}
920
Geoff Lang70d0f492015-12-10 17:45:46 -0500921LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
922{
923 switch (identifier)
924 {
925 case GL_BUFFER:
926 return getBuffer(name);
927 case GL_SHADER:
928 return getShader(name);
929 case GL_PROGRAM:
930 return getProgram(name);
931 case GL_VERTEX_ARRAY:
932 return getVertexArray(name);
933 case GL_QUERY:
934 return getQuery(name);
935 case GL_TRANSFORM_FEEDBACK:
936 return getTransformFeedback(name);
937 case GL_SAMPLER:
938 return getSampler(name);
939 case GL_TEXTURE:
940 return getTexture(name);
941 case GL_RENDERBUFFER:
942 return getRenderbuffer(name);
943 case GL_FRAMEBUFFER:
944 return getFramebuffer(name);
945 default:
946 UNREACHABLE();
947 return nullptr;
948 }
949}
950
951LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
952{
953 return getFenceSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
954}
955
Martin Radev9d901792016-07-15 15:58:58 +0300956void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
957{
958 LabeledObject *object = getLabeledObject(identifier, name);
959 ASSERT(object != nullptr);
960
961 std::string labelName = GetObjectLabelFromPointer(length, label);
962 object->setLabel(labelName);
963}
964
965void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
966{
967 LabeledObject *object = getLabeledObjectFromPtr(ptr);
968 ASSERT(object != nullptr);
969
970 std::string labelName = GetObjectLabelFromPointer(length, label);
971 object->setLabel(labelName);
972}
973
974void Context::getObjectLabel(GLenum identifier,
975 GLuint name,
976 GLsizei bufSize,
977 GLsizei *length,
978 GLchar *label) const
979{
980 LabeledObject *object = getLabeledObject(identifier, name);
981 ASSERT(object != nullptr);
982
983 const std::string &objectLabel = object->getLabel();
984 GetObjectLabelBase(objectLabel, bufSize, length, label);
985}
986
987void Context::getObjectPtrLabel(const void *ptr,
988 GLsizei bufSize,
989 GLsizei *length,
990 GLchar *label) const
991{
992 LabeledObject *object = getLabeledObjectFromPtr(ptr);
993 ASSERT(object != nullptr);
994
995 const std::string &objectLabel = object->getLabel();
996 GetObjectLabelBase(objectLabel, bufSize, length, label);
997}
998
Jamie Madilldc356042013-07-19 16:36:57 -0400999bool Context::isSampler(GLuint samplerName) const
1000{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001001 return mState.mSamplers->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -04001002}
1003
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001004void Context::bindArrayBuffer(GLuint bufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001005{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001006 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001007 mGLState.setArrayBufferBinding(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001008}
1009
Jiajia Qin9d7d0b12016-11-29 16:30:31 +08001010void Context::bindDrawIndirectBuffer(GLuint bufferHandle)
1011{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001012 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001013 mGLState.setDrawIndirectBufferBinding(this, buffer);
Jiajia Qin9d7d0b12016-11-29 16:30:31 +08001014}
1015
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001016void Context::bindElementArrayBuffer(GLuint bufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001017{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001018 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001019 mGLState.setElementArrayBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001020}
1021
Jamie Madilldedd7b92014-11-05 16:30:36 -05001022void Context::bindTexture(GLenum target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001023{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001024 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001025
Jamie Madilldedd7b92014-11-05 16:30:36 -05001026 if (handle == 0)
1027 {
1028 texture = mZeroTextures[target].get();
1029 }
1030 else
1031 {
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001032 texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -05001033 }
1034
1035 ASSERT(texture);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001036 mGLState.setSamplerTexture(this, target, texture);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00001037}
1038
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001039void Context::bindReadFramebuffer(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.setReadFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001044}
1045
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001046void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001047{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001048 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1049 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001050 mGLState.setDrawFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001051}
1052
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001053void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -04001054{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001055 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001056 mGLState.setVertexArrayBinding(vertexArray);
Jamie Madill57a89722013-07-02 11:57:03 -04001057}
1058
Shao80957d92017-02-20 21:25:59 +08001059void Context::bindVertexBuffer(GLuint bindingIndex,
1060 GLuint bufferHandle,
1061 GLintptr offset,
1062 GLsizei stride)
1063{
1064 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001065 mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Shao80957d92017-02-20 21:25:59 +08001066}
1067
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001068void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -04001069{
Geoff Lang76b10c92014-09-05 16:28:14 -04001070 ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -04001071 Sampler *sampler =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001072 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001073 mGLState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04001074}
1075
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001076void Context::bindImageTexture(GLuint unit,
1077 GLuint texture,
1078 GLint level,
1079 GLboolean layered,
1080 GLint layer,
1081 GLenum access,
1082 GLenum format)
1083{
1084 Texture *tex = mState.mTextures->getTexture(texture);
1085 mGLState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
1086}
1087
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001088void Context::bindGenericUniformBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001089{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001090 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001091 mGLState.setGenericUniformBufferBinding(this, buffer);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001092}
1093
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001094void Context::bindIndexedUniformBuffer(GLuint bufferHandle,
1095 GLuint index,
1096 GLintptr offset,
1097 GLsizeiptr size)
shannon.woods%transgaming.com@gtempaccount.com34089352013-04-13 03:36:57 +00001098{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001099 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001100 mGLState.setIndexedUniformBufferBinding(this, index, buffer, offset, size);
shannon.woods%transgaming.com@gtempaccount.com34089352013-04-13 03:36:57 +00001101}
1102
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001103void Context::bindGenericTransformFeedbackBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001104{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001105 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001106 mGLState.getCurrentTransformFeedback()->bindGenericBuffer(this, buffer);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001107}
1108
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001109void Context::bindIndexedTransformFeedbackBuffer(GLuint bufferHandle,
1110 GLuint index,
1111 GLintptr offset,
1112 GLsizeiptr size)
shannon.woods%transgaming.com@gtempaccount.com34089352013-04-13 03:36:57 +00001113{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001114 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001115 mGLState.getCurrentTransformFeedback()->bindIndexedBuffer(this, index, buffer, offset, size);
shannon.woods%transgaming.com@gtempaccount.com34089352013-04-13 03:36:57 +00001116}
1117
Jiajia Qin6eafb042016-12-27 17:04:07 +08001118void Context::bindGenericAtomicCounterBuffer(GLuint bufferHandle)
1119{
1120 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001121 mGLState.setGenericAtomicCounterBufferBinding(this, buffer);
Jiajia Qin6eafb042016-12-27 17:04:07 +08001122}
1123
1124void Context::bindIndexedAtomicCounterBuffer(GLuint bufferHandle,
1125 GLuint index,
1126 GLintptr offset,
1127 GLsizeiptr size)
1128{
1129 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001130 mGLState.setIndexedAtomicCounterBufferBinding(this, index, buffer, offset, size);
Jiajia Qin6eafb042016-12-27 17:04:07 +08001131}
1132
Jiajia Qinf546e7d2017-03-27 14:12:59 +08001133void Context::bindGenericShaderStorageBuffer(GLuint bufferHandle)
1134{
1135 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001136 mGLState.setGenericShaderStorageBufferBinding(this, buffer);
Jiajia Qinf546e7d2017-03-27 14:12:59 +08001137}
1138
1139void Context::bindIndexedShaderStorageBuffer(GLuint bufferHandle,
1140 GLuint index,
1141 GLintptr offset,
1142 GLsizeiptr size)
1143{
1144 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001145 mGLState.setIndexedShaderStorageBufferBinding(this, index, buffer, offset, size);
Jiajia Qinf546e7d2017-03-27 14:12:59 +08001146}
1147
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001148void Context::bindCopyReadBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001149{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001150 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001151 mGLState.setCopyReadBufferBinding(this, buffer);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001152}
1153
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001154void Context::bindCopyWriteBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001155{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001156 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001157 mGLState.setCopyWriteBufferBinding(this, buffer);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001158}
1159
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001160void Context::bindPixelPackBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001161{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001162 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001163 mGLState.setPixelPackBufferBinding(this, buffer);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001164}
1165
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001166void Context::bindPixelUnpackBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001167{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001168 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001169 mGLState.setPixelUnpackBufferBinding(this, buffer);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001170}
1171
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001172void Context::useProgram(GLuint program)
1173{
Jamie Madill6c1f6712017-02-14 19:08:04 -05001174 mGLState.setProgram(this, getProgram(program));
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001175}
1176
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001177void Context::bindTransformFeedback(GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001178{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001179 TransformFeedback *transformFeedback =
1180 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001181 mGLState.setTransformFeedbackBinding(this, transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -05001182}
1183
Geoff Lang5aad9672014-09-08 11:10:42 -04001184Error Context::beginQuery(GLenum target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001185{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001186 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001187 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001188
Geoff Lang5aad9672014-09-08 11:10:42 -04001189 // begin query
1190 Error error = queryObject->begin();
1191 if (error.isError())
1192 {
1193 return error;
1194 }
1195
1196 // set query as active for specified target only if begin succeeded
Jamie Madill4928b7c2017-06-20 12:57:39 -04001197 mGLState.setActiveQuery(this, target, queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001198
He Yunchaoacd18982017-01-04 10:46:42 +08001199 return NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001200}
1201
Geoff Lang5aad9672014-09-08 11:10:42 -04001202Error Context::endQuery(GLenum target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001203{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001204 Query *queryObject = mGLState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001205 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001206
Geoff Lang5aad9672014-09-08 11:10:42 -04001207 gl::Error error = queryObject->end();
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001208
Geoff Lang5aad9672014-09-08 11:10:42 -04001209 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madill4928b7c2017-06-20 12:57:39 -04001210 mGLState.setActiveQuery(this, target, nullptr);
Geoff Lang5aad9672014-09-08 11:10:42 -04001211
1212 return error;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001213}
1214
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001215Error Context::queryCounter(GLuint id, GLenum target)
1216{
1217 ASSERT(target == GL_TIMESTAMP_EXT);
1218
1219 Query *queryObject = getQuery(id, true, target);
1220 ASSERT(queryObject);
1221
1222 return queryObject->queryCounter();
1223}
1224
1225void Context::getQueryiv(GLenum target, GLenum pname, GLint *params)
1226{
1227 switch (pname)
1228 {
1229 case GL_CURRENT_QUERY_EXT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001230 params[0] = mGLState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001231 break;
1232 case GL_QUERY_COUNTER_BITS_EXT:
1233 switch (target)
1234 {
1235 case GL_TIME_ELAPSED_EXT:
1236 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1237 break;
1238 case GL_TIMESTAMP_EXT:
1239 params[0] = getExtensions().queryCounterBitsTimestamp;
1240 break;
1241 default:
1242 UNREACHABLE();
1243 params[0] = 0;
1244 break;
1245 }
1246 break;
1247 default:
1248 UNREACHABLE();
1249 return;
1250 }
1251}
1252
Geoff Lang2186c382016-10-14 10:54:54 -04001253void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001254{
Geoff Lang2186c382016-10-14 10:54:54 -04001255 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001256}
1257
Geoff Lang2186c382016-10-14 10:54:54 -04001258void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001259{
Geoff Lang2186c382016-10-14 10:54:54 -04001260 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001261}
1262
Geoff Lang2186c382016-10-14 10:54:54 -04001263void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001264{
Geoff Lang2186c382016-10-14 10:54:54 -04001265 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001266}
1267
Geoff Lang2186c382016-10-14 10:54:54 -04001268void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001269{
Geoff Lang2186c382016-10-14 10:54:54 -04001270 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001271}
1272
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001273Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001274{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001275 return mState.mFramebuffers->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001276}
1277
Jamie Madill2f348d22017-06-05 10:50:59 -04001278FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001279{
Jamie Madill96a483b2017-06-27 16:49:21 -04001280 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001281}
1282
Jamie Madill2f348d22017-06-05 10:50:59 -04001283Query *Context::getQuery(GLuint handle, bool create, GLenum type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001284{
Jamie Madill96a483b2017-06-27 16:49:21 -04001285 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001286 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001287 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001288 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001289
1290 Query *query = mQueryMap.query(handle);
1291 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001292 {
Jamie Madill96a483b2017-06-27 16:49:21 -04001293 query = new Query(mImplementation->createQuery(type), handle);
1294 query->addRef();
1295 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001296 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001297 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001298}
1299
Geoff Lang70d0f492015-12-10 17:45:46 -05001300Query *Context::getQuery(GLuint handle) const
1301{
Jamie Madill96a483b2017-06-27 16:49:21 -04001302 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001303}
1304
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001305Texture *Context::getTargetTexture(GLenum target) const
1306{
Ian Ewellbda75592016-04-18 17:25:54 -04001307 ASSERT(ValidTextureTarget(this, target) || ValidTextureExternalTarget(this, target));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001308 return mGLState.getTargetTexture(target);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001309}
1310
Geoff Lang76b10c92014-09-05 16:28:14 -04001311Texture *Context::getSamplerTexture(unsigned int sampler, GLenum type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001312{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001313 return mGLState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001314}
1315
Geoff Lang492a7e42014-11-05 13:27:06 -05001316Compiler *Context::getCompiler() const
1317{
Jamie Madill2f348d22017-06-05 10:50:59 -04001318 if (mCompiler.get() == nullptr)
1319 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001320 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001321 }
1322 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001323}
1324
Jamie Madillc1d770e2017-04-13 17:31:24 -04001325void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001326{
1327 switch (pname)
1328 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001329 case GL_SHADER_COMPILER:
1330 *params = GL_TRUE;
1331 break;
1332 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1333 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1334 break;
1335 default:
1336 mGLState.getBooleanv(pname, params);
1337 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001338 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001339}
1340
Jamie Madillc1d770e2017-04-13 17:31:24 -04001341void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001342{
Shannon Woods53a94a82014-06-24 15:20:36 -04001343 // Queries about context capabilities and maximums are answered by Context.
1344 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001345 switch (pname)
1346 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001347 case GL_ALIASED_LINE_WIDTH_RANGE:
1348 params[0] = mCaps.minAliasedLineWidth;
1349 params[1] = mCaps.maxAliasedLineWidth;
1350 break;
1351 case GL_ALIASED_POINT_SIZE_RANGE:
1352 params[0] = mCaps.minAliasedPointSize;
1353 params[1] = mCaps.maxAliasedPointSize;
1354 break;
1355 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1356 ASSERT(mExtensions.textureFilterAnisotropic);
1357 *params = mExtensions.maxTextureAnisotropy;
1358 break;
1359 case GL_MAX_TEXTURE_LOD_BIAS:
1360 *params = mCaps.maxLODBias;
1361 break;
1362
1363 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1364 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1365 {
1366 ASSERT(mExtensions.pathRendering);
1367 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1368 memcpy(params, m, 16 * sizeof(GLfloat));
1369 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001370 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001371
Jamie Madill231c7f52017-04-26 13:45:37 -04001372 default:
1373 mGLState.getFloatv(pname, params);
1374 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001375 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001376}
1377
Jamie Madillc1d770e2017-04-13 17:31:24 -04001378void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001379{
Shannon Woods53a94a82014-06-24 15:20:36 -04001380 // Queries about context capabilities and maximums are answered by Context.
1381 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001382
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001383 switch (pname)
1384 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001385 case GL_MAX_VERTEX_ATTRIBS:
1386 *params = mCaps.maxVertexAttributes;
1387 break;
1388 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1389 *params = mCaps.maxVertexUniformVectors;
1390 break;
1391 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
1392 *params = mCaps.maxVertexUniformComponents;
1393 break;
1394 case GL_MAX_VARYING_VECTORS:
1395 *params = mCaps.maxVaryingVectors;
1396 break;
1397 case GL_MAX_VARYING_COMPONENTS:
1398 *params = mCaps.maxVertexOutputComponents;
1399 break;
1400 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1401 *params = mCaps.maxCombinedTextureImageUnits;
1402 break;
1403 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
1404 *params = mCaps.maxVertexTextureImageUnits;
1405 break;
1406 case GL_MAX_TEXTURE_IMAGE_UNITS:
1407 *params = mCaps.maxTextureImageUnits;
1408 break;
1409 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1410 *params = mCaps.maxFragmentUniformVectors;
1411 break;
1412 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
1413 *params = mCaps.maxFragmentUniformComponents;
1414 break;
1415 case GL_MAX_RENDERBUFFER_SIZE:
1416 *params = mCaps.maxRenderbufferSize;
1417 break;
1418 case GL_MAX_COLOR_ATTACHMENTS_EXT:
1419 *params = mCaps.maxColorAttachments;
1420 break;
1421 case GL_MAX_DRAW_BUFFERS_EXT:
1422 *params = mCaps.maxDrawBuffers;
1423 break;
1424 // case GL_FRAMEBUFFER_BINDING: // now equivalent to
1425 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
1426 case GL_SUBPIXEL_BITS:
1427 *params = 4;
1428 break;
1429 case GL_MAX_TEXTURE_SIZE:
1430 *params = mCaps.max2DTextureSize;
1431 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001432 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
1433 *params = mCaps.maxRectangleTextureSize;
1434 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001435 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1436 *params = mCaps.maxCubeMapTextureSize;
1437 break;
1438 case GL_MAX_3D_TEXTURE_SIZE:
1439 *params = mCaps.max3DTextureSize;
1440 break;
1441 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1442 *params = mCaps.maxArrayTextureLayers;
1443 break;
1444 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1445 *params = mCaps.uniformBufferOffsetAlignment;
1446 break;
1447 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1448 *params = mCaps.maxUniformBufferBindings;
1449 break;
1450 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
1451 *params = mCaps.maxVertexUniformBlocks;
1452 break;
1453 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
1454 *params = mCaps.maxFragmentUniformBlocks;
1455 break;
1456 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1457 *params = mCaps.maxCombinedTextureImageUnits;
1458 break;
1459 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1460 *params = mCaps.maxVertexOutputComponents;
1461 break;
1462 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1463 *params = mCaps.maxFragmentInputComponents;
1464 break;
1465 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1466 *params = mCaps.minProgramTexelOffset;
1467 break;
1468 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1469 *params = mCaps.maxProgramTexelOffset;
1470 break;
1471 case GL_MAJOR_VERSION:
1472 *params = getClientVersion().major;
1473 break;
1474 case GL_MINOR_VERSION:
1475 *params = getClientVersion().minor;
1476 break;
1477 case GL_MAX_ELEMENTS_INDICES:
1478 *params = mCaps.maxElementsIndices;
1479 break;
1480 case GL_MAX_ELEMENTS_VERTICES:
1481 *params = mCaps.maxElementsVertices;
1482 break;
1483 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1484 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1485 break;
1486 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1487 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1488 break;
1489 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1490 *params = mCaps.maxTransformFeedbackSeparateComponents;
1491 break;
1492 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1493 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1494 break;
1495 case GL_MAX_SAMPLES_ANGLE:
1496 *params = mCaps.maxSamples;
1497 break;
1498 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001499 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001500 params[0] = mCaps.maxViewportWidth;
1501 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001502 }
1503 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001504 case GL_COMPRESSED_TEXTURE_FORMATS:
1505 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1506 params);
1507 break;
1508 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1509 *params = mResetStrategy;
1510 break;
1511 case GL_NUM_SHADER_BINARY_FORMATS:
1512 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1513 break;
1514 case GL_SHADER_BINARY_FORMATS:
1515 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1516 break;
1517 case GL_NUM_PROGRAM_BINARY_FORMATS:
1518 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1519 break;
1520 case GL_PROGRAM_BINARY_FORMATS:
1521 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1522 break;
1523 case GL_NUM_EXTENSIONS:
1524 *params = static_cast<GLint>(mExtensionStrings.size());
1525 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001526
Jamie Madill231c7f52017-04-26 13:45:37 -04001527 // GL_KHR_debug
1528 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1529 *params = mExtensions.maxDebugMessageLength;
1530 break;
1531 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1532 *params = mExtensions.maxDebugLoggedMessages;
1533 break;
1534 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1535 *params = mExtensions.maxDebugGroupStackDepth;
1536 break;
1537 case GL_MAX_LABEL_LENGTH:
1538 *params = mExtensions.maxLabelLength;
1539 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001540
Martin Radeve5285d22017-07-14 16:23:53 +03001541 // GL_ANGLE_multiview
1542 case GL_MAX_VIEWS_ANGLE:
1543 *params = mExtensions.maxViews;
1544 break;
1545
Jamie Madill231c7f52017-04-26 13:45:37 -04001546 // GL_EXT_disjoint_timer_query
1547 case GL_GPU_DISJOINT_EXT:
1548 *params = mImplementation->getGPUDisjoint();
1549 break;
1550 case GL_MAX_FRAMEBUFFER_WIDTH:
1551 *params = mCaps.maxFramebufferWidth;
1552 break;
1553 case GL_MAX_FRAMEBUFFER_HEIGHT:
1554 *params = mCaps.maxFramebufferHeight;
1555 break;
1556 case GL_MAX_FRAMEBUFFER_SAMPLES:
1557 *params = mCaps.maxFramebufferSamples;
1558 break;
1559 case GL_MAX_SAMPLE_MASK_WORDS:
1560 *params = mCaps.maxSampleMaskWords;
1561 break;
1562 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1563 *params = mCaps.maxColorTextureSamples;
1564 break;
1565 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1566 *params = mCaps.maxDepthTextureSamples;
1567 break;
1568 case GL_MAX_INTEGER_SAMPLES:
1569 *params = mCaps.maxIntegerSamples;
1570 break;
1571 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1572 *params = mCaps.maxVertexAttribRelativeOffset;
1573 break;
1574 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1575 *params = mCaps.maxVertexAttribBindings;
1576 break;
1577 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1578 *params = mCaps.maxVertexAttribStride;
1579 break;
1580 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
1581 *params = mCaps.maxVertexAtomicCounterBuffers;
1582 break;
1583 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
1584 *params = mCaps.maxVertexAtomicCounters;
1585 break;
1586 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
1587 *params = mCaps.maxVertexImageUniforms;
1588 break;
1589 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
1590 *params = mCaps.maxVertexShaderStorageBlocks;
1591 break;
1592 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
1593 *params = mCaps.maxFragmentAtomicCounterBuffers;
1594 break;
1595 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
1596 *params = mCaps.maxFragmentAtomicCounters;
1597 break;
1598 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
1599 *params = mCaps.maxFragmentImageUniforms;
1600 break;
1601 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
1602 *params = mCaps.maxFragmentShaderStorageBlocks;
1603 break;
1604 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1605 *params = mCaps.minProgramTextureGatherOffset;
1606 break;
1607 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1608 *params = mCaps.maxProgramTextureGatherOffset;
1609 break;
1610 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1611 *params = mCaps.maxComputeWorkGroupInvocations;
1612 break;
1613 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
1614 *params = mCaps.maxComputeUniformBlocks;
1615 break;
1616 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
1617 *params = mCaps.maxComputeTextureImageUnits;
1618 break;
1619 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1620 *params = mCaps.maxComputeSharedMemorySize;
1621 break;
1622 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
1623 *params = mCaps.maxComputeUniformComponents;
1624 break;
1625 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
1626 *params = mCaps.maxComputeAtomicCounterBuffers;
1627 break;
1628 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
1629 *params = mCaps.maxComputeAtomicCounters;
1630 break;
1631 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
1632 *params = mCaps.maxComputeImageUniforms;
1633 break;
1634 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
1635 *params = mCaps.maxCombinedComputeUniformComponents;
1636 break;
1637 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
1638 *params = mCaps.maxComputeShaderStorageBlocks;
1639 break;
1640 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1641 *params = mCaps.maxCombinedShaderOutputResources;
1642 break;
1643 case GL_MAX_UNIFORM_LOCATIONS:
1644 *params = mCaps.maxUniformLocations;
1645 break;
1646 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1647 *params = mCaps.maxAtomicCounterBufferBindings;
1648 break;
1649 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1650 *params = mCaps.maxAtomicCounterBufferSize;
1651 break;
1652 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1653 *params = mCaps.maxCombinedAtomicCounterBuffers;
1654 break;
1655 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1656 *params = mCaps.maxCombinedAtomicCounters;
1657 break;
1658 case GL_MAX_IMAGE_UNITS:
1659 *params = mCaps.maxImageUnits;
1660 break;
1661 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1662 *params = mCaps.maxCombinedImageUniforms;
1663 break;
1664 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1665 *params = mCaps.maxShaderStorageBufferBindings;
1666 break;
1667 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1668 *params = mCaps.maxCombinedShaderStorageBlocks;
1669 break;
1670 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1671 *params = mCaps.shaderStorageBufferOffsetAlignment;
1672 break;
1673 default:
1674 mGLState.getIntegerv(this, pname, params);
1675 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001676 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001677}
1678
Jamie Madill893ab082014-05-16 16:56:10 -04001679void Context::getInteger64v(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001680{
Shannon Woods53a94a82014-06-24 15:20:36 -04001681 // Queries about context capabilities and maximums are answered by Context.
1682 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001683 switch (pname)
1684 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001685 case GL_MAX_ELEMENT_INDEX:
1686 *params = mCaps.maxElementIndex;
1687 break;
1688 case GL_MAX_UNIFORM_BLOCK_SIZE:
1689 *params = mCaps.maxUniformBlockSize;
1690 break;
1691 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
1692 *params = mCaps.maxCombinedVertexUniformComponents;
1693 break;
1694 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
1695 *params = mCaps.maxCombinedFragmentUniformComponents;
1696 break;
1697 case GL_MAX_SERVER_WAIT_TIMEOUT:
1698 *params = mCaps.maxServerWaitTimeout;
1699 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001700
Jamie Madill231c7f52017-04-26 13:45:37 -04001701 // GL_EXT_disjoint_timer_query
1702 case GL_TIMESTAMP_EXT:
1703 *params = mImplementation->getTimestamp();
1704 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001705
Jamie Madill231c7f52017-04-26 13:45:37 -04001706 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1707 *params = mCaps.maxShaderStorageBlockSize;
1708 break;
1709 default:
1710 UNREACHABLE();
1711 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001712 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001713}
1714
Geoff Lang70d0f492015-12-10 17:45:46 -05001715void Context::getPointerv(GLenum pname, void **params) const
1716{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001717 mGLState.getPointerv(pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001718}
1719
Martin Radev66fb8202016-07-28 11:45:20 +03001720void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001721{
Shannon Woods53a94a82014-06-24 15:20:36 -04001722 // Queries about context capabilities and maximums are answered by Context.
1723 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001724
1725 GLenum nativeType;
1726 unsigned int numParams;
1727 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1728 ASSERT(queryStatus);
1729
1730 if (nativeType == GL_INT)
1731 {
1732 switch (target)
1733 {
1734 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1735 ASSERT(index < 3u);
1736 *data = mCaps.maxComputeWorkGroupCount[index];
1737 break;
1738 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1739 ASSERT(index < 3u);
1740 *data = mCaps.maxComputeWorkGroupSize[index];
1741 break;
1742 default:
1743 mGLState.getIntegeri_v(target, index, data);
1744 }
1745 }
1746 else
1747 {
1748 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1749 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001750}
1751
Martin Radev66fb8202016-07-28 11:45:20 +03001752void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001753{
Shannon Woods53a94a82014-06-24 15:20:36 -04001754 // Queries about context capabilities and maximums are answered by Context.
1755 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001756
1757 GLenum nativeType;
1758 unsigned int numParams;
1759 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1760 ASSERT(queryStatus);
1761
1762 if (nativeType == GL_INT_64_ANGLEX)
1763 {
1764 mGLState.getInteger64i_v(target, index, data);
1765 }
1766 else
1767 {
1768 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1769 }
1770}
1771
1772void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1773{
1774 // Queries about context capabilities and maximums are answered by Context.
1775 // Queries about current GL state values are answered by State.
1776
1777 GLenum nativeType;
1778 unsigned int numParams;
1779 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1780 ASSERT(queryStatus);
1781
1782 if (nativeType == GL_BOOL)
1783 {
1784 mGLState.getBooleani_v(target, index, data);
1785 }
1786 else
1787 {
1788 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1789 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001790}
1791
He Yunchao010e4db2017-03-03 14:22:06 +08001792void Context::getBufferParameteriv(GLenum target, GLenum pname, GLint *params)
1793{
1794 Buffer *buffer = mGLState.getTargetBuffer(target);
1795 QueryBufferParameteriv(buffer, pname, params);
1796}
1797
1798void Context::getFramebufferAttachmentParameteriv(GLenum target,
1799 GLenum attachment,
1800 GLenum pname,
1801 GLint *params)
1802{
1803 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
1804 QueryFramebufferAttachmentParameteriv(framebuffer, attachment, pname, params);
1805}
1806
1807void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
1808{
1809 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
1810 QueryRenderbufferiv(this, renderbuffer, pname, params);
1811}
1812
1813void Context::getTexParameterfv(GLenum target, GLenum pname, GLfloat *params)
1814{
1815 Texture *texture = getTargetTexture(target);
1816 QueryTexParameterfv(texture, pname, params);
1817}
1818
1819void Context::getTexParameteriv(GLenum target, GLenum pname, GLint *params)
1820{
1821 Texture *texture = getTargetTexture(target);
1822 QueryTexParameteriv(texture, pname, params);
1823}
1824void Context::texParameterf(GLenum target, GLenum pname, GLfloat param)
1825{
1826 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001827 SetTexParameterf(this, texture, pname, param);
He Yunchao010e4db2017-03-03 14:22:06 +08001828}
1829
1830void Context::texParameterfv(GLenum target, GLenum pname, const GLfloat *params)
1831{
1832 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001833 SetTexParameterfv(this, texture, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08001834}
1835
1836void Context::texParameteri(GLenum target, GLenum pname, GLint param)
1837{
1838 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001839 SetTexParameteri(this, texture, pname, param);
He Yunchao010e4db2017-03-03 14:22:06 +08001840}
1841
1842void Context::texParameteriv(GLenum target, GLenum pname, const GLint *params)
1843{
1844 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001845 SetTexParameteriv(this, texture, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08001846}
1847
Jamie Madill675fe712016-12-19 13:07:54 -05001848void Context::drawArrays(GLenum mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001849{
Jamie Madill4c19a8a2017-07-24 11:46:06 -04001850 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04001851 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
1852 MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001853}
1854
Jamie Madill675fe712016-12-19 13:07:54 -05001855void Context::drawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04001856{
Jamie Madill4c19a8a2017-07-24 11:46:06 -04001857 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04001858 ANGLE_CONTEXT_TRY(
1859 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
1860 MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback());
Geoff Langf6db0982015-08-25 13:04:00 -04001861}
1862
Jamie Madill876429b2017-04-20 15:46:24 -04001863void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001864{
Jamie Madill4c19a8a2017-07-24 11:46:06 -04001865 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04001866 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04001867}
1868
Jamie Madill675fe712016-12-19 13:07:54 -05001869void Context::drawElementsInstanced(GLenum mode,
1870 GLsizei count,
1871 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04001872 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04001873 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04001874{
Jamie Madill4c19a8a2017-07-24 11:46:06 -04001875 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04001876 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08001877 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04001878}
1879
Jamie Madill675fe712016-12-19 13:07:54 -05001880void Context::drawRangeElements(GLenum mode,
1881 GLuint start,
1882 GLuint end,
1883 GLsizei count,
1884 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04001885 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04001886{
Jamie Madill4c19a8a2017-07-24 11:46:06 -04001887 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04001888 ANGLE_CONTEXT_TRY(
1889 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001890}
1891
Jamie Madill876429b2017-04-20 15:46:24 -04001892void Context::drawArraysIndirect(GLenum mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08001893{
Jamie Madill4c19a8a2017-07-24 11:46:06 -04001894 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04001895 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08001896}
1897
Jamie Madill876429b2017-04-20 15:46:24 -04001898void Context::drawElementsIndirect(GLenum mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08001899{
Jamie Madill4c19a8a2017-07-24 11:46:06 -04001900 ANGLE_CONTEXT_TRY(prepareForDraw(mode));
Jamie Madillb6664922017-07-25 12:55:04 -04001901 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08001902}
1903
Jamie Madill675fe712016-12-19 13:07:54 -05001904void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001905{
Jamie Madill675fe712016-12-19 13:07:54 -05001906 handleError(mImplementation->flush());
Geoff Lang129753a2015-01-09 16:52:09 -05001907}
1908
Jamie Madill675fe712016-12-19 13:07:54 -05001909void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05001910{
Jamie Madill675fe712016-12-19 13:07:54 -05001911 handleError(mImplementation->finish());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001912}
1913
Austin Kinross6ee1e782015-05-29 17:05:37 -07001914void Context::insertEventMarker(GLsizei length, const char *marker)
1915{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001916 ASSERT(mImplementation);
1917 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07001918}
1919
1920void Context::pushGroupMarker(GLsizei length, const char *marker)
1921{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001922 ASSERT(mImplementation);
1923 mImplementation->pushGroupMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07001924}
1925
1926void Context::popGroupMarker()
1927{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001928 ASSERT(mImplementation);
1929 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07001930}
1931
Geoff Langd8605522016-04-13 10:19:12 -04001932void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
1933{
1934 Program *programObject = getProgram(program);
1935 ASSERT(programObject);
1936
1937 programObject->bindUniformLocation(location, name);
1938}
1939
Sami Väisänena797e062016-05-12 15:23:40 +03001940void Context::setCoverageModulation(GLenum components)
1941{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001942 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03001943}
1944
Sami Väisänene45e53b2016-05-25 10:36:04 +03001945void Context::loadPathRenderingMatrix(GLenum matrixMode, const GLfloat *matrix)
1946{
1947 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
1948}
1949
1950void Context::loadPathRenderingIdentityMatrix(GLenum matrixMode)
1951{
1952 GLfloat I[16];
1953 angle::Matrix<GLfloat>::setToIdentity(I);
1954
1955 mGLState.loadPathRenderingMatrix(matrixMode, I);
1956}
1957
1958void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
1959{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001960 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001961 if (!pathObj)
1962 return;
1963
1964 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1965 syncRendererState();
1966
1967 mImplementation->stencilFillPath(pathObj, fillMode, mask);
1968}
1969
1970void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
1971{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001972 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001973 if (!pathObj)
1974 return;
1975
1976 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1977 syncRendererState();
1978
1979 mImplementation->stencilStrokePath(pathObj, reference, mask);
1980}
1981
1982void Context::coverFillPath(GLuint path, GLenum coverMode)
1983{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001984 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001985 if (!pathObj)
1986 return;
1987
1988 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1989 syncRendererState();
1990
1991 mImplementation->coverFillPath(pathObj, coverMode);
1992}
1993
1994void Context::coverStrokePath(GLuint path, GLenum coverMode)
1995{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001996 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001997 if (!pathObj)
1998 return;
1999
2000 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2001 syncRendererState();
2002
2003 mImplementation->coverStrokePath(pathObj, coverMode);
2004}
2005
2006void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
2007{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002008 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002009 if (!pathObj)
2010 return;
2011
2012 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2013 syncRendererState();
2014
2015 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
2016}
2017
2018void Context::stencilThenCoverStrokePath(GLuint path,
2019 GLint reference,
2020 GLuint mask,
2021 GLenum coverMode)
2022{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002023 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002024 if (!pathObj)
2025 return;
2026
2027 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2028 syncRendererState();
2029
2030 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2031}
2032
Sami Väisänend59ca052016-06-21 16:10:00 +03002033void Context::coverFillPathInstanced(GLsizei numPaths,
2034 GLenum pathNameType,
2035 const void *paths,
2036 GLuint pathBase,
2037 GLenum coverMode,
2038 GLenum transformType,
2039 const GLfloat *transformValues)
2040{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002041 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002042
2043 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2044 syncRendererState();
2045
2046 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2047}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002048
Sami Väisänend59ca052016-06-21 16:10:00 +03002049void Context::coverStrokePathInstanced(GLsizei numPaths,
2050 GLenum pathNameType,
2051 const void *paths,
2052 GLuint pathBase,
2053 GLenum coverMode,
2054 GLenum transformType,
2055 const GLfloat *transformValues)
2056{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002057 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002058
2059 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2060 syncRendererState();
2061
2062 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2063 transformValues);
2064}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002065
Sami Väisänend59ca052016-06-21 16:10:00 +03002066void Context::stencilFillPathInstanced(GLsizei numPaths,
2067 GLenum pathNameType,
2068 const void *paths,
2069 GLuint pathBase,
2070 GLenum fillMode,
2071 GLuint mask,
2072 GLenum transformType,
2073 const GLfloat *transformValues)
2074{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002075 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002076
2077 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2078 syncRendererState();
2079
2080 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2081 transformValues);
2082}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002083
Sami Väisänend59ca052016-06-21 16:10:00 +03002084void Context::stencilStrokePathInstanced(GLsizei numPaths,
2085 GLenum pathNameType,
2086 const void *paths,
2087 GLuint pathBase,
2088 GLint reference,
2089 GLuint mask,
2090 GLenum transformType,
2091 const GLfloat *transformValues)
2092{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002093 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002094
2095 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2096 syncRendererState();
2097
2098 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2099 transformValues);
2100}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002101
Sami Väisänend59ca052016-06-21 16:10:00 +03002102void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2103 GLenum pathNameType,
2104 const void *paths,
2105 GLuint pathBase,
2106 GLenum fillMode,
2107 GLuint mask,
2108 GLenum coverMode,
2109 GLenum transformType,
2110 const GLfloat *transformValues)
2111{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002112 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002113
2114 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2115 syncRendererState();
2116
2117 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2118 transformType, transformValues);
2119}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002120
Sami Väisänend59ca052016-06-21 16:10:00 +03002121void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2122 GLenum pathNameType,
2123 const void *paths,
2124 GLuint pathBase,
2125 GLint reference,
2126 GLuint mask,
2127 GLenum coverMode,
2128 GLenum transformType,
2129 const GLfloat *transformValues)
2130{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002131 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002132
2133 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2134 syncRendererState();
2135
2136 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2137 transformType, transformValues);
2138}
2139
Sami Väisänen46eaa942016-06-29 10:26:37 +03002140void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2141{
2142 auto *programObject = getProgram(program);
2143
2144 programObject->bindFragmentInputLocation(location, name);
2145}
2146
2147void Context::programPathFragmentInputGen(GLuint program,
2148 GLint location,
2149 GLenum genMode,
2150 GLint components,
2151 const GLfloat *coeffs)
2152{
2153 auto *programObject = getProgram(program);
2154
Jamie Madillbd044ed2017-06-05 12:59:21 -04002155 programObject->pathFragmentInputGen(this, location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002156}
2157
jchen1015015f72017-03-16 13:54:21 +08002158GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2159{
jchen10fd7c3b52017-03-21 15:36:03 +08002160 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002161 return QueryProgramResourceIndex(programObject, programInterface, name);
2162}
2163
jchen10fd7c3b52017-03-21 15:36:03 +08002164void Context::getProgramResourceName(GLuint program,
2165 GLenum programInterface,
2166 GLuint index,
2167 GLsizei bufSize,
2168 GLsizei *length,
2169 GLchar *name)
2170{
2171 const auto *programObject = getProgram(program);
2172 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2173}
2174
jchen10191381f2017-04-11 13:59:04 +08002175GLint Context::getProgramResourceLocation(GLuint program,
2176 GLenum programInterface,
2177 const GLchar *name)
2178{
2179 const auto *programObject = getProgram(program);
2180 return QueryProgramResourceLocation(programObject, programInterface, name);
2181}
2182
Jamie Madill4c19a8a2017-07-24 11:46:06 -04002183Error Context::handleError(const Error &error)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002184{
Geoff Langda5777c2014-07-11 09:52:58 -04002185 if (error.isError())
2186 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002187 GLenum code = error.getCode();
2188 mErrors.insert(code);
2189 if (code == GL_OUT_OF_MEMORY && getWorkarounds().loseContextOnOutOfMemory)
2190 {
2191 markContextLost();
2192 }
Geoff Lang70d0f492015-12-10 17:45:46 -05002193
2194 if (!error.getMessage().empty())
2195 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002196 auto *debug = &mGLState.getDebug();
2197 debug->insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, error.getID(),
2198 GL_DEBUG_SEVERITY_HIGH, error.getMessage());
Geoff Lang70d0f492015-12-10 17:45:46 -05002199 }
Geoff Langda5777c2014-07-11 09:52:58 -04002200 }
Jamie Madill4c19a8a2017-07-24 11:46:06 -04002201
2202 return error;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002203}
2204
2205// Get one of the recorded errors and clear its flag, if any.
2206// [OpenGL ES 2.0.24] section 2.5 page 13.
2207GLenum Context::getError()
2208{
Geoff Langda5777c2014-07-11 09:52:58 -04002209 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002210 {
Geoff Langda5777c2014-07-11 09:52:58 -04002211 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002212 }
Geoff Langda5777c2014-07-11 09:52:58 -04002213 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002214 {
Geoff Langda5777c2014-07-11 09:52:58 -04002215 GLenum error = *mErrors.begin();
2216 mErrors.erase(mErrors.begin());
2217 return error;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002218 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002219}
2220
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002221// NOTE: this function should not assume that this context is current!
2222void Context::markContextLost()
2223{
2224 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002225 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002226 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002227 mContextLostForced = true;
2228 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002229 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002230}
2231
2232bool Context::isContextLost()
2233{
2234 return mContextLost;
2235}
2236
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002237GLenum Context::getResetStatus()
2238{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002239 // Even if the application doesn't want to know about resets, we want to know
2240 // as it will allow us to skip all the calls.
2241 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002242 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002243 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002244 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002245 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002246 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002247
2248 // EXT_robustness, section 2.6: If the reset notification behavior is
2249 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2250 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2251 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002252 }
2253
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002254 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2255 // status should be returned at least once, and GL_NO_ERROR should be returned
2256 // once the device has finished resetting.
2257 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002258 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002259 ASSERT(mResetStatus == GL_NO_ERROR);
2260 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002261
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002262 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002263 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002264 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002265 }
2266 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002267 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002268 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002269 // If markContextLost was used to mark the context lost then
2270 // assume that is not recoverable, and continue to report the
2271 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002272 mResetStatus = mImplementation->getResetStatus();
2273 }
Jamie Madill893ab082014-05-16 16:56:10 -04002274
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002275 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002276}
2277
2278bool Context::isResetNotificationEnabled()
2279{
2280 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2281}
2282
Corentin Walleze3b10e82015-05-20 11:06:25 -04002283const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002284{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002285 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002286}
2287
2288EGLenum Context::getClientType() const
2289{
2290 return mClientType;
2291}
2292
2293EGLenum Context::getRenderBuffer() const
2294{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002295 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2296 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002297 {
2298 return EGL_NONE;
2299 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002300
2301 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(GL_BACK);
2302 ASSERT(backAttachment != nullptr);
2303 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002304}
2305
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002306VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002307{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002308 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002309 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2310 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002311 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002312 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2313 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002314
Jamie Madill96a483b2017-06-27 16:49:21 -04002315 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002316 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002317
2318 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002319}
2320
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002321TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002322{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002323 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002324 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2325 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002326 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002327 transformFeedback =
2328 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002329 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002330 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002331 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002332
2333 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002334}
2335
2336bool Context::isVertexArrayGenerated(GLuint vertexArray)
2337{
Jamie Madill96a483b2017-06-27 16:49:21 -04002338 ASSERT(mVertexArrayMap.contains(0));
2339 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002340}
2341
2342bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2343{
Jamie Madill96a483b2017-06-27 16:49:21 -04002344 ASSERT(mTransformFeedbackMap.contains(0));
2345 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002346}
2347
Shannon Woods53a94a82014-06-24 15:20:36 -04002348void Context::detachTexture(GLuint texture)
2349{
2350 // Simple pass-through to State's detachTexture method, as textures do not require
2351 // allocation map management either here or in the resource manager at detach time.
2352 // Zero textures are held by the Context, and we don't attempt to request them from
2353 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002354 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002355}
2356
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002357void Context::detachBuffer(GLuint buffer)
2358{
Yuly Novikov5807a532015-12-03 13:01:22 -05002359 // Simple pass-through to State's detachBuffer method, since
2360 // only buffer attachments to container objects that are bound to the current context
2361 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002362
Yuly Novikov5807a532015-12-03 13:01:22 -05002363 // [OpenGL ES 3.2] section 5.1.2 page 45:
2364 // Attachments to unbound container objects, such as
2365 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2366 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002367 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002368}
2369
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002370void Context::detachFramebuffer(GLuint framebuffer)
2371{
Shannon Woods53a94a82014-06-24 15:20:36 -04002372 // Framebuffer detachment is handled by Context, because 0 is a valid
2373 // Framebuffer object, and a pointer to it must be passed from Context
2374 // to State at binding time.
2375
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002376 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002377 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2378 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2379 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002380
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002381 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002382 {
2383 bindReadFramebuffer(0);
2384 }
2385
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002386 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002387 {
2388 bindDrawFramebuffer(0);
2389 }
2390}
2391
2392void Context::detachRenderbuffer(GLuint renderbuffer)
2393{
Jamie Madilla02315b2017-02-23 14:14:47 -05002394 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002395}
2396
Jamie Madill57a89722013-07-02 11:57:03 -04002397void Context::detachVertexArray(GLuint vertexArray)
2398{
Jamie Madill77a72f62015-04-14 11:18:32 -04002399 // Vertex array detachment is handled by Context, because 0 is a valid
2400 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002401 // binding time.
2402
Jamie Madill57a89722013-07-02 11:57:03 -04002403 // [OpenGL ES 3.0.2] section 2.10 page 43:
2404 // If a vertex array object that is currently bound is deleted, the binding
2405 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002406 if (mGLState.removeVertexArrayBinding(vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002407 {
2408 bindVertexArray(0);
2409 }
2410}
2411
Geoff Langc8058452014-02-03 12:04:11 -05002412void Context::detachTransformFeedback(GLuint transformFeedback)
2413{
Corentin Walleza2257da2016-04-19 16:43:12 -04002414 // Transform feedback detachment is handled by Context, because 0 is a valid
2415 // transform feedback, and a pointer to it must be passed from Context to State at
2416 // binding time.
2417
2418 // The OpenGL specification doesn't mention what should happen when the currently bound
2419 // transform feedback object is deleted. Since it is a container object, we treat it like
2420 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002421 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002422 {
2423 bindTransformFeedback(0);
2424 }
Geoff Langc8058452014-02-03 12:04:11 -05002425}
2426
Jamie Madilldc356042013-07-19 16:36:57 -04002427void Context::detachSampler(GLuint sampler)
2428{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002429 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002430}
2431
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002432void Context::setVertexAttribDivisor(GLuint index, GLuint divisor)
2433{
Shaodde78e82017-05-22 14:13:27 +08002434 mGLState.setVertexAttribDivisor(this, index, divisor);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002435}
2436
Jamie Madille29d1672013-07-19 16:36:57 -04002437void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2438{
Geoff Langc1984ed2016-10-07 12:41:00 -04002439 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002440 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002441 SetSamplerParameteri(samplerObject, pname, param);
2442}
Jamie Madille29d1672013-07-19 16:36:57 -04002443
Geoff Langc1984ed2016-10-07 12:41:00 -04002444void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2445{
2446 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002447 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002448 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madille29d1672013-07-19 16:36:57 -04002449}
2450
2451void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2452{
Geoff Langc1984ed2016-10-07 12:41:00 -04002453 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002454 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002455 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madille29d1672013-07-19 16:36:57 -04002456}
2457
Geoff Langc1984ed2016-10-07 12:41:00 -04002458void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002459{
Geoff Langc1984ed2016-10-07 12:41:00 -04002460 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002461 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002462 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill9675b802013-07-19 16:36:59 -04002463}
2464
Geoff Langc1984ed2016-10-07 12:41:00 -04002465void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002466{
Geoff Langc1984ed2016-10-07 12:41:00 -04002467 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002468 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002469 QuerySamplerParameteriv(samplerObject, pname, params);
2470}
Jamie Madill9675b802013-07-19 16:36:59 -04002471
Geoff Langc1984ed2016-10-07 12:41:00 -04002472void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2473{
2474 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002475 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002476 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill9675b802013-07-19 16:36:59 -04002477}
2478
Olli Etuahof0fee072016-03-30 15:11:58 +03002479void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2480{
2481 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002482 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002483}
2484
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002485void Context::initRendererString()
2486{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002487 std::ostringstream rendererString;
2488 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002489 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002490 rendererString << ")";
2491
Geoff Langcec35902014-04-16 10:52:36 -04002492 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002493}
2494
Geoff Langc339c4e2016-11-29 10:37:36 -05002495void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002496{
Geoff Langc339c4e2016-11-29 10:37:36 -05002497 const Version &clientVersion = getClientVersion();
2498
2499 std::ostringstream versionString;
2500 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2501 << ANGLE_VERSION_STRING << ")";
2502 mVersionString = MakeStaticString(versionString.str());
2503
2504 std::ostringstream shadingLanguageVersionString;
2505 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2506 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2507 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2508 << ")";
2509 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002510}
2511
Geoff Langcec35902014-04-16 10:52:36 -04002512void Context::initExtensionStrings()
2513{
Geoff Langc339c4e2016-11-29 10:37:36 -05002514 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2515 std::ostringstream combinedStringStream;
2516 std::copy(strings.begin(), strings.end(),
2517 std::ostream_iterator<const char *>(combinedStringStream, " "));
2518 return MakeStaticString(combinedStringStream.str());
2519 };
2520
2521 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002522 for (const auto &extensionString : mExtensions.getStrings())
2523 {
2524 mExtensionStrings.push_back(MakeStaticString(extensionString));
2525 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002526 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002527
Bryan Bernhart58806562017-01-05 13:09:31 -08002528 const gl::Extensions &nativeExtensions = mImplementation->getNativeExtensions();
2529
Geoff Langc339c4e2016-11-29 10:37:36 -05002530 mRequestableExtensionStrings.clear();
2531 for (const auto &extensionInfo : GetExtensionInfoMap())
2532 {
2533 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08002534 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
2535 nativeExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002536 {
2537 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
2538 }
2539 }
2540 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002541}
2542
Geoff Langc339c4e2016-11-29 10:37:36 -05002543const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04002544{
Geoff Langc339c4e2016-11-29 10:37:36 -05002545 switch (name)
2546 {
2547 case GL_VENDOR:
2548 return reinterpret_cast<const GLubyte *>("Google Inc.");
2549
2550 case GL_RENDERER:
2551 return reinterpret_cast<const GLubyte *>(mRendererString);
2552
2553 case GL_VERSION:
2554 return reinterpret_cast<const GLubyte *>(mVersionString);
2555
2556 case GL_SHADING_LANGUAGE_VERSION:
2557 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
2558
2559 case GL_EXTENSIONS:
2560 return reinterpret_cast<const GLubyte *>(mExtensionString);
2561
2562 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2563 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
2564
2565 default:
2566 UNREACHABLE();
2567 return nullptr;
2568 }
Geoff Langcec35902014-04-16 10:52:36 -04002569}
2570
Geoff Langc339c4e2016-11-29 10:37:36 -05002571const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04002572{
Geoff Langc339c4e2016-11-29 10:37:36 -05002573 switch (name)
2574 {
2575 case GL_EXTENSIONS:
2576 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
2577
2578 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2579 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
2580
2581 default:
2582 UNREACHABLE();
2583 return nullptr;
2584 }
Geoff Langcec35902014-04-16 10:52:36 -04002585}
2586
2587size_t Context::getExtensionStringCount() const
2588{
2589 return mExtensionStrings.size();
2590}
2591
Geoff Langc339c4e2016-11-29 10:37:36 -05002592void Context::requestExtension(const char *name)
2593{
2594 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2595 ASSERT(extensionInfos.find(name) != extensionInfos.end());
2596 const auto &extension = extensionInfos.at(name);
2597 ASSERT(extension.Requestable);
2598
2599 if (mExtensions.*(extension.ExtensionsMember))
2600 {
2601 // Extension already enabled
2602 return;
2603 }
2604
2605 mExtensions.*(extension.ExtensionsMember) = true;
2606 updateCaps();
2607 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08002608
Jamie Madill2f348d22017-06-05 10:50:59 -04002609 // Release the shader compiler so it will be re-created with the requested extensions enabled.
2610 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04002611
2612 // Invalidate all cached completenesses for textures and framebuffer. Some extensions make new
2613 // formats renderable or sampleable.
2614 mState.mTextures->invalidateTextureComplenessCache();
2615 for (auto &zeroTexture : mZeroTextures)
2616 {
2617 zeroTexture.second->invalidateCompletenessCache();
2618 }
2619
2620 mState.mFramebuffers->invalidateFramebufferComplenessCache();
Geoff Langc339c4e2016-11-29 10:37:36 -05002621}
2622
2623size_t Context::getRequestableExtensionStringCount() const
2624{
2625 return mRequestableExtensionStrings.size();
2626}
2627
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002628void Context::beginTransformFeedback(GLenum primitiveMode)
2629{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002630 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002631 ASSERT(transformFeedback != nullptr);
2632 ASSERT(!transformFeedback->isPaused());
2633
Jamie Madill6c1f6712017-02-14 19:08:04 -05002634 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002635}
2636
2637bool Context::hasActiveTransformFeedback(GLuint program) const
2638{
2639 for (auto pair : mTransformFeedbackMap)
2640 {
2641 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
2642 {
2643 return true;
2644 }
2645 }
2646 return false;
2647}
2648
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002649void Context::initCaps(const egl::DisplayExtensions &displayExtensions)
Geoff Lang493daf52014-07-03 13:38:44 -04002650{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002651 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04002652
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002653 mExtensions = mImplementation->getNativeExtensions();
Geoff Lang493daf52014-07-03 13:38:44 -04002654
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002655 mLimitations = mImplementation->getNativeLimitations();
Austin Kinross02df7962015-07-01 10:03:42 -07002656
Geoff Langeb66a6e2016-10-31 13:06:12 -04002657 if (getClientVersion() < Version(3, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002658 {
2659 // Disable ES3+ extensions
Jamie Madill231c7f52017-04-26 13:45:37 -04002660 mExtensions.colorBufferFloat = false;
Geoff Langb66a9092016-05-16 15:59:14 -04002661 mExtensions.eglImageExternalEssl3 = false;
Vincent Lang25ab4512016-05-13 18:13:59 +02002662 mExtensions.textureNorm16 = false;
Martin Radev137032d2017-07-13 10:11:12 +03002663 mExtensions.multiview = false;
2664 mExtensions.maxViews = 1u;
Geoff Lang493daf52014-07-03 13:38:44 -04002665 }
2666
Geoff Langeb66a6e2016-10-31 13:06:12 -04002667 if (getClientVersion() > Version(2, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002668 {
2669 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
Jamie Madill231c7f52017-04-26 13:45:37 -04002670 // mExtensions.sRGB = false;
Geoff Lang493daf52014-07-03 13:38:44 -04002671 }
2672
Jamie Madill00ed7a12016-05-19 13:13:38 -04002673 // Some extensions are always available because they are implemented in the GL layer.
Jamie Madill231c7f52017-04-26 13:45:37 -04002674 mExtensions.bindUniformLocation = true;
2675 mExtensions.vertexArrayObject = true;
Geoff Langf41a7152016-09-19 15:11:17 -04002676 mExtensions.bindGeneratesResource = true;
Geoff Langfeb8c682017-02-13 16:07:35 -05002677 mExtensions.clientArrays = true;
Geoff Langc339c4e2016-11-29 10:37:36 -05002678 mExtensions.requestExtension = true;
Jamie Madill00ed7a12016-05-19 13:13:38 -04002679
2680 // Enable the no error extension if the context was created with the flag.
2681 mExtensions.noError = mSkipValidation;
2682
Corentin Wallezccab69d2017-01-27 16:57:15 -05002683 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Corentin Wallezc295e512017-01-27 17:47:50 -05002684 mExtensions.surfacelessContext = displayExtensions.surfacelessContext;
Corentin Wallezccab69d2017-01-27 16:57:15 -05002685
Geoff Lang70d0f492015-12-10 17:45:46 -05002686 // Explicitly enable GL_KHR_debug
2687 mExtensions.debug = true;
2688 mExtensions.maxDebugMessageLength = 1024;
2689 mExtensions.maxDebugLoggedMessages = 1024;
2690 mExtensions.maxDebugGroupStackDepth = 1024;
2691 mExtensions.maxLabelLength = 1024;
2692
Geoff Langff5b2d52016-09-07 11:32:23 -04002693 // Explicitly enable GL_ANGLE_robust_client_memory
2694 mExtensions.robustClientMemory = true;
2695
Jamie Madille08a1d32017-03-07 17:24:06 -05002696 // Determine robust resource init availability from EGL.
2697 mExtensions.robustResourceInitialization =
Jamie Madill948bbe52017-06-01 13:10:42 -04002698 egl::Display::GetClientExtensions().displayRobustResourceInitialization;
Jamie Madille08a1d32017-03-07 17:24:06 -05002699
Jamie Madillc43be722017-07-13 16:22:14 -04002700 // Enable the cache control query unconditionally.
2701 mExtensions.programCacheControl = true;
2702
Geoff Lang301d1612014-07-09 10:34:37 -04002703 // Apply implementation limits
2704 mCaps.maxVertexAttributes = std::min<GLuint>(mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002705 mCaps.maxVertexAttribBindings =
2706 getClientVersion() < ES_3_1
2707 ? mCaps.maxVertexAttributes
2708 : std::min<GLuint>(mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
2709
Jamie Madill231c7f52017-04-26 13:45:37 -04002710 mCaps.maxVertexUniformBlocks = std::min<GLuint>(
2711 mCaps.maxVertexUniformBlocks, IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
2712 mCaps.maxVertexOutputComponents =
2713 std::min<GLuint>(mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
Geoff Lang301d1612014-07-09 10:34:37 -04002714
Jamie Madill231c7f52017-04-26 13:45:37 -04002715 mCaps.maxFragmentInputComponents =
2716 std::min<GLuint>(mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
Geoff Lang3a61c322014-07-10 13:01:54 -04002717
Geoff Langc287ea62016-09-16 14:46:51 -04002718 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002719 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04002720 for (const auto &extensionInfo : GetExtensionInfoMap())
2721 {
2722 // If this context is for WebGL, disable all enableable extensions
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002723 if (mWebGLContext && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04002724 {
2725 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
2726 }
2727 }
2728
2729 // Generate texture caps
2730 updateCaps();
2731}
2732
2733void Context::updateCaps()
2734{
Geoff Lang900013c2014-07-07 11:32:19 -04002735 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002736 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04002737
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002738 for (auto capsIt : mImplementation->getNativeTextureCaps())
Geoff Lang493daf52014-07-03 13:38:44 -04002739 {
Geoff Langca271392017-04-05 12:30:00 -04002740 GLenum sizedInternalFormat = capsIt.first;
Jamie Madill231c7f52017-04-26 13:45:37 -04002741 TextureCaps formatCaps = capsIt.second;
Geoff Lang493daf52014-07-03 13:38:44 -04002742
Geoff Langca271392017-04-05 12:30:00 -04002743 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04002744
Geoff Lang0d8b7242015-09-09 14:56:53 -04002745 // Update the format caps based on the client version and extensions.
2746 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
2747 // ES3.
2748 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002749 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002750 formatCaps.renderable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002751 formatCaps.renderable && formatInfo.renderSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002752 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002753 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04002754
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002755 // OpenGL ES does not support multisampling with non-rendererable formats
2756 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Olli Etuaho50c562d2017-06-06 14:43:30 +03002757 if (!formatCaps.renderable ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002758 (getClientVersion() < ES_3_1 &&
2759 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04002760 {
Geoff Langd87878e2014-09-19 15:42:59 -04002761 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04002762 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03002763 else
2764 {
2765 // We may have limited the max samples for some required renderbuffer formats due to
2766 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
2767 GLuint formatMaxSamples = formatCaps.getMaxSamples();
2768
2769 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
2770 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
2771 // exception of signed and unsigned integer formats."
2772 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
2773 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
2774 {
2775 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
2776 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
2777 }
2778
2779 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
2780 if (getClientVersion() >= ES_3_1)
2781 {
2782 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
2783 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
2784 // the exception that the signed and unsigned integer formats are required only to
2785 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
2786 // multisamples, which must be at least one."
2787 if (formatInfo.componentType == GL_INT ||
2788 formatInfo.componentType == GL_UNSIGNED_INT)
2789 {
2790 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
2791 }
2792
2793 // GLES 3.1 section 19.3.1.
2794 if (formatCaps.texturable)
2795 {
2796 if (formatInfo.depthBits > 0)
2797 {
2798 mCaps.maxDepthTextureSamples =
2799 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
2800 }
2801 else if (formatInfo.redBits > 0)
2802 {
2803 mCaps.maxColorTextureSamples =
2804 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
2805 }
2806 }
2807 }
2808 }
Geoff Langd87878e2014-09-19 15:42:59 -04002809
2810 if (formatCaps.texturable && formatInfo.compressed)
2811 {
Geoff Langca271392017-04-05 12:30:00 -04002812 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04002813 }
2814
Geoff Langca271392017-04-05 12:30:00 -04002815 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04002816 }
Jamie Madill32447362017-06-28 14:53:52 -04002817
2818 // If program binary is disabled, blank out the memory cache pointer.
2819 if (!mImplementation->getNativeExtensions().getProgramBinary)
2820 {
2821 mMemoryProgramCache = nullptr;
2822 }
Geoff Lang493daf52014-07-03 13:38:44 -04002823}
2824
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002825void Context::initWorkarounds()
2826{
Jamie Madill761b02c2017-06-23 16:27:06 -04002827 // Apply back-end workarounds.
2828 mImplementation->applyNativeWorkarounds(&mWorkarounds);
2829
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002830 // Lose the context upon out of memory error if the application is
2831 // expecting to watch for those events.
2832 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2833}
2834
Jamie Madill4c19a8a2017-07-24 11:46:06 -04002835Error Context::prepareForDraw(GLenum drawMode)
Jamie Madillb6664922017-07-25 12:55:04 -04002836{
2837 syncRendererState();
Jamie Madill4c19a8a2017-07-24 11:46:06 -04002838
2839 InfoLog infoLog;
2840 Error err = mImplementation->triggerDrawCallProgramRecompilation(this, &infoLog,
2841 mMemoryProgramCache, drawMode);
2842 if (err.isError())
2843 {
2844 WARN() << "Dynamic recompilation error log: " << infoLog.str();
2845 }
2846 return err;
Jamie Madillb6664922017-07-25 12:55:04 -04002847}
2848
Jamie Madill1b94d432015-08-07 13:23:23 -04002849void Context::syncRendererState()
2850{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002851 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
Jamie Madillfe548342017-06-19 11:13:24 -04002852 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002853 mGLState.clearDirtyBits();
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002854 mGLState.syncDirtyObjects(this);
Jamie Madill1b94d432015-08-07 13:23:23 -04002855}
2856
Jamie Madillad9f24e2016-02-12 09:27:24 -05002857void Context::syncRendererState(const State::DirtyBits &bitMask,
2858 const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04002859{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002860 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madillfe548342017-06-19 11:13:24 -04002861 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002862 mGLState.clearDirtyBits(dirtyBits);
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002863 mGLState.syncDirtyObjects(this, objectMask);
Jamie Madill1b94d432015-08-07 13:23:23 -04002864}
Jamie Madillc29968b2016-01-20 11:17:23 -05002865
2866void Context::blitFramebuffer(GLint srcX0,
2867 GLint srcY0,
2868 GLint srcX1,
2869 GLint srcY1,
2870 GLint dstX0,
2871 GLint dstY0,
2872 GLint dstX1,
2873 GLint dstY1,
2874 GLbitfield mask,
2875 GLenum filter)
2876{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002877 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002878 ASSERT(drawFramebuffer);
2879
2880 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
2881 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
2882
Jamie Madillad9f24e2016-02-12 09:27:24 -05002883 syncStateForBlit();
Jamie Madillc29968b2016-01-20 11:17:23 -05002884
Jamie Madillc564c072017-06-01 12:45:42 -04002885 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002886}
Jamie Madillc29968b2016-01-20 11:17:23 -05002887
2888void Context::clear(GLbitfield mask)
2889{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002890 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002891 handleError(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05002892}
2893
2894void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
2895{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002896 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002897 handleError(mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002898}
2899
2900void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
2901{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002902 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002903 handleError(mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002904}
2905
2906void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
2907{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002908 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002909 handleError(mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002910}
2911
2912void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
2913{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002914 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002915 ASSERT(framebufferObject);
2916
2917 // If a buffer is not present, the clear has no effect
2918 if (framebufferObject->getDepthbuffer() == nullptr &&
2919 framebufferObject->getStencilbuffer() == nullptr)
2920 {
2921 return;
2922 }
2923
Jamie Madillad9f24e2016-02-12 09:27:24 -05002924 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002925 handleError(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05002926}
2927
2928void Context::readPixels(GLint x,
2929 GLint y,
2930 GLsizei width,
2931 GLsizei height,
2932 GLenum format,
2933 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002934 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05002935{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04002936 if (width == 0 || height == 0)
2937 {
2938 return;
2939 }
2940
Jamie Madillad9f24e2016-02-12 09:27:24 -05002941 syncStateForReadPixels();
Jamie Madillc29968b2016-01-20 11:17:23 -05002942
Jamie Madillb6664922017-07-25 12:55:04 -04002943 Framebuffer *readFBO = mGLState.getReadFramebuffer();
2944 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05002945
2946 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04002947 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05002948}
2949
2950void Context::copyTexImage2D(GLenum target,
2951 GLint level,
2952 GLenum internalformat,
2953 GLint x,
2954 GLint y,
2955 GLsizei width,
2956 GLsizei height,
2957 GLint border)
2958{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002959 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002960 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002961
Jamie Madillc29968b2016-01-20 11:17:23 -05002962 Rectangle sourceArea(x, y, width, height);
2963
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002964 const Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002965 Texture *texture =
2966 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05002967 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05002968}
2969
2970void Context::copyTexSubImage2D(GLenum target,
2971 GLint level,
2972 GLint xoffset,
2973 GLint yoffset,
2974 GLint x,
2975 GLint y,
2976 GLsizei width,
2977 GLsizei height)
2978{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04002979 if (width == 0 || height == 0)
2980 {
2981 return;
2982 }
2983
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002984 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002985 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002986
Jamie Madillc29968b2016-01-20 11:17:23 -05002987 Offset destOffset(xoffset, yoffset, 0);
2988 Rectangle sourceArea(x, y, width, height);
2989
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002990 const Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002991 Texture *texture =
2992 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05002993 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05002994}
2995
2996void Context::copyTexSubImage3D(GLenum target,
2997 GLint level,
2998 GLint xoffset,
2999 GLint yoffset,
3000 GLint zoffset,
3001 GLint x,
3002 GLint y,
3003 GLsizei width,
3004 GLsizei height)
3005{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003006 if (width == 0 || height == 0)
3007 {
3008 return;
3009 }
3010
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003011 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003012 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003013
Jamie Madillc29968b2016-01-20 11:17:23 -05003014 Offset destOffset(xoffset, yoffset, zoffset);
3015 Rectangle sourceArea(x, y, width, height);
3016
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003017 const Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003018 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003019 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003020}
3021
3022void Context::framebufferTexture2D(GLenum target,
3023 GLenum attachment,
3024 GLenum textarget,
3025 GLuint texture,
3026 GLint level)
3027{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003028 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003029 ASSERT(framebuffer);
3030
3031 if (texture != 0)
3032 {
3033 Texture *textureObj = getTexture(texture);
3034
3035 ImageIndex index = ImageIndex::MakeInvalid();
3036
3037 if (textarget == GL_TEXTURE_2D)
3038 {
3039 index = ImageIndex::Make2D(level);
3040 }
Corentin Wallez13c0dd42017-07-04 18:27:01 -04003041 else if (textarget == GL_TEXTURE_RECTANGLE_ANGLE)
3042 {
3043 index = ImageIndex::MakeRectangle(level);
3044 }
JiangYizhoubddc46b2016-12-09 09:50:51 +08003045 else if (textarget == GL_TEXTURE_2D_MULTISAMPLE)
3046 {
3047 ASSERT(level == 0);
3048 index = ImageIndex::Make2DMultisample();
3049 }
Jamie Madillc29968b2016-01-20 11:17:23 -05003050 else
3051 {
3052 ASSERT(IsCubeMapTextureTarget(textarget));
3053 index = ImageIndex::MakeCube(textarget, level);
3054 }
3055
Jamie Madilla02315b2017-02-23 14:14:47 -05003056 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003057 }
3058 else
3059 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003060 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003061 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003062
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003063 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003064}
3065
3066void Context::framebufferRenderbuffer(GLenum target,
3067 GLenum attachment,
3068 GLenum renderbuffertarget,
3069 GLuint renderbuffer)
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 (renderbuffer != 0)
3075 {
3076 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003077
3078 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex::MakeInvalid(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003079 renderbufferObject);
3080 }
3081 else
3082 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003083 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003084 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003085
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003086 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003087}
3088
3089void Context::framebufferTextureLayer(GLenum target,
3090 GLenum attachment,
3091 GLuint texture,
3092 GLint level,
3093 GLint layer)
3094{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003095 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003096 ASSERT(framebuffer);
3097
3098 if (texture != 0)
3099 {
3100 Texture *textureObject = getTexture(texture);
3101
3102 ImageIndex index = ImageIndex::MakeInvalid();
3103
3104 if (textureObject->getTarget() == GL_TEXTURE_3D)
3105 {
3106 index = ImageIndex::Make3D(level, layer);
3107 }
3108 else
3109 {
3110 ASSERT(textureObject->getTarget() == GL_TEXTURE_2D_ARRAY);
3111 index = ImageIndex::Make2DArray(level, layer);
3112 }
3113
Jamie Madilla02315b2017-02-23 14:14:47 -05003114 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003115 }
3116 else
3117 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003118 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003119 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003120
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003121 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003122}
3123
Martin Radev137032d2017-07-13 10:11:12 +03003124void Context::framebufferTextureMultiviewLayeredANGLE(GLenum target,
3125 GLenum attachment,
3126 GLuint texture,
3127 GLint level,
3128 GLint baseViewIndex,
3129 GLsizei numViews)
3130{
3131 UNIMPLEMENTED();
3132}
3133
3134void Context::framebufferTextureMultiviewSideBySideANGLE(GLenum target,
3135 GLenum attachment,
3136 GLuint texture,
3137 GLint level,
3138 GLsizei numViews,
3139 const GLint *viewportOffsets)
3140{
Martin Radev5dae57b2017-07-14 16:15:55 +03003141 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3142 ASSERT(framebuffer);
3143
3144 if (texture != 0)
3145 {
3146 Texture *textureObj = getTexture(texture);
3147
3148 ImageIndex index = ImageIndex::Make2D(level);
3149 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3150 textureObj, numViews, viewportOffsets);
3151 }
3152 else
3153 {
3154 framebuffer->resetAttachment(this, attachment);
3155 }
3156
3157 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003158}
3159
Jamie Madillc29968b2016-01-20 11:17:23 -05003160void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3161{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003162 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003163 ASSERT(framebuffer);
3164 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003165 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003166}
3167
3168void Context::readBuffer(GLenum mode)
3169{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003170 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003171 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003172 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003173}
3174
3175void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3176{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003177 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003178 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003179
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003180 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003181 ASSERT(framebuffer);
3182
3183 // The specification isn't clear what should be done when the framebuffer isn't complete.
3184 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003185 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003186}
3187
3188void Context::invalidateFramebuffer(GLenum target,
3189 GLsizei numAttachments,
3190 const GLenum *attachments)
3191{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003192 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003193 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003194
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003195 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003196 ASSERT(framebuffer);
3197
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003198 if (framebuffer->checkStatus(this) != GL_FRAMEBUFFER_COMPLETE)
Jamie Madillc29968b2016-01-20 11:17:23 -05003199 {
Jamie Madill437fa652016-05-03 15:13:24 -04003200 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003201 }
Jamie Madill437fa652016-05-03 15:13:24 -04003202
Jamie Madill4928b7c2017-06-20 12:57:39 -04003203 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003204}
3205
3206void Context::invalidateSubFramebuffer(GLenum target,
3207 GLsizei numAttachments,
3208 const GLenum *attachments,
3209 GLint x,
3210 GLint y,
3211 GLsizei width,
3212 GLsizei height)
3213{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003214 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003215 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003216
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003217 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003218 ASSERT(framebuffer);
3219
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003220 if (framebuffer->checkStatus(this) != GL_FRAMEBUFFER_COMPLETE)
Jamie Madillc29968b2016-01-20 11:17:23 -05003221 {
Jamie Madill437fa652016-05-03 15:13:24 -04003222 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003223 }
Jamie Madill437fa652016-05-03 15:13:24 -04003224
3225 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003226 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003227}
3228
Jamie Madill73a84962016-02-12 09:27:23 -05003229void Context::texImage2D(GLenum target,
3230 GLint level,
3231 GLint internalformat,
3232 GLsizei width,
3233 GLsizei height,
3234 GLint border,
3235 GLenum format,
3236 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003237 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003238{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003239 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003240
3241 Extents size(width, height, 1);
3242 Texture *texture =
3243 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003244 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3245 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003246}
3247
3248void Context::texImage3D(GLenum target,
3249 GLint level,
3250 GLint internalformat,
3251 GLsizei width,
3252 GLsizei height,
3253 GLsizei depth,
3254 GLint border,
3255 GLenum format,
3256 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003257 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003258{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003259 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003260
3261 Extents size(width, height, depth);
3262 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003263 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3264 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003265}
3266
3267void Context::texSubImage2D(GLenum target,
3268 GLint level,
3269 GLint xoffset,
3270 GLint yoffset,
3271 GLsizei width,
3272 GLsizei height,
3273 GLenum format,
3274 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003275 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003276{
3277 // Zero sized uploads are valid but no-ops
3278 if (width == 0 || height == 0)
3279 {
3280 return;
3281 }
3282
Jamie Madillad9f24e2016-02-12 09:27:24 -05003283 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003284
3285 Box area(xoffset, yoffset, 0, width, height, 1);
3286 Texture *texture =
3287 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003288 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3289 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003290}
3291
3292void Context::texSubImage3D(GLenum target,
3293 GLint level,
3294 GLint xoffset,
3295 GLint yoffset,
3296 GLint zoffset,
3297 GLsizei width,
3298 GLsizei height,
3299 GLsizei depth,
3300 GLenum format,
3301 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003302 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003303{
3304 // Zero sized uploads are valid but no-ops
3305 if (width == 0 || height == 0 || depth == 0)
3306 {
3307 return;
3308 }
3309
Jamie Madillad9f24e2016-02-12 09:27:24 -05003310 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003311
3312 Box area(xoffset, yoffset, zoffset, width, height, depth);
3313 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003314 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3315 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003316}
3317
3318void Context::compressedTexImage2D(GLenum target,
3319 GLint level,
3320 GLenum internalformat,
3321 GLsizei width,
3322 GLsizei height,
3323 GLint border,
3324 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003325 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003326{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003327 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003328
3329 Extents size(width, height, 1);
3330 Texture *texture =
3331 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003332 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003333 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003334 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003335}
3336
3337void Context::compressedTexImage3D(GLenum target,
3338 GLint level,
3339 GLenum internalformat,
3340 GLsizei width,
3341 GLsizei height,
3342 GLsizei depth,
3343 GLint border,
3344 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003345 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003346{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003347 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003348
3349 Extents size(width, height, depth);
3350 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003351 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003352 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003353 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003354}
3355
3356void Context::compressedTexSubImage2D(GLenum target,
3357 GLint level,
3358 GLint xoffset,
3359 GLint yoffset,
3360 GLsizei width,
3361 GLsizei height,
3362 GLenum format,
3363 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003364 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003365{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003366 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003367
3368 Box area(xoffset, yoffset, 0, width, height, 1);
3369 Texture *texture =
3370 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003371 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003372 format, imageSize,
3373 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003374}
3375
3376void Context::compressedTexSubImage3D(GLenum target,
3377 GLint level,
3378 GLint xoffset,
3379 GLint yoffset,
3380 GLint zoffset,
3381 GLsizei width,
3382 GLsizei height,
3383 GLsizei depth,
3384 GLenum format,
3385 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003386 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003387{
3388 // Zero sized uploads are valid but no-ops
3389 if (width == 0 || height == 0)
3390 {
3391 return;
3392 }
3393
Jamie Madillad9f24e2016-02-12 09:27:24 -05003394 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003395
3396 Box area(xoffset, yoffset, zoffset, width, height, depth);
3397 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003398 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003399 format, imageSize,
3400 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003401}
3402
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003403void Context::generateMipmap(GLenum target)
3404{
3405 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003406 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003407}
3408
Geoff Lang97073d12016-04-20 10:42:34 -07003409void Context::copyTextureCHROMIUM(GLuint sourceId,
Geoff Langfc72a072017-03-24 14:52:39 -04003410 GLint sourceLevel,
3411 GLenum destTarget,
Geoff Lang97073d12016-04-20 10:42:34 -07003412 GLuint destId,
Geoff Langfc72a072017-03-24 14:52:39 -04003413 GLint destLevel,
Geoff Lang97073d12016-04-20 10:42:34 -07003414 GLint internalFormat,
3415 GLenum destType,
3416 GLboolean unpackFlipY,
3417 GLboolean unpackPremultiplyAlpha,
3418 GLboolean unpackUnmultiplyAlpha)
3419{
3420 syncStateForTexImage();
3421
3422 gl::Texture *sourceTexture = getTexture(sourceId);
3423 gl::Texture *destTexture = getTexture(destId);
Geoff Langfc72a072017-03-24 14:52:39 -04003424 handleError(destTexture->copyTexture(
3425 this, destTarget, destLevel, internalFormat, destType, sourceLevel, unpackFlipY == GL_TRUE,
3426 unpackPremultiplyAlpha == GL_TRUE, unpackUnmultiplyAlpha == GL_TRUE, sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003427}
3428
3429void Context::copySubTextureCHROMIUM(GLuint sourceId,
Geoff Langfc72a072017-03-24 14:52:39 -04003430 GLint sourceLevel,
3431 GLenum destTarget,
Geoff Lang97073d12016-04-20 10:42:34 -07003432 GLuint destId,
Geoff Langfc72a072017-03-24 14:52:39 -04003433 GLint destLevel,
Geoff Lang97073d12016-04-20 10:42:34 -07003434 GLint xoffset,
3435 GLint yoffset,
3436 GLint x,
3437 GLint y,
3438 GLsizei width,
3439 GLsizei height,
3440 GLboolean unpackFlipY,
3441 GLboolean unpackPremultiplyAlpha,
3442 GLboolean unpackUnmultiplyAlpha)
3443{
3444 // Zero sized copies are valid but no-ops
3445 if (width == 0 || height == 0)
3446 {
3447 return;
3448 }
3449
3450 syncStateForTexImage();
3451
3452 gl::Texture *sourceTexture = getTexture(sourceId);
3453 gl::Texture *destTexture = getTexture(destId);
3454 Offset offset(xoffset, yoffset, 0);
3455 Rectangle area(x, y, width, height);
Geoff Langfc72a072017-03-24 14:52:39 -04003456 handleError(destTexture->copySubTexture(
3457 this, destTarget, destLevel, offset, sourceLevel, area, unpackFlipY == GL_TRUE,
3458 unpackPremultiplyAlpha == GL_TRUE, unpackUnmultiplyAlpha == GL_TRUE, sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003459}
3460
Geoff Lang47110bf2016-04-20 11:13:22 -07003461void Context::compressedCopyTextureCHROMIUM(GLuint sourceId, GLuint destId)
3462{
3463 syncStateForTexImage();
3464
3465 gl::Texture *sourceTexture = getTexture(sourceId);
3466 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05003467 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07003468}
3469
Geoff Lang496c02d2016-10-20 11:38:11 -07003470void Context::getBufferPointerv(GLenum target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03003471{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003472 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003473 ASSERT(buffer);
3474
Geoff Lang496c02d2016-10-20 11:38:11 -07003475 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03003476}
3477
Jamie Madill876429b2017-04-20 15:46:24 -04003478void *Context::mapBuffer(GLenum target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003479{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003480 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003481 ASSERT(buffer);
3482
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003483 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003484 if (error.isError())
3485 {
Jamie Madill437fa652016-05-03 15:13:24 -04003486 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003487 return nullptr;
3488 }
3489
3490 return buffer->getMapPointer();
3491}
3492
3493GLboolean Context::unmapBuffer(GLenum target)
3494{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003495 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003496 ASSERT(buffer);
3497
3498 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003499 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03003500 if (error.isError())
3501 {
Jamie Madill437fa652016-05-03 15:13:24 -04003502 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003503 return GL_FALSE;
3504 }
3505
3506 return result;
3507}
3508
Jamie Madill876429b2017-04-20 15:46:24 -04003509void *Context::mapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003510{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003511 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003512 ASSERT(buffer);
3513
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003514 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003515 if (error.isError())
3516 {
Jamie Madill437fa652016-05-03 15:13:24 -04003517 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003518 return nullptr;
3519 }
3520
3521 return buffer->getMapPointer();
3522}
3523
3524void Context::flushMappedBufferRange(GLenum /*target*/, GLintptr /*offset*/, GLsizeiptr /*length*/)
3525{
3526 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
3527}
3528
Jamie Madillad9f24e2016-02-12 09:27:24 -05003529void Context::syncStateForReadPixels()
3530{
3531 syncRendererState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
3532}
3533
3534void Context::syncStateForTexImage()
3535{
3536 syncRendererState(mTexImageDirtyBits, mTexImageDirtyObjects);
3537}
3538
3539void Context::syncStateForClear()
3540{
3541 syncRendererState(mClearDirtyBits, mClearDirtyObjects);
3542}
3543
3544void Context::syncStateForBlit()
3545{
3546 syncRendererState(mBlitDirtyBits, mBlitDirtyObjects);
3547}
3548
Jamie Madillc20ab272016-06-09 07:20:46 -07003549void Context::activeTexture(GLenum texture)
3550{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003551 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003552}
3553
Jamie Madill876429b2017-04-20 15:46:24 -04003554void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003555{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003556 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07003557}
3558
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003559void Context::blendEquation(GLenum mode)
3560{
3561 mGLState.setBlendEquation(mode, mode);
3562}
3563
Jamie Madillc20ab272016-06-09 07:20:46 -07003564void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
3565{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003566 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003567}
3568
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003569void Context::blendFunc(GLenum sfactor, GLenum dfactor)
3570{
3571 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
3572}
3573
Jamie Madillc20ab272016-06-09 07:20:46 -07003574void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
3575{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003576 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003577}
3578
Jamie Madill876429b2017-04-20 15:46:24 -04003579void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003580{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003581 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003582}
3583
Jamie Madill876429b2017-04-20 15:46:24 -04003584void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07003585{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003586 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07003587}
3588
3589void Context::clearStencil(GLint s)
3590{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003591 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07003592}
3593
3594void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
3595{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003596 mGLState.setColorMask(red == GL_TRUE, green == GL_TRUE, blue == GL_TRUE, alpha == GL_TRUE);
Jamie Madillc20ab272016-06-09 07:20:46 -07003597}
3598
3599void Context::cullFace(GLenum mode)
3600{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003601 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003602}
3603
3604void Context::depthFunc(GLenum func)
3605{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003606 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07003607}
3608
3609void Context::depthMask(GLboolean flag)
3610{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003611 mGLState.setDepthMask(flag != GL_FALSE);
Jamie Madillc20ab272016-06-09 07:20:46 -07003612}
3613
Jamie Madill876429b2017-04-20 15:46:24 -04003614void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07003615{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003616 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07003617}
3618
3619void Context::disable(GLenum cap)
3620{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003621 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003622}
3623
3624void Context::disableVertexAttribArray(GLuint index)
3625{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003626 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003627}
3628
3629void Context::enable(GLenum cap)
3630{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003631 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003632}
3633
3634void Context::enableVertexAttribArray(GLuint index)
3635{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003636 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003637}
3638
3639void Context::frontFace(GLenum mode)
3640{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003641 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003642}
3643
3644void Context::hint(GLenum target, GLenum mode)
3645{
3646 switch (target)
3647 {
3648 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003649 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003650 break;
3651
3652 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003653 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003654 break;
3655
3656 default:
3657 UNREACHABLE();
3658 return;
3659 }
3660}
3661
3662void Context::lineWidth(GLfloat width)
3663{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003664 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07003665}
3666
3667void Context::pixelStorei(GLenum pname, GLint param)
3668{
3669 switch (pname)
3670 {
3671 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003672 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003673 break;
3674
3675 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003676 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003677 break;
3678
3679 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003680 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003681 break;
3682
3683 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003684 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003685 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003686 break;
3687
3688 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03003689 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003690 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003691 break;
3692
3693 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03003694 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003695 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003696 break;
3697
3698 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003699 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003700 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003701 break;
3702
3703 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003704 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003705 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003706 break;
3707
3708 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003709 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003710 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003711 break;
3712
3713 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003714 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003715 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003716 break;
3717
3718 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003719 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003720 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003721 break;
3722
3723 default:
3724 UNREACHABLE();
3725 return;
3726 }
3727}
3728
3729void Context::polygonOffset(GLfloat factor, GLfloat units)
3730{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003731 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07003732}
3733
Jamie Madill876429b2017-04-20 15:46:24 -04003734void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07003735{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003736 mGLState.setSampleCoverageParams(clamp01(value), invert == GL_TRUE);
Jamie Madillc20ab272016-06-09 07:20:46 -07003737}
3738
3739void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
3740{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003741 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07003742}
3743
3744void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
3745{
3746 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3747 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003748 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003749 }
3750
3751 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3752 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003753 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003754 }
3755}
3756
3757void Context::stencilMaskSeparate(GLenum face, GLuint mask)
3758{
3759 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3760 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003761 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003762 }
3763
3764 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3765 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003766 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003767 }
3768}
3769
3770void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
3771{
3772 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3773 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003774 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003775 }
3776
3777 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3778 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003779 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003780 }
3781}
3782
3783void Context::vertexAttrib1f(GLuint index, GLfloat x)
3784{
3785 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003786 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003787}
3788
3789void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
3790{
3791 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003792 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003793}
3794
3795void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
3796{
3797 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003798 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003799}
3800
3801void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
3802{
3803 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003804 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003805}
3806
3807void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
3808{
3809 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003810 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003811}
3812
3813void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
3814{
3815 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003816 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003817}
3818
3819void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
3820{
3821 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003822 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003823}
3824
3825void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
3826{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003827 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07003828}
3829
3830void Context::vertexAttribPointer(GLuint index,
3831 GLint size,
3832 GLenum type,
3833 GLboolean normalized,
3834 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04003835 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07003836{
Shaodde78e82017-05-22 14:13:27 +08003837 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(GL_ARRAY_BUFFER), size,
3838 type, normalized == GL_TRUE, false, stride, ptr);
Jamie Madillc20ab272016-06-09 07:20:46 -07003839}
3840
Shao80957d92017-02-20 21:25:59 +08003841void Context::vertexAttribFormat(GLuint attribIndex,
3842 GLint size,
3843 GLenum type,
3844 GLboolean normalized,
3845 GLuint relativeOffset)
3846{
3847 mGLState.setVertexAttribFormat(attribIndex, size, type, normalized == GL_TRUE, false,
3848 relativeOffset);
3849}
3850
3851void Context::vertexAttribIFormat(GLuint attribIndex,
3852 GLint size,
3853 GLenum type,
3854 GLuint relativeOffset)
3855{
3856 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
3857}
3858
3859void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
3860{
Shaodde78e82017-05-22 14:13:27 +08003861 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Shao80957d92017-02-20 21:25:59 +08003862}
3863
3864void Context::setVertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
3865{
3866 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
3867}
3868
Jamie Madillc20ab272016-06-09 07:20:46 -07003869void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
3870{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003871 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07003872}
3873
3874void Context::vertexAttribIPointer(GLuint index,
3875 GLint size,
3876 GLenum type,
3877 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04003878 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07003879{
Shaodde78e82017-05-22 14:13:27 +08003880 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(GL_ARRAY_BUFFER), size,
3881 type, false, true, stride, pointer);
Jamie Madillc20ab272016-06-09 07:20:46 -07003882}
3883
3884void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
3885{
3886 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003887 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003888}
3889
3890void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
3891{
3892 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003893 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003894}
3895
3896void Context::vertexAttribI4iv(GLuint index, const GLint *v)
3897{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003898 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07003899}
3900
3901void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
3902{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003903 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07003904}
3905
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003906void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
3907{
3908 const VertexAttribCurrentValueData &currentValues =
3909 getGLState().getVertexAttribCurrentValue(index);
3910 const VertexArray *vao = getGLState().getVertexArray();
3911 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3912 currentValues, pname, params);
3913}
3914
3915void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
3916{
3917 const VertexAttribCurrentValueData &currentValues =
3918 getGLState().getVertexAttribCurrentValue(index);
3919 const VertexArray *vao = getGLState().getVertexArray();
3920 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3921 currentValues, pname, params);
3922}
3923
3924void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
3925{
3926 const VertexAttribCurrentValueData &currentValues =
3927 getGLState().getVertexAttribCurrentValue(index);
3928 const VertexArray *vao = getGLState().getVertexArray();
3929 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3930 currentValues, pname, params);
3931}
3932
3933void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
3934{
3935 const VertexAttribCurrentValueData &currentValues =
3936 getGLState().getVertexAttribCurrentValue(index);
3937 const VertexArray *vao = getGLState().getVertexArray();
3938 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3939 currentValues, pname, params);
3940}
3941
Jamie Madill876429b2017-04-20 15:46:24 -04003942void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003943{
3944 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
3945 QueryVertexAttribPointerv(attrib, pname, pointer);
3946}
3947
Jamie Madillc20ab272016-06-09 07:20:46 -07003948void Context::debugMessageControl(GLenum source,
3949 GLenum type,
3950 GLenum severity,
3951 GLsizei count,
3952 const GLuint *ids,
3953 GLboolean enabled)
3954{
3955 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003956 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
3957 (enabled != GL_FALSE));
Jamie Madillc20ab272016-06-09 07:20:46 -07003958}
3959
3960void Context::debugMessageInsert(GLenum source,
3961 GLenum type,
3962 GLuint id,
3963 GLenum severity,
3964 GLsizei length,
3965 const GLchar *buf)
3966{
3967 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003968 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07003969}
3970
3971void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
3972{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003973 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07003974}
3975
3976GLuint Context::getDebugMessageLog(GLuint count,
3977 GLsizei bufSize,
3978 GLenum *sources,
3979 GLenum *types,
3980 GLuint *ids,
3981 GLenum *severities,
3982 GLsizei *lengths,
3983 GLchar *messageLog)
3984{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003985 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
3986 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07003987}
3988
3989void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
3990{
3991 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003992 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07003993}
3994
3995void Context::popDebugGroup()
3996{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003997 mGLState.getDebug().popGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07003998}
3999
Jamie Madill876429b2017-04-20 15:46:24 -04004000void Context::bufferData(GLenum target, GLsizeiptr size, const void *data, GLenum usage)
Jamie Madill29639852016-09-02 15:00:09 -04004001{
4002 Buffer *buffer = mGLState.getTargetBuffer(target);
4003 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004004 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004005}
4006
Jamie Madill876429b2017-04-20 15:46:24 -04004007void Context::bufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004008{
4009 if (data == nullptr)
4010 {
4011 return;
4012 }
4013
4014 Buffer *buffer = mGLState.getTargetBuffer(target);
4015 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004016 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004017}
4018
Jamie Madillef300b12016-10-07 15:12:09 -04004019void Context::attachShader(GLuint program, GLuint shader)
4020{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004021 auto programObject = mState.mShaderPrograms->getProgram(program);
4022 auto shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004023 ASSERT(programObject && shaderObject);
4024 programObject->attachShader(shaderObject);
4025}
4026
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004027const Workarounds &Context::getWorkarounds() const
4028{
4029 return mWorkarounds;
4030}
4031
Jamie Madillb0817d12016-11-01 15:48:31 -04004032void Context::copyBufferSubData(GLenum readTarget,
4033 GLenum writeTarget,
4034 GLintptr readOffset,
4035 GLintptr writeOffset,
4036 GLsizeiptr size)
4037{
4038 // if size is zero, the copy is a successful no-op
4039 if (size == 0)
4040 {
4041 return;
4042 }
4043
4044 // TODO(jmadill): cache these.
4045 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4046 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4047
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004048 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004049}
4050
Jamie Madill01a80ee2016-11-07 12:06:18 -05004051void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4052{
4053 Program *programObject = getProgram(program);
4054 // TODO(jmadill): Re-use this from the validation if possible.
4055 ASSERT(programObject);
4056 programObject->bindAttributeLocation(index, name);
4057}
4058
4059void Context::bindBuffer(GLenum target, GLuint buffer)
4060{
4061 switch (target)
4062 {
4063 case GL_ARRAY_BUFFER:
4064 bindArrayBuffer(buffer);
4065 break;
4066 case GL_ELEMENT_ARRAY_BUFFER:
4067 bindElementArrayBuffer(buffer);
4068 break;
4069 case GL_COPY_READ_BUFFER:
4070 bindCopyReadBuffer(buffer);
4071 break;
4072 case GL_COPY_WRITE_BUFFER:
4073 bindCopyWriteBuffer(buffer);
4074 break;
4075 case GL_PIXEL_PACK_BUFFER:
4076 bindPixelPackBuffer(buffer);
4077 break;
4078 case GL_PIXEL_UNPACK_BUFFER:
4079 bindPixelUnpackBuffer(buffer);
4080 break;
4081 case GL_UNIFORM_BUFFER:
4082 bindGenericUniformBuffer(buffer);
4083 break;
4084 case GL_TRANSFORM_FEEDBACK_BUFFER:
4085 bindGenericTransformFeedbackBuffer(buffer);
4086 break;
Geoff Lang3b573612016-10-31 14:08:10 -04004087 case GL_ATOMIC_COUNTER_BUFFER:
Jiajia Qin6eafb042016-12-27 17:04:07 +08004088 bindGenericAtomicCounterBuffer(buffer);
Geoff Lang3b573612016-10-31 14:08:10 -04004089 break;
4090 case GL_SHADER_STORAGE_BUFFER:
Jiajia Qinf546e7d2017-03-27 14:12:59 +08004091 bindGenericShaderStorageBuffer(buffer);
Geoff Lang3b573612016-10-31 14:08:10 -04004092 break;
4093 case GL_DRAW_INDIRECT_BUFFER:
Jiajia Qin9d7d0b12016-11-29 16:30:31 +08004094 bindDrawIndirectBuffer(buffer);
Geoff Lang3b573612016-10-31 14:08:10 -04004095 break;
4096 case GL_DISPATCH_INDIRECT_BUFFER:
Geoff Lang9f090372016-12-02 10:20:43 -05004097 if (buffer != 0)
4098 {
4099 // Binding buffers to this binding point is not implemented yet.
4100 UNIMPLEMENTED();
4101 }
Geoff Lang3b573612016-10-31 14:08:10 -04004102 break;
Jamie Madill01a80ee2016-11-07 12:06:18 -05004103
4104 default:
4105 UNREACHABLE();
4106 break;
4107 }
4108}
4109
Jiajia Qin6eafb042016-12-27 17:04:07 +08004110void Context::bindBufferBase(GLenum target, GLuint index, GLuint buffer)
4111{
4112 bindBufferRange(target, index, buffer, 0, 0);
4113}
4114
4115void Context::bindBufferRange(GLenum target,
4116 GLuint index,
4117 GLuint buffer,
4118 GLintptr offset,
4119 GLsizeiptr size)
4120{
4121 switch (target)
4122 {
4123 case GL_TRANSFORM_FEEDBACK_BUFFER:
4124 bindIndexedTransformFeedbackBuffer(buffer, index, offset, size);
4125 bindGenericTransformFeedbackBuffer(buffer);
4126 break;
4127 case GL_UNIFORM_BUFFER:
4128 bindIndexedUniformBuffer(buffer, index, offset, size);
4129 bindGenericUniformBuffer(buffer);
4130 break;
4131 case GL_ATOMIC_COUNTER_BUFFER:
4132 bindIndexedAtomicCounterBuffer(buffer, index, offset, size);
4133 bindGenericAtomicCounterBuffer(buffer);
4134 break;
4135 case GL_SHADER_STORAGE_BUFFER:
Jiajia Qinf546e7d2017-03-27 14:12:59 +08004136 bindIndexedShaderStorageBuffer(buffer, index, offset, size);
4137 bindGenericShaderStorageBuffer(buffer);
Jiajia Qin6eafb042016-12-27 17:04:07 +08004138 break;
4139 default:
4140 UNREACHABLE();
4141 break;
4142 }
4143}
4144
Jamie Madill01a80ee2016-11-07 12:06:18 -05004145void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
4146{
4147 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4148 {
4149 bindReadFramebuffer(framebuffer);
4150 }
4151
4152 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4153 {
4154 bindDrawFramebuffer(framebuffer);
4155 }
4156}
4157
4158void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4159{
4160 ASSERT(target == GL_RENDERBUFFER);
4161 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004162 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04004163 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004164}
4165
JiangYizhoubddc46b2016-12-09 09:50:51 +08004166void Context::texStorage2DMultisample(GLenum target,
4167 GLsizei samples,
4168 GLenum internalformat,
4169 GLsizei width,
4170 GLsizei height,
4171 GLboolean fixedsamplelocations)
4172{
4173 Extents size(width, height, 1);
4174 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05004175 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
JiangYizhoubddc46b2016-12-09 09:50:51 +08004176 fixedsamplelocations));
4177}
4178
4179void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4180{
Jamie Madilldd43e6c2017-03-24 14:18:49 -04004181 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
JiangYizhoubddc46b2016-12-09 09:50:51 +08004182 const Framebuffer *framebuffer = mGLState.getReadFramebuffer();
4183
4184 switch (pname)
4185 {
4186 case GL_SAMPLE_POSITION:
4187 handleError(framebuffer->getSamplePosition(index, val));
4188 break;
4189 default:
4190 UNREACHABLE();
4191 }
4192}
4193
Jamie Madille8fb6402017-02-14 17:56:40 -05004194void Context::renderbufferStorage(GLenum target,
4195 GLenum internalformat,
4196 GLsizei width,
4197 GLsizei height)
4198{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004199 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4200 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
4201
Jamie Madille8fb6402017-02-14 17:56:40 -05004202 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04004203 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004204}
4205
4206void Context::renderbufferStorageMultisample(GLenum target,
4207 GLsizei samples,
4208 GLenum internalformat,
4209 GLsizei width,
4210 GLsizei height)
4211{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004212 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4213 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05004214
4215 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004216 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04004217 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004218}
4219
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004220void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
4221{
4222 const FenceSync *syncObject = getFenceSync(sync);
Geoff Lang82483b92017-04-11 15:33:00 -04004223 handleError(QuerySynciv(syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004224}
4225
JiangYizhoue18e6392017-02-20 10:32:23 +08004226void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
4227{
4228 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4229 QueryFramebufferParameteriv(framebuffer, pname, params);
4230}
4231
4232void Context::setFramebufferParameteri(GLenum target, GLenum pname, GLint param)
4233{
4234 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4235 SetFramebufferParameteri(framebuffer, pname, param);
4236}
4237
Jamie Madillb3f26b92017-07-19 15:07:41 -04004238Error Context::getScratchBuffer(size_t requstedSizeBytes,
4239 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05004240{
Jamie Madillb3f26b92017-07-19 15:07:41 -04004241 if (!mScratchBuffer.get(requstedSizeBytes, scratchBufferOut))
4242 {
4243 return OutOfMemory() << "Failed to allocate internal buffer.";
4244 }
4245 return NoError();
4246}
4247
4248Error Context::getZeroFilledBuffer(size_t requstedSizeBytes,
4249 angle::MemoryBuffer **zeroBufferOut) const
4250{
4251 if (!mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0))
Jamie Madille14951e2017-03-09 18:55:16 -05004252 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004253 return OutOfMemory() << "Failed to allocate internal buffer.";
Jamie Madille14951e2017-03-09 18:55:16 -05004254 }
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004255 return NoError();
Jamie Madille14951e2017-03-09 18:55:16 -05004256}
4257
Xinghua Cao2b396592017-03-29 15:36:04 +08004258void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
4259{
4260 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
4261 {
4262 return;
4263 }
4264
Jamie Madillfe548342017-06-19 11:13:24 -04004265 mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ);
Xinghua Cao2b396592017-03-29 15:36:04 +08004266}
4267
JiangYizhou165361c2017-06-07 14:56:57 +08004268void Context::texStorage2D(GLenum target,
4269 GLsizei levels,
4270 GLenum internalFormat,
4271 GLsizei width,
4272 GLsizei height)
4273{
4274 Extents size(width, height, 1);
4275 Texture *texture = getTargetTexture(target);
4276 handleError(texture->setStorage(this, target, levels, internalFormat, size));
4277}
4278
4279void Context::texStorage3D(GLenum target,
4280 GLsizei levels,
4281 GLenum internalFormat,
4282 GLsizei width,
4283 GLsizei height,
4284 GLsizei depth)
4285{
4286 Extents size(width, height, depth);
4287 Texture *texture = getTargetTexture(target);
4288 handleError(texture->setStorage(this, target, levels, internalFormat, size));
4289}
4290
Jamie Madillc1d770e2017-04-13 17:31:24 -04004291GLenum Context::checkFramebufferStatus(GLenum target)
4292{
4293 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4294 ASSERT(framebuffer);
4295
4296 return framebuffer->checkStatus(this);
4297}
4298
4299void Context::compileShader(GLuint shader)
4300{
4301 Shader *shaderObject = GetValidShader(this, shader);
4302 if (!shaderObject)
4303 {
4304 return;
4305 }
4306 shaderObject->compile(this);
4307}
4308
4309void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
4310{
4311 for (int i = 0; i < n; i++)
4312 {
4313 deleteBuffer(buffers[i]);
4314 }
4315}
4316
4317void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
4318{
4319 for (int i = 0; i < n; i++)
4320 {
4321 if (framebuffers[i] != 0)
4322 {
4323 deleteFramebuffer(framebuffers[i]);
4324 }
4325 }
4326}
4327
4328void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
4329{
4330 for (int i = 0; i < n; i++)
4331 {
4332 deleteRenderbuffer(renderbuffers[i]);
4333 }
4334}
4335
4336void Context::deleteTextures(GLsizei n, const GLuint *textures)
4337{
4338 for (int i = 0; i < n; i++)
4339 {
4340 if (textures[i] != 0)
4341 {
4342 deleteTexture(textures[i]);
4343 }
4344 }
4345}
4346
4347void Context::detachShader(GLuint program, GLuint shader)
4348{
4349 Program *programObject = getProgram(program);
4350 ASSERT(programObject);
4351
4352 Shader *shaderObject = getShader(shader);
4353 ASSERT(shaderObject);
4354
4355 programObject->detachShader(this, shaderObject);
4356}
4357
4358void Context::genBuffers(GLsizei n, GLuint *buffers)
4359{
4360 for (int i = 0; i < n; i++)
4361 {
4362 buffers[i] = createBuffer();
4363 }
4364}
4365
4366void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
4367{
4368 for (int i = 0; i < n; i++)
4369 {
4370 framebuffers[i] = createFramebuffer();
4371 }
4372}
4373
4374void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
4375{
4376 for (int i = 0; i < n; i++)
4377 {
4378 renderbuffers[i] = createRenderbuffer();
4379 }
4380}
4381
4382void Context::genTextures(GLsizei n, GLuint *textures)
4383{
4384 for (int i = 0; i < n; i++)
4385 {
4386 textures[i] = createTexture();
4387 }
4388}
4389
4390void Context::getActiveAttrib(GLuint program,
4391 GLuint index,
4392 GLsizei bufsize,
4393 GLsizei *length,
4394 GLint *size,
4395 GLenum *type,
4396 GLchar *name)
4397{
4398 Program *programObject = getProgram(program);
4399 ASSERT(programObject);
4400 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
4401}
4402
4403void Context::getActiveUniform(GLuint program,
4404 GLuint index,
4405 GLsizei bufsize,
4406 GLsizei *length,
4407 GLint *size,
4408 GLenum *type,
4409 GLchar *name)
4410{
4411 Program *programObject = getProgram(program);
4412 ASSERT(programObject);
4413 programObject->getActiveUniform(index, bufsize, length, size, type, name);
4414}
4415
4416void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
4417{
4418 Program *programObject = getProgram(program);
4419 ASSERT(programObject);
4420 programObject->getAttachedShaders(maxcount, count, shaders);
4421}
4422
4423GLint Context::getAttribLocation(GLuint program, const GLchar *name)
4424{
4425 Program *programObject = getProgram(program);
4426 ASSERT(programObject);
4427 return programObject->getAttributeLocation(name);
4428}
4429
4430void Context::getBooleanv(GLenum pname, GLboolean *params)
4431{
4432 GLenum nativeType;
4433 unsigned int numParams = 0;
4434 getQueryParameterInfo(pname, &nativeType, &numParams);
4435
4436 if (nativeType == GL_BOOL)
4437 {
4438 getBooleanvImpl(pname, params);
4439 }
4440 else
4441 {
4442 CastStateValues(this, nativeType, pname, numParams, params);
4443 }
4444}
4445
4446void Context::getFloatv(GLenum pname, GLfloat *params)
4447{
4448 GLenum nativeType;
4449 unsigned int numParams = 0;
4450 getQueryParameterInfo(pname, &nativeType, &numParams);
4451
4452 if (nativeType == GL_FLOAT)
4453 {
4454 getFloatvImpl(pname, params);
4455 }
4456 else
4457 {
4458 CastStateValues(this, nativeType, pname, numParams, params);
4459 }
4460}
4461
4462void Context::getIntegerv(GLenum pname, GLint *params)
4463{
4464 GLenum nativeType;
4465 unsigned int numParams = 0;
4466 getQueryParameterInfo(pname, &nativeType, &numParams);
4467
4468 if (nativeType == GL_INT)
4469 {
4470 getIntegervImpl(pname, params);
4471 }
4472 else
4473 {
4474 CastStateValues(this, nativeType, pname, numParams, params);
4475 }
4476}
4477
4478void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
4479{
4480 Program *programObject = getProgram(program);
4481 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04004482 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004483}
4484
Jamie Madillbe849e42017-05-02 15:49:00 -04004485void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04004486{
4487 Program *programObject = getProgram(program);
4488 ASSERT(programObject);
4489 programObject->getInfoLog(bufsize, length, infolog);
4490}
4491
4492void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
4493{
4494 Shader *shaderObject = getShader(shader);
4495 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004496 QueryShaderiv(this, shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004497}
4498
4499void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
4500{
4501 Shader *shaderObject = getShader(shader);
4502 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004503 shaderObject->getInfoLog(this, bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004504}
4505
4506void Context::getShaderPrecisionFormat(GLenum shadertype,
4507 GLenum precisiontype,
4508 GLint *range,
4509 GLint *precision)
4510{
4511 // TODO(jmadill): Compute shaders.
4512
4513 switch (shadertype)
4514 {
4515 case GL_VERTEX_SHADER:
4516 switch (precisiontype)
4517 {
4518 case GL_LOW_FLOAT:
4519 mCaps.vertexLowpFloat.get(range, precision);
4520 break;
4521 case GL_MEDIUM_FLOAT:
4522 mCaps.vertexMediumpFloat.get(range, precision);
4523 break;
4524 case GL_HIGH_FLOAT:
4525 mCaps.vertexHighpFloat.get(range, precision);
4526 break;
4527
4528 case GL_LOW_INT:
4529 mCaps.vertexLowpInt.get(range, precision);
4530 break;
4531 case GL_MEDIUM_INT:
4532 mCaps.vertexMediumpInt.get(range, precision);
4533 break;
4534 case GL_HIGH_INT:
4535 mCaps.vertexHighpInt.get(range, precision);
4536 break;
4537
4538 default:
4539 UNREACHABLE();
4540 return;
4541 }
4542 break;
4543
4544 case GL_FRAGMENT_SHADER:
4545 switch (precisiontype)
4546 {
4547 case GL_LOW_FLOAT:
4548 mCaps.fragmentLowpFloat.get(range, precision);
4549 break;
4550 case GL_MEDIUM_FLOAT:
4551 mCaps.fragmentMediumpFloat.get(range, precision);
4552 break;
4553 case GL_HIGH_FLOAT:
4554 mCaps.fragmentHighpFloat.get(range, precision);
4555 break;
4556
4557 case GL_LOW_INT:
4558 mCaps.fragmentLowpInt.get(range, precision);
4559 break;
4560 case GL_MEDIUM_INT:
4561 mCaps.fragmentMediumpInt.get(range, precision);
4562 break;
4563 case GL_HIGH_INT:
4564 mCaps.fragmentHighpInt.get(range, precision);
4565 break;
4566
4567 default:
4568 UNREACHABLE();
4569 return;
4570 }
4571 break;
4572
4573 default:
4574 UNREACHABLE();
4575 return;
4576 }
4577}
4578
4579void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
4580{
4581 Shader *shaderObject = getShader(shader);
4582 ASSERT(shaderObject);
4583 shaderObject->getSource(bufsize, length, source);
4584}
4585
4586void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
4587{
4588 Program *programObject = getProgram(program);
4589 ASSERT(programObject);
4590 programObject->getUniformfv(location, params);
4591}
4592
4593void Context::getUniformiv(GLuint program, GLint location, GLint *params)
4594{
4595 Program *programObject = getProgram(program);
4596 ASSERT(programObject);
4597 programObject->getUniformiv(location, params);
4598}
4599
4600GLint Context::getUniformLocation(GLuint program, const GLchar *name)
4601{
4602 Program *programObject = getProgram(program);
4603 ASSERT(programObject);
4604 return programObject->getUniformLocation(name);
4605}
4606
4607GLboolean Context::isBuffer(GLuint buffer)
4608{
4609 if (buffer == 0)
4610 {
4611 return GL_FALSE;
4612 }
4613
4614 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
4615}
4616
4617GLboolean Context::isEnabled(GLenum cap)
4618{
4619 return mGLState.getEnableFeature(cap);
4620}
4621
4622GLboolean Context::isFramebuffer(GLuint framebuffer)
4623{
4624 if (framebuffer == 0)
4625 {
4626 return GL_FALSE;
4627 }
4628
4629 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
4630}
4631
4632GLboolean Context::isProgram(GLuint program)
4633{
4634 if (program == 0)
4635 {
4636 return GL_FALSE;
4637 }
4638
4639 return (getProgram(program) ? GL_TRUE : GL_FALSE);
4640}
4641
4642GLboolean Context::isRenderbuffer(GLuint renderbuffer)
4643{
4644 if (renderbuffer == 0)
4645 {
4646 return GL_FALSE;
4647 }
4648
4649 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
4650}
4651
4652GLboolean Context::isShader(GLuint shader)
4653{
4654 if (shader == 0)
4655 {
4656 return GL_FALSE;
4657 }
4658
4659 return (getShader(shader) ? GL_TRUE : GL_FALSE);
4660}
4661
4662GLboolean Context::isTexture(GLuint texture)
4663{
4664 if (texture == 0)
4665 {
4666 return GL_FALSE;
4667 }
4668
4669 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
4670}
4671
4672void Context::linkProgram(GLuint program)
4673{
4674 Program *programObject = getProgram(program);
4675 ASSERT(programObject);
4676 handleError(programObject->link(this));
4677}
4678
4679void Context::releaseShaderCompiler()
4680{
Jamie Madill4928b7c2017-06-20 12:57:39 -04004681 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004682}
4683
4684void Context::shaderBinary(GLsizei n,
4685 const GLuint *shaders,
4686 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04004687 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04004688 GLsizei length)
4689{
4690 // No binary shader formats are supported.
4691 UNIMPLEMENTED();
4692}
4693
4694void Context::shaderSource(GLuint shader,
4695 GLsizei count,
4696 const GLchar *const *string,
4697 const GLint *length)
4698{
4699 Shader *shaderObject = getShader(shader);
4700 ASSERT(shaderObject);
4701 shaderObject->setSource(count, string, length);
4702}
4703
4704void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
4705{
4706 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
4707}
4708
4709void Context::stencilMask(GLuint mask)
4710{
4711 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
4712}
4713
4714void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
4715{
4716 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
4717}
4718
4719void Context::uniform1f(GLint location, GLfloat x)
4720{
4721 Program *program = mGLState.getProgram();
4722 program->setUniform1fv(location, 1, &x);
4723}
4724
4725void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
4726{
4727 Program *program = mGLState.getProgram();
4728 program->setUniform1fv(location, count, v);
4729}
4730
4731void Context::uniform1i(GLint location, GLint x)
4732{
4733 Program *program = mGLState.getProgram();
4734 program->setUniform1iv(location, 1, &x);
4735}
4736
4737void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
4738{
4739 Program *program = mGLState.getProgram();
4740 program->setUniform1iv(location, count, v);
4741}
4742
4743void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
4744{
4745 GLfloat xy[2] = {x, y};
4746 Program *program = mGLState.getProgram();
4747 program->setUniform2fv(location, 1, xy);
4748}
4749
4750void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
4751{
4752 Program *program = mGLState.getProgram();
4753 program->setUniform2fv(location, count, v);
4754}
4755
4756void Context::uniform2i(GLint location, GLint x, GLint y)
4757{
4758 GLint xy[2] = {x, y};
4759 Program *program = mGLState.getProgram();
4760 program->setUniform2iv(location, 1, xy);
4761}
4762
4763void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
4764{
4765 Program *program = mGLState.getProgram();
4766 program->setUniform2iv(location, count, v);
4767}
4768
4769void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
4770{
4771 GLfloat xyz[3] = {x, y, z};
4772 Program *program = mGLState.getProgram();
4773 program->setUniform3fv(location, 1, xyz);
4774}
4775
4776void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
4777{
4778 Program *program = mGLState.getProgram();
4779 program->setUniform3fv(location, count, v);
4780}
4781
4782void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
4783{
4784 GLint xyz[3] = {x, y, z};
4785 Program *program = mGLState.getProgram();
4786 program->setUniform3iv(location, 1, xyz);
4787}
4788
4789void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
4790{
4791 Program *program = mGLState.getProgram();
4792 program->setUniform3iv(location, count, v);
4793}
4794
4795void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4796{
4797 GLfloat xyzw[4] = {x, y, z, w};
4798 Program *program = mGLState.getProgram();
4799 program->setUniform4fv(location, 1, xyzw);
4800}
4801
4802void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
4803{
4804 Program *program = mGLState.getProgram();
4805 program->setUniform4fv(location, count, v);
4806}
4807
4808void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
4809{
4810 GLint xyzw[4] = {x, y, z, w};
4811 Program *program = mGLState.getProgram();
4812 program->setUniform4iv(location, 1, xyzw);
4813}
4814
4815void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
4816{
4817 Program *program = mGLState.getProgram();
4818 program->setUniform4iv(location, count, v);
4819}
4820
4821void Context::uniformMatrix2fv(GLint location,
4822 GLsizei count,
4823 GLboolean transpose,
4824 const GLfloat *value)
4825{
4826 Program *program = mGLState.getProgram();
4827 program->setUniformMatrix2fv(location, count, transpose, value);
4828}
4829
4830void Context::uniformMatrix3fv(GLint location,
4831 GLsizei count,
4832 GLboolean transpose,
4833 const GLfloat *value)
4834{
4835 Program *program = mGLState.getProgram();
4836 program->setUniformMatrix3fv(location, count, transpose, value);
4837}
4838
4839void Context::uniformMatrix4fv(GLint location,
4840 GLsizei count,
4841 GLboolean transpose,
4842 const GLfloat *value)
4843{
4844 Program *program = mGLState.getProgram();
4845 program->setUniformMatrix4fv(location, count, transpose, value);
4846}
4847
4848void Context::validateProgram(GLuint program)
4849{
4850 Program *programObject = getProgram(program);
4851 ASSERT(programObject);
4852 programObject->validate(mCaps);
4853}
4854
Jamie Madilld04908b2017-06-09 14:15:35 -04004855void Context::getProgramBinary(GLuint program,
4856 GLsizei bufSize,
4857 GLsizei *length,
4858 GLenum *binaryFormat,
4859 void *binary)
4860{
4861 Program *programObject = getProgram(program);
4862 ASSERT(programObject != nullptr);
4863
4864 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
4865}
4866
4867void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
4868{
4869 Program *programObject = getProgram(program);
4870 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04004871
Jamie Madilld04908b2017-06-09 14:15:35 -04004872 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
4873}
4874
Jamie Madillc29968b2016-01-20 11:17:23 -05004875} // namespace gl